[Mono-list] Embedded API: static constructor calling
jonathan at mugginsoft.com
jonathan at mugginsoft.com
Tue Oct 1 14:54:00 UTC 2013
On 1 Oct 2013, at 15:35, Robert Jordan <robertj at gmx.net> wrote:
> On 01.10.2013 15:16, jonathan at mugginsoft.com wrote:
>>
>> On 1 Oct 2013, at 14:01, Robert Jordan <robertj at gmx.net> wrote:
>>
>>> mono_field_get_value_object is not mono_field_STATIC_get!
>>> You are looking at the wrong function.
>>>
>>
>> Sorry. I was trying to imply that, as in mono_field_get_value_object, that mono_field_static_get_value should do its own vtable setup.
>> This looks like a bug.
>
> I don't think this is a bug. mono_field_static_get/set and
> mono_field_get/set behave pretty much the same: Both require
> that the ctor was already invoked. The former requires
> mono_runtime_class_init () whereas the latter needs
> mono_runtime_object_init () or an explicit non-default ctor
> invocation.
>
> mono_field_get_value_object () is somewhat different because it
> deals with both static and instance fields. It's more elaborated
> (and slower), and serves different purposes (maybe it's used by System.Reflection, I did't check).
I understand now that there is a corollary between mono_runtime_object_init and mono_runtime_class_init.
I noted that calling a static method does trigger the static constructor.
So the requirement might be that mono_runtime_class_init has to be called prior to static field access if a static method has not previously been called.
That sounds rather fragile.
So your solution of always calling mono_runtime_class_init prior to static field access is perhaps the most practical solution.
Jonathan
More information about the Mono-list
mailing list