Skip to content

Commit db7414b

Browse files
authored
Merge pull request numpy#22419 from HaoZeke/minorMaint
MAINT: Remove PyCObject from the SWIG interface
2 parents 241c905 + 9828092 commit db7414b

File tree

1 file changed

+32
-90
lines changed

1 file changed

+32
-90
lines changed

tools/swig/numpy.i

Lines changed: 32 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
%fragment("NumPy_Backward_Compatibility", "header")
5050
{
51-
%#if NPY_API_VERSION < 0x00000007
51+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
5252
%#define NPY_ARRAY_DEFAULT NPY_DEFAULT
5353
%#define NPY_ARRAY_FARRAY NPY_FARRAY
5454
%#define NPY_FORTRANORDER NPY_FORTRAN
@@ -69,7 +69,7 @@
6969
{
7070
/* Macros to extract array attributes.
7171
*/
72-
%#if NPY_API_VERSION < 0x00000007
72+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
7373
%#define is_array(a) ((a) && PyArray_Check((PyArrayObject*)a))
7474
%#define array_type(a) (int)(PyArray_TYPE((PyArrayObject*)a))
7575
%#define array_numdims(a) (((PyArrayObject*)a)->nd)
@@ -165,13 +165,11 @@
165165
return PyArray_EquivTypenums(actual_type, desired_type);
166166
}
167167

168-
%#ifdef SWIGPY_USE_CAPSULE
169-
void free_cap(PyObject * cap)
168+
void free_cap(PyObject * cap)
170169
{
171170
void* array = (void*) PyCapsule_GetPointer(cap,SWIGPY_CAPSULE_NAME);
172171
if (array != NULL) free(array);
173172
}
174-
%#endif
175173

176174

177175
}
@@ -293,7 +291,7 @@
293291
Py_INCREF(array_descr(ary));
294292
result = (PyArrayObject*) PyArray_FromArray(ary,
295293
array_descr(ary),
296-
%#if NPY_API_VERSION < 0x00000007
294+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
297295
NPY_FORTRANORDER);
298296
%#else
299297
NPY_ARRAY_F_CONTIGUOUS);
@@ -2459,13 +2457,9 @@
24592457

24602458
if (!array) SWIG_fail;
24612459

2462-
%#ifdef SWIGPY_USE_CAPSULE
2463-
PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2464-
%#else
2465-
PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2466-
%#endif
2460+
PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
24672461

2468-
%#if NPY_API_VERSION < 0x00000007
2462+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
24692463
PyArray_BASE(array) = cap;
24702464
%#else
24712465
PyArray_SetBaseObject(array,cap);
@@ -2493,13 +2487,9 @@
24932487

24942488
if (!array) SWIG_fail;
24952489

2496-
%#ifdef SWIGPY_USE_CAPSULE
2497-
PyObject* cap = PyCapsule_New((void*)(*$2), SWIGPY_CAPSULE_NAME, free_cap);
2498-
%#else
2499-
PyObject* cap = PyCObject_FromVoidPtr((void*)(*$2), free);
2500-
%#endif
2490+
PyObject* cap = PyCapsule_New((void*)(*$2), SWIGPY_CAPSULE_NAME, free_cap);
25012491

2502-
%#if NPY_API_VERSION < 0x00000007
2492+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
25032493
PyArray_BASE(array) = cap;
25042494
%#else
25052495
PyArray_SetBaseObject(array,cap);
@@ -2528,13 +2518,9 @@
25282518

25292519
if (!array) SWIG_fail;
25302520

2531-
%#ifdef SWIGPY_USE_CAPSULE
2532-
PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2533-
%#else
2534-
PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2535-
%#endif
2521+
PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
25362522

2537-
%#if NPY_API_VERSION < 0x00000007
2523+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
25382524
PyArray_BASE(array) = cap;
25392525
%#else
25402526
PyArray_SetBaseObject(array,cap);
@@ -2563,13 +2549,9 @@
25632549

25642550
if (!array) SWIG_fail;
25652551

2566-
%#ifdef SWIGPY_USE_CAPSULE
2567-
PyObject* cap = PyCapsule_New((void*)(*$3), SWIGPY_CAPSULE_NAME, free_cap);
2568-
%#else
2569-
PyObject* cap = PyCObject_FromVoidPtr((void*)(*$3), free);
2570-
%#endif
2552+
PyObject* cap = PyCapsule_New((void*)(*$3), SWIGPY_CAPSULE_NAME, free_cap);
25712553

2572-
%#if NPY_API_VERSION < 0x00000007
2554+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
25732555
PyArray_BASE(array) = cap;
25742556
%#else
25752557
PyArray_SetBaseObject(array,cap);
@@ -2598,13 +2580,9 @@
25982580

25992581
if (!array || !require_fortran(array)) SWIG_fail;
26002582

2601-
%#ifdef SWIGPY_USE_CAPSULE
2602-
PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2603-
%#else
2604-
PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2605-
%#endif
2583+
PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
26062584

2607-
%#if NPY_API_VERSION < 0x00000007
2585+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
26082586
PyArray_BASE(array) = cap;
26092587
%#else
26102588
PyArray_SetBaseObject(array,cap);
@@ -2633,13 +2611,9 @@
26332611

26342612
if (!array || !require_fortran(array)) SWIG_fail;
26352613

2636-
%#ifdef SWIGPY_USE_CAPSULE
2637-
PyObject* cap = PyCapsule_New((void*)(*$3), SWIGPY_CAPSULE_NAME, free_cap);
2638-
%#else
2639-
PyObject* cap = PyCObject_FromVoidPtr((void*)(*$3), free);
2640-
%#endif
2614+
PyObject* cap = PyCapsule_New((void*)(*$3), SWIGPY_CAPSULE_NAME, free_cap);
26412615

2642-
%#if NPY_API_VERSION < 0x00000007
2616+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
26432617
PyArray_BASE(array) = cap;
26442618
%#else
26452619
PyArray_SetBaseObject(array,cap);
@@ -2670,13 +2644,9 @@
26702644

26712645
if (!array) SWIG_fail;
26722646

2673-
%#ifdef SWIGPY_USE_CAPSULE
2674-
PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2675-
%#else
2676-
PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2677-
%#endif
2647+
PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
26782648

2679-
%#if NPY_API_VERSION < 0x00000007
2649+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
26802650
PyArray_BASE(array) = cap;
26812651
%#else
26822652
PyArray_SetBaseObject(array,cap);
@@ -2707,13 +2677,9 @@
27072677

27082678
if (!array) SWIG_fail;
27092679

2710-
%#ifdef SWIGPY_USE_CAPSULE
2711-
PyObject* cap = PyCapsule_New((void*)(*$4), SWIGPY_CAPSULE_NAME, free_cap);
2712-
%#else
2713-
PyObject* cap = PyCObject_FromVoidPtr((void*)(*$4), free);
2714-
%#endif
2680+
PyObject* cap = PyCapsule_New((void*)(*$4), SWIGPY_CAPSULE_NAME, free_cap);
27152681

2716-
%#if NPY_API_VERSION < 0x00000007
2682+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
27172683
PyArray_BASE(array) = cap;
27182684
%#else
27192685
PyArray_SetBaseObject(array,cap);
@@ -2744,13 +2710,9 @@
27442710

27452711
if (!array || !require_fortran(array)) SWIG_fail;
27462712

2747-
%#ifdef SWIGPY_USE_CAPSULE
2748-
PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2749-
%#else
2750-
PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2751-
%#endif
2713+
PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
27522714

2753-
%#if NPY_API_VERSION < 0x00000007
2715+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
27542716
PyArray_BASE(array) = cap;
27552717
%#else
27562718
PyArray_SetBaseObject(array,cap);
@@ -2781,13 +2743,9 @@
27812743

27822744
if (!array || !require_fortran(array)) SWIG_fail;
27832745

2784-
%#ifdef SWIGPY_USE_CAPSULE
2785-
PyObject* cap = PyCapsule_New((void*)(*$4), SWIGPY_CAPSULE_NAME, free_cap);
2786-
%#else
2787-
PyObject* cap = PyCObject_FromVoidPtr((void*)(*$4), free);
2788-
%#endif
2746+
PyObject* cap = PyCapsule_New((void*)(*$4), SWIGPY_CAPSULE_NAME, free_cap);
27892747

2790-
%#if NPY_API_VERSION < 0x00000007
2748+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
27912749
PyArray_BASE(array) = cap;
27922750
%#else
27932751
PyArray_SetBaseObject(array,cap);
@@ -2819,13 +2777,9 @@
28192777

28202778
if (!array) SWIG_fail;
28212779

2822-
%#ifdef SWIGPY_USE_CAPSULE
2823-
PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2824-
%#else
2825-
PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2826-
%#endif
2780+
PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
28272781

2828-
%#if NPY_API_VERSION < 0x00000007
2782+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
28292783
PyArray_BASE(array) = cap;
28302784
%#else
28312785
PyArray_SetBaseObject(array,cap);
@@ -2857,13 +2811,9 @@
28572811

28582812
if (!array) SWIG_fail;
28592813

2860-
%#ifdef SWIGPY_USE_CAPSULE
2861-
PyObject* cap = PyCapsule_New((void*)(*$5), SWIGPY_CAPSULE_NAME, free_cap);
2862-
%#else
2863-
PyObject* cap = PyCObject_FromVoidPtr((void*)(*$5), free);
2864-
%#endif
2814+
PyObject* cap = PyCapsule_New((void*)(*$5), SWIGPY_CAPSULE_NAME, free_cap);
28652815

2866-
%#if NPY_API_VERSION < 0x00000007
2816+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
28672817
PyArray_BASE(array) = cap;
28682818
%#else
28692819
PyArray_SetBaseObject(array,cap);
@@ -2895,13 +2845,9 @@
28952845

28962846
if (!array || !require_fortran(array)) SWIG_fail;
28972847

2898-
%#ifdef SWIGPY_USE_CAPSULE
2899-
PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2900-
%#else
2901-
PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2902-
%#endif
2848+
PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
29032849

2904-
%#if NPY_API_VERSION < 0x00000007
2850+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
29052851
PyArray_BASE(array) = cap;
29062852
%#else
29072853
PyArray_SetBaseObject(array,cap);
@@ -2933,13 +2879,9 @@
29332879

29342880
if (!array || !require_fortran(array)) SWIG_fail;
29352881

2936-
%#ifdef SWIGPY_USE_CAPSULE
2937-
PyObject* cap = PyCapsule_New((void*)(*$5), SWIGPY_CAPSULE_NAME, free_cap);
2938-
%#else
2939-
PyObject* cap = PyCObject_FromVoidPtr((void*)(*$5), free);
2940-
%#endif
2882+
PyObject* cap = PyCapsule_New((void*)(*$5), SWIGPY_CAPSULE_NAME, free_cap);
29412883

2942-
%#if NPY_API_VERSION < 0x00000007
2884+
%#if NPY_API_VERSION < NPY_1_7_API_VERSION
29432885
PyArray_BASE(array) = cap;
29442886
%#else
29452887
PyArray_SetBaseObject(array,cap);

0 commit comments

Comments
 (0)