summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2014-06-05 11:15:29 +0100
committerDaniel Kolesa <d.kolesa@samsung.com>2014-06-10 15:48:53 +0100
commit39cdde7280498c599bb216a378a36b8ca9c91d84 (patch)
tree693be02b26d691d1d4a143c395627804593aae0a
parent5ee0d530ca90e259119fadb74985c9912edae1c5 (diff)
elua: prevent method calls on bad objects
-rw-r--r--src/bin/elua/modules/lualian.lua20
-rw-r--r--src/bindings/luajit/eo.lua7
2 files changed, 17 insertions, 10 deletions
diff --git a/src/bin/elua/modules/lualian.lua b/src/bin/elua/modules/lualian.lua
index 3874c11a2d..87748f1df2 100644
--- a/src/bin/elua/modules/lualian.lua
+++ b/src/bin/elua/modules/lualian.lua
@@ -212,7 +212,7 @@ local Method = Node:clone {
212 local proto = self:gen_proto() 212 local proto = self:gen_proto()
213 s:write(" ", proto.name, proto.suffix or "", " = function(", 213 s:write(" ", proto.name, proto.suffix or "", " = function(",
214 table.concat(proto.args, ", "), ")\n") 214 table.concat(proto.args, ", "), ")\n")
215 s:write( " self:__do_start()\n") 215 s:write( " self:__do_start(__class)\n")
216 for i, v in ipairs(proto.allocs) do 216 for i, v in ipairs(proto.allocs) do
217 s:write(" local ", v[2], " = ffi.new(\"", v[1], "[1]\")\n") 217 s:write(" local ", v[2], " = ffi.new(\"", v[1], "[1]\")\n")
218 end 218 end
@@ -389,8 +389,8 @@ local Constructor = Method:clone {
389 end 389 end
390 local genv = (proto.ret_type ~= "void") 390 local genv = (proto.ret_type ~= "void")
391 s:write(" ", genv and "local v = " or "", "self:__ctor_common(", 391 s:write(" ", genv and "local v = " or "", "self:__ctor_common(",
392 "__lib.", self.parent_node.prefix, "_class_get(), parent, __lib.", 392 "__class, parent, __lib.", proto.full_name, ", ",
393 proto.full_name, ", ", table.concat(proto.vargs, ", "), ")\n") 393 table.concat(proto.vargs, ", "), ")\n")
394 if not defctor then 394 if not defctor then
395 table.insert(proto.rets, 1, "self") 395 table.insert(proto.rets, 1, "self")
396 end 396 end
@@ -410,8 +410,7 @@ local Default_Constructor = Node:clone {
410 410
411 s:write( " __ctor = function(self, parent)\n") 411 s:write( " __ctor = function(self, parent)\n")
412 s:write(" self:__define_properties(self.__proto.__proto)\n") 412 s:write(" self:__define_properties(self.__proto.__proto)\n")
413 s:write(" self:__ctor_common(__lib.", self.parent_node.prefix, 413 s:write(" self:__ctor_common(__class, parent)\n")
414 "_class_get(), parent)\n")
415 s:write(" end", last and "" or ",", last and "\n" or "\n\n") 414 s:write(" end", last and "" or ",", last and "\n" or "\n\n")
416 end, 415 end,
417 416
@@ -448,8 +447,10 @@ local Mixin = Node:clone {
448 ename = self.klass:name_get() 447 ename = self.klass:name_get()
449 end 448 end
450 449
451 s:write(("M.%s = eo.class_register(\"%s\", {\n"):format( 450 s:write(([[
452 ename, self.klass:full_name_get())) 451local __class = __lib.%s_class_get()
452M.%s = eo.class_register("%s", {
453]]):format(self.prefix, ename, self.klass:full_name_get()))
453 454
454 self:gen_children(s) 455 self:gen_children(s)
455 456
@@ -508,9 +509,10 @@ local Class = Node:clone {
508 end 509 end
509 510
510 s:write(([[ 511 s:write(([[
511local Parent = eo.class_get("%s") 512local __class = __lib.%s_class_get()
513local Parent = eo.class_get("%s")
512M.%s = eo.class_register("%s", Parent:clone { 514M.%s = eo.class_register("%s", Parent:clone {
513]]):format(self.parent, ename, self.klass:full_name_get())) 515]]):format(self.prefix, self.parent, ename, self.klass:full_name_get()))
514 516
515 self:gen_children(s) 517 self:gen_children(s)
516 518
diff --git a/src/bindings/luajit/eo.lua b/src/bindings/luajit/eo.lua
index 2549cb31f2..f53418e06e 100644
--- a/src/bindings/luajit/eo.lua
+++ b/src/bindings/luajit/eo.lua
@@ -12,6 +12,8 @@ ffi.cdef [[
12 Eina_Bool eo_init(void); 12 Eina_Bool eo_init(void);
13 Eina_Bool eo_shutdown(void); 13 Eina_Bool eo_shutdown(void);
14 14
15 Eina_Bool eo_isa(const Eo *obj, const Eo_Class *klass);
16
15 void eo_constructor(void); 17 void eo_constructor(void);
16 void eo_destructor(void); 18 void eo_destructor(void);
17 19
@@ -92,7 +94,10 @@ M.Eo_Base = util.Object:clone {
92 return retval 94 return retval
93 end, 95 end,
94 96
95 __do_start = function(self) 97 __do_start = function(self, klass)
98 if eo.eo_isa(self.__obj, klass) == 0 then
99 error("method call on an invalid object", 3)
100 end
96 local info = getinfo(3, "nlSf") 101 local info = getinfo(3, "nlSf")
97 return eo._eo_do_start(self.__obj, nil, false, info.source, 102 return eo._eo_do_start(self.__obj, nil, false, info.source,
98 getfuncname(info), info.currentline) ~= 0 103 getfuncname(info), info.currentline) ~= 0