On Fri, Aug 20, 2010 at 2:27 AM, Romain Francois
<[email protected]>wrote:

> I have not seen any of these files. But note that, as Dirk said before,
> please send patches rather than full copy of modified files.
>
> From some directory of your modified Rcpp tree, just do :
>
> $ svn diff > mypatch.diff
>
> and send that file, that should be ok.
>
> If you want to add files with this mechanism, you can. Just do
>
> $ svn add whatever/file
> $ svn diff > mypatch.diff
>
> The only thing you cannot do is svn commit.


The diff file msvc.patch.txt is attached, along with the three new .h files
that
should go into Rcpp/inst/include/msvc (or something else if you prefer).

While I could 'svn add Rcpp/src/msvcmath.cpp' I could not do this
for the .h files because the directory Rcpp/inst/include/msvc does not
exist,
and I couldn't create it.

These changes will permit compilation with Visual C++. The warning level
needs to be changed from the default to prevent a large number of
warning messages. The main purpose would be to check that the
C++ code is portable. If these changes are added you probably want to
note that MSVC is not officially (or even unofficially) supported.

On the tags/branches question, it appears that all projects on R-Forge are
laid out without the usual tags and branches subdirectories.Is this due to
restrictions at R-Forge? I guess the way to fetch files corresponding to
a particular CRAN release is to get versions that were current at the
time that the CRAN release happened, right?

Thanks,
Dominick
Index: src/RcppCommon.cpp
===================================================================
--- src/RcppCommon.cpp  (revision 2038)
+++ src/RcppCommon.cpp  (working copy)
@@ -197,7 +197,7 @@
        std::vector<int> *v = new std::vector<int> ;
        v->push_back( 1 ) ;
        v->push_back( 2 ) ;
-       Rcpp::XPtr< std::vector<int> > p(v) ;
+       Rcpp::XPtr< std::vector<int> > p(v, true) ;
        return p ;
 }
 
Index: src/msvcmath.cpp
===================================================================
--- src/msvcmath.cpp    (revision 0)
+++ src/msvcmath.cpp    (revision 0)
@@ -0,0 +1,49 @@
+#ifdef _MSC_VER
+
+#include <math.h>
+#include <stdexcept>
+#include "msvc/math.h"
+
+// This is adapted from code by John D. Cook, released to public domain.
+// See http://www.johndcook.com/math_h.html.
+
+double log1p(double x) {
+    if(x <= -1.0)
+       throw std::range_error("log1p: arg <= -1");
+    if(fabs(x) > 1.e-4)
+       return log(1.0 + x);
+    return (-0.5*x + 1.0)*x;
+}
+
+double erf(double x)
+{
+    // constants
+    double a1 =  0.254829592;
+    double a2 = -0.284496736;
+    double a3 =  1.421413741;
+    double a4 = -1.453152027;
+    double a5 =  1.061405429;
+    double p  =  0.3275911;
+
+    // Save the sign of x
+    int sign = 1;
+    if (x < 0)
+        sign = -1;
+    x = fabs(x);
+
+    // A&S formula 7.1.26
+    double t = 1.0/(1.0 + p*x);
+    double y = 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x);
+
+    return sign*y;
+}
+
+// Compute exp(x) - 1 without loss of precision for small values of x.
+double expm1(double x)
+{
+    if (fabs(x) < 1e-5)
+       return x + 0.5*x*x;
+    else
+       return exp(x) - 1.0;
+}
+#endif
\ No newline at end of file
Index: src/Date.cpp
===================================================================
--- src/Date.cpp        (revision 2038)
+++ src/Date.cpp        (working copy)
@@ -28,7 +28,11 @@
 #include <Rcpp/Date.h>
 #include <Rcpp/Function.h>
 #include <time.h>              // for gmtime
+#ifdef _MSC_VER /* not included with MSVC 2008 or MSVC 2010 */
+#include <msvc/unistd.h>
+#else
 #include <unistd.h>            // for read and close on Solaris
+#endif
 
 namespace Rcpp {
 
@@ -177,7 +181,11 @@
 #endif
 
 #include "stdlib.h"
+#if _MSC_VER < 1600 /* missing from MSVC 2008 (1500), present with MSVC 2010 
(1600) */
+#include "msvc/stdint.h"
+#else
 #include "stdint.h"
+#endif
 #include "stdio.h"
 #include "fcntl.h"
 #include "float.h"     /* for FLT_MAX and DBL_MAX */
Index: inst/include/RcppCommon.h
===================================================================
--- inst/include/RcppCommon.h   (revision 2038)
+++ inst/include/RcppCommon.h   (working copy)
@@ -119,6 +119,11 @@
 #define RcppExport extern "C"
 // #endif
 
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#include <msvc/math.h>
+#endif
+
 #include <Rcpp/internal/posixt.h>
 
 namespace Rcpp{
Index: inst/include/Rcpp/XPtr.h
===================================================================
--- inst/include/Rcpp/XPtr.h    (revision 2038)
+++ inst/include/Rcpp/XPtr.h    (working copy)
@@ -59,7 +59,11 @@
      *        so you need to make sure the pointer can be "delete" d
      *        this way (has to be a C++ object)
      */
+#ifdef _MSC_VER
+    explicit XPtr(T* p, bool set_delete_finalizer, SEXP tag = R_NilValue, SEXP 
prot = R_NilValue) ;
+#else
     explicit XPtr(T* p, bool set_delete_finalizer, SEXP tag, SEXP prot) ;
+#endif
 
     XPtr( const XPtr& other ) : RObject( other.asSexp() ) {}
     

Attachment: math.h
Description: Binary data

Attachment: stdint.h
Description: Binary data

Attachment: unistd.h
Description: Binary data

_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to