GithubHelp home page GithubHelp logo

Bogus method wrappers about eman2 HOT 5 CLOSED

cryoem avatar cryoem commented on August 31, 2024
Bogus method wrappers

from eman2.

Comments (5)

sludtke42 avatar sludtke42 commented on August 31, 2024

from eman2.

jcbollinger avatar jcbollinger commented on August 31, 2024

The main problem with the Vector wrappers is not the constness mismatch, which I agree does not likely present an issue in practice, but rather the reference vs value mismatch, which is hard to believe yields a result that works in any way correctly, unless by the grace of a lucky compiler optimization.

Changing the cast to match the function does eliminate the warning, and, I expect, correct any misbehavior. But inasmuch as the vector templates appear to be used only for built-in numeric types, a bigger win might be achieved by changing the functions to match the cast -- that is, to accept arguments by value instead of by reference. I would have gone ahead and submitted the PR if I were confident which of those alternatives would be preferred.

from eman2.

sludtke42 avatar sludtke42 commented on August 31, 2024

from eman2.

sludtke42 avatar sludtke42 commented on August 31, 2024

from eman2.

jcbollinger avatar jcbollinger commented on August 31, 2024

I apologize. It appears that I would have saved us both some time by preparing the following demo earlier. It segfaults when I run it against a binary installation of EMAN2 v2.31 (the official 64-bit Linux build, that is, not one of my own):

from EMAN2 import Vec3f

v = new Vec3f()
# prints "Vec3f(0.00,0.00,0.00)":
print v

# causes a segfault in the official build:
v.set_value(1.0, 1.0, 1.0)

# prints garbage in those of my own builds that reach this point:
print v

The behavior of the above example shows that the typedefs you point out and their use to interpose references to function pointers into the wrappers do not resolve the issue. I see no reason to think that they ever did. My best guess is that they were effective at disguising the problem from the contributor's compiler, so that it no longer warned, leading the contributor to suppose erroneously that the issue was in fact resolved.

The Python code in the current codebase does not exercise these particular wrappers, which mitigates the issue, and may explain why it has not been fixed. Of course, they could be unused in part because the issue has not been fixed. In any event, the issue stands as a trap for project contributors who try to use those wrappers in the future.

I will shortly submit a PR that actually does fix the problem for each of the wrapped vector classes. Although I think that the best solution would be to change the vector templates so that these particular functions accept their arguments by value (as their history shows they once did), and although my analysis of the current codebase is that doing so would have only positive effects any and everywhere within, I understand your reluctance to apply changes with broad scope. Accordingly, the PR will resolve the issue simply by fixing the wrappers to match the classes and removing the needless, otherwise-unused typedefs.

from eman2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.