Don't count $x = x + 1 as initialising or using x

This means we now warn for this case like we already do for $x += 1
and similar.

--- compiler/analyser.c
+++ compiler/analyser.c
@@ -372,13 +372,13 @@
     p->name = q;
 }

-static struct node * read_AE(struct analyser * a, int B) {
+static struct node * read_AE(struct analyser * a, struct name * assigned_to, int B) {
     struct tokeniser * t = a->tokeniser;
     struct node * p;
     struct node * q;
     switch (read_token(t)) {
         case c_minus: /* monadic */
-            q = read_AE(a, 100);
+            q = read_AE(a, assigned_to, 100);
             if (q->type == c_neg) {
                 /* Optimise away double negation, which avoids generators
                  * having to worry about generating "--" (decrement operator
@@ -398,13 +398,16 @@
             p->right = q;
             break;
         case c_bra:
-            p = read_AE(a, 0);
+            p = read_AE(a, assigned_to, 0);
             get_token(a, c_ket);
             break;
         case c_name:
             p = new_node(a, c_name);
             name_to_node(a, p, 'i');
-            if (p->name) p->name->value_used = true;
+            if (p->name) {
+                // $x = x + 1 shouldn't count as a use of x.
+                p->name->value_used = (p->name != assigned_to);
+            }
             break;
         case c_maxint:
         case c_minint:
@@ -443,7 +446,8 @@
             } else {
                 result = SIZE(p->literalstring);
             }
-            p = new_node(a, c_number);
+            p->type = c_number;
+            p->literalstring = NULL;
             p->number = result;
             break;
         }
@@ -461,7 +465,7 @@
         }
         q = new_node(a, token);
         q->left = p;
-        q->right = read_AE(a, b);
+        q->right = read_AE(a, assigned_to, b);
         p = q;
     }
 }
@@ -513,7 +517,7 @@
         case 'D':
             p->aux = read_C(a); continue;
         case 'A':
-            p->AE = read_AE(a, 0); continue;
+            p->AE = read_AE(a, 0, 0); continue;
         case 'f':
             get_token(a, c_for); continue;
         case 'S':
@@ -834,6 +838,24 @@
     if (!a->modifyable) error(a, e_not_allowed_inside_reverse);
 }

+static int ae_uses_name(struct node * p, struct name * q) {
+    switch (p->type) {
+        case c_name:
+        case c_lenof:
+        case c_sizeof:
+            if (p->name == q) return 1;
+            break;
+        case c_neg:
+            return ae_uses_name(p->right, q);
+        case c_multiply:
+        case c_plus:
+        case c_minus:
+        case c_divide:
+            return ae_uses_name(p->left, q) || ae_uses_name(p->right, q);
+    }
+    return 0;
+}
+
 static struct node * read_C(struct analyser * a) {
     struct tokeniser * t = a->tokeniser;
     int token = read_token(t);
@@ -926,7 +948,7 @@
             read_token(t);
             if (t->token == c_bra) {
                 /* Handle newer $(AE REL_OP AE) syntax. */
-                struct node * n = read_AE(a, 0);
+                struct node * n = read_AE(a, 0, 0);
                 read_token(t);
                 switch (t->token) {
                     case c_eq:
@@ -938,7 +960,7 @@
                         struct node * lhs = n;
                         n = new_node(a, t->token);
                         n->left = lhs;
-                        n->AE = read_AE(a, 0);
+                        n->AE = read_AE(a, 0, 0);
                         get_token(a, c_ket);
                         break;
                     }
@@ -981,32 +1003,32 @@
                         q = NULL;
                     }
                     p = new_node(a, read_AE_test(a));
-                    p->AE = read_AE(a, 0);
-
-                    if (q) {
-                        switch (p->type) {
-                            case c_mathassign:
-                                q->initialised = true;
-                                p->name = q;
-                                break;
-                            default:
-                                /* +=, etc don't "initialise" as they only
-                                 * amend an existing value.  Similarly, they
-                                 * don't count as using the value.
-                                 */
-                                p->name = q;
-                                break;
-                            case c_eq:
-                            case c_ne:
-                            case c_gr:
-                            case c_ge:
-                            case c_ls:
-                            case c_le:
-                                p->left = new_node(a, c_name);
-                                p->left->name = q;
+                    switch (p->type) {
+                        case c_eq:
+                        case c_ne:
+                        case c_gr:
+                        case c_ge:
+                        case c_ls:
+                        case c_le:
+                            p->left = new_node(a, c_name);
+                            p->left->name = q;
+                            if (q) {
                                 q->value_used = true;
-                                break;
-                        }
+                            }
+                            p->AE = read_AE(a, NULL, 0);
+                            break;
+                        default:
+                            /* +=, etc don't "initialise" as they only
+                             * amend an existing value.  Similarly, they
+                             * don't count as using the value.
+                             */
+                            p->name = q;
+                            p->AE = read_AE(a, q, 0);
+                            if (p->type == c_mathassign && q) {
+                                /* $x = x + 1 doesn't initialise x. */
+                                q->initialised = !ae_uses_name(p->AE, q);
+                            }
+                            break;
                     }
                 }
                 if (q) mark_used_in(a, q, p);
@@ -1252,6 +1274,7 @@
             case c_dollar:
                 /* c_true is a no-op. */
                 p->type = c_true;
+                p->AE = NULL;
                 break;
             default:
                 /* There are no read accesses to this variable, so any


calibrate: home in on correct lpj value more quickly

Binary chop with a jiffy-resync on each step to find an upper bound is
slow, so just race in a tight-ish loop to find an underestimate.

If done with lots of individual steps, sometimes several hundreds of
iterations would be required, which would impose a significant overhead,
and make the initial estimate very low.  By taking slowly increasing steps
there will be less overhead.

E.g.  an x86_64 2.67GHz could have fitted in 613 individual small delays,
but in reality should have been able to fit in a single delay 644 times
longer, so underestimated by 31 steps.  To reach the equivalent of 644
small delays with the accelerating scheme now requires about 130
iterations, so has <1/4th of the overhead, and can therefore be expected
to underestimate by only 7 steps.

As now we have a better initial estimate we can binary chop over a smaller
range.  With the loop overhead in the initial estimate kept low, and the
step sizes moderate, we won't have under-estimated by much, so chose as
tight a range as we can.

Signed-off-by: Phil Carmody <b694b4b08431b3bb23c9b1e9882202a88c5cc143@nokia.com>
Cc: Ingo Molnar <9dbbbf0688fedc85ad4da37637f1a64b8c718ee2@elte.hu>
Cc: Thomas Gleixner <00e4cf8f46a57000a44449bf9dd8cbbcc209fd2a@linutronix.de>
Cc: "H. Peter Anvin" <8a453bad9912ffe59bc0f0b8abe03df9be19379e@zytor.com>
Tested-by: Stephen Boyd <010521127f513270fe503d86ab8316ac5147f4b7@codeaurora.org>
Cc: Greg KH <79e2475f81a6317276bf7cbb3958b20d289b78df@kroah.com>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>

--- init/calibrate.c
+++ init/calibrate.c
@@ -110,8 +110,8 @@

 /*
  * This is the number of bits of precision for the loops_per_jiffy.  Each
- * bit takes on average 1.5/HZ seconds.  This (like the original) is a little
- * better than 1%
+ * time we refine our estimate after the first takes 1.5/HZ seconds, so try
+ * to start with a good estimate.
  * For the boot cpu we can skip the delay calibration and assign it a value
  * calculated based on the timer frequency.
  * For the rest of the CPUs we cannot assume that the timer frequency is same as
@@ -121,38 +121,49 @@

 static unsigned long __cpuinit calibrate_delay_converge(void)
 {
-	unsigned long lpj, ticks, loopbit;
-	int lps_precision = LPS_PREC;
+	/* First stage - slowly accelerate to find initial bounds */
+	unsigned long lpj, ticks, loopadd, chop_limit;
+	int trials = 0, band = 0, trial_in_band = 0;

 	lpj = (1<<12);
-	while ((lpj <<= 1) != 0) {
-		/* wait for "start of" clock tick */
+
+	/* wait for "start of" clock tick */
+	ticks = jiffies;
+	while (ticks == jiffies)
+		; /* nothing */
+	/* Go .. */
+	ticks = jiffies;
+	do {
+		if (++trial_in_band == (1<<band)) {
+			++band;
+			trial_in_band = 0;
+		}
+		__delay(lpj * band);
+		trials += band;
+	} while (ticks == jiffies);
+	/*
+	 * We overshot, so retreat to a clear underestimate. Then estimate
+	 * the largest likely undershoot. This defines our chop bounds.
+	 */
+	trials -= band;
+	loopadd = lpj * band;
+	lpj *= trials;
+	chop_limit = lpj >> (LPS_PREC + 1);
+
+	/*
+	 * Do a binary approximation to get lpj set to
+	 * equal one clock (up to LPS_PREC bits)
+	 */
+	while (loopadd > chop_limit) {
+		lpj += loopadd;
 		ticks = jiffies;
 		while (ticks == jiffies)
-			/* nothing */;
-		/* Go .. */
-		ticks = jiffies;
-		__delay(lpj);
-		ticks = jiffies - ticks;
-		if (ticks)
-			break;
-	}
-
-	/*
-	 * Do a binary approximation to get lpj set to
-	 * equal one clock (up to lps_precision bits)
-	 */
-	lpj >>= 1;
-	loopbit = lpj;
-	while (lps_precision-- && (loopbit >>= 1)) {
-		lpj |= loopbit;
-		ticks = jiffies;
-		while (ticks == jiffies)
-			/* nothing */;
+			; /* nothing */
 		ticks = jiffies;
 		__delay(lpj);
 		if (jiffies != ticks)	/* longer than 1 tick */
-			lpj &= ~loopbit;
+			lpj -= loopadd;
+		loopadd >>= 1;
 	}

 	return lpj;


Comments

Comments


lib-http: Added assert.

lib-http: Added assert.

--- src/lib-http/http-client-request.c
+++ src/lib-http/http-client-request.c
@@ -301,6 +301,7 @@
 	off_t ret;

 	i_assert(req->payload_input != NULL);
+	i_assert(req->payload_output != NULL);

 	/* chunked ostream needs to write to the parent stream's buffer */
 	o_stream_set_max_buffer_size(output, IO_BLOCK_SIZE);


test-message-parser: Fixed and improvements.

--- src/lib-mail/test-message-parser.c
+++ src/lib-mail/test-message-parser.c
@@ -67,28 +67,28 @@
 	return TRUE;
 }

-static void test_message_parser(void)
+static void test_message_parser_small_blocks(void)
 {
 	struct message_parser_ctx *parser;
 	struct istream *input;
 	struct message_part *parts, *parts2;
 	struct message_block block;
-	unsigned int i;
-	bool success = TRUE;
+	unsigned int i, end_of_headers_idx;
 	pool_t pool;
 	int ret;

+	test_begin("message parser in small blocks");
 	pool = pool_alloconly_create("message parser", 10240);
-	input = i_stream_create_from_data(test_msg, TEST_MSG_LEN);
+	input = test_istream_create(test_msg);

+	/* full parsing */
 	parser = message_parser_init(pool, input, 0, 0);
 	while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ;
-	i_assert(ret < 0);
-	ret = message_parser_deinit(&parser, &parts);
-	i_assert(ret == 0);
-	i_stream_unref(&input);
+	test_assert(ret < 0);
+	test_assert(message_parser_deinit(&parser, &parts) == 0);

-	input = test_istream_create(test_msg);
+	/* parsing in small blocks */
+	i_stream_seek(input, 0);
 	test_istream_set_allow_eof(input, FALSE);

 	parser = message_parser_init(pool, input, 0, 0);
@@ -98,26 +98,38 @@
 			test_istream_set_allow_eof(input, TRUE);
 		while ((ret = message_parser_parse_next_block(parser,
 							      &block)) > 0) ;
-		if (ret < 0 && i < TEST_MSG_LEN*2) {
-			success = FALSE;
-			break;
-		}
+		test_assert(ret == 0 || i > TEST_MSG_LEN*2);
 	}
-	ret = message_parser_deinit(&parser, &parts2);
-	i_assert(ret == 0);
+	test_assert(message_parser_deinit(&parser, &parts2) == 0);
+	test_assert(msg_parts_cmp(parts, parts2));
+
+	/* parsing in small blocks from preparsed parts */
+	i_stream_seek(input, 0);
+	test_istream_set_allow_eof(input, FALSE);
+
+	end_of_headers_idx = strstr(test_msg, "\n-----") - test_msg;
+	parser = message_parser_init_from_parts(parts, input, 0,
+					MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK);
+	for (i = 1; i <= TEST_MSG_LEN*2+1; i++) {
+		test_istream_set_size(input, i/2);
+		if (i > TEST_MSG_LEN*2)
+			test_istream_set_allow_eof(input, TRUE);
+		while ((ret = message_parser_parse_next_block(parser,
+							      &block)) > 0) ;
+		test_assert(ret == 0 || i >= end_of_headers_idx);
+	}
+	test_assert(message_parser_deinit(&parser, &parts2) == 0);
+	test_assert(msg_parts_cmp(parts, parts2));
+
 	i_stream_unref(&input);
-
-	if (!msg_parts_cmp(parts, parts2))
-		success = FALSE;
-
 	pool_unref(&pool);
-	test_out("message_parser()", success);
+	test_end();
 }

 int main(void)
 {
 	static void (*test_functions[])(void) = {
-		test_message_parser,
+		test_message_parser_small_blocks,
 		NULL
 	};
 	return test_run(test_functions);


lib-settings: Support also "seconds" and "minutes" (instead of just secs/mins)

--- src/lib-settings/settings-parser.c
+++ src/lib-settings/settings-parser.c
@@ -362,12 +362,14 @@
 	switch (i_toupper(*p)) {
 	case 'S':
 		multiply = 1;
-		if (strncasecmp(p, "secs", strlen(p)) == 0)
+		if (strncasecmp(p, "secs", strlen(p)) == 0 ||
+		    strncasecmp(p, "seconds", strlen(p)) == 0)
 			p = "";
 		break;
 	case 'M':
 		multiply = 60;
-		if (strncasecmp(p, "mins", strlen(p)) == 0)
+		if (strncasecmp(p, "mins", strlen(p)) == 0 ||
+		    strncasecmp(p, "minutes", strlen(p)) == 0)
 			p = "";
 		break;
 	case 'H':


Don't crash with 0 byte mails when saving/copying them and trying to add e.g. bodystructure to cache.

--- src/lib-storage/index/index-mail.c
+++ src/lib-storage/index/index-mail.c
@@ -1270,6 +1270,9 @@
 {
 	struct index_mail *mail = (struct index_mail *)_mail;

+	/* This is needed with 0 byte mails to get hdr=NULL call done. */
+	index_mail_cache_parse_continue(_mail);
+
 	if (mail->data.received_date == (time_t)-1)
 		mail->data.received_date = received_date;
 	if (mail->data.save_date == (time_t)-1) {


lib-storage: Fixed checking if mail's virtual size is cached.

--- src/lib-storage/index/index-mail.c
+++ src/lib-storage/index/index-mail.c
@@ -1329,7 +1329,7 @@
 		uoff_t vsize;

 		_mail->lookup_abort = MAIL_LOOKUP_ABORT_NOT_IN_CACHE;
-		if (mail_get_virtual_size(_mail, &vsize) <= 0)
+		if (mail_get_virtual_size(_mail, &vsize) < 0)
 			mail->data.access_part |= READ_HDR | READ_BODY;
 		_mail->lookup_abort = MAIL_LOOKUP_ABORT_NEVER;
 	}


Assert-crashfix

Assert-crashfix

--- src/lib-storage/index/index-sort.c
+++ src/lib-storage/index/index-sort.c
@@ -667,6 +667,7 @@
 	const struct mail_index_header *hdr;
 	const void *data;
 	struct mail_sort_node node;
+	uint32_t last_seq;

 	i_assert(mail->transaction == program->t);

@@ -708,7 +709,8 @@

 	/* add the nodes in the middle */
 	node.seq = program->last_sorted_seq + 1;
-	for (; node.seq <= program->prev_seq; node.seq++) {
+	last_seq = program->prev_seq;
+	for (; node.seq <= last_seq; node.seq++) {
 		mail_index_lookup_ext(t->trans_view, mail->seq, program->ext_id,
 				      &data, NULL);


cross/WindowInfo: USING math::Rectf INSTEAD OF glm::vec4 FOR BOUNDS

--- core/src/cross/WindowInfo.h
+++ core/src/cross/WindowInfo.h
@@ -1,79 +1,71 @@
-/*
- * THE NEW CHRONOTEXT TOOLKIT: https://github.com/arielm/new-chronotext-toolkit
- * COPYRIGHT (C) 2012-2015, ARIEL MALKA ALL RIGHTS RESERVED.
- *
- * THE FOLLOWING SOURCE-CODE IS DISTRIBUTED UNDER THE SIMPLIFIED BSD LICENSE:
- * https://github.com/arielm/new-chronotext-toolkit/blob/master/LICENSE.md
- */
-
 #pragma once

-#include "glm.h"
+#include "math/Rect.h"

 #include <iostream>

 namespace chr
 {
-    struct WindowInfo
+  struct WindowInfo
+  {
+    union
     {
-        union
-        {
-          glm::vec2 size;
-          struct { float width, height; };
-        };
+      glm::vec2 size;
+      struct { float width, height; };
+    };

-        int aaSamples;
-        int depthBits;
+    int aaSamples;
+    int depthBits;

-        static WindowInfo create(int width, int height, int aaSamples = 0, int depthBits = 0)
-        {
-            return WindowInfo(width, height, aaSamples, depthBits);
-        }
-
-        WindowInfo(const glm::ivec2 &size = glm::zero<glm::ivec2>(), int aaSamples = 0, int depthBits = 0)
-        :
-        size(size),
-        aaSamples(aaSamples),
-        depthBits(depthBits)
-        {}
-
-        WindowInfo(int width, int height, int aaSamples = 0, int depthBits = 0)
-        :
-        size(width, height),
-        aaSamples(aaSamples),
-        depthBits(depthBits)
-        {}
-
-        void rotate()
-        {
-            size = size.yx();
-        }
-
-        glm::vec4 bounds() const
-        {
-            return glm::vec4(0, 0, width, height);
-        }
+    static WindowInfo create(int width, int height, int aaSamples = 0, int depthBits = 0)
+    {
+      return WindowInfo(width, height, aaSamples, depthBits);
+    }
+
+    WindowInfo(const glm::ivec2 &size = glm::zero<glm::ivec2>(), int aaSamples = 0, int depthBits = 0)
+    :
+    size(size),
+    aaSamples(aaSamples),
+    depthBits(depthBits)
+    {}
+
+    WindowInfo(int width, int height, int aaSamples = 0, int depthBits = 0)
+    :
+    size(width, height),
+    aaSamples(aaSamples),
+    depthBits(depthBits)
+    {}
+
+    void rotate()
+    {
+      size = size.yx();
+    }
+
+    math::Rectf bounds() const
+    {
+      return math::Rectf(0, 0, width, height);
+    }

-        glm::vec2 center() const
-        {
-            return size * 0.5f;
-        }
-
-        float aspectRatio() const
-        {
-            return (size.y > 0) ? (width / height) : 0;
-        }
-
-        friend std::ostream& operator<<(std::ostream &lhs, const WindowInfo &rhs)
-        {
-            lhs
-            << "{"
-            << "size: [" << rhs.width << ", " << rhs.height << "]"
-            << ", anti-aliasing samples: " << rhs.aaSamples
-            << ", depth-bits: " << rhs.depthBits
-            << "}";
-
-            return lhs;
-        }
-    };
+    glm::vec2 center() const
+    {
+      return size * 0.5f;
+    }
+
+    float aspectRatio() const
+    {
+      return (size.y > 0) ? (width / height) : 0;
+    }
+
+    friend std::ostream& operator<<(std::ostream &lhs, const WindowInfo &rhs)
+    {
+      lhs
+      << "{"
+      << "size: [" << rhs.width << ", " << rhs.height << "]"
+      << ", anti-aliasing samples: " << rhs.aaSamples
+      << ", depth-bits: " << rhs.depthBits
+      << "}";
+
+      return lhs;
+    }
+  };
 }


evas: don't randomly move code around !

evas: don't randomly move code around !

git-svn-id: 24a995eca3b83137dd7eab3408044d7832e202f7@65916 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

--- src/lib/canvas/evas_object_image.c
+++ src/lib/canvas/evas_object_image.c
@@ -1,5 +1,7 @@
-#include "evas_common.h"
-#include "evas_private.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"  /* so that EAPI in Evas.h is correctly defined */
+#endif
+
 #include <sys/types.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -8,6 +10,8 @@
 #endif
 #include <math.h>

+#include "evas_common.h"
+#include "evas_private.h"
 #include "../engines/common/evas_convert_color.h"
 #include "../engines/common/evas_convert_colorspace.h"
 #include "../engines/common/evas_convert_yuv.h"


fix EAPI value on Windows

fix EAPI value on Windows

git-svn-id: 6d771e449150288cc513807b7f4d2af31e9482bd@40597 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

--- src/lib/canvas/evas_object_table.c
+++ src/lib/canvas/evas_object_table.c
@@ -1,5 +1,5 @@
+#include <errno.h>
 #include "evas_common.h"
-#include <errno.h>

 typedef struct _Evas_Object_Table_Data       Evas_Object_Table_Data;
 typedef struct _Evas_Object_Table_Option     Evas_Object_Table_Option;


Fix a little typo.

Fix a little typo.

SVN revision: 36989

--- src/lib/ecore_con/ecore_con_info.c
+++ src/lib/ecore_con/ecore_con_info.c
@@ -275,7 +275,7 @@
 	    recv = (Ecore_Con_Info *)torecv;

 	    recv->info.ai_addr = torecv + sizeof(Ecore_Con_Info);
-	    if (torecv != (sizeof(Ecore_Con_Info) + recv->info.ai_addrlen))
+	    if (torecv_len != (sizeof(Ecore_Con_Info) + recv->info.ai_addrlen))
 	      recv->info.ai_canonname = torecv + sizeof(Ecore_Con_Info) + recv->info.ai_addrlen;
 	    else
 	      recv->info.ai_canonname = NULL;


elementary/scroller - --duplicated compare.

--- src/lib/elm_interface_scrollable.c
+++ src/lib/elm_interface_scrollable.c
@@ -1529,23 +1529,26 @@
    eo_do(sid->pan_obj, elm_obj_pan_pos_min_get(&minx, &miny));
    eo_do(sid->pan_obj, elm_obj_pan_pos_get(&px, &py));

-   if (_paging_is_enabled(sid) && sid->page_snap_horiz)
-     {
-        //we passed one page to the right
-        if (x > sid->current_page.x + sid->pagesize_h)
-          x = sid->current_page.x + sid->pagesize_h;
-        //we passed one page to the left
-        if (x < sid->current_page.x - sid->pagesize_h)
-          x = sid->current_page.x - sid->pagesize_h;
-     }
-   if (_paging_is_enabled(sid) && sid->page_snap_vert)
-     {
-        //we passed one page to the bottom
-        if (y > sid->current_page.y + sid->pagesize_v)
-          y = sid->current_page.y + sid->pagesize_v;
-        //we passed one page to the top
-        if (y < sid->current_page.y - sid->pagesize_v)
-          y = sid->current_page.y - sid->pagesize_v;
+   if (_paging_is_enabled(sid))
+     {
+        if (sid->page_snap_horiz)
+          {
+             //we passed one page to the right
+             if (x > sid->current_page.x + sid->pagesize_h)
+               x = sid->current_page.x + sid->pagesize_h;
+             //we passed one page to the left
+             if (x < sid->current_page.x - sid->pagesize_h)
+               x = sid->current_page.x - sid->pagesize_h;
+          }
+        if (sid->page_snap_vert)
+          {
+             //we passed one page to the bottom
+             if (y > sid->current_page.y + sid->pagesize_v)
+               y = sid->current_page.y + sid->pagesize_v;
+             //we passed one page to the top
+             if (y < sid->current_page.y - sid->pagesize_v)
+               y = sid->current_page.y - sid->pagesize_v;
+          }
      }

    if (!_elm_config->thumbscroll_bounce_enable)


loaders: Use png_set_packswap() (to reduce size of code).

--- libs/loaders/GP_PNG.c
+++ libs/loaders/GP_PNG.c
@@ -200,7 +200,7 @@
 	}

 	if (color_type == PNG_COLOR_TYPE_GRAY)
-		res->bit_endian = 1;
+		png_set_packswap(png);

 	uint32_t y;

@@ -305,47 +305,22 @@
 	return 0;
 }

-static int write_png_data_g_swap(const GP_Context *src, png_structp png,
-                                 GP_ProgressCallback *callback)
-{
-	unsigned int y;
-	uint8_t row[src->bytes_per_row];
-
-	for (y = 0; y < src->h; y++) {
-		memcpy(row, GP_PIXEL_ADDR(src, 0, y), src->bytes_per_row);
-
+static int write_png_data(const GP_Context *src, png_structp png,
+                          GP_ProgressCallback *callback, int bit_endian_flag)
+{
+	/* Look if we need to swap data when writing */
+	if (bit_endian_flag) {
 		switch (src->pixel_type) {
 		case GP_PIXEL_G1:
-			GP_BitSwapRow_B1(row, src->bytes_per_row);
-		break;
 		case GP_PIXEL_G2:
-			GP_BitSwapRow_B4(row, src->bytes_per_row);
-		break;
 		case GP_PIXEL_G4:
-			GP_BitSwapRow_B4(row, src->bytes_per_row);
+			png_set_packswap(png);
 		break;
 		default:
 			return ENOSYS;
 		break;
 		}
-
-		png_write_row(png, row);
-
-		if (GP_ProgressCallbackReport(callback, y, src->h, src->w)) {
-			GP_DEBUG(1, "Operation aborted");
-			return ECANCELED;
-		}
-	}
-
-	return 0;
-}
-
-static int write_png_data(const GP_Context *src, png_structp png,
-                          GP_ProgressCallback *callback, int bit_endian_flag)
-{
-	/* Look if we need to swap data when writing */
-	if (bit_endian_flag)
-		return write_png_data_g_swap(src, png, callback);
+	}

 	unsigned int y;


net: Check object before increasing refcount

Check if object is non-NULL before increasing its reference count.

Fixes e823b8fe63846a9c60ebd59a8bf07e9c602a8528.

--- libs/net/grl-net-wc.c
+++ libs/net/grl-net-wc.c
@@ -773,7 +773,7 @@
   c->url = g_strdup (url);
   c->headers = headers? g_hash_table_ref (headers): NULL;
   c->result = result;
-  c->cancellable = g_object_ref (cancellable);
+  c->cancellable = cancellable ? g_object_ref (cancellable) : NULL;

   g_get_current_time (&now);


Bug 951460: Fix compiler warnings in sftk_compute_ANSI_X9_63_kdf and sftk_ANSI_X9_63_kdf. r=kaie.

--- lib/softoken/pkcs11c.c
+++ lib/softoken/pkcs11c.c
@@ -5657,6 +5657,7 @@
     return 0;
 }

+#ifdef NSS_ENABLE_ECC
 /* Inputs:
  *  key_len: Length of derived key to be generated.
  *  SharedSecret: a shared secret that is the output of a key agreement primitive.
@@ -5675,12 +5676,13 @@
     unsigned char *buffer = NULL, *output_buffer = NULL;
     PRUint32 buffer_len, max_counter, i;
     SECStatus rv;
+    CK_RV crv;

     /* Check that key_len isn't too long.  The maximum key length could be
      * greatly increased if the code below did not limit the 4-byte counter
      * to a maximum value of 255. */
     if (key_len > 254 * HashLen)
-	return SEC_ERROR_INVALID_ARGS;
+	return CKR_ARGUMENTS_BAD;

     if (SharedInfo == NULL)
 	SharedInfoLen = 0;
@@ -5688,7 +5690,7 @@
     buffer_len = SharedSecret->len + 4 + SharedInfoLen;
     buffer = (CK_BYTE *)PORT_Alloc(buffer_len);
     if (buffer == NULL) {
-	rv = SEC_ERROR_NO_MEMORY;
+	crv = CKR_HOST_MEMORY;
 	goto loser;
     }

@@ -5698,7 +5700,7 @@

     output_buffer = (CK_BYTE *)PORT_Alloc(max_counter * HashLen);
     if (output_buffer == NULL) {
-	rv = SEC_ERROR_NO_MEMORY;
+	crv = CKR_HOST_MEMORY;
 	goto loser;
     }

@@ -5715,8 +5717,11 @@

     for(i=0; i < max_counter; i++) {
 	rv = Hash(&output_buffer[i * HashLen], buffer, buffer_len);
-	if (rv != SECSuccess)
+	if (rv != SECSuccess) {
+	    /* 'Hash' should not fail. */
+	    crv = CKR_FUNCTION_FAILED;
 	    goto loser;
+	}

 	/* Increment counter (assumes max_counter < 255) */
 	buffer[SharedSecret->len + 3]++;
@@ -5728,7 +5733,7 @@
     }
     *key = output_buffer;

-    return SECSuccess;
+    return CKR_OK;

     loser:
 	if (buffer) {
@@ -5737,7 +5742,7 @@
 	if (output_buffer) {
 	    PORT_ZFree(output_buffer, max_counter * HashLen);
 	}
-	return rv;
+	return crv;
 }

 static CK_RV sftk_ANSI_X9_63_kdf(CK_BYTE **key, CK_ULONG key_len,
@@ -5761,8 +5766,9 @@
 	return sftk_compute_ANSI_X9_63_kdf(key, key_len, SharedSecret, SharedInfo,
 		   		 SharedInfoLen, SHA512_HashBuf, SHA512_LENGTH);
     else
-	return SEC_ERROR_INVALID_ALGORITHM;
-}
+	return CKR_MECHANISM_INVALID;
+}
+#endif

 /*
  * SSL Key generation given pre master secret
@@ -6814,12 +6820,11 @@
 	    secretlen = tmp.len;
 	} else {
 	    secretlen = keySize;
-	    rv = sftk_ANSI_X9_63_kdf(&secret, keySize,
+	    crv = sftk_ANSI_X9_63_kdf(&secret, keySize,
 			&tmp, mechParams->pSharedData,
 			mechParams->ulSharedDataLen, mechParams->kdf);
 	    PORT_ZFree(tmp.data, tmp.len);
-	    if (rv != SECSuccess) {
-		crv = CKR_HOST_MEMORY;
+	    if (crv != CKR_OK) {
 		break;
 	    }
 	    tmp.data = secret;


add decrypt code

add decrypt code

error: pathspec 'security/aesctr-sample.c' did not match any file(s) known to git

--- security/aesctr-sample.c
+++ security/aesctr-sample.c
@@ -0,0 +1,173 @@
+/*
+
+OpenSSL decrypt sample code
+
+can rough use AES-CTR encrypt/decrypt
+
+compile with gcc with -lcrypto
+
+Liuqing Yang<yllqq#outlook.com>
+
+*/
+
+#include <openssl/aes.h>
+#include <openssl/rand.h>
+#include <openssl/hmac.h>
+#include <openssl/buffer.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+
+// Code example uses partail code from: http://stackoverflow.com/questions/3141860/aes-ctr-256-encryption-mode-of-operation-on-openssl
+// Mostly in the ctr_ state, and init_ctr functions.
+
+struct ctr_state
+{
+	unsigned char ivec[AES_BLOCK_SIZE];
+	unsigned int num;
+	unsigned char ecount[AES_BLOCK_SIZE];
+};
+
+FILE *readFile;
+FILE *writeFile;
+AES_KEY key;
+
+int bytes_read, bytes_written;
+unsigned char indata[AES_BLOCK_SIZE];
+unsigned char outdata[AES_BLOCK_SIZE];
+unsigned char KEY[AES_BLOCK_SIZE];
+unsigned char iv[AES_BLOCK_SIZE];
+struct ctr_state state;
+
+int init_ctr(struct ctr_state *state, const unsigned char iv[16])
+{
+	/* aes_ctr128_encrypt requires 'num' and 'ecount' set to zero on the
+     * first call. */
+    state->num = 0;
+    memset(state->ecount, 0, AES_BLOCK_SIZE);
+
+    /* Initialise counter in 'ivec' to 0 */
+    memset(state->ivec + 8, 0, 8);
+
+    /* Copy IV into 'ivec' */
+    memcpy(state->ivec, iv, 8);
+
+	return 0;
+}
+
+void fencrypt(char* read, char* write, const unsigned char* enc_key)
+{
+    if(!memset(iv, 0, AES_BLOCK_SIZE))
+    {
+        fprintf(stderr, "Could not create zero iv.");
+        exit(1);
+    }
+
+	readFile = fopen(read,"rb"); // The b is required in windows.
+	writeFile = fopen(write,"wb");
+
+	if(readFile==NULL)
+	{
+		fprintf(stderr, "Read file is null.");
+		exit(1);
+	}
+
+	if(writeFile==NULL)
+	{
+		fprintf(stderr, "Write file is null.");
+		exit(1);
+	}
+
+	fwrite(iv, 1, 8, writeFile); // IV bytes 1 - 8
+    fwrite("\0\0\0\0\0\0\0\0", 1, 8, writeFile); // Fill the last 4 with null bytes 9 - 16
+
+	//Initializing the encryption KEY
+	if (AES_set_encrypt_key(enc_key, 128, &key) < 0)
+    {
+        fprintf(stderr, "Could not set encryption key.");
+        exit(1);
+    }
+
+	init_ctr(&state, iv); //Counter call
+	//Encrypting Blocks of 16 bytes and writing the output.txt with ciphertext
+	while(1)
+	{
+		bytes_read = fread(indata, 1, AES_BLOCK_SIZE, readFile);
+		AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);
+
+		bytes_written = fwrite(outdata, 1, bytes_read, writeFile);
+		if (bytes_read < AES_BLOCK_SIZE)
+		{
+			break;
+		}
+	}
+
+	fclose(writeFile);
+	fclose(readFile);
+}
+
+void fdecrypt(const char* read, const char* write)
+{
+	int ret;
+
+	readFile=fopen(read,"rb"); // The b is required in windows.
+	writeFile=fopen(write,"wb");
+
+	if(readFile==NULL)
+	{
+		fprintf(stderr,"Read file is null.");
+        exit(1);
+	}
+
+	if(writeFile==NULL)
+	{
+		fprintf(stderr, "Write file is null.");
+        exit(1);
+	}
+
+	ret = fread(KEY, 1, AES_BLOCK_SIZE, readFile);
+	if (ret != AES_BLOCK_SIZE)
+	{
+		fprintf(stderr, "Read KEY error.");
+	}
+
+    ret = fread(iv, 1, AES_BLOCK_SIZE, readFile);
+	if (ret != AES_BLOCK_SIZE)
+	{
+		fprintf(stderr, "Read IV error.");
+	}
+
+	//Initializing the encryption KEY
+    if (AES_set_encrypt_key(KEY, 128, &key) < 0)
+    {
+        fprintf(stderr, "Could not set decryption key.");
+        exit(1);
+    }
+
+	init_ctr(&state, iv);//Counter call
+	//Encrypting Blocks of 16 bytes and writing the output.txt with ciphertext
+	while(1)
+	{
+		bytes_read = fread(indata, 1, AES_BLOCK_SIZE, readFile);
+        //printf("%i\n", state.num);
+		AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);
+
+		bytes_written = fwrite(outdata, 1, bytes_read, writeFile);
+		if (bytes_read < AES_BLOCK_SIZE)
+		{
+			break;
+		}
+	}
+	fclose(writeFile);
+	fclose(readFile);
+}
+
+int main(int argc, char *argv[])
+{
+	//char key[]	= {0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,	0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04};
+    //fencrypt("encme.txt", "enced.enc", (const unsigned char*)key);
+	fdecrypt("enced.enc", "unenced.txt");
+    //getc(stdin);
+	return 0;
+}


os: allow os_time_advance() when OS not started.

This is useful in unit tests when we need to make time pass (e.g., to
test timeouts).

--- libs/os/src/os_time.c
+++ libs/os/src/os_time.c
@@ -97,10 +97,14 @@
     assert(ticks >= 0);

     if (ticks > 0) {
-        os_time_tick(ticks);
-        os_callout_tick();
-        os_sched_os_timer_exp();
-        os_sched(NULL);
+        if (!os_started()) {
+            g_os_time += ticks;
+        } else {
+            os_time_tick(ticks);
+            os_callout_tick();
+            os_sched_os_timer_exp();
+            os_sched(NULL);
+        }
     }
 }


SELinux: remove redundant pointer checks before calling kfree()

We don't need to check for NULL pointers before calling kfree().

Signed-off-by: Paul Moore <0fd1bf839ec6540c47f8fc82b7605eea08b33a06@hp.com>
Acked-by:  Stephen Smalley <d6e1285e1c84d3d5885c2124fdacc780e9fc0a94@tycho.nsa.gov>
Signed-off-by: James Morris <10d11de3abc355eabe955bb734f0f8e71da56e16@namei.org>

--- security/selinux/hooks.c
+++ security/selinux/hooks.c
@@ -4658,8 +4658,7 @@

 static void selinux_release_secctx(char *secdata, u32 seclen)
 {
-	if (secdata)
-		kfree(secdata);
+	kfree(secdata);
 }

 #ifdef CONFIG_KEYS


fix SkinBuilder's about toolbar item bug

--- libskin/skinbuilder.c
+++ libskin/skinbuilder.c
@@ -550,7 +550,7 @@

 		x = pl->toolbar.x1 + i * width;
 		tb = skin_toggle_button_new(root, pixbuf, x, pl->toolbar.y1);
-		add_object(builder, G_OBJECT(close), tb_items[i]);
+		add_object(builder, G_OBJECT(tb), tb_items[i]);
 	}

 	GnomeCanvasItem *playlistbox = gnome_canvas_item_new(root,


Styles.c: reindent

Styles.c: reindent

--- src/Styles.c
+++ src/Styles.c
@@ -1822,18 +1822,18 @@
 "y n yes no on off true false", "", "", "", "", "", "", "", "" };

 EDITLEXER lexYAML = { SCLEX_YAML, 63358, L"YAML", L"yaml; yml", L"", &KeyWords_YAML, {
-                          { STYLE_DEFAULT, 63126, L"Default", L"", L"" },
-                          //{ SCE_YAML_DEFAULT, L"Default", L"", L"" },
-                          { SCE_YAML_COMMENT, 63127, L"Comment", L"fore:#008800", L"" },
-                          { SCE_YAML_IDENTIFIER, 63129, L"Identifier", L"bold; fore:#0A246A", L"" },
-                          { SCE_YAML_KEYWORD, 63128, L"Keyword", L"fore:#880088", L"" },
-                          { SCE_YAML_NUMBER, 63130, L"Number", L"fore:#FF8000", L"" },
-                          { SCE_YAML_REFERENCE, 63359, L"Reference", L"fore:#008888", L"" },
-                          { SCE_YAML_DOCUMENT, 63360, L"Document", L"fore:#FFFFFF; bold; back:#000088; eolfilled", L"" },
-                          { SCE_YAML_TEXT, 63361, L"Text", L"fore:#404040", L"" },
-                          { SCE_YAML_ERROR, 63362, L"Error", L"fore:#FFFFFF; bold; italic; back:#FF0000; eolfilled", L"" },
-                          { SCE_YAML_OPERATOR, 63132, L"Operator", L"fore:#333366", L"" },
-                          { -1, 00000, L"", L"", L"" } } };
+                      { STYLE_DEFAULT, 63126, L"Default", L"", L"" },
+                      //{ SCE_YAML_DEFAULT, L"Default", L"", L"" },
+                      { SCE_YAML_COMMENT, 63127, L"Comment", L"fore:#008800", L"" },
+                      { SCE_YAML_IDENTIFIER, 63129, L"Identifier", L"bold; fore:#0A246A", L"" },
+                      { SCE_YAML_KEYWORD, 63128, L"Keyword", L"fore:#880088", L"" },
+                      { SCE_YAML_NUMBER, 63130, L"Number", L"fore:#FF8000", L"" },
+                      { SCE_YAML_REFERENCE, 63359, L"Reference", L"fore:#008888", L"" },
+                      { SCE_YAML_DOCUMENT, 63360, L"Document", L"fore:#FFFFFF; bold; back:#000088; eolfilled", L"" },
+                      { SCE_YAML_TEXT, 63361, L"Text", L"fore:#404040", L"" },
+                      { SCE_YAML_ERROR, 63362, L"Error", L"fore:#FFFFFF; bold; italic; back:#FF0000; eolfilled", L"" },
+                      { SCE_YAML_OPERATOR, 63132, L"Operator", L"fore:#333366", L"" },
+                      { -1, 00000, L"", L"", L"" } } };

 // This array holds all the lexers...
 // Don't forget to change the number of the lexer for HTML and XML


SELinux: Institute file_path_has_perm()

SELinux: Institute file_path_has_perm()

Create a file_path_has_perm() function that is like path_has_perm() but
instead takes a file struct that is the source of both the path and the
inode (rather than getting the inode from the dentry in the path).  This
is then used where appropriate.

This will be useful for situations like unionmount where it will be
possible to have an apparently-negative dentry (eg. a fallthrough) that is
open with the file struct pointing to an inode on the lower fs.

Signed-off-by: David Howells <ebac1d06c1688626821bb0e574a037a7a5354e49@redhat.com>
Signed-off-by: Al Viro <de609eb4d5d70b1d38ec6642adbfc33a2781f63c@zeniv.linux.org.uk>


SoupSocket: Use the local socket, when available, even on client side.

This allows binding the client connection to a specific local address.

--- libsoup/soup-socket.c
+++ libsoup/soup-socket.c
@@ -711,6 +711,9 @@
 		g_socket_client_set_enable_proxy (client, FALSE);
 	if (priv->timeout)
 		g_socket_client_set_timeout (client, priv->timeout);
+
+	if (priv->local_addr)
+		g_socket_client_set_local_address (client, soup_address_get_gsockaddr (priv->local_addr));

 	return client;
 }


Yama: handle 32-bit userspace prctl

Yama: handle 32-bit userspace prctl

When running a 64-bit kernel and receiving prctls from a 32-bit
userspace, the "-1" used as an unsigned long will end up being
misdetected. The kernel is looking for 0xffffffffffffffff instead of
0xffffffff. Since prctl lacks a distinct compat interface, Yama needs
to handle this translation itself. As such, support either value as
meaning PR_SET_PTRACER_ANY, to avoid breaking the ABI for 64-bit.

Signed-off-by: Kees Cook <50cb10d2be062154b17ab4d66a4eab34f1cf1c84@chromium.org>
Acked-by: John Johansen <28c604219333b0b085913923f8c4c96032f02c12@canonical.com>
Cc: 4fbacc2fa0ffdbb11bf1ad6925b886ebd08dd15f@vger.kernel.org
Signed-off-by: James Morris <bb9ce606a3116cc7a99739bd8e2dd57a2d5b69c1@oracle.com>


Removed FIFO config from AD5064 since it wasn't used anyway

--- src/ad5064.c
+++ src/ad5064.c
@@ -30,13 +30,13 @@
 ** ad5064.c
 **
 ** This unit implements an interface to an Analogue Devices AD5064 D/A
-** converter. The code below should be easy to modify to work with the
+** converter. The code below should be easy to modify to work with the
 ** AD5044 and AD5024 as well.
 **
 ** Usage assumptions/notes:
 **   1) There is a 3 usec delay required between transmits; the transmit
-**      function simply blocks until enough time has passed.
-**   2) Assumes there is enough space in the FIFO to send the required
+**      function simply blocks until enough time has passed.
+**   2) Assumes there is enough space in the FIFO to send the required
 **      messages; the 3 usec delay should mean this assumption is always
 **      satisified.
 **   3) A free running timer is preconfigured.
@@ -134,7 +134,7 @@

     /* Perform the necessary configuration for master mode */
     /* MCSPI_DATA_LINE_COMM_MODE_6 = D0 enabled for output, D1 disabled for output, receive on D1 */
-    McSPIMasterModeConfig(SOC_SPI_0_REGS, MCSPI_MULTI_CH,
+    McSPIMasterModeConfig(SOC_SPI_0_REGS, MCSPI_MULTI_CH,
                           MCSPI_TX_ONLY_MODE, MCSPI_DATA_LINE_COMM_MODE_6,
                           AD5064_SPI_CHANNEL);

@@ -143,7 +143,7 @@

     /* Configure the McSPI bus clock depending on clock mode */
     /* MCSPI_CLK_MODE_2: AD5064 reads data on the falling clock edge */
-    McSPIClkConfig(SOC_SPI_0_REGS, MCSPI_IN_CLK, MCSPI_OUT_FREQ, AD5064_SPI_CHANNEL,
+    McSPIClkConfig(SOC_SPI_0_REGS, MCSPI_IN_CLK, MCSPI_OUT_FREQ, AD5064_SPI_CHANNEL,
                    MCSPI_CLK_MODE_2);

     /* Configure the word length */
@@ -155,33 +155,26 @@
     /* Disable the receiver FIFO of McSPI peripheral */
     McSPIRxFIFOConfig(SOC_SPI_0_REGS, MCSPI_RX_FIFO_DISABLE, AD5064_SPI_CHANNEL);

-    /* Enable the transmitter FIFO of McSPI peripheral */
-    McSPITxFIFOConfig(SOC_SPI_0_REGS, MCSPI_TX_FIFO_ENABLE, AD5064_SPI_CHANNEL);
-
-    /* Set the interrupt levels for the FIFO (zero isn't a valid input! 32 bit words = 4 bytes) */
-    /* The total FIFO size is 64 bytes, either entirely for TX/RX or split 50:50 */
-    /* Interrupt level must be a multiple of the (rounded up) word size */
-    /* Almost empty and almost full values determine the number of bytes that can be *put* into */
-    /* the transmit buffer and *read* from the receive buffer respectively */
-    McSPIFIFOTrigLvlSet(SOC_SPI_0_REGS, 64, 64, MCSPI_TX_ONLY_MODE);
+    /* Disable the transmitter FIFO of McSPI peripheral */
+    McSPITxFIFOConfig(SOC_SPI_0_REGS, MCSPI_TX_FIFO_DISABLE, AD5064_SPI_CHANNEL);

     /* Disable any send delays */
     McSPIInitDelayConfig(SOC_SPI_0_REGS, MCSPI_INITDLY_0);
-
+
     /* Set the timing of the CS assertion to be minimal but allowable at 48 MHz */
     McSPICSTimeControlSet(SOC_SPI_0_REGS, MCSPI_CS_TCS_1PNT5_CLK, AD5064_SPI_CHANNEL);

     /* Enable the McSPI channel for communication - CS is automatically asserted in multi channel mode */
     McSPIChannelEnable(SOC_SPI_0_REGS, AD5064_SPI_CHANNEL);

-
+
     /* ******************************************************************* */
     /* GPIOs: Set up GPIOs */

     /* Pin muxes for necessary pins */
     GPIOPinMuxSetup(LDAC_PIN_MUX,   PAD_FS_RXD_NA_PUPDD(7));
     GPIOPinMuxSetup(CLR_PIN_MUX,    PAD_FS_RXD_NA_PUPDD(7));
-
+
     /* Pin directions */
     GPIODirModeSet(LDAC_REGS,   LDAC_PIN,   GPIO_DIR_OUTPUT);
     GPIODirModeSet(CLR_REGS,    CLR_PIN,    GPIO_DIR_OUTPUT);
@@ -222,12 +215,8 @@
 void ad5064Transmit(unsigned int value)
 {
     static unsigned int last_transmit = 0;
-    /* Use 4 usec delay as 3 usec isn't always enough */
+    /* Use 4 usec delay as 3 usec isn't always enough */
     while ((TIME - last_transmit) < (4*TIMER_1US));
-    /*
-      It assumes that there is space in the FIFO! Probably not something
-      to worry about...
-    */
     McSPITransmitData(SOC_SPI_0_REGS, value, AD5064_SPI_CHANNEL);
     last_transmit = TIME;
 }


Fix compilation of demos project on 32-bit

--- util/test/demos/vk/vk_headers.h
+++ util/test/demos/vk/vk_headers.h
@@ -30,6 +30,29 @@

 #define VK_NO_PROTOTYPES

+#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || \
+    defined(_M_X64) || defined(__ia64) || defined(_M_IA64) || defined(__aarch64__) ||       \
+    defined(__powerpc64__)
+
+#else
+
+// make handles typed even on 32-bit, by relying on C++
+#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(obj)                                 \
+  struct obj                                                                   \
+  {                                                                            \
+    obj() : handle(0) {}                                                       \
+    obj(uint64_t x) : handle(x) {}                                             \
+    bool operator==(const obj &other) const { return handle == other.handle; } \
+    bool operator<(const obj &other) const { return handle < other.handle; }   \
+    bool operator!=(const obj &other) const { return handle != other.handle; } \
+    bool operator==(const int &other) const { return handle == other; }        \
+    bool operator!=(const int &other) const { return handle != other; }        \
+    operator bool() const { return handle != 0; }                              \
+    uint64_t handle;                                                           \
+  };
+
+#endif
+
 // first include our local vulkan to ensure it's used over any system header
 #include "official/vulkan/vulkan.h"


Editor window: update menu dimming rules after
every change in the message, so shortcuts can
work properly
Fixes NB#78844

pmo-trunk-r4035

--- src/maemo/modest-msg-edit-window.c
+++ src/maemo/modest-msg-edit-window.c
@@ -1062,6 +1062,7 @@
 	modest_msg_edit_window_reset_modified (self);

 	modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (self));
+	modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
 	text_buffer_can_undo (priv->text_buffer, FALSE, self);
 	text_buffer_can_redo (priv->text_buffer, FALSE, self);

@@ -1359,7 +1360,8 @@

 	text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (obj));

-        modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (obj));
+	modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (obj));
+	modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (obj));
 	modest_window_check_dimming_rules_group (MODEST_WINDOW (obj), MODEST_DIMMING_RULES_CLIPBOARD);
 	priv->update_caption_visibility = TRUE;

@@ -2653,6 +2655,7 @@
 	wp_text_buffer_undo (WP_TEXT_BUFFER (priv->text_buffer));

 	modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
+	modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));

 }

@@ -2667,6 +2670,7 @@
 	wp_text_buffer_redo (WP_TEXT_BUFFER (priv->text_buffer));

 	modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
+	modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));

 }

@@ -2763,6 +2767,7 @@
 {

 	modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (userdata));
+	modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (userdata));
 	modest_window_check_dimming_rules_group (MODEST_WINDOW (userdata), MODEST_DIMMING_RULES_CLIPBOARD);
 	return FALSE;
 }
@@ -2772,12 +2777,14 @@
 		  ModestMsgEditWindow *editor)
 {
 	modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (editor));
+	modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (editor));
 }

 static void
 body_changed (GtkTextBuffer *buffer, ModestMsgEditWindow *editor)
 {
 	modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (editor));
+	modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (editor));
 }

 void
@@ -2928,6 +2935,7 @@
 	update_window_title (window);
 	gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
 	modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
+	modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
 }

 static void


default-constructor added

default-constructor added

--- src/atomic.h
+++ src/atomic.h
@@ -27,6 +27,10 @@

 template <typename T> class Atomic {
     public:
+        Atomic() {
+            pthread_mutex_init(&this->m, NULL);
+        }
+
         Atomic(const T& s) {
             pthread_mutex_init(&this->m, NULL);
             this->v = s;


mutexe added

mutexe added

--- src/atomic.h
+++ src/atomic.h
@@ -54,12 +54,16 @@
             }

             Atomic<T>& operator++() {
+                pthread_mutex_lock(&this->m);
                 ++this->v;
+                pthread_mutex_unlock(&this->m);
                 return *this;
             }

             Atomic<T>& operator--() {
+                pthread_mutex_lock(&this->m);
                 --this->v;
+                pthread_mutex_unlock(&this->m);
                 return *this;
             }


Changed private key versions for BCExchange

--- src/base58.h
+++ src/base58.h
@@ -599,12 +599,10 @@
 public:
     enum
     {
-        NUSHARES_SECRET = 149,      // PXXXXXXXX... for compressed keys
-        NUSHARES_SECRET_TEST = 223, // aXXXXXXXX... for compressed keys
-        NUBITS_SECRET = 150,        // PXXXXXXXX... for compressed keys
-        NUBITS_SECRET_TEST = 224,   // aXXXXXXXX... for compressed keys
-        DEFAULT_SECRET = 191,       // 128 + CBitcoinAddress::PUBKEY_ADDRESS
-        DEFAULT_SECRET_TEST = 160,  // 128 + CBitcoinAddress::PUBKEY_ADDRESS_TEST
+        BLOCKSHARES_SECRET = 153,      // PXXXXXXXX... for compressed keys
+        BLOCKSHARES_SECRET_TEST = 227, // aXXXXXXXX... for compressed keys
+        BLOCKCREDITS_SECRET = 154,        // PXXXXXXXX... for compressed keys
+        BLOCKCREDITS_SECRET_TEST = 228,   // aXXXXXXXX... for compressed keys
     };

     void SetSecret(const CSecret& vchSecret, bool fCompressed, unsigned char cUnit)
@@ -630,19 +628,16 @@
         {
             case '8':
                 if (fTest)
-                    return NUSHARES_SECRET_TEST;
+                    return BLOCKSHARES_SECRET_TEST;
                 else
-                    return NUSHARES_SECRET;
+                    return BLOCKSHARES_SECRET;
             case 'C':
                 if (fTest)
-                    return NUBITS_SECRET_TEST;
+                    return BLOCKCREDITS_SECRET_TEST;
                 else
-                    return NUBITS_SECRET;
+                    return BLOCKCREDITS_SECRET;
             default:
-                if (fTest)
-                    return DEFAULT_SECRET_TEST;
-                else
-                    return DEFAULT_SECRET;
+                throw std::runtime_error("Unknown unit");
         }
     }

@@ -652,36 +647,29 @@
         unsigned char cDetectedUnit = '?';
         switch(nVersion)
         {
-            case NUSHARES_SECRET:
+            case BLOCKSHARES_SECRET:
                 cDetectedUnit = '8';
                 break;
-            case NUSHARES_SECRET_TEST:
+            case BLOCKSHARES_SECRET_TEST:
                 cDetectedUnit = '8';
                 fExpectTestNet = true;
                 break;

-            case NUBITS_SECRET:
+            case BLOCKCREDITS_SECRET:
                 cDetectedUnit = 'C';
                 break;
-            case NUBITS_SECRET_TEST:
+            case BLOCKCREDITS_SECRET_TEST:
                 cDetectedUnit = 'C';
                 fExpectTestNet = true;
                 break;

-            case DEFAULT_SECRET:
-                break;
-            case DEFAULT_SECRET_TEST:
-                fExpectTestNet = true;
-                break;
-
             default:
                 return false;
         }

         bool fCorrectNetwork = fExpectTestNet == fTestNet;
         bool fExpectedFormat = vchData.size() == 32 || (vchData.size() == 33 && vchData[32] == 1);
-        // The detected default version '?' is always valid, while the new versions must be explicitly set
-        bool fCorrectUnit = cDetectedUnit == '?' || cDetectedUnit == cUnit;
+        bool fCorrectUnit = cDetectedUnit == cUnit;

         return fCorrectNetwork && fExpectedFormat && fCorrectUnit;
     }


base64: use checked xmalloc()

base64: use checked xmalloc()

--- src/base64.c
+++ src/base64.c
@@ -32,6 +32,7 @@
 #include <string.h>

 #include "base64.h"
+#include "xmalloc.h"

 /* Encodes the given data with base64..
  *
@@ -41,7 +42,7 @@
   static const char base64[] =
     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

-  char *str = (char *) malloc ((size + 3) * 4 / 3 + 1);
+  char *str = (char *) xmalloc ((size + 3) * 4 / 3 + 1);

   char *p = str;
   const unsigned char *q = (const unsigned char *) buf;


Fixed assert message.

Fixed assert message.

--- src/bgfx_p.h
+++ src/bgfx_p.h
@@ -2385,7 +2385,10 @@
 			}

 			uint32_t offset = (dib.m_startIndex + _startIndex)*indexSize;
-			uint32_t size   = bx::uint32_min(bx::uint32_satsub(dib.m_size, _startIndex*indexSize), _mem->size);
+			uint32_t size   = bx::uint32_min(offset
+				+ bx::uint32_min(bx::uint32_satsub(dib.m_size, _startIndex*indexSize), _mem->size)
+				, BGFX_CONFIG_DYNAMIC_INDEX_BUFFER_SIZE) - offset
+				;
 			BX_CHECK(_mem->size <= size, "Truncating dynamic index buffer update (size %d, mem size %d)."
 				, size
 				, _mem->size
@@ -2540,7 +2543,7 @@
 				, BGFX_CONFIG_DYNAMIC_VERTEX_BUFFER_SIZE) - offset
 				;
 			BX_CHECK(_mem->size <= size, "Truncating dynamic vertex buffer update (size %d, mem size %d)."
-				, dvb.m_size
+				, size
 				, _mem->size
 				);


fixed parsing of bibliography items with all capitals

git-svn-id: b62a74e6a85b74e782ead772f54cba8e909798b9@1152 6e728def-ac18-4b39-bad8-e7d984b3b6fa

--- src/biblio.c
+++ src/biblio.c
@@ -150,10 +150,12 @@
         (G_REGEX_CASELESS | G_REGEX_DOTALL), 0, NULL);

     subregex_ident = g_regex_new ("@.+{([^,]+),", 0, 0, NULL);
-    subregex_title = g_regex_new ("[^book]title[\\s]*=[\\s]*(.*)", 0, 0, NULL);
-    subregex_author = g_regex_new ("author[\\s]*=[\\s]*(.*)", 0, 0, NULL);
-    subregex_year = g_regex_new ("year[\\s]*=[\\s]*[{|\"]?([1|2][0-9]{3})", 0,
-            0, NULL);
+    subregex_title = g_regex_new
+		("[^book]title[\\s]*=[\\s]*(.*)", G_REGEX_CASELESS, 0, NULL);
+    subregex_author = g_regex_new
+		("author[\\s]*=[\\s]*(.*)", G_REGEX_CASELESS, 0, NULL);
+    subregex_year = g_regex_new
+		("year[\\s]*=[\\s]*[{|\"]?([1|2][0-9]{3})", G_REGEX_CASELESS, 0, NULL);
     regex_formatting = g_regex_new ("[{|}|\"|,|\\$]", 0, 0, NULL);


fixed bibtex regexes broken by rev 706 script

git-svn-id: b62a74e6a85b74e782ead772f54cba8e909798b9@723 6e728def-ac18-4b39-bad8-e7d984b3b6fa

--- src/biblio.c
+++ src/biblio.c
@@ -142,10 +142,10 @@
         "@proceedings|@techreport|@unpublished)([^@]*)",
         (G_REGEX_CASELESS | G_REGEX_DOTALL), 0, NULL);

-    subregex_ident = g_regex_new ("@.+{ ([^,]+),", 0, 0, NULL);
+    subregex_ident = g_regex_new ("@.+{([^,]+),", 0, 0, NULL);
     subregex_title = g_regex_new ("[^book]title[\\s]*=[\\s]*(.*)", 0, 0, NULL);
     subregex_author = g_regex_new ("author[\\s]*=[\\s]*(.*)", 0, 0, NULL);
-    subregex_year = g_regex_new ("year[\\s]*=[\\s]*[{|\"]? ([1|2][0-9]{3})", 0,
+    subregex_year = g_regex_new ("year[\\s]*=[\\s]*[{|\"]?([1|2][0-9]{3})", 0,
             0, NULL);
     regex_formatting = g_regex_new ("[{|}|\"|,|\\$]", 0, 0, NULL);


make header and impl consistent

make header and impl consistent

--- src/bigmpi.h
+++ src/bigmpi.h
@@ -105,16 +105,16 @@
 /* Supporting the v-collectives is obnoxious and a motivating use case is missing. */

 int MPIX_Gatherv_x(const void *sendbuf, MPI_Count sendcount, MPI_Datatype sendtype,
-                   void *recvbuf, const MPI_Count *recvcounts, const MPI_Aint *displs, MPI_Datatype recvtype,
+                   void *recvbuf, const MPI_Count recvcounts[], const MPI_Aint displs[], MPI_Datatype recvtype,
                    int root, MPI_Comm comm);
-int MPIX_Scatterv_x(const void *sendbuf, const MPI_Count *sendcounts, const MPI_Aint *displs, MPI_Datatype sendtype,
+int MPIX_Scatterv_x(const void *sendbuf, const MPI_Count sendcounts[], const MPI_Aint displs[], MPI_Datatype sendtype,
                     void *recvbuf, MPI_Count recvcount, MPI_Datatype recvtype,
                     int root, MPI_Comm comm);
 int MPIX_Allgatherv_x(const void *sendbuf, MPI_Count sendcount, MPI_Datatype sendtype,
-                      void *recvbuf, const MPI_Count *recvcounts, const MPI_Aint *displs, MPI_Datatype recvtype,
+                      void *recvbuf, const MPI_Count recvcounts[], const MPI_Aint displs[], MPI_Datatype recvtype,
                       MPI_Comm comm);
-int MPIX_Alltoallv_x(const void *sendbuf, const MPI_Count *sendcounts, const MPI_Aint *sdispls, MPI_Datatype sendtype,
-                     void *recvbuf, const MPI_Count *recvcounts, const MPI_Aint *rdispls, MPI_Datatype recvtype,
+int MPIX_Alltoallv_x(const void *sendbuf, const MPI_Count sendcounts[], const MPI_Aint sdispls[], MPI_Datatype sendtype,
+                     void *recvbuf, const MPI_Count recvcounts[], const MPI_Aint rdispls[], MPI_Datatype recvtype,
                      MPI_Comm comm);
 int MPIX_Alltoallw_x(const void *sendbuf, const MPI_Count sendcounts[], const MPI_Aint sdispls[], const MPI_Datatype sendtypes[],
                      void *recvbuf, const MPI_Count recvcounts[], const MPI_Aint rdispls[], const MPI_Datatype recvtypes[],


Fix typo

Fix typo

--- src/bt_fdw.c
+++ src/bt_fdw.c
@@ -231,7 +231,7 @@

 static TupleTableSlot *
 btExecForeignDelete(EState *estate,
-                    ReultRelInfo *rinfo,
+                    ResultRelInfo *rinfo,
                     TupleTableSlot *slot,
                     TupleTableSlot *planSlot) {


change tz time macro into multi-line

change tz time macro into multi-line

--- src/c/main.c
+++ src/c/main.c
@@ -302,9 +302,14 @@

     text_layer_set_text(tz03_time_layer, tz03_time_str);

-    utc_time = time(NULL); // TODO add to macro
     // TODO minute math, not just hours and seconds
-#define TZ_DO_TIME(TZ_MACRO)     utc_time += (60 * settings.TZ_MACRO ## _offset) + (60 * settings.local_offset_in_mins); utc_tm = gmtime(&utc_time); strftime(buffer, sizeof(buffer), time_format, utc_tm); snprintf(TZ_MACRO ## _time_str, sizeof(TZ_MACRO ## _time_str), "%s %s", buffer, settings.TZ_MACRO ## _name); text_layer_set_text(TZ_MACRO ## _time_layer, TZ_MACRO ## _time_str);
+#define TZ_DO_TIME(TZ_MACRO)\
+    utc_time = time(NULL);\
+    utc_time += (60 * settings.TZ_MACRO ## _offset) + (60 * settings.local_offset_in_mins);\
+    utc_tm = gmtime(&utc_time);\
+    strftime(buffer, sizeof(buffer), time_format, utc_tm);\
+    snprintf(TZ_MACRO ## _time_str, sizeof(TZ_MACRO ## _time_str), "%s %s", buffer, settings.TZ_MACRO ## _name);\
+    text_layer_set_text(TZ_MACRO ## _time_layer, TZ_MACRO ## _time_str);

 TZ_DO_TIME(tz04)
 TZ_DO_TIME(tz05)


Self-review.

Self-review.

--- src/c/main.c
+++ src/c/main.c
@@ -24,6 +24,7 @@
   blob_t result_blob;
   get_blob_data(result, &result_blob);
   blob_copy_to(&data_blob, &result_blob);
+  byte_buffer_dispose(&buffer);
   return result;
 }


Removed background, removed now step display

--- src/c/nixi.c
+++ src/c/nixi.c
@@ -16,7 +16,7 @@
 static GFont s_time_font;

 static Layer *background_layer;
-static Layer *steps_layer, *steps_now_layer;
+static Layer *steps_layer;
 static Layer *hour_layer, *minute_layer;

 static TextLayer *battery_text_layer, *location_text_layer;
@@ -55,7 +55,6 @@
 static void bluetooth_callback(bool connected);

 static void bluetooth_update_proc(Layer *layer, GContext *ctx);
-static void steps_now_proc_layer(Layer *layer, GContext *ctx);
 static void steps_proc_layer(Layer *layer, GContext *ctx);
 static void time_hour_update_proc(Layer *layer, GContext *ctx);
 static void time_minute_update_proc(Layer *layer, GContext *ctx);
@@ -205,9 +204,6 @@
   Layer *window_layer = window_get_root_layer(window);
   GRect bounds = layer_get_bounds(window_layer);

-  int hh = bounds.size.h>>1;
-  int hw = bounds.size.w>>1;
-
   // Create bluetooth meter Layer
   background_layer = layer_create(bounds);
   layer_set_update_proc(background_layer, bluetooth_update_proc);
@@ -227,11 +223,6 @@
   steps_layer = layer_create(bounds);
   layer_set_update_proc(steps_layer, steps_proc_layer);
   layer_add_child(window_layer, steps_layer);
-
-  // Create now steps meter Layer
-  steps_now_layer = layer_create(GRect(hw>>1, hh>>1, hw, hh));
-  layer_set_update_proc(steps_now_layer, steps_now_proc_layer);
-  layer_add_child(window_layer, steps_now_layer);

   s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_PIXELS_49));

@@ -305,7 +296,6 @@
   text_layer_destroy(steps_now_average_text_layer);
   text_layer_destroy(steps_average_text_layer);
   layer_destroy(steps_layer);
-  layer_destroy(steps_now_layer);

   text_layer_destroy(battery_text_layer);
   layer_destroy(background_layer);
@@ -366,30 +356,9 @@
  */
 static void bluetooth_update_proc(Layer *layer, GContext *ctx)
 {
-  int s, x, y, i, c;
-  GRect bounds = layer_get_bounds(layer);
-  graphics_context_set_fill_color(ctx, bluetooth_connected ? (dayTime ? GColorWhite : GColorBlack) : GColorRed);
-  graphics_fill_rect(ctx, bounds, 0, GCornerNone);
-  if (bluetooth_connected && dayTime) {
-    graphics_context_set_stroke_width(ctx, 5);
-    c = rand() % NUMBER_OF_COLOURS;
-    switch (c) {
-      case 0: graphics_context_set_stroke_color(ctx, GColorCadetBlue); break;
-      case 1: graphics_context_set_stroke_color(ctx, GColorBrass); break;
-      case 2: graphics_context_set_stroke_color(ctx, GColorChromeYellow); break;
-      case 3: graphics_context_set_stroke_color(ctx, GColorRoseVale); break;
-      case 4: graphics_context_set_stroke_color(ctx, GColorPurpureus); break;
-      case 5: graphics_context_set_stroke_color(ctx, GColorLiberty); break;
-      case 6:
-      default: graphics_context_set_stroke_color(ctx, GColorScreaminGreen); break;
-    }
-    for (i = 0; i < 5; i++) {
-      s = (rand() % 25) + 5;
-      x = (rand() % (bounds.size.w - (s>>1))) + s;
-      y = (rand() % (bounds.size.h - (s>>1))) + s;
-      graphics_draw_circle(ctx, GPoint(x, y), s);
-    }
-  }
+  if (bluetooth_connected && dayTime) return;
+  graphics_context_set_fill_color(ctx, bluetooth_connected ? GColorBlack : GColorRed);
+  graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
 }

 /**
@@ -458,30 +427,6 @@
   l = 1.0f * steps_average_now / steps_day_average;
   graphics_context_set_fill_color(ctx, GColorVividCerulean);
   graphics_fill_radial(ctx, bounds, GOvalScaleModeFitCircle, PIE_THICKNESS * 0.3, 0, l * DEG_TO_TRIGANGLE(360));
-}
-
-/**
- * When the steps layer is marked as dirty run this
- *
- * @param layer The layer to update
- * @param ctx   The context
- */
-static void steps_now_proc_layer(Layer *layer, GContext *ctx)
-{
-//   if (!dayTime) return;
-//   GRect bounds = layer_get_bounds(layer);
-
-//   float l = 1.0f * current_steps / steps_average_now;
-
-//   l = DEG_TO_TRIGANGLE((((l > 2) ? 1.0 : ((l < 0) ? -1.0 : l - 1.0))) * 180);
-
-//   graphics_context_set_fill_color(ctx, GColorLavenderIndigo);
-//   if (l < 0) {
-//     graphics_fill_radial(ctx, bounds, GOvalScaleModeFitCircle, PIE_THICKNESS, DEG_TO_TRIGANGLE(360) + l, DEG_TO_TRIGANGLE(360));
-//   } else {
-//     graphics_fill_radial(ctx, bounds, GOvalScaleModeFitCircle, PIE_THICKNESS, 0, l);
-//   }
-
 }

 /* Watch update for tick: */
@@ -548,7 +493,6 @@
   current_steps = (int)health_service_sum_today(HealthMetricStepCount);

   layer_mark_dirty(steps_layer);
-  layer_mark_dirty(steps_now_layer);
 }

 /* Helper functions */


fixed parameter generation in C output.

fixed parameter generation in C output.

--- src/carmlc.c
+++ src/carmlc.c
@@ -1,4 +1,4 @@
- #include <stdio.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
@@ -5232,10 +5232,24 @@
         case TPARAMLIST:
             printf("(");
             for(;idx < head->lenchildren; idx++) {
+                AST *dc_type = nil, *dc_name = nil;
                 if(head->children[idx]->tag == TIDENT) {
-                    printf("void *");
-                }
-                cwalk(head->children[idx], 0);
+                    dc_name = head->children[idx];
+                    printf("void *%s", dc_name->value);
+                } else {
+                    // now we've reached a TPARAMDEF
+                    // so just dump whatever is returned
+                    // by typespec2c
+                    dc_type = head->children[idx]->children[1];
+                    dc_name = head->children[idx]->children[0];
+                    tbuf = typespec2c(dc_type, buf, dc_name->value, 512);
+                    if(tbuf != nil) {
+                        printf("%s", tbuf);
+                    } else {
+                        printf("void *");
+                    }
+                }
+
                 if(idx < (head->lenchildren - 1)){
                     printf(", ");
                 }


Changes to polling the socket on read to get timeouts on cygwin also (hopefully).

--- src/client.c
+++ src/client.c
@@ -13,6 +13,8 @@

 #include <errno.h>
 #include <assert.h>
+
+#include <poll.h>

 #include "message.h"
 #include "command.h"
@@ -37,9 +39,9 @@
 static const char *msg_input = "Please input next command:";

 // declare internal functions
-void set_timeout(int *socket_fd, struct timeval *timeout);
+//void set_timeout(int *socket_fd, struct timeval *timeout);
 void send_message(int *socket_fd, unsigned char *packet, int packet_length, struct sockaddr_in *addr_remote, socklen_t *addr_len, char *server, int port);
-bool receive_message(bool *again, int *socket_fd, char *recvbuffer, struct sockaddr_in *addr_remote, socklen_t *addr_len);
+bool receive_message(int timeout, bool *again, struct pollfd *poll_fd, int *socket_fd, char *recvbuffer, struct sockaddr_in *addr_remote, socklen_t *addr_len);
 int makeargs(char *args, int *argc, char ***aa);

@@ -59,9 +61,10 @@
 	char **myargv; // the command inputted by user as argument vector
 	int myargc;    // argument count for the previous vector

-	struct timeval timeout;
-	timeout.tv_sec = 0;
-	timeout.tv_usec = 100;
+	struct pollfd poll_fd;
+	int poll_res;
+
+	int timeout = 100; // milliseconds

 	// seed random
 	srand(time(NULL));
@@ -111,12 +114,26 @@
 		return 6;
 	}

+	// setup poll
+	poll_fd.fd = socket_fd;
+	poll_fd.events = POLLIN;
+
 	// empty udp packet queue just in case
-	timeout.tv_sec = 0;
-	timeout.tv_usec = 50000;
-	set_timeout(&socket_fd, &timeout);
-	while(recvfrom(socket_fd, recvbuffer, RECV_BUFFER_SIZE, 0, (struct sockaddr *)&addr_remote, &addr_len) > 0);
-	//addr_remote.sin_port = htons(port);
+	timeout = 50;
+	while(true) {
+		poll_res = poll(&poll_fd, 1, timeout);
+		if(poll_res == -1) {
+			perror("ERROR: problem while polling socket.");
+		}
+		else if(poll_res == 0) {
+			// timeout
+			break;
+		}
+		else {
+			if(recvfrom(socket_fd, recvbuffer, RECV_BUFFER_SIZE, 0, (struct sockaddr *)&addr_remote, &addr_len) <= 0)
+				break;
+		}
+	}

 	//// Command loop

@@ -160,15 +177,10 @@
 		send_message(&socket_fd, packet, packet_length, &addr_remote, &addr_len, server, port);

 		// set timeout appropriately
-		if(request->service == 4) { // monitor
-			timeout.tv_sec = 0;
-			timeout.tv_usec = 50000; // 50 milliseconds
-		}
-		else {
-			timeout.tv_sec = 5;
-			timeout.tv_usec = 0;
-		}
-		set_timeout(&socket_fd, &timeout);
+		if(request->service == 4) // monitor
+			timeout = 50;
+		else
+			timeout = 5000;

 		struct timespec now;
 		int errcount = 0;
@@ -186,7 +198,7 @@
 				break;
 			}

-			if(!receive_message(&again, &socket_fd, recvbuffer, &addr_remote, &addr_len)) {
+			if(!receive_message(timeout, &again, &poll_fd, &socket_fd, recvbuffer, &addr_remote, &addr_len)) {
 				errcount++;
 				continue;
 			}
@@ -218,23 +230,6 @@
 	}

 	return 0;
-}
-
-void set_timeout(int *socket_fd, struct timeval *timeout) {
-	#ifdef _WIN32
-	// HOX: hope it doesn't overflow on our usage...
-	//int millis = (timeout->tv_sec * 1000) + (timeout->tv_usec / 1000);
-	uint64_t millis = (timeout->tv_sec * (uint64_t)1000) + (timeout->tv_usec / 1000);
-	if (setsockopt(*socket_fd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&millis, sizeof(millis)) < 0) {
-		perror("ERROR: setting socket options failed.");
-		exit(9);
-	}
-	#else
-	if (setsockopt(*socket_fd, SOL_SOCKET, SO_RCVTIMEO, timeout, sizeof(*timeout)) < 0) {
-		perror("ERROR: setting socket options failed.");
-		exit(9);
-	}
-	#endif
 }

 bool absolute_chaos() {
@@ -255,18 +250,29 @@
 	}
 }

-bool receive_message(bool *again, int *socket_fd, char *recvbuffer, struct sockaddr_in *addr_remote, socklen_t *addr_len) {
+bool receive_message(int timeout, bool *again, struct pollfd *poll_fd, int *socket_fd, char *recvbuffer, struct sockaddr_in *addr_remote, socklen_t *addr_len) {
 	// receive
 	if(!*again)
 		printf("Waiting for reply...\n");
 	*again = false;

+	int poll_res;
+
+	poll_res = poll(poll_fd, 1, timeout);
+	if(poll_res == -1) {
+		perror("ERROR: problem while polling socket.");
+		return false;
+	}
+	else if(poll_res == 0) {
+		// timeout
+		*again = true;
+		return true;
+	}
+
+	// else
+
 	int num_recv_bytes = recvfrom(*socket_fd, recvbuffer, RECV_BUFFER_SIZE, 0, (struct sockaddr *)addr_remote, addr_len);
 	if(num_recv_bytes <= -1) {
-		if(errno == EAGAIN) {
-			*again = true;
-			return true;
-		}
 		perror("ERROR: could not receive via recvfrom");
 		return false;
 	}


manage tuntap mac in client

manage tuntap mac in client

--- src/client.c
+++ src/client.c
@@ -329,6 +329,7 @@
 		vpn_ws_client_destroy(peer);
 		goto reconnect;
 	}
+	memcpy(peer->mac, vpn_ws_conf.tuntap_mac, 6);

 	struct pollfd pfd[2];
 	pfd[0].fd = peer->fd;


oopsie

oopsie

--- src/client.c
+++ src/client.c
@@ -319,7 +319,7 @@

         flags = 0;
         if (connection_closed)
-            flags |= HTTP_RESPONSE_PARSE_CONNECTION_CLOSED;
+            flags |= HTTP_RESPONSE_PARSE_EOF;

         ret = http_response_parse(c_buffer_data(rbuf), c_buffer_length(rbuf),
                                   flags, &response, &sz);


server: proxy: fix race condition when between client thread and server update thread

--- server/proxy/pf_update.c
+++ server/proxy/pf_update.c
@@ -71,6 +71,8 @@
 	rdpContext* ps = (rdpContext*)pdata->ps;
 	rdpGdi* gdi = context->gdi;

+	WLog_DBG(TAG, __FUNCTION__);
+
 	/* proxy end paint */
 	if (!ps->update->EndPaint(ps))
 		return FALSE;
@@ -220,8 +222,12 @@
 {
 	pClientContext* pc = (pClientContext*)context;
 	rdpContext* ps = (rdpContext*)pc->pdata->ps;
-	WLog_DBG(TAG, __FUNCTION__);
-	return ps->update->window->WindowCreate(ps, orderInfo, windowState);
+	BOOL rc;
+	WLog_DBG(TAG, __FUNCTION__);
+	EnterCriticalSection(&ps->update->mux);
+	rc = ps->update->window->WindowCreate(ps, orderInfo, windowState);
+	LeaveCriticalSection(&ps->update->mux);
+	return rc;
 }

 static BOOL pf_client_window_update(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
@@ -229,8 +235,12 @@
 {
 	pClientContext* pc = (pClientContext*)context;
 	rdpContext* ps = (rdpContext*)pc->pdata->ps;
-	WLog_DBG(TAG, __FUNCTION__);
-	return ps->update->window->WindowUpdate(ps, orderInfo, windowState);
+	BOOL rc;
+	WLog_DBG(TAG, __FUNCTION__);
+	EnterCriticalSection(&ps->update->mux);
+	rc = ps->update->window->WindowUpdate(ps, orderInfo, windowState);
+	LeaveCriticalSection(&ps->update->mux);
+	return rc;
 }

 static BOOL pf_client_window_icon(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
@@ -238,8 +248,12 @@
 {
 	pClientContext* pc = (pClientContext*)context;
 	rdpContext* ps = (rdpContext*)pc->pdata->ps;
-	WLog_DBG(TAG, __FUNCTION__);
-	return ps->update->window->WindowIcon(ps, orderInfo, windowIcon);
+	BOOL rc;
+	WLog_DBG(TAG, __FUNCTION__);
+	EnterCriticalSection(&ps->update->mux);
+	rc = ps->update->window->WindowIcon(ps, orderInfo, windowIcon);
+	LeaveCriticalSection(&ps->update->mux);
+	return rc;
 }

 static BOOL pf_client_window_cached_icon(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
@@ -247,16 +261,24 @@
 {
 	pClientContext* pc = (pClientContext*)context;
 	rdpContext* ps = (rdpContext*)pc->pdata->ps;
-	WLog_DBG(TAG, __FUNCTION__);
-	return ps->update->window->WindowCachedIcon(ps, orderInfo, windowCachedIcon);
+	BOOL rc;
+	WLog_DBG(TAG, __FUNCTION__);
+	EnterCriticalSection(&ps->update->mux);
+	rc = ps->update->window->WindowCachedIcon(ps, orderInfo, windowCachedIcon);
+	LeaveCriticalSection(&ps->update->mux);
+	return rc;
 }

 static BOOL pf_client_window_delete(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo)
 {
 	pClientContext* pc = (pClientContext*)context;
 	rdpContext* ps = (rdpContext*)pc->pdata->ps;
-	WLog_DBG(TAG, __FUNCTION__);
-	return ps->update->window->WindowDelete(ps, orderInfo);
+	BOOL rc;
+	WLog_DBG(TAG, __FUNCTION__);
+	EnterCriticalSection(&ps->update->mux);
+	rc = ps->update->window->WindowDelete(ps, orderInfo);
+	LeaveCriticalSection(&ps->update->mux);
+	return rc;
 }

 static BOOL pf_client_notify_icon_create(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
@@ -264,8 +286,12 @@
 {
 	pClientContext* pc = (pClientContext*)context;
 	rdpContext* ps = (rdpContext*)pc->pdata->ps;
-	WLog_DBG(TAG, __FUNCTION__);
-	return ps->update->window->NotifyIconCreate(ps, orderInfo, notifyIconState);
+	BOOL rc;
+	WLog_DBG(TAG, __FUNCTION__);
+	EnterCriticalSection(&ps->update->mux);
+	rc = ps->update->window->NotifyIconCreate(ps, orderInfo, notifyIconState);
+	LeaveCriticalSection(&ps->update->mux);
+	return rc;
 }

 static BOOL pf_client_notify_icon_update(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
@@ -273,16 +299,24 @@
 {
 	pClientContext* pc = (pClientContext*)context;
 	rdpContext* ps = (rdpContext*)pc->pdata->ps;
-	WLog_DBG(TAG, __FUNCTION__);
-	return ps->update->window->NotifyIconUpdate(ps, orderInfo, notifyIconState);
+	BOOL rc;
+	WLog_DBG(TAG, __FUNCTION__);
+	EnterCriticalSection(&ps->update->mux);
+	rc = ps->update->window->NotifyIconUpdate(ps, orderInfo, notifyIconState);
+	LeaveCriticalSection(&ps->update->mux);
+	return rc;
 }

 static BOOL pf_client_notify_icon_delete(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo)
 {
 	pClientContext* pc = (pClientContext*)context;
 	rdpContext* ps = (rdpContext*)pc->pdata->ps;
-	WLog_DBG(TAG, __FUNCTION__);
-	return ps->update->window->NotifyIconDelete(ps, orderInfo);
+	BOOL rc;
+	WLog_DBG(TAG, __FUNCTION__);
+	EnterCriticalSection(&ps->update->mux);
+	rc = ps->update->window->NotifyIconDelete(ps, orderInfo);
+	LeaveCriticalSection(&ps->update->mux);
+	return rc;
 }

 static BOOL pf_client_monitored_desktop(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
@@ -290,16 +324,24 @@
 {
 	pClientContext* pc = (pClientContext*)context;
 	rdpContext* ps = (rdpContext*)pc->pdata->ps;
-	WLog_DBG(TAG, __FUNCTION__);
-	return ps->update->window->MonitoredDesktop(ps, orderInfo, monitoredDesktop);
+	BOOL rc;
+	WLog_DBG(TAG, __FUNCTION__);
+	EnterCriticalSection(&ps->update->mux);
+	rc = ps->update->window->MonitoredDesktop(ps, orderInfo, monitoredDesktop);
+	LeaveCriticalSection(&ps->update->mux);
+	return rc;
 }

 static BOOL pf_client_non_monitored_desktop(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo)
 {
 	pClientContext* pc = (pClientContext*)context;
 	rdpContext* ps = (rdpContext*)pc->pdata->ps;
-	WLog_DBG(TAG, __FUNCTION__);
-	return ps->update->window->NonMonitoredDesktop(ps, orderInfo);
+	BOOL rc;
+	WLog_DBG(TAG, __FUNCTION__);
+	EnterCriticalSection(&ps->update->mux);
+	rc = ps->update->window->NonMonitoredDesktop(ps, orderInfo);
+	LeaveCriticalSection(&ps->update->mux);
+	return rc;
 }

 void pf_server_register_update_callbacks(rdpUpdate* update)


Fix compiler warning in commit.c

Fix compiler warning in commit.c

--- src/commit.c
+++ src/commit.c
@@ -173,7 +173,7 @@
 		buffer++;

 	if (parse_flags & COMMIT_FULL_PARSE && buffer < buffer_end) {
-		char *line_end;
+		const char *line_end;
 		size_t message_len = buffer_end - buffer;

 		/* Long message */


common BUGFIX copying enabled oper data

common BUGFIX copying enabled oper data

--- src/common.c
+++ src/common.c
@@ -4672,10 +4672,35 @@
     return NULL;
 }

+/**
+ * @brief Copy config NP containers as node and all of its parent siblings.
+ *
+ * @param[in] node Node to start copying to.
+ * @param[in] src Source node to copy from.
+ * @return err_info, NULL on success.
+ */
+static sr_error_info_t *
+sr_lyd_get_enabled_copy_config_np_cont(struct lyd_node *node, const struct lyd_node *src)
+{
+    sr_error_info_t *err_info = NULL;
+
+    while (node) {
+        if ((err_info = sr_lyd_copy_config_np_cont_r(NULL, node, src, lyd_owner_module(src)))) {
+            return err_info;
+        }
+
+        node = lyd_parent(node);
+        src = lyd_parent(src);
+    }
+
+    return NULL;
+}
+
 sr_error_info_t *
 sr_lyd_get_enabled_xpath(struct lyd_node **data, char **xpaths, uint16_t xp_count, int dup, struct lyd_node **new_data)
 {
     sr_error_info_t *err_info = NULL;
+    const struct ly_ctx *ctx = LYD_CTX(*data);
     struct lyd_node *root, *src, *parent;
     struct ly_set *cur_set, *set = NULL;
     size_t i;
@@ -4689,7 +4714,7 @@
     /* get only the selected subtrees in a set */
     for (i = 0; i < xp_count; ++i) {
         if (lyd_find_xpath(*data, xpaths[i], &cur_set)) {
-            sr_errinfo_new_ly(&err_info, LYD_CTX(*data));
+            sr_errinfo_new_ly(&err_info, ctx);
             goto cleanup;
         }

@@ -4697,7 +4722,7 @@
         if (set) {
             lyrc = ly_set_merge(set, cur_set, 0, NULL);
             ly_set_free(cur_set, NULL);
-            SR_CHECK_LY_GOTO(lyrc, LYD_CTX(*data), err_info, cleanup);
+            SR_CHECK_LY_GOTO(lyrc, ctx, err_info, cleanup);
         } else {
             set = cur_set;
         }
@@ -4706,74 +4731,64 @@
     for (i = 0; i < set->count; ++i) {
         /* get filtered subtree */
         src = set->dnodes[i];
+
         if (dup) {
             /* duplicate the subtree with parents */
             if (lyd_dup_single(src, NULL, LYD_DUP_RECURSIVE | LYD_DUP_WITH_PARENTS | LYD_DUP_WITH_FLAGS, &root)) {
-                sr_errinfo_new_ly(&err_info, LYD_CTX(*data));
+                sr_errinfo_new_ly(&err_info, ctx);
                 goto cleanup;
             }

-            /* set root to the first parent */
-            root = lyd_parent(root);
+            /* copy any nested config NP containers */
+            if ((err_info = sr_lyd_get_enabled_copy_config_np_cont(lyd_parent(root), src))) {
+                goto cleanup;
+            }
         } else {
             /* duplicate only the parents */
             parent = NULL;
             if (src->parent) {
                 if (lyd_dup_single(lyd_parent(src), NULL, LYD_DUP_WITH_PARENTS | LYD_DUP_WITH_FLAGS, &parent)) {
-                    sr_errinfo_new_ly(&err_info, LYD_CTX(*data));
+                    sr_errinfo_new_ly(&err_info, ctx);
                     goto cleanup;
                 }
             }

-            /* set root to the first parent */
-            root = parent;
-        }
-
-        /* go top-level and copy any config NP containers along the way */
-        if (root) {
-            while (1) {
-                if ((err_info = sr_lyd_copy_config_np_cont_r(NULL, root, src, lyd_owner_module(set->dnodes[i])))) {
-                    goto cleanup;
-                }
-
-                if (!root->parent) {
-                    /* leave with root pointing to the top-level node */
-                    break;
-                }
-                root = lyd_parent(root);
-
-                /* src should be a sibling, not parent (so move it afterwards) */
-                src = lyd_parent(src);
-            }
-        }
-
-        if (!dup) {
+            /* copy any nested config NP containers */
+            if ((err_info = sr_lyd_get_enabled_copy_config_np_cont(parent, src))) {
+                goto cleanup;
+            }
+
             /* we can unlink the subtree now */
             if (*data == src) {
                 /* unlinking data, move it */
                 *data = (*data)->next;
             }

+            /* relink into parent, if any */
             lyd_unlink_tree(src);
-            if (!root) {
-                /* top-level subtree */
-                root = src;
-            } else if (lyd_insert_child(parent, src)) {
-                sr_errinfo_new_ly(&err_info, LYD_CTX(*data));
+            if (parent && lyd_insert_child(parent, src)) {
+                sr_errinfo_new_ly(&err_info, ctx);
                 goto cleanup;
             }
+
+            root = src;
+        }
+
+        /* find top-level root */
+        while (root->parent) {
+            root = lyd_parent(root);
         }

         /* add any state NP containers */
         if (lyd_new_implicit_tree(root, LYD_IMPLICIT_NO_DEFAULTS, NULL)) {
-            sr_errinfo_new_ly(&err_info, LYD_CTX(*data));
+            sr_errinfo_new_ly(&err_info, ctx);
             goto cleanup;
         }

         /* merge into the final result */
         if (lyd_merge_tree(new_data, root, LYD_MERGE_DESTRUCT)) {
             lyd_free_all(root);
-            sr_errinfo_new_ly(&err_info, LYD_CTX(*data));
+            sr_errinfo_new_ly(&err_info, ctx);
             goto cleanup;
         }
     }


fix Win32 build regressions

fix Win32 build regressions

Date: Wed, 15 Aug 2012 15:59:25 -0700 (PDT)
From: Gernot Kvas <gernot.kvas@gmail.com>
Reply-To: avian@googlegroups.com
To: avian@googlegroups.com
Subject: Win32 build regression

Hi,

As I've forked on the July 19th and haven't updated since, I decided to
merge master into my WinCE branch. I found out that the following commits
have introduced build regressions on Windows:

1.)https://github.com/ReadyTalk/avian/commit/5a7c78e71ac7b4045c23d215162fb1284
8f1a5f3

=> strncasecmp is undefined for Windows

2.)https://github.com/ReadyTalk/avian/commit/b98abe3f94dbf552595554787ef2115c3
009856c

=> fpclassify and related constants are undefined for Windows

3.)https://github.com/ReadyTalk/avian/commit/20a290b992112f9b376d3a8d0180c1cca
8dd21e2

=> signbit is undefined for Windows

I attached a patch that makes everything build through (within Visual
Studio, the makefile still fails)

--- src/common.h
+++ src/common.h
@@ -24,6 +24,8 @@
 #include "math.h"

 #ifdef _MSC_VER
+
+#include "float.h"

 // don't complain about using 'this' in member initializers:
 #  pragma warning(disable:4355)
@@ -36,6 +38,34 @@
 typedef unsigned int uint32_t;
 typedef __int64 int64_t;
 typedef unsigned __int64 uint64_t;
+
+#define strncasecmp _strnicmp
+
+#define FP_NAN 0
+#define FP_INFINITE 1
+#define FP_UNDEF 2
+
+inline int fpclassify(double d) {
+
+	switch(_fpclass(d)) {
+		case _FPCLASS_SNAN:
+		case _FPCLASS_QNAN:
+			return FP_NAN;
+		case _FPCLASS_PINF:
+		case _FPCLASS_NINF:
+			return FP_INFINITE;
+	}
+	return FP_UNDEF;
+}
+
+#define INT32_MIN    ((int32_t) _I32_MIN)
+#define INT32_MAX    _I32_MAX
+#define INT64_MIN    ((int64_t) _I64_MIN)
+#define INT64_MAX    _I64_MAX
+
+inline int signbit(double d) {
+	return _copysign(1.0, d) < 0;
+}

 #  define not !
 #  define or ||


Move types.h include before ifaddres.h for u_int declaration

--- src/compat.h
+++ src/compat.h
@@ -26,6 +26,7 @@
 #include <windows.h>
 #include <ws2tcpip.h>
 #else
+#include <sys/types.h>
 #include <arpa/inet.h>
 #include <ifaddrs.h>
 #include <limits.h>
@@ -35,7 +36,6 @@
 #include <sys/fcntl.h>
 #include <sys/mman.h>
 #include <sys/socket.h>
-#include <sys/types.h>
 #include <unistd.h>
 #endif


Clarify some comments.  No object-code changes.

--- lib/gif_lib.h
+++ lib/gif_lib.h
@@ -60,13 +60,13 @@
 } ExtensionBlockList;

 typedef struct GifFileType {
-    GifWord SWidth, SHeight,        /* Screen dimensions. */
-      SColorResolution,         /* How many colors can we generate? */
-      SBackGroundColor;         /* I hope you understand this one... */
-    ColorMapObject *SColorMap;  /* NULL if not exists. */
-    int ImageCount;             /* Number of current image */
-    GifImageDesc Image;         /* Block describing current image */
-    struct SavedImage *SavedImages; /* Use this to accumulate file state */
+    GifWord SWidth, SHeight;    /* Size of virtual canvas */
+    GifWord SColorResolution;   /* How many colors can we generate? */
+    GifWord SBackGroundColor;   /* Background color for virtual canvas */
+    ColorMapObject *SColorMap;  /* Global color map, NULL if nonexistent. */
+    int ImageCount;             /* Number of current image (low-level API) */
+    GifImageDesc Image;         /* Current image (low-level API) */
+    struct SavedImage *SavedImages; /* Image sequence (high-level API) */
     ExtensionBlockList Trailing;    /* Extension blocks past last image */
     void *UserData;            /* hook to attach user data (TVT) */
     void *Private;             /* Don't mess with this! */


lib: fix signed/unsigned comparison issues

Store the result of set_vt_mode as a signed value so that errors can be
caught correctly.

Signed-off-by: Thomas Wood <b9025d6a953b68f894a0f6a80fd2af6d55b0badd@intel.com>
Signed-off-by: Daniel Vetter <c1b6782c4af8f0673da8923a0702a1832e5940f4@ffwll.ch>

--- lib/igt_kms.c
+++ lib/igt_kms.c
@@ -620,15 +620,16 @@

 void igt_set_vt_graphics_mode(void)
 {
+	long ret;
+
 	igt_install_exit_handler(restore_vt_mode_at_exit);

 	igt_disable_exit_handler();
-	orig_vt_mode = set_vt_mode(KD_GRAPHICS);
-	if (orig_vt_mode < 0)
-		orig_vt_mode = -1UL;
+	ret = set_vt_mode(KD_GRAPHICS);
 	igt_enable_exit_handler();

-	igt_assert(orig_vt_mode >= 0);
+	igt_assert(ret >= 0);
+	orig_vt_mode = ret;
 }

 int kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector,


isc_hex_fromtext didn't handle lowercase a-f

--- lib/isc/hex.c
+++ lib/isc/hex.c
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */

-/* $Id: hex.c,v 1.4 2000/11/18 03:01:12 bwelling Exp $ */
+/* $Id: hex.c,v 1.5 2000/11/19 20:58:58 bwelling Exp $ */

 #include <config.h>

@@ -93,7 +93,7 @@
 hex_decode_char(hex_decode_ctx_t *ctx, int c) {
 	char *s;

-	if ((s = strchr(hex, c)) == NULL)
+	if ((s = strchr(hex, toupper(c))) == NULL)
 		return (ISC_R_BADHEX);
 	ctx->val[ctx->digits++] = s - hex;
 	if (ctx->digits == 2) {


new buffer representation changes; use FATAL_ERROR not INSIST(0)

--- lib/isc/lex.c
+++ lib/isc/lex.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1998  Internet Software Consortium.
+ * Copyright (C) 1998, 1999  Internet Software Consortium.
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -22,6 +22,7 @@

 #include <isc/assertions.h>
 #include <isc/boolean.h>
+#include <isc/error.h>
 #include <isc/lex.h>
 #include <isc/list.h>

@@ -327,11 +328,13 @@
 		} else {
 			buffer = source->input;

-			if (buffer->current == buffer->base + buffer->used) {
+			if (buffer->current == buffer->used) {
 				c = EOF;
 				source->result = ISC_R_EOF;
-			} else
-				c = *buffer->current++;
+			} else {
+				c = *((char *)buffer->base + buffer->current);
+				buffer->current++;
+			}
 		}

 		if (lex->comment_ok && !no_comments) {
@@ -544,7 +547,9 @@
 			}
 			break;
 		default:
-			INSIST(0);
+			FATAL_ERROR(__FILE__, __LINE__,
+				    "Unexpected state %d", state);
+			/* Does not return. */
 		}

 	} while (!done);


formatting & macro updates

formatting & macro updates

--- lib/isc/lex.c
+++ lib/isc/lex.c
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */

-/* $Id: lex.c,v 1.61 2001/01/22 02:46:34 gson Exp $ */
+/* $Id: lex.c,v 1.62 2001/01/24 21:12:48 bwelling Exp $ */

 #include <config.h>

@@ -43,7 +43,7 @@
 	char *				name;
 	unsigned long			line;
 	unsigned long			saved_line;
-	LINK(struct inputsource)	link;
+	ISC_LINK(struct inputsource)	link;
 } inputsource;

 #define LEX_MAGIC			0x4C657821U	/* Lex!. */
@@ -295,7 +295,7 @@
 	if (source == NULL)
 		return (ISC_R_NOMORE);

-	UNLINK(lex->sources, source, link);
+	ISC_LIST_UNLINK(lex->sources, source, link);
 	if (source->is_file) {
 #ifdef HAVE_FLOCKFILE
 		funlockfile((FILE *)(source->input));
@@ -826,8 +826,10 @@
 	UNUSED(tokenp);

 	INSIST(source->ignored <= isc_buffer_consumedlength(source->pushback));
-	r->base = (unsigned char *)isc_buffer_base(source->pushback) + source->ignored;
-	r->length = isc_buffer_consumedlength(source->pushback) - source->ignored;
+	r->base = (unsigned char *)isc_buffer_base(source->pushback) +
+		  source->ignored;
+	r->length = isc_buffer_consumedlength(source->pushback) -
+		    source->ignored;
 }


hold partially read data in a packet.

hold partially read data in a packet.

--- lib/kcn_net.c
+++ lib/kcn_net.c
@@ -35,6 +35,7 @@
 	char kn_name[KCN_SOCKNAMELEN];
 	struct event kn_evread;
 	struct event kn_evwrite;
+	struct kcn_pkt kn_ipkt;
 	struct kcn_pkt_data *kn_ipktdata;
 	struct kcn_pkt_data *kn_opktdata;
 	struct kcn_pkt_queue kn_opktq;
@@ -74,6 +75,7 @@
 	event_set(&kn->kn_evwrite, fd, EV_WRITE | EV_TIMEOUT,
 	    kcn_net_write_cb, kn);
 	kn->kn_ipktdata = kcn_pkt_data_new(size);
+	kcn_pkt_init(&kn->kn_ipkt, kn->kn_ipktdata);
 	kn->kn_opktdata = kcn_pkt_data_new(size);
 	kcn_pkt_queue_init(&kn->kn_opktq);
 	kn->kn_readcb = readcb;
@@ -220,7 +222,6 @@
 kcn_net_read_cb(int fd, short events, void *arg)
 {
 	struct kcn_net *kn = arg;
-	struct kcn_pkt kp;
 	int error;

 	assert(kn->kn_fd == fd);
@@ -228,16 +229,14 @@
 	if (! kcn_net_event_check(kn, events, EV_READ))
 		return;

-	kcn_pkt_init(&kp, kn->kn_ipktdata);
-
-	error = kcn_pkt_read(kn->kn_fd, &kp);
+	error = kcn_pkt_read(kn->kn_fd, &kn->kn_ipkt);
 	if (error == EAGAIN)
 		goto out;
 	if (error != 0) {
 		LOG(DEBUG, "read() failed: %s", strerror(error));
 		goto out;
 	}
-	error = (*kn->kn_readcb)(kn, &kp, kn->kn_data);
+	error = (*kn->kn_readcb)(kn, &kn->kn_ipkt, kn->kn_data);
   out:
 	if (error == EAGAIN)
 		kcn_net_read_enable(kn);


add alpha getter/setter

add alpha getter/setter

--- lib/lsprite.c
+++ lib/lsprite.c
@@ -402,6 +402,21 @@
 }

 static int
+lsetalpha(lua_State *L) {
+	struct sprite *s = self(L);
+	uint8_t alpha = luaL_checkunsigned(L, 2);
+	s->t.color = (s->t.color >> 8) | (alpha << 24);
+	return 0;
+}
+
+static int
+lgetalpha(lua_State *L) {
+	struct sprite *s = self(L);
+	lua_pushunsigned(L, s->t.color & 0x000000FF);
+	return 1;
+}
+
+static int
 lgetadditive(lua_State *L) {
 	struct sprite *s = self(L);
 	lua_pushunsigned(L, s->t.additive);
@@ -426,6 +441,7 @@
 		{"type", lgettype },
 		{"text", lgettext},
 		{"color", lgetcolor },
+		{"alpha", lgetalpha },
 		{"additive", lgetadditive },
 		{"message", lgetmessage },
 		{"matrix", lgetmat },
@@ -446,6 +462,7 @@
 		{"matrix" , lsetmat},
 		{"text", lsettext},
 		{"color", lsetcolor},
+		{"alpha", lsetalpha},
 		{"additive", lsetadditive },
 		{"message", lsetmessage },
 		{"program", lsetprogram },
@@ -585,7 +602,7 @@
 		if (ani->component[i].name != NULL) {
 			lua_pushstring(L, ani->component[i].name);
 			cnt++;
-		}
+		}
 	}
 	return cnt;
 }
@@ -638,7 +655,7 @@
 			sprite_draw(s, NULL);
 		}
 	}
-
+
 	s->t.mat = parent_mat;
 	s->t.color = parent_color;

@@ -681,7 +698,7 @@
             s->t.mat = (struct matrix *)lua_touserdata(L, -2);
             s->t.color = (uint32_t)lua_tounsigned(L, -1);
             lua_pop(L, 2);
-
+
             sprite_draw_as_child(s, &srt, parent_mat, parent_color);
         }
     }else {
@@ -693,7 +710,7 @@
             s->t.color = (uint32_t)lua_tounsigned(L, -2);
             s->t.additive = (uint32_t)lua_tounsigned(L, -1);
             lua_pop(L, 3);
-
+
             sprite_draw_as_child(s, &srt, parent_mat, parent_color);
         }
     }


Always use "out of range" for RGPH_RANGE.

--- lib/luargph.c
+++ lib/luargph.c
@@ -156,7 +156,7 @@

 	nkeys = luaL_checkinteger(L, 1);
 	if (nkeys < 0)
-		return luaL_argerror(L, 1, "not in range");
+		return luaL_argerror(L, 1, "out of range");

 	flags = parse_flags(L, 2);

@@ -914,7 +914,7 @@

 	switch (res) {
 	case RGPH_RANGE:
-		return luaL_error(L, "edge is out of range");
+		return luaL_error(L, "out of range");
 	case RGPH_SUCCESS:
 		rank = rgph_rank(*pg);
 		switch (rank) {


Initial revision

Initial revision

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

--- lib/rpmlead.h
+++ lib/rpmlead.h
@@ -0,0 +1,21 @@
+#ifndef _H_RPMLEAD
+#define _H_RPMLEAD
+
+#define RPMLEAD_BINARY 0
+#define RPMLEAD_SOURCE 1
+
+#define RPMLEAD_MAGIC0 0xed
+#define RPMLEAD_MAGIC1 0xab
+#define RPMLEAD_MAGIC2 0xee
+#define RPMLEAD_MAGIC3 0xdb
+
+struct rpmlead {
+    char magic[4];
+    char major, minor;
+    short type;
+    short archnum;
+    char name[66];
+    short osnum;
+} ;
+
+#endif


hanoi cpp game resurrected

hanoi cpp game resurrected

error: pathspec 'CosBase/include/cos/cpp/hanoi.h' did not match any file(s) known to git

--- CosBase/include/cos/cpp/hanoi.h
+++ CosBase/include/cos/cpp/hanoi.h
@@ -0,0 +1,74 @@
+#ifndef COS_CPP_HANOI_H
+#define COS_CPP_HANOI_H
+
+/*
+ o---------------------------------------------------------------------o
+ |
+ | C Object System -- Hanoi Tower game
+ |
+ o---------------------------------------------------------------------o
+ |
+ | C Object System
+ |
+ | Copyright (c) 2006+ Laurent Deniau, laurent.deniau@cern.ch
+ |
+ | For more information, see:
+ | http://cern.ch/laurent.deniau/cos.html
+ |
+ o---------------------------------------------------------------------o
+ |
+ | This file is part of the C Object System framework.
+ |
+ | The C Object System is free software; you can redistribute it and/or
+ | modify it under the terms of the GNU Lesser General Public License
+ | as published by the Free Software Foundation; either version 3 of
+ | the License, or (at your option) any later version.
+ |
+ | The C Object System is distributed in the hope that it will be
+ | useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ |
+ | See <http://www.gnu.org/licenses> for more details.
+ |
+ o---------------------------------------------------------------------o
+ |
+ | $Id: hanoi.h,v 1.1 2009/10/05 18:46:19 ldeniau Exp $
+ |
+*/
+
+#include <cos/cpp/cpp.h>
+
+/* NOTE-USER: COS_PP_HANOI(N) returns the list of moves for n disks
+   ex: COS_PP_HANOI(2)  -> ((1,2),(1,3),(2,3))
+       COS_PP_HANOI(3)  -> ((1,3),(1,2),(3,2),(1,3),(2,1),(2,3),(1,3))
+       COS_PP_HANOI(16) -> (.. 65535 moves ..)
+       COS_PP_HANOI(20) -> (.. 1048575 moves ..)
+                           after 45s on my Pentium-M 1.5Ghz with gcc 4.1.1
+ */
+
+#define COS_PP_HANOI(n) \
+        COS_PP_CAT(COS_PP_HANOI_,n)(1,2,3)
+
+#define COS_PP_HANOI_0( L,C,R)                                     (   )
+#define COS_PP_HANOI_1( L,C,R)                                    ((L,R))
+#define COS_PP_HANOI_2( L,C,R) (COS_PP_SEQ(COS_PP_HANOI_1( L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_1( C,L,R)))
+#define COS_PP_HANOI_3( L,C,R) (COS_PP_SEQ(COS_PP_HANOI_2( L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_2( C,L,R)))
+#define COS_PP_HANOI_4( L,C,R) (COS_PP_SEQ(COS_PP_HANOI_3( L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_3( C,L,R)))
+#define COS_PP_HANOI_5( L,C,R) (COS_PP_SEQ(COS_PP_HANOI_4( L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_4( C,L,R)))
+#define COS_PP_HANOI_6( L,C,R) (COS_PP_SEQ(COS_PP_HANOI_5( L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_5( C,L,R)))
+#define COS_PP_HANOI_7( L,C,R) (COS_PP_SEQ(COS_PP_HANOI_6( L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_6( C,L,R)))
+#define COS_PP_HANOI_8( L,C,R) (COS_PP_SEQ(COS_PP_HANOI_7( L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_7( C,L,R)))
+#define COS_PP_HANOI_9( L,C,R) (COS_PP_SEQ(COS_PP_HANOI_8( L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_8( C,L,R)))
+#define COS_PP_HANOI_10(L,C,R) (COS_PP_SEQ(COS_PP_HANOI_9( L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_9( C,L,R)))
+#define COS_PP_HANOI_11(L,C,R) (COS_PP_SEQ(COS_PP_HANOI_10(L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_10(C,L,R)))
+#define COS_PP_HANOI_12(L,C,R) (COS_PP_SEQ(COS_PP_HANOI_11(L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_11(C,L,R)))
+#define COS_PP_HANOI_13(L,C,R) (COS_PP_SEQ(COS_PP_HANOI_12(L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_12(C,L,R)))
+#define COS_PP_HANOI_14(L,C,R) (COS_PP_SEQ(COS_PP_HANOI_13(L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_13(C,L,R)))
+#define COS_PP_HANOI_15(L,C,R) (COS_PP_SEQ(COS_PP_HANOI_14(L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_14(C,L,R)))
+#define COS_PP_HANOI_16(L,C,R) (COS_PP_SEQ(COS_PP_HANOI_15(L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_15(C,L,R)))
+#define COS_PP_HANOI_17(L,C,R) (COS_PP_SEQ(COS_PP_HANOI_16(L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_16(C,L,R)))
+#define COS_PP_HANOI_18(L,C,R) (COS_PP_SEQ(COS_PP_HANOI_17(L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_17(C,L,R)))
+#define COS_PP_HANOI_19(L,C,R) (COS_PP_SEQ(COS_PP_HANOI_18(L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_18(C,L,R)))
+#define COS_PP_HANOI_20(L,C,R) (COS_PP_SEQ(COS_PP_HANOI_19(L,R,C)),(L,R),COS_PP_SEQ(COS_PP_HANOI_19(C,L,R)))
+
+#endif // COS_CPP_HANOI_H