xref: /petsc/src/dm/impls/forest/p4est/petsc_p4est_package.h (revision 94ef8dde638caef1d0cd84a7dc8a2db65fcda8b6)
1 #if !defined(__PETSC_P4EST_PACKAGE_H)
2 #define      __PETSC_P4EST_PACKAGE_H
3 #include <petscsys.h>
4 #include <p4est_base.h>
5 
6 #if defined(PETSC_HAVE_SETJMP_H) && defined(PETSC_USE_ERRORCHECKING)
7 #include <setjmp.h>
8 PETSC_INTERN jmp_buf PetscScJumpBuf;
9 
10 #define PetscStackCallP4est(func,args) do {                                                                                                           \
11   if (setjmp(PetscScJumpBuf)) {                                                                                                                       \
12     return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,PETSC_ERR_LIB,PETSC_ERROR_REPEAT,"Error in p4est/libsc call %s()",#func); \
13   }                                                                                                                                                   \
14   else {                                                                                                                                              \
15     PetscStackPush(#func);                                                                                                                            \
16     func args;                                                                                                                                        \
17     PetscStackPop;                                                                                                                                    \
18   }                                                                                                                                                   \
19 } while (0)
20 #define PetscStackCallP4estReturn(ret,func,args) do {                                                                                                 \
21   if (setjmp(PetscScJumpBuf)) {                                                                                                                       \
22     return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,PETSC_ERR_LIB,PETSC_ERROR_REPEAT,"Error in p4est/libsc call %s()",#func); \
23   }                                                                                                                                                   \
24   else {                                                                                                                                              \
25     PetscStackPush(#func);                                                                                                                            \
26     ret = func args;                                                                                                                                  \
27     PetscStackPop;                                                                                                                                    \
28   }                                                                                                                                                   \
29 } while (0)
30 #else
31 #define PetscStackCallP4est(func,args) do { \
32   PetscStackPush(#func);                    \
33   func args;                                \
34   PetscStackPop;                            \
35 } while (0)
36 #define PetscStackCallP4estReturn(ret,func,args) do { \
37   PetscStackPush(#func);                              \
38   ret = func args;                                    \
39   PetscStackPop;                                      \
40 } while (0)
41 #endif
42 
43 #if defined(P4EST_ENABLE_DEBUG)
44 #define PETSC_P4EST_ASSERT(x) P4EST_ASSERT(x)
45 #else
46 #define PETSC_P4EST_ASSERT(x) (void)(x)
47 #endif
48 
49 PETSC_EXTERN PetscErrorCode PetscP4estInitialize();
50 
51 PETSC_STATIC_INLINE PetscErrorCode P4estLocidxCast(PetscInt a,p4est_locidx_t *b)
52 {
53   PetscFunctionBegin;
54   *b =  (p4est_locidx_t)(a);
55 #if defined(PETSC_USE_64BIT_INDICES)
56   if ((a) > P4EST_LOCIDX_MAX) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Index to large for p4est_locidx_t");
57 #endif
58   PetscFunctionReturn(0);
59 }
60 
61 PETSC_STATIC_INLINE PetscErrorCode P4estTopidxCast(PetscInt a,p4est_topidx_t *b)
62 {
63   PetscFunctionBegin;
64   *b =  (p4est_topidx_t)(a);
65 #if defined(PETSC_USE_64BIT_INDICES)
66   if ((a) > P4EST_TOPIDX_MAX) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Index to large for p4est_topidx_t");
67 #endif
68   PetscFunctionReturn(0);
69 }
70 
71 #endif
72