diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2023-08-09 12:15:54 +0200 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2023-08-09 12:15:54 +0200 |
commit | ad7258f68ce525845508fc0c4a329c282982ffa0 (patch) | |
tree | f6eb169911eef0a776f3b3b00eeb2b7d824ebbd7 /src/keeper.c | |
parent | d73f4cee37b0a43edadf9709289798ee4bfccc0e (diff) | |
download | lanes-ad7258f68ce525845508fc0c4a329c282982ffa0.tar.gz lanes-ad7258f68ce525845508fc0c4a329c282982ffa0.tar.bz2 lanes-ad7258f68ce525845508fc0c4a329c282982ffa0.zip |
new .internal_allocator configuration IUNTESTED)
new configuration option .internal_allocator to help LuaJIT users. THIS IS YET UNTESTED, USE AT YOUR OWN RISKS.
Diffstat (limited to 'src/keeper.c')
-rw-r--r-- | src/keeper.c | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/src/keeper.c b/src/keeper.c index 19b9e1a..f4dde0a 100644 --- a/src/keeper.c +++ b/src/keeper.c | |||
@@ -580,7 +580,7 @@ int keepercall_count( lua_State* L) | |||
580 | */ | 580 | */ |
581 | 581 | ||
582 | // called as __gc for the keepers array userdata | 582 | // called as __gc for the keepers array userdata |
583 | void close_keepers( Universe* U, lua_State* L) | 583 | void close_keepers( Universe* U) |
584 | { | 584 | { |
585 | if( U->keepers != NULL) | 585 | if( U->keepers != NULL) |
586 | { | 586 | { |
@@ -611,15 +611,8 @@ 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 | // don't hijack the state allocator when running LuaJIT because it looks like LuaJIT does not expect it and might invalidate the memory unexpectedly | 614 | AllocatorDefinition* const allocD = &U->internal_allocator; |
615 | #if USE_LUA_STATE_ALLOCATOR() | 615 | allocD->allocF( allocD->allocUD, U->keepers, sizeof( Keepers) + (nbKeepers - 1) * sizeof( Keeper), 0); |
616 | { | ||
617 | AllocatorDefinition* const allocD = &U->protected_allocator.definition; | ||
618 | allocD->allocF( allocD->allocUD, U->keepers, sizeof( Keepers) + (nbKeepers - 1) * sizeof( Keeper), 0); | ||
619 | } | ||
620 | #else // USE_LUA_STATE_ALLOCATOR() | ||
621 | free(U->keepers); | ||
622 | #endif // USE_LUA_STATE_ALLOCATOR() | ||
623 | U->keepers = NULL; | 616 | U->keepers = NULL; |
624 | } | 617 | } |
625 | } | 618 | } |
@@ -653,15 +646,10 @@ void init_keepers( Universe* U, lua_State* L) | |||
653 | // Keepers contains an array of 1 s_Keeper, adjust for the actual number of keeper states | 646 | // Keepers contains an array of 1 s_Keeper, adjust for the actual number of keeper states |
654 | { | 647 | { |
655 | size_t const bytes = sizeof( Keepers) + (nb_keepers - 1) * sizeof( Keeper); | 648 | size_t const bytes = sizeof( Keepers) + (nb_keepers - 1) * sizeof( Keeper); |
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 USE_LUA_STATE_ALLOCATOR() | ||
658 | { | 649 | { |
659 | AllocatorDefinition* const allocD = &U->protected_allocator.definition; | 650 | AllocatorDefinition* const allocD = &U->internal_allocator; |
660 | U->keepers = (Keepers*) allocD->allocF( allocD->allocUD, NULL, 0, bytes); | 651 | U->keepers = (Keepers*) allocD->allocF( allocD->allocUD, NULL, 0, bytes); |
661 | } | 652 | } |
662 | #else // USE_LUA_STATE_ALLOCATOR() | ||
663 | U->keepers = (Keepers*)malloc(bytes); | ||
664 | #endif // USE_LUA_STATE_ALLOCATOR() | ||
665 | if( U->keepers == NULL) | 653 | if( U->keepers == NULL) |
666 | { | 654 | { |
667 | (void) luaL_error( L, "init_keepers() failed while creating keeper array; out of memory"); | 655 | (void) luaL_error( L, "init_keepers() failed while creating keeper array; out of memory"); |