pyobject 1.2.7.1__tar.gz → 1.2.7.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {pyobject-1.2.7.1/pyobject.egg-info → pyobject-1.2.7.3}/PKG-INFO +1 -1
  2. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/__init__.py +3 -2
  3. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/pyobj_extension.c +129 -11
  4. {pyobject-1.2.7.1 → pyobject-1.2.7.3/pyobject.egg-info}/PKG-INFO +1 -1
  5. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/LICENSE +0 -0
  6. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/MANIFEST.in +0 -0
  7. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/README.rst +0 -0
  8. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/browser.py +0 -0
  9. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/code_.py +0 -0
  10. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/images/back.gif +0 -0
  11. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/images/codeobject.gif +0 -0
  12. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/images/dict.gif +0 -0
  13. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/images/empty_dict.gif +0 -0
  14. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/images/empty_list.gif +0 -0
  15. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/images/empty_tuple.gif +0 -0
  16. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/images/forward.gif +0 -0
  17. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/images/function.gif +0 -0
  18. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/images/list.gif +0 -0
  19. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/images/number.gif +0 -0
  20. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/images/python.gif +0 -0
  21. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/images/python.ico +0 -0
  22. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/images/refresh.gif +0 -0
  23. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/images/string.gif +0 -0
  24. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/images/tuple.gif +0 -0
  25. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/newtypes.py +0 -0
  26. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/search.py +0 -0
  27. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/super_reflect.py +0 -0
  28. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/test/README.md +0 -0
  29. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/test/__init__.py +0 -0
  30. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/test/browser_chs_locale.py +0 -0
  31. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/test/empty.pyc +0 -0
  32. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/test/interpreter_shutdown.py +0 -0
  33. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/test/pyc_zipper_lzma.py +0 -0
  34. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/test/pyc_zipper_unpack.py +0 -0
  35. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/test/pyc_zipper_zlib.py +0 -0
  36. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject/test/testcode.py +0 -0
  37. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject.egg-info/SOURCES.txt +0 -0
  38. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject.egg-info/dependency_links.txt +0 -0
  39. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/pyobject.egg-info/top_level.txt +0 -0
  40. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/setup.cfg +0 -0
  41. {pyobject-1.2.7.1 → pyobject-1.2.7.3}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyobject
3
- Version: 1.2.7.1
3
+ Version: 1.2.7.3
4
4
  Summary: 一个提供操作Python对象底层工具的模块。A utility tool with some submodules for operating internal python objects.
5
5
  Home-page: https://github.com/qfcy/pyobject
6
6
  Author: qfcy
@@ -6,7 +6,7 @@ from warnings import warn
6
6
  from pprint import pprint
7
7
 
8
8
  __author__="qfcy"
9
- __version__="1.2.7.1"
9
+ __version__="1.2.7.3"
10
10
 
11
11
  _ignore_names=["__builtins__","__doc__"]
12
12
  __all__=["objectname","bases","describe","desc"]
@@ -109,7 +109,8 @@ try:
109
109
  __all__.extend(["convptr","py_incref","py_decref","getrealrefcount",
110
110
  "setrefcount","list_in","getrefcount_nogil","setrefcount_nogil",
111
111
  "get_type_flag","set_type_flag","set_type_base","set_type_bases",
112
- "set_type_mro"])
112
+ "set_type_mro","get_type_subclasses","set_type_subclasses",
113
+ "set_type_subclasses_by_cls"])
113
114
  except ImportError:warn("Failed to import module pyobj_extension.")
114
115
 
115
116
  def test():
@@ -48,10 +48,11 @@ PyDoc_STRVAR(setrefcount_nogil_doc, u8"setrefcount_nogil(obj,ref_data)\n"
48
48
  #error "Python 3 is required"
49
49
  #endif
50
50
 
51
- #if PY_MINOR_VERSION >= 14
51
+ #if PY_MINOR_VERSION >= 13
52
+ #define _PY313
52
53
  #if defined(Py_GIL_DISABLED)
53
- // _PY314_NO_GIL: 是否启用无GIL的引用计数功能
54
- #define _PY314_NO_GIL
54
+ // _PY313_NO_GIL: 是否启用无GIL的引用计数功能
55
+ #define _PY313_NO_GIL
55
56
  #endif
56
57
 
57
58
  // 兼容旧版本Python
@@ -62,8 +63,21 @@ PyDoc_STRVAR(setrefcount_nogil_doc, u8"setrefcount_nogil(obj,ref_data)\n"
62
63
  #if PY_MINOR_VERSION <= 11
63
64
  #define Py_mod_multiple_interpreters 0
64
65
  #define Py_MOD_PER_INTERPRETER_GIL_SUPPORTED NULL
66
+ #else
67
+ #define _PY312
68
+ #endif
69
+
70
+ #endif
71
+
72
+ #if PY_MINOR_VERSION >= 12
73
+ #define _PY312P /* 3.12+所有版本 */
65
74
  #endif
66
75
 
76
+ #ifdef _PY312P
77
+ #define Py_BUILD_CORE
78
+ #include <internal/pycore_object.h> // _PyType_HasFeature()
79
+ #include <internal/pycore_typeobject.h> // struct type_cache
80
+ #undef Py_BUILD_CORE
67
81
  #endif
68
82
 
69
83
  static const int REFCNT_DELTA=2; // 调用时新增的引用计数
@@ -98,8 +112,8 @@ PyObject *py_decref(PyObject *self, PyObject *args) {
98
112
  }
99
113
 
100
114
  PyObject *getrealrefcount(PyObject *self, PyObject *args) {
101
- #ifdef _PY314_NO_GIL
102
- PyErr_SetString(PyExc_NotImplementedError, "getrealrefcount is not available in GIL-free versions of Python 3.14+");
115
+ #ifdef _PY313_NO_GIL
116
+ PyErr_SetString(PyExc_NotImplementedError, "getrealrefcount is not available in GIL-free versions of Python 3.13+");
103
117
  return NULL;
104
118
  #else
105
119
  PyObject *obj;
@@ -110,8 +124,8 @@ PyObject *getrealrefcount(PyObject *self, PyObject *args) {
110
124
  #endif
111
125
  }
112
126
  PyObject *setrefcount(PyObject *self, PyObject *args, PyObject *kwargs) {
113
- #ifdef _PY314_NO_GIL
114
- PyErr_SetString(PyExc_NotImplementedError, "setrefcount is not available in GIL-free versions of Python 3.14+");
127
+ #ifdef _PY313_NO_GIL
128
+ PyErr_SetString(PyExc_NotImplementedError, "setrefcount is not available in GIL-free versions of Python 3.13+");
115
129
  return NULL;
116
130
  #else
117
131
  PyObject *obj;Py_ssize_t n;
@@ -124,8 +138,8 @@ PyObject *setrefcount(PyObject *self, PyObject *args, PyObject *kwargs) {
124
138
  #endif
125
139
  }
126
140
  PyObject *getrefcount_nogil(PyObject *self, PyObject *args){
127
- #ifndef _PY314_NO_GIL
128
- PyErr_SetString(PyExc_NotImplementedError, "getrefcount_nogil is only available in GIL-free versions of Python 3.14+");
141
+ #ifndef _PY313_NO_GIL
142
+ PyErr_SetString(PyExc_NotImplementedError, "getrefcount_nogil is only available in GIL-free versions of Python 3.13+");
129
143
  return NULL;
130
144
  #else
131
145
  PyObject *obj;
@@ -139,8 +153,8 @@ PyObject *getrefcount_nogil(PyObject *self, PyObject *args){
139
153
  #endif
140
154
  }
141
155
  PyObject *setrefcount_nogil(PyObject *self, PyObject *args, PyObject *kwargs){
142
- #ifndef _PY314_NO_GIL
143
- PyErr_SetString(PyExc_NotImplementedError, "setrefcount_nogil is only available in GIL-free versions of Python 3.14+");
156
+ #ifndef _PY313_NO_GIL
157
+ PyErr_SetString(PyExc_NotImplementedError, "setrefcount_nogil is only available in GIL-free versions of Python 3.13+");
144
158
  return NULL;
145
159
  #else
146
160
  PyObject *obj = NULL;
@@ -265,6 +279,106 @@ static PyObject* set_type_mro(PyObject *self, PyObject *args, PyObject *kwargs)
265
279
  Py_RETURN_NONE;
266
280
  }
267
281
 
282
+ #ifdef _PY312
283
+ #define managed_static_type_state static_builtin_state /* 兼容3.12 */
284
+ #endif
285
+ PyObject **_lookup_tp_subclasses(PyTypeObject *self){ // 从解释器的实现typeobject.c复制
286
+ #ifdef _PY312P
287
+ if (self->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
288
+ PyInterpreterState *interp = _PyInterpreterState_GET();
289
+ managed_static_type_state *state = _PyStaticType_GetState(interp, self);
290
+ // assert(state != NULL);
291
+ return &(state->tp_subclasses);
292
+ }
293
+ #endif
294
+ return (PyObject **)&(self->tp_subclasses);
295
+ }
296
+ #define getSubclasses(cls) (*_lookup_tp_subclasses(cls))
297
+ static PyObject* get_type_subclasses(PyObject *self, PyObject *args, PyObject *kwargs) {
298
+ static char *kwlist[] = {"typeobj", NULL};
299
+ PyObject *typeobj;
300
+
301
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &typeobj))
302
+ return NULL;
303
+
304
+ PyTypeObject *type = (PyTypeObject *)typeobj;
305
+ if(!getSubclasses(type)) Py_RETURN_NONE;
306
+ return getSubclasses(type);
307
+ }
308
+
309
+ static PyObject* set_type_subclasses(PyObject *self, PyObject *args, PyObject *kwargs) {
310
+ static char *kwlist[] = {"typeobj", "subclasses", NULL};
311
+ PyObject *typeobj, *subclasses;
312
+
313
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO", kwlist, &typeobj, &subclasses))
314
+ return NULL;
315
+
316
+ PyTypeObject *type = (PyTypeObject *)typeobj;
317
+ if(getSubclasses(type)) Py_DECREF(getSubclasses(type));
318
+ if (PyLong_Check(subclasses) && PyLong_AsLong(subclasses) == 0) {
319
+ getSubclasses(type) = NULL; // 传入0表示设为NULL
320
+ } else {
321
+ Py_INCREF(subclasses);
322
+ getSubclasses(type) = subclasses;
323
+ }
324
+ Py_RETURN_NONE;
325
+ }
326
+ static PyObject* set_type_subclasses_by_cls(PyObject *self, PyObject *args, PyObject *kwargs) {
327
+ static char *kwlist[] = {"typeobj", "cls", NULL};
328
+ PyObject *typeobj, *cls;
329
+
330
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO", kwlist, &typeobj, &cls))
331
+ return NULL;
332
+
333
+ PyTypeObject *dst = (PyTypeObject *)typeobj, *src = (PyTypeObject *)cls;
334
+ #ifndef _PY312
335
+ if(getSubclasses(src)) Py_INCREF(getSubclasses(src));
336
+ if(getSubclasses(dst)) Py_DECREF(getSubclasses(src));
337
+ #endif
338
+ getSubclasses(dst) = getSubclasses(src);
339
+ Py_RETURN_NONE;
340
+ }
341
+
342
+ // -- 3.12+的外部符号 --
343
+ #ifdef _PY312P
344
+ static inline size_t
345
+ managed_static_type_index_get(PyTypeObject *self)
346
+ {
347
+ // assert(managed_static_type_index_is_set(self));
348
+ /* We store a 1-based index so 0 can mean "not initialized". */
349
+ return (size_t)self->tp_subclasses - 1;
350
+ }
351
+ #ifdef _PY312
352
+ static inline static_builtin_state *
353
+ managed_static_type_state_get(PyInterpreterState *interp, PyTypeObject *self)
354
+ {
355
+ return &(interp->types.builtins[managed_static_type_index_get(self)]);
356
+ }
357
+ #else
358
+ static managed_static_type_state *
359
+ managed_static_type_state_get(PyInterpreterState *interp, PyTypeObject *self)
360
+ {
361
+ // It's probably a builtin type.
362
+ size_t index = managed_static_type_index_get(self);
363
+ managed_static_type_state *state =
364
+ &(interp->types.builtins.initialized[index]);
365
+ if (state->type == self) {
366
+ return state;
367
+ }
368
+ if (index > _Py_MAX_MANAGED_STATIC_EXT_TYPES) {
369
+ return state;
370
+ }
371
+ return &(interp->types.for_extensions.initialized[index]);
372
+ }
373
+ #endif
374
+ /* For static types we store some state in an array on each interpreter. */
375
+ managed_static_type_state *_PyStaticType_GetState(PyInterpreterState *interp, PyTypeObject *self){
376
+ assert(self->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN);
377
+ return managed_static_type_state_get(interp, self);
378
+ }
379
+ #endif
380
+ // ----
381
+
268
382
  /*
269
383
  * List of functions to add to pyobj_extension in exec_pyobj_extension().
270
384
  */
@@ -284,6 +398,10 @@ static PyMethodDef pyobj_extension_functions[] = {
284
398
  {"set_type_base", (PyCFunction)set_type_base, METH_VARARGS | METH_KEYWORDS, "set_type_base(typeobj: type, base: type)"},
285
399
  {"set_type_bases", (PyCFunction)set_type_bases, METH_VARARGS | METH_KEYWORDS, "set_type_bases(typeobj: type, bases: tuple)"},
286
400
  {"set_type_mro", (PyCFunction)set_type_mro, METH_VARARGS | METH_KEYWORDS, "set_type_mro(typeobj: type, mro: tuple)"},
401
+ {"get_type_subclasses", (PyCFunction)get_type_subclasses, METH_VARARGS | METH_KEYWORDS, "get_type_subclasses(typeobj: type)"},
402
+ {"set_type_subclasses", (PyCFunction)set_type_subclasses, METH_VARARGS | METH_KEYWORDS, "set_type_subclasses(typeobj: type, subclasses: dict)"},
403
+ {"set_type_subclasses_by_cls", (PyCFunction)set_type_subclasses_by_cls, METH_VARARGS | METH_KEYWORDS,
404
+ "set_type_subclasses_by_cls(typeobj: type, cls: type)"},
287
405
  { NULL, NULL, 0, NULL } /* marks end of array */
288
406
  };
289
407
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyobject
3
- Version: 1.2.7.1
3
+ Version: 1.2.7.3
4
4
  Summary: 一个提供操作Python对象底层工具的模块。A utility tool with some submodules for operating internal python objects.
5
5
  Home-page: https://github.com/qfcy/pyobject
6
6
  Author: qfcy
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes