diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17c50040..6e21a41f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,11 +1,22 @@ name: CI on: -- push + push: + paths: + - .github/workflows/ci.yml + - ext/** + - lib/** + - spec/** + pull-request: + paths: + - .github/workflows/ci.yml + - ext/** + - lib/** + - spec/** jobs: - test: - name: Test + unix-like: + name: Test on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: @@ -35,13 +46,74 @@ jobs: ruby-version: ${{ matrix.ruby_version }} - name: Setup Python - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python_version }} architecture: ${{ matrix.python_architecture }} - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Prepare environment + run: | + gem install bundler + + - name: Install requirements + run: | + pip install --user numpy + bundle install + + - name: Compile pycall.so + run: | + bundle exec rake compile + + - name: Python investigator + run: | + python lib/pycall/python/investigator.py + + - name: Test + run: | + PYTHON=python bundle exec rake + + windows: + name: Test on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + os: + - windows-latest + ruby_version: + - 2.7.x + - 2.6.x + - 2.5.x + - 2.4.x + python_version: + - 3.8.x + - 3.7.x + - 3.6.x + - 2.7.x + python_architecture: + - x64 + + steps: + - name: Setup Ruby + if: matrix.ruby_version != 'master-nightly' + uses: actions/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby_version }} + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python_version }} + architecture: ${{ matrix.python_architecture }} + + - name: Checkout + uses: actions/checkout@v2 with: fetch-depth: 1 diff --git a/ext/pycall/pycall_internal.h b/ext/pycall/pycall_internal.h index 8e734e60..a75e71a0 100644 --- a/ext/pycall/pycall_internal.h +++ b/ext/pycall/pycall_internal.h @@ -663,6 +663,19 @@ Py_ssize_t pycall_python_hexversion(void); void pycall_Py_DecRef(PyObject *); +#if defined(_MSC_VER) && defined(RUBY_TYPED_FREE_IMMEDIATELY) +# define PYCALL_PYPTR_PARENT 0 +# define PYCALL_PYPTR_DATA_INIT_PARENT(pyptr_data) ((pyptr_data).parent = &pycall_pyptr_data_type) +#endif + +#ifndef PYCALL_PYPTR_PARENT +# define PYCALL_PYPTR_PARENT &pycall_pyptr_data_type +#endif + +#ifndef PYCALL_PYPTR_DATA_INIT_PARENT +# define PYCALL_PYPTR_DATA_INIT_PARENT(pyptr_data) ((void)0) +#endif + RUBY_EXTERN const rb_data_type_t pycall_pyptr_data_type; size_t pycall_pyptr_memsize(void const *); void pycall_pyptr_free(void *); diff --git a/ext/pycall/ruby_wrapper.c b/ext/pycall/ruby_wrapper.c index a1f745b6..e08272c9 100644 --- a/ext/pycall/ruby_wrapper.c +++ b/ext/pycall/ruby_wrapper.c @@ -356,11 +356,17 @@ PyRuby_getattro_with_gvl(PyRubyObject *pyro, PyObject *pyobj_name) VALUE cPyRubyPtr; -const rb_data_type_t pycall_pyrubyptr_data_type = { +static rb_data_type_t pycall_pyrubyptr_data_type = { "PyCall::PyRubyPtr", - { 0, pycall_pyptr_free, pycall_pyptr_memsize, }, + { + 0, + pycall_pyptr_free, + pycall_pyptr_memsize, + }, #ifdef RUBY_TYPED_FREE_IMMEDIATELY - &pycall_pyptr_data_type, 0, RUBY_TYPED_FREE_IMMEDIATELY + PYCALL_PYPTR_PARENT, + 0, + RUBY_TYPED_FREE_IMMEDIATELY #endif }; @@ -462,6 +468,9 @@ pycall_init_ruby_wrapper(void) /* PyCall::PyRubyPtr */ +// This cannot be defined above because MSVC 2019 results in error C2099: initializer is not a constant + PYCALL_PYPTR_DATA_INIT_PARENT(pycall_pyrubyptr_data_type); + cPyRubyPtr = rb_define_class_under(mPyCall, "PyRubyPtr", cPyPtr); rb_define_alloc_func(cPyRubyPtr, pycall_pyruby_allocate); rb_define_method(cPyRubyPtr, "__ruby_object_id__", pycall_pyruby_get_ruby_object_id, 0);