Removing unexisting function prototypes

Removing unexisting function prototypes

--- firmware/a_v4.h
+++ firmware/a_v4.h
@@ -18,8 +18,5 @@
 };

 void xmitCodeElement(uint16_t ontime, uint16_t offtime, uint8_t PWM_code );
-void flashslowLEDx( uint8_t num_blinks );
-void quickflashLEDx( uint8_t x );
 void tvbgone_sleep( void );
 void delay_ten_us(uint16_t us);
-void quickflashLED( void );


Introduce changes proposed in PR

Introduce changes proposed in PR

--- tree_sitter/binding.c
+++ tree_sitter/binding.c
@@ -1,7 +1,6 @@
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
 #include <wctype.h>
-#include <regex.h>
 #include "tree_sitter/api.h"

 // Types
@@ -41,14 +40,14 @@
 typedef struct {
   PyObject_HEAD;
   uint32_t capture_value_id;
-  const char *string_value;
+  PyObject *string_value;
   int is_positive;
 } CaptureEqString;

 typedef struct {
   PyObject_HEAD;
   uint32_t capture_value_id;
-  regex_t regex;
+  PyObject *regex;
   int is_positive;
 } CaptureMatchString;

@@ -56,7 +55,6 @@
   PyObject_HEAD
   TSQuery *query;
   PyObject *capture_names;
-  PyObject *string_values;
   PyObject *text_predicates;
 } Query;

@@ -67,6 +65,7 @@

 static TSTreeCursor default_cursor = {0};
 static TSQueryCursor *query_cursor = NULL;
+static PyObject *re_module = NULL;

 // Point

@@ -799,11 +798,12 @@
 }

 static void capture_eq_string_dealloc(CaptureEqString *self) {
+  Py_XDECREF(self->string_value);
   Py_TYPE(self)->tp_free(self);
 }

 static void capture_match_string_dealloc(CaptureMatchString *self) {
-  regfree(&self->regex);
+  Py_XDECREF(self->regex);
   Py_TYPE(self)->tp_free(self);
 }

@@ -847,26 +847,27 @@
   return (PyObject *)self;
 }

-static PyObject *capture_eq_string_new_internal(uint32_t capture_value_id, const char *string_value, int is_positive) {
+static PyObject *capture_eq_string_new_internal(uint32_t capture_value_id, const char* string_value, int is_positive) {
   CaptureEqString *self = (CaptureEqString *)capture_eq_string_type.tp_alloc(&capture_eq_string_type, 0);
   if (self != NULL) {
     self->capture_value_id = capture_value_id;
-    self->string_value = string_value;
+    self->string_value = PyBytes_FromString(string_value);
     self->is_positive = is_positive;
   }
   return (PyObject *)self;
 }

 static PyObject *capture_match_string_new_internal(uint32_t capture_value_id, const char *string_value, int is_positive) {
+  if (re_module == NULL)
+    re_module = PyImport_ImportModule("re");
   CaptureMatchString *self = (CaptureMatchString *)capture_match_string_type.tp_alloc(&capture_match_string_type, 0);
-  if (self != NULL) {
-    self->capture_value_id = capture_value_id;
-    if (regcomp(&self->regex, string_value, 0)) {
-      PyErr_SetString(PyExc_RuntimeError, "Failed to compile the regex");
-      return NULL;
-    }
-    self->is_positive = is_positive;
-  }
+  if (re_module == NULL || self == NULL)
+    return NULL;
+  self->capture_value_id = capture_value_id;
+  PyObject *re_compile = PyObject_GetAttrString(re_module,(char*)"compile");
+  self->regex = PyObject_CallFunction(re_compile, "s", string_value);
+  Py_DECREF(re_compile);
+  self->is_positive = is_positive;
   return (PyObject *)self;
 }

@@ -907,6 +908,11 @@
   if (tree->source == Py_None || tree->source == NULL) {
     return true;
   }
+
+  Node *node1 = NULL;
+  Node *node2 = NULL;
+  PyObject *node1_text = NULL;
+  PyObject *node2_text = NULL;
   // check if all text_predicates are satisfied
   for (Py_ssize_t j = 0; j < PyList_Size(pattern_text_predicates); j++) {
     PyObject *text_predicate = PyList_GetItem(pattern_text_predicates, j);
@@ -914,40 +920,64 @@
     if (capture_eq_capture_is_instance(text_predicate)) {
       uint32_t capture1_value_id = ((CaptureEqCapture *)text_predicate)->capture1_value_id;
       uint32_t capture2_value_id = ((CaptureEqCapture *)text_predicate)->capture2_value_id;
-      Node *node1 = node_for_capture_index(capture1_value_id, match, tree);
-      Node *node2 = node_for_capture_index(capture2_value_id, match, tree);
-      is_satisfied = PyObject_RichCompareBool(node_get_text(node1, NULL), node_get_text(node2, NULL), Py_EQ) == ((CaptureEqCapture *)text_predicate)->is_positive;
+      node1 = node_for_capture_index(capture1_value_id, match, tree);
+      node2 = node_for_capture_index(capture2_value_id, match, tree);
+      if (node1 == NULL || node2 == NULL)
+        goto error;
+      node1_text = node_get_text(node1, NULL);
+      node2_text = node_get_text(node2, NULL);
+      if (node1_text == NULL || node2_text == NULL)
+        goto error;
       Py_XDECREF(node1);
       Py_XDECREF(node2);
+      is_satisfied = PyObject_RichCompareBool(node1_text, node2_text, Py_EQ)
+                      == ((CaptureEqCapture *)text_predicate)->is_positive;
+      Py_XDECREF(node1_text);
+      Py_XDECREF(node2_text);
       if (!is_satisfied)
         return false;
     } else if (capture_eq_string_is_instance(text_predicate)) {
       uint32_t capture_value_id = ((CaptureEqString *)text_predicate)->capture_value_id;
-      Node *node1 = node_for_capture_index(capture_value_id, match, tree);
-      char *node_1_text = PyBytes_AsString(node_get_text(node1, NULL));
-      const char *string_value = ((CaptureEqString *)text_predicate)->string_value;
-      is_satisfied = (strcmp(node_1_text, string_value) == 0) == ((CaptureEqString *)text_predicate)->is_positive;
+      node1 = node_for_capture_index(capture_value_id, match, tree);
+      if (node1 == NULL)
+        goto error;
+      node1_text = node_get_text(node1, NULL);
+      if (node1_text == NULL)
+        goto error;
       Py_XDECREF(node1);
+      PyObject *string_value = ((CaptureEqString *)text_predicate)->string_value;
+      is_satisfied = PyObject_RichCompareBool(node1_text, string_value, Py_EQ)
+                      == ((CaptureEqString *)text_predicate)->is_positive;
+      Py_XDECREF(node1_text);
       if (!is_satisfied)
         return false;
     } else if (capture_match_string_is_instance(text_predicate)) {
       uint32_t capture_value_id = ((CaptureMatchString *)text_predicate)->capture_value_id;
-      Node *node1 = node_for_capture_index(capture_value_id, match, tree);
-      char *node_1_text = PyBytes_AsString(node_get_text(node1, NULL));
+      node1 = node_for_capture_index(capture_value_id, match, tree);
+      if (node1 == NULL)
+        goto error;
+      node1_text = node_get_text(node1, NULL);
+      if (node1_text == NULL)
+        goto error;
       Py_XDECREF(node1);
-      int ret = regexec(&((CaptureMatchString *)text_predicate)->regex, node_1_text, 0, NULL, 0);
-      if (ret && ret != REG_NOMATCH) {
-        PyErr_SetString(PyExc_RuntimeError, "An error happened during the regex match");
-        return NULL;
-      }
-      is_satisfied = (!ret && ((CaptureMatchString *)text_predicate)->is_positive)
-                     || (ret && !((CaptureMatchString *)text_predicate)->is_positive);
-      if (!is_satisfied) {
-          return false;
-      }
+      PyObject *search_result = PyObject_CallMethod(
+        ((CaptureMatchString *)text_predicate)->regex, "search", "s", PyBytes_AsString(node1_text)
+      );
+      Py_XDECREF(node1_text);
+      is_satisfied = (search_result != Py_None) == ((CaptureMatchString *)text_predicate)->is_positive;
+      Py_DECREF(search_result);
+      if (!is_satisfied)
+        return false;
     }
   }
   return true;
+
+  error:
+    Py_XDECREF(node1);
+    Py_XDECREF(node2);
+    Py_XDECREF(node1_text);
+    Py_XDECREF(node2_text);
+    return NULL;
 }

 static PyObject *query_captures(Query *self, PyObject *args, PyObject *kwargs) {
@@ -982,28 +1012,40 @@
   if (!query_cursor) query_cursor = ts_query_cursor_new();
   ts_query_cursor_exec(query_cursor, self->query, node->node);

+  QueryCapture *capture = NULL;
   PyObject *result = PyList_New(0);
+  if (result == NULL)
+    goto error;

   uint32_t capture_index;
   TSQueryMatch match;
   while (ts_query_cursor_next_capture(query_cursor, &match, &capture_index)) {
-    QueryCapture *capture = (QueryCapture *)query_capture_new_internal(match.captures[capture_index]);
+    capture = (QueryCapture *)query_capture_new_internal(match.captures[capture_index]);
+    if (capture == NULL)
+      goto error;
     if (satisfies_text_predicates(self, match, (Tree *)node->tree)) {
       PyObject *capture_name = PyList_GetItem(self->capture_names, capture->capture.index);
       PyObject *capture_node = node_new_internal(capture->capture.node, node->tree);
       PyObject *item = PyTuple_Pack(2, capture_node, capture_name);
+      if (item == NULL)
+        goto error;
       Py_XDECREF(capture_node);
       PyList_Append(result, item);
       Py_XDECREF(item);
     }
+    Py_XDECREF(capture);
   }
   return result;
+
+  error:
+    Py_XDECREF(result);
+    Py_XDECREF(capture);
+    return NULL;
 }

 static void query_dealloc(Query *self) {
   if (self->query) ts_query_delete(self->query);
   Py_XDECREF(self->capture_names);
-  Py_XDECREF(self->string_values);
   Py_XDECREF(self->text_predicates);
   Py_TYPE(self)->tp_free(self);
 }
@@ -1086,33 +1128,17 @@
     PyList_SetItem(query->capture_names, i, PyUnicode_FromStringAndSize(capture_name, length));
   }

-  unsigned string_count = ts_query_string_count(query->query);
-  query->string_values = PyList_New(string_count);
-  if (query->string_values == NULL) {
-    PyErr_SetString(PyExc_RuntimeError, "Failed to allocate list for query->string_values");
-    goto error;
-  }
-  for (unsigned i = 0; i < string_count; i++) {
-    unsigned length;
-    const char *string_value = ts_query_string_value_for_id(query->query, i, &length);
-    PyList_SetItem(query->string_values, i, PyUnicode_FromStringAndSize(string_value, length));
-  }
-
   unsigned pattern_count = ts_query_pattern_count(query->query);
   query->text_predicates = PyList_New(pattern_count);
-  if (query->text_predicates == NULL) {
-    PyErr_SetString(PyExc_RuntimeError, "Failed to allocate list for query->text_predicates");
+  if (query->text_predicates == NULL)
     goto error;
-  }

   for (unsigned i = 0; i < pattern_count; i++) {
     unsigned length;
     const TSQueryPredicateStep* predicate_step = ts_query_predicates_for_pattern(query->query, i, &length);
     pattern_text_predicates = PyList_New(0);
-    if (pattern_text_predicates == NULL) {
-      PyErr_SetString(PyExc_RuntimeError, "Failed to allocate list for pattern_text_predicates");
+    if (pattern_text_predicates == NULL)
       goto error;
-    }
     for (unsigned j = 0; j < length; j++) {
       unsigned predicate_len = 0;
       while ((predicate_step + predicate_len)->type != TSQueryPredicateStepTypeDone)
@@ -1124,44 +1150,39 @@
       }

       // Build a predicate for each of the supported predicate function names
-      PyObject *operator_name = PyList_GetItem(query->string_values, predicate_step->value_id);
-      if (PyUnicode_CompareWithASCIIString(operator_name, "eq?") == 0 ||
-          PyUnicode_CompareWithASCIIString(operator_name, "not-eq?") == 0) {
+      unsigned length;
+      const char *operator_name = ts_query_string_value_for_id(query->query, predicate_step->value_id, &length);
+      if (strcmp(operator_name, "eq?") == 0 || strcmp(operator_name, "not-eq?") == 0) {
         if (predicate_len != 3) {
           PyErr_SetString(PyExc_RuntimeError, "Wrong number of arguments to #eq? or #not-eq? predicate");
           goto error;
         }
-        if ((predicate_step + 1)->type != TSQueryPredicateStepTypeCapture) {
+        if (predicate_step[1].type != TSQueryPredicateStepTypeCapture) {
           PyErr_SetString(PyExc_RuntimeError, "First argument to #eq? or #not-eq? must be a capture name");
           goto error;
         }
-        int is_positive = PyUnicode_CompareWithASCIIString(operator_name, "eq?") == 0;
-        switch ((predicate_step + 2)->type) {
+        int is_positive = strcmp(operator_name, "eq?") == 0;
+        switch (predicate_step[2].type) {
           case TSQueryPredicateStepTypeCapture:
             ;
             CaptureEqCapture *capture_eq_capture_predicate = (CaptureEqCapture *)capture_eq_capture_new_internal(
-              (predicate_step+1)->value_id, (predicate_step+2)->value_id, is_positive
+              predicate_step[1].value_id, predicate_step[2].value_id, is_positive
             );
-            if (capture_eq_capture_predicate == NULL) {
-              PyErr_SetString(PyExc_RuntimeError, "Failed to allocate CaptureEqCapture text predicate");
+            if (capture_eq_capture_predicate == NULL)
               goto error;
-            }
             PyList_Append(pattern_text_predicates, (PyObject *)capture_eq_capture_predicate);
             Py_DECREF(capture_eq_capture_predicate);
             break;
           case TSQueryPredicateStepTypeString:
             ;
-            Py_ssize_t size;
-            const char *string_value = PyUnicode_AsUTF8AndSize(
-              PyList_GetItem(query->string_values, (predicate_step+2)->value_id), &size
+            const char *string_value = ts_query_string_value_for_id(
+              query->query, predicate_step[2].value_id, &length
             );
             CaptureEqString *capture_eq_string_predicate = (CaptureEqString *)capture_eq_string_new_internal(
-              (predicate_step+1)->value_id, string_value, is_positive
+              predicate_step[1].value_id, string_value, is_positive
             );
-            if (capture_eq_string_predicate == NULL) {
-              PyErr_SetString(PyExc_RuntimeError, "Failed to allocate CaptureEqString text predicate");
+            if (capture_eq_string_predicate == NULL)
               goto error;
-            }
             PyList_Append(pattern_text_predicates, (PyObject *)capture_eq_string_predicate);
             Py_DECREF(capture_eq_string_predicate);
             break;
@@ -1169,32 +1190,26 @@
             PyErr_SetString(PyExc_RuntimeError, "Second argument to #eq? or #not-eq? must be a capture name or a string literal");
             goto error;
         }
-      } else if (PyUnicode_CompareWithASCIIString(operator_name, "match?") == 0 ||
-                 PyUnicode_CompareWithASCIIString(operator_name, "not-match?") == 0) {
+      } else if (strcmp(operator_name, "match?") == 0 || strcmp(operator_name, "not-match?") == 0) {
         if (predicate_len != 3) {
           PyErr_SetString(PyExc_RuntimeError, "Wrong number of arguments to #match? or #not-match? predicate");
           goto error;
         }
-        if ((predicate_step + 1)->type != TSQueryPredicateStepTypeCapture) {
+        if (predicate_step[1].type != TSQueryPredicateStepTypeCapture) {
           PyErr_SetString(PyExc_RuntimeError, "First argument to #match? or #not-match? must be a capture name");
           goto error;
         }
-        if ((predicate_step + 2)->type != TSQueryPredicateStepTypeString) {
+        if (predicate_step[2].type != TSQueryPredicateStepTypeString) {
           PyErr_SetString(PyExc_RuntimeError, "Second argument to #match? or #not-match? must be a regex string");
           goto error;
         }
-        Py_ssize_t size;
-        const char *string_value = PyUnicode_AsUTF8AndSize(
-          PyList_GetItem(query->string_values, (predicate_step+2)->value_id), &size
+        const char *string_value = ts_query_string_value_for_id(query->query, predicate_step[2].value_id, &length);
+        int is_positive = strcmp(operator_name, "match?") == 0;
+        CaptureMatchString *capture_match_string_predicate = (CaptureMatchString *)capture_match_string_new_internal(
+          predicate_step[1].value_id, string_value, is_positive
         );
-        int is_positive = PyUnicode_CompareWithASCIIString(operator_name, "match?") == 0;
-        CaptureMatchString *capture_match_string_predicate = (CaptureMatchString *)capture_match_string_new_internal(
-          (predicate_step+1)->value_id, string_value, is_positive
-        );
-        if (capture_match_string_predicate == NULL) {
-          PyErr_SetString(PyExc_RuntimeError, "Failed to allocate CaptureMatchString text predicate");
+        if (capture_match_string_predicate == NULL)
           goto error;
-        }
         PyList_Append(pattern_text_predicates, (PyObject *)capture_match_string_predicate);
         Py_DECREF(capture_match_string_predicate);
       }


nrf5/drivers: Activate ssd1289 object in the display module.

--- nrf5/drivers/display/moddisplay.c
+++ nrf5/drivers/display/moddisplay.c
@@ -31,6 +31,7 @@
 #include "epaper_sld00200p_obj.h"
 #include "lcd_ili9341_obj.h"
 #include "lcd_ls0xxb7dxxx_obj.h"
+#include "lcd_ssd1289_obj.h"
 #include "oled_ssd1305_obj.h"
 #include "oled_ssd1306_obj.h"

@@ -45,14 +46,14 @@
 #if MICROPY_PY_DISPLAY_LCD_LS0XXB7DXXX
     { MP_OBJ_NEW_QSTR(MP_QSTR_LS0XXB7DXXX), (mp_obj_t)&lcd_ls0xxb7dxxx_type },
 #endif
+#if MICROPY_PY_DISPLAY_LCD_SSD1289
+    { MP_OBJ_NEW_QSTR(MP_QSTR_SSD1289), (mp_obj_t)&lcd_ssd1289_type },
+#endif
 #if MICROPY_PY_DISPLAY_OLED_SSD1305
     { MP_OBJ_NEW_QSTR(MP_QSTR_SSD1305), (mp_obj_t)&oled_ssd1305_type },
 #endif
 #if MICROPY_PY_DISPLAY_OLED_SSD1306
     { MP_OBJ_NEW_QSTR(MP_QSTR_SSD1306), (mp_obj_t)&oled_ssd1306_type },
-#endif
-#if 0
-    { MP_OBJ_NEW_QSTR(MP_QSTR_SSD1289), (mp_obj_t)&lcd_ssd1289_type }
 #endif
 };


Remove trailing space.

Remove trailing space.

--- numpy/core/src/multiarraymodule.c
+++ numpy/core/src/multiarraymodule.c
@@ -3895,15 +3895,15 @@
         }
         obj = (PyArrayObject *)PyArray_FromArray(ret, self->descr,
                                                  flags);
-	if (obj == NULL) {
- 		PyErr_SetString(PyExc_ValueError,
- 		                "unable to create array of proper type from output array");
-		ret = NULL;
-		Py_DECREF(self->descr);
-		goto fail;
-	}
+	if (obj == NULL) {
+ 		PyErr_SetString(PyExc_ValueError,
+ 		                "unable to create array of proper type from output array");
+		ret = NULL;
+		Py_DECREF(self->descr);
+		goto fail;
+	}
  	else if (obj != ret) {
-		copyret = 1;
+		copyret = 1;
 	}
         ret = obj;
     }


Fix ref-count leak in Ticket #843

Fix ref-count leak in Ticket #843

--- numpy/core/src/multiarraymodule.c
+++ numpy/core/src/multiarraymodule.c
@@ -2139,12 +2139,18 @@
     if (scalar == PyArray_NOSCALAR) {
         return PyArray_CanCastSafely(thistype, neededtype);
     }
+
     from = PyArray_DescrFromType(thistype);
     if (from->f->cancastscalarkindto &&
         (castlist = from->f->cancastscalarkindto[scalar])) {
         while (*castlist != PyArray_NOTYPE)
-            if (*castlist++ == neededtype) return 1;
-    }
+	    if (*castlist++ == neededtype) {
+		Py_DECREF(from);
+		return 1;
+	    }
+    }
+    Py_DECREF(from);
+
     switch(scalar) {
     case PyArray_BOOL_SCALAR:
     case PyArray_OBJECT_SCALAR:


Perhaps this will fix my problems? Trying to avoid annoying warning.

--- third_party/cpp/rapidjson/reader.h
+++ third_party/cpp/rapidjson/reader.h
@@ -1,683 +1,683 @@
-#ifndef RAPIDJSON_READER_H_
-#define RAPIDJSON_READER_H_
-
-// Copyright (c) 2011 Milo Yip (miloyip@gmail.com)
-// Version 0.1
-
-#include "rapidjson.h"
-#include "internal/pow10.h"
-#include "internal/stack.h"
-#include <csetjmp>
-
-#ifdef RAPIDJSON_SSE42
-#include <nmmintrin.h>
-#elif defined(RAPIDJSON_SSE2)
-#include <emmintrin.h>
-#endif
-
-#ifdef _MSC_VER
-#pragma warning(push)
-#pragma warning(disable : 4127) // conditional expression is constant
-#endif
-
-#ifndef RAPIDJSON_PARSE_ERROR
-#define RAPIDJSON_PARSE_ERROR(msg, offset) \
-	RAPIDJSON_MULTILINEMACRO_BEGIN \
-	parseError_ = msg; \
-	errorOffset_ = offset; \
-	longjmp(jmpbuf_, 1); \
-	RAPIDJSON_MULTILINEMACRO_END
-#endif
-
-namespace rapidjson {
-
-///////////////////////////////////////////////////////////////////////////////
-// ParseFlag
-
-//! Combination of parseFlags
-enum ParseFlag {
-	kParseDefaultFlags = 0,			//!< Default parse flags. Non-destructive parsing. Text strings are decoded into allocated buffer.
-	kParseInsituFlag = 1			//!< In-situ(destructive) parsing.
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// Handler
-
-/*!	\class rapidjson::Handler
-	\brief Concept for receiving events from GenericReader upon parsing.
-\code
-concept Handler {
-	typename Ch;
-
-	void Null();
-	void Bool(bool b);
-	void Int(int i);
-	void Uint(unsigned i);
-	void Int64(int64_t i);
-	void Uint64(uint64_t i);
-	void Double(double d);
-	void String(const Ch* str, SizeType length, bool copy);
-	void StartObject();
-	void EndObject(SizeType memberCount);
-	void StartArray();
-	void EndArray(SizeType elementCount);
-};
-\endcode
-*/
-///////////////////////////////////////////////////////////////////////////////
-// BaseReaderHandler
-
-//! Default implementation of Handler.
-/*! This can be used as base class of any reader handler.
-	\implements Handler
-*/
-template<typename Encoding = UTF8<> >
-struct BaseReaderHandler {
-	typedef typename Encoding::Ch Ch;
-
-	void Default() {}
-	void Null() { Default(); }
-	void Bool(bool) { Default(); }
-	void Int(int) { Default(); }
-	void Uint(unsigned) { Default(); }
-	void Int64(int64_t) { Default(); }
-	void Uint64(uint64_t) { Default(); }
-	void Double(double) { Default(); }
-	void String(const Ch*, SizeType, bool) { Default(); }
-	void StartObject() { Default(); }
-	void EndObject(SizeType) { Default(); }
-	void StartArray() { Default(); }
-	void EndArray(SizeType) { Default(); }
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// SkipWhitespace
-
-//! Skip the JSON white spaces in a stream.
-/*! \param stream A input stream for skipping white spaces.
-	\note This function has SSE2/SSE4.2 specialization.
-*/
-template<typename Stream>
-void SkipWhitespace(Stream& stream) {
-	Stream s = stream;	// Use a local copy for optimization
-	while (s.Peek() == ' ' || s.Peek() == '\n' || s.Peek() == '\r' || s.Peek() == '\t')
-		s.Take();
-	stream = s;
-}
-
-#ifdef RAPIDJSON_SSE42
-//! Skip whitespace with SSE 4.2 pcmpistrm instruction, testing 16 8-byte characters at once.
-inline const char *SkipWhitespace_SIMD(const char* p) {
-	static const char whitespace[16] = " \n\r\t";
-	__m128i w = _mm_loadu_si128((const __m128i *)&whitespace[0]);
-
-	for (;;) {
-		__m128i s = _mm_loadu_si128((const __m128i *)p);
-		unsigned r = _mm_cvtsi128_si32(_mm_cmpistrm(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_BIT_MASK | _SIDD_NEGATIVE_POLARITY));
-		if (r == 0)	// all 16 characters are whitespace
-			p += 16;
-		else {		// some of characters may be non-whitespace
-#ifdef _MSC_VER		// Find the index of first non-whitespace
-			unsigned long offset;
-			if (_BitScanForward(&offset, r))
-				return p + offset;
-#else
-			if (r != 0)
-				return p + __builtin_ffs(r) - 1;
-#endif
-		}
-	}
-}
-
-#elif defined(RAPIDJSON_SSE2)
-
-//! Skip whitespace with SSE2 instructions, testing 16 8-byte characters at once.
-inline const char *SkipWhitespace_SIMD(const char* p) {
-	static const char whitespaces[4][17] = {
-		"                ",
-		"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
-		"\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r",
-		"\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"};
-
-	__m128i w0 = _mm_loadu_si128((const __m128i *)&whitespaces[0][0]);
-	__m128i w1 = _mm_loadu_si128((const __m128i *)&whitespaces[1][0]);
-	__m128i w2 = _mm_loadu_si128((const __m128i *)&whitespaces[2][0]);
-	__m128i w3 = _mm_loadu_si128((const __m128i *)&whitespaces[3][0]);
-
-	for (;;) {
-		__m128i s = _mm_loadu_si128((const __m128i *)p);
-		__m128i x = _mm_cmpeq_epi8(s, w0);
-		x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1));
-		x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2));
-		x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3));
-		unsigned short r = ~_mm_movemask_epi8(x);
-		if (r == 0)	// all 16 characters are whitespace
-			p += 16;
-		else {		// some of characters may be non-whitespace
-#ifdef _MSC_VER		// Find the index of first non-whitespace
-			unsigned long offset;
-			if (_BitScanForward(&offset, r))
-				return p + offset;
-#else
-			if (r != 0)
-				return p + __builtin_ffs(r) - 1;
-#endif
-		}
-	}
-}
-
-#endif // RAPIDJSON_SSE2
-
-#ifdef RAPIDJSON_SIMD
-//! Template function specialization for InsituStringStream
-template<> inline void SkipWhitespace(InsituStringStream& stream) {
-	stream.src_ = const_cast<char*>(SkipWhitespace_SIMD(stream.src_));
-}
-
-//! Template function specialization for StringStream
-template<> inline void SkipWhitespace(StringStream& stream) {
-	stream.src_ = SkipWhitespace_SIMD(stream.src_);
-}
-#endif // RAPIDJSON_SIMD
-
-///////////////////////////////////////////////////////////////////////////////
-// GenericReader
-
-//! SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
-/*! GenericReader parses JSON text from a stream, and send events synchronously to an
-    object implementing Handler concept.
-
-    It needs to allocate a stack for storing a single decoded string during
-    non-destructive parsing.
-
-    For in-situ parsing, the decoded string is directly written to the source
-    text string, no temporary buffer is required.
-
-    A GenericReader object can be reused for parsing multiple JSON text.
-
-    \tparam Encoding Encoding of both the stream and the parse output.
-    \tparam Allocator Allocator type for stack.
-*/
-template <typename Encoding, typename Allocator = MemoryPoolAllocator<> >
-class GenericReader {
-public:
-	typedef typename Encoding::Ch Ch;
-
-	//! Constructor.
-	/*! \param allocator Optional allocator for allocating stack memory. (Only use for non-destructive parsing)
-		\param stackCapacity stack capacity in bytes for storing a single decoded string.  (Only use for non-destructive parsing)
-	*/
-	GenericReader(Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity) : stack_(allocator, stackCapacity), parseError_(0), errorOffset_(0) {}
-
-	//! Parse JSON text.
-	/*! \tparam parseFlags Combination of ParseFlag.
-		 \tparam Stream Type of input stream.
-		 \tparam Handler Type of handler which must implement Handler concept.
-		 \param stream Input stream to be parsed.
-		 \param handler The handler to receive events.
-		 \return Whether the parsing is successful.
-	*/
-	template <unsigned parseFlags, typename Stream, typename Handler>
-	bool Parse(Stream& stream, Handler& handler) {
-		parseError_ = 0;
-		errorOffset_ = 0;
-
-#ifdef _MSC_VER
-#pragma warning(push)
-#pragma warning(disable : 4611) // interaction between '_setjmp' and C++ object destruction is non-portable
-#endif
-		if (setjmp(jmpbuf_)) {
-#ifdef _MSC_VER
-#pragma warning(pop)
-#endif
-			stack_.Clear();
-			return false;
-		}
-
-		SkipWhitespace(stream);
-
-		if (stream.Peek() == '\0')
-			RAPIDJSON_PARSE_ERROR("Text only contains white space(s)", stream.Tell());
-		else {
-			switch (stream.Peek()) {
-				case '{': ParseObject<parseFlags>(stream, handler); break;
-				case '[': ParseArray<parseFlags>(stream, handler); break;
-				default: RAPIDJSON_PARSE_ERROR("Expect either an object or array at root", stream.Tell());
-			}
-			SkipWhitespace(stream);
-
-			if (stream.Peek() != '\0')
-				RAPIDJSON_PARSE_ERROR("Nothing should follow the root object or array.", stream.Tell());
-		}
-
-		return true;
-	}
-
-	bool HasParseError() const { return parseError_ != 0; }
-	const char* GetParseError() const { return parseError_; }
-	size_t GetErrorOffset() const { return errorOffset_; }
-
-private:
-	// Parse object: { string : value, ... }
-	template<unsigned parseFlags, typename Stream, typename Handler>
-	void ParseObject(Stream& stream, Handler& handler) {
-		RAPIDJSON_ASSERT(stream.Peek() == '{');
-		stream.Take();	// Skip '{'
-		handler.StartObject();
-		SkipWhitespace(stream);
-
-		if (stream.Peek() == '}') {
-			stream.Take();
-			handler.EndObject(0);	// empty object
-			return;
-		}
-
-		for (SizeType memberCount = 0;;) {
-			if (stream.Peek() != '"') {
-				RAPIDJSON_PARSE_ERROR("Name of an object member must be a string", stream.Tell());
-				break;
-			}
-
-			ParseString<parseFlags>(stream, handler);
-			SkipWhitespace(stream);
-
-			if (stream.Take() != ':') {
-				RAPIDJSON_PARSE_ERROR("There must be a colon after the name of object member", stream.Tell());
-				break;
-			}
-			SkipWhitespace(stream);
-
-			ParseValue<parseFlags>(stream, handler);
-			SkipWhitespace(stream);
-
-			++memberCount;
-
-			switch(stream.Take()) {
-				case ',': SkipWhitespace(stream); break;
-				case '}': handler.EndObject(memberCount); return;
-				default:  RAPIDJSON_PARSE_ERROR("Must be a comma or '}' after an object member", stream.Tell());
-			}
-		}
-	}
-
-	// Parse array: [ value, ... ]
-	template<unsigned parseFlags, typename Stream, typename Handler>
-	void ParseArray(Stream& stream, Handler& handler) {
-		RAPIDJSON_ASSERT(stream.Peek() == '[');
-		stream.Take();	// Skip '['
-		handler.StartArray();
-		SkipWhitespace(stream);
-
-		if (stream.Peek() == ']') {
-			stream.Take();
-			handler.EndArray(0); // empty array
-			return;
-		}
-
-		for (SizeType elementCount = 0;;) {
-			ParseValue<parseFlags>(stream, handler);
-			++elementCount;
-			SkipWhitespace(stream);
-
-			switch (stream.Take()) {
-				case ',': SkipWhitespace(stream); break;
-				case ']': handler.EndArray(elementCount); return;
-				default:  RAPIDJSON_PARSE_ERROR("Must be a comma or ']' after an array element.", stream.Tell());
-			}
-		}
-	}
-
-	template<unsigned parseFlags, typename Stream, typename Handler>
-	void ParseNull(Stream& stream, Handler& handler) {
-		RAPIDJSON_ASSERT(stream.Peek() == 'n');
-		stream.Take();
-
-		if (stream.Take() == 'u' && stream.Take() == 'l' && stream.Take() == 'l')
-			handler.Null();
-		else
-			RAPIDJSON_PARSE_ERROR("Invalid value", stream.Tell() - 1);
-	}
-
-	template<unsigned parseFlags, typename Stream, typename Handler>
-	void ParseTrue(Stream& stream, Handler& handler) {
-		RAPIDJSON_ASSERT(stream.Peek() == 't');
-		stream.Take();
-
-		if (stream.Take() == 'r' && stream.Take() == 'u' && stream.Take() == 'e')
-			handler.Bool(true);
-		else
-			RAPIDJSON_PARSE_ERROR("Invalid value", stream.Tell());
-	}
-
-	template<unsigned parseFlags, typename Stream, typename Handler>
-	void ParseFalse(Stream& stream, Handler& handler) {
-		RAPIDJSON_ASSERT(stream.Peek() == 'f');
-		stream.Take();
-
-		if (stream.Take() == 'a' && stream.Take() == 'l' && stream.Take() == 's' && stream.Take() == 'e')
-			handler.Bool(false);
-		else
-			RAPIDJSON_PARSE_ERROR("Invalid value", stream.Tell() - 1);
-	}
-
-	// Helper function to parse four hexidecimal digits in \uXXXX in ParseString().
-	template<typename Stream>
-	unsigned ParseHex4(Stream& stream) {
-		Stream s = stream;	// Use a local copy for optimization
-		unsigned codepoint = 0;
-		for (int i = 0; i < 4; i++) {
-			Ch c = s.Take();
-			codepoint <<= 4;
-			codepoint += c;
-			if (c >= '0' && c <= '9')
-				codepoint -= '0';
-			else if (c >= 'A' && c <= 'F')
-				codepoint -= 'A' - 10;
-			else if (c >= 'a' && c <= 'f')
-				codepoint -= 'a' - 10;
-			else
-				RAPIDJSON_PARSE_ERROR("Incorrect hex digit after \\u escape", s.Tell() - 1);
-		}
-		stream = s; // Restore stream
-		return codepoint;
-	}
-
-	// Parse string, handling the prefix and suffix double quotes and escaping.
-	template<unsigned parseFlags, typename Stream, typename Handler>
-	void ParseString(Stream& stream, Handler& handler) {
-#define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
-		static const Ch escape[256] = {
-			Z16, Z16, 0, 0,'\"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'/',
-			Z16, Z16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0,
-			0, 0,'\b', 0, 0, 0,'\f', 0, 0, 0, 0, 0, 0, 0,'\n', 0,
-			0, 0,'\r', 0,'\t', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-			Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16
-		};
-#undef Z16
-
-		Stream s = stream;	// Use a local copy for optimization
-		RAPIDJSON_ASSERT(s.Peek() == '\"');
-		s.Take();	// Skip '\"'
-		Ch *head;
-		SizeType len;
-		if (parseFlags & kParseInsituFlag)
-			head = s.PutBegin();
-		else
-			len = 0;
-
-#define RAPIDJSON_PUT(x) \
-	do { \
-		if (parseFlags & kParseInsituFlag) \
-			s.Put(x); \
-		else { \
-			*stack_.template Push<Ch>() = x; \
-			++len; \
-		} \
-	} while(false)
-
-		for (;;) {
-			Ch c = s.Take();
-			if (c == '\\') {	// Escape
-				Ch e = s.Take();
-				if ((sizeof(Ch) == 1 || e < 256) && escape[(unsigned char)e])
-					RAPIDJSON_PUT(escape[(unsigned char)e]);
-				else if (e == 'u') {	// Unicode
-					unsigned codepoint = ParseHex4(s);
-					if (codepoint >= 0xD800 && codepoint <= 0xDBFF) { // Handle UTF-16 surrogate pair
-						if (s.Take() != '\\' || s.Take() != 'u') {
-							RAPIDJSON_PARSE_ERROR("Missing the second \\u in surrogate pair", s.Tell() - 2);
-							return;
-						}
-						unsigned codepoint2 = ParseHex4(s);
-						if (codepoint2 < 0xDC00 || codepoint2 > 0xDFFF) {
-							RAPIDJSON_PARSE_ERROR("The second \\u in surrogate pair is invalid", s.Tell() - 2);
-							return;
-						}
-						codepoint = (((codepoint - 0xD800) << 10) | (codepoint2 - 0xDC00)) + 0x10000;
-					}
-
-					Ch buffer[4];
-					SizeType count = SizeType(Encoding::Encode(buffer, codepoint) - &buffer[0]);
-
-					if (parseFlags & kParseInsituFlag)
-						for (SizeType i = 0; i < count; i++)
-							s.Put(buffer[i]);
-					else {
-						memcpy(stack_.template Push<Ch>(count), buffer, count * sizeof(Ch));
-						len += count;
-					}
-				}
-				else {
-					RAPIDJSON_PARSE_ERROR("Unknown escape character", stream.Tell() - 1);
-					return;
-				}
-			}
-			else if (c == '"') {	// Closing double quote
-				if (parseFlags & kParseInsituFlag) {
-					size_t length = s.PutEnd(head);
-					RAPIDJSON_ASSERT(length <= 0xFFFFFFFF);
-					RAPIDJSON_PUT('\0');	// null-terminate the string
-					handler.String(head, SizeType(length), false);
-				}
-				else {
-					RAPIDJSON_PUT('\0');
-					handler.String(stack_.template Pop<Ch>(len), len - 1, true);
-				}
-				stream = s;	// restore stream
-				return;
-			}
-			else if (c == '\0') {
-				RAPIDJSON_PARSE_ERROR("lacks ending quotation before the end of string", stream.Tell() - 1);
-				return;
-			}
-			else if ((unsigned)c < 0x20) {	// RFC 4627: unescaped = %x20-21 / %x23-5B / %x5D-10FFFF
-				RAPIDJSON_PARSE_ERROR("Incorrect unescaped character in string", stream.Tell() - 1);
-				return;
-			}
-			else
-				RAPIDJSON_PUT(c);	// Normal character, just copy
-		}
-#undef RAPIDJSON_PUT
-	}
-
-	template<unsigned parseFlags, typename Stream, typename Handler>
-	void ParseNumber(Stream& stream, Handler& handler) {
-		Stream s = stream; // Local copy for optimization
-		// Parse minus
-		bool minus = false;
-		if (s.Peek() == '-') {
-			minus = true;
-			s.Take();
-		}
-
-		// Parse int: zero / ( digit1-9 *DIGIT )
-		unsigned i;
-		bool try64bit = false;
-		if (s.Peek() == '0') {
-			i = 0;
-			s.Take();
-		}
-		else if (s.Peek() >= '1' && s.Peek() <= '9') {
-			i = s.Take() - '0';
-
-			if (minus)
-				while (s.Peek() >= '0' && s.Peek() <= '9') {
-					if (i >= 214748364) { // 2^31 = 2147483648
-						if (i != 214748364 || s.Peek() > '8') {
-							try64bit = true;
-							break;
-						}
-					}
-					i = i * 10 + (s.Take() - '0');
-				}
-			else
-				while (s.Peek() >= '0' && s.Peek() <= '9') {
-					if (i >= 429496729) { // 2^32 - 1 = 4294967295
-						if (i != 429496729 || s.Peek() > '5') {
-							try64bit = true;
-							break;
-						}
-					}
-					i = i * 10 + (s.Take() - '0');
-				}
-		}
-		else {
-			RAPIDJSON_PARSE_ERROR("Expect a value here.", stream.Tell());
-			return;
-		}
-
-		// Parse 64bit int
-		uint64_t i64 = 0;
-		bool useDouble = false;
-		if (try64bit) {
-			i64 = i;
-			if (minus)
-				while (s.Peek() >= '0' && s.Peek() <= '9') {
-					if (i64 >= 922337203685477580uLL) // 2^63 = 9223372036854775808
-						if (i64 != 922337203685477580uLL || s.Peek() > '8') {
-							useDouble = true;
-							break;
-						}
-					i64 = i64 * 10 + (s.Take() - '0');
-				}
-			else
-				while (s.Peek() >= '0' && s.Peek() <= '9') {
-					if (i64 >= 1844674407370955161uLL) // 2^64 - 1 = 18446744073709551615
-						if (i64 != 1844674407370955161uLL || s.Peek() > '5') {
-							useDouble = true;
-							break;
-						}
-					i64 = i64 * 10 + (s.Take() - '0');
-				}
-		}
-
-		// Force double for big integer
-		double d = 0.0;
-		if (useDouble) {
-			d = (double)i64;
-			while (s.Peek() >= '0' && s.Peek() <= '9') {
-				if (d >= 1E307) {
-					RAPIDJSON_PARSE_ERROR("Number too big to store in double", stream.Tell());
-					return;
-				}
-				d = d * 10 + (s.Take() - '0');
-			}
-		}
-
-		// Parse frac = decimal-point 1*DIGIT
-		int expFrac = 0;
-		if (s.Peek() == '.') {
-			if (!useDouble) {
-				d = try64bit ? (double)i64 : (double)i;
-				useDouble = true;
-			}
-			s.Take();
-
-			if (s.Peek() >= '0' && s.Peek() <= '9') {
-				d = d * 10 + (s.Take() - '0');
-				--expFrac;
-			}
-			else {
-				RAPIDJSON_PARSE_ERROR("At least one digit in fraction part", stream.Tell());
-				return;
-			}
-
-			while (s.Peek() >= '0' && s.Peek() <= '9') {
-				if (expFrac > -16) {
-					d = d * 10 + (s.Peek() - '0');
-					--expFrac;
-				}
-				s.Take();
-			}
-		}
-
-		// Parse exp = e [ minus / plus ] 1*DIGIT
-		int exp = 0;
-		if (s.Peek() == 'e' || s.Peek() == 'E') {
-			if (!useDouble) {
-				d = try64bit ? (double)i64 : (double)i;
-				useDouble = true;
-			}
-			s.Take();
-
-			bool expMinus = false;
-			if (s.Peek() == '+')
-				s.Take();
-			else if (s.Peek() == '-') {
-				s.Take();
-				expMinus = true;
-			}
-
-			if (s.Peek() >= '0' && s.Peek() <= '9') {
-				exp = s.Take() - '0';
-				while (s.Peek() >= '0' && s.Peek() <= '9') {
-					exp = exp * 10 + (s.Take() - '0');
-					if (exp > 308) {
-						RAPIDJSON_PARSE_ERROR("Number too big to store in double", stream.Tell());
-						return;
-					}
-				}
-			}
-			else {
-				RAPIDJSON_PARSE_ERROR("At least one digit in exponent", s.Tell());
-				return;
-			}
-
-			if (expMinus)
-				exp = -exp;
-		}
-
-		// Finish parsing, call event according to the type of number.
-		if (useDouble) {
-			d *= internal::Pow10(exp + expFrac);
-			handler.Double(minus ? -d : d);
-		}
-		else {
-			if (try64bit) {
-				if (minus)
-					handler.Int64(-(int64_t)i64);
-				else
-					handler.Uint64(i64);
-			}
-			else {
-				if (minus)
-					handler.Int(-(int)i);
-				else
-					handler.Uint(i);
-			}
-		}
-
-		stream = s; // restore stream
-	}
-
-	// Parse any JSON value
-	template<unsigned parseFlags, typename Stream, typename Handler>
-	void ParseValue(Stream& stream, Handler& handler) {
-		switch (stream.Peek()) {
-			case 'n': ParseNull  <parseFlags>(stream, handler); break;
-			case 't': ParseTrue  <parseFlags>(stream, handler); break;
-			case 'f': ParseFalse <parseFlags>(stream, handler); break;
-			case '"': ParseString<parseFlags>(stream, handler); break;
-			case '{': ParseObject<parseFlags>(stream, handler); break;
-			case '[': ParseArray <parseFlags>(stream, handler); break;
-			default : ParseNumber<parseFlags>(stream, handler);
-		}
-	}
-
-	static const size_t kDefaultStackCapacity = 256;	//!< Default stack capacity in bytes for storing a single decoded string.
-	internal::Stack<Allocator> stack_;	//!< A stack for storing decoded string temporarily during non-destructive parsing.
-	jmp_buf jmpbuf_;					//!< setjmp buffer for fast exit from nested parsing function calls.
-	const char* parseError_;
-	size_t errorOffset_;
-}; // class GenericReader
-
-//! Reader with UTF8 encoding and default allocator.
-typedef GenericReader<UTF8<> > Reader;
-
-} // namespace rapidjson
-
-#ifdef _MSC_VER
-#pragma warning(pop)
-#endif
-
-#endif // RAPIDJSON_READER_H_
+#ifndef RAPIDJSON_READER_H_
+#define RAPIDJSON_READER_H_
+
+// Copyright (c) 2011 Milo Yip (miloyip@gmail.com)
+// Version 0.1
+
+#include "rapidjson.h"
+#include "internal/pow10.h"
+#include "internal/stack.h"
+#include <csetjmp>
+
+#ifdef RAPIDJSON_SSE42
+#include <nmmintrin.h>
+#elif defined(RAPIDJSON_SSE2)
+#include <emmintrin.h>
+#endif
+
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable : 4127) // conditional expression is constant
+#endif
+
+#ifndef RAPIDJSON_PARSE_ERROR
+#define RAPIDJSON_PARSE_ERROR(msg, offset) \
+	RAPIDJSON_MULTILINEMACRO_BEGIN \
+	parseError_ = msg; \
+	errorOffset_ = offset; \
+	longjmp(jmpbuf_, 1); \
+	RAPIDJSON_MULTILINEMACRO_END
+#endif
+
+namespace rapidjson {
+
+///////////////////////////////////////////////////////////////////////////////
+// ParseFlag
+
+//! Combination of parseFlags
+enum ParseFlag {
+	kParseDefaultFlags = 0,			//!< Default parse flags. Non-destructive parsing. Text strings are decoded into allocated buffer.
+	kParseInsituFlag = 1			//!< In-situ(destructive) parsing.
+};
+
+///////////////////////////////////////////////////////////////////////////////
+// Handler
+
+/*!	\class rapidjson::Handler
+	\brief Concept for receiving events from GenericReader upon parsing.
+\code
+concept Handler {
+	typename Ch;
+
+	void Null();
+	void Bool(bool b);
+	void Int(int i);
+	void Uint(unsigned i);
+	void Int64(int64_t i);
+	void Uint64(uint64_t i);
+	void Double(double d);
+	void String(const Ch* str, SizeType length, bool copy);
+	void StartObject();
+	void EndObject(SizeType memberCount);
+	void StartArray();
+	void EndArray(SizeType elementCount);
+};
+\endcode
+*/
+///////////////////////////////////////////////////////////////////////////////
+// BaseReaderHandler
+
+//! Default implementation of Handler.
+/*! This can be used as base class of any reader handler.
+	\implements Handler
+*/
+template<typename Encoding = UTF8<> >
+struct BaseReaderHandler {
+	typedef typename Encoding::Ch Ch;
+
+	void Default() {}
+	void Null() { Default(); }
+	void Bool(bool) { Default(); }
+	void Int(int) { Default(); }
+	void Uint(unsigned) { Default(); }
+	void Int64(int64_t) { Default(); }
+	void Uint64(uint64_t) { Default(); }
+	void Double(double) { Default(); }
+	void String(const Ch*, SizeType, bool) { Default(); }
+	void StartObject() { Default(); }
+	void EndObject(SizeType) { Default(); }
+	void StartArray() { Default(); }
+	void EndArray(SizeType) { Default(); }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+// SkipWhitespace
+
+//! Skip the JSON white spaces in a stream.
+/*! \param stream A input stream for skipping white spaces.
+	\note This function has SSE2/SSE4.2 specialization.
+*/
+template<typename Stream>
+void SkipWhitespace(Stream& stream) {
+	Stream s = stream;	// Use a local copy for optimization
+	while (s.Peek() == ' ' || s.Peek() == '\n' || s.Peek() == '\r' || s.Peek() == '\t')
+		s.Take();
+	stream = s;
+}
+
+#ifdef RAPIDJSON_SSE42
+//! Skip whitespace with SSE 4.2 pcmpistrm instruction, testing 16 8-byte characters at once.
+inline const char *SkipWhitespace_SIMD(const char* p) {
+	static const char whitespace[16] = " \n\r\t";
+	__m128i w = _mm_loadu_si128((const __m128i *)&whitespace[0]);
+
+	for (;;) {
+		__m128i s = _mm_loadu_si128((const __m128i *)p);
+		unsigned r = _mm_cvtsi128_si32(_mm_cmpistrm(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_BIT_MASK | _SIDD_NEGATIVE_POLARITY));
+		if (r == 0)	// all 16 characters are whitespace
+			p += 16;
+		else {		// some of characters may be non-whitespace
+#ifdef _MSC_VER		// Find the index of first non-whitespace
+			unsigned long offset;
+			if (_BitScanForward(&offset, r))
+				return p + offset;
+#else
+			if (r != 0)
+				return p + __builtin_ffs(r) - 1;
+#endif
+		}
+	}
+}
+
+#elif defined(RAPIDJSON_SSE2)
+
+//! Skip whitespace with SSE2 instructions, testing 16 8-byte characters at once.
+inline const char *SkipWhitespace_SIMD(const char* p) {
+	static const char whitespaces[4][17] = {
+		"                ",
+		"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
+		"\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r",
+		"\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"};
+
+	__m128i w0 = _mm_loadu_si128((const __m128i *)&whitespaces[0][0]);
+	__m128i w1 = _mm_loadu_si128((const __m128i *)&whitespaces[1][0]);
+	__m128i w2 = _mm_loadu_si128((const __m128i *)&whitespaces[2][0]);
+	__m128i w3 = _mm_loadu_si128((const __m128i *)&whitespaces[3][0]);
+
+	for (;;) {
+		__m128i s = _mm_loadu_si128((const __m128i *)p);
+		__m128i x = _mm_cmpeq_epi8(s, w0);
+		x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1));
+		x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2));
+		x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3));
+		unsigned short r = ~_mm_movemask_epi8(x);
+		if (r == 0)	// all 16 characters are whitespace
+			p += 16;
+		else {		// some of characters may be non-whitespace
+#ifdef _MSC_VER		// Find the index of first non-whitespace
+			unsigned long offset;
+			if (_BitScanForward(&offset, r))
+				return p + offset;
+#else
+			if (r != 0)
+				return p + __builtin_ffs(r) - 1;
+#endif
+		}
+	}
+}
+
+#endif // RAPIDJSON_SSE2
+
+#ifdef RAPIDJSON_SIMD
+//! Template function specialization for InsituStringStream
+template<> inline void SkipWhitespace(InsituStringStream& stream) {
+	stream.src_ = const_cast<char*>(SkipWhitespace_SIMD(stream.src_));
+}
+
+//! Template function specialization for StringStream
+template<> inline void SkipWhitespace(StringStream& stream) {
+	stream.src_ = SkipWhitespace_SIMD(stream.src_);
+}
+#endif // RAPIDJSON_SIMD
+
+///////////////////////////////////////////////////////////////////////////////
+// GenericReader
+
+//! SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
+/*! GenericReader parses JSON text from a stream, and send events synchronously to an
+    object implementing Handler concept.
+
+    It needs to allocate a stack for storing a single decoded string during
+    non-destructive parsing.
+
+    For in-situ parsing, the decoded string is directly written to the source
+    text string, no temporary buffer is required.
+
+    A GenericReader object can be reused for parsing multiple JSON text.
+
+    \tparam Encoding Encoding of both the stream and the parse output.
+    \tparam Allocator Allocator type for stack.
+*/
+template <typename Encoding, typename Allocator = MemoryPoolAllocator<> >
+class GenericReader {
+public:
+	typedef typename Encoding::Ch Ch;
+
+	//! Constructor.
+	/*! \param allocator Optional allocator for allocating stack memory. (Only use for non-destructive parsing)
+		\param stackCapacity stack capacity in bytes for storing a single decoded string.  (Only use for non-destructive parsing)
+	*/
+	GenericReader(Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity) : stack_(allocator, stackCapacity), parseError_(0), errorOffset_(0) {}
+
+	//! Parse JSON text.
+	/*! \tparam parseFlags Combination of ParseFlag.
+		 \tparam Stream Type of input stream.
+		 \tparam Handler Type of handler which must implement Handler concept.
+		 \param stream Input stream to be parsed.
+		 \param handler The handler to receive events.
+		 \return Whether the parsing is successful.
+	*/
+	template <unsigned parseFlags, typename Stream, typename Handler>
+	bool Parse(Stream& stream, Handler& handler) {
+		parseError_ = 0;
+		errorOffset_ = 0;
+
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable : 4611) // interaction between '_setjmp' and C++ object destruction is non-portable
+#endif
+		if (setjmp(jmpbuf_)) {
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+			stack_.Clear();
+			return false;
+		}
+
+		SkipWhitespace(stream);
+
+		if (stream.Peek() == '\0')
+			RAPIDJSON_PARSE_ERROR("Text only contains white space(s)", stream.Tell());
+		else {
+			switch (stream.Peek()) {
+				case '{': ParseObject<parseFlags>(stream, handler); break;
+				case '[': ParseArray<parseFlags>(stream, handler); break;
+				default: RAPIDJSON_PARSE_ERROR("Expect either an object or array at root", stream.Tell());
+			}
+			SkipWhitespace(stream);
+
+			if (stream.Peek() != '\0')
+				RAPIDJSON_PARSE_ERROR("Nothing should follow the root object or array.", stream.Tell());
+		}
+
+		return true;
+	}
+
+	bool HasParseError() const { return parseError_ != 0; }
+	const char* GetParseError() const { return parseError_; }
+	size_t GetErrorOffset() const { return errorOffset_; }
+
+private:
+	// Parse object: { string : value, ... }
+	template<unsigned parseFlags, typename Stream, typename Handler>
+	void ParseObject(Stream& stream, Handler& handler) {
+		RAPIDJSON_ASSERT(stream.Peek() == '{');
+		stream.Take();	// Skip '{'
+		handler.StartObject();
+		SkipWhitespace(stream);
+
+		if (stream.Peek() == '}') {
+			stream.Take();
+			handler.EndObject(0);	// empty object
+			return;
+		}
+
+		for (SizeType memberCount = 0;;) {
+			if (stream.Peek() != '"') {
+				RAPIDJSON_PARSE_ERROR("Name of an object member must be a string", stream.Tell());
+				break;
+			}
+
+			ParseString<parseFlags>(stream, handler);
+			SkipWhitespace(stream);
+
+			if (stream.Take() != ':') {
+				RAPIDJSON_PARSE_ERROR("There must be a colon after the name of object member", stream.Tell());
+				break;
+			}
+			SkipWhitespace(stream);
+
+			ParseValue<parseFlags>(stream, handler);
+			SkipWhitespace(stream);
+
+			++memberCount;
+
+			switch(stream.Take()) {
+				case ',': SkipWhitespace(stream); break;
+				case '}': handler.EndObject(memberCount); return;
+				default:  RAPIDJSON_PARSE_ERROR("Must be a comma or '}' after an object member", stream.Tell());
+			}
+		}
+	}
+
+	// Parse array: [ value, ... ]
+	template<unsigned parseFlags, typename Stream, typename Handler>
+	void ParseArray(Stream& stream, Handler& handler) {
+		RAPIDJSON_ASSERT(stream.Peek() == '[');
+		stream.Take();	// Skip '['
+		handler.StartArray();
+		SkipWhitespace(stream);
+
+		if (stream.Peek() == ']') {
+			stream.Take();
+			handler.EndArray(0); // empty array
+			return;
+		}
+
+		for (SizeType elementCount = 0;;) {
+			ParseValue<parseFlags>(stream, handler);
+			++elementCount;
+			SkipWhitespace(stream);
+
+			switch (stream.Take()) {
+				case ',': SkipWhitespace(stream); break;
+				case ']': handler.EndArray(elementCount); return;
+				default:  RAPIDJSON_PARSE_ERROR("Must be a comma or ']' after an array element.", stream.Tell());
+			}
+		}
+	}
+
+	template<unsigned parseFlags, typename Stream, typename Handler>
+	void ParseNull(Stream& stream, Handler& handler) {
+		RAPIDJSON_ASSERT(stream.Peek() == 'n');
+		stream.Take();
+
+		if (stream.Take() == 'u' && stream.Take() == 'l' && stream.Take() == 'l')
+			handler.Null();
+		else
+			RAPIDJSON_PARSE_ERROR("Invalid value", stream.Tell() - 1);
+	}
+
+	template<unsigned parseFlags, typename Stream, typename Handler>
+	void ParseTrue(Stream& stream, Handler& handler) {
+		RAPIDJSON_ASSERT(stream.Peek() == 't');
+		stream.Take();
+
+		if (stream.Take() == 'r' && stream.Take() == 'u' && stream.Take() == 'e')
+			handler.Bool(true);
+		else
+			RAPIDJSON_PARSE_ERROR("Invalid value", stream.Tell());
+	}
+
+	template<unsigned parseFlags, typename Stream, typename Handler>
+	void ParseFalse(Stream& stream, Handler& handler) {
+		RAPIDJSON_ASSERT(stream.Peek() == 'f');
+		stream.Take();
+
+		if (stream.Take() == 'a' && stream.Take() == 'l' && stream.Take() == 's' && stream.Take() == 'e')
+			handler.Bool(false);
+		else
+			RAPIDJSON_PARSE_ERROR("Invalid value", stream.Tell() - 1);
+	}
+
+	// Helper function to parse four hexidecimal digits in \uXXXX in ParseString().
+	template<typename Stream>
+	unsigned ParseHex4(Stream& stream) {
+		Stream s = stream;	// Use a local copy for optimization
+		unsigned codepoint = 0;
+		for (int i = 0; i < 4; i++) {
+			Ch c = s.Take();
+			codepoint <<= 4;
+			codepoint += c;
+			if (c >= '0' && c <= '9')
+				codepoint -= '0';
+			else if (c >= 'A' && c <= 'F')
+				codepoint -= 'A' - 10;
+			else if (c >= 'a' && c <= 'f')
+				codepoint -= 'a' - 10;
+			else
+				RAPIDJSON_PARSE_ERROR("Incorrect hex digit after \\u escape", s.Tell() - 1);
+		}
+		stream = s; // Restore stream
+		return codepoint;
+	}
+
+	// Parse string, handling the prefix and suffix double quotes and escaping.
+	template<unsigned parseFlags, typename Stream, typename Handler>
+	void ParseString(Stream& stream, Handler& handler) {
+#define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+		static const Ch escape[256] = {
+			Z16, Z16, 0, 0,'\"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'/',
+			Z16, Z16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0,
+			0, 0,'\b', 0, 0, 0,'\f', 0, 0, 0, 0, 0, 0, 0,'\n', 0,
+			0, 0,'\r', 0,'\t', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+			Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16
+		};
+#undef Z16
+
+		Stream s = stream;	// Use a local copy for optimization
+		RAPIDJSON_ASSERT(s.Peek() == '\"');
+		s.Take();	// Skip '\"'
+		Ch *head;
+		SizeType len;
+		if (parseFlags & kParseInsituFlag)
+			head = s.PutBegin();
+		else
+			len = 0;
+
+#define RAPIDJSON_PUT(x) \
+	do { \
+		if (parseFlags & kParseInsituFlag) \
+			s.Put(x); \
+		else { \
+			*stack_.template Push<Ch>() = x; \
+			++len; \
+		} \
+	} while(false)
+
+		for (;;) {
+			Ch c = s.Take();
+			if (c == '\\') {	// Escape
+				Ch e = s.Take();
+				if ((sizeof(e) == 1 || e < 256) && escape[(unsigned char)e])
+					RAPIDJSON_PUT(escape[(unsigned char)e]);
+				else if (e == 'u') {	// Unicode
+					unsigned codepoint = ParseHex4(s);
+					if (codepoint >= 0xD800 && codepoint <= 0xDBFF) { // Handle UTF-16 surrogate pair
+						if (s.Take() != '\\' || s.Take() != 'u') {
+							RAPIDJSON_PARSE_ERROR("Missing the second \\u in surrogate pair", s.Tell() - 2);
+							return;
+						}
+						unsigned codepoint2 = ParseHex4(s);
+						if (codepoint2 < 0xDC00 || codepoint2 > 0xDFFF) {
+							RAPIDJSON_PARSE_ERROR("The second \\u in surrogate pair is invalid", s.Tell() - 2);
+							return;
+						}
+						codepoint = (((codepoint - 0xD800) << 10) | (codepoint2 - 0xDC00)) + 0x10000;
+					}
+
+					Ch buffer[4];
+					SizeType count = SizeType(Encoding::Encode(buffer, codepoint) - &buffer[0]);
+
+					if (parseFlags & kParseInsituFlag)
+						for (SizeType i = 0; i < count; i++)
+							s.Put(buffer[i]);
+					else {
+						memcpy(stack_.template Push<Ch>(count), buffer, count * sizeof(Ch));
+						len += count;
+					}
+				}
+				else {
+					RAPIDJSON_PARSE_ERROR("Unknown escape character", stream.Tell() - 1);
+					return;
+				}
+			}
+			else if (c == '"') {	// Closing double quote
+				if (parseFlags & kParseInsituFlag) {
+					size_t length = s.PutEnd(head);
+					RAPIDJSON_ASSERT(length <= 0xFFFFFFFF);
+					RAPIDJSON_PUT('\0');	// null-terminate the string
+					handler.String(head, SizeType(length), false);
+				}
+				else {
+					RAPIDJSON_PUT('\0');
+					handler.String(stack_.template Pop<Ch>(len), len - 1, true);
+				}
+				stream = s;	// restore stream
+				return;
+			}
+			else if (c == '\0') {
+				RAPIDJSON_PARSE_ERROR("lacks ending quotation before the end of string", stream.Tell() - 1);
+				return;
+			}
+			else if ((unsigned)c < 0x20) {	// RFC 4627: unescaped = %x20-21 / %x23-5B / %x5D-10FFFF
+				RAPIDJSON_PARSE_ERROR("Incorrect unescaped character in string", stream.Tell() - 1);
+				return;
+			}
+			else
+				RAPIDJSON_PUT(c);	// Normal character, just copy
+		}
+#undef RAPIDJSON_PUT
+	}
+
+	template<unsigned parseFlags, typename Stream, typename Handler>
+	void ParseNumber(Stream& stream, Handler& handler) {
+		Stream s = stream; // Local copy for optimization
+		// Parse minus
+		bool minus = false;
+		if (s.Peek() == '-') {
+			minus = true;
+			s.Take();
+		}
+
+		// Parse int: zero / ( digit1-9 *DIGIT )
+		unsigned i;
+		bool try64bit = false;
+		if (s.Peek() == '0') {
+			i = 0;
+			s.Take();
+		}
+		else if (s.Peek() >= '1' && s.Peek() <= '9') {
+			i = s.Take() - '0';
+
+			if (minus)
+				while (s.Peek() >= '0' && s.Peek() <= '9') {
+					if (i >= 214748364) { // 2^31 = 2147483648
+						if (i != 214748364 || s.Peek() > '8') {
+							try64bit = true;
+							break;
+						}
+					}
+					i = i * 10 + (s.Take() - '0');
+				}
+			else
+				while (s.Peek() >= '0' && s.Peek() <= '9') {
+					if (i >= 429496729) { // 2^32 - 1 = 4294967295
+						if (i != 429496729 || s.Peek() > '5') {
+							try64bit = true;
+							break;
+						}
+					}
+					i = i * 10 + (s.Take() - '0');
+				}
+		}
+		else {
+			RAPIDJSON_PARSE_ERROR("Expect a value here.", stream.Tell());
+			return;
+		}
+
+		// Parse 64bit int
+		uint64_t i64 = 0;
+		bool useDouble = false;
+		if (try64bit) {
+			i64 = i;
+			if (minus)
+				while (s.Peek() >= '0' && s.Peek() <= '9') {
+					if (i64 >= 922337203685477580uLL) // 2^63 = 9223372036854775808
+						if (i64 != 922337203685477580uLL || s.Peek() > '8') {
+							useDouble = true;
+							break;
+						}
+					i64 = i64 * 10 + (s.Take() - '0');
+				}
+			else
+				while (s.Peek() >= '0' && s.Peek() <= '9') {
+					if (i64 >= 1844674407370955161uLL) // 2^64 - 1 = 18446744073709551615
+						if (i64 != 1844674407370955161uLL || s.Peek() > '5') {
+							useDouble = true;
+							break;
+						}
+					i64 = i64 * 10 + (s.Take() - '0');
+				}
+		}
+
+		// Force double for big integer
+		double d = 0.0;
+		if (useDouble) {
+			d = (double)i64;
+			while (s.Peek() >= '0' && s.Peek() <= '9') {
+				if (d >= 1E307) {
+					RAPIDJSON_PARSE_ERROR("Number too big to store in double", stream.Tell());
+					return;
+				}
+				d = d * 10 + (s.Take() - '0');
+			}
+		}
+
+		// Parse frac = decimal-point 1*DIGIT
+		int expFrac = 0;
+		if (s.Peek() == '.') {
+			if (!useDouble) {
+				d = try64bit ? (double)i64 : (double)i;
+				useDouble = true;
+			}
+			s.Take();
+
+			if (s.Peek() >= '0' && s.Peek() <= '9') {
+				d = d * 10 + (s.Take() - '0');
+				--expFrac;
+			}
+			else {
+				RAPIDJSON_PARSE_ERROR("At least one digit in fraction part", stream.Tell());
+				return;
+			}
+
+			while (s.Peek() >= '0' && s.Peek() <= '9') {
+				if (expFrac > -16) {
+					d = d * 10 + (s.Peek() - '0');
+					--expFrac;
+				}
+				s.Take();
+			}
+		}
+
+		// Parse exp = e [ minus / plus ] 1*DIGIT
+		int exp = 0;
+		if (s.Peek() == 'e' || s.Peek() == 'E') {
+			if (!useDouble) {
+				d = try64bit ? (double)i64 : (double)i;
+				useDouble = true;
+			}
+			s.Take();
+
+			bool expMinus = false;
+			if (s.Peek() == '+')
+				s.Take();
+			else if (s.Peek() == '-') {
+				s.Take();
+				expMinus = true;
+			}
+
+			if (s.Peek() >= '0' && s.Peek() <= '9') {
+				exp = s.Take() - '0';
+				while (s.Peek() >= '0' && s.Peek() <= '9') {
+					exp = exp * 10 + (s.Take() - '0');
+					if (exp > 308) {
+						RAPIDJSON_PARSE_ERROR("Number too big to store in double", stream.Tell());
+						return;
+					}
+				}
+			}
+			else {
+				RAPIDJSON_PARSE_ERROR("At least one digit in exponent", s.Tell());
+				return;
+			}
+
+			if (expMinus)
+				exp = -exp;
+		}
+
+		// Finish parsing, call event according to the type of number.
+		if (useDouble) {
+			d *= internal::Pow10(exp + expFrac);
+			handler.Double(minus ? -d : d);
+		}
+		else {
+			if (try64bit) {
+				if (minus)
+					handler.Int64(-(int64_t)i64);
+				else
+					handler.Uint64(i64);
+			}
+			else {
+				if (minus)
+					handler.Int(-(int)i);
+				else
+					handler.Uint(i);
+			}
+		}
+
+		stream = s; // restore stream
+	}
+
+	// Parse any JSON value
+	template<unsigned parseFlags, typename Stream, typename Handler>
+	void ParseValue(Stream& stream, Handler& handler) {
+		switch (stream.Peek()) {
+			case 'n': ParseNull  <parseFlags>(stream, handler); break;
+			case 't': ParseTrue  <parseFlags>(stream, handler); break;
+			case 'f': ParseFalse <parseFlags>(stream, handler); break;
+			case '"': ParseString<parseFlags>(stream, handler); break;
+			case '{': ParseObject<parseFlags>(stream, handler); break;
+			case '[': ParseArray <parseFlags>(stream, handler); break;
+			default : ParseNumber<parseFlags>(stream, handler);
+		}
+	}
+
+	static const size_t kDefaultStackCapacity = 256;	//!< Default stack capacity in bytes for storing a single decoded string.
+	internal::Stack<Allocator> stack_;	//!< A stack for storing decoded string temporarily during non-destructive parsing.
+	jmp_buf jmpbuf_;					//!< setjmp buffer for fast exit from nested parsing function calls.
+	const char* parseError_;
+	size_t errorOffset_;
+}; // class GenericReader
+
+//! Reader with UTF8 encoding and default allocator.
+typedef GenericReader<UTF8<> > Reader;
+
+} // namespace rapidjson
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
+#endif // RAPIDJSON_READER_H_


doxygen cosmetics

doxygen cosmetics

--- nvbio/strings/vectorized_string.h
+++ nvbio/strings/vectorized_string.h
@@ -78,10 +78,7 @@
 ///
 /// // loop through the scalar range
 /// for (uint32 i = 0; i < vec_range.x; ++i)
-/// {
-///     const char c = string[i];
-///     printf("%c", c);
-/// }
+///     printf("%c", string[i]);
 ///
 /// // loop through the vectorized range
 /// for (uint32 i = vec_range.x; i < vec_range.y; i += VECW)
@@ -97,10 +94,7 @@
 ///
 /// // loop through the scalar range
 /// for (uint32 i = vec_range.y; i < length( string ); ++i)
-/// {
-///     const char c = string[i];
-///     printf("%c", c);
-/// }
+///     printf("%c", string[i]);
 /// printf("\n");
 ///


Plug a leak.

Plug a leak.

--- configure.c
+++ configure.c
@@ -448,11 +448,12 @@

 	/* We need to delete the subnet route to have our metric or
 	 * prefer the interface. */
-	if (iface->net.s_addr != INADDR_BROADCAST) {
-		rt = get_subnet_route(dhcp);
+	rt = get_subnet_route(dhcp);
+	if (rt != NULL) {
 		rt->iface = iface;
 		if (!find_route(routes, rt, NULL, NULL))
 			del_route(iface, &rt->dest, &rt->net, &rt->gate, 0);
+		free(rt);
 	}

 	build_routes();


gnutls: Fix check for certain handshake failure conditions

It seems we have no tests to see if these errors work or not, because
the code is comparing a GTlsConnectionBaseStatus code to a GnuTLS error
code. It has been broken since 0e94c20acdc524e82c19eb95884887b74852326d.
The code previously used "status" as the name for a GnuTLS error code,
then changed it to be a GTlsConnectionBaseStatus in that commit. Alas, I
should have used a different intermediary name instead, which would have
caught this as a compiler error.

Getting the tests to return particular errors is likely impractical.
Let's just fix this and move on.

--- tls/gnutls/gtlsconnection-gnutls.c
+++ tls/gnutls/gtlsconnection-gnutls.c
@@ -374,9 +374,9 @@
           return G_TLS_CONNECTION_BASE_ERROR;
         }

-      if (status == GNUTLS_E_UNEXPECTED_PACKET_LENGTH ||
-          status == GNUTLS_E_DECRYPTION_FAILED ||
-          status == GNUTLS_E_UNSUPPORTED_VERSION_PACKET)
+      if (ret == GNUTLS_E_UNEXPECTED_PACKET_LENGTH ||
+          ret == GNUTLS_E_DECRYPTION_FAILED ||
+          ret == GNUTLS_E_UNSUPPORTED_VERSION_PACKET)
         {
           g_clear_error (&my_error);
           g_set_error (error, G_TLS_ERROR, G_TLS_ERROR_NOT_TLS,


obexd: Merge phonebook_data and cache_data

phonebook_data and cache_data are merged in phonebook-tracker.c.
Single structure is used in successive patches to keep reference
to pending D-Bus call.

--- obexd/plugins/phonebook-tracker.c
+++ obexd/plugins/phonebook-tracker.c
@@ -941,14 +941,8 @@
 	gboolean vcardentry;
 	const struct apparam_field *params;
 	GSList *contacts;
-};
-
-struct cache_data {
 	phonebook_cache_ready_cb ready_cb;
 	phonebook_entry_cb entry_cb;
-	void *user_data;
-	GString *listing;
-	int index;
 };

 struct phonebook_index {
@@ -1706,7 +1700,7 @@

 static void add_to_cache(char **reply, int num_fields, void *user_data)
 {
-	struct cache_data *cache = user_data;
+	struct phonebook_data *data = user_data;
 	char *formatted;
 	int i;

@@ -1732,11 +1726,11 @@

 	/* The owner vCard must have the 0 handle */
 	if (strcmp(reply[0], TRACKER_DEFAULT_CONTACT_ME) == 0)
-		cache->entry_cb(reply[0], 0, formatted, "",
-						reply[6], cache->user_data);
+		data->entry_cb(reply[0], 0, formatted, "",
+						reply[6], data->user_data);
 	else
-		cache->entry_cb(reply[0], PHONEBOOK_INVALID_HANDLE, formatted,
-					"", reply[6], cache->user_data);
+		data->entry_cb(reply[0], PHONEBOOK_INVALID_HANDLE, formatted,
+					"", reply[6], data->user_data);

 	g_free(formatted);

@@ -1744,10 +1738,10 @@

 done:
 	if (num_fields <= 0)
-		cache->ready_cb(cache->user_data);
+		data->ready_cb(data->user_data);

 	/*
-	 * cache is freed in query_free_data after call is unreffed.
+	 * data is freed in query_free_data after call is unreffed.
 	 * It is accessible by pointer from data (pending) associated to call.
 	 * Useful in cases when call was terminated.
 	 */
@@ -1919,7 +1913,7 @@
 void *phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
 		phonebook_cache_ready_cb ready_cb, void *user_data, int *err)
 {
-	struct cache_data *cache;
+	struct phonebook_data *data;
 	const char *query;

 	DBG("name %s", name);
@@ -1931,10 +1925,10 @@
 		return NULL;
 	}

-	cache = g_new0(struct cache_data, 1);
-	cache->entry_cb = entry_cb;
-	cache->ready_cb = ready_cb;
-	cache->user_data = user_data;
-
-	return query_tracker(query, 7, add_to_cache, cache, g_free, err);
-}
+	data = g_new0(struct phonebook_data, 1);
+	data->entry_cb = entry_cb;
+	data->ready_cb = ready_cb;
+	data->user_data = user_data;
+
+	return query_tracker(query, 7, add_to_cache, data, g_free, err);
+}


[ubuntu] Removed `
`

[ubuntu] Removed `
`

--- ubuntu/sources/main.c
+++ ubuntu/sources/main.c
@@ -1,95 +1,91 @@
-// Win32_Console.cpp : Defines the entry point for the console application.
-//
-
-//#include "stdafx.h"
-#include "operateImage.h"
-
-int main(int argc, char *argv[], char *envp[]) {
-#if 01
-	//char name[] = "resources/Edges.png";
-	//char name[] = "resources/Untitled100x100.png";
-	//char name[] = "resources/Untitled20x20.png";
-	char name[] = "resources/mask.png";
-	IplImage *aaa = cvLoadImage(name, CV_LOAD_IMAGE_GRAYSCALE);
-	IplImage *tmp3d = cvCreateImage(cvGetSize(aaa), IPL_DEPTH_8U, 3);
-	filterByVolume(aaa, tmp3d, 5000);
-	cvWaitKey(0);
-	cvReleaseImage(&aaa); cvReleaseImage(&tmp3d);
-	return 0;
-#endif
-#if 0
-	char name[] = "/home/uroboro/Downloads/floating_palace_by_jonone.jpg";
-	IplImage *aaa = cvLoadImage(name, -1);
-	if (!aaa) { printf("no image\n"); return 1; }
-	cvNamedWindow(name, 0); cvResizeWindow(name, aaa->width, aaa->height); cvShowImage(name, aaa);
-	cvWaitKey(0); cvReleaseImage(&aaa); cvDestroyWindow(name);
-	return 0;
-#endif
-
-	CvCapture *cv_cap = cvCaptureFromCAM(CV_CAP_ANY);
-	if (!cv_cap) {
-		printf("E: Could not open camera.\n");
-		cvWaitKey(0);
-		return -1;
-	}
-
-	int cam_width = (int)cvGetCaptureProperty(cv_cap, CV_CAP_PROP_FRAME_WIDTH);
-	int cam_height = (int)cvGetCaptureProperty(cv_cap, CV_CAP_PROP_FRAME_HEIGHT);
-	CvSize cam_size = cvSize(cam_width, cam_height);
-
-	Userdata userdata = getSessionUserdata(cam_size);
-
-	cvNamedWindow(INPUT_WINDOW, 0);
-	cvNamedWindow(OUTPUT_WINDOW, 0);
-	cvMoveWindow(OUTPUT_WINDOW, 0, 300);
-
-	cvSetMouseCallback(INPUT_WINDOW, mouseCallback, &userdata);
-
-	setupWindows(&userdata);
-
-	IplImage *input = userdata.input[0];
-
-	int use_cam = 1;
-	int flip = 1;
-	while ((userdata.key = cvWaitKey(userdata.timestep)) != 27) { // wait 50 ms (20 FPS) or for ESC key
-		switch (userdata.key) {
-		case ' ':
-			use_cam = !use_cam;
-			break;
-		case 'F':
-			flip = !flip;
-			break;
-		}
-
-		if (use_cam) {
-			IplImage *cam = cvQueryFrame(cv_cap); // get frame
-			if (!cam) {
-				printf("W: No input.\n");
-				continue;
-			}
-
-			cvCopy(cam, input, NULL);
-			if (flip) {
-				cvFlip(input, NULL, 1);
-			}
-		}
-		operateImage(&userdata);
-
-		cvResizeWindow(INPUT_WINDOW, cam_width / 2, cam_height / 2);
-		cvShowImage(INPUT_WINDOW, input);
-
-		cvResizeWindow(OUTPUT_WINDOW, cam_width / 2, cam_height / 2);
-		cvShowImage(OUTPUT_WINDOW, userdata.output[0]);
-	}
-
-	/* clean up */
-	cvReleaseCapture(&cv_cap);
-
-	freeSessionUserdata(&userdata);
-	destroyWindows(&userdata);
-
-	cvDestroyWindow(INPUT_WINDOW);
-	cvDestroyWindow(OUTPUT_WINDOW);
-
-	return 0;
-}
+#include "operateImage.h"
+
+int main(int argc, char *argv[], char *envp[]) {
+#if 0
+	//char name[] = "resources/Edges.png";
+	//char name[] = "resources/Untitled100x100.png";
+	//char name[] = "resources/Untitled20x20.png";
+	char name[] = "resources/mask.png";
+	IplImage *aaa = cvLoadImage(name, CV_LOAD_IMAGE_GRAYSCALE);
+	IplImage *tmp3d = cvCreateImage(cvGetSize(aaa), IPL_DEPTH_8U, 3);
+	filterByVolume(aaa, tmp3d, 5000);
+	cvWaitKey(0);
+	cvReleaseImage(&aaa); cvReleaseImage(&tmp3d);
+	return 0;
+#endif
+#if 0
+	char name[] = "/home/uroboro/Downloads/floating_palace_by_jonone.jpg";
+	IplImage *aaa = cvLoadImage(name, -1);
+	if (!aaa) { printf("no image\n"); return 1; }
+	cvNamedWindow(name, 0); cvResizeWindow(name, aaa->width, aaa->height); cvShowImage(name, aaa);
+	cvWaitKey(0); cvReleaseImage(&aaa); cvDestroyWindow(name);
+	return 0;
+#endif
+
+	CvCapture *cv_cap = cvCaptureFromCAM(CV_CAP_ANY);
+	if (!cv_cap) {
+		printf("E: Could not open camera.\n");
+		cvWaitKey(0);
+		return -1;
+	}
+
+	int cam_width = (int)cvGetCaptureProperty(cv_cap, CV_CAP_PROP_FRAME_WIDTH);
+	int cam_height = (int)cvGetCaptureProperty(cv_cap, CV_CAP_PROP_FRAME_HEIGHT);
+	CvSize cam_size = cvSize(cam_width, cam_height);
+
+	Userdata userdata = getSessionUserdata(cam_size);
+
+	cvNamedWindow(INPUT_WINDOW, 0);
+	cvNamedWindow(OUTPUT_WINDOW, 0);
+	cvMoveWindow(OUTPUT_WINDOW, 0, 300);
+
+	cvSetMouseCallback(INPUT_WINDOW, mouseCallback, &userdata);
+
+	setupWindows(&userdata);
+
+	IplImage *input = userdata.input[0];
+
+	int use_cam = 1;
+	int flip = 1;
+	while ((userdata.key = cvWaitKey(userdata.timestep)) != 27) { // wait 50 ms (20 FPS) or for ESC key
+		switch (userdata.key) {
+		case ' ':
+			use_cam = !use_cam;
+			break;
+		case 'F':
+			flip = !flip;
+			break;
+		}
+
+		if (use_cam) {
+			IplImage *cam = cvQueryFrame(cv_cap); // get frame
+			if (!cam) {
+				printf("W: No input.\n");
+				continue;
+			}
+
+			cvCopy(cam, input, NULL);
+			if (flip) {
+				cvFlip(input, NULL, 1);
+			}
+		}
+		operateImage(&userdata);
+
+		cvResizeWindow(INPUT_WINDOW, cam_width / 2, cam_height / 2);
+		cvShowImage(INPUT_WINDOW, input);
+
+		cvResizeWindow(OUTPUT_WINDOW, cam_width / 2, cam_height / 2);
+		cvShowImage(OUTPUT_WINDOW, userdata.output[0]);
+	}
+
+	/* clean up */
+	cvReleaseCapture(&cv_cap);
+
+	freeSessionUserdata(&userdata);
+	destroyWindows(&userdata);
+
+	cvDestroyWindow(INPUT_WINDOW);
+	cvDestroyWindow(OUTPUT_WINDOW);
+
+	return 0;
+}


Autodetect Intel Ice Lake (as SKYLAKEX target)

--- cpuid_x86.c
+++ cpuid_x86.c
@@ -1211,7 +1211,7 @@
 	  return CPUTYPE_CORE2;
 	}
 	break;
-      case 1:
+      case 1:  // family 6 exmodel 1
 	switch (model) {
 	case  6:
 	  return CPUTYPE_CORE2;
@@ -1228,7 +1228,7 @@
 	  return CPUTYPE_DUNNINGTON;
 	}
 	break;
-      case  2:
+      case  2: // family 6 exmodel 2
 	switch (model) {
 	case 5:
 	  //Intel Core (Clarkdale) / Core (Arrandale)
@@ -1257,7 +1257,7 @@
 	  return CPUTYPE_NEHALEM;
 	}
 	break;
-      case 3:
+      case 3: // family 6 exmodel 3
 	switch (model) {
 	case  7:
 	    // Bay Trail
@@ -1287,7 +1287,7 @@
 	    return CPUTYPE_NEHALEM;
 	}
 	break;
-      case 4:
+      case 4: // family 6 exmodel 4
         switch (model) {
         case 5:
 	case 6:
@@ -1321,7 +1321,7 @@
 	    return CPUTYPE_NEHALEM;
         }
         break;
-      case 5:
+      case 5:  // family 6 exmodel 5
         switch (model) {
 	case 6:
 	  //Broadwell
@@ -1364,7 +1364,7 @@
 	    return CPUTYPE_NEHALEM;
 	}
 	break;
-      case 6:
+      case 6:  // family 6 exmodel 6
         switch (model) {
         case 6: // Cannon Lake
           if(support_avx512())
@@ -1376,7 +1376,20 @@
 	  else
 	  return CPUTYPE_NEHALEM;
         }
-      break;
+      break;
+      case 7: // family 6 exmodel 7
+        switch (model) {
+        case 14: // Ice Lake
+          if(support_avx512())
+            return CPUTYPE_SKYLAKEX;
+          if(support_avx2())
+            return CPUTYPE_HASWELL;
+          if(support_avx())
+	    return CPUTYPE_SANDYBRIDGE;
+	  else
+	  return CPUTYPE_NEHALEM;
+        }
+      break;
       case 9:
       case 8:
         switch (model) {


support for section and segment offsets in copy menu

--- ui/addressindicator.h
+++ ui/addressindicator.h
@@ -11,11 +11,12 @@
 	Q_OBJECT

 	uint64_t m_begin, m_end;
+	BinaryViewRef m_view;

 public:
 	AddressIndicator(QWidget* parent);

-	void setOffsets(uint64_t begin, uint64_t end);
+	void setOffsets(uint64_t begin, uint64_t end, BinaryViewRef view);

 protected:
 	virtual void showMenu();


make randomize take 64 bit count to allow larger images to be tested
BUG=none
TESTED=untested

Review URL: https://webrtc-codereview.appspot.com/53679004

--- unit_test/unit_test.h
+++ unit_test/unit_test.h
@@ -58,8 +58,8 @@
 }
 #endif

-static inline void MemRandomize(uint8* dst, int len) {
-  int i;
+static inline void MemRandomize(uint8* dst, int64 len) {
+  int64 i;
   for (i = 0; i < len - 1; i += 2) {
     *reinterpret_cast<uint16*>(dst) = random();
     dst += 2;


net: fix IPv4 IHL and VHL define

net: fix IPv4 IHL and VHL define

Fix the RTE_IPV4_VHL_DEF macro that represents the value
for the IPv4 VHL and Minimum IHL header fields according to
rfc791.

Fixes: 2318d8d54565 ("net: define IPv4 IHL and VHL")
Cc: stable@dpdk.org

Reported-by: David Harton <41e0a1e2bcc9f6ca8a5f4060a6583dfdda62fd96@cisco.com>
Signed-off-by: Flavia Musatescu <08b0ac2f219c2a4095a8ee027157afceb099c374@intel.com>
Reviewed-by: Ferruh Yigit <ba8734c3c506d2e3557bd4ac8fdaccd25bdb9aa7@intel.com>

--- lib/librte_net/rte_ip.h
+++ lib/librte_net/rte_ip.h
@@ -101,7 +101,7 @@

 /* IPv4 default fields values */
 #define RTE_IPV4_MIN_IHL    (0x5)
-#define RTE_IPV4_VHL_DEF    (IPVERSION | RTE_IPV4_MIN_IHL)
+#define RTE_IPV4_VHL_DEF    ((IPVERSION << 4) | RTE_IPV4_MIN_IHL)

 /**
  * @internal Calculate a sum of all words in the buffer.


"infinity" check was missed from login_getcapsize(), add it

One manifestation of this bug: all networking users have coredumpsize=0

--- lib/libutil/login_cap.c
+++ lib/libutil/login_cap.c
@@ -21,7 +21,7 @@
  *
  * Low-level routines relating to the user capabilities database
  *
- *	$Id$
+ *	$Id: login_cap.c,v 1.10 1997/02/22 15:08:20 peter Exp $
  */

 #include <stdio.h>
@@ -456,6 +456,12 @@
     return def;
   else if (ret < 0)
     return error;
+
+  /*
+   * "inf" and "infinity" are two special cases for this.
+   */
+  if (!strcasecmp(res, "infinity") || !strcasecmp(res, "inf"))
+    return RLIM_INFINITY;

   errno = 0;
   tot = 0;


This is a bandaid for a pointer dereference when "restart" is used.

git-svn-id: 7d4b18ab7d176792635d6a7a77dd8cbbea8e8daa@3476 d4fa192b-c00b-0410-8231-f00ffab90ce4

--- lib/libvcl/vcc_action.c
+++ lib/libvcl/vcc_action.c
@@ -85,7 +85,8 @@
 		ERRCHK(tl);
 	}
 	Fb(tl, 1, "VRT_done(sp, VCL_RET_RESTART);\n");
-	vcc_ProcAction(tl->curproc, VCL_RET_RESTART, tl->t);
+	assert(VCL_RET_RESTART == (1 << 9));	/* XXX: BANDAID FIXME! */
+	vcc_ProcAction(tl->curproc, 9, tl->t);
 	vcc_NextToken(tl);
 }


Style...

Style...

git-svn-id: 7d4b18ab7d176792635d6a7a77dd8cbbea8e8daa@1766 d4fa192b-c00b-0410-8231-f00ffab90ce4

--- lib/libvcl/vcc_action.c
+++ lib/libvcl/vcc_action.c
@@ -266,6 +266,7 @@
 static void
 parse_purge(struct tokenlist *tl)
 {
+
 	vcc_NextToken(tl);

 	Fb(tl, 0, "VRT_purge(");


Fix memory leak and log spam from SIMTA-Seen-Before

--- receive.c
+++ receive.c
@@ -1971,7 +1971,7 @@
             read_err = PROTOCOL_ERROR;
         }

-        if ( rh->r_seen_before ) {
+        if (( read_err == NO_ERROR ) && rh->r_seen_before ) {
             system_message = "Seen Before";
             filter_message = strdup( rh->r_seen_before );
             message_banner = MESSAGE_DELETE;


remuxer: Fix calculation of total media size.

--- remuxer.c
+++ remuxer.c
@@ -296,13 +296,14 @@
                 if( !sample )
                     return REMUXER_ERR( "Failed to get sample.\n" );
                 /* Append sample into output movie. */
+                uint64_t sample_size = sample->length;      /* sample might be deleted internally after appending. */
                 if( lsmash_append_sample( output.root, out_track_ID, sample ) )
                 {
                     lsmash_delete_sample( sample );
                     return REMUXER_ERR( "Failed to append a sample.\n" );
                 }
                 largest_dts = LSMASH_MAX( largest_dts, (double)dts / input_media_timescale );
-                total_media_size += sample->length;
+                total_media_size += sample_size;
                 eprintf( "Importing: %"PRIu64" bytes\r", total_media_size );
                 ++ in_track->current_sample_number;
                 ++ out_track->current_sample_number;


lib/package_conflicts.c: adapt to pkgdb 0.21 format.

--- lib/package_conflicts.c
+++ lib/package_conflicts.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2012 Juan Romero Pardines.
+ * Copyright (c) 2012-2013 Juan Romero Pardines.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -40,8 +40,8 @@
 	prop_dictionary_t pkgd;
 	prop_object_t obj;
 	prop_object_iterator_t iter;
-	const char *cfpkg, *repopkgver, *pkgver, *pkgname, *repopkgname;
-	char *buf;
+	const char *cfpkg, *repopkgver, *pkgver;
+	char *pkgname, *repopkgname, *buf;

 	pkg_cflicts = prop_dictionary_get(pkg_repod, "conflicts");
 	if (pkg_cflicts == NULL || prop_array_count(pkg_cflicts) == 0)
@@ -49,7 +49,8 @@

 	trans_cflicts = prop_dictionary_get(xhp->transd, "conflicts");
 	prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &repopkgver);
-	prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &repopkgname);
+	repopkgname = xbps_pkg_name(repopkgver);
+	assert(repopkgname);

 	iter = prop_array_iterator(pkg_cflicts);
 	assert(iter);
@@ -63,12 +64,14 @@
 		if ((pkgd = xbps_pkgdb_get_pkg(xhp, cfpkg)) ||
 		    (pkgd = xbps_pkgdb_get_virtualpkg(xhp, cfpkg))) {
 			prop_dictionary_get_cstring_nocopy(pkgd,
-			    "pkgname", &pkgname);
-			if (strcmp(pkgname, repopkgname) == 0)
+			    "pkgver", &pkgver);
+			pkgname = xbps_pkg_name(pkgver);
+			assert(pkgname);
+			if (strcmp(pkgname, repopkgname) == 0) {
+				free(pkgname);
 				continue;
-
-			prop_dictionary_get_cstring_nocopy(pkgd,
-			    "pkgver", &pkgver);
+			}
+			free(pkgname);
 			xbps_dbg_printf(xhp, "found conflicting installed "
 			    "pkg %s with pkg in transaction %s\n", pkgver,
 			    repopkgver);
@@ -84,12 +87,14 @@
 		if ((pkgd = xbps_find_pkg_in_array(unsorted, cfpkg)) ||
 		    (pkgd = xbps_find_virtualpkg_in_array(xhp, unsorted, cfpkg))) {
 			prop_dictionary_get_cstring_nocopy(pkgd,
-			    "pkgname", &pkgname);
-			if (strcmp(pkgname, repopkgname) == 0)
+			    "pkgver", &pkgver);
+			pkgname = xbps_pkg_name(pkgver);
+			assert(pkgname);
+			if (strcmp(pkgname, repopkgname) == 0) {
+				free(pkgname);
 				continue;
-
-			prop_dictionary_get_cstring_nocopy(pkgd,
-			    "pkgver", &pkgver);
+			}
+			free(pkgname);
 			xbps_dbg_printf(xhp, "found conflicting pkgs in "
 			    "transaction %s <-> %s\n", pkgver, repopkgver);
 			buf = xbps_xasprintf("%s conflicts with "
@@ -100,4 +105,5 @@
 		}
 	}
 	prop_object_iterator_release(iter);
+	free(repopkgname);
 }


don't accept mail for unknown local users, even if global relay enabled

--- receive.c
+++ receive.c
@@ -374,80 +374,87 @@
      * probably preserve the results of our DNS check.
      */

-    if (( domain != NULL ) && ( simta_global_relay == 0 )) {
-	/*
-	 * Here we do an initial lookup in our domain table.  This is our
-	 * best opportunity to decline recipients that are not local or
-	 * unknown, since if we give an error the connecting client generates
-	 * the bounce.
-	 */
-	/* XXX check config file, check MXes */
-	if (( rc = check_hostname( domain )) != 0 ) {
-	    if ( rc < 0 ) {
-		syslog( LOG_ERR, "f_rcpt check_host: %s: failed", domain );
-		return( RECEIVE_SYSERROR );
-	    } else {
-		if ( snet_writef( snet, "%d %s: unknown host\r\n", 550,
+    if ( domain != NULL ) {
+	if ( simta_global_relay == 0 ) {
+	    /*
+	     * Here we do an initial lookup in our domain table.  This is
+	     * our best opportunity to decline recipients that are not
+	     * local or unknown, since if we give an error the connecting
+	     * client generates the bounce.
+	     */
+	    if (( rc = check_hostname( domain )) != 0 ) {
+		if ( rc < 0 ) {
+		    syslog( LOG_ERR, "f_rcpt check_host: %s: failed", domain );
+		    return( RECEIVE_SYSERROR );
+		} else {
+		    if ( snet_writef( snet, "%d %s: unknown host\r\n", 550,
+			    domain ) < 0 ) {
+			syslog( LOG_ERR, "f_rcpt snet_writef: %m" );
+			return( RECEIVE_CLOSECONNECTION );
+		    }
+		    syslog( LOG_ERR, "f_rcpt check_host %s: unknown host",
+			    domain );
+		    return( RECEIVE_OK );
+		}
+	    }
+	}
+
+	if (( host = host_local( domain )) == NULL ) {
+	    if ( simta_global_relay == 0 ) {
+		if ( snet_writef( snet,
+			"551 User not local; please try <%s>\r\n",
 			domain ) < 0 ) {
 		    syslog( LOG_ERR, "f_rcpt snet_writef: %m" );
 		    return( RECEIVE_CLOSECONNECTION );
 		}
-		syslog( LOG_ERR, "f_rcpt check_host %s: unknown host", domain );
 		return( RECEIVE_OK );
 	    }
-	}
-
-	if (( host = host_local( domain )) == NULL ) {
-	    if ( snet_writef( snet, "551 User not local; please try <%s>\r\n",
-		    addr ) < 0 ) {
-		syslog( LOG_ERR, "f_rcpt snet_writef: %m" );
-		return( RECEIVE_CLOSECONNECTION );
-	    }
-	    return( RECEIVE_OK );
-	}
-
-	/*
-	 * For local mail, we now have 5 minutes (rfc1123 5.3.2) to decline
-	 * to receive the message.  If we're in the default configuration, we
-	 * check the passwd and alias file.  Other configurations use "mailer"
-	 * specific checks.
-	 */
-
-	/* rfc 2821 section 3.7
-	 * A relay SMTP server is usually the target of a DNS MX record that
-	 * designates it, rather than the final delivery system.  The relay
-	 * server may accept or reject the task of relaying the mail in the same
-	 * way it accepts or rejects mail for a local user.  If it accepts the
-	 * task, it then becomes an SMTP client, establishes a transmission
-	 * channel to the next SMTP server specified in the DNS (according to
-	 * the rules in section 5), and sends it the mail.  If it declines to
-	 * relay mail to a particular address for policy reasons, a 550 response
-	 * SHOULD be returned.
-	 */
-
-	switch( local_address( addr, domain, host )) {
-	case NOT_LOCAL:
-	    syslog( LOG_INFO, "f_rcpt %s: address not local", addr );
-	    if ( snet_writef( snet,
-		    "%d Requested action not taken: User not found.\r\n",
-		    550 ) < 0 ) {
-		syslog( LOG_ERR, "f_rcpt snet_writef: %m" );
-		return( RECEIVE_CLOSECONNECTION );
-	    }
-	    return( RECEIVE_OK );
-
-	case LOCAL_ERROR:
-	default:
-	    syslog( LOG_ERR, "f_rcpt local_address %s: error", addr );
-	    if ( snet_writef( snet, "%d Requested action aborted: "
-		    "local error in processing.\r\n", 451 ) < 0 ) {
-		syslog( LOG_ERR, "f_rcpt snet_writef: %m" );
-		return( RECEIVE_CLOSECONNECTION );
-	    }
-	    return( RECEIVE_SYSERROR );
-
-	case LOCAL_ADDRESS:
-	    break;
+
+	} else {
+	    /*
+	     * For local mail, we now have 5 minutes (rfc1123 5.3.2)
+	     * to decline to receive the message.  If we're in the
+	     * default configuration, we check the passwd and alias file.
+	     * Other configurations use "mailer" specific checks.
+	     */
+
+	    /* rfc 2821 section 3.7
+	     * A relay SMTP server is usually the target of a DNS MX record
+	     * that designates it, rather than the final delivery system.
+	     * The relay server may accept or reject the task of relaying
+	     * the mail in the same way it accepts or rejects mail for
+	     * a local user.  If it accepts the task, it then becomes an
+	     * SMTP client, establishes a transmission channel to the next
+	     * SMTP server specified in the DNS (according to the rules
+	     * in section 5), and sends it the mail.  If it declines to
+	     * relay mail to a particular address for policy reasons, a 550
+	     * response SHOULD be returned.
+	     */
+
+	    switch( local_address( addr, domain, host )) {
+	    case NOT_LOCAL:
+		syslog( LOG_INFO, "f_rcpt %s: address not local", addr );
+		if ( snet_writef( snet,
+			"%d Requested action not taken: User not found.\r\n",
+			550 ) < 0 ) {
+		    syslog( LOG_ERR, "f_rcpt snet_writef: %m" );
+		    return( RECEIVE_CLOSECONNECTION );
+		}
+		return( RECEIVE_OK );
+
+	    case LOCAL_ERROR:
+	    default:
+		syslog( LOG_ERR, "f_rcpt local_address %s: error", addr );
+		if ( snet_writef( snet, "%d Requested action aborted: "
+			"local error in processing.\r\n", 451 ) < 0 ) {
+		    syslog( LOG_ERR, "f_rcpt snet_writef: %m" );
+		    return( RECEIVE_CLOSECONNECTION );
+		}
+		return( RECEIVE_SYSERROR );
+
+	    case LOCAL_ADDRESS:
+		break;
+	    }
 	}
     }


remuxer: Use lsmash_get/set_itunes_metadata to copy iTunes metadata.

--- remuxer.c
+++ remuxer.c
@@ -69,9 +69,10 @@
 {
     lsmash_root_t                 *root;
     input_track_t                 *track;
-    lsmash_itunes_metadata_list_t *itunes_meta_list;
+    lsmash_itunes_metadata_t      *itunes_metadata;
     lsmash_movie_parameters_t      movie_param;
     uint32_t                       num_tracks;
+    uint32_t                       num_itunes_metadata;
     uint32_t                       current_track_number;
 } input_movie_t;

@@ -108,13 +109,32 @@
 {
     if( !input )
         return;
-    lsmash_destroy_itunes_metadata( input->itunes_meta_list );
+    if( input->itunes_metadata )
+    {
+        for( uint32_t i = 0; i < input->num_itunes_metadata; i++ )
+        {
+            lsmash_itunes_metadata_t *metadata = &input->itunes_metadata[i];
+            if( metadata->type == ITUNES_METADATA_TYPE_STRING )
+            {
+                if( metadata->value.string )
+                    free( metadata->value.string );
+            }
+            else if( metadata->type == ITUNES_METADATA_TYPE_BINARY )
+                if( metadata->value.binary.data )
+                    free( metadata->value.binary.data );
+            if( metadata->meaning )
+                free( metadata->meaning );
+            if( metadata->name )
+                free( metadata->name );
+        }
+        free( input->itunes_metadata );
+    }
     if( input->track )
         free( input->track );
     lsmash_destroy_root( input->root );
-    input->root = NULL;
-    input->track = NULL;
-    input->itunes_meta_list = NULL;
+    input->root            = NULL;
+    input->track           = NULL;
+    input->itunes_metadata = NULL;
 }

 static void cleanup_output_movie( output_movie_t *output )
@@ -124,7 +144,7 @@
     if( output->track )
         free( output->track );
     lsmash_destroy_root( output->root );
-    output->root = NULL;
+    output->root  = NULL;
     output->track = NULL;
 }

@@ -213,6 +233,65 @@
              LSMASH_REV, LSMASH_GIT_HASH, __DATE__, __TIME__ );
 }

+static char *duplicate_string( char *src )
+{
+    if( !src )
+        return NULL;
+    int dst_size = strlen( src ) + 1;
+    char *dst = malloc( dst_size );
+    if( !dst )
+        return NULL;
+    memcpy( dst, src, dst_size );
+    return dst;
+}
+
+static int get_itunes_metadata( lsmash_root_t *root, uint32_t metadata_number, lsmash_itunes_metadata_t *metadata )
+{
+    memset( metadata, 0, sizeof(lsmash_itunes_metadata_t) );
+    if( lsmash_get_itunes_metadata( root, metadata_number, metadata ) )
+        return -1;
+    lsmash_itunes_metadata_t shadow = *metadata;
+    metadata->meaning = NULL;
+    metadata->name    = NULL;
+    memset( &metadata->value, 0, sizeof(lsmash_itunes_metadata_value_t) );
+    if( shadow.meaning )
+    {
+        char *temp = duplicate_string( shadow.meaning );
+        if( !temp )
+            return -1;
+        metadata->meaning = temp;
+    }
+    if( shadow.name )
+    {
+        char *temp = duplicate_string( shadow.name );
+        if( !temp )
+            goto fail;
+        metadata->name = temp;
+    }
+    if( shadow.type == ITUNES_METADATA_TYPE_STRING )
+    {
+        char *temp = duplicate_string( shadow.value.string );
+        if( !temp )
+            goto fail;
+        metadata->value.string = temp;
+    }
+    else if( shadow.type == ITUNES_METADATA_TYPE_BINARY )
+    {
+        uint8_t *temp = malloc( shadow.value.binary.size );
+        if( !temp )
+            goto fail;
+        memcpy( temp, shadow.value.binary.data, shadow.value.binary.size );
+        metadata->value.binary.data = temp;
+    }
+    return 0;
+fail:
+    if( metadata->meaning )
+        free( metadata->meaning );
+    if( metadata->name )
+        free( metadata->name );
+    return -1;
+}
+
 static int get_movie( input_movie_t *input, char *input_name )
 {
     if( !strcmp( input_name, "-" ) )
@@ -220,13 +299,29 @@
     input->root = lsmash_open_movie( input_name, LSMASH_FILE_MODE_READ );
     if( !input->root )
         return ERROR_MSG( "failed to open input file.\n" );
-    input->itunes_meta_list = lsmash_export_itunes_metadata( input->root );
-    if( !input->itunes_meta_list )
-        return ERROR_MSG( "failed to get iTunes metadata.\n" );
+    input->num_itunes_metadata = lsmash_count_itunes_metadata( input->root );
+    if( input->num_itunes_metadata )
+    {
+        input->itunes_metadata = malloc( input->num_itunes_metadata * sizeof(lsmash_itunes_metadata_t) );
+        if( !input->itunes_metadata )
+            return ERROR_MSG( "failed to alloc iTunes metadata.\n" );
+        uint32_t itunes_metadata_count = 0;
+        for( uint32_t i = 1; i <= input->num_itunes_metadata; i++ )
+        {
+            if( get_itunes_metadata( input->root, i, &input->itunes_metadata[itunes_metadata_count] ) )
+            {
+                WARNING_MSG( "failed to get an iTunes metadata.\n" );
+                continue;
+            }
+            ++itunes_metadata_count;
+        }
+        input->num_itunes_metadata = itunes_metadata_count;
+    }
     input->current_track_number = 1;
     lsmash_movie_parameters_t *movie_param = &input->movie_param;
     lsmash_initialize_movie_parameters( movie_param );
-    lsmash_get_movie_parameters( input->root, movie_param );
+    if( lsmash_get_movie_parameters( input->root, movie_param ) )
+        return ERROR_MSG( "failed to get movie parameters.\n" );
     uint32_t num_tracks = input->num_tracks = movie_param->number_of_tracks;
     /* Create tracks. */
     input_track_t *in_track = input->track = malloc( num_tracks * sizeof(input_track_t) );
@@ -507,12 +602,15 @@
     return lsmash_set_movie_parameters( output->root, &output->movie_param );
 }

-static int set_itunes_metadata( output_movie_t *output, input_movie_t *input, int num_input )
+static void set_itunes_metadata( output_movie_t *output, input_movie_t *input, int num_input )
 {
     for( int i = 0; i < num_input; i++ )
-        if( lsmash_import_itunes_metadata( output->root, input[i].itunes_meta_list ) )
-            return -1;
-    return 0;
+        for( uint32_t j = 0; j < input[i].num_itunes_metadata; j++ )
+            if( lsmash_set_itunes_metadata( output->root, input[i].itunes_metadata[j] ) )
+            {
+                WARNING_MSG( "failed to set an iTunes metadata.\n" );
+                continue;
+            }
 }

 static int set_starting_point( input_movie_t *input, input_track_t *in_track, uint32_t seek_point, int consider_rap )
@@ -572,8 +670,7 @@
         return ERROR_MSG( "failed to set output movie parameters.\n" );
     output_movie_t *output = remuxer->output;
     input_movie_t  *input  = remuxer->input;
-    if( set_itunes_metadata( output, input, remuxer->num_input ) )
-        return ERROR_MSG( "failed to set iTunes metadata.\n" );
+    set_itunes_metadata( output, input, remuxer->num_input );
     /* Allocate output tracks. */
     for( int i = 0; i < remuxer->num_input; i++ )
         output->num_tracks += input[i].num_tracks;


remuxer: Reduce sample accessing.

remuxer: Reduce sample accessing.

--- remuxer.c
+++ remuxer.c
@@ -49,6 +49,8 @@

 typedef struct
 {
+    lsmash_sample_t          *sample;
+    double                    dts;
     int                       reach_end_of_media_timeline;
     uint32_t                  track_ID;
     uint32_t                  last_sample_delta;
@@ -195,6 +197,8 @@
         if( lsmash_get_last_sample_delta_from_media_timeline( input->root, in_track[i].track_ID, &in_track[i].last_sample_delta ) )
             return ERROR_MSG( "failed to get the last sample delta.\n" );
         in_track[i].current_sample_number = 1;
+        in_track[i].sample                = NULL;
+        in_track[i].dts                   = 0;
     }
     lsmash_discard_boxes( input->root );
     return 0;
@@ -511,48 +515,52 @@
         /* Try append a sample in an input track where we didn't reach the end of media timeline. */
         if( !in_track->reach_end_of_media_timeline )
         {
-            output_track_t *out_track = &out_movie->track[out_movie->current_track_number - 1];
-            uint32_t in_track_ID = in_track->track_ID;
-            uint32_t out_track_ID = out_track->track_ID;
-            uint32_t input_media_timescale = in_track->media_param.timescale;
-            /* Get a DTS from a track in an input movie. */
-            uint64_t dts;
-            if( lsmash_get_dts_from_media_timeline( in_movie->root, in_track_ID, in_track->current_sample_number, &dts ) )
+            lsmash_sample_t *sample = in_track->sample;
+            /* Get a new sample data if the track doesn't hold any one. */
+            if( !sample )
             {
-                if( lsmash_check_sample_existence_in_media_timeline( in_movie->root, in_track_ID, in_track->current_sample_number ) )
-                    return ERROR_MSG( "failed to get the DTS.\n" );
+                sample = lsmash_get_sample_from_media_timeline( in_movie->root, in_track->track_ID, in_track->current_sample_number );
+                if( sample )
+                {
+                    in_track->sample = sample;
+                    in_track->dts = (double)sample->dts / in_track->media_param.timescale;
+                }
                 else
                 {
+                    if( lsmash_check_sample_existence_in_media_timeline( in_movie->root, in_track->track_ID, in_track->current_sample_number ) )
+                        return ERROR_MSG( "failed to get a sample.\n" );
+                    /* No more appendable samples in this track. */
+                    in_track->sample = NULL;
                     in_track->reach_end_of_media_timeline = 1;
                     if( --num_active_input_tracks == 0 )
                         break;      /* end of muxing */
                 }
             }
-            /* Get and append a sample if it's good time. */
-            else if( ((double)dts / input_media_timescale) <= largest_dts
-             || num_consecutive_sample_skip == num_active_input_tracks )
+            if( sample )
             {
-                /* Get an actual sample data from a track in an input movie. */
-                lsmash_sample_t *sample = lsmash_get_sample_from_media_timeline( in_movie->root, in_track_ID, in_track->current_sample_number );
-                if( !sample )
-                    return ERROR_MSG( "failed to get sample.\n" );
-                /* Append sample into output movie. */
-                uint64_t sample_size = sample->length;      /* sample might be deleted internally after appending. */
-                if( lsmash_append_sample( out_movie->root, out_track_ID, sample ) )
+                /* Append a sample if meeting a condition. */
+                if( in_track->dts <= largest_dts || num_consecutive_sample_skip == num_active_input_tracks )
                 {
-                    lsmash_delete_sample( sample );
-                    return ERROR_MSG( "failed to append a sample.\n" );
+                    /* Append a sample into output movie. */
+                    uint64_t sample_size = sample->length;      /* sample might be deleted internally after appending. */
+                    output_track_t *out_track = &out_movie->track[out_movie->current_track_number - 1];
+                    if( lsmash_append_sample( out_movie->root, out_track->track_ID, sample ) )
+                    {
+                        lsmash_delete_sample( sample );
+                        return ERROR_MSG( "failed to append a sample.\n" );
+                    }
+                    largest_dts = LSMASH_MAX( largest_dts, in_track->dts );
+                    in_track->sample = NULL;
+                    ++ in_track->current_sample_number;
+                    num_consecutive_sample_skip = 0;
+                    total_media_size += sample_size;
+                    /* Print, per 256 samples, total size of imported media. */
+                    if( ++sample_count == 0 )
+                        eprintf( "Importing: %"PRIu64" bytes\r", total_media_size );
                 }
-                largest_dts = LSMASH_MAX( largest_dts, (double)dts / input_media_timescale );
-                total_media_size += sample_size;
-                ++ in_track->current_sample_number;
-                num_consecutive_sample_skip = 0;
-                /* Print, per 256 samples, total size of imported media. */
-                if( ++sample_count == 0 )
-                    eprintf( "Importing: %"PRIu64" bytes\r", total_media_size );
+                else
+                    ++num_consecutive_sample_skip;      /* Skip appendig sample. */
             }
-            else
-                ++num_consecutive_sample_skip;      /* Skip appendig sample. */
         }
         /* Move the next track. */
         ++ in_movie->current_track_number;


Don't abort on maximum number of JSON stacks: return ENOMEM.  Eventually this will need to be re-written to be expandable.

--- kcgijson.c
+++ kcgijson.c
@@ -320,15 +320,16 @@
 {
 	enum kcgi_err	 er;

-	if ((er = kjson_check(r, key)) != KCGI_OK)
-		return er;
-	if ((er = kcgi_writer_putc(r->arg, '[')) != KCGI_OK)
-		return er;
-
 	if (r->stackpos >= KJSON_STACK_MAX - 1) {
 		XWARNX("maximum json stack size exceeded");
-		abort();
-	}
+		return KCGI_ENOMEM;
+	}
+
+	if ((er = kjson_check(r, key)) != KCGI_OK)
+		return er;
+	if ((er = kcgi_writer_putc(r->arg, '[')) != KCGI_OK)
+		return er;
+
 	r->stack[++r->stackpos].elements = 0;
 	r->stack[r->stackpos].type = KJSON_ARRAY;
 	return KCGI_OK;
@@ -406,15 +407,16 @@
 {
 	enum kcgi_err	 er;

-	if ((er = kjson_check(r, key)) != KCGI_OK)
-		return er;
-	if ((er = kcgi_writer_putc(r->arg, '"')) != KCGI_OK)
-		return er;
-
 	if (r->stackpos >= KJSON_STACK_MAX - 1) {
 		XWARNX("maximum json stack size exceeded");
-		abort();
-	}
+		return KCGI_ENOMEM;
+	}
+
+	if ((er = kjson_check(r, key)) != KCGI_OK)
+		return er;
+	if ((er = kcgi_writer_putc(r->arg, '"')) != KCGI_OK)
+		return er;
+
 	r->stack[++r->stackpos].elements = 0;
 	r->stack[r->stackpos].type = KJSON_STRING;
 	return KCGI_OK;
@@ -446,15 +448,16 @@
 {
 	enum kcgi_err	 er;

-	if ((er = kjson_check(r, key)) != KCGI_OK)
-		return er;
-	if ((er = kcgi_writer_putc(r->arg, '{')) != KCGI_OK)
-		return er;
-
 	if (r->stackpos >= KJSON_STACK_MAX - 1) {
 		XWARNX("maximum json stack size exceeded");
-		abort();
-	}
+		return KCGI_ENOMEM;
+	}
+
+	if ((er = kjson_check(r, key)) != KCGI_OK)
+		return er;
+	if ((er = kcgi_writer_putc(r->arg, '{')) != KCGI_OK)
+		return er;
+
 	r->stack[++r->stackpos].elements = 0;
 	r->stack[r->stackpos].type = KJSON_OBJECT;
 	return KCGI_OK;


Lines authored by gkassabli

Lines authored by gkassabli

This commit forms part of the blame-preserving initial commit suite.

--- lib/yogajni/yoga/Yoga.c
+++ lib/yogajni/yoga/Yoga.c
@@ -3323,3 +3323,6 @@
     config->pointScaleFactor = 0.0f;
   } else {
     config->pointScaleFactor = 1.0f / pixelsInPoint;
+  }
+}
+