Re: [racket-dev] Strange error with gui and ffi

2012-01-20 Thread Matthew Flatt
At Thu, 19 Jan 2012 15:40:07 +0100, Tobias Hammer wrote:
   Even if libVLCore is statically linked to a libjpeg, I think it could
   interact with dynamic loading of another libjpeg, depending on the
   platform and linking options.
 
 I digged a bit more and found the following line the rackets libffi:
 handle = dlopen(name, RTLD_NOW | RTLD_GLOBAL);
 If i interpret the manpages correct that means that all symbols from the 
 lib are loaded and used to resolve references. That may be convenient 
 for the libraries that the racket core uses but may lead strange 
 behavior like the one i got whenever name clashes happen.
 
 Maybe it would be a good idea to make this import all behavior optional.

I agree that RTLD_GLOBAL should be removed by default,
but it should be made available as an option. Meanwhile, the details of
`(ffi-lib #f)' will have to change for backward compatibility.


As far as I can tell or remember, RTLD_GLOBAL is mostly there to make
`(ffi-lib #f)' work, where the handle produced by `(ffi-lib #f)' finds
an export in any previously loaded library.

Since Racket keeps a table of all loaded libraries, maybe the right
change is to implement `(ffi-lib #f)' by traversing the table in
addition to using a global lookup, which means that `(ffi-lib #f)' can
work without always loading libraries with RTLD_GLOBAL. Meanwhile,
RTLD_GLOBAL could be optional behavior, as you suggest.

_
  Racket Developers list:
  http://lists.racket-lang.org/dev


[racket-dev] Strange error with gui and ffi

2012-01-19 Thread Tobias Hammer

Hi,

i am getting a strange error message from racket if i use racket/gui in 
the main module and only racket in a required one. If i load another 
shared lib in the required module i get the following output:


jpeg: unsupported library version: unknown

 === context ===
racket-5.2.0.1/collects/racket/draw/unsafe/jpeg.rkt: [running body]
racket-5.2.0.1/collects/racket/draw/private/bitmap.rkt: [traversing imports]
racket-5.2.0.1/collects/racket/draw/private/dc.rkt: [traversing imports]
racket-5.2.0.1/collects/racket/draw/private/svg-dc.rkt: [traversing imports]
racket-5.2.0.1/collects/racket/draw.rkt: [traversing imports]
racket-5.2.0.1/collects/mred/private/kernel.rkt: [traversing imports]
racket-5.2.0.1/collects/mred/private/const.rkt: [traversing imports]
racket-5.2.0.1/collects/mred/private/check.rkt: [traversing imports]
racket-5.2.0.1/collects/mred/private/mred.rkt: [traversing imports]
racket-5.2.0.1/collects/mred/mred.rkt: [traversing imports]
racket-5.2.0.1/collects/mred/main.rkt: [traversing imports]
racket-5.2.0.1/collects/racket/gui/base.rkt: [traversing imports]
racket-5.2.0.1/collects/racket/gui.rkt: [traversing imports]
guibug.rkt: [traversing imports]

Same problem with last nightly. It seems like it is happening only if 
the shared lib is statically linked to another libjpeg but as far as i 
understand that should have no invfuence on anything. It's also not 
happening if i use racket/gui instead of only racket as lang in the 
required module.


I used the following code to produce the error.

guibug.rkt:
#lang racket/gui
(require guibug_req.rkt)

guibug_req.rkt
#lang racket
(require ffi/unsafe)
(require racket/runtime-path)

(define-runtime-path lib-path libVLCore)
(define lib-handle (ffi-lib lib-path))

Has anyone an idea what is happening there?

Tobias


_
 Racket Developers list:
 http://lists.racket-lang.org/dev


Re: [racket-dev] Strange error with gui and ffi

2012-01-19 Thread Matthew Flatt
At Thu, 19 Jan 2012 13:30:40 +0100, Tobias Hammer wrote:
 i am getting a strange error message from racket if i use racket/gui in 
 the main module and only racket in a required one. If i load another 
 shared lib in the required module i get the following output:
 
 jpeg: unsupported library version: unknown

It does seem that loading libVLCore interferes with the use of libjpeg;
if you use `racket/gui' in guibug_req.rkt, that would avoid the
problem by initializing the libjpeg use in `racket/draw' (via
`racket/gui') before libVLCore is loaded.

Even if libVLCore is statically linked to a libjpeg, I think it could
interact with dynamic loading of another libjpeg, depending on the
platform and linking options.

Can you say more about the platform, libVLCore's linking, and the
libjpeg that libVLCore uses?

_
  Racket Developers list:
  http://lists.racket-lang.org/dev


Re: [racket-dev] Strange error with gui and ffi

2012-01-19 Thread Tobias Hammer

Am 01/19/2012 02:02 PM, schrieb Matthew Flatt:

At Thu, 19 Jan 2012 13:30:40 +0100, Tobias Hammer wrote:

i am getting a strange error message from racket if i use racket/gui in
the main module and only racket in a required one. If i load another
shared lib in the required module i get the following output:

jpeg: unsupported library version: unknown


It does seem that loading libVLCore interferes with the use of libjpeg;
if you use `racket/gui' in guibug_req.rkt, that would avoid the
problem by initializing the libjpeg use in `racket/draw' (via
`racket/gui') before libVLCore is loaded.


Sure, that would be a possibility.



Can you say more about the platform, libVLCore's linking, and the
libjpeg that libVLCore uses?



Platform is Suse linux i386.
The jpeg lib is IJG (http://www.ijg.org) release 6b from 1998. So it's 
pretty old and may be incompatible to the current version. But i can't 
replace it because the readme says it may be modified.
The linking is this libjpeg as normal static lib (.a) and the libVLCore 
as regular shared lib that includes the static lib.



 Even if libVLCore is statically linked to a libjpeg, I think it could
 interact with dynamic loading of another libjpeg, depending on the
 platform and linking options.

I digged a bit more and found the following line the rackets libffi:
handle = dlopen(name, RTLD_NOW | RTLD_GLOBAL);
If i interpret the manpages correct that means that all symbols from the 
lib are loaded and used to resolve references. That may be convenient 
for the libraries that the racket core uses but may lead strange 
behavior like the one i got whenever name clashes happen.


Maybe it would be a good idea to make this import all behavior optional.

Tobias




_
 Racket Developers list:
 http://lists.racket-lang.org/dev