# New Ticket Created by  Jason Gloudon 
# Please include the string:  [perl #16219]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=16219 >



This is a config test for the direction of stack growth that makes
the direction a compile time constant.

-- 
Jason


-- attachment  1 ------------------------------------------------------
url: http://rt.perl.org/rt2/attach/33958/27799/862ba3/stackprobe.diff

diff --exclude=CVS -urN parrot/MANIFEST parrot-patch/MANIFEST
--- parrot/MANIFEST     Tue Aug  6 20:54:05 2002
+++ parrot-patch/MANIFEST       Wed Aug 14 22:32:28 2002
@@ -48,6 +48,8 @@
 config/auto/pack.pl
 config/auto/sizes.pl
 config/auto/sizes/test_c.in
+config/auto/stackdir.pl
+config/auto/stackdir/test_c.in
 config/gen/config_h.pl
 config/gen/config_h/config_h.in
 config/gen/config_pm.pl
diff --exclude=CVS -urN parrot/config/auto/stack.pl parrot-patch/config/auto/stack.pl
--- parrot/config/auto/stack.pl Wed Dec 31 19:00:00 1969
+++ parrot-patch/config/auto/stack.pl   Wed Aug 14 22:32:28 2002
@@ -0,0 +1,23 @@
+package Configure::Step;
+
+use strict;
+use vars qw($description @args);
+use Parrot::Configure::Step ':auto';
+
+$description = "Determining stack growth direction...";
+
+@args=qw(miniparrot);
+
+sub runstep {
+
+  cc_gen('config/auto/stackdir/stack_c.in');
+  cc_build();
+  my %results=eval cc_run();
+  cc_clean();
+  
+  for(keys %results) {
+    Configure::Data->set($_ => $results{$_});
+  }
+}
+
+1;
diff --exclude=CVS -urN parrot/config/auto/stackdir/test_c.in 
parrot-patch/config/auto/stackdir/test_c.in
--- parrot/config/auto/stackdir/test_c.in       Wed Dec 31 19:00:00 1969
+++ parrot-patch/config/auto/stackdir/test_c.in Wed Aug 14 22:32:28 2002
@@ -0,0 +1,27 @@
+/*
+ * test.c - figure out some Configure settings
+ *
+ * This file is automatically generated by Configure
+ * from test_c.in.
+ */
+
+#include <stdio.h>
+
+void b(int *caller);
+
+void probe_stack_top(void){
+    int stack_top = 1;
+    probe_stack_bottom(&stack_top);
+}
+
+void probe_stack_bottom(int *stack_top){
+    int stack_bottom = 1;
+
+    printf("(\tstackdir => %d);", (stack_top - &stack_bottom) > 0 ? -1 : 1);
+}
+
+int main(int argc, char **argv) {
+       probe_stack_top();
+       return 0;
+}
+
diff --exclude=CVS -urN parrot/config/auto/stackdir.pl 
parrot-patch/config/auto/stackdir.pl
--- parrot/config/auto/stackdir.pl      Wed Dec 31 19:00:00 1969
+++ parrot-patch/config/auto/stackdir.pl        Wed Aug 14 22:32:28 2002
@@ -0,0 +1,23 @@
+package Configure::Step;
+
+use strict;
+use vars qw($description @args);
+use Parrot::Configure::Step ':auto';
+
+$description = "Determining stack growth direction...";
+
+@args=qw(miniparrot);
+
+sub runstep {
+
+  cc_gen('config/auto/stackdir/test_c.in');
+  cc_build();
+  my %results=eval cc_run();
+  cc_clean();
+  
+  for(keys %results) {
+    Configure::Data->set($_ => $results{$_});
+  }
+}
+
+1;
diff --exclude=CVS -urN parrot/config/gen/config_h/config_h.in 
parrot-patch/config/gen/config_h/config_h.in
--- parrot/config/gen/config_h/config_h.in      Wed Aug  7 00:01:56 2002
+++ parrot-patch/config/gen/config_h/config_h.in        Wed Aug 14 22:32:28 2002
@@ -41,6 +41,7 @@
 #define PARROT_BYTEORDER        ${byteorder}
 #define PARROT_BIGENDIAN        ${bigendian}
 #define PARROT_PTR_ALIGNMENT    ${ptr_alignment}
+#define PARROT_STACK_DIR        ${stackdir}
 
 typedef Parrot_Int INTVAL;
 typedef Parrot_UInt UINTVAL;
diff --exclude=CVS -urN parrot/dod.c parrot-patch/dod.c
--- parrot/dod.c        Tue Aug 13 20:10:48 2002
+++ parrot-patch/dod.c  Wed Aug 14 22:32:30 2002
@@ -335,7 +335,6 @@
     size_t lo_var_ptr = (size_t)interpreter->lo_var_ptr;
     size_t hi_var_ptr = (size_t)&lo_var_ptr;
     ptrdiff_t cur_var_ptr;
-    ptrdiff_t direction = (hi_var_ptr > lo_var_ptr) ? 1 : -1;
 
     size_t buffer_min = get_min_buffer_address(interpreter);
     size_t buffer_max = get_max_buffer_address(interpreter);
@@ -346,8 +345,8 @@
         return last;
     
     for (cur_var_ptr = lo_var_ptr;
-         (ptrdiff_t)(cur_var_ptr * direction) < (ptrdiff_t)(hi_var_ptr * direction);
-         cur_var_ptr = (size_t)( (ptrdiff_t)cur_var_ptr + direction * 
PARROT_PTR_ALIGNMENT )
+         (ptrdiff_t)(cur_var_ptr * PARROT_STACK_DIR) < (ptrdiff_t)(hi_var_ptr * 
+PARROT_STACK_DIR);
+         cur_var_ptr = (size_t)( (ptrdiff_t)cur_var_ptr + PARROT_STACK_DIR * 
+PARROT_PTR_ALIGNMENT )
          ) {
         size_t ptr = *(size_t *)cur_var_ptr;
         if (pmc_min < ptr && ptr < pmc_max && is_pmc_ptr(interpreter,(void *)ptr)) {
diff --exclude=CVS -urN parrot/lib/Parrot/Configure/RunSteps.pm 
parrot-patch/lib/Parrot/Configure/RunSteps.pm
--- parrot/lib/Parrot/Configure/RunSteps.pm     Thu Jul 18 16:15:40 2002
+++ parrot-patch/lib/Parrot/Configure/RunSteps.pm       Wed Aug 14 22:32:28 2002
@@ -17,6 +17,7 @@
     auto/alignptrs.pl
        auto/headers.pl
        auto/sizes.pl
+       auto/stackdir.pl
        auto/byteorder.pl
        auto/pack.pl
        auto/format.pl

Reply via email to