Fixes to some typedefs. Some other (less useful) typedefs are removed.

--- cyPointCloud.h
+++ cyPointCloud.h
@@ -362,37 +362,17 @@
 template <typename TYPE> _CY_TEMPLATE_ALIAS( PointCloud3, (PointCloud<Point3<TYPE>,TYPE,3>) );	//!< A 3D point cloud using a k-d tree
 template <typename TYPE> _CY_TEMPLATE_ALIAS( PointCloud4, (PointCloud<Point4<TYPE>,TYPE,4>) );	//!< A 4D point cloud using a k-d tree

-typedef PointCloud<Point2f,float,2>  PointCloud2f;	//!< A 2D point cloud using a k-d tree with single precision (float)
-typedef PointCloud<Point3f,float,3>  PointCloud3f;	//!< A 3D point cloud using a k-d tree with single precision (float)
-typedef PointCloud<Point4f,float,4>  PointCloud4f;	//!< A 4D point cloud using a k-d tree with single precision (float)
-
-typedef PointCloud<Point2f,double,2> PointCloud2d;	//!< A 2D point cloud using a k-d tree with double precision (double)
-typedef PointCloud<Point3f,double,3> PointCloud3d;	//!< A 3D point cloud using a k-d tree with double precision (double)
-typedef PointCloud<Point4f,double,4> PointCloud4d;	//!< A 4D point cloud using a k-d tree with double precision (double)
-
-typedef PointCloud<Point2f,int32_t,2>  PointCloud2i;	//!< A 2D point cloud using a k-d tree with 32-bit signed integer (int32_t)
-typedef PointCloud<Point3f,int32_t,3>  PointCloud3i;	//!< A 3D point cloud using a k-d tree with 32-bit signed integer (int32_t)
-typedef PointCloud<Point4f,int32_t,4>  PointCloud4i;	//!< A 4D point cloud using a k-d tree with 32-bit signed integer (int32_t)
-
-typedef PointCloud<Point2f,uint32_t,2> PointCloud2ui;	//!< A 2D point cloud using a k-d tree with 32-bit unsigned integer (uint32_t)
-typedef PointCloud<Point3f,uint32_t,3> PointCloud3ui;	//!< A 3D point cloud using a k-d tree with 32-bit unsigned integer (uint32_t)
-typedef PointCloud<Point4f,uint32_t,4> PointCloud4ui;	//!< A 4D point cloud using a k-d tree with 32-bit unsigned integer (uint32_t)
-
-typedef PointCloud<Point2f,int64_t,2>  PointCloud2l;	//!< A 2D point cloud using a k-d tree with 64-bit signed integer (int64_t)
-typedef PointCloud<Point3f,int64_t,3>  PointCloud3l;	//!< A 3D point cloud using a k-d tree with 64-bit signed integer (int64_t)
-typedef PointCloud<Point4f,int64_t,4>  PointCloud4l;	//!< A 4D point cloud using a k-d tree with 64-bit signed integer (int64_t)
-
-typedef PointCloud<Point2f,uint64_t,2> PointCloud2ul;	//!< A 2D point cloud using a k-d tree with 64-bit unsigned integer (uint64_t)
-typedef PointCloud<Point3f,uint64_t,3> PointCloud3ul;	//!< A 3D point cloud using a k-d tree with 64-bit unsigned integer (uint64_t)
-typedef PointCloud<Point4f,uint64_t,4> PointCloud4ul;	//!< A 4D point cloud using a k-d tree with 64-bit unsigned integer (uint64_t)
+typedef PointCloud<Point2f,float,2>  PointCloud2f;	//!< A 2D point cloud using a k-d tree with float  type elements
+typedef PointCloud<Point3f,float,3>  PointCloud3f;	//!< A 3D point cloud using a k-d tree with float  type elements
+typedef PointCloud<Point4f,float,4>  PointCloud4f;	//!< A 4D point cloud using a k-d tree with float  type elements
+
+typedef PointCloud<Point2d,double,2> PointCloud2d;	//!< A 2D point cloud using a k-d tree with double type elements
+typedef PointCloud<Point3d,double,3> PointCloud3d;	//!< A 3D point cloud using a k-d tree with double type elements
+typedef PointCloud<Point4d,double,4> PointCloud4d;	//!< A 4D point cloud using a k-d tree with double type elements

 template <typename TYPE, uint32_t DIMENSIONS> _CY_TEMPLATE_ALIAS( PointCloudN, (PointCloud<Point<TYPE,DIMENSIONS>,TYPE,DIMENSIONS>) );	//!< A multi-dimensional point cloud using a k-d tree
 template <uint32_t DIMENSIONS> _CY_TEMPLATE_ALIAS( PointCloudNf , (PointCloudN<float,   DIMENSIONS>) );	//!< A multi-dimensional point cloud using a k-d tree with single precision (float)
 template <uint32_t DIMENSIONS> _CY_TEMPLATE_ALIAS( PointCloudNd , (PointCloudN<double,  DIMENSIONS>) );	//!< A multi-dimensional point cloud using a k-d tree with double precision (double)
-template <uint32_t DIMENSIONS> _CY_TEMPLATE_ALIAS( PointCloudNi , (PointCloudN<int32_t, DIMENSIONS>) );	//!< A multi-dimensional point cloud using a k-d tree with 32-bit signed integer (int32_t)
-template <uint32_t DIMENSIONS> _CY_TEMPLATE_ALIAS( PointCloudNui, (PointCloudN<uint32_t,DIMENSIONS>) );	//!< A multi-dimensional point cloud using a k-d tree with 32-bit unsigned integer (uint32_t)
-template <uint64_t DIMENSIONS> _CY_TEMPLATE_ALIAS( PointCloudNl , (PointCloudN<int64_t, DIMENSIONS>) );	//!< A multi-dimensional point cloud using a k-d tree with 64-bit signed integer (int64_t)
-template <uint64_t DIMENSIONS> _CY_TEMPLATE_ALIAS( PointCloudNul, (PointCloudN<uint64_t,DIMENSIONS>) );	//!< A multi-dimensional point cloud using a k-d tree with 64-bit unsigned integer (uint64_t)
 #endif

 //-------------------------------------------------------------------------------
@@ -404,37 +384,17 @@
 template <typename TYPE> _CY_TEMPLATE_ALIAS( cyPointCloud3, (cy::PointCloud<cy::Point3<TYPE>,TYPE,3>) );	//!< A 3D point cloud using a k-d tree
 template <typename TYPE> _CY_TEMPLATE_ALIAS( cyPointCloud4, (cy::PointCloud<cy::Point4<TYPE>,TYPE,4>) );	//!< A 4D point cloud using a k-d tree

-typedef cy::PointCloud<cy::Point2f,float,2>  cyPointCloud2f;	//!< A 2D point cloud using a k-d tree with single precision (float)
-typedef cy::PointCloud<cy::Point3f,float,3>  cyPointCloud3f;	//!< A 3D point cloud using a k-d tree with single precision (float)
-typedef cy::PointCloud<cy::Point4f,float,4>  cyPointCloud4f;	//!< A 4D point cloud using a k-d tree with single precision (float)
-
-typedef cy::PointCloud<cy::Point2f,double,2> cyPointCloud2d;	//!< A 2D point cloud using a k-d tree with double precision (double)
-typedef cy::PointCloud<cy::Point3f,double,3> cyPointCloud3d;	//!< A 3D point cloud using a k-d tree with double precision (double)
-typedef cy::PointCloud<cy::Point4f,double,4> cyPointCloud4d;	//!< A 4D point cloud using a k-d tree with double precision (double)
-
-typedef cy::PointCloud<cy::Point2f,int32_t,2>  cyPointCloud2i;	//!< A 2D point cloud using a k-d tree with 32-bit signed integer (int32_t)
-typedef cy::PointCloud<cy::Point3f,int32_t,3>  cyPointCloud3i;	//!< A 3D point cloud using a k-d tree with 32-bit signed integer (int32_t)
-typedef cy::PointCloud<cy::Point4f,int32_t,4>  cyPointCloud4i;	//!< A 4D point cloud using a k-d tree with 32-bit signed integer (int32_t)
-
-typedef cy::PointCloud<cy::Point2f,uint32_t,2> cyPointCloud2ui;	//!< A 2D point cloud using a k-d tree with 32-bit unsigned integer (uint32_t)
-typedef cy::PointCloud<cy::Point3f,uint32_t,3> cyPointCloud3ui;	//!< A 3D point cloud using a k-d tree with 32-bit unsigned integer (uint32_t)
-typedef cy::PointCloud<cy::Point4f,uint32_t,4> cyPointCloud4ui;	//!< A 4D point cloud using a k-d tree with 32-bit unsigned integer (uint32_t)
-
-typedef cy::PointCloud<cy::Point2f,int64_t,2>  cyPointCloud2l;	//!< A 2D point cloud using a k-d tree with 64-bit signed integer (int64_t)
-typedef cy::PointCloud<cy::Point3f,int64_t,3>  cyPointCloud3l;	//!< A 3D point cloud using a k-d tree with 64-bit signed integer (int64_t)
-typedef cy::PointCloud<cy::Point4f,int64_t,4>  cyPointCloud4l;	//!< A 4D point cloud using a k-d tree with 64-bit signed integer (int64_t)
-
-typedef cy::PointCloud<cy::Point2f,uint64_t,2> cyPointCloud2ul;	//!< A 2D point cloud using a k-d tree with 64-bit unsigned integer (uint64_t)
-typedef cy::PointCloud<cy::Point3f,uint64_t,3> cyPointCloud3ul;	//!< A 3D point cloud using a k-d tree with 64-bit unsigned integer (uint64_t)
-typedef cy::PointCloud<cy::Point4f,uint64_t,4> cyPointCloud4ul;	//!< A 4D point cloud using a k-d tree with 64-bit unsigned integer (uint64_t)
+typedef cy::PointCloud<cy::Point2f,float,2>  cyPointCloud2f;	//!< A 2D point cloud using a k-d tree with float  type elements
+typedef cy::PointCloud<cy::Point3f,float,3>  cyPointCloud3f;	//!< A 3D point cloud using a k-d tree with float  type elements
+typedef cy::PointCloud<cy::Point4f,float,4>  cyPointCloud4f;	//!< A 4D point cloud using a k-d tree with float  type elements
+
+typedef cy::PointCloud<cy::Point2d,double,2> cyPointCloud2d;	//!< A 2D point cloud using a k-d tree with double type elements
+typedef cy::PointCloud<cy::Point3d,double,3> cyPointCloud3d;	//!< A 3D point cloud using a k-d tree with double type elements
+typedef cy::PointCloud<cy::Point4d,double,4> cyPointCloud4d;	//!< A 4D point cloud using a k-d tree with double type elements

 template <typename TYPE, uint32_t DIMENSIONS> _CY_TEMPLATE_ALIAS( cyPointCloudN, (cy::PointCloud<cy::Point<TYPE,DIMENSIONS>,TYPE,DIMENSIONS>) );	//!< A multi-dimensional point cloud using a k-d tree
-template <uint32_t DIMENSIONS> _CY_TEMPLATE_ALIAS( cyPointCloudNf , (cyPointCloudN<float,   DIMENSIONS>) );	//!< A multi-dimensional point cloud using a k-d tree with single precision (float)
-template <uint32_t DIMENSIONS> _CY_TEMPLATE_ALIAS( cyPointCloudNd , (cyPointCloudN<double,  DIMENSIONS>) );	//!< A multi-dimensional point cloud using a k-d tree with double precision (double)
-template <uint32_t DIMENSIONS> _CY_TEMPLATE_ALIAS( cyPointCloudNi , (cyPointCloudN<int32_t, DIMENSIONS>) );	//!< A multi-dimensional point cloud using a k-d tree with 32-bit signed integer (int32_t)
-template <uint32_t DIMENSIONS> _CY_TEMPLATE_ALIAS( cyPointCloudNui, (cyPointCloudN<uint32_t,DIMENSIONS>) );	//!< A multi-dimensional point cloud using a k-d tree with 32-bit unsigned integer (uint32_t)
-template <uint64_t DIMENSIONS> _CY_TEMPLATE_ALIAS( cyPointCloudNl , (cyPointCloudN<int64_t, DIMENSIONS>) );	//!< A multi-dimensional point cloud using a k-d tree with 64-bit signed integer (int64_t)
-template <uint64_t DIMENSIONS> _CY_TEMPLATE_ALIAS( cyPointCloudNul, (cyPointCloudN<uint64_t,DIMENSIONS>) );	//!< A multi-dimensional point cloud using a k-d tree with 64-bit unsigned integer (uint64_t)
+template <uint32_t DIMENSIONS> _CY_TEMPLATE_ALIAS( cyPointCloudNf , (cyPointCloudN<float,   DIMENSIONS>) );	//!< A multi-dimensional point cloud using a k-d tree with float  type elements
+template <uint32_t DIMENSIONS> _CY_TEMPLATE_ALIAS( cyPointCloudNd , (cyPointCloudN<double,  DIMENSIONS>) );	//!< A multi-dimensional point cloud using a k-d tree with double type elements
 #endif

 //-------------------------------------------------------------------------------


Increase stack size for larger number of processes.

--- src/findAQ.c
+++ src/findAQ.c
@@ -23,6 +23,7 @@

 static const int NUM_REQUIRED_ARGS = 5;
 static const int MAX_SOLUTION_SET_SIZE = 4096;
+static const int MAX_MPI_PROCS = 64;

 static const int EXIT_OK = 0;
 static const int EXIT_NUM_ARGS_INCORRECT = 1;
@@ -42,9 +43,35 @@
 /**
  * Function prototypes.
  */
+void expandStackSize();
 int readProgramArgs(int, char**, struct program_args*);
 static inline void godFunction(struct program_args*);
 static inline void gatherResults(int, int, struct aq_board*);
+
+/**
+ * We need more stack size than the default.
+ */
+void expandStackSize() {
+    // Set to 64MB.
+    const rlim_t stack_size = 64L * 1024L * 1024L;
+    struct rlimit rl;
+    int result;
+
+    result = getrlimit(RLIMIT_STACK, &rl);
+    if (result == 0) {
+        if (rl.rlim_cur < stack_size) {
+            rl.rlim_cur = stack_size;
+            result = setrlimit(RLIMIT_STACK, &rl);
+            if (result != 0) {
+                fprintf(stderr, "%s: Failed to increase stack size (errno %d)\n",
+                        "expandStackSize", result);
+            }
+        }
+    } else {
+        fprintf(stderr, "%s: Failed to increase stack size (errno %d)\n",
+                "expandStackSize", result);
+    }
+}

 /**
  * Reads the arguments for the program.
@@ -140,15 +167,24 @@
     int i, j, k;
     int has_existing_solutions;

+    struct aq_board all_solution_set[MAX_SOLUTION_SET_SIZE];
     int all_num_solutions;
     int all_max_queens;
-    struct aq_board all_solution_set[MAX_SOLUTION_SET_SIZE];
+
+    struct aq_board gathered_solution_set[MAX_MPI_PROCS][MAX_SOLUTION_SET_SIZE];
+    int gathered_num_solutions[MAX_MPI_PROCS];
+    int gathered_max_queens[MAX_MPI_PROCS];

     // MPI information.
     int mpi_rank;
     int mpi_nprocs;
     MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
     MPI_Comm_size(MPI_COMM_WORLD, &mpi_nprocs);
+
+#ifndef NDEBUG
+    assert(mpi_nprocs < MAX_MPI_PROCS &&
+           "Consider increasing MAX_MPI_PROCS");
+#endif

     // Declare a new type to MPI.
     struct aq_board mpi_board;
@@ -170,9 +206,6 @@
     MPI_Type_commit(&mpi_aq_board_type);

     // Send the solution set over.
-    struct aq_board gathered_solution_set[mpi_nprocs][MAX_SOLUTION_SET_SIZE];
-    int gathered_num_solutions[mpi_nprocs];
-    int gathered_max_queens[mpi_nprocs];
     MPI_Gather(&num_solutions, 1, MPI_INT, &gathered_num_solutions, 1, MPI_INT, 0,
             MPI_COMM_WORLD);
     MPI_Gather(&max_queens, 1, MPI_INT, &gathered_max_queens, 1, MPI_INT, 0,
@@ -362,7 +395,13 @@
  */
 int main(int argc, char* argv[]) {
     struct program_args args;
-    int retval = readProgramArgs(argc, argv, &args);
+    int retval;
+
+    // But first, let me expand the stack size.
+    expandStackSize();
+
+    // Read our arguments!
+    retval = readProgramArgs(argc, argv, &args);
     if (retval != EXIT_OK) {
         return retval;
     }


Fixed segmentation fault with no score file

--- Top/main.c
+++ Top/main.c
@@ -105,7 +105,6 @@
     char    *filnamp, *envoutyp = NULL;
     char    *sortedscore = NULL;
     char    *xtractedscore = "score.xtr";
-    char    *sconame = get_sconame(csound);
     char    *playscore = NULL;      /* unless we extract */
     FILE    *scorin = NULL, *scorout = NULL, *xfile = NULL;
     int     n;
@@ -283,13 +282,14 @@

     if (csound->scorename == NULL || strlen(csound->scorename) == 0) {
       /* No scorename yet */
+      char *sconame = get_sconame(csound);
       char *p;
       FILE *scof;
       tmpnam(sconame);              /* Generate score name */
       if ((p=strchr(sconame, '.')) != NULL) *p='\0'; /* with extention */
       strcat(sconame, ".sco");
       scof = fopen(sconame, "w");
-      fprintf(scof, "f0 86400\n");
+      fprintf(scof, "f0 42000\n");
       fclose(scof);
       csound->scorename = sconame;
       add_tmpfile(csound, sconame);     /* IV - Feb 03 2005 */


fix warnings

fix warnings

--- src/format.c
+++ src/format.c
@@ -176,7 +176,7 @@
 		start = ptr;
 		if (ce == CE_BYTES) {
 			code = *ptr++;
-			iter->current = (code < 0x80) ? code : -(int)code;
+			iter->current = (code < 0x80) ? (int)code : -(int)code;
 		} else if ((err = corpus_scan_utf8(&start, end))) {
 			iter->current = -(int)*ptr++;
 		} else {
@@ -192,7 +192,7 @@

 static int text_iter_retreat(struct text_iter *iter)
 {
-	const uint8_t *start, *begin, *ptr, *end;
+	const uint8_t *start, *begin, *ptr;
 	uint32_t code;
 	int nbyte, err, ret;

@@ -204,7 +204,6 @@

 	begin = iter->data.raw.begin;
 	ptr = iter->data.raw.ptr;
-	end = iter->data.raw.end;

 	// at SOT
 	if (ptr == begin) {
@@ -598,6 +597,7 @@
 			error("argument is not a character vector");
 		}
 		type = TEXT_RAW;
+		text = NULL;
 		PROTECT(ans = duplicate(sx)); nprot++;
 		n = XLENGTH(ans);
 	}


[gc_api] delete unused function new_buffer_header

git-svn-id: 1eb33f31d1a165515dfa52993683d2778fcf3173@38554 d31e2699-5ff4-0310-a27c-f18f2fbe73fe

--- src/gc/api.c
+++ src/gc/api.c
@@ -223,28 +223,6 @@

 /*

-=item C<Buffer * new_buffer_header(PARROT_INTERP)>
-
-Creates and returns a new C<Buffer> from the buffer header pool.  Calls
-C<get_free_buffer> to do all the work.
-
-=cut
-
-*/
-
-PARROT_CANNOT_RETURN_NULL
-PARROT_WARN_UNUSED_RESULT
-Buffer *
-new_buffer_header(PARROT_INTERP)
-{
-    ASSERT_ARGS(new_buffer_header)
-    return (Buffer *)get_free_buffer(interp,
-            interp->arena_base->buffer_header_pool);
-}
-
-
-/*
-
 =item C<void * new_bufferlike_header(PARROT_INTERP, size_t size)>

 Returns a new buffer-like header from the appropriate sized pool.


[GC] Removed the constant PMC marking code.  If there are any constant PObjs
that themselves point to non-constant PObjs, we need to find them and fix that.

There should be a minor speed improvement after this change.

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

--- src/gc/dod.c
+++ src/gc/dod.c
@@ -186,9 +186,6 @@
     } while (0);
 #else /* not PARROT_GC_GMS */

-    if (PObj_constant_TEST(obj) && PObj_custom_mark_TEST(obj))
-        VTABLE_mark(interp, (PMC *)obj);
-
     /* if object is live or on free list return */
     if (PObj_is_live_or_free_TESTALL(obj))
         return;
@@ -216,7 +213,7 @@
     /* if object is a PMC and contains buffers or PMCs, then attach
      * the PMC to the chained mark list.
      */
-    if (PObj_is_special_PMC_TEST(obj) && !PObj_constant_TEST(obj)) {
+    if (PObj_is_special_PMC_TEST(obj)) {
         mark_special(interp, (PMC*) obj);
     }
 #  ifndef NDEBUG


Fix bug in parser tests

Fix bug in parser tests

The act of parsing the ast pops the token from the token list, so we need
a pointer to the token for our assertion.

--- parser_tests.c
+++ parser_tests.c
@@ -25,9 +25,10 @@

 void test_parse_number() {
     struct token_list *tkl = make_token_list();
-    tkl.append(make_token(tok_number, NULL, 0.0, 42);
+    struct token *tk = make_token(tok_number, NULL, 0.0, 42);
+    append_token_list(tkl, tk);
     struct ast_node *result = parse_number(tkl);
-    EXPECT_EQ(result->val, tkl->head);
+    EXPECT_EQ(result->val, tk);
     EXPECT_EQ(result->num_children, 0);
     destroy_token_list(tkl);
 }


Forms: handle font size zero in default appearance

--- pdf/pdf_form.c
+++ pdf/pdf_form.c
@@ -10,11 +10,6 @@
 	Ff_Combo         = 1 << (18-1)
 };

-enum
-{
-	MaxNumChars = 20
-};
-
 struct fz_widget_s
 {
 	pdf_document *doc;
@@ -116,25 +111,69 @@
 	return widget;
 }

+static void copy_da_with_size_check(fz_context *ctx, fz_buffer *fzbuf, char *da, float h)
+{
+	int tok;
+	pdf_lexbuf lbuf;
+	fz_stream *str = fz_open_memory(ctx, da, strlen(da));
+
+	memset(lbuf.scratch, 0, sizeof(lbuf.scratch));
+	lbuf.size = sizeof(lbuf.scratch);
+	fz_try(ctx)
+	{
+		int last_tok_was_zero = 0;
+
+		for (tok = pdf_lex(str, &lbuf); tok != PDF_TOK_EOF; tok = pdf_lex(str, &lbuf))
+		{
+			if (last_tok_was_zero)
+			{
+				/* Tf with 0 size means choose size to fit, so replace
+				 * 0 with h */
+				if (tok = PDF_TOK_NAME && !strcmp(lbuf.scratch, "Tf"))
+					fz_buffer_printf(ctx, fzbuf, " %1.2f", h);
+				else
+					fz_buffer_printf(ctx, fzbuf, " %d", 0);
+
+				last_tok_was_zero = 0;
+			}
+
+			if (tok == PDF_TOK_INT && lbuf.i == 0)
+				last_tok_was_zero = 1;
+			else
+			{
+				fz_buffer_printf(ctx, fzbuf, " ");
+				pdf_print_token(ctx, fzbuf, tok, &lbuf);
+			}
+		}
+	}
+	fz_always(ctx)
+	{
+		fz_close(str);
+	}
+	fz_catch(ctx)
+	{
+		fz_rethrow(ctx);
+	}
+}
+
 fz_buffer *create_text_appearance(fz_context *ctx, fz_rect *bbox, char *da, char *text)
 {
+	int height;
 	fz_buffer *fzbuf;
-	int len;
-	unsigned char *buf;
 	fz_rect rect;
-	const char *fmt = "/Tx BMC"
+	const char *fmt1 =
+		"/Tx BMC"
 		" q"
-		" %.2f %.2f %.2f %.2f re"
+		" %1.2f %1.2f %1.2f %1.2f re"
 		" W"
 		" n"
-		" BT"
-		" %s"
+		" BT";
+	const char *fmt2 =
 		" (%s) Tj"
 		" ET"
 		" Q"
 		" EMC";

-	len = strlen(fmt) + 4*(MaxNumChars - 2) + strlen(da) - 2, strlen(text) - 2;
 	rect = *bbox;

 	if (rect.x1 - rect.x0 >= 2.0 && rect.y1 - rect.y0 >= 2.0)
@@ -145,13 +184,14 @@
 		rect.y1 -= 1.0;
 	}

-	fzbuf = fz_new_buffer(ctx, len+1);
-	(void)fz_buffer_storage(ctx, fzbuf, &buf);
-	fzbuf->len = snprintf(buf, len+1,
-		fmt, rect.x0, rect.y0, rect.x1 - rect.x0, rect.y1 - rect.y0,
-		da, text);
-	if (fzbuf->len < 0 || fzbuf->len > len)
-		fz_throw(ctx, "predicted length to small");
+	height = MAX(bbox->y1 - bbox->y0 - 4.0, 1.0);
+
+	fzbuf = fz_new_buffer(ctx, 0);
+	fz_buffer_printf(ctx, fzbuf, fmt1,
+		rect.x0, rect.y0, rect.x1 - rect.x0, rect.y1 - rect.y0);
+	copy_da_with_size_check(ctx, fzbuf, da, height);
+	fz_buffer_printf(ctx, fzbuf, fmt2,
+		text);

 	return fzbuf;
 }


Fixed issue #14

Fixed issue #14

Under FreeBSD events must be created after gbProcessInit since daemonizing the process would mess up timers ( see issue #14 ).

--- src/gibson.c
+++ src/gibson.c
@@ -234,7 +234,6 @@
 	server.cronperiod  = gbConfigReadInt( &server.config, "cron_period", 	   GB_DEFAULT_CRON_PERIOD );
 	server.pidfile	   = gbConfigReadString( &server.config, "pidfile",        GB_DEFAULT_PID_FILE );
     server.gc_ratio    = gbConfigReadTime( &server.config, "gc_ratio",         GB_DEFAULT_GC_RATIO );
-	server.events 	   = gbCreateEventLoop( server.limits.maxclients + 1024 );
 	server.clients 	   = ll_prealloc( server.limits.maxclients );
 	server.m_keys	   = ll_prealloc( 255 );
 	server.m_values	   = ll_prealloc( 255 );
@@ -280,7 +279,12 @@
 	gbLog( INFO, "Cron period      : %dms", server.cronperiod );

 	gbProcessInit();
-
+
+	/*
+	 * Under FreeBSD events must be created after gbProcessInit since daemonizing
+	 * the process would mess up timers ( see issue #14 ).
+	 */
+	server.events  = gbCreateEventLoop( server.limits.maxclients + 1024 );
 	server.cron_id = gbCreateTimeEvent( server.events, 1, gbServerCronHandler, &server, NULL );

 	gbCreateFileEvent( server.events, server.fd, GB_READABLE, gbAcceptHandler, &server );


fix up glGetError remote behavior

fix up glGetError remote behavior

--- src/gl/get.c
+++ src/gl/get.c
@@ -8,25 +8,38 @@
 #include "remote.h"

 void gl_set_error(GLenum error) {
-    LOAD_GLES(glGetError);
     // call upstream glGetError to clear the driver's error flag
-    gles_glGetError();
+    if (state.remote) {
+        remote_call(pack_glGetError(), NULL);
+    } else {
+        LOAD_GLES(glGetError);
+        gles_glGetError();
+    }
     state.error = error;
 }

 // calls upstream glGetError and saves the flag for the next caller
 GLenum gl_get_error() {
-    LOAD_GLES(glGetError);
-    state.error = gles_glGetError();
+    if (state.remote) {
+        remote_call(pack_glGetError(), &state.error);
+    } else {
+        LOAD_GLES(glGetError);
+        state.error = gles_glGetError();
+    }
     return state.error;
 }

 GLenum glGetError() {
-    LOAD_GLES(glGetError);
     if (state.block.active) {
         return GL_INVALID_OPERATION;
     }
-    GLenum error = gles_glGetError();
+    GLenum error;
+    if (state.remote) {
+        remote_call(pack_glGetError(), &error);
+    } else {
+        LOAD_GLES(glGetError);
+        error = gles_glGetError();
+    }
     if (error == GL_NO_ERROR) {
         error = state.error;
     }


[src] update reference from RT ticket to TT ticket nr.

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

--- src/global.c
+++ src/global.c
@@ -242,7 +242,7 @@
     ASSERT_ARGS(internal_ns_maybe_create)
     PMC *sub_ns;

-    /* RT #46157 - stop depending on typed namespace */
+    /* TT #1220 - stop depending on typed namespace */
     if (!(flags & INTERN_NS_CREAT))
         return PMCNULL;


Namespaces 16 - cleanup

Namespaces 16 - cleanup

* remove more old code
* adjust API pod to new functionality

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

--- src/global.c
+++ src/global.c
@@ -29,15 +29,14 @@
 =item C<PMC *
 Parrot_find_global(Parrot_Interp interpreter, STRING *class, STRING *globalname)>

-If C<class> is NULL search global stash. If C<globalname> is NULL, return the
-stash PMC.
+If C<class> is NULL search global stash. XXX TODO search current ns.

 Return NULL if the global isn't found or the global.

 =item C<PMC *
 Parrot_get_global(Parrot_Interp interpreter, STRING *class, STRING *globalname)>

-If the global exists, return it. If not either throw an exception or return an
+If the global exists, return it. If not either throw an exception or return a
 C<Null> PMC depending on the interpreter's error settings.

 =cut
@@ -78,10 +77,8 @@
         case enum_class_String:
             return Parrot_find_global(interpreter, PMC_str_val(ns), name);
         case enum_class_Key:
-            /* TODO query the class namespace directly */
-            ns = VTABLE_get_pmc_keyed(interpreter,
-                    interpreter->stash_hash, ns);
-            if (!(ns))
+            ns = VTABLE_get_pmc_keyed(interpreter, interpreter->stash_hash, ns);
+            if (!ns)
                 return NULL;
             /* fall through */
         case enum_class_NameSpace:
@@ -95,7 +92,7 @@
         STRING *name, void *next)
 {
     PMC *g = Parrot_find_global(interpreter, class, name);
-    if (!PMC_IS_NULL(g))
+    if (g)
         return g;
     if (PARROT_ERRORS_test(interpreter, PARROT_ERRORS_GLOBALS_FLAG))  {
         real_exception(interpreter, next, E_NameError,
@@ -109,7 +106,7 @@
 Parrot_get_global_p(Parrot_Interp interpreter, PMC *ns, STRING *name)
 {
     PMC *g = Parrot_find_global_p(interpreter, ns, name);
-    if (!PMC_IS_NULL(g))
+    if (g)
         return g;
     if (PARROT_ERRORS_test(interpreter, PARROT_ERRORS_GLOBALS_FLAG))  {
         real_exception(interpreter, NULL, E_NameError,
@@ -264,24 +261,7 @@
                 names = PMC_str_val(namespace);
                 if (!string_length(interpreter, names))
                     goto global_ns;
-                /*
-                 * if the namespace is a class, call add_method
-                 * on that class PMC
-                 */
-                class_type = pmc_type(interpreter, names);
-                if (class_type > enum_type_undef) {
-                    PMC *class;
-                    VTABLE *vtable;
-                    vtable = Parrot_base_vtables[class_type];
-                    if (!vtable)
-                        internal_exception(1, "empty vtable '%Ss'", names);
-                    class = vtable->class;
-                    if (!class)
-                        internal_exception(1, "empty class '%Ss'", names);
-                    VTABLE_add_method(interpreter, class, sub_name, sub_pmc);
-                }
-                else
-                    Parrot_store_global(interpreter, names, sub_name, sub_pmc);
+                Parrot_store_global(interpreter, names, sub_name, sub_pmc);
                 break;
             case enum_class_Key:
                 part = namespace;


[cage] some refactor and nano-optimization in src/global.c, no functional changes

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

--- src/global.c
+++ src/global.c
@@ -110,6 +110,69 @@

 /*

+=item C<static PMC * internal_ns_keyed_str(PARROT_INTERP, PMC *base_ns, STRING
+*key, int flags)>
+
+Internal function to do keyed namespace lookup relative to a given namespace
+PMC.  Understands STRINGs.
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CAN_RETURN_NULL
+static PMC *
+internal_ns_keyed_str(PARROT_INTERP, ARGIN(PMC *base_ns),
+    ARGIN(STRING *key), int flags)
+{
+    ASSERT_ARGS(internal_ns_keyed_str)
+    PMC * const ns = VTABLE_get_pmc_keyed_str(interp, base_ns, key);
+
+    if (!PMC_IS_NULL(ns) && VTABLE_isa(interp, ns, CONST_STRING(interp, "NameSpace")))
+        return ns;
+
+    return internal_ns_maybe_create(interp, base_ns, key, flags);
+}
+
+/*
+
+=item C<static PMC * internal_ns_keyed_key(PARROT_INTERP, PMC *ns, PMC *key, int
+flags)>
+
+Internal function to do keyed namespace lookup relative to a given namespace
+PMC.  Understands Key PMCs.  Used from C<internal_ns_keyed>.
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CAN_RETURN_NULL
+static PMC *
+internal_ns_keyed_key(PARROT_INTERP, ARGIN(PMC *ns), ARGIN(PMC *key), int flags)
+{
+    ASSERT_ARGS(internal_ns_keyed_key)
+    while (key) {
+        STRING * const part = VTABLE_get_string(interp, key);
+        PMC    *sub_ns      = VTABLE_get_pmc_keyed_str(interp, ns, part);
+
+        if (PMC_IS_NULL(sub_ns) || !VTABLE_isa(interp, sub_ns, CONST_STRING(interp, "NameSpace"))) {
+            sub_ns = internal_ns_maybe_create(interp, ns, part, flags);
+
+            if (PMC_IS_NULL(sub_ns))
+                return PMCNULL;
+        }
+
+        ns  = sub_ns;
+        key = VTABLE_shift_pmc(interp, key);
+    }
+
+    return ns;
+}
+
+/*
+
 =item C<static PMC * internal_ns_keyed(PARROT_INTERP, PMC *base_ns, PMC
 *pmc_key, int flags)>

@@ -127,107 +190,39 @@
 internal_ns_keyed(PARROT_INTERP, ARGIN(PMC *base_ns), ARGIN(PMC *pmc_key), int flags)
 {
     ASSERT_ARGS(internal_ns_keyed)
-    PMC *ns = base_ns;
-    INTVAL i, n;

     if (VTABLE_isa(interp, pmc_key, CONST_STRING(interp, "String"))) {
         STRING * const str_key = VTABLE_get_string(interp, pmc_key);
         return internal_ns_keyed_str(interp, base_ns, str_key, flags);
     }
-
     else if (pmc_key->vtable->base_type == enum_class_Key)
         return internal_ns_keyed_key(interp, base_ns, pmc_key, flags);
-    else
-        n = VTABLE_elements(interp, pmc_key); /* array of strings */
-
-    for (i = 0; i < n; ++i) {
-        STRING *part;
-        PMC *sub_ns;
-
-        if (!pmc_key)
-            Parrot_ex_throw_from_c_args(interp, NULL, 1,
-                "Passed a NULL pmc_key into VTABLE_get_string_keyed_int");
-
-        part   = VTABLE_get_string_keyed_int(interp, pmc_key, i);
-        sub_ns = VTABLE_get_pmc_keyed_str(interp, ns, part);
-
-        if (PMC_IS_NULL(sub_ns) || !VTABLE_isa(interp, sub_ns, CONST_STRING(interp, "NameSpace"))) {
-            sub_ns = internal_ns_maybe_create(interp, ns, part, flags);
-
-            if (PMC_IS_NULL(sub_ns))
-                return PMCNULL;
+    else {
+        /* array of strings */
+        STRING * const isans = CONST_STRING(interp, "NameSpace");
+        const INTVAL n = VTABLE_elements(interp, pmc_key);
+        INTVAL i;
+        PMC *ns = base_ns;
+
+        for (i = 0; i < n; ++i) {
+            if (!pmc_key)
+                Parrot_ex_throw_from_c_args(interp, NULL, 1,
+                    "Passed a NULL pmc_key into VTABLE_get_string_keyed_int");
+            else {
+                STRING * const part = VTABLE_get_string_keyed_int(interp, pmc_key, i);
+                PMC *sub_ns = VTABLE_get_pmc_keyed_str(interp, ns, part);
+
+                if (PMC_IS_NULL(sub_ns) || !VTABLE_isa(interp, sub_ns, isans)) {
+                    sub_ns = internal_ns_maybe_create(interp, ns, part, flags);
+                    if (PMC_IS_NULL(sub_ns))
+                        return PMCNULL;
+                }
+                ns = sub_ns;
+            }
         }
-
-        ns = sub_ns;
+        return ns;
     }
-
-    return ns;
-}
-
-
-/*
-
-=item C<static PMC * internal_ns_keyed_str(PARROT_INTERP, PMC *base_ns, STRING
-*key, int flags)>
-
-Internal function to do keyed namespace lookup relative to a given namespace
-PMC.  Understands STRINGs.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CAN_RETURN_NULL
-static PMC *
-internal_ns_keyed_str(PARROT_INTERP, ARGIN(PMC *base_ns),
-    ARGIN(STRING *key), int flags)
-{
-    ASSERT_ARGS(internal_ns_keyed_str)
-    PMC * const ns = VTABLE_get_pmc_keyed_str(interp, base_ns, key);
-
-    if (!PMC_IS_NULL(ns) && VTABLE_isa(interp, ns, CONST_STRING(interp, "NameSpace")))
-        return ns;
-
-    return internal_ns_maybe_create(interp, base_ns, key, flags);
-}
-
-/*
-
-=item C<static PMC * internal_ns_keyed_key(PARROT_INTERP, PMC *ns, PMC *key, int
-flags)>
-
-Internal function to do keyed namespace lookup relative to a given namespace
-PMC.  Understands Key PMCs.  Used from C<internal_ns_keyed>.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CAN_RETURN_NULL
-static PMC *
-internal_ns_keyed_key(PARROT_INTERP, ARGIN(PMC *ns), ARGIN(PMC *key), int flags)
-{
-    ASSERT_ARGS(internal_ns_keyed_key)
-    while (key) {
-        STRING * const part = VTABLE_get_string(interp, key);
-        PMC    *sub_ns      = VTABLE_get_pmc_keyed_str(interp, ns, part);
-
-        if (PMC_IS_NULL(sub_ns) || !VTABLE_isa(interp, sub_ns, CONST_STRING(interp, "NameSpace"))) {
-            sub_ns = internal_ns_maybe_create(interp, ns, part, flags);
-
-            if (PMC_IS_NULL(sub_ns))
-                return PMCNULL;
-        }
-
-        ns  = sub_ns;
-        key = VTABLE_shift_pmc(interp, key);
-    }
-
-    return ns;
-}
-
+}

 /*


Handle Zip archives that are "multi-part archives with only
one part" by simply ignoring the marker at the beginning
of the file.  (Zip archivers reserve four bytes at the beginning
of each part of a multi-part archive, if it happens to only
require one part, those four bytes get filled with a placeholder
that can be ignored.)

Thanks to: Marius Nuennerich,
	 for pointing me to a Zip archive that libarchive couldn't handle
MFC after: 7 days

--- lib/libarchive/archive_read_support_format_zip.c
+++ lib/libarchive/archive_read_support_format_zip.c
@@ -180,7 +180,8 @@
 		if ((p[2] == '\001' && p[3] == '\002')
 		    || (p[2] == '\003' && p[3] == '\004')
 		    || (p[2] == '\005' && p[3] == '\006')
-		    || (p[2] == '\007' && p[3] == '\010'))
+		    || (p[2] == '\007' && p[3] == '\010')
+		    || (p[2] == '0' && p[3] == '0'))
 			return (30);
 	}
 	return (0);
@@ -212,6 +213,23 @@
 		archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
 		    "Bad ZIP file");
 		return (ARCHIVE_FATAL);
+	}
+
+	/*
+	 * "PK00" signature is used for "split" archives that
+	 * only have a single segment.  This means we can just
+	 * skip the PK00; the first real file header should follow.
+	 */
+	if (signature[2] == '0' && signature[3] == '0') {
+		(a->decompressor->consume)(a, 4);
+		if ((h = __archive_read_ahead(a, 4)) == NULL)
+			return (ARCHIVE_FATAL);
+		signature = (const char *)h;
+		if (signature[0] != 'P' || signature[1] != 'K') {
+			archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+			    "Bad ZIP file");
+			return (ARCHIVE_FATAL);
+		}
 	}

 	if (signature[2] == '\001' && signature[3] == '\002') {


[PATCH] selinux: Fix MLS compatibility off-by-one bug

Fix an off-by-one error in the MLS compatibility code that was causing
contexts with a MLS suffix to be rejected, preventing sharing partitions
between FC4 and FC5.  Bug reported in

   https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=188068

Signed-off-by: Stephen Smalley <d6e1285e1c84d3d5885c2124fdacc780e9fc0a94@tycho.nsa.gov>
Acked-by: James Morris <10d11de3abc355eabe955bb734f0f8e71da56e16@redhat.com>
Cc: <4fbacc2fa0ffdbb11bf1ad6925b886ebd08dd15f@kernel.org>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@osdl.org>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@osdl.org>

--- security/selinux/ss/mls.c
+++ security/selinux/ss/mls.c
@@ -264,7 +264,7 @@

 	if (!selinux_mls_enabled) {
 		if (def_sid != SECSID_NULL && oldc)
-			*scontext += strlen(*scontext);
+			*scontext += strlen(*scontext)+1;
 		return 0;
 	}


Tegra: memctrl_v2: fix "overflow before widen" coverity issue

This patch fixes a coding error, where the size of the protected memory area
was truncated due to an incorrect typecast.

This defect was found by coverity and reported as CID 336781.

Change-Id: I41878b0a9a5e5cd78ef3393fdc7b9ea7f7403ed3
Signed-off-by: Varun Wadekar <517ae08f01cae398dbba5bef5ba1750f384c6daf@nvidia.com>

--- plat/nvidia/tegra/common/drivers/memctrl/memctrl_v2.c
+++ plat/nvidia/tegra/common/drivers/memctrl/memctrl_v2.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2019, NVIDIA Corporation. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -360,17 +361,15 @@

 	if ((phys_base > vmem_end_old) || (video_mem_base > vmem_end_new)) {
 		tegra_clear_videomem(video_mem_base,
-				     (uint32_t)video_mem_size_mb << 20U);
+				     video_mem_size_mb << 20U);
 	} else {
 		if (video_mem_base < phys_base) {
 			non_overlap_area_size = phys_base - video_mem_base;
-			tegra_clear_videomem(video_mem_base,
-					(uint32_t)non_overlap_area_size);
+			tegra_clear_videomem(video_mem_base, non_overlap_area_size);
 		}
 		if (vmem_end_old > vmem_end_new) {
 			non_overlap_area_size = vmem_end_old - vmem_end_new;
-			tegra_clear_videomem(vmem_end_new,
-					(uint32_t)non_overlap_area_size);
+			tegra_clear_videomem(vmem_end_new, non_overlap_area_size);
 		}
 	}


Fix CoeffReadCost of products to handle Dynamic costs


AmazonMp3.Store: Update server to handle amazon.ca

There is no MP3 store for Amazon.ca yet, so we have Home and Search use
the normal Music store.

--- src/Extensions/Banshee.AmazonMp3.Store/server/redirect.c
+++ src/Extensions/Banshee.AmazonMp3.Store/server/redirect.c
@@ -45,6 +45,7 @@
     gchar *input;
     gchar *domain;
     gchar *affiliate_code;
+    gchar *home_path, *search_category;
     gchar *p;
     gchar *dest_url = NULL;
     gboolean direct_url = FALSE;
@@ -52,6 +53,8 @@
     country = NULL;
     input = NULL;
     action = NULL;
+    home_path = "mp3";
+    search_category = "digital-music";

     remote_addr = g_getenv ("REMOTE_ADDR");

@@ -94,22 +97,35 @@
     } else if (strcmp (country, "JP") == 0) {
         domain = "co.jp";
         affiliate_code = "banshee-jp-22";
+    } else if (strcmp (country, "CA") == 0) {
+        domain = "ca";
+        affiliate_code = "banshee-ca-20";
+        // Amazon.ca doesn't have an MP3 store (yet), so
+        // adjust Home and Search to use the general music section
+        home_path = "music";
+        search_category = "popular";
     } else {
         domain = "com";
         affiliate_code = "banshee-20";
     }

     if (strcmp (action, "search") == 0) {
-        dest_url = g_strdup_printf ("http://www.amazon.%s/s/ref=nb_sb_noss?url=search-alias%%3Ddigital-music&field-keywords=%s", domain, input);
+        dest_url = g_strdup_printf (
+            "http://www.amazon.%s/s/ref=nb_sb_noss?url=search-alias%%3D%s&field-keywords=%s",
+            domain, search_category, input
+        );
     } else if (strcmp (action, "sign_out") == 0) {
-        dest_url = g_strdup_printf ("http://www.amazon.%s/gp/help/customer/sign-out.html/ref=ya__lo?ie=UTF8&returnPath=%%2Fmp3", domain);
+        dest_url = g_strdup_printf (
+            "http://www.amazon.%s/gp/help/customer/sign-out.html/ref=ya__lo?ie=UTF8&returnPath=%%2F%s",
+            domain, home_path
+        );
     } else if (strcmp (action, "about") == 0) {
         dest_url = g_strdup ("http://banshee.fm/about/revenue/");
         direct_url = TRUE;
     }

     if (dest_url == NULL) {
-        dest_url = g_strdup_printf ("http://www.amazon.%s/mp3", domain);
+        dest_url = g_strdup_printf ("http://www.amazon.%s/%s", domain, home_path);
     }

     if (direct_url) {


* subversion/libsvn_wc/wc_db_update_move.c
  (tc_editor_alter_file): Rename original_repos_relpath to
   move_dst_repos_relpath for cosmetic reasons.

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

--- subversion/libsvn_wc/wc_db_update_move.c
+++ subversion/libsvn_wc/wc_db_update_move.c
@@ -133,13 +133,13 @@
 {
   struct tc_editor_baton *b = baton;
   const svn_checksum_t *move_dst_checksum;
-  const char *original_repos_relpath;
+  const char *move_dst_repos_relpath;
   svn_revnum_t move_dst_revision;
   svn_kind_t kind;

   /* Get kind, revision, and checksum of the moved-here node. */
   SVN_ERR(svn_wc__db_depth_get_info(NULL, &kind, &move_dst_revision,
-                                    &original_repos_relpath, NULL, NULL, NULL,
+                                    &move_dst_repos_relpath, NULL, NULL, NULL,
                                     NULL, NULL, &move_dst_checksum, NULL,
                                     NULL, b->wcroot, dst_relpath,
                                     relpath_depth(b->move_root_dst_relpath),
@@ -198,7 +198,7 @@
             {
               original_version = svn_wc_conflict_version_dup(b->old_version,
                                                              scratch_pool);
-              original_version->path_in_repos = original_repos_relpath;
+              original_version->path_in_repos = move_dst_repos_relpath;
               original_version->node_kind = svn_node_file;
               SVN_ERR(svn_wc__conflict_skel_set_op_update(conflict_skel,
                                                           original_version,


The is_content_filtered parameter of the ViewHostMsg_FrameNavigate_Params was not serialized/deserialized.

BUG=2742 (partially)
Review URL: http://codereview.chromium.org/7351

git-svn-id: dd90618784b6a4b323ea0c23a071cb1c9e6f2ac7@3395 4ff67af0-8c30-449e-8e8b-ad334ec8d88c

--- chrome/common/render_messages.h
+++ chrome/common/render_messages.h
@@ -835,6 +835,7 @@
     WriteParam(m, p.gesture);
     WriteParam(m, p.contents_mime_type);
     WriteParam(m, p.is_post);
+    WriteParam(m, p.is_content_filtered);
   }
   static bool Read(const Message* m, void** iter, param_type* p) {
     return
@@ -851,7 +852,8 @@
       ReadParam(m, iter, &p->security_info) &&
       ReadParam(m, iter, &p->gesture) &&
       ReadParam(m, iter, &p->contents_mime_type) &&
-      ReadParam(m, iter, &p->is_post);
+      ReadParam(m, iter, &p->is_post) &&
+      ReadParam(m, iter, &p->is_content_filtered);
   }
   static void Log(const param_type& p, std::wstring* l) {
     l->append(L"(");
@@ -882,6 +884,8 @@
     LogParam(p.contents_mime_type, l);
     l->append(L", ");
     LogParam(p.is_post, l);
+    l->append(L", ");
+    LogParam(p.is_content_filtered, l);
     l->append(L")");
   }
 };


Prevent infinite recursion

Prevent infinite recursion

Systemd units tree can contain cycles in it, which causes
infinite recursion in our probe.

We will save processed units in a hash table and if we meet
an unit that is already processed we won't process it again.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1478285
See comment 11 in this BZ for a reproducer.

--- src/OVAL/probes/unix/linux/systemdunitdependency_probe.c
+++ src/OVAL/probes/unix/linux/systemdunitdependency_probe.c
@@ -135,14 +135,19 @@
 	return strncmp(unit + len - suffix_len, suffix, suffix_len) == 0;
 }

-static int add_unit_dependency(const char *dependency, SEXP_t *item)
-{
+static int add_unit_dependency(const char *dependency, SEXP_t *item, struct oscap_htable *visited_units)
+{
+	if (oscap_htable_get(visited_units, dependency) != NULL) {
+		return 1;
+	}
+	oscap_htable_add(visited_units, dependency, (void *) true);
 	SEXP_t *se_dependency = SEXP_string_new(dependency, strlen(dependency));
 	probe_item_ent_add(item, "dependency", NULL, se_dependency);
+	SEXP_free(se_dependency);
 	return 0;
 }

-static void get_all_dependencies_by_unit(DBusConnection *conn, const char *unit, SEXP_t *item)
+static void get_all_dependencies_by_unit(DBusConnection *conn, const char *unit, SEXP_t *item, struct oscap_htable *visited_units)
 {
 	if (!unit || strcmp(unit, "(null)") == 0)
 		return;
@@ -160,8 +165,8 @@
 			if (oscap_strcmp(requires[i], "") == 0)
 				continue;

-			if (add_unit_dependency(requires[i], item) == 0) {
-				get_all_dependencies_by_unit(conn, requires[i], item);
+			if (add_unit_dependency(requires[i], item, visited_units) == 0) {
+				get_all_dependencies_by_unit(conn, requires[i], item, visited_units);
 			}
 		}
 		free(requires);
@@ -176,8 +181,8 @@
 			if (oscap_strcmp(wants[i], "") == 0)
 				continue;

-			if (add_unit_dependency(wants[i], item) == 0) {
-				get_all_dependencies_by_unit(conn, wants[i], item);
+			if (add_unit_dependency(wants[i], item, visited_units) == 0) {
+				get_all_dependencies_by_unit(conn, wants[i], item, visited_units);
 			}
 		}
 		free(wants);
@@ -202,7 +207,9 @@
 					 "unit", OVAL_DATATYPE_SEXP, se_unit,
 					 NULL);

-	get_all_dependencies_by_unit(vars->dbus_conn, unit, item);
+	struct oscap_htable *visited_units = oscap_htable_new();
+	get_all_dependencies_by_unit(vars->dbus_conn, unit, item, visited_units);
+	oscap_htable_free(visited_units, NULL);

 	probe_item_collect(vars->ctx, item);
 	SEXP_free(se_unit);


* subversion/tests/libsvn_subr/path-test.c (test_uri_from_iri): Change
  array initialisers to use character constants instead of integers.
  This avoids warnings about value narrowing on Windows.

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


Fixed the error messages in pack_arrays so I knew which one was blowing up for Quake III

--- packer/pack_arrays.c
+++ packer/pack_arrays.c
@@ -11,7 +11,7 @@
 	UNUSED( type );
 	UNUSED( stride );
 	UNUSED( pointer );
-	crError( "Unimplemented Vertex Array Pack Function called!" );
+	crError( "Unimplemented crPackVertexPointer!" );
 }

 void PACK_APIENTRY crPackColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
@@ -20,7 +20,7 @@
 	UNUSED( type );
 	UNUSED( stride );
 	UNUSED( pointer );
-	crError( "Unimplemented Vertex Array Pack Function called!" );
+	crError( "Unimplemented crPackColorPointer!" );
 }

 void PACK_APIENTRY crPackNormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer )
@@ -28,7 +28,7 @@
 	UNUSED( type );
 	UNUSED( stride );
 	UNUSED( pointer );
-	crError( "Unimplemented Vertex Array Pack Function called!" );
+	crError( "Unimplemented crPackNormalPointer!" );
 }

 void PACK_APIENTRY crPackTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
@@ -37,14 +37,14 @@
 	UNUSED( type );
 	UNUSED( stride );
 	UNUSED( pointer );
-	crError( "Unimplemented Vertex Array Pack Function called!" );
+	crError( "Unimplemented crPackTexCoordPointer!" );
 }

 void PACK_APIENTRY crPackEdgeFlagPointer( GLsizei stride, const GLvoid *pointer )
 {
 	UNUSED( stride );
 	UNUSED( pointer );
-	crError( "Unimplemented Vertex Array Pack Function called!" );
+	crError( "Unimplemented crPackEdgeFlagPointer!" );
 }

 void PACK_APIENTRY crPackIndexPointer( GLenum type, GLsizei stride, const GLvoid *pointer )
@@ -52,7 +52,7 @@
 	UNUSED( type );
 	UNUSED( stride );
 	UNUSED( pointer );
-	crError( "Unimplemented Vertex Array Pack Function called!" );
+	crError( "Unimplemented crPackIndexPointer!" );
 }

 void PACK_APIENTRY crPackDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices )
@@ -61,5 +61,5 @@
 	UNUSED( count );
 	UNUSED( type );
 	UNUSED( indices );
-	crError( "Unimplemented DrawElements called!" );
+	crError( "Unimplemented crPackDrawElements!" );
 }


Bluetooth: Audio: Media - refactor include discovery start

Move the start of discovery of included services to a separate
function, in preparation for rewriting discovery.

Signed-off-by: Asbjørn Sæbø <79238bdce2d54e50328756ad5a8d04b51bb621fe@nordicsemi.no>

--- subsys/bluetooth/audio/mcc.c
+++ subsys/bluetooth/audio/mcc.c
@@ -1193,8 +1193,27 @@
 	}
 	return BT_GATT_ITER_STOP;
 }
+
+/* Start discovery of included services */
+static void discover_included(struct bt_conn *conn)
+{
+	int err;
+
+	discover_params.start_handle = cur_mcs_inst->start_handle;
+	discover_params.end_handle = cur_mcs_inst->end_handle;
+	discover_params.type = BT_GATT_DISCOVER_INCLUDE;
+	discover_params.func = discover_include_func;
+
+	BT_DBG("Start discovery of included services");
+	err = bt_gatt_discover(conn, &discover_params);
+	if (err) {
+		BT_DBG("Discover of included service failed (err %d)", err);
+		if (mcc_cb && mcc_cb->discover_mcs) {
+			mcc_cb->discover_mcs(conn, err);
+		}
+	}
+}
 #endif /* CONFIG_BT_MCC_OTS */
-

 /* This function is called when characteristics are found.
  * The function will store handles, and optionally subscribe to, GMCS
@@ -1207,7 +1226,6 @@
 {
 	struct bt_gatt_chrc *chrc;
 	struct bt_gatt_subscribe_params *sub_params = NULL;
-	int err = 0;

 	if (attr) {
 		/* Found an attribute */
@@ -1354,20 +1372,8 @@

 #ifdef CONFIG_BT_MCC_OTS

-	/* Discover included services */
-	discover_params.start_handle = cur_mcs_inst->start_handle;
-	discover_params.end_handle = cur_mcs_inst->end_handle;
-	discover_params.type = BT_GATT_DISCOVER_INCLUDE;
-	discover_params.func = discover_include_func;
-
-	BT_DBG("Start discovery of included services");
-	err = bt_gatt_discover(conn, &discover_params);
-	if (err) {
-		BT_DBG("Discover of included service failed (err %d)", err);
-		if (mcc_cb && mcc_cb->discover_mcs) {
-			mcc_cb->discover_mcs(conn, err);
-		}
-	}
+	/* Start discovery of included services to find OTS */
+	discover_included(conn);

 #else


net: dns: Fix end-of-results callback on error

Callers of dns_get_addr_info() depends on receiving an end-of-results
callback (where 'info' is NULL) when finished. Do this on failure in
cb_recv() instead of pointing to an empty object.

This fix will avoid a deadlock situation in getaddrinfo().

A reply code other than "no error" in the DNS response is a typical
case when the lookup failed and this occurs.

Moved "struct dns_addrinfo info" variable from cb_recv() to dns_read()
because it was now unused in cb_recv().

Adding tests for this requires network access and a DNS server,
or a mechanism for generating a DNS response with a reply code.

Signed-off-by: Stig Bjørlykke <ea07fa156e332ba20900aa10589adbee8ec38deb@nordicsemi.no>

--- subsys/net/lib/dns/resolve.c
+++ subsys/net/lib/dns/resolve.c
@@ -265,9 +265,9 @@
 		    struct net_pkt *pkt,
 		    struct net_buf *dns_data,
 		    u16_t *dns_id,
-		    struct net_buf *dns_cname,
-		    struct dns_addrinfo *info)
-{
+		    struct net_buf *dns_cname)
+{
+	struct dns_addrinfo info = { 0 };
 	/* Helper struct to track the dns msg received from the server */
 	struct dns_msg_t dns_msg;
 	u32_t ttl; /* RR ttl, so far it is not passed to caller */
@@ -333,10 +333,10 @@

 	if (ctx->queries[query_idx].query_type == DNS_QUERY_TYPE_A) {
 		address_size = DNS_IPV4_LEN;
-		addr = (u8_t *)&net_sin(&info->ai_addr)->sin_addr;
-		info->ai_family = AF_INET;
-		info->ai_addr.sa_family = AF_INET;
-		info->ai_addrlen = sizeof(struct sockaddr_in);
+		addr = (u8_t *)&net_sin(&info.ai_addr)->sin_addr;
+		info.ai_family = AF_INET;
+		info.ai_addr.sa_family = AF_INET;
+		info.ai_addrlen = sizeof(struct sockaddr_in);
 	} else if (ctx->queries[query_idx].query_type == DNS_QUERY_TYPE_AAAA) {
 		/* We cannot resolve IPv6 address if IPv6 is disabled. The reason
 		 * being that "struct sockaddr" does not have enough space for
@@ -344,10 +344,10 @@
 		 */
 #if defined(CONFIG_NET_IPV6)
 		address_size = DNS_IPV6_LEN;
-		addr = (u8_t *)&net_sin6(&info->ai_addr)->sin6_addr;
-		info->ai_family = AF_INET6;
-		info->ai_addr.sa_family = AF_INET6;
-		info->ai_addrlen = sizeof(struct sockaddr_in6);
+		addr = (u8_t *)&net_sin6(&info.ai_addr)->sin6_addr;
+		info.ai_family = AF_INET6;
+		info.ai_addr.sa_family = AF_INET6;
+		info.ai_addrlen = sizeof(struct sockaddr_in6);
 #else
 		ret = DNS_EAI_FAMILY;
 		goto quit;
@@ -380,7 +380,7 @@

 			memcpy(addr, src, address_size);

-			ctx->queries[query_idx].cb(DNS_EAI_INPROGRESS, info,
+			ctx->queries[query_idx].cb(DNS_EAI_INPROGRESS, &info,
 					ctx->queries[query_idx].user_data);
 			items++;
 			break;
@@ -429,14 +429,13 @@
 		ret = DNS_EAI_ALLDONE;
 	}

+	if (k_delayed_work_remaining_get(&ctx->queries[query_idx].timer) > 0) {
+		k_delayed_work_cancel(&ctx->queries[query_idx].timer);
+	}
+
 	/* Marks the end of the results */
 	ctx->queries[query_idx].cb(ret, NULL,
 				   ctx->queries[query_idx].user_data);
-
-	if (k_delayed_work_remaining_get(&ctx->queries[query_idx].timer) > 0) {
-		k_delayed_work_cancel(&ctx->queries[query_idx].timer);
-	}
-
 	ctx->queries[query_idx].cb = NULL;

 	net_pkt_unref(pkt);
@@ -458,7 +457,6 @@
 		    void *user_data)
 {
 	struct dns_resolve_context *ctx = user_data;
-	struct dns_addrinfo info = { 0 };
 	struct net_buf *dns_cname = NULL;
 	struct net_buf *dns_data = NULL;
 	u16_t dns_id = 0;
@@ -483,7 +481,7 @@
 		goto quit;
 	}

-	ret = dns_read(ctx, pkt, dns_data, &dns_id, dns_cname, &info);
+	ret = dns_read(ctx, pkt, dns_data, &dns_id, dns_cname);
 	if (!ret) {
 		/* We called the callback already in dns_read() if there
 		 * was no errors.
@@ -534,7 +532,8 @@
 		k_delayed_work_cancel(&ctx->queries[i].timer);
 	}

-	ctx->queries[i].cb(ret, &info, ctx->queries[i].user_data);
+	/* Marks the end of the results */
+	ctx->queries[i].cb(ret, NULL, ctx->queries[i].user_data);
 	ctx->queries[i].cb = NULL;

 free_buf:


Fixed bug where one bad publish would stop all publishing.

--- services/telemetry/telemetry-linux/source/server.c
+++ services/telemetry/telemetry-linux/source/server.c
@@ -177,7 +177,6 @@
             {
                 printf("Failed to publish to %d\r\n", current->id);
                 ret = false;
-                break;
             }
         }
     }


tidy

tidy

git-svn-id: f2acecaac6fbd5a03f3d4799db58dda434111981@23891 3eda493b-6a19-0410-b2e0-ec8ea4dd8fda

--- pfl/timerthr.c
+++ pfl/timerthr.c
@@ -22,12 +22,12 @@

 #include <unistd.h>

+#include "pfl/atomic.h"
 #include "pfl/cdefs.h"
+#include "pfl/iostats.h"
 #include "pfl/lockedlist.h"
+#include "pfl/thread.h"
 #include "pfl/time.h"
-#include "pfl/atomic.h"
-#include "pfl/iostats.h"
-#include "pfl/thread.h"

 #define psc_timercmp_addsec(tvp, s, uvp, cmp)				\
 	(((tvp)->tv_sec + (s) == (uvp)->tv_sec) ?			\


* subversion/include/svn_opt.h   (svn_opt_parse_revprop): Follow-up to r29492: note this is new in 1.6.

--- subversion/include/svn_opt.h
+++ subversion/include/svn_opt.h
@@ -544,6 +544,8 @@
  * @c NULL, allocate a new apr_hash_t in it.  @a revprops maps
  * const char * revprop names to svn_string_t * revprop values for use
  * with svn_repos_get_commit_editor5 and other get_commit_editor APIs.
+ *
+ * @since New in 1.6.
  */
 svn_error_t *
 svn_opt_parse_revprop(apr_hash_t **revprops, const char *revprop_spec,


No functional change.

No functional change.

* subversion/libsvn_wc/merge.c
  (svn_wc__internal_merge): Make a temporary parameter rename permanent.

--- subversion/libsvn_wc/merge.c
+++ subversion/libsvn_wc/merge.c
@@ -1321,7 +1321,6 @@
                        apr_pool_t *result_pool,
                        apr_pool_t *scratch_pool)
 {
-  apr_pool_t *pool = scratch_pool;  /* ### temporary rename  */
   const char *detranslated_target_abspath;
   svn_boolean_t is_binary = FALSE;
   const svn_prop_t *mimeprop;
@@ -1358,13 +1357,15 @@
   SVN_ERR(detranslate_wc_file(&detranslated_target_abspath, &mt,
                               (! is_binary) && diff3_cmd != NULL,
                               target_abspath,
-                              cancel_func, cancel_baton, pool, pool));
+                              cancel_func, cancel_baton,
+                              scratch_pool, scratch_pool));

   /* We cannot depend on the left file to contain the same eols as the
      right file. If the merge target has mods, this will mark the entire
      file as conflicted, so we need to compensate. */
   SVN_ERR(maybe_update_target_eols(&left_abspath, &mt, left_abspath,
-                                   cancel_func, cancel_baton, pool, pool));
+                                   cancel_func, cancel_baton,
+                                   scratch_pool, scratch_pool));

   if (is_binary)
     {


cros: build fix

cros: build fix

BUG=none
TEST=none
TBR=dpolukhin

Review URL: http://codereview.chromium.org/7034001

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@85440 0039d316-1c4b-4281-b951-d872f2087c98

--- chrome/browser/chromeos/login/mock_login_status_consumer.h
+++ chrome/browser/chromeos/login/mock_login_status_consumer.h
@@ -6,6 +6,7 @@
 #define CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_LOGIN_STATUS_CONSUMER_H_
 #pragma once

+#include "base/message_loop.h"
 #include "chrome/browser/chromeos/login/login_status_consumer.h"
 #include "chrome/common/net/gaia/gaia_auth_consumer.h"
 #include "testing/gmock/include/gmock/gmock.h"


* subversion/libsvn_wc/wc_db.c:
  (count_children, union_children, single_table_children,
      gather_children): add docstrings as a followup to r952493.

Suggested by: julianfoad

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

--- subversion/libsvn_wc/wc_db.c
+++ subversion/libsvn_wc/wc_db.c
@@ -830,6 +830,8 @@
 }

+/* Return the number of children under PARENT_RELPATH in the given WC_ID.
+   The table is implicitly defined by the STMT_IDX query.  */
 static svn_error_t *
 count_children(int *count,
                int stmt_idx,
@@ -877,6 +879,9 @@
 }

+/* When children of PARENT_RELPATH are in both BASE_NODE and WORKING_NODE,
+   this function can be used to union those two sets, returning the set
+   in *CHILDREN (allocated in RESULT_POOL).  */
 static svn_error_t *
 union_children(const apr_array_header_t **children,
                svn_sqlite__db_t *sdb,
@@ -902,6 +907,13 @@
 }

+/* Return all the children of PARENT_RELPATH from a single table, implicitly
+   defined by STMT_IDX. If the caller happens to know the count of children,
+   it should be passed as START_SIZE to pre-allocate space in the *CHILDREN
+   return value.
+
+   If the caller doesn't know the count, then it should pass a reasonable
+   idea of how many children may be present.  */
 static svn_error_t *
 single_table_children(const apr_array_header_t **children,
                       int stmt_idx,
@@ -939,7 +951,10 @@
 }

-/* */
+/* Return in *CHILDREN all of the children of the directory LOCAL_ABSPATH.
+   If BASE_ONLY is true, then *only* the children from BASE_NODE are
+   returned (those in WORKING_NODE are ignored). The result children are
+   allocated in RESULT_POOl.  */
 static svn_error_t *
 gather_children(const apr_array_header_t **children,
                 svn_boolean_t base_only,


Implement serial database restores for PG 9.3 and 9.4

Earlier all the BlockReader processes restored buffers in parallel, and
this may cause random-read contention on disks, and may lead to poor
restore performance.

With this commit the BlockReader processes will queue behind each other
and take turns to restore their databases.

For Postgres 9.3 this is implemented using LWLocks, and for version 9.4
the Dynamic Background Worker infrastructure is used.

A new boolean GUC parameter pg_hibernator.parallel is introduced to
reverse this behaviour. This parameter defaults to false.

--- pg_hibernate.c
+++ pg_hibernate.c
@@ -27,10 +27,22 @@
 #include "storage/fd.h"
 #include "storage/relfilenode.h"
 #include "utils/guc.h"
+#include "utils/memutils.h"
 #include "utils/snapmgr.h"
 #include "utils/rel.h"

 PG_MODULE_MAGIC;
+
+#if PG_VERSION_NUM == 90300
+typedef SharedState
+{
+	LWLockId	lock;
+} SharedState;
+static void		SharedStateSetup(void);
+static void		shmem_startup();
+static shmem_startup_hook_type prev_shmem_startup_hook = NULL;
+static SharedState *shared_mem = NULL;
+#endif

 typedef struct SavedBuffer
 {
@@ -50,8 +62,8 @@
 static void		DefineGUCs(void);
 static void		CreateDirectory(void);

-static void		CreateWorkers(void);
-static void		CreateWorker(int id);
+static void		RegisterBlockReaders(void);
+static bool		RegisterWorker(int id, void **handle);

 static void		BlockReaderMain(Datum main_arg);
 static void		ReadBlocks(int filenum, char *dbname);
@@ -62,6 +74,10 @@
 /* Secondary/supporting functions */
 static void		sigtermHandler(SIGNAL_ARGS);
 static void		sighupHandler(SIGNAL_ARGS);
+
+#if PG_VERSION_NUM >= 90400
+static void		addPendingWorker(int filenum);
+#endif

 static void		WorkerCommon(void);
 static int		SavedBufferCmp(const void *a, const void *b);
@@ -83,8 +99,9 @@
 static volatile sig_atomic_t got_sigterm = false;

 /* GUC variables */
-static bool		hibernate_enabled = true;
-static char*	default_database = "postgres";
+static bool		guc_enabled = true;					/* Is the extension enabled? */
+static bool		guc_parallel_enabled = false;		/* Can we restore databases in parallel? */
+static char*	guc_default_database = "postgres";	/* Default DB to connect to. */

 /*
  * Signal handler for SIGTERM
@@ -122,10 +139,75 @@
 void
 _PG_init(void)
 {
+#if PG_VERSION_NUM == 90300
+	SharedStateSetup();
+#endif
 	DefineGUCs();
 	CreateDirectory();
-	CreateWorkers();
-}
+	/*
+	 * Create the BufferSaver irrespective of whether the extension is enabled.
+	 * The BufferSaver will check the parameter when it receives SIGTERM, and act
+	 * accordingly. This way the user can start the server with the extension
+	 * disabled (pg_hibernator.enabled=false), enable the extension while
+	 * server is running, and expect the save-files to be created when the server
+	 * shuts down.
+	 */
+	 /* Register the BufferSaver worker */
+	RegisterWorker(0, NULL);
+
+#if PG_VERSION_NUM >= 90400
+	/*
+	 * In Postgres version 9.4 and above, we use the dynamic background worker
+	 * infrastructure for BlockReaders, and the BufferSaver process does the
+	 * legwork of registering the BlockReader workers.
+	 */
+#else	/* PG_VERSION_NUM == 90300 */
+
+	/*
+	 * In Postgres 9.3 we use regular workers for BlockReader processes, and
+	 * they are registered right here.
+	 */
+
+	RegisterBlockReaders(); /* Register the BlockReader worker processes */
+#endif
+}
+
+#if PG_VERSION_NUM == 90300
+static void
+SharedStateSetup()
+{
+	/* Request one LWLock */
+	RequestAddinLWLocks(1);
+
+	/* Register our hook for Shared Memory initialization */
+    prev_shmem_startup_hook = shmem_startup_hook;
+    shmem_startup_hook = shmem_startup;
+}
+
+static void
+shmem_startup()
+{
+	bool found;
+
+    /* reset in case this is a restart within the postmaster */
+    shared_mem = NULL;
+
+	if (prev_shmem_startup_hook)
+		prev_shmem_startup_hook();
+
+    LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
+	shared_mem = ShmemInitStruct("pg_hibernator",
+                           sizeof(SharedState),
+                           &found);
+    if (!found)
+    {
+        /* First time through */
+        shared_mem->lock = LWLockAssign();
+    }
+
+    LWLockRelease(AddinShmemInitLock);
+}
+#endif

 /* Declare the parameters */
 static void
@@ -134,19 +216,30 @@
 	DefineCustomBoolVariable("pg_hibernator.enabled",
 							"Enable/disable automatic hibernation.",
 							NULL,
-							&hibernate_enabled,
-							true,
+							&guc_enabled,
+							guc_enabled,
 							PGC_SIGHUP,
 							0,
 							NULL,
 							NULL,
 							NULL);

+	DefineCustomBoolVariable("pg_hibernator.parallel",
+							"Enable/disable restoring databases in parallel.",
+							NULL,
+							&guc_parallel_enabled,
+							guc_parallel_enabled,
+							PGC_SIGHUP,
+							0,
+							NULL,
+							NULL,
+							NULL);
+
 	DefineCustomStringVariable("pg_hibernator.default_database",
 							"Database to connect to, by default.",
 							"Postgres Hibernator will connect to this database when saving buffers, and when reading blocks of global objects.",
-							&default_database,
-							default_database,
+							&guc_default_database,
+							guc_default_database,
 							PGC_POSTMASTER,
 							0,
 							NULL,
@@ -192,28 +285,15 @@
 	/* XXX: Should we make sure we have write permissions on this directory? */
 }

-/*
- * Register the BufferSaver and BlockReader worker processes.
- */
-static void
-CreateWorkers(void)
+static void
+RegisterBlockReaders(void)
 {
 	DIR			   *dir;
 	const char	   *hibernate_dir;
 	struct dirent   *dent;

-	/*
-	 * Create the BufferSaver irrespective of whether the extension is enabled.
-	 * The BufferSaver will check the parameter when it receives SIGTERM, and act
-	 * accordingly. This way the user can start the server with the extension
-	 * disabled (pg_hibernator.enabled=false), enable the extension while
-	 * server is running, and expect the save-files to be created when the server
-	 * shuts down.
-	 */
-	CreateWorker(0);	/* Create the BufferSaver worker */
-
 	/* Don't create BlockReaders if the extension is disabled. */
-	if (!hibernate_enabled)
+	if (!guc_enabled)
 		return;

 	hibernate_dir = SAVE_LOCATION;
@@ -234,7 +314,11 @@
 		if (!parseSavefileName(dent->d_name, &filenum, dbname))
 			continue;

-		CreateWorker(filenum);
+#if PG_VERSION_NUM >= 90400
+		addPendingWorker(filenum);
+#else	/* PG_VERSION_NUM == 90300 */
+		RegisterWorker(filenum, NULL);
+#endif
 	}

 	if (errno != 0)
@@ -245,8 +329,68 @@
 	closedir(dir);
 }

-static void
-CreateWorker(int id)
+#if PG_VERSION_NUM >= 90400
+
+/* Used by BufferSaver */
+static List *pendingWorkers = NIL;
+
+static void
+addPendingWorker(int filenum)
+{
+	MemoryContext oldContext = MemoryContextSwitchTo(TopMemoryContext);
+
+	pendingWorkers = lappend_int(pendingWorkers, filenum);
+
+	MemoryContextSwitchTo(oldContext);
+}
+
+static void
+processOnePendingWorker()
+{
+	static BackgroundWorkerHandle *last_worker = NULL;
+
+	/* Nothing to do if the list is empty. */
+	if (list_length(pendingWorkers) == 0)
+		return;
+
+	if (last_worker != NULL)
+	{
+		pid_t pid;
+		BgwHandleStatus status = GetBackgroundWorkerPid(last_worker, &pid);
+
+		switch (status)
+		{
+			case BGWH_STARTED:
+			case BGWH_NOT_YET_STARTED:
+				/* Do nothing if parallelism is disabled */
+				if (!guc_parallel_enabled)
+					return;
+
+				/* Fall through */
+			case BGWH_STOPPED:
+				last_worker = NULL;
+				break;
+			default:
+				Assert(false);
+				break;
+		}
+	}
+
+	if (!RegisterWorker(linitial_int(pendingWorkers), (void**) &last_worker))
+		return;
+
+	/* Remove the element from pending list iff we could register a worker successfully. */
+	pendingWorkers = list_delete_first(pendingWorkers);
+}
+
+#endif
+
+/*
+ * The second parameter is declared void** because the type BackgroundWorkerHandle
+ * is not available in Postgres 9.3.
+ */
+static bool
+RegisterWorker(int id, void **handle)
 {
 	BackgroundWorker	worker;

@@ -277,7 +421,16 @@

 	worker.bgw_main_arg = Int32GetDatum(id);

+#if PG_VERSION_NUM >= 90400
+	return RegisterDynamicBackgroundWorker(&worker, (BackgroundWorkerHandle**) handle);
+#else
+	/*
+	 * This API is deficient as it can't report failure; it just does an
+	 * ereport(LOG) on failure.
+	 */
 	RegisterBackgroundWorker(&worker);
+	return true;
+#endif
 }

 static void
@@ -340,7 +493,19 @@
 	closedir(dir);

 	/* We found the file we're supposed to restore. */
+
+#if PG_VERSION_NUM == 90300
+	/* If parallelism is disabled, wait until it's our turn to read blocks. */
+	if (!guc_parallel_enabled)
+		LWLockAcquire(shared_mem->lock, LW_EXCLUSIVE);
+#endif
+
 	ReadBlocks(filenum, dbname);
+
+#if PG_VERSION_NUM == 90300
+	if (!guc_parallel_enabled)
+		LWLockRelease(shared_mem->lock);
+#endif

 	/*
 	 * Exit with non-zero status to ensure that this worker is not restarted.
@@ -390,7 +555,7 @@
 	file = fileOpen(filename, PG_BINARY_R);

 	/* To restore the global objects, use default database */
-	BackgroundWorkerInitializeConnection(filenum == 1 ? default_database : dbname, NULL);
+	BackgroundWorkerInitializeConnection(filenum == 1 ? guc_default_database : dbname, NULL);
 	SetCurrentStatementStartTimestamp();
 	StartTransactionCommand();
 	SPI_connect();
@@ -609,21 +774,32 @@
 {
 	WorkerCommon();

+#if PG_VERSION_NUM >= 90400
+	RegisterBlockReaders();
+#endif
+
 	/*
 	 * Main loop: do this until the SIGTERM handler tells us to terminate
 	 */
 	while (!got_sigterm)
 	{
 		int	rc;
-
+		int sleepTime;
+
+#if PG_VERSION_NUM >= 90400
+		processOnePendingWorker();
+		sleepTime = (list_length(pendingWorkers) == 0 ? 10 : 1);
+#else
+		sleepTime = 10;
+#endif
 		/*
-		 * Wait on the process latch, which sleeps as necessary, but is awakened if
-		 * postmaster dies. This way the background process goes away immediately
-		 * in case of an emergency.
+		 * Wait on the process latch, which sleeps as necessary, but is awakened
+		 * if postmaster dies. This way the background process goes away
+		 * immediately in case of an emergency.
 		 */
 		rc = WaitLatch(&MyProc->procLatch,
 					   WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
-					   10 * 1000L);
+					   sleepTime * 1000L);
 		ResetLatch(&MyProc->procLatch);

 		/* emergency bailout if postmaster has died */
@@ -646,7 +822,7 @@
 	 */

 	/* Save the buffers only if the extension is enabled. */
-	if (hibernate_enabled)
+	if (guc_enabled)
 		SaveBuffers();

 	/*
@@ -721,14 +897,14 @@
 	pg_qsort(saved_buffers, num_buffers, sizeof(SavedBuffer), SavedBufferCmp);

 	/*
-	 * Database numbers 0 and 1 are reserved; In CreateWorkers() 0 is used to
+	 * Database numbers 0 and 1 are reserved; In _PG_init() 0 is used to
 	 * identify and register the BufferSaver, and 1 is reserved here for
 	 * save-file that contains global objects.
 	 */
 	database_counter = 1;

 	/* Connect to the database and start a transaction for database name lookups. */
-	BackgroundWorkerInitializeConnection(default_database, NULL);
+	BackgroundWorkerInitializeConnection(guc_default_database, NULL);
 	SetCurrentStatementStartTimestamp();
 	StartTransactionCommand();
 	PushActiveSnapshot(GetTransactionSnapshot());


truncate display to fit

truncate display to fit

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

--- share/ctlcli_common.c
+++ share/ctlcli_common.c
@@ -139,7 +139,7 @@
 	    strcmp(site, lastsite))
 		printf("%s\n", site);

-	printf("  %-11s %35s %-8s %c%c%c%c%c %5d %4d %4d\n",
+	printf("  %-11s %35.35s %-8s %c%c%c%c%c %5d %4d %4d\n",
 	    res, nid, stype,
 	    scc->scc_flags & CSVCF_CONNECTING		? 'C' : '-',
 	    scc->scc_flags & CSVCF_CONNECTED		? 'O' : '-',


chip/stm32/clock-stm32f3.c: Format with clang-format

BUG=b:236386294
BRANCH=none
TEST=none

Change-Id: I8da571c9e5e151e7cc8bc32d6e1730c2fdf1b4b0
Signed-off-by: Jack Rosenthal <d3f605bef1867f59845d4ce6e4f83b8dc9e4e0ae@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729463
Reviewed-by: Jeremy Bettis <4df7b5147fee087dca33c181f288ee7dbf56e022@chromium.org>

--- chip/stm32/clock-stm32f3.c
+++ chip/stm32/clock-stm32f3.c
@@ -0,0 +1,501 @@
+/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Clocks and power management settings */
+
+#include "chipset.h"
+#include "clock.h"
+#include "clock-f.h"
+#include "common.h"
+#include "console.h"
+#include "cpu.h"
+#include "hooks.h"
+#include "hwtimer.h"
+#include "registers.h"
+#include "system.h"
+#include "task.h"
+#include "timer.h"
+#include "uart.h"
+#include "util.h"
+
+/* Console output macros */
+#define CPUTS(outstr) cputs(CC_CLOCK, outstr)
+#define CPRINTS(format, args...) cprints(CC_CLOCK, format, ##args)
+
+/* use 48Mhz USB-synchronized High-speed oscillator */
+#define HSI48_CLOCK 48000000
+
+/* use PLL at 38.4MHz as system clock. */
+#define PLL_CLOCK 38400000
+
+/* Low power idle statistics */
+#ifdef CONFIG_LOW_POWER_IDLE
+static int idle_sleep_cnt;
+static int idle_dsleep_cnt;
+static uint64_t idle_dsleep_time_us;
+static int dsleep_recovery_margin_us = 1000000;
+
+/*
+ * minimum delay to enter stop mode
+ *
+ * STOP_MODE_LATENCY: max time to wake up from STOP mode with regulator in low
+ * power mode is 5 us + PLL locking time is 200us.
+ *
+ * SET_RTC_MATCH_DELAY: max time to set RTC match alarm. If we set the alarm
+ * in the past, it will never wake up and cause a watchdog.
+ * For STM32F3, we are using HSE, which requires additional time to start up.
+ * Therefore, the latency for STM32F3 is set longer.
+ *
+ * RESTORE_HOST_ALARM_LATENCY: max latency between the deferred routine is
+ * called and the host alarm is actually restored. In practice, the max latency
+ * is measured as ~600us. 1000us should be conservative enough to guarantee
+ * we won't miss the host alarm.
+ */
+#ifdef CHIP_VARIANT_STM32F373
+#define STOP_MODE_LATENCY 500 /* us */
+#elif defined(CHIP_VARIANT_STM32F05X)
+#define STOP_MODE_LATENCY 300 /* us */
+#elif (CPU_CLOCK == PLL_CLOCK)
+#define STOP_MODE_LATENCY 300 /* us */
+#else
+#define STOP_MODE_LATENCY 50 /* us */
+#endif
+#define SET_RTC_MATCH_DELAY 200 /* us */
+
+#ifdef CONFIG_HOSTCMD_RTC
+#define RESTORE_HOST_ALARM_LATENCY 1000 /* us */
+#endif
+
+#endif /* CONFIG_LOW_POWER_IDLE */
+
+/*
+ * RTC clock frequency (By default connected to LSI clock)
+ *
+ * The LSI on any given chip can be between 30 kHz to 60 kHz.
+ * Without calibration, LSI frequency may be off by as much as 50%.
+ *
+ * Set synchronous clock freq to (RTC clock source / 2) to maximize
+ * subsecond resolution. Set asynchronous clock to 1 Hz.
+ */
+
+#define RTC_PREDIV_A 1
+#ifdef CONFIG_STM32_CLOCK_LSE
+#define RTC_FREQ (32768 / (RTC_PREDIV_A + 1)) /* Hz */
+/* GCD(RTC_FREQ, 1000000) */
+#define RTC_GCD 64
+#else /* LSI clock, 40kHz-ish */
+#define RTC_FREQ (40000 / (RTC_PREDIV_A + 1)) /* Hz */
+/* GCD(RTC_FREQ, 1000000) */
+#define RTC_GCD 20000
+#endif
+#define RTC_PREDIV_S (RTC_FREQ - 1)
+
+/*
+ * There are (1000000 / RTC_FREQ) us per RTC tick, take GCD of both terms
+ * for conversion calculations to fit in 32 bits.
+ */
+#define US_GCD (1000000 / RTC_GCD)
+#define RTC_FREQ_GCD (RTC_FREQ / RTC_GCD)
+
+int32_t rtcss_to_us(uint32_t rtcss)
+{
+	return ((RTC_PREDIV_S - (rtcss & 0x7fff)) * US_GCD) / RTC_FREQ_GCD;
+}
+
+uint32_t us_to_rtcss(int32_t us)
+{
+	return RTC_PREDIV_S - us * RTC_FREQ_GCD / US_GCD;
+}
+
+void config_hispeed_clock(void)
+{
+#ifdef CHIP_FAMILY_STM32F3
+	/* Ensure that HSE is ON */
+	wait_for_ready(&STM32_RCC_CR, BIT(16), BIT(17));
+
+	/*
+	 * HSE = 24MHz, no prescalar, no MCO, with PLL *2 => 48MHz SYSCLK
+	 * HCLK = SYSCLK, PCLK = HCLK / 2 = 24MHz
+	 * ADCCLK = PCLK / 6 = 4MHz
+	 * USB uses SYSCLK = 48MHz
+	 */
+	STM32_RCC_CFGR = 0x0041a400;
+
+	/* Enable the PLL */
+	STM32_RCC_CR |= 0x01000000;
+
+	/* Wait until the PLL is ready */
+	while (!(STM32_RCC_CR & 0x02000000))
+		;
+
+	/* Switch SYSCLK to PLL */
+	STM32_RCC_CFGR |= 0x2;
+
+	/* Wait until the PLL is the clock source */
+	while ((STM32_RCC_CFGR & 0xc) != 0x8)
+		;
+/* F03X and F05X and F070 don't have HSI48 */
+#elif defined(CHIP_VARIANT_STM32F03X) || defined(CHIP_VARIANT_STM32F05X) || \
+	defined(CHIP_VARIANT_STM32F070)
+	/* If PLL is the clock source, PLL has already been set up. */
+	if ((STM32_RCC_CFGR & 0xc) == 0x8)
+		return;
+
+	/* Ensure that HSI is ON */
+	wait_for_ready(&STM32_RCC_CR, BIT(0), BIT(1));
+
+	/*
+	 * HSI = 8MHz, HSI/2 with PLL *12 = ~48 MHz
+	 * therefore PCLK = FCLK = SYSCLK = 48MHz
+	 */
+	/* Switch the PLL source to HSI/2 */
+	STM32_RCC_CFGR &= ~(0x00018000);
+
+	/*
+	 * Specify HSI/2 clock as input clock to PLL and set PLL (*12).
+	 */
+	STM32_RCC_CFGR |= 0x00280000;
+
+	/* Enable the PLL. */
+	STM32_RCC_CR |= 0x01000000;
+
+	/* Wait until PLL is ready. */
+	while (!(STM32_RCC_CR & 0x02000000))
+		;
+
+	/* Switch SYSCLK to PLL. */
+	STM32_RCC_CFGR |= 0x2;
+
+	/* wait until the PLL is the clock source */
+	while ((STM32_RCC_CFGR & 0xc) != 0x8)
+		;
+#else
+	/* Ensure that HSI48 is ON */
+	wait_for_ready(&STM32_RCC_CR2, BIT(16), BIT(17));
+
+#if (CPU_CLOCK == HSI48_CLOCK)
+	/*
+	 * HSI48 = 48MHz, no prescaler, no MCO, no PLL
+	 * therefore PCLK = FCLK = SYSCLK = 48MHz
+	 * USB uses HSI48 = 48MHz
+	 */
+
+#ifdef CONFIG_USB
+	/*
+	 * Configure and enable Clock Recovery System
+	 *
+	 * Since we are running from the internal RC HSI48 clock, the CSR
+	 * is needed to guarantee an accurate 48MHz clock for USB.
+	 *
+	 * The default values configure the CRS to use the periodic USB SOF
+	 * as the SYNC signal for calibrating the HSI48.
+	 *
+	 */
+
+	/* Enable Clock Recovery System */
+	STM32_RCC_APB1ENR |= STM32_RCC_PB1_CRS;
+
+	/* Enable automatic trimming */
+	STM32_CRS_CR |= STM32_CRS_CR_AUTOTRIMEN;
+
+	/* Enable oscillator clock for the frequency error counter */
+	STM32_CRS_CR |= STM32_CRS_CR_CEN;
+#endif
+
+	/* switch SYSCLK to HSI48 */
+	STM32_RCC_CFGR = 0x00000003;
+
+	/* wait until the HSI48 is the clock source */
+	while ((STM32_RCC_CFGR & 0xc) != 0xc)
+		;
+
+#elif (CPU_CLOCK == PLL_CLOCK)
+	/*
+	 * HSI48 = 48MHz, no prescalar, no MCO, with PLL *4/5 => 38.4MHz SYSCLK
+	 * therefore PCLK = FCLK = SYSCLK = 38.4MHz
+	 * USB uses HSI48 = 48MHz
+	 */
+
+	/* If PLL is the clock source, PLL has already been set up. */
+	if ((STM32_RCC_CFGR & 0xc) == 0x8)
+		return;
+
+	/*
+	 * Specify HSI48 clock as input clock to PLL and set PLL multiplier
+	 * and divider.
+	 */
+	STM32_RCC_CFGR = 0x00098000;
+	STM32_RCC_CFGR2 = 0x4;
+
+	/* Enable the PLL. */
+	STM32_RCC_CR |= 0x01000000;
+
+	/* Wait until PLL is ready. */
+	while (!(STM32_RCC_CR & 0x02000000))
+		;
+
+	/* Switch SYSCLK to PLL. */
+	STM32_RCC_CFGR |= 0x2;
+
+	/* wait until the PLL is the clock source */
+	while ((STM32_RCC_CFGR & 0xc) != 0x8)
+		;
+
+#else
+#error "CPU_CLOCK must be either 48MHz or 38.4MHz"
+#endif
+#endif
+}
+
+#ifdef CONFIG_HIBERNATE
+void __enter_hibernate(uint32_t seconds, uint32_t microseconds)
+{
+	struct rtc_time_reg rtc;
+
+	if (seconds || microseconds)
+		set_rtc_alarm(seconds, microseconds, &rtc, 0);
+
+	/* interrupts off now */
+	interrupt_disable();
+
+#ifdef CONFIG_HIBERNATE_WAKEUP_PINS
+	/* enable the wake up pins */
+	STM32_PWR_CSR |= CONFIG_HIBERNATE_WAKEUP_PINS;
+#endif
+	STM32_PWR_CR |= 0xe;
+	CPU_SCB_SYSCTRL |= 0x4;
+	/* go to Standby mode */
+	asm("wfi");
+
+	/* we should never reach that point */
+	while (1)
+		;
+}
+#endif
+
+#ifdef CONFIG_HOSTCMD_RTC
+static void restore_host_wake_alarm_deferred(void)
+{
+	restore_host_wake_alarm();
+}
+DECLARE_DEFERRED(restore_host_wake_alarm_deferred);
+#endif
+
+#ifdef CONFIG_LOW_POWER_IDLE
+
+void clock_refresh_console_in_use(void)
+{
+}
+
+void __idle(void)
+{
+	timestamp_t t0;
+	uint32_t rtc_diff;
+	int next_delay, margin_us;
+	struct rtc_time_reg rtc0, rtc1;
+
+	while (1) {
+		interrupt_disable();
+
+		t0 = get_time();
+		next_delay = __hw_clock_event_get() - t0.le.lo;
+
+#ifdef CONFIG_LOW_POWER_IDLE_LIMITED
+		if (idle_is_disabled())
+			goto en_int;
+#endif
+
+		if (DEEP_SLEEP_ALLOWED &&
+#ifdef CONFIG_HOSTCMD_RTC
+		    /*
+		     * Don't go to deep sleep mode if we might miss the
+		     * wake alarm that the host requested. Note that the
+		     * host alarm always aligns to second. Considering the
+		     * worst case, we have to ensure alarm won't go off
+		     * within RESTORE_HOST_ALARM_LATENCY + 1 second after
+		     * EC exits deep sleep mode.
+		     */
+		    !is_host_wake_alarm_expired(
+			    (timestamp_t)(next_delay + t0.val + SECOND +
+					  RESTORE_HOST_ALARM_LATENCY)) &&
+#endif
+		    (next_delay > (STOP_MODE_LATENCY + SET_RTC_MATCH_DELAY))) {
+			/* Deep-sleep in STOP mode */
+			idle_dsleep_cnt++;
+
+			uart_enable_wakeup(1);
+
+			/* Set deep sleep bit */
+			CPU_SCB_SYSCTRL |= 0x4;
+
+			set_rtc_alarm(0, next_delay - STOP_MODE_LATENCY, &rtc0,
+				      0);
+			asm("wfi");
+
+			CPU_SCB_SYSCTRL &= ~0x4;
+
+			uart_enable_wakeup(0);
+
+			/*
+			 * By default only HSI 8MHz is enabled here. Re-enable
+			 * high-speed clock if in use.
+			 */
+			config_hispeed_clock();
+
+			/* Fast forward timer according to RTC counter */
+			reset_rtc_alarm(&rtc1);
+			rtc_diff = get_rtc_diff(&rtc0, &rtc1);
+			t0.val = t0.val + rtc_diff;
+			force_time(t0);
+
+#ifdef CONFIG_HOSTCMD_RTC
+			hook_call_deferred(
+				&restore_host_wake_alarm_deferred_data, 0);
+#endif
+			/* Record time spent in deep sleep. */
+			idle_dsleep_time_us += rtc_diff;
+
+			/* Calculate how close we were to missing deadline */
+			margin_us = next_delay - rtc_diff;
+			if (margin_us < 0)
+				/* Use CPUTS to save stack space */
+				CPUTS("Idle overslept!\n");
+
+			/* Record the closest to missing a deadline. */
+			if (margin_us < dsleep_recovery_margin_us)
+				dsleep_recovery_margin_us = margin_us;
+		} else {
+			idle_sleep_cnt++;
+
+			/* Normal idle : only CPU clock stopped */
+			asm("wfi");
+		}
+#ifdef CONFIG_LOW_POWER_IDLE_LIMITED
+	en_int:
+#endif
+		interrupt_enable();
+	}
+}
+#endif /* CONFIG_LOW_POWER_IDLE */
+
+int clock_get_freq(void)
+{
+	return CPU_CLOCK;
+}
+
+void clock_wait_bus_cycles(enum bus_type bus, uint32_t cycles)
+{
+	volatile uint32_t unused __attribute__((unused));
+
+	if (bus == BUS_AHB) {
+		while (cycles--)
+			unused = STM32_DMA1_REGS->isr;
+	} else { /* APB */
+		while (cycles--)
+			unused = STM32_USART_BRR(STM32_USART1_BASE);
+	}
+}
+
+void clock_enable_module(enum module_id module, int enable)
+{
+	if (module == MODULE_ADC) {
+		if (enable)
+			STM32_RCC_APB2ENR |= STM32_RCC_APB2ENR_ADCEN;
+		else
+			STM32_RCC_APB2ENR &= ~STM32_RCC_APB2ENR_ADCEN;
+		return;
+	} else if (module == MODULE_USB) {
+		if (enable)
+			STM32_RCC_APB1ENR |= STM32_RCC_PB1_USB;
+		else
+			STM32_RCC_APB1ENR &= ~STM32_RCC_PB1_USB;
+	}
+}
+
+int clock_is_module_enabled(enum module_id module)
+{
+	if (module == MODULE_ADC)
+		return !!(STM32_RCC_APB2ENR & STM32_RCC_APB2ENR_ADCEN);
+	else if (module == MODULE_USB)
+		return !!(STM32_RCC_APB1ENR & STM32_RCC_PB1_USB);
+	return 0;
+}
+
+void rtc_init(void)
+{
+	rtc_unlock_regs();
+
+	/* Enter RTC initialize mode */
+	STM32_RTC_ISR |= STM32_RTC_ISR_INIT;
+	while (!(STM32_RTC_ISR & STM32_RTC_ISR_INITF))
+		;
+
+	/* Set clock prescalars */
+	STM32_RTC_PRER = (RTC_PREDIV_A << 16) | RTC_PREDIV_S;
+
+	/* Start RTC timer */
+	STM32_RTC_ISR &= ~STM32_RTC_ISR_INIT;
+	while (STM32_RTC_ISR & STM32_RTC_ISR_INITF)
+		;
+
+	/* Enable RTC alarm interrupt */
+	STM32_RTC_CR |= STM32_RTC_CR_ALRAIE | STM32_RTC_CR_BYPSHAD;
+	STM32_EXTI_RTSR |= EXTI_RTC_ALR_EVENT;
+	task_enable_irq(STM32_IRQ_RTC_ALARM);
+
+	rtc_lock_regs();
+}
+
+#if defined(CONFIG_CMD_RTC) || defined(CONFIG_HOSTCMD_RTC)
+void rtc_set(uint32_t sec)
+{
+	struct rtc_time_reg rtc;
+
+	sec_to_rtc(sec, &rtc);
+	rtc_unlock_regs();
+
+	/* Disable alarm */
+	STM32_RTC_CR &= ~STM32_RTC_CR_ALRAE;
+
+	/* Enter RTC initialize mode */
+	STM32_RTC_ISR |= STM32_RTC_ISR_INIT;
+	while (!(STM32_RTC_ISR & STM32_RTC_ISR_INITF))
+		;
+
+	/* Set clock prescalars */
+	STM32_RTC_PRER = (RTC_PREDIV_A << 16) | RTC_PREDIV_S;
+
+	STM32_RTC_TR = rtc.rtc_tr;
+	STM32_RTC_DR = rtc.rtc_dr;
+	/* Start RTC timer */
+	STM32_RTC_ISR &= ~STM32_RTC_ISR_INIT;
+
+	rtc_lock_regs();
+}
+#endif
+
+#if defined(CONFIG_LOW_POWER_IDLE) && defined(CONFIG_COMMON_RUNTIME)
+#ifdef CONFIG_CMD_IDLE_STATS
+/**
+ * Print low power idle statistics
+ */
+static int command_idle_stats(int argc, char **argv)
+{
+	timestamp_t ts = get_time();
+
+	ccprintf("Num idle calls that sleep:           %d\n", idle_sleep_cnt);
+	ccprintf("Num idle calls that deep-sleep:      %d\n", idle_dsleep_cnt);
+	ccprintf("Time spent in deep-sleep:            %.6llds\n",
+		 idle_dsleep_time_us);
+	ccprintf("Total time on:                       %.6llds\n", ts.val);
+	ccprintf("Deep-sleep closest to wake deadline: %dus\n",
+		 dsleep_recovery_margin_us);
+
+	return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(idlestats, command_idle_stats, "",
+			"Print last idle stats");
+#endif /* CONFIG_CMD_IDLE_STATS */
+#endif


Show WARNING when open_basedir and realpath_turbo.open_basedir are set together

If open_basedir is set when realpath_turbo should be used it doesn't make sense
because then realpath cache is already disabled by PHP and cannot be re-enabled.

--- realpath_turbo.c
+++ realpath_turbo.c
@@ -51,6 +51,10 @@
 #endif

 	if (rpt_open_basedir && *rpt_open_basedir) {
+		if (PG(open_basedir) && *PG(open_basedir)) {
+			php_error_docref(NULL, E_WARNING, "open_basedir already set! Please unset open_basedir and only use realpath_turbo.open_basedir option. realpath_turbo will not have any effect when open_basedir is already set.");
+			return FAILURE;
+		}
 #if PHP_MAJOR_VERSION < 7
 		zend_alter_ini_entry("open_basedir", sizeof("open_basedir"), rpt_open_basedir, strlen(rpt_open_basedir), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
 #else


delegate-request: include cleanup

delegate-request: include cleanup

--- src/delegate-request.h
+++ src/delegate-request.h
@@ -8,15 +8,14 @@
 #ifndef BENG_PROXY_DELEGATE_REQUEST_H
 #define BENG_PROXY_DELEGATE_REQUEST_H

-#include "pool.h"
-
+struct pool;
 struct hstock;
 struct http_response_handler;
 struct async_operation_ref;
 struct jail_params;

 void
-delegate_stock_request(struct hstock *stock, pool_t pool,
+delegate_stock_request(struct hstock *stock, struct pool *pool,
                        const char *helper,
                        const struct jail_params *jail,
                        const char *path, const char *content_type,


Avoid cyclic dependencies in class_header.

Don't include uhdm.h, which in turn includes
everything, cyclic-including the current header - this
will result in undefined classes depending on which
of these are included first.

Instead, just include the header we need (the base
class of what we're extending).

Signed-off-by: Henner Zeller <259ad50fabbfd39355f36ecd6c0afca541ea66ef@acm.org>

--- templates/class_header.h
+++ templates/class_header.h
@@ -29,25 +29,26 @@
 #include "SymbolFactory.h"
 #include "BaseClass.h"
 #include "containers.h"
-#include "uhdm.h"
+
+#include "<EXTENDS>.h"

 namespace UHDM {
+class <CLASSNAME> <FINAL_CLASS> : public <EXTENDS> {
+public:
+  // Implicit constructor used to initialize all members,
+  // comment: <CLASSNAME>();
+  <VIRTUAL>~<CLASSNAME>() <FINAL_DESTRUCTOR> {}
+  <METHODS>
+  <VIRTUAL> UHDM_OBJECT_TYPE UhdmType() const <OVERRIDE_OR_FINAL> { return uhdm<CLASSNAME>; }

-  class <CLASSNAME> <FINAL_CLASS> : public <EXTENDS> {
-  public:
-    // Implicit constructor used to initialize all members,
-    // comment: <CLASSNAME>();
-    <VIRTUAL>~<CLASSNAME>() <FINAL_DESTRUCTOR> {}
-    <METHODS>
-   <VIRTUAL> UHDM_OBJECT_TYPE UhdmType() const <OVERRIDE_OR_FINAL> { return uhdm<CLASSNAME>; }
-  private:
-    <MEMBERS>
-  };
+private:
+  <MEMBERS>
+};

- <DISABLE_OBJECT_FACTORY>
-  class <CLASSNAME>Factory {
+<DISABLE_OBJECT_FACTORY>
+class <CLASSNAME>Factory {
   friend Serializer;
-  public:
+public:
   <CLASSNAME>* Make() {
     <CLASSNAME>* obj = new <CLASSNAME>();
     objects_.push_back(obj);
@@ -60,24 +61,25 @@
         break;
       }
     }
-  }
-  private:
-    std::vector<<CLASSNAME>*> objects_;
-  };
- <END_DISABLE_OBJECT_FACTORY>
-
-  class VectorOf<CLASSNAME>Factory {
+  }
+
+private:
+  std::vector<<CLASSNAME>*> objects_;
+};
+<END_DISABLE_OBJECT_FACTORY>
+
+class VectorOf<CLASSNAME>Factory {
   friend Serializer;
-  public:
-  std::vector<<CLASSNAME>*>* Make() {
-    std::vector<<CLASSNAME>*>* obj = new std::vector<<CLASSNAME>*>();
-    objects_.push_back(obj);
-    return obj;
-  }
-  private:
-  std::vector<std::vector<<CLASSNAME>*>*> objects_;
-  };
-
+ public:
+ std::vector<<CLASSNAME>*>* Make() {
+   std::vector<<CLASSNAME>*>* obj = new std::vector<<CLASSNAME>*>();
+   objects_.push_back(obj);
+   return obj;
+ }
+ private:
+ std::vector<std::vector<<CLASSNAME>*>*> objects_;
 };

+}  // namespace UHDM
+
 #endif


* subversion/libsvn_wc/wc_db.c
  (revert_list_read): Work around the fact that one compile-time-
    chosen branch of logic wants a 'const' array of marker paths while
    the other needs it non-const.

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

--- subversion/libsvn_wc/wc_db.c
+++ subversion/libsvn_wc/wc_db.c
@@ -6324,15 +6324,18 @@
                                                   scratch_pool);
           if (conflict_data)
             {
+              const apr_array_header_t *marker_paths;
               svn_skel_t *conflicts = svn_skel__parse(conflict_data,
                                                       conflict_len,
                                                       scratch_pool);

-              SVN_ERR(svn_wc__conflict_read_markers(&b->marker_paths,
+              SVN_ERR(svn_wc__conflict_read_markers(&marker_paths,
                                                     b->db, wcroot->abspath,
                                                     conflicts,
                                                     b->result_pool,
                                                     scratch_pool));
+              /* De-const-ify. */
+              b->marker_paths = (apr_array_header_t *)marker_paths;
             }
 #endif


Improved platform-dependent faithful(long double, long double)

--- test/native/math/double/unary.h
+++ test/native/math/double/unary.h
@@ -22,14 +22,16 @@

 static inline _Bool faithful(long double x, long double y)
 {
-#if LDBL_MANT_DIG > DBL_MANT_DIG
-    const uint64_t mask = ((uint64_t)1 << (LDBL_MANT_DIG - DBL_MANT_DIG)) - 1;
+    #if LDBL_MANT_DIG == DBL_MANT_DIG
+        return approx(x, y, 1);
+    #elif __SIZEOF_LONG_DOUBLE__ == __SIZEOF_INT128__
+        const uint64_t mask = ((uint64_t)1 << (LDBL_MANT_DIG - DBL_MANT_DIG)) - 1;

-    unsigned __int128 a = reinterpret(unsigned __int128, x);
-    unsigned __int128 b = reinterpret(unsigned __int128, y);
+        unsigned __int128 a = reinterpret(unsigned __int128, x);
+        unsigned __int128 b = reinterpret(unsigned __int128, y);

-    return a - b + mask <= 2 * mask;
-#else
-    return approx(x, y, 1);
-#endif
+        return a - b + mask <= 2 * mask;
+    #else
+        return identical(x, y) || (x && fabsl(x - y) <= fabs(nexttoward(x, y) - nexttoward(y, x)));
+    #endif
 }


Use SVN_WC__SINGLE_DB as check for sharding pristines instead of
SVN__SKIP_SUBDIR. The single DB format should be as close as (currently)
possible to the final 1.7 on-disk format.

* subversion/libsvn_wc/wc_db.c
  (SVN__SKIP_SUBDIR): Remove define.
  (get_pristine_fname): Check for SVN_WC__SINGLE_DB instead of
    !SVN__SKIP_SUBDIR.

--- subversion/libsvn_wc/wc_db.c
+++ subversion/libsvn_wc/wc_db.c
@@ -104,13 +104,6 @@
 #define UNKNOWN_WC_ID ((apr_int64_t) -1)
 #define FORMAT_FROM_SDB (-1)

-
-/* ### since we're putting the pristine files per-dir, then we don't need
-   ### to create subdirectories in order to keep the directory size down.
-   ### when we can aggregate pristine files across dirs/wcs, then we will
-   ### need to undo the SKIP. */
-#define SVN__SKIP_SUBDIR
-
 /* This is a character used to escape itself and the globbing character in
    globbing sql expressions below.  See escape_sqlite_like().

@@ -287,7 +280,7 @@
    to hold CHECKSUM's pristine file, relating to the pristine store
    configured for the working copy indicated by PDH. The returned path
    does not necessarily currently exist.
-#ifndef SVN__SKIP_SUBDIR
+#ifdef SVN_WC__SINGLE_DB
    Iff CREATE_SUBDIR is TRUE, then this function will make sure that the
    parent directory of PRISTINE_ABSPATH exists. This is only useful when
    about to create a new pristine.
@@ -303,7 +296,7 @@
 {
   const char *base_dir_abspath;
   const char *hexdigest = svn_checksum_to_cstring(sha1_checksum, scratch_pool);
-#ifndef SVN__SKIP_SUBDIR
+#ifdef SVN_WC__SINGLE_DB
   char subdir[3];
 #endif

@@ -325,7 +318,7 @@
   /* We should have a valid checksum and (thus) a valid digest. */
   SVN_ERR_ASSERT(hexdigest != NULL);

-#ifndef SVN__SKIP_SUBDIR
+#ifdef SVN_WC__SINGLE_DB
   /* Get the first two characters of the digest, for the subdir. */
   subdir[0] = hexdigest[0];
   subdir[1] = hexdigest[1];
@@ -350,7 +343,7 @@
   /* The file is located at DIR/.svn/pristine/XX/XXYYZZ... */
   *pristine_abspath = svn_dirent_join_many(result_pool,
                                            base_dir_abspath,
-#ifndef SVN__SKIP_SUBDIR
+#ifdef SVN_WC__SINGLE_DB
                                            subdir,
 #endif
                                            hexdigest,


Fix filename_append_suffix

Fix filename_append_suffix

--- php_fileutil.c
+++ php_fileutil.c
@@ -891,12 +891,12 @@

     dot = strrchr(filename, (int) '.');
     if ( dot != NULL ) {
-        newfilename = emalloc( sizeof(char) * (filename_len + suffix_len + 2) );
+        newfilename = emalloc( sizeof(char) * (filename_len + suffix_len + 10) );

         dst = newfilename;
         len = (dot - filename);
         src = filename;
-        memcpy(dst, src, len);
+        memcpy(dst, filename, len);
         dst += len;

         src = suffix;
@@ -905,8 +905,7 @@

         len = filename_len - (filename - dot);
-        src = dot;
-        memcpy(dst, src, len);
+        memcpy(dst, dot, len);
         dst += len;
         *dst = '\0';
         newfilename_len = filename_len + suffix_len;


Make 'public' (testable)

Make 'public' (testable)

--- src/declarative/graphicsitems/qmlgraphicswebview_p.h
+++ src/declarative/graphicsitems/qmlgraphicswebview_p.h
@@ -128,6 +128,7 @@
     qreal zoomFactor() const;
     void setZoomFactor(qreal);
     Q_INVOKABLE bool heuristicZoom(int clickX, int clickY, qreal maxzoom);
+    QRect elementAreaAt(int x, int y, int minwidth, int minheight) const;

     int preferredWidth() const;
     void setPreferredWidth(int);
@@ -223,7 +224,6 @@
     virtual void focusChanged(bool);
     virtual bool sceneEvent(QEvent *event);
     QmlGraphicsWebView *createWindow(QWebPage::WebWindowType type);
-    QRect elementAreaAt(int x, int y, int minwidth, int minheight) const;

 private:
     void init();


ifdef MacOS specific code

ifdef MacOS specific code

--- core/alsp_src/generic/lforeign.c
+++ core/alsp_src/generic/lforeign.c
@@ -554,10 +554,12 @@
 #include "alspi_slib.h"
 #include "cinterf.h"

+#ifdef MacOS
 static QDGlobals *GetQD(void)
 {
     return &qd;
 }
+#endif

 typedef unsigned long library_reference;


Add Function

Add Function

Add Two Numbers

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

--- addFunction.c
+++ addFunction.c
@@ -0,0 +1,79 @@
+// By Mickoon
+//---------------------------------------------------------------------
+// ADD TWO NUMBERS (in char format)
+//---------------------------------------------------------------------
+// Convert characters to integers first,
+// Then add two arbitrarily large integers inputs and define the result
+//---------------------------------------------------------------------
+// TIP: Use Binary Addition
+//---------------------------------------------------------------------
+
+void Add(char *input1, char *input2, char *sum)
+{
+	int numberOneSize = strlen(input1);
+	int numberTwoSize = strlen(input2);
+	int i, total, pos = 0;
+	int carry = 0;
+	int max = numberOneSize; 	// Let numberOneSize as max in first
+	char temp[MAX_ARRAY_SIZE]; 	// Temporary characters which contains the sum of these two inputs reversely
+
+	// When numberTwoSize is bigger than numberOneSize, which is maximum string length
+	// From initialisation, numberTwoSize becomes max.
+	if (numberTwoSize > numberOneSize)
+		max = numberTwoSize;
+
+	// e.g. numberOneSize = 18 and numberTwoSizse = 16:
+	// Calculation starts from the end of the number!
+	for (i = max - 1; i >= 0; i--)	// 17, 16, 15, ... 1, 0
+	{
+		if (max == numberOneSize)
+		{
+			// Converting input1 characters to integers values by subtracting '0', which is 48 in integer
+			// e.g. when (int)input1[9] in integer = 57 so when 57-48 = 9, which is integer
+			// Then add integers of input1 and input2 together
+			if (i > numberTwoSize)
+				total = (int)input1[i] - '0';
+			else
+				total = (int)input1[i] - '0' + (int)input2[i] - '0';
+		}
+		else
+		{
+			if (i > numberOneSize)
+				total = (int)input2[i] - '0';
+			else
+				total = (int)input2[i] - '0' + (int)input1[i] - '0';
+		}
+
+		// This shows when there is a carry the total number is added
+		if (carry == 1)
+		{
+			total++;
+			carry = 0;
+		}
+
+		// When the total number from adding two integers is equal or greater than 10 there is carry
+		// and then show the remainder on that position
+		if (total >= 10)
+		{
+			carry = 1;
+			total = total - 10;
+		}
+
+		temp[pos] = (char)total + '0';
+		pos++;
+	}
+
+	// When there is a carry at the start position on your temporary result,
+	// add number 1 integer to the next position of the array.
+	if (carry == 1)
+	{
+		temp[pos] = (char)1 + '0';
+		pos++;
+	}
+
+	// Final step: reverse back the temp value which is same as the sum of input1 and input2.
+	for (i = 0; i < pos; i++)
+	{
+		sum[i] = temp[pos - 1 - i];
+	}
+}


Use literal instead of constant to fix 9.4 build

PG_UINT32_MAX doesn't exist before 9.5. Missed this because I removed
my assert-enabled builds during packaging work.

Fixes #619

--- src/backend/distributed/executor/multi_router_executor.c
+++ src/backend/distributed/executor/multi_router_executor.c
@@ -301,9 +301,8 @@
 		Assert(currentAffectedTupleCount >= 0);

 #if (PG_VERSION_NUM < 90600)
-
 		/* before 9.6, PostgreSQL used a uint32 for this field, so check */
-		Assert(currentAffectedTupleCount <= PG_UINT32_MAX);
+		Assert(currentAffectedTupleCount <= 0xFFFFFFFF);
 #endif

 		if ((affectedTupleCount == -1) ||


conf: add prefix in virDomainNetDefParseXML

And use the newly added caps->host.netprefix for free interface
names that match the autogenerated target names.

Signed-off-by: Joao Martins <7c86cc079af931b7847bbaae227ac1245d2901a0@oracle.com>

--- src/conf/domain_conf.c
+++ src/conf/domain_conf.c
@@ -8434,6 +8434,7 @@
                         xmlNodePtr node,
                         xmlXPathContextPtr ctxt,
                         virHashTablePtr bootHash,
+                        char *prefix,
                         unsigned int flags)
 {
     virDomainNetDefPtr def;
@@ -8600,7 +8601,8 @@
                 ifname = virXMLPropString(cur, "dev");
                 if (ifname &&
                     (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) &&
-                    STRPREFIX(ifname, VIR_NET_GENERATED_PREFIX)) {
+                     (STRPREFIX(ifname, VIR_NET_GENERATED_PREFIX) ||
+                      (prefix && STRPREFIX(ifname, prefix)))) {
                     /* An auto-generated target name, blank it out */
                     VIR_FREE(ifname);
                 }
@@ -12556,6 +12558,7 @@
     xmlNodePtr node;
     xmlXPathContextPtr ctxt = NULL;
     virDomainDeviceDefPtr dev = NULL;
+    char *netprefix;

     if (!(xml = virXMLParseStringCtxt(xmlStr, _("(device_definition)"), &ctxt)))
         goto error;
@@ -12598,8 +12601,9 @@
             goto error;
         break;
     case VIR_DOMAIN_DEVICE_NET:
+        netprefix = caps->host.netprefix;
         if (!(dev->data.net = virDomainNetDefParseXML(xmlopt, node, ctxt,
-                                                      NULL, flags)))
+                                                      NULL, netprefix, flags)))
             goto error;
         break;
     case VIR_DOMAIN_DEVICE_INPUT:
@@ -14747,6 +14751,7 @@
     bool usb_other = false;
     bool usb_master = false;
     bool primaryVideo = false;
+    char *netprefix = NULL;

     if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE) {
         char *schema = virFileFindResource("domain.rng",
@@ -15932,11 +15937,13 @@
         goto error;
     if (n && VIR_ALLOC_N(def->nets, n) < 0)
         goto error;
+    netprefix = caps->host.netprefix;
     for (i = 0; i < n; i++) {
         virDomainNetDefPtr net = virDomainNetDefParseXML(xmlopt,
                                                          nodes[i],
                                                          ctxt,
                                                          bootHash,
+                                                         netprefix,
                                                          flags);
         if (!net)
             goto error;