Re: [PATCH v2 05/17] odb/source-inmemory: implement `read_object_stream()` callback
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Apr 9, 2026, 10:41 UTC
- Message-ID
- <adeCaAonGgwJFbQ5@pks.im>
- In-Reply-To
- <CAOLa=ZSHAF25zbJ=KHp=u0pFCpAHb-jd45A3dxTSn9pwKHkxFQ@mail.gmail.com>
On Thu, Apr 09, 2026 at 05:49:32AM -0400, Karthik Nayak wrote:
Show 42 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
>
> > Implement the `read_object_stream()` callback function for the in-memory
> > source.
> >
> > Signed-off-by: Patrick Steinhardt <ps@pks.im>
> > ---
> > odb/source-inmemory.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 50 insertions(+)
> >
> > diff --git a/odb/source-inmemory.c b/odb/source-inmemory.c
> > index 12c80f9b34..4a68169430 100644
> > --- a/odb/source-inmemory.c
> > +++ b/odb/source-inmemory.c
> > @@ -53,6 +54,54 @@ static int odb_source_inmemory_read_object_info(struct odb_source *source,
> > return 0;
> > }
> >
> > +struct odb_read_stream_inmemory {
> > + struct odb_read_stream base;
> > + const void *buf;
> > + size_t offset;
> > +};
> > +
>
> To stream objects, we have a new structure which is used in the callback.
>
> > +static ssize_t odb_read_stream_inmemory_read(struct odb_read_stream *stream,
> > + char *buf, size_t buf_len)
> > +{
> > + struct odb_read_stream_inmemory *inmemory =
> > + container_of(stream, struct odb_read_stream_inmemory, base);
> > + size_t bytes = buf_len;
>
>
>
> > + if (buf_len > inmemory->base.size - inmemory->offset)
> > + bytes = inmemory->base.size - inmemory->offset;
> > + memcpy(buf, inmemory->buf, bytes);
> > +
>
> Shouldn't the offset also be set and we only memcpy offset onwards?Oh, good catch. We don't have any users of this API yet, which is why it went undetected. Will fix, thanks.
Patrick