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

Multiple static functions, with same name and different parameters in a class will only expose one #1851

Closed
unier opened this issue Aug 31, 2017 · 1 comment · Fixed by #4129

Comments

@unier
Copy link

unier commented Aug 31, 2017

Example:

c++:

class SqBufferIoStream : public SqIoStream {
public:
	static std::shared_ptr<SqBufferIoStream> Open(const std::string& data);
	static std::shared_ptr<SqBufferIoStream> Open();
};

cython:

cdef extern from "SqBufferIoStream.h":
    cdef cppclass SqBufferIoStream:
        @staticmethod
        shared_ptr[SqBufferIoStream] Open(const string s)
        @staticmethod
        shared_ptr[SqBufferIoStream] Open()
Error compiling Cython file:
------------------------------------------------------------
        for command, description in c_map:
            p_map[command] = description
        return p_map

    def executeCommand(self, command, parameters):
        cdef shared_ptr[SqInputStream] b = dynamic_pointer_cast[SqInputStream, SqBufferIoStream](SqBufferIoStream.Open(_json.dumps(parameters)))
                                                                                                                     ^
------------------------------------------------------------

SqFoundationTypes.pyx:200:118: Call with wrong number of arguments (expected 0, got 1)

If I change to:

cdef extern from "SqBufferIoStream.h":
    cdef cppclass SqBufferIoStream:
        @staticmethod
        shared_ptr[SqBufferIoStream] Open()
        @staticmethod
        shared_ptr[SqBufferIoStream] Open(const string s)
Error compiling Cython file:
------------------------------------------------------------

    def executeCommand(self, command, parameters):
        cdef shared_ptr[SqInputStream] b = dynamic_pointer_cast[SqInputStream, SqBufferIoStream](SqBufferIoStream.Open(_json.dumps(parameters)))
        cdef SqKeyValueList data = SqJsonParser.ParseAsSqValue(b).get().GetKeyValueList()
        cdef SqKeyValueList c_kvl = self.c_this.get().ExecuteCommand(command, data)
        cdef shared_ptr[SqBufferIoStream] buf = SqBufferIoStream.Open()
                                                                    ^
------------------------------------------------------------

SqFoundationTypes.pyx:203:69: Call with wrong number of arguments (expected 1, got 0)

Version:

cython --version
Cython version 0.25.2
@unier unier changed the title Multiple static functions, with same name and different parameters in a class will only expose only one Multiple static functions, with same name and different parameters in a class will only expose one Aug 31, 2017
@scoder scoder added this to the 3.0 milestone May 3, 2021
@matham
Copy link
Contributor

matham commented May 28, 2022

As a workaround until 3.0 is released here's how I solved it for my case using the example above:

cdef extern from "SqBufferIoStream.h":
    cdef cppclass SqBufferIoStream:
        @staticmethod
        shared_ptr[SqBufferIoStream] Open1 "Open"(const string s)
        @staticmethod
        shared_ptr[SqBufferIoStream] Open0 "Open"()

Then just call it as Open1 or Open0 in the cython code and it will emit the correct code in the c++ file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants