Mercurial > pymonkey
diff runtime.c @ 62:2b5696b91b01
Fixed a bug whereby some objects wouldn't be finalized when a runtime was destroyed.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sat, 25 Jul 2009 22:51:20 -0700 |
parents | bc4263c6ae82 |
children | 345d4c0e3dd3 |
line wrap: on
line diff
--- a/runtime.c Sat Jul 25 16:14:03 2009 -0700 +++ b/runtime.c Sat Jul 25 22:51:20 2009 -0700 @@ -47,6 +47,7 @@ self = (PYM_JSRuntimeObject *) type->tp_alloc(type, 0); if (self != NULL) { self->rt = NULL; + self->cx = NULL; self->objects.ops = NULL; if (!JS_DHashTableInit(&self->objects, @@ -65,6 +66,13 @@ PyErr_SetString(PYM_error, "JS_NewRuntime() failed"); type->tp_dealloc((PyObject *) self); self = NULL; + } else { + self->cx = JS_NewContext(self->rt, 8192); + if (!self->cx) { + PyErr_SetString(PYM_error, "JS_NewContext() failed"); + type->tp_dealloc((PyObject *) self); + self = NULL; + } } } } @@ -80,6 +88,13 @@ self->objects.ops = NULL; } + if (self->cx) { + // Note that this will also force GC of any remaining objects + // in the runtime. + JS_DestroyContext(self->cx); + self->cx = NULL; + } + if (self->rt) { JS_DestroyRuntime(self->rt); self->rt = NULL;