Storing possibly-arrays as arrays

Alejandro Colomar (man-pages) alx.manpages at gmail.com
Sun Dec 19 01:01:18 UTC 2021


Hi Valentin,

On 12/18/21 21:10, Valentin V. Bartenev wrote:
>>
>> Most of the code is duplicated for the cases that 'share is not an
>> array' and 'share is an array', changing just a single line.  How about
>> reorganizing the data structures so that when both a string/object and
>> an array are a valid type
>> 	.type = NXT_CONF_VLDT_* | NXT_CONF_VLDT_ARRAY,
>> the data is _always_ stored as an array (of size 1 if it was not an
>> array originally)?
> [..]
> 
> The code you've just mentioned above is the first place where the data
> from a user's config is actually processed.  It's not stored anywhere
> when NXT_CONF_VLDT_* rules validate JSON scheme.

Okay, thanks!

> 
> 
> [..]
>> Another alternative, but maybe not so good since it kind of defeats the
>> difference between (nxt) arrays and non-arrays, would be to modify
>> nxt_conf_array_elements_count() so that
>>       if (value->type != NXT_CONF_VALUE_ARRAY) {
>>           return (index == 0) ? value : NULL;
>>       }
>> This would be similar to C pointers to variables, which can always be
>> considered as pointers to the first element of an array of size 1.
>>
> 
> That makes sense.

Good.  I added it to the patch set :)

Cheers,
Alex

-- 
Alejandro Colomar
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/


More information about the unit mailing list