modpython: Support global module hooks #98

The commit doesn't add support for the following module hooks:

    void OnClientCapLs(CClient* pClient, SCString& ssCaps)
    EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth)

The reason for this is they do not currently work with codegen.pl
This commit is contained in:
Kyle Fuller
2012-02-26 14:17:57 +00:00
parent 478dace3f5
commit 961e3a81c6
4 changed files with 78 additions and 10 deletions

View File

@@ -307,7 +307,7 @@ while (<$in>) {
}
say $out "\tif (!$a->{pyvar}) {";
say $out "\t\tCString sPyErr = m_pModPython->GetPyExceptionStr();";
say $out "\t\tDEBUG".'("modpython: " << GetUser()->GetUserName() << "/" << GetModName() << '."\"/$name: $a->{error}: \" << sPyErr);";
say $out "\t\tDEBUG".'("modpython: " << (GetUser() ? GetUser()->GetUserName() : CString("<no user>")) << "/" << GetModName() << '."\"/$name: $a->{error}: \" << sPyErr);";
print $out $cleanup;
say $out "\t\treturn $default;";
say $out "\t}";
@@ -323,14 +323,14 @@ while (<$in>) {
say $out "\t\tPyObject* pyVecEl = SWIG_NewInstanceObj(*i, SWIG_TypeQuery(\"$sub*\"), 0);";
say $out "\t\tif (!pyVecEl) {";
say $out "\t\t\tCString sPyErr = m_pModPython->GetPyExceptionStr();";
say $out "\t\t\tDEBUG".'("modpython: " << GetUser()->GetUserName() << "/" << GetModName() << '.
say $out "\t\t\tDEBUG".'("modpython: " << (GetUser() ? GetUser()->GetUserName() : CString("<no user>")) << "/" << GetModName() << '.
"\"/$name: can't convert element of vector '$a->{var}' to PyObject: \" << sPyErr);";
print $out $cleanup1;
say $out "\t\t\treturn $default;";
say $out "\t\t}";
say $out "\t\tif (PyList_Append($a->{pyvar}, pyVecEl)) {";
say $out "\t\t\tCString sPyErr = m_pModPython->GetPyExceptionStr();";
say $out "\t\t\tDEBUG".'("modpython: " << GetUser()->GetUserName() << "/" << GetModName() << '.
say $out "\t\t\tDEBUG".'("modpython: " << (GetUser() ? GetUser()->GetUserName() : CString("<no user>")) << "/" << GetModName() << '.
"\"/$name: can't add element of vector '$a->{var}' to PyObject: \" << sPyErr);";
say $out "\t\t\tPy_CLEAR(pyVecEl);";
print $out $cleanup1;
@@ -346,7 +346,7 @@ while (<$in>) {
say $out ", NULL);";
say $out "\tif (!pyRes) {";
say $out "\t\tCString sPyErr = m_pModPython->GetPyExceptionStr();";
say $out "\t\tDEBUG".'("modpython: " << GetUser()->GetUserName() << "/" << GetModName() << '."\"/$name failed: \" << sPyErr);";
say $out "\t\tDEBUG".'("modpython: " << (GetUser() ? GetUser()->GetUserName() : CString("<no user>")) << "/" << GetModName() << '."\"/$name failed: \" << sPyErr);";
print $out $cleanup;
say $out "\t\treturn $default;";
say $out "\t}";
@@ -364,7 +364,7 @@ while (<$in>) {
when (/^(.*)\*$/) {
say $out "\t\tint res = SWIG_ConvertPtr(pyRes, (void**)&result, SWIG_TypeQuery(\"$type\"), 0);";
say $out "\t\tif (!SWIG_IsOK(res)) {";
say $out "\t\t\tDEBUG(\"modpython: \" << GetUser()->GetUserName() << \"/\" << GetModName() << \"/$name was expected to return '$type' but error=\" << res);";
say $out "\t\t\tDEBUG(\"modpython: \" << (GetUser() ? GetUser()->GetUserName() : CString(\"<no user>\")) << \"/\" << GetModName() << \"/$name was expected to return '$type' but error=\" << res);";
say $out "\t\t\tresult = $default;";
say $out "\t\t}";
}
@@ -372,10 +372,10 @@ while (<$in>) {
say $out "\t\tCString* p = NULL;";
say $out "\t\tint res = SWIG_AsPtr_std_string(pyRes, &p);";
say $out "\t\tif (!SWIG_IsOK(res)) {";
say $out "\t\t\tDEBUG(\"modpython: \" << GetUser()->GetUserName() << \"/\" << GetModName() << \"/$name was expected to return '$type' but error=\" << res);";
say $out "\t\t\tDEBUG(\"modpython: \" << (GetUser() ? GetUser()->GetUserName() : CString(\"<no user>\")) << \"/\" << GetModName() << \"/$name was expected to return '$type' but error=\" << res);";
say $out "\t\t\tresult = $default;";
say $out "\t\t} else if (!p) {";
say $out "\t\t\tDEBUG(\"modpython: \" << GetUser()->GetUserName() << \"/\" << GetModName() << \"/$name was expected to return '$type' but returned NULL\");";
say $out "\t\t\tDEBUG(\"modpython: \" << (GetUser() ? GetUser()->GetUserName() : CString(\"<no user>\")) << \"/\" << GetModName() << \"/$name was expected to return '$type' but returned NULL\");";
say $out "\t\t\tresult = $default;";
say $out "\t\t} else result = *p;";
say $out "\t\tif (SWIG_IsNewObj(res)) free((char*)p); // Don't ask me, that's how SWIG works...";
@@ -384,7 +384,7 @@ while (<$in>) {
say $out "\t\tlong int x = PyLong_AsLong(pyRes);";
say $out "\t\tif (PyErr_Occurred()) {";
say $out "\t\t\tCString sPyErr = m_pModPython->GetPyExceptionStr();";
say $out "\t\t\tDEBUG".'("modpython: " << GetUser()->GetUserName() << "/" << GetModName() << '."\"/$name was expected to return EModRet but: \" << sPyErr);";
say $out "\t\t\tDEBUG".'("modpython: " << (GetUser() ? GetUser()->GetUserName() : CString("<no user>")) << "/" << GetModName() << '."\"/$name was expected to return EModRet but: \" << sPyErr);";
say $out "\t\t\tresult = $default;";
say $out "\t\t} else { result = (CModule::EModRet)x; }";
}
@@ -392,7 +392,7 @@ while (<$in>) {
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()->GetUserName() << "/" << GetModName() << '."\"/$name was expected to return EModRet but: \" << sPyErr);";
say $out "\t\t\tDEBUG".'("modpython: " << (GetUser() ? GetUser()->GetUserName() : CString("<no user>")) << "/" << GetModName() << '."\"/$name was expected to return EModRet but: \" << sPyErr);";
say $out "\t\t\tresult = $default;";
say $out "\t\t} else result = x ? true : false;";
}