[Python-3000-checkins] r58411 - python/branches/py3k/Python/pythonrun.c

guido.van.rossum python-3000-checkins at python.org
Wed Oct 10 23:38:59 CEST 2007


Author: guido.van.rossum
Date: Wed Oct 10 23:38:59 2007
New Revision: 58411

Modified:
   python/branches/py3k/Python/pythonrun.c
Log:
get rid of some more PyString uses.
Only the filename is still a PyString now.
(We'll need to deal with the default filesystem encoding to do it right.)


Modified: python/branches/py3k/Python/pythonrun.c
==============================================================================
--- python/branches/py3k/Python/pythonrun.c	(original)
+++ python/branches/py3k/Python/pythonrun.c	Wed Oct 10 23:38:59 2007
@@ -762,19 +762,19 @@
 	}
 	v = PySys_GetObject("ps1");
 	if (v != NULL) {
-		v = PyObject_Str(v);
+		v = PyObject_Unicode(v);
 		if (v == NULL)
 			PyErr_Clear();
-		else if (PyString_Check(v))
-			ps1 = PyString_AsString(v);
+		else if (PyUnicode_Check(v))
+			ps1 = PyUnicode_AsString(v);
 	}
 	w = PySys_GetObject("ps2");
 	if (w != NULL) {
-		w = PyObject_Str(w);
+		w = PyObject_Unicode(w);
 		if (w == NULL)
 			PyErr_Clear();
-		else if (PyString_Check(w))
-			ps2 = PyString_AsString(w);
+		else if (PyUnicode_Check(w))
+			ps2 = PyUnicode_AsString(w);
 	}
 	arena = PyArena_New();
 	if (arena == NULL) {
@@ -979,7 +979,8 @@
 		goto finally;
 	if (v == Py_None)
 		*text = NULL;
-	else if (! (*text = PyString_AsString(v)))
+        else if (!PyUnicode_Check(v) ||
+		 !(*text = PyUnicode_AsString(v)))
 		goto finally;
 	Py_DECREF(v);
 	return 1;
@@ -1093,7 +1094,7 @@
 	if (set_sys_last_vars) {
 		PySys_SetObject("last_type", exception);
 		PySys_SetObject("last_value", v);
-		PySys_SetObject("last_traceback", tb);
+		PySys_SetObject("last_traceback", tb ? tb : Py_None);
 	}
 	hook = PySys_GetObject("excepthook");
 	if (hook) {
@@ -1195,10 +1196,13 @@
 			}
 
 			moduleName = PyObject_GetAttrString(exception, "__module__");
-			if (moduleName == NULL)
+			if (moduleName == NULL || !PyUnicode_Check(moduleName))
+			{
+				Py_DECREF(moduleName);
 				err = PyFile_WriteString("<unknown>", f);
+			}
 			else {
-				char* modstr = PyString_AsString(moduleName);
+				char* modstr = PyUnicode_AsString(moduleName);
 				if (modstr && strcmp(modstr, "__builtin__"))
 				{
 					err = PyFile_WriteString(modstr, f);
@@ -1216,14 +1220,14 @@
 		else
 			err = PyFile_WriteObject(exception, f, Py_PRINT_RAW);
 		if (err == 0 && (value != Py_None)) {
-			PyObject *s = PyObject_Str(value);
+			PyObject *s = PyObject_Unicode(value);
 			/* only print colon if the str() of the
 			   object is not the empty string
 			*/
 			if (s == NULL)
 				err = -1;
-			else if (!PyString_Check(s) ||
-				 PyString_GET_SIZE(s) != 0)
+			else if (!PyUnicode_Check(s) ||
+				 PyUnicode_GetSize(s) != 0)
 				err = PyFile_WriteString(": ", f);
 			if (err == 0)
 			  err = PyFile_WriteObject(s, f, Py_PRINT_RAW);
@@ -1530,9 +1534,9 @@
 		PyObject *type, *value, *tb;
 		PyErr_Fetch(&type, &value, &tb);
 		if (value != NULL) {
-			u = PyObject_Str(value);
+			u = PyObject_Unicode(value);
 			if (u != NULL) {
-				msg = PyString_AsString(u);
+				msg = PyUnicode_AsString(u);
 			}
 		}
 		if (msg == NULL)


More information about the Python-3000-checkins mailing list