diff runtime.c @ 22:988a8998c75f

JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
author Atul Varma <varmaa@toolness.com>
date Sun, 28 Jun 2009 21:49:07 -0700
parents fbb9a61fa030
children 951ad1b15587
line wrap: on
line diff
--- a/runtime.c	Sun Jun 28 20:40:18 2009 -0700
+++ b/runtime.c	Sun Jun 28 21:49:07 2009 -0700
@@ -10,12 +10,22 @@
 
   self = (PYM_JSRuntimeObject *) type->tp_alloc(type, 0);
   if (self != NULL) {
-    self->rt = JS_NewRuntime(8L * 1024L * 1024L);
-    if (!self->rt) {
-      PyErr_SetString(PYM_error, "JS_NewRuntime() failed");
+    self->rt = NULL;
+
+    self->objects = PyDict_New();
+    if (self->objects == NULL) {
       type->tp_dealloc((PyObject *) self);
       self = NULL;
     }
+
+    if (self != NULL) {
+      self->rt = JS_NewRuntime(8L * 1024L * 1024L);
+      if (!self->rt) {
+        PyErr_SetString(PYM_error, "JS_NewRuntime() failed");
+        type->tp_dealloc((PyObject *) self);
+        self = NULL;
+      }
+    }
   }
 
   return (PyObject *) self;
@@ -24,6 +34,11 @@
 static void
 PYM_JSRuntimeDealloc(PYM_JSRuntimeObject *self)
 {
+  if (self->objects) {
+    Py_DECREF(self->objects);
+    self->objects = NULL;
+  }
+
   if (self->rt) {
     JS_DestroyRuntime(self->rt);
     self->rt = NULL;