[rkward-cvs] rkward/rkward/rbackend rembedinternal.cpp,1.41,1.42

Thomas Friedrichsmeier tfry at users.sourceforge.net
Mon Jun 19 20:04:33 UTC 2006


Update of /cvsroot/rkward/rkward/rkward/rbackend
In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv17490/rbackend

Modified Files:
	rembedinternal.cpp 
Log Message:
Simplify parsing, initialize na_double after R has started

Index: rembedinternal.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rembedinternal.cpp,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -d -r1.41 -r1.42
*** rembedinternal.cpp	20 Apr 2006 18:11:55 -0000	1.41
--- rembedinternal.cpp	19 Jun 2006 20:04:31 -0000	1.42
***************
*** 209,213 ****
  	RKGlobals::empty_char = strdup ("");
  	RKGlobals::unknown_char = strdup ("?");
! 	RKGlobals::na_double = NA_REAL;
  }
  
--- 209,213 ----
  	RKGlobals::empty_char = strdup ("");
  	RKGlobals::unknown_char = strdup ("?");
! //	RKGlobals::na_double = NA_REAL;			// this will be repeated in startR, as NA_REAL is 0 at this point!
  }
  
***************
*** 355,361 ****
  	R_CStackLimit = (unsigned long) -1;
  	setup_Rmainloop ();
  	return true;
  #else
! 	return (Rf_initEmbeddedR (argc, argv) >= 0);
  #endif
  }
--- 355,364 ----
  	R_CStackLimit = (unsigned long) -1;
  	setup_Rmainloop ();
+ 	RKGlobals::na_double = NA_REAL;
  	return true;
  #else
! 	bool ok = (Rf_initEmbeddedR (argc, argv) >= 0);
! 	RKGlobals::na_double = NA_REAL;
! 	return ok;
  #endif
  }
***************
*** 378,382 ****
  SEXP runCommandInternalBase (const char *command, REmbedInternal::RKWardRError *error) {
  // heavy copying from RServe below
- 	int maxParts=1;
  	int r_error = 0;
  	ParseStatus status = PARSE_NULL;
--- 381,384 ----
***************
*** 384,404 ****
  	SEXP cv, pr, exp;
  
- 	while (*c) {
- 		if (*c=='\n' || *c==';') maxParts++;
- 		c++;
- 	}
- 
  	PROTECT(cv=allocVector(STRSXP, 1));
  	SET_VECTOR_ELT(cv, 0, mkChar(command));  
  
  	// TODO: Maybe we can use R_ParseGeneral instead. Then we could find the exact character, where parsing fails
! 	while (maxParts>0) {
! 		pr=R_ParseVector(cv, maxParts, &status);
! 		// 2=incomplete; 4=eof
! 		if (status!=PARSE_INCOMPLETE && status!=PARSE_EOF) {
! 			break;
! 		}
! 		maxParts--;
! 	}
  	UNPROTECT(1);
  
--- 386,394 ----
  	SEXP cv, pr, exp;
  
  	PROTECT(cv=allocVector(STRSXP, 1));
  	SET_VECTOR_ELT(cv, 0, mkChar(command));  
  
  	// TODO: Maybe we can use R_ParseGeneral instead. Then we could find the exact character, where parsing fails
! 	pr=R_ParseVector(cv, -1, &status);
  	UNPROTECT(1);
  
***************
*** 449,452 ****
--- 439,444 ----
  	}
  
+ 	// for safety, let's protect exp for the two print calls below.
+ 	PROTECT (exp);
  	/* Do NOT ask me why, but the line below is needed for warnings to be printed, while otherwise they would not be shown.
  	Apparently we need to print at least something in order to achieve this. Whatever really happens in Rprintf () to have such an effect, I did not bother to find out. */
***************
*** 456,460 ****
  
  //	SET_SYMVALUE(R_LastvalueSymbol, exp);
! 
  	return exp;
  }
--- 448,452 ----
  
  //	SET_SYMVALUE(R_LastvalueSymbol, exp);
! 	UNPROTECT (1);		// exp; We unprotect this, as most of the time the caller is not really interested in the result
  	return exp;
  }
***************
*** 541,546 ****
  		reals = new double[*count];
  		for (int i = 0; i < *count; ++i) {
! 				reals[i] = REAL (realexp)[i];
! 				if (R_IsNaN (reals[i]) || R_IsNA (reals[i]) ) reals[i] = RKGlobals::na_double;
  		}
  		UNPROTECT (1);	// realexp
--- 533,538 ----
  		reals = new double[*count];
  		for (int i = 0; i < *count; ++i) {
! 			reals[i] = REAL (realexp)[i];
! 			if (R_IsNaN (reals[i]) || R_IsNA (reals[i]) ) reals[i] = RKGlobals::na_double;
  		}
  		UNPROTECT (1);	// realexp





More information about the rkward-tracker mailing list