|
|
|
# C style guide
|
|
|
|
|
|
|
|
<!--*
|
|
|
|
# Document freshness: For more information, see go/fresh-source.
|
|
|
|
freshness: { owner: 'haberman' reviewed: '2022-05-08' }
|
|
|
|
*-->
|
|
|
|
|
|
|
|
Since upb is written in pure C, we supplement the
|
|
|
|
[Google C++ style guide](https://google.github.io/styleguide/cppguide.html) with
|
|
|
|
some C-specific guidance.
|
|
|
|
|
|
|
|
Everything written here is intended to follow the spirit of the C++ style guide.
|
|
|
|
|
|
|
|
upb is currently inconsistent about following these conventions. It is intended
|
|
|
|
that all code will be updated to match these guidelines. The priority is
|
|
|
|
converting public interfaces as these are more difficult to change later.
|
|
|
|
|
|
|
|
## Naming
|
|
|
|
|
|
|
|
### Functions and Types
|
|
|
|
|
|
|
|
C does not have namespaces. Anywhere you would normally use a namespace
|
|
|
|
separator (`::`) in C++, we use an underscore (`_`) in C:
|
|
|
|
|
|
|
|
```c++
|
|
|
|
// C equivalent for upb::Arena::New()
|
|
|
|
upb_Arena* upb_Arena_New();
|
|
|
|
```
|
|
|
|
|
|
|
|
Since we rely on `_` to be our namespace separator, we never use it to merely
|
|
|
|
separate words in function or type names:
|
|
|
|
|
|
|
|
```c++
|
|
|
|
// BAD: this would be interpreted as upb::FieldDef::has::default().
|
|
|
|
bool upb_FieldDef_has_default(const upb_FieldDef* f);
|
|
|
|
|
|
|
|
// GOOD: this is equivalent to upb::FieldDef::HasDefault().
|
|
|
|
bool upb_FieldDef_HasDefault(const upb_FieldDef* f);
|
|
|
|
```
|
|
|
|
|
|
|
|
For multi-word namespaces, we use `PascalCase`:
|
|
|
|
|
|
|
|
```c++
|
|
|
|
// `PyUpb` is the namespace.
|
|
|
|
PyObject* PyUpb_CMessage_GetAttr(PyObject* _self, PyObject* attr);
|
|
|
|
```
|
|
|
|
|
|
|
|
### Private Functions and Members
|
|
|
|
|
|
|
|
Since we do not have `private` in C++, we use a leading underscore convention
|
|
|
|
to mark internal functions and variables that should only be accessed from
|
|
|
|
upb:
|
|
|
|
|
|
|
|
```c++
|
|
|
|
// Internal-only function.
|
|
|
|
int64_t _upb_Int64_FromLL();
|
|
|
|
|
|
|
|
// Internal-only members. Underscore prefixes are only necessary when the
|
|
|
|
// structure is defined in a header file.
|
|
|
|
typedef struct {
|
|
|
|
const int32_t* _values; // List of values <0 or >63
|
|
|
|
uint64_t _mask; // Bits are set for acceptable value 0 <= x < 64
|
|
|
|
int _value_count;
|
[protobuf] Upgrade third_party/protobuf to 22.x (#32606)
The very non-trivial upgrade of third_party/protobuf to 22.x
This PR strives to be as small as possible and many changes that were
compatible with protobuf 21.x and didn't have to be merged atomically
with the upgrade were already merged.
Due to the complexity of the upgrade, this PR wasn't created
automatically by a tool, but manually. Subsequent upgraded of
third_party/protobuf with our OSS release script should work again once
this change is merged.
This is best reviewed commit-by-commit, I tried to group changes in
logical areas.
Notable changes:
- the upgrade of third_party/protobuf submodule, the bazel protobuf
dependency itself
- upgrade of UPB dependency to 22.x (in the past, we used to always
upgrade upb to "main", but upb now has release branch as well). UPB
needs to be upgraded atomically with protobuf since there's a de-facto
circular dependency (new protobuf depends on new upb, which depends on
new protobuf for codegen).
- some protobuf and upb bazel rules are now aliases, so `
extract_metadata_from_bazel_xml.py` and `gen_upb_api_from_bazel_xml.py`
had to be modified to be able to follow aliases and reach the actual
aliased targets.
- some protobuf public headers were renamed, so especially
`src/compiler` needed to be updated to use the new headers.
- protobuf and upb now both depend on utf8_range project, so since we
bundle upb with grpc in some languages, we now have to bundle utf8_range
as well (hence changes in build for python, PHP, objC, cmake etc).
- protoc now depends on absl and utf8_range (previously protobuf had
absl dependency, but not for the codegen part), so python's
make_grpcio_tools.py required partial rewrite to be able to handle those
dependencies in the grpcio_tools build.
- many updates and fixes required for C++ distribtests (currently they
all pass, but we'll probably need to follow up, make protobuf's and
grpc's handling of dependencies more aligned and revisit the
distribtests)
- bunch of other changes mostly due to overhaul of protobuf's and upb's
internal build layout.
TODOs:
- [DONE] make sure IWYU and clang_tidy_code pass
- create a list of followups (e.g. work to reenable the few tests I had
to disable and to remove workaround I had to use)
- [DONE in cl/523706129] figure out problem(s) with internal import
---------
Co-authored-by: Craig Tiller <ctiller@google.com>
2 years ago
|
|
|
} upb_MiniTableEnum;
|
|
|
|
```
|