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; }