public inbox for guile-gtk@sourceware.org
 help / color / mirror / Atom feed
* Re: guile-gtk without dlopen (HP-UX) (fwd)
@ 1999-11-08 20:10 Stephen Tell
  1999-11-09 11:21 ` Marius Vollmer
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Tell @ 1999-11-08 20:10 UTC (permalink / raw)
  To: Marius Vollmer; +Cc: Guile-Gtk List

(sorry -  a previous fragment of this message got away from me
too soon.)

On 8 Nov 1999, Marius Vollmer wrote:

> However, in recent releases of Guile, dynamic-link uses RTLD_GLOBAL by
> default and thus libguiledlopenhelper is not needed at all (on dlopen
> platforms).  You might have to check the HPUX support of Guile if it
> behaves correctly, tho.  You could try to hack gtk/dynlink.scm so that
> it doesn't use the %sgtk-* functions at all.  If this doesn't work, we
> can then see how you can get by without dynamic linking.

I got my program running by hacking a copy of gtk/dynlink.scm,
to remove all of the sgtk/dlopen stuff, and changing 
merge-compiled-code to call the procedures try-using-libtool-name
and link-dynamic-module (found in boot-9.scm) instead of
dlopen-libtool-library and %sgtk-dlinit.

It looked like I wanted to use find-and-link-dynamic-module,
but it doesn't let the caller specify the init function and also looks in
searches for libtool .la files in %load-path.    Instead of adapting one
of the path-searching functions, I just coded in the right directory name
for this test.  FWIW, the hacked dynlink.scm is below.

Looking in %load-path seems pretty bogus, because by default it seems to
contain only directories under $PREFIX/share.  Either I must have to
manually add the right architecture-specific directories to
GUILE_LOAD_PATH, or it should really be looking in the shared library
path.

Somthing isn't quite right about this yet, because this doesn't work with
standalone guile-gtk applications.  I can get "guile-gtk -s
hello-world.scm" to work with my hacked dynlink.scm, but not "guile -s"

$ guile -s ./hello-world.scm
in sgt's hacked dynlink.scm
module-prefix is gtk-1.2
new merge-compiled-code guilegtk-1.2 sgtk_init_gtk_gtk_glue
ERROR: In procedure dynamic-call in expression (dynamic-call initname dynobj):
ERROR: undefined function

I think this may mean that I'm not really managing to load the dynamic
library, but that I can use it if it is already linked in. Part of my
difficulty modifying dynlink.scm is that I don't really understand what
the rest of merge-compiled-code is trying to do - possibly fiddling with
the module system to avoid loading anything twice?  (Still anxiously
waiting some real guile documentation here.)

And while I'm getting tracebacks on errors within my program, I can't
for the life of me get tracebacks from hello-world.scm, despite sprinkling
around the usual incantation: 
	(debug-enable 'backtrace) (read-enable 'positions)


Sorry for rambling on...  I've got a lashup that seems to work, but
haven't helped advance things much in general. This may be good enough for
me for a while.  I'll also try sprinkling (display) statements around the
dynamic-linking stuff in boot-9.scm.


> For the real fix, I think we need to have configure find out whether
> libguiledlopenhelper is needed or not because people might still be
> using old versions of Guile.

But we might as well skip libguiledlopenhelper if HAVE_DLOPEN is false,
since it isn't going to work anyway.

Thanks for the suggestions!
Steve

P.S.  The name of the environment variable containing the shared library
path varies, by the way: "libtool --config | grep shlibpath_var" will
yield LD_LIBRARY_PATH on linux and solaris, SHLIB_PATH on HP-UX.



-- 
Steve Tell | tell@cs.unc.edu | http://www.cs.unc.edu/~tell | KF4ZPF
Research Associate, Microelectronic Systems Laboratory
Computer Science Department, UNC@Chapel Hill.   W:919-962-1845

;; -*- scheme -*-

(display "in sgt's hacked dynlink.scm\n")

(debug-enable 'debug)
(debug-enable 'backtrace)
(read-enable 'positions)

(define-module (gtk dynlink)
  :use-module (gtk config)
  :use-module (ice-9 regex)
  :use-module (ice-9 debug)
)

(define (update-registered-modules)
  (set! registered-modules 
	(append! (convert-c-registered-modules #f)
		 registered-modules)))
;
; my attempt at using guile's own dynamic-libary stuff from boot-9.
;
(define-public (merge-compiled-code init-func libname)
  (let* ((module (current-module))
	 (interface (module-public-interface module))
	 (libnamenolib (make-shared-substring libname 3)))
    ;; make the new primitives visible from within the current module.
    (module-use! module interface) ; XXX - is this safe?
    (save-module-excursion
     (lambda ()
       (update-registered-modules)
       (set-current-module interface)

       (display "new merge-compiled-code ")
       (display libnamenolib)(display " ")(display init-func)(newline)

       (let* ((modname (list 'gtk '%static-initfuncs%
			     (string->symbol init-func)))
	      (modinfo (or-map (lambda (modinfo)
				 (if (equal? (car modinfo) modname)
				     modinfo
				     #f))
			       registered-modules))
	      (init-func (if modinfo (cadr modinfo) init-func))

	      (sharlib-full (try-using-libtool-name 
			     "/usr/local/contrib/moderated/lib" libname))

;	      (lib       (if modinfo (caddr modinfo)
;			     (or (link-dynamic-module sharlib-full init-func)
;				 (error "can't open library" libname)))))

; link-dynamic-module never returns anything.
	      )
	 (display "sharlibfull is ") (display sharlib-full)(newline)
	 (link-dynamic-module sharlib-full init-func)

;	 (display "lib is ") (display lib)(newline)
	 (display "modinfo is ") (display modinfo)(newline)

)))))

(define default-module-prefix 
  (string->symbol (string-append "gtk-" gtkconf-version)))
(define module-prefix #f)

(define-public (gtk-version-set prefix)
  (if (and module-prefix (not (eq? prefix module-prefix)))
      (error "Can't mix" module-prefix 'and prefix)
      (set! module-prefix prefix)))

(define-public (gtk-version-alias suffix)
  (if (not module-prefix)
      (set! module-prefix default-module-prefix))
;  (display "module-prefix is ")(display module-prefix)(newline)
  (let* ((mod-name (list module-prefix suffix))
	 (mod-iface (resolve-interface mod-name)))
    (or mod-iface
	(error "no such module" mod-name))
    (set-module-public-interface! (current-module) mod-iface)))

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: guile-gtk without dlopen (HP-UX) (fwd)
  1999-11-08 20:10 guile-gtk without dlopen (HP-UX) (fwd) Stephen Tell
@ 1999-11-09 11:21 ` Marius Vollmer
  1999-11-09 11:49   ` Stephen Tell
  0 siblings, 1 reply; 4+ messages in thread
From: Marius Vollmer @ 1999-11-09 11:21 UTC (permalink / raw)
  To: Stephen Tell; +Cc: Guile-Gtk List

Stephen Tell <tell@cs.unc.edu> writes:

> Looking in %load-path seems pretty bogus, because by default it seems to
> contain only directories under $PREFIX/share.

Yes, indeed.  It was a bad decision back then and I didn't expect it
to stick that long.  I'm now more in favor of amore explicit approach
to dynamic linking of C modules so that Guile does not need to do so
much guessing and consequently has fewer opportunities to guess wrong.

But, on the other hand, I'm pretty little motivated to do anything
about the current situation.  It seems to work in practice, to some
extent (i.e. there aren't too many complaints), and I like to wait for
the new module system.

If a package can't use Guile's built in mechanism, it can roll its
own, like guile-gtk does.

Now, guile-gtk needs to smarten up about other platforms besides
GNU/Linux.  It should do that by using Guile's dynamic-link function,
etc.

Anyway, that's the plan.

> I can get "guile-gtk -s hello-world.scm" to work with my hacked
> dynlink.scm, but not "guile -s"

Hmm, didn't "guile-gtk -s" work for you, aynway?  The executable
guile-gtk should not do any dynamic linking at all, because all
libraries are already there.

> $ guile -s ./hello-world.scm
> in sgt's hacked dynlink.scm
> module-prefix is gtk-1.2
> new merge-compiled-code guilegtk-1.2 sgtk_init_gtk_gtk_glue
> ERROR: In procedure dynamic-call in expression (dynamic-call initname dynobj):
> ERROR: undefined function

This error message comes from the HPUX implementation of
"dynamic-func".  It think it means that you loaded the library just
fine, but the init function couldn't be found.  You might want to
point GDB at "sysdep_dynl_func" and see why it's failing.

> Part of my difficulty modifying dynlink.scm is that I don't really
> understand what the rest of merge-compiled-code is trying to do -
> possibly fiddling with the module system to avoid loading anything
> twice?

The modinfo stuff?  Yes, that's supposed to deal with C modules that
have already been linked in, like with the guile-gtk executable.

> And while I'm getting tracebacks on errors within my program, I can't
> for the life of me get tracebacks from hello-world.scm, despite sprinkling
> around the usual incantation: 
> 	(debug-enable 'backtrace) (read-enable 'positions)

Yes, that's tricky sometimes.  Something needs to be done about error
reporting and debugging of Guile programs...

> But we might as well skip libguiledlopenhelper if HAVE_DLOPEN is false,
> since it isn't going to work anyway.

Yes.
 
> P.S.  The name of the environment variable containing the shared library
> path varies, by the way: "libtool --config | grep shlibpath_var" will
> yield LD_LIBRARY_PATH on linux and solaris, SHLIB_PATH on HP-UX.

Aha!  But I really expect to be using libltdl for all this platform
specific magic in the future.  I have a patch for it somewhere...

- Marius

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: guile-gtk without dlopen (HP-UX) (fwd)
  1999-11-09 11:21 ` Marius Vollmer
@ 1999-11-09 11:49   ` Stephen Tell
  1999-11-11 13:43     ` Marius Vollmer
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Tell @ 1999-11-09 11:49 UTC (permalink / raw)
  To: Marius Vollmer; +Cc: Guile-Gtk List

On 9 Nov 1999, Marius Vollmer wrote:

> Anyway, that's the plan.
> 
> > I can get "guile-gtk -s hello-world.scm" to work with my hacked
> > dynlink.scm, but not "guile -s"
> 
> Hmm, didn't "guile-gtk -s" work for you, aynway?  The executable
> guile-gtk should not do any dynamic linking at all, because all
> libraries are already there.

Yes, guile-gtk -s was fine for guile-only Gtk application, but for gwave,
my mixed guile/C app (that uses Gtk+ from both sides), only the hacked
dynlink.scm has worked so far - even though it too should have been fully
linked already.

I'll try debugging further, but it looks like what I might do is:

 - have gwave's configure/makefile install its own guile modules into
   $prefix/share/guile/app/gwave

 - Have gwave.c append $prefix/share/guile to %load-path if it isn't
   there already, after gh_enter and before it runs any guile code that
   can load modules.  This handles the case where guile and guile-gtk are
   distribution-provided in /usr, and my prefix is /usr/local.

 - On HP-UX only, install the hacked dynlink.scm down in
$prefix/share/guile/gwave/hpux-dynlink-hack/gtk/dynlink.scm, and add
that directory early in %load-path so the patched dynlink.scm gets used
only for gwave.


> Aha!  But I really expect to be using libltdl for all this platform
> specific magic in the future.  I have a patch for it somewhere...

So far as I know, libldtl works on HP-UX, so this will be great.  For
obvious reasons, I'd rather work on libldtl if necessary on oddball
platforms.

Thanks for your help.
Steve

-- 
Steve Tell | tell@cs.unc.edu | http://www.cs.unc.edu/~tell | KF4ZPF
Research Associate, Microelectronic Systems Laboratory
Computer Science Department, UNC@Chapel Hill.   W:919-962-1845


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: guile-gtk without dlopen (HP-UX) (fwd)
  1999-11-09 11:49   ` Stephen Tell
@ 1999-11-11 13:43     ` Marius Vollmer
  0 siblings, 0 replies; 4+ messages in thread
From: Marius Vollmer @ 1999-11-11 13:43 UTC (permalink / raw)
  To: Stephen Tell; +Cc: Guile-Gtk List

Stephen Tell <tell@cs.unc.edu> writes:

> So far as I know, libldtl works on HP-UX, so this will be great.  For
> obvious reasons, I'd rather work on libldtl if necessary on oddball
> platforms.

OK, I have scheduled the libltdl integration for this weekend.  Let's
see how it goes.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1999-11-11 13:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-08 20:10 guile-gtk without dlopen (HP-UX) (fwd) Stephen Tell
1999-11-09 11:21 ` Marius Vollmer
1999-11-09 11:49   ` Stephen Tell
1999-11-11 13:43     ` Marius Vollmer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).