[pypy-svn] r15043 - in pypy/dist/pypy: annotation rpython rpython/module translator/c translator/c/src translator/c/test
cfbolz at codespeak.net
cfbolz at codespeak.net
Mon Jul 25 17:33:19 CEST 2005
Author: cfbolz
Date: Mon Jul 25 17:33:18 2005
New Revision: 15043
Modified:
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/rpython/module/ll_os.py
pypy/dist/pypy/rpython/rbuiltin.py
pypy/dist/pypy/translator/c/extfunc.py
pypy/dist/pypy/translator/c/src/ll_os.h
pypy/dist/pypy/translator/c/test/test_extfunc.py
pypy/dist/pypy/translator/c/test/test_typed.py
Log:
(pedronis, cfbolz):
- some more builtin cleanup regarding the time functions
- implemented the os stat, fstat function in the c backend
- tests
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Mon Jul 25 17:33:18 2005
@@ -253,9 +253,6 @@
def pathpart(*args):
return SomeString()
-def time_func():
- return SomeFloat()
-
def import_func(*args):
return SomeObject()
@@ -290,10 +287,6 @@
BUILTIN_ANALYZERS[os.path.exists] = test
BUILTIN_ANALYZERS[os.path.isdir] = test
-# time stuff
-BUILTIN_ANALYZERS[time.time] = time_func
-BUILTIN_ANALYZERS[time.clock] = time_func
-
# import
BUILTIN_ANALYZERS[__import__] = import_func
Modified: pypy/dist/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_os.py (original)
+++ pypy/dist/pypy/rpython/module/ll_os.py Mon Jul 25 17:33:18 2005
@@ -110,6 +110,7 @@
tup.item7 = intmask(stat7)
tup.item8 = intmask(stat8)
tup.item9 = intmask(stat9)
+ return tup
def ll_os_fstat(fd):
(stat0, stat1, stat2, stat3, stat4,
@@ -123,4 +124,4 @@
stat5, stat6, stat7, stat8, stat9) = os.stat(from_rstr(path))
return ll_stat_result(stat0, stat1, stat2, stat3, stat4,
stat5, stat6, stat7, stat8, stat9)
-ll_os_fstat.suggested_primitive = True
+ll_os_stat.suggested_primitive = True
Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/rbuiltin.py Mon Jul 25 17:33:18 2005
@@ -258,25 +258,6 @@
BUILTIN_TYPER[rarithmetic.r_uint] = rtype_r_uint
BUILTIN_TYPER[objectmodel.instantiate] = rtype_instantiate
-import time
-
-def rtype_time_clock(hop):
- c = hop.inputconst(pyobj_repr, time.clock)
- v = hop.genop('simple_call', [c], resulttype = pyobj_repr)
- return hop.llops.convertvar(v, pyobj_repr, float_repr)
-
-BUILTIN_TYPER[time.clock] = rtype_time_clock
-
-
-def rtype_time_time(hop):
- c = hop.inputconst(pyobj_repr, time.time)
- v = hop.genop('simple_call', [c], resulttype = pyobj_repr)
- return hop.llops.convertvar(v, pyobj_repr, float_repr)
-
-BUILTIN_TYPER[time.time] = rtype_time_time
-
-import math
-
from pypy.rpython import extfunctable
def make_rtype_extfunc(extfuncinfo):
Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py (original)
+++ pypy/dist/pypy/translator/c/extfunc.py Mon Jul 25 17:33:18 2005
@@ -14,6 +14,8 @@
ll_os .ll_os_close: 'LL_os_close',
ll_os .ll_os_dup: 'LL_os_dup',
ll_os .ll_os_getcwd: 'LL_os_getcwd',
+ ll_os .ll_os_stat: 'LL_os_stat',
+ ll_os .ll_os_fstat: 'LL_os_fstat',
ll_time.ll_time_clock: 'LL_time_clock',
ll_math.ll_math_log10: 'LL_math_log10',
ll_math.ll_math_ceil: 'LL_math_ceil',
@@ -32,6 +34,7 @@
yield ('RPyString', STR)
yield ('RPyFREXP_RESULT', ll_math.FREXP_RESULT)
yield ('RPyMODF_RESULT', ll_math.MODF_RESULT)
+ yield ('RPySTAT_RESULT', ll_os.STAT_RESULT)
def predeclare_utility_functions(db, rtyper):
# Common utility functions
@@ -51,14 +54,14 @@
yield annotate(ll_math.ll_frexp_result, lltype.Float, lltype.Signed)
yield annotate(ll_math.ll_modf_result, lltype.Float, lltype.Float)
-
+ yield annotate(ll_os.ll_stat_result, *([lltype.Signed] * 10))
+
def predeclare_extfuncs(db, rtyper):
for func, funcobj in db.externalfuncs.items():
c_name = EXTERNALS[func]
funcptr = lltype._ptr(lltype.Ptr(lltype.typeOf(funcobj)), funcobj) # hum
yield c_name, funcptr
-
def predeclare_exception_data(db, rtyper):
# Exception-related types and constants
exceptiondata = rtyper.getexceptiondata()
Modified: pypy/dist/pypy/translator/c/src/ll_os.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/ll_os.h (original)
+++ pypy/dist/pypy/translator/c/src/ll_os.h Mon Jul 25 17:33:18 2005
@@ -19,6 +19,19 @@
*/
+/* just do what CPython is doing... */
+
+#if defined(MS_WIN64) || defined(MS_WINDOWS)
+# define STAT _stati64
+# define FSTAT _fstati64
+# define STRUCT_STAT struct _stati64
+#else
+# define STAT stat
+# define FSTAT fstat
+# define STRUCT_STAT struct stat
+#endif
+
+
int LL_os_open(RPyString *filename, int flag, int mode)
{
/* XXX unicode_file_names */
@@ -79,3 +92,43 @@
}
return RPyString_FromString(buf);
}
+
+RPySTAT_RESULT* _stat_construct_result_helper(STRUCT_STAT st) {
+ long res0, res1, res2, res3, res4, res5, res6, res7, res8, res9;
+ res0 = (long)st.st_mode;
+ res1 = (long)st.st_ino; /*XXX HAVE_LARGEFILE_SUPPORT!*/
+ res2 = (long)st.st_dev; /*XXX HAVE_LONG_LONG!*/
+ res3 = (long)st.st_nlink;
+ res4 = (long)st.st_uid;
+ res5 = (long)st.st_gid;
+ res6 = (long)st.st_size; /*XXX HAVE_LARGEFILE_SUPPORT!*/
+ res7 = (long)st.st_atime; /*XXX ignoring quite a lot of things for time here */
+ res8 = (long)st.st_mtime; /*XXX ignoring quite a lot of things for time here */
+ res9 = (long)st.st_ctime; /*XXX ignoring quite a lot of things for time here */
+ /*XXX ignoring BLOCK info here*/
+
+ return ll_stat_result(res0, res1, res2, res3, res4,
+ res5, res6, res7, res8, res9);
+}
+
+
+RPySTAT_RESULT* LL_os_stat(RPyString * fname) {
+ STRUCT_STAT st;
+ int error = STAT(RPyString_AsString(fname), &st);
+ if (error != 0) {
+ RAISE_OSERROR(errno);
+ return NULL;
+ }
+ return _stat_construct_result_helper(st);
+}
+
+RPySTAT_RESULT* LL_os_fstat(long fd) {
+ STRUCT_STAT st;
+ int error = FSTAT(fd, &st);
+ if (error != 0) {
+ RAISE_OSERROR(errno);
+ return NULL;
+ }
+ return _stat_construct_result_helper(st);
+}
+
Modified: pypy/dist/pypy/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_extfunc.py (original)
+++ pypy/dist/pypy/translator/c/test/test_extfunc.py Mon Jul 25 17:33:18 2005
@@ -54,9 +54,54 @@
assert open(filename, 'r').read() == "hello world\n"
os.unlink(filename)
+def test_os_stat():
+ filename = str(py.magic.autopath())
+ def call_stat():
+ st = os.stat(filename)
+ return st
+ f = compile(call_stat, [])
+ result = f()
+ assert result[0] == os.stat(filename)[0]
+ assert result[1] == os.stat(filename)[1]
+ assert result[2] == os.stat(filename)[2]
+
+def test_os_fstat():
+ filename = str(py.magic.autopath())
+ def call_fstat():
+ fd = os.open(filename, os.O_RDONLY, 0777)
+ st = os.fstat(fd)
+ return st
+ f = compile(call_fstat, [])
+ result = f()
+ assert result[0] == os.stat(filename)[0]
+ assert result[1] == os.stat(filename)[1]
+ assert result[2] == os.stat(filename)[2]
+
def test_getcwd():
def does_stuff():
return os.getcwd()
f1 = compile(does_stuff, [])
res = f1()
assert res == os.getcwd()
+
+def test_math_exp():
+ from math import exp
+ def fn(f):
+ return exp(f)
+ f = compile(fn, [float])
+ assert f(1.0) == exp(1.0)
+
+def test_math_frexp():
+ from math import frexp
+ def fn(x):
+ return frexp(x)
+ f = compile(fn, [float])
+ assert f(10.123) == frexp(10.123)
+
+def test_math_modf():
+ from math import modf
+ def fn(x):
+ return modf(x)
+ f = compile(fn, [float])
+ assert f(10.123) == modf(10.123)
+
Modified: pypy/dist/pypy/translator/c/test/test_typed.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_typed.py (original)
+++ pypy/dist/pypy/translator/c/test/test_typed.py Mon Jul 25 17:33:18 2005
@@ -275,27 +275,6 @@
res = self.getcompiled(fn)()
assert res == 0
- def test_math_exp(self):
- from math import exp
- def fn(f=float):
- return exp(f)
- f = self.getcompiled(fn)
- assert f(1.0) == exp(1.0)
-
- def test_math_frexp(self):
- from math import frexp
- def fn(x=float):
- return frexp(x)
- f = self.getcompiled(fn)
- assert f(10.123) == frexp(10.123)
-
- def test_math_modf(self):
- from math import modf
- def fn(x=float):
- return modf(x)
- f = self.getcompiled(fn)
- assert f(10.123) == modf(10.123)
-
def test_stringformatting(self):
def fn(i=int):
More information about the Pypy-commit
mailing list