Author: walter.doerwald
Date: Sun Jul  1 23:58:22 2007
New Revision: 56140

Modified:
   python/branches/py3k-struni/Modules/arraymodule.c
   python/branches/py3k-struni/Modules/datetimemodule.c
   python/branches/py3k-struni/Python/getargs.c
   python/branches/py3k-struni/Python/modsupport.c
Log:
Revert r56044 (which changed the %c format specifier to accept a
unicode char into an int variable) and add %C which does this.


Modified: python/branches/py3k-struni/Modules/arraymodule.c
==============================================================================
--- python/branches/py3k-struni/Modules/arraymodule.c   (original)
+++ python/branches/py3k-struni/Modules/arraymodule.c   Sun Jul  1 23:58:22 2007
@@ -1785,7 +1785,7 @@
        if (type == &Arraytype && !_PyArg_NoKeywords("array.array()", kwds))
                return NULL;
 
-       if (!PyArg_ParseTuple(args, "c|O:array", &c, &initial))
+       if (!PyArg_ParseTuple(args, "C|O:array", &c, &initial))
                return NULL;
 
        if (!(initial == NULL || PyList_Check(initial)

Modified: python/branches/py3k-struni/Modules/datetimemodule.c
==============================================================================
--- python/branches/py3k-struni/Modules/datetimemodule.c        (original)
+++ python/branches/py3k-struni/Modules/datetimemodule.c        Sun Jul  1 
23:58:22 2007
@@ -4033,7 +4033,7 @@
        PyObject *result;
        int us = DATE_GET_MICROSECOND(self);
 
-       if (!PyArg_ParseTupleAndKeywords(args, kw, "|c:isoformat", keywords, 
&sep))
+       if (!PyArg_ParseTupleAndKeywords(args, kw, "|C:isoformat", keywords, 
&sep))
                return NULL;
        if (us)
                result = 
PyUnicode_FromFormat("%04d-%02d-%02d%c%02d:%02d:%02d.%06d",

Modified: python/branches/py3k-struni/Python/getargs.c
==============================================================================
--- python/branches/py3k-struni/Python/getargs.c        (original)
+++ python/branches/py3k-struni/Python/getargs.c        Sun Jul  1 23:58:22 2007
@@ -761,6 +761,19 @@
 #endif /* WITHOUT_COMPLEX */
        
        case 'c': {/* char */
+               char *p = va_arg(*p_va, char *);
+               if (PyString_Check(arg) && PyString_Size(arg) == 1)
+                       *p = PyString_AS_STRING(arg)[0];
+               else if (PyUnicode_Check(arg) &&
+                        PyUnicode_GET_SIZE(arg) == 1 &&
+                        PyUnicode_AS_UNICODE(arg)[0] < 256)
+                       *p = PyUnicode_AS_UNICODE(arg)[0];
+               else
+                       return converterr("char < 256", arg, msgbuf, bufsize);
+               break;
+       }
+       
+       case 'C': {/* unicode char */
                int *p = va_arg(*p_va, int *);
                if (PyString_Check(arg) && PyString_Size(arg) == 1)
                        *p = PyString_AS_STRING(arg)[0];

Modified: python/branches/py3k-struni/Python/modsupport.c
==============================================================================
--- python/branches/py3k-struni/Python/modsupport.c     (original)
+++ python/branches/py3k-struni/Python/modsupport.c     Sun Jul  1 23:58:22 2007
@@ -385,6 +385,12 @@
 
                case 'c':
                {
+                       char p[1];
+                       p[0] = (char)va_arg(*p_va, int);
+                       return PyString_FromStringAndSize(p, 1);
+               }
+               case 'C':
+               {
                        int i = va_arg(*p_va, int);
                        Py_UNICODE c;
                        if (i < 0 || i > PyUnicode_GetMax()) {
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to