[pypy-svn] r14405 - in pypy/dist/pypy/translator/c: . test

arigo at codespeak.net arigo at codespeak.net
Thu Jul 7 20:16:33 CEST 2005


Author: arigo
Date: Thu Jul  7 20:16:31 2005
New Revision: 14405

Modified:
   pypy/dist/pypy/translator/c/extfunc_include.h
   pypy/dist/pypy/translator/c/fixedname.py
   pypy/dist/pypy/translator/c/test/test_fixedname.py
Log:
LL_os_open(), without exception support.


Modified: pypy/dist/pypy/translator/c/extfunc_include.h
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc_include.h	(original)
+++ pypy/dist/pypy/translator/c/extfunc_include.h	Thu Jul  7 20:16:31 2005
@@ -1,11 +1,37 @@
 /************************************************************/
  /***  C header subsection: external functions             ***/
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #include <time.h>
 
 /* The functions below are mapped to functions from pypy.rpython.extfunctable
    by the pypy.translator.c.fixedname.EXTERNALS dictionary. */
 
+#define RPyString_GET_SIZE(rps)		((rps)->rs_chars.length)
+#define RPyString_AS_STRING(rps)	((rps)->rs_chars.items)
+
+
+int LL_os_open(RPyString *filename, int flag, int mode)
+{
+	char buf[PATH_MAX];
+	int fd, error, namelen = RPyString_GET_SIZE(filename);
+	if (namelen >= PATH_MAX) {
+		error = ENAMETOOLONG;
+	}
+	else {
+		memcpy(buf, RPyString_AS_STRING(filename), namelen);
+		buf[namelen] = 0;
+		fd = open(buf, flag, mode);
+		if (fd != -1)
+			return fd;
+		error = errno;
+	}
+	/* XXX */
+	Py_FatalError("oups, that gives an OSError");
+}
+
 
 double LL_time_clock(void)
 {

Modified: pypy/dist/pypy/translator/c/fixedname.py
==============================================================================
--- pypy/dist/pypy/translator/c/fixedname.py	(original)
+++ pypy/dist/pypy/translator/c/fixedname.py	Thu Jul  7 20:16:31 2005
@@ -8,13 +8,14 @@
 
 # table of functions hand-written in extfunc_include.h
 EXTERNALS = {
+    extfunctable.ll_os_open:    'LL_os_open',
     extfunctable.ll_time_clock: 'LL_time_clock',
     }
 
 
 def predeclare_common_types(db, rtyper):
     # Common types
-    yield ('RPyString',                Ptr(STR))
+    yield ('RPyString', STR)
 
 
 def predeclare_extfuncs(db, rtyper):
@@ -67,7 +68,6 @@
         return predeclare(c_name, getfunctionptr(db.translator, ll_func))
 
     def predeclaretype(c_typename, lowleveltype):
-        assert isinstance(lowleveltype, Ptr)
         typename = db.gettype(lowleveltype)
         return 'typedef %s;' % cdecl(typename, c_typename)
 

Modified: pypy/dist/pypy/translator/c/test/test_fixedname.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_fixedname.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_fixedname.py	Thu Jul  7 20:16:31 2005
@@ -1,4 +1,5 @@
 import autopath
+from pypy.tool.udir import udir
 from pypy.translator.c.test.test_genc import compile
 
 
@@ -12,3 +13,16 @@
     assert type(t1) is float
     t2 = time.clock()
     assert t0 <= t1 <= t2
+
+
+def test_os_open():
+    import os
+    tmpfile = str(udir.join('test_os_open.txt'))
+    def does_stuff():
+        fd = os.open(tmpfile, os.O_WRONLY | os.O_CREAT, 0777)
+        return fd
+
+    f1 = compile(does_stuff, [])
+    fd = f1()
+    os.close(fd)
+    assert os.path.exists(tmpfile)



More information about the Pypy-commit mailing list