Skip to content

Fix compile error on MSVC 2019 #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 77 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions ext/pycall/pycall_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
15 changes: 12 additions & 3 deletions ext/pycall/ruby_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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);
Expand Down