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

Skip to content

Commit cb2117a

Browse files
committed
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.
1 parent c14149e commit cb2117a

2 files changed

Lines changed: 88 additions & 69 deletions

File tree

Mac/Modules/qt/_Qtmodule.c

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ PyObject *IdleManagerObj_New(IdleManager itself)
9898
{
9999
IdleManagerObject *it;
100100
if (itself == NULL) {
101-
PyErr_SetString(Qt_Error,"Cannot create null IdleManager");
101+
PyErr_SetString(Qt_Error,"Cannot create IdleManager from NULL pointer");
102102
return NULL;
103103
}
104104
it = PyObject_NEW(IdleManagerObject, &IdleManager_Type);
@@ -108,6 +108,11 @@ PyObject *IdleManagerObj_New(IdleManager itself)
108108
}
109109
int IdleManagerObj_Convert(PyObject *v, IdleManager *p_itself)
110110
{
111+
if (v == Py_None)
112+
{
113+
*p_itself = NULL;
114+
return 1;
115+
}
111116
if (!IdleManagerObj_Check(v))
112117
{
113118
PyErr_SetString(PyExc_TypeError, "IdleManager required");
@@ -216,7 +221,7 @@ PyObject *MovieCtlObj_New(MovieController itself)
216221
{
217222
MovieControllerObject *it;
218223
if (itself == NULL) {
219-
PyErr_SetString(Qt_Error,"Cannot create null MovieController");
224+
PyErr_SetString(Qt_Error,"Cannot create MovieController from NULL pointer");
220225
return NULL;
221226
}
222227
it = PyObject_NEW(MovieControllerObject, &MovieController_Type);
@@ -226,6 +231,11 @@ PyObject *MovieCtlObj_New(MovieController itself)
226231
}
227232
int MovieCtlObj_Convert(PyObject *v, MovieController *p_itself)
228233
{
234+
if (v == Py_None)
235+
{
236+
*p_itself = NULL;
237+
return 1;
238+
}
229239
if (!MovieCtlObj_Check(v))
230240
{
231241
PyErr_SetString(PyExc_TypeError, "MovieController required");
@@ -237,7 +247,7 @@ int MovieCtlObj_Convert(PyObject *v, MovieController *p_itself)
237247

238248
static void MovieCtlObj_dealloc(MovieControllerObject *self)
239249
{
240-
DisposeMovieController(self->ob_itself);
250+
if (self->ob_itself) DisposeMovieController(self->ob_itself);
241251
self->ob_type->tp_free((PyObject *)self);
242252
}
243253

@@ -1330,7 +1340,7 @@ PyObject *TimeBaseObj_New(TimeBase itself)
13301340
{
13311341
TimeBaseObject *it;
13321342
if (itself == NULL) {
1333-
PyErr_SetString(Qt_Error,"Cannot create null TimeBase");
1343+
PyErr_SetString(Qt_Error,"Cannot create TimeBase from NULL pointer");
13341344
return NULL;
13351345
}
13361346
it = PyObject_NEW(TimeBaseObject, &TimeBase_Type);
@@ -1340,6 +1350,11 @@ PyObject *TimeBaseObj_New(TimeBase itself)
13401350
}
13411351
int TimeBaseObj_Convert(PyObject *v, TimeBase *p_itself)
13421352
{
1353+
if (v == Py_None)
1354+
{
1355+
*p_itself = NULL;
1356+
return 1;
1357+
}
13431358
if (!TimeBaseObj_Check(v))
13441359
{
13451360
PyErr_SetString(PyExc_TypeError, "TimeBase required");
@@ -1818,7 +1833,7 @@ PyObject *UserDataObj_New(UserData itself)
18181833
{
18191834
UserDataObject *it;
18201835
if (itself == NULL) {
1821-
PyErr_SetString(Qt_Error,"Cannot create null UserData");
1836+
PyErr_SetString(Qt_Error,"Cannot create UserData from NULL pointer");
18221837
return NULL;
18231838
}
18241839
it = PyObject_NEW(UserDataObject, &UserData_Type);
@@ -1828,6 +1843,11 @@ PyObject *UserDataObj_New(UserData itself)
18281843
}
18291844
int UserDataObj_Convert(PyObject *v, UserData *p_itself)
18301845
{
1846+
if (v == Py_None)
1847+
{
1848+
*p_itself = NULL;
1849+
return 1;
1850+
}
18311851
if (!UserDataObj_Check(v))
18321852
{
18331853
PyErr_SetString(PyExc_TypeError, "UserData required");
@@ -1839,7 +1859,7 @@ int UserDataObj_Convert(PyObject *v, UserData *p_itself)
18391859

18401860
static void UserDataObj_dealloc(UserDataObject *self)
18411861
{
1842-
DisposeUserData(self->ob_itself);
1862+
if (self->ob_itself) DisposeUserData(self->ob_itself);
18431863
self->ob_type->tp_free((PyObject *)self);
18441864
}
18451865

@@ -2183,7 +2203,7 @@ PyObject *MediaObj_New(Media itself)
21832203
{
21842204
MediaObject *it;
21852205
if (itself == NULL) {
2186-
PyErr_SetString(Qt_Error,"Cannot create null Media");
2206+
PyErr_SetString(Qt_Error,"Cannot create Media from NULL pointer");
21872207
return NULL;
21882208
}
21892209
it = PyObject_NEW(MediaObject, &Media_Type);
@@ -2193,6 +2213,11 @@ PyObject *MediaObj_New(Media itself)
21932213
}
21942214
int MediaObj_Convert(PyObject *v, Media *p_itself)
21952215
{
2216+
if (v == Py_None)
2217+
{
2218+
*p_itself = NULL;
2219+
return 1;
2220+
}
21962221
if (!MediaObj_Check(v))
21972222
{
21982223
PyErr_SetString(PyExc_TypeError, "Media required");
@@ -2204,7 +2229,7 @@ int MediaObj_Convert(PyObject *v, Media *p_itself)
22042229

22052230
static void MediaObj_dealloc(MediaObject *self)
22062231
{
2207-
DisposeTrackMedia(self->ob_itself);
2232+
if (self->ob_itself) DisposeTrackMedia(self->ob_itself);
22082233
self->ob_type->tp_free((PyObject *)self);
22092234
}
22102235

@@ -3419,7 +3444,7 @@ PyObject *TrackObj_New(Track itself)
34193444
{
34203445
TrackObject *it;
34213446
if (itself == NULL) {
3422-
PyErr_SetString(Qt_Error,"Cannot create null Track");
3447+
PyErr_SetString(Qt_Error,"Cannot create Track from NULL pointer");
34233448
return NULL;
34243449
}
34253450
it = PyObject_NEW(TrackObject, &Track_Type);
@@ -3429,6 +3454,11 @@ PyObject *TrackObj_New(Track itself)
34293454
}
34303455
int TrackObj_Convert(PyObject *v, Track *p_itself)
34313456
{
3457+
if (v == Py_None)
3458+
{
3459+
*p_itself = NULL;
3460+
return 1;
3461+
}
34323462
if (!TrackObj_Check(v))
34333463
{
34343464
PyErr_SetString(PyExc_TypeError, "Track required");
@@ -3440,7 +3470,7 @@ int TrackObj_Convert(PyObject *v, Track *p_itself)
34403470

34413471
static void TrackObj_dealloc(TrackObject *self)
34423472
{
3443-
DisposeMovieTrack(self->ob_itself);
3473+
if (self->ob_itself) DisposeMovieTrack(self->ob_itself);
34443474
self->ob_type->tp_free((PyObject *)self);
34453475
}
34463476

@@ -4761,7 +4791,7 @@ PyObject *MovieObj_New(Movie itself)
47614791
{
47624792
MovieObject *it;
47634793
if (itself == NULL) {
4764-
PyErr_SetString(Qt_Error,"Cannot create null Movie");
4794+
PyErr_SetString(Qt_Error,"Cannot create Movie from NULL pointer");
47654795
return NULL;
47664796
}
47674797
it = PyObject_NEW(MovieObject, &Movie_Type);
@@ -4771,6 +4801,11 @@ PyObject *MovieObj_New(Movie itself)
47714801
}
47724802
int MovieObj_Convert(PyObject *v, Movie *p_itself)
47734803
{
4804+
if (v == Py_None)
4805+
{
4806+
*p_itself = NULL;
4807+
return 1;
4808+
}
47744809
if (!MovieObj_Check(v))
47754810
{
47764811
PyErr_SetString(PyExc_TypeError, "Movie required");
@@ -4782,7 +4817,7 @@ int MovieObj_Convert(PyObject *v, Movie *p_itself)
47824817

47834818
static void MovieObj_dealloc(MovieObject *self)
47844819
{
4785-
DisposeMovie(self->ob_itself);
4820+
if (self->ob_itself) DisposeMovie(self->ob_itself);
47864821
self->ob_type->tp_free((PyObject *)self);
47874822
}
47884823

@@ -7308,7 +7343,7 @@ PyObject *SGOutputObj_New(SGOutput itself)
73087343
{
73097344
SGOutputObject *it;
73107345
if (itself == NULL) {
7311-
PyErr_SetString(Qt_Error,"Cannot create null SGOutput");
7346+
PyErr_SetString(Qt_Error,"Cannot create SGOutput from NULL pointer");
73127347
return NULL;
73137348
}
73147349
it = PyObject_NEW(SGOutputObject, &SGOutput_Type);
@@ -7318,6 +7353,11 @@ PyObject *SGOutputObj_New(SGOutput itself)
73187353
}
73197354
int SGOutputObj_Convert(PyObject *v, SGOutput *p_itself)
73207355
{
7356+
if (v == Py_None)
7357+
{
7358+
*p_itself = NULL;
7359+
return 1;
7360+
}
73217361
if (!SGOutputObj_Check(v))
73227362
{
73237363
PyErr_SetString(PyExc_TypeError, "SGOutput required");

Mac/Modules/qt/qtsupport.py

Lines changed: 35 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -205,79 +205,58 @@
205205
dummyshortptr = FakeType('(short *)0')
206206
dummyStringPtr = FakeType('(StringPtr)0')
207207

208-
class MovieObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
208+
# XXXX Need to override output_tp_newBody() to allow for None initializer.
209+
class QtGlobalObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
209210
def outputCheckNewArg(self):
211+
# We don't allow NULL pointers to be returned by QuickTime API calls,
212+
# in stead we raise an exception
210213
Output("""if (itself == NULL) {
211-
PyErr_SetString(Qt_Error,"Cannot create null Movie");
214+
PyErr_SetString(Qt_Error,"Cannot create %s from NULL pointer");
212215
return NULL;
213-
}""")
216+
}""", self.name)
217+
218+
def outputCheckConvertArg(self):
219+
# But what we do allow is passing None whereever a quicktime object is
220+
# expected, and pass this as NULL to the API routines. Note you can
221+
# call methods too by creating an object with None as the initializer.
222+
Output("if (v == Py_None)")
223+
OutLbrace()
224+
Output("*p_itself = NULL;")
225+
Output("return 1;")
226+
OutRbrace()
227+
228+
class MovieObjectDefinition(QtGlobalObjectDefinition):
214229
def outputFreeIt(self, itselfname):
215-
Output("DisposeMovie(%s);", itselfname)
230+
Output("if (%s) DisposeMovie(%s);", itselfname, itselfname)
216231

217-
class TrackObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
218-
def outputCheckNewArg(self):
219-
Output("""if (itself == NULL) {
220-
PyErr_SetString(Qt_Error,"Cannot create null Track");
221-
return NULL;
222-
}""")
232+
class TrackObjectDefinition(QtGlobalObjectDefinition):
223233
def outputFreeIt(self, itselfname):
224-
Output("DisposeMovieTrack(%s);", itselfname)
234+
Output("if (%s) DisposeMovieTrack(%s);", itselfname, itselfname)
225235

226-
class MediaObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
227-
def outputCheckNewArg(self):
228-
Output("""if (itself == NULL) {
229-
PyErr_SetString(Qt_Error,"Cannot create null Media");
230-
return NULL;
231-
}""")
236+
class MediaObjectDefinition(QtGlobalObjectDefinition):
232237
def outputFreeIt(self, itselfname):
233-
Output("DisposeTrackMedia(%s);", itselfname)
238+
Output("if (%s) DisposeTrackMedia(%s);", itselfname, itselfname)
234239

235-
class UserDataObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
236-
def outputCheckNewArg(self):
237-
Output("""if (itself == NULL) {
238-
PyErr_SetString(Qt_Error,"Cannot create null UserData");
239-
return NULL;
240-
}""")
240+
class UserDataObjectDefinition(QtGlobalObjectDefinition):
241241
def outputFreeIt(self, itselfname):
242-
Output("DisposeUserData(%s);", itselfname)
242+
Output("if (%s) DisposeUserData(%s);", itselfname, itselfname)
243243

244-
class TimeBaseObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
245-
def outputCheckNewArg(self):
246-
Output("""if (itself == NULL) {
247-
PyErr_SetString(Qt_Error,"Cannot create null TimeBase");
248-
return NULL;
249-
}""")
250-
## def outputFreeIt(self, itselfname):
251-
## Output("DisposeTimeBase(%s);", itselfname)
252-
253-
class MovieCtlObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
254-
def outputCheckNewArg(self):
255-
Output("""if (itself == NULL) {
256-
PyErr_SetString(Qt_Error,"Cannot create null MovieController");
257-
return NULL;
258-
}""")
244+
class TimeBaseObjectDefinition(QtGlobalObjectDefinition):
245+
pass
246+
247+
class MovieCtlObjectDefinition(QtGlobalObjectDefinition):
259248
def outputFreeIt(self, itselfname):
260-
Output("DisposeMovieController(%s);", itselfname)
249+
Output("if (%s) DisposeMovieController(%s);", itselfname, itselfname)
261250

262-
class IdleManagerObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
263-
def outputCheckNewArg(self):
264-
Output("""if (itself == NULL) {
265-
PyErr_SetString(Qt_Error,"Cannot create null IdleManager");
266-
return NULL;
267-
}""")
268-
269-
class SGOutputObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
251+
class IdleManagerObjectDefinition(QtGlobalObjectDefinition):
252+
pass
253+
254+
class SGOutputObjectDefinition(QtGlobalObjectDefinition):
270255
# XXXX I'm not sure I fully understand how SGOutput works. It seems it's always tied
271256
# to a specific SeqGrabComponent, but I'm not 100% sure. Also, I'm not sure all the
272257
# routines that return an SGOutput actually return a *new* SGOutput. Need to read up on
273258
# this.
274-
def outputCheckNewArg(self):
275-
Output("""if (itself == NULL) {
276-
PyErr_SetString(Qt_Error,"Cannot create null SGOutput");
277-
return NULL;
278-
}""")
279-
# def outputFreeIt(self, itselfname):
280-
# Output("SGDisposeOutput(%s);", itselfname)
259+
pass
281260

282261

283262
# From here on it's basically all boiler plate...

0 commit comments

Comments
 (0)