Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 82b8fdb

Browse files
committed
Set __classcell__ if it exists
1 parent 03abf5e commit 82b8fdb

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-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
internal static extern void PyErr_Print();
19681968

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

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

src/runtime/typemanager.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,18 @@ internal static IntPtr CreateSubType(IntPtr py_name, IntPtr py_base_type, IntPtr
280280
IntPtr cls_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+
IntPtr cell = Runtime.PyDict_GetItemString(cls_dict, "__classcell__");
285+
if (cell != IntPtr.Zero)
286+
{
287+
// if (Runtime.PyObject_TypeCheck(cell, Runtime.PyCellType))
288+
{
289+
Runtime.XIncref(cell);
290+
Runtime.PyCell_Set(cell, py_type);
291+
}
292+
Runtime.PyDict_DelItemString(cls_dict, "__classcell__");
293+
}
294+
283295
return py_type;
284296
}
285297
catch (Exception e)

0 commit comments

Comments
 (0)