diff options
-rw-r--r-- | doc/ChangeLog | 6 | ||||
-rw-r--r-- | doc/data-rep.texi | 47 | ||||
-rw-r--r-- | doc/example-smob/ChangeLog | 8 | ||||
-rw-r--r-- | doc/example-smob/image-type.c | 17 |
4 files changed, 45 insertions, 33 deletions
diff --git a/doc/ChangeLog b/doc/ChangeLog index c38fac844..f465bde3f 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,9 @@ +2001-04-26 Neil Jerram <neil@ossau.uklinux.net> + + * data-rep.texi (Defining New Types (Smobs)): Use non-deprecated + smob interface. Thanks to Masao Uebayashi for the patch! + (Creating Instances): Don't need SCM_NIMP anymore. + 2001-04-25 Marius Vollmer <mvo@zagadka.ping.de> * guile.1: New file, from Robert Merkel and Rob Browning. diff --git a/doc/data-rep.texi b/doc/data-rep.texi index 83edcb87c..a563a7154 100644 --- a/doc/data-rep.texi +++ b/doc/data-rep.texi @@ -46,7 +46,7 @@ @c essay @sp 10 @c essay @comment The title is printed in a large font. @c essay @title Data Representation in Guile -@c essay @subtitle $Id: data-rep.texi,v 1.22 2001-04-20 13:26:55 ossau Exp $ +@c essay @subtitle $Id: data-rep.texi,v 1.23 2001-04-26 18:26:28 ossau Exp $ @c essay @subtitle For use with Guile @value{VERSION} @c essay @author Jim Blandy @c essay @author Free Software Foundation @@ -1493,13 +1493,15 @@ representing eight-bit grayscale images: @example #include <libguile.h> -long image_tag; +static long image_tag; void init_image_type () @{ - image_tag = scm_make_smob_type_mfpe ("image",sizeof(struct image), - mark_image, free_image, print_image, NULL); + image_tag = scm_make_smob_type ("image", sizeof (struct image)); + scm_set_smob_mark (image_tag, mark_image); + scm_set_smob_free (image_tag, free_image); + scm_set_smob_print (image_tag, print_image); @} @end example @@ -1573,8 +1575,8 @@ This function isn't usually sufficiently different from the usual Continuing the above example, if the global variable @code{image_tag} -contains a tag returned by @code{scm_newsmob}, here is how we could -construct a smob whose @sc{cdr} contains a pointer to a freshly +contains a tag returned by @code{scm_make_smob_type}, here is how we +could construct a smob whose @sc{cdr} contains a pointer to a freshly allocated @code{struct image}: @example @@ -1597,8 +1599,7 @@ make_image (SCM name, SCM s_width, SCM s_height) struct image *image; int width, height; - SCM_ASSERT (SCM_NIMP (name) && SCM_STRINGP (name), name, - SCM_ARG1, "make-image"); + SCM_ASSERT (SCM_STRINGP (name), name, SCM_ARG1, "make-image"); SCM_ASSERT (SCM_INUMP (s_width), s_width, SCM_ARG2, "make-image"); SCM_ASSERT (SCM_INUMP (s_height), s_height, SCM_ARG3, "make-image"); @@ -1625,7 +1626,7 @@ their arguments, to avoid misinterpreting some other datatype as a smob, and perhaps causing a segmentation fault. Fortunately, this is pretty simple to do. The function need only verify that its argument is a non-immediate, whose @sc{car} is the type tag returned by -@code{scm_newsmob}. +@code{scm_make_smob_type}. For example, here is a simple function that operates on an image smob, and checks the type of its argument. We also present an expanded @@ -1657,10 +1658,13 @@ clear_image (SCM image_smob) void init_image_type () @{ - image_tag = scm_newsmob (&image_funs); + image_tag = scm_make_smob_type ("image", sizeof (struct image)); + scm_set_smob_mark (image_tag, mark_image); + scm_set_smob_free (image_tag, free_image); + scm_set_smob_print (image_tag, print_image); - scm_make_gsubr ("make-image", 3, 0, 0, make_image); scm_make_gsubr ("clear-image", 1, 0, 0, clear_image); + scm_make_gsubr ("make-image", 3, 0, 0, make_image); @} @end example @@ -1826,8 +1830,7 @@ make_image (SCM name, SCM s_width, SCM s_height) SCM image_smob; int width, height; - SCM_ASSERT (SCM_NIMP (name) && SCM_STRINGP (name), name, - SCM_ARG1, "make-image"); + SCM_ASSERT (SCM_STRINGP (name), name, SCM_ARG1, "make-image"); SCM_ASSERT (SCM_INUMP (s_width), s_width, SCM_ARG2, "make-image"); SCM_ASSERT (SCM_INUMP (s_height), s_height, SCM_ARG3, "make-image"); @@ -1949,11 +1952,9 @@ static SCM make_image (SCM name, SCM s_width, SCM s_height) @{ struct image *image; - SCM image_smob; int width, height; - SCM_ASSERT (SCM_NIMP (name) && SCM_STRINGP (name), name, - SCM_ARG1, "make-image"); + SCM_ASSERT (SCM_STRINGP (name), name, SCM_ARG1, "make-image"); SCM_ASSERT (SCM_INUMP (s_width), s_width, SCM_ARG2, "make-image"); SCM_ASSERT (SCM_INUMP (s_height), s_height, SCM_ARG3, "make-image"); @@ -1967,9 +1968,7 @@ make_image (SCM name, SCM s_width, SCM s_height) image->name = name; image->update_func = SCM_BOOL_F; - SCM_NEWSMOB (image_smob, image_tag, image); - - return image_smob; + SCM_RETURN_NEWSMOB (image_tag, image); @} static SCM @@ -1995,6 +1994,7 @@ clear_image (SCM image_smob) static SCM mark_image (SCM image_smob) @{ + /* Mark the image's name and update function. */ struct image *image = (struct image *) SCM_SMOB_DATA (image_smob); scm_gc_mark (image->name); @@ -2026,14 +2026,13 @@ print_image (SCM image_smob, SCM port, scm_print_state *pstate) return 1; @} -static scm_smobfuns image_funs = @{ - mark_image, free_image, print_image, 0 -@}; - void init_image_type () @{ - image_tag = scm_newsmob (&image_funs); + image_tag = scm_make_smob_type ("image", sizeof (struct image)); + scm_set_smob_mark (image_tag, mark_image); + scm_set_smob_free (image_tag, free_image); + scm_set_smob_print (image_tag, print_image); scm_make_gsubr ("clear-image", 1, 0, 0, clear_image); scm_make_gsubr ("make-image", 3, 0, 0, make_image); diff --git a/doc/example-smob/ChangeLog b/doc/example-smob/ChangeLog index 316d0b0ec..12afa8813 100644 --- a/doc/example-smob/ChangeLog +++ b/doc/example-smob/ChangeLog @@ -1,3 +1,11 @@ +2001-04-26 Neil Jerram <neil@ossau.uklinux.net> + + * image-type.c (make_image): Don't need to use SCM_NIMP before + SCM_STRINGP. + (clear_image): Use SCM_SMOB_PREDICATE. + (clear_image, mark_image, free_image, print_image): Use + SCM_SMOB_DATA rather than SCM_CDR. + 2000-06-20 Mikael Djurfeldt <mdj@thalamus.nada.kth.se> * image-type.c: Removed unused scm_smobfuns structure. diff --git a/doc/example-smob/image-type.c b/doc/example-smob/image-type.c index 3c49e592e..fe0a9b802 100644 --- a/doc/example-smob/image-type.c +++ b/doc/example-smob/image-type.c @@ -42,8 +42,7 @@ make_image (SCM name, SCM s_width, SCM s_height) struct image *image; int width, height; - SCM_ASSERT (SCM_NIMP (name) && SCM_STRINGP (name), name, - SCM_ARG1, "make-image"); + SCM_ASSERT (SCM_STRINGP (name), name, SCM_ARG1, "make-image"); SCM_ASSERT (SCM_INUMP (s_width), s_width, SCM_ARG2, "make-image"); SCM_ASSERT (SCM_INUMP (s_height), s_height, SCM_ARG3, "make-image"); @@ -66,11 +65,10 @@ clear_image (SCM image_smob) int area; struct image *image; - SCM_ASSERT ((SCM_NIMP (image_smob) - && SCM_CAR (image_smob) == image_tag), - image_smob, SCM_ARG1, "clear-image"); + SCM_ASSERT (SCM_SMOB_PREDICATE (image_tag, image_smob), + image_smob, SCM_ARG1, "clear-image"); - image = (struct image *) SCM_CDR (image_smob); + image = (struct image *) SCM_SMOB_DATA (image_smob); area = image->width * image->height; memset (image->pixels, 0, area); @@ -84,7 +82,8 @@ clear_image (SCM image_smob) static SCM mark_image (SCM image_smob) { - struct image *image = (struct image *) SCM_CDR (image_smob); + /* Mark the image's name and update function. */ + struct image *image = (struct image *) SCM_SMOB_DATA (image_smob); scm_gc_mark (image->name); return image->update_func; @@ -93,7 +92,7 @@ mark_image (SCM image_smob) static scm_sizet free_image (SCM image_smob) { - struct image *image = (struct image *) SCM_CDR (image_smob); + struct image *image = (struct image *) SCM_SMOB_DATA (image_smob); scm_sizet size = image->width * image->height + sizeof (struct image); free (image->pixels); @@ -105,7 +104,7 @@ free_image (SCM image_smob) static int print_image (SCM image_smob, SCM port, scm_print_state *pstate) { - struct image *image = (struct image *) SCM_CDR (image_smob); + struct image *image = (struct image *) SCM_SMOB_DATA (image_smob); scm_puts ("#<image ", port); scm_display (image->name, port); |