Implement custom assert macro

Reviewed By: javache

Differential Revision: D3648805

fbshipit-source-id: a6bf1bb55e1e0ee37284647ab76d66f3956a66c0
This commit is contained in:
Emil Sjolander 2016-08-02 08:07:11 -07:00 committed by Facebook Github Bot
parent 2d168fcd61
commit f94e4348dd
4 changed files with 22 additions and 8 deletions

View File

@ -27,7 +27,7 @@ __forceinline const float fmaxf(const float a, const float b) {
CSSNodeRef CSSNodeNew() {
CSSNodeRef node = calloc(1, sizeof(CSSNode));
assert(node != NULL);
CSS_ASSERT(node != NULL, "Could not allocate memory for node");
CSSNodeInit(node);
return node;
@ -119,8 +119,7 @@ uint32_t CSSNodeChildCount(CSSNodeRef node) {
}
void CSSNodeMarkDirty(CSSNodeRef node) {
// Nodes without custom measure functions should not manually mark themselves as dirty
assert(node->measure != NULL);
CSS_ASSERT(node->measure != NULL, "Nodes without custom measure functions should not manually mark themselves as dirty");
_CSSNodeMarkDirty(node);
}
@ -794,8 +793,8 @@ static void setPosition(CSSNode* node, CSSDirection direction) {
static void layoutNodeImpl(CSSNode* node, float availableWidth, float availableHeight,
CSSDirection parentDirection, CSSMeasureMode widthMeasureMode, CSSMeasureMode heightMeasureMode, bool performLayout) {
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(availableWidth) ? widthMeasureMode == CSSMeasureModeUndefined : true, "availableWidth is indefinite so widthMeasureMode must be CSSMeasureModeUndefined");
CSS_ASSERT(isUndefined(availableHeight) ? heightMeasureMode == CSSMeasureModeUndefined : true, "availableHeight is indefinite so heightMeasureMode must be CSSMeasureModeUndefined");
float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, CSSFlexDirectionRow);
float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSSFlexDirectionColumn);

View File

@ -16,3 +16,17 @@
# define CSS_EXTERN_C_BEGIN
# define CSS_EXTERN_C_END
#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(); \
}

View File

@ -17,12 +17,12 @@ struct CSSNodeList {
CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity) {
CSSNodeListRef list = malloc(sizeof(struct CSSNodeList));
assert(list != NULL);
CSS_ASSERT(list != NULL, "Could not allocate memory for list");
list->capacity = initialCapacity;
list->count = 0;
list->items = malloc(sizeof(void*) * list->capacity);
assert(list->items != NULL);
CSS_ASSERT(list->items != NULL, "Could not allocate memory for items");
return list;
}
@ -43,7 +43,7 @@ void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, uint32_t index) {
if (list->count == list->capacity) {
list->capacity *= 2;
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--) {

View File

@ -15,6 +15,7 @@
#include <stdint.h>
#include <CSSLayout/CSSLayout.h>
#include <CSSLayout/CSSMacros.h>
CSS_EXTERN_C_BEGIN