Commit Graph

3 Commits

Author SHA1 Message Date
Erik Faye-Lund 9f717b5f23 util: remove needless c99_compat.h includes
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@collabora.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16812>
2022-06-02 13:09:16 +00:00
Yonggang Luo d9c3601e29 util: trim trailing space for files src/util/**/*
Using the following bash script doing that
```
cd src/util
find . -type f -print0 | xargs -0 -n1 sed -i 's/[ \t]*$//'
```

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15093>
2022-03-21 17:57:15 +00:00
Mike Blumenkrantz 171ccdbf1c util: add ptralloc
many times it will be the case that an allocation for a block of data
needs to be done in one alloc() call such that the members of a struct as well
as some extra trailing data are all in the same allocation like

```
struct Test {
  unsigned a[4];
  unsigned c;
};
unsigned *b; //ptr to uint[8]
```

should be allocated as a single block of (13 * sizeof(unsigned)) memory using
C pointer offsets to allocate the memory as

```
| Test | b |
```

with something like

```
struct Test *t = malloc(sizeof(struct Test) + (8 * sizeof(unsigned)));
```

and then set `b` with

```
t->b = ((uint8_t*)t) + sizeof(struct Test);
```

this is annoying, awful to read, and (at least for dum-dums like me) prone to errors,
however, so having some utility functions which can deliver the same
functionality with better readability helps out this case by transforming it to

```
unsigned *b;
void **ptrs[] = {(void*)&b};
size_t sizes[] = {8 * sizeof(unsigned));
struct Test *t = ptralloc(sizeof(struct Test), 1, sizes, ptrs);
```

where `b` is now set to the appropriate offset in memory

Acked-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13678>
2022-01-19 04:10:58 +00:00