forked from enlightenment/efl
elua - use safeptr with lightuserdata to work around luajit 64bit issue
luajit only supports 47bits on 64bit for lightuser data (bad! don't mess with opaque pointers... really unexpected and bad and probably should be fixed in luajit by doing things like on 32bit where pointers are not messed with etc.)
This commit is contained in:
parent
e0f4455eaa
commit
6587613a58
|
@ -70,6 +70,7 @@ EAPI Elua_State *
|
|||
elua_state_new(const char *progname)
|
||||
{
|
||||
Elua_State *ret = NULL;
|
||||
Eina_Safepointer *sp;
|
||||
lua_State *L = luaL_newstate();
|
||||
if (!L)
|
||||
return NULL;
|
||||
|
@ -77,7 +78,9 @@ elua_state_new(const char *progname)
|
|||
ret->luastate = L;
|
||||
if (progname) ret->progname = eina_stringshare_add(progname);
|
||||
luaL_openlibs(L);
|
||||
lua_pushlightuserdata(L, ret);
|
||||
sp = (Eina_Safepointer *)eina_safepointer_register(ret);
|
||||
ret->sp = sp;
|
||||
lua_pushlightuserdata(L, sp);
|
||||
lua_setfield(L, LUA_REGISTRYINDEX, "elua_ptr");
|
||||
return ret;
|
||||
}
|
||||
|
@ -106,6 +109,7 @@ elua_state_free(Elua_State *es)
|
|||
eina_stringshare_del(es->coredir);
|
||||
eina_stringshare_del(es->moddir);
|
||||
eina_stringshare_del(es->appsdir);
|
||||
eina_safepointer_unregister(es->sp);
|
||||
free(es);
|
||||
}
|
||||
|
||||
|
@ -260,7 +264,8 @@ elua_state_from_lua_state_get(lua_State *L)
|
|||
lua_getfield(L, LUA_REGISTRYINDEX, "elua_ptr");
|
||||
if (!lua_isnil(L, -1))
|
||||
{
|
||||
void *st = lua_touserdata(L, -1);
|
||||
Eina_Safepointer *sp = lua_touserdata(L, -1);
|
||||
void *st = eina_safepointer_get(sp);
|
||||
lua_pop(L, 1);
|
||||
return (Elua_State *)st;
|
||||
}
|
||||
|
@ -360,17 +365,16 @@ const luaL_Reg gettextlib[] =
|
|||
{ "bind_textdomain", _elua_gettext_bind_textdomain },
|
||||
{ "get_message_language", _elua_get_message_language },
|
||||
{ "get_localeconv", _elua_get_localeconv },
|
||||
#ifdef ENABLE_NLS
|
||||
{ "dgettext", dgettext },
|
||||
{ "dgettext", dngettext },
|
||||
#endif
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static Eina_Bool
|
||||
_elua_state_i18n_setup(const Elua_State *es)
|
||||
_elua_state_i18n_setup(Elua_State *es)
|
||||
{
|
||||
#ifdef ENABLE_NLS
|
||||
char *(*dgettextp)(const char*, const char*) = dgettext;
|
||||
char *(*dngettextp)(const char*, const char*, const char*, unsigned long)
|
||||
= dngettext;
|
||||
#endif
|
||||
char buf[PATH_MAX];
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(es, EINA_FALSE);
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(es->coredir, EINA_FALSE);
|
||||
|
@ -380,12 +384,6 @@ _elua_state_i18n_setup(const Elua_State *es)
|
|||
return EINA_FALSE;
|
||||
lua_createtable(es->luastate, 0, 0);
|
||||
luaL_register(es->luastate, NULL, gettextlib);
|
||||
#ifdef ENABLE_NLS
|
||||
lua_pushlightuserdata(es->luastate, *((void**)&dgettextp));
|
||||
lua_setfield(es->luastate, -2, "dgettext");
|
||||
lua_pushlightuserdata(es->luastate, *((void**)&dngettextp));
|
||||
lua_setfield(es->luastate, -2, "dngettext");
|
||||
#endif
|
||||
lua_call(es->luastate, 1, 0);
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ struct _Elua_State
|
|||
Eina_List *lmods;
|
||||
Eina_List *cmods;
|
||||
Eina_List *lincs;
|
||||
Eina_Safepointer *sp;
|
||||
int requireref, apploadref;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue