понедельник, 17 августа 2009 г.

MuPDF and Fitz: reference counting and documentation

I am currently trying to wrap MuPDF (which uses Fitz graphics library) with Python and create PDF editing application. At first I aim for very simple (but practical!) things: crop, reorder pages...

So far MuPDF source is very readable, I like it. But for some reason MuPDF doesn't have essential things you would normally expect from an open source project:
  • no decent web site (current page doesn't count),
  • no mailing list (well, there's fitz-dev, but it's basically dead - maybe crazy anti spam technique is to blame?),
  • no documentation.
Yes, virtually no documentation. For example, I'm currently trying to understand reference counting in MuPDF. I don't want to create a memory leaking monster! Getting refcounting right seems to be not an easy thing. Even MuPDF author has had some issues with it recently. It's even more difficult without the docs.

But, after some googling I found there was some documentation in now-not-working wiki.ghostscript.com. Fortunately, some information survived thanks to archive.org. It's very old (from 2004!), but it seems core concepts hasn't changes since then. Below are some extracts from the wiki, mostly about reference counting (that's what I am currently interested in).

Dynamic Objects:
The objects are reference counted. It is up to the creator of an object to drop it once it is no longer needed. Getting an element from an array or dictionary object does not modify the elements reference count, so if you need to hold on to the object for a longer amount of time, make damn sure you call keep on it.

Coding Style on memory allocation:
In general, when a function (verb) acts on an object or structure (noun), the name shall be fz_verbnoun. The following verbs shall be used consistently:

  • new: for heap-allocating new objects.
  • free: for destroying objects created by new. Alternate name: destroy
  • keep: increment a refcnt.
  • drop: decrement a refcnt.

Комментариев нет: