From 491539ff32e10801b65ad534d58c7f84f5000197 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 4 Jun 2015 19:37:03 -0400 Subject: [PATCH] Fix MSVC++ compiler error, bug927. --- Changes | 2 ++ include/verilated_vpi.h | 2 +- include/verilatedos.h | 16 ++++++++++++++++ src/verilog.l | 2 +- test_regress/t/t_dist_portability.pl | 19 +++++++++++++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 589caeffd..dd5a60a93 100644 --- a/Changes +++ b/Changes @@ -23,6 +23,8 @@ indicates the contributor was also the author of the fix; Thanks! **** Fix width extension on mis-width ports, bug918. [Patrick Maupin] +**** Fix MSVC++ compiler error, bug927. [Hans Tichelaar] + * Verilator 3.872 2015-04-05 diff --git a/include/verilated_vpi.h b/include/verilated_vpi.h index 01ea91bc0..824df3e99 100644 --- a/include/verilated_vpi.h +++ b/include/verilated_vpi.h @@ -421,7 +421,7 @@ public: do { \ va_list args; \ va_start(args, message); \ - vsnprintf(m_buff, sizeof(m_buff), message.c_str(), args); \ + VL_VSNPRINTF(m_buff, sizeof(m_buff), message.c_str(), args); \ va_end(args); \ } while (0) diff --git a/include/verilatedos.h b/include/verilatedos.h index e0c55b78b..83f41be4c 100644 --- a/include/verilatedos.h +++ b/include/verilatedos.h @@ -207,6 +207,22 @@ typedef unsigned long long vluint64_t; ///< 64-bit unsigned type # endif #endif +#ifdef _WIN32 +# define VL_VSNPRINTF vl_vsnprintf +inline int vl_vsnprintf(char* str, size_t size, const char* format, va_list ap) { + int count = -1; + if (size != 0) { + count = _vsnprintf_s(str, size, _TRUNCATE, format, ap); + } + if (count == -1) { + count = _vscprintf(format, ap); + } + return count; +} +#else +# define VL_VSNPRINTF vsnprintf +#endif + //========================================================================= // File system functions diff --git a/src/verilog.l b/src/verilog.l index 32e92bb80..f2de1aad1 100644 --- a/src/verilog.l +++ b/src/verilog.l @@ -117,7 +117,7 @@ void yyerrorf(const char* format, ...) { va_list ap; va_start(ap,format); - vsnprintf(msg,maxlen,format,ap); + VL_VSNPRINTF(msg,maxlen,format,ap); msg[maxlen-1] = '\0'; va_end(ap); diff --git a/test_regress/t/t_dist_portability.pl b/test_regress/t/t_dist_portability.pl index 96913a4d9..13d5a3d9c 100755 --- a/test_regress/t/t_dist_portability.pl +++ b/test_regress/t/t_dist_portability.pl @@ -18,6 +18,7 @@ if (!-r "$root/.git") { uint(); printfll(); cstr(); + vsnprintf(); } ok(1); @@ -86,4 +87,22 @@ sub cstr { } } +sub vsnprintf { + my $files = "src/*.c* src/*.h include/*.c* include/*.h test_c/*.c* test_regress/t/*.c* test_regress/t/*.h"; + my $cmd = "cd $root && grep -n -P 'vsnprintf' $files | sort"; + print "C $cmd\n"; + my $grep = `$cmd`; + my %names; + foreach my $line (split /\n/, $grep) { + if ($line =~ /\b(vsnprintf)\b/) { + next if $line =~ /# *define\s*VL_VSNPRINTF/; + print "$line\n"; + $names{$1} = 1; + } + } + if (keys %names) { + $Self->error("Files with vsnprintf, use VL_VSNPRINTF: ",join(' ',sort keys %names)); + } +} + 1;