[Python-checkins] python/dist/src/Mac/Modules/qt _Qtmodule.c, 1.20, 1.21 qtsupport.py, 1.25, 1.26

jackjansen at users.sourceforge.net jackjansen at users.sourceforge.net
Sun Jan 4 17:33:35 EST 2004


Update of /cvsroot/python/python/dist/src/Mac/Modules/qt
In directory sc8-pr-cvs1:/tmp/cvs-serv4011

Modified Files:
	_Qtmodule.c qtsupport.py 
Log Message:
Allow passing NULL pointers by passing None. This also works for the
factory functions, so you can call quicktime functions that are implemented
as methods on NULL too.

Still don't allow quicktime functions to return NULL pointers, though: I
think this always signals an error condition.


Index: _Qtmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/qt/_Qtmodule.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** _Qtmodule.c	3 Jan 2004 17:23:26 -0000	1.20
--- _Qtmodule.c	4 Jan 2004 22:33:33 -0000	1.21
***************
*** 99,103 ****
  	IdleManagerObject *it;
  	if (itself == NULL) {
! 						PyErr_SetString(Qt_Error,"Cannot create null IdleManager");
  						return NULL;
  					}
--- 99,103 ----
  	IdleManagerObject *it;
  	if (itself == NULL) {
! 						PyErr_SetString(Qt_Error,"Cannot create IdleManager from NULL pointer");
  						return NULL;
  					}
***************
*** 109,112 ****
--- 109,117 ----
  int IdleManagerObj_Convert(PyObject *v, IdleManager *p_itself)
  {
+ 	if (v == Py_None)
+ 	{
+ 		*p_itself = NULL;
+ 		return 1;
+ 	}
  	if (!IdleManagerObj_Check(v))
  	{
***************
*** 217,221 ****
  	MovieControllerObject *it;
  	if (itself == NULL) {
! 						PyErr_SetString(Qt_Error,"Cannot create null MovieController");
  						return NULL;
  					}
--- 222,226 ----
  	MovieControllerObject *it;
  	if (itself == NULL) {
! 						PyErr_SetString(Qt_Error,"Cannot create MovieController from NULL pointer");
  						return NULL;
  					}
***************
*** 227,230 ****
--- 232,240 ----
  int MovieCtlObj_Convert(PyObject *v, MovieController *p_itself)
  {
+ 	if (v == Py_None)
+ 	{
+ 		*p_itself = NULL;
+ 		return 1;
+ 	}
  	if (!MovieCtlObj_Check(v))
  	{
***************
*** 238,242 ****
  static void MovieCtlObj_dealloc(MovieControllerObject *self)
  {
! 	DisposeMovieController(self->ob_itself);
  	self->ob_type->tp_free((PyObject *)self);
  }
--- 248,252 ----
  static void MovieCtlObj_dealloc(MovieControllerObject *self)
  {
! 	if (self->ob_itself) DisposeMovieController(self->ob_itself);
  	self->ob_type->tp_free((PyObject *)self);
  }
***************
*** 1331,1335 ****
  	TimeBaseObject *it;
  	if (itself == NULL) {
! 						PyErr_SetString(Qt_Error,"Cannot create null TimeBase");
  						return NULL;
  					}
--- 1341,1345 ----
  	TimeBaseObject *it;
  	if (itself == NULL) {
! 						PyErr_SetString(Qt_Error,"Cannot create TimeBase from NULL pointer");
  						return NULL;
  					}
***************
*** 1341,1344 ****
--- 1351,1359 ----
  int TimeBaseObj_Convert(PyObject *v, TimeBase *p_itself)
  {
+ 	if (v == Py_None)
+ 	{
+ 		*p_itself = NULL;
+ 		return 1;
+ 	}
  	if (!TimeBaseObj_Check(v))
  	{
***************
*** 1819,1823 ****
  	UserDataObject *it;
  	if (itself == NULL) {
! 						PyErr_SetString(Qt_Error,"Cannot create null UserData");
  						return NULL;
  					}
--- 1834,1838 ----
  	UserDataObject *it;
  	if (itself == NULL) {
! 						PyErr_SetString(Qt_Error,"Cannot create UserData from NULL pointer");
  						return NULL;
  					}
***************
*** 1829,1832 ****
--- 1844,1852 ----
  int UserDataObj_Convert(PyObject *v, UserData *p_itself)
  {
+ 	if (v == Py_None)
+ 	{
+ 		*p_itself = NULL;
+ 		return 1;
+ 	}
  	if (!UserDataObj_Check(v))
  	{
***************
*** 1840,1844 ****
  static void UserDataObj_dealloc(UserDataObject *self)
  {
! 	DisposeUserData(self->ob_itself);
  	self->ob_type->tp_free((PyObject *)self);
  }
--- 1860,1864 ----
  static void UserDataObj_dealloc(UserDataObject *self)
  {
! 	if (self->ob_itself) DisposeUserData(self->ob_itself);
  	self->ob_type->tp_free((PyObject *)self);
  }
***************
*** 2184,2188 ****
  	MediaObject *it;
  	if (itself == NULL) {
! 						PyErr_SetString(Qt_Error,"Cannot create null Media");
  						return NULL;
  					}
--- 2204,2208 ----
  	MediaObject *it;
  	if (itself == NULL) {
! 						PyErr_SetString(Qt_Error,"Cannot create Media from NULL pointer");
  						return NULL;
  					}
***************
*** 2194,2197 ****
--- 2214,2222 ----
  int MediaObj_Convert(PyObject *v, Media *p_itself)
  {
+ 	if (v == Py_None)
+ 	{
+ 		*p_itself = NULL;
+ 		return 1;
+ 	}
  	if (!MediaObj_Check(v))
  	{
***************
*** 2205,2209 ****
  static void MediaObj_dealloc(MediaObject *self)
  {
! 	DisposeTrackMedia(self->ob_itself);
  	self->ob_type->tp_free((PyObject *)self);
  }
--- 2230,2234 ----
  static void MediaObj_dealloc(MediaObject *self)
  {
! 	if (self->ob_itself) DisposeTrackMedia(self->ob_itself);
  	self->ob_type->tp_free((PyObject *)self);
  }
***************
*** 3420,3424 ****
  	TrackObject *it;
  	if (itself == NULL) {
! 						PyErr_SetString(Qt_Error,"Cannot create null Track");
  						return NULL;
  					}
--- 3445,3449 ----
  	TrackObject *it;
  	if (itself == NULL) {
! 						PyErr_SetString(Qt_Error,"Cannot create Track from NULL pointer");
  						return NULL;
  					}
***************
*** 3430,3433 ****
--- 3455,3463 ----
  int TrackObj_Convert(PyObject *v, Track *p_itself)
  {
+ 	if (v == Py_None)
+ 	{
+ 		*p_itself = NULL;
+ 		return 1;
+ 	}
  	if (!TrackObj_Check(v))
  	{
***************
*** 3441,3445 ****
  static void TrackObj_dealloc(TrackObject *self)
  {
! 	DisposeMovieTrack(self->ob_itself);
  	self->ob_type->tp_free((PyObject *)self);
  }
--- 3471,3475 ----
  static void TrackObj_dealloc(TrackObject *self)
  {
! 	if (self->ob_itself) DisposeMovieTrack(self->ob_itself);
  	self->ob_type->tp_free((PyObject *)self);
  }
***************
*** 4762,4766 ****
  	MovieObject *it;
  	if (itself == NULL) {
! 						PyErr_SetString(Qt_Error,"Cannot create null Movie");
  						return NULL;
  					}
--- 4792,4796 ----
  	MovieObject *it;
  	if (itself == NULL) {
! 						PyErr_SetString(Qt_Error,"Cannot create Movie from NULL pointer");
  						return NULL;
  					}
***************
*** 4772,4775 ****
--- 4802,4810 ----
  int MovieObj_Convert(PyObject *v, Movie *p_itself)
  {
+ 	if (v == Py_None)
+ 	{
+ 		*p_itself = NULL;
+ 		return 1;
+ 	}
  	if (!MovieObj_Check(v))
  	{
***************
*** 4783,4787 ****
  static void MovieObj_dealloc(MovieObject *self)
  {
! 	DisposeMovie(self->ob_itself);
  	self->ob_type->tp_free((PyObject *)self);
  }
--- 4818,4822 ----
  static void MovieObj_dealloc(MovieObject *self)
  {
! 	if (self->ob_itself) DisposeMovie(self->ob_itself);
  	self->ob_type->tp_free((PyObject *)self);
  }
***************
*** 7309,7313 ****
  	SGOutputObject *it;
  	if (itself == NULL) {
! 						PyErr_SetString(Qt_Error,"Cannot create null SGOutput");
  						return NULL;
  					}
--- 7344,7348 ----
  	SGOutputObject *it;
  	if (itself == NULL) {
! 						PyErr_SetString(Qt_Error,"Cannot create SGOutput from NULL pointer");
  						return NULL;
  					}
***************
*** 7319,7322 ****
--- 7354,7362 ----
  int SGOutputObj_Convert(PyObject *v, SGOutput *p_itself)
  {
+ 	if (v == Py_None)
+ 	{
+ 		*p_itself = NULL;
+ 		return 1;
+ 	}
  	if (!SGOutputObj_Check(v))
  	{

Index: qtsupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/qt/qtsupport.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** qtsupport.py	3 Jan 2004 17:23:27 -0000	1.25
--- qtsupport.py	4 Jan 2004 22:33:33 -0000	1.26
***************
*** 206,282 ****
  dummyStringPtr = FakeType('(StringPtr)0')
  
! class MovieObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
  	def outputCheckNewArg(self):
  		Output("""if (itself == NULL) {
! 					PyErr_SetString(Qt_Error,"Cannot create null Movie");
  					return NULL;
! 				}""")
  	def outputFreeIt(self, itselfname):
! 		Output("DisposeMovie(%s);", itselfname)
  
! class TrackObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
! 	def outputCheckNewArg(self):
! 		Output("""if (itself == NULL) {
! 					PyErr_SetString(Qt_Error,"Cannot create null Track");
! 					return NULL;
! 				}""")
  	def outputFreeIt(self, itselfname):
! 		Output("DisposeMovieTrack(%s);", itselfname)
  
! class MediaObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
! 	def outputCheckNewArg(self):
! 		Output("""if (itself == NULL) {
! 					PyErr_SetString(Qt_Error,"Cannot create null Media");
! 					return NULL;
! 				}""")
  	def outputFreeIt(self, itselfname):
! 		Output("DisposeTrackMedia(%s);", itselfname)
  
! class UserDataObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
! 	def outputCheckNewArg(self):
! 		Output("""if (itself == NULL) {
! 					PyErr_SetString(Qt_Error,"Cannot create null UserData");
! 					return NULL;
! 				}""")
  	def outputFreeIt(self, itselfname):
! 		Output("DisposeUserData(%s);", itselfname)
! 
! class TimeBaseObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
! 	def outputCheckNewArg(self):
! 		Output("""if (itself == NULL) {
! 					PyErr_SetString(Qt_Error,"Cannot create null TimeBase");
! 					return NULL;
! 				}""")
! ##	def outputFreeIt(self, itselfname):
! ##		Output("DisposeTimeBase(%s);", itselfname)
  
! class MovieCtlObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
! 	def outputCheckNewArg(self):
! 		Output("""if (itself == NULL) {
! 					PyErr_SetString(Qt_Error,"Cannot create null MovieController");
! 					return NULL;
! 				}""")
  	def outputFreeIt(self, itselfname):
! 		Output("DisposeMovieController(%s);", itselfname)
! 
! class IdleManagerObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
! 	def outputCheckNewArg(self):
! 		Output("""if (itself == NULL) {
! 					PyErr_SetString(Qt_Error,"Cannot create null IdleManager");
! 					return NULL;
! 				}""")
  
! class SGOutputObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
  	# XXXX I'm not sure I fully understand how SGOutput works. It seems it's always tied
  	# to a specific SeqGrabComponent, but I'm not 100% sure. Also, I'm not sure all the
  	# routines that return an SGOutput actually return a *new* SGOutput. Need to read up on
  	# this.
! 	def outputCheckNewArg(self):
! 		Output("""if (itself == NULL) {
! 					PyErr_SetString(Qt_Error,"Cannot create null SGOutput");
! 					return NULL;
! 				}""")
! #	def outputFreeIt(self, itselfname):
! #		Output("SGDisposeOutput(%s);", itselfname)
  
  
--- 206,261 ----
  dummyStringPtr = FakeType('(StringPtr)0')
  
! # XXXX Need to override output_tp_newBody() to allow for None initializer.
! class QtGlobalObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
  	def outputCheckNewArg(self):
+ 		# We don't allow NULL pointers to be returned by QuickTime API calls,
+ 		# in stead we raise an exception
  		Output("""if (itself == NULL) {
! 					PyErr_SetString(Qt_Error,"Cannot create %s from NULL pointer");
  					return NULL;
! 				}""", self.name)
! 	
! 	def outputCheckConvertArg(self):
! 		# But what we do allow is passing None whereever a quicktime object is
! 		# expected, and pass this as NULL to the API routines. Note you can
! 		# call methods too by creating an object with None as the initializer.
! 		Output("if (v == Py_None)")
! 		OutLbrace()
! 		Output("*p_itself = NULL;")
! 		Output("return 1;")
! 		OutRbrace()
! 	
! class MovieObjectDefinition(QtGlobalObjectDefinition):
  	def outputFreeIt(self, itselfname):
! 		Output("if (%s) DisposeMovie(%s);", itselfname, itselfname)
  
! class TrackObjectDefinition(QtGlobalObjectDefinition):
  	def outputFreeIt(self, itselfname):
! 		Output("if (%s) DisposeMovieTrack(%s);", itselfname, itselfname)
  
! class MediaObjectDefinition(QtGlobalObjectDefinition):
  	def outputFreeIt(self, itselfname):
! 		Output("if (%s) DisposeTrackMedia(%s);", itselfname, itselfname)
  
! class UserDataObjectDefinition(QtGlobalObjectDefinition):
  	def outputFreeIt(self, itselfname):
! 		Output("if (%s) DisposeUserData(%s);", itselfname, itselfname)
  
! class TimeBaseObjectDefinition(QtGlobalObjectDefinition):
! 	pass
! 	
! class MovieCtlObjectDefinition(QtGlobalObjectDefinition):
  	def outputFreeIt(self, itselfname):
! 		Output("if (%s) DisposeMovieController(%s);", itselfname, itselfname)
  
! class IdleManagerObjectDefinition(QtGlobalObjectDefinition):
! 	pass
! 	
! class SGOutputObjectDefinition(QtGlobalObjectDefinition):
  	# XXXX I'm not sure I fully understand how SGOutput works. It seems it's always tied
  	# to a specific SeqGrabComponent, but I'm not 100% sure. Also, I'm not sure all the
  	# routines that return an SGOutput actually return a *new* SGOutput. Need to read up on
  	# this.
! 	pass
  
  





More information about the Python-checkins mailing list