Skip to content

Commit

Permalink
remove FUNCFLAG_VARIADIC
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrence-danna-apple committed Jul 15, 2020
1 parent 80f852b commit aeac14b
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 47 deletions.
7 changes: 0 additions & 7 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1579,13 +1579,6 @@ They are instances of a private class:
value usable as argument (integer, string, ctypes instance). This allows
defining adapters that can adapt custom objects as function parameters.

.. attribute:: variadic

Assign a boolean to specify that the function takes a variable number of
arguments. This does not matter on most platforms, but for Apple arm64
platforms variadic functions have a different calling convention than
normal functions.

.. attribute:: errcheck

Assign a Python function or another callable to this attribute. The
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,6 @@ def test_from_format(self):
c_char_p)

PyBytes_FromFormat = pythonapi.PyBytes_FromFormat
PyBytes_FromFormat.variadic = True
PyBytes_FromFormat.argtypes = (c_char_p,)
PyBytes_FromFormat.restype = py_object

Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2516,7 +2516,6 @@ def test_from_format(self):
name = "PyUnicode_FromFormat"
_PyUnicode_FromFormat = getattr(pythonapi, name)
_PyUnicode_FromFormat.argtypes = (c_char_p,)
_PyUnicode_FromFormat.variadic = True
_PyUnicode_FromFormat.restype = py_object

def PyUnicode_FromFormat(format, *args):
Expand Down
32 changes: 0 additions & 32 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3320,35 +3320,6 @@ PyCFuncPtr_get_restype(PyCFuncPtrObject *self, void *Py_UNUSED(ignored))
}
}

static int
PyCFuncPtr_set_variadic(PyCFuncPtrObject *self, PyObject *ob, void *Py_UNUSED(ignored))
{
StgDictObject *dict = PyObject_stgdict((PyObject *)self);
assert(dict);
int r = PyObject_IsTrue(ob);
if (r == 1) {
dict->flags |= FUNCFLAG_VARIADIC;
return 0;
} else if (r == 0) {
dict->flags &= ~FUNCFLAG_VARIADIC;
return 0;
} else {
return -1;
}
}

static PyObject *
PyCFuncPtr_get_variadic(PyCFuncPtrObject *self, void *Py_UNUSED(ignored))
{
StgDictObject *dict = PyObject_stgdict((PyObject *)self);
assert(dict); /* Cannot be NULL for PyCFuncPtrObject instances */
if (dict->flags & FUNCFLAG_VARIADIC)
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
}


static int
PyCFuncPtr_set_argtypes(PyCFuncPtrObject *self, PyObject *ob, void *Py_UNUSED(ignored))
{
Expand Down Expand Up @@ -3394,8 +3365,6 @@ static PyGetSetDef PyCFuncPtr_getsets[] = {
{ "argtypes", (getter)PyCFuncPtr_get_argtypes,
(setter)PyCFuncPtr_set_argtypes,
"specify the argument types", NULL },
{ "variadic", (getter)PyCFuncPtr_get_variadic, (setter)PyCFuncPtr_set_variadic,
"specify if function takes variable number of arguments", NULL },
{ NULL, NULL }
};

Expand Down Expand Up @@ -5870,7 +5839,6 @@ PyInit__ctypes(void)
PyModule_AddObject(m, "FUNCFLAG_USE_ERRNO", PyLong_FromLong(FUNCFLAG_USE_ERRNO));
PyModule_AddObject(m, "FUNCFLAG_USE_LASTERROR", PyLong_FromLong(FUNCFLAG_USE_LASTERROR));
PyModule_AddObject(m, "FUNCFLAG_PYTHONAPI", PyLong_FromLong(FUNCFLAG_PYTHONAPI));
PyModule_AddObject(m, "FUNCFLAG_VARIADIC", PyLong_FromLong(FUNCFLAG_VARIADIC));
PyModule_AddStringConstant(m, "__version__", "1.1.0");

PyModule_AddObject(m, "_memmove_addr", PyLong_FromVoidPtr(memmove));
Expand Down
11 changes: 6 additions & 5 deletions Modules/_ctypes/callproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,11 +847,12 @@ static int _call_function_pointer(int flags,
# define HAVE_FFI_PREP_CIF_VAR_RUNTIME false
# endif

/* Everyone SHOULD set f.variadic=True on variadic function pointers, but
* lots of existing code will not. If there's at least one arg and more
* args are passed than are defined in the prototype, then it must be a
* variadic function. */
bool is_variadic = (flags & FUNCFLAG_VARIADIC) || (argtypecount != 0 && argcount > argtypecount);
/* Even on Apple-arm64 the calling convention for variadic functions conincides
* with the standard calling convention in the case that the function called
* only with its fixed arguments. Thus, we do not need a special flag to be
* set on variadic functions. We treat a function as variadic if it is called
* with a nonzero number of variadic arguments */
bool is_variadic = (argtypecount != 0 && argcount > argtypecount);
(void) is_variadic;

#if defined(__APPLE__) && defined(__arm64__)
Expand Down
1 change: 0 additions & 1 deletion Modules/_ctypes/ctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ PyObject *_ctypes_callproc(PPROC pProc,
#define FUNCFLAG_PYTHONAPI 0x4
#define FUNCFLAG_USE_ERRNO 0x8
#define FUNCFLAG_USE_LASTERROR 0x10
#define FUNCFLAG_VARIADIC 0x20

#define TYPEFLAG_ISPOINTER 0x100
#define TYPEFLAG_HASPOINTER 0x200
Expand Down

0 comments on commit aeac14b

Please sign in to comment.