[pypy-dev] Fwd: cffi dlopen
Roshan Cherian
cherian.rosh at gmail.com
Fri Sep 18 10:02:13 CEST 2015
Hi Armin/Maciej,
Thanks for the reply, following the code sample I wrote up the following:
from cffi import FFI
ffi = FFI()
ffi.set_source("_ical_cffi_ext",
""" // passed to the real C compiler
#include <libical/ical.h>
""",
include_dirs=['./include'], # where ical.h is
libraries=['ical'],
library_dirs=['./lib'],) # or a list of libraries to link with
ffi.cdef(""" // some declarations from the man page
typedef struct icalcomponent_impl icalcomponent;
typedef struct icalproperty_impl icalproperty;
typedef ... icalparameter;
typedef struct icalvalue_impl icalvalue;
typedef ... icaltimezonechange; //really typedef struct
_icaltimezonechange
icaltimezonechange;
struct _icaltimezonechange {
int utc_offset;
int prev_utc_offset;
int year; /**< Actual year, e.g. 2001. */
int month; /**< 1 (Jan) to 12 (Dec). */
int day;
int hour;
int minute;
int second;
int is_daylight;
};
""")
if __name__ == "__main__":
ffi.compile()
_icaltimezonechange is opaque as its in src/libical/icaltimezone.c a c file
and not in in ical.h. However this struct is required for my purpose.
However when it compiles I do get errors like:
_ical_cffi_ext.c:455: error: dereferencing pointer to incomplete type
_ical_cffi_ext.c:457: error: invalid use of undefined type 'struct
_icaltimezonechange'
_ical_cffi_ext.c:458: error: dereferencing pointer to incomplete type
_ical_cffi_ext.c:468: error: invalid application of 'sizeof' to incomplete
type 'struct _icaltimezonechange'
_ical_cffi_ext.c:468: error: initializer element is not constant
_ical_cffi_ext.c:468: error: (near initialization for
'_cffi_struct_unions[2].alignment')
Can I know what should be done for these cases?
Thanks,
-Roshan
On Tue, Sep 15, 2015 at 8:17 AM, Armin Rigo <arigo at tunes.org> wrote:
> Hi Roshan,
>
> On Tue, Sep 15, 2015 at 5:01 PM, Roshan Cherian <cherian.rosh at gmail.com>
> wrote:
> >>>>> libical = ffi.dlopen(ctypes.util.find_library('ical'))
> >>>>>
> libical.ical_set_unknown_token_handling_setting(libical.ICAL_ASSUME_IANA_TOKEN)
> >
> > I get an error: AttributeError: ical_set_unknown_token_handling_setting
>
> This means the library file was found, but it doesn't contain any
> symbol of the name "ical_set_unknown_token_handling_setting". It may
> be because such a name is actually a macro. In that case you can't
> use ffi.dlopen().
>
> You should look at ffi.set_source() instead (and *not* ffi.verify();
> Maciej probably mentioned this by mistake, it is now called
> set_source()).
>
> > I haven't tried out ffi.verify I am not sure how to load a shared lib
> using
> > ffi.verify, I am sorry if my understanding is wrong.
>
> See
> http://cffi.readthedocs.org/en/latest/overview.html#real-example-api-level-out-of-line
> . In your case you need:
>
> ffi.set_source("_ical_cffi",
> """ #include <ical.h>
> """,
> include_dirs=['./include'], # or where ical.h is
> libraries=['ical'],
> library_dirs=['./lib'], # or where libical.so is
> )
>
> You also need the same ffi.cdef() as you use now, and ffi.compile() as
> shown in the example. The ffi.cdef() can use the syntax ``...``
> (dot-dot-dot) in many places when it is combined with
> ffi.set_source(). See the rest of the documentation section for more.
>
>
> A bientôt,
>
> Armin.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20150918/07c5a900/attachment.html>
More information about the pypy-dev
mailing list