Skip to content

Commit

Permalink
Updated some code in base library. Not complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
ax-6 committed Aug 15, 2024
1 parent feb1ff9 commit 240447e
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 13 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

cmake_minimum_required(VERSION 3.10)
project(AQ C)
enable_testing()

include_directories(${PROJECT_SOURCE_DIR})

Expand Down
2 changes: 2 additions & 0 deletions aqvm/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/base.c)
add_subdirectory(file)
add_subdirectory(hash)
add_subdirectory(io)
add_subdirectory(memory)
add_subdirectory(linked_list)
add_subdirectory(logging)
add_subdirectory(process)
Expand All @@ -22,6 +23,7 @@ add_library(AqvmBase STATIC ${SOURCES})
target_link_libraries(AqvmBase PRIVATE AqvmBaseFile)
target_link_libraries(AqvmBase PRIVATE AqvmBaseHash)
target_link_libraries(AqvmBase PRIVATE AqvmBaseIo)
target_link_libraries(AqvmBase PRIVATE AqvmBaseMemory)
target_link_libraries(AqvmBase PRIVATE AqvmBaseLinkedList)
target_link_libraries(AqvmBase PRIVATE AqvmBaseLogging)
target_link_libraries(AqvmBase PRIVATE AqvmBaseProcess)
Expand Down
8 changes: 4 additions & 4 deletions aqvm/base/file/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ struct AqvmBaseFile_File* AqvmBaseFile_fopen(const char* filename,
}

struct AqvmBaseFile_File* stream =
(struct AqvmBaseFile_File*)malloc(sizeof(struct AqvmBaseFile_File));
(struct AqvmBaseFile_File*)AqvmBaseMemory_malloc(sizeof(struct AqvmBaseFile_File));
if (stream == NULL) {
// TODO
return NULL;
}
stream->identifier = (AqvmBaseFileIdentifier_Identifier*)malloc(
stream->identifier = (AqvmBaseFileIdentifier_Identifier*)AqvmBaseMemory_malloc(
sizeof(AqvmBaseFileIdentifier_Identifier));
if (stream->identifier == NULL) {
// TODO
Expand Down Expand Up @@ -507,7 +507,7 @@ int AqvmBaseFile_setvbuf(struct AqvmBaseFile_File* stream, char* buffer,

struct AqvmBaseFile_File* AqvmBaseFile_tmpfile() {
struct AqvmBaseFile_File* stream =
(struct AqvmBaseFile_File*)malloc(sizeof(struct AqvmBaseFile_File));
(struct AqvmBaseFile_File*)AqvmBaseMemory_malloc(sizeof(struct AqvmBaseFile_File));
if (stream == NULL) {
// TODO
return NULL;
Expand All @@ -519,7 +519,7 @@ struct AqvmBaseFile_File* AqvmBaseFile_tmpfile() {
// TODO
return NULL;
}
stream->identifier = (AqvmBaseFileIdentifier_Identifier*)malloc(
stream->identifier = (AqvmBaseFileIdentifier_Identifier*)AqvmBaseMemory_malloc(
sizeof(AqvmBaseFileIdentifier_Identifier));
if (stream->identifier == NULL) {
// TODO
Expand Down
2 changes: 1 addition & 1 deletion aqvm/base/file/read_write_lock/read_write_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
struct AqvmBaseFileReadWriteLock_ReadWriteLock*
AqvmBaseFileReadWriteLock_CreateReadWriteLock() {
struct AqvmBaseFileReadWriteLock_ReadWriteLock* read_write_lock =
(struct AqvmBaseFileReadWriteLock_ReadWriteLock*)malloc(
(struct AqvmBaseFileReadWriteLock_ReadWriteLock*)AqvmBaseMemory_malloc(
sizeof(struct AqvmBaseFileReadWriteLock_ReadWriteLock));
if (read_write_lock == NULL) {
// TODO
Expand Down
6 changes: 3 additions & 3 deletions aqvm/base/linked_list/linked_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int AqvmBaseLinkedList_AddNode(struct AqvmBaseLinkedList_LinkedList* list,
}

struct AqvmBaseLinkedList_Node* new_node =
(struct AqvmBaseLinkedList_Node*)malloc(
(struct AqvmBaseLinkedList_Node*)AqvmBaseMemory_malloc(
sizeof(struct AqvmBaseLinkedList_Node));
if (new_node == NULL) {
// TODO
Expand Down Expand Up @@ -113,7 +113,7 @@ int AqvmBaseLinkedList_InsertNode(struct AqvmBaseLinkedList_LinkedList* list,
}

struct AqvmBaseLinkedList_Node* insert_node =
(struct AqvmBaseLinkedList_Node*)malloc(
(struct AqvmBaseLinkedList_Node*)AqvmBaseMemory_malloc(
sizeof(struct AqvmBaseLinkedList_Node));
if (insert_node == NULL) {
// TODO
Expand All @@ -140,7 +140,7 @@ int AqvmBaseLinkedList_PrependNode(struct AqvmBaseLinkedList_LinkedList* list,
}

struct AqvmBaseLinkedList_Node* new_node =
(struct AqvmBaseLinkedList_Node*)malloc(
(struct AqvmBaseLinkedList_Node*)AqvmBaseMemory_malloc(
sizeof(struct AqvmBaseLinkedList_Node));
if (new_node == NULL) {
// TODO
Expand Down
11 changes: 11 additions & 0 deletions aqvm/base/memory/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2024 AQ author, All Rights Reserved.
# This program is licensed under the AQ License. You can find the AQ license in
# the root directory.

cmake_minimum_required(VERSION 3.10)

include_directories(${PROJECT_SOURCE_DIR})

set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/memory.c)

add_library(AqvmBaseMemory STATIC ${SOURCES})
18 changes: 18 additions & 0 deletions aqvm/base/memory/memory.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2024 AQ author, All Rights Reserved.
// This program is licensed under the AQ License. You can find the AQ license in
// the root directory.

#include "aqvm/base/memory/memory.h"

#include <stddef.h>

void* AqvmBaseMemory_AqvmBaseMemory_malloc(size_t size) { return AqvmBaseMemory_malloc(size); }

int AqvmBaseMemory_free(void* ptr) {
if (ptr == NULL) {
// TODO
return -1;
}
free(ptr);
return 0;
}
14 changes: 14 additions & 0 deletions aqvm/base/memory/memory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2024 AQ author, All Rights Reserved.
// This program is licensed under the AQ License. You can find the AQ license in
// the root directory.

#ifndef AQ_AQVM_BASE_MEMORY_MEMORY_H_
#define AQ_AQVM_BASE_MEMORY_MEMORY_H_

#include <stddef.h>

void* AqvmBaseMemory_AqvmBaseMemory_malloc(size_t size);

int AqvmBaseMemory_free(void* ptr);

#endif
2 changes: 1 addition & 1 deletion aqvm/base/threading/file_lock/file_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int AqvmBaseThreadingFileLock_AddFileLock(struct AqvmBaseFile_File* file) {
file->lock = AqvmBaseThreadingFileLock_GetFileLock(file);
if (file->lock == NULL) {
struct AqvmBase_Pair* file_lock_pair =
(struct AqvmBase_Pair*)malloc(sizeof(struct AqvmBase_Pair));
(struct AqvmBase_Pair*)AqvmBaseMemory_malloc(sizeof(struct AqvmBase_Pair));
if (file_lock_pair == NULL) {
// TODO
return -2;
Expand Down
2 changes: 1 addition & 1 deletion aqvm/base/threading/mutex/mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AqvmBaseThreadingMutex_Mutex* AqvmBaseThreadingMutex_CreateMutex() {
return AqvmBaseThreadingMutexWindows_CreateMutex();
#else
// TODO(Threading): When Threading is developed, rewrite that code.
AqvmBaseThreadingMutex_Mutex* mutex = (AqvmBaseThreadingMutex_Mutex*)malloc(
AqvmBaseThreadingMutex_Mutex* mutex = (AqvmBaseThreadingMutex_Mutex*)AqvmBaseMemory_malloc(
sizeof(AqvmBaseThreadingMutex_Mutex));
if (mutex == NULL) {
// TODO
Expand Down
2 changes: 1 addition & 1 deletion aqvm/base/threading/mutex/unix/mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

AqvmBaseThreadingMutexUnix_Mutex *AqvmBaseThreadingMutexUnix_CreateMutex() {
AqvmBaseThreadingMutexUnix_Mutex *mutex =
(AqvmBaseThreadingMutexUnix_Mutex *)malloc(
(AqvmBaseThreadingMutexUnix_Mutex *)AqvmBaseMemory_malloc(
sizeof(AqvmBaseThreadingMutexUnix_Mutex));
if (mutex == NULL) {
// TODO
Expand Down
2 changes: 1 addition & 1 deletion aqvm/base/threading/mutex/windows/mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
AqvmBaseThreadingMutexWindows_Mutex*
AqvmBaseThreadingMutexWindows_CreateMutex() {
AqvmBaseThreadingMutexWindows_Mutex* mutex =
(AqvmBaseThreadingMutexWindows_Mutex*)malloc(
(AqvmBaseThreadingMutexWindows_Mutex*)AqvmBaseMemory_malloc(
sizeof(AqvmBaseThreadingMutexWindows_Mutex));
if (mutex == NULL) {
// TODO
Expand Down
2 changes: 1 addition & 1 deletion aqvm/memory/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct AqvmMemory_Memory* AqvmMemory_InitializeMemory(void* data, void* type,
"Memory initialization started.", NULL);

struct AqvmMemory_Memory* memory_ptr =
(struct AqvmMemory_Memory*)malloc(sizeof(struct AqvmMemory_Memory));
(struct AqvmMemory_Memory*)AqvmBaseMemory_malloc(sizeof(struct AqvmMemory_Memory));
if (memory_ptr == NULL) {
AqvmBaseLogging_OutputLog(
"ERROR", "AqvmMemory_InitializeMemory_MemoryAllocationFailure",
Expand Down

0 comments on commit 240447e

Please sign in to comment.