Commit cb2117a8 authored by Jack Jansen's avatar Jack Jansen

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.
parent c14149e6
...@@ -98,7 +98,7 @@ PyObject *IdleManagerObj_New(IdleManager itself) ...@@ -98,7 +98,7 @@ PyObject *IdleManagerObj_New(IdleManager itself)
{ {
IdleManagerObject *it; IdleManagerObject *it;
if (itself == NULL) { if (itself == NULL) {
PyErr_SetString(Qt_Error,"Cannot create null IdleManager"); PyErr_SetString(Qt_Error,"Cannot create IdleManager from NULL pointer");
return NULL; return NULL;
} }
it = PyObject_NEW(IdleManagerObject, &IdleManager_Type); it = PyObject_NEW(IdleManagerObject, &IdleManager_Type);
...@@ -108,6 +108,11 @@ PyObject *IdleManagerObj_New(IdleManager itself) ...@@ -108,6 +108,11 @@ PyObject *IdleManagerObj_New(IdleManager itself)
} }
int IdleManagerObj_Convert(PyObject *v, IdleManager *p_itself) int IdleManagerObj_Convert(PyObject *v, IdleManager *p_itself)
{ {
if (v == Py_None)
{
*p_itself = NULL;
return 1;
}
if (!IdleManagerObj_Check(v)) if (!IdleManagerObj_Check(v))
{ {
PyErr_SetString(PyExc_TypeError, "IdleManager required"); PyErr_SetString(PyExc_TypeError, "IdleManager required");
...@@ -216,7 +221,7 @@ PyObject *MovieCtlObj_New(MovieController itself) ...@@ -216,7 +221,7 @@ PyObject *MovieCtlObj_New(MovieController itself)
{ {
MovieControllerObject *it; MovieControllerObject *it;
if (itself == NULL) { if (itself == NULL) {
PyErr_SetString(Qt_Error,"Cannot create null MovieController"); PyErr_SetString(Qt_Error,"Cannot create MovieController from NULL pointer");
return NULL; return NULL;
} }
it = PyObject_NEW(MovieControllerObject, &MovieController_Type); it = PyObject_NEW(MovieControllerObject, &MovieController_Type);
...@@ -226,6 +231,11 @@ PyObject *MovieCtlObj_New(MovieController itself) ...@@ -226,6 +231,11 @@ PyObject *MovieCtlObj_New(MovieController itself)
} }
int MovieCtlObj_Convert(PyObject *v, MovieController *p_itself) int MovieCtlObj_Convert(PyObject *v, MovieController *p_itself)
{ {
if (v == Py_None)
{
*p_itself = NULL;
return 1;
}
if (!MovieCtlObj_Check(v)) if (!MovieCtlObj_Check(v))
{ {
PyErr_SetString(PyExc_TypeError, "MovieController required"); PyErr_SetString(PyExc_TypeError, "MovieController required");
...@@ -237,7 +247,7 @@ int MovieCtlObj_Convert(PyObject *v, MovieController *p_itself) ...@@ -237,7 +247,7 @@ int MovieCtlObj_Convert(PyObject *v, MovieController *p_itself)
static void MovieCtlObj_dealloc(MovieControllerObject *self) static void MovieCtlObj_dealloc(MovieControllerObject *self)
{ {
DisposeMovieController(self->ob_itself); if (self->ob_itself) DisposeMovieController(self->ob_itself);
self->ob_type->tp_free((PyObject *)self); self->ob_type->tp_free((PyObject *)self);
} }
...@@ -1330,7 +1340,7 @@ PyObject *TimeBaseObj_New(TimeBase itself) ...@@ -1330,7 +1340,7 @@ PyObject *TimeBaseObj_New(TimeBase itself)
{ {
TimeBaseObject *it; TimeBaseObject *it;
if (itself == NULL) { if (itself == NULL) {
PyErr_SetString(Qt_Error,"Cannot create null TimeBase"); PyErr_SetString(Qt_Error,"Cannot create TimeBase from NULL pointer");
return NULL; return NULL;
} }
it = PyObject_NEW(TimeBaseObject, &TimeBase_Type); it = PyObject_NEW(TimeBaseObject, &TimeBase_Type);
...@@ -1340,6 +1350,11 @@ PyObject *TimeBaseObj_New(TimeBase itself) ...@@ -1340,6 +1350,11 @@ PyObject *TimeBaseObj_New(TimeBase itself)
} }
int TimeBaseObj_Convert(PyObject *v, TimeBase *p_itself) int TimeBaseObj_Convert(PyObject *v, TimeBase *p_itself)
{ {
if (v == Py_None)
{
*p_itself = NULL;
return 1;
}
if (!TimeBaseObj_Check(v)) if (!TimeBaseObj_Check(v))
{ {
PyErr_SetString(PyExc_TypeError, "TimeBase required"); PyErr_SetString(PyExc_TypeError, "TimeBase required");
...@@ -1818,7 +1833,7 @@ PyObject *UserDataObj_New(UserData itself) ...@@ -1818,7 +1833,7 @@ PyObject *UserDataObj_New(UserData itself)
{ {
UserDataObject *it; UserDataObject *it;
if (itself == NULL) { if (itself == NULL) {
PyErr_SetString(Qt_Error,"Cannot create null UserData"); PyErr_SetString(Qt_Error,"Cannot create UserData from NULL pointer");
return NULL; return NULL;
} }
it = PyObject_NEW(UserDataObject, &UserData_Type); it = PyObject_NEW(UserDataObject, &UserData_Type);
...@@ -1828,6 +1843,11 @@ PyObject *UserDataObj_New(UserData itself) ...@@ -1828,6 +1843,11 @@ PyObject *UserDataObj_New(UserData itself)
} }
int UserDataObj_Convert(PyObject *v, UserData *p_itself) int UserDataObj_Convert(PyObject *v, UserData *p_itself)
{ {
if (v == Py_None)
{
*p_itself = NULL;
return 1;
}
if (!UserDataObj_Check(v)) if (!UserDataObj_Check(v))
{ {
PyErr_SetString(PyExc_TypeError, "UserData required"); PyErr_SetString(PyExc_TypeError, "UserData required");
...@@ -1839,7 +1859,7 @@ int UserDataObj_Convert(PyObject *v, UserData *p_itself) ...@@ -1839,7 +1859,7 @@ int UserDataObj_Convert(PyObject *v, UserData *p_itself)
static void UserDataObj_dealloc(UserDataObject *self) static void UserDataObj_dealloc(UserDataObject *self)
{ {
DisposeUserData(self->ob_itself); if (self->ob_itself) DisposeUserData(self->ob_itself);
self->ob_type->tp_free((PyObject *)self); self->ob_type->tp_free((PyObject *)self);
} }
...@@ -2183,7 +2203,7 @@ PyObject *MediaObj_New(Media itself) ...@@ -2183,7 +2203,7 @@ PyObject *MediaObj_New(Media itself)
{ {
MediaObject *it; MediaObject *it;
if (itself == NULL) { if (itself == NULL) {
PyErr_SetString(Qt_Error,"Cannot create null Media"); PyErr_SetString(Qt_Error,"Cannot create Media from NULL pointer");
return NULL; return NULL;
} }
it = PyObject_NEW(MediaObject, &Media_Type); it = PyObject_NEW(MediaObject, &Media_Type);
...@@ -2193,6 +2213,11 @@ PyObject *MediaObj_New(Media itself) ...@@ -2193,6 +2213,11 @@ PyObject *MediaObj_New(Media itself)
} }
int MediaObj_Convert(PyObject *v, Media *p_itself) int MediaObj_Convert(PyObject *v, Media *p_itself)
{ {
if (v == Py_None)
{
*p_itself = NULL;
return 1;
}
if (!MediaObj_Check(v)) if (!MediaObj_Check(v))
{ {
PyErr_SetString(PyExc_TypeError, "Media required"); PyErr_SetString(PyExc_TypeError, "Media required");
...@@ -2204,7 +2229,7 @@ int MediaObj_Convert(PyObject *v, Media *p_itself) ...@@ -2204,7 +2229,7 @@ int MediaObj_Convert(PyObject *v, Media *p_itself)
static void MediaObj_dealloc(MediaObject *self) static void MediaObj_dealloc(MediaObject *self)
{ {
DisposeTrackMedia(self->ob_itself); if (self->ob_itself) DisposeTrackMedia(self->ob_itself);
self->ob_type->tp_free((PyObject *)self); self->ob_type->tp_free((PyObject *)self);
} }
...@@ -3419,7 +3444,7 @@ PyObject *TrackObj_New(Track itself) ...@@ -3419,7 +3444,7 @@ PyObject *TrackObj_New(Track itself)
{ {
TrackObject *it; TrackObject *it;
if (itself == NULL) { if (itself == NULL) {
PyErr_SetString(Qt_Error,"Cannot create null Track"); PyErr_SetString(Qt_Error,"Cannot create Track from NULL pointer");
return NULL; return NULL;
} }
it = PyObject_NEW(TrackObject, &Track_Type); it = PyObject_NEW(TrackObject, &Track_Type);
...@@ -3429,6 +3454,11 @@ PyObject *TrackObj_New(Track itself) ...@@ -3429,6 +3454,11 @@ PyObject *TrackObj_New(Track itself)
} }
int TrackObj_Convert(PyObject *v, Track *p_itself) int TrackObj_Convert(PyObject *v, Track *p_itself)
{ {
if (v == Py_None)
{
*p_itself = NULL;
return 1;
}
if (!TrackObj_Check(v)) if (!TrackObj_Check(v))
{ {
PyErr_SetString(PyExc_TypeError, "Track required"); PyErr_SetString(PyExc_TypeError, "Track required");
...@@ -3440,7 +3470,7 @@ int TrackObj_Convert(PyObject *v, Track *p_itself) ...@@ -3440,7 +3470,7 @@ int TrackObj_Convert(PyObject *v, Track *p_itself)
static void TrackObj_dealloc(TrackObject *self) static void TrackObj_dealloc(TrackObject *self)
{ {
DisposeMovieTrack(self->ob_itself); if (self->ob_itself) DisposeMovieTrack(self->ob_itself);
self->ob_type->tp_free((PyObject *)self); self->ob_type->tp_free((PyObject *)self);
} }
...@@ -4761,7 +4791,7 @@ PyObject *MovieObj_New(Movie itself) ...@@ -4761,7 +4791,7 @@ PyObject *MovieObj_New(Movie itself)
{ {
MovieObject *it; MovieObject *it;
if (itself == NULL) { if (itself == NULL) {
PyErr_SetString(Qt_Error,"Cannot create null Movie"); PyErr_SetString(Qt_Error,"Cannot create Movie from NULL pointer");
return NULL; return NULL;
} }
it = PyObject_NEW(MovieObject, &Movie_Type); it = PyObject_NEW(MovieObject, &Movie_Type);
...@@ -4771,6 +4801,11 @@ PyObject *MovieObj_New(Movie itself) ...@@ -4771,6 +4801,11 @@ PyObject *MovieObj_New(Movie itself)
} }
int MovieObj_Convert(PyObject *v, Movie *p_itself) int MovieObj_Convert(PyObject *v, Movie *p_itself)
{ {
if (v == Py_None)
{
*p_itself = NULL;
return 1;
}
if (!MovieObj_Check(v)) if (!MovieObj_Check(v))
{ {
PyErr_SetString(PyExc_TypeError, "Movie required"); PyErr_SetString(PyExc_TypeError, "Movie required");
...@@ -4782,7 +4817,7 @@ int MovieObj_Convert(PyObject *v, Movie *p_itself) ...@@ -4782,7 +4817,7 @@ int MovieObj_Convert(PyObject *v, Movie *p_itself)
static void MovieObj_dealloc(MovieObject *self) static void MovieObj_dealloc(MovieObject *self)
{ {
DisposeMovie(self->ob_itself); if (self->ob_itself) DisposeMovie(self->ob_itself);
self->ob_type->tp_free((PyObject *)self); self->ob_type->tp_free((PyObject *)self);
} }
...@@ -7308,7 +7343,7 @@ PyObject *SGOutputObj_New(SGOutput itself) ...@@ -7308,7 +7343,7 @@ PyObject *SGOutputObj_New(SGOutput itself)
{ {
SGOutputObject *it; SGOutputObject *it;
if (itself == NULL) { if (itself == NULL) {
PyErr_SetString(Qt_Error,"Cannot create null SGOutput"); PyErr_SetString(Qt_Error,"Cannot create SGOutput from NULL pointer");
return NULL; return NULL;
} }
it = PyObject_NEW(SGOutputObject, &SGOutput_Type); it = PyObject_NEW(SGOutputObject, &SGOutput_Type);
...@@ -7318,6 +7353,11 @@ PyObject *SGOutputObj_New(SGOutput itself) ...@@ -7318,6 +7353,11 @@ PyObject *SGOutputObj_New(SGOutput itself)
} }
int SGOutputObj_Convert(PyObject *v, SGOutput *p_itself) int SGOutputObj_Convert(PyObject *v, SGOutput *p_itself)
{ {
if (v == Py_None)
{
*p_itself = NULL;
return 1;
}
if (!SGOutputObj_Check(v)) if (!SGOutputObj_Check(v))
{ {
PyErr_SetString(PyExc_TypeError, "SGOutput required"); PyErr_SetString(PyExc_TypeError, "SGOutput required");
......
...@@ -205,79 +205,58 @@ CodecQ = Type("CodecQ", "l") ...@@ -205,79 +205,58 @@ CodecQ = Type("CodecQ", "l")
dummyshortptr = FakeType('(short *)0') dummyshortptr = FakeType('(short *)0')
dummyStringPtr = FakeType('(StringPtr)0') dummyStringPtr = FakeType('(StringPtr)0')
class MovieObjectDefinition(PEP253Mixin, GlobalObjectDefinition): # XXXX Need to override output_tp_newBody() to allow for None initializer.
class QtGlobalObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
def outputCheckNewArg(self): 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) { Output("""if (itself == NULL) {
PyErr_SetString(Qt_Error,"Cannot create null Movie"); PyErr_SetString(Qt_Error,"Cannot create %s from NULL pointer");
return NULL; 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): def outputFreeIt(self, itselfname):
Output("DisposeMovie(%s);", itselfname) Output("if (%s) DisposeMovie(%s);", itselfname, itselfname)
class TrackObjectDefinition(PEP253Mixin, GlobalObjectDefinition): class TrackObjectDefinition(QtGlobalObjectDefinition):
def outputCheckNewArg(self):
Output("""if (itself == NULL) {
PyErr_SetString(Qt_Error,"Cannot create null Track");
return NULL;
}""")
def outputFreeIt(self, itselfname): def outputFreeIt(self, itselfname):
Output("DisposeMovieTrack(%s);", itselfname) Output("if (%s) DisposeMovieTrack(%s);", itselfname, itselfname)
class MediaObjectDefinition(PEP253Mixin, GlobalObjectDefinition): class MediaObjectDefinition(QtGlobalObjectDefinition):
def outputCheckNewArg(self):
Output("""if (itself == NULL) {
PyErr_SetString(Qt_Error,"Cannot create null Media");
return NULL;
}""")
def outputFreeIt(self, itselfname): def outputFreeIt(self, itselfname):
Output("DisposeTrackMedia(%s);", itselfname) Output("if (%s) DisposeTrackMedia(%s);", itselfname, itselfname)
class UserDataObjectDefinition(PEP253Mixin, GlobalObjectDefinition): class UserDataObjectDefinition(QtGlobalObjectDefinition):
def outputCheckNewArg(self):
Output("""if (itself == NULL) {
PyErr_SetString(Qt_Error,"Cannot create null UserData");
return NULL;
}""")
def outputFreeIt(self, itselfname): def outputFreeIt(self, itselfname):
Output("DisposeUserData(%s);", itselfname) Output("if (%s) DisposeUserData(%s);", itselfname, itselfname)
class TimeBaseObjectDefinition(PEP253Mixin, GlobalObjectDefinition): class TimeBaseObjectDefinition(QtGlobalObjectDefinition):
def outputCheckNewArg(self): pass
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): class MovieCtlObjectDefinition(QtGlobalObjectDefinition):
def outputCheckNewArg(self):
Output("""if (itself == NULL) {
PyErr_SetString(Qt_Error,"Cannot create null MovieController");
return NULL;
}""")
def outputFreeIt(self, itselfname): def outputFreeIt(self, itselfname):
Output("DisposeMovieController(%s);", itselfname) Output("if (%s) DisposeMovieController(%s);", itselfname, itselfname)
class IdleManagerObjectDefinition(PEP253Mixin, GlobalObjectDefinition): class IdleManagerObjectDefinition(QtGlobalObjectDefinition):
def outputCheckNewArg(self): pass
Output("""if (itself == NULL) {
PyErr_SetString(Qt_Error,"Cannot create null IdleManager");
return NULL;
}""")
class SGOutputObjectDefinition(PEP253Mixin, GlobalObjectDefinition): class SGOutputObjectDefinition(QtGlobalObjectDefinition):
# XXXX I'm not sure I fully understand how SGOutput works. It seems it's always tied # 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 # 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 # routines that return an SGOutput actually return a *new* SGOutput. Need to read up on
# this. # this.
def outputCheckNewArg(self): pass
Output("""if (itself == NULL) {
PyErr_SetString(Qt_Error,"Cannot create null SGOutput");
return NULL;
}""")
# def outputFreeIt(self, itselfname):
# Output("SGDisposeOutput(%s);", itselfname)
# From here on it's basically all boiler plate... # From here on it's basically all boiler plate...
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment