crosshair-tool 0.0.99__cp312-cp312-macosx_10_13_x86_64.whl
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.
- _crosshair_tracers.cpython-312-darwin.so +0 -0
- crosshair/__init__.py +42 -0
- crosshair/__main__.py +8 -0
- crosshair/_mark_stacks.h +790 -0
- crosshair/_preliminaries_test.py +18 -0
- crosshair/_tracers.h +94 -0
- crosshair/_tracers_pycompat.h +522 -0
- crosshair/_tracers_test.py +138 -0
- crosshair/abcstring.py +245 -0
- crosshair/auditwall.py +190 -0
- crosshair/auditwall_test.py +77 -0
- crosshair/codeconfig.py +113 -0
- crosshair/codeconfig_test.py +117 -0
- crosshair/condition_parser.py +1237 -0
- crosshair/condition_parser_test.py +497 -0
- crosshair/conftest.py +30 -0
- crosshair/copyext.py +155 -0
- crosshair/copyext_test.py +84 -0
- crosshair/core.py +1763 -0
- crosshair/core_and_libs.py +149 -0
- crosshair/core_regestered_types_test.py +82 -0
- crosshair/core_test.py +1316 -0
- crosshair/diff_behavior.py +314 -0
- crosshair/diff_behavior_test.py +261 -0
- crosshair/dynamic_typing.py +346 -0
- crosshair/dynamic_typing_test.py +210 -0
- crosshair/enforce.py +282 -0
- crosshair/enforce_test.py +182 -0
- crosshair/examples/PEP316/__init__.py +1 -0
- crosshair/examples/PEP316/bugs_detected/__init__.py +0 -0
- crosshair/examples/PEP316/bugs_detected/getattr_magic.py +16 -0
- crosshair/examples/PEP316/bugs_detected/hash_consistent_with_equals.py +31 -0
- crosshair/examples/PEP316/bugs_detected/shopping_cart.py +24 -0
- crosshair/examples/PEP316/bugs_detected/showcase.py +39 -0
- crosshair/examples/PEP316/correct_code/__init__.py +0 -0
- crosshair/examples/PEP316/correct_code/arith.py +60 -0
- crosshair/examples/PEP316/correct_code/chess.py +77 -0
- crosshair/examples/PEP316/correct_code/nesting_inference.py +17 -0
- crosshair/examples/PEP316/correct_code/numpy_examples.py +132 -0
- crosshair/examples/PEP316/correct_code/rolling_average.py +35 -0
- crosshair/examples/PEP316/correct_code/showcase.py +104 -0
- crosshair/examples/__init__.py +0 -0
- crosshair/examples/check_examples_test.py +146 -0
- crosshair/examples/deal/__init__.py +1 -0
- crosshair/examples/icontract/__init__.py +1 -0
- crosshair/examples/icontract/bugs_detected/__init__.py +0 -0
- crosshair/examples/icontract/bugs_detected/showcase.py +41 -0
- crosshair/examples/icontract/bugs_detected/wrong_sign.py +8 -0
- crosshair/examples/icontract/correct_code/__init__.py +0 -0
- crosshair/examples/icontract/correct_code/arith.py +51 -0
- crosshair/examples/icontract/correct_code/showcase.py +94 -0
- crosshair/fnutil.py +391 -0
- crosshair/fnutil_test.py +75 -0
- crosshair/fuzz_core_test.py +516 -0
- crosshair/libimpl/__init__.py +0 -0
- crosshair/libimpl/arraylib.py +161 -0
- crosshair/libimpl/binascii_ch_test.py +30 -0
- crosshair/libimpl/binascii_test.py +67 -0
- crosshair/libimpl/binasciilib.py +150 -0
- crosshair/libimpl/bisectlib_test.py +23 -0
- crosshair/libimpl/builtinslib.py +5228 -0
- crosshair/libimpl/builtinslib_ch_test.py +1191 -0
- crosshair/libimpl/builtinslib_test.py +3735 -0
- crosshair/libimpl/codecslib.py +86 -0
- crosshair/libimpl/codecslib_test.py +86 -0
- crosshair/libimpl/collectionslib.py +264 -0
- crosshair/libimpl/collectionslib_ch_test.py +252 -0
- crosshair/libimpl/collectionslib_test.py +332 -0
- crosshair/libimpl/copylib.py +23 -0
- crosshair/libimpl/copylib_test.py +18 -0
- crosshair/libimpl/datetimelib.py +2559 -0
- crosshair/libimpl/datetimelib_ch_test.py +354 -0
- crosshair/libimpl/datetimelib_test.py +112 -0
- crosshair/libimpl/decimallib.py +5257 -0
- crosshair/libimpl/decimallib_ch_test.py +78 -0
- crosshair/libimpl/decimallib_test.py +76 -0
- crosshair/libimpl/encodings/__init__.py +23 -0
- crosshair/libimpl/encodings/_encutil.py +187 -0
- crosshair/libimpl/encodings/ascii.py +44 -0
- crosshair/libimpl/encodings/latin_1.py +40 -0
- crosshair/libimpl/encodings/utf_8.py +93 -0
- crosshair/libimpl/encodings_ch_test.py +83 -0
- crosshair/libimpl/fractionlib.py +16 -0
- crosshair/libimpl/fractionlib_test.py +80 -0
- crosshair/libimpl/functoolslib.py +34 -0
- crosshair/libimpl/functoolslib_test.py +56 -0
- crosshair/libimpl/hashliblib.py +30 -0
- crosshair/libimpl/hashliblib_test.py +18 -0
- crosshair/libimpl/heapqlib.py +47 -0
- crosshair/libimpl/heapqlib_test.py +21 -0
- crosshair/libimpl/importliblib.py +18 -0
- crosshair/libimpl/importliblib_test.py +38 -0
- crosshair/libimpl/iolib.py +216 -0
- crosshair/libimpl/iolib_ch_test.py +128 -0
- crosshair/libimpl/iolib_test.py +19 -0
- crosshair/libimpl/ipaddresslib.py +8 -0
- crosshair/libimpl/itertoolslib.py +44 -0
- crosshair/libimpl/itertoolslib_test.py +44 -0
- crosshair/libimpl/jsonlib.py +984 -0
- crosshair/libimpl/jsonlib_ch_test.py +42 -0
- crosshair/libimpl/jsonlib_test.py +51 -0
- crosshair/libimpl/mathlib.py +179 -0
- crosshair/libimpl/mathlib_ch_test.py +44 -0
- crosshair/libimpl/mathlib_test.py +67 -0
- crosshair/libimpl/oslib.py +7 -0
- crosshair/libimpl/pathliblib_test.py +10 -0
- crosshair/libimpl/randomlib.py +178 -0
- crosshair/libimpl/randomlib_test.py +120 -0
- crosshair/libimpl/relib.py +846 -0
- crosshair/libimpl/relib_ch_test.py +169 -0
- crosshair/libimpl/relib_test.py +493 -0
- crosshair/libimpl/timelib.py +72 -0
- crosshair/libimpl/timelib_test.py +82 -0
- crosshair/libimpl/typeslib.py +15 -0
- crosshair/libimpl/typeslib_test.py +36 -0
- crosshair/libimpl/unicodedatalib.py +75 -0
- crosshair/libimpl/unicodedatalib_test.py +42 -0
- crosshair/libimpl/urlliblib.py +23 -0
- crosshair/libimpl/urlliblib_test.py +19 -0
- crosshair/libimpl/weakreflib.py +13 -0
- crosshair/libimpl/weakreflib_test.py +69 -0
- crosshair/libimpl/zliblib.py +15 -0
- crosshair/libimpl/zliblib_test.py +13 -0
- crosshair/lsp_server.py +261 -0
- crosshair/lsp_server_test.py +30 -0
- crosshair/main.py +973 -0
- crosshair/main_test.py +543 -0
- crosshair/objectproxy.py +376 -0
- crosshair/objectproxy_test.py +41 -0
- crosshair/opcode_intercept.py +601 -0
- crosshair/opcode_intercept_test.py +304 -0
- crosshair/options.py +218 -0
- crosshair/options_test.py +10 -0
- crosshair/patch_equivalence_test.py +75 -0
- crosshair/path_cover.py +209 -0
- crosshair/path_cover_test.py +138 -0
- crosshair/path_search.py +161 -0
- crosshair/path_search_test.py +52 -0
- crosshair/pathing_oracle.py +271 -0
- crosshair/pathing_oracle_test.py +21 -0
- crosshair/pure_importer.py +27 -0
- crosshair/pure_importer_test.py +16 -0
- crosshair/py.typed +0 -0
- crosshair/register_contract.py +273 -0
- crosshair/register_contract_test.py +190 -0
- crosshair/simplestructs.py +1165 -0
- crosshair/simplestructs_test.py +283 -0
- crosshair/smtlib.py +24 -0
- crosshair/smtlib_test.py +14 -0
- crosshair/statespace.py +1199 -0
- crosshair/statespace_test.py +108 -0
- crosshair/stubs_parser.py +352 -0
- crosshair/stubs_parser_test.py +43 -0
- crosshair/test_util.py +329 -0
- crosshair/test_util_test.py +26 -0
- crosshair/tools/__init__.py +0 -0
- crosshair/tools/check_help_in_doc.py +264 -0
- crosshair/tools/check_init_and_setup_coincide.py +119 -0
- crosshair/tools/generate_demo_table.py +127 -0
- crosshair/tracers.py +544 -0
- crosshair/tracers_test.py +154 -0
- crosshair/type_repo.py +151 -0
- crosshair/unicode_categories.py +589 -0
- crosshair/unicode_categories_test.py +27 -0
- crosshair/util.py +741 -0
- crosshair/util_test.py +173 -0
- crosshair/watcher.py +307 -0
- crosshair/watcher_test.py +107 -0
- crosshair/z3util.py +76 -0
- crosshair/z3util_test.py +11 -0
- crosshair_tool-0.0.99.dist-info/METADATA +144 -0
- crosshair_tool-0.0.99.dist-info/RECORD +176 -0
- crosshair_tool-0.0.99.dist-info/WHEEL +6 -0
- crosshair_tool-0.0.99.dist-info/entry_points.txt +3 -0
- crosshair_tool-0.0.99.dist-info/licenses/LICENSE +93 -0
- crosshair_tool-0.0.99.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import importlib
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_PYTHONHASHSEED_is_zero() -> None:
|
|
8
|
+
assert os.getenv("PYTHONHASHSEED") == "0", (
|
|
9
|
+
"CrossHair tests should be run with the PYTHONHASHSEED "
|
|
10
|
+
"environement variable set to 0. Some other tests rely on this "
|
|
11
|
+
"for deterministic behavior."
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_no_modules_named_foo() -> None:
|
|
16
|
+
# Try to ensure no leaked autogenerated files are on the path.
|
|
17
|
+
with pytest.raises(ImportError):
|
|
18
|
+
importlib.import_module("foo")
|
crosshair/_tracers.h
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#ifndef _COVERAGE_TRACER_H
|
|
2
|
+
#define _COVERAGE_TRACER_H
|
|
3
|
+
|
|
4
|
+
#include "structmember.h"
|
|
5
|
+
|
|
6
|
+
#include <Python.h>
|
|
7
|
+
|
|
8
|
+
#define RET_OK 0
|
|
9
|
+
#define RET_ERROR -1
|
|
10
|
+
#define RET_DISABLE_TRACING 1
|
|
11
|
+
|
|
12
|
+
typedef int BOOL;
|
|
13
|
+
#define FALSE 0
|
|
14
|
+
#define TRUE 1
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
#define DEFINE_VEC(N, T, INITNAME, PUSHNAME) \
|
|
18
|
+
typedef struct N {int count; int capacity; T * items;} N ; \
|
|
19
|
+
void INITNAME (N * vec, int cap) \
|
|
20
|
+
{ \
|
|
21
|
+
vec->count = 0; \
|
|
22
|
+
vec->capacity = cap; \
|
|
23
|
+
vec->items = PyMem_Malloc(sizeof(T) * cap); \
|
|
24
|
+
memset(vec->items, 0, sizeof(T) * cap); \
|
|
25
|
+
} \
|
|
26
|
+
int PUSHNAME (N * vec, T item) \
|
|
27
|
+
{ \
|
|
28
|
+
int count = vec->count; \
|
|
29
|
+
int capacity = vec->capacity; \
|
|
30
|
+
T* items = vec->items; \
|
|
31
|
+
if (count >= capacity) \
|
|
32
|
+
{ \
|
|
33
|
+
size_t halfsize = sizeof(T) * capacity; \
|
|
34
|
+
vec->capacity = (capacity *= 2); \
|
|
35
|
+
items = PyMem_Realloc(vec->items, halfsize << 1); \
|
|
36
|
+
if (items == NULL) \
|
|
37
|
+
{ \
|
|
38
|
+
return RET_ERROR; \
|
|
39
|
+
} \
|
|
40
|
+
memset(((unsigned char *) items) + halfsize, 0, halfsize); \
|
|
41
|
+
vec->items = items; \
|
|
42
|
+
} \
|
|
43
|
+
items[count] = item; \
|
|
44
|
+
vec->count++; \
|
|
45
|
+
return RET_OK; \
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
typedef struct HandlerTable {
|
|
49
|
+
PyObject * entries[256];
|
|
50
|
+
} HandlerTable;
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
typedef struct FrameNextIandCallback {
|
|
54
|
+
PyFrameObject* frame;
|
|
55
|
+
int expected_i;
|
|
56
|
+
PyObject* callback;
|
|
57
|
+
} FrameNextIandCallback;
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
typedef struct CodeAndStacks {
|
|
61
|
+
PyCodeObject* code_obj;
|
|
62
|
+
int64_t *stacks;
|
|
63
|
+
} CodeAndStacks;
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
DEFINE_VEC(FrameNextIandCallbackVec, FrameNextIandCallback, init_framecbvec, push_framecb);
|
|
67
|
+
DEFINE_VEC(ModuleVec, PyObject*, init_modulevec, push_module);
|
|
68
|
+
DEFINE_VEC(TableVec, HandlerTable, init_tablevec, push_table_entry)
|
|
69
|
+
|
|
70
|
+
typedef struct CTracer {
|
|
71
|
+
PyObject_HEAD
|
|
72
|
+
ModuleVec modules;
|
|
73
|
+
TableVec handlers;
|
|
74
|
+
FrameNextIandCallbackVec postop_callbacks;
|
|
75
|
+
BOOL enabled;
|
|
76
|
+
BOOL handling;
|
|
77
|
+
BOOL trace_all_opcodes;
|
|
78
|
+
int thread_id;
|
|
79
|
+
} CTracer;
|
|
80
|
+
|
|
81
|
+
extern PyTypeObject CTracerType;
|
|
82
|
+
|
|
83
|
+
typedef struct TraceSwap {
|
|
84
|
+
PyObject_HEAD
|
|
85
|
+
BOOL noop;
|
|
86
|
+
BOOL disabling;
|
|
87
|
+
PyObject* tracer;
|
|
88
|
+
} TraceSwap;
|
|
89
|
+
|
|
90
|
+
extern PyTypeObject TraceSwapType;
|
|
91
|
+
|
|
92
|
+
extern const uint8_t _ch_TRACABLE_INSTRUCTIONS[256];
|
|
93
|
+
|
|
94
|
+
#endif /* _COVERAGE_TRACER_H */
|
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
// Header file providing new C API functions to old Python versions.
|
|
2
|
+
//
|
|
3
|
+
// File distributed under the Zero Clause BSD (0BSD) license.
|
|
4
|
+
// Copyright Contributors to the pythoncapi_compat project.
|
|
5
|
+
//
|
|
6
|
+
// Homepage:
|
|
7
|
+
// https://github.com/python/pythoncapi_compat
|
|
8
|
+
//
|
|
9
|
+
// Latest version:
|
|
10
|
+
// https://raw.githubusercontent.com/python/pythoncapi_compat/master/pythoncapi_compat.h
|
|
11
|
+
//
|
|
12
|
+
// SPDX-License-Identifier: 0BSD
|
|
13
|
+
|
|
14
|
+
#ifndef PYTHONCAPI_COMPAT
|
|
15
|
+
#define PYTHONCAPI_COMPAT
|
|
16
|
+
|
|
17
|
+
#ifdef __cplusplus
|
|
18
|
+
extern "C" {
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
#include <Python.h>
|
|
22
|
+
#include "frameobject.h" // PyFrameObject, PyFrame_GetBack()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// Compatibility with Visual Studio 2013 and older which don't support
|
|
26
|
+
// the inline keyword in C (only in C++): use __inline instead.
|
|
27
|
+
#if (defined(_MSC_VER) && _MSC_VER < 1900 \
|
|
28
|
+
&& !defined(__cplusplus) && !defined(inline))
|
|
29
|
+
# define PYCAPI_COMPAT_STATIC_INLINE(TYPE) static __inline TYPE
|
|
30
|
+
#else
|
|
31
|
+
# define PYCAPI_COMPAT_STATIC_INLINE(TYPE) static inline TYPE
|
|
32
|
+
#endif
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
#ifndef _Py_CAST
|
|
36
|
+
# define _Py_CAST(type, expr) ((type)(expr))
|
|
37
|
+
#endif
|
|
38
|
+
|
|
39
|
+
// On C++11 and newer, _Py_NULL is defined as nullptr on C++11,
|
|
40
|
+
// otherwise it is defined as NULL.
|
|
41
|
+
#ifndef _Py_NULL
|
|
42
|
+
# if defined(__cplusplus) && __cplusplus >= 201103
|
|
43
|
+
# define _Py_NULL nullptr
|
|
44
|
+
# else
|
|
45
|
+
# define _Py_NULL NULL
|
|
46
|
+
# endif
|
|
47
|
+
#endif
|
|
48
|
+
|
|
49
|
+
// Cast argument to PyObject* type.
|
|
50
|
+
#ifndef _PyObject_CAST
|
|
51
|
+
# define _PyObject_CAST(op) _Py_CAST(PyObject*, op)
|
|
52
|
+
#endif
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
// bpo-42262 added Py_NewRef() to Python 3.10.0a3
|
|
56
|
+
#if PY_VERSION_HEX < 0x030A00A3 && !defined(Py_NewRef)
|
|
57
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
|
|
58
|
+
_Py_NewRef(PyObject *obj)
|
|
59
|
+
{
|
|
60
|
+
Py_INCREF(obj);
|
|
61
|
+
return obj;
|
|
62
|
+
}
|
|
63
|
+
#define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
|
|
64
|
+
#endif
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
// bpo-42262 added Py_XNewRef() to Python 3.10.0a3
|
|
68
|
+
#if PY_VERSION_HEX < 0x030A00A3 && !defined(Py_XNewRef)
|
|
69
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
|
|
70
|
+
_Py_XNewRef(PyObject *obj)
|
|
71
|
+
{
|
|
72
|
+
Py_XINCREF(obj);
|
|
73
|
+
return obj;
|
|
74
|
+
}
|
|
75
|
+
#define Py_XNewRef(obj) _Py_XNewRef(_PyObject_CAST(obj))
|
|
76
|
+
#endif
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
// bpo-39573 added Py_SET_REFCNT() to Python 3.9.0a4
|
|
80
|
+
#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_REFCNT)
|
|
81
|
+
PYCAPI_COMPAT_STATIC_INLINE(void)
|
|
82
|
+
_Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt)
|
|
83
|
+
{
|
|
84
|
+
ob->ob_refcnt = refcnt;
|
|
85
|
+
}
|
|
86
|
+
#define Py_SET_REFCNT(ob, refcnt) _Py_SET_REFCNT(_PyObject_CAST(ob), refcnt)
|
|
87
|
+
#endif
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
// Py_SETREF() and Py_XSETREF() were added to Python 3.5.2.
|
|
91
|
+
// It is excluded from the limited C API.
|
|
92
|
+
#if (PY_VERSION_HEX < 0x03050200 && !defined(Py_SETREF)) && !defined(Py_LIMITED_API)
|
|
93
|
+
#define Py_SETREF(op, op2) \
|
|
94
|
+
do { \
|
|
95
|
+
PyObject *_py_tmp = _PyObject_CAST(op); \
|
|
96
|
+
(op) = (op2); \
|
|
97
|
+
Py_DECREF(_py_tmp); \
|
|
98
|
+
} while (0)
|
|
99
|
+
|
|
100
|
+
#define Py_XSETREF(op, op2) \
|
|
101
|
+
do { \
|
|
102
|
+
PyObject *_py_tmp = _PyObject_CAST(op); \
|
|
103
|
+
(op) = (op2); \
|
|
104
|
+
Py_XDECREF(_py_tmp); \
|
|
105
|
+
} while (0)
|
|
106
|
+
#endif
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
// bpo-43753 added Py_Is(), Py_IsNone(), Py_IsTrue() and Py_IsFalse()
|
|
110
|
+
// to Python 3.10.0b1.
|
|
111
|
+
#if PY_VERSION_HEX < 0x030A00B1 && !defined(Py_Is)
|
|
112
|
+
# define Py_Is(x, y) ((x) == (y))
|
|
113
|
+
#endif
|
|
114
|
+
#if PY_VERSION_HEX < 0x030A00B1 && !defined(Py_IsNone)
|
|
115
|
+
# define Py_IsNone(x) Py_Is(x, Py_None)
|
|
116
|
+
#endif
|
|
117
|
+
#if PY_VERSION_HEX < 0x030A00B1 && !defined(Py_IsTrue)
|
|
118
|
+
# define Py_IsTrue(x) Py_Is(x, Py_True)
|
|
119
|
+
#endif
|
|
120
|
+
#if PY_VERSION_HEX < 0x030A00B1 && !defined(Py_IsFalse)
|
|
121
|
+
# define Py_IsFalse(x) Py_Is(x, Py_False)
|
|
122
|
+
#endif
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
// bpo-39573 added Py_SET_TYPE() to Python 3.9.0a4
|
|
126
|
+
#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
|
|
127
|
+
PYCAPI_COMPAT_STATIC_INLINE(void)
|
|
128
|
+
_Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
|
|
129
|
+
{
|
|
130
|
+
ob->ob_type = type;
|
|
131
|
+
}
|
|
132
|
+
#define Py_SET_TYPE(ob, type) _Py_SET_TYPE(_PyObject_CAST(ob), type)
|
|
133
|
+
#endif
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
// bpo-39573 added Py_SET_SIZE() to Python 3.9.0a4
|
|
137
|
+
#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_SIZE)
|
|
138
|
+
PYCAPI_COMPAT_STATIC_INLINE(void)
|
|
139
|
+
_Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size)
|
|
140
|
+
{
|
|
141
|
+
ob->ob_size = size;
|
|
142
|
+
}
|
|
143
|
+
#define Py_SET_SIZE(ob, size) _Py_SET_SIZE((PyVarObject*)(ob), size)
|
|
144
|
+
#endif
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
// bpo-40421 added PyFrame_GetCode() to Python 3.9.0b1
|
|
148
|
+
#if PY_VERSION_HEX < 0x030900B1
|
|
149
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyCodeObject*)
|
|
150
|
+
PyFrame_GetCode(PyFrameObject *frame)
|
|
151
|
+
{
|
|
152
|
+
assert(frame != _Py_NULL);
|
|
153
|
+
assert(frame->f_code != _Py_NULL);
|
|
154
|
+
return _Py_CAST(PyCodeObject*, Py_NewRef(frame->f_code));
|
|
155
|
+
}
|
|
156
|
+
#endif
|
|
157
|
+
|
|
158
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyCodeObject*)
|
|
159
|
+
_PyFrame_GetCodeBorrow(PyFrameObject *frame)
|
|
160
|
+
{
|
|
161
|
+
PyCodeObject *code = PyFrame_GetCode(frame);
|
|
162
|
+
Py_DECREF(code);
|
|
163
|
+
return code;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
// bpo-40421 added PyFrame_GetBack() to Python 3.9.0b1
|
|
168
|
+
#if PY_VERSION_HEX < 0x030900B1 && !defined(PYPY_VERSION)
|
|
169
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyFrameObject*)
|
|
170
|
+
PyFrame_GetBack(PyFrameObject *frame)
|
|
171
|
+
{
|
|
172
|
+
assert(frame != _Py_NULL);
|
|
173
|
+
return _Py_CAST(PyFrameObject*, Py_XNewRef(frame->f_back));
|
|
174
|
+
}
|
|
175
|
+
#endif
|
|
176
|
+
|
|
177
|
+
#if !defined(PYPY_VERSION)
|
|
178
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyFrameObject*)
|
|
179
|
+
_PyFrame_GetBackBorrow(PyFrameObject *frame)
|
|
180
|
+
{
|
|
181
|
+
PyFrameObject *back = PyFrame_GetBack(frame);
|
|
182
|
+
Py_XDECREF(back);
|
|
183
|
+
return back;
|
|
184
|
+
}
|
|
185
|
+
#endif
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
// bpo-40421 added PyFrame_GetLocals() to Python 3.11.0a7
|
|
189
|
+
#if PY_VERSION_HEX < 0x030B00A7 && !defined(PYPY_VERSION)
|
|
190
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
|
|
191
|
+
PyFrame_GetLocals(PyFrameObject *frame)
|
|
192
|
+
{
|
|
193
|
+
#if PY_VERSION_HEX >= 0x030400B1
|
|
194
|
+
if (PyFrame_FastToLocalsWithError(frame) < 0) {
|
|
195
|
+
return NULL;
|
|
196
|
+
}
|
|
197
|
+
#else
|
|
198
|
+
PyFrame_FastToLocals(frame);
|
|
199
|
+
#endif
|
|
200
|
+
return Py_NewRef(frame->f_locals);
|
|
201
|
+
}
|
|
202
|
+
#endif
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
// bpo-40421 added PyFrame_GetGlobals() to Python 3.11.0a7
|
|
206
|
+
#if PY_VERSION_HEX < 0x030B00A7 && !defined(PYPY_VERSION)
|
|
207
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
|
|
208
|
+
PyFrame_GetGlobals(PyFrameObject *frame)
|
|
209
|
+
{
|
|
210
|
+
return Py_NewRef(frame->f_globals);
|
|
211
|
+
}
|
|
212
|
+
#endif
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
// bpo-40421 added PyFrame_GetBuiltins() to Python 3.11.0a7
|
|
216
|
+
#if PY_VERSION_HEX < 0x030B00A7 && !defined(PYPY_VERSION)
|
|
217
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
|
|
218
|
+
PyFrame_GetBuiltins(PyFrameObject *frame)
|
|
219
|
+
{
|
|
220
|
+
return Py_NewRef(frame->f_builtins);
|
|
221
|
+
}
|
|
222
|
+
#endif
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
// bpo-40421 added PyFrame_GetLasti() to Python 3.11.0b1
|
|
226
|
+
#if PY_VERSION_HEX < 0x030B00B1 && !defined(PYPY_VERSION)
|
|
227
|
+
PYCAPI_COMPAT_STATIC_INLINE(int)
|
|
228
|
+
PyFrame_GetLasti(PyFrameObject *frame)
|
|
229
|
+
{
|
|
230
|
+
#if PY_VERSION_HEX >= 0x030A00A7
|
|
231
|
+
// bpo-27129: Since Python 3.10.0a7, f_lasti is an instruction offset,
|
|
232
|
+
// not a bytes offset anymore. Python uses 16-bit "wordcode" (2 bytes)
|
|
233
|
+
// instructions.
|
|
234
|
+
if (frame->f_lasti < 0) {
|
|
235
|
+
return -1;
|
|
236
|
+
}
|
|
237
|
+
return frame->f_lasti * 2;
|
|
238
|
+
#else
|
|
239
|
+
return frame->f_lasti;
|
|
240
|
+
#endif
|
|
241
|
+
}
|
|
242
|
+
#endif
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
// bpo-39947 added PyThreadState_GetInterpreter() to Python 3.9.0a5
|
|
246
|
+
#if PY_VERSION_HEX < 0x030900A5
|
|
247
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyInterpreterState *)
|
|
248
|
+
PyThreadState_GetInterpreter(PyThreadState *tstate)
|
|
249
|
+
{
|
|
250
|
+
assert(tstate != _Py_NULL);
|
|
251
|
+
return tstate->interp;
|
|
252
|
+
}
|
|
253
|
+
#endif
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
// bpo-40429 added PyThreadState_GetFrame() to Python 3.9.0b1
|
|
257
|
+
#if PY_VERSION_HEX < 0x030900B1 && !defined(PYPY_VERSION)
|
|
258
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyFrameObject*)
|
|
259
|
+
PyThreadState_GetFrame(PyThreadState *tstate)
|
|
260
|
+
{
|
|
261
|
+
assert(tstate != _Py_NULL);
|
|
262
|
+
return _Py_CAST(PyFrameObject *, Py_XNewRef(tstate->frame));
|
|
263
|
+
}
|
|
264
|
+
#endif
|
|
265
|
+
|
|
266
|
+
#if !defined(PYPY_VERSION)
|
|
267
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyFrameObject*)
|
|
268
|
+
_PyThreadState_GetFrameBorrow(PyThreadState *tstate)
|
|
269
|
+
{
|
|
270
|
+
PyFrameObject *frame = PyThreadState_GetFrame(tstate);
|
|
271
|
+
Py_XDECREF(frame);
|
|
272
|
+
return frame;
|
|
273
|
+
}
|
|
274
|
+
#endif
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
// bpo-39947 added PyInterpreterState_Get() to Python 3.9.0a5
|
|
278
|
+
#if PY_VERSION_HEX < 0x030900A5
|
|
279
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyInterpreterState*)
|
|
280
|
+
PyInterpreterState_Get(void)
|
|
281
|
+
{
|
|
282
|
+
PyThreadState *tstate;
|
|
283
|
+
PyInterpreterState *interp;
|
|
284
|
+
|
|
285
|
+
tstate = PyThreadState_GET();
|
|
286
|
+
if (tstate == _Py_NULL) {
|
|
287
|
+
Py_FatalError("GIL released (tstate is NULL)");
|
|
288
|
+
}
|
|
289
|
+
interp = tstate->interp;
|
|
290
|
+
if (interp == _Py_NULL) {
|
|
291
|
+
Py_FatalError("no current interpreter");
|
|
292
|
+
}
|
|
293
|
+
return interp;
|
|
294
|
+
}
|
|
295
|
+
#endif
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
// bpo-39947 added PyInterpreterState_Get() to Python 3.9.0a6
|
|
299
|
+
#if 0x030700A1 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x030900A6 && !defined(PYPY_VERSION)
|
|
300
|
+
PYCAPI_COMPAT_STATIC_INLINE(uint64_t)
|
|
301
|
+
PyThreadState_GetID(PyThreadState *tstate)
|
|
302
|
+
{
|
|
303
|
+
assert(tstate != _Py_NULL);
|
|
304
|
+
return tstate->id;
|
|
305
|
+
}
|
|
306
|
+
#endif
|
|
307
|
+
|
|
308
|
+
// bpo-43760 added PyThreadState_EnterTracing() to Python 3.11.0a2
|
|
309
|
+
#if PY_VERSION_HEX < 0x030B00A2 && !defined(PYPY_VERSION)
|
|
310
|
+
PYCAPI_COMPAT_STATIC_INLINE(void)
|
|
311
|
+
PyThreadState_EnterTracing(PyThreadState *tstate)
|
|
312
|
+
{
|
|
313
|
+
tstate->tracing++;
|
|
314
|
+
#if PY_VERSION_HEX >= 0x030A00A1
|
|
315
|
+
tstate->cframe->use_tracing = 0;
|
|
316
|
+
#else
|
|
317
|
+
tstate->use_tracing = 0;
|
|
318
|
+
#endif
|
|
319
|
+
}
|
|
320
|
+
#endif
|
|
321
|
+
|
|
322
|
+
// bpo-43760 added PyThreadState_LeaveTracing() to Python 3.11.0a2
|
|
323
|
+
#if PY_VERSION_HEX < 0x030B00A2 && !defined(PYPY_VERSION)
|
|
324
|
+
PYCAPI_COMPAT_STATIC_INLINE(void)
|
|
325
|
+
PyThreadState_LeaveTracing(PyThreadState *tstate)
|
|
326
|
+
{
|
|
327
|
+
int use_tracing = (tstate->c_tracefunc != _Py_NULL
|
|
328
|
+
|| tstate->c_profilefunc != _Py_NULL);
|
|
329
|
+
tstate->tracing--;
|
|
330
|
+
#if PY_VERSION_HEX >= 0x030A00A1
|
|
331
|
+
tstate->cframe->use_tracing = use_tracing;
|
|
332
|
+
#else
|
|
333
|
+
tstate->use_tracing = use_tracing;
|
|
334
|
+
#endif
|
|
335
|
+
}
|
|
336
|
+
#endif
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
// bpo-37194 added PyObject_CallNoArgs() to Python 3.9.0a1
|
|
340
|
+
#if PY_VERSION_HEX < 0x030900A1
|
|
341
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
|
|
342
|
+
PyObject_CallNoArgs(PyObject *func)
|
|
343
|
+
{
|
|
344
|
+
return PyObject_CallFunctionObjArgs(func, NULL);
|
|
345
|
+
}
|
|
346
|
+
#endif
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
// bpo-39245 made PyObject_CallOneArg() public (previously called
|
|
350
|
+
// _PyObject_CallOneArg) in Python 3.9.0a4
|
|
351
|
+
#if PY_VERSION_HEX < 0x030900A4
|
|
352
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
|
|
353
|
+
PyObject_CallOneArg(PyObject *func, PyObject *arg)
|
|
354
|
+
{
|
|
355
|
+
return PyObject_CallFunctionObjArgs(func, arg, NULL);
|
|
356
|
+
}
|
|
357
|
+
#endif
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
// bpo-1635741 added PyModule_AddObjectRef() to Python 3.10.0a3
|
|
361
|
+
#if PY_VERSION_HEX < 0x030A00A3
|
|
362
|
+
PYCAPI_COMPAT_STATIC_INLINE(int)
|
|
363
|
+
PyModule_AddObjectRef(PyObject *module, const char *name, PyObject *value)
|
|
364
|
+
{
|
|
365
|
+
int res;
|
|
366
|
+
Py_XINCREF(value);
|
|
367
|
+
res = PyModule_AddObject(module, name, value);
|
|
368
|
+
if (res < 0) {
|
|
369
|
+
Py_XDECREF(value);
|
|
370
|
+
}
|
|
371
|
+
return res;
|
|
372
|
+
}
|
|
373
|
+
#endif
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
// bpo-40024 added PyModule_AddType() to Python 3.9.0a5
|
|
377
|
+
#if PY_VERSION_HEX < 0x030900A5
|
|
378
|
+
PYCAPI_COMPAT_STATIC_INLINE(int)
|
|
379
|
+
PyModule_AddType(PyObject *module, PyTypeObject *type)
|
|
380
|
+
{
|
|
381
|
+
const char *name, *dot;
|
|
382
|
+
|
|
383
|
+
if (PyType_Ready(type) < 0) {
|
|
384
|
+
return -1;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// inline _PyType_Name()
|
|
388
|
+
name = type->tp_name;
|
|
389
|
+
assert(name != _Py_NULL);
|
|
390
|
+
dot = strrchr(name, '.');
|
|
391
|
+
if (dot != _Py_NULL) {
|
|
392
|
+
name = dot + 1;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return PyModule_AddObjectRef(module, name, _PyObject_CAST(type));
|
|
396
|
+
}
|
|
397
|
+
#endif
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
// bpo-40241 added PyObject_GC_IsTracked() to Python 3.9.0a6.
|
|
401
|
+
// bpo-4688 added _PyObject_GC_IS_TRACKED() to Python 2.7.0a2.
|
|
402
|
+
#if PY_VERSION_HEX < 0x030900A6 && !defined(PYPY_VERSION)
|
|
403
|
+
PYCAPI_COMPAT_STATIC_INLINE(int)
|
|
404
|
+
PyObject_GC_IsTracked(PyObject* obj)
|
|
405
|
+
{
|
|
406
|
+
return (PyObject_IS_GC(obj) && _PyObject_GC_IS_TRACKED(obj));
|
|
407
|
+
}
|
|
408
|
+
#endif
|
|
409
|
+
|
|
410
|
+
// bpo-40241 added PyObject_GC_IsFinalized() to Python 3.9.0a6.
|
|
411
|
+
// bpo-18112 added _PyGCHead_FINALIZED() to Python 3.4.0 final.
|
|
412
|
+
#if PY_VERSION_HEX < 0x030900A6 && PY_VERSION_HEX >= 0x030400F0 && !defined(PYPY_VERSION)
|
|
413
|
+
PYCAPI_COMPAT_STATIC_INLINE(int)
|
|
414
|
+
PyObject_GC_IsFinalized(PyObject *obj)
|
|
415
|
+
{
|
|
416
|
+
PyGC_Head *gc = _Py_CAST(PyGC_Head*, obj) - 1;
|
|
417
|
+
return (PyObject_IS_GC(obj) && _PyGCHead_FINALIZED(gc));
|
|
418
|
+
}
|
|
419
|
+
#endif
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
// bpo-39573 added Py_IS_TYPE() to Python 3.9.0a4
|
|
423
|
+
#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_IS_TYPE)
|
|
424
|
+
PYCAPI_COMPAT_STATIC_INLINE(int)
|
|
425
|
+
_Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
|
|
426
|
+
return Py_TYPE(ob) == type;
|
|
427
|
+
}
|
|
428
|
+
#define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST(ob), type)
|
|
429
|
+
#endif
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
// bpo-46906 added PyFloat_Pack2() and PyFloat_Unpack2() to Python 3.11a7.
|
|
433
|
+
// bpo-11734 added _PyFloat_Pack2() and _PyFloat_Unpack2() to Python 3.6.0b1.
|
|
434
|
+
// Python 3.11a2 moved _PyFloat_Pack2() and _PyFloat_Unpack2() to the internal
|
|
435
|
+
// C API: Python 3.11a2-3.11a6 versions are not supported.
|
|
436
|
+
#if 0x030600B1 <= PY_VERSION_HEX && PY_VERSION_HEX <= 0x030B00A1 && !defined(PYPY_VERSION)
|
|
437
|
+
PYCAPI_COMPAT_STATIC_INLINE(int)
|
|
438
|
+
PyFloat_Pack2(double x, char *p, int le)
|
|
439
|
+
{ return _PyFloat_Pack2(x, (unsigned char*)p, le); }
|
|
440
|
+
|
|
441
|
+
PYCAPI_COMPAT_STATIC_INLINE(double)
|
|
442
|
+
PyFloat_Unpack2(const char *p, int le)
|
|
443
|
+
{ return _PyFloat_Unpack2((const unsigned char *)p, le); }
|
|
444
|
+
#endif
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
// bpo-46906 added PyFloat_Pack4(), PyFloat_Pack8(), PyFloat_Unpack4() and
|
|
448
|
+
// PyFloat_Unpack8() to Python 3.11a7.
|
|
449
|
+
// Python 3.11a2 moved _PyFloat_Pack4(), _PyFloat_Pack8(), _PyFloat_Unpack4()
|
|
450
|
+
// and _PyFloat_Unpack8() to the internal C API: Python 3.11a2-3.11a6 versions
|
|
451
|
+
// are not supported.
|
|
452
|
+
#if PY_VERSION_HEX <= 0x030B00A1 && !defined(PYPY_VERSION)
|
|
453
|
+
PYCAPI_COMPAT_STATIC_INLINE(int)
|
|
454
|
+
PyFloat_Pack4(double x, char *p, int le)
|
|
455
|
+
{ return _PyFloat_Pack4(x, (unsigned char*)p, le); }
|
|
456
|
+
|
|
457
|
+
PYCAPI_COMPAT_STATIC_INLINE(int)
|
|
458
|
+
PyFloat_Pack8(double x, char *p, int le)
|
|
459
|
+
{ return _PyFloat_Pack8(x, (unsigned char*)p, le); }
|
|
460
|
+
|
|
461
|
+
PYCAPI_COMPAT_STATIC_INLINE(double)
|
|
462
|
+
PyFloat_Unpack4(const char *p, int le)
|
|
463
|
+
{ return _PyFloat_Unpack4((const unsigned char *)p, le); }
|
|
464
|
+
|
|
465
|
+
PYCAPI_COMPAT_STATIC_INLINE(double)
|
|
466
|
+
PyFloat_Unpack8(const char *p, int le)
|
|
467
|
+
{ return _PyFloat_Unpack8((const unsigned char *)p, le); }
|
|
468
|
+
#endif
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
// gh-92154 added PyCode_GetCode() to Python 3.11.0b1
|
|
472
|
+
#if PY_VERSION_HEX < 0x030B00B1 && !defined(PYPY_VERSION)
|
|
473
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
|
|
474
|
+
PyCode_GetCode(PyCodeObject *code)
|
|
475
|
+
{
|
|
476
|
+
return Py_NewRef(code->co_code);
|
|
477
|
+
}
|
|
478
|
+
#endif
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
// gh-95008 added PyCode_GetVarnames() to Python 3.11.0rc1
|
|
482
|
+
#if PY_VERSION_HEX < 0x030B00C1 && !defined(PYPY_VERSION)
|
|
483
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
|
|
484
|
+
PyCode_GetVarnames(PyCodeObject *code)
|
|
485
|
+
{
|
|
486
|
+
return Py_NewRef(code->co_varnames);
|
|
487
|
+
}
|
|
488
|
+
#endif
|
|
489
|
+
|
|
490
|
+
// gh-95008 added PyCode_GetFreevars() to Python 3.11.0rc1
|
|
491
|
+
#if PY_VERSION_HEX < 0x030B00C1 && !defined(PYPY_VERSION)
|
|
492
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
|
|
493
|
+
PyCode_GetFreevars(PyCodeObject *code)
|
|
494
|
+
{
|
|
495
|
+
return Py_NewRef(code->co_freevars);
|
|
496
|
+
}
|
|
497
|
+
#endif
|
|
498
|
+
|
|
499
|
+
// gh-95008 added PyCode_GetCellvars() to Python 3.11.0rc1
|
|
500
|
+
#if PY_VERSION_HEX < 0x030B00C1 && !defined(PYPY_VERSION)
|
|
501
|
+
PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
|
|
502
|
+
PyCode_GetCellvars(PyCodeObject *code)
|
|
503
|
+
{
|
|
504
|
+
return Py_NewRef(code->co_cellvars);
|
|
505
|
+
}
|
|
506
|
+
#endif
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
// Py_UNUSED() was added to Python 3.4.0b2.
|
|
510
|
+
#if PY_VERSION_HEX < 0x030400B2 && !defined(Py_UNUSED)
|
|
511
|
+
# if defined(__GNUC__) || defined(__clang__)
|
|
512
|
+
# define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
|
|
513
|
+
# else
|
|
514
|
+
# define Py_UNUSED(name) _unused_ ## name
|
|
515
|
+
# endif
|
|
516
|
+
#endif
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
#ifdef __cplusplus
|
|
520
|
+
}
|
|
521
|
+
#endif
|
|
522
|
+
#endif // PYTHONCAPI_COMPAT
|