forked from tada/pljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpljava.h
More file actions
138 lines (117 loc) · 3.62 KB
/
Copy pathpljava.h
File metadata and controls
138 lines (117 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* Copyright (c) 2004, 2005, 2006 TADA AB - Taby Sweden
* Distributed under the terms shown in the file COPYRIGHT
* found in the root folder of this project or at
* http://eng.tada.se/osprojects/COPYRIGHT.html
*
* @author Thomas Hallgren
*/
#ifndef __pljava_pljava_h
#define __pljava_pljava_h
#include <jni.h>
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************
* Misc stuff to tie Java to PostgreSQL. TRY/CATCH macros, thread
* blocking, etc. resides here.
*
* @author Thomas Hallgren
*****************************************************************/
#ifdef __STRICT_ANSI__
extern int vsnprintf(char* buf, size_t count, const char* format, va_list arg);
#endif
#include <postgres.h>
#include <lib/stringinfo.h>
#include <fmgr.h>
#include <mb/pg_wchar.h>
#include <utils/syscache.h>
#include <utils/memutils.h>
#include <tcop/tcopprot.h>
/*
* GETSTRUCT require "access/htup_details.h" to be included in PG9.3
*/
#if (PGSQL_MAJOR_VER > 9 || (PGSQL_MAJOR_VER == 9 && PGSQL_MINOR_VER >= 3))
#include "access/htup_details.h"
#endif
/* The errorOccured will be set when a call from Java into one of the
* backend functions results in a elog that causes a longjmp (Levels >= ERROR)
* that was trapped using the PLJAVA_TRY/PLJAVA_CATCH macros.
* When this happens, all further calls from Java must be blocked since the
* state of the current transaction is unknown. Further more, once the function
* that initially called Java finally returns, the intended longjmp (the one
* to the original value of Warn_restart) must be made.
*/
extern jlong mainThreadId;
extern bool pljavaEntryFence(JNIEnv* env);
extern JNIEnv* currentJNIEnv;
extern MemoryContext JavaMemoryContext;
#if (PGSQL_MAJOR_VER == 8 && PGSQL_MINOR_VER == 0)
#define STACK_BASE_VARS
#define STACK_BASE_PUSH(threadId)
#define STACK_BASE_POP()
#else
#if (PGSQL_MAJOR_VER > 8 || (PGSQL_MAJOR_VER == 8 && PGSQL_MINOR_VER >= 3))
extern PGDLLIMPORT char* stack_base_ptr;
#else
extern DLLIMPORT char* stack_base_ptr;
#endif
#define STACK_BASE_VARS \
long saveMainThreadId = 0; \
char* saveStackBasePtr = 0;
#define STACK_BASE_PUSH(threadId) \
if(threadId != mainThreadId) \
{ \
saveStackBasePtr = stack_base_ptr; \
saveMainThreadId = mainThreadId; \
stack_base_ptr = (char*)&saveMainThreadId; \
mainThreadId = threadId; \
elog(DEBUG1, "Changed stack_base_ptr from %p to %p", saveStackBasePtr, stack_base_ptr); \
}
#define STACK_BASE_POP() \
if(saveStackBasePtr != 0) \
{ \
stack_base_ptr = saveStackBasePtr; \
mainThreadId = saveMainThreadId; \
elog(DEBUG1, "Restored stack_base_ptr to %p", saveStackBasePtr); \
}
#endif
/* NOTE!
* When using the PG_TRY, PG_CATCH, PG_TRY_END family of macros,
* it is an ABSOLUTE NECESSITY to use the PG_TRY_RETURN or
* PG_TRY_RETURN_VOID in place of any return.
*/
#define PG_TRY_POP \
PG_exception_stack = save_exception_stack; \
error_context_stack = save_context_stack
#define PG_TRY_RETURN(retVal) { PG_TRY_POP; return retVal; }
#define PG_TRY_RETURN_VOID { PG_TRY_POP; return; }
/* Some error codes missing from errcodes.h
*
* Class 07 - Dynamic SQL Exception
*/
#define ERRCODE_INVALID_DESCRIPTOR_INDEX MAKE_SQLSTATE('0','7', '0','0','9')
/*
* Union used when coercing void* to jlong and vice versa
*/
typedef union
{
void* ptrVal;
jlong longVal; /* 64 bit quantity */
struct
{
/* Used when calculating pointer hash in systems where
* a pointer is 64 bit
*/
uint32 intVal_1;
uint32 intVal_2;
} x64;
} Ptr2Long;
struct Invocation_;
typedef struct Invocation_ Invocation;
struct Function_;
typedef struct Function_* Function;
#ifdef __cplusplus
}
#endif
#endif