protobuf/ruby/ext/google/protobuf_c/protobuf.h
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2014 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__
32 #define __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__
33 
34 #include <ruby/ruby.h>
35 #include <ruby/vm.h>
36 #include <ruby/encoding.h>
37 
38 #include "ruby-upb.h"
39 #include "defs.h"
40 
41 // These operate on a map field (i.e., a repeated field of submessages whose
42 // submessage type is a map-entry msgdef).
45 
46 // -----------------------------------------------------------------------------
47 // Arena
48 // -----------------------------------------------------------------------------
49 
50 // A Ruby object that wraps an underlying upb_arena. Any objects that are
51 // allocated from this arena should reference the Arena in rb_gc_mark(), to
52 // ensure that the object's underlying memory outlives any Ruby object that can
53 // reach it.
54 
55 VALUE Arena_new();
56 upb_arena *Arena_get(VALUE arena);
57 
58 // Fuses this arena to another, throwing a Ruby exception if this is not
59 // possible.
60 void Arena_fuse(VALUE arena, upb_arena *other);
61 
62 // Pins this Ruby object to the lifetime of this arena, so that as long as the
63 // arena is alive this object will not be collected.
64 //
65 // We use this to guarantee that the "frozen" bit on the object will be
66 // remembered, even if the user drops their reference to this precise object.
67 void Arena_Pin(VALUE arena, VALUE obj);
68 
69 // -----------------------------------------------------------------------------
70 // ObjectCache
71 // -----------------------------------------------------------------------------
72 
73 // Global object cache from upb array/map/message/symtab to wrapper object.
74 //
75 // This is a conceptually "weak" cache, in that it does not prevent "val" from
76 // being collected (though in Ruby <2.7 is it effectively strong, due to
77 // implementation limitations).
78 
79 // Adds an entry to the cache. The "arena" parameter must give the arena that
80 // "key" was allocated from. In Ruby <2.7.0, it will be used to remove the key
81 // from the cache when the arena is destroyed.
82 void ObjectCache_Add(const void* key, VALUE val);
83 
84 // Returns the cached object for this key, if any. Otherwise returns Qnil.
85 VALUE ObjectCache_Get(const void* key);
86 
87 // -----------------------------------------------------------------------------
88 // StringBuilder, for inspect
89 // -----------------------------------------------------------------------------
90 
91 struct StringBuilder;
93 
96 void StringBuilder_Printf(StringBuilder* b, const char *fmt, ...);
98 
100 
101 // -----------------------------------------------------------------------------
102 // Utilities.
103 // -----------------------------------------------------------------------------
104 
105 extern VALUE cTypeError;
106 
107 #ifdef NDEBUG
108 #define PBRUBY_ASSERT(expr) do {} while (false && (expr))
109 #else
110 #define PBRUBY_ASSERT(expr) assert(expr)
111 #endif
112 
113 #define PBRUBY_MAX(x, y) (((x) > (y)) ? (x) : (y))
114 
115 #define UPB_UNUSED(var) (void)var
116 
117 #endif // __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__
obj
OPENSSL_EXPORT const ASN1_OBJECT * obj
Definition: x509.h:1671
upb_arena
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:2252
StringBuilder
Definition: protobuf/ruby/ext/google/protobuf_c/protobuf.c:57
TypeInfo
Definition: protobuf/php/ext/google/protobuf/def.h:69
Arena_new
VALUE Arena_new()
Definition: protobuf/ruby/ext/google/protobuf_c/protobuf.c:217
arena
grpc_core::ScopedArenaPtr arena
Definition: binder_transport_test.cc:237
Arena_Pin
void Arena_Pin(VALUE arena, VALUE obj)
Definition: protobuf/ruby/ext/google/protobuf_c/protobuf.c:221
ruby-upb.h
StringBuilder_Free
void StringBuilder_Free(StringBuilder *b)
Definition: protobuf/ruby/ext/google/protobuf_c/protobuf.c:78
upb_fielddef
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:2934
ObjectCache_Get
VALUE ObjectCache_Get(const void *key)
Definition: protobuf/ruby/ext/google/protobuf_c/protobuf.c:397
b
uint64_t b
Definition: abseil-cpp/absl/container/internal/layout_test.cc:53
Arena_fuse
void Arena_fuse(VALUE arena, upb_arena *other)
Definition: protobuf/ruby/ext/google/protobuf_c/protobuf.c:207
testing::internal::fmt
GTEST_API_ const char * fmt
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1808
cTypeError
VALUE cTypeError
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.c:35
upb_msgval
Definition: php-upb.h:4612
field
const FieldDescriptor * field
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc:2692
key
const char * key
Definition: hpack_parser_table.cc:164
Arena_get
upb_arena * Arena_get(VALUE arena)
Definition: protobuf/ruby/ext/google/protobuf_c/protobuf.c:201
map_field_key
const upb_fielddef * map_field_key(const upb_fielddef *field)
Definition: php/ext/google/protobuf/storage.c:530
StringBuilder_Printf
void StringBuilder_Printf(StringBuilder *b, const char *fmt,...)
Definition: protobuf/ruby/ext/google/protobuf_c/protobuf.c:83
defs.h
map_field_value
const upb_fielddef * map_field_value(const upb_fielddef *field)
Definition: php/ext/google/protobuf/storage.c:535
StringBuilder_ToRubyString
VALUE StringBuilder_ToRubyString(StringBuilder *b)
Definition: protobuf/ruby/ext/google/protobuf_c/protobuf.c:107
StringBuilder_PrintMsgval
void StringBuilder_PrintMsgval(StringBuilder *b, upb_msgval val, TypeInfo info)
Definition: protobuf/ruby/ext/google/protobuf_c/protobuf.c:123
ObjectCache_Add
void ObjectCache_Add(const void *key, VALUE val)
Definition: protobuf/ruby/ext/google/protobuf_c/protobuf.c:383
StringBuilder_New
StringBuilder * StringBuilder_New()
Definition: protobuf/ruby/ext/google/protobuf_c/protobuf.c:69


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:47