On Mon, Jun 07, 2021 at 10:38:03AM -0400, Tom Lane wrote: > Hmm. We do include "-lpgcommon -lpgport" when building the ecpg test > programs on Unix, so I'd assumed that the MSVC scripts did the same. > Is there a good reason not to make them do so?
I was looking at that this morning, and yes we need to add more references here. Actually, adding only libpgport.lib allows the compilation and the tests to work, but I agree to add also libpgcommon.lib so as we don't fall into the same compilation trap again in the future. Now, I also see that using pgwin32_setenv() instead of src/port/setenv.c causes cl to be confused once we update ecpg_regression.proj because it cannot find setenv(). Bringing the question, why is it necessary to have both setenv.c and pgwin32_setenv() on HEAD? setenv.c should be enough once you have the fallback implementation of putenv() available. Attached is the patch I am finishing with, that also brings all this stuff closer to what I did in 12 and 13 for hamerkop. The failing test is passing for me now with MSVC and GSSAPI builds. Thoughts? -- Michael
diff --git a/src/include/port/win32_port.h b/src/include/port/win32_port.h
index 05c5a53442..e25f65b054 100644
--- a/src/include/port/win32_port.h
+++ b/src/include/port/win32_port.h
@@ -490,11 +490,9 @@ extern void _dosmaperr(unsigned long);
/* in port/win32env.c */
extern int pgwin32_putenv(const char *);
-extern int pgwin32_setenv(const char *name, const char *value, int overwrite);
extern int pgwin32_unsetenv(const char *name);
#define putenv(x) pgwin32_putenv(x)
-#define setenv(x,y,z) pgwin32_setenv(x,y,z)
#define unsetenv(x) pgwin32_unsetenv(x)
/* in port/win32security.c */
diff --git a/src/port/win32env.c b/src/port/win32env.c
index a03556078c..c8d43af381 100644
--- a/src/port/win32env.c
+++ b/src/port/win32env.c
@@ -1,7 +1,7 @@
/*-------------------------------------------------------------------------
*
* win32env.c
- * putenv(), setenv(), and unsetenv() for win32.
+ * putenv() and unsetenv() for win32.
*
* These functions update both the process environment and caches in
* (potentially multiple) C run-time library (CRT) versions.
@@ -117,35 +117,6 @@ pgwin32_putenv(const char *envval)
return _putenv(envval);
}
-int
-pgwin32_setenv(const char *name, const char *value, int overwrite)
-{
- int res;
- char *envstr;
-
- /* Error conditions, per POSIX */
- if (name == NULL || name[0] == '\0' || strchr(name, '=') != NULL ||
- value == NULL)
- {
- errno = EINVAL;
- return -1;
- }
-
- /* No work if variable exists and we're not to replace it */
- if (overwrite == 0 && getenv(name) != NULL)
- return 0;
-
- envstr = (char *) malloc(strlen(name) + strlen(value) + 2);
- if (!envstr) /* not much we can do if no memory */
- return -1;
-
- sprintf(envstr, "%s=%s", name, value);
-
- res = pgwin32_putenv(envstr);
- free(envstr);
- return res;
-}
-
int
pgwin32_unsetenv(const char *name)
{
diff --git a/src/interfaces/ecpg/test/connect/test5.pgc b/src/interfaces/ecpg/test/connect/test5.pgc
index e712fa8778..f7263935ce 100644
--- a/src/interfaces/ecpg/test/connect/test5.pgc
+++ b/src/interfaces/ecpg/test/connect/test5.pgc
@@ -18,6 +18,9 @@ exec sql begin declare section;
char *user="regress_ecpg_user1";
exec sql end declare section;
+ /* disable GSSENC to ensure stability of connection failure reports */
+ setenv("PGGSSENCMODE", "disable", 1);
+
ECPGdebug(1, stderr);
exec sql connect to ecpg2_regression as main;
diff --git a/src/interfaces/ecpg/test/expected/connect-test5.c b/src/interfaces/ecpg/test/expected/connect-test5.c
index 6ae5b589de..a86a5e4331 100644
--- a/src/interfaces/ecpg/test/expected/connect-test5.c
+++ b/src/interfaces/ecpg/test/expected/connect-test5.c
@@ -38,37 +38,33 @@ main(void)
#line 19 "test5.pgc"
+ /* disable GSSENC to ensure stability of connection failure reports */
+ setenv("PGGSSENCMODE", "disable", 1);
+
ECPGdebug(1, stderr);
{ ECPGconnect(__LINE__, 0, "ecpg2_regression" , NULL, NULL , "main", 0); }
-#line 23 "test5.pgc"
-
- { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "alter user regress_ecpg_user2 encrypted password 'insecure'", ECPGt_EOIT, ECPGt_EORT);}
-#line 24 "test5.pgc"
-
- { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "alter user regress_ecpg_user1 encrypted password 'connectpw'", ECPGt_EOIT, ECPGt_EORT);}
-#line 25 "test5.pgc"
-
- { ECPGtrans(__LINE__, NULL, "commit");}
#line 26 "test5.pgc"
- { ECPGdisconnect(__LINE__, "CURRENT");}
+ { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "alter user regress_ecpg_user2 encrypted password 'insecure'", ECPGt_EOIT, ECPGt_EORT);}
#line 27 "test5.pgc"
+
+ { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "alter user regress_ecpg_user1 encrypted password 'connectpw'", ECPGt_EOIT, ECPGt_EORT);}
+#line 28 "test5.pgc"
+
+ { ECPGtrans(__LINE__, NULL, "commit");}
+#line 29 "test5.pgc"
+
+ { ECPGdisconnect(__LINE__, "CURRENT");}
+#line 30 "test5.pgc"
/* <-- "main" not specified */
strcpy(db, "ecpg2_regression");
strcpy(id, "main");
{ ECPGconnect(__LINE__, 0, db , NULL, NULL , id, 0); }
-#line 31 "test5.pgc"
-
- { ECPGdisconnect(__LINE__, id);}
-#line 32 "test5.pgc"
-
-
- { ECPGconnect(__LINE__, 0, "ecpg2_regression" , NULL, NULL , "main", 0); }
#line 34 "test5.pgc"
- { ECPGdisconnect(__LINE__, "main");}
+ { ECPGdisconnect(__LINE__, id);}
#line 35 "test5.pgc"
@@ -86,21 +82,21 @@ main(void)
#line 41 "test5.pgc"
- { ECPGconnect(__LINE__, 0, "" , "regress_ecpg_user2" , "insecure" , "main", 0); }
+ { ECPGconnect(__LINE__, 0, "ecpg2_regression" , NULL, NULL , "main", 0); }
#line 43 "test5.pgc"
{ ECPGdisconnect(__LINE__, "main");}
#line 44 "test5.pgc"
- { ECPGconnect(__LINE__, 0, "ecpg2_regression" , "regress_ecpg_user1" , "connectpw" , "main", 0); }
+ { ECPGconnect(__LINE__, 0, "" , "regress_ecpg_user2" , "insecure" , "main", 0); }
#line 46 "test5.pgc"
{ ECPGdisconnect(__LINE__, "main");}
#line 47 "test5.pgc"
- { ECPGconnect(__LINE__, 0, "unix:postgresql://localhost/ecpg2_regression" , "regress_ecpg_user1" , "connectpw" , "main", 0); }
+ { ECPGconnect(__LINE__, 0, "ecpg2_regression" , "regress_ecpg_user1" , "connectpw" , "main", 0); }
#line 49 "test5.pgc"
{ ECPGdisconnect(__LINE__, "main");}
@@ -114,48 +110,55 @@ main(void)
#line 53 "test5.pgc"
- { ECPGconnect(__LINE__, 0, "unix:postgresql://localhost/ecpg2_regression" , user , "connectpw" , "main", 0); }
+ { ECPGconnect(__LINE__, 0, "unix:postgresql://localhost/ecpg2_regression" , "regress_ecpg_user1" , "connectpw" , "main", 0); }
#line 55 "test5.pgc"
{ ECPGdisconnect(__LINE__, "main");}
#line 56 "test5.pgc"
- { ECPGconnect(__LINE__, 0, "unix:postgresql://localhost/ecpg2_regression?connect_timeout=180 & client_encoding=latin1" , "regress_ecpg_user1" , "connectpw" , "main", 0); }
+ { ECPGconnect(__LINE__, 0, "unix:postgresql://localhost/ecpg2_regression" , user , "connectpw" , "main", 0); }
#line 58 "test5.pgc"
{ ECPGdisconnect(__LINE__, "main");}
#line 59 "test5.pgc"
- { ECPGconnect(__LINE__, 0, "unix:postgresql://200.46.204.71/ecpg2_regression" , "regress_ecpg_user1" , "connectpw" , "main", 0); }
+ { ECPGconnect(__LINE__, 0, "unix:postgresql://localhost/ecpg2_regression?connect_timeout=180 & client_encoding=latin1" , "regress_ecpg_user1" , "connectpw" , "main", 0); }
#line 61 "test5.pgc"
{ ECPGdisconnect(__LINE__, "main");}
#line 62 "test5.pgc"
- { ECPGconnect(__LINE__, 0, "unix:postgresql://localhost/" , "regress_ecpg_user2" , "insecure" , "main", 0); }
+ { ECPGconnect(__LINE__, 0, "unix:postgresql://200.46.204.71/ecpg2_regression" , "regress_ecpg_user1" , "connectpw" , "main", 0); }
#line 64 "test5.pgc"
{ ECPGdisconnect(__LINE__, "main");}
#line 65 "test5.pgc"
- /* connect twice */
- { ECPGconnect(__LINE__, 0, "ecpg2_regression" , NULL, NULL , "main", 0); }
-#line 68 "test5.pgc"
-
- { ECPGconnect(__LINE__, 0, "ecpg2_regression" , NULL, NULL , "main", 0); }
-#line 69 "test5.pgc"
+ { ECPGconnect(__LINE__, 0, "unix:postgresql://localhost/" , "regress_ecpg_user2" , "insecure" , "main", 0); }
+#line 67 "test5.pgc"
{ ECPGdisconnect(__LINE__, "main");}
-#line 70 "test5.pgc"
+#line 68 "test5.pgc"
+
+
+ /* connect twice */
+ { ECPGconnect(__LINE__, 0, "ecpg2_regression" , NULL, NULL , "main", 0); }
+#line 71 "test5.pgc"
+
+ { ECPGconnect(__LINE__, 0, "ecpg2_regression" , NULL, NULL , "main", 0); }
+#line 72 "test5.pgc"
+
+ { ECPGdisconnect(__LINE__, "main");}
+#line 73 "test5.pgc"
/* not connected */
{ ECPGdisconnect(__LINE__, "nonexistent");}
-#line 73 "test5.pgc"
+#line 76 "test5.pgc"
return 0;
diff --git a/src/interfaces/ecpg/test/expected/connect-test5.stderr b/src/interfaces/ecpg/test/expected/connect-test5.stderr
index a15f344320..abab1ba5a2 100644
--- a/src/interfaces/ecpg/test/expected/connect-test5.stderr
+++ b/src/interfaces/ecpg/test/expected/connect-test5.stderr
@@ -2,19 +2,19 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGconnect: opening database ecpg2_regression on <DEFAULT> port <DEFAULT>
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 24: query: alter user regress_ecpg_user2 encrypted password 'insecure'; with 0 parameter(s) on connection main
+[NO_PID]: ecpg_execute on line 27: query: alter user regress_ecpg_user2 encrypted password 'insecure'; with 0 parameter(s) on connection main
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 24: using PQexec
+[NO_PID]: ecpg_execute on line 27: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 24: OK: ALTER ROLE
+[NO_PID]: ecpg_process_output on line 27: OK: ALTER ROLE
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 25: query: alter user regress_ecpg_user1 encrypted password 'connectpw'; with 0 parameter(s) on connection main
+[NO_PID]: ecpg_execute on line 28: query: alter user regress_ecpg_user1 encrypted password 'connectpw'; with 0 parameter(s) on connection main
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 25: using PQexec
+[NO_PID]: ecpg_execute on line 28: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_process_output on line 25: OK: ALTER ROLE
+[NO_PID]: ecpg_process_output on line 28: OK: ALTER ROLE
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGtrans on line 26: action "commit"; connection "main"
+[NO_PID]: ECPGtrans on line 29: action "commit"; connection "main"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: connection main closed
[NO_PID]: sqlca: code: 0, state: 00000
@@ -40,9 +40,9 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: connection main closed
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlcode -402 on line 43: could not connect to database "<DEFAULT>" on line 43
+[NO_PID]: raising sqlcode -402 on line 46: could not connect to database "<DEFAULT>" on line 46
[NO_PID]: sqlca: code: -402, state: 08001
-[NO_PID]: raising sqlcode -220 on line 44: connection "main" does not exist on line 44
+[NO_PID]: raising sqlcode -220 on line 47: connection "main" does not exist on line 47
[NO_PID]: sqlca: code: -220, state: 08003
[NO_PID]: ECPGconnect: opening database ecpg2_regression on <DEFAULT> port <DEFAULT> for user regress_ecpg_user1
[NO_PID]: sqlca: code: 0, state: 00000
@@ -64,11 +64,11 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: connection main closed
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGconnect: non-localhost access via sockets on line 61
+[NO_PID]: ECPGconnect: non-localhost access via sockets on line 64
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlcode -402 on line 61: could not connect to database "ecpg2_regression" on line 61
+[NO_PID]: raising sqlcode -402 on line 64: could not connect to database "ecpg2_regression" on line 64
[NO_PID]: sqlca: code: -402, state: 08001
-[NO_PID]: raising sqlcode -220 on line 62: connection "main" does not exist on line 62
+[NO_PID]: raising sqlcode -220 on line 65: connection "main" does not exist on line 65
[NO_PID]: sqlca: code: -220, state: 08003
[NO_PID]: ECPGconnect: opening database <DEFAULT> on <DEFAULT> port <DEFAULT> for user regress_ecpg_user2
[NO_PID]: sqlca: code: 0, state: 00000
@@ -76,9 +76,9 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: connection main closed
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlcode -402 on line 64: could not connect to database "<DEFAULT>" on line 64
+[NO_PID]: raising sqlcode -402 on line 67: could not connect to database "<DEFAULT>" on line 67
[NO_PID]: sqlca: code: -402, state: 08001
-[NO_PID]: raising sqlcode -220 on line 65: connection "main" does not exist on line 65
+[NO_PID]: raising sqlcode -220 on line 68: connection "main" does not exist on line 68
[NO_PID]: sqlca: code: -220, state: 08003
[NO_PID]: ECPGconnect: opening database ecpg2_regression on <DEFAULT> port <DEFAULT>
[NO_PID]: sqlca: code: 0, state: 00000
@@ -86,5 +86,5 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: connection main closed
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlcode -220 on line 73: connection "nonexistent" does not exist on line 73
+[NO_PID]: raising sqlcode -220 on line 76: connection "nonexistent" does not exist on line 76
[NO_PID]: sqlca: code: -220, state: 08003
diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm
index 233ddbf4c2..387405e381 100644
--- a/src/tools/msvc/Mkvcbuild.pm
+++ b/src/tools/msvc/Mkvcbuild.pm
@@ -110,7 +110,7 @@ sub mkvcbuild
pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c
pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c
pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c
- strerror.c tar.c thread.c
+ strerror.c tar.c thread.c setenv.c
win32env.c win32error.c win32security.c win32setlocale.c win32stat.c);
push(@pgportfiles, 'strtof.c') if ($vsVersion < '14.00');
diff --git a/src/tools/msvc/ecpg_regression.proj b/src/tools/msvc/ecpg_regression.proj
index ec2760b1f6..a0fe9310b1 100644
--- a/src/tools/msvc/ecpg_regression.proj
+++ b/src/tools/msvc/ecpg_regression.proj
@@ -54,7 +54,7 @@
<!-- Run ECPG and the Visual C++ compiler on the files. Don't bother with dependency check between the steps -->
<Exec WorkingDirectory="%(Pgc.RelativeDir)" Command="$(OUTDIR)ecpg\ecpg -I ../../include --regression $(ECPGPARAM) -o %(Pgc.Filename).c %(Pgc.Filename).pgc" />
- <Exec WorkingDirectory="%(Pgc.RelativeDir)" Command="cl /nologo %(Pgc.FileName).c /TC /MD$(DEBUGLIB) /DENABLE_THREAD_SAFETY /DWIN32 /I. /I..\..\include /I..\..\..\libpq /I..\..\..\..\include /link /defaultlib:$(OUTDIR)libecpg\libecpg.lib /defaultlib:$(OUTDIR)libecpg_compat\libecpg_compat.lib /defaultlib:$(OUTDIR)libpgtypes\libpgtypes.lib" />
+ <Exec WorkingDirectory="%(Pgc.RelativeDir)" Command="cl /nologo %(Pgc.FileName).c /TC /MD$(DEBUGLIB) /DENABLE_THREAD_SAFETY /DWIN32 /I. /I..\..\include /I..\..\..\libpq /I..\..\..\..\include /link /defaultlib:$(OUTDIR)libecpg\libecpg.lib /defaultlib:$(OUTDIR)libecpg_compat\libecpg_compat.lib /defaultlib:$(OUTDIR)libpgtypes\libpgtypes.lib /defaultlib:$(OUTDIR)libpgport\libpgport.lib /defaultlib:$(OUTDIR)libpgcommon\libpgcommon.lib" />
</Target>
<!-- Clean up all output files -->
signature.asc
Description: PGP signature
