Support for querying foreign type designators

Bug #1881118 reported by Wilfredo Velázquez-Rodríguez
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
CFFI
Triaged
Wishlist
Unassigned

Bug Description

I am writing an API that uses CFFI underneath and have had the need to check if a designator for a foreign type (such as :uint8, or another user-defined type) actually designates a foreign type.

The most sane way I've found to do this is the following:

(defun foreign-type-p (foreign-type)
  (handler-case (and (cffi::parse-type foreign-type) t)
    (error () nil)))

I feel that there should be a better way to go about this

Luís Oliveira (luismbo)
Changed in cffi:
importance: Undecided → Wishlist
status: New → Triaged
Revision history for this message
Luís Oliveira (luismbo) wrote :

Sounds reasonable. Can you tell me a bit more about your API and why you need this feature?

Revision history for this message
Wilfredo Velázquez-Rodríguez (zulu-inuoe) wrote :

I'm building a Type Library (TLB) importer to auto-generate COM wrappers, but part of the yak-shaving is a small helper lib on top of CFFI to avoid repetitive & error-prone code and that's where I'm using this function right now
You can find the main code here:

https://github.com/Zulu-Inuoe/clom/blob/feature/tlb-import/src/cffi%2B.lisp

The TLDR is that it uses a custom declaration (via CLTL2) to define a variable's 'cffi-type' and I'm using

`(check-type type foreign-type)`

in order to sanity check and provide useful errors at macro-expansion

Revision history for this message
Stelian Ionescu (sionescu) wrote : Re: [Bug 1881118] Re: Support for querying foreign type designators

> Sounds reasonable. Can you tell me a bit more about your API and why you
> need this feature?

I use cffi::parse-type in the IOlib syscall wrappers: I need a generic way to determine the type size and signedness.

--
Stelian Ionescu

Revision history for this message
Wilfredo Velázquez-Rodríguez (zulu-inuoe) wrote :

Note I also make use of cffi::parse-type (as well as specializing on internal cffi classes) for my marshalling code - though I haven't ironed out all the kinks to it quite yet, and there's possibly a way I could accomplish it via CFFI's type translators.

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.