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: New smob interface


Greg Badros <gjb@cs.washington.edu> writes:

> /* begin */
> SCM
> scm_make_my_type (int a, SCM b)
> {
>   SCM z;
>   my_type_t *m = scm_must_malloc (sizeof (my_type_t), "my-type");
>   m->a = a;
>   m->b = b;
>   SCM_NEWSMOB (z, my_type, m);
>   return m;
> }
> /* end */
> 
> Shouldn't the "return m" be "return z"?

It should of course be z.  Sorry.

> What do you folks think about a RETURN_SCM_NEWSMOB macro that would let
> users write:
> 
> SCM
> scm_make_my_type (int a, SCM b)
> {
>   my_type_t *m = scm_must_malloc (sizeof (my_type_t), "my-type");
>   m->a = a;
>   m->b = b;
>   RETURN_SCM_NEWSMOB (my_type, m);
> }

We guarantee that names in Guile start with SCM or scm (or gh).

The name should be SCM_RETURN_SMOB, SCM_RETURN_NEW_SMOB or something
like that.  (The name NEWSMOB is chosen because of the similarity in
use to NEWCELL.)

I won't kill you if you add this.  Maybe other people have strong
opinions in this case?

> #define RETURN_SCM_NEWSMOB(t,m) do { SCM __guile_smob_answer; \
>                                      SCM_NEWSMOB(__guile_smob_answer,(t),(m));\
>                                      return __guile_smob_answer; } while (0)

What is the advantage of using do ... while compared to just using
braces?

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