Complex number support
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 3k
- Forks
- 386
- Avg merge
- 1h 43m
- Merged PRs (30d)
- 1
Description
I am using cbindgen v0.28.0 to create bindings to Rust functions that have complex arguments. For example,
#[no_mangle]
pub extern "C" fn channelizer_analysis_bank_2x(ptr: *mut Channelizer,
size: u32,
in_ptr: *const Complex32,
out_ptr: *mut Complex32) -> usize
cbindgen generates the following header file.
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>
struct Channelizer;
using Complex32 = Complex<float>;
extern "C" {
uintptr_t channelizer_analysis_bank_2x(Channelizer *ptr,
uint32_t size,
const Complex32 *in_ptr,
Complex32 *out_ptr);
g++ produces the following errors when trying to compile.
In file included from ./apps/chan_test.c:5:
../rust/lib/rust_channelizer/channelizer/rust_chan_bindings.h:9:19: error: ‘Complex’ does not name a type
9 | using Complex32 = Complex<float>;
| ^~~~~~~
../rust/lib/rust_channelizer/channelizer/rust_chan_bindings.h:22:46: error: ‘Complex32’ does not name a type
22 | const Complex32 *in_ptr,
| ^~~~~~~~~
../rust/lib/rust_channelizer/channelizer/rust_chan_bindings.h:23:40: error: ‘Complex32’ has not been declared
23 | Complex32 *out_ptr);
| ^~~~~~~~~
It appears the the generated header file has the following errors:
- Missing
#include <complex> using Complex32 = Complex<float>;should beusing Complex32 = complex<float>;
Applying these changes to the generate header file, I can successfully compile.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with cbindgen v0.28.0 using the Rust function signature shown and inspect the generated C++ header. Check the complex-number include and the generated Complex32 alias, then compile the header with g++ to confirm the corrected output builds successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100