]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libfontembed, libcupsfilters, libppd: assert() only if DEBUG is set
authorTill Kamppeter <till.kamppeter@gmail.com>
Thu, 25 Aug 2022 21:32:36 +0000 (23:32 +0200)
committerTill Kamppeter <till.kamppeter@gmail.com>
Thu, 25 Aug 2022 21:32:36 +0000 (23:32 +0200)
A failing assert() makes the whole program crash, a daemon (Printer
Application) crashes when a filter fails on a damaged input file, a
distro-packaged program sends automatic bug reports to the distro,
... Sometimes assert() is really overkill.

But assert() can be useful for debugging, as one gets easily aware
when some values are wrong somewhere (this probably made the
contributors yo cups-filters insert that many assert() calls).

At least, assert() should only be used for debugging, not in
production code.

Therefore we have replaced all assert() calls by the DEBUG_assert()
macro and the macro is set to assert() when the code is compiled with
the DEBUG macro set and to nothing otherwise. For setting this macro
and other debugging macros there are */debug-internal.h files for all
the 3 libraries now.

Also defined functions for DEBUG_printf and DEBUG_puts in
libcupsfilters (cupsfilters/debug.c).

On a compilation with DEBUG set ("CXXFLAGS=-DDEBUG CFLAGS=-DDEBUG
./configure ...") found some build failures and fixed them.

Also silenced all remaining warnings.

39 files changed:
Makefile.am
cupsfilters/debug-internal.h [new file with mode: 0644]
cupsfilters/debug.c [new file with mode: 0644]
cupsfilters/getline.c
cupsfilters/ieee1284.c
cupsfilters/pdftopdf/intervalset.cxx
cupsfilters/pdftopdf/nup.cxx
cupsfilters/pdftopdf/pdftopdf-processor.cxx
cupsfilters/pdftopdf/pdftopdf.cxx
cupsfilters/pdftopdf/pptypes.cxx
cupsfilters/pdftopdf/qpdf-cm.cxx
cupsfilters/pdftopdf/qpdf-pdftopdf-processor.cxx
cupsfilters/pdftopdf/qpdf-pdftopdf.cxx
cupsfilters/pdfutils.c
cupsfilters/texttopdf.c
filter/foomatic-rip/foomaticrip.c
filter/foomatic-rip/options.c
filter/foomatic-rip/util.c
filter/test_pdf1.c
filter/test_pdf2.c
fontembed/debug-internal.h [new file with mode: 0644]
fontembed/dynstring.c
fontembed/embed-pdf.c
fontembed/embed-sfnt.c
fontembed/embed.c
fontembed/fontfile.c
fontembed/frequent.c
fontembed/sfnt-subset.c
fontembed/sfnt.c
fontembed/test-analyze.c
fontembed/test-pdf.c
fontembed/test-ps.c
ppd/debug-internal.h
ppd/debug.c
ppd/ppd-cache.c
ppd/ppd-localize.c
ppd/raster-interpret.c
ppd/rastertops.c
utils/driverless.c

index a17724f579206c39012a219db355199e4ef867ab..c3a0ffafd3958edd4f08bb533a032c39058b4878 100644 (file)
@@ -188,6 +188,7 @@ libfontembed_la_SOURCES = \
        fontembed/aglfn13.c \
        fontembed/dynstring.c \
        fontembed/dynstring-private.h \
+       fontembed/debug-internal.h \
        fontembed/embed.c \
        fontembed/embed-sfnt.c \
        fontembed/embed-sfnt-int-private.h \
@@ -275,6 +276,8 @@ libcupsfilters_la_SOURCES = \
        cupsfilters/cmyk.c \
        cupsfilters/colord.c \
        cupsfilters/colormanager.c \
+       cupsfilters/debug.c \
+       cupsfilters/debug-internal.h \
        cupsfilters/dither.c \
        cupsfilters/filter.c \
        cupsfilters/ghostscript.c \
diff --git a/cupsfilters/debug-internal.h b/cupsfilters/debug-internal.h
new file mode 100644 (file)
index 0000000..2fa5c84
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Internal debugging macros for libcupsfilters.
+ *
+ * Copyright © 2007-2018 by Apple Inc.
+ * Copyright © 1997-2005 by Easy Software Products.
+ *
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more
+ * information.
+ */
+
+#ifndef _CUPS_FILTERS_DEBUG_INTERNAL_H_
+#  define _CUPS_FILTERS_DEBUG_INTERNAL_H_
+
+
+/*
+ * C++ magic...
+ */
+
+#  ifdef __cplusplus
+extern "C" {
+#  endif /* __cplusplus */
+
+
+/*
+ * The debug macros are used if you compile with DEBUG defined.
+ *
+ * Usage:
+ *
+ *   DEBUG_puts("string");
+ *   DEBUG_printf(("format string", arg, arg, ...));
+ *   DEBUG_assert(boolean expression);
+ *
+ * Note the extra parenthesis around the DEBUG_printf macro...
+ */
+
+#  ifdef DEBUG
+#    include <assert.h>
+#    define DEBUG_puts(x) _cf_debug_puts(x)
+#    define DEBUG_printf(x) _cf_debug_printf x
+#    define DEBUG_assert(x) assert(x)
+#  else
+#    define DEBUG_puts(x)
+#    define DEBUG_printf(x)
+#    define DEBUG_assert(x)
+#  endif /* DEBUG */
+
+#  ifdef DEBUG
+extern void    _cf_debug_printf(const char *format, ...);
+extern void    _cf_debug_puts(const char *s);
+#  endif /* DEBUG */
+
+#  ifdef __cplusplus
+}
+#  endif /* __cplusplus */
+
+#endif /* !_CUPS_FILTERS_DEBUG_INTERNAL_H_ */
diff --git a/cupsfilters/debug.c b/cupsfilters/debug.c
new file mode 100644 (file)
index 0000000..98a31ec
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Debugging functions for cupsfilters.
+ *
+ * Copyright © 2008-2018 by Apple Inc.
+ *
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more
+ * information.
+ */
+
+
+/*
+ * Include necessary headers...
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+
+/*
+ * '_cf_debug_printf()' - Write a formatted line to the log.
+ */
+
+void
+_cf_debug_printf(const char *format,   /* I - Printf-style format string */
+                 ...)                  /* I - Additional arguments as needed */
+{
+  va_list              ap;             /* Pointer to arguments */
+
+  va_start(ap, format);
+  vfprintf(stderr, format, ap);
+  va_end(ap);
+  fflush(stderr);
+}
+
+
+/*
+ * '_cf_debug_puts()' - Write a single line to the log.
+ */
+
+void
+_cf_debug_puts(const char *s)          /* I - String to output */
+{
+  fputs(s, stderr);
+  fflush(stderr);
+}
index 1f55f6ead14aaaf2dc51f3ae592effe2fc0654b8..d881da7299b3bc84bf5a0551e73a9adef63b0fc1 100644 (file)
@@ -25,7 +25,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 #include <sys/types.h>
 #include <stdio.h>
 #define NDEBUG
-#include <assert.h>
+#include "debug-internal.h"
 
 #include <stdlib.h>
 
@@ -72,7 +72,7 @@ getstr (lineptr, n, stream, terminator, offset)
         always (unless we get an error while reading the first char)
         NUL-terminate the line buffer.  */
 
-      assert(*n - nchars_avail == read_pos - *lineptr);
+      DEBUG_assert(*n - nchars_avail == read_pos - *lineptr);
       if (nchars_avail < 1)
        {
          if (*n > MIN_CHUNK)
@@ -85,7 +85,7 @@ getstr (lineptr, n, stream, terminator, offset)
          if (!*lineptr)
            return -1;
          read_pos = *n - nchars_avail + *lineptr;
-         assert(*n - nchars_avail == read_pos - *lineptr);
+         DEBUG_assert(*n - nchars_avail == read_pos - *lineptr);
        }
 
       if (c == EOF || ferror (stream))
index 14eb4a3e620aaae86bcb874a428bb6f6023a21b8..be3ce826b7e1394ee35fc1785bee1bcde6a39d71 100644 (file)
 
 #include <config.h>
 #include "ieee1284.h"
+#include "debug-internal.h"
 #include <cups/cups.h>
 #include <string.h>
 #include <ctype.h>
 #include <stdio.h>
-#define DEBUG_printf(x)
-#define DEBUG_puts(x)
 
 
 /*
index 6fe32bb686417b14aa2004b342469ec71f3e1880..d60f5a68616aeda78106be67c98fdfd785c04f4d 100644 (file)
@@ -1,6 +1,6 @@
 #include "intervalset-private.h"
 #include <stdio.h>
-#include <assert.h>
+#include "cupsfilters/debug-internal.h"
 #include <limits>
 #include <algorithm>
 
@@ -91,7 +91,7 @@ bool _cfPDFToPDFIntervalSet::intersect(const value_t &a,const value_t &b) const
 
 void _cfPDFToPDFIntervalSet::unite(value_t &aret,const value_t &b) const // {{{
 {
-  assert(intersect(aret,b));
+  DEBUG_assert(intersect(aret,b));
   if (b.first<aret.first) {
     aret.first=b.first;
   }
index b0e820985a466a216685164511985d1ee7d6eac0..d79e265a9eafa3881f29596739d49d3db3511770 100644 (file)
@@ -1,6 +1,6 @@
 #include "nup-private.h"
 #include <stdio.h>
-#include <assert.h>
+#include "cupsfilters/debug-internal.h"
 #include <string.h>
 #include <utility>
 
@@ -124,7 +124,7 @@ _cfPDFToPDFNupState::_cfPDFToPDFNupState(const _cfPDFToPDFNupParameters &param)
     nup(param.nupX*param.nupY),
     subpage(nup)
 {
-  assert( (param.nupX>0)&&(param.nupY>0) );
+  DEBUG_assert( (param.nupX>0)&&(param.nupY>0) );
 }
 // }}}
 
@@ -245,7 +245,7 @@ static std::pair<pdftopdf_axis_e,pdftopdf_position_e> parsePosition(char a,char
 
 bool _cfPDFToPDFParseNupLayout(const char *val,_cfPDFToPDFNupParameters &ret) // {{{
 {
-  assert(val);
+  DEBUG_assert(val);
   auto pos0=parsePosition(val[0],val[1]);
   if (pos0.second==CENTER) {
     return false;
index 2a801469cbb9bc4f03f5f0470fb925c16c28c9b8..6f17033fad1b0e09b3370013891d65415eee86b7 100644 (file)
@@ -1,7 +1,7 @@
 #include "pdftopdf-processor-private.h"
 #include "qpdf-pdftopdf-processor-private.h"
 #include <stdio.h>
-#include <assert.h>
+#include "cupsfilters/debug-internal.h"
 #include <numeric>
 
 void BookletMode_dump(pdftopdf_booklet_mode_e bkm,pdftopdf_doc_t *doc) // {{{
@@ -140,7 +140,7 @@ std::vector<int> _cfPDFToPDFBookletShuffle(int numPages,int signature) // {{{
   if (signature<0) {
     signature=(numPages+3)&~0x3;
   }
-  assert(signature%4==0);
+  DEBUG_assert(signature%4==0);
 
   std::vector<int> ret;
   ret.reserve(numPages+signature-1);
index c8678efe778c9bc4aff392c01e341b17ac4ae0e9..3246df77e647bb4c813c911ccf0da78af0e7dfcf 100644 (file)
@@ -5,7 +5,7 @@
 
 #include <config.h>
 #include <stdio.h>
-#include <assert.h>
+#include "cupsfilters/debug-internal.h"
 #include <cups/cups.h>
 #if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 6)
 #define HAVE_CUPS_1_7 1
@@ -33,7 +33,7 @@
 
 static bool optGetInt(const char *name,int num_options,cups_option_t *options,int *ret) // {{{
 {
-  assert(ret);
+  DEBUG_assert(ret);
   const char *val=cupsGetOption(name,num_options,options);
   if (val) {
     *ret=atoi(val);
@@ -45,7 +45,7 @@ static bool optGetInt(const char *name,int num_options,cups_option_t *options,in
 
 static bool optGetFloat(const char *name,int num_options,cups_option_t *options,float *ret) // {{{
 {
-  assert(ret);
+  DEBUG_assert(ret);
   const char *val=cupsGetOption(name,num_options,options);
   if (val) {
     *ret=atof(val);
@@ -162,7 +162,7 @@ static void parseRanges(const char *range,_cfPDFToPDFIntervalSet &ret) // {{{
 
 static bool _cfPDFToPDFParseBorder(const char *val,pdftopdf_border_type_e &ret) // {{{
 {
-  assert(val);
+  DEBUG_assert(val);
   if (strcasecmp(val,"none")==0) {
     ret=pdftopdf_border_type_e::NONE;
   } else if (strcasecmp(val,"single")==0) {
index 15536e2ecdfab3ae1824c74c17760ce02e78190f..f1344caa364757d0cf592b870c91fe9fd0ac2fbd 100644 (file)
@@ -1,7 +1,7 @@
 #include "pptypes-private.h"
 #include <utility>
 #include <stdio.h>
-#include <assert.h>
+#include "cupsfilters/debug-internal.h"
 
 void _cfPDFToPDFPositionDump(pdftopdf_position_e pos,pdftopdf_doc_t *doc) // {{{
 {
@@ -18,7 +18,7 @@ void _cfPDFToPDFPositionDump(pdftopdf_position_e pos,pdftopdf_doc_t *doc) // {{{
 
 void _cfPDFToPDFPositionDump(pdftopdf_position_e pos,pdftopdf_axis_e axis,pdftopdf_doc_t *doc) // {{{
 {
-  assert((axis == pdftopdf_axis_e::X) || (axis == pdftopdf_axis_e::Y));
+  DEBUG_assert((axis == pdftopdf_axis_e::X) || (axis == pdftopdf_axis_e::Y));
   if ((pos < LEFT) || (pos > RIGHT)) {
     if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
       "cfFilterPDFToPDF: Position %s: (bad position: %d)",
@@ -147,7 +147,7 @@ void _cfPDFToPDFPageRect::scale(float mult) // {{{
   if (mult==1.0) {
     return;
   }
-  assert(mult!=0.0);
+  DEBUG_assert(mult!=0.0);
 
   bottom*=mult;
   left*=mult;
index 966f5e6c969669db2eff7f7ff33aa6fc8b5edd43..bba4db1da1b0edb570c71f2393c7ec8f23043a4f 100644 (file)
@@ -1,6 +1,6 @@
 #include "qpdf-cm-private.h"
 #include <stdio.h>
-#include <assert.h>
+#include "cupsfilters/debug-internal.h"
 
 #include <stdexcept>
 
index f436ecfcfd7593baf1564b8b8702bcc2bd82329b..88a2edc2664d30c3abe182bd720d59a0955a27ea 100644 (file)
@@ -1,7 +1,7 @@
 #include "qpdf-pdftopdf-processor-private.h"
 #include <stdio.h>
 #include <stdarg.h>
-#include <assert.h>
+#include "cupsfilters/debug-internal.h"
 #include <stdexcept>
 #include <qpdf/QPDFWriter.hh>
 #include <qpdf/QUtil.hh>
@@ -39,7 +39,7 @@ _cfPDFToPDFQPDFPageHandle::_cfPDFToPDFQPDFPageHandle(QPDF *pdf,float width,float
   : no(0),
     rotation(ROT_0)
 {
-  assert(pdf);
+  DEBUG_assert(pdf);
   page=QPDFObjectHandle::parse(
     "<<"
     "  /Type /Page"
@@ -123,8 +123,8 @@ static _cfPDFToPDFPageRect ungetRect(_cfPDFToPDFPageRect rect,const _cfPDFToPDFQ
 // TODO? for non-existing (either drop comment or facility to create split streams needed)
 void _cfPDFToPDFQPDFPageHandle::add_border_rect(const _cfPDFToPDFPageRect &_rect,pdftopdf_border_type_e border,float fscale) // {{{
 {
-  assert(is_existing());
-  assert(border!=pdftopdf_border_type_e::NONE);
+  DEBUG_assert(is_existing());
+  DEBUG_assert(border!=pdftopdf_border_type_e::NONE);
 
   // straight from pstops
   const double lw=(border&THICK)?0.5:0.24;
@@ -135,8 +135,8 @@ void _cfPDFToPDFQPDFPageHandle::add_border_rect(const _cfPDFToPDFPageRect &_rect
 
   _cfPDFToPDFPageRect rect=ungetRect(_rect,*this,rotation,page);
 
-  assert(rect.left<=rect.right);
-  assert(rect.bottom<=rect.top);
+  DEBUG_assert(rect.left<=rect.right);
+  DEBUG_assert(rect.bottom<=rect.top);
 
   std::string boxcmd="q\n";
   boxcmd+="  "+QUtil::double_to_string(line_width)+" w 0 G \n";
@@ -154,7 +154,7 @@ void _cfPDFToPDFQPDFPageHandle::add_border_rect(const _cfPDFToPDFPageRect &_rect
   //   return;
   // }
   
-  assert(page.getOwningQPDF()); // existing pages are always indirect
+  DEBUG_assert(page.getOwningQPDF()); // existing pages are always indirect
 #ifdef DEBUG  // draw it on top
   static const char *pre="%pdftopdf q\n"
     "q\n",
@@ -273,7 +273,7 @@ bool _cfPDFToPDFQPDFPageHandle::is_landscape(pdftopdf_rotation_e orientation)
 void _cfPDFToPDFQPDFPageHandle::add_subpage(const std::shared_ptr<_cfPDFToPDFPageHandle> &sub,float xpos,float ypos,float scale,const _cfPDFToPDFPageRect *crop) // {{{
 {
   auto qsub=dynamic_cast<_cfPDFToPDFQPDFPageHandle *>(sub.get());
-  assert(qsub);
+  DEBUG_assert(qsub);
 
   std::string xoname="/X"+QUtil::int_to_string((qsub->no!=-1)?qsub->no:++no);
   if (crop) {
@@ -337,7 +337,7 @@ void _cfPDFToPDFQPDFPageHandle::mirror() // {{{
     // content.append(std::string("1 0 0 1 0 0 cm\n  ");
     content.append(xoname+" Do\n");
 
-    assert(!is_existing());
+    DEBUG_assert(!is_existing());
   }
 
   static const char *pre="%pdftopdf cm\n";
@@ -357,7 +357,7 @@ void _cfPDFToPDFQPDFPageHandle::rotate(pdftopdf_rotation_e rot) // {{{
 
 void _cfPDFToPDFQPDFPageHandle::add_label(const _cfPDFToPDFPageRect &_rect, const std::string label) // {{{
 {
-  assert(is_existing());
+  DEBUG_assert(is_existing());
 
   _cfPDFToPDFPageRect rect = ungetRect (_rect, *this, rotation, page);
 
@@ -433,7 +433,7 @@ void _cfPDFToPDFQPDFPageHandle::add_label(const _cfPDFToPDFPageRect &_rect, cons
 
   boxcmd += "Q\n";
 
-  assert(page.getOwningQPDF()); // existing pages are always indirect
+  DEBUG_assert(page.getOwningQPDF()); // existing pages are always indirect
   static const char *pre="%pdftopdf q\n"
     "q\n",
     *post="%pdftopdf Q\n"
@@ -451,7 +451,7 @@ void _cfPDFToPDFQPDFPageHandle::add_label(const _cfPDFToPDFPageRect &_rect, cons
 
 void _cfPDFToPDFQPDFPageHandle::debug(const _cfPDFToPDFPageRect &rect,float xpos,float ypos) // {{{
 {
-  assert(!is_existing());
+  DEBUG_assert(!is_existing());
   content.append(debug_box(rect,xpos,ypos));
 }
 // }}}
@@ -526,7 +526,7 @@ bool _cfPDFToPDFQPDFProcessor::load_filename(const char *name,pdftopdf_doc_t *do
 
 void _cfPDFToPDFQPDFProcessor::start(int flatten_forms) // {{{
 {
-  assert(pdf);
+  DEBUG_assert(pdf);
 
   if (flatten_forms) {
     QPDFAcroFormDocumentHelper afdh(*pdf);
@@ -570,7 +570,7 @@ std::vector<std::shared_ptr<_cfPDFToPDFPageHandle>> _cfPDFToPDFQPDFProcessor::ge
   if (!pdf) {
     if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
         "cfFilterPDFToPDF: No PDF loaded");
-    assert(0);
+    DEBUG_assert(0);
     return ret;
   }
   const int len=orig_pages.size();
@@ -587,7 +587,7 @@ std::shared_ptr<_cfPDFToPDFPageHandle> _cfPDFToPDFQPDFProcessor::new_page(float
   if (!pdf) {
     if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
         "cfFilterPDFToPDF: No PDF loaded");
-    assert(0);
+    DEBUG_assert(0);
     return std::shared_ptr<_cfPDFToPDFPageHandle>();
   }
   return std::shared_ptr<_cfPDFToPDFQPDFPageHandle>(new _cfPDFToPDFQPDFPageHandle(pdf.get(),width,height));
@@ -598,7 +598,7 @@ std::shared_ptr<_cfPDFToPDFPageHandle> _cfPDFToPDFQPDFProcessor::new_page(float
 
 void _cfPDFToPDFQPDFProcessor::add_page(std::shared_ptr<_cfPDFToPDFPageHandle> page,bool front) // {{{
 {
-  assert(pdf);
+  DEBUG_assert(pdf);
   auto qpage=dynamic_cast<_cfPDFToPDFQPDFPageHandle *>(page.get());
   if (qpage) {
     pdf->addPage(qpage->get(),front);
@@ -616,8 +616,8 @@ pdf->getRoot().removeKey("/PageLabels");
 
 void _cfPDFToPDFQPDFProcessor::multiply(int copies,bool collate) // {{{
 {
-  assert(pdf);
-  assert(copies>0);
+  DEBUG_assert(pdf);
+  DEBUG_assert(copies>0);
 
   std::vector<QPDFObjectHandle> pages=pdf->getAllPages(); // need copy
   const int len=pages.size();
@@ -641,7 +641,7 @@ void _cfPDFToPDFQPDFProcessor::multiply(int copies,bool collate) // {{{
 // TODO? elsewhere?
 void _cfPDFToPDFQPDFProcessor::auto_rotate_all(bool dst_lscape,pdftopdf_rotation_e normal_landscape) // {{{
 {
-  assert(pdf);
+  DEBUG_assert(pdf);
 
   const int len=orig_pages.size();
   for (int iA=0;iA<len;iA++) {
@@ -672,7 +672,7 @@ void _cfPDFToPDFQPDFProcessor::auto_rotate_all(bool dst_lscape,pdftopdf_rotation
 // TODO
 void _cfPDFToPDFQPDFProcessor::add_cm(const char *defaulticc,const char *outputicc) // {{{
 {
-  assert(pdf);
+  DEBUG_assert(pdf);
 
   if (_cfPDFToPDFHasOutputIntent(*pdf)) {
     return; // nothing to do
@@ -692,7 +692,7 @@ void _cfPDFToPDFQPDFProcessor::set_comments(const std::vector<std::string> &comm
   extraheader.clear();
   const int len=comments.size();
   for (int iA=0;iA<len;iA++) {
-    assert(comments[iA].at(0)=='%');
+    DEBUG_assert(comments[iA].at(0)=='%');
     extraheader.append(comments[iA]);
     extraheader.push_back('\n');
   }
index a3e5b33fe69a66e501c499baeb3d89fb5759940f..3009bddb57065b6174286a4b3574faeb55709dd2 100644 (file)
@@ -1,5 +1,5 @@
 #include "qpdf-pdftopdf-private.h"
-#include <assert.h>
+#include "cupsfilters/debug-internal.h"
 #include <stdexcept>
 #include <qpdf/QUtil.hh>
 
@@ -117,7 +117,7 @@ _cfPDFToPDFMatrix &_cfPDFToPDFMatrix::rotate(pdftopdf_rotation_e rot) // {{{
     ctm[1]=-ctm[1];
     break;
   default:
-    assert(0);
+    DEBUG_assert(0);
   }
   return *this;
 }
index ab9358a16e98a17de552ef1af6506a22f70ed80c..bb1d7b2e7fd860ed89801cef2fb148b2912d3d00 100644 (file)
@@ -8,7 +8,7 @@
  *
  */
 #include <stdio.h>
-#include <assert.h>
+#include "debug-internal.h"
 #include <stdarg.h>
 #include <memory.h>
 #include <stdlib.h>
@@ -18,7 +18,7 @@
 
 void cfPDFOutPrintF(cf_pdf_out_t *pdf,const char *fmt,...) // {{{
 {
-  assert(pdf);
+  DEBUG_assert(pdf);
   int len;
   va_list ap;
 
@@ -31,8 +31,8 @@ void cfPDFOutPrintF(cf_pdf_out_t *pdf,const char *fmt,...) // {{{
 
 void cfPDFOutPutString(cf_pdf_out_t *pdf,const char *str,int len) // {{{ - >len==-1: strlen()
 {
-  assert(pdf);
-  assert(str);
+  DEBUG_assert(pdf);
+  DEBUG_assert(str);
   if (len==-1) {
     len=strlen(str);
   }
@@ -62,8 +62,8 @@ void cfPDFOutPutString(cf_pdf_out_t *pdf,const char *str,int len) // {{{ - >len=
 
 void cfPDFOutPutHexString(cf_pdf_out_t *pdf,const char *str,int len) // {{{ - >len==-1: strlen()
 {
-  assert(pdf);
-  assert(str);
+  DEBUG_assert(pdf);
+  DEBUG_assert(str);
   if (len==-1) {
     len=strlen(str);
   }
@@ -108,8 +108,8 @@ const char *cfPDFOutToPDFDate(struct tm *curtm) // {{{
 
 int cfPDFOutAddXRef(cf_pdf_out_t *pdf) // {{{  -  returns obj_no
 {
-  assert(pdf);
-  assert(pdf->xrefsize<=pdf->xrefalloc);
+  DEBUG_assert(pdf);
+  DEBUG_assert(pdf->xrefsize<=pdf->xrefalloc);
 
   if (pdf->xrefsize==pdf->xrefalloc) {
     long *tmp;
@@ -128,9 +128,9 @@ int cfPDFOutAddXRef(cf_pdf_out_t *pdf) // {{{  -  returns obj_no
 
 int cfPDFOutAddPage(cf_pdf_out_t *pdf,int obj) // {{{ -  returns false on error
 {
-  assert(pdf);
-  assert(obj>0);
-  assert(pdf->pagessize<=pdf->pagesalloc);
+  DEBUG_assert(pdf);
+  DEBUG_assert(obj>0);
+  DEBUG_assert(pdf->pagessize<=pdf->pagesalloc);
 
   if (pdf->pagessize==pdf->pagesalloc) {
     int *tmp;
@@ -149,8 +149,8 @@ int cfPDFOutAddPage(cf_pdf_out_t *pdf,int obj) // {{{ -  returns false on error
 
 int cfPDFOutAddKeyValue(cf_pdf_out_t *pdf,const char *key,const char *val) // {{{ -  returns false on error
 {
-  assert(pdf);
-  assert(pdf->kvsize<=pdf->kvalloc);
+  DEBUG_assert(pdf);
+  DEBUG_assert(pdf->kvsize<=pdf->kvalloc);
 
   if (pdf->kvsize==pdf->kvalloc) {
     struct cf_keyval_t *tmp;
@@ -174,8 +174,8 @@ int cfPDFOutAddKeyValue(cf_pdf_out_t *pdf,const char *key,const char *val) // {{
 
 int cfPDFOutBeginPDF(cf_pdf_out_t *pdf) // ,...output_device?...) // {{{ - false on error
 {
-  assert(pdf);
-  assert(pdf->kvsize==0); // otherwise: finish_pdf has not been called
+  DEBUG_assert(pdf);
+  DEBUG_assert(pdf->kvsize==0); // otherwise: finish_pdf has not been called
   int pages_obj;
 
   pdf->xrefsize=pdf->pagessize=0;
@@ -193,7 +193,7 @@ void cfPDFOutFinishPDF(cf_pdf_out_t *pdf) // {{{
 {
   int iA;
   int root_obj,info_obj=0,xref_start;
-  assert( (pdf)&&(pdf->filepos!=-1) );
+  DEBUG_assert( (pdf)&&(pdf->filepos!=-1) );
 
   // pages 
   const int pages_obj=1;
@@ -273,7 +273,7 @@ void cfPDFOutFinishPDF(cf_pdf_out_t *pdf) // {{{
 void cfPDFOutFree(cf_pdf_out_t *pdf) // {{{
 {
   if (pdf) {
-    assert(pdf->kvsize==0); // otherwise: finish_pdf has not been called
+    DEBUG_assert(pdf->kvsize==0); // otherwise: finish_pdf has not been called
     free(pdf->kv);
     free(pdf->pages);
     free(pdf->xref);
@@ -288,7 +288,7 @@ static void pdfOut_outfn(const char *buf,int len,void *context) // {{{
 
   if (fwrite(buf,1,len,stdout)!=len) {
     perror("Short write");
-    assert(0);
+    DEBUG_assert(0);
     return;
   }
   pdf->filepos+=len;
@@ -297,8 +297,8 @@ static void pdfOut_outfn(const char *buf,int len,void *context) // {{{
 
 int cfPDFOutWriteFont(cf_pdf_out_t *pdf,EMB_PARAMS *emb) // {{{ 
 {
-  assert(pdf);
-  assert(emb);
+  DEBUG_assert(pdf);
+  DEBUG_assert(emb);
 
   EMB_PDF_FONTDESCR *fdes=emb_pdf_fontdescr(emb);
   if (!fdes) {
@@ -345,7 +345,7 @@ int cfPDFOutWriteFont(cf_pdf_out_t *pdf,EMB_PARAMS *emb) // {{{
                     "endobj\n");
 
   const int l0_obj=cfPDFOutAddXRef(pdf);
-  assert(l0_obj==ff_obj+1);
+  DEBUG_assert(l0_obj==ff_obj+1);
   cfPDFOutPrintF(pdf,"%d 0 obj\n"
                     "%ld\n"
                     "endobj\n"
@@ -353,7 +353,7 @@ int cfPDFOutWriteFont(cf_pdf_out_t *pdf,EMB_PARAMS *emb) // {{{
 
   if (emb->outtype==EMB_FMT_TTF) {
     const int l1_obj=cfPDFOutAddXRef(pdf);
-    assert(l1_obj==ff_obj+2);
+    DEBUG_assert(l1_obj==ff_obj+2);
     cfPDFOutPrintF(pdf,"%d 0 obj\n"
                       "%d\n"
                       "endobj\n"
index 9f610020624402ea0a61f18136515c92379f62b3..845360d38fabfbedf2ce1a94f64f975814f380bb 100644 (file)
@@ -15,7 +15,7 @@
  * Include necessary headers...
  */
 
-#include <assert.h>
+#include "debug-internal.h"
 #include <config.h>
 #include "cupsfilters/pdfutils.h"
 #include "cupsfilters/raster.h"
@@ -1503,24 +1503,24 @@ static EMB_PARAMS *font_load(const char *font, int fontwidth, cf_logfunc_t log,
   }
 
   FONTFILE *ff = fontfile_open_sfnt(otf);
-  assert(ff);
+  DEBUG_assert(ff);
   EMB_PARAMS *emb = emb_new(ff,
                            EMB_DEST_PDF16,
                            EMB_C_FORCE_MULTIBYTE|
                            EMB_C_TAKE_FONTFILE);
-  assert(emb);
-  assert(emb->plan&EMB_A_MULTIBYTE);
+  DEBUG_assert(emb);
+  DEBUG_assert(emb->plan&EMB_A_MULTIBYTE);
   return emb;
 }
 
 static EMB_PARAMS *font_std(const char *name)
 {
   FONTFILE *ff = fontfile_open_std(name);
-  assert(ff);
+  DEBUG_assert(ff);
   EMB_PARAMS *emb = emb_new(ff,
                            EMB_DEST_PDF16,
                            EMB_C_TAKE_FONTFILE);
-  assert(emb);
+  DEBUG_assert(emb);
   return emb;
 }
 
@@ -1637,7 +1637,7 @@ write_epilogue(texttopdf_doc_t *doc)
          (bits_used(emb->subset, emb->font->sfnt->numGlyphs)))
       {
         emb->font->fobj=cfPDFOutWriteFont(doc->pdf,emb);
-        assert(emb->font->fobj);
+        DEBUG_assert(emb->font->fobj);
       }
     }
   }
@@ -1703,7 +1703,7 @@ write_page(texttopdf_doc_t *doc)
                "endobj\n");
   
   int len_obj=cfPDFOutAddXRef(doc->pdf);
-  assert(len_obj==content+1);
+  DEBUG_assert(len_obj==content+1);
   cfPDFOutPrintF(doc->pdf,"%d 0 obj\n"
                "%ld\n"
                "endobj\n",
@@ -1804,9 +1804,9 @@ write_prolog(const char *title,           /* I - Title of job */
   * {{{ Output the PDF header...
   */
 
-  assert(!(doc->pdf));
+  DEBUG_assert(!(doc->pdf));
   doc->pdf = cfPDFOutNew();
-  assert(doc->pdf);
+  DEBUG_assert(doc->pdf);
 
   cfPDFOutBeginPDF(doc->pdf);
   cfPDFOutPrintF(doc->pdf,"%%cupsRotation: %d\n",
index 87c0561d5f5b2c6999be92746fb66991600efd8f..8fcb716cede8f90e6687d108ccb4dee0d791916e 100644 (file)
@@ -37,7 +37,6 @@
 #include <memory.h>
 #include <ctype.h>
 #include <stdarg.h>
-#include <assert.h>
 #include <unistd.h>
 #include <sys/wait.h>
 #include <math.h>
@@ -101,7 +100,6 @@ jobparams_t  *job = NULL;
 
 jobparams_t * get_current_job()
 {
-    assert(job);
     return job;
 }
 
index 1a1072f7e9d7446ccba29e56b7f01333737ab160..ef848b3663a29d0dcfd791e492ba6a1b8f8fd6aa 100644 (file)
@@ -26,7 +26,6 @@
 #include "util.h"
 #include <stdlib.h>
 #include <ctype.h>
-#include <assert.h>
 #include <regex.h>
 #include <string.h>
 #include <math.h>
@@ -482,7 +481,8 @@ static param_t * option_find_param_index(option_t *opt, const char *name, int *i
 static choice_t * option_find_choice(option_t *opt, const char *name)
 {
     choice_t *choice;
-    assert(opt && name);
+    if (!opt || !name)
+      return NULL;
     for (choice = opt->choicelist; choice; choice = choice->next) {
         if (!strcasecmp(choice->value, name))
             return choice;
@@ -815,11 +815,14 @@ void build_foomatic_custom_command(dstr_t *cmd, option_t *opt, const char *value
     if (!opt->proto && !strcmp(opt->name, "PageSize"))
     {
         choice_t *choice = option_find_choice(opt, "Custom");
-        char ** paramvalues = paramvalues_from_string(opt, values);
+        char **paramvalues = NULL;
         char width[30], height[30];
         int pos;
 
-        assert(choice);
+        if (!choice)
+         return;
+
+       paramvalues = paramvalues_from_string(opt, values);
 
         /* Get rid of the trailing ".00000", it confuses ghostscript */
         snprintf(width, 20, "%d", atoi(paramvalues[0]));
index b3e59a050fe9a32d1b38a34a92338e422ca14e2e..706e52ba693381a9d5ac24d79d6efa0f3860303c 100644 (file)
@@ -28,7 +28,6 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <stdarg.h>
-#include <assert.h>
 #include <errno.h>
 
 
@@ -981,7 +980,8 @@ void list_prepend(list_t *list, void *data)
 {
     listitem_t *item;
 
-    assert(list);
+    if (!list)
+      return;
 
     item = malloc(sizeof(listitem_t));
     item->data = data;
@@ -1003,7 +1003,8 @@ void list_append(list_t *list, void *data)
 {
     listitem_t *item;
 
-    assert(list);
+    if (!list)
+      return;
 
     item = malloc(sizeof(listitem_t));
     item->data = data;
@@ -1023,7 +1024,8 @@ void list_append(list_t *list, void *data)
 
 void list_remove(list_t *list, listitem_t *item)
 {
-    assert(item);
+    if (!list || !item)
+      return;
 
     if (item->prev)
         item->prev->next = item->next;
index 6781ef15ae2eeb4813cd66a079724132340fe584..63ba1464522982e342125a35e47ee879c6dfb69a 100644 (file)
@@ -1,5 +1,5 @@
 #include "pdfutils.h"
-#include <assert.h>
+#include "debug-internal.h"
 #include <string.h>
 
 int main()
@@ -7,7 +7,7 @@ int main()
   cf_pdf_out_t *pdf;
 
   pdf=cfPDFOutNew();
-  assert(pdf);
+  DEBUG_assert(pdf);
 
   cfPDFOutBeginPDF(pdf);
 
index 3fd4baadb1aff224f2a7da8c35d46106eb94bafa..efc329a9a3034b3c9450be8deb5a3a33c3cdf025 100644 (file)
@@ -1,6 +1,6 @@
 #include "pdfutils.h"
 #include "config.h"
-#include <assert.h>
+#include "debug-internal.h"
 #include "fontembed/embed.h"
 #include "fontembed/sfnt.h"
 
@@ -8,8 +8,8 @@
 
 static inline void write_string(cf_pdf_out_t *pdf,EMB_PARAMS *emb,const char *str) // {{{
 {
-  assert(pdf);
-  assert(emb);
+  DEBUG_assert(pdf);
+  DEBUG_assert(emb);
   int iA;
 
   if (emb->plan&EMB_A_MULTIBYTE) {
@@ -35,7 +35,7 @@ int main()
   cf_pdf_out_t *pdf;
 
   pdf=cfPDFOutNew();
-  assert(pdf);
+  DEBUG_assert(pdf);
 
   cfPDFOutBeginPDF(pdf);
 
@@ -53,7 +53,7 @@ int main()
     printf("Font %s was not loaded, exiting.\n", TESTFONT);
     return 1;
   }
-  assert(otf);
+  DEBUG_assert(otf);
   FONTFILE *ff=fontfile_open_sfnt(otf);
   EMB_PARAMS *emb=emb_new(ff,
                           EMB_DEST_PDF16,
@@ -77,7 +77,7 @@ int main()
   cfPDFOutPrintF(pdf,"\nendstream\n"
                     "endobj\n");
   const int clobj=cfPDFOutAddXRef(pdf);
-  assert(clobj==cobj+1);
+  DEBUG_assert(clobj==cobj+1);
   cfPDFOutPrintF(pdf,"%d 0 obj\n"
                     "%ld\n"
                     "endobj\n"
@@ -85,7 +85,7 @@ int main()
 
   // font
   int font_obj=cfPDFOutWriteFont(pdf,emb);
-  assert(font_obj);
+  DEBUG_assert(font_obj);
 
   int obj=cfPDFOutAddXRef(pdf);
   cfPDFOutPrintF(pdf,"%d 0 obj\n"
diff --git a/fontembed/debug-internal.h b/fontembed/debug-internal.h
new file mode 100644 (file)
index 0000000..f40dca5
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Internal debugging macros for libfontembed.
+ *
+ * Copyright © 2007-2018 by Apple Inc.
+ * Copyright © 1997-2005 by Easy Software Products.
+ *
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more
+ * information.
+ */
+
+#ifndef _FONTEMBED_DEBUG_INTERNAL_H_
+#  define _FONTEMBED_DEBUG_INTERNAL_H_
+
+
+/*
+ * C++ magic...
+ */
+
+#  ifdef __cplusplus
+extern "C" {
+#  endif /* __cplusplus */
+
+
+/*
+ * The debug macros are used if you compile with DEBUG defined.
+ *
+ * Usage:
+ *
+ *   DEBUG_assert(boolean expression);
+ */
+
+#  ifdef DEBUG
+#    include <assert.h>
+#    define DEBUG_assert(x) assert(x)
+#  else
+#    define DEBUG_assert(x)
+#  endif /* DEBUG */
+
+#  ifdef __cplusplus
+}
+#  endif /* __cplusplus */
+
+#endif /* !_FONTEMBED_DEBUG_INTERNAL_H_ */
index 439bf698512f2dbaabd0f5d246aeb90f977b76af..09ada5c1dce0ebbd97d96b57efa473e32f943da9 100644 (file)
@@ -1,22 +1,22 @@
 #include "dynstring-private.h"
+#include "debug-internal.h"
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <assert.h>
 
 int dyn_init(DYN_STRING *ds,int reserve_size) // {{{
 {
-  assert(ds);
-  assert(reserve_size>0);
+  DEBUG_assert(ds);
+  DEBUG_assert(reserve_size>0);
 
   ds->len=0;
   ds->alloc=reserve_size;
   ds->buf=malloc(ds->alloc+1);
   if (!ds->buf) {
     fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
-    assert(0);
+    DEBUG_assert(0);
     ds->len=-1;
     return -1;
   }
@@ -26,7 +26,7 @@ int dyn_init(DYN_STRING *ds,int reserve_size) // {{{
 
 void dyn_free(DYN_STRING *ds) // {{{
 {
-  assert(ds);
+  DEBUG_assert(ds);
 
   ds->len=-1;
   ds->alloc=0;
@@ -37,8 +37,8 @@ void dyn_free(DYN_STRING *ds) // {{{
 
 int dyn_ensure(DYN_STRING *ds,int free_space) // {{{
 {
-  assert(ds);
-  assert(free_space);
+  DEBUG_assert(ds);
+  DEBUG_assert(free_space);
 
   if (ds->len<0) {
     return -1;
@@ -51,7 +51,7 @@ int dyn_ensure(DYN_STRING *ds,int free_space) // {{{
   if (!tmp) {
     ds->len=-1;
     fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
-    assert(0);
+    DEBUG_assert(0);
     return -1;
   }
   ds->buf=tmp;
@@ -61,7 +61,7 @@ int dyn_ensure(DYN_STRING *ds,int free_space) // {{{
 
 int dyn_vprintf(DYN_STRING *ds,const char *fmt,va_list ap) // {{{
 {
-  assert(ds);
+  DEBUG_assert(ds);
 
   int need,len=strlen(fmt)+100;
   va_list va;
index 0b242839af3e4e5cb3daa63caaab327862a3fd21..cf90bc0ad795d4ef12605e68fd8cdd9ee0d48d46 100644 (file)
@@ -2,7 +2,7 @@
 #include "embed-pdf.h" // already included fron embed.h ...
 #include "embed-pdf-int-private.h"
 #include "embed-sfnt-int-private.h"
-#include <assert.h>
+#include "debug-internal.h"
 #include <errno.h>
 #include <string.h>
 #include <time.h>
@@ -38,11 +38,11 @@ static inline int emb_multibyte(EMB_PARAMS *emb) // {{{
 
 static const char *emb_pdf_escape_name(const char *name,int len) // {{{ // - statically allocated buffer
 {
-  assert(name);
+  DEBUG_assert(name);
   if (len==-1) {
     len=strlen(name);
   }
-  assert(len<=127); // pdf implementation limit
+  DEBUG_assert(len<=127); // pdf implementation limit
 
   static char buf[128*3];
   int iA,iB;
@@ -66,7 +66,7 @@ static const char *emb_pdf_escape_name(const char *name,int len) // {{{ // - sta
 // this is in the font dict
 const char *emb_pdf_get_font_subtype(EMB_PARAMS *emb) // {{{
 {
-  assert(emb);
+  DEBUG_assert(emb);
   return emb_pdf_font_subtype[emb->outtype][emb_multibyte(emb)];
 }
 // }}}
@@ -74,7 +74,7 @@ const char *emb_pdf_get_font_subtype(EMB_PARAMS *emb) // {{{
 // in font descriptor
 const char *emb_pdf_get_fontfile_key(EMB_PARAMS *emb) // {{{
 {
-  assert(emb);
+  DEBUG_assert(emb);
   return emb_pdf_fontfile_key[emb->outtype];
 }
 // }}}
@@ -82,7 +82,7 @@ const char *emb_pdf_get_fontfile_key(EMB_PARAMS *emb) // {{{
 // this is what to put in the font-stream dict
 const char *emb_pdf_get_fontfile_subtype(EMB_PARAMS *emb) // {{{
 {
-  assert(emb);
+  DEBUG_assert(emb);
   return emb_pdf_fontfile_subtype[emb->outtype][emb_multibyte(emb)];
 }
 // }}}
@@ -94,26 +94,26 @@ static EMB_PDF_FONTDESCR *emb_pdf_fd_new(const char *fontname,
                                   const char *cid_ordering, // or supplement==-1
                                   int cid_supplement) // -1 for non-cid
 {
-  assert(fontname);
+  DEBUG_assert(fontname);
   EMB_PDF_FONTDESCR *ret;
 
   int len=sizeof(EMB_PDF_FONTDESCR);
   if (subset_tag) {
-    assert(strlen(subset_tag)==6);
+    DEBUG_assert(strlen(subset_tag)==6);
     len+=7;
   }
   len+=strlen(fontname)+1;
   if (cid_supplement>=0) { // cid font
     len+=12; // space for panose
-    assert(cid_registry);
-    assert(cid_ordering);
+    DEBUG_assert(cid_registry);
+    DEBUG_assert(cid_ordering);
     len+=strlen(cid_registry)+1;
     len+=strlen(cid_ordering)+1;
   }
   ret=calloc(1,len);
   if (!ret) {
     fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
-    assert(0);
+    DEBUG_assert(0);
     return NULL;
   }
 
@@ -150,7 +150,7 @@ static EMB_PDF_FONTDESCR *emb_pdf_fd_new(const char *fontname,
 
 EMB_PDF_FONTDESCR *emb_pdf_fontdescr(EMB_PARAMS *emb) // {{{ -  to be freed by user
 {
-  assert(emb);
+  DEBUG_assert(emb);
 
   const char *subset_tag=NULL;
   // {{{ generate pdf subtag
@@ -173,13 +173,13 @@ EMB_PDF_FONTDESCR *emb_pdf_fontdescr(EMB_PARAMS *emb) // {{{ -  to be freed by u
 
   const char *fontname=NULL;
   if ( (emb->intype==EMB_FMT_TTF)||(emb->intype==EMB_FMT_OTF) ) { // TODO? use fontinfo from CFF when outtype==CFT, etc.?
-    assert(emb->font->sfnt);
+    DEBUG_assert(emb->font->sfnt);
     fontname=emb_otf_get_fontname(emb->font->sfnt);
   } else if (emb->outtype==EMB_FMT_STDFONT) {
     return NULL;
   } else {
     fprintf(stderr,"NOT IMPLEMENTED\n");
-    assert(0);
+    DEBUG_assert(0);
     return NULL;
   }
 
@@ -196,7 +196,7 @@ EMB_PDF_FONTDESCR *emb_pdf_fontdescr(EMB_PARAMS *emb) // {{{ -  to be freed by u
   if ( (emb->intype==EMB_FMT_TTF)||(emb->intype==EMB_FMT_OTF) ) {
     emb_otf_get_pdf_fontdescr(emb->font->sfnt,ret);
   } else {
-    assert(0);
+    DEBUG_assert(0);
   }
   return ret;
 }
@@ -204,11 +204,11 @@ EMB_PDF_FONTDESCR *emb_pdf_fontdescr(EMB_PARAMS *emb) // {{{ -  to be freed by u
 
 EMB_PDF_FONTWIDTHS *emb_pdf_fw_new(int datasize) // {{{
 {
-  assert(datasize>=0);
+  DEBUG_assert(datasize>=0);
   EMB_PDF_FONTWIDTHS *ret=calloc(1,sizeof(EMB_PDF_FONTWIDTHS)+datasize*sizeof(int));
   if (!ret) {
     fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
-    assert(0);
+    DEBUG_assert(0);
     return NULL;
   }
   return ret;
@@ -218,7 +218,7 @@ EMB_PDF_FONTWIDTHS *emb_pdf_fw_new(int datasize) // {{{
 // if default_width==-1: default_width will be estimated
 EMB_PDF_FONTWIDTHS *emb_pdf_fw_cidwidths(const BITSET glyphs,int len,int default_width,int (*getGlyphWidth)(void *context,int gid),void *context) // {{{ glyphs==NULL -> output all
 {
-  assert(getGlyphWidth);
+  DEBUG_assert(getGlyphWidth);
 
   FREQUENT *freq=NULL;
   if (default_width<0) {
@@ -256,7 +256,7 @@ EMB_PDF_FONTWIDTHS *emb_pdf_fw_cidwidths(const BITSET glyphs,int len,int default
     default_width=frequent_get(freq,0);
     free(freq);
   }
-  assert(default_width>0);
+  DEBUG_assert(default_width>0);
 
   // now create the array
   EMB_PDF_FONTWIDTHS *ret=emb_pdf_fw_new(size+1);
@@ -334,10 +334,10 @@ EMB_PDF_FONTWIDTHS *emb_pdf_fw_cidwidths(const BITSET glyphs,int len,int default
 //   -> encoding has a "len";  len<256
 EMB_PDF_FONTWIDTHS *emb_pdf_fontwidths(EMB_PARAMS *emb) // {{{
 {
-  assert(emb);
+  DEBUG_assert(emb);
 
   if ( (emb->intype==EMB_FMT_TTF)||(emb->intype==EMB_FMT_OTF) ) {
-    assert(emb->font->sfnt);
+    DEBUG_assert(emb->font->sfnt);
     if (emb->plan&EMB_A_MULTIBYTE) {
       return emb_otf_get_pdf_cidwidths(emb->font->sfnt,emb->subset);
     } else {
@@ -345,7 +345,7 @@ EMB_PDF_FONTWIDTHS *emb_pdf_fontwidths(EMB_PARAMS *emb) // {{{
     }
   } else {
     fprintf(stderr,"NOT IMPLEMENTED\n");
-    assert(0);
+    DEBUG_assert(0);
     return NULL;
   }
 }
@@ -356,7 +356,7 @@ EMB_PDF_FONTWIDTHS *emb_pdf_fontwidths(EMB_PARAMS *emb) // {{{
 
 #define NEXT /* {{{ */ \
   if ( (len<0)||(len>=size) ) { \
-    assert(0); \
+    DEBUG_assert(0); \
     free(ret); \
     return NULL; \
   } \
@@ -366,8 +366,8 @@ EMB_PDF_FONTWIDTHS *emb_pdf_fontwidths(EMB_PARAMS *emb) // {{{
 // TODO? /CIDSet    TODO... /FontFamily /FontStretch /FontWeight (PDF1.5?) would be nice...
 char *emb_pdf_simple_fontdescr(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,int fontfile_obj_ref) // {{{ - to be freed by user
 {
-  assert(emb);
-  assert(fdes);
+  DEBUG_assert(emb);
+  DEBUG_assert(fdes);
 
   char *ret=NULL,*pos;
   int len,size;
@@ -416,7 +416,7 @@ char *emb_pdf_simple_fontdescr(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,int fontf
     len=snprintf(pos,size,"  /Style << /Panose <");
     NEXT;
     if (size<30) {
-      assert(0);
+      DEBUG_assert(0);
       free(ret);
       return NULL;
     }
@@ -442,9 +442,9 @@ char *emb_pdf_simple_fontdescr(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,int fontf
 
 char *emb_pdf_simple_font(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,EMB_PDF_FONTWIDTHS *fwid,int fontdescr_obj_ref) // {{{ - to be freed by user
 {
-  assert(emb);
-  assert(fdes);
-  assert(fwid);
+  DEBUG_assert(emb);
+  DEBUG_assert(fdes);
+  DEBUG_assert(fwid);
 
   int iA,iB;
   DYN_STRING ret;
@@ -462,7 +462,7 @@ char *emb_pdf_simple_font(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,EMB_PDF_FONTWI
                   fontdescr_obj_ref);
 
   if (emb->plan&EMB_A_MULTIBYTE) { // multibyte
-    assert(fwid->warray);
+    DEBUG_assert(fwid->warray);
     dyn_printf(&ret,"  /CIDSystemInfo <<\n"
                     "    /Registry (%s)\n"
                     "    /Ordering (%s)\n"
@@ -496,7 +496,7 @@ char *emb_pdf_simple_font(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,EMB_PDF_FONTWI
       dyn_printf(&ret,"]\n");
     }
   } else { // "not std14"
-    assert(fwid->widths);
+    DEBUG_assert(fwid->widths);
     dyn_printf(&ret,
                     "  /Encoding /MacRomanEncoding\n"  // optional; TODO!!!!!
 //                    "  /ToUnicode ?\n"  // optional
@@ -513,7 +513,7 @@ char *emb_pdf_simple_font(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,EMB_PDF_FONTWI
   dyn_printf(&ret,">>\n");
   if (ret.len==-1) {
     dyn_free(&ret);
-    assert(0);
+    DEBUG_assert(0);
     return NULL;
   }
 
@@ -527,8 +527,8 @@ char *emb_pdf_simple_font(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,EMB_PDF_FONTWI
 // NOTE: this is _additionally_ to emb_pdf_simple_font()!
 char *emb_pdf_simple_cidfont(EMB_PARAMS *emb,const char *fontname,int descendant_obj_ref) // {{{ - to be freed by user
 {
-  assert(emb);
-  assert(fontname);
+  DEBUG_assert(emb);
+  DEBUG_assert(fontname);
 
   char *ret=NULL,*pos;
   int len,size;
@@ -568,8 +568,8 @@ char *emb_pdf_simple_cidfont(EMB_PARAMS *emb,const char *fontname,int descendant
 
 char *emb_pdf_simple_stdfont(EMB_PARAMS *emb) // {{{ - to be freed by user
 {
-  assert(emb);
-  assert(emb->font->stdname);
+  DEBUG_assert(emb);
+  DEBUG_assert(emb->font->stdname);
 
   char *ret=NULL,*pos;
   int len,size;
index ec49a6749cfdf6f906152c4bc2ed8cefe7a53481..f754a9f5033758d9dd53af8655efebd7e5eade7e 100644 (file)
@@ -3,7 +3,7 @@
 #include "embed-sfnt-int-private.h"
 #include "sfnt.h"
 #include "sfnt-int-private.h"
-#include <assert.h>
+#include "debug-internal.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -17,9 +17,9 @@ EMB_RIGHT_TYPE emb_otf_get_rights(OTF_FILE *otf) // {{{
   if (os2) {
     const unsigned short os2_version=get_USHORT(os2);
     // check len
-    assert( (os2_version!=0x0000)||(len==78) );
-    assert( (os2_version!=0x0001)||(len==86) );
-    assert( (os2_version<0x0002)||(os2_version>0x0004)||(len==96) );
+    DEBUG_assert( (os2_version!=0x0000)||(len==78) );
+    DEBUG_assert( (os2_version!=0x0001)||(len==86) );
+    DEBUG_assert( (os2_version<0x0002)||(os2_version>0x0004)||(len==96) );
     if (os2_version<=0x0004) {
       // get rights
       unsigned short fsType=get_USHORT(os2+8);
@@ -85,7 +85,7 @@ void emb_otf_get_pdf_fontdescr(OTF_FILE *otf,EMB_PDF_FONTDESCR *ret) // {{{
 //  TODO
 //  ... fill in struct
   char *head=otf_get_table(otf,OTF_TAG('h','e','a','d'),&len);
-  assert(head); // version is 1.0 from otf_load
+  DEBUG_assert(head); // version is 1.0 from otf_load
   ret->bbxmin=get_SHORT(head+36)*1000/otf->unitsPerEm;
   ret->bbymin=get_SHORT(head+38)*1000/otf->unitsPerEm;
   ret->bbxmax=get_SHORT(head+40)*1000/otf->unitsPerEm;
@@ -94,15 +94,15 @@ void emb_otf_get_pdf_fontdescr(OTF_FILE *otf,EMB_PDF_FONTDESCR *ret) // {{{
   free(head);
 
   char *post=otf_get_table(otf,OTF_TAG('p','o','s','t'),&len);
-  assert(post);
+  DEBUG_assert(post);
   const unsigned int post_version=get_ULONG(post);
   // check length
-  assert( (post_version!=0x00010000)||(len==32) );
-  assert( (post_version!=0x00020000)||(len>=34+2*otf->numGlyphs) );
-  assert( (post_version!=0x00025000)||(len==35+otf->numGlyphs) );
-  assert( (post_version!=0x00030000)||(len==32) );
-  assert( (post_version!=0x00020000)||(get_USHORT(post+32)==otf->numGlyphs) ); // v4?
-//  assert( (post_version==0x00030000)==(!!(otf->flags&OTF_F_FMT_CFF)) ); // ghostscript embedding does this..
+  DEBUG_assert( (post_version!=0x00010000)||(len==32) );
+  DEBUG_assert( (post_version!=0x00020000)||(len>=34+2*otf->numGlyphs) );
+  DEBUG_assert( (post_version!=0x00025000)||(len==35+otf->numGlyphs) );
+  DEBUG_assert( (post_version!=0x00030000)||(len==32) );
+  DEBUG_assert( (post_version!=0x00020000)||(get_USHORT(post+32)==otf->numGlyphs) ); // v4?
+//  DEBUG_assert( (post_version==0x00030000)==(!!(otf->flags&OTF_F_FMT_CFF)) ); // ghostscript embedding does this..
   // TODO: v4 (apple) :  uint16 reencoding[numGlyphs]
   if ( (post_version==0x00010000)||
        (post_version==0x00020000)||
@@ -122,9 +122,9 @@ void emb_otf_get_pdf_fontdescr(OTF_FILE *otf,EMB_PDF_FONTDESCR *ret) // {{{
   if (os2) {
     const unsigned short os2_version=get_USHORT(os2);
     // check len
-    assert( (os2_version!=0x0000)||(len==78) );
-    assert( (os2_version!=0x0001)||(len==86) );
-    assert( (os2_version<0x0002)||(os2_version>0x0004)||(len==96) );
+    DEBUG_assert( (os2_version!=0x0000)||(len==78) );
+    DEBUG_assert( (os2_version!=0x0001)||(len==86) );
+    DEBUG_assert( (os2_version<0x0002)||(os2_version>0x0004)||(len==96) );
     if (os2_version<=0x0004) {
 
       // from PDF14Deltas.pdf, pg 113
@@ -193,7 +193,7 @@ void emb_otf_get_pdf_fontdescr(OTF_FILE *otf,EMB_PDF_FONTDESCR *ret) // {{{
     const unsigned short d_gid=otf_from_unicode(otf,'.');
     if (d_gid) { // stemV=bbox['.'].width;
       len=otf_get_glyph(otf,d_gid);
-      assert(len>=10);
+      DEBUG_assert(len>=10);
       ret->stemV=(get_SHORT(otf->gly+6)-get_SHORT(otf->gly+2))*1000/otf->unitsPerEm;
     } else {
       if (macStyle&1) { // bold
@@ -224,7 +224,7 @@ void emb_otf_get_pdf_fontdescr(OTF_FILE *otf,EMB_PDF_FONTDESCR *ret) // {{{
 // HINT: caller sets len == otf->numGlyphs   (only when not using encoding...)
 EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_widths(OTF_FILE *otf,const unsigned short *encoding,int len,const BITSET glyphs) // {{{ glyphs==NULL -> all from 0 to len
 {
-  assert(otf);
+  DEBUG_assert(otf);
 
   int first=len,last=0;
   int iA;
@@ -271,7 +271,7 @@ EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_widths(OTF_FILE *otf,const unsigned short *e
     const int gid=(encoding)?encoding[first]:otf_from_unicode(otf,first); // TODO
     if (gid>=otf->numGlyphs) {
       fprintf(stderr,"Bad glyphid\n");
-      assert(0);
+      DEBUG_assert(0);
       free(ret);
       return NULL;
     }
@@ -294,7 +294,7 @@ static int emb_otf_pdf_glyphwidth(void *context,int gid) // {{{
 
 EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_cidwidths(OTF_FILE *otf,const BITSET glyphs) // {{{ // glyphs==NULL -> output all
 {
-  assert(otf);
+  DEBUG_assert(otf);
 
   // ensure hmtx is there
   if (!otf->hmtx) {
@@ -331,7 +331,7 @@ static const char *emb_otf_get_post_name(const char *post,unsigned short gid) //
     }
   } else if (post_version==0x00020000) {
     const unsigned short num_glyphs=get_USHORT(post+32);
-    // assert(num_glyphs==otf->numGlyphs);
+    // DEBUG_assert(num_glyphs==otf->numGlyphs);
     if (gid<num_glyphs) {
       unsigned short idx=get_USHORT(post+34+2*gid);
       if (idx<258) {
index 26607d6d73e9e08df50040b394ee80c5ed0d2c6a..93104ce267f16d1b9c0343c36507aca749128174 100644 (file)
@@ -1,6 +1,6 @@
 #include "embed.h"
 #include "embed-sfnt-int-private.h"
-#include <assert.h>
+#include "debug-internal.h"
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
@@ -8,8 +8,8 @@
 
 static inline int copy_file(FILE *f,OUTPUT_FN output,void *context) // {{{
 {
-  assert(f);
-  assert(output);
+  DEBUG_assert(f);
+  DEBUG_assert(output);
 
   char buf[4096];
   int iA,ret=0;
@@ -58,7 +58,7 @@ static inline int copy_file(FILE *f,OUTPUT_FN output,void *context) // {{{
 
 EMB_PARAMS *emb_new(FONTFILE *font,EMB_DESTINATION dest,EMB_CONSTRAINTS mode) // {{{
 {
-  assert(font);
+  DEBUG_assert(font);
 
   EMB_PARAMS *ret=calloc(1,sizeof(EMB_PARAMS));
   if (!ret) {
@@ -100,7 +100,7 @@ EMB_PARAMS *emb_new(FONTFILE *font,EMB_DESTINATION dest,EMB_CONSTRAINTS mode) //
     ret->intype=EMB_FMT_STDFONT;
     ret->rights=EMB_RIGHT_NONE;
   } else {
-    assert(0);
+    DEBUG_assert(0);
   }
 /*
   if ( (ret->intype==EMB_FMT_CFF)&&
@@ -176,7 +176,7 @@ EMB_PARAMS *emb_new(FONTFILE *font,EMB_DESTINATION dest,EMB_CONSTRAINTS mode) //
 
 int emb_embed(EMB_PARAMS *emb,OUTPUT_FN output,void *context) // {{{
 {
-  assert(emb);
+  DEBUG_assert(emb);
 
   if (emb->dest==EMB_DEST_NATIVE) {
   } else if (emb->dest<=EMB_DEST_PS) {
@@ -202,7 +202,7 @@ int emb_embed(EMB_PARAMS *emb,OUTPUT_FN output,void *context) // {{{
     }
   } else if (emb->dest<=EMB_DEST_PDF16) {
     if (emb->outtype==EMB_FMT_TTF) {
-      assert(emb->font->sfnt);
+      DEBUG_assert(emb->font->sfnt);
       if (emb->plan&EMB_A_SUBSET) {
         return otf_subset(emb->font->sfnt,emb->subset,output,context);
       } else if (emb->font->sfnt->numTTC) { //
@@ -215,11 +215,11 @@ int emb_embed(EMB_PARAMS *emb,OUTPUT_FN output,void *context) // {{{
         if (emb->plan&EMB_A_T1_TO_CFF) {
           // TODO
         } else {
-          // assert(emb->font->cff);
+          // DEBUG_assert(emb->font->cff);
           // TODO
         }
       } else {
-        assert(emb->font->sfnt);
+        DEBUG_assert(emb->font->sfnt);
         if (emb->plan&EMB_A_SUBSET) {
           return otf_subset_cff(emb->font->sfnt,emb->subset,output,context);
         } else {
@@ -228,7 +228,7 @@ int emb_embed(EMB_PARAMS *emb,OUTPUT_FN output,void *context) // {{{
       }
     } else if (emb->outtype==EMB_FMT_CFF) {
       if (emb->plan&EMB_A_OTF_TO_CFF) {
-        assert(emb->font->sfnt);
+        DEBUG_assert(emb->font->sfnt);
         if (emb->plan&EMB_A_SUBSET) {
           // TODO
         } else {
@@ -241,7 +241,7 @@ int emb_embed(EMB_PARAMS *emb,OUTPUT_FN output,void *context) // {{{
   }
 
   fprintf(stderr,"NOT IMPLEMENTED\n");
-  assert(0);
+  DEBUG_assert(0);
   return -1;
 }
 // }}}
index 703126c5da353f5828c41e2764745f3f122459d4..e59121b2db5887c6beab744480fc010e225841c4 100644 (file)
@@ -1,5 +1,5 @@
 #include "fontfile.h"
-#include <assert.h>
+#include "debug-internal.h"
 #include <string.h>
 
 //FONTFILE *fontfile_open(const char *filename);
@@ -16,7 +16,7 @@ FONTFILE *fontfile_open(const char *filename)
 FONTFILE *fontfile_open_sfnt(OTF_FILE *otf) // {{{
 {
   if (!otf) {
-    assert(0);
+    DEBUG_assert(0);
     return NULL;
   }
   FONTFILE *ret=calloc(1,sizeof(FONTFILE));
@@ -29,7 +29,7 @@ FONTFILE *fontfile_open_sfnt(OTF_FILE *otf) // {{{
 
 FONTFILE *fontfile_open_std(const char *name) // {{{
 {
-  assert(name);
+  DEBUG_assert(name);
   FONTFILE *ret=calloc(1,sizeof(FONTFILE));
 
   ret->stdname=strdup(name);
index 7a06b4e4b65ceb4194b9c5f1c02c35118959bfc2..1b0674372c95eb0119750360f67b79cdc05258fb 100644 (file)
@@ -1,5 +1,5 @@
 #include "frequent-private.h"
-#include <assert.h>
+#include "debug-internal.h"
 #include <stdlib.h>
 
 // misra-gries
@@ -14,7 +14,7 @@ struct _FREQUENT {
 // size is the precision/return size: in sequence with n _add(), it will find at most >size elements with occurence > n/(size+1) times
 FREQUENT *frequent_new(int size) // {{{ - just free() it
 {
-  assert(size>0);
+  DEBUG_assert(size>0);
   FREQUENT *ret=malloc(sizeof(ret[0])+sizeof(ret->pair[0])*size);
   if (!ret) {
     return NULL;
@@ -35,7 +35,7 @@ FREQUENT *frequent_new(int size) // {{{ - just free() it
 
 void frequent_add(FREQUENT *freq,intptr_t key) // {{{
 {
-  assert(freq);
+  DEBUG_assert(freq);
   int iA,zero=-1;
   for (iA=freq->size-1;iA>=0;iA--) {
     if (freq->pair[iA].key==key) {
@@ -68,7 +68,7 @@ static int frequent_cmp(const void *a,const void *b) // {{{
 // true frequency is somewhere between (count-zero) and count
 intptr_t frequent_get(FREQUENT *freq,int pos) // {{{
 {
-  assert(freq);
+  DEBUG_assert(freq);
   if (!freq->sorted) {
     // sort by (count-zero)
     qsort(freq->pair,freq->size,sizeof(freq->pair[0]),frequent_cmp);
index 93785ccd20c1e50abf2a79b3b5bfa1fb0e1e184d..0de2bc3c70498d5a023b335ed3dff5898ff78af6 100644 (file)
@@ -1,17 +1,17 @@
 #include "sfnt.h"
 #include "sfnt-int-private.h"
+#include "bitset.h"
+#include "debug-internal.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include <assert.h>
-#include "bitset.h"
 
 int otf_ttc_extract(OTF_FILE *otf,OUTPUT_FN output,void *context) // {{{
 {
-  assert(otf);
-  assert(output);
-  assert(otf->numTTC);
+  DEBUG_assert(otf);
+  DEBUG_assert(output);
+  DEBUG_assert(otf->numTTC);
   int iA;
 
   struct _OTF_WRITE *otw;
@@ -82,18 +82,21 @@ static int otf_subset_glyf(OTF_FILE *otf,int curgid,int donegid,BITSET glyphs) /
   do {
     flags=get_USHORT(cur);
     const unsigned short sub_gid=get_USHORT(cur+2);
-    assert(sub_gid<otf->numGlyphs);
+    DEBUG_assert(sub_gid<otf->numGlyphs);
     if (!bit_check(glyphs,sub_gid)) {
       // bad: temporarily load sub glyph
       const int len=otf_get_glyph(otf,sub_gid);
-      assert(len>0);
+      DEBUG_assert(len>0);
       bit_set(glyphs,sub_gid);
       if (sub_gid<donegid) {
         ret+=len;
         ret+=otf_subset_glyf(otf,sub_gid,donegid,glyphs); // composite of composites?, e.g. in DejaVu
       }
-      const int res=otf_get_glyph(otf,curgid); // reload current glyph
-      assert(res);
+#ifdef DEBUG
+      const int res =
+#endif
+       otf_get_glyph(otf,curgid); // reload current glyph
+      DEBUG_assert(res);
     }
 
     // skip parameters
@@ -117,9 +120,9 @@ static int otf_subset_glyf(OTF_FILE *otf,int curgid,int donegid,BITSET glyphs) /
 // TODO: cmap only required in non-CID context
 int otf_subset(OTF_FILE *otf,BITSET glyphs,OUTPUT_FN output,void *context) // {{{ - returns number of bytes written
 {
-  assert(otf);
-  assert(glyphs);
-  assert(output);
+  DEBUG_assert(otf);
+  DEBUG_assert(glyphs);
+  DEBUG_assert(output);
 
   int iA,b,c;
 
@@ -134,13 +137,13 @@ int otf_subset(OTF_FILE *otf,BITSET glyphs,OUTPUT_FN output,void *context) // {{
     if (glyphs[b]&c) {
       int len=otf_get_glyph(otf,iA);
       if (len<0) {
-        assert(0);
+        DEBUG_assert(0);
         return -1;
       } else if (len>0) {
         glyfSize+=len;
         len=otf_subset_glyf(otf,iA,iA,glyphs);
         if (len<0) {
-          assert(0);
+          DEBUG_assert(0);
           return -1;
         }
         glyfSize+=len;
@@ -155,7 +158,7 @@ int otf_subset(OTF_FILE *otf,BITSET glyphs,OUTPUT_FN output,void *context) // {{
   char *new_glyf=malloc(glyfSize);
   if ( (!new_loca)||(!new_glyf) ) {
     fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
-    assert(0);
+    DEBUG_assert(0);
     free(new_loca);
     free(new_glyf);
     return -1;
@@ -168,7 +171,7 @@ int otf_subset(OTF_FILE *otf,BITSET glyphs,OUTPUT_FN output,void *context) // {{
       c=1;
     }
 
-    assert(offset%2==0);
+    DEBUG_assert(offset%2==0);
     // TODO? change format? if glyfSize<0x20000
     if (otf->indexToLocFormat==0) {
       set_USHORT(new_loca+iA*2,offset/2);
@@ -178,7 +181,7 @@ int otf_subset(OTF_FILE *otf,BITSET glyphs,OUTPUT_FN output,void *context) // {{
 
     if (glyphs[b]&c) {
       const int len=otf_get_glyph(otf,iA);
-      assert(len>=0);
+      DEBUG_assert(len>=0);
       memcpy(new_glyf+offset,otf->gly,len);
       offset+=len;
     }
@@ -189,7 +192,7 @@ int otf_subset(OTF_FILE *otf,BITSET glyphs,OUTPUT_FN output,void *context) // {{
   } else { // ==1
     set_ULONG(new_loca+otf->numGlyphs*4,offset);
   }
-  assert(offset==glyfSize);
+  DEBUG_assert(offset==glyfSize);
 
   // determine new tables.
   struct _OTF_WRITE otw[]={ // sorted
@@ -224,8 +227,8 @@ int otf_subset(OTF_FILE *otf,BITSET glyphs,OUTPUT_FN output,void *context) // {{
 // TODO no subsetting actually done (for now)
 int otf_subset_cff(OTF_FILE *otf,BITSET glyphs,OUTPUT_FN output,void *context) // {{{ - returns number of bytes written
 {
-  assert(otf);
-  assert(output);
+  DEBUG_assert(otf);
+  DEBUG_assert(output);
 
 // TODO char *new_cff=cff_subset(...);
 
@@ -259,8 +262,8 @@ int otf_subset_cff(OTF_FILE *otf,BITSET glyphs,OUTPUT_FN output,void *context) /
 
 static int copy_block(FILE *f,long pos,int length,OUTPUT_FN output,void *context) // {{{
 {
-  assert(f);
-  assert(output);
+  DEBUG_assert(f);
+  DEBUG_assert(output);
 
   char buf[4096];
   int iA,ret;
@@ -293,8 +296,8 @@ static int copy_block(FILE *f,long pos,int length,OUTPUT_FN output,void *context
 
 int otf_cff_extract(OTF_FILE *otf,OUTPUT_FN output,void *context) // {{{ - returns number of bytes written
 {
-  assert(otf);
-  assert(output);
+  DEBUG_assert(otf);
+  DEBUG_assert(output);
 
   int idx=otf_find_table(otf,OTF_TAG('C','F','F',' '));
   if (idx==-1) {
@@ -325,7 +328,7 @@ int otf_cff_extract(OTF_FILE *otf,OUTPUT_FN output,void *context) // {{{ - retur
   char *new_cff=malloc(cffSize);
   if (!new_cff) {
     fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
-    assert(0);
+    DEBUG_assert(0);
     return -1;
   }
 
index 00d3f56e6fdf02a1020b287e18e8a13941b82eb2..d512213966b36a7affe6673df17dfa33a17818d4 100644 (file)
@@ -1,10 +1,10 @@
 #include "sfnt.h"
+#include "sfnt-int-private.h"
+#include "debug-internal.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include <assert.h>
-#include "sfnt-int-private.h"
 
 // TODO?
 // get_SHORT(head+48) // fontDirectionHint
@@ -18,10 +18,10 @@ static void otf_bsearch_params(int num, // {{{
                                int *entrySelector,
                                int *rangeShift)
 {
-  assert(num>0);
-  assert(searchRange);
-  assert(entrySelector);
-  assert(rangeShift);
+  DEBUG_assert(num>0);
+  DEBUG_assert(searchRange);
+  DEBUG_assert(entrySelector);
+  DEBUG_assert(rangeShift);
 
   int iA,iB;
   for (iA=1,iB=0;iA<=num;iA<<=1,iB++) {}
@@ -66,7 +66,7 @@ static char *otf_bsearch(char *table, // {{{
 
 static OTF_FILE *otf_new(FILE *f) // {{{
 {
-  assert(f);
+  DEBUG_assert(f);
 
   OTF_FILE *ret;
   ret=calloc(1,sizeof(OTF_FILE));
@@ -88,7 +88,7 @@ static char *otf_read(OTF_FILE *otf,char *buf,long pos,int length) // {{{
   if (length==0) {
     return buf;
   } else if (length<0) {
-    assert(0);
+    DEBUG_assert(0);
     return NULL;
   }
 
@@ -345,7 +345,7 @@ OTF_FILE *otf_load(const char *file) // {{{
 
 void otf_close(OTF_FILE *otf) // {{{
 {
-  assert(otf);
+  DEBUG_assert(otf);
   if (otf) {
     free(otf->gly);
     free(otf->cmap);
@@ -392,7 +392,7 @@ int otf_find_table(OTF_FILE *otf,unsigned int tag) // {{{  - table_index  or -1
     return -1;
   }
   char target[]={(tag>>24),(tag>>16),(tag>>8),tag};
-  //  assert(get_USHORT(buf+6)+get_USHORT(buf+10)==16*numTables);
+  //  DEBUG_assert(get_USHORT(buf+6)+get_USHORT(buf+10)==16*numTables);
   char *result=otf_bsearch(tables,target,4,
                            get_USHORT(buf+6),
                            get_USHORT(buf+8),
@@ -421,8 +421,8 @@ int otf_find_table(OTF_FILE *otf,unsigned int tag) // {{{  - table_index  or -1
 
 char *otf_get_table(OTF_FILE *otf,unsigned int tag,int *ret_len) // {{{
 {
-  assert(otf);
-  assert(ret_len);
+  DEBUG_assert(otf);
+  DEBUG_assert(ret_len);
 
   const int idx=otf_find_table(otf,tag);
   if (idx==-1) {
@@ -453,7 +453,7 @@ char *otf_get_table(OTF_FILE *otf,unsigned int tag,int *ret_len) // {{{
 
 int otf_load_glyf(OTF_FILE *otf) // {{{  - 0 on success
 {
-  assert((otf->flags&OTF_F_FMT_CFF)==0); // not for CFF
+  DEBUG_assert((otf->flags&OTF_F_FMT_CFF)==0); // not for CFF
   int iA,len;
   // {{{ find glyf table
   iA=otf_find_table(otf,OTF_TAG('g','l','y','f'));
@@ -474,7 +474,7 @@ int otf_load_glyf(OTF_FILE *otf) // {{{  - 0 on success
   }
   if (otf->glyphOffsets) {
     free(otf->glyphOffsets);
-    assert(0);
+    DEBUG_assert(0);
   }
   otf->glyphOffsets=malloc((otf->numGlyphs+1)*sizeof(unsigned int));
   if (!otf->glyphOffsets) {
@@ -511,7 +511,7 @@ int otf_load_glyf(OTF_FILE *otf) // {{{  - 0 on success
   }
   if (otf->gly) {
     free(otf->gly);
-    assert(0);
+    DEBUG_assert(0);
   }
   otf->gly=malloc(maxGlyfLen*sizeof(char));
   if (!otf->gly) {
@@ -557,7 +557,7 @@ int otf_load_more(OTF_FILE *otf) // {{{  - 0 on success   => hhea,hmtx,name,[gly
   }
   if (otf->hmtx) {
     free(otf->hmtx);
-    assert(0);
+    DEBUG_assert(0);
   }
   otf->hmtx=hmtx;
   // }}}
@@ -584,7 +584,7 @@ int otf_load_more(OTF_FILE *otf) // {{{  - 0 on success   => hhea,hmtx,name,[gly
   }
   if (otf->name) {
     free(otf->name);
-    assert(0);
+    DEBUG_assert(0);
   }
   otf->name=name;
   // }}}
@@ -603,7 +603,7 @@ int otf_load_cmap(OTF_FILE *otf) // {{{  - 0 on success
        (get_USHORT(cmap)!=0x0000)|| // version
        (len<get_USHORT(cmap+2)*8+4) ) {
     fprintf(stderr,"Unsupported OTF font / cmap table \n");
-    assert(0);
+    DEBUG_assert(0);
     return -1;
   }
   // check bounds, find (3,0) or (3,1) [TODO?]
@@ -617,7 +617,7 @@ int otf_load_cmap(OTF_FILE *otf) // {{{  - 0 on success
          (offset+get_USHORT(ndata+2)>len) ) {
       fprintf(stderr,"Bad cmap table \n");
       free(cmap);
-      assert(0);
+      DEBUG_assert(0);
       return -1;
     }
     if ( (get_USHORT(nrec)==3)&&
@@ -629,7 +629,7 @@ int otf_load_cmap(OTF_FILE *otf) // {{{  - 0 on success
   }
   if (otf->cmap) {
     free(otf->cmap);
-    assert(0);
+    DEBUG_assert(0);
   }
   otf->cmap=cmap;
 
@@ -639,7 +639,7 @@ int otf_load_cmap(OTF_FILE *otf) // {{{  - 0 on success
 
 int otf_get_width(OTF_FILE *otf,unsigned short gid) // {{{  -1 on error
 {
-  assert(otf);
+  DEBUG_assert(otf);
 
   if (gid>=otf->numGlyphs) {
     return -1;
@@ -673,14 +673,14 @@ static int otf_name_compare(const void *a,const void *b) // {{{
 
 const char *otf_get_name(OTF_FILE *otf,int platformID,int encodingID,int languageID,int nameID,int *ret_len) // {{{
 {
-  assert(otf);
-  assert(ret_len);
+  DEBUG_assert(otf);
+  DEBUG_assert(ret_len);
 
   // ensure name is there
   if (!otf->name) {
     if (otf_load_more(otf)!=0) {
       *ret_len=-1;
-      assert(0);
+      DEBUG_assert(0);
       return NULL;
     }
   }
@@ -705,8 +705,8 @@ const char *otf_get_name(OTF_FILE *otf,int platformID,int encodingID,int languag
 
 int otf_get_glyph(OTF_FILE *otf,unsigned short gid) // {{{ result in >otf->gly, returns length, -1 on error
 {
-  assert(otf);
-  assert((otf->flags&OTF_F_FMT_CFF)==0); // not for CFF
+  DEBUG_assert(otf);
+  DEBUG_assert((otf->flags&OTF_F_FMT_CFF)==0); // not for CFF
 
   if (gid>=otf->numGlyphs) {
     return -1;
@@ -715,7 +715,7 @@ int otf_get_glyph(OTF_FILE *otf,unsigned short gid) // {{{ result in >otf->gly,
   // ensure >glyphOffsets and >gly is there
   if ( (!otf->gly)||(!otf->glyphOffsets) ) {
     if (otf_load_more(otf)!=0) {
-      assert(0);
+      DEBUG_assert(0);
       return -1;
     }
   }
@@ -725,7 +725,7 @@ int otf_get_glyph(OTF_FILE *otf,unsigned short gid) // {{{ result in >otf->gly,
     return 0;
   }
 
-  assert(otf->glyfTable->length>=otf->glyphOffsets[gid+1]);
+  DEBUG_assert(otf->glyfTable->length>=otf->glyphOffsets[gid+1]);
   if (!otf_read(otf,otf->gly,
                 otf->glyfTable->offset+otf->glyphOffsets[gid],len)) {
     return -1;
@@ -737,14 +737,14 @@ int otf_get_glyph(OTF_FILE *otf,unsigned short gid) // {{{ result in >otf->gly,
 
 unsigned short otf_from_unicode(OTF_FILE *otf,int unicode) // {{{ 0 = missing
 {
-  assert(otf);
-  assert( (unicode>=0)&&(unicode<65536) );
-//  assert((otf->flags&OTF_F_FMT_CFF)==0); // not for CFF, other method!
+  DEBUG_assert(otf);
+  DEBUG_assert( (unicode>=0)&&(unicode<65536) );
+//  DEBUG_assert((otf->flags&OTF_F_FMT_CFF)==0); // not for CFF, other method!
 
   // ensure >cmap and >unimap is there
   if (!otf->cmap) {
     if (otf_load_cmap(otf)!=0) {
-      assert(0);
+      DEBUG_assert(0);
       return 0; // TODO?
     }
   }
@@ -763,7 +763,7 @@ unsigned short otf_from_unicode(OTF_FILE *otf,int unicode) // {{{ 0 = missing
                            get_USHORT(otf->unimap+10),
                            get_USHORT(otf->unimap+12),1);
   if (result>=otf->unimap+14+segCountX2) { // outside of endCode[segCount]
-    assert(0); // bad font, no 0xffff sentinel
+    DEBUG_assert(0); // bad font, no 0xffff sentinel
     return 0;
   }
 
@@ -815,7 +815,7 @@ int otf_action_copy_head(void *param,int csum,OUTPUT_FN output,void *context) //
 {
   OTF_FILE *otf=param;
   const int table_no=otf_find_table(otf,OTF_TAG('h','e','a','d')); // we can't have csum AND table_no ... never mind!
-  assert(table_no!=-1);
+  DEBUG_assert(table_no!=-1);
   const OTF_DIRENT *table=otf->tables+table_no;
 
   if (!output) { // get checksum and unpadded length
@@ -947,7 +947,7 @@ int otf_write_sfnt(struct _OTF_WRITE *otw,unsigned int version,int numTables,OUT
   for (iA=0;iA<numTables;iA++) {
     char *entry=start+12+16*order[iA];
     const int res=(*otw[order[iA]].action)(otw[order[iA]].param,otw[order[iA]].length,NULL,&csum);
-    assert(res>=0);
+    DEBUG_assert(res>=0);
     if (otw[order[iA]].tag==OTF_TAG('h','e','a','d')) {
       headAt=order[iA];
     }
@@ -979,10 +979,10 @@ int otf_write_sfnt(struct _OTF_WRITE *otw,unsigned int version,int numTables,OUT
       free(start);
       return -1;
     }
-    assert(((res+3)&~3)==res); // correctly padded? (i.e. next line is just ret+=res;)
+    DEBUG_assert(((res+3)&~3)==res); // correctly padded? (i.e. next line is just ret+=res;)
     ret+=(res+3)&~3;
   }
-  assert(offset==ret);
+  DEBUG_assert(offset==ret);
   free(order);
   free(start);
 
index ffb4510026ce4e30b4ac9124495aac612c88f2e6..252b42d520745b556d55442223d30213f37ee68d 100644 (file)
@@ -3,7 +3,7 @@
 #include "embed.h"
 #include "config.h"
 #include "embed-sfnt-int-private.h"
-#include <assert.h>
+#include "debug-internal.h"
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -19,13 +19,13 @@ enum { WEIGHT_THIN=100,
 
 void show_post(OTF_FILE *otf) // {{{
 {
-  assert(otf);
+  DEBUG_assert(otf);
   int len=0;
   char *buf;
 
   buf=otf_get_table(otf,OTF_TAG('p','o','s','t'),&len);
   if (!buf) {
-    assert(len==-1);
+    DEBUG_assert(len==-1);
     printf("No post table\n");
     return;
   }
@@ -51,13 +51,13 @@ void show_post(OTF_FILE *otf) // {{{
 
 void show_name(OTF_FILE *otf) // {{{
 {
-  assert(otf);
+  DEBUG_assert(otf);
   int iA,len=0;
   char *buf;
 
   buf=otf_get_table(otf,OTF_TAG('n','a','m','e'),&len);
   if (!buf) {
-    assert(len==-1);
+    DEBUG_assert(len==-1);
     printf("No name table\n");
     return;
   }
@@ -97,23 +97,23 @@ void show_name(OTF_FILE *otf) // {{{
 
 void show_cmap(OTF_FILE *otf) // {{{
 {
-  assert(otf);
+  DEBUG_assert(otf);
   int iA,len=0;
 
   char *cmap=otf_get_table(otf,OTF_TAG('c','m','a','p'),&len);
   if (!cmap) {
-    assert(len==-1);
+    DEBUG_assert(len==-1);
     printf("No cmap table\n");
     return;
   }
   printf("cmap:\n");
-  assert(get_USHORT(cmap)==0x0000); // version
+  DEBUG_assert(get_USHORT(cmap)==0x0000); // version
   const int numTables=get_USHORT(cmap+2);
   printf("  numTables: %d\n",numTables);
   for (iA=0;iA<numTables;iA++) {
     const char *nrec=cmap+4+8*iA;
     const char *ndata=cmap+get_ULONG(nrec+4);
-    assert(ndata>=cmap+4+8*numTables);
+    DEBUG_assert(ndata>=cmap+4+8*numTables);
     printf("  platformID/encodingID: %d/%d\n"
            "  offset: %d  data (format: %d, length: %d, language: %d);\n",
            get_USHORT(nrec),get_USHORT(nrec+2),
@@ -126,12 +126,12 @@ void show_cmap(OTF_FILE *otf) // {{{
 
 void show_glyf(OTF_FILE *otf,int full) // {{{
 {
-  assert(otf);
+  DEBUG_assert(otf);
 
   // ensure >glyphOffsets and >gly is there
   if ( (!otf->gly)||(!otf->glyphOffsets) ) {
     if (otf_load_glyf(otf)!=0) {
-      assert(0);
+      DEBUG_assert(0);
       return;
     }
   }
@@ -140,7 +140,7 @@ void show_glyf(OTF_FILE *otf,int full) // {{{
   int compGlyf=0,zeroGlyf=0;
 
   // {{{ glyf
-  assert(otf->gly);
+  DEBUG_assert(otf->gly);
   for (iA=0;iA<otf->numGlyphs;iA++) {
     int len=otf_get_glyph(otf,iA);
     if (len==0) {
@@ -162,7 +162,7 @@ void show_glyf(OTF_FILE *otf,int full) // {{{
 
 void show_hmtx(OTF_FILE *otf) // {{{
 {
-  assert(otf);
+  DEBUG_assert(otf);
   int iA;
 
   otf_get_width(otf,0); // load table.
@@ -194,7 +194,7 @@ int main(int argc,char **argv)
     return 1;
   }
 
-  assert(otf);
+  DEBUG_assert(otf);
   if (otf->numTTC) {
     printf("TTC has %d fonts, using %d\n",otf->numTTC,otf->useTTC);
   }
index 881a4dca47d1209f96e01bb573477ea915f6550b..20225abf22e219e1c4c5e2cc7533b9e5189a4505 100644 (file)
@@ -1,7 +1,7 @@
 #include "embed.h"
 #include "config.h"
 #include "sfnt.h"
-#include <assert.h>
+#include "debug-internal.h"
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -10,7 +10,7 @@ static void example_outfn(const char *buf,int len,void *context) // {{{
   FILE *f=(FILE *)context;
   if (fwrite(buf,1,len,f)!=len) {
     fprintf(stderr,"Short write: %m\n");
-    assert(0);
+    DEBUG_assert(0);
     return;
   }
 }
@@ -47,8 +47,8 @@ static void example_outfn(const char *buf,int len,void *context) // {{{
 
 static inline void write_string(FILE *f,EMB_PARAMS *emb,const char *str) // {{{
 {
-  assert(f);
-  assert(emb);
+  DEBUG_assert(f);
+  DEBUG_assert(emb);
   int iA;
 
   if (emb->plan&EMB_A_MULTIBYTE) {
@@ -82,7 +82,7 @@ int main(int argc,char **argv)
     printf("Font %s was not loaded, exiting.\n", TESTFONT);
     return 1;
   }
-  assert(otf);
+  DEBUG_assert(otf);
   FONTFILE *ff=fontfile_open_sfnt(otf);
   EMB_PARAMS *emb=emb_new(ff,
                           EMB_DEST_PDF16,
@@ -90,7 +90,7 @@ int main(int argc,char **argv)
                           EMB_C_TAKE_FONTFILE);
 
   FILE *f=fopen("test.pdf","w");
-  assert(f);
+  DEBUG_assert(f);
   int xref[100],xrefpos=3;
   int stream_len;
 
@@ -109,9 +109,9 @@ int main(int argc,char **argv)
 
   // {{{ do font
   EMB_PDF_FONTDESCR *fdes=emb_pdf_fontdescr(emb);
-  assert(fdes);
+  DEBUG_assert(fdes);
   EMB_PDF_FONTWIDTHS *fwid=emb_pdf_fontwidths(emb);
-  assert(fwid);
+  DEBUG_assert(fwid);
 
   STREAMDICT;
   int ff_ref=xrefpos;
@@ -138,7 +138,7 @@ int main(int argc,char **argv)
   OBJ;
   const int fd_ref=xrefpos;
   char *res=emb_pdf_simple_fontdescr(emb,fdes,ff_ref);
-  assert(res);
+  DEBUG_assert(res);
   fputs(res,f);
   free(res);
   ENDOBJ;
@@ -146,7 +146,7 @@ int main(int argc,char **argv)
   OBJ;
   int f_ref=xrefpos;
   res=emb_pdf_simple_font(emb,fdes,fwid,fd_ref);
-  assert(res);
+  DEBUG_assert(res);
   fputs(res,f);
   free(res);
   ENDOBJ;
@@ -155,7 +155,7 @@ int main(int argc,char **argv)
     OBJ;
     res=emb_pdf_simple_cidfont(emb,fdes->fontname,f_ref);
     f_ref=xrefpos;
-    assert(res);
+    DEBUG_assert(res);
     fputs(res,f);
     free(res);
     ENDOBJ;
index 688d9392fca2aca947d3f3a283f516dee8695a8c..bf182054ea5880e6d58b5261d23d26a2ebaef152 100644 (file)
@@ -1,7 +1,7 @@
 #include "embed.h"
 #include "config.h"
 #include "sfnt.h"
-#include <assert.h>
+#include "debug-internal.h"
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -12,7 +12,7 @@ static void example_outfn(const char *buf,int len,void *context) // {{{
   FILE *f=(FILE *)context;
   if (fwrite(buf,1,len,f)!=len) {
     fprintf(stderr,"Short write: %m\n");
-    assert(0);
+    DEBUG_assert(0);
     return;
   }
 }
@@ -20,8 +20,8 @@ static void example_outfn(const char *buf,int len,void *context) // {{{
 
 static inline void write_string(FILE *f,EMB_PARAMS *emb,const char *str) // {{{
 {
-  assert(f);
-  assert(emb);
+  DEBUG_assert(f);
+  DEBUG_assert(emb);
   int iA;
 
   if (emb->plan&EMB_A_MULTIBYTE) {
@@ -55,7 +55,7 @@ int main(int argc,char **argv)
     printf("Font %s was not loaded, exiting.\n", TESTFONT);
     return 1;
   }
-  assert(otf);
+  DEBUG_assert(otf);
   FONTFILE *ff=fontfile_open_sfnt(otf);
   EMB_PARAMS *emb=emb_new(ff,
                           EMB_DEST_PS,
@@ -63,7 +63,7 @@ int main(int argc,char **argv)
                           EMB_C_TAKE_FONTFILE);
 
   FILE *f=fopen("test.ps","w");
-  assert(f);
+  DEBUG_assert(f);
 
   fprintf(f,"%%!PS-Adobe-2.0\n");
 
index 5f8ed54a054407440d9242f1b95d9e34fc0f8f8f..afb6a7144a166cb608ad1f6df56a4add8fda59a5 100644 (file)
@@ -58,11 +58,14 @@ extern "C" {
  */
 
 #  ifdef DEBUG
+#    include <assert.h>
 #    define DEBUG_puts(x) _ppd_debug_puts(x)
 #    define DEBUG_printf(x) _ppd_debug_printf x
+#    define DEBUG_assert(x) assert(x)
 #  else
 #    define DEBUG_puts(x)
 #    define DEBUG_printf(x)
+#    define DEBUG_assert(x)
 #  endif /* DEBUG */
 
 
index 7b61bd50fb9b2a9b6015a358fe810444b31f1414..9e150facfd0b07912414501bf55ca4aa0d22bc04 100644 (file)
@@ -41,9 +41,9 @@ _ppd_gettimeofday(struct timeval *tv, /* I  - Timeval struct */
  * Globals...
  */
 
-static int             _ppd_debug_fd = -1;
+int                    _ppd_debug_fd = -1;
                                        /* Debug log file descriptor */
-static int             _ppd_debug_level = 1;
+int                    _ppd_debug_level = 1;
                                        /* Log level (0 to 9) */
 
 
@@ -54,10 +54,6 @@ static int           _ppd_debug_level = 1;
 static regex_t         *debug_filter = NULL;
                                        /* Filter expression for messages */
 static int             debug_init = 0; /* Did we initialize debugging? */
-static _ppd_mutex_t    debug_init_mutex = _PPD_MUTEX_INITIALIZER,
-                                       /* Mutex to control initialization */
-                       debug_log_mutex = _PPD_MUTEX_INITIALIZER;
-                                       /* Mutex to serialize log entries */
 
 
 /*
@@ -102,9 +98,7 @@ _ppd_debug_printf(const char *format,        /* I - Printf-style format string */
   {
     int        result;                         /* Filter result */
 
-    _ppdMutexLock(&debug_init_mutex);
     result = regexec(debug_filter, format, 0, NULL, 0);
-    _ppdMutexUnlock(&debug_init_mutex);
 
     if (result)
       return;
@@ -139,9 +133,7 @@ _ppd_debug_printf(const char *format,       /* I - Printf-style format string */
   * Write it out...
   */
 
-  _ppdMutexLock(&debug_log_mutex);
   write(_ppd_debug_fd, buffer, (size_t)bytes);
-  _ppdMutexUnlock(&debug_log_mutex);
 }
 
 
@@ -185,9 +177,7 @@ _ppd_debug_puts(const char *s)              /* I - String to output */
   {
     int        result;                         /* Filter result */
 
-    _ppdMutexLock(&debug_init_mutex);
     result = regexec(debug_filter, s, 0, NULL, 0);
-    _ppdMutexUnlock(&debug_init_mutex);
 
     if (result)
       return;
@@ -219,9 +209,7 @@ _ppd_debug_puts(const char *s)              /* I - String to output */
   * Write it out...
   */
 
-  _ppdMutexLock(&debug_log_mutex);
   write(_ppd_debug_fd, buffer, (size_t)bytes);
-  _ppdMutexUnlock(&debug_log_mutex);
 }
 
 
@@ -235,7 +223,6 @@ _ppd_debug_set(const char *logfile, /* I - Log file or NULL */
                const char *filter,     /* I - Filter string or NULL */
                int        force)       /* I - Force initialization */
 {
-  _ppdMutexLock(&debug_init_mutex);
 
   if (!debug_init || force)
   {
@@ -297,7 +284,6 @@ _ppd_debug_set(const char *logfile, /* I - Log file or NULL */
     debug_init = 1;
   }
 
-  _ppdMutexUnlock(&debug_init_mutex);
 }
 
 
index 577b850c67aa8fe25ff36afa73c5341dc2f1ee48..5c4060a2333a7b8c9f0bbec895d40337250d0e4f 100644 (file)
@@ -3551,7 +3551,7 @@ ppdCacheGetPageSize(
 #ifdef DEBUG
     if (attr)
       DEBUG_printf(("1ppdCacheGetPageSize: Found attribute %s (%s)",
-                    attr->name, ippTagString(attr->value_tag)));
+                    ippGetName(attr), ippTagString(ippGetValueTag(attr))));
     else
       DEBUG_puts("1ppdCacheGetPageSize: Did not find media attribute.");
 #endif /* DEBUG */
index 6771ac1d0ceffb5cf61fd7e3e39de91de6692577..ef34402187ed2fdae601cf35b11372e450665c28 100644 (file)
@@ -93,7 +93,7 @@ ppdLocalize(ppd_file_t *ppd)          /* I - PPD file */
                                      ll_CC);
        else
        {
-         snprintf(ckeyword, sizeof(ckeyword), "Custom%s", option->keyword);
+         snprintf(ckeyword, sizeof(ckeyword), "Custom%.34s", option->keyword);
 
          locattr = ppdLocalizedAttr(ppd, ckeyword, "True", ll_CC);
        }
index 9d5e4e59cd46334b97d58cb7ed8317679120e820..4796b86d097e00f65dfea72a7a87857d17cb0db6 100644 (file)
@@ -553,7 +553,7 @@ ppdRasterMatchPPDSize(
        fabs(header->PageSize[0] - size->right + size->left) / size->width < 0.01 &&
        (size_matched == NULL || !strcasecmp(pageSizeRequested, size->name)))
     {
-      DEBUG_printf("Imageable area fit");
+      DEBUG_puts("Imageable area fit\n");
       size_matched = size;
       if (landscape) *landscape = 0;
       if (image_fit) *image_fit = 1;
@@ -601,7 +601,7 @@ ppdRasterMatchPPDSize(
        fabs(header->PageSize[1] - size->right + size->left) / size->width < 0.01 &&
        (size_matched == NULL || !strcasecmp(pageSizeRequested, size->name)))
       {
-       DEBUG_printf("Imageable area fit");
+       DEBUG_puts("Imageable area fit\n");
        size_matched = size;
        if (landscape) *landscape = 1;
        if (image_fit) *image_fit = 1;
@@ -629,7 +629,7 @@ ppdRasterMatchPPDSize(
     /*
      * Custom size...
      */
-    DEBUG_printf("size = Custom");
+    DEBUG_puts("size = Custom\n");
     for (i = 0; i < 2; i ++)
       dimensions[i] = header->PageSize[i];
     for (i = 0; i < 4; i ++)
index bdb874c863125a7e3c559205cb722cd97e0c6444..fea2ffe190ea35b60954dd764d45d7b0e4c1db39 100644 (file)
@@ -12,7 +12,7 @@
 #include <string.h>
 #include <limits.h>
 #include <signal.h>
-#include <assert.h>
+#include "debug-internal.h"
 #include <zlib.h>
 
 /*
@@ -281,7 +281,7 @@ write_flate(cups_raster_t *ras,             /* I - Image data */
       ret = deflate(&strm, flush);
 
       /* check whether state is not clobbered */
-      assert(ret != Z_STREAM_ERROR);
+      DEBUG_assert(ret != Z_STREAM_ERROR);
       have = alloc - strm.avail_out;
       if (fwrite(out, 1, have, doc->outputfp) != have)
       {
@@ -293,7 +293,7 @@ write_flate(cups_raster_t *ras,             /* I - Image data */
     } while (strm.avail_out == 0);
 
     /* all input will be used */
-    assert(strm.avail_in == 0);
+    DEBUG_assert(strm.avail_in == 0);
 
     /* done when last data in file processed */
     free(pixdata);
@@ -301,7 +301,7 @@ write_flate(cups_raster_t *ras,             /* I - Image data */
   } while (flush != Z_FINISH);
 
   /* stream will be complete */
-  assert(ret == Z_STREAM_END);
+  DEBUG_assert(ret == Z_STREAM_END);
 
   /* clean up and return */
   (void)deflateEnd(&strm);
index 7ec3f5de37a8fb126ff11385436b92eed0478373..21ea6854332ca868485b0440f32cc59268425c4c 100644 (file)
@@ -285,17 +285,17 @@ listPrintersInArray(int reg_type_no, int mode, int isFax,
           strcasestr(pdl, "image/"))) {
        value[0] = '\0';
        if (strcasestr(pdl, "application/pdf"))
-         strncat(value, ",PDF", sizeof(value));
+         strncat(value, ",PDF", sizeof(value) - 1);
        if (strcasestr(pdl, "application/PCLm"))
-         strncat(value, ",PCLM", sizeof(value));
+         strncat(value, ",PCLM", sizeof(value) - 1);
        if (strcasestr(pdl, "application/postscript"))
-         strncat(value, ",PS", sizeof(value));
+         strncat(value, ",PS", sizeof(value) - 1);
        if (strcasestr(pdl, "application/vnd.hp-PCL"))
-         strncat(value, ",PCL", sizeof(value));
+         strncat(value, ",PCL", sizeof(value) - 1);
        if (strcasestr(pdl, "image/pwg-raster"))
-         strncat(value, ",PWGRaster", sizeof(value));
+         strncat(value, ",PWGRaster", sizeof(value) - 1);
        if (strcasestr(pdl, "image/urf"))
-         strncat(value, ",AppleRaster", sizeof(value));
+         strncat(value, ",AppleRaster", sizeof(value) - 1);
        for (ptr = strcasestr(pdl, "image/"); ptr;
             ptr = strcasestr(ptr, "image/")) {
          char *valptr = value + strlen(value);