Skip to content

Commit

Permalink
feat: added two helper functions that call std::malloc and std::free …
Browse files Browse the repository at this point in the history
…respectively. In the event of an error they behave in a manner compliant with Argon's memory management
  • Loading branch information
jacopodl committed Jul 11, 2024
1 parent 8ce6de1 commit 7d6946a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
22 changes: 21 additions & 1 deletion argon/vm/memory/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,24 @@ void *argon::vm::memory::Realloc(void *ptr, size_t size) {
Panic((datatype::ArObject *) datatype::error_oom);

return mem;
}
}

// MALLOC WRAPPER

void *argon::vm::memory::Copy2Malloc(void *src, size_t size) {
auto *buf = WMalloc(size);

if(buf!= nullptr)
argon::vm::memory::MemoryCopy(buf, src, size);

return buf;
}

void *argon::vm::memory::WMalloc(size_t size) {
void *ptr = malloc(size);

if(ptr == nullptr)
Panic((datatype::ArObject *) datatype::error_oom);

return ptr;
}
8 changes: 8 additions & 0 deletions argon/vm/memory/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ namespace argon::vm::memory {
void *Realloc(void *ptr, size_t size);

void Free(void *ptr);

// MALLOC WRAPPER

void *Copy2Malloc(void *src, size_t size);

void *WMalloc(size_t size);

const auto WFree= free;
}

#endif // !ARGON_VM_MEMORY_MEMORY_H_

0 comments on commit 7d6946a

Please sign in to comment.