Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 03d1b18

Browse files
committed
Enable PyOS_snprintf() et al. during alpha phase of 2.2.0 and
add another use case to the socketmodule.
1 parent 7770767 commit 03d1b18

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

Include/pyerrors.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ extern DL_IMPORT(PyObject *) PyErr_ProgramText(char *, int);
115115
# define snprintf _snprintf
116116
# define vsnprintf _vsnprintf
117117
#endif
118+
119+
/* Always enable the fallback solution during the 2.2.0 alpha cycle
120+
for enhanced testing */
121+
#if PY_VERSION_HEX < 0x020200B0
122+
# undef HAVE_SNPRINTF
123+
#endif
124+
118125
#ifndef HAVE_SNPRINTF
119126
#include <stdarg.h>
120127
extern DL_IMPORT(int) PyOS_snprintf(char *str, size_t size, const char *format, ...);

Modules/socketmodule.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,11 +2349,7 @@ PySocket_getaddrinfo(PyObject *self, PyObject *args)
23492349
return NULL;
23502350
}
23512351
if (PyInt_Check(pobj)) {
2352-
#ifndef HAVE_SNPRINTF
2353-
sprintf(pbuf, "%ld", PyInt_AsLong(pobj));
2354-
#else
2355-
snprintf(pbuf, sizeof(pbuf), "%ld", PyInt_AsLong(pobj));
2356-
#endif
2352+
PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", PyInt_AsLong(pobj));
23572353
pptr = pbuf;
23582354
} else if (PyString_Check(pobj)) {
23592355
pptr = PyString_AsString(pobj);
@@ -2424,11 +2420,7 @@ PySocket_getnameinfo(PyObject *self, PyObject *args)
24242420
n = PyArg_ParseTuple(sa, "si|ii", &hostp, &port, &flowinfo, scope_id);
24252421
if (n == 0)
24262422
goto fail;
2427-
#ifdef HAVE_SNPRINTF
2428-
snprintf(pbuf, sizeof(pbuf), "%d", port);
2429-
#else
2430-
sprintf(pbuf, "%d", port);
2431-
#endif
2423+
PyOS_snprintf(pbuf, sizeof(pbuf), "%d", port);
24322424
memset(&hints, 0, sizeof(hints));
24332425
hints.ai_family = PF_UNSPEC;
24342426
error = getaddrinfo(hostp, pbuf, &hints, &res);

0 commit comments

Comments
 (0)