Use the t# format where appropriate. Greg Stein.

This commit is contained in:
Guido van Rossum 1998-10-08 02:25:24 +00:00
parent b317f8aa0d
commit 7e48898d86
9 changed files with 34 additions and 37 deletions

View file

@ -213,7 +213,7 @@ binascii_a2b_uu(self, args)
PyObject *rv; PyObject *rv;
int ascii_len, bin_len; int ascii_len, bin_len;
if ( !PyArg_ParseTuple(args, "s#", &ascii_data, &ascii_len) ) if ( !PyArg_ParseTuple(args, "t#", &ascii_data, &ascii_len) )
return NULL; return NULL;
/* First byte: binary data length (in bytes) */ /* First byte: binary data length (in bytes) */
@ -343,7 +343,7 @@ binascii_a2b_base64(self, args)
PyObject *rv; PyObject *rv;
int ascii_len, bin_len; int ascii_len, bin_len;
if ( !PyArg_ParseTuple(args, "s#", &ascii_data, &ascii_len) ) if ( !PyArg_ParseTuple(args, "t#", &ascii_data, &ascii_len) )
return NULL; return NULL;
bin_len = ((ascii_len+3)/4)*3; /* Upper bound, corrected later */ bin_len = ((ascii_len+3)/4)*3; /* Upper bound, corrected later */
@ -457,7 +457,7 @@ binascii_a2b_hqx(self, args)
int len; int len;
int done = 0; int done = 0;
if ( !PyArg_ParseTuple(args, "s#", &ascii_data, &len) ) if ( !PyArg_ParseTuple(args, "t#", &ascii_data, &len) )
return NULL; return NULL;
/* Allocate a string that is too big (fixed later) */ /* Allocate a string that is too big (fixed later) */

View file

@ -969,13 +969,10 @@ MPZ_mpz(self, args)
mpz_clear(&mplongdigit); mpz_clear(&mplongdigit);
} }
else if (PyString_Check(objp)) { else if (PyString_Check(objp)) {
char *cp; char *cp = PyString_AS_STRING(objp);
int len; int len = PyString_GET_SIZE(objp);
MP_INT mplongdigit; MP_INT mplongdigit;
if (!PyArg_Parse(objp, "s#", &cp, &len))
return NULL;
if ((mpzp = newmpzobject()) == NULL) if ((mpzp = newmpzobject()) == NULL)
return NULL; return NULL;

View file

@ -106,7 +106,7 @@ nis_match (self, args)
int err; int err;
PyObject *res; PyObject *res;
if (!PyArg_Parse(args, "(s#s)", &key, &keylen, &map)) if (!PyArg_Parse(args, "(t#s)", &key, &keylen, &map))
return NULL; return NULL;
if ((err = yp_get_default_domain(&domain)) != 0) if ((err = yp_get_default_domain(&domain)) != 0)
return nis_error(err); return nis_error(err);

View file

@ -111,11 +111,11 @@ PyPcre_exec(self, args)
int offsets[100*2]; int offsets[100*2];
PyObject *list; PyObject *list;
if (!PyArg_ParseTuple(args, "s#|iiii", &string, &stringlen, &pos, &endpos, &options)) if (!PyArg_ParseTuple(args, "t#|iiii", &string, &stringlen, &pos, &endpos, &options))
return NULL; return NULL;
if (endpos == -1) {endpos = stringlen;} if (endpos == -1) {endpos = stringlen;}
count = pcre_exec(self->regex, self->regex_extra, count = pcre_exec(self->regex, self->regex_extra,
(char *)string, endpos, pos, options, string, endpos, pos, options,
offsets, sizeof(offsets)/sizeof(int) ); offsets, sizeof(offsets)/sizeof(int) );
/* If an error occurred during the match, and an exception was raised, /* If an error occurred during the match, and an exception was raised,
just return NULL and leave the exception alone. The most likely just return NULL and leave the exception alone. The most likely

View file

@ -612,7 +612,7 @@ posix_listdir(self, args)
WIN32_FIND_DATA FileData; WIN32_FIND_DATA FileData;
char namebuf[MAX_PATH+5]; char namebuf[MAX_PATH+5];
if (!PyArg_Parse(args, "s#", &name, &len)) if (!PyArg_Parse(args, "t#", &name, &len))
return NULL; return NULL;
if (len >= MAX_PATH) { if (len >= MAX_PATH) {
PyErr_SetString(PyExc_ValueError, "path too long"); PyErr_SetString(PyExc_ValueError, "path too long");
@ -673,7 +673,7 @@ posix_listdir(self, args)
char namebuf[MAX_PATH+5]; char namebuf[MAX_PATH+5];
struct _find_t ep; struct _find_t ep;
if (!PyArg_Parse(args, "s#", &name, &len)) if (!PyArg_Parse(args, "t#", &name, &len))
return NULL; return NULL;
if (len >= MAX_PATH) { if (len >= MAX_PATH) {
PyErr_SetString(PyExc_ValueError, "path too long"); PyErr_SetString(PyExc_ValueError, "path too long");
@ -738,7 +738,7 @@ posix_listdir(self, args)
FILEFINDBUF3 ep; FILEFINDBUF3 ep;
APIRET rc; APIRET rc;
if (!PyArg_Parse(args, "s#", &name, &len)) if (!PyArg_Parse(args, "t#", &name, &len))
return NULL; return NULL;
if (len >= MAX_PATH) { if (len >= MAX_PATH) {
PyErr_SetString(PyExc_ValueError, "path too long"); PyErr_SetString(PyExc_ValueError, "path too long");

View file

@ -121,7 +121,7 @@ regobj_match(re, args)
if (!PyArg_ParseTuple(args, "O|i", &argstring, &offset)) if (!PyArg_ParseTuple(args, "O|i", &argstring, &offset))
return NULL; return NULL;
if (!PyArg_Parse(argstring, "s#", &buffer, &size)) if (!PyArg_Parse(argstring, "t#", &buffer, &size))
return NULL; return NULL;
if (offset < 0 || offset > size) { if (offset < 0 || offset > size) {
@ -160,7 +160,7 @@ regobj_search(re, args)
if (!PyArg_ParseTuple(args, "O|i", &argstring, &offset)) if (!PyArg_ParseTuple(args, "O|i", &argstring, &offset))
return NULL; return NULL;
if (!PyArg_Parse(argstring, "s#", &buffer, &size)) if (!PyArg_Parse(argstring, "t#", &buffer, &size))
return NULL; return NULL;
if (offset < 0 || offset > size) { if (offset < 0 || offset > size) {
@ -410,7 +410,7 @@ newregexobject(pattern, translate, givenpat, groupindex)
char *pat; char *pat;
int size; int size;
if (!PyArg_Parse(pattern, "s#", &pat, &size)) if (!PyArg_Parse(pattern, "t#", &pat, &size))
return NULL; return NULL;
if (translate != NULL && PyString_Size(translate) != 256) { if (translate != NULL && PyString_Size(translate) != 256) {

View file

@ -472,7 +472,7 @@ getsockaddrarg,PySocketSockObject *,s, PyObject *,args, struct sockaddr **,addr_
char *path; char *path;
int len; int len;
addr = (struct sockaddr_un* )&(s->sock_addr).un; addr = (struct sockaddr_un* )&(s->sock_addr).un;
if (!PyArg_Parse(args, "s#", &path, &len)) if (!PyArg_Parse(args, "t#", &path, &len))
return 0; return 0;
if (len > sizeof addr->sun_path) { if (len > sizeof addr->sun_path) {
PyErr_SetString(PySocket_Error, PyErr_SetString(PySocket_Error,

View file

@ -546,7 +546,7 @@ drawing_text(dp, args)
{ {
int h, v, size; int h, v, size;
char *text; char *text;
if (!PyArg_Parse(args, "((ii)s#)", &h, &v, &text, &size)) if (!PyArg_Parse(args, "((ii)t#)", &h, &v, &text, &size))
return NULL; return NULL;
wdrawtext(h, v, text, size); wdrawtext(h, v, text, size);
Py_INCREF(Py_None); Py_INCREF(Py_None);
@ -582,7 +582,7 @@ drawing_textwidth(dp, args)
{ {
char *text; char *text;
int size; int size;
if (!PyArg_Parse(args, "s#", &text, &size)) if (!PyArg_Parse(args, "t#", &text, &size))
return NULL; return NULL;
return PyInt_FromLong((long)wtextwidth(text, size)); return PyInt_FromLong((long)wtextwidth(text, size));
} }
@ -594,7 +594,7 @@ drawing_textbreak(dp, args)
{ {
char *text; char *text;
int size, width; int size, width;
if (!PyArg_Parse(args, "(s#i)", &text, &size, &width)) if (!PyArg_Parse(args, "(t#i)", &text, &size, &width))
return NULL; return NULL;
return PyInt_FromLong((long)wtextbreak(text, size, width)); return PyInt_FromLong((long)wtextbreak(text, size, width));
} }
@ -1056,7 +1056,7 @@ text_settext(self, args)
char *text; char *text;
char *buf; char *buf;
int size; int size;
if (!PyArg_Parse(args, "s#", &text, &size)) if (!PyArg_Parse(args, "t#", &text, &size))
return NULL; return NULL;
if ((buf = PyMem_NEW(char, size)) == NULL) { if ((buf = PyMem_NEW(char, size)) == NULL) {
return PyErr_NoMemory(); return PyErr_NoMemory();
@ -1809,7 +1809,7 @@ window_setselection(self, args)
{ {
int sel, size, ok; int sel, size, ok;
char *text; char *text;
if (!PyArg_Parse(args, "(is#)", &sel, &text, &size)) if (!PyArg_Parse(args, "(it#)", &sel, &text, &size))
return NULL; return NULL;
ok = wsetselection(self->w_win, sel, text, size); ok = wsetselection(self->w_win, sel, text, size);
return PyInt_FromLong(ok); return PyInt_FromLong(ok);
@ -2320,7 +2320,7 @@ stdwin_setcutbuffer(self, args)
{ {
int i, size; int i, size;
char *str; char *str;
if (!PyArg_Parse(args, "(is#)", &i, &str, &size)) if (!PyArg_Parse(args, "(it#)", &i, &str, &size))
return NULL; return NULL;
wsetcutbuffer(i, str, size); wsetcutbuffer(i, str, size);
Py_INCREF(Py_None); Py_INCREF(Py_None);

View file

@ -141,7 +141,7 @@ strop_splitfields(self, args)
n = 0; n = 0;
splitcount = 0; splitcount = 0;
maxsplit = 0; maxsplit = 0;
if (!PyArg_ParseTuple(args, "s#|z#i", &s, &len, &sub, &n, &maxsplit)) if (!PyArg_ParseTuple(args, "t#|z#i", &s, &len, &sub, &n, &maxsplit))
return NULL; return NULL;
if (sub == NULL) if (sub == NULL)
return split_whitespace(s, len, maxsplit); return split_whitespace(s, len, maxsplit);
@ -211,7 +211,7 @@ strop_joinfields(self, args)
char* p = NULL; char* p = NULL;
intargfunc getitemfunc; intargfunc getitemfunc;
if (!PyArg_ParseTuple(args, "O|s#", &seq, &sep, &seplen)) if (!PyArg_ParseTuple(args, "O|t#", &seq, &sep, &seplen))
return NULL; return NULL;
if (sep == NULL) { if (sep == NULL) {
sep = " "; sep = " ";
@ -337,7 +337,7 @@ strop_find(self, args)
char *s, *sub; char *s, *sub;
int len, n, i = 0, last = INT_MAX; int len, n, i = 0, last = INT_MAX;
if (!PyArg_ParseTuple(args, "s#s#|ii", &s, &len, &sub, &n, &i, &last)) if (!PyArg_ParseTuple(args, "t#t#|ii", &s, &len, &sub, &n, &i, &last))
return NULL; return NULL;
if (last > len) if (last > len)
@ -382,7 +382,7 @@ strop_rfind(self, args)
int len, n, j; int len, n, j;
int i = 0, last = INT_MAX; int i = 0, last = INT_MAX;
if (!PyArg_ParseTuple(args, "s#s#|ii", &s, &len, &sub, &n, &i, &last)) if (!PyArg_ParseTuple(args, "t#t#|ii", &s, &len, &sub, &n, &i, &last))
return NULL; return NULL;
if (last > len) if (last > len)
@ -417,7 +417,7 @@ do_strip(args, striptype)
int len, i, j; int len, i, j;
if (!PyArg_Parse(args, "s#", &s, &len)) if (!PyArg_Parse(args, "t#", &s, &len))
return NULL; return NULL;
i = 0; i = 0;
@ -502,7 +502,7 @@ strop_lower(self, args)
PyObject *new; PyObject *new;
int changed; int changed;
if (!PyArg_Parse(args, "s#", &s, &n)) if (!PyArg_Parse(args, "t#", &s, &n))
return NULL; return NULL;
new = PyString_FromStringAndSize(NULL, n); new = PyString_FromStringAndSize(NULL, n);
if (new == NULL) if (new == NULL)
@ -542,7 +542,7 @@ strop_upper(self, args)
PyObject *new; PyObject *new;
int changed; int changed;
if (!PyArg_Parse(args, "s#", &s, &n)) if (!PyArg_Parse(args, "t#", &s, &n))
return NULL; return NULL;
new = PyString_FromStringAndSize(NULL, n); new = PyString_FromStringAndSize(NULL, n);
if (new == NULL) if (new == NULL)
@ -583,7 +583,7 @@ strop_capitalize(self, args)
PyObject *new; PyObject *new;
int changed; int changed;
if (!PyArg_Parse(args, "s#", &s, &n)) if (!PyArg_Parse(args, "t#", &s, &n))
return NULL; return NULL;
new = PyString_FromStringAndSize(NULL, n); new = PyString_FromStringAndSize(NULL, n);
if (new == NULL) if (new == NULL)
@ -634,7 +634,7 @@ strop_count(self, args)
int i = 0, last = INT_MAX; int i = 0, last = INT_MAX;
int m, r; int m, r;
if (!PyArg_ParseTuple(args, "s#s#|ii", &s, &len, &sub, &n, &i, &last)) if (!PyArg_ParseTuple(args, "t#t#|ii", &s, &len, &sub, &n, &i, &last))
return NULL; return NULL;
if (last > len) if (last > len)
last = len; last = len;
@ -679,7 +679,7 @@ strop_swapcase(self, args)
PyObject *new; PyObject *new;
int changed; int changed;
if (!PyArg_Parse(args, "s#", &s, &n)) if (!PyArg_Parse(args, "t#", &s, &n))
return NULL; return NULL;
new = PyString_FromStringAndSize(NULL, n); new = PyString_FromStringAndSize(NULL, n);
if (new == NULL) if (new == NULL)
@ -877,7 +877,7 @@ strop_maketrans(self, args)
int i, fromlen=0, tolen=0; int i, fromlen=0, tolen=0;
PyObject *result; PyObject *result;
if (!PyArg_ParseTuple(args, "s#s#", &from, &fromlen, &to, &tolen)) if (!PyArg_ParseTuple(args, "t#t#", &from, &fromlen, &to, &tolen))
return NULL; return NULL;
if (fromlen != tolen) { if (fromlen != tolen) {
@ -920,7 +920,7 @@ strop_translate(self, args)
PyObject *result; PyObject *result;
int trans_table[256]; int trans_table[256];
if (!PyArg_ParseTuple(args, "Ss#|s#", &input_obj, if (!PyArg_ParseTuple(args, "St#|t#", &input_obj,
&table1, &tablen, &del_table, &dellen)) &table1, &tablen, &del_table, &dellen))
return NULL; return NULL;
if (tablen != 256) { if (tablen != 256) {
@ -1134,7 +1134,7 @@ strop_replace(self, args)
int count = 0; int count = 0;
PyObject *new; PyObject *new;
if (!PyArg_ParseTuple(args, "s#s#s#|i", if (!PyArg_ParseTuple(args, "t#t#t#|i",
&str, &len, &pat, &pat_len, &sub, &sub_len, &str, &len, &pat, &pat_len, &sub, &sub_len,
&count)) &count))
return NULL; return NULL;