1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-02-07 13:42:41 +02:00
pgbackrest/libc/LibC.h
David Steele 48d0f77fe3 Remove dead LibC macros.
These macros were made obsolete when code was removed from LibC after the C migration was completed.
2020-02-21 11:31:31 -05:00

79 lines
7.6 KiB
C

/***********************************************************************************************************************************
Helper macros for LibC.xs
***********************************************************************************************************************************/
/***********************************************************************************************************************************
Package Names
***********************************************************************************************************************************/
#define PACKAGE_NAME "pgBackRest"
#define PACKAGE_NAME_LIBC PACKAGE_NAME "::LibC"
/***********************************************************************************************************************************
Error handling macros that throw a Perl error when a C error is caught
***********************************************************************************************************************************/
#define ERROR_XS_BEGIN() \
TRY_BEGIN()
#define ERROR_XS() \
croak("PGBRCLIB:%d:%s:%d:%s", errorCode(), errorFileName(), errorFileLine(), errorMessage());
#define ERROR_XS_END() \
CATCH_ANY() \
{ \
ERROR_XS(); \
} \
TRY_END();
/***********************************************************************************************************************************
Simplifies switching to a temp memory context in functions and includes error handling
***********************************************************************************************************************************/
#define MEM_CONTEXT_XS_TEMP() \
MEM_CONTEXT_XS_TEMP_memContext
#define MEM_CONTEXT_XS_TEMP_BEGIN() \
{ \
/* Create temp memory context */ \
MemContext *MEM_CONTEXT_XS_TEMP() = memContextNew("temporary"); \
\
/* Switch to temp memory context */ \
MemContext *MEM_CONTEXT_memContextPrior = memContextSwitch(MEM_CONTEXT_XS_TEMP()); \
\
/* Store any errors to be croaked to Perl at the end */ \
bool MEM_CONTEXT_XS_croak = false; \
\
/* Try the statement block */ \
TRY_BEGIN()
#define MEM_CONTEXT_XS_TEMP_END() \
/* Set error to be croak to Perl later */ \
CATCH_ANY() \
{ \
MEM_CONTEXT_XS_croak = true; \
} \
/* Free the context on error */ \
FINALLY() \
{ \
memContextSwitch(memContextPrior()); \
memContextFree(MEM_CONTEXT_XS_TEMP()); \
} \
TRY_END(); \
\
/* Croak on error */ \
if (MEM_CONTEXT_XS_croak) \
{ \
ERROR_XS() \
} \
}
/***********************************************************************************************************************************
Create new string from an SV
***********************************************************************************************************************************/
#define STR_NEW_SV(param) \
(SvOK(param) ? strNewN(SvPV_nolen(param), SvCUR(param)) : NULL)
/***********************************************************************************************************************************
Create const buffer from an SV
***********************************************************************************************************************************/
#define BUF_CONST_SV(param) \
(SvOK(param) ? BUF(SvPV_nolen(param), SvCUR(param)) : NULL)