-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[Mono] [swift-interop] Add support for reverse pinvoke argument lowering #104437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f4a08ad
f113643
ad59f6d
d703585
4af9745
bbf5612
b40a633
6ebc9bd
12ff9d8
3912225
e6401cb
f95d478
9e1f6e2
b7e8f35
a176c16
cb449f9
022eab3
96a2cb9
903d7b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4103,6 +4103,8 @@ marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, Mono | |||||
int i; | ||||||
EmitMarshalContext m; | ||||||
gboolean marshalling_enabled = FALSE; | ||||||
int *swift_sig_to_csig_mp = NULL; | ||||||
SwiftPhysicalLowering *swift_lowering = NULL; | ||||||
|
||||||
g_assert (method != NULL); | ||||||
error_init (error); | ||||||
|
@@ -4183,6 +4185,50 @@ marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, Mono | |||||
csig->hasthis = 0; | ||||||
csig->pinvoke = 1; | ||||||
|
||||||
if (invoke) | ||||||
mono_marshal_set_callconv_from_modopt (invoke, csig, TRUE); | ||||||
else | ||||||
mono_marshal_set_callconv_from_unmanaged_callers_only_attribute (method, csig); | ||||||
|
||||||
if (mono_method_signature_has_ext_callconv (csig, MONO_EXT_CALLCONV_SWIFTCALL)) { | ||||||
MonoClass *swift_self = mono_class_try_get_swift_self_class (); | ||||||
MonoClass *swift_error = mono_class_try_get_swift_error_class (); | ||||||
MonoClass *swift_indirect_result = mono_class_try_get_swift_indirect_result_class (); | ||||||
swift_lowering = g_newa (SwiftPhysicalLowering, sig->param_count); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where are these deallocated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Added deallocation for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Why they are allocated differently? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The runtime/src/mono/mono/mini/method-to-ir.c Line 7533 in f9eda07
|
||||||
swift_sig_to_csig_mp = g_newa (int, sig->param_count); | ||||||
GArray *new_params = g_array_sized_new (FALSE, FALSE, sizeof (MonoType*), csig->param_count); | ||||||
int new_param_count = 0; | ||||||
|
||||||
|
||||||
for (i = 0; i < csig->param_count; i++) { | ||||||
swift_lowering [i] = (SwiftPhysicalLowering){0}; | ||||||
swift_sig_to_csig_mp [i] = new_param_count; | ||||||
MonoType *ptype = csig->params [i]; | ||||||
MonoClass *klass = mono_class_from_mono_type_internal (ptype); | ||||||
|
||||||
if (mono_type_is_struct (ptype) && !(klass == swift_self || klass == swift_error || klass == swift_indirect_result)) { | ||||||
SwiftPhysicalLowering lowered_swift_struct = mono_marshal_get_swift_physical_lowering (ptype, FALSE); | ||||||
swift_lowering [i] = lowered_swift_struct; | ||||||
if (!lowered_swift_struct.by_reference) { | ||||||
for (uint32_t idx_lowered = 0; idx_lowered < lowered_swift_struct.num_lowered_elements; idx_lowered++) { | ||||||
g_array_append_val (new_params, lowered_swift_struct.lowered_elements [idx_lowered]); | ||||||
new_param_count++; | ||||||
} | ||||||
} else { | ||||||
ptype = mono_class_get_byref_type (klass); | ||||||
g_array_append_val (new_params, ptype); | ||||||
new_param_count++; | ||||||
} | ||||||
} else { | ||||||
g_array_append_val (new_params, ptype); | ||||||
new_param_count++; | ||||||
} | ||||||
} | ||||||
|
||||||
csig = mono_metadata_signature_dup_new_params (NULL, m_method_get_mem_manager (method), csig, new_param_count, (MonoType**)new_params->data); | ||||||
g_array_free (new_params, TRUE); | ||||||
} | ||||||
|
||||||
if (!marshalling_enabled) | ||||||
csig->marshalling_disabled = 1; | ||||||
|
||||||
|
@@ -4194,11 +4240,8 @@ marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, Mono | |||||
m.csig = csig; | ||||||
m.image = get_method_image (method); | ||||||
m.runtime_marshalling_enabled = marshalling_enabled; | ||||||
|
||||||
if (invoke) | ||||||
mono_marshal_set_callconv_from_modopt (invoke, csig, TRUE); | ||||||
else | ||||||
mono_marshal_set_callconv_from_unmanaged_callers_only_attribute(method, csig); | ||||||
m.swift_lowering = swift_lowering; | ||||||
m.swift_sig_to_csig_mp = swift_sig_to_csig_mp; | ||||||
|
||||||
/* The attribute is only available in Net 2.0 */ | ||||||
if (delegate_klass && mono_class_try_get_unmanaged_function_pointer_attribute_class ()) { | ||||||
|
@@ -4274,10 +4317,10 @@ marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, Mono | |||||
info->d.native_to_managed.klass = delegate_klass; | ||||||
|
||||||
res = mono_mb_create_and_cache_full (cache, method, | ||||||
mb, csig, sig->param_count + 16, | ||||||
mb, csig, csig->param_count + 16, | ||||||
info, NULL); | ||||||
} else { | ||||||
res = mono_mb_create (mb, csig, sig->param_count + 16, NULL); | ||||||
res = mono_mb_create (mb, csig, csig->param_count + 16, NULL); | ||||||
} | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need a MONO_TYPE_GENERICINST case to handle
SwiftSelf<T>
or other generics?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe currently we do not plan to support
SwiftSelf<T>
in reverse pinvokes #103576 (comment)cc: @kotlarmilos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#103576 (comment)