1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
|
#include "EXTERN.h"
#include "perl.h"
#include <stdint.h>
#include "XSUB.h"
/* TESTRANDOM should never be defined in the code released to
CPAN. That this is not defined is tested in
"xt/testrandom-invalid.t". */
//#define TESTRANDOM
#ifdef TESTRANDOM
#include <setjmp.h>
#endif /* def TESTRANDOM */
/* A structure representing the "null" in JSON. Although we're now
using PL_sv_yes and PL_sv_no, we don't use PL_sv_undef, because
perldoc perlguts says it's a bad idea. */
static SV * json_null;
/* Code starts here. */
#include "unicode.h"
#include "unicode.c"
#include "json-common.c"
#define PERLING
#include "json-perl.c"
#undef PERLING
#define TOKENING
#include "json-perl.c"
#undef TOKENING
#include "json-perl.c"
#include "json-entry-points.c"
#ifdef TESTRANDOM
#include "json-random-test.c"
#endif /* def TESTRANDOM */
#include "json-whitespace.c"
#ifdef NOPERL
#error "Cannot define NOPERL error when compiling Perl version"
#endif /* def NOPERL */
typedef json_parse_t * JSON__Parse;
typedef json_token_t * JSON__Tokenize;
MODULE=JSON::Parse PACKAGE=JSON::Parse
PROTOTYPES: DISABLE
BOOT:
{
json_null = get_sv ("JSON::Parse::null", GV_ADD);
SvREADONLY_on (json_null);
}
SV * parse_json (json)
SV * json;
CODE:
RETVAL = parse (json);
OUTPUT:
RETVAL
SV * parse_json_safer (json)
SV * json;
CODE:
RETVAL = parse_safe (json);
OUTPUT:
RETVAL
void assert_valid_json (json)
SV * json;
CODE:
validate (json, 0);
JSON::Parse
new (char * class, ...)
CODE:
if (! class) {
croak ("no class");
}
Newxz (RETVAL, 1, json_parse_t);
json_parse_init (RETVAL);
OUTPUT:
RETVAL
SV * run_internal (parser, json)
JSON::Parse parser
SV * json
CODE:
RETVAL = json_parse_run (parser, json);
OUTPUT:
RETVAL
void
check (parser, json)
JSON::Parse parser
SV * json
CODE:
check (parser, json);
void
DESTROY (parser)
JSON::Parse parser;
CODE:
json_parse_free (parser);
void
set_true (parser, user_true)
JSON::Parse parser;
SV * user_true;
CODE:
json_parse_set_true (parser, user_true);
void
set_false (parser, user_false)
JSON::Parse parser;
SV * user_false;
CODE:
json_parse_set_false (parser, user_false);
void
set_null (parser, user_null)
JSON::Parse parser;
SV * user_null;
CODE:
json_parse_set_null (parser, user_null);
void
delete_true (parser)
JSON::Parse parser;
CODE:
json_parse_delete_true (parser);
void
delete_false (parser)
JSON::Parse parser;
CODE:
json_parse_delete_false (parser);
void
copy_literals (parser, onoff)
JSON::Parse parser;
SV * onoff;
CODE:
json_parse_copy_literals (parser, onoff);
void
delete_null (parser)
JSON::Parse parser;
CODE:
json_parse_delete_null (parser);
void
no_warn_literals (parser, onoff)
JSON::Parse parser;
SV * onoff;
CODE:
parser->no_warn_literals = SvTRUE (onoff) ? 1 : 0;
void
detect_collisions (parser, onoff)
JSON::Parse parser;
SV * onoff;
CODE:
parser->detect_collisions = SvTRUE (onoff) ? 1 : 0;
void
diagnostics_hash (parser, onoff)
JSON::Parse parser;
SV * onoff;
CODE:
#if PERL_VERSION > 12
parser->diagnostics_hash = SvTRUE (onoff) ? 1 : 0;
#else
warn ("diagnostics_hash () requires Perl 5.14 or later; this is 5.%d",
PERL_VERSION);
#endif
void
warn_only (parser, onoff)
JSON::Parse parser;
SV * onoff;
CODE:
parser->warn_only = SvTRUE (onoff) ? 1 : 0;
int
get_warn_only (parser)
JSON::Parse parser;
CODE:
if (parser->warn_only) {
RETVAL = 1;
}
else {
RETVAL = 0;
}
OUTPUT:
RETVAL
void
set_max_depth (json, max_depth)
JSON::Parse json;
int max_depth;
CODE:
if (max_depth < 0) {
croak ("Invalid max depth %d", max_depth);
}
json->max_depth = max_depth;
int
get_max_depth (json)
JSON::Parse json;
CODE:
RETVAL = json->max_depth;
if (json->max_depth == 0) {
RETVAL = JSON_PARSE_DEFAULT_MAX_DEPTH;
}
OUTPUT:
RETVAL
#ifdef TESTRANDOM
int random_json ()
CODE:
RETVAL = random_json ();
OUTPUT:
RETVAL
#endif /* def TESTRANDOM */
void
upgrade_utf8 (parser, onoff)
JSON::Parse parser;
SV * onoff;
CODE:
parser->upgrade_utf8 = SvTRUE (onoff) ? 1 : 0;
MODULE=JSON::Parse PACKAGE=JSON::Tokenize
JSON::Tokenize tokenize_json (json)
SV * json;
CODE:
RETVAL = tokenize (json);
RETVAL->blessed = 1;
OUTPUT:
RETVAL
JSON::Tokenize tokenize_child (token)
JSON::Tokenize token
CODE:
RETVAL = 0;
if (token->child) {
RETVAL = token->child;
RETVAL->blessed = 1;
}
OUTPUT:
RETVAL
JSON::Tokenize tokenize_next (token)
JSON::Tokenize token
CODE:
if (token->next) {
RETVAL = token->next;
RETVAL->blessed = 1;
}
else {
RETVAL = 0;
}
OUTPUT:
RETVAL
int tokenize_start (token)
JSON::Tokenize token
CODE:
RETVAL = token->start;
OUTPUT:
RETVAL
int tokenize_end (token)
JSON::Tokenize token
CODE:
RETVAL = token->end;
OUTPUT:
RETVAL
SV * tokenize_type (token)
JSON::Tokenize token
CODE:
/* Only set this to the real value if everything is OK. */
RETVAL = & PL_sv_undef;
if (token->type > json_token_invalid &&
token->type < n_json_tokens) {
RETVAL = newSVpv (token_names[token->type], 0);
}
else {
warn ("Invalid JSON token type %d", token->type);
}
OUTPUT:
RETVAL
void DESTROY (token)
JSON::Tokenize token
CODE:
tokenize_free (token);
MODULE=JSON::Parse PACKAGE=JSON::Whitespace
SV * strip_whitespace (tokens, json)
JSON::Tokenize tokens;
SV * json;
CODE:
RETVAL = strip_whitespace (tokens, json);
OUTPUT:
RETVAL
|