Skip to content

Commit

Permalink
Merge branch 'master' into feature/python-enum-typed
Browse files Browse the repository at this point in the history
  • Loading branch information
fliiiix authored Apr 29, 2024
2 parents dfd66a6 + 7106d86 commit d64ce3c
Show file tree
Hide file tree
Showing 31 changed files with 434 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .bazelignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
node_modules
ts/node_modules
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# We cannot use "common" here because the "version" command doesn't support
# --deleted_packages. We need to specify it for both build and query instead.
build --deleted_packages=tests/ts/bazel_repository_test_dir
query --deleted_packages=tests/ts/bazel_repository_test_dir
build --deleted_packages=tests/bazel_repository_test_dir,tests/ts/bazel_repository_test_dir
query --deleted_packages=tests/bazel_repository_test_dir,tests/ts/bazel_repository_test_dir
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,32 @@ jobs:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}

publish-maven-kotlin:
name: Publish Maven - Kotlin
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./kotlin
steps:
- uses: actions/checkout@v3

- name: Set up Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
cache: 'maven'
server-id: ossrh
server-username: OSSRH_USERNAME
server-password: OSSRH_PASSWORD
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE # this needs to be an env var

- name: Publish Kotlin Library on Maven
run: ./gradlew publishAllPublicationsToSonatypeRepository
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}

13 changes: 4 additions & 9 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")

licenses(["notice"])
Expand All @@ -8,13 +6,6 @@ package(
default_visibility = ["//visibility:public"],
)

npm_link_all_packages(name = "node_modules")

npm_link_package(
name = "node_modules/flatbuffers",
src = "//ts:flatbuffers",
)

exports_files([
"LICENSE",
"tsconfig.json",
Expand All @@ -37,9 +28,13 @@ config_setting(
filegroup(
name = "distribution",
srcs = [
".bazelignore",
".npmrc",
"BUILD.bazel",
"WORKSPACE",
"build_defs.bzl",
"package.json",
"pnpm-lock.yaml",
"typescript.bzl",
"//grpc/src/compiler:distribution",
"//reflection:distribution",
Expand Down
31 changes: 21 additions & 10 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ http_archive(
],
)

# Import our own version of skylib before other rule sets (e.g. rules_swift)
# has a chance to import an old version.
http_archive(
name = "bazel_skylib",
sha256 = "66ffd9315665bfaafc96b52278f57c7e2dd09f5ede279ea6d39b2be471e7e3aa",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz",
],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

http_archive(
name = "build_bazel_rules_apple",
sha256 = "34c41bfb59cdaea29ac2df5a2fa79e5add609c71bb303b2ebb10985f93fa20e7",
Expand Down Expand Up @@ -101,7 +116,7 @@ load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock", "pnpm_repository")
load("@aspect_rules_js//npm:npm_import.bzl", "pnpm_repository")

pnpm_repository(name = "pnpm")

Expand Down Expand Up @@ -129,17 +144,13 @@ nodejs_register_toolchains(
node_version = DEFAULT_NODE_VERSION,
)

npm_translate_lock(
name = "npm",
npmrc = "//:.npmrc",
pnpm_lock = "//:pnpm-lock.yaml",
# Set this to True when the lock file needs to be updated, commit the
# changes, then set to False again.
update_pnpm_lock = False,
verify_node_modules_ignored = "//:.bazelignore",
load("@com_github_google_flatbuffers//ts:repositories.bzl", "flatbuffers_npm")

flatbuffers_npm(
name = "flatbuffers_npm",
)

load("@npm//:repositories.bzl", "npm_repositories")
load("@flatbuffers_npm//:repositories.bzl", "npm_repositories")

npm_repositories()

Expand Down
12 changes: 7 additions & 5 deletions include/flatbuffers/flatbuffer_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ inline voffset_t FieldIndexToOffset(voffset_t field_id) {
2 * sizeof(voffset_t); // Vtable size and Object Size.
size_t offset = fixed_fields + field_id * sizeof(voffset_t);
FLATBUFFERS_ASSERT(offset < std::numeric_limits<voffset_t>::max());
return static_cast<voffset_t>(offset);}
return static_cast<voffset_t>(offset);
}

template<typename T, typename Alloc = std::allocator<T>>
const T *data(const std::vector<T, Alloc> &v) {
Expand Down Expand Up @@ -241,7 +242,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
/// called.
uint8_t *ReleaseRaw(size_t &size, size_t &offset) {
Finished();
uint8_t* raw = buf_.release_raw(size, offset);
uint8_t *raw = buf_.release_raw(size, offset);
Clear();
return raw;
}
Expand Down Expand Up @@ -561,7 +562,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
return CreateString<OffsetT>(str.c_str(), str.length());
}

// clang-format off
// clang-format off
#ifdef FLATBUFFERS_HAS_STRING_VIEW
/// @brief Store a string in the buffer, which can contain any binary data.
/// @param[in] str A const string_view to copy in to the buffer.
Expand Down Expand Up @@ -743,7 +744,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
AssertScalarT<T>();
StartVector<T, OffsetT, LenT>(len);
if (len > 0) {
// clang-format off
// clang-format off
#if FLATBUFFERS_LITTLEENDIAN
PushBytes(reinterpret_cast<const uint8_t *>(v), len * sizeof(T));
#else
Expand Down Expand Up @@ -1470,7 +1471,8 @@ T *GetMutableTemporaryPointer(FlatBufferBuilder &fbb, Offset<T> offset) {

template<typename T>
const T *GetTemporaryPointer(const FlatBufferBuilder &fbb, Offset<T> offset) {
return GetMutableTemporaryPointer<T>(fbb, offset);
return reinterpret_cast<const T *>(fbb.GetCurrentBufferPointer() +
fbb.GetSize() - offset.o);
}

} // namespace flatbuffers
Expand Down
108 changes: 70 additions & 38 deletions include/flatbuffers/verifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
namespace flatbuffers {

// Helper class to verify the integrity of a FlatBuffer
class Verifier FLATBUFFERS_FINAL_CLASS {
template <bool TrackVerifierBufferSize>
class VerifierTemplate FLATBUFFERS_FINAL_CLASS {
public:
struct Options {
// The maximum nesting of tables and vectors before we call it invalid.
Expand All @@ -40,17 +41,18 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
bool assert = false;
};

explicit Verifier(const uint8_t *const buf, const size_t buf_len,
const Options &opts)
explicit VerifierTemplate(const uint8_t *const buf, const size_t buf_len,
const Options &opts)
: buf_(buf), size_(buf_len), opts_(opts) {
FLATBUFFERS_ASSERT(size_ < opts.max_size);
}

// Deprecated API, please construct with Verifier::Options.
Verifier(const uint8_t *const buf, const size_t buf_len,
const uoffset_t max_depth = 64, const uoffset_t max_tables = 1000000,
const bool check_alignment = true)
: Verifier(buf, buf_len, [&] {
// Deprecated API, please construct with VerifierTemplate::Options.
VerifierTemplate(const uint8_t *const buf, const size_t buf_len,
const uoffset_t max_depth = 64,
const uoffset_t max_tables = 1000000,
const bool check_alignment = true)
: VerifierTemplate(buf, buf_len, [&] {
Options opts;
opts.max_depth = max_depth;
opts.max_tables = max_tables;
Expand All @@ -62,25 +64,25 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
bool Check(const bool ok) const {
// clang-format off
#ifdef FLATBUFFERS_DEBUG_VERIFICATION_FAILURE
if (opts_.assert) { FLATBUFFERS_ASSERT(ok); }
#endif
#ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
if (!ok)
upper_bound_ = 0;
if (opts_.assert) { FLATBUFFERS_ASSERT(ok); }
#endif
// clang-format on
if (TrackVerifierBufferSize) {
if (!ok) {
upper_bound_ = 0;
}
}
return ok;
}

// Verify any range within the buffer.
bool Verify(const size_t elem, const size_t elem_len) const {
// clang-format off
#ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
if (TrackVerifierBufferSize) {
auto upper_bound = elem + elem_len;
if (upper_bound_ < upper_bound)
if (upper_bound_ < upper_bound) {
upper_bound_ = upper_bound;
#endif
// clang-format on
}
}
return Check(elem_len < size_ && elem <= size_ - elem_len);
}

Expand Down Expand Up @@ -210,14 +212,14 @@ class Verifier FLATBUFFERS_FINAL_CLASS {

// Call T::Verify, which must be in the generated code for this type.
const auto o = VerifyOffset<uoffset_t>(start);
return Check(o != 0) &&
reinterpret_cast<const T *>(buf_ + start + o)->Verify(*this)
// clang-format off
#ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
&& GetComputedSize()
#endif
;
// clang-format on
if (!Check(o != 0)) return false;
if (!(reinterpret_cast<const T *>(buf_ + start + o)->Verify(*this))) {
return false;
}
if (TrackVerifierBufferSize) {
if (GetComputedSize() == 0) return false;
}
return true;
}

template<typename T, int &..., typename SizeT>
Expand All @@ -232,7 +234,8 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
// If there is a nested buffer, it must be greater than the min size.
if (!Check(buf->size() >= FLATBUFFERS_MIN_BUFFER_SIZE)) return false;

Verifier nested_verifier(buf->data(), buf->size(), opts_);
VerifierTemplate<TrackVerifierBufferSize> nested_verifier(
buf->data(), buf->size(), opts_);
return nested_verifier.VerifyBuffer<T>(identifier);
}

Expand Down Expand Up @@ -286,21 +289,27 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
return true;
}

// Returns the message size in bytes
// Returns the message size in bytes.
//
// This should only be called after first calling VerifyBuffer or
// VerifySizePrefixedBuffer.
//
// This method should only be called for VerifierTemplate instances
// where the TrackVerifierBufferSize template parameter is true,
// i.e. for SizeVerifier. For instances where TrackVerifierBufferSize
// is false, this fails at runtime or returns zero.
size_t GetComputedSize() const {
// clang-format off
#ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
if (TrackVerifierBufferSize) {
uintptr_t size = upper_bound_;
// Align the size to uoffset_t
size = (size - 1 + sizeof(uoffset_t)) & ~(sizeof(uoffset_t) - 1);
return (size > size_) ? 0 : size;
#else
// Must turn on FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE for this to work.
(void)upper_bound_;
FLATBUFFERS_ASSERT(false);
return 0;
#endif
// clang-format on
}
// Must use SizeVerifier, or (deprecated) turn on
// FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE, for this to work.
(void)upper_bound_;
FLATBUFFERS_ASSERT(false);
return 0;
}

std::vector<uint8_t> *GetFlexReuseTracker() { return flex_reuse_tracker_; }
Expand All @@ -323,10 +332,33 @@ class Verifier FLATBUFFERS_FINAL_CLASS {

// Specialization for 64-bit offsets.
template<>
inline size_t Verifier::VerifyOffset<uoffset64_t>(const size_t start) const {
template<>
inline size_t VerifierTemplate<false>::VerifyOffset<uoffset64_t>(
const size_t start) const {
return VerifyOffset<uoffset64_t, soffset64_t>(start);
}
template<>
template<>
inline size_t VerifierTemplate<true>::VerifyOffset<uoffset64_t>(
const size_t start) const {
return VerifyOffset<uoffset64_t, soffset64_t>(start);
}

// Instance of VerifierTemplate that supports GetComputedSize().
using SizeVerifier = VerifierTemplate</*TrackVerifierBufferSize = */ true>;

// The FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE build configuration macro is
// deprecated, and should not be defined, since it is easy to misuse in ways
// that result in ODR violations. Rather than using Verifier and defining
// FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE, please use SizeVerifier instead.
#ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE // Deprecated, see above.
using Verifier = SizeVerifier;
#else
// Instance of VerifierTemplate that is slightly faster, but does not
// support GetComputedSize().
using Verifier = VerifierTemplate</*TrackVerifierBufferSize = */ false>;
#endif

} // namespace flatbuffers

#endif // FLATBUFFERS_VERIFIER_H_
7 changes: 7 additions & 0 deletions kotlin/convention-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}

repositories {
gradlePluginPortal()
}
Loading

0 comments on commit d64ce3c

Please sign in to comment.