Skip to content

Commit f810322

Browse files
committed
Fix the parsing of SDL 2.0.16 headers.
SDL event padding is now derived from the compiler. SDL_DEPRECATED is now ignored correctly. Fixes #110
1 parent a0fca3a commit f810322

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

parse_sdl2.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
RE_DEFINE_TRUNCATE = re.compile(r"(#define\s+\w+\s+).+$", flags=re.DOTALL)
2323
RE_TYPEDEF_TRUNCATE = re.compile(r"(typedef\s+\w+\s+\w+)\s*{.*\n}(?=.*;$)", flags=re.DOTALL | re.MULTILINE)
2424
RE_ENUM_TRUNCATE = re.compile(r"(\w+\s*=).+?(?=,$|})(?![^(']*\))", re.MULTILINE | re.DOTALL)
25+
RE_EVENT_PADDING = re.compile(r"Uint8 padding\[[^]]+\];", re.MULTILINE | re.DOTALL)
2526

2627

2728
def get_header(name: str) -> str:
@@ -76,6 +77,7 @@ def parse(header: str, NEEDS_PACK4: bool) -> Iterator[str]:
7677

7778
typedef = typedef.replace("SDLCALL", " ")
7879
typedef = typedef.replace("SDL_AUDIOCVT_PACKED ", "")
80+
typedef = RE_EVENT_PADDING.sub("Uint8 padding[...];", typedef)
7981

8082
if NEEDS_PACK4 and "typedef struct SDL_AudioCVT" in typedef:
8183
typedef = RE_TYPEDEF_TRUNCATE.sub(r"\1 { ...; }", typedef)
@@ -93,8 +95,9 @@ def parse(header: str, NEEDS_PACK4: bool) -> Iterator[str]:
9395
if "va_list" in decl:
9496
continue
9597
decl = re.sub(r"SDL_PRINTF_VARARG_FUNC\(\w*\)", "", decl)
96-
decl = decl.replace("extern DECLSPEC ", "")
97-
decl = decl.replace("SDLCALL", " ")
98+
decl = decl.replace("SDL_DEPRECATED", "")
99+
decl = decl.replace("SDLCALL", "")
100+
decl = re.sub(r"extern\s+DECLSPEC", "", decl)
98101
yield decl.replace("SDL_PRINTF_FORMAT_STRING ", "")
99102

100103

0 commit comments

Comments
 (0)