[Mono-list] Delegates and inter-assembly custom marshaler lookup
Patrick Hartling
patrick@vrac.iastate.edu
Wed, 21 Jan 2004 15:05:58 -0600
--=-xKFKoKG1wuOPwFXHfRkU
Content-Type: multipart/mixed; boundary="=-nBlE5l0JuOEgzqLd4D4M"
--=-nBlE5l0JuOEgzqLd4D4M
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
I have run across what I think is a bug in Mono's lookup of custom
marshalers associated with delegates. The problem occurs when a
delegate defined in a base class (A.Base in assembly A.dll) has a custom
marshaler for a parameter. If a class drived from A.Base in a different
assembly (B.Derived in assembly B.dll) tries to pass the delegate as a
function pointer to native code, Mono 0.29 hits an assertion failure on
line 2069 of mono/metadata/marshal.c (line 2082 for today's snapshot).
At a high level, mono_reflection_type_from_name() is returning NULL for
the custom marshaler type in question, though I have not nailed down
exactly why this is happening. In mono_reflection_type_from_name(),
info.assembly.name comes back NULL after the call to
mono_reflection_parse_type(). I think that if info.assembly.name were
not NULL, the correct assembly image would be found to get the custom
marshaler.
I have attached C# and C++ code with a makefile that can be used to
repeat the problem I am running into. I have verified that this code
works with the .NET Framework versions 1.0 and 1.1 (compiling the C++
code with Visual C++ 7.0 and 7.1 to match the .NET Framework version
accordingly). The code is more complicated than I would like it to be,
but to the best of my current understanding, it is the least amount of
code I can come up with to demonstrate the crash. Note that in B.cs, a
custom marshaler from the assembly A is used for a P/Invoke call, and it
works fine. For that reason, I concluded that the lookup problem is
related to delegates.
Looking through Bugzilla, it looks as though the first C# attachment
with Bug 43351
(http://bugzilla.ximian.com/showattachment.cgi?attach_id=3D4400) is
related to what I am running into, but that code runs correctly with
Mono 0.29. My guess is that the difference between the two cases is
that I am trying to access a delegate in an external assembly whereas
Marcus' example is contained within a single assembly.
-Patrick
--=20
Patrick L. Hartling | Research Assistant, VRAC
patrick@vrac.iastate.edu | 2274 Howe Hall Room 2624
http://www.vrac.iastate.edu/~patrick/ | http://www.vrac.iastate.edu/
PGP: http://wwwkeys.gpg.cz:11371/pks/lookup?op=3Dget&search=3D0xEBF86398
--=-nBlE5l0JuOEgzqLd4D4M
Content-Disposition: attachment; filename=A.cs
Content-Type: text/plain; name=A.cs; charset=UTF-8
Content-Transfer-Encoding: base64
dXNpbmcgU3lzdGVtOw0KdXNpbmcgU3lzdGVtLlJ1bnRpbWUuSW50ZXJvcFNlcnZpY2VzOw0KDQpu
YW1lc3BhY2UgQQ0Kew0KDQpwdWJsaWMgY2xhc3MgQXJnDQp7DQogICBwcm90ZWN0ZWQgaW50ZXJu
YWwgSW50UHRyIG1SYXdPYmplY3QgPSBJbnRQdHIuWmVybzsNCg0KICAgaW50ZXJuYWwgQXJnKElu
dFB0ciBvYmopDQogICB7DQogICAgICBtUmF3T2JqZWN0ID0gb2JqOw0KICAgfQ0KDQogICBbRGxs
SW1wb3J0KCJhX25hdGl2ZSIsIENoYXJTZXQgPSBDaGFyU2V0LkFuc2kpXQ0KICAgcHJpdmF0ZSBl
eHRlcm4gc3RhdGljIEludFB0ciBuZXdfQXJnKCk7DQoNCiAgIHB1YmxpYyBBcmcoKQ0KICAgew0K
ICAgICAgbVJhd09iamVjdCA9IG5ld19BcmcoKTsNCiAgIH0NCg0KICAgW0RsbEltcG9ydCgiYV9u
YXRpdmUiLCBDaGFyU2V0ID0gQ2hhclNldC5BbnNpKV0NCiAgIHByaXZhdGUgZXh0ZXJuIHN0YXRp
YyBJbnRQdHIgQXJnX2dvKEludFB0ciBvYmopOw0KDQogICBwdWJsaWMgdm9pZCBnbygpDQogICB7
DQogICAgICBBcmdfZ28obVJhd09iamVjdCk7DQogICB9DQp9DQoNCi8vIEN1c3RvbSBtYXJzaGFs
ZXIgZm9yIHRoZSB0eXBlIEEuQXJnIHdoaWNoIHdpbGwgYmUgdXNlZCBhcyBhbiBhdHRyaWJ1dGUg
dG8NCi8vIGEgZGVsZWdhdGUgcGFyYW1ldGVyIGluIHRoZSBjbGFzcyBBLkJhc2UuDQpwdWJsaWMg
Y2xhc3MgQXJnTWFyc2hhbGVyIDogSU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=-nBlE5l0JuOEgzqLd4D4M
Content-Disposition: attachment; filename=B.cs
Content-Type: text/plain; name=B.cs; charset=UTF-8
Content-Transfer-Encoding: base64
dXNpbmcgU3lzdGVtOw0KdXNpbmcgU3lzdGVtLlJ1bnRpbWUuSW50ZXJvcFNlcnZpY2VzOw0KDQpu
YW1lc3BhY2UgQg0Kew0KDQpwdWJsaWMgY2xhc3MgRGVyaXZlZCA6IEEuQmFzZQ0Kew0KICAgcHVi
bGljIERlcml2ZWQoKSA6IGJhc2UoKQ0KICAgew0KICAgfQ0KDQogICBwdWJsaWMgb3ZlcnJpZGUg
dm9pZCBmKEEuQXJnIGEpDQogICB7DQogICAgICBDb25zb2xlLldyaXRlTGluZSgiW0MjXSBCLkRl
cml2ZWQuZigpIGNhbGxpbmcgQS5BcmcuZ28oKSIpOw0KICAgICAgYS5nbygpOw0KICAgfQ0KfQ0K
DQpwdWJsaWMgY2xhc3MgUnVuDQp7DQogICAvLyBMb29raW5nIHVwIEEuQmFzZU1hcnNoYWxlciBp
biB0aGlzIGFzc2VtYmx5IHdvcmtzIGZpbmUuDQogICBbRGxsSW1wb3J0KCJiX25hdGl2ZSIsIENo
YXJTZXQgPSBDaGFyU2V0LkFuc2kpXQ0KICAgcHJpdmF0ZSBleHRlcm4gc3RhdGljIHZvaWQgaGFu
ZGxlQmFzZSgNCiAgICAgIFtNYXJzaGFsQXMoVW5tYW5hZ2VkVHlwZS5DdXN0b21NYXJzaGFsZXIs
DQogICAgICAgICAgICAgICAgIE1hcnNoYWxUeXBlUmVmID0gdHlwZW9mKEEuQmFzZU1hcnNoYWxl
cikpXSBBLkJhc2Ugb2JqKTsNCg0KICAgcHVibGljIHN0YXRpYyB2b2lkIE1haW4oU3RyaW5nW10g
YXJncykNCiAgIHsNCiAgICAgIERlcml2ZWQgb2JqID0gbmV3IERlcml2ZWQoKTsNCiAgICAgIGhh
bmRsZUJhc2Uob2JqKTsNCiAgIH0NCn0NCg0KfQ0K
--=-nBlE5l0JuOEgzqLd4D4M
Content-Disposition: attachment; filename=a_native.cpp
Content-Type: text/x-c++; name=a_native.cpp; charset=UTF-8
Content-Transfer-Encoding: base64
I2luY2x1ZGUgImFfbmF0aXZlLmgiDQoNCiNpZmRlZiBXSU4zMg0KI2RlZmluZSBETExfQVBJIF9f
ZGVjbHNwZWMoZGxsZXhwb3J0KQ0KI2Vsc2UNCiNkZWZpbmUgRExMX0FQSSANCiNlbmRpZg0KDQpj
bGFzcyBCYXNlQWRhcHRlciA6IHB1YmxpYyBCYXNlDQp7DQpwdWJsaWM6DQogICB0eXBlZGVmIHZv
aWQgKCpmX2NhbGxiYWNrX3QpKEFyZyopOw0KICAgZl9jYWxsYmFja190IGZfY2FsbGJhY2s7DQoN
CiAgIHZvaWQgZihBcmcqIGFyZykNCiAgIHsNCiAgICAgIGZfY2FsbGJhY2soYXJnKTsNCiAgIH0N
Cn07DQoNCmV4dGVybiAiQyINCnsNCg0KRExMX0FQSSBBcmcqIG5ld19BcmcoKQ0Kew0KICAgcmV0
dXJuIG5ldyBBcmc7DQp9DQoNCkRMTF9BUEkgdm9pZCBBcmdfZ28oQXJnKiBzZWxmXykNCnsNCiAg
IHNlbGZfLT5nbygpOw0KfQ0KDQpETExfQVBJIEJhc2VBZGFwdGVyKiBuZXdfQmFzZUFkYXB0ZXIo
QmFzZUFkYXB0ZXI6OmZfY2FsbGJhY2tfdCBjYikNCnsNCiAgIEJhc2VBZGFwdGVyKiBvYmogPSBu
ZXcgQmFzZUFkYXB0ZXI7DQogICBvYmotPmZfY2FsbGJhY2sgPSBjYjsNCiAgIHJldHVybiBvYmo7
DQp9DQoNCn0NCg==
--=-nBlE5l0JuOEgzqLd4D4M
Content-Disposition: attachment; filename=a_native.h
Content-Type: text/x-c-header; name=a_native.h; charset=UTF-8
Content-Transfer-Encoding: base64
I2lmbmRlZiBfQV9OQVRJVkVfSF8NCiNkZWZpbmUgX0FfTkFUSVZFX0hfDQoNCiNpbmNsdWRlIDxp
b3N0cmVhbT4NCg0KY2xhc3MgQXJnDQp7DQpwdWJsaWM6DQogICB2b2lkIGdvKCkNCiAgIHsNCiAg
ICAgIHN0ZDo6Y291dCA8PCAiW0MrK10gQXJnOjpnbygpIiA8PCBzdGQ6OmVuZGw7DQogICB9DQp9
Ow0KDQpjbGFzcyBCYXNlDQp7DQpwdWJsaWM6DQogICB2aXJ0dWFsIHZvaWQgZihBcmcqIGFyZykg
PSAwOw0KfTsNCg0KI2VuZGlmDQo=
--=-nBlE5l0JuOEgzqLd4D4M
Content-Disposition: attachment; filename=b_native.cpp
Content-Type: text/x-c++; name=b_native.cpp; charset=UTF-8
Content-Transfer-Encoding: base64
I2luY2x1ZGUgImFfbmF0aXZlLmgiDQoNCiNpZmRlZiBXSU4zMg0KI2RlZmluZSBETExfQVBJIF9f
ZGVjbHNwZWMoZGxsZXhwb3J0KQ0KI2Vsc2UNCiNkZWZpbmUgRExMX0FQSSANCiNlbmRpZg0KDQpl
eHRlcm4gIkMiDQp7DQoNCkRMTF9BUEkgdm9pZCBoYW5kbGVCYXNlKEJhc2UqIG9iaikNCnsNCiAg
IEFyZyBhcmc7DQogICBvYmotPmYoJmFyZyk7DQp9DQoNCn0NCg==
--=-nBlE5l0JuOEgzqLd4D4M
Content-Disposition: attachment; filename=Makefile
Content-Type: text/x-makefile; name=Makefile; charset=UTF-8
Content-Transfer-Encoding: base64
IyBMaW51eA0KQ1NDPQkJbWNzIC9kZWJ1Zw0KTUFLRV9ETEw9CWMrKyAtc2hhcmVkIC1vICRAICQ8
DQpMREZMQUdTPQktTC4gLWxhX25hdGl2ZQ0KTkFUSVZFX0RMTF9BPQlsaWJhX25hdGl2ZS5zbw0K
TkFUSVZFX0RMTF9CPQlsaWJiX25hdGl2ZS5zbw0KDQojIFdpbmRvd3MNCiNDU0M9CQljc2MgL25v
bG9nbyAvZGVidWcNCiNNQUtFX0RMTD0JY2wgL0RXSU4zMiAvbm9sb2dvIC9FSHNjICQ8IC9saW5r
IC9kbGwgL291dDokQA0KI0xERkxBR1M9CS9saWJwYXRoOi4gYV9uYXRpdmUubGliDQojTkFUSVZF
X0RMTF9BPQlhX25hdGl2ZS5kbGwNCiNOQVRJVkVfRExMX0I9CWJfbmF0aXZlLmRsbA0KDQphbGw6
IEEuZGxsIEIuZXhlICQoTkFUSVZFX0RMTF9BKSAkKE5BVElWRV9ETExfQikNCg0KQS5kbGw6IEEu
Y3MNCgkkKENTQykgL3RhcmdldDpsaWJyYXJ5IEEuY3MNCg0KQi5leGU6IEIuY3MNCgkkKENTQykg
Qi5jcyAvcjpBLmRsbA0KDQokKE5BVElWRV9ETExfQSk6IGFfbmF0aXZlLmNwcA0KCSQoTUFLRV9E
TEwpDQoNCiQoTkFUSVZFX0RMTF9CKTogYl9uYXRpdmUuY3BwDQoJJChNQUtFX0RMTCkgJChMREZM
QUdTKQ0KDQpjbGVhbjoNCglybSAtZiAqLmV4ZSAqLmxpYiAqLmV4cCAqLmRsbCAqLnNvICoucGRi
ICoub2JqDQo=
--=-nBlE5l0JuOEgzqLd4D4M--
--=-xKFKoKG1wuOPwFXHfRkU
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQBADumr5DgSg+v4Y5gRAvd1AJwPUICwC/GDPZwz5pOEolFu6gEP/QCfRNLw
DtZtoyLTlnNSCms6sw0pXVs=
=BjIZ
-----END PGP SIGNATURE-----
--=-xKFKoKG1wuOPwFXHfRkU--