changeset 15:baa4cb961330

JS objects in python-land are now rooted while in python-land so that they're not gc'd while in python-land.
author Atul Varma <varmaa@toolness.com>
date Sun, 28 Jun 2009 18:39:43 -0700
parents 9edcdb4ab12d
children 532b7ddca616
files context.c object.c
diffstat 2 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }
 
--- 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 = {