Fixed the mingw build by adding compatibility code for vsnprintf()

PiperOrigin-RevId: 448611947
pull/13171/head
Joshua Haberman 3 years ago committed by Copybara-Service
parent 555e7a6d57
commit a60e9a379e
  1. 3
      BUILD
  2. 2
      bazel/workspace_deps.bzl
  3. 5
      python/pb_unit_tests/well_known_types_test_wrapper.py
  4. 52
      upb/internal/vsnprintf_compat.h
  5. 3
      upb/json_encode.c
  6. 3
      upb/text_encode.c
  7. 3
      upb/util/def_to_proto.c
  8. 3
      upb/util/required_fields.c

@ -83,6 +83,9 @@ upb_proto_library_copts(
cc_library(
name = "port",
hdrs = [
"upb/internal/vsnprintf_compat.h",
],
copts = UPB_DEFAULT_COPTS,
textual_hdrs = [
"upb/port_def.inc",

@ -24,7 +24,7 @@ def upb_deps():
_github_archive,
name = "com_google_protobuf",
repo = "https://github.com/protocolbuffers/protobuf",
commit = "b180b2809f7e77fdf7dd075d26a7421085bac58f",
commit = "14803e6f63d4785ecd95adeeae3ac42a728b3857",
patches = ["//bazel:protobuf.patch"],
)

@ -27,10 +27,5 @@ from google.protobuf.internal.well_known_types_test import *
import os
import unittest
if os.name == 'nt':
# TODO(b/231335093): This currently trigggers an assertion failure on Windows
# for unknown reasons.
StructTest.__unittest_skip__ = True
if __name__ == '__main__':
unittest.main(verbosity=2)

@ -0,0 +1,52 @@
/*
* Copyright (c) 2009-2021, Google LLC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Google LLC nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UPB_INTERNAL_VSNPRINTF_COMPAT_H_
#define UPB_INTERNAL_VSNPRINTF_COMPAT_H_
#include <stdio.h>
// Must be last.
#include "upb/port_def.inc"
UPB_INLINE int _upb_vsnprintf(char* buf, size_t size, const char* fmt,
va_list ap) {
#if defined(__MINGW64__) || defined(__MINGW32__) || defined(_MSC_VER)
// The msvc runtime has a non-conforming vsnprintf() that requires the
// following compatibility code to become conformant.
int n = -1;
if (size != 0) n = _vsnprintf_s(buf, size, _TRUNCATE, fmt, ap);
if (n == -1) n = _vscprintf(fmt, ap);
return n;
#else
return vsnprintf(buf, size, fmt, ap);
#endif
}
#include "upb/port_undef.inc"
#endif // UPB_INTERNAL_VSNPRINTF_COMPAT_H_

@ -37,6 +37,7 @@
#include <string.h>
#include "upb/decode.h"
#include "upb/internal/vsnprintf_compat.h"
#include "upb/reflection.h"
#include "upb/upb_internal.h"
@ -112,7 +113,7 @@ static void jsonenc_printf(jsonenc* e, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
n = vsnprintf(e->ptr, have, fmt, args);
n = _upb_vsnprintf(e->ptr, have, fmt, args);
va_end(args);
if (UPB_LIKELY(have > n)) {

@ -34,6 +34,7 @@
#include <stdio.h>
#include <string.h>
#include "upb/internal/vsnprintf_compat.h"
#include "upb/reflection.h"
#include "upb/upb_internal.h"
@ -76,7 +77,7 @@ static void txtenc_printf(txtenc* e, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
n = vsnprintf(e->ptr, have, fmt, args);
n = _upb_vsnprintf(e->ptr, have, fmt, args);
va_end(args);
if (UPB_LIKELY(have > n)) {

@ -32,6 +32,7 @@
#include <setjmp.h>
#include <stdio.h>
#include "upb/internal/vsnprintf_compat.h"
#include "upb/reflection.h"
/* Must be last. */
@ -89,7 +90,7 @@ static upb_StringView printf_dup(upb_ToProto_Context* ctx, const char* fmt,
CHK_OOM(p);
va_list args;
va_start(args, fmt);
size_t n = vsnprintf(p, max, fmt, args);
size_t n = _upb_vsnprintf(p, max, fmt, args);
va_end(args);
UPB_ASSERT(n < max);
return (upb_StringView){.data = p, .size = n};

@ -32,6 +32,7 @@
#include <stdarg.h>
#include <stdio.h>
#include "upb/internal/vsnprintf_compat.h"
#include "upb/reflection.h"
// Must be last.
@ -55,7 +56,7 @@ static void upb_FieldPath_Printf(upb_PrintfAppender* a, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
n = vsnprintf(a->ptr, have, fmt, args);
n = _upb_vsnprintf(a->ptr, have, fmt, args);
va_end(args);
if (UPB_LIKELY(have > n)) {

Loading…
Cancel
Save