[pypy-svn] r18412 - in pypy/dist/pypy: rpython rpython/module translator/c translator/c/src translator/c/test

adim at codespeak.net adim at codespeak.net
Tue Oct 11 17:01:52 CEST 2005


Author: adim
Date: Tue Oct 11 17:01:49 2005
New Revision: 18412

Modified:
   pypy/dist/pypy/rpython/extfunctable.py
   pypy/dist/pypy/rpython/module/ll_stackless.py
   pypy/dist/pypy/rpython/objectmodel.py
   pypy/dist/pypy/translator/c/extfunc.py
   pypy/dist/pypy/translator/c/src/ll_stackless.h
   pypy/dist/pypy/translator/c/test/test_standalone.py
Log:
provided a simple implementation of stack_too_big()


Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py	(original)
+++ pypy/dist/pypy/rpython/extfunctable.py	Tue Oct 11 17:01:49 2005
@@ -209,6 +209,7 @@
 # stackless
 from pypy.rpython import objectmodel
 declare(objectmodel.stack_frames_depth, int, 'll_stackless/stack_frames_depth')
+declare(objectmodel.stack_too_big, bool, 'll_stackless/stack_too_big')
 
 # ___________________________________________________________
 # the exceptions that can be implicitely raised by some operations

Modified: pypy/dist/pypy/rpython/module/ll_stackless.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_stackless.py	(original)
+++ pypy/dist/pypy/rpython/module/ll_stackless.py	Tue Oct 11 17:01:49 2005
@@ -4,3 +4,7 @@
 def ll_stackless_stack_frames_depth():
     return objectmodel.stack_frames_depth()
 ll_stackless_stack_frames_depth.suggested_primitive = True
+
+def ll_stackless_stack_too_big():
+    return objectmodel.stack_too_big()
+ll_stackless_stack_too_big.suggested_primitive = True

Modified: pypy/dist/pypy/rpython/objectmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/objectmodel.py	(original)
+++ pypy/dist/pypy/rpython/objectmodel.py	Tue Oct 11 17:01:49 2005
@@ -41,6 +41,9 @@
 def stack_frames_depth():
     return len(inspect.stack())
 
+def stack_too_big():
+    return False
+
 # ____________________________________________________________
 
 

Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/extfunc.py	Tue Oct 11 17:01:49 2005
@@ -50,6 +50,7 @@
     ll_thread.ll_thread_start:     'LL_thread_start',
     ll_thread.ll_thread_get_ident: 'LL_thread_get_ident',
     ll_stackless.ll_stackless_stack_frames_depth: 'LL_stackless_stack_frames_depth',
+    ll_stackless.ll_stackless_stack_too_big: 'LL_stackless_stack_too_big',
     }
 
 #______________________________________________________

Modified: pypy/dist/pypy/translator/c/src/ll_stackless.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/ll_stackless.h	(original)
+++ pypy/dist/pypy/translator/c/src/ll_stackless.h	Tue Oct 11 17:01:49 2005
@@ -5,6 +5,10 @@
 #  error "Stackless support: only for stand-alone executables"
 #endif
 
+#ifndef MAX_STACK_SIZE
+#define MAX_STACK_SIZE (1 << 20)
+#endif
+
 #define STANDALONE_ENTRY_POINT   slp_standalone_entry_point
 
 
@@ -28,10 +32,12 @@
 extern long slp_retval_long;
 extern double slp_retval_double;
 extern void *slp_retval_voidptr;
+extern char *slp_base_stack_pointer;
 
 slp_frame_t* slp_new_frame(int size, int state);
 long LL_stackless_stack_frames_depth(void);
 void slp_main_loop(void);
+char LL_stackless_stack_too_big(void);
 
 #ifndef PYPY_NOT_MAIN_FILE
 
@@ -43,6 +49,7 @@
 long slp_retval_long;
 double slp_retval_double;
 void *slp_retval_voidptr;
+char *slp_base_stack_pointer = NULL;
 
 slp_frame_t* slp_new_frame(int size, int state)
 {
@@ -80,6 +87,19 @@
     }
 }
 
+char LL_stackless_stack_too_big(void)
+{
+  char local;
+  long result;
+  /* compute the difference between local variable and
+   * and a stack origin pointer
+   */
+  result = &local - slp_base_stack_pointer;
+  if (-MAX_STACK_SIZE < result && result < MAX_STACK_SIZE){
+    return 0;
+  }
+  return 1;
+}
 #include "slp_state_decoding.h"
 
 
@@ -132,7 +152,10 @@
 
 int slp_standalone_entry_point(RPyListOfString *argv)
 {
-	int result = PYPY_STANDALONE(argv);
+	char local;
+	int result;
+	slp_base_stack_pointer = &local;
+	result = PYPY_STANDALONE(argv);
 	if (slp_frame_stack_bottom) {
 		slp_main_loop();
 		result = (int) slp_retval_long;

Modified: pypy/dist/pypy/translator/c/test/test_standalone.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_standalone.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_standalone.py	Tue Oct 11 17:01:49 2005
@@ -2,7 +2,7 @@
 from pypy.translator.tool.cbuild import build_executable 
 from pypy.annotation.model import SomeList, SomeString
 from pypy.annotation.listdef import ListDef
-from pypy.rpython.objectmodel import stack_frames_depth
+from pypy.rpython.objectmodel import stack_frames_depth, stack_too_big
 import os
 
 
@@ -65,6 +65,19 @@
     assert data.strip() == '10'
 
 
+def test_stack_too_big():
+    def f(n):
+        if stack_too_big():
+            return n
+        return f(n+1)
+
+    def fn():
+        return f(0)
+    data = wrap_stackless_function(fn)
+    assert int(data.strip()) > 500
+
+
+    
 def wrap_stackless_function(fn):
     def entry_point(argv):
         os.write(1, str(fn())+"\n")



More information about the Pypy-commit mailing list