unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Suggestion for change in the new array interface
@ 2005-02-19 21:32 Mikael Djurfeldt
  2005-02-28  2:41 ` Marius Vollmer
  0 siblings, 1 reply; 2+ messages in thread
From: Mikael Djurfeldt @ 2005-02-19 21:32 UTC (permalink / raw)
  Cc: Mikael Djurfeldt

When programming with the new array interface I've noticed an
inconvenience that should be easy to fix:

When checking the arguments of a procedure there's a few things one
normally checks apart from the type. It's common that a procedure
takes an array of a specific rank, and it's not unusual that only
arrays of a specific dimension qualifies as an argument.

Since both rank and dimensionality are extracted from the array handle
this handle needs to be allocated *before* argument checking is
complete. This means that we have to free the handle on an error exit.
So, the code for argument checking only becomes:

  SCM_ASSERT (scm_is_typed_array (a, <array type>), a, <pos>, <function name>);
  scm_array_get_handle (a, &h);
  dims = scm_array_handle_dims (&h);
  if (scm_array_handle_rank (&h) != <rank>  || dims[0].ubnd -
dims[0].lbnd + 1 != <dim1> || ...)
  {
    scm_array_handle_release (&h);
    scm_wrong_type_arg (<function nam>, <pos>, a);
  }

Since it seems unreasonable to allow future code to modify the
dimension of an array, I don't see any reason why we couldn't ask for
the rank and dimensions fo an array without allocating the handle. The
above code could then instead look like this:

  SCM_ASSERT (scm_is_typed_array (a, <array type>), a, <pos>, <function name>);
  dims = scm_array_dims (a);
  SCM_ASSERT ( scm_array_rank (a) != <rank>  || dims[0].ubnd -
dims[0].lbnd + 1 != <dim1> || ...,
              a, <pos>, <function name>);
  scm_array_get_handle (a, &h);

This all of course depends on the first sentence in the description of
how to handle allocation of handles in the reference manual:

 "You must take care to always unreserve an array after reserving it,
also in the presence of non-local exits.  To simplify this, reserving
and unreserving work like a frame (*note Frames::): a call to
`scm_array_get_handle' can be thought of as beginning a frame and
`scm_array_handle_release' as ending it.  When a non-local exit happens
between these two calls, the array is implicitely unreserved."

The part after the first sentence indicates that I don't have to call
scm_array_handle_release before throwing the error. Is that so? In
that case this suggestion of change is unnecessary.

Comments?

M


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Suggestion for change in the new array interface
  2005-02-19 21:32 Suggestion for change in the new array interface Mikael Djurfeldt
@ 2005-02-28  2:41 ` Marius Vollmer
  0 siblings, 0 replies; 2+ messages in thread
From: Marius Vollmer @ 2005-02-28  2:41 UTC (permalink / raw)
  Cc: guile-devel

Mikael Djurfeldt <mdjurfeldt@gmail.com> writes:

> The part after the first sentence indicates that I don't have to call
> scm_array_handle_release before throwing the error. Is that so?

It is so.  Also, you can use scm_c_array_rank to get the array rank as
a size_t.  (I forgot to document this function, sorry...)

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-02-28  2:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-19 21:32 Suggestion for change in the new array interface Mikael Djurfeldt
2005-02-28  2:41 ` Marius Vollmer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).