Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit50428a3

Browse files
committed
Change JsonSemAction to allow non-throw error reporting.
Formerly, semantic action functions for the JSON parser returned void,so that there was no way for them to affect the parser's behavior.That means in particular that they can't force an error exit except bylongjmp'ing. That won't do in the context of our project to make inputfunctions return errors softly. Hence, change them to return the sameJsonParseErrorType enum value as the parser itself uses. If an actionfunction returns anything besides JSON_SUCCESS, the parse is abandonedand that error code is returned.Action functions can thus easily return the same error conditions thatthe parser already knows about. As an escape hatch for expansion, alsoinvent a code JSON_SEM_ACTION_FAILED that the core parser does not knowthe exact meaning of. When returning this code, an action functionmust use some out-of-band mechanism for reporting the error details.This commit simply makes the API change and causes all the existingaction functions to return JSON_SUCCESS, so that there is no actualchange in behavior here. This is long enough and boring enough thatit seemed best to commit it separately from the changes that makereal use of the new mechanism.In passing, remove a duplicate assignment oftransform_string_values_scalar.Discussion:https://postgr.es/m/1436686.1670701118@sss.pgh.pa.us
1 parentd02ef65 commit50428a3

File tree

5 files changed

+342
-168
lines changed

5 files changed

+342
-168
lines changed

‎src/backend/utils/adt/jsonb.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ typedef struct JsonbAggState
6363

6464
staticinlineDatumjsonb_from_cstring(char*json,intlen);
6565
staticsize_tcheckStringLen(size_tlen);
66-
staticvoidjsonb_in_object_start(void*pstate);
67-
staticvoidjsonb_in_object_end(void*pstate);
68-
staticvoidjsonb_in_array_start(void*pstate);
69-
staticvoidjsonb_in_array_end(void*pstate);
70-
staticvoidjsonb_in_object_field_start(void*pstate,char*fname,boolisnull);
66+
staticJsonParseErrorTypejsonb_in_object_start(void*pstate);
67+
staticJsonParseErrorTypejsonb_in_object_end(void*pstate);
68+
staticJsonParseErrorTypejsonb_in_array_start(void*pstate);
69+
staticJsonParseErrorTypejsonb_in_array_end(void*pstate);
70+
staticJsonParseErrorTypejsonb_in_object_field_start(void*pstate,char*fname,boolisnull);
7171
staticvoidjsonb_put_escaped_value(StringInfoout,JsonbValue*scalarVal);
72-
staticvoidjsonb_in_scalar(void*pstate,char*token,JsonTokenTypetokentype);
72+
staticJsonParseErrorTypejsonb_in_scalar(void*pstate,char*token,JsonTokenTypetokentype);
7373
staticvoidjsonb_categorize_type(Oidtypoid,
7474
JsonbTypeCategory*tcategory,
7575
Oid*outfuncoid);
@@ -291,39 +291,47 @@ checkStringLen(size_t len)
291291
returnlen;
292292
}
293293

294-
staticvoid
294+
staticJsonParseErrorType
295295
jsonb_in_object_start(void*pstate)
296296
{
297297
JsonbInState*_state= (JsonbInState*)pstate;
298298

299299
_state->res=pushJsonbValue(&_state->parseState,WJB_BEGIN_OBJECT,NULL);
300+
301+
returnJSON_SUCCESS;
300302
}
301303

302-
staticvoid
304+
staticJsonParseErrorType
303305
jsonb_in_object_end(void*pstate)
304306
{
305307
JsonbInState*_state= (JsonbInState*)pstate;
306308

307309
_state->res=pushJsonbValue(&_state->parseState,WJB_END_OBJECT,NULL);
310+
311+
returnJSON_SUCCESS;
308312
}
309313

310-
staticvoid
314+
staticJsonParseErrorType
311315
jsonb_in_array_start(void*pstate)
312316
{
313317
JsonbInState*_state= (JsonbInState*)pstate;
314318

315319
_state->res=pushJsonbValue(&_state->parseState,WJB_BEGIN_ARRAY,NULL);
320+
321+
returnJSON_SUCCESS;
316322
}
317323

318-
staticvoid
324+
staticJsonParseErrorType
319325
jsonb_in_array_end(void*pstate)
320326
{
321327
JsonbInState*_state= (JsonbInState*)pstate;
322328

323329
_state->res=pushJsonbValue(&_state->parseState,WJB_END_ARRAY,NULL);
330+
331+
returnJSON_SUCCESS;
324332
}
325333

326-
staticvoid
334+
staticJsonParseErrorType
327335
jsonb_in_object_field_start(void*pstate,char*fname,boolisnull)
328336
{
329337
JsonbInState*_state= (JsonbInState*)pstate;
@@ -335,6 +343,8 @@ jsonb_in_object_field_start(void *pstate, char *fname, bool isnull)
335343
v.val.string.val=fname;
336344

337345
_state->res=pushJsonbValue(&_state->parseState,WJB_KEY,&v);
346+
347+
returnJSON_SUCCESS;
338348
}
339349

340350
staticvoid
@@ -367,7 +377,7 @@ jsonb_put_escaped_value(StringInfo out, JsonbValue *scalarVal)
367377
/*
368378
* For jsonb we always want the de-escaped value - that's what's in token
369379
*/
370-
staticvoid
380+
staticJsonParseErrorType
371381
jsonb_in_scalar(void*pstate,char*token,JsonTokenTypetokentype)
372382
{
373383
JsonbInState*_state= (JsonbInState*)pstate;
@@ -443,6 +453,8 @@ jsonb_in_scalar(void *pstate, char *token, JsonTokenType tokentype)
443453
elog(ERROR,"unexpected parent of nested structure");
444454
}
445455
}
456+
457+
returnJSON_SUCCESS;
446458
}
447459

448460
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp