Warning: This is the manual of the legacy Guile 2.2 series. You may want to read the manual of the current stable series instead.
Next: Foreign Object Memory Management, Previous: Creating Foreign Objects, Up: Defining New Foreign Object Types [Contents][Index]
Functions that operate on foreign objects should check that the passed
SCM
value indeed is of the correct type before accessing its
data. They can do this with scm_assert_foreign_object_type
.
For example, here is a simple function that operates on an image object, and checks the type of its argument.
SCM clear_image (SCM image_obj) { int area; struct image *image; scm_assert_foreign_object_type (image_type, image_obj); image = scm_foreign_object_ref (image_obj, 0); 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); return SCM_UNSPECIFIED; }