This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: Making Guile slower
Greg Harvey <Greg.Harvey@thezone.net> writes:
> Mikael Djurfeldt <mdj@mdj.nada.kth.se> writes:
>
> > Greg Harvey <Greg.Harvey@thezone.net> writes:
> >
> > > Consider this:
> > >
> > > SCM_NEWCELL(foo);
> > > SCM_SETCDR(foo, scm_must_malloc(foo_size, s_make_foo));
> > > SCM_SETCAR(foo, scm_tc16_foo);
> >
> > ... which should be written ...
m = scm_must_malloc (foo_size, s_make_foo);
SCM_NEWCELL (foo);
SCM_SETCDR (foo, m);
SCM_SETCAR (foo, scm_tc16_foo);
> Yes, but it rarely is ;)
There are only 6 places where SCM_NEWCELL is used incorrectly:
* posix.c (scm_getgroups)
* strings (scm_makstr)
* strings (scm_make_shared_substring)
* strings (scm_mkstrport)
* struct.c (scm_make_vtable_vtable)
* unif.c (scm_make_ra)
You will have the same problem when you create a smob btw. For example
the following is wrong:
----------------------------------------
environment->obarray =
scm_make_vector ((SCM) SCM_MAKINUM (scm_symhash_dim), SCM_EOL);
SCM_NEWCELL (environment_smob);
SCM_SETCDR (environment_smob, environment);
SCM_SETCAR (environment_smob, scm_tc16_environment);
which should be written:
environment->obarray = SCM_EOL; // prevent obarray from being gc'ed
SCM_NEWCELL (environment_smob);
SCM_SETCDR (environment_smob, environment);
SCM_SETCAR (environment_smob, scm_tc16_environment);
environment->obarray =
scm_make_vector ((SCM) SCM_MAKINUM (scm_symhash_dim), SCM_EOL);
----------------------------------------
If someone uses SCM_NEWCELL() and doesn't understand what happens, it
is likely that he will experience the same problem when he creates
smobs. I think it is better to fix the usage of SCM_NEWCELL() in the
four files posix.c, strings.c, struct.c and unif.c and write some
documentation how SCM_NEWCELL() should be used.
Jost