Commit ebdcb50b authored by Larry Hastings's avatar Larry Hastings

Issue #19730: Argument Clinic now supports all the existing PyArg

"format units" as legacy converters, as well as two new features:
"self converters" and the "version" directive.
parent 3a907974
......@@ -188,6 +188,13 @@ typedef Py_ssize_t Py_hash_t;
#define SIZEOF_PY_UHASH_T SIZEOF_SIZE_T
typedef size_t Py_uhash_t;
/* Only used for compatibility with code that may not be PY_SSIZE_T_CLEAN. */
#ifdef PY_SSIZE_T_CLEAN
typedef Py_ssize_t Py_ssize_clean_t;
#else
typedef int Py_ssize_clean_t;
#endif
/* Largest possible value of size_t.
SIZE_MAX is part of C99, so it might be defined on some
platforms. If it is not defined, (size_t)-1 is a portable
......
......@@ -9,7 +9,6 @@ Projected release date: 2013-11-24
Core and Builtins
-----------------
- Use the repr of a module name in more places in import, especially
exceptions.
......@@ -450,6 +449,9 @@ Build
Tools/Demos
-----------
- Issue #19730: Argument Clinic now supports all the existing PyArg
"format units" as legacy converters, as well as two new features:
"self converters" and the "version" directive.
- Issue #19552: pyvenv now bootstraps pip into virtual environments by
default (pass --without-pip to request the old behaviour)
......
......@@ -4167,10 +4167,10 @@ PyDoc_STRVAR(datetime_datetime_now__doc__,
{"now", (PyCFunction)datetime_datetime_now, METH_VARARGS|METH_KEYWORDS|METH_CLASS, datetime_datetime_now__doc__},
static PyObject *
datetime_datetime_now_impl(PyObject *cls, PyObject *tz);
datetime_datetime_now_impl(PyTypeObject *cls, PyObject *tz);
static PyObject *
datetime_datetime_now(PyObject *cls, PyObject *args, PyObject *kwargs)
datetime_datetime_now(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"tz", NULL};
......@@ -4187,8 +4187,8 @@ exit:
}
static PyObject *
datetime_datetime_now_impl(PyObject *cls, PyObject *tz)
/*[clinic checksum: cde1daca68c9b7dca6df51759db2de1d43a39774]*/
datetime_datetime_now_impl(PyTypeObject *cls, PyObject *tz)
/*[clinic checksum: 5e61647d5d1feaf1ab096c5406ccea17bb7b061c]*/
{
PyObject *self;
......@@ -4198,7 +4198,7 @@ datetime_datetime_now_impl(PyObject *cls, PyObject *tz)
if (check_tzinfo_subclass(tz) < 0)
return NULL;
self = datetime_best_possible(cls,
self = datetime_best_possible((PyObject *)cls,
tz == Py_None ? localtime : gmtime,
tz);
if (self != NULL && tz != Py_None) {
......
......@@ -43,6 +43,20 @@ static PyTypeObject Dbmtype;
static PyObject *DbmError;
/*[clinic]
module dbm
class dbm.dbm
[clinic]*/
/*[clinic checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
/*[python]
class dbmobject_converter(self_converter):
type = "dbmobject *"
def converter_init(self):
self.name = 'dp'
[python]*/
/*[python checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
static PyObject *
newdbmobject(const char *file, int flags, int mode)
{
......@@ -248,27 +262,77 @@ static PySequenceMethods dbm_as_sequence = {
0, /* sq_inplace_repeat */
};
/*[clinic]
dbm.dbm.get
self: dbmobject
key: str(length=True)
[
default: object
]
/
Return the value for key if present, otherwise default.
[clinic]*/
PyDoc_STRVAR(dbm_dbm_get__doc__,
"Return the value for key if present, otherwise default.\n"
"\n"
"dbm.dbm.get(key, [default])");
#define DBM_DBM_GET_METHODDEF \
{"get", (PyCFunction)dbm_dbm_get, METH_VARARGS, dbm_dbm_get__doc__},
static PyObject *
dbm_dbm_get_impl(dbmobject *dp, const char *key, Py_ssize_clean_t key_length, int group_right_1, PyObject *default_value);
static PyObject *
dbm_get(dbmobject *dp, PyObject *args)
dbm_dbm_get(PyObject *self, PyObject *args)
{
datum key, val;
PyObject *defvalue = Py_None;
char *tmp_ptr;
Py_ssize_t tmp_size;
PyObject *return_value = NULL;
const char *key;
Py_ssize_clean_t key_length;
int group_right_1 = 0;
PyObject *default_value = NULL;
switch (PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args, "s#:get", &key, &key_length))
return NULL;
break;
case 2:
if (!PyArg_ParseTuple(args, "s#O:get", &key, &key_length, &default_value))
return NULL;
group_right_1 = 1;
break;
default:
PyErr_SetString(PyExc_TypeError, "dbm.dbm.get requires 1 to 2 arguments");
return NULL;
}
return_value = dbm_dbm_get_impl((dbmobject *)self, key, key_length, group_right_1, default_value);
if (!PyArg_ParseTuple(args, "s#|O:get",
&tmp_ptr, &tmp_size, &defvalue))
return NULL;
key.dptr = tmp_ptr;
key.dsize = tmp_size;
return return_value;
}
static PyObject *
dbm_dbm_get_impl(dbmobject *dp, const char *key, Py_ssize_clean_t key_length, int group_right_1, PyObject *default_value)
/*[clinic checksum: 5b4265e66568f163ef0fc7efec09410eaf793508]*/
{
datum dbm_key, val;
if (!group_right_1)
default_value = Py_None;
dbm_key.dptr = (char *)key;
dbm_key.dsize = key_length;
check_dbmobject_open(dp);
val = dbm_fetch(dp->di_dbm, key);
val = dbm_fetch(dp->di_dbm, dbm_key);
if (val.dptr != NULL)
return PyBytes_FromStringAndSize(val.dptr, val.dsize);
else {
Py_INCREF(defvalue);
return defvalue;
}
Py_INCREF(default_value);
return default_value;
}
static PyObject *
......@@ -333,9 +397,7 @@ static PyMethodDef dbm_methods[] = {
"close()\nClose the database."},
{"keys", (PyCFunction)dbm_keys, METH_NOARGS,
"keys() -> list\nReturn a list of all keys in the database."},
{"get", (PyCFunction)dbm_get, METH_VARARGS,
"get(key[, default]) -> value\n"
"Return the value for key if present, otherwise default."},
DBM_DBM_GET_METHODDEF
{"setdefault", (PyCFunction)dbm_setdefault, METH_VARARGS,
"setdefault(key[, default]) -> value\n"
"Return the value for key if present, otherwise default. If key\n"
......@@ -379,7 +441,6 @@ static PyTypeObject Dbmtype = {
/* ----------------------------------------------------------------- */
/*[clinic]
module dbm
dbm.open as dbmopen
......@@ -415,10 +476,10 @@ PyDoc_STRVAR(dbmopen__doc__,
{"open", (PyCFunction)dbmopen, METH_VARARGS, dbmopen__doc__},
static PyObject *
dbmopen_impl(PyObject *module, const char *filename, const char *flags, int mode);
dbmopen_impl(PyModuleDef *module, const char *filename, const char *flags, int mode);
static PyObject *
dbmopen(PyObject *module, PyObject *args)
dbmopen(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
const char *filename;
......@@ -436,8 +497,8 @@ exit:
}
static PyObject *
dbmopen_impl(PyObject *module, const char *filename, const char *flags, int mode)
/*[clinic checksum: 2b0ec9e3c6ecd19e06d16c9f0ba33848245cb1ab]*/
dbmopen_impl(PyModuleDef *module, const char *filename, const char *flags, int mode)
/*[clinic checksum: c1f2036017ec36a43ac6f59893732751e67c19d5]*/
{
int iflags;
......
......@@ -25,10 +25,10 @@ PyDoc_STRVAR(_weakref_getweakrefcount__doc__,
{"getweakrefcount", (PyCFunction)_weakref_getweakrefcount, METH_O, _weakref_getweakrefcount__doc__},
static Py_ssize_t
_weakref_getweakrefcount_impl(PyObject *module, PyObject *object);
_weakref_getweakrefcount_impl(PyModuleDef *module, PyObject *object);
static PyObject *
_weakref_getweakrefcount(PyObject *module, PyObject *object)
_weakref_getweakrefcount(PyModuleDef *module, PyObject *object)
{
PyObject *return_value = NULL;
Py_ssize_t _return_value;
......@@ -42,8 +42,8 @@ exit:
}
static Py_ssize_t
_weakref_getweakrefcount_impl(PyObject *module, PyObject *object)
/*[clinic checksum: 05cffbc3a4b193a0b7e645da81be281748704f69]*/
_weakref_getweakrefcount_impl(PyModuleDef *module, PyObject *object)
/*[clinic checksum: 015113be0c9a0a8672d35df10c63e3642cc23da4]*/
{
PyWeakReference **list;
......
......@@ -2460,10 +2460,10 @@ PyDoc_STRVAR(os_stat__doc__,
{"stat", (PyCFunction)os_stat, METH_VARARGS|METH_KEYWORDS, os_stat__doc__},
static PyObject *
os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks);
os_stat_impl(PyModuleDef *module, path_t *path, int dir_fd, int follow_symlinks);
static PyObject *
os_stat(PyObject *module, PyObject *args, PyObject *kwargs)
os_stat(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
......@@ -2485,8 +2485,8 @@ exit:
}
static PyObject *
os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks)
/*[clinic checksum: 89390f78327e3f045a81974d758d3996e2a71f68]*/
os_stat_impl(PyModuleDef *module, path_t *path, int dir_fd, int follow_symlinks)
/*[clinic checksum: b08112eff0ceab3ec2c72352da95ce73f245d104]*/
{
return posix_do_stat("stat", path, dir_fd, follow_symlinks);
}
......@@ -2600,10 +2600,10 @@ PyDoc_STRVAR(os_access__doc__,
{"access", (PyCFunction)os_access, METH_VARARGS|METH_KEYWORDS, os_access__doc__},
static PyObject *
os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd, int effective_ids, int follow_symlinks);
os_access_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd, int effective_ids, int follow_symlinks);
static PyObject *
os_access(PyObject *module, PyObject *args, PyObject *kwargs)
os_access(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
......@@ -2627,8 +2627,8 @@ exit:
}
static PyObject *
os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd, int effective_ids, int follow_symlinks)
/*[clinic checksum: aa3e145816a748172e62df8e44af74169c7e1247]*/
os_access_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd, int effective_ids, int follow_symlinks)
/*[clinic checksum: b9f8ececb061d31b64220c29526bfee642d1b602]*/
{
PyObject *return_value = NULL;
......@@ -2734,10 +2734,10 @@ PyDoc_STRVAR(os_ttyname__doc__,
{"ttyname", (PyCFunction)os_ttyname, METH_VARARGS, os_ttyname__doc__},
static char *
os_ttyname_impl(PyObject *module, int fd);
os_ttyname_impl(PyModuleDef *module, int fd);
static PyObject *
os_ttyname(PyObject *module, PyObject *args)
os_ttyname(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
int fd;
......@@ -2757,8 +2757,8 @@ exit:
}
static char *
os_ttyname_impl(PyObject *module, int fd)
/*[clinic checksum: c742dd621ec98d0f81d37d264e1d3c89c7a5fb1a]*/
os_ttyname_impl(PyModuleDef *module, int fd)
/*[clinic checksum: 61e4e525984cb293f949ccae6ae393c0011dfe8e]*/
{
char *ret;
......
......@@ -81,6 +81,13 @@ zlib_error(z_stream zst, int err, char *msg)
PyErr_Format(ZlibError, "Error %d %s: %.200s", err, msg, zmsg);
}
/*[clinic]
module zlib
class zlib.Compress
class zlib.Decompress
[clinic]*/
/*[clinic checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
PyDoc_STRVAR(compressobj__doc__,
"compressobj(level=-1, method=DEFLATED, wbits=15, memlevel=8,\n"
" strategy=Z_DEFAULT_STRATEGY[, zdict])\n"
......@@ -157,32 +164,86 @@ PyZlib_Free(voidpf ctx, void *ptr)
PyMem_RawFree(ptr);
}
PyDoc_STRVAR(compress__doc__,
"compress(string[, level]) -- Returned compressed string.\n"
/*[clinic]
zlib.compress
bytes: Py_buffer
Binary data to be compressed.
[
level: int
Compression level, in 0-9.
]
/
Returns compressed string.
[clinic]*/
PyDoc_STRVAR(zlib_compress__doc__,
"Returns compressed string.\n"
"\n"
"Optional arg level is the compression level, in 0-9.");
"zlib.compress(bytes, [level])\n"
" bytes\n"
" Binary data to be compressed.\n"
" level\n"
" Compression level, in 0-9.");
#define ZLIB_COMPRESS_METHODDEF \
{"compress", (PyCFunction)zlib_compress, METH_VARARGS, zlib_compress__doc__},
static PyObject *
PyZlib_compress(PyObject *self, PyObject *args)
zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int group_right_1, int level);
static PyObject *
zlib_compress(PyModuleDef *module, PyObject *args)
{
PyObject *return_value = NULL;
Py_buffer bytes;
int group_right_1 = 0;
int level = 0;
switch (PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args, "y*:compress", &bytes))
return NULL;
break;
case 2:
if (!PyArg_ParseTuple(args, "y*i:compress", &bytes, &level))
return NULL;
group_right_1 = 1;
break;
default:
PyErr_SetString(PyExc_TypeError, "zlib.compress requires 1 to 2 arguments");
return NULL;
}
return_value = zlib_compress_impl(module, &bytes, group_right_1, level);
/* Cleanup for bytes */
if (bytes.buf)
PyBuffer_Release(&bytes);
return return_value;
}
static PyObject *
zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int group_right_1, int level)
/*[clinic checksum: 03e857836db25448d4d572da537eb7faf7695d71]*/
{
PyObject *ReturnVal = NULL;
Py_buffer pinput;
Byte *input, *output = NULL;
unsigned int length;
int level=Z_DEFAULT_COMPRESSION, err;
int err;
z_stream zst;
/* require Python string object, optional 'level' arg */
if (!PyArg_ParseTuple(args, "y*|i:compress", &pinput, &level))
return NULL;
if (!group_right_1)
level = Z_DEFAULT_COMPRESSION;
if ((size_t)pinput.len > UINT_MAX) {
if ((size_t)bytes->len > UINT_MAX) {
PyErr_SetString(PyExc_OverflowError,
"Size does not fit in an unsigned int");
goto error;
}
input = pinput.buf;
length = (unsigned int)pinput.len;
input = bytes->buf;
length = (unsigned int)bytes->len;
zst.avail_out = length + length/1000 + 12 + 1;
......@@ -239,7 +300,6 @@ PyZlib_compress(PyObject *self, PyObject *args)
zlib_error(zst, err, "while finishing compression");
error:
PyBuffer_Release(&pinput);
PyMem_Free(output);
return ReturnVal;
......@@ -682,10 +742,6 @@ save_unconsumed_input(compobject *self, int err)
}
/*[clinic]
module zlib
class zlib.Decompress
zlib.Decompress.decompress
data: Py_buffer
......@@ -739,14 +795,15 @@ zlib_Decompress_decompress(PyObject *self, PyObject *args)
exit:
/* Cleanup for data */
PyBuffer_Release(&data);
if (data.buf)
PyBuffer_Release(&data);
return return_value;
}
static PyObject *
zlib_Decompress_decompress_impl(PyObject *self, Py_buffer *data, unsigned int max_length)
/*[clinic checksum: 76ca9259e3f5ca86bae9da3d0e75637b5d492234]*/
/*[clinic checksum: f83e91728d327462d7ccbee95299514f26b92253]*/
{
compobject *zself = (compobject *)self;
int err;
......@@ -966,8 +1023,6 @@ PyZlib_flush(compobject *self, PyObject *args)
#ifdef HAVE_ZLIB_COPY
/*[clinic]
class zlib.Compress
zlib.Compress.copy
Return a copy of the compression object.
......@@ -1295,8 +1350,7 @@ static PyMethodDef zlib_methods[] =
{
{"adler32", (PyCFunction)PyZlib_adler32, METH_VARARGS,
adler32__doc__},
{"compress", (PyCFunction)PyZlib_compress, METH_VARARGS,
compress__doc__},
ZLIB_COMPRESS_METHODDEF
{"compressobj", (PyCFunction)PyZlib_compressobj, METH_VARARGS|METH_KEYWORDS,
compressobj__doc__},
{"crc32", (PyCFunction)PyZlib_crc32, METH_VARARGS,
......
......@@ -12924,10 +12924,10 @@ PyDoc_STRVAR(unicode_maketrans__doc__,
{"maketrans", (PyCFunction)unicode_maketrans, METH_VARARGS|METH_STATIC, unicode_maketrans__doc__},
static PyObject *
unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z);
unicode_maketrans_impl(void *null, PyObject *x, PyObject *y, PyObject *z);
static PyObject *
unicode_maketrans(PyObject *null, PyObject *args)
unicode_maketrans(void *null, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *x;
......@@ -12938,15 +12938,15 @@ unicode_maketrans(PyObject *null, PyObject *args)
"O|UU:maketrans",
&x, &y, &z))
goto exit;
return_value = unicode_maketrans_impl(x, y, z);
return_value = unicode_maketrans_impl(null, x, y, z);
exit:
return return_value;
}
static PyObject *
unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z)
/*[clinic checksum: 137db9c3199e7906b7967009f511c24fa3235b5f]*/
unicode_maketrans_impl(void *null, PyObject *x, PyObject *y, PyObject *z)
/*[clinic checksum: 6d522e3aea2f2e123da3c5d367132a99d803f9b9]*/
{
PyObject *new = NULL, *key, *value;
Py_ssize_t i = 0;
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment