[PATCH] D32147: [PR32479] Avoid newlib vasprintf, since it requires gnu extensions
Ben Craig via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 17 18:28:38 PDT 2017
bcraig updated this revision to Diff 95520.
bcraig added reviewers: jyknight, mclow.lists, EricWF.
bcraig added a subscriber: cfe-commits.
https://reviews.llvm.org/D32147
Files:
include/__bsd_locale_fallbacks.h
include/__config
Index: include/__config
===================================================================
--- include/__config
+++ include/__config
@@ -871,6 +871,10 @@
#endif
#endif
+#if defined(_NEWLIB_VERSION)
+#define _LIBCPP_HAS_NO_ASPRINTF 1
+#endif
+
#ifdef __FreeBSD__
#define _DECLARE_C99_LDBL_MATH 1
#endif
Index: include/__bsd_locale_fallbacks.h
===================================================================
--- include/__bsd_locale_fallbacks.h
+++ include/__bsd_locale_fallbacks.h
@@ -118,7 +118,26 @@
va_list __va;
va_start(__va, __format);
__locale_raii __current( uselocale(__l), uselocale );
+#if _LIBCPP_HAS_NO_ASPRINTF
+ va_list __va2;
+ va_copy(__va2, __va);
+ int __res = vsnprintf(0, 0, __format, __va2);
+ va_end(__va2);
+ if(__res < 0)
+ {
+ va_end(__va);
+ return __res;
+ }
+ *__s = (char *)malloc(__res+1);
+ if(*__s == 0)
+ {
+ va_end(__va);
+ return -1;
+ }
+ vsnprintf(*__s, __res+1, __format, __va);
+#else
int __res = vasprintf(__s, __format, __va);
+#endif
va_end(__va);
return __res;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32147.95520.patch
Type: text/x-patch
Size: 1113 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170418/85bf639d/attachment.bin>
More information about the cfe-commits
mailing list