fts squat: Some error handling fixes fixes.

--HG--
branch : HEAD

--- src/plugins/fts-squat/squat-trie.c
+++ src/plugins/fts-squat/squat-trie.c
@@ -285,6 +285,8 @@
 			   struct dotlock **dotlock_r)
 {
 	int ret;
+
+	i_assert(trie->fd != -1);

 	*file_lock_r = NULL;
 	*dotlock_r = NULL;
@@ -1396,7 +1398,8 @@
 	} else {
 		ret = squat_trie_renumber_uidlists2(ctx, rebuild_ctx, iter);
 	}
-	squat_trie_iterate_deinit(iter);
+	if (squat_trie_iterate_deinit(iter) < 0)
+		ret = -1;

 	/* lock the trie before we rename uidlist */
 	i_assert(ctx->file_lock == NULL && ctx->dotlock == NULL);
@@ -1644,18 +1647,19 @@
 		path = trie->path;
 		ctx->compress_nodes =
 			trie->hdr.used_file_size == sizeof(trie->hdr);
+
+		if (trie->hdr.used_file_size == 0) {
+			/* lock before opening the file, in case we reopen it */
+			if (squat_trie_write_lock(ctx) < 0)
+				return -1;
+		}
 		output = o_stream_create_fd(trie->fd, 0, FALSE);
 		o_stream_cork(output);

 		if (trie->hdr.used_file_size != 0)
 			o_stream_seek(output, trie->hdr.used_file_size);
-		else {
-			if (squat_trie_write_lock(ctx) < 0) {
-				o_stream_unref(&output);
-				return -1;
-			}
+		else
 			o_stream_send(output, &trie->hdr, sizeof(trie->hdr));
-		}
 	}

 	ctx->output = output;


total freed size displayed was always equivalent to allocated, since all mem got cleaned up by the FREE call before.

--- source/tracelib2/tracelib2.c
+++ source/tracelib2/tracelib2.c
@@ -119,6 +119,7 @@
 // returns 0 if everything ok, else count of unfreed adresses
 int tlstats(void) {
 	tlInfo* mem;
+	size_t saveTotalFreed = tlTotalFreed;
 	size_t save = List_GetSize(&tlList);
 	printf("tracelib2 (R) simple mem debugging library (C) 2011 by anallyst (TM)\n");
 	printf("====================================================================\n");
@@ -134,7 +135,7 @@
 	if(save) printf("====================================================================\n");
 	printf("total number of unfreed chunks: %d\n", (int) save);
 	printf("total amount of allocated heap memory: %d\n", (int) tlTotalAlloced);
-	printf("total amount of freed heap memory: %d\n", (int) tlTotalFreed);
+	printf("total amount of freed heap memory: %d\n", (int) saveTotalFreed);
 	printf("peak memory usage: %d\n", (int) tlMaxUsed);
 	return save;
 }


Fix compiling issue with GCC-8.x in string test functions

Same pointer is passed to two or more restrict-qualified parameters of a function.

vpp/src/plugins/unittest/string_test.c: In function ‘test_strcpy_s’:
vpp/src/plugins/unittest/string_test.c:562:19: error: passing argument 1 to restrict-qualified parameter aliases with argument 3 [-Werror=restrict]
err = strcpy_s (dst, s1size, dst);
^~~ ~~~

Change-Id: Ica06b457bbcbf2d552eec380976c37f9fd447b1c
Signed-off-by: Lijian Zhang <5bf702a4364390af4958a9b6773dbd5c19bc4226@arm.com>
Reviewed-by: Sirshak Das <52b659a5c3604c18da7b4f485dd9254e5f624e3a@arm.com>

--- src/plugins/unittest/string_test.c
+++ src/plugins/unittest/string_test.c
@@ -530,6 +530,7 @@
 {
   char src[] = "To err is human.";
   char dst[64];
+  char *dst_alias = dst;
   int indicator;
   size_t s1size = sizeof (dst);	// including null
   errno_t err;
@@ -559,12 +560,9 @@
     return -1;

   /* overlap fail */
-#if __GNUC__ < 8
-  /* GCC 8 flunks this one at compile time... */
-  err = strcpy_s (dst, s1size, dst);
+  err = strcpy_s (dst, s1size, dst_alias);
   if (err == EOK)
     return -1;
-#endif

   /* overlap fail */
   err = strcpy_s (dst, s1size, dst + 1);
@@ -580,6 +578,7 @@
 {
   char src[] = "The journey of a one thousand miles begins with one step.";
   char dst[100];
+  char *dst_alias = dst;
   int indicator;
   errno_t err;

@@ -613,12 +612,9 @@
     return -1;

   /* overlap fail */
-#if __GNUC__ < 8
-  /* GCC 8 flunks this one at compile time... */
-  err = clib_strcpy (dst, dst);
+  err = clib_strcpy (dst, dst_alias);
   if (err == EOK)
     return -1;
-#endif

   /* overlap fail */
   err = clib_strcpy (dst, dst + 1);
@@ -634,6 +630,7 @@
 {
   char src[] = "Those who dare to fail miserably can achieve greatly.";
   char dst[100], old_dst[100];
+  char *dst_alias = dst;
   int indicator;
   size_t s1size = sizeof (dst);	// including null
   errno_t err;
@@ -712,12 +709,9 @@
     return -1;

   /* overlap fail */
-#if __GNUC__ < 8
-  /* GCC 8 flunks this one at compile time... */
-  err = strncpy_s (dst, s1size, dst, s1size);
+  err = strncpy_s (dst, s1size, dst_alias, s1size);
   if (err == EOK)
     return -1;
-#endif

   /* OK, seems to work */
   return 0;
@@ -728,6 +722,7 @@
 {
   char src[] = "Those who dare to fail miserably can achieve greatly.";
   char dst[100], old_dst[100];
+  char *dst_alias = dst;
   int indicator;
   size_t s1size = sizeof (dst);	// including null
   errno_t err;
@@ -768,15 +763,12 @@
   /* verify it against strncpy */
   memset_s (dst, sizeof (dst), 0, sizeof (dst));

-#if __GNUC__ < 8
-  /* GCC 8 flunks this one at compile time... */
   strncpy (dst, "The price of greatness is responsibility.", 10);
   if (strcmp_s (dst, clib_strnlen (dst, sizeof (dst)), "The price ",
 		&indicator) != EOK)
     return -1;
   if (indicator != 0)
     return -1;
-#endif

   /* n > string len of src */
   err = clib_strncpy (dst, src, clib_strnlen (src, sizeof (src)) + 10);
@@ -814,17 +806,14 @@
     return -1;

   /* overlap fail */
-  err = clib_strncpy (dst, dst + 1, s1size);
+  err = clib_strncpy (dst, dst + 1, s1size - 1);
   if (err == EOK)
     return -1;

   /* overlap fail */
-#if __GNUC__ < 8
-  /* GCC 8 flunks this one at compile time... */
-  err = clib_strncpy (dst, dst, s1size);
+  err = clib_strncpy (dst, dst_alias, s1size);
   if (err == EOK)
     return -1;
-#endif

   /* OK, seems to work */
   return 0;
@@ -834,6 +823,7 @@
 test_strcat_s (vlib_main_t * vm, unformat_input_t * input)
 {
   char src[100], dst[100], old_dst[100];
+  char *dst_alias = dst;
   size_t s1size = sizeof (dst);	// including null
   errno_t err;
   int indicator;
@@ -874,12 +864,9 @@
     return -1;

   /* overlap fail */
-#if __GNUC__ < 8
-  /* GCC 8 flunks this one at compile time... */
-  err = strcat_s (dst, s1size, dst);
-  if (err != EINVAL)
-    return -1;
-#endif
+  err = strcat_s (dst, s1size, dst_alias);
+  if (err != EINVAL)
+    return -1;

   /* not enough space for dst */
   err = strcat_s (dst, 10, src);
@@ -894,6 +881,7 @@
 test_clib_strcat (vlib_main_t * vm, unformat_input_t * input)
 {
   char src[100], dst[100], old_dst[100];
+  char *dst_alias = dst;
   size_t s1size = sizeof (dst);	// including null
   errno_t err;
   int indicator;
@@ -944,12 +932,9 @@
     return -1;

   /* overlap fail */
-#if __GNUC__ < 8
-  /* GCC 8 flunks this one at compile time... */
-  err = clib_strcat (dst, dst);
-  if (err != EINVAL)
-    return -1;
-#endif
+  err = clib_strcat (dst, dst_alias);
+  if (err != EINVAL)
+    return -1;

   /* OK, seems to work */
   return 0;
@@ -959,6 +944,7 @@
 test_strncat_s (vlib_main_t * vm, unformat_input_t * input)
 {
   char src[100], dst[100], old_dst[100];
+  char *dst_alias = dst;
   size_t s1size = sizeof (dst);	// including null
   errno_t err;
   char s1[] = "Two things are infinite: ";
@@ -1068,12 +1054,9 @@
     return -1;

   /* overlap fail */
-#if __GNUC__ < 8
-  /* GCC 8 flunks this one at compile time... */
-  err = strncat_s (dst, s1size, dst, clib_strnlen (dst, sizeof (dst)));
-  if (err != EINVAL)
-    return -1;
-#endif
+  err = strncat_s (dst, s1size, dst_alias, clib_strnlen (dst, sizeof (dst)));
+  if (err != EINVAL)
+    return -1;

   /* OK, seems to work */
   return 0;
@@ -1083,6 +1066,7 @@
 test_clib_strncat (vlib_main_t * vm, unformat_input_t * input)
 {
   char src[100], dst[100], old_dst[100];
+  char *dst_alias = dst;
   size_t s1size = sizeof (dst);	// including null
   errno_t err;
   char s1[] = "Two things are infinite: ";
@@ -1185,12 +1169,9 @@
     return -1;

   /* overlap fail */
-#if __GNUC__ < 8
-  /* GCC 8 flunks this one at compile time... */
-  err = clib_strncat (dst, dst, clib_strnlen (dst, sizeof (dst)));
-  if (err != EINVAL)
-    return -1;
-#endif
+  err = clib_strncat (dst, dst_alias, clib_strnlen (dst, sizeof (dst)));
+  if (err != EINVAL)
+    return -1;

   /* OK, seems to work */
   return 0;
@@ -1294,9 +1275,7 @@
 test_clib_strtok (vlib_main_t * vm, unformat_input_t * input)
 {
   int indicator;
-  char *s1 __attribute__ ((unused));
-  char *tok __attribute__ ((unused));
-  char *ptr __attribute__ ((unused));
+  char *s1, *s1_alias, *tok, *ptr;
   char str1[40];
   char *p2str;
   char *tok1, *tok2, *tok3, *tok4, *tok5, *tok6, *tok7;
@@ -1398,17 +1377,16 @@
   /* negative stuff */
   s1 = 0;
   ptr = 0;
-#if __GNUC__ < 8
-  /* GCC 8 flunks this one at compile time... */
-  tok = clib_strtok (s1, s1, (char **) 0);
+  s1_alias = s1;
+  tok = clib_strtok (s1, s1_alias, (char **) 0);
   if (tok != 0)
     return -1;

   /* s1 and ptr contents are null */
-  tok = clib_strtok (s1, s1, &ptr);
+  s1_alias = s1;
+  tok = clib_strtok (s1, s1_alias, &ptr);
   if (tok != 0)
     return -1;
-#endif

   /* verify it against strtok_r */
   /* No can do. This causes a crash in strtok_r */


allowed ; in NEKOPATH.

allowed ; in NEKOPATH.

git-svn-id: 4b6d41e9940b00d32d826e7d279a79f5b8ae3021@986 459513c6-d918-8e31-8e7a-abb81885386f

--- vm/load.c
+++ vm/load.c
@@ -241,7 +241,7 @@

 static value init_path( const char *path ) {
 	value l = val_null, tmp;
-	char *p;
+	char *p, *p2;
 #ifdef _WIN32
 	char exe_path[MAX_PATH];
 	if( path == NULL ) {
@@ -259,10 +259,15 @@
 #endif
 	while( true ) {
 		// windows drive letter (same behavior expected on all os)
-		if( *path && path[1] == ':' )
+		if( *path && path[1] == ':' ) {
 			p = strchr(path+2,':');
-		else
+			p2 = strchr(path+2,';');
+		} else {
 			p = strchr(path,':');
+			p2 = strchr(path,';');
+		}
+		if( p2 != NULL && p2 < p )
+			p = p2;
 		if( p != NULL )
 			*p = 0;
 		tmp = alloc_array(2);
@@ -276,7 +281,7 @@
 		val_array_ptr(tmp)[1] = l;
 		l = tmp;
 		if( p != NULL )
-			*p = ':';
+			*p = (p == p2)?';':':';
 		else
 			break;
 		path = p+1;


fixed some names.

fixed some names.

--- vm/neko.h
+++ vm/neko.h
@@ -87,9 +87,10 @@
 #define val_is_object(v)	(!val_is_int(v) && val_tag(v) == VAL_OBJECT)
 #define val_is_array(v)		(!val_is_int(v) && (val_tag(v)&7) == VAL_ARRAY)
 #define val_is_abstract(v)  (!val_is_int(v) && val_tag(v) == VAL_ABSTRACT)
-#define val_kind(v,t)		(val_is_abstract(v) && ((vabstract*)v)->kind == (t))
-#define val_check_kind(v,t)	if( !val_kind(v,t) ) return val_null;
+#define val_is_kind(v,t)	(val_is_abstract(v) && val_kind(v) == (t))
+#define val_check_kind(v,t)	if( !val_is_kind(v,t) ) return val_null;
 #define val_data(v)			((vabstract*)v)->data
+#define val_kind(v)			((vabstract*)v)->kind

 #define val_type(v)			(val_is_int(v) ? VAL_INT : (val_tag(v)&7))
 #define val_int(v)			(((int)(v)) >> 1)


for now we'll always load the fid's replication table on bmap retrieve.  this fixes a bug in cluster no share which was seen when a file had bmaps assigned on different ios's

git-svn-id: ae92b08b608af1c8cefa3e10d2325ea527204e07@17752 3eda493b-6a19-0410-b2e0-ec8ea4dd8fda

--- mount_slash/bmap_cli.c
+++ mount_slash/bmap_cli.c
@@ -293,14 +293,6 @@
 	fci = fcmh_2_fci(f);

  retry:
-	FCMH_LOCK(f);
-	if ((f->fcmh_flags & (FCMH_CLI_HAVEREPLTBL |
-	    FCMH_CLI_FETCHREPLTBL)) == 0) {
-		f->fcmh_flags |= FCMH_CLI_FETCHREPLTBL;
-		getreptbl = 1;
-	}
-	FCMH_ULOCK(f);
-
 	rc = slc_rmc_getimp1(&csvc, fci->fci_resm);
 	if (rc)
 		goto out;
@@ -312,8 +304,7 @@
 	mq->prefios[0] = prefIOS; /* Tell MDS of our preferred ION */
 	mq->bmapno = bmap->bcm_bmapno;
 	mq->rw = rw;
-	if (getreptbl)
-		mq->flags |= SRM_LEASEBMAPF_GETREPLTBL;
+	mq->flags |= SRM_LEASEBMAPF_GETREPLTBL;

 	DEBUG_FCMH(PLL_INFO, f, "retrieving bmap (bmapno=%u) (rw=%d)",
 	    bmap->bcm_bmapno, rw);
@@ -333,22 +324,17 @@
 	    "sbd_seq=%"PRId64" bmapnid=%"PRIx64, rw,
 	    mp->sbd.sbd_ion_nid, mp->sbd.sbd_seq, bmap_2_ion(bmap));

-	if (getreptbl) {
-		/* XXX don't forget that on write we need to invalidate
-		 *   the local replication table..
-		 */
-		fci->fci_nrepls = mp->nrepls;
-		memcpy(&fci->fci_reptbl, &mp->reptbl,
-		       sizeof(sl_replica_t) * SL_MAX_REPLICAS);
-		f->fcmh_flags |= FCMH_CLI_HAVEREPLTBL;
-		psc_waitq_wakeall(&f->fcmh_waitq);
-	}
-
+	fci->fci_nrepls = mp->nrepls;
+	memcpy(&fci->fci_reptbl, &mp->reptbl,
+	       sizeof(sl_replica_t) * SL_MAX_REPLICAS);
+	f->fcmh_flags |= FCMH_CLI_HAVEREPLTBL;
+
+	/* XXX not sure if this is really needed since nothing blocks on
+	 *     FCMH_CLI_HAVEREPLTBL
+	 */
+	psc_waitq_wakeall(&f->fcmh_waitq);
+	FCMH_ULOCK(f);
  out:
-	FCMH_RLOCK(f);
-	if (getreptbl)
-		f->fcmh_flags &= ~FCMH_CLI_FETCHREPLTBL;
-	FCMH_ULOCK(f);
 	if (rq) {
 		pscrpc_req_finished(rq);
 		rq = NULL;


minor whitespace cleanup

minor whitespace cleanup


Added ctest.c.

Added ctest.c.

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

--- test/ctest.c
+++ test/ctest.c
@@ -0,0 +1,377 @@
+//-----------------------------------------------------------------------------
+// Copyright 2012-2016 Masanori Morise. All Rights Reserved.
+// Author: mmorise [at] yamanashi.ac.jp (Masanori Morise)
+//
+// Test program for WORLD 0.1.2 (2012/08/19)
+// Test program for WORLD 0.1.3 (2013/07/26)
+// Test program for WORLD 0.1.4 (2014/04/29)
+// Test program for WORLD 0.1.4_3 (2015/03/07)
+// Test program for WORLD 0.2.0 (2015/05/29)
+// Test program for WORLD 0.2.0_1 (2015/05/31)
+// Test program for WORLD 0.2.0_2 (2015/06/06)
+// Test program for WORLD 0.2.0_3 (2015/07/28)
+// Test program for WORLD 0.2.0_4 (2015/11/15)
+// Test program for WORLD in GitHub (2015/11/16-)
+// Latest update: 2016/02/02
+
+// test.exe input.wav outout.wav f0 spec
+// input.wav  : Input file
+// output.wav : Output file
+// f0         : F0 scaling (a positive number)
+// spec       : Formant scaling (a positive number)
+//-----------------------------------------------------------------------------
+
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#if (defined (__WIN32__) || defined (_WIN32)) && !defined (__MINGW32__)
+#include <conio.h>
+#include <windows.h>
+#pragma comment(lib, "winmm.lib")
+#pragma warning(disable : 4996)
+#endif
+#if (defined (__linux__) || defined(__CYGWIN__) || defined(__APPLE__))
+#include <stdint.h>
+#include <sys/time.h>
+#endif
+
+// For .wav input/output functions.
+#include "./audioio.h"
+
+// WORLD core functions.
+#include "./../src/d4c.h"
+#include "./../src/dio.h"
+#include "./../src/matlabfunctions.h"
+#include "./../src/cheaptrick.h"
+#include "./../src/stonemask.h"
+#include "./../src/synthesis.h"
+
+#if (defined (__linux__) || defined(__CYGWIN__) || defined(__APPLE__))
+// Linux porting section: implement timeGetTime() by gettimeofday(),
+#ifndef DWORD
+#define DWORD uint32_t
+#endif
+DWORD timeGetTime() {
+  struct timeval tv;
+  gettimeofday(&tv, NULL);
+  DWORD ret = (DWORD)(tv.tv_usec / 1000 + tv.tv_sec * 1000);
+  return ret;
+}
+#endif
+
+//-----------------------------------------------------------------------------
+// struct for WORLD
+// This struct is an option.
+// Users are NOT forced to use this struct.
+//-----------------------------------------------------------------------------
+typedef struct {
+  double frame_period;
+  int fs;
+
+  double *f0;
+  double *time_axis;
+  int f0_length;
+
+  double **spectrogram;
+  double **aperiodicity;
+  int fft_size;
+} WorldParameters;
+
+static void DisplayInformation(int fs, int nbit, int x_length) {
+  printf("File information\n");
+  printf("Sampling : %d Hz %d Bit\n", fs, nbit);
+  printf("Length %d [sample]\n", x_length);
+  printf("Length %f [sec]\n", (double)(x_length) / fs);
+}
+
+static void F0Estimation(double *x, int x_length, WorldParameters *world_parameters) {
+  DioOption option = {0};
+  InitializeDioOption(&option);
+
+  // Modification of the option
+  // When you You must set the same value.
+  // If a different value is used, you may suffer a fatal error because of a
+  // illegal memory access.
+  option.frame_period = world_parameters->frame_period;
+
+  // Valuable option.speed represents the ratio for downsampling.
+  // The signal is downsampled to fs / speed Hz.
+  // If you want to obtain the accurate result, speed should be set to 1.
+  option.speed = 1;
+
+  // You should not set option.f0_floor to under world_kFloorF0.
+  // If you want to analyze such low F0 speech, please change world_kFloorF0.
+  // Processing speed may sacrify, provided that the FFT length changes.
+  option.f0_floor = 71.0;
+
+  // You can give a positive real number as the threshold.
+  // Most strict value is 0, but almost all results are counted as unvoiced.
+  // The value from 0.02 to 0.2 would be reasonable.
+  option.allowed_range = 0.1;
+
+  // Parameters setting and memory allocation.
+  world_parameters->f0_length = GetSamplesForDIO(world_parameters->fs,
+    x_length, world_parameters->frame_period);
+  world_parameters->f0 = (double*) malloc(sizeof(double) * (world_parameters->f0_length));
+  world_parameters->time_axis = (double*) malloc(sizeof(double) * (world_parameters->f0_length));
+  double *refined_f0 = (double*) malloc(sizeof(double) * (world_parameters->f0_length));
+
+  printf("\nAnalysis\n");
+  DWORD elapsed_time = timeGetTime();
+  Dio(x, x_length, world_parameters->fs, &option, world_parameters->time_axis,
+      world_parameters->f0);
+  printf("DIO: %d [msec]\n", timeGetTime() - elapsed_time);
+
+  // StoneMask is carried out to improve the estimation performance.
+  elapsed_time = timeGetTime();
+  StoneMask(x, x_length, world_parameters->fs, world_parameters->time_axis,
+      world_parameters->f0, world_parameters->f0_length, refined_f0);
+  printf("StoneMask: %d [msec]\n", timeGetTime() - elapsed_time);
+
+  for (int i = 0; i < world_parameters->f0_length; ++i)
+    world_parameters->f0[i] = refined_f0[i];
+
+  if(refined_f0 != NULL) {
+    free(refined_f0);
+    refined_f0 = NULL;
+  }
+  return;
+}
+
+static void SpectralEnvelopeEstimation(double *x, int x_length,
+    WorldParameters *world_parameters) {
+  CheapTrickOption option = {0};
+  InitializeCheapTrickOption(&option);
+
+  // This value may be better one for HMM speech synthesis.
+  // Default value is -0.09.
+  option.q1 = -0.15;
+
+  // Important notice (2016/02/02)
+  // You can control a parameter used for the lowest F0 in speech.
+  // You must not set the f0_floor to 0.
+  // It will cause a fatal error because fft_size indicates the infinity.
+  // You must not change the f0_floor after memory allocation.
+  // You should check the fft_size before excucing the analysis/synthesis.
+  // The default value (71.0) is strongly recommended.
+  // On the other hand, setting the lowest F0 of speech is a good choice
+  // to reduce the fft_size.
+  option.f0_floor = 71.0;
+
+  // Parameters setting and memory allocation.
+  world_parameters->fft_size =
+    GetFFTSizeForCheapTrick(world_parameters->fs, &option);
+  world_parameters->spectrogram = (double **) malloc(sizeof(double *) * (world_parameters->f0_length));
+  for (int i = 0; i < world_parameters->f0_length; ++i) {
+    world_parameters->spectrogram[i] =
+      (double*) malloc(sizeof(double) * (world_parameters->fft_size / 2 + 1));
+  }
+
+  DWORD elapsed_time = timeGetTime();
+  CheapTrick(x, x_length, world_parameters->fs, world_parameters->time_axis,
+      world_parameters->f0, world_parameters->f0_length, &option,
+      world_parameters->spectrogram);
+  printf("CheapTrick: %d [msec]\n", timeGetTime() - elapsed_time);
+}
+
+static void AperiodicityEstimation(double *x, int x_length,
+    WorldParameters *world_parameters) {
+  D4COption option = {0};
+  InitializeD4COption(&option);
+
+  // Parameters setting and memory allocation.
+  world_parameters->aperiodicity = (double **) malloc(sizeof(double *) * (world_parameters->f0_length));
+  for (int i = 0; i < world_parameters->f0_length; ++i) {
+    world_parameters->aperiodicity[i] =
+      (double*) malloc(sizeof(double) * (world_parameters->fft_size / 2 + 1));
+  }
+
+  DWORD elapsed_time = timeGetTime();
+  // option is not implemented in this version. This is for future update.
+  // We can use "NULL" as the argument.
+  D4C(x, x_length, world_parameters->fs, world_parameters->time_axis,
+      world_parameters->f0, world_parameters->f0_length,
+      world_parameters->fft_size, &option, world_parameters->aperiodicity);
+  printf("D4C: %d [msec]\n", timeGetTime() - elapsed_time);
+}
+
+static void ParameterModification(int argc, char *argv[], int fs, int f0_length,
+    int fft_size, double *f0, double **spectrogram) {
+  // F0 scaling
+  if (argc >= 4) {
+    double shift = atof(argv[3]);
+    for (int i = 0; i < f0_length; ++i) f0[i] *= shift;
+  }
+  if (argc < 5) return;
+
+  // Spectral stretching
+  double ratio = atof(argv[4]);
+  double *freq_axis1 = (double*) malloc(sizeof(double) * (fft_size));
+  double *freq_axis2 = (double*) malloc(sizeof(double) * (fft_size));
+  double *spectrum1 = (double*) malloc(sizeof(double) * (fft_size));
+  double *spectrum2 = (double*) malloc(sizeof(double) * (fft_size));
+
+  for (int i = 0; i <= fft_size / 2; ++i) {
+    freq_axis1[i] = ratio * i / fft_size * fs;
+    freq_axis2[i] = (double)(i) / fft_size * fs;
+  }
+  for (int i = 0; i < f0_length; ++i) {
+    for (int j = 0; j <= fft_size / 2; ++j)
+      spectrum1[j] = log(spectrogram[i][j]);
+    interp1(freq_axis1, spectrum1, fft_size / 2 + 1, freq_axis2,
+      fft_size / 2 + 1, spectrum2);
+    for (int j = 0; j <= fft_size / 2; ++j)
+      spectrogram[i][j] = exp(spectrum2[j]);
+    if (ratio >= 1.0) continue;
+    for (int j = (int)(fft_size / 2.0 * ratio);
+        j <= fft_size / 2; ++j)
+      spectrogram[i][j] =
+      spectrogram[i][(int)(fft_size / 2.0 * ratio) - 1];
+  }
+  if(spectrum1 != NULL) {
+    free(spectrum1);
+    spectrum1 = NULL;
+  }
+  if(spectrum2 != NULL) {
+    free(spectrum2);
+    spectrum2 = NULL;
+  }
+  if(freq_axis1 != NULL) {
+    free(freq_axis1);
+    freq_axis1 = NULL;
+  }
+  if(freq_axis2 != NULL) {
+    free(freq_axis2);
+    freq_axis2 = NULL;
+  }
+}
+
+static void WaveformSynthesis(WorldParameters *world_parameters, int fs,
+    int y_length, double *y) {
+  DWORD elapsed_time;
+  // Synthesis by the aperiodicity
+  printf("\nSynthesis\n");
+  elapsed_time = timeGetTime();
+  Synthesis(world_parameters->f0, world_parameters->f0_length,
+      world_parameters->spectrogram, world_parameters->aperiodicity,
+      world_parameters->fft_size, world_parameters->frame_period, fs,
+      y_length, y);
+  printf("WORLD: %d [msec]\n", timeGetTime() - elapsed_time);
+}
+
+static void DestroyMemory(WorldParameters *world_parameters) {
+  if(world_parameters->time_axis != NULL) {
+    free(world_parameters->time_axis);
+    world_parameters->time_axis = NULL;
+  }
+  if(world_parameters->f0 != NULL) {
+    free(world_parameters->f0);
+    world_parameters->f0 = NULL;
+  }
+  for (int i = 0; i < world_parameters->f0_length; ++i) {
+    if(world_parameters->spectrogram[i] != NULL) {
+      free(world_parameters->spectrogram[i]);
+      world_parameters->spectrogram[i] = NULL;
+    }
+    if(world_parameters->aperiodicity[i] != NULL) {
+      free(world_parameters->aperiodicity[i]);
+      world_parameters->aperiodicity[i] = NULL;
+    }
+  }
+  if(world_parameters->spectrogram != NULL) {
+    free(world_parameters->spectrogram);
+    world_parameters->spectrogram = NULL;
+  }
+  if(world_parameters->aperiodicity != NULL) {
+    free(world_parameters->aperiodicity);
+    world_parameters->aperiodicity = NULL;
+  }
+}
+
+//-----------------------------------------------------------------------------
+// Test program.
+// test.exe input.wav outout.wav f0 spec flag
+// input.wav  : argv[1] Input file
+// output.wav : argv[2] Output file
+// f0         : argv[3] F0 scaling (a positive number)
+// spec       : argv[4] Formant shift (a positive number)
+//-----------------------------------------------------------------------------
+int main(int argc, char *argv[]) {
+  if (argc != 2 && argc != 3 && argc != 4 && argc != 5) {
+    printf("error\n");
+    return -2;
+  }
+
+  // 2016/01/28: Important modification.
+  // Memory allocation is carried out in advanse.
+  // This is for compatibility with C language.
+  int x_length = GetAudioLength(argv[1]);
+  if (x_length <= 0) {
+    if (x_length == 0)
+      printf("error: File not found.\n");
+    else
+      printf("error: The file is not .wav format.\n");
+    return -1;
+  }
+  double *x = (double*) malloc(sizeof(double) * (x_length));
+  // wavread() must be called after GetAudioLength().
+  int fs, nbit;
+  wavread(argv[1], &fs, &nbit, x);
+  DisplayInformation(fs, nbit, x_length);
+
+  //---------------------------------------------------------------------------
+  // Analysis part
+  //---------------------------------------------------------------------------
+  // 2016/02/02
+  // A new struct is introduced to implement safe program.
+  WorldParameters world_parameters = { 0 };
+  // You must set fs and frame_period before analysis/synthesis.
+  world_parameters.fs = fs;
+
+  // 5.0 ms is the default value.
+  // Generally, the inverse of the lowest F0 of speech is the best.
+  // However, the more elapsed time is required.
+  world_parameters.frame_period = 5.0;
+
+  // F0 estimation
+  F0Estimation(x, x_length, &world_parameters);
+
+  // Spectral envelope estimation
+  SpectralEnvelopeEstimation(x, x_length, &world_parameters);
+
+  // Aperiodicity estimation by D4C
+  AperiodicityEstimation(x, x_length, &world_parameters);
+
+  // Note that F0 must not be changed until all parameters are estimated.
+  ParameterModification(argc, argv, fs, world_parameters.f0_length,
+    world_parameters.fft_size, world_parameters.f0,
+    world_parameters.spectrogram);
+
+  //---------------------------------------------------------------------------
+  // Synthesis part
+  //---------------------------------------------------------------------------
+  // The length of the output waveform
+  int y_length = (int)((world_parameters.f0_length - 1) *
+    world_parameters.frame_period / 1000.0 * fs) + 1;
+  double *y = (double*) malloc(sizeof(double) * (y_length));
+  // Synthesis
+  WaveformSynthesis(&world_parameters, fs, y_length, y);
+
+  // Output
+  wavwrite(y, y_length, fs, 16, argv[2]);
+
+  if(y != NULL) {
+    free(y);
+    y = NULL;
+  }
+  if(x != NULL) {
+    free(x);
+    x = NULL;
+  }
+  DestroyMemory(&world_parameters);
+
+  printf("complete.\n");
+  return 0;
+}


Fixed compiler warning

Fixed compiler warning

--- utils/utils.c
+++ utils/utils.c
@@ -357,7 +357,7 @@
 {
   const size_t MAXLINESIZE = 1024;
   char *time_string = my_malloc(sizeof(char), MAXLINESIZE);
-  double timediff = difftime(t1.tv_sec,t0.tv_sec);
+  double timediff = t1.tv_sec - t0.tv_sec;
   double ratios[] = {24*3600.0,  3600.0,  60.0,  1};
   char units[4][10]  = {"days", "hrs" , "mins", "secs"};
   int which = 0;
@@ -392,7 +392,7 @@

 void print_time(struct timeval t0,struct timeval t1,const char *s)
 {
-    double timediff = difftime(t1.tv_sec,t0.tv_sec);
+    double timediff = t1.tv_sec - t0.tv_sec;
     double ratios[] = {24*3600.0,  3600.0,  60.0,  1};
     char units[4][10]  = {"days", "hrs" , "mins", "secs"};
     int which = 0;


implement IO::Buffer#write

implement IO::Buffer#write

--- ext/iobuffer.c
+++ ext/iobuffer.c
@@ -83,6 +83,7 @@
   rb_define_method(cIO_Buffer, "empty?", IO_Buffer_empty, 0);
   rb_define_method(cIO_Buffer, "<<", IO_Buffer_append, 1);
   rb_define_method(cIO_Buffer, "append", IO_Buffer_append, 1);
+  rb_define_method(cIO_Buffer, "write", IO_Buffer_append, 1);
   rb_define_method(cIO_Buffer, "prepend", IO_Buffer_prepend, 1);
   rb_define_method(cIO_Buffer, "read", IO_Buffer_read, -1);
 	rb_define_method(cIO_Buffer, "to_str", IO_Buffer_to_str, 0);
@@ -596,4 +597,4 @@
 	} while(bytes_read == nbytes);

 	return total_bytes_read;
-}+}


Minor changes in XVM.

Minor changes in XVM.

--- sources/VirtualMachine/xvm.c
+++ sources/VirtualMachine/xvm.c
@@ -467,14 +467,14 @@

 void xvm_log_readfile_error(const char* filename)
 {
-    xvm_log_error("reading file \"%s\" failed\n", filename);
+    xvm_log_error("reading file \"%s\" failed", filename);
 }

 void xvm_log_exitcode_error(const xvm_exit_codes exit_code)
 {
     const char* err = xvm_exitcode_to_string(exit_code);
     if (err != NULL)
-        xvm_log_error("program terminated with error: \"%s\"\n", err);
+        xvm_log_error("program terminated with error: \"%s\"", err);
 }

@@ -894,7 +894,7 @@
     else if (opcode == OPCODE_PUSHC)
         printf("%i", _xvm_instr_get_sgn_value26(instr));

-    printf("\n");
+    puts("");
 }

 #endif
@@ -1863,7 +1863,7 @@
     module->handle = LoadLibraryA(filename);
     if (module->handle == 0)
     {
-        xvm_log_error("loading module \"%s\" failed\n", filename);
+        xvm_log_error("loading module \"%s\" failed", filename);
         return 0;
     }

@@ -1878,7 +1878,7 @@
     module->handle = dlopen(filename, RTLD_LAZY);
     if (module->handle == NULL)
     {
-        xvm_log_error("loading module \"%s\" failed\n", filename);
+        xvm_log_error("loading module \"%s\" failed", filename);
         return 0;
     }

@@ -1891,7 +1891,7 @@

     if (module->proc_count == NULL || module->fetch_proc == NULL || module->fetch_ident == NULL)
     {
-        xvm_log_error("loading interface of module \"%s\" failed\n", filename);
+        xvm_log_error("loading interface of module \"%s\" failed", filename);
         return 0;
     }

@@ -1929,6 +1929,10 @@
     return 0;
 }

+/*
+This function binds all invocations of the specified module to the byte code.
+All module invocations, which are not part of the byte code, are ignored.
+*/
 static int _xvm_bytecode_bind_module_ext(xvm_bytecode* byte_code, const xvm_module* module, int unbindFlag)
 {
     if (byte_code == NULL || module == NULL)
@@ -1944,8 +1948,6 @@
     int num_procs = module->proc_count();

     // Bind all module invocation procedures to byte code
-    size_t num_errors = 0;
-
     for (int i = 0; i < num_procs; ++i)
     {
         // Fetch invocation identifier
@@ -1956,8 +1958,7 @@
         if (unbindFlag != 0)
         {
             // Unbind procedure invocation
-            if (xvm_bytecode_bind_invocation(byte_code, ident, NULL) == 0)
-                ++num_errors;
+            xvm_bytecode_bind_invocation(byte_code, ident, NULL);
         }
         else
         {
@@ -1965,16 +1966,8 @@
             xvm_invocation_proc proc = module->fetch_proc(i);

             // Bind procedure invocation
-            if (xvm_bytecode_bind_invocation(byte_code, ident, proc) == 0)
-                ++num_errors;
-        }
-    }
-
-    // Check for errors during binding/unbinding
-    if (num_errors > 0)
-    {
-        xvm_log_error("%i invocation binding(s)/unbinding(s) from module to byte code failed\n", num_errors);
-        return 0;
+            xvm_bytecode_bind_invocation(byte_code, ident, proc);
+        }
     }

     return 1;
@@ -2159,7 +2152,8 @@
         case INSC_SYS_CALL:
         {
             int arg0 = _xvm_stack_pop(stack, reg_sp);
-            system(INT_TO_STR_REINTERPRET(arg0));
+            if (arg0)
+                system(INT_TO_STR_REINTERPRET(arg0));
         }
         break;

@@ -2167,7 +2161,8 @@
         case INSC_PRINT:
         {
             int arg0 = _xvm_stack_pop(stack, reg_sp);
-            printf("%s", INT_TO_STR_REINTERPRET(arg0));
+            if (arg0)
+                printf("%s", INT_TO_STR_REINTERPRET(arg0));
         }
         break;

@@ -2175,7 +2170,10 @@
         case INSC_PRINT_LN:
         {
             int arg0 = _xvm_stack_pop(stack, reg_sp);
-            puts(INT_TO_STR_REINTERPRET(arg0));
+            if (arg0)
+                puts(INT_TO_STR_REINTERPRET(arg0));
+            else
+                puts("");
         }
         break;


Updated wSearch.c

Updated wSearch.c

--- wSearch.c
+++ wSearch.c
@@ -40,7 +40,7 @@
   int i=0;
   fprintf(stderr, "%c[2K",27);
   while (*(p->processDone) == False){
-    fprintf(stderr,"%ld/%ld\r", *(p->curPos), *(p->fileSize));
+    fprintf(stderr,"Processed %ld/%ld bytes\r", *(p->curPos), *(p->fileSize));
     ++i;
     sleep(1);
   }


Unify macro O_BINARY for xdb_open

Unify macro O_BINARY for xdb_open

--- libscws/xdb.c
+++ libscws/xdb.c
@@ -34,6 +34,10 @@
 #include <sys/mman.h>
 #endif

+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 static int _xdb_hasher(xdb_t x, const char *s, int len)
 {
 	unsigned int h = x->base;
@@ -135,11 +139,7 @@
 		return NULL;

 	/* try to open & check the file */
-#ifdef WIN32
-	if ((x->fd = open(fpath, mode == 'w' ? O_RDWR|O_BINARY : O_RDONLY|O_BINARY)) < 0)
-#else //WIN32
-	if ((x->fd = open(fpath, mode == 'w' ? O_RDWR : O_RDONLY)) < 0)
-#endif //WIN32
+	if ((x->fd = open(fpath, mode == 'w' ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY)) < 0)
 	{
 #ifdef DEBUG
 		perror("Failed to open the XDB file");


usb: use driver_exists function

usb: use driver_exists function

--- libtock/usb.c
+++ libtock/usb.c
@@ -1,15 +1,7 @@
 #include "usb.h"

 int usb_exists(void) {
-  syscall_return_t com = command2(DRIVER_NUM_USB, 0, 0, 0);
-  if (com.type == TOCK_SYSCALL_SUCCESS) {
-    return TOCK_SUCCESS;
-  } else if (com.type > TOCK_SYSCALL_SUCCESS) {
-    // Returned an incorrect success code
-    return TOCK_FAIL;
-  } else {
-    return tock_error_to_rcode(com.data[0]);
-  }
+  return driver_exists(DRIVER_NUM_USB);
 }

 int usb_subscribe(subscribe_cb callback, void *ud) {


Refactor board/interface linking logic

Refactor board/interface linking logic

--- libty/board.c
+++ libty/board.c
@@ -135,6 +135,7 @@

     ty_list_init(&board->interfaces);

+    assert(iface->model);
     board->model = iface->model;
     board->serial = iface->serial;

@@ -282,9 +283,19 @@
     return NULL;
 }

-static inline bool model_is_valid(const tyb_board_model *model)
+static bool model_is_real(const tyb_board_model *model)
 {
     return model && model->code_size;
+}
+
+static bool iface_is_compatible(tyb_board_interface *iface, tyb_board *board)
+{
+    if (model_is_real(iface->model) && model_is_real(board->model) && iface->model != board->model)
+        return false;
+    if (iface->serial && board->serial && iface->serial != board->serial)
+        return false;
+
+    return true;
 }

 static int add_interface(tyb_monitor *manager, tyd_device *dev)
@@ -300,29 +311,28 @@

     board = find_board(manager, tyd_device_get_location(dev));

-    /* Maybe the device notifications came in the wrong order, or somehow the device removal
-       notifications were dropped somewhere and we never got it, so use heuristics to improve
-       board change detection. */
+    /* Maybe the device notifications came in the wrong order, or somehow the device
+       removal notifications were dropped somewhere and we never got them, so use
+       heuristics to improve board change detection. */
+    if (board && !iface_is_compatible(iface, board)) {
+        if (board->state == TYB_BOARD_STATE_ONLINE)
+            close_board(board);
+        drop_board(board);
+
+        tyb_board_unref(board);
+        board = NULL;
+    }
+
     if (board) {
-        if ((model_is_valid(iface->model) && model_is_valid(board->model) && iface->model != board->model)
-                || iface->serial != board->serial) {
-            if (board->state == TYB_BOARD_STATE_ONLINE)
-                close_board(board);
-            drop_board(board);
-
-            tyb_board_unref(board);
-            board = NULL;
-        } else if (board->vid != tyd_device_get_vid(dev) || board->pid != tyd_device_get_pid(dev)) {
+        if (board->vid != tyd_device_get_vid(dev) || board->pid != tyd_device_get_pid(dev)) {
             if (board->state == TYB_BOARD_STATE_ONLINE)
                 close_board(board);

             board->vid = tyd_device_get_vid(dev);
             board->pid = tyd_device_get_pid(dev);
         }
-    }
-
-    if (board) {
-        if (model_is_valid(iface->model))
+
+        if (model_is_real(iface->model))
             board->model = iface->model;
         if (iface->serial)
             board->serial = iface->serial;
@@ -1276,7 +1286,7 @@

     if (flags & TYB_UPLOAD_NOCHECK) {
         fw = task->upload.fws[0];
-    } else if (model_is_valid(board->model)) {
+    } else if (model_is_real(board->model)) {
         r = get_compatible_firmware(board, task->upload.fws, task->upload.fws_count, &fw);
         if (r < 0)
             return r;
@@ -1312,7 +1322,6 @@
     }

     if (!fw) {
-        // FIXME: make sure board->model is set
         r = get_compatible_firmware(board, task->upload.fws, task->upload.fws_count, &fw);
         if (r < 0)
             return r;


remove FIXME about parent-child relationships

Doesn't seem worth this holding things up.

--- libusb/core.c
+++ libusb/core.c
@@ -486,7 +486,8 @@
 		}
 	}

-	/* FIXME: implement later */
+	/* libusb doesn't implement this and it doesn't seem that important. If
+	 * someone asks for it, we can implement it in v1.1 or later. */
 	dev->num_children = 0;
 	dev->children = NULL;


rename "format" to "fmt" for consistency

--- libxo/libxo.c
+++ libxo/libxo.c
@@ -3644,6 +3644,10 @@
     return 0;
 }

+/*
+ * Remove any numeric precision/width format from the format string by
+ * inserting the "%" after the [0-9]+, returning the substring.
+ */
 static char *
 xo_fix_encoding (xo_handle_t *xop UNUSED, char *encoding)
 {
@@ -3657,8 +3661,7 @@
 	    break;
     }

-    cp -= 1;
-    *cp = '%';
+    *--cp = '%';		/* Back off and insert the '%' */

     return cp;
 }
@@ -4166,7 +4169,7 @@

 static void
 xo_format_value (xo_handle_t *xop, const char *name, ssize_t nlen,
-                const char *format, ssize_t flen,
+                const char *fmt, ssize_t flen,
                 const char *encoding, ssize_t elen, xo_xff_flags_t flags)
 {
     int pretty = XOF_ISSET(xop, XOF_PRETTY);
@@ -4253,7 +4256,7 @@
 	save.xhs_columns = xop->xo_columns;
 	save.xhs_anchor_columns = xop->xo_anchor_columns;

-	xo_do_format_field(xop, NULL, format, flen, flags);
+	xo_do_format_field(xop, NULL, fmt, flen, flags);

 	if (flags & XFF_HUMANIZE)
 	    xo_format_humanize(xop, xbp, &save, flags);
@@ -4264,7 +4267,7 @@
 	    flags |= XFF_NO_OUTPUT;

 	xo_buf_append_div(xop, "data", flags, name, nlen,
-			  format, flen, encoding, elen);
+			  fmt, flen, encoding, elen);
 	break;

     case XO_STYLE_XML:
@@ -4274,24 +4277,24 @@
 	 */
 	if (flags & XFF_DISPLAY_ONLY) {
 	    flags |= XFF_NO_OUTPUT;
-	    xo_do_format_field(xop, NULL, format, flen, flags);
+	    xo_do_format_field(xop, NULL, fmt, flen, flags);
 	    break;
 	}

 	if (encoding) {
-   	    format = encoding;
+   	    fmt = encoding;
 	    flen = elen;
 	} else {
 	    char *enc  = alloca(flen + 1);
-	    memcpy(enc, format, flen);
+	    memcpy(enc, fmt, flen);
 	    enc[flen] = '\0';
-	    format = xo_fix_encoding(xop, enc);
-	    flen = strlen(format);
+	    fmt = xo_fix_encoding(xop, enc);
+	    flen = strlen(fmt);
 	}

 	if (nlen == 0) {
 	    static char missing[] = "missing-field-name";
-	    xo_failure(xop, "missing field name: %s", format);
+	    xo_failure(xop, "missing field name: %s", fmt);
 	    name = missing;
 	    nlen = sizeof(missing) - 1;
 	}
@@ -4327,7 +4330,7 @@
 	}

 	xo_data_append(xop, ">", 1);
-	xo_do_format_field(xop, NULL, format, flen, flags);
+	xo_do_format_field(xop, NULL, fmt, flen, flags);
 	xo_data_append(xop, "</", 2);
 	xo_data_escape(xop, name, nlen);
 	xo_data_append(xop, ">", 1);
@@ -4338,19 +4341,19 @@
     case XO_STYLE_JSON:
 	if (flags & XFF_DISPLAY_ONLY) {
 	    flags |= XFF_NO_OUTPUT;
-	    xo_do_format_field(xop, NULL, format, flen, flags);
+	    xo_do_format_field(xop, NULL, fmt, flen, flags);
 	    break;
 	}

 	if (encoding) {
-	    format = encoding;
+	    fmt = encoding;
 	    flen = elen;
 	} else {
 	    char *enc  = alloca(flen + 1);
-	    memcpy(enc, format, flen);
+	    memcpy(enc, fmt, flen);
 	    enc[flen] = '\0';
-	    format = xo_fix_encoding(xop, enc);
-	    flen = strlen(format);
+	    fmt = xo_fix_encoding(xop, enc);
+	    flen = strlen(fmt);
 	}

 	int first = (xop->xo_stack[xop->xo_depth].xs_flags & XSF_NOT_FIRST)
@@ -4364,16 +4367,16 @@
 	    quote = 0;
 	else if (flen == 0) {
 	    quote = 0;
-	    format = "true";	/* JSON encodes empty tags as a boolean true */
+	    fmt = "true";	/* JSON encodes empty tags as a boolean true */
 	    flen = 4;
-	} else if (strchr("diouDOUeEfFgG", format[flen - 1]) == NULL)
+	} else if (strchr("diouDOUeEfFgG", fmt[flen - 1]) == NULL)
 	    quote = 1;
 	else
 	    quote = 0;

 	if (nlen == 0) {
 	    static char missing[] = "missing-field-name";
-	    xo_failure(xop, "missing field name: %s", format);
+	    xo_failure(xop, "missing field name: %s", fmt);
 	    name = missing;
 	    nlen = sizeof(missing) - 1;
 	}
@@ -4407,7 +4410,7 @@
 	if (quote)
 	    xo_data_append(xop, "\"", 1);

-	xo_do_format_field(xop, NULL, format, flen, flags);
+	xo_do_format_field(xop, NULL, fmt, flen, flags);

 	if (quote)
 	    xo_data_append(xop, "\"", 1);
@@ -4416,38 +4419,38 @@
     case XO_STYLE_SDPARAMS:
 	if (flags & XFF_DISPLAY_ONLY) {
 	    flags |= XFF_NO_OUTPUT;
-	    xo_do_format_field(xop, NULL, format, flen, flags);
+	    xo_do_format_field(xop, NULL, fmt, flen, flags);
 	    break;
 	}

 	if (encoding) {
-	    format = encoding;
+	    fmt = encoding;
 	    flen = elen;
 	} else {
 	    char *enc  = alloca(flen + 1);
-	    memcpy(enc, format, flen);
+	    memcpy(enc, fmt, flen);
 	    enc[flen] = '\0';
-	    format = xo_fix_encoding(xop, enc);
-	    flen = strlen(format);
+	    fmt = xo_fix_encoding(xop, enc);
+	    flen = strlen(fmt);
 	}

 	if (nlen == 0) {
 	    static char missing[] = "missing-field-name";
-	    xo_failure(xop, "missing field name: %s", format);
+	    xo_failure(xop, "missing field name: %s", fmt);
 	    name = missing;
 	    nlen = sizeof(missing) - 1;
 	}

 	xo_data_escape(xop, name, nlen);
 	xo_data_append(xop, "=\"", 2);
-	xo_do_format_field(xop, NULL, format, flen, flags);
+	xo_do_format_field(xop, NULL, fmt, flen, flags);
 	xo_data_append(xop, "\" ", 2);
 	break;

     case XO_STYLE_ENCODER:
 	if (flags & XFF_DISPLAY_ONLY) {
 	    flags |= XFF_NO_OUTPUT;
-	    xo_do_format_field(xop, NULL, format, flen, flags);
+	    xo_do_format_field(xop, NULL, fmt, flen, flags);
 	    break;
 	}

@@ -4457,27 +4460,27 @@
 	    quote = 0;
 	else if (flen == 0) {
 	    quote = 0;
-	    format = "true";	/* JSON encodes empty tags as a boolean true */
+	    fmt = "true";	/* JSON encodes empty tags as a boolean true */
 	    flen = 4;
-	} else if (strchr("diouxXDOUeEfFgGaAcCp", format[flen - 1]) == NULL)
+	} else if (strchr("diouxXDOUeEfFgGaAcCp", fmt[flen - 1]) == NULL)
 	    quote = 1;
 	else
 	    quote = 0;

 	if (encoding) {
-	    format = encoding;
+	    fmt = encoding;
 	    flen = elen;
 	} else {
 	    char *enc  = alloca(flen + 1);
-	    memcpy(enc, format, flen);
+	    memcpy(enc, fmt, flen);
 	    enc[flen] = '\0';
-	    format = xo_fix_encoding(xop, enc);
-	    flen = strlen(format);
+	    fmt = xo_fix_encoding(xop, enc);
+	    flen = strlen(fmt);
 	}

 	if (nlen == 0) {
 	    static char missing[] = "missing-field-name";
-	    xo_failure(xop, "missing field name: %s", format);
+	    xo_failure(xop, "missing field name: %s", fmt);
 	    name = missing;
 	    nlen = sizeof(missing) - 1;
 	}
@@ -4487,7 +4490,7 @@
 	xo_data_append(xop, "", 1);

 	ssize_t value_offset = xo_buf_offset(&xop->xo_data);
-	xo_do_format_field(xop, NULL, format, flen, flags);
+	xo_do_format_field(xop, NULL, fmt, flen, flags);
 	xo_data_append(xop, "", 1);

 	xo_encoder_handle(xop, quote ? XO_OP_STRING : XO_OP_CONTENT,


winpr-makecert: remove dependency on OPENSSL_Applink on Windows

--- winpr/tools/makecert/makecert.c
+++ winpr/tools/makecert/makecert.c
@@ -40,7 +40,6 @@
 	int argc;
 	char** argv;

-	BIO* bio;
 	RSA* rsa;
 	X509* x509;
 	EVP_PKEY* pkey;
@@ -454,7 +453,9 @@
 int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* path)
 {
 	FILE* fp;
+	int status;
 	int length;
+	int offset;
 	char* filename;
 	char* fullpath;

@@ -485,6 +486,9 @@

 	if (fp)
 	{
+		BIO* bio;
+		BYTE* x509_str;
+
 		if (context->pfxFormat)
 		{
 			if (!context->password)
@@ -497,17 +501,136 @@
 			OpenSSL_add_all_ciphers();
 			OpenSSL_add_all_digests();

-			context->pkcs12 = PKCS12_create(context->password, context->default_name, context->pkey,
-					context->x509, NULL, 0, 0, 0, 0, 0);
-
-			i2d_PKCS12_fp(fp, context->pkcs12);
+			context->pkcs12 = PKCS12_create(context->password, context->default_name,
+						context->pkey, context->x509, NULL, 0, 0, 0, 0, 0);
+
+			bio = BIO_new(BIO_s_mem());
+
+			if (!bio)
+				return -1;
+
+			status = i2d_PKCS12_bio(bio, context->pkcs12);
+
+			offset = 0;
+			length = 2048;
+			x509_str = (BYTE*) malloc(length);
+
+			status = BIO_read(bio, x509_str, length);
+
+			if (status < 0)
+				return -1;
+
+			offset += status;
+
+			while (offset >= length)
+			{
+				length *= 2;
+				x509_str = (BYTE*) realloc(x509_str, length);
+
+				status = BIO_read(bio, &x509_str[offset], length);
+
+				if (status < 0)
+					break;
+
+				offset += status;
+			}
+
+			if (status < 0)
+				return -1;
+
+			length = offset;
+
+			fwrite((void*) x509_str, length, 1, fp);
+
+			free(x509_str);
+			BIO_free(bio);
 		}
 		else
 		{
-			PEM_write_X509(fp, context->x509);
+			bio = BIO_new(BIO_s_mem());
+
+			if (!bio)
+				return -1;
+
+			status = PEM_write_bio_X509(bio, context->x509);
+
+			offset = 0;
+			length = 2048;
+			x509_str = (BYTE*) malloc(length);
+
+			status = BIO_read(bio, x509_str, length);
+
+			if (status < 0)
+				return -1;
+
+			offset += status;
+
+			while (offset >= length)
+			{
+				length *= 2;
+				x509_str = (BYTE*) realloc(x509_str, length);
+
+				status = BIO_read(bio, &x509_str[offset], length);
+
+				if (status < 0)
+					break;
+
+				offset += status;
+			}
+
+			if (status < 0)
+				return -1;
+
+			length = offset;
+
+			fwrite((void*) x509_str, length, 1, fp);
+
+			free(x509_str);
+			BIO_free(bio);

 			if (context->pemFormat)
-				PEM_write_PrivateKey(fp, context->pkey, NULL, NULL, 0, NULL, NULL);
+			{
+				bio = BIO_new(BIO_s_mem());
+
+				if (!bio)
+					return -1;
+
+				status = PEM_write_bio_PrivateKey(bio, context->pkey, NULL, NULL, 0, NULL, NULL);
+
+				offset = 0;
+				length = 2048;
+				x509_str = (BYTE*) malloc(length);
+
+				status = BIO_read(bio, x509_str, length);
+
+				if (status < 0)
+					return -1;
+
+				offset += status;
+
+				while (offset >= length)
+				{
+					length *= 2;
+					x509_str = (BYTE*) realloc(x509_str, length);
+
+					status = BIO_read(bio, &x509_str[offset], length);
+
+					if (status < 0)
+						break;
+
+					offset += status;
+				}
+
+				if (status < 0)
+					return -1;
+
+				length = offset;
+
+				fwrite((void*) x509_str, length, 1, fp);
+
+				free(x509_str);
+				BIO_free(bio);
+			}
 		}

 		fclose(fp);
@@ -522,7 +645,9 @@
 int makecert_context_output_private_key_file(MAKECERT_CONTEXT* context, char* path)
 {
 	FILE* fp;
+	int status;
 	int length;
+	int offset;
 	char* filename;
 	char* fullpath;

@@ -551,7 +676,50 @@

 	if (fp)
 	{
-		PEM_write_PrivateKey(fp, context->pkey, NULL, NULL, 0, NULL, NULL);
+		BIO* bio;
+		BYTE* x509_str;
+
+		bio = BIO_new(BIO_s_mem());
+
+		if (!bio)
+			return -1;
+
+		status = PEM_write_bio_PrivateKey(bio, context->pkey, NULL, NULL, 0, NULL, NULL);
+
+		offset = 0;
+		length = 2048;
+		x509_str = (BYTE*) malloc(length);
+
+		status = BIO_read(bio, x509_str, length);
+
+		if (status < 0)
+			return -1;
+
+		offset += status;
+
+		while (offset >= length)
+		{
+			length *= 2;
+			x509_str = (BYTE*) realloc(x509_str, length);
+
+			status = BIO_read(bio, &x509_str[offset], length);
+
+			if (status < 0)
+				break;
+
+			offset += status;
+		}
+
+		if (status < 0)
+			return -1;
+
+		length = offset;
+
+		fwrite((void*) x509_str, length, 1, fp);
+
+		free(x509_str);
+		BIO_free(bio);
+
 		fclose(fp);
 	}

@@ -581,9 +749,6 @@

 	if (!context->common_name)
 		context->common_name = _strdup(context->default_name);
-
-	CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
-	context->bio = BIO_new_fp(stderr, BIO_NOCLOSE);

 	if (!context->pkey)
 		context->pkey = EVP_PKEY_new();
@@ -712,7 +877,55 @@
 	 */

 	if (!context->silent)
-		X509_print_fp(stdout, context->x509);
+	{
+		BIO* bio;
+		int status;
+		int length;
+		int offset;
+		BYTE* x509_str;
+
+		bio = BIO_new(BIO_s_mem());
+
+		if (!bio)
+			return -1;
+
+		status = X509_print(bio, context->x509);
+
+		offset = 0;
+		length = 2048;
+		x509_str = (BYTE*) malloc(length + 1);
+
+		status = BIO_read(bio, x509_str, length);
+
+		if (status < 0)
+			return -1;
+
+		offset += status;
+
+		while (offset >= length)
+		{
+			length *= 2;
+			x509_str = (BYTE*) realloc(x509_str, length + 1);
+
+			status = BIO_read(bio, &x509_str[offset], length);
+
+			if (status < 0)
+				break;
+
+			offset += status;
+		}
+
+		if (status < 0)
+			return -1;
+
+		length = offset;
+		x509_str[length] = '\0';
+
+		printf("%s", x509_str);
+
+		free(x509_str);
+		BIO_free(bio);
+	}

 	/**
 	 * Output certificate and private key to files
@@ -757,9 +970,6 @@

 		CRYPTO_cleanup_all_ex_data();

-		CRYPTO_mem_leaks(context->bio);
-		BIO_free(context->bio);
-
 		free(context);
 	}
 }


parser: Free raiser if a component failed. Also free raiser's message at end.

The first was spotted by running lily_failtest under valgrind.
The second was spotted by AFT going through sanity.ly

--- lily_parser.c
+++ lily_parser.c
@@ -617,6 +617,7 @@
     lily_free_lex_state(parser->lex);
     lily_free_emit_state(parser->emit);
     lily_free_vm_state(parser->vm);
+    lily_free(parser->raiser->message);
     lily_free(parser->raiser);
     lily_free(parser);
 }
@@ -654,6 +655,7 @@
             lily_ast_free_pool(s->ast_pool);
         if (s->vm != NULL)
             lily_free_vm_state(s->vm);
+        lily_free(raiser);
         lily_free(s);
         return NULL;
     }


Add mostly stub functions for expression parsing. Handle builtin functions.

An abstract syntax tree, and bytecode emitter are still missing. This feels
incomplete, and it is. Also, the lexer needs to send parenthesis and such.

But at least the very basic thing is done. Progress!

--- lily_parser.c
+++ lily_parser.c
@@ -23,6 +23,28 @@
        this function is called. */
     {"", 1, 1}
 };
+
+typedef struct {
+    int depth;
+    int *num_expected;
+    int num_args;
+} expr_data;
+
+expr_data *expr_state;
+
+static void clear_expr_state(void)
+{
+    expr_state->depth = 0;
+    expr_state->num_args = 0;
+    memset(expr_state->num_expected, 0, 32);
+}
+
+static void enter_parenth(int args_needed)
+{
+    expr_state->num_expected[expr_state->depth] =
+        expr_state->num_args + args_needed;
+    expr_state->depth++;
+}

 void lily_init_parser(lily_parser_data *d)
 {
@@ -55,6 +77,54 @@
         lily_impl_fatal("Out of memory creating code section.\n");
     main_func->code_len = 4;
     main_func->code_pos = 0;
+
+    expr_state = malloc(sizeof(expr_data));
+    if (expr_state == NULL)
+        lily_impl_fatal("Out of memory creating expr info.\n");
+
+    expr_state->num_expected = malloc(sizeof(int) * 32);
+    if (expr_state->num_expected == NULL)
+        lily_impl_fatal("Out of memory creating expr info.\n");
+
+    clear_expr_state();
+}
+
+static lily_symbol *find_symbol(char *name)
+{
+    lily_symbol *sym;
+
+    sym = symtab;
+    while (sym != NULL) {
+        if (strcmp(sym->sym_name, name) == 0)
+            return sym;
+        sym = sym->next;
+    }
+    return NULL;
+}
+
+static void parse_expr_value(void)
+{
+    if (tok->tok_type == tk_word) {
+        lily_symbol *sym = find_symbol(tok->word_buffer);
+
+        if (sym != NULL) {
+            if (sym->callable) {
+                enter_parenth(sym->num_args);
+                lily_lexer();
+                parse_expr_value();
+            }
+        }
+    }
+}
+
+static void parse_expr_binary(void)
+{
+    parse_expr_value();
+};
+
+static void parse_statement(void)
+{
+    parse_expr_binary();
 }

 void lily_parser(void)
@@ -62,4 +132,6 @@
     tok = lily_lexer_token();

     lily_lexer();
+    if (tok->tok_type == tk_word)
+        parse_statement();
 }


Update BlynkProtocol.h

Update BlynkProtocol.h

--- firmware/BlynkProtocol.h
+++ firmware/BlynkProtocol.h
@@ -16,6 +16,7 @@
 #include "BlynkDebug.h"
 #include "BlynkProtocolDefs.h"
 #include "BlynkApi.h"
+#include "BlynkUtility.h"

 template <class Transp>
 class BlynkProtocol


Fix return value.

Fix return value.

--- php_swoole.h
+++ php_swoole.h
@@ -494,14 +494,14 @@
 void swoole_set_object_by_handle(uint32_t handle, void *ptr);
 void swoole_set_property_by_handle(uint32_t handle, int property_id, void *ptr);

-static sw_inline void* swoole_set_object(zval *zobject, void *ptr)
-{
-    return swoole_set_object_by_handle(Z_OBJ_HANDLE_P(zobject), ptr);
+static sw_inline void swoole_set_object(zval *zobject, void *ptr)
+{
+    swoole_set_object_by_handle(Z_OBJ_HANDLE_P(zobject), ptr);
 }

-static sw_inline void* swoole_set_property(zval *zobject, int property_id, void *ptr)
-{
-    return swoole_set_property_by_handle(Z_OBJ_HANDLE_P(zobject), property_id, ptr);
+static sw_inline void swoole_set_property(zval *zobject, int property_id, void *ptr)
+{
+    swoole_set_property_by_handle(Z_OBJ_HANDLE_P(zobject), property_id, ptr);
 }

 int swoole_convert_to_fd(zval *zfd);


enabled replay class constructor to take a file path as argument

--- php_yugioh.c
+++ php_yugioh.c
@@ -52,7 +52,7 @@

 // Argument information
 // {{{
-ZEND_BEGIN_ARG_INFO_EX(arginfo_yugioh_replay___construct, 0, 0, 0)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_yugioh_replay___construct, 0, 0, 1)
 ZEND_END_ARG_INFO()

 ZEND_BEGIN_ARG_INFO_EX(arginfo_yugioh_replay_from_file, 0, 0, 1)
@@ -130,12 +130,16 @@
 };
 // }}}

-// public function yugioh\replay::__construct(void) : void
+// public function yugioh\replay::__construct(string $file) : void
 // {{{
 PHP_METHOD(yugioh_replay, __construct)
 {
-	if (zend_parse_parameters_none() == FAILURE)
-		return;
+	char *file = NULL;
+	size_t file_len;
+
+	int argc = ZEND_NUM_ARGS();
+	if (zend_parse_parameters(argc, "s", STR_ARG(file)) == FAILURE)
+		RETURN_NULL();

 	zval *self = getThis();
 	HashTable *players = zend_hash_create(0);
@@ -143,6 +147,12 @@
 	zval players_zv;
 	ZVAL_ARR(&players_zv, players);
 	zend_update_property(yugioh_replay_class_entry, self, "players", sizeof("players") - 1, &players_zv);
+
+	zval func_name, rv, argv;
+	ZVAL_STRINGL(&argv, file, file_len);
+
+	ZVAL_LSTRING(&func_name, "read_file");
+	call_user_function(&Z_CE_P(self)->function_table, self, &func_name, &rv, 1, &argv);
 }
 // }}}


Add stream functionality to Python UGFX API

--- stmhal/ugfx.c
+++ stmhal/ugfx.c
@@ -695,7 +695,45 @@
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_ugfx_send_tab_obj, pyb_ugfx_send_tab);

-
+/// \method stream_start(x1, y1, w, h)
+///
+/// Starts a display stream
+///
+STATIC mp_obj_t pyb_ugfx_stream_start(mp_uint_t n_args, const mp_obj_t *args) {
+    // extract arguments
+    //pyb_ugfx_obj_t *self = args[0];
+    int x = mp_obj_get_int(args[1]);
+    int y = mp_obj_get_int(args[2]);
+    int w = mp_obj_get_int(args[3]);
+    int h = mp_obj_get_int(args[4]);
+
+    gdispStreamStart(x, y, w, h);
+
+    return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_ugfx_stream_start_obj, 5, 5, pyb_ugfx_stream_start);
+
+/// \method stream_color(color)
+///
+/// Sets a pixel. Needs to be called after stream_start
+///
+STATIC mp_obj_t pyb_ugfx_stream_color(mp_obj_t self_in, mp_obj_t color) {
+    gdispStreamColor(mp_obj_get_int(color));
+
+    return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_ugfx_stream_color_obj, pyb_ugfx_stream_color);
+
+/// \method stream_stop()
+///
+/// Ends stream
+///
+STATIC mp_obj_t pyb_ugfx_stream_stop(mp_obj_t self_in) {
+    gdispStreamStop();
+
+    return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_ugfx_stream_stop_obj, pyb_ugfx_stream_stop);

 STATIC const mp_map_elem_t pyb_ugfx_locals_dict_table[] = {
@@ -721,6 +759,11 @@
     { MP_OBJ_NEW_QSTR(MP_QSTR_print_fonts), (mp_obj_t)&pyb_ugfx_print_fonts_obj },
     { MP_OBJ_NEW_QSTR(MP_QSTR_send_tab), (mp_obj_t)&pyb_ugfx_send_tab_obj },

+    // instance methods: stream
+    { MP_OBJ_NEW_QSTR(MP_QSTR_stream_start), (mp_obj_t)&pyb_ugfx_stream_start_obj },
+    { MP_OBJ_NEW_QSTR(MP_QSTR_stream_color), (mp_obj_t)&pyb_ugfx_stream_color_obj },
+    { MP_OBJ_NEW_QSTR(MP_QSTR_stream_stop), (mp_obj_t)&pyb_ugfx_stream_stop_obj },
+
 	//class constants
     { MP_OBJ_NEW_QSTR(MP_QSTR_RED),        MP_OBJ_NEW_SMALL_INT(Red) },
     { MP_OBJ_NEW_QSTR(MP_QSTR_BLUE),       MP_OBJ_NEW_SMALL_INT(Blue) },


Fix c-unicode.c testcase again.

Fix c-unicode.c testcase again.

Specifying a fixed triple is not possible because that target may not
even be compiler. Go for a simpler fix by using a _? regex for the
prefix.

git-svn-id: ffe668792ed300d6c2daa1f6eba2e0aa28d7ec6c@253758 91177308-0d34-0410-b5e6-96231b3b80d8

--- test/CodeGen/c-unicode.c
+++ test/CodeGen/c-unicode.c
@@ -1,7 +1,7 @@
-// RUN: %clang --target=x86_64--linux-gnu -S %s -o - | FileCheck %s -check-prefix=ALLOWED
-// RUN: not %clang --target=x86_64--linux-gnu -std=c89 -S %s -o - 2>&1 | FileCheck %s -check-prefix=DENIED
+// RUN: %clang -S %s -o - | FileCheck %s -check-prefix=ALLOWED
+// RUN: not %clang -std=c89 -S %s -o - 2>&1 | FileCheck %s -check-prefix=DENIED
 int \uaccess = 0;
-// ALLOWED: "곎ss":
+// ALLOWED: "{{_?}}곎ss":
 // ALLOWED-NOT: "\uaccess":
 // DENIED: warning: universal character names are only valid in C99 or C++; treating as '\' followed by identifier [-Wunicode]
 // DENIED: error: expected identifier or '('


[MS] add an init test for thumbv7-windows-msvc

git-svn-id: ffe668792ed300d6c2daa1f6eba2e0aa28d7ec6c@318736 91177308-0d34-0410-b5e6-96231b3b80d8

--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -1437,6 +1437,11 @@
 // AARCH64-DARWIN: #define __WINT_TYPE__ int
 // AARCH64-DARWIN: #define __WINT_WIDTH__ 32
 // AARCH64-DARWIN: #define __aarch64__ 1
+
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=thumbv7-windows-msvc < /dev/null | FileCheck -match-full-lines -check-prefix ARM-MSVC %s
+//
+// ARM-MSVC: #define _M_ARM_NT 1
+// ARM-MSVC: #define _WIN32 1

 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=aarch64-windows-msvc < /dev/null | FileCheck -match-full-lines -check-prefix AARCH64-MSVC %s
 //


Working version with apr_sockets ....

Working version with apr_sockets ....

--- mod_websocket_mosquitto.c
+++ mod_websocket_mosquitto.c
@@ -34,7 +34,7 @@
   apr_thread_t *thread;
   int counter;
   int active;
-  int sockfd;
+  apr_socket_t *sockfd;
 } MosquittoData;

@@ -73,7 +73,8 @@
   if (dib != NULL) {
     /* Keep sending messages as long as the connection is active */
     while (dib->active) {
-      int bread = recv(dib->sockfd,buffer,sizeof(buffer),0);
+	  apr_size_t bread=sizeof(buffer);
+      apr_socket_recv(dib->sockfd,buffer,&bread);
       if (bread && dib->server)
          dib->server->send(dib->server, MESSAGE_TYPE_BINARY, (unsigned char *)buffer,bread);
      else
@@ -86,8 +87,7 @@
 void * CALLBACK mosquitto_on_connect(const WebSocketServer *server)
 {
   MosquittoData *dib = NULL;
-  struct sockaddr_in pin;
-  struct hostent *hp;
+  apr_sockaddr_t *sa;

   if ((server != NULL) && (server->version == WEBSOCKET_SERVER_VERSION_1)) {
     /* Get access to the request_rec strucure for this connection */
@@ -125,20 +125,15 @@
 		  request_rec *r = server->request(server);
 		  mosquitto_cfg* dir = ap_get_module_config(r->per_dir_config, &mod_websocket_mosquitto) ;

-		  ap_log_error(APLOG_MARK, APLOG_CRIT,0,NULL,"Connect %s:%s",dir->broker,dir->port);
+		  int rv = apr_sockaddr_info_get(&sa,dir->broker,APR_INET,atoi(dir->port),0,pool);
+		  if (rv) ap_log_error(APLOG_MARK, APLOG_CRIT,0,NULL,"apr_sockaddr_info_get failed #%x",rv);

-		  /* fill in the socket structure with host information */
-		  memset(&pin, 0, sizeof(pin));
-		  pin.sin_family = AF_INET;
-		  hp = gethostbyname(dir->broker); // we need to configure it later
-		  pin.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr;
-		  pin.sin_port = htons(atoi(dir->port));
-
-		  /* grab an Internet domain socket */
-		  dib->sockfd = socket(AF_INET, SOCK_STREAM, 0);
-          connect(dib->sockfd,(struct sockaddr *)  &pin, sizeof(pin));
-
-
+		  rv = apr_socket_create(&dib->sockfd,APR_INET, SOCK_STREAM, APR_PROTO_TCP,pool);
+		  if (rv) ap_log_error(APLOG_MARK, APLOG_CRIT,0,NULL,"apr_socket_create failed #%x",rv);
+
+		  rv = apr_socket_connect(dib->sockfd,sa);
+		  if (rv) ap_log_error(APLOG_MARK, APLOG_CRIT,0,NULL,"apr_socket_connect failed #%x",rv);
+
           /* Create a non-detached thread that will perform the work */
           if ((apr_threadattr_create(&thread_attr, pool) == APR_SUCCESS) &&
               (apr_threadattr_detach_set(thread_attr, 0) == APR_SUCCESS) &&
@@ -163,9 +158,11 @@
     const int type, unsigned char *buffer, const size_t buffer_size)
 {
   MosquittoData *dib = (MosquittoData *) plugin_private;
-
+  apr_size_t bwritten;
+
   if (dib != 0 && dib->sockfd)  // Just pass it on
-	send(dib->sockfd, buffer, buffer_size, 0);
+	bwritten = buffer_size;
+	apr_socket_send(dib->sockfd, (char *)buffer, &bwritten);
   return 0;
 }

@@ -180,7 +177,7 @@
       apr_status_t status;
       /* Wait for the thread to finish */
       status = apr_thread_join(&status, dib->thread);
-      close(dib->sockfd);
+      apr_socket_close(dib->sockfd);
     }
     apr_pool_destroy(dib->pool);
   }


vdagent-x11: move freeing of incr data sending buffers out of next_selection_request

--- vdagent-x11.c
+++ vdagent-x11.c
@@ -251,13 +251,6 @@
 static void vdagent_x11_next_selection_request(struct vdagent_x11 *x11)
 {
     struct vdagent_x11_selection_request *selection_request;
-
-    free(x11->selection_req_data);
-    x11->selection_req_data = NULL;
-    x11->selection_req_data_pos = 0;
-    x11->selection_req_data_size = 0;
-    x11->selection_req_atom = None;
-
     selection_request = x11->selection_req;
     x11->selection_req = selection_request->next;
     free(selection_request);
@@ -284,6 +277,11 @@
             vdagent_x11_next_selection_request(x11);
         }
     }
+    free(x11->selection_req_data);
+    x11->selection_req_data = NULL;
+    x11->selection_req_data_pos = 0;
+    x11->selection_req_data_size = 0;
+    x11->selection_req_atom = None;
     if (x11->conversion_req) {
         fprintf(x11->errfile,
                 "client clipboard request pending on clipboard ownership "
@@ -968,6 +966,11 @@
        incr transfer is done. Hence we do not check if we've send all data
        but instead check we've send the final 0 sized XChangeProperty. */
     if (len == 0) {
+        free(x11->selection_req_data);
+        x11->selection_req_data = NULL;
+        x11->selection_req_data_pos = 0;
+        x11->selection_req_data_size = 0;
+        x11->selection_req_atom = None;
         vdagent_x11_next_selection_request(x11);
         vdagent_x11_handle_selection_request(x11);
     }


display remaining parameters in vdpau-trace.c

--- vdpau-trace.c
+++ vdpau-trace.c
@@ -1,3 +1,4 @@
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include "vdpau-trace.h"
@@ -238,8 +239,8 @@
     (void)source_data;
     (void)source_pitches;
     if (!enabled) return;
-    fprintf(tlog, "%s%s VdpOutputSurfacePutBitsNative surface=%d\n", trace_header, impl_state,
-        surface);
+    fprintf(tlog, "%s%s VdpOutputSurfacePutBitsNative surface=%d, destination_rect=%s\n",
+        trace_header, impl_state, surface, rect2string(destination_rect));
 }

 void
@@ -338,6 +339,9 @@
     if (!enabled) return;
     fprintf(tlog, "%s%s VdpVideoMixerCreate device=%d, feature_count=%d, parameter_count=%d\n",
         trace_header, impl_state, device, feature_count, parameter_count);
+    for (uint32_t k = 0; k < feature_count; k ++)
+        fprintf(tlog, "%s      feature %s\n", trace_header_blank,
+            reverse_video_mixer_feature(features[k]));
     for (uint32_t k = 0; k < parameter_count; k ++) {
         fprintf(tlog, "%s      parameter ", trace_header_blank);
         switch (parameters[k]) {
@@ -410,6 +414,9 @@
     if (!enabled) return;
     fprintf(tlog, "%s%s VdpVideoMixerGetFeatureSupport mixer=%d, feature_count=%d\n",
         trace_header, impl_state, mixer, feature_count);
+    for (unsigned int k = 0; k < feature_count; k ++)
+        fprintf(tlog, "%s      feature %s\n", trace_header_blank,
+            reverse_video_mixer_feature(features[k]));
 }

 void
@@ -421,6 +428,9 @@
     if (!enabled) return;
     fprintf(tlog, "%s%s VdpVideoMixerGetFeatureEnables mixer=%d, feature_count=%d\n",
         trace_header, impl_state, mixer, feature_count);
+    for (unsigned int k = 0; k < feature_count; k ++)
+        fprintf(tlog, "%s      feature %s\n", trace_header_blank,
+            reverse_video_mixer_feature(features[k]));
 }

 void
@@ -433,6 +443,9 @@
     if (!enabled) return;
     fprintf(tlog, "%s%s VdpVideoMixerGetParameterValues mixer=%d, parameter_count=%d\n",
         trace_header, impl_state, mixer, parameter_count);
+    for (unsigned int k = 0; k < parameter_count; k ++)
+        fprintf(tlog, "%s      parameter %s\n", trace_header_blank,
+            reverse_video_mixer_parameter(parameters[k]));
 }

 void
@@ -445,6 +458,9 @@
     if (!enabled) return;
     fprintf(tlog, "%s%s VdpVideoMixerGetAttributeValues mixer=%d, attribute_count=%d\n",
         trace_header, impl_state, mixer, attribute_count);
+    for (unsigned int k = 0; k < attribute_count; k ++)
+        fprintf(tlog, "%s      attribute %s\n", trace_header_blank,
+            reverse_video_mixer_attribute(attributes[k]));
 }

 void
@@ -483,8 +499,8 @@
         fprintf(tlog, "%d", video_surface_future[k]);
     }
     fprintf(tlog, "],\n%s      video_source_rect=%s, destination_surface=%d, destination_rect=%s, "
-         "layers=[", trace_header_blank, rect2string(video_source_rect), destination_surface,
-         rect2string(destination_rect));
+         "destination_video_rect=%s, layers=[", trace_header_blank, rect2string(video_source_rect),
+         destination_surface, rect2string(destination_rect), rect2string(destination_video_rect));
     for (uint32_t k = 0; k < layer_count; k ++) {
         if (0 != k) fprintf(tlog, ",");
         fprintf(tlog, "{%d,src:%s,dst:%s}", layers[k].source_surface,
@@ -527,8 +543,10 @@
                                             VdpColor *const background_color)
 {
     if (!enabled) return;
-    fprintf(tlog, "%s%s VdpPresentationQueueSetBackgroundColor presentation_queue=%d\n",
-        trace_header, impl_state, presentation_queue);
+    fprintf(tlog, "%s%s VdpPresentationQueueSetBackgroundColor presentation_queue=%d, "
+        "background_color=(%.2f,%.2f,%.2f,%.2f)\n",
+        trace_header, impl_state, presentation_queue, background_color->red,
+        background_color->green, background_color->blue, background_color->alpha);
 }

 void
@@ -559,8 +577,10 @@
 {
     if (!enabled) return;
     fprintf(tlog, "%s%s VdpPresentationQueueDisplay presentation_queue=%d, surface=%d, "
-        "clip_width=%d, clip_height=%d\n", trace_header, impl_state, presentation_queue, surface,
+        "clip_width=%d, clip_height=%d,\n", trace_header, impl_state, presentation_queue, surface,
         clip_width, clip_height);
+    fprintf(tlog, "%s      earliest_presentation_time=%"PRIu64"\n", trace_header_blank,
+        earliest_presentation_time);
 }

 void