Define MAX_SCRIPT_ELEMENT_SIZE

Define MAX_SCRIPT_ELEMENT_SIZE

--- src/script.h
+++ src/script.h
@@ -20,7 +20,7 @@
 typedef std::vector<unsigned char> valtype;

 class CTransaction;
-
+static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520; // bytes
 /** Signature hash types/flags */
 enum
 {


Reorder conditions.

Reorder conditions.

--- src/search.c
+++ src/search.c
@@ -86,7 +86,7 @@
   //   that we compare the right part of the block to the ref_data.
   // - Reduce block_width and block_height so that the the size of the area
   //   being compared is correct.
-  if (left && top) {
+  if (top && left) {
     result += cor_sad(pic_data,
                       &ref_data[top * width + left],
                       left, top, width);
@@ -112,13 +112,6 @@
     result += hor_sad(&pic_data[top * width + (block_width - right)],
                       &ref_data[top * width + (block_width - right - 1)],
                       right, block_height - top, width);
-  } else if (top) {
-    result += ver_sad(pic_data,
-                      &ref_data[top * width],
-                      block_width, top, width);
-    result += reg_sad(&pic_data[top * width],
-                      &ref_data[top * width],
-                      block_width, block_height - top, width);
   } else if (bottom && left) {
     result += hor_sad(pic_data,
                       &ref_data[left],
@@ -145,6 +138,20 @@
     result += cor_sad(&pic_data[(block_height - bottom) * width + block_width - right],
                       &ref_data[(block_height - bottom - 1) * width + block_width - right - 1],
                       right, bottom, width);
+  } else if (top) {
+    result += ver_sad(pic_data,
+                      &ref_data[top * width],
+                      block_width, top, width);
+    result += reg_sad(&pic_data[top * width],
+                      &ref_data[top * width],
+                      block_width, block_height - top, width);
+  } else if (bottom) {
+    result += reg_sad(pic_data,
+                      ref_data,
+                      block_width, block_height - bottom, width);
+    result += ver_sad(&pic_data[(block_height - bottom) * width],
+                      &ref_data[(block_height - bottom - 1) * width],
+                      block_width, bottom, width);
   } else if (left) {
     result += hor_sad(pic_data,
                       &ref_data[left],
@@ -159,13 +166,6 @@
     result += hor_sad(&pic_data[block_width - right],
                       &ref_data[block_width - right - 1],
                       right, block_height, width);
-  } else if (bottom) {
-    result += reg_sad(pic_data,
-                      ref_data,
-                      block_width, block_height - bottom, width);
-    result += ver_sad(&pic_data[(block_height - bottom) * width],
-                      &ref_data[(block_height - bottom - 1) * width],
-                      block_width, bottom, width);
   } else {
     result += reg_sad(pic_data, ref_data, block_width, block_height, width);
   }


Fix ERROR_ACCESS_DENIED on windows #158

Fix ERROR_ACCESS_DENIED on windows #158

--- src/search.c
+++ src/search.c
@@ -205,7 +205,7 @@
 #ifdef _WIN32
         {
             HANDLE hmmap = CreateFileMapping(
-                (HANDLE)_get_osfhandle(fd), 0, PAGE_READONLY, 0, f_len, "ag");
+                (HANDLE)_get_osfhandle(fd), 0, PAGE_READONLY, 0, f_len, NULL);
             buf = (char*) MapViewOfFile(hmmap, FILE_SHARE_READ, 0, 0, f_len);
             if (hmmap != NULL)
               CloseHandle(hmmap);


MB-19259: Fix data race on DcpConsumer::backoffs

This member is read by stats processing concurrently with DcpConsumer
updating it. Change to RelaxedAtomic<>

As reported by ThreadSanitizer:

WARNING: ThreadSanitizer: data race (pid=24629)
  Read of size 4 at 0x7d5000016b9c by main thread (mutexes: write M27034, write M2479):
    #0 void ConnHandler::addStat<unsigned int>(), void const*) ep-engine/src/tapconnection.h:291:18 (ep.so+0x00000004e993)
    #1 DcpConsumer::addStats(), void const*) ep-engine/src/dcp/consumer.cc:731:5 (ep.so+0x00000005a2c3)
    ...

  Previous write of size 4 at 0x7d5000016b9c by thread T10:
    #0 DcpConsumer::processBufferedItems() ep-engine/src/dcp/consumer.cc:755:17 (ep.so+0x0000000539c3)
    #1 Processer::run() ep-engine/src/dcp/consumer.cc:57:13 (ep.so+0x00000005376b)
    #2 ExecutorThread::run() ep-engine/src/executorthread.cc:115:26 (ep.so+0x0000000e944e)
    ...

Change-Id: Iabddcc06213fbb80815d4b464c459adb922a0eff
Reviewed-on: http://review.couchbase.org/62977
Well-Formed: buildbot <80754af91bfb6d1073585b046fe0a474ce868509@couchbase.com>
Reviewed-by: Jim Walker <1cd02e31b43620d7c664e038ca42a060d61727b9@couchbase.com>
Reviewed-by: Will Gardner <cbd6f5d9092d9ef7d5c0510d53bba134b22c02f2@couchbase.com>
Tested-by: buildbot <80754af91bfb6d1073585b046fe0a474ce868509@couchbase.com>

--- src/dcp-consumer.h
+++ src/dcp-consumer.h
@@ -22,6 +22,9 @@

 #include "tapconnection.h"
 #include "dcp-stream.h"
+
+#include <relaxed_atomic.h>
+
 typedef RCPtr<PassiveStream> passive_stream_t;

 class DcpResponse;
@@ -126,7 +129,7 @@
     opaque_map opaqueMap_;

     rel_time_t lastNoopTime;
-    uint32_t backoffs;
+    Couchbase::RelaxedAtomic<uint32_t> backoffs;
     uint32_t noopInterval;
     bool enableNoop;
     bool sendNoopInterval;


Fix bignum adjusting zero

Fix bignum adjusting zero

--- src/miniscm.c
+++ src/miniscm.c
@@ -2403,7 +2403,7 @@
 	type(z) = T_NUMBER;
 	set_num_integer(z);
 	if (col <= 1 && INT32_MIN <= d && d <= INT32_MAX) {
-		ivalue(z) = (int32_t)d;
+		ivalue(z) = (col == 0) ? 0 : (int32_t)d;
 		bignum(z) = NIL;
 	} else {
 		ivalue(z) = sign * col;


Add FULL_CU_SPLIT_SEARCH macro for disabling cu split optimization.

--- src/search.c
+++ src/search.c
@@ -46,6 +46,13 @@
   ((x) >= 0 && (y) >= 0 \
   && (x) + (block_width) <= (width) \
   && (y) + (block_height) <= (height))
+
+#ifndef CU_SPLIT_COST
+#  define CU_SPLIT_COST 9
+#endif
+#ifndef FULL_CU_SPLIT_SEARCH
+#  define FULL_CU_SPLIT_SEARCH false
+#endif

 /**
  * This is used in the hexagon_search to select 3 points to search.
@@ -1404,11 +1411,7 @@
     // Bitcost
     cost += (cur_cu->type == CU_INTER ? cur_cu->inter.bitcost : cur_cu->intra[PU_INDEX(x >> 2, y >> 2)].bitcost) * (int32_t)(encoder_state->global->cur_lambda_cost+0.5);
   }
-
-#ifndef CU_SPLIT_COST
-#  define CU_SPLIT_COST 9
-#endif
-
+
   // Recursively split all the way to max search depth.
   if (depth < MAX_INTRA_SEARCH_DEPTH || (depth < MAX_INTER_SEARCH_DEPTH && encoder_state->global->slicetype != SLICE_I)) {
     int half_cu = cu_width / 2;
@@ -1419,7 +1422,7 @@
     // If skip mode was selected for the block, skip further search.
     // Skip mode means there's no coefficients in the block, so splitting
     // might not give any better results but takes more time to do.
-    if(cur_cu->type == CU_NOTSET || cbf) {
+    if (cur_cu->type == CU_NOTSET || cbf || FULL_CU_SPLIT_SEARCH) {
       split_cost += search_cu(encoder_state, x,           y,           depth + 1, work_tree);
       split_cost += search_cu(encoder_state, x + half_cu, y,           depth + 1, work_tree);
       split_cost += search_cu(encoder_state, x,           y + half_cu, depth + 1, work_tree);


npcx: adc: Properly wait for conversion interrupt

Certain tasks (eg. chipset) may be woken directly by other tasks /
unrelated interrupts. Add an explicit wake event for ADC conversion done
so that we're not mistakenly woken.

BUG=chrome-os-partner:54971
BRANCH=None
TEST=Manual on kevin rev5, run "reboot ap-off" then "sysjump rw", verify
console isn't spammed with GPIO warning message due to ADC failure to
read board version.

Signed-off-by: Shawn Nematbakhsh <5259333ce42e3ace6a73988cec7115ed9d3a661a@chromium.org>

Change-Id: I5477e11c2b434e4b350d81393f4463eea1a91e7c
Reviewed-on: https://chromium-review.googlesource.com/366943
Commit-Ready: Shawn N <5259333ce42e3ace6a73988cec7115ed9d3a661a@chromium.org>
Tested-by: Shawn N <5259333ce42e3ace6a73988cec7115ed9d3a661a@chromium.org>
Reviewed-by: Randall Spangler <62698fdbb84d1779579ee80c3f39fac22017e5bc@chromium.org>

--- chip/npcx/adc.c
+++ chip/npcx/adc.c
@@ -60,17 +60,6 @@
 DECLARE_HOOK(HOOK_FREQ_CHANGE, adc_freq_changed, HOOK_PRIO_DEFAULT);

 /**
- * Get current voltage data of the specified channel.
- *
- * @param input_ch		npcx input channel to read
- * @return ADC channel voltage data.(Range: 0~1023)
- */
-static int get_channel_data(enum npcx_adc_input_channel input_ch)
-{
-	return GET_FIELD(NPCX_CHNDAT(input_ch), NPCX_CHNDAT_CHDAT_FIELD);
-}
-
-/**
  * Flush an ADC sequencer and initiate a read.
  *
  * @param   input_ch    operation channel
@@ -105,11 +94,11 @@
 	SET_BIT(NPCX_ADCCNF, NPCX_ADCCNF_START);

 	/* Wait for interrupt */
-	event = task_wait_event(timeout);
+	event = task_wait_event_mask(TASK_EVENT_ADC_DONE, timeout);

 	task_waiting = TASK_ID_INVALID;

-	return event != TASK_EVENT_TIMER;
+	return (event == TASK_EVENT_ADC_DONE);

 }

@@ -124,15 +113,17 @@
 	const struct adc_t *adc = adc_channels + ch;
 	static struct mutex adc_lock;
 	int value;
+	uint16_t chn_data;

 	mutex_lock(&adc_lock);

 	if (start_single_and_wait(adc->input_ch, ADC_TIMEOUT_US)) {
+		chn_data = NPCX_CHNDAT(adc->input_ch);
 		if ((adc->input_ch ==
 			GET_FIELD(NPCX_ASCADD, NPCX_ASCADD_SADDR_FIELD))
-			&& (IS_BIT_SET(NPCX_CHNDAT(adc->input_ch),
+			&& (IS_BIT_SET(chn_data,
 					NPCX_CHNDAT_NEW))) {
-			value = get_channel_data(adc->input_ch) *
+			value = GET_FIELD(chn_data, NPCX_CHNDAT_CHDAT_FIELD) *
 				adc->factor_mul / adc->factor_div + adc->shift;
 		} else {
 			value = ADC_READ_ERROR;
@@ -167,7 +158,7 @@

 		/* Wake up the task which was waiting for the interrupt */
 		if (task_waiting != TASK_ID_INVALID)
-			task_wake(task_waiting);
+			task_set_event(task_waiting, TASK_EVENT_ADC_DONE, 0);
 	}
 }
 DECLARE_IRQ(NPCX_IRQ_ADC, adc_interrupt, 3);
@@ -205,6 +196,5 @@

 	/* Enable IRQs */
 	task_enable_irq(NPCX_IRQ_ADC);
-
 }
 DECLARE_HOOK(HOOK_INIT, adc_init, HOOK_PRIO_INIT_ADC);


Fix possibilities of crashing in GC

Fix possibilities of crashing in GC

--- src/miniscm.c
+++ src/miniscm.c
@@ -1619,20 +1619,22 @@
 }

 /* append list -- make new cells */
-pointer append(register pointer a, register pointer b)
-{
-	register pointer p = b, q;
+pointer append(pointer a, pointer b)
+{
+	register pointer q;

 	if (a != NIL) {
+		push_sink(&b);
 		a = reverse(a);
+		pop_sink();
 		while (a != NIL) {
 			q = cdr(a);
-			cdr(a) = p;
-			p = a;
+			cdr(a) = b;
+			b = a;
 			a = q;
 		}
 	}
-	return p;
+	return b;
 }

 /* list length */
@@ -2649,7 +2651,9 @@
 		s_return(mcons(code, x, args));

 	case OP_QQUOTE6:	/* quasiquote -- 'cons */
+		push_sink(&value);
 		s_save(OP_QQUOTE7, value, code);
+		pop_sink();
 		code = cdr(code);
 		s_goto(OP_QQUOTE1);

@@ -2667,16 +2671,17 @@
 		if (is_pair(car(code))) {
 			y = cons(cdar(code), cdr(code));
 			y = cons(LAMBDA, y);
-			x = caar(code);
+			args = caar(code);
 			code = y;
 		} else {
-			x = car(code);
+			args = car(code);
 			code = cadr(code);
 		}
-		if (!is_symbol(x)) {
+		if (!is_symbol(args)) {
 			Error_0("Variable is not symbol");
 		}
-		s_save(OP_DEF1, NIL, x);
+		s_save(OP_DEF1, NIL, args);
+		args = NIL;
 		s_goto(OP_EVAL);

 	case OP_DEF1:	/* define */
@@ -3031,18 +3036,18 @@
 #ifdef USE_MACRO
 	case OP_0MACRO:		/* macro */
 	case OP_DEFMACRO0:	/* define-macro */
-		if (is_pair(x = car(code))) {
-			if (!is_symbol(car(x))) {
+		if (is_pair(car(code))) {
+			if (!is_symbol(caar(code))) {
 				Error_0("Variable is not symbol");
 			}
-			s_save((operator == OP_0MACRO) ? OP_1MACRO : OP_DEFMACRO1, NIL, car(x));
+			s_save((operator == OP_0MACRO) ? OP_1MACRO : OP_DEFMACRO1, NIL, caar(code));
 			y = cons(cdar(code), cdr(code));
 			code = cons(LAMBDA, y);
 		} else {
-			if (!is_symbol(x)) {
+			if (!is_symbol(car(code))) {
 				Error_0("Variable is not symbol");
 			}
-			s_save((operator == OP_0MACRO) ? OP_1MACRO : OP_DEFMACRO1, NIL, x);
+			s_save((operator == OP_0MACRO) ? OP_1MACRO : OP_DEFMACRO1, NIL, caar(code));
 			code = cadr(code);
 		}
 		s_goto(OP_EVAL);
@@ -3082,8 +3087,9 @@
 				code = cdar(x);
 				s_goto(OP_BEGIN);
 			} else {/* else */
-				s_save(OP_CASE2, NIL, cdar(x));
-				code = caar(x);
+				code = car(x);
+				s_save(OP_CASE2, NIL, cdr(code));
+				code = car(code);
 				s_goto(OP_EVAL);
 			}
 		} else {
@@ -3121,14 +3127,19 @@
 			car(args) = cons(value, car(args));
 		}
 		y = NIL;
+		push_sink(&x);
 		for (x = cdr(args); x != NIL; x = cdr(x)) {
 			if (caar(x) == NIL) {
+				pop_sink();
 				s_return(non_alloc_rev(NIL, car(args)));
 			}
 			y = cons(caar(x), y);
 			car(x) = cdar(x);
 		}
+		pop_sink();
+		push_sink(&y);
 		s_save(OP_MAP1, args, code);
+		pop_sink();
 		args = non_alloc_rev(NIL, y);
 		s_goto(OP_APPLY);

@@ -3139,14 +3150,19 @@

 	case OP_FOREACH1:	/* for-each */
 		y = NIL;
+		push_sink(&x);
 		for (x = args; x != NIL; x = cdr(x)) {
 			if (caar(x) == NIL) {
+				pop_sink();
 				s_return(T);
 			}
 			y = cons(caar(x), y);
 			car(x) = cdar(x);
 		}
+		pop_sink();
+		push_sink(&y);
 		s_save(OP_FOREACH1, args, code);
+		pop_sink();
 		args = non_alloc_rev(NIL, y);
 		s_goto(OP_APPLY);

@@ -4093,21 +4109,21 @@
 	case OP_VEC2LIST:		/* vector->list */
 		if (!validargs("vector->list", 1, 1, TST_VECTOR)) Error_0(msg);
 		y = NIL;
-		for (x = car(args), w = ivalue(x) - 1; w >= 0; w--) {
-			y = cons(vector_elem(x, w), y);
+		for (w = ivalue(car(args)) - 1; w >= 0; w--) {
+			y = cons(vector_elem(car(args), w), y);
 		}
 		s_return(y);

 	case OP_LIST2VEC:		/* list->vector */
 		if (!validargs("list->vector", 1, 1, TST_LIST)) Error_0(msg);
-		x = car(args);
-		w = list_length(x);
+		args = car(args);
+		w = list_length(args);
 		if (w < 0) {
-			Error_1("list->vector: not a proper list:", x);
+			Error_1("list->vector: not a proper list:", args);
 		}
 		y = mk_vector(w);
-		for (w = 0; x != NIL; x = cdr(x)) {
-			set_vector_elem(y, w++, car(x));
+		for (w = 0; args != NIL; args = cdr(args)) {
+			set_vector_elem(y, w++, car(args));
 		}
 		s_return(y);

@@ -4344,7 +4360,7 @@
 		setresultready(code);
 		car(code) = cons(value, NIL);
 		cdr(code) = NIL;
-		s_return(value);
+		s_return(caar(code));

 	case OP_WRITE_CHAR:	/* write-char */
 	case OP_WRITE:		/* write */
@@ -4364,8 +4380,8 @@
 		}
 		if (is_pair(cdr(args))) {
 			if (cadr(args) != outport) {
-				x = cons(outport, NIL);
-				s_save(OP_SET_OUTPORT, x, NIL);
+				outport = cons(outport, NIL);
+				s_save(OP_SET_OUTPORT, outport, NIL);
 				outport = cadr(args);
 			}
 		}
@@ -4377,8 +4393,8 @@
 		if (!validargs("newline", 0, 1, TST_OUTPORT)) Error_0(msg);
 		if (is_pair(args)) {
 			if (car(args) != outport) {
-				x = cons(outport, NIL);
-				s_save(OP_SET_OUTPORT, x, NIL);
+				outport = cons(outport, NIL);
+				s_save(OP_SET_OUTPORT, outport, NIL);
 				outport = car(args);
 			}
 		}
@@ -4620,9 +4636,8 @@
 		if (!validargs("read", 0, 1, TST_INPORT)) Error_0(msg);
 		if (is_pair(args)) {
 			if (car(args) != inport) {
-				x = inport;
-				x = cons(x, NIL);
-				s_save(OP_SET_INPORT, x, NIL);
+				inport = cons(inport, NIL);
+				s_save(OP_SET_INPORT, inport, NIL);
 				inport = car(args);
 			}
 		}
@@ -4642,9 +4657,8 @@
 		}
 		if (is_pair(args)) {
 			if (car(args) != inport) {
-				x = inport;
-				x = cons(x, NIL);
-				s_save(OP_SET_INPORT, x, NIL);
+				inport = cons(inport, NIL);
+				s_save(OP_SET_INPORT, inport, NIL);
 				inport = car(args);
 			}
 		}
@@ -4756,12 +4770,8 @@
 		x = cons(value, NIL);
 		x = cons(QQUOTE, x);
 		x = cons(x, NIL);
-		push_sink(&x);
-		y = mk_symbol("vector");
-		x = cons(y, x);
-		y = mk_symbol("apply");
-		pop_sink();
-		s_return(cons(y, x));
+		x = cons(mk_symbol("vector"), x);
+		s_return(cons(mk_symbol("apply"), x));

 	case OP_RDUNQUOTE:
 		x = cons(value, NIL);
@@ -4830,15 +4840,13 @@
 	case OP_PVECFROM:
 OP_PVECFROM:
 		w = ivalue(cdr(args));
-		x = car(args);
-		if (w == ivalue(x)) {
+		if (w == ivalue(car(args))) {
 			putstr(")");
 			s_return(T);
 		} else {
 			ivalue(cdr(args)) = w + 1;
-			y = args;
-			args = vector_elem(x, w);
-			s_save(OP_PVECFROM, y, NIL);
+			s_save(OP_PVECFROM, args, NIL);
+			args = vector_elem(car(args), w);
 			if (w > 0) putstr(" ");
 			s_goto(OP_P0LIST);
 		}


Removed extra debug statements.

Removed extra debug statements.

--- src/dm_utilities.c
+++ src/dm_utilities.c
@@ -417,7 +417,7 @@
   /* Get the full_dm information */
   VecGetOwnershipRange(full_dm,&full_low,&full_high);
   VecGetArrayRead(full_dm,&full_dm_array);
-  printf("let's jam\n");
+
   for (ibef=0;ibef<nbef;ibef++){
     for (jbef=0;jbef<nbef;jbef++){
       for (iaf=0;iaf<naf;iaf++){
@@ -433,7 +433,7 @@
               /* Location in ptraced Hilbert space */
               /* naf*nbef = total_levels in subspace. Needed to get linearized position */
               loc_sub = naf*nbef*(naf*ibef+iaf)+naf*jbef+jaf;
-              printf("loc_full loc_sub: %d %d\n",loc_full,loc_sub);
+
               /* Add values */
               VecSetValue(ptraced_dm,loc_sub,val,ADD_VALUES);
             }


npcx: lpc: don't set SHCFG[7:5] in the driver's initialization

In older Nuvoton EC chips (prior NPCX5), the Semaphore register is
mapped to offset 0 of the Shared RAM Window by default. We usually
disable it in the driver by setting SHCFG[7:6] both to 1 if we want to
disable the Semaphore mechanism. However, in NPCX5 and later chips,
this behavior is deprecated (the Semaphore register is not mapped to
offset 0 of the Shared RAM Window by default).
These bits (including bit 5) were removed. The driver should keep these
bits at their default state. Otherwise, the Semaphore mechanism may not
work as expected.

BRANCH=none
BUG=b:73018524
TEST=pass make buildall.
TEST=build and flash reef/grunt/yorp image, stress test the host command
and host event, no symptom occurs.

Change-Id: I63031f3957d0485f18fb8c4f1b13ad56c2dc5804
Signed-off-by: CHLin <84d2fca36f9d804bb7b1903655f14e4c722a99c4@nuvoton.com>
Reviewed-on: https://chromium-review.googlesource.com/1383675
Commit-Ready: ChromeOS CL Exonerator Bot <fa429e5907f00867f797423aea74327bb02c91b6@appspot.gserviceaccount.com>
Tested-by: CH Lin <49997681dc186e71092740314bf6c6feeca6e227@nuvoton.com>
Reviewed-by: Randall Spangler <62698fdbb84d1779579ee80c3f39fac22017e5bc@chromium.org>
Reviewed-by: Mulin Chao <6bbc5af053a1dfdc363be6857f30de4ac3bcbd16@nuvoton.com>

--- chip/npcx/lpc.c
+++ chip/npcx/lpc.c
@@ -901,8 +901,6 @@

 	/* Don't stall SHM transactions */
 	NPCX_SHM_CTL = NPCX_SHM_CTL & ~0x40;
-	/* Semaphore and Indirect access disable */
-	NPCX_SHCFG = 0xE0;
 	/* Disable Protect Win1&2*/
 	NPCX_WIN_WR_PROT(0) = 0;
 	NPCX_WIN_WR_PROT(1) = 0;


server: print listen port on start

server: print listen port on start

--- src/server.c
+++ src/server.c
@@ -475,17 +475,30 @@
     void *foreign_loops[1];
     foreign_loops[0] = server->loop;
     info.foreign_loops = foreign_loops;
+    info.options |= LWS_SERVER_OPTION_EXPLICIT_VHOSTS;
 #endif

     context = lws_create_context(&info);
     if (context == NULL) {
-        lwsl_err("libwebsockets init failed\n");
+        lwsl_err("libwebsockets context creation failed\n");
         return 1;
     }
+
+#if LWS_LIBRARY_VERSION_MAJOR >= 3
+    struct lws_vhost *vhost = lws_create_vhost(context, &info);
+    if (vhost == NULL) {
+        lwsl_err("libwebsockets vhost creation failed\n");
+        return 1;
+    }
+    int port = lws_get_vhost_listen_port(vhost);
+#else
+    int port = info.port;
+#endif
+    lwsl_notice(" Listening on port: %d\n", port);

     if (browser) {
         char url[30];
-        sprintf(url, "%s://localhost:%d", ssl ? "https" : "http", info.port);
+        sprintf(url, "%s://localhost:%d", ssl ? "https" : "http", port);
         open_uri(url);
     }


upgrade for 4.2.0

upgrade for 4.2.0

--- src/ml-wifi.c
+++ src/ml-wifi.c
@@ -5,115 +5,27 @@
 #include "FreeRTOS.h"
 #include "task.h"
 #include "os.h"
-#include "semphr.h"
+
+#include "wifi_lwip_helper.h"
 #include "wifi_api.h"
-#include "lwip/ip4_addr.h"
-#include "lwip/inet.h"
-#include "lwip/netif.h"
-#include "lwip/tcpip.h"
-#include "lwip/dhcp.h"
-#include "ethernetif.h"
-#include "portmacro.h"
-#include "app_common.h"

 #include "jerry-api.h"
 #include "microlattice.h"

-static SemaphoreHandle_t ip_ready;
+void wifi_initial_task() {
+  lwip_net_ready();

-/**
-  * @brief  dhcp got ip will callback this function.
-  * @param[in] struct netif *netif: which network interface got ip.
-  * @retval None
-  */
-static void _ip_ready_callback(struct netif *netif)
-{
-    if (!ip4_addr_isany_val(netif->ip_addr)) {
-        char ip_addr[17] = {0};
-        if (NULL != inet_ntoa(netif->ip_addr)) {
-            strcpy(ip_addr, inet_ntoa(netif->ip_addr));
-            LOG_I(common, "************************");
-            LOG_I(common, "DHCP got IP:%s", ip_addr);
-            LOG_I(common, "************************");
-            wifi_callback();
-        } else {
-            LOG_E(common, "DHCP got Failed");
-        }
-    }
-    xSemaphoreGive(ip_ready);
-    LOG_I(common, "ip ready");
-}
-
-static int32_t _wifi_event_handler(wifi_event_t event,
-        uint8_t *payload,
-        uint32_t length)
-{
-    struct netif *sta_if;
-    LOG_I(common, "wifi event: %d", event);
-
-    switch(event)
-    {
-    case WIFI_EVENT_IOT_PORT_SECURE:
-        sta_if = netif_find_by_type(NETIF_TYPE_STA);
-        netif_set_link_up(sta_if);
-        LOG_I(common, "wifi connected");
-        break;
-    case WIFI_EVENT_IOT_DISCONNECTED:
-        sta_if = netif_find_by_type(NETIF_TYPE_STA);
-        netif_set_link_down(sta_if);
-        LOG_I(common, "wifi disconnected");
-        break;
-    }
-
-    return 1;
-}
-
-void wifi_connect(void)
-{
   char script [] = "global.eventStatus.emit('wifiConnect', true);";
   jerry_value_t eval_ret;
   eval_ret = jerry_eval(script, strlen (script), false);
   jerry_release_value (eval_ret);
-}

-wifi_config_t wifi_config = {0};
-lwip_tcpip_config_t tcpip_config = {{0}, {0}, {0}, {0}, {0}, {0}};
-
-void wifi_initial_task() {
-  struct netif *sta_if;
-  wifi_init(&wifi_config, NULL);
-  lwip_tcpip_init(&tcpip_config, WIFI_MODE_STA_ONLY);
-
-  ip_ready = xSemaphoreCreateBinary();
-
-  sta_if = netif_find_by_type(NETIF_TYPE_STA);
-  netif_set_status_callback(sta_if, _ip_ready_callback);
-  dhcp_start(sta_if);
-
-  // wait for result
-  xSemaphoreTake(ip_ready, portMAX_DELAY);
-  vTaskDelete(NULL);
-}
-
-void wifi_connect_task(void *parameter) {
-  wifi_connect();
   for (;;) {
       ;
   }
 }

-void wifi_callback(const struct netif *netif) {
-  xTaskCreate(wifi_connect_task, "WifiTask", 8048, NULL, 1, NULL);
-}
-
-DELCARE_HANDLER(__wifiActive) {
-  wifi_config_set_radio(jerry_get_number_value(args_p[0]));
-  return jerry_create_boolean (true);
-}
-
 DELCARE_HANDLER(__wifi) {
-  if (jerry_value_is_object(args_p[0])) {
-
     // mode
     jerry_value_t prop_mode = jerry_create_string ((const jerry_char_t *) "mode");
     jerry_value_t mode = jerry_get_property(args_p[0], prop_mode);
@@ -141,24 +53,24 @@
       jerry_string_to_char_buffer (password, password_buffer, password_req_sz);
       password_buffer[password_req_sz] = '\0';

-      wifi_connection_register_event_handler(WIFI_EVENT_IOT_INIT_COMPLETE , _wifi_event_handler);
-      wifi_connection_register_event_handler(WIFI_EVENT_IOT_CONNECTED, _wifi_event_handler);
-      wifi_connection_register_event_handler(WIFI_EVENT_IOT_PORT_SECURE, _wifi_event_handler);
-      wifi_connection_register_event_handler(WIFI_EVENT_IOT_DISCONNECTED, _wifi_event_handler);
+      wifi_config_t config = {0};
+
+      strcpy((char *)config.sta_config.ssid, ssid_buffer);
+      strcpy((char *)config.sta_config.password, password_buffer);
+      config.sta_config.ssid_length = strlen((const char *)config.sta_config.ssid);
+      config.sta_config.password_length = strlen((const char *)config.sta_config.password);

       if (strncmp (mode_buffer, "station", (size_t)mode_req_sz) == 0) {
-        wifi_config.opmode = WIFI_MODE_STA_ONLY;
-        strcpy((char *)wifi_config.sta_config.ssid, ssid_buffer);
-        wifi_config.sta_config.ssid_length = ssid_req_sz;
-        strcpy((char *)wifi_config.sta_config.password, password_buffer);
-        wifi_config.sta_config.password_length = password_req_sz;
-
+        config.opmode = WIFI_MODE_STA_ONLY;
       } else if (strncmp (mode_buffer, "ap", (size_t)mode_req_sz) == 0) {
-        wifi_config.opmode = WIFI_MODE_AP_ONLY;
+        config.opmode = WIFI_MODE_AP_ONLY;
       }

-      xTaskCreate(wifi_initial_task, "WifiInitTask", 2048, NULL, 1, NULL);
+      wifi_init(&config, NULL);
+      lwip_network_init(config.opmode);
+      lwip_net_start(config.opmode);

+      xTaskCreate(wifi_initial_task, "WifiInitTask", 4096, NULL, 1, NULL);
     }

     jerry_release_value(prop_mode);
@@ -168,12 +80,10 @@
     jerry_release_value(ssid);
     jerry_release_value(password);

-  }
-
-  return jerry_create_boolean (true);
+    return jerry_create_boolean (true);
+    /* Tcpip stack and net interface initialization,  dhcp client, dhcp server process initialization*/
 }

 void ml_wifi_init (void) {
   REGISTER_HANDLER(__wifi);
-  REGISTER_HANDLER(__wifiActive);
 }


that missing semicolon, lovely

that missing semicolon, lovely

--- src/server.c
+++ src/server.c
@@ -195,7 +195,7 @@

         //regressive and unecessary to see what's below root
         if (strcmp(relative_path, "/") == 0 && strcmp(de->d_name, "..") == 0)
-            continue
+            continue;

         fprintf(f, "", de->d_name, S_ISDIR(statbuf.st_mode) ? "/" : "");
         fprintf(f, "%s%s	", de->d_name, S_ISDIR(statbuf.st_mode) ? "/" : "");


Need to do the check right.

Need to do the check right.

--- src/server.c
+++ src/server.c
@@ -24,6 +24,8 @@
     check(srv->listen_fd >= 0, "Can't announce on TCP port %d", srv->port);

     check(fdnoblock(srv->listen_fd) == 0, "Failed to set listening port %d nonblocking.", srv->port);
+
+    return srv;

 error:
     Server_destroy(srv);
@@ -68,7 +70,7 @@

 int Server_add_proxy(Server *srv, Proxy *proxy)
 {
-    check(srv->proxy != NULL, "Too many proxies.");
+    check(srv->proxy == NULL, "Too many proxies.");

     srv->proxy = proxy;
     check(srv->proxy, "Failed to create proxy configuration.");
@@ -82,7 +84,7 @@

 int Server_add_handler(Server *srv, Handler *handler)
 {
-    check(srv->handler != NULL, "Too many handlers.");
+    check(srv->handler == NULL, "Too many handlers.");

     srv->handler = handler;
     check(srv->handler, "Handler is invalid.");


mod_hmh: small fix to new timezone code

mod_hmh: small fix to new timezone code

--- src/mod_hmh.c
+++ src/mod_hmh.c
@@ -214,7 +214,9 @@
 		bool valid = false;
 		char timezone[64];

-		if(snprintf(timezone, sizeof(timezone), ":%s.", arg) < sizeof(timezone)){
+		if (!strchr(arg, ':') &&
+			!strchr(arg, '.') &&
+			snprintf(timezone, sizeof(timezone), ":%s.", arg) < sizeof(timezone)){

 			// hack for Etc/* zones having reversed symbols...
 			char* p;
@@ -481,6 +483,7 @@
 static bool hmh_init(const IRCCoreCtx* _ctx){
 	ctx = _ctx;
 	ftw("/usr/share/zoneinfo/posix/", &ftw_cb, 10);
+	sb_push(tz_buf, 0);
 	return true;
 }


Use a less aggressive query buffer resize policy.

A user with many connections (10 thousand) on a single Redis server
reports in issue #4983 that sometimes Redis is idle becuase at the same
time many clients need to resize their query buffer according to the old
policy.

It looks like this was created by the fact that we allow the query
buffer to grow without problems to a size up to PROTO_MBULK_BIG_ARG
normally, but when the client is idle we immediately are more strict,
and a query buffer greater than 1024 bytes is already enough to trigger
the resize. So for instance if most of the clients stop at the same time
this issue should be easily triggered.

This behavior actually looks odd, and there should be only a clear limit
after we say, let's look at this query buffer to check if it's time to
resize it. This commit puts the limit at PROTO_MBULK_BIG_ARG, and the
check is performed both if compared to the peak usage the current usage
is too big, or if the client is idle.

Then when the check is performed, to waste just a few kbytes is
considered enough to proceed with the resize. This should fix the issue.

--- src/server.c
+++ src/server.c
@@ -845,13 +845,14 @@

     /* There are two conditions to resize the query buffer:
      * 1) Query buffer is > BIG_ARG and too big for latest peak.
-     * 2) Client is inactive and the buffer is bigger than 1k. */
-    if (((querybuf_size > PROTO_MBULK_BIG_ARG) &&
-         (querybuf_size/(c->querybuf_peak+1)) > 2) ||
-         (querybuf_size > 1024 && idletime > 2))
+     * 2) Query buffer is > BIG_ARG and client is idle. */
+    if (querybuf_size > PROTO_MBULK_BIG_ARG &&
+         ((querybuf_size/(c->querybuf_peak+1)) > 2 ||
+          idletime > 2))
     {
-        /* Only resize the query buffer if it is actually wasting space. */
-        if (sdsavail(c->querybuf) > 1024) {
+        /* Only resize the query buffer if it is actually wasting
+         * at least a few kbytes. */
+        if (sdsavail(c->querybuf) > 1024*4) {
             c->querybuf = sdsRemoveFreeSpace(c->querybuf);
         }
     }


dec_sse2: harmonize function suffixes

dec_sse2: harmonize function suffixes

BUG=webp:355

Change-Id: Ic0390a4a24a5d8caff5b8af9fc9d59769ec533b1

--- src/dsp/dec_sse2.c
+++ src/dsp/dec_sse2.c
@@ -30,7 +30,7 @@
 //------------------------------------------------------------------------------
 // Transforms (Paragraph 14.4)

-static void Transform(const int16_t* in, uint8_t* dst, int do_two) {
+static void Transform_SSE2(const int16_t* in, uint8_t* dst, int do_two) {
   // This implementation makes use of 16-bit fixed point versions of two
   // multiply constants:
   //    K1 = sqrt(2) * cos (pi/8) ~= 85627 / 2^16
@@ -250,7 +250,7 @@
     _mm_subs_epu8((p), (q)))

 // Shift each byte of "x" by 3 bits while preserving by the sign bit.
-static WEBP_INLINE void SignedShift8b(__m128i* const x) {
+static WEBP_INLINE void SignedShift8b_SSE2(__m128i* const x) {
   const __m128i zero = _mm_setzero_si128();
   const __m128i lo_0 = _mm_unpacklo_epi8(zero, *x);
   const __m128i hi_0 = _mm_unpackhi_epi8(zero, *x);
@@ -270,11 +270,11 @@
 }

 // input/output is uint8_t
-static WEBP_INLINE void GetNotHEV(const __m128i* const p1,
-                                  const __m128i* const p0,
-                                  const __m128i* const q0,
-                                  const __m128i* const q1,
-                                  int hev_thresh, __m128i* const not_hev) {
+static WEBP_INLINE void GetNotHEV_SSE2(const __m128i* const p1,
+                                       const __m128i* const p0,
+                                       const __m128i* const q0,
+                                       const __m128i* const q1,
+                                       int hev_thresh, __m128i* const not_hev) {
   const __m128i zero = _mm_setzero_si128();
   const __m128i t_1 = MM_ABS(*p1, *p0);
   const __m128i t_2 = MM_ABS(*q1, *q0);
@@ -287,11 +287,11 @@
 }

 // input pixels are int8_t
-static WEBP_INLINE void GetBaseDelta(const __m128i* const p1,
-                                     const __m128i* const p0,
-                                     const __m128i* const q0,
-                                     const __m128i* const q1,
-                                     __m128i* const delta) {
+static WEBP_INLINE void GetBaseDelta_SSE2(const __m128i* const p1,
+                                          const __m128i* const p0,
+                                          const __m128i* const q0,
+                                          const __m128i* const q1,
+                                          __m128i* const delta) {
   // beware of addition order, for saturation!
   const __m128i p1_q1 = _mm_subs_epi8(*p1, *q1);   // p1 - q1
   const __m128i q0_p0 = _mm_subs_epi8(*q0, *p0);   // q0 - p0
@@ -302,15 +302,16 @@
 }

 // input and output are int8_t
-static WEBP_INLINE void DoSimpleFilter(__m128i* const p0, __m128i* const q0,
-                                       const __m128i* const fl) {
+static WEBP_INLINE void DoSimpleFilter_SSE2(__m128i* const p0,
+                                            __m128i* const q0,
+                                            const __m128i* const fl) {
   const __m128i k3 = _mm_set1_epi8(3);
   const __m128i k4 = _mm_set1_epi8(4);
   __m128i v3 = _mm_adds_epi8(*fl, k3);
   __m128i v4 = _mm_adds_epi8(*fl, k4);

-  SignedShift8b(&v4);                  // v4 >> 3
-  SignedShift8b(&v3);                  // v3 >> 3
+  SignedShift8b_SSE2(&v4);             // v4 >> 3
+  SignedShift8b_SSE2(&v3);             // v3 >> 3
   *q0 = _mm_subs_epi8(*q0, v4);        // q0 -= v4
   *p0 = _mm_adds_epi8(*p0, v3);        // p0 += v3
 }
@@ -319,9 +320,9 @@
 // Update operations:
 // q = q - delta and p = p + delta; where delta = [(a_hi >> 7), (a_lo >> 7)]
 // Pixels 'pi' and 'qi' are int8_t on input, uint8_t on output (sign flip).
-static WEBP_INLINE void Update2Pixels(__m128i* const pi, __m128i* const qi,
-                                      const __m128i* const a0_lo,
-                                      const __m128i* const a0_hi) {
+static WEBP_INLINE void Update2Pixels_SSE2(__m128i* const pi, __m128i* const qi,
+                                           const __m128i* const a0_lo,
+                                           const __m128i* const a0_hi) {
   const __m128i a1_lo = _mm_srai_epi16(*a0_lo, 7);
   const __m128i a1_hi = _mm_srai_epi16(*a0_hi, 7);
   const __m128i delta = _mm_packs_epi16(a1_lo, a1_hi);
@@ -332,11 +333,11 @@
 }

 // input pixels are uint8_t
-static WEBP_INLINE void NeedsFilter(const __m128i* const p1,
-                                    const __m128i* const p0,
-                                    const __m128i* const q0,
-                                    const __m128i* const q1,
-                                    int thresh, __m128i* const mask) {
+static WEBP_INLINE void NeedsFilter_SSE2(const __m128i* const p1,
+                                         const __m128i* const p0,
+                                         const __m128i* const q0,
+                                         const __m128i* const q1,
+                                         int thresh, __m128i* const mask) {
   const __m128i m_thresh = _mm_set1_epi8(thresh);
   const __m128i t1 = MM_ABS(*p1, *q1);        // abs(p1 - q1)
   const __m128i kFE = _mm_set1_epi8(0xFE);
@@ -355,28 +356,29 @@
 // Edge filtering functions

 // Applies filter on 2 pixels (p0 and q0)
-static WEBP_INLINE void DoFilter2(__m128i* const p1, __m128i* const p0,
-                                  __m128i* const q0, __m128i* const q1,
-                                  int thresh) {
+static WEBP_INLINE void DoFilter2_SSE2(__m128i* const p1, __m128i* const p0,
+                                       __m128i* const q0, __m128i* const q1,
+                                       int thresh) {
   __m128i a, mask;
   const __m128i sign_bit = _mm_set1_epi8(0x80);
-  // convert p1/q1 to int8_t (for GetBaseDelta)
+  // convert p1/q1 to int8_t (for GetBaseDelta_SSE2)
   const __m128i p1s = _mm_xor_si128(*p1, sign_bit);
   const __m128i q1s = _mm_xor_si128(*q1, sign_bit);

-  NeedsFilter(p1, p0, q0, q1, thresh, &mask);
+  NeedsFilter_SSE2(p1, p0, q0, q1, thresh, &mask);

   FLIP_SIGN_BIT2(*p0, *q0);
-  GetBaseDelta(&p1s, p0, q0, &q1s, &a);
+  GetBaseDelta_SSE2(&p1s, p0, q0, &q1s, &a);
   a = _mm_and_si128(a, mask);     // mask filter values we don't care about
-  DoSimpleFilter(p0, q0, &a);
+  DoSimpleFilter_SSE2(p0, q0, &a);
   FLIP_SIGN_BIT2(*p0, *q0);
 }

 // Applies filter on 4 pixels (p1, p0, q0 and q1)
-static WEBP_INLINE void DoFilter4(__m128i* const p1, __m128i* const p0,
-                                  __m128i* const q0, __m128i* const q1,
-                                  const __m128i* const mask, int hev_thresh) {
+static WEBP_INLINE void DoFilter4_SSE2(__m128i* const p1, __m128i* const p0,
+                                       __m128i* const q0, __m128i* const q1,
+                                       const __m128i* const mask,
+                                       int hev_thresh) {
   const __m128i zero = _mm_setzero_si128();
   const __m128i sign_bit = _mm_set1_epi8(0x80);
   const __m128i k64 = _mm_set1_epi8(64);
@@ -386,7 +388,7 @@
   __m128i t1, t2, t3;

   // compute hev mask
-  GetNotHEV(p1, p0, q0, q1, hev_thresh, &not_hev);
+  GetNotHEV_SSE2(p1, p0, q0, q1, hev_thresh, &not_hev);

   // convert to signed values
   FLIP_SIGN_BIT4(*p1, *p0, *q0, *q1);
@@ -401,8 +403,8 @@

   t2 = _mm_adds_epi8(t1, k3);        // 3 * (q0 - p0) + hev(p1 - q1) + 3
   t3 = _mm_adds_epi8(t1, k4);        // 3 * (q0 - p0) + hev(p1 - q1) + 4
-  SignedShift8b(&t2);                // (3 * (q0 - p0) + hev(p1 - q1) + 3) >> 3
-  SignedShift8b(&t3);                // (3 * (q0 - p0) + hev(p1 - q1) + 4) >> 3
+  SignedShift8b_SSE2(&t2);           // (3 * (q0 - p0) + hev(p1 - q1) + 3) >> 3
+  SignedShift8b_SSE2(&t3);           // (3 * (q0 - p0) + hev(p1 - q1) + 4) >> 3
   *p0 = _mm_adds_epi8(*p0, t2);      // p0 += t2
   *q0 = _mm_subs_epi8(*q0, t3);      // q0 -= t3
   FLIP_SIGN_BIT2(*p0, *q0);
@@ -419,25 +421,26 @@
 }

 // Applies filter on 6 pixels (p2, p1, p0, q0, q1 and q2)
-static WEBP_INLINE void DoFilter6(__m128i* const p2, __m128i* const p1,
-                                  __m128i* const p0, __m128i* const q0,
-                                  __m128i* const q1, __m128i* const q2,
-                                  const __m128i* const mask, int hev_thresh) {
+static WEBP_INLINE void DoFilter6_SSE2(__m128i* const p2, __m128i* const p1,
+                                       __m128i* const p0, __m128i* const q0,
+                                       __m128i* const q1, __m128i* const q2,
+                                       const __m128i* const mask,
+                                       int hev_thresh) {
   const __m128i zero = _mm_setzero_si128();
   const __m128i sign_bit = _mm_set1_epi8(0x80);
   __m128i a, not_hev;

   // compute hev mask
-  GetNotHEV(p1, p0, q0, q1, hev_thresh, &not_hev);
+  GetNotHEV_SSE2(p1, p0, q0, q1, hev_thresh, &not_hev);

   FLIP_SIGN_BIT4(*p1, *p0, *q0, *q1);
   FLIP_SIGN_BIT2(*p2, *q2);
-  GetBaseDelta(p1, p0, q0, q1, &a);
+  GetBaseDelta_SSE2(p1, p0, q0, q1, &a);

   { // do simple filter on pixels with hev
     const __m128i m = _mm_andnot_si128(not_hev, *mask);
     const __m128i f = _mm_and_si128(a, m);
-    DoSimpleFilter(p0, q0, &f);
+    DoSimpleFilter_SSE2(p0, q0, &f);
   }

   { // do strong filter on pixels with not hev
@@ -462,15 +465,15 @@
     const __m128i a0_lo = _mm_add_epi16(a1_lo, f9_lo);  // Filter * 27 + 63
     const __m128i a0_hi = _mm_add_epi16(a1_hi, f9_hi);  // Filter * 27 + 63

-    Update2Pixels(p2, q2, &a2_lo, &a2_hi);
-    Update2Pixels(p1, q1, &a1_lo, &a1_hi);
-    Update2Pixels(p0, q0, &a0_lo, &a0_hi);
+    Update2Pixels_SSE2(p2, q2, &a2_lo, &a2_hi);
+    Update2Pixels_SSE2(p1, q1, &a1_lo, &a1_hi);
+    Update2Pixels_SSE2(p0, q0, &a0_lo, &a0_hi);
   }
 }

 // reads 8 rows across a vertical edge.
-static WEBP_INLINE void Load8x4(const uint8_t* const b, int stride,
-                                __m128i* const p, __m128i* const q) {
+static WEBP_INLINE void Load8x4_SSE2(const uint8_t* const b, int stride,
+                                     __m128i* const p, __m128i* const q) {
   // A0 = 63 62 61 60 23 22 21 20 43 42 41 40 03 02 01 00
   // A1 = 73 72 71 70 33 32 31 30 53 52 51 50 13 12 11 10
   const __m128i A0 = _mm_set_epi32(
@@ -496,11 +499,11 @@
   *q = _mm_unpackhi_epi32(C0, C1);
 }

-static WEBP_INLINE void Load16x4(const uint8_t* const r0,
-                                 const uint8_t* const r8,
-                                 int stride,
-                                 __m128i* const p1, __m128i* const p0,
-                                 __m128i* const q0, __m128i* const q1) {
+static WEBP_INLINE void Load16x4_SSE2(const uint8_t* const r0,
+                                      const uint8_t* const r8,
+                                      int stride,
+                                      __m128i* const p1, __m128i* const p0,
+                                      __m128i* const q0, __m128i* const q1) {
   // Assume the pixels around the edge (|) are numbered as follows
   //                00 01 | 02 03
   //                10 11 | 12 13
@@ -516,8 +519,8 @@
   // q0 = 73 63 53 43 33 23 13 03 72 62 52 42 32 22 12 02
   // p0 = f1 e1 d1 c1 b1 a1 91 81 f0 e0 d0 c0 b0 a0 90 80
   // q1 = f3 e3 d3 c3 b3 a3 93 83 f2 e2 d2 c2 b2 a2 92 82
-  Load8x4(r0, stride, p1, q0);
-  Load8x4(r8, stride, p0, q1);
+  Load8x4_SSE2(r0, stride, p1, q0);
+  Load8x4_SSE2(r8, stride, p0, q1);

   {
     // p1 = f0 e0 d0 c0 b0 a0 90 80 70 60 50 40 30 20 10 00
@@ -533,7 +536,8 @@
   }
 }

-static WEBP_INLINE void Store4x4(__m128i* const x, uint8_t* dst, int stride) {
+static WEBP_INLINE void Store4x4_SSE2(__m128i* const x,
+                                      uint8_t* dst, int stride) {
   int i;
   for (i = 0; i < 4; ++i, dst += stride) {
     WebPUint32ToMem(dst, _mm_cvtsi128_si32(*x));
@@ -542,12 +546,12 @@
 }

 // Transpose back and store
-static WEBP_INLINE void Store16x4(const __m128i* const p1,
-                                  const __m128i* const p0,
-                                  const __m128i* const q0,
-                                  const __m128i* const q1,
-                                  uint8_t* r0, uint8_t* r8,
-                                  int stride) {
+static WEBP_INLINE void Store16x4_SSE2(const __m128i* const p1,
+                                       const __m128i* const p0,
+                                       const __m128i* const q0,
+                                       const __m128i* const q1,
+                                       uint8_t* r0, uint8_t* r8,
+                                       int stride) {
   __m128i t1, p1_s, p0_s, q0_s, q1_s;

   // p0 = 71 70 61 60 51 50 41 40 31 30 21 20 11 10 01 00
@@ -574,55 +578,55 @@
   p1_s = _mm_unpacklo_epi16(t1, q1_s);
   q1_s = _mm_unpackhi_epi16(t1, q1_s);

-  Store4x4(&p0_s, r0, stride);
+  Store4x4_SSE2(&p0_s, r0, stride);
   r0 += 4 * stride;
-  Store4x4(&q0_s, r0, stride);
-
-  Store4x4(&p1_s, r8, stride);
+  Store4x4_SSE2(&q0_s, r0, stride);
+
+  Store4x4_SSE2(&p1_s, r8, stride);
   r8 += 4 * stride;
-  Store4x4(&q1_s, r8, stride);
+  Store4x4_SSE2(&q1_s, r8, stride);
 }

 //------------------------------------------------------------------------------
 // Simple In-loop filtering (Paragraph 15.2)

-static void SimpleVFilter16(uint8_t* p, int stride, int thresh) {
+static void SimpleVFilter16_SSE2(uint8_t* p, int stride, int thresh) {
   // Load
   __m128i p1 = _mm_loadu_si128((__m128i*)&p[-2 * stride]);
   __m128i p0 = _mm_loadu_si128((__m128i*)&p[-stride]);
   __m128i q0 = _mm_loadu_si128((__m128i*)&p[0]);
   __m128i q1 = _mm_loadu_si128((__m128i*)&p[stride]);

-  DoFilter2(&p1, &p0, &q0, &q1, thresh);
+  DoFilter2_SSE2(&p1, &p0, &q0, &q1, thresh);

   // Store
   _mm_storeu_si128((__m128i*)&p[-stride], p0);
   _mm_storeu_si128((__m128i*)&p[0], q0);
 }

-static void SimpleHFilter16(uint8_t* p, int stride, int thresh) {
+static void SimpleHFilter16_SSE2(uint8_t* p, int stride, int thresh) {
   __m128i p1, p0, q0, q1;

   p -= 2;  // beginning of p1

-  Load16x4(p, p + 8 * stride, stride, &p1, &p0, &q0, &q1);
-  DoFilter2(&p1, &p0, &q0, &q1, thresh);
-  Store16x4(&p1, &p0, &q0, &q1, p, p + 8 * stride, stride);
-}
-
-static void SimpleVFilter16i(uint8_t* p, int stride, int thresh) {
+  Load16x4_SSE2(p, p + 8 * stride, stride, &p1, &p0, &q0, &q1);
+  DoFilter2_SSE2(&p1, &p0, &q0, &q1, thresh);
+  Store16x4_SSE2(&p1, &p0, &q0, &q1, p, p + 8 * stride, stride);
+}
+
+static void SimpleVFilter16i_SSE2(uint8_t* p, int stride, int thresh) {
   int k;
   for (k = 3; k > 0; --k) {
     p += 4 * stride;
-    SimpleVFilter16(p, stride, thresh);
-  }
-}
-
-static void SimpleHFilter16i(uint8_t* p, int stride, int thresh) {
+    SimpleVFilter16_SSE2(p, stride, thresh);
+  }
+}
+
+static void SimpleHFilter16i_SSE2(uint8_t* p, int stride, int thresh) {
   int k;
   for (k = 3; k > 0; --k) {
     p += 4;
-    SimpleHFilter16(p, stride, thresh);
+    SimpleHFilter16_SSE2(p, stride, thresh);
   }
 }

@@ -667,23 +671,23 @@
   _mm_storel_epi64((__m128i*)&(v)[(stride)], p);                               \
 }

-static WEBP_INLINE void ComplexMask(const __m128i* const p1,
-                                    const __m128i* const p0,
-                                    const __m128i* const q0,
-                                    const __m128i* const q1,
-                                    int thresh, int ithresh,
-                                    __m128i* const mask) {
+static WEBP_INLINE void ComplexMask_SSE2(const __m128i* const p1,
+                                         const __m128i* const p0,
+                                         const __m128i* const q0,
+                                         const __m128i* const q1,
+                                         int thresh, int ithresh,
+                                         __m128i* const mask) {
   const __m128i it = _mm_set1_epi8(ithresh);
   const __m128i diff = _mm_subs_epu8(*mask, it);
   const __m128i thresh_mask = _mm_cmpeq_epi8(diff, _mm_setzero_si128());
   __m128i filter_mask;
-  NeedsFilter(p1, p0, q0, q1, thresh, &filter_mask);
+  NeedsFilter_SSE2(p1, p0, q0, q1, thresh, &filter_mask);
   *mask = _mm_and_si128(thresh_mask, filter_mask);
 }

 // on macroblock edges
-static void VFilter16(uint8_t* p, int stride,
-                      int thresh, int ithresh, int hev_thresh) {
+static void VFilter16_SSE2(uint8_t* p, int stride,
+                           int thresh, int ithresh, int hev_thresh) {
   __m128i t1;
   __m128i mask;
   __m128i p2, p1, p0, q0, q1, q2;
@@ -696,8 +700,8 @@
   LOAD_H_EDGES4(p, stride, q0, q1, q2, t1);
   MAX_DIFF2(t1, q2, q1, q0, mask);

-  ComplexMask(&p1, &p0, &q0, &q1, thresh, ithresh, &mask);
-  DoFilter6(&p2, &p1, &p0, &q0, &q1, &q2, &mask, hev_thresh);
+  ComplexMask_SSE2(&p1, &p0, &q0, &q1, thresh, ithresh, &mask);
+  DoFilter6_SSE2(&p2, &p1, &p0, &q0, &q1, &q2, &mask, hev_thresh);

   // Store
   _mm_storeu_si128((__m128i*)&p[-3 * stride], p2);
@@ -708,28 +712,28 @@
   _mm_storeu_si128((__m128i*)&p[+2 * stride], q2);
 }

-static void HFilter16(uint8_t* p, int stride,
-                      int thresh, int ithresh, int hev_thresh) {
+static void HFilter16_SSE2(uint8_t* p, int stride,
+                           int thresh, int ithresh, int hev_thresh) {
   __m128i mask;
   __m128i p3, p2, p1, p0, q0, q1, q2, q3;

   uint8_t* const b = p - 4;
-  Load16x4(b, b + 8 * stride, stride, &p3, &p2, &p1, &p0);
+  Load16x4_SSE2(b, b + 8 * stride, stride, &p3, &p2, &p1, &p0);
   MAX_DIFF1(p3, p2, p1, p0, mask);

-  Load16x4(p, p + 8 * stride, stride, &q0, &q1, &q2, &q3);
+  Load16x4_SSE2(p, p + 8 * stride, stride, &q0, &q1, &q2, &q3);
   MAX_DIFF2(q3, q2, q1, q0, mask);

-  ComplexMask(&p1, &p0, &q0, &q1, thresh, ithresh, &mask);
-  DoFilter6(&p2, &p1, &p0, &q0, &q1, &q2, &mask, hev_thresh);
-
-  Store16x4(&p3, &p2, &p1, &p0, b, b + 8 * stride, stride);
-  Store16x4(&q0, &q1, &q2, &q3, p, p + 8 * stride, stride);
+  ComplexMask_SSE2(&p1, &p0, &q0, &q1, thresh, ithresh, &mask);
+  DoFilter6_SSE2(&p2, &p1, &p0, &q0, &q1, &q2, &mask, hev_thresh);
+
+  Store16x4_SSE2(&p3, &p2, &p1, &p0, b, b + 8 * stride, stride);
+  Store16x4_SSE2(&q0, &q1, &q2, &q3, p, p + 8 * stride, stride);
 }

 // on three inner edges
-static void VFilter16i(uint8_t* p, int stride,
-                       int thresh, int ithresh, int hev_thresh) {
+static void VFilter16i_SSE2(uint8_t* p, int stride,
+                            int thresh, int ithresh, int hev_thresh) {
   int k;
   __m128i p3, p2, p1, p0;   // loop invariants

@@ -746,8 +750,8 @@

     // p3 and p2 are not just temporary variables here: they will be
     // re-used for next span. And q2/q3 will become p1/p0 accordingly.
-    ComplexMask(&p1, &p0, &p3, &p2, thresh, ithresh, &mask);
-    DoFilter4(&p1, &p0, &p3, &p2, &mask, hev_thresh);
+    ComplexMask_SSE2(&p1, &p0, &p3, &p2, thresh, ithresh, &mask);
+    DoFilter4_SSE2(&p1, &p0, &p3, &p2, &mask, hev_thresh);

     // Store
     _mm_storeu_si128((__m128i*)&b[0 * stride], p1);
@@ -761,12 +765,12 @@
   }
 }

-static void HFilter16i(uint8_t* p, int stride,
-                       int thresh, int ithresh, int hev_thresh) {
+static void HFilter16i_SSE2(uint8_t* p, int stride,
+                            int thresh, int ithresh, int hev_thresh) {
   int k;
   __m128i p3, p2, p1, p0;   // loop invariants

-  Load16x4(p, p + 8 * stride, stride, &p3, &p2, &p1, &p0);  // prologue
+  Load16x4_SSE2(p, p + 8 * stride, stride, &p3, &p2, &p1, &p0);  // prologue

   for (k = 3; k > 0; --k) {
     __m128i mask, tmp1, tmp2;
@@ -775,13 +779,13 @@
     p += 4;  // beginning of q0 (and next span)

     MAX_DIFF1(p3, p2, p1, p0, mask);   // compute partial mask
-    Load16x4(p, p + 8 * stride, stride, &p3, &p2, &tmp1, &tmp2);
+    Load16x4_SSE2(p, p + 8 * stride, stride, &p3, &p2, &tmp1, &tmp2);
     MAX_DIFF2(p3, p2, tmp1, tmp2, mask);

-    ComplexMask(&p1, &p0, &p3, &p2, thresh, ithresh, &mask);
-    DoFilter4(&p1, &p0, &p3, &p2, &mask, hev_thresh);
-
-    Store16x4(&p1, &p0, &p3, &p2, b, b + 8 * stride, stride);
+    ComplexMask_SSE2(&p1, &p0, &p3, &p2, thresh, ithresh, &mask);
+    DoFilter4_SSE2(&p1, &p0, &p3, &p2, &mask, hev_thresh);
+
+    Store16x4_SSE2(&p1, &p0, &p3, &p2, b, b + 8 * stride, stride);

     // rotate samples
     p1 = tmp1;
@@ -790,8 +794,8 @@
 }

 // 8-pixels wide variant, for chroma filtering
-static void VFilter8(uint8_t* u, uint8_t* v, int stride,
-                     int thresh, int ithresh, int hev_thresh) {
+static void VFilter8_SSE2(uint8_t* u, uint8_t* v, int stride,
+                          int thresh, int ithresh, int hev_thresh) {
   __m128i mask;
   __m128i t1, p2, p1, p0, q0, q1, q2;

@@ -803,8 +807,8 @@
   LOADUV_H_EDGES4(u, v, stride, q0, q1, q2, t1);
   MAX_DIFF2(t1, q2, q1, q0, mask);

-  ComplexMask(&p1, &p0, &q0, &q1, thresh, ithresh, &mask);
-  DoFilter6(&p2, &p1, &p0, &q0, &q1, &q2, &mask, hev_thresh);
+  ComplexMask_SSE2(&p1, &p0, &q0, &q1, thresh, ithresh, &mask);
+  DoFilter6_SSE2(&p2, &p1, &p0, &q0, &q1, &q2, &mask, hev_thresh);

   // Store
   STOREUV(p2, u, v, -3 * stride);
@@ -815,28 +819,28 @@
   STOREUV(q2, u, v, 2 * stride);
 }

-static void HFilter8(uint8_t* u, uint8_t* v, int stride,
-                     int thresh, int ithresh, int hev_thresh) {
+static void HFilter8_SSE2(uint8_t* u, uint8_t* v, int stride,
+                          int thresh, int ithresh, int hev_thresh) {
   __m128i mask;
   __m128i p3, p2, p1, p0, q0, q1, q2, q3;

   uint8_t* const tu = u - 4;
   uint8_t* const tv = v - 4;
-  Load16x4(tu, tv, stride, &p3, &p2, &p1, &p0);
+  Load16x4_SSE2(tu, tv, stride, &p3, &p2, &p1, &p0);
   MAX_DIFF1(p3, p2, p1, p0, mask);

-  Load16x4(u, v, stride, &q0, &q1, &q2, &q3);
+  Load16x4_SSE2(u, v, stride, &q0, &q1, &q2, &q3);
   MAX_DIFF2(q3, q2, q1, q0, mask);

-  ComplexMask(&p1, &p0, &q0, &q1, thresh, ithresh, &mask);
-  DoFilter6(&p2, &p1, &p0, &q0, &q1, &q2, &mask, hev_thresh);
-
-  Store16x4(&p3, &p2, &p1, &p0, tu, tv, stride);
-  Store16x4(&q0, &q1, &q2, &q3, u, v, stride);
-}
-
-static void VFilter8i(uint8_t* u, uint8_t* v, int stride,
-                      int thresh, int ithresh, int hev_thresh) {
+  ComplexMask_SSE2(&p1, &p0, &q0, &q1, thresh, ithresh, &mask);
+  DoFilter6_SSE2(&p2, &p1, &p0, &q0, &q1, &q2, &mask, hev_thresh);
+
+  Store16x4_SSE2(&p3, &p2, &p1, &p0, tu, tv, stride);
+  Store16x4_SSE2(&q0, &q1, &q2, &q3, u, v, stride);
+}
+
+static void VFilter8i_SSE2(uint8_t* u, uint8_t* v, int stride,
+                           int thresh, int ithresh, int hev_thresh) {
   __m128i mask;
   __m128i t1, t2, p1, p0, q0, q1;

@@ -851,8 +855,8 @@
   LOADUV_H_EDGES4(u, v, stride, q0, q1, t1, t2);
   MAX_DIFF2(t2, t1, q1, q0, mask);

-  ComplexMask(&p1, &p0, &q0, &q1, thresh, ithresh, &mask);
-  DoFilter4(&p1, &p0, &q0, &q1, &mask, hev_thresh);
+  ComplexMask_SSE2(&p1, &p0, &q0, &q1, thresh, ithresh, &mask);
+  DoFilter4_SSE2(&p1, &p0, &q0, &q1, &mask, hev_thresh);

   // Store
   STOREUV(p1, u, v, -2 * stride);
@@ -861,24 +865,24 @@
   STOREUV(q1, u, v, 1 * stride);
 }

-static void HFilter8i(uint8_t* u, uint8_t* v, int stride,
-                      int thresh, int ithresh, int hev_thresh) {
+static void HFilter8i_SSE2(uint8_t* u, uint8_t* v, int stride,
+                           int thresh, int ithresh, int hev_thresh) {
   __m128i mask;
   __m128i t1, t2, p1, p0, q0, q1;
-  Load16x4(u, v, stride, &t2, &t1, &p1, &p0);   // p3, p2, p1, p0
+  Load16x4_SSE2(u, v, stride, &t2, &t1, &p1, &p0);   // p3, p2, p1, p0
   MAX_DIFF1(t2, t1, p1, p0, mask);

   u += 4;  // beginning of q0
   v += 4;
-  Load16x4(u, v, stride, &q0, &q1, &t1, &t2);  // q0, q1, q2, q3
+  Load16x4_SSE2(u, v, stride, &q0, &q1, &t1, &t2);  // q0, q1, q2, q3
   MAX_DIFF2(t2, t1, q1, q0, mask);

-  ComplexMask(&p1, &p0, &q0, &q1, thresh, ithresh, &mask);
-  DoFilter4(&p1, &p0, &q0, &q1, &mask, hev_thresh);
+  ComplexMask_SSE2(&p1, &p0, &q0, &q1, thresh, ithresh, &mask);
+  DoFilter4_SSE2(&p1, &p0, &q0, &q1, &mask, hev_thresh);

   u -= 2;  // beginning of p1
   v -= 2;
-  Store16x4(&p1, &p0, &q0, &q1, u, v, stride);
+  Store16x4_SSE2(&p1, &p0, &q0, &q1, u, v, stride);
 }

 //------------------------------------------------------------------------------
@@ -895,7 +899,7 @@
 //   where: AC = (a + b + 1) >> 1,   BC = (b + c + 1) >> 1
 //   and ab = a ^ b, bc = b ^ c, lsb = (AC^BC)&1

-static void VE4(uint8_t* dst) {    // vertical
+static void VE4_SSE2(uint8_t* dst) {    // vertical
   const __m128i one = _mm_set1_epi8(1);
   const __m128i ABCDEFGH = _mm_loadl_epi64((__m128i*)(dst - BPS - 1));
   const __m128i BCDEFGH0 = _mm_srli_si128(ABCDEFGH, 1);
@@ -911,7 +915,7 @@
   }
 }

-static void LD4(uint8_t* dst) {   // Down-Left
+static void LD4_SSE2(uint8_t* dst) {   // Down-Left
   const __m128i one = _mm_set1_epi8(1);
   const __m128i ABCDEFGH = _mm_loadl_epi64((__m128i*)(dst - BPS));
   const __m128i BCDEFGH0 = _mm_srli_si128(ABCDEFGH, 1);
@@ -927,7 +931,7 @@
   WebPUint32ToMem(dst + 3 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(abcdefg, 3)));
 }

-static void VR4(uint8_t* dst) {   // Vertical-Right
+static void VR4_SSE2(uint8_t* dst) {   // Vertical-Right
   const __m128i one = _mm_set1_epi8(1);
   const int I = dst[-1 + 0 * BPS];
   const int J = dst[-1 + 1 * BPS];
@@ -952,7 +956,7 @@
   DST(0, 3) = AVG3(K, J, I);
 }

-static void VL4(uint8_t* dst) {   // Vertical-Left
+static void VL4_SSE2(uint8_t* dst) {   // Vertical-Left
   const __m128i one = _mm_set1_epi8(1);
   const __m128i ABCDEFGH = _mm_loadl_epi64((__m128i*)(dst - BPS));
   const __m128i BCDEFGH_ = _mm_srli_si128(ABCDEFGH, 1);
@@ -977,7 +981,7 @@
   DST(3, 3) = (extra_out >> 8) & 0xff;
 }

-static void RD4(uint8_t* dst) {   // Down-right
+static void RD4_SSE2(uint8_t* dst) {   // Down-right
   const __m128i one = _mm_set1_epi8(1);
   const __m128i XABCD = _mm_loadl_epi64((__m128i*)(dst - BPS - 1));
   const __m128i ____XABCD = _mm_slli_si128(XABCD, 4);
@@ -1006,7 +1010,7 @@
 //------------------------------------------------------------------------------
 // Luma 16x16

-static WEBP_INLINE void TrueMotion(uint8_t* dst, int size) {
+static WEBP_INLINE void TrueMotion_SSE2(uint8_t* dst, int size) {
   const uint8_t* top = dst - BPS;
   const __m128i zero = _mm_setzero_si128();
   int y;
@@ -1043,11 +1047,11 @@
   }
 }

-static void TM4(uint8_t* dst)   { TrueMotion(dst, 4); }
-static void TM8uv(uint8_t* dst) { TrueMotion(dst, 8); }
-static void TM16(uint8_t* dst)  { TrueMotion(dst, 16); }
-
-static void VE16(uint8_t* dst) {
+static void TM4_SSE2(uint8_t* dst)   { TrueMotion_SSE2(dst, 4); }
+static void TM8uv_SSE2(uint8_t* dst) { TrueMotion_SSE2(dst, 8); }
+static void TM16_SSE2(uint8_t* dst)  { TrueMotion_SSE2(dst, 16); }
+
+static void VE16_SSE2(uint8_t* dst) {
   const __m128i top = _mm_loadu_si128((const __m128i*)(dst - BPS));
   int j;
   for (j = 0; j < 16; ++j) {
@@ -1055,7 +1059,7 @@
   }
 }

-static void HE16(uint8_t* dst) {     // horizontal
+static void HE16_SSE2(uint8_t* dst) {     // horizontal
   int j;
   for (j = 16; j > 0; --j) {
     const __m128i values = _mm_set1_epi8(dst[-1]);
@@ -1064,7 +1068,7 @@
   }
 }

-static WEBP_INLINE void Put16(uint8_t v, uint8_t* dst) {
+static WEBP_INLINE void Put16_SSE2(uint8_t v, uint8_t* dst) {
   int j;
   const __m128i values = _mm_set1_epi8(v);
   for (j = 0; j < 16; ++j) {
@@ -1072,7 +1076,7 @@
   }
 }

-static void DC16(uint8_t* dst) {    // DC
+static void DC16_SSE2(uint8_t* dst) {  // DC
   const __m128i zero = _mm_setzero_si128();
   const __m128i top = _mm_loadu_si128((const __m128i*)(dst - BPS));
   const __m128i sad8x2 = _mm_sad_epu8(top, zero);
@@ -1085,37 +1089,37 @@
   }
   {
     const int DC = _mm_cvtsi128_si32(sum) + left + 16;
-    Put16(DC >> 5, dst);
-  }
-}
-
-static void DC16NoTop(uint8_t* dst) {   // DC with top samples not available
+    Put16_SSE2(DC >> 5, dst);
+  }
+}
+
+static void DC16NoTop_SSE2(uint8_t* dst) {  // DC with top samples unavailable
   int DC = 8;
   int j;
   for (j = 0; j < 16; ++j) {
     DC += dst[-1 + j * BPS];
   }
-  Put16(DC >> 4, dst);
-}
-
-static void DC16NoLeft(uint8_t* dst) {  // DC with left samples not available
+  Put16_SSE2(DC >> 4, dst);
+}
+
+static void DC16NoLeft_SSE2(uint8_t* dst) {  // DC with left samples unavailable
   const __m128i zero = _mm_setzero_si128();
   const __m128i top = _mm_loadu_si128((const __m128i*)(dst - BPS));
   const __m128i sad8x2 = _mm_sad_epu8(top, zero);
   // sum the two sads: sad8x2[0:1] + sad8x2[8:9]
   const __m128i sum = _mm_add_epi16(sad8x2, _mm_shuffle_epi32(sad8x2, 2));
   const int DC = _mm_cvtsi128_si32(sum) + 8;
-  Put16(DC >> 4, dst);
-}
-
-static void DC16NoTopLeft(uint8_t* dst) {  // DC with no top and left samples
-  Put16(0x80, dst);
+  Put16_SSE2(DC >> 4, dst);
+}
+
+static void DC16NoTopLeft_SSE2(uint8_t* dst) {  // DC with no top & left samples
+  Put16_SSE2(0x80, dst);
 }

 //------------------------------------------------------------------------------
 // Chroma

-static void VE8uv(uint8_t* dst) {    // vertical
+static void VE8uv_SSE2(uint8_t* dst) {    // vertical
   int j;
   const __m128i top = _mm_loadl_epi64((const __m128i*)(dst - BPS));
   for (j = 0; j < 8; ++j) {
@@ -1123,7 +1127,7 @@
   }
 }

-static void HE8uv(uint8_t* dst) {    // horizontal
+static void HE8uv_SSE2(uint8_t* dst) {    // horizontal
   int j;
   for (j = 0; j < 8; ++j) {
     const __m128i values = _mm_set1_epi8(dst[-1]);
@@ -1133,7 +1137,7 @@
 }

 // helper for chroma-DC predictions
-static WEBP_INLINE void Put8x8uv(uint8_t v, uint8_t* dst) {
+static WEBP_INLINE void Put8x8uv_SSE2(uint8_t v, uint8_t* dst) {
   int j;
   const __m128i values = _mm_set1_epi8(v);
   for (j = 0; j < 8; ++j) {
@@ -1141,7 +1145,7 @@
   }
 }

-static void DC8uv(uint8_t* dst) {     // DC
+static void DC8uv_SSE2(uint8_t* dst) {     // DC
   const __m128i zero = _mm_setzero_si128();
   const __m128i top = _mm_loadl_epi64((const __m128i*)(dst - BPS));
   const __m128i sum = _mm_sad_epu8(top, zero);
@@ -1152,29 +1156,29 @@
   }
   {
     const int DC = _mm_cvtsi128_si32(sum) + left + 8;
-    Put8x8uv(DC >> 4, dst);
-  }
-}
-
-static void DC8uvNoLeft(uint8_t* dst) {   // DC with no left samples
+    Put8x8uv_SSE2(DC >> 4, dst);
+  }
+}
+
+static void DC8uvNoLeft_SSE2(uint8_t* dst) {   // DC with no left samples
   const __m128i zero = _mm_setzero_si128();
   const __m128i top = _mm_loadl_epi64((const __m128i*)(dst - BPS));
   const __m128i sum = _mm_sad_epu8(top, zero);
   const int DC = _mm_cvtsi128_si32(sum) + 4;
-  Put8x8uv(DC >> 3, dst);
-}
-
-static void DC8uvNoTop(uint8_t* dst) {  // DC with no top samples
+  Put8x8uv_SSE2(DC >> 3, dst);
+}
+
+static void DC8uvNoTop_SSE2(uint8_t* dst) {  // DC with no top samples
   int dc0 = 4;
   int i;
   for (i = 0; i < 8; ++i) {
     dc0 += dst[-1 + i * BPS];
   }
-  Put8x8uv(dc0 >> 3, dst);
-}
-
-static void DC8uvNoTopLeft(uint8_t* dst) {    // DC with nothing
-  Put8x8uv(0x80, dst);
+  Put8x8uv_SSE2(dc0 >> 3, dst);
+}
+
+static void DC8uvNoTopLeft_SSE2(uint8_t* dst) {    // DC with nothing
+  Put8x8uv_SSE2(0x80, dst);
 }

 //------------------------------------------------------------------------------
@@ -1183,47 +1187,47 @@
 extern void VP8DspInitSSE2(void);

 WEBP_TSAN_IGNORE_FUNCTION void VP8DspInitSSE2(void) {
-  VP8Transform = Transform;
+  VP8Transform = Transform_SSE2;
 #if (USE_TRANSFORM_AC3 == 1)
   VP8TransformAC3 = TransformAC3_SSE2;
 #endif

-  VP8VFilter16 = VFilter16;
-  VP8HFilter16 = HFilter16;
-  VP8VFilter8 = VFilter8;
-  VP8HFilter8 = HFilter8;
-  VP8VFilter16i = VFilter16i;
-  VP8HFilter16i = HFilter16i;
-  VP8VFilter8i = VFilter8i;
-  VP8HFilter8i = HFilter8i;
-
-  VP8SimpleVFilter16 = SimpleVFilter16;
-  VP8SimpleHFilter16 = SimpleHFilter16;
-  VP8SimpleVFilter16i = SimpleVFilter16i;
-  VP8SimpleHFilter16i = SimpleHFilter16i;
-
-  VP8PredLuma4[1] = TM4;
-  VP8PredLuma4[2] = VE4;
-  VP8PredLuma4[4] = RD4;
-  VP8PredLuma4[5] = VR4;
-  VP8PredLuma4[6] = LD4;
-  VP8PredLuma4[7] = VL4;
-
-  VP8PredLuma16[0] = DC16;
-  VP8PredLuma16[1] = TM16;
-  VP8PredLuma16[2] = VE16;
-  VP8PredLuma16[3] = HE16;
-  VP8PredLuma16[4] = DC16NoTop;
-  VP8PredLuma16[5] = DC16NoLeft;
-  VP8PredLuma16[6] = DC16NoTopLeft;
-
-  VP8PredChroma8[0] = DC8uv;
-  VP8PredChroma8[1] = TM8uv;
-  VP8PredChroma8[2] = VE8uv;
-  VP8PredChroma8[3] = HE8uv;
-  VP8PredChroma8[4] = DC8uvNoTop;
-  VP8PredChroma8[5] = DC8uvNoLeft;
-  VP8PredChroma8[6] = DC8uvNoTopLeft;
+  VP8VFilter16 = VFilter16_SSE2;
+  VP8HFilter16 = HFilter16_SSE2;
+  VP8VFilter8 = VFilter8_SSE2;
+  VP8HFilter8 = HFilter8_SSE2;
+  VP8VFilter16i = VFilter16i_SSE2;
+  VP8HFilter16i = HFilter16i_SSE2;
+  VP8VFilter8i = VFilter8i_SSE2;
+  VP8HFilter8i = HFilter8i_SSE2;
+
+  VP8SimpleVFilter16 = SimpleVFilter16_SSE2;
+  VP8SimpleHFilter16 = SimpleHFilter16_SSE2;
+  VP8SimpleVFilter16i = SimpleVFilter16i_SSE2;
+  VP8SimpleHFilter16i = SimpleHFilter16i_SSE2;
+
+  VP8PredLuma4[1] = TM4_SSE2;
+  VP8PredLuma4[2] = VE4_SSE2;
+  VP8PredLuma4[4] = RD4_SSE2;
+  VP8PredLuma4[5] = VR4_SSE2;
+  VP8PredLuma4[6] = LD4_SSE2;
+  VP8PredLuma4[7] = VL4_SSE2;
+
+  VP8PredLuma16[0] = DC16_SSE2;
+  VP8PredLuma16[1] = TM16_SSE2;
+  VP8PredLuma16[2] = VE16_SSE2;
+  VP8PredLuma16[3] = HE16_SSE2;
+  VP8PredLuma16[4] = DC16NoTop_SSE2;
+  VP8PredLuma16[5] = DC16NoLeft_SSE2;
+  VP8PredLuma16[6] = DC16NoTopLeft_SSE2;
+
+  VP8PredChroma8[0] = DC8uv_SSE2;
+  VP8PredChroma8[1] = TM8uv_SSE2;
+  VP8PredChroma8[2] = VE8uv_SSE2;
+  VP8PredChroma8[3] = HE8uv_SSE2;
+  VP8PredChroma8[4] = DC8uvNoTop_SSE2;
+  VP8PredChroma8[5] = DC8uvNoLeft_SSE2;
+  VP8PredChroma8[6] = DC8uvNoTopLeft_SSE2;
 }

 #else  // !WEBP_USE_SSE2


Capped to opening a html directory in subdir Removed unecessary .. backlink for directory listing

--- src/server.c
+++ src/server.c
@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <time.h>
+#include <unistd.h>
 #include <sys/stat.h>
 #include <dirent.h>
 #include <netinet/in.h>
@@ -139,14 +140,18 @@
     char pathbuf[4096];
     int len;

-    printf("Processing request");
     if (!fgets(buf, sizeof(buf), f))
         return -1;
     printf("URL: %s", buf);

     //strtok - tokenizer strtok(NULL, " ") - takes another token
     method = strtok(buf, " ");
-    path = strtok(NULL, " ");
+    char curr_dir[150];
+    char *root;
+    getcwd(curr_dir, 150);
+    root = strcat(curr_dir, "/html");
+    path = strcat(root, strtok(NULL, " "));
+    printf("Path: %s\n", path);
     protocol = strtok(NULL, "\r");

     if (!method || !path || !protocol)
@@ -184,9 +189,6 @@
                 fprintf(f, "
Index of %s
\r\n", path);
                 fprintf(f, "
Name\t\t\t\t\tLast Modified\t\t\t\t\tSize\r\n");
                 fprintf(f, "
\r\n");
-
-                if (len > 1)
-                    fprintf(f, "..\r\n");

                 dir = opendir(path);
                 while((de = readdir(dir)) != NULL)


MsgPack: Using object returned by _put() to calculate iterator in insert(T)

--- src/msgpack.h
+++ src/msgpack.h
@@ -166,9 +166,6 @@
 	void _fill(bool recursive, bool lock);
 	void _fill(bool recursive, bool lock) const;

-	template <typename T, typename = std::enable_if_t<std::is_constructible<MsgPack, T>::value>>
-	std::pair<iterator, bool> insert(T&& v);
-
 public:
 	void lock() const;

@@ -188,6 +185,8 @@
 	MsgPack::iterator insert(const std::string& s, T&& val);
 	template <typename T>
 	MsgPack::iterator insert(size_t pos, T&& val);
+	template <typename T, typename = std::enable_if_t<std::is_constructible<MsgPack, T>::value>>
+	MsgPack::iterator insert(T&& v);

 	template <typename T>
 	MsgPack& push_back(T&& v);
@@ -1213,7 +1212,7 @@
 	switch (o._body->getType()) {
 		case Type::STR: {
 			auto& obj = _put(std::string(o._body->_obj->via.str.ptr, o._body->_obj->via.str.size), std::forward<T>(val));
-			return  MsgPack::Iterator<MsgPack>(this, obj->_body->_pos);
+			return  MsgPack::Iterator<MsgPack>(this, obj._body->_pos);
 		}
 		case Type::NEGATIVE_INTEGER:
 			if (o._body->_obj->via.i64 < 0) {
@@ -1237,7 +1236,7 @@
 template <typename T>
 inline MsgPack::iterator MsgPack::insert(const std::string& s, T&& val) {
 	auto& obj = _put(s, std::forward<T>(val));
-	return MsgPack::Iterator<MsgPack>(this, obj->_body->_pos);
+	return MsgPack::Iterator<MsgPack>(this, obj._body->_pos);
 }

@@ -1303,9 +1302,9 @@

 template <typename T, typename>
-inline std::pair<MsgPack::iterator, bool> MsgPack::insert(T&& v) {
+inline MsgPack::iterator MsgPack::insert(T&& v) {
 	MsgPack o(v);
-	bool done = false;
+	bool found = false;
 	MsgPack::Iterator<MsgPack> it = end();
 	switch (o._body->getType()) {
 		case Type::ARRAY:
@@ -1318,22 +1317,28 @@
 				if (key._body->getType() != Type::STR) {
 					break;
 				}
-				put(key, val);
-			}
-			done = true;
+				auto& obj = put(key, val);
+				if (!found) {
+					found = true;
+					it = MsgPack::Iterator<MsgPack>(this, obj._body->_pos);
+				}
+			}
 			break;
 		case Type::MAP:
 			for (auto& key : o) {
 				auto& val = o.at(key);
-				put(key, val);
-			}
-			done = true;
-			break;
-		default:
-			break;
-	}
-
-	return std::make_pair(it, done);
+				auto& obj = put(key, val);
+				if (!found) {
+					found = true;
+					it = MsgPack::Iterator<MsgPack>(this, obj._body->_pos);
+				}
+			}
+			break;
+		default:
+			break;
+	}
+
+	return it;
 }


enc_neon: enable intrinsics-only functions

CollectHistogram / SSE* / QuantizeBlock have no inline equivalents,
enable them where possible and use USE_INTRINSICS to control borderline
cases: it's left undefined for now.

Change-Id: I62235bc4ddb8aa0769d1ce18a90e0d7da1e18155

--- src/dsp/enc_neon.c
+++ src/dsp/enc_neon.c
@@ -15,7 +15,7 @@

 #if defined(WEBP_USE_NEON)

-#define USE_INTRINSICS   // use intrinsics when possible
+// #define USE_INTRINSICS   // use intrinsics when possible

 #include <assert.h>
 #include <arm_neon.h>
@@ -36,7 +36,7 @@
 // (with gcc-4.6). So we disable it for now. Later, it'll be conditional to
 // USE_INTRINSICS define.
 // With gcc-4.8, it's a little faster speed than inlined-assembly.
-#if 0  // defined(USE_INTRINSICS)
+#if defined(USE_INTRINSICS)

 // Treats 'v' as an uint8x8_t and zero extends to an int16x8_t.
 static WEBP_INLINE int16x8_t ConvertU8ToS16(uint32x2_t v) {
@@ -264,7 +264,7 @@

 // Forward transform.

-#if 0  // #ifdef USE_INTRINSICS
+#if defined(USE_INTRINSICS)

 static WEBP_INLINE void Transpose4x4_S16(const int16x4_t A, const int16x4_t B,
                                          const int16x4_t C, const int16x4_t D,
@@ -583,7 +583,7 @@
 // (with gcc-4.6). So we disable it for now. Later, it'll be conditional to
 // USE_INTRINSICS define.
 // With gcc-4.8, it's only slightly slower than the inlined.
-#if 0  // #ifdef USE_INTRINSICS
+#if defined(USE_INTRINSICS)

 // Zero extend an uint16x4_t 'v' to an int32x4_t.
 static WEBP_INLINE int32x4_t ConvertU16ToS32(uint16x4_t v) {
@@ -909,9 +909,6 @@
   return D;
 }

-
-#if defined(USE_INTRINSICS)
-
 //------------------------------------------------------------------------------

 static void CollectHistogram(const uint8_t* ref, const uint8_t* pred,
@@ -1002,13 +999,11 @@
   return SumToInt(vpaddlq_u16(prod));
 }

-#endif    // USE_INTRINSICS
-
 //------------------------------------------------------------------------------

 // Compilation with gcc-4.6.x is problematic for now. Disable this function
 // in this case.
-#if (__GNUC__ <= 4 && __GNUC_MINOR__ < 8)
+#if !LOCAL_GCC_PREREQ(4,8)
 #define SKIP_QUANTIZE
 #endif

@@ -1088,15 +1083,11 @@

   VP8TDisto4x4 = Disto4x4;
   VP8TDisto16x16 = Disto16x16;
-#if defined(USE_INTRINSICS)
   VP8CollectHistogram = CollectHistogram;
   VP8SSE16x16 = SSE16x16;
   VP8SSE16x8 = SSE16x8;
   VP8SSE8x8 = SSE8x8;
   VP8SSE4x4 = SSE4x4;
-#else
-  (void)Load4x4;    // to avoid a warning
-#endif
 #if !defined(SKIP_QUANTIZE)
   VP8EncQuantizeBlock = QuantizeBlock;
 #endif


added a hack to get the current number of open fds

--- src/server.c
+++ src/server.c
@@ -752,6 +752,21 @@
 			}
 		}

+		/* take probe to get an idea how many fds are currently open
+		 *
+		 * isn't there an easier way than calling open() ?
+		 *  */
+		if (1) {
+			int cur_max_fd;
+
+			if (-1 != (cur_max_fd = open("/dev/null", O_RDONLY))) {
+				close(cur_max_fd);
+				srv->cur_fds = cur_max_fd;
+			} else if (errno == EMFILE) {
+				srv->cur_fds = srv->max_fds;
+			}
+		}
+
 		if (srv->sockets_disabled) {
 			/* our server sockets are disabled, why ? */

@@ -801,7 +816,7 @@
 				} else if (srv->conns->used > srv->max_conns) {
 					log_error_write(srv, __FILE__, __LINE__, "s", "[note] sockets disabled, connection limit reached");
 				} else {
-					log_error_write(srv, __FILE__, __LINE__, "s", "[note] sockets disabled, out-of-fds (you may want to raise server.max-fds)");
+					TRACE("[note] servers sockets got disabled for a while as we are out of fds. We use %d of %d right now. (you may want to raise server.max-fds)", srv->cur_fds, srv->max_fds);
 				}

 				srv->sockets_disabled = 1;


WIP : Fix logic in flux register reset routine

--- src/patches/clawpatch/fclaw2d_clawpatch_conservation.c
+++ src/patches/clawpatch/fclaw2d_clawpatch_conservation.c
@@ -122,7 +122,7 @@
 		}
 		else if (reset_mode == FCLAW2D_TIME_SYNC_RESET_SAMESIZE)
 		{
-			reset_flux = (pdata->face_neighbors[k] == FCLAW2D_PATCH_SAMESIZE) ||
+			reset_flux = (pdata->face_neighbors[k] == FCLAW2D_PATCH_SAMESIZE) &&
 			      (this_patch->level == coarse_level);
 		}
 		else if (reset_mode == FCLAW2D_TIME_SYNC_RESET_LEVEL)


RuntimeConfigManager: Simplification.

RuntimeConfigManager: Simplification.

--- aprinter/printer/config_manager/RuntimeConfigManager.h
+++ aprinter/printer/config_manager/RuntimeConfigManager.h
@@ -346,19 +346,18 @@
     static bool checkCommand (Context c, WrapType<CommandChannel> cc)
     {
         auto cmd_num = CommandChannel::TheGcodeParser::getCmdNumber(c);
-        if (cmd_num == Params::GetConfigMCommand || cmd_num == Params::SetConfigMCommand) {
-            bool get_it = (cmd_num == Params::GetConfigMCommand);
-            char const *name = CommandChannel::get_command_param_str(c, 'I', "");
-            if (ListForEachForwardInterruptible<TypeGeneralList>(Foreach_get_set_cmd(), c, cc, get_it, name)) {
-                CommandChannel::reply_append_pstr(c, AMBRO_PSTR("Error:Unknown option\n"));
-            } else if (get_it) {
-                CommandChannel::reply_append_ch(c, '\n');
-            }
-            CommandChannel::finishCommand(c);
-            return false;
-        }
-        if (cmd_num == Params::ResetAllConfigMCommand) {
-            reset_all_config(c);
+        if (cmd_num == Params::GetConfigMCommand || cmd_num == Params::SetConfigMCommand || cmd_num == Params::ResetAllConfigMCommand) {
+            if (cmd_num == Params::ResetAllConfigMCommand) {
+                reset_all_config(c);
+            } else {
+                bool get_it = (cmd_num == Params::GetConfigMCommand);
+                char const *name = CommandChannel::get_command_param_str(c, 'I', "");
+                if (ListForEachForwardInterruptible<TypeGeneralList>(Foreach_get_set_cmd(), c, cc, get_it, name)) {
+                    CommandChannel::reply_append_pstr(c, AMBRO_PSTR("Error:Unknown option\n"));
+                } else if (get_it) {
+                    CommandChannel::reply_append_ch(c, '\n');
+                }
+            }
             CommandChannel::finishCommand(c);
             return false;
         }


Program hex files; run

Program hex files; run

--- selfprogram.c
+++ selfprogram.c
@@ -8,6 +8,7 @@
 #include <linux/hiddev.h>
 #include <poll.h>
 #include <stdbool.h>
+#include <stdio.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -45,13 +46,29 @@
 int verbosity;

-static
-int process_opts(int argc, char** argv)
+struct opts {
+    bool program_file;
+    bool print_config;
+    bool run;
+    bool test;
+};
+
+
+static
+int process_opts(int argc, char** argv, struct opts* opts)
 {
     opterr = 0;
     int r;
-    while ((r = getopt(argc, argv, "v")) != -1) {
-        if (r == 'v') {
+    while ((r = getopt(argc, argv, "fprTv")) != -1) {
+        if (r == 'f') {
+            opts->program_file = true;
+        } else if (r == 'p') {
+            opts->print_config = true;
+        } else if (r == 'r') {
+            opts->run = true;
+        } else if (r == 'T') {
+            opts->test = true;
+        } else if (r == 'v') {
             ++verbosity;
         } else if (r == '?') {
             fatal(E_COMMON, "Invalid option '%c'", optopt);
@@ -152,7 +169,8 @@

 static
-void send_data(int d, struct hiddev_usage_ref* ur, uint8_t* data, int len)
+void send_data_array(int d, struct hiddev_usage_ref* ur, unsigned int* data,
+        int len)
 {
     struct gp gp = {0};

@@ -172,15 +190,36 @@

 static
-int get_data(int d, struct hiddev_usage_ref* ur)
+void send_data(int d, struct hiddev_usage_ref* ur, unsigned int data, int len)
+{
+    struct gp gp = {0};
+
+    for (int b = 0; b < len; ++b) {
+        gp.dat = data & 1;
+        data >>= 1;
+        gp.clk = 1;
+        set_gp(d, ur, &gp);
+
+        usleep(T_CKH);
+
+        gp.clk = 0;
+        set_gp(d, ur, &gp);
+
+        usleep(T_CKL);
+    }
+}
+
+
+static
+unsigned int get_data(int d, struct hiddev_usage_ref* ur, int len)
 {
     struct gp gp = {0};

     gp.dat_in = 1;
     set_gp(d, ur, &gp);

-    int n = 0;
-    for (int b = 0; b <= 15; ++b) {
+    unsigned int n = 0;
+    for (int b = 0; b < len; ++b) {
         gp.clk = 1;
         set_gp(d, ur, &gp);

@@ -189,8 +228,7 @@
         gp.clk = 0;
         set_gp(d, ur, &gp);

-        if (1 <= b && b <= 14)
-            n = (n >> 1) + (get_dat(d, ur) << 13);
+        n = (n >> 1) + (get_dat(d, ur) << (len - 1));

         usleep(T_CKL);
     }
@@ -217,7 +255,7 @@

     usleep(T_ENTH);

-    uint8_t key[33] = {
+    unsigned int key[33] = {
         0, // don't care
         0, 1, 0, 0,
         1, 1, 0, 1,
@@ -228,91 +266,162 @@
         0, 1, 0, 1,
         0, 0, 0, 0,
     };
-    send_data(d, ur, key, lengthof(key));
+    send_data_array(d, ur, key, lengthof(key));
 }

 static
 void pic_load_configuration(int d, struct hiddev_usage_ref* ur)
 {
-    uint8_t command[6] = { 0, 0, 0, 0, 0, 0 };
-    send_data(d, ur, command, lengthof(command));
-
-    usleep(T_DLY);
-
-    uint8_t data[16] = {0};
-    send_data(d, ur, data, lengthof(data));
-
-    usleep(T_DLY);
+    send_data(d, ur, 0x00, 6);
+    usleep(T_DLY);
+    send_data(d, ur, 0x00, 16);
+    usleep(T_DLY);
+}
+
+
+static
+void pic_load_data(int d, struct hiddev_usage_ref* ur, unsigned int word)
+{
+    send_data(d, ur, 0x02, 6);
+    usleep(T_DLY);
+    send_data(d, ur, word << 1, 16);
+    usleep(T_DLY);
+}
+
+
+static
+unsigned int pic_read_data(int d, struct hiddev_usage_ref* ur)
+{
+    send_data(d, ur, 0x04, 6);
+    usleep(T_DLY);
+    unsigned int n = (get_data(d, ur, 16) >> 1) & 0x3FFF;
+    usleep(T_DLY);
+    return n;
 }

 static
 void pic_increment_address(int d, struct hiddev_usage_ref* ur)
 {
-    uint8_t command[6] = { 0, 0, 0, 1, 1, 0 };
-    send_data(d, ur, command, lengthof(command));
-
-    usleep(T_DLY);
-}
-
-
-static
-int pic_read_data(int d, struct hiddev_usage_ref* ur)
-{
-    uint8_t command[6] = { 0, 0, 0, 1, 0, 0 };
-    send_data(d, ur, command, lengthof(command));
-
-    usleep(T_DLY);
-
-    int n = get_data(d, ur);
-
-    usleep(T_DLY);
-
-    return n;
+    send_data(d, ur, 0x06, 6);
+    usleep(T_DLY);
+}
+
+
+static
+void pic_reset_address(int d, struct hiddev_usage_ref* ur)
+{
+    send_data(d, ur, 0x16, 6);
+    usleep(T_DLY);
+}
+
+
+static
+void pic_int_program(int d, struct hiddev_usage_ref* ur, bool config)
+{
+    send_data(d, ur, 0x08, 6);
+    usleep(config ? T_PINTC : T_PINTP);
+}
+
+
+static
+void pic_bulk_erase(int d, struct hiddev_usage_ref* ur)
+{
+    send_data(d, ur, 0x09, 6);
+    usleep(T_ERAB);
+}
+
+
+static
+void program_hex_file(int d, struct hiddev_usage_ref* ur, FILE* f)
+{
+    pic_bulk_erase(d, ur);
+    pic_reset_address(d, ur);
+
+    unsigned int addr = 0, len, newaddr, type;
+    int r;
+    while (true) {
+        r = fscanf(f, ":%2x%4x%2x", &len, &newaddr, &type);
+        if (ferror(f))
+            fatal_e(E_COMMON, "Can't read from hex file");
+        if (r < 3 || r == EOF)
+            fatal(E_COMMON, "Expected colon, length, address, and type");
+        if (type == 0x01)
+            break;
+
+        len /= 2;
+        newaddr /= 2;
+
+        if (newaddr < addr)
+            fatal(E_COMMON, "New address is lower than old address");
+
+        while (addr < newaddr) {
+            pic_increment_address(d, ur);
+            ++addr;
+        }
+
+        for (unsigned int i = 0; i < len; ++i) {
+            unsigned int low, high;
+            r = fscanf(f, "%2x%2x", &low, &high);
+            if (ferror(f))
+                fatal_e(E_COMMON, "Can't read from hex file");
+            if (r < 2 || r == EOF)
+                fatal(E_COMMON, "Expected word");
+            unsigned int word = low + (high << 8);
+            pic_load_data(d, ur, word);
+            pic_int_program(d, ur, false);
+            printf("[0x%04x] = 0x%04X\n", addr, word);
+            pic_increment_address(d, ur);
+            ++addr;
+        }
+
+        unsigned int garbage;
+        r = fscanf(f, "%2x\n", &garbage);
+            if (ferror(f))
+                fatal_e(E_COMMON, "Can't read from hex file");
+            if (r < 1 || r == EOF)
+                fatal(E_COMMON, "Expected checksum and newline");
+    }
 }

 int main(int argc, char** argv)
 {
-    int d;
+    struct opts opts = {0};
+    int first = process_opts(argc, argv, &opts);
+    if (opts.program_file + opts.print_config + opts.test > 1)
+        fatal(E_USAGE, "-f, -p, and -T are mutually exclusive");
+    if (argc - first != (opts.program_file ? 2 : 1))
+        fatal(E_USAGE, "Usage: %s [OPTIONS] DEVICE [HEXFILE]", argv[0]);
+
+    int d = open(argv[first], O_RDWR | O_NONBLOCK);
+    if (d == -1)
+        fatal_e(E_COMMON, "Can't open device");
+
+    struct hiddev_usage_ref* ur;
     {
-        int first = process_opts(argc, argv);
-        if (first >= argc)
-            fatal(E_USAGE, "Usage: %s [OPTIONS] DEVICE", argv[0]);
-
-        d = open(argv[first], O_RDWR | O_NONBLOCK);
-        if (d == -1)
-            fatal_e(E_COMMON, "Can't open device");
-    }
-
-    {
-        struct hiddev_usage_ref* ur;
-        {
-            struct hiddev_report_info ri;
-            ri.report_id = 0;
-            v1("Initializing...");
-            ur = init_report(d, &ri);
-        }
-
-        verify_fix_gp_settings(d, ur);
-
-        pic_enter_lvp(d, ur);
-
+        struct hiddev_report_info ri;
+        ri.report_id = 0;
+        v1("Initializing...");
+        ur = init_report(d, &ri);
+    }
+    verify_fix_gp_settings(d, ur);
+
+    pic_enter_lvp(d, ur);
+
+    if (opts.print_config) {
         pic_load_configuration(d, ur);

         unsigned int addr = 0x8000;
-
         print("User ID:\n");
         for (/* */; addr <= 0x8003; ++addr) {
             printf("    [0x%04"PRIX16"]: 0x%04"PRIX16"\n",
                 addr, pic_read_data(d, ur));
             pic_increment_address(d, ur);
         }
-
         for (/* */; addr <= 0x8004; ++addr)
             pic_increment_address(d, ur);
-
         print("Revision and device ID:\n");
         for (/* */; addr <= 0x8006; ++addr) {
             printf("    [0x%04"PRIX16"]: 0x%04"PRIX16"\n",
@@ -320,4 +429,33 @@
             pic_increment_address(d, ur);
         }
     }
-}
+
+    if (opts.test) {
+        pic_load_configuration(d, ur);
+        pic_bulk_erase(d, ur);
+        pic_load_data(d, ur, 0x0123);
+        pic_int_program(d, ur, true);
+    }
+
+    if (opts.program_file) {
+        FILE* f = fopen(argv[first + 1], "r");
+        if (f == NULL)
+            fatal_e(E_COMMON, "Can't open hex file");
+        program_hex_file(d, ur, f);
+        fclose(f); // and ignore errors
+    }
+
+    if (opts.run) {
+        struct gp gp = {
+            .n_mclr = 1,
+            .clk = 0,
+            .dat = 0,
+            .dat_in = 0,
+        };
+        set_gp(d, ur, &gp);
+    }
+
+    close(d); // and ignore errors
+
+    return 0;
+}


warning free.

warning free.

--- swoole_server.c
+++ swoole_server.c
@@ -2181,7 +2181,6 @@
     }

     int ret = 0;
-    int l = -1;
     SwooleG.lock.lock(&SwooleG.lock);
     if(conn->uid == 0) {
         conn->uid = uid;


Evas: No need to 'find format for depth' everytime, just use the
buffer depth. Fix typo in error message. Add a missing
cache_image_drop call. When doing mask_set, use the proper variable
for the _create_gc function.

git-svn-id: 24a995eca3b83137dd7eab3408044d7832e202f7@62603 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

--- src/modules/engines/software_x11/evas_xcb_outbuf.c
+++ src/modules/engines/software_x11/evas_xcb_outbuf.c
@@ -91,13 +91,11 @@
    Outbuf *buf = NULL;
    Gfx_Func_Convert func_conv= NULL;
    const xcb_setup_t *setup;
-   xcb_format_t *fmt;

    if (!(buf = calloc(1, sizeof(Outbuf))))
      return NULL;

    setup = xcb_get_setup(conn);
-   fmt = _find_format_by_depth(setup, xdepth);

    buf->w = w;
    buf->h = h;
@@ -203,7 +201,7 @@
    if (buf->priv.pal)
      {
         func_conv =
-          evas_common_convert_func_get(0, w, h, fmt->bits_per_pixel,
+          evas_common_convert_func_get(0, w, h, xdepth,
                                        buf->priv.mask.r,
                                        buf->priv.mask.g,
                                        buf->priv.mask.b,
@@ -212,7 +210,7 @@
    else
      {
         func_conv =
-          evas_common_convert_func_get(0, w, h, fmt->bits_per_pixel,
+          evas_common_convert_func_get(0, w, h, xdepth,
                                        buf->priv.mask.r,
                                        buf->priv.mask.g,
                                        buf->priv.mask.b,
@@ -225,7 +223,7 @@
             "  At depth         %i:"
             "  RGB format mask: %08x, %08x, %08x"
             "  Palette mode:    %i"
-            "  Not supported by and compiled in converters!"
+            "  Not supported by any compiled in converters!"
             " }", buf->priv.x11.xcb.depth, buf->priv.mask.r,
             buf->priv.mask.g, buf->priv.mask.b,
             buf->priv.pal ? (int)buf->priv.pal->colors : -1);
@@ -613,7 +611,6 @@
         /* FIXME: Async Push Disabled */

         _xcbob_sync(buf->priv.x11.xcb.conn);
-
         while (buf->priv.pending_writes)
           {
              im = eina_list_data_get(buf->priv.pending_writes);
@@ -625,7 +622,7 @@
              if (obr->xcbob) _unfind_xcbob(obr->xcbob, EINA_FALSE);
              if (obr->mask) _unfind_xcbob(obr->mask, EINA_FALSE);
              free(obr);
-//             evas_cache_image_drop(&im->cache_entry);
+             evas_cache_image_drop(&im->cache_entry);
           }
 #endif
      }
@@ -643,12 +640,12 @@
         im = buf->priv.onebuf;
         buf->priv.onebuf = NULL;
         obr = im->extended_info;
-        evas_cache_image_drop(&im->cache_entry);
         if (obr->xcbob)
           evas_software_xcb_output_buffer_free(obr->xcbob, EINA_FALSE);
         if (obr->mask)
           evas_software_xcb_output_buffer_free(obr->mask, EINA_FALSE);
         free(obr);
+        evas_cache_image_drop(&im->cache_entry);
      }
    else
      {
@@ -688,23 +685,10 @@
    unsigned char *data = NULL;
    int bpl = 0, yy = 0;
    int bw = 0, bh = 0;
-   int bpp = 0;

    obr = update->extended_info;
    if (!obr->xcbob) return;

-   if (obr->xcbob->xim)
-     bpp = obr->xcbob->xim->bpp;
-   else
-     {
-        const xcb_setup_t *setup;
-        xcb_format_t *fmt;
-
-        setup = xcb_get_setup(buf->priv.x11.xcb.conn);
-        fmt = _find_format_by_depth(setup, buf->priv.x11.xcb.depth);
-        bpp = fmt->bits_per_pixel;
-     }
-
    if ((buf->rot == 0) || (buf->rot == 180))
      {
         bw = w;
@@ -718,18 +702,19 @@
    if (buf->priv.pal)
      {
         func_conv =
-          evas_common_convert_func_get(0, bw, bh, bpp, buf->priv.mask.r,
+          evas_common_convert_func_get(0, bw, bh, buf->depth, buf->priv.mask.r,
                                        buf->priv.mask.g, buf->priv.mask.b,
                                        buf->priv.pal->colors, buf->rot);
      }
    else
      {
         func_conv =
-          evas_common_convert_func_get(0, bw, bh, bpp, buf->priv.mask.r,
+          evas_common_convert_func_get(0, bw, bh, buf->depth, buf->priv.mask.r,
                                        buf->priv.mask.g, buf->priv.mask.b,
                                        PAL_MODE_NONE, buf->rot);
      }
    if (!func_conv) return;
+
    if (!(data = evas_software_xcb_output_buffer_data(obr->xcbob, &bpl)))
      return;
    if (!(src_data = update->image.data)) return;
@@ -764,18 +749,17 @@
    if (buf->onebuf)
      {
         src_data += x + (y * update->cache_entry.w);
-        data += (bpl * obr->y) +
-           (obr->x * (evas_software_xcb_output_buffer_depth(obr->xcbob) / 8));
+        data += (bpl * obr->y) + (obr->x * (buf->depth / 8));
      }
    if (data != (unsigned char *)src_data)
      {
         if (buf->priv.pal)
           func_conv(src_data, data, update->cache_entry.w - w,
-                    (bpl / (bpp / 8)) - obr->w,
+                    (bpl / (buf->depth / 8)) - obr->w,
                     obr->w, obr->h, x, y, buf->priv.pal->lookup);
         else
           func_conv(src_data, data, update->cache_entry.w - w,
-                    (bpl / (bpp / 8)) - obr->w,
+                    (bpl / (buf->depth / 8)) - obr->w,
                     obr->w, obr->h, x, y, NULL);
      }
 #if 1
@@ -827,7 +811,7 @@
 #else
         /* Async Push */
         if (!((buf->priv.onebuf) && (buf->priv.onebuf_regions)))
-          evas_software_xcb_output_buffer_paste(obr->xcbob,
+          evas_software_xcb_output_buffer_paste(obr->mask,
                                                 buf->priv.x11.xcb.mask,
                                                 buf->priv.x11.xcb.gcm,
                                                 obr->x, obr->y, 0);
@@ -897,7 +881,7 @@
      {
         buf->priv.x11.xcb.gcm = xcb_generate_id(buf->priv.x11.xcb.conn);
         xcb_create_gc(buf->priv.x11.xcb.conn,
-                      buf->priv.x11.xcb.gcm, buf->priv.x11.xcb.win, 0, NULL);
+                      buf->priv.x11.xcb.gcm, buf->priv.x11.xcb.mask, 0, NULL);
      }
 }


Add missing prototype declaration.

Add missing prototype declaration.

* subversion/bindings/swig/ruby/libsvn_swig_ruby/swigutil_rb.h
  (svn_swig_rb_apr_hash_to_hash_svn_string): Add.

--- subversion/bindings/swig/ruby/libsvn_swig_ruby/swigutil_rb.h
+++ subversion/bindings/swig/ruby/libsvn_swig_ruby/swigutil_rb.h
@@ -27,6 +27,7 @@
 VALUE svn_swig_rb_svn_error_new(VALUE code, VALUE message);

 VALUE svn_swig_rb_apr_hash_to_hash_string(apr_hash_t *hash);
+VALUE svn_swig_rb_apr_hash_to_hash_svn_string(apr_hash_t *hash);
 VALUE svn_swig_rb_apr_hash_to_hash_swig_type(apr_hash_t *hash,
                                              const char *type_name);


Delete dplicate function in MsgPack

Delete dplicate function in MsgPack

--- src/msgpack.h
+++ src/msgpack.h
@@ -174,17 +174,7 @@
 	void reset(const MsgPack& other);
 	MsgPack path(const std::vector<std::string>& path) const;

-	template<typename M, typename std::enable_if_t<std::is_base_of<MsgPack, std::decay_t<M>>::value>* = nullptr>
-	MsgPack& operator=(M&& v) {
-		msgpack::object o(std::forward<M>(v), handler->zone.get());
-		body->obj->type = o.type;
-		body->obj->via = o.via;
-		body->m_alloc = -1;
-		init();
-		return *this;
-	}
-
-	template<typename T, typename std::enable_if_t<!std::is_base_of<MsgPack, std::decay_t<T>>::value>* = nullptr>
+	template<typename T>
 	MsgPack& operator=(T&& v) {
 		msgpack::object o(std::forward<T>(v), handler->zone.get());
 		body->obj->type = o.type;


Fix timer_list and events memory leak when shutting down

--- src/server.c
+++ src/server.c
@@ -13,6 +13,7 @@

 #define POLL_EVENTS POLLIN|POLLPRI

+// TODO we need a test build with 200ms. See defs.h.in
 #define TIMER_KAD_REFRESH_MILLIS 300000

 static int pollfds_update(struct pollfd fds[], const int nlisten,
@@ -34,6 +35,29 @@
         npeer++;
     }
     return npeer;
+}
+
+static bool timer_list_free_all(struct list_item *timers)
+{
+    log_debug("Freeing remaining timers and events.");
+    struct list_item * it = timers;
+    list_for(it, timers) {
+        struct timer *t = cont(it, struct timer, item);
+        if (!t) {
+            log_error("Undefined container in list.");
+            return false;
+        }
+
+        it = it->prev; // deleting inside for_list
+        list_delete(&t->item);
+        if (t->event && t->event->self) {
+            free(t->event->self);
+        }
+        if (t->self) {
+            free(t->self);
+        }
+    }
+    return true;
 }

 /**
@@ -103,7 +127,7 @@
         struct timer *timer_kad_bootstrap = malloc(sizeof(struct timer));
         if (!timer_kad_bootstrap) {
             log_perror(LOG_ERR, "Failed malloc: %s.", errno);
-            free(event_kad_bootstrap);
+            free_safer(event_kad_bootstrap);
             return false;
         }
         *timer_kad_bootstrap = (struct timer){
@@ -239,6 +263,8 @@
     } /* End event loop */

   server_end:
+    timer_list_free_all(&timer_list);
+
     peer_conn_close_all(&peer_list);

     kad_rpc_terminate(&kctx, conf->conf_dir);


Fix lightfunc constructor handling

Fix lightfunc constructor handling

* Allow lightfunc as constructor.

* Allow a bound function wrapping a lightfunc to work as a constructor.

--- src/duk_api_call.c
+++ src/duk_api_call.c
@@ -293,21 +293,41 @@

 	duk_dup(ctx, idx_cons);
 	for (;;) {
-		cons = duk_get_hobject(ctx, -1);
-		if (cons == NULL || !DUK_HOBJECT_HAS_CONSTRUCTABLE(cons)) {
-			/* Checking constructability from anything else than the
-			 * initial constructor is not strictly necessary, but a
-			 * nice sanity check.
-			 */
+		duk_tval *tv;
+		tv = DUK_GET_TVAL_NEGIDX(ctx, -1);
+		DUK_ASSERT(tv != NULL);
+
+		if (DUK_TVAL_IS_OBJECT(tv)) {
+			cons = DUK_TVAL_GET_OBJECT(tv);
+			DUK_ASSERT(cons != NULL);
+			if (!DUK_HOBJECT_IS_CALLABLE(cons) || !DUK_HOBJECT_HAS_CONSTRUCTABLE(cons)) {
+				/* Checking callability of the immediate target
+				 * is important, same for constructability.
+				 * Checking it for functions down the bound
+				 * function chain is not strictly necessary
+				 * because .bind() should normally reject them.
+				 * But it's good to check anyway because it's
+				 * technically possible to edit the bound function
+				 * chain via internal keys.
+				 */
+				goto not_constructable;
+			}
+			if (!DUK_HOBJECT_HAS_BOUNDFUNC(cons)) {
+				break;
+			}
+		} else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
+			/* Lightfuncs cannot be bound. */
+			break;
+		} else {
+			/* Anything else is not constructable. */
 			goto not_constructable;
-		}
-		if (!DUK_HOBJECT_HAS_BOUNDFUNC(cons)) {
-			break;
 		}
 		duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INT_TARGET);  /* -> [... cons target] */
 		duk_remove(ctx, -2);                                  /* -> [... target] */
 	}
-	DUK_ASSERT(cons != NULL && !DUK_HOBJECT_HAS_BOUNDFUNC(cons));
+	DUK_ASSERT(duk_is_callable(ctx, -1));
+	DUK_ASSERT(duk_is_lightfunc(ctx, -1) ||
+	           (duk_get_hobject(ctx, -1) != NULL && !DUK_HOBJECT_HAS_BOUNDFUNC(duk_get_hobject(ctx, -1))));

 	/* [... constructor arg1 ... argN final_cons] */


MIPS: DECstation CPU feature overrides

MIPS: DECstation CPU feature overrides

Signed-off-by: Maciej W. Rozycki <78f3a3d9d6e4d907a7d12e475d0a751d6b7e256b@linux-mips.org>
Cc: 562397917b9a8bf316569a848858b12fb417723f@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/5877/
Signed-off-by: Ralf Baechle <92f48d309cda194c8eda36aa8f9ae28c488fa208@linux-mips.org>


fixed onTask memory leak on PHP7.

fixed onTask memory leak on PHP7.

--- swoole_server.c
+++ swoole_server.c
@@ -814,7 +814,7 @@

     sw_zval_ptr_dtor(&zfd);
     sw_zval_ptr_dtor(&zfrom_id);
-    sw_zval_ptr_dtor(&zdata);
+    sw_zval_free(zdata);

     if (retval)
     {