[Python-checkins] r67986 - in python/branches/py3k-issue1717: Doc/c-api/unicode.rst Include/unicodeobject.h Modules/_pickle.c Objects/typeobject.c Objects/unicodeobject.c Python/ast.c Python/compile.c Python/symtable.c

mark.dickinson python-checkins at python.org
Sun Dec 28 17:33:52 CET 2008


Author: mark.dickinson
Date: Sun Dec 28 17:33:51 2008
New Revision: 67986

Log:
Revert PyUnicode_Compare changes.


Modified:
   python/branches/py3k-issue1717/Doc/c-api/unicode.rst
   python/branches/py3k-issue1717/Include/unicodeobject.h
   python/branches/py3k-issue1717/Modules/_pickle.c
   python/branches/py3k-issue1717/Objects/typeobject.c
   python/branches/py3k-issue1717/Objects/unicodeobject.c
   python/branches/py3k-issue1717/Python/ast.c
   python/branches/py3k-issue1717/Python/compile.c
   python/branches/py3k-issue1717/Python/symtable.c

Modified: python/branches/py3k-issue1717/Doc/c-api/unicode.rst
==============================================================================
--- python/branches/py3k-issue1717/Doc/c-api/unicode.rst	(original)
+++ python/branches/py3k-issue1717/Doc/c-api/unicode.rst	Sun Dec 28 17:33:51 2008
@@ -863,10 +863,16 @@
    occurrences.
 
 
-.. cfunction:: int PyUnicode_EqualToASCIIString(PyObject *uni, char *string)
+.. cfunction:: int PyUnicode_Compare(PyObject *left, PyObject *right)
 
-   Compare a unicode object, *uni*, with *string* and return 1 if equal,
-   otherwise 0.
+   Compare two strings and return -1, 0, 1 for less than, equal, and greater than,
+   respectively.
+
+
+.. cfunction:: int PyUnicode_CompareWithASCIIString(PyObject *uni, char *string)
+
+   Compare a unicode object, *uni*, with *string* and return -1, 0, 1 for less
+   than, equal, and greater than, respectively.
 
 
 .. cfunction:: int PyUnicode_RichCompare(PyObject *left,  PyObject *right,  int op)

Modified: python/branches/py3k-issue1717/Include/unicodeobject.h
==============================================================================
--- python/branches/py3k-issue1717/Include/unicodeobject.h	(original)
+++ python/branches/py3k-issue1717/Include/unicodeobject.h	Sun Dec 28 17:33:51 2008
@@ -152,6 +152,7 @@
 # define PyUnicode_AsUnicode PyUnicodeUCS2_AsUnicode
 # define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS2_AsUnicodeEscapeString
 # define PyUnicode_AsWideChar PyUnicodeUCS2_AsWideChar
+# define PyUnicode_Compare PyUnicodeUCS2_Compare
 # define PyUnicode_Concat PyUnicodeUCS2_Concat
 # define PyUnicode_Append PyUnicodeUCS2_Append
 # define PyUnicode_AppendAndDel PyUnicodeUCS2_AppendAndDel
@@ -249,6 +250,7 @@
 # define PyUnicode_AsUnicode PyUnicodeUCS4_AsUnicode
 # define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS4_AsUnicodeEscapeString
 # define PyUnicode_AsWideChar PyUnicodeUCS4_AsWideChar
+# define PyUnicode_Compare PyUnicodeUCS4_Compare
 # define PyUnicode_Concat PyUnicodeUCS4_Concat
 # define PyUnicode_Append PyUnicodeUCS4_Append
 # define PyUnicode_AppendAndDel PyUnicodeUCS4_AppendAndDel
@@ -1397,10 +1399,15 @@
 				   -1 = all */
     );
 
-/* Compare two strings and return 1 if both are equal, otherwise 0
- */
+/* Compare two strings and return -1, 0, 1 for less than, equal,
+   greater than resp. */
+
+PyAPI_FUNC(int) PyUnicode_Compare(
+    PyObject *left,		/* Left string */ 
+    PyObject *right		/* Right string */
+    );
 
-PyAPI_FUNC(int) PyUnicode_EqualToASCIIString(
+PyAPI_FUNC(int) PyUnicode_CompareWithASCIIString(
     PyObject *left,
     const char *right
     );

Modified: python/branches/py3k-issue1717/Modules/_pickle.c
==============================================================================
--- python/branches/py3k-issue1717/Modules/_pickle.c	(original)
+++ python/branches/py3k-issue1717/Modules/_pickle.c	Sun Dec 28 17:33:51 2008
@@ -2041,7 +2041,7 @@
         }
         else {
             use_newobj = PyUnicode_Check(name_str) && 
-                PyObject_RichCompareBool(name_str, newobj_str, Py_EQ) == 1;
+                PyUnicode_Compare(name_str, newobj_str) == 0;
             Py_DECREF(name_str);
         }
     }

Modified: python/branches/py3k-issue1717/Objects/typeobject.c
==============================================================================
--- python/branches/py3k-issue1717/Objects/typeobject.c	(original)
+++ python/branches/py3k-issue1717/Objects/typeobject.c	Sun Dec 28 17:33:51 2008
@@ -656,7 +656,7 @@
 	if (name == NULL)
 		return NULL;
 
-	if (mod != NULL && !PyUnicode_EqualToASCIIString(mod, "builtins"))
+	if (mod != NULL && PyUnicode_CompareWithASCIIString(mod, "builtins"))
 		rtn = PyUnicode_FromFormat("<class '%U.%U'>", mod, name);
 	else
 		rtn = PyUnicode_FromFormat("<class '%s'>", type->tp_name);
@@ -2029,7 +2029,7 @@
 			if (!valid_identifier(tmp))
 				goto bad_slots;
 			assert(PyUnicode_Check(tmp));
-			if (PyUnicode_EqualToASCIIString(tmp, "__dict__")) {
+			if (PyUnicode_CompareWithASCIIString(tmp, "__dict__") == 0) {
 				if (!may_add_dict || add_dict) {
 					PyErr_SetString(PyExc_TypeError,
 						"__dict__ slot disallowed: "
@@ -2038,7 +2038,7 @@
 				}
 				add_dict++;
 			}
-			if (PyUnicode_EqualToASCIIString(tmp, "__weakref__")) {
+			if (PyUnicode_CompareWithASCIIString(tmp, "__weakref__") == 0) {
 				if (!may_add_weak || add_weak) {
 					PyErr_SetString(PyExc_TypeError,
 						"__weakref__ slot disallowed: "
@@ -2060,9 +2060,9 @@
 		for (i = j = 0; i < nslots; i++) {
 			tmp = PyTuple_GET_ITEM(slots, i);
 			if ((add_dict && 
-			     PyUnicode_EqualToASCIIString(tmp, "__dict__")) ||
+			     PyUnicode_CompareWithASCIIString(tmp, "__dict__") == 0) ||
 			    (add_weak && 
-			     PyUnicode_EqualToASCIIString(tmp, "__weakref__")))
+			     PyUnicode_CompareWithASCIIString(tmp, "__weakref__") == 0))
 				continue;
 			tmp =_Py_Mangle(name, tmp);
 			if (!tmp)
@@ -2791,12 +2791,11 @@
 	name = type_name(type, NULL);
 	if (name == NULL)
 		return NULL;
-	if (mod != NULL && !PyUnicode_EqualToASCIIString(mod, "builtins"))
+	if (mod != NULL && PyUnicode_CompareWithASCIIString(mod, "builtins"))
 		rtn = PyUnicode_FromFormat("<%U.%U object at %p>", mod, name, self);
 	else
 		rtn = PyUnicode_FromFormat("<%s object at %p>",
 					  type->tp_name, self);
-
 	Py_XDECREF(mod);
 	Py_DECREF(name);
 	return rtn;
@@ -5977,7 +5976,7 @@
 		   (i.e. super, or a subclass), not the class of su->obj. */
 		skip = (PyUnicode_Check(name) &&
 			PyUnicode_GET_SIZE(name) == 9 &&
-			PyUnicode_EqualToASCIIString(name, "__class__"));
+			PyUnicode_CompareWithASCIIString(name, "__class__") == 0);
 	}
 
 	if (!skip) {
@@ -6174,8 +6173,8 @@
 		for (i = 0; i < n; i++) {
 			PyObject *name = PyTuple_GET_ITEM(co->co_freevars, i);
 			assert(PyUnicode_Check(name));
-                        if (PyUnicode_EqualToASCIIString(name,
-                                                       "__class__")) {
+                        if (!PyUnicode_CompareWithASCIIString(name,
+                                                              "__class__")) {
 				Py_ssize_t index = co->co_nlocals + 
 					PyTuple_GET_SIZE(co->co_cellvars) + i;
 				PyObject *cell = f->f_localsplus[index];

Modified: python/branches/py3k-issue1717/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k-issue1717/Objects/unicodeobject.c	(original)
+++ python/branches/py3k-issue1717/Objects/unicodeobject.c	Sun Dec 28 17:33:51 2008
@@ -6477,8 +6477,21 @@
 
 #endif
 
+int PyUnicode_Compare(PyObject *left,
+		      PyObject *right)
+{
+    if (PyUnicode_Check(left) && PyUnicode_Check(right))
+        return unicode_compare((PyUnicodeObject *)left,
+                               (PyUnicodeObject *)right);
+    PyErr_Format(PyExc_TypeError,
+                 "Can't compare %.100s and %.100s",
+                 left->ob_type->tp_name,
+                 right->ob_type->tp_name);
+    return -1;
+}
+
 int
-PyUnicode_EqualToASCIIString(PyObject* uni, const char* str)
+PyUnicode_CompareWithASCIIString(PyObject* uni, const char* str)
 {
     int i;
     Py_UNICODE *id;
@@ -6487,10 +6500,12 @@
     /* Compare Unicode string and source character set string */
     for (i = 0; id[i] && str[i]; i++)
 	if (id[i] != str[i])
-	    return 0;
-    if (id[i] || str[i])
-	return 0;
-    return 1;
+	    return ((int)id[i] < (int)str[i]) ? -1 : 1;
+    if (id[i])
+	return 1; /* uni is longer */
+    if (str[i])
+	return -1; /* str is longer */
+    return 0;
 }
 
 

Modified: python/branches/py3k-issue1717/Python/ast.c
==============================================================================
--- python/branches/py3k-issue1717/Python/ast.c	(original)
+++ python/branches/py3k-issue1717/Python/ast.c	Sun Dec 28 17:33:51 2008
@@ -367,7 +367,7 @@
     const char **p;
     assert(PyUnicode_Check(e->v.Name.id));
     for (p = FORBIDDEN; *p; p++) {
-        if (PyUnicode_EqualToASCIIString(e->v.Name.id, *p)) {
+        if (PyUnicode_CompareWithASCIIString(e->v.Name.id, *p) == 0) {
             ast_error(n, "assignment to keyword");
             return 1;
         }
@@ -2020,7 +2020,7 @@
                 key = e->v.Name.id;
                 for (k = 0; k < nkeywords; k++) {
                     tmp = ((keyword_ty)asdl_seq_GET(keywords, k))->arg;
-                    if (PyObject_RichCompareBool(tmp, key, Py_EQ) != 0) {
+                    if (!PyUnicode_Compare(tmp, key)) {
                         ast_error(CHILD(ch, 0), "keyword argument repeated");
                         return NULL;
                     }

Modified: python/branches/py3k-issue1717/Python/compile.c
==============================================================================
--- python/branches/py3k-issue1717/Python/compile.c	(original)
+++ python/branches/py3k-issue1717/Python/compile.c	Sun Dec 28 17:33:51 2008
@@ -2197,8 +2197,8 @@
 	}
 
 	if (s->lineno > c->c_future->ff_lineno) {
-		if (PyUnicode_EqualToASCIIString(s->v.ImportFrom.module,
-					       "__future__")) {
+		if (!PyUnicode_CompareWithASCIIString(s->v.ImportFrom.module,
+						      "__future__")) {
 			Py_DECREF(level);
 			Py_DECREF(names);
 			return compiler_error(c, 

Modified: python/branches/py3k-issue1717/Python/symtable.c
==============================================================================
--- python/branches/py3k-issue1717/Python/symtable.c	(original)
+++ python/branches/py3k-issue1717/Python/symtable.c	Sun Dec 28 17:33:51 2008
@@ -494,7 +494,7 @@
 		if (!PySet_Contains(free, name))
 			continue;
 		if (restricted != NULL &&
-                    !PyUnicode_EqualToASCIIString(name, restricted))
+                    PyUnicode_CompareWithASCIIString(name, restricted))
 			continue;
 		/* Replace LOCAL with CELL for this name, and remove
 		   from free. It is safe to replace the value of name 
@@ -1326,7 +1326,7 @@
 		/* Special-case super: it counts as a use of __class__ */
                 if (e->v.Name.ctx == Load &&
 		    st->st_cur->ste_type == FunctionBlock &&
-                    PyUnicode_EqualToASCIIString(e->v.Name.id, "super")) {
+                    !PyUnicode_CompareWithASCIIString(e->v.Name.id, "super")) {
 			if (!GET_IDENTIFIER(__class__) ||
 			    !symtable_add_def(st, __class__, USE))
 				return 0;
@@ -1466,7 +1466,7 @@
 		store_name = name;
 		Py_INCREF(store_name);
 	}
-	if (!PyUnicode_EqualToASCIIString(name, "*")) {
+	if (PyUnicode_CompareWithASCIIString(name, "*")) {
 		int r = symtable_add_def(st, store_name, DEF_IMPORT); 
 		Py_DECREF(store_name);
 		return r;


More information about the Python-checkins mailing list