From d92465cb37b8372266d6d430fbf1652cc8960acd Mon Sep 17 00:00:00 2001 From: kpl Date: Tue, 3 Dec 2013 13:48:31 -0800 Subject: [PATCH] cmData.h/c : Changed cmDataRecdAllocXXX() to return a cmDtRC_t. --- cmData.c | 42 +++++++++++++++++++++++++++++------------- cmData.h | 8 ++++---- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/cmData.c b/cmData.c index ab1e475..3bf2967 100644 --- a/cmData.c +++ b/cmData.c @@ -2146,46 +2146,60 @@ cmDtRC_t _cmDataRecdParseInputV(cmData_t* parent, cmErr_t* err, cmRC_t errRC, u return rc; } -cmData_t* cmDataRecdAllocLabelV( cmData_t* parent, cmErr_t* err, cmRC_t errRC, va_list vl ) +cmDtRC_t cmDataRecdAllocLabelV( cmData_t* parent, cmErr_t* err, cmRC_t errRC, cmData_t** ref, va_list vl ) { cmData_t* p = cmDataRecdAlloc(parent); + if( ref != NULL ) + *ref = NULL; + cmDtRC_t rc = _cmDataRecdParseInputV(p, err, errRC, false, vl ); if( rc != kOkDtRC ) { cmDataFree(p); p = NULL; } - return p; + + if( ref != NULL ) + *ref = p; + + return rc; } -cmData_t* cmDataRecdAllocLabelA( cmData_t* parent, cmErr_t* err, cmRC_t errRC, ... ) +cmDtRC_t cmDataRecdAllocLabelA( cmData_t* parent, cmErr_t* err, cmRC_t errRC, cmData_t** ref, ... ) { va_list vl; - va_start(vl,errRC); - cmData_t* p = cmDataRecdAllocLabelV(parent,err,errRC,vl); + va_start(vl,ref); + cmDtRC_t rc = cmDataRecdAllocLabelV(parent,err,errRC,ref,vl); va_end(vl); - return p; + return rc; } -cmData_t* cmDataRecdAllocIdV( cmData_t* parent, cmErr_t* err, cmRC_t errRC, va_list vl ) +cmDtRC_t cmDataRecdAllocIdV( cmData_t* parent, cmErr_t* err, cmRC_t errRC, cmData_t** ref, va_list vl ) { cmData_t* p = cmDataRecdAlloc(parent); + if( ref != NULL ) + *ref = NULL; + cmDtRC_t rc = _cmDataRecdParseInputV(p, err, errRC, true, vl ); if( rc != kOkDtRC ) { cmDataFree(p); p = NULL; } - return p; + + if( ref != NULL ) + *ref = p; + + return rc; } -cmData_t* cmDataRecdAllocIdA( cmData_t* parent, cmErr_t* err, cmRC_t errRC, ... ) +cmDtRC_t cmDataRecdAllocIdA( cmData_t* parent, cmErr_t* err, cmRC_t errRC, cmData_t** ref, ... ) { va_list vl; - va_start(vl,errRC); - cmData_t* p = cmDataRecdAllocIdV(parent,err,errRC,vl); + va_start(vl,ref); + cmRC_t rc = cmDataRecdAllocIdV(parent,err,errRC,ref,vl); va_end(vl); - return p; + return rc; } cmDtRC_t _cmDataRecdParseErrV( cmErr_t* err, unsigned rc, unsigned id, const cmChar_t* label, const cmChar_t* fmt, va_list vl ) @@ -3348,7 +3362,9 @@ void cmDataTest( cmCtx_t* ctx ) if( cmDataParserTest(ctx) != kOkDtRC ) return; - cmData_t* d0 = cmDataRecdAllocLabelA(NULL,&ctx->err,0, + cmData_t* d0 = NULL; + + cmDataRecdAllocLabelA(NULL,&ctx->err,0,&d0, "name", kStrDtId,"This is a string.", "id", kUIntDtId, 21, "real",kFloatDtId, 1.23, diff --git a/cmData.h b/cmData.h index dfeac24..aa54b72 100644 --- a/cmData.h +++ b/cmData.h @@ -631,11 +631,11 @@ extern "C" { // call. // 3) The cmDataRecdAllocLabelV() arg. list should be terminated with NULL. // The cmDataRecdAllocIdV() arg. list should be terminated with 'kInvalidDtId'. - cmData_t* cmDataRecdAllocLabelV( cmData_t* parent, cmErr_t* err, cmRC_t errRC, va_list vl ); - cmData_t* cmDataRecdAllocLabelA( cmData_t* parent, cmErr_t* err, cmRC_t errRC, ... ); + cmDtRC_t cmDataRecdAllocLabelV( cmData_t* parent, cmErr_t* err, cmRC_t errRC, cmData_t** ref, va_list vl ); + cmDtRC_t cmDataRecdAllocLabelA( cmData_t* parent, cmErr_t* err, cmRC_t errRC, cmData_t** ref, ... ); - cmData_t* cmDataRecdAllocIdV( cmData_t* parent, cmErr_t* err, cmRC_t errRC, va_list vl ); - cmData_t* cmDataRecdAllocIdA( cmData_t* parent, cmErr_t* err, cmRC_t errRC, ... ); + cmDtRC_t cmDataRecdAllocIdV( cmData_t* parent, cmErr_t* err, cmRC_t errRC, cmData_t** ref, va_list vl ); + cmDtRC_t cmDataRecdAllocIdA( cmData_t* parent, cmErr_t* err, cmRC_t errRC, cmData_t** ref, ... ); // Extract the data in a record to C variables. // Var-args format: