Use LOG_F interface for unsupported functions.

This will provide the function name in the log.

BUG=b/8115521
TESTED=enabled ANDROID_NOT_SUPPORTED on Linux and observed log lines as expected

Review URL: https://webrtc-codereview.appspot.com/1096005

git-svn-id: 03ae4fbe531b1eefc9d815f31e49022782c42458@3474 4adac7df-926f-26a2-2b94-8c16560cd09d

--- voice_engine/voice_engine_defines.h
+++ voice_engine/voice_engine_defines.h
@@ -16,8 +16,9 @@
 #ifndef WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H
 #define WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H

-#include "common_types.h"
-#include "engine_configurations.h"
+#include "webrtc/common_types.h"
+#include "webrtc/engine_configurations.h"
+#include "webrtc/system_wrappers/interface/logging.h"

 // ----------------------------------------------------------------------------
 //  Enumerators
@@ -188,6 +189,11 @@
 //  Macros
 // ----------------------------------------------------------------------------

+#define NOT_SUPPORTED(stat)                  \
+  LOG_F(LS_ERROR) << "not supported";        \
+  stat.SetLastError(VE_FUNC_NOT_SUPPORTED);  \
+  return -1;
+
 #if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
   #include <windows.h>
   #include <stdio.h>
@@ -356,10 +362,7 @@
   #define WEBRTC_VOICE_ENGINE_AGC_DEFAULT_MODE \
       GainControl::kAdaptiveDigital

-  #define ANDROID_NOT_SUPPORTED(stat)                         \
-      stat.SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,   \
-                        "API call not supported");            \
-      return -1;
+  #define ANDROID_NOT_SUPPORTED(stat) NOT_SUPPORTED(stat)

 #else // LINUX PC

@@ -455,10 +458,7 @@
   #define WEBRTC_VOICE_ENGINE_AGC_DEFAULT_MODE \
       GainControl::kAdaptiveDigital

-  #define IPHONE_NOT_SUPPORTED(stat) \
-    stat.SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, \
-                      "API call not supported"); \
-    return -1;
+  #define IPHONE_NOT_SUPPORTED(stat) NOT_SUPPORTED(stat)

 #else // Non-iPhone


Removing virtuality of Item::isStructuredItem().

--- src/store/api/item.h
+++ src/store/api/item.h
@@ -178,7 +178,7 @@
   /**
    *  @return  "true" if the item is a JSON item or a node
    */
-  virtual bool
+  bool
   isStructuredItem() const;

   /**


Draft tuna_chunk_fprintf

Draft tuna_chunk_fprintf

--- tuna/tuna.c
+++ tuna/tuna.c
@@ -33,6 +33,9 @@
 #include <strings.h>
 #include <time.h>

+#define STRINGIFY(s) STRINGIFY_HELPER(s)
+#define STRINGIFY_HELPER(s) #s
+
 #ifndef NAN
 /** C89 mechanism to obtain not-a-number. */
 #define NAN (sqrt(-1))
@@ -235,7 +238,7 @@

 tuna_stats*
 tuna_chunk_merge(tuna_stats* const s,
-                  const tuna_chunk* const k)
+                 const tuna_chunk* const k)
 {
     size_t i;
     tuna_stats_merge(s, &k->stats);
@@ -742,13 +745,30 @@
                    const char *format,
                    ...)
 {
+    int nwritten;
     va_list ap;
-
     va_start(ap, format);
-    /* TODO */
+    nwritten = vfprintf(stream, format, ap);
     va_end(ap);
-
-    return -1;
+    if (nwritten >= 0) {
+        int status = -1;
+        tuna_stats o;
+        memset(&o, 0, sizeof(o));
+        tuna_chunk_merge(&o, k);
+        status = fprintf(stream,
+                         "%s"
+                         "%" STRINGIFY(DBL_DIG) "lu "
+                         "%" STRINGIFY(DBL_DIG) "g +/- "
+                         "%" STRINGIFY(DBL_DIG) "g\n",
+                         *format ? " " : "",
+                         (long unsigned) tuna_stats_cnt(&o),
+                         tuna_stats_avg(&o),
+                         tuna_stats_std(&o));
+        nwritten = status > 0
+                 ? nwritten + status
+                 : status;
+    }
+    return nwritten;
 }

 int


Don't crash when we can't open a file.

Don't crash when we can't open a file.

--- util/muse.c
+++ util/muse.c
@@ -69,6 +69,8 @@

     st = file->file.exports;
     f = fopen(path, "r");
+    if (!f)
+        die("Couldn't open %s\n", path);
     loaduse(f, st);
     fclose(f);
 }


bfin: allow to build ldd

bfin: allow to build ldd

--- utils/ldd.c
+++ utils/ldd.c
@@ -32,6 +32,11 @@

 #if defined(__avr32__)
 #define MATCH_MACHINE(x) (x == EM_AVR32)
+#define ELFCLASSM      ELFCLASS32
+#endif
+
+#if defined(__bfin__)
+#define MATCH_MACHINE(x) (x == EM_BLACKFIN)
 #define ELFCLASSM      ELFCLASS32
 #endif


A better fix...

A better fix...

--- utils/ldd.c
+++ utils/ldd.c
@@ -281,7 +281,7 @@

 	/* If this is a fully resolved name, our job is easy */
 	if (stat (lib->name, &filestat) == 0) {
-		lib->path = lib->name;
+		lib->path = strdup(lib->name);
 		return;
 	}

@@ -470,7 +470,7 @@
 			return NULL;
 		newlib->name = malloc(strlen(s)+1);
 		strcpy(newlib->name, s);
-		newlib->path = newlib->name;
+		newlib->path = strdup(newlib->name);
 		newlib->resolved = 1;
 		newlib->next = NULL;

@@ -664,14 +664,12 @@
 			printf("\tnot a dynamic executable\n");

 		for (cur = lib_list; cur; cur=cur->next) {
+			free(cur->name);
+			cur->name=NULL;
 			if (cur->path && cur->path != not_found) {
 				free(cur->path);
 				cur->path=NULL;
 			}
-			if (cur->name) {
-				free(cur->name);
-				cur->name=NULL;
-			}
 		}
 		lib_list=NULL;
 	}


use EdgeWeight typedef where possible

use EdgeWeight typedef where possible

--- DataStructures/SegmentInformation.h
+++ DataStructures/SegmentInformation.h
@@ -39,7 +39,7 @@
 {
     FixedPointCoordinate location;
     NodeID name_id;
-    unsigned duration;
+    EdgeWeight duration;
     float length;
     short bearing; // more than enough [0..3600] fits into 12 bits
     TurnInstruction turn_instruction;
@@ -48,7 +48,7 @@

     explicit SegmentInformation(const FixedPointCoordinate &location,
                                 const NodeID name_id,
-                                const unsigned duration,
+                                const EdgeWeight duration,
                                 const float length,
                                 const TurnInstruction turn_instruction,
                                 const bool necessary,
@@ -60,7 +60,7 @@

     explicit SegmentInformation(const FixedPointCoordinate &location,
                                 const NodeID name_id,
-                                const unsigned duration,
+                                const EdgeWeight duration,
                                 const float length,
                                 const TurnInstruction turn_instruction)
         : location(location), name_id(name_id), duration(duration), length(length), bearing(0),


Skip incomplete dives.

Skip incomplete dives.

We received an interesting case of a dive computer whose battery died
during a dive. Apparantly the device recorded some samples, but failed
to terminate the dive properly. In the linked list, the next pointer of
this dive points to itself, which is obviously an invalid value.

I suspect the device initializes the next pointer to point to itself at
the start of a new dive, and updates it again with the correct value
once the dive has finished. But due to the battery failure, that last
step never happened.

Anyway, since we are traversing the linked list backwards, we don't need
the next pointer, and we can simply skip the incomplete dive. The error
is not returned immediately anymore, but delayed until the end of the
download.

--- src/suunto_common2.c
+++ src/suunto_common2.c
@@ -236,6 +236,9 @@

 	const suunto_common2_layout_t *layout = device->layout;

+	// Error status for delayed errors.
+	device_status_t status = DEVICE_STATUS_SUCCESS;
+
 	// Enable progress notifications.
 	device_progress_t progress = DEVICE_PROGRESS_INITIALIZER;
 	progress.maximum = layout->rb_profile_end - layout->rb_profile_begin +
@@ -404,32 +407,37 @@
 			free (data);
 			return DEVICE_STATUS_ERROR;
 		}
-		if (next != previous) {
+		if (next != previous && next != current) {
 			WARNING ("Profiles are not continuous.");
 			free (data);
 			return DEVICE_STATUS_ERROR;
 		}

+		if (next != current) {
+			unsigned int fp_offset = FP_OFFSET;
+			if (devinfo.model == 0x15)
+				fp_offset += 6; // HelO2
+
+			if (memcmp (p + fp_offset, device->fingerprint, sizeof (device->fingerprint)) == 0) {
+				free (data);
+				return DEVICE_STATUS_SUCCESS;
+			}
+
+			if (callback && !callback (p + 4, size - 4, p + fp_offset, sizeof (device->fingerprint), userdata)) {
+				free (data);
+				return DEVICE_STATUS_SUCCESS;
+			}
+		} else {
+			WARNING ("Skipping incomplete dive.");
+			status = DEVICE_STATUS_ERROR;
+		}
+
 		// Next dive.
 		previous = current;
 		current = prev;
-
-		unsigned int fp_offset = FP_OFFSET;
-		if (devinfo.model == 0x15)
-			fp_offset += 6; // HelO2
-
-		if (memcmp (p + fp_offset, device->fingerprint, sizeof (device->fingerprint)) == 0) {
-			free (data);
-			return DEVICE_STATUS_SUCCESS;
-		}
-
-		if (callback && !callback (p + 4, size - 4, p + fp_offset, sizeof (device->fingerprint), userdata)) {
-			free (data);
-			return DEVICE_STATUS_SUCCESS;
-		}
 	}

 	free (data);

-	return DEVICE_STATUS_SUCCESS;
-}
+	return status;
+}


Continued development on NEC ports.

Continued development on NEC ports.

git-svn-id: 43aea61533866f88f23079d48f4f5dc2d5288937@688 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

--- Demo/NEC_78K0R_IAR/FreeRTOSConfig.h
+++ Demo/NEC_78K0R_IAR/FreeRTOSConfig.h
@@ -112,7 +112,7 @@
 		#define INCLUDE_vTaskDelayUntil			1
 		#define INCLUDE_vTaskDelay				1

-		#ifdef configCLOCK_SOURCE == 0
+		#if configCLOCK_SOURCE == 0
 			#define configCPU_CLOCK_HZ			( ( unsigned portLONG ) 20000000 )  /* using the external clock source */
 		#else
 			#define configCPU_CLOCK_HZ			( ( unsigned portLONG ) 8000000 )   /* using the internal high speed clock */


ImgProps (chart, shape, image)

ImgProps (chart, shape, image)

git-svn-id: bd6e61130530ab01186c33a20f55445ba6f1e843@57854 954022d7-b5bf-4e40-9824-e11837661b57

--- DesktopEditor/Word_Api/Editor_Api.h
+++ DesktopEditor/Word_Api/Editor_Api.h
@@ -474,7 +474,7 @@
 {
 	class CAscShapeProp
 	{
-		js_wrapper<int>				m_nType;
+		js_wrapper<std::wstring>	m_sType;

 		js_wrapper<CAscFill>		m_oFill;
 		js_wrapper<CAscStroke>		m_oStroke;
@@ -487,16 +487,11 @@
 	public:
 		CAscShapeProp()
 		{
-			m_nType.SetNull();
-			m_oFill.SetNull();
-			m_oStroke.SetNull();
-			m_oPaddings.SetNull();
-
 			m_bCanFill = true;
 			m_bFromChart = false;
 		}

-		LINK_PROPERTY_INT_JS(Type)
+		LINK_PROPERTY_STRING_JS(Type)
 		LINK_PROPERTY_BOOL_JS(CanFill)
 		LINK_PROPERTY_BOOL_JS(FromChart)

@@ -543,9 +538,183 @@
 		LINK_PROPERTY_BOOL(IsCorrect)
 	};

+	class CAscValAxisSettings
+    {
+	private:
+		js_wrapper<int>			m_nMinValRule;		// c_oAscValAxisRule_
+		js_wrapper<int>			m_nMinVal;
+		js_wrapper<int>			m_nMaxValRule;		// c_oAscValAxisRule_
+		js_wrapper<int>			m_nMaxVal;
+
+        js_wrapper<bool>		m_bInsertValOrder;
+
+		js_wrapper<bool>		m_bLogScale;
+		js_wrapper<int>			m_nLogBase;
+
+        js_wrapper<int>			m_nDispUnitsRule;	// c_oAscValAxUnits_
+		js_wrapper<int>			m_nUnits;			// c_oAscValAxUnits_
+
+		js_wrapper<bool>		m_bShowUnitsOnChart;
+
+		js_wrapper<int>			m_nMajorTickMark;	// c_oAscTickMark_
+		js_wrapper<int>			m_nMinorTickMark;	// c_oAscTickMark_
+
+		js_wrapper<int>			m_nTickLabelsPos;	// c_oAscTickLabelsPos_
+
+		js_wrapper<int>			m_nCrossesRule;		// c_oAscCrossesRule_
+		js_wrapper<int>			m_nCrosses;
+
+		js_wrapper<int>			m_nAxisType;		// c_oAscAxisType_
+
+	public:
+		CAscValAxisSettings()
+		{
+		}
+
+		LINK_PROPERTY_INT_JS(MinValRule)
+		LINK_PROPERTY_INT_JS(MinVal)
+		LINK_PROPERTY_INT_JS(MaxValRule)
+		LINK_PROPERTY_INT_JS(MaxVal)
+
+		LINK_PROPERTY_BOOL_JS(InsertValOrder)
+
+		LINK_PROPERTY_BOOL_JS(LogScale)
+		LINK_PROPERTY_INT_JS(LogBase)
+
+		LINK_PROPERTY_INT_JS(DispUnitsRule)
+		LINK_PROPERTY_INT_JS(Units)
+
+		LINK_PROPERTY_BOOL_JS(ShowUnitsOnChart)
+
+		LINK_PROPERTY_INT_JS(MajorTickMark)
+		LINK_PROPERTY_INT_JS(MinorTickMark)
+
+		LINK_PROPERTY_INT_JS(TickLabelsPos)
+
+		LINK_PROPERTY_INT_JS(CrossesRule)
+		LINK_PROPERTY_INT_JS(Crosses)
+
+		LINK_PROPERTY_INT_JS(AxisType)
+    };
+
+	class CAscCatAxisSettings
+    {
+	private:
+        js_wrapper<double>		m_dInternalBetweenTick;
+		js_wrapper<int>			m_nIntervalBetweenLabelsRule;	// c_oAscBetweenLabelsRule_
+		js_wrapper<double>		m_dInternalBetweenLabels;
+
+		js_wrapper<bool>		m_bInvertCatOrder;
+		js_wrapper<double>		m_dLabelsAxisDistance;
+
+		js_wrapper<int>			m_nMajorTickMark;	// c_oAscTickMark_
+		js_wrapper<int>			m_nMinorTickMark;	// c_oAscTickMark_
+
+		js_wrapper<int>			m_nTickLabelsPos;	// c_oAscTickLabelsPos_
+
+		js_wrapper<int>			m_nCrossesRule;		// c_oAscCrossesRule_
+		js_wrapper<int>			m_nCrosses;
+
+		js_wrapper<int>			m_nLabelsPosition;	// c_oAscLabelsPosition_
+
+		js_wrapper<int>			m_nAxisType;		// c_oAscAxisType_
+
+	public:
+		CAscCatAxisSettings()
+		{
+		}
+
+		LINK_PROPERTY_DOUBLE_JS(InternalBetweenTick)
+		LINK_PROPERTY_INT_JS(IntervalBetweenLabelsRule)
+		LINK_PROPERTY_DOUBLE_JS(InternalBetweenLabels)
+
+		LINK_PROPERTY_BOOL_JS(InvertCatOrder)
+		LINK_PROPERTY_DOUBLE_JS(LabelsAxisDistance)
+
+		LINK_PROPERTY_INT_JS(MajorTickMark)
+		LINK_PROPERTY_INT_JS(MinorTickMark)
+		LINK_PROPERTY_INT_JS(TickLabelsPos)
+		LINK_PROPERTY_INT_JS(CrossesRule)
+		LINK_PROPERTY_INT_JS(Crosses)
+		LINK_PROPERTY_INT_JS(LabelsPosition)
+		LINK_PROPERTY_INT_JS(AxisType)
+    };
+
 	class CAscChartProperties
 	{
-		// TODO:
+	private:
+		js_wrapper<int>				m_nStyle;
+		js_wrapper<int>				m_nTitle;	// c_oAscChartTitleShowSettings_
+
+		js_wrapper<int>				m_nRowCols;
+
+        js_wrapper<int>				m_nHorAxisLabel;	// c_oAscChartHorAxisLabelShowSettings_
+		js_wrapper<int>				m_nVertAxisLabel;	// c_oAscChartVertAxisLabelShowSettings_
+
+		js_wrapper<int>				m_nLegendPos;		// c_oAscChartLegendShowSettings_
+		js_wrapper<int>				m_nDataLabelPos;	// c_oAscChartDataLabelsPos_
+
+		js_wrapper<int>				m_nHorAx;
+		js_wrapper<int>				m_nVertAx;
+
+		js_wrapper<int>				m_nHorGridLines;	// c_oAscGridLinesSettings_
+		js_wrapper<int>				m_nVertGridLines;	// c_oAscGridLinesSettings_
+
+		js_wrapper<int>				m_nType;
+
+		js_wrapper<bool>			m_bShowSerName;
+		js_wrapper<bool>			m_bShowCatName;
+		js_wrapper<bool>			m_bShowVal;
+
+		js_wrapper<std::wstring>	m_sSeparator;
+
+		js_wrapper<CAscValAxisSettings>	m_oHorAxisProps;
+		js_wrapper<CAscValAxisSettings>	m_oVertAxisProps;
+
+		js_wrapper<std::wstring>	m_sRange;
+		js_wrapper<bool>			m_bInColumns;
+
+		js_wrapper<bool>			m_bShowMarker;
+		js_wrapper<bool>			m_bLine;
+		js_wrapper<bool>			m_bSmooth;
+
+	public:
+		CAscChartProperties()
+		{
+		}
+
+		LINK_PROPERTY_INT_JS(Style)
+		LINK_PROPERTY_INT_JS(Title)
+
+		LINK_PROPERTY_INT_JS(RowCols)
+
+		LINK_PROPERTY_INT_JS(HorAxisLabel)
+		LINK_PROPERTY_INT_JS(VertAxisLabel)
+
+		LINK_PROPERTY_INT_JS(LegendPos)
+		LINK_PROPERTY_INT_JS(DataLabelPos)
+		LINK_PROPERTY_INT_JS(HorAx)
+		LINK_PROPERTY_INT_JS(VertAx)
+
+		LINK_PROPERTY_INT_JS(HorGridLines)
+		LINK_PROPERTY_INT_JS(VertGridLines)
+		LINK_PROPERTY_INT_JS(Type)
+
+		LINK_PROPERTY_BOOL_JS(ShowSerName)
+		LINK_PROPERTY_BOOL_JS(ShowCatName)
+		LINK_PROPERTY_BOOL_JS(ShowVal)
+
+		LINK_PROPERTY_STRING_JS(Separator)
+
+		LINK_PROPERTY_OBJECT_JS(CAscValAxisSettings, HorAxisProps)
+		LINK_PROPERTY_OBJECT_JS(CAscValAxisSettings, VertAxisProps)
+
+		LINK_PROPERTY_STRING_JS(Range)
+		LINK_PROPERTY_BOOL_JS(InColumns)
+
+		LINK_PROPERTY_BOOL_JS(ShowMarker)
+		LINK_PROPERTY_BOOL_JS(Line)
+		LINK_PROPERTY_BOOL_JS(Smooth)
 	};

 	class CAscImageProp
@@ -575,7 +744,7 @@
 		js_wrapper<CAscShapeProp> m_oShapeProperties;

 		js_wrapper<int> m_nChangeLevel;
-		js_wrapper<bool> m_bGroup;
+		js_wrapper<int> m_nGroup;

 		js_wrapper<bool> m_bFromGroup;

@@ -611,7 +780,7 @@

 		LINK_PROPERTY_INT_JS(ChangeLevel)

-		LINK_PROPERTY_BOOL_JS(Group)
+		LINK_PROPERTY_INT_JS(Group)
 		LINK_PROPERTY_BOOL_JS(FromGroup)
 		LINK_PROPERTY_BOOL_JS(SeveralCharts)

@@ -1034,6 +1203,56 @@
 	};
 }

+// header/footer
+namespace NSEditorApi
+{
+	class CAscHeaderFooterPr
+	{
+	private:
+		js_wrapper<int>		m_nType;
+		js_wrapper<double>	m_dPosition;
+		js_wrapper<bool>	m_bDifferentFirst;
+		js_wrapper<bool>	m_bDifferentEvenOdd;
+		js_wrapper<bool>	m_bLinkToPrevious;
+		js_wrapper<bool>	m_bLocked;
+
+	public:
+
+		CAscHeaderFooterPr()
+		{
+		}
+
+		LINK_PROPERTY_INT_JS(Type)
+		LINK_PROPERTY_DOUBLE_JS(Position)
+		LINK_PROPERTY_BOOL_JS(DifferentFirst)
+		LINK_PROPERTY_BOOL_JS(DifferentEvenOdd)
+		LINK_PROPERTY_BOOL_JS(LinkToPrevious)
+		LINK_PROPERTY_BOOL_JS(Locked)
+	};
+}
+
+// hyperlink
+namespace NSEditorApi
+{
+	class CAscHyperlinkPr
+	{
+	private:
+		js_wrapper<std::wstring> m_sText;
+		js_wrapper<std::wstring> m_sValue;
+		js_wrapper<std::wstring> m_sToolTip;
+
+	public:
+
+		CAscHyperlinkPr()
+		{
+		}
+
+		LINK_PROPERTY_STRING_JS(Text)
+		LINK_PROPERTY_STRING_JS(Value)
+		LINK_PROPERTY_STRING_JS(ToolTip)
+	};
+}
+
 // common
 namespace NSEditorApi
 {
@@ -1187,5 +1406,7 @@
 #define ASC_MENU_EVENT_TYPE_REDO				4
 #define ASC_MENU_EVENT_TYPE_LOADDOCUMENT		5
 #define ASC_MENU_EVENT_TYPE_STACK_OBJECTS		6
+#define ASC_MENU_EVENT_TYPE_HEADERFOOTER		7
+#define ASC_MENU_EVENT_TYPE_HYPERLINK			8

 #endif //_BUILD_EDITOR_API_CROSSPLATFORM_H_


ncd: net.watch.interfaces: port to NCDUdevManager

--- ncd/modules/net_watch_interfaces.c
+++ ncd/modules/net_watch_interfaces.c
@@ -38,111 +38,246 @@

 #include <stdlib.h>
 #include <string.h>
-#include <stdio.h>
-#include <ctype.h>
-
-#include <ncd/NCDInterfaceMonitor.h>
+
+#include <misc/debug.h>
+#include <misc/offset.h>
+#include <misc/parse_number.h>
+#include <structure/LinkedList1.h>
+#include <udevmonitor/NCDUdevManager.h>
 #include <ncd/NCDModule.h>
+#include <ncd/modules/event_template.h>

 #include <generated/blog_channel_ncd_net_watch_interfaces.h>

 #define ModuleLog(i, ...) NCDModuleInst_Backend_Log((i), BLOG_CURRENT_CHANNEL, __VA_ARGS__)
+
+struct device {
+    char *ifname;
+    char *devpath;
+    uintmax_t ifindex;
+    LinkedList1Node devices_list_node;
+};

 struct instance {
     NCDModuleInst *i;
-    NCDInterfaceMonitor monitor;
-    FILE *net_file;
-    char line_buf[256];
-    int processing;
-    const char *processing_type;
-    char processing_name[256];
+    NCDUdevClient client;
+    LinkedList1 devices_list;
+    event_template templ;
 };

 struct nextevent_instance {
     NCDModuleInst *i;
 };

-static void next_file_event (struct instance *o)
-{
-    ASSERT(!o->processing)
-    ASSERT(o->net_file)
-
-    char *name;
-
-    while (1) {
-        if (!fgets(o->line_buf, sizeof(o->line_buf), o->net_file)) {
-            // close file
-            fclose(o->net_file);
-
-            // set no net file
-            o->net_file = NULL;
-
-            // start processing monitor events
-            NCDInterfaceMonitor_Continue(&o->monitor);
-
-            return;
+static void templ_func_free (struct instance *o);
+
+struct device * find_device_by_ifname (struct instance *o, const char *ifname)
+{
+    LinkedList1Node *list_node = LinkedList1_GetFirst(&o->devices_list);
+    while (list_node) {
+        struct device *device = UPPER_OBJECT(list_node, struct device, devices_list_node);
+        if (!strcmp(device->ifname, ifname)) {
+            return device;
+        }
+        list_node = LinkedList1Node_Next(list_node);
+    }
+
+    return NULL;
+}
+
+struct device * find_device_by_devpath (struct instance *o, const char *devpath)
+{
+    LinkedList1Node *list_node = LinkedList1_GetFirst(&o->devices_list);
+    while (list_node) {
+        struct device *device = UPPER_OBJECT(list_node, struct device, devices_list_node);
+        if (!strcmp(device->devpath, devpath)) {
+            return device;
+        }
+        list_node = LinkedList1Node_Next(list_node);
+    }
+
+    return NULL;
+}
+
+static void free_device (struct instance *o, struct device *device)
+{
+    // remove from devices list
+    LinkedList1_Remove(&o->devices_list, &device->devices_list_node);
+
+    // free devpath
+    free(device->devpath);
+
+    // free ifname
+    free(device->ifname);
+
+    // free structure
+    free(device);
+}
+
+static int queue_event (struct instance *o, int added, const char *ifname)
+{
+    // init map
+    BStringMap map;
+    BStringMap_Init(&map);
+
+    // set type
+    if (!BStringMap_Set(&map, "event_type", (added ? "added" : "removed"))) {
+        ModuleLog(o->i, BLOG_ERROR, "BStringMap_Set failed");
+        goto fail1;
+    }
+
+    // set ifname
+    if (!BStringMap_Set(&map, "devname", ifname)) {
+        ModuleLog(o->i, BLOG_ERROR, "BStringMap_Set failed");
+        goto fail1;
+    }
+
+    // pass event to template
+    int was_empty;
+    if (!event_template_queue(&o->templ, map, &was_empty)) {
+        ModuleLog(o->i, BLOG_ERROR, "event_template_queue failed");
+        goto fail1;
+    }
+
+    // if event queue was empty, stop receiving udev events
+    if (was_empty) {
+        NCDUdevClient_Pause(&o->client);
+    }
+
+    return 1;
+
+fail1:
+    BStringMap_Free(&map);
+    ModuleLog(o->i, BLOG_ERROR, "failed to queue event");
+    return 0;
+}
+
+static void add_device (struct instance *o, const char *ifname, const char *devpath, uintmax_t ifindex)
+{
+    ASSERT(!find_device_by_ifname(o, ifname))
+    ASSERT(!find_device_by_devpath(o, devpath))
+
+    // allocate structure
+    struct device *device = malloc(sizeof(*device));
+    if (!device) {
+        ModuleLog(o->i, BLOG_ERROR, "malloc failed");
+        goto fail0;
+    }
+
+    // init ifname
+    if (!(device->ifname = strdup(ifname))) {
+        ModuleLog(o->i, BLOG_ERROR, "strdup failed");
+        goto fail1;
+    }
+
+    // init devpath
+    if (!(device->devpath = strdup(devpath))) {
+        ModuleLog(o->i, BLOG_ERROR, "strdup failed");
+        goto fail2;
+    }
+
+    // set ifindex
+    device->ifindex = ifindex;
+
+    // insert to devices list
+    LinkedList1_Append(&o->devices_list, &device->devices_list_node);
+
+    // queue event
+    if (!queue_event(o, 1, device->ifname)) {
+        goto fail3;
+    }
+
+    return;
+
+fail3:
+    LinkedList1_Remove(&o->devices_list, &device->devices_list_node);
+    free(device->devpath);
+fail2:
+    free(device->ifname);
+fail1:
+    free(device);
+fail0:
+    ModuleLog(o->i, BLOG_ERROR, "failed to add device %s", ifname);
+}
+
+static int remove_device (struct instance *o, struct device *device)
+{
+    if (!queue_event(o, 0, device->ifname)) {
+        goto fail0;
+    }
+
+    free_device(o, device);
+
+    return 1;
+
+fail0:
+    ModuleLog(o->i, BLOG_ERROR, "failed to remove device %s", device->ifname);
+    return 0;
+}
+
+static void next_event (struct instance *o)
+{
+    event_template_assert_enabled(&o->templ);
+
+    // order template to finish the current event
+    int is_empty;
+    event_template_next(&o->templ, &is_empty);
+
+    // if template has no events, continue udev events
+    if (is_empty) {
+        NCDUdevClient_Continue(&o->client);
+    }
+}
+
+static void client_handler (struct instance *o, char *devpath, int have_map, BStringMap map)
+{
+    // lookup existing device with this devpath
+    struct device *ex_device = find_device_by_devpath(o, devpath);
+    // lookup cache entry
+    const BStringMap *cache_map = NCDUdevManager_Query(o->i->umanager, devpath);
+
+    if (!cache_map) {
+        if (ex_device) {
+            remove_device(o, ex_device);
+        }
+        goto out;
+    }
+
+    const char *subsystem = BStringMap_Get(cache_map, "SUBSYSTEM");
+    const char *interface = BStringMap_Get(cache_map, "INTERFACE");
+    const char *ifindex_str = BStringMap_Get(cache_map, "IFINDEX");
+
+    uintmax_t ifindex;
+    if (!(subsystem && !strcmp(subsystem, "net") && interface && ifindex_str && parse_unsigned_integer(ifindex_str, &ifindex))) {
+        if (ex_device) {
+            remove_device(o, ex_device);
+        }
+        goto out;
+    }
+
+    if (ex_device && (strcmp(ex_device->ifname, interface) || ex_device->ifindex != ifindex)) {
+        if (!remove_device(o, ex_device)) {
+            goto out;
+        }
+        ex_device = NULL;
+    }
+
+    if (!ex_device) {
+        struct device *ex_ifname_device = find_device_by_ifname(o, interface);
+        if (ex_ifname_device) {
+            if (!remove_device(o, ex_ifname_device)) {
+                goto out;
+            }
         }

-        // parse line to get interface name
-        char *c = o->line_buf;
-        while (*c && isspace(*c)) {
-            c++;
-        }
-        name = c;
-        while (*c && *c != ':') {
-            c++;
-        }
-        if (*c != ':') {
-            continue;
-        }
-        *c = '\0';
-
-        break;
-    }
-
-    // set event
-    o->processing_type = "added";
-    snprintf(o->processing_name, sizeof(o->processing_name), "%s", name);
-    o->processing = 1;
-
-    // signal up
-    NCDModuleInst_Backend_Event(o->i, NCDMODULE_EVENT_UP);
-}
-
-static void next_event (struct instance *o)
-{
-    ASSERT(o->processing)
-
-    // set not processing
-    o->processing = 0;
-
-    // signal down
-    NCDModuleInst_Backend_Event(o->i, NCDMODULE_EVENT_DOWN);
-
-    if (o->net_file) {
-        next_file_event(o);
-        return;
-    } else {
-        // continue processing monitor events
-        NCDInterfaceMonitor_Continue(&o->monitor);
-    }
-}
-
-static void monitor_handler (struct instance *o, const char *ifname, int if_flags)
-{
-    ASSERT(!o->processing)
-    ASSERT(!o->net_file)
-
-    // pause monitor
-    NCDInterfaceMonitor_Pause(&o->monitor);
-
-    // set event
-    o->processing_type = ((if_flags & NCDIFCONFIG_FLAG_EXISTS) ? "added" : "removed");
-    snprintf(o->processing_name, sizeof(o->processing_name), "%s", ifname);
-    o->processing = 1;
-
-    // signal up
-    NCDModuleInst_Backend_Event(o->i, NCDMODULE_EVENT_UP);
+        add_device(o, interface, devpath, ifindex);
+    }
+
+out:
+    free(devpath);
+    if (have_map) {
+        BStringMap_Free(&map);
+    }
 }

 static void func_new (NCDModuleInst *i)
@@ -164,27 +299,15 @@
         goto fail1;
     }

-    // init monitor
-    if (!NCDInterfaceMonitor_Init(&o->monitor, o->i->reactor, (NCDInterfaceMonitor_handler)monitor_handler, o)) {
-        ModuleLog(o->i, BLOG_ERROR, "NCDInterfaceMonitor_Init failed");
-        goto fail1;
-    }
-    NCDInterfaceMonitor_Pause(&o->monitor);
-
-    // open /proc/net/dev
-    if (!(o->net_file = fopen("/proc/net/dev", "r"))) {
-        ModuleLog(o->i, BLOG_ERROR, "fopen(/proc/net/dev) failed");
-        goto fail2;
-    }
-
-    // set not processing
-    o->processing = 0;
-
-    next_file_event(o);
+    // init client
+    NCDUdevClient_Init(&o->client, o->i->umanager, o, (NCDUdevClient_handler)client_handler);
+
+    // init devices list
+    LinkedList1_Init(&o->devices_list);
+
+    event_template_new(&o->templ, o->i, BLOG_CURRENT_CHANNEL, o, (event_template_func_free)templ_func_free);
     return;

-fail2:
-    NCDInterfaceMonitor_Free(&o->monitor);
 fail1:
     free(o);
 fail0:
@@ -192,18 +315,19 @@
     NCDModuleInst_Backend_Event(i, NCDMODULE_EVENT_DEAD);
 }

-static void func_die (void *vo)
-{
-    struct instance *o = vo;
+static void templ_func_free (struct instance *o)
+{
     NCDModuleInst *i = o->i;

-    // close /proc/net/dev
-    if (o->net_file) {
-        fclose(o->net_file);
-    }
-
-    // free monitor
-    NCDInterfaceMonitor_Free(&o->monitor);
+    // free devices
+    LinkedList1Node *list_node;
+    while (list_node = LinkedList1_GetFirst(&o->devices_list)) {
+        struct device *device = UPPER_OBJECT(list_node, struct device, devices_list_node);
+        free_device(o, device);
+    }
+
+    // free client
+    NCDUdevClient_Free(&o->client);

     // free instance
     free(o);
@@ -211,30 +335,16 @@
     NCDModuleInst_Backend_Event(i, NCDMODULE_EVENT_DEAD);
 }

+static void func_die (void *vo)
+{
+    struct instance *o = vo;
+    event_template_die(&o->templ);
+}
+
 static int func_getvar (void *vo, const char *name, NCDValue *out)
 {
     struct instance *o = vo;
-    ASSERT(o->processing)
-
-    if (!strcmp(name, "event_type")) {
-        if (!NCDValue_InitString(out, o->processing_type)) {
-            ModuleLog(o->i, BLOG_ERROR, "NCDValue_InitString failed");
-            return 0;
-        }
-
-        return 1;
-    }
-
-    if (!strcmp(name, "devname")) {
-        if (!NCDValue_InitString(out, o->processing_name)) {
-            ModuleLog(o->i, BLOG_ERROR, "NCDValue_InitString failed");
-            return 0;
-        }
-
-        return 1;
-    }
-
-    return 0;
+    return event_template_getvar(&o->templ, name, out);
 }

 static void nextevent_func_new (NCDModuleInst *i)
@@ -258,7 +368,7 @@

     // get method object
     struct instance *mo = i->method_object->inst_user;
-    ASSERT(mo->processing)
+    event_template_assert_enabled(&mo->templ);

     // signal up.
     // Do it before finishing the event so our process does not advance any further if


massive overhaul of libvol2bird. Collection of the relevant data, as well as constructing a profile of a given type is now part of the libvol2bird library, as it should be (was previously here: https://github.com/jspaaks/baltrad-node/. Further added some printer methods for various variables. Also changed the paradigm to use static globals, which will help to simplify the interfaces (still TODO) and general clarity of the code.


detNumberOfGates now calculates the total number of gates within valid range for an array of scan elevations


add missing header

add missing header

--- Digipost/Digipost-Bridging-Header.h
+++ Digipost/Digipost-Bridging-Header.h
@@ -13,5 +13,5 @@
 #import "POSInvoice.h"
 #import "POSAttachment.h"
 #import "POSDocument.h"
-
+#import "UIViewController+BackButton.h"
 #import "POSReceipt.h"


fix irq flags in mac80211 code

fix irq flags in mac80211 code

A file in the net/mac80211 directory uses "int" for flags.  This can cause
hard to find bugs on some architectures.  This patch converts the flags to use
"long" instead.

This bug was discovered by doing an allyesconfig make on the -rt kernel where
checks are done to ensure all flags are of size sizeof(long).

Signed-off-by: Steven Rostedt <9d183ff83abfec5c556edaf86a280a53916a11d8@redhat.com>
Cc: "John W. Linville" <2a53bac7a5d324865ef46ec4c38b2c0fba1456b4@tuxdriver.com>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>

--- net/mac80211/rc80211_pid_debugfs.c
+++ net/mac80211/rc80211_pid_debugfs.c
@@ -85,7 +85,7 @@
 	struct rc_pid_sta_info *sinfo = inode->i_private;
 	struct rc_pid_event_buffer *events = &sinfo->events;
 	struct rc_pid_events_file_info *file_info;
-	unsigned int status;
+	unsigned long status;

 	/* Allocate a state struct */
 	file_info = kmalloc(sizeof(*file_info), GFP_KERNEL);
@@ -135,7 +135,7 @@
 	char pb[RC_PID_PRINT_BUF_SIZE];
 	int ret;
 	int p;
-	unsigned int status;
+	unsigned long status;

 	/* Check if there is something to read. */
 	if (events->next_entry == file_info->next_entry) {


changed ilutGetString(IL_VERSION) to ilutGetString(IL_VERSION_NUM)

--- DevIL/src-ILUT/src/ilut_states.c
+++ DevIL/src-ILUT/src/ilut_states.c
@@ -48,7 +48,8 @@
 	{
 		case IL_VENDOR:
 			return (const char*)_ilutVendor;
-		case IL_VERSION:
+		//changed 2003-09-04
+		case IL_VERSION_NUM:
 			return (const char*)_ilutVersion;
 		default:
 			ilSetError(ILUT_INVALID_PARAM);


Remove a couple unused macros

Remove a couple unused macros

--- Alc/vector.h
+++ Alc/vector.h
@@ -79,13 +79,6 @@
         _f(_iter);                                                            \
 } while(0)

-#define VECTOR_FOR_EACH_PARAMS(_t, _x, _f, ...)  do {                         \
-    _t *_iter = VECTOR_BEGIN((_x));                                           \
-    _t *_end = VECTOR_END((_x));                                              \
-    for(;_iter != _end;++_iter)                                               \
-        _f(__VA_ARGS__, _iter);                                               \
-} while(0)
-
 #define VECTOR_FIND_IF(_i, _t, _x, _f)  do {                                  \
     _t *_iter = VECTOR_BEGIN((_x));                                           \
     _t *_end = VECTOR_END((_x));                                              \
@@ -97,15 +90,4 @@
     (_i) = _iter;                                                             \
 } while(0)

-#define VECTOR_FIND_IF_PARMS(_i, _t, _x, _f, ...)  do {                       \
-    _t *_iter = VECTOR_BEGIN((_x));                                           \
-    _t *_end = VECTOR_END((_x));                                              \
-    for(;_iter != _end;++_iter)                                               \
-    {                                                                         \
-        if(_f(__VA_ARGS__, _iter))                                            \
-            break;                                                            \
-    }                                                                         \
-    (_i) = _iter;                                                             \
-} while(0)
-
 #endif /* AL_VECTOR_H */


Create Problem2-4.c

Create Problem2-4.c

error: pathspec 'Chapter-2/Problem2-4.c' did not match any file(s) known to git


hash: fix buffer overflow

hash: fix buffer overflow

need to check for \0 on the end of strings properly

--- src/hash.c
+++ src/hash.c
@@ -18,7 +18,7 @@
 hash_nullterminated(const char* a)
 {
 	uint32_t sum = 0;
-	while(a != 0)
+	while(*a != 0)
 	{
 		sum += *a;
 		++a;


[src] Removed some useless code from parrot_hash_size() as the hash parameter
is a NOTNULL parameter.

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

--- src/hash.c
+++ src/hash.c
@@ -1176,11 +1176,7 @@
 {
     ASSERT_ARGS(parrot_hash_size)

-    if (hash)
-        return hash->entries;
-
-    Parrot_ex_throw_from_c_args(interp, NULL, 1,
-        "parrot_hash_size asked to check a NULL hash\n");
+    return hash->entries;
 }


jenkins hash: optimize last memcpy

jenkins hash: optimize last memcpy

compiler cannot optimize variable-size memcpy.
use a inlined simple version then.

That makes this version always faster than
Jenkins version on Core Duo.  On other cpu-s
its +3% win although still slower than Jenkins'.

--- src/hash.c
+++ src/hash.c
@@ -56,7 +56,17 @@
 	c ^= b; c -= rot(b,24); \
 } while (0)

-/* simple version - let compiler worry about memory access */
+/* for a small amount of bytes the call to libc is a loss */
+static inline void simple_memcpy(void *dst, const void *src, size_t n)
+{
+	const uint8_t *s = src;
+	uint8_t *d = dst;
+
+	while (n--)
+		*d++ = *s++;
+}
+
+/* short version - let compiler worry about memory access */
 uint32_t lookup3_hash(const void *data, size_t len)
 {
 	uint32_t a, b, c;
@@ -78,7 +88,7 @@
 	}

 	buf[0] = buf[1] = buf[2] = 0;
-	memcpy(buf, p, len);
+	simple_memcpy(buf, p, len);
 	a += buf[0];
 	b += buf[1];
 	c += buf[2];


Fix spelling and POD errors

Fix spelling and POD errors

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

--- src/hash.c
+++ src/hash.c
@@ -14,7 +14,7 @@
 hashing functions can be set.

 This hash implementation uses just one piece of malloced memory. The
-C<hash->bu> union points into this regions. At positive indices are
+C<< hash->bu >> union points into this regions. At positive indices are
 bucket pointers, at negative indices is the bucket store itself.

 This hash doesn't move during GC, therefore a lot of the old caveats
@@ -573,7 +573,7 @@
 	bp->key = bp->value = NULL;
 	hash->free_list = bp;
     }
-    /* see the grafic in expand_hash */
+    /* see the graphic in expand_hash */
     hash->bu.bs = bp;
     for (i = 0; i < INITIAL_BUCKETS; ++i) {
 	hash->bu.bi[i] = NULL;
@@ -683,7 +683,7 @@
     void *res;

     /* idx directly in the bucket store, which is at negative
-     * addressess from the data pointer
+     * address from the data pointer
      */
     /* locate initial */
     if (bi == INITBucketIndex) {
@@ -972,7 +972,7 @@
 =item * Stop reallocating the bucket pool, and instead add chunks on.
 (Saves pointer fixups and copying during C<realloc>.)

-=item * Hash contraction (dunno if it's worth it)
+=item * Hash contraction (don't if it's worth it)

 =back


Avoid VLA in hash.h

Avoid VLA in hash.h

--- src/hash.h
+++ src/hash.h
@@ -25,9 +25,9 @@
     static const size_t OUTPUT_SIZE = CSHA256::OUTPUT_SIZE;

     void Finalize(unsigned char hash[OUTPUT_SIZE]) {
-        unsigned char buf[sha.OUTPUT_SIZE];
+        unsigned char buf[CSHA256::OUTPUT_SIZE];
         sha.Finalize(buf);
-        sha.Reset().Write(buf, sha.OUTPUT_SIZE).Finalize(hash);
+        sha.Reset().Write(buf, CSHA256::OUTPUT_SIZE).Finalize(hash);
     }

     CHash256& Write(const unsigned char *data, size_t len) {
@@ -49,9 +49,9 @@
     static const size_t OUTPUT_SIZE = CRIPEMD160::OUTPUT_SIZE;

     void Finalize(unsigned char hash[OUTPUT_SIZE]) {
-        unsigned char buf[sha.OUTPUT_SIZE];
+        unsigned char buf[CSHA256::OUTPUT_SIZE];
         sha.Finalize(buf);
-        CRIPEMD160().Write(buf, sha.OUTPUT_SIZE).Finalize(hash);
+        CRIPEMD160().Write(buf, CSHA256::OUTPUT_SIZE).Finalize(hash);
     }

     CHash160& Write(const unsigned char *data, size_t len) {


selection: Do not add duplicate lines into the selection

--- src/hstr.c
+++ src/hstr.c
@@ -110,6 +110,7 @@
 #define HH_CONFIG_BIG_KEYS_SKIP  "big-keys-skip"
 #define HH_CONFIG_BIG_KEYS_FLOOR "big-keys-floor"
 #define HH_CONFIG_BIG_KEYS_EXIT  "big-keys-exit"
+#define HH_CONFIG_UNIQUE_OFF "unique-off"

 #define HH_DEBUG_LEVEL_NONE  0
 #define HH_DEBUG_LEVEL_WARN  1
@@ -246,6 +247,7 @@
     int caseSensitive;

     bool interactive;
+    bool unique;

     unsigned char theme;
     int bigKeys;
@@ -271,6 +273,7 @@
     hstr->caseSensitive=HH_CASE_INSENSITIVE;

     hstr->interactive=true;
+    hstr->unique=true;

     hstr->theme=HH_THEME_MONO;
     hstr->bigKeys=RADIX_BIG_KEYS_SKIP;
@@ -333,6 +336,10 @@
             if(strstr(hstr_config,HH_CONFIG_WARN)) {
                 hstr->debugLevel=HH_DEBUG_LEVEL_WARN;
             }
+        }
+
+        if(strstr(hstr_config,HH_CONFIG_UNIQUE_OFF)) {
+            hstr->unique=false;
         }
     }
 }
@@ -367,6 +374,25 @@
     refresh();

     return promptLength;
+}
+
+void add_to_selection(Hstr *hstr, char *line, unsigned int *index)
+{
+    if (hstr->unique) {
+        // Search the selection for occurences of the line being added
+        for (int i = 0; i < *index; i++) {
+            if (strcmp(hstr->selection[i], line) == 0) {
+                // This line already in selection, skipping
+                return;
+            }
+        }
+    }
+
+    // Add the line to the selection
+    hstr->selection[*index]=line;
+
+    // Increment the selection index
+    *index = *index + 1;
 }

 void print_help_label()
@@ -529,19 +555,19 @@
     for(i=0; i<count && selectionCount<maxSelectionCount; i++) {
         if(source[i]) {
             if(!prefix || !strlen(prefix)) {
-                hstr->selection[selectionCount++]=source[i];
+                add_to_selection(hstr, source[i], &selectionCount);
             } else {
                 switch(hstr->historyMatch) {
                 case HH_MATCH_SUBSTRING:
                     switch(hstr->caseSensitive) {
                     case HH_CASE_SENSITIVE:
                         if(source[i]==strstr(source[i], prefix)) {
-                            hstr->selection[selectionCount++]=source[i];
+                            add_to_selection(hstr, source[i], &selectionCount);
                         }
                         break;
                     case HH_CASE_INSENSITIVE:
                         if(source[i]==strcasestr(source[i], prefix)) {
-                            hstr->selection[selectionCount++]=source[i];
+                            add_to_selection(hstr, source[i], &selectionCount);
                         }
                         break;
                     }
@@ -576,7 +602,7 @@
                         }
                     }
                     if (keywordsAllMatch) {
-                        hstr->selection[selectionCount++]=source[i];
+                        add_to_selection(hstr, source[i], &selectionCount);
                     }
                     free(keywordsPointerToDelete);
                     break;
@@ -594,13 +620,13 @@
                 case HH_CASE_SENSITIVE:
                     substring = strstr(source[i], prefix);
                     if (substring != NULL && substring!=source[i]) {
-                        hstr->selection[selectionCount++]=source[i];
+                        add_to_selection(hstr, source[i], &selectionCount);
                     }
                     break;
                 case HH_CASE_INSENSITIVE:
                     substring = strcasestr(source[i], prefix);
                     if (substring != NULL && substring!=source[i]) {
-                        hstr->selection[selectionCount++]=source[i];
+                        add_to_selection(hstr, source[i], &selectionCount);
                     }
                     break;
                 }


INCREF jit.* types before releasing the GIL

Signed-off-by: Niklas Koep <342d5290239d9c5264c8f98185afedb99596601a@gmail.com>

--- src/pyjit-jitmodule.c
+++ src/pyjit-jitmodule.c
@@ -85,9 +85,12 @@
         return NULL;
     PyFile_IncUseCount(fo);

+    Py_INCREF(type);
     Py_BEGIN_ALLOW_THREADS
     jit_dump_type(fp, type_);
     Py_END_ALLOW_THREADS
+    Py_DECREF(type);
+
     PyFile_DecUseCount(fo);

     Py_RETURN_NONE;
@@ -129,9 +132,16 @@
         return NULL;
     PyFile_IncUseCount(fo);

+    /* If func is dereferenced by another thread during I/O, it may call
+     * jit_function_abandon in the process and destroy memory jit_dump_value is
+     * still accessing. To remove this possibility, incref func here.
+     */
+    Py_INCREF(func);
     Py_BEGIN_ALLOW_THREADS
     jit_dump_value(fp, function, value_, prefix);
     Py_END_ALLOW_THREADS
+    Py_DECREF(func);
+
     PyFile_DecUseCount(fo);

     Py_RETURN_NONE;
@@ -172,9 +182,13 @@
         return NULL;
     PyFile_IncUseCount(fo);

+    /* TODO: Do have to keep a strong temp ref to insn here? */
+    Py_INCREF(func);
     Py_BEGIN_ALLOW_THREADS
     jit_dump_insn(fp, function, insn_);
     Py_END_ALLOW_THREADS
+    Py_DECREF(func);
+
     PyFile_DecUseCount(fo);

     Py_RETURN_NONE;
@@ -209,9 +223,12 @@
         return NULL;
     PyFile_IncUseCount(fo);

+    Py_INCREF(func);
     Py_BEGIN_ALLOW_THREADS
     jit_dump_function(fp, function, name);
     Py_END_ALLOW_THREADS
+    Py_DECREF(func);
+
     PyFile_DecUseCount(fo);

     Py_RETURN_NONE;


Fixed #145 and fixed #146 by changing color scheme to work for both black/white background terminals + removed inverse highlighting for monochromatic color scheme to make it readable again.

--- src/hstr.c
+++ src/hstr.c
@@ -76,6 +76,11 @@
 #define K_BACKSPACE 127
 #define K_ENTER 10

+#define HH_THEME_MONO   0
+#define HH_THEME_COLOR  1<<7
+#define HH_THEME_LIGHT  1|HH_THEME_COLOR
+#define HH_THEME_DARK   2|HH_THEME_COLOR
+
 #define HH_COLOR_NORMAL  1
 #define HH_COLOR_HIROW   2
 #define HH_COLOR_INFO    2
@@ -86,8 +91,8 @@
 #define HH_ENV_VAR_CONFIG      "HH_CONFIG"
 #define HH_ENV_VAR_PROMPT      "HH_PROMPT"

-#define HH_CONFIG_MONO       "monochromatic"
-#define HH_CONFIG_HICOLOR    "hicolor"
+#define HH_CONFIG_THEME_MONOCHROMATIC   "monochromatic"
+#define HH_CONFIG_THEME_HICOLOR         "hicolor"
 #define HH_CONFIG_CASE       "casesensitive"
 #define HH_CONFIG_REGEXP     "regexp"
 #define HH_CONFIG_SUBSTRING  "substring"
@@ -97,9 +102,9 @@
 #define HH_CONFIG_BLACKLIST  "blacklist"
 #define HH_CONFIG_DEBUG      "debug"
 #define HH_CONFIG_WARN       "warning"
-#define HH_CONFIG_BIG_KEYS_SKIP  "bigkeysskip"
-#define HH_CONFIG_BIG_KEYS_FLOOR "bigkeysfloor"
-#define HH_CONFIG_BIG_KEYS_EXIT  "bigkeysexit"
+#define HH_CONFIG_BIG_KEYS_SKIP  "big-keys-skip"
+#define HH_CONFIG_BIG_KEYS_FLOOR "big-keys-floor"
+#define HH_CONFIG_BIG_KEYS_EXIT  "big-keys-exit"

 #define HH_DEBUG_LEVEL_NONE  0
 #define HH_DEBUG_LEVEL_WARN  1
@@ -143,18 +148,6 @@
 #else
 #define LOGSELECTION(Y,SCREEN,MODEL)
 #endif
-
-void logstring(char* str){
-    FILE *f = fopen("/home/tbabej/hh.log", "a");
-    if (f == NULL)
-    {
-            perror("fopen");
-        printf("Error opening file!\n");
-        exit(1);
-    }
-    fprintf(f, "Debug: %s \n", str);
-        fclose(f);
-}

 static const char *HH_VIEW_LABELS[]={
         "ranking",
@@ -247,7 +240,7 @@

     bool interactive;

-    bool hicolor;
+    unsigned char theme;
     int bigKeys;
     int debugLevel;

@@ -272,7 +265,7 @@

     hstr->interactive=true;

-    hstr->hicolor=FALSE;
+    hstr->theme=HH_THEME_MONO;
     hstr->bigKeys=RADIX_BIG_KEYS_SKIP;
     hstr->debugLevel=HH_DEBUG_LEVEL_NONE;

@@ -286,8 +279,12 @@
 {
     char *hstr_config=getenv(HH_ENV_VAR_CONFIG);
     if(hstr_config && strlen(hstr_config)>0) {
-        if(strstr(hstr_config,HH_CONFIG_HICOLOR)) {
-            hstr->hicolor=TRUE;
+        if(strstr(hstr_config,HH_CONFIG_THEME_MONOCHROMATIC)) {
+            hstr->theme=HH_THEME_MONO;
+        } else {
+            if(strstr(hstr_config,HH_CONFIG_THEME_HICOLOR)) {
+                hstr->theme=HH_THEME_DARK;
+            }
         }
         if(strstr(hstr_config,HH_CONFIG_CASE)) {
             hstr->caseSensitive=HH_CASE_SENSITIVE;
@@ -337,7 +334,7 @@
 {
     int xoffset = 0, promptLength;

-    if(hstr->hicolor) {
+    if(hstr->theme & HH_THEME_COLOR) {
         color_attr_on(COLOR_PAIR(HH_COLOR_PROMPT));
         color_attr_on(A_BOLD);
     }
@@ -356,7 +353,7 @@
         free(hostname);
     }

-    if(hstr->hicolor) {
+    if(hstr->theme & HH_THEME_COLOR) {
         color_attr_off(A_BOLD);
         color_attr_off(COLOR_PAIR(HH_COLOR_PROMPT));
     }
@@ -378,12 +375,12 @@
     char screenLine[CMDLINE_LNG];
     snprintf(screenLine, getmaxx(stdscr), "History item '%s' deleted (%d occurrence%s)", cmd, occurences, (occurences==1?"":"s"));
     // TODO make this function
-    if(hstr->hicolor) {
+    if(hstr->theme & HH_THEME_COLOR) {
         color_attr_on(COLOR_PAIR(HH_COLOR_DELETE));
         color_attr_on(A_BOLD);
     }
     mvprintw(Y_OFFSET_HELP, 0, "%s", screenLine);
-    if(hstr->hicolor) {
+    if(hstr->theme & HH_THEME_COLOR) {
         color_attr_off(A_BOLD);
         color_attr_on(COLOR_PAIR(1));
     }
@@ -395,12 +392,12 @@
 {
     char screenLine[CMDLINE_LNG];
     snprintf(screenLine, getmaxx(stdscr), "%s", errorMessage);
-    if(hstr->hicolor) {
+    if(hstr->theme & HH_THEME_COLOR) {
         color_attr_on(COLOR_PAIR(HH_COLOR_DELETE));
         color_attr_on(A_BOLD);
     }
     mvprintw(Y_OFFSET_HELP, 0, "%s", screenLine);
-    if(hstr->hicolor) {
+    if(hstr->theme & HH_THEME_COLOR) {
         color_attr_off(A_BOLD);
         color_attr_on(COLOR_PAIR(1));
     }
@@ -412,12 +409,12 @@
 {
     char screenLine[CMDLINE_LNG];
     snprintf(screenLine, getmaxx(stdscr), "Command '%s' added to favorites (C-/ to show favorites)", cmd);
-    if(hstr->hicolor) {
+    if(hstr->theme & HH_THEME_COLOR) {
         color_attr_on(COLOR_PAIR(HH_COLOR_INFO));
         color_attr_on(A_BOLD);
     }
     mvprintw(Y_OFFSET_HELP, 0, screenLine);
-    if(hstr->hicolor) {
+    if(hstr->theme & HH_THEME_COLOR) {
         color_attr_off(A_BOLD);
         color_attr_on(COLOR_PAIR(1));
     }
@@ -442,13 +439,13 @@
     for (i=0; i < width; i++) {
         strcat(screenLine, "-");
     }
-    if(hstr->hicolor) {
+    if(hstr->theme & HH_THEME_COLOR) {
         color_attr_on(A_BOLD);
     }
     color_attr_on(A_REVERSE);
     mvprintw(Y_OFFSET_HISTORY, 0, "%s", screenLine);
     color_attr_off(A_REVERSE);
-    if(hstr->hicolor) {
+    if(hstr->theme & HH_THEME_COLOR) {
         color_attr_off(A_BOLD);
     }
     refresh();
@@ -624,7 +621,9 @@

     if(pattern && strlen(pattern)) {
         color_attr_on(A_BOLD);
-        color_attr_on(COLOR_PAIR(HH_COLOR_MATCH));
+        if(hstr->theme & HH_THEME_COLOR) {
+            color_attr_on(COLOR_PAIR(HH_COLOR_MATCH));
+        }
         char *p;
         char *keywordsSavePtr;
         char *keywordsToken;
@@ -665,7 +664,9 @@

             break;
         }
-        color_attr_on(COLOR_PAIR(HH_COLOR_NORMAL));
+        if(hstr->theme & HH_THEME_COLOR) {
+            color_attr_on(COLOR_PAIR(HH_COLOR_NORMAL));
+        }
         color_attr_off(A_BOLD);
     }
 }
@@ -673,7 +674,7 @@
 void hstr_print_highlighted_selection_row(char *text, int y, int width, Hstr *hstr)
 {
     color_attr_on(A_BOLD);
-    if(hstr->hicolor) {
+    if(hstr->theme & HH_THEME_COLOR) {
         color_attr_on(COLOR_PAIR(2));
     } else {
         color_attr_on(A_REVERSE);
@@ -683,7 +684,7 @@
             "%s%s" SPACE_PADDING SPACE_PADDING SPACE_PADDING,
             (terminal_has_colors()?" ":">"), text);
     mvprintw(y, 0, "%s", screenLine);
-    if(hstr->hicolor) {
+    if(hstr->theme & HH_THEME_COLOR) {
         color_attr_on(COLOR_PAIR(1));
     } else {
         color_attr_off(A_REVERSE);
@@ -822,11 +823,12 @@
     hstr_curses_start();
     // TODO move the code below to hstr_curses
     color_init_pair(HH_COLOR_NORMAL, -1, -1);
-    if(hstr->hicolor) {
+    if(hstr->theme & HH_THEME_COLOR) {
         color_init_pair(HH_COLOR_HIROW, COLOR_WHITE, COLOR_GREEN);
         color_init_pair(HH_COLOR_PROMPT, COLOR_BLUE, -1);
         color_init_pair(HH_COLOR_DELETE, COLOR_WHITE, COLOR_RED);
-        color_init_pair(HH_COLOR_MATCH, COLOR_YELLOW, -1);
+
+        color_init_pair(HH_COLOR_MATCH, COLOR_RED, -1);
     }

     color_attr_on(COLOR_PAIR(HH_COLOR_NORMAL));


added http_status_is_success()

added http_status_is_success()

--- src/http.h
+++ src/http.h
@@ -65,4 +65,10 @@
     return http_status_to_string_data[status / 100][status % 100];
 }

+static inline int
+http_status_is_success(http_status_t status)
+{
+    return status >= 200 && status < 300;
+}
+
 #endif


Addresses #2217 refs[t:2217]
Fix r16084, test now correctly shows file size reduces after many inserts and deletes

git-svn-id: b5c078ec0b4d3a50497e9dd3081db18a5b4f16e5@16108 c7de825b-a66e-492c-adef-691d508d4ae1

--- src/tests/filesize.c
+++ src/tests/filesize.c
@@ -54,13 +54,14 @@
     }
 }

-static void
-insert_n (u_int32_t ah) {
-    int datasize = 1500;
+#define INSERT_BIG 1500
+#define INSERT_SMALL 0
+static void
+insert_n (u_int32_t ah, int datasize) {
     uint64_t vdata[datasize];
     fill_rand(datasize, vdata);
     u_int32_t an = htonl(ah);
-    //    printf("insert an = %0X (ah = %0X)\n", an, ah);
+    //    if (verbose) printf("insert an = %0X (ah = %0X)\n", an, ah);
     DBT key = {.size = 4,             .data=&an };
     DBT val = {.size = sizeof(vdata), .data=vdata};
     int r = db->put(db, NULL, &key, &val, DB_YESOVERWRITE);
@@ -72,7 +73,7 @@
 delete_n (u_int32_t ah)
 {
     u_int32_t an = htonl(ah);
-    //    printf("delete an = %0X (ah = %0X)\n", an, ah);
+    //    if (verbose) printf("delete an = %0X (ah = %0X)\n", an, ah);
     DBT key = {.size = 4,             .data=&an };
     int r = db->del(db, NULL, &key, DB_DELETE_ANY);
     if (r == 0)
@@ -101,11 +102,11 @@
     r = dbc->c_get(dbc, &k, &v, DB_FIRST);
     if (r==0) {
 	nread++;
-	//	printf("First read, r = %0X, key = %0X (size=%d)\n", r, *(uint32_t*)k.data, k.size);
+	//	if (verbose) printf("First read, r = %0X, key = %0X (size=%d)\n", r, *(uint32_t*)k.data, k.size);
     }
     else if (r == DB_NOTFOUND)  {
 	nread_notfound++;
-	//	printf("First read failed: %d\n", r);
+	//	if (verbose) printf("First read failed: %d\n", r);
     }
     else
 	nread_failed++;
@@ -113,7 +114,7 @@
 	r = dbc->c_get(dbc, &k, &v, DB_NEXT);
 	if (r == 0) {
 	    nread++;
-	    //	    printf("read key = %0X (size=%d)\n", *(uint32_t*)k.data, k.size);
+	    //	    if (verbose) printf("read key = %0X (size=%d)\n", *(uint32_t*)k.data, k.size);
 	}
 	else if (r == DB_NOTFOUND)
 	    nread_notfound++;
@@ -135,7 +136,7 @@
     int r = env->get_iname(env, &dname, &iname);
     CKERR(r);
     sprintf(path, "%s/%s", ENVDIR, (char*)iname.data);
-    printf("path = %s\n", path);
+    if (verbose) printf("path = %s\n", path);
 }

@@ -151,7 +152,7 @@
 static void
 test_filesize (void)
 {
-    int N=1<<16;
+    int N=1<<14;
     int r, i, sizeM;

     get_file_pathname();
@@ -160,13 +161,13 @@
 	int offset = N * iter;

 	for (i=0; i<N; i++) {
-	    insert_n(i + offset);
+	    insert_n(i + offset, INSERT_BIG);
 	}

 	r = env->txn_checkpoint(env, 0, 0, 0);
 	CKERR(r);
-	sizeM = getsizeM();
-	printf("Filesize after iteration %d insertion and checkpoint = %dM\n", iter, sizeM);
+	int sizefirst = sizeM = getsizeM();
+	if (verbose) printf("Filesize after iteration %d insertion and checkpoint = %dM\n", iter, sizeM);

 	int preserve = 2;
 	for (i = preserve; i<(N); i++) {  // leave a little at the beginning
@@ -177,32 +178,33 @@
 	r = env->txn_checkpoint(env, 0, 0, 0);
 	CKERR(r);
 	sizeM = getsizeM();
-	printf("Filesize after iteration %d deletion and checkpoint 1 = %dM\n", iter, sizeM);
-
-	insert_n(preserve+offset + 1);
+	if (verbose) printf("Filesize after iteration %d deletion and checkpoint 1 = %dM\n", iter, sizeM);
+
+	for (i=0; i<N; i++) {
+	    insert_n(i + offset, INSERT_SMALL);
+	}
+	for (i = preserve; i<(N); i++) {  // leave a little at the beginning
+	    delete_n(i + offset);
+	}
+	scan(N);
 	r = env->txn_checkpoint(env, 0, 0, 0);
 	CKERR(r);
 	sizeM = getsizeM();
-	printf("Filesize after iteration %d deletion and checkpoint 2 = %dM\n", iter, sizeM);
-
-	insert_n(preserve+offset+2);
-	r = env->txn_checkpoint(env, 0, 0, 0);
-	CKERR(r);
-	sizeM = getsizeM();
-	printf("Filesize after iteration %d deletion and checkpoint 3 = %dM\n", iter, sizeM);
-
-	printf("ninsert = %d\n", ninsert);
-	printf("nread = %d, nread_notfound = %d, nread_failed = %d\n", nread, nread_notfound, nread_failed);
-	printf("ndelete = %d, ndelete_notfound = %d, ndelete_failed = %d\n", ndelete, ndelete_notfound, ndelete_failed);
+	if (verbose) printf("Filesize after iteration %d deletion and checkpoint 2 = %dM\n", iter, sizeM);
+        assert(sizeM < sizefirst);
+
+	if (verbose) printf("ninsert = %d\n", ninsert);
+	if (verbose) printf("nread = %d, nread_notfound = %d, nread_failed = %d\n", nread, nread_notfound, nread_failed);
+	if (verbose) printf("ndelete = %d, ndelete_notfound = %d, ndelete_failed = %d\n", ndelete, ndelete_notfound, ndelete_failed);
     }
 }

 int test_main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
     parse_args(argc, argv);
     setup();
-    print_engine_status(env);
+    if (verbose) print_engine_status(env);
     test_filesize();
-    print_engine_status(env);
+    if (verbose) print_engine_status(env);
     close_em();
     return 0;
 }


Add a getnameinfo() wrapper

Add a getnameinfo() wrapper

This wrapper takes a domain name or an IP as first argument
and a service name or port as second argument.
Either argument may be nil.

It returns a list of names (always only one in the IP case) and a
service name.

--- src/inet.c
+++ src/inet.c
@@ -16,6 +16,7 @@
 static int inet_global_toip(lua_State *L);
 static int inet_global_getaddrinfo(lua_State *L);
 static int inet_global_tohostname(lua_State *L);
+static int inet_global_getnameinfo(lua_State *L);
 static void inet_pushresolved(lua_State *L, struct hostent *hp);
 static int inet_global_gethostname(lua_State *L);

@@ -24,6 +25,7 @@
     { "toip", inet_global_toip},
     { "getaddrinfo", inet_global_getaddrinfo},
     { "tohostname", inet_global_tohostname},
+    { "getnameinfo", inet_global_getnameinfo},
     { "gethostname", inet_global_gethostname},
     { NULL, NULL}
 };
@@ -74,6 +76,52 @@
     lua_pushstring(L, hp->h_name);
     inet_pushresolved(L, hp);
     return 2;
+}
+
+static int inet_global_getnameinfo(lua_State *L) {
+    int i, ret;
+    char host[1024];
+    char serv[32];
+    struct addrinfo hints;
+    struct addrinfo *resolved, *iter;
+    const char *node = luaL_optstring(L, 1, NULL);
+    const char *service = luaL_optstring(L, 2, NULL);
+
+    if (!(node || service))
+        luaL_error(L, "You have to specify a hostname, a service, or both");
+
+    memset(&hints, 0, sizeof(hints));
+    hints.ai_socktype = SOCK_STREAM;
+    hints.ai_family = PF_UNSPEC;
+
+    /* getaddrinfo must get a node and a service argument */
+    ret = getaddrinfo(node ? node : "127.0.0.1", service ? service : "7",
+        &hints, &resolved);
+    if (ret != 0) {
+        lua_pushnil(L);
+        lua_pushstring(L, socket_gaistrerror(ret));
+        return 2;
+    }
+
+    lua_newtable(L);
+    for (i = 1, iter = resolved; iter; i++, iter = iter->ai_next) {
+        getnameinfo(iter->ai_addr, iter->ai_addrlen, host,
+            node ? sizeof(host) : 0, serv, service ? sizeof(serv) : 0, 0);
+
+        if (node) {
+            lua_pushnumber(L, i);
+            lua_pushstring(L, host);
+            lua_settable(L, -3);
+        }
+    }
+    freeaddrinfo(resolved);
+
+    if (service) {
+        lua_pushstring(L, serv);
+        return 2;
+    } else {
+        return 1;
+    }
 }

 /*-------------------------------------------------------------------------*\


Fix typo, --guiet should be --quiet.

Fix typo, --guiet should be --quiet.

--- src/info.c
+++ src/info.c
@@ -120,7 +120,7 @@
 		{ "origin",		no_argument,		NULL,	'o' },
 		{ "by-origin",		no_argument,		NULL,	'O' },
 		{ "prefix",		no_argument,		NULL,	'p' },
-		{ "guiet",		no_argument,		NULL,	'q' },
+		{ "quiet",		no_argument,		NULL,	'q' },
 		{ "required-by",	no_argument,		NULL,	'r' },
 		{ "raw",		no_argument,		NULL,	'R' },
 		{ "size",		no_argument,		NULL,	's' },


* src/info.h: include stdlib so we can use uint

--- src/info.h
+++ src/info.h
@@ -25,6 +25,7 @@

 #include <stdio.h>
 #include <stdint.h>
+#include <stdlib.h>
 #include "ref.h"

 /* Reference-counted strings */


[t:4759] Added extra non-flat 4.2 tree with nested transactions to get better coverage in brt-serialize.c and ule.c.

git-svn-id: b5c078ec0b4d3a50497e9dd3081db18a5b4f16e5@42768 c7de825b-a66e-492c-adef-691d508d4ae1

--- newbrt/tests/upgrade_test_simple.c
+++ newbrt/tests/upgrade_test_simple.c
@@ -69,19 +69,19 @@
 insert_something(BRT t, CACHETABLE UU(ct), void *UU(extra))
 {
     assert(t);
-
-    return 0;
-}
-
-static int
-scan_tree(BRT t, CACHETABLE UU(ct), void *UU(extra))
-{
-    assert(t);
-
+    int r = 0;
+    unsigned int dummy_value = 1 << 31;
+    DBT key;
+    DBT val;
+    toku_fill_dbt(&key, &dummy_value, sizeof(unsigned int));
+    toku_fill_dbt(&val, &dummy_value, sizeof(unsigned int));
+    r = toku_brt_insert (t, &key, &val, 0);
+    CKERR(r);
     return 0;
 }

 typedef int (*tree_cb)(BRT t, CACHETABLE ct, void *extra);
+
 static int
 with_open_tree(const char *fname, tree_cb cb, void *cb_extra)
 {
@@ -118,6 +118,7 @@
 #define TMPBRTFMT "%s-tmpdata.brt"
 static const char *origbrt_5_0 = "upgrade_test_data.brt.5.0";
 static const char *origbrt_4_2 = "upgrade_test_data.brt.4.2";
+static const char *not_flat_4_2 = "upgrade_test_data.brt.4.2.not.flat";

 static int
 run_test(const char *prog, const char *origbrt) {
@@ -144,9 +145,6 @@
     fraction = 1.0;
     r = with_open_tree(tempbrt, do_hot_optimize, &fraction);
     CKERR(r);
-    r = with_open_tree(tempbrt, scan_tree, NULL);
-    CKERR(r);
-
     r = unlink(tempbrt);
     CKERR(r);

@@ -163,5 +161,8 @@
     r = run_test(argv[0], origbrt_4_2);
     CKERR(r);

+    r = run_test(argv[0], not_flat_4_2);
+    CKERR(r);
+
     return r;
 }


nimble/ll: Fix RxAdd in AUX_CONNECT_RSP

nimble/ll: Fix RxAdd in AUX_CONNECT_RSP

We put TxAdd bit instead of RxAdd bit so connections failed in case we
used public address and remote used random address.

--- nimble/controller/src/ble_ll_adv.c
+++ nimble/controller/src/ble_ll_adv.c
@@ -731,7 +731,10 @@
     pdulen = BLE_LL_EXT_ADV_HDR_LEN + ext_hdr_len;

     /* Set BLE transmit header */
-    hdr = BLE_ADV_PDU_TYPE_AUX_CONNECT_RSP | rsp_data->rxadd;
+    hdr = BLE_ADV_PDU_TYPE_AUX_CONNECT_RSP;
+    if (rsp_data->rxadd) {
+        hdr |= BLE_ADV_PDU_HDR_RXADD_MASK;
+    }
     if (rsp_data->advsm->flags & BLE_LL_ADV_SM_FLAG_TX_ADD) {
         hdr |= BLE_ADV_PDU_HDR_TXADD_MASK;
     }


dbverify bugfix & begin fam check for child.

--- src/tools/dbverify.c
+++ src/tools/dbverify.c
@@ -134,6 +134,7 @@
 #define ERR_MISSING 9
 #define ERR_DELETED 10
 #define ERR_BADNAME 11
+#define ERR_BADFAMREF 12

 static struct errinfo errs[] = {
 	{ ERR_ORPHANNAME, 0, 0, "Orphan names" }
@@ -148,6 +149,7 @@
 	, { ERR_MISSING, 0, 0, "Missing records" }
 	, { ERR_DELETED, 0, 0, "Deleted records" }
 	, { ERR_BADNAME, 0, 0, "Bad name" }
+	, { ERR_BADFAMREF, 0, 0, "Bad family reference" }
 };
 static struct work todo;
 static LIST tofix;
@@ -294,11 +296,12 @@
 		finish_and_delete_nameset(dupseq);
 		dupseq = create_indiseq_null();
 	}
-	append_indiseq_null(dupseq, strsave(key), NULL, TRUE, TRUE);
+
+	append_indiseq_null(dupseq, strsave(key), name, TRUE, TRUE);

 	if (!indi) {
 		report_error(ERR_ORPHANNAME, "Orphaned name: %s", name);
-		if (todo.fix_evens)
+		if (todo.fix_ghosts)
 			enqueue_list(tofix, (VPTR)alloc_namerefn(name, key, ERR_ORPHANNAME));
 	} else {
 		NODE node;
@@ -312,7 +315,7 @@
 		join_indi(indi, nam, refn, sex, body, famc, fams);
 		if (!found) {
 			report_error(ERR_GHOSTNAME, "Ghost name: %s -> %s", name, key);
-			if (todo.find_ghosts)
+			if (todo.fix_ghosts)
 				enqueue_list(tofix, (VPTR)alloc_namerefn(name, key, ERR_GHOSTNAME));
 		}
 	}
@@ -337,11 +340,11 @@
 		finish_and_delete_refnset(dupseq);
 		dupseq = create_indiseq_null();
 	}
-	append_indiseq_null(dupseq, strsave(key), NULL, TRUE, TRUE);
+	append_indiseq_null(dupseq, strsave(key), refn, TRUE, TRUE);

 	if (!node) {
 		report_error(ERR_ORPHANNAME, "Orphaned refn: %s", refn);
-		if (todo.find_ghosts)
+		if (todo.fix_ghosts)
 			enqueue_list(tofix, (VPTR)alloc_namerefn(refn, key, ERR_ORPHANNAME));
 	} else {
 	}
@@ -397,10 +400,12 @@
 	seq_evens = create_indiseq_null();
 	seq_othes = create_indiseq_null();
 	traverse_db_key_nod0s(nodes_callback, NULL);
+	/* check what we saw against delete sets */
 	check_set(seq_indis, 'I');
-	/*
-	TO DO: compare these seqs against deletesets
-	*/
+	check_set(seq_fams, 'F');
+	check_set(seq_sours, 'S');
+	check_set(seq_evens, 'E');
+	check_set(seq_othes, 'X');
 	remove_indiseq(seq_indis, FALSE);
 	remove_indiseq(seq_fams, FALSE);
 	remove_indiseq(seq_sours, FALSE);
@@ -437,10 +442,13 @@
 	NODE indi1, name1, refn1, sex1, body1, famc1, fams1;
 	NODE node;
 	INT keynum = atoi(&key[1]);
+	CACHEEL icel;
 	if (!strcmp(key, prevkey)) {
 		report_error(ERR_DUPINDI, "Duplicate individual for %s", key);
 	}
 	indi1 = nztop(nod0);
+	icel = indi_to_cacheel(indi1);
+	lock_cache(icel);
 	split_indi(indi1, &name1, &refn1, &sex1, &body1, &famc1, &fams1);
 	for (node = name1; node; node = nsibling(node)) {
 		STRING name=nval(node);
@@ -449,11 +457,24 @@
 		}
 		/* TO DO: verify that name is in db */
 	}
+	for (node = refn1; node; node = nsibling(node)) {
+		STRING refn=nval(node);
+		/* TO DO: verify that refn is in db */
+	}
+	for (node = famc1; node; node = nsibling(node)) {
+		STRING famkey=rmvat(nval(node));
+		NODE fam = qkey_to_fam(famkey);
+		if (!fam) {
+			report_error(ERR_BADFAMREF, "Bad family reference (%s) individual %s", famkey, key);
+		}
+		/* TO DO: verify that family lists indi */
+	}
 	/* TO DO: check lineage links */
 	join_indi(indi1, name1, refn1, sex1, body1, famc1, fams1);
 	/*
 	TO DO: check pointers ?
 	*/
+	unlock_cache(icel);
 	append_indiseq_null(seq_indis, strsave(key), NULL, TRUE, TRUE);
 	return TRUE;
 }


piv-tool: increase receive buffer for the 'send-apdu' command

git-svn-id: 444ed946b9c2220da791e84c3dd156a05f92db99@5340 c6295689-39f2-0310-b995-f0e70906c6a9

--- src/tools/piv-tool.c
+++ src/tools/piv-tool.c
@@ -529,8 +529,8 @@
 static int send_apdu(void)
 {
 	sc_apdu_t apdu;
-	u8 buf[SC_MAX_APDU_BUFFER_SIZE+3], sbuf[SC_MAX_APDU_BUFFER_SIZE],
-	   rbuf[SC_MAX_APDU_BUFFER_SIZE*3], *p;
+	u8 buf[SC_MAX_APDU_BUFFER_SIZE+3], sbuf[SC_MAX_APDU_BUFFER_SIZE];
+	u8 rbuf[8192], *p;
 	size_t len, len0, r;
 	int c;


piv-tool: Fix memory leaks when generating key

Thank oss-fuzz
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=49077

--- src/tools/piv-tool.c
+++ src/tools/piv-tool.c
@@ -454,17 +454,22 @@
 		if (r == 0) {
 			fprintf(stderr, "EC_POINT_set_affine_coordinates_GFp failed\n");
 			EVP_PKEY_free(evpkey);
+			EC_GROUP_free(ecgroup);
+			EC_POINT_free(ecpoint);
 			return -1;
 		}
 #if OPENSSL_VERSION_NUMBER < 0x30000000L
 		eckey = EC_KEY_new();
 		r = EC_KEY_set_group(eckey, ecgroup);
+		EC_GROUP_free(ecgroup);
 		if (r == 0) {
 			fprintf(stderr, "EC_KEY_set_group failed\n");
 			EVP_PKEY_free(evpkey);
+			EC_POINT_free(ecpoint);
 			return -1;
 		}
 		r = EC_KEY_set_public_key(eckey, ecpoint);
+		EC_POINT_free(ecpoint);
 		if (r == 0) {
 			fprintf(stderr, "EC_KEY_set_public_key failed\n");
 			EVP_PKEY_free(evpkey);
@@ -480,13 +485,21 @@
 		len = EC_POINT_point2oct(ecgroup, ecpoint, POINT_CONVERSION_COMPRESSED, NULL, 0, NULL);
 		if (!(buf = malloc(len))) {
 			fprintf(stderr, "EC_KEY_set_public_key out of memory\n");
+			EC_GROUP_free(ecgroup);
+			EC_POINT_free(ecpoint);
 			return -1;
 		}
 		if (EC_POINT_point2oct(ecgroup, ecpoint, POINT_CONVERSION_COMPRESSED, buf, len, NULL) == 0) {
 			fprintf(stderr, "EC_KEY_set_public_key failed\n");
+			EC_GROUP_free(ecgroup);
+			EC_POINT_free(ecpoint);
 			free(buf);
 			return -1;
 		}
+
+		EC_GROUP_free(ecgroup);
+		EC_POINT_free(ecpoint);
+
 		if (!(bld = OSSL_PARAM_BLD_new()) ||
 			OSSL_PARAM_BLD_push_utf8_string(bld, "group", group_name, sizeof(group_name)) != 1 ||
 			OSSL_PARAM_BLD_push_octet_string(bld, "pub", buf, len) != 1 ||


Simplify Linux internal mask<->nodeset conversion

* Use topology complete nodeset to compute a valid max_os_index
  instead of traversing the list of numa nodes
* Use bitmap from/to ith_ulong routines to manipulate masks
* Factorize a hwloc_linux_membind_mask_to_nodeset()

git-svn-id: 16596cb260ed970f4d9975c965200205db0b6693@2619 4b44e086-7f34-40ce-a3bd-00e031736276

--- src/topology-linux.c
+++ src/topology-linux.c
@@ -852,26 +852,17 @@
 }

 static int
-hwloc_linux_membind_mask_from_nodeset(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset,
+hwloc_linux_membind_mask_from_nodeset(hwloc_topology_t topology __hwloc_attribute_unused,
+				      hwloc_const_nodeset_t nodeset,
 				      unsigned *max_os_index_p, unsigned long **linuxmaskp)
 {
   unsigned max_os_index = 0; /* highest os_index + 1 */
   unsigned long *linuxmask;
-  hwloc_obj_t obj;
-  int depth;
-  int index;
-
-  /* compute max_os_index */
-  depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NODE);
-  if (depth == HWLOC_TYPE_DEPTH_UNKNOWN) {
+  unsigned i;
+
+  max_os_index = hwloc_bitmap_last(nodeset);
+  if (max_os_index == (unsigned) -1)
     max_os_index = 0;
-    depth = 0;
-  } else {
-    obj = NULL;
-    while ((obj = hwloc_get_next_obj_by_depth(topology, depth, obj)) != NULL)
-      if (obj->os_index > max_os_index)
-	max_os_index = obj->os_index;
-  }
   /* round up to the nearest multiple of BITS_PER_LONG */
   max_os_index = (max_os_index + HWLOC_BITS_PER_LONG) & ~(HWLOC_BITS_PER_LONG - 1);

@@ -881,13 +872,29 @@
     return -1;
   }

-  hwloc_bitmap_foreach_begin(index, nodeset)
-    linuxmask[index/HWLOC_BITS_PER_LONG] |= 1UL << (index % HWLOC_BITS_PER_LONG);
-  hwloc_bitmap_foreach_end();
+  for(i=0; i<max_os_index/HWLOC_BITS_PER_LONG; i++)
+    linuxmask[i] = hwloc_bitmap_to_ith_ulong(nodeset, i);

   *max_os_index_p = max_os_index;
   *linuxmaskp = linuxmask;
   return 0;
+}
+
+static void
+hwloc_linux_membind_mask_to_nodeset(hwloc_topology_t topology __hwloc_attribute_unused,
+				    hwloc_nodeset_t nodeset,
+				    unsigned _max_os_index, const unsigned long *linuxmask)
+{
+  unsigned max_os_index;
+  unsigned i;
+
+  /* round up to the nearest multiple of BITS_PER_LONG */
+  max_os_index = (_max_os_index + HWLOC_BITS_PER_LONG) & ~(HWLOC_BITS_PER_LONG - 1);
+
+  hwloc_bitmap_zero(nodeset);
+  for(i=0; i<max_os_index/HWLOC_BITS_PER_LONG; i++)
+    hwloc_bitmap_from_ith_ulong(nodeset, i, linuxmask[i]);
+  /* if we don't trust the kernel, we could clear bits from _max_os_index+1 to max_os_index-1 */
 }
 #endif /* HWLOC_HAVE_SET_MEMPOLICY || HWLOC_HAVE_MBIND */

@@ -1021,24 +1028,20 @@
 	     * code says pol = current->mempolicy;... */
 hwloc_linux_get_thisthread_membind(hwloc_topology_t topology, hwloc_nodeset_t nodeset, hwloc_membind_policy_t *policy, int flags __hwloc_attribute_unused)
 {
-  hwloc_obj_t obj;
+  hwloc_const_bitmap_t complete_nodeset;
   unsigned max_os_index; /* highest os_index + 1 */
   unsigned long *linuxmask;
-  int depth;
   int linuxpolicy;
   int err;
-  unsigned index;

   /* compute max_os_index */
-  depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NODE);
-  if (depth == HWLOC_TYPE_DEPTH_UNKNOWN) {
+  complete_nodeset = hwloc_topology_get_complete_nodeset(topology);
+  if (complete_nodeset) {
+    max_os_index = hwloc_bitmap_last(complete_nodeset);
+    if (max_os_index == (unsigned) -1)
+      max_os_index = 0;
+  } else {
     max_os_index = 0;
-    depth = 0;
-  } else {
-    obj = NULL;
-    while ((obj = hwloc_get_next_obj_by_depth(topology, depth, obj)) != NULL)
-      if (obj->os_index > max_os_index)
-	max_os_index = obj->os_index;
   }
   /* round up to the nearest multiple of BITS_PER_LONG */
   max_os_index = (max_os_index + HWLOC_BITS_PER_LONG) & ~(HWLOC_BITS_PER_LONG - 1);
@@ -1056,11 +1059,7 @@
   if (linuxpolicy == MPOL_DEFAULT) {
     hwloc_bitmap_copy(nodeset, hwloc_get_root_obj(topology)->nodeset);
   } else {
-    hwloc_bitmap_zero(nodeset);
-    for (index = 0; index < max_os_index; index++) {
-      if (linuxmask[index/HWLOC_BITS_PER_LONG] & (1UL << (index % HWLOC_BITS_PER_LONG)))
-	hwloc_bitmap_set(nodeset, index);
-    }
+    hwloc_linux_membind_mask_to_nodeset(topology, nodeset, max_os_index, linuxmask);
   }

   switch (linuxpolicy) {


errno is EFOO, not -EFOO

errno is EFOO, not -EFOO

This commit was SVN r2045.

--- src/topology-linux.c
+++ src/topology-linux.c
@@ -503,7 +503,7 @@
 hwloc_linux_set_thisthread_cpubind(hwloc_topology_t topology, hwloc_const_cpuset_t hwloc_set, int policy __hwloc_attribute_unused)
 {
   if (topology->pid) {
-    errno = -ENOSYS;
+    errno = ENOSYS;
     return -1;
   }
   return hwloc_linux_set_tid_cpubind(topology, 0, hwloc_set);
@@ -513,7 +513,7 @@
 hwloc_linux_get_thisthread_cpubind(hwloc_topology_t topology, hwloc_cpuset_t hwloc_set, int policy __hwloc_attribute_unused)
 {
   if (topology->pid) {
-    errno = -ENOSYS;
+    errno = ENOSYS;
     return -1;
   }
   return hwloc_linux_get_tid_cpubind(topology, 0, hwloc_set);
@@ -528,7 +528,7 @@
   int err;

   if (topology->pid) {
-    errno = -ENOSYS;
+    errno = ENOSYS;
     return -1;
   }

@@ -595,7 +595,7 @@
   int err;

   if (topology->pid) {
-    errno = -ENOSYS;
+    errno = ENOSYS;
     return -1;
   }


Don't retry more than 10 times in hwloc_linux_foreach_proc_tid()

If, for some reason, the thread list doesn't change and one thread
keeps failing its callback, we don't want to retry forever.

Return EAGAIN instead.

git-svn-id: 14be032f8f42541b1a281b51ae8ea69814daf20e@4444 4b44e086-7f34-40ce-a3bd-00e031736276

--- src/topology-linux.c
+++ src/topology-linux.c
@@ -476,6 +476,7 @@
   DIR *taskdir;
   pid_t *tids, *newtids;
   unsigned i, nr, newnr, failed, failed_errno;
+  unsigned retrynr = 0;
   int err;

   if (pid)
@@ -517,6 +518,12 @@
     free(tids);
     tids = newtids;
     nr = newnr;
+    if (++retrynr > 10) {
+      /* we tried 10 times, it didn't work, the application is probably creating/destroying many threads, stop trying */
+      errno = EAGAIN;
+      err = -1;
+      goto out_with_tids;
+    }
     goto retry;
   }
   /* if all threads failed, return the last errno. */


Don't use 'override' as it only works in c++11.

--- src/qt/overviewpage.h
+++ src/qt/overviewpage.h
@@ -32,7 +32,7 @@
     void transactionClicked(const QModelIndex &index);

 protected:
-    void resizeEvent(QResizeEvent *event) override;
+    void resizeEvent(QResizeEvent *event);

 private:
     Ui::OverviewPage *ui;


Parse sysfs node distances and put them in a di...

Parse sysfs node distances and put them in a distance matrix,
without using it for now.

This commit was SVN r799.

--- src/topology-linux.c
+++ src/topology-linux.c
@@ -492,6 +492,36 @@
 }

 static void
+topo_parse_node_distance(const char *distancepath, unsigned *distances, unsigned nbnodes, int fsys_root_fd)
+{
+  char string[4096]; /* enough for hundreds of nodes */
+  char *tmp, *next;
+  FILE * fd;
+
+  fd = topo_fopen(distancepath, "r", fsys_root_fd);
+  if (!fd)
+    return;
+
+  if (!fgets(string, sizeof(string), fd))
+    return;
+
+  tmp = string;
+  while (tmp) {
+    unsigned distance = strtoul(tmp, &next, 0);
+    if (next == tmp)
+      break;
+    *distances = distance;
+    distances++;
+    nbnodes--;
+    if (!nbnodes)
+      break;
+    tmp = next+1;
+  }
+
+  fclose(fd);
+}
+
+static void
 look_sysfsnode(struct topo_topology *topology,
 	       const char *path,
 	       topo_cpuset_t *admin_disabled_mems_set)
@@ -501,6 +531,7 @@
   DIR *dir;
   struct dirent *dirent;
   topo_obj_t node;
+  unsigned *distances;

   dir = topo_opendir(path, topology->backend_params.sysfs.root_fd);
   if (dir)
@@ -520,6 +551,10 @@
   if (nbnodes <= 1)
     return;

+  distances = calloc(nbnodes*nbnodes, sizeof(*distances));
+  if (!distances)
+    return;
+
   for (osnode=0; osnode < nbnodes; osnode++)
     {
       char nodepath[SYSFS_NUMA_NODE_PATH_LEN];
@@ -544,7 +579,26 @@
       topo_debug("os node %u has cpuset %"TOPO_PRIxCPUSET"\n",
 		 osnode, TOPO_CPUSET_PRINTF_VALUE(&node->cpuset));
       topo_add_object(topology, node);
-    }
+
+      sprintf(nodepath, "%s/node%u/distance", path, osnode);
+      topo_parse_node_distance(nodepath, &distances[osnode*nbnodes], nbnodes, topology->backend_params.sysfs.root_fd);
+    }
+
+#ifdef TOPO_DEBUG
+  {
+    int i,j;
+    printf("node distance matrix:\n");
+    for(i=0; i<nbnodes; i++) {
+      for(j=0; j<nbnodes; j++)
+        printf("%d ", distances[i*nbnodes+j]);
+      printf("\n");
+    }
+  }
+#endif
+
+  /* TODO: group numa nodes according to the distance matrix */
+
+  free(distances);
 }

 /* Look at Linux' /sys/devices/system/cpu/cpu%d/topology/ */


use _S variants of CPU_SET for pthread_t bindin...

use _S variants of CPU_SET for pthread_t binding too

This commit was SVN r2230.

--- src/topology-linux.c
+++ src/topology-linux.c
@@ -562,7 +562,34 @@
    * int thread_migrate (int thread_id, int destination_node);
    */

-#ifdef HWLOC_HAVE_CPU_SET
+#if defined(HWLOC_HAVE_CPU_SET_S) && !defined(HWLOC_HAVE_OLD_SCHED_SETAFFINITY)
+  /* Use a separate block so that we can define specific variable
+     types here */
+  {
+     cpu_set_t *plinux_set;
+     unsigned cpu;
+     int last;
+     size_t setsize;
+
+     last = hwloc_cpuset_last(hwloc_set);
+     if (last == -1) {
+       errno = EINVAL;
+       return -1;
+     }
+
+     setsize = CPU_ALLOC_SIZE(last+1);
+     plinux_set = CPU_ALLOC(last+1);
+
+     CPU_ZERO_S(setsize, plinux_set);
+     hwloc_cpuset_foreach_begin(cpu, hwloc_set)
+         CPU_SET_S(cpu, setsize, plinux_set);
+     hwloc_cpuset_foreach_end();
+
+     err = pthread_setaffinity_np(tid, setsize, plinux_set);
+
+     CPU_FREE(plinux_set);
+  }
+#elif defined(HWLOC_HAVE_CPU_SET)
   /* Use a separate block so that we can define specific variable
      types here */
   {
@@ -625,7 +652,36 @@
   }
   /* TODO Kerrighed */

-#ifdef HWLOC_HAVE_CPU_SET
+#if defined(HWLOC_HAVE_CPU_SET_S) && !defined(HWLOC_HAVE_OLD_SCHED_SETAFFINITY)
+  /* Use a separate block so that we can define specific variable
+     types here */
+  {
+     cpu_set_t *plinux_set;
+     unsigned cpu;
+     int last;
+     size_t setsize;
+
+     last = hwloc_cpuset_last(topology->levels[0][0]->complete_cpuset);
+     assert (last != -1);
+
+     setsize = CPU_ALLOC_SIZE(last+1);
+     plinux_set = CPU_ALLOC(last+1);
+
+     err = pthread_getaffinity_np(tid, setsize, plinux_set);
+     if (err) {
+        CPU_FREE(plinux_set);
+        errno = err;
+        return -1;
+     }
+
+     hwloc_cpuset_zero(hwloc_set);
+     for(cpu=0; cpu<(unsigned) last; cpu++)
+       if (CPU_ISSET_S(cpu, setsize, plinux_set))
+	 hwloc_cpuset_set(hwloc_set, cpu);
+
+     CPU_FREE(plinux_set);
+  }
+#elif defined(HWLOC_HAVE_CPU_SET)
   /* Use a separate block so that we can define specific variable
      types here */
   {


Add debug prints to plugin loading

Add debug prints to plugin loading

Add some debug prints (and include stdio.h) which can help diagnose
plugin load problems.

Signed-off-by: Ville Syrjala <48bd072f57a62745d96f34f7d7d8cf0b89f84886@sci.fi>
Signed-off-by: Chris Larson <8cf06b7089d5169434d5def8b2d1c9c9c95f6e71@kergoth.com>

--- src/ts_load_module.c
+++ src/ts_load_module.c
@@ -15,6 +15,7 @@
 #ifdef HAVE_ALLOCA_H
 #include <alloca.h>
 #endif
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <dlfcn.h>
@@ -46,17 +47,27 @@
 	printf ("Loading module %s\n", fn);
 #endif
 	handle = dlopen(fn, RTLD_NOW);
-	if (!handle)
+	if (!handle) {
+#ifdef DEBUG
+		fprintf (stderr, "%s dlopen() failed: %s\n", fn, dlerror());
+#endif
 		return -1;
+	}

 	init = dlsym(handle, "mod_init");
 	if (!init) {
+#ifdef DEBUG
+		fprintf (stderr, "%s dlsym() failed: %s\n", fn, dlerror());
+#endif
 		dlclose(handle);
 		return -1;
 	}

 	info = init(ts, params);
 	if (!info) {
+#ifdef DEBUG
+		fprintf (stderr, "Can't init %s\n", fn);
+#endif
 		dlclose(handle);
 		return -1;
 	}
@@ -69,6 +80,9 @@
 		ret = __ts_attach(ts, info);
 	}
 	if (ret) {
+#ifdef DEBUG
+		fprintf (stderr, "Can't attach %s\n", fn);
+#endif
 		info->ops->fini(info);
 		dlclose(handle);
 	}


Add glibc style endianess check in CCAN

Add glibc style endianess check in CCAN

CCAN adds support for glibc style in the following commit :
https://github.com/rustyrussell/ccan/commit/759ac0f0564104d5028acd47c3e9fdb858c96d1d

Signed-off-by: Akshay Adiga <94c1c71a55369af58de437823f5298ad3423270c@linux.vnet.ibm.com>
Reviewed-by: Vaidyanathan Srinivasan <c012decff9dffda4c10860ab2ba9eb53320d90bc@linux.vnet.ibm.com>
Signed-off-by: Stewart Smith <ec31ab75ddf977353c8f660f92ea8b23f64aef25@linux.vnet.ibm.com>

--- ccan/endian/endian.h
+++ ccan/endian/endian.h
@@ -103,12 +103,21 @@
 }
 #endif

+/* Needed for Glibc like endiness check */
+#define	__LITTLE_ENDIAN	1234
+#define	__BIG_ENDIAN	4321
+
 /* Sanity check the defines.  We don't handle weird endianness. */
 #if !HAVE_LITTLE_ENDIAN && !HAVE_BIG_ENDIAN
 #error "Unknown endian"
 #elif HAVE_LITTLE_ENDIAN && HAVE_BIG_ENDIAN
 #error "Can't compile for both big and little endian."
+#elif HAVE_LITTLE_ENDIAN
+#define __BYTE_ORDER	__LITTLE_ENDIAN
+#elif HAVE_BIG_ENDIAN
+#define __BYTE_ORDER	__BIG_ENDIAN
 #endif
+

 #ifdef __CHECKER__
 /* sparse needs forcing to remove bitwise attribute from ccan/short_types */


app/testpmd: fix vdev socket initialization

The cmdline settings of port-numa-config and rxring-numa-config have
been flushed by the following init_config. If we don't configure the
port-numa-config, the virtual device will allocate the device ports to
socket 0. It will cause failure when the socket 0 is unavailable.

eg:
testpmd -l <cores from socket 1> --vdev net_pcap0,iface=lo
--socket-mem=64 -- --numa --port-numa-config="(0,1)"
--ring-numa-config="(0,1,1),(0,2,1)" -i

...
Configuring Port 0 (socket 0)
Failed to setup RX queue:No mempool allocation on the socket 0
EAL: Error - exiting with code: 1
  Cause: Start ports failed

Fix by allocate the devices port to the first available socket or the
socket configured in port-numa-config.

Fixes: 487f9a592a27 ("app/testpmd: fix NUMA structures initialization")
Fixes: 20a0286fd2c0 ("app/testpmd: check socket id validity")
Cc: stable@dpdk.org

Signed-off-by: Phil Yang <5a9b6465c065ff0e1fd5d2cb9eb2185e82f34247@arm.com>
Reviewed-by: Gavin Hu <207ee22c2cf71e20c5b5df8395050c07c07d8709@arm.com>
Reviewed-by: Ferruh Yigit <ba8734c3c506d2e3557bd4ac8fdaccd25bdb9aa7@intel.com>

--- app/test-pmd/testpmd.c
+++ app/test-pmd/testpmd.c
@@ -1021,12 +1021,6 @@

 	memset(port_per_socket,0,RTE_MAX_NUMA_NODES);

-	if (numa_support) {
-		memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
-		memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
-		memset(txring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
-	}
-
 	/* Configuration of logical cores. */
 	fwd_lcores = rte_zmalloc("testpmd: fwd_lcores",
 				sizeof(struct fwd_lcore *) * nb_lcores,
@@ -1063,9 +1057,12 @@
 			else {
 				uint32_t socket_id = rte_eth_dev_socket_id(pid);

-				/* if socket_id is invalid, set to 0 */
+				/*
+				 * if socket_id is invalid,
+				 * set to the first available socket.
+				 */
 				if (check_socket_id(socket_id) < 0)
-					socket_id = 0;
+					socket_id = socket_ids[0];
 				port_per_socket[socket_id]++;
 			}
 		}
@@ -1221,9 +1218,12 @@
 			else {
 				port->socket_id = rte_eth_dev_socket_id(pid);

-				/* if socket_id is invalid, set to 0 */
+				/*
+				 * if socket_id is invalid,
+				 * set to the first available socket.
+				 */
 				if (check_socket_id(port->socket_id) < 0)
-					port->socket_id = 0;
+					port->socket_id = socket_ids[0];
 			}
 		}
 		else {
@@ -2294,9 +2294,9 @@
 		return;

 	socket_id = (unsigned)rte_eth_dev_socket_id(pi);
-	/* if socket_id is invalid, set to 0 */
+	/* if socket_id is invalid, set to the first available socket. */
 	if (check_socket_id(socket_id) < 0)
-		socket_id = 0;
+		socket_id = socket_ids[0];
 	reconfig(pi, socket_id);
 	rte_eth_promiscuous_enable(pi);

@@ -2954,6 +2954,11 @@
 				"rte_zmalloc(%d struct rte_port) failed\n",
 				RTE_MAX_ETHPORTS);
 	}
+
+	/* Initialize ports NUMA structures */
+	memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
+	memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
+	memset(txring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
 }

 static void


test/dma: add more comprehensive copy tests

Add unit tests for various combinations of use for dmadev, copying
bursts of packets in various formats, e.g.

1. enqueuing two smaller bursts and completing them as one burst
2. enqueuing one burst and gathering completions in smaller bursts
3. using completed_status() function to gather completions rather than
   just completed()

Signed-off-by: Bruce Richardson <66b9e8e8fbd5e9f41f91b0af050876182ce9d0e4@intel.com>
Reviewed-by: Kevin Laatz <961b59698dfa2327ef66e48c81ae3315f5733fd1@intel.com>
Reviewed-by: Conor Walsh <e53367a822c9a2a32150eba4386d4e8c8c837c8e@intel.com>

--- app/test/test_dmadev.c
+++ app/test/test_dmadev.c
@@ -82,6 +82,98 @@
 	}
 }

+/* run a series of copy tests just using some different options for enqueues and completions */
+static int
+do_multi_copies(int16_t dev_id, uint16_t vchan,
+		int split_batches,     /* submit 2 x 16 or 1 x 32 burst */
+		int split_completions, /* gather 2 x 16 or 1 x 32 completions */
+		int use_completed_status) /* use completed or completed_status function */
+{
+	struct rte_mbuf *srcs[32], *dsts[32];
+	enum rte_dma_status_code sc[32];
+	unsigned int i, j;
+	bool dma_err = false;
+
+	/* Enqueue burst of copies and hit doorbell */
+	for (i = 0; i < RTE_DIM(srcs); i++) {
+		uint64_t *src_data;
+
+		if (split_batches && i == RTE_DIM(srcs) / 2)
+			rte_dma_submit(dev_id, vchan);
+
+		srcs[i] = rte_pktmbuf_alloc(pool);
+		dsts[i] = rte_pktmbuf_alloc(pool);
+		if (srcs[i] == NULL || dsts[i] == NULL)
+			ERR_RETURN("Error allocating buffers\n");
+
+		src_data = rte_pktmbuf_mtod(srcs[i], uint64_t *);
+		for (j = 0; j < COPY_LEN/sizeof(uint64_t); j++)
+			src_data[j] = rte_rand();
+
+		if (rte_dma_copy(dev_id, vchan, srcs[i]->buf_iova + srcs[i]->data_off,
+				dsts[i]->buf_iova + dsts[i]->data_off, COPY_LEN, 0) != id_count++)
+			ERR_RETURN("Error with rte_dma_copy for buffer %u\n", i);
+	}
+	rte_dma_submit(dev_id, vchan);
+
+	await_hw(dev_id, vchan);
+
+	if (split_completions) {
+		/* gather completions in two halves */
+		uint16_t half_len = RTE_DIM(srcs) / 2;
+		int ret = rte_dma_completed(dev_id, vchan, half_len, NULL, &dma_err);
+		if (ret != half_len || dma_err)
+			ERR_RETURN("Error with rte_dma_completed - first half. ret = %d, expected ret = %u, dma_err = %d\n",
+					ret, half_len, dma_err);
+
+		ret = rte_dma_completed(dev_id, vchan, half_len, NULL, &dma_err);
+		if (ret != half_len || dma_err)
+			ERR_RETURN("Error with rte_dma_completed - second half. ret = %d, expected ret = %u, dma_err = %d\n",
+					ret, half_len, dma_err);
+	} else {
+		/* gather all completions in one go, using either
+		 * completed or completed_status fns
+		 */
+		if (!use_completed_status) {
+			int n = rte_dma_completed(dev_id, vchan, RTE_DIM(srcs), NULL, &dma_err);
+			if (n != RTE_DIM(srcs) || dma_err)
+				ERR_RETURN("Error with rte_dma_completed, %u [expected: %zu], dma_err = %d\n",
+						n, RTE_DIM(srcs), dma_err);
+		} else {
+			int n = rte_dma_completed_status(dev_id, vchan, RTE_DIM(srcs), NULL, sc);
+			if (n != RTE_DIM(srcs))
+				ERR_RETURN("Error with rte_dma_completed_status, %u [expected: %zu]\n",
+						n, RTE_DIM(srcs));
+
+			for (j = 0; j < (uint16_t)n; j++)
+				if (sc[j] != RTE_DMA_STATUS_SUCCESSFUL)
+					ERR_RETURN("Error with rte_dma_completed_status, job %u reports failure [code %u]\n",
+							j, sc[j]);
+		}
+	}
+
+	/* check for empty */
+	int ret = use_completed_status ?
+			rte_dma_completed_status(dev_id, vchan, RTE_DIM(srcs), NULL, sc) :
+			rte_dma_completed(dev_id, vchan, RTE_DIM(srcs), NULL, &dma_err);
+	if (ret != 0)
+		ERR_RETURN("Error with completion check - ops unexpectedly returned\n");
+
+	for (i = 0; i < RTE_DIM(srcs); i++) {
+		char *src_data, *dst_data;
+
+		src_data = rte_pktmbuf_mtod(srcs[i], char *);
+		dst_data = rte_pktmbuf_mtod(dsts[i], char *);
+		for (j = 0; j < COPY_LEN; j++)
+			if (src_data[j] != dst_data[j])
+				ERR_RETURN("Error with copy of packet %u, byte %u\n", i, j);
+
+		rte_pktmbuf_free(srcs[i]);
+		rte_pktmbuf_free(dsts[i]);
+	}
+	return 0;
+}
+
 static int
 test_enqueue_copies(int16_t dev_id, uint16_t vchan)
 {
@@ -176,7 +268,14 @@
 		rte_pktmbuf_free(dst);
 	} while (0);

-	return 0;
+	/* test doing multiple copies */
+	return do_multi_copies(dev_id, vchan, 0, 0, 0) /* enqueue and complete 1 batch at a time */
+			/* enqueue 2 batches and then complete both */
+			|| do_multi_copies(dev_id, vchan, 1, 0, 0)
+			/* enqueue 1 batch, then complete in two halves */
+			|| do_multi_copies(dev_id, vchan, 0, 1, 0)
+			/* test using completed_status in place of regular completed API */
+			|| do_multi_copies(dev_id, vchan, 0, 0, 1);
 }

 static int


test/ipfrag: check fragment offsets

test/ipfrag: check fragment offsets

Add the test content of the fragment_offset(offset and MF)
to the test_ip_frag function. Add test data for a fragment
that is not the last fragment.

Signed-off-by: Huichao Cai <dd4248da1d20ebe372551fc9630a248c9f2a0bf1@163.com>
Acked-by: Konstantin Ananyev <cbd5212b59ab42a210d72992d23a3aa17cfd3eaf@intel.com>

--- app/test/test_ipfrag.c
+++ app/test/test_ipfrag.c
@@ -89,12 +89,14 @@
 }

 static void
-v4_allocate_packet_of(struct rte_mbuf *b, int fill, size_t s, int df,
+v4_allocate_packet_of(struct rte_mbuf *b, int fill,
+		      size_t s, int df, uint8_t mf, uint16_t off,
 		      uint8_t ttl, uint8_t proto, uint16_t pktid)
 {
 	/* Create a packet, 2k bytes long */
 	b->data_off = 0;
 	char *data = rte_pktmbuf_mtod(b, char *);
+	rte_be16_t fragment_offset = 0;	/**< fragmentation offset */

 	memset(data, fill, sizeof(struct rte_ipv4_hdr) + s);

@@ -106,9 +108,17 @@
 	b->data_len = b->pkt_len;
 	hdr->total_length = rte_cpu_to_be_16(b->pkt_len);
 	hdr->packet_id = rte_cpu_to_be_16(pktid);
-	hdr->fragment_offset = 0;
+
 	if (df)
-		hdr->fragment_offset = rte_cpu_to_be_16(0x4000);
+		fragment_offset |= 0x4000;
+
+	if (mf)
+		fragment_offset |= 0x2000;
+
+	if (off)
+		fragment_offset |= off;
+
+	hdr->fragment_offset = rte_cpu_to_be_16(fragment_offset);

 	if (!ttl)
 		ttl = 64; /* default to 64 */
@@ -155,38 +165,73 @@
 		rte_pktmbuf_free(mb[i]);
 }

+static inline void
+test_get_offset(struct rte_mbuf **mb, int32_t len,
+	uint16_t *offset, int ipv)
+{
+	int32_t i;
+
+	for (i = 0; i < len; i++) {
+		if (ipv == 4) {
+			struct rte_ipv4_hdr *iph =
+			    rte_pktmbuf_mtod(mb[i], struct rte_ipv4_hdr *);
+			offset[i] = iph->fragment_offset;
+		} else if (ipv == 6) {
+			struct ipv6_extension_fragment *fh =
+			    rte_pktmbuf_mtod_offset(
+					mb[i],
+					struct ipv6_extension_fragment *,
+					sizeof(struct rte_ipv6_hdr));
+			offset[i] = fh->frag_data;
+		}
+	}
+}
+
 static int
 test_ip_frag(void)
 {
 	static const uint16_t RND_ID = UINT16_MAX;
 	int result = TEST_SUCCESS;
-	size_t i;
+	size_t i, j;

 	struct test_ip_frags {
 		int      ipv;
 		size_t   mtu_size;
 		size_t   pkt_size;
 		int      set_df;
+		uint8_t  set_mf;
+		uint16_t set_of;
 		uint8_t  ttl;
 		uint8_t  proto;
 		uint16_t pkt_id;
 		int      expected_frags;
+		uint16_t expected_fragment_offset[BURST];
 	} tests[] = {
-		     {4, 1280, 1400, 0, 64, IPPROTO_ICMP, RND_ID, 2},
-		     {4, 1280, 1400, 0, 64, IPPROTO_ICMP, 0,      2},
-		     {4,  600, 1400, 0, 64, IPPROTO_ICMP, RND_ID, 3},
-		     {4,    4, 1400, 0, 64, IPPROTO_ICMP, RND_ID, -EINVAL},
-		     {4,  600, 1400, 1, 64, IPPROTO_ICMP, RND_ID, -ENOTSUP},
-		     {4,  600, 1400, 0,  0, IPPROTO_ICMP, RND_ID, 3},
-
-		     {6, 1280, 1400, 0, 64, IPPROTO_ICMP, RND_ID, 2},
-		     {6, 1300, 1400, 0, 64, IPPROTO_ICMP, RND_ID, 2},
-		     {6,    4, 1400, 0, 64, IPPROTO_ICMP, RND_ID, -EINVAL},
-		     {6, 1300, 1400, 0,  0, IPPROTO_ICMP, RND_ID, 2},
+		 {4, 1280, 1400, 0, 0, 0, 64, IPPROTO_ICMP, RND_ID,       2,
+		  {0x2000, 0x009D}},
+		 {4, 1280, 1400, 0, 0, 0, 64, IPPROTO_ICMP, 0,            2,
+		  {0x2000, 0x009D}},
+		 {4,  600, 1400, 0, 0, 0, 64, IPPROTO_ICMP, RND_ID,       3,
+		  {0x2000, 0x2048, 0x0090}},
+		 {4, 4, 1400, 0, 0, 0, 64, IPPROTO_ICMP, RND_ID,    -EINVAL},
+		 {4, 600, 1400, 1, 0, 0, 64, IPPROTO_ICMP, RND_ID, -ENOTSUP},
+		 {4, 600, 1400, 0, 0, 0, 0, IPPROTO_ICMP, RND_ID,         3,
+		  {0x2000, 0x2048, 0x0090}},
+		 {4, 68, 104, 0, 1, 13, 0, IPPROTO_ICMP, RND_ID,          3,
+		  {0x200D, 0x2013, 0x2019}},
+
+		 {6, 1280, 1400, 0, 0, 0, 64, IPPROTO_ICMP, RND_ID,       2,
+		  {0x0001, 0x04D0}},
+		 {6, 1300, 1400, 0, 0, 0, 64, IPPROTO_ICMP, RND_ID,       2,
+		  {0x0001, 0x04E0}},
+		 {6, 4, 1400, 0, 0, 0, 64, IPPROTO_ICMP, RND_ID,    -EINVAL},
+		 {6, 1300, 1400, 0, 0, 0, 0, IPPROTO_ICMP, RND_ID,        2,
+		  {0x0001, 0x04E0}},
 	};

 	for (i = 0; i < RTE_DIM(tests); i++) {
 		int32_t len = 0;
+		uint16_t fragment_offset[BURST];
 		uint16_t pktid = tests[i].pkt_id;
 		struct rte_mbuf *pkts_out[BURST];
 		struct rte_mbuf *b = rte_pktmbuf_alloc(pkt_pool);
@@ -201,6 +246,8 @@
 			v4_allocate_packet_of(b, 0x41414141,
 					      tests[i].pkt_size,
 					      tests[i].set_df,
+					      tests[i].set_mf,
+					      tests[i].set_of,
 					      tests[i].ttl,
 					      tests[i].proto,
 					      pktid);
@@ -225,13 +272,29 @@

 		rte_pktmbuf_free(b);

-		if (len > 0)
+		if (len > 0) {
+			test_get_offset(pkts_out, len,
+			    fragment_offset, tests[i].ipv);
 			test_free_fragments(pkts_out, len);
+		}

 		printf("%zd: checking %d with %d\n", i, len,
 		       tests[i].expected_frags);
 		RTE_TEST_ASSERT_EQUAL(len, tests[i].expected_frags,
 				      "Failed case %zd.\n", i);
+
+		if (len > 0) {
+			for (j = 0; j < (size_t)len; j++) {
+				printf("%zd-%zd: checking %d with %d\n",
+				    i, j, fragment_offset[j],
+				    rte_cpu_to_be_16(
+					tests[i].expected_fragment_offset[j]));
+				RTE_TEST_ASSERT_EQUAL(fragment_offset[j],
+				    rte_cpu_to_be_16(
+					tests[i].expected_fragment_offset[j]),
+				    "Failed case %zd.\n", i);
+			}
+		}

 	}


Remove incorrect stub in ocamltest_stdlib_stubs.c

Miscopied from win32unix.

--- ocamltest/ocamltest_stdlib_stubs.c
+++ ocamltest/ocamltest_stdlib_stubs.c
@@ -140,9 +140,6 @@

 #else /* HAS_SYMLINK */

-CAMLprim value unix_symlink(value to_dir, value path1, value path2)
-{ caml_invalid_argument("symlink not implemented"); }
-
 CAMLprim value caml_has_symlink(value unit)
 {
   CAMLparam0();


Fix custom baud rate errors on OSX

Fix custom baud rate errors on OSX

--- src/uart_comm_unix.c
+++ src/uart_comm_unix.c
@@ -120,7 +120,8 @@
     record_last_error(errno);
 }

-static int to_baudrate_constant(int speed) {
+static int to_baudrate_constant(int speed)
+{
     switch (speed) {
     case 0: return B0;
     case 50: return B50;
@@ -160,6 +161,11 @@
     }
 }

+static int is_custom_speed(int speed)
+{
+    return to_baudrate_constant(speed) < 0;
+}
+
 static int to_databits_constant(int bits)
 {
     switch (bits) {
@@ -188,13 +194,10 @@
     return ioctl(fd, TIOCSSERIAL, &serinfo);
 #elif defined(__APPLE__)
     // Custom baud rates supported on Tiger and beyond
-    // TODO: How does this interact with tcsetattr? Does it override? Is the one that's set last win?
-    //       Do we need to call it after every tcsetattr or do we clear it when going back to
-    //       a Posix baud rate?
-
-      speed_t sio_speed = speed;
-      return ioctl(fd,  IOSSIOSPEED, &sio_speed);
-
+    // NOTE: Apple appears to be picky. Once setting this, calling
+    //       tcsetattr() even with unchanged arguments seems to fail.
+    speed_t sio_speed = speed;
+    return ioctl(fd,  IOSSIOSPEED, &sio_speed);
 #else
     return -1;
 #endif
@@ -252,13 +255,14 @@
     } else {
         // Use custom baudrate

-#ifdef __linux__
+#if defined(__linux__)
         // Linux lets you set custom baudrates for the B38400 option
         cfsetispeed(&options, B38400);
         cfsetospeed(&options, B38400);
 #endif
-        if (set_custom_speed(fd, config->speed) < 0)
-            return -1;
+
+        // Custom speed options that don't involve tcsetattr() are
+        // done later.
     }

     // Specify data bits
@@ -397,27 +401,29 @@

     if (port->fd < 0) {
         debug("open failed on '%s'", name);
-        record_errno();
-        return -1;
+        goto handle_error;
     }

     // Lock the serial port for exclusive use (we don't want others messing with it by accident)
     if (flock(port->fd, LOCK_EX | LOCK_NB) < 0) {
         debug("flock failed on '%s'", name);
-        record_errno();
-        return -1;
+        goto handle_error;
     }

     if (uart_config_line(port->fd, config) < 0) {
         debug("uart_config_line failed");
-        record_errno();
-        return -1;
+        goto handle_error;
     }

     if (uart_config_flowcontrol(port->fd, config) < 0) {
         debug("uart_config_flowcontrol failed");
-        record_errno();
-        return -1;
+        goto handle_error;
+    }
+
+    if (is_custom_speed(config->speed) &&
+            set_custom_speed(port->fd, config->speed) < 0) {
+        debug("set_custom_speed failed");
+        goto handle_error;
     }

     port->active_mode_enabled = config->active;
@@ -426,6 +432,14 @@
     tcflush(port->fd, TCIOFLUSH);

     return 0;
+
+handle_error:
+    record_errno();
+
+    if (port->fd >= 0)
+        close(port->fd);
+    port->fd = -1;
+    return -1;
 }

 int uart_is_open(struct uart *port)


Fixed HA conf aggr period consolidation.