Beispiel
pycparser 2.22: Attempting to parse C code containing preprocessor directives like #include raises a ParseError.
Verifiziertes Beispiel für pypi pycparser 2.22: Attempting to parse C code containing preprocessor directives like #include raises a ParseError. Der Vertrag…
sha256:6cc14a356c0e73eff0829b186a2d10670a40864c0da5619ce62125b9c29a3cc2
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 3
- Signaturschlüssel, die es gebaut haben
- 3
Deklarierte Umgebung
python linux x64 python python pip
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| python 3.12 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-17 |
| python 3.12 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-18 |
| python 3.12 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1python:3.12-slim@sha256:09f7da3bc104… |
2026-09-08 |
Fall
HOW- Ziel
- Attempting to parse C code containing preprocessor directives like #include raises a ParseError.
- Pakete
- Symbole
-
- pycparser.c_parser.CParser
- pycparser.plyparser.ParseError
- Umgebung
- python
- Erstellt
- 2026-08-17T19:21:56Z
Contract
- CParser().parse() raises ParseError with 'Directives not supported yet' when given C code containing #include <stdio.h>, rather than successfully ignoring or processing it.
Dateien
- NOTES.md
- contract.py
- csx.json
- requirements.txt
Quelltext
# pycparser Preprocessor Directives
When querying for `pycparser` behaviour regarding C preprocessor macros and includes, the known solution (`sha256:3c5ca6f4d0fbebc7e9f426b8ff85289533a86a2af0b05839306773534fb7b397`) demonstrated basic C99 source parsing into an AST, node traversal, formatting, and `ParseError` on syntax errors.
However, a common trap is assuming `pycparser` will automatically handle or skip standard C preprocessor directives such as `#include`. Since it is a pure C parser without an integrated preprocessor, attempting to parse code with an `#include` directive (or other macros) does not gracefully skip it or raise a generic syntax error.
Instead, at release `2.22`, `CParser().parse()` explicitly raises a `ParseError` with the message "Directives not supported yet". This loudly breaks any code that naively passes unpreprocessed C headers to the library expecting them to be ignored.
from pycparser import c_parser
from pycparser.plyparser import ParseError
code = """#include <stdio.h>
int main() {
printf("Hello");
return 0;
}
"""
parser = c_parser.CParser()
try:
parser.parse(code)
assert False, "Expected ParseError but parsing succeeded"
except ParseError as e:
assert "Directives not supported yet" in str(e), f"Unexpected error message: {e}"
{"case":{"believed":"pycparser can automatically skip or handle standard preprocessor directives like #include when parsing C source.","caseId":"case:sha256:96be3970aced415d2cad4c1a0be05a4a81fae3da2ed2304ce0436647d3671ad2","contract":["CParser().parse() raises ParseError with 'Directives not supported yet' when given C code containing #include \u003cstdio.h\u003e, rather than successfully ignoring or processing it."],"goal":"Attempting to parse C code containing preprocessor directives like #include raises a ParseError.","kind":"HOW","packages":["pkg:pypi/pycparser@2.22"],"schemaVersion":1,"symbols":["pycparser.c_parser.CParser","pycparser.plyparser.ParseError"]},"contractCommand":["python","contract.py"],"environment":{"arch":"x64","ecosystem":"pypi","executionContext":"python","language":"python","os":"linux","packageManager":"pip","runtime":"python","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/pycparser@2.22"],"schemaVersion":1,"symbols":["pycparser.c_parser.CParser","pycparser.plyparser.ParseError"],"verifierAdapter":"python@1"}
pycparser==2.22