* smallprint.cc (tmpbuf): Declare new class holding a static buffer, protected

by a lock.
(__small_vsprintf): Use tmpbuf to hold large buffer.
(__small_vswprintf): Ditto.
This commit is contained in:
Christopher Faylor 2012-02-15 15:33:56 +00:00
parent 5eb802f8ed
commit a0f4e7d3f1
2 changed files with 40 additions and 3 deletions

View File

@ -1,3 +1,10 @@
2012-02-15 Christopher Faylor <me.cygwin2012@cgf.cx>
* smallprint.cc (tmpbuf): Declare new class holding a static buffer,
protected by a lock.
(__small_vsprintf): Use tmpbuf to hold large buffer.
(__small_vswprintf): Ditto.
2012-02-15 Corinna Vinschen <corinna@vinschen.de>
* flock.cc (lf_setlock): Add timeout variable and set before calling

View File

@ -1,6 +1,7 @@
/* smallprint.cc: small print routines for WIN32
Copyright 1996, 1998, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009
Copyright 1996, 1998, 2000, 2001, 2002, 2003, 2005, 2006,
2007, 2008, 2009, 2012
Red Hat, Inc.
This file is part of Cygwin.
@ -11,6 +12,7 @@ details. */
#include "winsup.h"
#include "ntdll.h"
#include "sync.h"
#include <stdlib.h>
#include <ctype.h>
#include <wchar.h>
@ -23,6 +25,34 @@ details. */
static const char hex_str[] = "0123456789ABCDEF";
class tmpbuf
{
static WCHAR buf[NT_MAX_PATH];
static muto lock;
bool locked;
public:
operator WCHAR * ()
{
if (!locked)
{
lock.init ("smallprint_buf")->acquire ();
locked = true;
}
return buf;
}
operator char * () {return (char *) ((WCHAR *) *this);}
tmpbuf (): locked (false) {};
~tmpbuf ()
{
if (locked)
lock.release ();
}
};
WCHAR tmpbuf::buf[NT_MAX_PATH];
muto tmpbuf::lock;
static char __fastcall *
__rn (char *dst, int base, int dosign, long long val, int len, int pad, unsigned long long mask)
{
@ -65,7 +95,7 @@ __rn (char *dst, int base, int dosign, long long val, int len, int pad, unsigned
int
__small_vsprintf (char *dst, const char *fmt, va_list ap)
{
char tmp[NT_MAX_PATH];
tmpbuf tmp;
char *orig = dst;
const char *s;
PWCHAR w;
@ -367,7 +397,7 @@ __wrn (PWCHAR dst, int base, int dosign, long long val, int len, int pad, unsign
int
__small_vswprintf (PWCHAR dst, const WCHAR *fmt, va_list ap)
{
WCHAR tmp[NT_MAX_PATH];
tmpbuf tmp;
PWCHAR orig = dst;
const char *s;
PWCHAR w;