[Python-checkins] python/dist/src/Mac/Modules/cf pycfbridge.c,1.4,1.5

jackjansen@sourceforge.net jackjansen@sourceforge.net
Mon, 13 May 2002 14:23:12 -0700


Update of /cvsroot/python/python/dist/src/Mac/Modules/cf
In directory usw-pr-cvs1:/tmp/cvs-serv21827/Python/Mac/Modules/cf

Modified Files:
	pycfbridge.c 
Log Message:
Added typechecking to the individual python->CF converters, so we can use them in the CF object initializers safely.

Index: pycfbridge.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/cf/pycfbridge.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** pycfbridge.c	8 May 2002 22:13:51 -0000	1.4
--- pycfbridge.c	13 May 2002 21:23:10 -0000	1.5
***************
*** 173,176 ****
--- 173,182 ----
  	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);
  	rv = CFArrayCreateMutable((CFAllocatorRef)NULL, size, &kCFTypeArrayCallBacks);
***************
*** 206,209 ****
--- 212,221 ----
  	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);
  	rv = CFDictionaryCreateMutable((CFAllocatorRef)NULL, size,
***************
*** 242,249 ****
--- 254,263 ----
  PyCF_Python2CF_simple(PyObject *src, CFTypeRef *dst) {
  	
+ #if 0
  	if (PyObject_HasAttrString(src, "CFType")) {
  		*dst = PyObject_CallMethod(src, "CFType", "");
  		return (*dst != NULL);
  	}
+ #endif
  	if (PyString_Check(src) || PyUnicode_Check(src)) 
  		return PyCF_Python2CF_string(src, (CFStringRef *)dst);
***************
*** 267,271 ****
  			
  	PyErr_Format(PyExc_TypeError,
! 		  "Cannot convert %.500s objects to CF",
  				     src->ob_type->tp_name);
  	return 0;
--- 281,285 ----
  			
  	PyErr_Format(PyExc_TypeError,
! 		  "Cannot convert %.500s objects to CFType",
  				     src->ob_type->tp_name);
  	return 0;
***************
*** 292,296 ****
  err:
  	PyErr_Format(PyExc_TypeError,
! 		  "Cannot convert %.500s objects to CF",
  				     src->ob_type->tp_name);
  	return 0;
--- 306,310 ----
  err:
  	PyErr_Format(PyExc_TypeError,
! 		  "Cannot convert %.500s objects to CFString",
  				     src->ob_type->tp_name);
  	return 0;