unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* loading a module
@ 2010-02-17 18:26 Tomas By
  2010-02-17 20:12 ` Andy Wingo
  2010-02-28 22:59 ` Neil Jerram
  0 siblings, 2 replies; 7+ messages in thread
From: Tomas By @ 2010-02-17 18:26 UTC (permalink / raw)
  To: guile-user

Hello one more time,

There was a little problem in mytest.c, where I had declared a pointer
only and no address location. This was the cause of the segmentation
fault.

With the following source files, the code Linas posted, after some
modifications, is compiled to a binary `vepstas' which runs fine with
no errors:

  $ ./vepstas
  #<mytype b7736510>
  $

Trying to load the Guile module, however, still fails.

I think the "file not found" message is just the general dynamic-link-
anything error.

Any help much appreciated...

(Guile 1.8.7)

/Tomas

---------- mytest.scm ------------------------------------------------

(define-module (mytest))
(export mytest)
(load-extension "libguile-mytest" "init_mytest")

---------- mylib.m (Mercury) -----------------------------------------

:- module mylib.

:- interface.
:- use_module io.
:- import_module list,bool.

:- type mytype ---> stuff(int,float,bool).

:- pred testproc(list(string),mytype,io.state,io.state).
:- mode testproc(in,out,di,uo) is det.

:- implementation.

:- pragma foreign_export("C",testproc(in,out,di,uo),"testproc_c").

testproc(_,X,!IO) :- X = stuff(0,0.0,no).

:- end_module mylib.

---------- mytest.h --------------------------------------------------

#ifndef MYDEF_H
#define MYDEF_H
#include <libguile.h>
SCM testproc_wrapper(SCM,SCM);
void init_mytest(void);
#endif /* MYDEF_H */

---------- mytest.c --------------------------------------------------

#include <libguile.h>
#include <mercury.h>
#include "mylibrary.h"
#include "mylib.mh"
#include "mytest.h"
#include <stdio.h>

void init_mytest()
{
  void *dummy;
  char* args[1] = {(char*)""};

  mercury_init(1,args,&dummy);

  (void)scm_make_smob_type("mytype",0);

  scm_c_define_gsubr("mytest",2,0,0,testproc_wrapper);
}

SCM testproc_wrapper(SCM s,SCM x)
{
  MR_Word temp = MR_list_empty();
  MR_Word p = NULL;

  testproc_c(temp,&p);

  SCM_SET_SMOB_DATA(x,(scm_t_bits)p);

  return SCM_BOOL_T;
}

---------- mylib.mh --------------------------------------------------

/*
** Automatically generated from `mylib.m'
** by the Mercury compiler,
** version rotd-2009-12-28, configured for i686-pc-linux-gnu.
** Do not edit.
*/
#ifndef MYLIB_MH
#define MYLIB_MH

#ifdef __cplusplus
extern "C" {
#endif

#ifdef MR_HIGHLEVEL_CODE
#include "mercury.h"
#else
  #ifndef MERCURY_HDR_EXCLUDE_IMP_H
  #include "mercury_imp.h"
  #endif
#endif
#ifdef MR_DEEP_PROFILING
#include "mercury_deep_profiling.h"
#endif

#ifndef MYLIB_DECL_GUARD
#define MYLIB_DECL_GUARD

#endif
void testproc_c(MR_Word, MR_Word *);

#ifdef __cplusplus
}
#endif

#endif /* MYLIB_MH */

---------- vepstas.c -------------------------------------------------

#include <libguile.h>
#include <mercury.h>
#include "mylibrary.h"

SCM testproc_wrapper(SCM,SCM);

int main(void)
{
  char* args[1] = {(char*)""};
  void *dummy;

  SCM x;
  scm_t_bits tag;

  mercury_init(1,args,&dummy);
  scm_init_guile();

  tag = scm_make_smob_type("mytype",0);
  SCM_NEWSMOB(x,tag,NULL);

  (void)testproc_wrapper(scm_from_locale_string(""),x);

  scm_display(x,scm_current_output_port());
  scm_newline(scm_current_output_port());

  return 0;
}

---------- Makefile --------------------------------------------------

nothing: lib

CC = gcc
LD = gcc
MMC = mmc
MMAKE = mmake

GUILE_CFLAGS=$(shell guile-config compile)
GUILE_LIBS=$(shell guile-config link)

MERCURY_CFLAGS=$(shell $(MMC) --output-cflags)
MERCURY_LIBS=$(shell $(MMC) --output-library-link-flags --mercury-linkage
shared)

CFLAGS = $(MERCURY_CFLAGS) $(GUILE_CFLAGS)
LIBS = $(MERCURY_LIBS) $(GUILE_LIBS)

LDFLAGS = -L. -Wl,-rpath . -lmylib

mylib.mh : mylib.m
	$(MMC) --make mylib.mh

mylibrary.h mylibrary.o : mylib.m
	$(MMC) --generate-standalone-interface mylibrary mylib.m

libmylib.so : mylib.m
	$(MMC) --make libmylib

mytest.o : mytest.h mytest.c mylibrary.h mylib.mh
	$(CC) -c mytest.c $(CFLAGS)

lib : mytest.o libmylib.so
	$(LD) -shared -fPIC -o libguile-mytest.so mytest.o $(LDFLAGS) $(LIBS)

install : mytest.scm lib
	sudo cp mytest.scm /usr/share/guile/1.8/
	sudo cp libguile-mytest.so /usr/lib/

vepstas : vepstas.c lib mylibrary.o
	$(CC) vepstas.c -o vepstas $(CFLAGS) mylibrary.o -lguile-mytest -L.
$(LDFLAGS) $(LIBS)

----------------------------------------------------------------------

guile> (use-modules (mytest))

Backtrace:
In unknown file:
    ...
   ?: 13  (begin (if # #) (make-modules-in # full-name))
   ?: 14* (if (or # #) (try-load-module name))
   ?: 15  [try-load-module (mytest)]
   ?: 16  (or (begin (try-module-linked name)) (try-module-autoload name)
...)
   ?: 17* [try-module-autoload (mytest)]
   ?: 18  (let* (# # # #) (resolve-module dir-hint-module-name #f) (and # #))
    ...
   ?: 19  (letrec ((load-file #)) (dynamic-wind (lambda () #) (lambda ()
#) ...) ...)
   ?: 20* [dynamic-wind #<procedure #f ()> #<procedure #f ()> #<procedure
#f ()>]
   ?: 21* [#<procedure #f ()>]
   ?: 22* (let* ((file #)) (cond (# => #) (# => #)))
   ?: 23  [#<procedure #f (full)> "/usr/share/guile/1.8/mytest.scm"]
   ?: 24  [with-fluid* #<fluid 7> #f #<procedure #f ()>]
   ?: 25* [#<procedure #f ()>]
   ?: 26* [load-file #<primitive-procedure primitive-load> ...]
   ?: 27* [save-module-excursion #<procedure #f ()>]
   ?: 28  (let (# #) (dynamic-wind # thunk #))
   ?: 29  [dynamic-wind #<procedure #f ()> #<procedure #f ()> #<procedure
#f ()>]
   ?: 30* [#<procedure #f ()>]
   ?: 31* [primitive-load "/usr/share/guile/1.8/mytest.scm"]
In /usr/share/guile/1.8/mytest.scm:
   3: 32* [load-extension "libguile-mytest" "init_mytest"]

/usr/share/guile/1.8/mytest.scm:3:1: In procedure dynamic-link in
expression (load-extension "libguile-mytest" "init_mytest"):
/usr/share/guile/1.8/mytest.scm:3:1: file: "libguile-mytest", message:
"file not found"
ABORT: (misc-error)
guile>

----------------------------------------------------------------------






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

* Re: loading a module
  2010-02-17 18:26 loading a module Tomas By
@ 2010-02-17 20:12 ` Andy Wingo
  2010-02-28 22:59 ` Neil Jerram
  1 sibling, 0 replies; 7+ messages in thread
From: Andy Wingo @ 2010-02-17 20:12 UTC (permalink / raw)
  To: Tomas By; +Cc: guile-user

On Wed 17 Feb 2010 19:26, "Tomas By" <tomas@basun.net> writes:

> I think the "file not found" message is just the general dynamic-link-
> anything error.

Yes, it is a libltdl bug. See
http://lists.gnu.org/archive/html/libtool/2009-12/msg00057.html

More than that, it's tough to say; I'm mercury-ignorant.

A
-- 
http://wingolog.org/




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

* Re: loading a module
@ 2010-02-17 20:21 Tomas By
  2010-02-18  6:07 ` Thien-Thi Nguyen
  0 siblings, 1 reply; 7+ messages in thread
From: Tomas By @ 2010-02-17 20:21 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guile-user

On Wed, February 17, 2010 21:12, Andy Wingo wrote:
> On Wed 17 Feb 2010 19:26, "Tomas By" <tomas@basun.net> writes:
> More than that, it's tough to say; I'm mercury-ignorant.

Well, since the `vepstas' binary works, the Mercury bit seems ok.

Do you have any suggestions for how to debug it?

Is there anything I can do to check the libguile-mytest.so file?

ldd doesn't seem to report anything wrong, but is there any
other test available from the shell?

/Tomas






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

* Re: loading a module
  2010-02-17 20:21 Tomas By
@ 2010-02-18  6:07 ` Thien-Thi Nguyen
  0 siblings, 0 replies; 7+ messages in thread
From: Thien-Thi Nguyen @ 2010-02-18  6:07 UTC (permalink / raw)
  To: guile-user

() "Tomas By" <tomas@basun.net>
() Wed, 17 Feb 2010 21:21:43 +0100

   ldd doesn't seem to report anything wrong, but is there any
   other test available from the shell?

If you have strace(1), you can use the script (i call it ~/bin/st):

 #!/bin/sh
 exec strace -f -e open "$@" 2>&1 | grep -v o.such.file

to find out what files are being opened succesfully.  Example usage:

|$ st guile -c '(quit)'
|open("/home/ttn/local/lib/libguile.so.9", O_RDONLY) = 3
|open("/home/ttn/local/lib/libltdl.so.7", O_RDONLY) = 3
|open("/etc/ld.so.cache", O_RDONLY)      = 3
|open("/lib/tls/i686/cmov/libm.so.6", O_RDONLY) = 3
|open("/lib/tls/i686/cmov/libdl.so.2", O_RDONLY) = 3
|open("/lib/tls/i686/cmov/libc.so.6", O_RDONLY) = 3
|open("/home/ttn/local/lib/guile/1.4.1.118/ice-9/boot-9.scm", O_RDONLY) = 3
|open("/home/ttn/local/lib/guile/site/.module-catalog", O_RDONLY) = 4
|open("/home/ttn/local/share/guile/site/.module-catalog", O_RDONLY) = 4
|open("/home/ttn/local/lib/guile/1.4.1.118/.module-catalog", O_RDONLY) = 4
|open("/home/ttn/local/lib/guile/site/init.scm", O_RDONLY) = 3
|Process 6112 detached

If you remove the "| grep -v o.such.file" portion, the output will include
all open(2) calls, including the ones that fail.

thi




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

* Re: loading a module
  2010-02-17 18:26 loading a module Tomas By
  2010-02-17 20:12 ` Andy Wingo
@ 2010-02-28 22:59 ` Neil Jerram
  1 sibling, 0 replies; 7+ messages in thread
From: Neil Jerram @ 2010-02-28 22:59 UTC (permalink / raw)
  To: Tomas By; +Cc: guile-user

"Tomas By" <tomas@basun.net> writes:

> Trying to load the Guile module, however, still fails.

This is really a stab in the dark - but could you try using a name for
the Scheme-level procedure that is different from the module name?
Currently they are both "mytest".

I think there could be some residual nonsense meaning for a binding that
has the same name as the module...

     Neil




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

* Re: loading a module
@ 2010-03-01 18:58 Tomas By
  2010-03-01 19:21 ` Neil Jerram
  0 siblings, 1 reply; 7+ messages in thread
From: Tomas By @ 2010-03-01 18:58 UTC (permalink / raw)
  To: Neil Jerram; +Cc: guile-user

On Sun, February 28, 2010 23:59, Neil Jerram wrote:
> This is really a stab in the dark - but could you try using a name for
> the Scheme-level procedure that is different from the module name?
> Currently they are both "mytest".
>
> I think there could be some residual nonsense meaning for a binding that
> has the same name as the module...

Thanks for the suggestion. I tried changing the name in the "define_gsubr"
and "export" statements and it made no difference.

But it's ok. Compiling my own binary is fine for what I am doing. I'm not
sure why I bother so much about this in the first place. Maybe I should
have my head looked at.

/Tomas






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

* Re: loading a module
  2010-03-01 18:58 Tomas By
@ 2010-03-01 19:21 ` Neil Jerram
  0 siblings, 0 replies; 7+ messages in thread
From: Neil Jerram @ 2010-03-01 19:21 UTC (permalink / raw)
  To: Tomas By; +Cc: guile-user

"Tomas By" <tomas@basun.net> writes:

> On Sun, February 28, 2010 23:59, Neil Jerram wrote:
>> This is really a stab in the dark - but could you try using a name for
>> the Scheme-level procedure that is different from the module name?
>> Currently they are both "mytest".
>>
>> I think there could be some residual nonsense meaning for a binding that
>> has the same name as the module...
>
> Thanks for the suggestion. I tried changing the name in the "define_gsubr"
> and "export" statements and it made no difference.
>
> But it's ok. Compiling my own binary is fine for what I am doing. I'm not
> sure why I bother so much about this in the first place. Maybe I should
> have my head looked at.

OK, fine.  But please do come and ask us again if you need to, and we'll
have another go.

     Neil






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

end of thread, other threads:[~2010-03-01 19:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-17 18:26 loading a module Tomas By
2010-02-17 20:12 ` Andy Wingo
2010-02-28 22:59 ` Neil Jerram
  -- strict thread matches above, loose matches on Subject: below --
2010-02-17 20:21 Tomas By
2010-02-18  6:07 ` Thien-Thi Nguyen
2010-03-01 18:58 Tomas By
2010-03-01 19:21 ` Neil Jerram

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).