Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNORE_DECLARATIONS: Usage? #5

Open
per42 opened this issue Sep 15, 2016 · 2 comments
Open

IGNORE_DECLARATIONS: Usage? #5

per42 opened this issue Sep 15, 2016 · 2 comments

Comments

@per42
Copy link

per42 commented Sep 15, 2016

I understand IGNORE_DECLARATIONS prunes typedefs from _fake_typedefs.h, which are anyway deliberately incorrect (fake). But that leaves my cython declarations with undeclared data types:

cdef extern from "components/offset_filter.h":
    ctypedef bool Comp_Success
    cdef struct If_Signal_Array:
        size_t count
        uint16_t items[1]

I still need those types to be declared. They can be dummy since the cython generated c code will include the correct headers. By removing the used types in IGNORE_DECLARATIONS, it almost works:

    ...
    ctypedef int size_t
    ctypedef _Bool bool
    ctypedef int uint16_t
    ...

_Bool needs to be replaced by bint, so I added filter for that in parse(). I noticed by accident that size_t is understood by Cython, but that is undocumented so probably best to typedef to int

    ...
    ctypedef int size_t
    ctypedef bint bool
    ctypedef int uint16_t
    ...

An alternative is to manually prepend the generated pxd with:

cdef extern:
    ctypedef bint _Bool

It seems I am missing some step here. What is the intended usage for dealing with standard types?

@tarruda
Copy link
Owner

tarruda commented Sep 15, 2016

It seems I am missing some step here. What is the intended usage for dealing with standard types?

The idea is that the standard types are already understood by cython, which is why IGNORE_DECLARATION exists.

@per42
Copy link
Author

per42 commented Sep 15, 2016

That makes perfect sense. I am new on Cython, but as far as I can tell from the documentation, these types are not standard Cython types. Perhaps it depends on the build, like size_t was available for me.

C:\Users\per.rosengren\code\zforce-application-simulator>\Anaconda2_32\python.exe setup.py build_ext -i --compiler=mingw32
Compiling zforce_app_sim/components/offset_filter.pyx because it changed.
[1/1] Cythonizing zforce_app_sim/components/offset_filter.pyx

Error compiling Cython file:
------------------------------------------------------------
...
cdef extern from "components/offset_filter.h":

    ctypedef bool Comp_Success
            ^
------------------------------------------------------------

zforce_app_sim\api\components\bar.pxd:3:13: 'bool' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
        If_Signals_signalCapacity
        If_TrackedObject_Array_capacity

    cdef struct If_Signal_Array:
        size_t count
        uint16_t items[1]
       ^
------------------------------------------------------------

zforce_app_sim\api\components\bar.pxd:16:8: 'uint16_t' is not a type identifier

With the pyx:

cdef extern from "components/offset_filter.h":

    ctypedef bool Comp_Success

    ctypedef void* Comp_Instance

    cdef enum If_Config:
        If_SyncedScan_programCapacity
        If_SyncedScan_jobCapacity
        If_Frame_syncedCapacity
        If_Signals_signalCapacity
        If_TrackedObject_Array_capacity

    cdef struct If_Signal_Array:
        size_t count
        uint16_t items[1]

    cdef struct If_Signals:
        If_Signal_Array signal
        uint_fast16_t timestamp

    Comp_Success Comp_SignalFilter_SignalsIn(Comp_Instance instance, If_Signals* signal)

    Comp_Success Comp_SignalFilter_SignalsOut(Comp_Instance instance, If_Signals* signal)

    void Comp_OffsetFilter_Run(Comp_Instance instance)

    If_Signal_Array* Comp_OffsetFilter_signalOffsets(Comp_Instance instance)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants