[pypy-svn] r45700 - in pypy/branch/pypy-more-rtti-inprogress: rpython rpython/module translator/c translator/c/src
arigo at codespeak.net
arigo at codespeak.net
Thu Aug 16 11:40:31 CEST 2007
Author: arigo
Date: Thu Aug 16 11:40:30 2007
New Revision: 45700
Modified:
pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py
pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py
pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py
pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h
Log:
os.lseek -> rffi
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py Thu Aug 16 11:40:30 2007
@@ -150,7 +150,6 @@
# external function declarations
posix = __import__(os.name)
-declare(os.lseek , r_longlong , 'll_os/lseek')
declare(os.isatty , bool , 'll_os/isatty')
if hasattr(posix, 'ftruncate'):
declare(os.ftruncate, noneannotation, 'll_os/ftruncate')
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py Thu Aug 16 11:40:30 2007
@@ -323,6 +323,55 @@
self.register(os.close, [int], s_None, llimpl=close_lltypeimpl,
export_name="ll_os.ll_os_close", oofakeimpl=os.close)
+ @registering(os.lseek)
+ def register_os_lseek(self):
+ if sys.platform.startswith('win'):
+ funcname = '_lseeki64'
+ INCLUDES = []
+ else:
+ funcname = 'lseek'
+ INCLUDES = self.UNISTD_INCL
+ if platform.defined('SEEK_SET', includes=INCLUDES):
+ SEEK_SET = platform.intdefined('SEEK_SET', includes=INCLUDES)
+ SEEK_CUR = platform.intdefined('SEEK_CUR', includes=INCLUDES)
+ SEEK_END = platform.intdefined('SEEK_END', includes=INCLUDES)
+ else:
+ SEEK_SET, SEEK_CUR, SEEK_END = 0, 1, 2
+ if (SEEK_SET, SEEK_CUR, SEEK_END) != (0, 1, 2):
+ # Turn 0, 1, 2 into SEEK_{SET,CUR,END}
+ def fix_seek_arg(n):
+ if n == 0: return SEEK_SET
+ if n == 1: return SEEK_CUR
+ if n == 2: return SEEK_END
+ return n
+ else:
+ def fix_seek_arg(n):
+ return n
+
+ os_lseek = rffi.llexternal(funcname,
+ [rffi.INT, rffi.LONGLONG, rffi.INT],
+ rffi.LONGLONG)
+
+ def lseek_lltypeimpl(fd, pos, how):
+ how = fix_seek_arg(how)
+ res = os_lseek(rffi.cast(rffi.INT, fd),
+ rffi.cast(rffi.LONGLONG, pos),
+ rffi.cast(rffi.INT, how))
+ res = rffi.cast(lltype.SignedLongLong, res)
+ if res < 0:
+ raise OSError(rffi.get_errno(), "os_lseek failed")
+ return res
+
+ def os_lseek_oofakeimpl(fd, pos, how):
+ res = os.lseek(fd, pos, how)
+ return r_longlong(res)
+
+ self.register(os.lseek, [int, r_longlong, int],
+ r_longlong,
+ llimpl = lseek_lltypeimpl,
+ export_name = "ll_os.ll_os_lseek",
+ oofakeimpl = os_lseek_oofakeimpl)
+
@registering(os.access)
def register_os_access(self):
os_access = rffi.llexternal('access',
@@ -629,10 +678,6 @@
# XXX deprecated style, this is all waiting to be converted to rffi
__metaclass__ = ClassMethods
- def ll_os_lseek(cls, fd,pos,how):
- return r_longlong(os.lseek(fd,pos,how))
- ll_os_lseek.suggested_primitive = True
-
def ll_os_isatty(cls, fd):
return os.isatty(fd)
ll_os_isatty.suggested_primitive = True
Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py Thu Aug 16 11:40:30 2007
@@ -20,7 +20,6 @@
# references to functions, so we cannot insert classmethods here.
EXTERNALS = {
- impl.ll_os_lseek.im_func: 'LL_os_lseek',
impl.ll_os_isatty.im_func: 'LL_os_isatty',
impl.ll_os_ftruncate.im_func:'LL_os_ftruncate',
impl.ll_os_strerror.im_func: 'LL_os_strerror',
Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h (original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h Thu Aug 16 11:40:30 2007
@@ -38,7 +38,6 @@
/* prototypes */
-long LL_os_lseek(long fd, long pos, long how);
int LL_os_isatty(long fd);
RPyString *LL_os_strerror(int errnum);
long LL_os_system(RPyString * fname);
@@ -70,30 +69,6 @@
#include "ll_osdefs.h"
-long LL_os_lseek(long fd, long pos, long how) {
-#if defined(MS_WIN64) || defined(MS_WINDOWS)
- PY_LONG_LONG res;
-#else
- off_t res;
-#endif
-#ifdef SEEK_SET
- /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */
- switch (how) {
- case 0: how = SEEK_SET; break;
- case 1: how = SEEK_CUR; break;
- case 2: how = SEEK_END; break;
- }
-#endif /* SEEK_END */
-#if defined(MS_WIN64) || defined(MS_WINDOWS)
- res = _lseeki64(fd, pos, how);
-#else
- res = lseek(fd, pos, how);
-#endif
- if (res < 0)
- RPYTHON_RAISE_OSERROR(errno);
- return res;
-}
-
int LL_os_isatty(long fd) {
return isatty((int)fd);
}
More information about the Pypy-commit
mailing list