netsurf: branch tlsa/selection-search-refactor updated. release/3.0-83-gb25d7b5

NetSurf Browser Project (Commit Mailer) no-reply at netsurf-browser.org
Thu May 16 18:18:44 BST 2013


Gitweb links:

...log http://git.netsurf-browser.org/netsurf.git/shortlog/b25d7b5b5ea0495e61a8b7afc2bbca520d7e447d
...commit http://git.netsurf-browser.org/netsurf.git/commit/b25d7b5b5ea0495e61a8b7afc2bbca520d7e447d
...tree http://git.netsurf-browser.org/netsurf.git/tree/b25d7b5b5ea0495e61a8b7afc2bbca520d7e447d

The branch, tlsa/selection-search-refactor has been updated
       via  b25d7b5b5ea0495e61a8b7afc2bbca520d7e447d (commit)
       via  023c014ac439b03de4e45dd4cf567fe3a393bbf7 (commit)
       via  51a5febad7794ae9b57e1d6094d1b8429d88cd47 (commit)
       via  dd5ec71a1f05f22d8dfba477d8338761f9768488 (commit)
      from  6c1148c8c6e77c313eeb1e104da3c81ba1eb1822 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=b25d7b5b5ea0495e61a8b7afc2bbca520d7e447d
commit b25d7b5b5ea0495e61a8b7afc2bbca520d7e447d
Merge: 6c1148c 023c014
Author: Michael Drake <tlsa at netsurf-browser.org>
Commit: Michael Drake <tlsa at netsurf-browser.org>

    Merge branch 'master' of git://git.netsurf-browser.org/netsurf into tlsa/selection-search-refactor



-----------------------------------------------------------------------

Summary of changes:
 desktop/hotlist.c |    4 +++
 utils/utf8.c      |   63 ++++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 50 insertions(+), 17 deletions(-)

diff --git a/desktop/hotlist.c b/desktop/hotlist.c
index 20cc8ea..055de3a 100644
--- a/desktop/hotlist.c
+++ b/desktop/hotlist.c
@@ -199,9 +199,13 @@ unsigned int hotlist_get_tree_flags(void)
  */
 void hotlist_cleanup(const char *hotlist_path)
 {
+	LOG(("Exporting hotlist..."));
 	hotlist_export(hotlist_path);
+	LOG(("Releasing handles..."));
 	hlcache_handle_release(folder_icon);
+	LOG(("Clearing hotlist tree nodes..."));
 	tree_url_node_cleanup();
+	LOG(("Hotlist cleaned up."));
 }
 
 
diff --git a/utils/utf8.c b/utils/utf8.c
index 885ca94..127ffe6 100644
--- a/utils/utf8.c
+++ b/utils/utf8.c
@@ -198,6 +198,13 @@ static struct {
 	iconv_t cd;	/**< Iconv conversion descriptor */
 } last_cd;
 
+static inline void utf8_clear_cd_cache(void)
+{
+	last_cd.from[0] = '\0';
+	last_cd.to[0] = '\0';
+	last_cd.cd = 0;
+}
+
 /**
  * Finalise the UTF-8 library
  */
@@ -207,9 +214,7 @@ void utf8_finalise(void)
 		iconv_close(last_cd.cd);
 
 	/* paranoia follows */
-	last_cd.from[0] = '\0';
-	last_cd.to[0] = '\0';
-	last_cd.cd = 0;
+	utf8_clear_cd_cache();
 }
 
 /**
@@ -331,9 +336,7 @@ utf8_convert_ret utf8_convert(const char *string, size_t len,
 		/* clear the cached conversion descriptor as it's invalid */
 		if (last_cd.cd)
 			iconv_close(last_cd.cd);
-		last_cd.from[0] = '\0';
-		last_cd.to[0] = '\0';
-		last_cd.cd = 0;
+		utf8_clear_cd_cache();
 		/** \todo handle the various cases properly
 		 * There are 3 possible error cases:
 		 * a) Insufficiently large output buffer
@@ -411,21 +414,43 @@ utf8_convert_ret utf8_to_html(const char *string, const char *encname,
 	if (len == 0)
 		len = strlen(string);
 
-	cd = iconv_open(encname, "UTF-8");
-	if (cd == (iconv_t) -1) {
-		if (errno == EINVAL)
-			return UTF8_CONVERT_BADENC;
-		/* default to no memory */
-		return UTF8_CONVERT_NOMEM;
+	/* we cache the last used conversion descriptor,
+	 * so check if we're trying to use it here */
+	if (strncasecmp(last_cd.from, "UTF-8", sizeof(last_cd.from)) == 0 &&
+			strncasecmp(last_cd.to, encname,
+					sizeof(last_cd.to)) == 0 &&
+			last_cd.cd != 0) {
+		cd = last_cd.cd;
+	}
+	else {
+		/* no match, so create a new cd */
+		cd = iconv_open(encname, "UTF-8");
+		if (cd == (iconv_t) -1) {
+			if (errno == EINVAL)
+				return UTF8_CONVERT_BADENC;
+			/* default to no memory */
+			return UTF8_CONVERT_NOMEM;
+		}
+
+		/* close the last cd - we don't care if this fails */
+		if (last_cd.cd)
+			iconv_close(last_cd.cd);
+
+		/* and copy the to/from/cd data into last_cd */
+		strncpy(last_cd.from, "UTF-8", sizeof(last_cd.from));
+		strncpy(last_cd.to, encname, sizeof(last_cd.to));
+		last_cd.cd = cd;
 	}
 
 	/* Worst case is ASCII -> UCS4, with all characters escaped: 
 	 * "&#xYYYYYY;", thus each input character may become a string 
-	 * of 10 UCS4 characters, each 4 bytes in length */
-	origoutlen = outlen = len * 10 * 4;
+	 * of 10 UCS4 characters, each 4 bytes in length, plus four for
+	 * terminating the string */
+	origoutlen = outlen = len * 10 * 4 + 4;
 	origout = out = malloc(outlen);
 	if (out == NULL) {
 		iconv_close(cd);
+		utf8_clear_cd_cache();
 		return UTF8_CONVERT_NOMEM;
 	}
 
@@ -444,6 +469,7 @@ utf8_convert_ret utf8_to_html(const char *string, const char *encname,
 				if (ret != UTF8_CONVERT_OK) {
 					free(origout);
 					iconv_close(cd);
+					utf8_clear_cd_cache();
 					return ret;
 				}
 			}
@@ -457,6 +483,7 @@ utf8_convert_ret utf8_to_html(const char *string, const char *encname,
 			if (ret != UTF8_CONVERT_OK) {
 				free(origout);
 				iconv_close(cd);
+				utf8_clear_cd_cache();
 				return ret;
 			}
 
@@ -474,19 +501,21 @@ utf8_convert_ret utf8_to_html(const char *string, const char *encname,
 		if (ret != UTF8_CONVERT_OK) {
 			free(origout);
 			iconv_close(cd);
+			utf8_clear_cd_cache();
 			return ret;
 		}
 	}
 
-	iconv_close(cd);
+	/* Terminate string */
+	memset(out, 0, 4);
+	outlen -= 4;
 
 	/* Shrink-wrap */
-	*result = realloc(origout, origoutlen - outlen + 4);
+	*result = realloc(origout, origoutlen - outlen);
 	if (*result == NULL) {
 		free(origout);
 		return UTF8_CONVERT_NOMEM;
 	}
-	memset(*result + (origoutlen - outlen), 0, 4);
 
 	return UTF8_CONVERT_OK;
 }


-- 
NetSurf Browser



More information about the netsurf-commits mailing list