diff options
| author | Armin Rigo <arigo@tunes.org> | 2016-10-28 00:05:25 +0200 |
|---|---|---|
| committer | Armin Rigo <arigo@tunes.org> | 2016-10-28 00:05:25 +0200 |
| commit | b66d371af0e90e93fc0d0d56a5a3e2ff76ff9610 (patch) | |
| tree | 98ef298c2dc4df78462baa0de5082645e87166f8 /c/_cffi_backend.c | |
| parent | dcfbf4bf975e66029e6ef00ce36395c75c2f3ee7 (diff) | |
| download | cffi-b66d371af0e90e93fc0d0d56a5a3e2ff76ff9610.tar.gz | |
One more case, this time in CompiledFFI.sizeof().
Diffstat (limited to 'c/_cffi_backend.c')
| -rw-r--r-- | c/_cffi_backend.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c index 1eb421b..3bba3a4 100644 --- a/c/_cffi_backend.c +++ b/c/_cffi_backend.c @@ -5483,20 +5483,25 @@ static PyObject *b_alignof(PyObject *self, PyObject *arg) return PyInt_FromLong(align); } +static Py_ssize_t direct_sizeof_cdata(CDataObject *cd) +{ + Py_ssize_t size; + if (cd->c_type->ct_flags & CT_ARRAY) + size = get_array_length(cd) * cd->c_type->ct_itemdescr->ct_size; + else { + size = _cdata_var_byte_size(cd); + if (size < 0) + size = cd->c_type->ct_size; + } + return size; +} + static PyObject *b_sizeof(PyObject *self, PyObject *arg) { Py_ssize_t size; if (CData_Check(arg)) { - CDataObject *cd = (CDataObject *)arg; - - if (cd->c_type->ct_flags & CT_ARRAY) - size = get_array_length(cd) * cd->c_type->ct_itemdescr->ct_size; - else { - size = _cdata_var_byte_size(cd); - if (size < 0) - size = cd->c_type->ct_size; - } + size = direct_sizeof_cdata((CDataObject *)arg); } else if (CTypeDescr_Check(arg)) { size = ((CTypeDescrObject *)arg)->ct_size; |
