summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Modules/syslogmodule.c
diff options
context:
space:
mode:
authorshadchin <[email protected]>2025-06-13 00:05:26 +0300
committershadchin <[email protected]>2025-06-13 00:35:30 +0300
commit796b9088366b10b4cd42885101fc20c0b5709b07 (patch)
treef287eacb0b95ffd7cabf95b16cafb4788645dc38 /contrib/tools/python3/Modules/syslogmodule.c
parentc72bca862651e507d2ff4980ef7f4ff7267a7227 (diff)
Update Python 3 to 3.12.10
commit_hash:dd2398e159fe1d72ea6b12da52fccc933a41a785
Diffstat (limited to 'contrib/tools/python3/Modules/syslogmodule.c')
-rw-r--r--contrib/tools/python3/Modules/syslogmodule.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/contrib/tools/python3/Modules/syslogmodule.c b/contrib/tools/python3/Modules/syslogmodule.c
index c925a42dc05..55ed2426fb4 100644
--- a/contrib/tools/python3/Modules/syslogmodule.c
+++ b/contrib/tools/python3/Modules/syslogmodule.c
@@ -49,8 +49,13 @@ Revision history:
/* syslog module */
+#ifndef Py_BUILD_CORE_BUILTIN
+# define Py_BUILD_CORE_MODULE 1
+#endif
+
#include "Python.h"
#include "osdefs.h" // SEP
+#include "pycore_sysmodule.h" // _PySys_GetOptionalAttrString()
#include <syslog.h>
@@ -84,45 +89,50 @@ syslog_get_argv(void)
Py_ssize_t argv_len, scriptlen;
PyObject *scriptobj;
Py_ssize_t slash;
- PyObject *argv = PySys_GetObject("argv");
+ PyObject *argv;
- if (argv == NULL) {
- return(NULL);
+ if (_PySys_GetOptionalAttrString("argv", &argv) <= 0) {
+ return NULL;
}
argv_len = PyList_Size(argv);
if (argv_len == -1) {
PyErr_Clear();
- return(NULL);
+ Py_DECREF(argv);
+ return NULL;
}
if (argv_len == 0) {
- return(NULL);
+ Py_DECREF(argv);
+ return NULL;
}
scriptobj = PyList_GetItem(argv, 0);
+ Py_XINCREF(scriptobj);
+ Py_DECREF(argv);
if (scriptobj == NULL) {
PyErr_Clear();
return NULL;
}
if (!PyUnicode_Check(scriptobj)) {
- return(NULL);
+ Py_DECREF(scriptobj);
+ return NULL;
}
scriptlen = PyUnicode_GET_LENGTH(scriptobj);
if (scriptlen == 0) {
- return(NULL);
+ Py_DECREF(scriptobj);
+ return NULL;
}
slash = PyUnicode_FindChar(scriptobj, SEP, 0, scriptlen, -1);
if (slash == -2) {
PyErr_Clear();
+ Py_DECREF(scriptobj);
return NULL;
}
if (slash != -1) {
- return PyUnicode_Substring(scriptobj, slash + 1, scriptlen);
- } else {
- Py_INCREF(scriptobj);
- return(scriptobj);
+ Py_SETREF(scriptobj, PyUnicode_Substring(scriptobj, slash + 1, scriptlen));
}
+ return scriptobj;
}
@@ -156,6 +166,9 @@ syslog_openlog_impl(PyObject *module, PyObject *ident, long logopt,
else {
/* get sys.argv[0] or NULL if we can't for some reason */
ident = syslog_get_argv();
+ if (ident == NULL && PyErr_Occurred()) {
+ return NULL;
+ }
}
/* At this point, ident should be INCREF()ed. openlog(3) does not