Skip to content

Commit

Permalink
libgap-api: clang-format, adjust some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed May 7, 2019
1 parent 4f6b7da commit 4a3108e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/libgap-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,7 @@ void GAP_LeaveStack_(void)

void GAP_EnterDebugMessage_(char * message, char * file, int line)
{
fprintf(stderr, "%s: %d; %s:%d\n", message, EnterStackCount, file,
line);
fprintf(stderr, "%s: %d; %s:%d\n", message, EnterStackCount, file, line);
}

int GAP_Error_Prejmp_(const char * file, int line)
Expand All @@ -437,7 +436,8 @@ int GAP_Error_Prejmp_(const char * file, int line)
}

/* Helper function for GAP_Error_Postjmp_ (see libgap-api.h) which manipulates
* EnterStackCount in the (generally unlikely) case of returning from a longjmp
* EnterStackCount in the (generally unlikely) case of returning from a
* longjmp
*/
void GAP_Error_Postjmp_Returning_(void)
{
Expand Down
53 changes: 28 additions & 25 deletions src/libgap-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extern syJmp_buf * GAP_GetReadJmpError(void);
extern void GAP_EnterDebugMessage_(char * message, char * file, int line);
extern void GAP_EnterStack_(void *);
extern void GAP_LeaveStack_(void);
extern int GAP_Error_Prejmp_(const char *, int);
extern int GAP_Error_Prejmp_(const char *, int);
extern void GAP_Error_Postjmp_Returning_(void);


Expand Down Expand Up @@ -63,14 +63,15 @@ static inline int GAP_Error_Postjmp_(int JumpRet)
// collector; otherwise GAP objects may be garbage collected while still in
// use.
//
// In general user code should use the more general GAP_Enter()/Leave() macros
// defined below, as these also specify a terminal point for unhandled GAP
// errors to bubble up to. However, GAP_EnterStack() and GAP_LeaveStack()
// should still be used in the defintion of a custom error handling callback as
// passed to GAP_Initialize(). Using the more general GAP_Enter() in this case
// will result in crashes if the error handler is entered recursively (you
// don't want the GAP error handling code to cause a longjmp into the error
// callback itself since then the error callback will never be returned from).
// In general user code should use the more general GAP_Enter()/Leave()
// macros defined below, as these also specify a terminal point for unhandled
// GAP errors to bubble up to. However, GAP_EnterStack() and
// GAP_LeaveStack() should still be used in the definition of a custom error
// handling callback as passed to GAP_Initialize(). Using the more general
// GAP_Enter() in this case will result in crashes if the error handler is
// entered recursively (you don't want the GAP error handling code to cause a
// longjmp into the error callback itself since then the error callback will
// never be returned from).
#ifdef __GNUC__
#define GAP_EnterStack() \
do { \
Expand All @@ -92,30 +93,30 @@ static inline int GAP_Error_Postjmp_(int JumpRet)
} while (0)
#endif

#define GAP_LeaveStack() \
GAP_LeaveStack_();
#define GAP_LeaveStack() GAP_LeaveStack_();


#define GAP_Error_Setjmp() \
(GAP_unlikely(GAP_Error_Prejmp_(__FILE__, __LINE__)) || \
GAP_Error_Postjmp_(sySetjmp(*GAP_GetReadJmpError())))


// Code which uses the GAP API exposed by this header file should sandwich any
// such calls between uses of the GAP_Enter() and GAP_Leave() macro as follows:
//
// Code which uses the GAP API exposed by this header file should sandwich
// any such calls between uses of the GAP_Enter() and GAP_Leave() macro as
// follows:
//
// int ok = GAP_Enter();
// if (ok) {
// ... // any number of calls to GAP APIs
// }
// GAP_Leave();
//
//
// This is in particular crucial if your code keeps references to any GAP
// functions in local variables: Calling GAP_Enter() ensures that GAP is aware
// of such references, and will not garbage collect the referenced objects.
// Failing to use these macros properly can lead to crashes, or worse, silent
// memory corruption. You have been warned!
//
// functions in local variables: Calling GAP_Enter() ensures that GAP is
// aware of such references, and will not garbage collect the referenced
// objects. Failing to use these macros properly can lead to crashes, or
// worse, silent memory corruption. You have been warned!
//
// Note that due to the implementation of these macros, you unfortunately
// cannot "simplify" the above example code to:
//
Expand All @@ -129,14 +130,14 @@ static inline int GAP_Error_Postjmp_(int JumpRet)
// is the return value of GAP_Error_Setjmp).
//
// * GAP_EnterStack() defined and explained above must be a macro since it
// needs to figure out (to the extent possible) the base address of the stack
// frame from which it is called.
// needs to figure out (to the extent possible) the base address of the
// stack frame from which it is called.
//
// * GAP_Error_Setjmp() effectively calls setjmp to the STATE(ReadJmpError)
// longjmp buffer, so that read errors which occur in GAP that are not
// otherwise "handled" by a TRY_IF_NO_ERROR { } block have a logical place
// to return to. It returns 1 if no error occurred, and 0 if returning from
// an error.
// to return to. It returns 1 if no error occurred, and 0 if returning
// from an error.
#define GAP_Enter() \
GAP_Error_Setjmp(); \
GAP_EnterStack()
Expand Down Expand Up @@ -327,8 +328,9 @@ Obj GAP_ElmList(Obj list, UInt pos);
// Returns a new empty plain list with capacity <capacity>
Obj GAP_NewPlist(Int capacity);


////
//// Records
//// records
////

// Returns 1 if <obj> is a GAP record, 0 if not.
Expand All @@ -347,6 +349,7 @@ Obj GAP_ElmRecord(Obj rec, Obj name);
// Returns a new empty plain record with capacity <capacity>.
Obj GAP_NewPrecord(Int capacity);


////
//// strings
////
Expand Down

0 comments on commit 4a3108e

Please sign in to comment.