clamydo commented on issue #35381:
URL: https://github.com/apache/arrow/issues/35381#issuecomment-1530949559
Sure. I have a bigger project that requires cxx11 ABI, therefore I'm
compiling myself and link arrow and pyarrow-cpp statically. But in the big
project this leads do hard to debug segmentation faults when using from python
with vanilla pyarrow.
Hence, I am writing a MVP C++ Python Extension to get an attack vector. With
that MVP I get an undefined symbol error (pointing to `arrow::float32()` when
importing the python module.
```
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: test.cpython-310-x86_64-linux-gnu.so: undefined symbol:
_ZN5arrow7float32Ev
```
```python
from setuptools import Extension, setup
setup(
ext_modules=[
Extension(
name="test",
include_dirs = [
'include',
],
extra_compile_args=['-std=c++17'],
extra_link_args=[
'-l:libarrow_bundled_dependencies.a',
'-l:libarrow.a',
'-l:libarrow_python.a',
],
library_dirs = [
'lib',
] ],
sources=["test.cpp"],
),
]
)
```
```c++
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <arrow/api.h>
#include <arrow/python/pyarrow.h>
#include <stdio.h>
static auto load_arrow_table(PyObject *pyobj, PyObject *args) -> PyObject * {
auto tbl = arrow::py::unwrap_table(pyobj);
Py_INCREF(Py_None);
return Py_None;
}
static PyMethodDef TestMethods[] = {
{"load_arrow_table", load_arrow_table, METH_VARARGS, "Some description"},
{NULL, NULL, 0, NULL} /* Sentinel */
};
static struct PyModuleDef testmodule = {
PyModuleDef_HEAD_INIT, "test", /* name of module */
NULL, /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the
module,
or -1 if the module keeps state in
global variables. */
TestMethods};
PyMODINIT_FUNC PyInit_test(void) { return PyModule_Create(&testmodule); }
auto main(int argc, char *argv[]) -> int {
// must be called to initialize pyarrow
arrow::py::import_pyarrow();
wchar_t *program = Py_DecodeLocale(argv[0], NULL);
if (program == NULL) {
fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
exit(1);
}
/* Add a built-in module, before Py_Initialize */
if (PyImport_AppendInittab("test", PyInit_test) == -1) {
fprintf(stderr, "Error: could not extend in-built modules table\n");
exit(1);
}
/* Pass argv[0] to the Python interpreter */
Py_SetProgramName(program);
/* Initialize the Python interpreter. Required.
If this step fails, it will be a fatal error. */
Py_Initialize();
/* Optionally import the module; alternatively,
import can be deferred until the embedded script
imports it. */
PyObject *pmodule = PyImport_ImportModule("test");
if (!pmodule) {
PyErr_Print();
fprintf(stderr, "Error: could not import module 'test'\n");
}
PyMem_RawFree(program);
return 0;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]