Skip to content

Commit 0730e20

Browse files
author
Maxim Orlov
committed
Issue #27: Add fix for Travis Ci failed tests.
1 parent d90fd21 commit 0730e20

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

pg_variables.c

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ typedef struct tagHtabToStat {
152152
HASH_SEQ_STATUS *status;
153153
Variable *variable;
154154
Package *package;
155+
int level;
155156
} HtabToStat;
156157

157158
/*
@@ -181,6 +182,12 @@ HtabToStat_eq_all(HtabToStat *entry, void *value)
181182
return true;
182183
}
183184

185+
static bool
186+
HtabToStat_level_eq(HtabToStat *entry, void *value)
187+
{
188+
return entry->level == *(int *) value;
189+
}
190+
184191
/*
185192
* Generic remove_if algorithm for HtabToStat.
186193
*
@@ -192,6 +199,7 @@ HtabToStat_remove_if(List **l, void *value,
192199
bool (*eq)(HtabToStat *, void *),
193200
bool match_first)
194201
{
202+
#if (PG_VERSION_NUM < 130000)
195203
ListCell *cell, *next, *prev = NULL;
196204
HtabToStat *entry = NULL;
197205

@@ -214,6 +222,23 @@ HtabToStat_remove_if(List **l, void *value,
214222
prev = cell;
215223
}
216224
}
225+
#else
226+
/*
227+
* See https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=1cff1b95ab6ddae32faa3efe0d95a820dbfdc164
228+
*
229+
* Version > 13 have different lists interface.
230+
*/
231+
ListCell *cell;
232+
HtabToStat *entry = NULL;
233+
234+
foreach(cell, *l)
235+
{
236+
entry = (HtabToStat *) lfirst(cell);
237+
238+
if (eq(entry, value))
239+
*l = foreach_delete_current(*l, cell);
240+
}
241+
#endif
217242
}
218243

219244
/*
@@ -243,6 +268,15 @@ remove_variables_package(List **l, Package *package)
243268
HtabToStat_remove_if(l, package, HtabToStat_package_eq, false);
244269
}
245270

271+
/*
272+
* Remove all the entrys for level.
273+
*/
274+
static void
275+
remove_variables_level(List **l, int level)
276+
{
277+
HtabToStat_remove_if(l, &level, HtabToStat_level_eq, false);
278+
}
279+
246280
/*
247281
* Remove all.
248282
*/
@@ -757,6 +791,7 @@ variable_select(PG_FUNCTION_ARGS)
757791
htab_to_stat->status = rstat;
758792
htab_to_stat->variable = variable;
759793
htab_to_stat->package = package;
794+
htab_to_stat->level = GetCurrentTransactionNestLevel();
760795
variables_stats = lcons((void *)htab_to_stat, variables_stats);
761796

762797
MemoryContextSwitchTo(oldcontext);
@@ -1356,7 +1391,6 @@ get_packages_stats(PG_FUNCTION_ARGS)
13561391
{
13571392
TupleDesc tupdesc;
13581393

1359-
//elog(INFO, " >>> ");
13601394
funcctx = SRF_FIRSTCALL_INIT();
13611395
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
13621396

@@ -1432,7 +1466,7 @@ get_packages_stats(PG_FUNCTION_ARGS)
14321466
else
14331467
{
14341468
packages_stats = list_delete(packages_stats, rstat);
1435-
// pfree(rstat);
1469+
pfree(rstat);
14361470
SRF_RETURN_DONE(funcctx);
14371471
}
14381472
}
@@ -2312,6 +2346,8 @@ pgvSubTransCallback(SubXactEvent event, SubTransactionId mySubid,
23122346
break;
23132347
}
23142348
}
2349+
2350+
remove_variables_level(&variables_stats, GetCurrentTransactionNestLevel());
23152351
}
23162352

23172353
/*

0 commit comments

Comments
 (0)