]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport of 1.8 (of _CFModule.c):
authorJack Jansen <jack.jansen@cwi.nl>
Wed, 27 Feb 2002 23:10:01 +0000 (23:10 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Wed, 27 Feb 2002 23:10:01 +0000 (23:10 +0000)
Added some support for unicode arguments.

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

index a7488132c994e54bad9f6e3c4ddae36754a6e064..a47fe85fcc5f95ccb4738dfa07200a381427733e 100644 (file)
@@ -2046,6 +2046,26 @@ static PyObject *CFMutableStringRefObj_CFStringAppend(CFMutableStringRefObject *
        return _res;
 }
 
+static PyObject *CFMutableStringRefObj_CFStringAppendCharacters(CFMutableStringRefObject *_self, PyObject *_args)
+{
+       PyObject *_res = NULL;
+       UniChar *chars__in__;
+       UniCharCount chars__len__;
+       int chars__in_len__;
+#ifndef CFStringAppendCharacters
+       PyMac_PRECHECK(CFStringAppendCharacters);
+#endif
+       if (!PyArg_ParseTuple(_args, "u#",
+                             &chars__in__, &chars__in_len__))
+               return NULL;
+       chars__len__ = chars__in_len__;
+       CFStringAppendCharacters(_self->ob_itself,
+                                chars__in__, chars__len__);
+       Py_INCREF(Py_None);
+       _res = Py_None;
+       return _res;
+}
+
 static PyObject *CFMutableStringRefObj_CFStringAppendPascalString(CFMutableStringRefObject *_self, PyObject *_args)
 {
        PyObject *_res = NULL;
@@ -2217,6 +2237,8 @@ static PyObject *CFMutableStringRefObj_CFStringTrimWhitespace(CFMutableStringRef
 static PyMethodDef CFMutableStringRefObj_methods[] = {
        {"CFStringAppend", (PyCFunction)CFMutableStringRefObj_CFStringAppend, 1,
         "(CFStringRef appendedString) -> None"},
+       {"CFStringAppendCharacters", (PyCFunction)CFMutableStringRefObj_CFStringAppendCharacters, 1,
+        "(Buffer chars) -> None"},
        {"CFStringAppendPascalString", (PyCFunction)CFMutableStringRefObj_CFStringAppendPascalString, 1,
         "(Str255 pStr, CFStringEncoding encoding) -> None"},
        {"CFStringAppendCString", (PyCFunction)CFMutableStringRefObj_CFStringAppendCString, 1,
@@ -3221,6 +3243,27 @@ static PyObject *CF_CFStringCreateWithCString(PyObject *_self, PyObject *_args)
        return _res;
 }
 
+static PyObject *CF_CFStringCreateWithCharacters(PyObject *_self, PyObject *_args)
+{
+       PyObject *_res = NULL;
+       CFStringRef _rv;
+       UniChar *chars__in__;
+       UniCharCount chars__len__;
+       int chars__in_len__;
+#ifndef CFStringCreateWithCharacters
+       PyMac_PRECHECK(CFStringCreateWithCharacters);
+#endif
+       if (!PyArg_ParseTuple(_args, "u#",
+                             &chars__in__, &chars__in_len__))
+               return NULL;
+       chars__len__ = chars__in_len__;
+       _rv = CFStringCreateWithCharacters((CFAllocatorRef)NULL,
+                                          chars__in__, chars__len__);
+       _res = Py_BuildValue("O&",
+                            CFStringRefObj_New, _rv);
+       return _res;
+}
+
 static PyObject *CF_CFStringCreateWithPascalStringNoCopy(PyObject *_self, PyObject *_args)
 {
        PyObject *_res = NULL;
@@ -3265,6 +3308,28 @@ static PyObject *CF_CFStringCreateWithCStringNoCopy(PyObject *_self, PyObject *_
        return _res;
 }
 
+static PyObject *CF_CFStringCreateWithCharactersNoCopy(PyObject *_self, PyObject *_args)
+{
+       PyObject *_res = NULL;
+       CFStringRef _rv;
+       UniChar *chars__in__;
+       UniCharCount chars__len__;
+       int chars__in_len__;
+#ifndef CFStringCreateWithCharactersNoCopy
+       PyMac_PRECHECK(CFStringCreateWithCharactersNoCopy);
+#endif
+       if (!PyArg_ParseTuple(_args, "u#",
+                             &chars__in__, &chars__in_len__))
+               return NULL;
+       chars__len__ = chars__in_len__;
+       _rv = CFStringCreateWithCharactersNoCopy((CFAllocatorRef)NULL,
+                                                chars__in__, chars__len__,
+                                                (CFAllocatorRef)NULL);
+       _res = Py_BuildValue("O&",
+                            CFStringRefObj_New, _rv);
+       return _res;
+}
+
 static PyObject *CF_CFStringCreateMutable(PyObject *_self, PyObject *_args)
 {
        PyObject *_res = NULL;
@@ -3667,10 +3732,14 @@ static PyMethodDef CF_methods[] = {
         "(Str255 pStr, CFStringEncoding encoding) -> (CFStringRef _rv)"},
        {"CFStringCreateWithCString", (PyCFunction)CF_CFStringCreateWithCString, 1,
         "(char* cStr, CFStringEncoding encoding) -> (CFStringRef _rv)"},
+       {"CFStringCreateWithCharacters", (PyCFunction)CF_CFStringCreateWithCharacters, 1,
+        "(Buffer chars) -> (CFStringRef _rv)"},
        {"CFStringCreateWithPascalStringNoCopy", (PyCFunction)CF_CFStringCreateWithPascalStringNoCopy, 1,
         "(Str255 pStr, CFStringEncoding encoding) -> (CFStringRef _rv)"},
        {"CFStringCreateWithCStringNoCopy", (PyCFunction)CF_CFStringCreateWithCStringNoCopy, 1,
         "(char* cStr, CFStringEncoding encoding) -> (CFStringRef _rv)"},
+       {"CFStringCreateWithCharactersNoCopy", (PyCFunction)CF_CFStringCreateWithCharactersNoCopy, 1,
+        "(Buffer chars) -> (CFStringRef _rv)"},
        {"CFStringCreateMutable", (PyCFunction)CF_CFStringCreateMutable, 1,
         "(CFIndex maxLength) -> (CFMutableStringRef _rv)"},
        {"CFStringCreateMutableCopy", (PyCFunction)CF_CFStringCreateMutableCopy, 1,
index b8ccb316c75675c1362604692349ee581e892dd6..3e09df4e3f38587ec10a2028253f9fdeb6c122bf 100644 (file)
@@ -92,6 +92,9 @@ class MyScanner(Scanner_OSX):
                        "CFStringGetCString", 
                        "CFStringGetCharacters",
                        "CFURLCreateStringWithFileSystemPath", # Gone in later releases
+                       "CFStringCreateMutableWithExternalCharactersNoCopy", # Not a clue...
+                       "CFStringSetExternalCharactersNoCopy",
+                       "CFStringGetCharacterAtIndex", # No format for single unichars yet.
                        ]
 
        def makegreylist(self):
@@ -105,9 +108,6 @@ class MyScanner(Scanner_OSX):
                        "void_ptr", # Ditto for various array lookup methods
                        "CFArrayApplierFunction", # Callback function pointer
                        "CFDictionaryApplierFunction", # Callback function pointer
-                       "UniChar_ptr", # XXXX To be done
-                       "const_UniChar_ptr", # XXXX To be done
-                       "UniChar", # XXXX To be done
                        "va_list", # For printf-to-a-cfstring. Use Python.
                        "const_CFStringEncoding_ptr", # To be done, I guess
                        ]
@@ -118,6 +118,9 @@ class MyScanner(Scanner_OSX):
                        ([("UInt8_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
                         [("UcharInBuffer", "*", "*")]),
                         
+                       ([("UniChar_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
+                        [("UnicodeInBuffer", "*", "*")]),
+
                        # Some functions return a const char *. Don't worry, we won't modify it.
                        ([("const_char_ptr", "*", "ReturnMode")],
                         [("return_stringptr", "*", "*")]),
index 0f95abed060edaffbe19ec694e6366edcdaa6e8d..fb275c3ed066dc98b7a499aa1a4f84299707d41c 100644 (file)
@@ -171,8 +171,6 @@ CFOptionFlags = Type("CFOptionFlags", "l")
 CFStringEncoding = Type("CFStringEncoding", "l")
 CFComparisonResult = Type("CFComparisonResult", "l")  # a bit dangerous, it's an enum
 CFURLPathStyle = Type("CFURLPathStyle", "l") #  a bit dangerous, it's an enum
-FSRef_ptr = OpaqueType("FSRef", "PyMac_BuildFSRef", "PyMac_GetFSRef")
-FSRef = OpaqueByValueType("FSRef", "PyMac_BuildFSRef", "PyMac_GetFSRef")
 
 char_ptr = stringptr
 return_stringptr = Type("char *", "s") # ONLY FOR RETURN VALUES!!