[kde-freebsd] [SOLVED] [Call for Help] kpythonpluginfactory (Printer Configuration)

David Naylor naylor.b.david at gmail.com
Sat Oct 31 15:49:31 CET 2009


On Saturday, 31 October 2009 10:26:55 David Naylor wrote:
> On Friday, 30 October 2009 18:25:17 Kris Moore wrote:
> > On Fri, 30 Oct 2009, David Naylor wrote:
> > > Hi,
> > >
> > > It appears that kpythonpluginfactory does not work when the python
> > > script calls a lib-dynload object (such as 'import time').  A typical
> > > message is:
> > >
> > > ImportError: /usr/local/lib/python2.6/lib-dynload/time.so: Undefined
> > > symbol "PyExc_IOError"
> > >
> > > This stops system-settings-printer-kde from working (and, I think
> > > plasma- python scripting).  I know this worked in KDE 4.2.0.  A
> > > tentative speculation to the cause leads me to conclude something
> > > happened to FreeBSD (I still needs to do an upgrade to RC2)*.
> > >
> > > I did, however, find a work around: get kpythonpluginfactory to link
> > > statically to python.  This obviously leads to a bigger file.
> > >
> > > Does anyone have KDE <4.2.2 running, if so please install
> > > print/system-config- printer-kde and see if you can load the "Printer
> > > Configuration" in systemsettings.  Please report if the config module
> > > loads and what version of KDE and FreeBSD you are running.
> > >
> > > Thanks,
> > >
> > > David
> > >
> > > *I'm also having problems with cups-smb and this may be related
> >
> > David,
> >
> > I did some investigation with this issue a while back. I think its a bug
> > in the python port itself, none of the lib-dynload libraries are linked
> > to the main python library. For example, if you run this:
> >
> > setenv LD_PRELOAD "/usr/local/lib/libpython2.6.so" ; systemsettings
> >
> > You should now be able to bring up the KDE printer interface. If you do
> >  this, you can see what those libs are linked to:
> >
> > # cd /usr/local/lib/python2.6/lib-dynload
> > # setenv LD_LIBRARY_PATH `pwd`
> > # ldd time.so
> > time.so:
> >  	libm.so.5 => /lib/libm.so.5
> >  	libthr.so.3 -> /lib/libthr.so.3
> >  	libc.so.7 => /lib/libc.so.7
> >
> > I'm thinking that if we fix the python port to link these lib-dynload/*
> >  libaries to /usr/local/lib/libpython2.6.so the problem will go away.
> >  Investigating this now actually, but if somebody else had ideas on this,
> >  please let us know :)
> 
> This is actually a design feature of python.  If those libraries are linked
>  to libpython then it will break the case where one links statically to
>  libpython. See http://bugs.python.org/issue4434 for the PR at python that
>  discusses it.
> 
> The way to get around this is to dlopen libpython with RTLD_GLOBAL.  I've
> checked the code in kpythonpluginfactory and that is exactly what it does.
> That behaviour has never changed.
> 
> I do remember this working for me a while back and stopped after I did a
> system wide upgrade.  This, I presume, also works for Linux.
> 
> I'm planning on upgrading to RC2 and if the issue is still present I'll
>  write a simple test program that should exhibit the same behaviour and
>  check to see if it works on older versions of FreeBSD.

It still does not work under RC2.  I am now doubting this is a regression and 
it was planetary alignments that had it working for me previously :-)

I wrote a test program that *should* trigger the same problem.  See 
rtld_global.shar for the program.  The default behaviour is my fix, to trigger 
the problem run `make -DTRIGGER`.  It is a small program and should be easy to 
figure out.  

See attached for the fix.  Add the patch to devel/kdebindings4-python-pykde4 
and reinstall. 

If you encounter any problems please let me know.  

Regards
-------------- next part --------------
# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	rtld_global
#	rtld_global/Makefile
#	rtld_global/libmaster.c
#	rtld_global/main.c
#	rtld_global/libslave.c
#	rtld_global/common.h
#	rtld_global/libplugin.c
#
echo c - rtld_global
mkdir -p rtld_global > /dev/null 2>&1
echo x - rtld_global/Makefile
sed 's/^X//' >rtld_global/Makefile << '54185eeffb995a36288ad17f38c2bdc0'
X.SUFFIXES: .a .c .o .so .so.1
X.SILENT:
X
XCFLAGS=-Wall -rdynamic
X
X.if defined(TRIGGER)
XCFLAGS+=-DTRIGGER
X.endif
X
XCC=cc
XAR=ar
XLN=ln
X
Xall:
X	echo "Running test without linking: "
X	make clean test #> /dev/null
X	echo "done"
X	echo
X	echo "Running test with linking: "
X	make clean test -DLINKED #> /dev/null
X	echo "done"
X
Xclean:
X	rm -f *.a *.o *.so* main
X
Xtest: main libmaster.so libslave.so
X	env LD_LIBRARY_PATH=${PWD} ./main
X
X.c.o:
X	${CC} ${CFLAGS} -c -fPIC -o $@ $<
X
X.c.so:
X	${CC} ${CFLAGS} -fPIC -shared -Wl,-soname,$@ -o $@ $<
X
X.if defined(LINKED)
Xlibplugin.so: libplugin.c libmaster.so
X	${CC} ${CFLAGS} -DLINKED -fPIC -L. -lmaster -shared -Wl,-soname,$@ -o $@ $<
X.endif
X
Xmain: main.o libplugin.so
X	cc ${CFLAGS} -o main main.o
54185eeffb995a36288ad17f38c2bdc0
echo x - rtld_global/libmaster.c
sed 's/^X//' >rtld_global/libmaster.c << '4c7e49ccff36dd33ab5357b611fe5d83'
X#include "common.h"
X
Xint master_func() {
X  void* libslave;
X  func_t func;
X
X  printf("libmaster: opening libslave:");
X  libslave = dlopen("libslave.so", RTLD_NOW);
X  STATUS_CHECK(libslave);
X
X  printf("libmaster: getting symbol 'libslave::slave_func':");
X  func = (func_t)dlfunc(libslave, "slave_func");
X  STATUS_CHECK(func);
X
X  printf("libmaster: calling 'libslave::slave_func'...\n");
X  return func();
X}
X
Xconst char* master_name() {
X  return "libmaster.1";
X}
4c7e49ccff36dd33ab5357b611fe5d83
echo x - rtld_global/main.c
sed 's/^X//' >rtld_global/main.c << 'cb6b43e30862d408f1380a58a3050ed8'
X#include "common.h"
X
Xint main(int argc, char** argv) {
X  void* libplugin;
X  func_t func;
X
X  printf("main: opening libplugin:");
X  libplugin = dlopen("libplugin.so", RTLD_LAZY /*| RTLD_GLOBAL*/);
X  STATUS_CHECK(libplugin);
X
X  printf("main: getting symbol 'libplugin::plugin_func':");
X  func = (func_t)dlfunc(libplugin, "plugin_func");
X  STATUS_CHECK(func);
X
X  printf("main: calling 'libplugin::plugin_func'...\n");
X  return func();
X}
cb6b43e30862d408f1380a58a3050ed8
echo x - rtld_global/libslave.c
sed 's/^X//' >rtld_global/libslave.c << '6027f0c5e11bc3f1d64c5398f3095d35'
X#include <stdio.h>
X
X/* Forward declaration from libmaster */
Xconst char* master_name();
X
Xint slave_func() {
X  printf("libslave: %s\n", master_name());
X  return 0;
X}
6027f0c5e11bc3f1d64c5398f3095d35
echo x - rtld_global/common.h
sed 's/^X//' >rtld_global/common.h << '96ded3809880f52ca04e85b8175d157f'
X#include <dlfcn.h>
X#include <stdio.h>
X
X#define STATUS_CHECK(var)                                                     \
X  if ((var) == NULL) {                                                          \
X    printf(" failure (%s)\n", dlerror());                                     \
X    return 1;                                                                 \
X  } else                                                                      \
X    printf(" success\n")
X
Xtypedef int (*func_t)();
96ded3809880f52ca04e85b8175d157f
echo x - rtld_global/libplugin.c
sed 's/^X//' >rtld_global/libplugin.c << 'a806cc4670bd702634b1d6e2d06150e5'
X#include "common.h"
X
X#ifdef LINKED
Xint master_func();
X#endif
X
Xint plugin_func() {
X  func_t func;
X
X#if !defined(LINKED) || defined(TRIGGER)
X  void* libmaster;
X
X  printf("libplugin: opening libmaster:");
X  libmaster = dlopen("libmaster.so", RTLD_LAZY | RTLD_GLOBAL);
X  STATUS_CHECK(libmaster);
X#else
X  void* libplugin;
X
X  printf("libplugin: exposing symbols globally:");
X  libplugin = dlopen("libplugin.so", RTLD_NOLOAD | RTLD_GLOBAL);
X  STATUS_CHECK(libplugin);
X#endif
X
X#ifndef LINKED
X  printf("libplugin: getting symbol 'libmaster::master_func':");
X  func = (func_t)dlfunc(libmaster, "master_func");
X  STATUS_CHECK(func);
X#else
X  func = &master_func;
X#endif
X
X  printf("libplugin: calling 'libmaster::master_func'...\n");
X  return func();
X}
a806cc4670bd702634b1d6e2d06150e5
exit

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch-python_pykde4_kpythonpluginfactory_kpythonpluginfactory.cpp
Type: text/x-c++src
Size: 763 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kde-freebsd/attachments/20091031/4b87e1a7/attachment.cpp 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: This is a digitally signed message part.
Url : http://mail.kde.org/pipermail/kde-freebsd/attachments/20091031/4b87e1a7/attachment.sig 


More information about the kde-freebsd mailing list