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
This repository was archived by the owner on Jul 22, 2023. It is now read-only.
/pythonnetPublic archive
forked frompythonnet/pythonnet

Commitb17b9d3

Browse files
committed
Set __classcell__ if it exists
If `PyCell_Set` is not called with a cell it will raise an exception,which is perfectly valid here.
1 parentd4eac3a commitb17b9d3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

‎src/runtime/runtime.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,15 @@ internal static IntPtr PyMem_Realloc(IntPtr ptr, long size)
19661966
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
19671967
internalstaticexternvoid PyErr_Print();
19681968

1969+
//====================================================================
1970+
// Cell API
1971+
//====================================================================
1972+
1973+
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
1974+
internalstaticextern NewReference PyCell_Get(IntPtr cell);
1975+
1976+
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
1977+
internalstaticexternint PyCell_Set(IntPtr cell, IntPtr value);
19691978

19701979
//====================================================================
19711980
// Miscellaneous

‎src/runtime/typemanager.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ internal static IntPtr CreateSubType(IntPtr py_name, IntPtr py_base_type, IntPtr
280280
IntPtrcls_dict=Marshal.ReadIntPtr(py_type,TypeOffset.tp_dict);
281281
Runtime.PyDict_Update(cls_dict,py_dict);
282282

283+
// Update the __classcell__ if it exists
284+
IntPtrcell=Runtime.PyDict_GetItemString(cls_dict,"__classcell__");
285+
if(cell!=IntPtr.Zero)
286+
{
287+
Runtime.PyCell_Set(cell,py_type);
288+
Runtime.PyDict_DelItemString(cls_dict,"__classcell__");
289+
}
290+
283291
returnpy_type;
284292
}
285293
catch(Exceptione)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp