aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2022-02-21 10:43:55 +0100
committerBenoit Germain <bnt.germain@gmail.com>2022-02-21 10:43:55 +0100
commita147fa3aaf2a60252bd9cfd609ee7b65725d0ce8 (patch)
tree03f65c229adb05d60a4e676c641059a32ec89d42 /src
parent652cf51e8d7dbb280e50095c00bc9c672699903f (diff)
downloadlanes-a147fa3aaf2a60252bd9cfd609ee7b65725d0ce8.tar.gz
lanes-a147fa3aaf2a60252bd9cfd609ee7b65725d0ce8.tar.bz2
lanes-a147fa3aaf2a60252bd9cfd609ee7b65725d0ce8.zip
use malloc/free for keeper control structure when compiling for LuaJIT
Diffstat (limited to 'src')
-rw-r--r--src/keeper.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/keeper.c b/src/keeper.c
index eea017f..6b3a810 100644
--- a/src/keeper.c
+++ b/src/keeper.c
@@ -611,9 +611,15 @@ void close_keepers( Universe* U, lua_State* L)
611 } 611 }
612 // free the keeper bookkeeping structure 612 // free the keeper bookkeeping structure
613 { 613 {
614 void* allocUD; 614 // don't hijack the state allocator when running LuaJIT because it looks like LuaJIT does not expect it and might invalidate the memory unexpectedly
615 lua_Alloc allocF = lua_getallocf( L, &allocUD); 615#if LUAJIT_FLAVOR == 0
616 allocF( allocUD, U->keepers, sizeof( Keepers) + (nbKeepers - 1) * sizeof( Keeper), 0); 616 {
617 AllocatorDefinition* const allocD = &U->protected_allocator.definition;
618 allocD->allocF( allocUD, U->keepers, sizeof( Keepers) + (nbKeepers - 1) * sizeof( Keeper), 0);
619 }
620#else // LUAJIT_FLAVOR
621 free(U->keepers);
622#endif // LUAJIT_FLAVOR
617 U->keepers = NULL; 623 U->keepers = NULL;
618 } 624 }
619 } 625 }
@@ -634,8 +640,6 @@ void init_keepers( Universe* U, lua_State* L)
634{ 640{
635 int i; 641 int i;
636 int nb_keepers; 642 int nb_keepers;
637 void* allocUD;
638 lua_Alloc allocF = lua_getallocf( L, &allocUD);
639 643
640 STACK_CHECK( L, 0); // L K 644 STACK_CHECK( L, 0); // L K
641 lua_getfield( L, 1, "nb_keepers"); // nb_keepers 645 lua_getfield( L, 1, "nb_keepers"); // nb_keepers
@@ -649,7 +653,15 @@ void init_keepers( Universe* U, lua_State* L)
649 // Keepers contains an array of 1 s_Keeper, adjust for the actual number of keeper states 653 // Keepers contains an array of 1 s_Keeper, adjust for the actual number of keeper states
650 { 654 {
651 size_t const bytes = sizeof( Keepers) + (nb_keepers - 1) * sizeof( Keeper); 655 size_t const bytes = sizeof( Keepers) + (nb_keepers - 1) * sizeof( Keeper);
652 U->keepers = (Keepers*) allocF( allocUD, NULL, 0, bytes); 656 // don't hijack the state allocator when running LuaJIT because it looks like LuaJIT does not expect it and might invalidate the memory unexpectedly
657#if LUAJIT_FLAVOR == 0
658 {
659 AllocatorDefinition* const allocD = &U->protected_allocator.definition;
660 U->keepers = (Keepers*) allocD->allocF( allocUD, NULL, 0, bytes);
661 }
662#else // LUAJIT_FLAVOR
663 U->keepers = (Keepers*)malloc(bytes);
664#endif // LUAJIT_FLAVOR
653 if( U->keepers == NULL) 665 if( U->keepers == NULL)
654 { 666 {
655 (void) luaL_error( L, "init_keepers() failed while creating keeper array; out of memory"); 667 (void) luaL_error( L, "init_keepers() failed while creating keeper array; out of memory");