Skip to content

Commit efe33e2

Browse files
committed
Update asciidtype for numpy 2.0
1 parent 910c027 commit efe33e2

File tree

7 files changed

+40
-44
lines changed

7 files changed

+40
-44
lines changed

asciidtype/asciidtype/src/asciidtype_main.c

Lines changed: 10 additions & 10 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 NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
4+
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
5+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
6+
#include "numpy/ndarraytypes.h"
57
#include "numpy/arrayobject.h"
6-
#include "numpy/experimental_dtype_api.h"
8+
#include "numpy/dtype_api.h"
79

810
#include "dtype.h"
911
#include "umath.h"
@@ -18,13 +20,7 @@ static struct PyModuleDef moduledef = {
1820
PyMODINIT_FUNC
1921
PyInit__asciidtype_main(void)
2022
{
21-
if (_import_array() < 0) {
22-
return NULL;
23-
}
24-
25-
if (import_experimental_dtype_api(15) < 0) {
26-
return NULL;
27-
}
23+
import_array();
2824

2925
PyObject *m = PyModule_Create(&moduledef);
3026
if (m == NULL) {
@@ -51,10 +47,14 @@ PyInit__asciidtype_main(void)
5147
goto error;
5248
}
5349

54-
if (init_ufuncs() < 0) {
50+
PyObject *numpy = init_ufuncs();
51+
52+
if (numpy == NULL) {
5553
goto error;
5654
}
5755

56+
Py_DECREF(numpy);
57+
5858
return m;
5959

6060
error:

asciidtype/asciidtype/src/casts.c

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

33
#define PY_ARRAY_UNIQUE_SYMBOL asciidtype_ARRAY_API
4-
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
4+
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
5+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
56
#define NO_IMPORT_ARRAY
67
#include "numpy/arrayobject.h"
7-
#include "numpy/experimental_dtype_api.h"
8+
#include "numpy/dtype_api.h"
89
#include "numpy/ndarraytypes.h"
910

1011
#include "casts.h"

asciidtype/asciidtype/src/casts.h

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

4-
#include <Python.h>
5-
6-
#define PY_ARRAY_UNIQUE_SYMBOL asciidtype_ARRAY_API
7-
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
8-
#define NO_IMPORT_ARRAY
9-
#include "numpy/arrayobject.h"
10-
#include "numpy/experimental_dtype_api.h"
11-
#include "numpy/ndarraytypes.h"
12-
134
PyArrayMethod_Spec **
145
get_casts(void);
156

asciidtype/asciidtype/src/dtype.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// clang-format off
2+
#include <Python.h>
3+
#include "structmember.h"
4+
// clang-format on
5+
6+
#define PY_ARRAY_UNIQUE_SYMBOL asciidtype_ARRAY_API
7+
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
8+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
9+
#define NO_IMPORT_ARRAY
10+
#include "numpy/ndarraytypes.h"
11+
#include "numpy/arrayobject.h"
12+
#include "numpy/ufuncobject.h"
13+
#include "numpy/dtype_api.h"
14+
115
#include "dtype.h"
216

317
#include "casts.h"

asciidtype/asciidtype/src/dtype.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +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-
9-
#define PY_ARRAY_UNIQUE_SYMBOL asciidtype_ARRAY_API
10-
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
11-
#define NO_IMPORT_ARRAY
12-
#include "numpy/arrayobject.h"
13-
#include "numpy/experimental_dtype_api.h"
14-
#include "numpy/ndarraytypes.h"
15-
164
typedef struct {
175
PyArray_Descr base;
186
long size;

asciidtype/asciidtype/src/umath.c

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

33
#define PY_ARRAY_UNIQUE_SYMBOL asciidtype_ARRAY_API
4-
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
4+
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
5+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
56
#define NO_IMPORT_ARRAY
6-
#include "numpy/arrayobject.h"
7-
#include "numpy/experimental_dtype_api.h"
87
#include "numpy/ndarraytypes.h"
8+
#include "numpy/arrayobject.h"
99
#include "numpy/ufuncobject.h"
10+
#include "numpy/dtype_api.h"
1011

1112
#include "dtype.h"
1213
#include "string.h"
@@ -17,7 +18,7 @@ ascii_add_strided_loop(PyArrayMethod_Context *context, char *const data[],
1718
npy_intp const dimensions[], npy_intp const strides[],
1819
NpyAuxData *NPY_UNUSED(auxdata))
1920
{
20-
PyArray_Descr **descrs = context->descriptors;
21+
PyArray_Descr *const *descrs = context->descriptors;
2122
long in1_size = ((ASCIIDTypeObject *)descrs[0])->size;
2223
long in2_size = ((ASCIIDTypeObject *)descrs[1])->size;
2324
long out_size = ((ASCIIDTypeObject *)descrs[2])->size;
@@ -112,7 +113,7 @@ ascii_equal_strided_loop(PyArrayMethod_Context *context, char *const data[],
112113
npy_intp const dimensions[], npy_intp const strides[],
113114
NpyAuxData *NPY_UNUSED(auxdata))
114115
{
115-
PyArray_Descr **descrs = context->descriptors;
116+
PyArray_Descr *const *descrs = context->descriptors;
116117
long in1_size = ((ASCIIDTypeObject *)descrs[0])->size;
117118
long in2_size = ((ASCIIDTypeObject *)descrs[1])->size;
118119

@@ -218,12 +219,14 @@ init_equal_ufunc(PyObject *numpy)
218219
return 0;
219220
}
220221

221-
int
222+
PyObject *
222223
init_ufuncs(void)
223224
{
225+
import_umath();
226+
224227
PyObject *numpy = PyImport_ImportModule("numpy");
225228
if (numpy == NULL) {
226-
return -1;
229+
return NULL;
227230
}
228231

229232
if (init_add_ufunc(numpy) < 0) {
@@ -234,10 +237,9 @@ init_ufuncs(void)
234237
goto error;
235238
}
236239

237-
Py_DECREF(numpy);
238-
return 0;
240+
return numpy;
239241

240242
error:
241243
Py_DECREF(numpy);
242-
return -1;
244+
return NULL;
243245
}

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-
int
4+
PyObject *
55
init_ufuncs(void);
66

77
#endif /*_NPY_UFUNC_H */

0 commit comments

Comments
 (0)