[Mono-list] Embedded API: thunk value type parameters and return types

Jonathan Mitchell lists at mugginsoft.com
Thu Sep 22 20:22:08 UTC 2016


I am trying to upgrade some method invoke based code to used thunks.

The comments for mono_method_get_unmanaged_thunk() say:

 * LIMITATIONS
 *
 * Value type arguments and return values are treated as they were objects:
 *
 * C#: public static Rectangle Intersect (Rectangle a, Rectangle b);
 * C:  typedef MonoObject* (*Intersect)(MonoObject*, MonoObject*, MonoException**);
 *
 * Arguments must be properly boxed upon trunk's invocation, while return
 * values must be unboxed.

However it seems that primitive value types are returned unboxed while non primitive value types are not.
Does the same apply for thunk parameters?
Are primitive value parameters based by value and non primitive value parameters as a boxed reference?

// Obj-C
// non primitive value type
    - (NSDate *)date
    {
		typedef MonoObject* (*Thunk)(MonoObject *, MonoObject**);
		static Thunk thunk;
		MonoObject *monoException = NULL;
		if (!thunk) {
			MonoMethod *monoMethod = GetPropertyGetMethod(self.monoClass, "Date");
			thunk = (Thunk)mono_method_get_unmanaged_thunk(monoMethod);
		}
		MonoObject *monoObject = thunk(self.monoObject, &monoException);
		if (monoException != NULL) @throw(NSExceptionFromMonoException(monoException, @{}));

		if ([self object:_date isEqualToMonoObject:monoObject]) return _date;					
		_date = [NSDate dateWithMonoDateTime:monoObject];

		return _date;
	}

// primitive value type
    - (int64_t)int64Number
    {
		typedef int64_t (*Thunk)(MonoObject *, MonoObject**);
		static Thunk thunk;
		MonoObject *monoException = NULL;
		if (!thunk) {
			MonoMethod *monoMethod = GetPropertyGetMethod(self.monoClass, "Int64Number");
			thunk = (Thunk)mono_method_get_unmanaged_thunk(monoMethod);
		}
		_int64Number = thunk(self.monoObject, &monoException);
		if (monoException != NULL) @throw(NSExceptionFromMonoException(monoException, @{}));
		return _int64Number;
	}


More information about the Mono-list mailing list