mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-21 10:29:02 +00:00
memory-management bugfix in reshape; JSON stdio iterate
This commit is contained in:
parent
361914de2c
commit
14aa4e77a1
4 changed files with 15 additions and 15 deletions
|
|
@ -329,8 +329,6 @@ static void main_usage_data_format_options(FILE* o, char* argv0) {
|
|||
fprintf(o, " e.g. '{\"a\":{\"b\":3}}' becomes a:b => 3 for\n");
|
||||
fprintf(o, " non-JSON formats. Defaults to %s.\n",
|
||||
DEFAULT_JSON_FLATTEN_SEPARATOR);
|
||||
// xxx fix this cmt once lrec_reader_stdio_json is complete
|
||||
fprintf(o, " NOTE: --json and --ijson are currently under construction, but --ojson works.\n");
|
||||
fprintf(o, "\n");
|
||||
fprintf(o, " -p is a keystroke-saver for --nidx --fs space --repifs\n");
|
||||
fprintf(o, "\n");
|
||||
|
|
|
|||
|
|
@ -143,13 +143,16 @@ static void lrec_reader_mmap_json_sof(void* pvstate, void* pvhandle) {
|
|||
parsed_top_level_json = json_parse_ex(item_start, length, error_buf, &item_start, &settings);
|
||||
|
||||
if (parsed_top_level_json == NULL) {
|
||||
fprintf(stderr, "Unable to parse JSON data: %s\n", error_buf);
|
||||
fprintf(stderr, "%s: Unable to parse JSON data: %s\n", error_buf, MLR_GLOBALS.argv0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// The lrecs have their string pointers pointing into the parsed-JSON objects (for
|
||||
// efficiency) so it's important we not free the latter until our free method.
|
||||
reference_json_objects_as_lrecs(pstate->precords, parsed_top_level_json, pstate->json_flatten_separator);
|
||||
if (!reference_json_objects_as_lrecs(pstate->precords, parsed_top_level_json, pstate->json_flatten_separator)) {
|
||||
fprintf(stderr, "%s: Unable to parse JSON data.\n", MLR_GLOBALS.argv0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (item_start == NULL)
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -294,8 +294,9 @@ static sllv_t* mapper_reshape_wide_to_long_no_regex_process(lrec_t* pinrec, cont
|
|||
for (sllse_t* pe = pstate->input_field_names->phead; pe != NULL; pe = pe->pnext) {
|
||||
char* key = pe->value;
|
||||
char* value = lrec_get(pinrec, key);
|
||||
if (value != NULL)
|
||||
lhmss_put(pairs, key, value, NO_FREE);
|
||||
if (value != NULL) {
|
||||
lhmss_put(pairs, mlr_strdup_or_die(key), mlr_strdup_or_die(value), FREE_ENTRY_KEY|FREE_ENTRY_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
// Unset the lrec keys after iterating over them, rather than during
|
||||
|
|
@ -332,7 +333,8 @@ static sllv_t* mapper_reshape_wide_to_long_regex_process(lrec_t* pinrec, context
|
|||
for (sllve_t* pf = pstate->input_field_regexes->phead; pf != NULL; pf = pf->pnext) {
|
||||
regex_t* pregex = pf->pvvalue;
|
||||
if (regmatch_or_die(pregex, pe->key, 0, NULL)) {
|
||||
lhmss_put(pairs, pe->key, pe->value, NO_FREE);
|
||||
lhmss_put(pairs, mlr_strdup_or_die(pe->key), mlr_strdup_or_die(pe->value),
|
||||
FREE_ENTRY_KEY|FREE_ENTRY_VALUE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
13
c/todo.txt
13
c/todo.txt
|
|
@ -61,8 +61,12 @@ TOP-OF-LIST SUMMARY
|
|||
TOP-OF-LIST DETAILS
|
||||
|
||||
* JSON I/O:
|
||||
! string-preservation for doubles !
|
||||
! UT !
|
||||
! mlr --json reshape -i x,y -o item,value rec.json
|
||||
|
||||
! acknowledgement to mld: https://github.com/udp/json-parser
|
||||
! stdio version. & prefer stremable version with fgetc rather than pointer-math.
|
||||
o wishlist: streamable version with fgetc rather than pointer-math.
|
||||
- on output, check 1st if mlhmmv is necessary? or just always?
|
||||
- cover x 2
|
||||
- define 'tabular JSON' by example @ mld
|
||||
|
|
@ -70,16 +74,9 @@ TOP-OF-LIST DETAILS
|
|||
- programmable allow-this-on-input flag
|
||||
- programmable allow-this-on-output flag
|
||||
- programmable flatten-separator
|
||||
? or support multi-level lrecs??
|
||||
o hp re :)
|
||||
! JSON/join UT. both/left/right json cases.
|
||||
|
||||
o bug:
|
||||
|
||||
$ mlr --jlistwrap --jvstack --json cat ~/bak/bmx/bookmarks-2016-02-02.json
|
||||
mlr: found array item within JSON object. This is valid but unmillerable JSON.
|
||||
]
|
||||
|
||||
? env vars??
|
||||
|
||||
* doc:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue