public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Corinna Vinschen <vinschen@redhat.com>
To: newlib@sourceware.org
Cc: Giovanni Bajo <rasky@develer.com>
Subject: Re: [PATCH] Allow fseek optimization also for cookied files.
Date: Mon, 20 Feb 2023 11:41:48 +0100	[thread overview]
Message-ID: <Y/NObJpoa/ngZrWo@calimero.vinschen.de> (raw)
In-Reply-To: <20230219014020.92927-1-rasky@develer.com>

On Feb 19 02:40, Giovanni Bajo wrote:
> Currently, fseek allows for a seek optimization where it does not
> actually seek if the target is within the current buffer. This
> optimization, though, is disabled in case of files with custom seek
> functions, such as those created by funopen / fopencookie. 
> 
> This prevents a useful use case of those functions: creating a transparent
> streaming decompressor (eg: gzopen). In fact, it is customary to
> allow streaming decompressors to be able to seek forward (by skipping
> bytes), but because of the missing seek optimization, even a simple
> one-byte seek forward might become a backward seek (that is, a seek
> that moves from the end of the current buffer backward to the seek
> destination within the buffer).
> 
> Since the check was explicit, there might be good reasons for it that
> elude me. It looks to me that if buffering is allowed by files
> returned by funopen, then the seek optimization cannot be a violation
> of the funopen protocol, because otherwise it should also be invalid
> to call the underlying readfn callback with size BUFSIZ when the user
> requested a different size. People that want an absolute 1:1 match
> between user-level calls and callbacks can obtain that by disabling
> buffering.

I'm not entirely sure about the reasing behind this, but the code in
newlib in terms of the seek optimization is still equivalent to the
upstream code in OpenBSD as well as FreeBSD.

Changing such a crucial piece of code and deviating from upstream
sounds like introducing subtil problems...


Corinna


      reply	other threads:[~2023-02-20 10:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-19  1:40 Giovanni Bajo
2023-02-20 10:41 ` Corinna Vinschen [this message]

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=Y/NObJpoa/ngZrWo@calimero.vinschen.de \
    --to=vinschen@redhat.com \
    --cc=newlib@sourceware.org \
    --cc=rasky@develer.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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).