Skip to content

Instantly share code, notes, and snippets.

@nddrylliog
Last active July 29, 2021 18:24
Show Gist options
  • Save nddrylliog/8722197 to your computer and use it in GitHub Desktop.
Save nddrylliog/8722197 to your computer and use it in GitHub Desktop.
LuaJIT modifications needed to re-enable custom 64-bit allocators.
diff --git a/src/lib_aux.c b/src/lib_aux.c
index 05fa6b1..c618094 100644
--- a/src/lib_aux.c
+++ b/src/lib_aux.c
@@ -346,9 +346,11 @@ LUALIB_API lua_State *luaL_newstate(void)
#if LJ_64
LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud)
{
- UNUSED(f); UNUSED(ud);
- fputs("Must use luaL_newstate() for 64 bit target\n", stderr);
- return NULL;
+ /* Re-enable custom 64-bit allocators */
+ lua_State *L;
+ L = lj_state_newstate(f, ud);
+ if (L) G(L)->panic = panic;
+ return L;
}
#endif
@Qix-
Copy link

Qix- commented Jan 3, 2019

Old gist, I know - but I don't quite understand why they're using signed memory offsets. I understand that using signed types gives you trapability whereas unsigned will silently overflow, but that's a poor reason to use signed types for memory offsets, especially when it cuts out a widely used architecture.

Further, the mmap implementation they provide simply does not work on the three machines I tried it on. I have no idea how they got it to work elsewhere. It receives a failure code from the call to mmap() and it doesn't specify why it fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment