Title: Crash when calling back through method with `ref ValueType` parameter · Issue #965 · pythonnet/pythonnet · GitHub
Open Graph Title: Crash when calling back through method with `ref ValueType` parameter · Issue #965 · pythonnet/pythonnet
X Title: Crash when calling back through method with `ref ValueType` parameter · Issue #965 · pythonnet/pythonnet
Description: Hi. In response to this query I had one of my colleagues debug an issue, and he found that PythonNet does not correctly generate code when calling into a function with a "ref ValueType" parameter. In his words: The problem is here in the...
Open Graph Description: Hi. In response to this query I had one of my colleagues debug an issue, and he found that PythonNet does not correctly generate code when calling into a function with a "ref ValueType" parameter. ...
X Description: Hi. In response to this query I had one of my colleagues debug an issue, and he found that PythonNet does not correctly generate code when calling into a function with a "ref ValueType" p...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/965
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crash when calling back through method with `ref ValueType` parameter","articleBody":"Hi. In response to [this query](https://stackoverflow.com/questions/58157606/segfault-when-installing-custom-imessagefilter-in-python-net-app) I had one of my colleagues debug an issue, and he found that PythonNet does not correctly generate code when calling into a function with a \"ref ValueType\" parameter. In his words:\r\n\r\nThe problem is [here](https://github.com/pythonnet/pythonnet/blob/60e6045f6873495170502f0247205a9c923fc1fe/src/runtime/classderived.cs#L397) in the PythonNet code: \r\n\r\n for (var i = 0; i \u003c parameters.Length; ++i)\r\n {\r\n il.Emit(OpCodes.Ldloc_0);\r\n il.Emit(OpCodes.Ldc_I4, i);\r\n il.Emit(OpCodes.Ldarg, i + 1);\r\n if (parameterTypes[i].IsValueType)\r\n {\r\n il.Emit(OpCodes.Box, parameterTypes[i]);\r\n }\r\n il.Emit(OpCodes.Stelem, typeof(object));\r\n }\r\n\r\nThe code is trying to store all of the incoming arguments in an array of type Object[]. The cases are:\r\n1.\tIf the incoming argument is of reference type, the reference can simply be stored in the array.\r\n2.\tIf the incoming argument is of struct type, the argument needs to be boxed into an object, which can then be stored in the array.\r\n3.\tIf the incoming argument is a “byref” (i.e., “ref” keyword in C#), more complicated handling is needed, including:\r\no\tOn the way in, the byref needs to read (via ldobj if the underlying type is a struct, or ldind.ref otherwise) to load the actual argument data that needs to flow through.\r\no\tOn the way out, the byref needs to written (via stobj or stind.ref) to make sure any updates applied by the callee are reflected back to the caller.\r\n\r\nThe code above handles #1 and #2, but doesn’t handle #3.\r\n\r\n---\r\n\r\nHopefully that's enough for someone to create or contribute a fix.","author":{"url":"https://github.com/zooba","@type":"Person","name":"zooba"},"datePublished":"2019-10-02T23:18:24.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/965/pythonnet/issues/965"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7b37714c-17e4-0035-495c-2700396266a0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9128:2F57DA:2FDBA61:308503F:69702DBC |
| html-safe-nonce | 084ca6bc5b4f471df35632fd91cf40e20f3d902a6c9e6557b812a53504edf767 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MTI4OjJGNTdEQToyRkRCQTYxOjMwODUwM0Y6Njk3MDJEQkMiLCJ2aXNpdG9yX2lkIjoiODUwNjgwNTI0NDA1Njg0MTY2MCIsInJlZ2lvbl9lZGdlIjoic2VhIiwicmVnaW9uX3JlbmRlciI6InNlYSJ9 |
| visitor-hmac | c2690754fcedb4c923954a83f04aad14a2e0c83fdbc5a681963ac78ec2238053 |
| hovercard-subject-tag | issue:501772957 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pythonnet/pythonnet/965/issue_layout |
| twitter:image | https://opengraph.githubassets.com/15aeddf28066df01e550d5fa828f55ee82ec59a94eb9745034d37609817bc457/pythonnet/pythonnet/issues/965 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/15aeddf28066df01e550d5fa828f55ee82ec59a94eb9745034d37609817bc457/pythonnet/pythonnet/issues/965 |
| og:image:alt | Hi. In response to this query I had one of my colleagues debug an issue, and he found that PythonNet does not correctly generate code when calling into a function with a "ref ValueType" parameter. ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zooba |
| hostname | github.com |
| expected-hostname | github.com |
| None | 01fa379f5de85ef8e791d09724e69709ce9eb9595278316e0a921312dc88e0bc |
| turbo-cache-control | no-preview |
| go-import | github.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git |
| octolytics-dimension-user_id | 6050430 |
| octolytics-dimension-user_login | pythonnet |
| octolytics-dimension-repository_id | 14748123 |
| octolytics-dimension-repository_nwo | pythonnet/pythonnet |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14748123 |
| octolytics-dimension-repository_network_root_nwo | pythonnet/pythonnet |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | dda91974c069382b0dfa47b2da7e28bd061c8331 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width