Mercurial > cpython-lru_cache-weakref
comparison Python/ceval.c @ 47294:4fe192d48960 legacy-trunk
Renamed PyString to PyBytes
| author | Christian Heimes <christian@cheimes.de> |
|---|---|
| date | Mon, 26 May 2008 12:51:38 +0000 |
| parents | 7670005da8c5 |
| children | 52294af4b663 |
comparison
equal
deleted
inserted
replaced
| 47292:abafccfe7501 | 47294:4fe192d48960 |
|---|---|
| 737 co = f->f_code; | 737 co = f->f_code; |
| 738 names = co->co_names; | 738 names = co->co_names; |
| 739 consts = co->co_consts; | 739 consts = co->co_consts; |
| 740 fastlocals = f->f_localsplus; | 740 fastlocals = f->f_localsplus; |
| 741 freevars = f->f_localsplus + co->co_nlocals; | 741 freevars = f->f_localsplus + co->co_nlocals; |
| 742 first_instr = (unsigned char*) PyString_AS_STRING(co->co_code); | 742 first_instr = (unsigned char*) PyBytes_AS_STRING(co->co_code); |
| 743 /* An explanation is in order for the next line. | 743 /* An explanation is in order for the next line. |
| 744 | 744 |
| 745 f->f_lasti now refers to the index of the last instruction | 745 f->f_lasti now refers to the index of the last instruction |
| 746 executed. You might think this was obvious from the name, but | 746 executed. You might think this was obvious from the name, but |
| 747 this wasn't always true before 2.3! PyFrame_New now sets | 747 this wasn't always true before 2.3! PyFrame_New now sets |
| 764 | 764 |
| 765 #ifdef LLTRACE | 765 #ifdef LLTRACE |
| 766 lltrace = PyDict_GetItemString(f->f_globals, "__lltrace__") != NULL; | 766 lltrace = PyDict_GetItemString(f->f_globals, "__lltrace__") != NULL; |
| 767 #endif | 767 #endif |
| 768 #if defined(Py_DEBUG) || defined(LLTRACE) | 768 #if defined(Py_DEBUG) || defined(LLTRACE) |
| 769 filename = PyString_AsString(co->co_filename); | 769 filename = PyBytes_AsString(co->co_filename); |
| 770 #endif | 770 #endif |
| 771 | 771 |
| 772 why = WHY_NOT; | 772 why = WHY_NOT; |
| 773 err = 0; | 773 err = 0; |
| 774 x = Py_None; /* Not a reference, just anything non-NULL */ | 774 x = Py_None; /* Not a reference, just anything non-NULL */ |
| 1145 i = a + b; | 1145 i = a + b; |
| 1146 if ((i^a) < 0 && (i^b) < 0) | 1146 if ((i^a) < 0 && (i^b) < 0) |
| 1147 goto slow_add; | 1147 goto slow_add; |
| 1148 x = PyInt_FromLong(i); | 1148 x = PyInt_FromLong(i); |
| 1149 } | 1149 } |
| 1150 else if (PyString_CheckExact(v) && | 1150 else if (PyBytes_CheckExact(v) && |
| 1151 PyString_CheckExact(w)) { | 1151 PyBytes_CheckExact(w)) { |
| 1152 x = string_concatenate(v, w, f, next_instr); | 1152 x = string_concatenate(v, w, f, next_instr); |
| 1153 /* string_concatenate consumed the ref to v */ | 1153 /* string_concatenate consumed the ref to v */ |
| 1154 goto skip_decref_vx; | 1154 goto skip_decref_vx; |
| 1155 } | 1155 } |
| 1156 else { | 1156 else { |
| 1347 i = a + b; | 1347 i = a + b; |
| 1348 if ((i^a) < 0 && (i^b) < 0) | 1348 if ((i^a) < 0 && (i^b) < 0) |
| 1349 goto slow_iadd; | 1349 goto slow_iadd; |
| 1350 x = PyInt_FromLong(i); | 1350 x = PyInt_FromLong(i); |
| 1351 } | 1351 } |
| 1352 else if (PyString_CheckExact(v) && | 1352 else if (PyBytes_CheckExact(v) && |
| 1353 PyString_CheckExact(w)) { | 1353 PyBytes_CheckExact(w)) { |
| 1354 x = string_concatenate(v, w, f, next_instr); | 1354 x = string_concatenate(v, w, f, next_instr); |
| 1355 /* string_concatenate consumed the ref to v */ | 1355 /* string_concatenate consumed the ref to v */ |
| 1356 goto skip_decref_v; | 1356 goto skip_decref_v; |
| 1357 } | 1357 } |
| 1358 else { | 1358 else { |
| 1574 err = PyFile_WriteString(" ", w); | 1574 err = PyFile_WriteString(" ", w); |
| 1575 if (err == 0) | 1575 if (err == 0) |
| 1576 err = PyFile_WriteObject(v, w, Py_PRINT_RAW); | 1576 err = PyFile_WriteObject(v, w, Py_PRINT_RAW); |
| 1577 if (err == 0) { | 1577 if (err == 0) { |
| 1578 /* XXX move into writeobject() ? */ | 1578 /* XXX move into writeobject() ? */ |
| 1579 if (PyString_Check(v)) { | 1579 if (PyBytes_Check(v)) { |
| 1580 char *s = PyString_AS_STRING(v); | 1580 char *s = PyBytes_AS_STRING(v); |
| 1581 Py_ssize_t len = PyString_GET_SIZE(v); | 1581 Py_ssize_t len = PyBytes_GET_SIZE(v); |
| 1582 if (len == 0 || | 1582 if (len == 0 || |
| 1583 !isspace(Py_CHARMASK(s[len-1])) || | 1583 !isspace(Py_CHARMASK(s[len-1])) || |
| 1584 s[len-1] == ' ') | 1584 s[len-1] == ' ') |
| 1585 PyFile_SoftSpace(w, 1); | 1585 PyFile_SoftSpace(w, 1); |
| 1586 } | 1586 } |
| 1703 if (why == WHY_RETURN || | 1703 if (why == WHY_RETURN || |
| 1704 why == WHY_CONTINUE) | 1704 why == WHY_CONTINUE) |
| 1705 retval = POP(); | 1705 retval = POP(); |
| 1706 } | 1706 } |
| 1707 else if (PyExceptionClass_Check(v) || | 1707 else if (PyExceptionClass_Check(v) || |
| 1708 PyString_Check(v)) { | 1708 PyBytes_Check(v)) { |
| 1709 w = POP(); | 1709 w = POP(); |
| 1710 u = POP(); | 1710 u = POP(); |
| 1711 PyErr_Restore(v, w, u); | 1711 PyErr_Restore(v, w, u); |
| 1712 why = WHY_RERAISE; | 1712 why = WHY_RERAISE; |
| 1713 break; | 1713 break; |
| 1867 PUSH(x); | 1867 PUSH(x); |
| 1868 continue; | 1868 continue; |
| 1869 | 1869 |
| 1870 case LOAD_GLOBAL: | 1870 case LOAD_GLOBAL: |
| 1871 w = GETITEM(names, oparg); | 1871 w = GETITEM(names, oparg); |
| 1872 if (PyString_CheckExact(w)) { | 1872 if (PyBytes_CheckExact(w)) { |
| 1873 /* Inline the PyDict_GetItem() calls. | 1873 /* Inline the PyDict_GetItem() calls. |
| 1874 WARNING: this is an extreme speed hack. | 1874 WARNING: this is an extreme speed hack. |
| 1875 Do not try this at home. */ | 1875 Do not try this at home. */ |
| 1876 long hash = ((PyStringObject *)w)->ob_shash; | 1876 long hash = ((PyBytesObject *)w)->ob_shash; |
| 1877 if (hash != -1) { | 1877 if (hash != -1) { |
| 1878 PyDictObject *d; | 1878 PyDictObject *d; |
| 1879 PyDictEntry *e; | 1879 PyDictEntry *e; |
| 1880 d = (PyDictObject *)(f->f_globals); | 1880 d = (PyDictObject *)(f->f_globals); |
| 1881 e = d->ma_lookup(d, w, hash); | 1881 e = d->ma_lookup(d, w, hash); |
| 2724 if (argcount > co->co_argcount) { | 2724 if (argcount > co->co_argcount) { |
| 2725 if (!(co->co_flags & CO_VARARGS)) { | 2725 if (!(co->co_flags & CO_VARARGS)) { |
| 2726 PyErr_Format(PyExc_TypeError, | 2726 PyErr_Format(PyExc_TypeError, |
| 2727 "%.200s() takes %s %d " | 2727 "%.200s() takes %s %d " |
| 2728 "%sargument%s (%d given)", | 2728 "%sargument%s (%d given)", |
| 2729 PyString_AsString(co->co_name), | 2729 PyBytes_AsString(co->co_name), |
| 2730 defcount ? "at most" : "exactly", | 2730 defcount ? "at most" : "exactly", |
| 2731 co->co_argcount, | 2731 co->co_argcount, |
| 2732 kwcount ? "non-keyword " : "", | 2732 kwcount ? "non-keyword " : "", |
| 2733 co->co_argcount == 1 ? "" : "s", | 2733 co->co_argcount == 1 ? "" : "s", |
| 2734 argcount); | 2734 argcount); |
| 2754 } | 2754 } |
| 2755 for (i = 0; i < kwcount; i++) { | 2755 for (i = 0; i < kwcount; i++) { |
| 2756 PyObject *keyword = kws[2*i]; | 2756 PyObject *keyword = kws[2*i]; |
| 2757 PyObject *value = kws[2*i + 1]; | 2757 PyObject *value = kws[2*i + 1]; |
| 2758 int j; | 2758 int j; |
| 2759 if (keyword == NULL || !PyString_Check(keyword)) { | 2759 if (keyword == NULL || !PyBytes_Check(keyword)) { |
| 2760 PyErr_Format(PyExc_TypeError, | 2760 PyErr_Format(PyExc_TypeError, |
| 2761 "%.200s() keywords must be strings", | 2761 "%.200s() keywords must be strings", |
| 2762 PyString_AsString(co->co_name)); | 2762 PyBytes_AsString(co->co_name)); |
| 2763 goto fail; | 2763 goto fail; |
| 2764 } | 2764 } |
| 2765 /* XXX slow -- speed up using dictionary? */ | 2765 /* XXX slow -- speed up using dictionary? */ |
| 2766 for (j = 0; j < co->co_argcount; j++) { | 2766 for (j = 0; j < co->co_argcount; j++) { |
| 2767 PyObject *nm = PyTuple_GET_ITEM( | 2767 PyObject *nm = PyTuple_GET_ITEM( |
| 2779 if (j >= co->co_argcount) { | 2779 if (j >= co->co_argcount) { |
| 2780 if (kwdict == NULL) { | 2780 if (kwdict == NULL) { |
| 2781 PyErr_Format(PyExc_TypeError, | 2781 PyErr_Format(PyExc_TypeError, |
| 2782 "%.200s() got an unexpected " | 2782 "%.200s() got an unexpected " |
| 2783 "keyword argument '%.400s'", | 2783 "keyword argument '%.400s'", |
| 2784 PyString_AsString(co->co_name), | 2784 PyBytes_AsString(co->co_name), |
| 2785 PyString_AsString(keyword)); | 2785 PyBytes_AsString(keyword)); |
| 2786 goto fail; | 2786 goto fail; |
| 2787 } | 2787 } |
| 2788 PyDict_SetItem(kwdict, keyword, value); | 2788 PyDict_SetItem(kwdict, keyword, value); |
| 2789 } | 2789 } |
| 2790 else { | 2790 else { |
| 2791 if (GETLOCAL(j) != NULL) { | 2791 if (GETLOCAL(j) != NULL) { |
| 2792 PyErr_Format(PyExc_TypeError, | 2792 PyErr_Format(PyExc_TypeError, |
| 2793 "%.200s() got multiple " | 2793 "%.200s() got multiple " |
| 2794 "values for keyword " | 2794 "values for keyword " |
| 2795 "argument '%.400s'", | 2795 "argument '%.400s'", |
| 2796 PyString_AsString(co->co_name), | 2796 PyBytes_AsString(co->co_name), |
| 2797 PyString_AsString(keyword)); | 2797 PyBytes_AsString(keyword)); |
| 2798 goto fail; | 2798 goto fail; |
| 2799 } | 2799 } |
| 2800 Py_INCREF(value); | 2800 Py_INCREF(value); |
| 2801 SETLOCAL(j, value); | 2801 SETLOCAL(j, value); |
| 2802 } | 2802 } |
| 2806 for (i = argcount; i < m; i++) { | 2806 for (i = argcount; i < m; i++) { |
| 2807 if (GETLOCAL(i) == NULL) { | 2807 if (GETLOCAL(i) == NULL) { |
| 2808 PyErr_Format(PyExc_TypeError, | 2808 PyErr_Format(PyExc_TypeError, |
| 2809 "%.200s() takes %s %d " | 2809 "%.200s() takes %s %d " |
| 2810 "%sargument%s (%d given)", | 2810 "%sargument%s (%d given)", |
| 2811 PyString_AsString(co->co_name), | 2811 PyBytes_AsString(co->co_name), |
| 2812 ((co->co_flags & CO_VARARGS) || | 2812 ((co->co_flags & CO_VARARGS) || |
| 2813 defcount) ? "at least" | 2813 defcount) ? "at least" |
| 2814 : "exactly", | 2814 : "exactly", |
| 2815 m, kwcount ? "non-keyword " : "", | 2815 m, kwcount ? "non-keyword " : "", |
| 2816 m == 1 ? "" : "s", i); | 2816 m == 1 ? "" : "s", i); |
| 2832 } | 2832 } |
| 2833 else { | 2833 else { |
| 2834 if (argcount > 0 || kwcount > 0) { | 2834 if (argcount > 0 || kwcount > 0) { |
| 2835 PyErr_Format(PyExc_TypeError, | 2835 PyErr_Format(PyExc_TypeError, |
| 2836 "%.200s() takes no arguments (%d given)", | 2836 "%.200s() takes no arguments (%d given)", |
| 2837 PyString_AsString(co->co_name), | 2837 PyBytes_AsString(co->co_name), |
| 2838 argcount + kwcount); | 2838 argcount + kwcount); |
| 2839 goto fail; | 2839 goto fail; |
| 2840 } | 2840 } |
| 2841 } | 2841 } |
| 2842 /* Allocate and initialize storage for cell vars, and copy free | 2842 /* Allocate and initialize storage for cell vars, and copy free |
| 2858 Should arrange for the compiler to put cellvars | 2858 Should arrange for the compiler to put cellvars |
| 2859 that are arguments at the beginning of the cellvars | 2859 that are arguments at the beginning of the cellvars |
| 2860 list so that we can march over it more efficiently? | 2860 list so that we can march over it more efficiently? |
| 2861 */ | 2861 */ |
| 2862 for (i = 0; i < PyTuple_GET_SIZE(co->co_cellvars); ++i) { | 2862 for (i = 0; i < PyTuple_GET_SIZE(co->co_cellvars); ++i) { |
| 2863 cellname = PyString_AS_STRING( | 2863 cellname = PyBytes_AS_STRING( |
| 2864 PyTuple_GET_ITEM(co->co_cellvars, i)); | 2864 PyTuple_GET_ITEM(co->co_cellvars, i)); |
| 2865 found = 0; | 2865 found = 0; |
| 2866 for (j = 0; j < nargs; j++) { | 2866 for (j = 0; j < nargs; j++) { |
| 2867 argname = PyString_AS_STRING( | 2867 argname = PyBytes_AS_STRING( |
| 2868 PyTuple_GET_ITEM(co->co_varnames, j)); | 2868 PyTuple_GET_ITEM(co->co_varnames, j)); |
| 2869 if (strcmp(cellname, argname) == 0) { | 2869 if (strcmp(cellname, argname) == 0) { |
| 2870 c = PyCell_New(GETLOCAL(j)); | 2870 c = PyCell_New(GETLOCAL(j)); |
| 2871 if (c == NULL) | 2871 if (c == NULL) |
| 2872 goto fail; | 2872 goto fail; |
| 3520 PyEval_GetFuncName(PyObject *func) | 3520 PyEval_GetFuncName(PyObject *func) |
| 3521 { | 3521 { |
| 3522 if (PyMethod_Check(func)) | 3522 if (PyMethod_Check(func)) |
| 3523 return PyEval_GetFuncName(PyMethod_GET_FUNCTION(func)); | 3523 return PyEval_GetFuncName(PyMethod_GET_FUNCTION(func)); |
| 3524 else if (PyFunction_Check(func)) | 3524 else if (PyFunction_Check(func)) |
| 3525 return PyString_AsString(((PyFunctionObject*)func)->func_name); | 3525 return PyBytes_AsString(((PyFunctionObject*)func)->func_name); |
| 3526 else if (PyCFunction_Check(func)) | 3526 else if (PyCFunction_Check(func)) |
| 3527 return ((PyCFunctionObject*)func)->m_ml->ml_name; | 3527 return ((PyCFunctionObject*)func)->m_ml->ml_name; |
| 3528 else if (PyClass_Check(func)) | 3528 else if (PyClass_Check(func)) |
| 3529 return PyString_AsString(((PyClassObject*)func)->cl_name); | 3529 return PyBytes_AsString(((PyClassObject*)func)->cl_name); |
| 3530 else if (PyInstance_Check(func)) { | 3530 else if (PyInstance_Check(func)) { |
| 3531 return PyString_AsString( | 3531 return PyBytes_AsString( |
| 3532 ((PyInstanceObject*)func)->in_class->cl_name); | 3532 ((PyInstanceObject*)func)->in_class->cl_name); |
| 3533 } else { | 3533 } else { |
| 3534 return func->ob_type->tp_name; | 3534 return func->ob_type->tp_name; |
| 3535 } | 3535 } |
| 3536 } | 3536 } |
| 3765 PyErr_Format(PyExc_TypeError, | 3765 PyErr_Format(PyExc_TypeError, |
| 3766 "%.200s%s got multiple values " | 3766 "%.200s%s got multiple values " |
| 3767 "for keyword argument '%.200s'", | 3767 "for keyword argument '%.200s'", |
| 3768 PyEval_GetFuncName(func), | 3768 PyEval_GetFuncName(func), |
| 3769 PyEval_GetFuncDesc(func), | 3769 PyEval_GetFuncDesc(func), |
| 3770 PyString_AsString(key)); | 3770 PyBytes_AsString(key)); |
| 3771 Py_DECREF(key); | 3771 Py_DECREF(key); |
| 3772 Py_DECREF(value); | 3772 Py_DECREF(value); |
| 3773 Py_DECREF(kwdict); | 3773 Py_DECREF(kwdict); |
| 3774 return NULL; | 3774 return NULL; |
| 3775 } | 3775 } |
| 4084 if (PyTuple_Check(w)) { | 4084 if (PyTuple_Check(w)) { |
| 4085 Py_ssize_t i, length; | 4085 Py_ssize_t i, length; |
| 4086 length = PyTuple_Size(w); | 4086 length = PyTuple_Size(w); |
| 4087 for (i = 0; i < length; i += 1) { | 4087 for (i = 0; i < length; i += 1) { |
| 4088 PyObject *exc = PyTuple_GET_ITEM(w, i); | 4088 PyObject *exc = PyTuple_GET_ITEM(w, i); |
| 4089 if (PyString_Check(exc)) { | 4089 if (PyBytes_Check(exc)) { |
| 4090 int ret_val; | 4090 int ret_val; |
| 4091 ret_val = PyErr_WarnEx( | 4091 ret_val = PyErr_WarnEx( |
| 4092 PyExc_DeprecationWarning, | 4092 PyExc_DeprecationWarning, |
| 4093 "catching of string " | 4093 "catching of string " |
| 4094 "exceptions is deprecated", 1); | 4094 "exceptions is deprecated", 1); |
| 4107 return NULL; | 4107 return NULL; |
| 4108 } | 4108 } |
| 4109 } | 4109 } |
| 4110 } | 4110 } |
| 4111 else { | 4111 else { |
| 4112 if (PyString_Check(w)) { | 4112 if (PyBytes_Check(w)) { |
| 4113 int ret_val; | 4113 int ret_val; |
| 4114 ret_val = PyErr_WarnEx( | 4114 ret_val = PyErr_WarnEx( |
| 4115 PyExc_DeprecationWarning, | 4115 PyExc_DeprecationWarning, |
| 4116 "catching of string " | 4116 "catching of string " |
| 4117 "exceptions is deprecated", 1); | 4117 "exceptions is deprecated", 1); |
| 4147 | 4147 |
| 4148 x = PyObject_GetAttr(v, name); | 4148 x = PyObject_GetAttr(v, name); |
| 4149 if (x == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) { | 4149 if (x == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4150 PyErr_Format(PyExc_ImportError, | 4150 PyErr_Format(PyExc_ImportError, |
| 4151 "cannot import name %.230s", | 4151 "cannot import name %.230s", |
| 4152 PyString_AsString(name)); | 4152 PyBytes_AsString(name)); |
| 4153 } | 4153 } |
| 4154 return x; | 4154 return x; |
| 4155 } | 4155 } |
| 4156 | 4156 |
| 4157 static int | 4157 static int |
| 4189 else | 4189 else |
| 4190 PyErr_Clear(); | 4190 PyErr_Clear(); |
| 4191 break; | 4191 break; |
| 4192 } | 4192 } |
| 4193 if (skip_leading_underscores && | 4193 if (skip_leading_underscores && |
| 4194 PyString_Check(name) && | 4194 PyBytes_Check(name) && |
| 4195 PyString_AS_STRING(name)[0] == '_') | 4195 PyBytes_AS_STRING(name)[0] == '_') |
| 4196 { | 4196 { |
| 4197 Py_DECREF(name); | 4197 Py_DECREF(name); |
| 4198 continue; | 4198 continue; |
| 4199 } | 4199 } |
| 4200 value = PyObject_GetAttr(v, name); | 4200 value = PyObject_GetAttr(v, name); |
| 4249 by augmenting the error message with more information.*/ | 4249 by augmenting the error message with more information.*/ |
| 4250 | 4250 |
| 4251 PyObject *ptype, *pvalue, *ptraceback; | 4251 PyObject *ptype, *pvalue, *ptraceback; |
| 4252 | 4252 |
| 4253 PyErr_Fetch(&ptype, &pvalue, &ptraceback); | 4253 PyErr_Fetch(&ptype, &pvalue, &ptraceback); |
| 4254 if (PyString_Check(pvalue)) { | 4254 if (PyBytes_Check(pvalue)) { |
| 4255 PyObject *newmsg; | 4255 PyObject *newmsg; |
| 4256 newmsg = PyString_FromFormat( | 4256 newmsg = PyBytes_FromFormat( |
| 4257 "Error when calling the metaclass bases\n" | 4257 "Error when calling the metaclass bases\n" |
| 4258 " %s", | 4258 " %s", |
| 4259 PyString_AS_STRING(pvalue)); | 4259 PyBytes_AS_STRING(pvalue)); |
| 4260 if (newmsg != NULL) { | 4260 if (newmsg != NULL) { |
| 4261 Py_DECREF(pvalue); | 4261 Py_DECREF(pvalue); |
| 4262 pvalue = newmsg; | 4262 pvalue = newmsg; |
| 4263 } | 4263 } |
| 4264 } | 4264 } |
| 4295 return -1; | 4295 return -1; |
| 4296 } | 4296 } |
| 4297 } | 4297 } |
| 4298 else if (locals == Py_None) | 4298 else if (locals == Py_None) |
| 4299 locals = globals; | 4299 locals = globals; |
| 4300 if (!PyString_Check(prog) && | 4300 if (!PyBytes_Check(prog) && |
| 4301 !PyUnicode_Check(prog) && | 4301 !PyUnicode_Check(prog) && |
| 4302 !PyCode_Check(prog) && | 4302 !PyCode_Check(prog) && |
| 4303 !PyFile_Check(prog)) { | 4303 !PyFile_Check(prog)) { |
| 4304 PyErr_SetString(PyExc_TypeError, | 4304 PyErr_SetString(PyExc_TypeError, |
| 4305 "exec: arg 1 must be a string, file, or code object"); | 4305 "exec: arg 1 must be a string, file, or code object"); |
| 4325 } | 4325 } |
| 4326 v = PyEval_EvalCode((PyCodeObject *) prog, globals, locals); | 4326 v = PyEval_EvalCode((PyCodeObject *) prog, globals, locals); |
| 4327 } | 4327 } |
| 4328 else if (PyFile_Check(prog)) { | 4328 else if (PyFile_Check(prog)) { |
| 4329 FILE *fp = PyFile_AsFile(prog); | 4329 FILE *fp = PyFile_AsFile(prog); |
| 4330 char *name = PyString_AsString(PyFile_Name(prog)); | 4330 char *name = PyBytes_AsString(PyFile_Name(prog)); |
| 4331 PyCompilerFlags cf; | 4331 PyCompilerFlags cf; |
| 4332 if (name == NULL) | 4332 if (name == NULL) |
| 4333 return -1; | 4333 return -1; |
| 4334 cf.cf_flags = 0; | 4334 cf.cf_flags = 0; |
| 4335 if (PyEval_MergeCompilerFlags(&cf)) | 4335 if (PyEval_MergeCompilerFlags(&cf)) |
| 4351 return -1; | 4351 return -1; |
| 4352 prog = tmp; | 4352 prog = tmp; |
| 4353 cf.cf_flags |= PyCF_SOURCE_IS_UTF8; | 4353 cf.cf_flags |= PyCF_SOURCE_IS_UTF8; |
| 4354 } | 4354 } |
| 4355 #endif | 4355 #endif |
| 4356 if (PyString_AsStringAndSize(prog, &str, NULL)) | 4356 if (PyBytes_AsStringAndSize(prog, &str, NULL)) |
| 4357 return -1; | 4357 return -1; |
| 4358 if (PyEval_MergeCompilerFlags(&cf)) | 4358 if (PyEval_MergeCompilerFlags(&cf)) |
| 4359 v = PyRun_StringFlags(str, Py_file_input, globals, | 4359 v = PyRun_StringFlags(str, Py_file_input, globals, |
| 4360 locals, &cf); | 4360 locals, &cf); |
| 4361 else | 4361 else |
| 4376 char *obj_str; | 4376 char *obj_str; |
| 4377 | 4377 |
| 4378 if (!obj) | 4378 if (!obj) |
| 4379 return; | 4379 return; |
| 4380 | 4380 |
| 4381 obj_str = PyString_AsString(obj); | 4381 obj_str = PyBytes_AsString(obj); |
| 4382 if (!obj_str) | 4382 if (!obj_str) |
| 4383 return; | 4383 return; |
| 4384 | 4384 |
| 4385 PyErr_Format(exc, format_str, obj_str); | 4385 PyErr_Format(exc, format_str, obj_str); |
| 4386 } | 4386 } |
| 4389 string_concatenate(PyObject *v, PyObject *w, | 4389 string_concatenate(PyObject *v, PyObject *w, |
| 4390 PyFrameObject *f, unsigned char *next_instr) | 4390 PyFrameObject *f, unsigned char *next_instr) |
| 4391 { | 4391 { |
| 4392 /* This function implements 'variable += expr' when both arguments | 4392 /* This function implements 'variable += expr' when both arguments |
| 4393 are strings. */ | 4393 are strings. */ |
| 4394 Py_ssize_t v_len = PyString_GET_SIZE(v); | 4394 Py_ssize_t v_len = PyBytes_GET_SIZE(v); |
| 4395 Py_ssize_t w_len = PyString_GET_SIZE(w); | 4395 Py_ssize_t w_len = PyBytes_GET_SIZE(w); |
| 4396 Py_ssize_t new_len = v_len + w_len; | 4396 Py_ssize_t new_len = v_len + w_len; |
| 4397 if (new_len < 0) { | 4397 if (new_len < 0) { |
| 4398 PyErr_SetString(PyExc_OverflowError, | 4398 PyErr_SetString(PyExc_OverflowError, |
| 4399 "strings are too large to concat"); | 4399 "strings are too large to concat"); |
| 4400 return NULL; | 4400 return NULL; |
| 4439 break; | 4439 break; |
| 4440 } | 4440 } |
| 4441 } | 4441 } |
| 4442 } | 4442 } |
| 4443 | 4443 |
| 4444 if (v->ob_refcnt == 1 && !PyString_CHECK_INTERNED(v)) { | 4444 if (v->ob_refcnt == 1 && !PyBytes_CHECK_INTERNED(v)) { |
| 4445 /* Now we own the last reference to 'v', so we can resize it | 4445 /* Now we own the last reference to 'v', so we can resize it |
| 4446 * in-place. | 4446 * in-place. |
| 4447 */ | 4447 */ |
| 4448 if (_PyString_Resize(&v, new_len) != 0) { | 4448 if (_PyBytes_Resize(&v, new_len) != 0) { |
| 4449 /* XXX if _PyString_Resize() fails, 'v' has been | 4449 /* XXX if _PyBytes_Resize() fails, 'v' has been |
| 4450 * deallocated so it cannot be put back into | 4450 * deallocated so it cannot be put back into |
| 4451 * 'variable'. The MemoryError is raised when there | 4451 * 'variable'. The MemoryError is raised when there |
| 4452 * is no value in 'variable', which might (very | 4452 * is no value in 'variable', which might (very |
| 4453 * remotely) be a cause of incompatibilities. | 4453 * remotely) be a cause of incompatibilities. |
| 4454 */ | 4454 */ |
| 4455 return NULL; | 4455 return NULL; |
| 4456 } | 4456 } |
| 4457 /* copy 'w' into the newly allocated area of 'v' */ | 4457 /* copy 'w' into the newly allocated area of 'v' */ |
| 4458 memcpy(PyString_AS_STRING(v) + v_len, | 4458 memcpy(PyBytes_AS_STRING(v) + v_len, |
| 4459 PyString_AS_STRING(w), w_len); | 4459 PyBytes_AS_STRING(w), w_len); |
| 4460 return v; | 4460 return v; |
| 4461 } | 4461 } |
| 4462 else { | 4462 else { |
| 4463 /* When in-place resizing is not an option. */ | 4463 /* When in-place resizing is not an option. */ |
| 4464 PyString_Concat(&v, w); | 4464 PyBytes_Concat(&v, w); |
| 4465 return v; | 4465 return v; |
| 4466 } | 4466 } |
| 4467 } | 4467 } |
| 4468 | 4468 |
| 4469 #ifdef DYNAMIC_EXECUTION_PROFILE | 4469 #ifdef DYNAMIC_EXECUTION_PROFILE |
