mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Added typechecking to the individual python->CF converters, so we can use them in the CF object initializers safely.
This commit is contained in:
parent
23be1ceb51
commit
eaba9d7b28
1 changed files with 16 additions and 2 deletions
|
@ -172,6 +172,12 @@ PyCF_Python2CF_sequence(PyObject *src, CFArrayRef *dst) {
|
||||||
PyObject *item_py = NULL;
|
PyObject *item_py = NULL;
|
||||||
int size, i;
|
int size, i;
|
||||||
|
|
||||||
|
if( !PySequence_Check(src) ) {
|
||||||
|
PyErr_Format(PyExc_TypeError,
|
||||||
|
"Cannot convert %.500s objects to CFArray",
|
||||||
|
src->ob_type->tp_name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
size = PySequence_Size(src);
|
size = PySequence_Size(src);
|
||||||
rv = CFArrayCreateMutable((CFAllocatorRef)NULL, size, &kCFTypeArrayCallBacks);
|
rv = CFArrayCreateMutable((CFAllocatorRef)NULL, size, &kCFTypeArrayCallBacks);
|
||||||
if (rv == NULL) {
|
if (rv == NULL) {
|
||||||
|
@ -205,6 +211,12 @@ PyCF_Python2CF_mapping(PyObject *src, CFDictionaryRef *dst) {
|
||||||
PyObject *item_py = NULL, *key_py = NULL, *value_py = NULL;
|
PyObject *item_py = NULL, *key_py = NULL, *value_py = NULL;
|
||||||
int size, i;
|
int size, i;
|
||||||
|
|
||||||
|
if( !PyMapping_Check(src) ) {
|
||||||
|
PyErr_Format(PyExc_TypeError,
|
||||||
|
"Cannot convert %.500s objects to CFDictionary",
|
||||||
|
src->ob_type->tp_name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
size = PyMapping_Size(src);
|
size = PyMapping_Size(src);
|
||||||
rv = CFDictionaryCreateMutable((CFAllocatorRef)NULL, size,
|
rv = CFDictionaryCreateMutable((CFAllocatorRef)NULL, size,
|
||||||
&kCFTypeDictionaryKeyCallBacks,
|
&kCFTypeDictionaryKeyCallBacks,
|
||||||
|
@ -241,10 +253,12 @@ err:
|
||||||
int
|
int
|
||||||
PyCF_Python2CF_simple(PyObject *src, CFTypeRef *dst) {
|
PyCF_Python2CF_simple(PyObject *src, CFTypeRef *dst) {
|
||||||
|
|
||||||
|
#if 0
|
||||||
if (PyObject_HasAttrString(src, "CFType")) {
|
if (PyObject_HasAttrString(src, "CFType")) {
|
||||||
*dst = PyObject_CallMethod(src, "CFType", "");
|
*dst = PyObject_CallMethod(src, "CFType", "");
|
||||||
return (*dst != NULL);
|
return (*dst != NULL);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (PyString_Check(src) || PyUnicode_Check(src))
|
if (PyString_Check(src) || PyUnicode_Check(src))
|
||||||
return PyCF_Python2CF_string(src, (CFStringRef *)dst);
|
return PyCF_Python2CF_string(src, (CFStringRef *)dst);
|
||||||
if (PyBool_Check(src)) {
|
if (PyBool_Check(src)) {
|
||||||
|
@ -266,7 +280,7 @@ PyCF_Python2CF_simple(PyObject *src, CFTypeRef *dst) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"Cannot convert %.500s objects to CF",
|
"Cannot convert %.500s objects to CFType",
|
||||||
src->ob_type->tp_name);
|
src->ob_type->tp_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -291,7 +305,7 @@ PyCF_Python2CF_string(PyObject *src, CFStringRef *dst) {
|
||||||
}
|
}
|
||||||
err:
|
err:
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"Cannot convert %.500s objects to CF",
|
"Cannot convert %.500s objects to CFString",
|
||||||
src->ob_type->tp_name);
|
src->ob_type->tp_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue