This commit was generated by cvs2svn to compensate for changes in r171164, which included commits to RCS files with non-trunk default branches.

error: pathspec 'sys/contrib/pf/net/pf_ruleset.c' did not match any file(s) known to git

--- sys/contrib/pf/net/pf_ruleset.c
+++ sys/contrib/pf/net/pf_ruleset.c
@@ -0,0 +1,415 @@
+/*	$OpenBSD: pf_ruleset.c,v 1.1 2006/10/27 13:56:51 mcbride Exp $ */
+
+/*
+ * Copyright (c) 2001 Daniel Hartmeier
+ * Copyright (c) 2002,2003 Henning Brauer
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *    - Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *    - Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Effort sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F30602-01-2-0537.
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#ifdef _KERNEL
+# include <sys/systm.h>
+#endif /* _KERNEL */
+#include <sys/mbuf.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/tcp.h>
+
+#include <net/if.h>
+#include <net/pfvar.h>
+
+#ifdef INET6
+#include <netinet/ip6.h>
+#endif /* INET6 */
+
+
+#ifdef _KERNEL
+# define DPFPRINTF(format, x...)		\
+	if (pf_status.debug >= PF_DEBUG_NOISY)	\
+		printf(format , ##x)
+#define rs_malloc(x)		malloc(x, M_TEMP, M_WAITOK)
+#define rs_free(x)		free(x, M_TEMP)
+
+#else
+/* Userland equivalents so we can lend code to pfctl et al. */
+
+# include <arpa/inet.h>
+# include <errno.h>
+# include <stdio.h>
+# include <stdlib.h>
+# include <string.h>
+# define rs_malloc(x)		 malloc(x)
+# define rs_free(x)		 free(x)
+
+# ifdef PFDEBUG
+#  include <sys/stdarg.h>
+#  define DPFPRINTF(format, x...)	fprintf(stderr, format , ##x)
+# else
+#  define DPFPRINTF(format, x...)	((void)0)
+# endif /* PFDEBUG */
+#endif /* _KERNEL */
+
+
+struct pf_anchor_global	 pf_anchors;
+struct pf_anchor	 pf_main_anchor;
+
+int			 pf_get_ruleset_number(u_int8_t);
+void			 pf_init_ruleset(struct pf_ruleset *);
+int			 pf_anchor_setup(struct pf_rule *,
+			    const struct pf_ruleset *, const char *);
+int			 pf_anchor_copyout(const struct pf_ruleset *,
+			    const struct pf_rule *, struct pfioc_rule *);
+void			 pf_anchor_remove(struct pf_rule *);
+
+static __inline int pf_anchor_compare(struct pf_anchor *, struct pf_anchor *);
+
+RB_GENERATE(pf_anchor_global, pf_anchor, entry_global, pf_anchor_compare);
+RB_GENERATE(pf_anchor_node, pf_anchor, entry_node, pf_anchor_compare);
+
+static __inline int
+pf_anchor_compare(struct pf_anchor *a, struct pf_anchor *b)
+{
+	int c = strcmp(a->path, b->path);
+
+	return (c ? (c < 0 ? -1 : 1) : 0);
+}
+
+int
+pf_get_ruleset_number(u_int8_t action)
+{
+	switch (action) {
+	case PF_SCRUB:
+	case PF_NOSCRUB:
+		return (PF_RULESET_SCRUB);
+		break;
+	case PF_PASS:
+	case PF_DROP:
+		return (PF_RULESET_FILTER);
+		break;
+	case PF_NAT:
+	case PF_NONAT:
+		return (PF_RULESET_NAT);
+		break;
+	case PF_BINAT:
+	case PF_NOBINAT:
+		return (PF_RULESET_BINAT);
+		break;
+	case PF_RDR:
+	case PF_NORDR:
+		return (PF_RULESET_RDR);
+		break;
+	default:
+		return (PF_RULESET_MAX);
+		break;
+	}
+}
+
+void
+pf_init_ruleset(struct pf_ruleset *ruleset)
+{
+	int	i;
+
+	memset(ruleset, 0, sizeof(struct pf_ruleset));
+	for (i = 0; i < PF_RULESET_MAX; i++) {
+		TAILQ_INIT(&ruleset->rules[i].queues[0]);
+		TAILQ_INIT(&ruleset->rules[i].queues[1]);
+		ruleset->rules[i].active.ptr = &ruleset->rules[i].queues[0];
+		ruleset->rules[i].inactive.ptr = &ruleset->rules[i].queues[1];
+	}
+}
+
+struct pf_anchor *
+pf_find_anchor(const char *path)
+{
+	struct pf_anchor	*key, *found;
+
+	key = (struct pf_anchor *)rs_malloc(sizeof(*key));
+	memset(key, 0, sizeof(*key));
+	strlcpy(key->path, path, sizeof(key->path));
+	found = RB_FIND(pf_anchor_global, &pf_anchors, key);
+	rs_free(key);
+	return (found);
+}
+
+struct pf_ruleset *
+pf_find_ruleset(const char *path)
+{
+	struct pf_anchor	*anchor;
+
+	while (*path == '/')
+		path++;
+	if (!*path)
+		return (&pf_main_ruleset);
+	anchor = pf_find_anchor(path);
+	if (anchor == NULL)
+		return (NULL);
+	else
+		return (&anchor->ruleset);
+}
+
+struct pf_ruleset *
+pf_find_or_create_ruleset(const char *path)
+{
+	char			*p, *q, *r;
+	struct pf_ruleset	*ruleset;
+	struct pf_anchor	*anchor, *dup, *parent = NULL;
+
+	if (path[0] == 0)
+		return (&pf_main_ruleset);
+	while (*path == '/')
+		path++;
+	ruleset = pf_find_ruleset(path);
+	if (ruleset != NULL)
+		return (ruleset);
+	p = (char *)rs_malloc(MAXPATHLEN);
+	bzero(p, MAXPATHLEN);
+	strlcpy(p, path, MAXPATHLEN);
+	while (parent == NULL && (q = strrchr(p, '/')) != NULL) {
+		*q = 0;
+		if ((ruleset = pf_find_ruleset(p)) != NULL) {
+			parent = ruleset->anchor;
+			break;
+		}
+	}
+	if (q == NULL)
+		q = p;
+	else
+		q++;
+	strlcpy(p, path, MAXPATHLEN);
+	if (!*q) {
+		rs_free(p);
+		return (NULL);
+	}
+	while ((r = strchr(q, '/')) != NULL || *q) {
+		if (r != NULL)
+			*r = 0;
+		if (!*q || strlen(q) >= PF_ANCHOR_NAME_SIZE ||
+		    (parent != NULL && strlen(parent->path) >=
+		    MAXPATHLEN - PF_ANCHOR_NAME_SIZE - 1)) {
+			rs_free(p);
+			return (NULL);
+		}
+		anchor = (struct pf_anchor *)rs_malloc(sizeof(*anchor));
+		if (anchor == NULL) {
+			rs_free(p);
+			return (NULL);
+		}
+		memset(anchor, 0, sizeof(*anchor));
+		RB_INIT(&anchor->children);
+		strlcpy(anchor->name, q, sizeof(anchor->name));
+		if (parent != NULL) {
+			strlcpy(anchor->path, parent->path,
+			    sizeof(anchor->path));
+			strlcat(anchor->path, "/", sizeof(anchor->path));
+		}
+		strlcat(anchor->path, anchor->name, sizeof(anchor->path));
+		if ((dup = RB_INSERT(pf_anchor_global, &pf_anchors, anchor)) !=
+		    NULL) {
+			printf("pf_find_or_create_ruleset: RB_INSERT1 "
+			    "'%s' '%s' collides with '%s' '%s'\n",
+			    anchor->path, anchor->name, dup->path, dup->name);
+			rs_free(anchor);
+			rs_free(p);
+			return (NULL);
+		}
+		if (parent != NULL) {
+			anchor->parent = parent;
+			if ((dup = RB_INSERT(pf_anchor_node, &parent->children,
+			    anchor)) != NULL) {
+				printf("pf_find_or_create_ruleset: "
+				    "RB_INSERT2 '%s' '%s' collides with "
+				    "'%s' '%s'\n", anchor->path, anchor->name,
+				    dup->path, dup->name);
+				RB_REMOVE(pf_anchor_global, &pf_anchors,
+				    anchor);
+				rs_free(anchor);
+				rs_free(p);
+				return (NULL);
+			}
+		}
+		pf_init_ruleset(&anchor->ruleset);
+		anchor->ruleset.anchor = anchor;
+		parent = anchor;
+		if (r != NULL)
+			q = r + 1;
+		else
+			*q = 0;
+	}
+	rs_free(p);
+	return (&anchor->ruleset);
+}
+
+void
+pf_remove_if_empty_ruleset(struct pf_ruleset *ruleset)
+{
+	struct pf_anchor	*parent;
+	int			 i;
+
+	while (ruleset != NULL) {
+		if (ruleset == &pf_main_ruleset || ruleset->anchor == NULL ||
+		    !RB_EMPTY(&ruleset->anchor->children) ||
+		    ruleset->anchor->refcnt > 0 || ruleset->tables > 0 ||
+		    ruleset->topen)
+			return;
+		for (i = 0; i < PF_RULESET_MAX; ++i)
+			if (!TAILQ_EMPTY(ruleset->rules[i].active.ptr) ||
+			    !TAILQ_EMPTY(ruleset->rules[i].inactive.ptr) ||
+			    ruleset->rules[i].inactive.open)
+				return;
+		RB_REMOVE(pf_anchor_global, &pf_anchors, ruleset->anchor);
+		if ((parent = ruleset->anchor->parent) != NULL)
+			RB_REMOVE(pf_anchor_node, &parent->children,
+			    ruleset->anchor);
+		rs_free(ruleset->anchor);
+		if (parent == NULL)
+			return;
+		ruleset = &parent->ruleset;
+	}
+}
+
+int
+pf_anchor_setup(struct pf_rule *r, const struct pf_ruleset *s,
+    const char *name)
+{
+	char			*p, *path;
+	struct pf_ruleset	*ruleset;
+
+	r->anchor = NULL;
+	r->anchor_relative = 0;
+	r->anchor_wildcard = 0;
+	if (!name[0])
+		return (0);
+	path = (char *)rs_malloc(MAXPATHLEN);
+	bzero(path, MAXPATHLEN);
+	if (name[0] == '/')
+		strlcpy(path, name + 1, MAXPATHLEN);
+	else {
+		/* relative path */
+		r->anchor_relative = 1;
+		if (s->anchor == NULL || !s->anchor->path[0])
+			path[0] = 0;
+		else
+			strlcpy(path, s->anchor->path, MAXPATHLEN);
+		while (name[0] == '.' && name[1] == '.' && name[2] == '/') {
+			if (!path[0]) {
+				printf("pf_anchor_setup: .. beyond root\n");
+				rs_free(path);
+				return (1);
+			}
+			if ((p = strrchr(path, '/')) != NULL)
+				*p = 0;
+			else
+				path[0] = 0;
+			r->anchor_relative++;
+			name += 3;
+		}
+		if (path[0])
+			strlcat(path, "/", MAXPATHLEN);
+		strlcat(path, name, MAXPATHLEN);
+	}
+	if ((p = strrchr(path, '/')) != NULL && !strcmp(p, "/*")) {
+		r->anchor_wildcard = 1;
+		*p = 0;
+	}
+	ruleset = pf_find_or_create_ruleset(path);
+	rs_free(path);
+	if (ruleset == NULL || ruleset->anchor == NULL) {
+		printf("pf_anchor_setup: ruleset\n");
+		return (1);
+	}
+	r->anchor = ruleset->anchor;
+	r->anchor->refcnt++;
+	return (0);
+}
+
+int
+pf_anchor_copyout(const struct pf_ruleset *rs, const struct pf_rule *r,
+    struct pfioc_rule *pr)
+{
+	pr->anchor_call[0] = 0;
+	if (r->anchor == NULL)
+		return (0);
+	if (!r->anchor_relative) {
+		strlcpy(pr->anchor_call, "/", sizeof(pr->anchor_call));
+		strlcat(pr->anchor_call, r->anchor->path,
+		    sizeof(pr->anchor_call));
+	} else {
+		char	*a, *p;
+		int	 i;
+
+		a = (char *)rs_malloc(MAXPATHLEN);
+		bzero(a, MAXPATHLEN);
+		if (rs->anchor == NULL)
+			a[0] = 0;
+		else
+			strlcpy(a, rs->anchor->path, MAXPATHLEN);
+		for (i = 1; i < r->anchor_relative; ++i) {
+			if ((p = strrchr(a, '/')) == NULL)
+				p = a;
+			*p = 0;
+			strlcat(pr->anchor_call, "../",
+			    sizeof(pr->anchor_call));
+		}
+		if (strncmp(a, r->anchor->path, strlen(a))) {
+			printf("pf_anchor_copyout: '%s' '%s'\n", a,
+			    r->anchor->path);
+			rs_free(a);
+			return (1);
+		}
+		if (strlen(r->anchor->path) > strlen(a))
+			strlcat(pr->anchor_call, r->anchor->path + (a[0] ?
+			    strlen(a) + 1 : 0), sizeof(pr->anchor_call));
+		rs_free(a);
+	}
+	if (r->anchor_wildcard)
+		strlcat(pr->anchor_call, pr->anchor_call[0] ? "/*" : "*",
+		    sizeof(pr->anchor_call));
+	return (0);
+}
+
+void
+pf_anchor_remove(struct pf_rule *r)
+{
+	if (r->anchor == NULL)
+		return;
+	if (r->anchor->refcnt <= 0) {
+		printf("pf_anchor_remove: broken refcount\n");
+		r->anchor = NULL;
+		return;
+	}
+	if (!--r->anchor->refcnt)
+		pf_remove_if_empty_ruleset(&r->anchor->ruleset);
+	r->anchor = NULL;
+}


monitor: manage pending modes

monitor: manage pending modes

--- sys/dev/netmap/netmap_monitor.c
+++ sys/dev/netmap/netmap_monitor.c
@@ -370,23 +370,32 @@
 				for (i = priv->np_qfirst[t]; i < priv->np_qlast[t]; i++) {
 					kring = &NMR(pna, t)[i];
 					mkring = &na->rx_rings[i];
-					netmap_monitor_add(mkring, kring, zmon);
+					if (nm_kring_pending_on(mkring)) {
+						netmap_monitor_add(mkring, kring, zmon);
+						mkring->nr_mode = NKR_NETMAP_ON;
+					}
 				}
 			}
 		}
 		na->na_flags |= NAF_NETMAP_ON;
 	} else {
-		if (pna == NULL) {
-			D("%s: parent left netmap mode, nothing to restore", na->name);
-			return 0;
-		}
-		na->na_flags &= ~NAF_NETMAP_ON;
+		if (na->active_fds == 0)
+			na->na_flags &= ~NAF_NETMAP_ON;
 		for_rx_tx(t) {
 			if (mna->flags & nm_txrx2flag(t)) {
 				for (i = priv->np_qfirst[t]; i < priv->np_qlast[t]; i++) {
-					kring = &NMR(pna, t)[i];
 					mkring = &na->rx_rings[i];
-					netmap_monitor_del(mkring, kring);
+					if (nm_kring_pending_off(mkring)) {
+						mkring->nr_mode = NKR_NETMAP_OFF;
+						/* we cannot access the parent krings if the parent
+						 * has left netmap mode. This is signaled by a NULL
+						 * pna pointer
+						 */
+						if (pna) {
+							kring = &NMR(pna, t)[i];
+							netmap_monitor_del(mkring, kring);
+						}
+					}
 				}
 			}
 		}


monitor: fix compilation

monitor: fix compilation


Add rcs Id

Add rcs Id

--- sys/gnu/i386/fpemul/control_w.h
+++ sys/gnu/i386/fpemul/control_w.h
@@ -43,6 +43,9 @@
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
+ *
+ *        $Id:$
+ *
  */

 #ifndef _CONTROLW_H_


fib: remove superfluous parameter

fib: remove superfluous parameter

--- sys/net/network_layer/fib/fib.c
+++ sys/net/network_layer/fib/fib.c
@@ -669,9 +669,9 @@
 * @brief Internal function:
 *        checks the lifetime and removes the entry in case it expired
 */
-static int fib_sr_check_lifetime(fib_sr_t *fib_sr, uint64_t *now)
-{
-    uint64_t tm = fib_sr->sr_lifetime - *now;
+static int fib_sr_check_lifetime(fib_sr_t *fib_sr)
+{
+    uint64_t tm = fib_sr->sr_lifetime - xtimer_now64();
     /* check if the lifetime expired */
     if ((int64_t)tm < 0) {
         /* remove this sr if its lifetime expired */
@@ -731,8 +731,6 @@
 int fib_sr_read_head(fib_table_t *table, fib_sr_t *fib_sr, kernel_pid_t *iface_id,
                      uint32_t *sr_flags, uint32_t *sr_lifetime)
 {
-    uint64_t now = xtimer_now64();
-
     mutex_lock(&(table->mtx_access));
     if ((fib_sr == NULL) || (iface_id == NULL) || (sr_flags == NULL)
         || (sr_lifetime == NULL) || (fib_is_sr_in_table(table, fib_sr) == -ENOENT) ) {
@@ -740,14 +738,14 @@
         return -EFAULT;
     }

-    if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) {
+    if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
         mutex_unlock(&(table->mtx_access));
         return -ENOENT;
     }

     *iface_id = fib_sr->sr_iface_id;
     *sr_flags = fib_sr->sr_flags;
-    *sr_lifetime = fib_sr->sr_lifetime - now;
+    *sr_lifetime = fib_sr->sr_lifetime - xtimer_now64();

     mutex_unlock(&(table->mtx_access));
     return 0;
@@ -756,8 +754,6 @@
 int fib_sr_read_destination(fib_table_t *table, fib_sr_t *fib_sr,
                             uint8_t *dst, size_t *dst_size)
 {
-    uint64_t now = xtimer_now64();
-
     mutex_lock(&(table->mtx_access));
     if ((fib_sr == NULL) || (dst == NULL) || (dst_size == NULL)
         || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
@@ -765,7 +761,7 @@
         return -EFAULT;
     }

-    if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) {
+    if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
         mutex_unlock(&(table->mtx_access));
         return -ENOENT;
     }
@@ -787,15 +783,13 @@
 int fib_sr_set(fib_table_t *table, fib_sr_t *fib_sr, kernel_pid_t *sr_iface_id,
                uint32_t *sr_flags, uint32_t *sr_lifetime)
 {
-    uint64_t now = xtimer_now64();
-
     mutex_lock(&(table->mtx_access));
     if ((fib_sr == NULL) || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
         mutex_unlock(&(table->mtx_access));
         return -EFAULT;
     }

-    if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) {
+    if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
         mutex_unlock(&(table->mtx_access));
         return -ENOENT;
     }
@@ -842,8 +836,6 @@

 int fib_sr_next(fib_table_t *table, fib_sr_t *fib_sr, fib_sr_entry_t **sr_path_entry)
 {
-    uint64_t now = xtimer_now64();
-
     mutex_lock(&(table->mtx_access));
     if ((fib_sr == NULL) || (sr_path_entry == NULL)
         || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
@@ -856,7 +848,7 @@
         return -EFAULT;
     }

-    if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) {
+    if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
         mutex_unlock(&(table->mtx_access));
         return -ENOENT;
     }
@@ -883,8 +875,6 @@
 int fib_sr_search(fib_table_t *table, fib_sr_t *fib_sr, uint8_t *addr, size_t addr_size,
                   fib_sr_entry_t **sr_path_entry)
 {
-    uint64_t now = xtimer_now64();
-
     mutex_lock(&(table->mtx_access));
     if ((fib_sr == NULL) || (addr == NULL) || (sr_path_entry == NULL)
         || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
@@ -892,7 +882,7 @@
         return -EFAULT;
     }

-    if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) {
+    if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
         mutex_unlock(&(table->mtx_access));
         return -ENOENT;
     }
@@ -918,8 +908,6 @@
 int fib_sr_entry_append(fib_table_t *table, fib_sr_t *fib_sr,
                         uint8_t *addr, size_t addr_size)
 {
-    uint64_t now = xtimer_now64();
-
     mutex_lock(&(table->mtx_access));
     if ((fib_sr == NULL) || (addr == NULL)
         || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
@@ -927,7 +915,7 @@
         return -EFAULT;
     }

-    if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) {
+    if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
         mutex_unlock(&(table->mtx_access));
         return -ENOENT;
     }
@@ -965,8 +953,6 @@
                      fib_sr_entry_t *sr_path_entry, uint8_t *addr, size_t addr_size,
                      bool keep_remaining_route)
 {
-    uint64_t now = xtimer_now64();
-
     mutex_lock(&(table->mtx_access));
     if ((fib_sr == NULL) || (sr_path_entry == NULL) || (addr == NULL)
         || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
@@ -974,7 +960,7 @@
         return -EFAULT;
     }

-    if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) {
+    if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
         mutex_unlock(&(table->mtx_access));
         return -ENOENT;
     }
@@ -1023,15 +1009,13 @@
 int fib_sr_entry_delete(fib_table_t *table, fib_sr_t *fib_sr, uint8_t *addr, size_t addr_size,
                         bool keep_remaining_route)
 {
-    uint64_t now = xtimer_now64();
-
     mutex_lock(&(table->mtx_access));
     if ((fib_sr == NULL) || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
         mutex_unlock(&(table->mtx_access));
         return -EFAULT;
     }

-    if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) {
+    if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
         mutex_unlock(&(table->mtx_access));
         return -ENOENT;
     }
@@ -1075,8 +1059,6 @@
                            uint8_t *addr_old, size_t addr_old_size,
                            uint8_t *addr_new, size_t addr_new_size)
 {
-    uint64_t now = xtimer_now64();
-
     mutex_lock(&(table->mtx_access));
     if ((fib_sr == NULL) || (addr_old == NULL) || (addr_new == NULL)
         || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
@@ -1084,7 +1066,7 @@
         return -EFAULT;
     }

-    if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) {
+    if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
         mutex_unlock(&(table->mtx_access));
         return -ENOENT;
     }
@@ -1127,15 +1109,13 @@
 int fib_sr_entry_get_address(fib_table_t *table, fib_sr_t *fib_sr, fib_sr_entry_t *sr_entry,
                              uint8_t *addr, size_t *addr_size)
 {
-    uint64_t now = xtimer_now64();
-
     mutex_lock(&(table->mtx_access));
     if ((fib_sr == NULL) || (fib_is_sr_in_table(table, fib_sr) == -ENOENT)) {
         mutex_unlock(&(table->mtx_access));
         return -EFAULT;
     }

-    if (fib_sr_check_lifetime(fib_sr, &now) == -ENOENT) {
+    if (fib_sr_check_lifetime(fib_sr) == -ENOENT) {
         mutex_unlock(&(table->mtx_access));
         return -ENOENT;
     }
@@ -1274,8 +1254,6 @@
                      uint8_t *addr_list, size_t *addr_list_elements, size_t *element_size,
                      bool reverse, fib_sr_t **fib_sr)
 {
-    uint64_t now = xtimer_now64();
-
     mutex_lock(&(table->mtx_access));

     if ((dst == NULL) || (sr_iface_id == NULL) || (sr_flags == NULL)
@@ -1292,7 +1270,7 @@
     /* Case 1 - check if we know a direct route */
     for (size_t i = 0; i < table->size; ++i) {

-        if (fib_sr_check_lifetime(&table->data.source_routes->headers[i], &now) == -ENOENT) {
+        if (fib_sr_check_lifetime(&table->data.source_routes->headers[i]) == -ENOENT) {
             /* expired, so skip this sr and remember its position */
             if (check_free_entry == -1) {
                 /* we want to fill up the source routes from the beginning */


Fix compile issue when RAND = UDEV.

Fix compile issue when RAND = UDEV.

--- src/rand/relic_rand_core.c
+++ src/rand/relic_rand_core.c
@@ -40,7 +40,7 @@
 #include "relic_md.h"
 #include "relic_err.h"

-#if SEED == DEV || SEED == UDEV
+#if RAND == UDEV || SEED == DEV || SEED == UDEV

 #include <sys/stat.h>
 #include <fcntl.h>


Delete mblbp-detect.h

Delete mblbp-detect.h

--- src/mblbp-detect.h
+++ src/mblbp-detect.h
@@ -1,46 +0,0 @@
-#ifndef __MBLBP_DETECT__
-#define __MBLBP_DETECT__
-
-#include <opencv/cv.h>
-
-#ifdef _OPENMP
-#include <omp.h>
-#endif
-
-typedef struct MBLBPWeak_
-{
-    int x;
-    int y;
-    int cellwidth;
-    int cellheight;
-    int* p[16]; // fast pointer
-    int look_up_table[59]; // look up table
-} MBLBPWeak;
-
-typedef struct MBLBPStage_
-{
-    int count;
-    int threshold;
-    MBLBPWeak * weak_classifiers;
-} MBLBPStage;
-
-typedef struct MBLBPCascade_
-{
-    int count;
-    int win_width;
-    int win_height;
-    int sum_image_step;
-    MBLBPStage * stages;
-} MBLBPCascade;
-
-MBLBPCascade * LoadMBLBPCascade(const char * filename );
-void ReleaseMBLBPCascade(MBLBPCascade ** ppCascade);
-
-CvSeq * MBLBPDetectMultiScale( const IplImage* img, //ͼ
-                               MBLBPCascade * pCascade, //
-                               CvMemStorage* storage, //ڴ
-                               int scale_factor1024x, //ɨ贰ϵǸ10241.1˴ӦΪ1024*1.1=1126
-                               int min_neighbors, //С
-                               int min_size, //Сɨ贰ڴСڿȣ
-							   int max_size=0); //ɨ贰ڴСڿȣ
-#endif


Removed useless preprocessor variable

Removed useless preprocessor variable

--- src/mem_io_start.c
+++ src/mem_io_start.c
@@ -83,7 +83,8 @@
     if (0 == strlen(params->domain_name))
         snprintf(hostname, MAX_LENGTH, "%s", nodename);
     else
-        snprintf(hostname, MAX_LENGTH, "%s.%s", nodename, DOMAIN_NAME);
+        snprintf(hostname, MAX_LENGTH, "%s.%s", nodename,
+                 params->domain_name);
     return hostname;
 }


Removed unnecessary variable declaration

--- src/mem_io_utils.h
+++ src/mem_io_utils.h
@@ -7,8 +7,6 @@
 #include "mem_io_cl_params.h"

 #define CHANNEL_ID_WIDTH 9
-
-extern char config_file_name[1024];

 redisContext *mem_io_connect(char host[], int port, int timeout_secs);
 void mem_io_auth(redisContext *context, char password[]);


Change prototype for TextureMemCpy to return void* (was void).

--- src/mesa/main/dd.h
+++ src/mesa/main/dd.h
@@ -525,7 +525,7 @@
     * from -- a pointer into client memory or a mesa temporary.
     * sz -- nr bytes to copy.
     */
-   void (*TextureMemCpy)( void *to, const void *from, size_t sz );
+   void* (*TextureMemCpy)( void *to, const void *from, size_t sz );

    /**
     * Called by glAreTextureResident().


mesa: minor reformatting/rewrapping in dd.h

--- src/mesa/main/dd.h
+++ src/mesa/main/dd.h
@@ -761,13 +761,13 @@

    /* May return NULL if MESA_MAP_NOWAIT_BIT is set in access:
     */
-   void * (*MapBufferRange)( GLcontext *ctx, GLenum target,
-                             GLintptr offset, GLsizeiptr length, GLbitfield access,
+   void * (*MapBufferRange)( GLcontext *ctx, GLenum target, GLintptr offset,
+                             GLsizeiptr length, GLbitfield access,
                              struct gl_buffer_object *obj);

-   void (*FlushMappedBufferRange) (GLcontext *ctx, GLenum target,
-                                   GLintptr offset, GLsizeiptr length,
-                                   struct gl_buffer_object *obj);
+   void (*FlushMappedBufferRange)(GLcontext *ctx, GLenum target,
+                                  GLintptr offset, GLsizeiptr length,
+                                  struct gl_buffer_object *obj);

    GLboolean (*UnmapBuffer)( GLcontext *ctx, GLenum target,
 			     struct gl_buffer_object *obj );
@@ -782,7 +782,8 @@
    struct gl_framebuffer * (*NewFramebuffer)(GLcontext *ctx, GLuint name);
    struct gl_renderbuffer * (*NewRenderbuffer)(GLcontext *ctx, GLuint name);
    void (*BindFramebuffer)(GLcontext *ctx, GLenum target,
-                           struct gl_framebuffer *fb, struct gl_framebuffer *fbread);
+                           struct gl_framebuffer *drawFb,
+                           struct gl_framebuffer *readFb);
    void (*FramebufferRenderbuffer)(GLcontext *ctx,
                                    struct gl_framebuffer *fb,
                                    GLenum attachment,


Added transfer annotation

Added transfer annotation

--- src/midgard_user.c
+++ src/midgard_user.c
@@ -203,7 +203,7 @@
  * </para></listitem>
  * </itemizedlist>
  *
- * Returns: new #MidgardUser instance or %NULL in case of failure
+ * Returns: (transfer full): new #MidgardUser instance or %NULL in case of failure
  *
  * Since 9.09
  */
@@ -294,7 +294,7 @@
  *
  * Returned array should be freed (g_free()) when no longer needed.
  *
- * Returns: newly allocated and NULL terminated array of #MidgardUser objects or %NULL
+ * Returns: (transfer full): newly allocated and NULL terminated array of #MidgardUser objects or %NULL
  *
  * Since 9.09
  */


Initialize new member X86Operand::FrontendSize in all codepaths.

This fixes MSAN-builds after r302179.

git-svn-id: 0ff597fd157e6f4fc38580e8d64ab130330d2411@302214 91177308-0d34-0410-b5e6-96231b3b80d8

--- lib/Target/X86/AsmParser/X86Operand.h
+++ lib/Target/X86/AsmParser/X86Operand.h
@@ -520,7 +520,7 @@
   static std::unique_ptr<X86Operand>
   CreateMem(unsigned ModeSize, const MCExpr *Disp, SMLoc StartLoc, SMLoc EndLoc,
             unsigned Size = 0, StringRef SymName = StringRef(),
-            void *OpDecl = nullptr) {
+            void *OpDecl = nullptr, unsigned FrontendSize = 0) {
     auto Res = llvm::make_unique<X86Operand>(Memory, StartLoc, EndLoc);
     Res->Mem.SegReg   = 0;
     Res->Mem.Disp     = Disp;
@@ -529,6 +529,7 @@
     Res->Mem.Scale    = 1;
     Res->Mem.Size     = Size;
     Res->Mem.ModeSize = ModeSize;
+    Res->Mem.FrontendSize = FrontendSize;
     Res->SymName      = SymName;
     Res->OpDecl       = OpDecl;
     Res->AddressOf    = false;


Wrap the header in the opencog namespace rather than using

Otherwise including that file silently declare using opencog (and even
worse std). That defeats the purpose of having a namespace.

Also move the using namespace std inside the opencog namespace, that
way at least one needs to using the opencog name in order to using std
as well, it's not ideal (ideally using namespace std should not be in
a header, but it limits the chances of name clash).

--- opencog/reasoning/RuleEngine/rule-engine-src/Rule.h
+++ opencog/reasoning/RuleEngine/rule-engine-src/Rule.h
@@ -26,7 +26,8 @@

 #include <opencog/atomspace/AtomSpace.h>

-using namespace opencog;
+namespace opencog {
+
 using namespace std;

 /**
@@ -73,4 +74,7 @@

 	Handle standardize_helper(Handle, std::map<Handle, Handle>&);
 };
+
+} // ~namespace opencog
+
 #endif /* RULE_H_ */


Fixed stuff, using struct & methods rather than union.

--- src/midi_UsbDefs.h
+++ src/midi_UsbDefs.h
@@ -28,7 +28,7 @@

 #pragma once

-#include "midi_Namespace.h"
+#include "midi_Defs.h"

 BEGIN_MIDI_NAMESPACE

@@ -69,9 +69,10 @@
             case noteOff:
             case controlChange:
             case pitchBend:
-            case polyKeyPress:
+            case polyPressure:
             case systemCommon3Bytes:
             case sysExEnds3Bytes:
+            case sysExStart:
                 return 3;

             case programChange:
@@ -87,7 +88,7 @@
             default:
                 break;
         }
-        return 0;
+        return 0; // Can be any length (1, 2 or 3).
     }
 };

@@ -95,17 +96,50 @@

 struct UsbMidiEventPacket
 {
-    union
+public:
+    inline UsbMidiEventPacket()
     {
-        uint32_t    mRawData;
-        struct
-        {
-            byte mCableNumber:4;
-            byte mCodeIndexNumber:4;
-            byte mMidi[3];
-        };
-        byte     mDataArray[4];
-    };
+        memset(mData, 0, 4 * sizeof(byte));
+    }
+
+public:
+    inline void setHeader(byte inCableNumber, byte inCodeIndexNumber)
+    {
+        const byte msb = (0x0f & inCableNumber) << 4;
+        const byte lsb = (0x0f & inCodeIndexNumber);
+        mData[0] = msb | lsb;
+    }
+    inline void setMidiData(const byte* inData)
+    {
+        mData[1] = *inData++;
+        mData[2] = *inData++;
+        mData[3] = *inData;
+    }
+    inline byte getCableNumber() const
+    {
+        return mData[0] >> 4;
+    }
+    inline byte getCodeIndexNumber() const
+    {
+        return mData[0] & 0x0f;
+    }
+    inline const byte* getMidiData() const
+    {
+        return mData + 1;
+    }
+    inline byte* getMidiData()
+    {
+        return mData + 1;
+    }
+    inline UsbMidiEventPacket& operator=(const byte* inData)
+    {
+        mData[0] = *inData++;
+        setMidiData(inData);
+        return *this;
+    }
+
+public:
+    byte mData[4];
 };

 END_MIDI_NAMESPACE


Win32: fix race condition initializing static mutexes

--- src/misc/threads.c
+++ src/misc/threads.c
@@ -360,7 +360,8 @@
         assert (p_mutex != &super_mutex); /* this one cannot be static */

         vlc_mutex_lock (&super_mutex);
-        vlc_mutex_init (p_mutex);
+        if (InterlockedCompareExchange (&p_mutex->initialized, 0, 0) == 0)
+            vlc_mutex_init (p_mutex);
         /* FIXME: destroy the mutex some time... */
         vlc_mutex_unlock (&super_mutex);
     }


Win32 threads: Set priority on success rather than failure. Patch from atmo.

--- src/misc/threads.c
+++ src/misc/threads.c
@@ -591,12 +591,12 @@
 #endif
         p_priv->thread_id.id = (DWORD)threadId;
         p_priv->thread_id.hThread = (HANDLE)hThread;
-    ResumeThread((HANDLE)hThread);
+        ResumeThread((HANDLE)hThread);
     }

     i_ret = ( p_priv->thread_id.hThread ? 0 : 1 );

-    if( i_ret && i_priority )
+    if( !i_ret && i_priority )
     {
         if( !SetThreadPriority(p_priv->thread_id.hThread, i_priority) )
         {


解决Linux下编译失败的问题

解决Linux下编译失败的问题

--- code/logger/inc/Logger.h
+++ code/logger/inc/Logger.h
@@ -7,6 +7,7 @@
 #define POPPY_LOGGER_LOGGER_H

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

 #include <string>


Use return value of EnsureUTF8() to specify whether the bytes sequence was valid (UTF-8) or not (incomplete, incorrect non-ASCII, or overlong sequences)


Remote driver CPU flags support

Remote driver CPU flags support

* src/remote/remote_driver.c: add the new entry point

--- src/remote/remote_driver.c
+++ src/remote/remote_driver.c
@@ -7462,6 +7462,33 @@
 done:
     remoteDriverUnlock(priv);

+    return rv;
+}
+
+
+static int
+remoteCPUCompare(virConnectPtr conn, const char *xmlDesc,
+                 unsigned int flags ATTRIBUTE_UNUSED)
+{
+    struct private_data *priv = conn->privateData;
+    remote_cpu_compare_args args;
+    remote_cpu_compare_ret ret;
+    int rv = VIR_CPU_COMPARE_ERROR;
+
+    remoteDriverLock(priv);
+
+    args.xml = (char *) xmlDesc;
+
+    memset(&ret, 0, sizeof (ret));
+    if (call(conn, priv, 0, REMOTE_PROC_CPU_COMPARE,
+             (xdrproc_t) xdr_remote_cpu_compare_args, (char *) &args,
+             (xdrproc_t) xdr_remote_cpu_compare_ret, (char *) &ret) == -1)
+        goto done;
+
+    rv = ret.result;
+
+done:
+    remoteDriverUnlock(priv);
     return rv;
 }

@@ -8830,7 +8857,7 @@
     remoteIsSecure, /* isSecure */
     remoteDomainIsActive, /* domainIsActive */
     remoteDomainIsPersistent, /* domainIsPersistent */
-    NULL, /* cpuCompare */
+    remoteCPUCompare, /* cpuCompare */
 };

 static virNetworkDriver network_driver = {


CLI: Handle consoles reporting zero size

For whatever reason, in the buildbot environment the TIOCGWINSZ
ioctl returns a 0x0 size, which causes a divide by zero. We
handle this by returning a default 80x24 size.

Closes: #2685
Approved by: alexlarsson

--- common/flatpak-utils.c
+++ common/flatpak-utils.c
@@ -6078,6 +6078,11 @@

   if (ioctl (STDOUT_FILENO, TIOCGWINSZ, &w) == 0)
     {
+      /* For whatever reason, in buildbot this returns 0, 0 so add a fallback */
+      if (w.ws_row == 0)
+        w.ws_row = 24;
+      if (w.ws_col == 0)
+        w.ws_col = 80;
       *rows = w.ws_row;
       *cols = w.ws_col;
     }


Now allows to limit the translation of  a Yahoo! name to a TA-Lib name convention using only the Yahoo! extension. Behavior before was to go onine when the extension was not recognized or existant.

git-svn-id: 33305d871a58cfd02b407b81d5206d2a785211eb@12 159cb52c-178a-4f3c-8eb8-d0aff033d058

--- c/src/ta_data/ta_source/ta_yahoo/ta_yahoo_priv.h
+++ c/src/ta_data/ta_source/ta_yahoo/ta_yahoo_priv.h
@@ -115,9 +115,16 @@
  * On success, both strings must be freed with TA_StringFree.
  * On failure, no string are allocated.
  *
- * This function is not speed optimized and usage of it
- * shall be carefully considered. Some translation requires
- * further online investigation (fetching of webPage).
+ * When the Yahoo! symbol is a known extension, this call
+ * is quite fast, but in the case that there is no extension
+ * further online investigation is required (fetching of webPage).
+ *
+ * Because this online investigation can be quite costly,
+ * in terms of time, the parameter allowOnlineProcessing
+ * must be true for allowing such investigation.
+ *
+ * In practice, only US symbols needs further investigation
+ * because many do not have an extension (by default I guess).
  *
  * On success, the allocated strings must be eventually freed
  * with TA_StringFree.
@@ -145,7 +152,9 @@
                                         TA_DecodingParam *info,
                                         const char *yahooSymbol,
                                         TA_String **allocatedCategoryName,
-                                        TA_String **allocatedSymbolName );
+                                        TA_String **allocatedSymbolName,
+                                        unsigned int allowOnlineProcessing );
+

 /* Providing a Category and Symbol name, the Yahoo! Symbol is rebuild.
  * TA_AllocStringFromLibName() is the complement of the function


o plan

o plan

--- common/rptqueue.test.c
+++ common/rptqueue.test.c
@@ -1,6 +1,7 @@
 #include "rptqueue.h"
 #include "test.h"
 #include <unistd.h>
+#include <stdio.h>

 static char display[24] = ".......................";
 int main (void)
@@ -19,7 +20,7 @@
   }
   rpt.ifd = pipeto[0];
   rpt.ofd = pipefrom[1];
-
+  printf("1..5\n");
   rpt_init(&rpt);
   upk_test_is(rpt.dlen, 23, "right length for display");
   rpt_write_status(&rpt,"abcdefghijklmnop");


Always check for read/write errors, and propagate them. Also, most functions now properly return -1 on error (some return a Boolean to indicate success, some return NULL on error).

--- common/stream/stream.c
+++ common/stream/stream.c
@@ -174,7 +174,7 @@
 /* #define BSTREAM_DEBUG 1 */

 /* Read at most cnt elements of size elmsize from the stream.  Returns
-   the number of elements actually read. */
+ * the number of elements actually read or < 0 on failure. */
 ssize_t
 mnstr_read(stream *s, void *buf, size_t elmsize, size_t cnt)
 {
@@ -183,12 +183,13 @@
 #endif
 	assert(s->access == ST_READ);
 	if (s->errnr)
-		return s->errnr;
+		return -1;
 	return (*s->read) (s, buf, elmsize, cnt);
 }

-/* Read one line (seperated by \n) of atmost maxcnt characters from the stream.
-   Returns the number of characters actually read, includes the trailing \n */
+/* Read one line (seperated by \n) of atmost maxcnt characters from
+ * the stream.  Returns the number of characters actually read,
+ * includes the trailing \n */
 ssize_t
 mnstr_readline(stream *s, void *buf, size_t maxcnt)
 {
@@ -197,7 +198,7 @@
 #endif
 	assert(s->access == ST_READ);
 	if (s->errnr)
-		return s->errnr;
+		return -1;
 	if (!s->readline) {
 		size_t len = 0;
 		char *b = buf, *start = buf;
@@ -206,15 +207,15 @@
 				break;
 		}
 		if (s->errnr)
-			return s->errnr;
+			return -1;
 		return (ssize_t) (start - b);
 	} else
 		return (*s->readline) (s, buf, maxcnt);
 }

 /* Write cnt elements of size elmsize to the stream.  Returns the
-   number of elements actually written.  If elmsize or cnt equals zero,
-   returns cnt. */
+ * number of elements actually written.  If elmsize or cnt equals zero,
+ * returns cnt. */
 ssize_t
 mnstr_write(stream *s, const void *buf, size_t elmsize, size_t cnt)
 {
@@ -223,7 +224,7 @@
 #endif
 	assert(s->access == ST_WRITE);
 	if (s->errnr)
-		return s->errnr;
+		return -1;
 	return (*s->write) (s, buf, elmsize, cnt);
 }

@@ -265,6 +266,7 @@
 	return (*s->error) (s);
 }

+/* flush buffer, return 0 on success, non-zero on failure */
 int
 mnstr_flush(stream *s)
 {
@@ -275,12 +277,13 @@
 #endif
 	assert(s->access == ST_WRITE);
 	if (s->errnr)
-		return s->errnr;
+		return -1;
 	if (s->flush)
 		return (*s->flush) (s);
 	return 0;
 }

+/* sync file to disk, return 0 on success, non-zero on failure */
 int
 mnstr_fsync(stream *s)
 {
@@ -291,7 +294,7 @@
 #endif
 	assert(s->access == ST_WRITE);
 	if (s->errnr)
-		return s->errnr;
+		return -1;
 	if (s->fsync)
 		return (*s->fsync) (s);
 	return 0;
@@ -306,7 +309,7 @@
 	printf("fgetpos %s\n", s->name ? s->name : "<unnamed>");
 #endif
 	if (s->errnr)
-		return s->errnr;
+		return -1;
 	if (s->fgetpos)
 		return (*s->fgetpos) (s, p);
 	return 0;
@@ -321,7 +324,7 @@
 	printf("fsetpos %s\n", s->name ? s->name : "<unnamed>");
 #endif
 	if (s->errnr)
-		return s->errnr;
+		return -1;
 	if (s->fsetpos)
 		return (*s->fsetpos) (s, p);
 	return 0;
@@ -494,8 +497,10 @@

 	if (!feof(fp)) {
 		rc = fread(buf, elmsize, cnt, fp);
-		if (ferror(fp))
+		if (ferror(fp)) {
 			s->errnr = MNSTR_READ_ERROR;
+			return -1;
+		}
 	}
 	return (ssize_t) rc;
 }
@@ -506,8 +511,10 @@
 	if (elmsize && cnt) {
 		size_t rc = fwrite(buf, elmsize, cnt, (FILE *) s->stream_data.p);

-		if (rc < cnt)
+		if (ferror((FILE *) s->stream_data.p)) {
 			s->errnr = MNSTR_WRITE_ERROR;
+			return -1;
+		}
 		return (ssize_t) rc;
 	}
 	return (ssize_t) cnt;
@@ -537,7 +544,7 @@

 	if (s->access == ST_WRITE && fflush(fp) < 0) {
 		s->errnr = MNSTR_WRITE_ERROR;
-		return 1;
+		return -1;
 	}
 	return 0;
 }
@@ -562,7 +569,7 @@
 #endif
 	    ) {
 		s->errnr = MNSTR_WRITE_ERROR;
-		return 1;
+		return -1;
 	}
 	return 0;
 }
@@ -581,7 +588,7 @@
 	*p = (lng) ftell(fp);	/* returns long */
 #endif
 #endif
-	return 0;
+	return *p < 0 ? -1 : 0;
 }

 static int
@@ -657,11 +664,15 @@
 {
 	gzFile fp = (gzFile) s->stream_data.p;
 	int size = (int) (elmsize * cnt);
+	int err;

 	if (!gzeof(fp)) {
 		size = gzread(fp, buf, size);
-		if (size)
-			return (ssize_t) (size / elmsize);
+		if (gzerror(fp, &err) != NULL) {
+			s->errnr = MNSTR_READ_ERROR;
+			return -1;
+		}
+		return (ssize_t) (size / elmsize);
 	}
 	return 0;
 }
@@ -669,10 +680,16 @@
 static ssize_t
 stream_gzwrite(stream *s, const void *buf, size_t elmsize, size_t cnt)
 {
+	gzFile fp = (gzFile) s->stream_data.p;
 	int size = (int) (elmsize * cnt);
+	int err;

 	if (size) {
-		size = gzwrite((gzFile) s->stream_data.p, buf, size);
+		size = gzwrite(fp, buf, size);
+		if (gzerror(fp, &err) != NULL) {
+			s->errnr = MNSTR_WRITE_ERROR;
+			return -1;
+		}
 		return (ssize_t) (size / elmsize);
 	}
 	return (ssize_t) cnt;
@@ -689,8 +706,9 @@
 static int
 stream_gzflush(stream *s)
 {
-	if (s->access == ST_WRITE)
-		gzflush((gzFile) s->stream_data.p, Z_SYNC_FLUSH);
+	if (s->access == ST_WRITE &&
+	    gzflush((gzFile) s->stream_data.p, Z_SYNC_FLUSH) != Z_OK)
+		return -1;
 	return 0;
 }

@@ -737,8 +755,11 @@
 		return NULL;
 	s->access = ST_WRITE;
 	s->type = ST_BIN;
-	if (s->errnr == MNSTR_NO__ERROR)
-		gzwrite((gzFile) s->stream_data.p, (void *) &s->byteorder, sizeof(s->byteorder));
+	if (s->errnr == MNSTR_NO__ERROR &&
+	    gzwrite((gzFile) s->stream_data.p, (void *) &s->byteorder, sizeof(s->byteorder)) < (int) sizeof(s->byteorder)) {
+		stream_gzclose(s);
+		s->errnr = MNSTR_OPEN_ERROR;
+	}
 	return s;
 }

@@ -847,8 +868,11 @@
 				stream_bzclose(s);
 			}
 		}
-		if (err == BZ_OK)
-			return size / elmsize;
+		if (err != BZ_OK) {
+			s->errnr = MNSTR_READ_ERROR;
+			return -1;
+		}
+		return size / elmsize;
 	}
 	return 0;
 }
@@ -861,8 +885,11 @@

 	if (size) {
 		BZ2_bzWrite(&err, ((struct bz *) s->stream_data.p)->b, (void *) buf, size);
-		if (err == BZ_OK)
-			return cnt;
+		if (err != BZ_OK) {
+			s->errnr = MNSTR_WRITE_ERROR;
+			return -1;
+		}
+		return cnt;
 	}
 	return 0;
 }
@@ -928,8 +955,11 @@
 		return NULL;
 	s->access = ST_WRITE;
 	s->type = ST_BIN;
-	if (s->errnr == MNSTR_NO__ERROR)
-		stream_bzwrite(s, (void *) &s->byteorder, sizeof(s->byteorder), 1);
+	if (s->errnr == MNSTR_NO__ERROR &&
+	    stream_bzwrite(s, (void *) &s->byteorder, sizeof(s->byteorder), 1) != 1) {
+		stream_bzclose(s);
+		s->errnr = MNSTR_OPEN_ERROR;
+	}
 	return s;
 }

@@ -1004,18 +1034,14 @@
 #ifdef HAVE_LIBZ
 		return open_gzrstream(filename);
 #else
-		if ((s = create_stream(filename)) != NULL)
-			s->errnr = MNSTR_OPEN_ERROR;
-		return s;
+		return NULL;	/* not supported */
 #endif
 	}
 	if (strcmp(ext, "bz2") == 0) {
 #ifdef HAVE_LIBBZ2
 		return open_bzrstream(filename);
 #else
-		if ((s = create_stream(filename)) != NULL)
-			s->errnr = MNSTR_OPEN_ERROR;
-		return s;
+		return NULL;	/* not supported */
 #endif
 	}
 	if ((s = open_stream(filename, "rb")) == NULL)
@@ -1047,18 +1073,14 @@
 #ifdef HAVE_LIBZ
 		return open_gzwstream_(filename, mode);
 #else
-		if ((s = create_stream(filename)) != NULL)
-			s->errnr = MNSTR_OPEN_ERROR;
-		return s;
+		return NULL;	/* not supported */
 #endif
 	}
 	if (strcmp(ext, "bz2") == 0) {
 #ifdef HAVE_LIBBZ2
 		return open_bzwstream_(filename, mode);
 #else
-		if ((s = create_stream(filename)) != NULL)
-			s->errnr = MNSTR_OPEN_ERROR;
-		return s;
+		return NULL;	/* not supported */
 #endif
 	}
 	if ((s = open_stream(filename, mode)) == NULL)
@@ -1098,18 +1120,14 @@
 #ifdef HAVE_LIBZ
 		return open_gzrastream(filename);
 #else
-		if ((s = create_stream(filename)) != NULL)
-			s->errnr = MNSTR_OPEN_ERROR;
-		return s;
+		return NULL;	/* not supported */
 #endif
 	}
 	if (strcmp(ext, "bz2") == 0) {
 #ifdef HAVE_LIBBZ2
 		return open_bzrastream(filename);
 #else
-		if ((s = create_stream(filename)) != NULL)
-			s->errnr = MNSTR_OPEN_ERROR;
-		return s;
+		return NULL;	/* not supported */
 #endif
 	}
 	if ((s = open_stream(filename, "r")) == NULL)
@@ -1133,18 +1151,14 @@
 #ifdef HAVE_LIBZ
 		return open_gzwastream_(filename, mode);
 #else
-		if ((s = create_stream(filename)) != NULL)
-			s->errnr = MNSTR_OPEN_ERROR;
-		return s;
+		return NULL;	/* not supported */
 #endif
 	}
 	if (strcmp(ext, "bz2") == 0) {
 #ifdef HAVE_LIBBZ2
 		return open_bzwastream_(filename, mode);
 #else
-		if ((s = create_stream(filename)) != NULL)
-			s->errnr = MNSTR_OPEN_ERROR;
-		return s;
+		return NULL;	/* not supported */
 #endif
 	}
 	if ((s = open_stream(filename, mode)) == NULL)
@@ -1276,8 +1290,8 @@

 	if (c->usesize - c->offset >= elmsize || !c->running) {
 		/* there is at least one element's worth of data
-		   available, or we have reached the end: return as
-		   much as we have, but no more than requested */
+		 * available, or we have reached the end: return as
+		 * much as we have, but no more than requested */
 		if (cnt * elmsize > c->usesize - c->offset)
 			cnt = (c->usesize - c->offset) / elmsize;
 		size = cnt * elmsize;
@@ -1422,11 +1436,14 @@
 	       (
 #ifdef NATIVE_WIN32
 		/* send works on int, make sure the argument fits */
-		((nr = send(s->stream_data.s, (void *) ((char *) buf + res), (int) min(size - res, 1 << 16), 0)) > 0)
+		((nr = send(s->stream_data.s, (void *) ((char *) buf + res),
+			    (int) min(size - res, 1 << 16), 0)) > 0)
 #else
-		((nr = write(s->stream_data.s, ((const char *) buf + res), size - res)) > 0)
-#endif
-		|| (s->timeout == 0 && (errno == EAGAIN || errno == EWOULDBLOCK))
+		((nr = write(s->stream_data.s, ((const char *) buf + res),
+			     size - res)) > 0)
+#endif
+		|| (s->timeout == 0
+		    && (errno == EAGAIN || errno == EWOULDBLOCK))
 		|| errno == EINTR)
 		) {
 		errno = 0;
@@ -1435,7 +1452,7 @@
 	}
 	if (nr < 0) {
 		s->errnr = MNSTR_WRITE_ERROR;
-		return nr;
+		return -1;
 	}
 	if (res > 0)
 		return (ssize_t) (res / elmsize);
@@ -1449,18 +1466,21 @@
 	ssize_t nr = 0, res = 0, size = (ssize_t) (elmsize * cnt);

 	if (!s || s->errnr)
-		return (-1);
+		return -1;

 	errno = 0;
 	while (res < size &&
 	       (
 #ifdef NATIVE_WIN32
 		/* recv works on int, make sure the argument fits */
-		((nr = recv(s->stream_data.s, (void *) ((char *) buf + res), (int) min(size - res, 1 << 16), 0)) > 0)
+		((nr = recv(s->stream_data.s, (void *) ((char *) buf + res),
+			    (int) min(size - res, 1 << 16), 0)) > 0)
 #else
-		((nr = read(s->stream_data.s, (void *) ((char *) buf + res), size - res)) > 0)
-#endif
-		|| (s->timeout == 0 && (errno == EAGAIN || errno == EWOULDBLOCK))
+		((nr = read(s->stream_data.s, (void *) ((char *) buf + res),
+			    size - res)) > 0)
+#endif
+		|| (s->timeout == 0
+		    && (errno == EAGAIN || errno == EWOULDBLOCK))
 		|| errno == EINTR)
 		) {
 		errno = 0;
@@ -1469,14 +1489,14 @@
 	}
 	if (nr < 0) {
 		s->errnr = MNSTR_READ_ERROR;
-		return nr;
+		return -1;
 	}
 	return (ssize_t) (res / elmsize);
 }

-/* Read one line (seperated by \n) of at most maxcnt characters from the
-   stream. Returns the number of characters actually read, includes the
-   trailing \n. */
+/* Read one line (seperated by \n) of at most maxcnt characters from the
+ * stream. Returns the number of characters actually read, includes the
+ * trailing \n. */
 static ssize_t
 socket_readline(stream *s, void *buf, size_t maxcnt)
 {
@@ -1487,7 +1507,7 @@
 			break;
 	}
 	if (s->errnr)
-		return s->errnr;
+		return -1;
 	return (ssize_t) (start - b);
 }

@@ -1618,8 +1638,11 @@
 		return NULL;
 	s->access = ST_WRITE;
 	s->type = ST_BIN;
-	if (s->errnr == MNSTR_NO__ERROR)
-		socket_write(s, (void *) &s->byteorder, sizeof(s->byteorder), 1);
+	if (s->errnr == MNSTR_NO__ERROR &&
+	    socket_write(s, (void *) &s->byteorder, sizeof(s->byteorder), 1) < 1) {
+		socket_close(s);
+		s->errnr = MNSTR_OPEN_ERROR;
+	}
 	return s;
 }

@@ -1696,7 +1719,7 @@
 	udp_stream *udp;

 	if (!s || s->errnr)
-		return (-1);
+		return -1;

 	udp = s->stream_data.p;
 	errno = 0;
@@ -1764,7 +1787,7 @@

 	hp = gethostbyname(hostname);
 	if (hp == NULL)
-		return 0;
+		return -1;

 	memset(&udp->addr, 0, sizeof(udp->addr));
 	if (write)
@@ -1777,10 +1800,10 @@
 	servsize = (socklen_t) sizeof(udp->addr);
 	udp->s = socket(serv->sa_family, SOCK_DGRAM, IPPROTO_UDP);
 	if (udp->s == INVALID_SOCKET)
-		return 0;
+		return -1;
 	if (!write && bind(udp->s, serv, servsize) < 0)
-		return 0;
-	return 1;
+		return -1;
+	return 0;
 }

 stream *
@@ -1791,9 +1814,9 @@
 #ifdef STREAM_DEBUG
 	printf("udp_rawastream %s %s\n", hostname, name);
 #endif
-	if (!s)
-		return NULL;
-	if (!udp_socket(s->stream_data.p, hostname, port, 0)) {
+	if (s == NULL)
+		return NULL;
+	if (udp_socket(s->stream_data.p, hostname, port, 0) < 0) {
 		udp_destroy(s);
 		return NULL;
 	}
@@ -1809,9 +1832,9 @@
 #ifdef STREAM_DEBUG
 	printf("udp_wastream %s %s\n", hostname, name);
 #endif
-	if (!s)
-		return NULL;
-	if (!udp_socket(s->stream_data.p, hostname, port, 1)) {
+	if (s == NULL)
+		return NULL;
+	if (udp_socket(s->stream_data.p, hostname, port, 1) < 0) {
 		udp_destroy(s);
 		return NULL;
 	}
@@ -1853,16 +1876,14 @@
 	s->type = ST_BIN;
 	if (fp == NULL)
 		s->errnr = MNSTR_OPEN_ERROR;
+
+	if (s->errnr == MNSTR_NO__ERROR &&
+	    (fread((void *) &s->byteorder, sizeof(s->byteorder), 1, fp) < 1 ||
+	     ferror(fp))) {
+		fclose(fp);
+		s->errnr = MNSTR_OPEN_ERROR;
+	}
 	s->stream_data.p = (void *) fp;
-
-	if (s->errnr == MNSTR_NO__ERROR) {
-		if (fread((void *) &s->byteorder, sizeof(s->byteorder), 1, fp) < 1 ||
-		    ferror(fp)) {
-			fclose(fp);
-			s->stream_data.p = NULL;
-			s->errnr = MNSTR_OPEN_ERROR;
-		}
-	}
 	return s;
 }

@@ -1880,13 +1901,14 @@
 	s->type = ST_BIN;
 	if (fp == NULL)
 		s->errnr = MNSTR_OPEN_ERROR;
+
+	if (s->errnr == MNSTR_NO__ERROR &&
+	    (fwrite((void *) &s->byteorder, sizeof(s->byteorder), 1, fp) < 1 ||
+	     ferror(fp))) {
+		fclose(fp);
+		s->errnr = MNSTR_OPEN_ERROR;
+	}
 	s->stream_data.p = (void *) fp;
-
-	if (s->errnr == MNSTR_NO__ERROR) {
-		if (fwrite((void *) &s->byteorder, sizeof(s->byteorder), 1, fp) < 1 ||
-		    ferror(fp))
-			s->errnr = MNSTR_OPEN_ERROR;
-	}
 	return s;
 }

@@ -1951,13 +1973,12 @@
 	char *bf = NULL;

 	/* if unconverted data from a previous call remains, add it to
-	   the start of the new data, using temporary space */
+	 * the start of the new data, using temporary space */
 	if (ic->buflen > 0) {
 		bf = malloc(ic->buflen + inbytesleft);
 		if (bf == NULL) {
 			/* cannot allocate memory */
-			s->errnr = MNSTR_WRITE_ERROR;
-			return -1;
+			goto bailout;
 		}
 		memcpy(bf, ic->buffer, ic->buflen);
 		memcpy(bf + ic->buflen, buf, inbytesleft);
@@ -1973,22 +1994,21 @@
 			switch (errno) {
 			case EILSEQ:
 				/* invalid multibyte sequence encountered */
-				s->errnr = MNSTR_WRITE_ERROR;
-				if (bf)
-					free(bf);
-				return -1;
+				goto bailout;
 			case EINVAL:
-				/* incomplete multibyte sequence encountered */
-				/* flush what has been converted */
-				if (outbytesleft < sizeof(ic->buffer))
-					mnstr_write(ic->s, ic->buffer, 1, sizeof(ic->buffer) - outbytesleft);
+				/* incomplete multibyte sequence
+				 * encountered flush what has been
+				 * converted */
+				if (outbytesleft < sizeof(ic->buffer) &&
+				    mnstr_write(ic->s, ic->buffer, 1, sizeof(ic->buffer) - outbytesleft) < 0) {
+					goto bailout;
+				}
 				/* remember what hasn't been converted */
 				if (inbytesleft > sizeof(ic->buffer)) {
-					/* ridiculously long multibyte sequence, so return error */
-					s->errnr = MNSTR_WRITE_ERROR;
-					if (bf)
-						free(bf);
-					return -1;
+					/* ridiculously long multibyte
+					 * sequence, so return
+					 * error */
+					goto bailout;
 				}
 				memcpy(ic->buffer, inbuf, inbytesleft);
 				ic->buflen = inbytesleft;
@@ -2000,17 +2020,22 @@
 				break;
 			default:
 				/* cannot happen (according to manual) */
-				s->errnr = MNSTR_WRITE_ERROR;
-				if (bf)
-					free(bf);
-				return -1;
+				goto bailout;
 			}
 		}
-		mnstr_write(ic->s, ic->buffer, 1, sizeof(ic->buffer) - outbytesleft);
+		if (mnstr_write(ic->s, ic->buffer, 1, sizeof(ic->buffer) - outbytesleft) < 0) {
+			goto bailout;
+		}
 	}
 	if (bf)
 		free(bf);
 	return (ssize_t) cnt;
+
+  bailout:
+	s->errnr = MNSTR_WRITE_ERROR;
+	if (bf)
+		free(bf);
+	return -1;
 }

 static ssize_t
@@ -2043,8 +2068,12 @@
 				s->errnr = MNSTR_READ_ERROR;
 				return -1;
 			}
-			iconv(ic->cd, NULL, NULL, &outbuf, &outbytesleft);
-			goto exit_func;
+			if (iconv(ic->cd, NULL, NULL, &outbuf, &outbytesleft) == (size_t) -1) {
+				/* some error occurred */
+				s->errnr = MNSTR_READ_ERROR;
+				return -1;
+			}
+			goto exit_func; /* double break */
 		default:
 			/* error */
 			s->errnr = MNSTR_READ_ERROR;
@@ -2061,8 +2090,8 @@
 				break;
 			case E2BIG:
 				/* not enough space in output buffer,
-				   return what we have, saving what's in
-				   the buffer */
+				 * return what we have, saving what's in
+				 * the buffer */
 				goto exit_func;
 			default:
 				/* cannot happen (according to manual) */
@@ -2082,9 +2111,9 @@
 	ic->buflen = inbytesleft;
 	if (outbytesleft == elmsize * cnt) {
 		/* if we're returning data, we must pass on EOF on the
-		   next call (i.e. keep ic->eof set), otherwise we
-		   must clear it so that the next call will cause the
-		   underlying stream to be read again */
+		 * next call (i.e. keep ic->eof set), otherwise we
+		 * must clear it so that the next call will cause the
+		 * underlying stream to be read again */
 		ic->eof = 0;
 	}
 	return (ssize_t) ((elmsize * cnt - outbytesleft) / elmsize);
@@ -2098,14 +2127,14 @@
 	size_t outbytesleft = sizeof(ic->buffer);

 	/* if unconverted data from a previous call remains, it was an
-	   incomplete multibyte sequence, so an error */
-	if (ic->buflen > 0) {
+	 * incomplete multibyte sequence, so an error */
+	if (ic->buflen > 0 ||
+	    iconv(ic->cd, NULL, NULL, &outbuf, &outbytesleft) == (size_t) -1 ||
+	    (outbytesleft < sizeof(ic->buffer) &&
+	     mnstr_write(ic->s, ic->buffer, 1, sizeof(ic->buffer) - outbytesleft) < 0)) {
 		s->errnr = MNSTR_WRITE_ERROR;
-		return 1;
-	}
-	iconv(ic->cd, NULL, NULL, &outbuf, &outbytesleft);
-	if (outbytesleft < sizeof(ic->buffer))
-		mnstr_write(ic->s, ic->buffer, 1, sizeof(ic->buffer) - outbytesleft);
+		return -1;
+	}
 	return mnstr_flush(ic->s);
 }

@@ -2195,24 +2224,29 @@
 }

 #else
-stream *iconv_rstream(stream *ss, const char *charset, const char *name) {
+stream *
+iconv_rstream(stream *ss, const char *charset, const char *name)
+{
 	(void) name;

 	if (strcmp(charset, "utf-8") == 0 ||
-			strcmp(charset, "UTF-8") == 0 ||
-			strcmp(charset, "UTF8") == 0)
+	    strcmp(charset, "UTF-8") == 0 ||
+	    strcmp(charset, "UTF8") == 0)
 		return ss;
-
+
 	return NULL;
 }
-stream *iconv_wstream(stream *ss, const char *charset, const char *name) {
+
+stream *
+iconv_wstream(stream *ss, const char *charset, const char *name)
+{
 	(void) name;

 	if (strcmp(charset, "utf-8") == 0 ||
-			strcmp(charset, "UTF-8") == 0 ||
-			strcmp(charset, "UTF8") == 0)
+	    strcmp(charset, "UTF-8") == 0 ||
+	    strcmp(charset, "UTF8") == 0)
 		return ss;
-
+
 	return NULL;
 }
 #endif /* HAVE_ICONV */
@@ -2288,7 +2322,7 @@
 		return (ssize_t) (size / elmsize);
 	} else {
 		s->errnr = MNSTR_READ_ERROR;
-		return 0;
+		return -1;
 	}
 }

@@ -2373,8 +2407,8 @@
 /* ------------------------------------------------------------------ */

 /* A buffered stream consists of a sequence of blocks.  Each block
-   consists of a count followed by the data in the block.  A flush is
-   indicated by an empty block (i.e. just a count of 0).
+ * consists of a count followed by the data in the block.  A flush is
+ * indicated by an empty block (i.e. just a count of 0).
  */
 typedef struct bs {
 	stream *s;		/* underlying stream */
@@ -2383,7 +2417,7 @@
 	size_t blks;		/* read/writen blocks (possibly partial) */
 	size_t bytes;		/* read/writen bytes */
 	char buf[BLOCK];	/* the buffered data (minus the size of
-				   size-short */
+				 * size-short */
 } bs;

 static bs *
@@ -2403,14 +2437,14 @@
 }

 /* Collect data until the internal buffer is filled, then write the
-   filled buffer to the underlying stream.
-   Struct field usage:
-   s - the underlying stream;
-   buf - the buffer in which data is collected;
-   nr - how much of buf is already filled (if nr == sizeof(buf) the
-        data is written to the underlying stream, so upon entry nr <
-        sizeof(buf));
-   itotal - unused.
+ * filled buffer to the underlying stream.
+ * Struct field usage:
+ * s - the underlying stream;
+ * buf - the buffer in which data is collected;
+ * nr - how much of buf is already filled (if nr == sizeof(buf) the
+ *      data is written to the underlying stream, so upon entry nr <
+ *      sizeof(buf));
+ * itotal - unused.
  */
 static ssize_t
 bs_write(stream *ss, const void *buf, size_t elmsize, size_t cnt)
@@ -2446,7 +2480,7 @@
 			}
 #endif
 			/* since the block is at max BLOCK (8K) - 2 size we can
-			   store it in a two byte integer */
+			 * store it in a two byte integer */
 			blksize = (short) s->nr;
 			s->bytes += s->nr;
 			/* the last bit tells whether a flush is in there, it's not
@@ -2467,9 +2501,9 @@
 }

 /* If the internal buffer is partially filled, write it to the
-   underlying stream.  Then in any case write an empty buffer to the
-   underlying stream to indicate to the receiver that the data was
-   flushed.
+ * underlying stream.  Then in any case write an empty buffer to the
+ * underlying stream to indicate to the receiver that the data was
+ * flushed.
  */
 static int
 bs_flush(stream *ss)
@@ -2499,7 +2533,7 @@
 		blksize = (short) (s->nr << 1);
 		s->bytes += s->nr;
 		/* indicate that this is the last buffer of a block by
-		   setting the low-order bit */
+		 * setting the low-order bit */
 		blksize |= (short) 1;
 		/* allways flush (even empty blocks) needed for the protocol) */
 #ifdef WORDS_BIGENDIAN
@@ -2518,14 +2552,14 @@
 }

 /* Read buffered data and return the number of items read.  At the
-   flush boundary we will return 0 to indicate the end of a block.
-
-   Structure field usage:
-   s - the underlying stream;
-   buf - not used;
-   itotal - the amount of data in the current block that hasn't yet
-            been read;
-   nr - indicates whether the flush marker has to be returned.
+ * flush boundary we will return 0 to indicate the end of a block.
+ *
+ * Structure field usage:
+ * s - the underlying stream;
+ * buf - not used;
+ * itotal - the amount of data in the current block that hasn't yet
+ *          been read;
+ * nr - indicates whether the flush marker has to be returned.
  */
 static ssize_t
 bs_read(stream *ss, void *buf, size_t elmsize, size_t cnt)
@@ -2646,8 +2680,8 @@
 }

 /* Read the next bit of a block.  If this was the last bit of the
-   current block, set the value pointed to by last to 1, otherwise set
-   it to 0. */
+ * current block, set the value pointed to by last to 1, otherwise set
+ * it to 0. */
 ssize_t
 bs_read_next(stream *ss, void *buf, size_t nbytes, int *last)
 {
@@ -2742,7 +2776,7 @@
 	tee_stream *ts = (tee_stream *) s->stream_data.p;
 	ssize_t reorig = ts->orig->write(ts->orig, buf, elmsize, cnt);
 	ssize_t relog = ts->log->write(ts->log, buf, elmsize, cnt);
-	return (reorig < relog) ? reorig : relog;
+	return reorig < relog ? reorig : relog;
 }

 static int
@@ -2751,7 +2785,7 @@
 	tee_stream *ts = (tee_stream *) s->stream_data.p;
 	int reorig = ts->orig->flush(ts->orig);
 	int relog = ts->log->flush(ts->log);
-	return (reorig < relog) ? reorig : relog;
+	return reorig < relog ? reorig : relog;
 }

 static void
@@ -2830,9 +2864,9 @@
 	char x = 0;

 	assert(s->read == bs_read || s->write == bs_write);
-	len = mnstr_read(s, buf, elmsize, cnt);
-	mnstr_read(s, &x, 0, 0);	/* read prompt */
-	if (x > 0)
+	if ((len = mnstr_read(s, buf, elmsize, cnt)) < 0 ||
+	    mnstr_read(s, &x, 0, 0) < 0	/* read prompt */ ||
+	    x > 0)
 		return -1;
 	return len;
 }
@@ -2857,7 +2891,7 @@
 mnstr_writeBte(stream *s, signed char val)
 {
 	if (!s || s->errnr)
-		return (0);
+		return 0;
 	return s->write(s, (void *) &val, sizeof(val), 1) == 1;
 }

@@ -2883,7 +2917,7 @@
 mnstr_writeSht(stream *s, short val)
 {
 	if (!s || s->errnr)
-		return (0);
+		return 0;
 	return s->write(s, (void *) &val, sizeof(val), 1) == 1;
 }

@@ -2909,7 +2943,7 @@
 mnstr_writeInt(stream *s, int val)
 {
 	if (!s || s->errnr)
-		return (0);
+		return 0;
 	return s->write(s, (void *) &val, sizeof(val), (size_t) 1) == 1;
 }

@@ -2935,7 +2969,7 @@
 mnstr_writeLng(stream *s, lng val)
 {
 	if (!s || s->errnr)
-		return (0);
+		return 0;
 	return s->write(s, (void *) &val, sizeof(val), (size_t) 1) == 1;
 }

@@ -2955,7 +2989,7 @@
 mnstr_writeBteArray(stream *s, const signed char *val, size_t cnt)
 {
 	if (!s || s->errnr)
-		return (0);
+		return 0;
 	return s->write(s, val, sizeof(*val), cnt) == (ssize_t) cnt;
 }

@@ -2970,7 +3004,7 @@
 	if (s->byteorder != 1234) {
 		size_t i;
 		for (i = 0; i < cnt; i++, val++)
-			*val = short_int_SWAP(*val);
+			*val = short_int_SWAP(*val);
 	}
 	return 1;
 }
@@ -2979,7 +3013,7 @@
 mnstr_writeShtArray(stream *s, const short *val, size_t cnt)
 {
 	if (!s || s->errnr)
-		return (0);
+		return 0;
 	return s->write(s, val, sizeof(*val), cnt) == (ssize_t) cnt;
 }

@@ -2994,7 +3028,7 @@
 	if (s->byteorder != 1234) {
 		size_t i;
 		for (i = 0; i < cnt; i++, val++)
-			*val = normal_int_SWAP(*val);
+			*val = normal_int_SWAP(*val);
 	}
 	return 1;
 }
@@ -3003,7 +3037,7 @@
 mnstr_writeIntArray(stream *s, const int *val, size_t cnt)
 {
 	if (!s || s->errnr)
-		return (0);
+		return 0;
 	return s->write(s, val, sizeof(*val), cnt) == (ssize_t) cnt;
 }

@@ -3018,7 +3052,7 @@
 	if (s->byteorder != 1234) {
 		size_t i;
 		for (i = 0; i < cnt; i++, val++)
-			*val = long_long_SWAP(*val);
+			*val = long_long_SWAP(*val);
 	}
 	return 1;
 }
@@ -3027,7 +3061,7 @@
 mnstr_writeLngArray(stream *s, const lng *val, size_t cnt)
 {
 	if (!s || s->errnr)
-		return (0);
+		return 0;
 	return s->write(s, val, sizeof(*val), cnt) == (ssize_t) cnt;
 }

@@ -3039,7 +3073,7 @@
 	size_t bfsz = BUFSIZ;
 	va_list ap;
 	if (!s || s->errnr)
-		return (-1);
+		return -1;

 	va_start(ap, format);
 	i = vsnprintf(bf, bfsz, format, ap);


tpm: allow less-than-4-bytes writes to TPM_STS register

Section 5.3.1 TPM Register Space Decode of TCG PC Client
Platform TPM Profile (PTP) Specification Rev 00.43 allows
partial access to registers: "Software may access only part
of a register, e.g. read or write one byte of a 4 byte register."

BUG=chrome-os-partner:54286
BRANCH=none
TEST=tpm driver successfully sets TPM_STS_COMMAND_READY
(see more details in BUG)

Change-Id: I92995f04c6f6221ab7e00d086c4067e447557476
Signed-off-by: Andrey Pronin <53bbebe6910b11f7aa2d1daaa466658eb4cba5f2@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/351701
Reviewed-by: Bill Richardson <129945214b1d548d8e49b6c29c43094f8c78057f@chromium.org>

--- common/tpm_registers.c
+++ common/tpm_registers.c
@@ -244,7 +244,7 @@
  */
 static void sts_reg_write(const uint8_t *data, uint32_t data_size)
 {
-	uint32_t value;
+	uint32_t value = 0;

 	data_size = MIN(data_size, 4);
 	memcpy(&value, data, data_size);


PHPC-134: Add the internal results here too

--- src/MongoDB/WriteResult.c
+++ src/MongoDB/WriteResult.c
@@ -391,6 +391,14 @@
 	*is_temp = 1;
 	array_init_size(&retval, 9);

+	{
+		zval *result = NULL;
+
+		MAKE_STD_ZVAL(result);
+		php_phongo_result_to_zval(result, &intern->result);
+		add_assoc_zval_ex(&retval, ZEND_STRS("result"), result);
+	}
+
 	add_assoc_long_ex(&retval, ZEND_STRS("nInserted"), intern->nInserted);
 	add_assoc_long_ex(&retval, ZEND_STRS("nMatched"), intern->nMatched);
 	add_assoc_long_ex(&retval, ZEND_STRS("nModified"), intern->nModified);


remove dead code

remove dead code

git-svn-id: 88467cb1fb04b8a755be7e1ee1026be4190196ef@4641 3a8e244f-b0f2-452b-bcba-4c88e055c3ca

--- compiler/include/vec.h
+++ compiler/include/vec.h
@@ -66,7 +66,6 @@
   C* end() { return v + n; }
   Vec<C>& operator=(Vec<C> &v) { this->copy(v); return *this; }
   int length () { return n; }
-  void quickSort(int left, int right);

  private:
   void add_internal(C a);


add viennacl version assertion

add viennacl version assertion

--- src/shogun/mathematics/linalg/LinalgBackendViennaCL.h
+++ src/shogun/mathematics/linalg/LinalgBackendViennaCL.h
@@ -41,8 +41,11 @@
 #include <viennacl/vector.hpp>
 #include <viennacl/linalg/inner_prod.hpp>
 #include <viennacl/linalg/matrix_operations.hpp>
+#include <shogun/mathematics/linalg/GPUMemoryViennaCL.h>
+
+#if VIENNACL_VERSION >= 10700
 #include <viennacl/linalg/sum.hpp>
-#include <shogun/mathematics/linalg/GPUMemoryViennaCL.h>
+#endif

 namespace shogun
 {
@@ -372,14 +375,6 @@
 		viennacl::linalg::vector_assign(vcl_vector, value);
 	}

-	/** ViennaCL vector sum method. */
-	template <typename T>
-	T sum_impl(const SGVector<T>& vec, bool no_diag=false) const
-	{
-		GPUMemoryViennaCL<T>* vec_gpu = cast_to_viennacl(vec);
-		return viennacl::linalg::sum(vec_gpu->data_vector(vec.size()));
-	}
-
 	/** ViennaCL matrix sum method. */
 	template <typename T>
 	T sum_impl(const SGMatrix<T>& mat, bool no_diag=false) const
@@ -402,6 +397,18 @@
 		return result[0];
 	}

+	/** ViennaCL vector sum method. */
+	template <typename T>
+	T sum_impl(const SGVector<T>& vec, bool no_diag=false) const
+	{
+		#if VIENNACL_VERSION >= 10700
+			GPUMemoryViennaCL<T>* vec_gpu = cast_to_viennacl(vec);
+			return viennacl::linalg::sum(vec_gpu->data_vector(vec.size()));
+		#else
+			return sum_impl(SGMatrix<T>(vec));
+		#endif
+	}
+
 	/** ViennaCL matrix sum method. */
 	template <typename T>
 	T sum_symmetric_impl(const SGMatrix<T>& mat, bool no_diag=false) const


[finsh] change display format for list_thread.

--- components/finsh/cmd.c
+++ components/finsh/cmd.c
@@ -117,12 +117,12 @@

     maxlen = object_name_maxlen(list);

-    rt_kprintf("%-*.s pri status      sp     stack size max used left tick  error\n", maxlen, "thread"); object_split(maxlen);
-    rt_kprintf(     " --  ------- ---------- ----------  ------  ---------- ---\n");
+    rt_kprintf("%-*.s pri  status      sp     stack size max used left tick  error\n", maxlen, "thread"); object_split(maxlen);
+    rt_kprintf(     " ---  ------- ---------- ----------  ------  ---------- ---\n");
     for (node = list->next; node != list; node = node->next)
     {
         thread = rt_list_entry(node, struct rt_thread, list);
-        rt_kprintf("%-*.*s %02d ", maxlen, RT_NAME_MAX, thread->name, thread->current_priority);
+        rt_kprintf("%-*.*s %3d ", maxlen, RT_NAME_MAX, thread->name, thread->current_priority);

         if (thread->stat == RT_THREAD_READY)        rt_kprintf(" ready  ");
         else if (thread->stat == RT_THREAD_SUSPEND) rt_kprintf(" suspend");


Fix: drbgtest fails when tests are executed in random order

[extended tests]

The test_rand_reseed assumed that the global DRBGs were not used
previously. This assumption is false when the tests are executed
in random order (OPENSSL_TEST_RAND_ORDER). So we uninstantiate
them first and add a test for the first instantiation.

Reviewed-by: Richard Levitte <5fb523282dd7956571c80524edc2dccfa0bd8234@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5680)

--- test/drbgtest.c
+++ test/drbgtest.c
@@ -691,13 +691,28 @@
         || !TEST_ptr_eq(private->parent, master))
         return 0;

+    /* uninstantiate the three global DRBGs */
+    RAND_DRBG_uninstantiate(private);
+    RAND_DRBG_uninstantiate(public);
+    RAND_DRBG_uninstantiate(master);
+
+
     /* Install hooks for the following tests */
     hook_drbg(master,  &master_ctx);
     hook_drbg(public,  &public_ctx);
     hook_drbg(private, &private_ctx);

-    /*
-     * Test initial state of shared DRBs
+
+    /*
+     * Test initial seeding of shared DRBGs
+     */
+    if (!TEST_true(test_drbg_reseed(1, master, public, private, 1, 1, 1)))
+        goto error;
+    reset_drbg_hook_ctx();
+
+
+    /*
+     * Test initial state of shared DRBGs
      */
     if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 0, 0)))
         goto error;


Fix memory leak in drbgtest

Fix memory leak in drbgtest

Reviewed-by: Matthias St. Pierre <1910231d24f125aceac7850dc92279eee8d52323@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/12613)

--- test/drbgtest.c
+++ test/drbgtest.c
@@ -531,10 +531,10 @@
     if (!TEST_ptr(rand = EVP_RAND_fetch(NULL, "CTR-DRBG", NULL))
             || !TEST_ptr(drbg = EVP_RAND_CTX_new(rand, parent))
             || !TEST_true(EVP_RAND_set_ctx_params(drbg, params))) {
-        EVP_RAND_CTX_rand(drbg);
-        EVP_RAND_free(rand);
+        EVP_RAND_CTX_free(drbg);
         drbg = NULL;
     }
+    EVP_RAND_free(rand);
     return drbg;
 }

@@ -627,13 +627,6 @@

 int setup_tests(void)
 {
-    /*
-     * TODO(3.0): figure out why and fix.
-     * Create the primary DRBG here to avoid a memory leak if it is done in
-     * the test cases.
-     */
-    if (RAND_get0_primary(NULL) == NULL)
-        return 0;
     ADD_TEST(test_rand_drbg_reseed);
     ADD_TEST(test_rand_drbg_prediction_resistance);
 #if defined(OPENSSL_THREADS)


Code cleanup

Code cleanup

--- src/modems/hayes.c
+++ src/modems/hayes.c
@@ -3070,18 +3070,17 @@

 /* on_code_cme_error */
+static void _cme_command_repeat(HayesChannel * channel, HayesCommand * command);
 static void _cme_error_registration(HayesChannel * channel, char const * error);

 static void _on_code_cme_error(HayesChannel * channel, char const * answer)
 {
-	const guint timeout = 5000;
 	Hayes * hayes = channel->hayes;
 	ModemPluginHelper * helper = hayes->helper;
 	/* XXX ugly */
 	HayesCommand * command = (channel->queue != NULL)
 		? channel->queue->data : NULL;
 	unsigned int u;
-	HayesCommand * p;
 	ModemEvent * event;

 	if(command != NULL)
@@ -3108,19 +3107,7 @@
 				break;
 			/* fallback */
 		case 14: /* SIM busy */
-			/* repeat the command */
-			if(command == NULL)
-				break;
-			if((p = hayes_command_new_copy(command)) == NULL)
-				break;
-			hayes_command_set_data(p,
-					hayes_command_get_data(command));
-			hayes_command_set_data(command, NULL);
-			channel->queue_timeout = g_slist_append(
-					channel->queue_timeout, p);
-			if(channel->source == 0)
-				channel->source = g_timeout_add(timeout,
-						_on_queue_timeout, channel);
+			_cme_command_repeat(channel, command);
 			break;
 		case 30:  /* No network service */
 			_cme_error_registration(channel, "No network service");
@@ -3165,6 +3152,23 @@
 		case 263: /* Invalid block */
 			break;
 	}
+}
+
+static void _cme_command_repeat(HayesChannel * channel, HayesCommand * command)
+{
+	const guint timeout = 5000;
+	HayesCommand * p;
+
+	if(command == NULL)
+		return;
+	if((p = hayes_command_new_copy(command)) == NULL)
+		return;
+	hayes_command_set_data(p, hayes_command_get_data(command));
+	hayes_command_set_data(command, NULL);
+	channel->queue_timeout = g_slist_append(channel->queue_timeout, p);
+	if(channel->source == 0)
+		channel->source = g_timeout_add(timeout, _on_queue_timeout,
+				channel);
 }

 static void _cme_error_registration(HayesChannel * channel, char const * error)


test/extended: Fix build on Windows

test/extended: Fix build on Windows

--- test/extended.c
+++ test/extended.c
@@ -124,10 +124,10 @@
 #else /* WIN32 */
 static void child_check_open_fds(void) {}

-static void check_cloexec_leaks(const char *slide, void *prog) {
-  (void) slide;
-  (void) prog;
-}
+static void check_cloexec_leaks(const char *slide G_GNUC_UNUSED,
+                                void *prog G_GNUC_UNUSED,
+                                int64_t x G_GNUC_UNUSED,
+                                int64_t y G_GNUC_UNUSED) {}
 #endif /* WIN32 */


Fixed interpreting USSD answers

Fixed interpreting USSD answers

--- src/modems/hayes.c
+++ src/modems/hayes.c
@@ -4215,8 +4215,7 @@
 	unsigned int u;
 	char buf[32];

-	/* FIXME really implement */
-	if(sscanf(answer, "%u\"%31[^\"]\",%u", &u, buf, &u) >= 2)
+	if(sscanf(answer, "%u,\"%31[^\"]\",%u", &u, buf, &u) >= 2)
 	{
 		buf[sizeof(buf) - 1] = '\0';
 		event->notification.content = buf;


update uva340

update uva340


added counting

added counting

--- src/versus.c
+++ src/versus.c
@@ -5,25 +5,28 @@

 #define MY_UUID { 0xD9, 0xF7, 0x28, 0xD3, 0x27, 0xD9, 0x4E, 0xF4, 0x8B, 0x6C, 0xA4, 0xAB, 0x26, 0xB0, 0xB0, 0xDF }
 PBL_APP_INFO(MY_UUID,
-             "Versus", "Nikhil Lele",
-             0, 1, /* App version */
-             DEFAULT_MENU_ICON,
-             APP_INFO_STANDARD_APP);
+			 "Versus", "Nikhil Lele",
+			 0, 1, /* App version */
+			 DEFAULT_MENU_ICON,
+			 APP_INFO_STANDARD_APP);

 Window window;

 #define SCORE_LEN 16 // max number of chars for display, include null-terminator
+#define MAX_SCORE 0xffff

 TextLayer layer_1;
 TextLayer layer_2;

 char scoreText_1[SCORE_LEN];
 char scoreText_2[SCORE_LEN];
-int score_1;
-int score_2;
+uint16_t score_1;
+uint16_t score_2;

 // From Minh Nguyen at http://stackoverflow.com/questions/3440726
-void itoa(int value, char *sp, int radix)
+// Adapted to constant radix of 10
+#define RADIX 10
+void itoa(int value, char *sp)
 {
     char tmp[SCORE_LEN]; // be careful with the length of the buffer
     char *tp = tmp;
@@ -31,14 +34,14 @@
     unsigned v;
     int sign;

-    sign = (radix == 10 && value < 0);
+    sign = (RADIX == 10 && value < 0);
     if (sign)   v = -value;
     else    v = (unsigned)value;

     while (v || tp == tmp)
     {
-        i = v % radix;
-        v /= radix; // v/=radix uses less CPU clocks than v=v/radix does
+        i = v % RADIX;
+        v /= RADIX; // v/=radix uses less CPU clocks than v=v/radix does
         if (i < 10)
           *tp++ = i+'0';
         else
@@ -52,89 +55,96 @@
 }

 void updateText_1() {
-  itoa(score_1, scoreText_1, 10);
-  text_layer_set_text(&layer_1, scoreText_1);
+	itoa(score_1, scoreText_1);
+	text_layer_set_text(&layer_1, scoreText_1);
 }

 void updateText_2() {
-  itoa(score_2, scoreText_2, 10);
-  text_layer_set_text(&layer_2, scoreText_2);
+	itoa(score_2, scoreText_2);
+	text_layer_set_text(&layer_2, scoreText_2);
 }

 void initTextLayer_1() {
-  text_layer_init(&layer_1, GRect(0, 20, 144 /* width */, 20 /* height */));
-  text_layer_set_text(&layer_1, "AAAAAAAA");
-  // text_layer_set_font(&layer_1, fonts_get_system_font(FONT_KEY_GOTHAM_30_BLACK));
-  layer_add_child(&window.layer, &layer_1.layer);
+	text_layer_init(&layer_1, GRect(10, 20, 144 /* width */, 40 /* height */));
+	text_layer_set_font(&layer_1, fonts_get_system_font(FONT_KEY_GOTHAM_30_BLACK));
+	updateText_1();
+	layer_add_child(&window.layer, &layer_1.layer);
 }

 void initTextLayer_2() {
-  text_layer_init(&layer_2, GRect(0, 50, 144 /* width */, 20 /* height */));
-  text_layer_set_text(&layer_2, "BBBBBBBB");
-  // text_layer_set_font(&layer_2, fonts_get_system_font(FONT_KEY_GOTHAM_30_BLACK));
-  layer_add_child(&window.layer, &layer_2.layer);
+	text_layer_init(&layer_2, GRect(10, 100, 144 /* width */, 40 /* height */));
+	text_layer_set_font(&layer_2, fonts_get_system_font(FONT_KEY_GOTHAM_30_BLACK));
+	updateText_2();
+	layer_add_child(&window.layer, &layer_2.layer);
 }

 /* Button Handlers */

 void up_single_click_handler(ClickRecognizerRef recognizer, Window *window) {
-  (void)recognizer;
-  (void)window;
-  updateText_1();
+	(void)recognizer;
+	(void)window;
+
+	if (score_1 < MAX_SCORE) score_1++;
+	updateText_1();
 }

 void down_single_click_handler(ClickRecognizerRef recognizer, Window *window) {
-  (void)recognizer;
-  (void)window;
-  updateText_2();
+	(void)recognizer;
+	(void)window;
+
+	if (score_2 < MAX_SCORE) score_2++;
+	updateText_2();
 }

 void select_single_click_handler(ClickRecognizerRef recognizer, Window *window) {
-  (void)recognizer;
-  (void)window;
+	(void)recognizer;
+	(void)window;
 }

 void select_long_click_handler(ClickRecognizerRef recognizer, Window *window) {
-  (void)recognizer;
-  (void)window;
-
+	(void)recognizer;
+	(void)window;
+	score_1 = 0;
+	score_2 = 0;
+	text_layer_set_text(&layer_1, "0");
+	text_layer_set_text(&layer_2, "0");
 }

 void click_config_provider(ClickConfig **config, Window *window) {
-  (void)window;
+	(void)window;

-  config[BUTTON_ID_SELECT]->click.handler = (ClickHandler) select_single_click_handler;
+	config[BUTTON_ID_SELECT]->click.handler = (ClickHandler) select_single_click_handler;

-  config[BUTTON_ID_SELECT]->long_click.handler = (ClickHandler) select_long_click_handler;
+	config[BUTTON_ID_SELECT]->long_click.handler = (ClickHandler) select_long_click_handler;

-  config[BUTTON_ID_UP]->click.handler = (ClickHandler) up_single_click_handler;
-  config[BUTTON_ID_UP]->click.repeat_interval_ms = 100;
+	config[BUTTON_ID_UP]->click.handler = (ClickHandler) up_single_click_handler;
+	config[BUTTON_ID_UP]->click.repeat_interval_ms = 100;

-  config[BUTTON_ID_DOWN]->click.handler = (ClickHandler) down_single_click_handler;
-  config[BUTTON_ID_DOWN]->click.repeat_interval_ms = 100;
+	config[BUTTON_ID_DOWN]->click.handler = (ClickHandler) down_single_click_handler;
+	config[BUTTON_ID_DOWN]->click.repeat_interval_ms = 100;
 }

 void handle_init(AppContextRef ctx) {
-  (void)ctx;
+	(void)ctx;

-  window_init(&window, "Versus");
-  window_stack_push(&window, true /* Animated */);
+	window_init(&window, "Versus");
+	window_stack_push(&window, true /* Animated */);

-  score_1 = 11111;
-  score_2 = 22222;
+	score_1 = 0;
+	score_2 = 0;

-  initTextLayer_1();
-  initTextLayer_2();
+	initTextLayer_1();
+	initTextLayer_2();

-  // Attach our desired button functionality
-  window_set_click_config_provider(&window, (ClickConfigProvider) click_config_provider);
+	// Attach our desired button functionality
+	window_set_click_config_provider(&window, (ClickConfigProvider) click_config_provider);
 }

 void pbl_main(void *params) {
-  PebbleAppHandlers handlers = {
-    .init_handler = &handle_init
-  };
+	PebbleAppHandlers handlers = {
+	.init_handler = &handle_init
+	};

-  app_event_loop(params, &handlers);
+	app_event_loop(params, &handlers);
 }


Eliminate compiler warning

Eliminate compiler warning


test/pollfree: fix compile on 32-bit x86

For some reason we don't have __NR_futex or SYS_futex there. Just skip
the test if we don't have the proper syscall number, this dates back to
the days of every arch having their own syscall numbering. Not worth
fixing this one up for real.

Signed-off-by: Jens Axboe <cd8c6775e60d6f67a6984377324e5290df3d5358@kernel.dk>

--- test/pollfree.c
+++ test/pollfree.c
@@ -24,6 +24,8 @@

 #include <linux/futex.h>

+#ifdef __NR_futex
+
 static void sleep_ms(uint64_t ms)
 {
   usleep(ms * 1000);
@@ -77,13 +79,13 @@
   if (ev->state)
     exit(1);
   __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE);
-  syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000);
+  syscall(__NR_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000);
 }

 static void event_wait(event_t* ev)
 {
   while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
-    syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0);
+    syscall(__NR_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0);
 }

 static int event_isset(event_t* ev)
@@ -100,7 +102,7 @@
     struct timespec ts;
     ts.tv_sec = remain / 1000;
     ts.tv_nsec = (remain % 1000) * 1000 * 1000;
-    syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts);
+    syscall(__NR_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts);
     if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
       return 1;
     now = current_time_ms();
@@ -412,3 +414,12 @@
   loop();
   return 0;
 }
+
+#else /* __NR_futex */
+
+int main(int argc, char *argv[])
+{
+  return 0;
+}
+
+#endif /* __NR_futex */


chgstv2: Move battery revival code to sub-routine

This patch moves battery revival code to revive_battery. It also
uses IS_ENABLED to increase readability. There is no functional
change.

BUG=None
BRANCH=None
TEST=buildall

Change-Id: I9c2689cdc3bcb843a5916f78c1f5e01948eff477
Signed-off-by: Daisuke Nojiri <fd5f93af191bf7e8f73ea71cc3c0f66b41b1dd49@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2929343
Reviewed-by: Vincent Palatin <70a9964ec8fd10b0b08fcc8623c2add25ddf99ac@chromium.org>

--- common/charge_state_v2.c
+++ common/charge_state_v2.c
@@ -1852,6 +1852,41 @@
 	}
 }

+static void revive_battery(int *need_static)
+{
+	if (IS_ENABLED(CONFIG_BATTERY_REQUESTS_NIL_WHEN_DEAD)
+			&& curr.requested_voltage == 0
+			&& curr.requested_current == 0
+			&& curr.batt.state_of_charge == 0) {
+		/*
+		 * Battery is dead, give precharge current
+		 * TODO (crosbug.com/p/29467): remove this workaround
+		 * for dead battery that requests no voltage/current
+		 */
+		curr.requested_voltage = batt_info->voltage_max;
+		curr.requested_current = batt_info->precharge_current;
+	} else if (IS_ENABLED(CONFIG_BATTERY_REVIVE_DISCONNECT)
+			&& curr.requested_voltage == 0
+			&& curr.requested_current == 0
+			&& battery_seems_disconnected) {
+		/*
+		 * Battery is in disconnect state. Apply a
+		 * current to kick it out of this state.
+		 */
+		CPRINTS("found battery in disconnect state");
+		curr.requested_voltage = batt_info->voltage_max;
+		curr.requested_current = batt_info->precharge_current;
+	} else if (curr.state == ST_PRECHARGE
+			|| battery_seems_dead || battery_was_removed) {
+		CPRINTS("battery woke up");
+		/* Update the battery-specific values */
+		batt_info = battery_get_info();
+		*need_static = 1;
+	}
+
+	battery_seems_dead = battery_was_removed = 0;
+}
+
 /* Main loop */
 void charger_task(void *u)
 {
@@ -2078,47 +2113,8 @@
 		battery_seems_disconnected =
 			battery_get_disconnect_state() == BATTERY_DISCONNECTED;

-#ifdef CONFIG_BATTERY_REQUESTS_NIL_WHEN_DEAD
-		/*
-		 * TODO (crosbug.com/p/29467): remove this workaround
-		 * for dead battery that requests no voltage/current
-		 */
-		if (curr.requested_voltage == 0 &&
-		    curr.requested_current == 0 &&
-		    curr.batt.state_of_charge == 0) {
-			/* Battery is dead, give precharge current */
-			curr.requested_voltage =
-				batt_info->voltage_max;
-			curr.requested_current =
-				batt_info->precharge_current;
-		} else
-#endif
-#ifdef CONFIG_BATTERY_REVIVE_DISCONNECT
-		if (curr.requested_voltage == 0 &&
-		    curr.requested_current == 0 &&
-		    battery_seems_disconnected) {
-			/*
-			 * Battery is in disconnect state. Apply a
-			 * current to kick it out of this state.
-			 */
-			CPRINTS("found battery in disconnect state");
-			curr.requested_voltage =
-				batt_info->voltage_max;
-			curr.requested_current =
-				batt_info->precharge_current;
-		} else
-#endif
-		if (curr.state == ST_PRECHARGE ||
-		    battery_seems_dead ||
-		    battery_was_removed) {
-			CPRINTS("battery woke up");
-
-			/* Update the battery-specific values */
-			batt_info = battery_get_info();
-			need_static = 1;
-		    }
-
-		battery_seems_dead = battery_was_removed = 0;
+		revive_battery(&need_static);
+
 		set_charge_state(ST_CHARGE);

 wait_for_it:


charger: fix coding error in charge_prevent_power_on()

BUG=none
BRANCH=none
TEST=make -j buildall

Change-Id: If60902ab0176435b41f70ca11e0f73b430b65fe5
Signed-off-by: li feng <0fd15d95d647a38d004d7ac9a3d0587bb1c98551@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/318650
Commit-Ready: Li1 Feng <0fd15d95d647a38d004d7ac9a3d0587bb1c98551@intel.com>
Tested-by: Li1 Feng <0fd15d95d647a38d004d7ac9a3d0587bb1c98551@intel.com>
Reviewed-by: Shawn N <5259333ce42e3ace6a73988cec7115ed9d3a661a@chromium.org>

--- common/charge_state_v2.c
+++ common/charge_state_v2.c
@@ -945,7 +945,7 @@
 	if (prevent_power_on)
 		if (charge_manager_get_power_limit_uw() >=
 		    MIN(LIKELY_PD_USBC_POWER_MW * 1000,
-			CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW * 1000));
+			CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW * 1000))
 			prevent_power_on = 0;
 #endif


change walletversion

change walletversion

--- src/wallet.h
+++ src/wallet.h
@@ -37,7 +37,7 @@
     FEATURE_WALLETCRYPT = 40000, // wallet encryption
     FEATURE_COMPRPUBKEY = 60000, // compressed public keys

-    FEATURE_LATEST = 60000
+    FEATURE_LATEST = 60001
 };


factorize code to retrieve audio/video codecs

--- src/mrl_internal.c
+++ src/mrl_internal.c
@@ -825,6 +825,45 @@
   mrl_metadata_plog (player, mrl);
 }

+static char *
+mrl_get_codec (player_t *player, mrl_t *mrl, mrl_type_t type)
+{
+  mrl_properties_t *prop;
+
+  if (!player)
+    return NULL;
+
+  /* try to use internal mrl? */
+  mrl_use_internal (player, &mrl);
+  if (!mrl)
+    return NULL;
+
+  if (!mrl->prop)
+    mrl_retrieve_properties (player, mrl);
+
+  prop = mrl->prop;
+  if (!prop)
+    return NULL;
+
+  switch (type)
+  {
+  case MRL_TYPE_AUDIO:
+  {
+    mrl_properties_audio_t *audio = prop->audio;
+    return audio && audio->codec ? strdup (audio->codec) : NULL;
+  }
+
+  case MRL_TYPE_VIDEO:
+  {
+    mrl_properties_video_t *video = prop->video;
+    return video && video->codec ? strdup (video->codec) : NULL;
+  }
+
+  default:
+    return NULL;
+  }
+}
+
 /*****************************************************************************/
 /*                   MRL Internal (Supervisor) functions                     */
 /*****************************************************************************/
@@ -973,55 +1012,17 @@
 char *
 mrl_sv_get_audio_codec (player_t *player, mrl_t *mrl)
 {
-  mrl_properties_t *prop;
-  mrl_properties_audio_t *audio;
-
-  plog (player, PLAYER_MSG_INFO, MODULE_NAME, __FUNCTION__);
-
-  if (!player)
-    return NULL;
-
-  /* try to use internal mrl? */
-  mrl_use_internal (player, &mrl);
-  if (!mrl)
-    return NULL;
-
-  if (!mrl->prop)
-    mrl_retrieve_properties (player, mrl);
-
-  prop = mrl->prop;
-  if (!prop)
-    return NULL;
-
-  audio = prop->audio;
-  return audio && audio->codec ? strdup (audio->codec) : NULL;
+  plog (player, PLAYER_MSG_INFO, MODULE_NAME, __FUNCTION__);
+
+  return mrl_get_codec (player, mrl, MRL_TYPE_AUDIO);
 }

 char *
 mrl_sv_get_video_codec (player_t *player, mrl_t *mrl)
 {
-  mrl_properties_t *prop;
-  mrl_properties_video_t *video;
-
-  plog (player, PLAYER_MSG_INFO, MODULE_NAME, __FUNCTION__);
-
-  if (!player)
-    return NULL;
-
-  /* try to use internal mrl? */
-  mrl_use_internal (player, &mrl);
-  if (!mrl)
-    return NULL;
-
-  if (!mrl->prop)
-    mrl_retrieve_properties (player, mrl);
-
-  prop = mrl->prop;
-  if (!prop)
-    return NULL;
-
-  video = prop->video;
-  return video && video->codec ? strdup (video->codec) : NULL;
+  plog (player, PLAYER_MSG_INFO, MODULE_NAME, __FUNCTION__);
+
+  return mrl_get_codec (player, mrl, MRL_TYPE_VIDEO);
 }

 off_t


net: Fix after 56e658a

net: Fix after 56e658a

--- src/net/ipv4/tcp.c
+++ src/net/ipv4/tcp.c
@@ -990,7 +990,6 @@
 	iphdr_t *iph;
 	tcphdr_t *tcph;
 	union sock_pointer sock;
-	struct sock *sk;
 	int res;

 	assert(skb != NULL);
@@ -998,11 +997,12 @@
 	iph = ip_hdr(skb);
 	tcph = tcp_hdr(skb);
 	sock.tcp_sk = tcp_lookup(iph->daddr, tcph->dest, iph->saddr, tcph->source);
-	sk = &sock.tcp_sk->inet.sk;
-
-	if (sk->sk_encap_rcv) {
-		if (0 > (res = sk->sk_encap_rcv(sk, skb)))
+
+	if ((sock.sk != NULL) && (sock.sk->sk_encap_rcv != NULL)) {
+		res = sock.sk->sk_encap_rcv(sock.sk, skb);
+		if (res < 0) {
 			return -res;
+		}
 	}

 	packet_print(sock, skb, "=>", skb->nh.iph->saddr, skb->h.th->source);


init widget.decoration.style

init widget.decoration.style

--- src/widget.h
+++ src/widget.h
@@ -129,6 +129,7 @@
     widget->decoration.tag = NULL;
     widget->decoration.width = NULL;
     widget->decoration.height = NULL;
+    widget->decoration.style = NULL;
     widget->display = WIDGET_DISPLAY_INLINE;
     widget->path_info = NULL;
     widget->query_string = NULL;


use a less costly emplace_back instead of push_back

--- src/neural_layer.h
+++ src/neural_layer.h
@@ -67,7 +67,7 @@

         for (unsigned idx = 0; idx < output_size_; ++idx)
         {
-            neuron_list_.push_back(
+            neuron_list_.emplace_back(
                 neuron<VALUE, WEIGHT, FUNC>(weight_matrix_.at(idx))
             );
             std::generate_n(weight_matrix_.at(idx).begin(),


Compat and docs.

Compat and docs.

--- src/window.c
+++ src/window.c
@@ -765,7 +765,7 @@
 	return 0;
 }

-#if SDL_VERSION_ATLEAST(2, 0, 4)
+#if SDL_VERSION_ATLEAST(2, 0, 4) && LUA_VERSION_NUM >= 502

 typedef struct {
 	lua_State *L;	// The Lua state the callback is in
@@ -794,8 +794,16 @@
 /*
  * Window:setHitTest(func)
  *
+ * Sets the HitTest callback for a window.
+ * It is highly recommended that this is called in the same thread that
+ * initialized video and calls SDL.pollEvent().
+ *
  * Arguments:
  *	func a callback function or nil to clear the hit-test callback.
+ *
+ * Returns:
+ *	true or nil on failure
+ *	the error message on failure
  */
 static int
 l_window_setHitTest(lua_State *L)
@@ -834,11 +842,12 @@
 		if (SDL_SetWindowHitTest(w, (SDL_HitTest)hitTestCallback, cd) < 0)
 			return commonPushSDLError(L, 1);
 	}
-	else
+	else {
 		if (SDL_SetWindowHitTest(w, NULL, NULL) < 0)
 			return commonPushSDLError(L, 1);
-
-	return 0;
+	}
+
+	return commonPush(L, "b", 1);
 }

 #endif
@@ -918,7 +927,7 @@
 	{ "updateSurface",	l_window_updateSurface		},
 	{ "updateSurfaceRects",	l_window_updateSurfaceRects	},
 	{ "warpMouse",		l_window_warpMouse		},
-#if SDL_VERSION_ATLEAST(2, 0, 4)
+#if SDL_VERSION_ATLEAST(2, 0, 4) && LUA_VERSION_NUM >= 502
 	{ "setHitTest",		l_window_setHitTest		},
 #endif
 	{ NULL,			NULL				}