]> granicus.if.org Git - python/commitdiff
Accept only the system default encoding when converting Python
authorJack Jansen <jack.jansen@cwi.nl>
Mon, 3 Mar 2003 13:12:59 +0000 (13:12 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Mon, 3 Mar 2003 13:12:59 +0000 (13:12 +0000)
strings to CF strings. Fixes 682215.

Mac/Modules/cf/_CFmodule.c
Mac/Modules/cf/cfsupport.py
Mac/Modules/cf/pycfbridge.c

index 4f5d935b2696d1ae8ec13146f7f3c1068adbc013..8473eb56bade5b4b39e020a2f157ee5207fbb23d 100644 (file)
@@ -14,9 +14,9 @@
 
 /* Macro to test whether a weak-loaded CFM function exists */
 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL )  {\
-       PyErr_SetString(PyExc_NotImplementedError, \
-       "Not available in this shared library/OS version"); \
-       return NULL; \
+        PyErr_SetString(PyExc_NotImplementedError, \
+        "Not available in this shared library/OS version"); \
+        return NULL; \
     }} while(0)
 
 
@@ -1458,7 +1458,7 @@ int CFStringRefObj_Convert(PyObject *v, CFStringRef *p_itself)
        if (v == Py_None) { *p_itself = NULL; return 1; }
        if (PyString_Check(v)) {
            char *cStr = PyString_AsString(v);
-               *p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, 0);
+               *p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, kCFStringEncodingASCII);
                return 1;
        }
        if (PyUnicode_Check(v)) {
index 973c4d4fae7a9e5d90fbe930fac370e25c5bdc5c..bb0ac40483f0c00ec408eb4b1753eb4d10846d20 100644 (file)
@@ -359,8 +359,10 @@ class CFStringRefObjectDefinition(MyGlobalObjectDefinition):
                Out("""
                if (v == Py_None) { *p_itself = NULL; return 1; }
                if (PyString_Check(v)) {
-                   char *cStr = PyString_AsString(v);
-                       *p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, 0);
+                   char *cStr;
+                   if (!PyArg_Parse(v, "et", "ascii", &cStr))
+                       return NULL;
+                       *p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, kCFStringEncodingASCII);
                        return 1;
                }
                if (PyUnicode_Check(v)) {
index 00efa725196519add0eb9e26b7b7d00331d19f65..d4466aca108c61890b1acfe278424f3daa0bbc68 100644 (file)
@@ -292,8 +292,9 @@ PyCF_Python2CF_string(PyObject *src, CFStringRef *dst) {
        UniChar *unichars;
        
        if (PyString_Check(src)) {
-               if ((chars = PyString_AsString(src)) == NULL ) goto err;
-               *dst = CFStringCreateWithCString((CFAllocatorRef)NULL, chars, 0);
+               if (!PyArg_Parse(src, "es", NULL, &chars))
+                       return NULL; /* This error is more descriptive than the general one below */
+               *dst = CFStringCreateWithCString((CFAllocatorRef)NULL, chars, kCFStringEncodingASCII);
                return 1;
        }
        if (PyUnicode_Check(src)) {