Implement custom assert macro
Summary: assert.h assertion gets stripped from builds. I don't want these assertions to be stripped so implement a custom assert macro. This also allows the assertion to be documented with a message. Reviewed By: javache Differential Revision: D3648805 fbshipit-source-id: a6bf1bb55e1e0ee37284647ab76d66f3956a66c0
This commit is contained in:
committed by
Facebook Github Bot 7
parent
ac44d2ea6e
commit
9689062f6c
@@ -27,7 +27,7 @@ __forceinline const float fmaxf(const float a, const float b) {
|
|||||||
|
|
||||||
CSSNodeRef CSSNodeNew() {
|
CSSNodeRef CSSNodeNew() {
|
||||||
CSSNodeRef node = calloc(1, sizeof(CSSNode));
|
CSSNodeRef node = calloc(1, sizeof(CSSNode));
|
||||||
assert(node != NULL);
|
CSS_ASSERT(node != NULL, "Could not allocate memory for node");
|
||||||
|
|
||||||
CSSNodeInit(node);
|
CSSNodeInit(node);
|
||||||
return node;
|
return node;
|
||||||
@@ -119,8 +119,7 @@ uint32_t CSSNodeChildCount(CSSNodeRef node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CSSNodeMarkDirty(CSSNodeRef node) {
|
void CSSNodeMarkDirty(CSSNodeRef node) {
|
||||||
// Nodes without custom measure functions should not manually mark themselves as dirty
|
CSS_ASSERT(node->measure != NULL, "Nodes without custom measure functions should not manually mark themselves as dirty");
|
||||||
assert(node->measure != NULL);
|
|
||||||
_CSSNodeMarkDirty(node);
|
_CSSNodeMarkDirty(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -794,8 +793,8 @@ static void setPosition(CSSNode* node, CSSDirection direction) {
|
|||||||
static void layoutNodeImpl(CSSNode* node, float availableWidth, float availableHeight,
|
static void layoutNodeImpl(CSSNode* node, float availableWidth, float availableHeight,
|
||||||
CSSDirection parentDirection, CSSMeasureMode widthMeasureMode, CSSMeasureMode heightMeasureMode, bool performLayout) {
|
CSSDirection parentDirection, CSSMeasureMode widthMeasureMode, CSSMeasureMode heightMeasureMode, bool performLayout) {
|
||||||
|
|
||||||
assert(isUndefined(availableWidth) ? widthMeasureMode == CSSMeasureModeUndefined : true); // availableWidth is indefinite so widthMeasureMode must be CSSMeasureModeUndefined
|
CSS_ASSERT(isUndefined(availableWidth) ? widthMeasureMode == CSSMeasureModeUndefined : true, "availableWidth is indefinite so widthMeasureMode must be CSSMeasureModeUndefined");
|
||||||
assert(isUndefined(availableHeight) ? heightMeasureMode == CSSMeasureModeUndefined : true); // availableHeight is indefinite so heightMeasureMode must be CSSMeasureModeUndefined
|
CSS_ASSERT(isUndefined(availableHeight) ? heightMeasureMode == CSSMeasureModeUndefined : true, "availableHeight is indefinite so heightMeasureMode must be CSSMeasureModeUndefined");
|
||||||
|
|
||||||
float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, CSSFlexDirectionRow);
|
float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, CSSFlexDirectionRow);
|
||||||
float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSSFlexDirectionColumn);
|
float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSSFlexDirectionColumn);
|
||||||
|
@@ -16,3 +16,17 @@
|
|||||||
# define CSS_EXTERN_C_BEGIN
|
# define CSS_EXTERN_C_BEGIN
|
||||||
# define CSS_EXTERN_C_END
|
# define CSS_EXTERN_C_END
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef FB_ASSERTIONS_ENABLED
|
||||||
|
#define FB_ASSERTIONS_ENABLED 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !(FB_ASSERTIONS_ENABLED)
|
||||||
|
#define abort()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CSS_ASSERT(X, message) \
|
||||||
|
if (!(X)) { \
|
||||||
|
fprintf(stderr, "%s\n", message); \
|
||||||
|
abort(); \
|
||||||
|
}
|
||||||
|
@@ -17,12 +17,12 @@ struct CSSNodeList {
|
|||||||
|
|
||||||
CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity) {
|
CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity) {
|
||||||
CSSNodeListRef list = malloc(sizeof(struct CSSNodeList));
|
CSSNodeListRef list = malloc(sizeof(struct CSSNodeList));
|
||||||
assert(list != NULL);
|
CSS_ASSERT(list != NULL, "Could not allocate memory for list");
|
||||||
|
|
||||||
list->capacity = initialCapacity;
|
list->capacity = initialCapacity;
|
||||||
list->count = 0;
|
list->count = 0;
|
||||||
list->items = malloc(sizeof(void*) * list->capacity);
|
list->items = malloc(sizeof(void*) * list->capacity);
|
||||||
assert(list->items != NULL);
|
CSS_ASSERT(list->items != NULL, "Could not allocate memory for items");
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, uint32_t index) {
|
|||||||
if (list->count == list->capacity) {
|
if (list->count == list->capacity) {
|
||||||
list->capacity *= 2;
|
list->capacity *= 2;
|
||||||
list->items = realloc(list->items, sizeof(void*) * list->capacity);
|
list->items = realloc(list->items, sizeof(void*) * list->capacity);
|
||||||
assert(list->items != NULL);
|
CSS_ASSERT(list->items != NULL, "Could not extend allocation for items");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t i = list->count; i > index; i--) {
|
for (uint32_t i = list->count; i > index; i--) {
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <CSSLayout/CSSLayout.h>
|
#include <CSSLayout/CSSLayout.h>
|
||||||
|
#include <CSSLayout/CSSMacros.h>
|
||||||
|
|
||||||
CSS_EXTERN_C_BEGIN
|
CSS_EXTERN_C_BEGIN
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user