Skip to content

Commit c8577c6

Browse files
author
Michael Meskes
committed
Inlined two functions to get rid of va_list problems on some archs.
1 parent a2e923a commit c8577c6

File tree

3 files changed

+149
-146
lines changed

3 files changed

+149
-146
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,4 +2183,9 @@ Thu, 29 Mar 2007 11:18:39 +0200
21832183
- Added patch by Magnus Hagander <magnus@hagander.net> to use native
21842184
win32 threads.
21852185
- Fixed regression tests to run threading tests.
2186+
2187+
Fr 27. Apr 08:55:25 CEST 2007
2188+
2189+
- Inlined two functions to get rid of va_list problems on some
2190+
architectures.
21862191
- Set ecpg version to 4.3.1.

src/interfaces/ecpg/ecpglib/descriptor.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* dynamic SQL support routines
22
*
3-
* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.20 2006/10/04 00:30:11 momjian Exp $
3+
* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.21 2007/04/27 06:56:11 meskes Exp $
44
*/
55

66
#define POSTGRES_ECPG_INTERNAL
@@ -507,7 +507,6 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
507507
do
508508
{
509509
enum ECPGdtype itemtype;
510-
enum ECPGttype type;
511510
const char *tobeinserted = NULL;
512511
bool malloced;
513512

@@ -516,13 +515,29 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
516515
if (itemtype == ECPGd_EODT)
517516
break;
518517

519-
type = va_arg(args, enum ECPGttype);
520-
#if defined(__GNUC__) && (defined (__powerpc__) || defined(__amd64__) || defined(__x86_64__))
521-
ECPGget_variable(args, type, var, false);
522-
#else
523-
ECPGget_variable(&args, type, var, false);
524-
#endif
518+
var->type = va_arg(args, enum ECPGttype);
519+
var->pointer = va_arg(args, char *);
525520

521+
var->varcharsize = va_arg(args, long);
522+
var->arrsize = va_arg(args, long);
523+
var->offset = va_arg(args, long);
524+
525+
if (var->arrsize == 0 || var->varcharsize == 0)
526+
var->value = *((char **) (var->pointer));
527+
else
528+
var->value = var->pointer;
529+
530+
/*
531+
* negative values are used to indicate an array without given bounds
532+
*/
533+
/* reset to zero for us */
534+
if (var->arrsize < 0)
535+
var->arrsize = 0;
536+
if (var->varcharsize < 0)
537+
var->varcharsize = 0;
538+
539+
var->next = NULL;
540+
526541
switch (itemtype)
527542
{
528543
case ECPGd_data:

src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 121 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.65 2007/03/29 12:02:24 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.66 2007/04/27 06:56:11 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -79,136 +79,6 @@ quote_postgres(char *arg, bool quote, int lineno)
7979
}
8080
}
8181

82-
#if defined(__GNUC__) && (defined (__powerpc__) || defined(__amd64__) || defined(__x86_64__))
83-
#define APREF ap
84-
#else
85-
#define APREF *ap
86-
#endif
87-
88-
void
89-
ECPGget_variable(va_list APREF, enum ECPGttype type, struct variable * var, bool indicator)
90-
{
91-
var->type = type;
92-
var->pointer = va_arg(APREF, char *);
93-
94-
var->varcharsize = va_arg(APREF, long);
95-
var->arrsize = va_arg(APREF, long);
96-
var->offset = va_arg(APREF, long);
97-
98-
if (var->arrsize == 0 || var->varcharsize == 0)
99-
var->value = *((char **) (var->pointer));
100-
else
101-
var->value = var->pointer;
102-
103-
/*
104-
* negative values are used to indicate an array without given bounds
105-
*/
106-
/* reset to zero for us */
107-
if (var->arrsize < 0)
108-
var->arrsize = 0;
109-
if (var->varcharsize < 0)
110-
var->varcharsize = 0;
111-
112-
var->next = NULL;
113-
114-
if (indicator)
115-
{
116-
var->ind_type = va_arg(APREF, enum ECPGttype);
117-
var->ind_pointer = va_arg(APREF, char *);
118-
var->ind_varcharsize = va_arg(APREF, long);
119-
var->ind_arrsize = va_arg(APREF, long);
120-
var->ind_offset = va_arg(APREF, long);
121-
122-
if (var->ind_type != ECPGt_NO_INDICATOR
123-
&& (var->ind_arrsize == 0 || var->ind_varcharsize == 0))
124-
var->ind_value = *((char **) (var->ind_pointer));
125-
else
126-
var->ind_value = var->ind_pointer;
127-
128-
/*
129-
* negative values are used to indicate an array without given bounds
130-
*/
131-
/* reset to zero for us */
132-
if (var->ind_arrsize < 0)
133-
var->ind_arrsize = 0;
134-
if (var->ind_varcharsize < 0)
135-
var->ind_varcharsize = 0;
136-
}
137-
}
138-
139-
/*
140-
* create a list of variables
141-
* The variables are listed with input variables preceding outputvariables
142-
* The end of each group is marked by an end marker.
143-
* per variable we list:
144-
* type - as defined in ecpgtype.h
145-
* value - where to store the data
146-
* varcharsize - length of string in case we have a stringvariable, else 0
147-
* arraysize - 0 for pointer (we don't know the size of the array),
148-
* 1 for simple variable, size for arrays
149-
* offset - offset between ith and (i+1)th entry in an array,
150-
* normally that means sizeof(type)
151-
* ind_type - type of indicator variable
152-
* ind_value - pointer to indicator variable
153-
* ind_varcharsize - empty
154-
* ind_arraysize - arraysize of indicator array
155-
* ind_offset - indicator offset
156-
*/
157-
static bool
158-
create_statement(int lineno, int compat, int force_indicator, struct connection * connection, struct statement ** stmt, const char *query, va_list APREF)
159-
{
160-
struct variable **list = &((*stmt)->inlist);
161-
enum ECPGttype type;
162-
163-
if (!(*stmt = (struct statement *) ECPGalloc(sizeof(struct statement), lineno)))
164-
return false;
165-
166-
(*stmt)->command = ECPGstrdup(query, lineno);
167-
(*stmt)->connection = connection;
168-
(*stmt)->lineno = lineno;
169-
(*stmt)->compat = compat;
170-
(*stmt)->force_indicator = force_indicator;
171-
172-
list = &((*stmt)->inlist);
173-
174-
type = va_arg(APREF, enum ECPGttype);
175-
176-
while (type != ECPGt_EORT)
177-
{
178-
if (type == ECPGt_EOIT)
179-
list = &((*stmt)->outlist);
180-
else
181-
{
182-
struct variable *var,
183-
*ptr;
184-
185-
if (!(var = (struct variable *) ECPGalloc(sizeof(struct variable), lineno)))
186-
return false;
187-
188-
ECPGget_variable(ap, type, var, true);
189-
190-
/* if variable is NULL, the statement hasn't been prepared */
191-
if (var->pointer == NULL)
192-
{
193-
ECPGraise(lineno, ECPG_INVALID_STMT, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, NULL);
194-
ECPGfree(var);
195-
return false;
196-
}
197-
198-
for (ptr = *list; ptr && ptr->next; ptr = ptr->next);
199-
200-
if (ptr == NULL)
201-
*list = var;
202-
else
203-
ptr->next = var;
204-
}
205-
206-
type = va_arg(APREF, enum ECPGttype);
207-
}
208-
209-
return (true);
210-
}
211-
21282
static void
21383
free_variable(struct variable * var)
21484
{
@@ -1519,6 +1389,8 @@ ECPGdo(int lineno, int compat, int force_indicator, const char *connection_name,
15191389
struct connection *con;
15201390
bool status;
15211391
char *oldlocale;
1392+
enum ECPGttype type;
1393+
struct variable **list;
15221394

15231395
/* Make sure we do NOT honor the locale for numeric input/output */
15241396
/* since the database wants the standard decimal point */
@@ -1540,17 +1412,128 @@ ECPGdo(int lineno, int compat, int force_indicator, const char *connection_name,
15401412

15411413
/* construct statement in our own structure */
15421414
va_start(args, query);
1543-
#if defined(__GNUC__) && (defined (__powerpc__) || defined(__amd64__) || defined(__x86_64__))
1544-
if (create_statement(lineno, compat, force_indicator, con, &stmt, query, args) == false)
1545-
#else
1546-
if (create_statement(lineno, compat, force_indicator, con, &stmt, query, &args) == false)
1547-
#endif
1415+
1416+
/*
1417+
* create a list of variables
1418+
* The variables are listed with input variables preceding outputvariables
1419+
* The end of each group is marked by an end marker.
1420+
* per variable we list:
1421+
* type - as defined in ecpgtype.h
1422+
* value - where to store the data
1423+
* varcharsize - length of string in case we have a stringvariable, else 0
1424+
* arraysize - 0 for pointer (we don't know the size of the array),
1425+
* 1 for simple variable, size for arrays
1426+
* offset - offset between ith and (i+1)th entry in an array,
1427+
* normally that means sizeof(type)
1428+
* ind_type - type of indicator variable
1429+
* ind_value - pointer to indicator variable
1430+
* ind_varcharsize - empty
1431+
* ind_arraysize - arraysize of indicator array
1432+
* ind_offset - indicator offset
1433+
*/
1434+
if (!(stmt = (struct statement *) ECPGalloc(sizeof(struct statement), lineno)))
15481435
{
15491436
setlocale(LC_NUMERIC, oldlocale);
15501437
ECPGfree(oldlocale);
1551-
free_statement(stmt);
1552-
return (false);
1438+
va_end(args);
1439+
return false;
1440+
}
1441+
1442+
stmt->command = ECPGstrdup(query, lineno);
1443+
stmt->connection = con;
1444+
stmt->lineno = lineno;
1445+
stmt->compat = compat;
1446+
stmt->force_indicator = force_indicator;
1447+
1448+
list = &(stmt->inlist);
1449+
1450+
type = va_arg(args, enum ECPGttype);
1451+
1452+
while (type != ECPGt_EORT)
1453+
{
1454+
if (type == ECPGt_EOIT)
1455+
list = &(stmt->outlist);
1456+
else
1457+
{
1458+
struct variable *var,
1459+
*ptr;
1460+
1461+
if (!(var = (struct variable *) ECPGalloc(sizeof(struct variable), lineno)))
1462+
{
1463+
setlocale(LC_NUMERIC, oldlocale);
1464+
ECPGfree(oldlocale);
1465+
free_statement(stmt);
1466+
va_end(args);
1467+
return false;
1468+
}
1469+
1470+
var->type = type;
1471+
var->pointer = va_arg(args, char *);
1472+
1473+
var->varcharsize = va_arg(args, long);
1474+
var->arrsize = va_arg(args, long);
1475+
var->offset = va_arg(args, long);
1476+
1477+
if (var->arrsize == 0 || var->varcharsize == 0)
1478+
var->value = *((char **) (var->pointer));
1479+
else
1480+
var->value = var->pointer;
1481+
1482+
/*
1483+
* negative values are used to indicate an array without given bounds
1484+
*/
1485+
/* reset to zero for us */
1486+
if (var->arrsize < 0)
1487+
var->arrsize = 0;
1488+
if (var->varcharsize < 0)
1489+
var->varcharsize = 0;
1490+
1491+
var->next = NULL;
1492+
1493+
var->ind_type = va_arg(args, enum ECPGttype);
1494+
var->ind_pointer = va_arg(args, char *);
1495+
var->ind_varcharsize = va_arg(args, long);
1496+
var->ind_arrsize = va_arg(args, long);
1497+
var->ind_offset = va_arg(args, long);
1498+
1499+
if (var->ind_type != ECPGt_NO_INDICATOR
1500+
&& (var->ind_arrsize == 0 || var->ind_varcharsize == 0))
1501+
var->ind_value = *((char **) (var->ind_pointer));
1502+
else
1503+
var->ind_value = var->ind_pointer;
1504+
1505+
/*
1506+
* negative values are used to indicate an array without given bounds
1507+
*/
1508+
/* reset to zero for us */
1509+
if (var->ind_arrsize < 0)
1510+
var->ind_arrsize = 0;
1511+
if (var->ind_varcharsize < 0)
1512+
var->ind_varcharsize = 0;
1513+
1514+
/* if variable is NULL, the statement hasn't been prepared */
1515+
if (var->pointer == NULL)
1516+
{
1517+
ECPGraise(lineno, ECPG_INVALID_STMT, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, NULL);
1518+
ECPGfree(var);
1519+
setlocale(LC_NUMERIC, oldlocale);
1520+
ECPGfree(oldlocale);
1521+
free_statement(stmt);
1522+
va_end(args);
1523+
return false;
1524+
}
1525+
1526+
for (ptr = *list; ptr && ptr->next; ptr = ptr->next);
1527+
1528+
if (ptr == NULL)
1529+
*list = var;
1530+
else
1531+
ptr->next = var;
1532+
}
1533+
1534+
type = va_arg(args, enum ECPGttype);
15531535
}
1536+
15541537
va_end(args);
15551538

15561539
/* are we connected? */

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