Next: Garbage Collecting Smobs, Previous: Creating Instances, Up: Defining New Types (Smobs)
Functions that operate on smobs should check that the passed
SCM value indeed is a suitable smob before accessing its data.
They can do this with scm_assert_smob_type.
For example, here is a simple function that operates on an image smob, and checks the type of its argument.
SCM
clear_image (SCM image_smob)
{
int area;
struct image *image;
scm_assert_smob_type (image_tag, image_smob);
image = (struct image *) SCM_SMOB_DATA (image_smob);
area = image->width * image->height;
memset (image->pixels, 0, area);
/* Invoke the image's update function.
*/
if (scm_is_true (image->update_func))
scm_call_0 (image->update_func);
scm_remember_upto_here_1 (image_smob);
return SCM_UNSPECIFIED;
}
See Remembering During Operations for an explanation of the call
to scm_remember_upto_here_1.