[FFmpeg-devel] [PATCH]lavfi/avfiltergraph: Do not return ENOMEM if filter is missing

Nicolas George george at nsup.org
Mon Feb 5 18:20:34 EET 2018

James Almer (2018-02-05):
> If it takes a parameter like the type of "something" you want to alloc
> then yes, I'd support that policy as there's no way to prevent the
> argument passed from being invalid, so NULL in that case will not mean


> But if there's no parameters at all, or if the parameter is a size one,
> then the failure can only be OOM.

I can think of a few cases where the failure could be something else.
For example if the structure that is allocated contains a mutex, the
error could come from pthread_mutex_init(), which can return other
errors than ENOMEM.

>				    In those cases I prefer the latter as
> it's more versatile in some situations, like using the function itself
> as an argument when calling another function.

That is true, but that also prevents from using the usual idiom:

	ret = ...;
	if (ret < 0)
	    return ret; /* or goto fail */

It requires an extra "ret = AVERROR(ENOMEM)", plus the braces. I think
this is more common than calling a function with the result without
checking it.

In terms of API regularity and simplicity, I find the hardcoding of
AVERROR(ENOMEM) in the call site very distasteful.


  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180205/4c29c436/attachment.sig>

More information about the ffmpeg-devel mailing list