forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit5c32c21
committed
jsonapi: add lexer option to keep token ownership
Commit0785d1b adds support for libpq as a JSON client, butallocations for string tokens can still be leaked during parsingfailures. This is tricky to fix for the object_field semantic callbacks:the field name must remain valid until the end of the object, but if aparsing error is encountered partway through, object_field_end() won'tbe invoked and the client won't get a chance to free the field name.This patch adds a flag to switch the ownership of parsed tokens to thelexer. When this is enabled, the client must make a copy of any tokensit wants to persist past the callback lifetime, but the lexer willhandle necessary cleanup on failure.Backend uses of the JSON parser don't need to use this flag, since theparser's allocations will occur in a short lived memory context.A -o option has been added to test_json_parser_incremental to exercisethe new setJsonLexContextOwnsTokens() API, and the test_json_parser TAPtests make use of it. (The test program now cleans up allocated memory,so that tests can be usefully run under leak sanitizers.)Author: Jacob ChampionDiscussion:https://postgr.es/m/CAOYmi+kb38EciwyBQOf9peApKGwraHqA7pgzBkvoUnw5BRfS1g@mail.gmail.com1 parent262283d commit5c32c21
File tree
6 files changed
+173
-33
lines changed- src
- common
- include/common
- test/modules/test_json_parser
- t
6 files changed
+173
-33
lines changedLines changed: 94 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
161 | 161 |
| |
162 | 162 |
| |
163 | 163 |
| |
| 164 | + | |
164 | 165 |
| |
165 | 166 |
| |
166 | 167 |
| |
| |||
280 | 281 |
| |
281 | 282 |
| |
282 | 283 |
| |
| 284 | + | |
283 | 285 |
| |
284 | 286 |
| |
285 | 287 |
| |
| |||
437 | 439 |
| |
438 | 440 |
| |
439 | 441 |
| |
440 |
| - | |
| 442 | + | |
441 | 443 |
| |
442 | 444 |
| |
443 | 445 |
| |
| |||
464 | 466 |
| |
465 | 467 |
| |
466 | 468 |
| |
467 |
| - | |
468 | 469 |
| |
469 | 470 |
| |
470 | 471 |
| |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
471 | 480 |
| |
472 | 481 |
| |
473 | 482 |
| |
| |||
530 | 539 |
| |
531 | 540 |
| |
532 | 541 |
| |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
533 | 561 |
| |
534 | 562 |
| |
535 | 563 |
| |
| |||
569 | 597 |
| |
570 | 598 |
| |
571 | 599 |
| |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
572 | 610 |
| |
573 | 611 |
| |
574 | 612 |
| |
575 | 613 |
| |
576 | 614 |
| |
577 | 615 |
| |
| 616 | + | |
578 | 617 |
| |
579 | 618 |
| |
580 | 619 |
| |
| |||
608 | 647 |
| |
609 | 648 |
| |
610 | 649 |
| |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
611 | 659 |
| |
612 | 660 |
| |
613 | 661 |
| |
| |||
655 | 703 |
| |
656 | 704 |
| |
657 | 705 |
| |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
658 | 716 |
| |
659 | 717 |
| |
| 718 | + | |
660 | 719 |
| |
661 | 720 |
| |
662 | 721 |
| |
| |||
826 | 885 |
| |
827 | 886 |
| |
828 | 887 |
| |
| 888 | + | |
829 | 889 |
| |
830 | 890 |
| |
831 | 891 |
| |
| |||
1086 | 1146 |
| |
1087 | 1147 |
| |
1088 | 1148 |
| |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
1089 | 1160 |
| |
1090 | 1161 |
| |
1091 | 1162 |
| |
| |||
1221 | 1292 |
| |
1222 | 1293 |
| |
1223 | 1294 |
| |
| 1295 | + | |
| 1296 | + | |
1224 | 1297 |
| |
| 1298 | + | |
1225 | 1299 |
| |
1226 |
| - | |
| 1300 | + | |
1227 | 1301 |
| |
1228 | 1302 |
| |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
1229 | 1306 |
| |
1230 | 1307 |
| |
1231 | 1308 |
| |
| |||
1238 | 1315 |
| |
1239 | 1316 |
| |
1240 | 1317 |
| |
1241 |
| - | |
| 1318 | + | |
1242 | 1319 |
| |
1243 | 1320 |
| |
1244 | 1321 |
| |
| |||
1255 | 1332 |
| |
1256 | 1333 |
| |
1257 | 1334 |
| |
| 1335 | + | |
| 1336 | + | |
1258 | 1337 |
| |
| 1338 | + | |
1259 | 1339 |
| |
1260 | 1340 |
| |
1261 | 1341 |
| |
| 1342 | + | |
| 1343 | + | |
1262 | 1344 |
| |
| 1345 | + | |
1263 | 1346 |
| |
1264 | 1347 |
| |
1265 | 1348 |
| |
| |||
1268 | 1351 |
| |
1269 | 1352 |
| |
1270 | 1353 |
| |
1271 |
| - | |
| 1354 | + | |
1272 | 1355 |
| |
1273 | 1356 |
| |
1274 | 1357 |
| |
| |||
1283 | 1366 |
| |
1284 | 1367 |
| |
1285 | 1368 |
| |
1286 |
| - | |
| 1369 | + | |
1287 | 1370 |
| |
1288 | 1371 |
| |
1289 | 1372 |
| |
1290 | 1373 |
| |
1291 | 1374 |
| |
1292 |
| - | |
| 1375 | + | |
1293 | 1376 |
| |
1294 | 1377 |
| |
1295 |
| - | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
1296 | 1382 |
| |
1297 | 1383 |
| |
1298 | 1384 |
| |
|
Lines changed: 25 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
92 | 92 |
| |
93 | 93 |
| |
94 | 94 |
| |
| 95 | + | |
95 | 96 |
| |
96 | 97 |
| |
97 | 98 |
| |
| 99 | + | |
98 | 100 |
| |
99 | 101 |
| |
100 | 102 |
| |
| |||
130 | 132 |
| |
131 | 133 |
| |
132 | 134 |
| |
133 |
| - | |
134 |
| - | |
135 |
| - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
136 | 139 |
| |
137 | 140 |
| |
138 | 141 |
| |
| |||
216 | 219 |
| |
217 | 220 |
| |
218 | 221 |
| |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
219 | 241 |
| |
220 | 242 |
| |
221 | 243 |
| |
|
Lines changed: 8 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
13 | 13 |
| |
14 | 14 |
| |
15 | 15 |
| |
16 |
| - | |
17 |
| - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
18 | 21 |
| |
19 | 22 |
| |
20 | 23 |
| |
21 |
| - | |
| 24 | + | |
22 | 25 |
| |
23 | 26 |
| |
24 |
| - | |
| 27 | + | |
25 | 28 |
| |
26 | 29 |
| |
27 | 30 |
| |
28 | 31 |
| |
29 | 32 |
| |
30 |
| - | |
| 33 | + | |
31 | 34 |
| |
32 | 35 |
| |
33 | 36 |
| |
|
Lines changed: 9 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
13 | 13 |
| |
14 | 14 |
| |
15 | 15 |
| |
16 |
| - | |
| 16 | + | |
17 | 17 |
| |
18 | 18 |
| |
19 | 19 |
| |
| |||
35 | 35 |
| |
36 | 36 |
| |
37 | 37 |
| |
38 |
| - | |
| 38 | + | |
39 | 39 |
| |
40 | 40 |
| |
41 | 41 |
| |
| |||
53 | 53 |
| |
54 | 54 |
| |
55 | 55 |
| |
56 |
| - | |
57 |
| - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
58 | 61 |
| |
59 | 62 |
| |
60 | 63 |
| |
61 |
| - | |
62 |
| - | |
| 64 | + | |
| 65 | + | |
63 | 66 |
| |
64 | 67 |
| |
65 | 68 |
| |
|
Lines changed: 7 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
16 | 16 |
| |
17 | 17 |
| |
18 | 18 |
| |
19 |
| - | |
20 |
| - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
21 | 24 |
| |
22 | 25 |
| |
23 | 26 |
| |
24 |
| - | |
| 27 | + | |
25 | 28 |
| |
26 |
| - | |
| 29 | + | |
27 | 30 |
| |
28 | 31 |
| |
29 | 32 |
| |
|
0 commit comments
Comments
(0)