How to wrap C function taking int64_t?

1,254 views
Skip to first unread message

Jeff

unread,
Aug 17, 2010, 2:03:54 PM8/17/10
to cython-users
I'm trying to wrap a C library which has a number of functions which
take an int64_t parameter. This is a piece of my pxd file wrapping
the C library's header:

from stdio cimport *
from stdlib cimport *
from stdint cimport *

cdef extern from "ga.h":
void GA_Abs_value_patch64(int g_a, int64_t *lo, int64_t *hi)

But this produces errors such as "'int64_t' is not a type identifier"
and "undeclared name not builtin: int64_t".
I need this to work on 32- and 64-bit platforms, so... did I miss
something obvious? Thanks.

Ken Watford

unread,
Aug 17, 2010, 2:14:05 PM8/17/10
to cython...@googlegroups.com
Cython 0.12 doesn't have a stdint.pxd file, so unless you've defined
it somewhere you won't get any types out of it.

If you don't mind NumPy being one of your requirements, you can do:

from numpy cimport int64_t

Lisandro Dalcin

unread,
Aug 17, 2010, 2:31:47 PM8/17/10
to cython...@googlegroups.com
On 17 August 2010 15:14, Ken Watford <kwat...@gmail.com> wrote:
> Cython 0.12 doesn't have a stdint.pxd file, so unless you've defined
> it somewhere you won't get any types out of it.
>
> If you don't mind NumPy being one of your requirements, you can do:
>
> from numpy cimport int64_t
>

Please do not top-post...

> On Tue, Aug 17, 2010 at 2:03 PM, Jeff <jeff....@pnl.gov> wrote:
>> I'm trying to wrap a C library which has a number of functions which
>> take an int64_t parameter.  This is a piece of my pxd file wrapping
>> the C library's header:
>>
>> from stdio cimport *
>> from stdlib cimport *
>> from stdint cimport *
>>
>> cdef extern from "ga.h":
>>    void GA_Abs_value_patch64(int g_a, int64_t *lo, int64_t *hi)
>>
>> But this produces errors such as "'int64_t' is not a type identifier"
>> and "undeclared name not builtin: int64_t".
>> I need this to work on 32- and 64-bit platforms, so... did I miss
>> something obvious?  Thanks.
>

In cython-devel (to be released VERY soon) there is fairly good
support for C99 integrals:
http://hg.cython.org/cython-devel/file/tip/Cython/Includes/libc/stdint.pxd

So, you just need to write:

from libc.stdint cimport int64_t


--
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169

Ken Watford

unread,
Aug 17, 2010, 2:50:57 PM8/17/10
to cython...@googlegroups.com
On Tue, Aug 17, 2010 at 2:31 PM, Lisandro Dalcin <dal...@gmail.com> wrote:
> On 17 August 2010 15:14, Ken Watford <kwat...@gmail.com> wrote:
>> Cython 0.12 doesn't have a stdint.pxd file, so unless you've defined
>> it somewhere you won't get any types out of it.
>>
>> If you don't mind NumPy being one of your requirements, you can do:
>>
>> from numpy cimport int64_t
>>
>
> Please do not top-post...

Sorry about that. My heuristic was:
if list is on Google Groups: top post
else: bottom post

Will have to pay more attention to that.

Robert Bradshaw

unread,
Aug 17, 2010, 6:59:00 PM8/17/10
to cython...@googlegroups.com

No problem, unless you've been on this list a while you wouldn't know.

As for the original question, you could also declare it directly, just
as we will in the next release:

cdef extern from "stdint.h":
ctypedef signed int int64_t

http://hg.cython.org/cython-devel/file/2bac73e04f8b/Cython/Includes/libc/stdint.pxd#l1

- Robert

Reply all
Reply to author
Forward
0 new messages