ref: cc7ef4a1ef58b01a1548fd988e3eaf344a7f472d
parent: df7406d80c8d6c1afa6310b7cd764b86f1b4aae1
author: Robin Watts <robin.watts@artifex.com>
date: Fri Dec 18 11:14:31 EST 2015
Move Memento include back into jbig2_priv.h It's clearly nicer not to have Memento as part of the external interface of jbig2, and this solves bug 696183. The include has ping ponged back and forth from jbig2.h in the past due to problems with the jbig2 allocator field naming. We fix that here with a spot of #ifdef/#undef-ery. We also simplify some of the hackery here. Rather than having specific defines such as GSBUILD (meaning 'get memento.h from some place that you magically know about') and JBIG_NO_MEMENTO (meaning 'just ignore memento.h at all'), we now just have JBIG_EXTERNAL_MEMENTO_H. Projects which have their own version of Memento in, and use jbig2dec should define JBIG_EXTERNAL_MEMENTO_H to the location of the memento.h file at build time.
--- a/jbig2.c
+++ b/jbig2.c
@@ -65,21 +65,8 @@
return allocator->alloc(allocator, size * num);
}
-void
-jbig2_free (Jbig2Allocator *allocator, void *p)
-{
- allocator->free (allocator, p);
-}
+/* jbig2_free and jbig2_realloc moved to the bottom of this file */
-void *
-jbig2_realloc (Jbig2Allocator *allocator, void *p, size_t size, size_t num)
-{
- /* check for integer multiplication overflow */
- if (num > 0 && size >= (size_t)-0x100 / num)
- return NULL;
- return allocator->realloc(allocator, p, size * num);
-}
-
static int
jbig2_default_error(void *data, const char *msg,
Jbig2Severity severity, int32_t seg_idx)
@@ -481,3 +468,28 @@
{
jbig2_free(ctx->allocator, ws);
}
+
+/* When Memento is in use, the ->free and ->realloc calls get
+ * turned into ->Memento_free and ->Memento_realloc, which is
+ * obviously problematic. Undefine free and realloc here to
+ * avoid this. */
+#ifdef MEMENTO
+#undef free
+#undef realloc
+#endif
+
+void
+jbig2_free (Jbig2Allocator *allocator, void *p)
+{
+ allocator->free (allocator, p);
+}
+
+void *
+jbig2_realloc (Jbig2Allocator *allocator, void *p, size_t size, size_t num)
+{
+ /* check for integer multiplication overflow */
+ if (num > 0 && size >= (size_t)-0x100 / num)
+ return NULL;
+ return allocator->realloc(allocator, p, size * num);
+}
+
--- a/jbig2.h
+++ b/jbig2.h
@@ -25,21 +25,6 @@
#ifndef _JBIG2_H
#define _JBIG2_H
-/* To enable Memento, either uncomment the following, or arrange to
- * predefine MEMENTO whilst building. */
-/* #define MEMENTO */
-
-/* SumatraPDF: allow to build without MEMENTO (clashes with MuPDF's) */
-#ifndef JBIG_NO_MEMENTO
-/* If we are building as part of GS then make sure we use the version
- * of MEMENTO that is part of gs (in case of version skew) */
-#ifdef GSBUILD
-#include "../base/memento.h"
-#else
-#include "memento.h"
-#endif
-#endif
-
/* warning levels */
typedef enum {
JBIG2_SEVERITY_DEBUG,
--- a/jbig2_priv.h
+++ b/jbig2_priv.h
@@ -18,6 +18,20 @@
*/
+/* To enable Memento, either uncomment the following, or arrange to
+ * predefine MEMENTO whilst building. */
+/* #define MEMENTO */
+
+/* If we are being compiled as part of a larger project that includes
+ * Memento, that project should define JBIG_EXTERNAL_MEMENTO_H to point
+ * to the include file to use.
+ */
+#ifdef JBIG_EXTERNAL_MEMENTO_H
+#include JBIG_EXTERNAL_MEMENTO_H
+#else
+#include "memento.h"
+#endif
+
/* library internals */
typedef uint8_t byte;