11/*
2- * Copyright (c) 2004-2023 Tada AB and other contributors, as listed below.
2+ * Copyright (c) 2004-2025 Tada AB and other contributors, as listed below.
33 *
44 * All rights reserved. This program and the accompanying materials
55 * are made available under the terms of the The BSD 3-Clause License
@@ -82,7 +82,8 @@ void pljava_ExecutionPlan_initialize(void)
8282 "Ljava/lang/Object;J)V" );
8383}
8484
85- static bool coerceObjects (void * ePlan , jobjectArray jvalues , Datum * * valuesPtr , char * * nullsPtr )
85+ static bool coerceObjects (
86+ SPIPlanPtr ePlan , jobjectArray jvalues , Datum * * valuesPtr , char * * nullsPtr )
8687{
8788 char * nulls = 0 ;
8889 Datum * values = 0 ;
@@ -149,11 +150,10 @@ Java_org_postgresql_pljava_internal_ExecutionPlan__1cursorOpen(JNIEnv* env, jobj
149150 STACK_BASE_PUSH (env )
150151 PG_TRY ();
151152 {
152- Ptr2Long p2l ;
153+ SPIPlanPtr plan = JLongGet ( SPIPlanPtr , _this ) ;
153154 Datum * values = 0 ;
154155 char * nulls = 0 ;
155- p2l .longVal = _this ;
156- if (coerceObjects (p2l .ptrVal , jvalues , & values , & nulls ))
156+ if (coerceObjects (plan , jvalues , & values , & nulls ))
157157 {
158158 Portal portal ;
159159 char * name = 0 ;
@@ -167,7 +167,7 @@ Java_org_postgresql_pljava_internal_ExecutionPlan__1cursorOpen(JNIEnv* env, jobj
167167 else
168168 read_only = (SPI_READONLY_FORCED == readonly_spec );
169169 portal = SPI_cursor_open (
170- name , p2l . ptrVal , values , nulls , read_only );
170+ name , plan , values , nulls , read_only );
171171 if (name != 0 )
172172 pfree (name );
173173 if (values != 0 )
@@ -204,10 +204,8 @@ Java_org_postgresql_pljava_internal_ExecutionPlan__1isCursorPlan(JNIEnv* env, jc
204204 BEGIN_NATIVE
205205 PG_TRY ();
206206 {
207- Ptr2Long p2l ;
208- p2l .longVal = _this ;
209207 Invocation_assertConnect ();
210- result = (jboolean )SPI_is_cursor_plan (p2l . ptrVal );
208+ result = (jboolean )SPI_is_cursor_plan (JLongGet ( SPIPlanPtr , _this ) );
211209 }
212210 PG_CATCH ();
213211 {
@@ -235,11 +233,10 @@ Java_org_postgresql_pljava_internal_ExecutionPlan__1execute(JNIEnv* env, jclass
235233 STACK_BASE_PUSH (env )
236234 PG_TRY ();
237235 {
238- Ptr2Long p2l ;
236+ SPIPlanPtr plan = JLongGet ( SPIPlanPtr , _this ) ;
239237 Datum * values = 0 ;
240238 char * nulls = 0 ;
241- p2l .longVal = _this ;
242- if (coerceObjects (p2l .ptrVal , jvalues , & values , & nulls ))
239+ if (coerceObjects (plan , jvalues , & values , & nulls ))
243240 {
244241 bool read_only ;
245242 Invocation_assertConnect ();
@@ -248,7 +245,7 @@ Java_org_postgresql_pljava_internal_ExecutionPlan__1execute(JNIEnv* env, jclass
248245 else
249246 read_only = (SPI_READONLY_FORCED == readonly_spec );
250247 result = (jint )SPI_execute_plan (
251- p2l . ptrVal , values , nulls , read_only , (int )count );
248+ plan , values , nulls , read_only , (int )count );
252249 if (result < 0 )
253250 Exception_throwSPI ("execute_plan" , result );
254251
@@ -285,7 +282,7 @@ Java_org_postgresql_pljava_internal_ExecutionPlan__1prepare(JNIEnv* env, jclass
285282 PG_TRY ();
286283 {
287284 char * cmd ;
288- void * ePlan ;
285+ SPIPlanPtr ePlan ;
289286 int paramCount = 0 ;
290287 Oid * paramOids = 0 ;
291288
@@ -314,21 +311,16 @@ Java_org_postgresql_pljava_internal_ExecutionPlan__1prepare(JNIEnv* env, jclass
314311 Exception_throwSPI ("prepare" , SPI_result );
315312 else
316313 {
317- Ptr2Long p2l ;
318-
319314 /* Make the plan durable
320315 */
321- p2l .longVal = 0L ; /* ensure that the rest is zeroed out */
322316 spi_ret = SPI_keepplan (ePlan );
323- if ( 0 == spi_ret )
324- p2l .ptrVal = ePlan ;
325- else
317+ if ( 0 != spi_ret )
326318 Exception_throwSPI ("keepplan" , spi_ret );
327319
328320 result = JNI_newObjectLocked (
329321 s_ExecutionPlan_class , s_ExecutionPlan_init ,
330322 /* (jlong)0 as resource owner: the saved plan isn't transient */
331- pljava_DualState_key (), (jlong )0 , key , p2l . longVal );
323+ pljava_DualState_key (), (jlong )0 , key , PointerGetJLong ( ePlan ) );
332324 }
333325 }
334326 PG_CATCH ();
0 commit comments