unu slice can now do multiple slices at once

git-svn-id: 9e9401559e51101c165cdce4d49b411eb20436ed@5560 3d70eeeb-363e-0410-a505-8a46323a89f2

--- src/unrrdu/slice.c
+++ src/unrrdu/slice.c
@@ -24,13 +24,14 @@
 #include "unrrdu.h"
 #include "privateUnrrdu.h"

-#define INFO "Slice at a position along an axis"
+#define INFO "Slice along one or more axes at given positions"
 char *_unrrdu_sliceInfoL =
   (INFO
-   ". Output nrrd dimension is one less than input nrrd "
-   "dimension (except when the input is itself 1-D).  "
+   ". Output nrrd dimension is less than input nrrd "
+   "dimension by the number of slice axes (except when the "
+   "input is or gets down to 1-D). "
    "Per-axis information is preserved.\n "
-   "* Uses nrrdSlice");
+   "* Uses nrrdSlice (possibly called multiple times)");

 int
 unrrdu_sliceMain(int argc, const char **argv, const char *me,
@@ -38,19 +39,27 @@
   hestOpt *opt = NULL;
   char *out, *err;
   Nrrd *nin, *nout;
-  unsigned int axis;
-  int pret;
-  size_t pos;
-  long int _pos[2];
+  unsigned int *axis;
+  int pret, axi, axisNum, posNum;
+  size_t pos[NRRD_DIM_MAX];
+  long int *_pos;
   airArray *mop;

-  OPT_ADD_AXIS(axis, "axis to slice along");
-  hestOptAdd(&opt, "p,position", "pos", airTypeOther, 1, 1, _pos, NULL,
-             "position to slice at:\n "
+  hestOptAdd(&opt, "a,axis", "axis", airTypeUInt, 1, -1, &axis, NULL,
+             "single axis or multiple axes to slice along.  "
+             "Giving multiple axes here leads to doing multiple slices "
+             "(at the corresponding positions "
+             "given with \"-p\"). Multiple axes should be identified "
+             "in terms of the axis numbering of the original nrrd; as "
+             "the slices are done (in the given ordering) the actual "
+             "slice axis will be different if previous slices were on "
+             "lower-numbered (faster) axes.", &axisNum);
+  hestOptAdd(&opt, "p,position", "pos", airTypeOther, 1, -1, &_pos, NULL,
+             "position(s) to slice at:\n "
              "\b\bo <int> gives 0-based index\n "
              "\b\bo M-<int> give index relative "
              "to the last sample on the axis (M == #samples-1).",
-             NULL, NULL, &unrrduHestPosCB);
+             &posNum, NULL, &unrrduHestPosCB);
   OPT_ADD_NIN(nin, "input nrrd");
   OPT_ADD_NOUT(out, "output nrrd");

@@ -60,24 +69,96 @@
   USAGE(_unrrdu_sliceInfoL);
   PARSE();
   airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);
-  if (!( axis < nin->dim )) {
-    fprintf(stderr, "%s: axis %d not in range [0,%d]\n", me, axis, nin->dim-1);
-    return 1;
+  if (axisNum != posNum) {
+    fprintf(stderr, "%s: # axes %u != # positions %u\n", me, axisNum, posNum);
+    airMopError(mop); return 1;
   }
-  if (_pos[0] == -1) {
-    fprintf(stderr, "%s: m+<int> specification format meaningless here\n", me);
-    return 1;
+  if (axisNum > NRRD_DIM_MAX) {
+    fprintf(stderr, "%s: got more slice axes %u than max nrrd dimension %u\n",
+            me, axisNum, NRRD_DIM_MAX);
+    airMopError(mop); return 1;
   }
-  pos = _pos[0]*(nin->axis[axis].size-1) + _pos[1];
+  for (axi=0; axi<axisNum; axi++) {
+    char stmp[AIR_STRLEN_SMALL];
+    if (axisNum > 1) {
+      sprintf(stmp, "[%d]", axi);
+    } else {
+      strcpy(stmp, "");
+    }
+    if (!( axis[axi] < nin->dim )) {
+      fprintf(stderr, "%s: axis%s %d not in range [0,%d]\n",
+              me, stmp, axis[axi], nin->dim-1);
+      airMopError(mop); return 1;
+    }
+    if (_pos[0 + 2*axi] == -1) {
+      fprintf(stderr, "%s: pos%s m+<int> spec not meaningful here\n",
+              me, stmp);
+      airMopError(mop); return 1;
+    }
+    pos[axi] = (_pos[0 + 2*axi]*(nin->axis[axis[axi]].size-1)
+                + _pos[1 + 2*axi]);
+    /*
+    printf("%s: [%d] axis = %u, pos = %u\n", me, axi, axis[axi],
+           AIR_CAST(unsigned int, pos[axi]));
+    */
+  }
+  /* check on possibly adjust slice axes downward */
+  if (axisNum > 1) {
+    int axj;
+    for (axi=0; axi<axisNum-1; axi++) {
+      for (axj=axi+1; axj<axisNum; axj++) {
+        if (axis[axi] == axis[axj]) {
+          fprintf(stderr, "%s: can't repeat axis: axis[%d] = axis[%d] = %u\n",
+                  me, axi, axj, axis[axj]);
+          airMopError(mop); return 1;
+        }
+      }
+    }
+    for (axi=0; axi<axisNum-1; axi++) {
+      for (axj=axi+1; axj<axisNum; axj++) {
+        axis[axj] -= (axis[axj] > axis[axi]);
+      }
+    }
+    /*
+    for (axi=0; axi<axisNum; axi++) {
+      printf("%s: axis[%d] = %u\n", me, axi, axis[axi]);
+    }
+    */
+  }

   nout = nrrdNew();
   airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);

-  if (nrrdSlice(nout, nin, axis, pos)) {
-    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
-    fprintf(stderr, "%s: error slicing nrrd:\n%s", me, err);
-    airMopError(mop);
-    return 1;
+  if (1 == axisNum) {
+    /* old single axis code */
+    if (nrrdSlice(nout, nin, axis[0], pos[0])) {
+      airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
+      fprintf(stderr, "%s: error slicing nrrd:\n%s", me, err);
+      airMopError(mop); return 1;
+    }
+  } else {
+    /* have to do multiple slices */
+    Nrrd *ntmp[2];
+    unsigned int tidx = 0;
+    ntmp[0] = nrrdNew();
+    airMopAdd(mop, ntmp[0], (airMopper)nrrdNuke, airMopAlways);
+    ntmp[1] = nrrdNew();
+    airMopAdd(mop, ntmp[1], (airMopper)nrrdNuke, airMopAlways);
+    for (axi=0; axi<axisNum; axi++) {
+      if (nrrdSlice((axi < axisNum-1
+                     ? ntmp[1-tidx] /* use an ntmp for all but last output */
+                     : nout),       /* and use nout for last output */
+                    (0 == axi
+                     ? nin          /* use nin for only first input */
+                     : ntmp[tidx]), /* use an ntmp for all but first input */
+                    axis[axi], pos[axi])) {
+        airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
+        fprintf(stderr, "%s: error with slice %d of %d:\n%s", me,
+                axi+1, axisNum, err);
+        airMopError(mop); return 1;
+      }
+      tidx = 1 - tidx;
+    }
   }

   SAVE(out, nout, NULL);


Simplify, rearrange a bit, and fix some bugs

This was quite a session of back-and-forth.  It might be possible to
split it up into simpler commits, but I've got better things to do with
my time at the moment.

--- pebble/src/modules/data.c
+++ pebble/src/modules/data.c
@@ -25,7 +25,7 @@
 static const uint8_t * s_agenda;
 static int32_t s_agenda_version;

-#define MAX_AGENDA_CAPACITY_BYTES (1<<12)
+#define MAX_AGENDA_CAPACITY_BYTES (1<<10)
 #define MIN_AGENDA_CAPACITY_BYTES (64)

 // All known data keys, from appinfo.js#appKeys
@@ -152,11 +152,28 @@
     // TODO: switch on error to ignore for now (present behavior), retry
     // with another call to bsky_data_update, or disable bsky_data for
     // some time.
+    const char * err_name = NULL;
+    switch (dict_error) {
+        case DICT_NOT_ENOUGH_STORAGE:
+            err_name = "DICT_NOT_ENOUGH_STORAGE"; break;
+        case DICT_INVALID_ARGS:
+            err_name = "DICT_INVALID_ARGS"; break;
+        case DICT_INTERNAL_INCONSISTENCY:
+            err_name = "DICT_INTERNAL_INCONSISTENCY"; break;
+        case DICT_MALLOC_FAILED:
+            err_name = "DICT_MALLOC_FAILED"; break;
+        case DICT_OK:
+            break;
+    }
+    if (err_name) {
+        APP_LOG(APP_LOG_LEVEL_ERROR,
+                "bsky_data_sync_error: %s",
+                err_name);
+    }
 }

 static AppSync s_sync;
 static uint8_t * s_buffer;
-static size_t s_buffer_size;

 bool bsky_data_init(void) {
     // We use static bool values help to ensure this method is
@@ -170,41 +187,7 @@
     if (s_bsky_data_inited_already) { return true; }
     APP_LOG(APP_LOG_LEVEL_DEBUG, "bsky_data_init()");

-    // Calculate and allocate memory for the sync dictionary.
-    //
-    // The general approach here with s_agenda_capacity_bytes is to
-    // start with an ideal maximum and cut it in half any time an
-    // allocation fails.
-    //
-    if (!s_buffer) {
-        s_agenda_capacity_bytes = MAX_AGENDA_CAPACITY_BYTES;
-        do {
-            s_buffer_size = dict_calc_buffer_size(
-                3,
-                sizeof(int32_t),
-                sizeof(int32_t),
-                s_agenda_capacity_bytes);
-            s_buffer = malloc(s_buffer_size);
-            if (s_buffer) {
-                break;
-            }
-            s_agenda_capacity_bytes /= 2;
-            if (s_agenda_capacity_bytes < MIN_AGENDA_CAPACITY_BYTES) {
-                break;
-            }
-        } while (!s_buffer);
-        if (!s_buffer) {
-            APP_LOG(APP_LOG_LEVEL_ERROR,
-                    "bsky_data_init: malloc(%u) failed",
-                    s_buffer_size);
-            return false;
-        }
-        APP_LOG(APP_LOG_LEVEL_DEBUG,
-                "bsky_data_init: malloc(%u):"
-                " s_agenda_capacity_bytes=%ld",
-                s_buffer_size,
-                s_agenda_capacity_bytes);
-    }
+    s_agenda_capacity_bytes = MAX_AGENDA_CAPACITY_BYTES;

     // Open the app_message inbox and outboxes.  Doing this before
     // registering app_message event handlers may result in dropping
@@ -217,30 +200,18 @@
                 sizeof(int32_t),
                 sizeof(int32_t));
         AppMessageResult result; // lint...
-        while (s_agenda_capacity_bytes >= MIN_AGENDA_CAPACITY_BYTES) {
-            const uint32_t size_inbound = dict_calc_buffer_size(
-                    2,
-                    s_agenda_capacity_bytes,
-                    sizeof(int32_t));
-            result = app_message_open(
-                    size_inbound,
-                    size_outbound);
-            if (result != APP_MSG_OUT_OF_MEMORY) {
-                APP_LOG(APP_LOG_LEVEL_DEBUG,
-                        "app_message_open:"
-                        " size_inbound=%lu,size_outbound=%lu",
-                        size_inbound,
-                        size_outbound);
-                break;
-            }
-            s_agenda_capacity_bytes /= 2;
-            if (s_agenda_capacity_bytes < MIN_AGENDA_CAPACITY_BYTES) {
-                s_agenda_capacity_bytes = 0;
-                APP_LOG(APP_LOG_LEVEL_INFO,
-                        "stopping at tried-everything");
-                break;
-            }
-        }
+        const uint32_t size_inbound = dict_calc_buffer_size(
+                2,
+                s_agenda_capacity_bytes,
+                sizeof(int32_t));
+        APP_LOG(APP_LOG_LEVEL_DEBUG,
+                "attempting app_message_open:"
+                " size_inbound=%lu,size_outbound=%lu",
+                size_inbound,
+                size_outbound);
+        result = app_message_open(
+                size_inbound,
+                size_outbound);
         if (result != APP_MSG_OK) {
             APP_LOG(APP_LOG_LEVEL_ERROR,
                     "app_message_open: %u",
@@ -262,11 +233,15 @@
     // defaults here typically should be zero.
     //
     if (!s_app_sync_inited_already) {
+        if (s_buffer) {
+            free (s_buffer);
+            s_buffer = NULL;
+        }
         uint8_t * zero_agenda = calloc (s_agenda_capacity_bytes, 1);
         if (!zero_agenda) {
             APP_LOG(APP_LOG_LEVEL_ERROR,
                     "bsky_data_init:"
-                    " out of memory at inopportune moment");
+                    " calloc failed to allocate initialization buffer");
             return false;
         }
         Tuplet initial_values[] = {
@@ -277,18 +252,29 @@
             TupletBytes(
                     BSKY_DATAKEY_AGENDA,
                     zero_agenda,
-                    sizeof(zero_agenda)),
+                    s_agenda_capacity_bytes),
             TupletInteger(
                     BSKY_DATAKEY_AGENDA_VERSION, (int32_t) 0),
             TupletInteger(
                     BSKY_DATAKEY_PEBBLE_NOW_UNIX_TIME,
                     (int32_t) time(NULL)),
         };
+        uint32_t buffer_size = dict_calc_buffer_size_from_tuplets(
+            initial_values,
+            sizeof(initial_values)/sizeof(initial_values[0]));
+        s_buffer = malloc(buffer_size);
+        if (!s_buffer) {
+            free(zero_agenda);
+            APP_LOG(APP_LOG_LEVEL_ERROR,
+                    "bsky_data_init:"
+                    " malloc failed to allocate sync buffer");
+            return false;
+        }
         APP_LOG(APP_LOG_LEVEL_DEBUG, "bsky_data_init: app_sync_init()");
         app_sync_init(
                 &s_sync,
                 s_buffer,
-                s_buffer_size,
+                buffer_size,
                 initial_values,
                 sizeof(initial_values)/sizeof(initial_values[0]),
                 bsky_data_sync_tuple_changed,


abiocardserver now runs over stdinput too

--- abiocard/abiocardserver.c
+++ abiocard/abiocardserver.c
@@ -242,8 +242,13 @@
     {
         int     n;

-        n = send(client_socket,snd_rsp,snd_rsp_si,0);
-        if (n < 0) return 0;
+        if(commandline_mode) {
+
+        } else {
+            n = send(client_socket,snd_rsp,snd_rsp_si,0);
+            if (n < 0) return 0;
+        }
+

         // Reset the response buffer
         snd_rsp_si = 0;
@@ -876,7 +881,7 @@
     U32         cmd_left;
     FLAG        ok;

-/*
+
     // DBG.
     {
         U32     u;
@@ -885,7 +890,7 @@
         for (u = 0; u < rcv_cmd_si; u++) printf("%c",rcv_cmd[u]);
         printf("\n");
     }
-*/
+

     // Reset the command receive buffer
     rcv_cmd_fi = 0;
@@ -1005,6 +1010,7 @@
 #ifndef DISABLE_ABIOCARD
     FLAG    ok;

+
     // Initialise the AbioCard driver
     ok = abiocard_init(&abiocard_init_io);
     if (!ok) return;
@@ -1156,6 +1162,7 @@
         if (strcmp(argv[arg_index],"-cl") == 0)
         {
             commandline_mode = 1;
+            return 1;
         }
         else
             return 0;
@@ -1184,6 +1191,7 @@
         "-p n       Server port, n=1..65535\n" \
         "-t n       Time-out value (seconds) for the client connection, n=5..65535\n" \
         "-bsc n     Choose the BSC controller, n=0..1\n" \
+        "-cl        Use command line mode instead of telnet server\n" \
         "\n"
     );
 }
@@ -1266,7 +1274,26 @@

     //Check if command line mode
     if(commandline_mode == 1){
+#ifndef DISABLE_ABIOCARD
+            FLAG    ok;
+
+
+            // Initialise the AbioCard driver
+            ok = abiocard_init(&abiocard_init_io);
+            if (!ok) return;
+#else
+            // Emulate
+            abiocard_init_io.rtc_present   = 0;
+            abiocard_init_io.ioexp_present = 0;
+            abiocard_init_io.adc_present   = 0;
+            abiocard_init_io.pwm_present   = 1;
+            abiocard_init_io.pwm2_present  = 0;
+#endif
+
+
+
         //Read the commands from command line instead of opening a telent server.
+        printf("Accept commands\n");

 	     int     n;

@@ -1276,54 +1303,68 @@
 	     // Reset the received command buffer
 	     rcv_cmd_si    = 0;
 	     rcv_cmd_error = 0;
-
 	     for (;;)
 	     {
-            int c = fgetc(stdin);
-            if ((c == 13) || (c == 10))
-            {
-                if (!rcv_cmd_error)
+             for (;;)
+             {
+                int c = fgetc(stdin);
+                if ((c == 13) || (c == 10))
                 {
-                    if (rcv_cmd_si > 0)
+                    if (!rcv_cmd_error)
                     {
-                        process_rcv_cmd();
-                        if (req_exit) return;
+                        if (rcv_cmd_si > 0)
+                        {
+                            process_rcv_cmd();
+                            if (req_exit)
+                             {
+#ifndef DISABLE_ABIOCARD
+                                 // De-initialise the AbioCard driver
+                                 abiocard_deinit();
+#endif
+                                 return 0;
+                             }
+                        }
+                    } else {
+                        printf("Receive command error\n");
+                    }
+                    // Reset the received command buffer
+                    rcv_cmd_si    = 0;
+                    rcv_cmd_error = 0;
+                    break;
+                }
+                else
+                if ((c >= 32) && (c <= 126))
+                {
+                    if (!rcv_cmd_error)
+                    {
+                        if (rcv_cmd_si < RCV_CMD_LEN)
+                        {
+                            rcv_cmd[rcv_cmd_si] = c;
+                            rcv_cmd_si++;
+                        }
+                        else
+                        {
+                            // Command buffer overflow
+                            rcv_cmd_error = 1;
+                        }
                     }
                 }
-                // Reset the received command buffer
-                rcv_cmd_si    = 0;
-                rcv_cmd_error = 0;
-            }
-            else
-            if ((c >= 32) && (c <= 126))
-            {
-                if (!rcv_cmd_error)
+                else
                 {
-                    if (rcv_cmd_si < RCV_CMD_LEN)
-                    {
-                        rcv_cmd[rcv_cmd_si] = c;
-                        rcv_cmd_si++;
-                    }
-                    else
-                    {
-                        // Command buffer overflow
-                        rcv_cmd_error = 1;
-                    }
+                    // Invalid character received
+                    rcv_cmd_error = 1;
                 }
             }
-            else
+            if (snd_rsp_si > 0)
             {
-                // Invalid character received
-                rcv_cmd_error = 1;
+                U32 u;
+                for (u = 0; u < snd_rsp_si; u++) printf("%c",snd_rsp[u]);
+                printf("\n");
+                // Reset the response buffer
+                snd_rsp_si = 0;
             }
         }
-        // Flush any outstanding characters for transmission
-        if (snd_rsp_si > 0)
-        {
-            printf(snd_rsp);
-            // Reset the response buffer
-            snd_rsp_si = 0;
-        }
+
     }
     //END Command Line


Ok. BTW Mr. Kataoka who is maintaing Japanese version of PostgreSQL
ODBC driver have found a bug in 6.3.2 pg_dump and have made patches.
I confirmed that the same bug still exists in the current source
tree. So I made up patches based on Kataoka's. Here are some
explanations.

o fmtId() returns pointer to a static memory in it. In the meantime
there is a line where is fmtId() called twice without saving the
first value returned by fmtId(). So second call to fmtId() will
break the first one.

o findTableByName() looks up a table by its name. if a table name
contanins upper letters or non ascii chars, fmtId() will returns
a name quoted in double quotes, which will not what findTableByName()
wants. The result is SEG fault.  -- Tatsuo Ishii t-ishii@sra.co.jp

--- src/bin/pg_dump/pg_dump.c
+++ src/bin/pg_dump/pg_dump.c
@@ -21,7 +21,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.80 1998/08/25 15:02:04 thomas Exp $
+ *	  $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.81 1998/08/29 18:06:57 momjian Exp $
  *
  * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
  *
@@ -2435,7 +2435,9 @@
 	int			i,
 				j,
 				k;
-	char		q[MAXQUERYLEN];
+	char		q[MAXQUERYLEN],
+				id1[MAXQUERYLEN],
+				id2[MAXQUERYLEN];
 	char	  **parentRels;		/* list of names of parent relations */
 	int			numParents;
 	int			actual_atts;	/* number of attrs in this CREATE statment */
@@ -2506,11 +2508,13 @@
 					}
 					else
 					{
+ 						strcpy(id1, fmtId(tblinfo[i].attnames[j]));
+ 						strcpy(id2, fmtId(tblinfo[i].typnames[j]));
 						sprintf(q, "%s%s%s %s",
 								q,
 								(actual_atts > 0) ? ", " : "",
-								fmtId(tblinfo[i].attnames[j]),
-								fmtId(tblinfo[i].typnames[j]));
+							id1,
+							id2);
 						actual_atts++;
 					}
 					if (tblinfo[i].adef_expr[j] != NULL)
@@ -2572,13 +2576,15 @@
 				indclass;
 	int			nclass;

-	char		q[MAXQUERYLEN];
+	char		q[MAXQUERYLEN],
+				id1[MAXQUERYLEN],
+				id2[MAXQUERYLEN];
 	PGresult   *res;

 	for (i = 0; i < numIndices; i++)
 	{
 		tableInd = findTableByName(tblinfo, numTables,
-								   fmtId(indinfo[i].indrelname));
+					   (indinfo[i].indrelname));

 		if (strcmp(indinfo[i].indproc, "0") == 0)
 			funcname = NULL;
@@ -2659,8 +2665,10 @@
 							attname, indinfo[i].indexrelname);
 					exit_nicely(g_conn);
 				}
+				strcpy(id1, fmtId(attname));
+				strcpy(id2, fmtId(classname[k]));
 				sprintf(attlist + strlen(attlist), "%s%s %s",
-						(k == 0) ? "" : ", ", fmtId(attname), fmtId(classname[k]));
+						(k == 0) ? "" : ", ", id1, id2);
 				free(classname[k]);
 			}
 		}
@@ -2668,10 +2676,12 @@
 		if (!tablename || (!strcmp(indinfo[i].indrelname, tablename)))
 		{

+			strcpy(id1, fmtId(indinfo[i].indexrelname));
+			strcpy(id2, fmtId(indinfo[i].indrelname));
 			sprintf(q, "CREATE %s INDEX %s on %s using %s (",
 			  (strcmp(indinfo[i].indisunique, "t") == 0) ? "UNIQUE" : "",
-					fmtId(indinfo[i].indexrelname),
-					fmtId(indinfo[i].indrelname),
+					id1,
+					id2,
 					indinfo[i].indamname);
 			if (funcname)
 			{


Print cache header's fields in more human-readable format.

--- src/util/idxview.c
+++ src/util/idxview.c
@@ -10,6 +10,7 @@

 #include <stdio.h>
 #include <stdlib.h>
+#include <time.h>

 static struct mail_index_header hdr;
 static ARRAY_DEFINE(extensions, struct mail_index_ext);
@@ -127,6 +128,60 @@
 	}
 }

+static const char *cache_decision2str(enum mail_cache_decision_type type)
+{
+	const char *str;
+
+	switch (type & ~MAIL_CACHE_DECISION_FORCED) {
+	case MAIL_CACHE_DECISION_NO:
+		str = "no";
+		break;
+	case MAIL_CACHE_DECISION_TEMP:
+		str = "temp";
+		break;
+	case MAIL_CACHE_DECISION_YES:
+		str = "yes";
+		break;
+	default:
+		return t_strdup_printf("0x%x", type);
+	}
+
+	if ((type & MAIL_CACHE_DECISION_FORCED) != 0)
+		str = t_strconcat(str, " (forced)", NULL);
+	return str;
+}
+
+#define CACHE_TYPE_IS_FIXED_SIZE(type) \
+	((type) == MAIL_CACHE_FIELD_FIXED_SIZE || \
+	 (type) == MAIL_CACHE_FIELD_BITMASK)
+static const char *cache_type2str(enum mail_cache_field_type type)
+{
+	switch (type) {
+	case MAIL_CACHE_FIELD_FIXED_SIZE:
+		return "fixed";
+	case MAIL_CACHE_FIELD_VARIABLE_SIZE:
+		return "variable";
+	case MAIL_CACHE_FIELD_STRING:
+		return "string";
+	case MAIL_CACHE_FIELD_BITMASK:
+		return "bitmask";
+	case MAIL_CACHE_FIELD_HEADER:
+		return "header";
+	default:
+		return t_strdup_printf("0x%x", type);
+	}
+}
+
+static const char *unixdate2str(time_t time)
+{
+	static char buf[64];
+	struct tm *tm;
+
+	tm = localtime(&time);
+	strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", tm);
+	return buf;
+}
+
 static void dump_cache_hdr(int fd)
 {
         struct mail_cache_header_fields fields;
@@ -208,8 +263,13 @@
 		field.decision = decision[i];
 		array_append(&cache_fields, &field, 1);

-		printf("%u: name=%s size=%u type=%u decision=%u last_used=%u\n",
-		       i, names, size[i], type[i], decision[i], last_used[i]);
+		printf("#%u %s: type=%s ", i, names, cache_type2str(type[i]));
+		if (size[i] != (uint32_t)-1 ||
+		    CACHE_TYPE_IS_FIXED_SIZE(type[i]))
+			printf("size=%u ", size[i]);
+		printf("decision=%s last_used=%s\n",
+		       cache_decision2str(decision[i]),
+		       unixdate2str(last_used[i]));
 		names += strlen(names) + 1;
 	}
 }


virJSONValueToString: bail out early on error

Now that we do not need to cater to YAJL 1, move the check for the
return value of yajl_gen_alloc earlier, so that we can assume it
was successful in later code.

Signed-off-by: Ján Tomko <4cab11cfb98d3c937327354a78eb07dbb6ee2bc6@redhat.com>
Reviewed-by: Daniel P. Berrangé <bb938cf255e055ff3507f2627d214e8e62118fcf@redhat.com>

--- src/util/virjson.c
+++ src/util/virjson.c
@@ -1941,16 +1941,14 @@
     VIR_DEBUG("object=%p", object);

     g = yajl_gen_alloc(NULL);
-    if (g) {
-        yajl_gen_config(g, yajl_gen_beautify, pretty ? 1 : 0);
-        yajl_gen_config(g, yajl_gen_indent_string, pretty ? "  " : " ");
-        yajl_gen_config(g, yajl_gen_validate_utf8, 1);
-    }
     if (!g) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Unable to create JSON formatter"));
         goto cleanup;
     }
+    yajl_gen_config(g, yajl_gen_beautify, pretty ? 1 : 0);
+    yajl_gen_config(g, yajl_gen_indent_string, pretty ? "  " : " ");
+    yajl_gen_config(g, yajl_gen_validate_utf8, 1);

     if (virJSONValueToStringOne(object, g) < 0) {
         virReportOOMError();


more

more

Signed-off-by: Jens Nyberg <7200009990a46d4bb36e24284136c70d739d75fd@gmail.com>

--- src/utils/netcat.c
+++ src/utils/netcat.c
@@ -44,14 +44,14 @@
     struct ethernet_header *eheader = (struct ethernet_header *)data;
     struct ipv4_header *iheader = (struct ipv4_header *)(eheader + 1);
     struct tcp_header *theader = (struct tcp_header *)(iheader + 1);
-    void *payload = (void *)(theader + 1);
+    void *pdata = (void *)(theader + 1);
     unsigned int length = sizeof (struct tcp_header) + count;
     unsigned short checksum;

     ethernet_initheader(eheader, ETHERNET_TYPE_IPV4, sha, tha);
     ipv4_initheader(iheader, local.address, remote.address, IPV4_PROTOCOL_TCP, length);
     tcp_initheader(theader, local.info.tcp.port, remote.info.tcp.port);
-    buffer_copy(payload, buffer, count);
+    buffer_copy(pdata, buffer, count);

     theader->flags[0] = (5 << 4);
     theader->flags[1] = flags;
@@ -75,13 +75,13 @@
     struct ethernet_header *eheader = (struct ethernet_header *)data;
     struct ipv4_header *iheader = (struct ipv4_header *)(eheader + 1);
     struct udp_header *uheader = (struct udp_header *)(iheader + 1);
-    void *payload = (void *)(uheader + 1);
+    void *pdata = (void *)(uheader + 1);
     unsigned int length = sizeof (struct udp_header) + count;

     ethernet_initheader(eheader, ETHERNET_TYPE_IPV4, sha, tha);
     ipv4_initheader(iheader, local.address, remote.address, IPV4_PROTOCOL_UDP, length);
     udp_initheader(uheader, local.info.udp.port, remote.info.udp.port, count);
-    buffer_copy(payload, buffer, count);
+    buffer_copy(pdata, buffer, count);

     /* Create checksum */

@@ -137,17 +137,17 @@

 }

-static unsigned int socket_tcp_receive(struct channel *channel, unsigned int source, struct tcp_header *header, void *payload, unsigned int psize)
-{
-
-    struct ipv4_arpentry *sentry = findarpentry(local.address);
-    struct ipv4_arpentry *tentry = findarpentry(remote.address);
+static unsigned int socket_tcp_receive(struct socket *local, struct socket *remote, struct tcp_header *header, void *pdata, unsigned int psize, struct channel *channel, unsigned int source)
+{
+
+    struct ipv4_arpentry *sentry = findarpentry(local->address);
+    struct ipv4_arpentry *tentry = findarpentry(remote->address);
     struct message_data data;

     if (!sentry || !tentry)
         return 0;

-    switch (local.info.tcp.state)
+    switch (local->info.tcp.state)
     {

     case TCP_STATE_LISTEN:
@@ -157,11 +157,11 @@
             /* remove later */
             channel_place(channel, source, EVENT_DATA, message_putstring(&data, "[SYN : SYN+ACK] LISTEN -> SYNRECEIVED\n", 0), &data);

-            remote.info.tcp.seq = loadint(header->seq) + 1;
-
-            send(&data, create_tcp_message(&data, sentry->haddress, tentry->haddress, TCP_FLAGS1_ACK | TCP_FLAGS1_SYN, local.info.tcp.seq, remote.info.tcp.seq, 0, 0));
-
-            local.info.tcp.state = TCP_STATE_SYNRECEIVED;
+            remote->info.tcp.seq = loadint(header->seq) + 1;
+
+            send(&data, create_tcp_message(&data, sentry->haddress, tentry->haddress, TCP_FLAGS1_ACK | TCP_FLAGS1_SYN, local->info.tcp.seq, remote->info.tcp.seq, 0, 0));
+
+            local->info.tcp.state = TCP_STATE_SYNRECEIVED;

         }

@@ -176,7 +176,7 @@

             /* SEND ACK */

-            local.info.tcp.state = TCP_STATE_ESTABLISHED;
+            local->info.tcp.state = TCP_STATE_ESTABLISHED;

         }

@@ -189,8 +189,8 @@
             /* remove later */
             channel_place(channel, source, EVENT_DATA, message_putstring(&data, "[ACK : ___] SYNRECEIVED -> ESTABLISHED\n", 0), &data);

-            local.info.tcp.seq = loadint(header->ack);
-            local.info.tcp.state = TCP_STATE_ESTABLISHED;
+            local->info.tcp.seq = loadint(header->ack);
+            local->info.tcp.state = TCP_STATE_ESTABLISHED;

         }

@@ -200,10 +200,10 @@
         if ((header->flags[1] & TCP_FLAGS1_PSH) && (header->flags[1] & TCP_FLAGS1_ACK))
         {

-            local.info.tcp.seq = loadint(header->ack);
-            remote.info.tcp.seq = loadint(header->seq) + psize;
-
-            send(&data, create_tcp_message(&data, sentry->haddress, tentry->haddress, TCP_FLAGS1_ACK, local.info.tcp.seq, remote.info.tcp.seq, 0, 0));
+            local->info.tcp.seq = loadint(header->ack);
+            remote->info.tcp.seq = loadint(header->seq) + psize;
+
+            send(&data, create_tcp_message(&data, sentry->haddress, tentry->haddress, TCP_FLAGS1_ACK, local->info.tcp.seq, remote->info.tcp.seq, 0, 0));

             return psize;

@@ -215,27 +215,27 @@
             /* remove later */
             channel_place(channel, source, EVENT_DATA, message_putstring(&data, "[FIN+ACK : ACK] ESTABLISHED -> CLOSEWAIT\n", 0), &data);

-            remote.info.tcp.seq = loadint(header->seq) + 1;
-
-            send(&data, create_tcp_message(&data, sentry->haddress, tentry->haddress, TCP_FLAGS1_ACK, local.info.tcp.seq, remote.info.tcp.seq, 0, 0));
-
-            local.info.tcp.state = TCP_STATE_CLOSEWAIT;
+            remote->info.tcp.seq = loadint(header->seq) + 1;
+
+            send(&data, create_tcp_message(&data, sentry->haddress, tentry->haddress, TCP_FLAGS1_ACK, local->info.tcp.seq, remote->info.tcp.seq, 0, 0));
+
+            local->info.tcp.state = TCP_STATE_CLOSEWAIT;

             /* Wait for application to close down */

             /* remove later */
             channel_place(channel, source, EVENT_DATA, message_putstring(&data, "[___ : FIN] CLOSEWAIT -> LASTACK\n", 0), &data);

-            send(&data, create_tcp_message(&data, sentry->haddress, tentry->haddress, TCP_FLAGS1_FIN, local.info.tcp.seq, remote.info.tcp.seq, 0, 0));
-
-            local.info.tcp.state = TCP_STATE_LASTACK;
+            send(&data, create_tcp_message(&data, sentry->haddress, tentry->haddress, TCP_FLAGS1_FIN, local->info.tcp.seq, remote->info.tcp.seq, 0, 0));
+
+            local->info.tcp.state = TCP_STATE_LASTACK;

         }

         else if (header->flags[1] & TCP_FLAGS1_ACK)
         {

-            local.info.tcp.seq = loadint(header->ack);
+            local->info.tcp.seq = loadint(header->ack);

         }

@@ -248,7 +248,7 @@
             /* remove later */
             channel_place(channel, source, EVENT_DATA, message_putstring(&data, "[ACK : ___] FINWAIT1 -> FINWAIT2\n", 0), &data);

-            local.info.tcp.state = TCP_STATE_FINWAIT2;
+            local->info.tcp.state = TCP_STATE_FINWAIT2;

         }

@@ -260,7 +260,7 @@

             /* Send ACK */

-            local.info.tcp.state = TCP_STATE_CLOSING;
+            local->info.tcp.state = TCP_STATE_CLOSING;

         }

@@ -273,14 +273,14 @@
             /* remove later */
             channel_place(channel, source, EVENT_DATA, message_putstring(&data, "[FIN : ACK] FINWAIT2 -> TIMEWAIT\n", 0), &data);

-            local.info.tcp.state = TCP_STATE_TIMEWAIT;
+            local->info.tcp.state = TCP_STATE_TIMEWAIT;

             /* Sleep some time */

             /* remove later */
             channel_place(channel, source, EVENT_DATA, message_putstring(&data, "[___ : ___] TIMEWAIT -> CLOSED\n", 0), &data);

-            local.info.tcp.state = TCP_STATE_CLOSED;
+            local->info.tcp.state = TCP_STATE_CLOSED;

         }

@@ -296,14 +296,14 @@
             /* remove later */
             channel_place(channel, source, EVENT_DATA, message_putstring(&data, "[ACK : ___] CLOSING -> TIMEWAIT\n", 0), &data);

-            local.info.tcp.state = TCP_STATE_TIMEWAIT;
+            local->info.tcp.state = TCP_STATE_TIMEWAIT;

             /* Sleep some time */

             /* remove later */
             channel_place(channel, source, EVENT_DATA, message_putstring(&data, "[___ : ___] TIMEWAIT -> CLOSED\n", 0), &data);

-            local.info.tcp.state = TCP_STATE_CLOSED;
+            local->info.tcp.state = TCP_STATE_CLOSED;

         }

@@ -316,7 +316,7 @@
             /* remove later */
             channel_place(channel, source, EVENT_DATA, message_putstring(&data, "[ACK : ___] LASTACK -> CLOSED\n", 0), &data);

-            local.info.tcp.state = TCP_STATE_CLOSED;
+            local->info.tcp.state = TCP_STATE_CLOSED;

         }

@@ -334,7 +334,7 @@

 }

-static unsigned int socket_udp_receive(struct channel *channel, unsigned int source, struct udp_header *header, void *payload, unsigned int psize)
+static unsigned int socket_udp_receive(struct socket *local, struct socket *remote, struct udp_header *header, void *pdata, unsigned int psize)
 {

     return psize;
@@ -364,14 +364,14 @@
             if (loadshort(theader->tp) == loadshort(local->info.tcp.port))
             {

-                void *payload = data + elen + ilen + tlen;
-                unsigned int payloadcount = itot - (ilen + tlen);
+                void *pdata = data + elen + ilen + tlen;
+                unsigned int psize = itot - (ilen + tlen);

                 if (!remote->active)
                     socket_inittcp(remote, iheader->sip, theader->sp, loadint(theader->seq));

-                if (socket_tcp_receive(channel, source, theader, payload, payloadcount))
-                    return buffer_write(output, outputcount, payload, payloadcount, 0);
+                if (socket_tcp_receive(local, remote, theader, pdata, psize, channel, source))
+                    return buffer_write(output, outputcount, pdata, psize, 0);

             }

@@ -386,14 +386,14 @@
             if (loadshort(uheader->tp) == loadshort(local->info.udp.port))
             {

-                void *payload = data + elen + ilen + ulen;
-                unsigned int payloadcount = itot - (ilen + ulen);
+                void *pdata = data + elen + ilen + ulen;
+                unsigned int psize = itot - (ilen + ulen);

                 if (!remote->active)
                     socket_initudp(remote, iheader->sip, uheader->sp);

-                if (socket_udp_receive(channel, source, uheader, payload, payloadcount))
-                    return buffer_write(output, outputcount, payload, payloadcount, 0);
+                if (socket_udp_receive(local, remote, uheader, pdata, psize))
+                    return buffer_write(output, outputcount, pdata, psize, 0);

             }

@@ -405,23 +405,23 @@

 }

-static unsigned int socket_tcp_send(struct channel *channel, unsigned int source, unsigned int length, void *buffer)
-{
-
-    struct ipv4_arpentry *sentry = findarpentry(local.address);
-    struct ipv4_arpentry *tentry = findarpentry(remote.address);
+static unsigned int socket_tcp_send(struct socket *local, struct socket *remote, unsigned int psize, void *pdata)
+{
+
+    struct ipv4_arpentry *sentry = findarpentry(local->address);
+    struct ipv4_arpentry *tentry = findarpentry(remote->address);
     struct message_data data;

     if (!sentry || !tentry)
         return 0;

-    switch (local.info.tcp.state)
+    switch (local->info.tcp.state)
     {

     case TCP_STATE_ESTABLISHED:
-        send(&data, create_tcp_message(&data, sentry->haddress, tentry->haddress, TCP_FLAGS1_PSH | TCP_FLAGS1_ACK, local.info.tcp.seq, remote.info.tcp.seq, length, buffer));
-
-        return length;
+        send(&data, create_tcp_message(&data, sentry->haddress, tentry->haddress, TCP_FLAGS1_PSH | TCP_FLAGS1_ACK, local->info.tcp.seq, remote->info.tcp.seq, psize, pdata));
+
+        return psize;

     }

@@ -429,36 +429,36 @@

 }

-static unsigned int socket_udp_send(struct channel *channel, unsigned int source, unsigned int length, void *buffer)
-{
-
-    struct ipv4_arpentry *sentry = findarpentry(local.address);
-    struct ipv4_arpentry *tentry = findarpentry(remote.address);
+static unsigned int socket_udp_send(struct socket *local, struct socket *remote, unsigned int psize, void *pdata)
+{
+
+    struct ipv4_arpentry *sentry = findarpentry(local->address);
+    struct ipv4_arpentry *tentry = findarpentry(remote->address);
     struct message_data data;

     if (!sentry || !tentry)
         return 0;

-    send(&data, create_udp_message(&data, sentry->haddress, tentry->haddress, length, buffer));
-
-    return length;
-
-}
-
-static unsigned int socket_send(struct channel *channel, unsigned int source, struct socket *socket, unsigned int count, void *buffer)
-{
-
-    if (!socket->active)
+    send(&data, create_udp_message(&data, sentry->haddress, tentry->haddress, psize, pdata));
+
+    return psize;
+
+}
+
+static unsigned int socket_send(struct socket *local, struct socket *remote, unsigned int psize, void *pdata)
+{
+
+    if (!remote->active)
         return 0;

-    switch (socket->protocol)
+    switch (local->protocol)
     {

     case IPV4_PROTOCOL_TCP:
-        return socket_tcp_send(channel, source, count, buffer);
+        return socket_tcp_send(local, remote, psize, pdata);

     case IPV4_PROTOCOL_UDP:
-        return socket_udp_send(channel, source, count, buffer);
+        return socket_udp_send(local, remote, psize, pdata);

     }

@@ -499,10 +499,9 @@
 {

     struct event_consoledata *consoledata = mdata;
-    char s = consoledata->data;
-    unsigned int count = socket_send(channel, source, &remote, 1, &s);
-
-    channel_place(channel, source, EVENT_DATA, count, &s);
+    unsigned int count = socket_send(&local, &remote, 1, &consoledata->data);
+
+    channel_place(channel, source, EVENT_DATA, count, &consoledata->data);

 }


fix the comment

fix the comment

--- src/butil/resource_pool.h
+++ src/butil/resource_pool.h
@@ -75,7 +75,7 @@

 // ResourcePool calls this function on newly constructed objects. If this
 // function returns false, the object is destructed immediately and
-// get_object() shall return NULL. This is useful when the constructor
+// get_resource() shall return NULL. This is useful when the constructor
 // failed internally(namely ENOMEM).
 template <typename T> struct ResourcePoolValidator {
     static bool validate(const T*) { return true; }


Improve some comments for corner cases

Improve some comments for corner cases

--- src/bytestream-multiple.c
+++ src/bytestream-multiple.c
@@ -468,7 +468,8 @@
   if (priv->active_bytestream)
     gabble_bytestream_iface_close (priv->active_bytestream, error);
   else
-    /* FIXME can it happen? maybe when there are no methods */
+    /* It can happen if the bytestream is still empty, i.e. not stream
+     * methods have been added yet */
     g_object_set (self, "state", GABBLE_BYTESTREAM_STATE_CLOSED, NULL);
 }

@@ -493,7 +494,6 @@

   if (priv->active_bytestream == NULL)
     {
-      /* FIXME no stream methods? */
       DEBUG ("no bytestreams to initiate");
       return FALSE;
     }


Added get_cipher.

Added get_cipher.

FossilOrigin-Name: 905d3a80067cbcf618bbf3f46617ff012bdf5be955ca64446c204bf842fa352b

--- src/capwap/dtls_openssl.h
+++ src/capwap/dtls_openssl.h
@@ -27,6 +27,7 @@
 extern int dtls_openssl_read(struct conn * conn, uint8_t *buffer, int len);
 extern int dtls_openssl_write(struct conn * conn, const uint8_t *buffer, int len);
 extern int dtls_openssl_connect(struct conn * conn);
+extern const char * dtls_openssl_get_cipher(struct conn * conn);

 extern int dtls_openssl_log_error(SSL * ssl, int rc, const char *txt);

@@ -42,6 +43,7 @@
 extern int dtls_openssl_bio_new(BIO *bi);
 extern int dtls_openssl_bio_free(BIO *bio);

+extern const char * dtls_openssl_get_currnet_cipher();

 extern BIO *bbb;


Fix void return statement

Fix void return statement

--- src/cc1/ops/stmt_return.c
+++ src/cc1/ops/stmt_return.c
@@ -67,8 +67,9 @@
 void gen_stmt_return(stmt *s, out_ctx *octx)
 {
 	out_ctrl_end_ret(
-			octx, s->expr ? gen_expr(s->expr, octx) : NULL, s->expr->tree_type);
-
+			octx,
+			s->expr ? gen_expr(s->expr, octx) : NULL,
+			s->expr ? s->expr->tree_type : NULL);
 }

 void style_stmt_return(stmt *s, out_ctx *octx)


vz: build fix for passing qemuCaps to virDomainDefParseNode

Missing piece for [1]

[1]: 577a1f98: qemu: Pass correct qemuCaps to virDomainDefParseNode

Signed-off-by: Nikolay Shirokovskiy <7fa0e2698a05be944b362bdf5d7736c0162e16c9@virtuozzo.com>

--- src/vz/vz_driver.c
+++ src/vz/vz_driver.c
@@ -2609,7 +2609,7 @@
         parse_flags |= VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE;

     if (!(def = virDomainSnapshotDefParseString(xmlDesc, driver->caps,
-                                                driver->xmlopt, NULL,
+                                                driver->xmlopt, NULL, NULL,
                                                 parse_flags)))
         goto cleanup;


typo

typo

git-svn-id: f2d781e409b7e36a714fc884bb9b2fc5091ddd28@2681 0ce88b0d-b2fd-0310-8134-9614164e65ea

--- src/winscard_msg.c
+++ src/winscard_msg.c
@@ -284,7 +284,7 @@
 	size_t remaining = buffer_size;

 	/*
-	 * repeate until we get the whole message
+	 * repeat until we get the whole message
 	 */
 	while (remaining > 0)
 	{


SCardGetStatusChange(): Context index was being used instead of Reader
index, it worked only when there was just one context.

Thanks to Najam Siddiqui for the bug report

git-svn-id: f2d781e409b7e36a714fc884bb9b2fc5091ddd28@1681 0ce88b0d-b2fd-0310-8134-9614164e65ea

--- src/winscard_scf.c
+++ src/winscard_scf.c
@@ -684,7 +684,7 @@
 	LPSCARD_READERSTATE_A rgReaderStates, DWORD cReaders)
 {

-	LONG rv, retIndice;
+	LONG rv, retIndice, readerIndice;
 	PSCARD_READERSTATE_A currReader;
 	PREADER_STATE rContext;
 	LPTSTR lpcReaderName;
@@ -706,6 +706,7 @@
 	i = 0;
 	currReader = 0;
 	retIndice = 0;
+	readerIndice = 0;
 	dwBreakFlag = 0;

 	if (rgReaderStates == 0 && cReaders > 0)
@@ -781,9 +782,9 @@

 			lpcReaderName = (char *) currReader->szReader;

-			retIndice = SCardGetReaderIndice(lpcReaderName);
+			readerIndice = SCardGetReaderIndice(lpcReaderName);
 			/* The requested reader name is not recognized */
-			if (0 > retIndice)
+			if (0 > readerIndice)
 			{
 				if (currReader->dwCurrentState & SCARD_STATE_UNKNOWN)
 				{
@@ -811,7 +812,7 @@
 	/*****************************************************************/
 				SCardEventLock();
 				/* Now we check all the Reader States */
-				dwState = psReaderMap[retIndice].dwCurrentState;
+				dwState = psReaderMap[readerIndice].dwCurrentState;

 	/*********** Check if the reader is in the correct state ********/
 				if (dwState & SCARD_STATE_UNKNOWN)
@@ -844,8 +845,8 @@

 				if (dwState & SCARD_STATE_PRESENT)
 				{
-					currReader->cbAtr = psReaderMap[retIndice].dwAtrLength;
-					memcpy(currReader->rgbAtr, psReaderMap[retIndice].bAtr,
+					currReader->cbAtr = psReaderMap[readerIndice].dwAtrLength;
+					memcpy(currReader->rgbAtr, psReaderMap[readerIndice].bAtr,
 						currReader->cbAtr);
 				}
 				else
@@ -920,7 +921,7 @@
 					}
 				}

-				if (-1 == psReaderMap[retIndice].SharedRefCount)
+				if (-1 == psReaderMap[readerIndice].SharedRefCount)
 				{
 					currReader->dwEventState |= SCARD_STATE_EXCLUSIVE;
 					currReader->dwEventState &= ~SCARD_STATE_INUSE;
@@ -930,7 +931,7 @@
 						dwBreakFlag = 1;
 					}
 				}
-				else if (psReaderMap[retIndice].SharedRefCount >= 1)
+				else if (psReaderMap[readerIndice].SharedRefCount >= 1)
 				{
 					/* A card must be inserted for it to be INUSE */
 					if (dwState & SCARD_STATE_PRESENT)


CreateContextThread(): log an error message in case of failuer since the
pcscd daemon will die shortly after that

git-svn-id: f2d781e409b7e36a714fc884bb9b2fc5091ddd28@2128 0ce88b0d-b2fd-0310-8134-9614164e65ea

--- src/winscard_svc.c
+++ src/winscard_svc.c
@@ -91,6 +91,8 @@
 	{
 		SYS_CloseFile(psContext[i].dwClientID);
 		psContext[i].dwClientID = 0;
+		Log2(PCSC_LOG_CRITICAL, "No more context available (max: %d)",
+			PCSCLITE_MAX_APPLICATIONS_CONTEXTS);
 		return SCARD_F_INTERNAL_ERROR;
 	}

@@ -100,6 +102,7 @@
 	{
 		SYS_CloseFile(psContext[i].dwClientID);
 		psContext[i].dwClientID = 0;
+		Log1(PCSC_LOG_CRITICAL, "SYS_ThreadCreate failed");
 		return SCARD_E_NO_MEMORY;
 	}


src/xenxs: Refactor code formating Vfb config

introduce function
   xenFormatXMVfb(virConfPtr conf,.........);
which formats Vfb config instead

Signed-off-by: Kiarie Kahurani <c9add1accb912784264f310f617467d4c47149ea@gmail.com>

--- src/xenxs/xen_xm.c
+++ src/xenxs/xen_xm.c
@@ -2128,6 +2128,126 @@
 }

+static int
+xenFormatXMVfb(virConfPtr conf,
+               virDomainDefPtr def,
+               int xendConfigVersion)
+{
+    int hvm = STREQ(def->os.type, "hvm") ? 1 : 0;
+
+    if (def->ngraphics == 1) {
+        if (hvm || (xendConfigVersion < XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) {
+            if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
+                if (xenXMConfigSetInt(conf, "sdl", 1) < 0)
+                    return -1;
+
+                if (xenXMConfigSetInt(conf, "vnc", 0) < 0)
+                    return -1;
+
+                if (def->graphics[0]->data.sdl.display &&
+                    xenXMConfigSetString(conf, "display",
+                                     def->graphics[0]->data.sdl.display) < 0)
+                    return -1;
+
+                if (def->graphics[0]->data.sdl.xauth &&
+                    xenXMConfigSetString(conf, "xauthority",
+                                         def->graphics[0]->data.sdl.xauth) < 0)
+                    return -1;
+            } else {
+                const char *listenAddr;
+
+                if (xenXMConfigSetInt(conf, "sdl", 0) < 0)
+                    return -1;
+
+                if (xenXMConfigSetInt(conf, "vnc", 1) < 0)
+                    return -1;
+
+                if (xenXMConfigSetInt(conf, "vncunused",
+                              def->graphics[0]->data.vnc.autoport ? 1 : 0) < 0)
+                    return -1;
+
+                if (!def->graphics[0]->data.vnc.autoport &&
+                    xenXMConfigSetInt(conf, "vncdisplay",
+                                  def->graphics[0]->data.vnc.port - 5900) < 0)
+                    return -1;
+
+                listenAddr = virDomainGraphicsListenGetAddress(def->graphics[0], 0);
+                if (listenAddr &&
+                    xenXMConfigSetString(conf, "vnclisten", listenAddr) < 0)
+                    return -1;
+
+                if (def->graphics[0]->data.vnc.auth.passwd &&
+                    xenXMConfigSetString(conf, "vncpasswd",
+                                        def->graphics[0]->data.vnc.auth.passwd) < 0)
+                    return -1;
+
+                if (def->graphics[0]->data.vnc.keymap &&
+                    xenXMConfigSetString(conf, "keymap",
+                                        def->graphics[0]->data.vnc.keymap) < 0)
+                    return -1;
+            }
+        } else {
+            virConfValuePtr vfb, disp;
+            char *vfbstr = NULL;
+            virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+            if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
+                virBufferAddLit(&buf, "type=sdl");
+                if (def->graphics[0]->data.sdl.display)
+                    virBufferAsprintf(&buf, ",display=%s",
+                                      def->graphics[0]->data.sdl.display);
+                if (def->graphics[0]->data.sdl.xauth)
+                    virBufferAsprintf(&buf, ",xauthority=%s",
+                                      def->graphics[0]->data.sdl.xauth);
+            } else {
+                const char *listenAddr
+                    = virDomainGraphicsListenGetAddress(def->graphics[0], 0);
+
+                virBufferAddLit(&buf, "type=vnc");
+                virBufferAsprintf(&buf, ",vncunused=%d",
+                                  def->graphics[0]->data.vnc.autoport ? 1 : 0);
+                if (!def->graphics[0]->data.vnc.autoport)
+                    virBufferAsprintf(&buf, ",vncdisplay=%d",
+                                      def->graphics[0]->data.vnc.port - 5900);
+                if (listenAddr)
+                    virBufferAsprintf(&buf, ",vnclisten=%s", listenAddr);
+                if (def->graphics[0]->data.vnc.auth.passwd)
+                    virBufferAsprintf(&buf, ",vncpasswd=%s",
+                                      def->graphics[0]->data.vnc.auth.passwd);
+                if (def->graphics[0]->data.vnc.keymap)
+                    virBufferAsprintf(&buf, ",keymap=%s",
+                                      def->graphics[0]->data.vnc.keymap);
+            }
+            if (virBufferCheckError(&buf) < 0)
+                return -1;
+
+            vfbstr = virBufferContentAndReset(&buf);
+
+            if (VIR_ALLOC(vfb) < 0) {
+                VIR_FREE(vfbstr);
+                return -1;
+            }
+
+            if (VIR_ALLOC(disp) < 0) {
+                VIR_FREE(vfb);
+                VIR_FREE(vfbstr);
+                return -1;
+            }
+
+            vfb->type = VIR_CONF_LIST;
+            vfb->list = disp;
+            disp->type = VIR_CONF_STRING;
+            disp->str = vfbstr;
+
+            if (virConfSetValue(conf, "vfb", vfb) < 0)
+                return -1;
+        }
+    }
+
+    return 0;
+}
+
+
 /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
    either 32, or 64 on a platform where long is big enough.  */
 verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT);
@@ -2155,7 +2275,7 @@
         goto cleanup;

     if (xenFormatXMOS(conf, def) < 0)
-        goto cleanup;
+         goto cleanup;

     if (xenFormatXMCPUFeatures(conf, def, xendConfigVersion) < 0)
         goto cleanup;
@@ -2196,104 +2316,8 @@
         }
     }

-    if (def->ngraphics == 1) {
-        if (hvm || (xendConfigVersion < XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) {
-            if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
-                if (xenXMConfigSetInt(conf, "sdl", 1) < 0)
-                    goto cleanup;
-                if (xenXMConfigSetInt(conf, "vnc", 0) < 0)
-                    goto cleanup;
-                if (def->graphics[0]->data.sdl.display &&
-                    xenXMConfigSetString(conf, "display",
-                                     def->graphics[0]->data.sdl.display) < 0)
-                    goto cleanup;
-                if (def->graphics[0]->data.sdl.xauth &&
-                    xenXMConfigSetString(conf, "xauthority",
-                                         def->graphics[0]->data.sdl.xauth) < 0)
-                    goto cleanup;
-            } else {
-                const char *listenAddr;
-
-                if (xenXMConfigSetInt(conf, "sdl", 0) < 0)
-                    goto cleanup;
-                if (xenXMConfigSetInt(conf, "vnc", 1) < 0)
-                    goto cleanup;
-                if (xenXMConfigSetInt(conf, "vncunused",
-                              def->graphics[0]->data.vnc.autoport ? 1 : 0) < 0)
-                    goto cleanup;
-                if (!def->graphics[0]->data.vnc.autoport &&
-                    xenXMConfigSetInt(conf, "vncdisplay",
-                                  def->graphics[0]->data.vnc.port - 5900) < 0)
-                    goto cleanup;
-                listenAddr = virDomainGraphicsListenGetAddress(def->graphics[0], 0);
-                if (listenAddr &&
-                    xenXMConfigSetString(conf, "vnclisten", listenAddr) < 0)
-                    goto cleanup;
-                if (def->graphics[0]->data.vnc.auth.passwd &&
-                    xenXMConfigSetString(conf, "vncpasswd",
-                                        def->graphics[0]->data.vnc.auth.passwd) < 0)
-                    goto cleanup;
-                if (def->graphics[0]->data.vnc.keymap &&
-                    xenXMConfigSetString(conf, "keymap",
-                                        def->graphics[0]->data.vnc.keymap) < 0)
-                    goto cleanup;
-            }
-        } else {
-            virConfValuePtr vfb, disp;
-            char *vfbstr = NULL;
-            virBuffer buf = VIR_BUFFER_INITIALIZER;
-            if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
-                virBufferAddLit(&buf, "type=sdl");
-                if (def->graphics[0]->data.sdl.display)
-                    virBufferAsprintf(&buf, ",display=%s",
-                                      def->graphics[0]->data.sdl.display);
-                if (def->graphics[0]->data.sdl.xauth)
-                    virBufferAsprintf(&buf, ",xauthority=%s",
-                                      def->graphics[0]->data.sdl.xauth);
-            } else {
-                const char *listenAddr
-                    = virDomainGraphicsListenGetAddress(def->graphics[0], 0);
-
-                virBufferAddLit(&buf, "type=vnc");
-                virBufferAsprintf(&buf, ",vncunused=%d",
-                                  def->graphics[0]->data.vnc.autoport ? 1 : 0);
-                if (!def->graphics[0]->data.vnc.autoport)
-                    virBufferAsprintf(&buf, ",vncdisplay=%d",
-                                      def->graphics[0]->data.vnc.port - 5900);
-                if (listenAddr)
-                    virBufferAsprintf(&buf, ",vnclisten=%s", listenAddr);
-                if (def->graphics[0]->data.vnc.auth.passwd)
-                    virBufferAsprintf(&buf, ",vncpasswd=%s",
-                                      def->graphics[0]->data.vnc.auth.passwd);
-                if (def->graphics[0]->data.vnc.keymap)
-                    virBufferAsprintf(&buf, ",keymap=%s",
-                                      def->graphics[0]->data.vnc.keymap);
-            }
-            if (virBufferCheckError(&buf) < 0)
-                goto cleanup;
-
-            vfbstr = virBufferContentAndReset(&buf);
-
-            if (VIR_ALLOC(vfb) < 0) {
-                VIR_FREE(vfbstr);
-                goto cleanup;
-            }
-
-            if (VIR_ALLOC(disp) < 0) {
-                VIR_FREE(vfb);
-                VIR_FREE(vfbstr);
-                goto cleanup;
-            }
-
-            vfb->type = VIR_CONF_LIST;
-            vfb->list = disp;
-            disp->type = VIR_CONF_STRING;
-            disp->str = vfbstr;
-
-            if (virConfSetValue(conf, "vfb", vfb) < 0)
-                goto cleanup;
-        }
-    }
+    if (xenFormatXMVfb(conf, def, xendConfigVersion) < 0)
+        goto cleanup;

     if (xenFormatXMDisks(conf, def, xendConfigVersion) < 0)
         goto cleanup;


[Feature] Add decompression support in rspamd client

--- src/client/rspamdclient.c
+++ src/client/rspamdclient.c
@@ -104,6 +104,7 @@
 	struct rspamd_client_connection *c;
 	struct ucl_parser *parser;
 	GError *err;
+	const rspamd_ftok_t *tok;

 	c = req->conn;

@@ -128,15 +129,98 @@
 			return 0;
 		}

-		parser = ucl_parser_new (0);
-		if (!ucl_parser_add_chunk (parser, msg->body_buf.begin, msg->body_buf.len)) {
-			err = g_error_new (RCLIENT_ERROR, msg->code, "Cannot parse UCL: %s",
-					ucl_parser_get_error (parser));
-			ucl_parser_free (parser);
-			req->cb (c, msg, c->server_name->str, NULL, req->input, req->ud, err);
-			g_error_free (err);
-
-			return 0;
+		tok = rspamd_http_message_find_header (msg, "compression");
+
+		if (tok) {
+			/* Need to uncompress */
+			rspamd_ftok_t t;
+
+			t.begin = "zstd";
+			t.len = 4;
+
+			if (rspamd_ftok_casecmp (tok, &t) == 0) {
+				ZSTD_DStream *zstream;
+				ZSTD_inBuffer zin;
+				ZSTD_outBuffer zout;
+				guchar *out;
+				gsize outlen, r;
+
+				zstream = ZSTD_createDStream ();
+				ZSTD_initDStream (zstream);
+
+				zin.pos = 0;
+				zin.src = msg->body_buf.begin;
+				zin.size = msg->body_buf.len;
+
+				if ((outlen = ZSTD_getDecompressedSize (zin.src, zin.size)) == 0) {
+					outlen = ZSTD_DStreamOutSize ();
+				}
+
+				out = g_malloc (outlen);
+				zout.dst = out;
+				zout.pos = 0;
+				zout.size = outlen;
+
+				while (zin.pos < zin.size) {
+					r = ZSTD_decompressStream (zstream, &zout, &zin);
+
+					if (ZSTD_isError (r)) {
+						err = g_error_new (RCLIENT_ERROR, 500,
+								"Decompression error: %s",
+								ZSTD_getErrorName (r));
+						req->cb (c, msg, c->server_name->str, NULL,
+								req->input, req->ud, err);
+						g_error_free (err);
+						ZSTD_freeDStream (zstream);
+						g_free (out);
+
+						return 0;
+					}
+
+					if (zout.pos == zout.size) {
+						/* We need to extend output buffer */
+						zout.size = zout.size * 1.5 + 1.0;
+						zout.dst = g_realloc (zout.dst, zout.size);
+					}
+				}
+
+				ZSTD_freeDStream (zstream);
+
+				parser = ucl_parser_new (0);
+				if (!ucl_parser_add_chunk (parser, zout.dst, zout.pos)) {
+					err = g_error_new (RCLIENT_ERROR, msg->code, "Cannot parse UCL: %s",
+							ucl_parser_get_error (parser));
+					ucl_parser_free (parser);
+					req->cb (c, msg, c->server_name->str, NULL, req->input, req->ud, err);
+					g_error_free (err);
+					g_free (out);
+
+					return 0;
+				}
+
+				g_free (out);
+			}
+			else {
+				err = g_error_new (RCLIENT_ERROR, 500,
+						"Invalid compression method");
+				req->cb (c, msg, c->server_name->str, NULL,
+						req->input, req->ud, err);
+				g_error_free (err);
+
+				return 0;
+			}
+		}
+		else {
+			parser = ucl_parser_new (0);
+			if (!ucl_parser_add_chunk (parser, msg->body_buf.begin, msg->body_buf.len)) {
+				err = g_error_new (RCLIENT_ERROR, msg->code, "Cannot parse UCL: %s",
+						ucl_parser_get_error (parser));
+				ucl_parser_free (parser);
+				req->cb (c, msg, c->server_name->str, NULL, req->input, req->ud, err);
+				g_error_free (err);
+
+				return 0;
+			}
 		}

 		req->cb (c, msg, c->server_name->str, ucl_parser_get_object (


GUAC-675: Source coordinates must be updated along with rect.

--- src/common/guac_surface.c
+++ src/common/guac_surface.c
@@ -400,7 +400,7 @@
  *               should be ignored), zero otherwise.
  */
 static void __guac_common_surface_put(unsigned char* src_buffer, int src_stride,
-                                      int sx, int sy,
+                                      int* sx, int* sy,
                                       guac_common_surface* dst, guac_common_rect* rect,
                                       int opaque) {

@@ -414,7 +414,10 @@
     int max_x = 0;
     int max_y = 0;

-    src_buffer += src_stride*sy + 4*sx;
+    int orig_x = rect->x;
+    int orig_y = rect->y;
+
+    src_buffer += src_stride * (*sy) + 4 * (*sx);
     dst_buffer += (dst_stride * rect->y) + (4 * rect->x);

     /* For each row */
@@ -461,6 +464,10 @@
         rect->width = 0;
         rect->height = 0;
     }
+
+    /* Update source X/Y */
+    *sx += rect->x - orig_x;
+    *sy += rect->y - orig_y;

 }

@@ -536,7 +543,7 @@
  * @param dx The destination X coordinate.
  * @param dy The destination Y coordinate.
  */
-static void __guac_common_surface_transfer(guac_common_surface* src, int sx, int sy,
+static void __guac_common_surface_transfer(guac_common_surface* src, int* sx, int* sy,
                                            guac_transfer_function op,
                                            guac_common_surface* dst, guac_common_rect* rect) {

@@ -552,9 +559,12 @@
     int max_x = 0;
     int max_y = 0;

+    int orig_x = rect->x;
+    int orig_y = rect->y;
+
     /* Copy forwards only if destination is in a different surface or is before source */
-    if (src != dst || rect->y < sy || (rect->y == sy && rect->x < sx)) {
-        src_buffer += src->stride*sy + 4*sx;
+    if (src != dst || rect->y < *sy || (rect->y == *sy && rect->x < *sx)) {
+        src_buffer += src->stride * (*sy) + 4 * (*sx);
         dst_buffer += (dst->stride * rect->y) + (4 * rect->x);
         src_stride = src->stride;
         dst_stride = dst->stride;
@@ -563,7 +573,7 @@

     /* Otherwise, copy backwards */
     else {
-        src_buffer += src->stride * (sy + rect->height - 1) + 4 * (sx + rect->width - 1);
+        src_buffer += src->stride * (*sy + rect->height - 1) + 4 * (*sx + rect->width - 1);
         dst_buffer += dst->stride * (rect->y + rect->height - 1) + 4 * (rect->x + rect->width - 1);
         src_stride = -src->stride;
         dst_stride = -dst->stride;
@@ -596,12 +606,18 @@

     }

-    /* Translate coordinate space of min_* and max_* if moving backwards */
+    /* Translate X coordinate space of moving backwards */
     if (step < 0) {
-        min_x = rect->width - 1 - min_x;
-        max_x = rect->width - 1 - max_x;
-        min_y = rect->height - 1 - min_y;
-        max_y = rect->height - 1 - max_y;
+        int old_max_x = max_x;
+        max_x = rect->width - 1 - min_x;
+        min_x = rect->width - 1 - old_max_x;
+    }
+
+    /* Translate Y coordinate space of moving backwards */
+    if (dst_stride < 0) {
+        int old_max_y = max_y;
+        max_y = rect->height - 1 - min_y;
+        min_y = rect->height - 1 - old_max_y;
     }

     /* Restrict destination rect to only updated pixels */
@@ -615,6 +631,10 @@
         rect->width = 0;
         rect->height = 0;
     }
+
+    /* Update source X/Y */
+    *sx += rect->x - orig_x;
+    *sy += rect->y - orig_y;

 }

@@ -732,7 +752,7 @@
         return;

     /* Update backing surface */
-    __guac_common_surface_put(buffer, stride, sx, sy, surface, &rect, format != CAIRO_FORMAT_ARGB32);
+    __guac_common_surface_put(buffer, stride, &sx, &sy, surface, &rect, format != CAIRO_FORMAT_ARGB32);
     if (rect.width <= 0 || rect.height <= 0)
         return;

@@ -792,7 +812,7 @@
         return;

     /* Update backing surface */
-    __guac_common_surface_transfer(src, sx, sy, GUAC_TRANSFER_BINARY_SRC, dst, &rect);
+    __guac_common_surface_transfer(src, &sx, &sy, GUAC_TRANSFER_BINARY_SRC, dst, &rect);
     if (rect.width <= 0 || rect.height <= 0)
         return;

@@ -827,7 +847,7 @@
         return;

     /* Update backing surface */
-    __guac_common_surface_transfer(src, sx, sy, op, dst, &rect);
+    __guac_common_surface_transfer(src, &sx, &sy, op, dst, &rect);
     if (rect.width <= 0 || rect.height <= 0)
         return;


Remove duplicated comments.

Remove duplicated comments.

--- src/containers/qtreetbl.c
+++ src/containers/qtreetbl.c
@@ -631,11 +631,6 @@
  * no keys in the table. It'll return empty qtreetbl_obj_t object
  * with errno ENOENT.
  *
- * When there's no matching key it look for closest smaller key
- * in the neighbors. The only exception when it returns bigger key
- * than given search key is that when there's no smaller keys available
- * in the table. In such case, it'll return the nearest bigger key.
- *
  * @param tbl       qtreetbl_t container pointer.
  * @param name      key name
  * @param namesize  key size


Remove unused

Remove unused

--- src/core/types/fio_dict.c
+++ src/core/types/fio_dict.c
@@ -221,7 +221,7 @@

   if (!dict || !pattern || !action)
     return;
-  fio_dict_s *child, *head = dict->parent, *to_call = NULL;
+  fio_dict_s *child, *head = dict->parent;
   uint8_t *pos = pattern;

   while (len && dict) {


SF patch #729395: Dictionary tuning

SF patch #729395: Dictionary tuning

* Increase dictionary growth rate resulting in more sparse dictionaries,
  fewer lookup collisions, increased memory use, and better cache
  performance.  For dicts with over 50k entries, keep the current
  growth rate in case an application is suffering from tight memory
  constraints.

* Set the most common case (no resize) to fall-through the test.

--- Objects/dictobject.c
+++ Objects/dictobject.c
@@ -531,17 +531,23 @@
 	Py_INCREF(value);
 	Py_INCREF(key);
 	insertdict(mp, key, hash, value);
-	/* If we added a key, we can safely resize.  Otherwise skip this!
-	 * If fill >= 2/3 size, adjust size.  Normally, this doubles the
-	 * size, but it's also possible for the dict to shrink (if ma_fill is
-	 * much larger than ma_used, meaning a lot of dict keys have been
-	 * deleted).
+	/* If we added a key, we can safely resize.  Otherwise just return!
+	 * If fill >= 2/3 size, adjust size.  Normally, this doubles or
+	 * quaduples the size, but it's also possible for the dict to shrink
+	 * (if ma_fill is much larger than ma_used, meaning a lot of dict
+	 * keys have been * deleted).
+	 *
+	 * Quadrupling the size improves average dictionary sparseness
+	 * (reducing collisions) at the cost of some memory and iteration
+	 * speed (which loops over every possible entry).  It also halves
+	 * the number of expensive resize operations in a growing dictionary.
+	 *
+	 * Very large dictionaries (over 50K items) use doubling instead.
+	 * This may help applications with severe memory constraints.
 	 */
-	if (mp->ma_used > n_used && mp->ma_fill*3 >= (mp->ma_mask+1)*2) {
-		if (dictresize(mp, mp->ma_used*2) != 0)
-			return -1;
-	}
-	return 0;
+	if (!(mp->ma_used > n_used && mp->ma_fill*3 >= (mp->ma_mask+1)*2))
+		return 0;
+	return dictresize(mp, mp->ma_used*(mp->ma_used>50000 ? 2 : 4));
 }

 int


fileobject.c: fix nasty bug; Makefile; turn on STROP and change lint flags.

--- Objects/fileobject.c
+++ Objects/fileobject.c
@@ -440,7 +440,7 @@
 					resizestring(&result, len-1);
 				else {
 					object *v;
-					v == newsizedstringobject(s, len-1);
+					v = newsizedstringobject(s, len-1);
 					DECREF(result);
 					result = v;
 				}


Patch #650834: Document 'U' in file mode, remove stale variables.

--- Objects/fileobject.c
+++ Objects/fileobject.c
@@ -1614,7 +1614,7 @@
 	{"softspace",	T_INT,		OFF(f_softspace), 0,
 	 "flag indicating that a space needs to be printed; used by print"},
 	{"mode",	T_OBJECT,	OFF(f_mode),	RO,
-	 "file mode ('r', 'w', 'a', possibly with 'b' or '+' added)"},
+	 "file mode ('r', 'U', 'w', 'a', possibly with 'b' or '+' added)"},
 	{"name",	T_OBJECT,	OFF(f_name),	RO,
 	 "file name"},
 	/* getattr(f, "closed") is implemented without this table */
@@ -1767,12 +1767,8 @@
 {
 	PyStringObject* l;

-	int i;
-
 	if (f->f_fp == NULL)
 		return err_closed();
-
-	i = f->f_softspace;

 	l = readahead_get_line_skip(f, 0, READAHEAD_BUFSIZE);
 	if (l == NULL || PyString_GET_SIZE(l) == 0) {


Added new quicksort implementation, tailored to sorting arrays of
object pointers.  Should be a bit faster than the C library's qsort(),
and doesn't have the prohibition on recursion that Solaris qsort() has
in the threaded version of their C library.

Thanks to discussions with Tim Peters.

--- Objects/listobject.c
+++ Objects/listobject.c
@@ -550,6 +550,231 @@
 	return ins(self, (int) self->ob_size, v);
 }

+#define NEWSORT
+
+#ifdef NEWSORT
+
+/* New quicksort implementation for arrays of object pointers.
+   Thanks to discussions with Tim Peters. */
+
+/* CMPERROR is returned by our comparison function when an error
+   occurred.  This is the largest negative integer (0x80000000 on a
+   32-bit system). */
+#define CMPERROR (1 << (8*sizeof(int) - 1))
+
+/* Comparison function.  Takes care of calling a user-supplied
+   comparison function (any callable Python object).  Calls the
+   standard comparison function, cmpobject(), if the user-supplied
+   function is NULL. */
+
+static int
+docompare(x, y, compare)
+	object *x;
+	object *y;
+	object *compare;
+{
+	object *args, *res;
+	int i;
+
+	if (compare == NULL)
+		return cmpobject(x, y);
+
+	args = mkvalue("(OO)", x, y);
+	if (args == NULL)
+		return CMPERROR;
+	res = call_object(compare, args);
+	DECREF(args);
+	if (res == NULL)
+		return CMPERROR;
+	if (!is_intobject(res)) {
+		DECREF(res);
+		err_setstr(TypeError, "comparison function should return int");
+		return CMPERROR;
+	}
+	i = getintvalue(res);
+	DECREF(res);
+	if (i < 0)
+		return -1;
+	if (i > 0)
+		return 1;
+	return 0;
+}
+
+/* Straight insertion sort.  More efficient for sorting small arrays. */
+
+static int
+insertionsort(array, size, compare)
+	object **array;	/* Start of array to sort */
+	int size;	/* Number of elements to sort */
+	object *compare;/* Comparison function object, or NULL for default */
+{
+	register object **a = array;
+	register int i;
+
+	for (i = 1; i < size; i++) {
+		register object *key = a[i];
+		register int j = i;
+		while (--j >= 0) {
+			register int k = docompare(a[j], key, compare);
+			if (k == CMPERROR)
+				return -1;
+			if (k <= 0)
+				break;
+			a[j+1] = a[j];
+			a[j] = key; /* For consistency */
+		}
+	}
+
+	return 0;
+}
+
+/* MINSIZE is the smallest array we care to partition; smaller arrays
+   are sorted using a straight insertion sort (above). */
+#define MINSIZE 10
+
+/* STACKSIZE is the size of our work stack.  A rough estimate is that
+   this allows us to sort arrays of MINSIZE * 2**STACKSIZE, or large
+   enough.  (Because of the way we push the biggest partition first,
+   the worst case occurs when all subarrays are always partitioned
+   exactly in two.) */
+#define STACKSIZE 64
+
+/* Quicksort algorithm.  Return -1 if an exception occurred; in this
+   case we leave the array partly sorted but otherwise in good health
+   (i.e. no items have been removed or duplicated). */
+
+static int
+quicksort(array, size, compare)
+	object **array;	/* Start of array to sort */
+	int size;	/* Number of elements to sort */
+	object *compare;/* Comparison function object, or NULL for default */
+{
+	register object **a, *tmp, *pivot;
+	register int n, l, r, k;
+	int top, i, j, n2;
+	object **astack[STACKSIZE];
+	int nstack[STACKSIZE];
+
+	/* Start out with the whole array on the work stack */
+	astack[0] = array;
+	nstack[0] = size;
+	top = 1;
+
+	/* Repeat until the work stack is empty */
+	while (--top >= 0) {
+		a = astack[top];
+		n = nstack[top];
+
+		/* If it's a small one, use straight insertion sort */
+		if (n < MINSIZE) {
+			if (insertionsort(a, n, compare) < 0)
+				return -1;
+			continue;
+		}
+
+		/* Choose median of a[0], a[n/2], a[n-1] as pivot */
+		i = n>>1;
+		j = n-1;
+		k = docompare(a[0], a[i], compare);
+		if (k == CMPERROR)
+			return -1;
+		if (k < 0)
+			{ tmp = a[0]; a[0] = a[i]; a[i] = tmp; }
+		k = docompare(a[j], a[i], compare);
+		if (k == CMPERROR)
+			return -1;
+		if (k < 0)
+			{ tmp = a[j]; a[j] = a[i]; a[i] = tmp; }
+		k = docompare(a[j], a[0], compare);
+		if (k == CMPERROR)
+			return -1;
+		if (k < 0)
+			{ tmp = a[j]; a[j] = a[0]; a[0] = tmp; }
+		pivot = a[0];
+
+		/* Partition the array */
+		l = 0;
+		r = n;
+		for (;;) {
+			/* Move left index to element > pivot */
+			while (++l < n) {
+				k = docompare(a[l], pivot, compare);
+				if (k == CMPERROR)
+					return -1;
+				if (k > 0)
+					break;
+			}
+			/* Move right index to element < pivot */
+			while (--r > 0) {
+				k = docompare(a[r], pivot, compare);
+				if (k == CMPERROR)
+					return -1;
+				if (k < 0)
+					break;
+			}
+			/* If they met, we're through */
+			if (r < l)
+				break;
+			/* Swap elements and continue */
+			{ tmp = a[l]; a[l] = a[r]; a[r] = tmp; }
+		}
+
+		/* Move the pivot into the middle */
+		{ tmp = a[0]; a[0] = a[r]; a[r] = tmp; }
+
+		/* We have now reached the following conditions:
+			0 <= r < l <= n
+			all x in a[0:r] are <= pivot
+			all x in a[r:l] are == pivot
+			all x in a[l:n] are >= pivot
+		   The partitions are a[0:r] and a[l:n]
+		 */
+
+		/* Push biggest partition first */
+		n2 = n - l;
+		if (r > n2) {
+			/* First one is bigger */
+			if (r > 1) {
+				astack[top] = a;
+				nstack[top++] = r;
+				if (n2 > 1) {
+					astack[top] = a+l;
+					nstack[top++] = n2;
+				}
+			}
+		} else {
+			/* Second one is bigger */
+			if (n2 > 1) {
+				astack[top] = a+l;
+				nstack[top++] = n2;
+				if (r > 1) {
+					astack[top] = a;
+					nstack[top++] = r;
+				}
+			}
+		}
+
+		/* Should assert top < STACKSIZE-1 */
+	}
+
+	/* Succes */
+	return 0;
+}
+
+static object *
+listsort(self, compare)
+	listobject *self;
+	object *compare;
+{
+	/* XXX Don't you *dare* changing the list's length in compare()! */
+	if (quicksort(self->ob_item, self->ob_size, compare) < 0)
+		return NULL;
+	INCREF(None);
+	return None;
+}
+
+#else /* !NEWSORT */
+
 static object *comparefunc;

 static int
@@ -616,6 +841,8 @@
 	INCREF(None);
 	return None;
 }
+
+#endif

 static object *
 listreverse(self, args)


add CH_USE_RESULT macro

add CH_USE_RESULT macro

--- chasky/common/macros.h
+++ chasky/common/macros.h
@@ -4,6 +4,8 @@
   __attribute__((__format__(__printf__, string_index, first_to_check)))
 #define CH_SCANF_ATTRIBUTE(string_index, first_to_check)                       \
   __attribute__((__format__(__scanf__, string_index, first_to_check)))
+
+#define CH_USE_RESULT __attribute__((warn_unused_result))

 // disable class's copy and assign function
 #define CH_DISALLOW_COPY_AND_ASSIGN(T)                                         \


Add ImGuilistClipper struct under CIMGUI_DEFINE_ENUMS_AND_STRUCTS

--- cimgui/cimgui.h
+++ cimgui/cimgui.h
@@ -387,6 +387,13 @@
     char            Name[32];
     struct ImFont*  DstFont;
 };
+
+struct ImGuiListClipper
+{
+    float   StartPosY;
+    float   ItemsHeight;
+    int     ItemsCount, StepNo, DisplayStart, DisplayEnd;
+};
 #endif // CIMGUI_DEFINE_ENUMS_AND_STRUCTS

 CIMGUI_API struct ImGuiIO*         igGetIO();


Implemented `if'

Implemented `if'

--- test-parser.c
+++ test-parser.c
@@ -356,6 +356,105 @@
     return sexp_free(values[1], error);
 }

+/* The `if' primitive function */
+static int prim_if(env_t env, sexp_t args, sexp_t *result, elvin_error_t error)
+{
+    sexp_t test, true_branch, false_branch;
+    sexp_t value;
+
+    /* Make sure we have at least one arg */
+    if (sexp_get_type(args) != SEXP_CONS)
+    {
+	ELVIN_ERROR_ELVIN_NOT_YET_IMPLEMENTED(error, "too few args");
+	return 0;
+    }
+
+    /* Extract it */
+    if ((test = cons_car(args, error)) == NULL)
+    {
+	return 0;
+    }
+
+    /* Move on to the next arg */
+    if ((args = cons_cdr(args, error)) == NULL)
+    {
+	return 0;
+    }
+
+    /* Make sure we have a second arg */
+    if (sexp_get_type(args) != SEXP_CONS)
+    {
+	ELVIN_ERROR_ELVIN_NOT_YET_IMPLEMENTED(error, "too few args");
+	return 0;
+    }
+
+    /* Extract it */
+    if ((true_branch = cons_car(args, error)) == NULL)
+    {
+	return 0;
+    }
+
+    /* Move on to the next arg */
+    if ((args = cons_cdr(args, error)) == NULL)
+    {
+	return 0;
+    }
+
+    /* Make sure we have a third arg */
+    if (sexp_get_type(args) != SEXP_CONS)
+    {
+	ELVIN_ERROR_ELVIN_NOT_YET_IMPLEMENTED(error, "too few args");
+	return 0;
+    }
+
+    /* Extract it */
+    if ((false_branch = cons_car(args, error)) == NULL)
+    {
+	return 0;
+    }
+
+    /* Move on to the next arg */
+    if ((args = cons_cdr(args, error)) == NULL)
+    {
+	return 0;
+    }
+
+    /* Make sure there are no more args */
+    if (sexp_get_type(args) != SEXP_NIL)
+    {
+	ELVIN_ERROR_ELVIN_NOT_YET_IMPLEMENTED(error, "too many args");
+	return 0;
+    }
+
+
+    /* Evaluate the test */
+    if (sexp_eval(test, env, &value, error) == 0)
+    {
+	return 0;
+    }
+
+    /* If it's non-nil then evaluate the true branch */
+    if (sexp_get_type(value) != SEXP_NIL)
+    {
+	if (sexp_eval(true_branch, env, result, error) == 0)
+	{
+	    sexp_free(value, NULL);
+	    return 0;
+	}
+    }
+    else
+    {
+	if (sexp_eval(false_branch, env, result, error) == 0)
+	{
+	    sexp_free(value, NULL);
+	    return 0;
+	}
+    }
+
+    /* Free the test's result */
+    return sexp_free(value, error);
+}
+
 /* The `lambda' primitive function */
 static int prim_lambda(env_t env, sexp_t args, sexp_t *result, elvin_error_t error)
 {
@@ -543,6 +642,7 @@
 	env_set_builtin(env, "cdr", prim_cdr, error) == 0 ||
 	env_set_builtin(env, "cons", prim_cons, error) == 0 ||
 	env_set_builtin(env, "eq", prim_eq, error) == 0 ||
+	env_set_builtin(env, "if", prim_if, error) == 0 ||
 	env_set_builtin(env, "lambda", prim_lambda, error) == 0 ||
 	env_set_builtin(env, "+", prim_plus, error) == 0 ||
 	env_set_builtin(env, "quote", prim_quote, error) == 0 ||


add (/) to seek in chapters with test-player

--- test-player.c
+++ test-player.c
@@ -61,6 +61,7 @@
   " 5/6 : previous/next subtitle\n" \
   " 7/8 : previous/next TV analog channel\n" \
   " {/} : previous/next radio channel\n" \
+  " (/) : previous/next chapter\n" \
   " u   : toggle subtitle visibility\n" \
   " a   : change aspect ratio (original/16:9)\n" \
   " l   : load a stream in the playlist\n" \
@@ -1005,6 +1006,14 @@
       player_radio_channel_next (player);
       printf ("RADIO CHANNEL NEXT\n");
       break;
+    case '(':
+      player_playback_seek_chapter (player, -1, 0);
+      printf ("SEEK CHAPTER -1\n");
+      break;
+    case ')':
+      player_playback_seek_chapter (player, 1, 0);
+      printf ("SEEK CHAPTER +1\n");
+      break;
     case '0':   /* increase volume */
       if (++volume > 100)
         volume = 100;


print out progress

print out progress

--- test/t_create.c
+++ test/t_create.c
@@ -23,6 +23,11 @@
         }
         posix_fallocate(fd, 0, rand() % sizemax);
         close(fd);
+
+        if (i % 100 == 0) {
+            double percent = (double) i / count;
+            fprintf(stderr, "%.2f are done\n", percent);
+        }
     }
 }


CDRIVER-25 added test for timeouts

CDRIVER-25 added test for timeouts

error: pathspec 'test/timeouts.c' did not match any file(s) known to git

--- test/timeouts.c
+++ test/timeouts.c
@@ -0,0 +1,39 @@
+/* timeouts.c */
+
+#include "test.h"
+#include "mongo.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+
+int main() {
+
+    mongo_connection conn[1];
+    bson_buffer bb;
+    bson b;
+    int res;
+    time_t t1, t2;
+
+    if( mongo_connect( conn, TEST_SERVER, 27017 ) != MONGO_OK ) {
+        printf("Failed to connect");
+        exit(1);
+    }
+
+    res = mongo_simple_str_command( conn, "test", "$eval",
+            "for(i=0; i<100000; i++) { db.foo.find() }", &b );
+
+    ASSERT( res == MONGO_OK );
+
+    /* 50ms timeout */
+    mongo_conn_set_timeout( conn, 50 );
+
+    ASSERT( conn->err == 0 );
+    res = mongo_simple_str_command( conn, "test", "$eval",
+            "for(i=0; i<100000; i++) { db.foo.find() }", &b );
+
+    ASSERT( res == MONGO_ERROR );
+    ASSERT( conn->err == MONGO_IO_ERROR );
+
+    return 0;
+}


Add comments to ngx_http_ssl_ct_create_srv_conf.

--- ngx_http_ssl_ct_module.c
+++ ngx_http_ssl_ct_module.c
@@ -116,12 +116,14 @@
 static char *ngx_http_ssl_ct_merge_srv_conf(ngx_conf_t *cf, void *parent,
     void *child)
 {
+    /* merge config */
     ngx_http_ssl_ct_srv_conf_t *prev = parent;
     ngx_http_ssl_ct_srv_conf_t *conf = child;

     ngx_conf_merge_value(conf->enable, prev->enable, 0);
     ngx_conf_merge_str_value(conf->sct, prev->sct, "");

+    /* validate config */
     if (conf->enable)
     {
         if (conf->sct.len == 0)
@@ -137,6 +139,7 @@
         return NGX_CONF_OK;
     }

+    /* get ngx_http_ssl_module configuration and check if SSL is enabled */
     ngx_http_ssl_srv_conf_t *ssl_conf = ngx_http_conf_get_module_srv_conf(cf,
         ngx_http_ssl_module);

@@ -147,6 +150,7 @@
         return NGX_CONF_ERROR;
     }

+    /* read .sct files */
     ngx_http_ssl_ct_ext *sct_list = ngx_http_ssl_ct_read_static_scts(cf,
         &conf->sct);
     if (!sct_list)
@@ -155,6 +159,7 @@
         return NGX_CONF_ERROR;
     }

+    /* add OpenSSL TLS extension */
     if (SSL_CTX_add_server_custom_ext(ssl_conf->ssl.ctx, NGX_HTTP_SSL_CT_EXT,
         &ngx_http_ssl_ct_ext_cb, NULL, sct_list, NULL, NULL) == 0)
     {


Enable OPTIONS method processing for normal requests

--- ngx_http_upload_module.c
+++ ngx_http_upload_module.c
@@ -711,13 +711,13 @@
     ngx_http_upload_ctx_t     *u;
     ngx_int_t                 rc;

-    ulcf = ngx_http_get_module_loc_conf(r, ngx_http_upload_module);
-
-    if((r->method & NGX_HTTP_OPTIONS) && ulcf->resumable_uploads)
+    if(r->method & NGX_HTTP_OPTIONS)
         return ngx_http_upload_options_handler(r);

     if (!(r->method & NGX_HTTP_POST))
         return NGX_HTTP_NOT_ALLOWED;
+
+    ulcf = ngx_http_get_module_loc_conf(r, ngx_http_upload_module);

     u = ngx_http_get_module_ctx(r, ngx_http_upload_module);

@@ -791,30 +791,32 @@
     ngx_table_elt_t                      *h;
     ngx_uint_t                           i;

-    t = ulcf->header_templates->elts;
-    for(i = 0; i < ulcf->header_templates->nelts; i++) {
-        if(ngx_http_complex_value(r, t->name, &name) != NGX_OK) {
-            return NGX_ERROR;
-        }
-
-        if(ngx_http_complex_value(r, t->value, &value) != NGX_OK) {
-            return NGX_ERROR;
-        }
-
-        if(name.len != 0 && value.len != 0) {
-            h = ngx_list_push(&r->headers_out.headers);
-            if(h == NULL) {
+    if(ulcf->header_templates != NULL) {
+        t = ulcf->header_templates->elts;
+        for(i = 0; i < ulcf->header_templates->nelts; i++) {
+            if(ngx_http_complex_value(r, t->name, &name) != NGX_OK) {
                 return NGX_ERROR;
             }

-            h->hash = 1;
-            h->key.len = name.len;
-            h->key.data = name.data;
-            h->value.len = value.len;
-            h->value.data = value.data;
-        }
-
-        t++;
+            if(ngx_http_complex_value(r, t->value, &value) != NGX_OK) {
+                return NGX_ERROR;
+            }
+
+            if(name.len != 0 && value.len != 0) {
+                h = ngx_list_push(&r->headers_out.headers);
+                if(h == NULL) {
+                    return NGX_ERROR;
+                }
+
+                h->hash = 1;
+                h->key.len = name.len;
+                h->key.data = name.data;
+                h->value.len = value.len;
+                h->value.data = value.data;
+            }
+
+            t++;
+        }
     }

     return NGX_OK;
@@ -851,12 +853,12 @@
     ngx_str_t                   dummy = ngx_string("<ngx_upload_module_dummy>");
     ngx_table_elt_t             *h;

+    if(ngx_http_upload_add_headers(r, ulcf) != NGX_OK) {
+        return NGX_HTTP_INTERNAL_SERVER_ERROR;
+    }
+
     if(ctx->prevent_output) {
         r->headers_out.status = NGX_HTTP_CREATED;
-
-        if(ngx_http_upload_add_headers(r, ulcf) != NGX_OK) {
-            return NGX_HTTP_INTERNAL_SERVER_ERROR;
-        }

         /*
          * Add range header and body


* src/dim/feedbacker/Easy.h: async class added + changed the effectiveness formula, it was based on an average of a population effectiveness and now it is based on a learning process using individuals one by one

--- src/dim/feedbacker/Easy.h
+++ src/dim/feedbacker/Easy.h
@@ -21,6 +21,7 @@
 #define _FEEDBACKER_EASY_H_

 #include <vector>
+#include <queue>

 #include "Base.h"

@@ -28,68 +29,276 @@
 {
     namespace feedbacker
     {
-	template <typename EOT>
-	class Easy : public Base<EOT>
+	namespace sync
 	{
-	public:
-	    virtual void firstCall(core::Pop<EOT>& /*pop*/, core::IslandData<EOT>& data)
+	    template <typename EOT>
+	    class Easy : public Base<EOT>
 	    {
-		_reqs.resize( this->size() );
-
-		for (size_t i = 0; i < this->size(); ++i)
-		    {
-			if (i == this->rank()) { continue; }
-			_reqs[i] = this->world().send_init( i, this->tag(), data.feedbacks[i] );
-		    }
-	    }
-
-	    void operator()(core::Pop<EOT>& pop, core::IslandData<EOT>& data)
+	    public:
+		virtual void firstCall(core::Pop<EOT>& /*pop*/, core::IslandData<EOT>& data)
+		{
+		    _reqs.resize( this->size() );
+
+		    for (size_t i = 0; i < this->size(); ++i)
+			{
+			    if (i == this->rank()) { continue; }
+			    _reqs[i] = this->world().send_init( i, this->tag(), data.feedbacks[i] );
+			}
+		}
+
+		void operator()(core::Pop<EOT>& pop, core::IslandData<EOT>& data)
+		{
+		    /************************************************
+		     * Send feedbacks back to all islands (ANALYSE) *
+		     ************************************************/
+
+		    std::vector<typename EOT::Fitness> sums(this->size(), 0);
+		    std::vector<int> nbs(this->size(), 0);
+		    for (auto &ind : pop)
+			{
+			    sums[ind.getLastIsland()] += ind.fitness() - ind.getLastFitness();
+			    ++nbs[ind.getLastIsland()];
+			}
+
+		    for (size_t i = 0; i < this->size(); ++i)
+			{
+			    if (i == this->rank()) { continue; }
+			    data.feedbacks[i] = nbs[i] > 0 ? sums[i] / nbs[i] : 0;
+			    this->world().start( _reqs[i] );
+			}
+
+		    // for island itself because of the MPI communication optimizing.
+		    data.feedbacks[this->rank()] = nbs[this->rank()] > 0 ? sums[this->rank()] / nbs[this->rank()] : 0;
+
+		    /**************************************
+		     * Receive feedbacks from all islands *
+		     **************************************/
+
+		    std::vector< boost::mpi::request > recv_reqs;
+
+		    for (size_t i = 0; i < this->size(); ++i)
+			{
+			    if (i == this->rank()) { continue; }
+			    recv_reqs.push_back( this->world().irecv( i, this->tag(), data.feedbacks[i] ) );
+			}
+
+		    /****************************
+		     * Process all MPI requests *
+		     ****************************/
+
+		    boost::mpi::wait_all( _reqs.begin(), _reqs.end() );
+		    boost::mpi::wait_all( recv_reqs.begin(), recv_reqs.end() );
+		}
+
+	    private:
+		std::vector< boost::mpi::request > _reqs;
+	    };
+	} // !sync
+
+	namespace async
+	{
+	    template <typename EOT>
+	    class Easy : public Base<EOT>
 	    {
-		/************************************************
-		 * Send feedbacks back to all islands (ANALYSE) *
-		 ************************************************/
-
-		std::vector<typename EOT::Fitness> sums(this->size(), 0);
-		std::vector<int> nbs(this->size(), 0);
-		for (auto &ind : pop)
-		    {
-			sums[ind.getLastIsland()] += ind.fitness() - ind.getLastFitness();
-			++nbs[ind.getLastIsland()];
-		    }
-
-		for (size_t i = 0; i < this->size(); ++i)
-		    {
-			if (i == this->rank()) { continue; }
-			data.feedbacks[i] = nbs[i] > 0 ? sums[i] / nbs[i] : 0;
-			this->world().start( _reqs[i] );
-		    }
-
-		// for island itself because of the MPI communication optimizing.
-		data.feedbacks[this->rank()] = nbs[this->rank()] > 0 ? sums[this->rank()] / nbs[this->rank()] : 0;
-
-		/**************************************
-		 * Receive feedbacks from all islands *
-		 **************************************/
-
-		std::vector< boost::mpi::request > recv_reqs;
-
-		for (size_t i = 0; i < this->size(); ++i)
-		    {
-			if (i == this->rank()) { continue; }
-			recv_reqs.push_back( this->world().irecv( i, this->tag(), data.feedbacks[i] ) );
-		    }
-
-		/****************************
-		 * Process all MPI requests *
-		 ****************************/
-
-		boost::mpi::wait_all( _reqs.begin(), _reqs.end() );
-		boost::mpi::wait_all( recv_reqs.begin(), recv_reqs.end() );
-	    }
-
-	private:
-	    std::vector< boost::mpi::request > _reqs;
-	};
+	    public:
+		virtual void firstCompute(core::Pop<EOT>& /*pop*/, core::IslandData<EOT>& /*data*/)
+		{
+		    std::ostringstream ss;
+		    ss << "trace.feedbacker." << this->rank() << ".algo.txt";
+		    _of_algo.open(ss.str());
+
+		    std::ostringstream ss_data;
+		    ss_data << "trace.feedbacker." << this->rank() << ".algo.data.txt";
+		    _of_algo_data.open(ss_data.str());
+		}
+
+		void compute(core::Pop<EOT>& pop, core::IslandData<EOT>& data)
+		{
+		    if (!pop.empty())
+			{
+			    /************************************************
+			     * Send feedbacks back to all islands (ANALYSE) *
+			     ************************************************/
+
+			    // old population based model for communication
+			    // std::vector<typename EOT::Fitness> sums(this->size(), 0);
+			    // std::vector<int> nbs(this->size(), 0);
+			    // for (auto& ind : pop)
+			    // 	{
+			    // 	    sums[ind.getLastIsland()] += ind.fitness() - ind.getLastFitness();
+			    // 	    ++nbs[ind.getLastIsland()];
+			    // 	}
+
+			    // _m_fbs.lock();
+			    // for (size_t i = 0; i < this->size(); ++i)
+			    // 	{
+			    // 	    if (i == this->rank()) { continue; }
+			    // 	    data.feedbacks[i] = nbs[i] > 0 ? sums[i] / nbs[i] : 0;
+			    // 	    // std::cout << data.feedbacks[i] << " "; std::cout.flush();
+			    // 	    _vec_fbs[i].push( data.feedbacks[i] );
+			    // 	}
+			    // _m_fbs.unlock();
+
+			    // // for island itself because of the MPI communication optimizing.
+			    // data.feedbacks[this->rank()] = nbs[this->rank()] > 0 ? sums[this->rank()] / nbs[this->rank()] : 0;
+
+			    // new model
+			    for (auto& ind : pop)
+			    	{
+			    	    auto delta = ind.fitness() - ind.getLastFitness();
+
+				    // if (ind.getLastIsland() == this->rank())
+				    // 	{
+				    // 	    auto& Ri = data.feedbacks[this->rank()];
+
+				    // 	    // data.feedbacks[this->rank()] = data.feedbacks[this->rank()] + 0.01 * ( delta - data.feedbacks[this->rank()] );
+				    // 	    Ri = Ri + 0.01 * ( delta - Ri );
+				    // 	    continue;
+				    // 	}
+
+				    auto& fbsPair = data.feedbackerSendingQueuesVector[ind.getLastIsland()];
+				    fbsPair.first.lock();
+				    fbsPair.second.push( delta );
+				    fbsPair.first.unlock();
+			    	}
+
+			    auto& fbr = data.feedbackerReceivingQueuesVector[this->rank()].second;
+			    auto& fbs = data.feedbackerSendingQueuesVector[this->rank()].second;
+			    while ( !fbs.empty() )
+			    	{
+			    	    fbr.push( fbs.front() );
+			    	    fbs.pop();
+			    	}
+			}
+
+		    /*************************************
+		     * Update feedbacks from all islands *
+		     *************************************/
+
+		    for (size_t i = 0; i < this->size(); ++i)
+			{
+			    // if (i == this->rank()) { continue; }
+
+			    auto& m = data.feedbackerReceivingQueuesVector[i].first;
+			    auto& fbr = data.feedbackerReceivingQueuesVector[i].second;
+			    auto& Ri = data.feedbacks[i];
+
+			    m.lock();
+			    size_t n = fbr.size();
+			    if (n)
+				{
+				    // typename EOT::Fitness sum = 0;
+				    while (!fbr.empty())
+					{
+					    // sum += _vec_fbr[i].front();
+
+					    auto& Fi = fbr.front();
+					    Ri = Ri + 0.01 * ( Fi - Ri );
+
+					    fbr.pop();
+					}
+				    // double coef = pop.size() / (popSize*this->size());
+				    // data.feedbacks[i] = (sum / (typename EOT::Fitness)(n))/* * coef*/;
+				    _of_algo_data << Ri << " "; _of_algo_data.flush();
+				    // std::cout << data.feedbacks[i] << " "; std::cout.flush();
+				}
+			    m.unlock();
+			}
+		}
+
+		virtual void firstCommunicate(core::Pop<EOT>&, core::IslandData<EOT>&)
+		{
+		    std::ostringstream ss;
+		    ss << "trace.feedbacker." << this->rank() << ".comm.txt";
+		    _of_comm.open(ss.str());
+
+		    std::ostringstream ss_data;
+		    ss_data << "trace.feedbacker." << this->rank() << ".comm.data.txt";
+		    _of_comm_data.open(ss_data.str());
+		}
+
+		void communicate(core::Pop<EOT>& /*pop*/, core::IslandData<EOT>& data)
+		{
+		    // size_t next = (this->rank()+1) % this->size();
+		    // _of_comm << _vec_fbs[next].size() << " ";
+		    // _of_comm << _vec_fbr[next].size() << " ";
+		    // _of_comm.flush();
+
+		    for (size_t i = 0; i < this->size(); ++i)
+			{
+			    if (i == this->rank()) continue;
+
+			    std::vector< boost::mpi::request > reqs;
+
+			    /***********************************
+			     * Send feedbacks to all islands *
+			     ***********************************/
+			    {
+
+				auto& fbs = data.feedbackerSendingQueuesVector[i].second;
+				auto& ms = data.feedbackerSendingQueuesVector[i].first;
+
+				ms.lock();
+				std::vector< typename EOT::Fitness > fbsVec;
+				while (!fbs.empty())
+				    {
+					fbsVec.push_back( fbs.front() );
+					fbs.pop();
+				    }
+				ms.unlock();
+
+				this->world().send(i, this->tag()*10, fbsVec.size());
+
+				if (fbsVec.size())
+				    {
+					reqs.push_back( this->world().isend(i, this->tag(), fbsVec) );
+				    }
+			    }
+
+			    /****************************************
+			     * Receive individuals from all islands *
+			     ****************************************/
+			    {
+
+				size_t count = 0;
+				this->world().recv(i, this->tag()*10, count);
+
+				std::vector< typename EOT::Fitness > fbrVec;
+				if (count)
+				    {
+					reqs.push_back( this->world().irecv(i, this->tag(), fbrVec) );
+				    }
+
+				/****************************
+				 * Process all MPI requests *
+				 ****************************/
+
+				boost::mpi::wait_all( reqs.begin(), reqs.end() );
+
+				auto& fbr = data.feedbackerReceivingQueuesVector[i].second;
+				auto& mr = data.feedbackerReceivingQueuesVector[i].first;
+
+				if (!fbrVec.empty())
+				    {
+					mr.lock();
+					for (size_t k = 0; k < fbrVec.size(); ++k)
+					    {
+						fbr.push( fbrVec[k] );
+					    }
+					mr.unlock();
+				    }
+			    }
+			}
+		}
+
+	    public:
+		size_t popSize = 0;
+
+	    private:
+		std::ofstream _of_comm, _of_algo;
+		std::ofstream _of_comm_data, _of_algo_data;
+	    };
+	} // !async
     }
 }


btshell: Fix parsing of high_duty parameter

Parsing was called twice resulting always storing default value (0).

--- apps/btshell/src/cmd.c
+++ apps/btshell/src/cmd.c
@@ -270,12 +270,6 @@
     params.sid = parse_arg_uint8_dflt("sid", 0, &rc);
     if (rc != 0) {
         console_printf("invalid 'sid' parameter\n");
-        return rc;
-    }
-
-    params.high_duty_directed = parse_arg_uint8_dflt("high_duty", 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'high_duty' parameter\n");
         return rc;
     }


add default values back in

add default values back in


cleanup

cleanup

--- strings_en.h
+++ strings_en.h
@@ -10,9 +10,9 @@
 const char HTTP_HEAD_END[]         PROGMEM = "
";
 const char HTTP_ROOT_MAIN[]        PROGMEM = "
{v}

WiFiManager
";
 const char HTTP_PORTAL_OPTIONS[]   PROGMEM = "<form action='/wifi' method='GET'><button>Configure WiFi</button></form>
<form action='/0wifi' method='GET'><button>Configure WiFi (No Scan)</button></form>
<form action='/i' method='GET'><button>Info</button></form>
<form action='/r' method='GET'><button>Restart</button></form>
<form action='/exit' method='GET'><button>Quit</button></form>";
-const char HTTP_ITEM_QI[]          PROGMEM = "

";
-const char HTTP_ITEM_QP[]          PROGMEM = "
{r}%
";
-const char HTTP_ITEM[]             PROGMEM = "
{v}{q}
";
+const char HTTP_ITEM_QI[]          PROGMEM = "

"; // rssi icons
+const char HTTP_ITEM_QP[]          PROGMEM = "
{r}%
"; // rssi percentage
+const char HTTP_ITEM[]             PROGMEM = "
{v}{q}
"; // {q} = HTTP_ITEM_QI, {r} = HTTP_ITEM_QP
 // const char HTTP_ITEM[]            PROGMEM = "
{v} {R} {r}% {q} {e}
"; // test all tokens
 const char HTTP_FORM_START[]       PROGMEM = "<form method='POST' action='wifisave'>SSID<input id='s' name='s' maxlength=32 placeholder='{v}'>
Password<input id='p' name='p' maxlength='64' type='password' placeholder=''>
";
 const char HTTP_FORM_END[]         PROGMEM = "
<button type='submit'>Save</button></form>";
@@ -77,7 +77,6 @@
 "    var params = typeof data == 'string' ? data : Object.keys(data).map("
 "            function(k){ return encodeURIComponent(k) + '=' + encodeURIComponent(data[k]) }"
 "        ).join('&');"
-""
 "    var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject(\"Microsoft.XMLHTTP\");"
 "    xhr.open('POST', url);"
 "    xhr.onreadystatechange = function() {"
@@ -86,11 +85,8 @@
 "    xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');"
 "    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');"
 "    xhr.send(params);"
-"    return xhr;"
-"}"
-"// example request\n"
+"    return xhr;}"
 "postAjax('/status', 'p1=1&p2=Hello+World', function(data){ console.log(data); });"
-"// example request with data object\n"
 "postAjax('/status', { p1: 1, p2: 'Hello World' }, function(data){ console.log(data); });"
 "</script>";
 #endif


Tracked down struct-lea bug - added

Tracked down struct-lea bug - added

error: pathspec 'struct_bug.c' did not match any file(s) known to git

--- struct_bug.c
+++ struct_bug.c
@@ -0,0 +1,5 @@
+main()
+{
+	struct { int i; } a;
+	&a; // most likely this is a problem is asm_sym, changing a mov to a lea and not qualifiying with ptr_depth_inc
+}


protect __USE_STD_IOSTREAM for aix

protect __USE_STD_IOSTREAM for aix

git-svn-id: ecbadac9c76e8cf640a0bca86f6bd796c98521e3@13658 27541ba8-7e3a-0410-8455-c3a389f83636

--- reflex/inc/Reflex/Kernel.h
+++ reflex/inc/Reflex/Kernel.h
@@ -1,4 +1,4 @@
-// @(#)root/reflex:$Name:  $:$Id: Kernel.h,v 1.6 2005/11/23 16:08:08 roiser Exp $
+// @(#)root/reflex:$Name:  $:$Id: Kernel.h,v 1.7 2005/12/12 14:40:45 roiser Exp $
 // Author: Stefan Roiser 2004

 // Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved.
@@ -23,7 +23,9 @@
 #endif

 #if defined(__alpha) && !defined(__linux)
+#ifndef __USE_STD_IOSTREAM
 #define __USE_STD_IOSTREAM
+#endif
 #endif

 // Some pragmas to avoid warnings in VisualC


slightly more efficient sblist_delete

slightly more efficient sblist_delete

--- src/sblist/sblist_delete.c
+++ src/sblist/sblist_delete.c
@@ -2,12 +2,8 @@
 #include <string.h>

 void sblist_delete(sblist* l, size_t item) {
-	size_t i, m;
 	if (l->count && item < l->count) {
-		m = l->count - 1;
-		for(i = item; i < m; i++) {
-			memcpy(sblist_get(l, i), sblist_get(l, i + 1), l->itemsize);
-		}
+		memmove(sblist_item_from_index(l, item), sblist_item_from_index(l, item + 1), (sblist_getsize(l) - (item + 1)) * l->itemsize);
 		l->count--;
 	}
 }


src/service: more targeted error message when loosing existing connection

Up to now, when the D-Bus disappeared, RAUC exited with:

| Connection to the bus can't be made for de.pengutronix.rauc

This is quite misleading as the connection was actually present before
but was cut off. Thus we differentiate these two cases by checking for
an already-set r_installer that implies r_on_bus_acquired was called
successfully before.

Signed-off-by: Enrico Joerns <a2e5f936c390f36494e46e71bcfbe365bb1e8c49@pengutronix.de>

--- src/service.c
+++ src/service.c
@@ -521,7 +521,10 @@
 	                             ? "session" : "system";

 	if (connection == NULL) {
-		g_printerr("Connection to the %s bus can't be made for %s\n", bus_type_name, name);
+		if (r_installer)
+			g_printerr("Lost connection to the %s bus\n", bus_type_name);
+		else
+			g_printerr("Connection to the %s bus can't be made for %s\n", bus_type_name, name);
 	} else {
 		g_printerr("Failed to obtain name %s on %s bus\n", name, bus_type_name);
 	}


SWL-2161 Use first 63 bytes as the default key

--- modules/pimu/module/src/pimu.c
+++ modules/pimu/module/src/pimu.c
@@ -171,8 +171,12 @@
             return PIMU_ACTION_ERROR;
         }
         data = key;
-    } else if(size < PIMU_CONFIG_PACKET_KEY_SIZE) {
-        PIMU_MEMCPY(key, data, size);
+    } else {
+        if(size < PIMU_CONFIG_PACKET_KEY_SIZE) {
+            PIMU_MEMCPY(key, data, size);
+        } else {
+            PIMU_MEMCPY(key, data, PIMU_CONFIG_PACKET_KEY_SIZE - 1);
+        }
         data = key;
     }
     pe = (pimu_entry_t*)nwac_search(pimu->nwac, data, now);


Allow empty `--` run/task/service descriptions => no progress

Signed-off-by: Joachim Nilsson <583c295fd7602c168ad814279bbc3894ba65f5d6@gmail.com>

--- src/service.c
+++ src/service.c
@@ -639,6 +639,15 @@

 		while (*desc && isblank(*desc))
 			desc++;
+	} else {
+		int pos;
+
+		/* Find "--\n" to denote empty/no description */
+		pos = (int)strlen(line) - 2;
+		if (pos > 0 && !strcmp(&line[pos], "--")) {
+			line[pos] = 0;
+			desc = &line[pos];
+		}
 	}

 	cmd = strtok(line, " ");