# HG changeset patch # User Atul Varma # Date 1246239583 25200 # Node ID baa4cb9613302d2197e33888ef1e8f0126989242 # Parent 9edcdb4ab12dd9df54f2b96e7d6e36d151f21155 JS objects in python-land are now rooted while in python-land so that they're not gc'd while in python-land. diff -r 9edcdb4ab12d -r baa4cb961330 context.c --- a/context.c Sun Jun 28 18:28:35 2009 -0700 +++ b/context.c Sun Jun 28 18:39:43 2009 -0700 @@ -31,6 +31,9 @@ if (object == NULL) return NULL; + object->runtime = self->runtime; + Py_INCREF(object->runtime); + object->obj = JS_NewObject(self->cx, &PYM_JS_ObjectClass, NULL, NULL); if (object->obj == NULL) { PyErr_SetString(PYM_error, "JS_NewObject() failed"); @@ -38,6 +41,9 @@ return NULL; } + JS_AddNamedRootRT(object->runtime->rt, &object->obj, + "Pymonkey-Generated Object"); + return (PyObject *) object; } diff -r 9edcdb4ab12d -r baa4cb961330 object.c --- a/object.c Sun Jun 28 18:28:35 2009 -0700 +++ b/object.c Sun Jun 28 18:39:43 2009 -0700 @@ -13,8 +13,13 @@ // JS_RemoveRoot() always returns JS_TRUE, so don't // bother checking its return value. - // Umm, we need a context... Crap. - //JS_RemoveRoot( + if (self->obj) { + JS_RemoveRootRT(self->runtime->rt, &self->obj); + self->obj = NULL; + } + + Py_DECREF(self->runtime); + self->runtime = NULL; } PyTypeObject PYM_JSObjectType = {