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/tools.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/tools.c')
-rw-r--r-- | src/tools.c | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/src/tools.c b/src/tools.c index 626da2b..5a6ae92 100644 --- a/src/tools.c +++ b/src/tools.c | |||
@@ -155,6 +155,20 @@ void luaG_dump( lua_State* L) | |||
155 | 155 | ||
156 | // ################################################################################################ | 156 | // ################################################################################################ |
157 | 157 | ||
158 | static void* libc_lua_Alloc(void* ud, void* ptr, size_t osize, size_t nsize) | ||
159 | { | ||
160 | (void)ud; (void)osize; /* not used */ | ||
161 | if (nsize == 0) | ||
162 | { | ||
163 | free(ptr); | ||
164 | return NULL; | ||
165 | } | ||
166 | else | ||
167 | { | ||
168 | return realloc(ptr, nsize); | ||
169 | } | ||
170 | } | ||
171 | |||
158 | static void* protected_lua_Alloc( void *ud, void *ptr, size_t osize, size_t nsize) | 172 | static void* protected_lua_Alloc( void *ud, void *ptr, size_t osize, size_t nsize) |
159 | { | 173 | { |
160 | void* p; | 174 | void* p; |
@@ -217,6 +231,22 @@ void initialize_allocator_function( Universe* U, lua_State* L) | |||
217 | U->protected_allocator.definition.allocF = lua_getallocf( L, &U->protected_allocator.definition.allocUD); | 231 | U->protected_allocator.definition.allocF = lua_getallocf( L, &U->protected_allocator.definition.allocUD); |
218 | } | 232 | } |
219 | lua_pop( L, 1); // settings | 233 | lua_pop( L, 1); // settings |
234 | STACK_MID(L, 0); | ||
235 | |||
236 | lua_getfield( L, -1, "internal_allocator"); // settings "libc"|"allocator" | ||
237 | { | ||
238 | char const* allocator = lua_tostring( L, -1); | ||
239 | if (stricmp(allocator, "libc") == 0) | ||
240 | { | ||
241 | U->internal_allocator.allocF = libc_lua_Alloc; | ||
242 | U->internal_allocator.allocUD = NULL; | ||
243 | } | ||
244 | else | ||
245 | { | ||
246 | U->internal_allocator = U->protected_allocator.definition; | ||
247 | } | ||
248 | } | ||
249 | lua_pop( L, 1); // settings | ||
220 | STACK_END( L, 0); | 250 | STACK_END( L, 0); |
221 | } | 251 | } |
222 | 252 | ||
@@ -1337,17 +1367,17 @@ static void copy_cached_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua | |||
1337 | 1367 | ||
1338 | if( lua_isnil( L2, -1)) // function is unknown | 1368 | if( lua_isnil( L2, -1)) // function is unknown |
1339 | { | 1369 | { |
1340 | lua_pop( L2, 1); // ... {cache} ... p | 1370 | lua_pop( L2, 1); // ... {cache} ... p |
1341 | 1371 | ||
1342 | // Set to 'true' for the duration of creation; need to find self-references | 1372 | // Set to 'true' for the duration of creation; need to find self-references |
1343 | // via upvalues | 1373 | // via upvalues |
1344 | // | 1374 | // |
1345 | // pushes a copy of the func, stores a reference in the cache | 1375 | // pushes a copy of the func, stores a reference in the cache |
1346 | copy_func( U, L2, L2_cache_i, L, i, mode_, upName_); // ... {cache} ... function | 1376 | copy_func( U, L2, L2_cache_i, L, i, mode_, upName_); // ... {cache} ... function |
1347 | } | 1377 | } |
1348 | else // found function in the cache | 1378 | else // found function in the cache |
1349 | { | 1379 | { |
1350 | lua_remove( L2, -2); // ... {cache} ... function | 1380 | lua_remove( L2, -2); // ... {cache} ... function |
1351 | } | 1381 | } |
1352 | STACK_END( L2, 1); | 1382 | STACK_END( L2, 1); |
1353 | ASSERT_L( lua_isfunction( L2, -1)); | 1383 | ASSERT_L( lua_isfunction( L2, -1)); |
@@ -1725,9 +1755,7 @@ static bool_t inter_copy_function( Universe* U, lua_State* L2, uint_t L2_cache_i | |||
1725 | { | 1755 | { |
1726 | DEBUGSPEW_CODE( fprintf( stderr, "FUNCTION %s\n", upName_)); | 1756 | DEBUGSPEW_CODE( fprintf( stderr, "FUNCTION %s\n", upName_)); |
1727 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | 1757 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); |
1728 | STACK_CHECK( L2, 0); | ||
1729 | copy_cached_func( U, L2, L2_cache_i, L, source_i_, mode_, upName_); // ... f | 1758 | copy_cached_func( U, L2, L2_cache_i, L, source_i_, mode_, upName_); // ... f |
1730 | STACK_END( L2, 1); | ||
1731 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); | 1759 | DEBUGSPEW_CODE( -- U->debugspew_indent_depth); |
1732 | } | 1760 | } |
1733 | STACK_END( L2, 1); | 1761 | STACK_END( L2, 1); |