Commit fa15042ce9f95b69dcd1dc89449ff3b295b9eff3

Authored by Jay Berkenbilt
1 parent a59e7ac7

Document decision not to remove raw QPDF pointers from the API

Showing 1 changed file with 29 additions and 10 deletions
... ... @@ -23,16 +23,6 @@ Pending changes:
23 23  
24 24 Soon: Break ground on "Document-level work"
25 25  
26   -Remove raw pointers from the API
27   -================================
28   -
29   -(For qpdf >= 12)
30   -
31   -See if we can remove raw pointers from the QPDF API. There's a
32   -discussion in https://github.com/qpdf/qpdf/pull/747. Possibly
33   -deprecate creation of QPDF objects by any means other than
34   -QPDF::create(), which returns a std::shared_ptr<QPDF>.
35   -
36 26 Fix Multiple Direct Object Owner Issue
37 27 ======================================
38 28  
... ... @@ -774,3 +764,32 @@ Rejected Ideas
774 764 stream filter, as well as modification of a stream's dictionary to
775 765 include creation of a new stream that is referenced from
776 766 /DecodeParms.
  767 +
  768 +* Removal of raw QPDF* from the API. Discussions in #747 and #754.
  769 + This is a summary of the arguments I put forth in #754. The idea was
  770 + to make QPDF::QPDF() private and require all QPDF objects to be
  771 + shared pointers created with QPDF::create(). This would enable us to
  772 + have QPDFObjectHandle::getOwningQPDF() return a std::weak_ptr<QPDF>.
  773 + Prior to #726 (QPDFObject/QPDFValue split, released in qpdf 11.0.0),
  774 + getOwningQPDF() could return an invalid pointer if the owning QPDF
  775 + disappeared, but this is no longer the case, which removes the main
  776 + motivation. QPDF 11 added QPDF::create() anyway though.
  777 +
  778 + Removing raw QPDF* would look something like this. Note that you
  779 + can't use std::make_shared<T> unless T has a public constructor.
  780 +
  781 + QPDF_POINTER_TRANSITION = 0 -- no warnings around calling the QPDF constructor
  782 + QPDF_POINTER_TRANSITION = 1 -- calls to QPDF() are deprecated, but QPDF is still available so code can be backward compatible and use std::make_shared<QPDF>
  783 + QPDF_POINTER_TRANSITION = 2 -- the QPDF constructor is private; all calls to std::make_shared<QPDF> have to be replaced with QPDF::create
  784 +
  785 + If we were to do this, we'd have to look at each use of QPDF* in the
  786 + interface and decide whether to use a std::shared_ptr or a
  787 + std::weak_ptr. The answer would almost always be to use a
  788 + std::weak_ptr, which means we'd have to take the extra step of
  789 + calling lock(), and it means there would be lots of code changes
  790 + cause people would have to pass weak pointers instead of raw
  791 + pointers around, and those have to be constructed and locked.
  792 + Passing std::shared_ptr around leaves the possibility of creating
  793 + circular references. It seems to be too much trouble in the library
  794 + and too much toil for library users to be worth the small benefit of
  795 + not having to call resetObjGen in QPDF's destructor.
... ...