Example #1
0
        static void Validate_ReferenceTrackingAPIs_InvalidArgs()
        {
            Console.WriteLine($"Running {nameof(Validate_ReferenceTrackingAPIs_InvalidArgs)}...");

            delegate * unmanaged <void> beginEndCallback;
            delegate * unmanaged <IntPtr, int> isReferencedCallback;
            delegate * unmanaged <IntPtr, void> trackedObjectEnteredFinalization;
            NativeObjCMarshalTests.GetExports(out beginEndCallback, out isReferencedCallback, out trackedObjectEnteredFinalization);

            Assert.Throws <ArgumentNullException>(
                () =>
            {
                ObjectiveCMarshal.Initialize(null, isReferencedCallback, trackedObjectEnteredFinalization, OnUnhandledExceptionPropagationHandler);
            });
            Assert.Throws <ArgumentNullException>(
                () =>
            {
                ObjectiveCMarshal.Initialize(beginEndCallback, null, trackedObjectEnteredFinalization, OnUnhandledExceptionPropagationHandler);
            });
            Assert.Throws <ArgumentNullException>(
                () =>
            {
                ObjectiveCMarshal.Initialize(beginEndCallback, isReferencedCallback, null, OnUnhandledExceptionPropagationHandler);
            });
            Assert.Throws <ArgumentNullException>(
                () =>
            {
                ObjectiveCMarshal.Initialize(beginEndCallback, isReferencedCallback, trackedObjectEnteredFinalization, null);
            });
            Assert.Throws <ArgumentNullException>(
                () =>
            {
                ObjectiveCMarshal.CreateReferenceTrackingHandle(null, out _);
            });
        }
Example #2
0
        // See  "Toggle-ref support for CoreCLR" in coreclr-bridge.m for more information.
        internal static void RegisterToggleReferenceCoreCLR(NSObject obj, IntPtr handle, bool isCustomType)
        {
            var gchandle = ObjectiveCMarshal.CreateReferenceTrackingHandle(obj, out var info);

            unsafe {
                TrackedObjectInfo *tracked_info;

                fixed(void *ptr = info)
                tracked_info = (TrackedObjectInfo *)ptr;

                tracked_info->Handle      = handle;
                tracked_info->Flags       = obj.FlagsInternal;
                obj.tracked_object_info   = tracked_info;
                obj.tracked_object_handle = gchandle;

                log_coreclr($"RegisterToggleReferenceCoreCLR ({obj.GetType ().FullName}, 0x{handle.ToString ("x")}, {isCustomType}) => Info=0x{((IntPtr) tracked_info).ToString ("x")} Flags={tracked_info->Flags}");
            }

            // Make sure the GCHandle we have is a weak one for custom types.
            if (isCustomType)
            {
                xamarin_switch_gchandle(handle, true);
            }
        }