Skip to content

refactor(libobs): move libc-bound dstr functions out (#6) - #50

Closed
b7216309-jpg wants to merge 1 commit into
obs-rust:masterfrom
b7216309-jpg:refactor/dstr-libc-extract
Closed

b7216309-jpg wants to merge 1 commit into
obs-rust:masterfrom
b7216309-jpg:refactor/dstr-libc-extract

Conversation

@b7216309-jpg

@b7216309-jpg b7216309-jpg commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Refs #43 (Phase 3 tracking; #6 closed when #33 merged)

A behavior-neutral extraction ahead of porting dstr.c (Phase 3, step 5), following "Extracting a function before porting it". The precedents are #5 and #42. This PR contains no Rust.

Fifteen functions move verbatim from util/dstr.c into the new util/dstr-libc.c:

Group Functions Why it stays in C
printf family dstr_printf, dstr_catf, dstr_vprintf, dstr_vcatf C varargs / va_list: stable Rust cannot define variadic functions (c_variadic is unstable), and the formatting is the C library's vsnprintf
wide-char compares wstrcmpi, wstrcmp_n, wstrcmpi_n, wstrstri, wcsdepad towupper is locale- and libc-dependent; wchar_t is 16-bit on Windows and 32-bit elsewhere
conversions dstr_from_mbs, dstr_to_mbs, dstr_to_wcs, dstr_from_wcs, dstr_to_upper, dstr_to_lower they go through platform.c (os_mbs_to_utf8_ptr, os_utf8_to_wcs_ptr) and towupper/towlower

wstrblank moves with them. The static inline is_padding helper, used by both strdepad and wcsdepad, is copied. The includes are kept identical. No header, signature or behavior changes, and the new file is always compiled. test_dstr is untouched.

What stays in dstr.c is pure byte-string logic: the astr* compares, strdepad, strlist_split, and the dstr copy/cat/insert/remove/replace/left/mid/right/depad/safe_printf family. That part maps onto a safe Rust core, and the port follows in a separate PR.

Verification

  • git diff of dstr.c has zero added lines (deletions only).
  • A script confirms that every function block in dstr-libc.c appears byte-for-byte in the original dstr.c.
  • Both files compile with MSVC (C11, warnings on), and ./lint passes.
  • Not run locally: the cmocka suite (no Docker here).

🤖 Generated with Claude Code

Behavior-neutral move, as the function-extraction policy requires.
These 15 functions move verbatim from util/dstr.c into the new
util/dstr-libc.c:

- the printf family (dstr_printf, dstr_catf, dstr_vprintf,
  dstr_vcatf), which takes C varargs and va_list;
- the wide-character compares (wstrcmpi, wstrcmp_n, wstrcmpi_n,
  wstrstri, wcsdepad), which depend on towupper and wchar_t width;
- the conversions (dstr_from_mbs, dstr_to_mbs, dstr_to_wcs,
  dstr_from_wcs, dstr_to_upper, dstr_to_lower), which go through
  platform.c and the locale.

wstrblank moves with them, and the static is_padding helper, which both
files use, is copied. No header, signature or behavior changes, and the
new file is always compiled.

What stays in dstr.c is pure byte-string logic that a Rust port can
replace under ENABLE_RUST_LIBOBS. Stable Rust cannot define variadic
functions, so the printf family has to stay in C.

Refs obs-rust#6

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@b7216309-jpg

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #68, which ports this (along with the rest of Phase 3) on top of the merged C fixes #53, #54 and #60. Thanks for picking up the decisions from here. The cf-tokenizer work (#42, #49) isn't covered by #68; I'll rebuild #49 on #68's lexer once it lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant