Skip to Content.
Sympa Menu

freetds - Re: [freetds] Solaris/SPARC: SIGBUS in unittests/array_out.c

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Peter C. Norton" <spacey-freetds.org AT ssr.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Solaris/SPARC: SIGBUS in unittests/array_out.c
  • Date: Wed, 22 Sep 2010 23:34:35 -0400

Frediano,

For the SIGBUS, the fix at
http://freetds.cvs.sourceforge.net/viewvc/freetds/freetds/src/odbc/unittests/array_out.c?r1=1.16&r2=1.17
works fine for me, thanks!.

More unittest failures:

(1) data fails in the following manner:

SELECT CONVERT(INT, '-123') AS data
SELECT CONVERT(INT, '78654') AS data
SELECT CONVERT(VARCHAR(10), ' 51245 ') AS data
SELECT CONVERT(UNIVARCHAR(10), u&'\06A4\FBA5') AS data
Wrong result
Got: 2 \ua406\ua5fb
Expected: 2 \u06a4\ufba5
SELECT CONVERT(DECIMAL, '1234.5678') AS data
SELECT CONVERT(NUMERIC, '8765.4321') AS data
SELECT CONVERT(FLOAT, '1234.5678') AS data
SELECT CONVERT(REAL, '8765.4321') AS data
SELECT CONVERT(SMALLMONEY, '765.4321') AS data
SELECT CONVERT(MONEY, '4321234.5678') AS data
SELECT CONVERT(DATETIME, '2006-06-09 11:22:44') AS data
SELECT CONVERT(SMALLDATETIME, '2006-06-12 22:37:21') AS data
SELECT CONVERT(DATETIME, '2006-06-09 11:22:44') AS data
SELECT CONVERT(SMALLDATETIME, '2006-06-12 22:37:21') AS data
FAIL: data

This looks like an endian problem, as the bytes appear to be swapped.
>From googling around, it looks like in the case of ODBC, it specifies
that that SQL_W_CHAR is in host byte order. However, this SPARC is
connecting to an x86 server and I don't see any checks for byte
ordering being done in the test:

case SQL_C_WCHAR:
assert(out_len >=0 && (out_len % sizeof(SQLWCHAR)) == 0);
sprintf(sbuf, "%u ", (unsigned int) (out_len /
sizeof(SQLWCHAR)));
wp = (SQLWCHAR*) out_buf;
for (i = 0; i < out_len / sizeof(SQLWCHAR); ++i)
if ((unsigned int) wp[i] < 256)
sprintf(strchr(sbuf, 0), "%c", (char) wp[i]);
else
sprintf(strchr(sbuf, 0), "\\u%04x", (unsigned
int) wp[i]);
break;

Is there a right way to check the byte order of the remote host and
correct for this in the test?

(2) timeout3 isn't returning consistently:

/tmp/freetds/src/odbc/unittests $ ./timeout3
Fake server binded at port 12340
try to connect to our port just to check connection timeout
Alarm Clock
/tmp/freetds/src/odbc/unittests $ ./timeout3
Fake server binded at port 12340
try to connect to our port just to check connection timeout
Message: HYT00 - [unixODBC][FreeTDS][SQL Server]Timeout expired
Done.

I'm testing this because my prior "make check" looked like this:
Fake server binded at port 12340
try to connect to our port just to check connection timeout
/bin/bash: line 4: 2854 Alarm Clock ${dir}$tst
FAIL: timeout3

Thanks,

-Peter


On Wed, Sep 22, 2010 at 09:22:52AM +0200, Frediano Ziglio wrote:
> I think that this patch works... too much :)
> The SIGBUS is due to wrong alignment in the test. ODBC programs should
> always align data passed to ODBC. Your program fix SIGBUS in the test but
> probably ODBC driver will core (correctly) in the driver. I aligned
> correctly record size for 64-bit platforms (it was aligned to SQLINTEGER
> instead of SQLLEN).
>
> freddy77
>
>
> 2010/9/21 Christos Zoulas <christos AT zoulas.com>
>
> > On Sep 21, 12:56pm, spacey-freetds.org AT ssr.com ("Peter C. Norton") wrote:
> > -- Subject: [freetds] Solaris/SPARC: SIGBUS in unittests/array_out.c
> >
> > | Group,
> > |
> > | I'm no good at alignment issues, so I'm looking for help here. I've
> > | got a 64-bit build of freetds-0.83.dev.20100902:
> > |
> > | nortonp@ssqa1 11:54 /tmp/freetds/src/odbc/unittests $ ./array_out
> > | odbctest
> >
> > Who in their right mind would try to run code on non Pee-Cee machines?!?
> > (just kidding). Try this completely untested fix...
> >
> > christos
> >
> > Index: array_out.c
> > ===================================================================
> > RCS file:
> > /src/twosigma/cvsroot/external/public/freetds/src/odbc/unittests/array_out.c,v
> > retrieving revision 1.1.1.3
> > diff -u -u -r1.1.1.3 array_out.c
> > --- array_out.c 17 Jun 2009 18:31:59 -0000 1.1.1.3
> > +++ array_out.c 21 Sep 2010 19:16:59 -0000
> > @@ -22,13 +22,12 @@
> > {
> > #define ARRAY_SIZE 10
> >
> > - SQLUINTEGER *ids;
> > + SQLUINTEGER *ids, id;
> > SQLCHAR *descs;
> > - SQLLEN *id_lens, *desc_lens;
> > + SQLLEN *id_lens, id_len, *desc_lens, desc_len;
> > SQLULEN processed;
> > SQLUSMALLINT i, statuses[ARRAY_SIZE];
> > - int desc_len = trunc ? 4 : 51;
> > - int rec_size = 0;
> > + int rec_size = 0, dlen = trunc ? 4 : 51;
> > Record *rec = NULL;
> > char status[20];
> >
> > @@ -41,37 +40,40 @@
> > SQLSetStmtAttr(Statement, SQL_ATTR_ROW_BIND_TYPE,
> > SQL_BIND_BY_COLUMN, 0);
> >
> > if (!record_bind) {
> > - ids = (SQLUINTEGER *) malloc(sizeof(SQLUINTEGER) *
> > ARRAY_SIZE);
> > - descs = malloc(sizeof(SQLCHAR) * ARRAY_SIZE * desc_len);
> > - desc_lens = (SQLLEN *) malloc(sizeof(SQLLEN) *
> > ARRAY_SIZE);
> > - id_lens = (SQLLEN *) malloc(sizeof(SQLLEN) * ARRAY_SIZE);
> > + ids = malloc(sizeof(*ids) * ARRAY_SIZE);
> > + descs = malloc(sizeof(*descs) * ARRAY_SIZE * dlen);
> > + desc_lens = malloc(sizeof(*desc_lens) * ARRAY_SIZE);
> > + id_lens = malloc(sizeof(*id_lens) * ARRAY_SIZE);
> > assert(descs && ids && desc_lens && id_lens);
> > } else {
> > - rec_size = sizeof(Record) + ((sizeof(SQLCHAR) * desc_len +
> > sizeof(SQLINTEGER) - 1) & ~(sizeof(SQLINTEGER) - 1));
> > + rec_size = sizeof(Record) + ((sizeof(SQLCHAR) * dlen +
> > sizeof(SQLINTEGER) - 1) & ~(sizeof(SQLINTEGER) - 1));
> > SQLSetStmtAttr(Statement, SQL_ATTR_ROW_BIND_TYPE,
> > int2ptr(rec_size), 0);
> > - rec = (Record *) malloc(rec_size * ARRAY_SIZE);
> > + rec = malloc(rec_size * ARRAY_SIZE);
> > ids = &rec->id;
> > id_lens = &rec->id_len;
> > desc_lens = &rec->desc_len;
> > descs = (SQLCHAR *) (((char *) rec) + sizeof(Record));
> > }
> > #define REC(f,n) (((char*)f)+rec_size*(n))
> > -#define DESCS(n) (rec ? (SQLCHAR*)REC(descs,n): (descs+(n)*desc_len))
> > -#define IDS(n) *(rec ? (SQLUINTEGER*)REC(ids,n) : &ids[n])
> > -#define ID_LENS(n) *(rec ? (SQLLEN*)REC(id_lens,n) : &id_lens[n])
> > -#define DESC_LENS(n) *(rec ? (SQLLEN*)REC(desc_lens,n) : &desc_lens[n])
> > +#define DESCS(n) (rec ? (SQLCHAR*)REC(descs,n): (descs+(n)*dlen))
> > +#define IDS(n) (rec ? (SQLUINTEGER*)REC(ids,n) : &ids[n])
> > +#define ID_LENS(n) (rec ? (SQLLEN*)REC(id_lens,n) : &id_lens[n])
> > +#define DESC_LENS(n) (rec ? (SQLLEN*)REC(desc_lens,n) : &desc_lens[n])
> >
> > processed = ARRAY_SIZE + 1;
> > for (i = 0; i < ARRAY_SIZE; i++) {
> > statuses[i] = SQL_ROW_UPDATED;
> > - IDS(i) = i * 132;
> > + id = i * 132;
> > + memcpy(IDS(i), &id, sizeof(id));
> > sprintf((char *) DESCS(i), "aaa");
> > - ID_LENS(i) = 0;
> > - DESC_LENS(i) = -i;
> > + id_len = 0;
> > + memcpy(ID_LENS(i), &id_len, sizeof(id_len));
> > + desc_len = -i;
> > + memcpy(DESC_LENS(i), &desc_len, sizeof(desc_len));
> > }
> >
> > - SQLBindCol(Statement, 1, SQL_C_ULONG, &IDS(0), 0, &ID_LENS(0));
> > - SQLBindCol(Statement, 2, SQL_C_CHAR, DESCS(0), desc_len,
> > &DESC_LENS(0));
> > + SQLBindCol(Statement, 1, SQL_C_ULONG, IDS(0), 0, ID_LENS(0));
> > + SQLBindCol(Statement, 2, SQL_C_CHAR, DESCS(0), dlen,
> > DESC_LENS(0));
> >
> > CHKExecDirect((SQLCHAR *) test_query, SQL_NTS, "S");
> >
> > @@ -85,8 +87,9 @@
> > sprintf(buf, "%crow number %d", 'a' + i, i * 13);
> > if (trunc)
> > buf[3] = 0;
> > - if (IDS(i) != i + 1 || strcmp((char *) DESCS(i), buf) !=
> > 0)
> > {
> > - fprintf(stderr, "Invalid result\n\tgot
> > '%d|%s'\n\texpected '%d|%s'\n", (int) IDS(i), DESCS(i), i + 1, buf);
> > + memcpy(&id, IDS(i), sizeof(id));
> > + if (id != i + 1 || strcmp((char *) DESCS(i), buf) != 0) {
> > + fprintf(stderr, "Invalid result\n\tgot
> > '%d|%s'\n\texpected '%d|%s'\n", (int) id, DESCS(i), i + 1, buf);
> > exit(1);
> > }
> >
> > _______________________________________________
> > FreeTDS mailing list
> > FreeTDS AT lists.ibiblio.org
> > http://lists.ibiblio.org/mailman/listinfo/freetds
> >
> _______________________________________________
> FreeTDS mailing list
> FreeTDS AT lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds




Archive powered by MHonArc 2.6.24.

Top of Page