ilo: assert core objects are zero-initialized

Core objects are usually embedded inside calloc()'ed objects and we expect
them to be zero-initialized.
This commit is contained in:
Chia-I Wu
2015-05-22 13:49:20 +08:00
parent 4d35eef326
commit ab7229b9b6
6 changed files with 29 additions and 2 deletions
@@ -31,6 +31,7 @@
#include "intel_winsys.h"
#include "ilo_core.h"
#include "ilo_debug.h"
#include "ilo_dev.h"
struct ilo_buffer {
@@ -43,6 +44,8 @@ static inline void
ilo_buffer_init(struct ilo_buffer *buf, const struct ilo_dev *dev,
unsigned size, uint32_t bind, uint32_t flags)
{
assert(ilo_is_zeroed(buf, sizeof(*buf)));
buf->bo_size = size;
/*
+1 -1
View File
@@ -333,7 +333,7 @@ ilo_builder_init(struct ilo_builder *builder,
{
int i;
memset(builder, 0, sizeof(*builder));
assert(ilo_is_zeroed(builder, sizeof(*builder)));
builder->dev = dev;
builder->winsys = winsys;
+17
View File
@@ -100,4 +100,21 @@ ilo_warn(const char *format, ...)
#endif
}
static inline bool
ilo_is_zeroed(const void *ptr, size_t size)
{
#ifdef DEBUG
size_t i;
for (i = 0; i < size; i++) {
if (*((const char *) ptr) != 0)
return false;
}
return true;
#else
return true;
#endif
}
#endif /* ILO_DEBUG_H */
+2
View File
@@ -40,6 +40,8 @@ ilo_dev_init(struct ilo_dev *dev, struct intel_winsys *winsys)
{
const struct intel_winsys_info *info;
assert(ilo_is_zeroed(dev, sizeof(*dev)));
info = intel_winsys_get_info(winsys);
dev->winsys = winsys;
+2 -1
View File
@@ -31,6 +31,7 @@
#include "intel_winsys.h"
#include "ilo_core.h"
#include "ilo_debug.h"
#include "ilo_dev.h"
struct ilo_fence {
@@ -40,7 +41,7 @@ struct ilo_fence {
static inline void
ilo_fence_init(struct ilo_fence *fence, const struct ilo_dev *dev)
{
/* no-op */
assert(ilo_is_zeroed(fence, sizeof(*fence)));
}
static inline void
+4
View File
@@ -1386,6 +1386,8 @@ void ilo_image_init(struct ilo_image *img,
struct ilo_image_params params;
bool transfer_only;
assert(ilo_is_zeroed(img, sizeof(*img)));
/* use transfer layout when the texture is never bound to GPU */
transfer_only = !(templ->bind & ~(PIPE_BIND_TRANSFER_WRITE |
PIPE_BIND_TRANSFER_READ));
@@ -1411,6 +1413,8 @@ ilo_image_init_for_imported(struct ilo_image *img,
{
struct ilo_image_params params;
assert(ilo_is_zeroed(img, sizeof(*img)));
if ((tiling == GEN6_TILING_X && bo_stride % 512) ||
(tiling == GEN6_TILING_Y && bo_stride % 128) ||
(tiling == GEN8_TILING_W && bo_stride % 64))