Author: Armin Rigo <[email protected]>
Branch:
Changeset: r154:47c327664396
Date: 2014-12-04 22:49 +0100
http://bitbucket.org/cffi/creflect/changeset/47c327664396/
Log: functions with '...'
diff --git a/zeffir/builder.c b/zeffir/builder.c
--- a/zeffir/builder.c
+++ b/zeffir/builder.c
@@ -153,9 +153,9 @@
return _zef_primitive(cb, sz, name, flags);
}
-static _crx_type_t *zef_get_function_type(_crx_builder_t *cb, _crx_type_t *ret,
- _crx_qual_type args[], int nargs,
- _crx_trampoline1_fn trampl)
+static _crx_type_t *_zef_function(_crx_builder_t *cb, _crx_type_t *ret,
+ _crx_qual_type args[], int nargs,
+ int dotdotdot)
{
if (PyErr_Occurred())
return NULL;
@@ -163,8 +163,9 @@
PyObject *name_obj;
CTypeDescrObject *ct;
size_t extra_len;
+ int nargsall = nargs + dotdotdot;
- if (nargs == 0) {
+ if (nargsall == 0) {
name_obj = combine_type_name(ret, "(void)");
if (name_obj == NULL)
return NULL;
@@ -173,10 +174,12 @@
char *p;
int i;
extra_len = 1 + 1; /* "(" ")" */
- extra_len += (nargs - 1) * 2; /* ", " */
+ extra_len += (nargsall - 1) * 2; /* ", " */
for (i = 0; i < nargs; i++) {
extra_len += strlen(args[i].type->ct_name);
}
+ if (dotdotdot)
+ extra_len += 3; /* "..." */
name_obj = combine_type_name_l(ret, extra_len);
if (name_obj == NULL)
return NULL;
@@ -192,6 +195,14 @@
memcpy(p, args[i].type->ct_name, len);
p += len;
}
+ if (dotdotdot) {
+ if (nargs > 0) {
+ *p++ = ',';
+ *p++ = ' ';
+ }
+ memcpy(p, "...", 3);
+ p += 3;
+ }
*p++ = ')';
assert(p - PyString_AS_STRING(name_obj) - ret->ct_name_position
== extra_len);
@@ -216,12 +227,19 @@
return ct;
}
+static _crx_type_t *zef_get_function_type(_crx_builder_t *cb, _crx_type_t *ret,
+ _crx_qual_type args[], int nargs,
+ _crx_trampoline1_fn trampl)
+{
+ return _zef_function(cb, ret, args, nargs, 0);
+}
+
static _crx_type_t *zef_get_ellipsis_function_type(_crx_builder_t *cb,
_crx_type_t *ret,
_crx_qual_type args[],
int nargs)
{
- abort();
+ return _zef_function(cb, ret, args, nargs, 1);
}
static _crx_type_t *zef_get_pointer_type(_crx_builder_t *cb,
diff --git a/zeffir/test/test_ctype.py b/zeffir/test/test_ctype.py
--- a/zeffir/test/test_ctype.py
+++ b/zeffir/test/test_ctype.py
@@ -74,6 +74,11 @@
assert repr(ffi.typeof("int(long a,short b)"))=="<ctype 'int(long,
short)'>"
assert repr(ffi.typeof("int(*)(long)"))=="<ctype 'int(*)(long)'>"
+def test_typedef_function_dotdotdot():
+ ffi = support.new_ffi()
+ assert repr(ffi.typeof("int(...)")) == "<ctype 'int(...)'>"
+ assert repr(ffi.typeof("int*(void*,...)")) == "<ctype 'int *(void *,
...)'>"
+
def test_simple_typedef():
ffi, lib = support.compile_and_open('ctype')
assert ffi.sizeof("foo_t") == ffi.sizeof("long long")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit