From dff036172f3a61e4f0de23e1b3d08f181e1ff4af Mon Sep 17 00:00:00 2001 From: Ryan Doupe Date: Thu, 19 Nov 2026 19:34:38 -0500 Subject: [PATCH 1/2] test: mirror scene-item parent-group query characterization (RED, Refs #5290) Tier 1 mirrors every assertion of test_sceneitem_get_group.c against the safe core; Tier 3 compares the original extracted C wrapper with the shim on one fixture through the real-named lock, walk and group-flag boundary, with mutants for a missing unlock, an unlocked walk, locking group items, a second flag read and a dropped result. The shared real-named full-lock stand-in in scene_atomic_update.c now dispatches to an active parent-group probe first. The core and shim are stubs that always return NULL, so: soldr cargo test -p obs-data --test obs-tests-core item_get_group test result: FAILED. 1 passed; 6 failed Co-Authored-By: Claude Opus 5.5 --- .../oracle.d/scene-item-get-group.list | 1 + .../obs-c-oracle/oracle/scene_atomic_update.c | 9 +- .../oracle/scene_item_get_group.c | 177 ++++++++++++++++++ rust/obs-scene/src/ffi/item_get_group.rs | 50 +++++ rust/obs-scene/src/ffi/mod.rs | 1 + rust/obs-scene/src/item_get_group.rs | 22 +++ rust/obs-scene/src/lib.rs | 1 + rust/obs-scene/tests/scene/item_get_group.rs | 168 +++++++++++++++++ .../tests/scene/item_get_group_parity.rs | 132 +++++++++++++ rust/obs-scene/tests/scene/main.rs | 2 + 10 files changed, 561 insertions(+), 2 deletions(-) create mode 100644 rust/obs-c-oracle/oracle.d/scene-item-get-group.list create mode 100644 rust/obs-c-oracle/oracle/scene_item_get_group.c create mode 100644 rust/obs-scene/src/ffi/item_get_group.rs create mode 100644 rust/obs-scene/src/item_get_group.rs create mode 100644 rust/obs-scene/tests/scene/item_get_group.rs create mode 100644 rust/obs-scene/tests/scene/item_get_group_parity.rs diff --git a/rust/obs-c-oracle/oracle.d/scene-item-get-group.list b/rust/obs-c-oracle/oracle.d/scene-item-get-group.list new file mode 100644 index 0000000000..87e80929bb --- /dev/null +++ b/rust/obs-c-oracle/oracle.d/scene-item-get-group.list @@ -0,0 +1 @@ +scene-item-get-group.inc|libobs/obs-scene-item-get-group.c.h|auto diff --git a/rust/obs-c-oracle/oracle/scene_atomic_update.c b/rust/obs-c-oracle/oracle/scene_atomic_update.c index a76985d814..a50ffb2305 100644 --- a/rust/obs-c-oracle/oracle/scene_atomic_update.c +++ b/rust/obs-c-oracle/oracle/scene_atomic_update.c @@ -69,15 +69,20 @@ void oracle_atomic_source_release(obs_source_t *source) struct atomic_fixture *f = source->context.data; atomic_release(&f->scene); } +/* The one real-named full-lock stand-in: a parent-group probe active on this + * thread (scene_item_get_group.c) owns the call, otherwise this recorder. */ +bool oracle_scene_get_group_full_lock(obs_scene_t *scene, bool lock); void obs_scene_atomic_full_lock(obs_scene_t *scene); void obs_scene_atomic_full_unlock(obs_scene_t *scene); void obs_scene_atomic_full_lock(obs_scene_t *scene) { - oracle_atomic_full_lock(scene); + if (!oracle_scene_get_group_full_lock(scene, true)) + oracle_atomic_full_lock(scene); } void obs_scene_atomic_full_unlock(obs_scene_t *scene) { - oracle_atomic_full_unlock(scene); + if (!oracle_scene_get_group_full_lock(scene, false)) + oracle_atomic_full_unlock(scene); } static void atomic_callback(void *data, obs_scene_t *scene) diff --git a/rust/obs-c-oracle/oracle/scene_item_get_group.c b/rust/obs-c-oracle/oracle/scene_item_get_group.c new file mode 100644 index 0000000000..30a0d79c69 --- /dev/null +++ b/rust/obs-c-oracle/oracle/scene_item_get_group.c @@ -0,0 +1,177 @@ +/* Original extracted parent-group wrapper over one recorded lock/walk boundary. + * The Rust shim reaches the same boundary through the real seam names: the + * shared full-lock definition in scene_atomic_update.c dispatches here while a + * probe is active on this thread, and the real group-flag adapter reads the + * fixture item (scene_item_group_scene.c). */ +#include "libobs/build/libobs.pch.h" + +void oracle_get_group_lock(obs_scene_t *scene); +void oracle_get_group_unlock(obs_scene_t *scene); +obs_sceneitem_t *oracle_obs_sceneitem_get_group(obs_scene_t *scene, obs_sceneitem_t *group_subitem); +#define obs_sceneitem_get_group oracle_obs_sceneitem_get_group +#define obs_scene_atomic_full_lock oracle_get_group_lock +#define obs_scene_atomic_full_unlock oracle_get_group_unlock +#include "scene-item-get-group.inc" +#undef obs_scene_atomic_full_unlock +#undef obs_scene_atomic_full_lock +#undef obs_sceneitem_get_group + +enum { GET_GROUP_EVENTS = 8, GET_GROUP_ITEMS = 4 }; +enum { EV_LOCK = 1, EV_LOOKUP = 2, EV_UNLOCK = 3, EV_FOREIGN = 0x100, EV_UNLOCKED_LOOKUP = 0x200 }; + +struct get_group_fixture { + struct obs_scene scene; + struct obs_scene_item item; + struct obs_scene_item groups[GET_GROUP_ITEMS]; + struct obs_scene_item foreign; + obs_sceneitem_t *result; + bool clobber; + unsigned depth; + unsigned count; + unsigned events[GET_GROUP_EVENTS]; +}; + +static _Thread_local struct get_group_fixture *get_group_active; + +static void get_group_record(struct get_group_fixture *f, unsigned event) +{ + if (f->count < GET_GROUP_EVENTS) + f->events[f->count] = event; + f->count++; +} + +/* Called by the shared real-named full-lock stand-ins; false when no probe of + * this thread owns the call, so the atomic-update recorder handles it. */ +bool oracle_scene_get_group_full_lock(obs_scene_t *scene, bool lock); +bool oracle_scene_get_group_full_lock(obs_scene_t *scene, bool lock) +{ + struct get_group_fixture *f = get_group_active; + if (!f) + return false; + unsigned event = lock ? EV_LOCK : EV_UNLOCK; + if (scene != &f->scene) + event |= EV_FOREIGN; + if (lock) + f->depth++; + else if (f->depth) + f->depth--; + else + event |= EV_UNLOCKED_LOOKUP; + get_group_record(f, event); + return true; +} + +void oracle_get_group_lock(obs_scene_t *scene) +{ + if (!oracle_scene_get_group_full_lock(scene, true)) + abort(); +} + +void oracle_get_group_unlock(obs_scene_t *scene) +{ + if (!oracle_scene_get_group_full_lock(scene, false)) + abort(); +} + +/* The C-owned walk stays in obs-scene.c.h; both sides reach this stand-in by + * its real name and get the fixture's chosen, borrowed result. */ +obs_sceneitem_t *obs_sceneitem_parent_group_lookup(obs_scene_t *scene, obs_sceneitem_t *group_subitem) +{ + struct get_group_fixture *f = get_group_active; + if (!f) + abort(); + unsigned event = EV_LOOKUP | (f->depth << 4); + if (scene != &f->scene || group_subitem != &f->item) + event |= EV_FOREIGN; + if (f->depth != 1) + event |= EV_UNLOCKED_LOOKUP; + get_group_record(f, event); + /* A later read of the group flag would now reject; C reads it once. */ + if (f->clobber) + f->item.is_group = true; + return f->result; +} + +static void get_group_init(struct get_group_fixture *f, unsigned bits) +{ + memset(f, 0, sizeof(*f)); + f->item.ref = 11; + f->item.is_group = (bits & 4) != 0; + f->item.parent = (bits & 0x100) ? NULL : &f->scene; + f->scene.first_item = &f->groups[0]; + for (size_t i = 0; i < GET_GROUP_ITEMS; i++) { + f->groups[i].ref = 17 + (long)i; + f->groups[i].is_group = (bits >> (9 + i)) & 1; + f->groups[i].removed = (bits & 8) != 0; + f->groups[i].parent = &f->scene; + f->groups[i].next = i + 1 < GET_GROUP_ITEMS ? &f->groups[i + 1] : NULL; + } + f->foreign.ref = 23; + f->foreign.is_group = true; + f->clobber = (bits & 0x10) != 0; + unsigned choice = (bits >> 5) & 7; + f->result = choice >= 1 && choice <= GET_GROUP_ITEMS ? &f->groups[choice - 1] + : choice == 5 ? &f->foreign + : choice == 6 ? &f->item + : NULL; +} + +typedef obs_sceneitem_t *(*get_group_fn)(obs_scene_t *, obs_sceneitem_t *); + +struct get_group_run { + obs_sceneitem_t *result; + unsigned count; + unsigned events[GET_GROUP_EVENTS]; + unsigned char objects[offsetof(struct get_group_fixture, result)]; +}; + +static void get_group_run(struct get_group_fixture *f, unsigned bits, get_group_fn getter, struct get_group_run *out) +{ + get_group_init(f, bits); + get_group_active = f; + out->result = getter((bits & 1) ? NULL : &f->scene, (bits & 2) ? NULL : &f->item); + get_group_active = NULL; + /* Undo the walk's clobber so the bytes show only what the wrapper wrote. */ + f->item.is_group = (bits & 4) != 0; + out->count = f->count; + memcpy(out->events, f->events, sizeof(out->events)); + memcpy(out->objects, f, sizeof(out->objects)); +} + +/* bits: 0 NULL scene, 1 NULL item, 2 group item, 3 removed groups, 4 clobber + * the flag during the walk, 5-7 walk result, 8 NULL item parent, 9-12 group + * flags of the scene's items. Both sides run on the same fixture address, so + * results compare as pointers. Returns 0 when the shim matches the original: + * 1 result identity, 2 trace, 4 any scene/item byte changed (refs included), + * 8 the original's own trace is not empty or exactly lock, lookup, unlock. */ +unsigned oracle_scene_item_get_group_probe(unsigned bits, get_group_fn rust); +unsigned oracle_scene_item_get_group_probe(unsigned bits, get_group_fn rust) +{ + static _Thread_local struct get_group_fixture fixture; + struct get_group_run expected, actual; + unsigned char before[sizeof(expected.objects)]; + get_group_init(&fixture, bits); + memcpy(before, &fixture, sizeof(before)); + get_group_run(&fixture, bits, oracle_obs_sceneitem_get_group, &expected); + get_group_run(&fixture, bits, rust, &actual); + unsigned result = 0; + if (expected.result != actual.result) + result |= 1; + if (expected.count != actual.count || memcmp(expected.events, actual.events, sizeof(expected.events))) + result |= 2; + if (memcmp(before, expected.objects, sizeof(before)) || memcmp(before, actual.objects, sizeof(before))) + result |= 4; + bool rejected = (bits & 7) != 0; + if (rejected ? expected.count != 0 + : expected.count != 3 || expected.events[0] != EV_LOCK || expected.events[1] != (EV_LOOKUP | 0x10) || + expected.events[2] != EV_UNLOCK) + result |= 8; + return result; +} + +/* Real header layout of the field the shim reads through its adapter. */ +size_t oracle_scene_item_get_group_layout(void); +size_t oracle_scene_item_get_group_layout(void) +{ + return sizeof(((struct obs_scene_item *)0)->is_group); +} diff --git a/rust/obs-scene/src/ffi/item_get_group.rs b/rust/obs-scene/src/ffi/item_get_group.rs new file mode 100644 index 0000000000..291b22a7df --- /dev/null +++ b/rust/obs-scene/src/ffi/item_get_group.rs @@ -0,0 +1,50 @@ +//! Parent-group query over the real C full lock, walk and group-flag seams. +use crate::item_get_group::{self, Query}; +use core::ffi::c_void; +use core::ptr::{self, NonNull}; + +unsafe extern "C" { + fn obs_scene_atomic_full_lock(scene: *mut c_void); + fn obs_scene_atomic_full_unlock(scene: *mut c_void); + fn obs_sceneitem_parent_group_lookup(scene: *mut c_void, item: *mut c_void) -> *mut c_void; + fn obs_sceneitem_group_scene_flag(item: *const c_void) -> *const bool; +} + +struct Live { + scene: NonNull, + item: NonNull, +} + +impl Query for Live { + type Group = NonNull; + fn is_group(&mut self) -> bool { + // SAFETY: the item is non-null and the caller keeps it readable. + unsafe { *obs_sceneitem_group_scene_flag(self.item.as_ptr()) } + } + fn lock(&mut self) { + // SAFETY: the scene is non-null and live under the caller's contract. + unsafe { obs_scene_atomic_full_lock(self.scene.as_ptr()) }; + } + fn lookup(&mut self) -> Option { + // SAFETY: the full lock is held; C walks the scene's item list. + NonNull::new(unsafe { + obs_sceneitem_parent_group_lookup(self.scene.as_ptr(), self.item.as_ptr()) + }) + } + fn unlock(&mut self) { + // SAFETY: paired with lock on the same scene. + unsafe { obs_scene_atomic_full_unlock(self.scene.as_ptr()) }; + } +} + +/// RED stub: not exported, so the C wrapper still links; always NULL. +/// +/// # Safety +/// Non-null arguments must be a live scene and a readable scene item, as in C. +pub unsafe extern "C" fn obs_sceneitem_get_group( + scene: *mut c_void, + item: *mut c_void, +) -> *mut c_void { + let _ = (scene, item, item_get_group::get_group::); + ptr::null_mut() +} diff --git a/rust/obs-scene/src/ffi/mod.rs b/rust/obs-scene/src/ffi/mod.rs index 904195f223..05213bf68c 100644 --- a/rust/obs-scene/src/ffi/mod.rs +++ b/rust/obs-scene/src/ffi/mod.rs @@ -47,6 +47,7 @@ pub mod item_transform_getters; pub mod item_transition_getters; pub mod item_transition_setters; +pub mod item_get_group; pub mod item_group_scene; pub mod item_hotkeys; pub mod item_visible; diff --git a/rust/obs-scene/src/item_get_group.rs b/rust/obs-scene/src/item_get_group.rs new file mode 100644 index 0000000000..73fc93b60d --- /dev/null +++ b/rust/obs-scene/src/item_get_group.rs @@ -0,0 +1,22 @@ +//! Parent-group query: reject before locking, then one full lock around the walk. + +/// A present scene and item, as seen by the query. C owns the locks and walk. +pub trait Query { + /// The group item the walk returns, borrowed. + type Group; + /// Read the item's group flag; called before any lock. + fn is_group(&mut self) -> bool; + /// Take the scene's full (video, then audio) lock. + fn lock(&mut self); + /// The first scene item that is the group holding the item, if any. + fn lookup(&mut self) -> Option; + /// Release the full lock. + fn unlock(&mut self); +} + +/// A missing scene or item, or a group item, is `None` without locking. +/// Otherwise the walk's result is returned as is, under exactly one lock. +pub fn get_group(query: Option<&mut Q>) -> Option { + let _ = query; + None // RED stub: the query is not ported yet. +} diff --git a/rust/obs-scene/src/lib.rs b/rust/obs-scene/src/lib.rs index 7e7ec6ebbf..94fe4b7527 100644 --- a/rust/obs-scene/src/lib.rs +++ b/rust/obs-scene/src/lib.rs @@ -91,6 +91,7 @@ pub mod item_transform_getters; pub mod item_transition_getters; pub mod item_transition_setters; +pub mod item_get_group; pub mod item_group_scene; pub mod item_hotkeys; pub mod item_visible; diff --git a/rust/obs-scene/tests/scene/item_get_group.rs b/rust/obs-scene/tests/scene/item_get_group.rs new file mode 100644 index 0000000000..f61271ff7d --- /dev/null +++ b/rust/obs-scene/tests/scene/item_get_group.rs @@ -0,0 +1,168 @@ +//! Tier 1 mirrors test_sceneitem_get_group.c: rejection before any flag read +//! or lock, one balanced full lock around the walk, and the walk's borrowed +//! result returned as is. The walk itself stays in C; the linked cases run a +//! safe model of it, so the wrapper is seen passing its first match through. +use obs_scene::item_get_group::{Query, get_group}; + +/// A safe scene item: group flag, removed flag, group context, reference count. +#[derive(Clone, Copy, PartialEq, Debug)] +struct Item { + is_group: bool, + removed: bool, + context: Option, + refs: i64, +} + +struct Model { + child_is_group: bool, + child_parent: Option, + child_refs: i64, + items: Vec, + /// `Some` replaces the model walk with a recorded fixed result. + recorded: Option>, + locked: bool, + flag_reads: u32, + locks: u32, + lookups: u32, + unlocks: u32, +} + +impl Model { + fn new() -> Self { + Self { + child_is_group: false, + child_parent: Some(1), + child_refs: 11, + items: (0..5) + .map(|i| Item { + is_group: false, + removed: false, + context: None, + refs: 17 + i, + }) + .collect(), + recorded: None, + locked: false, + flag_reads: 0, + locks: 0, + lookups: 0, + unlocks: 0, + } + } + + fn assert_balanced(&self) { + assert!(!self.locked); + assert_eq!(self.locks, self.lookups); + assert_eq!(self.locks, self.unlocks); + } +} + +impl Query for Model { + type Group = usize; + fn is_group(&mut self) -> bool { + assert!(!self.locked, "flag read under the lock"); + self.flag_reads += 1; + self.child_is_group + } + fn lock(&mut self) { + assert!(!self.locked); + assert_eq!(self.locks, self.lookups); + assert_eq!(self.locks, self.unlocks); + self.locked = true; + self.locks += 1; + } + fn lookup(&mut self) -> Option { + assert!(self.locked); + assert_eq!(self.locks, self.lookups + 1); + self.lookups += 1; + if let Some(result) = self.recorded { + return result; + } + // The C walk: the first group whose scene is the child's parent. It + // never consults the removed flag, and an absent parent matches an + // absent context. + self.items + .iter() + .position(|item| item.is_group && item.context == self.child_parent) + } + fn unlock(&mut self) { + assert!(self.locked); + assert_eq!(self.locks, self.lookups); + assert_eq!(self.locks, self.unlocks + 1); + self.locked = false; + self.unlocks += 1; + } +} + +#[test] +fn rejects_before_lock() { + let mut model = Model::new(); + // NULL scene and/or item: no handle, so nothing is read or locked. + assert_eq!(get_group::(None), None); + model.child_is_group = true; + assert_eq!(get_group(Some(&mut model)), None); + assert_eq!(model.flag_reads, 1); + assert_eq!((model.locks, model.lookups, model.unlocks), (0, 0, 0)); + model.assert_balanced(); +} + +#[test] +fn balanced_lookup_returns_borrowed_pointer() { + let mut model = Model::new(); + for i in 0..6u32 { + let result = (i < 5).then_some(i as usize); + model.recorded = Some(result); + assert_eq!(get_group(Some(&mut model)), result); + assert_eq!(model.locks, i + 1); + assert_eq!(model.lookups, model.locks); + assert_eq!(model.unlocks, model.locks); + assert!(!model.locked); + assert_eq!(model.child_refs, 11); + for (j, item) in model.items.iter().enumerate() { + assert_eq!(item.refs, 17 + j as i64); + } + } + model.assert_balanced(); +} + +fn linked_query(model: &mut Model, expected: Option) { + let items = model.items.clone(); + let child = (model.child_is_group, model.child_parent, model.child_refs); + for _ in 0..2 { + assert_eq!(get_group(Some(&mut *model)), expected); + // Includes every reference count: the result is borrowed. + assert_eq!(model.items, items); + assert_eq!( + (model.child_is_group, model.child_parent, model.child_refs), + child + ); + } + model.assert_balanced(); +} + +#[test] +fn linked_first_matching_parent_group() { + let mut model = Model::new(); + let items = core::mem::take(&mut model.items); + linked_query(&mut model, None); // empty scene + model.items = items; + linked_query(&mut model, None); // non-groups, even with a matching parent + model.items[0].context = model.child_parent; + for i in 1..4 { + model.items[i].is_group = true; + } + model.items[1].context = Some(2); + model.items[2].context = model.child_parent; + model.items[3].context = model.child_parent; + linked_query(&mut model, Some(2)); // skip ordinary item and foreign group + model.items[2].removed = true; + linked_query(&mut model, Some(2)); // characterized: removed is not consulted + model.items[2].context = Some(2); + linked_query(&mut model, Some(3)); + model.child_parent = Some(0); + linked_query(&mut model, None); // no matching group / foreign child + model.child_parent = None; + linked_query(&mut model, None); + model.items[1].context = None; + linked_query(&mut model, Some(1)); // characterized: NULL parent matches NULL context +} diff --git a/rust/obs-scene/tests/scene/item_get_group_parity.rs b/rust/obs-scene/tests/scene/item_get_group_parity.rs new file mode 100644 index 0000000000..402d56415e --- /dev/null +++ b/rust/obs-scene/tests/scene/item_get_group_parity.rs @@ -0,0 +1,132 @@ +//! Tier 3: the original extracted C wrapper versus the shim, on one fixture, +//! through the same real-named lock, walk and group-flag boundary. Compares +//! the returned pointer, the lock/walk trace and every scene and item byte +//! (reference counts included). No intentional differences. Mutants show the +//! probe catches each broken contract. +use core::ffi::c_void; +use obs_scene::ffi::item_get_group::obs_sceneitem_get_group; +use proptest::prelude::*; + +type Getter = unsafe extern "C" fn(*mut c_void, *mut c_void) -> *mut c_void; +unsafe extern "C" { + fn oracle_scene_item_get_group_probe(bits: u32, getter: Getter) -> u32; + fn oracle_scene_item_get_group_layout() -> usize; + fn obs_scene_atomic_full_lock(scene: *mut c_void); + fn obs_scene_atomic_full_unlock(scene: *mut c_void); + fn obs_sceneitem_parent_group_lookup(scene: *mut c_void, item: *mut c_void) -> *mut c_void; + fn obs_sceneitem_group_scene_flag(item: *const c_void) -> *const bool; +} + +fn probe(bits: u32, getter: Getter) -> u32 { + // SAFETY: the oracle owns a complete fixture and passes only its own + // scene and item, or NULL, to the getter. + unsafe { oracle_scene_item_get_group_probe(bits, getter) } +} + +fn check(bits: u32) { + assert_eq!(probe(bits, obs_sceneitem_get_group), 0, "bits={bits:#x}"); +} + +#[test] +fn group_flag_is_one_byte_bool() { + // SAFETY: a pure header measurement. + assert_eq!( + unsafe { oracle_scene_item_get_group_layout() }, + size_of::() + ); +} + +#[test] +fn characterized_edges() { + // Every rejection, result choice, removed and clobber flag, with and + // without an item parent, over a few group-flag patterns. + for low in 0..0x200 { + for groups in [0, 0b0110, 0b1111] { + check(low | (groups << 9)); + } + } +} + +proptest! { + #![proptest_config(ProptestConfig { + cases: obs_c_oracle::parity::cases(256), failure_persistence: None, + ..ProptestConfig::default() + })] + #[test] + fn get_group_matches_c(bits in 0..0x2000u32) { + check(bits); + } +} + +unsafe fn is_group(item: *mut c_void) -> bool { + // SAFETY: mutants read the flag only for a non-null fixture item. + unsafe { *obs_sceneitem_group_scene_flag(item) } +} + +unsafe extern "C" fn no_unlock(scene: *mut c_void, item: *mut c_void) -> *mut c_void { + if scene.is_null() || item.is_null() || unsafe { is_group(item) } { + return core::ptr::null_mut(); + } + // SAFETY: fixture scene and item; the unlock is deliberately missing. + unsafe { + obs_scene_atomic_full_lock(scene); + obs_sceneitem_parent_group_lookup(scene, item) + } +} + +unsafe extern "C" fn unlocked_walk(scene: *mut c_void, item: *mut c_void) -> *mut c_void { + if scene.is_null() || item.is_null() || unsafe { is_group(item) } { + return core::ptr::null_mut(); + } + // SAFETY: fixture scene and item; the walk deliberately runs unlocked. + unsafe { obs_sceneitem_parent_group_lookup(scene, item) } +} + +unsafe extern "C" fn locks_group_items(scene: *mut c_void, item: *mut c_void) -> *mut c_void { + if scene.is_null() || item.is_null() { + return core::ptr::null_mut(); + } + // SAFETY: fixture scene and item; the group check deliberately follows the lock. + unsafe { + obs_scene_atomic_full_lock(scene); + let group = obs_sceneitem_parent_group_lookup(scene, item); + obs_scene_atomic_full_unlock(scene); + if is_group(item) { + return core::ptr::null_mut(); + } + group + } +} + +unsafe extern "C" fn rereads_flag(scene: *mut c_void, item: *mut c_void) -> *mut c_void { + // SAFETY: as the shim, then a second flag read after the walk. + let group = unsafe { obs_sceneitem_get_group(scene, item) }; + if group.is_null() || unsafe { is_group(item) } { + return core::ptr::null_mut(); + } + group +} + +unsafe extern "C" fn always_null(scene: *mut c_void, item: *mut c_void) -> *mut c_void { + // SAFETY: as the shim; the result is deliberately dropped. + unsafe { obs_sceneitem_get_group(scene, item) }; + core::ptr::null_mut() +} + +#[test] +fn mutants_are_caught() { + // A present, non-group item whose walk finds the second group. + let found = 2 << 5; + // A group item: rejected before any lock. + let group = found | 4; + // The walk sets the item's flag, as another thread could. + let clobbered = found | 0x10; + assert_eq!(probe(found, no_unlock) & 2, 2); + assert_eq!(probe(found, unlocked_walk) & 2, 2); + assert_eq!(probe(group, locks_group_items) & 2, 2); + assert_eq!(probe(clobbered, rereads_flag) & 1, 1); + assert_eq!(probe(found, always_null) & 1, 1); + for bits in [found, group, clobbered] { + check(bits); + } +} diff --git a/rust/obs-scene/tests/scene/main.rs b/rust/obs-scene/tests/scene/main.rs index 12e4ed3f6b..e0e59b5d8e 100644 --- a/rust/obs-scene/tests/scene/main.rs +++ b/rust/obs-scene/tests/scene/main.rs @@ -92,6 +92,8 @@ mod item_transition_getters_parity; mod item_transition_setters; mod item_transition_setters_parity; +mod item_get_group; +mod item_get_group_parity; mod item_group_scene; mod item_group_scene_parity; mod item_hotkeys; From d3a31f116d38f69616e4e7af586e8abd80d96af8 Mon Sep 17 00:00:00 2001 From: Ryan Doupe Date: Thu, 19 Nov 2026 19:41:14 -0500 Subject: [PATCH 2/2] obs-scene: swap scene-item parent-group query to safe Rust (Refs #5290) obs_sceneitem_get_group now comes from obs-scene in the hybrid libobs. Safe Rust rejects a NULL scene or item before any read and a group item (read through the existing obs_sceneitem_group_scene_flag adapter) before any lock, then takes the C-owned full lock once around the C-owned walk (obs_sceneitem_parent_group_lookup, still shared with the reorder callers) and returns its result as a borrowed pointer. The original wrapper moves to the libobs.ported-scene-item-get-group group for the C reference build. soldr cargo test -p obs-data --test obs-tests-core item_get_group test result: ok. 7 passed; 0 failed Co-Authored-By: Claude Opus 5.5 Ci-Attestation: {"at":1795137681,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":94,"stamp":"da860ded63ac467c9cf83c567dba639f","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137681,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":94,"stamp":"0c389a57702fbdc62568259a4dae7617","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137681,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":94,"stamp":"7048fd9b7ac42f1352508e2d737820e3","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137681,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":94,"stamp":"1e08863b727f90be5e9a3a924ddb6cb9","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137585,"gate":"general/all/client-lint","host":"linux-x86_64","key":"e4de114e7e55e2cfc5dfec3c6b859e0f8cd5ecd15e5898620e2c7dda37453f6c","lane":"client-lint","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":76,"stamp":"37cfe49363a1176fbb702c4a707df14a","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137681,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":94,"stamp":"3d9dc77840a45f93b6d67b6baa66bb90","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137586,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"e4de114e7e55e2cfc5dfec3c6b859e0f8cd5ecd15e5898620e2c7dda37453f6c","lane":"client-lint","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":76,"stamp":"bd5348b2573edd5ea87ca662ae133cee","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137586,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"e4de114e7e55e2cfc5dfec3c6b859e0f8cd5ecd15e5898620e2c7dda37453f6c","lane":"client-lint","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":76,"stamp":"9c1a276dda417faf502be2256c407bd1","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137586,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"e4de114e7e55e2cfc5dfec3c6b859e0f8cd5ecd15e5898620e2c7dda37453f6c","lane":"client-lint","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":76,"stamp":"fa5721ed25a260a7bed795e858eeceaf","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137586,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"e4de114e7e55e2cfc5dfec3c6b859e0f8cd5ecd15e5898620e2c7dda37453f6c","lane":"client-lint","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":76,"stamp":"b1e3d097f0677c77ea9b3b490b710517","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137585,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"e4de114e7e55e2cfc5dfec3c6b859e0f8cd5ecd15e5898620e2c7dda37453f6c","lane":"client-lint","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":76,"stamp":"112a54dd02aba35da15cebdc166b61fe","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137585,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"e4de114e7e55e2cfc5dfec3c6b859e0f8cd5ecd15e5898620e2c7dda37453f6c","lane":"client-lint","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":76,"stamp":"78c272385f5b9e255edb1420175853a4","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137586,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"e4de114e7e55e2cfc5dfec3c6b859e0f8cd5ecd15e5898620e2c7dda37453f6c","lane":"client-lint","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":76,"stamp":"38857d4734d1b0c4f1238c5a07f4f0ef","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137586,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"e4de114e7e55e2cfc5dfec3c6b859e0f8cd5ecd15e5898620e2c7dda37453f6c","lane":"client-lint","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":76,"stamp":"1172c74a4f56f25860c502e3c5667b17","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137586,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"e4de114e7e55e2cfc5dfec3c6b859e0f8cd5ecd15e5898620e2c7dda37453f6c","lane":"client-lint","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":76,"stamp":"ec2c3daff22940c896cc5a92bc7b5c24","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137586,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"e4de114e7e55e2cfc5dfec3c6b859e0f8cd5ecd15e5898620e2c7dda37453f6c","lane":"client-lint","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":76,"stamp":"e286b851bf5794cad1b5c19b99d49052","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137585,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"e4de114e7e55e2cfc5dfec3c6b859e0f8cd5ecd15e5898620e2c7dda37453f6c","lane":"client-lint","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":76,"stamp":"24fb535f2cf2fff3dedf25bdcb81d1a2","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137585,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"e4de114e7e55e2cfc5dfec3c6b859e0f8cd5ecd15e5898620e2c7dda37453f6c","lane":"client-lint","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":76,"stamp":"55946666aa60602cf1b87cfdd19eb9c9","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Ci-Attestation: {"at":1795137891,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"a4f4bca8fc277273a683223fed952e899635c97ccec4f74cf01f470f22d5d114","lane":"client-test-x86_64-unknown-linux-gnu","parents":["dff036172f3a61e4f0de23e1b3d08f181e1ff4af"],"secs":209,"stamp":"ec7da1f51a98b2b6873903eeb5d965c2","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6","v":1,"via":"run"} Client-Checks: {"checks":{"base":"3b8563940504be9c25e19d594fa5667996cb13b6","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.core-source+.h.c","libobs/build/libobs.ported-scene-item-get-group+.h.c","libobs/build/ported-source-sets/scene-item-get-group.json","libobs/cmake/rust-exports.d/obs-scene-item_get_group.txt","rust/README.md","rust/obs-build/tests/native.rs","rust/obs-build/tests/native/registration/canonical_scene_item_get_group_swap_is_registered.rs","rust/obs-c-oracle/oracle.d/scene-item-get-group.list","rust/obs-c-oracle/oracle/scene_atomic_update.c","rust/obs-c-oracle/oracle/scene_item_get_group.c","rust/obs-scene/src/ffi/item_get_group.rs","rust/obs-scene/src/ffi/mod.rs","rust/obs-scene/src/item_get_group.rs","rust/obs-scene/src/lib.rs","rust/obs-scene/tests/scene/item_get_group.rs","rust/obs-scene/tests/scene/item_get_group_parity.rs","rust/obs-scene/tests/scene/main.rs"],"head":"96aab97749dd1b990e449adbaf9eafa9c51d81cd","tools":{"orchestrator-python":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]","schema-dependencies":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]\n{'jsonschema': '4.26.0', 'json_source_map': '1.0.5'}","uv":"uv 0.13.5 (x86_64-unknown-linux-gnu)","xmllint":"xmllint: using libxml version 21504-GITv2.15.4\n compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ICU ISO8859X Regexps Automata RelaxNG Schemas Schematron Modules Debug Zlib"},"tracked-digest":"35a0cd9f4ee6d3dac836568a817c111c6f705a5ec7caf2b26e422be4aed86eb3","tree":"d2738fb520af1cfd3acbf2f753e375fca6f213f6"}} --- libobs/build/libobs.core-source+.h.c | 1 - .../libobs.ported-scene-item-get-group+.h.c | 5 +++ .../scene-item-get-group.json | 5 +++ .../obs-scene-item_get_group.txt | 1 + rust/README.md | 1 + rust/obs-build/tests/native.rs | 2 + ...scene_item_get_group_swap_is_registered.rs | 37 +++++++++++++++++++ .../oracle/scene_item_get_group.c | 4 +- rust/obs-scene/src/ffi/item_get_group.rs | 10 +++-- rust/obs-scene/src/item_get_group.rs | 10 ++++- 10 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 libobs/build/libobs.ported-scene-item-get-group+.h.c create mode 100644 libobs/build/ported-source-sets/scene-item-get-group.json create mode 100644 libobs/cmake/rust-exports.d/obs-scene-item_get_group.txt create mode 100644 rust/obs-build/tests/native/registration/canonical_scene_item_get_group_swap_is_registered.rs diff --git a/libobs/build/libobs.core-source+.h.c b/libobs/build/libobs.core-source+.h.c index d5b941beb5..d43b159069 100644 --- a/libobs/build/libobs.core-source+.h.c +++ b/libobs/build/libobs.core-source+.h.c @@ -31,7 +31,6 @@ #include "libobs/obs-scene-item-blending-method-fields.c.h" #include "libobs/obs-scene-item-blending-mode-fields.c.h" #include "libobs/obs-scene-item-bounds-setters-fields.c.h" -#include "libobs/obs-scene-item-get-group.c.h" #include "libobs/obs-scene-item-group-scene-fields.c.h" #include "libobs/obs-scene-item-hotkey-bridge.c.h" #include "libobs/obs-scene-item-hotkeys-fields.c.h" diff --git a/libobs/build/libobs.ported-scene-item-get-group+.h.c b/libobs/build/libobs.ported-scene-item-get-group+.h.c new file mode 100644 index 0000000000..93746b8832 --- /dev/null +++ b/libobs/build/libobs.ported-scene-item-get-group+.h.c @@ -0,0 +1,5 @@ +/* Unity group (BUILD.md): original parent-group query for the C reference. */ + +#include "libobs/build/libobs.pch.h" + +#include "libobs/obs-scene-item-get-group.c.h" diff --git a/libobs/build/ported-source-sets/scene-item-get-group.json b/libobs/build/ported-source-sets/scene-item-get-group.json new file mode 100644 index 0000000000..88f9e1833c --- /dev/null +++ b/libobs/build/ported-source-sets/scene-item-get-group.json @@ -0,0 +1,5 @@ +{ + "LIBOBS_PORTED_SOURCES": [ + "build/libobs.ported-scene-item-get-group+.h.c" + ] +} diff --git a/libobs/cmake/rust-exports.d/obs-scene-item_get_group.txt b/libobs/cmake/rust-exports.d/obs-scene-item_get_group.txt new file mode 100644 index 0000000000..528e933feb --- /dev/null +++ b/libobs/cmake/rust-exports.d/obs-scene-item_get_group.txt @@ -0,0 +1 @@ +obs_sceneitem_get_group diff --git a/rust/README.md b/rust/README.md index a2c5b07f13..a0d20e968a 100644 --- a/rust/README.md +++ b/rust/README.md @@ -372,6 +372,7 @@ The private output starting/encoder-demand queries use lazy safe Rust decisions | `libobs/obs-scene-ref.c.h` | `obs-scene::refs` | Scene ownership delegates to the existing source API without a separate counter. Preserves NULL no-ops, argument scene identity on successful promotion, one source retain/release and expiry. Tier 1 mirrors unchanged `test_scene_ref`; Tier 3 uses original scene/source C bodies and real private layouts. No intentional differences. | | `libobs/obs-scene-render-plan.c.h` | `obs-scene::render_plan` | Swapped in hybrid `libobs` (group `libobs.ported-scene-render-plan`). The per-item render decisions of `render_item()` and `render_item_texture()`, one hidden function each, called where the C made the decision with the values it read there: whether the item is drawn through its texrender (`obs_scene_render_texture_enabled`: a crop or bounds crop, a scale filter, sRGB off, a blend mode other than Normal, or a nested scene that is not a group); keep, destroy, create or recreate the texrender; the empty-source gate of #573 (a running show/hide transition is still rendered, at size 0); the clear colour (#1406: white for Darken); the child drawn (show transition, hide transition or source); the linear sRGB state; whether a directly drawn source gets centred texture coordinates (`obs_scene_texcoords_centered`, the C's `memcmp` against the identity with floored x and y translation, so the Rust compares every entry's bits); the effect (Point's sampler, the base dimension, the low-resolution bilinear effect below 0.5, Bicubic, Lanczos, Area and its upscale, with `fabsf(scale - 1) <= EPSILON` in `f32`); the SDR white multiplier; and the technique. `obs-scene.c.h` keeps every `gs_*` call in its order, `obs_source_video_render()`, the texrender objects, `obs_get_video_sdr_white_level()` (passed as a value; now read for every space pair, a plain getter), the blend table (#1521) and `calc_cx`/`calc_cy` (#1947), and maps the effect and technique values to `obs->video.*` and the technique names; `gs_texrender_get_format()` is still asked only with a texrender that is wanted, and each transition only when the item's visibility selects it. `struct obs_scene_render_triggers` and `struct obs_scene_render_effect_plan` are mirrored; the triggers and `&item->draw_transform` (obs-graphics' `matrix4`) are read through pointers. The enum values cross as `int`; `obs-scene.c.h` checks the mirrored constants and the enum sizes at compile time. Kept, characterized, not endorsed: a white level of 0 gives `80.f / 0`, +inf; a NaN output scale is never close to 1 nor below 0.5, so the filter's own effect is used and Area does not upscale; a quiet NaN or infinite translation counts as centred, and a -0.0 anywhere but the translation does not. `test_scene_render_plan_steps` compiles the C into itself, and `test_scene_render_plan_steps_rust` runs the same test source against `libobs_rust-static`; `test_item_transition_empty_source`, `test_darken_transparent`, `test_scene_rotated_scale_filter`, `test_scene_blend`, `test_visibility_transition` and `test_group_hide_transition_audio` see the swap through the hybrid. Tier 3 compares every output field by field, bit for bit, exhaustively over the enums and flags and with proptests over bit-pattern floats and matrices. No intentional differences. | | `libobs/obs-scene-item-alignment-setter.c.h` | `obs-scene::item_alignment_setter` | Swapped in hybrid `libobs`. Safe Rust stores every alignment bit between the existing C-owned captured-parent fields lock/unlock, then unconditionally calls the C-owned bounds transform update. NULL is silent; unchanged values still update. Tier 1 mirrors the characterization, unchanged Tier 2 covers live dispatch and callbacks, and Tier 3 compares original C whole-item bytes, alignment at update, call counts and mutex state for arbitrary bits and defer counts. No intentional differences; no network protocol (Tier 4 inapplicable). | +| `libobs/obs-scene-item-get-group.c.h` | `obs-scene::item_get_group` | Swapped in hybrid `libobs`. Safe Rust rejects a NULL scene or item before any read, and a group item (read through the existing `obs_sceneitem_group_scene_flag` adapter) before any lock, then takes the C-owned full lock once around the C-owned walk (`obs_sceneitem_parent_group_lookup`, shared with the reorder callers) and returns its result as a borrowed pointer, with no reference taken. Kept, characterized, not endorsed (the walk's behaviour): the removed flag is not consulted and a NULL parent matches a NULL group context. Tier 1 mirrors every assertion of the unchanged `test_sceneitem_get_group`; Tier 2 runs it against both libobs builds; Tier 3 compares the original C wrapper on the same fixture (result pointer, lock/walk trace, every scene and item byte) with mutants for a missing unlock, an unlocked walk, locking a group item, a second flag read and a dropped result. No intentional differences; no network protocol (Tier 4 inapplicable). | | `libobs/obs-scene-item-audio-actions.c.h` | `obs-scene::item_audio_actions` | Swapped in hybrid `libobs` (group `libobs.ported-scene-item-audio-actions`). The scene item's side of the visibility audio ramp: `apply_scene_item_audio_actions()`, `apply_scene_item_volume()` and `process_all_audio_actions()`, declared in `obs-internal.h` without `EXPORT`, so the shims stay hidden. The safe core works on an `ItemAudio` trait; the shim reaches the item only through the live adapter `obs-scene-item-audio-actions-fields.c.h` (the `actions_mutex` lock and unlock, the queue's address, the atomic `visible` load and store, the atomic `active_refs` decrement, and the two sources of the removal), so `struct obs_scene_item` is not mirrored, and applies the queue with the `audio_actions` shim in place. It keeps the C's order: the visibility copied, passed to the core and written back under the lock; the reference drops and `obs_source_remove_active_child()` after the unlock; the first action copied under the lock and its window checked after it. Kept, characterized, not endorsed: every hide drops a reference, without bound, and the child is removed only on a drop to 0; the window looks at the first action only. Tier 3 runs the original C over the original C core and the same adapter, with every lock, atomic and removal recorded in one trace, and compares the trace, the item, every byte the queue held, the gains and the return value. Intentional difference, where C has undefined behaviour and libobs never gets there: a null item does nothing. The core's own differences (a rate of 0 for the window, `ts` 0 with a buffer) are the only inputs Tier 3 leaves out. `test_scene_audio_action_steps` compiles the C item side into itself and stays the C characterization; the real-libobs `test_scene_audio_actions` covers the swap. | | `libobs/obs-scene-item-blending-mode.c.h` | `obs-scene::item_blending_mode` | Swapped in hybrid `libobs`; preserves arbitrary blend enum bits, null diagnostics and atomic transform invalidation through private C adapters. Complete real-item byte parity and enum storage layout checks cover the boundary. No intentional differences. | | `libobs/obs-scene-item-blending-method.c.h` | `obs-scene::item_blending_method` | Stores nonnegative enum values verbatim, preserving NULL diagnostics and every surrounding item byte, including transform dirtiness. Private C field access follows Rust NULL validation; callback-only exact differential parity covers repeated writes. No intentional differences. | diff --git a/rust/obs-build/tests/native.rs b/rust/obs-build/tests/native.rs index a6a8cab241..41372e9346 100644 --- a/rust/obs-build/tests/native.rs +++ b/rust/obs-build/tests/native.rs @@ -29,6 +29,8 @@ mod canonical_qt_core_filename_is_registered; mod canonical_rust_static_windows_keys_are_registered; #[path = "native/registration/canonical_scene_item_alignment_setter_swap_is_registered.rs"] mod canonical_scene_item_alignment_setter_swap_is_registered; +#[path = "native/registration/canonical_scene_item_get_group_swap_is_registered.rs"] +mod canonical_scene_item_get_group_swap_is_registered; #[path = "native/registration/canonical_source_canvas_getter_swap_is_registered.rs"] mod canonical_source_canvas_getter_swap_is_registered; #[path = "native/registration/canonical_source_configurable_swap_is_registered.rs"] diff --git a/rust/obs-build/tests/native/registration/canonical_scene_item_get_group_swap_is_registered.rs b/rust/obs-build/tests/native/registration/canonical_scene_item_get_group_swap_is_registered.rs new file mode 100644 index 0000000000..51f64ebf72 --- /dev/null +++ b/rust/obs-build/tests/native/registration/canonical_scene_item_get_group_swap_is_registered.rs @@ -0,0 +1,37 @@ +use super::*; + +#[test] +fn canonical_scene_item_get_group_swap_is_registered() { + use obs_build::validation::graph::{Graph, Source}; + let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."); + let mut graph = Graph::load(&root.join("test/cmocka/build/test-graph.json")).unwrap(); + let name = "test_sceneitem_get_group"; + graph.targets.retain(|key, _| key == name); + graph.tests.retain(|key, _| key == name); + for os in ["OS_LINUX", "OS_MACOS", "OS_WINDOWS"] { + let selected = graph.select(&[(os.into(), true)].into()).unwrap(); + assert!( + matches!(selected.targets[name].sources.as_slice(), [Source::Path(path)] + if path == "test/cmocka/test_sceneitem_get_group.c") + ); + assert_eq!(selected.tests[name].target, name); + } + let ported = + fs::read_to_string(root.join("libobs/build/ported-source-sets/scene-item-get-group.json")) + .unwrap(); + assert!(ported.contains("build/libobs.ported-scene-item-get-group+.h.c")); + let group = + fs::read_to_string(root.join("libobs/build/libobs.ported-scene-item-get-group+.h.c")) + .unwrap(); + assert!(group.contains("#include \"libobs/obs-scene-item-get-group.c.h\"")); + let hybrid = fs::read_to_string(root.join("libobs/build/libobs.core-source+.h.c")).unwrap(); + assert!(!hybrid.contains("#include \"libobs/obs-scene-item-get-group.c.h\"")); + // The C-owned seams stay in the production group: the full lock and the + // shared parent-group walk in obs-scene.c.h, the group-flag adapter beside it. + assert!(hybrid.contains("#include \"libobs/obs-scene.c.h\"")); + assert!(hybrid.contains("#include \"libobs/obs-scene-item-group-scene-fields.c.h\"")); + let exports = + fs::read_to_string(root.join("libobs/cmake/rust-exports.d/obs-scene-item_get_group.txt")) + .unwrap(); + assert_eq!(exports.trim(), "obs_sceneitem_get_group"); +} diff --git a/rust/obs-c-oracle/oracle/scene_item_get_group.c b/rust/obs-c-oracle/oracle/scene_item_get_group.c index 30a0d79c69..fb0f44ce20 100644 --- a/rust/obs-c-oracle/oracle/scene_item_get_group.c +++ b/rust/obs-c-oracle/oracle/scene_item_get_group.c @@ -163,8 +163,8 @@ unsigned oracle_scene_item_get_group_probe(unsigned bits, get_group_fn rust) result |= 4; bool rejected = (bits & 7) != 0; if (rejected ? expected.count != 0 - : expected.count != 3 || expected.events[0] != EV_LOCK || expected.events[1] != (EV_LOOKUP | 0x10) || - expected.events[2] != EV_UNLOCK) + : expected.count != 3 || expected.events[0] != EV_LOCK || + expected.events[1] != (EV_LOOKUP | 0x10) || expected.events[2] != EV_UNLOCK) result |= 8; return result; } diff --git a/rust/obs-scene/src/ffi/item_get_group.rs b/rust/obs-scene/src/ffi/item_get_group.rs index 291b22a7df..7777b508cd 100644 --- a/rust/obs-scene/src/ffi/item_get_group.rs +++ b/rust/obs-scene/src/ffi/item_get_group.rs @@ -37,14 +37,18 @@ impl Query for Live { } } -/// RED stub: not exported, so the C wrapper still links; always NULL. +/// The group item holding `item` in `scene`, borrowed (no reference taken). /// /// # Safety /// Non-null arguments must be a live scene and a readable scene item, as in C. +#[unsafe(no_mangle)] pub unsafe extern "C" fn obs_sceneitem_get_group( scene: *mut c_void, item: *mut c_void, ) -> *mut c_void { - let _ = (scene, item, item_get_group::get_group::); - ptr::null_mut() + let (Some(scene), Some(item)) = (NonNull::new(scene), NonNull::new(item)) else { + return ptr::null_mut(); + }; + item_get_group::get_group(Some(&mut Live { scene, item })) + .map_or(ptr::null_mut(), NonNull::as_ptr) } diff --git a/rust/obs-scene/src/item_get_group.rs b/rust/obs-scene/src/item_get_group.rs index 73fc93b60d..56cb879093 100644 --- a/rust/obs-scene/src/item_get_group.rs +++ b/rust/obs-scene/src/item_get_group.rs @@ -17,6 +17,12 @@ pub trait Query { /// A missing scene or item, or a group item, is `None` without locking. /// Otherwise the walk's result is returned as is, under exactly one lock. pub fn get_group(query: Option<&mut Q>) -> Option { - let _ = query; - None // RED stub: the query is not ported yet. + let query = query?; + if query.is_group() { + return None; + } + query.lock(); + let group = query.lookup(); + query.unlock(); + group }