diff options
| author | Armin Rigo <arigo@tunes.org> | 2016-10-27 17:21:47 +0200 |
|---|---|---|
| committer | Armin Rigo <arigo@tunes.org> | 2016-10-27 17:21:47 +0200 |
| commit | dcfbf4bf975e66029e6ef00ce36395c75c2f3ee7 (patch) | |
| tree | 1d690e444a9b53a9615c88e69982ca217ad50acc /doc/source/ref.rst | |
| parent | 0b175568e2b8afc92ecef2ed88fc8ae0b56c0b83 (diff) | |
| download | cffi-dcfbf4bf975e66029e6ef00ce36395c75c2f3ee7.tar.gz | |
Decided to fix ffi.sizeof() too. Update the documentation.
Diffstat (limited to 'doc/source/ref.rst')
| -rw-r--r-- | doc/source/ref.rst | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/doc/source/ref.rst b/doc/source/ref.rst index 99d255a..b028f4e 100644 --- a/doc/source/ref.rst +++ b/doc/source/ref.rst @@ -141,7 +141,8 @@ Here are a few examples of where buffer() would be useful: into a struct over a socket, rewriting the contents of mystruct[0] Remember that like in C, you can use ``array + index`` to get the pointer -to the index'th item of an array. +to the index'th item of an array. (In C you might more naturally write +``&array[index]``, but that is equivalent.) The returned object is not a built-in buffer nor memoryview object, because these objects' API changes too much across Python versions. @@ -255,6 +256,14 @@ lengths. argument in bytes. The argument can be either a C type, or a cdata object, like in the equivalent ``sizeof`` operator in C. +For ``array = ffi.new("T[]", n)``, then ``ffi.sizeof(array)`` returns +``n * ffi.sizeof("T")``. *New in version 1.9:* Similar rules apply for +structures with aa variable-sized array at the end. More precisely, if +``p`` was returned by ``ffi.new("struct foo *", ...)``, then +``ffi.sizeof(p[0])`` now returns the total allocated size. In previous +versions, it used to just return ``ffi.sizeof(ffi.typeof(p[0]))``, which +is the size of the structure ignoring the variable-sized part. + **ffi.alignof("C type")**: return the natural alignment size in bytes of the argument. Corresponds to the ``__alignof__`` operator in GCC. |
