From dda72768155ec16d741d5583b98f70bd149bc989 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 31 Aug 2026 00:28:48 +0000 Subject: [PATCH] Drop the C shim for float formatting now that jsonpull is C++ json_print_one() reached fpfmt through dtoa_shortest(), a C-linkage wrapper in text.cpp that strdup()ed the formatted string so the C jsonpull could take it and free() it. jsonpull has been C++ since 4f26211, so it can append the std::string directly and skip the copy, the allocation, and the free. That was the shim's only caller, so fpfmt/fpfmt.h goes away with it. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_014wJRAuhMninQE4wK2TUfuZ --- CHANGELOG.md | 4 +++- fpfmt/fpfmt.h | 14 -------------- jsonpull/jsonpull.cpp | 6 ++---- text.cpp | 12 ------------ 4 files changed, 5 insertions(+), 31 deletions(-) delete mode 100644 fpfmt/fpfmt.h diff --git a/CHANGELOG.md b/CHANGELOG.md index bd0d7d54..7212f192 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,9 @@ final digit (`9.823748927348929e+55` becomes `9.823748927348928e+55`). Every such value still parses back to exactly the same double, so this changes only the spelling, never the number. `make fpfmt-bench` rebuilds the head-to-head - comparison against the old implementation. + comparison against the old implementation. `jsonpull`, now that it is C++, + calls `fpfmt::dtoa()` directly rather than through the `strdup`ing C shim + that `milo/milo.h` used to declare. # 2.82.0 diff --git a/fpfmt/fpfmt.h b/fpfmt/fpfmt.h deleted file mode 100644 index 9a0bd71f..00000000 --- a/fpfmt/fpfmt.h +++ /dev/null @@ -1,14 +0,0 @@ -// C-callable shortest-float formatting, for jsonpull. -// The implementation lives in text.cpp and calls fpfmt::dtoa(). - -#ifdef __cplusplus -extern "C" { -#endif - -// dtoa_shortest returns a newly strdup()ed shortest decimal form of val. -// The caller owns the result. -char *dtoa_shortest(double val); - -#ifdef __cplusplus -} -#endif diff --git a/jsonpull/jsonpull.cpp b/jsonpull/jsonpull.cpp index 36928267..5f896e47 100644 --- a/jsonpull/jsonpull.cpp +++ b/jsonpull/jsonpull.cpp @@ -11,7 +11,7 @@ #include #include #include "jsonpull.h" -#include "../fpfmt/fpfmt.h" +#include "../fpfmt/fpfmt.hpp" #define BUFFER 10000 @@ -803,9 +803,7 @@ static void json_print_one(std::string &val, const json_object *o) { snprintf(s, sizeof(s), "%llu", o->large_unsigned()); val.append(s); } else { - char *s = dtoa_shortest(o->number()); - val.append(s); - free(s); + val.append(fpfmt::dtoa(o->number())); } } else if (o->type == JSON_NULL) { val.append("null"); diff --git a/text.cpp b/text.cpp index 20f4d6a2..6d6e5445 100644 --- a/text.cpp +++ b/text.cpp @@ -6,7 +6,6 @@ #include #include "text.hpp" #include "fpfmt/fpfmt.hpp" -#include "fpfmt/fpfmt.h" #include "errors.hpp" /** @@ -176,17 +175,6 @@ std::string format_commandline(int argc, char **argv) { return out; } -// for jsonpull to call from C -char *dtoa_shortest(double val) { - std::string s = fpfmt::dtoa(val); - char *dup = strdup(s.c_str()); - if (dup == NULL) { - perror("strdup"); - exit(EXIT_MEMORY); - } - return dup; -} - // to work with data from https://github.com/kmike/text-unidecode std::vector read_unidecode(const char *fname) { std::string data;