<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>tests/test-turnover.py</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -30,3 +30,6 @@ Keiji Costantini
 
 Richard Boulton
     * Initial patch for filtering Python access.
+
+marc
+    * Report on Context turnover causing segfaults.</diff>
      <filename>THANKS</filename>
    </modified>
    <modified>
      <diff>@@ -344,10 +344,6 @@ Context_new(PyTypeObject* type, PyObject* args, PyObject* kwargs)
      *  garbage collection from happening on either side of the
      *  bridge.
      *
-     *  To make sure that the context stays alive we'll add a
-     *  reference to the Context* anytime we wrap a Python
-     *  object for use in JS.
-     *
      */
     JS_SetContextPrivate(self-&gt;cx, self);
 </diff>
      <filename>spidermonkey/context.c</filename>
    </modified>
    <modified>
      <diff>@@ -34,6 +34,7 @@ finalize(JSContext* jscx, JSObject* jsobj)
     if(pycx == NULL)
     {
         fprintf(stderr, &quot;*** NO PYTHON CONTEXT ***\n&quot;);
+        JS_EndRequest(jscx);
         return;
     }
 </diff>
      <filename>spidermonkey/pyiter.c</filename>
    </modified>
    <modified>
      <diff>@@ -224,12 +224,6 @@ js_finalize(JSContext* jscx, JSObject* jsobj)
     JS_EndRequest(jscx);
 
     Py_DECREF(pyobj);
-
-    // Technically, this could turn out to be nasty. If
-    // this is the last object keeping the python cx
-    // alive, then this call could be deleting the cx
-    // we're about to return to.
-    Py_DECREF(pycx);
 }
 
 PyObject*
@@ -493,12 +487,6 @@ py2js_object(Context* cx, PyObject* pyobj)
         goto error;
     }
 
-    /*
-        As noted in Context_new, here we must ref the Python context
-        to make sure it stays alive while a Python object may be
-        referenced in the JS VM.
-    */
-    Py_INCREF(cx);
     ret = OBJECT_TO_JSVAL(jsobj);
     goto success;
 </diff>
      <filename>spidermonkey/pyobject.c</filename>
    </modified>
    <modified>
      <diff>@@ -20,12 +20,17 @@ Runtime_new(PyTypeObject* type, PyObject* args, PyObject* kwargs)
     if(self == NULL) goto error;
 
     self-&gt;rt = JS_NewRuntime(stacksize);
-    if(self-&gt;rt == NULL) goto error;
+    if(self-&gt;rt == NULL)
+    {
+        PyErr_SetString(JSError, &quot;Failed to allocate new JSRuntime.&quot;);
+        goto error;
+    }
 
     goto success;
 
 error:
     Py_XDECREF(self);
+    self = NULL;
 
 success:
     return (PyObject*) self;</diff>
      <filename>spidermonkey/runtime.c</filename>
    </modified>
    <modified>
      <diff>@@ -46,7 +46,7 @@ def test_exceed_time(cx):
     script = &quot;&quot;&quot;
         var time = function() {return (new Date()).getTime();};
         var start = time();
-        while((time() - start) &lt; 2000) {}
+        while((time() - start) &lt; 100000) {}
     &quot;&quot;&quot;
     cx.max_time(1)
     t.raises(SystemError, cx.execute, script)</diff>
      <filename>tests/test-context.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>38872a8e736002095794a745e013dee66be25bd4</id>
    </parent>
  </parents>
  <author>
    <name>Paul J. Davis</name>
    <email>paul.joseph.davis@gmail.com</email>
  </author>
  <url>http://github.com/davisp/python-spidermonkey/commit/6d5e357f9cd4ae3cfaaf25aafbf6c121cf519ac2</url>
  <id>6d5e357f9cd4ae3cfaaf25aafbf6c121cf519ac2</id>
  <committed-date>2009-06-26T16:45:51-07:00</committed-date>
  <authored-date>2009-06-26T16:45:51-07:00</authored-date>
  <message>Fix segfaults when large numbers of contexts.

Turns out that I had an error in my logic about how to reference count
the python context object. I removed references to it from Python
objects that are wrapped in the JavaScript VM. I'm more than 50% certain that
this is correct as when the Python context dies, it'll destroy the
JSContext* and along with it all references to Python objects that need
refernces to the Context.

[#21 state:resolved]</message>
  <tree>f70696ccfc31719d988d2f65425db9725bb2401f</tree>
  <committer>
    <name>Paul J. Davis</name>
    <email>paul.joseph.davis@gmail.com</email>
  </committer>
</commit>
