[Python-checkins] cpython: Avoid calling functions with an empty string as format string
victor.stinner
python-checkins at python.org
Tue Sep 6 00:46:33 EDT 2016
https://hg.python.org/cpython/rev/8ee4ed577c03
changeset: 103113:8ee4ed577c03
user: Victor Stinner <victor.stinner at gmail.com>
date: Mon Sep 05 18:16:01 2016 -0700
summary:
Avoid calling functions with an empty string as format string
Directly pass NULL rather than an empty string.
files:
Modules/_cursesmodule.c | 2 +-
Modules/_elementtree.c | 2 +-
Modules/_sqlite/connection.c | 16 ++++++++--------
Modules/_sqlite/cursor.c | 2 +-
Modules/_sqlite/module.c | 2 +-
Modules/_testcapimodule.c | 4 ++--
Modules/faulthandler.c | 6 +++---
Objects/genobject.c | 2 +-
Objects/weakrefobject.c | 2 +-
Python/bltinmodule.c | 12 ++++++------
Python/pylifecycle.c | 10 +++++-----
Python/pythonrun.c | 4 ++--
Python/traceback.c | 4 ++--
13 files changed, 34 insertions(+), 34 deletions(-)
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -2306,7 +2306,7 @@
goto error;
}
- data = _PyObject_CallMethodId(stream, &PyId_read, "");
+ data = _PyObject_CallMethodId(stream, &PyId_read, NULL);
if (data == NULL)
goto error;
if (!PyBytes_Check(data)) {
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -3399,7 +3399,7 @@
}
else if (self->handle_close) {
Py_DECREF(res);
- return PyObject_CallFunction(self->handle_close, "");
+ return _PyObject_CallNoArg(self->handle_close);
}
else {
return res;
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -672,7 +672,7 @@
aggregate_instance = (PyObject**)sqlite3_aggregate_context(context, sizeof(PyObject*));
if (*aggregate_instance == 0) {
- *aggregate_instance = PyObject_CallFunction(aggregate_class, "");
+ *aggregate_instance = PyObject_CallFunction(aggregate_class, NULL);
if (PyErr_Occurred()) {
*aggregate_instance = 0;
@@ -744,7 +744,7 @@
PyErr_Fetch(&exception, &value, &tb);
restore = 1;
- function_result = _PyObject_CallMethodId(*aggregate_instance, &PyId_finalize, "");
+ function_result = _PyObject_CallMethodId(*aggregate_instance, &PyId_finalize, NULL);
Py_DECREF(*aggregate_instance);
@@ -960,7 +960,7 @@
gilstate = PyGILState_Ensure();
#endif
- ret = PyObject_CallFunction((PyObject*)user_arg, "");
+ ret = PyObject_CallFunction((PyObject*)user_arg, NULL);
if (!ret) {
if (_enable_callback_tracebacks) {
@@ -1291,7 +1291,7 @@
PyObject* result = 0;
PyObject* method = 0;
- cursor = _PyObject_CallMethodId((PyObject*)self, &PyId_cursor, "");
+ cursor = _PyObject_CallMethodId((PyObject*)self, &PyId_cursor, NULL);
if (!cursor) {
goto error;
}
@@ -1320,7 +1320,7 @@
PyObject* result = 0;
PyObject* method = 0;
- cursor = _PyObject_CallMethodId((PyObject*)self, &PyId_cursor, "");
+ cursor = _PyObject_CallMethodId((PyObject*)self, &PyId_cursor, NULL);
if (!cursor) {
goto error;
}
@@ -1349,7 +1349,7 @@
PyObject* result = 0;
PyObject* method = 0;
- cursor = _PyObject_CallMethodId((PyObject*)self, &PyId_cursor, "");
+ cursor = _PyObject_CallMethodId((PyObject*)self, &PyId_cursor, NULL);
if (!cursor) {
goto error;
}
@@ -1519,7 +1519,7 @@
goto finally;
}
- uppercase_name = _PyObject_CallMethodId(name, &PyId_upper, "");
+ uppercase_name = _PyObject_CallMethodId(name, &PyId_upper, NULL);
if (!uppercase_name) {
goto finally;
}
@@ -1611,7 +1611,7 @@
method_name = "rollback";
}
- result = PyObject_CallMethod((PyObject*)self, method_name, "");
+ result = PyObject_CallMethod((PyObject*)self, method_name, NULL);
if (!result) {
return NULL;
}
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -143,7 +143,7 @@
PyObject* retval;
_Py_IDENTIFIER(upper);
- upcase_key = _PyObject_CallMethodId(key, &PyId_upper, "");
+ upcase_key = _PyObject_CallMethodId(key, &PyId_upper, NULL);
if (!upcase_key) {
return NULL;
}
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
--- a/Modules/_sqlite/module.c
+++ b/Modules/_sqlite/module.c
@@ -192,7 +192,7 @@
}
/* convert the name to upper case */
- name = _PyObject_CallMethodId(orig_name, &PyId_upper, "");
+ name = _PyObject_CallMethodId(orig_name, &PyId_upper, NULL);
if (!name) {
goto error;
}
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -2137,7 +2137,7 @@
PyObject *rc;
int success;
PyGILState_STATE s = PyGILState_Ensure();
- rc = PyObject_CallFunction((PyObject *)callable, "");
+ rc = _PyObject_CallNoArg((PyObject *)callable);
success = (rc != NULL);
Py_XDECREF(rc);
PyGILState_Release(s);
@@ -3406,7 +3406,7 @@
/* Allocate a Python thread state for this thread */
state = PyGILState_Ensure();
- res = PyObject_CallFunction(test_c_thread->callback, "", NULL);
+ res = _PyObject_CallNoArg(test_c_thread->callback);
Py_CLEAR(test_c_thread->callback);
if (res == NULL) {
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -168,7 +168,7 @@
return fd;
}
- result = _PyObject_CallMethodId(file, &PyId_fileno, "");
+ result = _PyObject_CallMethodId(file, &PyId_fileno, NULL);
if (result == NULL)
return -1;
@@ -186,7 +186,7 @@
return -1;
}
- result = _PyObject_CallMethodId(file, &PyId_flush, "");
+ result = _PyObject_CallMethodId(file, &PyId_flush, NULL);
if (result != NULL)
Py_DECREF(result);
else {
@@ -1290,7 +1290,7 @@
if (module == NULL) {
return -1;
}
- res = _PyObject_CallMethodId(module, &PyId_enable, "");
+ res = _PyObject_CallMethodId(module, &PyId_enable, NULL);
Py_DECREF(module);
if (res == NULL)
return -1;
diff --git a/Objects/genobject.c b/Objects/genobject.c
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -261,7 +261,7 @@
PyErr_WriteUnraisable(yf);
PyErr_Clear();
} else {
- retval = PyObject_CallFunction(meth, "");
+ retval = _PyObject_CallNoArg(meth);
Py_DECREF(meth);
if (retval == NULL)
return -1;
diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c
--- a/Objects/weakrefobject.c
+++ b/Objects/weakrefobject.c
@@ -453,7 +453,7 @@
method(PyObject *proxy) { \
_Py_IDENTIFIER(special); \
UNWRAP(proxy); \
- return _PyObject_CallMethodId(proxy, &PyId_##special, ""); \
+ return _PyObject_CallMethodId(proxy, &PyId_##special, NULL); \
}
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1784,7 +1784,7 @@
if (do_flush == -1)
return NULL;
else if (do_flush) {
- tmp = _PyObject_CallMethodId(file, &PyId_flush, "");
+ tmp = _PyObject_CallMethodId(file, &PyId_flush, NULL);
if (tmp == NULL)
return NULL;
else
@@ -1850,7 +1850,7 @@
}
/* First of all, flush stderr */
- tmp = _PyObject_CallMethodId(ferr, &PyId_flush, "");
+ tmp = _PyObject_CallMethodId(ferr, &PyId_flush, NULL);
if (tmp == NULL)
PyErr_Clear();
else
@@ -1859,7 +1859,7 @@
/* We should only use (GNU) readline if Python's sys.stdin and
sys.stdout are the same as C's stdin and stdout, because we
need to pass it those. */
- tmp = _PyObject_CallMethodId(fin, &PyId_fileno, "");
+ tmp = _PyObject_CallMethodId(fin, &PyId_fileno, NULL);
if (tmp == NULL) {
PyErr_Clear();
tty = 0;
@@ -1872,7 +1872,7 @@
tty = fd == fileno(stdin) && isatty(fd);
}
if (tty) {
- tmp = _PyObject_CallMethodId(fout, &PyId_fileno, "");
+ tmp = _PyObject_CallMethodId(fout, &PyId_fileno, NULL);
if (tmp == NULL) {
PyErr_Clear();
tty = 0;
@@ -1907,7 +1907,7 @@
stdin_errors_str = _PyUnicode_AsString(stdin_errors);
if (!stdin_encoding_str || !stdin_errors_str)
goto _readline_errors;
- tmp = _PyObject_CallMethodId(fout, &PyId_flush, "");
+ tmp = _PyObject_CallMethodId(fout, &PyId_flush, NULL);
if (tmp == NULL)
PyErr_Clear();
else
@@ -1987,7 +1987,7 @@
if (PyFile_WriteObject(prompt, fout, Py_PRINT_RAW) != 0)
return NULL;
}
- tmp = _PyObject_CallMethodId(fout, &PyId_flush, "");
+ tmp = _PyObject_CallMethodId(fout, &PyId_flush, NULL);
if (tmp == NULL)
PyErr_Clear();
else
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -493,7 +493,7 @@
int status = 0;
if (fout != NULL && fout != Py_None && !file_is_closed(fout)) {
- tmp = _PyObject_CallMethodId(fout, &PyId_flush, "");
+ tmp = _PyObject_CallMethodId(fout, &PyId_flush, NULL);
if (tmp == NULL) {
PyErr_WriteUnraisable(fout);
status = -1;
@@ -503,7 +503,7 @@
}
if (ferr != NULL && ferr != Py_None && !file_is_closed(ferr)) {
- tmp = _PyObject_CallMethodId(ferr, &PyId_flush, "");
+ tmp = _PyObject_CallMethodId(ferr, &PyId_flush, NULL);
if (tmp == NULL) {
PyErr_Clear();
status = -1;
@@ -1072,7 +1072,7 @@
text = PyUnicode_FromString(name);
if (text == NULL || _PyObject_SetAttrId(raw, &PyId_name, text) < 0)
goto error;
- res = _PyObject_CallMethodId(raw, &PyId_isatty, "");
+ res = _PyObject_CallMethodId(raw, &PyId_isatty, NULL);
if (res == NULL)
goto error;
isatty = PyObject_IsTrue(res);
@@ -1343,7 +1343,7 @@
Py_XDECREF(tb);
/* sys.stderr may be buffered: call sys.stderr.flush() */
- res = _PyObject_CallMethodId(ferr, &PyId_flush, "");
+ res = _PyObject_CallMethodId(ferr, &PyId_flush, NULL);
if (res == NULL)
PyErr_Clear();
else
@@ -1453,7 +1453,7 @@
PyErr_Clear();
return;
}
- result = _PyObject_CallMethodId(threading, &PyId__shutdown, "");
+ result = _PyObject_CallMethodId(threading, &PyId__shutdown, NULL);
if (result == NULL) {
PyErr_WriteUnraisable(threading);
}
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -950,7 +950,7 @@
f = _PySys_GetObjectId(&PyId_stderr);
if (f != NULL) {
- r = _PyObject_CallMethodId(f, &PyId_flush, "");
+ r = _PyObject_CallMethodId(f, &PyId_flush, NULL);
if (r)
Py_DECREF(r);
else
@@ -958,7 +958,7 @@
}
f = _PySys_GetObjectId(&PyId_stdout);
if (f != NULL) {
- r = _PyObject_CallMethodId(f, &PyId_flush, "");
+ r = _PyObject_CallMethodId(f, &PyId_flush, NULL);
if (r)
Py_DECREF(r);
else
diff --git a/Python/traceback.c b/Python/traceback.c
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -314,7 +314,7 @@
if (fob == NULL) {
PyErr_Clear();
- res = _PyObject_CallMethodId(binary, &PyId_close, "");
+ res = _PyObject_CallMethodId(binary, &PyId_close, NULL);
Py_DECREF(binary);
if (res)
Py_DECREF(res);
@@ -334,7 +334,7 @@
break;
}
}
- res = _PyObject_CallMethodId(fob, &PyId_close, "");
+ res = _PyObject_CallMethodId(fob, &PyId_close, NULL);
if (res)
Py_DECREF(res);
else
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list