Working on the ARM port (kudos to Snark), which has, unlike x86, unsigned 
char, we stumbled upon several places in Sage library (in Cython code) 
where char type was used for (essentially) operating on bit strings.

One example (in Sage 4.8) is computing pickle for a dense Z_2-matrix in 
matrix/Matrix_mod2_dense.pyx (line 1750):

cdef char *buf = <char*>gdImagePngPtr(im, &size) 
data = [buf[i] for i in range(size)]

and then data (list of Python ints) goes into the pickle, resulting in a 
plaform-dependent pickle (as on x86 there are signed bytes, i.e. -128..127, 
and on ARM unsigned, i.e. 0..255).

Another example is in graphs/graph_decompositions/vertex_separation.pyx, 
where
a similar abuse of char type is taking place 
(spotted<https://groups.google.com/d/msg/sage-devel/2HwMYI1CY98/RmyuXKh9WFUJ>by 
Willem-Jan).

Volker 
says<https://groups.google.com/d/msg/sage-devel/2HwMYI1CY98/9vu2xkBynDoJ>we 
should "use C99 integer types if the code assumes signedness and/or a 
particular bit width for "char". Just include inttypes.h (C) or cinttypes 
(C++), then int8_t is a signed 8-bit integer and uint8_t is an unsigned 
8-bit integer."

Thus, if you are aware of other places where char is abused in a similar 
fashion, please fix them!
Probably it's got to be mentioned in the developer's guide, too.

References:
https://groups.google.com/d/msg/sage-devel/2HwMYI1CY98/j0L5xvhnPSIJ
https://groups.google.com/d/msg/sage-devel/_OuLJdHk-So/ZG4jpbIG5h0J

Dima


-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to