Skip to content

Commit a811c38

Browse files
committed
Fix various minor errors in passing arguments to
PyArg_ParseTuple.
1 parent aac1316 commit a811c38

4 files changed

Lines changed: 27 additions & 16 deletions

File tree

‎Modules/_ctypes/callproc.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,11 +1247,11 @@ static PyObject *py_dl_open(PyObject *self, PyObject *args)
12471247

12481248
static PyObject *py_dl_close(PyObject *self, PyObject *args)
12491249
{
1250-
void * handle;
1250+
int handle;
12511251

12521252
if (!PyArg_ParseTuple(args, "i:dlclose", &handle))
12531253
return NULL;
1254-
if (dlclose(handle)) {
1254+
if (dlclose((void*)handle)) {
12551255
PyErr_SetString(PyExc_OSError,
12561256
ctypes_dlerror());
12571257
return NULL;
@@ -1263,12 +1263,12 @@ static PyObject *py_dl_close(PyObject *self, PyObject *args)
12631263
static PyObject *py_dl_sym(PyObject *self, PyObject *args)
12641264
{
12651265
char *name;
1266-
void *handle;
1266+
int handle;
12671267
void *ptr;
12681268

12691269
if (!PyArg_ParseTuple(args, "is:dlsym", &handle, &name))
12701270
return NULL;
1271-
ptr = ctypes_dlsym(handle, name);
1271+
ptr = ctypes_dlsym((void*)handle, name);
12721272
if (!ptr) {
12731273
PyErr_SetString(PyExc_OSError,
12741274
ctypes_dlerror());
@@ -1286,7 +1286,7 @@ static PyObject *py_dl_sym(PyObject *self, PyObject *args)
12861286
static PyObject *
12871287
call_function(PyObject *self, PyObject *args)
12881288
{
1289-
PPROC func;
1289+
int func;
12901290
PyObject *arguments;
12911291
PyObject *result;
12921292

@@ -1296,7 +1296,7 @@ call_function(PyObject *self, PyObject *args)
12961296
&PyTuple_Type, &arguments))
12971297
return NULL;
12981298

1299-
result = _CallProc(func,
1299+
result = _CallProc((PPROC)func,
13001300
arguments,
13011301
#ifdef MS_WIN32
13021302
NULL,
@@ -1317,7 +1317,7 @@ call_function(PyObject *self, PyObject *args)
13171317
static PyObject *
13181318
call_cdeclfunction(PyObject *self, PyObject *args)
13191319
{
1320-
PPROC func;
1320+
int func;
13211321
PyObject *arguments;
13221322
PyObject *result;
13231323

@@ -1327,7 +1327,7 @@ call_cdeclfunction(PyObject *self, PyObject *args)
13271327
&PyTuple_Type, &arguments))
13281328
return NULL;
13291329

1330-
result = _CallProc(func,
1330+
result = _CallProc((PPROC)func,
13311331
arguments,
13321332
#ifdef MS_WIN32
13331333
NULL,
@@ -1510,7 +1510,7 @@ resize(PyObject *self, PyObject *args)
15101510
#else
15111511
"On:resize",
15121512
#endif
1513-
(PyObject *)&obj, &size))
1513+
&obj, &size))
15141514
return NULL;
15151515

15161516
dict = PyObject_stgdict((PyObject *)obj);

‎Modules/_ssl.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ PySocket_ssl(PyObject *self, PyObject *args)
317317

318318
if (!PyArg_ParseTuple(args, "O!|zz:ssl",
319319
PySocketModule.Sock_Type,
320-
(PyObject*)&Sock,
320+
&Sock,
321321
&key_file, &cert_file))
322322
return NULL;
323323

‎Modules/audioop.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,12 @@ audioop_findfit(PyObject *self, PyObject *args)
472472
double aj_m1, aj_lm1;
473473
double sum_ri_2, sum_aij_2, sum_aij_ri, result, best_result, factor;
474474

475+
/* Passing a short** for an 's' argument is correct only
476+
if the string contents is aligned for interpretation
477+
as short[]. Due to the definition of PyStringObject,
478+
this is currently (Python 2.6) the case. */
475479
if ( !PyArg_ParseTuple(args, "s#s#:findfit",
476-
&cp1, &len1, &cp2, &len2) )
480+
(char**)&cp1, &len1, (char**)&cp2, &len2) )
477481
return 0;
478482
if ( len1 & 1 || len2 & 1 ) {
479483
PyErr_SetString(AudioopError, "Strings should be even-sized");
@@ -530,7 +534,7 @@ audioop_findfactor(PyObject *self, PyObject *args)
530534
double sum_ri_2, sum_aij_ri, result;
531535

532536
if ( !PyArg_ParseTuple(args, "s#s#:findfactor",
533-
&cp1, &len1, &cp2, &len2) )
537+
(char**)&cp1, &len1, (char**)&cp2, &len2) )
534538
return 0;
535539
if ( len1 & 1 || len2 & 1 ) {
536540
PyErr_SetString(AudioopError, "Strings should be even-sized");
@@ -562,7 +566,8 @@ audioop_findmax(PyObject *self, PyObject *args)
562566
double aj_m1, aj_lm1;
563567
double result, best_result;
564568

565-
if ( !PyArg_ParseTuple(args, "s#i:findmax", &cp1, &len1, &len2) )
569+
if ( !PyArg_ParseTuple(args, "s#i:findmax",
570+
(char**)&cp1, &len1, &len2) )
566571
return 0;
567572
if ( len1 & 1 ) {
568573
PyErr_SetString(AudioopError, "Strings should be even-sized");

‎Modules/dbmmodule.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,13 @@ dbm_keys(register dbmobject *dp, PyObject *unused)
208208
static PyObject *
209209
dbm_has_key(register dbmobject *dp, PyObject *args)
210210
{
211+
char *tmp_ptr;
211212
datum key, val;
212213
int tmp_size;
213214

214-
if (!PyArg_ParseTuple(args, "s#:has_key", &key.dptr, &tmp_size))
215+
if (!PyArg_ParseTuple(args, "s#:has_key", &tmp_ptr, &tmp_size))
215216
return NULL;
217+
key.dptr = tmp_ptr;
216218
key.dsize = tmp_size;
217219
check_dbmobject_open(dp);
218220
val = dbm_fetch(dp->di_dbm, key);
@@ -224,11 +226,13 @@ dbm_get(register dbmobject *dp, PyObject *args)
224226
{
225227
datum key, val;
226228
PyObject *defvalue = Py_None;
229+
char *tmp_ptr;
227230
int tmp_size;
228231

229232
if (!PyArg_ParseTuple(args, "s#|O:get",
230-
&key.dptr, &tmp_size, &defvalue))
233+
&tmp_ptr, &tmp_size, &defvalue))
231234
return NULL;
235+
key.dptr = tmp_ptr;
232236
key.dsize = tmp_size;
233237
check_dbmobject_open(dp);
234238
val = dbm_fetch(dp->di_dbm, key);
@@ -245,11 +249,13 @@ dbm_setdefault(register dbmobject *dp, PyObject *args)
245249
{
246250
datum key, val;
247251
PyObject *defvalue = NULL;
252+
char *tmp_ptr;
248253
int tmp_size;
249254

250255
if (!PyArg_ParseTuple(args, "s#|S:setdefault",
251-
&key.dptr, &tmp_size, &defvalue))
256+
&tmp_ptr, &tmp_size, &defvalue))
252257
return NULL;
258+
key.dptr = tmp_ptr;
253259
key.dsize = tmp_size;
254260
check_dbmobject_open(dp);
255261
val = dbm_fetch(dp->di_dbm, key);

0 commit comments

Comments
 (0)