fix(ui-windows): AdBanner was an unresolved external - add the placeholder widget#6640
Conversation
…rror perry_ui_adbanner_create is a required dispatch row (ui_table/part_a.rs AdBanner) but was never defined in the Windows staticlib, so any TS program using AdBanner(...) died at link time with an unresolved external. Implement the same layout-placeholder semantics as the macOS backend (no Google Mobile Ads SDK exists for either desktop OS): an empty STATIC pinned to the Google AdSize slot dimensions (DPI-scaled) so cross-platform layouts reserve exactly the space the live banner occupies on iOS/Android. Verified: an AdBanner app now compiles, links, and renders a reserved 320x50 slot between siblings (previously: LNK2019).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a Windows ad banner placeholder widget that reserves a size-specific, DPI-scaled layout area, registers the widget, and exposes creation through a new C-compatible FFI function. ChangesWindows ad banner
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Runtime
participant FFI
participant AdBanner
participant WidgetRegistry
participant Win32
Runtime->>FFI: call perry_ui_adbanner_create
FFI->>AdBanner: pass unit ID and size pointers
AdBanner->>AdBanner: calculate banner dimensions
AdBanner->>Win32: create STATIC placeholder
AdBanner->>WidgetRegistry: register handle and fixed size
WidgetRegistry-->>FFI: return widget handle
FFI-->>Runtime: return i64 handle
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/perry-ui-windows/src/widgets/ad_banner.rs`:
- Around line 25-35: Update str_from_header to use a bounded lifetime tied to
the input pointer instead of returning &'static str, and replace
from_utf8_unchecked with std::str::from_utf8. Return the existing empty-string
fallback when the byte slice is invalid while preserving the null-pointer
behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 41b82b86-2a54-4cc1-b07a-5423b71758f0
📒 Files selected for processing (3)
crates/perry-ui-windows/src/ffi/widget_create.rscrates/perry-ui-windows/src/widgets/ad_banner.rscrates/perry-ui-windows/src/widgets/mod.rs
| fn str_from_header(ptr: *const u8) -> &'static str { | ||
| if ptr.is_null() { | ||
| return ""; | ||
| } | ||
| unsafe { | ||
| let header = ptr as *const perry_runtime::string::StringHeader; | ||
| let len = (*header).byte_len as usize; | ||
| let data = ptr.add(std::mem::size_of::<perry_runtime::string::StringHeader>()); | ||
| std::str::from_utf8_unchecked(std::slice::from_raw_parts(data, len)) | ||
| } | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win
Prevent Undefined Behavior by safely parsing potentially invalid UTF-8 strings.
The perry_runtime::string::StringHeader explicitly documents that strings may contain lone surrogates (WTF-8). Calling std::str::from_utf8_unchecked on such strings invokes Undefined Behavior in Rust. Use std::str::from_utf8 and safely fall back (e.g., to an empty string) if the bytes are invalid.
Additionally, returning &'static str for a runtime-allocated string is semantically incorrect because the string's lifetime is bound to the runtime's memory, not the life of the program. It should use a bounded lifetime parameter.
🔒️ Proposed fix
-fn str_from_header(ptr: *const u8) -> &'static str {
+fn str_from_header<'a>(ptr: *const u8) -> &'a str {
if ptr.is_null() {
return "";
}
unsafe {
let header = ptr as *const perry_runtime::string::StringHeader;
let len = (*header).byte_len as usize;
let data = ptr.add(std::mem::size_of::<perry_runtime::string::StringHeader>());
- std::str::from_utf8_unchecked(std::slice::from_raw_parts(data, len))
+ std::str::from_utf8(std::slice::from_raw_parts(data, len)).unwrap_or("")
}
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/perry-ui-windows/src/widgets/ad_banner.rs` around lines 25 - 35,
Update str_from_header to use a bounded lifetime tied to the input pointer
instead of returning &'static str, and replace from_utf8_unchecked with
std::str::from_utf8. Return the existing empty-string fallback when the byte
slice is invalid while preserving the null-pointer behavior.
|
Addressed in the follow-up commit: str_from_header now uses a checked std::str::from_utf8 with an empty-string fallback (invalid size key => default 320x50 slot), since runtime strings are WTF-8 and may carry lone surrogates. Kept the &'static signature for now - it matches the crate-wide str_from_header idiom used in ~15 sibling files (all of which also use from_utf8_unchecked and predate this PR); filing the crate-wide sweep separately so this PR stays scoped to the missing symbol. |
Runtime strings are WTF-8 (lone surrogates possible), so exposing the raw bytes via from_utf8_unchecked is UB. Parse checked; invalid input falls back to the empty string and therefore the default 320x50 banner slot. Addresses the CodeRabbit review on #6640. The same unchecked idiom exists in ~15 sibling files predating this PR - tracked separately.
AdBanner is a required dispatch-table row (perry-dispatch/src/ui_table/part_a.rs, method \AdBanner\ -> \perry_ui_adbanner_create) but the symbol did not exist in perry-ui-windows: any TS program touching AdBanner failed at link with an unresolved external (found in the 2026-07-18 Windows audit).
This ports the macOS placeholder semantics (perry-ui-macos/src/widgets/adbanner.rs, #867): no ads SDK exists for desktop, so the widget is an empty STATIC pinned via fixed width/height to the Google AdSize slot dimensions (banner/large-banner/medium-rectangle/full-banner/leaderboard, DPI-scaled) — layouts previewed on Windows reserve exactly the space the real ad occupies on mobile.
Verified on Windows 11: the test app compiles + links (previously LNK2019) and renders a reserved 320x50 slot between two Text siblings (PrintWindow capture).
No version bump / changelog per maintainer instruction.
Summary by CodeRabbit