Skip to content
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

Conversion function redefinition error when handling C++ types #3741

Closed
KmolYuan opened this issue Jul 14, 2020 · 3 comments · Fixed by #3743
Closed

Conversion function redefinition error when handling C++ types #3741

KmolYuan opened this issue Jul 14, 2020 · 3 comments · Fixed by #3743

Comments

@KmolYuan
Copy link
Contributor

I have a extension class which including C++ member (std::vector<my_struct>, and my_struct has some std::pair<int, int> members).
And there also has a std::pair<int, int> type definition in the same source.

I'm found that the conversion function (std::pair<int, int> to tuple[int, int]) is defined twice unless added @cython.auto_pickle(False) on my extension class.

11510:18: error: redefinition of 'PyObject* __pyx_convert_pair_to_py_int____int(const std::pair<int, int>&)'
 static PyObject *__pyx_convert_pair_to_py_int____int(std::pair<int,int>  const &__pyx_v_p) {
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10055:18: note: 'PyObject* __pyx_convert_pair_to_py_int____int(const std::pair<int, int>&)' previously defined here
 static PyObject *__pyx_convert_pair_to_py_int____int(std::pair<int,int>  const &__pyx_v_p) {
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I'm not clearly know how Cython checks the tool functions of ctypedef.
In another case My extension members are sharing a same ctypedef with local variables, but this error is not occurred.

@KmolYuan KmolYuan changed the title "auto_pickle" option causes conversion function redefinition error when handling C++ member "ctypdef" causes conversion function redefinition error when handling C++ types Jul 14, 2020
@KmolYuan KmolYuan changed the title "ctypdef" causes conversion function redefinition error when handling C++ types Conversion function redefinition error when handling C++ types Jul 14, 2020
@KmolYuan
Copy link
Contributor Author

When I'm using vector[pair[int, int]] and map[int, bint] in the same file, the error comes again.
Regardless creating type alias or using original form can't solve the problem.

Maybe somewhere Cython treats bint as a different type when generating conversion functions.

@da-woods
Copy link
Contributor

This looks like substantially the same issue as #3716 and #3734. The problem is where Cython utility code is itself generating utility code. Each lot of 2nd-level generated utility code is generated without access to the full module scope so can end up sharing names.

I'll try to have a look at it in the near future. Although it looked trick to solve last time I looked

@KmolYuan
Copy link
Contributor Author

KmolYuan commented Jul 19, 2020

My case is little complex, which mixed a lot of functions and cannot extracted to a small one.
I'm not actually know what cause the duplicated code in my module.

The repo is here, change this line from Status & to object can reproduce the error: (build by setup.py)
https://github.com/KmolYuan/pyslvs/blob/master/pyslvs/topo_config.pyx#L187

But this error does not bother me at the moment.

scoder pushed a commit that referenced this issue Mar 27, 2021
* Avoid UtilityCode from cimport_from_pyx files
* Unique names for generated cfunc wrappers, avoid pxd pickle code
* Set .in_pxd on nodes prior to analyse_declarations

Fixes #3716
Fixes #3741
Fixes #3734
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants