Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f0df35e

Browse files
authored
GH-115802: JIT "small" code for Windows (GH-115964)
1 parent 45d8871 commit f0df35e

26 files changed

+126
-93
lines changed

Include/cpython/optimizer.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ PyAPI_FUNC(_PyOptimizerObject *) PyUnstable_GetOptimizer(void);
9292

9393
PyAPI_FUNC(_PyExecutorObject *) PyUnstable_GetExecutor(PyCodeObject *code, int offset);
9494

95-
int
96-
_PyOptimizer_Optimize(struct _PyInterpreterFrame *frame, _Py_CODEUNIT *start, PyObject **stack_pointer, _PyExecutorObject **exec_ptr);
97-
9895
void _Py_ExecutorInit(_PyExecutorObject *, const _PyBloomFilter *);
9996
void _Py_ExecutorClear(_PyExecutorObject *);
10097
void _Py_BloomFilter_Init(_PyBloomFilter *);

Include/internal/pycore_ceval.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,22 +181,26 @@ extern PyObject* _Py_MakeCoro(PyFunctionObject *func);
181181

182182
/* Handle signals, pending calls, GIL drop request
183183
and asynchronous exception */
184-
extern int _Py_HandlePending(PyThreadState *tstate);
184+
PyAPI_FUNC(int) _Py_HandlePending(PyThreadState *tstate);
185185

186186
extern PyObject * _PyEval_GetFrameLocals(void);
187187

188-
extern const binaryfunc _PyEval_BinaryOps[];
189-
int _PyEval_CheckExceptStarTypeValid(PyThreadState *tstate, PyObject* right);
190-
int _PyEval_CheckExceptTypeValid(PyThreadState *tstate, PyObject* right);
191-
int _PyEval_ExceptionGroupMatch(PyObject* exc_value, PyObject *match_type, PyObject **match, PyObject **rest);
192-
void _PyEval_FormatAwaitableError(PyThreadState *tstate, PyTypeObject *type, int oparg);
193-
void _PyEval_FormatExcCheckArg(PyThreadState *tstate, PyObject *exc, const char *format_str, PyObject *obj);
194-
void _PyEval_FormatExcUnbound(PyThreadState *tstate, PyCodeObject *co, int oparg);
195-
void _PyEval_FormatKwargsError(PyThreadState *tstate, PyObject *func, PyObject *kwargs);
196-
PyObject *_PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type, Py_ssize_t nargs, PyObject *kwargs);
197-
PyObject *_PyEval_MatchKeys(PyThreadState *tstate, PyObject *map, PyObject *keys);
198-
int _PyEval_UnpackIterable(PyThreadState *tstate, PyObject *v, int argcnt, int argcntafter, PyObject **sp);
199-
void _PyEval_FrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame *frame);
188+
typedef PyObject *(*conversion_func)(PyObject *);
189+
190+
PyAPI_DATA(const binaryfunc) _PyEval_BinaryOps[];
191+
PyAPI_DATA(const conversion_func) _PyEval_ConversionFuncs[];
192+
193+
PyAPI_FUNC(int) _PyEval_CheckExceptStarTypeValid(PyThreadState *tstate, PyObject* right);
194+
PyAPI_FUNC(int) _PyEval_CheckExceptTypeValid(PyThreadState *tstate, PyObject* right);
195+
PyAPI_FUNC(int) _PyEval_ExceptionGroupMatch(PyObject* exc_value, PyObject *match_type, PyObject **match, PyObject **rest);
196+
PyAPI_FUNC(void) _PyEval_FormatAwaitableError(PyThreadState *tstate, PyTypeObject *type, int oparg);
197+
PyAPI_FUNC(void) _PyEval_FormatExcCheckArg(PyThreadState *tstate, PyObject *exc, const char *format_str, PyObject *obj);
198+
PyAPI_FUNC(void) _PyEval_FormatExcUnbound(PyThreadState *tstate, PyCodeObject *co, int oparg);
199+
PyAPI_FUNC(void) _PyEval_FormatKwargsError(PyThreadState *tstate, PyObject *func, PyObject *kwargs);
200+
PyAPI_FUNC(PyObject *)_PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type, Py_ssize_t nargs, PyObject *kwargs);
201+
PyAPI_FUNC(PyObject *)_PyEval_MatchKeys(PyThreadState *tstate, PyObject *map, PyObject *keys);
202+
PyAPI_FUNC(int) _PyEval_UnpackIterable(PyThreadState *tstate, PyObject *v, int argcnt, int argcntafter, PyObject **sp);
203+
PyAPI_FUNC(void) _PyEval_FrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame *frame);
200204

201205

202206
/* Bits that can be set in PyThreadState.eval_breaker */

Include/internal/pycore_dict.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ PyAPI_FUNC(Py_ssize_t) _PyDict_SizeOf(PyDictObject *);
5252
of a key wins, if override is 2, a KeyError with conflicting key as
5353
argument is raised.
5454
*/
55-
extern int _PyDict_MergeEx(PyObject *mp, PyObject *other, int override);
55+
PyAPI_FUNC(int) _PyDict_MergeEx(PyObject *mp, PyObject *other, int override);
5656

5757
extern void _PyDict_DebugMallocStats(FILE *out);
5858

@@ -100,10 +100,10 @@ extern Py_ssize_t _Py_dict_lookup(PyDictObject *mp, PyObject *key, Py_hash_t has
100100

101101
extern Py_ssize_t _PyDict_LookupIndex(PyDictObject *, PyObject *);
102102
extern Py_ssize_t _PyDictKeys_StringLookup(PyDictKeysObject* dictkeys, PyObject *key);
103-
extern PyObject *_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *);
103+
PyAPI_FUNC(PyObject *)_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *);
104104

105105
/* Consumes references to key and value */
106-
extern int _PyDict_SetItem_Take2(PyDictObject *op, PyObject *key, PyObject *value);
106+
PyAPI_FUNC(int) _PyDict_SetItem_Take2(PyDictObject *op, PyObject *key, PyObject *value);
107107
extern int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name, PyObject *value);
108108

109109
extern int _PyDict_Pop_KnownHash(
@@ -247,8 +247,8 @@ _PyDict_NotifyEvent(PyInterpreterState *interp,
247247
}
248248

249249
extern PyObject *_PyObject_MakeDictFromInstanceAttributes(PyObject *obj, PyDictValues *values);
250-
extern bool _PyObject_MakeInstanceAttributesFromDict(PyObject *obj, PyDictOrValues *dorv);
251-
extern PyObject *_PyDict_FromItems(
250+
PyAPI_FUNC(bool) _PyObject_MakeInstanceAttributesFromDict(PyObject *obj, PyDictOrValues *dorv);
251+
PyAPI_FUNC(PyObject *)_PyDict_FromItems(
252252
PyObject *const *keys, Py_ssize_t keys_offset,
253253
PyObject *const *values, Py_ssize_t values_offset,
254254
Py_ssize_t length);

Include/internal/pycore_floatobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct _Py_float_runtime_state {
3434

3535

3636

37-
void _PyFloat_ExactDealloc(PyObject *op);
37+
PyAPI_FUNC(void) _PyFloat_ExactDealloc(PyObject *op);
3838

3939

4040
extern void _PyFloat_DebugMallocStats(FILE* out);

Include/internal/pycore_function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct _py_func_state {
2929
extern PyFunctionObject* _PyFunction_FromConstructor(PyFrameConstructor *constr);
3030

3131
extern uint32_t _PyFunction_GetVersionForCurrentState(PyFunctionObject *func);
32-
extern void _PyFunction_SetVersion(PyFunctionObject *func, uint32_t version);
32+
PyAPI_FUNC(void) _PyFunction_SetVersion(PyFunctionObject *func, uint32_t version);
3333
PyFunctionObject *_PyFunction_LookupByVersion(uint32_t version);
3434

3535
extern PyObject *_Py_set_function_type_params(

Include/internal/pycore_genobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern "C" {
1010

1111
#include "pycore_freelist.h"
1212

13-
extern PyObject *_PyGen_yf(PyGenObject *);
13+
PyAPI_FUNC(PyObject *)_PyGen_yf(PyGenObject *);
1414
extern void _PyGen_Finalize(PyObject *self);
1515

1616
// Export for '_asyncio' shared extension
@@ -19,7 +19,7 @@ PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);
1919
// Export for '_asyncio' shared extension
2020
PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
2121

22-
extern PyObject *_PyCoro_GetAwaitableIter(PyObject *o);
22+
PyAPI_FUNC(PyObject *)_PyCoro_GetAwaitableIter(PyObject *o);
2323
extern PyObject *_PyAsyncGenValueWrapperNew(PyThreadState *state, PyObject *);
2424

2525
extern PyTypeObject _PyCoroWrapper_Type;

Include/internal/pycore_intrinsics.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ typedef struct {
4444
const char *name;
4545
} intrinsic_func2_info;
4646

47-
extern const intrinsic_func1_info _PyIntrinsics_UnaryFunctions[];
48-
extern const intrinsic_func2_info _PyIntrinsics_BinaryFunctions[];
47+
PyAPI_DATA(const intrinsic_func1_info) _PyIntrinsics_UnaryFunctions[];
48+
PyAPI_DATA(const intrinsic_func2_info) _PyIntrinsics_BinaryFunctions[];
4949

5050
#endif // !Py_INTERNAL_INTRINSIC_H

Include/internal/pycore_list.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ extern "C" {
1010

1111
#include "pycore_freelist.h" // _PyFreeListState
1212

13-
extern PyObject* _PyList_Extend(PyListObject *, PyObject *);
13+
PyAPI_FUNC(PyObject*) _PyList_Extend(PyListObject *, PyObject *);
1414
extern void _PyList_DebugMallocStats(FILE *out);
1515

1616
#define _PyList_ITEMS(op) _Py_RVALUE(_PyList_CAST(op)->ob_item)
1717

18-
extern int
18+
PyAPI_FUNC(int)
1919
_PyList_AppendTakeRefListResize(PyListObject *self, PyObject *newitem);
2020

2121
// In free-threaded build: self should be locked by the caller, if it should be thread-safe.
@@ -54,7 +54,7 @@ typedef struct {
5454
PyListObject *it_seq; /* Set to NULL when iterator is exhausted */
5555
} _PyListIterObject;
5656

57-
extern PyObject *_PyList_FromArraySteal(PyObject *const *src, Py_ssize_t n);
57+
PyAPI_FUNC(PyObject *)_PyList_FromArraySteal(PyObject *const *src, Py_ssize_t n);
5858

5959
#ifdef __cplusplus
6060
}

Include/internal/pycore_long.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ PyAPI_DATA(PyObject*) _PyLong_Rshift(PyObject *, size_t);
121121
// Export for 'math' shared extension
122122
PyAPI_DATA(PyObject*) _PyLong_Lshift(PyObject *, size_t);
123123

124-
extern PyObject* _PyLong_Add(PyLongObject *left, PyLongObject *right);
125-
extern PyObject* _PyLong_Multiply(PyLongObject *left, PyLongObject *right);
126-
extern PyObject* _PyLong_Subtract(PyLongObject *left, PyLongObject *right);
124+
PyAPI_FUNC(PyObject*) _PyLong_Add(PyLongObject *left, PyLongObject *right);
125+
PyAPI_FUNC(PyObject*) _PyLong_Multiply(PyLongObject *left, PyLongObject *right);
126+
PyAPI_FUNC(PyObject*) _PyLong_Subtract(PyLongObject *left, PyLongObject *right);
127127

128128
// Export for 'binascii' shared extension.
129129
PyAPI_DATA(unsigned char) _PyLong_DigitValue[256];

Include/internal/pycore_object.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
7373
.ob_size = size \
7474
}
7575

76-
extern void _Py_NO_RETURN _Py_FatalRefcountErrorFunc(
76+
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalRefcountErrorFunc(
7777
const char *func,
7878
const char *message);
7979

@@ -684,7 +684,7 @@ PyAPI_FUNC(PyObject*) _PyObject_LookupSpecial(PyObject *, PyObject *);
684684

685685
extern int _PyObject_IsAbstract(PyObject *);
686686

687-
extern int _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);
687+
PyAPI_FUNC(int) _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);
688688
extern PyObject* _PyObject_NextNotImplemented(PyObject *);
689689

690690
// Pickle support.

Include/internal/pycore_optimizer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ extern int _Py_uop_frame_pop(_Py_UOpsContext *ctx);
111111

112112
PyAPI_FUNC(PyObject *) _Py_uop_symbols_test(PyObject *self, PyObject *ignored);
113113

114+
PyAPI_FUNC(int) _PyOptimizer_Optimize(_PyInterpreterFrame *frame, _Py_CODEUNIT *start, PyObject **stack_pointer, _PyExecutorObject **exec_ptr);
115+
114116
#ifdef __cplusplus
115117
}
116118
#endif

Include/internal/pycore_pyerrors.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ extern void _PyErr_Fetch(
9595

9696
extern PyObject* _PyErr_GetRaisedException(PyThreadState *tstate);
9797

98-
extern int _PyErr_ExceptionMatches(
98+
PyAPI_FUNC(int) _PyErr_ExceptionMatches(
9999
PyThreadState *tstate,
100100
PyObject *exc);
101101

@@ -114,18 +114,18 @@ extern void _PyErr_SetObject(
114114

115115
extern void _PyErr_ChainStackItem(void);
116116

117-
extern void _PyErr_Clear(PyThreadState *tstate);
117+
PyAPI_FUNC(void) _PyErr_Clear(PyThreadState *tstate);
118118

119119
extern void _PyErr_SetNone(PyThreadState *tstate, PyObject *exception);
120120

121121
extern PyObject* _PyErr_NoMemory(PyThreadState *tstate);
122122

123-
extern void _PyErr_SetString(
123+
PyAPI_FUNC(void) _PyErr_SetString(
124124
PyThreadState *tstate,
125125
PyObject *exception,
126126
const char *string);
127127

128-
extern PyObject* _PyErr_Format(
128+
PyAPI_FUNC(PyObject*) _PyErr_Format(
129129
PyThreadState *tstate,
130130
PyObject *exception,
131131
const char *format,

Include/internal/pycore_sliceobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern "C" {
1111

1212
/* runtime lifecycle */
1313

14-
extern PyObject *
14+
PyAPI_FUNC(PyObject *)
1515
_PyBuildSlice_ConsumeRefs(PyObject *start, PyObject *stop);
1616

1717
#ifdef __cplusplus

Include/internal/pycore_tuple.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern PyStatus _PyTuple_InitGlobalObjects(PyInterpreterState *);
2121
#define _PyTuple_ITEMS(op) _Py_RVALUE(_PyTuple_CAST(op)->ob_item)
2222

2323
extern PyObject *_PyTuple_FromArray(PyObject *const *, Py_ssize_t);
24-
extern PyObject *_PyTuple_FromArraySteal(PyObject *const *, Py_ssize_t);
24+
PyAPI_FUNC(PyObject *)_PyTuple_FromArraySteal(PyObject *const *, Py_ssize_t);
2525

2626
typedef struct {
2727
PyObject_HEAD

Include/internal/pycore_typeobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ extern PyObject* _Py_slot_tp_getattr_hook(PyObject *self, PyObject *name);
147147

148148
extern PyTypeObject _PyBufferWrapper_Type;
149149

150-
extern PyObject* _PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj,
150+
PyAPI_FUNC(PyObject*) _PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj,
151151
PyObject *name, int *meth_found);
152152

153153

Include/internal/pycore_unicodeobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
3131
PyObject *op,
3232
int check_content);
3333

34-
extern void _PyUnicode_ExactDealloc(PyObject *op);
34+
PyAPI_FUNC(void) _PyUnicode_ExactDealloc(PyObject *op);
3535
extern Py_ssize_t _PyUnicode_InternedSize(void);
3636

3737
// Get a copy of a Unicode string.
@@ -202,7 +202,7 @@ PyAPI_FUNC(PyObject*) _PyUnicode_TransformDecimalAndSpaceToASCII(
202202

203203
/* --- Methods & Slots ---------------------------------------------------- */
204204

205-
extern PyObject* _PyUnicode_JoinArray(
205+
PyAPI_FUNC(PyObject*) _PyUnicode_JoinArray(
206206
PyObject *separator,
207207
PyObject *const *items,
208208
Py_ssize_t seqlen

Python/bytecodes.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,7 +2755,7 @@ dummy_func(
27552755
GOTO_ERROR(error);
27562756
}
27572757
DECREF_INPUTS();
2758-
res = _PyObject_CallNoArgsTstate(tstate, enter);
2758+
res = PyObject_CallNoArgs(enter);
27592759
Py_DECREF(enter);
27602760
if (res == NULL) {
27612761
Py_DECREF(exit);
@@ -2790,7 +2790,7 @@ dummy_func(
27902790
GOTO_ERROR(error);
27912791
}
27922792
DECREF_INPUTS();
2793-
res = _PyObject_CallNoArgsTstate(tstate, enter);
2793+
res = PyObject_CallNoArgs(enter);
27942794
Py_DECREF(enter);
27952795
if (res == NULL) {
27962796
Py_DECREF(exit);
@@ -3822,9 +3822,9 @@ dummy_func(
38223822
}
38233823

38243824
inst(CONVERT_VALUE, (value -- result)) {
3825-
convertion_func_ptr conv_fn;
3825+
conversion_func conv_fn;
38263826
assert(oparg >= FVC_STR && oparg <= FVC_ASCII);
3827-
conv_fn = CONVERSION_FUNCTIONS[oparg];
3827+
conv_fn = _PyEval_ConversionFuncs[oparg];
38283828
result = conv_fn(value);
38293829
Py_DECREF(value);
38303830
ERROR_IF(result == NULL, error);

Python/ceval.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,12 @@ const binaryfunc _PyEval_BinaryOps[] = {
337337
[NB_INPLACE_XOR] = PyNumber_InPlaceXor,
338338
};
339339

340+
const conversion_func _PyEval_ConversionFuncs[4] = {
341+
[FVC_STR] = PyObject_Str,
342+
[FVC_REPR] = PyObject_Repr,
343+
[FVC_ASCII] = PyObject_ASCII
344+
};
345+
340346

341347
// PEP 634: Structural Pattern Matching
342348

Python/ceval_macros.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,6 @@ do { \
352352
} \
353353
} while (0);
354354

355-
typedef PyObject *(*convertion_func_ptr)(PyObject *);
356-
357-
static const convertion_func_ptr CONVERSION_FUNCTIONS[4] = {
358-
[FVC_STR] = PyObject_Str,
359-
[FVC_REPR] = PyObject_Repr,
360-
[FVC_ASCII] = PyObject_ASCII
361-
};
362355

363356
// GH-89279: Force inlining by using a macro.
364357
#if defined(_MSC_VER) && SIZEOF_INT == 4

Python/executor_cases.c.h

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

Python/generated_cases.c.h

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

0 commit comments

Comments
 (0)