* Unexpected srfi-4 C Interface Change in 2.0.10
@ 2014-03-19 14:22 Barry Fishman
0 siblings, 0 replies; 4+ messages in thread
From: Barry Fishman @ 2014-03-19 14:22 UTC (permalink / raw)
To: guile-devel
When building C interface code using scm_f32vector_writable_elements()
in 2.0.10 and on the trunk I found:
For a vector generated in guile with:
(f32vector 0.25 0.25 0.25 1.0)
I found in the C interface:
scm_t_array_handle handle;
size_t vlen, vinc;
float *arrayp;
arrayp = scm_f32vector_writable_elements(s_uvec, &handle,
&vlen, &vinc)
When I test vlen it now seems to contain the number of bytes (16)
rather than the number of elements (4) in the f32vector.
It was 4 in 2.0.9 and the guile trunk I built on Jan 8.
It was 16 in 2.0.10 and the guile trunk I built on March 17.
I assume it relates to the Feb 8 changes, where:
(in commit dc65b88d839c326889618112c4870ad3a64e9446)
*lenp = scm_c_bytevector_length (uvec) / width;
and width is set to 1 in the macro:
DEFINE_SRFI_4_C_FUNCS (F32, f32, float, 1);
--
Barry Fishman
^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <mailman.201.1395244856.16207.guile-devel@gnu.org>]
* Unexpected srfi-4 C Interface Change in 2.0.10
[not found] <mailman.201.1395244856.16207.guile-devel@gnu.org>
@ 2014-03-19 17:04 ` Daniel Llorens
2014-03-19 18:12 ` Mark H Weaver
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Llorens @ 2014-03-19 17:04 UTC (permalink / raw)
To: guile-devel
> Message: 2
> Date: Wed, 19 Mar 2014 10:22:40 -0400
> From: Barry Fishman <barry_fishman@acm.org>
> To: guile-devel@gnu.org
> Subject: Unexpected srfi-4 C Interface Change in 2.0.10
> Message-ID: <m37g7qxo7j.fsf@barry_fishman.acm.org>
> Content-Type: text/plain
>
> When building C interface code using scm_f32vector_writable_elements()
> in 2.0.10 and on the trunk I found:
>
> For a vector generated in guile with:
>
> (f32vector 0.25 0.25 0.25 1.0)
>
> I found in the C interface:
>
> scm_t_array_handle handle;
> size_t vlen, vinc;
> float *arrayp;
>
> arrayp = scm_f32vector_writable_elements(s_uvec, &handle,
> &vlen, &vinc)
>
> When I test vlen it now seems to contain the number of bytes (16)
> rather than the number of elements (4) in the f32vector.
>
> It was 4 in 2.0.9 and the guile trunk I built on Jan 8.
> It was 16 in 2.0.10 and the guile trunk I built on March 17.
> I assume it relates to the Feb 8 changes, where:
> (in commit dc65b88d839c326889618112c4870ad3a64e9446)
>
> *lenp = scm_c_bytevector_length (uvec) / width;
>
> and width is set to 1 in the macro:
>
> DEFINE_SRFI_4_C_FUNCS (F32, f32, float, 1);
This is a bug. Is there a test setup for the C interface?
The last argument of DEFINE_SRFI_4_C_FUNCS (1) is correct; that can be 1 or 2, because complex types use a pointer to real. We could use C99 complex types and get rid of it. Just cast the pointer for C<99 users (?)
The bug appeared in replacing the deprecated scm_uniform_vector_elements() with the bytevector functions. Generally lengths are computed with scm_i_array_element_type_sizes[] in uniform.c (e.g. see make_bytevector() in bytevector.c).
So the patch would be
*lenp = scm_c_bytevector_length (uvec) / (width * scm_i_array_element_type_sizes[ETYPE (TAG)]) ;
Actually I'd do
*lenp = scm_c_bytevector_length (uvec) / (width * sizeof(ctype))
(Both untested).
Regards,
Daniel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Unexpected srfi-4 C Interface Change in 2.0.10
2014-03-19 17:04 ` Daniel Llorens
@ 2014-03-19 18:12 ` Mark H Weaver
2014-03-19 21:43 ` Andy Wingo
0 siblings, 1 reply; 4+ messages in thread
From: Mark H Weaver @ 2014-03-19 18:12 UTC (permalink / raw)
To: Daniel Llorens; +Cc: guile-devel
Daniel Llorens <daniel.llorens@bluewin.ch> writes:
>> Message: 2
>> Date: Wed, 19 Mar 2014 10:22:40 -0400
>> From: Barry Fishman <barry_fishman@acm.org>
>> To: guile-devel@gnu.org
>> Subject: Unexpected srfi-4 C Interface Change in 2.0.10
>> Message-ID: <m37g7qxo7j.fsf@barry_fishman.acm.org>
>> Content-Type: text/plain
>>
>> When building C interface code using scm_f32vector_writable_elements()
>> in 2.0.10 and on the trunk I found:
>>
>> For a vector generated in guile with:
>>
>> (f32vector 0.25 0.25 0.25 1.0)
>>
>> I found in the C interface:
>>
>> scm_t_array_handle handle;
>> size_t vlen, vinc;
>> float *arrayp;
>>
>> arrayp = scm_f32vector_writable_elements(s_uvec, &handle,
>> &vlen, &vinc)
>>
>> When I test vlen it now seems to contain the number of bytes (16)
>> rather than the number of elements (4) in the f32vector.
>>
>> It was 4 in 2.0.9 and the guile trunk I built on Jan 8.
>> It was 16 in 2.0.10 and the guile trunk I built on March 17.
>> I assume it relates to the Feb 8 changes, where:
>> (in commit dc65b88d839c326889618112c4870ad3a64e9446)
>>
>> *lenp = scm_c_bytevector_length (uvec) / width;
>>
>> and width is set to 1 in the macro:
>>
>> DEFINE_SRFI_4_C_FUNCS (F32, f32, float, 1);
>
> This is a bug. Is there a test setup for the C interface?
>
> The last argument of DEFINE_SRFI_4_C_FUNCS (1) is correct; that can be 1 or 2, because complex types use a pointer to real. We could use C99 complex types and get rid of it. Just cast the pointer for C<99 users (?)
>
> The bug appeared in replacing the deprecated scm_uniform_vector_elements() with the bytevector functions. Generally lengths are computed with scm_i_array_element_type_sizes[] in uniform.c (e.g. see make_bytevector() in bytevector.c).
>
> So the patch would be
>
> *lenp = scm_c_bytevector_length (uvec) / (width * scm_i_array_element_type_sizes[ETYPE (TAG)]) ;
>
> Actually I'd do
>
> *lenp = scm_c_bytevector_length (uvec) / (width * sizeof(ctype))
This last one looks good to me. The length check 4 lines above this
also needs to be fixed:
if (!scm_is_bytevector (uvec) \
|| (scm_c_bytevector_length (uvec) % (width * sizeof(ctype)))) \
scm_wrong_type_arg_msg (NULL, 0, uvec, #tag "vector"); \
I guess it's time to release 2.0.11 :-/
Mark
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-03-19 21:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-19 14:22 Unexpected srfi-4 C Interface Change in 2.0.10 Barry Fishman
[not found] <mailman.201.1395244856.16207.guile-devel@gnu.org>
2014-03-19 17:04 ` Daniel Llorens
2014-03-19 18:12 ` Mark H Weaver
2014-03-19 21:43 ` Andy Wingo
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).