Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Unified Diff: third_party/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h

Issue 1291903002: Pull new version of protobuf sources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Build fix attempts Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h
diff --git a/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.h b/third_party/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h
similarity index 51%
copy from third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.h
copy to third_party/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h
index 50ad035ba8ff80ac5fd0f1d18b4d97b48116aee2..18ddd5cd4d59bbb393925f8d872e3fbda709b570 100644
--- a/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.h
+++ b/third_party/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h
@@ -1,6 +1,6 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
-// http://code.google.com/p/protobuf/
+// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@@ -28,59 +28,70 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Author: kenton@google.com (Kenton Varda)
-// Based on original Protocol Buffers design by
-// Sanjay Ghemawat, Jeff Dean, and others.
+// Author: tibell@google.com (Johan Tibell)
-#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_EXTENSION_H__
-#define GOOGLE_PROTOBUF_COMPILER_CPP_EXTENSION_H__
+#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_SCOPED_PYOBJECT_PTR_H__
+#define GOOGLE_PROTOBUF_PYTHON_CPP_SCOPED_PYOBJECT_PTR_H__
-#include <string>
#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/compiler/cpp/cpp_options.h>
+
+#include <Python.h>
namespace google {
-namespace protobuf {
- class FieldDescriptor; // descriptor.h
- namespace io {
- class Printer; // printer.h
+class ScopedPyObjectPtr {
+ public:
+ // Constructor. Defaults to initializing with NULL.
+ // There is no way to create an uninitialized ScopedPyObjectPtr.
+ explicit ScopedPyObjectPtr(PyObject* p = NULL) : ptr_(p) { }
+
+ // Destructor. If there is a PyObject object, delete it.
+ ~ScopedPyObjectPtr() {
+ Py_XDECREF(ptr_);
}
-}
-namespace protobuf {
-namespace compiler {
-namespace cpp {
+ // Reset. Deletes the current owned object, if any.
+ // Then takes ownership of a new object, if given.
+ // this->reset(this->get()) works.
+ PyObject* reset(PyObject* p = NULL) {
+ if (p != ptr_) {
+ Py_XDECREF(ptr_);
+ ptr_ = p;
+ }
+ return ptr_;
+ }
-// Generates code for an extension, which may be within the scope of some
-// message or may be at file scope. This is much simpler than FieldGenerator
-// since extensions are just simple identifiers with interesting types.
-class ExtensionGenerator {
- public:
- // See generator.cc for the meaning of dllexport_decl.
- explicit ExtensionGenerator(const FieldDescriptor* desycriptor,
- const Options& options);
- ~ExtensionGenerator();
+ // Releases ownership of the object.
+ PyObject* release() {
+ PyObject* p = ptr_;
+ ptr_ = NULL;
+ return p;
+ }
- // Header stuff.
- void GenerateDeclaration(io::Printer* printer);
+ operator PyObject*() { return ptr_; }
- // Source file stuff.
- void GenerateDefinition(io::Printer* printer);
+ PyObject* operator->() const {
+ assert(ptr_ != NULL);
+ return ptr_;
+ }
+
+ PyObject* get() const { return ptr_; }
+
+ Py_ssize_t refcnt() const { return Py_REFCNT(ptr_); }
- // Generate code to register the extension.
- void GenerateRegistration(io::Printer* printer);
+ void inc() const { Py_INCREF(ptr_); }
+
+ // Comparison operators.
+ // These return whether a ScopedPyObjectPtr and a raw pointer
+ // refer to the same object, not just to two different but equal
+ // objects.
+ bool operator==(const PyObject* p) const { return ptr_ == p; }
+ bool operator!=(const PyObject* p) const { return ptr_ != p; }
private:
- const FieldDescriptor* descriptor_;
- string type_traits_;
- Options options_;
+ PyObject* ptr_;
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator);
+ GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ScopedPyObjectPtr);
};
-} // namespace cpp
-} // namespace compiler
-} // namespace protobuf
-
} // namespace google
-#endif // GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__
+#endif // GOOGLE_PROTOBUF_PYTHON_CPP_SCOPED_PYOBJECT_PTR_H__

Powered by Google App Engine
This is Rietveld 408576698