diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2022-02-07 14:51:54 +0100 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2022-02-07 14:51:54 +0100 |
commit | c913a6747c420ff12fc1f0c39df791215ad2fcfd (patch) | |
tree | 8175f6fa39e1ca22881c178a0c3cfde5f95fdeb5 /src/linda.c | |
parent | d5c81657982e96f768f76ea6c01db536f8649284 (diff) | |
download | lanes-c913a6747c420ff12fc1f0c39df791215ad2fcfd.tar.gz lanes-c913a6747c420ff12fc1f0c39df791215ad2fcfd.tar.bz2 lanes-c913a6747c420ff12fc1f0c39df791215ad2fcfd.zip |
removed explicit calls to malloc/free
Lane and linda userdata were allocated with malloc/free, preventing embedders from fully controlling memory operations. Now all internal Lanes allocations go through the master state alloc function.
Diffstat (limited to 'src/linda.c')
-rw-r--r-- | src/linda.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/linda.c b/src/linda.c index a9c9710..21b38fe 100644 --- a/src/linda.c +++ b/src/linda.c | |||
@@ -758,6 +758,9 @@ LUAG_FUNC( linda_towatch) | |||
758 | */ | 758 | */ |
759 | static void* linda_id( lua_State* L, DeepOp op_) | 759 | static void* linda_id( lua_State* L, DeepOp op_) |
760 | { | 760 | { |
761 | Universe* const U = universe_get(L); | ||
762 | AllocatorDefinition* const allocD = &U->protected_allocator.definition; | ||
763 | |||
761 | switch( op_) | 764 | switch( op_) |
762 | { | 765 | { |
763 | case eDO_new: | 766 | case eDO_new: |
@@ -794,7 +797,7 @@ static void* linda_id( lua_State* L, DeepOp op_) | |||
794 | * One can use any memory allocation scheme. | 797 | * One can use any memory allocation scheme. |
795 | * just don't use L's allocF because we don't know which state will get the honor of GCing the linda | 798 | * just don't use L's allocF because we don't know which state will get the honor of GCing the linda |
796 | */ | 799 | */ |
797 | s = (struct s_Linda*) malloc( sizeof(struct s_Linda) + name_len); // terminating 0 is already included | 800 | s = (struct s_Linda*) allocD->allocF( allocD->allocUD, NULL, 0, sizeof(struct s_Linda) + name_len); // terminating 0 is already included |
798 | if( s) | 801 | if( s) |
799 | { | 802 | { |
800 | s->prelude.magic.value = DEEP_VERSION.value; | 803 | s->prelude.magic.value = DEEP_VERSION.value; |
@@ -827,7 +830,7 @@ static void* linda_id( lua_State* L, DeepOp op_) | |||
827 | // There aren't any lanes waiting on these lindas, since all proxies have been gc'ed. Right? | 830 | // There aren't any lanes waiting on these lindas, since all proxies have been gc'ed. Right? |
828 | SIGNAL_FREE( &linda->read_happened); | 831 | SIGNAL_FREE( &linda->read_happened); |
829 | SIGNAL_FREE( &linda->write_happened); | 832 | SIGNAL_FREE( &linda->write_happened); |
830 | free( linda); | 833 | allocD->allocF( allocD->allocUD, linda, sizeof(struct s_Linda) + strlen(linda->name), 0); |
831 | return NULL; | 834 | return NULL; |
832 | } | 835 | } |
833 | 836 | ||