Permalink
Browse files

Fix global python modules.

  • Loading branch information...
1 parent 76aaafd commit 0c9eae226eb70d28f3e212d26b58e3dbd461c846 Alexey Sokolov committed with kylef Aug 9, 2011
Showing with 32 additions and 3 deletions.
  1. +1 −0 modules/modpython/functions.in
  2. +9 −0 modules/modpython/modpython.i
  3. +13 −1 modules/modpython/module.h
  4. +9 −2 modules/modpython/znc.py
@@ -61,3 +61,4 @@ void OnServerCapResult(const CString& sCap, bool bSuccess)
EModRet OnTimerAutoJoin(CChan& Channel)
bool OnEmbeddedWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl)=false
+EModRet OnModuleLoading(const CString& sModName, const CString& sArgs, bool& bSuccess, CString& sRetMsg)
@@ -73,6 +73,15 @@ namespace std {
}
}
+%typemap(out) CString&, CString* {
+ if ($1) {
+ $result = CPyRetString::wrap(*$1);
+ } else {
+ $result = Py_None;
+ Py_INCREF(Py_None);
+ }
+}
+
#define u_short unsigned short
#define u_int unsigned int
#include "../ZNCString.h"
View
@@ -23,6 +23,13 @@ class CPyModule : public CModule {
CModPython* m_pModPython;
VWebSubPages* _GetSubPages();
public:
+ CPyModule(const CString& sModName, const CString& sDataPath,
+ PyObject* pyObj, CModule* pModPython)
+ : CModule(NULL, sModName, sDataPath) {
+ m_pyObj = pyObj;
+ Py_INCREF(pyObj);
+ m_pModPython = reinterpret_cast<CModPython*>(pModPython);
+ }
CPyModule(CUser* pUser, const CString& sModName, const CString& sDataPath,
PyObject* pyObj, CModule* pModPython)
: CModule(NULL, pUser, sModName, sDataPath) {
@@ -108,16 +115,21 @@ class CPyModule : public CModule {
virtual void OnServerCapResult(const CString& sCap, bool bSuccess);
virtual EModRet OnTimerAutoJoin(CChan& Channel);
bool OnEmbeddedWebRequest(CWebSock&, const CString&, CTemplate&);
+EModRet OnModuleLoading(const CString& sModName, const CString& sArgs, bool& bSuccess, CString& sRetMsg);
};
static inline CPyModule* AsPyModule(CModule* p) {
return dynamic_cast<CPyModule*>(p);
}
-inline CPyModule* CreatePyModule(CUser* pUser, const CString& sModName, const CString& sDataPath, PyObject* pyObj, CModule* pModPython) {
+inline CPyModule* CreateUserPyModule(CUser* pUser, const CString& sModName, const CString& sDataPath, PyObject* pyObj, CModule* pModPython) {
return new CPyModule(pUser, sModName, sDataPath, pyObj, pModPython);
}
+inline CPyModule* CreateGlobalPyModule(const CString& sModName, const CString& sDataPath, PyObject* pyObj, CModule* pModPython) {
+ return new CPyModule(sModName, sDataPath, pyObj, pModPython);
+}
+
class CPyTimer : public CTimer {
PyObject* m_pyObj;
CModPython* m_pModPython;
View
@@ -438,11 +438,15 @@ def load_module(modname, args, user, retmsg, modpython):
return 1
cl = pymodule.__dict__[modname]
module = cl()
- module._cmod = CreatePyModule(user, modname, datapath, module, modpython)
+ if user:
+ module._cmod = CreateUserPyModule(user, modname, datapath, module, modpython)
+ else:
+ module._cmod = CreateGlobalPyModule(modname, datapath, module, modpython)
module.nv = ModuleNV(module._cmod)
module.SetDescription(cl.description)
module.SetArgs(args)
module.SetModPath(pymodule.__file__)
+ module.SetType(cl.module_type)
if user:
user.GetModules().push_back(module._cmod)
@@ -488,8 +492,11 @@ def load_module(modname, args, user, retmsg, modpython):
def unload_module(module):
module.OnShutdown()
cmod = module._cmod
+ if module.GetType() == ModuleTypeUser:
+ cmod.GetUser().GetModules().removeModule(cmod)
+ elif module.GetType() == ModuleTypeGlobal:
+ CZNC.Get().GetModules().removeModule(cmod)
del module._cmod
- cmod.GetUser().GetModules().removeModule(cmod)
cmod.DeletePyModule()
del cmod

0 comments on commit 0c9eae2

Please sign in to comment.