[FFmpeg-devel] Ideas to replace the options system

Nicolas George george at nsup.org
Fri Dec 4 19:12:30 CET 2015


Le quartidi 14 frimaire, an CCXXIV, Ganesh Ajjanagadde a écrit :
> >       And while we are at it, we should change them to accept strings as
> >       pointer+length or pointer+end instead of zero-terminated C strings.
> Are you referring here to something like djb's netstrings:
> http://cr.yp.to/proto/netstrings.txt?

Not exactly. What you quote is for external representation: serializing to
files or sockets. It would be really inefficient for using inside programs
due to the endless ASCII-decimal conversion. . What I am saying is that
strings should be something like this:

struct string {
    char *text;
    size_t len;
};

or possibly:

struct string {
    char *text;
    char *end;
};

... not just "char *text" and a 0 byte at the end. There are many reasons
for this, the most obvious is this: if you want to extract a substring in
the middle (or the beginning, but not the end), with the 0-termination
convention, you have to change the original string to place the 0, or to
copy it if you can not modify it. With the structure, you just have to
adjust the len/end field.

Most languages except C work with strings like that; 0-termination is really
an oddity of the C language (and, unfortunately the kernels that are build
around it).

(As for the choice between len and end, it depends on the use case; len is
probably better for general-purpose code, but when walking the string, end
is constant. Fortunately, they are an addition/subtraction away from each
other.)

(Also, char* would rather be uint8_t*, to handle UTF-8.)

Regards,

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


More information about the ffmpeg-devel mailing list