- 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.
This commit is contained in:
parent
c468fd28b6
commit
340d98f564
|
@ -83,9 +83,11 @@ class MyScanner(Scanner_OSX):
|
||||||
"CFStringGetPascalStringPtr", # TBD automatically
|
"CFStringGetPascalStringPtr", # TBD automatically
|
||||||
"CFStringGetCStringPtr",
|
"CFStringGetCStringPtr",
|
||||||
"CFStringGetCharactersPtr",
|
"CFStringGetCharactersPtr",
|
||||||
|
"CFStringGetCString",
|
||||||
|
"CFStringGetCharacters",
|
||||||
# OSX only, to be done
|
# OSX only, to be done
|
||||||
"CFURLCreateWithFileSystemPath",
|
## "CFURLCreateWithFileSystemPath",
|
||||||
"CFURLCreateStringWithFileSystemPath",
|
## "CFURLCreateStringWithFileSystemPath",
|
||||||
]
|
]
|
||||||
|
|
||||||
def makegreylist(self):
|
def makegreylist(self):
|
||||||
|
|
|
@ -119,7 +119,6 @@ OptionalCFURLRef = OpaqueByValueType("CFURLRef", "OptionalCFURLRefObj")
|
||||||
class MyGlobalObjectDefinition(GlobalObjectDefinition):
|
class MyGlobalObjectDefinition(GlobalObjectDefinition):
|
||||||
def outputCheckNewArg(self):
|
def outputCheckNewArg(self):
|
||||||
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
|
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
|
||||||
Output("CFRetain(itself);")
|
|
||||||
def outputStructMembers(self):
|
def outputStructMembers(self):
|
||||||
GlobalObjectDefinition.outputStructMembers(self)
|
GlobalObjectDefinition.outputStructMembers(self)
|
||||||
Output("void (*ob_freeit)(CFTypeRef ptr);")
|
Output("void (*ob_freeit)(CFTypeRef ptr);")
|
||||||
|
@ -243,6 +242,16 @@ class CFMutableDataRefObjectDefinition(MyGlobalObjectDefinition):
|
||||||
class CFStringRefObjectDefinition(MyGlobalObjectDefinition):
|
class CFStringRefObjectDefinition(MyGlobalObjectDefinition):
|
||||||
basechain = "&CFTypeRefObj_chain"
|
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):
|
def outputRepr(self):
|
||||||
Output()
|
Output()
|
||||||
Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
|
Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
|
||||||
|
@ -255,6 +264,10 @@ class CFStringRefObjectDefinition(MyGlobalObjectDefinition):
|
||||||
class CFMutableStringRefObjectDefinition(CFStringRefObjectDefinition):
|
class CFMutableStringRefObjectDefinition(CFStringRefObjectDefinition):
|
||||||
basechain = "&CFStringRefObj_chain"
|
basechain = "&CFStringRefObj_chain"
|
||||||
|
|
||||||
|
def outputCheckConvertArg(self):
|
||||||
|
# Mutable, don't allow Python strings
|
||||||
|
return MyGlobalObjectDefinition.outputCheckConvertArg(self)
|
||||||
|
|
||||||
def outputRepr(self):
|
def outputRepr(self):
|
||||||
Output()
|
Output()
|
||||||
Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
|
Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
|
||||||
|
@ -309,8 +322,8 @@ module.addobject(CFURLRef_object)
|
||||||
# ADD addobject call here
|
# ADD addobject call here
|
||||||
|
|
||||||
# Create the generator classes used to populate the lists
|
# Create the generator classes used to populate the lists
|
||||||
Function = OSErrFunctionGenerator
|
Function = OSErrWeakLinkFunctionGenerator
|
||||||
Method = OSErrMethodGenerator
|
Method = OSErrWeakLinkMethodGenerator
|
||||||
|
|
||||||
# Create and populate the lists
|
# Create and populate the lists
|
||||||
functions = []
|
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 CFMutableStringRef_methods: CFMutableStringRef_object.add(f)
|
||||||
for f in CFURLRef_methods: CFURLRef_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
|
# ADD add forloop here
|
||||||
|
|
||||||
# generate output (open the output file as late as possible)
|
# generate output (open the output file as late as possible)
|
||||||
|
|
Loading…
Reference in New Issue