[cgi] reorder the CGI parsing

[cgi] reorder the CGI parsing

--- src/mod_cgi.c
+++ src/mod_cgi.c
@@ -55,6 +55,8 @@
 #define dbg(...)
 #endif

+#define cgi_dbg(...)
+
 static char str_null[] = "";
 static char str_gatewayinterface[] = "CGI/1.1";
 static char str_contenttype[] = "Content-Type";
@@ -72,6 +74,7 @@
 {
 	enum
 	{
+		STATE_SETUP,
 		STATE_START,
 		STATE_INFINISH,
 		STATE_HEADERCOMPLETE,
@@ -85,7 +88,7 @@

 	char *cgipath;
 	char *path_info;
-
+
 	pid_t pid;
 	int tocgi[2];
 	int fromcgi[2];
@@ -473,95 +476,66 @@
 	mod_cgi_ctx_t *ctx = (mod_cgi_ctx_t *)arg;
 	mod_cgi_config_t *config = ctx->mod->config;

-	if (ctx->pid == -1)
-	{
-		warn("cgi: pid -1");
-		return EREJECT;
-	}
-
-	if (ctx->pid == 0)
-	{
-		if (ctx->path_info)
-			free(ctx->path_info);
-		ctx->path_info = utils_urldecode(httpmessage_REQUEST(request,"uri"));
-		char *str = ctx->path_info;
-		if (str && config->docroot && ctx->cgipath == NULL)
-		{
-			int length = strlen(str);
-			length += strlen(config->docroot) + 1;
-
-			char *filepath;
-			filepath = calloc(1, length + 1);
-			snprintf(filepath, length + 1, "%s/%s", config->docroot, str);
-
-			if (utils_searchexp(str, config->deny) == ESUCCESS &&
-				utils_searchexp(str, config->allow) != ESUCCESS)
+	if (ctx->state == STATE_SETUP)
+	{
+		if (ctx->pid == -1)
+		{
+			warn("cgi: pid -1");
+			return EREJECT;
+		}
+
+		if (ctx->pid == 0)
+		{
+			if (ctx->path_info)
+				free(ctx->path_info);
+			ctx->path_info = utils_urldecode(httpmessage_REQUEST(request,"uri"));
+			char *str = ctx->path_info;
+			if (str && config->docroot && ctx->cgipath == NULL)
 			{
-				dbg("cgi: %s forbidden extension", ctx->path_info);
-				free(filepath);
-				return EREJECT;
+				int length = strlen(str);
+				length += strlen(config->docroot) + 1;
+
+				char *filepath;
+				filepath = calloc(1, length + 1);
+				snprintf(filepath, length + 1, "%s/%s", config->docroot, str);
+
+				if (utils_searchexp(str, config->deny) == ESUCCESS &&
+					utils_searchexp(str, config->allow) != ESUCCESS)
+				{
+					dbg("cgi: %s forbidden extension", ctx->path_info);
+					free(filepath);
+					return EREJECT;
+				}
+				struct stat filestat;
+				int ret = stat(filepath, &filestat);
+				if (ret != 0)
+				{
+					dbg("cgi: %s not found", ctx->path_info);
+					free(filepath);
+					return EREJECT;
+				}
+				if (S_ISDIR(filestat.st_mode))
+				{
+					dbg("cgi: %s is directory", ctx->path_info);
+					free(filepath);
+					return EREJECT;
+				}
+				/* at least user or group may execute the CGI */
+				if ((filestat.st_mode & (S_IXUSR | S_IXGRP)) != (S_IXUSR | S_IXGRP))
+				{
+					httpmessage_result(response, RESULT_404);
+					warn("cgi: %s access denied", ctx->path_info);
+					free(filepath);
+					return ESUCCESS;
+				}
+				dbg("cgi: run %s", filepath);
+				ctx->cgipath = filepath;
 			}
-			struct stat filestat;
-			int ret = stat(filepath, &filestat);
-			if (ret != 0)
-			{
-				dbg("cgi: %s not found", ctx->path_info);
-				free(filepath);
-				return EREJECT;
-			}
-			if (S_ISDIR(filestat.st_mode))
-			{
-				dbg("cgi: %s is directory", ctx->path_info);
-				free(filepath);
-				return EREJECT;
-			}
-			/* at least user or group may execute the CGI */
-			if ((filestat.st_mode & (S_IXUSR | S_IXGRP)) != (S_IXUSR | S_IXGRP))
-			{
-				httpmessage_result(response, RESULT_404);
-				warn("cgi: %s access denied", ctx->path_info);
-				free(filepath);
-				return ESUCCESS;
-			}
-			dbg("cgi: run %s", filepath);
-			ctx->cgipath = filepath;
-		}
-		ctx->pid = _mod_cgi_fork(ctx, request);
-	}
-
-	if (ctx->state >= STATE_OUTFINISH)
-	{
-		int status;
-#if defined(RESULT_302)
-		/**
-		 * RFC 3875 : 6.2.3
-		 */
-		const char *location = httpmessage_REQUEST(response, str_location);
-		if (location != NULL && location[0] != '\0')
-			httpmessage_result(response, RESULT_302);
-#endif
-		httpmessage_parsecgi(response, NULL, 0);
-		ret = waitpid(ctx->pid, &status, WNOHANG);
-		if (ret != 0 && WIFEXITED(status))
-		{
-			if (ctx->state & STATE_SHUTDOWN);
-				httpclient_shutdown(ctx->ctl);
-
-			ctx->state = STATE_END;
-			ctx->pid = 0;
-			ret = ESUCCESS;
-		}
-		else
-			ret = ECONTINUE;
-	}
-	else if (ctx->state >= STATE_CONTENTCOMPLETE)
-	{
-		ctx->state = STATE_OUTFINISH;
-		kill(ctx->pid, SIGTERM);
-		dbg("cgi complete");
-		ret = ECONTINUE;
-	}
-	else if (ctx->tocgi[1] > 0 && ctx->state <= STATE_INFINISH)
+			ctx->pid = _mod_cgi_fork(ctx, request);
+			ctx->state = STATE_START;
+		}
+	}
+	else if (ctx->tocgi[1] > 0 && ctx->state == STATE_START)
 	{
 		char *input;
 		int inputlen;
@@ -579,7 +553,11 @@
 			ctx->tocgi[1] = -1;
 		}
 	}
-	if (ctx->state >= STATE_INFINISH && ctx->state < STATE_OUTFINISH)
+	/**
+	 * when the request is complete the module must check the CGI immedialty
+	 * otherwise the client will wait more data from request
+	 */
+	if (ctx->state >= STATE_INFINISH && ctx->state < STATE_CONTENTCOMPLETE)
 	{
 		int sret;
 		fd_set rfds;
@@ -594,7 +572,7 @@
 			size = read(ctx->fromcgi[0], ctx->chunk, size);
 			if (size < 1)
 			{
-				ctx->state = STATE_OUTFINISH;
+				ctx->state = STATE_CONTENTCOMPLETE;
 				ret = ECONTINUE;
 				if (size < 0)
 				{
@@ -604,8 +582,8 @@
 			else
 			{
 				ctx->chunk[size] = 0;
-				//dbg("cgi: receive (%d)", size);
-				//dbg("cgi: receive (%d)\n%s", size, ctx->chunk);
+				cgi_dbg("cgi: receive (%d)", size);
+				cgi_dbg("cgi: receive (%d)\n%s", size, ctx->chunk);
 				/**
 				 * if content_length is not null, parcgi is able to
 				 * create the content.
@@ -613,32 +591,35 @@
 				 * to set the header.
 				 */
 				int rest = size;
-				while (rest > 0)
+				if (rest > 0)
 				{
 					ret = httpmessage_parsecgi(response, ctx->chunk, &rest);
-					//dbg("cgi: parse %d data %d %d", ret, size, rest);
-					//dbg("cgi: parse %d data %d %d\n%s#", ret, size, rest, ctx->chunk);
-					if (ret != EINCOMPLETE)
+					cgi_dbg("cgi: parse %d data %d %d", ret, size, rest);
+					cgi_dbg("cgi: parse %d data %d %d\n%s#", ret, size, rest, ctx->chunk);
+					if (ret == ECONTINUE && ctx->state < STATE_HEADERCOMPLETE)
 					{
-						char *offset = ctx->chunk;
-						if (ctx->state == STATE_INFINISH)
-						{
-						}
-						else if (size > 0 && rest == 0)
-						{
-							/**
-							 * The Content-Type may be added by the CGI
-							 */
-							httpmessage_addcontent(response, "none", offset, size);
-						}
+#if defined(RESULT_302)
+						/**
+						 * RFC 3875 : 6.2.3
+						 */
+						const char *location = httpmessage_REQUEST(response, str_location);
+						if (location != NULL && location[0] != '\0')
+							httpmessage_result(response, RESULT_302);
+#endif
 						ctx->state = STATE_HEADERCOMPLETE;
 					}
 					if (ret == ESUCCESS)
 					{
 						ctx->state = STATE_CONTENTCOMPLETE;
+						//parse_cgi is complete but not this module
 					}
 				}
 			}
+			/**
+			 * the request is completed to not wait more data the module
+			 * muest returns ECONTINUE or ESUCCESS now
+			 */
+			ret = ECONTINUE;
 		}
 		else
 		{
@@ -648,8 +629,28 @@
 			ret = ECONTINUE;
 		}
 	}
-	/* this mod returns EINCOMPLETE
-	 * because it needs to wait the end
+	else if (ctx->state == STATE_CONTENTCOMPLETE)
+	{
+		close(ctx->fromcgi[0]);
+		httpmessage_parsecgi(response, NULL, 0);
+		ret = ECONTINUE;
+		ctx->state = STATE_OUTFINISH | STATE_SHUTDOWN;
+	}
+	else if ((ctx->state & STATE_OUTFINISH) == STATE_OUTFINISH)
+	{
+		long long length;
+		ret = httpmessage_content(response, NULL, &length);
+		dbg("content len %d %lld", ret, length);
+		if (ret == 0)
+			ctx->state = STATE_END | STATE_SHUTDOWN;
+		ret = ECONTINUE;
+	}
+	else if ((ctx->state & STATE_END) == STATE_END)
+	{
+		ret = ESUCCESS;
+	}
+	/* this mod returns EINCOMPLETE
+	 * because it needs to wait the end
 	 * to know the length of the content */
 	return ret;
 }


runtime: fix heapdump bugs.

runtime: fix heapdump bugs.

Iterate the right number of times in arrays and channels.
Handle channels with zero-sized objects in them.
Output longer type names if we have them.
Compute argument offset correctly.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/82980043

--- src/pkg/runtime/heapdump.c
+++ src/pkg/runtime/heapdump.c
@@ -186,7 +186,14 @@
 	dumpint(TagType);
 	dumpint((uintptr)t);
 	dumpint(t->size);
-	dumpstr(*t->string);
+	if(t->x == nil || t->x->pkgPath == nil || t->x->name == nil) {
+		dumpstr(*t->string);
+	} else {
+		dumpint(t->x->pkgPath->len + 1 + t->x->name->len);
+		write(t->x->pkgPath->str, t->x->pkgPath->len);
+		write((byte*)".", 1);
+		write(t->x->name->str, t->x->name->len);
+	}
 	dumpbool(t->size > PtrSize || (t->kind & KindNoPointers) == 0);
 	dumpfields((uintptr*)t->gc + 1);
 }
@@ -375,7 +382,7 @@
 	dumpint(FieldKindEol);

 	// Record arg info for parent.
-	child->argoff = s->argp - (byte*)s->sp;
+	child->argoff = s->argp - (byte*)s->fp;
 	child->arglen = s->arglen;
 	child->sp = (byte*)s->sp;
 	child->depth++;
@@ -853,11 +860,13 @@
 		playgcprog(0, (uintptr*)type->gc + 1, dumpeface_callback, obj);
 		break;
 	case TypeInfo_Array:
-		for(i = 0; i < size; i += type->size)
+		for(i = 0; i <= size - type->size; i += type->size)
 			playgcprog(i, (uintptr*)type->gc + 1, dumpeface_callback, obj);
 		break;
 	case TypeInfo_Chan:
-		for(i = runtime·Hchansize; i < size; i += type->size)
+		if(type->size == 0) // channels may have zero-sized objects in them
+			break;
+		for(i = runtime·Hchansize; i <= size - type->size; i += type->size)
 			playgcprog(i, (uintptr*)type->gc + 1, dumpeface_callback, obj);
 		break;
 	}


runtime: faster mcentral alloc.

runtime: faster mcentral alloc.

Reduce individual object handling by anticipating how much of them are servable.

Not a chunked transfer cache, but decent enough to make sure the bottleneck is not here.

Mac OSX, median of 10 runs:

benchmark                 old ns/op    new ns/op    delta
BenchmarkBinaryTree17    5358937333   4892813012   -8.70%
BenchmarkFannkuch11      3257752475   3315436116   +1.77%
BenchmarkGobDecode         23277349     23001114   -1.19%
BenchmarkGobEncode         14367327     14262925   -0.73%
BenchmarkGzip             441045541    440451719   -0.13%
BenchmarkGunzip           139117663    139622494   +0.36%
BenchmarkJSONEncode        45715854     45687802   -0.06%
BenchmarkJSONDecode       103949570    106530032   +2.48%
BenchmarkMandelbrot200      4542462      4548290   +0.13%
BenchmarkParse              7790558      7557540   -2.99%
BenchmarkRevcomp          831436684    832510381   +0.13%
BenchmarkTemplate         133789824    133007337   -0.58%

benchmark                  old MB/s     new MB/s  speedup
BenchmarkGobDecode            32.82        33.33    1.02x
BenchmarkGobEncode            53.42        53.86    1.01x
BenchmarkGzip                 43.70        44.01    1.01x
BenchmarkGunzip              139.09       139.14    1.00x
BenchmarkJSONEncode           42.69        42.56    1.00x
BenchmarkJSONDecode           18.78        17.91    0.95x
BenchmarkParse                 7.37         7.67    1.04x
BenchmarkRevcomp             306.83       305.70    1.00x
BenchmarkTemplate             14.57        14.56    1.00x

R=rsc, dvyukov
CC=golang-dev
https://golang.org/cl/7005055

--- src/pkg/runtime/mcentral.c
+++ src/pkg/runtime/mcentral.c
@@ -34,12 +34,13 @@
 // Allocate up to n objects from the central free list.
 // Return the number of objects allocated.
 // The objects are linked together by their first words.
-// On return, *pstart points at the first object and *pend at the last.
+// On return, *pstart points at the first object.
 int32
 runtime·MCentral_AllocList(MCentral *c, int32 n, MLink **pfirst)
 {
-	MLink *first, *last, *v;
-	int32 i;
+	MSpan *s;
+	MLink *first, *last;
+	int32 cap, avail, i;

 	runtime·lock(c);
 	// Replenish central list if empty.
@@ -50,41 +51,34 @@
 			return 0;
 		}
 	}
-
-	// Copy from list, up to n.
+	s = c->nonempty.next;
+	cap = (s->npages << PageShift) / s->elemsize;
+	avail = cap - s->ref;
+	if(avail < n)
+		n = avail;
+
 	// First one is guaranteed to work, because we just grew the list.
-	first = MCentral_Alloc(c);
+	first = s->freelist;
 	last = first;
-	for(i=1; i<n && (v = MCentral_Alloc(c)) != nil; i++) {
-		last->next = v;
-		last = v;
-	}
+	for(i=1; i<n; i++) {
+		last = last->next;
+	}
+	s->freelist = last->next;
 	last->next = nil;
-	c->nfree -= i;
+	s->ref += n;
+	c->nfree -= n;
+
+	if(n == avail) {
+		if(s->freelist != nil || s->ref != cap) {
+			runtime·throw("invalid freelist");
+		}
+		runtime·MSpanList_Remove(s);
+		runtime·MSpanList_Insert(&c->empty, s);
+	}

 	runtime·unlock(c);
 	*pfirst = first;
-	return i;
-}
-
-// Helper: allocate one object from the central free list.
-static void*
-MCentral_Alloc(MCentral *c)
-{
-	MSpan *s;
-	MLink *v;
-
-	if(runtime·MSpanList_IsEmpty(&c->nonempty))
-		return nil;
-	s = c->nonempty.next;
-	s->ref++;
-	v = s->freelist;
-	s->freelist = v->next;
-	if(s->freelist == nil) {
-		runtime·MSpanList_Remove(s);
-		runtime·MSpanList_Insert(&c->empty, s);
-	}
-	return v;
+	return n;
 }

 // Free n objects back into the central free list.


Revert "PL/Python: Fix potential NULL pointer dereference"

This reverts commit e42e2f38907681c48c43f49c5ec9f9f41a9aa9a5.

It's not safe to return in the middle of a PG_TRY block, so this will
have to be done differently.

--- src/pl/plpython/plpy_spi.c
+++ src/pl/plpython/plpy_spi.c
@@ -361,10 +361,7 @@

 	result = (PLyResultObject *) PLy_result_new();
 	if (!result)
-	{
-		SPI_freetuptable(tuptable);
-		return NULL;
-	}
+		return NULL;
 	Py_DECREF(result->status);
 	result->status = PyInt_FromLong(status);

@@ -417,9 +414,7 @@
 				if (!result->rows)
 				{
 					Py_DECREF(result);
-					MemoryContextDelete(cxt);
-					SPI_freetuptable(tuptable);
-					return NULL;
+					result = NULL;
 				}
 				else
 				{


MsgPack: Removed insert() receiving ARRAY/MAP, added emplace()

--- src/msgpack.h
+++ src/msgpack.h
@@ -151,23 +151,22 @@
 	MsgPack::iterator _find(size_t pos);
 	MsgPack::const_iterator _find(size_t pos) const;

+	template <typename M, typename = std::enable_if_t<std::is_same<MsgPack, std::decay_t<M>>::value>>
+	std::pair<size_t, MsgPack::iterator> _erase(M&& o);
 	std::pair<size_t, MsgPack::iterator> _erase(const std::string& key);
 	std::pair<size_t, MsgPack::iterator> _erase(size_t pos);

+	template <typename M, typename T, typename = std::enable_if_t<std::is_same<MsgPack, std::decay_t<M>>::value>>
+	std::pair<MsgPack*, bool> _put(M&& o, T&& val, bool overwrite);
 	template <typename T>
 	std::pair<MsgPack*, bool> _put(const std::string& key, T&& val, bool overwrite);
-
 	template <typename T>
 	std::pair<MsgPack*, bool> _put(size_t pos, T&& val, bool overwrite);

+	template <typename M, typename T, typename = std::enable_if_t<std::is_same<MsgPack, std::decay_t<M>>::value>>
+	std::pair<MsgPack*, bool> _insert(M&& o, T&& val, bool overwrite);
 	template <typename T>
 	std::pair<MsgPack*, bool> _insert(size_t pos, T&& val, bool overwrite);
-
-	template <typename M, typename T, typename = std::enable_if_t<std::is_same<MsgPack, std::decay_t<M>>::value>>
-	std::pair<MsgPack*, bool> _put(M&& o, T&& val, bool overwrite);
-
-	template <typename M, typename T, typename = std::enable_if_t<std::is_same<MsgPack, std::decay_t<M>>::value>>
-	std::pair<MsgPack*, bool> _insert(M&& o, T&& val, bool overwrite);

 	void _fill(bool recursive, bool lock);
 	void _fill(bool recursive, bool lock) const;
@@ -185,14 +184,15 @@
 	template <typename T>
 	MsgPack::iterator put(size_t pos, T&& val);

+	template <typename K, typename V>
+	std::pair<MsgPack::iterator, bool> insert(const std::pair<K&&, V&&>& val);
+
 	template <typename M, typename T, typename = std::enable_if_t<std::is_same<MsgPack, std::decay_t<M>>::value>>
-	std::pair<MsgPack::iterator, bool> insert(M&& o, T&& val);
+	std::pair<MsgPack::iterator, bool> emplace(M&& o, T&& val);
 	template <typename T>
-	std::pair<MsgPack::iterator, bool> insert(const std::string& s, T&& val);
+	std::pair<MsgPack::iterator, bool> emplace(const std::string& s, T&& val);
 	template <typename T>
-	std::pair<MsgPack::iterator, bool> insert(size_t pos, T&& val);
-	template <typename T, typename = std::enable_if_t<std::is_constructible<MsgPack, T>::value>>
-	MsgPack::iterator insert(T&& v);
+	std::pair<MsgPack::iterator, bool> emplace(size_t pos, T&& val);

 	template <typename T>
 	void push_back(T&& v);
@@ -240,6 +240,8 @@
 	iterator erase(iterator it);

 	void clear() noexcept;
+
+	std::size_t hash() const;

 	explicit operator bool() const;

@@ -277,7 +279,6 @@
 	MsgPack::Type getType() const noexcept;
 	std::string getStrType() const noexcept;

-	std::size_t hash() const;
 	bool operator==(const MsgPack& other) const;
 	bool operator!=(const MsgPack& other) const;
 	MsgPack operator+(double val);
@@ -962,6 +963,24 @@
 }

+template <typename M, typename>
+inline std::pair<size_t, MsgPack::iterator> MsgPack::_erase(M&& o) {
+	switch (o._body->getType()) {
+		case Type::STR:
+			return _erase(std::string(o._body->_obj->via.str.ptr, o._body->_obj->via.str.size));
+		case Type::NEGATIVE_INTEGER:
+			if (o._body->_obj->via.i64 < 0) {
+				THROW(msgpack::type_error);
+			}
+			return _erase(static_cast<size_t>(o._body->_obj->via.i64));
+		case Type::POSITIVE_INTEGER:
+			return _erase(static_cast<size_t>(o._body->_obj->via.u64));
+		default:
+			THROW(msgpack::type_error);
+	}
+}
+
+
 inline std::pair<size_t, MsgPack::iterator> MsgPack::_erase(const std::string& key) {
 	switch (_body->getType()) {
 		case Type::UNDEFINED:
@@ -1037,57 +1056,21 @@
 }

-inline MsgPack& MsgPack::path(const std::vector<std::string>& path) {
-	auto current = this;
-	for (const auto& s : path) {
-		switch (current->_const_body->getType()) {
-			case Type::MAP: {
-				current = &current->at(s);
-				break;
-			}
-			case Type::ARRAY: {
-				std::string::size_type sz;
-				int pos = std::stoi(s, &sz);
-				if (pos < 0 || sz != s.size()) {
-					THROW(invalid_argument, "The index for the array must be a positive integer, it is: " + s);
-				}
-				current = &current->at(pos);
-				break;
-			}
-
-			default:
-				THROW(invalid_argument, "The container must be a map or an array to access: " + s);
-		}
-	}
-
-	return *current;
-}
-
-
-inline const MsgPack& MsgPack::path(const std::vector<std::string>& path) const {
-	auto current = this;
-	for (const auto& s : path) {
-		switch (current->getType()) {
-			case Type::MAP: {
-				current = &current->at(s);
-				break;
-			}
-			case Type::ARRAY: {
-				std::string::size_type sz;
-				int pos = std::stoi(s, &sz);
-				if (pos < 0 || sz != s.size()) {
-					THROW(invalid_argument, "The index for the array must be a positive integer, it is: " + s);
-				}
-				current = &current->at(pos);
-				break;
-			}
-
-			default:
-				THROW(invalid_argument, "The container must be a map or an array to access: " + s);
-		}
-	}
-
-	return *current;
+template <typename M, typename T, typename>
+inline std::pair<MsgPack*, bool> MsgPack::_put(M&& o, T&& val, bool overwrite) {
+	switch (o._body->getType()) {
+		case Type::STR:
+			return _put(std::string(o._body->_obj->via.str.ptr, o._body->_obj->via.str.size), std::forward<T>(val), overwrite);
+		case Type::NEGATIVE_INTEGER:
+			if (o._body->_obj->via.i64 < 0) {
+				THROW(msgpack::type_error);
+			}
+			return _put(static_cast<size_t>(o._body->_obj->via.i64), std::forward<T>(val), overwrite);
+		case Type::POSITIVE_INTEGER:
+			return _put(static_cast<size_t>(o._body->_obj->via.u64), std::forward<T>(val), overwrite);
+		default:
+			THROW(msgpack::type_error);
+	}
 }

@@ -1164,24 +1147,6 @@

 template <typename M, typename T, typename>
-inline std::pair<MsgPack*, bool> MsgPack::_put(M&& o, T&& val, bool overwrite) {
-	switch (o._body->getType()) {
-		case Type::STR:
-			return _put(std::string(o._body->_obj->via.str.ptr, o._body->_obj->via.str.size), std::forward<T>(val), overwrite);
-		case Type::NEGATIVE_INTEGER:
-			if (o._body->_obj->via.i64 < 0) {
-				THROW(msgpack::type_error);
-			}
-			return _put(static_cast<size_t>(o._body->_obj->via.i64), std::forward<T>(val), overwrite);
-		case Type::POSITIVE_INTEGER:
-			return _put(static_cast<size_t>(o._body->_obj->via.u64), std::forward<T>(val), overwrite);
-		default:
-			THROW(msgpack::type_error);
-	}
-}
-
-
-template <typename M, typename T, typename>
 inline std::pair<MsgPack*, bool> MsgPack::_insert(M&& o, T&& val, bool overwrite) {
 	switch (o._body->getType()) {
 		case Type::STR:
@@ -1238,61 +1203,6 @@
 		default:
 			THROW(msgpack::type_error);
 	}
-}
-
-
-template <typename M, typename T, typename>
-inline MsgPack::iterator MsgPack::put(M&& o, T&& val) {
-	_fill(false, false);
-	auto pair = _put(std::forward<M>(o), std::forward<T>(val), true);
-	return MsgPack::Iterator<MsgPack>(this, pair.first->_body->_pos);
-}
-
-
-template <typename M, typename T, typename>
-inline std::pair<MsgPack::iterator, bool> MsgPack::insert(M&& o, T&& val) {
-	_fill(false, false);
-	auto pair = _insert(std::forward<M>(o), std::forward<T>(val), false);
-	return std::make_pair(MsgPack::Iterator<MsgPack>(this, pair.first->_body->_pos), pair.second);
-}
-
-
-template <typename T>
-inline MsgPack::iterator MsgPack::put(const std::string& s, T&& val) {
-	_fill(false, false);
-	auto pair = _put(s, std::forward<T>(val), true);
-	return MsgPack::Iterator<MsgPack>(this, pair.first->_body->_pos);
-}
-
-
-template <typename T>
-inline std::pair<MsgPack::iterator, bool> MsgPack::insert(const std::string& s, T&& val) {
-	_fill(false, false);
-	auto pair = _put(s, std::forward<T>(val), false);
-	return std::make_pair(MsgPack::Iterator<MsgPack>(this, pair.first->_body->_pos), pair.second);
-}
-
-
-template <typename T>
-inline MsgPack::iterator MsgPack::put(size_t pos, T&& val) {
-	_fill(false, false);
-	auto pair = _put(pos, std::forward<T>(val), true);
-	return MsgPack::Iterator<MsgPack>(this, pair.first->_body->_pos);
-}
-
-
-template <typename T>
-inline std::pair<MsgPack::iterator, bool> MsgPack::insert(size_t pos, T&& val) {
-	_fill(false, false);
-	auto pair = _insert(pos, std::forward<T>(val), false);
-	return std::make_pair(MsgPack::Iterator<MsgPack>(this, pair.first->_body->_pos), pair.second);
-}
-
-
-template <typename T>
-inline void MsgPack::push_back(T&& v) {
-	_fill(false, false);
-	_put(size(), std::forward<T>(v), false);
 }

@@ -1328,6 +1238,67 @@
 }

+template <typename M, typename T, typename>
+inline MsgPack::iterator MsgPack::put(M&& o, T&& val) {
+	_fill(false, false);
+	auto pair = _put(std::forward<M>(o), std::forward<T>(val), true);
+	return MsgPack::Iterator<MsgPack>(this, pair.first->_body->_pos);
+}
+
+
+template <typename T>
+inline MsgPack::iterator MsgPack::put(const std::string& s, T&& val) {
+	_fill(false, false);
+	auto pair = _put(s, std::forward<T>(val), true);
+	return MsgPack::Iterator<MsgPack>(this, pair.first->_body->_pos);
+}
+
+
+template <typename T>
+inline MsgPack::iterator MsgPack::put(size_t pos, T&& val) {
+	_fill(false, false);
+	auto pair = _put(pos, std::forward<T>(val), true);
+	return MsgPack::Iterator<MsgPack>(this, pair.first->_body->_pos);
+}
+
+
+template <typename M, typename T, typename>
+inline std::pair<MsgPack::iterator, bool> MsgPack::emplace(M&& o, T&& val) {
+	_fill(false, false);
+	auto pair = _insert(std::forward<M>(o), std::forward<T>(val), false);
+	return std::make_pair(MsgPack::Iterator<MsgPack>(this, pair.first->_body->_pos), pair.second);
+}
+
+
+template <typename T>
+inline std::pair<MsgPack::iterator, bool> MsgPack::emplace(const std::string& s, T&& val) {
+	_fill(false, false);
+	auto pair = _put(s, std::forward<T>(val), false);
+	return std::make_pair(MsgPack::Iterator<MsgPack>(this, pair.first->_body->_pos), pair.second);
+}
+
+
+template <typename T>
+inline std::pair<MsgPack::iterator, bool> MsgPack::emplace(size_t pos, T&& val) {
+	_fill(false, false);
+	auto pair = _insert(pos, std::forward<T>(val), false);
+	return std::make_pair(MsgPack::Iterator<MsgPack>(this, pair.first->_body->_pos), pair.second);
+}
+
+
+template <typename K, typename V>
+inline std::pair<MsgPack::iterator, bool> MsgPack::insert(const std::pair<K&&, V&&>& val) {
+	return emplace(std::forward<K>(val.first), std::forward<V>(val.second));
+}
+
+
+template <typename T>
+inline void MsgPack::push_back(T&& v) {
+	_fill(false, false);
+	_put(size(), std::forward<T>(v), false);
+}
+
+
 inline void MsgPack::lock() const {
 	_fill(true, true);
 }
@@ -1336,41 +1307,6 @@
 template <typename T>
 inline decltype(auto) MsgPack::external(std::function<T(const msgpack::object&)> f) const {
 	return f(*_body->_obj);
-}
-
-
-template <typename T, typename>
-inline MsgPack::iterator MsgPack::insert(T&& v) {
-	_fill(false, false);
-	MsgPack o(v);
-	auto pos = size();
-	switch (o._body->getType()) {
-		case Type::ARRAY:
-			if (o._body->_obj->via.array.size % 2) {
-				break;
-			}
-			for (auto o_it = o.begin(); o_it != o.end(); ++o_it) {
-				auto key = *o_it;
-				auto val = *++o_it;
-				if (key._body->getType() != Type::STR) {
-					break;
-				}
-				auto pair = _put(key, val, false);
-				pos = pair.first->_body->_pos;
-			}
-			break;
-		case Type::MAP:
-			for (auto& key : o) {
-				auto& val = o.at(key);
-				auto pair = _put(key, val, false);
-				pos = pair.first->_body->_pos;
-			}
-			break;
-		default:
-			break;
-	}
-
-	return MsgPack::Iterator<MsgPack>(this, pos);
 }

@@ -1544,6 +1480,60 @@
 		default:
 			THROW(msgpack::type_error);
 	}
+}
+
+
+inline MsgPack& MsgPack::path(const std::vector<std::string>& path) {
+	auto current = this;
+	for (const auto& s : path) {
+		switch (current->_const_body->getType()) {
+			case Type::MAP: {
+				current = &current->at(s);
+				break;
+			}
+			case Type::ARRAY: {
+				std::string::size_type sz;
+				int pos = std::stoi(s, &sz);
+				if (pos < 0 || sz != s.size()) {
+					THROW(invalid_argument, "The index for the array must be a positive integer, it is: " + s);
+				}
+				current = &current->at(pos);
+				break;
+			}
+
+			default:
+				THROW(invalid_argument, "The container must be a map or an array to access: " + s);
+		}
+	}
+
+	return *current;
+}
+
+
+inline const MsgPack& MsgPack::path(const std::vector<std::string>& path) const {
+	auto current = this;
+	for (const auto& s : path) {
+		switch (current->getType()) {
+			case Type::MAP: {
+				current = &current->at(s);
+				break;
+			}
+			case Type::ARRAY: {
+				std::string::size_type sz;
+				int pos = std::stoi(s, &sz);
+				if (pos < 0 || sz != s.size()) {
+					THROW(invalid_argument, "The index for the array must be a positive integer, it is: " + s);
+				}
+				current = &current->at(pos);
+				break;
+			}
+
+			default:
+				THROW(invalid_argument, "The container must be a map or an array to access: " + s);
+		}
+	}
+
+	return *current;
 }

@@ -1642,19 +1632,7 @@
 template <typename M, typename>
 inline size_t MsgPack::erase(M&& o) {
 	_fill(false, false);
-	switch (o._body->getType()) {
-		case Type::STR:
-			return _erase(std::string(o._body->_obj->via.str.ptr, o._body->_obj->via.str.size)).first;
-		case Type::NEGATIVE_INTEGER:
-			if (o._body->_obj->via.i64 < 0) {
-				THROW(msgpack::type_error);
-			}
-			return _erase(static_cast<size_t>(o._body->_obj->via.i64)).first;
-		case Type::POSITIVE_INTEGER:
-			return _erase(static_cast<size_t>(o._body->_obj->via.u64)).first;
-		default:
-			THROW(msgpack::type_error);
-	}
+	return _erase(std::forward<M>(o)).first;
 }

@@ -1691,6 +1669,29 @@
 			break;
 		default:
 			break;
+	}
+}
+
+
+inline std::size_t MsgPack::hash() const {
+	switch (_body->getType()) {
+		case Type::MAP: {
+			_fill(false, false);
+			size_t pos = 0;
+			std::size_t hash = 0;
+			const auto pend = &_body->_obj->via.map.ptr[_body->_obj->via.map.size];
+			for (auto p = &_body->_obj->via.map.ptr[pos]; p != pend; ++p, ++pos) {
+				if (p->key.type != msgpack::type::STR) {
+					THROW(msgpack::type_error);
+				}
+				auto val = MsgPack(std::make_shared<Body>(_body->_zone, _body->_base, _body, true, 0, nullptr, &p->val));
+				hash ^= std::hash<std::string>{}(std::string(p->key.via.str.ptr, p->key.via.str.size));
+				hash ^= val.hash();
+			}
+			return hash;
+		}
+		default:
+			return std::hash<std::string>{}(serialise());
 	}
 }

@@ -2008,28 +2009,6 @@
 }

-inline std::size_t MsgPack::hash() const {
-	switch (_body->getType()) {
-		case Type::MAP: {
-			size_t pos = 0;
-			std::size_t hash = 0;
-			const auto pend = &_body->_obj->via.map.ptr[_body->_obj->via.map.size];
-			for (auto p = &_body->_obj->via.map.ptr[pos]; p != pend; ++p, ++pos) {
-				if (p->key.type != msgpack::type::STR) {
-					THROW(msgpack::type_error);
-				}
-				auto val = MsgPack(std::make_shared<Body>(_body->_zone, _body->_base, _body, true, 0, nullptr, &p->val));
-				hash ^= std::hash<std::string>{}(std::string(p->key.via.str.ptr, p->key.via.str.size));
-				hash ^= val.hash();
-			}
-			return hash;
-		}
-		default:
-			return std::hash<std::string>{}(serialise());
-	}
-}
-
-
 inline bool MsgPack::operator==(const MsgPack& other) const {
 	return this == &other || *_const_body->_obj == *other._const_body->_obj;
 }


Switch: Add argv loading

Switch: Add argv loading

--- src/platform/switch/main.c
+++ src/platform/switch/main.c
@@ -524,7 +524,16 @@
 	_mapKey(&runner.params.keyMap, AUTO_INPUT, KEY_DRIGHT, GUI_INPUT_RIGHT);

 	audoutStartAudioOut();
-	mGUIRunloop(&runner);
+
+	if (argc > 1) {
+		size_t i;
+		for (i = 0; runner.keySources[i].id; ++i) {
+			mInputMapLoad(&runner.params.keyMap, runner.keySources[i].id, mCoreConfigGetInput(&runner.config));
+		}
+		mGUIRun(&runner, argv[1]);
+	} else {
+		mGUIRunloop(&runner);
+	}

 	glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
 	glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);


libtirpc-0.1.10 - fix rpc_createerr tsd create

The pthread_getspecific() call returns either the address of the tsd or
NULL and a call to pthread_getspecific() on a key value not obtained by a
call to pthread_key_create() is undefined.

The pthread_key_create() call returns either zero or a negative error
code.

So the __rpc_createerr() routine looks kinda broken.

Signed-off-by: Ian Kent <8eb244bbad33301d1dd6563ddaa6aaafb9f45cfc@redhat.com>
Signed-off-by: Steve Dickson <305cc9d5027c0f4e08c2697d4cabde07a8221669@redhat.com>

--- src/mt_misc.c
+++ src/mt_misc.c
@@ -91,27 +91,24 @@
 __rpc_createerr()
 {
 	static thread_key_t rce_key = -1;
-	struct rpc_createerr *rce_addr = 0;
+	struct rpc_createerr *rce_addr;

-	if ((rce_addr = (struct rpc_createerr *)thr_getspecific(rce_key))
-		       	!= (struct rpc_createerr *)-1) {
-		mutex_lock(&tsd_lock);
-		if (thr_keycreate(&rce_key, free) != -1) {
-			mutex_unlock(&tsd_lock);
-			return (&rpc_createerr);
-		}
-		mutex_unlock(&tsd_lock);
-	}
+	mutex_lock(&tsd_lock);
+	if (rce_key == -1)
+		thr_keycreate(&rce_key, free);
+	mutex_unlock(&tsd_lock);
+
+	rce_addr = (struct rpc_createerr *)thr_getspecific(rce_key);
 	if (!rce_addr) {
 		rce_addr = (struct rpc_createerr *)
 			malloc(sizeof (struct rpc_createerr));
-		if (thr_setspecific(rce_key, (void *) rce_addr) != 0) {
+		if (!rce_addr ||
+		    thr_setspecific(rce_key, (void *) rce_addr) != 0) {
 			if (rce_addr)
 				free(rce_addr);
 			return (&rpc_createerr);
 		}
 		memset(rce_addr, 0, sizeof (struct rpc_createerr));
-		return (rce_addr);
 	}
 	return (rce_addr);
 }


Only care about orientation update time right now

--- src/platforms/Quadcopter.h
+++ src/platforms/Quadcopter.h
@@ -32,11 +32,11 @@
 ///////////

 void isrCallback(){
+    sensors.update();
     tic(0);
-    sensors.update();
     orientation.update(sensors);
+    toc(0);
     output.update(orientation);
-    toc(0);
 }
 void updatePID(float d){
     using namespace AirSettings;


src/netbase.h: Fix endian in CNetAddr serialization

We've chosen to htons/ntohs explicitly on reading and writing
(I do not know why). But as READWRITE already does an endian swap
on big endian, this means the port number gets switched around,
which was what we were trying to avoid in the first place. So
to make this compatible, serialize it as FLATDATA.

--- src/netbase.h
+++ src/netbase.h
@@ -162,7 +162,7 @@
         inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
             READWRITE(FLATDATA(ip));
             unsigned short portN = htons(port);
-            READWRITE(portN);
+            READWRITE(FLATDATA(portN));
             if (ser_action.ForRead())
                  port = ntohs(portN);
         }


include <arpa/inet.h> for inet_pton

include <arpa/inet.h> for inet_pton

--- src/nfsping.h
+++ src/nfsping.h
@@ -11,6 +11,7 @@
 #include <time.h>
 #include <signal.h>
 #include <netinet/in.h>
+#include <arpa/inet.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netdb.h>


none eeprom/flash OTSIM900LinkConfig get funciton

--- content/OTRadioLink/utility/OTSIM900Link_OTSIM900Link.h
+++ content/OTRadioLink/utility/OTSIM900Link_OTSIM900Link.h
@@ -132,6 +132,8 @@
                         break;
                         }
                     }
+#else
+                c = *src;
 #endif // ARDUINO_ARCH_AVR
                 return c;
                 }


Checking for option dependencies implemented

--- src/options.c
+++ src/options.c
@@ -135,6 +135,30 @@
         fprintf(stderr, "   ");
         nc_print_option(ctx, opt_index, stderr);
         fprintf(stderr, "\n");
+    }
+    exit(1);
+}
+
+static void nc_option_requires(struct nc_parse_context *ctx, int opt_index) {
+    unsigned long mask;
+    int i;
+    struct nc_option *opt;
+
+    fprintf(stderr, "%s: Option", ctx->argv[0]);
+    nc_print_option(ctx, opt_index, stderr);
+    fprintf(stderr, "requires at least one of the following options:\n");
+
+    mask = ctx->options[opt_index].requires_mask;
+    for(i = 0;; ++i) {
+        opt = &ctx->options[i];
+        if(!opt->longname)
+            break;
+        if(opt->mask_set & mask) {
+            fprintf(stderr, "    --%s\n", opt->longname);
+            if(opt->shortname) {
+                fprintf(stderr, "    -%c\n", opt->shortname);
+            }
+        }
     }
     exit(1);
 }
@@ -351,7 +375,7 @@
                 if(!*a) {  // Matches end of option name
                     best_match = i;
                     longest_prefix = cur_prefix;
-                    break;
+                    goto finish;
                 }
                 if(cur_prefix == longest_prefix) {
                     best_match = -1;  // Ambiguity
@@ -365,6 +389,7 @@
             }
         }
     }
+finish:
     if(best_match >= 0) {
         opt = &ctx->options[best_match];
         ctx->last_option_usage[best_match] = ctx->data;
@@ -444,6 +469,22 @@
     }
 }

+void nn_check_requires(struct nc_parse_context *ctx) {
+    int i;
+    struct nc_option *opt;
+
+    for(i = 0;; ++i) {
+        opt = &ctx->options[i];
+        if(!opt->longname)
+            break;
+        if(!ctx->last_option_usage[i])
+            continue;
+        if(opt->requires_mask && !(opt->requires_mask & ctx->mask)) {
+            nc_option_requires(ctx, i);
+        }
+    }
+}
+
 void nc_parse_options(struct nc_option *options, void *target,
                       int argc, char **argv) {
     struct nc_parse_context ctx;
@@ -468,6 +509,8 @@
         nc_parse_arg(&ctx);
     }

+    nn_check_requires(&ctx);
+
     free(ctx.last_option_usage);

 }


- allow detection of AFS to force v4 conversion on

--- src/options.c
+++ src/options.c
@@ -328,15 +328,15 @@
 	options->v4 = option_b(pamh, argc, argv,
 			       ctx, options->realm, "krb4_convert");
 	if (options->v4 == -1) {
-		/* default is to have this behavior disabled */
+		/* default is to have this behavior disabled... */
 		options->v4 = 0;
-		/* unless /afs is on a different device from /, which suggests
-		 * that AFS is running */
-		if (stat("/", &stroot) == 0) {
-			if (stat("/afs", &stafs) == 0) {
-				if (stroot.st_dev != stafs.st_dev) {
-					options->v4 = 1;
-				}
+	}
+	/* ... unless /afs is on a different device from /, which suggests that
+	 * AFS is running */
+	if (stat("/", &stroot) == 0) {
+		if (stat("/afs", &stafs) == 0) {
+			if (stroot.st_dev != stafs.st_dev) {
+				options->v4 = 1;
 			}
 		}
 	}


Updated options_print_usage() in options.c.

--- src/options.c
+++ src/options.c
@@ -99,13 +99,18 @@

 int options_print_usage(option_context_pt options, FILE *out) {
-	fprintf(out, "\n%s\n\nUsage: %s%s\nwhere OPTIONS can be\n\n", options->banner, options->cmd, options->description);
+	fprintf(out, "NAME\n\n  %s - %s\n\nSYNOPSYS\n\n  %s %s\n\n", options->cmd, options->description, options->cmd, options->synopsis);
 	option_entry_pt opt = options->ops;
+	if(opt->character) {
+		fprintf(out, "OPTIONS\n\n");
+	}
 	while(opt->character) {
 		fprintf(out, "  -%c %8s %s\n", opt->character, option_arg_type_to_string(opt->arg_type), opt->usage);
 		opt++;
 	}
-	fprintf(out, "\n");
+	if(options->banner) {
+		fprintf(out, "\nVERSION\n\n%s\n", options->banner);
+	}
 	return 0;
 }


Added a more descriptive line for --ignore-panel.

--- src/options.c
+++ src/options.c
@@ -158,7 +158,7 @@
   "                                    visitors count.\n"
   "  --double-decode                 - Decode double-encoded values.\n"
   "  --ignore-crawlers               - Ignore crawlers.\n"
-  "  --ignore-panel=PANEL            - Ignore parsing the given panel.\n"
+  "  --ignore-panel=PANEL            - Ignore parsing/displaying the given panel.\n"
   "  --ignore-referer=<needle>       - Ignore a referer from being counted.\n"
   "                                    Wild cards are allowed. i.e., *.bing.com\n"
   "  --real-os                       - Display real OS names. e.g, Windows XP,\n"


Added set_defaults function

Added set_defaults function

--- src/options.c
+++ src/options.c
@@ -16,16 +16,7 @@
 #define DEFAULT_FOREGROUND "#ffffff"
 #define DEFAULT_BACKGROUND "#000000"

-struct options options = {
-	.sizes[0] = DEFAULT_SIZES,
-	.sizes[1] = DEFAULT_SIZES,
-	.sizes[2] = DEFAULT_SIZES,
-	.bar_height = DEFAULT_HEIGHT,
-	.bar_on_bottom = DEFAULT_ON_BOTTOM,
-	.default_font = DEFAULT_FONT,
-	.default_foreground = DEFAULT_FOREGROUND,
-	.default_background = DEFAULT_BACKGROUND
-};
+struct options options;

 static struct option long_options[] = {
 	{ "help", no_argument, 0, 'h' },
@@ -39,8 +30,21 @@
 	{ "background", required_argument, 0, 'b' }
 };

+static void set_defaults()
+{
+	options.sizes[0] = DEFAULT_SIZES;
+	options.sizes[1] = DEFAULT_SIZES;
+	options.sizes[2] = DEFAULT_SIZES;
+	options.bar_height = DEFAULT_HEIGHT;
+	options.bar_on_bottom = DEFAULT_ON_BOTTOM;
+	options.default_font = strdup(DEFAULT_FONT);
+	options.default_foreground = strdup(DEFAULT_FOREGROUND);
+	options.default_background = strdup(DEFAULT_BACKGROUND);
+}
+
 void options_init(int argc, char **argv)
 {
+	set_defaults();
 	while (1) {
 		int arg = getopt_long(argc, argv, "hu:l:r:c:mg:t:f:b:",
 				long_options, NULL);


Move comment

Move comment

--- src/options.c
+++ src/options.c
@@ -729,11 +729,12 @@
     }

     if (accepts_query && argc > 0) {
-        // use the provided query
         if (!needs_query && strlen(argv[0]) == 0) {
-          opts.query = ag_strdup(".");
+            // use default query
+            opts.query = ag_strdup(".");
         } else {
-          opts.query = ag_strdup(argv[0]);
+            // use the provided query
+            opts.query = ag_strdup(argv[0]);
         }
         argc--;
         argv++;


Don't leak

Don't leak

--- src/options.c
+++ src/options.c
@@ -321,12 +321,15 @@
                     opts.workers = atoi(optarg);
                     break;
                 } else if (strcmp(longopts[opt_index].name, "color-line-number") == 0) {
+                    free(opts.color_line_number);
                     ag_asprintf(&opts.color_line_number, "\e%s", optarg);
                     break;
                 } else if (strcmp(longopts[opt_index].name, "color-match") == 0) {
+                    free(opts.color_match);
                     ag_asprintf(&opts.color_match, "\e%s", optarg);
                     break;
                 } else if (strcmp(longopts[opt_index].name, "color-path") == 0) {
+                    free(opts.color_path);
                     ag_asprintf(&opts.color_path, "\e%s", optarg);
                     break;
                 }


Don't allocate a new identity list in the new session's options.

The previous list is not freed. Since the new session just got
created, an identity list is already allocated and empty.

Signed-off-by: Sebastien Boving <62d754cc350e84d3b1c32ae79f976f5348e74a40@google.com>
Reviewed-by: Andreas Schneider <5be00ddc76278cf6077f5047ca3384a88460c671@cryptomilk.org>

--- src/options.c
+++ src/options.c
@@ -92,12 +92,6 @@

     if (src->opts.identity) {
         struct ssh_iterator *it;
-
-        new->opts.identity = ssh_list_new();
-        if (new->opts.identity == NULL) {
-            ssh_free(new);
-            return -1;
-        }

         it = ssh_list_get_iterator(src->opts.identity);
         while (it) {


both ogg libraries side-by-side

both ogg libraries side-by-side

--- src/opusenc.c
+++ src/opusenc.c
@@ -43,6 +43,7 @@
 #include "opus_header.h"
 #include "speex_resampler.h"
 #include "picture.h"
+#include "ogg_packer.h"

 #define MAX_CHANNELS 8

@@ -85,6 +86,7 @@

 struct OggOpusEnc {
   OpusMSEncoder *st;
+  oggpacker *oggp;
   int rate;
   int channels;
   float *buffer;
@@ -119,6 +121,16 @@
   if (err) return -1;
   length = page->header_len+page->body_len;
   if (enc->page_callback) enc->page_callback(user_data, length, 0);
+
+  {
+    unsigned char *page;
+    int len;
+    if (oggp_get_next_page(enc->oggp, &page, &len)) {
+      fwrite(page, 1, len, stdout);
+      fflush(stdout);
+    }
+  }
+
   return length;
 }

@@ -126,6 +138,9 @@
   ogg_page og;
   int ret;
   int written = 0;
+
+  oggp_flush_page(enc->oggp);
+
   while ( (ret = ogg_stream_flush(&enc->streams->os, &og)) ) {
     if (!ret) break;
     ret = oe_write_page(enc, &og, enc->streams->user_data);
@@ -295,6 +310,9 @@
     enc->streams->serialno = rand();
   }

+  enc->oggp = oggp_create(enc->streams->serialno);
+  /* FIXME: How the hell do we handle failure here? */
+
   if (ogg_stream_init(&enc->streams->os, enc->streams->serialno) == -1) {
     assert(0);
     /* FIXME: How the hell do we handle that? */
@@ -317,6 +335,12 @@
     op.granulepos=0;
     op.packetno=0;
     ogg_stream_packetin(&enc->streams->os, &op);
+
+    unsigned char *p;
+    p = oggp_get_packet_buffer(enc->oggp, 276);
+    memcpy(p, header_data, packet_size);
+    oggp_commit_packet(enc->oggp, packet_size, 0, 0);
+
     oe_flush_page(enc);

     op.packet = (unsigned char *)enc->streams->comment;
@@ -326,6 +350,11 @@
     op.granulepos = 0;
     op.packetno = 1;
     ogg_stream_packetin(&enc->streams->os, &op);
+
+    p = oggp_get_packet_buffer(enc->oggp, enc->streams->comment_length);
+    memcpy(p, enc->streams->comment, enc->streams->comment_length);
+    oggp_commit_packet(enc->oggp, enc->streams->comment_length, 0, 0);
+
     oe_flush_page(enc);
   }
   enc->streams->stream_is_init = 1;
@@ -373,10 +402,17 @@
       cont = 0;
       if (op.e_o_s) op.granulepos=end_granule48k-enc->streams->granule_offset;
       ogg_stream_packetin(&enc->streams->os, &op);
+      {
+        unsigned char *p;
+        p = oggp_get_packet_buffer(enc->oggp, MAX_PACKET_SIZE);
+        memcpy(p, packet, nbBytes);
+        oggp_commit_packet(enc->oggp, nbBytes, op.granulepos, op.e_o_s);
+      }
       if (enc->packet_callback) enc->packet_callback(enc->streams->user_data, op.packet, op.bytes, 0);
       /* FIXME: Also flush on too many segments. */
       flush_needed = op.e_o_s || enc->curr_granule - enc->last_page_granule > enc->max_ogg_delay;
       if (flush_needed) {
+        oggp_flush_page(enc->oggp);
         while (ogg_stream_flush_fill(&enc->streams->os, &og, 255*255)) {
           if (ogg_page_packets(&og) != 0) enc->last_page_granule = ogg_page_granulepos(&og) + enc->streams->granule_offset;
           int ret = oe_write_page(enc, &og, enc->streams->user_data);


pacconf: return non-zero on unknown directives

Signed-off-by: Andrew Gregory <13115e38efea9b5bf08524f6765f5bb44291d47f@gmail.com>

--- src/pacconf.c
+++ src/pacconf.c
@@ -260,8 +260,9 @@
 	}
 }

-void list_repo_directives(alpm_list_t *directives)
-{
+int list_repo_directives(alpm_list_t *directives)
+{
+	int ret = 0;
 	alpm_list_t *i;
 	pu_repo_t *repo = NULL;

@@ -274,12 +275,12 @@

 	if(!repo) {
 		fprintf(stderr, "error: repo '%s' not configured\n", repo_name);
-		return;
+		return 1;
 	}

 	if(!directives) {
 		dump_repo(repo);
-		return;
+		return 0;
 	}

 	for(i = directives; i; i = i->next) {
@@ -289,19 +290,26 @@
 			show_siglevel("SigLevel", repo->siglevel, 0);
 		} else if(strcasecmp(i->data, "Usage") == 0) {
 			show_usage("Usage", repo->usage);
+		} else if(strcasecmp(i->data, "Include") == 0) {
+			fputs("warning: 'Include' directives cannot be queried\n", stderr);
+			ret = 1;
 		} else {
 			fprintf(stderr, "warning: unknown directive '%s'\n", (char*) i->data);
-		}
-	}
-}
-
-void list_directives(alpm_list_t *directives)
-{
+			ret = 1;
+		}
+	}
+
+	return ret;
+}
+
+int list_directives(alpm_list_t *directives)
+{
+	int ret = 0;
 	alpm_list_t *i;

 	if(!directives) {
 		dump_config();
-		return;
+		return 0;
 	}

 	for(i = directives; i; i = i->next) {
@@ -359,11 +367,14 @@

 		} else if(strcasecmp(i->data, "Include") == 0) {
 			fputs("warning: 'Include' directives cannot be queried\n", stderr);
-
+			ret = 1;
 		} else {
 			fprintf(stderr, "warning: unknown directive '%s'\n", (char*) i->data);
-		}
-	}
+			ret = 1;
+		}
+	}
+
+	return ret;
 }

 int main(int argc, char **argv)
@@ -392,9 +403,9 @@
 		}
 		list_repos();
 	} else if(repo_name) {
-		list_repo_directives(directives);
+		ret = list_repo_directives(directives);
 	} else {
-		list_directives(directives);
+		ret = list_directives(directives);
 	}

 cleanup:


pacsift: use pu_print_version

pacsift: use pu_print_version

Signed-off-by: Andrew Gregory <13115e38efea9b5bf08524f6765f5bb44291d47f@gmail.com>

--- src/pacsift.c
+++ src/pacsift.c
@@ -4,6 +4,8 @@
 #include <regex.h>

 #include <pacutils.h>
+
+const char *myname = "pacsift", *myver = "0.1";

 pu_config_t *config = NULL;
 alpm_handle_t *handle = NULL;
@@ -205,12 +207,6 @@
 	cleanup(ret);
 }

-void version(void)
-{
-	printf("pacsift v0.1 - libalpm %s\n", alpm_version());
-	cleanup(0);
-}
-
 pu_config_t *parse_opts(int argc, char **argv)
 {
 	char *config_file = "/etc/pacman.conf";
@@ -276,7 +272,8 @@
 				usage(0);
 				break;
 			case FLAG_VERSION:
-				version();
+				pu_print_version(myname, myver);
+				cleanup(0);
 				break;

 			case FLAG_INVERT:


fix compiler warnings

fix compiler warnings

--- src/padding.c
+++ src/padding.c
@@ -60,7 +60,7 @@
     AES_ErrorDetails* err_details)
 {
     AES_UNUSED_PARAMETER(err_details);
-    memset(dest, padding_size, padding_size);
+    memset(dest, (int) padding_size, padding_size);
     return AES_SUCCESS;
 }


Remove animation when window shows

Remove animation when window shows

--- src/palermo.c
+++ src/palermo.c
@@ -173,7 +173,7 @@
     .unload = window_unload,
   });

-  const bool animated = true;
+  const bool animated = false;
   window_stack_push(window, animated);
 }


size of memset to 0 error

size of memset to 0 error

--- src/pattern.c
+++ src/pattern.c
@@ -820,7 +820,7 @@

 	struct context * ctx = (struct context *)_ctx;
 	bool * field = (bool *)malloc(pat->count * sizeof(bool));
-	memset(field, 0, sizeof(field));
+	memset(field, 0, pat->count * sizeof(bool));

 	int i;
 	int fc = 0;


Update RC

Update RC

--- src/penalty.h
+++ src/penalty.h
@@ -3,6 +3,7 @@
 #include "core.h"
 #include "group.h"
 #include "space.h"
+#include <Eigen/Dense>

 namespace Faunus {


Restore msg_store chunks.

Restore msg_store chunks.

--- src/persist.c
+++ src/persist.c
@@ -328,6 +328,106 @@
 }

+static int _db_msg_store_chunk_restore(mosquitto_db *db, int db_fd)
+{
+	uint64_t i64temp, store_id;
+	uint32_t i32temp, payloadlen;
+	uint16_t i16temp, slen, source_mid, mid;
+	uint8_t qos, retain, *payload = NULL;
+	char *source_id = NULL;
+	char *topic = NULL;
+	int rc = 0;
+	struct mosquitto_msg_store *stored = NULL;
+
+#define read_e(a, b, c) if(read(a, b, c) != c){ goto error; }
+	read_e(db_fd, &i64temp, sizeof(uint64_t));
+	store_id = be64toh(i64temp);
+
+	read_e(db_fd, &i16temp, sizeof(uint16_t));
+	slen = ntohs(i16temp);
+	if(slen){
+		source_id = _mosquitto_calloc(slen, sizeof(char));
+		if(!source_id){
+			close(db_fd);
+			mqtt3_log_printf(MOSQ_LOG_ERR, "Error: Out of memory.");
+			return 1;
+		}
+		if(read(db_fd, source_id, slen) != slen){
+			mqtt3_log_printf(MOSQ_LOG_ERR, "Error: %s.", strerror(errno));
+			close(db_fd);
+			_mosquitto_free(source_id);
+			return 1;
+		}
+	}
+	read_e(db_fd, &i16temp, sizeof(uint16_t));
+	source_mid = ntohs(i16temp);
+
+	read_e(db_fd, &i16temp, sizeof(uint16_t));
+	mid = ntohs(i16temp);
+
+	read_e(db_fd, &i16temp, sizeof(uint16_t));
+	slen = ntohs(i16temp);
+	if(slen){
+		topic = _mosquitto_calloc(slen+1, sizeof(char));
+		if(!topic){
+			close(db_fd);
+			_mosquitto_free(source_id);
+			mqtt3_log_printf(MOSQ_LOG_ERR, "Error: Out of memory.");
+			return 1;
+		}
+		if(read(db_fd, topic, slen) != slen){
+			mqtt3_log_printf(MOSQ_LOG_ERR, "Error: %s.", strerror(errno));
+			close(db_fd);
+			_mosquitto_free(source_id);
+			_mosquitto_free(topic);
+			return 1;
+		}
+	}else{
+		mqtt3_log_printf(MOSQ_LOG_ERR, "Error: Invalid msg_store chunk when restoring persistent database.");
+		close(db_fd);
+		_mosquitto_free(source_id);
+		return 1;
+	}
+	read_e(db_fd, &qos, sizeof(uint8_t));
+	read_e(db_fd, &retain, sizeof(uint8_t));
+
+	read_e(db_fd, &i32temp, sizeof(uint32_t));
+	payloadlen = ntohl(i32temp);
+
+	if(payloadlen){
+		payload = _mosquitto_malloc(payloadlen);
+		if(!payload){
+			close(db_fd);
+			_mosquitto_free(source_id);
+			_mosquitto_free(topic);
+			mqtt3_log_printf(MOSQ_LOG_ERR, "Error: Out of memory.");
+			return 1;
+		}
+		if(read(db_fd, &payload, payloadlen) != payloadlen){
+			mqtt3_log_printf(MOSQ_LOG_ERR, "Error: %s.", strerror(errno));
+			close(db_fd);
+			_mosquitto_free(source_id);
+			_mosquitto_free(topic);
+			_mosquitto_free(payload);
+			return 1;
+		}
+	}
+
+#undef read_e
+	rc = mqtt3_db_message_store(db, source_id, source_mid, topic, qos, payloadlen, payload, retain, &stored, store_id);
+	_mosquitto_free(source_id);
+	_mosquitto_free(topic);
+	_mosquitto_free(payload);
+
+	return rc;
+error:
+	mqtt3_log_printf(MOSQ_LOG_ERR, "Error: %s.", strerror(errno));
+	if(db_fd >= 0) close(db_fd);
+	if(source_id) _mosquitto_free(source_id);
+	if(topic) _mosquitto_free(topic);
+	return 1;
+}
+
 static int _db_retain_chunk_restore(mosquitto_db *db, int db_fd)
 {
 	uint64_t i64temp, store_id;
@@ -440,6 +540,7 @@
 					break;

 				case DB_CHUNK_MSG_STORE:
+					if(_db_msg_store_chunk_restore(db, fd)) return 1;
 					break;

 				case DB_CHUNK_CLIENT_MSG:


Comment typo

Comment typo

--- src/pl-comp.c
+++ src/pl-comp.c
@@ -5295,7 +5295,7 @@

 /** clause(H, B).
     clause(H, B, Ref).
-    clause(H, B, Ref, Bindings).
+    '$clause'(H, B, Ref, Bindings).
 */


* Ongoing patch to tell/1 and see/1

* Ongoing patch to tell/1 and see/1

--- src/pl-file.c
+++ src/pl-file.c
@@ -111,10 +111,14 @@
 } alias;

+#define IO_TELL	0x001			/* opened by tell/1 */
+#define IO_SEE  0x002			/* opened by see/1 */
+
 typedef struct
 { alias *alias_head;
   alias *alias_tail;
   atom_t filename;			/* associated filename */
+  unsigned flags;
 } stream_context;

@@ -127,6 +131,7 @@

     ctx->alias_head = ctx->alias_tail = NULL;
     ctx->filename = NULL_ATOM;
+    ctx->flags = 0;
     addHTable(streamContext, s, ctx);

     return ctx;
@@ -1669,6 +1674,28 @@
 		 *	  EDINBURGH I/O		*
 		 *******************************/

+static IOSTREAM *
+findStreamFromFile(atom_t name, unsigned int flags)
+{ TableEnum e;
+  Symbol symb;
+  IOSTREAM *s = NULL;
+
+  e = newTableEnum(streamContext);
+  while( (symb=advanceTableEnum(e)) )
+  { stream_context *ctx = symb->value;
+
+    if ( ctx->filename == name &&
+	 true(ctx, flags) )
+    { s = symb->name;
+      break;
+    }
+  }
+  freeTableEnum(e);
+
+  return s;
+}
+
+
 word
 pl_see(term_t f)
 { IOSTREAM *s;
@@ -1678,13 +1705,16 @@
   LOCK();
   if ( get_stream_handle(f, &s, SH_ALIAS|SH_UNLOCKED) )
   { Scurin = s;
-    UNLOCK();
-    succeed;
-  }
-  UNLOCK();
+    goto ok;
+  }
+
   if ( PL_get_atom(f, &a) && a == ATOM_user )
   { Scurin = Suser_input;
-    succeed;
+    goto ok;
+  }
+  if ( (s = findStreamFromFile(a, IO_SEE)) )
+  { Scurin = s;
+    goto ok;
   }

   mode = PL_new_term_ref();
@@ -1692,8 +1722,12 @@
   if ( !(s = openStream(f, mode, 0)) )
     fail;

+  set(getStreamContext(s), IO_SEE);
   pl_push_input_context();
   Scurin = s;
+
+ok:
+  UNLOCK();

   succeed;
 }
@@ -1722,12 +1756,18 @@
   term_t mode;

   LOCK();
-  if ( get_stream_handle(f, &s, SH_ALIAS|SH_UNLOCKED) )
+  if ( get_stream_handle(f, &s, SH_UNLOCKED) )
   { Scurout = s;
     goto ok;
   }
+
   if ( PL_get_atom(f, &a) && a == ATOM_user )
   { Scurout = Suser_output;
+    goto ok;
+  }
+
+  if ( (s = findStreamFromFile(a, IO_TELL)) )
+  { Scurout = s;
     goto ok;
   }

@@ -1738,6 +1778,7 @@
     fail;
   }

+  set(getStreamContext(s), IO_TELL);
   pushOutputContext();
   Scurout = s;


Update supervisor when adding clauses to a static predicate.  This fixes issues with -notably- term_expansion/2 and goal_expansion/2 predicates that are local to a module.

--- src/pl-proc.c
+++ src/pl-proc.c
@@ -776,10 +776,16 @@
 }

-/*  Assert a clause to a procedure. Where askes to assert either at the
-    head or at the tail of the clause list.
-
- ** Fri Apr 29 12:44:08 1988  jan@swivax.UUCP (Jan Wielemaker)  */
+/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+Assert a clause to a procedure. Where askes to assert either at the head
+or at the tail of the clause list.
+
+(*) This function updates the indexing information.  If we have a static
+procedure, it deletes the supervisor. This is  probably a bit rough, but
+deals with -for example- clauses for   term_expansion/2. After the first
+definition this will be  called  and   an  S_TRUSTME  supervisor will be
+installed, causing further clauses to have no effect.
+- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

 ClauseRef
 assertProcedure(Procedure proc, Clause clause, int where ARG_LD)
@@ -810,6 +816,9 @@
   clause->generation.created = ++GD->generation;
   clause->generation.erased  = ~0L;	/* infinite */
 #endif
+
+  if ( false(def, DYNAMIC) )		/* see (*) above */
+    freeCodesDefinition(def);

   if ( def->hash_info )
   { assert(!(def->indexPattern & NEED_REINDEX));


pack-objects: remove redundant and wrong call to deflateEnd()

We somehow called deflateEnd() on a stream that we have called
deflateEnd() on already.

In fact, the second deflateEnd() has always been returning
Z_STREAM_ERROR.  We just never checked the error return from
that particular deflateEnd().

The first one returns 0 for success.  We might want to tighten
the check even more to check that.

Noticed by Marco.

Signed-off-by: Junio C Hamano <a6723cc3f76163bf7adb636a73ac3b0ceb3e6b9b@pobox.com>

--- builtin-pack-objects.c
+++ builtin-pack-objects.c
@@ -445,7 +445,7 @@
 			/* nothing */;
 		deflateEnd(&stream);
 		datalen = stream.total_out;
-		deflateEnd(&stream);
+
 		/*
 		 * The object header is a byte of 'type' followed by zero or
 		 * more bytes of length.


gnrc_ipv6_nib: use rmutex instead of mutex for locking

--- sys/net/gnrc/network_layer/ipv6/nib/_nib-internal.c
+++ sys/net/gnrc/network_layer/ipv6/nib/_nib-internal.c
@@ -42,7 +42,7 @@
 #if GNRC_IPV6_NIB_CONF_MULTIHOP_P6C
 static _nib_abr_entry_t _abrs[GNRC_IPV6_NIB_ABR_NUMOF];
 #endif  /* GNRC_IPV6_NIB_CONF_MULTIHOP_P6C */
-static mutex_t _nib_mutex = MUTEX_INIT;
+static rmutex_t _nib_mutex = RMUTEX_INIT;

 static char addr_str[IPV6_ADDR_MAX_STR_LEN];

@@ -70,12 +70,12 @@

 void _nib_acquire(void)
 {
-    mutex_lock(&_nib_mutex);
+    rmutex_lock(&_nib_mutex);
 }

 void _nib_release(void)
 {
-    mutex_unlock(&_nib_mutex);
+    rmutex_unlock(&_nib_mutex);
 }

 static inline bool _addr_equals(const ipv6_addr_t *addr,


Bug 700925: Fall back to "hail mary" font upon missing font dict in ExtGState.

When font dictionary was missing this used to cause an assertion.
Commit 58517162baebb8465796a9de6125307ee7fe7a28 fixed this issue
by loading a "hail mary" font, but only in one of two locations
where pdf_load_font() was called. This commit addresses the
second occurrence by also loading a "hail mary" font.

--- source/pdf/pdf-interpret.c
+++ source/pdf/pdf-interpret.c
@@ -175,7 +175,11 @@
 	{
 		pdf_obj *font_ref = pdf_array_get(ctx, obj, 0);
 		pdf_obj *font_size = pdf_array_get(ctx, obj, 1);
-		pdf_font_desc *font = pdf_load_font(ctx, csi->doc, csi->rdb, font_ref);
+		pdf_font_desc *font;
+		if (pdf_is_dict(ctx, font_ref))
+			font = pdf_load_font(ctx, csi->doc, csi->rdb, font_ref);
+		else
+			font = pdf_load_hail_mary_font(ctx, csi->doc);
 		fz_try(ctx)
 			proc->op_Tf(ctx, proc, "ExtGState", font, pdf_to_real(ctx, font_size));
 		fz_always(ctx)


Add basefreq to Wavetable struct

Add basefreq to Wavetable struct

--- dds_playground/src/wavetables.h
+++ dds_playground/src/wavetables.h
@@ -16,14 +16,16 @@
     u32 increment;

     u8 currentnote;
+    u16 basefreq;
 } Wavetable;

 #define WT_SINE_LENGTH 256
 #define WT_SINE_AMPLITUDE 127
+#define WT_SINE_BASEFREQ 31.25

 int wt_sine_data[WT_SINE_LENGTH];

-inline void wt_init(Wavetable *table, int *data, u16 len) {
+inline void wt_init(Wavetable *table, int *data, u16 len, u16 basefreq) {
     table->len = len;
     table->wave = data;

@@ -32,6 +34,7 @@
     table->increment = 0;

     table->currentnote = NONOTE;
+    table->basefreq = basefreq;
 }

 inline void initialize_datatables() {


straighten the list of objects to deltify

Not all objects are subject to deltification, so avoid carrying those
along, and provide the real count to progress display.

Signed-off-by: Nicolas Pitre <d659c10e27d52b00987b65e85d99bce5480adcae@cam.org>
Signed-off-by: Junio C Hamano <a6723cc3f76163bf7adb636a73ac3b0ceb3e6b9b@pobox.com>

--- builtin-pack-objects.c
+++ builtin-pack-objects.c
@@ -1313,12 +1313,6 @@
 	if (trg_entry->type != src_entry->type)
 		return -1;

-	/* We do not compute delta to *create* objects we are not
-	 * going to pack.
-	 */
-	if (trg_entry->preferred_base)
-		return -1;
-
 	/*
 	 * We do not bother to try a delta that we discarded
 	 * on an earlier try, but only when reusing delta data.
@@ -1443,42 +1437,23 @@
 	n->depth = 0;
 }

-static void find_deltas(struct object_entry **list, int window, int depth)
-{
-	uint32_t i = nr_objects, idx = 0, count = 0, processed = 0;
+static void find_deltas(struct object_entry **list, unsigned list_size,
+			unsigned nr_deltas, int window, int depth)
+{
+	uint32_t i = list_size, idx = 0, count = 0, processed = 0;
 	unsigned int array_size = window * sizeof(struct unpacked);
 	struct unpacked *array;
 	int max_depth;

-	if (!nr_objects)
-		return;
 	array = xmalloc(array_size);
 	memset(array, 0, array_size);
 	if (progress)
-		start_progress(&progress_state, "Deltifying %u objects...", "", nr_result);
+		start_progress(&progress_state, "Deltifying %u objects...", "", nr_deltas);

 	do {
 		struct object_entry *entry = list[--i];
 		struct unpacked *n = array + idx;
 		int j, best_base = -1;
-
-		if (!entry->preferred_base)
-			processed++;
-
-		if (progress)
-			display_progress(&progress_state, processed);
-
-		if (entry->delta)
-			/* This happens if we decided to reuse existing
-			 * delta from a pack.  "!no_reuse_delta &&" is implied.
-			 */
-			continue;
-
-		if (entry->size < 50)
-			continue;
-
-		if (entry->no_try_delta)
-			continue;

 		free_unpacked(n);
 		n->entry = entry;
@@ -1490,6 +1465,15 @@
 			free_unpacked(array + tail);
 			count--;
 		}
+
+		/* We do not compute delta to *create* objects we are not
+		 * going to pack.
+		 */
+		if (entry->preferred_base)
+			goto next;
+
+		if (progress)
+			display_progress(&progress_state, ++processed);

 		/*
 		 * If the current object is at pack edge, take the depth the
@@ -1565,18 +1549,41 @@
 static void prepare_pack(int window, int depth)
 {
 	struct object_entry **delta_list;
-	uint32_t i;
+	uint32_t i, n, nr_deltas;

 	get_object_details();

-	if (!window || !depth)
+	if (!nr_objects || !window || !depth)
 		return;

 	delta_list = xmalloc(nr_objects * sizeof(*delta_list));
-	for (i = 0; i < nr_objects; i++)
-		delta_list[i] = objects + i;
-	qsort(delta_list, nr_objects, sizeof(*delta_list), type_size_sort);
-	find_deltas(delta_list, window+1, depth);
+	nr_deltas = n = 0;
+
+	for (i = 0; i < nr_objects; i++) {
+		struct object_entry *entry = objects + i;
+
+		if (entry->delta)
+			/* This happens if we decided to reuse existing
+			 * delta from a pack.  "!no_reuse_delta &&" is implied.
+			 */
+			continue;
+
+		if (entry->size < 50)
+			continue;
+
+		if (entry->no_try_delta)
+			continue;
+
+		if (!entry->preferred_base)
+			nr_deltas++;
+
+		delta_list[n++] = entry;
+	}
+
+	if (nr_deltas) {
+		qsort(delta_list, n, sizeof(*delta_list), type_size_sort);
+		find_deltas(delta_list, n, nr_deltas, window+1, depth);
+	}
 	free(delta_list);
 }


added recheck document dimensions on preview update

--- src/preview.c
+++ src/preview.c
@@ -105,7 +105,10 @@
     if (pc->doc) g_object_unref(pc->doc);

     pc->doc = poppler_document_new_from_file(pc->uri, NULL, &err);
-    pc->page = poppler_document_get_page(pc->doc, pc->page_current);
+    pc->page = poppler_document_get_page(pc->doc, pc->page_current);
+
+    // recheck document dimensions on refresh for orientation changes:
+    poppler_page_get_size(pc->page, &pc->page_width, &pc->page_height);

     pc->page_total = poppler_document_get_n_pages(pc->doc);
     preview_set_pagedata(pc);


Rename WET_CLICK to LCUI_WEVENT_CLICK

Rename WET_CLICK to LCUI_WEVENT_CLICK

--- demo/src/ui/helpers/ui_helper.c
+++ demo/src/ui/helpers/ui_helper.c
@@ -15,7 +15,7 @@
 	if( !link ) {
 		return;
 	}
-	ev.type = WET_CLICK;
+	ev.type = LCUI_WEVENT_CLICK;
 	ev.button.button = 1;
 	Widget_TriggerEvent( link, &ev, NULL );
 }


core: Remove dead code

core: Remove dead code

rfcomm can only be NULL in this path

--- src/profile.c
+++ src/profile.c
@@ -1294,10 +1294,6 @@
 	if (l2cap) {
 		ext->servers = g_slist_remove(ext->servers, l2cap);
 		ext_io_destroy(l2cap);
-	}
-	if (rfcomm) {
-		ext->servers = g_slist_remove(ext->servers, rfcomm);
-		ext_io_destroy(rfcomm);
 	}

 	return 0;


added canon ixus 110 is

added canon ixus 110 is

git-svn-id: 40dd595c6684d839db675001a64203a1457e7319@12284 67ed7778-7388-44ab-90cf-0a291f65f57c

--- camlibs/ptp2/library.c
+++ camlibs/ptp2/library.c
@@ -925,6 +925,9 @@
 	/* mitch <debianuser@mll.dissimulo.com> */
 	{"Canon:EOS 50D",			0x04a9, 0x319b, PTP_CAP|PTP_CAP_PREVIEW|PTPBUG_DELETE_SENDS_EVENT},

+	/* Carsten Grohmann <carstengrohmann@gmx.de> */
+	{"Canon:Digital IXUS 110 IS",		0x04a9, 0x31bd, PTPBUG_DELETE_SENDS_EVENT},
+
 	{"Canon:PowerShot A480",		0x04a9, 0x31bf, PTPBUG_DELETE_SENDS_EVENT},

 	/* IRC Reporter */


Agg distinct (WIP)

Agg distinct (WIP)

--- src/provsql.c
+++ src/provsql.c
@@ -768,11 +768,15 @@
     {
       Aggref *ar_v = (Aggref *)te_v->expr;
       if (list_length(ar_v->aggdistinct)>0) {
+        TargetEntry *te_new = NULL;
         found = 1;
         //the agg distinct clause is added to the GROUP BY clause
         new_q->groupClause = lappend(new_q->groupClause, ar_v->aggdistinct);
         //remove aggref and replace by its arguments
-        lst_v = lappend(lst_v, ar_v->args);
+        te_new = (TargetEntry *)ar_v->args;
+        te_new->resno = te_v->resno;
+        te_new->resname = te_v->resname;
+        lst_v = lappend(lst_v, te_new);
       }
       else
       {
@@ -1400,7 +1404,7 @@
       Query *subq = check_for_agg_distinct(q);
       if(subq) // agg distinct detected, create a subquery
       {
-        elog_node_display(NOTICE, "Rewritted sub-query", subq, true);
+        elog_node_display(NOTICE, "Rewritten sub-query", subq, true);
       }
       replace_aggregations_in_select(q, prov_atts,
                                      has_union ? SR_PLUS : (has_difference ? SR_MONUS : SR_TIMES), constants);


added powershot sd970 alias for ixus 990is

git-svn-id: 40dd595c6684d839db675001a64203a1457e7319@12653 67ed7778-7388-44ab-90cf-0a291f65f57c

--- camlibs/ptp2/library.c
+++ camlibs/ptp2/library.c
@@ -983,6 +983,8 @@
 	{"Canon:PowerShot SX200 IS",		0x04a9, 0x31c0, 0},
 	/* https://sourceforge.net/tracker/index.php?func=detail&aid=2789326&group_id=8874&atid=358874 */
 	{"Canon:Digital IXUS 990 IS",		0x04a9, 0x31c1, PTPBUG_DELETE_SENDS_EVENT},
+	/* Michael Ole Olsen <gnu@gmx.net> */
+	{"Canon:PowerShot SD970 IS",		0x04a9, 0x31c1, PTPBUG_DELETE_SENDS_EVENT},
 	/* https://sourceforge.net/tracker/?func=detail&aid=2769511&group_id=8874&atid=208874 */
 	/* Do not confuse with PowerShot SX100IS */
 	{"Canon:Digital IXUS 100 IS",           0x04a9, 0x31c2, PTPBUG_DELETE_SENDS_EVENT},


Refine the delta map slightly.

Refine the delta map slightly.


added powershot 3100IS id

added powershot 3100IS id

git-svn-id: 40dd595c6684d839db675001a64203a1457e7319@13693 67ed7778-7388-44ab-90cf-0a291f65f57c

--- camlibs/ptp2/library.c
+++ camlibs/ptp2/library.c
@@ -1138,6 +1138,9 @@
 	/* IRC reporter */
 	{"Canon:EOS 550D",			0x04a9, 0x31ea, PTP_CAP|PTP_CAP_PREVIEW},

+	/* ErVito on IRC */
+	{"Canon:PowerShot A3100 IS",		0x04a9, 0x31f1, PTPBUG_DELETE_SENDS_EVENT},
+
 	{"Canon:Digital IXUS 130",		0x04a9, 0x31f3, PTPBUG_DELETE_SENDS_EVENT},
 	/* Mark Voorhies <mvoorhie@yahoo.com> */
 	{"Canon:PowerShot SD1300 IS",		0x04a9, 0x31f4, PTPBUG_DELETE_SENDS_EVENT},


cal n ranks on a node and my node rank.

cal n ranks on a node and my node rank.

--- src/quo-mpi.c
+++ src/quo-mpi.c
@@ -146,6 +146,14 @@
                                             &(mpi->smpcomm)))) {
         goto out;
     }
+    if (MPI_SUCCESS != MPI_Comm_size(mpi->smpcomm, &(mpi->nsmpranks))) {
+        rc = QUO_ERR_MPI;
+        goto out;
+    }
+    if (MPI_SUCCESS != MPI_Comm_rank(mpi->smpcomm, &(mpi->smprank))) {
+        rc = QUO_ERR_MPI;
+        goto out;
+    }
 out:
     if (netnums) free(netnums);
     return rc;
@@ -173,11 +181,11 @@

     if (QUO_SUCCESS != (rc = commchan_setup(mpi))) goto out;
     /* gather some basic info that we need */
-    if (MPI_SUCCESS != MPI_Comm_size(MPI_COMM_WORLD, &(mpi->nranks))) {
-        rc = QUO_ERR_MPI;
-        goto out;
-    }
-    if (MPI_SUCCESS != MPI_Comm_rank(MPI_COMM_WORLD, &(mpi->rank))) {
+    if (MPI_SUCCESS != MPI_Comm_size(mpi->commchan, &(mpi->nranks))) {
+        rc = QUO_ERR_MPI;
+        goto out;
+    }
+    if (MPI_SUCCESS != MPI_Comm_rank(mpi->commchan, &(mpi->rank))) {
         rc = QUO_ERR_MPI;
         goto out;
     }


added j3

added j3

git-svn-id: 40dd595c6684d839db675001a64203a1457e7319@14426 67ed7778-7388-44ab-90cf-0a291f65f57c

--- camlibs/ptp2/library.c
+++ camlibs/ptp2/library.c
@@ -967,6 +967,8 @@
 	{"Nikon:J1",    		  0x04b0, 0x0602, PTP_CAP},
 	/* https://bugzilla.novell.com/show_bug.cgi?id=814622 Martin Caj at SUSE */
 	{"Nikon:J2",    		  0x04b0, 0x0603, PTP_CAP},
+	/* Ralph Schindler <ralph@ralphschindler.com> */
+	{"Nikon:J3",    		  0x04b0, 0x0605, PTP_CAP},

 #if 0


remove debug message

remove debug message

--- src/rcsocks.c
+++ src/rcsocks.c
@@ -431,7 +431,6 @@

 int main (int argc, char *argv[]) {
     parse_arg(argc, argv);
-    printf("%d\n", sizeof(s_client));
     server_relay(globalArgs.port, globalArgs.listen,
 #ifdef HAVE_LIBSSL
                  globalArgs.ssl


test-client-view-operations.c: For now disable the regular access test

This test was written to protect against deadlocks in EBookBackendSqliteDB
with concurrent read access. Currently two in a row fails when fetching
the newly added contacts in the test book, still dont know why but it's
orthogonal to the reason for this test.

--- tests/libebook/client/test-client-view-operations.c
+++ tests/libebook/client/test-client-view-operations.c
@@ -8,7 +8,7 @@
 #include "client-test-utils.h"
 #include "e-test-server-utils.h"

-static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
+/* static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 }; */
 static ETestServerClosure direct_book_closure = { E_TEST_SERVER_DIRECT_ADDRESS_BOOK, NULL, 0 };

 #define N_THREADS  5
@@ -256,10 +256,14 @@
 	g_test_init (&argc, &argv, NULL);
 	setlocale (LC_ALL, "en_US.UTF-8");

-	g_test_add ("/EBookClient/ConcurrentViews", ETestServerFixture, &book_closure,
-		    e_test_server_utils_setup, test_concurrent_views, e_test_server_utils_teardown);
 	g_test_add ("/EBookClient/DirectAccess/ConcurrentViews", ETestServerFixture, &direct_book_closure,
 		    e_test_server_utils_setup, test_concurrent_views, e_test_server_utils_teardown);

+	/* Run Direct Access only to protect against lockups, this second iteration fails
+	 * while adding the initial contact, don't know why yet.
+	 */
+	/* g_test_add ("/EBookClient/ConcurrentViews", ETestServerFixture, &book_closure, */
+	/* 	    e_test_server_utils_setup, test_concurrent_views, e_test_server_utils_teardown); */
+
 	return e_test_server_utils_run ();
 }


stdutils::custom_error

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

--- deps/stdutils/src/customerror.h
+++ deps/stdutils/src/customerror.h
@@ -0,0 +1,34 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+// customerror.h
+//
+// Copyright (c) 2014 Eric Lombrozo
+//
+// All Rights Reserved.
+//
+
+#pragma once
+
+#include <stdexcept>
+
+namespace stdutils
+{
+
+class custom_error : public std::runtime_error
+{
+public:
+    explicit custom_error(const std::string& what, int code = 0)
+        : std::runtime_error(what), code_(code) { }
+
+    explicit custom_error(const char* what, int code = 0)
+        : std::runtime_error(what), code_(code) { }
+
+    virtual ~custom_error() throw() { }
+
+    int code() const { return code_; }
+
+private:
+    int code_;
+};
+
+}


mark loop variables unsigned

mark loop variables unsigned

git-svn-id: 40dd595c6684d839db675001a64203a1457e7319@14518 67ed7778-7388-44ab-90cf-0a291f65f57c

--- camlibs/ptp2/library.c
+++ camlibs/ptp2/library.c
@@ -139,7 +139,7 @@
 	putfunc_t	putfunc;
 };

-static int nrofspecial_files = 0;
+static unsigned int nrofspecial_files = 0;
 static struct special_file *special_files = NULL;

 static int
@@ -309,7 +309,7 @@
 	) {
 		PTPDeviceInfo	ndi, newdi, *outerdi;
 		uint16_t	ret;
-		int		i;
+		unsigned int	i;

 		ret = ptp_getdeviceinfo (params, &params->outer_deviceinfo);
 		if (ret != PTP_RC_OK)
@@ -398,7 +398,7 @@
 	}

 	if (di->VendorExtensionID == PTP_VENDOR_NIKON) {
-		int i;
+		unsigned int i;

 		if (ptp_operation_issupported(&camera->pl->params, PTP_OC_NIKON_GetVendorPropCodes)) {
 			uint16_t  	*xprops;
@@ -1748,7 +1748,7 @@
 int
 camera_abilities (CameraAbilitiesList *list)
 {
-	int i;
+	unsigned int i;
 	CameraAbilities a;

 	for (i = 0; i < sizeof(models)/sizeof(models[0]); i++) {
@@ -2774,7 +2774,7 @@

 			ret = ptp_getstorageids(params, &storageids);
 			if (ret == PTP_RC_OK) {
-				int k, stgcnt = 0;
+				unsigned int k, stgcnt = 0;
 				for (k=0;k<storageids.n;k++) {
 					if (!(storageids.Storage[k] & 0xffff)) continue;
 					if (storageids.Storage[k] == 0x80000001) continue;
@@ -3044,7 +3044,7 @@

             	GP_DEBUG("PTPBUG_NIKON_BROKEN_CAPTURE bug workaround");
 		while (tries--) {
-			int i;
+			unsigned int i;
 			uint16_t ret = ptp_getobjecthandles (params, PTP_HANDLER_SPECIAL, 0x000000, 0x000000, &handles);
 			if (ret != PTP_RC_OK)
 				break;
@@ -3286,7 +3286,8 @@

 				ret = ptp_getstorageids(params, &storageids);
 				if (ret == PTP_RC_OK) {
-					int k, stgcnt = 0;
+					unsigned int k, stgcnt = 0;
+
 					for (k=0;k<storageids.n;k++) {
 						if (!(storageids.Storage[k] & 0xffff)) continue;
 						if (storageids.Storage[k] == 0x80000001) continue;
@@ -3862,7 +3863,7 @@
 	if (dt == PTP_DTC_STR)
 		return snprintf (txt, spaceleft, "'%s'", data->str);
 	if (dt & PTP_DTC_ARRAY_MASK) {
-		int i;
+		unsigned int i;

 		n = snprintf (txt, spaceleft, "a[%d] ", data->a.count);
 		if (n >= spaceleft) return 0; spaceleft -= n; txt += n;
@@ -4031,7 +4032,8 @@
 static int
 camera_summary (Camera* camera, CameraText* summary, GPContext *context)
 {
-	int n, i, j;
+	unsigned int i, j;
+	int n;
 	uint16_t ret;
 	int spaceleft;
 	char *txt;
@@ -4441,7 +4443,7 @@
 static uint32_t
 find_child (PTPParams *params,const char *file,uint32_t storage,uint32_t handle,PTPObject **retob)
 {
-	int 		i;
+	unsigned int	i;
 	uint16_t	ret;

 	ret = ptp_list_folder (params, storage, handle);
@@ -4504,7 +4506,7 @@
     Camera *camera = (Camera *)data;
     PTPParams *params = &camera->pl->params;
     uint32_t parent, storage=0x0000000;
-    int i,hasgetstorageids;
+    unsigned int i, hasgetstorageids;
     SET_CONTEXT_P(params, context);

     gp_log (GP_LOG_DEBUG, "ptp2", "file_list_func(%s)", folder);
@@ -4574,7 +4576,7 @@
 		void *data, GPContext *context)
 {
 	PTPParams *params = &((Camera *)data)->pl->params;
-	int i, hasgetstorageids;
+	unsigned int i, hasgetstorageids;
 	uint32_t handler,storage;

 	SET_CONTEXT_P(params, context);
@@ -4682,7 +4684,7 @@
 ) {
 	uint16_t ret, *props = NULL;
 	uint32_t propcnt = 0;
-	int j;
+	unsigned int j;
 	MTPProperties	*mprops;
 	PTPObject	*ob;

@@ -4696,17 +4698,18 @@

 	mprops = ob->mtpprops;
 	if (mprops) { /* use the fast method, without device access since cached.*/
-		char			propname[256];
-		char			text[256];
-		int 			i, n;
+		char		propname[256];
+		char		text[256];
+		unsigned int	i, n;

 		for (j=0;j<ob->nrofmtpprops;j++) {
 			MTPProperties		*xpl = &mprops[j];

-			for (i=sizeof(uninteresting_props)/sizeof(uninteresting_props[0]);i--;)
+			for (i=0;i<sizeof(uninteresting_props)/sizeof(uninteresting_props[0]);i++)
 				if (uninteresting_props[i] == xpl->property)
 					break;
-			if (i != -1) /* Is uninteresting. */
+			/* Is uninteresting. */
+			if (i == sizeof(uninteresting_props)/sizeof(uninteresting_props[0]))
 				continue;
 			for(i=0;i<propcnt;i++) {
 				/* Mark handled property as 0 */
@@ -4848,7 +4851,7 @@
 	uint32_t propcnt = 0;
 	char	*filedata = NULL;
 	unsigned long	filesize = 0;
-	int j;
+	unsigned int j;

 	if (gp_file_get_data_and_size (file, (const char**)&filedata, &filesize) < GP_OK)
 		return (GP_ERROR);
@@ -4934,7 +4937,7 @@
 	PTPParams *params = &camera->pl->params;
 	uint32_t	numobjects = 0, *objects = NULL;
 	uint16_t	ret;
-	int		i, contentlen = 0;
+	unsigned int	i, contentlen = 0;
 	char		*content = NULL;

 	ret = ptp_mtp_getobjectreferences (params, object_id, &objects, &numobjects);
@@ -5260,7 +5263,7 @@
 #endif

 	if (!strcmp (folder, "/special")) {
-		int i;
+		unsigned int i;

 		for (i=0;i<nrofspecial_files;i++)
 			if (!strcmp (special_files[i].name, filename))
@@ -5421,7 +5424,7 @@
 	gp_log ( GP_LOG_DEBUG, "ptp2/put_file_func", "folder=%s, filename=%s", folder, filename);

 	if (!strcmp (folder, "/special")) {
-		int i;
+		unsigned int i;

 		for (i=0;i<nrofspecial_files;i++)
 			if (!strcmp (special_files[i].name, filename))
@@ -5810,7 +5813,7 @@
 	PTPParams *params 	= &camera->pl->params;
 	PTPStorageInfo		si;
 	PTPStorageIDs		sids;
-	int			i,n;
+	unsigned int		i,n;
 	uint16_t		ret;
 	CameraStorageInformation*sif;

@@ -6340,7 +6343,7 @@

 uint16_t
 ptp_list_folder (PTPParams *params, uint32_t storage, uint32_t handle) {
-	int			i, changed, last;
+	unsigned int		i, changed, last;
 	uint16_t		ret;
 	uint32_t		xhandle = handle;
 	PTPObject		*newobs;
@@ -6392,7 +6395,8 @@
 	last = changed = 0;
 	for (i=0;i<handles.n;i++) {
 		PTPObject	*ob;
-		int j;
+		unsigned int	j;
+
 		ob = NULL;
 		for (j=0;j<params->nrofobjects;j++) {
 			if (params->objects[(last+j)%params->nrofobjects].oid == handles.Handler[i])  {
@@ -6463,7 +6467,8 @@
 camera_init (Camera *camera, GPContext *context)
 {
     	CameraAbilities a;
-	int ret, i, retried = 0;
+	unsigned int i;
+	int ret, retried = 0;
 	PTPParams *params;
 	char *curloc, *camloc;
 	GPPortSettings	settings;


refactoring

refactoring

--- spapp/spgeomex/sptrackrf.h
+++ spapp/spgeomex/sptrackrf.h
@@ -133,7 +133,7 @@
                     Mat val = zeroMat(6, 1);
                     Mat dev = zeroMat(6, 1);

-                    Mem1<const RandomForestReg::Node*> &rfnode = node.rf.execute2(data);
+                    const Mem1<const RandomForestReg::Node*> &rfnode = node.rf.execute2(data);
                     for (int s = 0; s < 6; s++) {
                         val[s] = rfnode[s]->val;
                         dev[s] = rfnode[s]->dev;


Cruft.

Cruft.

--- src/re/main.c
+++ src/re/main.c
@@ -385,7 +385,6 @@

 	if (group) {
 		struct re_err err;
-		int r;

 		if (argc != 1) {
 			fprintf(stderr, "expected one group input\n");


* tools/server-side/svn-populate-node-origins-index.c:
  Revert changes accidentally added in r1073854.

git-svn-id: f8a4e5e023278da1e04e203c7fe051e3c4285d88@1073855 13f79535-47bb-0310-9956-ffa450edef68

--- tools/server-side/svn-populate-node-origins-index.c
+++ tools/server-side/svn-populate-node-origins-index.c
@@ -96,7 +96,8 @@
       if ((change->change_kind == svn_fs_path_change_add)
           || (change->change_kind == svn_fs_path_change_replace))
         {
-          if (!change->copyfrom_known)
+          if (! (change->copyfrom_path
+                            && SVN_IS_VALID_REVNUM(change->copyfrom_rev)))
             {
               svn_revnum_t origin;
               SVN_ERR(svn_fs_node_origin_rev(&origin, root, path, subpool));


S110 in PTP mode

S110 in PTP mode

--- camlibs/ptp2/library.c
+++ camlibs/ptp2/library.c
@@ -1421,7 +1421,7 @@
 	{"Canon:EOS 6D",			0x04a9, 0x3250, PTP_CAP|PTP_CAP_PREVIEW},

 	/* "T. Ludewig" <t.ludewig@gmail.com> */
-	{"Canon:PowerShot S110",		0x04a9, 0x325b, PTPBUG_DELETE_SENDS_EVENT},
+	{"Canon:PowerShot S110 (PTP Mode)",	0x04a9, 0x325b, PTPBUG_DELETE_SENDS_EVENT},
 	/* "T. Ludewig" <t.ludewig@gmail.com> */
 	{"Canon:PowerShot SX500IS",		0x04a9, 0x325c, PTPBUG_DELETE_SENDS_EVENT},
 	/* "T. Ludewig" <t.ludewig@gmail.com> */


update debug_print about plug-in

update debug_print about plug-in

--- src/replyto.c
+++ src/replyto.c
@@ -77,7 +77,7 @@
 {
   syl_init_gettext(REPLYTO, "lib/locale");

-  debug_print(gettext("ReplyToNotify notify support Plug-in"));
+  debug_print(gettext("ReplyTo support Plug-in"));
   debug_print(dgettext("ReplyTo", "ReplyTo support Plug-in"));

   syl_plugin_add_menuitem("/Tools", NULL, NULL, NULL);


Fix a memory leak when forwarding REMOTE_ADDR.

The code was using `bfromcstr`, which copies and allocates a new
`bstring`, but it seems that ownership remained with the caller
and it was not calling `bdestroy`. Fixed by calling `bdestroy`
manually.

--- src/request.c
+++ src/request.c
@@ -416,7 +416,11 @@
         }

         tns_render_hash_pair(&outbuf, &HTTP_METHOD, method);
-        tns_render_hash_pair(&outbuf, &HTTP_REMOTE_ADDR, bfromcstr(conn->remote));
+        bstring bremote = bfromcstr(conn->remote);
+        tns_render_hash_pair(&outbuf, &HTTP_REMOTE_ADDR, bremote);
+        if (bremote) {
+            bdestroy(bremote);
+        }
     }

     check(tns_render_request_end(&outbuf, header_start, uuid, id, Request_path(req)) != -1, "Failed to finalize request.");
@@ -522,7 +526,11 @@
             B(headers, &HTTP_URL_SCHEME, &HTTP_HTTP, &f);
         }

-        B(headers, &HTTP_REMOTE_ADDR, bfromcstr(conn->remote), &f);
+        bstring bremote = bfromcstr(conn->remote);
+        B(headers, &HTTP_REMOTE_ADDR, bremote, &f);
+        if (bremote) {
+            bdestroy(bremote);
+        }
     }

     bconchar(headers, '}');


fix a rare crash

fix a rare crash

--- src/reverse.c
+++ src/reverse.c
@@ -45,7 +45,7 @@
 static int drain(sox_effect_t * effp, sox_sample_t *obuf, size_t *osamp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  size_t i, j;
+  int i, j;

   if (p->pos == 0) {
     fflush(p->tmp_file);


Improved inteface of scanner.

Improved inteface of scanner.

--- src/scanner.h
+++ src/scanner.h
@@ -1,9 +1,11 @@
 #ifndef FLORA_SCANNER_H
 #define FLORA_SCANNER_H

-#include <cctype>
+#include <queue>
+#include <utility>

 #include "flora.h"
+#include "checks.h"
 #include "token.h"
 #include "character-predicates.h"

@@ -18,13 +20,39 @@
   ~Scanner();
   // TODO
   void Initialize();
-  Token Peek();
   Token Advance();
+  void SaveBookmark();
+  void LoadBookmark();
+  void ClearBookmark();
+  std::string GetTokenLiteral();
 private:
+  enum class State {
+    Uninitialized, Running, Recording, Restoring, Error, End
+  };
+  // The recording queue for bookmark function
+  std::queue<std::pair<Token, std::string>> records_;
+  // The current state of scanner
+  State state_;
+  // Next character
+  int peek;
+  // The literal of token
+  std::string literal_;
+  // Advance next character.
+  char Next();
+  // Returns true if the next character is expected character
+  bool Match(char expect);
+  // Set the literal of token
+  inline void SetTokenLiteral(const char *literal);
+  inline void SetTokenLiteral(std::string &literal);
+  inline void SetTokenLiteral(char literal);
+  inline void ClearTokenLiteral();
+  // Report error, call before returning Token::Illegal
+  inline void ReportScannerError(const char *message);
+  inline void MarkEndOfSource();
   // Scan a token
   Token Scan();
-  // Skip comments
-  void SkipMultipleLineComment();
+  // Skip comments, returns true if error occurs
+  bool SkipMultipleLineComment();
   void SkipSingleLineComment();
   // Scan literals and escapees of strings and characters
   Token ScanStringLiteral();
@@ -32,9 +60,9 @@
   char ScanStringEscape();
   char ScanCharacterEscape();
   // Scan identifiers and keywords
-  Token ScanIdentifierOrKeyword();
+  Token ScanIdentifierOrKeyword(char firstChar);
   // Scan integers and real numebers
-  Token ScanIntegerOrRealNumber();
+  Token ScanIntegerOrRealNumber(char firstChar);
   Token ScanRealNumber();
 };


Create math_tables.h

Create math_tables.h

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

--- math_tables.h
+++ math_tables.h
@@ -0,0 +1,36 @@
+#ifndef MATH_TABLES_H
+#define MATH_TABLES_H
+
+#include <stdint.h>
+
+#define AUBANDS 25
+
+extern const int32_t lfe_fir[512];
+extern const int32_t band_interpolation[2][512];
+extern const int32_t band_spectrum[2][8];
+
+extern const int32_t cos_table[2048];
+extern const int32_t bitrev[256];
+extern const int32_t auf[9][AUBANDS][256];
+extern const int32_t cb_to_level[2048];
+extern const int32_t cb_to_add[256];
+
+extern const int32_t quant_levels_cb[27];
+
+#ifdef _MSC_VER
+#define INLINE __forceinline
+#else
+#define INLINE inline
+#endif
+
+INLINE static int32_t cos_t(int32_t x)
+{
+	return cos_table[x & 2047];
+}
+
+INLINE static int32_t sin_t(int32_t x)
+{
+	return cos_t(x - 512);
+}
+
+#endif


sdo_req: explain why we do things via mloop_async.

--- src/sdo_req.c
+++ src/sdo_req.c
@@ -12,6 +12,11 @@
  * A request can be handled in either a synchronous or asynchronous manner, by
  * either waiting for it to finish using sdo_req_wait() or registering an
  * "on_done" callback.
+ *
+ * Note: When an SDO request is done, the next request on the queue is scheduled
+ * to be processed via mloop_async. This is because sdo_async cannot start
+ * itself within its own on_done callback. The same is also true for mloop_async
+ * but because they are starting each other, the problem is solved for both.
  */
 #include <assert.h>
 #include <pthread.h>


Add SPI bit modify command definition

Add SPI bit modify command definition


Fix starting and stopping of SysV init scripts

Due to lack of tests the SysV start/stop script stopped working.
Unclear when.

Signed-off-by: Joachim Wiberg <583c295fd7602c168ad814279bbc3894ba65f5d6@gmail.com>

--- src/service.c
+++ src/service.c
@@ -570,6 +570,7 @@
 			wordfree(&we);
 		} else {
 			i = 0;
+			args[i++] = svc->cmd;
 			args[i++] = svc->cmd;
 			args[i++] = "start";
 		}


sub shm CHANGE continue normally on callback timeout

Refs #1680

--- src/shm_sub.c
+++ src/shm_sub.c
@@ -1794,7 +1794,7 @@
             break;
         default:
             /* no longer a listener event, we could have timeouted */
-            sr_errinfo_new(&err_info, SR_ERR_INTERNAL, NULL, "Unable to finish processing event with ID %u priority %u "
+            sr_errinfo_new(&err_info, SR_ERR_TIME_OUT, NULL, "Unable to finish processing event with ID %u priority %u "
                     "(timeout probably).", multi_sub_shm->request_id, multi_sub_shm->priority);
             return err_info;
         }
@@ -2064,7 +2064,7 @@
         break;
     default:
         /* no longer a listener event, we could have timeouted */
-        sr_errinfo_new(&err_info, SR_ERR_INTERNAL, NULL, "Unable to finish processing event with ID %u (timeout probably).",
+        sr_errinfo_new(&err_info, SR_ERR_TIME_OUT, NULL, "Unable to finish processing event with ID %u (timeout probably).",
                 sub_shm->request_id);
         return err_info;
     }
@@ -2839,7 +2839,9 @@

     while (ATOMIC_LOAD_RELAXED(subs->thread_running)) {
         /* process the new event (or subscription stop time has elapsed) */
-        if (sr_process_events(subs, NULL, &stop_time_in) != SR_ERR_OK) {
+        ret = sr_process_events(subs, NULL, &stop_time_in);
+        if ((ret != SR_ERR_OK) && (ret != SR_ERR_TIME_OUT)) {
+            /* continue on time out */
             goto error;
         }


Fixed weird C error.

Fixed weird C error.

--- src/shooter.c
+++ src/shooter.c
@@ -53,9 +53,10 @@
 }

 void runShooter() {
+	float controllerOutput;
 	switch (state) {
 	case (LONG):
-		float controllerOutput = bangBangController(SHOOTER_SPEED_LONG, shooterSpeed);
+		controllerOutput = bangBangController(SHOOTER_SPEED_LONG, shooterSpeed);
 		printf("Shooter Power: %f/n/r", controllerOutput);
 		setShooterMotor(controllerOutput * 127);
 		break;


fix tick function name

fix tick function name

--- src/sixfour.c
+++ src/sixfour.c
@@ -73,7 +73,7 @@
     }
 }

-static void handle_second_tick(struct tm* tick_time, TimeUnits units_changed) {
+static void handle_minute_tick(struct tm* tick_time, TimeUnits units_changed) {
     APP_LOG(APP_LOG_LEVEL_DEBUG, "tick");

     DictionaryIterator *iter;
@@ -194,7 +194,7 @@
     const bool animated = true;
     window_stack_push(window, animated);

-    tick_timer_service_subscribe(MINUTE_UNIT, &handle_second_tick);
+    tick_timer_service_subscribe(MINUTE_UNIT, &handle_minute_tick);

     APP_LOG(APP_LOG_LEVEL_DEBUG, "init done");
 }


Fix C++ usage of sparkey library

Fix C++ usage of sparkey library

--- src/sparkey.h
+++ src/sparkey.h
@@ -205,6 +205,10 @@

 #include <stdint.h>

+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef enum {
   SPARKEY_SUCCESS = 0,
   SPARKEY_INTERNAL_ERROR = -1,
@@ -639,5 +643,9 @@
  */
 char * sparkey_create_log_filename(const char *index_filename);

+#ifdef __cplusplus
+}
 #endif

+#endif
+


Added SRU decode of maximumTerms, responsePosition and extraRequestData

--- src/srwutil.c
+++ src/srwutil.c
@@ -1,8 +1,8 @@
 /*
- * Copyright (c) 2002-2004, Index Data.
+ * Copyright (c) 2002-2005, Index Data.
  * See the file LICENSE for details.
  *
- * $Id: srwutil.c,v 1.21 2005-01-09 21:50:26 adam Exp $
+ * $Id: srwutil.c,v 1.22 2005-01-11 10:50:06 adam Exp $
  */
 /**
  * \file srwutil.c
@@ -234,6 +234,9 @@
     return 2;
 }

+/**
+  http://www.loc.gov/z3950/agency/zing/srw/service.html
+*/
 int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
 		   Z_SOAP **soap_package, ODR decode, char **charset,
 		   Z_SRW_diagnostic **diag, int *num_diag)
@@ -262,6 +265,9 @@
 	char *recordPacking = "xml";  /* xml packing is default for SRU */
 	char *maximumRecords = 0;
 	char *startRecord = 0;
+	char *maximumTerms = 0;
+	char *responsePosition = 0;
+	char *extraRequestData = 0;
 	char **uri_name;
 	char **uri_val;

@@ -313,6 +319,12 @@
 		    maximumRecords = v;
 		else if (!strcmp(n, "startRecord"))
 		    startRecord = v;
+		else if (!strcmp(n, "maximumTerms"))
+		    maximumTerms = v;
+		else if (!strcmp(n, "responsePosition"))
+		    responsePosition = v;
+		else if (!strcmp(n, "extraRequestData"))
+		    extraRequestData = v;
 		else
 		    yaz_add_srw_diagnostic(decode, diag, num_diag, 8, n);
 	    }
@@ -385,6 +397,8 @@
         }
 	else if (!strcmp(operation, "explain"))
 	{
+	    /* Transfer SRU explain parameters to common struct */
+	    /* http://www.loc.gov/z3950/agency/zing/srw/explain.html */
             Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_explain_request);

 	    sr->srw_version = version;
@@ -410,7 +424,12 @@
 	}
 	else if (!strcmp(operation, "scan"))
 	{
+	    /* Transfer SRU scan parameters to common struct */
+	    /* http://www.loc.gov/z3950/agency/zing/srw/scan.html */
             Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_scan_request);
+
+	    sr->srw_version = version;
+	    *srw_pdu = sr;

             if (scanClause)
             {
@@ -425,9 +444,15 @@
 	    else
 		yaz_add_srw_diagnostic(decode, diag, num_diag, 7,
 				       "scanClause");
-	    sr->srw_version = version;
-	    *srw_pdu = sr;
 	    sr->u.scan_request->database = db;
+
+	    if (maximumTerms)
+		sr->u.scan_request->maximumTerms =
+		    odr_intdup(decode, atoi(maximumTerms));
+	    if (responsePosition)
+		sr->u.scan_request->responsePosition =
+		    odr_intdup(decode, atoi(responsePosition));
+
             sr->u.scan_request->stylesheet = stylesheet;

 	    (*soap_package) = odr_malloc(decode, sizeof(**soap_package));


Fixed bug #601: SRU decode does not issue diagnostic for bad parameter values.

--- src/srwutil.c
+++ src/srwutil.c
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2005, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: srwutil.c,v 1.41 2006-06-02 13:08:27 adam Exp $
+ * $Id: srwutil.c,v 1.42 2006-06-05 18:08:10 adam Exp $
  */
 /**
  * \file srwutil.c
@@ -398,6 +398,22 @@
     return 2;
 }

+static int yaz_sru_integer_decode(ODR odr, const char *pname,
+                                  const char *valstr, int **valp,
+                                  Z_SRW_diagnostic **diag, int *num_diag)
+
+{
+    int ival;
+    if (!valstr)
+        return 0;
+    if (sscanf(valstr, "%d", &ival) != 1)
+    {
+        yaz_add_srw_diagnostic(odr, diag, num_diag, 6, pname);
+        return 0;
+    }
+    *valp = odr_intdup(odr, ival);
+    return 1;
+}
 /**
   http://www.loc.gov/z3950/agency/zing/srw/service.html
 */
@@ -561,12 +577,13 @@
             sr->u.request->recordPacking = recordPacking;
             sr->u.request->stylesheet = stylesheet;

-            if (maximumRecords)
-                sr->u.request->maximumRecords =
-                    odr_intdup(decode, atoi(maximumRecords));
-            if (startRecord)
-                sr->u.request->startRecord =
-                    odr_intdup(decode, atoi(startRecord));
+            yaz_sru_integer_decode(decode, "maximumRecords", maximumRecords,
+                                   &sr->u.request->maximumRecords,
+                                   diag, num_diag);
+
+            yaz_sru_integer_decode(decode, "startRecord", startRecord,
+                                   &sr->u.request->startRecord,
+                                   diag, num_diag);

             sr->u.request->database = db;

@@ -637,12 +654,15 @@
                                        "scanClause");
             sr->u.scan_request->database = db;

-            if (maximumTerms)
-                sr->u.scan_request->maximumTerms =
-                    odr_intdup(decode, atoi(maximumTerms));
-            if (responsePosition)
-                sr->u.scan_request->responsePosition =
-                    odr_intdup(decode, atoi(responsePosition));
+            yaz_sru_integer_decode(decode, "maximumTerms",
+                                   maximumTerms,
+                                   &sr->u.scan_request->maximumTerms,
+                                   diag, num_diag);
+
+            yaz_sru_integer_decode(decode, "responsePosition",
+                                   responsePosition,
+                                   &sr->u.scan_request->responsePosition,
+                                   diag, num_diag);

             sr->u.scan_request->stylesheet = stylesheet;


ccl/ ident/ new vars

ccl/ ident/ new vars

--- src/stealth.h
+++ src/stealth.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014 The Okcash Developers
+// Copyright (c) 2014 The Okcash developers
 // Distributed under the MIT/X11 software license, see the accompanying
 // file license.txt or http://www.opensource.org/licenses/mit-license.php.

@@ -13,20 +13,10 @@
 #include "util.h"
 #include "serialize.h"
 #include "key.h"
-
-
-typedef std::vector<uint8_t> data_chunk;
+#include "hash.h"
+#include "types.h"

 const uint32_t MAX_STEALTH_NARRATION_SIZE = 48;
-
-const size_t ec_secret_size = 32;
-const size_t ec_compressed_size = 33;
-const size_t ec_uncompressed_size = 65;
-
-const uint8_t stealth_version_byte = 0x28;
-
-typedef struct ec_secret { uint8_t e[ec_secret_size]; } ec_secret;
-typedef data_chunk ec_point;

 typedef uint32_t stealth_bitfield;

@@ -36,27 +26,8 @@
     stealth_bitfield bitfield;
 };

-template <typename T, typename Iterator>
-T from_big_endian(Iterator in)
-{
-    //VERIFY_UNSIGNED(T);
-    T out = 0;
-    size_t i = sizeof(T);
-    while (0 < i)
-        out |= static_cast<T>(*in++) << (8 * --i);
-    return out;
-}
-
-template <typename T, typename Iterator>
-T from_little_endian(Iterator in)
-{
-    //VERIFY_UNSIGNED(T);
-    T out = 0;
-    size_t i = 0;
-    while (i < sizeof(T))
-        out |= static_cast<T>(*in++) << (8 * i++);
-    return out;
-}
+const uint256 MAX_SECRET("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140");
+const uint256 MIN_SECRET(16000); // increase? min valid key is 1

 class CStealthAddress
 {
@@ -64,7 +35,7 @@
     CStealthAddress()
     {
         options = 0;
-    }
+    };

     uint8_t options;
     ec_point scan_pubkey;
@@ -85,8 +56,13 @@

     bool operator <(const CStealthAddress& y) const
     {
-        return memcmp(&scan_pubkey[0], &y.scan_pubkey[0], ec_compressed_size) < 0;
-    }
+        return memcmp(&scan_pubkey[0], &y.scan_pubkey[0], EC_COMPRESSED_SIZE) < 0;
+    };
+
+    bool operator ==(const CStealthAddress& y) const
+    {
+        return memcmp(&scan_pubkey[0], &y.scan_pubkey[0], EC_COMPRESSED_SIZE) == 0;
+    };

     IMPLEMENT_SERIALIZE
     (
@@ -101,17 +77,15 @@

 };

-void AppendChecksum(data_chunk& data);
-
-bool VerifyChecksum(const data_chunk& data);
-
 int GenerateRandomSecret(ec_secret& out);

 int SecretToPublicKey(const ec_secret& secret, ec_point& out);

 int StealthSecret(ec_secret& secret, ec_point& pubkey, const ec_point& pkSpend, ec_secret& sharedSOut, ec_point& pkOut);
 int StealthSecretSpend(ec_secret& scanSecret, ec_point& ephemPubkey, ec_secret& spendSecret, ec_secret& secretOut);
-int StealthSharedToSecretSpend(ec_secret& sharedS, ec_secret& spendSecret, ec_secret& secretOut);
+int StealthSharedToSecretSpend(const ec_secret& sharedS, const ec_secret& spendSecret, ec_secret& secretOut);
+
+int StealthSharedToPublicKey(const ec_point& pkSpend, const ec_secret &sharedS, ec_point &pkOut);

 bool IsStealthAddress(const std::string& encodedAddress);


First implementation of yaz_stemmer API. Can compile.

--- src/stemmer.c
+++ src/stemmer.c
@@ -10,32 +10,95 @@

 #include <yaz/stemmer.h>

+#include <yaz/xmalloc.h>
+
+#include <libstemmer.h>
+
 #include <unicode/ustring.h>  /* some more string fcns*/
 #include <unicode/uchar.h>    /* char names           */

+enum stemmer_implementation {
+    yaz_snowball
+};
 struct yaz_stemmer_t
 {
     int implementation;
+    // Required for cloning.
+    const char *locale;
+    const char *rule;
     union {
-        struct sb_stemmer *snowballer;
+        struct sb_stemmer *sb_stemmer;
     };
 };

+const char* yaz_stemmer_lookup_charenc(const char *charenc) {
+    return charenc;
+}
+
+const char* yaz_stemmer_lookup_algorithm(const char *locale, const char *rule) {
+    return rule;
+}
+
+yaz_stemmer_p yaz_stemmer_snowball_create(const char *locale, const char *rule, UErrorCode *status) {
+    const char *charenc = yaz_stemmer_lookup_charenc(locale);
+    const char *algorithm = yaz_stemmer_lookup_algorithm(locale,rule);
+    struct sb_stemmer *stemmer = sb_stemmer_new(algorithm, charenc);
+    yaz_stemmer_p yaz_stemmer;
+    if (stemmer == 0) {
+        *status = U_ARGUMENT_TYPE_MISMATCH;
+        return 0;
+    }
+    yaz_stemmer = xmalloc(sizeof(*yaz_stemmer));
+    yaz_stemmer->implementation = yaz_snowball;
+    yaz_stemmer->locale = xstrdup(locale);
+    yaz_stemmer->rule = xstrdup(rule);
+    yaz_stemmer->sb_stemmer = stemmer;
+
+    return yaz_stemmer;
+}
+
 yaz_stemmer_p yaz_stemmer_create(const char *locale, const char *rule, UErrorCode *status) {
-    return 0;
+    *status = U_ZERO_ERROR;
+    // dispatch logic required if more algorithms is implemented.
+    return yaz_stemmer_snowball_create(locale, rule, status);
 }

 yaz_stemmer_p yaz_stemmer_clone(yaz_stemmer_p stemmer) {
-    return 0;
+    UErrorCode error = U_ZERO_ERROR;
+    return yaz_stemmer_create(stemmer->locale, stemmer->rule, &error);
 }

-void yaz_stemmer_stem(yaz_stemmer_p stemmer, struct icu_buf_utf16 *dst, struct icu_buf_utf16* src, UErrorCode *status) {
-
+void yaz_stemmer_stem(yaz_stemmer_p stemmer, struct icu_buf_utf16 *dst, struct icu_buf_utf16* src, UErrorCode *status)
+{
+    switch(stemmer->implementation) {
+    case yaz_snowball: {
+        int length;
+        struct icu_buf_utf8 *utf8_buf = icu_buf_utf8_create(0);
+        icu_utf16_to_utf8(utf8_buf, src, status);
+        if (*status == U_ZERO_ERROR) {
+            const char *sb_symbol = sb_stemmer_stem(stemmer->sb_stemmer, icu_buf_utf8_to_cstr(utf8_buf), length);
+            if (sb_symbol == 0) {
+                icu_buf_utf16_copy(dst, src);
+            }
+            else {
+                icu_utf16_from_utf8_cstr(dst, sb_symbol, status);
+            }
+        }
+        return ;
+        break;
+    }
+    }
 }

 void yaz_stemmer_destroy(yaz_stemmer_p stemmer) {
-
-
+    switch (stemmer->implementation) {
+    case yaz_snowball:
+        sb_stemmer_delete(stemmer->sb_stemmer);
+        break;
+    }
+    free(stemmer->locale);
+    free(stemmer->rule);
+    free(stemmer);
 }

 #endif /* YAZ_HAVE_ICU */


added char_is_digit()

added char_is_digit()

--- src/strutil.h
+++ src/strutil.h
@@ -17,6 +17,12 @@
     return (ch & ~0x1f) == 0;
 }

+static inline int
+char_is_digit(char ch)
+{
+    return ch >= '0' && ch <= '9';
+}
+
 void
 str_to_lower(char *s);


syscall: update io_uring_enter() to match kernel type

We would randomly fail depending on what garbage was passed in
the two sigset related fields.

Reported-by: Jeff Moyer <cd6badf7869d996b866599075536a600ed1910b5@redhat.com>
Signed-off-by: Jens Axboe <cd8c6775e60d6f67a6984377324e5290df3d5358@kernel.dk>

--- src/syscall.c
+++ src/syscall.c
@@ -36,5 +36,5 @@
 		   unsigned int flags)
 {
 	return syscall(__NR_sys_io_uring_enter, fd, to_submit, min_complete,
-			flags);
+			flags, NULL, 0);
 }


sysrepo BUGFIX memory leak

sysrepo BUGFIX memory leak

--- src/sysrepo.c
+++ src/sysrepo.c
@@ -4202,6 +4202,9 @@

 cleanup:
     lyd_free_withsiblings(input_tree);
+    while (output_tree->parent) {
+        output_tree = output_tree->parent;
+    }
     lyd_free_withsiblings(output_tree);
     if (err_info) {
         sr_free_values(*output, *output_cnt);