Menu

#94 (typep x (type-of x)) must => T (FFI)

closed-remind
ffi (23)
5
2002-03-15
2002-03-12
No

[71]> (type-of #'c-self)
FFI:FOREIGN-FUNCTION
[72]> (typep #'c-self *)
*** - TYPEP: invalid type specification
FFI:FOREIGN-FUNCTION

This is in violation to the CLHS:
http://www.xanalys.com/software_tools/reference/HyperSp
ec/Body/f_tp_of.htm#type-of

"2. For all objects, (typep object (type-of object))
returns true. Implicit in this is that type specifiers
which are not valid for use with typep, such as the
list form of the function type specifier, are never
returned by type-of."

The following are currently lost situations:

1. I cannot signal type-error with FOREIGN-FUNCTION, as
the type ought to be something that the system
understands.

2. the CHECK-TYPE macro cannot be used to ensure
something is a foreign function.

See:
2. Break [74]> (let ((f #'c-self)) (check-type f
function))
NIL
2. Break [74]> (let ((f #'c-self)) (check-type f
ffi:foreign-function))
*** - TYPEP: invalid type specification
FFI:FOREIGN-FUNCTION
4. Break [77]> #'c-self
#<FOREIGN-FUNCTION "C_self" #x00401037>

Discussion

  • Sam Steingold

    Sam Steingold - 2002-03-12
    • assigned_to: haible --> sds
     
  • Sam Steingold

    Sam Steingold - 2002-03-14
    • status: open --> closed-fixed
     
  • Sam Steingold

    Sam Steingold - 2002-03-14

    Logged In: YES
    user_id=5735

    thank you for your bug report.
    the bug has been fixed in the CVS tree.
    you can either wait for the next release (recommended)
    or check out the current CVS tree (see http://clisp.cons.org\)
    and build CLISP from the sources (be advised that between
    releases the CVS tree is very unstable and may not even build
    on your platform).

     
  • Jörg Höhle

    Jörg Höhle - 2002-03-15
    • status: closed-fixed --> open-remind
     
  • Jörg Höhle

    Jörg Höhle - 2002-03-15

    Logged In: YES
    user_id=377168

    The fix is not complete, as it doesn't show that
    FOREIGN-FUNCTION is a subtype of function: integration into
    the type system is incomplete.
    I have a patch that I'll send in.
    [3]> (typep #'c-self 'function)
    T
    [4]> (subtypep 'ffi:foreign-function 'function)
    NIL ;
    NIL
    [5]> (subtypep 'function 'ffi:foreign-function)
    NIL ;
    T
    [8]> (type-of #'c-self)
    FFI:FOREIGN-FUNCTION

     
  • Jörg Höhle

    Jörg Höhle - 2002-03-15
    • status: open-remind --> closed-remind
     
  • Jörg Höhle

    Jörg Höhle - 2002-03-15

    Logged In: YES
    user_id=377168

    Now
    (subtypep 'ffi:foreign-function 'function)
    T ;
    T
    while doing so I was so free as to re-establish alphabetical
    ordering among calls to DEF-ATOMIC-TYPE.

    The patch is against CLISP-2.28, not current CVS.
    *** orig/type.lisp Sat Feb 23 06:19:46 2002
    --- src/type.lisp Fri Mar 15 13:38:38 2002
    ***************
    *** 231,236 ****
    --- 231,251 ----
    )
    (def-atomic-type FIXNUM fixnump)
    (def-atomic-type FLOAT floatp)
    + ; foreign1.lisp is loaded after this file,
    + ; so the FFI symbols are not external yet.
    + #+FFI
    + (def-atomic-type FFI::FOREIGN-ADDRESS
    + (lambda (x) (eq 'ffi::foreign-address (type-of x))))
    + #+FFI
    + (def-atomic-type FFI::FOREIGN-FUNCTION
    + (lambda (x) (eq 'ffi::foreign-function (type-of x))))
    + #+FFI
    + (def-atomic-type FFI::FOREIGN-VARIABLE
    + (lambda (x) (eq 'ffi::foreign-variable (type-of x))))
    + ; See lispbibl.d (#define FOREIGN) and predtype.d
    (TYPE-OF):
    + #+(or UNIX FFI AMIGA DIR-KEY)
    + (def-atomic-type FOREIGN-POINTER
    + (lambda (x) (eq 'foreign-pointer (type-of x))))
    (def-atomic-type FUNCTION functionp)
    (def-atomic-type CLOS:GENERIC-FUNCTION
    clos::generic-function-p)
    (def-atomic-type HASH-TABLE hash-table-p)
    ***************
    *** 1116,1122 ****
    READTABLE SYMBOL)
    (no)
    )
    ! ((CLOS:GENERIC-FUNCTION COMPILED-FUNCTION)
    (if (eq type2 'FUNCTION) (yes) (no))
    )
    (CLOS:STANDARD-GENERIC-FUNCTION
    --- 1131,1137 ----
    READTABLE SYMBOL)
    (no)
    )
    ! ((CLOS:GENERIC-FUNCTION COMPILED-FUNCTION #+FFI
    FFI::FOREIGN-FUNCTION)
    (if (eq type2 'FUNCTION) (yes) (no))
    )
    (CLOS:STANDARD-GENERIC-FUNCTION

     

Log in to post a comment.