summaryrefslogtreecommitdiffstats
path: root/Mac
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2001-07-01 22:04:02 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2001-07-01 22:04:02 (GMT)
commit340d98f564ac3ce8ee46b1f2c4f382718c10effe (patch)
tree1338525beed8ef675c7f14774d04eb7b8c6b289f /Mac
parentc468fd28b66b37f95963f9b99db097c16407b408 (diff)
downloadcpython-340d98f564ac3ce8ee46b1f2c4f382718c10effe.zip
cpython-340d98f564ac3ce8ee46b1f2c4f382718c10effe.tar.gz
cpython-340d98f564ac3ce8ee46b1f2c4f382718c10effe.tar.bz2
- Use weaklink generators so we can support OSX-only calls without crashing on OS9.
- Convert CFString to/from Python strings. Currently always MacRoman, to be fixed later (as is unicode support). Python->CFString conversion is automatic.
Diffstat (limited to 'Mac')
-rw-r--r--Mac/Modules/cf/cfscan.py6
-rw-r--r--Mac/Modules/cf/cfsupport.py40
2 files changed, 41 insertions, 5 deletions
diff --git a/Mac/Modules/cf/cfscan.py b/Mac/Modules/cf/cfscan.py
index 2d11867..7941875 100644
--- a/Mac/Modules/cf/cfscan.py
+++ b/Mac/Modules/cf/cfscan.py
@@ -83,9 +83,11 @@ class MyScanner(Scanner_OSX):
"CFStringGetPascalStringPtr", # TBD automatically
"CFStringGetCStringPtr",
"CFStringGetCharactersPtr",
+ "CFStringGetCString",
+ "CFStringGetCharacters",
# OSX only, to be done
- "CFURLCreateWithFileSystemPath",
- "CFURLCreateStringWithFileSystemPath",
+## "CFURLCreateWithFileSystemPath",
+## "CFURLCreateStringWithFileSystemPath",
]
def makegreylist(self):
diff --git a/Mac/Modules/cf/cfsupport.py b/Mac/Modules/cf/cfsupport.py
index bdc20f8..170d4db 100644
--- a/Mac/Modules/cf/cfsupport.py
+++ b/Mac/Modules/cf/cfsupport.py
@@ -119,7 +119,6 @@ OptionalCFURLRef = OpaqueByValueType("CFURLRef", "OptionalCFURLRefObj")
class MyGlobalObjectDefinition(GlobalObjectDefinition):
def outputCheckNewArg(self):
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
- Output("CFRetain(itself);")
def outputStructMembers(self):
GlobalObjectDefinition.outputStructMembers(self)
Output("void (*ob_freeit)(CFTypeRef ptr);")
@@ -243,6 +242,16 @@ class CFMutableDataRefObjectDefinition(MyGlobalObjectDefinition):
class CFStringRefObjectDefinition(MyGlobalObjectDefinition):
basechain = "&CFTypeRefObj_chain"
+ def outputCheckConvertArg(self):
+ 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);
+ return 1;
+ }
+ """)
+
def outputRepr(self):
Output()
Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
@@ -255,6 +264,10 @@ class CFStringRefObjectDefinition(MyGlobalObjectDefinition):
class CFMutableStringRefObjectDefinition(CFStringRefObjectDefinition):
basechain = "&CFStringRefObj_chain"
+ def outputCheckConvertArg(self):
+ # Mutable, don't allow Python strings
+ return MyGlobalObjectDefinition.outputCheckConvertArg(self)
+
def outputRepr(self):
Output()
Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
@@ -309,8 +322,8 @@ module.addobject(CFURLRef_object)
# ADD addobject call here
# Create the generator classes used to populate the lists
-Function = OSErrFunctionGenerator
-Method = OSErrMethodGenerator
+Function = OSErrWeakLinkFunctionGenerator
+Method = OSErrWeakLinkMethodGenerator
# Create and populate the lists
functions = []
@@ -343,6 +356,27 @@ for f in CFStringRef_methods: CFStringRef_object.add(f)
for f in CFMutableStringRef_methods: CFMutableStringRef_object.add(f)
for f in CFURLRef_methods: CFURLRef_object.add(f)
+# Manual generators for getting data out of strings
+
+getasstring_body = """
+int size = CFStringGetLength(_self->ob_itself)+1;
+char *data = malloc(size);
+
+if( data == NULL ) return PyErr_NoMemory();
+if ( CFStringGetCString(_self->ob_itself, data, size, 0) ) {
+ _res = (PyObject *)PyString_FromString(data);
+} else {
+ PyErr_SetString(PyExc_RuntimeError, "CFStringGetCString could not fit the string");
+ _res = NULL;
+}
+free(data);
+return _res;
+"""
+
+f = ManualGenerator("CFStringGetString", getasstring_body);
+f.docstring = lambda: "() -> (string _rv)"
+CFStringRef_object.add(f)
+
# ADD add forloop here
# generate output (open the output file as late as possible)