Skip to content

Commit 6c53f1a

Browse files
committed
Merge branch 'master' of github.com:python/cpython
2 parents 74bdf1b + 39f6436 commit 6c53f1a

12 files changed

Lines changed: 183 additions & 151 deletions

File tree

Include/compile.h

Lines changed: 9 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,9 @@
11
#ifndef Py_COMPILE_H
22
#define Py_COMPILE_H
3-
4-
#ifndef Py_LIMITED_API
5-
63
#ifdef __cplusplus
74
extern "C" {
85
#endif
96

10-
/* Public interface */
11-
#define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
12-
CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \
13-
CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL | \
14-
CO_FUTURE_GENERATOR_STOP | CO_FUTURE_ANNOTATIONS)
15-
#define PyCF_MASK_OBSOLETE (CO_NESTED)
16-
17-
/* bpo-39562: CO_FUTURE_ and PyCF_ constants must be kept unique.
18-
PyCF_ constants can use bits from 0x0100 to 0x10000.
19-
CO_FUTURE_ constants use bits starting at 0x20000. */
20-
#define PyCF_SOURCE_IS_UTF8 0x0100
21-
#define PyCF_DONT_IMPLY_DEDENT 0x0200
22-
#define PyCF_ONLY_AST 0x0400
23-
#define PyCF_IGNORE_COOKIE 0x0800
24-
#define PyCF_TYPE_COMMENTS 0x1000
25-
#define PyCF_ALLOW_TOP_LEVEL_AWAIT 0x2000
26-
#define PyCF_COMPILE_MASK (PyCF_ONLY_AST | PyCF_ALLOW_TOP_LEVEL_AWAIT | \
27-
PyCF_TYPE_COMMENTS | PyCF_DONT_IMPLY_DEDENT)
28-
29-
#ifndef Py_LIMITED_API
30-
typedef struct {
31-
int cf_flags; /* bitmask of CO_xxx flags relevant to future */
32-
int cf_feature_version; /* minor Python version (PyCF_ONLY_AST) */
33-
} PyCompilerFlags;
34-
35-
#define _PyCompilerFlags_INIT \
36-
(PyCompilerFlags){.cf_flags = 0, .cf_feature_version = PY_MINOR_VERSION}
37-
#endif
38-
39-
/* Future feature support */
40-
41-
typedef struct {
42-
int ff_features; /* flags set by future statements */
43-
int ff_lineno; /* line number of last future statement */
44-
} PyFutureFeatures;
45-
46-
#define FUTURE_NESTED_SCOPES "nested_scopes"
47-
#define FUTURE_GENERATORS "generators"
48-
#define FUTURE_DIVISION "division"
49-
#define FUTURE_ABSOLUTE_IMPORT "absolute_import"
50-
#define FUTURE_WITH_STATEMENT "with_statement"
51-
#define FUTURE_PRINT_FUNCTION "print_function"
52-
#define FUTURE_UNICODE_LITERALS "unicode_literals"
53-
#define FUTURE_BARRY_AS_BDFL "barry_as_FLUFL"
54-
#define FUTURE_GENERATOR_STOP "generator_stop"
55-
#define FUTURE_ANNOTATIONS "annotations"
56-
57-
struct _mod; /* Declare the existence of this type */
58-
#define PyAST_Compile(mod, s, f, ar) PyAST_CompileEx(mod, s, f, -1, ar)
59-
PyAPI_FUNC(PyCodeObject *) PyAST_CompileEx(
60-
struct _mod *mod,
61-
const char *filename, /* decoded from the filesystem encoding */
62-
PyCompilerFlags *flags,
63-
int optimize,
64-
PyArena *arena);
65-
PyAPI_FUNC(PyCodeObject *) PyAST_CompileObject(
66-
struct _mod *mod,
67-
PyObject *filename,
68-
PyCompilerFlags *flags,
69-
int optimize,
70-
PyArena *arena);
71-
PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(
72-
struct _mod * mod,
73-
const char *filename /* decoded from the filesystem encoding */
74-
);
75-
PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromASTObject(
76-
struct _mod * mod,
77-
PyObject *filename
78-
);
79-
80-
/* _Py_Mangle is defined in compile.c */
81-
PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
82-
83-
#define PY_INVALID_STACK_EFFECT INT_MAX
84-
PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg);
85-
PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump);
86-
87-
typedef struct {
88-
int optimize;
89-
int ff_features;
90-
} _PyASTOptimizeState;
91-
92-
PyAPI_FUNC(int) _PyAST_Optimize(struct _mod *, PyArena *arena, _PyASTOptimizeState *state);
93-
94-
#ifdef __cplusplus
95-
}
96-
#endif
97-
98-
#endif /* !Py_LIMITED_API */
99-
1007
/* These definitions must match corresponding definitions in graminit.h. */
1018
#define Py_single_input 256
1029
#define Py_file_input 257
@@ -106,4 +13,13 @@ PyAPI_FUNC(int) _PyAST_Optimize(struct _mod *, PyArena *arena, _PyASTOptimizeSta
10613
/* This doesn't need to match anything */
10714
#define Py_fstring_input 800
10815

16+
#ifndef Py_LIMITED_API
17+
# define Py_CPYTHON_COMPILE_H
18+
# include "cpython/compile.h"
19+
# undef Py_CPYTHON_COMPILE_H
20+
#endif
21+
22+
#ifdef __cplusplus
23+
}
24+
#endif
10925
#endif /* !Py_COMPILE_H */

Include/cpython/compile.h

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#ifndef Py_CPYTHON_COMPILE_H
2+
# error "this header file must not be included directly"
3+
#endif
4+
5+
/* Public interface */
6+
#define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
7+
CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \
8+
CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL | \
9+
CO_FUTURE_GENERATOR_STOP | CO_FUTURE_ANNOTATIONS)
10+
#define PyCF_MASK_OBSOLETE (CO_NESTED)
11+
12+
/* bpo-39562: CO_FUTURE_ and PyCF_ constants must be kept unique.
13+
PyCF_ constants can use bits from 0x0100 to 0x10000.
14+
CO_FUTURE_ constants use bits starting at 0x20000. */
15+
#define PyCF_SOURCE_IS_UTF8 0x0100
16+
#define PyCF_DONT_IMPLY_DEDENT 0x0200
17+
#define PyCF_ONLY_AST 0x0400
18+
#define PyCF_IGNORE_COOKIE 0x0800
19+
#define PyCF_TYPE_COMMENTS 0x1000
20+
#define PyCF_ALLOW_TOP_LEVEL_AWAIT 0x2000
21+
#define PyCF_COMPILE_MASK (PyCF_ONLY_AST | PyCF_ALLOW_TOP_LEVEL_AWAIT | \
22+
PyCF_TYPE_COMMENTS | PyCF_DONT_IMPLY_DEDENT)
23+
24+
typedef struct {
25+
int cf_flags; /* bitmask of CO_xxx flags relevant to future */
26+
int cf_feature_version; /* minor Python version (PyCF_ONLY_AST) */
27+
} PyCompilerFlags;
28+
29+
#define _PyCompilerFlags_INIT \
30+
(PyCompilerFlags){.cf_flags = 0, .cf_feature_version = PY_MINOR_VERSION}
31+
32+
/* Future feature support */
33+
34+
typedef struct {
35+
int ff_features; /* flags set by future statements */
36+
int ff_lineno; /* line number of last future statement */
37+
} PyFutureFeatures;
38+
39+
#define FUTURE_NESTED_SCOPES "nested_scopes"
40+
#define FUTURE_GENERATORS "generators"
41+
#define FUTURE_DIVISION "division"
42+
#define FUTURE_ABSOLUTE_IMPORT "absolute_import"
43+
#define FUTURE_WITH_STATEMENT "with_statement"
44+
#define FUTURE_PRINT_FUNCTION "print_function"
45+
#define FUTURE_UNICODE_LITERALS "unicode_literals"
46+
#define FUTURE_BARRY_AS_BDFL "barry_as_FLUFL"
47+
#define FUTURE_GENERATOR_STOP "generator_stop"
48+
#define FUTURE_ANNOTATIONS "annotations"
49+
50+
struct _mod; /* Declare the existence of this type */
51+
#define PyAST_Compile(mod, s, f, ar) PyAST_CompileEx(mod, s, f, -1, ar)
52+
PyAPI_FUNC(PyCodeObject *) PyAST_CompileEx(
53+
struct _mod *mod,
54+
const char *filename, /* decoded from the filesystem encoding */
55+
PyCompilerFlags *flags,
56+
int optimize,
57+
PyArena *arena);
58+
PyAPI_FUNC(PyCodeObject *) PyAST_CompileObject(
59+
struct _mod *mod,
60+
PyObject *filename,
61+
PyCompilerFlags *flags,
62+
int optimize,
63+
PyArena *arena);
64+
PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(
65+
struct _mod * mod,
66+
const char *filename /* decoded from the filesystem encoding */
67+
);
68+
PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromASTObject(
69+
struct _mod * mod,
70+
PyObject *filename
71+
);
72+
73+
/* _Py_Mangle is defined in compile.c */
74+
PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
75+
76+
#define PY_INVALID_STACK_EFFECT INT_MAX
77+
PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg);
78+
PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump);
79+
80+
typedef struct {
81+
int optimize;
82+
int ff_features;
83+
} _PyASTOptimizeState;
84+
85+
PyAPI_FUNC(int) _PyAST_Optimize(struct _mod *, PyArena *arena, _PyASTOptimizeState *state);

Include/internal/pycore_dtoa.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#ifndef PY_NO_SHORT_FLOAT_REPR
2-
#ifndef Py_INTERNAL_DTOA_H
3-
#define Py_INTERNAL_DTOA_H
42
#ifdef __cplusplus
53
extern "C" {
64
#endif
@@ -19,21 +17,7 @@ PyAPI_FUNC(void) _Py_dg_freedtoa(char *s);
1917
PyAPI_FUNC(double) _Py_dg_stdnan(int sign);
2018
PyAPI_FUNC(double) _Py_dg_infinity(int sign);
2119

22-
#define _PyDtoa_Kmax 7
23-
24-
typedef uint32_t _PyDtoa_ULong;
25-
typedef int32_t _PyDtoa_Long;
26-
typedef uint64_t _PyDtoa_ULLong;
27-
28-
struct
29-
_PyDtoa_Bigint {
30-
struct _PyDtoa_Bigint *next;
31-
int k, maxwds, sign, wds;
32-
_PyDtoa_ULong x[1];
33-
};
34-
3520
#ifdef __cplusplus
3621
}
3722
#endif
38-
#endif /* !Py_INTERNAL_DTOA_H */
3923
#endif /* !PY_NO_SHORT_FLOAT_REPR */

Include/internal/pycore_interp.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ extern "C" {
1313
#include "pycore_gil.h" // struct _gil_runtime_state
1414
#include "pycore_gc.h" // struct _gc_runtime_state
1515
#include "pycore_warnings.h" // struct _warnings_runtime_state
16-
#include "pycore_dtoa.h"
1716

1817
struct _pending_calls {
1918
PyThread_type_lock lock;
@@ -322,9 +321,6 @@ struct _is {
322321

323322
struct ast_state ast;
324323
struct type_cache type_cache;
325-
#ifndef PY_NO_SHORT_FLOAT_REPR
326-
struct _PyDtoa_Bigint *dtoa_freelist[_PyDtoa_Kmax + 1];
327-
#endif
328324
};
329325

330326
extern void _PyInterpreterState_ClearModules(PyInterpreterState *interp);

Lib/__future__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
argument to the builtin function compile() to enable the feature in
4343
dynamically compiled code. This flag is stored in the .compiler_flag
4444
attribute on _Future instances. These values must match the appropriate
45-
#defines of CO_xxx flags in Include/compile.h.
45+
#defines of CO_xxx flags in Include/cpython/compile.h.
4646
4747
No feature line is ever to be deleted from this file.
4848
"""

Makefile.pre.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ PYTHON_HEADERS= \
11051105
$(srcdir)/Include/cpython/bytesobject.h \
11061106
$(srcdir)/Include/cpython/ceval.h \
11071107
$(srcdir)/Include/cpython/code.h \
1108+
$(srcdir)/Include/cpython/compile.h \
11081109
$(srcdir)/Include/cpython/dictobject.h \
11091110
$(srcdir)/Include/cpython/fileobject.h \
11101111
$(srcdir)/Include/cpython/fileutils.h \
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Speed up calls to ``map()`` by using the :pep:`590` ``vectorcall`` calling
2+
convention. Patch by Dong-hee Na.

PCbuild/pythoncore.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
<ClInclude Include="..\Include\cpython\bytesobject.h" />
132132
<ClInclude Include="..\Include\cpython\ceval.h" />
133133
<ClInclude Include="..\Include\cpython\code.h" />
134+
<ClInclude Include="..\Include\cpython\compile.h" />
134135
<ClInclude Include="..\Include\cpython\dictobject.h" />
135136
<ClInclude Include="..\Include\cpython\fileobject.h" />
136137
<ClInclude Include="..\Include\cpython\fileutils.h" />

PCbuild/pythoncore.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@
393393
<ClInclude Include="..\Include\cpython\code.h">
394394
<Filter>Include\cpython</Filter>
395395
</ClInclude>
396+
<ClInclude Include="..\Include\cpython\compile.h">
397+
<Filter>Include</Filter>
398+
</ClInclude>
396399
<ClInclude Include="..\Include\cpython\dictobject.h">
397400
<Filter>Include\cpython</Filter>
398401
</ClInclude>

Python/bltinmodule.c

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,8 +1264,48 @@ map_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
12641264
}
12651265
lz->iters = iters;
12661266
func = PyTuple_GET_ITEM(args, 0);
1267-
Py_INCREF(func);
1268-
lz->func = func;
1267+
lz->func = Py_NewRef(func);
1268+
1269+
return (PyObject *)lz;
1270+
}
1271+
1272+
static PyObject *
1273+
map_vectorcall(PyObject *type, PyObject * const*args,
1274+
size_t nargsf, PyObject *kwnames)
1275+
{
1276+
PyTypeObject *tp = (PyTypeObject *)type;
1277+
if (tp == &PyMap_Type && !_PyArg_NoKwnames("map", kwnames)) {
1278+
return NULL;
1279+
}
1280+
1281+
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
1282+
if (nargs < 2) {
1283+
PyErr_SetString(PyExc_TypeError,
1284+
"map() must have at least two arguments.");
1285+
return NULL;
1286+
}
1287+
1288+
PyObject *iters = PyTuple_New(nargs-1);
1289+
if (iters == NULL) {
1290+
return NULL;
1291+
}
1292+
1293+
for (int i=1; i<nargs; i++) {
1294+
PyObject *it = PyObject_GetIter(args[i]);
1295+
if (it == NULL) {
1296+
Py_DECREF(iters);
1297+
return NULL;
1298+
}
1299+
PyTuple_SET_ITEM(iters, i-1, it);
1300+
}
1301+
1302+
mapobject *lz = (mapobject *)tp->tp_alloc(tp, 0);
1303+
if (lz == NULL) {
1304+
Py_DECREF(iters);
1305+
return NULL;
1306+
}
1307+
lz->iters = iters;
1308+
lz->func = Py_NewRef(args[0]);
12691309

12701310
return (PyObject *)lz;
12711311
}
@@ -1403,6 +1443,7 @@ PyTypeObject PyMap_Type = {
14031443
PyType_GenericAlloc, /* tp_alloc */
14041444
map_new, /* tp_new */
14051445
PyObject_GC_Del, /* tp_free */
1446+
.tp_vectorcall = (vectorcallfunc)map_vectorcall
14061447
};
14071448

14081449

0 commit comments

Comments
 (0)