Skip to content

Commit 5ff8640

Browse files
committed
restructure defines and undef NPY_API_SYMBOL_ATTRIBUTE
1 parent c39e593 commit 5ff8640

File tree

6 files changed

+27
-24
lines changed

6 files changed

+27
-24
lines changed

src/pdal/io/NumpyReader.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#include <pdal/util/Algorithm.hpp>
4444
#include <pdal/util/Extractor.hpp>
4545

46-
#include "../plang/Environment.hpp"
46+
4747

4848
#if NPY_ABI_VERSION < 0x02000000
4949
#define PyDataType_FIELDS(descr) ((descr)->fields)
@@ -138,6 +138,7 @@ void NumpyReader::setArray(PyObject* array)
138138
Py_XINCREF(m_array);
139139
}
140140

141+
141142
PyArrayObject* load_npy_file(std::string const& filename)
142143
{
143144

@@ -167,10 +168,11 @@ PyArrayObject* load_npy_file(std::string const& filename)
167168
if (!array)
168169
throw pdal::pdal_error(plang::getTraceback());
169170

170-
PyArrayObject* output = reinterpret_cast<PyArrayObject*>(array);
171-
if (!output)
172-
throw pdal_error(plang::getTraceback());
173-
return output;
171+
172+
PyArrayObject* nparray = reinterpret_cast<PyArrayObject*>(array);
173+
if (!PyArray_Check(array))
174+
throw pdal_error("Numpy file did not return an array!");
175+
return nparray;
174176
}
175177

176178
PyArrayObject* load_npy_script(std::string const& source,
@@ -201,10 +203,10 @@ PyArrayObject* load_npy_script(std::string const& source,
201203

202204
Py_XDECREF(scriptArgs);
203205

204-
PyArrayObject* output = reinterpret_cast<PyArrayObject*>(array);
205-
if (!output)
206-
throw pdal_error(plang::getTraceback());
207-
return output;
206+
if (!PyArray_Check(array))
207+
throw pdal_error("Numpy script did not return an array!");
208+
209+
return reinterpret_cast<PyArrayObject*>(array);
208210
}
209211

210212
void NumpyReader::initialize()

src/pdal/io/NumpyReader.hpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@
3737
#include <pdal/Reader.hpp>
3838
#include <pdal/Streamable.hpp>
3939

40+
#include "../plang/Environment.hpp"
4041
#include "../plang/Invocation.hpp"
4142

42-
#include <Python.h>
43-
#define NPY_NO_DEPRECATED_API NPY_1_22_API_VERSION
44-
#define PY_ARRAY_UNIQUE_SYMBOL PDAL_ARRAY_API
45-
#define NO_IMPORT_ARRAY
46-
#include <numpy/arrayobject.h>
43+
#define NO_IMPORT_ARRAY // Already have it from Environment.hpp
44+
#include <numpy/ndarrayobject.h>
4745

4846
#include <memory>
4947

src/pdal/plang/Environment.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@
3939
#include "Environment.hpp"
4040
#include "Redirector.hpp"
4141

42-
#define NPY_TARGET_VERSION NPY_1_22_API_VERSION
43-
#define NPY_NO_DEPRECATED_API NPY_1_22_API_VERSION
4442

45-
#define PY_ARRAY_UNIQUE_SYMBOL PDAL_ARRAY_API
46-
47-
#include <numpy/arrayobject.h>
43+
#include <numpy/ndarrayobject.h>
4844
#include <pdal/util/FileUtils.hpp>
4945
#include <pdal/util/Utils.hpp>
5046

@@ -147,7 +143,12 @@ Environment::Environment()
147143
{
148144
// #undef NUMPY_IMPORT_ARRAY_RETVAL
149145
// #define NUMPY_IMPORT_ARRAY_RETVAL VOID
150-
_import_array();
146+
147+
#if NPY_ABI_VERSION < 0x02000000
148+
import_array();
149+
#else
150+
PyArray_ImportNumPyAPI();
151+
#endif
151152
return ;
152153
};
153154

@@ -165,7 +166,6 @@ Environment::Environment()
165166
throw pdal_error("unable to add redirector module!");
166167
}
167168

168-
169169
initNumpy();
170170
PyImport_ImportModule("redirector");
171171

src/pdal/plang/Environment.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
#include "Script.hpp"
5050
#include "gil.hpp"
5151

52+
#define PY_ARRAY_UNIQUE_SYMBOL PDAL_ARRAY_API
53+
#define NPY_TARGET_VERSION NPY_1_22_API_VERSION
54+
#define NPY_API_SYMBOL_ATTRIBUTE
55+
#define NPY_NO_DEPRECATED_API NPY_1_22_API_VERSION
56+
5257
namespace pdal
5358
{
5459
namespace plang

src/pdal/plang/Invocation.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@
3636

3737
#include <pdal/util/Algorithm.hpp>
3838

39-
#define NPY_NO_DEPRECATED_API NPY_1_22_API_VERSION
4039
#define NO_IMPORT_ARRAY
41-
#define PY_ARRAY_UNIQUE_SYMBOL PDAL_ARRAY_API
42-
#include <numpy/arrayobject.h>
40+
#include <numpy/ndarrayobject.h>
4341

4442
namespace
4543
{

src/pdal/test/data/1.2-with-color.npy

48 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)