Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1089bdc

Browse files
authored
gh-99300: Use Py_NewRef() in Doc/ directory (#99480)
Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() andPy_XNewRef() in test C files of the Doc/ directory.Replace PyModule_AddObject() with PyModule_AddObjectRef() to simplifyreference counting.
1 parent65dd745 commit1089bdc

File tree

3 files changed

+15
-33
lines changed

3 files changed

+15
-33
lines changed

‎Doc/includes/custom2.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ Custom_init(CustomObject *self, PyObject *args, PyObject *kwds)
5151

5252
if (first) {
5353
tmp=self->first;
54-
Py_INCREF(first);
55-
self->first=first;
54+
self->first=Py_NewRef(first);
5655
Py_XDECREF(tmp);
5756
}
5857
if (last) {
5958
tmp=self->last;
60-
Py_INCREF(last);
61-
self->last=last;
59+
self->last=Py_NewRef(last);
6260
Py_XDECREF(tmp);
6361
}
6462
return0;
@@ -127,9 +125,7 @@ PyInit_custom2(void)
127125
if (m==NULL)
128126
returnNULL;
129127

130-
Py_INCREF(&CustomType);
131-
if (PyModule_AddObject(m,"Custom", (PyObject*)&CustomType)<0) {
132-
Py_DECREF(&CustomType);
128+
if (PyModule_AddObjectRef(m,"Custom", (PyObject*)&CustomType)<0) {
133129
Py_DECREF(m);
134130
returnNULL;
135131
}

‎Doc/includes/custom3.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ Custom_init(CustomObject *self, PyObject *args, PyObject *kwds)
5151

5252
if (first) {
5353
tmp=self->first;
54-
Py_INCREF(first);
55-
self->first=first;
54+
self->first=Py_NewRef(first);
5655
Py_DECREF(tmp);
5756
}
5857
if (last) {
5958
tmp=self->last;
60-
Py_INCREF(last);
61-
self->last=last;
59+
self->last=Py_NewRef(last);
6260
Py_DECREF(tmp);
6361
}
6462
return0;
@@ -73,8 +71,7 @@ static PyMemberDef Custom_members[] = {
7371
staticPyObject*
7472
Custom_getfirst(CustomObject*self,void*closure)
7573
{
76-
Py_INCREF(self->first);
77-
returnself->first;
74+
returnPy_NewRef(self->first);
7875
}
7976

8077
staticint
@@ -91,17 +88,15 @@ Custom_setfirst(CustomObject *self, PyObject *value, void *closure)
9188
return-1;
9289
}
9390
tmp=self->first;
94-
Py_INCREF(value);
95-
self->first=value;
91+
self->first=Py_NewRef(value);
9692
Py_DECREF(tmp);
9793
return0;
9894
}
9995

10096
staticPyObject*
10197
Custom_getlast(CustomObject*self,void*closure)
10298
{
103-
Py_INCREF(self->last);
104-
returnself->last;
99+
returnPy_NewRef(self->last);
105100
}
106101

107102
staticint
@@ -118,8 +113,7 @@ Custom_setlast(CustomObject *self, PyObject *value, void *closure)
118113
return-1;
119114
}
120115
tmp=self->last;
121-
Py_INCREF(value);
122-
self->last=value;
116+
self->last=Py_NewRef(value);
123117
Py_DECREF(tmp);
124118
return0;
125119
}
@@ -178,9 +172,7 @@ PyInit_custom3(void)
178172
if (m==NULL)
179173
returnNULL;
180174

181-
Py_INCREF(&CustomType);
182-
if (PyModule_AddObject(m,"Custom", (PyObject*)&CustomType)<0) {
183-
Py_DECREF(&CustomType);
175+
if (PyModule_AddObjectRef(m,"Custom", (PyObject*)&CustomType)<0) {
184176
Py_DECREF(m);
185177
returnNULL;
186178
}

‎Doc/includes/custom4.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,12 @@ Custom_init(CustomObject *self, PyObject *args, PyObject *kwds)
6767

6868
if (first) {
6969
tmp=self->first;
70-
Py_INCREF(first);
71-
self->first=first;
70+
self->first=Py_NewRef(first);
7271
Py_DECREF(tmp);
7372
}
7473
if (last) {
7574
tmp=self->last;
76-
Py_INCREF(last);
77-
self->last=last;
75+
self->last=Py_NewRef(last);
7876
Py_DECREF(tmp);
7977
}
8078
return0;
@@ -89,8 +87,7 @@ static PyMemberDef Custom_members[] = {
8987
staticPyObject*
9088
Custom_getfirst(CustomObject*self,void*closure)
9189
{
92-
Py_INCREF(self->first);
93-
returnself->first;
90+
returnPy_NewRef(self->first);
9491
}
9592

9693
staticint
@@ -114,8 +111,7 @@ Custom_setfirst(CustomObject *self, PyObject *value, void *closure)
114111
staticPyObject*
115112
Custom_getlast(CustomObject*self,void*closure)
116113
{
117-
Py_INCREF(self->last);
118-
returnself->last;
114+
returnPy_NewRef(self->last);
119115
}
120116

121117
staticint
@@ -192,9 +188,7 @@ PyInit_custom4(void)
192188
if (m==NULL)
193189
returnNULL;
194190

195-
Py_INCREF(&CustomType);
196-
if (PyModule_AddObject(m,"Custom", (PyObject*)&CustomType)<0) {
197-
Py_DECREF(&CustomType);
191+
if (PyModule_AddObjectRef(m,"Custom", (PyObject*)&CustomType)<0) {
198192
Py_DECREF(m);
199193
returnNULL;
200194
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp