[Python-3000-checkins] r57582 - python/branches/py3k/Modules/posixmodule.c

guido.van.rossum python-3000-checkins at python.org
Tue Aug 28 01:24:47 CEST 2007


Author: guido.van.rossum
Date: Tue Aug 28 01:24:46 2007
New Revision: 57582

Modified:
   python/branches/py3k/Modules/posixmodule.c
Log:
posix.confname(): enforce that names as str instances.


Modified: python/branches/py3k/Modules/posixmodule.c
==============================================================================
--- python/branches/py3k/Modules/posixmodule.c	(original)
+++ python/branches/py3k/Modules/posixmodule.c	Tue Aug 28 01:24:46 2007
@@ -5441,7 +5441,7 @@
 
 static int
 conv_confname(PyObject *arg, int *valuep, struct constdef *table,
-	      size_t tablesize)
+              size_t tablesize)
 {
     if (PyInt_Check(arg)) {
         *valuep = PyInt_AS_LONG(arg);
@@ -5450,16 +5450,20 @@
     else {
         /* look up the value in the table using a binary search */
         size_t lo = 0;
-		size_t mid;
+        size_t mid;
         size_t hi = tablesize;
         int cmp;
         const char *confname;
         Py_ssize_t namelen;
-        if (PyObject_AsCharBuffer(arg, &confname, &namelen) < 0) {
+        if (!PyUnicode_Check(arg)) {
             PyErr_SetString(PyExc_TypeError,
                             "configuration names must be strings or integers");
             return 0;
         }
+        confname = PyUnicode_AsString(arg);
+        if (confname == NULL)
+            return 0;
+        namelen = strlen(confname);
         while (lo < hi) {
             mid = (lo + hi) / 2;
             cmp = strcmp(confname, table[mid].name);


More information about the Python-3000-checkins mailing list