[pypy-svn] r46243 - in pypy/branch/pypy-more-rtti-inprogress/rpython: lltypesystem module
arigo at codespeak.net
arigo at codespeak.net
Sun Sep 2 19:50:04 CEST 2007
Author: arigo
Date: Sun Sep 2 19:50:02 2007
New Revision: 46243
Modified:
pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/ll2ctypes.py
pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py
Log:
Start again with Windows porting.
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/ll2ctypes.py Sun Sep 2 19:50:02 2007
@@ -44,6 +44,7 @@
if max_n is not None and fieldname == S._arrayfld:
cls = build_ctypes_array(FIELDTYPE, max_n)
elif isinstance(FIELDTYPE, lltype.Ptr) and FIELDTYPE.TO is S:
+ # XXX this is not the right hack to handle circular structures!
cls = ctypes.POINTER(S._name)
else:
cls = get_ctypes_type(FIELDTYPE)
@@ -436,6 +437,9 @@
libraries = getattr(funcptr._obj, 'libraries', None)
if not libraries:
cfunc = getattr(standard_c_lib, funcname, None)
+ # XXX magic: on Windows try to load the function from 'kernel32' too
+ if cfunc is None and hasattr(ctypes, 'windll'):
+ cfunc = getattr(ctypes.windll.kernel32, funcname, None)
else:
cfunc = None
for libname in libraries:
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 Sun Sep 2 19:50:02 2007
@@ -30,12 +30,19 @@
register(function, [CLOCK_T], ...)
"""
- _includes_ = ['sys/times.h', 'utime.h', 'sys/types.h', 'unistd.h',
- 'signal.h', 'wait.h']
+ _includes_ = []
if not sys.platform.startswith('win'):
- _includes_ += ['dirent.h', 'sys/stat.h']
-
- CLOCK_T = platform.SimpleType('clock_t', rffi.INT)
+ _includes_ += ['dirent.h', 'sys/stat.h',
+ 'sys/times.h', 'utime.h', 'sys/types.h', 'unistd.h',
+ 'signal.h', 'wait.h']
+
+ CLOCK_T = platform.SimpleType('clock_t', rffi.INT)
+
+ TMS = platform.Struct(
+ 'struct tms', [('tms_utime', rffi.INT),
+ ('tms_stime', rffi.INT),
+ ('tms_cutime', rffi.INT),
+ ('tms_cstime', rffi.INT)])
NAME_MAX = platform.DefinedConstantInteger('NAME_MAX')
@@ -43,12 +50,6 @@
SEEK_CUR = platform.DefinedConstantInteger('SEEK_CUR')
SEEK_END = platform.DefinedConstantInteger('SEEK_END')
- TMS = platform.Struct(
- 'struct tms', [('tms_utime', rffi.INT),
- ('tms_stime', rffi.INT),
- ('tms_cutime', rffi.INT),
- ('tms_cstime', rffi.INT)])
-
class RegisterOs(BaseLazyRegistering):
_stringpolicy_ = 'fullauto'
@@ -185,26 +186,64 @@
@registering(os.times)
def register_os_times(self):
- self.TMSP = lltype.Ptr(self.TMS)
- os_times = self.llexternal('times', [self.TMSP], self.CLOCK_T)
+ if sys.platform.startswith('win'):
+ HANDLE = rffi.LONG
+ FILETIME = rffi.CStruct('_FILETIME', ('dwLowDateTime', rffi.LONG),
+ ('dwHighDateTime', rffi.LONG))
+ GetCurrentProcess = self.llexternal('GetCurrentProcess', [],
+ HANDLE)
+ GetProcessTimes = self.llexternal('GetProcessTimes',
+ [HANDLE,
+ lltype.Ptr(FILETIME),
+ lltype.Ptr(FILETIME),
+ lltype.Ptr(FILETIME),
+ lltype.Ptr(FILETIME)],
+ lltype.Bool)
+
+ def times_lltypeimpl():
+ pcreate = lltype.malloc(FILETIME, flavor='raw')
+ pexit = lltype.malloc(FILETIME, flavor='raw')
+ pkernel = lltype.malloc(FILETIME, flavor='raw')
+ puser = lltype.malloc(FILETIME, flavor='raw')
+ hProc = GetCurrentProcess()
+ GetProcessTimes(hProc, pcreate, pexit, pkernel, puser)
+ # The fields of a FILETIME structure are the hi and lo parts
+ # of a 64-bit value expressed in 100 nanosecond units
+ # (of course).
+ result = (pkernel.c_dwHighDateTime*429.4967296 +
+ pkernel.c_dwLowDateTime*1E-7,
+ puser.c_dwHighDateTime*429.4967296 +
+ puser.c_dwLowDateTime*1E-7,
+ 0, 0, 0)
+ lltype.free(puser, flavor='raw')
+ lltype.free(pkernel, flavor='raw')
+ lltype.free(pexit, flavor='raw')
+ lltype.free(pcreate, flavor='raw')
+ return result
+ self.register(os.times, [], (float, float, float, float, float),
+ "ll_os.ll_times", llimpl=times_lltypeimpl)
+ return
+
+ TMSP = lltype.Ptr(self.TMS)
+ os_times = self.llexternal('times', [TMSP], self.CLOCK_T)
# Here is a random extra platform parameter which is important.
# Strictly speaking, this should probably be retrieved at runtime, not
# at translation time.
- self.CLOCK_TICKS_PER_SECOND = float(os.sysconf('SC_CLK_TCK'))
+ CLOCK_TICKS_PER_SECOND = float(os.sysconf('SC_CLK_TCK'))
def times_lltypeimpl():
- l_tmsbuf = lltype.malloc(self.TMSP.TO, flavor='raw')
+ l_tmsbuf = lltype.malloc(TMSP.TO, flavor='raw')
try:
result = os_times(l_tmsbuf)
if result == -1:
raise OSError(rffi.get_errno(), "times failed")
return (
- l_tmsbuf.c_tms_utime / self.CLOCK_TICKS_PER_SECOND,
- l_tmsbuf.c_tms_stime / self.CLOCK_TICKS_PER_SECOND,
- l_tmsbuf.c_tms_cutime / self.CLOCK_TICKS_PER_SECOND,
- l_tmsbuf.c_tms_cstime / self.CLOCK_TICKS_PER_SECOND,
- result / self.CLOCK_TICKS_PER_SECOND)
+ l_tmsbuf.c_tms_utime / CLOCK_TICKS_PER_SECOND,
+ l_tmsbuf.c_tms_stime / CLOCK_TICKS_PER_SECOND,
+ l_tmsbuf.c_tms_cutime / CLOCK_TICKS_PER_SECOND,
+ l_tmsbuf.c_tms_cstime / CLOCK_TICKS_PER_SECOND,
+ result / CLOCK_TICKS_PER_SECOND)
finally:
lltype.free(l_tmsbuf, flavor='raw')
self.register(os.times, [], (float, float, float, float, float),
@@ -264,11 +303,11 @@
return extdef([], (str, str, str, str, str),
"ll_os.ll_uname", llimpl=uname_llimpl)
- @registering(os.getuid)
+ @registering_if(os, 'getuid')
def register_os_getuid(self):
return self.extdef_for_os_function_returning_int('getuid')
- @registering(os.geteuid)
+ @registering_if(os, 'geteuid')
def register_os_geteuid(self):
return self.extdef_for_os_function_returning_int('geteuid')
@@ -428,7 +467,12 @@
@registering(os.access)
def register_os_access(self):
- os_access = self.llexternal('access', [rffi.CCHARP, rffi.INT],
+ if sys.platform.startswith('win'):
+ name = '_access'
+ else:
+ name = 'access'
+ os_access = self.llexternal(name,
+ [rffi.CCHARP, rffi.INT],
rffi.INT)
def access_llimpl(path, mode):
More information about the pypy-svn
mailing list