[GRASS-dev] r.terraflow Windows patch

Glynn Clements glynn at gclements.plus.com
Wed Mar 12 16:14:44 EDT 2008


Moritz Lennert wrote:

> >> > Can someone test the attached patch on Windows (MSys)?
> >>
> >> I now get:
> >>
> >> main.cc: In function `void record_args(int, char**)':
> >> main.cc:327: error: `ctime_r' undeclared (first use this function)
> >
> > The attached patch should fix that issue.
> >
> > If there are any remaining errors, please use "make -k", so that you
> > get all of them.
> 
> Log attached.

The attached patch supersedes both previous patches, and should be
applied to the stock SVN source (either revert the previous patches
with "patch -R ...", or use "svn revert").

-- 
Glynn Clements <glynn at gclements.plus.com>

-------------- next part --------------
Index: raster/r.terraflow/main.cc
===================================================================
--- raster/r.terraflow/main.cc	(revision 30536)
+++ raster/r.terraflow/main.cc	(working copy)
@@ -324,8 +324,12 @@
     exit(1);
   }
 
+#ifdef __MINGW32__
+  strcpy(buf, ctime(&t));
+#else
   ctime_r(&t, buf);
   buf[24] = '\0';
+#endif
   stats->timestamp(buf);
   
   *stats << "Command Line: " << endl;
@@ -519,7 +523,8 @@
  
   /* check STREAM path (the place where intermediate STREAMs are placed) */
   sprintf(buf, "%s=%s",STREAM_TMPDIR, opt->streamdir);
-  putenv(buf);
+  /* don't pass an automatic variable; putenv() isn't guaranteed to make a copy */
+  putenv(G_store(buf));
   if (getenv(STREAM_TMPDIR) == NULL) {
     fprintf(stderr, "%s:", STREAM_TMPDIR);
     G_fatal_error("not set");
Index: raster/r.terraflow/common.cc
===================================================================
--- raster/r.terraflow/common.cc	(revision 30536)
+++ raster/r.terraflow/common.cc	(working copy)
@@ -18,7 +18,9 @@
 
 
 #include <sys/types.h>
+#ifdef USE_LARGEMEM
 #include <sys/mman.h>
+#endif
 #include <ctype.h>
 
 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
Index: raster/r.terraflow/stats.cc
===================================================================
--- raster/r.terraflow/stats.cc	(revision 30536)
+++ raster/r.terraflow/stats.cc	(working copy)
@@ -21,7 +21,9 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/time.h>
+#ifndef __MINGW32__
 #include <sys/resource.h>
+#endif
 #include <stdio.h>
 #include <errno.h>
 
@@ -126,7 +128,9 @@
   //ofstream that takes an fd; wrote another noclobber() function that
   //closes fd and returns the name;
   rt_start(tm);
+#ifndef __MINGW32__
   bss = sbrk(0);
+#endif
   char buf[BUFSIZ];
   *this << freeMem(buf) << endl;
 }
@@ -135,6 +139,9 @@
 
 long 
 statsRecorder::freeMem() {
+#ifdef __MINGW32__
+  return -1;
+#else
   struct rlimit rlim;
   if (getrlimit(RLIMIT_DATA, &rlim) == -1) {
 	perror("getrlimit: ");
@@ -148,6 +155,7 @@
   } 
   long freeMem = rlim.rlim_cur - ((char*)sbrk(0)-(char*)bss);
   return freeMem;
+#endif /* __MINGW32__ */
 }
 
 char *
Index: raster/r.terraflow/IOStream/include/rtimer.h
===================================================================
--- raster/r.terraflow/IOStream/include/rtimer.h	(revision 30536)
+++ raster/r.terraflow/IOStream/include/rtimer.h	(working copy)
@@ -22,6 +22,38 @@
 
 /* $Id$ */
 
+#ifdef __MINGW32__
+
+#include <time.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+
+typedef struct {
+  time_t tv1, tv2;
+} Rtimer;
+
+#define rt_start(rt)				\
+  if((time(&(rt.tv1)) == ((time_t) -1))) {	\
+	perror("time");				\
+	exit(1);				\
+  }
+
+/* doesn't really stop, just updates endtimes */
+#define rt_stop(rt)								\
+  if((time(&(rt.tv2)) == ((time_t) -1))) {	\
+	perror("time");				\
+	exit(1);				\
+  }
+
+#define rt_u_useconds(rt)	rt_w_useconds(rt)
+
+#define rt_s_useconds(rt)	rt_w_useconds(rt)
+
+#define rt_w_useconds(rt)	(1.0e6 * (rt.tv2 - rt.tv1))
+
+#else /* __MINGW32__ */
+
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <stdio.h>
@@ -48,10 +80,6 @@
         perror("rusage/gettimeofday");			\
         exit(1);								\
   }
-
-/* not required to be called, but makes values print as 0. 
-   obviously a hack */
-#define rt_zero(rt) bzero(&(rt),sizeof(Rtimer));
 	
 
 #define rt_u_useconds(rt)							\
@@ -72,12 +100,16 @@
 	  - ((double)rt.tv1.tv_usec +			\
 		 (double)rt.tv1.tv_sec*1000000))
 
+#endif /* __MINGW32__ */
+
+/* not required to be called, but makes values print as 0. 
+   obviously a hack */
+#define rt_zero(rt) bzero(&(rt),sizeof(Rtimer));
+
 #define rt_seconds(rt) (rt_w_useconds(rt)/1000000)
 
 #define rt_sprint(buf, rt) rt_sprint_safe(buf,rt)
 
 char * rt_sprint_safe(char *buf, Rtimer rt);
 
-
-
 #endif /* RTIMER_H */
Index: raster/r.terraflow/IOStream/include/ami_stream.h
===================================================================
--- raster/r.terraflow/IOStream/include/ami_stream.h	(revision 30536)
+++ raster/r.terraflow/IOStream/include/ami_stream.h	(working copy)
@@ -36,6 +36,10 @@
 
 #include "mm.h" // Get the memory manager.
 
+#ifdef __MINGW32__
+#define getpagesize() (4096)
+#endif
+
 #define DEBUG_DELETE if(0)
 
 // The name of the environment variable which keeps the name of the
@@ -421,7 +425,7 @@
   
   // Get rid of the file if not persistent and if not substream.
   if ((per != PERSIST_PERSISTENT) && (substream_level == 0)) {
-    if (unlink(path) == -1) {
+    if (remove(path) == -1) {
       cerr << "AMI_STREAM: failed to unlink " << path << endl;
       perror("cannot unlink ");
       assert(0);
Index: raster/r.terraflow/IOStream/include/quicksort.h
===================================================================
--- raster/r.terraflow/IOStream/include/quicksort.h	(revision 30536)
+++ raster/r.terraflow/IOStream/include/quicksort.h	(working copy)
@@ -41,7 +41,11 @@
     
     // Try to get a good partition value and avoid being bitten by already
     // sorted input.
+#ifdef __MINGW32__
+    ptpart = data + (rand() % n);
+#else
     ptpart = data + (random() % n);
+#endif
     tpart = *ptpart;
     *ptpart = data[0];
     data[0] = tpart;
Index: raster/r.terraflow/IOStream/lib/src/ami_stream.cc
===================================================================
--- raster/r.terraflow/IOStream/lib/src/ami_stream.cc	(revision 30536)
+++ raster/r.terraflow/IOStream/lib/src/ami_stream.cc	(working copy)
@@ -42,7 +42,11 @@
   assert(base_dir);
 
   sprintf(tmp_path, "%s/%s_XXXXXX", base_dir, base);
+#ifdef __MINGW32__
+  fd = mktemp(tmp_path) ? open(tmp_path, O_CREAT|O_EXCL|O_RDWR, 0600) : -1;
+#else
   fd  = mkstemp(tmp_path);
+#endif
 
   if (fd == -1) {
     cerr <<  "ami_single_temp_name: ";
Index: raster/r.terraflow/IOStream/lib/src/rtimer.cc
===================================================================
--- raster/r.terraflow/IOStream/lib/src/rtimer.cc	(revision 30536)
+++ raster/r.terraflow/IOStream/lib/src/rtimer.cc	(working copy)
@@ -18,7 +18,6 @@
 
 
 #include <sys/time.h>
-#include <sys/resource.h>
 #include <stdio.h>
 #include <string.h>
 #include <strings.h>
Index: raster/r.terraflow/IOStream/lib/src/mm_utils.cc
===================================================================
--- raster/r.terraflow/IOStream/lib/src/mm_utils.cc	(revision 30536)
+++ raster/r.terraflow/IOStream/lib/src/mm_utils.cc	(working copy)
@@ -17,7 +17,6 @@
  *****************************************************************************/
 
 #include <sys/types.h>
-#include <sys/mman.h>
 #include <ctype.h>
 
 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
Index: raster/r.terraflow/flow.cc
===================================================================
--- raster/r.terraflow/flow.cc	(revision 30536)
+++ raster/r.terraflow/flow.cc	(working copy)
@@ -64,8 +64,12 @@
       perror("time");
       exit(1);
     }
+#ifdef __MINGW32__
+    strcpy(buf, ctime(&t));
+#else
     ctime_r(&t, buf);
     buf[24] = '\0';
+#endif
     stats->timestamp(buf);
     *stats << endl;  
     


More information about the grass-dev mailing list