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

Prototype error for CMessage.GetParamsColon on Python #1749

Open
worstje opened this issue Aug 15, 2020 · 2 comments
Open

Prototype error for CMessage.GetParamsColon on Python #1749

worstje opened this issue Aug 15, 2020 · 2 comments

Comments

@worstje
Copy link

worstje commented Aug 15, 2020

Version: 1.8.1

The API bindings appear unhappy in Python.

Traceback (most recent call last):
  File "/.../modules/blah.py", line 246, in OnPrivCTCPMessage
    self.PutModule("ParamsColon 1: "   str(message.GetParamsColon(1)))
  File "/.../znc/modpython/znc_core.py", line 3588, in GetParamsColon
     return _znc_core.CMessage_GetParamsColon(self, uIdx, uLen)
TypeError: Wrong number or type of arguments for overloaded function 'CMessage_GetParamsColon'.
  Possible C/C   prototypes are:
    CMessage::GetParamsColon(unsigned int,unsigned int) const
    CMessage::GetParamsColon(unsigned int) const

Relevant lines in /.../znc/modpython/znc_core.py are as follows:

def GetParamsColon(self, uIdx: 'unsigned int', uLen: 'unsigned int'=-1) -> "CString":
    return _znc_core.CMessage_GetParamsColon(self, uIdx, uLen)

Clearly an unsigned int cannot be -1 (why that definition on C side anyways?!), so my guess is that some code (SWIG?) chokes on this.

I have tried setting uLen to None in the hope it would fall back to the 1-parameter version, but no dice.

Temporary workaround for anyone who needs the default for that parameter:

import _znc_core
self.PutModule("ParamsColon 1: "   str(_znc_core.CMessage_GetParamsColon(message, 1)))

I don't know what the proper way is to resolve this. Regenerate SWIG? Fix the original class definition with a proper overload somehow? I leave it up to the experts. 😄

@DarthGandalf
Copy link
Member

Can you show your code?

@worstje
Copy link
Author

worstje commented Aug 15, 2020

It is pretty much in the traceback, which is why I didn't post it. It is just a global module, with the hook in it, and the line of the exception.

# paramcolonexample.py

import traceback
import znc

class paramcolonexample(znc.Module):
    description = "Example python3 module that shows broken GetParamColon binding"

    # virtual EModRet CModule::OnPrivCTCPMessage ( CCTCPMessage& Message )
    def OnPrivCTCPMessage(self, message):
        try:
            self.PutModule("Broken binding test!")
            self.PutModule("ParamsColon: "   str(message.GetParamsColon(3)))
        except Exception as ex:
            self.PutModule("An error occurred while executing this command.")
            self.PutModule(''.join(traceback.format_exception(etype=type(ex), value=ex, tb=ex.__traceback__)))
        return znc.CONTINUE

(Edited to add the return statement that is there in my code but forgotten about... but I might as well add it before someone is like 'you should put that in', because it is in there in reality. 😄 )

((And edited a second time because our conversation made me realize that you couldn't see the exception because znc loves swallowing uncaught exceptions.))

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

2 participants