Skip to Content.
Sympa Menu

freetds - RE: asprintf vasprintf

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Castellano, Nicholas" <Nicholas_Castellano AT acml.com>
  • To: "'TDS Development Group'" <freetds AT franklin.metalab.unc.edu>
  • Subject: RE: asprintf vasprintf
  • Date: Thu, 29 Aug 2002 10:23:44 -0400

I don't like that implementation. It tries to reinvent the wheel, and won't
behave quite the same as the native stdio calls on any given platform. In
particular, its handling of floating point numbers makes me really nervous.

Here is my new patch. It's kind of a cheap trick but it gets the job done.
If you're really worried about complexity, we could use this new approach to
replace the non-threadsafe version too.

It could be made slightly more efficient and robust by not opening and
closing the filehandle each time. I'm not going to worry about that right
now, until there's a consensus that this is the way to go (there's no point
in putting more effort into this if somebody decides to use Powell's version
despite my concerns). If this change is accepted and committed, then I'll
go ahead with that.

--nick

-----Original Message-----
From: bounce-freetds-145195 AT franklin.oit.unc.edu
[mailto:bounce-freetds-145195 AT franklin.oit.unc.edu]
Sent: Thursday, August 29, 2002 10:05 AM
To: TDS Development Group
Subject: [freetds] RE: asprintf vasprintf


>
> There just doesn't seem to be any way to safely change the
> signal handler on
> the fly in a library function like this, without potentially causing
> undesired behavior in another thread. In particular, all
> pthread calls are
> off-limits in signal handlers, which makes it virtually
> impossible to do
> anything about this.
>
> I've decided to take another approach and provide a
> completely different
> implementation of vasprintf() that will be used when thread safety is
> enabled. Stay tuned for another patch later today.
>

I think we should use Patrick Powell implementation of snprintf/vsnprintf.
I tought about using pthread keys and other pthread stuff but other problem
raise (portability, complexity).

freddy77

=================================
"STRICTLY PERSONAL AND CONFIDENTIAL

This message may contain confidential and proprietary material for the sole
use of the intended recipient. Any review or distribution by others is
strictly prohibited. If you are not the intended recipient please contact
the sender and delete all copies.
The contents of this message that do not relate to the official business of
our company shall be understood as neither given nor endorsed by it."

=================================

---
You are currently subscribed to freetds as: [Nicholas_Castellano AT acml.com]
To unsubscribe, forward this message to
$subst('Email.Unsub')


The information contained in this transmission may contain privileged and
confidential information and is intended only for the use of the person(s)
named above. If you are not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient, any
review, dissemination, distribution or duplication of this communication is
strictly prohibited. If you are not the intended recipient, please contact
the sender immediately by reply e-mail and destroy all copies of the
original message. Please note that for certain accounts we do not accept
orders and/or instructions by e-mail, and for those accounts we will not be
responsible for carrying out such orders and/or instructions. Kindly refrain
from sending orders or instructions by e-mail unless you have confirmed that
we accept such communications for your account. Please also note that to
satisfy regulatory requirements we review the outgoing and incoming e-mail
correspondence of staff members serving certain functions.




Index: asprintf.c
===================================================================
RCS file: /cvsroot/freetds/freetds/src/tds/asprintf.c,v
retrieving revision 1.2
diff -u -r1.2 asprintf.c
--- asprintf.c 23 Aug 2002 13:10:15 -0000 1.2
+++ asprintf.c 29 Aug 2002 14:19:08 -0000
@@ -13,15 +13,19 @@
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
+#include <string.h>
+#ifndef _REENTRANT
#include <sys/mman.h>
#include <setjmp.h>
#include <signal.h>
#include <assert.h>
-#include <string.h>
+#endif

static char software_version[] = "$Id: asprintf.c,v 1.2 2002/08/23
13:10:15 freddy77 Exp $";
static void *no_unused_var_warn[] = {software_version,
no_unused_var_warn};
+
+#ifndef _REENTRANT
static jmp_buf env;

static void
@@ -29,10 +33,37 @@
{
longjmp(env, 1);
}
+#endif

int
vasprintf(char **ret, const char *fmt, va_list ap)
{
+#ifdef _REENTRANT
+ FILE *fp;
+ int len;
+ char *buf;
+
+ if ((fp = fopen("/dev/null", "w")) == NULL) {
+ *ret = NULL;
+ return -1;
+ }
+ len = vfprintf(fp, fmt, ap);
+ if (fclose(fp) != 0) {
+ *ret = NULL;
+ return -1;
+ }
+ if (len < 0) {
+ *ret = NULL;
+ return len;
+ }
+ if ((buf = malloc(len + 1)) == NULL) {
+ *ret = NULL;
+ return -1;
+ }
+ vsprintf(buf, fmt, ap);
+ *ret = buf;
+ return len;
+#else
volatile char *buf = NULL;
volatile unsigned int pgs;
struct sigaction sa, osa;
@@ -81,6 +112,7 @@
}
*ret = (char *) buf;
return len;
+#endif
}

int



Archive powered by MHonArc 2.6.24.

Top of Page