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

Declaring global variable of array of struct from native library. #5688

Closed
S-YOU opened this issue Feb 8, 2018 · 1 comment
Closed

Declaring global variable of array of struct from native library. #5688

S-YOU opened this issue Feb 8, 2018 · 1 comment

Comments

@S-YOU
Copy link

S-YOU commented Feb 8, 2018

Original C code has something like this

struct rte_eth_dev rte_eth_devices[32];

If I declare like this on lib

$rte_eth_devices : RteEthDev[32]

I got compile time error like this.

Module validation failed: Function return type does not match operand type of return inst!
  ret [32 x %"struct.LibDpdk::RteEthDev"]* %0
 [32 x %"struct.LibDpdk::RteEthDev"]
???
???
???
???
???
???
???
???

Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues

I could declare like RteEthDev*, but actual array is not allocated there, got invalid memory access later on.

Is there anything I am missing or is this a limitation?

@ysbaddaden
Copy link
Contributor

Does struct rte_eth_dev rte_eth_devices[32]; ends up being static, in C?

Maybe a workaround:

lib X
  $rte_eth_devices : RteEthDev
end

rte_eth_devices = Slice.new(pointerof(X.rte_eth_devices), 32)

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

No branches or pull requests

3 participants