From c0bf4f1eb4ff7704aa4d7326411e2686ea580923 Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Fri, 15 May 2020 23:46:44 -0700 Subject: [PATCH 1/3] Fix compile error on MSVC 2019. MSVC does not support initializing the rb_data_type_t structure from a pointer. Error is: ruby_wrapper.c(359): error C2099: initializer is not a constant ruby_wrapper.c(359): error C4047: 'initializing': 'void *' differs in levels of indirection from 'int' Fixed by moving code to pycall_init_ruby_wrapper. --- ext/pycall/ruby_wrapper.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ext/pycall/ruby_wrapper.c b/ext/pycall/ruby_wrapper.c index a1f745b6..92b2e882 100644 --- a/ext/pycall/ruby_wrapper.c +++ b/ext/pycall/ruby_wrapper.c @@ -356,12 +356,9 @@ PyRuby_getattro_with_gvl(PyRubyObject *pyro, PyObject *pyobj_name) VALUE cPyRubyPtr; -const rb_data_type_t pycall_pyrubyptr_data_type = { +rb_data_type_t pycall_pyrubyptr_data_type = { "PyCall::PyRubyPtr", - { 0, pycall_pyptr_free, pycall_pyptr_memsize, }, -#ifdef RUBY_TYPED_FREE_IMMEDIATELY - &pycall_pyptr_data_type, 0, RUBY_TYPED_FREE_IMMEDIATELY -#endif + { 0, pycall_pyptr_free, pycall_pyptr_memsize, } }; static inline int @@ -462,11 +459,19 @@ pycall_init_ruby_wrapper(void) /* PyCall::PyRubyPtr */ +// This cannot be defined above because MSVC 2019 results in error C2099: initializer is not a constant +#ifdef RUBY_TYPED_FREE_IMMEDIATELY + pycall_pyrubyptr_data_type.parent = &pycall_pyptr_data_type; + pycall_pyrubyptr_data_type.data = 0; + pycall_pyrubyptr_data_type.flags = RUBY_TYPED_FREE_IMMEDIATELY; +#endif + 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); rb_define_module_function(mPyCall, "wrap_ruby_object", pycall_m_wrap_ruby_object, 1); + } /* --- File internal utilities --- */ From 4b25edf9fe1c0777778aae0a32ce85bde3781041 Mon Sep 17 00:00:00 2001 From: Kenta Murata Date: Mon, 25 May 2020 14:16:11 +0900 Subject: [PATCH 2/3] Rewrite the initialization of pycall_pyrubyptr_data_type --- ext/pycall/pycall_internal.h | 13 +++++++++++++ ext/pycall/ruby_wrapper.c | 20 ++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) 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 92b2e882..e08272c9 100644 --- a/ext/pycall/ruby_wrapper.c +++ b/ext/pycall/ruby_wrapper.c @@ -356,9 +356,18 @@ PyRuby_getattro_with_gvl(PyRubyObject *pyro, PyObject *pyobj_name) VALUE cPyRubyPtr; -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_PARENT, + 0, + RUBY_TYPED_FREE_IMMEDIATELY +#endif }; static inline int @@ -460,18 +469,13 @@ pycall_init_ruby_wrapper(void) /* PyCall::PyRubyPtr */ // This cannot be defined above because MSVC 2019 results in error C2099: initializer is not a constant -#ifdef RUBY_TYPED_FREE_IMMEDIATELY - pycall_pyrubyptr_data_type.parent = &pycall_pyptr_data_type; - pycall_pyrubyptr_data_type.data = 0; - pycall_pyrubyptr_data_type.flags = RUBY_TYPED_FREE_IMMEDIATELY; -#endif + 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); rb_define_module_function(mPyCall, "wrap_ruby_object", pycall_m_wrap_ruby_object, 1); - } /* --- File internal utilities --- */ From fba7b41b309a1574524a9993fe606717987428c6 Mon Sep 17 00:00:00 2001 From: Kenta Murata Date: Mon, 25 May 2020 14:34:35 +0900 Subject: [PATCH 3/3] WIP: CI on Windows --- .github/workflows/ci.yml | 82 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 5 deletions(-) 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