| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 620bb27 commit ea525a2
14 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -777,6 +777,14 @@ All of the following opcodes use their arguments. | |||
| 777 | 777 | .. versionadded:: 3.6 | |
| 778 | 778 | ||
| 779 | 779 | ||
| 780 | + .. opcode:: BUILD_STRING (count) | ||
| 781 | + | ||
| 782 | + Concatenates *count* strings from the stack and pushes the resulting string | ||
| 783 | + onto the stack. | ||
| 784 | + | ||
| 785 | + .. versionadded:: 3.6 | ||
| 786 | + | ||
| 787 | + | ||
| 780 | 788 | .. opcode:: LOAD_ATTR (namei) | |
| 781 | 789 | ||
| 782 | 790 | Replaces TOS with ``getattr(TOS, co_names[namei])``. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -123,6 +123,7 @@ extern "C" { | |||
| 123 | 123 | #define SETUP_ASYNC_WITH 154 | |
| 124 | 124 | #define FORMAT_VALUE 155 | |
| 125 | 125 | #define BUILD_CONST_KEY_MAP 156 | |
| 126 | + #define BUILD_STRING 157 | ||
| 126 | 127 | ||
| 127 | 128 | /* EXCEPT_HANDLER is a special, implicit block type which is created when | |
| 128 | 129 | entering an except handler. It is not an opcode but we define it here | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1955,6 +1955,14 @@ PyAPI_FUNC(PyObject*) PyUnicode_Join( | |||
| 1955 | 1955 | PyObject *seq /* Sequence object */ | |
| 1956 | 1956 | ); | |
| 1957 | 1957 | ||
| 1958 | + #ifndef Py_LIMITED_API | ||
| 1959 | + PyAPI_FUNC(PyObject *) _PyUnicode_JoinArray( | ||
| 1960 | + PyObject *separator, | ||
| 1961 | + PyObject **items, | ||
| 1962 | + Py_ssize_t seqlen | ||
| 1963 | + ); | ||
| 1964 | + #endif /* Py_LIMITED_API */ | ||
| 1965 | + | ||
| 1958 | 1966 | /* Return 1 if substr matches str[start:end] at the given tail end, 0 | |
| 1959 | 1967 | otherwise. */ | |
| 1960 | 1968 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -232,7 +232,8 @@ def _write_atomic(path, data, mode=0o666): | |||
| 232 | 232 | # Python 3.6a1 3370 (16 bit wordcode) | |
| 233 | 233 | # Python 3.6a1 3371 (add BUILD_CONST_KEY_MAP opcode #27140) | |
| 234 | 234 | # Python 3.6a1 3372 (MAKE_FUNCTION simplification, remove MAKE_CLOSURE | |
| 235 | - #27095) | ||
| 235 | + # #27095) | ||
| 236 | + # Python 3.6b1 3373 (add BUILD_STRING opcode #27078) | ||
| 236 | 237 | # | |
| 237 | 238 | # MAGIC must change whenever the bytecode emitted by the compiler may no | |
| 238 | 239 | # longer be understood by older implementations of the eval loop (usually | |
@@ -241,7 +242,7 @@ def _write_atomic(path, data, mode=0o666): | |||
| 241 | 242 | # Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array | |
| 242 | 243 | # in PC/launcher.c must also be updated. | |
| 243 | 244 | ||
| 244 | - MAGIC_NUMBER = (3372).to_bytes(2, 'little') + b'\r\n' | ||
| 245 | + MAGIC_NUMBER = (3373).to_bytes(2, 'little') + b'\r\n' | ||
| 245 | 246 | _RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c | |
| 246 | 247 | ||
| 247 | 248 | _PYCACHE = '__pycache__' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -213,5 +213,6 @@ def jabs_op(name, op): | |||
| 213 | 213 | ||
| 214 | 214 | def_op('FORMAT_VALUE', 155) | |
| 215 | 215 | def_op('BUILD_CONST_KEY_MAP', 156) | |
| 216 | + def_op('BUILD_STRING', 157) | ||
| 216 | 217 | ||
| 217 | 218 | del def_op, name_op, jrel_op, jabs_op | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,8 @@ What's New in Python 3.6.0 beta 1 | |||
| 10 | 10 | Core and Builtins | |
| 11 | 11 | ----------------- | |
| 12 | 12 | ||
| 13 | + - Issue #27078: Added BUILD_STRING opcode. Optimized f-strings evaluation. | ||
| 14 | + | ||
| 13 | 15 | - Issue #17884: Python now requires systems with inttypes.h and stdint.h | |
| 14 | 16 | ||
| 15 | 17 | - Issue #27961: Require platforms to support ``long long``. Python hasn't | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -675,13 +675,31 @@ PyObject_Format(PyObject *obj, PyObject *format_spec) | |||
| 675 | 675 | PyObject *result = NULL; | |
| 676 | 676 | _Py_IDENTIFIER(__format__); | |
| 677 | 677 | ||
| 678 | + if (format_spec != NULL && !PyUnicode_Check(format_spec)) { | ||
| 679 | + PyErr_Format(PyExc_SystemError, | ||
| 680 | + "Format specifier must be a string, not %.200s", | ||
| 681 | + Py_TYPE(format_spec)->tp_name); | ||
| 682 | + return NULL; | ||
| 683 | + } | ||
| 684 | + | ||
| 685 | + /* Fast path for common types. */ | ||
| 686 | + if (format_spec == NULL || PyUnicode_GET_LENGTH(format_spec) == 0) { | ||
| 687 | + if (PyUnicode_CheckExact(obj)) { | ||
| 688 | + Py_INCREF(obj); | ||
| 689 | + return obj; | ||
| 690 | + } | ||
| 691 | + if (PyLong_CheckExact(obj)) { | ||
| 692 | + return PyObject_Str(obj); | ||
| 693 | + } | ||
| 694 | + } | ||
| 695 | + | ||
| 678 | 696 | /* If no format_spec is provided, use an empty string */ | |
| 679 | 697 | if (format_spec == NULL) { | |
| 680 | 698 | empty = PyUnicode_New(0, 0); | |
| 681 | 699 | format_spec = empty; | |
| 682 | 700 | } | |
| 683 | 701 | ||
| 684 | - /* Find the (unbound!) __format__ method (a borrowed reference) */ | ||
| 702 | + /* Find the (unbound!) __format__ method */ | ||
| 685 | 703 | meth = _PyObject_LookupSpecial(obj, &PyId___format__); | |
| 686 | 704 | if (meth == NULL) { | |
| 687 | 705 | if (!PyErr_Occurred()) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9892,20 +9892,10 @@ case_operation(PyObject *self, | |||
| 9892 | 9892 | PyObject * | |
| 9893 | 9893 | PyUnicode_Join(PyObject *separator, PyObject *seq) | |
| 9894 | 9894 | { | |
| 9895 | - PyObject *sep = NULL; | ||
| 9896 | - Py_ssize_t seplen; | ||
| 9897 | - PyObject *res = NULL; /* the result */ | ||
| 9898 | - PyObject *fseq; /* PySequence_Fast(seq) */ | ||
| 9899 | - Py_ssize_t seqlen; /* len(fseq) -- number of items in sequence */ | ||
| 9895 | + PyObject *res; | ||
| 9896 | + PyObject *fseq; | ||
| 9897 | + Py_ssize_t seqlen; | ||
| 9900 | 9898 | PyObject **items; | |
| 9901 | - PyObject *item; | ||
| 9902 | - Py_ssize_t sz, i, res_offset; | ||
| 9903 | - Py_UCS4 maxchar; | ||
| 9904 | - Py_UCS4 item_maxchar; | ||
| 9905 | - int use_memcpy; | ||
| 9906 | - unsigned char *res_data = NULL, *sep_data = NULL; | ||
| 9907 | - PyObject *last_obj; | ||
| 9908 | - unsigned int kind = 0; | ||
| 9909 | 9899 | ||
| 9910 | 9900 | fseq = PySequence_Fast(seq, "can only join an iterable"); | |
| 9911 | 9901 | if (fseq == NULL) { | |
@@ -9916,21 +9906,39 @@ PyUnicode_Join(PyObject *separator, PyObject *seq) | |||
| 9916 | 9906 | * so we are sure that fseq won't be mutated. | |
| 9917 | 9907 | */ | |
| 9918 | 9908 | ||
| 9909 | + items = PySequence_Fast_ITEMS(fseq); | ||
| 9919 | 9910 | seqlen = PySequence_Fast_GET_SIZE(fseq); | |
| 9911 | + res = _PyUnicode_JoinArray(separator, items, seqlen); | ||
| 9912 | + Py_DECREF(fseq); | ||
| 9913 | + return res; | ||
| 9914 | + } | ||
| 9915 | + | ||
| 9916 | + PyObject * | ||
| 9917 | + _PyUnicode_JoinArray(PyObject *separator, PyObject **items, Py_ssize_t seqlen) | ||
| 9918 | + { | ||
| 9919 | + PyObject *res = NULL; /* the result */ | ||
| 9920 | + PyObject *sep = NULL; | ||
| 9921 | + Py_ssize_t seplen; | ||
| 9922 | + PyObject *item; | ||
| 9923 | + Py_ssize_t sz, i, res_offset; | ||
| 9924 | + Py_UCS4 maxchar; | ||
| 9925 | + Py_UCS4 item_maxchar; | ||
| 9926 | + int use_memcpy; | ||
| 9927 | + unsigned char *res_data = NULL, *sep_data = NULL; | ||
| 9928 | + PyObject *last_obj; | ||
| 9929 | + unsigned int kind = 0; | ||
| 9930 | + | ||
| 9920 | 9931 | /* If empty sequence, return u"". */ | |
| 9921 | 9932 | if (seqlen == 0) { | |
| 9922 | - Py_DECREF(fseq); | ||
| 9923 | 9933 | _Py_RETURN_UNICODE_EMPTY(); | |
| 9924 | 9934 | } | |
| 9925 | 9935 | ||
| 9926 | 9936 | /* If singleton sequence with an exact Unicode, return that. */ | |
| 9927 | 9937 | last_obj = NULL; | |
| 9928 | - items = PySequence_Fast_ITEMS(fseq); | ||
| 9929 | 9938 | if (seqlen == 1) { | |
| 9930 | 9939 | if (PyUnicode_CheckExact(items[0])) { | |
| 9931 | 9940 | res = items[0]; | |
| 9932 | 9941 | Py_INCREF(res); | |
| 9933 | - Py_DECREF(fseq); | ||
| 9934 | 9942 | return res; | |
| 9935 | 9943 | } | |
| 9936 | 9944 | seplen = 0; | |
@@ -10065,13 +10073,11 @@ PyUnicode_Join(PyObject *separator, PyObject *seq) | |||
| 10065 | 10073 | assert(res_offset == PyUnicode_GET_LENGTH(res)); | |
| 10066 | 10074 | } | |
| 10067 | 10075 | ||
| 10068 | - Py_DECREF(fseq); | ||
| 10069 | 10076 | Py_XDECREF(sep); | |
| 10070 | 10077 | assert(_PyUnicode_CheckConsistency(res, 1)); | |
| 10071 | 10078 | return res; | |
| 10072 | 10079 | ||
| 10073 | 10080 | onError: | |
| 10074 | - Py_DECREF(fseq); | ||
| 10075 | 10081 | Py_XDECREF(sep); | |
| 10076 | 10082 | Py_XDECREF(res); | |
| 10077 | 10083 | return NULL; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1089,7 +1089,7 @@ static PYC_MAGIC magic_values[] = { | |||
| 1089 | 1089 | { 3190, 3230, L"3.3" }, | |
| 1090 | 1090 | { 3250, 3310, L"3.4" }, | |
| 1091 | 1091 | { 3320, 3351, L"3.5" }, | |
| 1092 | - { 3360, 3371, L"3.6" }, | ||
| 1092 | + { 3360, 3373, L"3.6" }, | ||
| 1093 | 1093 | { 0 } | |
| 1094 | 1094 | }; | |
| 1095 | 1095 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2538,6 +2538,24 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) | |||
| 2538 | 2538 | DISPATCH(); | |
| 2539 | 2539 | } | |
| 2540 | 2540 | ||
| 2541 | + TARGET(BUILD_STRING) { | ||
| 2542 | + PyObject *str; | ||
| 2543 | + PyObject *empty = PyUnicode_New(0, 0); | ||
| 2544 | + if (empty == NULL) { | ||
| 2545 | + goto error; | ||
| 2546 | + } | ||
| 2547 | + str = _PyUnicode_JoinArray(empty, stack_pointer - oparg, oparg); | ||
| 2548 | + Py_DECREF(empty); | ||
| 2549 | + if (str == NULL) | ||
| 2550 | + goto error; | ||
| 2551 | + while (--oparg >= 0) { | ||
| 2552 | + PyObject *item = POP(); | ||
| 2553 | + Py_DECREF(item); | ||
| 2554 | + } | ||
| 2555 | + PUSH(str); | ||
| 2556 | + DISPATCH(); | ||
| 2557 | + } | ||
| 2558 | + | ||
| 2541 | 2559 | TARGET(BUILD_TUPLE) { | |
| 2542 | 2560 | PyObject *tup = PyTuple_New(oparg); | |
| 2543 | 2561 | if (tup == NULL) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments