Thread and guile environment

2010-07-05 Thread rixed
Suppose I have a multithreaded C program. Isn't the guile environment supposed
to be shared amongst all threads ? That's what I understood from reading the
docs anyway.

Yet this simple exemple shows the opposite (see the 3 attached files).
So am I supposed to source my global scheme definitions in all threads ?


#include 
#include 
#include 

static void *load_file_with_guile(void *filename)
{
scm_c_primitive_load((char *)filename);
return NULL;
}

static void *hug_me(void *str)
{
scm_c_eval_string(str);
}

static void *thread_hugme(void *dummy)
{
//scm_with_guile(load_file_with_guile, "bug.scm");
scm_with_guile(hug_me, "(hug 2)");
return NULL;
}

int main(void) {
scm_with_guile(load_file_with_guile, "bug.scm");

scm_with_guile(hug_me, "(hug 1)");

pthread_t thread;
pthread_create(&thread, NULL, thread_hugme, NULL);

pthread_join(thread, NULL);

return 0;
}
(use-modules (ice-9 format))
(define (hug x) (format #t "HUG ~a !\n" x))
CFLAGS += $(shell guile-config compile)
LDLIBS += $(shell guile-config link) -lpthread

all: bug


Best way to call a user defined hook (written in guile) from C when the hook need plenty parameters

2010-07-05 Thread rixed
Hello !

Frequently, our C program computes a set of approximately 50 values that it 
wants
to make accessible for a user defined call back so that the user can choose to
print some of these values (if some condition is met for instance).

I first thought to make some C functions accessible that would return the
values (one C getter per value), and have the C scheme procedure call these
C functions for the values it's interested in. But the problem is that it's
a little verbose (both in C and in scheme due to the required parenthesis).

I then though of binding the values to global variables that the user callback
would use but ruled this out because I was afraid this solution would be slow.

Then I wanted to pass the values as regular parameters, but I don't want to 
impose
the user to define his function with 50 parameters.

So finally we came up with something like this :

The user enter merely a list of the values he wants (in a "configuration" file) 
:

(define user-fields `(foo bar (+ baz foo) (if (> foo bar) 1 2)))

And then in C we evaluate :

(define (hook-helper %s) (lambda () #\t))

where %s is the long list of parameters (foo bar baz...) that's inserted by the 
C program.
And :

(define (hook . args) (local-eval (cons print-user-fields user-fields) 
(procedure-environment (apply hook-helper args

So the user entry is minimal and we can, for each set of values, apply the hook
function to the values (which is I think one of the fastest way to make 
available some
a set of named values to scheme).

The downside is : the above scheme line looks like black magic.

Can anyone suggest a better way to do this ?





Re: Trying guile as an extention language for a 'real world' product

2010-07-05 Thread Thien-Thi Nguyen
() ri...@happyleptic.org
() Sat, 3 Jul 2010 07:36:51 +0200

   Are there any contraindication against using
   guile as an extention language for configuration ?

I don't think so.

Configuration is specialization, moved early.
Guile can handle that, as long as early is not too early.

thi



Re: Best way to call a user defined hook (written in guile) from C when the hook need plenty parameters

2010-07-05 Thread Thien-Thi Nguyen
() ri...@happyleptic.org
() Mon, 5 Jul 2010 10:56:36 +0200

   Can anyone suggest a better way to do this ?

For "a set of named values", you can use an association list.

If the paren verbosity is off-putting, a common way is to take/show
plists externally (minimal (one) set of parens).  So, user sees:

  (k1 v1 k2 v2 ...)

which is not so threatening, but you manipulate internally:
 
  ((k1 . v1)
   (k2 . v2)
   ...)

This requires a transform, but you do that anyway
(as part of validating the user input), right?

All this presumes that there is no need to specify all keys all the time.
(Re-reading your post, perhaps i am misunderstanding the problem question.)

If the problem really is: how to avoid unwieldy argument lists, the answer
is still "use an association list", but pass to the user a procedure that
encapsulates it.  For example:

(define (query-proc alist)
  "Encapsulate ALIST; return a procedure to query it."
  (lambda (key)
(assoc-ref alist key)))

(define ALIST '((k1 . v1) (k2 . v2)))
(define QUERY (query-proc ALIST))

;; On the user side:

(define (monitor query)
  (for-each (lambda (key)
  (simple-format #t "k: ~S~%v: ~S~%" key (query key)))
'(k1 k2)))

This example is read-only; if you want ‘monitor’ to be able to munge
you can change ‘query-proc’ to perhaps ‘query/munge-proc’:

(define (query/munge-proc alist)
  "Encapsulate ALIST; return a procedure query/munge it."
  (lambda (key . newval)
(if (null? newval)
(assoc-ref alist key)
(set! alist (assoc-set! alist key (car newval))

(It all depends on how much you trust the users.  ;-)

thi



guile-gnome - git clone + 3 debian patches - compilation error

2010-07-05 Thread David Pirotte
Hi Andy,

From a fresh git clone + the 3 debian patches, I get the following error 
[below].

[but yesterday i succeeded compiling the debian tree patched with your 
 suggested 2 revname ??]

Cheers,
David


;; --

the 3 debian patches @

http://patch-tracker.debian.org/package/guile-gnome-platform/2.16.1-4

;; --

few installed lib info:

ii  libgtk2.0-0 2.20.1-1  
ii  libglib2.0-02.24.1-1 
ii  libgnome2-0 2.30.0-1 
ii  libgnomeui-02.24.3-1


;; --

patching 'trace'

da...@rascar:/usr/local/src/guile-gnome 100 $ 
./patch-guile-gnome-git-with-debian-patches 
patching file glib/test-suite/Makefile.am
patching file gtk/gnome/gw/gtk-support.c
patching file gtk/gnome/gw/gtk-support.h
patching file gtk/gnome/overrides/gtk.defs
patching file gtk/gnome/gw/Makefile.am
da...@rascar:/usr/local/src/guile-gnome 101 $ 


;; --

error output

...
mv -f .deps/libgw_guile_gnome_gtk_la-gtk-support.Tpo 
.deps/libgw_guile_gnome_gtk_la-gtk-support.Plo
/bin/sh ../../../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. 
-I../../..-I../../../glib/gnome/gobject -I../../../glib/gnome/gobject -I. 
-I. -Wall -Werror -g -I/usr/include/guile-cairo -I/usr/include/cairo 
-I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12   
-pthread -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include 
-I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 
-I/usr/include/gio-unix-2.0/ -I/usr/include/pixman-1 -I/usr/include/freetype2 
-I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
-std=gnu99-g -O2 -MT libgw_guile_gnome_gtk_la-guile-gnome-gw-gtk.lo -MD -MP 
-MF .deps/libgw_guile_gnome_gtk_la-guile-gnome-gw-gtk.Tpo -c -o 
libgw_guile_gnome_gtk_la-guile-gnome-gw-gtk.lo `test -f 'guile-gnome-gw-gtk.c' 
|| echo './'`guile-gnome-gw-gtk.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../.. 
-I../../../glib/gnome/gobject -I../../../glib/gnome/gobject -I. -I. -Wall 
-Werror -g -I/usr/include/guile-cairo -I/usr/include/cairo 
-I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 
-pthread -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include 
-I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 
-I/usr/include/gio-unix-2.0/ -I/usr/include/pixman-1 -I/usr/include/freetype2 
-I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include 
-std=gnu99 -g -O2 -MT libgw_guile_gnome_gtk_la-guile-gnome-gw-gtk.lo -MD -MP 
-MF .deps/libgw_guile_gnome_gtk_la-guile-gnome-gw-gtk.Tpo -c 
guile-gnome-gw-gtk.c  -fPIC -DPIC -o 
.libs/libgw_guile_gnome_gtk_la-guile-gnome-gw-gtk.o
cc1: warnings being treated as errors
guile-gnome-gw-gtk.c: In function 
'gw__tmp6246_gtk_recent_info_get_application_info_wrapper':
guile-gnome-gw-gtk.c:27337: error: passing argument 3 of 
'gtk_recent_info_get_application_info' from incompatible pointer type
/usr/include/gtk-2.0/gtk/gtkrecentmanager.h:187: note: expected 'const gchar 
**' but argument is of type 'char **'
make[5]: *** [libgw_guile_gnome_gtk_la-guile-gnome-gw-gtk.lo] Error 1
make[5]: Leaving directory 
`/usr/local/src/guile-gnome/guile-gnome-platform/gtk/gnome/gw'
make[4]: *** [all] Error 2
make[4]: Leaving directory 
`/usr/local/src/guile-gnome/guile-gnome-platform/gtk/gnome/gw'
make[3]: *** [all-recursive] Error 1


config.log.gz
Description: GNU Zip compressed data


Re: Thread and guile environment

2010-07-05 Thread Neil Jerram
ri...@happyleptic.org writes:

> Suppose I have a multithreaded C program. Isn't the guile environment supposed
> to be shared amongst all threads ? That's what I understood from reading the
> docs anyway.
>
> Yet this simple exemple shows the opposite (see the 3 attached files).
> So am I supposed to source my global scheme definitions in all threads ?

Hm.  I think I recall a bug to do with different threads starting in
different modules.  Does it work if you add

(define-module (guile-user))

at the start of your bug.scm ?

 Neil



Re: Best way to call a user defined hook (written in guile) from C when the hook need plenty parameters

2010-07-05 Thread Neil Jerram
ri...@happyleptic.org writes:

> (define (hook-helper %s) (lambda () #\t))
>
> where %s is the long list of parameters (foo bar baz...) that's inserted by 
> the C program.
> And :
>
> (define (hook . args) (local-eval (cons print-user-fields user-fields) 
> (procedure-environment (apply hook-helper args

Using local-eval and procedure-environment like this won't work in Guile
1.9/2.0, I believe.

But you could get a similar effect - which I think will still work in
1.9/2.0 - by creating a module, defining values in it, and then
evaluating in that module.  (In Guile, module == top level environment.)

(Note that the bindings in a module are conceptually similar to an alist,
so this is actually not so different from what Thien-Thi suggested.)

To create a module, in Scheme:

(define-module (xxx))

Then your C code would access that using

SCM module = scm_c_resolve_module ("xxx");

and define each value in it using

scm_c_module_define (module, name, value);

and finally evaluate in that module using

scm_c_eval_string_in_module (expression, module);

It would also seem (at least to me) a bit less magical to define the
user-fields as a procedure, e.g.:

(define (calc-user-fields)
  (list foo
bar
(+ baz foo)
(if (> foo bar) 1 2)))

and then the "expression" above would be "(calc-user-fields)".

All completely untested, of course! :-)

Regards,
 Neil



Re: guile-gnome2 - Segmentation fault

2010-07-05 Thread David Pirotte
Hi Andy,
guile-gnome users,

Launching the following little application example and clicking the 'Start' 
button
systematically provoke a segmentation fault on guile-gnome-2 [and guile-gnome-0]

Does it crashes for you [any guile-gnome user willing to try?] too?

Thanks,
David

ps: while building this small example, I thought it was due to the calls

...
(gtku/status-pop statusbar "")
(gtku/status-push statusbar (get-value model iter 0) "")
...

in my (connect selection 'changed ...) code, but then I commented and it
still crashed.

;; --

Le Thu, 01 Jul 2010 11:58:04 +0100,
Andy Wingo  a écrit :

> On Tue 29 Jun 2010 22:33, David Pirotte  writes:
> 
> > I'll try to produce a better backtrace [some .deb package have no -dbg
> > corresponding package and the -dev do not always include debugging symbols]
> >
> > But in order to help me helping developpers to get rid og this bug [which 
> > did
> > not desappear with the guile-gnome0 -> guile-gnome2 'porting' [in progress 
> > but
> > some bits working already], I am sending what i could come up with so far.
> 
> Thanks for the report. Unfortunately the backtrace is not
> sufficient. Something is being freed with g_free which should be freed
> via a specific deallocator. Can you check to see that the following
> patches are applied to the debian package:
> 
>   0ca1de9d89ed7b2899e49f273f27f810540a6508
>   3d11c93b290992b2c4d9eeef57c2a7a54f808783
> 
> Thanks,
> Andy
#! /bin/sh
# -*- scheme -*-
hn=`hostname`
if [[ "$hn" == "tabu" ]]
then exec guile-gnome-0 -s $0 "$@"
else exec guile-gnome-2 -s $0 "$@"
fi
!#

;; guile-gnome
;; Copyright (C) 2003,2004 Free Software Foundation, Inc.

;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as   
;; published by the Free Software Foundation; either version 2 of   
;; the License, or (at your option) any later version.  
;;  
;; This program is distributed in the hope that it will be useful,  
;; but WITHOUT ANY WARRANTY; without even the implied warranty of   
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details. 
;;  
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, contact:
;;
;; Free Software Foundation   Voice:  +1-617-542-5942
;; 59 Temple Place - Suite 330Fax:+1-617-542-2652
;; Boston, MA  02111-1307,  USA   g...@gnu.org

(read-set! keywords 'prefix)

(use-modules (ice-9 receive)
	 (oop goops) 
	 (gnome gobject)
	 (gnome gtk)
	 (gnome gtk gdk-event))


(define *model* #f)
(define *selection* #f)

(define (pack-tv-column tv column renderer pos)
  (pack-start column renderer #t)
  (add-attribute column renderer "text" pos)
  (append-column tv column))

(define (add-columns treeview)
  (let* ((renderer1 (make ))
	 (column1   (make 
		  :title   "Column 1"
		  :sizing  'fixed
		  :fixed-width 65
	;:clickable   #f
	;:resizable   #f
	;:reorderable #f
		  :alignment   .5
		  ))
	 (renderer2 (make ))
	 (column2   (make 
		  :title   "Column 2"
		  :sizing  'fixed
		  :fixed-width 65
	;:clickable   #f
	;:resizable   #f
	;:reorderable #f
		  :alignment   .5
		  ))
	 (renderer3 (make ))
	 (column3   (make 
		  :title   "Column 3"
		  :expand  #t
		  :alignment   .5
		  ))
	 ;; ROW BACKGROUND COLOUR
	 (renderer4 (make 
		  :xalign  1))
	 (column4   (make 
		  :visible #f
		  ))
	 ;; ROW FOREGROUND COLOUR
	 (renderer5 (make 
		  :xalign  1))
	 (column5   (make 
		  :visible #f
		  )))


(pack-tv-column treeview column1 renderer1 0)
(pack-tv-column treeview column2 renderer2 1)
(pack-tv-column treeview column3 renderer3 2)
(pack-tv-column treeview column4 renderer4 3)
(pack-tv-column treeview column5 renderer5 4)

;; background colour
(add-attribute column1 renderer1 "cell-background" 3)
(add-attribute column2 renderer2 "cell-background" 3)
(add-attribute column3 renderer3 "cell-background" 3)

;; foreground colour
(add-attribute column1 renderer1 "foreground" 4)
(add-attribute column2 renderer2 "foreground" 4)
(add-attribute column3 renderer3 "foreground" 4)

(set-search-column treeview 2)

))

(define (ocs/add-model treeview)
  (let* ((column-types (list 
			 
			 
			 
			 ))
	 (model (gtk-list-store-new column-types)))
(set-model treeview model)
(values model
	(get-selection treeview))
))

(define (setup-treeview treeview)
  (add-columns treeview)
  (receive (model selection)
  (ocs/add-model treeview)
(set-mod