Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Commit

Permalink
Fix for talloc, in order to improve mesa shader compiler performance …
Browse files Browse the repository at this point in the history
…on windows from abysmal to merely poor. The vsnprintf() implementation in MSVC's libc does not conform to C99, and returns -1 if the given buffer is too small to hold the given format. Passing it NULL and a size of zero returns the number of chars required.

BUG=NONE
TEST=all GPU layout tests
R=kbr
Review URL: http://codereview.chromium.org/6711035

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78710 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
senorblanco@chromium.org committed Mar 18, 2011
1 parent 05a467a commit 4736e53
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
2 changes: 2 additions & 0 deletions third_party/talloc/README.chromium
Expand Up @@ -19,3 +19,5 @@ chromium.patch):
- An implementation of strnlen was provided for platforms not
supporting it (in particular, Mac OS X).
- A use of ssize_t was changed to size_t on Windows.
- a call to vsnprintf() querying the required buffer size was changed to use
ptr NULL size 0 in order to satisfy MSVC
44 changes: 38 additions & 6 deletions third_party/talloc/chromium.patch
@@ -1,6 +1,6 @@
diff -c -r talloc-2.0.1/talloc.c talloc/talloc.c
*** talloc-2.0.1/talloc.c Tue Dec 15 06:16:57 2009
--- talloc/talloc.c Mon Oct 25 13:58:42 2010
--- talloc/talloc.c Fri Mar 18 13:03:11 2011
***************
*** 30,36 ****
inspired by http://swapped.cc/halloc/
Expand Down Expand Up @@ -285,7 +285,30 @@ diff -c -r talloc-2.0.1/talloc.c talloc/talloc.c
{
char *ret;
***************
*** 1736,1749 ****
*** 1699,1709 ****
int len;
char *ret;
va_list ap2;
- char c;

- /* this call looks strange, but it makes it work on older solaris boxes */
va_copy(ap2, ap);
! len = vsnprintf(&c, 1, fmt, ap2);
va_end(ap2);
if (unlikely(len < 0)) {
return NULL;
--- 1722,1730 ----
int len;
char *ret;
va_list ap2;

va_copy(ap2, ap);
! len = vsnprintf(NULL, 0, fmt, ap2);
va_end(ap2);
if (unlikely(len < 0)) {
return NULL;
***************
*** 1736,1754 ****
return ret;
}

Expand All @@ -298,9 +321,14 @@ diff -c -r talloc-2.0.1/talloc.c talloc/talloc.c
{
ssize_t alen;
va_list ap2;
char c;
- char c;

--- 1759,1777 ----
va_copy(ap2, ap);
! alen = vsnprintf(&c, 1, fmt, ap2);
va_end(ap2);

if (alen <= 0) {
--- 1757,1779 ----
return ret;
}

Expand All @@ -318,11 +346,15 @@ diff -c -r talloc-2.0.1/talloc.c talloc/talloc.c
+ size_t alen;
+ #endif
va_list ap2;
char c;

va_copy(ap2, ap);
! alen = vsnprintf(NULL, 0, fmt, ap2);
va_end(ap2);

if (alen <= 0) {
diff -c -r talloc-2.0.1/talloc.h talloc/talloc.h
*** talloc-2.0.1/talloc.h Wed Oct 28 16:14:20 2009
--- talloc/talloc.h Mon Oct 25 15:11:18 2010
--- talloc/talloc.h Fri Mar 18 13:03:02 2011
***************
*** 28,33 ****
--- 28,37 ----
Expand Down
7 changes: 2 additions & 5 deletions third_party/talloc/talloc.c
Expand Up @@ -1722,11 +1722,9 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap)
int len;
char *ret;
va_list ap2;
char c;

/* this call looks strange, but it makes it work on older solaris boxes */
va_copy(ap2, ap);
len = vsnprintf(&c, 1, fmt, ap2);
len = vsnprintf(NULL, 0, fmt, ap2);
va_end(ap2);
if (unlikely(len < 0)) {
return NULL;
Expand Down Expand Up @@ -1773,10 +1771,9 @@ static INLINE char *__talloc_vaslenprintf_append(char *s, size_t slen,
size_t alen;
#endif
va_list ap2;
char c;

va_copy(ap2, ap);
alen = vsnprintf(&c, 1, fmt, ap2);
alen = vsnprintf(NULL, 0, fmt, ap2);
va_end(ap2);

if (alen <= 0) {
Expand Down

0 comments on commit 4736e53

Please sign in to comment.