free barriers properly

free barriers properly

--- arangod/V8Server/v8-query.cpp
+++ arangod/V8Server/v8-query.cpp
@@ -73,6 +73,16 @@
 #define WRAP_SHAPED_JSON(...) TRI_WrapShapedJson<ReadTransactionType>(__VA_ARGS__)

 ////////////////////////////////////////////////////////////////////////////////
+/// @brief free barrier if set
+////////////////////////////////////////////////////////////////////////////////
+
+#define FREE_BARRIER(barrier) \
+  if (barrier != 0) {         \
+    TRI_FreeBarrier(barrier); \
+    barrier = 0;              \
+  }
+
+////////////////////////////////////////////////////////////////////////////////
 /// @}
 ////////////////////////////////////////////////////////////////////////////////

@@ -1114,11 +1124,19 @@
     TRI_V8_EXCEPTION(scope, TRI_ERROR_ARANGO_NO_INDEX);
   }

-  TRI_barrier_t* barrier = 0;
   TRI_voc_ssize_t total = 0;
   TRI_voc_size_t count = 0;
   bool error = false;

+  TRI_barrier_t* barrier = TRI_CreateBarrierElement(&primary->_barrierList);
+
+  if (barrier == 0) {
+    TRI_FreeSkiplistIterator(skiplistIterator);
+    TRI_V8_EXCEPTION_MEMORY(scope);
+  }
+
+  assert(barrier != 0);
+
   while (true) {
     TRI_skiplist_index_element_t* indexElement = skiplistIterator->_next(skiplistIterator);

@@ -1129,14 +1147,6 @@
     ++total;

     if (total > skip && count < limit) {
-      if (barrier == 0) {
-        barrier = TRI_CreateBarrierElement(&primary->_barrierList);
-        if (barrier == 0) {
-          error = true;
-          break;
-        }
-      }
-
       v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, (TRI_doc_mptr_t const*) indexElement->_document, barrier);

       if (doc.IsEmpty()) {
@@ -1164,7 +1174,12 @@
   result->Set(v8::String::New("count"), v8::Number::New(count));

   if (error) {
+    FREE_BARRIER(barrier);
     TRI_V8_EXCEPTION_MEMORY(scope);
+  }
+
+  if (count == 0) {
+    FREE_BARRIER(barrier);
   }

   return scope.Close(result);
@@ -1323,11 +1338,19 @@
   TRI_voc_ssize_t total = 0;
   TRI_voc_size_t count = 0;
   bool error = false;
+
+  TRI_barrier_t* barrier = TRI_CreateBarrierElement(&primary->_barrierList);
+
+  if (barrier == 0) {
+    if (indexIterator != NULL) {
+      TRI_FreeIndexIterator(indexIterator);
+    }
+    TRI_V8_EXCEPTION_MEMORY(scope);
+  }
+
+  assert(barrier != 0);

   if (indexIterator != NULL) {
-    TRI_barrier_t* barrier = 0;
-
-
     while (true) {
       TRI_doc_mptr_t* data = (TRI_doc_mptr_t*) indexIterator->_next(indexIterator);

@@ -1335,19 +1358,9 @@
         break;
       }

-
       ++total;

       if (total > skip && count < limit) {
-        if (barrier == 0) {
-          barrier = TRI_CreateBarrierElement(&primary->_barrierList);
-
-          if (barrier == 0) {
-            error = true;
-            break;
-          }
-        }
-
         v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, data, barrier);

         if (doc.IsEmpty()) {
@@ -1361,10 +1374,8 @@
       }
     }

-
     // free data allocated by index result
     TRI_FreeIndexIterator(indexIterator);
-
   }

   else {
@@ -1383,7 +1394,12 @@
   result->Set(v8::String::New("count"), v8::Number::New(count));

   if (error) {
+    FREE_BARRIER(barrier);
     TRI_V8_EXCEPTION_MEMORY(scope);
+  }
+
+  if (count == 0) {
+    FREE_BARRIER(barrier);
   }

   return scope.Close(result);
@@ -1501,6 +1517,7 @@
   TRI_Free(TRI_UNKNOWN_MEM_ZONE, tmp);

   if (error) {
+    FREE_BARRIER(barrier);
     return TRI_ERROR_OUT_OF_MEMORY;
   }

@@ -1581,9 +1598,14 @@

   trx.lockRead();

-  TRI_barrier_t* barrier = 0;
   uint32_t count = 0;
   bool error = false;
+
+  TRI_barrier_t* barrier = TRI_CreateBarrierElement(&primary->_barrierList);
+
+  if (barrier == 0) {
+    TRI_V8_EXCEPTION_MEMORY(scope);
+  }

   // argument is a list of vertices
   if (argv[0]->IsArray()) {
@@ -1609,14 +1631,6 @@
       }

       for (size_t j = 0;  j < edges._length;  ++j) {
-        if (barrier == 0) {
-          barrier = TRI_CreateBarrierElement(&primary->_barrierList);
-          if (barrier == 0) {
-            error = true;
-            break;
-          }
-        }
-
         v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, (TRI_doc_mptr_t const*) edges._buffer[j], barrier);

         if (doc.IsEmpty()) {
@@ -1649,6 +1663,7 @@
     res = TRI_ParseVertex(resolver, cid, key, argv[0], true);

     if (res != TRI_ERROR_NO_ERROR) {
+      FREE_BARRIER(barrier);
       TRI_V8_EXCEPTION(scope, res);
     }

@@ -1659,14 +1674,6 @@
     }

     for (size_t j = 0;  j < edges._length;  ++j) {
-      if (barrier == 0) {
-        barrier = TRI_CreateBarrierElement(&primary->_barrierList);
-        if (barrier == 0) {
-          error = true;
-          break;
-        }
-      }
-
       v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, (TRI_doc_mptr_t const*) edges._buffer[j], barrier);

       if (doc.IsEmpty()) {
@@ -1689,7 +1696,12 @@
   // .............................................................................

   if (error) {
+    FREE_BARRIER(barrier);
     TRI_V8_EXCEPTION_MEMORY(scope);
+  }
+
+  if (count == 0) {
+    FREE_BARRIER(barrier);
   }

   return scope.Close(documents);
@@ -1751,6 +1763,7 @@
   res = trx.finish(res);

   if (res != TRI_ERROR_NO_ERROR) {
+    FREE_BARRIER(barrier);
     TRI_V8_EXCEPTION(scope, res);
   }

@@ -1771,6 +1784,7 @@
     v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, &docs[i], barrier);

     if (doc.IsEmpty()) {
+      FREE_BARRIER(barrier);
       TRI_V8_EXCEPTION_MEMORY(scope);
     }
     else {
@@ -1780,6 +1794,10 @@

   result->Set(v8::String::New("total"), v8::Number::New(total));
   result->Set(v8::String::New("count"), v8::Number::New(count));
+
+  if (count == 0) {
+    FREE_BARRIER(barrier);
+  }

   return scope.Close(result);
 }
@@ -1831,6 +1849,7 @@
   res = trx.finish(res);

   if (res != TRI_ERROR_NO_ERROR) {
+    FREE_BARRIER(barrier);
     TRI_V8_EXCEPTION(scope, res);
   }

@@ -1851,6 +1870,7 @@
     v8::Handle<v8::Value> document = WRAP_SHAPED_JSON(trx, col->_cid, &docs[i], barrier);

     if (document.IsEmpty()) {
+      FREE_BARRIER(barrier);
       TRI_V8_EXCEPTION_MEMORY(scope);
     }
     else {
@@ -1861,6 +1881,10 @@
   result->Set(v8::String::New("total"), v8::Number::New(total));
   result->Set(v8::String::New("count"), v8::Number::New(count));
   result->Set(v8::String::New("skip"), v8::Number::New(internalSkip));
+
+  if (count == 0) {
+    FREE_BARRIER(barrier);
+  }

   return scope.Close(result);
 }
@@ -1909,23 +1933,20 @@
   res = trx.finish(res);

   if (res != TRI_ERROR_NO_ERROR) {
-    if (barrier != 0) {
-      TRI_FreeBarrier(barrier);
-    }
-
+    FREE_BARRIER(barrier);
     TRI_V8_EXCEPTION(scope, res);
   }

   if (document._data == 0 || document._key == 0) {
-    if (barrier != 0) {
-      TRI_FreeBarrier(barrier);
-    }
+    FREE_BARRIER(barrier);

     return scope.Close(v8::Null());
   }

   v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, &document, barrier);
+
   if (doc.IsEmpty()) {
+    FREE_BARRIER(barrier);
     TRI_V8_EXCEPTION_MEMORY(scope);
   }

@@ -2013,35 +2034,35 @@
   size_t total = filtered._length;
   size_t count = 0;
   bool error = false;
+
+  TRI_barrier_t* barrier = 0;
+
+  if (total > 0) {
+    barrier = TRI_CreateBarrierElement(&primary->_barrierList);
+
+    if (barrier == 0) {
+      TRI_DestroyVector(&filtered);
+      TRI_V8_EXCEPTION_MEMORY(scope);
+    }
+  }

   if (0 < total) {
-    size_t s;
-    size_t e;
-
+    assert(barrier != 0);
+
+    size_t s, e;
     CalculateSkipLimitSlice(filtered._length, skip, limit, s, e);

-    if (s < e) {
-      // only go in here if something has to be done, otherwise barrier memory might be lost
-      TRI_barrier_t* barrier = TRI_CreateBarrierElement(&primary->_barrierList);
-      if (barrier == 0) {
+    for (size_t j = s; j < e; ++j) {
+      TRI_doc_mptr_t* mptr = (TRI_doc_mptr_t*) TRI_AtVector(&filtered, j);
+
+      v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, mptr, barrier);
+
+      if (doc.IsEmpty()) {
         error = true;
+        break;
       }
       else {
-        for (size_t j = s; j < e; ++j) {
-          TRI_doc_mptr_t* mptr = (TRI_doc_mptr_t*) TRI_AtVector(&filtered, j);
-
-          v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, mptr, barrier);
-
-          if (doc.IsEmpty()) {
-            error = true;
-            break;
-          }
-          else {
-            documents->Set(count, doc);
-            ++count;
-          }
-
-        }
+        documents->Set(count++, doc);
       }
     }
   }
@@ -2060,7 +2081,12 @@
   CleanupExampleObject(shaper->_memoryZone, n, pids, values);

   if (error) {
+    FREE_BARRIER(barrier);
     TRI_V8_EXCEPTION_MEMORY(scope);
+  }
+
+  if (count == 0) {
+    FREE_BARRIER(barrier);
   }

   return scope.Close(result);
@@ -2138,32 +2164,29 @@
   size_t total = list._length;
   size_t count = 0;
   bool error = false;
+
+  TRI_barrier_t* barrier = 0;

   if (0 < total) {
-    size_t s;
-    size_t e;
-
+    barrier = TRI_CreateBarrierElement(&primary->_barrierList);
+
+    if (barrier == 0) {
+      TRI_DestroyIndexResult(&list);
+      TRI_V8_EXCEPTION_MEMORY(scope);
+    }
+
+    size_t s, e;
     CalculateSkipLimitSlice(total, skip, limit, s, e);

-    if (s < e) {
-      TRI_barrier_t* barrier = TRI_CreateBarrierElement(&primary->_barrierList);
-      if (barrier == 0) {
+    for (size_t i = s;  i < e;  ++i) {
+      v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, collection->_cid, list._documents[i], barrier);
+
+      if (doc.IsEmpty()) {
         error = true;
+        break;
       }
       else {
-        for (size_t i = s;  i < e;  ++i) {
-          v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, collection->_cid, list._documents[i], barrier);
-
-          if (doc.IsEmpty()) {
-            error = true;
-            break;
-          }
-          else {
-            documents->Set(count, doc);
-            ++count;
-          }
-
-        }
+        documents->Set(count++, doc);
       }
     }
   }
@@ -2175,7 +2198,12 @@
   result->Set(v8::String::New("count"), v8::Number::New(count));

   if (error) {
+    FREE_BARRIER(barrier);
     TRI_V8_EXCEPTION_MEMORY(scope);
+  }
+
+  if (count == 0) {
+    FREE_BARRIER(barrier);
   }

   return scope.Close(result);
@@ -2536,7 +2564,7 @@
   assert(barrier != 0);

   if (n == 0) {
-    TRI_FreeBarrier(barrier);
+    FREE_BARRIER(barrier);
   }

   if (returnList) {
@@ -2551,6 +2579,7 @@
         // error
         trx.finish(res);

+        FREE_BARRIER(barrier);
         TRI_V8_EXCEPTION_MEMORY(scope);
       }

@@ -2573,6 +2602,7 @@
     trx.finish(res);

     if (result.IsEmpty()) {
+      FREE_BARRIER(barrier);
       TRI_V8_EXCEPTION_MEMORY(scope);
     }

@@ -2667,6 +2697,7 @@
   TRI_FreeResultFulltextIndex(queryResult);

   if (error) {
+    FREE_BARRIER(barrier);
     TRI_V8_EXCEPTION_MEMORY(scope);
   }

@@ -2795,7 +2826,7 @@
   assert(barrier != 0);

   if (n == 0) {
-    TRI_FreeBarrier(barrier);
+    FREE_BARRIER(barrier);
   }

   if (returnList) {
@@ -2810,6 +2841,7 @@
         // error
         trx.finish(res);

+        FREE_BARRIER(barrier);
         TRI_V8_EXCEPTION_MEMORY(scope);
       }

@@ -2832,6 +2864,7 @@
     trx.finish(res);

     if (result.IsEmpty()) {
+      FREE_BARRIER(barrier);
       TRI_V8_EXCEPTION_MEMORY(scope);
     }


remove warning

remove warning

--- src/condor_c++_util/memory_file.C
+++ src/condor_c++_util/memory_file.C
@@ -128,7 +128,7 @@
 ssize_t memory_file::read( char *data, size_t length )
 {

-	if( (data==0) || (length<0) || (pointer<0) ) return -1;
+	if( (data==0) || (pointer<0) ) return -1;
 	if( pointer>=filesize ) return 0;

 	if(length==0) return 0;
@@ -147,7 +147,7 @@

 ssize_t memory_file::write( char *data, size_t length )
 {
-	if( (data==0) || (length<0) || (pointer<0) ) return -1;
+	if( (data==0) || (pointer<0) ) return -1;

 	if(length==0) return 0;


Remove dead code

Remove dead code

--- src/condor_chirp/condor_chirp.cpp
+++ src/condor_chirp/condor_chirp.cpp
@@ -1048,5 +1048,4 @@
 		printf("\tError: %d (%s)\n", errno, strerror(errno));
 	}
 	return ret_val;
-	exit(-1);
-}
+}


fix: initialization of Texture m_data

fix: initialization of Texture m_data

--- core/src/gl/texture.cpp
+++ core/src/gl/texture.cpp
@@ -66,10 +66,15 @@

 void Texture::setSubData(const GLuint* _subData, unsigned int _xoff, unsigned int _yoff, unsigned int _width,
                          unsigned int _height) {
+    size_t bpp = bytesPerPixel();
+    size_t divisor = sizeof(GLuint) / bpp;
+
+    // Init m_data if update() was not called after resize()
+    if (m_data.size() != (m_width * m_height) / divisor) {
+        m_data.resize((m_width * m_height) / divisor);
+    }

     // update m_data with subdata
-    size_t bpp = bytesPerPixel();
-    size_t divisor = sizeof(GLuint) / bpp;
     for (size_t j = 0; j < _height; j++) {
         size_t dpos = ((j + _yoff) * m_width + _xoff) / divisor;
         size_t spos = (j * _width) / divisor;
@@ -126,7 +131,10 @@

         generate(_textureUnit);

-        if (m_data.size() == 0) { m_data.assign(m_width * m_height, 0); }
+        if (m_data.size() == 0) {
+            size_t divisor = sizeof(GLuint) / bytesPerPixel();
+            m_data.resize((m_width * m_height) / divisor, 0);
+        }

     } else {
         bind(_textureUnit);


FlatMeshNode: don't skip first frame

FlatMeshNode: don't skip first frame

--- src/controls/src/flatmeshnode.cpp
+++ src/controls/src/flatmeshnode.cpp
@@ -152,9 +152,12 @@
 void FlatMeshNode::maybeAnimate()
 {
     static QElapsedTimer t;
-    if(!t.isValid()) t.start();
-    if (m_animated && t.elapsed() >= 100) {
-        t.restart();
+    bool firstFrame = false;
+    if(!t.isValid()) {
+        t.start();
+        firstFrame = true;
+    }
+    if (firstFrame || (m_animated && t.restart() >= 100)) {
         m_animationState += 0.03;

         /* Interpolate all points positions according to the animationState */
@@ -166,28 +169,30 @@
         }

         /* Update all triangles' geometries according to the new points position */
+        qreal lastCenterX = m_unitWidth*(NUM_POINTS_X-1);
+        qreal lastcenterY = m_unitHeight*(NUM_POINTS_Y-1);
         QSGGeometryNode *triangle = static_cast<QSGGeometryNode *>(firstChild());
         for(int i = 0; i < NUM_POINTS_X*NUM_POINTS_Y; i++) {
-            if(m_points[i].centerX != m_unitWidth*(NUM_POINTS_X-1) && m_points[i].centerY != m_unitHeight*(NUM_POINTS_Y-1)) {
+            if(m_points[i].centerX != lastCenterX && m_points[i].centerY != lastcenterY) {
                 int random = rand()%2;
                 for(int n = 0; n < 2; n++) {
                     QSGGeometry::Point2D *v = triangle->geometry()->vertexDataAsPoint2D();
-                    if(random==0) {
-                        if(n==0) {
+                    if(random) {
+                        if(n) {
                             v[0] = m_points[i].currentPos;
                             v[1] = m_points[i+NUM_POINTS_X].currentPos;
                             v[2] = m_points[i+NUM_POINTS_X+1].currentPos;
-                        } else if(n==1) {
+                        } else {
                             v[0] = m_points[i].currentPos;
                             v[1] = m_points[i+1].currentPos;
                             v[2] = m_points[i+NUM_POINTS_X+1].currentPos;
                         }
                     } else {
-                        if(n==0) {
+                        if(n) {
                             v[0] = m_points[i].currentPos;
                             v[1] = m_points[i+NUM_POINTS_X].currentPos;
                             v[2] = m_points[i+1].currentPos;
-                        } else if(n==1) {
+                        } else {
                             v[0] = m_points[i+NUM_POINTS_X].currentPos;
                             v[1] = m_points[i+1].currentPos;
                             v[2] = m_points[i+NUM_POINTS_X+1].currentPos;


Fixes: NB#299639 - The location of dragger is changed when moving another dragger through it to the edge of the search input field in Messaging.

RevBy: Heikki Holstila, Adrian Yanes
Details: Need to emit selection changed signal in one more place to make selection handles update properly.

--- src/corelib/widgets/mtextedit.cpp
+++ src/corelib/widgets/mtextedit.cpp
@@ -1783,6 +1783,7 @@
     QTextCursor *currentCursor = d->cursor();
     if (anchorPosition == currentCursor->anchor() && newCursorPosition == currentCursor->position()
         && model()->enabledSelectionControls() == selectionControls) {
+        emit selectionChanged(); // for updating selection handles
         return;
     }


Crowdin: fix logic error in handling of v1 auth tokens

Pre-existing old tokens from Poedit versions older than 2.3 were not
handled correctly: instead of ignoring them, Poedit would partially
use them and get into a state where no API client was created (due to
lack of auth token), but other code thought that Crowdin was available.
This resulted in crash when any Crowdin-related UI was shown.

Fixes #725.

--- src/crowdin_client.cpp
+++ src/crowdin_client.cpp
@@ -560,7 +560,11 @@
     {
         token = token.substr(2);
     }
-    // else: 'token' is empty string
+    else
+    {
+        // 'token' is empty or invalid, make sure it is empty
+        token.clear();
+    }

     m_cachedAuthToken = std::make_unique<std::string>(token);
     return token;


rm var print

rm var print

--- src/maiken/process.cpp
+++ src/maiken/process.cpp
@@ -72,9 +72,8 @@
 }  // namespace maiken

 void maiken::Application::process() KTHROW(kul::Exception) {
-  const kul::hash::set::String &cmds(CommandStateMachine::INSTANCE().commands());
-  const auto gEnvVars = maiken::AppVars::INSTANCE().envVars();
-  for(auto const& ev : gEnvVars) KLOG(INF) << ev.first << " : " << ev.second;
+  auto const& cmds = CommandStateMachine::INSTANCE().commands();
+  auto const& gEnvVars = maiken::AppVars::INSTANCE().envVars();

   kul::os::PushDir pushd(this->project().dir());
   auto loadModules = [&](Application &app) {


Added comment

Added comment

git-svn-id: 27238e37a5eae711b76ec703b45445819ea9563e@592 c3353b84-d008-0410-9ed9-b55c4f7fa7e8

--- libpqxx/test/test004.cxx
+++ libpqxx/test/test004.cxx
@@ -100,6 +100,9 @@
       if (notifs)
 	throw logic_error("Got " + to_string(notifs) +
 	    " unexpected notification(s)!");
+      // Sleep one second using a libpqxx-internal function.  Kids, don't try
+      // this at home!  The pqxx::internal namespace is not for third-party use
+      // and may change radically at any time.
       pqxx::internal::sleep_seconds(1);
       notifs = C.get_notifs();
       cout << ".";


Always check return of stat #6345

Always check return of stat #6345


Fixed times reported for `FileInfo` on 32bit linux.

--- src/main/cpp/posix.cpp
+++ src/main/cpp/posix.cpp
@@ -76,7 +76,7 @@
 }

 jlong timestamp(struct timespec t) {
-    return t.tv_sec * 1000 + t.tv_nsec / 1000;
+    return (jlong)(t.tv_sec) * 1000 + (jlong)(t.tv_nsec) / 1000;
 }

 JNIEXPORT void JNICALL
@@ -130,9 +130,9 @@
         }
         env->SetLongField(dest, blockSizeField, fileInfo.st_blksize);
 #ifdef __linux__
-        env->SetLongField(dest, accessTimeField, fileInfo.st_atime * 1000);
-        env->SetLongField(dest, modificationTimeField, fileInfo.st_mtime * 1000);
-        env->SetLongField(dest, statusChangeTime, fileInfo.st_ctime * 1000);
+        env->SetLongField(dest, accessTimeField, timestamp(fileInfo.st_atim));
+        env->SetLongField(dest, modificationTimeField, timestamp(fileInfo.st_mtim));
+        env->SetLongField(dest, statusChangeTime, timestamp(fileInfo.st_ctim));
 #else
         env->SetLongField(dest, accessTimeField, timestamp(fileInfo.st_atimespec));
         env->SetLongField(dest, modificationTimeField, timestamp(fileInfo.st_mtimespec));


Changes to documentation

Changes to documentation

--- src/impl/getcpinfo.cpp
+++ src/impl/getcpinfo.cpp
@@ -16,7 +16,7 @@
 //! @parblock
 //! An UINT Identifier for the code page for which to retrieve information.
 //! See Code Page Identifiers for details
-//! 65001 in the number for UTF8.  It is the only valid inpur parameter
+//! 65001 in the number for UTF8.  It is the only valid input parameter
 //!because Linux and Unix only use UTF8 for codepage
 //!
 //! @endparblock
@@ -28,6 +28,13 @@
 //! LPCPINFO is a pointer to the structure _cpinfo used to contain the information
 //! about a code page
 //!
+//!
+//! typedef struct _cpinfo {
+//!    UINT MaxCharSize;
+//!    BYTE DefaultChar[MAX_DEFAULTCHAR];
+//!    BYTE LeadByte[MAX_LEADBYTES];
+//! } CPINFO, *LPCPINFO;
+//!
 //! _cpinfo is a struct that comprises
 //!
 //! UINT MaxCharSize;
@@ -70,8 +77,8 @@
 //! extended error information, call GetLastError.
 //!
 //! [MSDN documentation]:https://msdn.microsoft.com/en-us/library/windows/desktop/dd318078%28v=vs.85%29.aspx
-//! [_cpinfo]: https://msdn.microsoft.com/en-us/library/windows/desktop/dd317780%28v=vs.85%29.aspx
-//! [CodePageIdentifiers] https://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx
+//! [_cpinfo]: https://msdn.microsoft.com/en-us/library/windows/desktop/dd317780(v=vs.85).aspx
+//! [CodePageIdentifiers] https://msdn.microsoft.com/en-us/library/windows/desktop/dd317756(v=vs.85).aspx

 BOOL GetCPInfoW(UINT codepage, CPINFO* cpinfo)
 {
@@ -87,7 +94,6 @@
         return FALSE;
     }

-    // 65001 is the code page for UTF8, Linux and Unix default it UTF8
     if (codepage != const_cpinfo::UTF8)
     {
         //If other value is used return error because Linux and Unix only used UTF-8 for codepage
@@ -99,12 +105,13 @@
     cpinfo->DefaultChar[0] = '?';
     cpinfo->DefaultChar[1] = '0';
     cpinfo->MaxCharSize = 4;
+
     for (int i = 0; i < const_cpinfo::MAX_LEADBYTES; i++ )
     {
         // UTF-8 uses the default has no LeadByte as result LeadByte is '0'
-        cpinfo->LeadByte[i] = '0';
-
+        cpinfo->LeadByte[i] = '0';
     }
+
     return TRUE;

 }


Format posix.cpp

Format posix.cpp

--- src/main/cpp/posix.cpp
+++ src/main/cpp/posix.cpp
@@ -19,25 +19,25 @@
  */
 #ifndef _WIN32

+#include "generic.h"
 #include "net_rubygrapefruit_platform_internal_jni_NativeLibraryFunctions.h"
 #include "net_rubygrapefruit_platform_internal_jni_PosixFileFunctions.h"
 #include "net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions.h"
 #include "net_rubygrapefruit_platform_internal_jni_PosixTerminalFunctions.h"
 #include "net_rubygrapefruit_platform_internal_jni_PosixTypeFunctions.h"
-#include "generic.h"
+#include <dirent.h>
+#include <errno.h>
 #include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
 #include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
+#include <sys/utsname.h>
+#include <termios.h>
 #include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/utsname.h>
-#include <dirent.h>
-#include <string.h>
-#include <termios.h>
-
-JNIEXPORT void JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_NativeLibraryFunctions_getSystemInfo(JNIEnv *env, jclass target, jobject info, jobject result) {
+
+JNIEXPORT void JNICALL
+Java_net_rubygrapefruit_platform_internal_jni_NativeLibraryFunctions_getSystemInfo(JNIEnv* env, jclass target, jobject info, jobject result) {
     jclass infoClass = env->GetObjectClass(info);

     struct utsname machine_info;
@@ -57,7 +57,7 @@
 }

 JNIEXPORT void JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_PosixTypeFunctions_getNativeTypeInfo(JNIEnv *env, jclass target, jobject info) {
+Java_net_rubygrapefruit_platform_internal_jni_PosixTypeFunctions_getNativeTypeInfo(JNIEnv* env, jclass target, jobject info) {
     jclass infoClass = env->GetObjectClass(info);
     env->SetIntField(info, env->GetFieldID(infoClass, "int_bytes", "I"), sizeof(int));
     env->SetIntField(info, env->GetFieldID(infoClass, "u_long_bytes", "I"), sizeof(u_long));
@@ -72,7 +72,7 @@
  */

 JNIEXPORT void JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_PosixFileFunctions_chmod(JNIEnv *env, jclass target, jstring path, jint mode, jobject result) {
+Java_net_rubygrapefruit_platform_internal_jni_PosixFileFunctions_chmod(JNIEnv* env, jclass target, jstring path, jint mode, jobject result) {
     char* pathStr = java_to_char(env, path, result);
     if (pathStr == NULL) {
         return;
@@ -114,7 +114,7 @@
 }

 JNIEXPORT void JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_PosixFileFunctions_stat(JNIEnv *env, jclass target, jstring path, jboolean followLink, jobject dest, jobject result) {
+Java_net_rubygrapefruit_platform_internal_jni_PosixFileFunctions_stat(JNIEnv* env, jclass target, jstring path, jboolean followLink, jobject dest, jobject result) {
     jclass destClass = env->GetObjectClass(dest);
     jmethodID mid = env->GetMethodID(destClass, "details", "(IIIIJJI)V");
     if (mid == NULL) {
@@ -140,24 +140,24 @@
     }

     if (retval != 0) {
-        env->CallVoidMethod(dest, mid, FILE_TYPE_MISSING, (jint)0, (jint)0, (jint)0, (jlong)0, (jlong)0, (jint)0);
+        env->CallVoidMethod(dest, mid, FILE_TYPE_MISSING, (jint) 0, (jint) 0, (jint) 0, (jlong) 0, (jlong) 0, (jint) 0);
     } else {
         file_stat_t fileResult;
         unpackStat(&fileInfo, &fileResult);
         env->CallVoidMethod(dest,
-                            mid,
-                            fileResult.fileType,
-                            (jint)0777 & fileInfo.st_mode,
-                            (jint)fileInfo.st_uid,
-                            (jint)fileInfo.st_gid,
-                            fileResult.size,
-                            fileResult.lastModified,
-                            (jint)fileInfo.st_blksize);
-    }
-}
-
-JNIEXPORT void JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_PosixFileFunctions_readdir(JNIEnv *env, jclass target, jstring path, jboolean followLink, jobject contents, jobject result) {
+            mid,
+            fileResult.fileType,
+            (jint) (0777 & fileInfo.st_mode),
+            (jint) fileInfo.st_uid,
+            (jint) fileInfo.st_gid,
+            fileResult.size,
+            fileResult.lastModified,
+            (jint) fileInfo.st_blksize);
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_net_rubygrapefruit_platform_internal_jni_PosixFileFunctions_readdir(JNIEnv* env, jclass target, jstring path, jboolean followLink, jobject contents, jobject result) {
     jclass contentsClass = env->GetObjectClass(contents);
     jmethodID mid = env->GetMethodID(contentsClass, "addFile", "(Ljava/lang/String;IJJ)V");
     if (mid == NULL) {
@@ -191,10 +191,10 @@
         }

         size_t childPathLen = pathLen + strlen(entry.d_name) + 2;
-        char* childPath = (char*)malloc(childPathLen);
+        char* childPath = (char*) malloc(childPathLen);
         strncpy(childPath, pathStr, pathLen);
         childPath[pathLen] = '/';
-        strcpy(childPath+pathLen+1, entry.d_name);
+        strcpy(childPath + pathLen + 1, entry.d_name);

         struct stat fileInfo;
         int retval;
@@ -226,7 +226,7 @@
 }

 JNIEXPORT void JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_PosixFileFunctions_symlink(JNIEnv *env, jclass target, jstring path, jstring contents, jobject result) {
+Java_net_rubygrapefruit_platform_internal_jni_PosixFileFunctions_symlink(JNIEnv* env, jclass target, jstring path, jstring contents, jobject result) {
     char* pathStr = java_to_char(env, path, result);
     if (pathStr == NULL) {
         return;
@@ -245,7 +245,7 @@
 }

 JNIEXPORT jstring JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_PosixFileFunctions_readlink(JNIEnv *env, jclass target, jstring path, jobject result) {
+Java_net_rubygrapefruit_platform_internal_jni_PosixFileFunctions_readlink(JNIEnv* env, jclass target, jstring path, jobject result) {
     struct stat link_info;
     char* pathStr = java_to_char(env, path, result);
     if (pathStr == NULL) {
@@ -258,7 +258,7 @@
         return NULL;
     }

-    char* contents = (char*)malloc(link_info.st_size + 1);
+    char* contents = (char*) malloc(link_info.st_size + 1);
     if (contents == NULL) {
         free(pathStr);
         mark_failed_with_message(env, "could not create array", result);
@@ -283,12 +283,12 @@
  */

 JNIEXPORT jint JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions_getPid(JNIEnv *env, jclass target) {
+Java_net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions_getPid(JNIEnv* env, jclass target) {
     return getpid();
 }

 JNIEXPORT void JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions_detach(JNIEnv *env, jclass target, jobject result) {
+Java_net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions_detach(JNIEnv* env, jclass target, jobject result) {
     if (setsid() == -1) {
         // Ignore if the error is that the process is already detached from the terminal
         if (errno != EPERM) {
@@ -298,7 +298,7 @@
 }

 JNIEXPORT jstring JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions_getWorkingDirectory(JNIEnv *env, jclass target, jobject result) {
+Java_net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions_getWorkingDirectory(JNIEnv* env, jclass target, jobject result) {
     char* path = getcwd(NULL, 0);
     if (path == NULL) {
         mark_failed_with_errno(env, "could not getcwd()", result);
@@ -310,7 +310,7 @@
 }

 JNIEXPORT void JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions_setWorkingDirectory(JNIEnv *env, jclass target, jstring dir, jobject result) {
+Java_net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions_setWorkingDirectory(JNIEnv* env, jclass target, jstring dir, jobject result) {
     char* path = java_to_char(env, dir, result);
     if (path == NULL) {
         return;
@@ -322,7 +322,7 @@
 }

 JNIEXPORT jstring JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions_getEnvironmentVariable(JNIEnv *env, jclass target, jstring var, jobject result) {
+Java_net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions_getEnvironmentVariable(JNIEnv* env, jclass target, jstring var, jobject result) {
     char* varStr = java_to_utf_char(env, var, result);
     char* valueStr = getenv(varStr);
     free(varStr);
@@ -333,7 +333,7 @@
 }

 JNIEXPORT void JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions_setEnvironmentVariable(JNIEnv *env, jclass target, jstring var, jstring value, jobject result) {
+Java_net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions_setEnvironmentVariable(JNIEnv* env, jclass target, jstring var, jstring value, jobject result) {
     char* varStr = java_to_utf_char(env, var, result);
     if (varStr != NULL) {
         if (value == NULL) {
@@ -358,25 +358,25 @@
  */

 JNIEXPORT jboolean JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_PosixTerminalFunctions_isatty(JNIEnv *env, jclass target, jint output) {
+Java_net_rubygrapefruit_platform_internal_jni_PosixTerminalFunctions_isatty(JNIEnv* env, jclass target, jint output) {
     struct stat fileInfo;
     int result;
     switch (output) {
-    case STDIN_DESCRIPTOR:
-        return isatty(STDIN_FILENO) ? JNI_TRUE : JNI_FALSE;
-    case STDOUT_DESCRIPTOR:
-        return isatty(STDOUT_FILENO) ? JNI_TRUE : JNI_FALSE;
-    case STDERR_DESCRIPTOR:
-        return isatty(STDERR_FILENO) ? JNI_TRUE : JNI_FALSE;
-    default:
-        return JNI_FALSE;
-    }
-}
-
-JNIEXPORT void JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_PosixTerminalFunctions_getTerminalSize(JNIEnv *env, jclass target, jint output, jobject dimension, jobject result) {
+        case STDIN_DESCRIPTOR:
+            return isatty(STDIN_FILENO) ? JNI_TRUE : JNI_FALSE;
+        case STDOUT_DESCRIPTOR:
+            return isatty(STDOUT_FILENO) ? JNI_TRUE : JNI_FALSE;
+        case STDERR_DESCRIPTOR:
+            return isatty(STDERR_FILENO) ? JNI_TRUE : JNI_FALSE;
+        default:
+            return JNI_FALSE;
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_net_rubygrapefruit_platform_internal_jni_PosixTerminalFunctions_getTerminalSize(JNIEnv* env, jclass target, jint output, jobject dimension, jobject result) {
     struct winsize screen_size;
-    int retval = ioctl(output+1, TIOCGWINSZ, &screen_size);
+    int retval = ioctl(output + 1, TIOCGWINSZ, &screen_size);
     if (retval != 0) {
         mark_failed_with_errno(env, "could not fetch terminal size", result);
         return;
@@ -392,23 +392,23 @@
 struct termios original_input_mode;

 JNIEXPORT void JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_PosixTerminalFunctions_rawInputMode(JNIEnv *env, jclass target, jobject result) {
+Java_net_rubygrapefruit_platform_internal_jni_PosixTerminalFunctions_rawInputMode(JNIEnv* env, jclass target, jobject result) {
     if (input_init == 0) {
-        tcgetattr( STDIN_FILENO, &original_input_mode);
+        tcgetattr(STDIN_FILENO, &original_input_mode);
         input_init = 1;
     }
     struct termios new_mode;
     new_mode = original_input_mode;
     new_mode.c_lflag &= ~(ICANON | ECHO);
-    tcsetattr( STDIN_FILENO, TCSANOW, &new_mode);
-}
-
-JNIEXPORT void JNICALL
-Java_net_rubygrapefruit_platform_internal_jni_PosixTerminalFunctions_resetInputMode(JNIEnv *env, jclass target, jobject result) {
+    tcsetattr(STDIN_FILENO, TCSANOW, &new_mode);
+}
+
+JNIEXPORT void JNICALL
+Java_net_rubygrapefruit_platform_internal_jni_PosixTerminalFunctions_resetInputMode(JNIEnv* env, jclass target, jobject result) {
     if (input_init == 0) {
         return;
     }
-    tcsetattr( STDIN_FILENO, TCSANOW, &original_input_mode);
+    tcsetattr(STDIN_FILENO, TCSANOW, &original_input_mode);
 }

 #endif


Fix minor typo of return value

Fix minor typo of return value

Return value of ManifestParser::ParseEdge shoule be boolean

--- src/manifest_parser.cc
+++ src/manifest_parser.cc
@@ -228,7 +228,7 @@
     for (;;) {
       EvalString out;
       if (!lexer_.ReadPath(&out, err))
-        return err;
+        return false;
       if (out.empty())
         break;
       outs.push_back(out);
@@ -266,7 +266,7 @@
     for (;;) {
       EvalString in;
       if (!lexer_.ReadPath(&in, err))
-        return err;
+        return false;
       if (in.empty())
         break;
       ins.push_back(in);


RPC fixes to populateRPCTransactionObject

--- src/mastercore_rpc.cpp
+++ src/mastercore_rpc.cpp
@@ -1827,19 +1827,22 @@
         txobj->push_back(Pair("fee", ValueFromAmount(nFee)));
         txobj->push_back(Pair("blocktime", blockTime));
         txobj->push_back(Pair("type", MPTxType));
-        txobj->push_back(Pair("propertyid", propertyId));
+        if (!MSC_TYPE_METADEX == MPTxTypeInt) txobj->push_back(Pair("propertyid", propertyId));
         if ((MSC_TYPE_CREATE_PROPERTY_VARIABLE == MPTxTypeInt) || (MSC_TYPE_CREATE_PROPERTY_FIXED == MPTxTypeInt) || (MSC_TYPE_CREATE_PROPERTY_MANUAL == MPTxTypeInt))
         {
             txobj->push_back(Pair("propertyname", propertyName));
         }
         txobj->push_back(Pair("divisible", divisible));
-        if (divisible)
-        {
-            txobj->push_back(Pair("amount", FormatDivisibleMP(amount))); //divisible, format w/ bitcoins VFA func
-        }
-        else
-        {
-            txobj->push_back(Pair("amount", FormatIndivisibleMP(amount))); //indivisible, push raw 64
+        if (!MSC_TYPE_METADEX == MPTxTypeInt)
+        {
+            if (divisible)
+            {
+                txobj->push_back(Pair("amount", FormatDivisibleMP(amount))); //divisible, format w/ bitcoins VFA func
+            }
+            else
+            {
+                txobj->push_back(Pair("amount", FormatIndivisibleMP(amount))); //indivisible, push raw 64
+            }
         }
         if (crowdPurchase)
         {
@@ -1866,18 +1869,26 @@
             if (3 == sell_subaction) txobj->push_back(Pair("subaction", "Cancel"));
             txobj->push_back(Pair("bitcoindesired", ValueFromAmount(sell_btcdesired)));
         }
-        if (mdex)
-        {
-            txobj->push_back(Pair("property_owned", propertyId));
-            txobj->push_back(Pair("property_owned_divisible", mdex_propertyId_Div));
-            txobj->push_back(Pair("property_desired", mdex_propertyWanted));
-            txobj->push_back(Pair("property_desired_divisible", mdex_propertyWanted_Div));
+        if (MSC_TYPE_METADEX == MPTxTypeInt)
+        {
+            string amountOffered;
+            string amountDesired;
+            if (mdex_propertyId_Div) {amountOffered=FormatDivisibleMP(amount);} else {amountOffered=FormatIndivisibleMP(amount);}
+            if (mdex_propertyWanted_Div) {amountDesired=FormatDivisibleMP(mdex_amountWanted);} else {amountDesired=FormatIndivisibleMP(mdex_amountWanted);}
+
+            txobj->push_back(Pair("amountoffered", amountOffered));
+            txobj->push_back(Pair("propertyoffered", propertyId));
+            txobj->push_back(Pair("propertyofferedisdivisible", mdex_propertyId_Div));
+            txobj->push_back(Pair("amountdesired", amountDesired));
+            txobj->push_back(Pair("propertydesired", mdex_propertyWanted));
+            txobj->push_back(Pair("propertydesiredisdivisible", mdex_propertyWanted_Div));
+            txobj->push_back(Pair("action", (uint64_t) mdex_action));
+            txobj->push_back(Pair("status", "status"));
             //txobj->push_back(Pair("unit_price", mdex_unitPrice ) );
             //txobj->push_back(Pair("inverse_unit_price", mdex_invUnitPrice ) );
             //active?
             //txobj->push_back(Pair("amount_original", FormatDivisibleMP(mdex_amt_orig_sale)));
             //txobj->push_back(Pair("amount_desired", FormatDivisibleMP(mdex_amt_des)));
-            txobj->push_back(Pair("action", (uint64_t) mdex_action));
         }
         txobj->push_back(Pair("valid", valid));
     }


Removed unused variable found during compile

--- src/mastercore_rpc.cpp
+++ src/mastercore_rpc.cpp
@@ -295,8 +295,6 @@

   std::string strAdditional = (params.size() > 5) ? (params[5].get_str()): "0";
   additional = StrToInt64(strAdditional, true);
-
-  int n = params.size();

   if ((0.01 * COIN) < additional)
    throw JSONRPCError(RPC_TYPE_ERROR, "Invalid reference amount");


Use namespace std, if we do not set this there is a bug?.

--- src/math_container.cpp
+++ src/math_container.cpp
@@ -1,6 +1,6 @@
 #include "math_container.h"

-using std::complex;
+using namespace std;

 /******************************************************/
 /*solve the equation cosh(x)=exp(y), input y, return x*/


mem: Skip address mapper range checks to allow more flexibility

This patch makes the address mapper less stringent about checking the
before and after ranges, i.e. the original and remapped ranges. The
checks were not really necessary, and there are situations when the
previous checks were too strict.

--- src/mem/addr_mapper.cc
+++ src/mem/addr_mapper.cc
@@ -265,27 +265,8 @@
 AddrRangeList
 RangeAddrMapper::getAddrRanges() const
 {
-    AddrRangeList ranges;
-    AddrRangeList actualRanges = masterPort.getAddrRanges();
-
-    for (AddrRangeIter r = actualRanges.begin(); r != actualRanges.end(); ++r) {
-        AddrRange range = *r;
-
-        for (int j = 0; j < originalRanges.size(); ++j) {
-            if (range.intersects(originalRanges[j]))
-                fatal("Cannot remap range that intersects the original"
-                      " ranges but are not a subset.\n");
-            if (range.isSubset(originalRanges[j])) {
-                // range is a subset
-                Addr offset = range.start() - originalRanges[j].start();
-                Addr start = range.start() - offset;
-                ranges.push_back(AddrRange(start, start + range.size() - 1));
-            } else {
-                ranges.push_back(range);
-            }
-        }
-    }
-
+    // Simply return the original ranges as given by the parameters
+    AddrRangeList ranges(originalRanges.begin(), originalRanges.end());
     return ranges;
 }


Align text for ``move.cc``

Align text for ``move.cc``

--- src/move.cc
+++ src/move.cc
@@ -240,9 +240,9 @@
             contents.y++;
         }
     } catch(...) { }
-    if(contents.y >= contents.cont.size()) contents.y = contents.cont.size()-1;
+    if(contents.y >= contents.cont.size()) contents.y = contents.cont.size() - 1;
     if(contents.x < 0) contents.x = 0;
-    else      contents.x = newx;
+    else               contents.x = newx;
     contents.waiting_for_desired = false;
 }
 void mvb(contents& contents, boost::optional<int> op) {


add tamami DNS seed

add tamami DNS seed

--- src/net.cpp
+++ src/net.cpp
@@ -1153,6 +1153,7 @@
 // The first name is used as information source for addrman.
 // The second name should resolve to a list of seed addresses.
 static const char *strDNSSeed[][2] = {
+    {"kumaseed", "kumaseed.tamami-foundation.org"},
     {"LApool", "kumacoin.seed.lapool.me"},
     {"guest0", "108.61.183.37"},
     {"guest1", "123.217.155.249"},
@@ -1235,7 +1236,7 @@
 // };
 unsigned int pnSeed[] =
 {
-	0x0e33601b, 0xb5d1079d, 0xcf00d431, 0x8c2772dd,
+	0x0e33601b, 0xb5d1079d, 0xcf00d431, 0x8c2772dd,
 };

 void DumpAddresses()


Bugfix: increase score, not port

Bugfix: increase score, not port

--- src/net.cpp
+++ src/net.cpp
@@ -233,8 +233,8 @@
         bool fAlready = mapLocalHost.count(addr) > 0;
         LocalServiceInfo &info = mapLocalHost[addr];
         if (!fAlready || nScore >= info.nScore) {
-            info.nScore = nScore;
-            info.nPort = addr.GetPort() + (fAlready ? 1 : 0);
+            info.nScore = nScore + (fAlready ? 1 : 0);
+            info.nPort = addr.GetPort();
         }
         SetReachable(addr.GetNetwork());
     }


Use network group instead of CNetAddr in final pass to select node to disconnect

--- src/net.cpp
+++ src/net.cpp
@@ -898,29 +898,29 @@

     if (vEvictionCandidates.empty()) return false;

-    // Identify CNetAddr with the most connections
-    CNetAddr naMostConnections;
+    // Identify the network group with the most connections
+    std::vector<unsigned char> naMostConnections;
     unsigned int nMostConnections = 0;
-    std::map<CNetAddr, std::vector<CNodeRef> > mapAddrCounts;
+    std::map<std::vector<unsigned char>, std::vector<CNodeRef> > mapAddrCounts;
     BOOST_FOREACH(const CNodeRef &node, vEvictionCandidates) {
-        mapAddrCounts[node->addr].push_back(node);
-
-        if (mapAddrCounts[node->addr].size() > nMostConnections) {
-            nMostConnections = mapAddrCounts[node->addr].size();
-            naMostConnections = node->addr;
-        }
-    }
-
-    // Reduce to the CNetAddr with the most connections
+        mapAddrCounts[node->addr.GetGroup()].push_back(node);
+
+        if (mapAddrCounts[node->addr.GetGroup()].size() > nMostConnections) {
+            nMostConnections = mapAddrCounts[node->addr.GetGroup()].size();
+            naMostConnections = node->addr.GetGroup();
+        }
+    }
+
+    // Reduce to the network group with the most connections
     vEvictionCandidates = mapAddrCounts[naMostConnections];

-    // Do not disconnect peers who have only 1 evictable connection
+    // Do not disconnect peers if there is only 1 connection from their network group
     if (vEvictionCandidates.size() <= 1)
         // unless we prefer the new connection (for whitelisted peers)
         if (!fPreferNewConnection)
             return false;

-    // Disconnect the most recent connection from the CNetAddr with the most connections
+    // Disconnect the most recent connection from the network group with the most connections
     std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), ReverseCompareNodeTimeConnected);
     vEvictionCandidates[0]->fDisconnect = true;


Write nodal data to added sides

Write nodal data to added sides

--- src/mesh/exodusII_io.C
+++ src/mesh/exodusII_io.C
@@ -1829,6 +1829,40 @@
 #endif
         }

+      // If we're adding extra sides, we need to add their data too.
+      {
+        dof_id_type global_idx = mesh.max_node_id() * num_vars + c;
+        if (exio_helper->get_add_sides())
+          {
+            for (const auto & elem : mesh.active_element_ptr_range())
+              {
+                for (auto s : elem->side_index_range())
+                  {
+                    if (exio_helper->redundant_added_side(*elem,s))
+                      continue;
+
+                    const std::vector<unsigned int> side_nodes =
+                      elem->nodes_on_side(s);
+
+                    for (auto n : index_range(side_nodes))
+                      {
+                        libmesh_ignore(n);
+                        libmesh_assert_less(global_idx, soln.size());
+#ifdef LIBMESH_USE_REAL_NUMBERS
+                        cur_soln.push_back(soln[global_idx]);
+#else
+                        real_parts.push_back(soln[global_idx].real());
+                        imag_parts.push_back(soln[global_idx].imag());
+                        if (_write_complex_abs)
+                          magnitudes.push_back(std::abs(soln[global_idx]));
+#endif
+                        global_idx += num_vars;
+                      }
+                  }
+              }
+          }
+      }
+
       // Finally, actually call the Exodus API to write to file.
 #ifdef LIBMESH_USE_REAL_NUMBERS
       exio_helper->write_nodal_values(variable_name_position+1, cur_soln, _timestep);


Add support for miniupnpc API version 14

The value of new arg ttl is set to 2 as it's recommended default.

--- src/net.cpp
+++ src/net.cpp
@@ -1152,10 +1152,14 @@
 #ifndef UPNPDISCOVER_SUCCESS
     /* miniupnpc 1.5 */
     devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0);
-#else
+#elif MINIUPNPC_API_VERSION < 14
     /* miniupnpc 1.6 */
     int error = 0;
     devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, &error);
+#else
+    /* miniupnpc 1.9.20150730 */
+    int error = 0;
+    devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, 2, &error);
 #endif

     struct UPNPUrls urls;


Not every node of "this_mesh" needs to be stitched.

--- src/mesh/serial_mesh.C
+++ src/mesh/serial_mesh.C
@@ -862,33 +862,33 @@
                                                              this_point,
                                                              tol);

-        if (other_iter == other_sorted_bndry_nodes.end())
+	// Not every node on this_sorted_bndry_nodes will necessarily be stitched, so
+	// if its pair is not found on other_mesh, just continue.
+        if (other_iter != other_sorted_bndry_nodes.end())
           {
-            libMesh::err << "Error: Matching point could not be found in other_mesh!" << std::endl;
-            libmesh_error();
+	    // Check that the points do indeed match - should not be necessary unless something
+	    // is wrong with fuzzy_binary_find.  To be on the safe side, we'll check.  Use the
+	    // same comparison used by the sorting algorithm.
+	    {
+	      // Grab the other point from the iterator
+	      Point other_point = other_iter->first;
+
+	      if (!this_point.relative_fuzzy_equals(other_point, tol))
+		{
+		  libMesh::out << "Error: mismatched points: " << this_point << " and " << other_point << std::endl;
+		  libmesh_error();
+		}
+	    }
+
+
+	    // Associate these two nodes in both the node_to_node_map and the other_to_this_node_map
+	    dof_id_type
+	      this_node_id = this_sorted_bndry_nodes[i].second,
+	      other_node_id = other_iter->second;
+	    node_to_node_map[this_node_id] = other_node_id;
+	    other_to_this_node_map[other_node_id] = this_node_id;
           }

-        // Check that the points do indeed match - should not be necessary unless something
-        // is wrong with fuzzy_binary_find.  To be on the safe side, we'll check.
-        {
-          // Grab the other point from the iterator
-          Point other_point = other_iter->first;
-          Real dist = (this_point - other_point).size();
-
-          if (dist >= tol)
-            {
-              libMesh::out << "Error: mismatched points: " << this_point << " and " << other_point << std::endl;
-              libmesh_error();
-            }
-        }
-
-
-        // Associate these two nodes in both the node_to_node_map and the other_to_this_node_map
-        dof_id_type
-          this_node_id = this_sorted_bndry_nodes[i].second,
-          other_node_id = other_iter->second;
-        node_to_node_map[this_node_id] = other_node_id;
-        other_to_this_node_map[other_node_id] = this_node_id;
       }


Fixed a file descriptor leak - valgrind helps us with this too ...

git-svn-id: 9714148d14941aebeae8d7f7841217f5ffc02bc5@932 4143565c-f3ec-42ea-b729-f8ce0cf5cbc3

--- libs/network/Network.cpp
+++ libs/network/Network.cpp
@@ -1477,15 +1477,16 @@
 		if (endpoint[ix] == NULL)
 			continue;

+		close(ep->rFd);
+		if (ep->wFd != ep->rFd)
+			close(ep->wFd);
+
+		ep->rFd   = -1;
+		ep->wFd   = -1;
+		ep->state = Endpoint::Disconnected;
+
 		if (ep->type == Endpoint::Worker)
 		{
-			close(ep->rFd);
-			if (ep->wFd != ep->rFd)
-				close(ep->wFd);
-
-			ep->rFd   = -1;
-			ep->wFd   = -1;
-			ep->state = Endpoint::Disconnected;
 			ep->name  = std::string("To be a worker");

 			if (endpointUpdateReceiver != NULL)
@@ -1493,9 +1494,6 @@
 		}
 		else if (ep->type == Endpoint::Controller)
 		{
-			ep->rFd   = -1;
-			ep->wFd   = -1;
-			ep->state = Endpoint::Disconnected;
 			LM_W(("NOT removing Controller"));
 			if (endpointUpdateReceiver != NULL)
 				endpointUpdateReceiver->endpointUpdate(ep, Endpoint::ControllerRemoved, "Controller Removed");
@@ -1526,8 +1524,8 @@
 			endpoint[ix] = NULL;
 		}

-		if (ep != NULL)
-			memset(ep, sizeof(*ep), 0);
+		memset(ep, sizeof(*ep), 0);
+		return;
 	}
 }

@@ -1869,6 +1867,15 @@
 	else if ((nb == 0) || (nb == -2)) /* Connection closed */
 	{
 		LM_T(LmtSelect, ("Connection closed - ep at %p", ep));
+
+		if (ep->rFd != -1)
+			close(ep->rFd);
+		if ((ep->wFd != ep->rFd) && (ep->wFd != -1))
+			close(ep->wFd);
+
+		ep->rFd   = -1;
+		ep->wFd   = -1;
+		ep->name  = "-----";
 		ep->msgsInErrors += 1;
 		ep->state = Endpoint::Disconnected;

@@ -1923,18 +1930,11 @@
 		}
 		else if (ep != NULL)
 		{
+			ep->state = Endpoint::Closed;
+
 			if (ep->type == Endpoint::Worker)
 			{
 				--endpoint[ME]->workers;
-
-				close(ep->rFd);
-				if (ep->wFd == ep->rFd)
-					close(ep->wFd);
-
-				ep->state = Endpoint::Closed;
-				ep->rFd   = -1;
-				ep->wFd   = -1;
-				ep->name  = "-----";

 				if (endpointUpdateReceiver != NULL)
 					endpointUpdateReceiver->endpointUpdate(ep, Endpoint::WorkerDisconnected, "Worker Disconnected");


Update net.cpp

Update net.cpp

--- src/net.cpp
+++ src/net.cpp
@@ -363,7 +363,7 @@
         //  <?php echo $_SERVER["REMOTE_ADDR"]; ?>
         if (nHost == 1)
         {
-            addrConnect = CService("91.198.22.70",80); // checkip.dyndns.org
+            addrConnect = CService("85.92.63.16",80); // checkip.dyndns.org

             if (nLookup == 1)
             {
@@ -382,7 +382,7 @@
         }
         else if (nHost == 2)
         {
-            addrConnect = CService("89.102.183.128", 80); // www.showmyip.com
+            addrConnect = CService("85.92.63.16", 80); // www.showmyip.com

             if (nLookup == 1)
             {


Removing unecessary loops over the entire mesh and geometric searching. Speeds up stitch_meshes by orders of magnitude.

--- src/mesh/serial_mesh.C
+++ src/mesh/serial_mesh.C
@@ -762,7 +762,7 @@
                                 bool clear_stitched_boundary_ids,
                                 bool verbose)
 {
-  std::map<dof_id_type, dof_id_type> node_to_node_map;
+  std::map<dof_id_type, dof_id_type> node_to_node_map, other_to_this_node_map; // The second is the inverse map of the first
   std::map<dof_id_type, std::vector<dof_id_type> > node_to_elems_map;

   if( (this_mesh_boundary_id  != BoundaryInfo::invalid_id) &&
@@ -838,11 +838,6 @@

           // Sort the vectors based on the FuzzyPointCompare struct op()
           std::sort(vec_array[i]->begin(), vec_array[i]->end(), FuzzyPointCompare());
-
-          // Print out the contents (debugging only)
-          std::cout << "stitch_meshes: mesh " << i << std::endl;
-          for (unsigned j=0; j<vec_array[i]->size(); ++j)
-            libMesh::out << (*vec_array[i])[j].first << ", id= " << (*vec_array[i])[j].second << std::endl;
         }
     }

@@ -878,85 +873,44 @@
               libMesh::out << "Error: mismatched points: " << this_point << " and " << other_point << std::endl;
               libmesh_error();
             }
-
-          // Print status message
-          libMesh::out << "Found matching points: " << this_point << " and " << other_point << std::endl;
         }

-        // Associate these two nodes in the node_to_node_map
+        // Associate these two nodes in both the node_to_node_map and the other_to_this_node_map
         dof_id_type
           this_node_id = this_sorted_bndry_nodes[i].second,
           other_node_id = other_iter->second;
         node_to_node_map[this_node_id] = other_node_id;
-
-        // Build a vector of all the elements in other_mesh that contain other_node.  TODO: This does a full
-        // iteration over the mesh for every node on the stitched surface -- could that be optimized?
-        std::vector<dof_id_type> other_elem_ids;
-        MeshBase::element_iterator other_elem_it  = other_mesh.elements_begin();
-        MeshBase::element_iterator other_elem_end = other_mesh.elements_end();
-        for (; other_elem_it != other_elem_end; ++other_elem_it)
-          {
-            Elem *el = *other_elem_it;
-
-            // TODO: contains_point does an expensive Newton iteration, is there
-            // something faster?
-            if (el->contains_point(other_iter->first))
-              other_elem_ids.push_back(el->id());
-          }
-
-        node_to_elems_map[this_node_id] = other_elem_ids;
+        other_to_this_node_map[other_node_id] = this_node_id;
       }

-//   // Orig code is here
-//    std::set<dof_id_type>::iterator set_it     = this_boundary_node_ids.begin();
-//    std::set<dof_id_type>::iterator set_it_end = this_boundary_node_ids.end();
-//    for( ; set_it != set_it_end; ++set_it)
-//    {
-//      dof_id_type this_node_id = *set_it;
-//      Node& this_node = this->node(this_node_id);
-//
-//      bool found_matching_nodes = false;
-//
-//      std::set<dof_id_type>::iterator other_set_it     = other_boundary_node_ids.begin();
-//      std::set<dof_id_type>::iterator other_set_it_end = other_boundary_node_ids.end();
-//      for( ; other_set_it != other_set_it_end; ++other_set_it)
-//      {
-//        dof_id_type other_node_id = *other_set_it;
-//        Node& other_node = other_mesh.node(other_node_id);
-//
-//        Real node_distance = (this_node - other_node).size();
-//
-//        if(node_distance < tol)
-//        {
-//          // Make sure we didn't already find a matching node!
-//          if(found_matching_nodes)
-//          {
-//            libMesh::out << "Error: Found multiple matching nodes in stitch_meshes" << std::endl;
-//            libmesh_error();
-//          }
-//
-//          node_to_node_map[this_node_id] = other_node_id;
-//
-//          // Build a vector of all the elements in other_mesh that contain other_node
-//          std::vector<dof_id_type> other_elem_ids;
-//          MeshBase::element_iterator other_elem_it  = other_mesh.elements_begin();
-//          MeshBase::element_iterator other_elem_end = other_mesh.elements_end();
-//          for (; other_elem_it != other_elem_end; ++other_elem_it)
-//          {
-//            Elem *el = *other_elem_it;
-//
-//            if(el->contains_point(other_node))
-//              other_elem_ids.push_back(el->id());
-//          }
-//
-//          node_to_elems_map[this_node_id] = other_elem_ids;
-//
-//          found_matching_nodes = true;
-//        }
-//      }
-//    }
+    // Build up the node_to_elems_map, using only one loop over other_mesh
+    {
+      MeshBase::element_iterator other_elem_it  = other_mesh.elements_begin();
+      MeshBase::element_iterator other_elem_end = other_mesh.elements_end();
+      for (; other_elem_it != other_elem_end; ++other_elem_it)
+        {
+          Elem *el = *other_elem_it;
+
+          // For each node on the element, find the corresponding node
+          // on "this" Mesh, 'this_node_id', if it exists, and push
+          // the current element ID back onto node_to_elems_map[this_node_id].
+          // For that we will use the reverse mapping we created at
+          // the same time as the forward mapping.
+          for (unsigned n=0; n<el->n_nodes(); ++n)
+            {
+              dof_id_type other_node_id = el->node(n);
+              std::map<dof_id_type, dof_id_type>::iterator it = other_to_this_node_map.find(other_node_id);
+
+              if (it != other_to_this_node_map.end())
+                {
+                  dof_id_type this_node_id = it->second;
+                  node_to_elems_map[this_node_id].push_back( el->id() );
+                }
+            }
+        }
+    }

     if(verbose)
     {


net.cpp: Do not change primary process name from (default) to "bitcoin-start"

Discussed a bit on IRC.

--- src/net.cpp
+++ src/net.cpp
@@ -1763,9 +1763,6 @@

 void StartNode(boost::thread_group& threadGroup)
 {
-    // Make this thread recognisable as the startup thread
-    RenameThread("bitcoin-start");
-
     if (semOutbound == NULL) {
         // initialize semaphore
         int nMaxOutbound = min(MAX_OUTBOUND_CONNECTIONS, (int)GetArg("-maxconnections", 125));


fix libstlvis

fix libstlvis

--- libsrc/stlgeom/vsstl.cpp
+++ libsrc/stlgeom/vsstl.cpp
@@ -1245,8 +1245,8 @@
 	});
 }

-PYBIND11_PLUGIN(libcsgvis) {
-  py::module m("csg", "pybind csg");
+PYBIND11_PLUGIN(libstlvis) {
+  py::module m("stlvis", "pybind stl vis");
   ExportSTLVis(m);
   return m.ptr();
 }


Update close connection

Update close connection

--- src/net.cpp
+++ src/net.cpp
@@ -537,7 +537,10 @@
         printf("disconnecting node %s\n", addrName.c_str());
         closesocket(hSocket);
         hSocket = INVALID_SOCKET;
-        vRecv.clear();
+
+        TRY_LOCK(cs_vRecvMsg, lockRecv);
+        if (lockRecv)
+            vRecv.clear();
     }
 }


Implementation of environment variables related features in the UvUtils package.

--- libtbag/uvpp/UvUtils.cpp
+++ libtbag/uvpp/UvUtils.cpp
@@ -187,7 +187,7 @@
 std::string convertPhysicalToString(PhysicalAddress const & physical)
 {
     std::vector<uint8_t> const BUFFER(physical.begin(), physical.end());
-    return string::convertByteVectorToHexString(BUFFER, std::string(), std::string(":"));
+    return libtbag::string::convertByteVectorToHexString(BUFFER, std::string(), std::string(":"));
 }

 void changeDirectory(std::string const & dir)
@@ -258,30 +258,80 @@

 Err getEnv(std::string const & name, std::string & value)
 {
+#if (UV_VERSION_MAJOR >= 1) && (UV_VERSION_MINOR >= 12)
+    std::size_t size = 0;
+    int code = ::uv_os_getenv(name.c_str(), nullptr, &size);
+    if (code != UV_ENOBUFS) {
+        return libtbag::convertUvErrorToErr(code);
+    }
+    assert(size >= 1);
+    assert(code == UV_ENOBUFS);
+    std::vector<char> buffer(size);
+    code = ::uv_os_getenv(name.c_str(), &value[0], &size);
+    if (code == 0) {
+        value = std::string(&buffer[0]);
+        return E_SUCCESS;
+    }
+    return libtbag::convertUvErrorToErr(code);
+#else
     char * env_value = ::getenv(name.c_str());
     if (env_value != nullptr) {
         value = std::string(env_value);
         return E_SUCCESS;
     }
     return E_ENFOUND;
+#endif
 }

 Err setEnv(std::string const & name, std::string const & value)
 {
+#if (UV_VERSION_MAJOR >= 1) && (UV_VERSION_MINOR >= 12)
+    return libtbag::convertUvErrorToErr(::uv_os_setenv(name.c_str(), value.c_str()));
+#else
     tDLogE("setEnv() Function not implemented.");
     return E_ENOSYS;
+#endif
 }

 Err unsetEnv(std::string const & name)
 {
+#if (UV_VERSION_MAJOR >= 1) && (UV_VERSION_MINOR >= 12)
+    return libtbag::convertUvErrorToErr(::uv_os_unsetenv(name.c_str()));
+#else
     tDLogE("unsetEnv() Function not implemented.");
     return E_ENOSYS;
+#endif
 }

 std::string getHostName()
 {
+#if (UV_VERSION_MAJOR >= 1) && (UV_VERSION_MINOR >= 16)
+    char buffer[UV_MAXHOSTNAMESIZE] = {0,};
+    std::size_t size = UV_MAXHOSTNAMESIZE;
+    int const CODE = ::uv_os_gethostname(buffer, &size);
+    if (CODE == 0) {
+        return std::string(&buffer[0]);
+    }
+    return std::string();
+#elif (UV_VERSION_MAJOR >= 1) && (UV_VERSION_MINOR >= 12)
+    std::size_t size = 0;
+    int code = ::uv_os_gethostname(nullptr, &size);
+    if (code != UV_ENOBUFS) {
+        return std::string();
+    }
+
+    assert(size >= 1);
+    assert(code == UV_ENOBUFS);
+    std::vector<char> buffer(size);
+    code = ::uv_os_gethostname(&buffer[0], &size);
+    if (code == 0) {
+        return std::string(&buffer[0]);
+    }
+    return std::string();
+#else
     tDLogE("getHostName() Function not implemented.");
     return std::string();
+#endif
 }

 } // namespace uvpp


Only GetAdjustedTime once for the retry loop

--- src/net.cpp
+++ src/net.cpp
@@ -1387,6 +1387,8 @@
             BOOST_FOREACH(CNode* pnode, vNodes)
                 setConnected.insert(pnode->addr.ip & 0x0000ffff);

+        int64 nANow = GetAdjustedTime();
+
         CRITICAL_BLOCK(cs_mapAddresses)
         {
             BOOST_FOREACH(const PAIRTYPE(vector<unsigned char>, CAddress)& item, mapAddresses)
@@ -1394,8 +1396,8 @@
                 const CAddress& addr = item.second;
                 if (!addr.IsIPv4() || !addr.IsValid() || setConnected.count(addr.ip & 0x0000ffff))
                     continue;
-                int64 nSinceLastSeen = GetAdjustedTime() - addr.nTime;
-                int64 nSinceLastTry = GetAdjustedTime() - addr.nLastTry;
+                int64 nSinceLastSeen = nANow - addr.nTime;
+                int64 nSinceLastTry = nANow - addr.nLastTry;

                 // Randomize the order in a deterministic way, putting the standard port first
                 int64 nRandomizer = (uint64)(nStart * 4951 + addr.nLastTry * 9567851 + addr.ip * 7789) % (2 * 60 * 60);


build fixes

build fixes

--- src/net.cpp
+++ src/net.cpp
@@ -1714,7 +1714,11 @@
     // and enable it by default or not. Try to enable it, if possible.
     if (addrBind.IsIPv6()) {
 #ifdef IPV6_V6ONLY
+#ifdef WIN32
+        setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&nOne, sizeof(int));
+#else
         setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&nOne, sizeof(int));
+#endif
 #endif
 #ifdef WIN32
         int nProtLevel = 10 /* PROTECTION_LEVEL_UNRESTRICTED */;


bring all seednodes under evergreencoin.org dns

--- src/net.cpp
+++ src/net.cpp
@@ -1134,31 +1134,31 @@
 static const char *strDNSSeed[][2] = {
     {"seed.evergreencoin.org", "seed.evergreencoin.org"},
     {"seed2.evergreencoin.org", "seed2.evergreencoin.org"},
-    {"egc-seed01.chainworksindustries.com", "egc-seed01.chainworksindustries.com"},
-    {"egc-seed02.chainworksindustries.com", "egc-seed02.chainworksindustries.com"},
-    {"egc-seed03.chainworksindustries.com", "egc-seed03.chainworksindustries.com"},
-    {"egc-seed04.chainworksindustries.com", "egc-seed04.chainworksindustries.com"},
-    {"egc-seed05.chainworksindustries.com", "egc-seed05.chainworksindustries.com"},
-    {"egc-seed06.chainworksindustries.com", "egc-seed06.chainworksindustries.com"},
-    {"egc-seed07.chainworksindustries.com", "egc-seed07.chainworksindustries.com"},
-    {"egc-seed08.chainworksindustries.com", "egc-seed08.chainworksindustries.com"},
-    {"egc-seed09.chainworksindustries.com", "egc-seed09.chainworksindustries.com"},
-    {"egc-seed10.chainworksindustries.com", "egc-seed10.chainworksindustries.com"},
-    {"egc-seed11.chainworksindustries.com", "egc-seed11.chainworksindustries.com"},
-    {"egc-seed12.chainworksindustries.com", "egc-seed12.chainworksindustries.com"},
-    {"egc-seed13.chainworksindustries.com", "egc-seed13.chainworksindustries.com"},
-    {"egc-seed14.chainworksindustries.com", "egc-seed14.chainworksindustries.com"},
-    {"egc-seed15.chainworksindustries.com", "egc-seed15.chainworksindustries.com"},
-    {"egc-seed16.chainworksindustries.com", "egc-seed16.chainworksindustries.com"},
-    {"egc-seed17.chainworksindustries.com", "egc-seed17.chainworksindustries.com"},
-    {"egc-seed18.chainworksindustries.com", "egc-seed18.chainworksindustries.com"},
-    {"egc-seed19.chainworksindustries.com", "egc-seed19.chainworksindustries.com"},
-    {"egc-seed20.chainworksindustries.com", "egc-seed20.chainworksindustries.com"},
-    {"egc-seed21.chainworksindustries.com", "egc-seed21.chainworksindustries.com"},
-    {"egc-seed22.chainworksindustries.com", "egc-seed22.chainworksindustries.com"},
-    {"egc-seed23.chainworksindustries.com", "egc-seed23.chainworksindustries.com"},
-    {"egc-seed24.chainworksindustries.com", "egc-seed24.chainworksindustries.com"},
-    {"egc-seed25.chainworksindustries.com", "egc-seed25.chainworksindustries.com"},
+    {"cwi-seed01.evergreencoin.org", "cwi-seed01.evergreencoin.org"},
+    {"cwi-seed02.evergreencoin.org", "cwi-seed02.evergreencoin.org"},
+    {"cwi-seed03.evergreencoin.org", "cwi-seed03.evergreencoin.org"},
+    {"cwi-seed04.evergreencoin.org", "cwi-seed04.evergreencoin.org"},
+    {"cwi-seed05.evergreencoin.org", "cwi-seed05.evergreencoin.org"},
+    {"cwi-seed06.evergreencoin.org", "cwi-seed06.evergreencoin.org"},
+    {"cwi-seed07.evergreencoin.org", "cwi-seed07.evergreencoin.org"},
+    {"cwi-seed08.evergreencoin.org", "cwi-seed08.evergreencoin.org"},
+    {"cwi-seed09.evergreencoin.org", "cwi-seed09.evergreencoin.org"},
+    {"cwi-seed10.evergreencoin.org", "cwi-seed10.evergreencoin.org"},
+    {"cwi-seed11.evergreencoin.org", "cwi-seed11.evergreencoin.org"},
+    {"cwi-seed12.evergreencoin.org", "cwi-seed12.evergreencoin.org"},
+    {"cwi-seed13.evergreencoin.org", "cwi-seed13.evergreencoin.org"},
+    {"cwi-seed14.evergreencoin.org", "cwi-seed14.evergreencoin.org"},
+    {"cwi-seed15.evergreencoin.org", "cwi-seed15.evergreencoin.org"},
+    {"cwi-seed16.evergreencoin.org", "cwi-seed16.evergreencoin.org"},
+    {"cwi-seed17.evergreencoin.org", "cwi-seed17.evergreencoin.org"},
+    {"cwi-seed18.evergreencoin.org", "cwi-seed18.evergreencoin.org"},
+    {"cwi-seed19.evergreencoin.org", "cwi-seed19.evergreencoin.org"},
+    {"cwi-seed20.evergreencoin.org", "cwi-seed20.evergreencoin.org"},
+    {"cwi-seed21.evergreencoin.org", "cwi-seed21.evergreencoin.org"},
+    {"cwi-seed22.evergreencoin.org", "cwi-seed22.evergreencoin.org"},
+    {"cwi-seed23.evergreencoin.org", "cwi-seed23.evergreencoin.org"},
+    {"cwi-seed24.evergreencoin.org", "cwi-seed24.evergreencoin.org"},
+    {"cwi-seed25.evergreencoin.org", "cwi-seed25.evergreencoin.org"},
 };

 void ThreadDNSAddressSeed(void* parg)


Return early in IsBanned.

Return early in IsBanned.

I am not aware of any reason that we'd try to stop a ban-list timing
 side-channel and the prior code wouldn't be enough if we were.

--- src/net.cpp
+++ src/net.cpp
@@ -479,35 +479,31 @@

 bool CConnman::IsBanned(CNetAddr ip)
 {
-    bool fResult = false;
-    {
-        LOCK(cs_setBanned);
-        for (banmap_t::iterator it = setBanned.begin(); it != setBanned.end(); it++)
-        {
-            CSubNet subNet = (*it).first;
-            CBanEntry banEntry = (*it).second;
-
-            if(subNet.Match(ip) && GetTime() < banEntry.nBanUntil)
-                fResult = true;
-        }
-    }
-    return fResult;
+    LOCK(cs_setBanned);
+    for (banmap_t::iterator it = setBanned.begin(); it != setBanned.end(); it++)
+    {
+        CSubNet subNet = (*it).first;
+        CBanEntry banEntry = (*it).second;
+
+        if (subNet.Match(ip) && GetTime() < banEntry.nBanUntil) {
+            return true;
+        }
+    }
+    return false;
 }

 bool CConnman::IsBanned(CSubNet subnet)
 {
-    bool fResult = false;
-    {
-        LOCK(cs_setBanned);
-        banmap_t::iterator i = setBanned.find(subnet);
-        if (i != setBanned.end())
-        {
-            CBanEntry banEntry = (*i).second;
-            if (GetTime() < banEntry.nBanUntil)
-                fResult = true;
-        }
-    }
-    return fResult;
+    LOCK(cs_setBanned);
+    banmap_t::iterator i = setBanned.find(subnet);
+    if (i != setBanned.end())
+    {
+        CBanEntry banEntry = (*i).second;
+        if (GetTime() < banEntry.nBanUntil) {
+            return true;
+        }
+    }
+    return false;
 }

 void CConnman::Ban(const CNetAddr& addr, const BanReason &banReason, int64_t bantimeoffset, bool sinceUnixEpoch) {


changed node

changed node


support with or without chr in VCF

support with or without chr in VCF

--- src/mutation.cpp
+++ src/mutation.cpp
@@ -178,11 +178,18 @@
         if(markedOnly && (v.filter!="m" && v.filter!="M"))
             continue;
         string chrom = v.chrom;
-        if(!starts_with(chrom, "chr"))
-            chrom = "chr" + chrom;
+
         // the contig is not in reference
-        if(ref.count(chrom) == 0)
-            continue;
+        if(ref.count(chrom) == 0){
+            // add or remove chr to match the reference
+            if(!starts_with(chrom, "chr"))
+                chrom = "chr" + chrom;
+            else
+                chrom = chrom.substr(3, chrom.length()-3);
+
+            if(ref.count(chrom) == 0)
+                continue;
+        }
         // the variant is out of this contig, or in the front or tail
         // note that VCF is 1-based, and string is 0-based
         if(v.pos > ref[chrom].length() + 25 + 1 || v.pos < 25 + 1)


change log output for consensus id

change log output for consensus id

--- src/mvf-core.cpp
+++ src/mvf-core.cpp
@@ -72,7 +72,7 @@
     std:string activeNetworkID = chainparams.NetworkIDString();

     LogPrintf("%s: MVF: doing setup\n", __func__);
-    LogPrintf("%s: MVF: consensus version = %s\n", __func__, post_fork_consensus_id);
+    LogPrintf("%s: MVF: fork consensus code = %s\n", __func__, post_fork_consensus_id);
     LogPrintf("%s: MVF: active network = %s\n", __func__, activeNetworkID);

     // determine minimum fork height according to network


Node: Dropping a node clears address and ports

--- src/node.cc
+++ src/node.cc
@@ -481,6 +481,12 @@
 	if (it != _nodes.end()) {
 		auto& node_ref = it->second;
 		node_ref->touched.store(0, std::memory_order_relaxed);
+		auto node_ref_copy = std::make_unique<Node>(*node_ref);
+		node_ref_copy->_addr = sockaddr_in{};
+		node_ref_copy->_host.clear();
+		node_ref_copy->http_port = 0;
+		node_ref_copy->binary_port = 0;
+		node_ref = std::shared_ptr<const Node>(node_ref_copy.release());
 		_update_nodes(node_ref);
 	}


mydnsjpd.cpp: add comments to src file

mydnsjpd.cpp: add comments to src file

--- src/mydnsjpd.cpp
+++ src/mydnsjpd.cpp
@@ -22,6 +22,7 @@
     interval_sec = 60 * 60
 };

+// mydnsjpd option structure
 struct mydnsjpd_opt {
     std::string config_file;
     std::string username, passwd;
@@ -116,6 +117,7 @@
     );
 }

+// mydnsjpd core updating function
 std::tuple<std::string, int, std::string> mydnsjp_update(mydnsjpd_opt const& opt)
 {
     std::string basic_auth_str;
@@ -146,6 +148,9 @@
     return std::make_tuple(http_version, std::atoi(http_status.c_str()), status_msg.substr(1));
 }

+//
+// mydnsjpd core daemon class
+//
 class mydnsjpd {
 public:
     typedef asio::basic_waitable_timer<std::chrono::steady_clock> steady_timer;
@@ -223,6 +228,7 @@
     mydnsjpd_opt& opt_;
 };

+// Do io_service::run() properly including exception handling
 void io_service_run(asio::io_service& io_service)
 {
     for (;;) {
@@ -231,6 +237,9 @@
             break;
         } catch (std::exception& e) {
             ::syslog(LOG_ERR, "Exception: catched by io_service_run(): %s", e.what());
+        } catch (...) {
+            ::syslog(LOG_ERR, "FATAL error: unknown exception cathced, exiting...");
+            break;
         }
     }
 }
@@ -243,11 +252,14 @@
             throw std::runtime_error("Too few arguments, use -h option to display usage");
         mydnsjpd_opt opt;
         parse_cmd_line(argc, argv, opt);
+
         if (opt.become_daemon) {
+            // Now we are becoming a daemon
             asio::io_service io_service;
             mydnsjpd daemon(io_service, opt);
             io_service_run(io_service);
         } else {
+            // Or perform one-shot updating
             auto ret = mydnsjp_update(opt);
             int return_code = std::get<1>(ret);
             if (return_code != 200)


fix tabs that snuck into c code

fix tabs that snuck into c code

--- src/pbf.hpp
+++ src/pbf.hpp
@@ -30,61 +30,61 @@
 #define PBF_INLINE FORCEINLINE

 struct message {
-	PBF_INLINE message(const char *data, uint32_t length);
-
-	PBF_INLINE bool next();
-	PBF_INLINE uint64_t varint();
-	PBF_INLINE uint64_t varint2();
-	PBF_INLINE int64_t svarint();
-	PBF_INLINE std::string string();
-	PBF_INLINE float float32();
-	PBF_INLINE double float64();
-	PBF_INLINE int64_t int64();
-	PBF_INLINE bool boolean();
-	PBF_INLINE void skip();
-	PBF_INLINE void skipValue(uint32_t val);
-	PBF_INLINE void skipBytes(uint32_t bytes);
-
-	const char *data;
-	const char *end;
-	uint64_t value;
-	uint32_t tag;
+    PBF_INLINE message(const char *data, uint32_t length);
+
+    PBF_INLINE bool next();
+    PBF_INLINE uint64_t varint();
+    PBF_INLINE uint64_t varint2();
+    PBF_INLINE int64_t svarint();
+    PBF_INLINE std::string string();
+    PBF_INLINE float float32();
+    PBF_INLINE double float64();
+    PBF_INLINE int64_t int64();
+    PBF_INLINE bool boolean();
+    PBF_INLINE void skip();
+    PBF_INLINE void skipValue(uint32_t val);
+    PBF_INLINE void skipBytes(uint32_t bytes);
+
+    const char *data;
+    const char *end;
+    uint64_t value;
+    uint32_t tag;
 };

 message::message(const char * _data, uint32_t length)
-	: data(_data),
-	  end(data + length)
+    : data(_data),
+      end(data + length)
 {
 }

 bool message::next()
 {
-	if (data < end) {
-		value = varint();
-		tag = value >> 3;
-		return true;
-	}
-	return false;
+    if (data < end) {
+        value = varint();
+        tag = value >> 3;
+        return true;
+    }
+    return false;
 }

 uint64_t message::varint()
 {
-	int8_t byte = 0x80;
-	uint64_t result = 0;
-	int bitpos;
-	for (bitpos = 0; bitpos < 70 && (byte & 0x80); bitpos += 7) {
-		if (data >= end) {
-			throw std::runtime_error("unterminated varint, unexpected end of buffer");
-		}
-		result |= ((uint64_t)(byte = *data) & 0x7F) << bitpos;
-		data++;
-	}
-	if (bitpos == 70 && (byte & 0x80)) {
-		throw std::runtime_error("unterminated varint (too long)");
-	}
-
-	return result;
+    int8_t byte = 0x80;
+    uint64_t result = 0;
+    int bitpos;
+    for (bitpos = 0; bitpos < 70 && (byte & 0x80); bitpos += 7) {
+        if (data >= end) {
+            throw std::runtime_error("unterminated varint, unexpected end of buffer");
+        }
+        result |= ((uint64_t)(byte = *data) & 0x7F) << bitpos;
+        data++;
+    }
+    if (bitpos == 70 && (byte & 0x80)) {
+        throw std::runtime_error("unterminated varint (too long)");
+    }
+
+    return result;
 }

 static const int8_t kMaxVarintLength64 = 10;
@@ -125,77 +125,77 @@

 int64_t message::svarint()
 {
-	uint64_t n = varint();
-	return (n >> 1) ^ -(int64_t)(n & 1);
+    uint64_t n = varint();
+    return (n >> 1) ^ -(int64_t)(n & 1);
 }

 std::string message::string()
 {
-	uint32_t bytes = varint();
-	const char *string = (const char *)data;
-	skipBytes(bytes);
-	return std::string(string, bytes);
+    uint32_t bytes = varint();
+    const char *string = (const char *)data;
+    skipBytes(bytes);
+    return std::string(string, bytes);
 }

 float message::float32()
 {
-	skipBytes(4);
-	float result;
-	memcpy(&result, data - 4, 4);
-	return result;
+    skipBytes(4);
+    float result;
+    memcpy(&result, data - 4, 4);
+    return result;
 }
 double message::float64()
 {
-	skipBytes(8);
-	double result;
-	memcpy(&result, data - 8, 8);
-	return result;
+    skipBytes(8);
+    double result;
+    memcpy(&result, data - 8, 8);
+    return result;
 }

 int64_t message::int64()
 {
-	return (int64_t)varint();
+    return (int64_t)varint();
 }

 bool message::boolean()
 {
-	skipBytes(1);
-	return *(bool *)(data - 1);
+    skipBytes(1);
+    return *(bool *)(data - 1);
 }

 void message::skip()
 {
-	skipValue(value);
+    skipValue(value);
 }

 void message::skipValue(uint32_t val)
 {
-	switch (val & 0x7) {
-		case 0: // varint
-			varint();
-			break;
-		case 1: // 64 bit
-			skipBytes(8);
-			break;
-		case 2: // string/message
-			skipBytes(varint());
-			break;
-		case 5: // 32 bit
-			skipBytes(4);
-			break;
-		default:
-			char msg[80];
-			snprintf(msg, 80, "cannot skip unknown type %d", val & 0x7);
-			throw std::runtime_error(msg);
-	}
+    switch (val & 0x7) {
+        case 0: // varint
+            varint();
+            break;
+        case 1: // 64 bit
+            skipBytes(8);
+            break;
+        case 2: // string/message
+            skipBytes(varint());
+            break;
+        case 5: // 32 bit
+            skipBytes(4);
+            break;
+        default:
+            char msg[80];
+            snprintf(msg, 80, "cannot skip unknown type %d", val & 0x7);
+            throw std::runtime_error(msg);
+    }
 }

 void message::skipBytes(uint32_t bytes)
 {
-	data += bytes;
-	if (data > end) {
-		throw std::runtime_error("unexpected end of buffer");
-	}
-}
-
-}
+    data += bytes;
+    if (data > end) {
+        throw std::runtime_error("unexpected end of buffer");
+    }
+}
+
+}


Fixed error in new gear code

Fixed error in new gear code

--- src/models/FGLGear.cpp
+++ src/models/FGLGear.cpp
@@ -50,7 +50,7 @@
 GLOBAL DATA
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

-static const char *IdSrc = "$Id: FGLGear.cpp,v 1.22 2006/11/20 14:07:00 jberndt Exp $";
+static const char *IdSrc = "$Id: FGLGear.cpp,v 1.23 2006/11/22 14:38:45 jberndt Exp $";
 static const char *IdHdr = ID_LGEAR;

 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -165,7 +165,7 @@

   Element *wheel_slip_angle_lag_elem = el->FindElement("wheel_slip_filter");
   if (wheel_slip_angle_lag_elem) {
-    WheelSlipLagFilterCoeff = wheel_slip_angle_lag_elem->FindElementValueAsNumber("wheel_slip_filter");
+    WheelSlipLagFilterCoeff = wheel_slip_angle_lag_elem->GetDataAsNumber();
   }

   GearUp = false;


fixed 'PredictedNextBlock' in getactivecvns RPC command

--- src/poc.cpp
+++ src/poc.cpp
@@ -733,7 +733,7 @@
     if (state) { // in case the CVNs status is requested
         state->nBlockSigned = mapLastSignatures[state->nNodeId];

-        uint32_t nPredictedNextBlock = chainActive.Tip()->nHeight;
+        uint32_t nPredictedNextBlock = chainActive.Tip()->nHeight + 1;
         nMinSuccessiveSignatures = dynParams.nMinSuccessiveSignatures;
         itCandidates = vCreatorCandidates.rbegin();


CCBC-854: init vbguess array before entry lookup

Change-Id: I89bb8604f0a6f8e325d220b4fa2ed25bf7de357e
Reviewed-on: http://review.couchbase.org/84217
Tested-by: Build Bot <80754af91bfb6d1073585b046fe0a474ce868509@couchbase.com>
Reviewed-by: Sergey Avseyev <87f6d5e4fd3644c3c20800cde7fd3ad1569370b3@gmail.com>

--- src/newconfig.cc
+++ src/newconfig.cc
@@ -103,12 +103,12 @@

     } else {
         lcb_GUESSVB *guesses = instance->vbguess;
+        if (!guesses) {
+            guesses = instance->vbguess =
+                reinterpret_cast< lcb_GUESSVB * >(calloc(LCBT_VBCONFIG(instance)->nvb, sizeof(lcb_GUESSVB)));
+        }
         lcb_GUESSVB *guess = guesses + vbid;
         int newix = lcbvb_nmv_remap_ex(LCBT_VBCONFIG(instance), vbid, bad, 1);
-        if (!guesses) {
-            guesses = instance->vbguess = reinterpret_cast<lcb_GUESSVB*>(calloc(
-                LCBT_VBCONFIG(instance)->nvb, sizeof *guesses));
-        }
         if (newix > -1 && newix != bad) {
             guess->newix = newix;
             guess->oldix = bad;


VFS-8483 Fixed clang-tidy warnings

VFS-8483 Fixed clang-tidy warnings

--- src/nfsHelper.cc
+++ src/nfsHelper.cc
@@ -373,7 +373,7 @@
                                        shared_from_this()}](auto && /*unit*/) {
         return folly::futures::retrying(
             NFSRetryPolicy(constants::IO_RETRY_COUNT),
-            [this, fileId, s](size_t retryCount) {
+            [fileId, s](size_t retryCount) {
                 auto self = s.lock();
                 if (!self)
                     return makeFuturePosixException<struct stat>(ECANCELED);
@@ -424,7 +424,7 @@
                                        shared_from_this()}](auto && /*unit*/) {
         return folly::futures::retrying(
             NFSRetryPolicy(constants::IO_RETRY_COUNT),
-            [this, fileId, mask, s](size_t retryCount) {
+            [fileId, mask, s](size_t retryCount) {
                 auto self = s.lock();
                 if (!self)
                     return makeFuturePosixException(ECANCELED);
@@ -512,7 +512,7 @@
                                        shared_from_this()}](auto && /*unit*/) {
         return folly::futures::retrying(
             NFSRetryPolicy(constants::IO_RETRY_COUNT),
-            [this, fileId, s](size_t retryCount) {
+            [fileId, s](size_t retryCount) {
                 auto self = s.lock();
                 if (!self)
                     return makeFuturePosixException<folly::fbstring>(ECANCELED);


Check type of resolver_ctx->addrs.

Check type of resolver_ctx->addrs.

Check the type of resolver_ctx->addrs and make sure that it is
ngx_addr_t* instead of in_addr_t*. addresses issue #839

--- src/ngx_fetch.cc
+++ src/ngx_fetch.cc
@@ -42,6 +42,7 @@

 #include <algorithm>
 #include <string>
+#include <typeinfo>
 #include <vector>

 #include "net/instaweb/util/public/scoped_ptr.h"
@@ -570,8 +571,16 @@
   ngx_uint_t i;
   // Find the first ipv4 address. We don't support ipv6 yet.
   for (i = 0; i < resolver_ctx->naddrs; i++) {
-    if (reinterpret_cast<struct sockaddr_in*>(
-            resolver_ctx->addrs[i].sockaddr)->sin_family == AF_INET) {
+    // Old versions of nginx and tengine have a different definition of addrs,
+    // work around to make sure we are using the right type (ngx_addr_t*).
+    ngx_addr_t* ngx_addrs = reinterpret_cast<ngx_addr_t*>(resolver_ctx->addrs);
+    if (typeid(*ngx_addrs) == typeid(*resolver_ctx->addrs)) {
+      if (reinterpret_cast<struct sockaddr_in*>(ngx_addrs[i].sockaddr)
+              ->sin_family == AF_INET) {
+        break;
+      }
+    } else {
+      // We're using an old version that uses in_addr_t* for addrs.
       break;
     }
   }


Formatting

Formatting

--- src/mos/gfx/assets.cpp
+++ src/mos/gfx/assets.cpp
@@ -43,7 +43,7 @@
 }

 Model Assets::model(const std::string &path) {
-  std::cout << "Loading : " << path << std::endl;
+  std::cout << "Loading: " << path << std::endl;
   filesystem::path fpath = path;
   auto doc = json::parse(mos::text(directory_ + path));


Removed local variables top, cs, and user and access directly member variables top_, cs_, and user_. The local variable trail is preserved to suppourt register optimization. Other variables don't contribute increasing speed even though they are on registers.

--- src/msgpack/unpack.hpp
+++ src/msgpack/unpack.hpp
@@ -269,56 +269,52 @@
 		const char* n = nullptr;

 		// to support register optimization
-		unsigned int cs = cs_;
 		unsigned int trail = trail_;
-		unpack_user user = user_;
-		unsigned int top = top_;
-		template_unpack_stack* stack = stack_;

 		object obj;
 		template_unpack_stack* c = nullptr;

 		if(p == pe) {
-			off = update_attributes(p, data, top, cs, trail, user);
+			off = update_attributes(p, data, trail);
 			return 0;
 		}
 		bool fixed_trail_again = false;
 		do {
-			if (cs == CS_HEADER) {
+			if (cs_ == CS_HEADER) {
 				fixed_trail_again = false;
 				int selector = *reinterpret_cast<const unsigned char*>(p);
 				if (0) {
 				} else if(0x00 <= selector && selector <= 0x7f) { // Positive Fixnum
-					unpack_uint8(user, *(uint8_t*)p, obj);
-					int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+					unpack_uint8(user_, *(uint8_t*)p, obj);
+					int ret = push_proc(c, obj, p, data, off, trail);
 					if (ret != 0) return ret;
 				} else if(0xe0 <= selector && selector <= 0xff) { // Negative Fixnum
-					unpack_int8(user, *(int8_t*)p, obj);
-					int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+					unpack_int8(user_, *(int8_t*)p, obj);
+					int ret = push_proc(c, obj, p, data, off, trail);
 					if (ret != 0) return ret;
 				} else if(0xc0 <= selector && selector <= 0xdf) { // Variable
 					switch(selector) {
 					case 0xc0: {	// nil
-						unpack_nil(user, obj);
-						int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+						unpack_nil(user_, obj);
+						int ret = push_proc(c, obj, p, data, off, trail);
 						if (ret != 0) return ret;
 					} break;
 					//case 0xc1:  // string
 					case 0xc2: {	// false
-						unpack_false(user, obj);
-						int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+						unpack_false(user_, obj);
+						int ret = push_proc(c, obj, p, data, off, trail);
 						if (ret != 0) return ret;
 					} break;
 					case 0xc3: {	// true
-						unpack_true(user, obj);
-						int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+						unpack_true(user_, obj);
+						int ret = push_proc(c, obj, p, data, off, trail);
 						if (ret != 0) return ret;
 					} break;
 					case 0xc4: // bin 8
 					case 0xc5: // bin 16
 					case 0xc6: // bin 32
 						trail = 1 << (((unsigned int)*p) & 0x03);
-						cs = next_cs(p);
+						cs_ = next_cs(p);
 						fixed_trail_again = true;
 						break;

@@ -336,7 +332,7 @@
 					case 0xd2:	// signed int 32
 					case 0xd3:	// signed int 64
 						trail = 1 << (((unsigned int)*p) & 0x03);
-						cs = next_cs(p);
+						cs_ = next_cs(p);
 						fixed_trail_again = true;
 						break;
 					//case 0xd4:
@@ -348,7 +344,7 @@
 					case 0xda:	// raw 16 (str 16)
 					case 0xdb:	// raw 32 (str 32)
 						trail = 1 << ((((unsigned int)*p) & 0x03) - 1);
-						cs = next_cs(p);
+						cs_ = next_cs(p);
 						fixed_trail_again = true;
 						break;
 					case 0xdc:	// array 16
@@ -356,56 +352,56 @@
 					case 0xde:	// map 16
 					case 0xdf:	// map 32
 						trail = 2 << (((unsigned int)*p) & 0x01);
-						cs = next_cs(p);
+						cs_ = next_cs(p);
 						fixed_trail_again = true;
 						break;
 					default:
-						off = update_attributes(p, data, top, cs, trail, user);
+						off = update_attributes(p, data, trail);
 						return -1;
 					}
 				} else if(0xa0 <= selector && selector <= 0xbf) { // FixRaw
 					trail = (unsigned int)*p & 0x1f;
 					if(trail == 0) {
-						unpack_raw(user, data, n, trail, obj);
-						int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+						unpack_raw(user_, data, n, trail, obj);
+						int ret = push_proc(c, obj, p, data, off, trail);
 						if (ret != 0) return ret;
 					}
-					cs = ACS_RAW_VALUE;
+					cs_ = ACS_RAW_VALUE;
 					fixed_trail_again = true;

 				} else if(0x90 <= selector && selector <= 0x9f) { // FixArray
 					int ret = push_aggregate<fix_tag>(
-						unpack_array(), CT_ARRAY_ITEM, stack, c, obj, p, p, data, off, top, cs, trail, user);
+						unpack_array(), CT_ARRAY_ITEM, c, obj, p, p, data, off, trail);
 					if (ret != 0) return ret;
 				} else if(0x80 <= selector && selector <= 0x8f) { // FixMap
 					int ret = push_aggregate<fix_tag>(
-						unpack_map(), CT_MAP_KEY, stack, c, obj, p, p, data, off, top, cs, trail, user);
+						unpack_map(), CT_MAP_KEY, c, obj, p, p, data, off, trail);
 					if (ret != 0) return ret;
 				} else {
-					off = update_attributes(p, data, top, cs, trail, user);
+					off = update_attributes(p, data, trail);
 					return -1;
 				}
 				// end CS_HEADER
 			}
-			if (cs != CS_HEADER || fixed_trail_again) {
+			if (cs_ != CS_HEADER || fixed_trail_again) {
 				if (fixed_trail_again) {
 					++p;
 					fixed_trail_again = false;
 				}
 				if((size_t)(pe - p) < trail) {
-					off = update_attributes(p, data, top, cs, trail, user);
+					off = update_attributes(p, data, trail);
 					return 0;
 				}
 				n = p;
 				p += trail - 1;
-				switch(cs) {
+				switch(cs_) {
 				//case CS_
 				//case CS_
 				case CS_FLOAT: {
 					union { uint32_t i; float f; } mem;
 					mem.i = load<uint32_t>(n);
-					unpack_float(user, mem.f, obj);
-					int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+					unpack_float(user_, mem.f, obj);
+					int ret = push_proc(c, obj, p, data, off, trail);
 					if (ret != 0) return ret;
 				} break;
 				case CS_DOUBLE: {
@@ -415,60 +411,60 @@
 					// https://github.com/msgpack/msgpack-perl/pull/1
 					mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
 #endif
-					unpack_double(user, mem.f, obj);
-					int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+					unpack_double(user_, mem.f, obj);
+					int ret = push_proc(c, obj, p, data, off, trail);
 					if (ret != 0) return ret;
 				} break;
 				case CS_UINT_8: {
-					unpack_uint8(user, load<uint8_t>(n), obj);
-					int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+					unpack_uint8(user_, load<uint8_t>(n), obj);
+					int ret = push_proc(c, obj, p, data, off, trail);
 					if (ret != 0) return ret;
 				} break;
 				case CS_UINT_16: {
-					unpack_uint16(user, load<uint16_t>(n), obj);
-					int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+					unpack_uint16(user_, load<uint16_t>(n), obj);
+					int ret = push_proc(c, obj, p, data, off, trail);
 					if (ret != 0) return ret;
 				} break;
 				case CS_UINT_32: {
-					unpack_uint32(user, load<uint32_t>(n), obj);
-					int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+					unpack_uint32(user_, load<uint32_t>(n), obj);
+					int ret = push_proc(c, obj, p, data, off, trail);
 					if (ret != 0) return ret;
 				} break;
 				case CS_UINT_64: {
-					unpack_uint64(user, load<uint64_t>(n), obj);
-					int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+					unpack_uint64(user_, load<uint64_t>(n), obj);
+					int ret = push_proc(c, obj, p, data, off, trail);
 					if (ret != 0) return ret;
 				} break;
 				case CS_INT_8: {
-					unpack_int8(user, load<uint8_t>(n), obj);
-					int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+					unpack_int8(user_, load<uint8_t>(n), obj);
+					int ret = push_proc(c, obj, p, data, off, trail);
 					if (ret != 0) return ret;
 				} break;
 				case CS_INT_16: {
-					unpack_int16(user, load<int16_t>(n), obj);
-					int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+					unpack_int16(user_, load<int16_t>(n), obj);
+					int ret = push_proc(c, obj, p, data, off, trail);
 					if (ret != 0) return ret;
 				} break;
 				case CS_INT_32: {
-					unpack_int32(user, load<int32_t>(n), obj);
-					int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+					unpack_int32(user_, load<int32_t>(n), obj);
+					int ret = push_proc(c, obj, p, data, off, trail);
 					if (ret != 0) return ret;
 				} break;
 				case CS_INT_64: {
-					unpack_int64(user, load<int64_t>(n), obj);
-					int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+					unpack_int64(user_, load<int64_t>(n), obj);
+					int ret = push_proc(c, obj, p, data, off, trail);
 					if (ret != 0) return ret;
 				} break;
 				case CS_BIN_8:
 				case CS_RAW_8:
 					trail = load<uint8_t>(n);
 					if(trail == 0) {
-						unpack_raw(user, data, n, trail, obj);
-						int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+						unpack_raw(user_, data, n, trail, obj);
+						int ret = push_proc(c, obj, p, data, off, trail);
 						if (ret != 0) return ret;
 					}
 					else {
-						cs = ACS_RAW_VALUE;
+						cs_ = ACS_RAW_VALUE;
 						fixed_trail_again = true;
 					}
 					break;
@@ -476,12 +472,12 @@
 				case CS_RAW_16:
 					trail = load<uint16_t>(n);
 					if(trail == 0) {
-						unpack_raw(user, data, n, trail, obj);
-						int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+						unpack_raw(user_, data, n, trail, obj);
+						int ret = push_proc(c, obj, p, data, off, trail);
 						if (ret != 0) return ret;
 					}
 					else {
-						cs = ACS_RAW_VALUE;
+						cs_ = ACS_RAW_VALUE;
 						fixed_trail_again = true;
 					}
 					break;
@@ -489,50 +485,50 @@
 				case CS_RAW_32:
 					trail = load<uint32_t>(n);
 					if(trail == 0) {
-						unpack_raw(user, data, n, trail, obj);
-						int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+						unpack_raw(user_, data, n, trail, obj);
+						int ret = push_proc(c, obj, p, data, off, trail);
 						if (ret != 0) return ret;
 					}
 					else {
-						cs = ACS_RAW_VALUE;
+						cs_ = ACS_RAW_VALUE;
 						fixed_trail_again = true;
 					}
 					break;
 				case ACS_RAW_VALUE: {
-					unpack_raw(user, data, n, trail, obj);
-					int ret = push_proc(stack, c, obj, p, data, off, top, cs, trail, user);
+					unpack_raw(user_, data, n, trail, obj);
+					int ret = push_proc(c, obj, p, data, off, trail);
 					if (ret != 0) return ret;
 				} break;
 				case CS_ARRAY_16: {
 					int ret = push_aggregate<uint16_t>(
-						unpack_array(), CT_ARRAY_ITEM, stack, c, obj, p, n, data, off, top, cs, trail, user);
+						unpack_array(), CT_ARRAY_ITEM, c, obj, p, n, data, off, trail);
 					if (ret != 0) return ret;
 				} break;
 				case CS_ARRAY_32: {
 					/* FIXME security guard */
 					int ret = push_aggregate<uint32_t>(
-						unpack_array(), CT_ARRAY_ITEM, stack, c, obj, p, n, data, off, top, cs, trail, user);
+						unpack_array(), CT_ARRAY_ITEM, c, obj, p, n, data, off, trail);
 					if (ret != 0) return ret;
 				} break;
 				case CS_MAP_16: {
 					int ret = push_aggregate<uint16_t>(
-						unpack_map(), CT_MAP_KEY, stack, c, obj, p, n, data, off, top, cs, trail, user);
+						unpack_map(), CT_MAP_KEY, c, obj, p, n, data, off, trail);
 					if (ret != 0) return ret;
 				} break;
 				case CS_MAP_32: {
 					/* FIXME security guard */
 					int ret = push_aggregate<uint32_t>(
-						unpack_map(), CT_MAP_KEY, stack, c, obj, p, n, data, off, top, cs, trail, user);
+						unpack_map(), CT_MAP_KEY, c, obj, p, n, data, off, trail);
 					if (ret != 0) return ret;
 				} break;
 				default:
-					off = update_attributes(p, data, top, cs, trail, user);
+					off = update_attributes(p, data, trail);
 					return -1;
 				}
 			}
 		} while(p != pe);

-		off = update_attributes(p, data, top, cs, trail, user);
+		off = update_attributes(p, data, trail);
 		return 0;
 	}

@@ -547,33 +543,29 @@
 	int push_aggregate(
 		Func const& f,
 		unsigned int ct,
-		template_unpack_stack* stack,
 		template_unpack_stack*& c,
 		object& obj,
 		const char*& current,
 		const char* load_pos,
 		const char* origin,
 		size_t& off,
-		unsigned int& top,
-		unsigned int& cs,
-		unsigned int trail,
-		unpack_user& user) {
-		if(top < MSGPACK_EMBED_STACK_SIZE /* FIXME */
-		   && f(user, load<T>(load_pos), stack[top].obj())) {
+		unsigned int trail) {
+		if(top_ < MSGPACK_EMBED_STACK_SIZE /* FIXME */
+		   && f(user_, load<T>(load_pos), stack_[top_].obj())) {
 			if(load<T>(load_pos) == 0) {
-				obj = stack[top].obj();
-				int ret = push_proc(stack, c, obj, current, origin, off, top, cs, trail, user);
+				obj = stack_[top_].obj();
+				int ret = push_proc(c, obj, current, origin, off, trail);
 				if (ret != 0) return ret;
 			}
 			else {
-				stack[top].set_ct(ct);
-				stack[top].set_count(load<T>(load_pos));
-				++top;
-				header_again(cs, current);
+				stack_[top_].set_ct(ct);
+				stack_[top_].set_count(load<T>(load_pos));
+				++top_;
+				header_again(current);
 			}
 		}
 		else {
-			off = update_attributes(current, origin, top, cs, trail, user);
+			off = update_attributes(current, origin, trail);
 			return -1;
 		}
 		return 0;
@@ -582,40 +574,29 @@
 	size_t update_attributes(
 		const char* current,
 		const char* origin,
-		unsigned int top,
-		unsigned int cs,
-		unsigned int trail,
-		unpack_user const& user) {
+		unsigned int trail) {
 		trail_ = trail;
-		top_ = top;
-		cs_ = cs;
-		user_ = user;
 		return current - origin;
 	}

-	static void header_again(unsigned int& cs, const char*& current) {
-		cs = CS_HEADER;
+	void header_again(const char*& current) {
+		cs_ = CS_HEADER;
 		++current;
 	}
-	static int push_item(
-		template_unpack_stack* stack,
-		template_unpack_stack*& c,
-		object& obj,
-		unsigned int top,
-		unpack_user& user) {
+	int push_item(template_unpack_stack*& c, object& obj) {
 		bool finish = false;
 		while (!finish) {
-			if(top == 0) {
+			if(top_ == 0) {
 				return 1;
 			}
-			c = &stack[top-1];
+			c = &stack_[top_ - 1];
 			switch(c->ct()) {
 			case CT_ARRAY_ITEM:
-				unpack_array_item(user, c->obj(), obj);
+				unpack_array_item(user_, c->obj(), obj);
 				if(c->decl_count() == 0) {
 					obj = c->obj();
-					--top;
-					/*printf("stack pop %d\n", top);*/
+					--top_;
+					/*printf("stack pop %d\n", top_);*/
 				}
 				else {
 					finish = true;
@@ -627,11 +608,11 @@
 				finish = true;
 				break;
 			case CT_MAP_VALUE:
-				unpack_map_item(user, c->obj(), c->map_key(), obj);
+				unpack_map_item(user_, c->obj(), c->map_key(), obj);
 				if(c->decl_count() == 0) {
 					obj = c->obj();
-					--top;
-					/*printf("stack pop %d\n", top);*/
+					--top_;
+					/*printf("stack pop %d\n", top_);*/
 				}
 				else {
 					c->set_ct(CT_MAP_KEY);
@@ -646,28 +627,24 @@
 	}

 	int push_proc(
-		template_unpack_stack* stack,
 		template_unpack_stack*& c,
 		object& obj,
 		const char*& current,
 		const char* origin,
 		size_t& off,
-		unsigned int top,
-		unsigned int& cs,
-		unsigned int trail,
-		unpack_user& user) {
-		int ret = push_item(stack, c, obj, top, user);
+		unsigned int trail) {
+		int ret = push_item(c, obj);
 		if (ret > 0) {
-			stack[0].setObj(obj);
+			stack_[0].setObj(obj);
 			++current;
 			/*printf("-- finish --\n"); */
-			off = update_attributes(current, origin, top, cs, trail, user);
+			off = update_attributes(current, origin, trail);
 		}
 		else if (ret < 0) {
-			off = update_attributes(current, origin, top, cs, trail, user);
+			off = update_attributes(current, origin, trail);
 		}
 		else {
-			header_again(cs, current);
+			header_again(current);
 		}
 		return ret;
 	}