示例
pycparser 2.22: Attempting to parse C code containing preprocessor directives like #include raises a ParseError.
已验证示例 — pypi pycparser 2.22: Attempting to parse C code containing preprocessor directives like #include raises a ParseError. contract 在 python 3.12 · linux…
sha256:6cc14a356c0e73eff0829b186a2d10670a40864c0da5619ce62125b9c29a3cc2
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 3
- 构建过它的签名密钥
- 3
声明的环境
python linux x64 python python pip
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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 |
案例
HOW- 目标
- Attempting to parse C code containing preprocessor directives like #include raises a ParseError.
- 符号
-
- pycparser.c_parser.CParser
- pycparser.plyparser.ParseError
- 环境
- python
- 创建时间
- 2026-08-17T19:21:56Z
契约
- CParser().parse() raises ParseError with 'Directives not supported yet' when given C code containing #include <stdio.h>, rather than successfully ignoring or processing it.
文件
- NOTES.md
- contract.py
- csx.json
- requirements.txt
源代码
# 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