fix(cl): preserve null callback arguments in automatically detected forwarding macros

Chiusa
#1,134 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Una pull request collegata è già stata integrata.

  • #1147 di @MeteorsLiu — chiusa senza merge
  • #1151 di @xushiwei — integrata

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c, go, macos
Ambito
tooling

Direzione di ricerca

Start in cl/macrofunc.go at doCompileAutoMacroFunc, where detected macro arguments reach cb.Val(arg.v), and inspect the fropen/fwopen declarations from the configured macOS headers. Reproduce with GOOS=darwin GOARCH=arm64 llcppg ./generated ./source. Done means automatic generation preserves the null callback arguments or rejects the unsupported macro shape cleanly, without generating an invalid call or panicking; add a focused regression case for this macro form.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Automatic forwarding-macro generation panics on macOS fropen, which passes integer zero as three null callback arguments to funopen.

Reproduction

Use a source Go module requiring github.com/goplus/lib v0.7.0, with this configuration in source/llcppg.cfg:

{
  "Name": "libc",
  "Language": "c",
  "Dir": "$GOOS-$GOARCH/include",
  "Files": [
    "stdio.h"
  ],
  "FailFast": 0,
  "IgnoreInline": true
}

Put the selected inputs under source/darwin-arm64/include, with the macOS 14.0 SDK headers available there where included. Leave Stdlib unset, and run:

GOOS=darwin GOARCH=arm64 llcppg ./generated ./source

The relevant SDK declarations are:

FILE *funopen(const void *,
              int (*)(void *, char *, int),
              int (*)(void *, const char *, int),
              fpos_t (*)(void *, fpos_t, int),
              int (*)(void *));
#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)

The SDK also annotates these callback parameters as nullable. Its native header was not edited for the reproduction.

Actual result

Generation exits 2. The diagnostic reports an untyped int passed to a generated func(...) c.Int parameter while generating fropen.

In cl/macrofunc.go:doCompileAutoMacroFunc, these constant arguments reach cb.Val(arg.v) unchanged. The C integer constant 0 is valid as a null function pointer in this argument context; emitting it as an ordinary Go integer loses that meaning.

Expected behavior

Preserve the C null-callback semantics for the detected macro. If this macro shape is outside the supported subset, reject its automatic conversion cleanly instead of starting an invalid Go call and panicking.

Related #1109 lists pointer constants such as NULL and (void *)0 as an open question. This is a reproduced implementation failure on integer literal 0 accepted by the current automatic detection path, rather than a proposal for a new macro API or C wrapper.

Environment

Reproduced on macOS/arm64 with LLVM/libclang 22.1.8, LLGo 1.0.9 and github.com/goplus/lib v0.7.0. The relevant installed generator sources were checked byte-for-byte against current main 90bd72cf. SDK-dependent cases use macOS 14.0 headers. These are generation-stage results, not cross-platform or ABI certification.

Lingua principale
Go
Stelle
40
Fork
13
Merge medio
2h 48m
PR unite (30g)
109

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di goplus/llcppg

Tutte le issue di goplus/llcppg

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.