FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Port SetAttrString/HasAttrString to SetAttrId/GetAttrId. · python/cpython@1c67dd9 · GitHub

Repository navigation

Commit 1c67dd9

Browse files
committed
Port SetAttrString/HasAttrString to SetAttrId/GetAttrId.
1 parent bd928fe commit 1c67dd9

12 files changed

Lines changed: 200 additions & 183 deletions

File tree

‎Modules/_cursesmodule.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,6 +2454,8 @@ update_lines_cols(void)
24542454
{
24552455
PyObject *o;
24562456
PyObject *m = PyImport_ImportModuleNoBlock("curses");
2457+
_Py_IDENTIFIER(LINES);
2458+
_Py_IDENTIFIER(COLS);
24572459

24582460
if (!m)
24592461
return 0;
@@ -2463,12 +2465,13 @@ update_lines_cols(void)
24632465
Py_DECREF(m);
24642466
return 0;
24652467
}
2466-
if (PyObject_SetAttrString(m, "LINES", o)) {
2468+
if (_PyObject_SetAttrId(m, &PyId_LINES, o)) {
24672469
Py_DECREF(m);
24682470
Py_DECREF(o);
24692471
return 0;
24702472
}
2471-
if (PyDict_SetItemString(ModDict, "LINES", o)) {
2473+
/* PyId_LINES.object will be initialized here. */
2474+
if (PyDict_SetItem(ModDict, PyId_LINES.object, o)) {
24722475
Py_DECREF(m);
24732476
Py_DECREF(o);
24742477
return 0;
@@ -2479,12 +2482,12 @@ update_lines_cols(void)
24792482
Py_DECREF(m);
24802483
return 0;
24812484
}
2482-
if (PyObject_SetAttrString(m, "COLS", o)) {
2485+
if (_PyObject_SetAttrId(m, &PyId_COLS, o)) {
24832486
Py_DECREF(m);
24842487
Py_DECREF(o);
24852488
return 0;
24862489
}
2487-
if (PyDict_SetItemString(ModDict, "COLS", o)) {
2490+
if (PyDict_SetItem(ModDict, PyId_COLS.object, o)) {
24882491
Py_DECREF(m);
24892492
Py_DECREF(o);
24902493
return 0;

‎Modules/_pickle.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4388,12 +4388,13 @@ static PyObject *
43884388
instantiate(PyObject *cls, PyObject *args)
43894389
{
43904390
PyObject *result = NULL;
4391+
_Py_IDENTIFIER(__getinitargs__);
43914392
/* Caller must assure args are a tuple. Normally, args come from
43924393
Pdata_poptuple which packs objects from the top of the stack
43934394
into a newly created tuple. */
43944395
assert(PyTuple_Check(args));
43954396
if (Py_SIZE(args) > 0 || !PyType_Check(cls) ||
4396-
PyObject_HasAttrString(cls, "__getinitargs__")) {
4397+
_PyObject_HasAttrId(cls, &PyId___getinitargs__)) {
43974398
result = PyObject_CallObject(cls, args);
43984399
}
43994400
else {
@@ -5557,6 +5558,7 @@ Unpickler_init(UnpicklerObject *self, PyObject *args, PyObject *kwds)
55575558
PyObject *fix_imports = Py_True;
55585559
char *encoding = NULL;
55595560
char *errors = NULL;
5561+
_Py_IDENTIFIER(persistent_load);
55605562

55615563
/* XXX: That is an horrible error message. But, I don't know how to do
55625564
better... */
@@ -5591,8 +5593,7 @@ Unpickler_init(UnpicklerObject *self, PyObject *args, PyObject *kwds)
55915593
if (self->fix_imports == -1)
55925594
return -1;
55935595

5594-
if (PyObject_HasAttrString((PyObject *)self, "persistent_load")) {
5595-
_Py_IDENTIFIER(persistent_load);
5596+
if (_PyObject_HasAttrId((PyObject *)self, &PyId_persistent_load)) {
55965597
self->pers_func = _PyObject_GetAttrId((PyObject *)self,
55975598
&PyId_persistent_load);
55985599
if (self->pers_func == NULL)

‎Modules/itertoolsmodule.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ tee(PyObject *self, PyObject *args)
626626
{
627627
Py_ssize_t i, n=2;
628628
PyObject *it, *iterable, *copyable, *result;
629+
_Py_IDENTIFIER(__copy__);
629630

630631
if (!PyArg_ParseTuple(args, "O|n", &iterable, &n))
631632
return NULL;
@@ -643,7 +644,7 @@ tee(PyObject *self, PyObject *args)
643644
Py_DECREF(result);
644645
return NULL;
645646
}
646-
if (!PyObject_HasAttrString(it, "__copy__")) {
647+
if (!_PyObject_HasAttrId(it, &PyId___copy__)) {
647648
copyable = tee_fromiterable(it);
648649
Py_DECREF(it);
649650
if (copyable == NULL) {
@@ -654,7 +655,6 @@ tee(PyObject *self, PyObject *args)
654655
copyable = it;
655656
PyTuple_SET_ITEM(result, 0, copyable);
656657
for (i=1 ; i<n ; i++) {
657-
_Py_IDENTIFIER(__copy__);
658658

659659
copyable = _PyObject_CallMethodId(copyable, &PyId___copy__, NULL);
660660
if (copyable == NULL) {

‎Objects/descrobject.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ property_init(PyObject *self, PyObject *args, PyObject *kwds)
13111311
in dict of the subclass instance instead,
13121312
otherwise it gets shadowed by __doc__ in the
13131313
class's dict. */
1314-
int err = PyObject_SetAttrString(self, "__doc__", get_doc);
1314+
int err = _PyObject_SetAttrId(self, &PyId___doc__, get_doc);
13151315
Py_DECREF(get_doc);
13161316
if (err < 0)
13171317
return -1;

‎Objects/dictobject.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,8 @@ dict_update_common(PyObject *self, PyObject *args, PyObject *kwds, char *methnam
13871387
result = -1;
13881388

13891389
else if (arg != NULL) {
1390-
if (PyObject_HasAttrString(arg, "keys"))
1390+
_Py_IDENTIFIER(keys);
1391+
if (_PyObject_HasAttrId(arg, &PyId_keys))
13911392
result = PyDict_Merge(self, arg, 1);
13921393
else
13931394
result = PyDict_MergeFromSeq2(self, arg, 1);
@@ -2747,7 +2748,7 @@ dictviews_or(PyObject* self, PyObject *other)
27472748
{
27482749
PyObject *result = PySet_New(self);
27492750
PyObject *tmp;
2750-
_Py_identifier(update);
2751+
_Py_IDENTIFIER(update);
27512752

27522753
if (result == NULL)
27532754
return NULL;

‎Parser/asdl_c.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ def visitModule(self, mod):
747747
static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
748748
{
749749
int i, result;
750+
_Py_IDENTIFIER(_attributes);
750751
PyObject *s, *l = PyTuple_New(num_fields);
751752
if (!l)
752753
return 0;
@@ -758,7 +759,7 @@ def visitModule(self, mod):
758759
}
759760
PyTuple_SET_ITEM(l, i, s);
760761
}
761-
result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
762+
result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0;
762763
Py_DECREF(l);
763764
return result;
764765
}
@@ -1024,7 +1025,7 @@ def visitSum(self, sum, name):
10241025
for a in sum.attributes:
10251026
self.emit("value = ast2obj_%s(o->%s);" % (a.type, a.name), 1)
10261027
self.emit("if (!value) goto failed;", 1)
1027-
self.emit('if (PyObject_SetAttrString(result, "%s", value) < 0)' % a.name, 1)
1028+
self.emit('if (_PyObject_SetAttrId(result, &PyId_%s, value) < 0)' % a.name, 1)
10281029
self.emit('goto failed;', 2)
10291030
self.emit('Py_DECREF(value);', 1)
10301031
self.func_end()
@@ -1070,7 +1071,7 @@ def emit(s, d):
10701071
value = "o->v.%s.%s" % (name, field.name)
10711072
self.set(field, value, depth)
10721073
emit("if (!value) goto failed;", 0)
1073-
emit('if (PyObject_SetAttrString(result, "%s", value) == -1)' % field.name, 0)
1074+
emit('if (_PyObject_SetAttrId(result, &PyId_%s, value) == -1)' % field.name, 0)
10741075
emit("goto failed;", 1)
10751076
emit("Py_DECREF(value);", 0)
10761077

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL