/ Check-in [bc9a9a60]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix the JSON1 extension so that it does not depend on isdigit() and strtod() from the standard library when compiled into SQLite as part of the amalgamation.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bc9a9a60c31ebf9b11ac89ae5f99a3b66d6efc67
User & Date: drh 2015-10-16 15:35:39
Context
2015-10-16
15:56
Cherrypick the json form-feed fix, and other #ifdef and build script changes to address minor issues that came to light after the 3.9.0 release. Update the version number to 3.9.1. No logic changes except for the form-feed bug-fix in json1 (ticket [57eec374ae1d0a1d4a]). check-in: 746fcd2f user: drh tags: branch-3.9
15:42
Fix the fuzzershell utility program so that it compiles with the amalgamation that includes JSON1 support. check-in: d6fc616e user: drh tags: trunk
15:35
Fix the JSON1 extension so that it does not depend on isdigit() and strtod() from the standard library when compiled into SQLite as part of the amalgamation. check-in: bc9a9a60 user: drh tags: trunk
15:16
Form-feed is not valid whitespace for json. Fix for ticket [57eec374ae1d0a1d] check-in: 28957d63 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/misc/json1.c.

    24     24   #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_JSON1)
    25     25   #if !defined(_SQLITEINT_H_)
    26     26   #include "sqlite3ext.h"
    27     27   #endif
    28     28   SQLITE_EXTENSION_INIT1
    29     29   #include <assert.h>
    30     30   #include <string.h>
    31         -#include <ctype.h>  /* amalgamator: keep */
    32     31   #include <stdlib.h>
    33     32   #include <stdarg.h>
    34     33   
    35     34   #define UNUSED_PARAM(X)  (void)(X)
    36     35   
    37     36   #ifndef LARGEST_INT64
    38     37   # define LARGEST_INT64  (0xffffffff|(((sqlite3_int64)0x7fffffff)<<32))
................................................................................
    39     38   # define SMALLEST_INT64 (((sqlite3_int64)-1) - LARGEST_INT64)
    40     39   #endif
    41     40   
    42     41   /*
    43     42   ** Versions of isspace(), isalnum() and isdigit() to which it is safe
    44     43   ** to pass signed char values.
    45     44   */
    46         -#define safe_isdigit(x) isdigit((unsigned char)(x))
    47         -#define safe_isalnum(x) isalnum((unsigned char)(x))
           45  +#ifdef sqlite3Isdigit
           46  +   /* Use the SQLite core versions if this routine is part of the
           47  +   ** SQLite amalgamation */
           48  +#  define safe_isdigit(x) sqlite3Isdigit(x)
           49  +#  define safe_isalnum(x) sqlite3Isalnum(x)
           50  +#else
           51  +   /* Use the standard library for separate compilation */
           52  +#include <ctype.h>  /* amalgamator: keep */
           53  +#  define safe_isdigit(x) isdigit((unsigned char)(x))
           54  +#  define safe_isalnum(x) isalnum((unsigned char)(x))
           55  +#endif
    48     56   
    49     57   /*
    50     58   ** Growing our own isspace() routine this way is twice as fast as
    51     59   ** the library isspace() function, resulting in a 7% overall performance
    52     60   ** increase for the parser.  (Ubuntu14.10 gcc 4.8.4 x64 with -Os).
    53     61   */
    54     62   static const char jsonIsSpace[] = {
................................................................................
   510    518         if( pNode->u.zJContent[0]=='-' ){ i = -i; }
   511    519         sqlite3_result_int64(pCtx, i);
   512    520         int_done:
   513    521         break;
   514    522         int_as_real: /* fall through to real */;
   515    523       }
   516    524       case JSON_REAL: {
   517         -      double r = strtod(pNode->u.zJContent, 0);
          525  +      double r;
          526  +#ifdef SQLITE_AMALGAMATION
          527  +      const char *z = pNode->u.zJContent;
          528  +      sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8);
          529  +#else
          530  +      r = strtod(pNode->u.zJContent, 0);
          531  +#endif
   518    532         sqlite3_result_double(pCtx, r);
   519    533         break;
   520    534       }
   521    535       case JSON_STRING: {
   522    536   #if 0 /* Never happens because JNODE_RAW is only set by json_set(),
   523    537         ** json_insert() and json_replace() and those routines do not
   524    538         ** call jsonReturn() */