mirror of
https://github.com/znc/znc.git
synced 2026-08-08 01:43:03 +02:00
Refactor default return values of callbacks of perl/python modules
See #1424
This commit is contained in:
+12
-35
@@ -45,13 +45,6 @@ print $out <<'EOF';
|
||||
* Don't change it manually. *
|
||||
***************************************************************************/
|
||||
|
||||
/*#include "module.h"
|
||||
#include "swigperlrun.h"
|
||||
#include <EXTERN.h>
|
||||
#include <perl.h>
|
||||
#include <XSUB.h>
|
||||
#include "pstring.h"*/
|
||||
|
||||
namespace {
|
||||
template<class T>
|
||||
struct SvToPtr {
|
||||
@@ -73,15 +66,8 @@ namespace {
|
||||
return static_cast<CModule::EModRet>(SvUV(sv));
|
||||
}
|
||||
}
|
||||
/*
|
||||
#define PSTART dSP; I32 ax; int ret = 0; ENTER; SAVETMPS; PUSHMARK(SP)
|
||||
#define PCALL(name) PUTBACK; ret = call_pv(name, G_EVAL|G_ARRAY); SPAGAIN; SP -= ret; ax = (SP - PL_stack_base) + 1
|
||||
#define PEND PUTBACK; FREETMPS; LEAVE
|
||||
#define PUSH_STR(s) XPUSHs(PString(s).GetSV())
|
||||
#define PUSH_PTR(type, p) XPUSHs(SWIG_NewInstanceObj(const_cast<type>(p), SWIG_TypeQuery(#type), SWIG_SHADOW))
|
||||
*/
|
||||
#define PSTART_IDF(Func) PSTART; XPUSHs(GetPerlObj()); PUSH_STR(#Func)
|
||||
#define PCALLMOD(Error, Success) PCALL("ZNC::Core::CallModFunc"); if (SvTRUE(ERRSV)) { DEBUG("Perl hook died with: " + PString(ERRSV)); Error; } else { Success; } PEND
|
||||
#define PCALLMOD(Error, Success) PCALL("ZNC::Core::CallModFunc"); if (SvTRUE(ERRSV)) { DEBUG("Perl hook died with: " + PString(ERRSV)); Error; } else { if (!SvIV(ST(0))) { Error; } Success; } PEND
|
||||
|
||||
EOF
|
||||
|
||||
@@ -89,30 +75,18 @@ while (<$in>) {
|
||||
my ($type, $name, $args, $default) = /(\S+)\s+(\w+)\((.*)\)(?:=(\w+))?/ or next;
|
||||
$type =~ s/(EModRet)/CModule::$1/;
|
||||
$type =~ s/^\s*(.*?)\s*$/$1/;
|
||||
unless (defined $default) {
|
||||
given ($type) {
|
||||
when ('bool') { $default = 'true' }
|
||||
when ('CModule::EModRet') { $default = 'CONTINUE' }
|
||||
when ('CString') { $default = '""' }
|
||||
when (/\*$/) { $default = "($type)nullptr" }
|
||||
}
|
||||
}
|
||||
my @arg = map {
|
||||
my ($t, $v) = /^\s*(.*\W)\s*(\w+)\s*$/;
|
||||
$t =~ s/^\s*(.*?)\s*$/$1/;
|
||||
my ($tt, $tm) = $t =~ /^(.*?)\s*?(\*|&)?$/;
|
||||
{type=>$t, var=>$v, base=>$tt, mod=>$tm//''}
|
||||
} split /,/, $args;
|
||||
say $out "$type CPerlModule::$name($args) {";
|
||||
say $out "\t$type result = $default;" if $type ne 'void';
|
||||
say $out "\tPSTART_IDF($name);";
|
||||
given ($type) {
|
||||
when ('CString') { print $out "\tPUSH_STR($default);" }
|
||||
when (/\*$/) { my $t=$type; $t=~s/^const//; print $out "\tPUSH_PTR($t, $default);" }
|
||||
when ('void') { print $out "\tmXPUSHi(0);" }
|
||||
default { print $out "\tmXPUSHi(static_cast<int>($default));" }
|
||||
unless (defined $default) {
|
||||
$default = "CModule::$name(" . (join ', ', map { $_->{var} } @arg) . ")";
|
||||
}
|
||||
say $out " // Default value";
|
||||
say $out "$type CPerlModule::$name($args) {";
|
||||
say $out "\t$type result{};" if $type ne 'void';
|
||||
say $out "\tPSTART_IDF($name);";
|
||||
for my $a (@arg) {
|
||||
given ($a->{type}) {
|
||||
when (/(vector\s*<\s*(.*)\*\s*>)/) {
|
||||
@@ -131,9 +105,12 @@ while (<$in>) {
|
||||
default { say $out "\tmXPUSHi($a->{var});" }
|
||||
}
|
||||
}
|
||||
say $out "\tPCALLMOD(,";
|
||||
my $x = 0;
|
||||
say $out "\t\tresult = ".sv($type)."(ST(0));" if $type ne 'void';
|
||||
say $out "\tPCALLMOD(";
|
||||
print $out "\t\t";
|
||||
print $out "result = " if $type ne 'void';
|
||||
say $out "$default;,";
|
||||
my $x = 1;
|
||||
say $out "\t\tresult = ".sv($type)."(ST(1));" if $type ne 'void';
|
||||
for my $a (@arg) {
|
||||
$x++;
|
||||
say $out "\t\t$a->{var} = PString(ST($x));" if $a->{base} eq 'CString' && $a->{mod} eq '&';
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
bool OnBoot()=true
|
||||
bool WebRequiresLogin()=true
|
||||
bool WebRequiresAdmin()=false
|
||||
bool OnBoot()
|
||||
bool WebRequiresLogin()
|
||||
bool WebRequiresAdmin()
|
||||
CString GetWebMenuTitle()
|
||||
bool OnWebPreRequest(CWebSock& WebSock, const CString& sPageName)=false
|
||||
bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl)=false
|
||||
VWebSubPages* _GetSubPages()
|
||||
bool OnWebPreRequest(CWebSock& WebSock, const CString& sPageName)
|
||||
bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl)
|
||||
VWebSubPages* _GetSubPages()=nullptr
|
||||
void OnPreRehash()
|
||||
void OnPostRehash()
|
||||
void OnIRCDisconnected()
|
||||
@@ -59,10 +59,10 @@ EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage)
|
||||
EModRet OnPrivNotice(CNick& Nick, CString& sMessage)
|
||||
EModRet OnChanNotice(CNick& Nick, CChan& Channel, CString& sMessage)
|
||||
EModRet OnTopic(CNick& Nick, CChan& Channel, CString& sTopic)
|
||||
bool OnServerCapAvailable(const CString& sCap)=false
|
||||
bool OnServerCapAvailable(const CString& sCap)
|
||||
void OnServerCapResult(const CString& sCap, bool bSuccess)
|
||||
EModRet OnTimerAutoJoin(CChan& Channel)
|
||||
bool OnEmbeddedWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl)=false
|
||||
bool OnEmbeddedWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl)
|
||||
EModRet OnAddNetwork(CIRCNetwork& Network, CString& sErrorRet)
|
||||
EModRet OnDeleteNetwork(CIRCNetwork& Network)
|
||||
EModRet OnSendToClient(CString& sLine, CClient& Client)
|
||||
|
||||
@@ -221,14 +221,9 @@ sub ModInfoByPath {
|
||||
sub CallModFunc {
|
||||
my $pmod = shift;
|
||||
my $func = shift;
|
||||
my $default = shift;
|
||||
my @arg = @_;
|
||||
my $res = $pmod->$func(@arg);
|
||||
# print "Returned from $func(@_): $res, (@arg)\n";
|
||||
unless (defined $res) {
|
||||
$res = $default if defined $default;
|
||||
}
|
||||
($res, @arg)
|
||||
(defined $res, $res, @arg)
|
||||
}
|
||||
|
||||
sub CallTimer {
|
||||
|
||||
@@ -248,14 +248,6 @@ while (<$in>) {
|
||||
my ($type, $name, $args, $default) = /(\S+)\s+(\w+)\((.*)\)(?:=(\w+))?/ or next;
|
||||
$type =~ s/(EModRet)/CModule::$1/;
|
||||
$type =~ s/^\s*(.*?)\s*$/$1/;
|
||||
unless (defined $default) {
|
||||
given ($type) {
|
||||
when ('bool') { $default = 'true' }
|
||||
when ('CModule::EModRet') { $default = 'CONTINUE' }
|
||||
when ('CString') { $default = '""' }
|
||||
when (/\*$/) { $default = "($type)nullptr" }
|
||||
}
|
||||
}
|
||||
my @arg = map {
|
||||
my ($t, $v) = /^\s*(.*\W)\s*(\w+)\s*$/;
|
||||
$t =~ s/^\s*(.*?)\s*$/$1/;
|
||||
@@ -263,10 +255,13 @@ while (<$in>) {
|
||||
{type=>$t, var=>$v, base=>$tb, mod=>$tm//'', pyvar=>"pyArg_$v", error=>"can't convert parameter '$v' to PyObject"}
|
||||
} split /,/, $args;
|
||||
|
||||
unless (defined $default) {
|
||||
$default = "CModule::$name(" . (join ', ', map { $_->{var} } @arg) . ")";
|
||||
}
|
||||
|
||||
unshift @arg, {type=>'$func$', var=>"", base=>"", mod=>"", pyvar=>"pyName", error=>"can't convert string '$name' to PyObject"};
|
||||
|
||||
my $cleanup = '';
|
||||
$default = '' if $type eq 'void';
|
||||
|
||||
say $out "$type CPyModule::$name($args) {";
|
||||
for my $a (@arg) {
|
||||
@@ -413,7 +408,7 @@ while (<$in>) {
|
||||
say $out "\t\t} else { result = (CModule::EModRet)x; }";
|
||||
}
|
||||
when ('bool') {
|
||||
say $out "\t\tint x = PyObject_IsTrue(pyRes);";
|
||||
say $out "\t\tint x = PyObject_IsTrue(pyRes);";
|
||||
say $out "\t\tif (-1 == x) {";
|
||||
say $out "\t\t\tCString sPyErr = m_pModPython->GetPyExceptionStr();";
|
||||
say $out "\t\t\tDEBUG".'("modpython: " << (GetUser() ? GetUser()->GetUserName() : CString("<no user>")) << "/" << GetModName() << '."\"/$name was expected to return EModRet but: \" << sPyErr);";
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
bool OnBoot()=true
|
||||
bool WebRequiresLogin()=true
|
||||
bool WebRequiresAdmin()=false
|
||||
bool OnBoot()
|
||||
bool WebRequiresLogin()
|
||||
bool WebRequiresAdmin()
|
||||
CString GetWebMenuTitle()
|
||||
bool OnWebPreRequest(CWebSock& WebSock, const CString& sPageName)=false
|
||||
bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl)=false
|
||||
VWebSubPages* _GetSubPages()
|
||||
bool OnWebPreRequest(CWebSock& WebSock, const CString& sPageName)
|
||||
bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl)
|
||||
VWebSubPages* _GetSubPages()=nullptr
|
||||
void OnPreRehash()
|
||||
void OnPostRehash()
|
||||
void OnIRCDisconnected()
|
||||
@@ -59,10 +59,10 @@ EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage)
|
||||
EModRet OnPrivNotice(CNick& Nick, CString& sMessage)
|
||||
EModRet OnChanNotice(CNick& Nick, CChan& Channel, CString& sMessage)
|
||||
EModRet OnTopic(CNick& Nick, CChan& Channel, CString& sTopic)
|
||||
bool OnServerCapAvailable(const CString& sCap)=false
|
||||
bool OnServerCapAvailable(const CString& sCap)
|
||||
void OnServerCapResult(const CString& sCap, bool bSuccess)
|
||||
EModRet OnTimerAutoJoin(CChan& Channel)
|
||||
bool OnEmbeddedWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl)=false
|
||||
bool OnEmbeddedWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl)
|
||||
EModRet OnAddNetwork(CIRCNetwork& Network, CString& sErrorRet)
|
||||
EModRet OnDeleteNetwork(CIRCNetwork& Network)
|
||||
EModRet OnSendToClient(CString& sLine, CClient& Client)
|
||||
@@ -106,7 +106,7 @@ void OnClientConnect(CZNCSock* pSock, const CString& sHost, unsigned short uPort
|
||||
void OnFailedLogin(const CString& sUsername, const CString& sRemoteIP)
|
||||
EModRet OnUnknownUserRaw(CClient* pClient, CString& sLine)
|
||||
EModRet OnUnknownUserRawMessage(CMessage& Message)
|
||||
bool IsClientCapSupported(CClient* pClient, const CString& sCap, bool bState)=false
|
||||
bool IsClientCapSupported(CClient* pClient, const CString& sCap, bool bState)
|
||||
void OnClientCapRequest(CClient* pClient, const CString& sCap, bool bState)
|
||||
EModRet OnModuleLoading(const CString& sModName, const CString& sArgs, CModInfo::EModuleType eType, bool& bSuccess, CString& sRetMsg)
|
||||
EModRet OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg)
|
||||
|
||||
Reference in New Issue
Block a user