message: Add additional functional utilities to `pybind11_lib`.
  A SWIG struct for handling receiving SWIG Python objects as argument. A `pyo` function that converts a PyObject* to a py::object without error checking for performance optimization. A throwTypeError function that throws a Python TypeError with the given message.
diff: @@ -21,8 +21,30 @@ limitations under the License.
  namespace py = pybind11;
  +// SWIG struct so pybind11 can handle SWIG objects returned by tf_session
  +// until that is converted over to pybind11.
  +// This type is intended to be layout-compatible with an initial sequence of
  +// certain objects pointed to by a PyObject pointer. The intended use is to
  +// first check dynamically that a given PyObject* py has the correct type,
  +// and then use `reinterpret_cast<SwigPyObject*>(py)` to retrieve the member
  +// `ptr` for further, custom use. SWIG wrapped objects' layout is documented
  +// here: http://www.swig.org/Doc4.0/Python.html#Python_nn28
  +typedef struct {
  + PyObject_HEAD void* ptr; // This is the pointer to the actual C++ obj.
  + void* ty;
  + int own;
  + PyObject* next;
  + PyObject* dict;
  +} SwigPyObject;
  +
  namespace tensorflow {
  +// Convert PyObject* to py::object with no error handling.
  +
  +inline py::object pyo(PyObject* ptr) {
  + return py::reinterpret_steal<py::object>(ptr);
  +}
  +
  // Raise an exception if the PyErrOcurred flag is set or else return the Python
  // object.
  @@ -33,6 +55,11 @@ inline py::object pyo_or_throw(PyObject* ptr) {
  return py::reinterpret_steal<py::object>(ptr);
  }
  +void throwTypeError(const char* error_message) {
  + PyErr_SetString(PyExc_TypeError, error_message);
  + throw pybind11::error_already_set();
  +}
  +
  } // namespace tensorflow
  #endif // TENSORFLOW_PYTHON_LIB_CORE_PYBIND11_LIB_H_
  