Exemple #1
0
        static unsafe void InitializeCoreCLRBridge(InitializationOptions *options)
        {
            if (options->xamarin_objc_msgsend != IntPtr.Zero)
            {
                ObjectiveCMarshal.SetMessageSendCallback(ObjectiveCMarshal.MessageSendFunction.MsgSend, options->xamarin_objc_msgsend);
            }

            if (options->xamarin_objc_msgsend_super != IntPtr.Zero)
            {
                ObjectiveCMarshal.SetMessageSendCallback(ObjectiveCMarshal.MessageSendFunction.MsgSendSuper, options->xamarin_objc_msgsend_super);
            }

            if (options->xamarin_objc_msgsend_stret != IntPtr.Zero)
            {
                ObjectiveCMarshal.SetMessageSendCallback(ObjectiveCMarshal.MessageSendFunction.MsgSendStret, options->xamarin_objc_msgsend_stret);
            }

            if (options->xamarin_objc_msgsend_super_stret != IntPtr.Zero)
            {
                ObjectiveCMarshal.SetMessageSendCallback(ObjectiveCMarshal.MessageSendFunction.MsgSendSuperStret, options->xamarin_objc_msgsend_super_stret);
            }

            delegate * unmanaged <void> beginEndCallback            = (delegate * unmanaged <void>)options->reference_tracking_begin_end_callback;
            delegate * unmanaged <IntPtr, int> isReferencedCallback = (delegate * unmanaged <IntPtr, int>)options->reference_tracking_is_referenced_callback;
            delegate * unmanaged <IntPtr, void> trackedObjectEnteredFinalization = (delegate * unmanaged <IntPtr, void>)options->reference_tracking_tracked_object_entered_finalization;
            ObjectiveCMarshal.Initialize(beginEndCallback, isReferencedCallback, trackedObjectEnteredFinalization, UnhandledExceptionPropagationHandler);
        }
Exemple #2
0
        private static void ValidateSetMessageSendPendingExceptionImpl(MessageSendFunction msgSend)
        {
            if (!LibObjC.SupportedOnPlatform(msgSend))
            {
                return;
            }

            IntPtr func = msgSend switch
            {
                MessageSendFunction.MsgSend => (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, IntPtr>) & MsgSend,
                MessageSendFunction.MsgSendFpret => (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, IntPtr>) & MsgSendFpret,
                MessageSendFunction.MsgSendStret => (IntPtr)(delegate * unmanaged <IntPtr *, IntPtr, IntPtr, void>) & MsgSendStret,
                MessageSendFunction.MsgSendSuper => (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, IntPtr>) & MsgSendSuper,
                MessageSendFunction.MsgSendSuperStret => (IntPtr)(delegate * unmanaged <IntPtr *, IntPtr, IntPtr, void>) & MsgSendSuperStret,
                _ => throw new Exception($"Unknown {nameof(MessageSendFunction)}"),
            };

            // Override message send function
            //
            // We are using the overriding mechanism to enable validating in the Libraries test suite.
            // Technically any Objective-C code that is entered via msgSend could call the managed SetMessageSendPendingException()
            // and it would be thrown when returning from the P/Invoke. This approach avoids us having to
            // create a pure Objective-C library for testing this behavior.
            ObjectiveCMarshal.SetMessageSendCallback(msgSend, func);

            // Call message send function through P/Invoke
            IntPtr inst = IntPtr.Zero;
            IntPtr sel  = IntPtr.Zero;

            Exception ex = Assert.Throws <PendingException>(() => LibObjC.CallPInvoke(msgSend, inst, sel));

            Assert.Equal(msgSend.ToString(), ex.Message);
        }