[PATCH v2] elf: Fix tst-relro-symbols.py argument passing
Florian Weimer
fweimer@redhat.com
Thu Dec 15 20:09:22 GMT 2022
* Adhemerval Zanella Netto:
>>> + help='required symbol names')
>>> return parser
>>>
>>> def main(argv):
>>
>> Despite the use of [] here, there does not seem to be a sharing hazard:
>>
>> import argparse
>> parser = argparse.ArgumentParser()
>> parser.add_argument('--foo', action='append', default=[])
>> print(parser.parse_args('--foo 1 --foo 2'.split()))
>> print(parser.parse_args('--foo 3 --foo 4'.split()))
>>
>> Prints:
>>
>> Namespace(foo=['1', '2'])
>> Namespace(foo=['3', '4'])
>>
>> I would have expected:
>>
>> Namespace(foo=['1', '2'])
>> Namespace(foo=['1', '2', '3', '4'])
>
> For state tracking you need to pass a namespace, as described by
> documentation [1].
>
> import argparse
>
> class State:
> pass
>
> state = State()
> parser = argparse.ArgumentParser()
> parser.add_argument('--foo', action='append', default=[])
> parser.parse_args('--foo 1 --foo 2'.split(), namespace=state)
> print(state.foo)
> parser.parse_args('--foo 3 --foo 4'.split(), namespace=state)
> print(state.foo)
>
> It prints:
>
> ['1', '2']
> ['1', '2', '3', '4']
Oh, I was concerned that the [] would be used directly, and not cloned.
Then you'd get sharing, too. After all, the [] is only evaluated once,
when add_argument is called. I don't see the cloning described in the
manual.
Thanks,
Florian
More information about the Libc-alpha
mailing list