Added handling of charsets in id3v2

Added handling of charsets in id3v2

ISO-8859-1, UTF-16 w/ BOM and UTF-16 w/o BOM are converted to UTF-8

--- lib/id3.c
+++ lib/id3.c
@@ -6,7 +6,7 @@
  **  It was pretty annoying that I had to write this
  **  but I could not find one single ID3 library
  **  that had a BSD license and was written in C.
- */
+ */

 /* ====================================================================
 Copyright (c) 2006, Tangent Org
@@ -44,6 +44,7 @@

 #include <id3.h>
 #include <config.h>
+#include <iconv.h>
 #include "md5.h"

 void md5_signature(const unsigned char *buf, int length, char *result);
@@ -78,7 +79,7 @@
   "Anime", "JPop", "Synthpop"
 };

-static const char * genre_string(int genre)
+static const char * genre_string(int genre)
 {
   if (genre < GENRE_MAX && genre > -1)
     return id3_genres[genre];
@@ -86,35 +87,127 @@
   return NULL;
 }

-static void clean_string(unsigned char *string, int length)
-{
-  unsigned char *ptr= string;
-
-  for(; (ptr - string) < length; ptr++)
-    if (!isprint(*ptr))
-      *ptr= ' ';
-
-}
-
-static char * add_tag(ID3 *info, const char *tag, size_t length)
+void encode_conv(char *str_input, unsigned int len, const char *fromcode, const char *tocode) {
+    size_t iconv_value;
+    char *str_output;
+    size_t str_input_len, str_output_len, new_len;
+    iconv_t conv_desc;
+
+    /* The variables with "start" in their name are solely for display
+     of what the function is doing. As iconv runs, it alters the
+     values of the variables, so these are for keeping track of the
+     start points and start lengths. */
+    char *_str_output;
+    const char *_str_input;
+    size_t _str_output_len, _str_input_len;
+
+    conv_desc = iconv_open(tocode, fromcode);
+    if (conv_desc == -1) {
+        /* Initialization failure. */
+        if (errno == EINVAL) {
+            fprintf(stderr, "Conversion from '%s' to '%s' is not supported.\n",
+                    fromcode, tocode);
+        } else {
+            fprintf(stderr, "Initialization failure: %s\n", strerror(errno));
+        }
+        exit(1);
+    }
+
+    // len - 1 because or first byte indicating encoding
+    if (!(len-1)) {
+        fprintf(stderr, "Input string is empty.\n");
+        return (0);
+    }
+    str_input_len = len - 1;
+
+    /* Assign enough space to put the UTF-8. */
+    str_output_len = str_input_len * 2;
+    str_output = calloc(str_output_len, 1);
+
+    /* Keep track of the variables. */
+    _str_output = str_output;
+    _str_output_len = str_output_len;
+    _str_input = str_input++;
+    _str_input_len = str_input_len;
+
+    iconv_value = iconv(conv_desc, &str_input, &str_input_len, &str_output, &str_output_len);
+
+    /* Handle failures. */
+    if (iconv_value == (size_t) -1) {
+        fprintf(stderr, "iconv failed: in string '%s', length %d, "
+            "out string '%s', length %d\n", str_input, str_input_len, _str_output, _str_output_len);
+        switch (errno) {
+        case EILSEQ:
+            fprintf(stderr, "Invalid multibyte sequence.\n");
+            break;
+        case EINVAL:
+            fprintf(stderr, "Incomplete multibyte sequence.\n");
+            break;
+        case E2BIG:
+            fprintf(stderr, "No more room.\n");
+            break;
+        default:
+            fprintf(stderr, "Error: %s.\n", strerror(errno));
+        }
+        exit(1);
+    }
+
+    if (iconv_close(conv_desc) != 0) {
+        fprintf(stderr, "iconv_close failed: %s\n", strerror(errno));
+        exit(1);
+    }
+
+    memset(_str_input, 0, len);
+
+    new_len = _str_output_len - str_output_len;
+    memcpy(_str_input, _str_output, new_len);
+
+    free(_str_output);
+}
+
+static void convert_string(unsigned char *str, int length)
+{
+    char *utf8;
+    int i, new_length;
+
+    /**
+     * 0: ISO-8859-1
+     * 1: UTF-16 w/ BOM
+     * 2: UTF-16 w/o BOM
+     * 3: UTF-8
+     */
+    if (*str == 0) {
+        encode_conv(str, length, "ISO-8859-1", "UTF-8");
+    } else if (*str == 1 || *str == 2) {
+        encode_conv(str, length, "UTF-16", "UTF-8");
+    } else if (*str == 3) {
+        // Keep as is, remove encoding byte
+        for (i = 0; i < length - 1; i++) {
+            str[i] = str[i + 1];
+        }
+        str[length - 1] = '\0';
+    }
+}
+
+static char * add_tag(ID3 *info, const char *tag, size_t length)
 {
   unsigned char *begin;

   // If the current tag is too big for our block of memory
-  if ((length + info->length) > info->size)
-  {
-    if ( info->user_memory)
+  if ((length + info->length) > info->size)
+  {
+    if ( info->user_memory)
     {
       // This because we didn't allocate the memory in the first place, and this should be an error
       return NULL;
     }
-    else if ( info->size == 0 )
+    else if ( info->size == 0 )
     {
       info->buffer= (unsigned char *)malloc(ID3_INIT_SIZE);
       info->size= ID3_INIT_SIZE;
       info->ptr= info->buffer;
     }
-    else if ( length > info->tag_length  )
+    else if ( length > info->tag_length  )
     {
       info->buffer= realloc(info->buffer, info->tag_length);
       info->ptr= info->buffer + info->length;
@@ -131,7 +224,7 @@
   }
   begin= info->ptr;
   memcpy(info->ptr, tag, length);
-  clean_string(info->ptr, length);
+  convert_string(info->ptr, length);
   info->length += length + 1;
   info->ptr += length;
   *info->ptr++= '\0';
@@ -140,7 +233,7 @@
   return (char *)begin;
 }

-static void select_tag(ID3 *info, const char *name, const char *ptr, size_t length)
+static void select_tag(ID3 *info, const char *name, const char *ptr, size_t length)
 {
   if (!strcmp(name, "title"))
   {
@@ -185,10 +278,10 @@
 }

-static size_t id3_size(const unsigned char* buffer)
+static size_t id3_size(const unsigned char* buffer)
 {
   size_t size = 0;
-  size=  (buffer[3] & 0x7f) +
+  size=  (buffer[3] & 0x7f) +
     ((buffer[2] & 0x7f) << 7) +
     ((buffer[1] & 0x7f) << 14) +
     ((buffer[0] & 0x7f) << 21);
@@ -196,29 +289,29 @@
   return size;
 }

-static size_t id3_size2(const unsigned char * buffer)
+static size_t id3_size2(const unsigned char * buffer)
 {
   size_t size = 0;
-  size=  (buffer[2] & 0x7f) +
+  size=  (buffer[2] & 0x7f) +
     ((buffer[1] & 0x7f) << 7) +
     ((buffer[0] & 0x7f) << 14);

   return size;
 }

-static size_t get_framesize(const unsigned char *buffer)
+static size_t get_framesize(const unsigned char *buffer)
 {
   return ((buffer[6] << 8) + (buffer[7]));
 }

-static int get_id3v1_tag (ID3 *info, unsigned char *blob, size_t blob_length)
+static int get_id3v1_tag (ID3 *info, unsigned char *blob, size_t blob_length)
 {
   unsigned char *ptr= (unsigned char *)blob;
   const char *genre= NULL;

   ptr += (blob_length - 128);

-  if (!memcmp(ptr, "TAG", 3))
+  if (!memcmp(ptr, "TAG", 3))
   {
     /* Paranoid, not all systems are made equally */
     ptr +=3;
@@ -257,11 +350,11 @@
   return ID3_ERR_NO_TAG;
 }

-static int id_2_2(ID3 *info, unsigned char *blob)
+static int id_2_2(ID3 *info, unsigned char *blob)
 {
   unsigned char *ptr= blob;

-  while (info->tag_length > (ptr - blob))
+  while (info->tag_length > (ptr - blob))
   {
     size_t size= id3_size2(ptr+3);
     char *compare_ptr= (char *)ptr;
@@ -271,7 +364,7 @@
       return 0;
     }

-    if (size + (ptr - blob) > info->tag_length)
+    if (size + (ptr - blob) > info->tag_length)
       break;

     if (!strncmp("TP1", compare_ptr, 3) && (info->mask & ARTIST_TAG))
@@ -279,41 +372,41 @@
       info->processor(info, "artist", compare_ptr + 6, size);
       info->mask_found |= ARTIST_TAG;
     }
-    else if (!strncmp("TT2", compare_ptr, 3) && (info->mask & TITLE_TAG))
+    else if (!strncmp("TT2", compare_ptr, 3) && (info->mask & TITLE_TAG))
     {
       info->processor(info, "title", compare_ptr + 6, size);
       info->mask_found |= TITLE_TAG;
     }
-    else if (!strncmp("TAL", compare_ptr, 3) && (info->mask & ALBUM_TAG))
+    else if (!strncmp("TAL", compare_ptr, 3) && (info->mask & ALBUM_TAG))
     {
       info->processor(info, "album", compare_ptr + 6, size);
       info->mask_found |= ALBUM_TAG;
     }
-    else if (!strncmp("TRK", compare_ptr, 3) && (info->mask & TRACK_TAG))
+    else if (!strncmp("TRK", compare_ptr, 3) && (info->mask & TRACK_TAG))
     {
       info->processor(info, "track", compare_ptr + 6, size);
       info->mask_found |= TRACK_TAG;
     }
-    else if (!strncmp("TEN", compare_ptr, 3) && (info->mask & ENCODER_TAG))
+    else if (!strncmp("TEN", compare_ptr, 3) && (info->mask & ENCODER_TAG))
     {
       info->processor(info, "encoder", compare_ptr + 6, size);
       info->mask_found |= ENCODER_TAG;
     }
-    else if (!strncmp("TYE", compare_ptr, 3) && (info->mask & YEAR_TAG))
+    else if (!strncmp("TYE", compare_ptr, 3) && (info->mask & YEAR_TAG))
     {
       info->processor(info, "year", compare_ptr + 6, size);
       info->mask_found |= YEAR_TAG;
     }
-    else if (!strncmp("COM", compare_ptr, 3) && (info->mask & COMMENT_TAG))
+    else if (!strncmp("COM", compare_ptr, 3) && (info->mask & COMMENT_TAG))
     {
       info->processor(info, "comment", compare_ptr + 6, size);
       info->mask_found |= COMMENT_TAG;
     }
-    else if (!strncmp("TCO", compare_ptr, 3) && (info->mask & GENRE_TAG))
+    else if (!strncmp("TCO", compare_ptr, 3) && (info->mask & GENRE_TAG))
     {
       info->processor(info, "genre", compare_ptr + 6, size);
       info->mask_found |= GENRE_TAG;
-    }
+    }
     else
     {
       char temp[4];
@@ -331,52 +424,52 @@
   return 0;
 }

-static int id_2_3(ID3 *info, unsigned char *blob)
+static int id_2_3(ID3 *info, unsigned char *blob)
 {
   unsigned char *ptr= blob;

-  while (info->tag_length > (ptr - blob))
+  while (info->tag_length > (ptr - blob))
   {
     size_t size= get_framesize(ptr);
     char *compare_ptr= (char *)ptr;

-    if (size + (ptr - blob) > info->tag_length)
+    if (size + (ptr - blob) > info->tag_length)
       break;

     if (size <= 0)
       return 0;

-    if (!strncmp("TPE1", compare_ptr, 4) && (info->mask & ARTIST_TAG))
+    if (!strncmp("TPE1", compare_ptr, 4) && (info->mask & ARTIST_TAG))
     {
       info->processor(info, "artist", compare_ptr +10, size);
       info->mask_found |= ARTIST_TAG;
     }
-    else if (!strncmp("TIT2", compare_ptr, 4) && (info->mask & TITLE_TAG))
+    else if (!strncmp("TIT2", compare_ptr, 4) && (info->mask & TITLE_TAG))
     {
       info->processor(info, "title", compare_ptr +10, size);
       info->mask_found |= TITLE_TAG;
     }
-    else if (!strncmp("TALB", compare_ptr, 4) && (info->mask & ALBUM_TAG))
+    else if (!strncmp("TALB", compare_ptr, 4) && (info->mask & ALBUM_TAG))
     {
       info->processor(info, "album", compare_ptr +10, size);
       info->mask_found |= ARTIST_TAG;
     }
-    else if (!strncmp("TRCK",compare_ptr,4) && (info->mask & TRACK_TAG))
+    else if (!strncmp("TRCK",compare_ptr,4) && (info->mask & TRACK_TAG))
     {
       info->processor(info, "track", compare_ptr +10, size);
       info->mask_found |= TRACK_TAG;
     }
-    else if (!strncmp("TYER",compare_ptr,4) && (info->mask & YEAR_TAG))
+    else if (!strncmp("TYER",compare_ptr,4) && (info->mask & YEAR_TAG))
     {
       info->processor(info, "year", compare_ptr +10, size);
       info->mask_found |= YEAR_TAG;
     }
-    else if (!strncmp("TENC",compare_ptr,4) && (info->mask & ENCODER_TAG))
+    else if (!strncmp("TENC",compare_ptr,4) && (info->mask & ENCODER_TAG))
     {
       info->processor(info, "encoder", compare_ptr +10, size);
       info->mask_found |= ENCODER_TAG;
     }
-    else if (!strncmp("COMM",compare_ptr,4) && (info->mask & COMMENT_TAG))
+    else if (!strncmp("COMM",compare_ptr,4) && (info->mask & COMMENT_TAG))
     {
       info->processor(info, "commment", compare_ptr +10, size);
       info->mask_found |= COMMENT_TAG;
@@ -397,18 +490,18 @@
   return 0;
 }

-static int process_extended_header(ID3 *info, unsigned char *blob)
+static int process_extended_header(ID3 *info, unsigned char *blob)
 {
   unsigned long CRC= 0;
   unsigned long paddingsize= 0;

   /*
-    Shortcut. The extended header size will be either 6 or 10 bytes.
+    Shortcut. The extended header size will be either 6 or 10 bytes.
     If it's ten bytes, it means that there's CRC data (though we check
-    the flag anyway). I'm gonna save it, though I'll be damned if I
+    the flag anyway). I'm gonna save it, though I'll be damned if I
     know what to do with it.
   */
-  if ((blob[3] == 0x0A) && (blob[4]))
+  if ((blob[3] == 0x0A) && (blob[4]))
     CRC= (blob[10] << 24) + (blob[11] << 16) +
       (blob[12] << 8) + (blob[13]);

@@ -422,39 +515,39 @@
   return id_2_3(info, blob);
 }

-static int get_id3v2_tag (ID3 *info, unsigned char *blob, size_t blob_length)
+static int get_id3v2_tag (ID3 *info, unsigned char *blob, size_t blob_length)
 {
   int unsynchronized= 0;
   int hasExtendedHeader= 0;
   unsigned char *ptr_buffer= blob;

-  if (!strncmp((char *)ptr_buffer, "ID3", 3))
+  if (!strncmp((char *)ptr_buffer, "ID3", 3))
   {
     info->tag_length= id3_size(ptr_buffer+6);
     snprintf(info->version, VERSION_SIZE, "2.%d.%d", blob[3], blob[4]);

-    if ((blob[5] & 0x40) >> 6)
+    if ((blob[5] & 0x40) >> 6)
       hasExtendedHeader= 1;

-    if ((blob[5] & 0x80) >> 7)
+    if ((blob[5] & 0x80) >> 7)
       unsynchronized= 1;

     /* We can not handle experimental tags */
-    if ((blob[5] & 0x20) >> 5)
+    if ((blob[5] & 0x20) >> 5)
       return 1;

 #ifdef NOT_SUPPORTED
-    if (unsynchronized)
+    if (unsynchronized)
     {
       register int i,j; /*index*/
       /*
         Replace every instance of '0xFF 0x00'
         with '0xFF'
       */
-      for(i=10; i < info->tag_length; i++)
-        if (blob[i] == 0xFF && blob[i+1] == 0x00)
-          for(j=i+1; i < info->tag_length; i++)
+      for(i=10; i < info->tag_length; i++)
+        if (blob[i] == 0xFF && blob[i+1] == 0x00)
+          for(j=i+1; i < info->tag_length; i++)
             blob[j]= blob[j+1];

     }
@@ -463,23 +556,23 @@
     /* Move past the above */
     ptr_buffer += 10;
     /*If the tag has an extended header, parse it*/
-    if (hasExtendedHeader)
+    if (hasExtendedHeader)
       return process_extended_header(info, blob);
-    else if (blob[3] == 2)
+    else if (blob[3] == 2)
       return id_2_2(info, ptr_buffer);
-    else if (blob[3] == 3)
+    else if (blob[3] == 3)
       return id_2_3(info, ptr_buffer);
     // Yes, I will need to fix this at some point
-    else if (blob[3] == 4)
+    else if (blob[3] == 4)
       return id_2_3(info, ptr_buffer);
-    else
+    else
       return ID3_ERR_UNSUPPORTED_FORMAT;
   }

   return 1;
 }

-int ID3_to_file(char *filename, char *newfile)
+int ID3_to_file(char *filename, char *newfile)
 {
   int rc= ID3_OK;
   caddr_t blob, tag;
@@ -489,15 +582,15 @@

   size_t tag_length= 0;

-  if (stat(filename, &blob_buf))
+  if (stat(filename, &blob_buf))
     return -1;

-  if ((fd= open(filename, O_RDONLY)) ==  -1)
+  if ((fd= open(filename, O_RDONLY)) ==  -1)
     return -1;

   blob= mmap(NULL, blob_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
-  if ((blob == NULL) || (blob ==(caddr_t)-1))
+  if ((blob == NULL) || (blob ==(caddr_t)-1))
     return ID3_ERR_EMPTY_FILE;

   close(fd);
@@ -511,15 +604,15 @@

-  if ((blob_buf.st_size > 128))
+  if ((blob_buf.st_size > 128))
   {
     ptr= (unsigned char *)blob + (blob_buf.st_size - 128);
     //  Set ptr back to NULL if it is not pointing to a tag
-    if (memcmp(ptr, "TAG", 3))
+    if (memcmp(ptr, "TAG", 3))
       ptr= NULL;
   }

-  if (!strncmp(blob, "ID3", 3))
+  if (!strncmp(blob, "ID3", 3))
   {
     tag_length= id3_size((unsigned char *)blob+6);
   }
@@ -533,7 +626,7 @@
       return -1;
     ftruncate(fileno(new), total);
     tag= mmap(NULL, total, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(new), 0);
-    if ((tag == NULL) || (tag ==(caddr_t)-1))
+    if ((tag == NULL) || (tag ==(caddr_t)-1))
       return ID3_ERR_EMPTY_FILE;

     fclose(new);
@@ -553,7 +646,7 @@
   return rc;
 }

-int parse_file_ID3(ID3 *info, char *filename)
+int parse_file_ID3(ID3 *info, char *filename)
 {
   int rc= ID3_OK;
   caddr_t blob;
@@ -561,7 +654,7 @@
   size_t blocksize= (size_t)getpagesize();
   struct stat sb;

-  if ((fd= open(filename, O_RDONLY)) ==  -1)
+  if ((fd= open(filename, O_RDONLY)) ==  -1)
     return -1;

   (void)fstat(fd, &sb);
@@ -574,7 +667,7 @@
     blocksize= sb.st_size < blocksize ? sb.st_size : blocksize;

   blob= mmap(NULL, blocksize, PROT_READ, MAP_PRIVATE, fd, 0);
-  if (blob ==(caddr_t)-1)
+  if (blob ==(caddr_t)-1)
   {
     close(fd);
     return ID3_ERR_EMPTY_FILE;
@@ -593,7 +686,7 @@
       munmap(blob, blocksize);
       blocksize= length;
       blob= mmap(NULL, blocksize, PROT_READ, MAP_PRIVATE, fd, 0);
-      if ((blob == NULL) || (blob ==(caddr_t)-1))
+      if ((blob == NULL) || (blob ==(caddr_t)-1))
         return ID3_ERR_EMPTY_FILE;
     }
   }
@@ -607,7 +700,7 @@
   {
     info->data= blob;
     info->data_size= blocksize;
-  }
+  }
   else
   {
     munmap(blob, blocksize);
@@ -617,14 +710,14 @@
   return rc;
 }

-int parse_blob_ID3(ID3 *info, unsigned char *blob, size_t blob_length)
+int parse_blob_ID3(ID3 *info, unsigned char *blob, size_t blob_length)
 {
   int rc= ID3_ERR_NO_TAG;

   // Sometimes people encode both headers, so we test for both

   // Why 127 instead of 128? The file may only have a tag in it
-  if ((blob_length > 127) && !get_id3v1_tag(info, blob, blob_length))
+  if ((blob_length > 127) && !get_id3v1_tag(info, blob, blob_length))
     rc= ID3_OK;

   if (!get_id3v2_tag(info, blob, blob_length))
@@ -636,7 +729,7 @@
   return rc;
 }

-int destroy_ID3(ID3 *info)
+int destroy_ID3(ID3 *info)
 {
   DEBUG_ENTER("destroy_ID3");
   if (info && !info->user_memory)
@@ -649,12 +742,12 @@
   DEBUG_RETURN(0); //Eventually we should do more here
 }

-void set_flags_ID3(ID3 *info, id3flags mask)
+void set_flags_ID3(ID3 *info, id3flags mask)
 {
   info->mask= mask;
 }

-void set_memory_ID3(ID3 *info, unsigned char *ptr, size_t size)
+void set_memory_ID3(ID3 *info, unsigned char *ptr, size_t size)
 {
   if (info->size)
     return;
@@ -664,10 +757,10 @@
   info->size= size;
 }

-ID3 * create_ID3(ID3 *info)
+ID3 * create_ID3(ID3 *info)
 {
   //At the moment ID3 is just a structure
-  if (info)
+  if (info)
   {
     id3flags mask= info->mask;
     void *func= info->processor;
@@ -682,11 +775,11 @@
     info->allocated= info->allocated;
     info->processor= func ? func : select_tag;
     info->ptr= info->buffer;
-  }
-  else
+  }
+  else
   {
     info= (ID3 *)malloc(sizeof(ID3));
-    if (info)
+    if (info)
       memset(info, 0, sizeof(ID3));
     else {
       assert(0);


idr: print a stack dump after ida_remove warning

We print a dump stack after idr_remove warning.  This is useful to find
the faulty piece of code.  Let's do the same for ida_remove, as it would
be equally useful there.

[5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org: convert the open-coded printk+dump_stack into WARN()]
Signed-off-by: Jean Delvare <efca98801f3398ebd7eeff805a2c18e6c49e84d4@suse.de>
Cc: Tejun Heo <546b05909706652891a87f7bfe385ae147f61f91@kernel.org>
Cc: Takashi Iwai <4596b3305151c7ee743192a95d394341e3d3b644@suse.de>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>

--- lib/idr.c
+++ lib/idr.c
@@ -524,9 +524,7 @@

 static void idr_remove_warning(int id)
 {
-	printk(KERN_WARNING
-		"idr_remove called for id=%d which is not allocated.\n", id);
-	dump_stack();
+	WARN(1, "idr_remove called for id=%d which is not allocated.\n", id);
 }

 static void sub_remove(struct idr *idp, int shift, int id)
@@ -1064,8 +1062,7 @@
 	return;

  err:
-	printk(KERN_WARNING
-	       "ida_remove called for id=%d which is not allocated.\n", id);
+	WARN(1, "ida_remove called for id=%d which is not allocated.\n", id);
 }
 EXPORT_SYMBOL(ida_remove);


Fix kernel-doc comment typo '@id'

Fix kernel-doc comment typo '@id'

Signed-off-by: Paul Bolle <0bda9a89324ffe2d19adec61a9f1cd9f8c8e45f0@tiscali.nl>
Signed-off-by: Jiri Kosina <ed58f755cc8caaf10c3e8c731a8b86fb8f13d6cb@suse.cz>

--- lib/idr.c
+++ lib/idr.c
@@ -858,7 +858,7 @@
  * and go back to the idr_pre_get() call.  If the idr is full, it will
  * return %-ENOSPC.
  *
- * @id returns a value in the range %0 ... %0x7fffffff.
+ * @p_id returns a value in the range %0 ... %0x7fffffff.
  */
 int ida_get_new(struct ida *ida, int *p_id)
 {


remove unused typedef

remove unused typedef

--- lib/log.c
+++ lib/log.c
@@ -29,11 +29,6 @@
 #include "libvlc_internal.h"
 #include <vlc/libvlc.h>
 #include <assert.h>
-
-struct libvlc_log_t
-{
-    libvlc_instance_t  *p_instance;
-};

 unsigned libvlc_get_log_verbosity( const libvlc_instance_t *p_instance )
 {


fixed minor g++ warning

fixed minor g++ warning

--- lib/lz4.c
+++ lib/lz4.c
@@ -766,7 +766,7 @@

     if (dict->initCheck) LZ4_resetStream(LZ4_dict);                         /* Uninitialized structure detected */

-    if (dictSize < HASH_UNIT)
+    if (dictSize < (int)HASH_UNIT)
     {
         dict->dictionary = NULL;
         dict->dictSize = 0;


minor refactor

minor refactor

--- lib/lz4.c
+++ lib/lz4.c
@@ -1237,11 +1237,9 @@
                 op = oCopyLimit;
             }
             while (op<cpy) *op++ = *match++;
-        }
-        else {
+        } else {
             LZ4_copy8(op, match);
-            if (length>16)
-                LZ4_wildCopy(op+8, match+8, cpy);
+            if (length>16) LZ4_wildCopy(op+8, match+8, cpy);
         }
         op=cpy;   /* correction */
     }


Initialize Current Offset to 1

Initialize Current Offset to 1

--- lib/lz4.c
+++ lib/lz4.c
@@ -550,7 +550,7 @@
                            tableType == byPtr);

     size_t currentOffset = ((tableType == byU32 || tableType == byU16) &&
-                            !resetTable) ? cctx->currentOffset : 0;
+                            !resetTable) ? cctx->currentOffset : 1;
     const BYTE* base = (const BYTE*) source - currentOffset;
     const BYTE* lowLimit;
     const BYTE* const lowRefLimit = ip - cctx->dictSize;
@@ -593,7 +593,7 @@
     if (resetTable) {
       DEBUGLOG(4, "Resetting table in %p", cctx);
       MEM_INIT(cctx->hashTable, 0, LZ4_HASHTABLESIZE);
-      cctx->currentOffset = 0;
+      cctx->currentOffset = 1;
     }

     if (inputSize<LZ4_minLength) goto _last_literals;                  /* Input too small, no compression (all literals) */
@@ -793,7 +793,7 @@
     int result;
 #if (LZ4_HEAPMODE)
     LZ4_stream_t* ctxPtr = ALLOCATOR(1, sizeof(LZ4_stream_t));   /* malloc-calloc always properly aligned */
-    ctxPtr->internal_donotuse.currentOffset = 0;
+    ctxPtr->internal_donotuse.currentOffset = 1;
 #else
     LZ4_stream_t ctx;
     LZ4_stream_t* const ctxPtr = &ctx;
@@ -1039,7 +1039,7 @@
 {
     DEBUGLOG(5, "LZ4_resetStream %p", LZ4_stream);
     MEM_INIT(LZ4_stream, 0, sizeof(LZ4_stream_t));
-    LZ4_stream->internal_donotuse.currentOffset = 0;
+    LZ4_stream->internal_donotuse.currentOffset = 1;
     LZ4_stream->internal_donotuse.tableType = unusedTable;
 }


refactored mouse handlers and fixed a divide by zero in scrollbar math

--- lib/win.c
+++ lib/win.c
@@ -18,11 +18,8 @@
 static void oninput(int mods, Rune key);
 static void onmouse(MouseAct act, MouseBtn btn, int x, int y);
 static void onshutdown(void);
-static void mouse_wheelup(WinRegion id, size_t count, size_t row, size_t col);
-static void mouse_wheeldn(WinRegion id, size_t count, size_t row, size_t col);
-static void mouse_left(WinRegion id, size_t count, size_t row, size_t col);
-static void mouse_middle(WinRegion id, size_t count, size_t row, size_t col);
-static void mouse_right(WinRegion id, size_t count, size_t row, size_t col);
+static void onwheelup(WinRegion id, size_t count, size_t row, size_t col);
+static void onwheeldn(WinRegion id, size_t count, size_t row, size_t col);

 static XFont Font;
 static XConfig Config = {
@@ -34,11 +31,11 @@
 };

 void (*MouseActs[MOUSE_BTN_COUNT])(WinRegion id, size_t count, size_t row, size_t col) = {
-    [MOUSE_BTN_LEFT]      = mouse_left,
-    [MOUSE_BTN_MIDDLE]    = mouse_middle,
-    [MOUSE_BTN_RIGHT]     = mouse_right,
-    [MOUSE_BTN_WHEELUP]   = mouse_wheelup,
-    [MOUSE_BTN_WHEELDOWN] = mouse_wheeldn,
+    [MOUSE_BTN_LEFT]      = onmouseleft,
+    [MOUSE_BTN_MIDDLE]    = onmousemiddle,
+    [MOUSE_BTN_RIGHT]     = onmouseright,
+    [MOUSE_BTN_WHEELUP]   = onwheelup,
+    [MOUSE_BTN_WHEELDOWN] = onwheeldn,
 };

 static WinRegion Focused = EDIT;
@@ -169,6 +166,7 @@
     /* draw the scroll region */
     View* view = win_view(EDIT);
     size_t bend = buf_end(win_buf(EDIT));
+    if (bend == 0) bend = 1;
     size_t vbeg = view->rows[0]->off;
     size_t vend = view->rows[view->nrows-1]->off + view->rows[view->nrows-1]->rlen;
     size_t vtot = ((vend - vbeg) * 100) / bend;
@@ -181,7 +179,7 @@
     x11_draw_rect(CLR_BASE01, Regions[SCROLL].width, Regions[SCROLL].y - 2, 1, Regions[SCROLL].height);
     x11_draw_rect(CLR_BASE00, 0, Regions[SCROLL].y - 2, Regions[SCROLL].width, thumbreg);
     x11_draw_rect(CLR_BASE03, 0, thumboff, Regions[SCROLL].width, thumbsz);
-
+
     /* place the cursor on screen */
     if (Regions[Focused].csrx != SIZE_MAX && Regions[Focused].csry != SIZE_MAX) {
         x11_draw_rect(CLR_BASE3,
@@ -216,6 +214,41 @@
      * the private use area is used to encode special keys */
     if (key < 0xE000 || key > 0xF8FF)
         view_insert(win_view(FOCUSED), true, key);
+}
+
+static void onclick(MouseAct act, MouseBtn btn, int x, int y) {
+    WinRegion id = getregion(x, y);
+    size_t row = (y-Regions[id].y) / x11_font_height(Font);
+    size_t col = (x-Regions[id].x) / x11_font_width(Font);
+    if (id == SCROLL) {
+        id = EDIT;
+        switch (btn) {
+            case MOUSE_BTN_LEFT:
+                view_scroll(win_view(EDIT), -row);
+                break;
+            case MOUSE_BTN_MIDDLE: {
+                    size_t percent = ((y - (Regions[SCROLL].y-2)) * 100) / Regions[SCROLL].height;
+                    size_t off = buf_bol(win_buf(EDIT), buf_end(win_buf(EDIT)) * percent / 100);
+                    size_t csrx, csry;
+                    win_view(EDIT)->rows[0]->off = off;
+                    view_update(win_view(EDIT), &csrx, &csry);
+                }
+                break;
+            case MOUSE_BTN_RIGHT:
+                view_scroll(win_view(EDIT), +row);
+                break;
+            case MOUSE_BTN_WHEELUP:
+                view_scroll(win_view(id), -ScrollLines);
+                break;
+            case MOUSE_BTN_WHEELDOWN:
+                view_scroll(win_view(id), +ScrollLines);
+                break;
+            default:
+                break;
+        }
+    } else if (MouseActs[btn]) {
+        MouseActs[btn](MouseBtns[btn].region, MouseBtns[btn].count, row, col);
+    }
 }

 static void onmouse(MouseAct act, MouseBtn btn, int x, int y) {
@@ -247,9 +280,7 @@
             else
                 MouseBtns[btn].count = 1;
         } else if (MouseBtns[btn].count > 0) {
-            /* execute the action on button release */
-            if (MouseActs[btn])
-                MouseActs[btn](MouseBtns[btn].region, MouseBtns[btn].count, row, col);
+            onclick(act, btn, x, y);
         }
     }
 }
@@ -258,35 +289,12 @@
     x11_deinit();
 }

-static void mouse_wheelup(WinRegion id, size_t count, size_t row, size_t col) {
-    if (id == SCROLL) id = EDIT;
+static void onwheelup(WinRegion id, size_t count, size_t row, size_t col) {
     view_scroll(win_view(id), -ScrollLines);
 }

-static void mouse_wheeldn(WinRegion id, size_t count, size_t row, size_t col) {
-    if (id == SCROLL) id = EDIT;
+static void onwheeldn(WinRegion id, size_t count, size_t row, size_t col) {
     view_scroll(win_view(id), +ScrollLines);
-}
-
-static void mouse_left(WinRegion id, size_t count, size_t row, size_t col) {
-    if (id == SCROLL)
-        view_scroll(win_view(EDIT), row);
-    else
-        onmouseleft(id,count,row,col);
-}
-
-static void mouse_middle(WinRegion id, size_t count, size_t row, size_t col) {
-    if (id == SCROLL)
-        printf("scroll row: %lu\n", row);
-    else
-        onmousemiddle(id,count,row,col);
-}
-
-static void mouse_right(WinRegion id, size_t count, size_t row, size_t col) {
-    if (id == SCROLL)
-        view_scroll(win_view(EDIT), row - (win_view(EDIT)->nrows-1));
-    else
-        onmouseright(id,count,row,col);
 }

 /*****************************************************************************/


x86 32-bit context switches and dill_setsp for stack protection support


Add implementation of create_connection_cb() callback

--- src/connection/manager.c
+++ src/connection/manager.c
@@ -25,11 +25,17 @@
  * along with waysome. If not, see <http://www.gnu.org/licenses/>.
  */

+#include <errno.h>
 #include <stdlib.h>
 #include <string.h>

 #include "connection/manager.h"
+#include "connection/processor.h"
 #include "objects/set.h"
+#include "serialize/deserializer.h"
+#include "serialize/json/deserializer.h"
+#include "serialize/json/serializer.h"
+#include "serialize/serializer.h"
 #include "util/socket.h"

 #define SOCK_NAME "waysome.sock"
@@ -101,7 +107,37 @@
 create_connection_cb(
     int fd
 ) {
-    //!< @todo implement
-    return -1;
+    int res = 0;
+    struct ws_serializer* ser = ws_serializer_json_serializer_new();
+    if (!ser) {
+        goto out;
+    }
+
+    struct ws_deserializer* deser = ws_serializer_json_deserializer_new();
+    if (!deser) {
+        res = -ENOMEM;
+        goto clean_ser;
+    }
+
+    struct ws_connection_processor* p;
+    p = ws_connection_processor_new(fd, deser, ser);
+    if (!p) {
+        res = -ENOMEM;
+        goto clean_deser;
+    }
+
+    if (!ws_set_insert(&connman.connections, &p->obj)) {
+        goto clean_deser;
+    }
+
+    goto out;
+clean_deser:
+    ws_deserializer_deinit(deser);
+
+clean_ser:
+    ws_serializer_deinit(ser);
+
+out:
+    return res;
 }


Fix double check enable from motor left

Fix double check enable from motor left

--- src/control/motors_PID.c
+++ src/control/motors_PID.c
@@ -213,9 +213,10 @@
         case 0:
             motor_state[num] = state;
             MOTOR_ENABLE1 = enable ^ parameter_motor_left.enable_set;
+            break;
         case 1:
             motor_state[num] = state;
-            MOTOR_ENABLE2 = enable ^ parameter_motor_left.enable_set;
+            MOTOR_ENABLE2 = enable ^ parameter_motor_right.enable_set;
             break;
     }
 }


SDK version bump. Again. Hopefully the interfaces will be stable soon.

--- src/core/sdk/constants.h
+++ src/core/sdk/constants.h
@@ -133,5 +133,5 @@
                 static const char* ExternalId = "external_id";
             }

-            static const int SdkVersion = 9;
+            static const int SdkVersion = 10;
 } } }


Say crop instead of cropabs in croprel error message

--- src/core/simplefilters.c
+++ src/core/simplefilters.c
@@ -49,27 +49,27 @@
     msg[0] = 0;

     if (y < 0 || x < 0)
-        sprintf(msg, "CropAbs: negative corner coordinates not allowed");
+        sprintf(msg, "Crop: negative corner coordinates not allowed");

     if (width <= 0 || height <= 0)
-        sprintf(msg, "CropAbs: negative/zero cropping dimensions not allowed");
+        sprintf(msg, "Crop: negative/zero cropping dimensions not allowed");

     if (srcheight > 0 && srcwidth > 0)
         if (srcheight < height + y || srcwidth < width + x)
-            sprintf(msg, "CropAbs: cropped area extends beyond frame dimensions");
+            sprintf(msg, "Crop: cropped area extends beyond frame dimensions");

     if (fi) {
         if (width % (1 << fi->subSamplingW))
-            sprintf(msg, "CropAbs: cropped area needs to have mod %d width", 1 << fi->subSamplingW);
+            sprintf(msg, "Crop: cropped area needs to have mod %d width", 1 << fi->subSamplingW);

         if (height % (1 << fi->subSamplingH))
-            sprintf(msg, "CropAbs: cropped area needs to have mod %d height", 1 << fi->subSamplingH);
+            sprintf(msg, "Crop: cropped area needs to have mod %d height", 1 << fi->subSamplingH);

         if (x % (1 << fi->subSamplingW))
-            sprintf(msg, "CropAbs: cropped area needs to have mod %d width offset", 1 << fi->subSamplingW);
+            sprintf(msg, "Crop: cropped area needs to have mod %d width offset", 1 << fi->subSamplingW);

         if (y % (1 << fi->subSamplingH))
-            sprintf(msg, "CropAbs: cropped area needs to have mod %d height offset", 1 << fi->subSamplingH);
+            sprintf(msg, "Crop: cropped area needs to have mod %d height offset", 1 << fi->subSamplingH);
     }

     if (msg[0])
@@ -153,7 +153,7 @@

     if (!isConstantFormat(d.vi)) {
         vsapi->freeNode(d.node);
-        RETERROR("CropRel: constant format needed... for now");
+        RETERROR("CropRel: constant format needed");
     }

     d.x = int64ToIntS(vsapi->propGetInt(in, "left", 0, &err));


[core] Move @params to right location for NIActionSource

--- src/core/src/NIActions.h
+++ src/core/src/NIActions.h
@@ -143,14 +143,14 @@
 };
 #endif

-/**
- * The protocol for a data source that can be used with NIActions.
+/** The protocol for a data source that can be used with NIActions. */
+@protocol NIActionsDataSource <NSObject>
+
+/**
+ * The object located at the given indexPath.
  *
  * @param indexPath The index path of the requested object.
  */
-@protocol NIActionsDataSource <NSObject>
-
-/** The object located at the given indexPath. */
 - (id)objectAtIndexPath:(NSIndexPath *)indexPath;

 @end


Check number of operation files read-in

Check number of operation files read-in

--- src/cycles/cycles_init.c
+++ src/cycles/cycles_init.c
@@ -85,6 +85,12 @@
          * Copy crop management to each element
          */
         cropmgmt = &elem[i].cropmgmt;
+
+        if (agtbl->op[i] > agtbl->nopfile)
+        {
+            printf ("ERROR: Operation file for operation index %d is not provided!\n", agtbl->op[i]);
+            exit (1);
+        }

         opind = agtbl->op[i] - 1;


director: director_mail_servers setting can now contain host names.

--- src/director/mail-host.c
+++ src/director/mail-host.c
@@ -50,39 +50,35 @@

 static int mail_host_add(struct mail_host_list *list, const char *host)
 {
-	struct ip_addr ip;
-
-	if (net_addr2ip(host, &ip) < 0) {
-		i_error("Invalid IP address: %s", host);
-		return -1;
-	}
-
-	mail_host_add_ip(list, &ip);
+	struct ip_addr *ips;
+	unsigned int i, ips_count;
+
+	if (net_gethostbyname(host, &ips, &ips_count) < 0) {
+		i_error("Unknown mail host: %s", host);
+		return -1;
+	}
+
+	for (i = 0; i < ips_count; i++)
+		mail_host_add_ip(list, &ips[i]);
 	return 0;
 }

 static int
-mail_hosts_add_range(struct mail_host_list *list, const char *host1, const char *host2)
-{
-	struct ip_addr ip1, ip2;
+mail_hosts_add_range(struct mail_host_list *list,
+		     struct ip_addr ip1, struct ip_addr ip2)
+{
 	uint32_t *ip1_arr, *ip2_arr;
 	uint32_t i1, i2;
 	unsigned int i, j, max_bits, last_bits;

-	if (net_addr2ip(host1, &ip1) < 0) {
-		i_error("Invalid IP address: %s", host1);
-		return -1;
-	}
-	if (net_addr2ip(host2, &ip2) < 0) {
-		i_error("Invalid IP address: %s", host2);
-		return -1;
-	}
 	if (ip1.family != ip2.family) {
-		i_error("IP address family mismatch: %s vs %s", host1, host2);
+		i_error("IP address family mismatch: %s vs %s",
+			net_ip2addr(&ip1), net_ip2addr(&ip2));
 		return -1;
 	}
 	if (net_ip_cmp(&ip1, &ip2) > 0) {
-		i_error("IP addresses reversed: %s-%s", host1, host2);
+		i_error("IP addresses reversed: %s-%s",
+			net_ip2addr(&ip1), net_ip2addr(&ip2));
 		return -1;
 	}
 	if (IPADDR_IS_V4(&ip1)) {
@@ -106,7 +102,7 @@
 	for (i = 0; i < (max_bits-last_bits)/32; i++) {
 		if (ip1_arr[i] != ip2_arr[i]) {
 			i_error("IP address range too large: %s-%s",
-				host1, host2);
+				net_ip2addr(&ip1), net_ip2addr(&ip2));
 			return -1;
 		}
 	}
@@ -116,7 +112,7 @@
 	for (j = last_bits; j < 32; j++) {
 		if ((i1 & (1 << j)) != (i2 & (1 << j))) {
 			i_error("IP address range too large: %s-%s",
-				host1, host2);
+				net_ip2addr(&ip1), net_ip2addr(&ip2));
 			return -1;
 		}
 	}
@@ -136,16 +132,26 @@
 	int ret = 0;

 	T_BEGIN {
-		const char *const *tmp, *p;
+		const char *const *tmp, *p, *host1, *host2;
+		struct ip_addr ip1, ip2;

 		tmp = t_strsplit_spaces(hosts_string, " ");
 		for (; *tmp != NULL; tmp++) {
 			p = strchr(*tmp, '-');
-			if (p == NULL) {
-				if (mail_host_add(list, *tmp) < 0)
-					ret = -1;
-			} else if (mail_hosts_add_range(list, t_strdup_until(*tmp, p),
-							p + 1) < 0)
+			if (p != NULL) {
+				/* see if this is ip1-ip2 range */
+				host1 = t_strdup_until(*tmp, p);
+				host2 = p + 1;
+				if (net_addr2ip(host1, &ip1) == 0 &&
+				    net_addr2ip(host2, &ip2) == 0) {
+					if (mail_hosts_add_range(list, ip1,
+								 ip2) < 0)
+						ret = -1;
+					continue;
+				}
+			}
+
+			if (mail_host_add(list, *tmp) < 0)
 				ret = -1;
 		}
 	} T_END;


doveadm: Compile fix for previous auth change.

--- src/doveadm/doveadm-pw.c
+++ src/doveadm/doveadm-pw.c
@@ -95,7 +95,8 @@
 		size_t size;
 		const char *error;

-		if (password_decode(hash, scheme, &raw_password, &size) <= 0) {
+		if (password_decode(hash, scheme, &raw_password, &size,
+				    &error) <= 0) {
 			fprintf(stderr, "reverse decode check failed\n");
 			exit(2);
 		}


separate ext strings with a space

separate ext strings with a space

--- src/egl/main/egldriver.c
+++ src/egl/main/egldriver.c
@@ -207,9 +207,9 @@
    drv->Extensions[0] = 0;

    if (drv->MESA_screen_surface)
-      strcat(drv->Extensions, "EGL_MESA_screen_surface");
+      strcat(drv->Extensions, "EGL_MESA_screen_surface ");
    if (drv->MESA_copy_context)
-      strcat(drv->Extensions, "EGL_MESA_copy_context");
+      strcat(drv->Extensions, "EGL_MESA_copy_context ");
    assert(strlen(drv->Extensions) < MAX_EXTENSIONS_LEN);
 }


reenable debug

reenable debug

--- src/elasticsearch-conn.c
+++ src/elasticsearch-conn.c
@@ -82,7 +82,7 @@
         http_set.max_pipelined_requests = 1;
         http_set.max_redirects = 1;
         http_set.max_attempts = 3;
-        http_set.debug = FALSE; /*todo: debug*/
+        http_set.debug = debug;
         elasticsearch_http_client = http_client_init(&http_set);
     }


command.c: cleanup code

command.c: cleanup code

--- src/emc/motion/command.c
+++ src/emc/motion/command.c
@@ -1423,11 +1423,6 @@
             break;

 	case EMCMOT_CLEAR_PROBE_FLAGS:
-//	    rtapi_print_msg(RTAPI_MSG_DBG, "CLEAR_PROBE_FLAGS");
-//	    if (emcmotStatus->probe_cmd != USB_CMD_NOOP) {
-//	        reportError(_("initiate probe command while usb_cmd is not USB_CMD_NOOP"));
-//	        fprintf(stderr,"initiate probe command while usb_cmd is not USB_CMD_NOOP");
-//	    }
 	    break;

 	case EMCMOT_PROBE:
@@ -1504,7 +1499,7 @@
                   emcmotStatus->usb_cmd |= PROBE_CMD_TYPE;
                   emcmotStatus->usb_cmd_param[0] = (double) USB_CMD_PROBE_LOW;
                 }
-                fprintf(stderr,"usb_cmd(0x%0x) usb_cmd_param(%f)\n",
+                fprintf(stderr,"command.c: usb_cmd(0x%0x) usb_cmd_param(%f)\n",
                     emcmotStatus->usb_cmd, emcmotStatus->usb_cmd_param[0]);
 	    }
 	    break;


fix: current css value error

fix: current css value error

Signed-off-by: Eric, Hsu-yao Tsai <ad8e9cf61b582456bbe32d188af06658a1707686@araisrobo.com>

--- src/emc/motion/control.c
+++ src/emc/motion/control.c
@@ -30,6 +30,7 @@

 // Mark strings for translation, but defer translation to userspace
 #define _(s) (s)
+#define PI                      3.141592653589

 /* kinematics flags */
 KINEMATICS_FORWARD_FLAGS fflags = 0;
@@ -1750,7 +1751,9 @@
 	*(emcmot_hal_data->spindle_speed_out_rps) = speed/60.;
 	/* calculate css and exprot to hal pin */
 	// TODO: confirm rad or diam mode??
-	*(emcmot_hal_data->spindle_css) = *(emcmot_hal_data->spindle_speed_out_rps) * denom * 0.5;
+	*(emcmot_hal_data->spindle_css) = *(emcmot_hal_data->spindle_speed_out_rps) * denom * 2 * PI;
+	/*fprintf(stderr," css_factor(%f) spindle_speed_out(%f) denom(%f) cs(%f) \n",emcmotStatus->spindle.css_factor,  speed,
+	        denom, emcmotStatus->spindle.css_factor*2*PI/60);*/
     } else {
 	*(emcmot_hal_data->spindle_speed_out) = emcmotStatus->spindle.speed * emcmotStatus->net_spindle_scale;
 	*(emcmot_hal_data->spindle_speed_out_rps) = emcmotStatus->spindle.speed * emcmotStatus->net_spindle_scale / 60.;


LuaWrapper cleanup - closes #828

LuaWrapper cleanup - closes #828


fixed linux

fixed linux

--- src/engine/lua_wrapper.h
+++ src/engine/lua_wrapper.h
@@ -15,6 +15,7 @@

 struct Universe;
 struct CameraParams;
+struct PipelineTexture;

 namespace LuaWrapper
 {
@@ -534,6 +535,7 @@
 }

 void push(lua_State* L, const CameraParams& value);
+void push(lua_State* L, const PipelineTexture& value);

 inline void push(lua_State* L, float value)
 {


small tweaks

small tweaks

--- src/fiber_event_native.c
+++ src/fiber_event_native.c
@@ -82,11 +82,11 @@
     }
 }

-static int fiber_poll_events_internal(int wait_ms)
+static int fiber_poll_events_internal(uint32_t seconds, uint32_t useconds)
 {
 #if defined(LINUX)
     struct epoll_event events[64];
-    const int count = epoll_wait(event_fd, events, 64, 0);
+    const int count = epoll_wait(event_fd, events, 64, seconds * 1000 + useconds / 1000);
     if(count < 0) {
         assert(count >= 0 && "epoll_wait failed!");
         const char* err_msg = "epoll_wait failed!";
@@ -117,7 +117,7 @@
     port_event_t events[64];
     uint_t nget = 1;
     errno = 0;
-    timespec_t timeout = {wait_ms / 1000, wait_ms * 1000000};
+    timespec_t timeout = {seconds, useconds * 1000};
     const int ret = port_getn(event_fd, events, 64, &nget, &timeout);
     fiber_manager_t* const manager = fiber_manager_get();
     uint_t i;
@@ -150,7 +150,7 @@
         return FIBER_EVENT_NOTINIT;
     }

-    return fiber_poll_events_internal(0);
+    return fiber_poll_events_internal(0, 0);
 }

 size_t fiber_poll_events_blocking(uint32_t seconds, uint32_t useconds)
@@ -160,7 +160,7 @@
         return 0;
     }

-    return fiber_poll_events_internal(seconds * 1000 + useconds / 1000);
+    return fiber_poll_events_internal(seconds, useconds);
 }

 int fiber_wait_for_event(int fd, uint32_t events)
@@ -241,7 +241,7 @@
 #else
 #error OS not supported
 #endif
-    //result = -1 -> this indicates to fiber_wait_for_event that the fd was closed
+    //setting result to -1 indicates to fiber_wait_for_event that the fd was closed
     fiber_event_wake_waiters(fiber_manager_get(), info, -1);
     fiber_spinlock_unlock(&info->spinlock);
 }


fix for solaris cpu usage

fix for solaris cpu usage

--- src/fiber_event_native.c
+++ src/fiber_event_native.c
@@ -291,6 +291,7 @@
         (void)ret;
         abort();
     }
+    return nget;
 #else
 #error OS not supported
 #endif


filter|symsync: moving loop filter to iirfiltsos object

--- src/filter/src/symsync.c
+++ src/filter/src/symsync.c
@@ -38,10 +38,6 @@
 #include <string.h>
 #include <math.h>

-// use theoretical 2nd-order integrating PLL filter?
-// NOTE: works ok for k_out=[1,2]
-#define SYMSYNC_USE_PLL         0
-
 #define DEBUG_SYMSYNC           0
 #define DEBUG_SYMSYNC_PRINT     0
 #define DEBUG_SYMSYNC_FILENAME  "symsync_internal_debug.m"
@@ -68,27 +64,19 @@

     // floating-point phase
     float tau;                  // accumulated timing phase (0 <= tau <= 1)
+    float tau_decim;            // timing phase, retained for get_tau() method
     float bf;                   // soft filterbank index

     // loop filter
-    float alpha;                // percent of old error sample to retain
-    float beta;                 // percent of new error sample to retain
-    float q;                    // instantaneous timing error estimate
-    float q_hat;                // filtered timing error estimate
-    float q_prime;              // buffered timing error estimate
-    float q_tmp;                // buffered timing error estimate (level 2)
-#if SYMSYNC_USE_PLL
-    // phase-locked loop
-    float B[3];
-    float A[3];
-    iirfiltsos_rrrf pll;
-#endif
+    float q;                    // instantaneous timing error
+    float q_hat;                // filtered timing error
+    float B[3];                 // loop filter feed-forward coefficients
+    float A[3];                 // loop filter feed-back coefficients
+    iirfiltsos_rrrf pll;        // loop filter object (iir filter)

     unsigned int npfb;
-    FIRPFB()  mf;   // matched filter
-    FIRPFB() dmf;   // derivative matched filter
-
-    float tau_decim;            // timing phase, retained for get_tau() method
+    FIRPFB()  mf;               // matched filter
+    FIRPFB() dmf;               // derivative matched filter

 #if DEBUG_SYMSYNC
     windowf debug_del;
@@ -156,12 +144,10 @@
     q->dmf = FIRPFB(_create)(q->npfb, dh, _h_len);

     // reset state and initialize loop filter
-#if SYMSYNC_USE_PLL
     q->A[0] = 1.0f;     q->B[0] = 0.0f;
     q->A[1] = 0.0f;     q->B[1] = 0.0f;
     q->A[2] = 0.0f;     q->B[2] = 0.0f;
     q->pll = iirfiltsos_rrrf_create(q->B, q->A);
-#endif
     SYMSYNC(_clear)(q);
     SYMSYNC(_set_lf_bw)(q, 0.01f);

@@ -242,9 +228,7 @@
     FIRPFB(_destroy)(_q->mf);
     FIRPFB(_destroy)(_q->dmf);

-#if SYMSYNC_USE_PLL
     iirfiltsos_rrrf_destroy(_q->pll);
-#endif

     // free main object memory
     free(_q);
@@ -265,13 +249,9 @@
     _q->bf      = 0.0f;
     _q->q       = 0.0f;
     _q->q_hat   = 0.0f;
-    _q->q_prime = 0.0f;
-    _q->q_tmp   = 0.0f;
     _q->decim_counter = 0;
     _q->tau_decim     = 0.0f;
-#if SYMSYNC_USE_PLL
     iirfiltsos_rrrf_clear(_q->pll);
-#endif
 }

 void SYMSYNC(_clear)(SYMSYNC() _q) {
@@ -311,16 +291,20 @@
         exit(1);
     }

-#if SYMSYNC_USE_PLL
-    float zeta = 1.1f;
-    float K = 1000.0f;
-    iirdes_pll_active_lag(0.5f*_bt, zeta, K, _q->B, _q->A);
+    float alpha = 1.000f - _bt;
+    float beta  = 0.220f * _bt;
+    float a     = 0.500f;
+    float b     = 0.495f;
+
+    _q->B[0] = beta;
+    _q->B[1] = 0.00f;
+    _q->B[2] = 0.00f;
+
+    _q->A[0] = 1.00f - a*alpha;
+    _q->A[1] = -b*alpha;
+    _q->A[2] = 0.00f;
+
     iirfiltsos_rrrf_set_coefficients(_q->pll, _q->B, _q->A);
-#else
-    // set loop filter bandwidth
-    _q->alpha = 1.00f - _bt;    // percent of old sample to retain
-    _q->beta  = 0.22f * _bt;    // percent of new sample to retain
-#endif
 }

 // set synchronizer output rate (samples/symbol)
@@ -388,19 +372,9 @@

     //  2.  filter error signal: retain large percent (alpha) of
     //      old estimate and small percent (beta) of new estimate
-#if SYMSYNC_USE_PLL
     iirfiltsos_rrrf_execute(_q->pll, _q->q, &_q->q_hat);
     _q->del = (float)(_q->k)/(float)(_q->k_out) + _q->q_hat;
     //_q->del = (float)(_q->k) * (1 + _q->q_hat);
-#else
-    _q->q_hat   = (_q->q)*(_q->beta) + (_q->q_prime)*(_q->alpha);
-    _q->q_prime = _q->q_hat * 0.50f + _q->q_tmp * 0.49f;
-    _q->q_tmp   = _q->q_prime;
-
-    // TODO : check the output step size, relative to input
-    //_q->del     = (float)(_q->k) + _q->q_hat;
-    _q->del     = (float)(_q->k)/(float)(_q->k_out) + _q->q_hat;
-#endif

 #if DEBUG_SYMSYNC_PRINT
     printf("q : %12.8f, del : %12.8f, q_hat : %12.8f\n", _q->q, _q->del, _q->q_hat);
@@ -460,11 +434,7 @@
         }
         _q->decim_counter++;

-#if SYMSYNC_USE_PLL
-        _q->tau     = _q->del;
-#else
         _q->tau += _q->del;
-#endif
         _q->bf = _q->tau * (float)(_q->npfb);
         _q->b  = (int)roundf(_q->bf);
         n++;
@@ -490,10 +460,6 @@

     fprintf(fid,"npfb = %u;\n",_q->npfb);
     fprintf(fid,"k = %u;\n",_q->k);
-    fprintf(fid,"\n\n");
-
-    fprintf(fid,"alpha = %12.5e;\n",_q->alpha);
-    fprintf(fid,"beta = %12.5e;\n",_q->beta);
     fprintf(fid,"\n\n");

 #if DEBUG_SYMSYNC


Wii: Enable savestates

Wii: Enable savestates

--- src/gba/gui/gui-runner.c
+++ src/gba/gui/gui-runner.c
@@ -156,8 +156,6 @@
 	GUIMenuItemListInit(&stateSaveMenu.items, 9);
 	GUIMenuItemListInit(&stateLoadMenu.items, 9);
 	*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Unpause", .data = (void*) RUNNER_CONTINUE };
-#if !(defined(__POWERPC__) || defined(__PPC__))
-	// PPC doesn't have working savestates yet
 	*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Save state", .submenu = &stateSaveMenu };
 	*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Load state", .submenu = &stateLoadMenu };

@@ -180,7 +178,7 @@
 	*GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 7", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_7) };
 	*GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 8", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_8) };
 	*GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 9", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_9) };
-#endif
+
 	*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Take screenshot", .data = (void*) RUNNER_SCREENSHOT };
 	*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Configure", .data = (void*) RUNNER_CONFIG };
 	*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Exit game", .data = (void*) RUNNER_EXIT };


glsl: Hook up loop_variable_state destructor to plug a memory leak.

While ~loop_state() is already freeing the loop_variable_state objects
via ralloc_free(this->mem_ctx), the ~loop_variable_state() destructor
was never getting called, so the hash table inside loop_variable_state
was never getting destroyed.

Fixes a memory leak in any shader with loops.

NOTE: This is a candidate for stable release branches.

Signed-off-by: Kenneth Graunke <bd2562f754ec92342f93f61c25d731e290a2ffa8@whitecape.org>

--- src/glsl/loop_analysis.h
+++ src/glsl/loop_analysis.h
@@ -140,6 +140,23 @@
    {
       hash_table_dtor(this->var_hash);
    }
+
+   static void* operator new(size_t size, void *ctx)
+   {
+      void *lvs = ralloc_size(ctx, size);
+      assert(lvs != NULL);
+
+      ralloc_set_destructor(lvs, (void (*)(void*)) destructor);
+
+      return lvs;
+   }
+
+private:
+   static void
+   destructor(loop_variable_state *lvs)
+   {
+      lvs->~loop_variable_state();
+   }
 };


gmio_stla: improve error report for input operation, accept mixed-case text

--- src/gmio_stl/stla_read.c
+++ src/gmio_stl/stla_read.c
@@ -156,13 +156,89 @@
     return -3;
 }

-GMIO_INLINE void parsing_error(gmio_stla_parse_data_t* data)
-{
+GMIO_INLINE const char* token_to_string(gmio_stla_token_t token)
+{
+    switch (token) {
+    case ENDFACET_token: return "endfacet";
+    case ENDLOOP_token: return "endloop";
+    case ENDSOLID_token: return "endsolid";
+    case FACET_token: return "facet";
+    case ID_token: return "ID";
+    /*case FLOAT_token: return "FLOAT";*/
+    case LOOP_token: return "loop";
+    case NORMAL_token: return "normal";
+    case OUTER_token: return "outer";
+    case SOLID_token: return "solid";
+    case VERTEX_token: return "vertex";
+    case empty_token:
+    case unknown_token: return "";
+    }
+    return "";
+}
+
+GMIO_INLINE void parsing_error_msg(
+        gmio_stla_parse_data_t* data, const char* msg)
+{
+    fprintf(stderr,
+            "\n"
+            "gmio_stla_read() parsing error: %s\n"
+            "                 current token: <%s>\n"
+            "                 current token string: \"%s\"\n",
+            msg,
+            token_to_string(data->token),
+            data->string_buffer.ptr);
     data->error = GMIO_TRUE;
     data->token = unknown_token;
-    fprintf(stderr,
-            "\n[gmio_stla_read()] parsing_error, token: \"%s\"\n",
-            data->string_buffer.ptr);
+}
+
+GMIO_INLINE void parsing_error(gmio_stla_parse_data_t* data)
+{
+    parsing_error_msg(data, "unknown");
+}
+
+GMIO_INLINE void parsing_error_token_expected(
+        gmio_stla_parse_data_t* data, gmio_stla_token_t token)
+{
+    char msg[256] = { 0 };
+    sprintf(msg,
+            "token <%s> expected, got <%s>",
+            token_to_string(token),
+            token_to_string(data->token));
+    parsing_error_msg(data, msg);
+}
+
+GMIO_INLINE gmio_bool_t gmio_clocale_char_iequals(char c1, char c2)
+{
+    return c1 == c2 || c1 == (c2 - 32) ? GMIO_TRUE : GMIO_FALSE;
+}
+
+/*! Returns 0 if \p str1 and \p str2 compare equal, non-zero otherwise
+ *
+ *  It assumes that <tt>len(str1) >= len(str2)</tt>
+ */
+GMIO_INLINE int gmio_stricmp(const char* str1, const char* str2)
+{
+    while (*str1 != 0 && *str2 != 0) {
+        if (gmio_clocale_char_iequals(*str1, *str2) == GMIO_FALSE)
+            return 1;
+        ++str1;
+        ++str2;
+    }
+    return *str1 == 0 && *str2 == 0 ? 0 : 1;
+}
+
+GMIO_INLINE gmio_bool_t gmio_istarts_with(const char* str, const char* begin)
+{
+    while (*begin != 0) {
+        if (*str == 0
+                || gmio_clocale_char_iequals(*str, *begin) == GMIO_FALSE)
+        {
+            return GMIO_FALSE;
+        }
+        ++str;
+        ++begin;
+    }
+    return GMIO_TRUE;
 }

 static gmio_stla_token_t parsing_find_token(
@@ -180,32 +256,32 @@
         switch (word[0]) {
         case 'f':
         case 'F':
-            if (strcmp(word + 1, "acet") == 0)
+            if (gmio_stricmp(word + 1, "acet") == 0)
                 return FACET_token;
             break;
         case 'l':
         case 'L':
-            if (strcmp(word + 1, "oop") == 0)
+            if (gmio_stricmp(word + 1, "oop") == 0)
                 return LOOP_token;
             break;
         case 'n':
         case 'N':
-            if (strcmp(word + 1, "ormal") == 0)
+            if (gmio_stricmp(word + 1, "ormal") == 0)
                 return NORMAL_token;
             break;
         case 'o':
         case 'O':
-            if (strcmp(word + 1, "uter") == 0)
+            if (gmio_stricmp(word + 1, "uter") == 0)
                 return OUTER_token;
             break;
         case 's':
         case 'S':
-            if (strcmp(word + 1, "olid") == 0)
+            if (gmio_stricmp(word + 1, "olid") == 0)
                 return SOLID_token;
             break;
         case 'v':
         case 'V':
-            if (strcmp(word + 1, "ertex") == 0)
+            if (gmio_stricmp(word + 1, "ertex") == 0)
                 return VERTEX_token;
             break;
         default:
@@ -214,21 +290,21 @@
     }

     /* Might be "end..." token */
-    if (word_len >= 7 && strncmp(word, "end", 3) == 0) {
+    if (word_len >= 7 && gmio_istarts_with(word, "end") == GMIO_TRUE) {
         switch (word[3]) {
         case 'f':
         case 'F':
-            if (strcmp(word + 4, "acet") == 0)
+            if (gmio_stricmp(word + 4, "acet") == 0)
                 return ENDFACET_token;
             break;
         case 'l':
         case 'L':
-            if (strcmp(word + 4, "oop") == 0)
+            if (gmio_stricmp(word + 4, "oop") == 0)
                 return ENDLOOP_token;
             break;
         case 's':
         case 'S':
-            if (strcmp(word + 4, "olid") == 0)
+            if (gmio_stricmp(word + 4, "olid") == 0)
                 return ENDSOLID_token;
             break;
         default:
@@ -262,7 +338,7 @@
     if (data->token == token)
         parsing_advance(data);
     else
-        parsing_error(data);
+        parsing_error_token_expected(data, token);
 }

 static void parse_solidname_beg(gmio_stla_parse_data_t* data)
@@ -276,7 +352,7 @@
     case ID_token:
         break;
     default:
-        parsing_error(data);
+        parsing_error_msg(data, "unexpected token for 'solid <name>'");
     }
 }

@@ -291,7 +367,7 @@
     case empty_token:
         break;
     default:
-        parsing_error(data);
+        parsing_error_msg(data, "unexpected token for 'endsolid <name>'");
     }
 }

@@ -315,7 +391,7 @@
         break;
     }
     default:
-        parsing_error(data);
+        parsing_error_token_expected(data, SOLID_token);
     } /* end switch */
 }

@@ -335,7 +411,7 @@
         break;
     }
     default:
-        parsing_error(data);
+        parsing_error_token_expected(data, ENDSOLID_token);
     } /* end switch */
 }

@@ -348,13 +424,13 @@
     switch (data->token) {
     case FLOAT_token: {
         if (get_current_token_as_float32(data, &coords->x) != 0)
-            parsing_error(data);
+            parsing_error_msg(data, "failed to get X coord");
         parsing_eat_token(FLOAT_token, data);
         if (get_current_token_as_float32(data, &coords->y) != 0)
-            parsing_error(data);
+            parsing_error_msg(data, "failed to get Y coord");
         parsing_eat_token(FLOAT_token, data);
         if (get_current_token_as_float32(data, &coords->z) != 0)
-            parsing_error(data);
+            parsing_error_msg(data, "failed to get Z coord");
         parsing_eat_token(FLOAT_token, data);
         break;
     }


Fixed compile failure with older glx headers.

git-svn-id: f4e1a40f847802203273bde8e26df4d11611876a@7951 44470bb9-56e9-0310-a0f8-c586564d3dc6

--- src/graphics/OGLHelper.h
+++ src/graphics/OGLHelper.h
@@ -49,6 +49,9 @@
 // this function.
 #ifndef PFNGLXSWAPINTERVALEXTPROC
 typedef int ( * PFNGLXSWAPINTERVALEXTPROC) (Display *dpy, GLXDrawable drawable, int interval);
+#endif
+#ifndef GLX_CONTEXT_ES2_PROFILE_BIT_EXT
+    #define GLX_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004
 #endif
 #endif


Add missing include to parchment.c.

Add missing include to parchment.c.

--- src/graphics/parchment.c
+++ src/graphics/parchment.c
@@ -32,6 +32,8 @@

 #include <SDL.h>
 #include <SDL_image.h>
+
+#include <string.h>

 #include "../bsd.h"


fixed hmac-sha3

fixed hmac-sha3

--- src/hash/api_hash_sha3.h
+++ src/hash/api_hash_sha3.h
@@ -22,44 +22,64 @@

 NAMESPACE_BEGIN(CryptoppApi)

+class CryptoppSha3_224 : public CryptoPP::SHA3_224
+{
+public:
+    unsigned int BlockSize() const {return 72;}
+};
+
+class CryptoppSha3_256 : public CryptoPP::SHA3_256
+{
+public:
+    unsigned int BlockSize() const {return 104;}
+};
+
+class CryptoppSha3_384 : public CryptoPP::SHA3_384
+{
+public:
+    unsigned int BlockSize() const {return 136;}
+};
+
+class CryptoppSha3_512 : public CryptoPP::SHA3_512
+{
+public:
+    unsigned int BlockSize() const {return 144;}
+};
+
 class HashSha3_224 : public HashAbstract
 {
 public:
     HashSha3_224();
-    size_t getBlockSize() const {return 72;}

 private:
-    CryptoPP::SHA3_224 m_hash;
+    CryptoppSha3_224 m_hash;
 };

 class HashSha3_256 : public HashAbstract
 {
 public:
     HashSha3_256();
-    size_t getBlockSize() const {return 104;}

 private:
-    CryptoPP::SHA3_256 m_hash;
+    CryptoppSha3_256 m_hash;
 };

 class HashSha3_384 : public HashAbstract
 {
 public:
     HashSha3_384();
-    size_t getBlockSize() const {return 136;}

 private:
-    CryptoPP::SHA3_384 m_hash;
+    CryptoppSha3_384 m_hash;
 };

 class HashSha3_512 : public HashAbstract
 {
 public:
     HashSha3_512();
-    size_t getBlockSize() const {return 144;}

 private:
-    CryptoPP::SHA3_512 m_hash;
+    CryptoppSha3_512 m_hash;
 };

 NAMESPACE_END


Adds Windows Server 2012 and Windows 8 detection to os_getversion as per the details from http://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx

--- src/host/os_getversion.c
+++ src/host/os_getversion.c
@@ -133,6 +133,17 @@
 		else
 		{
 			info->description = "Windows 7";
+		}
+	}
+	else if (versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion == 2 )
+	{
+		if (versionInfo.wProductType != VER_NT_WORKSTATION)
+		{
+			info->description = "Windows Server 2012";
+		}
+		else
+		{
+			info->description = "Windows 8";
 		}
 	}
 	else


Remove unused variable.

Remove unused variable.

BUG=None
TEST=None
CID=12579

Review URL: http://codereview.chromium.org/3136023

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@57842 0039d316-1c4b-4281-b951-d872f2087c98

--- chrome/service/remoting/remoting_directory_service.h
+++ chrome/service/remoting/remoting_directory_service.h
@@ -31,7 +31,7 @@
     virtual void OnRemotingDirectoryError() {}
   };

-  RemotingDirectoryService(Client* client);
+  explicit RemotingDirectoryService(Client* client);
   ~RemotingDirectoryService();

   // Add this computer as host. Use the token for authentication.
@@ -59,9 +59,6 @@
   Client* client_;
   scoped_ptr<URLFetcher> fetcher_;

-  // True if a URL request has made and response is pending.
-  bool request_pending_;
-
   // Host key generated during host registration.
   scoped_ptr<remoting::HostKeyPair> host_key_pair_;

@@ -72,4 +69,4 @@
   DISALLOW_COPY_AND_ASSIGN(RemotingDirectoryService);
 };

-#endif // CHROME_SERVICE_REMOTING_REMOTING_DIRECTORY_SERVICE_H_
+#endif  // CHROME_SERVICE_REMOTING_REMOTING_DIRECTORY_SERVICE_H_


Handle strings for Python 2

Handle strings for Python 2

--- com.ibm.streamsx.topology/opt/python/include/splpy.h
+++ com.ibm.streamsx.topology/opt/python/include/splpy.h
@@ -51,28 +51,6 @@
 while(0)

 #if PY_MAJOR_VERSION == 3
-#define GET_PYTHON_VALUE_AS_UTF8_AND_ASSIGN(pvalue,pattr)                \
-do {                                                                     \
-      Py_ssize_t size = 0;                                               \
-      char * bytes = PyUnicode_AsUTF8AndSize(pvalue, &size);             \
-      GET_PYTHON_VALUE_THROWIFERROR(bytes);                              \
-      pattr.assign((const char *)bytes, (size_t) size);                  \
-   }                                                                     \
-while(0)
-#else
-#define GET_PYTHON_VALUE_AS_UTF8_AND_ASSIGN(pvalue,pattr)                \
-do {                                                                     \
-      Py_ssize_t size = 0;                                               \
-      PyObject *utf8String = PyUnicode_AsUTF8String(pvalue);             \
-      char *bytes = PyString_AsString(utf8String);                       \
-      GET_PYTHON_VALUE_THROWIFERROR(bytes);                              \
-      pattr.assign((const char *)bytes, strlen((const char *)bytes));    \
-      Py_DECREF(utf8String);                                             \
-   }                                                                     \
-while(0)
-#endif
-
-#if PY_MAJOR_VERSION == 3
 #define GET_PYTHON_ATTR_FROM_MEMORY(pbytes,psizeb)                       \
      PyMemoryView_FromMemory((char *) pbytes, psizeb, PyBUF_READ);
 #else
@@ -115,8 +93,44 @@
     /*
     ** Convert to a SPL rstring from a Python string object.
     */
-    inline void pyAttributeFromPyObject(SPL::rstring & attr, PyObject * value) {
-      GET_PYTHON_VALUE_AS_UTF8_AND_ASSIGN(value,attr);
+    inline SPL::rstring & pyAttributeFromPyObject(SPL::rstring & attr, PyObject * value) {
+      Py_ssize_t size = 0;
+      char * bytes = NULL;
+
+#if PY_MAJOR_VERSION == 3
+      // Python 3 character strings are unicode objects
+      if (PyUnicode_Check(value)) {
+          bytes = PyUnicode_AsUTF8AndSize(value, &size);
+          GET_PYTHON_VALUE_THROWIFERROR(bytes);
+      } else {
+          // Create a string from the object
+          PyObject *svalue = PyObject_Str(value);
+          bytes = PyUnicode_AsUTF8AndSize(svalue, &size);
+          Py_DECREF(svalue);
+          GET_PYTHON_VALUE_THROWIFERROR(bytes);
+      }
+#else
+      // Python 2 supports Unicode and byte character strings
+      // Default is byte character strings.
+      if (PyUnicode_Check(value)) {
+          PyObject *utf8String = PyUnicode_AsUTF8String(pvalue);
+          int x = PyString_AsStringAndSize(utf8String, &bytes, &size);
+          Py_DECREF(utf8String);
+          GET_PYTHON_VALUE_THROWIFERROR(bytes);
+      } else if (PyString_Check(value)) {
+          int x = PyString_AsStringAndSize(value, &bytes, &size);
+          // TODO
+      } else {
+          // Create a string from the object
+          PyObject *svalue = PyObject_Str(value);
+          int x = PyString_AsStringAndSize(svalue, &bytes, &size);
+          Py_DECREF(*svalue);
+         // TODO
+      }
+#endif
+      attr.assign((const char *)bytes, (size_t) size);
+
+      return attr;
     }

     /**************************************************************/


modified SoftClipping algorithm

modified SoftClipping algorithm

--- src/audio-effects/base-effect.c
+++ src/audio-effects/base-effect.c
@@ -68,17 +68,20 @@
 void SoftClipping(volatile float* pData, float threshold){
     register uint32_t i;
     register float gg = powf(10, (threshold / 10.0f)) * SAMPLE_MAX;
-    float ff;
-
+    float ratio = 1;
+    float tmp = 1 / (ratio * gg);
     for (i = 0; i < SAMPLE_NUM; i++){
-        if (pData[i] > gg){
-            arm_sqrt_f32((pData[i] - gg), &ff);
-            pData[i] = gg + ff;
-        }else if (pData[i] < -gg){
-            arm_sqrt_f32((-pData[i] - gg), &ff);
-            pData[i] = -gg + ff;
+        if (pData[i] > ratio * gg){
+            pData[i] = gg;
+        }
+        else if (pData[i] < -ratio * gg){
+            pData[i] = -gg;
+        }
+        else{
+            pData[i] = arm_sin_f32(PI * pData[i] * 0.5 * tmp) * gg;
         }
     }
+
     return;
 }


auth: Ignore empty initial response strings.

--- src/auth/auth-request-handler.c
+++ src/auth/auth-request-handler.c
@@ -362,7 +362,10 @@
 		return TRUE;
 	}

-	if (initial_resp == NULL) {
+	/* Empty initial response is a "=" base64 string. Completely empty
+	   string shouldn't really be sent, but at least Exim does it,
+	   so just allow it for backwards compatibility.. */
+	if (initial_resp == NULL || *initial_resp == '\0') {
 		initial_resp_data = NULL;
 		initial_resp_len = 0;
 	} else {


Include missing library

Include missing library

Change-Id: I054d2d357261068adb1a5747e8618eac429ef5f3
Signed-off-by: Brian McGillion <e5584ecd8ee5868d4650d758a8412085be93f4f1@intel.com>

--- conn_test_app/conn_test_app.c
+++ conn_test_app/conn_test_app.c
@@ -20,6 +20,7 @@
 #include "tee_client_api.h"

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

 int main()
 {


Further twiddling of nodeHash.c hashtable sizing calculation.

On reflection, the submitted patch didn't really work to prevent the
request size from exceeding MaxAllocSize, because of the fact that we'd
happily round nbuckets up to the next power of 2 after we'd limited it to
max_pointers.  The simplest way to enforce the limit correctly is to
round max_pointers down to a power of 2 when it isn't one already.

(Note that the constraint to INT_MAX / 2, if it were doing anything useful
at all, is properly applied after that.)

--- src/backend/executor/nodeHash.c
+++ src/backend/executor/nodeHash.c
@@ -415,6 +415,7 @@
 	long		hash_table_bytes;
 	long		skew_table_bytes;
 	long		max_pointers;
+	long		mppow2;
 	int			nbatch = 1;
 	int			nbuckets;
 	double		dbuckets;
@@ -485,14 +486,20 @@
 	 */
 	max_pointers = (work_mem * 1024L) / sizeof(HashJoinTuple);
 	max_pointers = Min(max_pointers, MaxAllocSize / sizeof(HashJoinTuple));
-	/* also ensure we avoid integer overflow in nbatch and nbuckets */
+	/* If max_pointers isn't a power of 2, must round it down to one */
+	mppow2 = 1L << my_log2(max_pointers);
+	if (max_pointers != mppow2)
+		max_pointers = mppow2 / 2;
+
+	/* Also ensure we avoid integer overflow in nbatch and nbuckets */
 	/* (this step is redundant given the current value of MaxAllocSize) */
 	max_pointers = Min(max_pointers, INT_MAX / 2);

 	dbuckets = ceil(ntuples / NTUP_PER_BUCKET);
 	dbuckets = Min(dbuckets, max_pointers);
+	nbuckets = (int) dbuckets;
 	/* don't let nbuckets be really small, though ... */
-	nbuckets = Max((int) dbuckets, 1024);
+	nbuckets = Max(nbuckets, 1024);
 	/* ... and force it to be a power of 2. */
 	nbuckets = 1 << my_log2(nbuckets);


Remove obsolete code to create 'pg_stat_tmp' directory on demand.

It is created by initdb these days, as hinted by the comment.

--- src/backend/postmaster/pgstat.c
+++ src/backend/postmaster/pgstat.c
@@ -70,8 +70,6 @@
 #include "utils/tqual.h"
 #include "cdb/cdbvars.h"

-// for mkdir
-#include "sys/stat.h"

 /* ----------
  * Timer definitions.
@@ -359,13 +357,6 @@
 	 */
 	StaticAssertStmt(sizeof(PgStat_Msg) <= PGSTAT_MAX_MSG_SIZE,
 				   "maximum stats message size exceeds PGSTAT_MAX_MSG_SIZE");
-
-	/*
-	 * Create stats temp directory if not present; ignore errors.
-	 * This avoids the need to initdb... This is temporary code, and
-	 * can be removed in the future, as initdb does this for us.
-	 */
-	mkdir("pg_stat_tmp", 0700);

 	/*
 	 * Create the UDP socket for sending and receiving statistic messages


Make local copy of client hostnames in backend status array.

The other strings, application_name and query string, were snapshotted to
local memory in pgstat_read_current_status(), but we forgot to do that for
client hostnames. As a result, the client hostname would appear to change in
the local copy, if the client disconnected.

Backpatch to all supported versions.

Author: Edmund Horner
Reviewed-by: Michael Paquier
Discussion: https://www.postgresql.org/message-id/CAMyN-kA7aOJzBmrYFdXcc7Z0NmW%2B5jBaf_m%3D_-77uRNyKC9r%3DA%40mail.gmail.com

--- src/backend/postmaster/pgstat.c
+++ src/backend/postmaster/pgstat.c
@@ -2842,6 +2842,7 @@
 	LocalPgBackendStatus *localtable;
 	LocalPgBackendStatus *localentry;
 	char	   *localappname,
+			   *localclienthostname,
 			   *localactivity;
 	int			i;

@@ -2855,6 +2856,9 @@
 		MemoryContextAlloc(pgStatLocalContext,
 						   sizeof(LocalPgBackendStatus) * MaxBackends);
 	localappname = (char *)
+		MemoryContextAlloc(pgStatLocalContext,
+						   NAMEDATALEN * MaxBackends);
+	localclienthostname = (char *)
 		MemoryContextAlloc(pgStatLocalContext,
 						   NAMEDATALEN * MaxBackends);
 	localactivity = (char *)
@@ -2888,6 +2892,8 @@
 				 */
 				strcpy(localappname, (char *) beentry->st_appname);
 				localentry->backendStatus.st_appname = localappname;
+				strcpy(localclienthostname, (char *) beentry->st_clienthostname);
+				localentry->backendStatus.st_clienthostname = localclienthostname;
 				strcpy(localactivity, (char *) beentry->st_activity);
 				localentry->backendStatus.st_activity = localactivity;
 			}
@@ -2910,6 +2916,7 @@

 			localentry++;
 			localappname += NAMEDATALEN;
+			localclienthostname += NAMEDATALEN;
 			localactivity += pgstat_track_activity_query_size;
 			localNumBackends++;
 		}


clean up the wording and capitalization for desklock config

SVN revision: 21808

--- src/bin/e_int_config_desklock.c
+++ src/bin/e_int_config_desklock.c
@@ -270,7 +270,7 @@
      edje_object_signal_callback_add(rwd->o_radio, "toggle_on", "",
 				     _e_desklock_cb_syswide_auth_method, cfdata);

-     oc = e_widget_radio_add(evas, _("Personilized password"), 1, rg_auth);
+     oc = e_widget_radio_add(evas, _("Personalized password"), 1, rg_auth);
      e_widget_framelist_object_append(of,oc);

      rwd = e_widget_data_get(oc);
@@ -292,7 +292,7 @@
    e_widget_min_size_set(ob, 200, 25);
    e_widget_framelist_object_append(of, ob);

-   ob = e_widget_check_add(evas, _("Show Password"), &(cfdata->show_password));
+   ob = e_widget_check_add(evas, _("Show password"), &(cfdata->show_password));
    cfdata->gui.show_passwd_check = ob;
 #ifdef HAVE_PAM
    if (cfdata->auth_method == 0)
@@ -308,14 +308,14 @@
    of = e_widget_framelist_add(evas, _("Automatic Locking"), 0);
    e_widget_disabled_set(of, !ecore_x_screensaver_event_available_get());

-   ob = e_widget_check_add(evas, _("Lock when the Screensaver starts"), &(cfdata->autolock));
+   ob = e_widget_check_add(evas, _("Enable screensaver"), &(cfdata->use_timeout));
    e_widget_disabled_set(ob, !ecore_x_screensaver_event_available_get());
    e_widget_framelist_object_append(of, ob);
-
-   ob = e_widget_check_add(evas, _("Set the screensaver timeout"), &(cfdata->use_timeout));
+
+   ob = e_widget_check_add(evas, _("Lock when the screensaver starts"), &(cfdata->autolock));
    e_widget_disabled_set(ob, !ecore_x_screensaver_event_available_get());
    e_widget_framelist_object_append(of, ob);
-
+
    ob = e_widget_label_add(evas, _("Time until screensaver starts"));
    e_widget_disabled_set(ob, !ecore_x_screensaver_event_available_get());
    e_widget_framelist_object_append(of, ob);
@@ -431,19 +431,19 @@
         {
           rg = e_widget_radio_group_new((int *)(&(cfdata->login_box_zone)));

-          ob = e_widget_radio_add(evas, _("Show On All Screen Zones"), LOGINBOX_SHOW_ALL_SCREENS,
+          ob = e_widget_radio_add(evas, _("Show on all screen zones"), LOGINBOX_SHOW_ALL_SCREENS,
       			    rg);
           cfdata->gui.loginbox_obj.show_all_screens = ob;
           if (cfdata->zone_count == 1) e_widget_disabled_set(ob, 1);
           e_widget_framelist_object_append(of, ob);

-          ob = e_widget_radio_add(evas, _("Show On Current Screen Zone"),
+          ob = e_widget_radio_add(evas, _("Show on current screen zone"),
       			    LOGINBOX_SHOW_CURRENT_SCREENS, rg);
           cfdata->gui.loginbox_obj.show_current_screen = ob;
           if (cfdata->zone_count == 1) e_widget_disabled_set(ob, 1);
           e_widget_framelist_object_append(of, ob);

-          ob = e_widget_radio_add(evas, _("Show On Screen Zone :"), LOGINBOX_SHOW_SPECIFIC_SCREEN,
+          ob = e_widget_radio_add(evas, _("Show on screen zone #:"), LOGINBOX_SHOW_SPECIFIC_SCREEN,
       			    rg);
           cfdata->gui.loginbox_obj.show_specific_screen = ob;
           if (cfdata->zone_count == 1) e_widget_disabled_set(ob, 1);
@@ -471,7 +471,7 @@
         edje_object_signal_callback_add(wd->o_radio, "toggle_on", "",
        				 _e_desklock_cb_syswide_auth_method, cfdata);

-        oc = e_widget_radio_add(evas, _("Personilized password"), 1, rg_auth);
+        oc = e_widget_radio_add(evas, _("Personalized password"), 1, rg_auth);
         e_widget_framelist_object_append(of,oc);

         wd = e_widget_data_get(oc);
@@ -494,7 +494,7 @@
 	e_widget_min_size_set(ob, 200, 25);
 	e_widget_framelist_object_append(of, ob);

-	ob = e_widget_check_add(evas, _("Show Password"), &(cfdata->show_password));
+	ob = e_widget_check_add(evas, _("Show password"), &(cfdata->show_password));
 	cfdata->gui.show_passwd_check = ob;

 #ifdef HAVE_PAM
@@ -519,14 +519,14 @@
       {
 	e_widget_disabled_set(of, !ecore_x_screensaver_event_available_get());

-	ob = e_widget_check_add(evas, _("Lock when the Screensaver starts"), &(cfdata->autolock));
+	ob = e_widget_check_add(evas, _("Enable screensaver"), &(cfdata->use_timeout));
 	e_widget_disabled_set(ob, !ecore_x_screensaver_event_available_get());
 	e_widget_framelist_object_append(of, ob);
-
-	ob = e_widget_check_add(evas, _("Set the screensaver timeout"), &(cfdata->use_timeout));
+
+	ob = e_widget_check_add(evas, _("Lock when the screensaver starts"), &(cfdata->autolock));
 	e_widget_disabled_set(ob, !ecore_x_screensaver_event_available_get());
 	e_widget_framelist_object_append(of, ob);
-
+
 	ob = e_widget_label_add(evas, _("Time until screensaver starts"));
 	e_widget_disabled_set(ob, !ecore_x_screensaver_event_available_get());
 	e_widget_framelist_object_append(of, ob);


Removed warnings

Removed warnings

--- src/cc1/ops/expr_compound_lit.c
+++ src/cc1/ops/expr_compound_lit.c
@@ -22,11 +22,14 @@

 void gen_expr_compound_lit(expr *e, symtable *stab)
 {
+	(void)e;
+	(void)stab;
 	ICE("TODO: gen_expr_(cast){}");
 }

 void gen_expr_str_compound_lit(expr *e, symtable *stab)
 {
+	(void)stab;
 	idt_printf("(%s){}:\n", decl_to_str(e->decl));
 	gen_str_indent++;
 	print_decl(e->decl,


Implemented top level data message packing.

--- src/common/protocol/msgs/data.c
+++ src/common/protocol/msgs/data.c
@@ -24,19 +24,24 @@

 int HVN_msg_data_send(int fd, HVN_msg_data_t* msg_in)
 {
-  msgpack_sbuffer sbuf;
-  msgpack_sbuffer_init(&sbuf);
-  msgpack_packer pck;
-  msgpack_packer_init(&pck, &sbuf, msgpack_sbuffer_write);
+    msgpack_sbuffer sbuf;
+    msgpack_packer pck;

+    msgpack_sbuffer_init(&sbuf);
+    msgpack_packer_init(&pck, &sbuf, msgpack_sbuffer_write);

+    if(HVN_msg_pack_array(&pck, msg_in->ops, HVN_msg_pack_dbop) == HVN_SUCCESS) {
+        if(HVN_msg_fdwrite(fd, sbuf.size, sbuf.data) != HVN_SUCCESS) {
+            LOG(HVN_LOG_ERR, "Failed to send a packed data message.");
+            return HVN_ERROR;
+        }
+    } else {
+        LOG(HVN_LOG_ERR, "Failed to pack a data message.");
+        return HVN_ERROR;
+    }

-// A data message contains one or more ordered operations to perform on the
-// database state machine.
-typedef struct HVN_msg_data_t {
-    UT_array* ops; // HVN_db_op_t[]
-} HVN_msg_data_t;
-
+    msgpack_sbuffer_destroy(&sbuf);
+    return HVN_SUCCESS;
 }

 int HVN_msg_data_recv(HVN_msg_data_t** msg_out, int fd)


added a lookup() method which returns a pointer to the value

--- src/condor_c++_util/HashTable.h
+++ src/condor_c++_util/HashTable.h
@@ -30,6 +30,7 @@

   int insert(const Index &index, const Value &value);
   int lookup(const Index &index, Value &value);
+  int lookup(const Index &index, Value* &value);
   int getNext(Index &index, void *current, Value &value,
 	      void *&next);
   int remove(const Index &index);
@@ -114,6 +115,34 @@
 #endif
     if (bucket->index == index) {
       value = bucket->value;
+      return 0;
+    }
+    bucket = bucket->next;
+  }
+
+#ifdef DEBUGHASH
+  dump();
+#endif
+
+  return -1;
+}
+
+// This lookup() is the same as above, but it expects (and returns) a
+// _pointer_ reference to the value.
+
+template <class Index, class Value>
+int HashTable<Index,Value>::lookup(const Index &index, Value* &value )
+{
+  int idx = hashfcn(index, tableSize);
+
+  HashBucket<Index, Value> *bucket = ht[idx];
+  while(bucket) {
+#ifdef DEBUGHASH
+    cerr << "%%  Comparing " << *(long *)&bucket->index
+         << " vs. " << *(long *)index << endl;
+#endif
+    if (bucket->index == index) {
+      value = (Value *) &(bucket->value);
       return 0;
     }
     bucket = bucket->next;


Fix hash<Quadruple<...> >

Fix hash<Quadruple<...> >

--- include/BALL/DATATYPE/hashMap.h
+++ include/BALL/DATATYPE/hashMap.h
@@ -96,10 +96,10 @@
 		};

 		template <class A, class B, class C, class D>
-		struct hash< const ::BALL::Quadruple<A, B, C, D> > : public std::unary_function< const ::BALL::Quadruple<A, B, C, D>, size_t>
-		{
-			inline size_t
-			operator()(const ::BALL::Quadruple<A, B, C, D> q) const
+		struct hash< ::BALL::Quadruple<A, B, C, D> > : public std::unary_function< const ::BALL::Quadruple<A, B, C, D>, size_t>
+		{
+			inline size_t
+			operator()( ::BALL::Quadruple<A, B, C, D> q) const
 			{
 				size_t seed = 0;
 				hash_combine_ala_boost(seed, q.first);


fixed: clear

fixed: clear

--- include/BALL/MATHS/quaternion.h
+++ include/BALL/MATHS/quaternion.h
@@ -1,7 +1,7 @@
 // -*- Mode: C++; tab-width: 2; -*-
 // vi: set ts=2:
 //
-// $Id: quaternion.h,v 1.36 2003/06/09 22:40:49 oliver Exp $
+// $Id: quaternion.h,v 1.37 2003/06/10 23:16:01 amoll Exp $
 //

 #ifndef BALL_MATHS_QUATERNION_H
@@ -289,7 +289,8 @@
 	void TQuaternion<T>::clear()
 		throw()
 	{
-		i = j = k = angle = (T)0;
+		i = j = k = (T)0;
+		angle = (T)1;
 	}

 	template <typename T>


Some fixes and features on the new quaternion class, doc still missing

--- include/BALL/MATHS/quaternion.h
+++ include/BALL/MATHS/quaternion.h
@@ -36,14 +36,21 @@

 		void set(const boost::math::quaternion<T>& q);
 		void set(const T& w, const T& i, const T& j, const T& k);
-		void constructFromAxis(const TVector3<T>& axis, const T& new_angle);
-
+		void setIdentity();
+		void normalize();
+		void swap(TQuaternion& q);
+		void fromAxisAngle(const TVector3<T>& axis, const T& angle);
+		void toAxisAngle(TVector3<T>& axis, T& angle);
+
+		T getAngle() const;
+		TVector3<T> getAxis();
 		TQuaternion& operator = (const boost::math::quaternion<T>& q);
 		TQuaternion& operator = (const TQuaternion& q);
+		void dump(std::ostream& s = std::cout, Size depth = 0) const;
 		TMatrix4x4<T>& getRotationMatrix(TMatrix4x4<T>& m) const;

-		TQuaternion getConjugate() const
-			throw();
+		TQuaternion getInverse() const;
+		TQuaternion getConjugate() const;

 		T& w();
 		const T& w() const;
@@ -54,67 +61,37 @@
 		T& k();
 		const T& k() const;

-		protected:
-
-		T& w_;
-
-		T& i_;
-
-		T& j_;
-
-		T& k_;
-
 	};

 	template <typename T>
 	TQuaternion<T>::TQuaternion()
-		: boost::math::quaternion<T>(),
-			w_(this->a),
-			i_(this->b),
-			j_(this->c),
-			k_(this->d)
+		: boost::math::quaternion<T>()
 	{
 	}

 	template <typename T>
 	TQuaternion<T>::TQuaternion(const boost::math::quaternion<T>& q)
-		:	boost::math::quaternion<T>(q),
-			w_(this->a),
-			i_(this->b),
-			j_(this->c),
-			k_(this->d)
+		:	boost::math::quaternion<T>(q)
 	{
 	}

 	template <typename T>
 	TQuaternion<T>::TQuaternion(const TQuaternion& q)
-		:	boost::math::quaternion<T>(q),
-			w_(this->a),
-			i_(this->b),
-			j_(this->c),
-			k_(this->d)
+		:	boost::math::quaternion<T>(q)
 	{
 	}

 	template <typename T>
 	TQuaternion<T>::TQuaternion(const T& w, const T& i, const T& j, const T& k)
-		: boost::math::quaternion<T>(w, i, j, k),
-			w_(this->a),
-			i_(this->b),
-			j_(this->c),
-			k_(this->d)
-	{
-	}
-
-	template <typename T>
-	TQuaternion<T>::TQuaternion(const TVector3<T>& axis, const T& new_angle)
-		: boost::math::quaternion<T>(),
-			w_(this->a),
-			i_(this->b),
-			j_(this->c),
-			k_(this->d)
-	{
-		constructFromAxis(axis, new_angle);
+		: boost::math::quaternion<T>(w, i, j, k)
+	{
+	}
+
+	template <typename T>
+	TQuaternion<T>::TQuaternion(const TVector3<T>& axis, const T& angle)
+		: boost::math::quaternion<T>()
+	{
+		fromAxisAngle(axis, angle);
 	}

 	template <typename T>
@@ -125,7 +102,7 @@
 	template <typename T>
 	void TQuaternion<T>::clear()
 	{
-		boost::math::quaternion<T>::operator= ((T)1);
+		this->setIdentity();
 	}

 	template <typename T>
@@ -138,32 +115,122 @@
 	BALL_INLINE
 	void TQuaternion<T>::set(const T& w, const T& i, const T& j, const T& k)
 	{
-		w_ = w;
-		i_ = i;
-		j_ = j;
-		k_ = k;
-
-	}
-
-	template <typename T>
-	void TQuaternion<T>::constructFromAxis(const TVector3<T>& axis, const T& new_angle)
-	{
-		T length = (T)sqrt(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z);
+		this->a = w;
+		this->b = i;
+		this->c = j;
+		this->d = k;
+
+	}
+
+	template <typename T>
+	BALL_INLINE
+	void TQuaternion<T>::setIdentity()
+	{
+		this->a = (T)1;
+		this->b = this->c = this->d = (T)0;
+	}
+
+	template <typename T>
+	BALL_INLINE
+	void TQuaternion<T>::normalize()
+	{
+		T length = (T) norm(*this);
+
+		if (!(Maths::isEqual(length, (T)0)))
+		{
+			this->a /= length;
+			this->b /= length;
+			this->c /= length;
+			this->d /= length;
+		}
+	}
+
+	template <typename T>
+	void TQuaternion<T>::swap(TQuaternion<T>& q)
+	{
+		T tmp = q.a;
+		q.a = this->a;
+		this->a = tmp;
+
+		tmp = q.b;
+		q.b = this->b;
+		this->b = tmp;
+
+		tmp = q.c;
+		q.c = this->c;
+		this->c = tmp;
+
+		tmp = q.d;
+		q.d = this->d;
+		this->d = tmp;
+	}
+
+	template <typename T>
+	void TQuaternion<T>::fromAxisAngle(const TVector3<T>& axis, const T& angle)
+	{
+		T length = axis.getLength();

 		if (Maths::isEqual(length, (T)0))
 		{
-			i_ = j_ = k_ = (T)0;
-			w_ = (T)1;
+			this->b = this->c = this->d = (T)0;
+			this->a = (T)1;
 		}
 		else
 		{
-			T omega = (T) (new_angle * 0.5);
+			T omega = (T) (angle * 0.5);
 			T sin_omega = (T)::sin(omega);

-			w_ = (T)::cos(omega);
-			i_ = axis.x * sin_omega / length;
-			j_ = axis.y * sin_omega / length;
-			k_ = axis.z * sin_omega / length;
+			this->a = (T)::cos(omega);
+			this->b = axis.x * sin_omega / length;
+			this->c = axis.y * sin_omega / length;
+			this->d = axis.z * sin_omega / length;
+		}
+	}
+
+	template <typename T>
+	void TQuaternion<T>::toAxisAngle(TVector3<T>& axis, T& angle)
+	{
+		T length = (T) norm(*this);
+
+		if (Maths::isEqual(length, (T)0))
+		{
+			axis.x = axis.y = angle= (T)0;
+			axis.y = (T)1;
+		}
+		else
+		{
+			angle = 2 * (T)::acos(this->a);
+			axis.x = this->b / length;
+			axis.y = this->c / length;
+			axis.z = this->d / length;
+		}
+	}
+
+	template <typename T>
+	T TQuaternion<T>::getAngle() const
+	{
+		T length = (T) norm(*this);
+		if (Maths::isEqual(length, (T)0))
+		{
+			return (T)(0);
+		}
+		else
+		{
+			return (T)(2 * (T)::acos(this->a));
+		}
+	}
+
+	template <typename T>
+	TVector3<T> TQuaternion<T>::getAxis()
+	{
+		T length = (T) norm(*this);
+		if (Maths::isEqual(length, (T)0))
+		{
+			return TVector3<T>((T)0,(T)0,(T)1);
+		}
+		else
+		{
+			return TVector3<T>(this->b/length, this->c/length, this->d/length);
 		}
 	}

@@ -184,6 +251,47 @@
 	}

 	template <typename T>
+	std::istream& operator >>(std::istream& s, TQuaternion<T>& q)
+		throw()
+	{
+		char c;
+		s >> c >> q.w() >> q.i() >> q.j() >> q.k() >> c;
+		return s;
+	}
+
+	template <typename T>
+	std::ostream& operator << (std::ostream& s, const TQuaternion<T>& q)
+		throw()
+	{
+		s << '(' << q.w() << ',' << q.i() << ','
+				     << q.j() << ',' << q.k() << ')';
+
+		return s;
+	}
+
+	template <typename T>
+	void TQuaternion<T>::dump(std::ostream& s, Size depth) const
+	{
+		BALL_DUMP_STREAM_PREFIX(s);
+
+		BALL_DUMP_HEADER(s, this, this);
+
+		BALL_DUMP_DEPTH(s, depth);
+		s << "    w: " << w << std::endl;
+
+		BALL_DUMP_DEPTH(s, depth);
+		s << "    i: " << i << std::endl;
+
+		BALL_DUMP_DEPTH(s, depth);
+		s << "    j: " << j << std::endl;
+
+		BALL_DUMP_DEPTH(s, depth);
+		s << "    k: " << k << std::endl;
+
+		BALL_DUMP_STREAM_SUFFIX(s);
+	}
+
+	template <typename T>
 	const T& TQuaternion<T>::w() const
 	{
 		return this->a;
@@ -234,22 +342,22 @@
 	template <typename T>
 	TMatrix4x4<T>& TQuaternion<T>::getRotationMatrix(TMatrix4x4<T>& m) const
 	{
-		T s = 2.0 / (i_*i_ + j_*j_ + k_*k_ + w_*w_ );
+		T s = 2.0 / (this->b*this->b + this->c*this->c + this->d*this->d + this->a*this->a );
 		m.set
 			(
-				(T)(1.0 - s * (j_ * j_ + k_ * k_)),
-				(T)(s * (i_ * j_ - k_ * w_)),
-				(T)(s * (k_ * i_ + j_ * w_)),
+				(T)(1.0 - s * (this->c * this->c + this->d * this->d)),
+				(T)(s * (this->b * this->c - this->d * this->a)),
+				(T)(s * (this->d * this->b + this->c * this->a)),
 				(T)0,

-				(T)(s * (i_ * j_ + k_ * w_)),
-				(T)(1.0 - s * (k_ * k_ + i_ * i_)),
-				(T)(s * (j_ * k_ - i_ * w_)),
+				(T)(s * (this->b * this->c + this->d * this->a)),
+				(T)(1.0 - s * (this->d * this->d + this->b * this->b)),
+				(T)(s * (this->c * this->d - this->b * this->a)),
 				(T)0,

-				(T)(s * (k_ * i_ - j_ * w_)),
-				(T)(s * (j_ * k_ + i_ * w_)),
-				(T)(1.0 - s * (j_ * j_ + i_ * i_)),
+				(T)(s * (this->d * this->b - this->c * this->a)),
+				(T)(s * (this->c * this->d + this->b * this->a)),
+				(T)(1.0 - s * (this->c * this->c + this->b * this->b)),
 				(T)0,

 				(T)0,
@@ -263,10 +371,17 @@

 	template <typename T>
 	BALL_INLINE
+	TQuaternion<T> TQuaternion<T>::getInverse() const
+	{
+
+		return conj(*this) / norm(*this);
+	}
+
+	template <typename T>
+	BALL_INLINE
 	TQuaternion<T> TQuaternion<T>::getConjugate() const
-		throw()
-	{
-		return conj(this);
+	{
+		return conj(*this);
 	}


fix RandInt32 .

fix RandInt32 .

--- include/LightGBM/utils/random.h
+++ include/LightGBM/utils/random.h
@@ -95,12 +95,12 @@
 private:
   inline int RandInt16() {
     x = (214013 * x + 2531011);
-    return (x >> 16) & 0x7FFF;
+    return static_cast<int>((x >> 16) & 0x7FFF);
   }

   inline int RandInt32() {
     x = (214013 * x + 2531011);
-    return x & 0x7FFFFFF;
+    return static_cast<int>(x & 0x7FFFFFFF);
   }

   unsigned int x = 123456789;


firmware: use new mmcm interface

firmware: use new mmcm interface

--- firmware/main.c
+++ firmware/main.c
@@ -25,16 +25,16 @@

 /* hdmi_out functions */

-static void hdmi_out_write_mmcm_reg(uint32_t address, uint32_t data) {
-	hdmi_out_driver_clocking_drp_addr_write(address);
-    hdmi_out_driver_clocking_drp_di_write(data);
-    hdmi_out_driver_clocking_drp_dwe_write(1);
-    hdmi_out_driver_clocking_drp_den_write(1);
+static void hdmi_out_mmcm_write(uint8_t address, uint16_t data) {
+	hdmi_out_driver_clocking_mmcm_adr_write(address);
+    hdmi_out_driver_clocking_mmcm_dat_w_write(data);
+    hdmi_out_driver_clocking_mmcm_write_write(1);
+    while (hdmi_out_driver_clocking_mmcm_drdy_read() == 0);
 }

 static void hdmi_out_config_720p60(void) {
-    hdmi_out_write_mmcm_reg(0x8, 0x1000 + (4 << 6)  + 6);
-    hdmi_out_write_mmcm_reg(0xa, 0x1000 + (2  << 6) + 2);
+    hdmi_out_mmcm_write(0x8, 0x1000 + (10 << 6)  + 10);
+    hdmi_out_mmcm_write(0xa, 0x1000 + (2  << 6) + 2);

     hdmi_out_core_initiator_hres_write(1280);
     hdmi_out_core_initiator_hsync_start_write(1390);


x86: Define Additional MSRs

x86: Define Additional MSRs

Define these MSRs in preparation for their use on the x86_64 port

--- include/arch/x86/arch/machine.h
+++ include/arch/x86/arch/machine.h
@@ -26,6 +26,9 @@
 #define IA32_SYSENTER_EIP_MSR   0x176
 #define IA32_FS_BASE_MSR        0xC0000100
 #define IA32_GS_BASE_MSR        0xC0000101
+#define IA32_LSTAR_MSR          0xC0000082
+#define IA32_STAR_MSR           0xC0000081
+#define IA32_FMASK_MSR          0xC0000084

 #define BROADWELL_MODEL_ID      0xD4
 #define HASWELL_MODEL_ID        0xC3


Use an ordered map sorted by ID for coupled elements

--- include/base/ghosting_functor.h
+++ include/base/ghosting_functor.h
@@ -25,6 +25,7 @@
 #include "libmesh/id_types.h"
 #include "libmesh/mesh_base.h"
 #include "libmesh/reference_counted_object.h"
+#include "libmesh/dof_object.h"

 // C++ Includes
 #include <unordered_map>
@@ -228,7 +229,7 @@
    * What elements do we care about and what variables do we care
    * about on each element?
    */
-  typedef std::unordered_map<const Elem*, const CouplingMatrix*> map_type;
+  typedef std::map<const Elem*, const CouplingMatrix*, CompareDofObjectsByID> map_type;

   /**
    * For the specified range of active elements, what other elements


adding callback data type introspection

adding callback data type introspection

--- include/cinder/audio/Callback.h
+++ include/cinder/audio/Callback.h
@@ -30,6 +30,8 @@
 	#include "cinder/audio/CocoaCaConverter.h"
 #endif

+#include <boost/type_traits/is_same.hpp>
+
 namespace cinder { namespace audio {

 template<typename,typename> class LoaderSourceCallback;
@@ -45,7 +47,7 @@
 	double getDuration() const { return 100.0; } //TODO: support for endless sources

  private:
-	Callback( T* callbackObj, CallbackFunction callbackFn, bool ownCallbackObj, uint32_t aSampleRate, uint16_t aChannelCount, DataType aDataType );
+	Callback( T* callbackObj, CallbackFunction callbackFn, bool ownCallbackObj, uint32_t aSampleRate, uint16_t aChannelCount );

 	void getData( uint64_t inSampleOffset, uint32_t ioSampleCount, Buffer *ioBuffer );

@@ -55,13 +57,13 @@

 	friend class LoaderSourceCallback<T,U>;
 	template <typename T2, typename U2>
-	friend shared_ptr<Callback<T2,U2> > createCallback( T2* callbackObj, void (T2::*callbackFn)( uint64_t inSampleOffset, uint32_t inSampleCount, BufferT<U2> *ioBuffer ), bool ownCallbackObj, uint32_t aSampleRate, uint16_t aChannelCount, Io::DataType aDataType );
+	friend shared_ptr<Callback<T2,U2> > createCallback( T2* callbackObj, void (T2::*callbackFn)( uint64_t inSampleOffset, uint32_t inSampleCount, BufferT<U2> *ioBuffer ), bool ownCallbackObj, uint32_t aSampleRate, uint16_t aChannelCount );
 };

 template<typename T, typename U>
-shared_ptr<Callback<T,U> > createCallback( T* callbackObj, void (T::*callbackFn)( uint64_t inSampleOffset, uint32_t inSampleCount, BufferT<U> *ioBuffer ), bool ownCallbackObj = false, uint32_t aSampleRate = 44100, uint16_t aChannelCount = 2, Io::DataType aDataType = Io::FLOAT32 )
-{
-	return shared_ptr<Callback<T,U> >( new Callback<T,U>( callbackObj, callbackFn, ownCallbackObj, aSampleRate, aChannelCount, aDataType ) );
+shared_ptr<Callback<T,U> > createCallback( T* callbackObj, void (T::*callbackFn)( uint64_t inSampleOffset, uint32_t inSampleCount, BufferT<U> *ioBuffer ), bool ownCallbackObj = false, uint32_t aSampleRate = 44100, uint16_t aChannelCount = 2 )
+{
+	return shared_ptr<Callback<T,U> >( new Callback<T,U>( callbackObj, callbackFn, ownCallbackObj, aSampleRate, aChannelCount ) );
 }

 template<typename T, typename U>
@@ -89,28 +91,40 @@
 };

 template<typename T, typename U>
-Callback<T,U>::Callback( T* callbackObj, CallbackFunction callbackFn, bool ownCallbackObj, uint32_t aSampleRate, uint16_t aChannelCount, DataType aDataType )
+Callback<T,U>::Callback( T* callbackObj, CallbackFunction callbackFn, bool ownCallbackObj, uint32_t aSampleRate, uint16_t aChannelCount )
 	: Source(), mCallbackFn( callbackFn ), mCallbackObj( callbackObj ), mOwnsCallbackObj( ownCallbackObj )
 {
 	mIsPcm = true;
 	mSampleRate = aSampleRate;
 	mChannelCount = aChannelCount;
 	mIsInterleaved = true;
-	mDataType = aDataType;
 	mIsBigEndian = false;

-	if( mDataType == UINT8 || mDataType == INT8 ) {
+	if( boost::is_same<U,uint8_t>::value ) {
+		mDataType = Io::UINT8;
 		mBitsPerSample = 8;
-	} else if( mDataType == INT16 ) {
+	} else if( boost::is_same<U,int8_t>::value ) {
+		mDataType = Io::INT8;
+		mBitsPerSample = 8;
+	} else if( boost::is_same<U,uint16_t>::value ) {
+		mDataType = Io::UINT16;
 		mBitsPerSample = 16;
-	} else if( mDataType == UINT32 || mDataType == INT32 || mDataType == FLOAT32 ) {
+	} else if( boost::is_same<U,int16_t>::value ) {
+		mDataType = Io::INT16;
+		mBitsPerSample = 16;
+	} else if( boost::is_same<U,uint32_t>::value ) {
+		mDataType = Io::UINT32;
+		mBitsPerSample = 32;
+	} else if( boost::is_same<U,int32_t>::value ) {
+		mDataType = Io::UINT32;
+		mBitsPerSample = 32;
+	} else if( boost::is_same<U,float>::value ) {
+		mDataType = Io::FLOAT32;
 		mBitsPerSample = 32;
 	} else {
-		if( mOwnsCallbackObj ) {
-			delete callbackObj;
-		}
-		throw IoExceptionUnsupportedDataType();
-	}
+		throw IoExceptionUnsupportedDataType(); //This callback seems to be providing an unsupprted type of data
+	}
+
 	mBlockAlign = ( mBitsPerSample / 8 ) * mChannelCount;
 }


Disabled DisposeAll() for the moment since it needs some re-working so as
not to crash. This should not cause any leaks since all clients still
manually invoke Free() on the objects they have allocated.

git-svn-id: 28d9401aa571d5108e51b194aae6f24ca5964c06@20766 8cc4aa7f-3514-0410-904f-f2cc9021211c

--- include/csutil/blockallocator.h
+++ include/csutil/blockallocator.h
@@ -153,6 +153,7 @@
    */
   void DisposeAll()
   {
+#if 0
     for (size_t i = blocks.Length(); i-- > 0; )
     {
       csBlock const& bl = blocks[i];
@@ -170,6 +171,7 @@
     }
     blocks.Empty();
     firstfreeblock = (size_t)-1;
+#endif
   }

 public:


Squashed '3rdparty/github/genericLogger-remote/' changes from 3ff620f..f720750

f720750 Fix omitted inclusion of (required) <stdarg.h> in runtime.h (also included in genericLogger.h anyway), fixed include order because of mingw that requires <unistd.h> to be included BEFORE <time.h> so that localtime_r is defined...

git-subtree-dir: 3rdparty/github/genericLogger-remote
git-subtree-split: f7207508103e12d0ba7cf4e27d1afea2859776be

--- include/genericLogger/runtime.h
+++ include/genericLogger/runtime.h
@@ -12,8 +12,14 @@
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
 #endif
+#ifdef HAVE_STDARG_H
+#include <stdarg.h>
+#endif
 #ifdef HAVE_STDINT_H
 #include <stdint.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
 #endif
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
@@ -27,9 +33,6 @@
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
 #ifdef HAVE_IO_H
 #include <io.h>
 #endif


Modernized loop to eliminate the non-matching sign comparison compiler warning.

--- include/igl/xml/XMLSerializer.h
+++ include/igl/xml/XMLSerializer.h
@@ -489,15 +489,14 @@
     {
       if(name.find("::", 0) == 0)
         name.replace(0,3,"");
-
-      std::stringstream stream;
-      for(unsigned int i=0;i<numForbiddenChars;i++)
+
+      for(auto chr : forbiddenChars)
       {
         std::stringstream searchs;
-        searchs << ":" << (int)forbiddenChars[i];
+        searchs << ":" << (int)chr;
         std::string search = searchs.str();
         std::string replace;
-        replace = forbiddenChars[i];
+        replace = chr;

         ReplaceSubString(name,search,replace);
       }


autoref fix for nullptr value

autoref fix for nullptr value

--- fnord-base/autoref_impl.h
+++ fnord-base/autoref_impl.h
@@ -17,12 +17,12 @@

 template <typename T>
 AutoRef<T>::AutoRef(T* ref) : ref_(ref) {
-  ref_->incRef();
+  if (ref_) ref_->incRef();
 }

 template <typename T>
 AutoRef<T>::AutoRef(const AutoRef<T>& other) : ref_(other.ref_) {
-  ref_->incRef();
+  if (ref_) ref_->incRef();
 }

 template <typename T>
@@ -37,7 +37,9 @@
   }

   ref_ = other.ref_;
-  ref_->incRef();
+  if (ref_) {
+    ref_->incRef();
+  }

   return *this;
 }


#import order was messed up, now fixed

#import order was messed up, now fixed

--- win32_handmade/handmade.h
+++ win32_handmade/handmade.h
@@ -27,14 +27,13 @@
 typedef float real32;
 typedef double real64;

-#include "handmade.cpp"
-#include "win32_handmade.h"
-
 #include <Windows.h>
 #include <stdio.h>
 #include <Xinput.h>
 #include <dsound.h>
 #include <math.h>
+
+#include "win32_handmade.h"

 #if !defined(HANDMADE_H)


Set a better icon for codecs

Set a better icon for codecs

As per Jakub's guidance.

--- libappstream-builder/plugins/asb-plugin-appdata.c
+++ libappstream-builder/plugins/asb-plugin-appdata.c
@@ -176,7 +176,7 @@
 		g_autoptr(AsIcon) icon = NULL;
 		icon = as_icon_new ();
 		as_icon_set_kind (icon, AS_ICON_KIND_STOCK);
-		as_icon_set_name (icon, "application-x-executable");
+		as_icon_set_name (icon, "application-x-addon");
 		as_app_add_icon (AS_APP (app), icon);
 		as_app_add_category (AS_APP (app), "Addons");
 		as_app_add_category (AS_APP (app), "Codecs");


uClibc_pthread.h wasn't ever included

uClibc_pthread.h wasn't ever included

--- libpthread/linuxthreads/sysdeps/pthread/pthread.h
+++ libpthread/linuxthreads/sysdeps/pthread/pthread.h
@@ -24,7 +24,7 @@
 #include <signal.h>
 #include <bits/pthreadtypes.h>
 #include <bits/initspin.h>
-#if defined _LIBC && ( defined IS_IN_libc && defined NOT_IN_libc )
+#if defined _LIBC && ( defined IS_IN_libc || defined NOT_IN_libc )
 #include <bits/uClibc_pthread.h>
 #endif


meta-porter: keep a ref on self during connecting a connection

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

--- wocky/wocky-meta-porter.c
+++ wocky/wocky-meta-porter.c
@@ -385,7 +385,7 @@
     {
       DEBUG ("connection error: %s", error->message);
       g_clear_error (&error);
-      return;
+      goto out;
     }

   if (from != NULL)
@@ -440,6 +440,9 @@
     }

   g_object_unref (connection);
+
+out:
+  g_object_unref (self);
 }

 static gboolean
@@ -458,7 +461,7 @@
   DEBUG ("new connection from %s!", str);

   wocky_ll_connector_incoming_async (G_IO_STREAM (socket_connection),
-      NULL, new_connection_connect_cb, self);
+      NULL, new_connection_connect_cb, g_object_ref (self));

   g_free (str);
   g_object_unref (addr);