[Pkg-bitcoin-commits] [libunivalue] 30/76: remove optional compiling/linking of numparse functions, take them local

Jonas Smedegaard dr at jones.dk
Mon Apr 4 09:18:29 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libunivalue.

commit c00cda398db8abe4b038010ba5a409ef1731918f
Author: Jonas Schnelli <jonas.schnelli at include7.ch>
Date:   Mon Sep 7 15:12:12 2015 +0200

    remove optional compiling/linking of numparse functions, take them local
---
 configure.ac        |  8 -------
 lib/Makefile.am     |  7 ------
 lib/numberparse.cpp | 67 -----------------------------------------------------
 lib/univalue.cpp    | 65 ++++++++++++++++++++++++++++++++++++++++++++++++---
 4 files changed, 62 insertions(+), 85 deletions(-)

diff --git a/configure.ac b/configure.ac
index 85f8eaf..f33b057 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,14 +21,6 @@ AC_PATH_TOOL(RANLIB, ranlib)
 AC_PATH_TOOL(STRIP, strip)
 PKG_PROG_PKG_CONFIG
 
-# Enable numfunc
-AC_ARG_WITH([numfunc],
-  [AS_HELP_STRING([--with-numfunc],
-  [enable compiling of number parsing functions (default is yes)])],
-  [use_numfunc=$withval],
-  [use_numfunc=yes])
-AM_CONDITIONAL([USE_NUMFUNC], [test x$use_numfunc = xyes])
-
 AC_LANG_PUSH([C++])
 
 AC_CONFIG_FILES([lib/Makefile test/Makefile Makefile])
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 7b2712b..a287dc6 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -8,13 +8,6 @@ libunivalue_a_SOURCES = \
 	univalue_read.cpp \
 	univalue_write.cpp
 
-# ----------------------------------
-# optional add numberparse functions
-# ----------------------------------
-if USE_NUMFUNC
-libunivalue_a_SOURCES += numberparse.cpp
-endif
-
 noinst_PROGRAMS = gen
 
 gen_SOURCES = gen.cpp
diff --git a/lib/numberparse.cpp b/lib/numberparse.cpp
deleted file mode 100644
index e04daec..0000000
--- a/lib/numberparse.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2015 Bitcoin Core Developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-#include <limits>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <locale>
-#include <sstream>
-
-static bool ParsePrechecks(const std::string& str)
-{
-    if (str.empty()) // No empty string allowed
-        return false;
-    if (str.size() >= 1 && (isspace(str[0]) || isspace(str[str.size()-1]))) // No padding allowed
-        return false;
-    if (str.size() != strlen(str.c_str())) // No embedded NUL characters allowed
-        return false;
-    return true;
-}
-
-bool ParseInt32(const std::string& str, int32_t *out)
-{
-    if (!ParsePrechecks(str))
-        return false;
-    char *endp = NULL;
-    errno = 0; // strtol will not set errno if valid
-    long int n = strtol(str.c_str(), &endp, 10);
-    if(out) *out = (int32_t)n;
-    // Note that strtol returns a *long int*, so even if strtol doesn't report a over/underflow
-    // we still have to check that the returned value is within the range of an *int32_t*. On 64-bit
-    // platforms the size of these types may be different.
-    return endp && *endp == 0 && !errno &&
-        n >= std::numeric_limits<int32_t>::min() &&
-        n <= std::numeric_limits<int32_t>::max();
-}
-
-bool ParseInt64(const std::string& str, int64_t *out)
-{
-    if (!ParsePrechecks(str))
-        return false;
-    char *endp = NULL;
-    errno = 0; // strtoll will not set errno if valid
-    long long int n = strtoll(str.c_str(), &endp, 10);
-    if(out) *out = (int64_t)n;
-    // Note that strtoll returns a *long long int*, so even if strtol doesn't report a over/underflow
-    // we still have to check that the returned value is within the range of an *int64_t*.
-    return endp && *endp == 0 && !errno &&
-        n >= std::numeric_limits<int64_t>::min() &&
-        n <= std::numeric_limits<int64_t>::max();
-}
-
-bool ParseDouble(const std::string& str, double *out)
-{
-    if (!ParsePrechecks(str))
-        return false;
-    if (str.size() >= 2 && str[0] == '0' && str[1] == 'x') // No hexadecimal floats allowed
-        return false;
-    std::istringstream text(str);
-    text.imbue(std::locale::classic());
-    double result;
-    text >> result;
-    if(out) *out = result;
-    return text.eof() && !text.fail();
-}
-
diff --git a/lib/univalue.cpp b/lib/univalue.cpp
index a4d5b94..883e865 100644
--- a/lib/univalue.cpp
+++ b/lib/univalue.cpp
@@ -5,15 +5,74 @@
 
 #include <stdint.h>
 #include <ctype.h>
+#include <errno.h>
 #include <iomanip>
+#include <limits>
 #include <sstream>
 #include <stdexcept>
+#include <stdlib.h>
+#include <string.h>
 
 #include "univalue.h"
 
-extern bool ParseInt32(const std::string& str, int32_t *out);
-extern bool ParseInt64(const std::string& str, int64_t *out);
-extern bool ParseDouble(const std::string& str, double *out);
+namespace 
+{
+static bool ParsePrechecks(const std::string& str)
+{
+    if (str.empty()) // No empty string allowed
+        return false;
+    if (str.size() >= 1 && (isspace(str[0]) || isspace(str[str.size()-1]))) // No padding allowed
+        return false;
+    if (str.size() != strlen(str.c_str())) // No embedded NUL characters allowed
+        return false;
+    return true;
+}
+
+bool ParseInt32(const std::string& str, int32_t *out)
+{
+    if (!ParsePrechecks(str))
+        return false;
+    char *endp = NULL;
+    errno = 0; // strtol will not set errno if valid
+    long int n = strtol(str.c_str(), &endp, 10);
+    if(out) *out = (int32_t)n;
+    // Note that strtol returns a *long int*, so even if strtol doesn't report a over/underflow
+    // we still have to check that the returned value is within the range of an *int32_t*. On 64-bit
+    // platforms the size of these types may be different.
+    return endp && *endp == 0 && !errno &&
+        n >= std::numeric_limits<int32_t>::min() &&
+        n <= std::numeric_limits<int32_t>::max();
+}
+
+bool ParseInt64(const std::string& str, int64_t *out)
+{
+    if (!ParsePrechecks(str))
+        return false;
+    char *endp = NULL;
+    errno = 0; // strtoll will not set errno if valid
+    long long int n = strtoll(str.c_str(), &endp, 10);
+    if(out) *out = (int64_t)n;
+    // Note that strtoll returns a *long long int*, so even if strtol doesn't report a over/underflow
+    // we still have to check that the returned value is within the range of an *int64_t*.
+    return endp && *endp == 0 && !errno &&
+        n >= std::numeric_limits<int64_t>::min() &&
+        n <= std::numeric_limits<int64_t>::max();
+}
+
+bool ParseDouble(const std::string& str, double *out)
+{
+    if (!ParsePrechecks(str))
+        return false;
+    if (str.size() >= 2 && str[0] == '0' && str[1] == 'x') // No hexadecimal floats allowed
+        return false;
+    std::istringstream text(str);
+    text.imbue(std::locale::classic());
+    double result;
+    text >> result;
+    if(out) *out = result;
+    return text.eof() && !text.fail();
+}
+}
 
 using namespace std;
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/libunivalue.git



More information about the Pkg-bitcoin-commits mailing list