This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA 01/14] Introduce py-ref.h


On Mon, 07 Nov 2016 06:47:23 +0100, Tom Tromey wrote:
> +  /* Copy another instance.  */
> +  gdbpy_reference &operator= (const gdbpy_reference &other)
> +  {
> +    Py_XDECREF (m_obj);
> +    m_obj = other.m_obj;
> +    if (m_obj != NULL)
> +      Py_INCREF (m_obj);
> +    return *this;
> +  }
> +
> +  /* Transfer ownership from another instance.  */
> +  gdbpy_reference &operator= (gdbpy_reference &&other)
> +  {
> +    Py_XDECREF (m_obj);
> +    m_obj = other.m_obj;
> +    other.m_obj = NULL;
> +    return *this;
> +  }

These two methods stale-reference / deallocate during self-assignments:
  gdbpyref = gdbpyref;
  gdbpyref = std::move (gdbpyref);

std::unique_ptr<> and std::shared_ptr<> behave correctly in such cases.


Jan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]