Bring the locate_copyfrom() handler in our update_editor into the WC-NG
world.  Document it's current behavior which before this patch relied
on svn_wc_entry_t perticularities. This enables future extenstion later.
Also allow using known to be good pristine data without reusing its
in-wc data, to avoid some cases where we contacted the repository, but
really had all the data we need.

It is probably easier to review locate_copyfrom() as a new function, then
trying to extract the old behavior from the patch.

* subversion/libsvn_wc/update_editor.c
  (locate_copyfrom): Rewritten to return streams and hash tables with
     contents and properties. Document old-assumptions as they apply
     to the wc-ng world.
  (add_file_with_history): Update caller. Take scratch pool.
  (add_file): Update caller. Use subpool as scratch_pool for
     add_file_with_history.

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

--- subversion/libsvn_wc/update_editor.c
+++ subversion/libsvn_wc/update_editor.c
@@ -3354,15 +3354,35 @@
 }

-/* Beginning at DIR_ABSPATH (from repository with uuid DIR_REPOS_UUID and
-   with repos_relpath DIR_REPOS_RELPATH) within a working copy, search the
-   working copy for a pre-existing versioned file which is exactly equal
-   to COPYFROM_PATH@COPYFROM_REV.
-
-   If the file isn't found, set *RETURN_ABSPATH to NULL.
-
-   If the file is found, return the absolute path to it in
-   *RETURN_ABSPATH.
+/* Beginning at DIR_ABSPATH within a working copy, search the working copy
+   copy for a pre-existing versioned file which is exactly equal to
+   COPYFROM_PATH@COPYFROM_REV.
+
+   The current implementation does this by taking the repos_relpath of
+   dir_abspath and copyfrom_relpath to calculate where in the working copy
+   repos_relpath would be and then tries to confirm its guess.
+
+   1) When it finds a copied file there, it looks for its origin to see
+   if the origin matches the copied file good enough to use it as new base
+   contents and properties. If that is the case set NEW_BASE_CONTENTS
+   and NEW_BASE_PROPS to the found restult.
+
+   If the new base information is found check if the node is tree-conflicted,
+   and when that is the case use its in-wc contents and actual properties
+   to set NEW_CONTENTS and NEW_PROPS.
+
+   (If new base info is found, return)
+
+   2) If the node's BASE information matches the expected origin matches the the
+   copy origin good enough use it as NEW_BASE_CONTENTS and NEW_BASE_PROPS.
+
+   If the new base information is found and the db_status of the node is normal,
+   then set NEW_CONTENTS and NEW_PROPS with the found values.
+
+   If data is not found, its values will be set to NULL.
+
+   Allocate the return values in RESULT_POOL, but perform all temporary allocations
+   in SCRATCH_POOL.

    ### With a centralized datastore this becomes much easier. For now we
    ### keep the old algorithm because the result is also used for copying
@@ -3370,32 +3390,40 @@
    ### local file moves.
 */
 static svn_error_t *
-locate_copyfrom(svn_wc__db_t *db,
-                const char *copyfrom_path,
+locate_copyfrom(svn_stream_t **new_base_contents,
+                svn_stream_t **new_contents,
+                apr_hash_t **new_base_props,
+                apr_hash_t **new_props,
+                svn_wc__db_t *db,
+                const char *dir_abspath,
+                const char *copyfrom_relpath,
                 svn_revnum_t copyfrom_rev,
-                const char *dir_abspath,
-                const char *dir_repos_uuid,
-                const char *dir_repos_relpath,
-                const char **return_abspath,
                 apr_pool_t *result_pool,
                 apr_pool_t *scratch_pool)
 {
   const char *ancestor_abspath, *ancestor_relpath;
-  const char *copyfrom_relpath;
+  const char *dir_repos_relpath, *dir_repos_root_url, *dir_repos_uuid;
+  const char *repos_relpath, *repos_root_url, *repos_uuid;
+  const char *local_abspath;
+
   apr_size_t levels_up;
-  const char *file_abspath;
   svn_error_t *err;

-  SVN_ERR_ASSERT(dir_repos_relpath && dir_repos_uuid);
-  SVN_ERR_ASSERT(copyfrom_path[0] == '/');
+  SVN_ERR_ASSERT(copyfrom_relpath[0] != '/');
+
+  SVN_ERR(svn_wc__db_scan_base_repos(&dir_repos_relpath, &dir_repos_root_url,
+                                     &dir_repos_uuid,
+                                     db, dir_abspath,
+                                     scratch_pool, scratch_pool));

   /* Be pessimistic.  This function is basically a series of tests
      that gives dozens of ways to fail our search, returning
      SVN_NO_ERROR in each case.  If we make it all the way to the
      bottom, we have a real discovery to return. */
-  *return_abspath = NULL;
-
-  copyfrom_relpath = copyfrom_path+1; /* Skip the initial '/' */
+  *new_base_contents = NULL;
+  *new_contents = NULL;
+  *new_base_props = NULL;
+  *new_props = NULL;

   /* Subtract the dest_dir's URL from the repository "root" URL to get
      the absolute FS path represented by dest_dir. */
@@ -3415,118 +3443,227 @@
     ancestor_abspath = svn_dirent_dirname(ancestor_abspath, scratch_pool);

   /* Verify hypothetical ancestor */
+  err = svn_wc__db_scan_base_repos(&repos_relpath, &repos_root_url,
+                                   &repos_uuid,
+                                   db, ancestor_abspath,
+                                   scratch_pool, scratch_pool);
+
+  if (err && ((err->apr_err == SVN_ERR_WC_NOT_WORKING_COPY) ||
+              (err->apr_err == SVN_ERR_WC_PATH_FOUND)))
+    {
+      svn_error_clear(err);
+      return SVN_NO_ERROR;
+    }
+  else
+    SVN_ERR(err);
+
+  /* If we got this far, we know that the ancestor dir exists, and
+     that it's a working copy too.  But is it from the same
+     repository?  And does it represent the URL we expect it to? */
+  if ((strcmp(dir_repos_uuid, repos_uuid) != 0)
+      || (strcmp(dir_repos_root_url, repos_root_url) != 0)
+      || (strcmp(ancestor_relpath, repos_relpath) != 0))
+    return SVN_NO_ERROR;
+
+  /* Add the remaining components to cwd, then add the remaining relpath to
+     where we hope the copyfrom_relpath file exists. */
+  local_abspath = svn_dirent_join(ancestor_abspath,
+                                 svn_dirent_skip_ancestor(ancestor_relpath,
+                                                          copyfrom_relpath),
+                                 scratch_pool);
+
+  /* Verify file in expected location */
   {
-    const char *repos_relpath, *repos_uuid;
-
-    err = svn_wc__db_scan_base_repos(&repos_relpath, NULL, &repos_uuid,
-                                     db, ancestor_abspath,
-                                     scratch_pool, scratch_pool);
-
-    if (err && ((err->apr_err == SVN_ERR_WC_NOT_WORKING_COPY) ||
-                (err->apr_err == SVN_ERR_WC_PATH_FOUND)))
+    svn_revnum_t rev, changed_rev;
+    svn_wc__db_status_t status, base_status;
+    svn_boolean_t conflicted, have_base;
+    const svn_checksum_t *checksum;
+
+    err = svn_wc__db_read_info(&status, NULL, &rev, &repos_relpath,
+                               &repos_root_url, &repos_uuid, &changed_rev,
+                               NULL, NULL, NULL, NULL, &checksum, NULL, NULL,
+                               NULL, NULL, NULL, NULL, NULL, NULL, &have_base,
+                               NULL, &conflicted, NULL,
+                               db, local_abspath, scratch_pool, scratch_pool);
+
+    if (err && ((err->apr_err == SVN_ERR_WC_NOT_WORKING_COPY ||
+                (err->apr_err == SVN_ERR_WC_PATH_NOT_FOUND))))
       {
         svn_error_clear(err);
         return SVN_NO_ERROR;
       }
-    else
-      SVN_ERR(err);
-
-    /* If we got this far, we know that the ancestor dir exists, and
-       that it's a working copy too.  But is it from the same
-       repository?  And does it represent the URL we expect it to? */
-    if (strcmp(dir_repos_uuid, repos_uuid) != 0)
+
+    /* Check if we have an added node with the right copyfrom information, as
+       this is what you would see on a file move. */
+
+    if (status == svn_wc__db_status_added)
+      {
+        const char *op_root_abspath;
+        const char *original_repos_relpath, *original_root_url;
+        const char *original_uuid;
+        svn_revnum_t original_rev;
+
+        SVN_ERR(svn_wc__db_scan_addition(&status, &op_root_abspath,
+                                         &repos_relpath, &repos_root_url,
+                                         &repos_uuid, &original_repos_relpath,
+                                         &original_root_url, &original_uuid,
+                                         &original_rev,
+                                         db, local_abspath,
+                                         scratch_pool, scratch_pool));
+
+        if (status == svn_wc__db_status_copied
+            || status == svn_wc__db_status_moved_here)
+          {
+            original_repos_relpath = svn_relpath_join(
+                                    original_repos_relpath,
+                                    svn_dirent_skip_ancestor(op_root_abspath,
+                                                             local_abspath),
+                                    scratch_pool);
+
+            /* If the repository location matches our exact guess and
+               the file's recorded revisions tell us that the file had the
+               same contents at the copyfrom_revision, we can use this
+               data as new_base */
+            if (strcmp(original_repos_relpath, copyfrom_relpath) == 0
+                && strcmp(original_root_url, dir_repos_root_url) == 0
+                && strcmp(original_uuid, dir_repos_uuid) == 0
+                && strcmp(repos_relpath, copyfrom_relpath) == 0
+                && strcmp(repos_root_url, dir_repos_root_url) == 0
+                && strcmp(repos_uuid, dir_repos_uuid) == 0
+
+                && SVN_IS_VALID_REVNUM(changed_rev)
+                && changed_rev <= copyfrom_rev
+                && copyfrom_rev <= original_rev)
+              {
+                svn_node_kind_t kind;
+                svn_boolean_t text_changed;
+
+                /* WORKING_NODE has the right new-BASE information,
+                   so we have at least a partial result. */
+                SVN_ERR(svn_wc__db_pristine_read(new_base_contents,
+                                                 db, local_abspath, checksum,
+                                                 result_pool, scratch_pool));
+                SVN_ERR(svn_wc__get_pristine_props(new_base_props,
+                                                   db, local_abspath,
+                                                   result_pool, scratch_pool));
+
+                /* If the node is conflicted, that might have happened because
+                   the node was deleted. Which might indicate that we have
+                   a file move. In this case we like the real file data */
+                if (!conflicted
+                    && status == svn_wc__db_status_copied)
+                  return SVN_NO_ERROR; /* A local copy is no local modification
+                                          that we should keep */
+
+                /* ### TODO: Add verification to check that the conflict
+                       tells us that this is the right thing to do.
+
+                   ### Pre 1.7 we just assumed that it is ok without checking for
+                       conflicts, so this is not a regression */
+
+                SVN_ERR(svn_io_check_path(local_abspath, &kind, scratch_pool));
+
+                if (kind != svn_node_file)
+                  return SVN_NO_ERROR; /* Nothing to copy */
+
+                SVN_ERR(svn_wc__internal_text_modified_p(&text_changed, db,
+                                                         local_abspath, FALSE,
+                                                         TRUE, scratch_pool));
+
+                if (!text_changed)
+                  return SVN_NO_ERROR; /* Take the easy route */
+
+                SVN_ERR(svn_stream_open_readonly(new_contents, local_abspath,
+                                                 result_pool, scratch_pool));
+
+                SVN_ERR(svn_wc__get_actual_props(new_props, db, local_abspath,
+                                                 result_pool, scratch_pool));
+
+                return SVN_NO_ERROR;
+              }
+          }
+      }
+
+    if (!have_base)
       return SVN_NO_ERROR;

-    if (strcmp(ancestor_relpath, repos_relpath) != 0)
+    base_status = status;
+
+    if (status != svn_wc__db_status_normal)
+      SVN_ERR(svn_wc__db_base_get_info(&base_status, NULL, &rev,
+                                       &repos_relpath, &repos_root_url,
+                                       &repos_uuid, &changed_rev, NULL,
+                                       NULL, NULL, NULL, &checksum, NULL,
+                                       NULL, NULL,
+                                       db, local_abspath,
+                                       scratch_pool, scratch_pool));
+
+    if (base_status != svn_wc__db_status_normal)
+      return SVN_NO_ERROR; /* No interesting BASE_NODE */
+
+    if (!repos_relpath || !repos_root_url || !repos_uuid)
+      SVN_ERR(svn_wc__db_scan_base_repos(&repos_relpath, &repos_root_url,
+                                         &repos_uuid,
+                                         db, local_abspath,
+                                         scratch_pool, scratch_pool));
+
+    /* Is it from the same repository */
+    if ((strcmp(dir_repos_uuid, repos_uuid) != 0)
+        || (strcmp(dir_repos_root_url, repos_root_url) != 0)
+        || (strcmp(copyfrom_relpath, repos_relpath) != 0))
       return SVN_NO_ERROR;
-  }
-
-  /* Add the remaining components to cwd, then add the remaining relpath to
-     where we hope the copyfrom_relpath file exists. */
-  file_abspath = svn_dirent_join(ancestor_abspath,
-                                 svn_dirent_skip_ancestor(ancestor_relpath,
-                                                          copyfrom_relpath),
-                                 scratch_pool);
-
-  /* Verify file in expected location */
-  {
-    svn_node_kind_t kind;
-    svn_revnum_t addition_rev = SVN_INVALID_REVNUM;
-    const char *repos_relpath, *repos_uuid;
-
-    /* First: does the proposed file path even exist? */
-    SVN_ERR(svn_io_check_path(file_abspath, &kind, scratch_pool));
-    if (kind != svn_node_file)
-      return SVN_NO_ERROR;
-
-    /* Next: is the file under version control?   */
-    err = svn_wc__db_scan_base_repos(&repos_relpath, NULL, &repos_uuid,
-                                     db, file_abspath,
-                                     scratch_pool, scratch_pool);
-
-    if (err && ((err->apr_err == SVN_ERR_WC_NOT_WORKING_COPY) ||
-                (err->apr_err == SVN_ERR_WC_PATH_NOT_FOUND)))
+
+    /* Ok, we know that we look at the right node, but do we have the
+       right revision?
+
+       To be sure that the base node has the right properties and text,
+       the node must be the same in copyfrom_rev and changed_rev, which
+       is only true within this specific range
+       */
+    if (!(SVN_IS_VALID_REVNUM(changed_rev)
+          && changed_rev <= copyfrom_rev
+          && copyfrom_rev <= rev))
       {
-        svn_error_clear(err);
-
-        /* ### Our entries handling made us handle the following
-               scenario: An older version of a file was copied at
-               exactly the expected location. Reproduced this behavior
-               until we can really querry the entire workingcopy. */
-
-        err = svn_wc__db_scan_addition(NULL, NULL, NULL, NULL, NULL,
-                                       &repos_relpath, NULL, &repos_uuid,
-                                       &addition_rev, db, file_abspath,
-                                       scratch_pool, scratch_pool);
-
-        if (err && ((err->apr_err == SVN_ERR_WC_NOT_WORKING_COPY ||
-              (err->apr_err == SVN_ERR_WC_PATH_NOT_FOUND))))
-          {
-            svn_error_clear(err);
-
-            return SVN_NO_ERROR;
-          }
-        else
-          SVN_ERR(err);
-      }
-    else
-      SVN_ERR(err);
-
-    if (strcmp(dir_repos_uuid, repos_uuid))
-      return SVN_NO_ERROR;
-
-    if (strcmp(copyfrom_relpath, repos_relpath))
-      return SVN_NO_ERROR;
-
-    if (SVN_IS_VALID_REVNUM(addition_rev) && addition_rev == copyfrom_rev)
-      {
-        /* We found the right file as copy source */
-        *return_abspath = apr_pstrdup(result_pool, file_abspath);
         return SVN_NO_ERROR;
       }
+
+    /* BASE_NODE has the right new-BASE information,
+       so we have at least a partial result. */
+    SVN_ERR(svn_wc__db_pristine_read(new_base_contents,
+                                     db, local_abspath, checksum,
+                                     result_pool, scratch_pool));
+
+    SVN_ERR(svn_wc__db_base_get_props(new_base_props,
+                                      db, local_abspath, result_pool,
+                                      scratch_pool));
+
+    /* If the node is in status normal, the user probably intended to make
+       a copy of this in-wc node, so copy its local changes over to
+       the new file. */
+    if (status == svn_wc__db_status_normal)
+      {
+        svn_node_kind_t kind;
+        svn_boolean_t text_changed;
+
+        SVN_ERR(svn_io_check_path(local_abspath, &kind, scratch_pool));
+
+        if (kind != svn_node_file)
+          return SVN_NO_ERROR; /* Nothing to copy */
+
+        SVN_ERR(svn_wc__internal_text_modified_p(&text_changed, db,
+                                                 local_abspath, FALSE,
+                                                 TRUE, scratch_pool));
+
+        if (!text_changed)
+            return SVN_NO_ERROR; /* Take the easy route */
+
+        SVN_ERR(svn_stream_open_readonly(new_contents, local_abspath,
+                                         result_pool, scratch_pool));
+
+        SVN_ERR(svn_wc__get_actual_props(new_props, db, local_abspath,
+                                         result_pool, scratch_pool));
+      }
   }
-
-  /* Do we actually have valid revisions for the file?  (See Issue
-     #2977.) */
-  {
-    svn_revnum_t wc_rev, change_rev;
-
-    SVN_ERR(svn_wc__db_base_get_info(NULL, NULL, &wc_rev, NULL, NULL, NULL,
-                                     &change_rev, NULL, NULL, NULL, NULL, NULL,
-                                     NULL, NULL, NULL, db, file_abspath,
-                                     scratch_pool, scratch_pool));
-
-    if (!SVN_IS_VALID_REVNUM(wc_rev) || !SVN_IS_VALID_REVNUM(change_rev))
-      return SVN_NO_ERROR;
-
-    /* Do we have the the right *version* of the file? */
-    if (! ((change_rev <= copyfrom_rev) && (copyfrom_rev <= wc_rev)))
-      return SVN_NO_ERROR;
-  }
-
-  /* Success!  We found the exact file we wanted! */
-  *return_abspath = apr_pstrdup(result_pool, file_abspath);
-
   return SVN_NO_ERROR;
 }

@@ -3576,36 +3713,26 @@
                       const char *copyfrom_path,
                       svn_revnum_t copyfrom_rev,
                       struct file_baton *tfb,
-                      apr_pool_t *pool)
+                      apr_pool_t *result_pool,
+                      apr_pool_t *scratch_pool)
 {
   struct edit_baton *eb = pb->edit_baton;
-  apr_hash_t *base_props, *working_props;
-  svn_error_t *err;
   svn_stream_t *copied_stream;
-  const char *src_local_abspath, *copied_text_base_tmp_abspath;
+  const char *copied_text_base_tmp_abspath;
   svn_wc__db_t *db = eb->db;
-  const char *dir_repos_relpath, *dir_repos_root, *dir_repos_uuid;
-
-  /* The file_pool can stick around for a *long* time, so we want to
-     use a subpool for any temporary allocations. */
-  apr_pool_t *subpool = svn_pool_create(pool);
+  svn_stream_t *new_base_contents, *new_contents;
+  apr_hash_t *new_base_props, *new_props;
+
+  SVN_ERR_ASSERT(copyfrom_path[0] == '/');

   tfb->added_with_history = TRUE;

   /* Attempt to locate the copyfrom_path in the working copy first. */
-
-  SVN_ERR(svn_wc__db_scan_base_repos(&dir_repos_relpath, &dir_repos_root,
-                                     &dir_repos_uuid, db, pb->local_abspath,
-                                     subpool, subpool));
-
-  err = locate_copyfrom(eb->db, copyfrom_path, copyfrom_rev, pb->local_abspath,
-                        dir_repos_uuid, dir_repos_relpath,
-                        &src_local_abspath, subpool, subpool);
-
-  if (err && err->apr_err == SVN_ERR_WC_COPYFROM_PATH_NOT_FOUND)
-    svn_error_clear(err);
-  else
-    SVN_ERR(err);
+  SVN_ERR(locate_copyfrom(&new_base_contents, &new_contents,
+                          &new_base_props, &new_props,
+                          db, pb->local_abspath,
+                          copyfrom_path+1, /* Create repos_relpath */
+                          copyfrom_rev, result_pool, scratch_pool));

   /* Open the text base for writing (this will get us a temporary file).  */
   SVN_ERR(svn_wc__open_writable_base(&copied_stream,
@@ -3616,54 +3743,20 @@
                                      &tfb->copied_text_base_md5_checksum,
                                      &tfb->copied_text_base_sha1_checksum,
                                      db, pb->local_abspath,
-                                     pool, pool));
-
-  if (src_local_abspath != NULL) /* Found a file to copy */
+                                     result_pool, scratch_pool));
+
+  if (new_base_contents && new_base_props)
     {
       /* Copy the existing file's text-base over to the (temporary)
          new text-base, where the file baton expects it to be.  Get
          the text base and props from the usual place or from the
          revert place, depending on scheduling. */
-      svn_stream_t *source_text_base;
-      const svn_wc_entry_t *src_entry;
-
-      SVN_ERR(svn_wc__get_entry(&src_entry, db, src_local_abspath, FALSE,
-                            svn_node_file, FALSE, subpool, subpool));
-
-      if (src_entry->schedule == svn_wc_schedule_add)
-        SVN_ERR(svn_wc__get_pristine_contents(&source_text_base,
-                                              db, src_local_abspath,
-                                              subpool, subpool));
-      else
-        SVN_ERR(svn_wc__get_ultimate_base_contents(&source_text_base,
-                                                   db, src_local_abspath,
-                                                   subpool, subpool));
-
-      /* If this has no base, should we use an empty stream?
-       * This assert wants to verify that there are no such callers. */
-      SVN_ERR_ASSERT(source_text_base != NULL);
-
-      if (src_entry->schedule == svn_wc_schedule_replace
-          && src_entry->copyfrom_url)
-        {
-          SVN_ERR(svn_wc__get_revert_props(&base_props, db,
-                                           src_local_abspath, pool, subpool));
-          /* The old working props are lost, just like the old
-             working file text is.  Just use the base props. */
-          working_props = base_props;
-        }
-      else
-        {
-          SVN_ERR(svn_wc__get_pristine_props(&base_props,
-                                             db, src_local_abspath,
-                                             pool, subpool));
-          SVN_ERR(svn_wc__get_actual_props(&working_props,
-                                           db, src_local_abspath,
-                                           pool, subpool));
-        }
-
-      SVN_ERR(svn_stream_copy3(source_text_base, copied_stream,
-                               eb->cancel_func, eb->cancel_baton, pool));
+      SVN_ERR(svn_stream_copy3(new_base_contents, copied_stream,
+                               eb->cancel_func, eb->cancel_baton,
+                               scratch_pool));
+
+      if (!new_props)
+        new_props = new_base_props;
     }
   else  /* Couldn't find a file to copy  */
     {
@@ -3680,45 +3773,49 @@
          to the root of the repository so skip the first '/'. */
       SVN_ERR(eb->fetch_func(eb->fetch_baton, copyfrom_path + 1, copyfrom_rev,
                              copied_stream,
-                             NULL, &base_props, pool));
+                             NULL, &new_base_props, scratch_pool));
       SVN_ERR(svn_stream_close(copied_stream));
-      working_props = base_props;
+
+      /* Filter out wc-props */
+      /* ### Do we get new values as modification or should these really
+             be installed? */
+      new_base_props = svn_prop_hash_dup(copy_regular_props(new_base_props,
+                                                             scratch_pool),
+                                         result_pool);
+
+      new_props = new_base_props;
     }

   SVN_ERR(svn_wc__db_pristine_install(db, copied_text_base_tmp_abspath,
                                       tfb->copied_text_base_sha1_checksum,
                                       tfb->copied_text_base_md5_checksum,
-                                      subpool));
-
-  /* Loop over whatever props we have in memory, and add all
-     regular props to hashes in the baton. Skip entry and wc
-     properties, these are only valid for the original file. */
-  tfb->copied_base_props = copy_regular_props(base_props, pool);
-  tfb->copied_working_props = copy_regular_props(working_props, pool);
-
-  if (src_local_abspath != NULL)
+                                      scratch_pool));
+
+  tfb->copied_base_props = new_base_props;
+
+  if (new_contents)
     {
       /* If we copied an existing file over, we need to copy its
          working text too, to preserve any local mods.  (We already
          read its working *props* into tfb->copied_working_props.) */
-      svn_boolean_t text_changed;
-
-      SVN_ERR(svn_wc__internal_text_modified_p(&text_changed, eb->db,
-                                               src_local_abspath, FALSE,
-                                               TRUE, subpool));
-
-      if (text_changed)
-        {
-          /* Make a unique file name for the copied working text. */
-          SVN_ERR(get_empty_tmp_file(&tfb->copied_working_text, eb->db,
-                                     pb->local_abspath, pool, pool));
-
-          SVN_ERR(svn_io_copy_file(src_local_abspath, tfb->copied_working_text,
-                                   TRUE, subpool));
-        }
-    }
-
-  svn_pool_destroy(subpool);
+      const char *temp_dir_abspath;
+      svn_stream_t *tmp_contents;
+
+        /* Make a unique file name for the copied working text. */
+      SVN_ERR(svn_wc__db_temp_wcroot_tempdir(&temp_dir_abspath,
+                                             db, pb->local_abspath,
+                                             scratch_pool, scratch_pool));
+
+      SVN_ERR(svn_stream_open_unique(&tmp_contents, &tfb->copied_working_text,
+                                     temp_dir_abspath, svn_io_file_del_none,
+                                     result_pool, scratch_pool));
+
+      SVN_ERR(svn_stream_copy3(new_contents, tmp_contents, eb->cancel_func,
+                               eb->cancel_baton,
+                               scratch_pool));
+
+       tfb->copied_working_props = new_props;
+    }

   return SVN_NO_ERROR;
 }
@@ -4089,14 +4186,14 @@
                       svn_wc_notify_tree_conflict, subpool);
     }

-  svn_pool_destroy(subpool);
-
   /* Now, if this is an add with history, do the history part. */
   if (copyfrom_path && !fb->skip_this)
     {
       SVN_ERR(add_file_with_history(pb, copyfrom_path, copyfrom_rev,
-                                    fb, pool));
-    }
+                                    fb, pool, subpool));
+    }
+
+  svn_pool_destroy(subpool);

   return SVN_NO_ERROR;
 }


Added unit test for xadmin down

Added unit test for xadmin down

--- atmitest/atmiunit1.c
+++ atmitest/atmiunit1.c
@@ -315,6 +315,12 @@
     assert_equal(ret, SUCCEED);
 }

+Ensure(test037_down)
+{
+    int ret;
+    ret=system_dbg("test037_down/run.sh");
+    assert_equal(ret, SUCCEED);
+}

 TestSuite *atmi_test_all(void)
 {
@@ -373,6 +379,9 @@
     add_test(suite, test035_hkeep);
     /* mvitolin Bug #110, 22/05/2017 */
     add_test(suite, test036_tprecover);
+
+    /* Bug #133 */
+    add_test(suite, test037_down);

     return suite;
 }


One: Don't print error on timeout.

One: Don't print error on timeout.

--- lib/One/One.c
+++ lib/One/One.c
@@ -385,6 +385,10 @@
           switch (errno) {
                case EINTR:
                     continue;
+               case ETIMEDOUT:
+                    D_DEBUG_AT( One_Queue, "  -> TIMEOUT\n" );
+                    ret = DR_TIMEOUT;
+                    goto error;
                default:
                     break;
           }
@@ -462,6 +466,10 @@
           switch (errno) {
                case EINTR:
                     continue;
+               case ETIMEDOUT:
+                    D_DEBUG_AT( One_Queue, "  -> TIMEOUT\n" );
+                    ret = DR_TIMEOUT;
+                    goto error;
                default:
                     break;
           }
@@ -556,6 +564,10 @@
           switch (errno) {
                case EINTR:
                     continue;
+               case ETIMEDOUT:
+                    D_DEBUG_AT( One_Queue, "  -> TIMEOUT\n" );
+                    ret = DR_TIMEOUT;
+                    goto error;
                default:
                     break;
           }


Mutex checking

Mutex checking


Reduce code dupe. Provide THistStatUncertainty::TBinStat::GetUncertainty.

--- hist/hist/v7/inc/ROOT/THistStats.h
+++ hist/hist/v7/inc/ROOT/THistStats.h
@@ -15,6 +15,7 @@
 #ifndef ROOT7_THistStats_h
 #define ROOT7_THistStats_h

+#include <cmath>
 #include <vector>
 #include "ROOT/RArrayView.h"

@@ -43,27 +44,19 @@
   using Content_t = STORAGE<PRECISION>;

   /**
-  Const-view on a THistStatContent for a given bin.
+   \class TBinStat
+   Mutable view on a THistStatContent for a given bin.
+   Template argument can be `Weight_t` for a const view or `Weight_t&` for a
+   modifying view.
   */
-  class TConstBinStat {
-  public:
-    TConstBinStat(Weight_t content): fContent(content) {}
-    Weight_t GetContent() const { return fContent; }
-
-  private:
-    Weight_t fContent; ///< Content of this bin.
-  };
-
-  /**
-  Mutable view on a THistStatContent for a given bin.
-  */
+  template <class WEIGHT>
   class TBinStat {
   public:
-    TBinStat(Weight_t& content): fContent(content) {}
-    Weight_t& GetContent() const { return fContent; }
+    TBinStat(WEIGHT content): fContent(content) {}
+    WEIGHT GetContent() const { return fContent; }

   private:
-    Weight_t& fContent; ///< Reference to the content of this bin.
+    WEIGHT fContent; ///< (Reference to) the content of this bin.
   };

 private:
@@ -111,9 +104,13 @@
   }

   /// Get a view on the statistics values of a bin.
-  TConstBinStat GetView(int idx) const { return TConstBinStat(fBinContent[idx]); }
+  TBinStat<Weight_t> GetView(int idx) const {
+    return TBinStat<Weight_t>(fBinContent[idx]);
+  }
   /// Get a (non-const) view on the statistics values of a bin.
-  TBinStat GetView(int idx) { return TBinStat(fBinContent[idx]); }
+  TBinStat<Weight_t&> GetView(int idx) {
+    return TBinStat<Weight_t&>(fBinContent[idx]);
+  }
 };

@@ -133,35 +130,25 @@
   using typename Base_t::Content_t;

   /**
-  Const-view on a THistStatUncertainty for a given bin.
+   \class TBinStat
+   View on a THistStatUncertainty for a given bin.
+   Template argument can be `Weight_t` for a const view or `Weight_t&` for a
+   modifying view.
   */
-  class TConstBinStat {
-  public:
-    TConstBinStat(Weight_t content, Weight_t sumw2):
-      fContent(content), fSumW2(sumw2) {}
-    Weight_t GetContent() const { return fContent; }
-    Weight_t GetSumW2() const { return fSumW2; }
-
-  private:
-    Weight_t fContent; ///< Content of this bin.
-    Weight_t fSumW2; ///< The bin's sum of square of weights.
-  };
-
-  /**
-  Mutable view on a THistStatUncertainty for a given bin.
-  */
+  template <class WEIGHT>
   class TBinStat {
   public:
-    TBinStat(Weight_t& content, Weight_t& sumw2):
-    fContent(content), fSumW2(sumw2) {}
-    Weight_t& GetContent() const { return fContent; }
-    Weight_t& GetSumW2() const { return fSumW2; }
+    TBinStat(WEIGHT content, WEIGHT sumw2):
+      fContent(content), fSumW2(sumw2) {}
+    WEIGHT GetContent() const { return fContent; }
+    WEIGHT GetSumW2() const { return fSumW2; }
+    // Can never modify this. Set GetSumW2() instead.
+    WEIGHT GetUncertainty() const { return std::sqrt(std::abs(fSumW2)); }

   private:
-    Weight_t& fContent; ///< Content of this bin.
-    Weight_t& fSumW2; ///< Uncertainty of the content of this bin.
+    WEIGHT fContent; ///< Content of this bin.
+    WEIGHT fSumW2; ///< The bin's sum of square of weights.
   };
-

 private:
   /// Uncertainty of the content for each bin.
@@ -188,12 +175,12 @@
   std::vector<double>& GetSumWeightsSquared() { return fSumWeightsSquared; }

   /// Get a view on the statistics values of a bin.
-  TConstBinStat GetView(int idx) const {
-    return TConstBinStat(this->GetBinContent(idx), fSumWeightsSquared[idx]);
+  TBinStat<Weight_t> GetView(int idx) const {
+    return TBinStat<Weight_t>(this->GetBinContent(idx), fSumWeightsSquared[idx]);
   }
   /// Get a (non-const) view on the statistics values of a bin.
-  TBinStat GetView(int idx) {
-    return TBinStat(this->GetBinContent(idx), fSumWeightsSquared[idx]);
+  TBinStat<Weight_t&> GetView(int idx) {
+    return TBinStat<Weight_t&>(this->GetBinContent(idx), fSumWeightsSquared[idx]);
   }
 };


Allow user configuration of RPL Lifetime and Lifetime Unit

--- core/net/rpl/rpl-private.h
+++ core/net/rpl/rpl-private.h
@@ -113,10 +113,18 @@
 #define RPL_ZERO_LIFETIME               0

 /* Default route lifetime unit. */
+#ifndef RPL_CONF_DEFAULT_LIFETIME_UNIT
 #define RPL_DEFAULT_LIFETIME_UNIT       0xffff
+#else
+#define RPL_DEFAULT_LIFETIME_UNIT	RPL_CONF_DEFAULT_LIFETIME_UNIT
+#endif

 /* Default route lifetime as a multiple of the lifetime unit. */
+#ifndef RPL_CONF_DEFAULT_LIFETIME
 #define RPL_DEFAULT_LIFETIME            0xff
+#else
+#define RPL_DEFAULT_LIFETIME		RPL_CONF_DEFAULT_LIFETIME
+#endif

 #define RPL_LIFETIME(instance, lifetime) \
           ((unsigned long)(instance)->lifetime_unit * (lifetime))


Use the window stack of new contexts.

Use the window stack of new contexts.

--- src/display/idirectfbdisplaylayer.c
+++ src/display/idirectfbdisplaylayer.c
@@ -239,7 +239,8 @@

                     data->context = context;
                     data->region  = region;
-               }
+                    data->stack   = dfb_layer_context_windowstack( data->context );
+                }

                break;

@@ -265,6 +266,7 @@

                data->context = context;
                data->region  = region;
+               data->stack   = dfb_layer_context_windowstack( data->context );

                break;


Clarify documentation on `isHeadDetached`.

--- Classes/GTRepository.h
+++ Classes/GTRepository.h
@@ -72,7 +72,7 @@
 @property (nonatomic, readonly, strong) NSURL *gitDirectoryURL;
 @property (nonatomic, readonly, getter=isBare) BOOL bare; // Is this a 'bare' repository?  i.e. created with git clone --bare
 @property (nonatomic, readonly, getter=isEmpty) BOOL empty; // Is this repository empty? Will only be YES for a freshly `git init`'d repo.
-@property (nonatomic, readonly, getter=isHeadDetached) BOOL headDetached; // Is HEAD detached? i.e., not pointing to any permanent ref.
+@property (nonatomic, readonly, getter=isHeadDetached) BOOL headDetached; // Is HEAD detached? i.e., not pointing to a valid reference.
 @property (nonatomic, readonly, getter=isHeadOrphaned) BOOL headOrphaned; // Is HEAD orphaned? i.e., not pointing to anything.

 + (BOOL)initializeEmptyRepositoryAtURL:(NSURL *)localFileURL error:(NSError **)error;


Typo fix.

Typo fix.

--- Classes/ObjectiveGit.h
+++ Classes/ObjectiveGit.h
@@ -38,7 +38,7 @@
 #import <ObjectiveGit/GTTreeBuilder.h>
 #import <ObjectiveGit/GTBlob.h>
 #import <ObjectiveGit/GTBlame.h>
-#import <objectiveGit/GTBlameHunk.h>
+#import <ObjectiveGit/GTBlameHunk.h>
 #import <ObjectiveGit/GTTag.h>
 #import <ObjectiveGit/GTIndex.h>
 #import <ObjectiveGit/GTIndexEntry.h>


fix comment style

fix comment style

--- src/core/lib/iomgr/ev_epoll_linux.c
+++ src/core/lib/iomgr/ev_epoll_linux.c
@@ -1462,10 +1462,10 @@
   set_ready(exec_ctx, fd, &fd->read_closure);

   /* Note, it is possible that fd_become_readable might be called twice with
-  // different 'notifier's when an fd becomes readable and it is in two epoll
-  // sets (This can happen briefly during polling island merges). In such cases
-  // it does not really matter which notifer is set as the read_notifier_pollset
-  // (They would both point to the same polling island anyway)
+     different 'notifier's when an fd becomes readable and it is in two epoll
+     sets (This can happen briefly during polling island merges). In such cases
+     it does not really matter which notifer is set as the read_notifier_pollset
+     (They would both point to the same polling island anyway) */
   gpr_atm_no_barrier_store(&fd->read_notifier_pollset, (gpr_atm)notifier);
 }


Fix output of -v option.

Fix output of -v option.

--- usr.sbin/pccard/pccardd/cardd.c
+++ usr.sbin/pccard/pccardd/cardd.c
@@ -88,6 +88,7 @@
 			pr_cmd(cp->remove);
 		}
 	}
+	fflush(stdout);
 }

 static void


Put verbosity in the right place.

Put verbosity in the right place.

--- usr.sbin/pkg_install/lib/file.c
+++ usr.sbin/pkg_install/lib/file.c
@@ -1,5 +1,5 @@
 #ifndef lint
-static const char *rcsid = "$Id: file.c,v 1.21 1996/03/12 06:12:43 jkh Exp $";
+static const char *rcsid = "$Id: file.c,v 1.22 1996/06/20 18:33:51 jkh Exp $";
 #endif

 /*
@@ -255,8 +255,6 @@
 	    if (!tpid) {
 		dup2(fileno(ftp), 0);
 		i = execl("/usr/bin/tar", "tar", Verbose ? "-xzvf" : "-xzf", "-", 0);
-		if (Verbose)
-		    printf("tar command returns %d status\n", i);
 		exit(i);
 	    }
 	    else {
@@ -264,6 +262,8 @@

 		fclose(ftp);
 		tpid = waitpid(tpid, &pstat, 0);
+		if (Verbose)
+		    printf("tar command returns %d status\n", WEXITSTATUS(pstat));
 	    }
 	}
 	else


e10k: request VF regs using PCI endpoint cap

Signed-off-by: Roni Häcki <ac1438dbed87008d3b9d6c77a0ffddf380f86b06@inf.ethz.ch>

--- usr/drivers/e10k/e10k_cdriver.c
+++ usr/drivers/e10k/e10k_cdriver.c
@@ -1292,6 +1292,12 @@
     struct capref irq, devid, regs;
     if (!get_vf_resources(vf_num, &devid, &regs, &irq)){
         err = NIC_ERR_ALLOC_QUEUE;
+    }
+
+    debug_printf("PCI request VF bar \n");
+    err = pci_sriov_get_vf_bar_cap(vf_num, 0, &regs);
+    if (err_is_fail(err)) {
+        goto out;
     }

     d_mac = e10k_ral_ral_rdf(st->d, vf_num) | ((uint64_t) e10k_rah_rah_rdf(st->d, vf_num) << 32);


wrapped code in #ifndef NODH

wrapped code in #ifndef NODH

--- usr/lib/pkcs11/common/mech_dh.c
+++ usr/lib/pkcs11/common/mech_dh.c
@@ -317,6 +317,8 @@
 #include "h_extern.h"
 #include "tok_spec_struct.h"

+#ifndef NODH
+
 //
 //
 CK_RV
@@ -512,3 +514,5 @@

    return rc;
 }
+
+#endif


Fix a warning.

Fix a warning.

--- usrsctplib/netinet/sctp_input.c
+++ usrsctplib/netinet/sctp_input.c
@@ -32,7 +32,7 @@

 #ifdef __FreeBSD__
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_input.c 323774 2017-09-19 20:09:58Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_input.c 323776 2017-09-19 20:24:13Z tuexen $");
 #endif

 #include <netinet/sctp_os.h>
@@ -2716,7 +2716,7 @@
 		} else {
 			staleness = diff.tv_sec * 1000000;
 		}
-		if (UINT32_MAX - staleness >= diff.tv_usec) {
+		if (UINT32_MAX - staleness >= (uint32_t)diff.tv_usec) {
 			staleness += diff.tv_usec;
 		} else {
 			staleness = UINT32_MAX;


pars_info_add_*(): In debug builds (UNIV_DEBUG), check that the given name is not already used.

--- pars/pars0pars.c
+++ pars/pars0pars.c
@@ -1963,6 +1963,8 @@
 {
 	pars_bound_lit_t*	pbl;

+	ut_ad(!pars_info_get_bound_lit(info, name));
+
 	pbl = mem_heap_alloc(info->heap, sizeof(*pbl));

 	pbl->name = name;
@@ -2053,6 +2055,8 @@
 {
 	pars_user_func_t*	puf;

+	ut_ad(!pars_info_get_user_func(info, name));
+
 	puf = mem_heap_alloc(info->heap, sizeof(*puf));

 	puf->name = name;


cpu/stm32_common/flashpage: clear EOP bit

This was taken from STM32 Cube generated code

--- cpu/stm32_common/periph/flashpage.c
+++ cpu/stm32_common/periph/flashpage.c
@@ -69,6 +69,11 @@
 {
     DEBUG("[flashpage] waiting for any pending operation to finish\n");
     while (FLASH->SR & FLASH_SR_BSY) {}
+
+    /* Clear 'end of operation' bit in status register */
+    if (FLASH->SR & FLASH_SR_EOP) {
+        FLASH->SR &= ~(FLASH_SR_EOP);
+    }
 }

 static void _erase_page(void *page_addr)


ENH: Extensing SetStringMacro() to accept both (const char *) and      (const std::string &). It add a two methods with different signatures.

--- Code/Common/itkMacro.h
+++ Code/Common/itkMacro.h
@@ -203,7 +203,11 @@
       this->m_##name = ""; \
       } \
     this->Modified(); \
-  }
+  } \
+  virtual void Set##name (const std::string & _arg) \
+  { \
+    this->Set##name( _arg.c_str() ); \
+  } \

 /** Get character string.  Creates member Get"name"()


perf annotate: Handle PERF_RECORD_EXIT events

Noticed annotate wasn't handling those events while introducing
perf_event__process_{fork,exit}.

Cc: David Ahern <b80c1600f604d3b0d768f26f90a76757e76005dd@gmail.com>
Cc: Frederic Weisbecker <e8a1bf9163cb25e93cfd6540f223b3872ea7ee55@gmail.com>
Cc: Jiri Olsa <2c6594f608aa3d41e98d48846a6328831f7084ad@redhat.com>
Cc: Mike Galbraith <3cfa3897b7f55b5396b7a47c83b66325184bc9b4@gmx.de>
Cc: Namhyung Kim <5c915a589b3ddf58cebf14bec41bcc143b37ac3c@gmail.com>
Cc: Paul Mackerras <19a0ba370c443ba08d20b5061586430ab449ee8c@samba.org>
Cc: Peter Zijlstra <3fddac958924aef220f202ca567388ddab3f14a8@infradead.org>
Cc: Stephane Eranian <f199ae9781930a5b94b284ca2f471140752002a7@google.com>
Link: 7136537606c68d29b4f8ce68e081a3af4a2c80f3@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <293abb6b76d7791c0732cc517d38c4b5c734b87f@redhat.com>

--- tools/perf/builtin-annotate.c
+++ tools/perf/builtin-annotate.c
@@ -246,6 +246,7 @@
 			.sample	= process_sample_event,
 			.mmap	= perf_event__process_mmap,
 			.comm	= perf_event__process_comm,
+			.exit	= perf_event__process_exit,
 			.fork	= perf_event__process_fork,
 			.ordered_samples = true,
 			.ordering_requires_timestamps = true,


Fixed bug #1318. Explicitly set number of selected items to zero in ClearSelectedPositions()

--- lib/Xm/List.c
+++ lib/Xm/List.c
@@ -3879,6 +3879,7 @@

   lw->list.selectedPositionCount = 0;
   lw->list.selectedPositions = NULL;
+  lw->list.selectedItemCount = 0;
 }


COMP: vtkDebugMacro is a dummy now for all Borland builds. This is a last ditch attempt to avoid Borland linker LME1518 errors.

--- Code/Common/itkMacro.h
+++ Code/Common/itkMacro.h
@@ -398,7 +398,7 @@
 /** This macro is used to print debug (or other information). They are
  * also used to catch errors, etc. Example usage looks like:
  * itkDebugMacro(<< "this is debug info" << this->SomeVariable); */
-#ifdef ITK_LEAN_AND_MEAN
+#if defined(ITK_LEAN_AND_MEAN) || defined(__BORLANDC__)
 #define itkDebugMacro(x)
 #else
 #define itkDebugMacro(x) \


Update DeviceIo protocol based on EFI 1.1 updated spec.

git-svn-id: 5648d1bec6962b0a6d1d1b40eba8cf5cdb62da3d@6654 6f19259b-4bc3-4df7-8a09-765794883524

--- MdePkg/Include/Protocol/DeviceIo.h
+++ MdePkg/Include/Protocol/DeviceIo.h
@@ -36,10 +36,14 @@
 typedef EFI_DEVICE_IO_PROTOCOL  EFI_DEVICE_IO_INTERFACE;

 typedef enum {
-  IO_UINT8 = 0,
-  IO_UINT16 = 1,
-  IO_UINT32 = 2,
-  IO_UINT64 = 3
+	IO_UINT8  = 0,
+	IO_UINT16 = 1,
+	IO_UINT32 = 2,
+	IO_UINT64 = 3,
+	MMIO_COPY_UINT8  = 4,
+	MMIO_COPY_UINT16 = 5,
+	MMIO_COPY_UINT32 = 6,
+	MMIO_COPY_UINT64 = 7
 } EFI_IO_WIDTH;

 /**
@@ -50,7 +54,10 @@
   @param  Address               The base address of the I/O operations.
   @param  Count                 The number of I/O operations to perform.
   @param  Buffer                For read operations, the destination buffer to store the results. For write
-                                operations, the source buffer to write data from.
+                                operations, the source buffer to write data from. If
+																Width is MMIO_COPY_UINT8, MMIO_COPY_UINT16,
+																MMIO_COPY_UINT32, or MMIO_COPY_UINT64, then
+																Buffer is interpreted as a base address of an I/O operation such as Address.

   @retval EFI_SUCCESS           The data was read from or written to the device.
   @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.


egl/x11: trust our loader over the xserver for the drivername

This is a port of commit 7bd95ec437a(dri2: Trust our own driver name
lookup over the server's.) from glx/dri2.

v2: Add newline between code and multiline comment. (Matt)

Cc: Julien Isorce <177997fc8166815df6f85d30d1378a7a2fd73bfe@gmail.com>
Reported-by: Julien Isorce <177997fc8166815df6f85d30d1378a7a2fd73bfe@gmail.com>
Signed-off-by: Emil Velikov <4c996f2f093ddd0585a556460b4cc3ba555546ef@gmail.com>
Acked-by: Alex Deucher <08dc22c6156113f2deff178e35e3ed9b24d6af9e@amd.com>
Reviewed-by: Eric Anholt <96f164ad4d9b2b0dacf8ebee2bb1eeb3aa69adf1@anholt.net>

--- src/egl/drivers/dri2/platform_x11.c
+++ src/egl/drivers/dri2/platform_x11.c
@@ -519,7 +519,7 @@
    xcb_generic_error_t *error;
    xcb_screen_iterator_t s;
    xcb_screen_t *screen;
-   char *driver_name, *device_name;
+   char *driver_name, *loader_driver_name, *device_name;
    const xcb_query_extension_reply_t *extension;

    xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_xfixes_id);
@@ -596,6 +596,16 @@
    }

    driver_name = xcb_dri2_connect_driver_name (connect);
+
+   /* If Mesa knows about the appropriate driver for this fd, then trust it.
+    * Otherwise, default to the server's value.
+    */
+   loader_driver_name = loader_get_driver_for_fd(dri2_dpy->fd, 0);
+   if (loader_driver_name) {
+      free(driver_name);
+      driver_name = loader_driver_name;
+   }
+
    dri2_dpy->driver_name =
       strndup(driver_name,
               xcb_dri2_connect_driver_name_length(connect));


Create coin_label.c

Create coin_label.c

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

--- coin_label.c
+++ coin_label.c
@@ -0,0 +1,122 @@
+#include <math.h>
+#include "coin_label.h"
+
+Uint8 classify(int y,int Cr, Uint8* copper, Uint8* silver, int k){
+
+	double index1=0.0000,index2=0.0000;
+	double del_1Y, del_1Cr, del_2Y, del_2Cr;  //delX and delY refer matlab code
+    double prob1, prob2;
+
+//    if (y < BG_TH)  return 0;
+
+//#define MEAN1_Y    75
+//#define MEAN1_Cr   143
+//#define VAR1_Y      485
+//#define VAR1_Cr     53
+//#define CORR1      ( 15876.0 / (VAR1_Y * VAR1_Cr))
+//#define PROP1      ( 126.0 / (VAR1_Y * VAR1_Cr))
+//
+//
+//#define MEAN2_Y    110
+//#define MEAN2_Cr   131
+//#define VAR2_Y      414
+//#define VAR2_Cr     7
+//#define CORR2      ( 16.0 / (VAR2_Y * VAR2_Cr) )
+//#define PROP2      ( 4.0 / (VAR2_Y * VAR2_Cr) )
+
+	del_1Y = y - MEAN1_Y;
+	del_1Cr = Cr - MEAN1_Cr;
+
+	del_2Y = y - MEAN2_Y;
+	del_2Cr = Cr - MEAN2_Cr;
+
+	index1 = (1.0/(1.0-CORR1)) * ( del_1Y*del_1Y / VAR1_Y + del_1Cr*del_1Cr / VAR1_Cr - 2*PROP1 * del_1Y*del_1Cr);
+	index2 = (1.0/(1.0-CORR2)) * ( del_2Y*del_2Y / VAR2_Y + del_2Cr*del_2Cr / VAR2_Cr - 2*PROP2 * del_2Y*del_2Cr);
+
+
+	prob1 = (1.0/2.0*PI) / sqrt(VAR1_Y * VAR1_Cr * (1.0-CORR1) * exp(index1));
+	prob2 = (1.0/2.0*PI) / sqrt(VAR2_Y * VAR2_Cr * (1.0-CORR2) * exp(index2));
+
+	if (prob1 < prob2) {
+		silver[k] = 1;
+		return 2;
+	}
+	else {
+		copper[k] = 1;
+		return 1;
+	}
+}
+
+
+Uint8 binary_filter(Uint8* label, int y, int x, int width) {
+	int i, j;
+	int sum = 0;
+
+	for (i = y - FILTER_SIZE/2; i <= y + FILTER_SIZE/2; i++)
+		for (j = x - FILTER_SIZE/2; j <= x + FILTER_SIZE/2; j++) {
+			sum += label[i*width + j];
+		}
+
+	if (sum > FILTER_SIZE * FILTER_SIZE/2.0)
+		return 1;
+	else
+		return 0;
+}
+
+
+//Uint8 isEdge(Uint8 *label, int y, int x, int width) {
+//	int pos = y*width + x;
+//	int diff;
+//	char pattern = 0;
+//
+//	pattern |= label[pos++] << 7;      //upper-left
+//	pattern |= label[pos++] << 6;      //upper
+//	pattern |= label[pos++] << 5;      //upper-right
+//
+//	pos += width;
+//
+//	pattern |= label[pos] << 4;        //right
+//
+//	pos += width;
+//
+//	pattern |= label[pos--] << 3;      //lower-right
+//	pattern |= label[pos--] << 2;      //lower
+//	pattern |= label[pos--] << 1;      //lower-left
+//
+//	pos -= width;
+//
+//	pattern |= label[pos];        //left
+//
+//
+//	if (label[pos-width] - label[pos+width])
+//		return 1; //up to down
+//
+//	if (label[pos-width-1] - label[pos+width+1])
+//		return 1; //upper-left to lower-right
+//
+//	if (label[pos-width+1] - label[pos+width-1])
+//		return 1; //upper-right to lower-left
+//
+//	if (label[pos+1] - label[pos-1])
+//	    return 1; //right-to-left
+//
+//
+//	diff = label[pos-width-1] + (label[pos-width]<<1) + label[pos-width+1]
+//	       - label[pos+width-1] - (label[pos+width]<<1) - label[pos+width+1];
+//	//top-bottom difference
+//
+//	if (diff != 0)  return 255;
+//
+//	diff = label[pos-width-1] + (label[pos-1]<<1) + label[pos+width-1]
+//	       - label[pos-width+1] - (label[pos+1]<<1) - label[pos+width+1];
+//	//left-right difference
+//
+//	if (diff != 0)  return 255;
+//	else            return 0;
+//}
+
+
+
+
+
+


transaction: Use flatpak_decomposed_new_from_pref()

--- common/flatpak-transaction.c
+++ common/flatpak-transaction.c
@@ -2262,7 +2262,6 @@
 op_get_runtime_ref (FlatpakTransactionOperation *op)
 {
   g_autofree char *runtime_pref = NULL;
-  char *ref = NULL;
   FlatpakDecomposed *decomposed;

   if (!op->resolved_metakey)
@@ -2280,13 +2279,9 @@
   if (runtime_pref == NULL)
     return NULL;

-  ref = g_strconcat ("runtime/", runtime_pref, NULL);
-  decomposed = flatpak_decomposed_new_from_ref_take (ref, NULL);
+  decomposed = flatpak_decomposed_new_from_pref (FLATPAK_KINDS_RUNTIME, runtime_pref, NULL);
   if (decomposed == NULL)
-    {
-      g_debug ("Invalid runtime ref %s in metadata", ref);
-      g_free (ref);
-    }
+    g_debug ("Invalid runtime ref %s in metadata", runtime_pref);

   return decomposed;
 }


i2b_PVK_bio: don't set PEM_R_BIO_WRITE_FAILURE in case of success

but in case of an error

CLA: trivial

Reviewed-by: Richard Levitte <5fb523282dd7956571c80524edc2dccfa0bd8234@openssl.org>
Reviewed-by: Bernd Edlinger <ac6902843ae77cc0d49b9c8ddec4cbf141db1bb7@hotmail.de>
Reviewed-by: Tomas Mraz <973cc78d8b4cb00714230ba9be0225e917ab4ac6@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/11380)

--- crypto/pem/pvkfmt.c
+++ crypto/pem/pvkfmt.c
@@ -882,9 +882,9 @@
     wrlen = BIO_write(out, tmp, outlen);
     OPENSSL_free(tmp);
     if (wrlen == outlen) {
-        PEMerr(PEM_F_I2B_PVK_BIO, PEM_R_BIO_WRITE_FAILURE);
         return outlen;
     }
+    PEMerr(PEM_F_I2B_PVK_BIO, PEM_R_BIO_WRITE_FAILURE);
     return -1;
 }


bootstrap:ncc0: use ccache if available in PATH

--- bootstrap/ncc0.main.c
+++ bootstrap/ncc0.main.c
@@ -13,6 +13,7 @@
 struct opt {
   bool verbose;
   bool compile;
+  const char *ccache;
   const char *compiler;
   const char *cflags;
 };
@@ -63,10 +64,11 @@
     EXCEPT(e);
   }

-  static const char *fmt = "%s " CFLAGS " %s -xc %s -c -o %s";
-  char *cmd = calloc(strlen(fmt) + strlen(g_opt.compiler) + strlen(g_opt.cflags)
-                     + strlen(c_fn) + strlen(o_fn) - 5 + 1, sizeof(char));
-  sprintf(cmd, fmt, g_opt.compiler, g_opt.cflags, c_fn, o_fn);
+  static const char *fmt = "%s %s " CFLAGS " %s -xc %s -c -o %s";
+  char *cmd = calloc(strlen(fmt) + strlen(g_opt.ccache)
+                     + strlen(g_opt.compiler) + strlen(g_opt.cflags)
+                     + strlen(c_fn) + strlen(o_fn) + 1, sizeof(char));
+  sprintf(cmd, fmt, g_opt.ccache, g_opt.compiler, g_opt.cflags, c_fn, o_fn);

   error e = sh(cmd);
   free(cmd);
@@ -94,15 +96,17 @@
 }

 static ERROR clink(const char *out_fn, const char *inputs, const char *extra) {
-  static const char fmt[] = "%s " LDFLAGS " %s %s %s -o %s%s";
+  static const char fmt[] = "%s %s " LDFLAGS " %s %s %s -o %s%s";
   const char *ext = "";
   if (strcmp(g_opt.compiler, "emcc") == 0) {
     ext = ".js";
   }
-  size_t len = strlen(fmt) + strlen(g_opt.compiler) + strlen(g_opt.cflags)
-    + strlen(inputs) + strlen(extra) + strlen(out_fn) + strlen(ext) - 7;
+  size_t len = strlen(fmt) + strlen(g_opt.ccache)
+    + strlen(g_opt.compiler) + strlen(g_opt.cflags)
+    + strlen(inputs) + strlen(extra) + strlen(out_fn) + strlen(ext);
   char *cmd = calloc(len + 1, sizeof(char));
-  sprintf(cmd, fmt, g_opt.compiler, g_opt.cflags, inputs, extra, out_fn, ext);
+  sprintf(cmd, fmt, g_opt.ccache, g_opt.compiler,
+          g_opt.cflags, inputs, extra, out_fn, ext);

   error e = sh(cmd);
   free(cmd);
@@ -243,7 +247,7 @@
     runner = "d8";
     ext = ".js";
   }
-  char *cmd = calloc(strlen(fmt) + strlen(runner) + strlen(main_fn) + strlen(ext) - 4 + 1, sizeof(char));
+  char *cmd = calloc(strlen(fmt) + strlen(runner) + strlen(main_fn) + strlen(ext) + 1, sizeof(char));
   sprintf(cmd, fmt, runner, out_fn, ext);
   e = sh(cmd);
   free(cmd);
@@ -293,6 +297,7 @@
   g_opt.verbose = false;
   g_opt.compile = true;
   g_opt.compiler = "gcc";
+  g_opt.ccache = "ccache";
   g_opt.cflags = "";

   if (getenv("NCC_VERBOSE")) {
@@ -306,6 +311,11 @@
   }
   if (getenv("NCC_CFLAGS")) {
     g_opt.cflags = strdup(getenv("NCC_CFLAGS"));
+  }
+
+  int status = system("ccache --version &> /dev/null");
+  if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+    g_opt.ccache = "";
   }

   struct globalctx gctx;


patch-id: take "commit" prefix as well as "diff-tree" prefix

Some time ago we changed git-log in a massive way, and one consequence is
that the keyword changed. Adjust patch-id for that.

[jc: as Linus suggests, allowing both old and new prefix.]

Signed-off-by: Johannes Schindelin <b4cf3b77c95aaa57254d96e276bf14cfc9472402@gmx.de>
Signed-off-by: Junio C Hamano <dc50d1021234060e53ec42a77d526afa2fe07479@cox.net>

--- patch-id.c
+++ patch-id.c
@@ -42,6 +42,8 @@

 		if (!memcmp(line, "diff-tree ", 10))
 			p += 10;
+		else if (!memcmp(line, "commit ", 7))
+			p += 7;

 		if (!get_sha1_hex(p, n)) {
 			flush_current_id(patchlen, sha1, &ctx);


KEYS: Fix public_key asymmetric key subtype name

The length of the name of an asymmetric key subtype must be stored in struct
asymmetric_key_subtype::name_len so that it can be matched by a search for
"<subkey_name>:<partial_fingerprint>".  Fix the public_key subtype to have
name_len set.

Signed-off-by: David Howells <ebac1d06c1688626821bb0e574a037a7a5354e49@redhat.com>
Signed-off-by: James Morris <bb9ce606a3116cc7a99739bd8e2dd57a2d5b69c1@oracle.com>


TRIV: correct a verbose message.

TRIV: correct a verbose message.

--- patching.c
+++ patching.c
@@ -121,7 +121,7 @@
 			min_rgrad = (*(*(affected+goal_mode)+i))->rgrad;
 	}
 	if (verbose) {
-		printf( "Minimum reachability gradient value in Exit or U_i: %d\n", min_rgrad );
+		printf( "Minimum reachability gradient value in Entry or U_i: %d\n", min_rgrad );
 		fflush( stdout );
 	}
 	i = 0;


genicam: plug memory leak

genicam: plug memory leak

--- src/arvgcregisterdescriptionnode.c
+++ src/arvgcregisterdescriptionnode.c
@@ -151,6 +151,7 @@
 	ArvGcRegisterDescriptionNode *node = ARV_GC_REGISTER_DESCRIPTION_NODE (object);

 	g_free (node->model_name);
+	g_free (node->vendor_name);

 	parent_class->finalize (object);
 }


- fix compile error (again)

- fix compile error (again)

as per
https://devzone.nordicsemi.com/question/6950/upgrading-to-sdk-520-breaks
-build/?answer=14073#post-id-14073

--- utility/nrf51822/s110/nrf_svc.h
+++ utility/nrf51822/s110/nrf_svc.h
@@ -16,7 +16,7 @@
   { \
     __asm( \
         "svc %0\n" \
-        "bx r14" : : "I" (number) : "r0" \
+        "bx r14" : : "I" ((uint16_t)number) : "r0" \
     ); \
   }
 #elif defined (__ICCARM__)
@@ -25,9 +25,9 @@
 PRAGMA(swi_number = number) \
  __swi return_type signature;
 #else
-#define SVCALL(number, return_type, signature) return_type signature
+#define SVCALL(number, return_type, signature) return_type signature
 #endif
 #endif	// SVCALL
-
+
 #endif	// SVCALL_AS_NORMAL_FUNCTION
 #endif	// NRF_SVC__


test jpeg

test jpeg

--- video/capture.c
+++ video/capture.c
@@ -330,7 +330,8 @@
     fprintf(stream, "  field order: %d\n", pix->field);
     fprintf(stream, "  bytes per line: %u\n", pix->bytesperline);
     fprintf(stream, "  image size: %u bytes\n", pix->sizeimage);
-    fprintf(stream, "  color space: %u\n", pix->colorspace);
+    fprintf(stream, "  color space: %u %u\n", pix->colorspace, V4L2_COLORSPACE_JPEG);
+    fprintf(stream, "  extended fields: %u\n", pix->priv == V4L2_PIX_FMT_PRIV_MAGIC ? 1 : 0);
 }

 int list_supported_image_formats(int fd) {
@@ -371,6 +372,8 @@
             errno_exit("VIDIOC_S_FMT");
     }
     if (1) {
+        pix->width       = 960;
+        pix->height      = 720;
         pix->pixelformat = V4L2_PIX_FMT_MJPEG;
         pix->field       = V4L2_FIELD_INTERLACED;
     }


Fix memory leak in BufFileCreateShared().

Also this commit unifies some duplicated code in makeBufFile() and
BufFileOpenShared() into new function makeBufFileCommon().

Author: Antonin Houska
Reviewed-By: Thomas Munro, Tatsuo Ishii
Discussion: https://postgr.es/m/16139.1529049566%40localhost

--- src/backend/storage/file/buffile.c
+++ src/backend/storage/file/buffile.c
@@ -99,6 +99,7 @@
 	char		buffer[BLCKSZ];
 };

+static BufFile *makeBufFileCommon(int nfiles);
 static BufFile *makeBufFile(File firstfile);
 static void extendBufFile(BufFile *file);
 static void BufFileLoadBuffer(BufFile *file);
@@ -106,21 +107,16 @@
 static int	BufFileFlush(BufFile *file);
 static File MakeNewSharedSegment(BufFile *file, int segment);

-
-/*
- * Create a BufFile given the first underlying physical file.
- * NOTE: caller must set isInterXact if appropriate.
+/*
+ * Create BufFile and perform the common initialization.
  */
 static BufFile *
-makeBufFile(File firstfile)
+makeBufFileCommon(int nfiles)
 {
 	BufFile    *file = (BufFile *) palloc(sizeof(BufFile));

-	file->numFiles = 1;
-	file->files = (File *) palloc(sizeof(File));
-	file->files[0] = firstfile;
-	file->offsets = (off_t *) palloc(sizeof(off_t));
-	file->offsets[0] = 0L;
+	file->numFiles = nfiles;
+	file->offsets = (off_t *) palloc0(sizeof(off_t) * nfiles);
 	file->isInterXact = false;
 	file->dirty = false;
 	file->resowner = CurrentResourceOwner;
@@ -128,6 +124,21 @@
 	file->curOffset = 0L;
 	file->pos = 0;
 	file->nbytes = 0;
+
+	return file;
+}
+
+/*
+ * Create a BufFile given the first underlying physical file.
+ * NOTE: caller must set isInterXact if appropriate.
+ */
+static BufFile *
+makeBufFile(File firstfile)
+{
+	BufFile    *file = makeBufFileCommon(1);
+
+	file->files = (File *) palloc(sizeof(File));
+	file->files[0] = firstfile;
 	file->readOnly = false;
 	file->fileset = NULL;
 	file->name = NULL;
@@ -246,23 +257,12 @@
 {
 	BufFile    *file;

-	file = (BufFile *) palloc(sizeof(BufFile));
+	file = makeBufFileCommon(1);
 	file->fileset = fileset;
 	file->name = pstrdup(name);
-	file->numFiles = 1;
 	file->files = (File *) palloc(sizeof(File));
 	file->files[0] = MakeNewSharedSegment(file, 0);
-	file->offsets = (off_t *) palloc(sizeof(off_t));
-	file->offsets[0] = 0L;
-	file->isInterXact = false;
-	file->dirty = false;
-	file->resowner = CurrentResourceOwner;
-	file->curFile = 0;
-	file->curOffset = 0L;
-	file->pos = 0;
-	file->nbytes = 0;
 	file->readOnly = false;
-	file->name = pstrdup(name);

 	return file;
 }
@@ -283,7 +283,6 @@
 	File	   *files;
 	int			nfiles = 0;

-	file = (BufFile *) palloc(sizeof(BufFile));
 	files = palloc(sizeof(File) * capacity);

 	/*
@@ -317,16 +316,8 @@
 				(errcode_for_file_access(),
 				 errmsg("could not open BufFile \"%s\"", name)));

-	file->numFiles = nfiles;
+	file = makeBufFileCommon(nfiles);
 	file->files = files;
-	file->offsets = (off_t *) palloc0(sizeof(off_t) * nfiles);
-	file->isInterXact = false;
-	file->dirty = false;
-	file->resowner = CurrentResourceOwner;	/* Unused, can't extend */
-	file->curFile = 0;
-	file->curOffset = 0L;
-	file->pos = 0;
-	file->nbytes = 0;
 	file->readOnly = true;		/* Can't write to files opened this way */
 	file->fileset = fileset;
 	file->name = pstrdup(name);


Hi,

 Hi,

 small changes in formatting.c code (better memory usage ...etc.) and
better
to_char's cache (will fastly for more to_char()s in one query).

(It is probably end of to_char() development in 7.0 cycle.)

                                                Karel

--- src/backend/utils/adt/formatting.c
+++ src/backend/utils/adt/formatting.c
@@ -1,7 +1,7 @@
 /* -----------------------------------------------------------------------
  * formatting.c
  *
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.5 2000/03/08 01:34:36 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.6 2000/03/16 01:35:41 momjian Exp $
  *
  *
  *   Portions Copyright (c) 1999-2000, PostgreSQL, Inc
@@ -14,11 +14,9 @@
  *
  *
  *   Cache & Memory:
- *	Routines use (itself) internal cache for format pictures. If
- *	new format arg is same as a last format string, routines do not
- *	call the format-parser.
+ *	Routines use (itself) internal cache for format pictures.
  *
- *	The cache uses a static buffer and is persistent across transactions.
+ *	The cache uses a static buffers and is persistent across transactions.
  *	If format-picture is bigger than cache buffer, parser is called always.
  *
  *   NOTE for Number version:
@@ -90,18 +88,11 @@
  * Maximal length of one node
  * ----------
  */
-#define DCH_MAX_ITEM_SIZ		9	/* some month name ? 	  */
-#define NUM_MAX_ITEM_SIZ		16	/* roman number 	  */
-
-/* ----------
- * Format picture cache limits
- * ----------
- */
-#define NUM_CACHE_SIZE	64
-#define DCH_CACHE_SIZE	128
-
-/* ----------
- * More in float.c
+#define DCH_MAX_ITEM_SIZ		9	/* max julian day 		*/
+#define NUM_MAX_ITEM_SIZ		8	/* roman number (RN has 15 chars) 	*/
+
+/* ----------
+ * More is in float.c
  * ----------
  */
 #define MAXFLOATWIDTH   64
@@ -281,6 +272,42 @@
 #define IS_PLUS(_f)	((_f)->flag & NUM_F_PLUS)
 #define IS_ROMAN(_f)	((_f)->flag & NUM_F_ROMAN)
 #define IS_MULTI(_f)	((_f)->flag & NUM_F_MULTI)
+
+/* ----------
+ * Format picture cache
+ *  	(cache size:
+ *		Number part 	= NUM_CACHE_SIZE * NUM_CACHE_FIELDS
+ *		Date-time part	= DCH_CACHE_SIZE * DCH_CACHE_FIELDS
+ *	)
+ * ----------
+ */
+#define NUM_CACHE_SIZE		64
+#define NUM_CACHE_FIELDS	16
+#define DCH_CACHE_SIZE		128
+#define DCH_CACHE_FIELDS	16
+
+typedef struct {
+	FormatNode	format	[ DCH_CACHE_SIZE +1];
+	char		str	[ DCH_CACHE_SIZE +1];
+	int		age;
+} DCHCacheEntry;
+
+typedef struct {
+	FormatNode	format	[ NUM_CACHE_SIZE +1];
+	char		str	[ NUM_CACHE_SIZE +1];
+	int		age;
+	NUMDesc		Num;
+} NUMCacheEntry;
+
+static DCHCacheEntry	DCHCache	[ DCH_CACHE_FIELDS +1];	/* global cache for date/time part */
+static int		n_DCHCache = 0;				/* number of entries */
+static int		DCHCounter = 0;
+
+static NUMCacheEntry	NUMCache	[ NUM_CACHE_FIELDS +1];	/* global cache for number part */
+static int		n_NUMCache = 0;				/* number of entries */
+static int		NUMCounter = 0;
+
+#define MAX_INT32	(2147483640)

 /* ----------
  * Private global-modul definitions
@@ -625,8 +652,7 @@
 static int dch_time(int arg, char *inout, int suf, int flag, FormatNode *node);
 static int dch_date(int arg, char *inout, int suf, int flag, FormatNode *node);
 static char *fill_str(char *str, int c, int max);
-static FormatNode *NUM_cache( int len, char *CacheStr, FormatNode *CacheFormat,
-	   NUMDesc *CacheNum, NUMDesc *Num, char *pars_str, int *flag);
+static FormatNode *NUM_cache( int len, NUMDesc *Num, char *pars_str, int *flag);
 static char *int_to_roman(int number);
 static void NUM_prepare_locale(NUMProc *Np);
 static char *get_last_relevant_decnum(char *num);
@@ -634,6 +660,10 @@
 static void NUM_numpart_to_char(NUMProc *Np, int id);
 static char *NUM_processor (FormatNode *node, NUMDesc *Num, char *inout, char *number,
 					int plen, int sign, int type);
+static DCHCacheEntry *DCH_cache_search( char *str );
+static DCHCacheEntry *DCH_cache_getnew( char *str );
+static NUMCacheEntry *NUM_cache_search( char *str );
+static NUMCacheEntry *NUM_cache_getnew( char *str );

 /* ----------
@@ -1259,7 +1289,7 @@

 /* ----------
- * Global format opton for DCH version
+ * Global format option for DCH version
  * ----------
  */
 static int
@@ -1384,7 +1414,7 @@

 #define CHECK_SEQ_SEARCH(_l, _s) {					\
 	if (_l <= 0) { 							\
-		elog(ERROR, "to_datatime(): bad value for %s", _s);		\
+		elog(ERROR, "to_timestamp(): bad value for %s", _s);	\
 	}								\
 }

@@ -1778,6 +1808,84 @@
 	return -1;
 }

+static DCHCacheEntry *
+DCH_cache_getnew( char *str )
+{
+	DCHCacheEntry 	*ent	= NULL;
+
+	/* counter overload check  - paranoa? */
+	if (DCHCounter + DCH_CACHE_FIELDS >= MAX_INT32) {
+		DCHCounter = 0;
+
+		for(ent = DCHCache; ent <= (DCHCache + DCH_CACHE_FIELDS); ent++)
+		        ent->age = (++DCHCounter);
+	}
+
+	/* ----------
+	 * Cache is full - needs remove any older entry
+	 * ----------
+	 */
+	if (n_DCHCache > DCH_CACHE_FIELDS) {
+
+		DCHCacheEntry   *old 	= DCHCache+0;
+#ifdef DEBUG_TO_FROM_CHAR
+		elog(DEBUG_elog_output, "Cache is full (%d)", n_DCHCache);
+#endif
+		for(ent = DCHCache; ent <= (DCHCache + DCH_CACHE_FIELDS); ent++) {
+			if (ent->age < old->age)
+				old = ent;
+		}
+#ifdef DEBUG_TO_FROM_CHAR
+		elog(DEBUG_elog_output, "OLD: '%s' AGE: %d", old->str, old->age);
+#endif
+		strcpy(old->str, str);		/* check str size before this func. */
+		/* old->format fill parser */
+		old->age = (++DCHCounter);
+		return old;
+
+	} else {
+#ifdef DEBUG_TO_FROM_CHAR
+		elog(DEBUG_elog_output, "NEW (%d)", n_DCHCache);
+#endif
+		ent = DCHCache + n_DCHCache;
+		strcpy(ent->str, str);		/* check str size before this func. */
+		/* ent->format fill parser */
+		ent->age = (++DCHCounter);
+		++n_DCHCache;
+		return ent;
+	}
+
+	return (DCHCacheEntry *) NULL;		/* never */
+}
+
+static DCHCacheEntry *
+DCH_cache_search( char *str )
+{
+	int		i = 0;
+	DCHCacheEntry 	*ent;
+
+	/* counter overload check  - paranoa? */
+	if (DCHCounter + DCH_CACHE_FIELDS >= MAX_INT32) {
+		DCHCounter = 0;
+
+		for(ent = DCHCache; ent <= (DCHCache + DCH_CACHE_FIELDS); ent++)
+		        ent->age = (++DCHCounter);
+	}
+
+	for(ent = DCHCache; ent <= (DCHCache + DCH_CACHE_FIELDS); ent++) {
+		if (i == n_DCHCache)
+			break;
+		if (strcmp(ent->str, str) == 0) {
+			ent->age = (++DCHCounter);
+			return ent;
+		}
+		i++;
+	}
+
+	return (DCHCacheEntry *) NULL;
+}
+
+
 /****************************************************************************
  *				Public routines
  ***************************************************************************/
@@ -1789,23 +1897,19 @@
 text *
 timestamp_to_char(Timestamp *dt, text *fmt)
 {
-	static FormatNode	CacheFormat[ DCH_CACHE_SIZE +1];
-	static char		CacheStr[ DCH_CACHE_SIZE +1];
-
-	text 			*result;
+	text 			*result, *result_tmp;
 	FormatNode		*format;
-	int			flag=0;
 	char			*str;
 	double          	fsec;
 	char       		*tzn;
-	int			len=0, tz, x=0;
+	int			len=0, tz, flag = 0, x=0;

 	if ((!PointerIsValid(dt)) || (!PointerIsValid(fmt)))
 		return NULL;

 	len 	= VARSIZE(fmt) - VARHDRSZ;

-	if ((!len) || (TIMESTAMP_NOT_FINITE(*dt)))
+	if ((!len) || (TIMESTAMP_NOT_FINITE(*dt)))
 		return textin("");

 	tm->tm_sec	=0;	tm->tm_year	=0;
@@ -1814,19 +1918,19 @@
 	tm->tm_mday	=1;	tm->tm_isdst	=0;
 	tm->tm_mon	=1;

-	if (TIMESTAMP_IS_EPOCH(*dt)) {
-		x = timestamp2tm(SetTimestamp(*dt), NULL, tm, &fsec, NULL);
-
-	} else if (TIMESTAMP_IS_CURRENT(*dt)) {
-		x = timestamp2tm(SetTimestamp(*dt), &tz, tm, &fsec, &tzn);
-
-	} else {
-		x = timestamp2tm(*dt, &tz, tm, &fsec, &tzn);
-	}
-
-	if (x!=0)
-		elog(ERROR, "to_char(): Unable to convert timestamp to tm");
-
+ 	if (TIMESTAMP_IS_EPOCH(*dt)) {
+ 		x = timestamp2tm(SetTimestamp(*dt), NULL, tm, &fsec, NULL);
+
+  	} else if (TIMESTAMP_IS_CURRENT(*dt)) {
+ 		x = timestamp2tm(SetTimestamp(*dt), &tz, tm, &fsec, &tzn);
+
+  	} else {
+ 		x = timestamp2tm(*dt, &tz, tm, &fsec, &tzn);
+  	}
+
+ 	if (x!=0)
+ 		elog(ERROR, "to_char(): Unable to convert timestamp to tm");
+
 	tm->tm_wday = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) + 1) % 7;
 	tm->tm_yday = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(tm->tm_year, 1,1) +1;

@@ -1850,7 +1954,7 @@
 	 * ----------
          */
 	if ( len > DCH_CACHE_SIZE ) {
-
+
 		format = (FormatNode *) palloc((len + 1) * sizeof(FormatNode));
 		flag  = 1;

@@ -1865,33 +1969,29 @@
 		 * Use cache buffers
 		 * ----------
 		 */
-#ifdef DEBUG_TO_FROM_CHAR
-		elog(DEBUG_elog_output, "DCH_TO_CHAR() Len:            %d",  len);
-		elog(DEBUG_elog_output, "DCH_TO_CHAR() Cache - str:   >%s<", CacheStr);
-		elog(DEBUG_elog_output, "DCH_TO_CHAR() Arg.str:       >%s<", str);
-#endif
+		DCHCacheEntry	*ent;
 		flag = 0;

-       		if (strcmp(CacheStr, str) != 0) {
+       		if ((ent = DCH_cache_search(str)) == NULL) {
+
+			ent = DCH_cache_getnew(str);

 			/* ----------
-			 * Can't use the cache, must run parser and save a original
-			 * format-picture string to the cache.
+			 * Not in the cache, must run parser and save a new
+			 * format-picture to the cache.
 			 * ----------
         		 */
-			strncpy(CacheStr, str, DCH_CACHE_SIZE);
-
-         		parse_format(CacheFormat, str, DCH_keywords,
+         		parse_format(ent->format, str, DCH_keywords,
          		     DCH_suff, DCH_index, DCH_TYPE, NULL);
-
+
+			(ent->format + len)->type = NODE_TYPE_END;		/* Paranoa? */
+
 #ifdef DEBUG_TO_FROM_CHAR
-			/* dump_node(CacheFormat, len); */
+			/* dump_node(ent->format, len); */
 			/* dump_index(DCH_keywords, DCH_index); */
 #endif
-         		(CacheFormat + len)->type = NODE_TYPE_END;	/* Paranoa? */
-        	}
-
-        	format = CacheFormat;
+        	}
+        	format = ent->format;
 	}

 	DCH_processor(format, VARDATA(result), TO_CHAR);
@@ -1900,7 +2000,20 @@
 		pfree(format);

 	pfree(str);
-	VARSIZE(result) = strlen(VARDATA(result)) + VARHDRSZ;
+
+	/* ----------
+	 * for result is allocated max memory, which current format-picture
+	 * needs, now it must be re-allocate to result real size
+	 * ----------
+	 */
+	len 		= strlen(VARDATA(result));
+	result_tmp 	= result;
+	result 		= (text *) palloc( len + 1 + VARHDRSZ);
+
+	strcpy( VARDATA(result), VARDATA(result_tmp));
+	VARSIZE(result) = len + VARHDRSZ;
+	pfree(result_tmp);
+
 	return result;
 }

@@ -1915,9 +2028,6 @@
 Timestamp *
 to_timestamp(text *date_str, text *fmt)
 {
-	static FormatNode	CacheFormat[ DCH_CACHE_SIZE +1];
-	static char		CacheStr[ DCH_CACHE_SIZE +1];
-
 	FormatNode		*format;
 	int			flag=0;
 	Timestamp		*result;
@@ -1963,37 +2073,35 @@
          			     DCH_suff, DCH_index, DCH_TYPE, NULL);

 			(format + len)->type = NODE_TYPE_END;		/* Paranoa? */
-
 		} else {
-
+
 			/* ----------
 			 * Use cache buffers
 			 * ----------
 			 */
-#ifdef DEBUG_TO_FROM_CHAR
-			elog(DEBUG_elog_output, "DCH_TO_CHAR() Len:            %d",  len);
-			elog(DEBUG_elog_output, "DCH_TO_CHAR() Cache - str:   >%s<", CacheStr);
-			elog(DEBUG_elog_output, "DCH_TO_CHAR() Arg.str:       >%s<", str);
-#endif
+			DCHCacheEntry	*ent;
 			flag = 0;

-	       		if (strcmp(CacheStr, str) != 0) {
-
+	       		if ((ent = DCH_cache_search(str)) == NULL) {
+
+				ent = DCH_cache_getnew(str);
+
 				/* ----------
-				 * Can't use the cache, must run parser and save a original
-				 * format-picture string to the cache.
+				 * Not in the cache, must run parser and save a new
+				 * format-picture to the cache.
 				 * ----------
-	        		 */
-				strncpy(CacheStr, str, DCH_CACHE_SIZE);
-
-	         		parse_format(CacheFormat, str, DCH_keywords,
-        	 		     DCH_suff, DCH_index, DCH_TYPE, NULL);
-
-        	 		(CacheFormat + len)->type = NODE_TYPE_END;	/* Paranoa? */
-        		}
-
-        		format = CacheFormat;
-		}
+        			 */
+         			parse_format(ent->format, str, DCH_keywords,
+         			     DCH_suff, DCH_index, DCH_TYPE, NULL);
+
+				(ent->format + len)->type = NODE_TYPE_END;		/* Paranoa? */
+#ifdef DEBUG_TO_FROM_CHAR
+				/* dump_node(ent->format, len); */
+				/* dump_index(DCH_keywords, DCH_index); */
+#endif
+        		}
+        		format = ent->format;
+		}

 		/* ----------
 		 * Call action for each node in FormatNode tree
@@ -2083,16 +2191,107 @@
 	return str;
 }

+#define zeroize_NUM(_n) {		\
+	(_n)->flag 		= 0;	\
+	(_n)->lsign		= 0;	\
+	(_n)->pre		= 0;	\
+	(_n)->post		= 0;	\
+	(_n)->pre_lsign_num	= 0;	\
+	(_n)->need_locale	= 0;	\
+	(_n)->multi		= 0;	\
+	(_n)->zero_start	= 0;	\
+	(_n)->zero_end		= 0;	\
+}
+
+static NUMCacheEntry *
+NUM_cache_getnew( char *str )
+{
+	NUMCacheEntry 	*ent	= NULL;
+
+	/* counter overload check  - paranoa? */
+	if (NUMCounter + NUM_CACHE_FIELDS >= MAX_INT32) {
+		NUMCounter = 0;
+
+		for(ent = NUMCache; ent <= (NUMCache + NUM_CACHE_FIELDS); ent++)
+		        ent->age = (++NUMCounter);
+	}
+
+	/* ----------
+	 * Cache is full - needs remove any older entry
+	 * ----------
+	 */
+	if (n_NUMCache > NUM_CACHE_FIELDS) {
+
+		NUMCacheEntry   *old 	= NUMCache+0;
+
+#ifdef DEBUG_TO_FROM_CHAR
+		elog(DEBUG_elog_output, "Cache is full (%d)", n_NUMCache);
+#endif
+
+		for(ent = NUMCache; ent <= (NUMCache + NUM_CACHE_FIELDS); ent++) {
+			if (ent->age < old->age)
+				old = ent;
+		}
+#ifdef DEBUG_TO_FROM_CHAR
+		elog(DEBUG_elog_output, "OLD: '%s' AGE: %d", old->str, old->age);
+#endif
+		strcpy(old->str, str);		/* check str size before this func. */
+		/* old->format fill parser */
+		old->age = (++NUMCounter);
+
+		ent = old;
+
+	} else {
+#ifdef DEBUG_TO_FROM_CHAR
+		elog(DEBUG_elog_output, "NEW (%d)", n_NUMCache);
+#endif
+		ent = NUMCache + n_NUMCache;
+		strcpy(ent->str, str);		/* check str size before this func. */
+		/* ent->format fill parser */
+		ent->age = (++NUMCounter);
+		++n_NUMCache;
+	}
+
+	zeroize_NUM(&ent->Num);
+
+	return ent;		/* never */
+}
+
+static NUMCacheEntry *
+NUM_cache_search( char *str )
+{
+	int		i = 0;
+	NUMCacheEntry 	*ent;
+
+	/* counter overload check  - paranoa? */
+	if (NUMCounter + NUM_CACHE_FIELDS >= MAX_INT32) {
+		NUMCounter = 0;
+
+		for(ent = NUMCache; ent <= (NUMCache + NUM_CACHE_FIELDS); ent++)
+		        ent->age = (++NUMCounter);
+	}
+
+	for(ent = NUMCache; ent <= (NUMCache + NUM_CACHE_FIELDS); ent++) {
+		if (i == n_NUMCache)
+			break;
+		if (strcmp(ent->str, str) == 0) {
+			ent->age = (++NUMCounter);
+			return ent;
+		}
+		i++;
+	}
+
+	return (NUMCacheEntry *) NULL;
+}

 /* ----------
  * Cache routine for NUM to_char version
  * ----------
  */
 static FormatNode *
-NUM_cache( int len, char *CacheStr, FormatNode *CacheFormat,
-	   NUMDesc *CacheNum, NUMDesc *Num, char *pars_str, int *flag)
+NUM_cache( int len, NUMDesc *Num, char *pars_str, int *flag)
 {
-	FormatNode 	*format;
+	FormatNode 	*format = NULL;
 	char		*str;

 	/* ----------
@@ -2113,86 +2312,57 @@
 		format = (FormatNode *) palloc((len + 1) * sizeof(FormatNode));
 		*flag  = 1;

-		Num->flag 		= 0;
-		Num->lsign		= 0;
-		Num->pre		= 0;
-		Num->post		= 0;
-         	Num->pre_lsign_num	= 0;
-		Num->zero_start		= 0;
-		Num->zero_end		= 0;
-		Num->need_locale	= 0;
-		Num->multi		= 0;
-
+        	zeroize_NUM(Num);
+
 		parse_format(format, str, NUM_keywords,
          			NULL, NUM_index, NUM_TYPE, Num);

 		(format + len)->type = NODE_TYPE_END;		/* Paranoa? */
-		pfree(str);
-		return format;

 	} else {
-
+
 		/* ----------
-		 * Use cache buffer
+		 * Use cache buffers
 		 * ----------
 		 */
-#ifdef DEBUG_TO_FROM_CHAR
-		elog(DEBUG_elog_output, "NUM_TO_CHAR() Len:            %d",  len);
-		elog(DEBUG_elog_output, "NUM_TO_CHAR() Cache - str:   >%s<", CacheStr);
-		elog(DEBUG_elog_output, "NUM_TO_CHAR() Arg.str:       >%s<", str);
-#endif
-		*flag = 0;
-
-       		if (strcmp(CacheStr, str) != 0) {
+		NUMCacheEntry	*ent;
+		flag = 0;
+
+       		if ((ent = NUM_cache_search(str)) == NULL) {
+
+			ent = NUM_cache_getnew(str);

 			/* ----------
-			 * Can't use the cache, must run parser and save a original
-			 * format-picture string to the cache.
+			 * Not in the cache, must run parser and save a new
+			 * format-picture to the cache.
 			 * ----------
         		 */
-			strncpy(CacheStr, str, NUM_CACHE_SIZE);
-
-         		/* ----------
-         		 * Set zeros to CacheNum struct
-         		 * ----------
-         		 */
-			CacheNum->flag 		= 0;
-			CacheNum->lsign		= 0;
-			CacheNum->pre		= 0;
-			CacheNum->post		= 0;
-         		CacheNum->pre_lsign_num	= 0;
-        		CacheNum->need_locale	= 0;
-        		CacheNum->multi		= 0;
-         		CacheNum->zero_start	= 0;
-         		CacheNum->zero_end	= 0;
-
-         		parse_format(CacheFormat, str, NUM_keywords,
-         			NULL, NUM_index, NUM_TYPE, CacheNum);
-
-#ifdef DEBUG_TO_FROM_CHAR
-			/* dump_node(CacheFormat, len); */
-			/* dump_index(NUM_keywords, NUM_index); */
-#endif
-
-         		(CacheFormat + len)->type = NODE_TYPE_END;	/* Paranoa? */
-        	}
-       		/* ----------
+         		parse_format(ent->format, str, NUM_keywords,
+         			NULL, NUM_index, NUM_TYPE, &ent->Num);
+
+			(ent->format + len)->type = NODE_TYPE_END;		/* Paranoa? */
+
+        	}
+
+        	format = ent->format;
+
+		/* ----------
 		 * Copy cache to used struct
 		 * ----------
 		 */
-		Num->flag 		= CacheNum->flag;
-		Num->lsign		= CacheNum->lsign;
-		Num->pre		= CacheNum->pre;
-		Num->post		= CacheNum->post;
-		Num->pre_lsign_num 	= CacheNum->pre_lsign_num;
-		Num->need_locale	= CacheNum->need_locale;
-		Num->multi		= CacheNum->multi;
-		Num->zero_start		= CacheNum->zero_start;
-		Num->zero_end		= CacheNum->zero_end;
-
-		pfree(str);
-		return CacheFormat;
-	}
+		Num->flag 		= ent->Num.flag;
+		Num->lsign		= ent->Num.lsign;
+		Num->pre		= ent->Num.pre;
+		Num->post		= ent->Num.post;
+		Num->pre_lsign_num 	= ent->Num.pre_lsign_num;
+		Num->need_locale	= ent->Num.need_locale;
+		Num->multi		= ent->Num.multi;
+		Num->zero_start		= ent->Num.zero_start;
+		Num->zero_end		= ent->Num.zero_end;
+	}
+
+	pfree(str);
+	return format;
 }

@@ -2332,8 +2502,10 @@
 {
 	char	*result,
 		*p = strchr(num, '.');
-
-	/*elog(NOTICE, "CALL: get_last_relevant_decnum()");*/
+
+#ifdef DEBUG_TO_FROM_CHAR
+	elog(DEBUG_elog_output, "CALL: get_last_relevant_decnum()");
+#endif

 	if (!p)
 		p = num;
@@ -2359,14 +2531,17 @@
 	elog(DEBUG_elog_output, " --- scan start --- ");
 #endif

-#define OVERLOAD_TEST	(Np->inout_p >= Np->inout + plen)
-
 	if (*Np->inout_p == ' ')
 		Np->inout_p++;

+#define OVERLOAD_TEST	(Np->inout_p >= Np->inout + plen)
+
+  	if (*Np->inout_p == ' ')
+  		Np->inout_p++;
+
 	if (OVERLOAD_TEST)
 		return;
-
+
 	/* ----------
 	 * read sign
 	 * ----------
@@ -2420,7 +2595,7 @@
 			Np->inout_p++;
 		}
 	}
-
+
 	if (OVERLOAD_TEST)
 		return;

@@ -2441,7 +2616,7 @@

 #ifdef DEBUG_TO_FROM_CHAR
 		elog(DEBUG_elog_output, "Read digit (%c).", *Np->inout_p);
-#endif
+#endif

 	/* ----------
 	 * read decimal point
@@ -3047,15 +3222,14 @@
 		return textin("");					\
 									\
 	result	= (text *) palloc( (len * NUM_MAX_ITEM_SIZ) + 1 + VARHDRSZ);	\
-	format = NUM_cache(len, CacheStr, CacheFormat, &CacheNum, &Num, \
-			VARDATA(fmt), &flag);				\
+	format  = NUM_cache(len, &Num, VARDATA(fmt), &flag);		\
 }

 /* ----------
  * MACRO: Finish part of NUM
  * ----------
  */
-#define NUM_TOCHAR_finish {							\
+#define NUM_TOCHAR_finish {						\
 									\
 	NUM_processor(format, &Num, VARDATA(result), 			\
 		numstr, plen, sign, TO_CHAR);				\
@@ -3064,21 +3238,29 @@
 	if (flag)							\
 		pfree(format);						\
 									\
-	VARSIZE(result) = strlen(VARDATA(result)) + VARHDRSZ; 	 	\
+	/* ----------							\
+	 * for result is allocated max memory, which current format-picture\
+	 * needs, now it must be re-allocate to result real size	\
+	 * ----------							\
+	 */								\
+	len 		= strlen(VARDATA(result));			\
+	result_tmp 	= result;					\
+	result 		= (text *) palloc( len + 1 + VARHDRSZ);		\
+									\
+	strcpy( VARDATA(result), VARDATA(result_tmp));  		\
+	VARSIZE(result) = len + VARHDRSZ; 				\
+	pfree(result_tmp);						\
 }

 /* -------------------
- * NUMERIC to_number()
+ * NUMERIC to_number() (convert string to numeric)
  * -------------------
  */
 Numeric
 numeric_to_number(text *value, text *fmt)
 {
-	static FormatNode	CacheFormat[ NUM_CACHE_SIZE +1];
-	static char		CacheStr[ NUM_CACHE_SIZE +1];
-	static NUMDesc		CacheNum;
-
 	NUMDesc			Num;
+	Numeric			result;
 	FormatNode		*format;
 	char 			*numstr;
 	int			flag=0;
@@ -3094,8 +3276,7 @@
 	if (!len)
 		return numeric_in(NULL, 0, 0);

-	format = NUM_cache(len, CacheStr, CacheFormat, &CacheNum, &Num,
-			VARDATA(fmt), &flag);
+	format = NUM_cache(len, &Num, VARDATA(fmt), &flag);

 	numstr	= (char *) palloc( (len * NUM_MAX_ITEM_SIZ) + 1);

@@ -3104,8 +3285,13 @@

 	scale = Num.post;
 	precision = MAX(0, Num.pre) + scale;
-
-	return numeric_in(numstr, 0, ((precision << 16) | scale) + VARHDRSZ);
+
+	if (flag)
+		pfree(format);
+
+	result = numeric_in(numstr, 0, ((precision << 16) | scale) + VARHDRSZ);
+	pfree(numstr);
+	return result;
 }

 /* ------------------
@@ -3115,16 +3301,13 @@
 text *
 numeric_to_char(Numeric value, text *fmt)
 {
-	static FormatNode	CacheFormat[ NUM_CACHE_SIZE +1];
-	static char		CacheStr[ NUM_CACHE_SIZE +1];
-	static NUMDesc		CacheNum;
-
 	NUMDesc			Num;
 	FormatNode		*format;
-	text 			*result;
+	text 			*result, *result_tmp;
 	int			flag=0;
 	int			len=0, plen=0, sign=0;
 	char			*numstr, *orgnum, *p;
+	Numeric 		x 	= NULL;

 	NUM_TOCHAR_prepare;

@@ -3133,18 +3316,29 @@
 	 * ----------
 	 */
 	if (IS_ROMAN(&Num)) {
-	 	numstr = orgnum = int_to_roman( numeric_int4( numeric_round(value, 0)));
+		x = numeric_round(value, 0);
+	 	numstr = orgnum = int_to_roman( numeric_int4( x ));
+	 	pfree(x);

 	} else {
-		Numeric val = value;
+		Numeric val 	= value;

 		if (IS_MULTI(&Num)) {
-			val = numeric_mul(value,
-				numeric_power(int4_numeric(10), int4_numeric(Num.multi)));
+			Numeric a = int4_numeric(10);
+			Numeric b = int4_numeric(Num.multi);
+
+			x = numeric_power(a, b);
+			val = numeric_mul(value, x);
+			pfree(x);
+			pfree(a);
+			pfree(b);
 			Num.pre += Num.multi;
 		}

-		orgnum = numeric_out( numeric_round(val, Num.post) );
+		x = numeric_round(val, Num.post);
+		orgnum = numeric_out( x );
+		pfree(x);
+
 		if (*orgnum == '-') { 					/* < 0 */
 			sign = '-';
 			numstr = orgnum+1;
@@ -3164,7 +3358,10 @@
 			fill_str(numstr, '#', Num.pre);
 			*(numstr + Num.pre) = '.';
 			fill_str(numstr + 1 + Num.pre, '#', Num.post);
-		}
+		}
+
+		if (IS_MULTI(&Num))
+			pfree(val);
 	}

 	NUM_TOCHAR_finish;
@@ -3178,13 +3375,9 @@
 text *
 int4_to_char(int32 value, text *fmt)
 {
-	static FormatNode	CacheFormat[ NUM_CACHE_SIZE +1];
-	static char		CacheStr[ NUM_CACHE_SIZE +1];
-	static NUMDesc		CacheNum;
-
 	NUMDesc			Num;
 	FormatNode		*format;
-	text 			*result;
+	text 			*result, *result_tmp;
 	int			flag=0;
 	int			len=0, plen=0, sign=0;
 	char			*numstr, *orgnum;
@@ -3247,13 +3440,9 @@
 text *
 int8_to_char(int64 *value, text *fmt)
 {
-	static FormatNode	CacheFormat[ NUM_CACHE_SIZE +1];
-	static char		CacheStr[ NUM_CACHE_SIZE +1];
-	static NUMDesc		CacheNum;
-
 	NUMDesc			Num;
 	FormatNode		*format;
-	text 			*result;
+	text 			*result, *result_tmp;
 	int			flag=0;
 	int			len=0, plen=0, sign=0;
 	char			*numstr, *orgnum;
@@ -3317,13 +3506,9 @@
 text *
 float4_to_char(float32 value, text *fmt)
 {
-	static FormatNode	CacheFormat[ NUM_CACHE_SIZE +1];
-	static char		CacheStr[ NUM_CACHE_SIZE +1];
-	static NUMDesc		CacheNum;
-
 	NUMDesc			Num;
 	FormatNode		*format;
-	text 			*result;
+	text 			*result, *result_tmp;
 	int			flag=0;
 	int			len=0, plen=0, sign=0;
 	char			*numstr, *orgnum, *p;
@@ -3385,13 +3570,9 @@
 text *
 float8_to_char(float64 value, text *fmt)
 {
-	static FormatNode	CacheFormat[ NUM_CACHE_SIZE +1];
-	static char		CacheStr[ NUM_CACHE_SIZE +1];
-	static NUMDesc		CacheNum;
-
 	NUMDesc			Num;
 	FormatNode		*format;
-	text 			*result;
+	text 			*result, *result_tmp;
 	int			flag=0;
 	int			len=0, plen=0, sign=0;
 	char			*numstr, *orgnum, *p;


Remove unused variable

Remove unused variable

--- src/strategies/avx2/picture-avx2.c
+++ src/strategies/avx2/picture-avx2.c
@@ -647,7 +647,6 @@
   __m256i diff = _mm256_setzero_si256();
   __m128i sum;

-  __m128i temp = _mm_setzero_si128();
   __m256i ref_epi16;
   __m256i rec_epi16;


avoid agglomeration with 0 threshold

avoid agglomeration with 0 threshold

--- DataStructures/Stack.h
+++ DataStructures/Stack.h
@@ -392,6 +392,7 @@
                 }

                 RagNode<Label> * node2 = rag->find_rag_node(spot1);
+
                 if (!node2) {
                     node2 = rag->insert_rag_node(spot1);
                 }
@@ -569,8 +570,13 @@

 void Stack::agglomerate_rag(double threshold)
 {
+    if (threshold == 0.0) {
+        return;
+    }
+
     MergePriority* priority = new ProbPriority(feature_mgr, rag);
     priority->initialize_priority(threshold);
+

     while (!(priority->empty())) {


Stream: client SSL certificates were not checked in some cases.

If ngx_stream_ssl_init_connection() succeeded immediately, the check was not
done.

The bug had appeared in 1.11.8 (41cb1b64561d).

--- src/stream/ngx_stream_ssl_module.c
+++ src/stream/ngx_stream_ssl_module.c
@@ -284,6 +284,7 @@
 {
     long                    rc;
     X509                   *cert;
+    ngx_int_t               rv;
     ngx_connection_t       *c;
     ngx_stream_ssl_conf_t  *sslcf;

@@ -305,7 +306,11 @@
             return NGX_ERROR;
         }

-        return ngx_stream_ssl_init_connection(&sslcf->ssl, c);
+        rv = ngx_stream_ssl_init_connection(&sslcf->ssl, c);
+
+        if (rv != NGX_OK) {
+            return rv;
+        }
     }

     if (sslcf->verify) {


actually use msg_queue in ip.c

actually use msg_queue in ip.c

msg_queue is defined but never used, hook it up so IP packets get queued instead of dropped when there is more than one.
change the name to ip_msg_queue to avoid naming conflicts.

--- sys/net/network_layer/sixlowpan/ip.c
+++ sys/net/network_layer/sixlowpan/ip.c
@@ -45,7 +45,7 @@

 uint8_t ip_send_buffer[BUFFER_SIZE];
 uint8_t buffer[BUFFER_SIZE];
-msg_t msg_queue[IP_PKT_RECV_BUF_SIZE];
+msg_t ip_msg_queue[IP_PKT_RECV_BUF_SIZE];
 ipv6_hdr_t *ipv6_buf;
 icmpv6_hdr_t *icmp_buf;
 uint8_t *nextheader;
@@ -268,6 +268,8 @@
     ipv6_addr_t myaddr;
     uint8_t i;
     uint16_t packet_length;
+
+    msg_init_queue(ip_msg_queue, IP_PKT_RECV_BUF_SIZE);

     ipv6_addr_init(&myaddr, 0xabcd, 0x0, 0x0, 0x0, 0x3612, 0x00ff, 0xfe00,
                    sixlowpan_mac_get_radio_address());