[Mono-list] Troubling passing DateTime via embedded API
Mitchell Jonathan
mugginsoft at googlemail.com
Fri Jul 26 13:21:43 UTC 2013
On 26 Jul 2013, at 13:48, Robert Jordan <robertj at gmx.net> wrote:
> On 26.07.2013 14:09, jonathan at mugginsoft.com wrote:
>> // validate the Mono representatiom
>> int64_t ticks = DB_UNBOX_INT64(DBMonoObjectGetProperty(monoDateTime, "Ticks"));
>> MonoString *monoString = mono_object_to_string(monoDateTime, NULL);
>
> mono_object_to_string () is buggy with respect to value types:
>
Thanks Robert
Patching mono_object_to_string gives the right string rep.
otest[15354:303] NSDate date = 2013-07-26 13:01:05 +0000 Mono DateTime = 26/07/2013 13:01:05 ticks = 635104404656226816
Will try and figure out what is going on with the tick count.
The tick count looks okay on the C side as far as I can see.
Perhaps the invocation code is at fault here:
MonoObject *DBMonoObjectInvoke(MonoObject *monoObject, const char *methodName, int numArgs, va_list va_args) {
MonoObject *monoException = NULL;
MonoObject *retval = NULL;
MonoClass *klass = mono_object_get_class(monoObject);
MonoMethod *meth = GetMonoObjectMethod(monoObject, methodName);
if(meth != NULL) {
void *invokeObj = mono_class_is_valuetype(klass) ? mono_object_unbox(monoObject) : monoObject;
void *monoArgs[numArgs];
DBPopulateMethodArgsFromVarArgs(monoArgs, va_args, numArgs);
retval = mono_runtime_invoke(meth, invokeObj, monoArgs, &monoException);
}
if(monoException != NULL) @throw(NSExceptionFromMonoException(monoException));
return(retval);
}
// mono_object_to_string is buggy
// https://github.com/mono/mono/pull/708/files
MonoString *
mono_object_to_string_ex (MonoObject *obj, MonoObject **exc)
{
static MonoMethod *to_string = NULL;
MonoMethod *method;
void *target = obj;
//g_assert (obj);
if (!to_string)
to_string = mono_class_get_method_from_name_flags (mono_get_object_class (), "ToString", 0, 0x0040 | 0x0006);
method = mono_object_get_virtual_method (obj, to_string);
// Unbox value type if needed
if (mono_class_is_valuetype (mono_method_get_class (method))) {
target = mono_object_unbox (obj);
}
return (MonoString *) mono_runtime_invoke (method, target, NULL, exc);
}
Jonathan
More information about the Mono-list
mailing list