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

no method value(::CLPackedAttr) #224

Closed
vchuravy opened this issue Feb 24, 2019 · 4 comments · Fixed by #278
Closed

no method value(::CLPackedAttr) #224

vchuravy opened this issue Feb 24, 2019 · 4 comments · Fixed by #278
Labels
record struct/union/enum issues

Comments

@vchuravy
Copy link
Collaborator

vchuravy commented Feb 24, 2019

ERROR: LoadError: MethodError: no method matching value(::CLPackedAttr)
Closest candidates are:
  value(!Matched::CLEnumConstantDecl) at /home/vchuravy/.julia/packages/Clang/NONKM/src/cursor.jl:246
Stacktrace:
 [1] wrap!(::DefaultContext, ::CLEnumDecl) at /home/vchuravy/.julia/packages/Clang/NONKM/src/wrap_c.jl:97
 [2] run(::WrapContext) at /home/vchuravy/.julia/packages/Clang/NONKM/src/compat.jl:122
 [3] top-level scope at none:0

It seems to be just:

typedef enum {
    /* Operation completed successfully */
    UCS_OK                         =   0,

    /* Operation is queued and still in progress */
    UCS_INPROGRESS                 =   1,

    /* Failure codes */
    UCS_ERR_NO_MESSAGE             =  -1,
    UCS_ERR_NO_RESOURCE            =  -2,
    UCS_ERR_IO_ERROR               =  -3,
    UCS_ERR_NO_MEMORY              =  -4,
    UCS_ERR_INVALID_PARAM          =  -5,
    UCS_ERR_UNREACHABLE            =  -6,
    UCS_ERR_INVALID_ADDR           =  -7,
    UCS_ERR_NOT_IMPLEMENTED        =  -8,
    UCS_ERR_MESSAGE_TRUNCATED      =  -9,
    UCS_ERR_NO_PROGRESS            = -10,
    UCS_ERR_BUFFER_TOO_SMALL       = -11,
    UCS_ERR_NO_ELEM                = -12,
    UCS_ERR_SOME_CONNECTS_FAILED   = -13,
    UCS_ERR_NO_DEVICE              = -14,
    UCS_ERR_BUSY                   = -15,
    UCS_ERR_CANCELED               = -16,
    UCS_ERR_SHMEM_SEGMENT          = -17,
    UCS_ERR_ALREADY_EXISTS         = -18,
    UCS_ERR_OUT_OF_RANGE           = -19,
    UCS_ERR_TIMED_OUT              = -20,
    UCS_ERR_EXCEEDS_LIMIT          = -21,
    UCS_ERR_UNSUPPORTED            = -22,
    UCS_ERR_REJECTED               = -23,

    UCS_ERR_FIRST_LINK_FAILURE     = -40,
    UCS_ERR_LAST_LINK_FAILURE      = -59,
    UCS_ERR_FIRST_ENDPOINT_FAILURE = -60,
    UCS_ERR_LAST_ENDPOINT_FAILURE  = -79,
    UCS_ERR_ENDPOINT_TIMEOUT       = -80,

    UCS_ERR_LAST                   = -100
} __attribute__((packed)) ucs_status_t ;

@Gnimuc
Copy link
Member

Gnimuc commented Feb 25, 2019

Since __attribute__(xxx) is not supported by Julia, one might need to wrap this kinda structures manually with additional dummy padding fields to ensure the correct alignement. Indeed, wrap! should be able to catch __attribute__ keywords and print warning messages instead of throwing errors.

This is a "packed" enum, no padding is needed, so maybe we could make wrap! work on this special case.
EDIT: I'm not sure whether Julia compiler will add padding between fields in the same way as C or not. But this enum only has integer fields which seems to be compatible with Julia.

@Gnimuc
Copy link
Member

Gnimuc commented Feb 25, 2019

It looks like libclang provides a way to get the fieldoffset info:

function clang_Type_getOffsetOf(T, S)
ccall((:clang_Type_getOffsetOf, libclang), Clonglong, (CXType, Cstring), T, S)
end
function clang_Cursor_getOffsetOfField(C)
ccall((:clang_Cursor_getOffsetOfField, libclang), Clonglong, (CXCursor,), C)
end

maybe we could write a macro/function for constructing structs with dummy padding fields automatically inserted?

@vchuravy
Copy link
Collaborator Author

I think a packed enum means that it will be only using Int8 in this case? But I am not a 100% on all the C-semantics.

In any case Clang.jl should at least ignore it and print a warning.

@ihnorton
Copy link
Collaborator

I'm not sure whether Julia compiler will add padding between fields in the same way as C or not. But this enum only has integer fields which seems to be compatible with Julia.

Yes, it has to respect the platform alignment rules (e.g. base reflects a bunch of structs from libraries like libuv that would be very broken otherwise).

maybe we could write a macro/function for constructing structs with dummy padding fields automatically inserted?

The only issue there is that the output will probably be wrong on systems where ptrdiff_t is 32-bit (ARM and x86 Windows; not sure if Julia still even supports the latter). I don't know a good solution to that... Ideally this would be pushed down in to the compiler, but it is enough of an edge-case that everybody has obviously gotten by without it for this long, using https://github.com/Keno/StructIO.jl and StrPack, etc.

I think a packed enum means that it will be only using Int8 in this case? But I am not a 100% on all the C-semantics.

IIUC yes, from a quick read of GCC's page about it -- should pack to the smallest type which can represent the range. That said, this is about the point where I might start thinking about C helper shims to get the as-compiled size, especially if you are going to be using UCX on any "interesting" hardware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
record struct/union/enum issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants