@@ -1672,26 +1672,15 @@ -(void)drawRect:(NSRect)rect
1672
1672
goto exit ;
1673
1673
}
1674
1674
}
1675
-
1676
- renderer = PyObject_CallMethod (canvas, " _draw" , " " , NULL );
1677
- if (!renderer)
1678
- {
1675
+ if (!(renderer = PyObject_CallMethod (canvas, " _draw" , " " , NULL ))
1676
+ || !(renderer_buffer = PyObject_GetAttrString (renderer, " _renderer" ))) {
1679
1677
PyErr_Print ();
1680
1678
goto exit ;
1681
1679
}
1682
-
1683
- renderer_buffer = PyObject_GetAttrString (renderer, " _renderer" );
1684
- if (!renderer_buffer) {
1685
- PyErr_Print ();
1686
- goto exit ;
1687
- }
1688
-
1689
1680
if (_copy_agg_buffer (cr, renderer_buffer)) {
1690
1681
printf (" copy_agg_buffer failed\n " );
1691
1682
goto exit ;
1692
1683
}
1693
-
1694
-
1695
1684
if (!NSIsEmptyRect (rubberband)) {
1696
1685
NSFrameRect (rubberband);
1697
1686
}
@@ -2391,63 +2380,37 @@ static void context_cleanup(const void* info)
2391
2380
CFRunLoopRef runloop;
2392
2381
CFRunLoopTimerRef timer;
2393
2382
CFRunLoopTimerContext context;
2394
- double milliseconds;
2395
2383
CFAbsoluteTime firstFire;
2396
2384
CFTimeInterval interval;
2397
- PyObject* attribute ;
2398
- PyObject* failure ;
2385
+ PyObject* py_interval = NULL , * py_single = NULL , * py_on_timer = NULL ;
2386
+ int single ;
2399
2387
runloop = CFRunLoopGetCurrent ();
2400
2388
if (!runloop) {
2401
2389
PyErr_SetString (PyExc_RuntimeError, " Failed to obtain run loop" );
2402
2390
return NULL ;
2403
2391
}
2404
- attribute = PyObject_GetAttrString ((PyObject*)self, " _interval" );
2405
- if (attribute==NULL )
2406
- {
2407
- PyErr_SetString (PyExc_AttributeError, " Timer has no attribute '_interval'" );
2408
- return NULL ;
2409
- }
2410
- milliseconds = PyFloat_AsDouble (attribute);
2411
- failure = PyErr_Occurred ();
2412
- Py_DECREF (attribute);
2413
- if (failure) return NULL ;
2414
- attribute = PyObject_GetAttrString ((PyObject*)self, " _single" );
2415
- if (attribute==NULL )
2416
- {
2417
- PyErr_SetString (PyExc_AttributeError, " Timer has no attribute '_single'" );
2418
- return NULL ;
2392
+ if (!(py_interval = PyObject_GetAttrString ((PyObject*)self, " _interval" ))
2393
+ || ((interval = PyFloat_AsDouble (py_interval) / 1000 .), PyErr_Occurred ())
2394
+ || !(py_single = PyObject_GetAttrString ((PyObject*)self, " _single" ))
2395
+ || ((single = PyObject_IsTrue (py_single)) == -1 )
2396
+ || !(py_on_timer = PyObject_GetAttrString ((PyObject*)self, " _on_timer" ))) {
2397
+ goto exit ;
2419
2398
}
2420
- // Need to tell when to first fire this timer, so get the current time
2421
- // and add an interval.
2422
- interval = milliseconds / 1000.0 ;
2399
+ // (current time + interval) is time of first fire.
2423
2400
firstFire = CFAbsoluteTimeGetCurrent () + interval;
2424
- switch (PyObject_IsTrue (attribute)) {
2425
- case 1 :
2426
- interval = 0 ;
2427
- break ;
2428
- case 0 : // Set by default above
2429
- break ;
2430
- case -1 :
2431
- default :
2432
- PyErr_SetString (PyExc_ValueError, " Cannot interpret _single attribute as True of False" );
2433
- return NULL ;
2434
- }
2435
- Py_DECREF (attribute);
2436
- attribute = PyObject_GetAttrString ((PyObject*)self, " _on_timer" );
2437
- if (attribute==NULL )
2438
- {
2439
- PyErr_SetString (PyExc_AttributeError, " Timer has no attribute '_on_timer'" );
2440
- return NULL ;
2401
+ if (single) {
2402
+ interval = 0 ;
2441
2403
}
2442
- if (!PyMethod_Check (attribute )) {
2404
+ if (!PyMethod_Check (py_on_timer )) {
2443
2405
PyErr_SetString (PyExc_RuntimeError, " _on_timer should be a Python method" );
2444
- return NULL ;
2406
+ goto exit ;
2445
2407
}
2408
+ Py_INCREF (py_on_timer);
2446
2409
context.version = 0 ;
2447
2410
context.retain = NULL ;
2448
2411
context.release = context_cleanup;
2449
2412
context.copyDescription = NULL ;
2450
- context.info = attribute ;
2413
+ context.info = py_on_timer ;
2451
2414
timer = CFRunLoopTimerCreate (kCFAllocatorDefault ,
2452
2415
firstFire,
2453
2416
interval,
@@ -2456,9 +2419,8 @@ static void context_cleanup(const void* info)
2456
2419
timer_callback,
2457
2420
&context);
2458
2421
if (!timer) {
2459
- Py_DECREF (attribute);
2460
2422
PyErr_SetString (PyExc_RuntimeError, " Failed to create timer" );
2461
- return NULL ;
2423
+ goto exit ;
2462
2424
}
2463
2425
if (self->timer ) {
2464
2426
CFRunLoopTimerInvalidate (self->timer );
@@ -2469,7 +2431,15 @@ static void context_cleanup(const void* info)
2469
2431
* the timer lost before we have a chance to decrease the reference count
2470
2432
* of the attribute */
2471
2433
self->timer = timer;
2472
- Py_RETURN_NONE;
2434
+ exit :
2435
+ Py_XDECREF (py_interval);
2436
+ Py_XDECREF (py_single);
2437
+ Py_XDECREF (py_on_timer);
2438
+ if (PyErr_Occurred ()) {
2439
+ return NULL ;
2440
+ } else {
2441
+ Py_RETURN_NONE;
2442
+ }
2473
2443
}
2474
2444
2475
2445
static PyObject*
0 commit comments