[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/5] 9pfs: introduce P9Array
From: |
Daniel P . Berrangé |
Subject: |
Re: [PATCH 1/5] 9pfs: introduce P9Array |
Date: |
Fri, 1 Oct 2021 16:16:47 +0100 |
User-agent: |
Mutt/2.0.7 (2021-05-04) |
On Fri, Oct 01, 2021 at 04:26:17PM +0200, Christian Schoenebeck wrote:
> Implements deep auto free of arrays while retaining common C-style
> squared bracket access. Main purpose of this API is to get rid of
> error prone individual array deallocation pathes in user code, i.e.
> turning something like this:
>
> void doSomething(size_t n) {
> Foo *foos = malloc(n * sizeof(Foo));
> for (...) {
> foos[i].s = malloc(...);
> if (...) {
> goto out;
> }
> }
> out:
> if (...) {
> for (...) {
> /* deep deallocation */
> free(foos[i].s);
> }
> /* array deallocation */
> free(foos);
> }
> }
>
> into something more simple and safer like:
>
> void doSomething(size_t n) {
> P9ARRAY_REF(Foo) foos = NULL;
> P9ARRAY_NEW(Foo, foos, n);
> for (...) {
> foos[i].s = malloc(...);
> if (...) {
> return; /* array auto freed here */
> }
> }
> /* array auto freed here */
> }
As explained before, I'm against the idea of introducing new ways
to automatically free local variables that are not using g_auto*
functionality. It is not following the QEMU wide coding style
that is documented.
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
- [PATCH 0/5] 9pfs: introduce P9Array, Christian Schoenebeck, 2021/10/01
- [PATCH 1/5] 9pfs: introduce P9Array, Christian Schoenebeck, 2021/10/01
- Re: [PATCH 1/5] 9pfs: introduce P9Array,
Daniel P . Berrangé <=
- [PATCH 2/5] fsdev/p9array.h: check scalar type in P9ARRAY_NEW(), Christian Schoenebeck, 2021/10/01
- [PATCH 3/5] 9pfs: make V9fsString usable via P9Array API, Christian Schoenebeck, 2021/10/01
- [PATCH 4/5] 9pfs: make V9fsPath usable via P9Array API, Christian Schoenebeck, 2021/10/01
- [PATCH 5/5] 9pfs: use P9Array in v9fs_walk(), Christian Schoenebeck, 2021/10/01
- Re: [PATCH 0/5] 9pfs: introduce P9Array, Christian Schoenebeck, 2021/10/14