public void DecRef() { var oldRef = References; if (!IsInvalid) { Python.Py_DecRef(Pointer); } if (oldRef == 1) { Pointer = IntPtr.Zero; } }
internal static string GetValueInternal(IntPtr pointer) { if (PyObject_IsInstance(pointer, Python.Type.Unicode) == 0) { var raw = GetRawInternal(pointer); if (raw == null) { return(""); } return(Encoding.ASCII.GetString(raw)); } var mem = PyUnicodeUCS2_AsEncodedString(pointer, "utf-8", "ignore"); if (mem == IntPtr.Zero) { return(""); } var res = Marshal.PtrToStringAnsi(mem); Python.Py_DecRef(mem); return(res); }