[Blotter-commits] r1609 - pkg/quantstrat/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu May 8 13:08:00 CEST 2014


Author: bodanker
Date: 2014-05-08 13:08:00 +0200 (Thu, 08 May 2014)
New Revision: 1609

Modified:
   pkg/quantstrat/src/firstCross.c
Log:
- Fix protect stack imbalance


Modified: pkg/quantstrat/src/firstCross.c
===================================================================
--- pkg/quantstrat/src/firstCross.c	2014-05-04 14:32:35 UTC (rev 1608)
+++ pkg/quantstrat/src/firstCross.c	2014-05-08 11:08:00 UTC (rev 1609)
@@ -16,42 +16,54 @@
     int_rel = asInteger(rel);
     int_start = asInteger(start)-1;
 
+    /* return number of observations if relationship is never TRUE */
+    SEXP result = ScalarInteger(nrows(x));
+
     switch(int_rel) {
         case 1:  /* >  */
             real_x = REAL(x);
             for(i=int_start; i<nrows(x); i++)
-                if(real_x[i] >  real_th)
-                    return(ScalarInteger(i+1));
+                if(real_x[i] >  real_th) {
+                    result = ScalarInteger(i+1);
+                    break;
+                }
             break;
         case 2:  /* <  */
             real_x = REAL(x);
             for(i=int_start; i<nrows(x); i++)
-                if(real_x[i] <  real_th)
-                    return(ScalarInteger(i+1));
+                if(real_x[i] >  real_th) {
+                    result = ScalarInteger(i+1);
+                    break;
+                }
             break;
         case 3:  /* == */
             real_x = REAL(x);
             for(i=int_start; i<nrows(x); i++)
-                if(real_x[i] == real_th)
-                    return(ScalarInteger(i+1));
+                if(real_x[i] >  real_th) {
+                    result = ScalarInteger(i+1);
+                    break;
+                }
             break;
         case 4:  /* >= */
             real_x = REAL(x);
             for(i=int_start; i<nrows(x); i++)
-                if(real_x[i] >= real_th)
-                    return(ScalarInteger(i+1));
+                if(real_x[i] >  real_th) {
+                    result = ScalarInteger(i+1);
+                    break;
+                }
             break;
         case 5:  /* <= */
             real_x = REAL(x);
             for(i=int_start; i<nrows(x); i++)
-                if(real_x[i] <= real_th)
-                    return(ScalarInteger(i+1));
+                if(real_x[i] >  real_th) {
+                    result = ScalarInteger(i+1);
+                    break;
+                }
             break;
         default:
             error("unsupported relationship operator");
   }
   UNPROTECT(P);
-  /* return number of observations if relationship is never TRUE */
-  return(ScalarInteger(nrows(x)));
+  return(result);
 }
 



More information about the Blotter-commits mailing list