Skip to content

Commit f0f4514

Browse files
committed
Issue python#2443: Added a new macro, Py_VA_COPY, which is equivalent to C99
va_copy, but available on all python platforms. Untabified a few unrelated files.
1 parent 3a879e8 commit f0f4514

13 files changed

Lines changed: 74 additions & 124 deletions

File tree

Include/pyport.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,4 +822,14 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
822822
#define Py_ULL(x) Py_LL(x##U)
823823
#endif
824824

825+
#ifdef VA_LIST_IS_ARRAY
826+
#define Py_VA_COPY(x, y) Py_MEMCPY((x), (y), sizeof(va_list))
827+
#else
828+
#ifdef __va_copy
829+
#define Py_VA_COPY __va_copy
830+
#else
831+
#define Py_VA_COPY(x, y) (x) = (y)
832+
#endif
833+
#endif
834+
825835
#endif /* Py_PYPORT_H */

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ Core and Builtins
583583
C-API
584584
-----
585585

586+
- Issue #2443: A new macro, `Py_VA_COPY`, copies the state of the
587+
variable argument list. `Py_VA_COPY` is equivalent to C99
588+
`va_copy`, but available on all python platforms.
589+
586590
- PySlice_GetIndicesEx now clips the step to [-PY_SSIZE_T_MAX, PY_SSIZE_T_MAX]
587591
instead of [-PY_SSIZE_T_MAX-1, PY_SSIZE_T_MAX]. This makes it safe to do
588592
"step = -step" when reversing a slice.

Modules/_elementtree.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,15 +2870,15 @@ static PyMethodDef _functions[] = {
28702870

28712871

28722872
static struct PyModuleDef _elementtreemodule = {
2873-
PyModuleDef_HEAD_INIT,
2874-
"_elementtree",
2875-
NULL,
2876-
-1,
2877-
_functions,
2878-
NULL,
2879-
NULL,
2880-
NULL,
2881-
NULL
2873+
PyModuleDef_HEAD_INIT,
2874+
"_elementtree",
2875+
NULL,
2876+
-1,
2877+
_functions,
2878+
NULL,
2879+
NULL,
2880+
NULL,
2881+
NULL
28822882
};
28832883

28842884
PyMODINIT_FUNC
@@ -2890,12 +2890,12 @@ PyInit__elementtree(void)
28902890

28912891
/* Initialize object types */
28922892
if (PyType_Ready(&TreeBuilder_Type) < 0)
2893-
return NULL;
2893+
return NULL;
28942894
if (PyType_Ready(&Element_Type) < 0)
2895-
return NULL;
2895+
return NULL;
28962896
#if defined(USE_EXPAT)
28972897
if (PyType_Ready(&XMLParser_Type) < 0)
2898-
return NULL;
2898+
return NULL;
28992899
#endif
29002900

29012901
m = PyModule_Create(&_elementtreemodule);
@@ -2905,8 +2905,8 @@ PyInit__elementtree(void)
29052905
/* The code below requires that the module gets already added
29062906
to sys.modules. */
29072907
PyDict_SetItemString(PyImport_GetModuleDict(),
2908-
_elementtreemodule.m_name,
2909-
m);
2908+
_elementtreemodule.m_name,
2909+
m);
29102910

29112911
/* python glue code */
29122912

Modules/_hashopenssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ static struct PyMethodDef EVP_functions[] = {
559559
CONSTRUCTOR_METH_DEF(sha384),
560560
CONSTRUCTOR_METH_DEF(sha512),
561561
#endif
562-
{NULL, NULL} /* Sentinel */
562+
{NULL, NULL} /* Sentinel */
563563
};
564564

565565

Objects/abstract.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,15 +2311,7 @@ objargs_mktuple(va_list va)
23112311
va_list countva;
23122312
PyObject *result, *tmp;
23132313

2314-
#ifdef VA_LIST_IS_ARRAY
2315-
memcpy(countva, va, sizeof(va_list));
2316-
#else
2317-
#ifdef __va_copy
2318-
__va_copy(countva, va);
2319-
#else
2320-
countva = va;
2321-
#endif
2322-
#endif
2314+
Py_VA_COPY(countva, va);
23232315

23242316
while (((PyObject *)va_arg(countva, PyObject *)) != NULL)
23252317
++n;

Objects/bytearrayobject.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -936,12 +936,12 @@ bytearray_repr(PyByteArrayObject *self)
936936
static PyObject *
937937
bytearray_str(PyObject *op)
938938
{
939-
if (Py_BytesWarningFlag) {
940-
if (PyErr_WarnEx(PyExc_BytesWarning,
941-
"str() on a bytearray instance", 1))
942-
return NULL;
943-
}
944-
return bytearray_repr((PyByteArrayObject*)op);
939+
if (Py_BytesWarningFlag) {
940+
if (PyErr_WarnEx(PyExc_BytesWarning,
941+
"str() on a bytearray instance", 1))
942+
return NULL;
943+
}
944+
return bytearray_repr((PyByteArrayObject*)op);
945945
}
946946

947947
static PyObject *
@@ -1458,7 +1458,7 @@ bytearray_translate(PyByteArrayObject *self, PyObject *args)
14581458
static PyObject *
14591459
bytearray_maketrans(PyObject *null, PyObject *args)
14601460
{
1461-
return _Py_bytes_maketrans(args);
1461+
return _Py_bytes_maketrans(args);
14621462
}
14631463

14641464

Objects/bytesobject.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,7 @@ PyBytes_FromFormatV(const char *format, va_list vargs)
173173
char *s;
174174
PyObject* string;
175175

176-
#ifdef VA_LIST_IS_ARRAY
177-
Py_MEMCPY(count, vargs, sizeof(va_list));
178-
#else
179-
#ifdef __va_copy
180-
__va_copy(count, vargs);
181-
#else
182-
count = vargs;
183-
#endif
184-
#endif
176+
Py_VA_COPY(count, vargs);
185177
/* step 1: figure out how large a buffer we need */
186178
for (f = format; *f; f++) {
187179
if (*f == '%') {

Objects/capsule.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -298,27 +298,27 @@ Python import mechanism to link to one another.\n\
298298

299299
PyTypeObject PyCapsule_Type = {
300300
PyVarObject_HEAD_INIT(&PyType_Type, 0)
301-
"PyCapsule", /*tp_name*/
302-
sizeof(PyCapsule), /*tp_basicsize*/
303-
0, /*tp_itemsize*/
301+
"PyCapsule", /*tp_name*/
302+
sizeof(PyCapsule), /*tp_basicsize*/
303+
0, /*tp_itemsize*/
304304
/* methods */
305305
capsule_dealloc, /*tp_dealloc*/
306-
0, /*tp_print*/
307-
0, /*tp_getattr*/
308-
0, /*tp_setattr*/
309-
0, /*tp_reserved*/
306+
0, /*tp_print*/
307+
0, /*tp_getattr*/
308+
0, /*tp_setattr*/
309+
0, /*tp_reserved*/
310310
capsule_repr, /*tp_repr*/
311-
0, /*tp_as_number*/
312-
0, /*tp_as_sequence*/
313-
0, /*tp_as_mapping*/
314-
0, /*tp_hash*/
315-
0, /*tp_call*/
316-
0, /*tp_str*/
317-
0, /*tp_getattro*/
318-
0, /*tp_setattro*/
319-
0, /*tp_as_buffer*/
320-
0, /*tp_flags*/
321-
PyCapsule_Type__doc__ /*tp_doc*/
311+
0, /*tp_as_number*/
312+
0, /*tp_as_sequence*/
313+
0, /*tp_as_mapping*/
314+
0, /*tp_hash*/
315+
0, /*tp_call*/
316+
0, /*tp_str*/
317+
0, /*tp_getattro*/
318+
0, /*tp_setattro*/
319+
0, /*tp_as_buffer*/
320+
0, /*tp_flags*/
321+
PyCapsule_Type__doc__ /*tp_doc*/
322322
};
323323

324324

Objects/memoryobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,10 @@ static PyMappingMethods memory_as_mapping = {
775775
};
776776

777777
static PySequenceMethods memory_as_sequence = {
778-
0, /* sq_length */
779-
0, /* sq_concat */
780-
0, /* sq_repeat */
781-
(ssizeargfunc)memory_item, /* sq_item */
778+
0, /* sq_length */
779+
0, /* sq_concat */
780+
0, /* sq_repeat */
781+
(ssizeargfunc)memory_item, /* sq_item */
782782
};
783783

784784
/* Buffer methods */

Objects/unicodectype.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ Py_UNICODE _PyUnicode_ToTitlecase(register Py_UNICODE ch)
6363
int delta = ctype->title;
6464

6565
if (ctype->flags & NODELTA_MASK)
66-
return delta;
66+
return delta;
6767

6868
if (delta >= 32768)
69-
delta -= 65536;
69+
delta -= 65536;
7070

7171
return ch + delta;
7272
}
@@ -114,7 +114,7 @@ int _PyUnicode_ToDecimalDigit(Py_UNICODE ch)
114114
int _PyUnicode_IsDecimalDigit(Py_UNICODE ch)
115115
{
116116
if (_PyUnicode_ToDecimalDigit(ch) < 0)
117-
return 0;
117+
return 0;
118118
return 1;
119119
}
120120

@@ -131,7 +131,7 @@ int _PyUnicode_ToDigit(Py_UNICODE ch)
131131
int _PyUnicode_IsDigit(Py_UNICODE ch)
132132
{
133133
if (_PyUnicode_ToDigit(ch) < 0)
134-
return 0;
134+
return 0;
135135
return 1;
136136
}
137137

@@ -195,9 +195,9 @@ Py_UNICODE _PyUnicode_ToUppercase(Py_UNICODE ch)
195195
const _PyUnicode_TypeRecord *ctype = gettyperecord(ch);
196196
int delta = ctype->upper;
197197
if (ctype->flags & NODELTA_MASK)
198-
return delta;
198+
return delta;
199199
if (delta >= 32768)
200-
delta -= 65536;
200+
delta -= 65536;
201201
return ch + delta;
202202
}
203203

@@ -209,9 +209,9 @@ Py_UNICODE _PyUnicode_ToLowercase(Py_UNICODE ch)
209209
const _PyUnicode_TypeRecord *ctype = gettyperecord(ch);
210210
int delta = ctype->lower;
211211
if (ctype->flags & NODELTA_MASK)
212-
return delta;
212+
return delta;
213213
if (delta >= 32768)
214-
delta -= 65536;
214+
delta -= 65536;
215215
return ch + delta;
216216
}
217217

0 commit comments

Comments
 (0)