Skip to content

Commit

Permalink
Various fixes of modperl and modpython.
Browse files Browse the repository at this point in the history
Including cygwin support #216
  • Loading branch information
DarthGandalf committed Aug 26, 2012
1 parent a1e8b08 commit f80ae4a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 22 deletions.
4 changes: 2 additions & 2 deletions modules/Makefile.in
Expand Up @@ -20,14 +20,14 @@ CXX := @CXX@
MODFLAGS := -I$(srcdir)/../include -I../include @CPPFLAGS@ @MODFLAGS@
MODLINK := @MODLINK@
LDFLAGS := @LDFLAGS@
ISCYGWIN := @ISCYGWIN@

# LIBS are not and should not be used in here.
# The znc binary links already against those.
# ...but not on cygwin!
LIBS :=
ifeq "@ISCYGWIN@" "1"
ifeq "$(ISCYGWIN)" "1"
LIBS += @LIBS@
LDFLAGS += ${LIBS}
endif

PERL_ON := @PERL@
Expand Down
5 changes: 4 additions & 1 deletion modules/modperl.cpp
Expand Up @@ -63,10 +63,13 @@ class CModPerl: public CModule {
m_pPerl = perl_alloc();
perl_construct(m_pPerl);
if (perl_parse(m_pPerl, xs_init, argc, argv, environ)) {
sMessage = "Can't initialize perl. ";
if (SvTRUE(ERRSV)) {
sMessage += PString(ERRSV);
}
perl_free(m_pPerl);
PERL_SYS_TERM();
m_pPerl = NULL;
sMessage = "Can't initialize perl.";
DEBUG(__PRETTY_FUNCTION__ << " can't init perl");
return false;
}
Expand Down
18 changes: 13 additions & 5 deletions modules/modperl/Makefile.inc
Expand Up @@ -14,8 +14,16 @@ modperlLDFLAGS := $(PERL_LD)
# Find additional headers for out-of-tree build
modperlCXXFLAGS += -I.

ifeq "$(ISCYGWIN)" "1"
PERLCEXT_EXT := "dll"
PERLDEPONMOD := "modperl.so"
else
PERLCEXT_EXT := "so"
PERLDEPONMOD :=
endif

PERLHOOK := modperl_install
CLEAN += modperl/ZNC.so modperl/ZNC.pm modperl/ZNC.o
CLEAN += modperl/ZNC.$(PERLCEXT_EXT) modperl/ZNC.pm modperl/ZNC.o
CLEAN += modperl/swigperlrun.h modperl/ZNC.cpp modperl/functions.cpp
CLEAN += modperl/gen
all: modperl_all
Expand All @@ -28,11 +36,11 @@ endif

install: $(PERLHOOK)

modperl_all: modperl/ZNC.so modperl/swigperlrun.h modperl/functions.cpp
modperl_all: modperl/ZNC.$(PERLCEXT_EXT) modperl/swigperlrun.h modperl/functions.cpp

modperl/ZNC.so: modperl/ZNC.o Makefile
modperl/ZNC.$(PERLCEXT_EXT): modperl/ZNC.o Makefile modperl.so
$(E) Linking ZNC Perl bindings library...
$(Q)$(CXX) $(MODFLAGS) $(LDFLAGS) $(MODLINK) -o $@ $< $(PERL_LD)
$(Q)$(CXX) $(MODFLAGS) $(LDFLAGS) $(MODLINK) -o $@ $< $(PERL_LD) $(PERLDEPONMOD)

modperl/ZNC.o: modperl/ZNC.cpp Makefile
@mkdir -p modperl
Expand All @@ -51,6 +59,6 @@ modperl_install: install_datadir modperl_all
$(INSTALL_DATA) $$i $(DESTDIR)$(MODDIR); \
done
mkdir -p $(DESTDIR)$(MODDIR)/modperl
$(INSTALL_PROGRAM) modperl/ZNC.so $(DESTDIR)$(MODDIR)/modperl
$(INSTALL_PROGRAM) modperl/ZNC.$(PERLCEXT_EXT) $(DESTDIR)$(MODDIR)/modperl
$(INSTALL_DATA) modperl/ZNC.pm $(DESTDIR)$(MODDIR)/modperl
$(INSTALL_DATA) $(srcdir)/modperl/startup.pl $(DESTDIR)$(MODDIR)/modperl
32 changes: 23 additions & 9 deletions modules/modpython.cpp
Expand Up @@ -81,8 +81,13 @@ class CModPython: public CModule {

bool OnLoad(const CString& sArgsi, CString& sMessage) {
CString sModPath, sTmp;
if (!CModules::FindModPath("modpython/_znc_core.so", sModPath, sTmp)) {
sMessage = "modpython/_znc_core.so not found.";
#ifdef __CYGWIN__
CString sDllPath = "modpython/_znc_core.dll";
#else
CString sDllPath = "modpython/_znc_core.so";
#endif
if (!CModules::FindModPath(sDllPath, sModPath, sTmp)) {
sMessage = sDllPath + " not found.";
return false;
}
sTmp = CDir::ChangeDir(sModPath, "..");
Expand Down Expand Up @@ -328,14 +333,23 @@ class CModPython: public CModule {
}

virtual ~CModPython() {
if (!m_PyZNCModule) {
DEBUG("~CModPython(): seems like CModPython::OnLoad() didn't initialize python");
return;
}
PyObject* pyFunc = PyObject_GetAttrString(m_PyZNCModule, "unload_all");
PyObject* pyRes = PyObject_CallFunctionObjArgs(pyFunc, NULL);
if (!pyRes) {
CString sRetMsg = GetPyExceptionStr();
DEBUG("modpython tried to unload all modules in its destructor, but: " << sRetMsg);
}
Py_CLEAR(pyRes);
Py_CLEAR(pyFunc);
if (!pyFunc) {
CString sRetMsg = GetPyExceptionStr();
DEBUG("~CModPython(): couldn't find unload_all: " << sRetMsg);
return;
}
PyObject* pyRes = PyObject_CallFunctionObjArgs(pyFunc, NULL);
if (!pyRes) {
CString sRetMsg = GetPyExceptionStr();
DEBUG("modpython tried to unload all modules in its destructor, but: " << sRetMsg);
}
Py_CLEAR(pyRes);
Py_CLEAR(pyFunc);

Py_CLEAR(m_PyFormatException);
Py_CLEAR(m_PyZNCModule);
Expand Down
18 changes: 13 additions & 5 deletions modules/modpython/Makefile.inc
Expand Up @@ -10,8 +10,16 @@ PYTHONCOMMON += -Wno-redundant-decls
modpythonCXXFLAGS := $(PYTHONCOMMON) -I.
modpythonLDFLAGS := $(PY_LDFLAGS)

ifeq "${ISCYGWIN}" "1"
PYCEXT_EXT := dll
PYDEPONMOD := ./modpython.so
else
PYCEXT_EXT := so
PYDEPONMOD :=
endif

PYTHONHOOK := modpython_install
CLEAN += modpython/_znc_core.so modpython/_znc_core.cpp modpython/znc_core.py modpython/znc_core.pyc
CLEAN += modpython/_znc_core.$(PYCEXT_EXT) modpython/_znc_core.cpp modpython/znc_core.py modpython/znc_core.pyc
CLEAN += modpython/swigpyrun.h modpython/znc.pyc modpython/functions.cpp modpython/compiler *.pyc
CLEAN += modpython/_znc_core.o modpython/compiler.o
ifneq "$(srcdir)" "."
Expand All @@ -35,7 +43,7 @@ install: $(PYTHONHOOK)
ifeq "$(PYTHON_ON)" "yes"
all: modpython_all
endif
modpython_all: modpython/_znc_core.so modpython/znc.pyc modpython/znc_core.pyc
modpython_all: modpython/_znc_core.$(PYCEXT_EXT) modpython/znc.pyc modpython/znc_core.pyc
modpython_all: $(addsuffix c, $(notdir $(wildcard $(srcdir)/*.py)))

modpython/_znc_core.o: modpython/_znc_core.cpp Makefile
Expand All @@ -44,9 +52,9 @@ modpython/_znc_core.o: modpython/_znc_core.cpp Makefile
$(E) Building ZNC python bindings library...
$(Q)$(CXX) $(MODFLAGS) -I$(srcdir) -MD -MF .depend/modpython.library.dep $(PYTHONCOMMON) -o $@ $< -c

modpython/_znc_core.so: modpython/_znc_core.o Makefile
modpython/_znc_core.$(PYCEXT_EXT): modpython/_znc_core.o Makefile modpython.so
$(E) Linking ZNC python bindings library...
$(Q)$(CXX) $(MODFLAGS) $(LDFLAGS) $(MODLINK) -o $@ $< $(PY_LDFLAGS)
$(Q)$(CXX) $(MODFLAGS) $(LDFLAGS) $(MODLINK) -o $@ $< $(PY_LDFLAGS) $(PYDEPONMOD)

ifneq "$(SWIG)" ""
modpython/znc_core.py modpython/_znc_core.cpp modpython/functions.cpp modpython/swigpyrun.h: modpython/codegen.pl modpython/functions.in Makefile
Expand All @@ -70,7 +78,7 @@ modpython_install: install_datadir modpython_all
$(INSTALL_DATA) $$i $(DESTDIR)$(MODDIR); \
done
mkdir -p $(DESTDIR)$(MODDIR)/modpython
$(INSTALL_PROGRAM) modpython/_znc_core.so $(DESTDIR)$(MODDIR)/modpython
$(INSTALL_PROGRAM) modpython/_znc_core.$(PYCEXT_EXT) $(DESTDIR)$(MODDIR)/modpython
$(INSTALL_DATA) modpython/znc_core.pyc $(DESTDIR)$(MODDIR)/modpython
if test -r modpython/znc_core.py;\
then $(INSTALL_DATA) modpython/znc_core.py $(DESTDIR)$(MODDIR)/modpython;\
Expand Down
2 changes: 2 additions & 0 deletions modules/modpython/znc.py
Expand Up @@ -575,6 +575,8 @@ def unload_module(module):
def unload_all():
while len(_py_modules) > 0:
mod = _py_modules.pop()
# add it back to set, otherwise unload_module will be sad
_py_modules.add(mod)
unload_module(mod)


Expand Down

0 comments on commit f80ae4a

Please sign in to comment.