Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2017-04-13 06:30:53 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-04-13 06:37:27 +0300
commit64660b902c3fb52fe5a3cb5bf232f90283db8732 (patch)
treec9549b247ca35e92c3f03db4f07d95aaede60e48 /intern
parentc080702e73f1729897033343d44198488b6fed9f (diff)
Use 'safe' macros for common free operation
Same as MEM_SAFE_FREE macro, checks for NULL, runs free then sets NULL. Blocks of code that do this many times are noisy and likely errors here wouldn't be noticed immediately. Also NULL's static vars which were being left set.
Diffstat (limited to 'intern')
-rw-r--r--intern/gawain/gawain/batch.h16
-rw-r--r--intern/gawain/gawain/element.h10
-rw-r--r--intern/gawain/gawain/vertex_buffer.h10
3 files changed, 36 insertions, 0 deletions
diff --git a/intern/gawain/gawain/batch.h b/intern/gawain/gawain/batch.h
index 532c45ae832..2802dad3db3 100644
--- a/intern/gawain/gawain/batch.h
+++ b/intern/gawain/gawain/batch.h
@@ -109,3 +109,19 @@ Batch* create_BatchWithOwnVertexBufferAndElementList(PrimitiveType, VertexFormat
Batch* create_BatchInGeneral(PrimitiveType, VertexBufferStuff, ElementListStuff);
#endif // future plans
+
+
+/* Macros */
+
+#define BATCH_DISCARD_SAFE(batch) do { \
+ if (batch != NULL) { \
+ Batch_discard(batch); \
+ batch = NULL; \
+ } \
+} while (0)
+#define BATCH_DISCARD_ALL_SAFE(batch) do { \
+ if (batch != NULL) { \
+ Batch_discard_all(batch); \
+ batch = NULL; \
+ } \
+} while (0)
diff --git a/intern/gawain/gawain/element.h b/intern/gawain/gawain/element.h
index f22d7c0ffda..fde395ce898 100644
--- a/intern/gawain/gawain/element.h
+++ b/intern/gawain/gawain/element.h
@@ -62,3 +62,13 @@ ElementList* ElementList_build(ElementListBuilder*);
void ElementList_build_in_place(ElementListBuilder*, ElementList*);
void ElementList_discard(ElementList*);
+
+
+/* Macros */
+
+#define ELEMENTLIST_DISCARD_SAFE(elem) do { \
+ if (elem != NULL) { \
+ ElementList_discard(elem); \
+ elem = NULL; \
+ } \
+} while (0)
diff --git a/intern/gawain/gawain/vertex_buffer.h b/intern/gawain/gawain/vertex_buffer.h
index 687f15e9e98..3a2575fa2e1 100644
--- a/intern/gawain/gawain/vertex_buffer.h
+++ b/intern/gawain/gawain/vertex_buffer.h
@@ -62,3 +62,13 @@ void VertexBuffer_fill_attrib_stride(VertexBuffer*, unsigned a_idx, unsigned str
// void setAttrib4ub(unsigned a_idx, unsigned v_idx, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
void VertexBuffer_use(VertexBuffer*);
+
+
+/* Macros */
+
+#define VERTEXBUFFER_DISCARD_SAFE(verts) do { \
+ if (verts != NULL) { \
+ VertexBuffer_discard(verts); \
+ verts = NULL; \
+ } \
+} while (0)