diff src/runtime.cpp @ 129:7b7a23615873

Added weakref support for runtimes.
author Atul Varma <varmaa@toolness.com>
date Sun, 23 Aug 2009 17:52:47 -0700
parents ac8ca0ee7760
children f956a6dea16c
line wrap: on
line diff
--- a/src/runtime.cpp	Sun Aug 23 17:39:28 2009 -0700
+++ b/src/runtime.cpp	Sun Aug 23 17:52:47 2009 -0700
@@ -46,6 +46,7 @@
 
   self = (PYM_JSRuntimeObject *) type->tp_alloc(type, 0);
   if (self != NULL) {
+    self->weakrefs = NULL;
     self->thread = PyThread_get_thread_ident();
     self->rt = NULL;
     self->cx = NULL;
@@ -84,6 +85,9 @@
 static void
 PYM_JSRuntimeDealloc(PYM_JSRuntimeObject *self)
 {
+  if (self->weakrefs)
+    PyObject_ClearWeakRefs((PyObject *) self);
+
   if (self->objects.ops) {
     JS_DHashTableFinish(&self->objects);
     self->objects.ops = NULL;
@@ -154,13 +158,15 @@
   0,                           /*tp_getattro*/
   0,                           /*tp_setattro*/
   0,                           /*tp_as_buffer*/
-  Py_TPFLAGS_DEFAULT,          /*tp_flags*/
+  /*tp_flags*/
+  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS,
   /* tp_doc */
   "JavaScript Runtime.",
   0,		               /* tp_traverse */
   0,		               /* tp_clear */
   0,		               /* tp_richcompare */
-  0,		               /* tp_weaklistoffset */
+  /* tp_weaklistoffset */
+  offsetof(PYM_JSRuntimeObject, weakrefs),
   0,		               /* tp_iter */
   0,		               /* tp_iternext */
   PYM_JSRuntimeMethods,        /* tp_methods */