[pypy-svn] r16559 - pypy/dist/pypy/translator/llvm2/module
rxe at codespeak.net
rxe at codespeak.net
Thu Aug 25 22:42:53 CEST 2005
Author: rxe
Date: Thu Aug 25 22:42:52 2005
New Revision: 16559
Removed:
pypy/dist/pypy/translator/llvm2/module/ll_os.py
pypy/dist/pypy/translator/llvm2/module/ll_os_path.py
Modified:
pypy/dist/pypy/translator/llvm2/module/extfunction.py
pypy/dist/pypy/translator/llvm2/module/genexterns.c
pypy/dist/pypy/translator/llvm2/module/support.py
Log:
Add the remaining functions to generate (ll_os). (ericvrp/rxe)
Modified: pypy/dist/pypy/translator/llvm2/module/extfunction.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/extfunction.py (original)
+++ pypy/dist/pypy/translator/llvm2/module/extfunction.py Thu Aug 25 22:42:52 2005
@@ -38,9 +38,9 @@
extfunctions = {} #dependencies, llvm-code
-import support, ll_os
+import support
-for module in (support, ll_os):
+for module in (support,):
extdeclarations += module.extdeclarations
extfunctions.update(module.extfunctions)
extdeclarations += '\n;application function prototypes'
Modified: pypy/dist/pypy/translator/llvm2/module/genexterns.c
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/genexterns.c (original)
+++ pypy/dist/pypy/translator/llvm2/module/genexterns.c Thu Aug 25 22:42:52 2005
@@ -3,8 +3,6 @@
#include <ctype.h>
#include <python2.3/Python.h>
-#define NULL (void *) 0
-
#define LL_MATH_SET_ERANGE_IF_MATH_ERROR Py_SET_ERANGE_IF_OVERFLOW
// c forward declarations
@@ -13,10 +11,12 @@
struct RPyFREXP_RESULT;
struct RPyMODF_RESULT;
struct RPyString;
+struct RPySTAT_RESULT;
struct RPyFREXP_RESULT *ll_frexp_result__Float_Signed(double, int);
struct RPyMODF_RESULT *ll_modf_result__Float_Float(double, double);
-
+struct RPySTAT_RESULT *ll_stat_result__Signed_Signed_Signed_Signed_Signed_Signed_Signed_Signed_Signed_Signed(int, int, int, int, int,
+ int, int, int, int, int);
char *RPyString_AsString(struct RPyString*);
int RPyString_Size(struct RPyString*);
struct RPyString *RPyString_FromString(char *);
@@ -24,6 +24,9 @@
void prepare_and_raise_OverflowError(char *);
void prepare_and_raise_ValueError(char *);
void prepare_and_raise_IOError(char *);
+void ll_raise_OSError__Signed(int error);
+
+#define RPYTHON_RAISE_OSERROR(error) ll_raise_OSError__Signed(error)
int ll_math_is_error(double x) {
if (errno == ERANGE) {
@@ -490,3 +493,195 @@
return RPyString_FromString(buffer);
}
+/************************************************************/
+ /*** C header subsection: os module ***/
+
+#if !(defined(MS_WIN64) || defined(MS_WINDOWS))
+# include <unistd.h>
+# include <sys/types.h>
+# include <sys/stat.h>
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#ifndef PATH_MAX
+ /* assume windows */
+# define PATH_MAX 254
+#endif
+
+/* The functions below are mapped to functions from pypy.rpython.module.*
+ by the pypy.translator.c.extfunc.EXTERNALS dictionary.
+ They should correspond to the functions with the suggested_primitive
+ flag set, and NOT necessarily directly to the ll_os_*() functions.
+ See for example ll_read_into(), which is called by ll_os_read().
+ The latter would be messy to write here, but ll_read_into() is quite easy.
+*/
+
+
+/* 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(struct RPyString *filename, int flag, int mode)
+{
+ /* XXX unicode_file_names */
+ char buf[PATH_MAX];
+ int fd, namelen = RPyString_Size(filename);
+ if (namelen >= PATH_MAX) {
+ RPYTHON_RAISE_OSERROR(ENAMETOOLONG);
+ return -1;
+ }
+ else {
+ memcpy(buf, RPyString_AsString(filename), namelen);
+ buf[namelen] = 0;
+ fd = open(buf, flag, mode);
+ if (fd < 0)
+ RPYTHON_RAISE_OSERROR(errno);
+ return fd;
+ }
+}
+
+long ll_read_into(int fd, struct RPyString *buffer)
+{
+ long n = read(fd, RPyString_AsString(buffer), RPyString_Size(buffer));
+ if (n < 0)
+ RPYTHON_RAISE_OSERROR(errno);
+ return n;
+}
+
+long ll_os_write(int fd, struct RPyString *buffer)
+{
+ long n = write(fd, RPyString_AsString(buffer), RPyString_Size(buffer));
+ if (n < 0)
+ RPYTHON_RAISE_OSERROR(errno);
+ return n;
+}
+
+void ll_os_close(int fd)
+{
+ if (close(fd) < 0)
+ RPYTHON_RAISE_OSERROR(errno);
+}
+
+int ll_os_dup(int fd)
+{
+ fd = dup(fd);
+ if (fd < 0)
+ RPYTHON_RAISE_OSERROR(errno);
+ return fd;
+}
+
+struct RPyString *ll_os_getcwd(void)
+{
+ char buf[PATH_MAX];
+ char *res;
+ res = getcwd(buf, sizeof buf);
+ if (res == NULL) {
+ RPYTHON_RAISE_OSERROR(errno);
+ return NULL;
+ }
+ return RPyString_FromString(buf);
+}
+
+struct 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__Signed_Signed_Signed_Signed_Signed_Signed_Signed_Signed_Signed_Signed(res0, res1, res2, res3, res4,
+ res5, res6, res7, res8, res9);
+}
+
+
+struct RPySTAT_RESULT* ll_os_stat(struct RPyString * fname) {
+ STRUCT_STAT st;
+ int error = STAT(RPyString_AsString(fname), &st);
+ if (error != 0) {
+ RPYTHON_RAISE_OSERROR(errno);
+ return NULL;
+ }
+ return _stat_construct_result_helper(st);
+}
+
+struct RPySTAT_RESULT* ll_os_fstat(long fd) {
+ STRUCT_STAT st;
+ int error = FSTAT(fd, &st);
+ if (error != 0) {
+ RPYTHON_RAISE_OSERROR(errno);
+ return NULL;
+ }
+ return _stat_construct_result_helper(st);
+}
+
+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;
+}
+
+long ll_os_isatty(long fd) {
+ return (int)isatty((int)fd);
+}
+
+#ifdef HAVE_FTRUNCATE
+void ll_os_ftruncate(long fd, long length) { /*XXX add longfile support */
+ int res;
+ res = ftruncate((int)fd, (off_t)length);
+ if (res < 0) {
+ RPYTHON_RAISE_OSERROR(errno);
+ }
+}
+#endif
+
+struct RPyString *ll_os_strerror(int errnum) {
+ char *res;
+ res = strerror(errnum);
+ return RPyString_FromString(res);
+}
+
+long ll_os_system(struct RPyString * fname) {
+ return system(RPyString_AsString(fname));
+}
+
+void ll_os_unlink(struct RPyString * fname) {
+ int error = unlink(RPyString_AsString(fname));
+ if (error != 0) {
+ RPYTHON_RAISE_OSERROR(errno);
+ }
+}
Modified: pypy/dist/pypy/translator/llvm2/module/support.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/support.py (original)
+++ pypy/dist/pypy/translator/llvm2/module/support.py Thu Aug 25 22:42:52 2005
@@ -6,7 +6,7 @@
declare ccc uint %strlen(sbyte*)
declare ccc int %strcmp(sbyte*, sbyte*)
declare ccc sbyte* %memset(sbyte*, int, uint)
-
+declare ccc sbyte* %strncpy(sbyte *, sbyte *, int)
%__print_debug_info = internal global bool false
%__print_debug_info_option = internal constant [19 x sbyte] c"--print-debug-info\\00"
"""
More information about the Pypy-commit
mailing list