code:
This patch enables building binutils using TCC and Mes C Library

  * disable building DOC
  * remove signed int trickery that does not work with TCC
  * fixe the malloc prototype to use size_t
  * add missing includes
  * remove C99'isms to avoid of mixing code and variable declaration
  * [MES_BOOTSTRAP]: remove strncmp to avoid duplicat symbol

Upstream status: Not presented upstream.

diff -purN -x config.status -x config.h -x BOOT ../binutils-2.20.1a/bfd/elf32-i386.c binutils-2.20.1a/bfd/elf32-i386.c
--- ../binutils-2.20.1a/bfd/elf32-i386.c	2009-09-10 13:47:12.000000000 +0200
+++ binutils-2.20.1a/bfd/elf32-i386.c	2018-06-23 19:33:20.068134411 +0200
@@ -4254,6 +4254,7 @@ elf_i386_finish_dynamic_symbol (bfd *out
 	      if (!h->pointer_equality_needed)
 		abort ();

+              {
 	      /* For non-shared object, we can't use .got.plt, which
 		 contains the real function addres if we need pointer
 		 equality.  We load the GOT entry with the PLT entry.  */
@@ -4262,6 +4263,7 @@ elf_i386_finish_dynamic_symbol (bfd *out
 			  (plt->output_section->vma
 			   + plt->output_offset + h->plt.offset),
 			  htab->elf.sgot->contents + h->got.offset);
+              }
 	      return TRUE;
 	    }
 	}
diff -purN -x config.status -x config.h -x BOOT ../binutils-2.20.1a/bfd/elfcode.h binutils-2.20.1a/bfd/elfcode.h
--- ../binutils-2.20.1a/bfd/elfcode.h	2009-09-10 13:47:12.000000000 +0200
+++ binutils-2.20.1a/bfd/elfcode.h	2018-06-19 19:07:16.647627075 +0200
@@ -73,6 +73,7 @@
 #include "bfdlink.h"
 #include "libbfd.h"
 #include "elf-bfd.h"
+#include <limits.h>

 /* Renaming structures, typedefs, macros and functions to be size-specific.  */
 #define Elf_External_Ehdr	NAME(Elf,External_Ehdr)
@@ -706,8 +707,8 @@ elf_object_p (bfd *abfd)
       if (i_ehdrp->e_shnum != 1)
 	{
 	  /* Check that we don't have a totally silly number of sections.  */
-	  if (i_ehdrp->e_shnum > (unsigned int) -1 / sizeof (x_shdr)
-	      || i_ehdrp->e_shnum > (unsigned int) -1 / sizeof (i_shdr))
+	  if (i_ehdrp->e_shnum > INT_MAX / sizeof (x_shdr)
+	      || i_ehdrp->e_shnum > INT_MAX / sizeof (i_shdr))
 	    goto got_wrong_format_error;

 	  where += (i_ehdrp->e_shnum - 1) * sizeof (x_shdr);
diff -purN -x config.status -x config.h -x BOOT ../binutils-2.20.1a/bfd/Makefile.in binutils-2.20.1a/bfd/Makefile.in
--- ../binutils-2.20.1a/bfd/Makefile.in	2010-03-03 14:59:15.000000000 +0100
+++ binutils-2.20.1a/bfd/Makefile.in	2018-06-16 14:00:46.297724081 +0200
@@ -320,7 +320,7 @@ ACLOCAL_AMFLAGS = -I . -I .. -I ../confi
 # RELEASE=y
 INCDIR = $(srcdir)/../include
 CSEARCH = -I. -I$(srcdir) -I$(INCDIR)
-SUBDIRS = doc po
+SUBDIRS = # these fail to build: doc po
 bfddocdir = doc
 libbfd_la_LDFLAGS = $(am__append_1) -release `cat libtool-soversion` \
 	@SHARED_LDFLAGS@ $(am__empty)
diff -purN -x config.status -x config.h -x BOOT ../binutils-2.20.1a/binutils/arparse.c binutils-2.20.1a/binutils/arparse.c
--- ../binutils-2.20.1a/binutils/arparse.c	2009-10-16 13:52:16.000000000 +0200
+++ binutils-2.20.1a/binutils/arparse.c	2018-06-19 01:30:00.576219981 +0200
@@ -330,7 +330,7 @@ YYID (i)
 #   define YYMALLOC malloc
 #   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
      || defined __cplusplus || defined _MSC_VER)
-void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
+void *malloc (size_t); /* INFRINGES ON USER NAME SPACE */
 #   endif
 #  endif
 #  ifndef YYFREE
diff -purN -x config.status -x config.h -x BOOT ../binutils-2.20.1a/binutils/dwarf.c binutils-2.20.1a/binutils/dwarf.c
--- ../binutils-2.20.1a/binutils/dwarf.c	2009-09-14 13:43:26.000000000 +0200
+++ binutils-2.20.1a/binutils/dwarf.c	2018-06-16 14:01:45.162684662 +0200
@@ -27,6 +27,10 @@
 #include "dwarf2.h"
 #include "dwarf.h"

+#if MES_BOOTSTRAP
+#include "getopt.h"
+#endif
+
 static int have_frame_base;
 static int need_base_address;

diff -purN -x config.status -x config.h -x BOOT ../binutils-2.20.1a/binutils/sysinfo.c binutils-2.20.1a/binutils/sysinfo.c
--- ../binutils-2.20.1a/binutils/sysinfo.c	2009-10-16 13:52:17.000000000 +0200
+++ binutils-2.20.1a/binutils/sysinfo.c	2018-06-19 01:29:23.823612807 +0200
@@ -286,7 +286,7 @@ YYID (i)
 #   define YYMALLOC malloc
 #   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
      || defined __cplusplus || defined _MSC_VER)
-void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
+void *malloc (size_t); /* INFRINGES ON USER NAME SPACE */
 #   endif
 #  endif
 #  ifndef YYFREE
diff -purN -x config.status -x config.h -x BOOT ../binutils-2.20.1a/gas/config/tc-i386.c binutils-2.20.1a/gas/config/tc-i386.c
--- ../binutils-2.20.1a/gas/config/tc-i386.c	2009-09-14 13:43:27.000000000 +0200
+++ binutils-2.20.1a/gas/config/tc-i386.c	2018-06-23 19:39:37.546254752 +0200
@@ -4869,6 +4869,7 @@ build_modrm_byte (void)
   if (vex_3_sources)
     {
       unsigned int nds, reg;
+      expressionS *exp;

       if (i.tm.opcode_modifier.veximmext
 	  && i.tm.opcode_modifier.immext)
@@ -4892,7 +4893,7 @@ build_modrm_byte (void)

       /* Generate an 8bit immediate operand to encode the register
 	 operand.  */
-      expressionS *exp = &im_expressions[i.imm_operands++];
+      exp = &im_expressions[i.imm_operands++];
       i.op[i.operands].imms = exp;
       i.types[i.operands] = imm8;
       i.operands++;
diff -purN -x config.status -x config.h -x BOOT ../binutils-2.20.1a/ld/ldgram.c binutils-2.20.1a/ld/ldgram.c
--- ../binutils-2.20.1a/ld/ldgram.c	2009-10-16 13:52:15.000000000 +0200
+++ binutils-2.20.1a/ld/ldgram.c	2018-06-19 01:30:57.809165437 +0200
@@ -561,7 +561,7 @@ YYID (i)
 #   define YYMALLOC malloc
 #   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
      || defined __cplusplus || defined _MSC_VER)
-void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
+void *malloc (size_t); /* INFRINGES ON USER NAME SPACE */
 #   endif
 #  endif
 #  ifndef YYFREE
diff -purN -x config.status -x config.h -x BOOT ../binutils-2.20.1a/libiberty/strncmp.c binutils-2.20.1a/libiberty/strncmp.c
--- ../binutils-2.20.1a/libiberty/strncmp.c	2005-03-28 04:09:01.000000000 +0200
+++ binutils-2.20.1a/libiberty/strncmp.c	2018-06-23 19:19:50.038992482 +0200
@@ -15,6 +15,13 @@ Compares the first @var{n} bytes of two
 #include <ansidecl.h>
 #include <stddef.h>

+#if !MES_BOOTSTRAP
+
+/*
+   libtool: link: /gnu/store/rgwjixk5zl7s2d3xsb2ws2z2q3m0xjm4-tcc-boot-0.9.26-0.97196ce/bin/tcc -D __GLIBC_MINOR__=6 -D MES_BOOTSTRAP=1 -g -o size size.o bucomm.o version.o filemode.o  ../bfd/.libs/libbfd.a ../libiberty/libiberty.a ./../intl/libintl.a
+   /gnu/store/rgwjixk5zl7s2d3xsb2ws2z2q3m0xjm4-tcc-boot-0.9.26-0.97196ce/lib/libc.a: error: 'strncmp' defined twice
+*/
+
 int
 strncmp(const char *s1, const char *s2, register size_t n)
 {
@@ -31,3 +38,5 @@ strncmp(const char *s1, const char *s2,
     }
   return 0;
 }
+
+#endif // !MES_BOOTSTRAP


code:
Enable the workaround for the Loongson 2F bug by default.

Patch by Mark H Weaver <mhw@netris.org>.

--- binutils/gas/config/tc-mips.c.orig	2012-09-04 10:21:03.000000000 -0400
+++ binutils/gas/config/tc-mips.c	2013-10-06 02:23:21.651983768 -0400
@@ -910,10 +910,10 @@
 };

 /* ...likewise -mfix-loongson2f-jump.  */
-static bfd_boolean mips_fix_loongson2f_jump;
+static bfd_boolean mips_fix_loongson2f_jump = FALSE;

 /* ...likewise -mfix-loongson2f-nop.  */
-static bfd_boolean mips_fix_loongson2f_nop;
+static bfd_boolean mips_fix_loongson2f_nop = TRUE;

 /* True if -mfix-loongson2f-nop or -mfix-loongson2f-jump passed.  */
 static bfd_boolean mips_fix_loongson2f;
--- binutils/gas/testsuite/gas/mips/mips.exp.orig	2012-09-04 10:17:13.000000000 -0400
+++ binutils/gas/testsuite/gas/mips/mips.exp	2013-10-06 02:23:21.663983768 -0400
@@ -91,6 +91,12 @@

     # Catch because the variable won't be set the first time through.
     catch {unset mips_arches}
+
+    # Disable the loongson2f nop fix by default, because most of the
+    # existing test cases for mips will fail otherwise.
+    global ASFLAGS
+    set old_ASFLAGS "$ASFLAGS"
+    set ASFLAGS "$ASFLAGS -mno-fix-loongson2f-nop"
 }

 # mips_arch_create ARCH GPRSIZE EXTENDS PROPS AS_FLAGS OBJDUMP_FLAGS \

repo_name: maximed/guix

license: mit


code:
This following patch was originally found at the debian mingw-w64 team's
binutils repo located here:
https://salsa.debian.org/mingw-w64-team/binutils-mingw-w64.git

Invoke the following in the aforementioned repo to see the original patch:

  $ git show da63f6b:debian/patches/reproducible-import-libraries.patch

Description: Make DLL import libraries reproducible
Author: Benjamin Moody <benjamin.moody@gmail.com>
Bug-Debian: https://bugs.debian.org/915055

--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -2844,6 +2844,7 @@

   bfd_set_format (outarch, bfd_archive);
   outarch->has_armap = 1;
+  outarch->flags |= BFD_DETERMINISTIC_OUTPUT;

   /* Work out a reasonable size of things to put onto one line.  */
   ar_head = make_head (outarch);


code:
This following patch was originally found at the debian mingw-w64 team's
binutils repo located here:
https://salsa.debian.org/mingw-w64-team/binutils-mingw-w64.git

Invoke the following in the aforementioned repo to see the original patch:

  $ git show da63f6b:debian/patches/specify-timestamp.patch

Description: Allow the PE timestamp to be specified
Author: Stephen Kitt <skitt@debian.org>

--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -70,6 +70,9 @@
 #include <wctype.h>
 #endif

+#include <errno.h>
+#include <limits.h>
+
 /* NOTE: it's strange to be including an architecture specific header
    in what's supposed to be general (to PE/PEI) code.  However, that's
    where the definitions are, and they don't vary per architecture
@@ -879,10 +882,38 @@

   /* Use a real timestamp by default, unless the no-insert-timestamp
      option was chosen.  */
-  if ((pe_data (abfd)->insert_timestamp))
-    H_PUT_32 (abfd, time (0), filehdr_out->f_timdat);
-  else
+  if (pe_data (abfd)->insert_timestamp) {
+    time_t now;
+    char *source_date_epoch;
+    unsigned long long epoch;
+    char *endptr;
+
+    now = time(NULL);
+    source_date_epoch = getenv("SOURCE_DATE_EPOCH");
+    if (source_date_epoch) {
+      errno = 0;
+      epoch = strtoull(source_date_epoch, &endptr, 10);
+      if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
+          || (errno != 0 && epoch == 0)) {
+        _bfd_error_handler("Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n",
+                           strerror(errno));
+      } else if (endptr == source_date_epoch) {
+        _bfd_error_handler("Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n",
+                           endptr);
+      } else if (*endptr != '\0') {
+        _bfd_error_handler("Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n",
+                           endptr);
+      } else if (epoch > ULONG_MAX) {
+        _bfd_error_handler("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to: %lu but was found to be: %llu\n",
+                           ULONG_MAX, epoch);
+      } else {
+        now = epoch;
+      }
+    }
+    H_PUT_32 (abfd, now, filehdr_out->f_timdat);
+  } else {
     H_PUT_32 (abfd, 0, filehdr_out->f_timdat);
+  }

   PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr,
 		      filehdr_out->f_symptr);
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -26,6 +26,8 @@
 #include "filenames.h"
 #include "safe-ctype.h"

+#include <errno.h>
+#include <limits.h>
 #include <time.h>

 #include "ld.h"
@@ -1202,8 +1204,36 @@

   memset (edata_d, 0, edata_sz);

-  if (pe_data (abfd)->insert_timestamp)
-    H_PUT_32 (abfd, time (0), edata_d + 4);
+  if (pe_data (abfd)->insert_timestamp) {
+    time_t now;
+    char *source_date_epoch;
+    unsigned long long epoch;
+    char *endptr;
+
+    now = time(NULL);
+    source_date_epoch = getenv("SOURCE_DATE_EPOCH");
+    if (source_date_epoch) {
+      errno = 0;
+      epoch = strtoull(source_date_epoch, &endptr, 10);
+      if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
+	  || (errno != 0 && epoch == 0)) {
+	einfo("Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n",
+	      strerror(errno));
+      } else if (endptr == source_date_epoch) {
+	einfo("Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n",
+	      endptr);
+      } else if (*endptr != '\0') {
+	einfo("Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n",
+	      endptr);
+      } else if (epoch > ULONG_MAX) {
+	einfo("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to: %lu but was found to be: %llu\n",
+	      ULONG_MAX, epoch);
+      } else {
+	now = epoch;
+      }
+    }
+    H_PUT_32 (abfd, now, edata_d + 4);
+  }

   if (pe_def_file->version_major != -1)
     {
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -303,7 +303,7 @@
      OPTION_USE_NUL_PREFIXED_IMPORT_TABLES},
     {"no-leading-underscore", no_argument, NULL, OPTION_NO_LEADING_UNDERSCORE},
     {"leading-underscore", no_argument, NULL, OPTION_LEADING_UNDERSCORE},
-    {"insert-timestamp", no_argument, NULL, OPTION_INSERT_TIMESTAMP},
+    {"insert-timestamp", optional_argument, NULL, OPTION_INSERT_TIMESTAMP},
     {"no-insert-timestamp", no_argument, NULL, OPTION_NO_INSERT_TIMESTAMP},
 #ifdef DLL_SUPPORT
     /* getopt allows abbreviations, so we do this to stop it
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -321,7 +321,7 @@
     {"no-bind", no_argument, NULL, OPTION_NO_BIND},
     {"wdmdriver", no_argument, NULL, OPTION_WDM_DRIVER},
     {"tsaware", no_argument, NULL, OPTION_TERMINAL_SERVER_AWARE},
-    {"insert-timestamp", no_argument, NULL, OPTION_INSERT_TIMESTAMP},
+    {"insert-timestamp", optional_argument, NULL, OPTION_INSERT_TIMESTAMP},
     {"no-insert-timestamp", no_argument, NULL, OPTION_NO_INSERT_TIMESTAMP},
     {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
     {NULL, no_argument, NULL, 0}


code:
diff --git a/intern/itasc/kdl/tree.hpp b/intern/itasc/kdl/tree.hpp
index c8a253fc901..bd35f82d185 100644
--- a/intern/itasc/kdl/tree.hpp
+++ b/intern/itasc/kdl/tree.hpp
@@ -34,7 +34,7 @@ namespace KDL
     //Forward declaration
     class TreeElement;
     // Eigen allocator is needed for alignment of Eigen data types
-    typedef std::map<std::string,TreeElement, std::less<std::string>, Eigen::aligned_allocator<std::pair<std::string, TreeElement> > > SegmentMap;
+    typedef std::map<std::string,TreeElement, std::less<std::string>, Eigen::aligned_allocator<std::pair<const std::string, TreeElement> > > SegmentMap;

     class TreeElement
     {
diff --git a/intern/cycles/util/util_sseb.h b/intern/cycles/util/util_sseb.h
index 6e669701f3b..977976c3fc0 100644
--- a/intern/cycles/util/util_sseb.h
+++ b/intern/cycles/util/util_sseb.h
@@ -22,6 +22,9 @@ CCL_NAMESPACE_BEGIN

 #ifdef __KERNEL_SSE2__

+struct ssei;
+struct ssef;
+
 /*! 4-wide SSE bool type. */
 struct sseb
 {
@@ -116,7 +119,7 @@ __forceinline const sseb unpacklo( const sseb& a, const sseb& b ) { return _mm_u
 __forceinline const sseb unpackhi( const sseb& a, const sseb& b ) { return _mm_unpackhi_ps(a, b); }

 template<size_t i0, size_t i1, size_t i2, size_t i3> __forceinline const sseb shuffle( const sseb& a ) {
-	return _mm_shuffle_epi32(a, _MM_SHUFFLE(i3, i2, i1, i0));
+	return _mm_castsi128_ps(_mm_shuffle_epi32(a, _MM_SHUFFLE(i3, i2, i1, i0)));
 }

 template<> __forceinline const sseb shuffle<0, 1, 0, 1>( const sseb& a ) {


code:
commit e6d803fd4a383cecf8c643095f093a31c944b785
Author: Robert-André Mauchin <zebob.m@gmail.com>
Date:   Wed Apr 3 01:36:52 2019 +0200

    Fix for GCC9 new OpenMP data sharing

    GCC 9 started implementing the OpenMP 4.0 and later behavior. When not using
    default clause or when using default(shared), this makes no difference, but
    if using default(none), previously the choice was not specify the const
    qualified variables on the construct at all, or specify in firstprivate
    clause. In GCC 9 as well as for OpenMP 4.0 compliance, those variables need
    to be specified on constructs in which they are used, either in shared or
    in firstprivate clause. Specifying them in firstprivate clause is one way to
    achieve compatibility with both older GCC versions and GCC 9,
    another option is to drop the default(none) clause.

    This patch thus drops the default(none) clause.

    See https://gcc.gnu.org/gcc-9/porting_to.html#ompdatasharing

    Signed-off-by: Robert-André Mauchin <zebob.m@gmail.com>

diff --git a/intern/elbeem/intern/solver_main.cpp b/intern/elbeem/intern/solver_main.cpp
index 68f7c04cd54..514087b6130 100644
--- a/intern/elbeem/intern/solver_main.cpp
+++ b/intern/elbeem/intern/solver_main.cpp
@@ -381,7 +381,7 @@ LbmFsgrSolver::mainLoop(const int lev)
 	GRID_REGION_INIT();
 #if PARALLEL==1
 	const int gDebugLevel = ::gDebugLevel;
-#pragma omp parallel default(none) num_threads(mNumOMPThreads) \
+#pragma omp parallel num_threads(mNumOMPThreads) \
   reduction(+: \
 	  calcCurrentMass,calcCurrentVolume, \
 		calcCellsFilled,calcCellsEmptied, \
@@ -1126,7 +1126,7 @@ LbmFsgrSolver::preinitGrids()
 		GRID_REGION_INIT();
 #if PARALLEL==1
 	const int gDebugLevel = ::gDebugLevel;
-#pragma omp parallel default(none) num_threads(mNumOMPThreads) \
+#pragma omp parallel num_threads(mNumOMPThreads) \
   reduction(+: \
 	  calcCurrentMass,calcCurrentVolume, \
 		calcCellsFilled,calcCellsEmptied, \
@@ -1164,7 +1164,7 @@ LbmFsgrSolver::standingFluidPreinit()
 	GRID_REGION_INIT();
 #if PARALLEL==1
 	const int gDebugLevel = ::gDebugLevel;
-#pragma omp parallel default(none) num_threads(mNumOMPThreads) \
+#pragma omp parallel num_threads(mNumOMPThreads) \
   reduction(+: \
 	  calcCurrentMass,calcCurrentVolume, \
 		calcCellsFilled,calcCellsEmptied, \


code:
https://sources.debian.org/data/main/b/blender/2.79.b+dfsg0-4/debian/patches/0008-fix_building_with_latest_versions_of_FFmpeg.patch

From: Bastien Montagne <montagne29@wanadoo.fr>
Date: Tue, 8 May 2018 16:00:52 +0200
Subject: fix_building_with_latest_versions_of_FFmpeg

Some years-old deprecated stuff has now been removed.

Correct solution is probably to use valid defines etc. in own code, but
this is more FFMEPG maintainer task (since it also may change how old
FFMPEG we do support...).
---
 intern/ffmpeg/ffmpeg_compat.h                  | 39 ++++++++++++++++++++++++++
 source/blender/blenkernel/intern/writeffmpeg.c |  3 +-
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/intern/ffmpeg/ffmpeg_compat.h b/intern/ffmpeg/ffmpeg_compat.h
index 9c06c8a..f7f437c 100644
--- a/intern/ffmpeg/ffmpeg_compat.h
+++ b/intern/ffmpeg/ffmpeg_compat.h
@@ -109,6 +109,45 @@ int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)

 #endif

+/* XXX TODO Probably fix to correct modern flags in code? Not sure how old FFMPEG we want to support though,
+ * so for now this will do. */
+
+#ifndef FF_MIN_BUFFER_SIZE
+#  ifdef AV_INPUT_BUFFER_MIN_SIZE
+#    define FF_MIN_BUFFER_SIZE AV_INPUT_BUFFER_MIN_SIZE
+#  endif
+#endif
+
+#ifndef FF_INPUT_BUFFER_PADDING_SIZE
+#  ifdef AV_INPUT_BUFFER_PADDING_SIZE
+#    define FF_INPUT_BUFFER_PADDING_SIZE AV_INPUT_BUFFER_PADDING_SIZE
+#  endif
+#endif
+
+#ifndef CODEC_FLAG_GLOBAL_HEADER
+#  ifdef AV_CODEC_FLAG_GLOBAL_HEADER
+#    define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
+#  endif
+#endif
+
+#ifndef CODEC_FLAG_GLOBAL_HEADER
+#  ifdef AV_CODEC_FLAG_GLOBAL_HEADER
+#    define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
+#  endif
+#endif
+
+#ifndef CODEC_FLAG_INTERLACED_DCT
+#  ifdef AV_CODEC_FLAG_INTERLACED_DCT
+#    define CODEC_FLAG_INTERLACED_DCT AV_CODEC_FLAG_INTERLACED_DCT
+#  endif
+#endif
+
+#ifndef CODEC_FLAG_INTERLACED_ME
+#  ifdef AV_CODEC_FLAG_INTERLACED_ME
+#    define CODEC_FLAG_INTERLACED_ME AV_CODEC_FLAG_INTERLACED_ME
+#  endif
+#endif
+
 /* FFmpeg upstream 1.0 is the first who added AV_ prefix. */
 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54, 59, 100)
 #  define AV_CODEC_ID_NONE CODEC_ID_NONE
diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c
index a19e414..04d508a 100644
--- a/source/blender/blenkernel/intern/writeffmpeg.c
+++ b/source/blender/blenkernel/intern/writeffmpeg.c
@@ -605,7 +605,8 @@ static AVStream *alloc_video_stream(FFMpegContext *context, RenderData *rd, int
 	c->rc_buffer_aggressivity = 1.0;
 #endif

-	c->me_method = ME_EPZS;
+	/* Deprecated and not doing anything since July 2015, deleted in recent ffmpeg */
+	//c->me_method = ME_EPZS;

 	codec = avcodec_find_encoder(c->codec_id);
 	if (!codec)


code:
From: Sergey Sharybin <sergey@blender.org>
Date: Fri, 28 Dec 2018 11:25:35 +0100
Subject: adapt_build_against_OIIO2

---
 intern/cycles/blender/blender_python.cpp           |  2 +-
 intern/cycles/graph/node_xml.cpp                   |  2 +-
 intern/cycles/render/buffers.cpp                   |  4 ++--
 intern/cycles/render/image.cpp                     | 15 ++++--------
 intern/cycles/render/image.h                       |  3 ++-
 intern/cycles/util/util_unique_ptr.h               | 28 ++++++++++++++++++++++
 .../blender/imbuf/intern/oiio/openimageio_api.cpp  | 19 +++++++--------
 7 files changed, 48 insertions(+), 25 deletions(-)
 create mode 100644 intern/cycles/util/util_unique_ptr.h

diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp
index 54973fd..bee6dd1 100644
--- a/intern/cycles/blender/blender_python.cpp
+++ b/intern/cycles/blender/blender_python.cpp
@@ -493,7 +493,7 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args)
 				socket_type = "NodeSocketString";
 				data_type = BL::NodeSocket::type_STRING;
 				if(param->validdefault)
-					default_string = param->sdefault[0];
+					default_string = param->sdefault[0].string();
 			}
 			else
 				continue;
diff --git a/intern/cycles/graph/node_xml.cpp b/intern/cycles/graph/node_xml.cpp
index d26b3b2..2a24104 100644
--- a/intern/cycles/graph/node_xml.cpp
+++ b/intern/cycles/graph/node_xml.cpp
@@ -250,7 +250,7 @@ void xml_read_node(XMLReader& reader, Node *node, xml_node xml_node)
 		}
 	}

-	if(node->name)
+	if(!node->name.empty())
 		reader.node_map[node->name] = node;
 }

diff --git a/intern/cycles/render/buffers.cpp b/intern/cycles/render/buffers.cpp
index cf402c3..f84a37a 100644
--- a/intern/cycles/render/buffers.cpp
+++ b/intern/cycles/render/buffers.cpp
@@ -27,6 +27,7 @@
 #include "util/util_opengl.h"
 #include "util/util_time.h"
 #include "util/util_types.h"
+#include "util/util_unique_ptr.h"

 CCL_NAMESPACE_BEGIN

@@ -453,7 +454,7 @@ void DisplayBuffer::write(Device *device, const string& filename)
 	device->pixels_copy_from(rgba, 0, w, h);

 	/* write image */
-	ImageOutput *out = ImageOutput::create(filename);
+	unique_ptr<ImageOutput> out = unique_ptr<ImageOutput>(ImageOutput::create(filename));
 	ImageSpec spec(w, h, 4, TypeDesc::UINT8);
 	int scanlinesize = w*4*sizeof(uchar);

@@ -468,7 +469,6 @@ void DisplayBuffer::write(Device *device, const string& filename)

 	out->close();

-	delete out;
 }

 device_memory& DisplayBuffer::rgba_data()
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index 595eb46..a143b02 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -23,6 +23,7 @@
 #include "util/util_path.h"
 #include "util/util_progress.h"
 #include "util/util_texture.h"
+#include "util/util_unique_ptr.h"

 #ifdef WITH_OSL
 #include <OSL/oslexec.h>
@@ -148,7 +149,7 @@ ImageDataType ImageManager::get_image_metadata(const string& filename,
 		return IMAGE_DATA_TYPE_BYTE4;
 	}

-	ImageInput *in = ImageInput::create(filename);
+	unique_ptr<ImageInput> in(ImageInput::create(filename));

 	if(in) {
 		ImageSpec spec;
@@ -194,7 +195,6 @@ ImageDataType ImageManager::get_image_metadata(const string& filename,
 			in->close();
 		}

-		delete in;
 	}

 	if(is_half) {
@@ -449,7 +449,7 @@ void ImageManager::tag_reload_image(const string& filename,
 }

 bool ImageManager::file_load_image_generic(Image *img,
-                                           ImageInput **in,
+                                           unique_ptr<ImageInput> *in,
                                            int &width,
                                            int &height,
                                            int &depth,
@@ -465,7 +465,7 @@ bool ImageManager::file_load_image_generic(Image *img,
 		}

 		/* load image from file through OIIO */
-		*in = ImageInput::create(img->filename);
+		*in = unique_ptr<ImageInput>(ImageInput::create(img->filename));

 		if(!*in)
 			return false;
@@ -477,8 +477,6 @@ bool ImageManager::file_load_image_generic(Image *img,
 			config.attribute("oiio:UnassociatedAlpha", 1);

 		if(!(*in)->open(img->filename, spec, config)) {
-			delete *in;
-			*in = NULL;
 			return false;
 		}

@@ -500,8 +498,6 @@ bool ImageManager::file_load_image_generic(Image *img,
 	if(!(components >= 1 && components <= 4)) {
 		if(*in) {
 			(*in)->close();
-			delete *in;
-			*in = NULL;
 		}

 		return false;
@@ -519,7 +515,7 @@ bool ImageManager::file_load_image(Image *img,
                                    device_vector<DeviceType>& tex_img)
 {
 	const StorageType alpha_one = (FileFormat == TypeDesc::UINT8)? 255 : 1;
-	ImageInput *in = NULL;
+	unique_ptr<ImageInput> in = NULL;
 	int width, height, depth, components;
 	if(!file_load_image_generic(img, &in, width, height, depth, components)) {
 		return false;
@@ -575,7 +571,6 @@ bool ImageManager::file_load_image(Image *img,
 		}
 		cmyk = strcmp(in->format_name(), "jpeg") == 0 && components == 4;
 		in->close();
-		delete in;
 	}
 	else {
 		if(FileFormat == TypeDesc::FLOAT) {
diff --git a/intern/cycles/render/image.h b/intern/cycles/render/image.h
index db7e28a..f4a14f4 100644
--- a/intern/cycles/render/image.h
+++ b/intern/cycles/render/image.h
@@ -23,6 +23,7 @@
 #include "util/util_image.h"
 #include "util/util_string.h"
 #include "util/util_thread.h"
+#include "util/util_unique_ptr.h"
 #include "util/util_vector.h"

 CCL_NAMESPACE_BEGIN
@@ -133,7 +134,7 @@ private:
 	bool pack_images;

 	bool file_load_image_generic(Image *img,
-	                             ImageInput **in,
+	                             unique_ptr<ImageInput> *in,
 	                             int &width,
 	                             int &height,
 	                             int &depth,
diff --git a/intern/cycles/util/util_unique_ptr.h b/intern/cycles/util/util_unique_ptr.h
new file mode 100644
index 0000000..1ceae73
--- /dev/null
+++ b/intern/cycles/util/util_unique_ptr.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2011-2013 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __UTIL_UNIQUE_PTR_H__
+#define __UTIL_UNIQUE_PTR_H__
+
+#include <memory>
+
+CCL_NAMESPACE_BEGIN
+
+using std::unique_ptr;
+
+CCL_NAMESPACE_END
+
+#endif  /* __UTIL_UNIQUE_PTR_H__ */
diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.cpp b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
index b123d50..7f2fac9 100644
--- a/source/blender/imbuf/intern/oiio/openimageio_api.cpp
+++ b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
@@ -35,6 +35,11 @@
 #include "utfconv.h"
 #endif

+// NOTE: Keep first, BLI_path_util conflicts with OIIO's format.
+#include <memory>
+#include <openimageio_api.h>
+#include <OpenImageIO/imageio.h>
+
 extern "C"
 {
 #include "MEM_guardedalloc.h"
@@ -48,12 +53,10 @@ extern "C"
 #include "IMB_colormanagement_intern.h"
 }

-#include <openimageio_api.h>
-#include <OpenImageIO/imageio.h>
-
 OIIO_NAMESPACE_USING

 using std::string;
+using std::unique_ptr;

 typedef unsigned char uchar;

@@ -197,7 +200,6 @@ int imb_save_photoshop(struct ImBuf *ibuf, const char * /*name*/, int flags)

 struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspace[IM_MAX_SPACE])
 {
-	ImageInput *in = NULL;
 	struct ImBuf *ibuf = NULL;
 	int width, height, components;
 	bool is_float, is_alpha;
@@ -210,7 +212,7 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac

 	colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);

-	in = ImageInput::create(filename);
+	unique_ptr<ImageInput> in(ImageInput::create(filename));
 	if (!in) {
 		std::cerr << __func__ << ": ImageInput::create() failed:" << std::endl
 		          << OIIO_NAMESPACE::geterror() << std::endl;
@@ -223,7 +225,6 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
 	if (!in->open(filename, spec, config)) {
 		std::cerr << __func__ << ": ImageInput::open() failed:" << std::endl
 		          << in->geterror() << std::endl;
-		delete in;
 		return NULL;
 	}

@@ -249,19 +250,17 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
 	if (!(components >= 1 && components <= 4)) {
 		if (in) {
 			in->close();
-			delete in;
 		}
 		return NULL;
 	}

 	if (is_float)
-		ibuf = imb_oiio_load_image_float(in, width, height, components, flags, is_alpha);
+		ibuf = imb_oiio_load_image_float(in.get(), width, height, components, flags, is_alpha);
 	else
-		ibuf = imb_oiio_load_image(in, width, height, components, flags, is_alpha);
+		ibuf = imb_oiio_load_image(in.get(), width, height, components, flags, is_alpha);

 	if (in) {
 		in->close();
-		delete in;
 	}

 	if (!ibuf)


code:
Copied from https://git.blender.org/gitweb/gitweb.cgi/blender.git/patch/1db47a2ccd1e68994bf8140eba6cc2a26a2bc91f
Fixes <https://bugs.gnu.org/33608>.

From 1db47a2ccd1e68994bf8140eba6cc2a26a2bc91f Mon Sep 17 00:00:00 2001
From: Campbell Barton <ideasman42@gmail.com>
Date: Thu, 12 Jul 2018 08:28:06 +0200
Subject: [PATCH] Fix PyRNA class registration w/ Python 3.7

In Python3.7 this now raises an error.
---
 source/blender/python/intern/bpy_rna.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 9052b6f580a..80b0aa7a51b 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -7577,10 +7577,12 @@ static int bpy_class_validate_recursive(PointerRNA *dummyptr, StructRNA *srna, v
 		if (!(flag & PROP_REGISTER))
 			continue;

+		/* TODO(campbell): Use Python3.7x _PyObject_LookupAttr(), also in the macro below. */
 		identifier = RNA_property_identifier(prop);
 		item = PyObject_GetAttrString(py_class, identifier);

 		if (item == NULL) {
+			PyErr_Clear();
 			/* Sneaky workaround to use the class name as the bl_idname */

 #define     BPY_REPLACEMENT_STRING(rna_attr, py_attr)                         \
@@ -7596,6 +7598,9 @@ static int bpy_class_validate_recursive(PointerRNA *dummyptr, StructRNA *srna, v
 					}                                                         \
 					Py_DECREF(item);                                          \
 				}                                                             \
+				else {                                                        \
+					PyErr_Clear();                                            \
+				}                                                             \
 			}  /* intentionally allow else here */

 			if (false) {}  /* needed for macro */
--
2.20.1


code:
From 4b663ecf264020b1d7003a137ce84b06d7ec4ce6 Mon Sep 17 00:00:00 2001
From: bartus <szczepaniak.bartek+github@gmail.com>
Date: Sat, 16 Nov 2019 20:29:30 +0100
Subject: [PATCH] Add python 3.8 support.

---
 source/blender/python/generic/py_capi_utils.c | 27 +++++++++++++++----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c
index 545e0506f84..a7eab70600b 100644
--- a/source/blender/python/generic/py_capi_utils.c
+++ b/source/blender/python/generic/py_capi_utils.c
@@ -696,9 +696,16 @@ PyObject *PyC_UnicodeFromByte(const char *str)
  ****************************************************************************/
 PyObject *PyC_DefaultNameSpace(const char *filename)
 {
+	#if PY_VERSION_HEX >= 0x03080000
+	PyObject *modules = PyImport_GetModuleDict();
+	PyObject *builtins = PyEval_GetBuiltins();
+	#else
 	PyInterpreterState *interp = PyThreadState_GET()->interp;
+	PyObject *modules = interp->modules;
+	PyObject *builtins = interp->builtins;
+	#endif
 	PyObject *mod_main = PyModule_New("__main__");
-	PyDict_SetItemString(interp->modules, "__main__", mod_main);
+	PyDict_SetItemString(modules, "__main__", mod_main);
 	Py_DECREF(mod_main); /* sys.modules owns now */
 	PyModule_AddStringConstant(mod_main, "__name__", "__main__");
 	if (filename) {
@@ -706,8 +713,8 @@ PyObject *PyC_DefaultNameSpace(const char *filename)
 		 * note: this wont map to a real file when executing text-blocks and buttons. */
 		PyModule_AddObject(mod_main, "__file__", PyC_UnicodeFromByte(filename));
 	}
-	PyModule_AddObject(mod_main, "__builtins__", interp->builtins);
-	Py_INCREF(interp->builtins); /* AddObject steals a reference */
+	PyModule_AddObject(mod_main, "__builtins__", builtins);
+	Py_INCREF(builtins); /* AddObject steals a reference */
 	return PyModule_GetDict(mod_main);
 }

@@ -734,15 +741,25 @@ bool PyC_NameSpace_ImportArray(PyObject *py_dict, const char *imports[])
 /* restore MUST be called after this */
 void PyC_MainModule_Backup(PyObject **main_mod)
 {
+	#if PY_VERSION_HEX >= 0x03080000
+	PyObject *modules = PyImport_GetModuleDict();
+	#else
 	PyInterpreterState *interp = PyThreadState_GET()->interp;
-	*main_mod = PyDict_GetItemString(interp->modules, "__main__");
+	PyObject *modules = interp->modules;
+	#endif
+	*main_mod = PyDict_GetItemString(modules, "__main__");
 	Py_XINCREF(*main_mod); /* don't free */
 }

 void PyC_MainModule_Restore(PyObject *main_mod)
 {
+	#if PY_VERSION_HEX >= 0x03080000
+	PyObject *modules = PyImport_GetModuleDict();
+	#else
 	PyInterpreterState *interp = PyThreadState_GET()->interp;
-	PyDict_SetItemString(interp->modules, "__main__", main_mod);
+	PyObject *modules = interp->modules;
+	#endif
+	PyDict_SetItemString(modules, "__main__", main_mod);
 	Py_XDECREF(main_mod);
 }

--
2.24.0

From 44f719b63238503ef8f933f55383c6d4798995cc Mon Sep 17 00:00:00 2001
From: Campbell Barton <ideasman42@gmail.com>
Date: Thu, 13 Sep 2018 17:06:07 +1000
Subject: [PATCH] Cleanup: use PyImport_GetModuleDict

Replace direct access using PyThreadState_GET
---
 source/blender/python/bmesh/bmesh_py_api.c        | 2 +-
 source/blender/python/generic/idprop_py_api.c     | 2 +-
 source/blender/python/intern/bpy_interface.c      | 2 +-
 source/blender/python/intern/gpu.c                | 4 ++--
 source/blender/python/mathutils/mathutils.c       | 2 +-
 source/blender/python/mathutils/mathutils_noise.c | 5 +++--
 source/gameengine/Ketsji/KX_PythonInit.cpp        | 2 +-
 7 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/source/blender/python/bmesh/bmesh_py_api.c b/source/blender/python/bmesh/bmesh_py_api.c
index d5973baeadb..d7324eabb6c 100644
--- a/source/blender/python/bmesh/bmesh_py_api.c
+++ b/source/blender/python/bmesh/bmesh_py_api.c
@@ -196,7 +196,7 @@ PyObject *BPyInit_bmesh(void)
 {
 	PyObject *mod;
 	PyObject *submodule;
-	PyObject *sys_modules = PyThreadState_GET()->interp->modules;
+	PyObject *sys_modules = PyImport_GetModuleDict();

 	BPy_BM_init_types();
 	BPy_BM_init_types_select();
diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c
index 4d4d5232800..8bed0f28cba 100644
--- a/source/blender/python/generic/idprop_py_api.c
+++ b/source/blender/python/generic/idprop_py_api.c
@@ -1795,7 +1795,7 @@ PyObject *BPyInit_idprop(void)
 {
 	PyObject *mod;
 	PyObject *submodule;
-	PyObject *sys_modules = PyThreadState_GET()->interp->modules;
+	PyObject *sys_modules = PyImport_GetModuleDict();

 	mod = PyModule_Create(&IDProp_module_def);

diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 7ca087e4993..123c938b921 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -537,7 +537,7 @@ static bool python_script_exec(

 	if (py_dict) {
 #ifdef PYMODULE_CLEAR_WORKAROUND
-		PyModuleObject *mmod = (PyModuleObject *)PyDict_GetItemString(PyThreadState_GET()->interp->modules, "__main__");
+		PyModuleObject *mmod = (PyModuleObject *)PyDict_GetItemString(PyImport_GetModuleDict(), "__main__");
 		PyObject *dict_back = mmod->md_dict;
 		/* freeing the module will clear the namespace,
 		 * gives problems running classes defined in this namespace being used later. */
diff --git a/source/blender/python/intern/gpu.c b/source/blender/python/intern/gpu.c
index 43796dc9474..d902b6838f4 100644
--- a/source/blender/python/intern/gpu.c
+++ b/source/blender/python/intern/gpu.c
@@ -326,7 +326,7 @@ PyObject *GPU_initPython(void)
 {
 	PyObject *module;
 	PyObject *submodule;
-	PyObject *sys_modules = PyThreadState_GET()->interp->modules;
+	PyObject *sys_modules = PyImport_GetModuleDict();

 	module = PyInit_gpu();

@@ -337,6 +337,6 @@ PyObject *GPU_initPython(void)
 	PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
 	Py_INCREF(submodule);

-	PyDict_SetItem(PyImport_GetModuleDict(), PyModule_GetNameObject(module), module);
+	PyDict_SetItem(sys_modules, PyModule_GetNameObject(module), module);
 	return module;
 }
diff --git a/source/blender/python/mathutils/mathutils.c b/source/blender/python/mathutils/mathutils.c
index a3a4e7f313b..f021d456b3a 100644
--- a/source/blender/python/mathutils/mathutils.c
+++ b/source/blender/python/mathutils/mathutils.c
@@ -615,7 +615,7 @@ PyMODINIT_FUNC PyInit_mathutils(void)
 {
 	PyObject *mod;
 	PyObject *submodule;
-	PyObject *sys_modules = PyThreadState_GET()->interp->modules;
+	PyObject *sys_modules = PyImport_GetModuleDict();

 	if (PyType_Ready(&vector_Type) < 0)
 		return NULL;
diff --git a/source/blender/python/mathutils/mathutils_noise.c b/source/blender/python/mathutils/mathutils_noise.c
index 839d1ffc588..834322c0aed 100644
--- a/source/blender/python/mathutils/mathutils_noise.c
+++ b/source/blender/python/mathutils/mathutils_noise.c
@@ -845,6 +845,7 @@ static struct PyModuleDef M_Noise_module_def = {
 /*----------------------------MODULE INIT-------------------------*/
 PyMODINIT_FUNC PyInit_mathutils_noise(void)
 {
+	PyObject *sys_modules = PyImport_GetModuleDict();
 	PyObject *submodule = PyModule_Create(&M_Noise_module_def);
 	PyObject *item_types, *item_metrics;

@@ -852,11 +853,11 @@ PyMODINIT_FUNC PyInit_mathutils_noise(void)
 	setRndSeed(0);

 	PyModule_AddObject(submodule, "types", (item_types = PyInit_mathutils_noise_types()));
-	PyDict_SetItemString(PyThreadState_GET()->interp->modules, "noise.types", item_types);
+	PyDict_SetItemString(sys_modules, "noise.types", item_types);
 	Py_INCREF(item_types);

 	PyModule_AddObject(submodule, "distance_metrics", (item_metrics = PyInit_mathutils_noise_metrics()));
-	PyDict_SetItemString(PyThreadState_GET()->interp->modules, "noise.distance_metrics", item_metrics);
+	PyDict_SetItemString(sys_modules, "noise.distance_metrics", item_metrics);
 	Py_INCREF(item_metrics);

 	return submodule;
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index 251273cf7a8..9611a4ea49b 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -2234,7 +2234,7 @@ PyMODINIT_FUNC initBGE(void)
 {
 	PyObject *mod;
 	PyObject *submodule;
-	PyObject *sys_modules = PyThreadState_GET()->interp->modules;
+	PyObject *sys_modules = PyImport_GetModuleDict();
 	const char *mod_full;

 	mod = PyModule_Create(&BGE_module_def);
--
2.25.0


code:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e89a6a9..a594786 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -126,10 +126,6 @@ find_package(LibBpf)
 find_package(LibBfd)
 find_package(LibOpcodes)

-if(${LIBBFD_FOUND} AND ${LIBOPCODES_FOUND})
-  set(HAVE_BFD_DISASM TRUE)
-endif()
-
 include(CheckIncludeFile)
 check_include_file("sys/sdt.h" HAVE_SYSTEMTAP_SYS_SDT_H)


code:
From https://github.com/Hummer12007/brightnessctl/issues/67

--- a/Makefile
+++ b/Makefile
@@ -18,6 +18,8 @@ MODE = ${MODE_${INSTALL_UDEV_RULES}}
 ifdef ENABLE_SYSTEMD
 	CFLAGS += ${shell pkg-config --cflags libsystemd}
 	LDLIBS += ${shell pkg-config --libs libsystemd}
+	CFLAGS += ${shell pkg-config --cflags libelogind}
+	LDLIBS += ${shell pkg-config --libs libelogind}
 	CPPFLAGS += -DENABLE_SYSTEMD
 	INSTALL_UDEV_RULES=0
 	MODE = 0755


code:
David Leverton writes about adventure/crc.c:

The 'adventure' game from the games-misc/bsd-games-2.13 package crashes
when saving the game on AMD64 (and probably other 64-bit systems, but I
haven't checked).  Find attached to fix this.

http://bugs.gentoo.org/show_bug.cgi?id=77032

About utmpentry.c:

the utmpx structure defines the ut_tv member a little differently on
64bit hosts so that a 32bit and 64bit structure can be shared.  So the
ut_tv is a custom 32bit structure rather than the native 64bit timeval
structure.  Work around is to assign the submembers instead.

http://bugs.gentoo.org/show_bug.cgi?id=102667

--- bsd-games/adventure/crc.c
+++ bsd-games/adventure/crc.c
@@ -134,7 +134,8 @@
				if (step >= sizeof(crctab) / sizeof(crctab[0]))
					step = 0;
			}
-			crcval = (crcval << 8) ^ crctab[i];
+			/* Mask to 32 bits. */
+			crcval = ((crcval << 8) ^ crctab[i]) & 0xffffffff;
		}
-	return crcval & 0xffffffff;	/* Mask to 32 bits. */
+	return crcval;
 }
--- bsd-games/dm/utmpentry.c
+++ bsd-games/dm/utmpentry.c
@@ -291,7 +291,8 @@
	e->line[sizeof(e->line) - 1] = '\0';
	(void)strncpy(e->host, up->ut_host, sizeof(up->ut_host));
	e->name[sizeof(e->host) - 1] = '\0';
-	e->tv = up->ut_tv;
+	e->tv.tv_sec = up->ut_tv.tv_sec;
+	e->tv.tv_usec = up->ut_tv.tv_usec;
	adjust_size(e);
 }
 #endif


code:
Remove a few 'setenv's from the definition.

diff -Naur bsd-games-2.17/config.params bsd-games-patch/config.params
--- bsd-games-2.17/config.params	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/config.params	2020-04-22 20:49:40.809695248 +0700
@@ -0,0 +1,16 @@
+bsd_games_cfg_do_chown=n
+bsd_games_cfg_non_interactive=y
+
+# Fix some man-pages: cfscores, morse, ppt, rot13, snscore, teachgammon.
+bsd_games_cfg_use_dot_so=syml
+
+# Don't build some games:
+# Countmail require some BSD-package called `from`.
+# DM is a toy to restrict access to bsd-games.
+# Fortune seems to be already packaged (fortune-mod).
+# Wargames isn't convenient as a game launcher.
+bsd_games_cfg_no_build_dirs="countmail dm fortune wargames"
+
+# Those are substitute*'d with GNU miscfiles.
+bsd_games_cfg_hangman_wordsfile=WORD_LIST
+bsd_games_cfg_dictionary_src=WORD_LIST


code:
As we cannot install outside the Store, and those games do not create the
needed writable files on their own, we need a wrapper script.

diff -Naur bsd-games-2.17/atc/Makefrag bsd-games-patch/atc/Makefrag
--- bsd-games-2.17/atc/Makefrag	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/atc/Makefrag	2020-04-23 20:24:04.446176222 +0700
@@ -47,7 +47,8 @@
	mv atc/lex.yy.c $@

 atc_install:	atc_all
-	$(INSTALL_SCORE_GAME) atc/atc $(INSTALL_PREFIX)$(GAMESDIR)/atc
+	$(INSTALL_SCORE_GAME) wrapper $(INSTALL_PREFIX)$(GAMESDIR)/atc
+	$(INSTALL_SCORE_GAME) atc/atc $(INSTALL_PREFIX)$(GAMESDIR)/.atc-real
	$(HIDE_GAME) atc
	$(INSTALL_SCORE_FILE) $(ATC_SCOREFILE)
	$(INSTALL_MANUAL) atc/atc.6
diff -Naur bsd-games-2.17/battlestar/Makefrag bsd-games-patch/battlestar/Makefrag
--- bsd-games-2.17/battlestar/Makefrag	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/battlestar/Makefrag	2020-04-23 20:24:04.482175771 +0700
@@ -32,7 +32,8 @@
 battlestar_all:	battlestar/battlestar battlestar/battlestar.6

 battlestar_install:	battlestar_all
-	$(INSTALL_SCORE_GAME) battlestar/battlestar $(INSTALL_PREFIX)$(GAMESDIR)/battlestar
+	$(INSTALL_SCORE_GAME) wrapper $(INSTALL_PREFIX)$(GAMESDIR)/battlestar
+	$(INSTALL_SCORE_GAME) battlestar/battlestar $(INSTALL_PREFIX)$(GAMESDIR)/.battlestar-real
	$(HIDE_GAME) battlestar
	$(INSTALL_MANUAL) battlestar/battlestar.6
	$(INSTALL_SCORE_FILE) $(BATTLESTAR_SCOREFILE)
diff -Naur bsd-games-2.17/canfield/canfield/Makefrag bsd-games-patch/canfield/canfield/Makefrag
--- bsd-games-2.17/canfield/canfield/Makefrag	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/canfield/canfield/Makefrag	2020-04-23 20:24:04.522175270 +0700
@@ -31,7 +31,8 @@
 canfield_canfield_all:	canfield/canfield/canfield canfield/canfield/canfield.6

 canfield_canfield_install: canfield_canfield_all
-	$(INSTALL_SCORE_GAME) canfield/canfield/canfield $(INSTALL_PREFIX)$(GAMESDIR)/canfield
+	$(INSTALL_SCORE_GAME) wrapper $(INSTALL_PREFIX)$(GAMESDIR)/canfield
+	$(INSTALL_SCORE_GAME) canfield/canfield/canfield $(INSTALL_PREFIX)$(GAMESDIR)/.canfield-real
	$(HIDE_GAME) canfield
	$(INSTALL_MANUAL) canfield/canfield/canfield.6
	$(INSTALL_SCORE_FILE) $(CANFIELD_SCOREFILE)
diff -ur bsd-games-2.17.orig/canfield/cfscores/Makefrag bsd-games-2.17/canfield/cfscores/Makefrag
--- bsd-games-2.17.orig/canfield/cfscores/Makefrag	1970-01-01 07:00:01.000000000 +0700
+++ bsd-games-2.17/canfield/cfscores/Makefrag	2020-08-06 12:20:10.592076477 +0700
@@ -32,6 +32,7 @@
 canfield_cfscores_all:	canfield/cfscores/cfscores

 canfield_cfscores_install:	canfield_cfscores_all
-	$(INSTALL_BINARY) canfield/cfscores/cfscores $(INSTALL_PREFIX)$(GAMESDIR)/cfscores
+	$(INSTALL_BINARY) wrapper $(INSTALL_PREFIX)$(GAMESDIR)/cfscores
+	$(INSTALL_BINARY) canfield/cfscores/cfscores $(INSTALL_PREFIX)$(GAMESDIR)/.cfscores-real
	$(HIDE_GAME) cfscores
	$(INSTALL_MANUAL) canfield.6 cfscores.6
diff -Naur bsd-games-2.17/cribbage/Makefrag bsd-games-patch/cribbage/Makefrag
--- bsd-games-2.17/cribbage/Makefrag	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/cribbage/Makefrag	2020-04-23 20:24:04.534175120 +0700
@@ -31,7 +31,8 @@
 cribbage_all:	cribbage/cribbage cribbage/cribbage.n cribbage/cribbage.6

 cribbage_install:	cribbage_all
-	$(INSTALL_SCORE_GAME) cribbage/cribbage $(INSTALL_PREFIX)$(GAMESDIR)/cribbage
+	$(INSTALL_SCORE_GAME) wrapper $(INSTALL_PREFIX)$(GAMESDIR)/cribbage
+	$(INSTALL_SCORE_GAME) cribbage/cribbage $(INSTALL_PREFIX)$(GAMESDIR)/.cribbage-real
	$(HIDE_GAME) cribbage
	$(INSTALL_DATA) cribbage/cribbage.n $(INSTALL_PREFIX)$(CRIBBAGE_INSTRFILE)
	$(INSTALL_SCORE_FILE) $(CRIBBAGE_SCOREFILE)
diff -Naur bsd-games-2.17/hack/Makefrag bsd-games-patch/hack/Makefrag
--- bsd-games-2.17/hack/Makefrag	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/hack/Makefrag	2020-04-23 20:24:04.590174419 +0700
@@ -53,7 +53,8 @@
 hack/hack.zap.d hack/rnd.d:	hack/hack.onames.h

 hack_install:	hack_all
-	$(INSTALL_SCORE_GAME) hack/hack $(INSTALL_PREFIX)$(GAMESDIR)/hack
+	$(INSTALL_SCORE_GAME) wrapper $(INSTALL_PREFIX)$(GAMESDIR)/hack
+	$(INSTALL_SCORE_GAME) hack/hack $(INSTALL_PREFIX)$(GAMESDIR)/.hack-real
	$(HIDE_GAME) hack
	$(INSTALL_HACK_DIR) $(INSTALL_PREFIX)$(HACK_DIR)
	set -e; for f in data help hh rumors; do $(INSTALL_DATA) hack/$$f $(INSTALL_PREFIX)$(HACK_DIR)/$$f; done
diff -Naur bsd-games-2.17/phantasia/Makefrag bsd-games-patch/phantasia/Makefrag
--- bsd-games-2.17/phantasia/Makefrag	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/phantasia/Makefrag	2020-04-23 20:24:04.650173667 +0700
@@ -38,7 +38,8 @@
	touch phantasia/scorefiles.stamp

 phantasia_install:	phantasia_all
-	$(INSTALL_SCORE_GAME) phantasia/phantasia $(INSTALL_PREFIX)$(GAMESDIR)/phantasia
+	$(INSTALL_SCORE_GAME) wrapper $(INSTALL_PREFIX)$(GAMESDIR)/phantasia
+	$(INSTALL_SCORE_GAME) phantasia/phantasia $(INSTALL_PREFIX)$(GAMESDIR)/.phantasia-real
	$(HIDE_GAME) phantasia
	(set -e; for f in $(phantasia_VFILES1); do \
	    cp phantasia/$$f $(INSTALL_PREFIX)$(PHANTASIA_DIR)/$$f; \
diff -Naur bsd-games-2.17/robots/Makefrag bsd-games-patch/robots/Makefrag
--- bsd-games-2.17/robots/Makefrag	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/robots/Makefrag	2020-04-23 20:24:04.702173016 +0700
@@ -32,7 +32,8 @@
 robots_all:	robots/robots robots/robots.6

 robots_install:	robots_all
-	$(INSTALL_SCORE_GAME) robots/robots $(INSTALL_PREFIX)$(GAMESDIR)/robots
+	$(INSTALL_SCORE_GAME) wrapper $(INSTALL_PREFIX)$(GAMESDIR)/robots
+	$(INSTALL_SCORE_GAME) robots/robots $(INSTALL_PREFIX)$(GAMESDIR)/.robots-real
	$(HIDE_GAME) robots
	$(INSTALL_SCORE_FILE) $(ROBOTS_SCOREFILE)
	$(INSTALL_MANUAL) robots/robots.6
diff -Naur bsd-games-2.17/sail/Makefrag bsd-games-patch/sail/Makefrag
--- bsd-games-2.17/sail/Makefrag	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/sail/Makefrag	2020-04-23 20:24:04.710172917 +0700
@@ -31,7 +31,8 @@
 sail_all:	sail/sail sail/sail.6

 sail_install:	sail_all
-	$(INSTALL_SCORE_GAME) sail/sail $(INSTALL_PREFIX)$(GAMESDIR)/sail
+	$(INSTALL_SCORE_GAME) wrapper $(INSTALL_PREFIX)$(GAMESDIR)/sail
+	$(INSTALL_SCORE_GAME) sail/sail $(INSTALL_PREFIX)$(GAMESDIR)/.sail-real
	$(HIDE_GAME) sail
	$(INSTALL_SCORE_FILE) $(SAIL_SCOREFILE)
	$(INSTALL_SAIL_DIR) $(INSTALL_PREFIX)$(SAIL_DIR)
diff -Naur bsd-games-2.17/snake/snake/Makefrag bsd-games-patch/snake/snake/Makefrag
--- bsd-games-2.17/snake/snake/Makefrag	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/snake/snake/Makefrag	2020-04-23 20:24:04.722172766 +0700
@@ -31,7 +31,8 @@
 snake_snake_all:	snake/snake/snake snake/snake/snake.6

 snake_snake_install:	snake_snake_all
-	$(INSTALL_SCORE_GAME) snake/snake/snake $(INSTALL_PREFIX)$(GAMESDIR)/snake
+	$(INSTALL_SCORE_GAME) wrapper $(INSTALL_PREFIX)$(GAMESDIR)/snake
+	$(INSTALL_SCORE_GAME) snake/snake/snake $(INSTALL_PREFIX)$(GAMESDIR)/.snake-real
	$(HIDE_GAME) snake
	$(INSTALL_SCORE_FILE) $(SNAKE_SCOREFILE)
	$(INSTALL_SCORE_FILE) $(SNAKE_RAWSCOREFILE)
--- bsd-games-2.17.orig/snake/snscore/Makefrag	1970-01-01 07:00:01.000000000 +0700
+++ bsd-games-2.17/snake/snscore/Makefrag	2020-08-06 12:33:09.636089394 +0700
@@ -32,6 +32,7 @@
 snake_snscore_all:	snake/snscore/snscore

 snake_snscore_install:	snake_snscore_all
-	$(INSTALL_BINARY) snake/snscore/snscore $(INSTALL_PREFIX)$(GAMESDIR)/snscore
+	$(INSTALL_BINARY) wrapper $(INSTALL_PREFIX)$(GAMESDIR)/snscore
+	$(INSTALL_BINARY) snake/snscore/snscore $(INSTALL_PREFIX)$(GAMESDIR)/.snscore-real
	$(HIDE_GAME) snscore
	$(INSTALL_MANUAL) snake.6 snscore.6
diff -Naur bsd-games-2.17/tetris/Makefrag bsd-games-patch/tetris/Makefrag
--- bsd-games-2.17/tetris/Makefrag	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/tetris/Makefrag	2020-04-23 20:24:04.734172616 +0700
@@ -32,7 +32,8 @@
 tetris_all:	tetris/tetris tetris/tetris.6

 tetris_install:	tetris_all
-	$(INSTALL_SCORE_GAME) tetris/tetris $(INSTALL_PREFIX)$(GAMESDIR)/tetris-bsd
+	$(INSTALL_SCORE_GAME) wrapper $(INSTALL_PREFIX)$(GAMESDIR)/tetris-bsd
+	$(INSTALL_SCORE_GAME) tetris/tetris $(INSTALL_PREFIX)$(GAMESDIR)/.tetris-bsd-real
	$(HIDE_GAME) tetris-bsd
	$(INSTALL_SCORE_FILE) $(TETRIS_SCOREFILE)
	ln -f tetris/tetris.6 tetris/tetris-bsd.6
diff -Naur bsd-games-2.17/wrapper bsd-games-patch/wrapper
--- bsd-games-2.17/wrapper	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/wrapper	2020-04-23 20:24:37.153766719 +0700
@@ -0,0 +1,91 @@
+#!/bin/sh
+# This file works around limitations of our read-only Store.
+
+set -e
+
+check_empty_files () {
+    # those start empty
+    for f in ${@}
+    do
+        if [[ ! -f ${f} ]]
+        then
+            touch      ${f}
+            echo "$(pwd)/${f} RESTORED"
+        fi
+    done
+}
+check_data_files () {
+    # those start with some initial data
+    for f in ${@}
+    do
+        if [[ ! -f ${f} ]]
+        then
+            cp STATIC_DATA/${game}/${f} ${f}
+            chmod u+w ${f}
+            echo "$(pwd)/${f} RESTORED"
+        fi
+    done
+}
+visit_dir () {
+    mkdir -p ${1}
+    cd ${1}
+}
+exit_with_variable_error () {
+    variables="${1}${2:+ or ${2}}"
+    echo "Guix: Please set up the ${variables} variable."
+    echo "Examples:"
+    echo "   export ${1}=/var/multiplayer"
+    echo "   export ${2:-${1}}=~/.local/share/bsd-games"
+    echo "You can place this in ~/.bashrc or a similar file for Your shell."
+    echo "For multiplayer this directory should be writable for all players."
+    exit 1
+}
+
+game=$(basename $0)
+if [[ ${game} == "hack" ]]
+then
+    if   [[ -n ${HACKDIR} ]];       then visit_dir "${HACKDIR}"
+    elif [[ -n ${BSD_GAMES_DIR} ]]; then visit_dir "${BSD_GAMES_DIR}/hack"
+    else exit_with_variable_error "HACKDIR" "BSD_GAMES_DIR"
+    fi
+else
+    if [[ -n ${BSD_GAMES_DIR} ]]; then visit_dir "${BSD_GAMES_DIR}"
+    else exit_with_variable_error "BSD_GAMES_DIR"
+    fi
+fi
+
+case ${game} in
+    ### Games with score-files
+    atc)
+        check_empty_files "atc_score";;
+    battlestar)
+        check_empty_files "battlestar.log";;
+    canfield)
+        check_empty_files "cfscores";;
+    cribbage)
+        check_empty_files "criblog";;
+    robots)
+        check_empty_files "robots_roll";;
+    snake)
+        check_empty_files "snakerawscores" "snake.log";;
+    tetris)
+        check_empty_files "tetris-bsd.scores";;
+    ### Games with saved state
+    hack)
+        check_empty_files "record" "perm"
+        check_data_files "data" "help" "hh" "rumors"
+        visit_dir "save"
+        cd ../../;;
+    phantasia)
+        visit_dir "phantasia"
+        check_empty_files "characs" "gold" "lastdead"\
+                          "mess" "motd" "scoreboard" "void"
+        check_data_files "monsters"
+        cd ../;;
+    sail)
+        visit_dir "sail"
+        check_empty_files "log" "syncfile"
+        cd ../;;
+esac
+
+exec .${game}-real ${@}


code:
diff --git a/hunt/hunt/playit.c b/hunt/hunt/playit.c
index 9acf86e..881a4e7 100644
--- a/hunt/hunt/playit.c
+++ b/hunt/hunt/playit.c
@@ -114,7 +114,7 @@ playit()
		bad_con();
		/* NOTREACHED */
	}
-	if (ntohl(version) != (unsigned long)HUNT_VERSION) {
+	if (ntohl(version) != (uint32_t)HUNT_VERSION) {
		bad_ver();
		/* NOTREACHED */
	}
@@ -649,7 +649,7 @@ do_message()
		bad_con();
		/* NOTREACHED */
	}
-	if (ntohl(version) != (unsigned long)HUNT_VERSION) {
+	if (ntohl(version) != (uint32_t)HUNT_VERSION) {
		bad_ver();
		/* NOTREACHED */
	}


code:
Those games rely on user to provide the files to write scores in.
Those score-files are initially empty.  Anyway, the Store is read-only.
So we do not install those empty files.

diff -Naur bsd-games-2.17/install-score.in bsd-games-patch/install-score.in
--- bsd-games-2.17/install-score.in	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/install-score.in	2020-04-22 21:41:47.810544804 +0700
@@ -1,45 +0,0 @@
-# install-score.in - install a score file
-#
-# Copyright (c) 1997, 1998, 1999 Joseph Samuel Myers.
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. The name of the author may not be used to endorse or promote products
-#    derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
-# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-
-set -e
-
-if [ "$1" = "-p" ]; then
-    scorefile="@install_prefix@$2"
-    perms=@vardata_perms_priv@
-else
-    scorefile="@install_prefix@$1"
-    perms=@vardata_perms@
-fi
-
-mkdir -p "$(dirname "$scorefile")"
-
-test -e "$scorefile" || touch "$scorefile"
-if [ @do_chown@ = y ]; then
-    chown @vardata_owner@:@vardata_group@ "$scorefile"
-fi
-chmod "$perms" "$scorefile"
diff -Naur bsd-games-2.17/phantasia/Makefrag bsd-games-patch/phantasia/Makefrag
--- bsd-games-2.17/phantasia/Makefrag	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/phantasia/Makefrag	2020-04-22 21:26:00.162409464 +0700
@@ -27,9 +27,8 @@
 # SUCH DAMAGE.

 phantasia_DIRS := $(GAMESDIR) $(MAN6DIR) $(PHANTASIA_DIR)
-phantasia_VFILES1 := gold lastdead mess monsters motd void
-phantasia_VFILES2 := scoreboard characs
-phantasia_CLEANFILES := $(phantasia_VFILES1) $(phantasia_VFILES2) scorefiles.stamp
+phantasia_VFILES1 := monsters
+phantasia_CLEANFILES := $(phantasia_VFILES1) scorefiles.stamp

 phantasia_all:	phantasia/phantasia phantasia/phantasia.6 phantasia/scorefiles.stamp

@@ -43,9 +42,4 @@
	(set -e; for f in $(phantasia_VFILES1); do \
	    cp phantasia/$$f $(INSTALL_PREFIX)$(PHANTASIA_DIR)/$$f; \
	    $(INSTALL_SCORE_FILE) $(PHANTASIA_DIR)/$$f; done)
-	(set -e; for f in $(phantasia_VFILES2); do \
-	    if [ ! -e $(PHANTASIA_DIR)/$$f ]; then \
-		cp phantasia/$$f $(INSTALL_PREFIX)$(PHANTASIA_DIR)/$$f; fi; done; \
-	    $(INSTALL_SCORE_FILE) $(PHANTASIA_DIR)/scoreboard; \
-	    $(INSTALL_SCORE_FILE) -p $(PHANTASIA_DIR)/characs)
	$(INSTALL_MANUAL) phantasia/phantasia.6
diff -Naur bsd-games-2.17/sail/Makefrag bsd-games-patch/sail/Makefrag
--- bsd-games-2.17/sail/Makefrag	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/sail/Makefrag	2020-04-22 21:26:48.701801676 +0700
@@ -34,5 +34,4 @@
	$(INSTALL_SCORE_GAME) sail/sail $(INSTALL_PREFIX)$(GAMESDIR)/sail
	$(HIDE_GAME) sail
	$(INSTALL_SCORE_FILE) $(SAIL_SCOREFILE)
-	$(INSTALL_SAIL_DIR) $(INSTALL_PREFIX)$(SAIL_DIR)
	$(INSTALL_MANUAL) sail/sail.6


code:
--- a/dab/gamescreen.h	2004-01-02 23:34:51.000000000 +0530
+++ b/dab/gamescreen.h	2008-07-31 23:45:19.000000000 +0530
@@ -70,9 +70,9 @@
     virtual void redraw(void) = 0;			// Refresh
     virtual int getinput(void) = 0;			// Get user input
     virtual void bell(void) = 0;			// Beep
-    virtual void score(size_t p, const PLAYER& p) = 0;	// Post current score
-    virtual void games(size_t p, const PLAYER& p) = 0;	// Post games won
-    virtual void total(size_t p, const PLAYER& p) = 0;	// Post total score
+    virtual void score(size_t, const PLAYER&) = 0;	// Post current score
+    virtual void games(size_t, const PLAYER&) = 0;	// Post games won
+    virtual void total(size_t, const PLAYER&) = 0;	// Post total score
     virtual void ties(const PLAYER& p) = 0;		// Post tie games
 };


code:
diff -Naur bsd-games-2.17/boggle/boggle/bog.c bsd-games-2.17.1/boggle/boggle/bog.c
--- bsd-games-2.17/boggle/boggle/bog.c	2004-12-07 07:34:21.000000000 -0600
+++ bsd-games-2.17.1/boggle/boggle/bog.c	2010-05-22 10:51:23.000000000 -0500
@@ -336,7 +336,7 @@
	}

	while (1) {
-		if (getline(buf) == NULL) {
+		if (boggle_getline(buf) == NULL) {
			if (feof(stdin))
				clearerr(stdin);
			break;
diff -Naur bsd-games-2.17/boggle/boggle/extern.h bsd-games-2.17.1/boggle/boggle/extern.h
--- bsd-games-2.17/boggle/boggle/extern.h	2004-01-27 14:52:07.000000000 -0600
+++ bsd-games-2.17.1/boggle/boggle/extern.h	2010-05-22 10:51:23.000000000 -0500
@@ -43,7 +43,7 @@
 long	 dictseek(FILE *, long, int);
 void	 findword(void);
 void	 flushin(FILE *);
-char	*getline(char *);
+char	*boggle_getline(char *);
 void	 getword(char *);
 int	 help(void);
 int	 inputch(void);
diff -Naur bsd-games-2.17/boggle/boggle/mach.c bsd-games-2.17.1/boggle/boggle/mach.c
--- bsd-games-2.17/boggle/boggle/mach.c	2004-12-07 07:34:21.000000000 -0600
+++ bsd-games-2.17.1/boggle/boggle/mach.c	2010-05-22 10:51:23.000000000 -0500
@@ -168,7 +168,7 @@
  * - doesn't accept words longer than MAXWORDLEN or containing caps
  */
 char *
-getline(q)
+boggle_getline(q)
	char *q;
 {
	int ch, done;
diff -Naur bsd-games-2.17/cribbage/cribbage.h bsd-games-2.17.1/cribbage/cribbage.h
--- bsd-games-2.17/cribbage/cribbage.h	2004-02-08 16:29:14.000000000 -0600
+++ bsd-games-2.17.1/cribbage/cribbage.h	2010-05-22 10:51:23.000000000 -0500
@@ -77,7 +77,7 @@
 int	 fifteens(const CARD [], int);
 void	 game(void);
 void	 gamescore(void);
-char	*getline(void);
+char	*cribbage_getline(void);
 int	 getuchar(void);
 int	 incard(CARD *);
 int	 infrom(const CARD [], int, const char *);
diff -Naur bsd-games-2.17/cribbage/crib.c bsd-games-2.17.1/cribbage/crib.c
--- bsd-games-2.17/cribbage/crib.c	2004-01-27 14:52:07.000000000 -0600
+++ bsd-games-2.17.1/cribbage/crib.c	2010-05-22 10:51:23.000000000 -0500
@@ -221,7 +221,7 @@
			if (!rflag) {			/* player cuts deck */
				msg(quiet ? "Cut for crib? " :
			    "Cut to see whose crib it is -- low card wins? ");
-				getline();
+				cribbage_getline();
			}
			i = (rand() >> 4) % CARDS;	/* random cut */
			do {	/* comp cuts deck */
@@ -397,7 +397,7 @@
		if (!rflag) {	/* random cut */
			msg(quiet ? "Cut the deck? " :
		    "How many cards down do you wish to cut the deck? ");
-			getline();
+			cribbage_getline();
		}
		i = (rand() >> 4) % (CARDS - pos);
		turnover = deck[i + pos];
diff -Naur bsd-games-2.17/cribbage/io.c bsd-games-2.17.1/cribbage/io.c
--- bsd-games-2.17/cribbage/io.c	2004-12-07 07:34:21.000000000 -0600
+++ bsd-games-2.17.1/cribbage/io.c	2010-05-22 10:51:23.000000000 -0500
@@ -245,7 +245,7 @@

	retval = FALSE;
	rnk = sut = EMPTY;
-	if (!(line = getline()))
+	if (!(line = cribbage_getline()))
		goto gotit;
	p = p1 = line;
	while (*p1 != ' ' && *p1 != '\0')
@@ -346,7 +346,7 @@

	for (sum = 0;;) {
		msg(prompt);
-		if (!(p = getline()) || *p == '\0') {
+		if (!(p = cribbage_getline()) || *p == '\0') {
			msg(quiet ? "Not a number" :
			    "That doesn't look like a number");
			continue;
@@ -528,12 +528,12 @@
 }

 /*
- * getline:
+ * cribbage_getline:
  *      Reads the next line up to '\n' or EOF.  Multiple spaces are
  *	compressed to one space; a space is inserted before a ','
  */
 char *
-getline()
+cribbage_getline()
 {
	char *sp;
	int c, oy, ox;
diff -Naur bsd-games-2.17/gomoku/bdisp.c bsd-games-2.17.1/gomoku/bdisp.c
--- bsd-games-2.17/gomoku/bdisp.c	2003-12-16 20:47:37.000000000 -0600
+++ bsd-games-2.17.1/gomoku/bdisp.c	2010-05-22 10:51:23.000000000 -0500
@@ -241,7 +241,7 @@
 }

 int
-getline(buf, size)
+gomoku_getline(buf, size)
	char *buf;
	int size;
 {
diff -Naur bsd-games-2.17/gomoku/gomoku.h bsd-games-2.17.1/gomoku/gomoku.h
--- bsd-games-2.17/gomoku/gomoku.h	2004-01-27 14:52:07.000000000 -0600
+++ bsd-games-2.17.1/gomoku/gomoku.h	2010-05-22 10:51:23.000000000 -0500
@@ -263,7 +263,7 @@

 void	bdinit(struct spotstr *);
 void	init_overlap(void);
-int	getline(char *, int);
+int	gomoku_getline(char *, int);
 void	ask(const char *);
 void	dislog(const char *);
 void	bdump(FILE *);
diff -Naur bsd-games-2.17/gomoku/main.c bsd-games-2.17.1/gomoku/main.c
--- bsd-games-2.17/gomoku/main.c	2004-01-27 14:52:07.000000000 -0600
+++ bsd-games-2.17.1/gomoku/main.c	2010-05-22 10:51:23.000000000 -0500
@@ -155,7 +155,7 @@
		if (inputfp == NULL && test == 0) {
			for (;;) {
				ask("black or white? ");
-				getline(buf, sizeof(buf));
+				gomoku_getline(buf, sizeof(buf));
				if (buf[0] == 'b' || buf[0] == 'B') {
					color = BLACK;
					break;
@@ -172,7 +172,7 @@
		}
	} else {
		setbuf(stdout, 0);
-		getline(buf, sizeof(buf));
+		gomoku_getline(buf, sizeof(buf));
		if (strcmp(buf, "black") == 0)
			color = BLACK;
		else if (strcmp(buf, "white") == 0)
@@ -244,7 +244,7 @@
		getinput:
			if (interactive)
				ask("move? ");
-			if (!getline(buf, sizeof(buf))) {
+			if (!gomoku_getline(buf, sizeof(buf))) {
				curmove = RESIGN;
				break;
			}
@@ -256,7 +256,7 @@
					FILE *fp;

					ask("save file name? ");
-					(void)getline(buf, sizeof(buf));
+					(void)gomoku_getline(buf, sizeof(buf));
					if ((fp = fopen(buf, "w")) == NULL) {
						glog("cannot create save file");
						goto getinput;
@@ -309,14 +309,14 @@
		if (i != RESIGN) {
		replay:
			ask("replay? ");
-			if (getline(buf, sizeof(buf)) &&
+			if (gomoku_getline(buf, sizeof(buf)) &&
			    (buf[0] == 'y' || buf[0] == 'Y'))
				goto again;
			if (strcmp(buf, "save") == 0) {
				FILE *fp;

				ask("save file name? ");
-				(void)getline(buf, sizeof(buf));
+				(void)gomoku_getline(buf, sizeof(buf));
				if ((fp = fopen(buf, "w")) == NULL) {
					glog("cannot create save file");
					goto replay;
@@ -367,7 +367,7 @@
		quit();
 top:
	ask("cmd? ");
-	if (!getline(fmtbuf, sizeof(fmtbuf)))
+	if (!gomoku_getline(fmtbuf, sizeof(fmtbuf)))
		quit();
	switch (*fmtbuf) {
	case '\0':


code:
diff --git a/hunt/hunt/hunt.c b/hunt/hunt/hunt.c
index 11f4c44..28321bc 100644
--- a/hunt/hunt/hunt.c
+++ b/hunt/hunt/hunt.c
@@ -394,7 +394,8 @@ broadcast_vec(s, vector)

	vec_cnt = 0;
	for (ip = ifp; ip; ip = ip->ifa_next)
-		if ((ip->ifa_addr->sa_family == AF_INET) &&
+		if (ip->ifa_addr &&
+		    (ip->ifa_addr->sa_family == AF_INET) &&
		    (ip->ifa_flags & IFF_BROADCAST))
			vec_cnt++;

@@ -405,7 +406,8 @@ broadcast_vec(s, vector)

	vec_cnt = 0;
	for (ip = ifp; ip; ip = ip->ifa_next)
-		if ((ip->ifa_addr->sa_family == AF_INET) &&
+		if (ip->ifa_addr &&
+		    (ip->ifa_addr->sa_family == AF_INET) &&
		    (ip->ifa_flags & IFF_BROADCAST))
			memcpy(&(*vector)[vec_cnt++], ip->ifa_broadaddr,
			       sizeof(struct sockaddr_in));


code:
Arch's patch, and a fix for the "number" game's test.
--- bsdgames-2.17.orig/number/number.c
+++ bsdgames-2.17/number/number.c
@@ -78,9 +78,9 @@

 void	convert(char *);
 int	main(int, char *[]);
-int	number(const char *, int);
-void	pfract(int);
-int	unit(int, const char *);
+int	number(const char *, int, int *);
+void	pfract(int, int);
+int	unit(int, const char *, int *);
 void	usage(void) __attribute__((__noreturn__));

 int lflag;
@@ -131,7 +131,7 @@
 convert(line)
	char *line;
 {
-	int flen, len, rval;
+	int flen, len, rval, singular;
	char *p, *fraction;

	flen = 0;
@@ -174,7 +174,7 @@
		--len;
	}

-	rval = len > 0 ? unit(len, line) : 0;
+	rval = len > 0 ? unit(len, line, &singular) : 0;
	if (fraction != NULL && flen != 0)
		for (p = fraction; *p != '\0'; ++p)
			if (*p != '0') {
@@ -182,10 +182,10 @@
					(void)printf("%sand%s",
					    lflag ? " " : "",
					    lflag ? " " : "\n");
-				if (unit(flen, fraction)) {
+				if (unit(flen, fraction, &singular)) {
					if (lflag)
						(void)printf(" ");
-					pfract(flen);
+					pfract(flen, singular);
					rval = 1;
				}
				break;
@@ -197,9 +197,10 @@
 }

 int
-unit(len, p)
+unit(len, p, singular)
	int len;
	const char *p;
+	int *singular;
 {
	int off, rval;

@@ -208,7 +209,7 @@
		if (len % 3) {
			off = len % 3;
			len -= off;
-			if (number(p, off)) {
+			if (number(p, off, singular)) {
				rval = 1;
				(void)printf(" %s%s",
				    name3[len / 3], lflag ? " " : ".\n");
@@ -217,14 +218,16 @@
		}
		for (; len > 3; p += 3) {
			len -= 3;
-			if (number(p, 3)) {
+			if (number(p, 3, singular)) {
				rval = 1;
				(void)printf(" %s%s",
				    name3[len / 3], lflag ? " " : ".\n");
			}
		}
	}
-	if (number(p, len)) {
+	if (number(p, len, singular)) {
+		if (rval)
+			*singular = 0;
		if (!lflag)
			(void)printf(".\n");
		rval = 1;
@@ -233,17 +236,20 @@
 }

 int
-number(p, len)
+number(p, len, singular)
	const char *p;
	int len;
+	int *singular;
 {
	int val, rval;

	rval = 0;
+	*singular = 1;
	switch (len) {
	case 3:
		if (*p != '0') {
			rval = 1;
+			*singular = 0;
			(void)printf("%s hundred", name1[*p - '0']);
		}
		++p;
@@ -262,33 +268,42 @@
			}
			rval = 1;
		}
+		if (val != 1)
+			*singular = 0;
		break;
	case 1:
		if (*p != '0') {
			rval = 1;
			(void)printf("%s", name1[*p - '0']);
		}
+		if (*p != '1')
+			*singular = 0;
	}
	return (rval);
 }

 void
-pfract(len)
+pfract(len, singular)
	int len;
+	int singular;
 {
	static const char *const pref[] = { "", "ten-", "hundred-" };

	switch(len) {
	case 1:
-		(void)printf("tenths.\n");
+		(void)printf("tenth");
		break;
	case 2:
-		(void)printf("hundredths.\n");
+		(void)printf("hundredth");
		break;
	default:
-		(void)printf("%s%sths.\n", pref[len % 3], name3[len / 3]);
+		(void)printf("%s%sth", pref[len % 3], name3[len / 3]);
		break;
	}
+	if (!singular) {
+		printf("s");
+	}
+	printf(".\n");
 }

 void
diff -Naur bsd-games-2.17/tests/number.-0.1 bsd-games-patch/tests/number.-0.1
--- bsd-games-2.17/tests/number.-0.1	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/tests/number.-0.1	2020-04-17 15:14:27.831098084 +0700
@@ -1,3 +1,3 @@
 minus
 one.
-tenths.
+tenth.
diff -Naur bsd-games-2.17/tests/number.-0.2 bsd-games-patch/tests/number.-0.2
--- bsd-games-2.17/tests/number.-0.2	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/tests/number.-0.2	2020-04-17 15:20:48.162336279 +0700
@@ -0,0 +1,3 @@
+minus
+two.
+tenths.
diff -Naur bsd-games-2.17/tests/number.test bsd-games-patch/tests/number.test
--- bsd-games-2.17/tests/number.test	1970-01-01 07:00:00.000000000 +0700
+++ bsd-games-patch/tests/number.test	2020-04-17 15:20:22.774654155 +0700
@@ -36,6 +36,8 @@
 testno 1
 number/number -- -0.1 >test.out 2>&1 || failtest
 compare test.out tests/number.-0.1
+number/number -- -0.2 >test.out 2>&1 || failtest
+compare test.out tests/number.-0.2
 rm -f test.out

 testno 2


code:
There is already a "fish" shell.
diff -ur bsd-games-2.17.orig/fish/Makefrag bsd-games-2.17/fish/Makefrag
--- bsd-games-2.17.orig/fish/Makefrag	1970-01-01 07:00:01.000000000 +0700
+++ bsd-games-2.17/fish/Makefrag	2020-08-06 19:18:43.204492847 +0700
@@ -31,7 +31,7 @@
 fish_all:	fish/fish fish/fish.instr fish/fish.6

 fish_install:	fish_all
-	$(INSTALL_BINARY) fish/fish $(INSTALL_PREFIX)$(GAMESDIR)/fish
+	$(INSTALL_BINARY) fish/fish $(INSTALL_PREFIX)$(GAMESDIR)/fish-game
	$(HIDE_GAME) fish
	$(INSTALL_DATA) fish/fish.instr $(INSTALL_PREFIX)$(FISH_INSTRFILE)
	$(INSTALL_MANUAL) fish/fish.6


code:
diff -ru a/include/stdio.h b/include/stdio.h
--- a/include/stdio.h	2000-08-04 10:24:39.000000000 +1000
+++ b/include/stdio.h	2005-06-18 14:26:35.000000000 +1000
@@ -34,6 +34,10 @@
 #include <bsd-games.h>
 #include_next <stdio.h>

+__BEGIN_DECLS
+
 #ifndef HAVE_fgetln
 extern char *fgetln(FILE *stream, size_t *len);
 #endif
+
+__END_DECLS


code:
Skeleton status files are installed read-only.  When copying to the config dir
upon initialization, make sure they end up writable.

--- byobu-5.127/usr/bin/byobu-janitor.in
+++ byobu-5.127/usr/bin/byobu-janitor.in
@@ -82,6 +82,7 @@
 	if [ ! -r "$BYOBU_CONFIG_DIR/$f" ]; then
 		# Copy from skeleton, if possible
 		cp -f "$BYOBU_PREFIX/share/$PKG/status/$f" "$BYOBU_CONFIG_DIR/$f"
+		chmod +w "$BYOBU_CONFIG_DIR/$f"
 	fi
 done


code:
From f5cf01083baf7e8dc8318db3648bc6098dc32d67 Mon Sep 17 00:00:00 2001
From: Nicholas Guriev <guriev-ns@ya.ru>
Date: Sat, 18 Apr 2020 13:30:17 +0300
Subject: [PATCH] Search for GoogleTest via pkg-config first

---
 tests/CMakeLists.txt | 55 ++++++++++++++++++++++++--------------------
 1 file changed, 30 insertions(+), 25 deletions(-)

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 02193197..53d475c2 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,36 +1,41 @@
 cmake_minimum_required(VERSION 3.0.2)

 project(GSLTests CXX)
+include(FindPkgConfig)

 # will make visual studio generated project group files
 set_property(GLOBAL PROPERTY USE_FOLDERS ON)

-configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
-execute_process(
-    COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
-    RESULT_VARIABLE result
-    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download
-)
-if(result)
-    message(FATAL_ERROR "CMake step for googletest failed: ${result}")
-endif()
+pkg_search_module(GTestMain gtest_main)
+if (NOT GTestMain_FOUND)
+    configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
+    execute_process(
+        COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
+        RESULT_VARIABLE result
+        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download
+    )
+    if(result)
+        message(FATAL_ERROR "CMake step for googletest failed: ${result}")
+    endif()

-execute_process(
-    COMMAND ${CMAKE_COMMAND} --build .
-    RESULT_VARIABLE result
-    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download
-)
-if(result)
-    message(FATAL_ERROR "CMake step for googletest failed: ${result}")
-endif()
+    execute_process(
+        COMMAND ${CMAKE_COMMAND} --build .
+        RESULT_VARIABLE result
+        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download
+    )
+    if(result)
+        message(FATAL_ERROR "CMake step for googletest failed: ${result}")
+    endif()

-set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
+    set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
+    set(GTestMain_LIBRARIES gtest_main)

-add_subdirectory(
-    ${CMAKE_CURRENT_BINARY_DIR}/googletest-src
-    ${CMAKE_CURRENT_BINARY_DIR}/googletest-build
-    EXCLUDE_FROM_ALL
-)
+    add_subdirectory(
+        ${CMAKE_CURRENT_BINARY_DIR}/googletest-src
+        ${CMAKE_CURRENT_BINARY_DIR}/googletest-build
+        EXCLUDE_FROM_ALL
+    )
+endif()

 if (MSVC AND (GSL_CXX_STANDARD EQUAL 17))
     set(GSL_CPLUSPLUS_OPT -Zc:__cplusplus -permissive-)
@@ -149,7 +154,7 @@ function(add_gsl_test name)
     target_link_libraries(${name}
         GSL
         gsl_tests_config
-        gtest_main
+        ${GTestMain_LIBRARIES}
     )
     add_test(
         ${name}
@@ -254,7 +259,7 @@ function(add_gsl_test_noexcept name)
     target_link_libraries(${name}
         GSL
         gsl_tests_config_noexcept
-        gtest_main
+        ${GTestMain_LIBRARIES}
     )
     add_test(
       ${name}


code:
Copied from Debian.

From: Carlos Garcia Campos <cgarcia@igalia.com>
Date: Mon, 19 Nov 2018 12:33:07 +0100
Subject: ft: Use FT_Done_MM_Var instead of free when available in
 cairo_ft_apply_variations

Fixes a crash when using freetype >= 2.9

[This is considered to be security-sensitive because WebKitGTK+ sets its
own memory allocator, which is not compatible with system free(), making
this a remotely triggerable denial of service or memory corruption.]

Origin: upstream, commit:90e85c2493fdfa3551f202ff10282463f1e36645
Bug: https://gitlab.freedesktop.org/cairo/cairo/merge_requests/5
Bug-Debian: https://bugs.debian.org/916389
Bug-CVE: CVE-2018-19876
---
 src/cairo-ft-font.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 325dd61..981973f 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -2393,7 +2393,11 @@ skip:
 done:
         free (coords);
         free (current_coords);
+#if HAVE_FT_DONE_MM_VAR
+        FT_Done_MM_Var (face->glyph->library, ft_mm_var);
+#else
         free (ft_mm_var);
+#endif
     }
 }


code:
Copied from Debian.

From 03a820b173ed1fdef6ff14b4468f5dbc02ff59be Mon Sep 17 00:00:00 2001
From: Heiko Lewin <heiko.lewin@worldiety.de>
Date: Tue, 15 Dec 2020 16:48:19 +0100
Subject: [PATCH] Fix mask usage in image-compositor

[trimmed test case, since not used in Debian build]

---
 src/cairo-image-compositor.c                |   8 ++--

--- cairo-1.16.0.orig/src/cairo-image-compositor.c
+++ cairo-1.16.0/src/cairo-image-compositor.c
@@ -2601,14 +2601,14 @@ _inplace_src_spans (void *abstract_rende
 		    unsigned num_spans)
 {
     cairo_image_span_renderer_t *r = abstract_renderer;
-    uint8_t *m;
+    uint8_t *m, *base = (uint8_t*)pixman_image_get_data(r->mask);
     int x0;

     if (num_spans == 0)
 	return CAIRO_STATUS_SUCCESS;

     x0 = spans[0].x;
-    m = r->_buf;
+    m = base;
     do {
 	int len = spans[1].x - spans[0].x;
 	if (len >= r->u.composite.run_length && spans[0].coverage == 0xff) {
@@ -2646,7 +2646,7 @@ _inplace_src_spans (void *abstract_rende
 				      spans[0].x, y,
 				      spans[1].x - spans[0].x, h);

-	    m = r->_buf;
+	    m = base;
 	    x0 = spans[1].x;
 	} else if (spans[0].coverage == 0x0) {
 	    if (spans[0].x != x0) {
@@ -2675,7 +2675,7 @@ _inplace_src_spans (void *abstract_rende
 #endif
 	    }

-	    m = r->_buf;
+	    m = base;
 	    x0 = spans[1].x;
 	} else {
 	    *m++ = spans[0].coverage;


code:
From 19e8d7701c302b0eca4c638705a6db625352caa3 Mon Sep 17 00:00:00 2001
From: Brendan Tildesley <mail@brendan.scot>
Date: Thu, 25 Feb 2021 12:17:30 +1100
Subject: [PATCH] Don't check for updates.

---
 src/calibre/gui2/main.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py
index 776f8bebfb..4302716d7e 100644
--- a/src/calibre/gui2/main.py
+++ b/src/calibre/gui2/main.py
@@ -59,8 +59,8 @@ def option_parser():
                       help=_('Start minimized to system tray.'))
     parser.add_option('-v', '--verbose', default=0, action='count',
                       help=_('Ignored, do not use. Present only for legacy reasons'))
-    parser.add_option('--no-update-check', default=False, action='store_true',
-            help=_('Do not check for updates'))
+    parser.add_option('--update-check', dest='no_update_check', default=True, action='store_false',
+            help=_('Check for updates'))
     parser.add_option('--ignore-plugins', default=False, action='store_true',
             help=_('Ignore custom plugins, useful if you installed a plugin'
                 ' that is preventing calibre from starting'))
--
2.30.1


code:
From d8225e83c3b73f0e0da73874910f50ca652f48cf Mon Sep 17 00:00:00 2001
From: Brendan Tildesley <mail@brendan.scot>
Date: Thu, 25 Feb 2021 00:48:00 +1100
Subject: [PATCH] Remove test_sqlite

---
 src/calibre/test_build.py | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py
index 0ab7aa0646..87fdfabd9a 100644
--- a/src/calibre/test_build.py
+++ b/src/calibre/test_build.py
@@ -273,12 +273,6 @@ def read_changes():
         m.close()
         self.assertEqual(winutil.parse_cmdline('"c:\\test exe.exe" "some arg" 2'), ('c:\\test exe.exe', 'some arg', '2'))

-    def test_sqlite(self):
-        import sqlite3
-        conn = sqlite3.connect(':memory:')
-        from calibre.library.sqlite import load_c_extensions
-        self.assertTrue(load_c_extensions(conn, True), 'Failed to load sqlite extension')
-
     def test_apsw(self):
         import apsw
         conn = apsw.Connection(':memory:')
--
2.30.1


code:
From 9edf67191cc3655480b6fd418247709ade930b1a Mon Sep 17 00:00:00 2001
From: Brendan Tildesley <mail@brendan.scot>
Date: Thu, 25 Feb 2021 00:33:10 +1100
Subject: [PATCH] Remove test_unrar

---
 src/calibre/test_build.py | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py
index b37fb1bcfb..0ab7aa0646 100644
--- a/src/calibre/test_build.py
+++ b/src/calibre/test_build.py
@@ -369,10 +369,6 @@ def test_file_dialog_helper(self):
         from calibre.gui2.win_file_dialogs import test
         test()

-    def test_unrar(self):
-        from calibre.utils.unrar import test_basic
-        test_basic()
-
     def test_7z(self):
         from calibre.utils.seven_zip import test_basic
         test_basic()
--
2.30.1


code:
Fix build failure on glibc 2.28 where 'renameat2' would end up being
declared twice: <https://github.com/systemd/casync/issues/166>.

From 625244ca47e8ee1375d2d0092271bfd13b0913ea Mon Sep 17 00:00:00 2001
From: Daniel Mack <daniel@zonque.org>
Date: Tue, 13 Nov 2018 17:52:48 +0100
Subject: [PATCH] meson.build: pass -D_GNU_SOURCE when checking for functions

As described in #166, -D_GNU_SOURCE needs to be passed to the meson function
availability checker. h/t to @tomeon for providing a link to the solution as
well.
---
 meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index f42ed16..c0f741e 100644
--- a/meson.build
+++ b/meson.build
@@ -78,6 +78,6 @@ foreach ident : [
         ['copy_file_range',   '''#include <sys/syscall.h>
                                  #include <unistd.h>'''],
 ]
-        have = cc.has_function(ident[0], prefix : ident[1])
+        have = cc.has_function(ident[0], args : '-D_GNU_SOURCE', prefix : ident[1])
         conf.set10('HAVE_' + ident[0].to_upper(), have)
 endforeach


code:
Fix CVE-2017-11110:

https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-11110
https://bugzilla.redhat.com/show_bug.cgi?id=1468471
https://security-tracker.debian.org/tracker/CVE-2017-11110

Patch copied from openSUSE:

https://build.opensuse.org/package/view_file/openSUSE:Maintenance:6985/catdoc.openSUSE_Leap_42.2_Update/CVE-2017-11110.patch?expand=1

From: Andreas Stieger <astieger@suse.com>
Date: Mon, 10 Jul 2017 15:37:58 +0000
References: CVE-2017-11110 http://bugzilla.suse.com/show_bug.cgi?id=1047877

All .doc I found had sectorSize 0x09 at offset 0x1e. Guarding it against <4.

---
 src/ole.c |    5 +++++
 1 file changed, 5 insertions(+)

Index: catdoc-0.95/src/ole.c
===================================================================
--- catdoc-0.95.orig/src/ole.c	2016-05-25 06:37:12.000000000 +0200
+++ catdoc-0.95/src/ole.c	2017-07-10 17:42:33.578308107 +0200
@@ -106,6 +106,11 @@ FILE* ole_init(FILE *f, void *buffer, si
 		return NULL;
 	}
  	sectorSize = 1<<getshort(oleBuf,0x1e);
+	/* CVE-2017-11110) */
+ 	if (sectorSize < 4) {
+		fprintf(stderr,"sectorSize < 4 not supported\n");
+		return NULL;
+	}
 	shortSectorSize=1<<getshort(oleBuf,0x20);

 /* Read BBD into memory */
@@ -147,7 +152,7 @@ FILE* ole_init(FILE *f, void *buffer, si
 		}

 		fseek(newfile, 512+mblock*sectorSize, SEEK_SET);
-		if(fread(tmpBuf+MSAT_ORIG_SIZE+(sectorSize-4)*i,
+		if(fread(tmpBuf+MSAT_ORIG_SIZE+(sectorSize-4)*i, /* >= 4 for CVE-2017-11110 */
 						 1, sectorSize, newfile) != sectorSize) {
 			fprintf(stderr, "Error read MSAT!\n");
 			ole_finish();


code:
diff -r -u cdparanoia-III-10.2.old/interface/Makefile.in cdparanoia-III-10.2.new/interface/Makefile.in
--- cdparanoia-III-10.2.old/interface/Makefile.in	2008-08-21 18:08:54.000000000 +0200
+++ cdparanoia-III-10.2.new/interface/Makefile.in	2013-08-07 18:48:32.000000000 +0200
@@ -7,7 +7,7 @@
 srcdir=@srcdir@

 @SET_MAKE@
-FLAGS=@SBPCD_H@ @UCDROM_H@ @TYPESIZES@ @CFLAGS@
+FLAGS=@SBPCD_H@ @UCDROM_H@ @TYPESIZES@ @CFLAGS@ -fPIC
 OPT=@OPT@ $(FLAGS)
 DEBUG=@DEBUG@ -DCDDA_TEST
 CC=@CC@
@@ -33,7 +33,7 @@

 slib:
 	$(MAKE) lessmessy
-	$(MAKE) libcdda_interface.so CFLAGS="$(OPT) -fpic"
+	$(MAKE) libcdda_interface.so CFLAGS="$(OPT)"
 	[ -e libcdda_interface.so.0 ] || ln -s libcdda_interface.so libcdda_interface.so.0

 test:
@@ -46,7 +46,7 @@
 	$(RANLIB) libcdda_interface.a

 libcdda_interface.so: 	$(OFILES)
-	$(CC) -fpic -shared -o libcdda_interface.so.0.$(VERSION) -Wl,-soname -Wl,libcdda_interface.so.0 $(OFILES) $(LIBS)
+	$(CC) -fPIC -shared -o libcdda_interface.so.0.$(VERSION) -Wl,-soname -Wl,libcdda_interface.so.0 $(OFILES) $(LIBS)
 	[ -e libcdda_interface.so.0 ] || ln -s libcdda_interface.so.0.$(VERSION) libcdda_interface.so.0
 	[ -e libcdda_interface.so ] || ln -s libcdda_interface.so.0.$(VERSION) libcdda_interface.so

diff -r -u cdparanoia-III-10.2.old/paranoia/Makefile.in cdparanoia-III-10.2.new/paranoia/Makefile.in
--- cdparanoia-III-10.2.old/paranoia/Makefile.in	2008-09-04 21:02:47.000000000 +0200
+++ cdparanoia-III-10.2.new/paranoia/Makefile.in	2013-08-07 18:49:54.000000000 +0200
@@ -9,7 +9,7 @@

 @SET_MAKE@
 FLAGS=@TYPESIZES@ @CFLAGS@
-OPT=@OPT@ $(FLAGS)
+OPT=@OPT@ $(FLAGS) -fPIC
 DEBUG=@DEBUG@
 CC=@CC@
 LD=@CC@
@@ -34,7 +34,7 @@

 slib:
 	$(MAKE) lessmessy
-	$(MAKE) libcdda_paranoia.so CFLAGS="$(OPT) -fpic"
+	$(MAKE) libcdda_paranoia.so CFLAGS="$(OPT)"

 #test:	$(TFILES)
 #
@@ -44,7 +44,7 @@
 	$(RANLIB) libcdda_paranoia.a

 libcdda_paranoia.so: 	$(OFILES)
-	$(CC) -fpic -shared -o libcdda_paranoia.so.0.$(VERSION) -Wl,-soname -Wl,libcdda_paranoia.so.0 $(OFILES) -L ../interface -lcdda_interface
+	$(CC) -fPIC -shared -o libcdda_paranoia.so.0.$(VERSION) -Wl,-soname -Wl,libcdda_paranoia.so.0 $(OFILES) -L ../interface -lcdda_interface
 	[ -e libcdda_paranoia.so.0 ] || ln -s libcdda_paranoia.so.0.$(VERSION) libcdda_paranoia.so.0
 	[ -e libcdda_paranoia.so ] || ln -s libcdda_paranoia.so.0.$(VERSION) libcdda_paranoia.so


code:
Patch for version 3.01, taken from upstream at
https://sourceforge.net/projects/cdrtools/files/cdrtools-3.01-fix-20151126-mkisofs-isoinfo.patch

--- cdrtools-3.01.orig/mkisofs/diag/isoinfo.c	2015-07-22 20:36:45.000000000 +0000
+++ cdrtools-3.01/mkisofs/diag/isoinfo.c	2015-11-17 19:35:40.000000000 +0000
@@ -1,8 +1,8 @@
-/* @(#)isoinfo.c	1.95 15/07/22 joerg */
+/* @(#)isoinfo.c	1.100 15/11/17 joerg */
 #include <schily/mconfig.h>
 #ifndef	lint
 static	UConst char sccsid[] =
-	"@(#)isoinfo.c	1.95 15/07/22 joerg";
+	"@(#)isoinfo.c	1.100 15/11/17 joerg";
 #endif
 /*
  * File isodump.c - dump iso9660 directory information.
@@ -148,8 +148,10 @@ LOCAL char	er_id[256];
 LOCAL int	su_version = 0;
 LOCAL int	rr_version = 0;
 LOCAL int	aa_version = 0;
+LOCAL int	cl_extent = 0;
 LOCAL int	ucs_level = 0;
 LOCAL BOOL	iso9660_inodes = FALSE;
+LOCAL uid_t	myuid;

 #ifdef	USE_FIND
 LOCAL findn_t	*find_node;		/* syntaxtree from find_parse()	*/
@@ -208,6 +210,9 @@ LOCAL	void	extract		__PR((char *rootname
 LOCAL	void	extract_file	__PR((int f,
 					struct iso_directory_record * idr,
 					char *fname));
+LOCAL	void	parse_cl_dir	__PR((struct iso_directory_record *idr,
+					int extent));
+LOCAL	BOOL	parse_de	__PR((struct iso_directory_record *idr));
 LOCAL	void	parse_dir	__PR((char * rootname, int extent, int len));
 LOCAL	void	usage		__PR((int excode));
 EXPORT	int	main		__PR((int argc, char *argv[]));
@@ -459,7 +464,6 @@ parse_rr(pnt, len, cont_flag)
 	int slen;
 	int xlen;
 	int ncount;
-	int cl_extent;
 	int pl_extent;
 	int cont_extent, cont_offset, cont_size;
 	int flag1, flag2;
@@ -469,7 +473,7 @@ parse_rr(pnt, len, cont_flag)

 	symlinkname[0] = 0;

-	cont_extent = cont_offset = cont_size = 0;
+	cl_extent = cont_extent = cont_offset = cont_size = 0;

 	ncount = 0;
 	flag1 = -1;
@@ -714,6 +718,7 @@ struct todo
 };

 LOCAL struct todo	*todo_idr = NULL;
+LOCAL struct todo	**todo_pp = &todo_idr;

 LOCAL char		*months[12] = {"Jan", "Feb", "Mar", "Apr",
 				"May", "Jun", "Jul",
@@ -962,8 +967,14 @@ static	BOOL		isfirst = TRUE;
 	close(f);
 	return;
 setmode:
-	fchmodat(AT_FDCWD, fname, fstat_buf.st_mode, AT_SYMLINK_NOFOLLOW);
 	fchownat(AT_FDCWD, fname, fstat_buf.st_uid, fstat_buf.st_gid, AT_SYMLINK_NOFOLLOW);
+	if (myuid != 0 && S_ISDIR(fstat_buf.st_mode)) {
+		/*
+		 * Temporary hack until we have a dirstack like star.
+		 */
+		fstat_buf.st_mode |= S_IWUSR;
+	}
+	fchmodat(AT_FDCWD, fname, fstat_buf.st_mode, AT_SYMLINK_NOFOLLOW);
 	times[0].tv_sec = fstat_buf.st_atime;
 	times[0].tv_nsec = stat_ansecs(&fstat_buf);
 	times[1].tv_sec = fstat_buf.st_mtime;
@@ -1001,6 +1012,143 @@ extract_file(f, idr, fname)
 	}
 }

+
+LOCAL void
+parse_cl_dir(idr, extent)
+	struct iso_directory_record	*idr;
+	int				extent;
+{
+	char				cl_name_buf[256*3];
+
+	strlcpy(cl_name_buf, name_buf, sizeof (cl_name_buf));
+#ifdef	USE_SCG
+	readsecs(extent - sector_offset, idr, 1);
+#else
+	lseek(fileno(infile), ((off_t)(extent - sector_offset)) << 11, SEEK_SET);
+	read(fileno(infile), idr, 2048);
+#endif
+
+	if (parse_de(idr) && use_rock)
+		dump_rr(idr);
+	strlcpy(name_buf, cl_name_buf, sizeof (name_buf));
+}
+
+LOCAL BOOL
+parse_de(idr)
+	struct iso_directory_record	*idr;
+{
+	unsigned char	uc;
+
+	if (idr->length[0] == 0)
+		return (FALSE);
+	memset(&fstat_buf, 0, sizeof (fstat_buf));
+	found_rr = 0;
+	name_buf[0] = xname[0] = 0;
+	fstat_buf.st_size = (off_t)(unsigned)isonum_733((unsigned char *)idr->size);
+	if (idr->flags[0] & 2)
+		fstat_buf.st_mode |= S_IFDIR;
+	else
+		fstat_buf.st_mode |= S_IFREG;
+	if (idr->name_len[0] == 1 && idr->name[0] == 0)
+		strcpy(name_buf, ".");
+	else if (idr->name_len[0] == 1 && idr->name[0] == 1)
+		strcpy(name_buf, "..");
+	else {
+		switch (ucs_level) {
+		case 3:
+		case 2:
+		case 1:
+			/*
+			 * Unicode name.  Convert as best we can.
+			 */
+			{
+			int	j;
+				name_buf[0] = '\0';
+#ifdef	USE_ICONV
+			if (use_iconv(unls)) {
+				int	u;
+				char	*to = name_buf;
+
+				for (j = 0, u = 0; j < (int)idr->name_len[0] / 2; j++) {
+					char	*ibuf = (char *)&idr->name[j*2];
+					size_t	isize = 2;		/* UCS-2 character size */
+					size_t	osize = 4;
+
+					if (iconv(unls->sic_uni2cd, (__IC_CONST char **)&ibuf, &isize,
+							(char **)&to, &osize) == -1) {
+						int	err = geterrno();
+
+						if ((err == EINVAL || err == EILSEQ) &&
+						    osize == 4) {
+							*to = '_';
+							u += 1;
+							to++;
+						}
+					} else {
+						u += 4 - osize;
+						to = &name_buf[u];
+					}
+				}
+				j = u;
+			} else
+#endif
+			for (j = 0; j < (int)idr->name_len[0] / 2; j++) {
+				UInt16_t	unichar;
+
+				unichar = (idr->name[j*2] & 0xFF) * 256 +
+					    (idr->name[j*2+1] & 0xFF);
+
+				/*
+				 * Get the backconverted char
+				 */
+				if (unls)
+					uc = sic_uni2c(unls, unichar);
+				else
+					uc = unichar > 255 ? '_' : unichar;
+
+				name_buf[j] = uc ? uc : '_';
+			}
+			name_buf[j] = '\0';
+			}
+			break;
+		case 0:
+			/*
+			 * Normal non-Unicode name.
+			 */
+			strncpy(name_buf, idr->name, idr->name_len[0]);
+			name_buf[idr->name_len[0]] = 0;
+			break;
+		default:
+			/*
+			 * Don't know how to do these yet.  Maybe they are the same
+			 * as one of the above.
+			 */
+			exit(1);
+		}
+	}
+	memcpy(date_buf, idr->date, 9);
+	/*
+	 * Always first set up time stamps and file modes from
+	 * ISO-9660. This is used as a fallback in case that
+	 * there is no related Rock Ridge based data.
+	 */
+	fstat_buf.st_atime =
+	fstat_buf.st_mtime =
+	fstat_buf.st_ctime = iso9660_time(date_buf, NULL, FALSE);
+	fstat_buf.st_mode |= S_IRUSR|S_IXUSR |
+		    S_IRGRP|S_IXGRP |
+		    S_IROTH|S_IXOTH;
+	fstat_buf.st_nlink = 1;
+	fstat_buf.st_ino = 0;
+	fstat_buf.st_uid = 0;
+	fstat_buf.st_gid = 0;
+	if (iso9660_inodes) {
+		fstat_buf.st_ino = (unsigned long)
+		    isonum_733((unsigned char *)idr->extent);
+	}
+	return (TRUE);
+}
+
 LOCAL void
 parse_dir(rootname, extent, len)
 	char	*rootname;
@@ -1012,12 +1160,13 @@ parse_dir(rootname, extent, len)
 	struct iso_directory_record * idr;
 	struct iso_directory_record	didr;
 	struct stat			dstat;
-	unsigned char	uc;
+	unsigned char	cl_buffer[2048];
 	unsigned char	flags = 0;
 	Llong		size = 0;
 	int		sextent = 0;
 	int	rlen;
 	int	blen;
+	int	rr_flags = 0;
 static	char	*n = 0;
 static	int	nlen = 0;

@@ -1039,115 +1188,23 @@ static	int	nlen = 0;
 		i = 0;
 		while (1 == 1) {
 			idr = (struct iso_directory_record *) &buffer[i];
-			if (idr->length[0] == 0) break;
-			memset(&fstat_buf, 0, sizeof (fstat_buf));
-			found_rr = 0;
-			name_buf[0] = xname[0] = 0;
-			fstat_buf.st_size = (off_t)(unsigned)isonum_733((unsigned char *)idr->size);
-			if (idr->flags[0] & 2)
-				fstat_buf.st_mode |= S_IFDIR;
-			else
-				fstat_buf.st_mode |= S_IFREG;
-			if (idr->name_len[0] == 1 && idr->name[0] == 0)
-				strcpy(name_buf, ".");
-			else if (idr->name_len[0] == 1 && idr->name[0] == 1)
-				strcpy(name_buf, "..");
-			else {
-				switch (ucs_level) {
-				case 3:
-				case 2:
-				case 1:
-					/*
-					 * Unicode name.  Convert as best we can.
-					 */
-					{
-					int	j;
-
-					name_buf[0] = '\0';
-#ifdef	USE_ICONV
-					if (use_iconv(unls)) {
-						int	u;
-						char	*to = name_buf;
-
-						for (j = 0, u = 0; j < (int)idr->name_len[0] / 2; j++) {
-							char	*ibuf = (char *)&idr->name[j*2];
-							size_t	isize = 2;		/* UCS-2 character size */
-							size_t	osize = 4;
-
-							if (iconv(unls->sic_uni2cd, (__IC_CONST char **)&ibuf, &isize,
-									(char **)&to, &osize) == -1) {
-								int	err = geterrno();
-
-								if ((err == EINVAL || err == EILSEQ) &&
-								    osize == 4) {
-									*to = '_';
-									u += 1;
-									to++;
-								}
-							} else {
-								u += 4 - osize;
-								to = &name_buf[u];
-							}
-						}
-						j = u;
-					} else
-#endif
-					for (j = 0; j < (int)idr->name_len[0] / 2; j++) {
-						UInt16_t	unichar;
-
-						unichar = (idr->name[j*2] & 0xFF) * 256 +
-							    (idr->name[j*2+1] & 0xFF);
-
-						/*
-						 * Get the backconverted char
-						 */
-						if (unls)
-							uc = sic_uni2c(unls, unichar);
-						else
-							uc = unichar > 255 ? '_' : unichar;
+			if (idr->length[0] == 0)
+				break;
+			parse_de(idr);
+			if (use_rock) {
+				rr_flags = dump_rr(idr);

-						name_buf[j] = uc ? uc : '_';
-					}
-					name_buf[j] = '\0';
-					}
-					break;
-				case 0:
+				if (rr_flags & RR_FLAG_CL) {
 					/*
-					 * Normal non-Unicode name.
+					 * Need to reparse the child link
+					 * but note that we parse "CL/."
+					 * so we get no usable file name.
 					 */
-					strncpy(name_buf, idr->name, idr->name_len[0]);
-					name_buf[idr->name_len[0]] = 0;
-					break;
-				default:
-					/*
-					 * Don't know how to do these yet.  Maybe they are the same
-					 * as one of the above.
-					 */
-					exit(1);
-				}
+					idr = (struct iso_directory_record *) cl_buffer;
+					parse_cl_dir(idr, cl_extent);
+				} else if (rr_flags & RR_FLAG_RE)
+					goto cont;	/* skip rr_moved */
 			}
-			memcpy(date_buf, idr->date, 9);
-			/*
-			 * Always first set up time stamps and file modes from
-			 * ISO-9660. This is used as a fallback in case that
-			 * there is no related Rock Ridge based data.
-			 */
-			fstat_buf.st_atime =
-			fstat_buf.st_mtime =
-			fstat_buf.st_ctime = iso9660_time(date_buf, NULL, FALSE);
-			fstat_buf.st_mode |= S_IRUSR|S_IXUSR |
-				    S_IRGRP|S_IXGRP |
-				    S_IROTH|S_IXOTH;
-			fstat_buf.st_nlink = 1;
-			fstat_buf.st_ino = 0;
-			fstat_buf.st_uid = 0;
-			fstat_buf.st_gid = 0;
-			if (iso9660_inodes) {
-				fstat_buf.st_ino = (unsigned long)
-				    isonum_733((unsigned char *)idr->extent);
-			}
-			if (use_rock)
-				dump_rr(idr);
 			if (Xtract &&
 			    (idr->flags[0] & 2) != 0 &&
 			    idr->name_len[0] == 1 &&
@@ -1170,30 +1227,30 @@ static	int	nlen = 0;
 				n[rlen] = '\0';

 			if ((idr->flags[0] & 2) != 0 &&
-			    (idr->name_len[0] != 1 ||
+			    ((rr_flags & RR_FLAG_CL) ||
+			    idr->name_len[0] != 1 ||
 			    (idr->name[0] != 0 && idr->name[0] != 1))) {
 				/*
 				 * This is a plain directory (neither "xxx/."
 				 * nor "xxx/..").
 				 * Add this directory to the todo list.
 				 */
-				td = todo_idr;
-				if (td != NULL) {
-					while (td->next != NULL)
-						td = td->next;
-					td->next = (struct todo *) malloc(sizeof (*td));
-					td = td->next;
-				} else {
-					todo_idr = td = (struct todo *) malloc(sizeof (*td));
-				}
+				td = (struct todo *) malloc(sizeof (*td));
+				if (td == NULL)
+					comerr(_("No memory.\n"));
 				td->next = NULL;
 				td->extent = isonum_733((unsigned char *)idr->extent);
 				td->length = isonum_733((unsigned char *)idr->size);
 				td->name = (char *) malloc(strlen(rootname)
 								+ strlen(name_buf) + 2);
+				if (td->name == NULL)
+					comerr(_("No memory.\n"));
 				strcpy(td->name, rootname);
 				strcat(td->name, name_buf);
 				strcat(td->name, "/");
+
+				*todo_pp = td;
+				todo_pp = &td->next;
 			} else {
 				if (xtract && strcmp(xtract, n) == 0) {
 					extract_file(STDOUT_FILENO, idr, "stdout");
@@ -1253,6 +1310,7 @@ static	int	nlen = 0;
 				if ((idr->flags[0] & ISO_MULTIEXTENT) == 0)
 					size = 0;
 			}
+		cont:
 			i += buffer[i];
 			if (i > 2048 - offsetof(struct iso_directory_record, name[0])) break;
 		}
@@ -1381,12 +1439,13 @@ main(argc, argv)
 		usage(0);
 	if (prvers) {
 		printf(_("isoinfo %s (%s-%s-%s) Copyright (C) 1993-1999 %s (C) 1999-2015 %s\n"),
-					VERSION,
+					"3.02a02",
 					HOST_CPU, HOST_VENDOR, HOST_OS,
 					_("Eric Youngdale"),
 					_("Joerg Schilling"));
 		exit(0);
 	}
+	myuid = getuid();
 #ifdef	USE_FIND
 	if (do_find) {
 		finda_t	fa;
--- cdrtools-3.01.orig/mkisofs/udf.c	2013-04-24 20:45:18.000000000 +0000
+++ cdrtools-3.01/mkisofs/udf.c	2015-11-25 22:07:30.000000000 +0000
@@ -1,15 +1,15 @@
-/* @(#)udf.c	1.42 13/04/24 Copyright 2001-2013 J. Schilling */
+/* @(#)udf.c	1.43 15/11/25 Copyright 2001-2015 J. Schilling */
 #include <schily/mconfig.h>
 #ifndef lint
 static	UConst char sccsid[] =
-	"@(#)udf.c	1.42 13/04/24 Copyright 2001-2013 J. Schilling";
+	"@(#)udf.c	1.43 15/11/25 Copyright 2001-2015 J. Schilling";
 #endif
 /*
  * udf.c - UDF support for mkisofs
  *
  * Written by Ben Rudiak-Gould (2001).
  *
- * Copyright 2001-2013 J. Schilling.
+ * Copyright 2001-2015 J. Schilling.
  */
 /*
  * This program is free software; you can redistribute it and/or modify
@@ -98,7 +98,7 @@ static	UConst char sccsid[] =
 extern	int	use_sparcboot;

 extern struct directory *root;
-extern time_t		begun;
+extern struct timeval	tv_begun;

 static unsigned lba_main_seq;
 static unsigned lba_main_seq_copy;
@@ -110,7 +110,7 @@ static unsigned lba_end_anchor_vol_desc;
 static unsigned num_udf_files;
 static unsigned num_udf_directories;

-static unsigned volume_set_id[2];
+static unsigned volume_set_id[2] = { 0, 0 };

 #define	UDF_MAIN_SEQ_LENGTH (16)
 #define	UDF_INTEG_SEQ_LENGTH (2)
@@ -723,7 +723,7 @@ set_primary_vol_desc(buf, lba)
 	/*pvd->volume_abstract;*/
 	/*pvd->volume_copyright_notice;*/
 	/*pvd->application_ident;*/
-	set_timestamp_from_time_t(&pvd->recording_date_and_time, begun);
+	set_timestamp_from_time_t(&pvd->recording_date_and_time, tv_begun.tv_sec);
 	set_impl_ident(&pvd->impl_ident);
 	set_tag(&pvd->desc_tag, UDF_TAGID_PRIMARY_VOLUME_DESC, lba, 512);
 }
@@ -831,7 +831,7 @@ set_logical_vol_integrity_desc(buf, lba)
 	udf_logical_volume_integrity_desc *lvid =
 				(udf_logical_volume_integrity_desc *)buf;

-	set_timestamp_from_time_t(&lvid->recording_date, begun);
+	set_timestamp_from_time_t(&lvid->recording_date, tv_begun.tv_sec);
 	set32(&lvid->integrity_type, UDF_INTEGRITY_TYPE_CLOSE);
 	/*lvid->next_integrity_extent;*/
 	set64(&lvid->logical_volume_contents_use.unique_id,
@@ -859,7 +859,7 @@ set_file_set_desc(buf, rba)
 {
 	udf_file_set_desc *fsd = (udf_file_set_desc *)buf;

-	set_timestamp_from_time_t(&fsd->recording_date_and_time, begun);
+	set_timestamp_from_time_t(&fsd->recording_date_and_time, tv_begun.tv_sec);
 	set16(&fsd->interchange_level, 3);
 	set16(&fsd->maximum_interchange_level, 3);
 	set32(&fsd->character_set_list, 1);
@@ -1986,8 +1986,10 @@ udf_main_seq_write(out)
 	 * volume_set_id needs to be set to a (64-bit) "unique" number.
 	 * This will have to do for now.
 	 */
-	volume_set_id[0] = begun;
-	volume_set_id[1] = (unsigned)clock();	/* XXX Maybe non-portable */
+	if (volume_set_id[0] == 0) {
+		volume_set_id[0] = tv_begun.tv_sec;
+		volume_set_id[1] = (unsigned)tv_begun.tv_usec;
+	}

 	memset(buf, 0, sizeof (buf));
 	set_primary_vol_desc(buf, last_extent_written++);
--- cdrtools-3.01.orig/mkisofs/mkisofs.c	2015-01-01 14:19:51.000000000 +0000
+++ cdrtools-3.01/mkisofs/mkisofs.c
@@ -69 +69 @@ int		path_ind;
-char	version_string[] = VERSION;
+char	version_string[] = "3.01-fix-20151126";