Files
sdk/runtime/bin/ffi_test/ffi_test_fields.h
Simon Binder f2329a703f [vm/ffi] Fix field tests on Windows
Fields used in Dart test with `@Native` fields must be `extern "C"` to
avoid name mangling.
As seen from build and test failures, MSVC doesn't seem to consistently
use C fields for `extern "C"` fields defined in a C++ file.
By moving these fields into a C file, they can be referenced both from
the other C++ test functions and via Dart fields.

TEST=Windows CI build

Cq-Include-Trybots: luci.dart.try:vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-aot-win-debug-x64c-try
Change-Id: Ia504a1d6e04efd00bdd50de54f4b65292ec7a41a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342260
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Hossein Yousefi <yousefi@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2023-12-18 16:55:01 +00:00

37 lines
1023 B
C

// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef RUNTIME_BIN_FFI_TEST_FFI_TEST_FIELDS_H_
#define RUNTIME_BIN_FFI_TEST_FFI_TEST_FIELDS_H_
#include <stdint.h>
#if defined(_WIN32)
#define DART_EXPORT_FIELD __declspec(dllexport)
#else
#define DART_EXPORT_FIELD __attribute__((visibility("default")))
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct Coord {
double x;
double y;
struct Coord* next;
};
// These fields and structs are being accessed by @Native Dart variables in
// tests, so they must be defined with C linkage to avoid name mangling.
// MSVC doesn't seem to like extern "C" fields in C++ files, so the files are
// moved into a separate C file.
extern DART_EXPORT_FIELD int32_t globalInt;
extern DART_EXPORT_FIELD struct Coord globalStruct;
#ifdef __cplusplus
}
#endif
#endif // RUNTIME_BIN_FFI_TEST_FFI_TEST_FIELDS_H_