Skip to content

Commit

Permalink
cleanup and fix osx flat_namespace thing
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Sep 24, 2024
1 parent 31e6462 commit 1d8403c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# executable. PDAL plugins need to link against libpython, but if a plugin
# is loaded inside a python process, it must resolve symbols from the python
# executable instead of libpython. Using flat namespace allows that.
set(PYTHON_LINK_LIBRARY ${PYTHON_LINK_LIBRARY} -Wl,-flat_namespace)
# set(PYTHON_LINK_LIBRARY ${PYTHON_LINK_LIBRARY} -Wl,-flat_namespace)
endif()

PDAL_PYTHON_ADD_PLUGIN(numpy_reader reader numpy
Expand Down
38 changes: 15 additions & 23 deletions src/pdal/io/NumpyReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,32 +360,24 @@ Dimension::Id NumpyReader::registerDim(PointLayoutPtr layout,
return id;
}

namespace
{


Dimension::Type getType(PyArray_Descr *dtype, const std::string& name)
void NumpyReader::createFields(PointLayoutPtr layout)
{
if (!dtype)
throw pdal_error("Can't fetch data type for numpy field.");

Dimension::Type pdalType =
plang::Environment::getPDALDataType(dtype->type_num);
if (pdalType == Dimension::Type::None)
auto getPDALType = [](int type_num, const std::string& name)
{
std::ostringstream oss;
oss << "Unable to map dimension '" << name << "' because its "
"type '" << dtype->type_num <<"' is not mappable to PDAL";
throw pdal_error(oss.str());
}
return pdalType;
}

} // unnamed namespace

Dimension::Type pdalType =
plang::Environment::getPDALDataType(type_num);
if (pdalType == Dimension::Type::None)
{
std::ostringstream oss;
oss << "Unable to map dimension '" << name << "' because its "
"type '" << type_num <<"' is not mappable to PDAL";
throw pdal_error(oss.str());
}
return pdalType;
};

void NumpyReader::createFields(PointLayoutPtr layout)
{
Dimension::Id id;
Dimension::Type type;
int offset;
Expand All @@ -398,7 +390,7 @@ void NumpyReader::createFields(PointLayoutPtr layout)
// Array isn't structured - just a bunch of data.
if (m_numFields <= 0)
{
type = getType(m_dtype, m_defaultDimension);
type = getPDALType(m_dtype->type_num, m_defaultDimension);
id = registerDim(layout, m_defaultDimension, type);
m_fields.push_back({id, type, 0});
}
Expand All @@ -425,7 +417,7 @@ void NumpyReader::createFields(PointLayoutPtr layout)

// Get type.
PyArray_Descr* dt = (PyArray_Descr *)PySequence_Fast_GET_ITEM(tup, 0);
type = getType(dt, name);
type = getPDALType(dt->type_num, name);

char byteorder = dt->byteorder;
int elsize = (int) PyDataType_ELSIZE(dt);
Expand Down
2 changes: 0 additions & 2 deletions src/pdal/plang/Environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ Environment::Environment()
// the return.
auto initNumpy = []()
{
// #undef NUMPY_IMPORT_ARRAY_RETVAL
// #define NUMPY_IMPORT_ARRAY_RETVAL VOID

#if NPY_ABI_VERSION < 0x02000000
_import_array();
Expand Down
2 changes: 1 addition & 1 deletion src/pdal/plang/Environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

#define PY_ARRAY_UNIQUE_SYMBOL PDAL_ARRAY_API
#define NPY_TARGET_VERSION NPY_1_22_API_VERSION
#define NPY_API_SYMBOL_ATTRIBUTE
// #define NPY_API_SYMBOL_ATTRIBUTE
#define NPY_NO_DEPRECATED_API NPY_1_22_API_VERSION

namespace pdal
Expand Down

0 comments on commit 1d8403c

Please sign in to comment.