[cgma-dev] r3166 - cgm/trunk/itaps
kraftche at cae.wisc.edu
kraftche at cae.wisc.edu
Thu Sep 24 17:16:34 CDT 2009
Author: kraftche
Date: 2009-09-24 17:16:34 -0500 (Thu, 24 Sep 2009)
New Revision: 3166
Modified:
cgm/trunk/itaps/CATag.cpp
Log:
o Rewrite most of TAG_CHECK_SIZE as an inline function rather than a macro,
making debugging easier, valgrind output more meaningfull, etc.
o Fix bug where TAG_CHECK_SIZE attempts to free and re-allocate an input
array if it is of insufficient size. This is a violation of the ITAPS
API specifications and was resulting in nasty stuff like deleting the
underlying array out from underneath an std::vector.
Modified: cgm/trunk/itaps/CATag.cpp
===================================================================
--- cgm/trunk/itaps/CATag.cpp 2009-09-24 22:14:13 UTC (rev 3165)
+++ cgm/trunk/itaps/CATag.cpp 2009-09-24 22:16:34 UTC (rev 3166)
@@ -46,17 +46,27 @@
}; \
array ## _size = this_size;
-#define TAG_CHECK_SIZE(array, allocated, size) \
- if (allocated < size) {\
- if (NULL != array) free(array); \
- allocated=size; \
- array = (char*)malloc(allocated); \
- if (NULL == array) {\
- iGeom_setLastError(iBase_MEMORY_ALLOCATION_FAILED); \
- return iBase_MEMORY_ALLOCATION_FAILED; \
- }\
+static inline iBase_ErrorType tag_check_size( char*& array,
+ int& allocated,
+ int size )
+{
+ if (!array || !allocated) {
+ allocated = size;
+ array = (char*)malloc(allocated);
+ if (!array)
+ return iBase_MEMORY_ALLOCATION_FAILED;
}
+ else if (allocated < size) {
+ return iBase_BAD_ARRAY_SIZE;
+ }
+
+ return iBase_SUCCESS;
+}
+#define TAG_CHECK_SIZE(array, allocated, size) \
+ if (iBase_ErrorType tag_check_size_tmp = tag_check_size( array, allocated, size )) \
+ return tag_check_size_tmp;
+
#define RETURN(a) {iGeom_setLastError(a); return a;}
const char *CGMTagManager::CATag_NAME = "ITAPS_Tag";
More information about the cgma-dev
mailing list