mpd: run clang-format

mpd: run clang-format

--- src/print_mpd.c
+++ src/print_mpd.c
@@ -9,126 +9,121 @@

 #include "i3status.h"

-#define COPY_CROP(dst, src) \
-        do { \
-                const char *tsrc = src; \
-                const unsigned int maxcplen = sizeof(dst)-4; \
-                if (src) { \
-                        strncpy(dst, tsrc, maxcplen+1); \
-                        if (strlen(tsrc) > maxcplen) { \
-                                strcpy(dst + maxcplen, "..."); \
-                        } \
-                } \
-        } while(0)
-
+#define COPY_CROP(dst, src)                            \
+    do {                                               \
+        const char *tsrc = src;                        \
+        const unsigned int maxcplen = sizeof(dst) - 4; \
+        if (src) {                                     \
+            strncpy(dst, tsrc, maxcplen + 1);          \
+            if (strlen(tsrc) > maxcplen) {             \
+                strcpy(dst + maxcplen, "...");         \
+            }                                          \
+        }                                              \
+    } while (0)

 void print_mpd(yajl_gen json_gen, char *buffer, const char *host, int port, const char *password, const char *format) {
-        const char *walk;
-        char *outwalk = buffer;
-        static char titlebuf[40];
-        static char artistbuf[40];
-        static char albumbuf[40];
-        static char trackbuf[10];
-        static char datebuf[10];
+    const char *walk;
+    char *outwalk = buffer;
+    static char titlebuf[40];
+    static char artistbuf[40];
+    static char albumbuf[40];
+    static char trackbuf[10];
+    static char datebuf[10];

-        static struct mpd_connection *conn;
-        struct mpd_status *status = NULL;
-        enum mpd_state state;
-        struct mpd_song *song;
+    static struct mpd_connection *conn;
+    struct mpd_status *status = NULL;
+    enum mpd_state state;
+    struct mpd_song *song;

-        /* First run */
+    /* First run */
+    if (conn == NULL) {
+        conn = mpd_connection_new(host, port, 1500);
         if (conn == NULL) {
-                conn = mpd_connection_new(host, port, 1500);
-                if (conn == NULL) {
-                        START_COLOR("color_bad");
-                        outwalk += sprintf(outwalk, "%s", "ERROR");
-                        goto print_end;
-                }
-
-                if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) {
-                        START_COLOR("color_bad");
-                        outwalk += sprintf(outwalk, "%s", "CONNECT ERROR");
-                        mpd_connection_free(conn);
-                        conn = NULL;
-                        goto print_end;
-                }
-
-                if (password != NULL && strcmp(password, "") != 0 &&
-                                !mpd_run_password(conn, password)) {
-                        START_COLOR("color_bad");
-                        outwalk += sprintf(outwalk, "%s", "PASS ERROR");
-                        mpd_connection_free(conn);
-                        conn = NULL;
-                        goto print_end;
-                }
+            START_COLOR("color_bad");
+            outwalk += sprintf(outwalk, "%s", "ERROR");
+            goto print_end;
         }

-        if ((status = mpd_run_status(conn))) {
-                state = mpd_status_get_state(status);
+        if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) {
+            START_COLOR("color_bad");
+            outwalk += sprintf(outwalk, "%s", "CONNECT ERROR");
+            mpd_connection_free(conn);
+            conn = NULL;
+            goto print_end;
         }

-        if (!status || (state != MPD_STATE_PLAY && state != MPD_STATE_PAUSE)) {
-                START_COLOR("color_bad");
-                outwalk += sprintf(outwalk, "%s", "Stopped");
-                mpd_connection_free(conn);
-                conn = NULL;
-                goto print_end;
+        if (password != NULL && strcmp(password, "") != 0 &&
+            !mpd_run_password(conn, password)) {
+            START_COLOR("color_bad");
+            outwalk += sprintf(outwalk, "%s", "PASS ERROR");
+            mpd_connection_free(conn);
+            conn = NULL;
+            goto print_end;
+        }
+    }
+
+    if ((status = mpd_run_status(conn))) {
+        state = mpd_status_get_state(status);
+    }
+
+    if (!status || (state != MPD_STATE_PLAY && state != MPD_STATE_PAUSE)) {
+        START_COLOR("color_bad");
+        outwalk += sprintf(outwalk, "%s", "Stopped");
+        mpd_connection_free(conn);
+        conn = NULL;
+        goto print_end;
+    }
+
+    mpd_status_free(status);
+
+    if (state == MPD_STATE_PLAY)
+        START_COLOR("color_good");
+    else if (state == MPD_STATE_PAUSE)
+        START_COLOR("color_degraded");
+
+    song = mpd_run_current_song(conn);
+
+    COPY_CROP(titlebuf, mpd_song_get_tag(song, MPD_TAG_TITLE, 0));
+    COPY_CROP(artistbuf, mpd_song_get_tag(song, MPD_TAG_ARTIST, 0));
+    COPY_CROP(albumbuf, mpd_song_get_tag(song, MPD_TAG_ALBUM, 0));
+    COPY_CROP(trackbuf, mpd_song_get_tag(song, MPD_TAG_TRACK, 0));
+    COPY_CROP(datebuf, mpd_song_get_tag(song, MPD_TAG_DATE, 0));
+
+    mpd_song_free(song);
+
+    for (walk = format; *walk != '\0'; walk++) {
+        if (*walk != '%') {
+            *(outwalk++) = *walk;
+            continue;
         }

-        mpd_status_free(status);
-
-        if (state == MPD_STATE_PLAY)
-                START_COLOR("color_good");
-        else if (state == MPD_STATE_PAUSE)
-                START_COLOR("color_degraded");
-
-        song = mpd_run_current_song(conn);
-
-        COPY_CROP(titlebuf, mpd_song_get_tag(song, MPD_TAG_TITLE, 0));
-        COPY_CROP(artistbuf, mpd_song_get_tag(song, MPD_TAG_ARTIST, 0));
-        COPY_CROP(albumbuf, mpd_song_get_tag(song, MPD_TAG_ALBUM, 0));
-        COPY_CROP(trackbuf, mpd_song_get_tag(song, MPD_TAG_TRACK, 0));
-        COPY_CROP(datebuf, mpd_song_get_tag(song, MPD_TAG_DATE, 0));
-
-        mpd_song_free(song);
-
-        for (walk = format; *walk != '\0'; walk++) {
-                if (*walk != '%') {
-                        *(outwalk++) = *walk;
-                        continue;
-                }
-
-                if (BEGINS_WITH(walk+1, "title")) {
-                        if (*titlebuf)
-                                outwalk += sprintf(outwalk, "%s", titlebuf);
-                        walk += strlen("title");
-                }
-                else if (BEGINS_WITH(walk+1, "artist")) {
-                        if (*artistbuf)
-                                outwalk += sprintf(outwalk, "%s", artistbuf);
-                        walk += strlen("artist");
-                }
-                else if (BEGINS_WITH(walk+1, "album")) {
-                        if (*albumbuf)
-                                outwalk += sprintf(outwalk, "%s", albumbuf);
-                        walk += strlen("album");
-                }
-                else if (BEGINS_WITH(walk+1, "track")) {
-                        if (*trackbuf)
-                                outwalk += sprintf(outwalk, "%s", trackbuf);
-                        walk += strlen("track");
-                }
-                else if (BEGINS_WITH(walk+1, "date")) {
-                        if (*datebuf)
-                                outwalk += sprintf(outwalk, "%s", datebuf);
-                        walk += strlen("date");
-                }
+        if (BEGINS_WITH(walk + 1, "title")) {
+            if (*titlebuf)
+                outwalk += sprintf(outwalk, "%s", titlebuf);
+            walk += strlen("title");
+        } else if (BEGINS_WITH(walk + 1, "artist")) {
+            if (*artistbuf)
+                outwalk += sprintf(outwalk, "%s", artistbuf);
+            walk += strlen("artist");
+        } else if (BEGINS_WITH(walk + 1, "album")) {
+            if (*albumbuf)
+                outwalk += sprintf(outwalk, "%s", albumbuf);
+            walk += strlen("album");
+        } else if (BEGINS_WITH(walk + 1, "track")) {
+            if (*trackbuf)
+                outwalk += sprintf(outwalk, "%s", trackbuf);
+            walk += strlen("track");
+        } else if (BEGINS_WITH(walk + 1, "date")) {
+            if (*datebuf)
+                outwalk += sprintf(outwalk, "%s", datebuf);
+            walk += strlen("date");
         }
+    }

 print_end:

-        END_COLOR;
-        OUTPUT_FULL_TEXT(buffer);
+    END_COLOR;
+    OUTPUT_FULL_TEXT(buffer);

-        return;
+    return;
 }


set an XML id for the decoration tag

set an XML id for the decoration tag

--- src/processor.c
+++ src/processor.c
@@ -633,12 +633,22 @@
 embed_decorate(pool_t pool, istream_t istream, const struct widget *widget)
 {
     growing_buffer_t tag;
+    const char *prefix;

     assert(istream != NULL);
     assert(!istream_has_handler(istream));

     tag = growing_buffer_new(pool, 256);
-    growing_buffer_write_string(tag, "<div class='embed' style='overflow:auto; margin:5pt; border:1px dotted red;");
+    growing_buffer_write_string(tag, "
width != NULL) {
         growing_buffer_write_string(tag, "width:");


always call PyEval_InitThreads

always call PyEval_InitThreads


* novice.

  * novice.

git-svn-id: 7e42957eae6452db79c3ea1a6279e527418ba1c8@2418 1a406e8e-add9-4483-a2c8-d8cac5b7c224


Forgotten header file

Forgotten header file

error: pathspec 'pipeline/cpipeline.h' did not match any file(s) known to git

--- pipeline/cpipeline.h
+++ pipeline/cpipeline.h
@@ -0,0 +1,38 @@
+#pragma once
+
+#include <Python.h>
+
+
+typedef struct {
+  PyObject_HEAD
+#ifdef PIPELINE_OPAQUE
+  PyObject* ready;
+#else
+  void* (*ready)(PyObject*, void*);
+  void* ready_closure;
+#endif
+  PyObject* task_done;
+  PyObject* queue[10];
+  size_t queue_start;
+  size_t queue_end;
+} Pipeline;
+
+
+#define PIPELINE_EMPTY(p) (p)->queue_start == (p)->queue_end
+
+#ifndef PIPELINE_OPAQUE
+PyObject*
+Pipeline_new(Pipeline* self);
+
+void
+Pipeline_dealloc(Pipeline* self);
+
+int
+Pipeline_init(Pipeline* self, void* (*ready)(PyObject*, void*), void* closure);
+
+PyObject*
+Pipeline_queue(Pipeline* self, PyObject* task);
+
+void*
+cpipeline_init(void);
+#endif


Remove case sensitivity bug with channel for 'replace'

--- src/commands.c
+++ src/commands.c
@@ -1291,6 +1291,7 @@
 		struct _SeenDB *SeenRecord = NULL;
 		char Message[4096], OutBuf[4096];
 		char H[2][2048] = { "", "" };
+		char Chan[128];

 		if (!*Argument)
 		{
@@ -1303,6 +1304,12 @@
 			IRC_Message(SendTo, "This command only works in a channel.");
 			return;
 		}
+
+		for (Inc = 0; Inc < sizeof Chan - 1 && SendTo[Inc] != '\0'; ++Inc)
+		{ /*We need a lowercase channel name.*/
+			Chan[Inc] = tolower(SendTo[Inc]);
+		}
+		Chan[Inc] = '\0';

 		for (Inc = 0; Inc < sizeof TargetUser - 1 && TW[Inc] != ' ' && TW[Inc] != '\0'; ++Inc)
 		{ /*Get the target user of the replace.*/
@@ -1343,7 +1350,7 @@
 			return;
 		}

-		if (strcmp(SeenRecord->Channel, SendTo) != 0)
+		if (strcmp(SeenRecord->Channel, Chan) != 0)
 		{ /*Wrong channel.*/
 			IRC_Message(SendTo, "User's last speech was not in this channel. Cannot replace.");
 			return;


unittests: Add success / error message

unittests: Add success / error message


bounds/ray-intersects: extract duplicated loop

--- bounds/ray-intersects.98.c
+++ bounds/ray-intersects.98.c
@@ -4,6 +4,8 @@

 #include <assert.h>

+static void check_one_axis(mushcoords, mushcoords, const mushbounds*,
+                           mushcell, mushcell, mushdim, bool*, mushucell*);
 static bool matches(mushucell, mushcell, mushcell, mushcell, mushcell);
 static void get_hittable_range(mushcell, mushcell, mushcell,
                                mushcell*, mushcell*);
@@ -198,43 +200,12 @@
          // and thus we'd be using method 2 instead.
          assert (!(a == MUSHCELL_MIN && b == MUSHCELL_MAX));

-         // For each coordinate that we might hit (being careful in case b ==
-         // MUSHCELL_MAX)...
-         for (mushcell p = a; p <= b && p >= a; p = mushcell_inc(p)) {
-            // ... figure out the move counts that hit it which would also be
-            // improvements to best_move_count.
-            mushucell moves, increment;
-
-            const mushucell n = get_move_count(
-               o.v[i], p, delta.v[i],
-               &moves, &increment, got_move_count ? &best_move_count : NULL);
-
-            // For each of the plausible move counts, in order...
-            for (mushucell c = 0; c < n; ++c) {
-               mushucell m = moves + c*increment;
-
-               // ... make sure that along the other axes, with the same number
-               // of moves, we fall within the box.
-               for (mushdim j = 0; j < MUSHSPACE_DIM; ++j) if (i != j)
-                  if (!matches(m, beg->v[j], end->v[j], o.v[j], delta.v[j]))
-                     goto next_move_count_1;
-
-               // If we did fall within the box, we have a better solution for
-               // the whole ray, and we can move to the next point. (Since
-               // get_move_count guarantees that any later m's for this point
-               // would be greater.)
-               best_move_count = m;
-               got_move_count  = true;
-               break;
-next_move_count_1:;
-            }
-         }
+         check_one_axis(o, delta, bounds, a, b, i,
+                        &got_move_count, &best_move_count);
       }
    } else {
 method2:
-      // Method 2: check all points along a selected axis. Practically
-      // identical to the point-loop in method 1: see the comments there for
-      // more info.
+      // Method 2: check all points along a selected axis.

       // If we aborted method selection early, our selected axis might have a
       // zero delta: rectify that.
@@ -243,28 +214,8 @@
          do ++axis2; while (!delta.v[axis2]);
       }

-      const mushcell b = beg->v[axis2], e = end->v[axis2];
-
-      for (mushcell p = b; p <= e && p >= b; p = mushcell_inc(p)) {
-         mushucell moves, increment;
-
-         const mushucell n = get_move_count(
-            o.v[axis2], p, delta.v[axis2],
-            &moves, &increment, got_move_count ? &best_move_count : NULL);
-
-         for (mushucell c = 0; c < n; ++c) {
-            mushucell m = moves + c*increment;
-
-            for (mushdim j = 0; j < MUSHSPACE_DIM; ++j) if (axis2 != j)
-               if (!matches(m, beg->v[j], end->v[j], o.v[j], delta.v[j]))
-                  goto next_move_count_2;
-
-            best_move_count = m;
-            got_move_count  = true;
-            break;
-next_move_count_2:;
-         }
-      }
+      check_one_axis(o, delta, bounds, beg->v[axis2], end->v[axis2], axis2,
+                     &got_move_count, &best_move_count);
    }
    if (!got_move_count)
       return false;
@@ -273,6 +224,46 @@
    *phit_pos    = mushcoords_add(o, mushcoords_muls(delta, best_move_count));
    assert (mushbounds_contains(bounds, *phit_pos));
    return true;
+}
+
+static void check_one_axis(
+   mushcoords o, mushcoords delta, const mushbounds* bounds,
+   mushcell a, mushcell b, mushdim axis,
+   bool* got_move_count, mushucell* best_move_count)
+{
+   const mushcoords *beg = &bounds->beg, *end = &bounds->end;
+
+   // For each coordinate that we might hit (being careful in case b ==
+   // MUSHCELL_MAX)...
+   for (mushcell p = a; p <= b && p >= a; p = mushcell_inc(p)) {
+      // ... figure out the move counts that hit it which would also be
+      // improvements to best_move_count.
+      mushucell moves, increment;
+
+      const mushucell n = get_move_count(
+         o.v[axis], p, delta.v[axis],
+         &moves, &increment, *got_move_count ? best_move_count : NULL);
+
+      // For each of the plausible move counts, in order...
+      for (mushucell c = 0; c < n; ++c) {
+         const mushucell m = moves + c*increment;
+
+         // ... make sure that along the other axes, with the same number of
+         // moves, we fall within the box.
+         for (mushdim i = 0; i < MUSHSPACE_DIM; ++i) if (i != axis)
+            if (!matches(m, beg->v[i], end->v[i], o.v[i], delta.v[i]))
+               goto next_move_count;
+
+         // If we did fall within the box, we have a better solution for
+         // the whole ray, and we can move to the next point. (Since
+         // get_move_count guarantees that any later m's for this point
+         // would be greater.)
+         *best_move_count = m;
+         *got_move_count  = true;
+         break;
+next_move_count:;
+      }
+   }
 }

 static bool matches(


A little more progress, also don't remap stderr

--- src/filter-runner/filter-runner.c
+++ src/filter-runner/filter-runner.c
@@ -33,6 +33,11 @@
   void *data;
 };

+struct ohandle {
+  FILE *in;
+  FILE *out;
+};
+
 static void assert_result(int result) {
   if (result == -1) {
     perror("error");
@@ -40,13 +45,13 @@
   }
 }

-static int get_size_or_die(FILE *in, FILE *err) {
+static int get_size_or_die(FILE *in) {
   char *line = NULL;
   size_t n;
   int result;

   if (getline(&line, &n, in) == -1) {
-    fprintf(err, "Can't read size\n");
+    fprintf(stderr, "Can't read size\n");
     exit(EXIT_FAILURE);
   }

@@ -59,12 +64,12 @@

   free(line);

-  fprintf(err, "size: %d\n", result);
+  fprintf(stderr, "size: %d\n", result);
   return result;
 }

-static char *get_string_or_die(FILE *in, FILE *err) {
-  int size = get_size_or_die(in, err);
+static char *get_string_or_die(FILE *in) {
+  int size = get_size_or_die(in);

   if (size == -1) {
     return NULL;
@@ -74,7 +79,7 @@
   result[size] = '\0';

   if (fread(result, size, 1, in) != 1) {
-    fprintf(err, "Can't read string\n");
+    fprintf(stderr, "Can't read string\n");
     exit(EXIT_FAILURE);
   }

@@ -84,11 +89,11 @@
   return result;
 }

-static char **get_strings_or_die(FILE *in, FILE *err) {
+static char **get_strings_or_die(FILE *in) {
   GSList *list = NULL;

   char *str;
-  while ((str = get_string_or_die(in, err)) != NULL) {
+  while ((str = get_string_or_die(in)) != NULL) {
     list = g_slist_prepend(list, str);
   }

@@ -108,8 +113,8 @@
   return result;
 }

-static void *get_blob_or_die(FILE *in, FILE *err, int *bloblen_OUT) {
-  int size = get_size_or_die(in, err);
+static void *get_blob_or_die(FILE *in, int *bloblen_OUT) {
+  int size = get_size_or_die(in);
   *bloblen_OUT = size;

   uint8_t *blob;
@@ -120,7 +125,7 @@
     blob = g_malloc(size);

     if (fread(blob, size, 1, in) != 1) {
-      fprintf(err, "Can't read blob\n");
+      fprintf(stderr, "Can't read blob\n");
       exit(EXIT_FAILURE);
     }
   }
@@ -131,22 +136,18 @@
   return blob;
 }

-static void init_file_descriptors(int *stdin_orig, int *stdout_orig, int *stderr_orig,
-				  int *stdout_log, int *stderr_log) {
+static void init_file_descriptors(int *stdin_orig, int *stdout_orig,
+				  int *stdout_log) {
   int stdout_pipe[2];
-  int stderr_pipe[2];
-
-  // save orig stdin/stdout/stderr
+
+  // save orig stdin/stdout
   *stdin_orig = dup(0);
   assert_result(*stdin_orig);
   *stdout_orig = dup(1);
   assert_result(*stdout_orig);
-  *stderr_orig = dup(2);
-  assert_result(*stderr_orig);

   // make pipes
   assert_result(pipe(stdout_pipe));
-  assert_result(pipe(stderr_pipe));

   // open /dev/null to stdin
   int devnull = open("/dev/null", O_RDONLY);
@@ -154,53 +155,50 @@
   assert_result(dup2(devnull, 0));
   assert_result(close(devnull));

-  // dup to stdout/stderr
+  // dup to stdout
   assert_result(dup2(stdout_pipe[1], 1));
   assert_result(close(stdout_pipe[1]));
-  assert_result(dup2(stderr_pipe[1], 2));
-  assert_result(close(stderr_pipe[1]));

   // save
   *stdout_log = stdout_pipe[0];
-  *stderr_log = stderr_pipe[0];
-}
-
-static void init_filter(FILE *in, FILE *err, struct filter_ops *ops) {
+}
+
+static void init_filter(FILE *in, struct filter_ops *ops) {
   char *error;

   // read shared object name
-  char *filename = get_string_or_die(in, err);
-  fprintf(err, "filename: %s\n", filename);
+  char *filename = get_string_or_die(in);
+  fprintf(stderr, "filename: %s\n", filename);

   // read init function name
-  char *init_name = get_string_or_die(in, err);
-  fprintf(err, "init_name: %s\n", init_name);
+  char *init_name = get_string_or_die(in);
+  fprintf(stderr, "init_name: %s\n", init_name);

   // read eval function name
-  char *eval_name = get_string_or_die(in, err);
-  fprintf(err, "eval_name: %s\n", eval_name);
+  char *eval_name = get_string_or_die(in);
+  fprintf(stderr, "eval_name: %s\n", eval_name);

   // read fini function name
-  char *fini_name = get_string_or_die(in, err);
-  fprintf(err, "fini_name: %s\n", fini_name);
+  char *fini_name = get_string_or_die(in);
+  fprintf(stderr, "fini_name: %s\n", fini_name);

   // read argument list
-  char **args = get_strings_or_die(in, err);
-  fprintf(err, "args len: %d\n", g_strv_length(args));
+  char **args = get_strings_or_die(in);
+  fprintf(stderr, "args len: %d\n", g_strv_length(args));

   // read name
-  char *filter_name = get_string_or_die(in, err);
-  fprintf(err, "filter_name: %s\n", filter_name);
+  char *filter_name = get_string_or_die(in);
+  fprintf(stderr, "filter_name: %s\n", filter_name);

   // read blob
   int bloblen;
-  uint8_t *blob = get_blob_or_die(in, err, &bloblen);
-  fprintf(err, "bloblen: %d\n", bloblen);
+  uint8_t *blob = get_blob_or_die(in, &bloblen);
+  fprintf(stderr, "bloblen: %d\n", bloblen);

   // dlopen
   void *handle = dlopen(filename, RTLD_LAZY | RTLD_LOCAL);
   if (!handle) {
-    fprintf(err, "%s\n", dlerror());
+    fprintf(stderr, "%s\n", dlerror());
     exit(EXIT_FAILURE);
   }

@@ -210,7 +208,7 @@
 		     void **filter_args);
   *(void **) (&filter_init) = dlsym(handle, init_name);
   if ((error = dlerror()) != NULL) {
-    fprintf(err, "%s\n", error);
+    fprintf(stderr, "%s\n", error);
     exit(EXIT_FAILURE);
   }

@@ -218,21 +216,21 @@
 			      bloblen, blob,
 			      filter_name, &ops->data);
   if (result != 0) {
-    fprintf(err, "filter init failed\n");
-    exit(EXIT_FAILURE);
-  }
-  fprintf(err, "filter init success\n");
+    fprintf(stderr, "filter init failed\n");
+    exit(EXIT_FAILURE);
+  }
+  fprintf(stderr, "filter init success\n");

   // save
   *(void **) (&ops->eval) = dlsym(handle, eval_name);
   if ((error = dlerror()) != NULL) {
-    fprintf(err, "%s\n", error);
+    fprintf(stderr, "%s\n", error);
     exit(EXIT_FAILURE);
   }

   *(void **) (&ops->fini) = dlsym(handle, fini_name);
   if ((error = dlerror()) != NULL) {
-    fprintf(err, "%s\n", error);
+    fprintf(stderr, "%s\n", error);
     exit(EXIT_FAILURE);
   }

@@ -249,111 +247,90 @@

 struct logger_data {
   FILE *out;
-  FILE *err;
   int stdout_log;
-  int stderr_log;
 };

-
-static void write_log_message(const char *tag, int fd, FILE *out, FILE *err) {
-  ssize_t size;
-  uint8_t buf[BUFSIZ];
-
-  // read from fd
-  size = read(fd, buf, BUFSIZ);
-  if (size <= 0) {
-    fprintf(err, "Can't read\n");
-    exit(EXIT_FAILURE);
-  }
-
-  // print it
-  g_static_mutex_lock(&out_mutex);
-  if (fprintf(out, "%s\n%d\n", tag, size) == -1) {
-    fprintf(err, "Can't write\n");
-    exit(EXIT_FAILURE);
-  }
-  if (fwrite(buf, size, 1, out) != 1) {
-    fprintf(err, "Can't write\n");
-    exit(EXIT_FAILURE);
-  }
-  if (fprintf(out, "\n") == -1) {
-    fprintf(err, "Can't write\n");
-    exit(EXIT_FAILURE);
-  }
-  g_static_mutex_unlock(&out_mutex);
-}

 static gpointer logger(gpointer data) {
   struct logger_data *l = data;

   FILE *out = l->out;
-  FILE *err = l->err;
   int stdout_log = l->stdout_log;
-  int stderr_log = l->stderr_log;

   // block signals
   sigset_t set;
   sigfillset(&set);
   pthread_sigmask(SIG_SETMASK, &set, NULL);

-  fprintf(err, "Logger thread is ready\n");
+  fprintf(stderr, "Logger thread is ready\n");

   // go
   while (true) {
-    fd_set rfds;
-    FD_ZERO(&rfds);
-    FD_SET(stdout_log, &rfds);
-    FD_SET(stderr_log, &rfds);
-
-    int val = select(MAX(stdout_log, stderr_log) + 1, &rfds, NULL, NULL, NULL);
-
-    if (val == -1 && errno == EINTR) {
-      continue;
-    } else if (val == -1) {
-      exit(EXIT_FAILURE);
-    }
-
-    if (FD_ISSET(stdout_log, &rfds)) {
-      write_log_message("log-stdout", stdout_log, out, err);
-    }
-    if (FD_ISSET(stderr_log, &rfds)) {
-      write_log_message("log-stderr", stderr_log, out, err);
-    }
+    ssize_t size;
+    uint8_t buf[BUFSIZ];
+
+    // read from fd
+    size = read(stdout_log, buf, BUFSIZ);
+    if (size <= 0) {
+      fprintf(stderr, "Can't read\n");
+      exit(EXIT_FAILURE);
+    }
+
+    // print it
+    g_static_mutex_lock(&out_mutex);
+    if (fprintf(out, "stdout\n%d\n", size) == -1) {
+      perror("Can't write");
+      exit(EXIT_FAILURE);
+    }
+    if (fwrite(buf, size, 1, out) != 1) {
+      perror("Can't write");
+      exit(EXIT_FAILURE);
+    }
+    if (fprintf(out, "\n") == -1) {
+      perror("Can't write");
+      exit(EXIT_FAILURE);
+    }
+    g_static_mutex_unlock(&out_mutex);
   }

   return NULL;
 }

+
+static void send_result(FILE *out, int result) {
+
+}
+
+
 static void run_filter(struct filter_ops *ops,
-		       int stdin_orig, int stdout_orig, int stderr_orig,
-		       int stdout_log, int stderr_log) {
+		       int stdin_orig, int stdout_orig,
+		       int stdout_log) {
   // make files
-  FILE *err = fdopen(stderr_orig, "w");
-  if (!err) {
-    exit(EXIT_FAILURE);
-  }
-  setbuf(err, NULL);
-
   FILE *in = fdopen(stdin_orig, "r");
   if (!in) {
-    fprintf(err, "%s\n", strerror(errno));
+    fprintf(stderr, "%s\n", strerror(errno));
     exit(EXIT_FAILURE);
   }
   FILE *out = fdopen(stdout_orig, "w");
   if (!out) {
-    fprintf(err, "%s\n", strerror(errno));
+    fprintf(stderr, "%s\n", strerror(errno));
     exit(EXIT_FAILURE);
   }

   // start logging thread
-  struct logger_data data = { out, err, stdout_log, stderr_log };
+  struct logger_data data = { out, stdout_log };
   if (g_thread_create(logger, &data, false, NULL) == NULL) {
-    fprintf(err, "Can't create logger thread\n");
-    exit(EXIT_FAILURE);
-  }
+    fprintf(stderr, "Can't create logger thread\n");
+    exit(EXIT_FAILURE);
+  }
+
+  struct ohandle ohandle = { in, out };

   while (true) {
-
+    // eval and return result
+    int result = (*ops->eval)(&ohandle, ops->data);
+
+    send_result(out, result);
   }
 }

@@ -364,19 +341,17 @@

   int stdin_orig;
   int stdout_orig;
-  int stderr_orig;

   int stdout_log;
-  int stderr_log;

   if (!g_thread_supported ()) g_thread_init (NULL);

-  init_filter(stdin, stderr, &ops);
-  init_file_descriptors(&stdin_orig, &stdout_orig, &stderr_orig,
-			&stdout_log, &stderr_log);
+  init_filter(stdin, &ops);
+  init_file_descriptors(&stdin_orig, &stdout_orig,
+			&stdout_log);
   run_filter(&ops,
-	     stdin_orig, stdout_orig, stderr_orig,
-	     stdout_log, stderr_log);
+	     stdin_orig, stdout_orig,
+	     stdout_log);

   return EXIT_SUCCESS;
 }


fix problems with using 3D and video playback

--- src/psb_accel.c
+++ src/psb_accel.c
@@ -308,6 +308,14 @@
 }
 #endif

+static void*
+psbExaCreatePixmap(ScreenPtr pScreen, int w, int h, int depth, int usage_hint, int bpp, int* new_pitch  )
+{
+	return NULL;
+}
+static void
+psbExaDestroyPixmap(ScreenPtr pScreen, void* driverPriv ){
+}
 static Bool
 psbExaPixmapIsOffscreen(PixmapPtr p)
 {
@@ -1313,6 +1321,7 @@
     pExa->pixmapOffsetAlign = 8;
     pExa->pixmapPitchAlign = 32 * 4;
     pExa->flags = EXA_OFFSCREEN_PIXMAPS;
+    pExa->flags |= EXA_HANDLES_PIXMAPS | EXA_MIXED_PIXMAPS;
     pExa->maxX = 2047;
     pExa->maxY = 2047;
     pExa->WaitMarker = psbExaWaitMarker;
@@ -1328,6 +1337,9 @@
     pExa->Composite = psbExaSuperComposite;
     pExa->DoneComposite = psbExaDoneComposite;
     pExa->PixmapIsOffscreen = psbExaPixmapIsOffscreen;
+	pExa->CreatePixmap = NULL;
+	pExa->CreatePixmap2 = psbExaCreatePixmap;
+	pExa->DestroyPixmap = psbExaDestroyPixmap;
     pExa->PrepareAccess = psbExaPrepareAccess;
     pExa->FinishAccess = psbExaFinishAccess;
     pExa->UploadToScreen = psbExaUploadToScreen;


publickey_list_free: no return value from a void function

Fixed a compiler warning I introduced previously when checking input
arguments more. I also added a check for the other pointer to avoid NULL
pointer dereferences.

--- src/publickey.c
+++ src/publickey.c
@@ -999,8 +999,8 @@
     LIBSSH2_SESSION *session;
     libssh2_publickey_list *p = pkey_list;

-    if(!pkey)
-        return LIBSSH2_ERROR_BAD_USE;
+    if(!pkey || !p)
+        return;

     session = pkey->channel->session;


new redis-cli command connect

new redis-cli command connect

--- src/redis-cli.c
+++ src/redis-cli.c
@@ -273,6 +273,11 @@
     size_t *argvlen;
     int j;

+    if (context == NULL) {
+        printf("Not connected, please use: connect <host> <port>\n");
+        return REDIS_OK;
+    }
+
     config.raw_output = !strcasecmp(command,"info");
     if (!strcasecmp(command,"help")) {
         showInteractiveHelp();
@@ -319,7 +324,8 @@
         int lastarg = i==argc-1;

         if (!strcmp(argv[i],"-h") && !lastarg) {
-            config.hostip = argv[i+1];
+            sdsfree(config.hostip);
+            config.hostip = sdsnew(argv[i+1]);
             i++;
         } else if (!strcmp(argv[i],"-h") && lastarg) {
             usage();
@@ -419,14 +425,16 @@
                     strcasecmp(argv[0],"exit") == 0)
                 {
                     exit(0);
+                } else if (argc == 3 && !strcasecmp(argv[0],"connect")) {
+                    sdsfree(config.hostip);
+                    config.hostip = sdsnew(argv[1]);
+                    config.hostport = atoi(argv[2]);
+                    cliConnect(1);
                 } else {
                     long long start_time = mstime(), elapsed;

                     if (cliSendCommand(argc,argv,1) != REDIS_OK) {
-                        printf("Reconnecting... ");
-                        fflush(stdout);
-                        if (cliConnect(1) != REDIS_OK) exit(1);
-                        printf("OK\n");
+                        cliConnect(1);

                         /* If we still cannot send the command,
                          * print error and abort. */
@@ -466,7 +474,7 @@
 int main(int argc, char **argv) {
     int firstarg;

-    config.hostip = "127.0.0.1";
+    config.hostip = sdsnew("127.0.0.1");
     config.hostport = 6379;
     config.hostsocket = NULL;
     config.repeat = 1;


Fix redis-cli memory leak when sending set preference command.

--- src/redis-cli.c
+++ src/redis-cli.c
@@ -1412,6 +1412,8 @@
                     exit(0);
                 } else if (argv[0][0] == ':') {
                     cliSetPreferences(argv,argc,1);
+                    sdsfreesplitres(argv,argc);
+                    linenoiseFree(line);
                     continue;
                 } else if (strcasecmp(argv[0],"restart") == 0) {
                     if (config.eval) {


Fix SharedPtr::reset

Fix SharedPtr::reset

SharedPtr::reset did not actually set the stored pointer value.
Correct this, with other minor tidies:

* Ensure counter is set to NULL if pointer is reset to NULL
* Be consistent about not clearing pointers in decrement_counter().

--- platform/SharedPtr.h
+++ platform/SharedPtr.h
@@ -145,10 +145,13 @@
         // Clean up by decrementing counter
         decrement_counter();

+        _ptr = ptr;
         if (ptr != NULL) {
             // Allocate counter on the heap, so it can be shared
             _counter = new uint32_t;
             *_counter = 1;
+        } else {
+            _counter = NULL;
         }
     }

@@ -226,6 +229,8 @@
     /**
      * @brief Decrement reference counter.
      * @details If count reaches zero, free counter and delete object pointed to.
+     * Does not modify our own pointers - assumption is they will be overwritten
+     * or destroyed immediately afterwards.
      */
     void decrement_counter()
     {
@@ -233,9 +238,7 @@
             uint32_t new_value = core_util_atomic_decr_u32(_counter, 1);
             if (new_value == 0) {
                 delete _counter;
-                _counter = NULL;
                 delete _ptr;
-                _ptr = NULL;
             }
         }
     }


redis-cli: save an RDB dump from remote server to local file.

--- src/redis-cli.c
+++ src/redis-cli.c
@@ -41,6 +41,7 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <assert.h>
+#include <fcntl.h>

 #include "hiredis.h"
 #include "sds.h"
@@ -73,6 +74,8 @@
     int cluster_reissue_command;
     int slave_mode;
     int pipe_mode;
+    int getrdb_mode;
+    char *rdb_filename;
     int bigkeys;
     int stdinarg; /* get last arg from stdin. (-x option) */
     char *auth;
@@ -660,6 +663,9 @@
             config.latency_mode = 1;
         } else if (!strcmp(argv[i],"--slave")) {
             config.slave_mode = 1;
+        } else if (!strcmp(argv[i],"--rdb") && !lastarg) {
+            config.getrdb_mode = 1;
+            config.rdb_filename = argv[++i];
         } else if (!strcmp(argv[i],"--pipe")) {
             config.pipe_mode = 1;
         } else if (!strcmp(argv[i],"--bigkeys")) {
@@ -720,6 +726,7 @@
 "  --raw            Use raw formatting for replies (default when STDOUT is not a tty)\n"
 "  --latency        Enter a special mode continuously sampling latency\n"
 "  --slave          Simulate a slave showing commands received from the master\n"
+"  --rdb <filename> Transfer an RDB dump from remote server to local file.\n"
 "  --pipe           Transfer raw Redis protocol from stdin to server\n"
 "  --bigkeys        Sample Redis keys looking for big keys\n"
 "  --eval <file>    Send an EVAL command using the Lua script at <file>\n"
@@ -927,15 +934,15 @@
     }
 }

-static void slaveMode(void) {
+/* Sends SYNC and reads the number of bytes in the payload. Used both by
+ * slaveMode() and getRDB(). */
+unsigned long long sendSync(int fd) {
     /* To start we need to send the SYNC command and return the payload.
      * The hiredis client lib does not understand this part of the protocol
      * and we don't want to mess with its buffers, so everything is performed
      * using direct low-level I/O. */
-    int fd = context->fd;
-    char buf[1024], *p;
+    char buf[4096], *p;
     ssize_t nread;
-    unsigned long long payload;

     /* Send the SYNC command. */
     if (write(fd,"SYNC\r\n",6) != 6) {
@@ -955,12 +962,25 @@
         p++;
     }
     *p = '\0';
-    payload = strtoull(buf+1,NULL,10);
-    fprintf(stderr,"SYNC with master, discarding %lld bytes of bulk tranfer...\n",
-            payload);
+    if (buf[0] == '-') {
+        printf("SYNC with master failed: %s\n", buf);
+        exit(1);
+    }
+    return strtoull(buf+1,NULL,10);
+}
+
+static void slaveMode(void) {
+    int fd = context->fd;
+    unsigned long long payload = sendSync(fd);
+    char buf[1024];
+
+    fprintf(stderr,"SYNC with master, discarding %llu "
+                   "bytes of bulk tranfer...\n", payload);

     /* Discard the payload. */
     while(payload) {
+        ssize_t nread;
+
         nread = read(fd,buf,(payload > sizeof(buf)) ? sizeof(buf) : payload);
         if (nread <= 0) {
             fprintf(stderr,"Error reading RDB payload while SYNCing\n");
@@ -970,9 +990,54 @@
     }
     fprintf(stderr,"SYNC done. Logging commands from master.\n");

-    /* Now we can use the hiredis to read the incoming protocol. */
+    /* Now we can use hiredis to read the incoming protocol. */
     config.output = OUTPUT_CSV;
     while (cliReadReply(0) == REDIS_OK);
+}
+
+/* This function implements --rdb, so it uses the replication protocol in order
+ * to fetch the RDB file from a remote server. */
+static void getRDB(void) {
+    int s = context->fd;
+    int fd;
+    unsigned long long payload = sendSync(s);
+    char buf[4096];
+
+    fprintf(stderr,"SYNC sent to master, writing %llu bytes to '%s'\n",
+        payload, config.rdb_filename);
+
+    /* Write to file. */
+    if (!strcmp(config.rdb_filename,"-")) {
+        fd = STDOUT_FILENO;
+    } else {
+        fd = open(config.rdb_filename, O_CREAT|O_WRONLY, 0644);
+        if (fd == -1) {
+            fprintf(stderr, "Error opening '%s': %s\n", config.rdb_filename,
+                strerror(errno));
+            exit(1);
+        }
+    }
+
+    while(payload) {
+        ssize_t nread, nwritten;
+
+        nread = read(s,buf,(payload > sizeof(buf)) ? sizeof(buf) : payload);
+        if (nread <= 0) {
+            fprintf(stderr,"I/O Error reading RDB payload from socket\n");
+            exit(1);
+        }
+        nwritten = write(fd, buf, nread);
+        if (nwritten != nread) {
+            fprintf(stderr,"Error writing data to file: %s\n",
+                strerror(errno));
+            exit(1);
+        }
+        payload -= nread;
+    }
+    close(s); /* Close the file descriptor ASAP as fsync() may take time. */
+    fsync(fd);
+    fprintf(stderr,"Transfer finished with success.\n");
+    exit(0);
 }

 static void pipeMode(void) {
@@ -1203,6 +1268,8 @@
     config.latency_mode = 0;
     config.cluster_mode = 0;
     config.slave_mode = 0;
+    config.getrdb_mode = 0;
+    config.rdb_filename = NULL;
     config.pipe_mode = 0;
     config.bigkeys = 0;
     config.stdinarg = 0;
@@ -1231,6 +1298,12 @@
         slaveMode();
     }

+    /* Get RDB mode. */
+    if (config.getrdb_mode) {
+        cliConnect(0);
+        getRDB();
+    }
+
     /* Pipe mode */
     if (config.pipe_mode) {
         if (cliConnect(0) == REDIS_ERR) exit(1);


redis-cli --stat, stolen from redis-tools.

Redis-tools is a connection of tools no longer mantained that was
intented as a way to economically make sense of Redis in the pre-vmware
sponsorship era. However there was a nice redis-stat utility, this
commit imports one of the functionalities of this tool here in redis-cli
as it seems to be pretty useful.

Usage: redis-cli --stat

The output is similar to vmstat in the format, but with Redis specific
stuff of course.

From the point of view of the monitored instance, only INFO is used in
order to grab data.

--- src/redis-cli.c
+++ src/redis-cli.c
@@ -42,6 +42,7 @@
 #include <sys/time.h>
 #include <assert.h>
 #include <fcntl.h>
+#include <limits.h>

 #include "hiredis.h"
 #include "sds.h"
@@ -76,6 +77,7 @@
     int slave_mode;
     int pipe_mode;
     int getrdb_mode;
+    int stat_mode;
     char *rdb_filename;
     int bigkeys;
     int stdinarg; /* get last arg from stdin. (-x option) */
@@ -630,6 +632,36 @@
     return REDIS_OK;
 }

+/* Send the INFO command, reconnecting the link if needed. */
+static redisReply *reconnectingInfo(void) {
+    redisContext *c = context;
+    redisReply *reply = NULL;
+    int tries = 0;
+
+    assert(!c->err);
+    while(reply == NULL) {
+        while (c->err & (REDIS_ERR_IO | REDIS_ERR_EOF)) {
+            printf("Reconnecting (%d)...\r", ++tries);
+            fflush(stdout);
+
+            redisFree(c);
+            c = redisConnect(config.hostip,config.hostport);
+            usleep(1000000);
+        }
+
+        reply = redisCommand(c,"INFO");
+        if (c->err && !(c->err & (REDIS_ERR_IO | REDIS_ERR_EOF))) {
+            fprintf(stderr, "Error: %s\n", c->errstr);
+            exit(1);
+        } else if (tries > 0) {
+            printf("\n");
+        }
+    }
+
+    context = c;
+    return reply;
+}
+
 /*------------------------------------------------------------------------------
  * User interface
  *--------------------------------------------------------------------------- */
@@ -670,6 +702,8 @@
             config.latency_mode = 1;
         } else if (!strcmp(argv[i],"--slave")) {
             config.slave_mode = 1;
+        } else if (!strcmp(argv[i],"--stat")) {
+            config.stat_mode = 1;
         } else if (!strcmp(argv[i],"--rdb") && !lastarg) {
             config.getrdb_mode = 1;
             config.rdb_filename = argv[++i];
@@ -1265,6 +1299,145 @@
     }
 }

+/* Return the specified INFO field from the INFO command output "info".
+ * A new buffer is allocated for the result, that needs to be free'd.
+ * If the field is not found NULL is returned. */
+static char *getInfoField(char *info, char *field) {
+    char *p = strstr(info,field);
+    char *n1, *n2;
+    char *result;
+
+    if (!p) return NULL;
+    p += strlen(field)+1;
+    n1 = strchr(p,'\r');
+    n2 = strchr(p,',');
+    if (n2 && n2 < n1) n1 = n2;
+    result = malloc(sizeof(char)*(n1-p)+1);
+    memcpy(result,p,(n1-p));
+    result[n1-p] = '\0';
+    return result;
+}
+
+/* Like the above function but automatically convert the result into
+ * a long. On error (missing field) LONG_MIN is returned. */
+static long getLongInfoField(char *info, char *field) {
+    char *value = getInfoField(info,field);
+    long l;
+
+    if (!value) return LONG_MIN;
+    l = strtol(value,NULL,10);
+    free(value);
+    return l;
+}
+
+/* Convert number of bytes into a human readable string of the form:
+ * 100B, 2G, 100M, 4K, and so forth. */
+void bytesToHuman(char *s, long long n) {
+    double d;
+
+    if (n < 0) {
+        *s = '-';
+        s++;
+        n = -n;
+    }
+    if (n < 1024) {
+        /* Bytes */
+        sprintf(s,"%lluB",n);
+        return;
+    } else if (n < (1024*1024)) {
+        d = (double)n/(1024);
+        sprintf(s,"%.2fK",d);
+    } else if (n < (1024LL*1024*1024)) {
+        d = (double)n/(1024*1024);
+        sprintf(s,"%.2fM",d);
+    } else if (n < (1024LL*1024*1024*1024)) {
+        d = (double)n/(1024LL*1024*1024);
+        sprintf(s,"%.2fG",d);
+    }
+}
+
+static void statMode() {
+    redisReply *reply;
+    long aux, requests = 0;
+    int i = 0;
+
+    while(1) {
+        char buf[64];
+        int j;
+
+        reply = reconnectingInfo();
+        if (reply->type == REDIS_REPLY_ERROR) {
+            printf("ERROR: %s\n", reply->str);
+            exit(1);
+        }
+
+        if ((i++ % 20) == 0) {
+            printf(
+"------- data ------ --------------------- load -------------------- - child -\n"
+"keys       mem      clients blocked requests            connections          \n");
+        }
+
+        /* Keys */
+        aux = 0;
+        for (j = 0; j < 20; j++) {
+            long k;
+
+            sprintf(buf,"db%d:keys",j);
+            k = getLongInfoField(reply->str,buf);
+            if (k == LONG_MIN) continue;
+            aux += k;
+        }
+        sprintf(buf,"%ld",aux);
+        printf("%-11s",buf);
+
+        /* Used memory */
+        aux = getLongInfoField(reply->str,"used_memory");
+        bytesToHuman(buf,aux);
+        printf("%-8s",buf);
+
+        /* Clients */
+        aux = getLongInfoField(reply->str,"connected_clients");
+        sprintf(buf,"%ld",aux);
+        printf(" %-8s",buf);
+
+        /* Blocked (BLPOPPING) Clients */
+        aux = getLongInfoField(reply->str,"blocked_clients");
+        sprintf(buf,"%ld",aux);
+        printf("%-8s",buf);
+
+        /* Requets */
+        aux = getLongInfoField(reply->str,"total_commands_processed");
+        sprintf(buf,"%ld (+%ld)",aux,requests == 0 ? 0 : aux-requests);
+        printf("%-19s",buf);
+        requests = aux;
+
+        /* Connections */
+        aux = getLongInfoField(reply->str,"total_connections_received");
+        sprintf(buf,"%ld",aux);
+        printf(" %-12s",buf);
+
+        /* Children */
+        aux = getLongInfoField(reply->str,"bgsave_in_progress");
+        aux |= getLongInfoField(reply->str,"aof_rewrite_in_progress") << 1;
+        switch(aux) {
+        case 0: break;
+        case 1:
+            printf("SAVE");
+            break;
+        case 2:
+            printf("AOF");
+            break;
+        case 3:
+            printf("SAVE+AOF");
+            break;
+        }
+
+        printf("\n");
+        freeReplyObject(reply);
+        usleep(config.interval);
+    }
+}
+
 int main(int argc, char **argv) {
     int firstarg;

@@ -1329,6 +1502,13 @@
         findBigKeys();
     }

+    /* Stat mode */
+    if (config.stat_mode) {
+        if (cliConnect(0) == REDIS_ERR) exit(1);
+        if (config.interval == 0) config.interval = 1000000;
+        statMode();
+    }
+
     /* Start interactive mode when no command is provided */
     if (argc == 0 && !config.eval) {
         /* Note that in repl mode we don't abort on connection error.


kmshttpendpoint: Fix macro definition

kmshttpendpoint: Fix macro definition

Change-Id: Ie4f7bf8747cadcbbefce5a3a3ea998c4170dac44

--- src/gst-plugins/kmshttpendpoint.h
+++ src/gst-plugins/kmshttpendpoint.h
@@ -13,7 +13,7 @@
  *
  */
 #ifndef _KMS_HTTP_ENDPOINT_H_
-#define _KMS_HTTP_ENDPOINT_H
+#define _KMS_HTTP_ENDPOINT_H_

 #include <commons/kmselement.h>


minor error in debug printouts

minor error in debug printouts

--- common/vtkSetGet.h
+++ common/vtkSetGet.h
@@ -136,7 +136,7 @@
 #define vtkSetObjectMacro(name,type) \
 void Set##name (type* _arg) \
   { \
-  if (Debug)   cerr << "Debug: In " __FILE__ << ", line " << __LINE__ << "\n" << this->GetClassName() << " (" << this << "): setting " << #name " to " << &_arg << "\n\n"; \
+  if (Debug)   cerr << "Debug: In " __FILE__ << ", line " << __LINE__ << "\n" << this->GetClassName() << " (" << this << "): setting " << #name " to " << _arg << "\n\n"; \
   if (name != _arg) \
     { \
     name = _arg; \
@@ -155,7 +155,7 @@
 #define vtkSetRefCountedObjectMacro(name,type) \
 void Set##name (type* _arg) \
   { \
-  if (Debug)   cerr << "Debug: In " __FILE__ << ", line " << __LINE__ << "\n" << this->GetClassName() << " (" << this << "): setting " << #name " to " << &_arg << "\n\n"; \
+  if (Debug)   cerr << "Debug: In " __FILE__ << ", line " << __LINE__ << "\n" << this->GetClassName() << " (" << this << "): setting " << #name " to " << _arg << "\n\n"; \
   if (name != _arg) \
     { \
     if (name != NULL) name->UnRegister(this); \


adding PatternMatch_Shell

adding PatternMatch_Shell

--- package/dscript.shell/shell_glue.c
+++ package/dscript.shell/shell_glue.c
@@ -173,6 +173,36 @@
 	RETURNb_(ret);
 }

+
+static KMETHOD PatternMatch_Shell(KonohaContext *kctx, KonohaStack *sfp)
+{
+	VAR_PatternMatch(stmt, nameid, tokenList, beginIdx, endIdx);
+	kToken *firstToken = tokenList->tokenItems[beginIdx];
+	DBG_P("firstToken='%s', isCommand=%d", S_text(firstToken->text), isCommand(S_text(firstToken->text)));
+	RETURNi_((firstToken->resolvedSyntaxInfo->keyword == KW_SymbolPattern && isCommand(S_text(firstToken->text))) ? 0 : -1);
+}
+
+static KMETHOD Statement_Shell(KonohaContext *kctx, KonohaStack *sfp)
+{
+	VAR_Statement(stmt, gma);
+	kTokenArray *tokenList = (kTokenArray *)kStmt_getObjectNULL(kctx, stmt, KW_TokenPattern);
+	if(tokenList != NULL) {
+		kString *cmd = NULL;
+		if(IS_Token(tokenList)) {
+			cmd = ((kToken*)tokenList)->text;
+		}
+		else {
+			DBG_ASSERT(IS_Array(tokenList));
+			cmd = splitWhiteSpace(kctx, tokenList);  // forget GC
+			PUSH_GCSTACK(cmd);
+		}
+		DBG_P("cmd=%s", S_text(cmd));
+		system(S_text(cmd));
+		kStmt_done(kctx, stmt);
+	}
+	RETURNb_(false);
+}
+
 // ----------------------------------------------------------------------------
 /* define class */

@@ -182,7 +212,7 @@
 	KImportPackage(ns, "dscript.subproc", pline);
 	KDEFINE_SYNTAX SYNTAX[] = {
 		{ SYM_("dsh"), 0, "\"dsh\" $Token*", 0, 0, NULL, NULL, Statement_dsh, Statement_dsh, NULL, },
-	//	{ SYM_("$Shell"), 0, "$Shell $Token*", 0, 0, PatternMatch_Shell, NULL, Statement_Shell, Statement_Shell},
+		{ SYM_("$Shell"), 0, "$Shell $Token*", 0, 0, PatternMatch_Shell, NULL, Statement_Shell, Statement_Shell},
 		{ KW_END, },
 	};
 	SUGAR kNameSpace_defineSyntax(kctx, ns, SYNTAX, packageNameSpace);


Report $SYS/broker/uptime in same format as rsmb.

--- src/database.c
+++ src/database.c
@@ -1607,7 +1607,7 @@
 	if(interval && now - interval > last_update){
 		_mqtt3_db_transaction_begin();

-		snprintf(buf, 100, "%d", (int)(now - start_time));
+		snprintf(buf, 100, "%d seconds", (int)(now - start_time));
 		mqtt3_db_messages_queue("$SYS/broker/uptime", 2, strlen(buf), (uint8_t *)buf, 1);

 		if(!mqtt3_db_message_count(&count)){


sockmax==NULL is a failure condition in mqtt3_db_outgoing_check().


filelist: Do not print error when a correct filelist file is specified

--- src/filelist.c
+++ src/filelist.c
@@ -523,6 +523,7 @@
 	FILE *fp;
 	gib_list *list = NULL;
 	char s[1024], s1[1024];
+	Imlib_Load_Error err = IMLIB_LOAD_ERROR_NONE;
 	Imlib_Image tmp_im;
 	struct stat st;
 	signed short tmp_magick_timeout;
@@ -535,12 +536,15 @@
 	 */
 	tmp_magick_timeout = opt.magick_timeout;
 	opt.magick_timeout = -1;
-	if (!stat(filename, &st) && S_ISREG(st.st_mode) &&
-			feh_load_image_char(&tmp_im, filename)) {
-		weprintf("Filelist file %s is an image, refusing to use it.\n"
-			"Did you mix up -f and -F?", filename);
-		opt.filelistfile = NULL;
-		return NULL;
+	if (!stat(filename, &st) && S_ISREG(st.st_mode)) {
+		tmp_im = imlib_load_image_with_error_return(filename, &err);
+		if (err == IMLIB_LOAD_ERROR_NONE) {
+			gib_imlib_free_image_and_decache(tmp_im);
+			weprintf("Filelist file %s is an image, refusing to use it.\n"
+				"Did you mix up -f and -F?", filename);
+			opt.filelistfile = NULL;
+			return NULL;
+		}
 	}
 	opt.magick_timeout = tmp_magick_timeout;


HEVC/dec: Fix weight/offset in HCP_WEIGHTOFFSET

Signed-off-by: Xiang, Haihao <8d677183e5993577d4fa73a419b76987913292d6@intel.com>

--- src/gen9_mfd.c
+++ src/gen9_mfd.c
@@ -649,8 +649,8 @@
     for (i = 0; i < 16; i++) {
         if (i < MIN((num_ref_minus1 + 1), 15)) {
             OUT_BCS_BATCH(batch,
-                          luma_offset[i] << 8 |
-                          delta_luma_weight[i]);
+                          (luma_offset[i] & 0xff) << 8 |
+                          (delta_luma_weight[i] & 0xff));
         } else {
             OUT_BCS_BATCH(batch, 0);
         }
@@ -658,10 +658,10 @@
     for (i = 0; i < 16; i++) {
         if (i < MIN((num_ref_minus1 + 1), 15)) {
             OUT_BCS_BATCH(batch,
-                          chroma_offset[i][1] << 24 |
-                          delta_chroma_weight[i][1] << 16 |
-                          chroma_offset[i][0] << 8 |
-                          delta_chroma_weight[i][0]);
+                          (chroma_offset[i][1] & 0xff) << 24 |
+                          (delta_chroma_weight[i][1] & 0xff) << 16 |
+                          (chroma_offset[i][0] & 0xff) << 8 |
+                          (delta_chroma_weight[i][0] & 0xff));
         } else {
             OUT_BCS_BATCH(batch, 0);
         }


Simplify generator (2), add 'addsd' to generator

The decoder still handles 'addsd' as pass-through

--- src/generate.c
+++ src/generate.c
@@ -39,6 +39,11 @@
     OpSegOverride so;
     uint8_t b[10];    // partly generated machine code
     int blen;         // valid bytes in b
+
+    int32_t opc;
+    OperandEncoding oe;
+    ValType vt;
+    int flags;
 };

 static
@@ -290,6 +295,27 @@
     return o;
 }

+// append bytes for opcode and operands
+static
+int appendOO(GContext* c, int o, int opc)
+{
+    uint8_t* buf = c->buf;
+    if (opc > 255) {
+        assert(opc < 65536);
+        buf[o++] = (uint8_t) (opc >> 8);
+        buf[o++] = (uint8_t) (opc & 255);
+    }
+    else
+        buf[o++] = (uint8_t) opc;
+
+    // append bytes for encoded operands
+    for(int i=0; i < c->blen; i++)
+        buf[o++] = c->b[i];
+
+    return o;
+}
+
+
 // flags for genModRM/genDigitRM
 #define GEN_66OnVT16  1

@@ -299,10 +325,9 @@
 // automatically generate REX prefix depending on operand types.
 // Returns byte length of generated instruction.
 static
-int genModRM(GContext* c, int opc, int opc2,
+int genModRM(GContext* c, int opc,
              Operand* o1, Operand* o2, ValType vt, int flags)
 {
-    uint8_t* buf = c->buf;
     int o = 0;

     calcModRM(c, o1, o2);
@@ -311,28 +336,22 @@
     if ((vt == VT_Implicit) && ((c->ps & PS_REXW) == 0)) c->rex &= ~REX_MASK_W;
     if ((flags & GEN_66OnVT16) && (opValType(o1) == VT_16)) c->ps |= PS_66;
     o = genPrefix(c);
-    buf[o++] = (uint8_t) opc;
-    if (opc2 >=0)
-        buf[o++] = (uint8_t) opc2;
-    for(int i=0; i < c->blen; i++)
-        buf[o++] = c->b[i];
+    o = appendOO(c, o, opc);

     return o;
 }

 // Operand o1: r/m
 static
-int genDigitRM(GContext* c, int opc, int digit, Operand* o1, int flags)
-{
-    uint8_t* buf = c->buf;
+int genDigitRM(GContext* c, int opc,
+               int digit, Operand* o1, int flags)
+{
     int o;

     calcModRMDigit(c, o1, digit);
     if ((flags & GEN_66OnVT16) && (opValType(o1) == VT_16)) c->ps |= PS_66;
     o = genPrefix(c);
-    buf[o++] = (uint8_t) opc;
-    for(int i=0; i < c->blen; i++)
-        buf[o++] = c->b[i];
+    o = appendOO(c, o, opc);

     return o;
 }
@@ -370,7 +389,7 @@

 // Operand o1: r/m, o2: r, o3: imm
 static
-int genModRMI(GContext* c, int opc, int opc2,
+int genModRMI(GContext* c, int opc,
               Operand* o1, Operand* o2, Operand* o3, int flags)
 {
     uint8_t* buf = c->buf;
@@ -379,19 +398,15 @@
     calcModRM(c, o1, o2);
     if ((flags & GEN_66OnVT16) && (opValType(o1) == VT_16)) c->ps |= PS_66;
     o = genPrefix(c);
-    buf[o++] = (uint8_t) opc;
-    if (opc2 >=0)
-        buf[o++] = (uint8_t) opc2;
-    for(int i=0; i < c->blen; i++)
-        buf[o++] = c->b[i];
+    o = appendOO(c, o, opc);

     return appendI(buf, o, o3);
 }

 // Operand o1: r/m, o2: imm
 static
-int genDigitMI(GContext* c, int opc, int digit,
-               Operand* o1, Operand* o2, int flags)
+int genDigitMI(GContext* c, int opc,
+               int digit, Operand* o1, Operand* o2, int flags)
 {
     uint8_t* buf = c->buf;
     int o;
@@ -400,9 +415,7 @@
     calcModRMDigit(c, o1, digit);
     if ((flags & GEN_66OnVT16) && (opValType(o1) == VT_16)) c->ps |= PS_66;
     o = genPrefix(c);
-    buf[o++] = (uint8_t) opc;
-    for(int i=0; i < c->blen; i++)
-        buf[o++] = c->b[i];
+    o = appendOO(c, o, opc);

     return appendI(buf, o, o2);
 }
@@ -422,9 +435,39 @@
     if (opValType(o1) == VT_64) c->rex |= REX_MASK_W;
     if ((flags & GEN_66OnVT16) && (opValType(o1) == VT_16)) c->ps |= PS_66;
     o = genPrefix(c);
-    buf[o++] = (uint8_t) (opc + (r & 7));
+    assert((opc < 256) && ((opc&7)==0));
+    o = appendOO(c, o, opc + (r & 7));
     return appendI(buf, o, o2);
 }
+
+
+// almost generic generator, using data from GContext
+static
+int genInstr(GContext* c)
+{
+    Instr* i = c->instr;
+    ValType vt = c->vt;
+    int flags = c->flags;
+    int opc = c->opc;
+
+    switch(c->oe) {
+    case OE_MR: return genModRM(c, opc, &(i->dst), &(i->src), vt, flags);
+    case OE_RM: return genModRM(c, opc, &(i->src), &(i->dst), vt, flags);
+    default: break;
+    }
+    return 0;
+}
+
+static
+void setGenInfo(GContext* c,
+                PrefixSet ps, int opc, OperandEncoding oe, ValType vt)
+{
+    c->ps = ps;
+    c->oe = oe;
+    c->vt = vt;
+    c->opc = opc;
+}
+

 // if imm64 and value fitting into imm32, return imm32 version
 // otherwise, or if operand is not imm, just return the original
@@ -611,14 +654,14 @@
                 copyOperand(&eSrc, src);
                 eSrc.type = (src->type == OT_Reg32) ? OT_Reg64 : OT_Ind64;
                 // use 'movsx r64,r/m 32' (0x63)
-                return genModRM(cxt, 0x63, -1, &eSrc, dst, VT_None, 0);
+                return genModRM(cxt, 0x63, &eSrc, dst, VT_None, 0);
             }
             // fall through for regular 'mov r,r' with same operand sizes
         case OT_Ind32:
         case OT_Ind64:
             if (opValType(src) != opValType(dst)) return -1;
             // use 'mov r/m,r 32/64' (0x89 MR)
-            return genModRM(cxt, 0x89, -1, dst, src, VT_None, 0);
+            return genModRM(cxt, 0x89, dst, src, VT_None, 0);

         default: return -1;
         }
@@ -631,7 +674,7 @@
         case OT_Reg64:
             if (opValType(src) == opValType(dst)) {
                 // use 'mov r,r/m 32/64' (0x8B RM)
-                return genModRM(cxt, 0x8B, -1, src, dst, VT_None, 0);
+                return genModRM(cxt, 0x8B, src, dst, VT_None, 0);
             }
             else if ((opValType(src) == VT_32) &&
                      (opValType(dst) == VT_64)) {
@@ -639,7 +682,7 @@
                 copyOperand(&eSrc, src);
                 eSrc.type = (src->type == OT_Reg32) ? OT_Reg64 : OT_Ind64;
                 // use 'movsx r64,r/m 32' (0x63)
-                return genModRM(cxt, 0x63, -1, &eSrc, dst, VT_None, 0);
+                return genModRM(cxt, 0x63, &eSrc, dst, VT_None, 0);
             }
             break;

@@ -658,7 +701,7 @@
         case OT_Reg64:
             if (src->val == 0) {
                 // setting to 0: use 'xor r/m,r 32/64' (0x31 MR)
-                return genModRM(cxt, 0x31, -1, dst, dst, VT_None, 0);
+                return genModRM(cxt, 0x31, dst, dst, VT_None, 0);
             }
             // use 'mov r/m 32/64, imm32' (0xC7/0)
             return genDigitMI(cxt, 0xC7, 0, dst, src, 0);
@@ -673,7 +716,7 @@
         case OT_Reg64:
             if (src->val == 0) {
                 // setting to 0: use 'xor r/m,r 32/64' (0x31 MR)
-                return genModRM(cxt, 0x31, -1, dst, dst, VT_None, 0);
+                return genModRM(cxt, 0x31, dst, dst, VT_None, 0);
             }
             // use 'mov r64,imm64' (REX.W + 0xB8)
             return genOI(cxt, 0xB8, dst, src, 0);
@@ -726,7 +769,7 @@
             default: assert(0);
             }
             // use 'cmov r,r/m 32/64' (opc RM)
-            return genModRM(cxt, opc, -1, src, dst, VT_None, 0);
+            return genModRM(cxt, opc, src, dst, VT_None, 0);
             break;

         default: return -1;
@@ -764,12 +807,12 @@
         case OT_Ind32:
         case OT_Ind64:
             // use 'add r/m,r 32/64' (0x01 MR)
-            return genModRM(cxt, 0x01, -1, dst, src, VT_None, GEN_66OnVT16);
+            return genModRM(cxt, 0x01, dst, src, VT_None, GEN_66OnVT16);

         case OT_Reg8:
         case OT_Ind8:
             // use 'add r/m,r 8' (0x00 MR)
-            return genModRM(cxt, 0x00, -1, dst, src, VT_None, 0);
+            return genModRM(cxt, 0x00, dst, src, VT_None, 0);

         default: return -1;
         }
@@ -783,13 +826,13 @@
         switch(dst->type) {
         case OT_Reg8:
             // use 'add r,r/m 8' (0x02 RM)
-            return genModRM(cxt, 0x02, -1, src, dst, VT_None, 0);
+            return genModRM(cxt, 0x02, src, dst, VT_None, 0);

         case OT_Reg16:
         case OT_Reg32:
         case OT_Reg64:
             // use 'add r,r/m 16/32/64' (0x03 RM)
-            return genModRM(cxt, 0x03, -1, src, dst, VT_None, GEN_66OnVT16);
+            return genModRM(cxt, 0x03, src, dst, VT_None, GEN_66OnVT16);

         default: return -1;
         }
@@ -890,7 +933,7 @@
         case OT_Ind32:
         case OT_Ind64:
             // use 'sub r/m,r 32/64' (0x29 MR)
-            return genModRM(cxt, 0x29, -1, dst, src, VT_None, 0);
+            return genModRM(cxt, 0x29, dst, src, VT_None, 0);

         default: return -1;
         }
@@ -904,7 +947,7 @@
         case OT_Reg32:
         case OT_Reg64:
             // use 'sub r,r/m 32/64' (0x2B RM)
-            return genModRM(cxt, 0x2B, -1, src, dst, VT_None, 0);
+            return genModRM(cxt, 0x2B, src, dst, VT_None, 0);

         default: return -1;
         }
@@ -966,12 +1009,12 @@
         case OT_Ind32:
         case OT_Ind64:
             // use 'test r/m,r 16/32/64' (0x85 MR)
-            return genModRM(cxt, 0x85, -1, dst, src, VT_None, GEN_66OnVT16);
+            return genModRM(cxt, 0x85, dst, src, VT_None, GEN_66OnVT16);

         case OT_Reg8:
         case OT_Ind8:
             // use 'test r/m,r 8' (0x84 MR)
-            return genModRM(cxt, 0x84, -1, dst, src, VT_None, 0);
+            return genModRM(cxt, 0x84, dst, src, VT_None, 0);

         default: return -1;
         }
@@ -1061,7 +1104,7 @@
         case OT_Reg32:
         case OT_Reg64:
             // use 'imul r,r/m 32/64' (0x0F 0xAF RM)
-            return genModRM(cxt, 0x0F, 0xAF, src, dst, VT_None, 0);
+            return genModRM(cxt, 0x0FAF, src, dst, VT_None, 0);

         default: return -1;
         }
@@ -1072,7 +1115,7 @@
         case OT_Reg32:
         case OT_Reg64:
             // use 'imul r,r/m 32/64,imm8' (0x6B/r RMI)
-            return genModRMI(cxt, 0x6B, -1, dst, dst, src, 0);
+            return genModRMI(cxt, 0x6B, dst, dst, src, 0);

         default: return -1;
         }
@@ -1084,7 +1127,7 @@
         case OT_Reg32:
         case OT_Reg64:
             // use 'imul r,r/m 32/64,imm32' (0x69/r RMI)
-            return genModRMI(cxt, 0x69, -1, dst, dst, src, 0);
+            return genModRMI(cxt, 0x69, dst, dst, src, 0);

         default: return -1;
         }
@@ -1135,7 +1178,7 @@
         case OT_Reg64:
         case OT_Ind64:
             // use 'xor r/m,r 32/64' (0x31 MR)
-            return genModRM(cxt, 0x31, -1, dst, src, VT_None, 0);
+            return genModRM(cxt, 0x31, dst, src, VT_None, 0);

         default: return -1;
         }
@@ -1149,7 +1192,7 @@
         case OT_Reg32:
         case OT_Reg64:
             // use 'xor r,r/m 32/64' (0x33 RM)
-            return genModRM(cxt, 0x33, -1, src, dst, VT_None, 0);
+            return genModRM(cxt, 0x33, src, dst, VT_None, 0);

         default: return -1;
         }
@@ -1209,7 +1252,7 @@
         case OT_Reg64:
         case OT_Ind64:
             // use 'or r/m,r 32/64' (0x09 MR)
-            return genModRM(cxt, 0x09, -1, dst, src, VT_None, 0);
+            return genModRM(cxt, 0x09, dst, src, VT_None, 0);

         default: return -1;
         }
@@ -1223,7 +1266,7 @@
         case OT_Reg32:
         case OT_Reg64:
             // use 'or r,r/m 32/64' (0x0B RM)
-            return genModRM(cxt, 0x0B, -1, src, dst, VT_None, 0);
+            return genModRM(cxt, 0x0B, src, dst, VT_None, 0);

         default: return -1;
         }
@@ -1288,12 +1331,12 @@
         case OT_Ind32:
         case OT_Ind64:
             // use 'and r/m,r 16/32/64' (0x21 MR)
-            return genModRM(cxt, 0x21, -1, dst, src, VT_None, GEN_66OnVT16);
+            return genModRM(cxt, 0x21, dst, src, VT_None, GEN_66OnVT16);

         case OT_Reg8:
         case OT_Ind8:
             // use 'and r/m,r 8' (0x20 MR)
-            return genModRM(cxt, 0x20, -1, dst, src, VT_None, 0);
+            return genModRM(cxt, 0x20, dst, src, VT_None, 0);

         default: return -1;
         }
@@ -1308,13 +1351,13 @@
         switch(dst->type) {
         case OT_Reg8:
             // use 'and r,r/m 8' (0x22 RM)
-            return genModRM(cxt, 0x22, -1, src, dst, VT_None, 0);
+            return genModRM(cxt, 0x22, src, dst, VT_None, 0);

         case OT_Reg16:
         case OT_Reg32:
         case OT_Reg64:
             // use 'and r,r/m 32/64' (0x23 RM)
-            return genModRM(cxt, 0x23, -1, src, dst, VT_None, GEN_66OnVT16);
+            return genModRM(cxt, 0x23, src, dst, VT_None, GEN_66OnVT16);

         default: return -1;
         }
@@ -1486,7 +1529,7 @@
     case OT_Reg32:
     case OT_Reg64:
         // use 'lea r/m,r 32/64' (0x8d)
-        return genModRM(cxt, 0x8d, -1, src, dst, VT_None, 0);
+        return genModRM(cxt, 0x8d, src, dst, VT_None, 0);

     default: return -1;
     }
@@ -1544,7 +1587,7 @@
         case OT_Reg64:
         case OT_Ind64:
             // use 'cmp r/m,r 32/64' (0x39 MR)
-            return genModRM(cxt, 0x39, -1, dst, src, VT_None, 0);
+            return genModRM(cxt, 0x39, dst, src, VT_None, 0);

         default: return -1;
         }
@@ -1559,7 +1602,7 @@
         case OT_Reg32:
         case OT_Reg64:
             // use 'cmp r,r/m 32/64' (0x3B RM)
-            return genModRM(cxt, 0x3B, -1, src, dst, VT_None, 0);
+            return genModRM(cxt, 0x3B, src, dst, VT_None, 0);

         default: return -1;
         }
@@ -1605,23 +1648,24 @@
 {
     Instr* instr = cxt->instr;
     ValType vt = instr->vtype;
-    int o = 0;
+    int o = 0, opc;

     assert(instr->ptLen > 0);
     cxt->ps = instr->ptPSet;

-    if (instr->ptLen < 2) instr->ptOpc[1] = -1;
     assert(instr->ptLen < 3);
+    if (instr->ptLen < 2)
+        opc = instr->ptOpc[0];
+    else
+        opc = (instr->ptOpc[0] << 8) | instr->ptOpc[1];

     switch(instr->ptEnc) {
     case OE_MR:
-        o += genModRM(cxt, instr->ptOpc[0], instr->ptOpc[1],
-                &(instr->dst), &(instr->src), vt, 0);
+        o += genModRM(cxt, opc, &(instr->dst), &(instr->src), vt, 0);
         break;

     case OE_RM:
-        o += genModRM(cxt, instr->ptOpc[0], instr->ptOpc[1],
-                &(instr->src), &(instr->dst), vt, 0);
+        o += genModRM(cxt, opc, &(instr->src), &(instr->dst), vt, 0);
         break;

     default: assert(0);
@@ -1640,6 +1684,11 @@
     c->so = OSO_None;
     c->ps = PS_No;
     c->blen = 0;
+
+    c->opc = -1;
+    c->oe = OE_Invalid;
+    c->flags = 0;
+    c->vt = VT_None;
 }

 // generate code for a captured BB
@@ -1767,6 +1816,12 @@
             case IT_TEST:
                 used = genTest(&cxt);
                 break;
+
+            case IT_ADDSS:
+                setGenInfo(&cxt, PS_F3, 0x0F58, OE_RM, VT_Implicit);
+                genInstr(&cxt);
+                break;
+
             case IT_HINT_CALL:
             case IT_HINT_RET:
                 break;


Add normalize_sender parameter to the greylister.

Signed-off-by: Florent Bruneau <5d0958454f46908a14eb42e25abfc486c9e7cb2c@polytechnique.org>

--- postlicyd/greylist.c
+++ postlicyd/greylist.c
@@ -48,6 +48,7 @@
     unsigned lookup_by_host : 1;
     unsigned no_sender      : 1;
     unsigned no_recipient   : 1;
+    unsigned normalize_sender: 1;
     int delay;
     int retry_window;
     int client_awl;
@@ -63,6 +64,7 @@
 #define GREYLIST_INIT { .lookup_by_host = false,       \
                         .no_sender = false,            \
                         .no_recipient = false,         \
+                        .normalize_sender = true,      \
                         .delay = 300,                  \
                         .retry_window = 2 * 24 * 3600, \
                         .client_awl = 5,               \
@@ -298,8 +300,13 @@
     }
 }

-static const char *sender_normalize(const char *sender, char *buf, int len)
-{
+static const char *sender_normalize(const greylist_config_t * config,
+                                    const char *sender, char *buf, int len)
+{
+    if (!config->normalize_sender) {
+        return sender;
+    }
+
     const char *at = strchr(sender, '@');
     int rpos = 0, wpos = 0, userlen;

@@ -425,7 +432,7 @@
      */
     klen = snprintf(key, sizeof(key), "%s/%s/%s",
                     c_net(config, c_addr->str, c_name->str, cnet, sizeof(cnet)),
-                    config->no_sender ? "" : sender_normalize(sender->str, sbuf, sizeof(sbuf)),
+                    config->no_sender ? "" : sender_normalize(config, sender->str, sbuf, sizeof(sbuf)),
                     config->no_recipient ? "" : rcpt->str);
     klen = MIN(klen, ssizeof(key) - 1);

@@ -516,6 +523,7 @@
           FILTER_PARAM_PARSE_BOOLEAN(LOOKUP_BY_HOST, config->lookup_by_host);
           FILTER_PARAM_PARSE_BOOLEAN(NO_SENDER, config->no_sender);
           FILTER_PARAM_PARSE_BOOLEAN(NO_RECIPIENT, config->no_recipient);
+          FILTER_PARAM_PARSE_BOOLEAN(NORMALIZE_SENDER, config->normalize_sender);
           FILTER_PARAM_PARSE_INT(RETRY_WINDOW, config->retry_window);
           FILTER_PARAM_PARSE_INT(CLIENT_AWL,   config->client_awl);
           FILTER_PARAM_PARSE_INT(DELAY,        config->delay);
@@ -574,6 +582,7 @@
     /* Parameters.
      */
     (void)filter_param_register(type, "lookup_by_host");
+    (void)filter_param_register(type, "normalize_sender");
     (void)filter_param_register(type, "no_sender");
     (void)filter_param_register(type, "no_recipient");
     (void)filter_param_register(type, "delay");


USE THIS PATCH, not the one I just sent

USE THIS PATCH, not the one I just sent

(Logical change 1.738)

--- libsefs/fsdata.c
+++ libsefs/fsdata.c
@@ -1088,13 +1088,13 @@

 	if (request_type == SEFS_TYPES) {
 		sprintf(count_stmt,"SELECT count(*) from types");
-		sprintf(select_stmt,"SELECT type_name from types");
+		sprintf(select_stmt,"SELECT type_name from types order by type_name");
 	} else if (request_type == SEFS_USERS) {
 		sprintf(count_stmt,"SELECT count(*) from users");
-		sprintf(select_stmt,"SELECT user_name from users");
+		sprintf(select_stmt,"SELECT user_name from users order by user_name");
 	} else if (request_type == SEFS_PATHS) {
 		sprintf(count_stmt,"SELECT count(*) from paths");
-		sprintf(select_stmt,"SELECT path from paths");
+		sprintf(select_stmt,"SELECT path from paths order by path");
 	}

 	if (request_type != SEFS_OBJECTCLASS) {


Auto merged

Auto merged

2004/10/28 15:20:02-04:00 columbia!mowery
fixed repeat error

(Logical change 1.417)

--- libsefs/fsdata.c
+++ libsefs/fsdata.c
@@ -333,6 +333,7 @@
 			else if (errno == EACCES)
 			{
 				fprintf(stderr, "Access denied to link at %s\n", file);
+				errno = 0;
 			}
 			else
 			{


Improve the documentation of ssh_options_getopt().

git-svn-id: b1dee0d48e635e16c3b356ce77271b225d4db9f7@373 7dcaeef0-15fb-0310-b436-a5af3365683c

--- libssh/options.c
+++ libssh/options.c
@@ -796,19 +796,25 @@
   return 0;
 }
 /**
+ * @brief Parse command line arguments.
+ *
  * This is a helper for your application to generate the appropriate
  * options from the command line arguments.\n
- * the argv array and argc value are changed so that parsed
- * arguments won't appear anymore in them.\n
+ * The argv array and argc value are changed so that the parsed
+ * arguments wont appear anymore in them.\n
  * The single arguments (without switches) are not parsed. thus,
- * myssh -u aris localhost \n
- * command won't set the hostname value of options to localhost.
- * \brief parse command line arguments
- * \param options an empty option structure pointer
- * \param argcptr pointer to argument count
- * \param argv arguments list pointer
- * \returns 0 on success, -1 on error
- * \sa ssh_options_new()
+ * myssh -l user localhost\n
+ * The command wont set the hostname value of options to localhost.
+ *
+ * @param options       An empty option structure pointer.
+ *
+ * @param argcptr       The pointer to the argument count.
+ *
+ * @param argv          The arguments list pointer.
+ *
+ * @returns 0 on success, < 0 on error.
+ *
+ * @see ssh_options_new()
  */
 int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **argv) {
   char *user = NULL;


Bug 365997: updated PR_USPacificTimeParameters with the new US Daylight Saving Time rule.  By Nelson Bolyard of Sun Microsystems.  r=wtc.

--- pr/src/misc/prtime.c
+++ pr/src/misc/prtime.c
@@ -777,9 +777,53 @@
  *------------------------------------------------------------------------
  */

+/*
+ * Returns the mday of the first sunday of the month, where
+ * mday and wday are for a given day in the month.
+ * mdays start with 1 (e.g. 1..31).
+ * wdays start with 0 and are in the range 0..6.  0 = Sunday.
+ */
+#define firstSunday(mday, wday) (((mday - wday + 7 - 1) % 7) + 1)
+
+/*
+ * Returns the mday for the N'th Sunday of the month, where
+ * mday and wday are for a given day in the month.
+ * mdays start with 1 (e.g. 1..31).
+ * wdays start with 0 and are in the range 0..6.  0 = Sunday.
+ * N has the following values: 0 = first, 1 = second (etc), -1 = last.
+ * ndays is the number of days in that month, the same value as the
+ * mday of the last day of the month.
+ */
+static PRInt32
+NthSunday(PRInt32 mday, PRInt32 wday, PRInt32 N, PRInt32 ndays)
+{
+    PRInt32 firstSun = firstSunday(mday, wday);
+
+    if (N < 0)
+        N = (ndays - firstSun) / 7;
+    return firstSun + (7 * N);
+}
+
+typedef struct DSTParams {
+    PRInt8 dst_start_month;       /* 0 = January */
+    PRInt8 dst_start_Nth_Sunday;  /* N as defined above */
+    PRInt8 dst_start_month_ndays; /* ndays as defined above */
+    PRInt8 dst_end_month;         /* 0 = January */
+    PRInt8 dst_end_Nth_Sunday;    /* N as defined above */
+    PRInt8 dst_end_month_ndays;   /* ndays as defined above */
+} DSTParams;
+
+static const DSTParams dstParams[2] = {
+    /* year < 2007:  First April Sunday - Last October Sunday */
+    { 3, 0, 30, 9, -1, 31 },
+    /* year >= 2007: Second March Sunday - First November Sunday */
+    { 2, 1, 31, 10, 0, 30 }
+};
+
 PR_IMPLEMENT(PRTimeParameters)
 PR_USPacificTimeParameters(const PRExplodedTime *gmt)
 {
+    DSTParams * dst;
     PRTimeParameters retVal;
     PRExplodedTime st;

@@ -809,61 +853,51 @@
     /* Apply the offset to GMT to obtain the local standard time */
     ApplySecOffset(&st, retVal.tp_gmt_offset);

+    if (st.tm_year < 2007) { /* first April Sunday - Last October Sunday */
+	dst = &dstParams[0];
+    } else {                 /* Second March Sunday - First November Sunday */
+	dst = &dstParams[1];
+    }
+
     /*
      * Apply the rules on standard time or GMT to obtain daylight saving
      * time offset.  In this implementation, we use the US DST rule.
      */
-    if (st.tm_month < 3) {
+    if (st.tm_month < dst->dst_start_month) {
         retVal.tp_dst_offset = 0L;
-    } else if (st.tm_month == 3) {
-        if (st.tm_wday == 0) {
-            /* A Sunday */
-            if (st.tm_mday <= 7) {
-                /* First Sunday */
-                /* 01:59:59 PST -> 03:00:00 PDT */
-                if (st.tm_hour < 2) {
-                    retVal.tp_dst_offset = 0L;
-                } else {
-                    retVal.tp_dst_offset = 3600L;
-                }
-            } else {
-                /* Not first Sunday */
-                retVal.tp_dst_offset = 3600L;
-            }
-        } else {
-            /* Not a Sunday.  See if before first Sunday or after */
-            if (st.tm_wday + 1 <= st.tm_mday) {
-                /* After first Sunday */
-                retVal.tp_dst_offset = 3600L;
-            } else {
-                /* Before first Sunday */
-                retVal.tp_dst_offset = 0L;
-            }
+    } else if (st.tm_month == dst->dst_start_month) {
+	int NthSun = NthSunday(st.tm_mday, st.tm_wday,
+			       dst->dst_start_Nth_Sunday,
+			       dst->dst_start_month_ndays);
+	if (st.tm_mday < NthSun) {              /* Before starting Sunday */
+	    retVal.tp_dst_offset = 0L;
+        } else if (st.tm_mday == NthSun) {      /* Starting Sunday */
+	    /* 01:59:59 PST -> 03:00:00 PDT */
+	    if (st.tm_hour < 2) {
+		retVal.tp_dst_offset = 0L;
+	    } else {
+		retVal.tp_dst_offset = 3600L;
+	    }
+	} else {                                /* After starting Sunday */
+	    retVal.tp_dst_offset = 3600L;
         }
-    } else if (st.tm_month < 9) {
+    } else if (st.tm_month < dst->dst_end_month) {
         retVal.tp_dst_offset = 3600L;
-    } else if (st.tm_month == 9) {
-        if (st.tm_wday == 0) {
-            if (31 - st.tm_mday < 7) {
-                /* Last Sunday */
-                /* 01:59:59 PDT -> 01:00:00 PST */
-                if (st.tm_hour < 1) {
-                    retVal.tp_dst_offset = 3600L;
-                } else {
-                    retVal.tp_dst_offset = 0L;
-                }
-            } else {
-                /* Not last Sunday */
-                retVal.tp_dst_offset = 3600L;
-            }
-        } else {
-            /* See if before or after last Sunday */
-            if (7 - st.tm_wday <= 31 - st.tm_mday) {
-                /* before last Sunday */
-                retVal.tp_dst_offset = 3600L;
-            } else {
-                retVal.tp_dst_offset = 0L;
-            }
+    } else if (st.tm_month == dst->dst_end_month) {
+	int NthSun = NthSunday(st.tm_mday, st.tm_wday,
+			       dst->dst_end_Nth_Sunday,
+			       dst->dst_end_month_ndays);
+	if (st.tm_mday < NthSun) {              /* Before ending Sunday */
+	    retVal.tp_dst_offset = 3600L;
+        } else if (st.tm_mday == NthSun) {      /* Ending Sunday */
+	    /* 01:59:59 PDT -> 01:00:00 PST */
+	    if (st.tm_hour < 1) {
+		retVal.tp_dst_offset = 3600L;
+	    } else {
+		retVal.tp_dst_offset = 0L;
+	    }
+	} else {                                /* After ending Sunday */
+	    retVal.tp_dst_offset = 0L;
         }
     } else {
         retVal.tp_dst_offset = 0L;


fix uninitialized data

fix uninitialized data

--- src/test_libFLAC/metadata_manip.c
+++ src/test_libFLAC/metadata_manip.c
@@ -433,6 +433,9 @@
 	FLAC__StreamMetadata *block, *app, *padding;
 	FLAC__byte data[1000];
 	unsigned our_current_position = 0;
+
+	/* initialize 'data' to avoid Valgrind errors */
+	memset(data, 0, sizeof(data));

 	printf("\n\n++++++ testing level 1 interface\n");

@@ -1092,6 +1095,9 @@
 	FLAC__byte data[2000];
 	unsigned our_current_position;

+	/* initialize 'data' to avoid Valgrind errors */
+	memset(data, 0, sizeof(data));
+
 	printf("\n\n++++++ testing level 2 interface\n");

 	printf("generate read-only file\n");


fix typo: prestest -> pretest

fix typo: prestest -> pretest

--- src/rmbt_flow.c
+++ src/rmbt_flow.c
@@ -943,7 +943,7 @@
 	return read_ok_accept(s);
 }

-static inline bool do_prestest_uplink(State *s) {
+static inline bool do_pretest_uplink(State *s) {
 	return do_pretest(s, s->config->ul_pretest_duration_s, &s->targ->flow_result->pretest_ul, do_putchunks);
 }

@@ -1153,7 +1153,7 @@
 	set_phase(s, PH_pretest_ul);
 	my_log(s, "pretest uplink start... (min %" PRIuFAST16 "s)", s->config->ul_pretest_duration_s);
 	if (s->targ->do_uplink)
-		RETURN_IF_NOK(do_prestest_uplink(s));
+		RETURN_IF_NOK(do_pretest_uplink(s));
 	BARRIER;
 	my_log(s, "pretest uplink end.");


linux/kvm_base: fail nicely with VirtualBox is running

--- linux/kvm_base.c
+++ linux/kvm_base.c
@@ -261,6 +261,11 @@
     /* Create a VM */
     vmfd = ioctl(kvmfd, KVM_CREATE_VM, 0);
     if (vmfd < 0) {
+        if (errno == EBUSY) {
+            /* Fail nicely when there is someone else using the VM engine (eg. VirtualBox) */
+            printf("Something is preventing from creating new VMs (VirtualBox?), exiting.\n");
+            return 0;
+        }
         perror("ioctl(KVM_CREATE_VM)");
         return 1;
     }


removed unused ioctrl header

removed unused ioctrl header

--- pressanykey/ioctrl.h
+++ pressanykey/ioctrl.h
@@ -1,16 +0,0 @@
-#include "memorymap.h"
-
-typedef struct {
-  unsigned FUNC:3;
-  unsigned MODE:2;
-  unsigned HYS:1;
-  unsigned RESERVED0:4;
-  unsigned OD:1;
-  unsigned RESERVED1:21;
-} IOCON__
-
-typedef union {
-  IOCON__ ctrl;
-  HW_RW   raw;
-} IOCON_
-


fix wrong commit for Darwin

fix wrong commit for Darwin

--- lisp/c/sysfunc.c
+++ lisp/c/sysfunc.c
@@ -97,7 +97,7 @@
 #if Solaris2
 extern _end();
 #else
-//extern edata();
+extern edata();
 #endif

 xmark(ctx,p)


Handle invalid UTF-8 byte sequences gracefully by replacing them with 0xFFFD

CouchDB's Erlang JSON parser allows storing of invalid UTF-8 byte sequences.
The Query Server inside CouchDB fails upon encountering these byte sequences.
The view process fails for the current batch of document updates. The result
is that the view is invariably broken. Only removing the document in question
solves this otherwise, but finding that is hard as the `log()` inside the
Query Server dies with the invalid byte sequence because our protocol is
synchronous and map results an `log()` messages generated therein are
submitted together.

This patch replaces invalid bytes with the the surrogate chacracter 0xFFFD.

Closes COUCHDB-1425.

Patch by Sam Rijs <recv@awesan.de> and Paul Davis.

Eventually, this should be fixed at the HTTP level, so that no documents
with invalid byte sequences can be written to CouchDB. The jiffy encoder
we'll get with BigCouch will do that for us. This is a fix for the releases
until then.

--- priv/couch_js/utf8.c
+++ priv/couch_js/utf8.c
@@ -66,24 +66,31 @@
         c = *src++;
         srclen--;

-        if((c >= 0xDC00) && (c <= 0xDFFF)) goto bad_surrogate;
-
-        if(c < 0xD800 || c > 0xDBFF)
-        {
-            v = c;
-        }
-        else
+        if(c <= 0xD7FF || c >= 0xE000)
+        {
+            v = (uint32) c;
+        }
+        else if(c >= 0xD800 && c <= 0xDBFF)
         {
             if(srclen < 1) goto buffer_too_small;
             c2 = *src++;
             srclen--;
-            if ((c2 < 0xDC00) || (c2 > 0xDFFF))
-            {
-                c = c2;
-                goto bad_surrogate;
-            }
-            v = ((c - 0xD800) << 10) + (c2 - 0xDC00) + 0x10000;
-        }
+            if(c2 >= 0xDC00 && c2 <= 0xDFFF)
+            {
+                v = (uint32) (((c - 0xD800) << 10) + (c2 - 0xDC00) + 0x10000);
+            }
+            else
+            {
+                // Invalid second half of surrogate pair
+                v = (uint32) 0xFFFD;
+            }
+        }
+        else
+        {
+            // Invalid first half surrogate pair
+            v = (uint32) 0xFFFD;
+        }
+
         if(v < 0x0080)
         {
             /* no encoding necessary - performance hack */
@@ -108,10 +115,6 @@

     *dstlenp = (origDstlen - dstlen);
     return JS_TRUE;
-
-bad_surrogate:
-    *dstlenp = (origDstlen - dstlen);
-    return JS_FALSE;

 buffer_too_small:
     *dstlenp = (origDstlen - dstlen);


initialize pointer to NULL

initialize pointer to NULL

git-svn-id: 444ed946b9c2220da791e84c3dd156a05f92db99@1925 c6295689-39f2-0310-b995-f0e70906c6a9

--- src/scdl/scdl.c
+++ src/scdl/scdl.c
@@ -46,7 +46,7 @@
 dlfcn_open(scdl_context_t *mod, const char *name)
 {
 	const char	**dir, *ldlist[64];
-	char		pathbuf[4096], *ldenv;
+	char		pathbuf[4096], *ldenv = NULL;
 	unsigned int	n = 0, flags = 0;

 #ifdef RTLD_NOW


Fixed DELETE.

Fixed DELETE.

--- src/scheduler.c
+++ src/scheduler.c
@@ -166,6 +166,7 @@

     while( __keep_going__ ) {
         int info_period = 3;
+        int schedule_changed = 0;

         pthread_mutex_lock( &schedule_lock );

@@ -179,7 +180,7 @@
             if (NULL == current_blocked_macs) {
                 if (NULL != blocked_macs) {
                     current_blocked_macs = blocked_macs;
-                    call_firewall( firewall_cmd, current_blocked_macs );
+                    schedule_changed = 1;
                 }
             } else {
                 if (NULL != blocked_macs) {
@@ -187,7 +188,7 @@
                         aker_free(current_blocked_macs);
                         current_blocked_macs = blocked_macs;

-                        call_firewall( firewall_cmd, current_blocked_macs );
+                        schedule_changed = 1;
                     } else {/* No Change In Schedule */
                         if (0 == (info_period++ % 3)) {/* Reduce Clutter */
                             debug_print("scheduler_thread(): No Change\n");
@@ -197,8 +198,19 @@
                 } else {
                     aker_free(current_blocked_macs);
                     current_blocked_macs = NULL;
+                    schedule_changed = 1;
                 }
             }
+        } else {
+            if( current_blocked_macs ) {
+                aker_free(current_blocked_macs);
+                current_blocked_macs = NULL;
+                schedule_changed = 1;
+            }
+        }
+
+        if( 0 != schedule_changed ) {
+            call_firewall( firewall_cmd, current_blocked_macs );
         }

         tm.tv_sec = get_next_unixtime(current_schedule, current_unix_time);


fix codetest failure - there should be at least one space between a C keyword and any subsequent open parenthesis and trailing whitespace

git-svn-id: 3fb9cb7d2119864934bf556c38993074c0698f2e@47988 d31e2699-5ff4-0310-a27c-f18f2fbe73fe

--- src/scheduler.c
+++ src/scheduler.c
@@ -83,7 +83,7 @@

     interp->quantum_done = Parrot_floatval_time() + PARROT_TASK_SWITCH_QUANTUM;

-    if(interp_count++ > 1) {
+    if (interp_count++ > 1) {
         fprintf(stderr, "More than one interp?\n");
         exit(0);
     }
@@ -105,7 +105,7 @@

 =item C<void Parrot_cx_check_tasks(PARROT_INTERP, PMC *scheduler)>

-If a wake request has been received or an OS timer has expired
+If a wake request has been received or an OS timer has expired
 then handle tasks.

 =cut
@@ -116,7 +116,7 @@
 Parrot_cx_check_tasks(PARROT_INTERP, ARGMOD(PMC *scheduler))
 {
     ASSERT_ARGS(Parrot_cx_check_tasks)
-    if  ( Parrot_alarm_check(&(interp->last_alarm))
+    if  ( Parrot_alarm_check(&(interp->last_alarm))
           || SCHEDULER_wake_requested_TEST(scheduler)) {
         Parrot_cx_handle_tasks(interp, scheduler);
     }
@@ -145,7 +145,7 @@
     Parrot_cx_check_alarms(interp, scheduler);
     Parrot_cx_check_quantum(interp, scheduler);

-    if(SCHEDULER_resched_requested_TEST(scheduler)) {
+    if (SCHEDULER_resched_requested_TEST(scheduler)) {
         SCHEDULER_resched_requested_CLEAR(scheduler);
         Parrot_cx_schedule_next_task(interp, scheduler);
     }
@@ -207,7 +207,7 @@
     Parrot_Scheduler_attributes *sched = PARROT_SCHEDULER(scheduler);
     FLOATVAL time_now = Parrot_floatval_time();

-    if(time_now >= interp->quantum_done)
+    if (time_now >= interp->quantum_done)
         SCHEDULER_resched_requested_SET(scheduler);
 }

@@ -230,7 +230,7 @@
     Parrot_Scheduler_attributes *sched = PARROT_SCHEDULER(scheduler);
     INTVAL task_count = VTABLE_get_integer(interp, sched->task_queue);

-    if(task_count > 0) {
+    if (task_count > 0) {
         PMC *sub = VTABLE_shift_pmc(interp, sched->task_queue);

         FLOATVAL time_now = Parrot_floatval_time();
@@ -287,7 +287,7 @@

 Add a task to to the task queue for execution.

-Probably cannot be called across interpreters/threads, must instead be
+Probably cannot be called across interpreters/threads, must instead be
 called from within the interpreter's runloop.

 =cut
@@ -320,12 +320,12 @@

 PARROT_EXPORT
 void
-Parrot_cx_schedule_immediate(PARROT_INTERP, ARGIN(PMC *task))
+Parrot_cx_schedule_immediate(PARROT_INTERP, ARGIN(PMC *task))
 {
     ASSERT_ARGS(Parrot_cx_schedule_immediate)
     Parrot_Scheduler_attributes *sched = PARROT_SCHEDULER(interp->scheduler);
     VTABLE_unshift_pmc(interp, sched->task_queue, task);
-    SCHEDULER_wake_requested_SET(interp->scheduler);
+    SCHEDULER_wake_requested_SET(interp->scheduler);
     SCHEDULER_resched_requested_SET(interp->scheduler);
 }

@@ -475,7 +475,7 @@
 {
     ASSERT_ARGS(Parrot_cx_add_handler_local)
     if (PMC_IS_NULL(Parrot_pcc_get_handlers(interp, interp->ctx)))
-        Parrot_pcc_set_handlers(interp, interp->ctx,
+        Parrot_pcc_set_handlers(interp, interp->ctx,
                                 Parrot_pmc_new(interp, enum_class_ResizablePMCArray));

     VTABLE_unshift_pmc(interp, Parrot_pcc_get_handlers(interp, interp->ctx), handler);
@@ -958,18 +958,18 @@

 PARROT_EXPORT
 void
-Parrot_cx_check_alarms(PARROT_INTERP, ARGMOD(PMC *scheduler))
+Parrot_cx_check_alarms(PARROT_INTERP, ARGMOD(PMC *scheduler))
 {
     ASSERT_ARGS(Parrot_cx_check_alarms)
     Parrot_Scheduler_attributes *sched = PARROT_SCHEDULER(scheduler);
     INTVAL   alarm_count = VTABLE_get_integer(interp, sched->alarms);
     FLOATVAL now_time    = Parrot_floatval_time();

-    while(alarm_count) {
+    while (alarm_count) {
         PMC *alarm = VTABLE_shift_pmc(interp, sched->alarms);
         FLOATVAL alarm_time = VTABLE_get_number(interp, alarm);

-        if(alarm_time < now_time) {
+        if (alarm_time < now_time) {
             Parrot_Alarm_attributes *data = PARROT_ALARM(alarm);
             Parrot_cx_schedule_immediate(interp, data->alarm_sub);
         } else {
@@ -1042,10 +1042,10 @@
     Parrot_cx_check_tasks(interp, interp->scheduler);
     now_time = Parrot_floatval_time();

-    while(now_time < done_time) {
+    while (now_time < done_time) {
         alarm_count = VTABLE_get_integer(interp, sched->alarms);
-
-        if(alarm_count > 0) {
+
+        if (alarm_count > 0) {
             alarm = VTABLE_shift_pmc(interp, sched->alarms);
             alarm_time = VTABLE_get_number(interp, alarm);
             VTABLE_unshift_pmc(interp, sched->alarms, alarm);
@@ -1053,7 +1053,7 @@

         sleep_time = now_time - fmin(done_time, alarm_time);

-        if(sleep_time > 0.0) {
+        if (sleep_time > 0.0) {
             Parrot_floatval_sleep(sleep_time);
         }


minor cleanup

minor cleanup

--- src/scheduler.c
+++ src/scheduler.c
@@ -621,8 +621,6 @@
             {
                 to_enable = sx_set_remove (to_enable, a);

-//              kyu_command (cons (make_symbol ("need"), cons (a, r)));
-
                 if (nexp (car (r))) /* unresolved requirements */
                 {
                     unresolved = sx_set_merge (unresolved, cdr (r));


fixed a bug with non main PROC calling proxc_exit

--- src/scheduler.c
+++ src/scheduler.c
@@ -306,7 +306,7 @@
             break;
         case PROC_ENDED:
             /* termination test */
-            sched->is_exit = (sched->curr_proc == sched->main_proc);
+            sched->is_exit = sched->is_exit || (sched->curr_proc == sched->main_proc);

             /* cleanup */
             proc_free(sched->curr_proc);


if master is already unblocked, do not unblock it twice

--- src/scripting.c
+++ src/scripting.c
@@ -1367,7 +1367,7 @@
          * script timeout was detected. */
         aeCreateFileEvent(server.el,c->fd,AE_READABLE,
                           readQueryFromClient,c);
-        if (server.masterhost && server.master) {
+        if (server.masterhost && server.master && !(server.master->flags & CLIENT_UNBLOCKED)) {
             server.master->flags |= CLIENT_UNBLOCKED;
             listAddNodeTail(server.unblocked_clients,server.master);
         }


Fix bug with null in lua

Fix bug with null in lua

--- src/scripting.c
+++ src/scripting.c
@@ -110,6 +110,9 @@
 	case RLITE_REPLY_INTEGER:
 		rliteToLuaType_Int(lua,reply);
 		break;
+	case RLITE_REPLY_NIL:
+		lua_pushboolean(lua,0);
+		break;
 	case RLITE_REPLY_STRING:
 		rliteToLuaType_Bulk(lua,reply);
 		break;


added HAVE_CONFIG_H and HAVE_SBRK #ifdefs to ease portability

--- src/sd/malloc.c
+++ src/sd/malloc.c
@@ -21,7 +21,11 @@
 #include "config.h"
 #endif
 #include <stdio.h>
+
+#ifdef HAVE_CONFIG_H
 #include <unistd.h>
+#endif
+
 #include <string.h>
 #include <stdlib.h>
 #include <sd/error.h>
@@ -43,6 +47,7 @@
 {
     void* p = 0;

+#ifndef HAVE_SBRK
     if (n == 0)
 	p = malloc ((size_t) 1);

@@ -64,6 +69,7 @@
 	    abort();
 	}
     }
+#endif
     return p;
 }


increased verbosity of compile output

increased verbosity of compile output

--- lisp_compiler2.c
+++ lisp_compiler2.c
@@ -291,7 +291,13 @@
     default:
       ERROR("Number of macro arguments not supported: %i", argcnt);
     }
-    COMPILE_ASSERT(td != error_def);
+    if(td == error_def && !is_check_type_run()){
+      loge("Unable to compile: ");
+      expr e = {.type = EXPR};
+      e.sub_expr = *se;
+      print_expr(&e); loge("\n");
+    }
+
     return td;

   }else if(var_type->type == FUNCTION ||


#3461 test case with larger rows that crash the leaf splitter refs[t:3461]

git-svn-id: b5c078ec0b4d3a50497e9dd3081db18a5b4f16e5@30307 c7de825b-a66e-492c-adef-691d508d4ae1

--- src/tests/test_blobs_leaf_split.c
+++ src/tests/test_blobs_leaf_split.c
@@ -23,7 +23,7 @@

 int test_main(int argc, char * const argv[]) {
 #if defined(TOKUDB)
-    char *db_env_dir = "blobs.leafsplit.env.tokudb";
+    char *db_env_dir = "blobs.leafsplit.env.tdb";
 #else
     char *db_env_dir = "blobs.leafsplit.env.bdb";
 #endif


File serialise.h was added

File serialise.h was added

error: pathspec 'src/serialise.h' did not match any file(s) known to git

--- src/serialise.h
+++ src/serialise.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2015 deipi.com LLC and contributors. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef XAPIAND_INCLUDED_SERIALISE_UNSER_H
+#define XAPIAND_INCLUDED_SERIALISE_UNSER_H
+
+#include "xapiand.h"
+#include "htm.h"
+
+// Data types
+#define NUMERIC_TYPE 'n'
+#define STRING_TYPE 's'
+#define DATE_TYPE 'd'
+#define GEO_TYPE 'g'
+#define BOOLEAN_TYPE 'b'
+#define ARRAY_TYPE 'a'
+#define OBJECT_TYPE 'o'
+#define NO_TYPE ' '
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+// No translation needed for big endian system.
+#define Swap7Bytes(val) val // HTM's trixel's ids are represent in 7 bytes.
+#define Swap4Bytes(val) val // Unsigned int is represent in 4 bytes
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+// Swap 7 byte, 56 bit values. (If it is not big endian, It is considered little endian)
+#define Swap7Bytes(val) ((((val) >> 48) & 0xFF) | (((val) >> 32) & 0xFF00) | (((val) >> 16) & 0xFF0000) | \
+ 						((val) & 0xFF000000) | (((val) << 16) & 0xFF00000000) | \
+						(((val) << 32) & 0xFF0000000000) | (((val) << 48) & 0xFF000000000000))
+#define Swap4Bytes(val) ((((val) >> 24) & 0xFF) | (((val) >> 8) & 0xFF00) | \
+						(((val) <<  8) & 0xFF0000) | ((val << 24) & 0xFF000000))
+#endif
+
+
+const unsigned int SIZE_SERIALISE_CARTESIAN = 12;
+const unsigned int DOUBLE2INT = 1000000000;
+const unsigned int MAXDOU2INT =  999999999;
+
+
+namespace Serialise {
+	std::string serialise(char field_type, const std::string &field_value);
+	std::string numeric(const std::string &field_value);
+	std::string date(const std::string &field_value);
+	// Serialise a normalize cartesian coordinate in SIZE_SERIALISE_CARTESIAN bytes.
+	std::string cartesian(const Cartesian &norm_cartesian);
+	// Serialise a trixel's id (HTM).
+	std::string trixel_id(uInt64 id);
+	std::string boolean(const std::string &field_value);
+};
+
+
+namespace Unserialise {
+	std::string unserialise(char field_type, const std::string &field_name, const std::string &serialise_val);
+	std::string numeric(const std::string &serialise_val);
+	std::string date(const std::string &serialise_val);
+	// Unserialise a serialise cartesian coordinate.
+	Cartesian cartesian(const std::string &str);
+	// Unserialise a trixel's id (HTM).
+	uInt64 trixel_id(const std::string &str);
+	std::string boolean(const std::string &serialise_val);
+};
+
+
+#endif /* XAPIAND_INCLUDED_SERIALISE_UNSER_H */


UUIDRepr: simple is first (== 0)

UUIDRepr: simple is first (== 0)

--- src/serialise.h
+++ src/serialise.h
@@ -72,6 +72,7 @@
 constexpr uint32_t MAXDOU2INT = 2000000000;

 enum class UUIDRepr : uint8_t {
+	simple,
 #ifdef UUID_USE_GUID
 	guid,
 #endif
@@ -90,7 +91,6 @@
 #ifdef UUID_USE_BASE62
 	base62,
 #endif
-	simple,
 };

 class CartesianList;


Lockin, advance version 0.3.24.66

Lockin, advance version 0.3.24.66

--- src/serialize.h
+++ src/serialize.h
@@ -42,7 +42,7 @@
 class CAutoFile;
 static const unsigned int MAX_SIZE = 0x02000000;

-static const int VERSION = 32465;
+static const int VERSION = 32466;
 static const char* pszSubVer = "";
 static const bool VERSION_IS_BETA = true;