<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[134120] trunk/dports/science/lparse</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="https://trac.macports.org/changeset/134120">134120</a></dd>
<dt>Author</dt> <dd>larryv@macports.org</dd>
<dt>Date</dt> <dd>2015-03-18 14:04:13 -0700 (Wed, 18 Mar 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>lparse: Avoid namespace collisions (#41871)

A textbook case of the perils of &quot;using namespace std&quot;.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkdportssciencelparsePortfile">trunk/dports/science/lparse/Portfile</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkdportssciencelparsefilesavoidnamespacecollisionspatch">trunk/dports/science/lparse/files/avoid-namespace-collisions.patch</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkdportssciencelparsePortfile"></a>
<div class="modfile"><h4>Modified: trunk/dports/science/lparse/Portfile (134119 => 134120)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/dports/science/lparse/Portfile        2015-03-18 21:02:09 UTC (rev 134119)
+++ trunk/dports/science/lparse/Portfile        2015-03-18 21:04:13 UTC (rev 134120)
</span><span class="lines">@@ -29,7 +29,8 @@
</span><span class="cx">                     sha256  886d29723f7188296e48584a4a32b8f111414acb7ca8490af28ef6b7f1717298
</span><span class="cx"> 
</span><span class="cx"> patchfiles          fix-bison-version-detection.patch \
</span><del>-                    fix-recursive-make.patch
</del><ins>+                    fix-recursive-make.patch \
+                    avoid-namespace-collisions.patch
</ins><span class="cx"> 
</span><span class="cx"> # this configure argument is only used for installing
</span><span class="cx"> configure.pre_args  --prefix=${destroot}${prefix}/bin
</span></span></pre></div>
<a id="trunkdportssciencelparsefilesavoidnamespacecollisionspatch"></a>
<div class="addfile"><h4>Added: trunk/dports/science/lparse/files/avoid-namespace-collisions.patch (0 => 134120)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/dports/science/lparse/files/avoid-namespace-collisions.patch                                (rev 0)
+++ trunk/dports/science/lparse/files/avoid-namespace-collisions.patch        2015-03-18 21:04:13 UTC (rev 134120)
</span><span class="lines">@@ -0,0 +1,367 @@
</span><ins>+Step 1: Use &quot;`using namespace std`&quot;, polluting your global namespace.
+Step 2: Define identifiers like &quot;`hash`&quot; and &quot;`runtime_error`&quot;.
+Step 3: Wait years for C++ to incorporate those identifiers.
+Step 4: Watch modern compilers trip over the resulting collisions.
+Step 5: ???
+Step 6: Profit!
+
+Index: src/instance.cc
+===================================================================
+--- src/instance.cc.orig
++++ src/instance.cc
+@@ -287,7 +287,7 @@ void HashSet::Clear(int new_ar)
+ }

+ /* the hash algorithm is from
+-   http://ourworld.compuserve.com/homepages/bob_jenkins/evahash.htm */
++   https://web.archive.org/web/19990218144446/http://ourworld.compuserve.com/homepages/bob_jenkins/evahash.htm */


+ /* The mixing step */
+@@ -305,7 +305,7 @@ void HashSet::Clear(int new_ar)
+ }


+-unsigned long hash(const char *key, unsigned long length,
++unsigned long lparseHash(const char *key, unsigned long length,
+                    unsigned long initval)
+ {
+   u4 a, b, c; /* internal state */
+@@ -362,9 +362,9 @@ unsigned long HashSet::FindIndex(Instanc
+   else
+     table = items;
+   
+-  ind1 = hash((char *)key, arity*4, SEED_1) % mask;
++  ind1 = lparseHash((char *)key, arity*4, SEED_1) % mask;
+   if (table[ind1] &amp;&amp; !equal_item(key, table[ind1], arity))
+-    ind2 = (hash((char *)key, arity*4, SEED_2) % mask) + 1;
++    ind2 = (lparseHash((char *)key, arity*4, SEED_2) % mask) + 1;
+   else
+     return ind1;

+Index: src/error.h
+===================================================================
+--- src/error.h.orig
++++ src/error.h
+@@ -98,6 +98,6 @@ const char *error_file_and_line(long lin
+ // target system.

+ #include &quot;term.h&quot;
+-void runtime_error(InternalFunction f, ErrorType t, long a1 = 0, long a2 = 0);
++void lparse_runtime_error(InternalFunction f, ErrorType t, long a1 = 0, long a2 = 0);

+ #endif
+Index: src/library.cc
+===================================================================
+--- src/library.cc.orig
++++ src/library.cc
+@@ -164,7 +164,7 @@ long int_plus(int nargs, long *args )

+   for (i=0; i &lt; nargs; i++) {
+     if (IS_CONSTANT(args[i])) 
+-      runtime_error(FUN_PLUS, ERR_ARGUMENT, args[i]);
++      lparse_runtime_error(FUN_PLUS, ERR_ARGUMENT, args[i]);

+     result += args[i];
+   }
+@@ -175,25 +175,25 @@ long int_plus(int nargs, long *args )
+ long int_exp(int nargs, long *args )
+ {
+   if (nargs != 2) {
+-    runtime_error(FUN_EXP, ERR_NUMARGS, 2);
++    lparse_runtime_error(FUN_EXP, ERR_NUMARGS, 2);
+   }
+   long base = args[0];
+   long power = args[1];
+   long result = 1;
+   
+   if (IS_CONSTANT(args[0])) 
+-    runtime_error(FUN_EXP, ERR_ARGUMENT, args[0]);
++    lparse_runtime_error(FUN_EXP, ERR_ARGUMENT, args[0]);

+   if (IS_CONSTANT(args[1])) 
+-    runtime_error(FUN_EXP, ERR_ARGUMENT, args[1]);
++    lparse_runtime_error(FUN_EXP, ERR_ARGUMENT, args[1]);

+   if (power &lt; 0)
+-    runtime_error(FUN_EXP, ERR_ARGUMENT, args[1]);
++    lparse_runtime_error(FUN_EXP, ERR_ARGUMENT, args[1]);
+   
+   while (power--) {
+     result *= base;
+     if (IS_CONSTANT(result))
+-      runtime_error(FUN_EXP, ERR_OVERFLOW, 0);
++      lparse_runtime_error(FUN_EXP, ERR_OVERFLOW, 0);
+   }
+   return result;
+ }
+@@ -201,16 +201,16 @@ long int_exp(int nargs, long *args )
+ long int_norm(int nargs, long *args)
+ {
+   if (nargs != 1) {
+-    runtime_error(FUN_NORM, ERR_NUMARGS, 1);
++    lparse_runtime_error(FUN_NORM, ERR_NUMARGS, 1);
+   }
+   
+   if (args[0] &lt; 0 || args[0] &gt; predicate_table-&gt;Size())
+-    runtime_error(FUN_NORM, ERR_RANGE, args[0]);
++    lparse_runtime_error(FUN_NORM, ERR_RANGE, args[0]);

+   long p = args[0];

+   if (!predicates[p]-&gt;DomainPredicate())
+-    runtime_error(FUN_NORM, ERR_NONFIXED_EXTENSION, args[0]);
++    lparse_runtime_error(FUN_NORM, ERR_NONFIXED_EXTENSION, args[0]);
+   
+   if (predicates[p]-&gt;atoms)
+     return predicates[p]-&gt;atoms-&gt;Size();
+@@ -258,11 +258,11 @@ long int_minus(int nargs, long *args)
+   result = args[0];

+   if (IS_CONSTANT(result)) 
+-    runtime_error(FUN_MINUS, ERR_ARGUMENT, args[i]);
++    lparse_runtime_error(FUN_MINUS, ERR_ARGUMENT, args[i]);
+  
+   for (i = 1; i &lt; nargs; i++) { // '1' intentional
+     if (IS_CONSTANT(args[i])) 
+-      runtime_error(FUN_MINUS, ERR_ARGUMENT, args[i]);
++      lparse_runtime_error(FUN_MINUS, ERR_ARGUMENT, args[i]);

+     result -= args[i];
+   }
+@@ -277,7 +277,7 @@ long int_abs(int, long *args)
+   result = args[0];

+   if (IS_CONSTANT(result)) 
+-    runtime_error(FUN_ABS, ERR_ARGUMENT, result);
++    lparse_runtime_error(FUN_ABS, ERR_ARGUMENT, result);
+       
+   
+   if (result &lt; 0)
+@@ -300,7 +300,7 @@ long int_le(int nargs, long *args)

+   for (i = 1 ; i &lt; nargs; i++ ) { // '1' intentional
+     if (IS_CONSTANT(args[i]))
+-      runtime_error(FUN_LE, ERR_INVALID_COMPARE, args[0], args[i]);
++      lparse_runtime_error(FUN_LE, ERR_INVALID_COMPARE, args[0], args[i]);
+     
+     if (args[i] &lt; prior_value) {
+       result = 0;
+@@ -324,7 +324,7 @@ long int_ge(int nargs, long *args)
+   
+   for (i = 1 ; i &lt; nargs; i++ ) { // '1' intentional
+     if (IS_CONSTANT(args[i]))
+-      runtime_error(FUN_GE, ERR_INVALID_COMPARE, args[0],args[i]);
++      lparse_runtime_error(FUN_GE, ERR_INVALID_COMPARE, args[0],args[i]);

+     
+     if (args[i] &gt; prior_value) {
+@@ -349,7 +349,7 @@ long int_gt(int nargs, long *args)
+   
+   for (i = 1 ; i &lt; nargs; i++ ) { // '1' intentional
+     if (IS_CONSTANT(args[i]))
+-      runtime_error(FUN_GT, ERR_INVALID_COMPARE, args[0],args[i]);
++      lparse_runtime_error(FUN_GT, ERR_INVALID_COMPARE, args[0],args[i]);

+     if (args[i] &gt;= prior_value) {
+       result = 0;
+@@ -373,7 +373,7 @@ long int_lt(int nargs, long *args)
+   
+   for (i = 1 ; i &lt; nargs; i++ ) { // '1' intentional
+     if (IS_CONSTANT(args[i]))
+-      runtime_error(FUN_LT, ERR_INVALID_COMPARE, args[0], args[i]);
++      lparse_runtime_error(FUN_LT, ERR_INVALID_COMPARE, args[0], args[i]);

+     if (args[i] &lt;= prior_value) {
+       result = 0;
+@@ -408,11 +408,11 @@ long int_times(int nargs, long *args)
+   int i = 0;

+   if (IS_CONSTANT(result)) 
+-    runtime_error(FUN_TIMES, ERR_ARGUMENT, args[i]);
++    lparse_runtime_error(FUN_TIMES, ERR_ARGUMENT, args[i]);

+   for (i = 0; i &lt; nargs; i++) {
+     if (IS_CONSTANT(args[i])) 
+-      runtime_error(FUN_TIMES, ERR_ARGUMENT, args[i]);
++      lparse_runtime_error(FUN_TIMES, ERR_ARGUMENT, args[i]);

+     result *= args[i];
+   }
+@@ -425,14 +425,14 @@ long int_div(int nargs, long *args)
+   int i = 0;

+   if (IS_CONSTANT(result)) 
+-    runtime_error(FUN_DIV, ERR_ARGUMENT, args[i]);
++    lparse_runtime_error(FUN_DIV, ERR_ARGUMENT, args[i]);

+   for (i = 1; i &lt; nargs; i++) { // '1' intentional
+     if (IS_CONSTANT(args[i])) 
+-      runtime_error(FUN_DIV,ERR_ARGUMENT, args[i]);
++      lparse_runtime_error(FUN_DIV,ERR_ARGUMENT, args[i]);
+     
+     if (args[i] == 0) {
+-      runtime_error(FUN_DIV,ERR_DIVIDE_BY_ZERO, 0); 
++      lparse_runtime_error(FUN_DIV,ERR_DIVIDE_BY_ZERO, 0); 
+     } else {
+       result /= args[i];
+     }
+@@ -446,14 +446,14 @@ long int_mod(int nargs, long *args)
+   int i = 0;

+   if (IS_CONSTANT(result)) 
+-    runtime_error(FUN_MOD, ERR_ARGUMENT, args[i]);
++    lparse_runtime_error(FUN_MOD, ERR_ARGUMENT, args[i]);

+   for (i = 1; i &lt; nargs; i++) { // '1' intentional
+     if (IS_CONSTANT(args[i])) 
+-      runtime_error(FUN_MOD, ERR_ARGUMENT, args[i]);
++      lparse_runtime_error(FUN_MOD, ERR_ARGUMENT, args[i]);

+     if (args[i] == 0) {
+-      runtime_error(FUN_MOD, ERR_DIVIDE_BY_ZERO, 0); 
++      lparse_runtime_error(FUN_MOD, ERR_DIVIDE_BY_ZERO, 0); 
+     } else {
+       result %= args[i];
+       if (result &lt; 0)
+@@ -469,11 +469,11 @@ long int_and(int nargs, long *args)
+   int i = 0;

+   if (IS_CONSTANT(result)) 
+-    runtime_error(FUN_AND, ERR_ARGUMENT, args[i]);
++    lparse_runtime_error(FUN_AND, ERR_ARGUMENT, args[i]);
+   
+   for (i = 1; i &lt; nargs; i++) { // '1' intentional
+     if (IS_CONSTANT(args[i])) 
+-      runtime_error(FUN_AND, ERR_ARGUMENT, args[i]);
++      lparse_runtime_error(FUN_AND, ERR_ARGUMENT, args[i]);
+     
+     result &amp;= args[i];
+   }
+@@ -486,11 +486,11 @@ long int_or(int nargs, long *args)
+   int i = 0;

+   if (IS_CONSTANT(result)) 
+-    runtime_error(FUN_OR, ERR_ARGUMENT, args[i]);
++    lparse_runtime_error(FUN_OR, ERR_ARGUMENT, args[i]);

+   for (i = 1; i &lt; nargs; i++) { // '1' intentional
+     if (IS_CONSTANT(args[i])) 
+-      runtime_error(FUN_OR, ERR_ARGUMENT, args[i]);
++      lparse_runtime_error(FUN_OR, ERR_ARGUMENT, args[i]);

+     result |= args[i];
+   }
+@@ -503,11 +503,11 @@ long int_xor(int nargs, long *args)
+   int i = 0;

+   if (IS_CONSTANT(result)) 
+-    runtime_error(FUN_XOR, ERR_ARGUMENT, args[i]);
++    lparse_runtime_error(FUN_XOR, ERR_ARGUMENT, args[i]);

+   for (i = 1; i &lt; nargs; i++) { // '1' intentional
+     if (IS_CONSTANT(args[i])) 
+-      runtime_error(FUN_XOR, ERR_ARGUMENT, args[i]);
++      lparse_runtime_error(FUN_XOR, ERR_ARGUMENT, args[i]);

+     result ^= args[i];
+   }
+@@ -520,7 +520,7 @@ long int_not(int, long *args)
+   long result = args[0];

+   if (IS_CONSTANT(result)) 
+-    runtime_error(FUN_NOT, ERR_ARGUMENT, result);
++    lparse_runtime_error(FUN_NOT, ERR_ARGUMENT, result);
+   
+   result = ~result;
+   return result;
+@@ -540,7 +540,7 @@ long lt_string(int nargs, long *args)
+   for (int i = 1; i &lt; nargs; i++) {
+     second = constant_table-&gt;LookupByValue(args[i]);
+     if (!second)
+-      runtime_error(FUN_LT, ERR_INVALID_COMPARE, args[0], args[i]);
++      lparse_runtime_error(FUN_LT, ERR_INVALID_COMPARE, args[0], args[i]);

+     if (strcmp(first, second) &gt;= 0) {
+       result = 0;
+@@ -564,7 +564,7 @@ long le_string(int nargs, long *args)
+   for (int i = 1; i &lt; nargs; i++) {
+     second = constant_table-&gt;LookupByValue(args[i]);
+     if (!second)
+-      runtime_error(FUN_LE, ERR_INVALID_COMPARE,args[0], args[i]);
++      lparse_runtime_error(FUN_LE, ERR_INVALID_COMPARE,args[0], args[i]);

+     if (strcmp(first, second) &gt; 0) {
+       result = 0;
+@@ -589,7 +589,7 @@ long gt_string(int nargs, long *args)
+   for (int i = 1; i &lt; nargs; i++) {
+     second = constant_table-&gt;LookupByValue(args[i]);
+     if (!second)
+-      runtime_error(FUN_GT, ERR_INVALID_COMPARE, args[0],args[i]);
++      lparse_runtime_error(FUN_GT, ERR_INVALID_COMPARE, args[0],args[i]);

+     if (strcmp(first, second) &lt;= 0) {
+       result = 0;
+@@ -614,7 +614,7 @@ long ge_string(int nargs, long *args)
+   for (int i = 1; i &lt; nargs; i++) {
+     second = constant_table-&gt;LookupByValue(args[i]);
+     if (!second)
+-      runtime_error(FUN_GE, ERR_INVALID_COMPARE,args[0], args[i]);
++      lparse_runtime_error(FUN_GE, ERR_INVALID_COMPARE,args[0], args[i]);

+     if (strcmp(first, second) &lt; 0) {
+       result = 0;
+Index: src/extern.h
+===================================================================
+--- src/extern.h.orig
++++ src/extern.h
+@@ -76,7 +76,7 @@ extern LongList *command_line_constants;

+ extern LiteralList *implicit_domain_list;

+-unsigned long hash(const char *key, unsigned long length,
++unsigned long lparseHash(const char *key, unsigned long length,
+                    unsigned long initval);

+ // replacement of strdup that is not standard
+Index: src/symbol.cc
+===================================================================
+--- src/symbol.cc.orig
++++ src/symbol.cc
+@@ -127,9 +127,9 @@ unsigned long SymbolTable::FindIndex(con
+   else
+     table = items;
+   
+-  ind1 = hash(key, strlen(key), SEED_1) % mask;
++  ind1 = lparseHash(key, strlen(key), SEED_1) % mask;
+   if (table[ind1] &amp;&amp; strcmp(key, table[ind1]-&gt;symbol))
+-    ind2 = (hash(key, strlen(key), SEED_2) % mask) + 1;
++    ind2 = (lparseHash(key, strlen(key), SEED_2) % mask) + 1;
+   else 
+     return ind1;

+@@ -398,9 +398,9 @@ unsigned long FunctionTable::FindIndex(c
+   else
+     table = items;
+   
+-  ind1 = hash(key, strlen(key), SEED_1) % mask;
++  ind1 = lparseHash(key, strlen(key), SEED_1) % mask;
+   if (table[ind1] &amp;&amp; strcmp(key, table[ind1]-&gt;symbol))
+-    ind2 = (hash(key, strlen(key), SEED_2) % mask) + 1;
++    ind2 = (lparseHash(key, strlen(key), SEED_2) % mask) + 1;
+   else
+     return ind1;

+Index: src/error.cc
+===================================================================
+--- src/error.cc.orig
++++ src/error.cc
+@@ -343,7 +343,7 @@ void RuntimeError::Print()
+   output(cerr, &quot;\n&quot;);
+ }

+-void runtime_error(InternalFunction, ErrorType t, long a1, long a2)  
++void lparse_runtime_error(InternalFunction, ErrorType t, long a1, long a2)  
+ {
+   RuntimeError rt(t, a1, a2);
+   throw rt;
</ins></span></pre>
</div>
</div>

</body>
</html>