Please add FOREIGN-ARRAY-TO-LISP-SPECIALIZED

Bug #1740800 reported by Michał "phoe" Herda
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
CFFI
Fix Released
Wishlist
Luís Oliveira

Bug Description

CFFI's FOREIGN-ARRAY-TO-LISP always allocates vectors of element type T, even where it has all the required information to allocate more specialized arrays. This means that client code needs to do costly coercions if it wants to use CFFI converted vectors inside code that requires, for instance, octet vectors, even if the array type provided to FOREIGN-ARRAY-TO-LISP specifically states that the data is a vector of UNSIGNED-CHARs.

Backwards compatibility requires that FOREIGN-ARRAY-TO-LISP returns vectors of type T. Therefore, I request that a new function is added, that I roughly called FOREIGN-ARRAY-TO-LISP-SPECIALIZED, that automatically creates and returns arrays of properly specialized types.

Revision history for this message
Luís Oliveira (luismbo) wrote :

How about adding &REST MAKE-ARRAY-ARGUMENTS to FOREIGN-ARRAY-TO-LISP arglist then applying MAKE-ARRAY to that?

Revision history for this message
Michał "phoe" Herda (phoe-krk) wrote :

@luismbo Your proposition seems like a backwards compatible change, and also much cleaner than mine. I am in favor of that.

Revision history for this message
Luís Oliveira (luismbo) wrote :

Feel like opening a pull request with that change, a test and a manual update? :-)

Revision history for this message
Michał "phoe" Herda (phoe-krk) wrote :

I can try.

What kind of test suite should I run once I have made the change?

Revision history for this message
Luís Oliveira (luismbo) wrote :

IIRC these array functions are not being tested nor documented in the manual, so you'll have to create a new test in the cffi-tests suite. A simple test might be to use foreign-array-to-lisp to create a displaced array (or an adjustable array?) and then test that indeed such an array has been created. (I don't think it's easy to portably test with specialized arrays because not all Lisps support the same kind of specialized arrays.)

Revision history for this message
Michał "phoe" Herda (phoe-krk) wrote :

PR created at https://github.com/cffi/cffi/pull/128

Test results:

6 out of 322 total tests failed: FUNCALL.VARARGS.DOUBLE,
   DEFCFUN.VARARGS.FLOAT, DEFCFUN.VARARGS.DOUBLE, FSBV.WFO,
   FSBV.MAKEPAIR.1, FSBV.MAKEPAIR.2.
3 unexpected failures: FUNCALL.VARARGS.DOUBLE, DEFCFUN.VARARGS.FLOAT,
   DEFCFUN.VARARGS.DOUBLE.

Revision history for this message
Luís Oliveira (luismbo) wrote :

PR accepted. The unexpected failures happen because those 3 tests are sensitive to locale settings. :-(

Changed in cffi:
status: New → Fix Committed
importance: Undecided → Wishlist
assignee: nobody → Luís Oliveira (luismbo)
Luís Oliveira (luismbo)
Changed in cffi:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.