[Pomp-commits] r115 - pkg/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 29 03:35:49 CEST 2009


Author: kingaa
Date: 2009-04-29 03:35:48 +0200 (Wed, 29 Apr 2009)
New Revision: 115

Modified:
   pkg/src/bspline.c
   pkg/src/dsobol.c
Log:


Modified: pkg/src/bspline.c
===================================================================
--- pkg/src/bspline.c	2009-04-28 12:04:28 UTC (rev 114)
+++ pkg/src/bspline.c	2009-04-29 01:35:48 UTC (rev 115)
@@ -7,6 +7,7 @@
 // B-spline basis
 
 SEXP bspline_basis (SEXP x, SEXP degree, SEXP knots) {
+  int nprotect = 0;
   SEXP y;
   int nx = length(x);
   int nknots = length(knots);
@@ -15,17 +16,18 @@
   double *ydata;
   int i;
   if (deg < 0) error("must have degree > 0 in 'bspline.basis'");
-  PROTECT(y = allocMatrix(REALSXP,nx,nbasis));
+  PROTECT(y = allocMatrix(REALSXP,nx,nbasis)); nprotect++;
   ydata = REAL(y);
   for (i = 0; i < nbasis; i++) {
     bspline_internal(ydata,REAL(x),nx,i,deg,REAL(knots),nknots);
     ydata += nx;
   }
-  UNPROTECT(1);
+  UNPROTECT(nprotect);
   return(y);
 }
 
 SEXP bspline_basis_function (SEXP x, SEXP i, SEXP degree, SEXP knots) {
+  int nprotect = 0;
   SEXP y;
   int nx = length(x);
   int nknots = length(knots);
@@ -35,9 +37,9 @@
   if ((ival < 0) || (deg < 0) || (ival + deg >= nknots-1)) 
     error("bad arguments in 'bspline'");
 
-  PROTECT(y = NEW_NUMERIC(nx));
+  PROTECT(y = NEW_NUMERIC(nx)); nprotect++;
   bspline_internal(REAL(y),REAL(x),nx,ival,deg,REAL(knots),nknots);
-  UNPROTECT(1);
+  UNPROTECT(nprotect);
   return(y);
 }
 

Modified: pkg/src/dsobol.c
===================================================================
--- pkg/src/dsobol.c	2009-04-28 12:04:28 UTC (rev 114)
+++ pkg/src/dsobol.c	2009-04-29 01:35:48 UTC (rev 115)
@@ -8,12 +8,13 @@
 
 SEXP sobol_sequence (SEXP dim)
 {
+  int nprotect = 0;
   SEXP data;
   int d = INTEGER(dim)[0];
   int n = INTEGER(dim)[1];
-  PROTECT(data = allocMatrix(REALSXP,d,n));
+  PROTECT(data = allocMatrix(REALSXP,d,n)); nprotect++;
   dsobol(REAL(data),d,n);
-  UNPROTECT(1);
+  UNPROTECT(nprotect);
   return(data);
 }
 



More information about the pomp-commits mailing list