Discussion:
[Python-3000-checkins] r65676 - in python/branches/py3k/Modules: md5module.c sha1module.c
martin.v.loewis
2008-08-14 15:52:24 UTC
Permalink
Author: martin.v.loewis
Date: Thu Aug 14 17:52:23 2008
New Revision: 65676

Log:
Use s* to receive data. Fixes #3552.


Modified:
python/branches/py3k/Modules/md5module.c
python/branches/py3k/Modules/sha1module.c

Modified: python/branches/py3k/Modules/md5module.c
==============================================================================
--- python/branches/py3k/Modules/md5module.c (original)
+++ python/branches/py3k/Modules/md5module.c Thu Aug 14 17:52:23 2008
@@ -411,14 +411,14 @@
static PyObject *
MD5_update(MD5object *self, PyObject *args)
{
- unsigned char *cp;
- int len;
-
- if (!PyArg_ParseTuple(args, "s#:update", &cp, &len))
+ Py_buffer buf;
+
+ if (!PyArg_ParseTuple(args, "s*:update", &buf))
return NULL;

- md5_process(&self->hash_state, cp, len);
+ md5_process(&self->hash_state, buf.buf, buf.len);

+ PyBuffer_Release(&buf);
Py_INCREF(Py_None);
return Py_None;
}
@@ -511,11 +511,11 @@
{
static char *kwlist[] = {"string", NULL};
MD5object *new;
- unsigned char *cp = NULL;
- int len;
+ Py_buffer buf;
+ buf.buf = NULL;

- if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s#:new", kwlist,
- &cp, &len)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s*:new", kwlist,
+ &buf)) {
return NULL;
}

@@ -528,8 +528,10 @@
Py_DECREF(new);
return NULL;
}
- if (cp)
- md5_process(&new->hash_state, cp, len);
+ if (buf.buf) {
+ md5_process(&new->hash_state, buf.buf, buf.len);
+ PyBuffer_Release(&buf);
+ }

return (PyObject *)new;
}

Modified: python/branches/py3k/Modules/sha1module.c
==============================================================================
--- python/branches/py3k/Modules/sha1module.c (original)
+++ python/branches/py3k/Modules/sha1module.c Thu Aug 14 17:52:23 2008
@@ -387,14 +387,14 @@
static PyObject *
SHA1_update(SHA1object *self, PyObject *args)
{
- unsigned char *cp;
- int len;
+ Py_buffer buf;

- if (!PyArg_ParseTuple(args, "s#:update", &cp, &len))
+ if (!PyArg_ParseTuple(args, "s*:update", &buf))
return NULL;

- sha1_process(&self->hash_state, cp, len);
+ sha1_process(&self->hash_state, buf.buf, buf.len);

+ PyBuffer_Release(&buf);
Py_INCREF(Py_None);
return Py_None;
}
@@ -487,11 +487,10 @@
{
static char *kwlist[] = {"string", NULL};
SHA1object *new;
- unsigned char *cp = NULL;
- int len;
+ Py_buffer buf;

- if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s#:new", kwlist,
- &cp, &len)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s*:new", kwlist,
+ &buf)) {
return NULL;
}

@@ -504,8 +503,10 @@
Py_DECREF(new);
return NULL;
}
- if (cp)
- sha1_process(&new->hash_state, cp, len);
+ if (buf.buf) {
+ sha1_process(&new->hash_state, buf.buf, buf.len);
+ PyBuffer_Release(&buf);
+ }

return (PyObject *)new;
}

Loading...