On Mon, 20 Jan 2014 08:10:03 -0800 (PST) Volker Braun <[email protected]> wrote:
> http://trac.sagemath.org/ticket/15699 Since I'm currently unable to login to trac, I'll respond here: Since it is unlikely that scanf will succeed after having failed once (since it is then stuck somewhere in the middle of 0e+00) the code in the current patch will just fill the rest of the array with the last number that succeeded, disregarding anything remaining in the file. I think we can do better than that. Please find attached a patch on 540db9e211 (u/vbraun/glibc_scanf_workaround_for_atlas) that uses a different approach, namely replacing scanf by strtod. The patch is a bit more complicated than necessary, as checking "end ! = buf" instead of "errno == 0 && end ! = buf && *end == '\n'" is probably sufficient for this usecase. Regards, Erik Massop -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/groups/opt_out.
>From 3a7a922a8012857628d90c2f2625f08210d0c9dc Mon Sep 17 00:00:00 2001 From: Erik Massop <[email protected]> Date: Wed, 22 Jan 2014 11:47:06 +0100 Subject: [PATCH] Avoid scanf instead of just ignoring rest of file --- .../atlas/patches/glibc_scanf_workaround.patch | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/build/pkgs/atlas/patches/glibc_scanf_workaround.patch b/build/pkgs/atlas/patches/glibc_scanf_workaround.patch index f52eccd..9118aac 100644 --- a/build/pkgs/atlas/patches/glibc_scanf_workaround.patch +++ b/build/pkgs/atlas/patches/glibc_scanf_workaround.patch @@ -1,20 +1,29 @@ Bug in glibc-2.18: https://sourceware.org/bugzilla/show_bug.cgi?id=15917 -Patch taken from openSUSE 13.1 --- a/tune/sysinfo/masrch.c +++ b/tune/sysinfo/masrch.c -@@ -113,7 +113,12 @@ double matime +@@ -1,6 +1,7 @@ + #include <stdio.h> + #include <stdlib.h> + #include <assert.h> ++#include <errno.h> + + #ifndef NTIM + #define NTIM 3 +@@ -113,7 +114,14 @@ j = 0; for (i=0; i != NTIM; i++) { - assert( fscanf(fp, "%lf", &mflop[i]) ); -+ if(fscanf(fp, "%lf", &mflop[i])==0) { -+ if (i>0) -+ mflop[i]=mflop[i-1]; -+ else -+ assert(0); -+ } ++ /* FIXME: This assumes one float per line immediately followed by \n. */ ++ char buf[100]; /* enough to read a double */ ++ char *end; ++ ++ assert(fgets(buf, sizeof buf, fp)); ++ errno = 0; ++ mflop[i] = strtod(buf, &end); ++ assert(errno == 0 && end != buf && *end == '\n'); } fclose(fp); /* -- 1.8.5.2
