mirror of
https://github.com/python/cpython.git
synced 2025-11-26 13:22:51 +00:00
Port SetAttrString/HasAttrString to SetAttrId/GetAttrId.
This commit is contained in:
parent
bd928fef42
commit
1c67dd9b15
12 changed files with 200 additions and 183 deletions
|
|
@ -654,8 +654,9 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
|
|||
return NULL;
|
||||
|
||||
if (module_globals) {
|
||||
static PyObject *get_source_name = NULL;
|
||||
static PyObject *splitlines_name = NULL;
|
||||
_Py_IDENTIFIER(get_source);
|
||||
_Py_IDENTIFIER(splitlines);
|
||||
PyObject *tmp;
|
||||
PyObject *loader;
|
||||
PyObject *module_name;
|
||||
PyObject *source;
|
||||
|
|
@ -663,16 +664,12 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
|
|||
PyObject *source_line;
|
||||
PyObject *returned;
|
||||
|
||||
if (get_source_name == NULL) {
|
||||
get_source_name = PyUnicode_InternFromString("get_source");
|
||||
if (!get_source_name)
|
||||
return NULL;
|
||||
}
|
||||
if (splitlines_name == NULL) {
|
||||
splitlines_name = PyUnicode_InternFromString("splitlines");
|
||||
if (!splitlines_name)
|
||||
return NULL;
|
||||
}
|
||||
if ((tmp = _PyUnicode_FromId(&PyId_get_source)) == NULL)
|
||||
return NULL;
|
||||
Py_DECREF(tmp);
|
||||
if ((tmp = _PyUnicode_FromId(&PyId_splitlines)) == NULL)
|
||||
return NULL;
|
||||
Py_DECREF(tmp);
|
||||
|
||||
/* Check/get the requisite pieces needed for the loader. */
|
||||
loader = PyDict_GetItemString(module_globals, "__loader__");
|
||||
|
|
@ -682,11 +679,11 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
|
|||
goto standard_call;
|
||||
|
||||
/* Make sure the loader implements the optional get_source() method. */
|
||||
if (!PyObject_HasAttrString(loader, "get_source"))
|
||||
if (!_PyObject_HasAttrId(loader, &PyId_get_source))
|
||||
goto standard_call;
|
||||
/* Call get_source() to get the source code. */
|
||||
source = PyObject_CallMethodObjArgs(loader, get_source_name,
|
||||
module_name, NULL);
|
||||
source = PyObject_CallMethodObjArgs(loader, PyId_get_source.object,
|
||||
module_name, NULL);
|
||||
if (!source)
|
||||
return NULL;
|
||||
else if (source == Py_None) {
|
||||
|
|
@ -695,8 +692,9 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
|
|||
}
|
||||
|
||||
/* Split the source into lines. */
|
||||
source_list = PyObject_CallMethodObjArgs(source, splitlines_name,
|
||||
NULL);
|
||||
source_list = PyObject_CallMethodObjArgs(source,
|
||||
PyId_splitlines.object,
|
||||
NULL);
|
||||
Py_DECREF(source);
|
||||
if (!source_list)
|
||||
return NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue