Skip to content

Commit

Permalink
Remove dead LibC macros.
Browse files Browse the repository at this point in the history
These macros were made obsolete when code was removed from LibC after the C migration was completed.
  • Loading branch information
dwsteele committed Feb 21, 2020
1 parent dfc5f67 commit 48d0f77
Showing 1 changed file with 9 additions and 123 deletions.
132 changes: 9 additions & 123 deletions libc/LibC.h
Expand Up @@ -8,44 +8,6 @@ Package Names
#define PACKAGE_NAME "pgBackRest"
#define PACKAGE_NAME_LIBC PACKAGE_NAME "::LibC"

/***********************************************************************************************************************************
Load C error into ERROR_SV_error
#define FUNCTION_NAME_ERROR "libcExceptionNew"
#define ERROR_SV() \
SV *ERROR_SV_error; \
\
{ \
// Push parameters onto the Perl stack \
ENTER; \
SAVETMPS; \
PUSHMARK(SP); \
EXTEND(SP, 2); \
PUSHs(sv_2mortal(newSViv(errorCode()))); \
PUSHs(sv_2mortal(newSVpv(errorMessage(), 0))); \
PUTBACK; \
\
// Call error function \
int count = call_pv(PACKAGE_NAME_LIBC "::" FUNCTION_NAME_ERROR, G_SCALAR); \
SPAGAIN; \
\
// Check that correct number of parameters was returned \
if (count != 1) \
croak("expected 1 return value from " FUNCTION_NAME_ERROR "()"); \
\
// Make a copy of the error that can be returned \
ERROR_SV_error = newSVsv(POPs); \
\
// Clean up the stack \
PUTBACK; \
FREETMPS; \
LEAVE; \
}
This turned out to be a dead end because Perl 5.10 does not support croak_sv(), but this code has been kept for example purposes.
***********************************************************************************************************************************/

/***********************************************************************************************************************************
Error handling macros that throw a Perl error when a C error is caught
***********************************************************************************************************************************/
Expand All @@ -62,84 +24,6 @@ Error handling macros that throw a Perl error when a C error is caught
} \
TRY_END();

/***********************************************************************************************************************************
Core context handling macros, only intended to be called from other macros
***********************************************************************************************************************************/
#define MEM_CONTEXT_XS_CORE_BEGIN(memContext) \
/* Switch to the new memory context */ \
MemContext *MEM_CONTEXT_memContextPrior = memContextSwitch(memContext); \
\
/* 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_CORE_END() \
/* Set error to be croak to Perl later */ \
CATCH_ANY() \
{ \
MEM_CONTEXT_XS_croak = true; \
} \
/* Free the context on error */ \
FINALLY() \
{ \
memContextSwitch(memContextPrior()); \
} \
TRY_END();

/***********************************************************************************************************************************
Simplifies creation of the memory context in constructors and includes error handling
***********************************************************************************************************************************/
#define MEM_CONTEXT_XS_NEW_BEGIN(contextName) \
{ \
/* Attempt to create the memory context */ \
MemContext *MEM_CONTEXT_XS_memContext = NULL; \
\
TRY_BEGIN() \
{ \
MEM_CONTEXT_XS_memContext = memContextNew(contextName); \
} \
CATCH_ANY() \
{ \
ERROR_XS() \
} \
TRY_END(); \
\
MEM_CONTEXT_XS_CORE_BEGIN(MEM_CONTEXT_XS_memContext)

#define MEM_CONTEXT_XS_NEW_END() \
MEM_CONTEXT_XS_CORE_END(); \
\
/* Free context and croak on error */ \
if (MEM_CONTEXT_XS_croak) \
{ \
memContextFree(MEM_CONTEXT_XS_memContext); \
\
ERROR_XS() \
} \
}

#define MEM_CONTEXT_XS() \
MEM_CONTEXT_XS_memContext

/***********************************************************************************************************************************
Simplifies switching the memory context in functions and includes error handling
***********************************************************************************************************************************/
#define MEM_CONTEXT_XS_BEGIN(memContext) \
{ \
MEM_CONTEXT_XS_CORE_BEGIN(memContext)

#define MEM_CONTEXT_XS_END() \
MEM_CONTEXT_XS_CORE_END(); \
\
/* Croak on error */ \
if (MEM_CONTEXT_XS_croak) \
{ \
ERROR_XS() \
} \
}

/***********************************************************************************************************************************
Simplifies switching to a temp memory context in functions and includes error handling
***********************************************************************************************************************************/
Expand All @@ -148,9 +32,17 @@ Simplifies switching to a temp memory context in functions and includes error ha

#define MEM_CONTEXT_XS_TEMP_BEGIN() \
{ \
/* Create temp memory context */ \
MemContext *MEM_CONTEXT_XS_TEMP() = memContextNew("temporary"); \
\
MEM_CONTEXT_XS_CORE_BEGIN(MEM_CONTEXT_XS_TEMP())
/* 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 */ \
Expand All @@ -173,12 +65,6 @@ Simplifies switching to a temp memory context in functions and includes error ha
} \
}

/***********************************************************************************************************************************
Free memory context in destructors
***********************************************************************************************************************************/
#define MEM_CONTEXT_XS_DESTROY(memContext) \
memContextFree(memContext)

/***********************************************************************************************************************************
Create new string from an SV
***********************************************************************************************************************************/
Expand Down

0 comments on commit 48d0f77

Please sign in to comment.