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

Commit8639f09

Browse files
committed
Merge remote-tracking branch 'upstream/master' into domain-reload-test-cases-fixes
2 parents94f29a7 +9307bb3 commit8639f09

File tree

6 files changed

+29
-16
lines changed

6 files changed

+29
-16
lines changed

‎src/runtime/interop.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,9 @@ internal static Type GetPrototype(string name)
491491
returnpmap[name]asType;
492492
}
493493

494+
495+
internalstaticDictionary<IntPtr,Delegate>allocatedThunks=newDictionary<IntPtr,Delegate>();
496+
494497
internalstaticThunkInfoGetThunk(MethodInfomethod,stringfuncType=null)
495498
{
496499
Typedt;
@@ -505,6 +508,7 @@ internal static ThunkInfo GetThunk(MethodInfo method, string funcType = null)
505508
}
506509
Delegated=Delegate.CreateDelegate(dt,method);
507510
varinfo=newThunkInfo(d);
511+
allocatedThunks[info.Address]=d;
508512
returninfo;
509513
}
510514

‎src/runtime/managedtype.cs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ internal static int PyVisit(IntPtr ob, IntPtr visit, IntPtr arg)
178178
{
179179
return0;
180180
}
181-
varvisitFunc=(Interop.ObjObjFunc)Marshal.GetDelegateForFunctionPointer(visit,typeof(Interop.ObjObjFunc));
181+
varvisitFunc=NativeCall.GetDelegate<Interop.ObjObjFunc>(visit);
182182
returnvisitFunc(ob,arg);
183183
}
184184

@@ -196,7 +196,7 @@ internal void CallTypeClear()
196196
{
197197
return;
198198
}
199-
varclearFunc=(Interop.InquiryFunc)Marshal.GetDelegateForFunctionPointer(clearPtr,typeof(Interop.InquiryFunc));
199+
varclearFunc=NativeCall.GetDelegate<Interop.InquiryFunc>(clearPtr);
200200
clearFunc(pyHandle);
201201
}
202202

@@ -214,7 +214,8 @@ internal void CallTypeTraverse(Interop.ObjObjFunc visitproc, IntPtr arg)
214214
{
215215
return;
216216
}
217-
vartraverseFunc=(Interop.ObjObjArgFunc)Marshal.GetDelegateForFunctionPointer(traversePtr,typeof(Interop.ObjObjArgFunc));
217+
vartraverseFunc=NativeCall.GetDelegate<Interop.ObjObjArgFunc>(traversePtr);
218+
218219
varvisiPtr=Marshal.GetFunctionPointerForDelegate(visitproc);
219220
traverseFunc(pyHandle,visiPtr,arg);
220221
}

‎src/runtime/nativecall.cs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ public static int Int_Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3)
4040
returnd(a1,a2,a3);
4141
}
4242

43-
privatestaticTGetDelegate<T>(IntPtrfp)whereT:Delegate
43+
internalstaticTGetDelegate<T>(IntPtrfp)whereT:Delegate
4444
{
45-
// Use Marshal.GetDelegateForFunctionPointer<> directly after upgrade the framework
46-
return(T)Marshal.GetDelegateForFunctionPointer(fp,typeof(T));
45+
Delegated=null;
46+
if(!Interop.allocatedThunks.TryGetValue(fp,outd))
47+
{
48+
// We don't cache this delegate because this is a pure delegate ot unmanaged.
49+
d=Marshal.GetDelegateForFunctionPointer<T>(fp);
50+
}
51+
return(T)d;
4752
}
4853
}
4954
}

‎src/runtime/runtime.cs‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,16 +1025,13 @@ internal static bool PyObject_IsIterable(IntPtr pointer)
10251025
}
10261026

10271027
[DllImport(_PythonDll,CallingConvention=CallingConvention.Cdecl)]
1028-
internalstaticexternintPyObject_HasAttrString(IntPtrpointer,stringname);
1028+
internalstaticexternintPyObject_HasAttrString(IntPtrpointer,[MarshalAs(UnmanagedType.CustomMarshaler,MarshalTypeRef=typeof(Utf8Marshaler))]string name);
10291029

10301030
[DllImport(_PythonDll,CallingConvention=CallingConvention.Cdecl)]
1031-
internalstaticexternIntPtr PyObject_GetAttrString(IntPtrpointer,stringname);
1031+
internalstaticexternIntPtr PyObject_GetAttrString(IntPtrpointer,[MarshalAs(UnmanagedType.CustomMarshaler,MarshalTypeRef=typeof(Utf8Marshaler))]string name);
10321032

10331033
[DllImport(_PythonDll,CallingConvention=CallingConvention.Cdecl)]
1034-
internalstaticexternIntPtr PyObject_GetAttrString(IntPtrpointer,IntPtrname);
1035-
1036-
[DllImport(_PythonDll,CallingConvention=CallingConvention.Cdecl)]
1037-
internalstaticexternintPyObject_SetAttrString(IntPtrpointer,stringname,IntPtrvalue);
1034+
internalstaticexternintPyObject_SetAttrString(IntPtrpointer,[MarshalAs(UnmanagedType.CustomMarshaler,MarshalTypeRef=typeof(Utf8Marshaler))]string name,IntPtrvalue);
10381035

10391036
[DllImport(_PythonDll,CallingConvention=CallingConvention.Cdecl)]
10401037
internalstaticexternintPyObject_HasAttr(IntPtrpointer,IntPtrname);
@@ -1649,7 +1646,7 @@ internal static bool PyDict_Check(IntPtr ob)
16491646
/// Return value: Borrowed reference.
16501647
/// </summary>
16511648
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
1652-
internalstaticextern IntPtr PyDict_GetItemString(IntPtr pointer,string key);
1649+
internalstaticextern IntPtr PyDict_GetItemString(IntPtr pointer,[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Utf8Marshaler))]string key);
16531650

16541651
/// <summary>
16551652
/// Return 0 on success or -1 on failure.
@@ -1661,13 +1658,13 @@ internal static bool PyDict_Check(IntPtr ob)
16611658
/// Return 0 on success or -1 on failure.
16621659
/// </summary>
16631660
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
1664-
internalstaticexternint PyDict_SetItemString(IntPtr pointer,string key, IntPtr value);
1661+
internalstaticexternint PyDict_SetItemString(IntPtr pointer,[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Utf8Marshaler))]string key, IntPtr value);
16651662

16661663
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
16671664
internalstaticexternint PyDict_DelItem(IntPtr pointer, IntPtr key);
16681665

16691666
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
1670-
internalstaticexternint PyDict_DelItemString(IntPtr pointer,string key);
1667+
internalstaticexternint PyDict_DelItemString(IntPtr pointer,[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Utf8Marshaler))]string key);
16711668

16721669
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
16731670
internalstaticexternint PyMapping_HasKey(IntPtr pointer, IntPtr key);
@@ -2019,7 +2016,7 @@ internal static IntPtr PyMem_Realloc(IntPtr ptr, long size)
20192016
//====================================================================
20202017

20212018
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
2022-
internalstaticexternvoid PyErr_SetString(IntPtr ob,string message);
2019+
internalstaticexternvoid PyErr_SetString(IntPtr ob,[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Utf8Marshaler))]string message);
20232020

20242021
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
20252022
internalstaticexternvoid PyErr_SetObject(BorrowedReference type, BorrowedReference exceptionObject);

‎src/testing/methodtest.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,10 @@ public static string ParamsArrayOverloaded(int i, params int[] paramsArray)
713713
{
714714
return"with params-array";
715715
}
716+
717+
publicstaticvoidEncodingTestÅngström()
718+
{
719+
}
716720
}
717721

718722

‎src/tests/test_method.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,3 +1221,5 @@ def test_params_array_overload():
12211221
# res = MethodTest.ParamsArrayOverloaded(paramsArray=[], i=1)
12221222
# assert res == "with params-array"
12231223

1224+
deftest_method_encoding():
1225+
MethodTest.EncodingTestÅngström()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp