Skip to content

Printing a struct and function type signatures? #12

@billtohara

Description

@billtohara

Is it possible to print the signature of a loaded function? For example, gettimeofday is tricky because the arguments are pointers to structs. Is it possible to get this signature back:

int gettimeofday(struct timeval *restrict tp, void *restrict tzp);

And even better that timeval is this? (taken from sys/time.h)

struct timeval {
             time_t       tv_sec;   /* seconds since Jan. 1, 1970 */
             suseconds_t  tv_usec;  /* and microseconds */
     };

I get stuck in not knowing how to proceed from the "QualType" for the arguments.

   >>> import pydffi
   >>> FFI = pydffi.FFI()
   >>> CU = FFI.cdef("#include <sys/time.h>")
   >>> CU.funcs.gettimeofday.type().returnType.kind
   BasicKind.Int
   >>> CU.funcs.gettimeofday.type().params[0]
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
   TypeError: Unable to convert function return value to a Python type! The signature was
   	(arg0: pydffi.FunctionType) -> List[dffi::QualType].   

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions