From: Igor Munkin <imun@tarantool.org> To: Sergey Kaplun <skaplun@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH luajit v2 2/7] core: introduce write buffer module Date: Sat, 26 Dec 2020 17:22:25 +0300 [thread overview] Message-ID: <20201226142225.GH5396@tarantool.org> (raw) In-Reply-To: <cf6d3a0728d2d34cb3ab6cb91e3db5ee68093e21.1608907726.git.skaplun@tarantool.org> Sergey, Thanks for the patch! LGTM, except the nits below. On 25.12.20, Sergey Kaplun wrote: > This patch introduces the standalone module for writing data to the > file, socket or memory (and so on) via the special buffer. > The module provides the API for buffer initial setup > and its convenient usage. > > Part of tarantool/tarantool#5442 > --- > > Changes in v2: > - Removed custom memcpy. > - lj_wbuf_addn() fills buffer to the end first and then flushes. > - Changed assert in lj_wbuf_flush() to early return. > > src/Makefile | 2 +- > src/Makefile.dep | 23 ++++---- > src/lj_wbuf.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++ > src/lj_wbuf.h | 87 +++++++++++++++++++++++++++++ > src/ljamalg.c | 1 + > 5 files changed, 242 insertions(+), 12 deletions(-) > create mode 100644 src/lj_wbuf.c > create mode 100644 src/lj_wbuf.h > <snipped> > diff --git a/src/Makefile.dep b/src/Makefile.dep > index 75409bf..59ed450 100644 > --- a/src/Makefile.dep > +++ b/src/Makefile.dep > @@ -211,28 +211,29 @@ lj_vmevent.o: lj_vmevent.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ > lj_vm.h lj_vmevent.h > lj_vmmath.o: lj_vmmath.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ > lj_ir.h lj_vm.h > +lj_wbuf.o: lj_wbuf.c lj_wbuf.h lj_def.h lua.h luaconf.h lj_utils.h > ljamalg.o: ljamalg.c lua.h luaconf.h lauxlib.h lj_gc.c lj_obj.h lj_def.h \ <snipped> > - lj_utils_leb128.c lj_utils.h lib_aux.c lib_base.c lj_libdef.h lib_math.c \ > - lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c \ > - lib_bit.c lib_jit.c lib_ffi.c lib_misc.c lib_init.c > + lj_utils_leb128.c lib_aux.c lib_base.c lj_libdef.h lib_math.c lib_string.c \ > + lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_bit.c lib_jit.c \ > + lib_ffi.c lib_misc.c lib_init.c Minor: Why this part is changed? If this is done on purpose, please move this change to the previous patch. Otherwise, <make depends> looks buggy and I propose to make these changes manually. Feel free to ignore. > luajit.o: luajit.c lua.h luaconf.h lauxlib.h lualib.h luajit.h lj_arch.h <snipped> > diff --git a/src/lj_wbuf.c b/src/lj_wbuf.c > new file mode 100644 > index 0000000..8f090eb > --- /dev/null > +++ b/src/lj_wbuf.c > @@ -0,0 +1,141 @@ <snipped> > + /* > + ** Very unlikely: We are told to write a large buffer at once. > + ** Buffer not belong to us so we must to pump data Typo: s/Buffer not belong/Buffer doesn't belong/. > + ** through buffer. Typo: s/through buffer/through the buffer/. > + */ <snipped> > diff --git a/src/lj_wbuf.h b/src/lj_wbuf.h > new file mode 100644 > index 0000000..58a109e > --- /dev/null > +++ b/src/lj_wbuf.h > @@ -0,0 +1,87 @@ <snipped> > +typedef size_t (*lj_wbuf_writer)(const void **data, size_t len, void *opt); > + > +/* Write buffer. */ > +struct lj_wbuf { > + /* > + ** Buffer writer which will called at buffer write. Typo: s/will called at buffer write/is called on the buffer flush/. > + ** Should return amount of written bytes on success or zero in case of error. > + ** *data should contain new buffer of size greater or equal to len. If you consider the <len> as a size of the new buffer, then you need to pass its pointer but not its value to the writer. Otherwise this requirement has no sense IMHO. > + ** If *data == NULL stream stops. Minor: It would be nice to describe the contract of this function near its typedef above. > + */ > + lj_wbuf_writer writer; > + /* Context for writer function. */ > + void *ctx; > + /* Buffer size. */ > + size_t size; > + /* Saved errno in case of error. */ > + int saved_errno; There is an empty padding to fit the alignment here. It's better to move this field right prior to the <flags>. > + /* Start of buffer. */ > + uint8_t *buf; > + /* Current position in buffer. */ > + uint8_t *pos; > + /* Internal flags. */ > + volatile uint8_t flags; > +}; > + > +/* Init buffer. */ Typo: s/Init buffer/Initialize the buffer/. > +void lj_wbuf_init(struct lj_wbuf *buf, lj_wbuf_writer writer, void *ctx, > + uint8_t *mem, size_t size); <snipped> > -- > 2.28.0 > -- Best regards, IM
next prev parent reply other threads:[~2020-12-26 14:22 UTC|newest] Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-12-25 15:26 [Tarantool-patches] [PATCH luajit v2 0/7] LuaJIT memory profiler Sergey Kaplun 2020-12-25 15:26 ` [Tarantool-patches] [PATCH luajit v2 1/7] utils: introduce leb128 reader and writer Sergey Kaplun 2020-12-25 21:42 ` Igor Munkin 2020-12-26 9:32 ` Sergey Kaplun 2020-12-26 13:57 ` Sergey Kaplun 2020-12-26 18:47 ` Sergey Ostanevich 2020-12-25 15:26 ` [Tarantool-patches] [PATCH luajit v2 2/7] core: introduce write buffer module Sergey Kaplun 2020-12-26 14:22 ` Igor Munkin [this message] 2020-12-26 15:26 ` Sergey Kaplun 2020-12-26 19:03 ` Sergey Ostanevich 2020-12-26 19:37 ` Sergey Kaplun 2020-12-28 1:43 ` Sergey Kaplun 2020-12-25 15:26 ` [Tarantool-patches] [PATCH luajit v2 3/7] vm: introduce VM states for Lua and fast functions Sergey Kaplun 2020-12-26 19:07 ` Sergey Ostanevich 2020-12-27 23:48 ` Igor Munkin 2020-12-28 3:54 ` Sergey Kaplun 2020-12-25 15:26 ` [Tarantool-patches] [PATCH luajit v2 4/7] core: introduce new mem_L field Sergey Kaplun 2020-12-26 19:12 ` Sergey Ostanevich 2020-12-26 19:42 ` Sergey Kaplun 2020-12-27 13:09 ` Igor Munkin 2020-12-27 17:44 ` Sergey Kaplun 2020-12-25 15:26 ` [Tarantool-patches] [PATCH luajit v2 5/7] core: introduce memory profiler Sergey Kaplun 2020-12-27 10:58 ` Sergey Ostanevich 2020-12-27 11:54 ` Sergey Kaplun 2020-12-27 13:27 ` Sergey Ostanevich 2020-12-27 16:44 ` Igor Munkin 2020-12-27 21:47 ` Sergey Kaplun 2020-12-25 15:26 ` [Tarantool-patches] [PATCH luajit v2 6/7] misc: add Lua API for " Sergey Kaplun 2020-12-27 11:54 ` Sergey Ostanevich 2020-12-27 13:42 ` Sergey Kaplun 2020-12-27 15:37 ` Sergey Ostanevich 2020-12-27 18:58 ` Igor Munkin 2020-12-28 0:14 ` Sergey Kaplun 2020-12-25 15:26 ` [Tarantool-patches] [PATCH luajit v2 7/7] tools: introduce a memory profile parser Sergey Kaplun 2020-12-26 22:56 ` Igor Munkin 2020-12-27 7:16 ` Sergey Kaplun 2020-12-28 5:30 ` Sergey Kaplun 2020-12-28 5:33 ` Igor Munkin 2020-12-28 6:28 ` Sergey Kaplun 2020-12-28 6:31 ` Igor Munkin 2020-12-27 13:24 ` Sergey Ostanevich 2020-12-27 16:02 ` Sergey Kaplun 2020-12-27 21:55 ` Sergey Ostanevich 2020-12-28 2:05 ` [Tarantool-patches] [PATCH luajit v3 2/2] misc: add Lua API for memory profiler Sergey Kaplun 2020-12-28 2:49 ` Igor Munkin 2020-12-28 5:19 ` Sergey Kaplun 2020-12-28 2:06 ` [Tarantool-patches] [PATCH luajit v3 1/2] core: introduce " Sergey Kaplun 2020-12-28 3:59 ` Igor Munkin 2020-12-28 4:05 ` [Tarantool-patches] [PATCH luajit v3 3/7] vm: introduce VM states for Lua and fast functions Sergey Kaplun 2020-12-28 5:14 ` Igor Munkin 2020-12-28 6:01 ` [Tarantool-patches] [PATCH luajit v2 0/7] LuaJIT memory profiler Alexander V. Tikhonov 2020-12-28 8:15 ` Igor Munkin
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=20201226142225.GH5396@tarantool.org \ --to=imun@tarantool.org \ --cc=skaplun@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH luajit v2 2/7] core: introduce write buffer module' \ /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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox