summaryrefslogtreecommitdiffstats
path: root/Alc/vector.h
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-04-03 11:13:12 -0700
committerChris Robinson <[email protected]>2014-04-03 11:13:12 -0700
commit482fb37b688b94f5aff78a8dc34e78c1e2840058 (patch)
treed32b2e32aa76df381019151b137f420dde3a1ffe /Alc/vector.h
parent570eb4e1a7efb15a93a8b70e9293de6523b63284 (diff)
Recognize NULL as an empty vector/string
Diffstat (limited to 'Alc/vector.h')
-rw-r--r--Alc/vector.h10
1 files changed, 5 insertions, 5 deletions
diff --git a/Alc/vector.h b/Alc/vector.h
index 4c994581..57939719 100644
--- a/Alc/vector.h
+++ b/Alc/vector.h
@@ -18,7 +18,7 @@ typedef struct vector__s {
} *vector_##T; \
typedef const struct vector_##T##_s *const_vector_##T;
-#define VECTOR_INIT(_x) do { (_x) = calloc(1, sizeof(*(_x))); } while(0)
+#define VECTOR_INIT(_x) do { (_x) = NULL; } while(0)
#define VECTOR_DEINIT(_x) do { free((_x)); (_x) = NULL; } while(0)
/* Helper to increase a vector's reserve. Do not call directly. */
@@ -29,13 +29,13 @@ ALboolean vector_reserve(void *ptr, size_t base_size, size_t obj_count, size_t o
ALboolean vector_resize(void *ptr, size_t base_size, size_t obj_count, size_t obj_size);
#define VECTOR_RESIZE(_x, _c) (vector_resize(&(_x), sizeof(*(_x)), (_c), sizeof((_x)->Data[0])))
-#define VECTOR_CAPACITY(_x) ((const ALsizei)(_x)->Capacity)
-#define VECTOR_SIZE(_x) ((const ALsizei)(_x)->Size)
+#define VECTOR_CAPACITY(_x) ((const ALsizei)((_x) ? (_x)->Capacity : 0))
+#define VECTOR_SIZE(_x) ((const ALsizei)((_x) ? (_x)->Size : 0))
#define VECTOR_ITER_BEGIN(_x) ((_x)->Data)
-#define VECTOR_ITER_END(_x) ((_x)->Data + (_x)->Size)
+#define VECTOR_ITER_END(_x) ((_x)->Data + VECTOR_SIZE((_x)))
-#define VECTOR_PUSH_BACK(_x, _obj) (vector_reserve(&(_x), sizeof(*(_x)), (_x)->Size+1, sizeof((_x)->Data[0]), AL_FALSE) && \
+#define VECTOR_PUSH_BACK(_x, _obj) (vector_reserve(&(_x), sizeof(*(_x)), VECTOR_SIZE(_x)+1, sizeof((_x)->Data[0]), AL_FALSE) && \
(((_x)->Data[(_x)->Size++] = (_obj)),AL_TRUE))
#define VECTOR_POP_BACK(_x) ((void)((_x)->Size--))