Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Crash when calling back through method withref ValueType parameter #965

Closed
Labels
@zooba

Description

@zooba

Hi. In response tothis 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 ishere in the PythonNet code:

        for (var i = 0; i < parameters.Length; ++i)        {            il.Emit(OpCodes.Ldloc_0);            il.Emit(OpCodes.Ldc_I4, i);            il.Emit(OpCodes.Ldarg, i + 1);            if (parameterTypes[i].IsValueType)            {                il.Emit(OpCodes.Box, parameterTypes[i]);            }            il.Emit(OpCodes.Stelem, typeof(object));        }

The code is trying to store all of the incoming arguments in an array of type Object[]. The cases are:

  1. If the incoming argument is of reference type, the reference can simply be stored in the array.
  2. If the incoming argument is of struct type, the argument needs to be boxed into an object, which can then be stored in the array.
  3. If the incoming argument is a “byref” (i.e., “ref” keyword in C#), more complicated handling is needed, including:
    oOn 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.
    oOn 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.

The code above handles#1 and#2, but doesn’t handle#3.


Hopefully that's enough for someone to create or contribute a fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp