[Mono-dev] add_internal_call with int32[]
Jonathan Mitchell
lists at mugginsoft.com
Mon Apr 30 15:54:16 UTC 2018
> On 30 Apr 2018, at 16:17, pierre <pierre.saunier at ppmodeler.com> wrote:
>
> Yes, this is working...
> but how can I do If I have an int32_t array in the embedder (on a linux64 system for example, where int is mapped to int64_t)?
> or the opposite, If I have an int64_t array in the embedder (on a windows64 system where int is mapped to int32_t)?
The embedded signatures use C# type names as opposed to the .NET framework type names.
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/built-in-types-table
So in one of my macOS 64bit Objective-C methods I have:
/*!
Managed method name : Sum
Managed return type : System.Int64
Managed param types : System.Int64[]
*/
- (int64_t)sum_withInt64Array:(System_Array *)p1
{
MonoObject *monoObject = [self invokeMonoMethod:"Sum(long[])" withNumArgs:1, [p1 monoRTInvokeArg]]; // defined in Dubrovnik see below
return DB_UNBOX_INT64(monoObject);
}
#define DB_UNBOX_INT64( x ) ( *(int64_t *)mono_object_unbox( x ) )
To me it seems that 64 bits managed maps to 64 bits unmanaged quite naturally.
If it didn’t all hell would break loose in my case.
Of course Mono runs on a ton of different platforms so things may be different in other situations.
The Dubrovnik unit tests demonstrate calling a number of more complex method signatures.
https://github.com/ThesaurusSoftware/Dubrovnik/blob/BPUKM-1819/Framework/XCode/Dubrovnik%20Unit%20Tests/Dubrovnik_Unit_Tests.m
Jonathan
>
>
>
> On 30/04/2018 17:10, Jonathan Mitchell wrote:
>>
>> Try
>>
>> mono_add_internal_call("testObj::mono_testObj_fromInts(object,int[])", mono_testObj_fromInts);
>>
>> It’s very handy to have some utility code to iterate over a managed class and dump out the native method signatures.
>> It can save a lot of time when you have complex signatures.
>>
>> Jonathan
>>
>>> On 30 Apr 2018, at 16:05, pierre <pierre.saunier at ppmodeler.com> wrote:
>>>
>>> Hi,
>>>
>>> I am having trouble with the following code:
>>>
>>> [MethodImplAttribute(MethodImplOptions.InternalCall)]
>>> static extern private void mono_testObj_fromInts(object testObj, Int32[] from);
>>> public void fromInts(Int32[] from)
>>> {
>>> mono_testObj_fromInts(this, (Int32[])from);
>>> }
>>> and in the embedder:
>>>
>>> mono_add_internal_call("testObj::mono_testObj_fromInts(object,int32[])", mono_testObj_fromInts);
>>>
>>> when run, I got the error:
>>> An exception was thrown when calling Script:Main: (System.MissingMethodException) Attempted to access a missing method.
>>> StackTrace:
>>> at (wrapper managed-to-native) testObj.mono_testObj_fromInts(object,int[])
>>> of course, if I change the mono_add_internal_call to use int[] it is working... but, if I do that, and if I have understood properly, on some systems, int is mapped to int32_t and on other to int64_t.
>>> How can I make the mono_add_internal_call to work with int or int32 or int64?
>>>
>>>
>>> Thanks,
>>>
>>> Pierre
>>>
>>> _______________________________________________
>>> Mono-devel-list mailing list
>>> Mono-devel-list at lists.dot.net
>>> http://lists.dot.net/mailman/listinfo/mono-devel-list
>>
>>
>>
>> _______________________________________________
>> Mono-devel-list mailing list
>>
>> Mono-devel-list at lists.dot.net
>> http://lists.dot.net/mailman/listinfo/mono-devel-list
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.dot.net
> http://lists.dot.net/mailman/listinfo/mono-devel-list
More information about the Mono-devel-list
mailing list