Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9c81fc2

Browse files
authored
gh-105481: do not auto-generate pycore_intrinsics.h (#106913)
1 parent214a25d commit9c81fc2

File tree

11 files changed

+174
-91
lines changed

11 files changed

+174
-91
lines changed

‎Include/cpython/compile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,5 @@ PyAPI_FUNC(int) PyUnstable_OpcodeHasFree(int opcode);
7777
PyAPI_FUNC(int)PyUnstable_OpcodeHasLocal(intopcode);
7878
PyAPI_FUNC(int)PyUnstable_OpcodeHasExc(intopcode);
7979

80+
PyAPI_FUNC(PyObject*)_PyUnstable_GetUnaryIntrinsicName(intindex);
81+
PyAPI_FUNC(PyObject*)_PyUnstable_GetBinaryIntrinsicName(intindex);

‎Include/internal/pycore_intrinsics.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Auto-generated by Tools/build/generate_opcode_h.py from Lib/opcode.py
21

32
/* Unary Functions: */
43
#defineINTRINSIC_1_INVALID 0
@@ -26,7 +25,18 @@
2625

2726
#defineMAX_INTRINSIC_2 4
2827

29-
typedefPyObject*(*instrinsic_func1)(PyThreadState*tstate,PyObject*value);
30-
typedefPyObject*(*instrinsic_func2)(PyThreadState*tstate,PyObject*value1,PyObject*value2);
31-
externconstinstrinsic_func1_PyIntrinsics_UnaryFunctions[];
32-
externconstinstrinsic_func2_PyIntrinsics_BinaryFunctions[];
28+
typedefPyObject*(*intrinsic_func1)(PyThreadState*tstate,PyObject*value);
29+
typedefPyObject*(*intrinsic_func2)(PyThreadState*tstate,PyObject*value1,PyObject*value2);
30+
31+
typedefstruct {
32+
intrinsic_func1func;
33+
constchar*name;
34+
}intrinsic_func1_info;
35+
36+
typedefstruct {
37+
intrinsic_func2func;
38+
constchar*name;
39+
}intrinsic_func2_info;
40+
41+
externconstintrinsic_func1_info_PyIntrinsics_UnaryFunctions[];
42+
externconstintrinsic_func2_info_PyIntrinsics_BinaryFunctions[];

‎Lib/opcode.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ def pseudo_op(name, op, real_ops):
257257
__all__.extend(["hasarg","hasconst","hasname","hasjump","hasjrel",
258258
"hasjabs","hasfree","haslocal","hasexc"])
259259

260+
_intrinsic_1_descs=_opcode.get_intrinsic1_descs()
261+
_intrinsic_2_descs=_opcode.get_intrinsic2_descs()
262+
260263
hascompare= [opmap["COMPARE_OP"]]
261264

262265
_nb_ops= [
@@ -288,29 +291,6 @@ def pseudo_op(name, op, real_ops):
288291
("NB_INPLACE_XOR","^="),
289292
]
290293

291-
_intrinsic_1_descs= [
292-
"INTRINSIC_1_INVALID",
293-
"INTRINSIC_PRINT",
294-
"INTRINSIC_IMPORT_STAR",
295-
"INTRINSIC_STOPITERATION_ERROR",
296-
"INTRINSIC_ASYNC_GEN_WRAP",
297-
"INTRINSIC_UNARY_POSITIVE",
298-
"INTRINSIC_LIST_TO_TUPLE",
299-
"INTRINSIC_TYPEVAR",
300-
"INTRINSIC_PARAMSPEC",
301-
"INTRINSIC_TYPEVARTUPLE",
302-
"INTRINSIC_SUBSCRIPT_GENERIC",
303-
"INTRINSIC_TYPEALIAS",
304-
]
305-
306-
_intrinsic_2_descs= [
307-
"INTRINSIC_2_INVALID",
308-
"INTRINSIC_PREP_RERAISE_STAR",
309-
"INTRINSIC_TYPEVAR_WITH_BOUND",
310-
"INTRINSIC_TYPEVAR_WITH_CONSTRAINTS",
311-
"INTRINSIC_SET_FUNCTION_TYPE_PARAMS",
312-
]
313-
314294

315295
_cache_format= {
316296
"LOAD_GLOBAL": {

‎Makefile.pre.in

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,11 +1427,9 @@ regen-opcode:
14271427
$(srcdir)/Lib/opcode.py \
14281428
$(srcdir)/Lib/_opcode_metadata.py \
14291429
$(srcdir)/Include/opcode.h.new \
1430-
$(srcdir)/Include/internal/pycore_opcode.h.new \
1431-
$(srcdir)/Include/internal/pycore_intrinsics.h.new
1430+
$(srcdir)/Include/internal/pycore_opcode.h.new
14321431
$(UPDATE_FILE) $(srcdir)/Include/opcode.h $(srcdir)/Include/opcode.h.new
14331432
$(UPDATE_FILE) $(srcdir)/Include/internal/pycore_opcode.h $(srcdir)/Include/internal/pycore_opcode.h.new
1434-
$(UPDATE_FILE) $(srcdir)/Include/internal/pycore_intrinsics.h $(srcdir)/Include/internal/pycore_intrinsics.h.new
14351433

14361434
.PHONY: regen-token
14371435
regen-token:

‎Modules/_opcode.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include"compile.h"
33
#include"opcode.h"
44
#include"internal/pycore_code.h"
5+
#include"internal/pycore_intrinsics.h"
56

67
/*[clinic input]
78
module _opcode
@@ -220,6 +221,60 @@ _opcode_get_specialization_stats_impl(PyObject *module)
220221
#endif
221222
}
222223

224+
/*[clinic input]
225+
226+
_opcode.get_intrinsic1_descs
227+
228+
Return a list of names of the unary intrinsics.
229+
[clinic start generated code]*/
230+
231+
staticPyObject*
232+
_opcode_get_intrinsic1_descs_impl(PyObject*module)
233+
/*[clinic end generated code: output=bd1ddb6b4447d18b input=13b51c712618459b]*/
234+
{
235+
PyObject*list=PyList_New(MAX_INTRINSIC_1+1);
236+
if (list==NULL) {
237+
returnNULL;
238+
}
239+
for (inti=0;i <=MAX_INTRINSIC_1;i++) {
240+
PyObject*name=_PyUnstable_GetUnaryIntrinsicName(i);
241+
if (name==NULL) {
242+
Py_DECREF(list);
243+
returnNULL;
244+
}
245+
PyList_SET_ITEM(list,i,name);
246+
}
247+
returnlist;
248+
}
249+
250+
251+
/*[clinic input]
252+
253+
_opcode.get_intrinsic2_descs
254+
255+
Return a list of names of the binary intrinsics.
256+
[clinic start generated code]*/
257+
258+
staticPyObject*
259+
_opcode_get_intrinsic2_descs_impl(PyObject*module)
260+
/*[clinic end generated code: output=40e62bc27584c8a0 input=e83068f249f5471b]*/
261+
{
262+
PyObject*list=PyList_New(MAX_INTRINSIC_2+1);
263+
if (list==NULL) {
264+
returnNULL;
265+
}
266+
for (inti=0;i <=MAX_INTRINSIC_2;i++) {
267+
PyObject*name=_PyUnstable_GetBinaryIntrinsicName(i);
268+
if (name==NULL) {
269+
Py_DECREF(list);
270+
returnNULL;
271+
}
272+
PyList_SET_ITEM(list,i,name);
273+
}
274+
returnlist;
275+
}
276+
277+
223278
staticPyMethodDef
224279
opcode_functions[]= {
225280
_OPCODE_STACK_EFFECT_METHODDEF
@@ -232,6 +287,8 @@ opcode_functions[] = {
232287
_OPCODE_HAS_LOCAL_METHODDEF
233288
_OPCODE_HAS_EXC_METHODDEF
234289
_OPCODE_GET_SPECIALIZATION_STATS_METHODDEF
290+
_OPCODE_GET_INTRINSIC1_DESCS_METHODDEF
291+
_OPCODE_GET_INTRINSIC2_DESCS_METHODDEF
235292
{NULL,NULL,0,NULL}
236293
};
237294

‎Modules/clinic/_opcode.c.h

Lines changed: 37 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎Python/bytecodes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,14 +698,14 @@ dummy_func(
698698

699699
inst(CALL_INTRINSIC_1, (value--res)) {
700700
assert(oparg <=MAX_INTRINSIC_1);
701-
res=_PyIntrinsics_UnaryFunctions[oparg](tstate,value);
701+
res=_PyIntrinsics_UnaryFunctions[oparg].func(tstate,value);
702702
DECREF_INPUTS();
703703
ERROR_IF(res==NULL,error);
704704
}
705705

706706
inst(CALL_INTRINSIC_2, (value2,value1--res)) {
707707
assert(oparg <=MAX_INTRINSIC_2);
708-
res=_PyIntrinsics_BinaryFunctions[oparg](tstate,value2,value1);
708+
res=_PyIntrinsics_BinaryFunctions[oparg].func(tstate,value2,value1);
709709
DECREF_INPUTS();
710710
ERROR_IF(res==NULL,error);
711711
}

‎Python/executor_cases.c.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎Python/generated_cases.c.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎Python/intrinsics.c

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/******** Unary functions ********/
1515

1616
staticPyObject*
17-
no_intrinsic(PyThreadState*tstate,PyObject*unused)
17+
no_intrinsic1(PyThreadState*tstate,PyObject*unused)
1818
{
1919
_PyErr_SetString(tstate,PyExc_SystemError,"invalid intrinsic function");
2020
returnNULL;
@@ -203,25 +203,35 @@ make_typevar(PyThreadState* Py_UNUSED(ignored), PyObject *v)
203203
return_Py_make_typevar(v,NULL,NULL);
204204
}
205205

206-
constinstrinsic_func1
206+
207+
#defineINTRINSIC_FUNC_ENTRY(N,F) \
208+
[N] = {F, #N},
209+
210+
constintrinsic_func1_info
207211
_PyIntrinsics_UnaryFunctions[]= {
208-
[0]=no_intrinsic,
209-
[INTRINSIC_PRINT]=print_expr,
210-
[INTRINSIC_IMPORT_STAR]=import_star,
211-
[INTRINSIC_STOPITERATION_ERROR]=stopiteration_error,
212-
[INTRINSIC_ASYNC_GEN_WRAP]=_PyAsyncGenValueWrapperNew,
213-
[INTRINSIC_UNARY_POSITIVE]=unary_pos,
214-
[INTRINSIC_LIST_TO_TUPLE]=list_to_tuple,
215-
[INTRINSIC_TYPEVAR]=make_typevar,
216-
[INTRINSIC_PARAMSPEC]=_Py_make_paramspec,
217-
[INTRINSIC_TYPEVARTUPLE]=_Py_make_typevartuple,
218-
[INTRINSIC_SUBSCRIPT_GENERIC]=_Py_subscript_generic,
219-
[INTRINSIC_TYPEALIAS]=_Py_make_typealias,
212+
INTRINSIC_FUNC_ENTRY(INTRINSIC_1_INVALID,no_intrinsic1)
213+
INTRINSIC_FUNC_ENTRY(INTRINSIC_PRINT,print_expr)
214+
INTRINSIC_FUNC_ENTRY(INTRINSIC_IMPORT_STAR,import_star)
215+
INTRINSIC_FUNC_ENTRY(INTRINSIC_STOPITERATION_ERROR,stopiteration_error)
216+
INTRINSIC_FUNC_ENTRY(INTRINSIC_ASYNC_GEN_WRAP,_PyAsyncGenValueWrapperNew)
217+
INTRINSIC_FUNC_ENTRY(INTRINSIC_UNARY_POSITIVE,unary_pos)
218+
INTRINSIC_FUNC_ENTRY(INTRINSIC_LIST_TO_TUPLE,list_to_tuple)
219+
INTRINSIC_FUNC_ENTRY(INTRINSIC_TYPEVAR,make_typevar)
220+
INTRINSIC_FUNC_ENTRY(INTRINSIC_PARAMSPEC,_Py_make_paramspec)
221+
INTRINSIC_FUNC_ENTRY(INTRINSIC_TYPEVARTUPLE,_Py_make_typevartuple)
222+
INTRINSIC_FUNC_ENTRY(INTRINSIC_SUBSCRIPT_GENERIC,_Py_subscript_generic)
223+
INTRINSIC_FUNC_ENTRY(INTRINSIC_TYPEALIAS,_Py_make_typealias)
220224
};
221225

222226

223227
/******** Binary functions ********/
224228

229+
staticPyObject*
230+
no_intrinsic2(PyThreadState*tstate,PyObject*unused1,PyObject*unused2)
231+
{
232+
_PyErr_SetString(tstate,PyExc_SystemError,"invalid intrinsic function");
233+
returnNULL;
234+
}
225235

226236
staticPyObject*
227237
prep_reraise_star(PyThreadState*unused,PyObject*orig,PyObject*excs)
@@ -246,10 +256,31 @@ make_typevar_with_constraints(PyThreadState* Py_UNUSED(ignored), PyObject *name,
246256
return_Py_make_typevar(name,NULL,evaluate_constraints);
247257
}
248258

249-
constinstrinsic_func2
259+
constintrinsic_func2_info
250260
_PyIntrinsics_BinaryFunctions[]= {
251-
[INTRINSIC_PREP_RERAISE_STAR]=prep_reraise_star,
252-
[INTRINSIC_TYPEVAR_WITH_BOUND]=make_typevar_with_bound,
253-
[INTRINSIC_TYPEVAR_WITH_CONSTRAINTS]=make_typevar_with_constraints,
254-
[INTRINSIC_SET_FUNCTION_TYPE_PARAMS]=_Py_set_function_type_params,
261+
INTRINSIC_FUNC_ENTRY(INTRINSIC_2_INVALID,no_intrinsic2)
262+
INTRINSIC_FUNC_ENTRY(INTRINSIC_PREP_RERAISE_STAR,prep_reraise_star)
263+
INTRINSIC_FUNC_ENTRY(INTRINSIC_TYPEVAR_WITH_BOUND,make_typevar_with_bound)
264+
INTRINSIC_FUNC_ENTRY(INTRINSIC_TYPEVAR_WITH_CONSTRAINTS,make_typevar_with_constraints)
265+
INTRINSIC_FUNC_ENTRY(INTRINSIC_SET_FUNCTION_TYPE_PARAMS,_Py_set_function_type_params)
255266
};
267+
268+
#undef INTRINSIC_FUNC_ENTRY
269+
270+
PyObject*
271+
_PyUnstable_GetUnaryIntrinsicName(intindex)
272+
{
273+
if (index<0||index>MAX_INTRINSIC_1) {
274+
returnNULL;
275+
}
276+
returnPyUnicode_FromString(_PyIntrinsics_UnaryFunctions[index].name);
277+
}
278+
279+
PyObject*
280+
_PyUnstable_GetBinaryIntrinsicName(intindex)
281+
{
282+
if (index<0||index>MAX_INTRINSIC_2) {
283+
returnNULL;
284+
}
285+
returnPyUnicode_FromString(_PyIntrinsics_BinaryFunctions[index].name);
286+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp