Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1071)

Unified Diff: src/utils/SkLua.cpp

Issue 109793010: Prevent crash in Lua bindings. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkLua.cpp
===================================================================
--- src/utils/SkLua.cpp (revision 12703)
+++ src/utils/SkLua.cpp (working copy)
@@ -6,6 +6,7 @@
*/
#include "SkLua.h"
+#include "SkAnnotation.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkDocument.h"
@@ -31,6 +32,7 @@
return #T "_LuaMetaTableName"; \
}
+DEF_MTNAME(SkAnnotation)
DEF_MTNAME(SkCanvas)
DEF_MTNAME(SkDocument)
DEF_MTNAME(SkImage)
@@ -56,7 +58,7 @@
}
template <typename T> void push_ref(lua_State* L, T* ref) {
- *(T**)lua_newuserdata(L, sizeof(T*)) = SkRef(ref);
+ *(T**)lua_newuserdata(L, sizeof(T*)) = SkSafeRef(ref);
luaL_getmetatable(L, get_mtname<T>());
lua_setmetatable(L, -2);
}
@@ -635,6 +637,16 @@
return 0;
}
+static int lpaint_getAnnotation(lua_State* L) {
+ const SkPaint* paint = get_obj<SkPaint>(L, 1);
+ SkAnnotation* annotation = paint->getAnnotation();
+ if (annotation) {
+ push_ref(L, annotation);
+ return 1;
+ }
+ return 0;
+}
+
static int lpaint_gc(lua_State* L) {
get_obj<SkPaint>(L, 1)->~SkPaint();
return 0;
@@ -660,6 +672,7 @@
{ "getFontMetrics", lpaint_getFontMetrics },
{ "getEffects", lpaint_getEffects },
{ "getShader", lpaint_getShader },
+ { "getAnnotation", lpaint_getAnnotation },
{ "__gc", lpaint_gc },
{ NULL, NULL }
};
@@ -974,7 +987,7 @@
///////////////////////////////////////////////////////////////////////////////
static int ltypeface_gc(lua_State* L) {
- get_ref<SkTypeface>(L, 1)->unref();
+ SkSafeUnref(get_ref<SkTypeface>(L, 1));
reed1 2013/12/17 16:31:50 I believe you, but this just seems wrong. If we ha
return 0;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698