message: Make Operation.node_def fetch from C API when enabled
  Also fixes previously-introduced memory management bugs in graph_def_versions and op_def.
diff: @@ -1639,7 +1639,7 @@ class Operation(object):
  def colocation_groups(self):
  """Returns the list of colocation groups of the op."""
  default_colocation_group = [
  - compat.as_bytes("loc:@%s" % self._node_def.name)
  + compat.as_bytes("loc:@%s" % self.name)
  ]
  try:
  class_attr = self.get_attr("_class")
  @@ -1894,7 +1894,7 @@ class Operation(object):
  ["^%s" % op.name for op in self._control_inputs])
  def __str__(self):
  - return str(self._node_def)
  + return str(self.node_def)
  def __repr__(self):
  return "<tf.Operation '%s' type=%s>" % (self.name, self.type)
  @@ -2011,7 +2011,7 @@ class Operation(object):
  @property
  def node_def(self):
  # pylint: disable=line-too-long
  - """Returns a serialized `NodeDef` representation of this operation.
  + """Returns the `NodeDef` representation of this operation.
  Returns:
  A
  @@ -2019,6 +2019,15 @@ class Operation(object):
  protocol buffer.
  """
  # pylint: enable=line-too-long
  + if self._c_op:
  + with c_api_util.tf_buffer() as buf:
  + with errors.raise_exception_on_not_ok_status() as status:
  + c_api.TF_OperationToNodeDef(self._c_op, buf, status)
  + data = c_api.TF_GetBuffer(buf)
  + node_def = node_def_pb2.NodeDef()
  + node_def.ParseFromString(compat.as_bytes(data))
  + return node_def
  + else:
  return self._node_def
  @property
  @@ -2033,8 +2042,8 @@ class Operation(object):
  """
  # pylint: enable=line-too-long
  if self._c_op:
  - with errors.raise_exception_on_not_ok_status() as status:
  with c_api_util.tf_buffer() as buf:
  + with errors.raise_exception_on_not_ok_status() as status:
  # pylint: disable=protected-access
  c_api.TF_GraphGetOpDef(self._graph._c_graph,
  compat.as_bytes(self.type), buf, status)
  @@ -2750,8 +2759,8 @@ class Graph(object):
  """
  # pylint: enable=line-too-long
  if self._c_graph:
  - with errors.raise_exception_on_not_ok_status() as status:
  with c_api_util.tf_buffer() as buf:
  + with errors.raise_exception_on_not_ok_status() as status:
  c_api.TF_GraphVersions(self._c_graph, buf, status)
  data = c_api.TF_GetBuffer(buf)
  version_def = versions_pb2.VersionDef()
  