[pypy-svn] r15771 - in pypy/dist/pypy/translator/c: . src

pedronis at codespeak.net pedronis at codespeak.net
Mon Aug 8 16:48:03 CEST 2005


Author: pedronis
Date: Mon Aug  8 16:47:56 2005
New Revision: 15771

Modified:
   pypy/dist/pypy/translator/c/external.py
   pypy/dist/pypy/translator/c/extfunc.py
   pypy/dist/pypy/translator/c/funcgen.py
   pypy/dist/pypy/translator/c/src/exception.h
   pypy/dist/pypy/translator/c/src/ll_os.h
   pypy/dist/pypy/translator/c/src/ll_time.h
   pypy/dist/pypy/translator/c/src/mem.h
   pypy/dist/pypy/translator/c/src/support.h
Log:
issue107 in-progress

use the prefixes: RPy/RPYTHON/rpython (and Py) consistently with our exception machinary:

now we have

RPyExceptionOccurred
RPyRaiseException
RPyFetchException
RPyMatchException
RPyConvertExceptionFromCPython
RPyConvertExceptionToCPython
RPyRaiseSimpleException

RPyRaiseSimpleException is used as:

	RPyRaiseSimpleException(PyExc_IOError, "select() failed")

and 

RPYTHON_RAISE_OSERROR




Modified: pypy/dist/pypy/translator/c/external.py
==============================================================================
--- pypy/dist/pypy/translator/c/external.py	(original)
+++ pypy/dist/pypy/translator/c/external.py	Mon Aug  8 16:47:56 2005
@@ -28,8 +28,8 @@
         call = '%s(%s)' % (self.fnptr._name, ', '.join(self.argnames()))
         if self.FUNCTYPE.RESULT != Void:
             yield 'result = %s;' % call
-            yield 'if (PyErr_Occurred()) ConvertExceptionFromCPython();'
+            yield 'if (PyErr_Occurred()) RPyConvertExceptionFromCPython();'
             yield 'return result;'
         else:
             yield '%s;' % call
-            yield 'if (PyErr_Occurred()) ConvertExceptionFromCPython();'
+            yield 'if (PyErr_Occurred()) RPyConvertExceptionFromCPython();'

Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/extfunc.py	Mon Aug  8 16:47:56 2005
@@ -99,7 +99,7 @@
 
     yield ('RPYTHON_EXCEPTION_MATCH',  exceptiondata.ll_exception_match)
     yield ('RPYTHON_TYPE_OF_EXC_INST', exceptiondata.ll_type_of_exc_inst)
-    yield ('RAISE_OSERROR',            exceptiondata.ll_raise_OSError)
+    yield ('RPYTHON_RAISE_OSERROR',    exceptiondata.ll_raise_OSError)
     if not db.standalone:
         yield ('RPYTHON_PYEXCCLASS2EXC', exceptiondata.ll_pyexcclass2exc)
 
@@ -108,7 +108,7 @@
             lltype.pyobjectptr(pyexccls))
         # strange naming here because the macro name must be
         # a substring of PyExc_%s
-        yield ('Exc_%s' % pyexccls.__name__, exc_llvalue)
+        yield ('RPyExc_%s' % pyexccls.__name__, exc_llvalue)
 
 
 def predeclare_all(db, rtyper):

Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py	(original)
+++ pypy/dist/pypy/translator/c/funcgen.py	Mon Aug  8 16:47:56 2005
@@ -104,7 +104,7 @@
             assert self.lltypemap(self.graph.getreturnvar()) == PyObjPtr
             yield '{'
             yield '\t%s;' % cdecl(exc_value_typename, 'vanishing_exc_value')
-            yield '\tConvertExceptionToCPython(vanishing_exc_value);'
+            yield '\tRPyConvertExceptionToCPython(vanishing_exc_value);'
             yield '\t%s' % self.db.cdecrefstmt('vanishing_exc_value', lltype_of_exception_value)
             yield '}'
         yield 'return %s; ' % self.error_return_value()
@@ -257,10 +257,10 @@
                         T2 = link.last_exc_value.concretetype
                     typ1 = self.db.gettype(T1)
                     typ2 = self.db.gettype(T2)
-                    yield 'if (MatchException(%s)) {' % (self.db.get(etype),)
+                    yield 'if (RPyMatchException(%s)) {' % (self.db.get(etype),)
                     yield '\t%s;' % cdecl(typ1, 'exc_cls')
                     yield '\t%s;' % cdecl(typ2, 'exc_value')
-                    yield '\tFetchException(exc_cls, exc_value, %s);' % (
+                    yield '\tRPyFetchException(exc_cls, exc_value, %s);' % (
                         cdecl(typ2, ''))
                     d = {}
                     if isinstance(link.last_exception, Variable):
@@ -362,11 +362,11 @@
         args = [self.expr(v) for v in op.args if self.lltypemap(v) != Void]
         if self.lltypemap(op.result) == Void:
             # skip assignment of 'void' return value
-            return '%s(%s); if (ExceptionOccurred()) FAIL(%s)' % (
+            return '%s(%s); if (RPyExceptionOccurred()) FAIL(%s)' % (
                 args[0], ', '.join(args[1:]), err)
         else:
             r = self.expr(op.result)
-            return '%s = %s(%s); if (ExceptionOccurred()) FAIL(%s)' % (
+            return '%s = %s(%s); if (RPyExceptionOccurred()) FAIL(%s)' % (
                 r, args[0], ', '.join(args[1:]), err)
 
     # low-level operations

Modified: pypy/dist/pypy/translator/c/src/exception.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/exception.h	(original)
+++ pypy/dist/pypy/translator/c/src/exception.h	Mon Aug  8 16:47:56 2005
@@ -13,42 +13,42 @@
 static RPYTHON_EXCEPTION_VTABLE	rpython_exc_type = NULL;
 static RPYTHON_EXCEPTION	rpython_exc_value = NULL;
 
-#define ExceptionOccurred()	(rpython_exc_type != NULL)
+#define RPyExceptionOccurred()	(rpython_exc_type != NULL)
 
 #define RPyRaiseException(etype, evalue)		\
-		assert(!ExceptionOccurred());	\
+		assert(!RPyExceptionOccurred());	\
 		rpython_exc_type = etype;	\
 		rpython_exc_value = evalue
 
-#define FetchException(etypevar, evaluevar, type_of_evaluevar)		\
+#define RPyFetchException(etypevar, evaluevar, type_of_evaluevar)       \
 		etypevar = rpython_exc_type;				\
 		evaluevar = (type_of_evaluevar) rpython_exc_value;	\
 		rpython_exc_type = NULL;				\
 		rpython_exc_value = NULL
 
-#define MatchException(etype)	RPYTHON_EXCEPTION_MATCH(rpython_exc_type,  \
+#define RPyMatchException(etype)	RPYTHON_EXCEPTION_MATCH(rpython_exc_type,  \
 					(RPYTHON_EXCEPTION_VTABLE) etype)
 
 #ifndef PYPY_STANDALONE
-static void ConvertExceptionFromCPython(void)
+static void RPyConvertExceptionFromCPython(void)
 {
 	/* convert the CPython exception to an RPython one */
 	PyObject *exc_type, *exc_value, *exc_tb;
 	assert(PyErr_Occurred());
-	assert(!ExceptionOccurred());
+	assert(!RPyExceptionOccurred());
 	PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
 	/* XXX loosing the error message here */
 	rpython_exc_value = RPYTHON_PYEXCCLASS2EXC(exc_type);
 	rpython_exc_type = RPYTHON_TYPE_OF_EXC_INST(rpython_exc_value);
 }
 
-static void _ConvertExceptionToCPython(void)
+static void _RPyConvertExceptionToCPython(void)
 {
 	/* XXX 1. uses officially bad fishing */
 	/* XXX 2. looks for exception classes by name, fragile */
 	char* clsname;
 	PyObject* pycls;
-	assert(ExceptionOccurred());
+	assert(RPyExceptionOccurred());
 	assert(!PyErr_Occurred());
 	clsname = rpython_exc_type->ov_name->items;
 	pycls = PyDict_GetItemString(PyEval_GetBuiltins(), clsname);
@@ -61,8 +61,8 @@
 	}
 }
 
-#define ConvertExceptionToCPython(vanishing)    \
-	_ConvertExceptionToCPython();		\
+#define RPyConvertExceptionToCPython(vanishing)    \
+	_RPyConvertExceptionToCPython();		\
 	vanishing = rpython_exc_value;		\
 	rpython_exc_type = NULL;		\
 	rpython_exc_value = NULL;
@@ -70,20 +70,20 @@
 #endif   /* !PYPY_STANDALONE */
 
 
-#define RaiseSimpleException(exc, msg)				\
+#define RPyRaiseSimpleException(exc, msg)		        \
 		/* XXX 1. uses officially bad fishing */	\
 		/* XXX 2. msg is ignored */			\
-		rpython_exc_type = (exc)->o_typeptr;		\
-		rpython_exc_value = (exc);			\
+		rpython_exc_type = (R##exc)->o_typeptr;		\
+		rpython_exc_value = (R##exc);			\
 		rpython_exc_value->refcount++
 
 /******************************************************************/
 #else    /* non-RPython version of exceptions, using CPython only */
 /******************************************************************/
 
-#define ExceptionOccurred()           PyErr_Occurred()
+#define RPyExceptionOccurred()           PyErr_Occurred()
 #define RPyRaiseException(etype, evalue) PyErr_Restore(etype, evalue, NULL)
-#define FetchException(etypevar, evaluevar, ignored)   {	\
+#define RPyFetchException(etypevar, evaluevar, ignored)   {	\
 		PyObject *__tb;					\
 		PyErr_Fetch(&etypevar, &evaluevar, &__tb);	\
 		if (evaluevar == NULL) {			\
@@ -92,12 +92,12 @@
 		}						\
 		Py_XDECREF(__tb);				\
 	}
-#define MatchException(etype)         PyErr_ExceptionMatches(etype)
-#define ConvertExceptionFromCPython() /* nothing */
-#define ConvertExceptionToCPython(vanishing) vanishing = NULL  
+#define RPyMatchException(etype)         PyErr_ExceptionMatches(etype)
+#define RPyConvertExceptionFromCPython() /* nothing */
+#define RPyConvertExceptionToCPython(vanishing) vanishing = NULL  
 
-#define RaiseSimpleException(exc, msg) \
-		PyErr_SetString(Py##exc, msg)    /* pun */
+#define RPyRaiseSimpleException(exc, msg) \
+		PyErr_SetString(exc, msg)    /* pun */
 
 /******************************************************************/
 #endif                                             /* HAVE_RTYPER */

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 Aug  8 16:47:56 2005
@@ -42,7 +42,7 @@
 	char buf[PATH_MAX];
 	int fd, namelen = RPyString_Size(filename);
 	if (namelen >= PATH_MAX) {
-		RAISE_OSERROR(ENAMETOOLONG);
+		RPYTHON_RAISE_OSERROR(ENAMETOOLONG);
 		return -1;
 	}
 	else {
@@ -50,7 +50,7 @@
 		buf[namelen] = 0;
 		fd = open(buf, flag, mode);
 		if (fd < 0)
-			RAISE_OSERROR(errno);
+			RPYTHON_RAISE_OSERROR(errno);
 		return fd;
 	}
 }
@@ -59,7 +59,7 @@
 {
 	long n = read(fd, RPyString_AsString(buffer), RPyString_Size(buffer));
 	if (n < 0)
-		RAISE_OSERROR(errno);
+		RPYTHON_RAISE_OSERROR(errno);
 	return n;
 }
 
@@ -67,21 +67,21 @@
 {
 	long n = write(fd, RPyString_AsString(buffer), RPyString_Size(buffer));
 	if (n < 0)
-		RAISE_OSERROR(errno);
+		RPYTHON_RAISE_OSERROR(errno);
 	return n;
 }
 
 void LL_os_close(int fd)
 {
 	if (close(fd) < 0)
-		RAISE_OSERROR(errno);
+		RPYTHON_RAISE_OSERROR(errno);
 }
 
 int LL_os_dup(int fd)
 {
 	fd = dup(fd);
 	if (fd < 0)
-		RAISE_OSERROR(errno);
+		RPYTHON_RAISE_OSERROR(errno);
 	return fd;
 }
 
@@ -91,7 +91,7 @@
 	char *res;
 	res = getcwd(buf, sizeof buf);
 	if (res == NULL) {
-		RAISE_OSERROR(errno);
+		RPYTHON_RAISE_OSERROR(errno);
 		return NULL;
 	}
 	return RPyString_FromString(buf);
@@ -120,7 +120,7 @@
   STRUCT_STAT st;
   int error = STAT(RPyString_AsString(fname), &st);
   if (error != 0) {
-    RAISE_OSERROR(errno);
+    RPYTHON_RAISE_OSERROR(errno);
     return NULL;
   }
   return _stat_construct_result_helper(st);
@@ -130,7 +130,7 @@
   STRUCT_STAT st;
   int error = FSTAT(fd, &st);
   if (error != 0) {
-    RAISE_OSERROR(errno);
+    RPYTHON_RAISE_OSERROR(errno);
     return NULL;
   }
   return _stat_construct_result_helper(st);
@@ -156,7 +156,7 @@
     res = lseek(fd, pos, how);
 #endif
     if (res < 0)
-        RAISE_OSERROR(errno);
+        RPYTHON_RAISE_OSERROR(errno);
     return res;
 }
 
@@ -169,7 +169,7 @@
     int res;
     res = ftruncate((int)fd, (off_t)length);
     if (res < 0) {
-	RAISE_OSERROR(errno);
+	RPYTHON_RAISE_OSERROR(errno);
     }
 }
 #endif

Modified: pypy/dist/pypy/translator/c/src/ll_time.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/ll_time.h	(original)
+++ pypy/dist/pypy/translator/c/src/ll_time.h	Mon Aug  8 16:47:56 2005
@@ -60,7 +60,7 @@
 	unsigned long ul_millis;
 
 	if (millisecs > (double)ULONG_MAX) {
-		RaiseSimpleException(Exc_OverflowError,
+		RPyRaiseSimpleException(PyExc_OverflowError,
 				     "sleep length is too large");
 		return;
 	}
@@ -77,7 +77,7 @@
 				 * handler called.
 				 *
 			Sleep(1);
-			RaiseSimpleException(Exc_IOError, "interrupted");
+			RPyRaiseSimpleException(PyExc_IOError, "interrupted");
 			return;
 		}
 	}*/
@@ -94,7 +94,7 @@
 #else
 		if (1) {
 #endif
-			RaiseSimpleException(Exc_IOError, "select() failed");
+			RPyRaiseSimpleException(PyExc_IOError, "select() failed");
 			return;
 		}
 	}

Modified: pypy/dist/pypy/translator/c/src/mem.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/mem.h	(original)
+++ pypy/dist/pypy/translator/c/src/mem.h	Mon Aug  8 16:47:56 2005
@@ -10,7 +10,7 @@
 
 #define OP_ZERO_MALLOC(size, r, err)  {                                 \
     r = (void*) PyObject_Malloc(size);                                  \
-    if (r == NULL) FAIL_EXCEPTION(err, Exc_MemoryError, "out of memory")\
+    if (r == NULL) FAIL_EXCEPTION(err, PyExc_MemoryError, "out of memory")\
     memset((void*) r, 0, size);                                         \
     COUNT_MALLOC                                                        \
   }

Modified: pypy/dist/pypy/translator/c/src/support.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/support.h	(original)
+++ pypy/dist/pypy/translator/c/src/support.h	Mon Aug  8 16:47:56 2005
@@ -11,13 +11,13 @@
 
 #define FAIL_EXCEPTION(err, exc, msg) \
 	{ \
-		RaiseSimpleException(exc, msg); \
+		RPyRaiseSimpleException(exc, msg); \
 		FAIL(err) \
 	}
-#define FAIL_OVF(err, msg) FAIL_EXCEPTION(err, Exc_OverflowError, msg)
-#define FAIL_VAL(err, msg) FAIL_EXCEPTION(err, Exc_ValueError, msg)
-#define FAIL_ZER(err, msg) FAIL_EXCEPTION(err, Exc_ZeroDivisionError, msg)
-#define CFAIL(err)         { ConvertExceptionFromCPython(); FAIL(err) }
+#define FAIL_OVF(err, msg) FAIL_EXCEPTION(err, PyExc_OverflowError, msg)
+#define FAIL_VAL(err, msg) FAIL_EXCEPTION(err, PyExc_ValueError, msg)
+#define FAIL_ZER(err, msg) FAIL_EXCEPTION(err, PyExc_ZeroDivisionError, msg)
+#define CFAIL(err)         { RPyConvertExceptionFromCPython(); FAIL(err) }
 
 
 #ifndef PYPY_STANDALONE



More information about the Pypy-commit mailing list