@@ -348,8 +348,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
348
348
[pool release ];
349
349
}
350
350
351
- Py_INCREF (Py_None);
352
- return Py_None;
351
+ Py_RETURN_NONE;
353
352
}
354
353
355
354
static PyObject*
@@ -362,8 +361,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
362
361
return NULL ;
363
362
}
364
363
[view setNeedsDisplay: YES ];
365
- Py_INCREF (Py_None);
366
- return Py_None;
364
+ Py_RETURN_NONE;
367
365
}
368
366
369
367
static PyObject*
@@ -376,8 +374,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
376
374
return NULL ;
377
375
}
378
376
[view displayIfNeeded ];
379
- Py_INCREF (Py_None);
380
- return Py_None;
377
+ Py_RETURN_NONE;
381
378
}
382
379
383
380
static PyObject*
@@ -420,8 +417,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
420
417
}
421
418
422
419
[view setRubberband: rubberband];
423
- Py_INCREF (Py_None);
424
- return Py_None;
420
+ Py_RETURN_NONE;
425
421
}
426
422
427
423
static PyObject*
@@ -434,8 +430,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
434
430
return NULL ;
435
431
}
436
432
[view removeRubberband ];
437
- Py_INCREF (Py_None);
438
- return Py_None;
433
+ Py_RETURN_NONE;
439
434
}
440
435
441
436
static NSImage * _read_ppm_image (PyObject* obj)
@@ -546,8 +541,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
546
541
if (error==0 ) close (channel[1 ]);
547
542
if (interrupted) raise (SIGINT);
548
543
549
- Py_INCREF (Py_None);
550
- return Py_None;
544
+ Py_RETURN_NONE;
551
545
}
552
546
553
547
static PyObject*
@@ -563,8 +557,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
563
557
data1: 0
564
558
data2: 0 ];
565
559
[NSApp postEvent: event atStart: true ];
566
- Py_INCREF (Py_None);
567
- return Py_None;
560
+ Py_RETURN_NONE;
568
561
}
569
562
570
563
static PyMethodDef FigureCanvas_methods[] = {
@@ -770,8 +763,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
770
763
[window orderFrontRegardless ];
771
764
[pool release ];
772
765
}
773
- Py_INCREF (Py_None);
774
- return Py_None;
766
+ Py_RETURN_NONE;
775
767
}
776
768
777
769
static PyObject*
@@ -785,8 +777,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
785
777
[pool release ];
786
778
self->window = NULL ;
787
779
}
788
- Py_INCREF (Py_None);
789
- return Py_None;
780
+ Py_RETURN_NONE;
790
781
}
791
782
792
783
static PyObject*
@@ -808,8 +799,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
808
799
[pool release ];
809
800
}
810
801
PyMem_Free (title);
811
- Py_INCREF (Py_None);
812
- return Py_None;
802
+ Py_RETURN_NONE;
813
803
}
814
804
815
805
static PyObject*
@@ -830,8 +820,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
830
820
if (result) {
831
821
return result;
832
822
} else {
833
- Py_INCREF (Py_None);
834
- return Py_None;
823
+ Py_RETURN_NONE;
835
824
}
836
825
}
837
826
@@ -1280,8 +1269,7 @@ -(void)save_figure:(id)sender
1280
1269
[button setEnabled: YES ];
1281
1270
}
1282
1271
[pool release ];
1283
- Py_INCREF (Py_None);
1284
- return Py_None;
1272
+ Py_RETURN_NONE;
1285
1273
}
1286
1274
1287
1275
static PyObject*
@@ -1783,8 +1771,7 @@ -(void)save_figure:(id)sender
1783
1771
[pool release ];
1784
1772
}
1785
1773
1786
- Py_INCREF (Py_None);
1787
- return Py_None;
1774
+ Py_RETURN_NONE;
1788
1775
}
1789
1776
1790
1777
static PyMethodDef NavigationToolbar2_methods[] = {
@@ -1888,8 +1875,7 @@ -(void)save_figure:(id)sender
1888
1875
free (buffer);
1889
1876
return string;
1890
1877
}
1891
- Py_INCREF (Py_None);
1892
- return Py_None;
1878
+ Py_RETURN_NONE;
1893
1879
}
1894
1880
1895
1881
static PyObject*
@@ -1906,8 +1892,7 @@ -(void)save_figure:(id)sender
1906
1892
case 4 : break ;
1907
1893
default : return NULL ;
1908
1894
}
1909
- Py_INCREF (Py_None);
1910
- return Py_None;
1895
+ Py_RETURN_NONE;
1911
1896
}
1912
1897
1913
1898
@implementation WindowServerConnectionManager
@@ -2845,8 +2830,7 @@ - (int)index
2845
2830
Py_BEGIN_ALLOW_THREADS
2846
2831
[NSApp run ];
2847
2832
Py_END_ALLOW_THREADS
2848
- Py_INCREF (Py_None);
2849
- return Py_None;
2833
+ Py_RETURN_NONE;
2850
2834
}
2851
2835
2852
2836
typedef struct {
@@ -2883,10 +2867,19 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)
2883
2867
PyObject* method = info;
2884
2868
PyGILState_STATE gstate = PyGILState_Ensure ();
2885
2869
PyObject* result = PyObject_CallFunction (method, NULL );
2886
- if (result==NULL ) PyErr_Print ();
2870
+ if (result) {
2871
+ Py_DECREF (result);
2872
+ } else {
2873
+ PyErr_Print ();
2874
+ }
2887
2875
PyGILState_Release (gstate);
2888
2876
}
2889
2877
2878
+ static void context_cleanup (const void * info)
2879
+ {
2880
+ Py_DECREF ((PyObject*)info);
2881
+ }
2882
+
2890
2883
static PyObject*
2891
2884
Timer__timer_start (Timer* self, PyObject* args)
2892
2885
{
@@ -2902,10 +2895,6 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)
2902
2895
PyErr_SetString (PyExc_RuntimeError, " Failed to obtain run loop" );
2903
2896
return NULL ;
2904
2897
}
2905
- context.version = 0 ;
2906
- context.retain = 0 ;
2907
- context.release = 0 ;
2908
- context.copyDescription = 0 ;
2909
2898
attribute = PyObject_GetAttrString ((PyObject*)self, " _interval" );
2910
2899
if (attribute==NULL )
2911
2900
{
@@ -2934,6 +2923,7 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)
2934
2923
PyErr_SetString (PyExc_ValueError, " Cannot interpret _single attribute as True of False" );
2935
2924
return NULL ;
2936
2925
}
2926
+ Py_DECREF (attribute);
2937
2927
attribute = PyObject_GetAttrString ((PyObject*)self, " _on_timer" );
2938
2928
if (attribute==NULL )
2939
2929
{
@@ -2944,6 +2934,10 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)
2944
2934
PyErr_SetString (PyExc_RuntimeError, " _on_timer should be a Python method" );
2945
2935
return NULL ;
2946
2936
}
2937
+ context.version = 0 ;
2938
+ context.retain = NULL ;
2939
+ context.release = context_cleanup;
2940
+ context.copyDescription = NULL ;
2947
2941
context.info = attribute;
2948
2942
timer = CFRunLoopTimerCreate (kCFAllocatorDefault ,
2949
2943
0 ,
@@ -2953,44 +2947,31 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)
2953
2947
timer_callback,
2954
2948
&context);
2955
2949
if (!timer) {
2950
+ Py_DECREF (attribute);
2956
2951
PyErr_SetString (PyExc_RuntimeError, " Failed to create timer" );
2957
2952
return NULL ;
2958
2953
}
2959
- Py_INCREF (attribute);
2960
2954
if (self->timer ) {
2961
- CFRunLoopTimerGetContext (self->timer , &context);
2962
- attribute = context.info ;
2963
- Py_DECREF (attribute);
2964
- CFRunLoopRemoveTimer (runloop, self->timer , kCFRunLoopCommonModes );
2955
+ CFRunLoopTimerInvalidate (self->timer );
2965
2956
CFRelease (self->timer );
2966
2957
}
2967
2958
CFRunLoopAddTimer (runloop, timer, kCFRunLoopCommonModes );
2968
2959
/* Don't release the timer here, since the run loop may be destroyed and
2969
2960
* the timer lost before we have a chance to decrease the reference count
2970
2961
* of the attribute */
2971
2962
self->timer = timer;
2972
- Py_INCREF (Py_None);
2973
- return Py_None;
2963
+ Py_RETURN_NONE;
2974
2964
}
2975
2965
2976
2966
static PyObject*
2977
2967
Timer__timer_stop (Timer* self)
2978
2968
{
2979
2969
if (self->timer ) {
2980
- PyObject* attribute;
2981
- CFRunLoopTimerContext context;
2982
- CFRunLoopTimerGetContext (self->timer , &context);
2983
- attribute = context.info ;
2984
- Py_DECREF (attribute);
2985
- CFRunLoopRef runloop = CFRunLoopGetCurrent ();
2986
- if (runloop) {
2987
- CFRunLoopRemoveTimer (runloop, self->timer , kCFRunLoopCommonModes );
2988
- }
2970
+ CFRunLoopTimerInvalidate (self->timer );
2989
2971
CFRelease (self->timer );
2990
2972
self->timer = NULL ;
2991
2973
}
2992
- Py_INCREF (Py_None);
2993
- return Py_None;
2974
+ Py_RETURN_NONE;
2994
2975
}
2995
2976
2996
2977
static void
0 commit comments