aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/_warnings.c41
-rw-r--r--Python/ast.c5
-rw-r--r--Python/bltinmodule.c6
-rw-r--r--Python/ceval.c170
-rw-r--r--Python/clinic/_warnings.c.h38
-rw-r--r--Python/codecs.c27
-rw-r--r--Python/compile.c9
-rw-r--r--Python/errors.c18
-rw-r--r--Python/getargs.c27
-rw-r--r--Python/import.c4
-rw-r--r--Python/importdl.c2
-rw-r--r--Python/marshal.c4
-rw-r--r--Python/modsupport.c151
-rw-r--r--Python/pylifecycle.c6
-rw-r--r--Python/pythonrun.c6
-rw-r--r--Python/structmember.c2
-rw-r--r--Python/sysmodule.c46
17 files changed, 327 insertions, 235 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 6cfae77f126..67f4c6bbe02 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -1,5 +1,6 @@
#include "Python.h"
#include "frameobject.h"
+#include "clinic/_warnings.c.h"
#define MODULE_NAME "_warnings"
@@ -26,7 +27,7 @@ check_matched(PyObject *obj, PyObject *arg)
if (obj == Py_None)
return 1;
- result = _PyObject_CallMethodId(obj, &PyId_match, "O", arg);
+ result = _PyObject_CallMethodIdObjArgs(obj, &PyId_match, arg, NULL);
if (result == NULL)
return -1;
@@ -476,7 +477,7 @@ warn_explicit(PyObject *category, PyObject *message,
}
else {
text = message;
- message = PyObject_CallFunction(category, "O", message);
+ message = PyObject_CallFunctionObjArgs(category, message, NULL);
if (message == NULL)
goto cleanup;
}
@@ -485,6 +486,10 @@ warn_explicit(PyObject *category, PyObject *message,
if (lineno_obj == NULL)
goto cleanup;
+ if (source == Py_None) {
+ source = NULL;
+ }
+
/* Create key. */
key = PyTuple_Pack(3, text, category, lineno_obj);
if (key == NULL)
@@ -805,22 +810,26 @@ do_warn(PyObject *message, PyObject *category, Py_ssize_t stack_level,
return res;
}
-static PyObject *
-warnings_warn(PyObject *self, PyObject *args, PyObject *kwds)
-{
- static char *kw_list[] = {"message", "category", "stacklevel",
- "source", NULL};
- PyObject *message, *category = NULL, *source = NULL;
- Py_ssize_t stack_level = 1;
+/*[clinic input]
+warn as warnings_warn
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OnO:warn", kw_list,
- &message, &category, &stack_level, &source))
- return NULL;
+ message: object
+ category: object = None
+ stacklevel: Py_ssize_t = 1
+ source: object = None
+Issue a warning, or maybe ignore it or raise an exception.
+[clinic start generated code]*/
+
+static PyObject *
+warnings_warn_impl(PyObject *module, PyObject *message, PyObject *category,
+ Py_ssize_t stacklevel, PyObject *source)
+/*[clinic end generated code: output=31ed5ab7d8d760b2 input=bfdf5cf99f6c4edd]*/
+{
category = get_category(message, category);
if (category == NULL)
return NULL;
- return do_warn(message, category, stack_level, source);
+ return do_warn(message, category, stacklevel, source);
}
static PyObject *
@@ -1098,15 +1107,11 @@ exit:
}
-PyDoc_STRVAR(warn_doc,
-"Issue a warning, or maybe ignore it or raise an exception.");
-
PyDoc_STRVAR(warn_explicit_doc,
"Low-level inferface to warnings functionality.");
static PyMethodDef warnings_functions[] = {
- {"warn", (PyCFunction)warnings_warn, METH_VARARGS | METH_KEYWORDS,
- warn_doc},
+ WARNINGS_WARN_METHODDEF
{"warn_explicit", (PyCFunction)warnings_warn_explicit,
METH_VARARGS | METH_KEYWORDS, warn_explicit_doc},
{"_filters_mutated", (PyCFunction)warnings_filters_mutated, METH_NOARGS,
diff --git a/Python/ast.c b/Python/ast.c
index 82f4529bf91..e6786d47f95 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -2738,11 +2738,6 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
return NULL;
}
- if (nargs + nkeywords + ngens > 255) {
- ast_error(c, n, "more than 255 arguments");
- return NULL;
- }
-
args = _Py_asdl_seq_new(nargs + ngens, c->c_arena);
if (!args)
return NULL;
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 69e5f08b0ee..5e1f5624b96 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1923,7 +1923,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
char *s = NULL;
PyObject *stdin_encoding = NULL, *stdin_errors = NULL;
PyObject *stdout_encoding = NULL, *stdout_errors = NULL;
- char *stdin_encoding_str, *stdin_errors_str;
+ const char *stdin_encoding_str, *stdin_errors_str;
PyObject *result;
size_t len;
@@ -1944,7 +1944,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
Py_DECREF(tmp);
if (prompt != NULL) {
/* We have a prompt, encode it as stdout would */
- char *stdout_encoding_str, *stdout_errors_str;
+ const char *stdout_encoding_str, *stdout_errors_str;
PyObject *stringpo;
stdout_encoding = _PyObject_GetAttrId(fout, &PyId_encoding);
stdout_errors = _PyObject_GetAttrId(fout, &PyId_errors);
@@ -2074,7 +2074,7 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds)
}
if (ndigits == NULL || ndigits == Py_None)
- result = PyObject_CallFunctionObjArgs(round, NULL);
+ result = _PyObject_CallNoArg(round);
else
result = PyObject_CallFunctionObjArgs(round, ndigits, NULL);
Py_DECREF(round);
diff --git a/Python/ceval.c b/Python/ceval.c
index d5172b9631f..c6c6e05650b 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -83,63 +83,6 @@ static long dxp[256];
#endif
#endif
-/* Function call profile */
-#ifdef CALL_PROFILE
-#define PCALL_NUM 11
-static int pcall[PCALL_NUM];
-
-#define PCALL_ALL 0
-#define PCALL_FUNCTION 1
-#define PCALL_FAST_FUNCTION 2
-#define PCALL_FASTER_FUNCTION 3
-#define PCALL_METHOD 4
-#define PCALL_BOUND_METHOD 5
-#define PCALL_CFUNCTION 6
-#define PCALL_TYPE 7
-#define PCALL_GENERATOR 8
-#define PCALL_OTHER 9
-#define PCALL_POP 10
-
-/* Notes about the statistics
-
- PCALL_FAST stats
-
- FAST_FUNCTION means no argument tuple needs to be created.
- FASTER_FUNCTION means that the fast-path frame setup code is used.
-
- If there is a method call where the call can be optimized by changing
- the argument tuple and calling the function directly, it gets recorded
- twice.
-
- As a result, the relationship among the statistics appears to be
- PCALL_ALL == PCALL_FUNCTION + PCALL_METHOD - PCALL_BOUND_METHOD +
- PCALL_CFUNCTION + PCALL_TYPE + PCALL_GENERATOR + PCALL_OTHER
- PCALL_FUNCTION > PCALL_FAST_FUNCTION > PCALL_FASTER_FUNCTION
- PCALL_METHOD > PCALL_BOUND_METHOD
-*/
-
-#define PCALL(POS) pcall[POS]++
-
-PyObject *
-PyEval_GetCallStats(PyObject *self)
-{
- return Py_BuildValue("iiiiiiiiiii",
- pcall[0], pcall[1], pcall[2], pcall[3],
- pcall[4], pcall[5], pcall[6], pcall[7],
- pcall[8], pcall[9], pcall[10]);
-}
-#else
-#define PCALL(O)
-
-PyObject *
-PyEval_GetCallStats(PyObject *self)
-{
- Py_INCREF(Py_None);
- return Py_None;
-}
-#endif
-
-
#ifdef WITH_THREAD
#define GIL_REQUEST _Py_atomic_load_relaxed(&gil_drop_request)
#else
@@ -718,7 +661,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
return tstate->interp->eval_frame(f, throwflag);
}
-PyObject *
+PyObject* _Py_HOT_FUNCTION
_PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
{
#ifdef DXPAIRS
@@ -1424,6 +1367,12 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
PyObject *right = POP();
PyObject *left = TOP();
PyObject *sum;
+ /* NOTE(haypo): Please don't try to micro-optimize int+int on
+ CPython using bytecode, it is simply worthless.
+ See http://bugs.python.org/issue21955 and
+ http://bugs.python.org/issue10044 for the discussion. In short,
+ no patch shown any impact on a realistic benchmark, only a minor
+ speedup on microbenchmarks. */
if (PyUnicode_CheckExact(left) &&
PyUnicode_CheckExact(right)) {
sum = unicode_concatenate(left, right, f, next_instr);
@@ -1538,7 +1487,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
TARGET(SET_ADD) {
PyObject *v = POP();
- PyObject *set = stack_pointer[-oparg];
+ PyObject *set = PEEK(oparg);
int err;
err = PySet_Add(set, v);
Py_DECREF(v);
@@ -2400,8 +2349,10 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
TARGET(DELETE_DEREF) {
PyObject *cell = freevars[oparg];
- if (PyCell_GET(cell) != NULL) {
- PyCell_Set(cell, NULL);
+ PyObject *oldobj = PyCell_GET(cell);
+ if (oldobj != NULL) {
+ PyCell_SET(cell, NULL);
+ Py_DECREF(oldobj);
DISPATCH();
}
format_exc_unbound(co, oparg);
@@ -2798,7 +2749,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
PyObject *map;
int err;
STACKADJ(-2);
- map = stack_pointer[-oparg]; /* dict */
+ map = PEEK(oparg); /* dict */
assert(PyDict_CheckExact(map));
err = PyDict_SetItem(map, key, value); /* map[key] = value */
Py_DECREF(value);
@@ -3111,7 +3062,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
Py_DECREF(mgr);
if (enter == NULL)
goto error;
- res = PyObject_CallFunctionObjArgs(enter, NULL);
+ res = _PyObject_CallNoArg(enter);
Py_DECREF(enter);
if (res == NULL)
goto error;
@@ -3145,7 +3096,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
}
SET_TOP(exit);
Py_DECREF(mgr);
- res = PyObject_CallFunctionObjArgs(enter, NULL);
+ res = _PyObject_CallNoArg(enter);
Py_DECREF(enter);
if (res == NULL)
goto error;
@@ -3184,8 +3135,12 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
gotos should still be resumed.)
*/
+ PyObject* stack[3];
PyObject *exit_func;
- PyObject *exc = TOP(), *val = Py_None, *tb = Py_None, *res;
+ PyObject *exc, *val, *tb, *res;
+
+ val = tb = Py_None;
+ exc = TOP();
if (exc == Py_None) {
(void)POP();
exit_func = TOP();
@@ -3229,8 +3184,11 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
assert(block->b_type == EXCEPT_HANDLER);
block->b_level--;
}
- /* XXX Not the fastest way to call it... */
- res = PyObject_CallFunctionObjArgs(exit_func, exc, val, tb, NULL);
+
+ stack[0] = exc;
+ stack[1] = val;
+ stack[2] = tb;
+ res = _PyObject_FastCall(exit_func, stack, 3);
Py_DECREF(exit_func);
if (res == NULL)
goto error;
@@ -3270,7 +3228,6 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
PREDICTED(CALL_FUNCTION);
TARGET(CALL_FUNCTION) {
PyObject **sp, *res;
- PCALL(PCALL_ALL);
sp = stack_pointer;
res = call_function(&sp, oparg, NULL);
stack_pointer = sp;
@@ -3286,7 +3243,6 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
names = POP();
assert(PyTuple_CheckExact(names) && PyTuple_GET_SIZE(names) <= oparg);
- PCALL(PCALL_ALL);
sp = stack_pointer;
res = call_function(&sp, oparg, names);
stack_pointer = sp;
@@ -3301,7 +3257,6 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
TARGET(CALL_FUNCTION_EX) {
PyObject *func, *callargs, *kwargs = NULL, *result;
- PCALL(PCALL_ALL);
if (oparg & 0x01) {
kwargs = POP();
if (!PyDict_CheckExact(kwargs)) {
@@ -4091,8 +4046,6 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
* when the generator is resumed. */
Py_CLEAR(f->f_back);
- PCALL(PCALL_GENERATOR);
-
/* Create a new generator that owns the ready to run frame
* and return that as the value. */
if (is_coro) {
@@ -4245,7 +4198,7 @@ do_raise(PyObject *exc, PyObject *cause)
if (PyExceptionClass_Check(exc)) {
type = exc;
- value = PyObject_CallObject(exc, NULL);
+ value = _PyObject_CallNoArg(exc);
if (value == NULL)
goto raise_error;
if (!PyExceptionInstance_Check(value)) {
@@ -4270,10 +4223,13 @@ do_raise(PyObject *exc, PyObject *cause)
goto raise_error;
}
+ assert(type != NULL);
+ assert(value != NULL);
+
if (cause) {
PyObject *fixed_cause;
if (PyExceptionClass_Check(cause)) {
- fixed_cause = PyObject_CallObject(cause, NULL);
+ fixed_cause = _PyObject_CallNoArg(cause);
if (fixed_cause == NULL)
goto raise_error;
Py_DECREF(cause);
@@ -4296,8 +4252,8 @@ do_raise(PyObject *exc, PyObject *cause)
PyErr_SetObject(type, value);
/* PyErr_SetObject incref's its arguments */
- Py_XDECREF(value);
- Py_XDECREF(type);
+ Py_DECREF(value);
+ Py_DECREF(type);
return 0;
raise_error:
@@ -4681,7 +4637,8 @@ PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
The arg must be a tuple or NULL. The kw must be a dict or NULL. */
PyObject *
-PyEval_CallObjectWithKeywords(PyObject *func, PyObject *args, PyObject *kwargs)
+PyEval_CallObjectWithKeywords(PyObject *callable,
+ PyObject *args, PyObject *kwargs)
{
#ifdef Py_DEBUG
/* PyEval_CallObjectWithKeywords() must not be called with an exception
@@ -4691,7 +4648,7 @@ PyEval_CallObjectWithKeywords(PyObject *func, PyObject *args, PyObject *kwargs)
#endif
if (args == NULL) {
- return _PyObject_FastCallDict(func, NULL, 0, kwargs);
+ return _PyObject_FastCallDict(callable, NULL, 0, kwargs);
}
if (!PyTuple_Check(args)) {
@@ -4706,7 +4663,7 @@ PyEval_CallObjectWithKeywords(PyObject *func, PyObject *args, PyObject *kwargs)
return NULL;
}
- return PyObject_Call(func, args, kwargs);
+ return PyObject_Call(callable, args, kwargs);
}
const char *
@@ -4766,7 +4723,7 @@ if (tstate->use_tracing && tstate->c_profilefunc) { \
x = call; \
}
-static PyObject *
+static PyObject* _Py_HOT_FUNCTION
call_function(PyObject ***pp_stack, Py_ssize_t oparg, PyObject *kwnames)
{
PyObject **pfunc = (*pp_stack) - oparg - 1;
@@ -4782,17 +4739,17 @@ call_function(PyObject ***pp_stack, Py_ssize_t oparg, PyObject *kwnames)
if (PyCFunction_Check(func)) {
PyThreadState *tstate = PyThreadState_GET();
- PCALL(PCALL_CFUNCTION);
-
stack = (*pp_stack) - nargs - nkwargs;
C_TRACE(x, _PyCFunction_FastCallKeywords(func, stack, nargs, kwnames));
}
else {
if (PyMethod_Check(func) && PyMethod_GET_SELF(func) != NULL) {
- /* optimize access to bound methods */
+ /* Optimize access to bound methods. Reuse the Python stack
+ to pass 'self' as the first argument, replace 'func'
+ with 'self'. It avoids the creation of a new temporary tuple
+ for arguments (to replace func with self) when the method uses
+ FASTCALL. */
PyObject *self = PyMethod_GET_SELF(func);
- PCALL(PCALL_METHOD);
- PCALL(PCALL_BOUND_METHOD);
Py_INCREF(self);
func = PyMethod_GET_FUNCTION(func);
Py_INCREF(func);
@@ -4824,7 +4781,6 @@ call_function(PyObject ***pp_stack, Py_ssize_t oparg, PyObject *kwnames)
while ((*pp_stack) > pfunc) {
w = EXT_POP(*pp_stack);
Py_DECREF(w);
- PCALL(PCALL_POP);
}
return x;
@@ -4839,7 +4795,7 @@ call_function(PyObject ***pp_stack, Py_ssize_t oparg, PyObject *kwnames)
done before evaluating the frame.
*/
-static PyObject*
+static PyObject* _Py_HOT_FUNCTION
_PyFunction_FastCall(PyCodeObject *co, PyObject **args, Py_ssize_t nargs,
PyObject *globals)
{
@@ -4849,7 +4805,6 @@ _PyFunction_FastCall(PyCodeObject *co, PyObject **args, Py_ssize_t nargs,
Py_ssize_t i;
PyObject *result;
- PCALL(PCALL_FASTER_FUNCTION);
assert(globals != NULL);
/* XXX Perhaps we should create a specialized
PyFrame_New() that doesn't take locals, but does
@@ -4895,9 +4850,6 @@ fast_function(PyObject *func, PyObject **stack,
/* kwnames must only contains str strings, no subclass, and all keys must
be unique */
- PCALL(PCALL_FUNCTION);
- PCALL(PCALL_FAST_FUNCTION);
-
if (co->co_kwonlyargcount == 0 && nkwargs == 0 &&
co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE))
{
@@ -4960,9 +4912,6 @@ _PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs,
assert(nargs == 0 || args != NULL);
assert(kwargs == NULL || PyDict_Check(kwargs));
- PCALL(PCALL_FUNCTION);
- PCALL(PCALL_FAST_FUNCTION);
-
if (co->co_kwonlyargcount == 0 &&
(kwargs == NULL || PyDict_Size(kwargs) == 0) &&
co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE))
@@ -5030,23 +4979,6 @@ _PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs,
static PyObject *
do_call_core(PyObject *func, PyObject *callargs, PyObject *kwdict)
{
-#ifdef CALL_PROFILE
- /* At this point, we have to look at the type of func to
- update the call stats properly. Do it here so as to avoid
- exposing the call stats machinery outside ceval.c
- */
- if (PyFunction_Check(func))
- PCALL(PCALL_FUNCTION);
- else if (PyMethod_Check(func))
- PCALL(PCALL_METHOD);
- else if (PyType_Check(func))
- PCALL(PCALL_TYPE);
- else if (PyCFunction_Check(func))
- PCALL(PCALL_CFUNCTION);
- else
- PCALL(PCALL_OTHER);
-#endif
-
if (PyCFunction_Check(func)) {
PyObject *result;
PyThreadState *tstate = PyThreadState_GET();
@@ -5345,8 +5277,10 @@ unicode_concatenate(PyObject *v, PyObject *w,
PyObject **freevars = (f->f_localsplus +
f->f_code->co_nlocals);
PyObject *c = freevars[oparg];
- if (PyCell_GET(c) == v)
- PyCell_Set(c, NULL);
+ if (PyCell_GET(c) == v) {
+ PyCell_SET(c, NULL);
+ Py_DECREF(v);
+ }
break;
}
case STORE_NAME:
@@ -5430,8 +5364,8 @@ _PyEval_RequestCodeExtraIndex(freefunc free)
static void
dtrace_function_entry(PyFrameObject *f)
{
- char* filename;
- char* funcname;
+ const char *filename;
+ const char *funcname;
int lineno;
filename = PyUnicode_AsUTF8(f->f_code->co_filename);
@@ -5444,8 +5378,8 @@ dtrace_function_entry(PyFrameObject *f)
static void
dtrace_function_return(PyFrameObject *f)
{
- char* filename;
- char* funcname;
+ const char *filename;
+ const char *funcname;
int lineno;
filename = PyUnicode_AsUTF8(f->f_code->co_filename);
@@ -5461,7 +5395,7 @@ maybe_dtrace_line(PyFrameObject *frame,
int *instr_lb, int *instr_ub, int *instr_prev)
{
int line = frame->f_lineno;
- char *co_filename, *co_name;
+ const char *co_filename, *co_name;
/* If the last instruction executed isn't in the current
instruction window, reset the window.
diff --git a/Python/clinic/_warnings.c.h b/Python/clinic/_warnings.c.h
new file mode 100644
index 00000000000..db2245cb5b1
--- /dev/null
+++ b/Python/clinic/_warnings.c.h
@@ -0,0 +1,38 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+PyDoc_STRVAR(warnings_warn__doc__,
+"warn($module, /, message, category=None, stacklevel=1, source=None)\n"
+"--\n"
+"\n"
+"Issue a warning, or maybe ignore it or raise an exception.");
+
+#define WARNINGS_WARN_METHODDEF \
+ {"warn", (PyCFunction)warnings_warn, METH_FASTCALL, warnings_warn__doc__},
+
+static PyObject *
+warnings_warn_impl(PyObject *module, PyObject *message, PyObject *category,
+ Py_ssize_t stacklevel, PyObject *source);
+
+static PyObject *
+warnings_warn(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"message", "category", "stacklevel", "source", NULL};
+ static _PyArg_Parser _parser = {"O|OnO:warn", _keywords, 0};
+ PyObject *message;
+ PyObject *category = Py_None;
+ Py_ssize_t stacklevel = 1;
+ PyObject *source = Py_None;
+
+ if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
+ &message, &category, &stacklevel, &source)) {
+ goto exit;
+ }
+ return_value = warnings_warn_impl(module, message, category, stacklevel, source);
+
+exit:
+ return return_value;
+}
+/*[clinic end generated code: output=b3c5297c2c55778c input=a9049054013a1b77]*/
diff --git a/Python/codecs.c b/Python/codecs.c
index fe57d0dc42d..688a40bd6ff 100644
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -284,7 +284,7 @@ PyObject *codec_makeincrementalcodec(PyObject *codec_info,
if (errors)
ret = PyObject_CallFunction(inccodec, "s", errors);
else
- ret = PyObject_CallFunction(inccodec, NULL);
+ ret = _PyObject_CallNoArg(inccodec);
Py_DECREF(inccodec);
return ret;
}
@@ -322,7 +322,7 @@ PyObject *codec_getstreamcodec(const char *encoding,
if (errors != NULL)
streamcodec = PyObject_CallFunction(codeccls, "Os", stream, errors);
else
- streamcodec = PyObject_CallFunction(codeccls, "O", stream);
+ streamcodec = PyObject_CallFunctionObjArgs(codeccls, stream, NULL);
Py_DECREF(codecs);
return streamcodec;
}
@@ -867,17 +867,14 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
Py_UCS4 c;
if (PyObject_TypeCheck(exc, (PyTypeObject *)PyExc_UnicodeDecodeError)) {
- unsigned char *p;
+ const unsigned char *p;
if (PyUnicodeDecodeError_GetStart(exc, &start))
return NULL;
if (PyUnicodeDecodeError_GetEnd(exc, &end))
return NULL;
if (!(object = PyUnicodeDecodeError_GetObject(exc)))
return NULL;
- if (!(p = (unsigned char*)PyBytes_AsString(object))) {
- Py_DECREF(object);
- return NULL;
- }
+ p = (const unsigned char*)PyBytes_AS_STRING(object);
res = PyUnicode_New(4 * (end - start), 127);
if (res == NULL) {
Py_DECREF(object);
@@ -1134,7 +1131,7 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
PyObject *restuple;
PyObject *object;
PyObject *encode;
- char *encoding;
+ const char *encoding;
int code;
int bytelength;
Py_ssize_t i;
@@ -1220,7 +1217,7 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
return restuple;
}
else if (PyObject_TypeCheck(exc, (PyTypeObject *)PyExc_UnicodeDecodeError)) {
- unsigned char *p;
+ const unsigned char *p;
Py_UCS4 ch = 0;
if (PyUnicodeDecodeError_GetStart(exc, &start))
return NULL;
@@ -1228,10 +1225,7 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
return NULL;
if (!(object = PyUnicodeDecodeError_GetObject(exc)))
return NULL;
- if (!(p = (unsigned char*)PyBytes_AsString(object))) {
- Py_DECREF(object);
- return NULL;
- }
+ p = (const unsigned char*)PyBytes_AS_STRING(object);
if (!(encode = PyUnicodeDecodeError_GetEncoding(exc))) {
Py_DECREF(object);
return NULL;
@@ -1338,7 +1332,7 @@ PyCodec_SurrogateEscapeErrors(PyObject *exc)
}
else if (PyObject_TypeCheck(exc, (PyTypeObject *)PyExc_UnicodeDecodeError)) {
PyObject *str;
- unsigned char *p;
+ const unsigned char *p;
Py_UCS2 ch[4]; /* decode up to 4 bad bytes. */
int consumed = 0;
if (PyUnicodeDecodeError_GetStart(exc, &start))
@@ -1347,10 +1341,7 @@ PyCodec_SurrogateEscapeErrors(PyObject *exc)
return NULL;
if (!(object = PyUnicodeDecodeError_GetObject(exc)))
return NULL;
- if (!(p = (unsigned char*)PyBytes_AsString(object))) {
- Py_DECREF(object);
- return NULL;
- }
+ p = (const unsigned char*)PyBytes_AS_STRING(object);
while (consumed < 4 && consumed < end-start) {
/* Refuse to escape ASCII bytes. */
if (p[start+consumed] < 128)
diff --git a/Python/compile.c b/Python/compile.c
index 35151cdd590..76f08da432b 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -3348,11 +3348,8 @@ compiler_dict(struct compiler *c, expr_ty e)
/* If there is more than one dict, they need to be merged into a new
* dict. If there is one dict and it's an unpacking, then it needs
* to be copied into a new dict." */
- while (containers > 1 || is_unpacking) {
- int oparg = containers < 255 ? containers : 255;
- ADDOP_I(c, BUILD_MAP_UNPACK, oparg);
- containers -= (oparg - 1);
- is_unpacking = 0;
+ if (containers > 1 || is_unpacking) {
+ ADDOP_I(c, BUILD_MAP_UNPACK, containers);
}
return 1;
}
@@ -4043,7 +4040,7 @@ compiler_visit_keyword(struct compiler *c, keyword_ty k)
static int
expr_constant(struct compiler *c, expr_ty e)
{
- char *id;
+ const char *id;
switch (e->kind) {
case Ellipsis_kind:
return 1;
diff --git a/Python/errors.c b/Python/errors.c
index 7b25a2202c2..74283c9be33 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -62,7 +62,7 @@ _PyErr_CreateException(PyObject *exception, PyObject *value)
return PyObject_Call(exception, value, NULL);
}
else {
- return _PyObject_CallArg1(exception, value);
+ return PyObject_CallFunctionObjArgs(exception, value, NULL);
}
}
@@ -158,10 +158,10 @@ PyErr_SetString(PyObject *exception, const char *string)
}
-PyObject *
+PyObject* _Py_HOT_FUNCTION
PyErr_Occurred(void)
{
- PyThreadState *tstate = _PyThreadState_UncheckedGet();
+ PyThreadState *tstate = PyThreadState_GET();
return tstate == NULL ? NULL : tstate->curexc_type;
}
@@ -582,9 +582,7 @@ PyErr_SetFromErrnoWithFilename(PyObject *exc, const char *filename)
PyObject *
PyErr_SetFromErrnoWithUnicodeFilename(PyObject *exc, const Py_UNICODE *filename)
{
- PyObject *name = filename ?
- PyUnicode_FromUnicode(filename, wcslen(filename)) :
- NULL;
+ PyObject *name = filename ? PyUnicode_FromWideChar(filename, -1) : NULL;
PyObject *result = PyErr_SetFromErrnoWithFilenameObjects(exc, name, NULL);
Py_XDECREF(name);
return result;
@@ -691,9 +689,7 @@ PyObject *PyErr_SetExcFromWindowsErrWithUnicodeFilename(
int ierr,
const Py_UNICODE *filename)
{
- PyObject *name = filename ?
- PyUnicode_FromUnicode(filename, wcslen(filename)) :
- NULL;
+ PyObject *name = filename ? PyUnicode_FromWideChar(filename, -1) : NULL;
PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObjects(exc,
ierr,
name,
@@ -729,9 +725,7 @@ PyObject *PyErr_SetFromWindowsErrWithUnicodeFilename(
int ierr,
const Py_UNICODE *filename)
{
- PyObject *name = filename ?
- PyUnicode_FromUnicode(filename, wcslen(filename)) :
- NULL;
+ PyObject *name = filename ? PyUnicode_FromWideChar(filename, -1) : NULL;
PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObjects(
PyExc_OSError,
ierr, name, NULL);
diff --git a/Python/getargs.c b/Python/getargs.c
index 616c6eb1073..c552d0fe27a 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -74,7 +74,7 @@ static const char *converttuple(PyObject *, const char **, va_list *, int,
int *, char *, size_t, int, freelist_t *);
static const char *convertsimple(PyObject *, const char **, va_list *, int,
char *, size_t, freelist_t *);
-static Py_ssize_t convertbuffer(PyObject *, void **p, const char **);
+static Py_ssize_t convertbuffer(PyObject *, const void **p, const char **);
static int getbuffer(PyObject *, Py_buffer *, const char**);
static int vgetargskeywords(PyObject *, PyObject *,
@@ -625,7 +625,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
const char *format = *p_format;
char c = *format++;
- char *sarg;
+ const char *sarg;
switch (c) {
@@ -897,7 +897,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
}
break;
}
- count = convertbuffer(arg, p, &buf);
+ count = convertbuffer(arg, (const void **)p, &buf);
if (count < 0)
return converterr(buf, arg, msgbuf, bufsize);
if (*format == '#') {
@@ -928,7 +928,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
if (sarg == NULL)
return converterr(CONV_UNICODE,
arg, msgbuf, bufsize);
- PyBuffer_FillInfo(p, arg, sarg, len, 1, 0);
+ PyBuffer_FillInfo(p, arg, (void *)sarg, len, 1, 0);
}
else { /* any bytes-like object */
const char *buf;
@@ -943,7 +943,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
format++;
} else if (*format == '#') { /* a string or read-only bytes-like object */
/* "s#" or "z#" */
- void **p = (void **)va_arg(*p_va, char **);
+ const void **p = (const void **)va_arg(*p_va, const char **);
FETCH_SIZE;
if (c == 'z' && arg == Py_None) {
@@ -970,7 +970,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
format++;
} else {
/* "s" or "z" */
- char **p = va_arg(*p_va, char **);
+ const char **p = va_arg(*p_va, const char **);
Py_ssize_t len;
sarg = NULL;
@@ -1027,7 +1027,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
*p = PyUnicode_AsUnicodeAndSize(arg, &len);
if (*p == NULL)
RETURN_ERR_OCCURRED;
- if (Py_UNICODE_strlen(*p) != (size_t)len) {
+ if (wcslen(*p) != (size_t)len) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
RETURN_ERR_OCCURRED;
}
@@ -1074,9 +1074,14 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
(PyBytes_Check(arg) || PyByteArray_Check(arg))) {
s = arg;
Py_INCREF(s);
- if (PyObject_AsCharBuffer(s, &ptr, &size) < 0)
- return converterr("(AsCharBuffer failed)",
- arg, msgbuf, bufsize);
+ if (PyBytes_Check(arg)) {
+ size = PyBytes_GET_SIZE(s);
+ ptr = PyBytes_AS_STRING(s);
+ }
+ else {
+ size = PyByteArray_GET_SIZE(s);
+ ptr = PyByteArray_AS_STRING(s);
+ }
}
else if (PyUnicode_Check(arg)) {
/* Encode object; use default error handling */
@@ -1300,7 +1305,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
}
static Py_ssize_t
-convertbuffer(PyObject *arg, void **p, const char **errmsg)
+convertbuffer(PyObject *arg, const void **p, const char **errmsg)
{
PyBufferProcs *pb = Py_TYPE(arg)->tp_as_buffer;
Py_ssize_t count;
diff --git a/Python/import.c b/Python/import.c
index cd865a54236..aef18005e23 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1035,7 +1035,7 @@ _imp_create_builtin(PyObject *module, PyObject *spec)
{
struct _inittab *p;
PyObject *name;
- char *namestr;
+ const char *namestr;
PyObject *mod;
name = PyObject_GetAttrString(spec, "name");
@@ -1705,7 +1705,7 @@ PyImport_ReloadModule(PyObject *m)
Py_INCREF(imp);
}
- reloaded_module = _PyObject_CallMethodId(imp, &PyId_reload, "O", m);
+ reloaded_module = _PyObject_CallMethodIdObjArgs(imp, &PyId_reload, m, NULL);
Py_DECREF(imp);
return reloaded_module;
}
diff --git a/Python/importdl.c b/Python/importdl.c
index f56fa94cc42..d8656b94333 100644
--- a/Python/importdl.c
+++ b/Python/importdl.c
@@ -94,7 +94,7 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
#endif
PyObject *name_unicode = NULL, *name = NULL, *path = NULL, *m = NULL;
const char *name_buf, *hook_prefix;
- char *oldcontext;
+ const char *oldcontext;
dl_funcptr exportfunc;
PyModuleDef *def;
PyObject *(*p0)(void);
diff --git a/Python/marshal.c b/Python/marshal.c
index 87a4b240a41..d71d3c2b9db 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -1274,7 +1274,7 @@ r_object(RFILE *p)
if (n == 0 && type == TYPE_FROZENSET) {
/* call frozenset() to get the empty frozenset singleton */
- v = PyObject_CallFunction((PyObject*)&PyFrozenSet_Type, NULL);
+ v = _PyObject_CallNoArg((PyObject*)&PyFrozenSet_Type);
if (v == NULL)
break;
R_REF(v);
@@ -1649,7 +1649,7 @@ marshal_dump(PyObject *self, PyObject *args)
s = PyMarshal_WriteObjectToString(x, version);
if (s == NULL)
return NULL;
- res = _PyObject_CallMethodId(f, &PyId_write, "O", s);
+ res = _PyObject_CallMethodIdObjArgs(f, &PyId_write, s, NULL);
Py_DECREF(s);
return res;
}
diff --git a/Python/modsupport.c b/Python/modsupport.c
index aabee8fa59d..01b5dc9dda0 100644
--- a/Python/modsupport.c
+++ b/Python/modsupport.c
@@ -7,16 +7,17 @@
typedef double va_double;
static PyObject *va_build_value(const char *, va_list, int);
+static PyObject **va_build_stack(PyObject **small_stack, Py_ssize_t small_stack_len, const char *, va_list, int, Py_ssize_t*);
/* Package context -- the full module name for package imports */
-char *_Py_PackageContext = NULL;
+const char *_Py_PackageContext = NULL;
/* Helper for mkvalue() to scan the length of a format */
-static int
-countformat(const char *format, int endchar)
+static Py_ssize_t
+countformat(const char *format, char endchar)
{
- int count = 0;
+ Py_ssize_t count = 0;
int level = 0;
while (level > 0 || *format != endchar) {
switch (*format) {
@@ -28,8 +29,9 @@ countformat(const char *format, int endchar)
case '(':
case '[':
case '{':
- if (level == 0)
+ if (level == 0) {
count++;
+ }
level++;
break;
case ')':
@@ -45,8 +47,9 @@ countformat(const char *format, int endchar)
case '\t':
break;
default:
- if (level == 0)
+ if (level == 0) {
count++;
+ }
}
format++;
}
@@ -57,17 +60,18 @@ countformat(const char *format, int endchar)
/* Generic function to create a value -- the inverse of getargs() */
/* After an original idea and first implementation by Steven Miale */
-static PyObject *do_mktuple(const char**, va_list *, int, int, int);
-static PyObject *do_mklist(const char**, va_list *, int, int, int);
-static PyObject *do_mkdict(const char**, va_list *, int, int, int);
+static PyObject *do_mktuple(const char**, va_list *, char, Py_ssize_t, int);
+static int do_mkstack(PyObject **, const char**, va_list *, char, Py_ssize_t, int);
+static PyObject *do_mklist(const char**, va_list *, char, Py_ssize_t, int);
+static PyObject *do_mkdict(const char**, va_list *, char, Py_ssize_t, int);
static PyObject *do_mkvalue(const char**, va_list *, int);
static void
-do_ignore(const char **p_format, va_list *p_va, int endchar, int n, int flags)
+do_ignore(const char **p_format, va_list *p_va, char endchar, Py_ssize_t n, int flags)
{
PyObject *v;
- int i;
+ Py_ssize_t i;
assert(PyErr_Occurred());
v = PyTuple_New(n);
for (i = 0; i < n; i++) {
@@ -91,15 +95,16 @@ do_ignore(const char **p_format, va_list *p_va, int endchar, int n, int flags)
"Unmatched paren in format");
return;
}
- if (endchar)
+ if (endchar) {
++*p_format;
+ }
}
static PyObject *
-do_mkdict(const char **p_format, va_list *p_va, int endchar, int n, int flags)
+do_mkdict(const char **p_format, va_list *p_va, char endchar, Py_ssize_t n, int flags)
{
PyObject *d;
- int i;
+ Py_ssize_t i;
if (n < 0)
return NULL;
if (n % 2) {
@@ -146,10 +151,10 @@ do_mkdict(const char **p_format, va_list *p_va, int endchar, int n, int flags)
}
static PyObject *
-do_mklist(const char **p_format, va_list *p_va, int endchar, int n, int flags)
+do_mklist(const char **p_format, va_list *p_va, char endchar, Py_ssize_t n, int flags)
{
PyObject *v;
- int i;
+ Py_ssize_t i;
if (n < 0)
return NULL;
/* Note that we can't bail immediately on error as this will leak
@@ -179,11 +184,48 @@ do_mklist(const char **p_format, va_list *p_va, int endchar, int n, int flags)
return v;
}
+static int
+do_mkstack(PyObject **stack, const char **p_format, va_list *p_va,
+ char endchar, Py_ssize_t n, int flags)
+{
+ Py_ssize_t i;
+
+ if (n < 0) {
+ return -1;
+ }
+ /* Note that we can't bail immediately on error as this will leak
+ refcounts on any 'N' arguments. */
+ for (i = 0; i < n; i++) {
+ PyObject *w = do_mkvalue(p_format, p_va, flags);
+ if (w == NULL) {
+ do_ignore(p_format, p_va, endchar, n - i - 1, flags);
+ goto error;
+ }
+ stack[i] = w;
+ }
+ if (**p_format != endchar) {
+ PyErr_SetString(PyExc_SystemError,
+ "Unmatched paren in format");
+ goto error;
+ }
+ if (endchar) {
+ ++*p_format;
+ }
+ return 0;
+
+error:
+ n = i;
+ for (i=0; i < n; i++) {
+ Py_DECREF(stack[i]);
+ }
+ return -1;
+}
+
static PyObject *
-do_mktuple(const char **p_format, va_list *p_va, int endchar, int n, int flags)
+do_mktuple(const char **p_format, va_list *p_va, char endchar, Py_ssize_t n, int flags)
{
PyObject *v;
- int i;
+ Py_ssize_t i;
if (n < 0)
return NULL;
/* Note that we can't bail immediately on error as this will leak
@@ -286,8 +328,8 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags)
}
else {
if (n < 0)
- n = Py_UNICODE_strlen(u);
- v = PyUnicode_FromUnicode(u, n);
+ n = wcslen(u);
+ v = PyUnicode_FromWideChar(u, n);
}
return v;
}
@@ -465,7 +507,7 @@ static PyObject *
va_build_value(const char *format, va_list va, int flags)
{
const char *f = format;
- int n = countformat(f, '\0');
+ Py_ssize_t n = countformat(f, '\0');
va_list lva;
PyObject *retval;
@@ -485,9 +527,68 @@ va_build_value(const char *format, va_list va, int flags)
return retval;
}
+PyObject **
+_Py_VaBuildStack(PyObject **small_stack, Py_ssize_t small_stack_len,
+ const char *format, va_list va, Py_ssize_t *p_nargs)
+{
+ return va_build_stack(small_stack, small_stack_len, format, va, 0, p_nargs);
+}
+
+PyObject **
+_Py_VaBuildStack_SizeT(PyObject **small_stack, Py_ssize_t small_stack_len,
+ const char *format, va_list va, Py_ssize_t *p_nargs)
+{
+ return va_build_stack(small_stack, small_stack_len, format, va, FLAG_SIZE_T, p_nargs);
+}
+
+static PyObject **
+va_build_stack(PyObject **small_stack, Py_ssize_t small_stack_len,
+ const char *format, va_list va, int flags, Py_ssize_t *p_nargs)
+{
+ const char *f;
+ Py_ssize_t n;
+ va_list lva;
+ PyObject **stack;
+ int res;
+
+ n = countformat(format, '\0');
+ if (n < 0) {
+ *p_nargs = 0;
+ return NULL;
+ }
+
+ if (n == 0) {
+ *p_nargs = 0;
+ return small_stack;
+ }
+
+ if (n <= small_stack_len) {
+ stack = small_stack;
+ }
+ else {
+ stack = PyMem_Malloc(n * sizeof(stack[0]));
+ if (stack == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ }
+
+ va_copy(lva, va);
+ f = format;
+ res = do_mkstack(stack, &f, &lva, '\0', n, flags);
+ va_end(lva);
+
+ if (res < 0) {
+ return NULL;
+ }
+
+ *p_nargs = n;
+ return stack;
+}
+
PyObject *
-PyEval_CallFunction(PyObject *obj, const char *format, ...)
+PyEval_CallFunction(PyObject *callable, const char *format, ...)
{
va_list vargs;
PyObject *args;
@@ -501,7 +602,7 @@ PyEval_CallFunction(PyObject *obj, const char *format, ...)
if (args == NULL)
return NULL;
- res = PyEval_CallObject(obj, args);
+ res = PyEval_CallObject(callable, args);
Py_DECREF(args);
return res;
@@ -509,14 +610,14 @@ PyEval_CallFunction(PyObject *obj, const char *format, ...)
PyObject *
-PyEval_CallMethod(PyObject *obj, const char *methodname, const char *format, ...)
+PyEval_CallMethod(PyObject *obj, const char *name, const char *format, ...)
{
va_list vargs;
PyObject *meth;
PyObject *args;
PyObject *res;
- meth = PyObject_GetAttrString(obj, methodname);
+ meth = PyObject_GetAttrString(obj, name);
if (meth == NULL)
return NULL;
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index a4f7f823bc6..06030c330a0 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -193,7 +193,8 @@ add_flag(int flag, const char *envs)
static char*
get_codec_name(const char *encoding)
{
- char *name_utf8, *name_str;
+ const char *name_utf8;
+ char *name_str;
PyObject *codec, *name = NULL;
codec = _PyCodec_Lookup(encoding);
@@ -1284,8 +1285,7 @@ initstdio(void)
when import.c tries to write to stderr in verbose mode. */
encoding_attr = PyObject_GetAttrString(std, "encoding");
if (encoding_attr != NULL) {
- const char * std_encoding;
- std_encoding = PyUnicode_AsUTF8(encoding_attr);
+ const char *std_encoding = PyUnicode_AsUTF8(encoding_attr);
if (std_encoding != NULL) {
PyObject *codec_info = _PyCodec_Lookup(std_encoding);
Py_XDECREF(codec_info);
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index c881f901ab5..b862e2b361c 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -154,7 +154,7 @@ PyRun_InteractiveOneObject(FILE *fp, PyObject *filename, PyCompilerFlags *flags)
PyObject *m, *d, *v, *w, *oenc = NULL, *mod_name;
mod_ty mod;
PyArena *arena;
- char *ps1 = "", *ps2 = "", *enc = NULL;
+ const char *ps1 = "", *ps2 = "", *enc = NULL;
int errcode = 0;
_Py_IDENTIFIER(encoding);
_Py_IDENTIFIER(__main__);
@@ -511,8 +511,8 @@ PyErr_Print(void)
static void
print_error_text(PyObject *f, int offset, PyObject *text_obj)
{
- char *text;
- char *nl;
+ const char *text;
+ const char *nl;
text = PyUnicode_AsUTF8(text_obj);
if (text == NULL)
diff --git a/Python/structmember.c b/Python/structmember.c
index be2737d405e..e653d0277c1 100644
--- a/Python/structmember.c
+++ b/Python/structmember.c
@@ -249,7 +249,7 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
Py_XDECREF(oldv);
break;
case T_CHAR: {
- char *string;
+ const char *string;
Py_ssize_t len;
string = PyUnicode_AsUTF8AndSize(v, &len);
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 52034ff7fb5..9c4d9e6a1ca 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -108,7 +108,7 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o)
{
PyObject *stdout_encoding = NULL;
PyObject *encoded, *escaped_str, *repr_str, *buffer, *result;
- char *stdout_encoding_str;
+ const char *stdout_encoding_str;
int ret;
stdout_encoding = _PyObject_GetAttrId(outf, &PyId_encoding);
@@ -130,7 +130,7 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o)
buffer = _PyObject_GetAttrId(outf, &PyId_buffer);
if (buffer) {
- result = _PyObject_CallMethodId(buffer, &PyId_write, "(O)", encoded);
+ result = _PyObject_CallMethodIdObjArgs(buffer, &PyId_write, encoded, NULL);
Py_DECREF(buffer);
Py_DECREF(encoded);
if (result == NULL)
@@ -1098,7 +1098,7 @@ _PySys_GetSizeOf(PyObject *o)
Py_TYPE(o)->tp_name);
}
else {
- res = PyObject_CallFunctionObjArgs(method, NULL);
+ res = _PyObject_CallNoArg(method);
Py_DECREF(method);
}
@@ -1287,6 +1287,19 @@ a 11-tuple where the entries in the tuple are counts of:\n\
10. Number of stack pops performed by call_function()"
);
+static PyObject *
+sys_callstats(PyObject *self)
+{
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "sys.callstats() has been deprecated in Python 3.7 "
+ "and will be removed in the future", 1) < 0) {
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -1350,9 +1363,23 @@ PyDoc_STRVAR(is_finalizing_doc,
Return True if Python is exiting.");
+#ifdef ANDROID_API_LEVEL
+PyDoc_STRVAR(getandroidapilevel_doc,
+"getandroidapilevel()\n\
+\n\
+Return the build time API version of Android as an integer.");
+
+static PyObject *
+sys_getandroidapilevel(PyObject *self)
+{
+ return PyLong_FromLong(ANDROID_API_LEVEL);
+}
+#endif /* ANDROID_API_LEVEL */
+
+
static PyMethodDef sys_methods[] = {
/* Might as well keep this in alphabetic order */
- {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,
+ {"callstats", (PyCFunction)sys_callstats, METH_NOARGS,
callstats_doc},
{"_clear_type_cache", sys_clear_type_cache, METH_NOARGS,
sys_clear_type_cache__doc__},
@@ -1434,6 +1461,10 @@ static PyMethodDef sys_methods[] = {
METH_VARARGS | METH_KEYWORDS, set_asyncgen_hooks_doc},
{"get_asyncgen_hooks", sys_get_asyncgen_hooks, METH_NOARGS,
get_asyncgen_hooks_doc},
+#ifdef ANDROID_API_LEVEL
+ {"getandroidapilevel", (PyCFunction)sys_getandroidapilevel, METH_NOARGS,
+ getandroidapilevel_doc},
+#endif
{NULL, NULL} /* sentinel */
};
@@ -1547,8 +1578,9 @@ error:
Py_XDECREF(name);
Py_XDECREF(value);
/* No return value, therefore clear error state if possible */
- if (_PyThreadState_UncheckedGet())
+ if (_PyThreadState_UncheckedGet()) {
PyErr_Clear();
+ }
}
PyObject *
@@ -2293,7 +2325,7 @@ sys_pyfile_write_unicode(PyObject *unicode, PyObject *file)
if (writer == NULL)
goto error;
- result = _PyObject_CallArg1(writer, unicode);
+ result = PyObject_CallFunctionObjArgs(writer, unicode, NULL);
if (result == NULL) {
goto error;
} else {
@@ -2403,7 +2435,7 @@ sys_format(_Py_Identifier *key, FILE *fp, const char *format, va_list va)
{
PyObject *file, *message;
PyObject *error_type, *error_value, *error_traceback;
- char *utf8;
+ const char *utf8;
PyErr_Fetch(&error_type, &error_value, &error_traceback);
file = _PySys_GetObjectId(key);