2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-21 05:02:17 +00:00

Compare commits

..

3 Commits

Author SHA1 Message Date
Stefan Seefeld
32da86df26 Improve test coverage. 2025-12-02 08:53:09 -05:00
Neil Schemenauer
e89f86b74f Update Linux CI scripts, more Python versions.
Update scripts to use actions/setup-python to install different Python
versions.  Add run-faber.sh and get-py-env.py scripts.  Add
test-ubuntu-py-ver.yml CI script to test with different Python versions.
2025-12-02 08:19:45 -05:00
Neil Schemenauer
5013564316 Add "nogil" option for BOOST_PYTHON_MODULE_INIT.
Implement optional arguments for BOOST_PYTHON_MODULE_INIT and allow the
boost::python::mod_gil_not_used() option.  This sets the
Py_MOD_GIL_NOT_USED flag for the extension module.

To define a module that supports free-threaded Python, define it
like this:

    BOOST_PYTHON_MODULE(my_module, boost::python::mod_gil_not_used())
    {
        ...
    }
2025-12-02 08:19:45 -05:00
3 changed files with 26 additions and 16 deletions

View File

@@ -17,10 +17,22 @@ jobs:
cxx: [g++, clang++] cxx: [g++, clang++]
std: [c++11, c++14, c++17] std: [c++11, c++14, c++17]
include: include:
# Also test with free-threaded build of Python
- python-version: '2.7' - python-version: '2.7'
cxx: g++ cxx: g++
std: c++11 std: c++11
- python-version: '3.10'
cxx: g++
std: c++17
- python-version: '3.11'
cxx: g++
std: c++17
- python-version: '3.12'
cxx: g++
std: c++17
- python-version: '3.13'
cxx: g++
std: c++17
# Also test with free-threaded build of Python
- python-version: '3.14t' - python-version: '3.14t'
cxx: clang++ cxx: clang++
std: c++17 std: c++17
@@ -47,15 +59,10 @@ jobs:
python3 -m pip install -U faber --break-system-packages python3 -m pip install -U faber --break-system-packages
echo "CXX=${{ matrix.cxx }}" >> "$GITHUB_ENV" echo "CXX=${{ matrix.cxx }}" >> "$GITHUB_ENV"
echo "CXX_STD=${{ matrix.std }}" >> "$GITHUB_ENV" echo "CXX_STD=${{ matrix.std }}" >> "$GITHUB_ENV"
- name: build - name: build-py2
if: "${{ matrix.python-version != '2.7' }}"
run: |
.github/run-faber.sh
- name: build
if: "${{ matrix.python-version == '2.7' }}" if: "${{ matrix.python-version == '2.7' }}"
run: | run: |
python --version python --version
echo ${BOOST_PY_DEPS}
${{ matrix.cxx }} --version ${{ matrix.cxx }} --version
faber -v faber -v
sed -e "s/\$PYTHON/python/g" .ci/faber > ~/.faber sed -e "s/\$PYTHON/python/g" .ci/faber > ~/.faber
@@ -66,15 +73,14 @@ jobs:
cxxflags=-std=${{ matrix.std }} \ cxxflags=-std=${{ matrix.std }} \
cppflags=-std=${{ matrix.std }} \ cppflags=-std=${{ matrix.std }} \
-j`nproc` -j`nproc`
- name: test - name: build-py3
if: "${{ matrix.python-version != '2.7' }}" if: "${{ matrix.python-version != '2.7' }}"
run: | run: |
.github/run-faber.sh test.report .github/run-faber.sh
- name: test - name: test-py2
if: "${{ matrix.python-version == '2.7' }}" if: "${{ matrix.python-version == '2.7' }}"
run: | run: |
faber \ faber \
--debug \
--with-boost-include=${BOOST_PY_DEPS} \ --with-boost-include=${BOOST_PY_DEPS} \
--builddir=build \ --builddir=build \
cxx.name=${{ matrix.cxx }} \ cxx.name=${{ matrix.cxx }} \
@@ -82,3 +88,7 @@ jobs:
cppflags=-std=${{ matrix.std }} \ cppflags=-std=${{ matrix.std }} \
-j`nproc` \ -j`nproc` \
test.report test.report
- name: test-py3
if: "${{ matrix.python-version != '2.7' }}"
run: |
.github/run-faber.sh test.report

View File

@@ -127,7 +127,7 @@ BOOST_PYTHON_DECL PyObject* init_module(char const* name, void(*)());
# endif # endif
# ifdef HAS_CXX11 # if defined(HAS_CXX11) && (PY_VERSION_HEX >= 0x03000000)
# define BOOST_PYTHON_MODULE_INIT(name, ...) \ # define BOOST_PYTHON_MODULE_INIT(name, ...) \
void BOOST_PP_CAT(init_module_,name)(); \ void BOOST_PP_CAT(init_module_,name)(); \
extern "C" BOOST_SYMBOL_EXPORT _BOOST_PYTHON_MODULE_INIT(name, __VA_ARGS__) extern "C" BOOST_SYMBOL_EXPORT _BOOST_PYTHON_MODULE_INIT(name, __VA_ARGS__)
@@ -135,7 +135,7 @@ extern "C" BOOST_SYMBOL_EXPORT _BOOST_PYTHON_MODULE_INIT(name, __VA_ARGS__)
# define BOOST_PYTHON_MODULE_INIT(name) \ # define BOOST_PYTHON_MODULE_INIT(name) \
void BOOST_PP_CAT(init_module_,name)(); \ void BOOST_PP_CAT(init_module_,name)(); \
extern "C" BOOST_SYMBOL_EXPORT _BOOST_PYTHON_MODULE_INIT(name) extern "C" BOOST_SYMBOL_EXPORT _BOOST_PYTHON_MODULE_INIT(name)
# endif // HAS_CXX11 # endif // HAS_CXX11 && Python 3
# endif # endif

View File

@@ -8,15 +8,15 @@ int get_value() {
return 1234; return 1234;
} }
#ifdef HAS_CXX11 #if defined(HAS_CXX11) && (PY_VERSION_HEX >= 0x03000000)
// C++11 build: test with mod_gil_not_used option // C++11 build with Python 3: test with mod_gil_not_used option
BOOST_PYTHON_MODULE(module_nogil_ext, boost::python::mod_gil_not_used()) BOOST_PYTHON_MODULE(module_nogil_ext, boost::python::mod_gil_not_used())
{ {
using namespace boost::python; using namespace boost::python;
def("get_value", get_value); def("get_value", get_value);
} }
#else #else
// C++98 build: test without optional arguments // C++98 build or Python 2: test without optional arguments
BOOST_PYTHON_MODULE(module_nogil_ext) BOOST_PYTHON_MODULE(module_nogil_ext)
{ {
using namespace boost::python; using namespace boost::python;