Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/database/src/ioc/db/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ HTMLS += dbCommonOutput.html

dbCore_SRCS += dbLock.c
dbCore_SRCS += dbAccess.c
dbCore_SRCS += dbAccessNoThrow.c
dbCore_SRCS += dbBkpt.c
dbCore_SRCS += dbChannel.c
dbCore_SRCS += dbConstLink.c
Expand Down
5 changes: 3 additions & 2 deletions modules/database/src/ioc/db/dbAccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "caeventmask.h"
#include "callback.h"
#include "dbAccessDefs.h"
#include "dbAccessNoThrow.h"
#include "dbAddr.h"
#include "dbBase.h"
#include "dbBkpt.h"
Expand Down Expand Up @@ -928,7 +929,7 @@ long dbGet(DBADDR *paddr, short dbrType,
if(!paddr->vfields || !(prset=dbGetRset(paddr))->get_vfield)
return S_db_badDbrtype;

return prset->get_vfield(paddr, vfield);
return dbRecSupGetVFieldNoThrow(prset, paddr, vfield);
}

if (nRequest && *nRequest == 0)
Expand Down Expand Up @@ -1345,7 +1346,7 @@ long dbPut(DBADDR *paddr, short dbrType,
if(!paddr->vfields || !prset->put_vfield)
return S_db_badDbrtype;

return prset->put_vfield(paddr, vfield);
return dbRecSupPutVFieldNoThrow(prset, paddr, vfield);
}

if (special == SPC_ATTRIBUTE || paddr->ro)
Expand Down
60 changes: 60 additions & 0 deletions modules/database/src/ioc/db/dbAccessNoThrow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*************************************************************************\
* Copyright (c) 2021 Lucas Russo
* SPDX-License-Identifier: EPICS
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/

#include <stdexcept>

#include "recSup.h"
#include "dbAccessDefs.h"
#include "errlog.h"
#include "dbAccessNoThrow.h"

/*
* Maps possible excpetions to DB error codes. Using the
* "exception dispatcher" pattern.
*/
inline long dbExceptionToLong()
{
try {
throw;
}
catch (std::exception& e) {
errlogPrintf("dbExceptionToLong: Unhandled exception %s: %s\n",
typeid(e).name(), e.what());
return S_db_errArg;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is much value in translating specific exceptions.

It might be more useful to print the specific exception type typeid(e).name() along with e.what().

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Is S_db_errArg a good error for this general "unhandled exception" case?

}

/*
* Pseudo variadic templates for use without C++11 features
*/

template <typename F, typename T1, typename T2>
long dbRecSupNoThrowWrapper(F f, T1 t1, T2 t2) {
try {
return f(t1, t2);
}
catch(...){
return dbExceptionToLong();
}
}

/*
* Wraps all RecordSupport functions from throwable functions to no-throwable ones,
* without using C++11 features
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this does give a good example of why I didn't do this initially. For the moment, let's only add wrappers as they used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sounds good.

*
* For use with C code
*/

long dbRecSupGetVFieldNoThrow(rset *prset, struct dbAddr *paddr, struct VField *vfield)
{
return dbRecSupNoThrowWrapper(prset->get_vfield, paddr, vfield);
}

long dbRecSupPutVFieldNoThrow(rset *prset, struct dbAddr *paddr, const struct VField *vfield)
{
return dbRecSupNoThrowWrapper(prset->put_vfield, paddr, vfield);
}
26 changes: 26 additions & 0 deletions modules/database/src/ioc/db/dbAccessNoThrow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*************************************************************************\
* Copyright (c) 2021 Lucas Russo
* SPDX-License-Identifier: EPICS
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/

#ifndef INC_dbAccessNoThrow_H
#define INC_dbAccessNoThrow_H

#include <dbCoreAPI.h>

#ifdef __cplusplus
extern "C" {
#endif

DBCORE_API long dbRecSupGetVFieldNoThrow(rset *prset,
struct dbAddr *paddr, struct VField *vfield);
DBCORE_API long dbRecSupPutVFieldNoThrow(rset *prset,
struct dbAddr *paddr, const struct VField *vfield);

#ifdef __cplusplus
}
#endif

#endif /* INC_dbAccessNoThrow_H */