Adds support for death tests in OpenBSD (by Paweł Hajdan Jr.)

--- include/gtest/internal/gtest-port.h
+++ include/gtest/internal/gtest-port.h
@@ -91,6 +91,7 @@
 //     GTEST_OS_LINUX_ANDROID - Google Android
 //   GTEST_OS_MAC      - Mac OS X
 //   GTEST_OS_NACL     - Google Native Client (NaCl)
+//   GTEST_OS_OPENBSD  - OpenBSD
 //   GTEST_OS_SOLARIS  - Sun Solaris
 //   GTEST_OS_SYMBIAN  - Symbian
 //   GTEST_OS_WINDOWS  - Windows (Desktop, MinGW, or Mobile)
@@ -242,6 +243,8 @@
 # define GTEST_OS_HPUX 1
 #elif defined __native_client__
 # define GTEST_OS_NACL 1
+#elif defined __OpenBSD__
+# define GTEST_OS_OPENBSD 1
 #endif  // __CYGWIN__

 // Brings in definitions for functions used in the testing::internal::posix
@@ -540,7 +543,8 @@
 // pops up a dialog window that cannot be suppressed programmatically.
 #if (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
      (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
-     GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX)
+     GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \
+     GTEST_OS_OPENBSD)
 # define GTEST_HAS_DEATH_TEST 1
 # include <vector>  // NOLINT
 #endif


Better check for 'is home'.

Better check for 'is home'.

git-svn-id: 6ac5796aeae0cef97fb47bcc287d4ce899c6fa6e@43843 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

--- src/modules/illume2/e_mod_layout.c
+++ src/modules/illume2/e_mod_layout.c
@@ -219,9 +219,10 @@
 Eina_Bool
 illume_border_is_home(E_Border *bd)
 {
-   if ((bd->client.icccm.name) &&
-       (strstr(bd->client.icccm.name, "Illume-Home")) ||
-       (strstr(bd->client.icccm.title, "Home")))
+   if (((bd->client.icccm.name) &&
+        (strstr(bd->client.icccm.name, "Illume-Home"))) ||
+       ((bd->client.icccm.title) &&
+        (strstr(bd->client.icccm.title, "Home"))))
      return 1;
    return 0;
 }


verify that GV is valid to avoid segfaults
PR:
Obtained from:
Submitted by:
Reviewed by:

git-svn-id: b4be4a41b2a3352907de631eb6da1671a2f7b614@70666 13f79535-47bb-0310-9956-ffa450edef68

--- src/modules/perl/modperl_handler.c
+++ src/modules/perl/modperl_handler.c
@@ -456,7 +456,9 @@
         if (CvANON((CV*)sv)) {
             return modperl_handler_new_anon(aTHX_ p, (CV*)sv);
         }
-        gv = CvGV((CV*)sv);
+        if (!(gv = CvGV((CV*)sv))) {
+            Perl_croak(aTHX_ "can't resolve the code reference");
+        }
         name = apr_pstrcat(p, HvNAME(GvSTASH(gv)), "::", GvNAME(gv), NULL);
         return modperl_handler_new(p, apr_pstrdup(p, name));
         break;


Add move constructor and move assignment to fix MSVC build.

git-svn-id: 0ff597fd157e6f4fc38580e8d64ab130330d2411@274186 91177308-0d34-0410-b5e6-96231b3b80d8

--- include/llvm/Object/ArchiveWriter.h
+++ include/llvm/Object/ArchiveWriter.h
@@ -26,6 +26,17 @@
   unsigned UID = 0, GID = 0, Perms = 0644;

   NewArchiveMember() = default;
+  NewArchiveMember(NewArchiveMember &&Other)
+      : Buf(std::move(Other.Buf)), ModTime(Other.ModTime), UID(Other.UID),
+        GID(Other.GID), Perms(Other.Perms) {}
+  NewArchiveMember &operator=(NewArchiveMember &&Other) {
+    Buf = std::move(Other.Buf);
+    ModTime = Other.ModTime;
+    UID = Other.UID;
+    GID = Other.GID;
+    Perms = Other.Perms;
+    return *this;
+  }
   NewArchiveMember(MemoryBufferRef BufRef);

   static Expected<NewArchiveMember>


add an m_ConstantInt matching predicate that binds to a uint64_t, and add an m_OneUse()
predicate that matches if the subexpr has a single use.

git-svn-id: 0ff597fd157e6f4fc38580e8d64ab130330d2411@130235 91177308-0d34-0410-b5e6-96231b3b80d8

--- include/llvm/Support/PatternMatch.h
+++ include/llvm/Support/PatternMatch.h
@@ -40,6 +40,23 @@
   return const_cast<Pattern&>(P).match(V);
 }

+
+template<typename SubPattern_t>
+struct OneUse_match {
+  SubPattern_t SubPattern;
+
+  OneUse_match(const SubPattern_t &SP) : SubPattern(SP) {}
+
+  template<typename OpTy>
+  bool match(OpTy *V) {
+    return V->hasOneUse() && SubPattern.match(V);
+  }
+};
+
+template<typename T>
+inline OneUse_match<T> m_OneUse(const T &SubPattern) { return SubPattern; }
+
+
 template<typename Class>
 struct class_match {
   template<typename ITy>
@@ -227,7 +244,25 @@
 /// m_Specific - Match if we have a specific specified value.
 inline specificval_ty m_Specific(const Value *V) { return V; }

-
+struct bind_const_intval_ty {
+  uint64_t &VR;
+  bind_const_intval_ty(uint64_t &V) : VR(V) {}
+
+  template<typename ITy>
+  bool match(ITy *V) {
+    if (ConstantInt *CV = dyn_cast<ConstantInt>(V))
+      if (CV->getBitWidth() <= 64) {
+        VR = CV->getZExtValue();
+        return true;
+      }
+    return false;
+  }
+};
+
+/// m_ConstantInt - Match a ConstantInt and bind to its value.  This does not
+/// match ConstantInts wider than 64-bits.
+inline bind_const_intval_ty m_ConstantInt(uint64_t &V) { return V; }
+
 //===----------------------------------------------------------------------===//
 // Matchers for specific binary operators.
 //


Added prototypes for emitting prologue and epilogue for function code
generation.

git-svn-id: 0ff597fd157e6f4fc38580e8d64ab130330d2411@4927 91177308-0d34-0410-b5e6-96231b3b80d8

--- include/llvm/Target/MRegisterInfo.h
+++ include/llvm/Target/MRegisterInfo.h
@@ -129,6 +129,16 @@
                     unsigned DestReg, unsigned SrcReg,
                     unsigned ImmOffset, unsigned dataSize) const = 0;

+  virtual MachineBasicBlock::iterator
+  emitPrologue(MachineBasicBlock *MBB,
+               MachineBasicBlock::iterator MBBI,
+               unsigned numBytes) const = 0;
+
+  virtual MachineBasicBlock::iterator
+  emitEpilogue(MachineBasicBlock *MBB,
+               MachineBasicBlock::iterator MBBI,
+               unsigned numBytes) const = 0;
+
   virtual const unsigned* getCalleeSaveRegs() const = 0;
   virtual const unsigned* getCallerSaveRegs() const = 0;


Don't call the signal handler registered by the JVM.

We're changing the symantics of the signal, so it doesn't make sense to fall back on the JVM's symantics.  What is worse, is that the old code prevented a clean shutdown.

Fix for Bug # 27729

Reported By: Krzysztof Cieniuch kcieniuch@wp.pl

git-svn-id: d2ff9ed2f92be9d06337bb70c57551c02d1e392c@140761 13f79535-47bb-0310-9956-ffa450edef68

--- src/native/unix/native/jsvc-unix.c
+++ src/native/unix/native/jsvc-unix.c
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: jsvc-unix.c,v 1.9 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: jsvc-unix.c,v 1.10 2004/03/18 03:59:41 billbarker Exp $ */
 #include "jsvc.h"

 #include <signal.h>
@@ -46,7 +46,6 @@
             } else {
                 stopping=true;
             }
-            if (handler_trm!=NULL) (*handler_trm)(sig);
             break;
         }

@@ -57,7 +56,6 @@
             } else {
                 stopping=true;
             }
-            if (handler_int!=NULL) (*handler_int)(sig);
             break;
         }

@@ -69,7 +67,6 @@
                 stopping=true;
                 doreload=true;
             }
-            if (handler_hup!=NULL) (*handler_hup)(sig);
             break;
         }


added some const

added some const

--- include/mlk/filesystem/filesystem.h
+++ include/mlk/filesystem/filesystem.h
@@ -37,8 +37,8 @@
 			fs_handle(const std::string &path) :
 				m_path(path) {}

-			bool exists() {return dir::exists(m_path);}
-			bool create() {return dir::create(m_path);}
+			bool exists() const {return dir::exists(m_path);}
+			bool create() const {return dir::create(m_path);}
 		};

 		template<> class fs_handle<fs_type::file>


Fix for unused variable warning

Fix for unused variable warning

--- include/parallel/parallel_algebra.h
+++ include/parallel/parallel_algebra.h
@@ -325,7 +325,7 @@
 {
 public:
 #ifdef LIBMESH_HAVE_MPI
-  static void vector_max (void *invec, void *inoutvec, int *len, MPI_Datatype *datatype)
+  static void vector_max (void *invec, void *inoutvec, int *len, MPI_Datatype *)
   {
     V *in = static_cast<V *>(invec);
     V *inout = static_cast<V *>(inoutvec);
@@ -334,7 +334,7 @@
         inout[i](d) = std::max(in[i](d), inout[i](d));
   }

-  static void vector_min (void *invec, void *inoutvec, int *len, MPI_Datatype *datatype)
+  static void vector_min (void *invec, void *inoutvec, int *len, MPI_Datatype *)
   {
     V *in = static_cast<V *>(invec);
     V *inout = static_cast<V *>(inoutvec);
@@ -343,7 +343,7 @@
         inout[i](d) = std::min(in[i](d), inout[i](d));
   }

-  static void vector_sum (void *invec, void *inoutvec, int *len, MPI_Datatype *datatype)
+  static void vector_sum (void *invec, void *inoutvec, int *len, MPI_Datatype *)
   {
     V *in = static_cast<V *>(invec);
     V *inout = static_cast<V *>(inoutvec);


Allow accessing of non-const samples via reference.

--- include/sampleflow/element_access.h
+++ include/sampleflow/element_access.h
@@ -184,6 +184,24 @@
     }

+
+    /**
+     * Like the previous function, but for non-`const` objects for which the
+     * returned object is a reference to the elements of the `sample` object.
+     */
+    template <typename SampleType>
+    auto get_nth_element (SampleType       &sample,
+                          const std::size_t index)
+    -> typename std::enable_if<internal::has_subscript_operator<SampleType>::value == true,
+    typename std::remove_cv<
+    typename std::remove_reference<
+    decltype(std::declval<SampleType>()[index])>::type>::type>::type &
+    {
+      assert (index < size(sample));
+      return sample[index];
+    }
+
+
     /**
      * A function that, for types `SampleType` for which one can not build
      * expressions of the form `sample[i]`, simply returns the object itself.
@@ -203,6 +221,22 @@
       assert (index == 0);
       return sample;
     }
+
+
+    /**
+     * Like the previous function, but for non-`const` objects for which the
+     * returned object is a reference to the (single) element
+     * of the `sample` object.
+     */
+    template <typename SampleType>
+    auto get_nth_element (SampleType       &sample,
+                          const std::size_t index)
+    -> typename std::enable_if<internal::has_subscript_operator<SampleType>::value == false,
+    SampleType>::type &
+    {
+      assert (index == 0);
+      return sample;
+    }
   }
 }


Remove unused member from backtracer

Remove unused member from backtracer

--- include/spdlog/details/backtracer.h
+++ include/spdlog/details/backtracer.h
@@ -16,26 +16,16 @@
 namespace details {
 class backtracer
 {
-    std::mutex mutex_;
-    size_t n_messages_;
+    std::mutex mutex_;
     circular_q<log_msg_buffer> messages_;

 public:
-    explicit backtracer(size_t n_messages)
-        : n_messages_{n_messages}
-        , messages_{n_messages}
+    explicit backtracer(size_t n_messages) : messages_{n_messages}
     {}

-    backtracer(const backtracer &other)
-        : n_messages_{other.n_messages_}
-        , messages_{other.messages_}
+    backtracer(const backtracer &other) : messages_{other.messages_}
     {}
-
-    size_t n_messages() const
-    {
-        return n_messages_;
-    }
-
+
     void add(const log_msg &msg)
     {
         std::lock_guard<std::mutex> lock{mutex_};


Add missing recordingContext override to SkPaintFilterCanvas

This should fix the gpu-specific slides in Viewer.

Change-Id: I3ff069005bfe3639eb9608223b13c64f4c28c396
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/301441
Reviewed-by: John Stiles <f4fcf42d3bb5924557f1eeb3be66747535e585da@google.com>
Reviewed-by: Brian Salomon <61fabaaf0876044aeedfd8e351e485c028d69e7b@google.com>
Commit-Queue: Robert Phillips <95e8ac5504948c7bf91b22c16a8dbb7ae7c66bfd@google.com>

--- include/utils/SkPaintFilterCanvas.h
+++ include/utils/SkPaintFilterCanvas.h
@@ -32,6 +32,7 @@
     // Forwarded to the wrapped canvas.
     SkISize getBaseLayerSize() const override { return proxy()->getBaseLayerSize(); }
     GrContext*  getGrContext() override { return proxy()->getGrContext();     }
+    GrRecordingContext* recordingContext() override { return proxy()->recordingContext(); }
     GrRenderTargetContext* internal_private_accessTopLayerRenderTargetContext() override {
         return proxy()->internal_private_accessTopLayerRenderTargetContext();
     }


nodedev: Separate mdevctl monitor setup into a function

Signed-off-by: Michal Privoznik <83d82aaba2eed257f4814b0c239c260c4caaadf0@redhat.com>
Reviewed-by: Pavel Hrdina <d4772d05997b8abf035041e3b4f4996380ea7e7a@redhat.com>

--- src/node_device/node_device_udev.c
+++ src/node_device/node_device_udev.c
@@ -2119,6 +2119,29 @@
 }

+static int
+mdevctlEnableMonitor(udevEventData *priv)
+{
+    g_autoptr(GFile) mdevctlConfigDir = g_file_new_for_path("/etc/mdevctl.d");
+
+    /* mdevctl may add notification events in the future:
+     * https://github.com/mdevctl/mdevctl/issues/27. For now, fall back to
+     * monitoring the mdevctl configuration directory for changes.
+     * mdevctl configuration is stored in a directory tree within
+     * /etc/mdevctl.d/. There is a directory for each parent device, which
+     * contains a file defining each mediated device */
+    virMutexLock(&priv->mdevctlLock);
+    if (!(priv->mdevctlMonitors = monitorFileRecursively(priv,
+                                                         mdevctlConfigDir))) {
+        virMutexUnlock(&priv->mdevctlLock);
+        return -1;
+    }
+    virMutexUnlock(&priv->mdevctlLock);
+
+    return 0;
+}
+
+
 static void
 mdevctlEventHandleCallback(GFileMonitor *monitor G_GNUC_UNUSED,
                            GFile *file,
@@ -2168,7 +2191,6 @@
 {
     udevEventDataPtr priv = NULL;
     struct udev *udev = NULL;
-    g_autoptr(GFile) mdevctlConfigDir = g_file_new_for_path("/etc/mdevctl.d");

     if (root != NULL) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
@@ -2272,19 +2294,8 @@
     if (priv->watch == -1)
         goto unlock;

-    /* mdevctl may add notification events in the future:
-     * https://github.com/mdevctl/mdevctl/issues/27. For now, fall back to
-     * monitoring the mdevctl configuration directory for changes.
-     * mdevctl configuration is stored in a directory tree within
-     * /etc/mdevctl.d/. There is a directory for each parent device, which
-     * contains a file defining each mediated device */
-    virMutexLock(&priv->mdevctlLock);
-    if (!(priv->mdevctlMonitors = monitorFileRecursively(priv,
-                                                         mdevctlConfigDir))) {
-        virMutexUnlock(&priv->mdevctlLock);
+    if (mdevctlEnableMonitor(priv) < 0)
         goto unlock;
-    }
-    virMutexUnlock(&priv->mdevctlLock);

     virObjectUnlock(priv);


Added operator-(Vector)

Added operator-(Vector)

--- include/uvector/vector_operations.h
+++ include/uvector/vector_operations.h
@@ -137,6 +137,7 @@

 	template <size_t N, int K> inline auto operator!(const Vector<bool, N, K>& a) { Vector<bool, N> r; for (size_t i = 0; i < N; ++i) r[i] = !a[i]; return r; }

+	TEMPLATE_VECTOR_A inline auto operator-(const VECTOR_A& a) { VECTOR_A r; for (size_t i = 0; i < NA; ++i) r[i] = -a[i]; return r; }

 	TEMPLATE_VECTORS_AB	inline auto operator==(const VECTOR_A& a, const VECTOR_B& b) { return details::apply<op::eq>(a, b); }
 	TEMPLATE_VECTORS_AB	inline auto operator!=(const VECTOR_A& a, const VECTOR_B& b) { return details::apply<op::ne>(a, b); }


Fixed algorithm bugs

Fixed algorithm bugs

--- src/noname_tools/algorithm_tools.h
+++ src/noname_tools/algorithm_tools.h
@@ -15,15 +15,16 @@
 		{
 			// Inspired from: https://codereview.stackexchange.com/questions/106773/dividing-a-range-into-n-sub-ranges

-			static_assert(std::is_same<InputIt, typename std::iterator_traits<OutputIt>::value_type>::value,
+			static_assert(std::is_same<InputIt, typename OutputIt::container_type::value_type>::value,
 				"Error: The output iterator value type has to be the same as the input iterator type!");

 			if (n == 0) return;
+			if (first == last) return;

 			const auto dist = std::distance(first, last);
 			n = std::min<size_t>(n, dist);
 			const auto chunk = dist / n;
-			const auto remainder = dist % n;
+			auto remainder = dist % n;

 			*dest++ = first;

@@ -41,10 +42,12 @@
 		template <typename InputIt, typename Func>
 		Func for_each_and_successor(InputIt first, InputIt last, Func f)
 		{
-			auto next = std::next(first);
-			for(; next != last; ++next) {
-				f(*first, *next);
-				first = next;
+			if(first != last) {
+				auto next = std::next(first);
+				for (; next != last; ++next) {
+					f(*first, *next);
+					first = next;
+				}
 			}

 			return std::move(f);


fix(compression): error out if we have too many samples

--- includes/acl/compression/compress.h
+++ includes/acl/compression/compress.h
@@ -464,6 +464,9 @@
 		if (error_result.any())
 			return error_result;

+		if (track_list.get_num_samples_per_track() > 0xFFFF)
+			return ErrorResult("ACL only supports up to 65535 samples");
+
 		// Disable floating point exceptions during compression because we leverage all SIMD lanes
 		// and we might intentionally divide by zero, etc.
 		scope_disable_fp_exceptions fp_off;
@@ -505,6 +508,9 @@
 		if (error_result.any())
 			return error_result;

+		if (track_list.get_num_samples_per_track() > 0xFFFF)
+			return ErrorResult("ACL only supports up to 65535 samples");
+
 		// Disable floating point exceptions during compression because we leverage all SIMD lanes
 		// and we might intentionally divide by zero, etc.
 		scope_disable_fp_exceptions fp_off;


Remove useless if-test.

Remove useless if-test.

Coverity complained that this check is pointless, and it's right.
There is no case where we'd call ExecutorStart with a null plannedstmt,
and if we did, it'd have crashed before here.  Thinko in commit cc415a56d.

--- src/backend/executor/execMain.c
+++ src/backend/executor/execMain.c
@@ -249,9 +249,7 @@
 	estate->es_crosscheck_snapshot = RegisterSnapshot(queryDesc->crosscheck_snapshot);
 	estate->es_top_eflags = eflags;
 	estate->es_instrument = queryDesc->instrument_options;
-
-	if (queryDesc->plannedstmt)
-		estate->es_jit_flags = queryDesc->plannedstmt->jitFlags;
+	estate->es_jit_flags = queryDesc->plannedstmt->jitFlags;

 	/*
 	 * Set up an AFTER-trigger statement context, unless told not to, or


Ensure consistent results when FormSortKeys fails to find all the expected keys (it was returning uninitialized memory).

--- src/backend/executor/nodeSort.c
+++ src/backend/executor/nodeSort.c
@@ -7,11 +7,12 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/executor/nodeSort.c,v 1.18 1999/02/13 23:15:27 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/executor/nodeSort.c,v 1.19 1999/06/03 03:17:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include "postgres.h"
+#include <string.h>

 #include "executor/executor.h"
 #include "executor/execdebug.h"
@@ -58,6 +59,7 @@
 	if (keycount <= 0)
 		elog(ERROR, "FormSortKeys: keycount <= 0");
 	sortkeys = (ScanKey) palloc(keycount * sizeof(ScanKeyData));
+	MemSet((char *) sortkeys, 0, keycount * sizeof(ScanKeyData));

 	/* ----------------
 	 *	form each scan key from the resdom info in the target list
@@ -72,7 +74,7 @@
 		reskey = resdom->reskey;
 		reskeyop = resdom->reskeyop;

-		if (reskey > 0)
+		if (reskey > 0)			/* ignore TLEs that are not sort keys */
 		{
 			ScanKeyEntryInitialize(&sortkeys[reskey - 1],
 								   0,


Further code review for pg_stat_ssl patch.

Fix additional bogosity in commit 9029f4b37406b21a.  Include the
BackendSslStatusBuffer in the BackendStatusShmemSize calculation,
avoid ugly and error-prone casts to char* and back, put related
code stanzas into a consistent order (and fix a couple of previous
instances of that sin).  All cosmetic except for the size oversight.

--- src/backend/postmaster/pgstat.c
+++ src/backend/postmaster/pgstat.c
@@ -2478,8 +2478,8 @@

 static PgBackendStatus *BackendStatusArray = NULL;
 static PgBackendStatus *MyBEEntry = NULL;
+static char *BackendAppnameBuffer = NULL;
 static char *BackendClientHostnameBuffer = NULL;
-static char *BackendAppnameBuffer = NULL;
 static char *BackendActivityBuffer = NULL;
 static Size BackendActivityBufferSize = 0;
 #ifdef USE_SSL
@@ -2495,13 +2495,22 @@
 {
 	Size		size;

+	/* BackendStatusArray: */
 	size = mul_size(sizeof(PgBackendStatus), MaxBackends);
+	/* BackendAppnameBuffer: */
 	size = add_size(size,
 					mul_size(NAMEDATALEN, MaxBackends));
+	/* BackendClientHostnameBuffer: */
+	size = add_size(size,
+					mul_size(NAMEDATALEN, MaxBackends));
+	/* BackendActivityBuffer: */
 	size = add_size(size,
 					mul_size(pgstat_track_activity_query_size, MaxBackends));
+#ifdef USE_SSL
+	/* BackendSslStatusBuffer: */
 	size = add_size(size,
-					mul_size(NAMEDATALEN, MaxBackends));
+					mul_size(sizeof(PgBackendSSLStatus), MaxBackends));
+#endif
 	return size;
 }

@@ -2566,26 +2575,6 @@
 		}
 	}

-#ifdef USE_SSL
-	/* Create or attach to the shared SSL status buffer */
-	size = mul_size(sizeof(PgBackendSSLStatus), MaxBackends);
-	BackendSslStatusBuffer = (PgBackendSSLStatus *)
-		ShmemInitStruct("Backend SSL Status Buffer", size, &found);
-
-	if (!found)
-	{
-		MemSet(BackendSslStatusBuffer, 0, size);
-
-		/* Initialize st_sslstatus pointers. */
-		buffer = (char *) BackendSslStatusBuffer;
-		for (i = 0; i < MaxBackends; i++)
-		{
-			BackendStatusArray[i].st_sslstatus = (PgBackendSSLStatus *) buffer;
-			buffer += sizeof(PgBackendSSLStatus);
-		}
-	}
-#endif
-
 	/* Create or attach to the shared activity buffer */
 	BackendActivityBufferSize = mul_size(pgstat_track_activity_query_size,
 										 MaxBackends);
@@ -2606,6 +2595,28 @@
 			buffer += pgstat_track_activity_query_size;
 		}
 	}
+
+#ifdef USE_SSL
+	/* Create or attach to the shared SSL status buffer */
+	size = mul_size(sizeof(PgBackendSSLStatus), MaxBackends);
+	BackendSslStatusBuffer = (PgBackendSSLStatus *)
+		ShmemInitStruct("Backend SSL Status Buffer", size, &found);
+
+	if (!found)
+	{
+		PgBackendSSLStatus *ptr;
+
+		MemSet(BackendSslStatusBuffer, 0, size);
+
+		/* Initialize st_sslstatus pointers. */
+		ptr = BackendSslStatusBuffer;
+		for (i = 0; i < MaxBackends; i++)
+		{
+			BackendStatusArray[i].st_sslstatus = ptr;
+			ptr++;
+		}
+	}
+#endif
 }

@@ -2932,11 +2943,11 @@
 	volatile PgBackendStatus *beentry;
 	LocalPgBackendStatus *localtable;
 	LocalPgBackendStatus *localentry;
+	char	   *localappname,
+			   *localactivity;
 #ifdef USE_SSL
 	PgBackendSSLStatus *localsslstatus;
 #endif
-	char	   *localappname,
-			   *localactivity;
 	int			i;

 	Assert(!pgStatRunningInCollector);
@@ -2951,15 +2962,15 @@
 	localappname = (char *)
 		MemoryContextAlloc(pgStatLocalContext,
 						   NAMEDATALEN * MaxBackends);
+	localactivity = (char *)
+		MemoryContextAlloc(pgStatLocalContext,
+						   pgstat_track_activity_query_size * MaxBackends);
 #ifdef USE_SSL
 	localsslstatus = (PgBackendSSLStatus *)
 		MemoryContextAlloc(pgStatLocalContext,
 						   sizeof(PgBackendSSLStatus) * MaxBackends);
 #endif

-	localactivity = (char *)
-		MemoryContextAlloc(pgStatLocalContext,
-						   pgstat_track_activity_query_size * MaxBackends);
 	localNumBackends = 0;

 	beentry = BackendStatusArray;


[ This description should have been on the earlier fork/exec
  commit, but I am adding it now so it is in CVS.]

The patch basically is a slight rearrangement of the code to allow
fork/exec on Unix, with the ultimate goal of doing CreateProcess on
Win32.  The changes are:

        o  Write out postmaster global variables and per-backend
variables to be read by the exec'ed backend

        o  Mark some static variables as global when exec is used so
then can be dumped from postmaster.c, marked NON_EXEC_STATIC

        o  Remove value passing with -p now that we have per-backend
file

        o  Move some pointer storage out of shared memory for easier
dumping.

        o  Modified pgsql_temp directory cleanup to handle per-database
directories and the backend exec directory under datadir.

Claudio Natoli

--- src/backend/storage/ipc/shmem.c
+++ src/backend/storage/ipc/shmem.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.75 2003/12/20 17:31:21 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.76 2003/12/21 04:30:10 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -258,9 +258,7 @@
  * ShmemInitHash -- Create/Attach to and initialize
  *		shared memory hash table.
  *
- * Notes:
- *
- * assume caller is doing some kind of synchronization
+ * We assume caller is doing some kind of synchronization
  * so that two people dont try to create/initialize the
  * table at once.
  */


Fix typo in comment.

Fix typo in comment.

neha khatri

--- src/backend/utils/adt/varlena.c
+++ src/backend/utils/adt/varlena.c
@@ -69,7 +69,7 @@
 	int			last_returned;	/* Last comparison result (cache) */
 	bool		cache_blob;		/* Does buf2 contain strxfrm() blob, etc? */
 	bool		collate_c;
-	bool		bpchar;			/* Sorting pbchar, not varchar/text/bytea? */
+	bool		bpchar;			/* Sorting bpchar, not varchar/text/bytea? */
 	hyperLogLogState abbr_card; /* Abbreviated key cardinality state */
 	hyperLogLogState full_card; /* Full key cardinality state */
 	double		prop_card;		/* Required cardinality proportion */


Fix invalid alloc size when invalidating caches

In AddInvalidationMessage() a new chunk always has double size of last
chunk, but once the size exceeds 1GB, the max allowed alloc size, an
error like "invalid memory alloc request size 1,342,177,300" will be
thrown.

Fixed by limiting the chunk size.

(cherry picked from commit a268b387530ba4007d97a9c72e402546f48ce9bc)

--- src/backend/utils/cache/inval.c
+++ src/backend/utils/cache/inval.c
@@ -247,6 +247,14 @@
 	{
 		/* Need another chunk; double size of last chunk */
 		int			chunksize = 2 * chunk->maxitems;
+
+		/*
+		 * Keep in mind: the max allowed alloc size is about 1GB, for
+		 * simplification we set the upper limit to half of that.
+		 */
+#define MAXCHUNKSIZE (MaxAllocSize / 2 / sizeof(SharedInvalidationMessage))
+		if (chunksize > MAXCHUNKSIZE)
+			chunksize >>= 1;

 		chunk = (InvalidationChunk *)
 			MemoryContextAlloc(CurTransactionContext,


runtime: don't assume AT_RANDOM provide 4-byte aligned ptr

R=dave, remyoudompheng
CC=golang-dev
http://codereview.appspot.com/6854056

--- src/pkg/runtime/signal_linux_arm.c
+++ src/pkg/runtime/signal_linux_arm.c
@@ -173,10 +173,13 @@
 void
 runtime·setup_auxv(int32 argc, void *argv_list)
 {
-	byte **argv = &argv_list;
+	byte **argv;
 	byte **envp;
+	byte *rnd;
 	uint32 *auxv;
 	uint32 t;
+
+	argv = &argv_list;

 	// skip envp to get to ELF auxiliary vector.
 	for(envp = &argv[argc+1]; *envp != nil; envp++)
@@ -186,8 +189,10 @@
 	for(auxv=(uint32*)envp; auxv[0] != AT_NULL; auxv += 2) {
 		switch(auxv[0]) {
 		case AT_RANDOM: // kernel provided 16-byte worth of random data
-			if(auxv[1])
-				runtime·randomNumber = *(uint32*)(auxv[1] + 4);
+			if(auxv[1]) {
+				rnd = (byte*)auxv[1];
+				runtime·randomNumber = rnd[4] | rnd[5]<<8 | rnd[6]<<16 | rnd[7]<<24;
+			}
 			break;
 		case AT_PLATFORM: // v5l, v6l, v7l
 			if(auxv[1]) {


squat_trie_lookup(): Make sure we clear result arrays first.

--- src/plugins/fts-squat/squat-trie.c
+++ src/plugins/fts-squat/squat-trie.c
@@ -1630,6 +1630,9 @@
 	unsigned int i, start, bytes, str_bytelen, str_charlen;
 	int ret = 0;

+	array_clear(definite_uids);
+	array_clear(maybe_uids);
+
 	memset(&ctx, 0, sizeof(ctx));
 	ctx.trie = trie;
 	ctx.type = type;


uidlist renumbering: changed iteration code to iterate children first. This
will be needed for handling expunges.

--HG--
branch : HEAD

--- src/plugins/fts-squat/squat-trie.c
+++ src/plugins/fts-squat/squat-trie.c
@@ -999,7 +999,7 @@
 }

 static struct squat_trie_iterate_context *
-squat_trie_iterate_uidlist_init(struct squat_trie *trie)
+squat_trie_iterate_init(struct squat_trie *trie)
 {
 	struct squat_trie_iterate_context *ctx;

@@ -1011,7 +1011,7 @@
 }

 static int
-squat_trie_iterate_uidlist_deinit(struct squat_trie_iterate_context *ctx)
+squat_trie_iterate_deinit(struct squat_trie_iterate_context *ctx)
 {
 	int ret = ctx->failed ? -1 : 0;

@@ -1021,72 +1021,38 @@
 }

 static struct squat_node *
-squat_trie_iterate_uidlist_first(struct squat_trie_iterate_context *ctx)
-{
-	struct squat_node *node = ctx->cur.node;
-	int level;
-
-	if (UIDLIST_IS_SINGLETON(node->uid_list_idx)) {
-		/* no uidlists */
-		i_assert(node == &ctx->trie->root);
-		return NULL;
-	}
-
-	if (node->children_not_mapped) {
-		level = array_count(&ctx->parents);
-
-		if (node_read_children(ctx->trie, node, level) < 0) {
+squat_trie_iterate_first(struct squat_trie_iterate_context *ctx)
+{
+	if (ctx->cur.node->children_not_mapped) {
+		if (node_read_children(ctx->trie, ctx->cur.node, 1) < 0) {
 			ctx->failed = TRUE;
 			return NULL;
 		}
 	}
-	return node;
+	return ctx->cur.node;
 }

 static struct squat_node *
-squat_trie_iterate_uidlist_next(struct squat_trie_iterate_context *ctx)
+squat_trie_iterate_next(struct squat_trie_iterate_context *ctx)
 {
 	struct squat_trie_iterate_node *iter_nodes;
-	struct squat_node *node = ctx->cur.node;
 	struct squat_node *children;
 	unsigned int count;

-	/* return our children first */
-	children = NODE_CHILDREN_NODES(node);
-	for (; ctx->cur.idx < node->child_count; ctx->cur.idx++) {
-		if (!UIDLIST_IS_SINGLETON(children[ctx->cur.idx].uid_list_idx))
-			return &children[ctx->cur.idx++];
-	}
-
-	ctx->cur.idx = 0;
-	for (;;) {
-		/* next start iterating our childrens' children */
-		while (ctx->cur.idx < node->child_count) {
-			uint32_t list_idx =
-				children[ctx->cur.idx++].uid_list_idx;
-
-			if (UIDLIST_IS_SINGLETON(list_idx))
-				continue;
-
-			array_append(&ctx->parents, &ctx->cur, 1);
-			ctx->cur.node = &children[ctx->cur.idx-1];
-			ctx->cur.idx = 0;
-			if (squat_trie_iterate_uidlist_first(ctx) == NULL)
-				return NULL;
-			return squat_trie_iterate_uidlist_next(ctx);
-		}
-
-		/* no more children. go to next sibling's children */
+	while (ctx->cur.idx == ctx->cur.node->child_count) {
 		iter_nodes = array_get_modifiable(&ctx->parents, &count);
 		if (count == 0)
 			return NULL;
-
 		ctx->cur = iter_nodes[count-1];
 		array_delete(&ctx->parents, count-1, 1);
-
-		node = ctx->cur.node;
-		children = NODE_CHILDREN_NODES(node);
-	}
+	}
+
+	ctx->cur.idx++;
+	array_append(&ctx->parents, &ctx->cur, 1);
+	children = NODE_CHILDREN_NODES(ctx->cur.node);
+	ctx->cur.node = &children[ctx->cur.idx-1];
+	ctx->cur.idx = 0;
+	return ctx->cur.node;
 }

 static int
@@ -1111,24 +1077,25 @@
 		I_MAX((unsigned int)now, ctx->trie->hdr.indexid + 1);

 	i_array_init(&uids, 1024);
-	iter = squat_trie_iterate_uidlist_init(ctx->trie);
-	node = squat_trie_iterate_uidlist_first(iter);
+	iter = squat_trie_iterate_init(ctx->trie);
+	node = squat_trie_iterate_first(iter);
 	new_uid_list_idx = 0x100;
 	while (node != NULL) {
-		array_clear(&uids);
-		if (squat_uidlist_get(ctx->trie->uidlist, node->uid_list_idx,
-				      &uids) < 0) {
-			ret = -1;
-			break;
-		}
-		max_count = I_MAX(max_count, array_count(&uids));
-		squat_uidlist_rebuild_next(rebuild_ctx, &uids);
-		node->uid_list_idx = new_uid_list_idx << 1;
-		new_uid_list_idx++;
-
-		node = squat_trie_iterate_uidlist_next(iter);
-	}
-	squat_trie_iterate_uidlist_deinit(iter);
+		if (!UIDLIST_IS_SINGLETON(node->uid_list_idx)) {
+			array_clear(&uids);
+			if (squat_uidlist_get(ctx->trie->uidlist,
+					      node->uid_list_idx, &uids) < 0) {
+				ret = -1;
+				break;
+			}
+			max_count = I_MAX(max_count, array_count(&uids));
+			squat_uidlist_rebuild_next(rebuild_ctx, &uids);
+			node->uid_list_idx = new_uid_list_idx << 1;
+			new_uid_list_idx++;
+		}
+		node = squat_trie_iterate_next(iter);
+	}
+	squat_trie_iterate_deinit(iter);
 	array_free(&uids);

 	/* lock the trie before we rename uidlist */


virtual plugin: Optimized syncing a large number of physical mailboxes. Especially when the number of mails was large the old code took a lot of CPU time. Based on patch by Teemu Huovila.

--- src/plugins/virtual/virtual-sync.c
+++ src/plugins/virtual/virtual-sync.c
@@ -36,6 +36,11 @@
 	ARRAY_TYPE(seq_range) sync_expunges;

 	ARRAY(struct virtual_add_record) all_adds;
+
+	/* all messages in this sync */
+	ARRAY(const struct virtual_mail_index_record) all_mails;
+	uint32_t all_mails_idx, all_mails_prev_mailbox_id;
+
 	enum mailbox_sync_flags flags;
 	uint32_t uid_validity;

@@ -629,45 +634,79 @@
 	}
 }

+static void
+virtual_sync_backend_add_vmsgs_results(struct virtual_sync_context *ctx,
+				       struct virtual_backend_box *bbox,
+                                       uint32_t real_uid,
+                                       struct mail_search_result *result,
+                                       const uint32_t vseq)
+{
+	struct virtual_backend_uidmap uidmap;
+	uint32_t vuid, seq;
+
+	mail_index_lookup_uid(ctx->sync_view, vseq, &vuid);
+
+	memset(&uidmap, 0, sizeof(uidmap));
+	uidmap.real_uid = real_uid;
+	uidmap.virtual_uid = vuid;
+	array_append(&bbox->uids, &uidmap, 1);
+
+	if (result == NULL)
+		;
+	else if (mail_index_lookup_seq(bbox->box->view, real_uid, &seq))
+		seq_range_array_add(&result->uids, real_uid);
+	else
+		seq_range_array_add(&result->removed_uids, real_uid);
+}
+
 static void
 virtual_sync_backend_handle_old_vmsgs(struct virtual_sync_context *ctx,
 				      struct virtual_backend_box *bbox,
 				      struct mail_search_result *result)
 {
-	const struct virtual_mail_index_record *vrec;
-	struct virtual_backend_uidmap uidmap;
+	const struct virtual_mail_index_record *vrec, *vrecs;
 	const void *data;
-	uint32_t seq, vseq, vuid, messages;
-
-	/* add the currently existing UIDs to uidmap. remember the messages
-	   that were already expunged */
-	memset(&uidmap, 0, sizeof(uidmap));
+	uint32_t vseq, messages;
+
+	/* find the messages that currently exist in virtual index and add them
+	   to the backend mailbox's list of uids. */
 	array_clear(&bbox->uids);

-	messages = mail_index_view_get_messages_count(ctx->sync_view);
-	for (vseq = 1; vseq <= messages; vseq++) {
-		mail_index_lookup_uid(ctx->sync_view, vseq, &vuid);
-		mail_index_lookup_ext(ctx->sync_view, vseq,
-				      ctx->mbox->virtual_ext_id, &data, NULL);
-		vrec = data;
-		if (vrec->mailbox_id == bbox->mailbox_id) {
-			uidmap.real_uid = vrec->real_uid;
-			uidmap.virtual_uid = vuid;
-			array_append(&bbox->uids, &uidmap, 1);
-
-			if (result == NULL)
-				;
-			else if (mail_index_lookup_seq(bbox->box->view,
-						       vrec->real_uid, &seq)) {
-				seq_range_array_add(&result->uids,
-						    vrec->real_uid);
-			} else {
-				seq_range_array_add(&result->removed_uids,
-						    vrec->real_uid);
+	if (array_is_created(&ctx->all_mails)) {
+		i_assert(ctx->all_mails_prev_mailbox_id < bbox->mailbox_id);
+		vrecs = array_get(&ctx->all_mails, &messages);
+		for (vseq = ctx->all_mails_idx + 1; vseq <= messages; vseq++) {
+			vrec = &vrecs[vseq - 1];
+			if (vrec->mailbox_id != bbox->mailbox_id) {
+				if (vrec->mailbox_id < bbox->mailbox_id) {
+					/* stale mailbox_id, ignore */
+					continue;
+				}
+				/* Should be in mailbox_id order,
+				   so skip to next box */
+				break;
 			}
-		}
-	}
-
+
+			virtual_sync_backend_add_vmsgs_results(ctx,
+				bbox, vrec->real_uid, result, vseq);
+		}
+		ctx->all_mails_idx = vseq - 1;
+		ctx->all_mails_prev_mailbox_id = bbox->mailbox_id;
+	} else {
+		/* there should be only a single backend mailbox, but in the
+		   existing index there may be stale mailbox_ids that we'll
+		   just skip over. */
+		messages = mail_index_view_get_messages_count(ctx->sync_view);
+		for (vseq = 1; vseq <= messages; vseq++) {
+			mail_index_lookup_ext(ctx->sync_view, vseq,
+			                      ctx->mbox->virtual_ext_id, &data, NULL);
+			vrec = data;
+			if (vrec->mailbox_id == bbox->mailbox_id) {
+				virtual_sync_backend_add_vmsgs_results(ctx,
+					bbox, vrec->real_uid, result, vseq);
+			}
+		}
+	}
 	virtual_sync_bbox_uids_sort(bbox);
 }

@@ -1442,6 +1481,33 @@
 	}
 }

+static int
+virtual_sync_mails_mailbox_cmp(const struct virtual_mail_index_record *v1,
+			       const struct virtual_mail_index_record *v2)
+{
+	if (v1->mailbox_id < v2->mailbox_id)
+		return -1;
+	if (v1->mailbox_id > v2->mailbox_id)
+		return 1;
+	return 0;
+}
+
+static void virtual_sync_bboxes_get_mails(struct virtual_sync_context *ctx)
+{
+	uint32_t messages, vseq;
+	const void *mail_data;
+	const struct virtual_mail_index_record *vrec;
+
+	messages = mail_index_view_get_messages_count(ctx->sync_view);
+	for (vseq = 1; vseq <= messages; vseq++) {
+		mail_index_lookup_ext(ctx->sync_view, vseq,
+				      ctx->mbox->virtual_ext_id, &mail_data, NULL);
+		vrec = mail_data;
+		array_append(&ctx->all_mails, vrec, 1);
+	}
+	array_sort(&ctx->all_mails, virtual_sync_mails_mailbox_cmp);
+}
+
 static int virtual_sync_backend_boxes(struct virtual_sync_context *ctx)
 {
 	struct virtual_backend_box *const *bboxes;
@@ -1453,6 +1519,14 @@

 	i_array_init(&ctx->all_adds, 128);
 	bboxes = array_get(&ctx->mbox->backend_boxes, &count);
+
+	/* we have different optimizations depending on whether the virtual
+	   mailbox consists of multiple backend boxes or just one */
+	if (count > 1) {
+		i_array_init(&ctx->all_mails, 128);
+		virtual_sync_bboxes_get_mails(ctx);
+	}
+
 	for (i = 0; i < count; i++) {
 		if (virtual_sync_backend_box(ctx, bboxes[i]) < 0) {
 			/* backend failed, copy the error */
@@ -1471,6 +1545,8 @@
 	}
 	ret = virtual_sync_backend_add_new(ctx);
 	array_free(&ctx->all_adds);
+	if (array_is_created(&ctx->all_mails))
+		array_free(&ctx->all_mails);
 	return ret;
 }


i#1306 Dr. Heapstat -replace_malloc, part 9:

Clean up warts in realloc handling wrt
client_{add,remove}_malloc_{pre,post} for out-of-place realloc:

+ Split ALLOC_INVOKE_CLIENT into ALLOC_INVOKE_CLIENT_DATA and
  ALLOC_INVOKE_CLIENT_ACTION
+ Invoke the data routines client_remove_malloc_{pre,post} on a
  realloc free, but delay the client_add_malloc_{pre,post}
  until after the free is finished
+ Add a new header flag CHUNK_SKIP_ITER to temporarily hide
  the new realloc chunk from a client iteration from
  client_remove_malloc_{pre,post}

SVN-Revision: 1491

--- common/alloc_replace.c
+++ common/alloc_replace.c
@@ -134,6 +134,7 @@
 #ifdef WINDOWS
     CHUNK_LAYER_RTL   = MALLOC_RESERVED_8,          /* 0x0800 */
 #endif
+    CHUNK_SKIP_ITER   =                                0x1000,

     /* meta-flags */
 #ifdef WINDOWS
@@ -375,12 +376,20 @@
     ALLOC_SYNCHRONIZE      = 0x0001, /* malloc, free, and realloc */
     ALLOC_ZERO             = 0x0002, /* malloc and realloc */
     ALLOC_IS_REALLOC       = 0x0004, /* malloc and free */
-    ALLOC_INVOKE_CLIENT    = 0x0008, /* malloc and free */
-    ALLOC_IN_PLACE_ONLY    = 0x0010, /* realloc */
-    ALLOC_ALLOW_NULL       = 0x0020, /* realloc: do not fail on NULL */
-    ALLOC_ALLOW_EMPTY      = 0x0040, /* realloc: size==0 does re-allocate */
-    ALLOC_IGNORE_MISMATCH  = 0x0080, /* free, realloc, size */
-    ALLOC_IS_QUERY         = 0x0100, /* check_type_match */
+    /* Routines that free the client_data (client_malloc_data_free(),
+     * client_handle_free_reuse()) and routines reporting on invalid
+     * heap args or OOM are called regardless of these flags' values.
+     */
+    /* Whether to invoke client_{add,remove}_malloc_{pre,post} */
+    ALLOC_INVOKE_CLIENT_DATA   = 0x0008, /* malloc and free */
+    /* Whether to invoke client_handle_{malloc,free} */
+    ALLOC_INVOKE_CLIENT_ACTION = 0x0010, /* malloc and free */
+    ALLOC_INVOKE_CLIENT    = ALLOC_INVOKE_CLIENT_DATA | ALLOC_INVOKE_CLIENT_ACTION,
+    ALLOC_IN_PLACE_ONLY    = 0x0020, /* realloc */
+    ALLOC_ALLOW_NULL       = 0x0040, /* realloc: do not fail on NULL */
+    ALLOC_ALLOW_EMPTY      = 0x0080, /* realloc: size==0 does re-allocate */
+    ALLOC_IGNORE_MISMATCH  = 0x0100, /* free, realloc, size */
+    ALLOC_IS_QUERY         = 0x0200, /* check_type_match */
 } alloc_flags_t;

 /***************************************************************************
@@ -688,9 +697,12 @@
                            head->alloc_size, false/*!pre_us*/, true/*redzone*/,
                            TEST(ALLOC_ZERO, flags), TEST(ALLOC_IS_REALLOC, flags),
                            0, head->user_data };
-    head->user_data = client_add_malloc_pre(&info, mc, caller);
-    client_add_malloc_post(&info);
-    if (TEST(ALLOC_INVOKE_CLIENT, flags)) {
+    if (TEST(ALLOC_INVOKE_CLIENT_DATA, flags)) {
+        head->user_data = client_add_malloc_pre(&info, mc, caller);
+        info.client_data = head->user_data;
+        client_add_malloc_post(&info);
+    }
+    if (TEST(ALLOC_INVOKE_CLIENT_ACTION, flags)) {
         ASSERT(drcontext != NULL, "invalid arg");
         client_handle_malloc(drcontext, &info, mc);
     }
@@ -1511,9 +1523,9 @@
     return head;
 }

-/* ALLOC_INVOKE_CLIENT in flags only applies to successful allocation
- * and only client_handle_malloc(): client is still notified on
- * failure, and is notified of post-malloc.
+/* As noted in the flag definitions, ALLOC_INVOKE_CLIENT_* in flags
+ * only applies to successful allocation: client is still notified on failure
+ * and when client user data is freed or shifted.
  */
 static byte *
 replace_alloc_common(arena_header_t *arena, size_t request_size, alloc_flags_t flags,
@@ -1597,7 +1609,7 @@
         }
         if (arena == NULL)
             arena = arena_extend(last_arena, add_size);
-        if (arena == NULL) {
+        if (arena == NULL) {  /* ignore ALLOC_INVOKE_CLIENT */
             client_handle_alloc_failure(request_size, caller, mc);
             goto replace_alloc_common_done;
         }
@@ -1764,7 +1776,7 @@
                 }
             }
 #endif
-            if (!valid) {
+            if (!valid) { /* call regardless of ALLOC_INVOKE_CLIENT */
                 client_invalid_heap_arg(caller, (byte *)ptr, mc,
                                         /* XXX: we might be replacing RtlHeapFree or
                                          * _free_dbg but it's not worth trying to
@@ -1785,10 +1797,11 @@
      * or we always want to replace w/ free callstack?
      */
     header_to_info(head, &info, NULL, 0);
-    client_remove_malloc_pre(&info);
+    if (TEST(ALLOC_INVOKE_CLIENT_DATA, flags))
+        client_remove_malloc_pre(&info);
     if (TESTANY(CHUNK_MMAP | CHUNK_PRE_US, head->flags)) {
         if (head->user_data != NULL)
-            client_malloc_data_free(head->user_data);
+            client_malloc_data_free(head->user_data); /* ignores ALLOC_INVOKE_CLIENT */
         head->user_data = NULL;
     } else
         head->user_data = client_malloc_data_to_free_list(head->user_data, mc, caller);
@@ -1798,10 +1811,10 @@
      */
     head->flags |= CHUNK_FREED; /* even if CHUNK_MMAP, so a client iter will skip */

-    client_remove_malloc_post(&info);
-
-    /* we ignore the return value */
-    if (TEST(ALLOC_INVOKE_CLIENT, flags)) {
+    if (TEST(ALLOC_INVOKE_CLIENT_DATA, flags))
+        client_remove_malloc_post(&info);
+    if (TEST(ALLOC_INVOKE_CLIENT_ACTION, flags)) {
+        /* we ignore the return value */
         client_handle_free(&info, (byte *)ptr, mc, caller, NULL,
                            false/*reuse delayed*/ _IF_WINDOWS(NULL));
     }
@@ -1912,11 +1925,28 @@
         if (res != NULL) {
             head = header_from_ptr(res);
             memcpy(res, ptr, MIN(size, old_request_size));
+            /* Prevent client iteration in client_remove_malloc_{pre,post} from
+             * seeing the new alloc and complaining that it has not yet had
+             * client_add_malloc_{pre,post} called on it yet.
+             */
+            head->flags |= CHUNK_SKIP_ITER;
             replace_free_common(arena, ptr,
-                                sub_flags /*no client */ | ALLOC_IS_REALLOC |
+                                sub_flags | ALLOC_IS_REALLOC |
+                                /* we do want client_remove_malloc_{pre,post} as they
+                                 * must be called around the actual free -- but
+                                 * no client_handle_free()
+                                 */
+                                ALLOC_INVOKE_CLIENT_DATA /* not _ACTION */ |
                                 ALLOC_IGNORE_MISMATCH,
                                 drcontext, mc, caller, alloc_type);
+            head->flags &= ~CHUNK_SKIP_ITER;
             header_to_info(head, &new_info, NULL, flags | ALLOC_IS_REALLOC);
+            /* We delay client_add_malloc_{pre,post} until here, to avoid a client
+             * iterating inside the event and seeing both the new and old allocs!
+             */
+            notify_client_alloc(drcontext, (byte *)res, head,
+                                flags | ALLOC_IS_REALLOC | ALLOC_INVOKE_CLIENT_DATA,
+                                mc, caller);
             client_handle_realloc(drcontext, &old_info, &new_info, was_mmap, mc);
         }
     }
@@ -1972,6 +2002,13 @@
     void *data;
 } alloc_iter_data_t;

+static inline bool
+skip_chunk_in_iter(alloc_iter_data_t *data, chunk_header_t *head)
+{
+    return (data->only_live && TEST(CHUNK_FREED, head->flags)) ||
+        TEST(CHUNK_SKIP_ITER, head->flags);
+}
+
 static bool
 alloc_iter_own_arena(byte *iter_arena_start, byte *iter_arena_end, uint flags
                      _IF_WINDOWS(HANDLE heap), void *iter_data)
@@ -1988,7 +2025,7 @@
     /* We rely on the heap region lock to avoid races accessing this */
     if (TEST(HEAP_MMAP, flags)) {
         chunk_header_t *head = header_from_mmap_base(iter_arena_start);
-        if (!data->only_live || !TEST(CHUNK_FREED, head->flags)) {
+        if (!skip_chunk_in_iter(data, head)) {
             header_to_info(head, &info, NULL, 0);
             ASSERT(TEST(CHUNK_MMAP, head->flags), "mmap chunk inconsistent");
             LOG(2, "%s: "PFX"-"PFX"\n", __FUNCTION__, info.base,
@@ -2009,7 +2046,7 @@
         head = header_from_ptr(cur);
         LOG(3, "\tchunk %s "PFX"-"PFX"\n", TEST(CHUNK_FREED, head->flags) ? "freed" : "",
             ptr_from_header(head), ptr_from_header(head) + head->alloc_size);
-        if (!data->only_live || !TEST(CHUNK_FREED, head->flags)) {
+        if (!skip_chunk_in_iter(data, head)) {
             header_to_info(head, &info, NULL, 0);
             if (!data->cb(&info, data->data)) {
                 iterator_unlock(arena, false/*!in alloc*/);
@@ -2057,7 +2094,7 @@
         for (he = pre_us_table.table[i]; he != NULL; he = he->next) {
             chunk_header_t *head = (chunk_header_t *) he->payload;
             byte *start = he->key;
-            if (!only_live || !TEST(CHUNK_FREED, head->flags)) {
+            if (!skip_chunk_in_iter(&data, head)) {
                 LOG(3, "\tpre-us "PFX"-"PFX"-"PFX"\n",
                     start, start + chunk_request_size(head), start + head->alloc_size);
                 header_to_info(head, &info, start, 0);
@@ -3683,8 +3720,8 @@
     LOG(3, "new pre-us alloc "PFX"-"PFX"-"PFX"\n", start, end, real_end);
     ASSERT(new_entry, "should be no pre-us dups");
     notify_client_alloc(NULL, start, head,
-                        0 /* no invoke: caller can do that on its own */,
-                        mc, post_call);
+                        /* no client action: caller can do that on its own */
+                        ALLOC_INVOKE_CLIENT_DATA, mc, post_call);
 }

 static bool


Fix string comparison

Fix string comparison

Fixes the compilation errors like:

    ../nginx-clojure-0.3.0/src/c/ngx_http_clojure_module.c: In function 'ngx_http_clojure_merge_loc_conf':
    ../nginx-clojure-0.3.0/src/c/ngx_http_clojure_module.c:662:78: error: comparison with string literal results in unspecified behavior [-Werror=address]
       if (!conf->handler ##  _type.len && conf->enable_ ## handler &&  # handler != "content_handler") {  \
                                                                                ^
    ../nginx-clojure-0.3.0/src/c/ngx_http_clojure_module.c:704:2: note: in expansion of macro 'ngx_http_clojure_merge_handler'
      ngx_http_clojure_merge_handler(conf, prev, content_handler);
      ^

--- src/c/ngx_http_clojure_module.c
+++ src/c/ngx_http_clojure_module.c
@@ -659,7 +659,7 @@
                 } \
            } \
 		}  \
-		if (!conf->handler ##  _type.len && conf->enable_ ## handler &&  # handler != "content_handler") {  \
+		if (!conf->handler ##  _type.len && conf->enable_ ## handler && ngx_strcmp( # handler, "content_handler") != 0) {  \
 					if (conf->enable_content_handler || conf->content_handler_type.len) {  \
 						ngx_conf_merge_str_value(conf->handler ##  _type,  conf->content_handler_type, "clojure"); \
 					} \


fixes issue 1005

fixes issue 1005

Clear allocator type flags when re-using from free list

SVN-Revision: 1012

--- common/alloc_replace.c
+++ common/alloc_replace.c
@@ -775,7 +775,7 @@
             client_malloc_data_free(head->user_data);
             head->user_data = NULL;
         }
-        head->flags &= ~CHUNK_FREED;
+        head->flags &= ~(CHUNK_FREED | MALLOC_ALLOCATOR_FLAGS);
     }
     return head;
 }
@@ -867,8 +867,8 @@
     head->request_size = request_size;
     head->flags |= alloc_type;
     res = ptr_from_header(head);
-    LOG(2, "\treplace_alloc_common request=%d, alloc=%d => "PFX"\n",
-        head->request_size, head->alloc_size, res);
+    LOG(2, "\treplace_alloc_common flags="PIFX" request=%d, alloc=%d => "PFX"\n",
+        head->flags, head->request_size, head->alloc_size, res);

     ASSERT(head->alloc_size >= request_size, "chunk too small");

@@ -892,6 +892,8 @@
                  dr_mcontext_t *mc, app_pc caller)
 {
     uint alloc_type = (head->flags & MALLOC_ALLOCATOR_FLAGS);
+    LOG(3, "\tcheck_type_match: alloc flags="PIFX" vs free="PIFX"\n",
+        head->flags, free_type);
     ASSERT((free_type & ~(MALLOC_ALLOCATOR_FLAGS)) == 0, "invalid type flags");
     if ((alloc_type != MALLOC_ALLOCATOR_UNKNOWN &&
          free_type != MALLOC_ALLOCATOR_UNKNOWN) &&


test fix after last commit

test fix after last commit

--- test/log-format-resolution-test.h
+++ test/log-format-resolution-test.h
@@ -8,15 +8,15 @@
     EXPECT_EQ(ELPP_LITERAL("%logger %thread"), format.format());
     EXPECT_EQ("", format.dateTimeFormat());

-    LogFormat format2(Level::Info, ELPP_LITERAL("%logger %datetime{%d/%M/%Y %h:%m:%s  } %thread"));
-    EXPECT_EQ(ELPP_LITERAL("%logger %datetime{%d/%M/%Y %h:%m:%s  } %thread"), format2.userFormat());
+    LogFormat format2(Level::Info, ELPP_LITERAL("%logger %datetime{%Y-%M-%d %h:%m:%s  } %thread"));
+    EXPECT_EQ(ELPP_LITERAL("%logger %datetime{%Y-%M-%d %h:%m:%s  } %thread"), format2.userFormat());
     EXPECT_EQ(ELPP_LITERAL("%logger %datetime %thread"), format2.format());
-    EXPECT_EQ("%d/%M/%Y %h:%m:%s  ", format2.dateTimeFormat());
+    EXPECT_EQ("%Y-%M-%d %h:%m:%s  ", format2.dateTimeFormat());

-    LogFormat format3(Level::Info, ELPP_LITERAL("%logger %datetime{%d/%M/%Y} %thread"));
-    EXPECT_EQ(ELPP_LITERAL("%logger %datetime{%d/%M/%Y} %thread"), format3.userFormat());
+    LogFormat format3(Level::Info, ELPP_LITERAL("%logger %datetime{%Y-%M-%d} %thread"));
+    EXPECT_EQ(ELPP_LITERAL("%logger %datetime{%Y-%M-%d} %thread"), format3.userFormat());
     EXPECT_EQ(ELPP_LITERAL("%logger %datetime %thread"), format3.format());
-    EXPECT_EQ("%d/%M/%Y", format3.dateTimeFormat());
+    EXPECT_EQ("%Y-%M-%d", format3.dateTimeFormat());
 }

 TEST(LogFormatResolutionTest, DefaultFormat) {
@@ -24,17 +24,17 @@
     LogFormat defaultFormat(Level::Info, ELPP_LITERAL("%logger %datetime %thread"));
     EXPECT_EQ(ELPP_LITERAL("%logger %datetime %thread"), defaultFormat.userFormat());
     EXPECT_EQ(ELPP_LITERAL("%logger %datetime %thread"), defaultFormat.format());
-    EXPECT_EQ("%d/%M/%Y %H:%m:%s,%g", defaultFormat.dateTimeFormat());
+    EXPECT_EQ("%Y-%M-%d %H:%m:%s,%g", defaultFormat.dateTimeFormat());

     LogFormat defaultFormat2(Level::Info, ELPP_LITERAL("%logger %datetime %thread"));
     EXPECT_EQ(ELPP_LITERAL("%logger %datetime %thread"), defaultFormat2.userFormat());
     EXPECT_EQ(ELPP_LITERAL("%logger %datetime %thread"), defaultFormat2.format());
-    EXPECT_EQ("%d/%M/%Y %H:%m:%s,%g", defaultFormat2.dateTimeFormat());
+    EXPECT_EQ("%Y-%M-%d %H:%m:%s,%g", defaultFormat2.dateTimeFormat());

     LogFormat defaultFormat4(Level::Verbose, ELPP_LITERAL("%logger %level-%vlevel %datetime %thread"));
     EXPECT_EQ(ELPP_LITERAL("%logger %level-%vlevel %datetime %thread"), defaultFormat4.userFormat());
     EXPECT_EQ(ELPP_LITERAL("%logger VER-%vlevel %datetime %thread"), defaultFormat4.format());
-    EXPECT_EQ("%d/%M/%Y %H:%m:%s,%g", defaultFormat4.dateTimeFormat());
+    EXPECT_EQ("%Y-%M-%d %H:%m:%s,%g", defaultFormat4.dateTimeFormat());
 }

 TEST(LogFormatResolutionTest, EscapedFormat) {


VLA-compound-literal can continue after error

--- src/cc1/ops/expr_compound_lit.c
+++ src/cc1/ops/expr_compound_lit.c
@@ -67,7 +67,9 @@
 		decl_init_create_assignments_base(d->bits.var.init.dinit,
 				d->ref, e, &d->bits.var.init.expr);

-		fold_expr(d->bits.var.init.expr, stab);
+		if(d->bits.var.init.expr)
+			fold_expr(d->bits.var.init.expr, stab);
+		/* else had error */

 	}else{
 		fold_decl_global_init(d, stab);


net/dns: Add test of dns_mx for site with multiple MXs

--- net/dns_mx.c
+++ net/dns_mx.c
@@ -54,18 +54,34 @@
 DNS_R_FN_WRAP(mx, const char*)

 #ifdef SELFTEST_MAIN
-#include "str/iter.h"
+struct dns_result out = {0};
+
+static void doit(const char* fqdn)
+{
+  int i;
+
+  debugfn(dns_mx(&out, fqdn));
+  obuf_putf(&outbuf, "s{ => }d{\n}", fqdn, out.count);
+  dns_sort_mx(out.rr.mx, out.count);
+  for (i = 0; i < out.count; ++i)
+    obuf_putf(&outbuf, "d{ }d{: \"}s{\"\n}", i, out.rr.mx[i].distance, out.rr.mx[i].name);
+}
+
 MAIN
 {
-  struct dns_result out = {0};
-  int i;
-
-  debugfn(dns_mx(&out, "untroubled.org"));
-  for (i = 0; i < out.count; ++i)
-    obuf_putf(&outbuf, "d{ }d{: \"}s{\"\n}", i, out.rr.mx[i].distance, out.rr.mx[i].name);
+  doit("untroubled.org");
+  doit("google.com");
 }
 #endif
 #ifdef SELFTEST_EXP
 result=0
+untroubled.org => 1
 0 12801: "mx.futurequest.net"
+result=0
+google.com => 5
+0 10: "aspmx.l.google.com"
+1 20: "alt1.aspmx.l.google.com"
+2 30: "alt2.aspmx.l.google.com"
+3 40: "alt3.aspmx.l.google.com"
+4 50: "alt4.aspmx.l.google.com"
 #endif


appdata: Include compatible arches in main arch when unique

For example, if a i386 build is in the repo but no x86-64 version then
also add the i386 build to the x86-64 appstream data.  However, don't
add it if that would cause a duplicate (i.e. both the x86-64 and i386
version).

Closes: #1585
Approved by: alexlarsson

--- common/flatpak-utils.c
+++ common/flatpak-utils.c
@@ -419,39 +419,65 @@
   return FALSE;
 }

+static struct {
+  const char *kernel_arch;
+  const char *compat_arch;
+} compat_arches[] = {
+  { "x86_64", "i386" },
+  { "aarch64", "arm" },
+};
+
+static const char *
+flatpak_get_compat_arch (const char *kernel_arch)
+{
+  int i;
+
+  /* Also add all other arches that are compatible with the kernel arch */
+  for (i = 0; i < G_N_ELEMENTS(compat_arches); i++)
+    {
+      if (strcmp (compat_arches[i].kernel_arch, kernel_arch) == 0)
+        return compat_arches[i].compat_arch;
+    }
+
+  return NULL;
+}
+
+static const char *
+flatpak_get_compat_arch_reverse (const char *compat_arch)
+{
+  int i;
+
+  /* Also add all other arches that are compatible with the kernel arch */
+  for (i = 0; i < G_N_ELEMENTS(compat_arches); i++)
+    {
+      if (strcmp (compat_arches[i].compat_arch, compat_arch) == 0)
+        return compat_arches[i].kernel_arch;
+    }
+
+  return NULL;
+}
+
 /* Get all compatible arches for this host in order of priority */
 const char **
 flatpak_get_arches (void)
 {
   static gsize arches = 0;
-  static struct {
-    const char *kernel_arch;
-    const char *compat_arch;
-  } compat_arches[] = {
-    { "x86_64", "i386" },
-    { "aarch64", "arm" },
-  };

   if (g_once_init_enter (&arches))
     {
       gsize new_arches = 0;
       const char *main_arch = flatpak_get_arch ();
       const char *kernel_arch = flatpak_get_kernel_arch ();
+      const char *compat_arch;
       GPtrArray *array = g_ptr_array_new ();
-      int i;

       /* This is the userspace arch, i.e. the one flatpak itself was
          build for. It's always first. */
       g_ptr_array_add (array, (char *)main_arch);

-      /* Also add all other arches that are compatible with the kernel arch */
-      for (i = 0; i < G_N_ELEMENTS(compat_arches); i++)
-        {
-          if ((strcmp (compat_arches[i].kernel_arch, kernel_arch) == 0) &&
-              /* Don't re-add the main arch */
-              (strcmp (compat_arches[i].compat_arch, main_arch) != 0))
-            g_ptr_array_add (array, (char *)compat_arches[i].compat_arch);
-        }
+      compat_arch = flatpak_get_compat_arch (kernel_arch);
+      if (strcmp (compat_arch, main_arch) != 0)
+        g_ptr_array_add (array, (char *)compat_arch);

       g_ptr_array_add (array, NULL);
       new_arches = (gsize)g_ptr_array_free (array, FALSE);
@@ -3582,7 +3608,15 @@

       arch = split[2];
       if (!g_hash_table_contains (arches, arch))
-        g_hash_table_add (arches, g_strdup (arch));
+        {
+          const char *reverse_compat_arch;
+          g_hash_table_add (arches, g_strdup (arch));
+
+          /* If repo contains e.g. i386, also generated x86-64 appdata */
+          reverse_compat_arch = flatpak_get_compat_arch_reverse (arch);
+          if (reverse_compat_arch)
+            g_hash_table_add (arches, g_strdup (reverse_compat_arch));
+        }
     }

   GLNX_HASH_TABLE_FOREACH (arches, const char *, arch)
@@ -3600,6 +3634,9 @@
       g_autoptr(FlatpakXml) appstream_root = NULL;
       g_autoptr(GBytes) xml_data = NULL;
       gboolean skip_commit = FALSE;
+      const char *compat_arch;
+
+      compat_arch = flatpak_get_compat_arch (arch);

       if (g_mkdtemp_full (tmpdir, 0755) == NULL)
         return flatpak_fail (error, "Can't create temporary directory");
@@ -3622,7 +3659,17 @@
             continue;

           if (strcmp (split[2], arch) != 0)
-            continue;
+            {
+              g_autofree char *main_ref = NULL;
+              /* Include refs that don't match the main arch (e.g. x86_64), if they match
+                 the compat arch (e.g. i386) and the main arch version is not in the repo */
+              if (g_strcmp0 (split[2], compat_arch) == 0)
+                main_ref = g_strdup_printf ("%s/%s/%s/%s",
+                                            split[0], split[1], arch, split[3]);
+              if (main_ref == NULL ||
+                  g_hash_table_lookup (all_refs, main_ref))
+                continue;
+            }

           if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, commit,
                                          &commit_v, NULL))


do not include `uuid/uuid.h` for compatibility with FreeBSD / NetBSD

--- neverbleed.c
+++ neverbleed.c
@@ -36,7 +36,6 @@
 #include <sys/types.h>
 #include <sys/uio.h>
 #include <unistd.h>
-#include <uuid/uuid.h>
 #include <openssl/rand.h>
 #include <openssl/ssl.h>
 #ifdef __linux__


cmds: Add '-d' option to 'lsusb'

cmds: Add '-d' option to 'lsusb'

--- src/cmds/hardware/lsusb/lsusb.c
+++ src/cmds/hardware/lsusb/lsusb.c
@@ -18,6 +18,7 @@
 	printf("\t[-h]                    - print this help\n");
 	printf("\t[-v]                    - print verbose output with device, configuration and interface descriptors\n");
 	printf("\t[-s [[bus]:]devnum]     - print by device number and optional bus number (both in decimal)\n");
+	printf("\t[-d [vendor]:[product]] - print by vendor id and/or product id (both in hexadecimal)\n");

 }

@@ -146,7 +147,12 @@
 	uint16_t devnum = 0;
 	int devnum_set = 0;

-	while (-1 != (opt = getopt(argc, argv, "s:h:v"))) {
+	uint16_t vendor = 0;
+	int vendor_set = 0;
+	uint16_t product = 0;
+	int product_set = 0;
+
+	while (-1 != (opt = getopt(argc, argv, "s:d:h:v"))) {
 		switch (opt) {
 		case '?':
 		case 'h':
@@ -174,6 +180,22 @@
 				}
 			}
 			break;
+		case 'd':
+			cp = strchr(optarg, ':');
+			if (!cp) {
+				print_error();
+				return 0;
+			}
+			*cp++ = 0;
+			if (*optarg) {
+				vendor_set = 1;
+				vendor = strtoul(optarg, NULL, 16);
+			}
+			if (*cp) {
+				product_set = 1;
+				product = strtoul(cp, NULL, 16);
+			}
+			break;
 		default:
 			print_error();
 			return 0;
@@ -186,6 +208,11 @@
 			continue;
 		}

+		if ((vendor_set && vendor != usb_dev->dev_desc.id_vendor) ||
+				(product_set && product != usb_dev->dev_desc.id_product)) {
+			continue;
+		}
+
 		show_usb_dev(usb_dev);
 		if(flag) {
 			int conf_cnt = 0;


utils: ctrl-api-test: add some tests for multiple host rings

--- utils/ctrl-api-test.c
+++ utils/ctrl-api-test.c
@@ -139,6 +139,8 @@
 	uint32_t nr_rx_slots;   /* slots in rx rings */
 	uint16_t nr_tx_rings;   /* number of tx rings */
 	uint16_t nr_rx_rings;   /* number of rx rings */
+	uint16_t nr_host_tx_rings;   /* number of host tx rings */
+	uint16_t nr_host_rx_rings;   /* number of host rx rings */
 	uint16_t nr_mem_id;     /* id of the memory allocator */
 	uint16_t nr_ringid;     /* ring(s) we care about */
 	uint32_t nr_mode;       /* specify NR_REG_* modes */
@@ -241,6 +243,8 @@
 	req.nr_tx_slots   = ctx->nr_tx_slots;
 	req.nr_rx_slots   = ctx->nr_rx_slots;
 	req.nr_tx_rings   = ctx->nr_tx_rings;
+	req.nr_host_tx_rings = ctx->nr_host_tx_rings;
+	req.nr_host_rx_rings = ctx->nr_host_rx_rings;
 	req.nr_rx_rings   = ctx->nr_rx_rings;
 	req.nr_extra_bufs = ctx->nr_extra_bufs;
 	ret               = ioctl(ctx->fd, NIOCCTRL, &hdr);
@@ -254,23 +258,29 @@
 	printf("nr_rx_slots %u\n", req.nr_rx_slots);
 	printf("nr_tx_rings %u\n", req.nr_tx_rings);
 	printf("nr_rx_rings %u\n", req.nr_rx_rings);
+	printf("nr_host_tx_rings %u\n", req.nr_host_tx_rings);
+	printf("nr_host_rx_rings %u\n", req.nr_host_rx_rings);
 	printf("nr_mem_id %u\n", req.nr_mem_id);
 	printf("nr_extra_bufs %u\n", req.nr_extra_bufs);

 	success = req.nr_memsize && (ctx->nr_mode == req.nr_mode) &&
-	                       (ctx->nr_ringid == req.nr_ringid) &&
-	                       (ctx->nr_flags == req.nr_flags) &&
-	                       ((!ctx->nr_tx_slots && req.nr_tx_slots) ||
-	                        (ctx->nr_tx_slots == req.nr_tx_slots)) &&
-	                       ((!ctx->nr_rx_slots && req.nr_rx_slots) ||
-	                        (ctx->nr_rx_slots == req.nr_rx_slots)) &&
-	                       ((!ctx->nr_tx_rings && req.nr_tx_rings) ||
-	                        (ctx->nr_tx_rings == req.nr_tx_rings)) &&
-	                       ((!ctx->nr_rx_rings && req.nr_rx_rings) ||
-	                        (ctx->nr_rx_rings == req.nr_rx_rings)) &&
-	                       ((!ctx->nr_mem_id && req.nr_mem_id) ||
-	                        (ctx->nr_mem_id == req.nr_mem_id)) &&
-	                       (ctx->nr_extra_bufs == req.nr_extra_bufs);
+		       (ctx->nr_ringid == req.nr_ringid) &&
+		       (ctx->nr_flags == req.nr_flags) &&
+		       ((!ctx->nr_tx_slots && req.nr_tx_slots) ||
+			(ctx->nr_tx_slots == req.nr_tx_slots)) &&
+		       ((!ctx->nr_rx_slots && req.nr_rx_slots) ||
+			(ctx->nr_rx_slots == req.nr_rx_slots)) &&
+		       ((!ctx->nr_tx_rings && req.nr_tx_rings) ||
+			(ctx->nr_tx_rings == req.nr_tx_rings)) &&
+		       ((!ctx->nr_rx_rings && req.nr_rx_rings) ||
+			(ctx->nr_rx_rings == req.nr_rx_rings)) &&
+		       ((!ctx->nr_host_tx_rings && req.nr_host_tx_rings) ||
+			(ctx->nr_host_tx_rings == req.nr_host_tx_rings)) &&
+		       ((!ctx->nr_host_rx_rings && req.nr_host_rx_rings) ||
+			(ctx->nr_host_rx_rings == req.nr_host_rx_rings)) &&
+		       ((!ctx->nr_mem_id && req.nr_mem_id) ||
+			(ctx->nr_mem_id == req.nr_mem_id)) &&
+		       (ctx->nr_extra_bufs == req.nr_extra_bufs);
 	if (!success) {
 		return -1;
 	}
@@ -280,6 +290,8 @@
 	ctx->nr_rx_slots   = req.nr_rx_slots;
 	ctx->nr_tx_rings   = req.nr_tx_rings;
 	ctx->nr_rx_rings   = req.nr_rx_rings;
+	ctx->nr_host_tx_rings = req.nr_host_tx_rings;
+	ctx->nr_host_rx_rings = req.nr_host_rx_rings;
 	ctx->nr_mem_id     = req.nr_mem_id;
 	ctx->nr_extra_bufs = req.nr_extra_bufs;

@@ -447,7 +459,7 @@
 }

 static int
-port_register_host(struct TestContext *ctx)
+port_register_hostall(struct TestContext *ctx)
 {
 	ctx->nr_mode = NR_REG_SW;
 	return port_register(ctx);
@@ -461,10 +473,29 @@
 }

 static int
-port_register_single_ring_couple(struct TestContext *ctx)
+port_register_single_hw_pair(struct TestContext *ctx)
 {
 	ctx->nr_mode   = NR_REG_ONE_NIC;
 	ctx->nr_ringid = 0;
+	return port_register(ctx);
+}
+
+static int
+port_register_single_host_pair(struct TestContext *ctx)
+{
+	ctx->nr_mode   = NR_REG_ONE_SW;
+	ctx->nr_host_tx_rings = 2;
+	ctx->nr_host_rx_rings = 2;
+	ctx->nr_ringid = 1;
+	return port_register(ctx);
+}
+
+static int
+port_register_hostall_many(struct TestContext *ctx)
+{
+	ctx->nr_mode   = NR_REG_SW;
+	ctx->nr_host_tx_rings = 5;
+	ctx->nr_host_rx_rings = 4;
 	return port_register(ctx);
 }

@@ -1934,8 +1965,10 @@
 	decltest(port_info_get),
 	decltest(port_register_hwall_host),
 	decltest(port_register_hwall),
-	decltest(port_register_host),
-	decltest(port_register_single_ring_couple),
+	decltest(port_register_hostall),
+	decltest(port_register_single_hw_pair),
+	decltest(port_register_single_host_pair),
+	decltest(port_register_hostall_many),
 	decltest(vale_attach_detach),
 	decltest(vale_attach_detach_host_rings),
 	decltest(vale_ephemeral_port_hdr_manipulation),


utils: add test for nr_arg3 argument

utils: add test for nr_arg3 argument

--- utils/ctrl-api-test.c
+++ utils/ctrl-api-test.c
@@ -291,6 +291,27 @@
 	 * using an older kernel (with ABI 12 or higher) and a newer
 	 * application (with ABI greater than NETMAP_API). */
 	return niocregif(ctx, NETMAP_API+2);
+}
+
+static int
+legacy_regif_extra_bufs(struct TestContext *ctx)
+{
+	ctx->nr_mode = NR_REG_ALL_NIC;
+	ctx->nr_extra_bufs = 20;
+	return niocregif(ctx, NETMAP_API_NIOCREGIF);
+}
+
+static int
+legacy_regif_extra_bufs_pipe(struct TestContext *ctx)
+{
+	char pipe_name[128];
+
+	snprintf(pipe_name, sizeof(pipe_name), "%s{%s", ctx->ifname, "pipeexbuf");
+	ctx->ifname  = pipe_name;
+	ctx->nr_mode = NR_REG_ALL_NIC;
+	ctx->nr_extra_bufs = 20;
+
+	return niocregif(ctx, NETMAP_API_NIOCREGIF);
 }

 /* Only valid after a successful port_register(). */
@@ -1505,6 +1526,8 @@
 	decltest(legacy_regif_12),
 	decltest(legacy_regif_sw),
 	decltest(legacy_regif_future),
+	decltest(legacy_regif_extra_bufs),
+	decltest(legacy_regif_extra_bufs_pipe),
 };

 static void


driver_name_map: add nouveau and radeon for Mesa Gallium

This patch allows va_getDriverName to succeed.
It is useful in vaInitialize to select the vaapi
driver provided by Mesa Gallium:
lib/dri/gallium_drv_video.so

Signed-off-by: Julien Isorce <2904e845d63d102574cbb95a4bcdefac0a5d7af0@samsung.com>

--- va/drm/va_drm_utils.c
+++ va/drm/va_drm_utils.c
@@ -41,6 +41,8 @@
     { "pvrsrvkm",   8, "pvr"    }, // Intel UMG PVR driver
     { "emgd",       4, "emgd"   }, // Intel ECG PVR driver
     { "hybrid",     6, "hybrid" }, // Intel OTC Hybrid driver
+    { "nouveau",    7, "gallium" }, // Mesa Gallium driver
+    { "radeon",     6, "gallium" }, // Mesa Gallium driver
     { NULL, }
 };


remove duplicate struct entry

remove duplicate struct entry

--- conary/lib/streamset.c
+++ conary/lib/streamset.c
@@ -1005,7 +1005,6 @@
     { "find",   (PyCFunction) StreamSet_Find,   METH_VARARGS | METH_CLASS    },
     { "freeze", (PyCFunction) StreamSet_Freeze, METH_VARARGS | METH_KEYWORDS },
     { "thaw",   (PyCFunction) StreamSet_Thaw,   METH_VARARGS                 },
-    { "thaw",   (PyCFunction) StreamSet_Thaw,   METH_VARARGS                 },
     { "twm",    (PyCFunction) StreamSet_Twm,    METH_VARARGS | METH_KEYWORDS },
     {NULL}  /* Sentinel */
 };


typo and formatting adjustments for board definitions

--- V2X_Firmware/src/V2X/V2X_board.h
+++ V2X_Firmware/src/V2X/V2X_board.h
@@ -41,18 +41,18 @@
  * Activate to maintain power to CPU
  */
 #if V2X_REV >= REV_20
-#define PWR_3V3_PIN				  IOPORT_CREATE_PIN(PORTA, 4)
+#define PWR_3V3_PIN				  IOPORT_CREATE_PIN(PORTA,4)
 #define PWR_3V3_ACTIVE			  true
-#define PWR_3V3_INACTIVE		  !3V3_ACTIVE
+#define PWR_3V3_INACTIVE		  !PWR_3V3_ACTIVE
 #endif

 /** \name LED0 definitions
  *  net: SEQ_LED3 or "PWR" LED
  *  @{ */
-#if V2X_REV == REV_12
-	#define LED0_PIN                  IOPORT_CREATE_PIN(PORTB, 0)
-#elif V2X_REV >= REV_20
-#define LED0_PIN                  IOPORT_CREATE_PIN(PORTE, 2)
+#if V2X_REV <= REV_12
+#define LED0_PIN                  IOPORT_CREATE_PIN(PORTB,0)
+#elif V2X_REV >= REV_20
+#define LED0_PIN                  IOPORT_CREATE_PIN(PORTE,2)
 #endif
 #define LED0_ACTIVE               true
 #define LED0_INACTIVE             !LED0_ACTIVE
@@ -61,10 +61,10 @@
 /** \name LED1 definitions
  *  net: SEQ_LED1 or "M2M" LED
  *  @{ */
-#if V2X_REV == REV_12
-	#define LED1_PIN                  IOPORT_CREATE_PIN(PORTA, 6)
-#elif V2X_REV >= REV_20
-#define LED1_PIN                  IOPORT_CREATE_PIN(PORTE, 1)
+#if V2X_REV <= REV_12
+#define LED1_PIN                  IOPORT_CREATE_PIN(PORTA,6)
+#elif V2X_REV >= REV_20
+#define LED1_PIN                  IOPORT_CREATE_PIN(PORTE,1)
 #endif
 #define LED1_ACTIVE               true
 #define LED1_INACTIVE             !LED0_ACTIVE
@@ -73,10 +73,10 @@
 /** \name LED2 definitions
  *  net: SEQ_LED2 or "GPS" LED
  *  @{ */
-#if V2X_REV == REV_12
-	#define LED2_PIN                  IOPORT_CREATE_PIN(PORTA, 7)
-#elif V2X_REV >= REV_20
-#define LED2_PIN                  IOPORT_CREATE_PIN(PORTE, 3)
+#if V2X_REV <= REV_12
+#define LED2_PIN                  IOPORT_CREATE_PIN(PORTA,7)
+#elif V2X_REV >= REV_20
+#define LED2_PIN                  IOPORT_CREATE_PIN(PORTE,3)
 #endif
 #define LED2_ACTIVE               true
 #define LED2_INACTIVE             !LED0_ACTIVE
@@ -127,7 +127,7 @@

 /** \name SW0 definitions
  *  @{ */
-#define SW0_PIN                   IOPORT_CREATE_PIN(PORTA, 0)
+#define SW0_PIN                   IOPORT_CREATE_PIN(PORTA,0)
 #define SW0_ACTIVE                true
 #define SW0_INACTIVE              !SW0_ACTIVE
 /** @} */
@@ -146,7 +146,7 @@

 /** \name SW1 definitions
  *  @{ */
-#define SW1_PIN                   IOPORT_CREATE_PIN(PORTD, 5)
+#define SW1_PIN                   IOPORT_CREATE_PIN(PORTD,5)
 #define SW1_ACTIVE                FALSE
 #define SW1_INACTIVE              !SW1_ACTIVE
 /** @} */
@@ -184,7 +184,7 @@

 /** \name BUF0 definitions
  *  @{ */
-#define BUF0_PIN                   IOPORT_CREATE_PIN(PORTB, 2)
+#define BUF0_PIN                   IOPORT_CREATE_PIN(PORTB,2)
 #define BUF0_ACTIVE                true
 #define BUF0_INACTIVE              !BUF0_ACTIVE
 /** @} */
@@ -207,7 +207,7 @@

 /** \name BUF1 definitions
 *  @{ */
-#define BUF1_PIN                   IOPORT_CREATE_PIN(PORTB, 3)
+#define BUF1_PIN                   IOPORT_CREATE_PIN(PORTB,3)
 #define BUF1_ACTIVE                true
 #define BUF1_INACTIVE              !BUF1_ACTIVE
 /** @} */
@@ -220,7 +220,7 @@

 /** \name CP0 definitions
  *  @{ */
-#define CP0_PIN                   IOPORT_CREATE_PIN(PORTA, 1)
+#define CP0_PIN                   IOPORT_CREATE_PIN(PORTA,1)
 #define CP0_ACTIVE                true
 #define CP0_INACTIVE              !CP0_ACTIVE
 /** @} */
@@ -257,8 +257,8 @@
 #define EXT1_PIN_HUB_STATUS                IOPORT_CREATE_PIN(PORTA,4)
 #define EXT1_PIN_HUB_SUSPEND               IOPORT_CREATE_PIN(PORTA,5)
 /* DELETEME: HUB_STATUS unnecessary without FTDI in the mix */
+#endif
 #define EXT1_PIN_HUB_STATUS                IOPORT_CREATE_PIN(PORTA,3)
-#endif
 #define EXT1_PIN_HOST_SHORT_CIRCUIT        IOPORT_CREATE_PIN(PORTB,1)
 #define EXT1_PIN_SR_CLEAR                  IOPORT_CREATE_PIN(PORTC,0)
 #define EXT1_PIN_SR_LATCH                  IOPORT_CREATE_PIN(PORTC,1)
@@ -283,6 +283,7 @@
 #define EXT1_PIN_SIM_PWR                   IOPORT_CREATE_PIN(PORTD,4)
 #define EXT1_PIN_SEQ_RXD                   IOPORT_CREATE_PIN(PORTD,6) //RX SIGNAL (PORT D RXD1) FROM FTDI MODULE FOR SEQ AT INTERFACE, ALSO USB DM
 #define EXT1_PIN_SEQ_TXD                   IOPORT_CREATE_PIN(PORTD,7) //TX SIGNAL (PORT D TXD1) TO FTDI MODULE FOR SEQ AT INTERFACE, ALSO USB DP
+/* FIXME: Add definition for HUB_PWR_PRT1 pin, on PORTA,3 ?? */
 /** @} */

 /* FIXME: Is the following TWI definition incorrect, or irrelevant?


Updated Example File

Updated Example File

--- Examples/SinglyLinkedLists_example.c
+++ Examples/SinglyLinkedLists_example.c
@@ -1,13 +1,60 @@
-//
-// Created by ronnymajani on 16.04.2017.
-//
 #include <stdio.h>
 #include "Data Structures/Linked Lists/SinglyLinkedList.h"

-ds_sll_func_return_t printElement(void* element,  ds_sll_node_t* node, int index, void* extra) {
+/* Example Executable Functions */
+ds_sll_func_return_t printElement(void* element, ds_sll_node_t* node, int index, void* extra) {
     printf("%d >> %d\n", index, *((int*)element));
     return DS_SLL_CONTINUE_EXECUTION;
 }
+
+/* Stores the maximum int in `maxElement` */
+ds_sll_func_return_t getMaxElement(void* element, ds_sll_node_t* node, int index, void* maxElement) {
+    if(element == NULL) {
+        return DS_SLL_CONTINUE_EXECUTION;
+    }
+    else if(maxElement == NULL) {
+        *(int*)maxElement = *(int*)element;
+    } else if(*(int*)element > *(int*)maxElement) {
+        *(int*)maxElement = *(int*)element;
+    }
+    return DS_SLL_CONTINUE_EXECUTION;
+}
+
+/* Sets maxNode to point to the node containing the maximum element */
+ds_sll_func_return_t maxNode(void* element, ds_sll_node_t* node, int index, void* maxNode) {
+    // maxNode is a pointer to a pointer to a ds_sll_node_t
+    ds_sll_node_t **maximum_node_p = (ds_sll_node_t**)maxNode;
+    if(element == NULL) {
+        return DS_SLL_CONTINUE_EXECUTION;
+    }
+    else if(*maximum_node_p == NULL) {
+        *maximum_node_p = node;
+    } else if(*(int*)element > *(int*)ds_sll_extractElementFromNode(*maximum_node_p)) {
+        *(ds_sll_node_t**)maxNode = node;
+    }
+    return DS_SLL_CONTINUE_EXECUTION;
+}
+
+typedef struct findNodeFuncParams {
+    int input;
+    int output_index;
+    ds_sll_node_t* output_node;
+} findNodeFuncParams;
+
+/* finds the node containing the given element (params->input) and stores a pointer to that node in params->output */
+ds_sll_func_return_t findNode(void* element, ds_sll_node_t* node, int index, void* shared) {
+    findNodeFuncParams* params = (findNodeFuncParams*)shared;
+
+    if(params->input == *(int*)element) {
+        params->output_index = index;
+        params->output_node = node;
+        return DS_SLL_STOP_EXECUTION;
+    } else {
+        return DS_SLL_CONTINUE_EXECUTION;
+    }
+}
+
+

 int equals(void* elem1, void* elem2) {
     return *((int*)elem1) == *((int*)elem2);
@@ -72,6 +119,29 @@
     node = ds_sll_findNodeContainingElement(mylist, NULL, equals, &index);
     printf("element %d also found at index %d <%d>\n\n", x, index, *((int*)node->element));

+    /* Test Executable Functions */
+    printf("---------------\n\n");
+    // example of getMaxElement
+    int *max_element = (int*)malloc(sizeof(int));
+    ds_sll_executeFunctionOnElements(mylist, getMaxElement, (void*)max_element);
+    printf("Max Element in list: %d\n", *max_element);
+    free(max_element);
+
+    // example of maxNode
+    ds_sll_node_t* max_node = NULL;
+    ds_sll_executeFunctionOnElements(mylist, maxNode, (void*)&max_node);
+    int* max_node_element = (int*)ds_sll_extractElementFromNode(max_node);
+    printf("Max Element in Max Node is: %d\n", *max_node_element);
+
+    // example of findNode
+    findNodeFuncParams* params = (findNodeFuncParams*) malloc(sizeof(findNodeFuncParams));
+    params->input = 77;
+    ds_sll_executeFunctionOnElements(mylist, findNode, (void*)params);
+    printf("Node containing element (%d) is located at index %d\n", params->input, params->output_index);
+    free(params);
+    printf("\n---------------\n\n");
+
+    /* Split Linked List */
     ds_sll_splitSinglyLinkedListAtIndex(mylist, newlist, 3);
     printf("split list at index %d\n", 3);


Fixed more leaks found by the Clang Static Analyzer.

--- Extras/HardwareGrowler/USBNotifier.c
+++ Extras/HardwareGrowler/USBNotifier.c
@@ -34,18 +34,20 @@
 			CFStringRef deviceName = CFStringCreateWithCString(kCFAllocatorDefault,
 															   deviceNameChars,
 															   kCFStringEncodingASCII);
-			if ((CFStringCompare(deviceName, CFSTR("OHCI Root Hub Simulation"), 0) == kCFCompareEqualTo) ||
-				(CFStringCompare(deviceName, CFSTR("UHCI Root Hub Simulation"), 0) == kCFCompareEqualTo)) {
+			if (deviceName) {
+				if ((CFStringCompare(deviceName, CFSTR("OHCI Root Hub Simulation"), 0) == kCFCompareEqualTo) ||
+					(CFStringCompare(deviceName, CFSTR("UHCI Root Hub Simulation"), 0) == kCFCompareEqualTo)) {
+					CFRelease(deviceName);
+					deviceName = CFCopyLocalizedString(CFSTR("USB Bus"), "");
+				} else if (CFStringCompare(deviceName, CFSTR("EHCI Root Hub Simulation"), 0) == kCFCompareEqualTo) {
+					CFRelease(deviceName);
+					deviceName = CFCopyLocalizedString(CFSTR("USB 2.0 Bus"), "");
+				}
+
+				// NSLog(@"USB Device Attached: %@" , deviceName);
+				AppController_usbDidConnect(deviceName);
 				CFRelease(deviceName);
-				deviceName = CFCopyLocalizedString(CFSTR("USB Bus"), "");
-			} else if (CFStringCompare(deviceName, CFSTR("EHCI Root Hub Simulation"), 0) == kCFCompareEqualTo) {
-				CFRelease(deviceName);
-				deviceName = CFCopyLocalizedString(CFSTR("USB 2.0 Bus"), "");
 			}
-
-			// NSLog(@"USB Device Attached: %@" , deviceName);
-			AppController_usbDidConnect(deviceName);
-			CFRelease(deviceName);
 		}

 		IOObjectRelease(thisObject);
@@ -71,14 +73,19 @@
 		CFStringRef deviceName = CFStringCreateWithCString(kCFAllocatorDefault,
 														   deviceNameChars,
 														   kCFStringEncodingASCII);
-		if (CFStringCompare(deviceName, CFSTR("OHCI Root Hub Simulation"), 0) == kCFCompareEqualTo)
-			deviceName = CFCopyLocalizedString(CFSTR("USB Bus"), "");
-		else if (CFStringCompare(deviceName, CFSTR("EHCI Root Hub Simulation"), 0) == kCFCompareEqualTo)
-			deviceName = CFCopyLocalizedString(CFSTR("USB 2.0 Bus"), "");
+		if (deviceName) {
+			if (CFStringCompare(deviceName, CFSTR("OHCI Root Hub Simulation"), 0) == kCFCompareEqualTo) {
+				CFRelease(deviceName);
+				deviceName = CFCopyLocalizedString(CFSTR("USB Bus"), "");
+			} else if (CFStringCompare(deviceName, CFSTR("EHCI Root Hub Simulation"), 0) == kCFCompareEqualTo) {
+				CFRelease(deviceName);
+				deviceName = CFCopyLocalizedString(CFSTR("USB 2.0 Bus"), "");
+			}

-		// NSLog(@"USB Device Detached: %@" , deviceName);
-		AppController_usbDidDisconnect(deviceName);
-		CFRelease(deviceName);
+			// NSLog(@"USB Device Detached: %@" , deviceName);
+			AppController_usbDidDisconnect(deviceName);
+			CFRelease(deviceName);
+		}

 		IOObjectRelease(thisObject);
 	}


Revision for the comparison by ID

Revision for the comparison by ID

--- plugins/berhasil1June2/class/node.c
+++ plugins/berhasil1June2/class/node.c
@@ -258,7 +258,7 @@
 					  } else
 						  next_table=x+5;
 	        	  } else
-	        		  next_table=1;
+	        		  next_table=x+1;
 	          } else if ((table_index0-x)<=4 && (table_index0-x)>0) {
 	        	  if (e0->dst==0){
 	        		  if (e0->proto==0) {


Correct comments referencing old names

Correct comments referencing old names

--- bounds/ray-intersects.98.c
+++ bounds/ray-intersects.98.c
@@ -57,7 +57,8 @@
     * 1. Realize that the set of points which can actually be reached with a
     *    given delta is limited to some points near the edge of the box: if the
     *    delta is (1,0), only the leftmost edge of the box can be touched, and
-    *    thus only they need to be checked. (See the getBegEnd() helper.)
+    *    thus only they need to be checked. (See the get_hittable_range()
+    *    helper.)
     *
     *    The number of different (coordinate, move count) pairs that we have to
     *    check in this approach is:
@@ -393,8 +394,8 @@
    if (!best_move_count)
       return count;

-   // We have a bestMoves to stay under: reduce count to ensure that we do stay
-   // under it.
+   // We have a best_move_count to stay under: reduce count to ensure that we
+   // do stay under it.

    // Time for another binary search.
    for (mushucell low = 0, high = count;;) {


Fix order of cleanup argument vs expected

--- src/cc1/ops/stmt_code.c
+++ src/cc1/ops/stmt_code.c
@@ -37,8 +37,8 @@
 		return;
 	}

-	targ = args->arglist[0]->ref;
-	expected = type_ptr_to(d->ref);
+	expected = args->arglist[0]->ref;
+	targ = type_ptr_to(d->ref);
 	if(!(type_cmp(targ, expected, 0) & TYPE_EQUAL_ANY)){
 		char targ_buf[TYPE_STATIC_BUFSIZ];
 		char expected_buf[TYPE_STATIC_BUFSIZ];


Possible destroyed mutex fix

Possible destroyed mutex fix

--- bsp/include/bsp/bspClass.h
+++ bsp/include/bsp/bspClass.h
@@ -417,6 +417,14 @@

         if (ProcId() == 0)
         {
+            for (auto &thr : mThreads)
+            {
+                if (thr.valid())
+                {
+                    thr.get();
+                }
+            }
+
             mThreads.clear();

             mProcCount = 0;


memcmp does not accurately determine whether two keys are the same.  Take out the overactive assertion.  Addresses #788, #789.

git-svn-id: 4b2652e19d8125fd9d24eff55f31fd1beb5a42e7@3980 c7de825b-a66e-492c-adef-691d508d4ae1

--- newbrt/brt.c
+++ newbrt/brt.c
@@ -1125,8 +1125,8 @@
 				      u_int32_t dlen, void *dval,
 				      BRT_CMD cmd,
 				      u_int32_t *newlen, u_int32_t *disksize, LEAFENTRY *new_data) {
-    assert(cmd->u.id.key->size == klen);
-    assert(memcmp(cmd->u.id.key->data, kval, klen)==0);
+    //assert(cmd->u.id.key->size == klen);
+    //assert(memcmp(cmd->u.id.key->data, kval, klen)==0);
     switch (cmd->type) {
     case BRT_INSERT:
 	return le_both(cmd->xid,
@@ -1169,8 +1169,8 @@
 	prev_len = plen;  prev_val = pval;
     }
     // keep the committed value for rollback.
-    assert(cmd->u.id.key->size == klen);
-    assert(memcmp(cmd->u.id.key->data, kval, klen)==0);
+    //assert(cmd->u.id.key->size == klen);
+    //assert(memcmp(cmd->u.id.key->data, kval, klen)==0);
     switch (cmd->type) {
     case BRT_INSERT:
 	return le_both(cmd->xid,
@@ -1208,8 +1208,8 @@
 				    BRT_CMD cmd,
 				    u_int32_t *newlen, u_int32_t *disksize, LEAFENTRY *new_data) {
     // keep the committed value for rollback
-    assert(cmd->u.id.key->size == klen);
-    assert(memcmp(cmd->u.id.key->data, kval, klen)==0);
+    //assert(cmd->u.id.key->size == klen);
+    //assert(memcmp(cmd->u.id.key->data, kval, klen)==0);
     switch (cmd->type) {
     case BRT_INSERT:
 	if (cmd->xid == xid) {
@@ -1260,8 +1260,8 @@
 				     u_int32_t plen , void *pval,
 				     BRT_CMD cmd,
 				     u_int32_t *newlen, u_int32_t *disksize, LEAFENTRY *new_data) {
-    assert(cmd->u.id.key->size == klen);
-    assert(memcmp(cmd->u.id.key->data, kval, klen)==0);
+    //assert(cmd->u.id.key->size == klen);
+    //assert(memcmp(cmd->u.id.key->data, kval, klen)==0);
     switch (cmd->type) {
     case BRT_INSERT:
 	if (cmd->xid == xid) {


Addresses #855, #856.  More 0s become NULLs.  toku_omt_cursor_prev checks for index = 0
so that it can invalidate and return EINVAL (since index is unsigned)

git-svn-id: 4b2652e19d8125fd9d24eff55f31fd1beb5a42e7@4336 c7de825b-a66e-492c-adef-691d508d4ae1

--- newbrt/omt.c
+++ newbrt/omt.c
@@ -71,7 +71,7 @@

 int toku_omt_cursor_create (OMTCURSOR *omtcp) {
     OMTCURSOR MALLOC(c);
-    if (c==0) return errno;
+    if (c==NULL) return errno;
     c->omt = NULL;
     c->next = c->prev = NULL;
     *omtcp = c;
@@ -497,7 +497,7 @@

 int toku_omt_find_zero(OMT V, int (*h)(OMTVALUE, void*extra), void*extra, OMTVALUE *value, u_int32_t *index, OMTCURSOR c) {
     u_int32_t tmp_index;
-    if (index==0) index=&tmp_index;
+    if (index==NULL) index=&tmp_index;
     int r = find_internal_zero(V, V->root, h, extra, value, index);
     if (c && r==0) {
 	associate(V,c);
@@ -554,7 +554,7 @@
 int toku_omt_find(OMT V, int (*h)(OMTVALUE, void*extra), void*extra, int direction, OMTVALUE *value, u_int32_t *index, OMTCURSOR c) {
     u_int32_t tmp_index;
     int r;
-    if (index==0) index=&tmp_index;
+    if (index==NULL) index=&tmp_index;
     if (direction==0) {
 	abort();
     } else if (direction<0) {
@@ -637,22 +637,27 @@
 int toku_omt_cursor_next (OMTCURSOR c, OMTVALUE *v) {
     if (c->omt == NULL) return EINVAL;
     c->index++;
-    int r = toku_omt_fetch(c->omt, c->index, v, 0);
+    int r = toku_omt_fetch(c->omt, c->index, v, NULL);
     if (r!=0) toku_omt_cursor_invalidate(c);
     return r;
 }

 int toku_omt_cursor_prev (OMTCURSOR c, OMTVALUE *v) {
     if (c->omt == NULL) return EINVAL;
+    if (c->index==0) {
+       toku_omt_cursor_invalidate(c);
+       return EINVAL;
+    }
     c->index--;
-    int r = toku_omt_fetch(c->omt, c->index, v, 0);
+    int r = toku_omt_fetch(c->omt, c->index, v, NULL);
     if (r!=0) toku_omt_cursor_invalidate(c);
     return r;
 }

 int toku_omt_cursor_current (OMTCURSOR c, OMTVALUE *v) {
     if (c->omt == NULL) return EINVAL;
-    int r = toku_omt_fetch(c->omt, c->index, v, 0);
+    int r = toku_omt_fetch(c->omt, c->index, v, NULL);
     if (r!=0) toku_omt_cursor_invalidate(c);
     return r;
 }
+


Pack the enum?

Pack the enum?

--- lib/facil/core/types/fiobj/fiobject.h
+++ lib/facil/core/types/fiobj/fiobject.h
@@ -23,6 +23,10 @@

 #include "fio_siphash.h"

+#if !defined(__GNUC__)
+#define __attribute__(x) /* :-( */
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -31,7 +35,7 @@
 Core Types
 ***************************************************************************** */

-typedef enum fiobj_type_enum {
+typedef enum __attribute__((packed)) {
   FIOBJ_T_NUMBER = 0x01,
   FIOBJ_T_NULL = 0x06,
   FIOBJ_T_TRUE = 0x16,


use TAGMALLOC again

use TAGMALLOC again

git-svn-id: 4b2652e19d8125fd9d24eff55f31fd1beb5a42e7@92 c7de825b-a66e-492c-adef-691d508d4ae1

--- newbrt/pma.c
+++ newbrt/pma.c
@@ -304,10 +304,8 @@
 }

 int pma_create (PMA *pma, int (*compare_fun)(DB*,const DBT*,const DBT*)) {
-    struct pma *result;
     int error;
-
-    result = toku_malloc(sizeof (struct pma));
+    TAGMALLOC(PMA, result);
     if (result==0) return -1;
     result->n_pairs_present = 0;
     result->pairs = 0;


out_datadog: fix variable declaration and codestyle

Signed-off-by: Eduardo Silva <81f705dc2ce1a61a2621e0e4b442a9474e1d0c70@treasure-data.com>

--- plugins/out_datadog/datadog_remap.c
+++ plugins/out_datadog/datadog_remap.c
@@ -25,11 +25,12 @@
 #include "datadog.h"
 #include "datadog_remap.h"

-const char* ECS_ARN_PREFIX = "arn:aws:ecs:";
-const char* ECS_CLUSTER_PREFIX = "cluster/";
-const char* ECS_TASK_PREFIX = "task/";
+const char *ECS_ARN_PREFIX = "arn:aws:ecs:";
+const char *ECS_CLUSTER_PREFIX = "cluster/";
+const char *ECS_TASK_PREFIX = "task/";

-static void dd_remap_append_kv_to_ddtags(const char* key, const char* val, size_t val_len, flb_sds_t dd_tags)
+static void dd_remap_append_kv_to_ddtags(const char *key,
+                                         const char *val, size_t val_len, flb_sds_t dd_tags)
 {
     if (flb_sds_len(dd_tags) != 0) {
         flb_sds_cat(dd_tags, FLB_DATADOG_TAG_SEPERATOR, strlen(FLB_DATADOG_TAG_SEPERATOR));
@@ -40,86 +41,124 @@
 }

 /* default remapping: just move the key/val pair under dd_tags */
-static void dd_remap_move_to_tags(const char* tag_name, msgpack_object attr_value, flb_sds_t dd_tags)
+static void dd_remap_move_to_tags(const char *tag_name,
+                                  msgpack_object attr_value, flb_sds_t dd_tags)
 {
-    dd_remap_append_kv_to_ddtags(tag_name, attr_value.via.str.ptr, attr_value.via.str.size, dd_tags);
+    dd_remap_append_kv_to_ddtags(tag_name, attr_value.via.str.ptr,
+                                 attr_value.via.str.size, dd_tags);
 }

 /* remapping function for container_name */
-static void dd_remap_container_name(const char* tag_name, msgpack_object attr_value, flb_sds_t dd_tags)
+static void dd_remap_container_name(const char *tag_name,
+                                    msgpack_object attr_value, flb_sds_t dd_tags)
 {
     /* remove the first / if present */
-    unsigned int adjust = attr_value.via.str.ptr[0] == '/' ? 1 : 0;
-    flb_sds_t buf = flb_sds_create_len(attr_value.via.str.ptr + adjust, attr_value.via.str.size - adjust);
+    unsigned int adjust;
+    flb_sds_t buf;
+
+    adjust = attr_value.via.str.ptr[0] == '/' ? 1 : 0;
+    buf = flb_sds_create_len(attr_value.via.str.ptr + adjust,
+                             attr_value.via.str.size - adjust);
     dd_remap_append_kv_to_ddtags(tag_name, buf, strlen(buf), dd_tags);
     flb_sds_destroy(buf);
 }

 /* remapping function for ecs_cluster */
-static void dd_remap_ecs_cluster(const char* tag_name, msgpack_object attr_value, flb_sds_t dd_tags)
+static void dd_remap_ecs_cluster(const char *tag_name,
+                                 msgpack_object attr_value, flb_sds_t dd_tags)
 {
-    flb_sds_t buf = flb_sds_create_len(attr_value.via.str.ptr, attr_value.via.str.size);
-    char* cluster_name = strstr(buf, ECS_CLUSTER_PREFIX);
+    flb_sds_t buf;
+    char *cluster_name;
+
+    buf = flb_sds_create_len(attr_value.via.str.ptr, attr_value.via.str.size);
+    cluster_name = strstr(buf, ECS_CLUSTER_PREFIX);
+
     if (cluster_name != NULL) {
         cluster_name += strlen(ECS_CLUSTER_PREFIX);
         dd_remap_append_kv_to_ddtags(tag_name, cluster_name, strlen(cluster_name), dd_tags);
     }
     else {
-        /* here the input is invalid: not in form of "XXXXXXcluster/"cluster-name
-           we preverse the original value under tag "cluster_name" */
+        /*
+         * here the input is invalid: not in form of "XXXXXXcluster/"cluster-name
+         * we preverse the original value under tag "cluster_name".
+         */
         dd_remap_append_kv_to_ddtags(tag_name, buf, strlen(buf), dd_tags);
     }
     flb_sds_destroy(buf);
 }

 /* remapping function for ecs_task_definition */
-static void dd_remap_ecs_task_definition(const char* tag_name, msgpack_object attr_value, flb_sds_t dd_tags)
+static void dd_remap_ecs_task_definition(const char *tag_name,
+                                         msgpack_object attr_value, flb_sds_t dd_tags)
 {
-    flb_sds_t buf = flb_sds_create_len(attr_value.via.str.ptr, attr_value.via.str.size);
-    char* split = strchr(buf, ':');
+    flb_sds_t buf;
+    char *split;
+
+    buf = flb_sds_create_len(attr_value.via.str.ptr, attr_value.via.str.size);
+    split = strchr(buf, ':');
+
     if (split != NULL) {
         dd_remap_append_kv_to_ddtags("task_family", buf, split-buf, dd_tags);
         dd_remap_append_kv_to_ddtags("task_version", split+1, strlen(split+1), dd_tags);
     }
     else {
-        /* here the input is invalid: not in form of task_name:task_version
-           we preverse the original value under tag "ecs_task_definition" */
+        /*
+         * here the input is invalid: not in form of task_name:task_version
+         * we preverse the original value under tag "ecs_task_definition".
+         */
         dd_remap_append_kv_to_ddtags(tag_name, buf, strlen(buf), dd_tags);
     }
     flb_sds_destroy(buf);
 }

 /* remapping function for ecs_task_arn */
-static void dd_remap_ecs_task_arn(const char* tag_name, msgpack_object attr_value, flb_sds_t dd_tags)
+static void dd_remap_ecs_task_arn(const char *tag_name,
+                                  msgpack_object attr_value, flb_sds_t dd_tags)
 {
-    flb_sds_t buf = flb_sds_create_len(attr_value.via.str.ptr, attr_value.via.str.size);
-    /* if the input is invalid, not in the form of "arn:aws:ecs:region:XXXX"
-       then we won't add the "region" in the dd_tags. */
-    if ((strlen(buf) > strlen(ECS_ARN_PREFIX)) &&  (strncmp(buf, ECS_ARN_PREFIX, strlen(ECS_ARN_PREFIX)) == 0)) {
-        char * remain = buf + strlen(ECS_ARN_PREFIX);
-        char* split = strchr(remain, ':');
+    flb_sds_t buf;
+    char *remain;
+    char *split;
+    char *task_arn;
+
+    buf = flb_sds_create_len(attr_value.via.str.ptr, attr_value.via.str.size);
+
+    /*
+     * if the input is invalid, not in the form of "arn:aws:ecs:region:XXXX"
+     * then we won't add the "region" in the dd_tags.
+     */
+    if ((strlen(buf) > strlen(ECS_ARN_PREFIX)) &&
+        (strncmp(buf, ECS_ARN_PREFIX, strlen(ECS_ARN_PREFIX)) == 0)) {
+
+        remain = buf + strlen(ECS_ARN_PREFIX);
+        split = strchr(remain, ':');
+
         if (split != NULL) {
             dd_remap_append_kv_to_ddtags("region", remain, split-remain, dd_tags);
         }
     }
-    char* task_arn = strstr(buf, ECS_TASK_PREFIX);
+
+    task_arn = strstr(buf, ECS_TASK_PREFIX);
     if (task_arn != NULL) {
         /* parse out the task_arn */
         task_arn += strlen(ECS_TASK_PREFIX);
         dd_remap_append_kv_to_ddtags(tag_name, task_arn, strlen(task_arn), dd_tags);
     }
     else {
-        /* if the input is invalid, not in the form of "XXXXXXXXtask/"task-arn
-           then we preverse the original value under tag "task_arn" */
+        /*
+         * if the input is invalid, not in the form of "XXXXXXXXtask/"task-arn
+         * then we preverse the original value under tag "task_arn".
+         */
         dd_remap_append_kv_to_ddtags(tag_name, buf, strlen(buf), dd_tags);
     }
     flb_sds_destroy(buf);
 }

-/* Statically defines the set of remappings rules in the form of
-   1) original attr name 2) remapped tag name 3) remapping functions
-   The remapping functions assume the input is valid, and will always
-   produce one or more tags to be added in dd_tags */
+/*
+ * Statically defines the set of remappings rules in the form of
+ * 1) original attr name 2) remapped tag name 3) remapping functions
+ * The remapping functions assume the input is valid, and will always
+ * produce one or more tags to be added in dd_tags.
+ */
 const struct dd_attr_tag_remapping remapping[] = {
     {"container_id", "container_id", dd_remap_move_to_tags},
     {"container_name", "container_name", dd_remap_container_name},
@@ -129,21 +168,28 @@
     {"ecs_task_arn", "task_arn", dd_remap_ecs_task_arn}
 };

-/* check against dd_attr_tag_remapping to see if a given attributes key/val
-   pair need remapping. The key has to match origin_attr_name, and the val
-   has to be of type string and non-empty.
-   return value is the index of the remapping rule in dd_attr_tag_remapping,
-   or -1 if no need to remap */
+/*
+ * Check against dd_attr_tag_remapping to see if a given attributes key/val
+ * pair need remapping. The key has to match origin_attr_name, and the val
+ * has to be of type string and non-empty.
+ * return value is the index of the remapping rule in dd_attr_tag_remapping,
+ * or -1 if no need to remap
+ */
 int dd_attr_need_remapping(const msgpack_object key, const msgpack_object val)
 {
+    int i;
+
     if ((val.type != MSGPACK_OBJECT_STR) || (val.via.str.size == 0)) {
         return -1;
     }
-    for (int i = 0; i < sizeof(remapping)/sizeof(struct dd_attr_tag_remapping); i++) {
+
+    for (i = 0; i < sizeof(remapping) / sizeof(struct dd_attr_tag_remapping); i++) {
         if ((key.via.str.size == strlen(remapping[i].origin_attr_name) &&
-            memcmp(key.via.str.ptr, remapping[i].origin_attr_name, key.via.str.size) == 0)) {
+             memcmp(key.via.str.ptr,
+                    remapping[i].origin_attr_name, key.via.str.size) == 0)) {
             return i;
         }
     }
+
     return -1;
 }


escape_filename: if the number of unacceptable characters is zero then simply duplicate the filename.

Signed-off-by: Jonny Lamb <3d1fb3642aaab2ff70e3392a5ab916bf99eed6a3@collabora.co.uk>

--- lib/gibber/gibber-oob-file-transfer.c
+++ lib/gibber/gibber-oob-file-transfer.c
@@ -757,6 +757,9 @@
         unacceptable++;
     }

+  if (unacceptable == 0)
+    return g_strdup (unescaped);
+
   result = g_malloc (p - unescaped + unacceptable * 2 + 1);

   for (q = result, p = unescaped; *p != '\0'; p++)


Allow privileged code to upgrade the system to prepare for Verb migration

--- mud/home/System/initd.c
+++ mud/home/System/initd.c
@@ -457,7 +457,7 @@
 /* called differently in 0.59 */
 void upgrade_system()
 {
-	ACCESS_CHECK(VERB());
+	ACCESS_CHECK(VERB() || INTERFACE() || KADMIN());

 	/* check to make sure current version is ready */
 	upgrade_check_ready();


create_transfer_offer: add brackets around IPv6 address

--- lib/gibber/gibber-oob-file-transfer.c
+++ lib/gibber/gibber-oob-file-transfer.c
@@ -425,6 +425,7 @@
   gchar host_name[NI_MAXHOST];
   struct sockaddr_storage name_addr;
   socklen_t name_addr_len = sizeof (name_addr);
+  gchar *host_escaped;

   GibberXmppStanza *stanza;
   GibberXmppNode *query_node;
@@ -451,12 +452,23 @@
   getnameinfo ((struct sockaddr *) &name_addr, name_addr_len, host_name,
       sizeof (host_name), NULL, 0, NI_NUMERICHOST);

+  if (name_addr.ss_family == AF_INET6)
+    {
+      /* put brackets around the IP6 */
+      host_escaped = g_strdup_printf("[%s]", host_name);
+    }
+  else
+    {
+      /* IPv4: No need to modify the host_name */
+      host_escaped = g_strdup (host_name);
+    }
+
   filename_escaped = g_uri_escape_string (GIBBER_FILE_TRANSFER (self)->filename,
       NULL, FALSE);
-  /* FIXME: this won't work with IPv6 address */
-  url = g_strdup_printf ("http://%s:%d/%s/%s", host_name,
+  url = g_strdup_printf ("http://%s:%d/%s/%s", host_escaped,
       soup_server_get_port (self->priv->server),
       GIBBER_FILE_TRANSFER (self)->id, filename_escaped);
+  g_free (host_escaped);
   g_free (filename_escaped);
   served_name = g_strdup_printf ("/%s/%s", GIBBER_FILE_TRANSFER (self)->id,
       GIBBER_FILE_TRANSFER (self)->filename);