On Fri, Oct 25, 2013 at 8:17 AM, Pavel Levshin <[email protected]> wrote:
> > > But then, it turns out applicable to most functions: > > What if there is an argument which is a JSON object? It looks like it will > leak every time. Argh... I thought you were right, but actually we use json_object_object_get() to obtain the value, which does not increment the reference count. So json_object_put() [free] is not required nor permitted here. Doc: http://json-c.github.io/json-c/json-c-0.10/doc/html/json__object_8h.html#acc3628d97c6308dc967006e4268c4e7f > There should be some varFree() function for this. > > Anyhow, that's a good suggestion and I will add it. But it will be equal to the current code, except that it is easier to extend in the future. And, at last, what if r[0].datatype is unitialized and equals 'S' by > accident? Shouldn't there be initialization for every struct var? > It must be initialized, if not that's an error. We try to avoid unnecessary writes, and this would definitely be one (as the type always needs to be set correctly). Thanks again, Rainer > > > -- > Pavel Levshin > > > 25.10.2013 1:18, Pavel Levshin: > >> Hello. >> >> I hope it will be useful. Now, when local variables are real JSON >> containers, why don't extract all submatches at once? I've given it a try >> and it works. The patch is based on a current master-var-refactor, I am >> sorry for this mess. I will redo it if needed when the refactoring will be >> done. >> >> I've extended re_extract to achieve this behaviour. Creation of a new >> function (re_extract_all) just for this would lead to code duplication. The >> modified function returns a container with all submatches on request. >> Submatches in the container are identified by index, where "0" is whole >> match. New behaviour is achieved by setting 'submatch' parameter to any >> negative number. For non-negative numbers, it works as it used to. Example: >> >> # re_extract(expr, re, match, submatch, no-found) >> >> set $.str = "Testing 31 32 33 and so on"; >> set $.var = re_extract($.str, "^([[:alnum:]]+) ([0-9]+) ([0-9]+)", 0, >> -1, "nothing"); >> set $!matches = $.var; # container here >> set $!match2 = $.var!2; # 2nd submatch >> >> And here is the output of all these variables (with some magic template): >> >> _local_ { "str": "Testing 31 32 33 and so on", "var": { "0": "Testing 31 >> 32", "1": "Testing", "2": "31", "3": "32" } } >> _msg_ { "matches": { "0": "Testing 31 32", "1": "Testing", "2": "31", >> "3": "32" }, "match2": "31" } >> >> >> By the way, this patch also fixes a bug with buffer overflow in >> re_extract. >> >> >> -- >> Pavel Levshin >> >> >> >> ______________________________**_________________ >> rsyslog mailing list >> http://lists.adiscon.net/**mailman/listinfo/rsyslog<http://lists.adiscon.net/mailman/listinfo/rsyslog> >> http://www.rsyslog.com/**professional-services/<http://www.rsyslog.com/professional-services/> >> What's up with rsyslog? Follow https://twitter.com/rgerhards >> NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad >> of sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you >> DON'T LIKE THAT. >> > > ______________________________**_________________ > rsyslog mailing list > http://lists.adiscon.net/**mailman/listinfo/rsyslog<http://lists.adiscon.net/mailman/listinfo/rsyslog> > http://www.rsyslog.com/**professional-services/<http://www.rsyslog.com/professional-services/> > What's up with rsyslog? Follow https://twitter.com/rgerhards > NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad > of sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you > DON'T LIKE THAT. > _______________________________________________ rsyslog mailing list http://lists.adiscon.net/mailman/listinfo/rsyslog http://www.rsyslog.com/professional-services/ What's up with rsyslog? Follow https://twitter.com/rgerhards NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad of sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you DON'T LIKE THAT.

