Go to file
Peterino2 79dd39e36a feat: Strip format attribute macros and add va_list support - +2 APIs!
Added support for C printf/scanf format attribute macros and variadic argument
lists, unlocking 2 more perfect APIs.

## Features Added

### 1. Format Attribute Macro Stripping
Strips compiler attribute macros from function declarations:
- `SDL_PRINTF_FORMAT_STRING`
- `SDL_WPRINTF_FORMAT_STRING`
- `SDL_SCANF_FORMAT_STRING`
- `SDL_PRINTF_VARARG_FUNC(N)`
- `SDL_PRINTF_VARARG_FUNCV(N)`
- `SDL_WPRINTF_VARARG_FUNC(N)`
- `SDL_SCANF_VARARG_FUNC(N)`

**Before** (C):
```c
extern SDL_DECLSPEC bool SDLCALL SDL_SetError(
    SDL_PRINTF_FORMAT_STRING const char *fmt, ...
) SDL_PRINTF_VARARG_FUNC(1);
```

**After** (Zig):
```zig
pub inline fn setError(fmt: [*c]const u8, ...) bool {
    return c.SDL_SetError(fmt, ...);
}
```

### 2. Variadic Arguments Support
Added `va_list` type conversion:
- C type: `va_list`
- Zig type: `std.builtin.VaList`

**Implementation**: Added `const std = @import("std");` to generated headers
to make `std.builtin.VaList` available.

### 3. Double Void Pointer Support
Added conversion for `void **`:
- C type: `void **userdata`
- Zig type: `userdata: [*c]?*anyopaque`

## Implementation Details

### Macro Stripping Algorithm (patterns.zig)
1. **Format String Macros**: Scan function text for format macros
   - Pattern: `SDL_PRINTF_FORMAT_STRING const char *fmt`
   - Remove macro, keep type: `const char *fmt`
   - Handle: PRINTF, WPRINTF, SCANF variants

2. **Vararg Function Macros**: Find and remove end-of-declaration macros
   - Pattern: `) SDL_PRINTF_VARARG_FUNC(1);`
   - Locate macro position
   - Find closing `)` and remove from macro to `)`
   - Handle: PRINTF, WPRINTF, SCANF, FUNCV variants

3. **Safe String Manipulation**:
   - Create new string with `std.fmt.allocPrint`
   - Clear and repopulate ArrayList (avoids aliasing)
   - Defer cleanup of temporary strings

### Type Conversions (types.zig)
```zig
// Variadic lists
"va_list" → "std.builtin.VaList"

// Double void pointers
"void **" → "[*c]?*anyopaque"
```

### Header Generation (codegen.zig)
Added std import to all generated files:
```zig
const std = @import("std");
pub const c = @import("c.zig").c;
```

## Results

### Before
- 22/43 APIs perfect (51%)
- Format macros: NOT STRIPPED
- va_list: NOT SUPPORTED
- void **: PARTIALLY SUPPORTED

### After
- **24/43 APIs perfect (56%)** 
- Format macros: FULLY STRIPPED
- va_list: FULLY SUPPORTED
- void **: FULLY SUPPORTED

**Progress: +5% (+2 APIs)**

### New Perfect APIs

 **SDL_error.h** (24 lines)
   - Error handling API
   - `SDL_SetError()` uses printf-style formatting
   - Had 1 error: format macros + va_list
   - Now perfect!

 **SDL_log.h** (148 lines)
   - Logging system with priority levels
   - Multiple printf-style log functions
   - Custom log output callbacks
   - Had 1 error: format macros + void**
   - Now perfect!

## Testing

Tested against all 43 SDL3 headers:
- **24 compile perfectly** (56%) 
- 19 have 1-13 errors
- 0 complete failures

**Cumulative Progress**:
- Session start: 15 APIs (35%)
- After function pointers: 19 APIs (44%)
- After arrays/comments: 22 APIs (51%)
- After format macros: **24 APIs (56%)** 🎉

**More than HALF of SDL3 APIs generate perfectly!**

## Impact

**Immediate**: +2 perfect APIs (5% improvement)
**Unlocked**: Printf-style functions now work everywhere
**Fixed**: Variadic argument handling

## Code Changes

### src/patterns.zig (+60 lines)
- `scanFunction()`: Strip format and vararg macros
- Safe string manipulation with allocPrint
- Handles all format macro variants

### src/types.zig (+2 lines)
- Added `va_list` → `std.builtin.VaList` conversion
- Added `void **` → `[*c]?*anyopaque` conversion

### src/codegen.zig (+2 lines)
- Added `const std = @import("std");` to generated headers
- Updated test expectations

## Known Limitations

Function pointer fields in structs not yet supported:
```c
Sint64 (SDLCALL *size)(void *userdata);  // Struct field
```

This affects:
- SDL_iostream.h (IOStreamInterface)
- SDL_storage.h (StorageInterface)
- SDL_dialog.h (DialogFileFilter callback)

Will be addressed in future commits.

---

Printf-style functions now work perfectly across SDL3!
2026-01-22 14:55:45 -08:00
.github/workflows big rework on automation.py and staging game builds now 2025-10-12 15:24:57 -07:00
archive archiving a lot of things then moving to yet another redo of the build system 2025-11-28 20:22:51 -08:00
build saving 2026-01-19 21:40:05 -08:00
buildgen enabling shader gen 2026-01-08 17:19:52 -08:00
depot updates to engine time and seemingly bugs are fixed 2026-01-03 16:35:31 -08:00
docs adding claude helper files and documentation, also testing parallel-job 2025-10-25 15:08:40 -07:00
engine saving 2026-01-21 22:41:50 -08:00
extras samplegame is now compiling on windows in both debug and static build modes on 0.15 2025-10-19 23:35:28 -07:00
lib feat: Strip format attribute macros and add va_list support - +2 APIs! 2026-01-22 14:55:45 -08:00
projects updates to engine time and seemingly bugs are fixed 2026-01-03 16:35:31 -08:00
testing replaced all references of std.time.sleep with std.Thread.sleep 2025-10-13 17:56:07 -07:00
tools finished enet 2025-10-13 17:53:42 -07:00
.gitattributes Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
.gitignore big rework on automation.py and staging game builds now 2025-10-12 15:24:57 -07:00
CLAUDE.md crated zuck game content and creating hello-window 2025-10-26 20:02:36 -07:00
LICENSE Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
README.md saving 2025-12-19 02:18:45 -08:00
build.archive.zig new build system who dis 2025-12-07 14:35:58 -08:00
build.zig saving 2025-12-30 13:55:35 -08:00
build.zig.zon new build system who dis 2025-12-07 14:35:58 -08:00
content.txt content and shader cooking stuff 2025-04-13 14:12:48 -07:00
todo.txt spec generation complete 2025-12-27 22:51:40 -08:00

README.md

Backlog

zig version: 0.15.1

Backlog Labs Game Engine.

Getting Started

run tools/scripts/first-time-setup.py

ffmpeg -i INPUT.mp4 -c:v libtheora -q:v 7 -c:a libvorbis -q:a 4 OUTPUT.ogv

git-bug Cheat Sheet

This project uses git-bug for distributed issue tracking. Issues are stored directly in the repository.

Common Commands

Listing Issues

git bug bug                    # List all issues
git bug bug status:open        # List only open issues
git bug bug status:closed      # List only closed issues

Creating Issues

git bug bug new -t "title" -m "message"              # Create new issue
git bug bug new -t "Add feature X" -m "Description"  # Example

Viewing & Managing Issues

git bug bug show <id>          # Show issue details
git bug bug comment <id>       # Add a comment to an issue
git bug bug close <id>         # Close an issue
git bug bug open <id>          # Reopen an issue
git bug bug status <id>        # Show issue status

Labels

git bug bug label <id>              # Show labels for an issue
git bug bug label new <id> <label>  # Add a label
git bug bug label rm <id> <label>   # Remove a label

Syncing

git bug pull                   # Pull issue updates from remote
git bug push                   # Push issue updates to remote

Standard Labels

Component Labels: core, rendering, physics, build-system, platform, assets, audio, ui, documentation

Type Labels:

  • bug - Defects or incorrect behavior
  • feature - New functionality
  • enhancement - Improvements to existing features
  • task - General development work
  • documentation - Documentation improvements
  • question - Design decisions or discussions
  • refactoring - Code cleanup

Problem Type Labels (for bugs):

  • memory - Memory issues
  • threading - Concurrency issues
  • crash - Application crashes
  • build - Build system issues

Quick Examples

# Create a bug report
git bug bug new -t "Memory leak in asset loader" -m "Assets not freed when unloading scenes"
git bug bug label new <id> bug assets memory

# Create a feature request
git bug bug new -t "Add terrain generation" -m "Implement heightmap-based terrain"
git bug bug label new <id> feature rendering

# Create a task
git bug bug new -t "Update to Zig 0.15" -m "Migrate to latest Zig version"
git bug bug label new <id> task build-system

# View and comment on an issue
git bug bug show abc123
git bug bug comment abc123

Tips

  • Issue IDs can be abbreviated (first few characters)
  • Use --non-interactive flag for scripting
  • Issues sync with git bug pull/push
  • Keep descriptions factual and clear