unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* The future: accessing vectors, arrays, etc from C
@ 2004-12-30 14:56 Marius Vollmer
  2005-01-04  0:31 ` Kevin Ryde
  2005-01-05  0:04 ` Neil Jerram
  0 siblings, 2 replies; 15+ messages in thread
From: Marius Vollmer @ 2004-12-30 14:56 UTC (permalink / raw)


Hi,

after some procrastination, I have more or less convinced myself to
make accessing vectors and arrays (including uniform numeric vectors
and arrays) more difficult from C.  Here is how and why.  Please
comment!


Right now, Guile's implementation of vectors and arrays is a bit
upside down: arrays are build on top of vectors, with the consequence
that not all one-dimensional arrays can be treated as vectors.  While
fixing this, we should also allow future improvements like
copy-on-write sub-arrays, growable vectors etc.

The first step is to come up with a C API that supports rich array
(and vector) implementations.  (We already have such an API for
strings, but it is not exported since the string implementation needs
to change significantly once more for Unicode support.)

One observation is that we can not have an API that locks arrays while
the locker is allowed to run arbitrary code.  That would probably very
quickly lead to unmanageable dead locks.

However, we do want allow C code access to the raw storage block of an
array, so that it can pass it to external code such as an image
processing library or linear algebra routines.

This can be achieved with a two-level scheme where an array points to
a storage object.  The storage object of an array can change over time
(when the array is copied-on-write, say), but storage objects
themselves always point to the same raw memory.

When accessing an array from C, one extracts the storage object and
then only works with that object.  The raw memory of the storage
object is guaranteed to stay in place as long as the storage object
itself is protected.

This mechanism is abstracted away via an 'array handle'.  You need to
get an array handle and then can access the array memory through this
handle.  The handle needs to be protected: this is most easily done by
just placing it on the stack, and then you don't need to 'release' it,
which is very comfortable.

Here are procedures for dealing with such handles.

  - void scm_array_get_handle (SCM array, scm_t_array_handle *h);

  Fill the array handle H so that it can be used with the procedures
  below.  The handle H must be visible to the garbage collector,
  therefore H must point to a struct on the stack.  See also
  scm_array_handle_copy.

  When ARRAY is not an array, an error is signalled.  All kinds of
  arrays are acceptable, including uniform numeric arrays, strings,
  and bitvectors.  To restrict the type of the array, use one of the
  scm_array_handle_*_elements functions.


  - void scm_vector_get_handle (SCM vec, scm_t_array_handle *);

  Like scm_array_get_handle, but only accepts one-dimensional arrays.


  - scm_t_array_handle *scm_array_handle_copy (scm_t_array_handle *H)

  Make a copy of H and return it.  This copy must be freed with
  scm_array_handle_free (H).  This function might be useful in
  situationswhere you can not allocate you handle on the stack.


  - void scm_array_handle_free (scm_t_array_handle *H)

  Free the array handle H, which _must_ have been created with
  scm_array_handle_copy.  Normal handles that are allocated on the
  stack _must_ _not_ be freed with this procedure.


  - size_t scm_array_handle_rank (scm_t_array_handle *);
  - scm_t_array_dimension *scm_array_handle_dims (scm_t_array_handle *);

  These procedures deliver information about the storage layout of the
  array, to be detailed elsewhere.


  - SCM scm_array_handle_ref (scm_t_array_handle *, size_t pos);

  Return the value at position POS in the storage vector of the
  handle.  POS can be computed from the layout information above and
  must be valid; no range checking is done.

  This function works for all kinds of arrays.


  - void scm_array_handle_set (scm_t_array_handle *, size_t pos, SCM val);

  Set the value at position POS in the storage vector of the handle to
  VAL.


  - const SCM *scm_array_handle_elements (scm_t_array_handle *);

  Return a pointer to the raw memory of a generic (non-uniform) array
  for reading.  When the array is not a generic one, signal an error.

  This pointer is valid as long as the handle is protected.  It is
  possible that the representation of the original array changes (in a
  copy-on-write operation, say) and in that case the pointer returned
  by this function will still be valid, but will no longer belong to
  the original array.  Thus, you might miss modifications to the
  array.  It is therefore best to refresh the pointer by a new call to
  this function from time to time.  Exactly how often is up to you.


  - SCM *scm_array_handle_writable_elements (scm_t_array_handle *);
  
  Like scm_array_handle_elements, but returns a pointer that is good
  for reading and writing.

  - size_t scm_array_handle_element_size (scm_t_array_handle *);
  - const void *scm_array_handle_untyped_elements (scm_t_array_handle *);
  - void *scm_array_handle_untyped_writable_elements (scm_t_array_handle *);

  Like above, but works with any kind of array.  You are not allowed
  to interpret the values, but you can copy them around with memcpy,
  say.


  - const scm_t_uint8 *scm_array_handle_u8_elements (scm_t_array_handle *);
  - scm_t_uint8 *scm_array_handle_u8_writable_elements (scm_t_array_handle *);
  - const scm_t_int8 *scm_array_handle_s8_elements (scm_t_array_handle *);
  - scm_t_int8 *scm_array_handle_s8_writable_elements (scm_t_array_handle *);
  - ETC

  Like scm_array_handle_elements and scm_array_handle_writable_elements,
  but for uniform numeric arrays.


  - const scm_t_uint32 *scm_array_handle_bit_elements (scm_t_array_handle *);
  - scm_t_uint8 *scm_array_handle_bit_writable_elements (scm_t_array_handle *);

  For bitvectors.


A typical function that optimizes for f64vectors:

  double
  vector_norm (SCM vec)
  {
    scm_t_array_handle h;
    scm_t_array_dimension *dim;
    size_t i;
    double sum = 0;

    scm_vector_get_handle (vec, &h);
    dim = scm_array_handle_dimensions (&h);

    if (scm_is_true (scm_f64vector_p (vec)))
      {
        double *elts;

        elts = scm_array_handle_f64_elements (&h);
        for (i = 0; i <= dim->len; i++, elts += dim->inc)
          sum += elts[0]*elts[0];

      }
    else
      {
        size_t pos = 0;
        for (i = 0; i <= dim->len; i++, pos += dim->inc)
          {
            double elt = scm_to_double (scm_array_handle_ref (&h, pos));
            sum += elt*elt;
          }
      }

    return sqrt (sum);
  }


There are and will be alternative and simpler ways to access vectors.
The first is just to use scm_c_vector_ref and scm_c_vector_set_x.  A
second is to only work with 'simple' vectors.  A simple vector is what
we have now: a simple, non-changing pointer to memory.  You can use
the macros SCM_SIMPLE_VECTOR_REF and SCM_SIMPLE_VECTOR_SET with them
but you don't get the full generality.


So what do you say?  Is something like the above acceptable?  Too
involved?  Are there holes in the thinking?

Again, the point is to make it relatively easy to write very general
code when dealing with vectors and arrays, to allow for future
improvements to the arrays implementation (maybe to the point of
unifying it with the string implementation) and to be thread-safe.

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


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


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

* Re: The future: accessing vectors, arrays, etc from C
  2004-12-30 14:56 The future: accessing vectors, arrays, etc from C Marius Vollmer
@ 2005-01-04  0:31 ` Kevin Ryde
  2005-01-04  1:51   ` Marius Vollmer
  2005-01-05  0:04 ` Neil Jerram
  1 sibling, 1 reply; 15+ messages in thread
From: Kevin Ryde @ 2005-01-04  0:31 UTC (permalink / raw)
  Cc: guile-user

Marius Vollmer <mvo@zagadka.de> writes:
>
>     scm_t_array_dimension *dim;
>
>         for (i = 0; i <= dim->len; i++, elts += dim->inc)

Will that be i < dim->len?

And scm_t_array_dimension will have something about the logical low
and high index values, in case you have an array starting from 1 or 5
or 10 or whatever?


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


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

* Re: The future: accessing vectors, arrays, etc from C
  2005-01-04  0:31 ` Kevin Ryde
@ 2005-01-04  1:51   ` Marius Vollmer
  0 siblings, 0 replies; 15+ messages in thread
From: Marius Vollmer @ 2005-01-04  1:51 UTC (permalink / raw)
  Cc: guile-user

Kevin Ryde <user42@zip.com.au> writes:

> Marius Vollmer <mvo@zagadka.de> writes:
>>
>>     scm_t_array_dimension *dim;
>>
>>         for (i = 0; i <= dim->len; i++, elts += dim->inc)
>
> Will that be i < dim->len?

Yes, right.

> And scm_t_array_dimension will have something about the logical low
> and high index values, in case you have an array starting from 1 or 5
> or 10 or whatever?

Yes, exactly.

Right now, I use the existing scm_t_array_dim.  But maybe one can come
up with something better, like having a lower bound and a length
instead of lower and upper bounds.


I have implemented this interface in CVS head now, and there is some
documentation about it, but everything is in a lot of flux right
now...

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


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


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

* Re: The future: accessing vectors, arrays, etc from C
  2004-12-30 14:56 The future: accessing vectors, arrays, etc from C Marius Vollmer
  2005-01-04  0:31 ` Kevin Ryde
@ 2005-01-05  0:04 ` Neil Jerram
  2005-01-05  4:12   ` Mike Gran
                     ` (2 more replies)
  1 sibling, 3 replies; 15+ messages in thread
From: Neil Jerram @ 2005-01-05  0:04 UTC (permalink / raw)
  Cc: guile-user

Marius Vollmer wrote:
> Hi,
> 
> after some procrastination, I have more or less convinced myself to
> make accessing vectors and arrays (including uniform numeric vectors
> and arrays) more difficult from C.  Here is how and why.  Please
> comment!

Hi Marius,

Apologies for the slow response on this.  In general I think your 
proposal looks good, but I have two points to raise for consideration.

Firstly, I recall an old discussion between Jim and Mikael about a 
"leasing" interface in this area, which struck me at that time as very 
elegant.  I've not analysed how close it is to your thoughts, or how 
relevant it might be, but I thought you might like to review that and 
consider whether it affects your thinking at all.  The URLs of two 
relevant messages are:

http://sources.redhat.com/ml/guile/1999-01/msg00093.html
http://sources.redhat.com/ml/guile/1999-01/msg00109.html

Secondly, I am slightly concerned about the level of change that this 
means in the C API.  Actually, to be precise, I'm not sure I'm bothered 
about the level of change per se, as I believe the current reality is 
that a Guile application writer has no choice but to select an available 
major version of Guile (e.g. 1.6) and to target their application at 
specifically that version; and fortunately the bugs in Guile are few 
enough that it is feasible to stick with an older version.

However, I wonder if perhaps we should have a more explicit and public 
policy on the level of change that is (i) acceptable and (ii) likely, 
from one major release to the next, so that developers know what to expect?

What do you (and everyone else) think?

Regards,
	Neil


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


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

* Re: The future: accessing vectors, arrays, etc from C
  2005-01-05  0:04 ` Neil Jerram
@ 2005-01-05  4:12   ` Mike Gran
  2005-01-05 18:10     ` Marius Vollmer
  2005-01-05 11:52   ` Thien-Thi Nguyen
  2005-01-05 18:01   ` Marius Vollmer
  2 siblings, 1 reply; 15+ messages in thread
From: Mike Gran @ 2005-01-05  4:12 UTC (permalink / raw)
  Cc: guile-user


--- Neil Jerram <neil@ossau.uklinux.net> wrote:

> However, I wonder if perhaps we should have a more explicit and
> public 
> policy on the level of change that is (i) acceptable and (ii) likely,
> 
> from one major release to the next, so that developers know what to
> expect?
> 
> What do you (and everyone else) think?
> 

The design goals and expected improvements of 1.8 over 1.6 are unclear
to me.  I don't track those discussions closely.

Every change to the API increases the risk of problems in updating a
code base, but, if the reward gained is great enough, the risk is
acceptable.

I'm fine with these array API changes.  They work.  If if should be
done, do it.  But, it would be comforting to see that the API
approaches a frozen state as the design goals of 1.8 are met.  

(If the API is sufficiently different to disallow interoperation
between a 1.6 codebase and a 1.8 codebase, it may as well be called
2.0.)

-
Mike Gran


		
__________________________________ 
Do you Yahoo!? 
The all-new My Yahoo! - What will yours do?
http://my.yahoo.com 


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


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

* Re: The future: accessing vectors, arrays, etc from C
  2005-01-05  0:04 ` Neil Jerram
  2005-01-05  4:12   ` Mike Gran
@ 2005-01-05 11:52   ` Thien-Thi Nguyen
  2005-01-05 18:01   ` Marius Vollmer
  2 siblings, 0 replies; 15+ messages in thread
From: Thien-Thi Nguyen @ 2005-01-05 11:52 UTC (permalink / raw)


   From: Neil Jerram <neil@ossau.uklinux.net>
   Date: Wed, 05 Jan 2005 00:04:28 +0000

   However, I wonder if perhaps we should have a more explicit and
   public policy on the level of change that is (i) acceptable and (ii)
   likely, from one major release to the next, so that developers know
   what to expect?

probably it is better to simply accurately label what is released,
than to restrict what is released.  if the changes are major, bump
the major version number.  otherwise, the discrepency between label
and goods inside the package just introduces confusion and mistrust.

along w/ this approach would have to be an acceptance that not everyone
is interested in following the change in lockstep.  historically, that
understanding has not been easy for guile maintainers to muster in word
or deed, however.  perhaps you will be able to break new ground here.

basically, it is fine to "wander around the design space", as long as
the activity is not misrepresented (or self-mistaken) as leadership.

thi


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


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

* Re: The future: accessing vectors, arrays, etc from C
  2005-01-05  0:04 ` Neil Jerram
  2005-01-05  4:12   ` Mike Gran
  2005-01-05 11:52   ` Thien-Thi Nguyen
@ 2005-01-05 18:01   ` Marius Vollmer
  2005-01-06 19:13     ` Marius Vollmer
  2005-01-08 23:19     ` Neil Jerram
  2 siblings, 2 replies; 15+ messages in thread
From: Marius Vollmer @ 2005-01-05 18:01 UTC (permalink / raw)
  Cc: guile-user

Neil Jerram <neil@ossau.uklinux.net> writes:

> Firstly, I recall an old discussion between Jim and Mikael about a
> "leasing" interface in this area, which struck me at that time as
> very elegant.

Yes, I didn't remember this discussion.  Thank you for pointing it
out!

> I've not analysed how close it is to your thoughts, or how relevant
> it might be, but I thought you might like to review that and
> consider whether it affects your thinking at all.

The proposed leasing interface doesn't try to solve the problem that I
am adressing now: allowing changes to the representation of arrays
(which I take here to include vectors, uniform or not, bitvectors, and
strings) in a multi-threaded program.[1]

The leasing interface addresses the situation where you want to access
a Scheme vector as a vector of doubles, and want to avoid to making a
copy of the elements in the case the Scheme vector is a uniform
numeric vector already.  It doens't really deal with non-local exits,
I think, for example, which are important, too.

A change in representation of an array might happen when the copy for
a copy-on-write array takes place, or when the first 16-bit Unicode
character is stored in a 8-bit string.  In general, when we can come
up with a C API to arrays that is convenient and allows such changes
to happen, we should install it.  Once we can change represetation, we
can implement a lot of cool things (whether they are a good idea or
not), like growing arrays in place.

I think we can have such an API.  I will post documentation for it
soonish.

It will be more tedious to use than the old one mainly because it is
more general, something which has nothing to do with allowing
representations to change: When using the new API, your code must be
able to deal with non-contiguously stored vectors, while previously
you could just assume that all vectors are stored contiguously.

> Secondly, I am slightly concerned about the level of change that this
> means in the C API.

Yes, I am too.

> Actually, to be precise, I'm not sure I'm bothered about the level
> of change per se, as I believe the current reality is that a Guile
> application writer has no choice but to select an available major
> version of Guile (e.g. 1.6) and to target their application at
> specifically that version; and fortunately the bugs in Guile are few
> enough that it is feasible to stick with an older version.

Yes, you will be missing all the cool new features, tho.

> However, I wonder if perhaps we should have a more explicit and
> public policy on the level of change that is (i) acceptable and (ii)
> likely, from one major release to the next, so that developers know
> what to expect?

Hmm, that would be hard to formalize, no?

I think I get a feel for how intrusive these changes are, since I have
to change all of Guile itself to use the new API.  I hope that
restrains me from doing large, unmotivated changes.  Everytime when
installing a new API and changing Guile to use it, the code got much
cleaner (in my opinion), more robust, and subtle bugs were fixed.

What I am worried about is that I have not done the deprecation of the
old interfaces as good as it could be done.

For example, instead of the old SCM_VECTORP, SCM_VECTOR_REF and
SCM_VECTOR_SET, you now should use scm_is_simple_vector,
SCM_SIMPLE_VECTOR_REF, and SCM_SIMPLE_VECTOR_SET.  That might appear
to be arbitrary, since only names have changed.

On the other hand, this name change makes it clear that only the
special case of simple vectors is being dealt with, and people might
be motivated to look up in the manual how to deal with the general
case.

Hmm.

[1] Many of the problems also appear in single-threaded programs when
the program is allowed to do arbitrary things while having a lease for
an array.


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


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

* Re: The future: accessing vectors, arrays, etc from C
  2005-01-05  4:12   ` Mike Gran
@ 2005-01-05 18:10     ` Marius Vollmer
  0 siblings, 0 replies; 15+ messages in thread
From: Marius Vollmer @ 2005-01-05 18:10 UTC (permalink / raw)
  Cc: guile-user, Neil Jerram

Mike Gran <spk121@yahoo.com> writes:

> The design goals and expected improvements of 1.8 over 1.6 are unclear
> to me.  I don't track those discussions closely.

One goal is the make the C API to Scheme values much more robust in
the presence of multi-threading, internationalization, and future
developments in general.  After that, I hope that we don't need to
change the interfaces incompatibly any time soon.

> I'm fine with these array API changes.  They work.  If if should be
> done, do it.  But, it would be comforting to see that the API
> approaches a frozen state as the design goals of 1.8 are met.  

The Guile API is huge (and has developed mostly by just declaring
parts of the original SCM implementation as an API), and some parts of
it will probably remain that might need bigger changes after 1.8, like
the API for ports, records, structures, or modules.

I think the pressure to release 1.8 is now high enough to not try to
come up with something saner for those parts.  I really only want to
finish the array stuff (with turned out to be much larger than I
tought), and threads.

> (If the API is sufficiently different to disallow interoperation
> between a 1.6 codebase and a 1.8 codebase, it may as well be called
> 2.0.)

Yes, that is worth thinking about.  Hopefully, a lot of code written
for 1.6 will continue to work for a start, but most of it will likely
need to be changed to avoid using deprecated features.


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


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

* Re: The future: accessing vectors, arrays, etc from C
  2005-01-05 18:01   ` Marius Vollmer
@ 2005-01-06 19:13     ` Marius Vollmer
  2005-01-06 23:08       ` Neil Jerram
  2005-01-08 23:19     ` Neil Jerram
  1 sibling, 1 reply; 15+ messages in thread
From: Marius Vollmer @ 2005-01-06 19:13 UTC (permalink / raw)
  Cc: guile-user

Marius Vollmer <marius.vollmer@uni-dortmund.de> writes:

> I think we can have such an API.  I will post documentation for it
> soonish.

Ok, please look at the version of the manual here:

    http://www.dt.e-technik.uni-dortmund.de/~mvo/guile.html/

Especially

    http://www.dt.e-technik.uni-dortmund.de/~mvo/guile.html/Accessing-Arrays-from-C.html

and

    http://www.dt.e-technik.uni-dortmund.de/~mvo/guile.html/Vector-Accessing-from-C.html

but also

    http://www.dt.e-technik.uni-dortmund.de/~mvo/guile.html/Uniform-Numeric-Vectors.html

and 

    http://www.dt.e-technik.uni-dortmund.de/~mvo/guile.html/Bit-Vectors.html


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


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

* Re: The future: accessing vectors, arrays, etc from C
  2005-01-06 19:13     ` Marius Vollmer
@ 2005-01-06 23:08       ` Neil Jerram
  0 siblings, 0 replies; 15+ messages in thread
From: Neil Jerram @ 2005-01-06 23:08 UTC (permalink / raw)
  Cc: guile-user

Marius Vollmer wrote:
> Marius Vollmer <marius.vollmer@uni-dortmund.de> writes:
> 
> 
>>I think we can have such an API.  I will post documentation for it
>>soonish.
> 
> 
> Ok, please look at the version of the manual here:
> 
>     http://www.dt.e-technik.uni-dortmund.de/~mvo/guile.html/
> 
Many thanks.  This looks good, especially in explaining your previous 
email's note about storage sometimes being non-contiguous - which was 
worrying me quite a lot until I understood what you meant!

I still need to respond more fully to your and others' comments on 
leasing and API change - I hope to do that over the coming weekend.

Regards,
	Neil


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


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

* Re: The future: accessing vectors, arrays, etc from C
  2005-01-05 18:01   ` Marius Vollmer
  2005-01-06 19:13     ` Marius Vollmer
@ 2005-01-08 23:19     ` Neil Jerram
  2005-01-11 18:01       ` Marius Vollmer
  1 sibling, 1 reply; 15+ messages in thread
From: Neil Jerram @ 2005-01-08 23:19 UTC (permalink / raw)
  Cc: guile-user

Marius Vollmer wrote:
> 
> The proposed leasing interface doesn't try to solve the problem that I
> am adressing now ... [it] addresses the situation where you want to access
> a Scheme vector as a vector of doubles, and want to avoid to making a
> copy of the elements in the case the Scheme vector is a uniform
> numeric vector already.

Yes, I see that now - thanks for explaining.  (There is a minor 
similarity, in that both leases and your handles protect the underlying 
storage from GC, but that's about it.)

> A change in representation of an array might happen when the copy for
> a copy-on-write array takes place, or when the first 16-bit Unicode
> character is stored in a 8-bit string.

Just to check understanding: is it correct that:

- all such changes have to be driven from Scheme code?

- such changes do not affect the arrays obtained by C code through the 
scm_*_array_handle_*_elements functions?

>  In general, when we can come
> up with a C API to arrays that is convenient and allows such changes
> to happen, we should install it.  Once we can change represetation, we
> can implement a lot of cool things (whether they are a good idea or
> not), like growing arrays in place.

Agreed, subject to general concerns about API change which we discuss below.

> It will be more tedious to use than the old one mainly because it is
> more general, something which has nothing to do with allowing
> representations to change: When using the new API, your code must be
> able to deal with non-contiguously stored vectors, while previously
> you could just assume that all vectors are stored contiguously.

This worried me when I first read it, but in fact I think the only 
increase in tediousness is that the increment from one element to the 
next may not always be 1.  But it will always be some constant.  Is that 
right, or am I missing some other kinds of tediousness? :-)

I think this delta is OK, personally.  And in practice many applications 
  will be able to get away with asserting that the increment is 1, by 
simplying avoiding array mapping in more than one dimension.

>>Actually, to be precise, I'm not sure I'm bothered about the level
>>of change per se, as I believe the current reality is that a Guile
>>application writer has no choice but to select an available major
>>version of Guile (e.g. 1.6) and to target their application at
>>specifically that version; and fortunately the bugs in Guile are few
>>enough that it is feasible to stick with an older version.
> 
> 
> Yes, you will be missing all the cool new features, tho.

Yes, of course.  Also, in my view, the whole point of Guile is to 
minimize your C code and maximize your Scheme code; for anyone who 
agrees with this, the cost of upgrading to a new version (which is 
roughly proportional to the amount of C code) should be dwarfed by the 
benefit (roughly proportional to the amount of Scheme code).

Even so, I think we could usefully make a public statement (perhaps by 
adding it to the manual) reflecting the apparent consensus from this 
discussion, namely...

1. We do _not_ regard it as an overriding aim to maintain C API 
compatibility between Guile releases (that is, between versions w.x and 
y.z where ((w != y) || (x != z))); we believe it is more important to 
improve Guile's overall utility, which sometimes conflicts with 
retaining API compatibility.

2. Consequently, the developer of a non-trivial Guile application must 
in practice choose a particular Guile release and write their C code 
according to that release's C API, and should expect _some_ work to be 
required when enhancing their application to target a new Guile release.

3. On the other hand, we will obviously not pointlessly change the C API 
between releases, for at least four pragmatic reasons.

    - We don't want to annoy our users for no reason!

    - Any API change itself requires work by the core Guile developers.

    - The core Guile code uses its own APIs, so any unnecessary changes 
would require unnecessary work in Guile's own internals.

    - Most of the core Guile developers also write Guile applications, 
so any unnecessary changes would require unnecessary work in those 
applications as well.

4. Consequently the upgrade work mentioned in (2), while non-zero, 
should always be as small as it could reasonably be.

5. Where possible, we will support the old C API, for the next one or 
more releases, as a "deprecated" interface.  Guile's deprecation 
infrastructure both highlights to1	 the developer that they are using a 
deprecated interface, and gives them a one-line hint as to what they 
should be doing instead.

6. We will aim to document API changes completely.  The first point of 
reference for this is usually the NEWS file in each new release.  Such 
documentation may be imperfect in practice, but only for the same 
reasons that make documentation in general imperfect.

> What I am worried about is that I have not done the deprecation of the
> old interfaces as good as it could be done.
> 
> For example, instead of the old SCM_VECTORP, SCM_VECTOR_REF and
> SCM_VECTOR_SET, you now should use scm_is_simple_vector,
> SCM_SIMPLE_VECTOR_REF, and SCM_SIMPLE_VECTOR_SET.  That might appear
> to be arbitrary, since only names have changed.
> 
> On the other hand, this name change makes it clear that only the
> special case of simple vectors is being dealt with, and people might
> be motivated to look up in the manual how to deal with the general
> case.

Sounds good and sufficiently motivated to me.  I presume SCM_VECTORP, 
SCM_VECTOR_REF and SCM_VECTOR_SET will remain available as deprecated 
macros, won't they?

Regards,
	Neil


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


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

* Re: The future: accessing vectors, arrays, etc from C
  2005-01-08 23:19     ` Neil Jerram
@ 2005-01-11 18:01       ` Marius Vollmer
  2005-01-11 19:53         ` Mikael Djurfeldt
  2005-01-16  8:06         ` Neil Jerram
  0 siblings, 2 replies; 15+ messages in thread
From: Marius Vollmer @ 2005-01-11 18:01 UTC (permalink / raw)
  Cc: guile-user

Neil Jerram <neil@ossau.uklinux.net> writes:

>> A change in representation of an array might happen when the copy for
>> a copy-on-write array takes place, or when the first 16-bit Unicode
>> character is stored in a 8-bit string.
>
> Just to check understanding: is it correct that:
>
> - all such changes have to be driven from Scheme code?

Hmm, I'm not sure what you are getting at.  Certainly C code can
trigger these changes as well, but they do not happen spontaneously.

For example, you might get an error about not being allowed to change
a reserved array when you try to grow a vector while it is being
sorted in another thread.  The thing to do then is to use some
synchronization (such as a mutex) to prevent this situation.

> - such changes do not affect the arrays obtained by C code through the
> scm_*_array_handle_*_elements functions?

Right.  Those arrays are 'reserved' while C code accesses them and you
can't change them in a way that would invalidate the pointers that C
code is using.

>> It will be more tedious to use than the old one mainly because it is
>> more general, something which has nothing to do with allowing
>> representations to change: When using the new API, your code must be
>> able to deal with non-contiguously stored vectors, while previously
>> you could just assume that all vectors are stored contiguously.
>
> This worried me when I first read it, but in fact I think the only
> increase in tediousness is that the increment from one element to the
> next may not always be 1.  But it will always be some constant.  Is
> that right, or am I missing some other kinds of tediousness? :-)

That is exactly right.

(There are any number of schemes to store arrays in memory, just think
about sparse or band matrices, and we can't offer them all.  I think
the current compromise by Guile is the right one.)

> I think this delta is OK, personally.  And in practice many
> applications will be able to get away with asserting that the
> increment is 1, by simplying avoiding array mapping in more than one
> dimension.

Hmm, no, even vectors can have increments != 1.  The diagonal of a
matrix would be an example.

> Even so, I think we could usefully make a public statement (perhaps by
> adding it to the manual) reflecting the apparent consensus from this
> discussion, namely...

Yours is a very good summary, but I myself wouldn't want to put it in
the manual... just let reality speak for itself.  But it should be
recorded somewhere.  Maybe in the FAQ?

>> [...]
>
> Sounds good and sufficiently motivated to me.  I presume SCM_VECTORP,
> SCM_VECTOR_REF and SCM_VECTOR_SET will remain available as deprecated
> macros, won't they?

Yes, but their performance sucks.


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


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

* Re: The future: accessing vectors, arrays, etc from C
  2005-01-11 18:01       ` Marius Vollmer
@ 2005-01-11 19:53         ` Mikael Djurfeldt
  2005-01-15 21:27           ` Neil Jerram
  2005-01-16  8:06         ` Neil Jerram
  1 sibling, 1 reply; 15+ messages in thread
From: Mikael Djurfeldt @ 2005-01-11 19:53 UTC (permalink / raw)
  Cc: guile-user, djurfeldt, Neil Jerram

On Tue, 11 Jan 2005 19:01:44 +0100, Marius Vollmer
<marius.vollmer@uni-dortmund.de> wrote:
> Neil Jerram <neil@ossau.uklinux.net> writes:
> > Even so, I think we could usefully make a public statement (perhaps by
> > adding it to the manual) reflecting the apparent consensus from this
> > discussion, namely...
> 
> Yours is a very good summary, but I myself wouldn't want to put it in
> the manual... just let reality speak for itself.  But it should be
> recorded somewhere.  Maybe in the FAQ?

It should probably also be added to the policy directory in the
workbook CVS module.

M


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


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

* Re: The future: accessing vectors, arrays, etc from C
  2005-01-11 19:53         ` Mikael Djurfeldt
@ 2005-01-15 21:27           ` Neil Jerram
  0 siblings, 0 replies; 15+ messages in thread
From: Neil Jerram @ 2005-01-15 21:27 UTC (permalink / raw)
  Cc: guile-user, Marius Vollmer

Mikael Djurfeldt wrote:
> On Tue, 11 Jan 2005 19:01:44 +0100, Marius Vollmer
> <marius.vollmer@uni-dortmund.de> wrote:
> 
>>Neil Jerram <neil@ossau.uklinux.net> writes:
>>
>>>Even so, I think we could usefully make a public statement (perhaps by
>>>adding it to the manual) reflecting the apparent consensus from this
>>>discussion, namely...
>>
>>Yours is a very good summary, but I myself wouldn't want to put it in
>>the manual... just let reality speak for itself.  But it should be
>>recorded somewhere.  Maybe in the FAQ?
> 
> 
> It should probably also be added to the policy directory in the
> workbook CVS module.
> 

Thanks for the suggestion; statement is now saved in 
workbook/policy/api-changes.text.

(FAQ will take a little longer, as I need to sort out my CVS access to 
the web pages.)

	Neil



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


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

* Re: The future: accessing vectors, arrays, etc from C
  2005-01-11 18:01       ` Marius Vollmer
  2005-01-11 19:53         ` Mikael Djurfeldt
@ 2005-01-16  8:06         ` Neil Jerram
  1 sibling, 0 replies; 15+ messages in thread
From: Neil Jerram @ 2005-01-16  8:06 UTC (permalink / raw)
  Cc: guile-user

Marius Vollmer wrote:
> 
> Yours is a very good summary, but I myself wouldn't want to put it in
> the manual... just let reality speak for itself.  But it should be
> recorded somewhere.  Maybe in the FAQ?

OK, I've added this to the FAQ now.  Please take a look - especially as 
I had to do some of the "gnu-ify" steps by hand - and let me know if any 
markups needed.

Regards,
	Neil


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


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

end of thread, other threads:[~2005-01-16  8:06 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-30 14:56 The future: accessing vectors, arrays, etc from C Marius Vollmer
2005-01-04  0:31 ` Kevin Ryde
2005-01-04  1:51   ` Marius Vollmer
2005-01-05  0:04 ` Neil Jerram
2005-01-05  4:12   ` Mike Gran
2005-01-05 18:10     ` Marius Vollmer
2005-01-05 11:52   ` Thien-Thi Nguyen
2005-01-05 18:01   ` Marius Vollmer
2005-01-06 19:13     ` Marius Vollmer
2005-01-06 23:08       ` Neil Jerram
2005-01-08 23:19     ` Neil Jerram
2005-01-11 18:01       ` Marius Vollmer
2005-01-11 19:53         ` Mikael Djurfeldt
2005-01-15 21:27           ` Neil Jerram
2005-01-16  8:06         ` Neil Jerram

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).