diff --git a/src/pre_generated-zmq.nobj.c b/src/pre_generated-zmq.nobj.c index b78fc59..970605c 100644 --- a/src/pre_generated-zmq.nobj.c +++ b/src/pre_generated-zmq.nobj.c @@ -195,10 +195,10 @@ typedef struct obj_udata { } obj_udata; /* use static pointer as key to weak userdata table. */ -static char *obj_udata_weak_ref_key = "obj_udata_weak_ref_key"; +static char obj_udata_weak_ref_key[] = "obj_udata_weak_ref_key"; /* use static pointer as key to module's private table. */ -static char *obj_udata_private_key = "obj_udata_private_key"; +static char obj_udata_private_key[] = "obj_udata_private_key"; #if LUAJIT_FFI typedef struct ffi_export_symbol { @@ -932,6 +932,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "local tonumber = tonumber\n" "local tostring = tostring\n" "local rawset = rawset\n" +"local setmetatable = setmetatable\n" "local p_config = package.config\n" "local p_cpath = package.cpath\n" "\n" @@ -954,16 +955,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "\n" "local _M, _priv, udata_new = ...\n" "\n" -"local band = bit.band\n" -"local d_getmetatable = debug.getmetatable\n" -"local d_setmetatable = debug.setmetatable\n" -"\n" "local OBJ_UDATA_FLAG_OWN = 1\n" -"local OBJ_UDATA_FLAG_LOOKUP = 2\n" -"local OBJ_UDATA_LAST_FLAG = OBJ_UDATA_FLAG_LOOKUP\n" -"\n" -"local OBJ_TYPE_FLAG_WEAK_REF = 1\n" -"local OBJ_TYPE_SIMPLE = 2\n" "\n" "local function ffi_safe_cdef(block_name, cdefs)\n" " local fake_type = \"struct sentinel_\" .. block_name .. \"_ty\"\n" @@ -1005,154 +997,6 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "\n" "]])\n" "\n" -"-- cache mapping of cdata to userdata\n" -"local weak_objects = setmetatable({}, { __mode = \"v\" })\n" -"\n" -"local function obj_udata_luacheck_internal(obj, type_mt, not_delete)\n" -" local obj_mt = d_getmetatable(obj)\n" -" if obj_mt == type_mt then\n" -" -- convert userdata to cdata.\n" -" return ffi.cast(\"obj_udata *\", obj)\n" -" end\n" -" if not_delete then\n" -" error(\"(expected `\" .. type_mt['.name'] .. \"`, got \" .. type(obj) .. \")\", 3)\n" -" end\n" -"end\n" -"\n" -"local function obj_udata_luacheck(obj, type_mt)\n" -" local ud = obj_udata_luacheck_internal(obj, type_mt, true)\n" -" return ud.obj\n" -"end\n" -"\n" -"local function obj_udata_to_cdata(objects, ud_obj, c_type, ud_mt)\n" -" -- convert userdata to cdata.\n" -" local c_obj = ffi.cast(c_type, obj_udata_luacheck(ud_obj, ud_mt))\n" -" -- cache converted cdata\n" -" rawset(objects, ud_obj, c_obj)\n" -" return c_obj\n" -"end\n" -"\n" -"local function obj_udata_luadelete(ud_obj, type_mt)\n" -" local ud = obj_udata_luacheck_internal(ud_obj, type_mt, false)\n" -" if not ud then return nil, 0 end\n" -" local obj, flags = ud.obj, ud.flags\n" -" -- null userdata.\n" -" ud.obj = nil\n" -" ud.flags = 0\n" -" -- invalid userdata, by setting the metatable to nil.\n" -" d_setmetatable(ud_obj, nil)\n" -" return obj, flags\n" -"end\n" -"\n" -"local function obj_udata_luapush(obj, type_mt, obj_type, flags)\n" -" if obj == nil then return end\n" -"\n" -" -- apply type's dynamic caster.\n" -" if obj_type.dcaster ~= nil then\n" -" local obj_ptr = ffi.new(\"void *[1]\", obj)\n" -" local type_ptr = ffi.new(\"obj_type *[1]\", obj_type)\n" -" obj_type.dcaster(obj_ptr, type_ptr)\n" -" obj = obj_ptr[1]\n" -" type = type_ptr[1]\n" -" end\n" -"\n" -" -- create new userdata\n" -" local ud_obj = udata_new(ffi.sizeof\"obj_udata\", type_mt)\n" -" local ud = ffi.cast(\"obj_udata *\", ud_obj)\n" -" -- init. object\n" -" ud.obj = obj\n" -" ud.flags = flags\n" -"\n" -" return ud_obj\n" -"end\n" -"\n" -"local function obj_udata_luadelete_weak(ud_obj, type_mt)\n" -" local ud = obj_udata_luacheck_internal(ud_obj, type_mt, false)\n" -" if not ud then return nil, 0 end\n" -" local obj, flags = ud.obj, ud.flags\n" -" -- null userdata.\n" -" ud.obj = nil\n" -" ud.flags = 0\n" -" -- invalid userdata, by setting the metatable to nil.\n" -" d_setmetatable(ud_obj, nil)\n" -" -- remove object from weak ref. table.\n" -" local obj_key = tonumber(ffi.cast('uintptr_t', obj))\n" -" weak_objects[obj_key] = nil\n" -" return obj, flags\n" -"end\n" -"\n" -"local function obj_udata_luapush_weak(obj, type_mt, obj_type, flags)\n" -" if obj == nil then return end\n" -"\n" -" -- apply type's dynamic caster.\n" -" if obj_type.dcaster ~= nil then\n" -" local obj_ptr = ffi.new(\"void *[1]\", obj)\n" -" local type_ptr = ffi.new(\"obj_type *[1]\", obj_type)\n" -" obj_type.dcaster(obj_ptr, type_ptr)\n" -" obj = obj_ptr[1]\n" -" type = type_ptr[1]\n" -" end\n" -"\n" -" -- lookup object in weak ref. table.\n" -" local obj_key = tonumber(ffi.cast('uintptr_t', obj))\n" -" local ud_obj = weak_objects[obj_key]\n" -" if ud_obj ~= nil then return ud_obj end\n" -"\n" -" -- create new userdata\n" -" ud_obj = udata_new(ffi.sizeof\"obj_udata\", type_mt)\n" -" local ud = ffi.cast(\"obj_udata *\", ud_obj)\n" -" -- init. object\n" -" ud.obj = obj\n" -" ud.flags = flags\n" -"\n" -" -- cache weak reference to object.\n" -" weak_objects[obj_key] = ud_obj\n" -"\n" -" return ud_obj\n" -"end\n" -"\n" -"local function obj_simple_udata_luacheck(ud_obj, type_mt)\n" -" local obj_mt = d_getmetatable(ud_obj)\n" -" if obj_mt == type_mt then\n" -" -- convert userdata to cdata.\n" -" return ffi.cast(\"void *\", ud_obj)\n" -" end\n" -" error(\"(expected `\" .. type_mt['.name'] .. \"`, got \" .. type(ud_obj) .. \")\", 3)\n" -"end\n" -"\n" -"local function obj_simple_udata_to_cdata(objects, ud_obj, c_type, ud_mt)\n" -" -- convert userdata to cdata.\n" -" local c_obj = ffi.cast(c_type, obj_simple_udata_luacheck(ud_obj, ud_mt))[0]\n" -" -- cache converted cdata\n" -" rawset(objects, ud_obj, c_obj)\n" -" return c_obj\n" -"end\n" -"\n" -"local function obj_embed_udata_to_cdata(objects, ud_obj, c_type, ud_mt)\n" -" -- convert userdata to cdata.\n" -" local c_obj = ffi.cast(c_type, obj_simple_udata_luacheck(ud_obj, ud_mt))\n" -" -- cache converted cdata\n" -" rawset(objects, ud_obj, c_obj)\n" -" return c_obj\n" -"end\n" -"\n" -"local function obj_simple_udata_luadelete(ud_obj, type_mt)\n" -" -- invalid userdata, by setting the metatable to nil.\n" -" d_setmetatable(ud_obj, nil)\n" -"end\n" -"\n" -"local function obj_simple_udata_luapush(c_obj, size, type_mt)\n" -" if c_obj == nil then return end\n" -"\n" -" -- create new userdata\n" -" local ud_obj = udata_new(size, type_mt)\n" -" local cdata = ffi.cast(\"void *\", ud_obj)\n" -" -- init. object\n" -" ffi.copy(cdata, c_obj, size)\n" -"\n" -" return ud_obj, cdata\n" -"end\n" -"\n" "local function obj_ptr_to_id(ptr)\n" " return tonumber(ffi.cast('uintptr_t', ptr))\n" "end\n" @@ -1164,7 +1008,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "local function register_default_constructor(_pub, obj_name, constructor)\n" " local pub_constructor = _pub[obj_name]\n" " if type(pub_constructor) == 'table' then\n" -" d_setmetatable(pub_constructor, { __call = function(t,...)\n" +" setmetatable(pub_constructor, { __call = function(t,...)\n" " return constructor(...)\n" " end,\n" " __metatable = false,\n" @@ -1282,6 +1126,13 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "end\n" "_pub.zmq = _M\n" "for obj_name,pub in pairs(_M) do\n" +" if type(pub) == 'table' then\n" +" local new_pub = {}\n" +" for k,v in pairs(pub) do\n" +" new_pub[k] = v\n" +" end\n" +" pub = new_pub\n" +" end\n" " _pub[obj_name] = pub\n" "end\n" "\n" @@ -1346,7 +1197,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " function obj_type_ZMQ_Socket_delete(ptr)\n" " local id = obj_ptr_to_id(ptr)\n" " local flags = obj_flags[id]\n" -" if not flags then return ptr, 0 end\n" +" if not flags then return nil, 0 end\n" " ffi.gc(ptr, nil)\n" " obj_flags[id] = nil\n" " return ptr, flags\n" @@ -1433,7 +1284,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " function obj_type_ZMQ_Ctx_delete(ptr)\n" " local id = obj_ptr_to_id(ptr)\n" " local flags = obj_flags[id]\n" -" if not flags then return ptr, 0 end\n" +" if not flags then return nil, 0 end\n" " ffi.gc(ptr, nil)\n" " obj_flags[id] = nil\n" " return ptr, flags\n" @@ -1482,7 +1333,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " function obj_type_ZMQ_StopWatch_delete(ptr)\n" " local id = obj_ptr_to_id(ptr)\n" " local flags = obj_flags[id]\n" -" if not flags then return ptr, 0 end\n" +" if not flags then return nil, 0 end\n" " ffi.gc(ptr, nil)\n" " obj_flags[id] = nil\n" " return ptr, flags\n" @@ -1694,8 +1545,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "-- Start \"ZMQ_Socket\" FFI interface\n" "-- method: close\n" "function _meth.ZMQ_Socket.close(self)\n" -" local self,this_flags1 = obj_type_ZMQ_Socket_delete(self)\n" -" if(band(this_flags1,OBJ_UDATA_FLAG_OWN) == 0) then return end\n" +" local self, free,this_flags1=obj_type_ZMQ_Socket_delete(self)\n" +" if not self then return end\n" " local rc_zmq_close1\n" " rc_zmq_close1 = C.zmq_close(self)\n" " -- check for error.\n" @@ -2111,8 +1962,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "-- Start \"ZMQ_Ctx\" FFI interface\n" "-- method: term\n" "function _meth.ZMQ_Ctx.term(self)\n" -" local self,this_flags1 = obj_type_ZMQ_Ctx_delete(self)\n" -" if(band(this_flags1,OBJ_UDATA_FLAG_OWN) == 0) then return end\n" +" local self, free,this_flags1=obj_type_ZMQ_Ctx_delete(self)\n" +" if not self then return end\n" " local rc_zmq_term1\n" " rc_zmq_term1 = C.zmq_term(self)\n" " -- check for error.\n" @@ -2160,8 +2011,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "register_default_constructor(_pub,\"ZMQ_StopWatch\",_pub.ZMQ_StopWatch.start)\n" "-- method: stop\n" "function _meth.ZMQ_StopWatch.stop(self)\n" -" local self,this_flags1 = obj_type_ZMQ_StopWatch_delete(self)\n" -" if(band(this_flags1,OBJ_UDATA_FLAG_OWN) == 0) then return end\n" +" local self, free,this_flags1=obj_type_ZMQ_StopWatch_delete(self)\n" +" if not self then return end\n" " local usecs1\n" " usecs1 = C.zmq_stopwatch_stop(self)\n" " usecs1 = tonumber(usecs1)\n"