[Python-Dev] Add Py_off_t and related APIs?
Victor Stinner
victor.stinner at haypocalc.com
Tue Jan 13 23:24:52 CET 2009
Le Tuesday 13 January 2009 22:47:52 Victor Stinner, vous avez écrit :
> Le Tuesday 13 January 2009 21:33:28 Martin v. Löwis, vous avez écrit :
> > I would do this through a converter function (O&), but yes,
> > making it private to the io library sounds about right. Who
> > else would benefit from it?
>
> On Linux, mmap() prototype is (...)
A more complete answer... Current usage of off_t types in Python:
(1) mmap.mmap(): [use Py_ssize_t]
Use "Py_ssize_t i = PyNumber_AsSsize_t(o, PyExc_OverflowError)".
(2) posix.lseek(), posix.ftruncate(), fcnt.lockf(): [off_t,
struct flock for fcntl.lockf()]
Use PyInt_AsLong(posobj),
or "PyLong_Check(posobj)? PyLong_AsLongLong(posobj) : PyInt_AsLong(posobj)"
if HAVE_LARGEFILE_SUPPORT.
(3) posix.stat(): [struct win32_stat/struct stat]
use PyInt_FromLong(st->st_size),
or PyLong_FromLongLong((PY_LONG_LONG)st->st_size) if HAVE_LARGEFILE_SUPPORT
---
Using >>find /usr/include -name "*.h"|xargs grep -H off_t<< I found:
- file operations:
* lseek(), truncate(), fseeko(), ftello()
* file size in the *stat() structure
* (fcntl) lockf(), fadvice(), fallocate()
* pread(), pwrite()
* async I/O like aio_read()
- dirent structure used by readir()
- sendfile()
- mmap()
Some libraries define their own offset type:
- [gzip] z_off_t used by gzseek(), gztell() defined as a long
- [mysql] my_off_t is unsigned long, or ulonglong size if sizeof(off_t) > 4,
os_off_t is off_t
- etc.
--
Victor Stinner aka haypo
http://www.haypocalc.com/blog/
More information about the Python-Dev
mailing list