Commit 757fb0e5 authored by Michael Meskes's avatar Michael Meskes

- Fixed Informix compat math functions to cope with the situations

  where one argument takes the result.
- Applied thread patches by Lee Kindness
parent 80ac9b06
...@@ -1724,9 +1724,9 @@ Wed Dec 17 16:11:16 CET 2003 ...@@ -1724,9 +1724,9 @@ Wed Dec 17 16:11:16 CET 2003
variable listing for output variables in cursor definitions variable listing for output variables in cursor definitions
- Fixed incorrect if call in long=>numeric conversion. - Fixed incorrect if call in long=>numeric conversion.
- Set ecpg version to 3.1.0 - Set ecpg version to 3.1.0
- Set ecpg library to 4.1.0 - Set ecpg library to 4.1
- Set pgtypes library to 1.1.0 - Set pgtypes library to 1.1
- Set compat library to 1.1.0 - Set compat library to 1.1
Mon Jan 26 21:57:14 CET 2004 Mon Jan 26 21:57:14 CET 2004
...@@ -1759,6 +1759,14 @@ Thu Mar 4 08:29:02 CET 2004 ...@@ -1759,6 +1759,14 @@ Thu Mar 4 08:29:02 CET 2004
- Fixed segfault due to missing check for variable declaration. - Fixed segfault due to missing check for variable declaration.
- Added check for multidimensional array usage. - Added check for multidimensional array usage.
- Set pgtypeslib version to 1.2.
Sun Mar 14 12:59:15 CET 2004
- Fixed Informix compat math functions to cope with the situations
where one argument takes the result.
- Applied thread patches by Lee Kindness
- Set pgtypes library version to 1.2.
- Set ecpg version to 3.2.0. - Set ecpg version to 3.2.0.
- Set compat library version to 1.2.
- Set ecpg library version to 4.2.
...@@ -60,8 +60,7 @@ deccall3(decimal * arg1, decimal * arg2, decimal * result, int (*ptr) (numeric * ...@@ -60,8 +60,7 @@ deccall3(decimal * arg1, decimal * arg2, decimal * result, int (*ptr) (numeric *
*nres; *nres;
int i; int i;
/* set it to null in case it errors out later */ /* we must NOT set the result to NULL here because it may be the same variable as one of the arguments */
rsetnull(CDECIMALTYPE, (char *) result);
if (risnull(CDECIMALTYPE, (char *) arg1) || risnull(CDECIMALTYPE, (char *) arg2)) if (risnull(CDECIMALTYPE, (char *) arg1) || risnull(CDECIMALTYPE, (char *) arg2))
return 0; return 0;
...@@ -100,8 +99,13 @@ deccall3(decimal * arg1, decimal * arg2, decimal * result, int (*ptr) (numeric * ...@@ -100,8 +99,13 @@ deccall3(decimal * arg1, decimal * arg2, decimal * result, int (*ptr) (numeric *
i = (*ptr) (a1, a2, nres); i = (*ptr) (a1, a2, nres);
if (i == 0) /* No error */ if (i == 0) /* No error */
{
/* set the result to null in case it errors out later */
rsetnull(CDECIMALTYPE, (char *) result);
PGTYPESnumeric_to_decimal(nres, result); PGTYPESnumeric_to_decimal(nres, result);
}
PGTYPESnumeric_free(nres); PGTYPESnumeric_free(nres);
PGTYPESnumeric_free(a1); PGTYPESnumeric_free(a1);
PGTYPESnumeric_free(a2); PGTYPESnumeric_free(a2);
...@@ -268,7 +272,6 @@ decdiv(decimal * n1, decimal * n2, decimal * result) ...@@ -268,7 +272,6 @@ decdiv(decimal * n1, decimal * n2, decimal * result)
int i; int i;
rsetnull(CDECIMALTYPE, (char *) result);
i = deccall3(n1, n2, result, PGTYPESnumeric_div); i = deccall3(n1, n2, result, PGTYPESnumeric_div);
if (i != 0) if (i != 0)
...@@ -293,7 +296,6 @@ decmul(decimal * n1, decimal * n2, decimal * result) ...@@ -293,7 +296,6 @@ decmul(decimal * n1, decimal * n2, decimal * result)
{ {
int i; int i;
rsetnull(CDECIMALTYPE, (char *) result);
i = deccall3(n1, n2, result, PGTYPESnumeric_mul); i = deccall3(n1, n2, result, PGTYPESnumeric_mul);
if (i != 0) if (i != 0)
...@@ -315,7 +317,6 @@ decsub(decimal * n1, decimal * n2, decimal * result) ...@@ -315,7 +317,6 @@ decsub(decimal * n1, decimal * n2, decimal * result)
{ {
int i; int i;
rsetnull(CDECIMALTYPE, (char *) result);
i = deccall3(n1, n2, result, PGTYPESnumeric_sub); i = deccall3(n1, n2, result, PGTYPESnumeric_sub);
if (i != 0) if (i != 0)
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# #
# Copyright (c) 1994, Regents of the University of California # Copyright (c) 1994, Regents of the University of California
# #
# $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.13 2004/02/10 07:26:25 tgl Exp $ # $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.14 2004/03/14 12:16:29 meskes Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -14,7 +14,7 @@ include $(top_builddir)/src/Makefile.global ...@@ -14,7 +14,7 @@ include $(top_builddir)/src/Makefile.global
NAME= ecpg NAME= ecpg
SO_MAJOR_VERSION= 4 SO_MAJOR_VERSION= 4
SO_MINOR_VERSION= 1 SO_MINOR_VERSION= 2
override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) $(CPPFLAGS) $(THREAD_CPPFLAGS) override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) $(CPPFLAGS) $(THREAD_CPPFLAGS)
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.19 2003/11/29 19:52:08 pgsql Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.20 2004/03/14 12:16:29 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL #define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -14,9 +14,20 @@ ...@@ -14,9 +14,20 @@
#ifdef ENABLE_THREAD_SAFETY #ifdef ENABLE_THREAD_SAFETY
static pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_key_t actual_connection_key;
static pthread_once_t actual_connection_key_once = PTHREAD_ONCE_INIT;
#else
static struct connection *actual_connection = NULL;
#endif #endif
static struct connection *all_connections = NULL; static struct connection *all_connections = NULL;
static struct connection *actual_connection = NULL;
#ifdef ENABLE_THREAD_SAFETY
static void
ecpg_actual_connection_init(void)
{
pthread_key_create(&actual_connection_key, NULL);
}
#endif
static struct connection * static struct connection *
ecpg_get_connection_nr(const char *connection_name) ecpg_get_connection_nr(const char *connection_name)
...@@ -24,7 +35,13 @@ ecpg_get_connection_nr(const char *connection_name) ...@@ -24,7 +35,13 @@ ecpg_get_connection_nr(const char *connection_name)
struct connection *ret = NULL; struct connection *ret = NULL;
if ((connection_name == NULL) || (strcmp(connection_name, "CURRENT") == 0)) if ((connection_name == NULL) || (strcmp(connection_name, "CURRENT") == 0))
{
#ifdef ENABLE_THREAD_SAFETY
ret = pthread_getspecific(actual_connection_key);
#else
ret = actual_connection; ret = actual_connection;
#endif
}
else else
{ {
struct connection *con; struct connection *con;
...@@ -86,8 +103,13 @@ ecpg_finish(struct connection * act) ...@@ -86,8 +103,13 @@ ecpg_finish(struct connection * act)
con->next = act->next; con->next = act->next;
} }
#ifdef ENABLE_THREAD_SAFETY
if( pthread_getspecific(actual_connection_key) == act )
pthread_setspecific(actual_connection_key, all_connections);
#else
if (actual_connection == act) if (actual_connection == act)
actual_connection = all_connections; actual_connection = all_connections;
#endif
ECPGlog("ecpg_finish: Connection %s closed.\n", act->name); ECPGlog("ecpg_finish: Connection %s closed.\n", act->name);
...@@ -150,7 +172,11 @@ ECPGsetconn(int lineno, const char *connection_name) ...@@ -150,7 +172,11 @@ ECPGsetconn(int lineno, const char *connection_name)
if (!ECPGinit(con, connection_name, lineno)) if (!ECPGinit(con, connection_name, lineno))
return (false); return (false);
#ifdef ENABLE_THREAD_SAFETY
pthread_setspecific(actual_connection_key, con);
#else
actual_connection = con; actual_connection = con;
#endif
return true; return true;
} }
...@@ -370,7 +396,13 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p ...@@ -370,7 +396,13 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
else else
this->next = all_connections; this->next = all_connections;
actual_connection = all_connections = this; all_connections = this;
#ifdef ENABLE_THREAD_SAFETY
pthread_once(&actual_connection_key_once, ecpg_actual_connection_init);
pthread_setspecific(actual_connection_key, all_connections);
#else
actual_connection = all_connections;
#endif
ECPGlog("ECPGconnect: opening database %s on %s port %s %s%s%s%s\n", ECPGlog("ECPGconnect: opening database %s on %s port %s %s%s%s%s\n",
realname ? realname : "<DEFAULT>", realname ? realname : "<DEFAULT>",
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.18 2003/11/29 19:52:08 pgsql Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.19 2004/03/14 12:16:30 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL #define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -118,10 +118,15 @@ ECPGinit(const struct connection * con, const char *connection_name, const int l ...@@ -118,10 +118,15 @@ ECPGinit(const struct connection * con, const char *connection_name, const int l
} }
#ifdef ENABLE_THREAD_SAFETY #ifdef ENABLE_THREAD_SAFETY
static void static void *ecpg_sqlca_key_destructor(void *arg)
ecpg_sqlca_key_init(void)
{ {
pthread_key_create(&sqlca_key, NULL); if( arg != NULL )
free(arg); /* sqlca structure allocated in ECPGget_sqlca */
}
static void ecpg_sqlca_key_init(void)
{
pthread_key_create(&sqlca_key, ecpg_sqlca_key_destructor);
} }
#endif #endif
......
# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.43 2003/12/19 23:29:15 momjian Exp $ # $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.44 2004/03/14 12:16:30 meskes Exp $
subdir = src/interfaces/ecpg/test subdir = src/interfaces/ecpg/test
top_builddir = ../../../.. top_builddir = ../../../..
...@@ -10,7 +10,7 @@ ECPG = ../preproc/ecpg -I$(srcdir)/../include ...@@ -10,7 +10,7 @@ ECPG = ../preproc/ecpg -I$(srcdir)/../include
TESTS = test1 test2 test3 test4 perftest dyntest dyntest2 test_notice test_code100 test_init testdynalloc num_test dt_test test_informix TESTS = test1 test2 test3 test4 perftest dyntest dyntest2 test_notice test_code100 test_init testdynalloc num_test dt_test test_informix
ifeq ($(enable_thread_safety), yes) ifeq ($(enable_thread_safety), yes)
TESTS += test_thread TESTS += test_thread test_thread_implicit
endif endif
all: $(TESTS) all: $(TESTS)
......
/* /*
* Thread test program * Thread test program
* by Philip Yarra * by Philip Yarra & Lee Kindness.
*/ */
/* #define ECPGDEBUG */
#include <pthread.h> #include <pthread.h>
#include <stdlib.h> #include <stdlib.h>
void ins1(void); void *test_thread(void *arg);
void ins2(void);
EXEC SQL BEGIN DECLARE SECTION; EXEC SQL BEGIN DECLARE SECTION;
char *dbname; char *l_dbname;
int iterations = 10;
EXEC SQL END DECLARE SECTION; EXEC SQL END DECLARE SECTION;
int nthreads = 2;
int iterations = 10;
int int main(int argc, char *argv[])
main(int argc, char *argv[])
{ {
pthread_t thread1, #ifdef ECPGDEBUG
thread2; char debugfilename[] = "thread_test.log";
EXEC SQL BEGIN DECLARE SECTION; FILE *debugfile;
int rows; #endif
EXEC SQL END DECLARE SECTION; pthread_t *threads;
int n;
if (argc < 2 || argc > 3) EXEC SQL BEGIN DECLARE SECTION;
{ int l_rows;
fprintf(stderr, "Usage: %s dbname [iterations]\n", argv[0]); EXEC SQL END DECLARE SECTION;
return 1;
} /* parse command line arguments */
dbname = argv[1]; if( (argc < 2) || (argc > 4) )
{
if (argc == 3) fprintf(stderr, "Usage: %s dbname [threads] [iterations_per_thread]\n", argv[0]);
iterations = atoi(argv[2]); return( 1 );
if (iterations % 2 != 0) }
{ l_dbname = argv[1];
fprintf(stderr, "iterations must be an even number\n"); if( argc >= 3 )
return 1; nthreads = atoi(argv[2]);
} if( argc == 4 )
iterations = atoi(argv[3]);
EXEC SQL CONNECT TO:dbname AS test0;
/* open ECPG debug log? */
/* DROP might fail */ #ifdef ECPGDEBUG
EXEC SQL AT test0 DROP TABLE test_thread; debugfile = fopen(debugfilename, "w");
EXEC SQL AT test0 COMMIT WORK; if( debugfile != NULL )
EXEC SQL AT test0 CREATE TABLE test_thread(message TEXT); ECPGdebug(1, debugfile);
EXEC SQL AT test0 COMMIT WORK; else
EXEC SQL DISCONNECT test0; fprintf(stderr, "Cannot open ECPG debug log: %s\n", debugfilename);
#endif
pthread_create(&thread1, NULL, (void * (*)(void *)) ins1, NULL);
pthread_create(&thread2, NULL, (void * (*)(void *)) ins2, NULL); /* setup test_thread table */
pthread_join(thread1, NULL); EXEC SQL CONNECT TO:l_dbname;
pthread_join(thread2, NULL); EXEC SQL DROP TABLE test_thread; /* DROP might fail */
EXEC SQL COMMIT;
EXEC SQL CONNECT TO:dbname AS test3; EXEC SQL CREATE TABLE
EXEC SQL AT test3 SELECT COUNT(*) INTO :rows FROM test_thread; test_thread(tstamp TIMESTAMP NOT NULL DEFAULT CAST(timeofday() AS TIMESTAMP),
EXEC SQL AT test3 COMMIT WORK; thread TEXT NOT NULL,
EXEC SQL DISCONNECT test3; iteration INTEGER NOT NULL,
PRIMARY KEY(thread, iteration));
if (rows == iterations) EXEC SQL COMMIT;
printf("\nSuccess.\n"); EXEC SQL DISCONNECT;
else
printf("\nFailure.\n"); /* create, and start, threads */
return 0; threads = calloc(nthreads, sizeof(pthread_t));
if( threads == NULL )
{
fprintf(stderr, "Cannot alloc memory\n");
return( 1 );
}
for( n = 0; n < nthreads; n++ )
{
pthread_create(&threads[n], NULL, test_thread, (void *)n + 1);
}
/* wait for thread completion */
for( n = 0; n < nthreads; n++ )
{
pthread_join(threads[n], NULL);
}
free(threads);
/* and check results */
EXEC SQL CONNECT TO :l_dbname;
EXEC SQL SELECT COUNT(*) INTO :l_rows FROM test_thread;
EXEC SQL COMMIT;
EXEC SQL DISCONNECT;
if( l_rows == (nthreads * iterations) )
printf("\nSuccess.\n");
else
printf("\nERROR: Failure - expecting %d rows, got %d.\n", nthreads * iterations, l_rows);
/* close ECPG debug log? */
#ifdef ECPGDEBUG
if( debugfile != NULL )
{
ECPGdebug(0, debugfile);
fclose(debugfile);
}
#endif
return( 0 );
} }
void void *test_thread(void *arg)
ins1(void)
{ {
int i; long threadnum = (long)arg;
EXEC SQL WHENEVER sqlerror sqlprint; EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL CONNECT TO:dbname AS test1; int l_i;
char l_connection[128];
for (i = 0; i < iterations / 2; i++) EXEC SQL END DECLARE SECTION;
{
printf("thread 1 : inserting\n"); /* build up connection name, and connect to database */
EXEC SQL AT test1 INSERT INTO test_thread VALUES('thread1'); snprintf(l_connection, sizeof(l_connection), "thread_%03ld", threadnum);
EXEC SQL WHENEVER sqlerror sqlprint;
printf("thread 1 : insert done\n"); EXEC SQL CONNECT TO :l_dbname AS :l_connection;
} if( sqlca.sqlcode != 0 )
EXEC SQL AT test1 COMMIT WORK; {
EXEC SQL DISCONNECT test1; printf("%s: ERROR: cannot connect to database!\n", l_connection);
return( NULL );
printf("thread 1 : done!\n"); }
} EXEC SQL AT :l_connection BEGIN;
/* insert into test_thread table */
void for( l_i = 1; l_i <= iterations; l_i++ )
ins2(void) {
{ printf("%s: inserting %d\n", l_connection, l_i);
int i; EXEC SQL AT :l_connection INSERT INTO test_thread(thread, iteration) VALUES(:l_connection, :l_i);
EXEC SQL WHENEVER sqlerror sqlprint; if( sqlca.sqlcode == 0 )
EXEC SQL CONNECT TO:dbname AS test2; printf("%s: insert done\n", l_connection);
else
for (i = 0; i < iterations / 2; i++) printf("%s: ERROR: insert failed!\n", l_connection);
{ }
printf("thread 2: inserting\n");
EXEC SQL AT test2 INSERT INTO test_thread VALUES('thread2'); /* all done */
EXEC SQL AT :l_connection COMMIT;
printf("thread 2: insert done\n"); EXEC SQL DISCONNECT :l_connection;
} printf("%s: done!\n", l_connection);
EXEC SQL AT test2 COMMIT WORK; return( NULL );
EXEC SQL DISCONNECT test2;
printf("thread 2: done!\n");
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment