LukeMathWalker / LukeMathWalker/cheadergen

Structs with same name in different modules generate corrupt C header

Open
#27 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

diagnostics
Dominant language
Rust
Stars
34
Forks
4
PR merge metrics
No merged PRs in 30d

Description

```
mod m1 {
typedef struct { int a; int b; } Foo;
}

mod m2 {
typedef struct { int c; } Foo;
}

int foo_user(m1::Foo f1, m2::Foo f2) {

}
```
This is CO2 code, but I would expect it to happen in Rust as well.

Actual output:
```C
typedef struct Foo {
int32_t a;
int32_t b;
} Foo;

typedef struct Foo {
int32_t c;
} Foo;

int32_t foo_user(struct Foo f1, struct Foo f2);
```
Expected output:
```C
typedef struct m1_Foo {
int32_t a;
int32_t b;
} m1_Foo;

typedef struct m2_Foo {
int32_t c;
} m2_Foo;

int32_t foo_user(struct m1_Foo f1, struct m2_Foo f2);
```
Another valid option is to raise error and force the user to rename one of the structs using an attribute. But I guess I would prefer the auto disambiguation.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the shown CO2 example and trace the header-generation entry point that emits both Foo definitions. Compare the generated C header with the expected m1_Foo and m2_Foo names, then determine how the issue should be handled and verify that the two module-scoped structs no longer collide.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.