Skip to content

Refactor Doom modules to use native c"..." literals and remove duplicated cstr! macros#145

Merged
sunsided merged 2 commits into
mainfrom
copilot/refactor-cstr-macros-to-cliterals
May 23, 2026
Merged

Refactor Doom modules to use native c"..." literals and remove duplicated cstr! macros#145
sunsided merged 2 commits into
mainfrom
copilot/refactor-cstr-macros-to-cliterals

Conversation

Copilot AI commented May 22, 2026

Copy link
Copy Markdown
Contributor

cstr! was duplicated across multiple Doom modules and routinely produced mutable raw pointers for string literals that are actually read-only. This change replaces those macro calls with native Rust C-string literals and makes mutability explicit only where required by FFI signatures.

  • Replace cstr! usage with native C-string literals

    • Converted call sites from cstr!("...") to c"...".as_ptr().
    • Removed all local macro_rules! cstr definitions from affected modules.
  • Make pointer mutability explicit at FFI boundaries

    • Added .cast_mut() only where data flows into APIs/types that still require *mut c_char (while preserving read-only backing storage semantics).
    • Kept read-only paths as *const c_char where possible.
  • Align argv parameter APIs with read-only usage

    • Updated m_argv signatures used for argument matching (M_CheckParmWithArgs, M_CheckParm, M_ParmExists) to accept *const c_char.
    • Simplified callers by removing unnecessary mutable-pointer coercions.
  • Mechanical cleanup from macro removal

    • Updated nearby docs/comments that referenced cstr!.
    • Preserved behavior; this is a structural/type-safety refactor.
// before
let p = M_CheckParmWithArgs(cstr!("-file"), 1);
printf(cstr!(" adding %s\n"), filename);

// after
let p = M_CheckParmWithArgs(c"-file".as_ptr(), 1);
printf(c" adding %s\n".as_ptr(), filename);

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_/home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libgimli-46dc78dc6a8cb06a.rlib /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_/home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libcfg_if-0ce073fff809ec38.rlib /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_/home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/librustc_demangle-146c3f1190dee2e2.rlib /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_/home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libstd_detect-e305c7135f50bfab.rlib eUlG/symbols.o cript_build-d2cc17342796f4f3.build_script_build.7e66a80fa321764f-cgu.0.rcgu.o cript_build-d2cc17342796f4f3.build_script_build.7e66a80fa321764f-cgu.1.rcgu.o cript_build-d2cc17342796f4f3.build_script_build.7e66a80fa321764f-cgu.2.rcgu.o cript_build-d2cc17342796f4f3.5jda16q7vra9bvmy1a0oko6we.rcgu.o /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libminiz_oxide-5ad929a15a8e6727.rlib /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libadler2-1f570ee5c6635aae.rlib ib 64-REDACTED-linux-gnu/lib/libstd-d1237ef7159db0a2.rlib 64-REDACTED-linux-gnu/lib/libpanic_unwind-4be5972b22d3a6da.rlib 64-REDACTED-linux-gnu/lib/libobject-2a81194c9d07bbf6.rlib 64-REDACTED-linux-gnu/lib/libmemchr-ea71fa85f6699d6b.rlib 64-REDACTED-linux-gnu/lib/libaddr2line-a79a8816d9fd6004.rlib 64-REDACTED-linux-gnu/lib/libgimli-46dc78dc6a8cb06a.rlib 64-REDACTED-linux-gnu/lib/libcfg_if-0ce073fff809ec38.rlib (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Refactor: replace cstr! macros with c"..." literals Refactor Doom modules to use native c"..." literals and remove duplicated cstr! macros May 22, 2026
Copilot AI requested a review from sunsided May 22, 2026 19:05
@sunsided sunsided marked this pull request as ready for review May 23, 2026 20:40
Copilot AI review requested due to automatic review settings May 23, 2026 20:40
@github-actions github-actions Bot added area-p_spec Area: p_spec area-f_finale Area: f_finale area-m_argv Area: m_argv area-w_main Area: w_main area-statdump Area: statdump area-d_mode Area: d_mode area-dstrings Area: dstrings area-hu_stuff Area: hu_stuff area-r_draw Area: r_draw labels May 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors multiple Doom-engine Rust port modules to stop using locally duplicated cstr! macros and instead use native Rust C-string literals (c"...") for 'static NUL-terminated strings, while also tightening argv-parameter APIs to be read-only (*const c_char).

Changes:

  • Replaced cstr!("...") call sites with c"...".as_ptr() (and .cast_mut() only where required by existing FFI signatures).
  • Removed duplicated per-module macro_rules! cstr helpers.
  • Updated m_argv’s argument-matching APIs (M_CheckParmWithArgs, M_CheckParm, M_ParmExists) to accept *const c_char.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
room/src/doom/w_main.rs Switches -file parsing strings to c"..." literals and removes local cstr!.
room/src/doom/statdump.rs Removes local cstr! and uses c"-statdump".as_ptr() with updated argv API.
room/src/doom/r_draw.rs Replaces cstr! uses in WAD lump name lookups with c"..." literals.
room/src/doom/p_spec.rs Removes local cstr!, updates ANIMDEFS to c"..." literals, and updates -donut flag lookup.
room/src/doom/m_argv.rs Changes argv-check function parameters from *mut c_char to *const c_char.
room/src/doom/hu_stuff.rs Converts many exported string tables to c"..." literals and removes local cstr!.
room/src/doom/f_finale.rs Converts finale text/name constants and lump-name strings to c"..." literals.
room/src/doom/dstrings.rs Removes cstr! macro and uses c"..." literals for quit-message tables.
room/src/doom/d_mode.rs Converts D_GameMissionString return strings to c"..." literals and removes local cstr!.
room/src/doom/d_iwad.rs Converts IWAD metadata and flag strings to c"..." literals and removes local cstr!.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sunsided sunsided merged commit 5587fca into main May 23, 2026
4 checks passed
@sunsided sunsided deleted the copilot/refactor-cstr-macros-to-cliterals branch May 23, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-d_mode Area: d_mode area-dstrings Area: dstrings area-f_finale Area: f_finale area-hu_stuff Area: hu_stuff area-m_argv Area: m_argv area-p_spec Area: p_spec area-r_draw Area: r_draw area-statdump Area: statdump area-w_main Area: w_main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: replace cstr! macros with c"..." literals

3 participants