Support for querying foreign type designators

Bug #1881118 reported by Wilfredo Velázquez-Rodríguez on 2020-05-28
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
CFFI
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) on 2020-05-28
Changed in cffi:
importance: Undecided → Wishlist
status: New → Triaged
Luís Oliveira (luismbo) wrote :

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

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

> 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

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  Edit
Everyone can see this information.

Other bug subscribers