gh-107149: make new opcode util functions private rather than public and unstable (#112042)

This commit is contained in:
Irit Katriel 2023-11-14 00:31:02 +00:00 committed by GitHub
parent b28bb130bb
commit 36aab34fab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 39 deletions

View file

@ -68,15 +68,3 @@ typedef struct {
#define PY_INVALID_STACK_EFFECT INT_MAX
PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg);
PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump);
PyAPI_FUNC(int) PyUnstable_OpcodeIsValid(int opcode);
PyAPI_FUNC(int) PyUnstable_OpcodeHasArg(int opcode);
PyAPI_FUNC(int) PyUnstable_OpcodeHasConst(int opcode);
PyAPI_FUNC(int) PyUnstable_OpcodeHasName(int opcode);
PyAPI_FUNC(int) PyUnstable_OpcodeHasJump(int opcode);
PyAPI_FUNC(int) PyUnstable_OpcodeHasFree(int opcode);
PyAPI_FUNC(int) PyUnstable_OpcodeHasLocal(int opcode);
PyAPI_FUNC(int) PyUnstable_OpcodeHasExc(int opcode);
PyAPI_FUNC(PyObject*) PyUnstable_GetUnaryIntrinsicName(int index);
PyAPI_FUNC(PyObject*) PyUnstable_GetBinaryIntrinsicName(int index);

View file

@ -102,6 +102,20 @@ int _PyCompile_EnsureArrayLargeEnough(
int _PyCompile_ConstCacheMergeOne(PyObject *const_cache, PyObject **obj);
// Export for '_opcode' extention module
PyAPI_FUNC(int) _PyCompile_OpcodeIsValid(int opcode);
PyAPI_FUNC(int) _PyCompile_OpcodeHasArg(int opcode);
PyAPI_FUNC(int) _PyCompile_OpcodeHasConst(int opcode);
PyAPI_FUNC(int) _PyCompile_OpcodeHasName(int opcode);
PyAPI_FUNC(int) _PyCompile_OpcodeHasJump(int opcode);
PyAPI_FUNC(int) _PyCompile_OpcodeHasFree(int opcode);
PyAPI_FUNC(int) _PyCompile_OpcodeHasLocal(int opcode);
PyAPI_FUNC(int) _PyCompile_OpcodeHasExc(int opcode);
PyAPI_FUNC(PyObject*) _PyCompile_GetUnaryIntrinsicName(int index);
PyAPI_FUNC(PyObject*) _PyCompile_GetBinaryIntrinsicName(int index);
/* Access compiler internals for unit testing */
// Export for '_testinternalcapi' shared extension

View file

@ -6,6 +6,7 @@
#include "compile.h"
#include "opcode.h"
#include "internal/pycore_code.h"
#include "internal/pycore_compile.h"
#include "internal/pycore_intrinsics.h"
/*[clinic input]
@ -78,7 +79,7 @@ static int
_opcode_is_valid_impl(PyObject *module, int opcode)
/*[clinic end generated code: output=b0d918ea1d073f65 input=fe23e0aa194ddae0]*/
{
return PyUnstable_OpcodeIsValid(opcode);
return _PyCompile_OpcodeIsValid(opcode);
}
/*[clinic input]
@ -94,8 +95,8 @@ static int
_opcode_has_arg_impl(PyObject *module, int opcode)
/*[clinic end generated code: output=7a062d3b2dcc0815 input=93d878ba6361db5f]*/
{
return PyUnstable_OpcodeIsValid(opcode) &&
PyUnstable_OpcodeHasArg(opcode);
return _PyCompile_OpcodeIsValid(opcode) &&
_PyCompile_OpcodeHasArg(opcode);
}
/*[clinic input]
@ -111,8 +112,8 @@ static int
_opcode_has_const_impl(PyObject *module, int opcode)
/*[clinic end generated code: output=c646d5027c634120 input=a6999e4cf13f9410]*/
{
return PyUnstable_OpcodeIsValid(opcode) &&
PyUnstable_OpcodeHasConst(opcode);
return _PyCompile_OpcodeIsValid(opcode) &&
_PyCompile_OpcodeHasConst(opcode);
}
/*[clinic input]
@ -128,8 +129,8 @@ static int
_opcode_has_name_impl(PyObject *module, int opcode)
/*[clinic end generated code: output=b49a83555c2fa517 input=448aa5e4bcc947ba]*/
{
return PyUnstable_OpcodeIsValid(opcode) &&
PyUnstable_OpcodeHasName(opcode);
return _PyCompile_OpcodeIsValid(opcode) &&
_PyCompile_OpcodeHasName(opcode);
}
/*[clinic input]
@ -145,8 +146,8 @@ static int
_opcode_has_jump_impl(PyObject *module, int opcode)
/*[clinic end generated code: output=e9c583c669f1c46a input=35f711274357a0c3]*/
{
return PyUnstable_OpcodeIsValid(opcode) &&
PyUnstable_OpcodeHasJump(opcode);
return _PyCompile_OpcodeIsValid(opcode) &&
_PyCompile_OpcodeHasJump(opcode);
}
@ -168,8 +169,8 @@ static int
_opcode_has_free_impl(PyObject *module, int opcode)
/*[clinic end generated code: output=d81ae4d79af0ee26 input=117dcd5c19c1139b]*/
{
return PyUnstable_OpcodeIsValid(opcode) &&
PyUnstable_OpcodeHasFree(opcode);
return _PyCompile_OpcodeIsValid(opcode) &&
_PyCompile_OpcodeHasFree(opcode);
}
@ -186,8 +187,8 @@ static int
_opcode_has_local_impl(PyObject *module, int opcode)
/*[clinic end generated code: output=da5a8616b7a5097b input=9a798ee24aaef49d]*/
{
return PyUnstable_OpcodeIsValid(opcode) &&
PyUnstable_OpcodeHasLocal(opcode);
return _PyCompile_OpcodeIsValid(opcode) &&
_PyCompile_OpcodeHasLocal(opcode);
}
/*[clinic input]
@ -203,8 +204,8 @@ static int
_opcode_has_exc_impl(PyObject *module, int opcode)
/*[clinic end generated code: output=41b68dff0ec82a52 input=db0e4bdb9bf13fa5]*/
{
return PyUnstable_OpcodeIsValid(opcode) &&
PyUnstable_OpcodeHasExc(opcode);
return _PyCompile_OpcodeIsValid(opcode) &&
_PyCompile_OpcodeHasExc(opcode);
}
/*[clinic input]
@ -309,7 +310,7 @@ _opcode_get_intrinsic1_descs_impl(PyObject *module)
return NULL;
}
for (int i=0; i <= MAX_INTRINSIC_1; i++) {
PyObject *name = PyUnstable_GetUnaryIntrinsicName(i);
PyObject *name = _PyCompile_GetUnaryIntrinsicName(i);
if (name == NULL) {
Py_DECREF(list);
return NULL;
@ -336,7 +337,7 @@ _opcode_get_intrinsic2_descs_impl(PyObject *module)
return NULL;
}
for (int i=0; i <= MAX_INTRINSIC_2; i++) {
PyObject *name = PyUnstable_GetBinaryIntrinsicName(i);
PyObject *name = _PyCompile_GetBinaryIntrinsicName(i);
if (name == NULL) {
Py_DECREF(list);
return NULL;

View file

@ -883,49 +883,49 @@ PyCompile_OpcodeStackEffect(int opcode, int oparg)
}
int
PyUnstable_OpcodeIsValid(int opcode)
_PyCompile_OpcodeIsValid(int opcode)
{
return IS_VALID_OPCODE(opcode);
}
int
PyUnstable_OpcodeHasArg(int opcode)
_PyCompile_OpcodeHasArg(int opcode)
{
return OPCODE_HAS_ARG(opcode);
}
int
PyUnstable_OpcodeHasConst(int opcode)
_PyCompile_OpcodeHasConst(int opcode)
{
return OPCODE_HAS_CONST(opcode);
}
int
PyUnstable_OpcodeHasName(int opcode)
_PyCompile_OpcodeHasName(int opcode)
{
return OPCODE_HAS_NAME(opcode);
}
int
PyUnstable_OpcodeHasJump(int opcode)
_PyCompile_OpcodeHasJump(int opcode)
{
return OPCODE_HAS_JUMP(opcode);
}
int
PyUnstable_OpcodeHasFree(int opcode)
_PyCompile_OpcodeHasFree(int opcode)
{
return OPCODE_HAS_FREE(opcode);
}
int
PyUnstable_OpcodeHasLocal(int opcode)
_PyCompile_OpcodeHasLocal(int opcode)
{
return OPCODE_HAS_LOCAL(opcode);
}
int
PyUnstable_OpcodeHasExc(int opcode)
_PyCompile_OpcodeHasExc(int opcode)
{
return IS_BLOCK_PUSH_OPCODE(opcode);
}

View file

@ -5,6 +5,7 @@
#include "pycore_frame.h"
#include "pycore_function.h"
#include "pycore_global_objects.h"
#include "pycore_compile.h" // _PyCompile_GetUnaryIntrinsicName, etc
#include "pycore_intrinsics.h" // INTRINSIC_PRINT
#include "pycore_pyerrors.h" // _PyErr_SetString()
#include "pycore_runtime.h" // _Py_ID()
@ -269,7 +270,7 @@ _PyIntrinsics_BinaryFunctions[] = {
#undef INTRINSIC_FUNC_ENTRY
PyObject*
PyUnstable_GetUnaryIntrinsicName(int index)
_PyCompile_GetUnaryIntrinsicName(int index)
{
if (index < 0 || index > MAX_INTRINSIC_1) {
return NULL;
@ -278,7 +279,7 @@ PyUnstable_GetUnaryIntrinsicName(int index)
}
PyObject*
PyUnstable_GetBinaryIntrinsicName(int index)
_PyCompile_GetBinaryIntrinsicName(int index)
{
if (index < 0 || index > MAX_INTRINSIC_2) {
return NULL;