2023-08-21 19:15:52 +02:00
|
|
|
#ifndef Py_BUILD_CORE_BUILTIN
|
|
|
|
# define Py_BUILD_CORE_MODULE 1
|
|
|
|
#endif
|
|
|
|
|
2013-11-23 23:49:22 +01:00
|
|
|
#include "Python.h"
|
2023-07-14 19:41:52 +02:00
|
|
|
#include "compile.h"
|
2013-11-23 23:49:22 +01:00
|
|
|
#include "opcode.h"
|
2024-06-26 13:54:03 +02:00
|
|
|
#include "pycore_ceval.h"
|
|
|
|
#include "pycore_code.h"
|
|
|
|
#include "pycore_compile.h"
|
|
|
|
#include "pycore_intrinsics.h"
|
|
|
|
#include "pycore_optimizer.h" // _Py_GetExecutor()
|
2024-07-11 00:48:37 +02:00
|
|
|
#include "pycore_opcode_metadata.h" // IS_VALID_OPCODE, OPCODE_HAS_*, etc
|
|
|
|
#include "pycore_opcode_utils.h"
|
2013-11-23 23:49:22 +01:00
|
|
|
|
2014-01-07 21:41:53 +01:00
|
|
|
/*[clinic input]
|
2013-11-23 23:49:22 +01:00
|
|
|
module _opcode
|
2014-01-07 21:41:53 +01:00
|
|
|
[clinic start generated code]*/
|
2014-01-28 14:00:08 +01:00
|
|
|
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=117442e66eb376e6]*/
|
2013-11-24 00:37:55 +01:00
|
|
|
|
2015-04-03 22:53:51 +02:00
|
|
|
#include "clinic/_opcode.c.h"
|
|
|
|
|
2014-01-07 21:41:53 +01:00
|
|
|
/*[clinic input]
|
2013-11-23 23:49:22 +01:00
|
|
|
|
|
|
|
_opcode.stack_effect -> int
|
|
|
|
|
|
|
|
opcode: int
|
2014-02-01 07:03:12 +01:00
|
|
|
oparg: object = None
|
2013-11-23 23:49:22 +01:00
|
|
|
/
|
2018-09-18 08:54:26 +02:00
|
|
|
*
|
|
|
|
jump: object = None
|
2013-11-23 23:49:22 +01:00
|
|
|
|
|
|
|
Compute the stack effect of the opcode.
|
2014-01-07 21:41:53 +01:00
|
|
|
[clinic start generated code]*/
|
2013-11-23 23:49:22 +01:00
|
|
|
|
|
|
|
static int
|
2018-09-18 08:54:26 +02:00
|
|
|
_opcode_stack_effect_impl(PyObject *module, int opcode, PyObject *oparg,
|
|
|
|
PyObject *jump)
|
|
|
|
/*[clinic end generated code: output=64a18f2ead954dbb input=461c9d4a44851898]*/
|
2013-11-23 23:49:22 +01:00
|
|
|
{
|
2014-02-01 07:03:12 +01:00
|
|
|
int oparg_int = 0;
|
2018-09-18 08:54:26 +02:00
|
|
|
int jump_int;
|
2023-06-17 18:00:16 +02:00
|
|
|
|
|
|
|
if (oparg != Py_None) {
|
2014-02-01 07:03:12 +01:00
|
|
|
oparg_int = (int)PyLong_AsLong(oparg);
|
2020-09-07 10:48:44 +02:00
|
|
|
if ((oparg_int == -1) && PyErr_Occurred()) {
|
2014-02-01 07:03:12 +01:00
|
|
|
return -1;
|
2020-09-07 10:48:44 +02:00
|
|
|
}
|
2013-11-23 23:49:22 +01:00
|
|
|
}
|
2023-06-17 18:00:16 +02:00
|
|
|
|
2018-09-18 08:54:26 +02:00
|
|
|
if (jump == Py_None) {
|
|
|
|
jump_int = -1;
|
|
|
|
}
|
|
|
|
else if (jump == Py_True) {
|
|
|
|
jump_int = 1;
|
|
|
|
}
|
|
|
|
else if (jump == Py_False) {
|
|
|
|
jump_int = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"stack_effect: jump must be False, True or None");
|
|
|
|
return -1;
|
|
|
|
}
|
2023-06-17 18:00:16 +02:00
|
|
|
int effect = PyCompile_OpcodeStackEffectWithJump(opcode, oparg_int, jump_int);
|
2013-11-23 23:49:22 +01:00
|
|
|
if (effect == PY_INVALID_STACK_EFFECT) {
|
2023-06-17 18:00:16 +02:00
|
|
|
PyErr_SetString(PyExc_ValueError, "invalid opcode or oparg");
|
|
|
|
return -1;
|
2013-11-23 23:49:22 +01:00
|
|
|
}
|
|
|
|
return effect;
|
|
|
|
}
|
|
|
|
|
2021-07-29 18:26:53 +02:00
|
|
|
/*[clinic input]
|
|
|
|
|
2023-07-14 19:41:52 +02:00
|
|
|
_opcode.is_valid -> bool
|
|
|
|
|
|
|
|
opcode: int
|
|
|
|
|
|
|
|
Return True if opcode is valid, False otherwise.
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
_opcode_is_valid_impl(PyObject *module, int opcode)
|
|
|
|
/*[clinic end generated code: output=b0d918ea1d073f65 input=fe23e0aa194ddae0]*/
|
|
|
|
{
|
2024-07-11 00:48:37 +02:00
|
|
|
return IS_VALID_OPCODE(opcode);
|
2023-07-14 19:41:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
|
|
|
|
_opcode.has_arg -> bool
|
|
|
|
|
|
|
|
opcode: int
|
|
|
|
|
|
|
|
Return True if the opcode uses its oparg, False otherwise.
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
_opcode_has_arg_impl(PyObject *module, int opcode)
|
|
|
|
/*[clinic end generated code: output=7a062d3b2dcc0815 input=93d878ba6361db5f]*/
|
|
|
|
{
|
2024-07-11 00:48:37 +02:00
|
|
|
return IS_VALID_OPCODE(opcode) && OPCODE_HAS_ARG(opcode);
|
2023-07-14 19:41:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
|
|
|
|
_opcode.has_const -> bool
|
|
|
|
|
|
|
|
opcode: int
|
|
|
|
|
|
|
|
Return True if the opcode accesses a constant, False otherwise.
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
_opcode_has_const_impl(PyObject *module, int opcode)
|
|
|
|
/*[clinic end generated code: output=c646d5027c634120 input=a6999e4cf13f9410]*/
|
|
|
|
{
|
2024-07-11 00:48:37 +02:00
|
|
|
return IS_VALID_OPCODE(opcode) && OPCODE_HAS_CONST(opcode);
|
2023-07-14 19:41:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
|
|
|
|
_opcode.has_name -> bool
|
|
|
|
|
|
|
|
opcode: int
|
|
|
|
|
|
|
|
Return True if the opcode accesses an attribute by name, False otherwise.
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
_opcode_has_name_impl(PyObject *module, int opcode)
|
|
|
|
/*[clinic end generated code: output=b49a83555c2fa517 input=448aa5e4bcc947ba]*/
|
|
|
|
{
|
2024-07-11 00:48:37 +02:00
|
|
|
return IS_VALID_OPCODE(opcode) && OPCODE_HAS_NAME(opcode);
|
2023-07-14 19:41:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
|
|
|
|
_opcode.has_jump -> bool
|
|
|
|
|
|
|
|
opcode: int
|
|
|
|
|
|
|
|
Return True if the opcode has a jump target, False otherwise.
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
_opcode_has_jump_impl(PyObject *module, int opcode)
|
|
|
|
/*[clinic end generated code: output=e9c583c669f1c46a input=35f711274357a0c3]*/
|
|
|
|
{
|
2024-07-11 00:48:37 +02:00
|
|
|
return IS_VALID_OPCODE(opcode) && OPCODE_HAS_JUMP(opcode);
|
2023-07-14 19:41:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
|
2023-07-18 20:42:44 +02:00
|
|
|
_opcode.has_free -> bool
|
|
|
|
|
|
|
|
opcode: int
|
|
|
|
|
|
|
|
Return True if the opcode accesses a free variable, False otherwise.
|
|
|
|
|
|
|
|
Note that 'free' in this context refers to names in the current scope
|
|
|
|
that are referenced by inner scopes or names in outer scopes that are
|
|
|
|
referenced from this scope. It does not include references to global
|
|
|
|
or builtin scopes.
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
_opcode_has_free_impl(PyObject *module, int opcode)
|
|
|
|
/*[clinic end generated code: output=d81ae4d79af0ee26 input=117dcd5c19c1139b]*/
|
|
|
|
{
|
2024-07-11 00:48:37 +02:00
|
|
|
return IS_VALID_OPCODE(opcode) && OPCODE_HAS_FREE(opcode);
|
2023-07-18 20:42:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
|
|
|
|
_opcode.has_local -> bool
|
|
|
|
|
|
|
|
opcode: int
|
|
|
|
|
|
|
|
Return True if the opcode accesses a local variable, False otherwise.
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
_opcode_has_local_impl(PyObject *module, int opcode)
|
|
|
|
/*[clinic end generated code: output=da5a8616b7a5097b input=9a798ee24aaef49d]*/
|
|
|
|
{
|
2024-07-11 00:48:37 +02:00
|
|
|
return IS_VALID_OPCODE(opcode) && OPCODE_HAS_LOCAL(opcode);
|
2023-07-18 20:42:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
|
|
|
|
_opcode.has_exc -> bool
|
|
|
|
|
|
|
|
opcode: int
|
|
|
|
|
|
|
|
Return True if the opcode sets an exception handler, False otherwise.
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
_opcode_has_exc_impl(PyObject *module, int opcode)
|
|
|
|
/*[clinic end generated code: output=41b68dff0ec82a52 input=db0e4bdb9bf13fa5]*/
|
|
|
|
{
|
2024-07-11 00:48:37 +02:00
|
|
|
return IS_VALID_OPCODE(opcode) && IS_BLOCK_PUSH_OPCODE(opcode);
|
2023-07-18 20:42:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
|
2021-07-29 18:26:53 +02:00
|
|
|
_opcode.get_specialization_stats
|
|
|
|
|
|
|
|
Return the specialization stats
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_opcode_get_specialization_stats_impl(PyObject *module)
|
|
|
|
/*[clinic end generated code: output=fcbc32fdfbec5c17 input=e1f60db68d8ce5f6]*/
|
|
|
|
{
|
2021-12-15 16:32:32 +01:00
|
|
|
#ifdef Py_STATS
|
2021-07-29 18:26:53 +02:00
|
|
|
return _Py_GetSpecializationStats();
|
|
|
|
#else
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-07-20 18:46:04 +02:00
|
|
|
/*[clinic input]
|
|
|
|
|
2023-08-17 18:07:58 +02:00
|
|
|
_opcode.get_nb_ops
|
|
|
|
|
|
|
|
Return array of symbols of binary ops.
|
|
|
|
|
|
|
|
Indexed by the BINARY_OP oparg value.
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_opcode_get_nb_ops_impl(PyObject *module)
|
|
|
|
/*[clinic end generated code: output=d997d306cc15426f input=9462fc544c823176]*/
|
|
|
|
{
|
|
|
|
PyObject *list = PyList_New(NB_OPARG_LAST + 1);
|
|
|
|
if (list == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#define ADD_NB_OP(NUM, STR) \
|
|
|
|
do { \
|
2023-10-20 17:08:41 +02:00
|
|
|
PyObject *pair = Py_BuildValue("ss", #NUM, STR); \
|
2023-08-17 18:07:58 +02:00
|
|
|
if (pair == NULL) { \
|
|
|
|
Py_DECREF(list); \
|
|
|
|
return NULL; \
|
|
|
|
} \
|
|
|
|
PyList_SET_ITEM(list, (NUM), pair); \
|
|
|
|
} while(0);
|
|
|
|
|
|
|
|
ADD_NB_OP(NB_ADD, "+");
|
|
|
|
ADD_NB_OP(NB_AND, "&");
|
|
|
|
ADD_NB_OP(NB_FLOOR_DIVIDE, "//");
|
|
|
|
ADD_NB_OP(NB_LSHIFT, "<<");
|
|
|
|
ADD_NB_OP(NB_MATRIX_MULTIPLY, "@");
|
|
|
|
ADD_NB_OP(NB_MULTIPLY, "*");
|
|
|
|
ADD_NB_OP(NB_REMAINDER, "%");
|
|
|
|
ADD_NB_OP(NB_OR, "|");
|
|
|
|
ADD_NB_OP(NB_POWER, "**");
|
|
|
|
ADD_NB_OP(NB_RSHIFT, ">>");
|
|
|
|
ADD_NB_OP(NB_SUBTRACT, "-");
|
|
|
|
ADD_NB_OP(NB_TRUE_DIVIDE, "/");
|
|
|
|
ADD_NB_OP(NB_XOR, "^");
|
|
|
|
ADD_NB_OP(NB_INPLACE_ADD, "+=");
|
|
|
|
ADD_NB_OP(NB_INPLACE_AND, "&=");
|
|
|
|
ADD_NB_OP(NB_INPLACE_FLOOR_DIVIDE, "//=");
|
|
|
|
ADD_NB_OP(NB_INPLACE_LSHIFT, "<<=");
|
|
|
|
ADD_NB_OP(NB_INPLACE_MATRIX_MULTIPLY, "@=");
|
|
|
|
ADD_NB_OP(NB_INPLACE_MULTIPLY, "*=");
|
|
|
|
ADD_NB_OP(NB_INPLACE_REMAINDER, "%=");
|
|
|
|
ADD_NB_OP(NB_INPLACE_OR, "|=");
|
|
|
|
ADD_NB_OP(NB_INPLACE_POWER, "**=");
|
|
|
|
ADD_NB_OP(NB_INPLACE_RSHIFT, ">>=");
|
|
|
|
ADD_NB_OP(NB_INPLACE_SUBTRACT, "-=");
|
|
|
|
ADD_NB_OP(NB_INPLACE_TRUE_DIVIDE, "/=");
|
|
|
|
ADD_NB_OP(NB_INPLACE_XOR, "^=");
|
|
|
|
|
|
|
|
#undef ADD_NB_OP
|
|
|
|
|
|
|
|
for(int i = 0; i <= NB_OPARG_LAST; i++) {
|
|
|
|
if (PyList_GET_ITEM(list, i) == NULL) {
|
|
|
|
Py_DECREF(list);
|
|
|
|
PyErr_Format(PyExc_ValueError,
|
|
|
|
"Missing initialization for NB_OP %d",
|
|
|
|
i);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
|
2023-07-20 18:46:04 +02:00
|
|
|
_opcode.get_intrinsic1_descs
|
|
|
|
|
|
|
|
Return a list of names of the unary intrinsics.
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_opcode_get_intrinsic1_descs_impl(PyObject *module)
|
|
|
|
/*[clinic end generated code: output=bd1ddb6b4447d18b input=13b51c712618459b]*/
|
|
|
|
{
|
|
|
|
PyObject *list = PyList_New(MAX_INTRINSIC_1 + 1);
|
|
|
|
if (list == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
for (int i=0; i <= MAX_INTRINSIC_1; i++) {
|
2023-11-14 01:31:02 +01:00
|
|
|
PyObject *name = _PyCompile_GetUnaryIntrinsicName(i);
|
2023-07-20 18:46:04 +02:00
|
|
|
if (name == NULL) {
|
|
|
|
Py_DECREF(list);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
PyList_SET_ITEM(list, i, name);
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
|
|
|
|
_opcode.get_intrinsic2_descs
|
|
|
|
|
|
|
|
Return a list of names of the binary intrinsics.
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_opcode_get_intrinsic2_descs_impl(PyObject *module)
|
|
|
|
/*[clinic end generated code: output=40e62bc27584c8a0 input=e83068f249f5471b]*/
|
|
|
|
{
|
|
|
|
PyObject *list = PyList_New(MAX_INTRINSIC_2 + 1);
|
|
|
|
if (list == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
for (int i=0; i <= MAX_INTRINSIC_2; i++) {
|
2023-11-14 01:31:02 +01:00
|
|
|
PyObject *name = _PyCompile_GetBinaryIntrinsicName(i);
|
2023-07-20 18:46:04 +02:00
|
|
|
if (name == NULL) {
|
|
|
|
Py_DECREF(list);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
PyList_SET_ITEM(list, i, name);
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2024-03-23 23:32:33 +01:00
|
|
|
/*[clinic input]
|
|
|
|
|
2024-06-20 16:07:24 +02:00
|
|
|
_opcode.get_special_method_names
|
|
|
|
|
|
|
|
Return a list of special method names.
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_opcode_get_special_method_names_impl(PyObject *module)
|
|
|
|
/*[clinic end generated code: output=fce72614cd988d17 input=25f2115560bdf163]*/
|
|
|
|
{
|
|
|
|
PyObject *list = PyList_New(SPECIAL_MAX + 1);
|
|
|
|
if (list == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
for (int i=0; i <= SPECIAL_MAX; i++) {
|
|
|
|
PyObject *name = _Py_SpecialMethods[i].name;
|
|
|
|
if (name == NULL) {
|
|
|
|
Py_DECREF(list);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
PyList_SET_ITEM(list, i, name);
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
|
2024-03-23 23:32:33 +01:00
|
|
|
_opcode.get_executor
|
|
|
|
|
|
|
|
code: object
|
|
|
|
offset: int
|
|
|
|
|
|
|
|
Return the executor object at offset in code if exists, None otherwise.
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_opcode_get_executor_impl(PyObject *module, PyObject *code, int offset)
|
|
|
|
/*[clinic end generated code: output=c035c7a47b16648f input=85eff93ea7aac282]*/
|
|
|
|
{
|
|
|
|
if (!PyCode_Check(code)) {
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
"expected a code object, not '%.100s'",
|
|
|
|
Py_TYPE(code)->tp_name);
|
|
|
|
return NULL;
|
|
|
|
}
|
2024-05-01 03:26:34 +02:00
|
|
|
#ifdef _Py_TIER2
|
2024-06-26 13:54:03 +02:00
|
|
|
return (PyObject *)_Py_GetExecutor((PyCodeObject *)code, offset);
|
2024-05-01 03:26:34 +02:00
|
|
|
#else
|
|
|
|
PyErr_Format(PyExc_RuntimeError,
|
|
|
|
"Executors are not available in this build");
|
|
|
|
return NULL;
|
|
|
|
#endif
|
2024-03-23 23:32:33 +01:00
|
|
|
}
|
2023-07-20 18:46:04 +02:00
|
|
|
|
2013-11-23 23:49:22 +01:00
|
|
|
static PyMethodDef
|
|
|
|
opcode_functions[] = {
|
|
|
|
_OPCODE_STACK_EFFECT_METHODDEF
|
2023-07-14 19:41:52 +02:00
|
|
|
_OPCODE_IS_VALID_METHODDEF
|
|
|
|
_OPCODE_HAS_ARG_METHODDEF
|
|
|
|
_OPCODE_HAS_CONST_METHODDEF
|
|
|
|
_OPCODE_HAS_NAME_METHODDEF
|
|
|
|
_OPCODE_HAS_JUMP_METHODDEF
|
2023-07-18 20:42:44 +02:00
|
|
|
_OPCODE_HAS_FREE_METHODDEF
|
|
|
|
_OPCODE_HAS_LOCAL_METHODDEF
|
|
|
|
_OPCODE_HAS_EXC_METHODDEF
|
2021-07-29 18:26:53 +02:00
|
|
|
_OPCODE_GET_SPECIALIZATION_STATS_METHODDEF
|
2023-08-17 18:07:58 +02:00
|
|
|
_OPCODE_GET_NB_OPS_METHODDEF
|
2023-07-20 18:46:04 +02:00
|
|
|
_OPCODE_GET_INTRINSIC1_DESCS_METHODDEF
|
|
|
|
_OPCODE_GET_INTRINSIC2_DESCS_METHODDEF
|
2024-03-23 23:32:33 +01:00
|
|
|
_OPCODE_GET_EXECUTOR_METHODDEF
|
2024-06-20 16:07:24 +02:00
|
|
|
_OPCODE_GET_SPECIAL_METHOD_NAMES_METHODDEF
|
2013-11-23 23:49:22 +01:00
|
|
|
{NULL, NULL, 0, NULL}
|
|
|
|
};
|
|
|
|
|
2024-07-11 00:48:37 +02:00
|
|
|
static int
|
2023-08-01 19:05:00 +02:00
|
|
|
_opcode_exec(PyObject *m) {
|
|
|
|
if (PyModule_AddIntMacro(m, ENABLE_SPECIALIZATION) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2024-11-04 20:13:32 +01:00
|
|
|
if (PyModule_AddIntMacro(m, ENABLE_SPECIALIZATION_FT) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2023-08-01 19:05:00 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-05-05 23:11:27 +02:00
|
|
|
static PyModuleDef_Slot module_slots[] = {
|
2023-08-01 19:05:00 +02:00
|
|
|
{Py_mod_exec, _opcode_exec},
|
2023-05-05 23:11:27 +02:00
|
|
|
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
|
2024-05-03 17:30:55 +02:00
|
|
|
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
|
2023-05-05 23:11:27 +02:00
|
|
|
{0, NULL}
|
|
|
|
};
|
|
|
|
|
2013-11-23 23:49:22 +01:00
|
|
|
static struct PyModuleDef opcodemodule = {
|
|
|
|
PyModuleDef_HEAD_INIT,
|
2020-09-07 10:48:44 +02:00
|
|
|
.m_name = "_opcode",
|
|
|
|
.m_doc = "Opcode support module.",
|
|
|
|
.m_size = 0,
|
2023-05-05 23:11:27 +02:00
|
|
|
.m_methods = opcode_functions,
|
|
|
|
.m_slots = module_slots,
|
2013-11-23 23:49:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
PyMODINIT_FUNC
|
|
|
|
PyInit__opcode(void)
|
|
|
|
{
|
2020-09-07 10:48:44 +02:00
|
|
|
return PyModuleDef_Init(&opcodemodule);
|
2013-11-23 23:49:22 +01:00
|
|
|
}
|