diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2022-02-17 16:30:36 +0100 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2022-02-17 16:30:36 +0100 |
commit | c2f88350772c01631ea3b7d60e56cea335c458b7 (patch) | |
tree | b4fcc4bebb094190b0dc13561ab24c1593da86f7 /src/lanes.c | |
parent | 2c0000d5169cacf950d06637ada1a371cf382896 (diff) | |
download | lanes-c2f88350772c01631ea3b7d60e56cea335c458b7.tar.gz lanes-c2f88350772c01631ea3b7d60e56cea335c458b7.tar.bz2 lanes-c2f88350772c01631ea3b7d60e56cea335c458b7.zip |
NEVER use allocator obtained from lua_getallocf to allocate stuff manually when compiling for LuaJIT
Diffstat (limited to 'src/lanes.c')
-rw-r--r-- | src/lanes.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/lanes.c b/src/lanes.c index 8817071..bf0f0a3 100644 --- a/src/lanes.c +++ b/src/lanes.c | |||
@@ -238,7 +238,6 @@ static bool_t tracking_remove( Lane* s) | |||
238 | 238 | ||
239 | static void lane_cleanup( Lane* s) | 239 | static void lane_cleanup( Lane* s) |
240 | { | 240 | { |
241 | AllocatorDefinition* const allocD = &s->U->protected_allocator.definition; | ||
242 | // Clean up after a (finished) thread | 241 | // Clean up after a (finished) thread |
243 | // | 242 | // |
244 | #if THREADWAIT_METHOD == THREADWAIT_CONDVAR | 243 | #if THREADWAIT_METHOD == THREADWAIT_CONDVAR |
@@ -254,7 +253,15 @@ static void lane_cleanup( Lane* s) | |||
254 | } | 253 | } |
255 | #endif // HAVE_LANE_TRACKING | 254 | #endif // HAVE_LANE_TRACKING |
256 | 255 | ||
257 | allocD->allocF(allocD->allocUD, s, sizeof(Lane), 0); | 256 | // don't hijack the state allocator when running LuaJIT because it looks like LuaJIT does not expect it and might invalidate the memory unexpectedly |
257 | #if LUAJIT_FLAVOR == 0 | ||
258 | { | ||
259 | AllocatorDefinition* const allocD = &s->U->protected_allocator.definition; | ||
260 | allocD->allocF(allocD->allocUD, s, sizeof(Lane), 0); | ||
261 | } | ||
262 | #else // LUAJIT_FLAVOR | ||
263 | free(s); | ||
264 | #endif // LUAJIT_FLAVOR | ||
258 | } | 265 | } |
259 | 266 | ||
260 | /* | 267 | /* |
@@ -1054,7 +1061,6 @@ LUAG_FUNC( lane_new) | |||
1054 | #define FIXED_ARGS 7 | 1061 | #define FIXED_ARGS 7 |
1055 | int const nargs = lua_gettop(L) - FIXED_ARGS; | 1062 | int const nargs = lua_gettop(L) - FIXED_ARGS; |
1056 | Universe* U = universe_get( L); | 1063 | Universe* U = universe_get( L); |
1057 | AllocatorDefinition* const allocD = &U->protected_allocator.definition; | ||
1058 | ASSERT_L( nargs >= 0); | 1064 | ASSERT_L( nargs >= 0); |
1059 | 1065 | ||
1060 | // public Lanes API accepts a generic range -3/+3 | 1066 | // public Lanes API accepts a generic range -3/+3 |
@@ -1224,7 +1230,15 @@ LUAG_FUNC( lane_new) | |||
1224 | // | 1230 | // |
1225 | // a Lane full userdata needs a single uservalue | 1231 | // a Lane full userdata needs a single uservalue |
1226 | ud = lua_newuserdatauv( L, sizeof( Lane*), 1); // func libs priority globals package required gc_cb lane | 1232 | ud = lua_newuserdatauv( L, sizeof( Lane*), 1); // func libs priority globals package required gc_cb lane |
1227 | s = *ud = (Lane*) allocD->allocF( allocD->allocUD, NULL, 0, sizeof(Lane)); | 1233 | // don't hijack the state allocator when running LuaJIT because it looks like LuaJIT does not expect it and might invalidate the memory unexpectedly |
1234 | #if LUAJIT_FLAVOR == 0 | ||
1235 | { | ||
1236 | AllocatorDefinition* const allocD = &U->protected_allocator.definition; | ||
1237 | s = *ud = (Lane*)allocD->allocF(allocD->allocUD, NULL, 0, sizeof(Lane)); | ||
1238 | } | ||
1239 | #else // LUAJIT_FLAVOR | ||
1240 | s = *ud = (Lane*) malloc(sizeof(Lane)); | ||
1241 | #endif // LUAJIT_FLAVOR | ||
1228 | if( s == NULL) | 1242 | if( s == NULL) |
1229 | { | 1243 | { |
1230 | return luaL_error( L, "could not create lane: out of memory"); | 1244 | return luaL_error( L, "could not create lane: out of memory"); |