Commit 92d6a4e5 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

resource_handle: optimize error messages

parent c2526898
2014-10-23 Nathanael Huebbe
* resource_handle: optimize error messages
2014-10-23 Uwe Schulzweida 2014-10-23 Uwe Schulzweida
* Version 1.6.5 released * Version 1.6.5 released
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#if defined (HAVE_EXECINFO_H) #if defined (HAVE_EXECINFO_H)
#include <execinfo.h> #include <execinfo.h>
...@@ -373,7 +374,7 @@ void reshReplace(cdiResH resH, void *p, const resOps *ops) ...@@ -373,7 +374,7 @@ void reshReplace(cdiResH resH, void *p, const resOps *ops)
static listElem_t * static listElem_t *
reshGetElem(const char *caller, cdiResH resH, const resOps *ops) reshGetElem(const char *caller, const char* expressionString, cdiResH resH, const resOps *ops)
{ {
listElem_t *listElem; listElem_t *listElem;
int nsp; int nsp;
...@@ -387,9 +388,9 @@ reshGetElem(const char *caller, cdiResH resH, const resOps *ops) ...@@ -387,9 +388,9 @@ reshGetElem(const char *caller, cdiResH resH, const resOps *ops)
nsp = namespaceGetActive (); nsp = namespaceGetActive ();
nspT = namespaceResHDecode ( resH ); nspT = namespaceResHDecode ( resH );
assert(nspT.idx >= 0);
if (nspT.nsp == nsp && if (nspT.nsp == nsp &&
nspT.idx >= 0 &&
nspT.idx < resHList[nsp].size) nspT.idx < resHList[nsp].size)
{ {
listElem = resHList[nsp].resources + nspT.idx; listElem = resHList[nsp].resources + nspT.idx;
...@@ -399,23 +400,31 @@ reshGetElem(const char *caller, cdiResH resH, const resOps *ops) ...@@ -399,23 +400,31 @@ reshGetElem(const char *caller, cdiResH resH, const resOps *ops)
{ {
LIST_UNLOCK(); LIST_UNLOCK();
show_stackframe(); show_stackframe();
xabortC(caller, "Invalid namespace %d or index %d for resource handle %d when using namespace %d of size %d!",
nspT.nsp, nspT.idx, (int)resH, nsp, resHList[nsp].size); if ( resH == CDI_UNDEFID )
{
xabortC(caller, "Error while trying to resolve the ID \"%s\" in `%s()`: the value is CDI_UNDEFID (= %d).\n\tThis is most likely the result of a failed earlier call. Please check the IDs returned by CDI.", expressionString, caller, resH);
}
else
{
xabortC(caller, "Error while trying to resolve the ID \"%s\" in `%s()`: the value is garbage (= %d, which resolves to namespace = %d, index = %d).\n\tThis is either the result of using an uninitialized variable,\n\tof using a value as an ID that is not an ID,\n\tor of using an ID after it has been invalidated.", expressionString, caller, resH, nspT.nsp, nspT.idx);
}
} }
if ( !(listElem && listElem->res.v.ops == ops) ) if ( !(listElem && listElem->res.v.ops == ops) )
{ {
show_stackframe(); show_stackframe();
xabortC(caller, "Invalid resource handle %d, list element not found!", (int)resH);
xabortC(caller, "Error while trying to resolve the ID \"%s\" in `%s()`: list element not found. The failed ID is %d", expressionString, caller, (int)resH);
} }
return listElem; return listElem;
} }
void *reshGetValue(const char * caller, cdiResH resH, const resOps * ops) void *reshGetValue(const char * caller, const char* expressionString, cdiResH resH, const resOps * ops)
{ {
return reshGetElem(caller, resH, ops)->res.v.val; return reshGetElem(caller, expressionString, resH, ops)->res.v.val;
} }
/**************************************************************/ /**************************************************************/
...@@ -513,17 +522,17 @@ int reshCountType ( const resOps * ops ) ...@@ -513,17 +522,17 @@ int reshCountType ( const resOps * ops )
/**************************************************************/ /**************************************************************/
int int
reshResourceGetPackSize(int resH, const resOps *ops, void *context) reshResourceGetPackSize_intern(int resH, const resOps *ops, void *context, const char* caller, const char* expressionString)
{ {
listElem_t *curr = reshGetElem(__func__, resH, ops); listElem_t *curr = reshGetElem(caller, expressionString, resH, ops);
return curr->res.v.ops->valGetPackSize(curr->res.v.val, context); return curr->res.v.ops->valGetPackSize(curr->res.v.val, context);
} }
void void
reshPackResource(int resH, const resOps *ops, reshPackResource_intern(int resH, const resOps *ops, void *buf, int buf_size, int *position, void *context,
void *buf, int buf_size, int *position, void *context) const char* caller, const char* expressionString)
{ {
listElem_t *curr = reshGetElem(__func__, resH, ops); listElem_t *curr = reshGetElem(caller, expressionString, resH, ops);
curr->res.v.ops->valPack(curr->res.v.val, buf, buf_size, position, context); curr->res.v.ops->valPack(curr->res.v.val, buf, buf_size, position, context);
} }
......
...@@ -59,8 +59,9 @@ void reshDestroy(cdiResH); ...@@ -59,8 +59,9 @@ void reshDestroy(cdiResH);
int reshCountType ( const resOps * ); int reshCountType ( const resOps * );
void * reshGetValue(const char *, cdiResH, const resOps * ); void * reshGetValue(const char* caller, const char* expressionString, cdiResH id, const resOps* ops);
#define reshGetVal(resH, ops) reshGetValue(__func__, resH, ops) #define reshGetVal(resH, ops) reshGetValue(__func__, #resH, resH, ops)
void reshGetResHListOfType ( int, int *, const resOps * ); void reshGetResHListOfType ( int, int *, const resOps * );
...@@ -80,9 +81,11 @@ cdiResHFilterApply(const resOps *p, ...@@ -80,9 +81,11 @@ cdiResHFilterApply(const resOps *p,
void reshPackBufferCreate ( char **, int *, void *context ); void reshPackBufferCreate ( char **, int *, void *context );
void reshPackBufferDestroy ( char ** ); void reshPackBufferDestroy ( char ** );
int reshResourceGetPackSize(int resh, const resOps *ops, void *context); int reshResourceGetPackSize_intern(int resh, const resOps *ops, void *context, const char* caller, const char* expressionString);
void reshPackResource(int resh, const resOps *ops, #define reshResourceGetPackSize(resh, ops, context) reshResourceGetPackSize_intern(resh, ops, context, __func__, #resh)
void *buf, int buf_size, int *position, void *context); void reshPackResource_intern(int resh, const resOps *ops, void *buf, int buf_size, int *position, void *context, const char* caller, const char* expressionString);
#define reshPackResource(resh, ops, buf, buf_size, position, context) reshPackResource_intern(resh, ops, buf, buf_size, position, context, __func__, #resh)
void reshSetStatus ( cdiResH, const resOps *, int ); void reshSetStatus ( cdiResH, const resOps *, int );
int reshGetStatus ( cdiResH, const resOps * ); int reshGetStatus ( cdiResH, const resOps * );
......
...@@ -86,10 +86,10 @@ resOps vlist_ops = { ...@@ -86,10 +86,10 @@ resOps vlist_ops = {
}; };
vlist_t *vlist_to_pointer(int code) vlist_t *vlist_to_pointer(int vlistID)
{ {
VLIST_INIT(); VLIST_INIT();
return (vlist_t*) reshGetVal(code, &vlist_ops ); return (vlist_t*) reshGetVal(vlistID, &vlist_ops );
} }
static static
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment