Commits

Ronald Oussoren committed 4415ced

Fix a crash in NSArchiving support for Python objects

Without this patch the testsuite would cause a hard crash
in Python versions that have the thread-safe trashcan implemention
(3.3 and all upcoming stable releases). The crash happens
because a PyObjC callback method didn't get the GIL, and this
accidently worked in previous versions (but was probably an
accident waiting to happen and could have caused problems in
multithreaded scripts)

Comments (0)

Files changed (9)

pyobjc-core/Modules/objc/OC_PythonArray.m

  */
 -(void)pyobjcSetValue:(NSObject*)other
 {
-	PyObject* v = PyObjC_IdToPython(other);
-	Py_XDECREF(value);
-	value = v;
+	PyObjC_BEGIN_WITH_GIL
+		PyObject* v = PyObjC_IdToPython(other);
+		Py_XDECREF(value);
+		value = v;
+	PyObjC_END_WITH_GIL
 }
 
 -(id)initWithCoder:(NSCoder*)coder
 	PyObject* t;
 	int code;
         int size;
+
 	if ([coder allowsKeyedCoding]) {
 		code = [coder decodeInt32ForKey:@"pytype"];
 	} else {
 				if (proxy == NULL) {
 					PyObjC_RegisterObjCProxy(value, self);
 				} else {
+					[proxy retain];
 					[self release];
-					[proxy retain];
 					self = (OC_PythonArray*)proxy;
 				}
 

pyobjc-core/Modules/objc/OC_PythonDate.m

  */
 -(void)pyobjcSetValue:(NSObject*)other
 {
-	PyObject* v = PyObjC_IdToPython(other);
-	Py_XDECREF(value);
-	value = v;
+	PyObjC_BEGIN_WITH_GIL
+		PyObject* v = PyObjC_IdToPython(other);
+		Py_XDECREF(value);
+		value = v;
+	PyObjC_END_WITH_GIL
 }
 
 -(id)initWithCoder:(NSCoder*)coder

pyobjc-core/Modules/objc/OC_PythonDictionary.m

  */
 -(void)pyobjcSetValue:(NSObject*)other
 {
-	PyObject* v = PyObjC_IdToPython(other);
-	Py_XDECREF(value);
-	value = v;
+	PyObjC_BEGIN_WITH_GIL
+		PyObject* v = PyObjC_IdToPython(other);
+		Py_XDECREF(value);
+		value = v;
+	PyObjC_END_WITH_GIL
 }
 
 - (id)initWithCoder:(NSCoder*)coder

pyobjc-core/Modules/objc/OC_PythonNumber.m

  */
 -(void)pyobjcSetValue:(NSObject*)other
 {
-	PyObject* v = PyObjC_IdToPython(other);
-	Py_XDECREF(value);
-	value = v;
+	PyObjC_BEGIN_WITH_GIL
+		PyObject* v = PyObjC_IdToPython(other);
+		Py_XDECREF(value);
+		value = v;
+	PyObjC_END_WITH_GIL
 }
 
 - (id)initWithCoder:(NSCoder*)coder

pyobjc-core/Modules/objc/OC_PythonObject.m

  */
 -(void)pyobjcSetValue:(NSObject*)other
 {
-	PyObject* value = PyObjC_IdToPython(other);
-	Py_XDECREF(pyObject);
-	pyObject = value;
+	PyObjC_BEGIN_WITH_GIL
+		PyObject* value = PyObjC_IdToPython(other);
+		Py_XDECREF(pyObject);
+		pyObject = value;
+	PyObjC_END_WITH_GIL
 }
 
 -(id)initWithCoder:(NSCoder*)coder

pyobjc-core/Modules/objc/OC_PythonSet.m

  */
 -(void)pyobjcSetValue:(NSObject*)other
 {
-	PyObject* v = PyObjC_IdToPython(other);
-	Py_XDECREF(value);
-	value = v;
+	PyObjC_BEGIN_WITH_GIL
+		PyObject* v = PyObjC_IdToPython(other);
+		Py_XDECREF(value);
+		value = v;
+	PyObjC_END_WITH_GIL
 }
 
 - (id)initWithCoder:(NSCoder*)coder

pyobjc-core/Modules/objc/OC_PythonString.m

  */
 -(void)pyobjcSetValue:(NSObject*)other
 {
-	PyObject* v = PyObjC_IdToPython(other);
-	Py_XDECREF(value);
-	value = v;
+	PyObjC_BEGIN_WITH_GIL
+		PyObject* v = PyObjC_IdToPython(other);
+		Py_XDECREF(value);
+		value = v;
+	PyObjC_END_WITH_GIL
 }
 
 - (id)initWithCoder:(NSCoder*)coder

pyobjc-core/Modules/objc/OC_PythonUnicode.m

  */
 -(void)pyobjcSetValue:(NSObject*)other
 {
-	PyObject* v = PyObjC_IdToPython(other);
-	Py_XDECREF(value);
-	value = v;
+	PyObjC_BEGIN_WITH_GIL
+		PyObject* v = PyObjC_IdToPython(other);
+		Py_XDECREF(value);
+		value = v;
+	PyObjC_END_WITH_GIL
 }
 
 -(id)initWithCoder:(NSCoder*)coder

pyobjc-core/NEWS.txt

 Version 2.4  (or 3.0)
 ---------------------
 
+- Fix crash when unarchiving a Python object. 
+
 - Add missing calls to ``[super init]`` in the implementation of
   OC_PythonUnicode and OC_PythonString (the ObjC proxies for python's
   unicode and str types)