Skip to content

Commit bab245d

Browse files
committed
Use unique symbol for ufunc API
1 parent b6edc01 commit bab245d

File tree

30 files changed

+93
-95
lines changed

30 files changed

+93
-95
lines changed

asciidtype/asciidtype/src/asciidtype_main.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include <Python.h>
22

33
#define PY_ARRAY_UNIQUE_SYMBOL asciidtype_ARRAY_API
4+
#define PY_UFUNC_UNIQUE_SYMBOL asciidtype_UFUNC_API
45
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
56
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
67
#include "numpy/ndarraytypes.h"
78
#include "numpy/arrayobject.h"
9+
#include "numpy/ufuncobject.h"
810
#include "numpy/dtype_api.h"
911

1012
#include "dtype.h"
@@ -21,6 +23,7 @@ PyMODINIT_FUNC
2123
PyInit__asciidtype_main(void)
2224
{
2325
import_array();
26+
import_umath();
2427

2528
PyObject *m = PyModule_Create(&moduledef);
2629
if (m == NULL) {
@@ -47,14 +50,10 @@ PyInit__asciidtype_main(void)
4750
goto error;
4851
}
4952

50-
PyObject *numpy = init_ufuncs();
51-
52-
if (numpy == NULL) {
53+
if (init_ufuncs() == -1) {
5354
goto error;
5455
}
5556

56-
Py_DECREF(numpy);
57-
5857
return m;
5958

6059
error:

asciidtype/asciidtype/src/casts.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include <Python.h>
22

33
#define PY_ARRAY_UNIQUE_SYMBOL asciidtype_ARRAY_API
4+
#define PY_UFUNC_UNIQUE_SYMBOL asciidtype_UFUNC_API
45
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
56
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
67
#define NO_IMPORT_ARRAY
8+
#define NO_IMPORT_UFUNC
79
#include "numpy/arrayobject.h"
810
#include "numpy/dtype_api.h"
911
#include "numpy/ndarraytypes.h"

asciidtype/asciidtype/src/dtype.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
// clang-format on
55

66
#define PY_ARRAY_UNIQUE_SYMBOL asciidtype_ARRAY_API
7+
#define PY_UFUNC_UNIQUE_SYMBOL asciidtype_UFUNC_API
78
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
89
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
910
#define NO_IMPORT_ARRAY
11+
#define NO_IMPORT_UFUNC
1012
#include "numpy/ndarraytypes.h"
1113
#include "numpy/arrayobject.h"
1214
#include "numpy/ufuncobject.h"

asciidtype/asciidtype/src/umath.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include <Python.h>
22

33
#define PY_ARRAY_UNIQUE_SYMBOL asciidtype_ARRAY_API
4+
#define PY_UFUNC_UNIQUE_SYMBOL asciidtype_UFUNC_API
45
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
56
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
67
#define NO_IMPORT_ARRAY
8+
#define NO_IMPORT_UFUNC
79
#include "numpy/ndarraytypes.h"
810
#include "numpy/arrayobject.h"
911
#include "numpy/ufuncobject.h"
@@ -219,14 +221,12 @@ init_equal_ufunc(PyObject *numpy)
219221
return 0;
220222
}
221223

222-
PyObject *
224+
int
223225
init_ufuncs(void)
224226
{
225-
import_umath();
226-
227227
PyObject *numpy = PyImport_ImportModule("numpy");
228228
if (numpy == NULL) {
229-
return NULL;
229+
return -1;
230230
}
231231

232232
if (init_add_ufunc(numpy) < 0) {
@@ -237,9 +237,9 @@ init_ufuncs(void)
237237
goto error;
238238
}
239239

240-
return numpy;
240+
return 0;
241241

242242
error:
243243
Py_DECREF(numpy);
244-
return NULL;
244+
return -1;
245245
}

asciidtype/asciidtype/src/umath.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef _NPY_UFUNC_H
22
#define _NPY_UFUNC_H
33

4-
PyObject *
4+
int
55
init_ufuncs(void);
66

77
#endif /*_NPY_UFUNC_H */

metadatadtype/metadatadtype/src/casts.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include <Python.h>
22

33
#define PY_ARRAY_UNIQUE_SYMBOL metadatadtype_ARRAY_API
4+
#define PY_UFUNC_UNIQUE_SYMBOL metadatadtype_UFUNC_API
45
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
56
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
67
#define NO_IMPORT_ARRAY
8+
#define NO_IMPORT_UFUNC
79
#include "numpy/arrayobject.h"
810
#include "numpy/dtype_api.h"
911
#include "numpy/ndarraytypes.h"

metadatadtype/metadatadtype/src/dtype.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
// clang-format off
2+
#include <Python.h>
3+
#include "structmember.h"
4+
// clang-format on
5+
16
#define PY_ARRAY_UNIQUE_SYMBOL metadatadtype_ARRAY_API
7+
#define PY_UFUNC_UNIQUE_SYMBOL metadatadtype_UFUNC_API
28
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
39
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
410
#define NO_IMPORT_ARRAY
11+
#define NO_IMPORT_UFUNC
512
#include "numpy/arrayobject.h"
613
#include "numpy/dtype_api.h"
714
#include "numpy/ndarraytypes.h"

metadatadtype/metadatadtype/src/dtype.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
#ifndef _NPY_DTYPE_H
22
#define _NPY_DTYPE_H
33

4-
// clang-format off
5-
#include <Python.h>
6-
#include "structmember.h"
7-
// clang-format on
8-
94
typedef struct {
105
PyArray_Descr base;
116
PyObject *metadata;

metadatadtype/metadatadtype/src/metadatadtype_main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include <Python.h>
22

33
#define PY_ARRAY_UNIQUE_SYMBOL metadatadtype_ARRAY_API
4+
#define PY_UFUNC_UNIQUE_SYMBOL metadatadtype_UFUNC_API
45
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
56
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
67
#include "numpy/arrayobject.h"
8+
#include "numpy/ufuncobject.h"
79
#include "numpy/dtype_api.h"
810

911
#include "umath.h"
@@ -20,6 +22,7 @@ PyMODINIT_FUNC
2022
PyInit__metadatadtype_main(void)
2123
{
2224
import_array();
25+
import_umath();
2326

2427
PyObject *m = PyModule_Create(&moduledef);
2528
if (m == NULL) {
@@ -47,7 +50,7 @@ PyInit__metadatadtype_main(void)
4750
goto error;
4851
}
4952

50-
if (init_ufuncs(m) == NULL) {
53+
if (init_ufuncs() == -1) {
5154
goto error;
5255
}
5356

metadatadtype/metadatadtype/src/umath.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include <Python.h>
22

33
#define PY_ARRAY_UNIQUE_SYMBOL metadatadtype_ARRAY_API
4+
#define PY_UFUNC_UNIQUE_SYMBOL metadatadtype_UFUNC_API
45
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
56
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
67
#define NO_IMPORT_ARRAY
8+
#define NO_IMPORT_UFUNC
79
#include "numpy/ndarraytypes.h"
810
#include "numpy/arrayobject.h"
911
#include "numpy/ufuncobject.h"
@@ -103,11 +105,9 @@ add_wrapping_loop(const char *ufunc_name, PyArray_DTypeMeta **dtypes,
103105
return res;
104106
}
105107

106-
PyObject *
107-
init_ufuncs(PyObject *module)
108+
int
109+
init_ufuncs(void)
108110
{
109-
import_umath();
110-
111111
PyArray_DTypeMeta *binary_orig_dtypes[3] = {&MetadataDType, &MetadataDType,
112112
&MetadataDType};
113113
PyArray_DTypeMeta *binary_wrapped_dtypes[3] = {
@@ -126,9 +126,8 @@ init_ufuncs(PyObject *module)
126126
goto error;
127127
}
128128

129-
return module;
129+
return 0;
130130
error:
131131

132-
Py_DECREF(module);
133-
return NULL;
132+
return -1;
134133
}

0 commit comments

Comments
 (0)