Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eaba9d7

Browse files
committed
Added typechecking to the individual python->CF converters, so we can use them in the CF object initializers safely.
1 parent 23be1ce commit eaba9d7

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

Mac/Modules/cf/pycfbridge.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ PyCF_Python2CF_sequence(PyObject *src, CFArrayRef *dst) {
172172
PyObject *item_py = NULL;
173173
int size, i;
174174

175+
if( !PySequence_Check(src) ) {
176+
PyErr_Format(PyExc_TypeError,
177+
"Cannot convert %.500s objects to CFArray",
178+
src->ob_type->tp_name);
179+
return 0;
180+
}
175181
size = PySequence_Size(src);
176182
rv = CFArrayCreateMutable((CFAllocatorRef)NULL, size, &kCFTypeArrayCallBacks);
177183
if (rv == NULL) {
@@ -205,6 +211,12 @@ PyCF_Python2CF_mapping(PyObject *src, CFDictionaryRef *dst) {
205211
PyObject *item_py = NULL, *key_py = NULL, *value_py = NULL;
206212
int size, i;
207213

214+
if( !PyMapping_Check(src) ) {
215+
PyErr_Format(PyExc_TypeError,
216+
"Cannot convert %.500s objects to CFDictionary",
217+
src->ob_type->tp_name);
218+
return 0;
219+
}
208220
size = PyMapping_Size(src);
209221
rv = CFDictionaryCreateMutable((CFAllocatorRef)NULL, size,
210222
&kCFTypeDictionaryKeyCallBacks,
@@ -241,10 +253,12 @@ PyCF_Python2CF_mapping(PyObject *src, CFDictionaryRef *dst) {
241253
int
242254
PyCF_Python2CF_simple(PyObject *src, CFTypeRef *dst) {
243255

256+
#if 0
244257
if (PyObject_HasAttrString(src, "CFType")) {
245258
*dst = PyObject_CallMethod(src, "CFType", "");
246259
return (*dst != NULL);
247260
}
261+
#endif
248262
if (PyString_Check(src) || PyUnicode_Check(src))
249263
return PyCF_Python2CF_string(src, (CFStringRef *)dst);
250264
if (PyBool_Check(src)) {
@@ -266,7 +280,7 @@ PyCF_Python2CF_simple(PyObject *src, CFTypeRef *dst) {
266280
}
267281

268282
PyErr_Format(PyExc_TypeError,
269-
"Cannot convert %.500s objects to CF",
283+
"Cannot convert %.500s objects to CFType",
270284
src->ob_type->tp_name);
271285
return 0;
272286
}
@@ -291,7 +305,7 @@ PyCF_Python2CF_string(PyObject *src, CFStringRef *dst) {
291305
}
292306
err:
293307
PyErr_Format(PyExc_TypeError,
294-
"Cannot convert %.500s objects to CF",
308+
"Cannot convert %.500s objects to CFString",
295309
src->ob_type->tp_name);
296310
return 0;
297311
}

0 commit comments

Comments
 (0)