[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52776] trunk/blender/source/blender/ python/intern/bpy_traceback.c: update parse_syntax_error() from python3. 3 - this is an internal python function that isn't exposed to the api.

Campbell Barton ideasman42 at gmail.com
Tue Dec 4 21:09:09 CET 2012


Revision: 52776
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52776
Author:   campbellbarton
Date:     2012-12-04 20:09:07 +0000 (Tue, 04 Dec 2012)
Log Message:
-----------
update parse_syntax_error() from python3.3 - this is an internal python function that isn't exposed to the api.

Modified Paths:
--------------
    trunk/blender/source/blender/python/intern/bpy_traceback.c

Modified: trunk/blender/source/blender/python/intern/bpy_traceback.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_traceback.c	2012-12-04 19:58:13 UTC (rev 52775)
+++ trunk/blender/source/blender/python/intern/bpy_traceback.c	2012-12-04 20:09:07 UTC (rev 52776)
@@ -39,70 +39,80 @@
 	return PyBytes_AS_STRING((*coerce = PyUnicode_EncodeFSDefault(tb->tb_frame->f_code->co_filename)));
 }
 
-/* copied from pythonrun.c, 3.2.0 */
+/* copied from pythonrun.c, 3.3.0 */
 static int
 parse_syntax_error(PyObject *err, PyObject **message, const char **filename,
                    int *lineno, int *offset, const char **text)
 {
 	long hold;
 	PyObject *v;
+	_Py_IDENTIFIER(msg);
+	_Py_IDENTIFIER(filename);
+	_Py_IDENTIFIER(lineno);
+	_Py_IDENTIFIER(offset);
+	_Py_IDENTIFIER(text);
 
-	/* old style errors */
-	if (PyTuple_Check(err))
-		return PyArg_ParseTuple(err, "O(ziiz)", message, filename,
-		                        lineno, offset, text);
+	*message = NULL;
 
 	/* new style errors.  `err' is an instance */
-
-	if (!(v = PyObject_GetAttrString(err, "msg")))
+	*message = _PyObject_GetAttrId(err, &PyId_msg);
+	if (!*message)
 		goto finally;
-	*message = v;
 
-	if (!(v = PyObject_GetAttrString(err, "filename")))
+	v = _PyObject_GetAttrId(err, &PyId_filename);
+	if (!v)
 		goto finally;
-	if (v == Py_None)
+	if (v == Py_None) {
+		Py_DECREF(v);
 		*filename = NULL;
-	else if (!(*filename = _PyUnicode_AsString(v)))
-		goto finally;
+	}
+	else {
+		*filename = _PyUnicode_AsString(v);
+		Py_DECREF(v);
+		if (!*filename)
+			goto finally;
+	}
 
-	Py_DECREF(v);
-	if (!(v = PyObject_GetAttrString(err, "lineno")))
+	v = _PyObject_GetAttrId(err, &PyId_lineno);
+	if (!v)
 		goto finally;
 	hold = PyLong_AsLong(v);
 	Py_DECREF(v);
-	v = NULL;
 	if (hold < 0 && PyErr_Occurred())
 		goto finally;
 	*lineno = (int)hold;
 
-	if (!(v = PyObject_GetAttrString(err, "offset")))
+	v = _PyObject_GetAttrId(err, &PyId_offset);
+	if (!v)
 		goto finally;
 	if (v == Py_None) {
 		*offset = -1;
 		Py_DECREF(v);
-		v = NULL;
-	}
-	else {
+	} else {
 		hold = PyLong_AsLong(v);
 		Py_DECREF(v);
-		v = NULL;
 		if (hold < 0 && PyErr_Occurred())
 			goto finally;
 		*offset = (int)hold;
 	}
 
-	if (!(v = PyObject_GetAttrString(err, "text")))
+	v = _PyObject_GetAttrId(err, &PyId_text);
+	if (!v)
 		goto finally;
-	if (v == Py_None)
+	if (v == Py_None) {
+		Py_DECREF(v);
 		*text = NULL;
-	else if (!PyUnicode_Check(v) ||
-	         !(*text = _PyUnicode_AsString(v)))
-		goto finally;
-	Py_DECREF(v);
+	}
+	else {
+		*text = _PyUnicode_AsString(v);
+		Py_DECREF(v);
+		if (!*text)
+			goto finally;
+	}
 	return 1;
 
 finally:
-	Py_XDECREF(v);
+	Py_XDECREF(*message);
 	return 0;
 }
 /* end copied function! */




More information about the Bf-blender-cvs mailing list