Thanks for the bug reports.
On Wed Jul 05 20:51:52 2017, philperry@hvc.rr.com wrote:
Show quoted text> I'm running the old examples/021_synfonts against PDF::API2 2.032 (just
> released), on Win7. The first font (/Times-Roman/) reports an error on
> PDF::API2::Basic::PDF::File line 933 ($objind->is_obj($self)) that the
> method can't be called. I traced this down to a newly-added "weaken"
> statement at line 870 in sub out_obj(), which apparently is causing a
> corefont object to be empty (at least, for Times-Roman). Commenting out
> that line lets everything run, but I'm not sure if that's safe or has
> undesirable interactions with other things.
The idea behind using "weaken" is to eliminate circular references, which cause memory leaks in Perl. PDF::API2 is/was full of them, and the code that's intended to catch them wasn't working (try using Devel::Cycle's find_cycle() function on a PDF::API2 object either before or after calling stringify() or end(), or run t/circular-references.t on 2.031 or earlier).
In order for this to work, when there are two references in a structure to the same object, weaken needs to be called on the one that's going to go out of scope first. Otherwise, the other reference becomes undef while it could still be needed, which is what you saw.
I've been trying unsuccessfully to recreate the circumstances where the weaken call was necessary in out_obj and add_obj this morning. I think some of the other weaken calls may be doing the job, so I've commented out both of them. I've also added a test to ensure that this particular case stays fixed in the future.
Show quoted text> By the way, to run 021_synfonts all the way through,
> PDF::API2::Resource::Font::CoreFont:: bankgothic needs a fix: change sub
> fontdata to sub data.
Fixed, and covered with a test as well.
Show quoted text> I was working on a utility for corefonts when the /weaken/ changes came
> out, and encountered the same problem (with Times-Roman, but not
> Helvetica or Helvetica-Bold), so I suspect it's not unique to
> 021_synfonts. It may be a flaw in the Times-Roman font or its supporting
> files.
>
Helvetica is being added to the PDF in the same scope as the save call, so that's why it worked. Not sure about Helvetica-Bold -- it theoretically should've had the same issue as the other fonts.