unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* [guile/scwm] SCM_HOOKP changed?
@ 2002-09-15 13:01 P Pareit
  2002-09-15 20:56 ` Thien-Thi Nguyen
  2002-09-15 23:59 ` Marius Vollmer
  0 siblings, 2 replies; 8+ messages in thread
From: P Pareit @ 2002-09-15 13:01 UTC (permalink / raw)


Hey,

I have a lot of code depending on SCM_HOOKP, has SCM_HOOKP changed in any way?
I also seen it is not documented, so I guess it should not be used, is 
scm_hook_p the right alternative?

The following program should show my problem:

// make-hook test program
//

#include <stdio.h>
#include <libguile.h>

#ifndef SCM_MAGIC_SNARFER
#define SCWM_GLOBAL_HOOK(var, name, args, docstring) \
SCM var
#else
#define SCWM_GLOBAL_HOOK(var, name, args, docstring) \
SCM_VARIABLE_INIT(var, name, scm_make_hook(SCM_MAKINUM(args)))
#endif

SCWM_GLOBAL_HOOK(error_hook, "error-hook", 1, "...");

void inner_main(void* closure, int argc, char** argv)
{
#ifndef SCM_MAGIC_SNARFER
#include "main.x"
#endif
  if (!SCM_HOOKP(error_hook)) {
    fprintf(stderr, "SCM_HOOKP(error_hook) returns false!\n");
  }
  if (!scm_hook_p(error_hook)) {
    fprintf(stderr, "scm_hook_p(error_hook) returns false!\n");
  }
}

int main(int argc, char* argv[])
{
  scm_boot_guile(argc, argv, inner_main, NULL);
}

and can be compiled with the following Makefile:


test: main.o
	gcc -g -o test main.c `guile-config link`

main.o: main.c main.x
	gcc -g -c main.c `guile-config compile`

main.x: main.c
	guile-snarf -o main.x main.c

clean:
	rm -f *.o
	rm -f *.x

pieter;


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


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

* Re: [guile/scwm] SCM_HOOKP changed?
  2002-09-15 13:01 [guile/scwm] SCM_HOOKP changed? P Pareit
@ 2002-09-15 20:56 ` Thien-Thi Nguyen
  2002-09-15 21:28   ` Thien-Thi Nguyen
  2002-09-15 23:59 ` Marius Vollmer
  1 sibling, 1 reply; 8+ messages in thread
From: Thien-Thi Nguyen @ 2002-09-15 20:56 UTC (permalink / raw)
  Cc: guile-user

   From: P Pareit <pieter.pareit@planetinternet.be>
   Date: Sun, 15 Sep 2002 15:01:24 +0200

   I also seen it is not documented

lack of documentation for installed headers is a bug.

in this case, check out the "C Hooks" node, which explains how to manage
hooks from C.  probably it is confusing to include references to C func
`scm_make_hook' and the like in "Hook Reference"; they should be removed
to emphasize the two different systems.

thi


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


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

* Re: [guile/scwm] SCM_HOOKP changed?
  2002-09-15 20:56 ` Thien-Thi Nguyen
@ 2002-09-15 21:28   ` Thien-Thi Nguyen
  2002-09-16  4:39     ` Thien-Thi Nguyen
  2002-09-16  9:50     ` Marius Vollmer
  0 siblings, 2 replies; 8+ messages in thread
From: Thien-Thi Nguyen @ 2002-09-15 21:28 UTC (permalink / raw)
  Cc: guile-user

   From: Thien-Thi Nguyen <ttn@giblet.glug.org>
   Date: Sun, 15 Sep 2002 13:56:54 -0700

   they should be removed
   to emphasize the two different systems.

actually removal just obfuscates.  this is better:

   2002-09-15  Thien-Thi Nguyen  <ttn@dream.glug.org>

	* scheme-utility.twerp (Hook Reference): Mention and pxref C-level hooks.
	(C Hooks): Add subsection "Handling Scheme-level hooks from C code".

see below for diff.

thi


______________________________________________
Index: scheme-utility.twerp
===================================================================
RCS file: /home/ttn/cvs/guile-core/doc/ref/scheme-utility.twerp,v
retrieving revision 1.4
diff -w -c -b -c -p -r1.4 scheme-utility.twerp
*** scheme-utility.twerp	29 Aug 2002 05:34:05 -0000	1.4
--- scheme-utility.twerp	15 Sep 2002 21:21:56 -0000
*************** The ordering of the list of procedures r
*** 402,407 ****
--- 402,411 ----
  matches the order in which those procedures would be called if the hook
  was run using @code{run-hook}.
  
+ Note that the following C functions are for handling
+ @dfn{Scheme-level} hooks in C; there are also @dfn{C-level} hooks
+ which have their own interface (@pxref{C Hooks}).
+ 
  @twerpdoc (make-hook (C scm_make_hook))
  
  @twerpdoc (hook? (C scm_hook_p))
*************** function's closure data, and the call cl
*** 529,534 ****
--- 533,556 ----
  
  @code{scm_c_hook_run}'s return value is the return value of the last
  function to be called.
+ @end deftypefn
+ 
+ @subsection Handling Scheme-level hooks from C code
+ 
+ To handle Scheme-level hooks from C code you must use the appropriate
+ C functions (@pxref{Hook Reference}).  For example:
+ 
+ @example
+ if (SCM_HOOKP (obj))
+   /* handle C-level hook */
+ else if (scm_hook_p (obj))
+   /* handle Scheme-level hook using C functions */
+ else
+   /* do something else (obj is not a hook) */
+ @end example
+ 
+ @deftypefn {C Macro} int SCM_HOOKP (x)
+ Return 1 if @var{x} is a C-level hook and 0 otherwise.
  @end deftypefn
  
  


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


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

* Re: [guile/scwm] SCM_HOOKP changed?
  2002-09-15 13:01 [guile/scwm] SCM_HOOKP changed? P Pareit
  2002-09-15 20:56 ` Thien-Thi Nguyen
@ 2002-09-15 23:59 ` Marius Vollmer
  1 sibling, 0 replies; 8+ messages in thread
From: Marius Vollmer @ 2002-09-15 23:59 UTC (permalink / raw)
  Cc: guile-user

P Pareit <pieter.pareit@planetinternet.be> writes:

> Hey,
> 
> I have a lot of code depending on SCM_HOOKP, has SCM_HOOKP changed
> in any way?  I also seen it is not documented, so I guess it should
> not be used, is scm_hook_p the right alternative?

No, the problem is something else.

SCM_HOOKP returns a C boolean, that is, either 0 or 1.  scm_hook_p
returns a Scheme boolean, either SCM_BOOL_F or SCM_BOOL_T (which are
both true in the C sense).

In your program belowe, error_hook is a variable, not a hook.  Both
SCM_HOOKP and scm_hook_p returne their variant of false, but you test
the return value of scm_hook_p in the wrong way.  You would have to
write

  if (SCM_FALSEP (scm_hook_p (error_hook)))
    ...

(Do not compare directly with SCM_BOOL_F since there might be other
false values, like scm_lisp_nil.)

The reason why error_hook is a variable is because scm_c_define
returns the variable that it has created or reused, not the value that
the variable is initialized with.

The best think to do is probably to use SCM_SNARF_HERE and
SCM_SNARF_INIT, like so:

  #define SCWM_GLOBAL_HOOK(var, name, args, docstring) \
   SCM_SNARF_HERE (SCM var) \
   SCM_SNARF_INIT ( \
     var = scm_permanent_object (scm_make_hook(SCM_MAKINUM(args))); \
     scm_c_define (name, var);)

Guile will support SCM_SNARF_HERE and SCM_SNARF_INIT, I think there is
no way around that.  When possibly, I'll also add
backwards-compatability for SCM__I, etc.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


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

* Re: [guile/scwm] SCM_HOOKP changed?
  2002-09-15 21:28   ` Thien-Thi Nguyen
@ 2002-09-16  4:39     ` Thien-Thi Nguyen
  2002-09-16  9:50     ` Marius Vollmer
  1 sibling, 0 replies; 8+ messages in thread
From: Thien-Thi Nguyen @ 2002-09-16  4:39 UTC (permalink / raw)
  Cc: guile-user

   From: Thien-Thi Nguyen <ttn@giblet.glug.org>
   Date: Sun, 15 Sep 2002 14:28:16 -0700

   + else if (scm_hook_p (obj))

this needs to be

     SCM_NFALSEP (scm_hook_p (obj))

thi


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


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

* Re: [guile/scwm] SCM_HOOKP changed?
  2002-09-15 21:28   ` Thien-Thi Nguyen
  2002-09-16  4:39     ` Thien-Thi Nguyen
@ 2002-09-16  9:50     ` Marius Vollmer
  2002-09-16 11:35       ` Thien-Thi Nguyen
  1 sibling, 1 reply; 8+ messages in thread
From: Marius Vollmer @ 2002-09-16  9:50 UTC (permalink / raw)
  Cc: guile-user

Thien-Thi Nguyen <ttn@giblet.glug.org> writes:

> @deftypefn {C Macro} int SCM_HOOKP (x)
> Return 1 if @var{x} is a C-level hook and 0 otherwise.
> @end deftypefn

This is wrong.  SCM_HOOKP is for Scheme-level hooks.  It is a variant
of scm_hook_p, like SCM_VECTORP is a variant of scm_vector_p.

There is no type predicate for C-level hooks (like there is no type
predicate for ints).

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


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

* Re: [guile/scwm] SCM_HOOKP changed?
  2002-09-16  9:50     ` Marius Vollmer
@ 2002-09-16 11:35       ` Thien-Thi Nguyen
  2002-09-19 20:20         ` Neil Jerram
  0 siblings, 1 reply; 8+ messages in thread
From: Thien-Thi Nguyen @ 2002-09-16 11:35 UTC (permalink / raw)
  Cc: guile-user

   From: Marius Vollmer <mvo@zagadka.ping.de>
   Date: 16 Sep 2002 11:50:33 +0200

   This is wrong.  SCM_HOOKP is for Scheme-level hooks.  It is a variant
   of scm_hook_p, like SCM_VECTORP is a variant of scm_vector_p.

   There is no type predicate for C-level hooks (like there is no type
   predicate for ints).

thanks for pointing this out.  i've changed the docs to:

  @example
  if (SCM_NFALSEP (scm_hook_p (obj)))
    scm_reset_hook_x (obj);
  else
    /* do something else (obj is not a hook) */
  @end example
  
  In addition to @code{scm_hook_p} there is a slightly faster variant:
  
  @deftypefn {C Macro} int SCM_HOOKP (x)
  Return 1 if @var{x} is a Scheme-level hook and 0 otherwise.
  @end deftypefn

(will show up in 1.4.1.88 or so.)

thi


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


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

* Re: [guile/scwm] SCM_HOOKP changed?
  2002-09-16 11:35       ` Thien-Thi Nguyen
@ 2002-09-19 20:20         ` Neil Jerram
  0 siblings, 0 replies; 8+ messages in thread
From: Neil Jerram @ 2002-09-19 20:20 UTC (permalink / raw)
  Cc: mvo, guile-user

>>>>> "Thien-Thi" == Thien-Thi Nguyen <ttn@giblet.glug.org> writes:

    Thien-Thi> thanks for pointing this out.  i've changed the docs to: [...]

Thanks for the patches; I've applied all these changes to Guile CVS.

        Neil



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


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

end of thread, other threads:[~2002-09-19 20:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-15 13:01 [guile/scwm] SCM_HOOKP changed? P Pareit
2002-09-15 20:56 ` Thien-Thi Nguyen
2002-09-15 21:28   ` Thien-Thi Nguyen
2002-09-16  4:39     ` Thien-Thi Nguyen
2002-09-16  9:50     ` Marius Vollmer
2002-09-16 11:35       ` Thien-Thi Nguyen
2002-09-19 20:20         ` Neil Jerram
2002-09-15 23:59 ` 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).