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

NIFC cannot handle stat #423

Closed
Araq opened this issue Jan 29, 2025 · 0 comments
Closed

NIFC cannot handle stat #423

Araq opened this issue Jan 29, 2025 · 0 comments
Assignees

Comments

@Araq
Copy link
Member

Araq commented Jan 29, 2025

NIFC wraps every array in its own struct so that we get the correct copy semantics from C. This is generally a good idea but fails for code like:

type
  Dirent* {.importc: "struct dirent", header: "<dirent.h>".} = object
    d_type* {.importc: "d_type".}: uint8
    d_name* {.importc: "d_name".}: array[DirNameLen, char]

The array d_name is not under NIFC's control and has no such struct wrapper. NIFC needs to special case the access obj.d_name in the AtC case:

# genexprs.nim
  ...
  of AtC:
    let (a, i) = sons2(t, n)
    genx c, t, a
    c.add Dot
    c.add "a"
    c.add BracketLe
    genx c, t, i
    c.add BracketRi
demotomohiro added a commit to demotomohiro/nif that referenced this issue Jan 29, 2025
demotomohiro added a commit to demotomohiro/nif that referenced this issue Jan 30, 2025
Araq pushed a commit that referenced this issue Jan 31, 2025
* NIFC: Implement #423 only for the simplest case

* Implement #423 only for importC struct fields

* Move isImportC to nifc/typenav.nim

* Fix test code so that it produces valid C code
@Araq Araq closed this as completed Jan 31, 2025
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