Skip to content

Commit 70626c3

Browse files
authored
Merge pull request #97 from ngoldbaum/update-for-numpy-2.0
Update for numpy 2.0
2 parents 1f2c42e + 14b5343 commit 70626c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+626
-630
lines changed

asciidtype/asciidtype/src/asciidtype_main.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +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 PY_UFUNC_UNIQUE_SYMBOL asciidtype_UFUNC_API
5+
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
6+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
7+
#include "numpy/ndarraytypes.h"
58
#include "numpy/arrayobject.h"
6-
#include "numpy/experimental_dtype_api.h"
9+
#include "numpy/ufuncobject.h"
10+
#include "numpy/dtype_api.h"
711

812
#include "dtype.h"
913
#include "umath.h"
@@ -18,13 +22,8 @@ static struct PyModuleDef moduledef = {
1822
PyMODINIT_FUNC
1923
PyInit__asciidtype_main(void)
2024
{
21-
if (_import_array() < 0) {
22-
return NULL;
23-
}
24-
25-
if (import_experimental_dtype_api(15) < 0) {
26-
return NULL;
27-
}
25+
import_array();
26+
import_umath();
2827

2928
PyObject *m = PyModule_Create(&moduledef);
3029
if (m == NULL) {
@@ -51,7 +50,7 @@ PyInit__asciidtype_main(void)
5150
goto error;
5251
}
5352

54-
if (init_ufuncs() < 0) {
53+
if (init_ufuncs() == -1) {
5554
goto error;
5655
}
5756

asciidtype/asciidtype/src/casts.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +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 PY_UFUNC_UNIQUE_SYMBOL asciidtype_UFUNC_API
5+
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
6+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
57
#define NO_IMPORT_ARRAY
8+
#define NO_IMPORT_UFUNC
69
#include "numpy/arrayobject.h"
7-
#include "numpy/experimental_dtype_api.h"
10+
#include "numpy/dtype_api.h"
811
#include "numpy/ndarraytypes.h"
912

1013
#include "casts.h"
@@ -46,7 +49,7 @@ ascii_to_ascii(PyArrayMethod_Context *context, char *const data[],
4649
npy_intp const dimensions[], npy_intp const strides[],
4750
NpyAuxData *NPY_UNUSED(auxdata))
4851
{
49-
PyArray_Descr **descrs = context->descriptors;
52+
PyArray_Descr *const *descrs = context->descriptors;
5053
long in_size = ((ASCIIDTypeObject *)descrs[0])->size;
5154
long out_size = ((ASCIIDTypeObject *)descrs[1])->size;
5255
long copy_size;
@@ -111,7 +114,7 @@ unicode_to_ascii(PyArrayMethod_Context *context, char *const data[],
111114
npy_intp const dimensions[], npy_intp const strides[],
112115
NpyAuxData *NPY_UNUSED(auxdata))
113116
{
114-
PyArray_Descr **descrs = context->descriptors;
117+
PyArray_Descr *const *descrs = context->descriptors;
115118
long in_size = (descrs[0]->elsize) / 4;
116119
long out_size = ((ASCIIDTypeObject *)descrs[1])->size;
117120
long copy_size;
@@ -162,7 +165,7 @@ ascii_to_unicode(PyArrayMethod_Context *context, char *const data[],
162165
npy_intp const dimensions[], npy_intp const strides[],
163166
NpyAuxData *NPY_UNUSED(auxdata))
164167
{
165-
PyArray_Descr **descrs = context->descriptors;
168+
PyArray_Descr *const *descrs = context->descriptors;
166169
long in_size = ((ASCIIDTypeObject *)descrs[0])->size;
167170
long out_size = (descrs[1]->elsize) / 4;
168171
long copy_size;

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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
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 PY_UFUNC_UNIQUE_SYMBOL asciidtype_UFUNC_API
8+
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
9+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
10+
#define NO_IMPORT_ARRAY
11+
#define NO_IMPORT_UFUNC
12+
#include "numpy/ndarraytypes.h"
13+
#include "numpy/arrayobject.h"
14+
#include "numpy/ufuncobject.h"
15+
#include "numpy/dtype_api.h"
16+
117
#include "dtype.h"
218

319
#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: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
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 PY_UFUNC_UNIQUE_SYMBOL asciidtype_UFUNC_API
5+
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
6+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
57
#define NO_IMPORT_ARRAY
6-
#include "numpy/arrayobject.h"
7-
#include "numpy/experimental_dtype_api.h"
8+
#define NO_IMPORT_UFUNC
89
#include "numpy/ndarraytypes.h"
10+
#include "numpy/arrayobject.h"
911
#include "numpy/ufuncobject.h"
12+
#include "numpy/dtype_api.h"
1013

1114
#include "dtype.h"
1215
#include "string.h"
@@ -17,7 +20,7 @@ ascii_add_strided_loop(PyArrayMethod_Context *context, char *const data[],
1720
npy_intp const dimensions[], npy_intp const strides[],
1821
NpyAuxData *NPY_UNUSED(auxdata))
1922
{
20-
PyArray_Descr **descrs = context->descriptors;
23+
PyArray_Descr *const *descrs = context->descriptors;
2124
long in1_size = ((ASCIIDTypeObject *)descrs[0])->size;
2225
long in2_size = ((ASCIIDTypeObject *)descrs[1])->size;
2326
long out_size = ((ASCIIDTypeObject *)descrs[2])->size;
@@ -112,7 +115,7 @@ ascii_equal_strided_loop(PyArrayMethod_Context *context, char *const data[],
112115
npy_intp const dimensions[], npy_intp const strides[],
113116
NpyAuxData *NPY_UNUSED(auxdata))
114117
{
115-
PyArray_Descr **descrs = context->descriptors;
118+
PyArray_Descr *const *descrs = context->descriptors;
116119
long in1_size = ((ASCIIDTypeObject *)descrs[0])->size;
117120
long in2_size = ((ASCIIDTypeObject *)descrs[1])->size;
118121

@@ -234,7 +237,6 @@ init_ufuncs(void)
234237
goto error;
235238
}
236239

237-
Py_DECREF(numpy);
238240
return 0;
239241

240242
error:

asciidtype/reinstall.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
set -xeuo pipefail
3+
IFS=$'\n\t'
4+
5+
if [ -d "build/" ]
6+
then
7+
rm -r build
8+
fi
9+
10+
#meson setup build -Db_sanitize=address,undefined
11+
meson setup build
12+
python -m pip uninstall -y asciidtype
13+
python -m pip install . -v --no-build-isolation -Cbuilddir=build -C'compile-args=-v' -Csetup-args="-Dbuildtype=debug"
14+
#python -m pip install . -v --no-build-isolation -Cbuilddir=build -C'compile-args=-v'

metadatadtype/metadatadtype/src/casts.c

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

33
#define PY_ARRAY_UNIQUE_SYMBOL metadatadtype_ARRAY_API
4-
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
4+
#define PY_UFUNC_UNIQUE_SYMBOL metadatadtype_UFUNC_API
5+
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
6+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
57
#define NO_IMPORT_ARRAY
8+
#define NO_IMPORT_UFUNC
69
#include "numpy/arrayobject.h"
7-
#include "numpy/experimental_dtype_api.h"
10+
#include "numpy/dtype_api.h"
811
#include "numpy/ndarraytypes.h"
912

1013
#include "casts.h"
@@ -186,7 +189,7 @@ static PyArray_DTypeMeta *m2m_dtypes[2] = {NULL, NULL};
186189
static PyType_Slot m2m_slots[] = {
187190
{NPY_METH_resolve_descriptors,
188191
&metadata_to_metadata_resolve_descriptors},
189-
{_NPY_METH_get_loop, &metadata_to_metadata_get_loop},
192+
{NPY_METH_get_loop, &metadata_to_metadata_get_loop},
190193
{0, NULL}};
191194

192195
PyArrayMethod_Spec MetadataToMetadataCastSpec = {
@@ -200,7 +203,7 @@ PyArrayMethod_Spec MetadataToMetadataCastSpec = {
200203
};
201204

202205
static PyType_Slot m2f_slots[] = {
203-
{_NPY_METH_get_loop, &metadata_to_float64_get_loop}, {0, NULL}};
206+
{NPY_METH_get_loop, &metadata_to_float64_get_loop}, {0, NULL}};
204207

205208
static char *m2f_name = "cast_MetadataDType_to_Float64";
206209

metadatadtype/metadatadtype/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 metadatadtype_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

metadatadtype/metadatadtype/src/dtype.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// clang-format off
2+
#include <Python.h>
3+
#include "structmember.h"
4+
// clang-format on
5+
6+
#define PY_ARRAY_UNIQUE_SYMBOL metadatadtype_ARRAY_API
7+
#define PY_UFUNC_UNIQUE_SYMBOL metadatadtype_UFUNC_API
8+
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
9+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
10+
#define NO_IMPORT_ARRAY
11+
#define NO_IMPORT_UFUNC
12+
#include "numpy/arrayobject.h"
13+
#include "numpy/dtype_api.h"
14+
#include "numpy/ndarraytypes.h"
15+
116
#include "dtype.h"
217

318
#include "casts.h"
@@ -74,8 +89,9 @@ new_metadatadtype_instance(PyObject *metadata)
7489
}
7590
Py_INCREF(metadata);
7691
new->metadata = metadata;
77-
new->base.elsize = sizeof(double);
78-
new->base.alignment = _Alignof(double); /* is there a better spelling? */
92+
PyArray_Descr *base = (PyArray_Descr *)new;
93+
base->elsize = sizeof(double);
94+
base->alignment = _Alignof(double); /* is there a better spelling? */
7995
/* do not support byte-order for now */
8096

8197
return new;

metadatadtype/metadatadtype/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 metadatadtype_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
PyObject *metadata;

metadatadtype/metadatadtype/src/metadatadtype_main.c

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

33
#define PY_ARRAY_UNIQUE_SYMBOL metadatadtype_ARRAY_API
4-
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
4+
#define PY_UFUNC_UNIQUE_SYMBOL metadatadtype_UFUNC_API
5+
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
6+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
57
#include "numpy/arrayobject.h"
6-
#include "numpy/experimental_dtype_api.h"
8+
#include "numpy/ufuncobject.h"
9+
#include "numpy/dtype_api.h"
710

8-
#include "dtype.h"
911
#include "umath.h"
12+
#include "dtype.h"
1013

1114
static struct PyModuleDef moduledef = {
1215
PyModuleDef_HEAD_INIT,
@@ -18,12 +21,8 @@ static struct PyModuleDef moduledef = {
1821
PyMODINIT_FUNC
1922
PyInit__metadatadtype_main(void)
2023
{
21-
if (_import_array() < 0) {
22-
return NULL;
23-
}
24-
if (import_experimental_dtype_api(15) < 0) {
25-
return NULL;
26-
}
24+
import_array();
25+
import_umath();
2726

2827
PyObject *m = PyModule_Create(&moduledef);
2928
if (m == NULL) {
@@ -51,7 +50,7 @@ PyInit__metadatadtype_main(void)
5150
goto error;
5251
}
5352

54-
if (init_ufuncs() < 0) {
53+
if (init_ufuncs() == -1) {
5554
goto error;
5655
}
5756

metadatadtype/metadatadtype/src/umath.c

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

33
#define PY_ARRAY_UNIQUE_SYMBOL metadatadtype_ARRAY_API
4-
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
4+
#define PY_UFUNC_UNIQUE_SYMBOL metadatadtype_UFUNC_API
5+
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
6+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
57
#define NO_IMPORT_ARRAY
6-
#include "numpy/arrayobject.h"
7-
#include "numpy/experimental_dtype_api.h"
8+
#define NO_IMPORT_UFUNC
89
#include "numpy/ndarraytypes.h"
10+
#include "numpy/arrayobject.h"
911
#include "numpy/ufuncobject.h"
12+
#include "numpy/dtype_api.h"
1013

1114
#include "dtype.h"
1215
#include "umath.h"
1316

1417
static int
1518
translate_given_descrs(int nin, int nout,
16-
PyArray_DTypeMeta *NPY_UNUSED(wrapped_dtypes[]),
17-
PyArray_Descr *given_descrs[],
19+
PyArray_DTypeMeta *const NPY_UNUSED(wrapped_dtypes[]),
20+
PyArray_Descr *const given_descrs[],
1821
PyArray_Descr *new_descrs[])
1922
{
2023
for (int i = 0; i < nin + nout; i++) {
@@ -35,8 +38,8 @@ translate_given_descrs(int nin, int nout,
3538

3639
static int
3740
translate_loop_descrs(int nin, int NPY_UNUSED(nout),
38-
PyArray_DTypeMeta *NPY_UNUSED(new_dtypes[]),
39-
PyArray_Descr *given_descrs[],
41+
PyArray_DTypeMeta *const NPY_UNUSED(new_dtypes[]),
42+
PyArray_Descr *const given_descrs[],
4043
PyArray_Descr *original_descrs[],
4144
PyArray_Descr *loop_descrs[])
4245
{
@@ -125,5 +128,6 @@ init_ufuncs(void)
125128

126129
return 0;
127130
error:
131+
128132
return -1;
129133
}

0 commit comments

Comments
 (0)