mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: Best place to discuss other lightweight libraries?
Date: Mon, 22 Apr 2013 19:06:28 -0400	[thread overview]
Message-ID: <20130422230628.GT20323@brightrain.aerifal.cx> (raw)
In-Reply-To: <5175BCB9.5090309@gentoo.org>

On Tue, Apr 23, 2013 at 12:42:01AM +0200, Luca Barbato wrote:
> On 04/22/2013 11:52 PM, Rich Felker wrote:
> >> For this there aren't solution that won't cause different problems I'm
> >> afraid.
> > 
> > Sure there are. I get the impression you can tell I was talking about
> > libav/ffmpeg's log interface. :-) The obvious solution is to bind log
> > contexts to the object you're acting on. See this nice talk:
> > 
> > http://misko.hevery.com/2008/11/21/clean-code-talks-global-state-and-singletons/
> > 
> > If I remember right, part of the problem way back was that there were
> > deep function calls that had no context available to them, and that
> > didn't _need_ a context for anything but logging warnings or whatnot.
> 
> In the specific case yes. I tried to foster proper return error
> propagation, so you get something more meaningful than EINVAL/-1 and
> that is usually enough in those specific cases.
> 
> The general problem is that the library user wants to be the only one
> having a say on what goes where so single point overrides are useful.

The problem with your comment here is the phrase "library user". Who
is the library user? You may be thinking from a standpoint (in our
example) of MPlayer, but what if instead the application you were
looking at were a file manager that itself had no awareness of video
files, and only ended up processing them as part of a library pulled
in from a plugin for file previews? Obviously there is no way the app
can be aware of where the log messages should go since it's not aware
the library even exists. The user is the library that depends on the
library doing the logging, not the app, and it's very possible that
there is more than once such library. In which case, you have madness.

> When you start using those libraries in situations in which you'd like
> to have per-$situation logging then you start to scream.

Keep in mind it might not even be "per-situation logging". It might be
something like one plugin needing to send the message back up to the
application as a popup message to display, and another plugin just
wanting to render the message text as a file preview in place of an
image...

> > Yes, basically. Dependency on glib means your library will impose
> > bloat and it will preclude robustness.
> 
> Yet glib gives you oh-so-many-features (I fell for it once), sadly there
> aren't many utility libs that provide sort of useful data structures,

If you want the data structures, I think that means you should be
using C++, not C.

> eventloops,

If your program is event-loop-performance-critical (think httpd), you
probably need a custom one for your application.

If it's not, you could probably write a much simpler program using
threads. It might even perform better too.

> threadpools

Similar situation. Threadpools are an optimization that shouldn't be
applied prematurely, and if you do need them, you probably want a
custom solution.

> and portable string mangling (e.g. strl*
> functions) in a single widespread package.

strl* considered harmful, for 3 reasons:

1. Concatenation is a bad idiom. See
http://en.wikipedia.org/wiki/Schlemiel_the_Painter's_algorithm

2. It duplicates standard functionality in snprintf. Yes it's quicker
for some cases (pure copying), but in that case you probably should
just be using the original string in-place. On the other hand,
building the whole output in one step with snprintf makes it obvious
that your code is correct and avoids issue #1 above.

3. While returning the length that "would be needed" is useful if you
want to allocate and retry, it's harmful if your goal is to protect
against malicious inputs. For instance,

    strlcpy(buf, some_500_gb_string, 10)

has to process the whole input string even though it's going to throw
away most of it. BTW this issue applies to snprintf too, but at least
it has something useful to be computing. With strl*, the return value
is always something that would be trivial to obtain yourself if you
needed it.

I'm aware some people like strl* and we have them in musl because it's
better to provide them than to deal with people rolling their own and
doing it in wrong and insecure ways. But I still would recommend
against using them in new code.

Rich


  reply	other threads:[~2013-04-22 23:06 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-21 16:30 LM
2013-04-21 20:17 ` Rob Landley
2013-04-21 20:24 ` Rob Landley
2013-04-24 11:39   ` LM
2013-04-25 19:30     ` Rob Landley
2013-04-21 23:26 ` Isaac Dunham
2013-04-22 14:53 ` Rich Felker
2013-04-22 15:21   ` Luca Barbato
2013-04-22 16:40     ` LM
2013-04-22 16:47       ` Daniel Cegiełka
2013-04-22 22:07         ` Rich Felker
2013-04-23 12:50           ` LM
2013-04-23 14:40             ` John Spencer
2013-04-23 14:58               ` Rich Felker
2013-04-22 19:31       ` Luca Barbato
2013-04-22 23:24       ` Rob Landley
2013-04-22 23:31         ` Rich Felker
2013-04-23  0:54           ` Rob Landley
2013-04-23  1:46             ` Rich Felker
2013-04-23  5:04               ` Isaac Dunham
2013-04-23 13:47                 ` Rich Felker
2013-04-23 21:25                   ` Luca Barbato
2013-04-23 21:50                   ` Kurt H Maier
2013-04-24  2:37                     ` Rich Felker
2013-04-24  4:43                       ` Kurt H Maier
2013-04-24 13:37                         ` Rich Felker
2013-04-24  0:50                   ` idunham
2013-04-24  6:11                 ` Rob Landley
2013-04-22 21:52     ` Rich Felker
2013-04-22 22:42       ` Luca Barbato
2013-04-22 23:06         ` Rich Felker [this message]
2013-04-23  0:26           ` Luca Barbato
2013-04-23  2:14             ` Rob Landley
2013-04-23 19:07               ` Strake
2013-04-23 19:24                 ` Daniel Cegiełka
2013-04-23 21:33                   ` Szabolcs Nagy
2013-04-24 12:12                     ` Zvi Gilboa
2013-04-23 21:34               ` Luca Barbato
2013-04-24 11:18                 ` Daniel Cegiełka
2013-04-24 11:48                   ` Kurt H Maier
2013-04-24 12:32                     ` Daniel Cegiełka
2013-04-24 13:38                       ` Rich Felker
2013-04-24 13:55                         ` Daniel Cegiełka
2013-04-24 13:37                     ` go support (was: Best place to discuss other lightweight libraries?) John Spencer
2013-04-24 13:39                       ` Rich Felker
2013-04-24 16:33                       ` Kurt H Maier
2013-04-24 15:47                     ` Best place to discuss other lightweight libraries? Szabolcs Nagy
2013-04-24 19:17                       ` Rich Felker
2013-04-25  6:40                         ` Szabolcs Nagy
2013-04-25 19:37                     ` Rob Landley
2013-04-24 13:28                   ` go support (was: Best place to discuss other lightweight libraries?) John Spencer
2013-04-24 13:42                     ` Rich Felker
2013-04-24 14:06                   ` Best place to discuss other lightweight libraries? Christian Neukirchen
2013-04-29 11:41                     ` Daniel Cegiełka
2013-04-29 16:31                       ` Go (was: [musl] Best place to discuss other lightweight libraries?) John Spencer
2013-04-29 16:44                         ` Daniel Cegiełka
2013-04-23  0:31       ` Best place to discuss other lightweight libraries? Rob Landley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130422230628.GT20323@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).