Files
swift-mirror/test/Runtime/refcount_hooks.swift
T
Mike Ash 3fb5d9c0a6 [Runtime] Fix the swift_retain hook when ObjC interop is disabled.
Mask the non-native bridgeobject bits rather than all spare bits. This prevents us from trying to retain pointers that aren't valid native object pointers.
2026-05-15 17:31:07 -04:00

28 lines
875 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-run-simple-swift(-import-objc-header %S/Inputs/refcount_hooks.h)
// REQUIRES: executable_test
// REQUIRES: OS=macosx || OS=linux-gnu
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime
// Override _swift_allocObject with a no-op wrapper that forwards to the
// original implementation. This ensures the runtime goes through the hooks
// path and exercises the hooks machinery without crashing.
var originalAllocObject: AllocObjectFn = _swift_allocObject
func hookedAllocObject(
_ metadata: UnsafeRawPointer?,
_ requiredSize: Int,
_ requiredAlignmentMask: Int
) -> UnsafeMutableRawPointer? {
return originalAllocObject(metadata, requiredSize, requiredAlignmentMask)
}
_swift_allocObject = hookedAllocObject
// A single print does plenty of refcounting to exercise the hooks.
print("Hello, world.")