[FFmpeg-devel] [PATCH] avformat/utils: add helper functions to retrieve index entries from an AVStream

Nicolas George george at nsup.org
Thu Mar 25 13:55:43 EET 2021


James Almer (12021-03-24):
> I think it's clear by now that nothing i could say will convince you it's
> better to not return a pointer to an internal array when there are safer
> alternatives, and i already gave my reasons why, none of which satisfied
> you, so i don't see the point in keeping this discussion going.

I find this comment quite offensive. You did not manage to convince me
because your arguments have not been up to the task. Do not try to push
the fault on me, and I will refrain from accusing you of not taking my
arguments into account. Coming to an agreement is a process, it requires
both parts to refine their arguments progressively.

This is a matter of choosing the least of several drawbacks. So let us
compare the drawbacks and not muddle things further.

For me:

1. having a dynamic allocation is way way worse than
2. having sizeof(AVIndexEntry) in the ABI, which is somewhat worse than
3. having a function with many arguments, which is a tiny bit worse than
4. having a "use this pointer immediately" constraint.

We agree except on 3>4, so let us focus on that.

Option (3) has these practical drawbacks: Many arguments involves more
typing and the risk of messing with the order and getting invalid
values. It also requires redesigning the API if we add fields and
exporting them is useful. And it requires either the overhead of NULL
checks or the caller declaring unneeded variables.

Option (4) has the obvious practical drawback that misusing the API
causes undefined behavior.

The constraint of using a pointer immediately on risk of undefined
behavior is actually a frequent one, in FFmpeg but also in C at large:
gethosbtyname, localtime, etc.

For me, that makes it approximately on par with the risk of messing the
order of the many arguments.

Which leaves more typing, NULL checks overhead or useless variables
(still more typing).

It is tiny, I have no trouble admitting, but it is tiny in favor of one
solution.

If you do not agree with these estimates, please explain exactly where.

> If some other developer wants to chime in and comment which approach they
> prefer, then that would be ideal.

Indeed.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20210325/1b3047a5/attachment.sig>


More information about the ffmpeg-devel mailing list