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
* Version 1.6.5 released
......
......@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#if defined (HAVE_EXECINFO_H)
#include <execinfo.h>
......@@ -373,7 +374,7 @@ void reshReplace(cdiResH resH, void *p, const resOps *ops)
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;
int nsp;
......@@ -387,9 +388,9 @@ reshGetElem(const char *caller, cdiResH resH, const resOps *ops)
nsp = namespaceGetActive ();
nspT = namespaceResHDecode ( resH );
assert(nspT.idx >= 0);
if (nspT.nsp == nsp &&
nspT.idx >= 0 &&
nspT.idx < resHList[nsp].size)
{
listElem = resHList[nsp].resources + nspT.idx;
......@@ -399,23 +400,31 @@ reshGetElem(const char *caller, cdiResH resH, const resOps *ops)
{
LIST_UNLOCK();
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) )
{
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;
}
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 )
/**************************************************************/
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);
}
void
reshPackResource(int resH, const resOps *ops,
void *buf, int buf_size, int *position, void *context)
reshPackResource_intern(int resH, const resOps *ops, 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);
}
......
......@@ -59,8 +59,9 @@ void reshDestroy(cdiResH);
int reshCountType ( const resOps * );
void * reshGetValue(const char *, cdiResH, const resOps * );
#define reshGetVal(resH, ops) reshGetValue(__func__, resH, ops)
void * reshGetValue(const char* caller, const char* expressionString, cdiResH id, const resOps* ops);
#define reshGetVal(resH, ops) reshGetValue(__func__, #resH, resH, ops)
void reshGetResHListOfType ( int, int *, const resOps * );
......@@ -80,9 +81,11 @@ cdiResHFilterApply(const resOps *p,
void reshPackBufferCreate ( char **, int *, void *context );
void reshPackBufferDestroy ( char ** );
int reshResourceGetPackSize(int resh, const resOps *ops, void *context);
void reshPackResource(int resh, const resOps *ops,
void *buf, int buf_size, int *position, void *context);
int reshResourceGetPackSize_intern(int resh, const resOps *ops, void *context, const char* caller, const char* expressionString);
#define reshResourceGetPackSize(resh, ops, context) reshResourceGetPackSize_intern(resh, ops, context, __func__, #resh)
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 );
int reshGetStatus ( cdiResH, const resOps * );
......
......@@ -86,10 +86,10 @@ resOps vlist_ops = {
};
vlist_t *vlist_to_pointer(int code)
vlist_t *vlist_to_pointer(int vlistID)
{
VLIST_INIT();
return (vlist_t*) reshGetVal(code, &vlist_ops );
return (vlist_t*) reshGetVal(vlistID, &vlist_ops );
}
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