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

Namespace collision with libcombine? #23

Open
FFroehlich opened this issue Apr 2, 2021 · 3 comments
Open

Namespace collision with libcombine? #23

FFroehlich opened this issue Apr 2, 2021 · 3 comments

Comments

@FFroehlich
Copy link

A user reported the following issue with AMICI: AMICI-dev/AMICI#1483

What ends up happening is that sbml_model.all_elements has type libcombine.SBaseList instead of the usual libsbml.ListWrapperSBase.

I can reproduce that this always happens if both libcombine and libsbml are imported simultaneously. It appears that all kinds of other model elements are also stripped of their usual types and appear as SBase elements. I suspect that this is some kind of incompatibility that arises from the fact that both are swig exported interfaces.

@fbergmann
Copy link
Member

indeed, libCombine should probably not be exposing the duplicated symbol (as it won't make any use of that). Until i release a new version i'd recommend to first include libcombine, and then libsedml.

@leonplanken
Copy link

leonplanken commented Feb 14, 2025

We ran into this problem as well: a bug that only appeared when importing tellurium. Thanks to the comments above, I've reduced it to the following minimal example:

# type_of_bug = "NONE"
# type_of_bug = "ONLY_MEMORY_LEAK"
type_of_bug = "BOTH"
workaround = False

if type_of_bug == "ONLY_MEMORY_LEAK":
    import libcombine
import libsbml
if type_of_bug == "BOTH":
    import libcombine

plus_minus = {libsbml.AST_PLUS, libsbml.AST_MINUS}

m = libsbml.parseL3Formula('42')
if workaround:
    m = libsbml.ASTNode(m)
t = m.getType()  # This yields the memory leak message
try:
    if t in plus_minus:  # This yields the TypeError
        pass
except TypeError as e:
    print(e)
else:
    print("don't panic!")

Note that even when importing libcombine first, as suggested above, there's still an issue of a memory leak. However, we also found a workaround for both issues, using the ASTNode copy constructor.

@fbergmann
Copy link
Member

I'm afraid I still don't have a solution for this, several libraries (sbml, numl, combine, sedml, and sbng) use SWIG generated types out of the core libsbml library. Other than using a custom import order I have no solution for the moment. I'm happy to hear if anyone else found one.

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

No branches or pull requests

3 participants