Skip to content

Commit

Permalink
- add DLLIMPORT to Dynamic_library_path declaration for Win32
Browse files Browse the repository at this point in the history
- add pkglib_path[] declaration for Win32
- modify debug code for PROTECT/UNPROTECT
- add missing UNPROTECT(1) in spi code -- fix for "stack imbalance" warning
  • Loading branch information
jconway committed Jun 12, 2007
1 parent 07f8448 commit 974dc94
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
4 changes: 3 additions & 1 deletion pg_backend_support.c
Expand Up @@ -37,7 +37,9 @@
#include "utils/memutils.h" #include "utils/memutils.h"


/* GUC variable */ /* GUC variable */
extern char *Dynamic_library_path; extern DLLIMPORT char *Dynamic_library_path;
/* Postgres global */
extern DLLIMPORT char pkglib_path[];


/* compiled function hash table */ /* compiled function hash table */
extern HTAB *plr_HashTable; extern HTAB *plr_HashTable;
Expand Down
6 changes: 4 additions & 2 deletions pg_rsupport.c
Expand Up @@ -142,6 +142,7 @@ plr_SPI_exec(SEXP rsql)


PROTECT(rsql = AS_CHARACTER(rsql)); PROTECT(rsql = AS_CHARACTER(rsql));
sql = CHAR(STRING_ELT(rsql, 0)); sql = CHAR(STRING_ELT(rsql, 0));
UNPROTECT(1);
if (sql == NULL) if (sql == NULL)
error("%s", "cannot exec empty query"); error("%s", "cannot exec empty query");


Expand Down Expand Up @@ -285,6 +286,7 @@ plr_SPI_prepare(SEXP rsql, SEXP rargtypes)


PROTECT(rsql = AS_CHARACTER(rsql)); PROTECT(rsql = AS_CHARACTER(rsql));
sql = CHAR(STRING_ELT(rsql, 0)); sql = CHAR(STRING_ELT(rsql, 0));
UNPROTECT(1);
if (sql == NULL) if (sql == NULL)
error("%s", "cannot prepare empty query"); error("%s", "cannot prepare empty query");


Expand Down Expand Up @@ -341,6 +343,8 @@ plr_SPI_prepare(SEXP rsql, SEXP rargtypes)
else else
typeids = NULL; typeids = NULL;


UNPROTECT(1);

/* switch to SPI memory context */ /* switch to SPI memory context */
oldcontext = MemoryContextSwitchTo(plr_SPI_context); oldcontext = MemoryContextSwitchTo(plr_SPI_context);


Expand All @@ -355,8 +359,6 @@ plr_SPI_prepare(SEXP rsql, SEXP rargtypes)
} }
PLR_PG_CATCH(); PLR_PG_CATCH();
PLR_PG_END_TRY(); PLR_PG_END_TRY();

UNPROTECT(2);


if (pplan == NULL) if (pplan == NULL)
{ {
Expand Down
16 changes: 16 additions & 0 deletions plr.c
Expand Up @@ -1524,3 +1524,19 @@ getModulesSql(Oid nspOid)


return sql->data; return sql->data;
} }

#ifdef DEBUGPROTECT
SEXP
pg_protect(SEXP s, char *fn, int ln)
{
elog(NOTICE, "\tPROTECT\t1\t%s\t%d", fn, ln);
return protect(s);
}

void
pg_unprotect(int n, char *fn, int ln)
{
elog(NOTICE, "\tUNPROTECT\t%d\t%s\t%d", n, fn, ln);
unprotect(n);
}
#endif /* DEBUGPROTECT */
15 changes: 5 additions & 10 deletions plr.h
Expand Up @@ -91,17 +91,12 @@


#ifdef DEBUGPROTECT #ifdef DEBUGPROTECT
#undef PROTECT #undef PROTECT
#define PROTECT(s) \ extern SEXP pg_protect(SEXP s, char *fn, int ln);
do { \ #define PROTECT(s) pg_protect(s, __FILE__, __LINE__)
elog(NOTICE, "\tPROTECT\t1\t%s\t%d", __FILE__, __LINE__); \
protect(s); \
} while (0)
#undef UNPROTECT #undef UNPROTECT
#define UNPROTECT(n) \ extern void pg_unprotect(int n, char *fn, int ln);
do { \ #define UNPROTECT(n) pg_unprotect(n, __FILE__, __LINE__)
elog(NOTICE, "\tUNPROTECT\t%d\t%s\t%d", n, __FILE__, __LINE__); \
unprotect(n); \
} while (0)
#endif /* DEBUGPROTECT */ #endif /* DEBUGPROTECT */


#define xpfree(var_) \ #define xpfree(var_) \
Expand Down

0 comments on commit 974dc94

Please sign in to comment.