Skip to content

Commit 757fb0e

Browse files
author
Michael Meskes
committed
- Fixed Informix compat math functions to cope with the situations
where one argument takes the result. - Applied thread patches by Lee Kindness
1 parent 80ac9b0 commit 757fb0e

File tree

7 files changed

+190
-111
lines changed

7 files changed

+190
-111
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,9 +1724,9 @@ Wed Dec 17 16:11:16 CET 2003
17241724
variable listing for output variables in cursor definitions
17251725
- Fixed incorrect if call in long=>numeric conversion.
17261726
- Set ecpg version to 3.1.0
1727-
- Set ecpg library to 4.1.0
1728-
- Set pgtypes library to 1.1.0
1729-
- Set compat library to 1.1.0
1727+
- Set ecpg library to 4.1
1728+
- Set pgtypes library to 1.1
1729+
- Set compat library to 1.1
17301730

17311731
Mon Jan 26 21:57:14 CET 2004
17321732

@@ -1759,6 +1759,14 @@ Thu Mar 4 08:29:02 CET 2004
17591759

17601760
- Fixed segfault due to missing check for variable declaration.
17611761
- Added check for multidimensional array usage.
1762-
- Set pgtypeslib version to 1.2.
1762+
1763+
Sun Mar 14 12:59:15 CET 2004
1764+
1765+
- Fixed Informix compat math functions to cope with the situations
1766+
where one argument takes the result.
1767+
- Applied thread patches by Lee Kindness
1768+
- Set pgtypes library version to 1.2.
17631769
- Set ecpg version to 3.2.0.
1770+
- Set compat library version to 1.2.
1771+
- Set ecpg library version to 4.2.
17641772

src/interfaces/ecpg/compatlib/informix.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ deccall3(decimal * arg1, decimal * arg2, decimal * result, int (*ptr) (numeric *
6060
*nres;
6161
int i;
6262

63-
/* set it to null in case it errors out later */
64-
rsetnull(CDECIMALTYPE, (char *) result);
63+
/* we must NOT set the result to NULL here because it may be the same variable as one of the arguments */
6564
if (risnull(CDECIMALTYPE, (char *) arg1) || risnull(CDECIMALTYPE, (char *) arg2))
6665
return 0;
6766

@@ -100,8 +99,13 @@ deccall3(decimal * arg1, decimal * arg2, decimal * result, int (*ptr) (numeric *
10099
i = (*ptr) (a1, a2, nres);
101100

102101
if (i == 0) /* No error */
102+
{
103+
104+
/* set the result to null in case it errors out later */
105+
rsetnull(CDECIMALTYPE, (char *) result);
103106
PGTYPESnumeric_to_decimal(nres, result);
104-
107+
}
108+
105109
PGTYPESnumeric_free(nres);
106110
PGTYPESnumeric_free(a1);
107111
PGTYPESnumeric_free(a2);
@@ -268,7 +272,6 @@ decdiv(decimal * n1, decimal * n2, decimal * result)
268272

269273
int i;
270274

271-
rsetnull(CDECIMALTYPE, (char *) result);
272275
i = deccall3(n1, n2, result, PGTYPESnumeric_div);
273276

274277
if (i != 0)
@@ -293,7 +296,6 @@ decmul(decimal * n1, decimal * n2, decimal * result)
293296
{
294297
int i;
295298

296-
rsetnull(CDECIMALTYPE, (char *) result);
297299
i = deccall3(n1, n2, result, PGTYPESnumeric_mul);
298300

299301
if (i != 0)
@@ -315,7 +317,6 @@ decsub(decimal * n1, decimal * n2, decimal * result)
315317
{
316318
int i;
317319

318-
rsetnull(CDECIMALTYPE, (char *) result);
319320
i = deccall3(n1, n2, result, PGTYPESnumeric_sub);
320321

321322
if (i != 0)

src/interfaces/ecpg/ecpglib/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.13 2004/02/10 07:26:25 tgl Exp $
7+
# $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.14 2004/03/14 12:16:29 meskes Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -14,7 +14,7 @@ include $(top_builddir)/src/Makefile.global
1414

1515
NAME= ecpg
1616
SO_MAJOR_VERSION= 4
17-
SO_MINOR_VERSION= 1
17+
SO_MINOR_VERSION= 2
1818

1919
override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) $(CPPFLAGS) $(THREAD_CPPFLAGS)
2020

src/interfaces/ecpg/ecpglib/connect.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.19 2003/11/29 19:52:08 pgsql Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.20 2004/03/14 12:16:29 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -14,17 +14,34 @@
1414

1515
#ifdef ENABLE_THREAD_SAFETY
1616
static pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER;
17+
static pthread_key_t actual_connection_key;
18+
static pthread_once_t actual_connection_key_once = PTHREAD_ONCE_INIT;
19+
#else
20+
static struct connection *actual_connection = NULL;
1721
#endif
1822
static struct connection *all_connections = NULL;
19-
static struct connection *actual_connection = NULL;
23+
24+
#ifdef ENABLE_THREAD_SAFETY
25+
static void
26+
ecpg_actual_connection_init(void)
27+
{
28+
pthread_key_create(&actual_connection_key, NULL);
29+
}
30+
#endif
2031

2132
static struct connection *
2233
ecpg_get_connection_nr(const char *connection_name)
2334
{
2435
struct connection *ret = NULL;
2536

2637
if ((connection_name == NULL) || (strcmp(connection_name, "CURRENT") == 0))
38+
{
39+
#ifdef ENABLE_THREAD_SAFETY
40+
ret = pthread_getspecific(actual_connection_key);
41+
#else
2742
ret = actual_connection;
43+
#endif
44+
}
2845
else
2946
{
3047
struct connection *con;
@@ -86,8 +103,13 @@ ecpg_finish(struct connection * act)
86103
con->next = act->next;
87104
}
88105

106+
#ifdef ENABLE_THREAD_SAFETY
107+
if( pthread_getspecific(actual_connection_key) == act )
108+
pthread_setspecific(actual_connection_key, all_connections);
109+
#else
89110
if (actual_connection == act)
90111
actual_connection = all_connections;
112+
#endif
91113

92114
ECPGlog("ecpg_finish: Connection %s closed.\n", act->name);
93115

@@ -150,7 +172,11 @@ ECPGsetconn(int lineno, const char *connection_name)
150172
if (!ECPGinit(con, connection_name, lineno))
151173
return (false);
152174

175+
#ifdef ENABLE_THREAD_SAFETY
176+
pthread_setspecific(actual_connection_key, con);
177+
#else
153178
actual_connection = con;
179+
#endif
154180
return true;
155181
}
156182

@@ -370,7 +396,13 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
370396
else
371397
this->next = all_connections;
372398

373-
actual_connection = all_connections = this;
399+
all_connections = this;
400+
#ifdef ENABLE_THREAD_SAFETY
401+
pthread_once(&actual_connection_key_once, ecpg_actual_connection_init);
402+
pthread_setspecific(actual_connection_key, all_connections);
403+
#else
404+
actual_connection = all_connections;
405+
#endif
374406

375407
ECPGlog("ECPGconnect: opening database %s on %s port %s %s%s%s%s\n",
376408
realname ? realname : "<DEFAULT>",

src/interfaces/ecpg/ecpglib/misc.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.18 2003/11/29 19:52:08 pgsql Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.19 2004/03/14 12:16:30 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -118,10 +118,15 @@ ECPGinit(const struct connection * con, const char *connection_name, const int l
118118
}
119119

120120
#ifdef ENABLE_THREAD_SAFETY
121-
static void
122-
ecpg_sqlca_key_init(void)
121+
static void *ecpg_sqlca_key_destructor(void *arg)
123122
{
124-
pthread_key_create(&sqlca_key, NULL);
123+
if( arg != NULL )
124+
free(arg); /* sqlca structure allocated in ECPGget_sqlca */
125+
}
126+
127+
static void ecpg_sqlca_key_init(void)
128+
{
129+
pthread_key_create(&sqlca_key, ecpg_sqlca_key_destructor);
125130
}
126131
#endif
127132

src/interfaces/ecpg/test/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.43 2003/12/19 23:29:15 momjian Exp $
1+
# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.44 2004/03/14 12:16:30 meskes Exp $
22

33
subdir = src/interfaces/ecpg/test
44
top_builddir = ../../../..
@@ -10,7 +10,7 @@ ECPG = ../preproc/ecpg -I$(srcdir)/../include
1010

1111
TESTS = test1 test2 test3 test4 perftest dyntest dyntest2 test_notice test_code100 test_init testdynalloc num_test dt_test test_informix
1212
ifeq ($(enable_thread_safety), yes)
13-
TESTS += test_thread
13+
TESTS += test_thread test_thread_implicit
1414
endif
1515

1616
all: $(TESTS)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy