[Python-Dev] Add Py_off_t and related APIs? (original) (raw)

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:

Some libraries define their own offset type:

-- Victor Stinner aka haypo http://www.haypocalc.com/blog/



More information about the Python-Dev mailing list