Allow Sharing C++ Classes Across Modules · Issue #4561 - GitHub

Skip to content Dismiss alert {{ message }} / cython Public
  • Uh oh!

    There was an error while loading. Please reload this page.

  • Notifications You must be signed in to change notification settings
  • Fork 1.6k
  • Star 10.6k
  • Code
  • Issues 1.3k
  • Pull requests 175
  • Actions
  • Wiki
  • Security
  • Insights
Additional navigation options Allow sharing C++ classes across modules #4561New issueNew issueOpenOpenAllow sharing C++ classes across modules#4561LabelsC++Code GenerationType Analysisfeature@datdinhquoc

Description

@datdinhquocdatdinhquocopened on Jan 7, 2022

I have these files to reproduce the problem, mod2.pxd:

cdef void myapi() cdef cppclass myclass: void mymethod()

mod2.pyx

cdef void myapi(): print("I am OK (from myapi)") cdef cppclass myclass: void mymethod(): # Using anything C is OK cdef int i = 0 i += 1 # Crash with Python var # Segmentation fault j = 0 j += 1 # Crash with Python function # Segmentation fault print("I am crashing!")

mod1.pxd

cdef void myfunc()

mod1.pyx

from mod2 cimport myapi, myclass cdef cppclass foo: void bar(): print("I am OK (from foo.bar)") cdef void myfunc(): print("I am OK") myapi() cdef foo f f.bar() # Stack var: Segmentation fault print("Calling myclass.mymethod...") cdef myclass t t.mymethod() # # Pointer: Segmentation fault # print("Calling myclass.mymethod...") # cdef myclass* t2 = new myclass() # t2.mymethod() cpdef test(): myfunc()

Main Python programme app.py

import mod1 mod1.test()

It's a segmentation fault which happens in a Cython struct myclass when using anything Python. Also in mod2, but the global function myapi is OK. From a struct method foo.bar but in the same file is also OK.

I'm using Python 3.8.2, and Cython 0.29.26

mod1 and mod2 are translated into C++ with cython -3 --cplus command, and compiled with gcc to .so files. It happened the same if using Python build tool. As suggested from https://stackoverflow.com/a/55669343/5581893 I tried to add -DCYTHON_PEP489_MULTI_PHASE_INIT=0 to all gcc commands but no help.

This situation seems strange, why are Python stuff not touch-able from mod2 (fails in struct only)?

Metadata

Metadata

Assignees

No one assigned

Labels

C++Code GenerationType Analysisfeature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You can’t perform that action at this time.

Từ khóa » Cython C++ Github