handle null pointers returned from nfs call

--- src/df.c
+++ src/df.c
@@ -105,9 +105,9 @@
 }

-FSSTAT3res get_fsstat(struct sockaddr_in *client_sock, FSSTAT3args *fsstatargp) {
+FSSTAT3res *get_fsstat(struct sockaddr_in *client_sock, FSSTAT3args *fsstatargp) {
     CLIENT client;
-    FSSTAT3res fsstatres;
+    FSSTAT3res *fsstatres;
     const u_long version = 3;
     struct timeval timeout = NFS_TIMEOUT;
     int nfs_sock = RPC_ANYSOCK;
@@ -116,14 +116,18 @@
     client = *clntudp_create(client_sock, NFS_PROGRAM, version, timeout, &nfs_sock);
     client.cl_auth = authunix_create_default();

-    fsstatres = *nfsproc3_fsstat_3(fsstatargp, &client);
-
-    if (fsstatres.status != NFS3_OK) {
-        clnt_geterr(&client, &clnt_err);
-        if (clnt_err.re_status)
-            clnt_perror(&client, "nfsproc3_fsstat_3");
-        else
-            nfs_perror(fsstatres.status);
+    fsstatres = nfsproc3_fsstat_3(fsstatargp, &client);
+
+    if (fsstatres) {
+        if (fsstatres->status != NFS3_OK) {
+            clnt_geterr(&client, &clnt_err);
+            if (clnt_err.re_status)
+                clnt_perror(&client, "nfsproc3_fsstat_3");
+            else
+                nfs_perror(fsstatres->status);
+        }
+    } else {
+        clnt_perror(&client, "nfsproc3_fsstat_3");
     }

     return fsstatres;
@@ -190,8 +194,8 @@
     char line[81];
     size_t max_path_len;
     char *path_spacing;
-    FSSTAT3args fsstatarg;
-    FSSTAT3res  fsstatres;
+    FSSTAT3args  fsstatarg;
+    FSSTAT3res  *fsstatres;
     struct sockaddr_in client_sock;

     client_sock.sin_family = AF_INET;
@@ -226,24 +230,24 @@

         fsstatres = get_fsstat(&client_sock, &fsstatarg);

-        if (fsstatres.status == NFS3_OK) {
+        if (fsstatres && fsstatres->status == NFS3_OK) {
             if (inodes) {
-                printf("%" PRIu64 "\n", fsstatres.FSSTAT3res_u.resok.tfiles - fsstatres.FSSTAT3res_u.resok.ffiles);
+                printf("%" PRIu64 "\n", fsstatres->FSSTAT3res_u.resok.tfiles - fsstatres->FSSTAT3res_u.resok.ffiles);
             } else {
                 /* format results by prefix */
                 /* keep track of the lengths for column layout */
-                len = prefix_print(fsstatres.FSSTAT3res_u.resok.tbytes, total, prefix);
+                len = prefix_print(fsstatres->FSSTAT3res_u.resok.tbytes, total, prefix);
                 if (len > total_max_len)
                     total_max_len = len;
-                len = prefix_print(fsstatres.FSSTAT3res_u.resok.tbytes - fsstatres.FSSTAT3res_u.resok.fbytes, used, prefix);
+                len = prefix_print(fsstatres->FSSTAT3res_u.resok.tbytes - fsstatres->FSSTAT3res_u.resok.fbytes, used, prefix);
                 if (len > used_max_len)
                     used_max_len = len;
-                len = prefix_print(fsstatres.FSSTAT3res_u.resok.fbytes, avail, prefix);
+                len = prefix_print(fsstatres->FSSTAT3res_u.resok.fbytes, avail, prefix);
                 if (len > avail_max_len)
                     avail_max_len = len;

                 /* percent full */
-                capacity = (1 - ((double)fsstatres.FSSTAT3res_u.resok.fbytes / fsstatres.FSSTAT3res_u.resok.tbytes)) * 100;
+                capacity = (1 - ((double)fsstatres->FSSTAT3res_u.resok.fbytes / fsstatres->FSSTAT3res_u.resok.tbytes)) * 100;

                 /* TODO check max line length < 80 or truncate path */
                 len = total_max_len + used_max_len + avail_max_len + strlen(" capacity");


Adding set_type_comparators() helper

Adding set_type_comparators() helper

--- symbol.c
+++ symbol.c
@@ -42,6 +42,7 @@

 /* local functions */
 enum type map_type(enum yytokentype t);
+void set_type_comparators();
 char *print_basetype(struct typeinfo *t);
 void print_typeinfo(FILE *stream, char *k, struct typeinfo *v);

@@ -90,6 +91,36 @@
 struct typeinfo void_type;
 struct typeinfo class_type;
 struct typeinfo unknown_type;
+
+/*
+ * Initialize comparator types
+ */
+void set_type_comparators()
+{
+	int_type.base = INT_T;
+	int_type.pointer = false;
+
+	double_type.base = DOUBLE_T;
+	double_type.pointer = false;
+
+	char_type.base = CHAR_T;
+	char_type.pointer = false;
+
+	string_type.base = CHAR_T;
+	string_type.pointer = true; /* a C string is a char* */
+
+	bool_type.base = BOOL_T;
+	bool_type.pointer = false;
+
+	void_type.base = VOID_T;
+	void_type.pointer = false;
+
+	class_type.base = CLASS_T;
+	class_type.pointer = false;
+
+	unknown_type.base = UNKNOWN_T;
+	unknown_type.pointer = false;
+}

 /*
  * Maps a Bison type to a 120++ type.
@@ -218,6 +249,8 @@
  */
 struct hasht *symbol_populate(struct tree *syntax)
 {
+	set_type_comparators();
+
 	struct hasht *global = hasht_new(32, true, NULL, NULL, &symbol_free);

 	/* initialize scope stack */
@@ -571,30 +604,8 @@
  * Get typeinfo for identifier or literal value.
  */
 struct typeinfo *get_typeinfo(struct tree *n) {
-	/* initalize/reset base type comparators */
-	int_type.base = INT_T;
-	int_type.pointer = false;
-
-	double_type.base = DOUBLE_T;
-	double_type.pointer = false;
-
-	char_type.base = CHAR_T;
-	char_type.pointer = false;
-
-	string_type.base = CHAR_T;
-	string_type.pointer = true; /* a C string is a char* */
-
-	bool_type.base = BOOL_T;
-	bool_type.pointer = false;
-
-	void_type.base = VOID_T;
-	void_type.pointer = false;
-
-	class_type.base = CLASS_T;
-	class_type.pointer = false;
-
-	unknown_type.base = UNKNOWN_T;
-	unknown_type.pointer = false;
+	/* reset base type comparators */
+	set_type_comparators();

 	/* attempt to get identifier or class */
 	char *k = get_identifier(n);


yajl_tree_parse: fix memory leak on error

ctx.stack was not being cleaned up after a parse error. this patch pops
all remaining elements and frees them.

--- src/yajl_tree.c
+++ src/yajl_tree.c
@@ -458,6 +458,9 @@
              snprintf(error_buffer, error_buffer_size, "%s", internal_err_str);
              YA_FREE(&(handle->alloc), internal_err_str);
         }
+        while (ctx.stack) {
+            yajl_tree_free(context_pop(&ctx));
+        }
         yajl_free (handle);
         return NULL;
     }


src/dm: report errno value when open fails

Signed-off-by: Jan Luebbe <3a82f1ac4ad59607a20f180f1c67ac8ba31ad0d5@pengutronix.de>

--- src/dm.c
+++ src/dm.c
@@ -68,10 +68,11 @@

 	dmfd = open("/dev/mapper/control", O_RDWR|O_CLOEXEC);
 	if (dmfd < 0) {
-		g_set_error(error,
-				G_FILE_ERROR,
-				G_FILE_ERROR_FAILED,
-				"Failed to open /dev/mapper/control");
+		int err = errno;
+		g_set_error(error,
+				G_FILE_ERROR,
+				G_FILE_ERROR_FAILED,
+				"Failed to open /dev/mapper/control: %s", g_strerror(err));
 		res = FALSE;
 		goto out;
 	}
@@ -146,10 +147,11 @@

 	checkfd = g_open(dm_verity->upper_dev, O_RDONLY|O_CLOEXEC, 0);
 	if (checkfd < 0) {
-		g_set_error(error,
-				G_FILE_ERROR,
-				G_FILE_ERROR_FAILED,
-				"Failed to open %s", dm_verity->upper_dev);
+		int err = errno;
+		g_set_error(error,
+				G_FILE_ERROR,
+				G_FILE_ERROR_FAILED,
+				"Failed to open %s: %s", dm_verity->upper_dev, g_strerror(err));
 		res = FALSE;
 		goto out_remove_dm;
 	}


More null checking!

More null checking!

--- symbol.c
+++ symbol.c
@@ -375,6 +375,9 @@
  */
 struct token *get_category_(struct tree *n, int target, int before)
 {
+	if (n == NULL)
+		return NULL;
+
 	if (tree_size(n) == 1) {
 		struct token *t = n->data;
 		if (t->category == target || t->category == before)
@@ -429,6 +432,9 @@
  */
 char *get_class(struct tree *n)
 {
+	if (n == NULL)
+		return NULL;
+
 	struct token *t = get_category(n, CLASS_NAME, IDENTIFIER);
 	if (t)
 		return t->text;
@@ -640,6 +646,11 @@
  */
 struct typeinfo *type_check(struct tree *n)
 {
+	if (n == NULL) {
+		fprintf(stderr, "type_check(): n was null\n");
+		return NULL;
+	}
+
 	if (tree_size(n) == 1)
 		return get_typeinfo(n);


Update ds.c

Update ds.c

--- src/ds.c
+++ src/ds.c
@@ -47,6 +47,19 @@
     leveldb_readoptions_set_fill_cache(server.roptions, 1);

     leveldb_writeoptions_set_sync(server.woptions, 0);
+}
+
+static void checkRlTTL(redisDb *db, robj *key) {
+    if(server.rl_ttl) {
+        if(server.rl_ttlcheck >= server.rl_ttl) {
+            return;
+        }
+        long long expire = getExpire(db,key);
+        if(expire == -1 || expire-mstime() < server.rl_ttlcheck) {
+            expire = server.rl_ttl * 1000;
+            setExpire(db, key, mstime()+expire);
+        }
+    }
 }

 void ds_exists(redisClient *c) {
@@ -1152,19 +1165,6 @@
     }
     ds_getCommand(c, 0);
     return;
-}
-
-static void checkRlTTL(redisDb *db, robj *key) {
-    if(server.rl_ttl) {
-        if(server.rl_ttlcheck >= server.rl_ttl) {
-            return;
-        }
-        long long expire = getExpire(db,key);
-        if(expire == -1 || expire-mstime() < server.rl_ttlcheck) {
-            expire = server.rl_ttl * 1000;
-            setExpire(db, key, mstime()+expire);
-        }
-    }
 }


Start hooking up PNG reading

Start hooking up PNG reading

--- stitch.c
+++ stitch.c
@@ -82,6 +82,45 @@
 static void fail(png_structp png_ptr, png_const_charp error_msg) {
 	fprintf(stderr, "PNG error %s\n", error_msg);
 	exit(EXIT_FAILURE);
+}
+
+void png_read_data(png_structp png_ptr, png_bytep out, png_size_t toread) {
+	struct data *d = (struct data *) png_get_io_ptr(png_ptr);
+	memcpy(out, d->buf + d->len, toread);
+	d->len+= toread;
+}
+
+struct image *read_png(char *s, int len) {
+	png_structp png_ptr;
+	png_infop info_ptr;
+
+	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, fail, fail, fail);
+	if (png_ptr == NULL) {
+		fprintf(stderr, "PNG failure (write struct)\n");
+		exit(EXIT_FAILURE);
+	}
+	info_ptr = png_create_info_struct(png_ptr);
+	if (info_ptr == NULL) {
+		png_destroy_write_struct(&png_ptr, NULL);
+		fprintf(stderr, "PNG failure (info struct)\n");
+		exit(EXIT_FAILURE);
+	}
+
+	struct data d;
+	d.buf = s;
+	d.len = 0;
+	d.nalloc = len;
+
+	png_set_read_fn(png_ptr, &d, png_read_data);
+	png_read_info(png_ptr, info_ptr);
+
+	struct image *i = malloc(sizeof(struct image));
+	i->width = png_get_image_width(png_ptr, info_ptr);
+	i->height = png_get_image_height(png_ptr, info_ptr);
+
+	printf("%dx%d\n", i->width, i->height);
+
+	exit(1);
 }

 int main(int argc, char **argv) {
@@ -219,9 +258,8 @@

 			struct image *i;

-			if (data.len >= 4 && memcmp(data.buf, "\211PNG", 4) == 0) {
-				fprintf(stderr, "looks like png\n");
-				exit(EXIT_FAILURE);
+			if (data.len >= 4 && memcmp(data.buf, "\x89PNG", 4) == 0) {
+				i = read_png(data.buf, data.len);
 			} else if (data.len >= 2 && memcmp(data.buf, "\xFF\xD8", 2) == 0) {
 				i = read_jpeg(data.buf, data.len);
 			} else {


MFC: r261529

MFC: r261529

Try to make the style used here consistent.


* src/fa.c (fa_make_empty): do not mark fa as minimal or deterministic

Even though the empty fa is both minimal and deterministic, this function
is also used to allocate new fa's which may be modified further,
invalidating their being marked as minimal or deterministic. For example,
the fa constructed by fa_intersect was erroneously marked as minimal
because of this, making it impossible to actually minimize that fa.

Not marking the empty fa as minimal and deterministic will not cause any
problems, and may only cause us to unnecessarily try to determinize or
minimize the fa, which, given the size of the empty fa will be very fast
operations.

--- src/fa.c
+++ src/fa.c
@@ -1795,8 +1795,12 @@
         fa_free(fa);
         return NULL;
     }
-    fa->deterministic = 1;
-    fa->minimal = 1;
+    /* Even though, technically, this fa is both minimal and deterministic,
+     * this function is also used to allocate new fa's which are then modified
+     * further. Rather than risk erroneously marking such an fa as minimal
+     * and deterministic, we do not do that here and take the minor hit if
+     * that should ever need to be determined for an actual empty fa
+     */
     return fa;
 }


(eval0eval.c:388) Bug#55227 Fix compiler warnings in innodb with gcc 4.6

--- storage/innobase/eval/eval0eval.c
+++ storage/innobase/eval/eval0eval.c
@@ -385,13 +385,11 @@
 	func_node_t*	func_node)	/*!< in: function node */
 {
 	que_node_t*	arg1;
-	que_node_t*	arg2;
 	sym_node_t*	cursor;
 	sel_node_t*	sel_node;
 	ibool		ibool_val;

 	arg1 = func_node->args;
-	arg2 = que_node_get_next(arg1);

 	ut_ad(func_node->func == PARS_NOTFOUND_TOKEN);


update wyhashmap

update wyhashmap

--- wyhash.h
+++ wyhash.h
@@ -221,13 +221,6 @@
     else{	idx[pos]=hash_of_key;	keys[pos]=key;	value[pos]=0;  }	//	if the key is new. you may insert the key or not if it is just a lookup
     free(idx);	//	free the index
 */
-/*
-static  inline  uint64_t  wyhashmap(uint64_t  *keys,  uint64_t  size,  uint64_t hash){
-  uint64_t  i;
-  for(i=hash%size;keys[i]&&keys[i]!=hash;i=(i+1)%size);
-  return  i;
-}
-*/
 #if defined(__SIZEOF_INT128__) && defined(wyhashmap128)
 typedef	__uint128_t	wyhashmap_t;
 #elif defined(wyhashmap32)


fix previous wrong change on is_autoglobal

git-svn-id: 88e1a00e4eab3b0bb0c09889526309a3e2f5bd8a@862 c26eb9a1-5813-0410-bd6c-c2e55f420ca7

--- xcache.c
+++ xcache.c
@@ -2630,19 +2630,12 @@
 {
 	xc_hash_value_t hv;

-	switch (Z_TYPE_P(name)) {
 #ifdef IS_UNICODE
-		case IS_UNICODE:
-#endif
-		case IS_STRING:
-			break;
-		default:
-#ifdef IS_UNICODE
-			convert_to_unicode(name);
+	convert_to_unicode(name);
 #else
-			convert_to_string(name);
-#endif
-	}
+	convert_to_string(name);
+#endif
+
 #ifdef IS_UNICODE
 	xce->entry.name_type = name->type;
 #endif
@@ -3146,9 +3139,15 @@
 {
 	zval *name;

-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name) == FAILURE) {
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) {
 		return;
 	}
+
+#ifdef IS_UNICODE
+	convert_to_unicode(name);
+#else
+	convert_to_string(name);
+#endif

 	RETURN_BOOL(zend_u_hash_exists(CG(auto_globals), UG(unicode), Z_STRVAL_P(name), Z_STRLEN_P(name) + 1));
 }


norme update

norme update


remove warning about unreferenced local variable

--- xcache.c
+++ xcache.c
@@ -2849,7 +2849,9 @@
 	char *ptr;
 	int left, len;
 	xc_shm_scheme_t *scheme;
+#ifdef HAVE_XCACHE_COVERAGER
 	char *covdumpdir;
+#endif

 	php_info_print_table_start();
 	php_info_print_table_header(2, "XCache Support", "enabled");


io BUGFIX properly prefix all rcp reply elements

Fixes cesnet/netopeer2#72

--- src/io.c
+++ src/io.c
@@ -800,14 +800,36 @@
 }

 static void
-nc_write_error(struct wclb_arg *arg, struct nc_server_error *err)
-{
-    uint16_t i;
+nc_write_error_elem(struct wclb_arg *arg, const char *name, uint16_t nam_len, const char *prefix, uint16_t pref_len, int open)
+{
+    if (open) {
+        nc_write_clb((void *)arg, "<", 1, 0);
+    } else {
+        nc_write_clb((void *)arg, "</", 2, 0);
+    }
+
+    if (prefix) {
+        nc_write_clb((void *)arg, prefix, pref_len, 0);
+        nc_write_clb((void *)arg, ":", 1, 0);
+    }
+
+    nc_write_clb((void *)arg, name, nam_len, 0);
+    nc_write_clb((void *)arg, ">", 1, 0);
+}
+
+static void
+nc_write_error(struct wclb_arg *arg, struct nc_server_error *err, const char *prefix)
+{
+    uint16_t i, pref_len;
     char str_sid[11];

-    nc_write_clb((void *)arg, "<rpc-error>", 11, 0);
-
-    nc_write_clb((void *)arg, "<error-type>", 12, 0);
+    if (prefix) {
+        pref_len = strlen(prefix);
+    }
+
+    nc_write_error_elem(arg, "rpc-error", 9, prefix, pref_len, 1);
+
+    nc_write_error_elem(arg, "error-type", 10, prefix, pref_len, 1);
     switch (err->type) {
     case NC_ERR_TYPE_TRAN:
         nc_write_clb((void *)arg, "transport", 9, 0);
@@ -825,9 +847,10 @@
         ERRINT;
         return;
     }
-    nc_write_clb((void *)arg, "</error-type>", 13, 0);
-
-    nc_write_clb((void *)arg, "<error-tag>", 11, 0);
+
+    nc_write_error_elem(arg, "error-type", 10, prefix, pref_len, 0);
+
+    nc_write_error_elem(arg, "error-tag", 9, prefix, pref_len, 1);
     switch (err->tag) {
     case NC_ERR_IN_USE:
         nc_write_clb((void *)arg, "in-use", 6, 0);
@@ -890,24 +913,26 @@
         ERRINT;
         return;
     }
-    nc_write_clb((void *)arg, "</error-tag>", 12, 0);
-
-    nc_write_clb((void *)arg, "<error-severity>error</error-severity>", 38, 0);
+    nc_write_error_elem(arg, "error-tag", 9, prefix, pref_len, 0);
+
+    nc_write_error_elem(arg, "error-severity", 14, prefix, pref_len, 1);
+    nc_write_clb((void *)arg, "error", 5, 0);
+    nc_write_error_elem(arg, "error-severity", 14, prefix, pref_len, 0);

     if (err->apptag) {
-        nc_write_clb((void *)arg, "<error-app-tag>", 15, 0);
+        nc_write_error_elem(arg, "error-app-tag", 13, prefix, pref_len, 1);
         nc_write_clb((void *)arg, err->apptag, strlen(err->apptag), 1);
-        nc_write_clb((void *)arg, "</error-app-tag>", 16, 0);
+        nc_write_error_elem(arg, "error-app-tag", 13, prefix, pref_len, 0);
     }

     if (err->path) {
-        nc_write_clb((void *)arg, "<error-path>", 12, 0);
+        nc_write_error_elem(arg, "error-path", 10, prefix, pref_len, 1);
         nc_write_clb((void *)arg, err->path, strlen(err->path), 1);
-        nc_write_clb((void *)arg, "</error-path>", 13, 0);
+        nc_write_error_elem(arg, "error-path", 10, prefix, pref_len, 0);
     }

     if (err->message) {
-        nc_write_clb((void *)arg, "<error-message", 14, 0);
+        nc_write_error_elem(arg, "error-message", 13, prefix, pref_len, 1);
         if (err->message_lang) {
             nc_write_clb((void *)arg, " xml:lang=\"", 11, 0);
             nc_write_clb((void *)arg, err->message_lang, strlen(err->message_lang), 1);
@@ -915,45 +940,45 @@
         }
         nc_write_clb((void *)arg, ">", 1, 0);
         nc_write_clb((void *)arg, err->message, strlen(err->message), 1);
-        nc_write_clb((void *)arg, "</error-message>", 16, 0);
+        nc_write_error_elem(arg, "error-message", 13, prefix, pref_len, 0);
     }

     if ((err->sid > -1) || err->attr_count || err->elem_count || err->ns_count || err->other_count) {
-        nc_write_clb((void *)arg, "<error-info>", 12, 0);
+        nc_write_error_elem(arg, "error-info", 10, prefix, pref_len, 1);

         if (err->sid > -1) {
-            nc_write_clb((void *)arg, "<session-id>", 12, 0);
+            nc_write_error_elem(arg, "session-id", 10, prefix, pref_len, 1);
             sprintf(str_sid, "%u", (uint32_t)err->sid);
             nc_write_clb((void *)arg, str_sid, strlen(str_sid), 0);
-            nc_write_clb((void *)arg, "</session-id>", 13, 0);
+            nc_write_error_elem(arg, "session-id", 10, prefix, pref_len, 0);
         }

         for (i = 0; i < err->attr_count; ++i) {
-            nc_write_clb((void *)arg, "<bad-attribute>", 15, 0);
+            nc_write_error_elem(arg, "bad-attribute", 13, prefix, pref_len, 1);
             nc_write_clb((void *)arg, err->attr[i], strlen(err->attr[i]), 1);
-            nc_write_clb((void *)arg, "</bad-attribute>", 16, 0);
+            nc_write_error_elem(arg, "bad-attribute", 13, prefix, pref_len, 0);
         }

         for (i = 0; i < err->elem_count; ++i) {
-            nc_write_clb((void *)arg, "<bad-element>", 13, 0);
+            nc_write_error_elem(arg, "bad-element", 11, prefix, pref_len, 1);
             nc_write_clb((void *)arg, err->elem[i], strlen(err->elem[i]), 1);
-            nc_write_clb((void *)arg, "</bad-element>", 14, 0);
+            nc_write_error_elem(arg, "bad-element", 11, prefix, pref_len, 0);
         }

         for (i = 0; i < err->ns_count; ++i) {
-            nc_write_clb((void *)arg, "<bad-namespace>", 15, 0);
+            nc_write_error_elem(arg, "bad-namespace", 13, prefix, pref_len, 1);
             nc_write_clb((void *)arg, err->ns[i], strlen(err->ns[i]), 1);
-            nc_write_clb((void *)arg, "</bad-namespace>", 16, 0);
+            nc_write_error_elem(arg, "bad-namespace", 13, prefix, pref_len, 0);
         }

         for (i = 0; i < err->other_count; ++i) {
             lyxml_print_clb(nc_write_xmlclb, (void *)arg, err->other[i], 0);
         }

-        nc_write_clb((void *)arg, "</error-info>", 13, 0);
-    }
-
-    nc_write_clb((void *)arg, "</rpc-error>", 12, 0);
+        nc_write_error_elem(arg, "error-info", 10, prefix, pref_len, 0);
+    }
+
+    nc_write_error_elem(arg, "rpc-error", 9, prefix, pref_len, 0);
 }

 /* return -1 can change session status */
@@ -962,7 +987,7 @@
 {
     va_list ap;
     int count;
-    const char *attrs;
+    const char *attrs, *base_prefix;
     struct lyd_node *content;
     struct lyxml_elem *rpc_elem;
     struct nc_server_reply *reply;
@@ -1014,9 +1039,11 @@
             nc_write_clb((void *)&arg, "<", 1, 0);
             nc_write_clb((void *)&arg, rpc_elem->ns->prefix, strlen(rpc_elem->ns->prefix), 0);
             nc_write_clb((void *)&arg, ":rpc-reply", 10, 0);
+            base_prefix = rpc_elem->ns->prefix;
         }
         else {
             nc_write_clb((void *)&arg, "<rpc-reply", 10, 0);
+            base_prefix = NULL;
         }

         /* can be NULL if replying with a malformed-message error */
@@ -1029,7 +1056,12 @@
         }
         switch (reply->type) {
         case NC_RPL_OK:
-            nc_write_clb((void *)&arg, "<ok/>", 5, 0);
+            nc_write_clb((void *)&arg, "<", 1, 0);
+            if (base_prefix) {
+                nc_write_clb((void *)&arg, base_prefix, strlen(base_prefix), 0);
+                nc_write_clb((void *)&arg, ":", 1, 0);
+            }
+            nc_write_clb((void *)&arg, "ok/>", 4, 0);
             break;
         case NC_RPL_DATA:
             assert(((struct nc_server_reply_data *)reply)->data->schema->nodetype == LYS_RPC);
@@ -1054,7 +1086,7 @@
         case NC_RPL_ERROR:
             error_rpl = (struct nc_server_reply_error *)reply;
             for (i = 0; i < error_rpl->count; ++i) {
-                nc_write_error(&arg, error_rpl->err[i]);
+                nc_write_error(&arg, error_rpl->err[i], base_prefix);
             }
             break;
         default:


static analysis fixes 2

static analysis fixes 2

--- src/io.c
+++ src/io.c
@@ -165,7 +165,7 @@
 static struct termios term;
 static volatile sig_atomic_t flag_sigwinch;

-static int io_recv(struct connection*, char*, size_t);
+static void io_recv(struct connection*, char*, size_t);

 static void
 io_close(struct connection *c)
@@ -491,7 +491,6 @@
 	}

 	freeaddrinfo(res);
-	c->soc = soc;

 	return IO_ST_CXED;
 }
@@ -671,7 +670,7 @@
 	return NULL;
 }

-static int
+static void
 io_recv(struct connection *c, char *buf, size_t n)
 {
 	UNUSED(c);
@@ -697,8 +696,6 @@
 		}
 	}
 #endif
-
-	return 0;
 }

 void
@@ -721,6 +718,7 @@
 	struct sigaction sa;

 	sa.sa_handler = sigaction_sigwinch;
+	sa.sa_flags = 0;
 	sigemptyset(&sa.sa_mask);

 	if (sigaction(SIGWINCH, &sa, NULL) < 0)


use C9x types

use C9x types

--- src/ip.c
+++ src/ip.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
  *
- * $Id: ip.c,v 1.21 2002/01/07 01:55:15 dugsong Exp $
+ * $Id: ip.c,v 1.20 2002/01/07 01:54:27 dugsong Exp $
  */

 #include "config.h"
@@ -233,7 +233,7 @@
 	return (len);
 }
 #else /* !HAVE_RAWIP_COOKED */
-size_t
+ssize_t
 ip_send(ip_t *i, const void *buf, size_t len)
 {
 	struct ip_hdr *ip;


2003-11-06  Roland McGrath  <roland@redhat.com>

	* strace.c (tprintf): Check result of vfprintf and use perror when it
	fails while not writing to stderr itself.  Fixes Debian bug #218762.

--- strace.c
+++ strace.c
@@ -2213,8 +2213,14 @@
 	va_list args;

 	VA_START(args, fmt);
-	if (outf)
-		curcol += vfprintf(outf, fmt, args);
+	if (outf) {
+		int n = vfprintf(outf, fmt, args);
+		if (n < 0 && outf != stderr)
+			perror(outfname == NULL
+			       ? "<writing to pipe>" : outfname);
+		else
+			curcol += n;
+	}
 	va_end(args);
 	return;
 }


a FreeBSD fix that actually works

a FreeBSD fix that actually works

--- src/kc.h
+++ src/kc.h
@@ -64,10 +64,8 @@
 extern I vn_ct,vm_ct,vd_ct,vt_ct;
 extern I interrupted;

-#ifdef FreeBSD
-extern _IO_ssize_t getline (char **__restrict __lineptr,
-			    size_t *__restrict __n,
-			    FILE *__restrict __stream) __wur;
+#ifdef __FreeBSD__
+extern ssize_t getline(S *lineptr, size_t *n, FILE *f);
 #endif

 #ifndef WIN32


Apply ABSL_MUST_USE_RESULT annotation to MemoryModifyFunction.

All exising calls now consume the return value.

PiperOrigin-RevId: 485713993
Change-Id: I178a751da42dc38ac2fae2c250409e7185cfc99f

--- tcmalloc/huge_cache.h
+++ tcmalloc/huge_cache.h
@@ -43,8 +43,9 @@
  public:
   explicit MemoryModifyFunction(ReleaseFunction func) : func_(func) {}

-  // TODO(b/122551676): Plumb ABSL_MUST_USE_RESULT here.
-  bool operator()(void* start, size_t len) { return func_(start, len); }
+  ABSL_MUST_USE_RESULT bool operator()(void* start, size_t len) {
+    return func_(start, len);
+  }

  private:
   ReleaseFunction func_;


Fix bug in strlen

Fix bug in strlen

Off by one error.

--- string.c
+++ string.c
@@ -2,7 +2,7 @@

 unsigned int strlen(const char* str) {
     const char* strStart = str;
-    while (*(str++) != '\0') {}
+    while (*(str) != '\0') {++str;}
     return str-strStart;
 }


issue 79: 2 args

issue 79: 2 args

--- src/kn.c
+++ src/kn.c
@@ -28,22 +28,44 @@

 #ifndef WIN32

+C bx[128]={0};
 K read_tape(I i, I type) {   // type in {0,1} -> {select loop, 4: resp reader}
-  I nbytes=0;
-  if(HTTP_PORT){C buf[128]; nbytes=recv(i,buf,128,0);
-    if(nbytes <= 0) {if (nbytes == 0)printf("server: socket %lld hung up\n", i); else perror("recv"); GC; }
+  I nbytes=0,n=0; C by[128]={0};
+  if(HTTP_PORT) {
+    if(bx[0]=='\0')nbytes=recv(i,bx,128,0); else nbytes=recv(i,by,128,0);
+    if(nbytes<=0){if (nbytes==0)printf("server: socket %lld hung up\n", i); else perror("recv"); GC;}
     K h=*denameS(".",".m.h",0);
-    if(6==h->t)send(i,buf,nbytes,0);   //echo back only if .m.h does not exist
+    if(6==h->t){send(i,bx,nbytes,0); bx[0]='\0'; close_tape(i); R (K)0;}  //echo back only if .m.h does not exist
     else {
-      if(7!=h->t && 3!=h->n){
-        I n=snprintf(buf,128,"%s",".m.h is not type 7-3"); if(n>=128)R WE;
-        send(i,buf,strlen(buf),0);}
-      else {
-        I n; for(n=0;n<128;n++){if(buf[n]=='\r')break;} buf[n]='\0';
-        S x=kC(kK(h)[CODE]); I sb=strlen(buf),sx=strlen(x);
-        C c[7+sb+sx]; c[0]='{'; c[1+sx]='}'; c[2+sx]='['; c[5+sx+sb]=']';
-        c[3+sx]='"'; c[4+sx+sb]='"'; c[6+sx+sb]='\0';
-        DO(sx,c[1+i]=x[i])  DO(sb,c[4+sx+i]=buf[i])
+      if(7!=h->t && 3!=h->n) {
+        I n=snprintf(bx,128,"%s",".m.h is not type 7-3"); if(n>=128)R WE;
+        send(i,bx,strlen(bx),0); }
+      else {   //have .m.h of type 7-3
+        S f=kC(kK(h)[CODE]); I ax=0,ay=0,sf=strlen(f);
+        DO(sf, if(f[i]=='x')ax=1; else if(f[i]=='y')ay=1;) I na=maX(1,ax+ay);
+        if(na==2) {
+          if(by[0]=='\0'){ C bn[1]; bn[0]='\0'; send(i,bn,1,0); close_tape(i); R (K)0; }
+          else {
+            for(n=0;n<128;++n){if(bx[n]=='\r')break;} bx[n]='\0';
+            for(n=0;n<128;++n){if(by[n]=='\r')break;} by[n]='\0';
+            I sbx=strlen(bx); I sby=strlen(by);
+            C c[10+sf+sbx+sby]; c[0]='{'; c[1+sf]='}'; c[2+sf]='['; c[8+sf+sbx+sby]=']';
+            c[3+sf]=c[4+sf+sbx]=c[6+sf+sbx]=c[7+sf+sbx+sby]='"';
+            c[5+sf+sbx]=';'; c[9+sf+sbx+sby]='\0';
+            DO(sf,c[1+i]=f[i])  DO(sbx,c[4+sf+i]=bx[i]) DO(sby,c[7+sf+sbx+i]=by[i])
+            K r=X(c); I w=128; C bck[w];
+            switch(r->t) {
+              CS(1, {n=snprintf(bck,w,"%lld",*kI(r)); if(n>=w){bck[w-4]=bck[w-3]=bck[w-2]='.';}})
+              CS(2, {n=snprintf(bck,w,"%f",*kF(r)); if(n>=w){bck[w-4]=bck[w-3]=bck[w-2]='.';}})
+              CS(3, {n=snprintf(bck,w,"%s",kC(r)); if(n>=w){bck[w-4]=bck[w-3]=bck[w-2]='.';}})
+              CS(-3,{n=snprintf(bck,w,"%s",kC(r)); if(n>=w){bck[w-4]=bck[w-3]=bck[w-2]='.';}})
+              default:{n=snprintf(bck,w,"%s","NYI: .m.h result of that type and count"); if(n>=w)R WE;} }
+            send(i,bck,strlen(bck),0); bx[0]='\0'; close_tape(i); R (K)0; } }
+        for(n=0;n<128;n++){if(bx[n]=='\r' || bx[n]=='\0')break;}
+        bx[n]='\0'; I sbx=strlen(bx);
+        C c[7+sf+sbx]; c[0]='{'; c[1+sf]='}'; c[2+sf]='['; c[5+sf+sbx]=']';
+        c[3+sf]=c[4+sf+sbx]='"'; c[6+sf+sbx]='\0';
+        DO(sf,c[1+i]=f[i])  DO(sbx,c[4+sf+i]=bx[i])
         K r=X(c); I w=128; C bck[w];
         switch(r->t){
           CS(1, {n=snprintf(bck,w,"%lld",*kI(r)); if(n>=w){bck[w-4]=bck[w-3]=bck[w-2]='.';}})
@@ -51,8 +73,7 @@
           CS(3, {n=snprintf(bck,w,"%s",kC(r)); if(n>=w){bck[w-4]=bck[w-3]=bck[w-2]='.';}})
           CS(-3,{n=snprintf(bck,w,"%s",kC(r)); if(n>=w){bck[w-4]=bck[w-3]=bck[w-2]='.';}})
           default:{n=snprintf(bck,w,"%s","NYI: .m.h result of that type and count"); if(n>=w)R WE;} }
-        send(i,bck,strlen(bck),0); } }
-    close_tape(i); R (K)0; }
+        send(i,bck,strlen(bck),0); bx[0]='\0'; close_tape(i); R (K)0; } } }
   I c=CP[i].r, m=sizeof(M1),g; K z=0;
   S b = c<m?c+(S)&CP[i].m1:c+kC(CP[i].k);
   g = c<m?m-c:CP[i].m1.n;


partial fix for #397: original script works

--- src/kx.c
+++ src/kx.c
@@ -1029,9 +1029,9 @@

   u=*v; //Fixes a bug, see above. Not thread-safe. Adding to LOCALS probably better
   *v=VA(t3)?t3:(V)&t3;
-  if(*(v+i)==(V)offsetEach){if(grnt)cd(grnt); grnt=ci(prnt);}
+  if(*(v+i)==(V)offsetEach && (!grnt || prnt==grnt)){if(grnt)cd(grnt); grnt=ci(prnt);}
   e=dv_ex(0,v+i,t2); *v=u;
-  if(*(v+i)==(V)offsetEach){if(grnt)cd(grnt); grnt=0;}
+  if(*(v+i)==(V)offsetEach && prnt==grnt){if(grnt)cd(grnt); grnt=0;}
   cd(t2); if(!VA(t3) && (encp!=3 || (encp==3 && kV(t3)[CACHE_WD])))cd(t3);
     //the encp conditions address the 2 variations of issue #247, neither of which work in k2.8 or k3.2
   R e;


Declare variables where they are used.

Declare variables where they are used.

--- src/mp.c
+++ src/mp.c
@@ -65,17 +65,17 @@
 mp_digit
 mp_add_n(const mp_digit *u, const mp_digit *v, mp_size size, mp_digit *w)
 {
-	mp_digit cy, ud, vd;
-
-	ASSERT(u != NULL);
-	ASSERT(v != NULL);
-	ASSERT(w != NULL);
-
-	for (cy = 0; size--; ++w) {
-		ud = *u++;
-		vd = *v++;
+	ASSERT(u);
+	ASSERT(v);
+	ASSERT(w);
+
+	mp_digit cy = 0;
+	while (size--) {
+		mp_digit ud = *u++;
+		const mp_digit vd = *v++;
 		cy  = (ud += cy) < cy;
 		cy += (*w = ud + vd) < vd;
+		++w;
 	}
 	return cy;
 }
@@ -85,8 +85,6 @@
 mp_add(const mp_digit *u, mp_size usize,
 	   const mp_digit *v, mp_size vsize, mp_digit *w)
 {
-	mp_digit cy;
-
 	ASSERT(u);
 	ASSERT(usize > 0);
 	ASSERT(u[usize - 1]);
@@ -95,13 +93,13 @@
 	ASSERT(v[vsize - 1]);

 	if (usize < vsize) {
-		cy = mp_add_n(u, v, usize, w);
+		mp_digit cy = mp_add_n(u, v, usize, w);
 		if (v != w) {
 			mp_copy(v + usize, vsize - usize, w + usize);
 		}
 		return cy ? mp_inc(w + usize, vsize - usize) : 0;
 	} else if (usize > vsize) {
-		cy = mp_add_n(u, v, vsize, w);
+		mp_digit cy = mp_add_n(u, v, vsize, w);
 		if (u != w) {
 			mp_copy(u + vsize, usize - vsize, w + vsize);
 		}
@@ -115,13 +113,11 @@
 mp_digit
 mp_addi(mp_digit *u, mp_size usize, const mp_digit *v, mp_size vsize)
 {
-	mp_digit cy;
-
 	ASSERT(u != NULL);
 	ASSERT(v != NULL);
 	ASSERT(usize >= vsize);

-	cy = mp_addi_n(u, v, vsize);
+	mp_digit cy = mp_addi_n(u, v, vsize);
 	return cy ? mp_inc(u + vsize, usize - vsize) : 0;
 }

@@ -135,12 +131,10 @@
 mp_digit
 mp_dsubi(mp_digit *u, mp_size size, mp_digit v)
 {
-	mp_digit u0;
-
 	if (v == 0 || size == 0)
 		return v;
-	u0 = u[0];
-	return ((u[0] -= v) > u0) ? mp_dec(&u[1], size - 1) : 0;
+	const mp_digit u0 = u[0];
+	return ((u[0] -= v) > u0) ? mp_dec(u + 1, size - 1) : 0;
 }

 /* Set w[size] = u[size] - v[size] and return the borrow. */
@@ -148,17 +142,17 @@
 mp_digit
 mp_sub_n(const mp_digit *u, const mp_digit *v, mp_size size, mp_digit *w)
 {
-	mp_digit ud, vd, cy;
-
 	ASSERT(u != NULL);
 	ASSERT(v != NULL);
 	ASSERT(w != NULL);

-	for (cy = 0; size--; ++w) {
-		ud = *u++;
-		vd = *v++;
+	mp_digit cy = 0;
+	while (size--) {
+		const mp_digit ud = *u++;
+		mp_digit vd = *v++;
 		cy  = (vd += cy) < cy;
 		cy += (*w = ud - vd) > ud;
+		++w;
 	}
 	return cy;
 }
@@ -187,16 +181,16 @@
 mp_digit
 mp_subi_n(mp_digit *u, const mp_digit *v, mp_size size)
 {
-	mp_digit ud, vd, cy;
-
 	ASSERT(u != NULL);
 	ASSERT(v != NULL);

-	for (cy = 0; size--; ++u) {
-		vd = *v++;
-		ud = *u;
+	mp_digit cy = 0;
+	while (size--) {
+		mp_digit vd = *v++;
+		const mp_digit ud = *u;
 		cy  = (vd += cy) < cy;
 		cy += (*u -= vd) > ud;
+		++u;
 	}
 	return cy;
 }
@@ -237,8 +231,6 @@
 mp_digit
 mp_dmul(const mp_digit *u, mp_size size, mp_digit v, mp_digit *w)
 {
-	mp_digit cy, p0, p1;
-
 	if (v <= 1) {
 		if (v == 0)
 			mp_zero(w, size);
@@ -247,10 +239,13 @@
 		return 0;
 	}

-	for (cy = 0; size--; ++u, ++w) {
+	mp_digit cy = 0;
+	while (size--) {
+		mp_digit p1, p0;
 		digit_mul(*u, v, p1, p0);
 		cy = ((p0 += cy) < cy) + p1;
-		*w = p0;
+		*w++ = p0;
+		++u;
 	}
 	return cy;
 }
@@ -260,18 +255,18 @@
 mp_digit
 mp_dmuli(mp_digit *u, mp_size size, mp_digit v)
 {
-	mp_digit cy, p0, p1;
-
 	if (v <= 1) {
 		if (v == 0)
 			mp_zero(u, size);
 		return 0;
 	}

-	for (cy = 0; size--; ++u) {
+	mp_digit cy = 0;
+	while (size--) {
+		mp_digit p1, p0;
 		digit_mul(*u, v, p1, p0);
 		cy = ((p0 += cy) < cy) + p1;
-		*u = p0;
+		*u++ = p0;
 	}
 	return cy;
 }
@@ -281,18 +276,19 @@
 mp_digit
 mp_dmul_add(const mp_digit *u, mp_size size, mp_digit v, mp_digit *w)
 {
-	mp_digit cy, p0, p1;
-
-	ASSERT(u != NULL);
-	ASSERT(w != NULL);
+	ASSERT(u);
+	ASSERT(w);

 	if (v <= 1)
 		return v ? mp_addi_n(w, u, size) : 0;

-	for (cy = 0; size--; ++u, ++w) {
+	mp_digit cy = 0;
+	while (size--) {
+		mp_digit p1, p0;
 		digit_mul(*u, v, p1, p0);
 		cy  = ((p0 += cy) < cy) + p1;
 		cy += ((*w += p0) < p0);
+		++u; ++w;
 	}
 	return cy;
 }
@@ -324,21 +320,16 @@
 void
 mp_exp(const mp_digit *u, mp_size size, unsigned long exp, mp_digit *v)
 {
-	int odd;
-	unsigned long n;
-	mp_digit *y, *z;
-	mp_size ysize, zsize;
-
 	/* Knuth's algorithm 4.6.3-A.
 	 * Perform binary powering, making use of the basic identity
 	 *      2i     2 i
 	 *     u   = (u )
-	 * to exponentiate a number faster than the naive method.  While the
+	 * to exponentiate a number faster than the naive method. While the
 	 * exponent is greater than one, we square the intermediate result (which
-	 * began at base).  If the exponent is odd, we multiply by the base.  Then
+	 * began at base). If the exponent is odd, we multiply by the base. Then
 	 * we halve the exponent and repeat the process. */
 	mp_zero(v, size * exp);
-	/* Strictly speaking, 0^0 is undefined, but we return 0 here. */
+	/* 0^0 is not clearly defined, but we return 0 here. */
 	if (size == 0)
 		return;
 	if (exp == 0) {
@@ -351,26 +342,27 @@
 	}

 	/* A1. */
-	n = exp;
+	mp_digit *y;
 	MP_TMP_ALLOC(y, size * exp);
 	y[0] = 1;
-	ysize = 1;
-
+	mp_size ysize = 1;
+
+	mp_digit *z;
 	MP_TMP_ALLOC0(z, size * exp);
 	mp_copy(u, size, z);
-	zsize = size;
+	mp_size zsize = size;

 	for (;;) {
 		/* A2. */
-		odd = n & 1;
-		n >>= 1;
+		const bool odd = exp & 1;
+		exp >>= 1;
 		if (odd) {
 			/* A3. */
 			mp_mul(y, ysize, z, zsize, v);
 			ysize = mp_rsize(v, ysize + zsize);
 			mp_copy(v, ysize, y);
 			/* A4. */
-			if (n == 0) {
+			if (exp == 0) {
 				mp_copy(y, ysize, v);
 				MP_TMP_FREE(y);
 				MP_TMP_FREE(z);
@@ -384,97 +376,89 @@
 	}
 }

-/* Multiply u[size] by 2^power and store in v[size], returning carry.
- * Power will be taken modulo MP_DIGIT_BITS. */
-mp_digit
-mp_lshift(const mp_digit *u, mp_size size, unsigned power, mp_digit *v)
-{
-	unsigned subp;
-	mp_digit p, q;
-
-	if (size == 0)
-		return 0;
-	if ((power &= (MP_DIGIT_BITS - 1)) == 0) {
+/* Multiply u[size] by 2^shift and store in v[size], returning carry.
+ * shift will be taken modulo MP_DIGIT_BITS. */
+mp_digit
+mp_lshift(const mp_digit *u, mp_size size, unsigned shift, mp_digit *v)
+{
+	if (!size)
+		return 0;
+	shift &= MP_DIGIT_BITS - 1;
+	if (!shift) {
 		if (u != v)
 			mp_copy(u, size, v);
 		return 0;
 	}
-	q = 0;
-	subp = MP_DIGIT_BITS - power;
+	const unsigned subp = MP_DIGIT_BITS - shift;
+	mp_digit q = 0;
 	do {
-		p = *u++;
-		*v++ = (p << power) | q;
+		const mp_digit p = *u++;
+		*v++ = (p << shift) | q;
 		q = p >> subp;
 	} while (--size);
 	return q;
 }

-/* Divide u[size] by 2^power. */
-mp_digit
-mp_rshift(const mp_digit *u, mp_size size, unsigned power, mp_digit *v)
-{
-	unsigned subp;
-	mp_digit p, q;
-
-	if (size == 0)
-		return 0;
-	if ((power &= (MP_DIGIT_BITS - 1)) == 0) {
+/* Divide u[size] by 2^shift. */
+mp_digit
+mp_rshift(const mp_digit *u, mp_size size, unsigned shift, mp_digit *v)
+{
+	if (size == 0)
+		return 0;
+	shift &= MP_DIGIT_BITS - 1;
+	if (!shift) {
 		if (u != v)
 			mp_copy(u, size, v);
 		return 0;
 	}

-	subp = MP_DIGIT_BITS - power;
+	const unsigned subp = MP_DIGIT_BITS - shift;
 	u += size;
 	v += size;
-	q = 0;
+	mp_digit q = 0;
 	do {
-		p = *--u;
-		*--v = (p >> power) | q;
+		const mp_digit p = *--u;
+		*--v = (p >> shift) | q;
 		q = p << subp;
 	} while (--size);
 	return q >> subp;
 }

-/* Multiply u[size] by 2^power, power taken modulo MP_DIGIT_BITS. */
+/* Multiply u[size] by 2^shift, shift taken modulo MP_DIGIT_BITS. */
 #ifndef MP_LSHIFTI_ASM
 mp_digit
-mp_lshifti(mp_digit *u, mp_size size, unsigned power)
-{
-	unsigned subp;
-	mp_digit p, q;
-
-	if (size == 0 || (power &= (MP_DIGIT_BITS - 1)) == 0)
-		return 0;
-
-	subp = MP_DIGIT_BITS - power;
-	q = 0;
+mp_lshifti(mp_digit *u, mp_size size, unsigned shift)
+{
+	shift &= MP_DIGIT_BITS - 1;
+	if (!size || !shift)
+		return 0;
+
+	const unsigned subp = MP_DIGIT_BITS - shift;
+	mp_digit q = 0;
 	do {
-		p = *u;
-		*u++ = (p << power) | q;
+		const mp_digit p = *u;
+		*u++ = (p << shift) | q;
 		q = p >> subp;
 	} while (--size);
 	return q;
 }
 #endif /* !MP_LSHIFTI_ASM */

-/* Divide u[size] by 2^power, power taken modulo MP_DIGIT_BITS. */
+/* Divide u[size] by 2^shift, shift taken modulo MP_DIGIT_BITS. */
 #ifndef MP_RSHIFTI_ASM
 mp_digit
-mp_rshifti(mp_digit *u, mp_size size, unsigned power)
-{
-	unsigned subp;
-	mp_digit p, q;
-
-	if (size == 0 || (power &= (MP_DIGIT_BITS - 1)) == 0)
-		return 0;
-
-	subp = MP_DIGIT_BITS - power;
+mp_rshifti(mp_digit *u, mp_size size, unsigned shift)
+{
+	shift &= MP_DIGIT_BITS - 1;
+	if (!size || !shift)
+		return 0;
+
+	unsigned subp = MP_DIGIT_BITS - shift;
 	u += size;
-	q = 0;
+	mp_digit q = 0;
 	do {
-		p = *--u;
-		*u = (p >> power) | q;
+		const mp_digit p = *--u;
+		*u = (p >> shift) | q;
 		q = p << subp;
 	} while (--size);
 	return q >> subp;
@@ -511,14 +495,13 @@
 		return 0;

 	if ((v & (v - 1)) == 0) {
-		return mp_rshifti(u, size, mp_digit_log2(v));
+		return mp_rshifti(u, size, mp_digit_lsb_shift(v));
 	} else {
-		mp_digit q, r, s0, s1;
-
-		s1 = 0;
+		mp_digit s1 = 0;
 		u += size;
 		do {
-			s0 = *--u;
+			mp_digit s0 = *--u;
+			mp_digit q, r;
 			if (s1 == 0) {
 				q = s0 / v;
 				r = s0 % v;
@@ -547,16 +530,15 @@
 	if ((v & (v - 1)) == 0) {
 		return u[0] & (v - 1);
 	} else {
-		mp_digit q, r, s0, s1;
-
-		s1 = 0;
+		mp_digit s1 = 0;
 		u += size;
 		do {
-			s0 = *--u;
+			mp_digit s0 = *--u;
+			mp_digit r;
 			if (s1 == 0) {
-				q = s0 / v;
 				r = s0 % v;
 			} else {
+				mp_digit q;
 				digit_div(s1, s0, v, q, r);
 			}
 			s1 = r;
@@ -601,13 +583,11 @@
 		sum += mp_byte_pop[*u++];
 	} while (--size);
 #else
-	mp_digit q;
-
 	MP_NORMALIZE(u, size);
 	if (size == 0)
 		return 0;
 	do {
-		for (q = *u++; q != 0; q >>= 8)
+		for (mp_digit q = *u++; q != 0; q >>= 8)
 			sum += mp_byte_pop[q & 0xff];
 	} while (--size);
 #endif
@@ -624,10 +604,8 @@
 	while (size--)
 		hdist += mp_byte_pop[u[size] ^ v[size]];
 #else
-	mp_digit k;
-
 	while (size--)
-		for (k = u[size] ^ v[size]; k != 0; k >>= 8)
+		for (mp_digit k = u[size] ^ v[size]; k != 0; k >>= 8)
 			hdist += mp_byte_pop[k & 0xff];
 #endif
 	return hdist;


- remove unneccessary semicolon

- remove unneccessary semicolon

--- src/o1.h
+++ src/o1.h
@@ -32,7 +32,7 @@
     void setRequestTokenUrl(const QUrl &value);

     /// Parameters to pass with request URL.
-    Q_PROPERTY(QList<O0RequestParameter> requestParameters READ requestParameters WRITE setRequestParameters);
+    Q_PROPERTY(QList<O0RequestParameter> requestParameters READ requestParameters WRITE setRequestParameters)
     QList<O0RequestParameter> requestParameters();
     void setRequestParameters(const QList<O0RequestParameter> &value);


remove comment for rejected ticket.

remove comment for rejected ticket.

git-svn-id: 6e74a02f85675cec270f5d931b0f6998666294a3@42220 d31e2699-5ff4-0310-a27c-f18f2fbe73fe

--- src/oo.c
+++ src/oo.c
@@ -878,14 +878,6 @@
         invalidate_type_caches(interp, (UINTVAL)type);
 }

-
-/*
- * quick'n'dirty method cache
- * RT #45987: use a hash if method_name is not constant
- *       i.e. from obj.$Sreg(args)
- *       If this hash is implemented mark it during GC
- */
-
 /*

 =item C<PMC * Parrot_find_method_direct(PARROT_INTERP, PMC *_class, STRING


Refresh the screen on close

Refresh the screen on close

This fixes an issue where, after running pick through vim, after you
exited vim the terminal would not be cleared.

--- src/ui.c
+++ src/ui.c
@@ -54,8 +54,8 @@
 void
 stop_curses()
 {
-
 	endwin();
+	refresh();
 	fflush(stdout);
 	dup2(stdoutfd, STDOUT_FILENO);
 	close(stdoutfd);


Add the G_GNUC_NULL_TERMINATED annotation to tp_asv_new()

--- telepathy-glib/dbus.h
+++ telepathy-glib/dbus.h
@@ -104,7 +104,7 @@
   return g_hash_table_size /* */ ((GHashTable *) asv);
 }

-GHashTable *tp_asv_new (const gchar *first_key, ...);
+GHashTable *tp_asv_new (const gchar *first_key, ...) G_GNUC_NULL_TERMINATED;
 gboolean tp_asv_get_boolean (const GHashTable *asv, const gchar *key,
     gboolean *valid);
 void tp_asv_set_boolean (GHashTable *asv, const gchar *key, gboolean value);


Add buffer name in Bufact

Add buffer name in Bufact

--- src/ui.c
+++ src/ui.c
@@ -26,7 +26,7 @@
 #define COLOR_HL     (ui_color(COLOR_YELLOW, hftirc->ui->bg) | A_BOLD)
 #define COLOR_WROTE  (ui_color(COLOR_CYAN, hftirc->ui->bg))
 #define COLOR_ACT    (ui_color(COLOR_WHITE,  COLOR_THEME) | A_UNDERLINE)
-#define COLOR_HLACT  (ui_color(COLOR_YELLOW, COLOR_THEME) | A_BOLD | A_UNDERLINE)
+#define COLOR_HLACT  (ui_color(COLOR_RED, COLOR_THEME) | A_BOLD | A_UNDERLINE)

 void
 ui_init(void)
@@ -174,6 +174,8 @@
                wattron(hftirc->ui->statuswin,
                          ((hftirc->cb[i].act == 2) ? COLOR_HLACT : COLOR_ACT));
                wprintw(hftirc->ui->statuswin, "%d", i);
+               wattroff(hftirc->ui->statuswin, A_UNDERLINE);
+               wprintw(hftirc->ui->statuswin, ":%s", hftirc->cb[i].name);
                wattroff(hftirc->ui->statuswin,
                          ((hftirc->cb[i].act == 2) ? COLOR_HLACT : COLOR_ACT));
                waddch(hftirc->ui->statuswin, ' ');


dbus.h: include _gen/genums.h, for TP_TYPE_DBUS_ERROR

--- telepathy-glib/dbus.h
+++ telepathy-glib/dbus.h
@@ -25,6 +25,8 @@

 #include <telepathy-glib/defs.h>
 #include <telepathy-glib/dbus-daemon.h>
+
+#include <telepathy-glib/_gen/genums.h>

 G_BEGIN_DECLS


hash size reduced

hash size reduced

--- src/vg.c
+++ src/vg.c
@@ -95,7 +95,7 @@
   R y;
 }

-#define HFR 2
+#define HFR 1
 Z K newH(I n){ I m=1<<(HFR+cl2(n));K h=newK(-1,m);M(h);R h; }
 Z I hg(K h,uI hk,I k,uI*p)
 {


Fix a bug with *rest args

Fix a bug with *rest args

--- src/vm.c
+++ src/vm.c
@@ -519,7 +519,6 @@
                 NOGC(extra);

                 for (int i = irest; i < argc; ++i) {
-                        if (i == ikwargs) continue;
                         value_array_push(extra, stack.items[fp + i]);
                         stack.items[fp + i] = NIL;
                 }


First implementation

First implementation

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

--- stable_vector.h
+++ stable_vector.h
@@ -0,0 +1,158 @@
+#pragma once
+
+#include <vector>
+#include <array>
+#include <memory>
+#include <iterator>
+
+#include <boost/operators.hpp>
+#include <boost/container/static_vector.hpp>
+
+template <typename _T, std::size_t _ElementsPerChunk = 512>
+struct stable_vector
+{
+	typedef _T          value_type;
+	typedef _T&         reference;
+	typedef const _T&   const_reference;
+	typedef std::size_t size_type;
+	typedef size_type   difference_type;
+
+private:
+	typedef boost::container::static_vector<_T, _ElementsPerChunk> chunk_type;
+	typedef std::vector<std::unique_ptr<chunk_type>> storage_type;
+
+	typedef stable_vector<_T, _ElementsPerChunk> container;
+
+	template <typename _Iter>
+	struct iterator_base
+	{
+		iterator_base(container* c = nullptr, size_type i = 0) :
+			m_container(c),
+			m_index(i) {}
+
+		reference operator*() { return (*m_container)[m_index]; }
+		iterator_base operator+(size_type i) { return {m_container, m_index + i}; }
+
+		iterator_base& operator+=(size_type i) { m_index += i; return *this; }
+		iterator_base& operator++() { ++m_index; return *this; }
+
+		iterator_base& operator-=(size_type i) { m_index -= i; return *this; }
+		iterator_base& operator--() { --m_index; return *this; }
+
+		size_type operator-(iterator_base it) { return m_index - it.m_index; }
+
+		bool operator<(iterator_base it) const  { return m_index < it.m_index; }
+		bool operator==(iterator_base it) const { return m_container == it.m_container && m_index == it.m_index; }
+
+	protected:
+		container* m_container = nullptr;
+		size_type  m_index;
+	};
+
+public:
+	struct const_iterator;
+
+	struct iterator :
+		public iterator_base<iterator>,
+		public boost::random_access_iterator_helper<iterator, value_type>
+	{
+		using iterator_base<iterator>::iterator_base;
+		friend struct const_iterator;
+	};
+
+	struct const_iterator :
+		public iterator_base<const_iterator>,
+		public boost::random_access_iterator_helper<const_iterator, const value_type>
+	{
+		using iterator_base<const_iterator>::iterator_base;
+
+		const_iterator(const iterator& it) :
+			iterator_base<const_iterator>(it.m_container, it.m_index)
+		{}
+	};
+
+	iterator begin() { return {this, 0}; }
+	iterator end()   { return {this, size() - 1}; }
+
+	const_iterator cbegin() const { return const_cast<container&>(*this).begin(); }
+	const_iterator cend()   const { return const_cast<container&>(*this).end(); }
+
+	size_type size()     const
+	{
+		return std::accumulate(m_chunks.cbegin(),
+							   m_chunks.cend(),
+							   0,
+							   [](size_type s, auto& chunk_ptr) { return s + chunk_ptr->size(); });
+	}
+	size_type max_size() const { return std::numeric_limits<size_type>::max(); }
+	bool      empty()    const { return m_chunks.empty(); }
+
+	bool operator==(const container& c) const { return std::equal(cbegin(), cend(), c.cbegin(), c.cend()); }
+	bool operator!=(const container& c) const { return !operator==(c); }
+
+	void swap(container& c)
+	{
+		std::swap(m_chunks, c.m_chunks);
+		std::swap(m_size, c.m_size);
+	}
+
+	friend void swap(container& l, container& r)
+	{
+		l.swap(r);
+	}
+
+	reference front() { return m_chunks.front()->front(); }
+	const_reference front() const { return front(); }
+
+	reference back() { return m_chunks.back()->back(); }
+	const_reference back() const { return back(); }
+
+private:
+	chunk_type& current_chunk()
+	{
+		if (m_chunks.empty() || m_chunks.back()->size() == _ElementsPerChunk)
+			m_chunks.emplace_back();
+
+		return *m_chunks.back();
+	}
+
+public:
+	void push_back(_T&& t)
+	{
+		chunk_type& chunk = current_chunk();
+		chunk.push_back(std::move(t));
+	}
+
+	template<typename... _Args>
+	void emplace_back(_Args&&... args)
+	{
+		chunk_type& chunk = current_chunk();
+		::new((void *)&(chunk[chunk.size()])) _T(std::forward<_Args>(args)...);
+	}
+
+	reference operator[](size_type i)
+	{
+		size_type chunk_idx = i / _ElementsPerChunk;
+		chunk_type& chunk = m_chunks[chunk_idx];
+		return chunk[i - chunk_idx * _ElementsPerChunk];
+	}
+
+	const_reference operator[](size_type i) const { return operator[](i); }
+
+	reference at(size_type i)
+	{
+		if (i >= m_size)
+			throw std::out_of_range("stable_vector::at");
+
+		size_type chunk_idx = i / _ElementsPerChunk;
+		chunk_type& chunk = m_chunks[chunk_idx];
+		return chunk[i - chunk_idx * _ElementsPerChunk];
+	}
+
+	const_reference at(size_type i) const { return at(i); }
+
+private:
+	storage_type m_chunks;
+	size_type    m_size = 0;
+};
+


* Implemented Cheney copy garbage collector

--- src/vm.c
+++ src/vm.c
@@ -270,10 +270,18 @@

 /*
  * this callback is called by the garbage collector
- * to get all the heap roots. It must return NULL
+ * to get all the mutator roots. It must return NULL
  * when there are no more roots to scan
  */
 typedef duna_Object* (*duna_Roots_Callback)(void*);
+
+/* forward reference to object in to-space */
+typedef struct duna_Forward_Ref_ duna_Forward_Ref;
+
+struct duna_Forward_Ref_ {
+  DUNA_GC_BASE;
+  duna_GCObject *ref;
+};

 typedef struct duna_Store_ duna_Store;

@@ -328,54 +336,61 @@
   S->roots_cb = S->roots_cb_data = NULL;
 }

+static uint32_t sizeof_gcobj(duna_GCObject* obj)
+{
+  uint32_t size;
+
+  switch(obj->type) {
+  case DUNA_TYPE_CLOSURE:
+    size = ((duna_Closure*)obj)->nr_free;
+    size = sizeof(duna_Closure) +
+           (size == 0 ? 0 : size - 1) * sizeof(duna_Object);
+    break;
+
+  case DUNA_TYPE_PAIR:
+    size = sizeof(duna_Pair);
+    break;
+
+  case DUNA_TYPE_CONTINUATION:
+    size = sizeof(duna_Continuation) +
+           (((duna_Continuation*)obj)->size-1) * sizeof(duna_Object);
+    break;
+
+  case DUNA_TYPE_BOX:
+    size = sizeof(duna_Box);
+    break;
+  default:
+    size = 0;
+  };
+
+  return size;
+}
+
 static void copy_object(duna_Store* S, duna_Object* obj)
 {
   void *to;
   uint32_t size;

-  /*
-   * when an object is copied the forwarding
-   * pointer is put inside a Box, which is
-   * the smallest object and therefore always
-   * fits
-   */
+  if(DUNA_IMMEDIATE_P(obj)) {
+    /* if not heap-allocated, bail */
+    return;
+  }

   if(obj->value.gc->type == DUNA_FORWARD_TAG) {
     /* already copied, just update pointer */
-    obj->value.gc = ((duna_Box*)obj->value.gc)->value.value.gc;
+    obj->value.gc = ((duna_Forward_Ref*)obj->value.gc)->ref;
     return;
   }

+  /* copying */
   to = S->to_space + S->size;
-  switch(obj->type) {
-  case DUNA_TYPE_CLOSURE:
-    size = ((duna_Closure*)obj->value.gc)->nr_free;
-    size = sizeof(duna_Closure) + (size == 0 ? 0 : size - 1) * sizeof(duna_Object);
-    memcpy(to, obj->value.gc, size);
-    S->size += size;
-    break;
-
-  case DUNA_TYPE_PAIR:
-    memcpy(to, obj->value.gc, sizeof(duna_Pair));
-    S->size += sizeof(duna_Pair);
-    break;
-
-  case DUNA_TYPE_CONTINUATION:
-    size = sizeof(duna_Continuation) +
-           (((duna_Continuation*)obj->value.gc)->size-1) * sizeof(duna_Object);
-    memcpy(to, obj->value.gc, size);
-    S->size += size;
-    break;
-
-  case DUNA_TYPE_BOX:
-    memcpy(to, obj->value.gc, sizeof(duna_Box));
-    S->size += sizeof(duna_Box);
-    break;
-  };
+  size = sizeof_gcobj(obj->value.gc);
+  memcpy(to, obj->value.gc, size);
+  S->size += size;

   /* leave a forwarding pointer and update */
   obj->value.gc->type = DUNA_FORWARD_TAG;
-  ((duna_Box*)obj->value.gc)->value.value.gc = to;
+  ((duna_Forward_Ref*)obj->value.gc)->ref = to;
   obj->value.gc = to;
 }

@@ -387,28 +402,61 @@
    */
   void *scan;
   duna_Object *obj;
-
-  fprintf(stderr, "Doing GC!\n");
+  uint32_t old_size;

   if(!S->roots_cb) {
     return;
   }

+  old_size = S->size;
+  S->size = 0;
+
   /* copying roots */
-  S->size = 0;
   while((obj = S->roots_cb(S->roots_cb_data))) {
-    if(!DUNA_IMMEDIATE_P(obj)) {
-      copy_object(S, obj);
-    }
+    copy_object(S, obj);
   }

   /* now scan to-space */
   scan = S->to_space;
-
-  /* exchange spaces */
+  while(scan < S->to_space + S->size) {
+    uint32_t i, size;
+    duna_GCObject *gcobj;
+
+    gcobj = scan;
+    size = sizeof_gcobj(gcobj);
+
+    switch(gcobj->type) {
+    case DUNA_TYPE_CLOSURE:
+      for(i = 0; i < ((duna_Closure*)gcobj)->nr_free; i++) {
+	copy_object(S, &(((duna_Closure*)gcobj)->free_vars[i]));
+      }
+      break;
+
+    case DUNA_TYPE_PAIR:
+      copy_object(S, &((duna_Pair*)gcobj)->car);
+      copy_object(S, &((duna_Pair*)gcobj)->car);
+      break;
+
+    case DUNA_TYPE_CONTINUATION:
+      for(i = 0; i < ((duna_Continuation*)gcobj)->size; i++) {
+	copy_object(S, &(((duna_Continuation*)gcobj)->stack[i]));
+      }
+      break;
+
+    case DUNA_TYPE_BOX:
+      copy_object(S, &((duna_Box*)gcobj)->value);
+      break;
+    };
+
+    scan += size;
+  }
+
+  /* swap spaces */
   scan = S->from_space;
   S->from_space = S->to_space;
   S->to_space = scan;
+
+  printf("GC: before: %u after: %u\n", old_size, S->size);
 }

 static int expand_store(duna_Store* S)
@@ -561,6 +609,51 @@
   duna_Object proc;
 };

+/* garbage collector callback */
+
+struct gc_data {
+  duna_State *D;
+  uint32_t state, count;
+};
+
+static struct gc_data gc_data;
+
+static duna_Object* gc_callback(void *ud)
+{
+  duna_Object *obj;
+  struct gc_data *gc_data;
+
+  gc_data = (struct gc_data*) ud;
+
+  if(gc_data->state == 0) {
+    /* stack */
+    obj = &gc_data->D->stack[gc_data->count++];
+    if(gc_data->count == gc_data->D->sp) {
+      gc_data->state++;
+      gc_data->count = 0;
+    }
+  } else if(gc_data->state == 1) {
+    /* registers */
+    if(gc_data->count == 0) {
+      obj = &gc_data->D->accum;
+      gc_data->count++;
+    } else if(gc_data->count == 1) {
+      obj = &gc_data->D->proc;
+      gc_data->count++;
+    } else {
+      gc_data->state = 0;
+      gc_data->count = 0;
+      obj = NULL;
+    }
+  } else {
+    gc_data->state = 0;
+    gc_data->count = 0;
+    obj = NULL;
+  }
+
+  return obj;
+}
+
 duna_State* duna_init(void)
 {
   duna_State *D = NULL;
@@ -571,7 +664,10 @@
   }

   /* store */
-  if(init_store(&D->store, NULL, NULL) == 0) {
+  gc_data.D = D;
+  gc_data.state = 0;
+  gc_data.count = 0;
+  if(init_store(&D->store, gc_callback, &gc_data) == 0) {
     return NULL;
   }

@@ -791,7 +887,7 @@
     duna_Object tmp;

     /* debugging */
-    /*duna_dump(D);*/
+    duna_dump(D);
     assert(D->pc < D->code_size);

     instr = D->code[D->pc++];
@@ -915,9 +1011,10 @@
       /* number of free variables */
       dw1 = EXTRACT_ARG(instr);

-      D->accum.type = DUNA_TYPE_CLOSURE;
-      D->accum.value.gc = (duna_GCObject*) alloc_closure(&D->store, dw1);
-      check_alloc(D, D->accum.value.gc);
+      tmp.type = DUNA_TYPE_CLOSURE;
+      tmp.value.gc = (duna_GCObject*) alloc_closure(&D->store, dw1);
+      check_alloc(D, tmp.value.gc);
+      D->accum = tmp;

       /*
        * There is always a jump after this instruction, to jump over the
@@ -979,9 +1076,10 @@
     case DUNA_OP_SAVE_CONT:
       dw1 = D->sp * sizeof(duna_Object);

-      D->accum.type = DUNA_TYPE_CONTINUATION;
-      D->accum.value.gc = (duna_GCObject*) alloc_continuation(&D->store, D->sp);
-      check_alloc(D, D->accum.value.gc);
+      tmp.type = DUNA_TYPE_CONTINUATION;
+      tmp.value.gc = (duna_GCObject*) alloc_continuation(&D->store, D->sp);
+      check_alloc(D, tmp.value.gc);
+      D->accum = tmp;

       /* copying stack */
       memcpy(((duna_Continuation*)D->accum.value.gc)->stack, D->stack, dw1);
@@ -1012,13 +1110,12 @@
       break;

     case DUNA_OP_BOX:
-      tmp = D->accum;
-
-      D->accum.type = DUNA_TYPE_BOX;
-      D->accum.value.gc = (duna_GCObject*) alloc_box(&D->store);
-      check_alloc(D, D->accum.value.gc);
-
-      ((duna_Box*)D->accum.value.gc)->value = tmp;
+      tmp.type = DUNA_TYPE_BOX;
+      tmp.value.gc = (duna_GCObject*) alloc_box(&D->store);
+      check_alloc(D, tmp.value.gc);
+
+      ((duna_Box*)tmp.value.gc)->value = D->accum;
+      D->accum = tmp;
       break;

     case DUNA_OP_OPEN_BOX:
@@ -1101,13 +1198,13 @@
       break;

     case DUNA_OP_CONS:
-      tmp = D->accum;
-      D->accum.type = DUNA_TYPE_PAIR;
-      D->accum.value.gc = (duna_GCObject*) alloc_pair(&D->store);
-      check_alloc(D, D->accum.value.gc);
-
-      ((duna_Pair*)D->accum.value.gc)->car = tmp;
-      ((duna_Pair*)D->accum.value.gc)->cdr = D->stack[--D->sp];
+      tmp.type = DUNA_TYPE_PAIR;
+      tmp.value.gc = (duna_GCObject*) alloc_pair(&D->store);
+      check_alloc(D, tmp.value.gc);
+
+      ((duna_Pair*)tmp.value.gc)->car = D->accum;
+      ((duna_Pair*)tmp.value.gc)->cdr = D->stack[--D->sp];
+      D->accum = tmp;
       break;

     case DUNA_OP_CAR:


Add copy_constant function.

Add copy_constant function.

--- src/vm.c
+++ src/vm.c
@@ -95,69 +95,6 @@
     return object->d;
 }

-void copy_object(Object *a, Object *b) {
-    // TODO - clear old string?
-
-    switch (b->type) {
-        case OBJECT_INT:
-            a->type = OBJECT_INT;
-            a->i = b->i;
-            break;
-
-        case OBJECT_BOOL:
-            a->type = OBJECT_BOOL;
-            a->i = b->i;
-            break;
-
-        case OBJECT_REAL:
-            a->type = OBJECT_REAL;
-            a->d = b->d;
-            break;
-
-        case OBJECT_NULL:
-            a->type = OBJECT_NULL;
-            break;
-
-        case OBJECT_STRING:
-            a->type = OBJECT_STRING;
-            a->s = b->s;
-            break;
-
-        case OBJECT_CLOSURE:
-            a->type = OBJECT_CLOSURE;
-            a->c = b->c;
-            break;
-    }
-}
-
-void print(Object *o) {
-    switch (o->type) {
-        case OBJECT_INT:
-            printf("<INT %d>\n", o->i);
-            break;
-
-        case OBJECT_REAL:
-            printf("<REAL %.2f>\n", o->d);
-            break;
-
-        case OBJECT_BOOL:
-            printf("<%s>\n", o->i == 1 ? "true" : "false");
-            break;
-
-        case OBJECT_NULL:
-            printf("<NULL>\n");
-            break;
-
-        case OBJECT_STRING:
-            printf("<STRING %s>\n", o->s);
-            break;
-
-        case OBJECT_CLOSURE:
-            printf("<CLOSURE>\n");
-            break;
-    }
-}
-
 Upval *make_upval(State *state, int slot) {
     Upval *upval = malloc(sizeof *upval);
     UpvalNode *node = malloc(sizeof *node);
@@ -250,6 +187,117 @@
     state->current = root;
     state->head = NULL;
     return state;
+}
+
+void copy_object(Object *o1, Object *o2) {
+    // TODO - share string instances as a heap object,
+    // garbage collect at this point (instead of free)
+
+    if (o1->type == OBJECT_STRING) {
+        free(o1->s);
+    } else if (o1->type == OBJECT_CLOSURE) {
+        // TODO - also store closures on the heap for GC
+        // can't clean them yet, because they may exist in
+        // multiple registers
+    }
+
+    switch (o2->type) {
+        case OBJECT_INT:
+            o1->type = OBJECT_INT;
+            o1->i = o2->i;
+            break;
+
+        case OBJECT_BOOL:
+            o1->type = OBJECT_BOOL;
+            o1->i = o2->i;
+            break;
+
+        case OBJECT_REAL:
+            o1->type = OBJECT_REAL;
+            o1->d = o2->d;
+            break;
+
+        case OBJECT_NULL:
+            o1->type = OBJECT_NULL;
+            break;
+
+        case OBJECT_STRING:
+            o1->type = OBJECT_STRING;
+            o1->s = strdup(o2->s);
+            break;
+
+        case OBJECT_CLOSURE:
+            o1->type = OBJECT_CLOSURE;
+            o1->c = o2->c;
+            break;
+    }
+}
+
+void copy_constant(Object *o, Constant *c) {
+    // TODO - share string instances as a heap object,
+    // garbage collect at this point (instead of free)
+
+    if (o->type == OBJECT_STRING) {
+        free(o->s);
+    } else if (o->type == OBJECT_CLOSURE) {
+        // TODO - also store closures on the heap for GC
+        // can't clean them yet, because they may exist in
+        // multiple registers
+    }
+
+    switch (c->type) {
+        case CONST_INT:
+            o->type = OBJECT_INT;
+            o->i = c->i;
+            break;
+
+        case CONST_REAL:
+            o->type = OBJECT_REAL;
+            o->d = c->d;
+            break;
+
+        case CONST_BOOL:
+            o->type = OBJECT_BOOL;
+            o->i = c->i;
+            break;
+
+        case CONST_NULL:
+            o->type = OBJECT_NULL;
+            break;
+
+        case CONST_STRING:
+            o->type = OBJECT_STRING;
+            o->s = strdup(c->s);
+            break;
+    }
+}
+
+void print(Object *o) {
+    switch (o->type) {
+        case OBJECT_INT:
+            printf("<INT %d>\n", o->i);
+            break;
+
+        case OBJECT_REAL:
+            printf("<REAL %.2f>\n", o->d);
+            break;
+
+        case OBJECT_BOOL:
+            printf("<%s>\n", o->i == 1 ? "true" : "false");
+            break;
+
+        case OBJECT_NULL:
+            printf("<NULL>\n");
+            break;
+
+        case OBJECT_STRING:
+            printf("<STRING %s>\n", o->s);
+            break;
+
+        case OBJECT_CLOSURE:
+            printf("<CLOSURE>\n");
+            break;
+    }
 }

 void execute_function(State *state) {
@@ -269,40 +317,13 @@

         switch (o) {
             case OP_MOVE:
+            {
                 if (b < 256) {
                     copy_object(registers[a], registers[b]);
                 } else {
-                    // TODO - clear old string?
-
-                    Constant *constant = chunk->constants[b - 256];
-
-                    switch (constant->type) {
-                        case CONST_INT:
-                            registers[a]->type = OBJECT_INT;
-                            registers[a]->i = constant->i;
-                            break;
-
-                        case CONST_BOOL:
-                            registers[a]->type = OBJECT_BOOL;
-                            registers[a]->i = constant->i;
-                            break;
-
-                        case CONST_REAL:
-                            registers[a]->type = OBJECT_REAL;
-                            registers[a]->d = constant->d;
-                            break;
-
-                        case CONST_NULL:
-                            registers[a]->type = OBJECT_NULL;
-                            break;
-
-                        case CONST_STRING:
-                            registers[a]->type = OBJECT_STRING;
-                            registers[a]->s = constant->s;
-                            break;
-                    }
-                }
-                break;
+                    copy_constant(registers[a], chunk->constants[b - 256]);
+                }
+            } break;

             case OP_GETUPVAR:
             {
@@ -548,38 +569,13 @@

             case OP_RETURN:
             {
+                // TODO - no need to put into register 0
+                // TODO - does this mean that register 0 is unnecessary as special-use?
+
                 if (b < 256) {
                     copy_object(registers[0], registers[b]);
                 } else {
-                    // TODO - clear old string?
-
-                    Constant *constant = chunk->constants[b - 256];
-
-                    switch (constant->type) {
-                        case CONST_INT:
-                            registers[0]->type = OBJECT_INT;
-                            registers[0]->i = constant->i;
-                            break;
-
-                        case CONST_BOOL:
-                            registers[0]->type = OBJECT_BOOL;
-                            registers[0]->i = constant->i;
-                            break;
-
-                        case CONST_REAL:
-                            registers[0]->type = OBJECT_REAL;
-                            registers[0]->d = constant->d;
-                            break;
-
-                        case CONST_NULL:
-                            registers[0]->type = OBJECT_NULL;
-                            break;
-
-                        case CONST_STRING:
-                            registers[0]->type = OBJECT_STRING;
-                            registers[0]->s = constant->s;
-                            break;
-                    }
+                    copy_constant(registers[0], chunk->constants[b - 256]);
                 }

                 UpvalNode *head;
@@ -669,5 +665,9 @@
 }

 void execute(Chunk *chunk) {
-    execute_function(make_state(make_frame(NULL, make_closure(chunk))));
-}
+    Closure *closure = make_closure(chunk);
+    Frame *frame = make_frame(NULL, closure);
+    State *state = make_state(frame);
+
+    execute_function(state);
+}


sscall: Use `sig_atomic_t'

sscall: Use `sig_atomic_t'

Signed-off-by: Dimitris Papastamos <a91262282f71bb8488398dcc9202f777d0206664@opensource.wolfsonmicro.com>

--- sscall.c
+++ sscall.c
@@ -109,7 +109,7 @@
 static pthread_mutex_t capture_state_lock;

 /* Set to 1 when SIGINT is received */
-static volatile int handle_sigint;
+static volatile sig_atomic_t handle_sigint;

 /* Play back audio from the client */
 static void *


sscall: Use MSG_DONTWAIT

sscall: Use MSG_DONTWAIT

Signed-off-by: Dimitris Papastamos <a91262282f71bb8488398dcc9202f777d0206664@opensource.wolfsonmicro.com>

--- sscall.c
+++ sscall.c
@@ -306,7 +306,7 @@
 	do {
 		addr_len = sizeof(their_addr);
 		bytes = recvfrom(srv_sockfd, buf,
-				 sizeof(buf), 0,
+				 sizeof(buf), MSG_DONTWAIT,
 				 (struct sockaddr *)&their_addr,
 				 &addr_len);
 		if (bytes > 0)


Html: Clean up/refactor keyboard handling.

The main benefit is we do not attempt to subclass the embedded MSIE window
before we really need it. MSHTML.DLL creates the embedded window after
some delay, so attempting to subclass it with every message until it got
created was an overkill.

--- mctrl/html.c
+++ mctrl/html.c
@@ -103,6 +103,43 @@
     MC_CONTAINEROF(ptr_inplace_frame, html_t, inplace_frame)
 #define MC_HTML_FROM_UI_HANDLER(ptr_ui_handler)                               \
     MC_CONTAINEROF(ptr_ui_handler, html_t, ui_handler)
+
+
+
+static BSTR
+html_bstr(const void* from_str, int from_type)
+{
+    WCHAR* str_w;
+    BSTR str_b;
+
+    if(from_str == NULL) {
+        /* According to MSDN, BSTR should never be NULL. */
+        from_str = L"";
+        from_type = MC_STRW;
+    }
+
+    if(from_type == MC_STRW) {
+        str_w = (WCHAR*) from_str;
+    } else {
+        char* str_a;
+        MC_ASSERT(from_type == MC_STRA);
+        str_a = (char*) from_str;
+        str_w = (WCHAR*) mc_str(str_a, from_type, MC_STRW);
+        if(MC_ERR(str_w == NULL)) {
+            MC_TRACE("html_bstr: mc_str() failed.");
+            return NULL;
+        }
+    }
+
+    str_b = SysAllocString(str_w);
+    if(MC_ERR(str_b == NULL))
+        MC_TRACE("html_bstr: SysAllocString() failed.");
+
+    if(str_w != from_str)
+        free(str_w);
+
+    return str_b;
+}

 static ULONG STDMETHODCALLTYPE
@@ -991,45 +1028,159 @@
 };

+/*****************************
+ *** Subclass of IE Window ***
+ *****************************/
+
+/* We subclass the embedded browser window to handle keyboard messages.
+ * We need to call IOleInPlaceActiveObject::TranslateAccelerator().
+ *
+ * Normally the call should be done directly in application's main loop, but
+ * hey, we are DLL and cannot do that.
+ *
+ * Furthermore, the embedded window likely does some magic to get <tab>
+ * keystrokes. I do not know how to replicate this for our host window but
+ * the subclassing works around this issue.
+ *
+ * (As far as I can understand it, the culprit is that main message pump
+ * usually handles <tab> in IsDialogMessage(), before DispatchMessage(), so it
+ * does not propagate into window procedure. So how the embedded window achieves
+ * to get it is mystery to me.)
+ *
+ * Propagating the keystroke messages from html_proc() into the embedded
+ * window procedure and resetting the focus to the embedded window whenever
+ * our host window gets it works around these issues.
+ */
+
+static BOOL
+html_key_msg(html_t* html, UINT msg, WPARAM wp, LPARAM lp)
+{
+    DWORD pos;
+    MSG message;
+    IOleInPlaceActiveObject* active_iface;
+    HRESULT hr;
+    BOOL ret = FALSE;
+
+    pos = GetMessagePos();
+
+    /* Setup the message structure */
+    message.hwnd = html->ie_win;
+    message.message = msg;
+    message.wParam = wp;
+    message.lParam = lp;
+    message.time = GetMessageTime();
+    message.pt.x = GET_X_LPARAM(pos);
+    message.pt.y = GET_Y_LPARAM(pos);
+
+    /* ->TranslateAccelerator() */
+    hr = IWebBrowser2_QueryInterface(html->browser2,
+                        &IID_IOleInPlaceActiveObject, (void**)&active_iface);
+    if(MC_ERR(hr != S_OK  ||  active_iface == NULL)) {
+        MC_TRACE_HR("html_key_msg: "
+                    "QueryInterface(IID_IOleInPlaceActiveObject) failed.");
+        goto err_active;
+    }
+
+    hr = IOleInPlaceActiveObject_TranslateAccelerator(active_iface, &message);
+    switch(hr) {
+        case S_OK:    ret = TRUE; break;
+        case S_FALSE: /*noop */ break;
+        default:
+            MC_TRACE_ERR("html_key_msg: ->TranslateAccelerator() failed.");
+            break;
+    }
+
+    /* Cleanup */
+    IOleInPlaceActiveObject_Release(active_iface);
+err_active:
+    return ret;
+}
+
+static LRESULT CALLBACK
+html_ie_subclass_proc(HWND win, UINT msg, WPARAM wp, LPARAM lp)
+{
+    html_t* html;
+    WNDPROC ie_proc;
+
+    html = (html_t*) GetProp(win, ie_prop);
+    ie_proc = html->ie_proc;
+
+    if(WM_KEYFIRST <= msg && msg <= WM_KEYLAST) {
+        if(html_key_msg(html, msg, wp, lp))
+            return 0;
+    }
+
+    switch(msg) {
+        case WM_GETDLGCODE:
+            return DLGC_WANTALLKEYS;
+
+        case WM_NCDESTROY:
+            SetWindowLongPtr(html->ie_win, GWLP_WNDPROC, (LONG_PTR) ie_proc);
+            RemoveProp(html->ie_win, ie_prop);
+            html_Release(html);
+            break;
+    }
+
+    return CallWindowProc(ie_proc, win, msg, wp, lp);
+}
+
+static HWND
+html_find_ie_window(HWND win)
+{
+    static const TCHAR ie_wc[] = _T("Internet Explorer_Server");
+    HWND w;
+
+    w = FindWindowEx(win, NULL, ie_wc, NULL);
+    if(w != NULL)
+        return w;
+
+    win = GetWindow(win, GW_CHILD);
+    while(win != NULL) {
+        w = html_find_ie_window(win);
+        if(w != NULL)
+            return w;
+
+        win = GetWindow(win, GW_HWNDNEXT);
+    }
+
+    return NULL;
+}
+
+static HWND
+html_get_ie_win(html_t* html)
+{
+    if(html->ie_win != NULL)
+        return html->ie_win;
+
+    html->ie_win = html_find_ie_window(html->win);
+
+    if(html->ie_win != NULL) {
+        /* The IE maybe may live in another thread, let it have its own
+         * reference of the html_t. */
+        html_AddRef(html);
+
+        /* Subclass the IE window. */
+        html->ie_proc = (WNDPROC) SetWindowLongPtr(html->ie_win,
+                        GWLP_WNDPROC, (LONG_PTR) html_ie_subclass_proc);
+        SetProp(html->ie_win, ie_prop, (HANDLE) html);
+
+        /* Propagate focus to it from our window. */
+        if(GetFocus() == html->win) {
+            SetFocus(html->ie_win);
+
+            /* FIXME: SetFocus() does not really work here. */
+            MC_SEND(html->ie_win, WM_LBUTTONDOWN, 0, 0);
+            MC_SEND(html->ie_win, WM_LBUTTONUP, 0, 0);
+        }
+    }
+
+    return html->ie_win;
+}
+

 /**********************************
  *** Host window implementation ***
  **********************************/
-
-static BSTR
-html_bstr(const void* from_str, int from_type)
-{
-    WCHAR* str_w;
-    BSTR str_b;
-
-    if(from_str == NULL) {
-        /* According to MSDN, BSTR should never be NULL. */
-        from_str = L"";
-        from_type = MC_STRW;
-    }
-
-    if(from_type == MC_STRW) {
-        str_w = (WCHAR*) from_str;
-    } else {
-        char* str_a;
-        MC_ASSERT(from_type == MC_STRA);
-        str_a = (char*) from_str;
-        str_w = (WCHAR*) mc_str(str_a, from_type, MC_STRW);
-        if(MC_ERR(str_w == NULL)) {
-            MC_TRACE("html_bstr: mc_str() failed.");
-            return NULL;
-        }
-    }
-
-    str_b = SysAllocString(str_w);
-    if(MC_ERR(str_b == NULL))
-        MC_TRACE("html_bstr: SysAllocString() failed.");
-
-    if(str_w != from_str)
-        free(str_w);
-
-    return str_b;
-}

 static LRESULT
 html_notify_http_error(html_t* html, int http_status, const WCHAR* url)
@@ -1278,24 +1429,6 @@
     IDispatch_Release(doc_dispatch_iface);
 err_dispatch:
     return hr;
-}
-
-static HRESULT
-html_call_script_func_ex(html_t* html, MC_HMCALLSCRIPTFUNCEX* csfe)
-{
-    if(MC_ERR(csfe->cbSize != sizeof(MC_HMCALLSCRIPTFUNCEX))) {
-        MC_TRACE("html_call_script_func_ex: Unsupported cbSize %u", csfe->cbSize);
-        return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
-    }
-
-    if(MC_ERR(csfe->lpRet != NULL  &&  V_VT(csfe->lpRet) != VT_EMPTY)) {
-        MC_TRACE("html_call_script_func_ex: "
-                 "MC_HMCALLSCRIPTFUNCEX::lpRet is not VT_EMPTY.");
-        return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
-    }
-
-    return html_do_call_script_func(html, csfe->pszFuncName, csfe->cArgs,
-                                    csfe->lpvArgs, csfe->lpRet);
 }

 static int
@@ -1416,48 +1549,22 @@
     return 0;
 }

-static BOOL
-html_key_msg(html_t* html, UINT msg, WPARAM wp, LPARAM lp)
-{
-    DWORD pos;
-    MSG message;
-    IOleInPlaceActiveObject* active_iface;
-    HRESULT hr;
-    BOOL ret = FALSE;
-
-    pos = GetMessagePos();
-
-    /* Setup the message structure */
-    message.hwnd = html->ie_win;
-    message.message = msg;
-    message.wParam = wp;
-    message.lParam = lp;
-    message.time = GetMessageTime();
-    message.pt.x = GET_X_LPARAM(pos);
-    message.pt.y = GET_Y_LPARAM(pos);
-
-    /* ->TranslateAccelerator() */
-    hr = IWebBrowser2_QueryInterface(html->browser2,
-                        &IID_IOleInPlaceActiveObject, (void**)&active_iface);
-    if(MC_ERR(hr != S_OK  ||  active_iface == NULL)) {
-        MC_TRACE_HR("html_key_msg: "
-                    "QueryInterface(IID_IOleInPlaceActiveObject) failed.");
-        goto err_active;
-    }
-
-    hr = IOleInPlaceActiveObject_TranslateAccelerator(active_iface, &message);
-    switch(hr) {
-        case S_OK:    ret = TRUE; break;
-        case S_FALSE: /*noop */ break;
-        default:
-            MC_TRACE_ERR("html_key_msg: ->TranslateAccelerator() failed.");
-            break;
-    }
-
-    /* Cleanup */
-    IOleInPlaceActiveObject_Release(active_iface);
-err_active:
-    return ret;
+static HRESULT
+html_call_script_func_ex(html_t* html, MC_HMCALLSCRIPTFUNCEX* csfe)
+{
+    if(MC_ERR(csfe->cbSize != sizeof(MC_HMCALLSCRIPTFUNCEX))) {
+        MC_TRACE("html_call_script_func_ex: Unsupported cbSize %u", csfe->cbSize);
+        return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
+    }
+
+    if(MC_ERR(csfe->lpRet != NULL  &&  V_VT(csfe->lpRet) != VT_EMPTY)) {
+        MC_TRACE("html_call_script_func_ex: "
+                 "MC_HMCALLSCRIPTFUNCEX::lpRet is not VT_EMPTY.");
+        return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
+    }
+
+    return html_do_call_script_func(html, csfe->pszFuncName, csfe->cArgs,
+                                    csfe->lpvArgs, csfe->lpRet);
 }

 static html_t*
@@ -1569,13 +1676,6 @@
 static void
 html_destroy(html_t* html)
 {
-    /* Unsubclass IE window */
-    if(html->ie_win != NULL) {
-        SetWindowLongPtr(html->ie_win, GWLP_WNDPROC, (LONG_PTR)html->ie_proc);
-        RemoveProp(html->ie_win, ie_prop);
-        html->ie_win = NULL;
-    }
-
     /* Destruction of the embedded browser seems to be quite tricky.
      * See http://stackoverflow.com/a/14652605/917880. */

@@ -1637,57 +1737,6 @@
     html_Release(html);
 }

-
-static LRESULT CALLBACK
-html_ie_subclass_proc(HWND win, UINT msg, WPARAM wp, LPARAM lp)
-{
-    html_t* html;
-    LRESULT ret;
-
-    html = (html_t*) GetProp(win, ie_prop);
-
-    if(WM_KEYFIRST <= msg && msg <= WM_KEYLAST) {
-        if(html_key_msg(html, msg, wp, lp))
-            return 0;
-    }
-
-    if(msg == WM_GETDLGCODE)
-        return DLGC_WANTALLKEYS;
-
-    ret = CallWindowProc(html->ie_proc, win, msg, wp, lp);
-
-    if(msg == WM_DESTROY) {
-        SetWindowLongPtr(win, GWLP_WNDPROC, (LONG_PTR)html->ie_proc);
-        RemoveProp(win, ie_prop);
-        html->ie_win = NULL;
-    }
-
-    return ret;
-}
-
-static HWND
-html_find_ie_window(HWND win)
-{
-    static const TCHAR ie_wc[] = _T("Internet Explorer_Server");
-    HWND w;
-
-    w = FindWindowEx(win, NULL, ie_wc, NULL);
-    if(w != NULL)
-        return w;
-
-    win = GetWindow(win, GW_CHILD);
-    while(win != NULL) {
-        w = html_find_ie_window(win);
-        if(w != NULL)
-            return w;
-
-        win = GetWindow(win, GW_HWNDNEXT);
-    }
-
-    return NULL;
-}
-
-
 static LRESULT CALLBACK
 html_proc(HWND win, UINT msg, WPARAM wp, LPARAM lp)
 {
@@ -1696,26 +1745,12 @@
     /* This shuts up Coverity issue CID989764. */
     MC_ASSERT(html != NULL  ||  msg == WM_NCCREATE  ||  msg == WM_NCDESTROY);

-    if(html != NULL  &&  html->ie_win == NULL) {
-        /* Let's try to subclass IE window. This is very dirty hack,
-         * which allows us to forward keyboard messages properly to
-         * IOleInPlaceActiveObject::TranslateAccelerator().
-         *
-         * Normally this should be done from main app. loop but we do not
-         * have it under control in the DLL. */
-        html->ie_win = html_find_ie_window(win);
-        if(html->ie_win != NULL) {
-            HTML_TRACE("html_proc: Subclassing MSIE.");
-            html->ie_proc = (WNDPROC) SetWindowLongPtr(html->ie_win,
-                            GWLP_WNDPROC, (LONG_PTR) html_ie_subclass_proc);
-            SetProp(html->ie_win, ie_prop, (HANDLE) html);
-
-            if(GetFocus() == win) {
-                SetFocus(html->ie_win);
-                MC_SEND(html->ie_win, WM_LBUTTONDOWN, 0, 0);
-                MC_SEND(html->ie_win, WM_LBUTTONUP, 0, 0);
-            }
-        }
+    /* Forward keystrokes to the IE window. */
+    if(WM_KEYFIRST <= msg  &&  msg <= WM_KEYLAST) {
+        HWND ie_win = html_get_ie_win(html);
+        if(ie_win != NULL)
+            MC_SEND(ie_win, msg, wp, lp);
+        return 0;
     }

     switch(msg) {
@@ -1794,12 +1829,17 @@
         }

         case WM_SETFOCUS:
-            if(html->ie_win) {
-                SetFocus(html->ie_win);
-                MC_SEND(html->ie_win, WM_LBUTTONDOWN, 0, 0);
-                MC_SEND(html->ie_win, WM_LBUTTONUP, 0, 0);
+        {
+            HWND ie_win = html_get_ie_win(html);
+            if(ie_win != NULL) {
+                SetFocus(ie_win);
+
+                /* FIXME: SetFocus() does not really work here. */
+                MC_SEND(ie_win, WM_LBUTTONDOWN, 0, 0);
+                MC_SEND(ie_win, WM_LBUTTONUP, 0, 0);
             }
             return 0;
+        }

         case WM_GETDLGCODE:
             return DLGC_WANTALLKEYS;
@@ -1833,13 +1873,6 @@
             if(html != NULL)
                 html_ncdestroy(html);
             return 0;
-    }
-
-    /* Forward keystrokes to the IE */
-    if(WM_KEYFIRST <= msg  &&  msg <= WM_KEYLAST) {
-        if(html->ie_win)
-            MC_SEND(html->ie_win, msg, wp, lp);
-        return 0;
     }

     return DefWindowProc(win, msg, wp, lp);


don't overwrite the error in ykp_import_config()

fixes #50

--- ykpers.c
+++ ykpers.c
@@ -1068,8 +1068,9 @@
 		return _ykp_json_import_cfg(cfg, buf, len);
 	} else if(format == YKP_FORMAT_LEGACY) {
 		ykp_errno = YKP_ENOTYETIMPL;
-	}
-	ykp_errno = YKP_EINVAL;
+	} else {
+		ykp_errno = YKP_EINVAL;
+	}
 	return 0;
 }
 int ykp_write_config(const YKP_CONFIG *cfg,


Const correct parseSubOptions

Const correct parseSubOptions

* Function static
* Arguments const where applicable

--- client/common/cmdline.c
+++ client/common/cmdline.c
@@ -1506,27 +1506,29 @@
 	CmdLineSubOptionCb cb;
 } CmdLineSubOptions;

-static BOOL parseSubOptions(rdpSettings* settings, const CmdLineSubOptions* opts, const char* arg)
+static BOOL parseSubOptions(rdpSettings* settings, const CmdLineSubOptions* opts, size_t count,
+                            const char* arg)
 {
 	BOOL found = FALSE;
 	size_t xx;

-	for (xx = 0; opts[xx].optname; xx++)
-	{
-		size_t optlen = strlen(opts[xx].optname);
-
-		if (strncmp(opts[xx].optname, arg, optlen) == 0)
+	for (xx = 0; xx < count; xx++)
+	{
+		const CmdLineSubOptions* opt = &opts[xx];
+		size_t optlen = strlen(opt->optname);
+
+		if (strncmp(opt->optname, arg, optlen) == 0)
 		{
 			const char* val = &arg[optlen];
 			BOOL status;

-			switch (opts[xx].opttype)
+			switch (opt->opttype)
 			{
 			case CMDLINE_SUBOPTION_STRING:
-				status = freerdp_settings_set_string(settings, opts[xx].id, val);
+				status = freerdp_settings_set_string(settings, opt->id, val);
 				break;
 			case CMDLINE_SUBOPTION_FILE:
-				status = read_pem_file(settings, opts[xx].id, val);
+				status = read_pem_file(settings, opt->id, val);
 				break;
 			default:
 				WLog_ERR(TAG, "invalid subOption type");
@@ -1536,7 +1538,7 @@
 			if (!status)
 				return FALSE;

-			if (opts[xx].cb && !opts[xx].cb(val, settings))
+			if (opt->cb && !opt->cb(val, settings))
 				return FALSE;

 			found = TRUE;
@@ -3316,6 +3318,16 @@
 					return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
 			}
 		}
+		CommandLineSwitchCase(arg, "pkcs11-module")
+		{
+			if (!copy_value(arg->Value, &settings->Pkcs11Module))
+				return COMMAND_LINE_ERROR_MEMORY;
+		}
+		CommandLineSwitchCase(arg, "pkinit-anchors")
+		{
+			if (!copy_value(arg->Value, &settings->PkinitAnchors))
+				return COMMAND_LINE_ERROR_MEMORY;
+		}
 		CommandLineSwitchCase(arg, "kerberos")
 		{
 			size_t count;
@@ -3329,21 +3341,19 @@
 			if (ptr.pc)
 			{
 				size_t x;
-				static const CmdLineSubOptions opts[] = {
+				const CmdLineSubOptions opts[] = {
 					{ "start-time:", FreeRDP_KerberosStartTime, CMDLINE_SUBOPTION_STRING, NULL },
 					{ "lifetime:", FreeRDP_KerberosLifeTime, CMDLINE_SUBOPTION_STRING, NULL },
-					{ "renewable-lifetime:", FreeRDP_KerberosRenewableLifeTime, CMDLINE_SUBOPTION_STRING, NULL },
+					{ "renewable-lifetime:", FreeRDP_KerberosRenewableLifeTime,
+					  CMDLINE_SUBOPTION_STRING, NULL },
 					{ "cache:", FreeRDP_KerberosCache, CMDLINE_SUBOPTION_STRING, NULL },
-					{ "armor:", FreeRDP_KerberosArmor, CMDLINE_SUBOPTION_STRING, NULL },
-					{ "pkinit-anchors:", FreeRDP_PkinitAnchors, CMDLINE_SUBOPTION_STRING, NULL },
-					{ "pkcs11-module:", FreeRDP_Pkcs11Module, CMDLINE_SUBOPTION_STRING, NULL },
-					{ NULL, 0, CMDLINE_SUBOPTION_STRING, NULL }
+					{ "armor:", FreeRDP_KerberosArmor, CMDLINE_SUBOPTION_STRING, NULL }
 				};

 				for (x = 1; x < count; x++)
 				{
 					const char* cur = ptr.pc[x];
-					if (!parseSubOptions(settings, opts, cur))
+					if (!parseSubOptions(settings, opts, ARRAYSIZE(opts), cur))
 					{
 						free(ptr.p);
 						return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
@@ -3381,21 +3391,22 @@
 			if (ptr.pc)
 			{
 				size_t x;
-				static const CmdLineSubOptions opts[] = {
-					{ "cert:", FreeRDP_SmartcardCertificate, CMDLINE_SUBOPTION_FILE, setSmartcardEmulation },
-					{ "key:", FreeRDP_SmartcardPrivateKey, CMDLINE_SUBOPTION_FILE, setSmartcardEmulation },
+				const CmdLineSubOptions opts[] = {
+					{ "cert:", FreeRDP_SmartcardCertificate, CMDLINE_SUBOPTION_FILE,
+					  setSmartcardEmulation },
+					{ "key:", FreeRDP_SmartcardPrivateKey, CMDLINE_SUBOPTION_FILE,
+					  setSmartcardEmulation },
 					{ "pin:", FreeRDP_SmartcardPin, CMDLINE_SUBOPTION_STRING, NULL },
 					{ "csp:", FreeRDP_CspName, CMDLINE_SUBOPTION_STRING, NULL },
 					{ "reader:", FreeRDP_ReaderName, CMDLINE_SUBOPTION_STRING, NULL },
 					{ "card:", FreeRDP_CardName, CMDLINE_SUBOPTION_STRING, NULL },
-					{ "container:", FreeRDP_ContainerName, CMDLINE_SUBOPTION_STRING, NULL },
-					{ NULL, 0, CMDLINE_SUBOPTION_STRING, NULL },
+					{ "container:", FreeRDP_ContainerName, CMDLINE_SUBOPTION_STRING, NULL }
 				};

 				for (x = 1; x < count; x++)
 				{
 					const char* cur = ptr.pc[x];
-					if (!parseSubOptions(settings, opts, cur))
+					if (!parseSubOptions(settings, opts, ARRAYSIZE(opts), cur))
 					{
 						free(ptr.p);
 						return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;


fix #1433

fix #1433

--- swoole.c
+++ swoole.c
@@ -839,10 +839,6 @@
     zend_declare_property_bool(swoole_server_class_entry_ptr, ZEND_STRL("taskworker"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
     zend_declare_property_long(swoole_server_class_entry_ptr, ZEND_STRL("worker_pid"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);

-#ifdef HAVE_PCRE
-    zend_declare_property_null(swoole_server_class_entry_ptr, ZEND_STRL("connections"), ZEND_ACC_PUBLIC TSRMLS_CC);
-#endif
-
     SWOOLE_INIT_CLASS_ENTRY(swoole_timer_ce, "swoole_timer", "Swoole\\Timer", swoole_timer_methods);
     swoole_timer_class_entry_ptr = zend_register_internal_class(&swoole_timer_ce TSRMLS_CC);
     SWOOLE_CLASS_ALIAS(swoole_timer, "Swoole\\Timer");


Supporting init declaration lists recursively

--- symbol.c
+++ symbol.c
@@ -356,6 +356,60 @@
 	}
 }

+void init_decl(enum type t, struct tree *n)
+{
+	char *k = NULL;
+	struct typeinfo *v = NULL;
+
+	switch (get_rule(n)) {
+	case INIT_DECL: { /* simple variable, possibly with initializer */
+		if (tree_size(n) == 2) {
+			k = get_token(n, 0)->text;
+			v = typeinfo_new(t, false, 0);
+		} else {
+			init_decl(t, tree_index(n, 0));
+		}
+		break;
+	}
+	case DECL2: { /* simple pointer variable */
+		k = get_token(n, 1)->text;
+		v = typeinfo_new(t, true, 0);
+		break;
+	}
+	case DIRECT_DECL6: { /* simple array with size */
+		k = get_token(n, 0)->text;
+		size_t size = get_token(n, 2)->ival;
+		v = typeinfo_new(ARRAY_T, false, 2, typeinfo_new(t, false, 0), size);
+		break;
+	}
+	case DIRECT_DECL2: { /* function prototype */
+		k = get_token(n, 0)->text;
+		struct list *params = list_new(NULL, NULL);
+		if (tree_size(n) > 2)
+			proto_param_list(params, tree_index(n, 1));
+		v = typeinfo_new(FUNCTION_T, false, 3, t, params, NULL);
+		break;
+	}
+	default:
+		semantic_error("unsupported declaration type", n);
+	}
+	if (v)
+		insert_symbol(k, v, n, NULL);
+}
+
+void init_decl_list(enum type t, struct tree *n)
+{
+	if (get_rule(n) == INIT_DECL_LIST2) {
+		struct list_node *iter = list_head(n->children);
+		while (!list_end(iter)) {
+			init_decl_list(t, iter->data);
+			iter = iter->next;
+		}
+	} else {
+		init_decl(t, n);
+	}
+}
+
 bool handle_node(struct tree *n, int d)
 {
 	switch (get_rule(n)) {
@@ -363,44 +417,9 @@
 		/* this may need to be synthesized */
 		enum type t = get_type(get_token(n, 0)->category);

-		char *k = NULL;
-		struct typeinfo *v = NULL;
-
 		struct tree *init_decl = tree_index(n, 1);
-		struct tree *direct_decl = tree_index(init_decl, 0);
-
-		switch (get_rule(direct_decl)) {
-		case DECL2: { /* simple pointer variable */
-			k = get_token(direct_decl, 1)->text;
-			v = typeinfo_new(t, true, 0);
-			break;
-		}
-		case DIRECT_DECL6: { /* simple array with size */
-			k = get_token(direct_decl, 0)->text;
-			size_t size = get_token(direct_decl, 2)->ival;
-			v = typeinfo_new(ARRAY_T, false, 2, size, t);
-			break;
-		}
-		case DIRECT_DECL2: { /* function prototype */
-			k = get_token(direct_decl, 0)->text;
-			struct list *params = list_new(NULL, NULL);
-			if (tree_size(direct_decl) > 2)
-				proto_param_list(params, tree_index(direct_decl, 1));
-			v = typeinfo_new(FUNCTION_T, false, 3, t, params, NULL);
-			break;
-		}
-		default: {
-			/* simple variable, possibly with initializer */
-			if (tree_size(init_decl) <= 3) {
-				k = get_token(init_decl, 0)->text;
-				v = typeinfo_new(t, false, 0);
-			} else {
-				semantic_error("unsupported declaration type", n);
-			}
-		}
-		}
-		if (v)
-			insert_symbol(k, v, n, NULL);
+		init_decl_list(t, init_decl);
+
 		return false;
 	}
 	case FUNCTION_DEF2: {


Forgot to beautify symbol.h

Forgot to beautify symbol.h

--- symbol.h
+++ symbol.h
@@ -49,35 +49,35 @@
 typedef struct Type_tag * Type;

 struct Type_tag {
-    enum {                               /*****     ****/
-       TYPE_VOID,                        /*    */
-       TYPE_INTEGER,                     /*                   */
-       TYPE_BOOLEAN,                     /*               */
-       TYPE_CHAR,                        /*                 */
-       TYPE_REAL,                        /*                */
-       TYPE_ARRAY,                       /*     */
-       TYPE_IARRAY,                      /*    */
-    } kind;
-    Type           refType;              /*              */
-    RepInteger     size;                 /* ,    */
-    unsigned int   refCount;             /*           */
+	enum {                               /*****     ****/
+		TYPE_VOID,                        /*    */
+		TYPE_INTEGER,                     /*                   */
+		TYPE_BOOLEAN,                     /*               */
+		TYPE_CHAR,                        /*                 */
+		TYPE_REAL,                        /*                */
+		TYPE_ARRAY,                       /*     */
+		TYPE_IARRAY,                      /*    */
+	} kind;
+	Type           refType;              /*              */
+	RepInteger     size;                 /* ,    */
+	unsigned int   refCount;             /*           */
 };

 /*      */

-typedef enum {
-   ENTRY_VARIABLE,                       /*                  */
-   ENTRY_CONSTANT,                       /*                    */
-   ENTRY_FUNCTION,                       /*                 */
-   ENTRY_PARAMETER,                      /*       */
-   ENTRY_TEMPORARY                       /*        */
+typedef enum {
+	ENTRY_VARIABLE,                       /*                  */
+	ENTRY_CONSTANT,                       /*                    */
+	ENTRY_FUNCTION,                       /*                 */
+	ENTRY_PARAMETER,                      /*       */
+	ENTRY_TEMPORARY                       /*        */
 } EntryType;

 /*    */

-typedef enum {
-   PASS_BY_VALUE,                        /* '                   */
-   PASS_BY_REFERENCE                     /* '                */
+typedef enum {
+	PASS_BY_VALUE,                        /* '                   */
+	PASS_BY_REFERENCE                     /* '                */
 } PassMode;

 /*      */
@@ -85,58 +85,58 @@
 typedef struct SymbolEntry_tag SymbolEntry;

 struct SymbolEntry_tag {
-   const char   * id;                 /*            */
-   EntryType      entryType;          /*               */
-   unsigned int   nestingLevel;       /*               */
-   unsigned int   hashValue;          /*            */
-   SymbolEntry  * nextHash;           /*    ..     */
-   SymbolEntry  * nextInScope;        /*     */
-
-   union {                            /*     : */
-
-      struct {                                /*******  *******/
-         Type          type;                  /*                  */
-         int           offset;                /* Offset  ..       */
-      } eVariable;
-
-      struct {                                /********  ********/
-         Type          type;                  /*                  */
-         union {                              /*                   */
-            RepInteger vInteger;              /*                */
-            RepBoolean vBoolean;              /*                 */
-            RepChar    vChar;                 /*             */
-            RepReal    vReal;                 /*             */
-            RepString  vString;               /*           */
-         } value;
-      } eConstant;
-
-      struct {                                /*******  *******/
-         bool          isForward;             /*  forward        */
-         SymbolEntry * firstArgument;         /*        */
-         SymbolEntry * lastArgument;          /*    */
-         Type          resultType;            /*     */
-         enum {                               /*    */
-             PARDEF_COMPLETE,                    /*       */
-             PARDEF_DEFINE,                      /*       */
-             PARDEF_CHECK                        /*       */
-         } pardef;
-         int           firstQuad;             /*          */
-      } eFunction;
-
-      struct {                                /******  *******/
-         Type          type;                  /*                  */
-         int           offset;                /* Offset  ..       */
-         PassMode      mode;                  /*       */
-         SymbolEntry * next;                  /*      */
-      } eParameter;
-
-      struct {                                /**   **/
-         Type          type;                  /*                  */
-         int           offset;                /* Offset  ..       */
-         int           number;
-      } eTemporary;
-
-   } u;                               /*   union               */
+	const char   * id;                 /*            */
+	EntryType      entryType;          /*               */
+	unsigned int   nestingLevel;       /*               */
+	unsigned int   hashValue;          /*            */
+	SymbolEntry  * nextHash;           /*    ..     */
+	SymbolEntry  * nextInScope;        /*     */
+
+	union {                            /*     : */
+
+		struct {                                /*******  *******/
+			Type          type;                  /*                  */
+			int           offset;                /* Offset  ..       */
+		} eVariable;
+
+		struct {                                /********  ********/
+			Type          type;                  /*                  */
+			union {                              /*                   */
+				RepInteger vInteger;              /*                */
+				RepBoolean vBoolean;              /*                 */
+				RepChar    vChar;                 /*             */
+				RepReal    vReal;                 /*             */
+				RepString  vString;               /*           */
+			} value;
+		} eConstant;
+
+		struct {                                /*******  *******/
+			bool          isForward;             /*  forward        */
+			SymbolEntry * firstArgument;         /*        */
+			SymbolEntry * lastArgument;          /*    */
+			Type          resultType;            /*     */
+			enum {                               /*    */
+				PARDEF_COMPLETE,                    /*       */
+				PARDEF_DEFINE,                      /*       */
+				PARDEF_CHECK                        /*       */
+			} pardef;
+			int           firstQuad;             /*          */
+		} eFunction;
+
+		struct {                                /******  *******/
+			Type          type;                  /*                  */
+			int           offset;                /* Offset  ..       */
+			PassMode      mode;                  /*       */
+			SymbolEntry * next;                  /*      */
+		} eParameter;
+
+		struct {                                /**   **/
+			Type          type;                  /*                  */
+			int           offset;                /* Offset  ..       */
+			int           number;
+		} eTemporary;
+
+	} u;                               /*   union               */
 };

 /*         */
@@ -144,17 +144,17 @@
 typedef struct Scope_tag Scope;

 struct Scope_tag {
-    unsigned int   nestingLevel;             /*        */
-    unsigned int   negOffset;                /*   offset */
-    Scope        * parent;                   /*    */
-    SymbolEntry  * entries;                  /*     */
+	unsigned int   nestingLevel;             /*        */
+	unsigned int   negOffset;                /*   offset */
+	Scope        * parent;                   /*    */
+	SymbolEntry  * entries;                  /*     */
 };

 /*      */

 typedef enum {
-    LOOKUP_CURRENT_SCOPE,
-    LOOKUP_ALL_SCOPES
+	LOOKUP_CURRENT_SCOPE,
+	LOOKUP_ALL_SCOPES
 } LookupType;

 /* ---------------------------------------------------------------------
@@ -185,14 +185,14 @@
 SymbolEntry * newConstant        (const char * name, Type type, ...);
 SymbolEntry * newFunction        (const char * name);
 SymbolEntry * newParameter       (const char * name, Type type,
-                                  PassMode mode, SymbolEntry * f);
+									PassMode mode, SymbolEntry * f);
 SymbolEntry * newTemporary       (Type type);

 void          forwardFunction    (SymbolEntry * f);
 void          endFunctionHeader  (SymbolEntry * f, Type type);
 void          destroyEntry       (SymbolEntry * e);
 SymbolEntry * lookupEntry        (const char * name, LookupType type,
-                                  bool err);
+									bool err);

 Type          typeArray          (RepInteger size, Type refType);
 Type          typeIArray         (Type refType);


[clutter-clone] Override the parent opacity to self not self->parent

The opacity of the source actor when painted from the clone should be
combined with the opacity of the clone as well as the clone's parents,
instead of just the parents.

--- clutter/clutter-clone.c
+++ clutter/clutter-clone.c
@@ -118,7 +118,6 @@
 {
   ClutterClone *clone = CLUTTER_CLONE (self);
   ClutterClonePrivate *priv = clone->priv;
-  ClutterActor *parent;
   ClutterGeometry geom, clone_geom;
   gfloat x_scale, y_scale;

@@ -145,14 +144,13 @@
   cogl_scale (x_scale, y_scale, 1.0);

   /* The final bits of magic:
-   * - We need to make sure that when the clone-source actor's paint method
-   *   calls clutter_actor_get_paint_opacity, it traverses our parent not it's
-   *   real parent.
+   * - We need to make sure that when the clone-source actor's paint
+   *   method calls clutter_actor_get_paint_opacity, it traverses to
+   *   us and our parent not it's real parent.
    * - We need to stop clutter_actor_paint applying the model view matrix of
    *   the clone source actor.
    */
-  parent = clutter_actor_get_parent (self);
-  _clutter_actor_set_opacity_parent (priv->clone_source, parent);
+  _clutter_actor_set_opacity_parent (priv->clone_source, self);
   _clutter_actor_set_enable_model_view_transform (priv->clone_source, FALSE);

   clutter_actor_paint (priv->clone_source);


Delete stdafx.h

Delete stdafx.h

--- stdafx.h
+++ stdafx.h
@@ -1,15 +0,0 @@
-// stdafx.h : include file for standard system include files,
-// or project specific include files that are used frequently, but
-// are changed infrequently
-//
-
-#pragma once
-
-#include "targetver.h"
-
-#include <stdio.h>
-#include <tchar.h>
-
-
-
-// TODO: reference additional headers your program requires here


Ouvrir l'executable en mode binaire, bien sur

git-svn-id: e7e61699ce1738538ffebb75374fbea0924bc775@3347 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02

--- stdlib/header.c
+++ stdlib/header.c
@@ -165,13 +165,17 @@
   write(2, msg, strlen(msg));
 }

+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 int main(int argc, char ** argv)
 {
   char * truename, * runtime_path;
   int fd;

   truename = searchpath(argv[0]);
-  fd = open(truename, O_RDONLY);
+  fd = open(truename, O_RDONLY | O_BINARY);
   if (fd == -1 || (runtime_path = read_runtime_path(fd)) == NULL) {
     errwrite(truename);
     errwrite(" not found or is not a bytecode executable file\n");