pika-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Pika-dev] C argument type for indices?


From: Tom Lord
Subject: Re: [Pika-dev] C argument type for indices?
Date: Mon, 2 Feb 2004 15:36:51 -0800 (PST)


    > From: Andreas Rottmann <address@hidden>

    > I just saw that the vector index arguments are declared as
    > t_scm_word. This is wrong, just as with the hashes. Should we use
    > fixnums here, too, or is t_ulong better for the job?

    > I'll fix those together with the hash/word issue.

Good spotting.

It's worse, than that.   They're inconsistent:  the `n_elts' parameter
to `scm_make_vector' is `int' but the index `elt' parameter to
`scm_ref_vector_elt' is `t_scm_word'.

Sigh.

And this reflects inconsistency with and in the lower level code, too:

`scm_set_n_limb_elts' (src/reps/vtable-obj-imp.h) takes an `int' size,
`scm_ref_limb_elt' takes a `t_uing' offset and so forth.

I think that the thing to do here is to consistently use `ssize_t' for
all of these purposes.

ssize_t is certainly large enough and leaves us with negative values
for exceptional-case return values, defaults, and the like.

(`int' is fine for the number of limbs and limb indexes -- just not
for elt offsets into limbs.  `int' is similarly fine for vtable-object
slot indexes.)

t_scm_fixnum is right for hash values because we want to be able to
convert those to and from Scheme without needing bignums.

But the range of t_scm_fixnum can be reasonable yet still be too small
to contain the largest reasonable vector size.  For example, 16-bit
fixnums would be extreme -- but not completely unreasonable.  But even
in such an implementation, a limit of 2^15 vector elements would be
unreasonable.

-t





reply via email to

[Prev in Thread] Current Thread [Next in Thread]