This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: how to scm_smob_p?


forcer <forcer@mindless.com> writes:

> Hi there.
> I'm currently facing a problem while writing an extension library for guile:
> I created a smob, which i use extensively in the library,
> but i don't know how to type-check for this smob.
> Currently i'm checking wether ((long)gh_car(scm) == my_smob_tag), and if
> not i'll throw an error.
> The problem i encountered is that if a wrong object (that is, any immediate
> type) it will bomb for obvious reasons (car will not point to anything
> useful)
> I tried to also do a gh_pair_p and scm_pair_p but both return 0/#f (which
> is quite logical, you don't want a smob to be a pair for anyone but guile)
> so now i'm on the search for a scm_smob_p. Any ideas?

See, e.g., our macro conventions in scwm.  From scwm/color.h:

#define COLOR_P(X) (SCM_NIMP(X) && gh_car(X) == (SCM)scm_tc16_scwm_color)

thus, the macro can be applied to any SCM safely.

Greg