Open ehsantn opened 6 years ago
I've just run into this issue - will post an update if I determine what the problem is (I think it's something locale-related).
Create a C extension function in a python package which creates/uses a regex object. Compile the package and run code that calls the C extension function.
Unfortunately it seems not to quite be as simple as this. For example, the following module:
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include <boost/regex.hpp>
static PyObject*
match_regex(PyObject *self, PyObject *args) {
const char *arg;
if (!PyArg_ParseTuple(args, "s", &arg))
return nullptr;
boost::regex r(":.*");
if (boost::regex_match(arg, r))
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
}
static PyMethodDef testmethods[] = {
{"match_regex", match_regex, METH_VARARGS, "Match regex"},
{NULL, NULL, 0, NULL}
};
static PyModuleDef testmodule = {
PyModuleDef_HEAD_INIT,
"test",
"Test module with a boost::regex",
-1,
testmethods,
};
PyMODINIT_FUNC
PyInit_test(void)
{
return PyModule_Create(&testmodule);
}
Built using a setup.py:
from setuptools import setup, Extension
module = Extension(
'test',
sources=['test.cpp'],
libraries=['boost_regex'],
)
setup(
name="test",
ext_modules=[module]
)
run with
python setup.py build_ext --inplace
and then used like, e.g.:
$ python -c "import test; print(test.match_regex(':x'))"
True
$ python -c "import test; print(test.match_regex('a:'))"
False
seems to work. So there's some other factor at play in the crash, likely induced by some additional library / package.
I think this is encountered when the object using Boost has been built using a GCC (and therefore libstdc++) newer than the one in the Anaconda environment, and when the Anaconda environment's libstdc++ is encountered first during the linker's search for the libstdc++ library - ensuring that the latest libstdc++ is on the search path first resolves the issue.
I think this is not really an Anaconda issue per se, and this might as well be closed (if anyone's minding this issue / repo).
I'm trying to use boost::regex in a Python CPP extension module. However, it crashes with a segfault. Using std::regex works fine.
Actual Behavior
Segfault, here is gdb backtrace:
Expected Behavior
It should work like std::regex does.
Steps to Reproduce
Create a C extension function in a python package which creates/uses a regex object. Compile the package and run code that calls the C extension function.
Anaconda or Miniconda version:
Anaconda 5.01.
Operating System:
Ubuntu 16.04
conda info
conda list --show-channel-urls