Formatted files with clang-format.

pull/13171/head
Joshua Haberman 4 years ago
parent 5d8c3db94f
commit eec1a45e02
  1. 2
      python/BUILD
  2. 211
      python/descriptor.c
  3. 21
      python/descriptor.h
  4. 5
      python/descriptor_pool.c
  5. 12
      python/descriptor_pool.h
  6. 17
      python/protobuf.h

@ -18,6 +18,8 @@ cc_binary(
# casts between function pointers and object pointers.
"-Wno-pedantic",
],
# We use a linker script to hide all symbols except the entry point for
# the module.
linkopts = ["-Wl,--version-script,$(location :version_script.lds)"],
linkshared = True,
linkstatic = True,

@ -13,11 +13,11 @@
* 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
* 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
@ -38,12 +38,12 @@
typedef struct {
PyObject_HEAD
PyObject *pool; // We own a ref.
PyObject *pool; // We own a ref.
const void *def; // Type depends on the class. Kept alive by "pool".
} PyUpb_DescriptorBase;
PyObject *PyUpb_AnyDescriptor_GetPool(PyObject *desc) {
PyUpb_DescriptorBase *base = (void*)desc;
PyUpb_DescriptorBase *base = (void *)desc;
return base->pool;
}
@ -56,7 +56,7 @@ static PyObject *PyUpb_DescriptorBase_New(PyTypeObject *subtype, PyObject *args,
static PyObject *PyUpb_DescriptorBase_NewInternal(PyTypeObject *type,
const void *def,
PyObject *pool) {
PyUpb_DescriptorBase *base = (PyUpb_DescriptorBase*)PyUpb_ObjCache_Get(def);
PyUpb_DescriptorBase *base = (PyUpb_DescriptorBase *)PyUpb_ObjCache_Get(def);
if (!base) {
base = PyObject_New(PyUpb_DescriptorBase, type);
@ -70,15 +70,15 @@ static PyObject *PyUpb_DescriptorBase_NewInternal(PyTypeObject *type,
}
static void PyUpb_DescriptorBase_Dealloc(PyUpb_DescriptorBase *self) {
PyUpb_DescriptorBase *base = (PyUpb_DescriptorBase*)self;
PyUpb_DescriptorBase *base = (PyUpb_DescriptorBase *)self;
PyUpb_ObjCache_Delete(base->def);
Py_CLEAR(base->pool);
PyObject_Del(self);
}
#define DESCRIPTOR_BASE_SLOTS \
{Py_tp_new, (void*)&PyUpb_DescriptorBase_New}, \
{Py_tp_dealloc, (void*)&PyUpb_DescriptorBase_Dealloc}
#define DESCRIPTOR_BASE_SLOTS \
{Py_tp_new, (void *)&PyUpb_DescriptorBase_New}, \
{Py_tp_dealloc, (void *)&PyUpb_DescriptorBase_Dealloc}
// -----------------------------------------------------------------------------
// FieldDescriptor
@ -90,74 +90,70 @@ static PyObject *PyUpb_FieldDescriptor_GetType(PyUpb_DescriptorBase *self,
}
static PyObject *PyUpb_FieldDescriptor_GetLabel(PyUpb_DescriptorBase *self,
void *closure) {
void *closure) {
return PyLong_FromLong(upb_fielddef_label(self->def));
}
static PyObject *PyUpb_FieldDescriptor_GetNumber(PyUpb_DescriptorBase *self,
void *closure) {
void *closure) {
return PyLong_FromLong(upb_fielddef_number(self->def));
}
static PyGetSetDef PyUpb_FieldDescriptor_Getters[] = {
/*
{ "full_name", (getter)GetFullName, NULL, "Full name"},
{ "name", (getter)GetName, NULL, "Unqualified name"},
{ "camelcase_name", (getter)GetCamelcaseName, NULL, "Camelcase name"},
{ "json_name", (getter)GetJsonName, NULL, "Json name"},
{ "file", (getter)GetFile, NULL, "File Descriptor"},
/*
{ "full_name", (getter)GetFullName, NULL, "Full name"},
{ "name", (getter)GetName, NULL, "Unqualified name"},
{ "camelcase_name", (getter)GetCamelcaseName, NULL, "Camelcase name"},
{ "json_name", (getter)GetJsonName, NULL, "Json name"},
{ "file", (getter)GetFile, NULL, "File Descriptor"},
*/
{"type", (getter)PyUpb_FieldDescriptor_GetType, NULL, "Type"},
/*
{ "cpp_type", (getter)PyUpb_FieldDescriptor_GetCppType, NULL, "C++ Type"},
*/
{"label", (getter)PyUpb_FieldDescriptor_GetLabel, NULL, "Label"},
{"number", (getter)PyUpb_FieldDescriptor_GetNumber, NULL, "Number"},
/*
{ "index", (getter)GetIndex, NULL, "Index"},
{ "default_value", (getter)GetDefaultValue, NULL, "Default Value"},
{ "has_default_value", (getter)HasDefaultValue},
{ "is_extension", (getter)IsExtension, NULL, "ID"},
{ "id", (getter)GetID, NULL, "ID"},
{ "_cdescriptor", (getter)GetCDescriptor, NULL, "HAACK REMOVE ME"},
{ "message_type", (getter)GetMessageType, (setter)SetMessageType,
"Message type"},
{ "enum_type", (getter)GetEnumType, (setter)SetEnumType, "Enum type"},
{ "containing_type", (getter)GetContainingType, (setter)SetContainingType,
"Containing type"},
{ "extension_scope", (getter)GetExtensionScope, (setter)NULL,
"Extension scope"},
{ "containing_oneof", (getter)GetContainingOneof,
(setter)SetContainingOneof, "Containing oneof"}, { "has_options",
(getter)GetHasOptions, (setter)SetHasOptions, "Has Options"}, { "_options",
(getter)NULL, (setter)SetOptions, "Options"}, { "_serialized_options",
(getter)NULL, (setter)SetSerializedOptions, "Serialized Options"},
*/
{ "type", (getter)PyUpb_FieldDescriptor_GetType, NULL, "Type"},
/*
{ "cpp_type", (getter)PyUpb_FieldDescriptor_GetCppType, NULL, "C++ Type"},
*/
{ "label", (getter)PyUpb_FieldDescriptor_GetLabel, NULL, "Label"},
{ "number", (getter)PyUpb_FieldDescriptor_GetNumber, NULL, "Number"},
/*
{ "index", (getter)GetIndex, NULL, "Index"},
{ "default_value", (getter)GetDefaultValue, NULL, "Default Value"},
{ "has_default_value", (getter)HasDefaultValue},
{ "is_extension", (getter)IsExtension, NULL, "ID"},
{ "id", (getter)GetID, NULL, "ID"},
{ "_cdescriptor", (getter)GetCDescriptor, NULL, "HAACK REMOVE ME"},
{ "message_type", (getter)GetMessageType, (setter)SetMessageType,
"Message type"},
{ "enum_type", (getter)GetEnumType, (setter)SetEnumType, "Enum type"},
{ "containing_type", (getter)GetContainingType, (setter)SetContainingType,
"Containing type"},
{ "extension_scope", (getter)GetExtensionScope, (setter)NULL,
"Extension scope"},
{ "containing_oneof", (getter)GetContainingOneof, (setter)SetContainingOneof,
"Containing oneof"},
{ "has_options", (getter)GetHasOptions, (setter)SetHasOptions, "Has Options"},
{ "_options", (getter)NULL, (setter)SetOptions, "Options"},
{ "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
"Serialized Options"},
*/
{NULL}
};
{NULL}};
static PyMethodDef PyUpb_FieldDescriptor_Methods[] = {
/*
{ "GetOptions", (PyCFunction)GetOptions, METH_NOARGS, },
*/
{NULL}
};
/*
{ "GetOptions", (PyCFunction)GetOptions, METH_NOARGS, },
*/
{NULL}};
static PyType_Slot PyUpb_FieldDescriptor_Slots[] = {
DESCRIPTOR_BASE_SLOTS,
{Py_tp_methods, PyUpb_FieldDescriptor_Methods},
{Py_tp_getset, PyUpb_FieldDescriptor_Getters},
{0, NULL}
};
DESCRIPTOR_BASE_SLOTS,
{Py_tp_methods, PyUpb_FieldDescriptor_Methods},
{Py_tp_getset, PyUpb_FieldDescriptor_Getters},
{0, NULL}};
static PyType_Spec PyUpb_FieldDescriptor_Spec = {
PYUPB_MODULE_NAME ".FieldDescriptor",
sizeof(PyUpb_DescriptorBase),
0, // tp_itemsize
Py_TPFLAGS_DEFAULT,
PyUpb_FieldDescriptor_Slots,
PYUPB_MODULE_NAME ".FieldDescriptor",
sizeof(PyUpb_DescriptorBase),
0, // tp_itemsize
Py_TPFLAGS_DEFAULT,
PyUpb_FieldDescriptor_Slots,
};
PyObject *PyUpb_FieldDescriptor_GetOrCreateWrapper(const upb_fielddef *field,
@ -176,54 +172,51 @@ static PyObject *PyUpb_FileDescriptor_GetName(PyUpb_DescriptorBase *self,
return PyUnicode_FromString(upb_filedef_name(self->def));
}
static PyGetSetDef PyUpb_FileDescriptor_Getters[] = {
/*
{ "pool", (getter)GetPool, NULL, "pool"},
*/
{ "name", (getter)PyUpb_FileDescriptor_GetName, NULL, "name"},
/*
{ "package", (getter)GetPackage, NULL, "package"},
{ "serialized_pb", (getter)GetSerializedPb},
{ "message_types_by_name", PyUpb_FileDescriptor_GetMessageTypesByName, NULL,
"Messages by name"},
{ "enum_types_by_name", PyUpb_FileDescriptor_GetEnumTypesByName, NULL,
"Enums by name"},
{ "extensions_by_name", (getter)GetExtensionsByName, NULL,
"Extensions by name"},
{ "services_by_name", (getter)GetServicesByName, NULL, "Services by name"},
{ "dependencies", (getter)GetDependencies, NULL, "Dependencies"},
{ "public_dependencies", (getter)GetPublicDependencies, NULL, "Dependencies"},
{ "has_options", (getter)GetHasOptions, (setter)SetHasOptions, "Has Options"},
{ "_options", (getter)NULL, (setter)SetOptions, "Options"},
{ "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
"Serialized Options"},
{ "syntax", (getter)GetSyntax, (setter)NULL, "Syntax"},
*/
{NULL}
};
static PyGetSetDef PyUpb_FileDescriptor_Getters[] =
{
/*
{ "pool", (getter)GetPool, NULL, "pool"},
*/
{"name", (getter)PyUpb_FileDescriptor_GetName, NULL, "name"},
/*
{ "package", (getter)GetPackage, NULL, "package"},
{ "serialized_pb", (getter)GetSerializedPb},
{ "message_types_by_name", PyUpb_FileDescriptor_GetMessageTypesByName,
NULL, "Messages by name"}, { "enum_types_by_name",
PyUpb_FileDescriptor_GetEnumTypesByName, NULL, "Enums by name"}, {
"extensions_by_name", (getter)GetExtensionsByName, NULL, "Extensions by
name"}, { "services_by_name", (getter)GetServicesByName, NULL, "Services
by name"}, { "dependencies", (getter)GetDependencies, NULL,
"Dependencies"}, { "public_dependencies", (getter)GetPublicDependencies,
NULL, "Dependencies"},
{ "has_options", (getter)GetHasOptions, (setter)SetHasOptions, "Has
Options"}, { "_options", (getter)NULL, (setter)SetOptions, "Options"},
{ "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
"Serialized Options"},
{ "syntax", (getter)GetSyntax, (setter)NULL, "Syntax"},
*/
{NULL}};
static PyMethodDef PyUpb_FileDescriptor_Methods[] = {
/*
{ "GetOptions", (PyCFunction)GetOptions, METH_NOARGS, },
{ "CopyToProto", (PyCFunction)CopyToProto, METH_O, },
*/
{NULL}
};
/*
{ "GetOptions", (PyCFunction)GetOptions, METH_NOARGS, },
{ "CopyToProto", (PyCFunction)CopyToProto, METH_O, },
*/
{NULL}};
static PyType_Slot PyUpb_FileDescriptor_Slots[] = {
DESCRIPTOR_BASE_SLOTS,
{Py_tp_methods, PyUpb_FileDescriptor_Methods},
{Py_tp_getset, PyUpb_FileDescriptor_Getters},
{0, NULL}
};
DESCRIPTOR_BASE_SLOTS,
{Py_tp_methods, PyUpb_FileDescriptor_Methods},
{Py_tp_getset, PyUpb_FileDescriptor_Getters},
{0, NULL}};
static PyType_Spec PyUpb_FileDescriptor_Spec = {
PYUPB_MODULE_NAME ".FileDescriptor", // tp_name
sizeof(PyUpb_DescriptorBase), // tp_basicsize
0, // tp_itemsize
Py_TPFLAGS_DEFAULT, // tp_flags
PyUpb_FileDescriptor_Slots,
PYUPB_MODULE_NAME ".FileDescriptor", // tp_name
sizeof(PyUpb_DescriptorBase), // tp_basicsize
0, // tp_itemsize
Py_TPFLAGS_DEFAULT, // tp_flags
PyUpb_FileDescriptor_Slots,
};
PyObject *PyUpb_FileDescriptor_GetOrCreateWrapper(const upb_filedef *file,
@ -234,7 +227,7 @@ PyObject *PyUpb_FileDescriptor_GetOrCreateWrapper(const upb_filedef *file,
}
const upb_filedef *PyUpb_FileDescriptor_GetDef(PyObject *_self) {
PyUpb_DescriptorBase *self = (void*)_self;
PyUpb_DescriptorBase *self = (void *)_self;
return self->def;
}
@ -242,7 +235,7 @@ const upb_filedef *PyUpb_FileDescriptor_GetDef(PyObject *_self) {
// Top Level
// -----------------------------------------------------------------------------
bool PyUpb_InitDescriptor(PyObject* m) {
bool PyUpb_InitDescriptor(PyObject *m) {
PyUpb_ModuleState *s = PyUpb_ModuleState_Get();
s->field_descriptor_type =

@ -13,11 +13,11 @@
* 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
* 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
@ -25,14 +25,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PYPB_DESCRIPTOR_H__
#define PYPB_DESCRIPTOR_H__
#ifndef PYUPB_DESCRIPTOR_H__
#define PYUPB_DESCRIPTOR_H__
#include <stdbool.h>
#include "upb/def.h"
#include "protobuf.h"
#include "upb/def.h"
PyObject *PyUpb_FieldDescriptor_GetOrCreateWrapper(const upb_fielddef *field,
PyObject *pool);
@ -41,6 +40,6 @@ PyObject *PyUpb_FileDescriptor_GetOrCreateWrapper(const upb_filedef *file,
const upb_filedef *PyUpb_FileDescriptor_GetDef(PyObject *file);
bool PyUpb_InitDescriptor(PyObject* m);
bool PyUpb_InitDescriptor(PyObject *m);
#endif // PYPB_DESCRIPTOR_H__
#endif // PYUPB_DESCRIPTOR_H__

@ -41,14 +41,15 @@ typedef struct {
PyObject* db;
} PyUpb_DescriptorPool;
static PyObject* PyUpb_DescriptorPool_DoCreate(PyTypeObject* type, PyObject* db) {
static PyObject* PyUpb_DescriptorPool_DoCreate(PyTypeObject* type,
PyObject* db) {
PyUpb_DescriptorPool* pool = PyObject_New(PyUpb_DescriptorPool, type);
pool->symtab = upb_symtab_new();
pool->db = db;
return &pool->ob_base;
}
static void PyUpb_DescriptorPool_Dealloc(PyUpb_DescriptorPool *self) {
static void PyUpb_DescriptorPool_Dealloc(PyUpb_DescriptorPool* self) {
upb_symtab_free(self->symtab);
Py_CLEAR(self->db);
PyObject_Del(self);

@ -13,11 +13,11 @@
* 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
* 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
@ -34,4 +34,4 @@
bool PyUpb_InitDescriptorPool(PyObject* m);
#endif // PYUPB_DESCRIPTOR_POOL_H__
#endif // PYUPB_DESCRIPTOR_POOL_H__

@ -13,11 +13,11 @@
* 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
* 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
@ -36,9 +36,8 @@
// This function was not officially added to the limited API until Python 3.10.
// But in practice it has been stable since Python 3.1. See:
// https://bugs.python.org/issue41784
PyAPI_FUNC(const char *) PyUnicode_AsUTF8AndSize(
PyObject *unicode,
Py_ssize_t *size);
PyAPI_FUNC(const char *)
PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *size);
#include "upb/table_internal.h"
@ -88,7 +87,7 @@ PyObject *PyUpb_ObjCache_Get(const void *key); // returns NULL if not present.
// Utilities
// -----------------------------------------------------------------------------
PyTypeObject *AddObject(PyObject *m, const char* name, PyType_Spec* spec);
PyTypeObject *AddObject(PyObject *m, const char *name, PyType_Spec *spec);
const char *PyUpb_GetStrData(PyObject *obj);
#endif // PYUPB_PROTOBUF_H__

Loading…
Cancel
Save