Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a function fjson_object_array_del_idx #155

Merged
merged 1 commit into from
Jun 22, 2018

Conversation

nhosoi
Copy link

@nhosoi nhosoi commented Jun 13, 2018

Adding "void fjson_object_array_del_idx(struct fjson_object *jso, int idx)",
which deletes the idx-th element in the array type object.

This patch is a part of work to support a requirement to remove empty json objects in parsing JSON.
Adding parse_json_ex to grammar/rainerscript.c for supporting compact.
Adding parameters variable, alt_variable and compact to mmjsonparse.

@nhosoi
Copy link
Author

nhosoi commented Jun 13, 2018

Note: this PR is needed by "JSON parsing extension" (rsyslog/rsyslog#2773).

@rgerhards rgerhards added this to the 0.99.8 milestone Jun 14, 2018
@rgerhards rgerhards self-assigned this Jun 14, 2018
Copy link
Member

@rgerhards rgerhards left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR LGTM, mergable even without changes. Nevertheless, I would appreciate them. Let me know your decision so that I can go forward in any case.

arraylist.c Outdated
* Deleting the idx-th element in the array_list.
*/
void
array_list_del_idx(struct array_list *arr, int idx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a hard requirement, but we nowadays prefer const modifier where possible. Helps a lot with static analyzers and protects against accidental var modification. I know it's kind of controversial with C programmers, thus not a hard requirement ;-)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where would const be used ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array_list_del_idx(struct array_list *const arr, const int idx)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @rgerhards ! I've added "const" as you suggested.

arraylist.c Outdated
}
if(arr->array[idx]) arr->free_fn(arr->array[idx]);
arr->length--;
for ( ; idx < arr->length; idx++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't memmove be better?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it should have been... :) Thanks! Fixed.

@nhosoi nhosoi force-pushed the json_object_array_del_idx branch from 82ba0eb to 284a897 Compare June 14, 2018 17:59
arraylist.c Outdated
return;
}
if(arr->array[idx]) arr->free_fn(arr->array[idx]);
memmove(arr->array + idx, arr->array + idx + 1, (--arr->length - idx) * sizeof(void *));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if removing the last element, that is, if idx == (arr->length-1) then arr->array + idx + 1 will point to random memory after the array - will probably cause compiler checker errors - in this case, you do not need the memmove

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also when removing the last element, the expression (--arr->length - idx) * sizeof(void *) will be 0 - it is possible that given a 0 argument memmove is a no-op, but it isn't clear from this implementation https://code.woboq.org/userspace/glibc/string/memmove.c.html that src will never be accessed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, this is one of my test cases and valgrind did not complain an invalid memory access... :p

"mmk3":[{"a0":"v0"},{},{"a1":"v1"},{"a2":"v2"},{},{},{"a3":"v3"},{}]
==>
"mmk3": [ { "a0": "v0" }, { "a1": "v1" }, { "a2": "v2" }, { "a3": "v3" } ]

If idx is the last one, the size (--arr->length - idx) * sizeof(void *) would be 0. In the case, memmove just returns?

@nhosoi nhosoi force-pushed the json_object_array_del_idx branch 2 times, most recently from a2d5364 to 4246d40 Compare June 14, 2018 18:31
}
if(arr->array[idx]) arr->free_fn(arr->array[idx]);
if (--arr->length > idx) {
memmove(arr->array + idx, arr->array + idx + 1, (arr->length - idx) * sizeof(void *));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

… idx)",

which deletes the idx-th element in the array type object.
@nhosoi nhosoi force-pushed the json_object_array_del_idx branch from 4246d40 to e32df78 Compare June 15, 2018 15:40
@nhosoi
Copy link
Author

nhosoi commented Jun 18, 2018

Hi @rgerhards,
Could there be anything else I'm supposed to modify? I'd like to see how rsyslog/rsyslog#2773 goes with this patch... Thanks!

@rgerhards
Copy link
Member

I "just" need to keep up, be out of office parts of this week. Please note that I also must craft a release so that we can see it in rsyslog. Prefer to do that not under time-pressure, past has shown things go wrong if I try to hurry releases... Sorry for some delay.

@nhosoi
Copy link
Author

nhosoi commented Jun 18, 2018

Thank you for your quick response, @rgerhards. I understand your concern and I was just hoping to double-check if there is something I'd better do on my side. Thanks.

@richm
Copy link

richm commented Jul 30, 2018

@rgerhards when will there be a release of libfastjson which includes this commit?

@rgerhards
Copy link
Member

@richm I need to fiddle with some CI checks, not sure if I make it for 8.37 :-( sry for that

@richm
Copy link

richm commented Aug 7, 2018

This PR was added to the 0.99.8 milestone which is after the release https://github.com/rsyslog/libfastjson/releases/tag/v0.99.8 - should it be added to the 0.99.9 milestone instead?
Also, when is the planned release of v0.99.9?

@richm
Copy link

richm commented May 17, 2019

ping - when is the planned release of v0.99.9?

nhosoi added a commit to nhosoi/origin-aggregated-logging that referenced this pull request May 17, 2019
libfastjson - Adding "void fjson_object_array_del_idx(struct
 fjson_object *jso, int idx)", which deletes the idx-th element
 in the array type object.

 upstream PR: rsyslog/libfastjson#155

liblognorm - Adding a parameter skipempty to the json field type.
 If skipempty is set as follows, empty json objects are dropped
 from the parsed result.
  %field_name:json:skipempty%

 If any parameter other than "skipempty" is given ("bogus" in this
 example), an error message "invalid flag for JSON parser: bogus"
 is issued.

 Add test for the skipempty parameter.

 upstream PR: rsyslog/liblognorm#305
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants