Bug 698353 - NDEBUG in fitz/context.h prevents debug builds of user programs
Summary: NDEBUG in fitz/context.h prevents debug builds of user programs
Status: RESOLVED FIXED
Alias: None
Product: MuPDF
Classification: Unclassified
Component: fitz (show other bugs)
Version: master
Hardware: PC All
: P4 normal
Assignee: MuPDF bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-14 01:55 UTC by Paul Irofti
Modified: 2017-11-09 07:19 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Irofti 2017-08-14 01:55:39 UTC
Hi,

The following block of code in fitz/context.h breaks DEBUG builds for programs that include this header

 576 #if defined(MEMENTO) || !defined(NDEBUG)
 577 #define FITZ_DEBUG_LOCKING
 578 #endif

I should not be obligated to build a debug version of mupdf in order to debug my own program. Here is error

/usr/local/pobj/k2pdfopt-2.42/k2pdfopt_v2.42/k2pdfoptlib/k2sys.c:120: warning: \
                warning: sprintf() is often misused, please use snprintf()
/usr/local/lib/libglib-2.0.so.4200.5: warning: warning: stpcpy() is dangerous; do not \
use it willuslib/libwilluslib.a(font.c.o): In function `fz_lock':
/usr/local/include/mupdf/fitz/context.h:596: undefined reference to \
`fz_lock_debug_lock' willuslib/libwilluslib.a(font.c.o): In function `fz_unlock':
/usr/local/include/mupdf/fitz/context.h:603: undefined reference to \
`fz_lock_debug_unlock' willuslib/libwilluslib.a(font.c.o): In function `fz_lock':
/usr/local/include/mupdf/fitz/context.h:596: undefined reference to \
`fz_lock_debug_lock' willuslib/libwilluslib.a(font.c.o): In function `fz_unlock':
/usr/local/include/mupdf/fitz/context.h:603: undefined reference to \
                `fz_lock_debug_unlock'
/usr/local/include/mupdf/fitz/context.h:603: undefined reference to \
                `fz_lock_debug_unlock'

where fz_lock_debug_lock and fz_lock_debug_unlock are not defined. Could we remove the !defined(NDEBUG) term and perhaps replace it with something more sensible like defined(FZ_LOCK_DEBUG)?

Thank you,
Paul Irofti
Comment 1 Robin Watts 2017-11-09 07:19:01 UTC
Fixed in:

commit 258f03a0a55c1aa802e1be47e463d8abc5096196
Author: Robin Watts <robin.watts@artifex.com>
Date:   Wed Nov 8 19:45:14 2017 +0000

    Bug 698353: Avoid having our API depend on DEBUG/NDEBUG.

    Currently, our API uses static inlines for fz_lock and
    fz_unlock, the definitions for which depend on whether
    we build NDEBUG or not. This isn't ideal as it causes
    problems when people link a release binary with a debug
    lib (or vice versa).

    We really want to continue to use static inlines for the
    locking functions as used from MuPDF, as we hit them
    hard in the keep/drop functions.

    We therefore remove fz_lock/fz_unlock from the public API
    entirely. Accordingly, we move the fz_lock/fz_unlock
    static inlines into fitz-imp.h (an internal header),
    together with the fz_keep_.../fz_drop_... functions.

    We then have public fz_lock/fz_unlock functions for any
    external callers to use that are free of compilications.

    At the same time, to avoid another indirection, we change
    from holding the locking functions as a pointer to a
    struct to a struct itself.