diff options
| author | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-06-09 18:56:19 +0330 |
|---|---|---|
| committer | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-06-09 18:56:19 +0330 |
| commit | 8dc246166a007c2815f93ff6db535a660b05431c (patch) | |
| tree | a3747464019316434103fe757a83fbdd990f16ce /code/lib/memory.felan | |
| parent | 03e9e1708eada3985529949302f214a223a297c2 (diff) | |
fix assigning to dereference access in a chain
Diffstat (limited to 'code/lib/memory.felan')
| -rw-r--r-- | code/lib/memory.felan | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/code/lib/memory.felan b/code/lib/memory.felan index 55451c5..2710685 100644 --- a/code/lib/memory.felan +++ b/code/lib/memory.felan @@ -2,12 +2,23 @@ libc :: @c_library("/usr/lib/libc.so.6"); malloc :: @c_function(libc,"malloc",(i64)->(*void)); +realloc :: @c_function(libc,"realloc",(*void,i64)->(*void)); free :: @c_function(libc,"free",(*void)->void); malloc :: (size:i64,comptime t:type) -> (*t) { return @cast(malloc(size*@cast(@size_of(t),i64)),*t); }; +realloc :: (ptr:*anytype,size:u64) -> (@type_of(ptr)) { + return @cast( + realloc( + @cast(ptr,*void), + @cast(size*@size_of(@type_of(ptr.*)),i64), + ), + @type_of(ptr) + ); +}; + free :: (ptr:*anytype) -> void { free(@cast(ptr,*void)); }; |