[Lldb-commits] [PATCH] D12206: Inline fake snprintf to avoid linkage issues on Windows.
Zachary Turner via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 20 12:41:06 PDT 2015
looks good, can you add a comment to explain why it's inlined though.
On Thu, Aug 20, 2015 at 12:14 PM Chaoren Lin <chaorenl at google.com> wrote:
> chaoren created this revision.
> chaoren added a reviewer: zturner.
> chaoren added a subscriber: lldb-commits.
>
> dllexport doesn't work if linking against a static library with its own
> copy of snprintf.
>
> http://reviews.llvm.org/D12206
>
> Files:
> include/lldb/Host/windows/win32.h
> source/Host/windows/Windows.cpp
>
> Index: source/Host/windows/Windows.cpp
> ===================================================================
> --- source/Host/windows/Windows.cpp
> +++ source/Host/windows/Windows.cpp
> @@ -203,18 +203,17 @@
> }
>
> #if _MSC_VER < 1900
> -int snprintf(char *buffer, size_t count, const char *format, ...)
> +namespace lldb_private {
> +int vsnprintf(char *buffer, size_t count, const char *format, va_list
> argptr)
> {
> int old_errno = errno;
> - va_list argptr;
> - va_start(argptr, format);
> - int r = vsnprintf(buffer, count, format, argptr);
> + int r = ::vsnprintf(buffer, count, format, argptr);
> int new_errno = errno;
> buffer[count-1] = '\0';
> if (r == -1 || r == count)
> {
> FILE *nul = fopen("nul", "w");
> - int bytes_written = vfprintf(nul, format, argptr);
> + int bytes_written = ::vfprintf(nul, format, argptr);
> fclose(nul);
> if (bytes_written < count)
> errno = new_errno;
> @@ -224,9 +223,9 @@
> r = bytes_written;
> }
> }
> - va_end(argptr);
> return r;
> }
> +} // namespace lldb_private
> #endif
>
> #endif // _MSC_VER
> Index: include/lldb/Host/windows/win32.h
> ===================================================================
> --- include/lldb/Host/windows/win32.h
> +++ include/lldb/Host/windows/win32.h
> @@ -65,8 +65,18 @@
> int strncasecmp(const char* s1, const char* s2, size_t n);
>
> #if _MSC_VER < 1900
> -int __declspec(dllexport)
> -snprintf(char *buffer, size_t count, const char *format, ...);
> +namespace lldb_private {
> +int vsnprintf(char *buffer, size_t count, const char *format, va_list
> argptr);
> +}
> +
> +int inline snprintf(char *buffer, size_t count, const char *format, ...)
> +{
> + va_list argptr;
> + va_start(argptr, format);
> + int r = lldb_private::vsnprintf(buffer, count, format, argptr);
> + va_end(argptr);
> + return r;
> +}
> #endif
>
> #define STDIN_FILENO 0
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150820/29ca640d/attachment.html>
More information about the lldb-commits
mailing list