Add CMAC functions to the benchmark sample application

--- programs/test/benchmark.c
+++ programs/test/benchmark.c
@@ -1,7 +1,7 @@
 /*
  *  Benchmark demonstration program
  *
- *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ *  Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
  *  SPDX-License-Identifier: Apache-2.0
  *
  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -61,6 +61,7 @@
 #include "mbedtls/camellia.h"
 #include "mbedtls/gcm.h"
 #include "mbedtls/ccm.h"
+#include "mbedtls/cmac.h"
 #include "mbedtls/havege.h"
 #include "mbedtls/ctr_drbg.h"
 #include "mbedtls/hmac_drbg.h"
@@ -92,7 +93,8 @@

 #define OPTIONS                                                         \
     "md4, md5, ripemd160, sha1, sha256, sha512,\n"                      \
-    "arc4, des3, des, aes_cbc, aes_gcm, aes_ccm, camellia, blowfish,\n" \
+    "arc4, des3, des, camellia, blowfish,\n"                             \
+    "aes_cbc, aes_gcm, aes_ccm, aes_cmac, des3_cmac,\n"                 \
     "havege, ctr_drbg, hmac_drbg\n"                                     \
     "rsa, dhm, ecdsa, ecdh.\n"

@@ -234,7 +236,9 @@

 typedef struct {
     char md4, md5, ripemd160, sha1, sha256, sha512,
-         arc4, des3, des, aes_cbc, aes_gcm, aes_ccm, camellia, blowfish,
+         arc4, des3, des,
+         aes_cbc, aes_gcm, aes_ccm, aes_cmac, des3_cmac,
+         camellia, blowfish,
          havege, ctr_drbg, hmac_drbg,
          rsa, dhm, ecdsa, ecdh;
 } todo_list;
@@ -283,6 +287,10 @@
                 todo.aes_gcm = 1;
             else if( strcmp( argv[i], "aes_ccm" ) == 0 )
                 todo.aes_ccm = 1;
+            else if( strcmp( argv[i], "aes_cmac" ) == 0 )
+                todo.aes_cmac = 1;
+            else if( strcmp( argv[i], "des3_cmac" ) == 0 )
+                todo.des3_cmac = 1;
             else if( strcmp( argv[i], "camellia" ) == 0 )
                 todo.camellia = 1;
             else if( strcmp( argv[i], "blowfish" ) == 0 )
@@ -358,7 +366,8 @@
     }
 #endif

-#if defined(MBEDTLS_DES_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
+#if defined(MBEDTLS_DES_C)
+#if defined(MBEDTLS_CIPHER_MODE_CBC)
     if( todo.des3 )
     {
         mbedtls_des3_context des3;
@@ -378,7 +387,25 @@
                 mbedtls_des_crypt_cbc( &des, MBEDTLS_DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) );
         mbedtls_des_free( &des );
     }
-#endif
+
+#endif /* MBEDTLS_CIPHER_MODE_CBC */
+#if defined(MBEDTLS_CMAC_C)
+    if( todo.des3_cmac )
+    {
+        unsigned char output[8];
+        const mbedtls_cipher_info_t *cipher_info;
+
+        memset( buf, 0, sizeof( buf ) );
+        memset( tmp, 0, sizeof( tmp ) );
+
+        cipher_info = mbedtls_cipher_info_from_type( MBEDTLS_CIPHER_DES_EDE3_ECB );
+
+        TIME_AND_TSC( "3DES-CMAC",
+                        mbedtls_cipher_cmac( cipher_info, tmp, 192, buf,
+                        BUFSIZE, output ) );
+    }
+#endif /* MBEDTLS_CMAC_C */
+#endif /* MBEDTLS_DES_C */

 #if defined(MBEDTLS_AES_C)
 #if defined(MBEDTLS_CIPHER_MODE_CBC)
@@ -447,7 +474,37 @@
         }
     }
 #endif
-#endif
+#if defined(MBEDTLS_CMAC_C)
+    if( todo.aes_cmac )
+    {
+        unsigned char output[16];
+        const mbedtls_cipher_info_t *cipher_info;
+        mbedtls_cipher_type_t cipher_type;
+        int keysize;
+
+        for( keysize = 128, cipher_type = MBEDTLS_CIPHER_AES_128_ECB;
+             keysize <= 256;
+             keysize += 64, cipher_type++ )
+        {
+            mbedtls_snprintf( title, sizeof( title ), "AES-CMAC-%d", keysize );
+
+            memset( buf, 0, sizeof( buf ) );
+            memset( tmp, 0, sizeof( tmp ) );
+
+            cipher_info = mbedtls_cipher_info_from_type( cipher_type );
+
+            TIME_AND_TSC( title,
+                             mbedtls_cipher_cmac( cipher_info, tmp, keysize,
+                                                  buf, BUFSIZE, output ) );
+        }
+
+        memset( buf, 0, sizeof( buf ) );
+        memset( tmp, 0, sizeof( tmp ) );
+        TIME_AND_TSC( "AES-CMAC-PRF-128",
+                    mbedtls_aes_cmac_prf_128( tmp, 16, buf, BUFSIZE, output ) );
+    }
+#endif /* MBEDTLS_CMAC_C */
+#endif /* MBEDTLS_AES_C */

 #if defined(MBEDTLS_CAMELLIA_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
     if( todo.camellia )


programs/test: fix build without MBEDTLS_HAVE_TIME

Allow programs/test/udp_proxy.c to build when MBEDTLS_HAVE_TIME is
not defined. In this case, do not attempt to seed the pseudo-random
number generator used to sometimes produce corrupt packets and other
erroneous data.

Signed-off-by: David Horstmann <0386b5e8f8e5ea8a58d40026a5369df20e1c750d@arm.com>

--- programs/test/udp_proxy.c
+++ programs/test/udp_proxy.c
@@ -32,9 +32,11 @@
 #else
 #include <stdio.h>
 #include <stdlib.h>
+#if defined(MBEDTLS_HAVE_TIME)
 #include <time.h>
 #define mbedtls_time            time
 #define mbedtls_time_t          time_t
+#endif
 #define mbedtls_printf          printf
 #define mbedtls_calloc          calloc
 #define mbedtls_free            free
@@ -821,6 +823,7 @@

     get_options( argc, argv );

+#if defined(MBEDTLS_HAVE_TIME)
     /*
      * Decisions to drop/delay/duplicate packets are pseudo-random: dropping
      * exactly 1 in N packets would lead to problems when a flight has exactly
@@ -831,11 +834,12 @@
      */
     if( opt.seed == 0 )
     {
-        opt.seed = (unsigned int) time( NULL );
+        opt.seed = (unsigned int) mbedtls_time( NULL );
         mbedtls_printf( "  . Pseudo-random seed: %u\n", opt.seed );
     }

     srand( opt.seed );
+#endif /* MBEDTLS_HAVE_TIME */

     /*
      * 0. "Connect" to the server


Add option 'delay_ccs' to udp_proxy

Add option 'delay_ccs' to udp_proxy

--- programs/test/udp_proxy.c
+++ programs/test/udp_proxy.c
@@ -85,6 +85,7 @@
     "                        duplicate 1 packet every N packets\n"          \
     "    delay=%%d            default: 0 (no delayed packets)\n"            \
     "                        delay 1 packet every N packets\n"              \
+    "    delay_ccs=%%d        default: 0 (don't delay ChangeCipherSuite)\n" \
     "    drop=%%d             default: 0 (no dropped packets)\n"            \
     "                        drop 1 packet every N packets\n"               \
     "\n"
@@ -101,6 +102,7 @@

     int duplicate;              /* duplicate 1 in N packets (none if 0)     */
     int delay;                  /* delay 1 packet in N (none if 0)          */
+    int delay_ccs;              /* delay ChangeCipherSpec                   */
     int drop;                   /* drop 1 packet in N (none if 0)           */
 } opt;

@@ -181,6 +183,12 @@
         {
             opt.delay = atoi( q );
             if( opt.delay < 0 || opt.delay > 10 || opt.delay == 1 )
+                exit_usage( p, q );
+        }
+        else if( strcmp( p, "delay_ccs" ) == 0 )
+        {
+            opt.delay_ccs = atoi( q );
+            if( opt.delay_ccs < 0 || opt.delay_ccs > 1 )
                 exit_usage( p, q );
         }
         else if( strcmp( p, "drop" ) == 0 )
@@ -301,9 +309,11 @@
     {
         drop_cnt = 0;
     }
-    else if( opt.delay != 0 &&
-        strcmp( cur.type, "ApplicationData" ) != 0 &&
-        ++delay_cnt == opt.delay )
+    else if( ( opt.delay_ccs == 1 &&
+               strcmp( cur.type, "ChangeCipherSpec" ) == 0 ) ||
+             ( opt.delay != 0 &&
+               strcmp( cur.type, "ApplicationData" ) != 0 &&
+               ++delay_cnt == opt.delay ) )
     {
         delay_cnt = 0;
         memcpy( &prev, &cur, sizeof( packet ) );


Version of rmtGetProcAddress that preserves return type

--- lib/Remotery.c
+++ lib/Remotery.c
@@ -205,23 +205,18 @@
     #endif
 }

+#if defined(RMT_PLATFORM_WINDOWS)
+static FARPROC rmtGetProcAddress(void* handle, const char* symbol)
+{
+    return GetProcAddress((HMODULE)handle, (LPCSTR)symbol);
+}
+#elif defined(RMT_PLATFORM_POSIX)
 static void* rmtGetProcAddress(void* handle, const char* symbol)
 {
-    #if defined(RMT_PLATFORM_WINDOWS)
-        #ifdef _MSC_VER
-            #pragma warning(push)
-            #pragma warning(disable:4152) // C4152: nonstandard extension, function/data pointer conversion in expression
-        #endif
-        return GetProcAddress((HMODULE)handle, (LPCSTR)symbol);
-        #ifdef _MSC_VER
-            #pragma warning(pop)
-        #endif
-    #elif defined(RMT_PLATFORM_POSIX)
-        return dlsym(handle, symbol);
-    #else
-        return NULL;
-    #endif
-}
+    return dlsym(handle, symbol);
+}
+#endif
+
 #endif

 /*


py/frozenmod.h: Add missing header guards

--- py/frozenmod.h
+++ py/frozenmod.h
@@ -23,6 +23,8 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#ifndef __MICROPY_INCLUDED_PY_FROZENMOD_H__
+#define __MICROPY_INCLUDED_PY_FROZENMOD_H__

 #include "py/lexer.h"

@@ -35,3 +37,5 @@
 int mp_find_frozen_module(const char *str, size_t len, void **data);
 const char *mp_find_frozen_str(const char *str, size_t *len);
 mp_import_stat_t mp_frozen_stat(const char *str);
+
+#endif // __MICROPY_INCLUDED_PY_FROZENMOD_H__


Fixed issue with sgnjn translation

Fixed issue with sgnjn translation

Susan is passing now!

--- sbt/Builder.h
+++ sbt/Builder.h
@@ -771,7 +771,7 @@
         b = bitOrPointerCast(b, ity);
         a = _and(a, nsgn);
         // negate b's signal bit
-        b = _xor(b, b);
+        b = _xor(b, llvm::ConstantInt::get(ity, ~0ULL));
         b = _and(b, sgn);
         llvm::Value* v = _or(a, b);
         // to fp


Fix errors in OpenGL code when compiling in C mode.

--- lib/Remotery.c
+++ lib/Remotery.c
@@ -5171,6 +5171,8 @@

 static enum rmtError OpenGLTimestamp_Constructor(OpenGLTimestamp* stamp)
 {
+    int error;
+
     assert(stamp != NULL);

     ObjectLink_Constructor((ObjectLink*)stamp);
@@ -5182,7 +5184,7 @@
     assert(g_Remotery != NULL);
     assert(g_Remotery->__glGenQueries != NULL);
     glGenQueries(2, stamp->queries);
-    int error = glGetError();
+    error = glGetError();
     if (error != GL_NO_ERROR)
         return RMT_ERROR_OPENGL_ERROR;

@@ -5197,9 +5199,10 @@
     // Destroy queries
     if (stamp->queries[0] != 0)
     {
+        int error;
         assert(g_Remotery->__glDeleteQueries != NULL);
         glDeleteQueries(2, stamp->queries);
-        int error = glGetError();
+        error = glGetError();
         assert(error == GL_NO_ERROR);
     }
 }
@@ -5207,26 +5210,30 @@

 static void OpenGLTimestamp_Begin(OpenGLTimestamp* stamp)
 {
+    int error;
+
     assert(stamp != NULL);

     // Start of disjoint and first query
     assert(g_Remotery != NULL);
     assert(g_Remotery->__glQueryCounter != NULL);
     glQueryCounter(stamp->queries[0], GL_TIMESTAMP);
-    int error = glGetError();
+    error = glGetError();
     assert(error == GL_NO_ERROR);
 }

 static void OpenGLTimestamp_End(OpenGLTimestamp* stamp)
 {
+    int error;
+
     assert(stamp != NULL);

     // End of disjoint and second query
     assert(g_Remotery != NULL);
     assert(g_Remotery->__glQueryCounter != NULL);
     glQueryCounter(stamp->queries[1], GL_TIMESTAMP);
-    int error = glGetError();
+    error = glGetError();
     assert(error == GL_NO_ERROR);
 }


Fix issues with quick inverse of degenerate matrix

This fixes part of the issues reported in T46322. Still need to solve
issue with wrong intersection distance scaling.


* [ios] add delegate for WXBaseViewController

--- ios/sdk/WeexSDK/Sources/Controller/WXBaseViewController.h
+++ ios/sdk/WeexSDK/Sources/Controller/WXBaseViewController.h
@@ -26,7 +26,7 @@
  * special bundle URL.
  */

-@interface WXBaseViewController : UIViewController
+@interface WXBaseViewController : UIViewController<UIGestureRecognizerDelegate>

 /**
  * @abstract initializes the viewcontroller with bundle url.


Generator now requires that instructions that do not read from their output register, write to a non-live register.

--- src/generator.c
+++ src/generator.c
@@ -3,7 +3,6 @@
 #include "invocation.h"
 #include "program.h"

-// TODO: mov should always write to a non-live register
 // TODO: mov/cmov should never use r0 == r1
 // TODO: sbb/sub/xor with r0 == r1 don't really read input; how to handle?
 // TODO: model known flag values, rather than just defined/undefined? ex: if cf is known to be 0, such as after and/or/xor, don't generate adc/sbb
@@ -93,16 +92,34 @@
             }
           break;
         case 2:
-          for(size_t r0 = 0; r0 < XO_NUM_REGISTERS; ++r0)
-            if(live_regs & register_index_to_set_(r0))
-            {
-              for(size_t r1 = 0; r1 < XO_NUM_REGISTERS; ++r1)
-                if(live_regs & register_index_to_set_(r1))
-                {
-                  xo_invocation_init(&prog->invocations[inv], insn, r0, r1);
-                  generate_(prog, inv+1, input_regs, output_regs, live_regs | register_index_to_set_(r0), new_live_flags, callback, userdata);
-                }
-            }
+
+          // if insn reads from its output reg, both regs must be live
+          // otherwise, r0 must be non-live and r1 must be live
+          // TODO: this grows the set of live regs, which is bad for performance... what to do?
+          if(insn->input_regs & insn->output_regs)
+          {
+            for(size_t r0 = 0; r0 < XO_NUM_REGISTERS; ++r0)
+              if(live_regs & register_index_to_set_(r0))
+              {
+                for(size_t r1 = 0; r1 < XO_NUM_REGISTERS; ++r1)
+                  if(live_regs & register_index_to_set_(r1))
+                  {
+                    xo_invocation_init(&prog->invocations[inv], insn, r0, r1);
+                    generate_(prog, inv+1, input_regs, output_regs, live_regs | register_index_to_set_(r0), new_live_flags, callback, userdata);
+                  }
+              }
+          }
+          else
+          {
+            size_t r0 = register_set_to_index_(~live_regs); // TODO: what if all regs are live?
+
+            for(size_t r1 = 0; r1 < XO_NUM_REGISTERS; ++r1)
+              if(live_regs & register_index_to_set_(r1))
+              {
+                xo_invocation_init(&prog->invocations[inv], insn, r0, r1);
+                generate_(prog, inv+1, input_regs, output_regs, live_regs | register_index_to_set_(r0), new_live_flags, callback, userdata);
+              }
+          }
           break;
       }
     }


virStorageFileParseBackingStoreStr: use g_strsplit instead of virStringSplitCount

The presence of the second element can be checked by looking at it
directly.

Signed-off-by: Peter Krempa <2cf5c04c61aa466e4a47bfedc747d17279c72ffc@redhat.com>
Reviewed-by: Ján Tomko <4cab11cfb98d3c937327354a78eb07dbb6ee2bc6@redhat.com>

--- src/util/virstoragefile.c
+++ src/util/virstoragefile.c
@@ -192,17 +192,16 @@
                                    char **target,
                                    unsigned int *chainIndex)
 {
-    size_t nstrings;
     unsigned int idx = 0;
     char *suffix;
     g_auto(GStrv) strings = NULL;

     *chainIndex = 0;

-    if (!(strings = virStringSplitCount(str, "[", 2, &nstrings)))
+    if (!(strings = g_strsplit(str, "[", 2)))
         return -1;

-    if (nstrings == 2) {
+    if (strings[0] && strings[1]) {
         if (virStrToLong_uip(strings[1], &suffix, 10, &idx) < 0 ||
             STRNEQ(suffix, "]"))
             return -1;


(split) Changes to generator INDENT type.

--- src/generator.h
+++ src/generator.h
@@ -125,8 +125,16 @@
 class Indentor {
     public:
         Indentor():
-                indent(0) {}
+                indent(0),
+                m_string("    ")
+        {
+        }
         int indent;
+        const QString &string() const {
+            return m_string;
+        }
+    private:
+        QString m_string;
 };

 class Indentation {
@@ -138,6 +146,9 @@
         ~Indentation() {
             indentor.indent--;
         }
+        const QString &string() const {
+            return indentor.string();
+        }

     private:
         Indentor &indentor;
@@ -145,7 +156,7 @@

 inline QTextStream &operator <<(QTextStream &s, const Indentor &indentor) {
     for (int i = 0; i < indentor.indent; ++i)
-        s << "    ";
+        s << indentor.string();
     return s;
 }


ARMv7-M-coreVectors.c: use lower case letters for hex numbers

--- source/architecture/ARM/ARMv7-M/ARMv7-M-coreVectors.c
+++ source/architecture/ARM/ARMv7-M/ARMv7-M-coreVectors.c
@@ -8,7 +8,7 @@
  * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
  * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  *
- * \date 2015-06-22
+ * \date 2015-12-09
  */

 /*---------------------------------------------------------------------------------------------------------------------+
@@ -45,8 +45,8 @@
 	while (1);
 }

-// Reserved 0x1C
-__attribute__ ((weak)) void __Reserved_0x1C_Handler(void)
+// Reserved 0x1c
+__attribute__ ((weak)) void __Reserved_0x1c_Handler(void)
 {
 	while (1);
 }
@@ -128,7 +128,7 @@
 		MemManage_Handler,						// Memory management
 		BusFault_Handler,						// Pre-fetch fault, memory access fault
 		UsageFault_Handler,						// Undefined instruction or illegal state
-		__Reserved_0x1C_Handler,				// Reserved 0x1C
+		__Reserved_0x1c_Handler,				// Reserved 0x1c
 		__Reserved_0x20_Handler,				// Reserved 0x20
 		__Reserved_0x24_Handler,				// Reserved 0x24
 		__Reserved_0x28_Handler,				// Reserved 0x28


Add comparion operators for itk::SmartPointer<T>

--- Modules/Core/include/mitkWeakPointer.h
+++ Modules/Core/include/mitkWeakPointer.h
@@ -343,4 +343,58 @@
   return !(left < right);
 }

+template <class T>
+bool operator !=(const mitk::WeakPointer<T> &left, itk::SmartPointer<T> right) noexcept
+{
+  return !(left == right);
+}
+
+template <class T>
+bool operator <=(const mitk::WeakPointer<T> &left, itk::SmartPointer<T> right) noexcept
+{
+  return !(right < left);
+}
+
+template <class T>
+bool operator >(const mitk::WeakPointer<T> &left, itk::SmartPointer<T> right) noexcept
+{
+  return right < left;
+}
+
+template <class T>
+bool operator >=(const mitk::WeakPointer<T> &left, itk::SmartPointer<T> right) noexcept
+{
+  return !(left < right);
+}
+
+template <class T>
+bool operator ==(itk::SmartPointer<T> left, const mitk::WeakPointer<T> &right) noexcept
+{
+  return right == left;
+}
+
+template <class T>
+bool operator !=(itk::SmartPointer<T> left, const mitk::WeakPointer<T> &right) noexcept
+{
+  return !(right == left);
+}
+
+template <class T>
+bool operator <=(itk::SmartPointer<T> left, const mitk::WeakPointer<T> &right) noexcept
+{
+  return !(right < left);
+}
+
+template <class T>
+bool operator >(itk::SmartPointer<T> left, const mitk::WeakPointer<T> &right) noexcept
+{
+  return right < left;
+}
+
+template <class T>
+bool operator >=(itk::SmartPointer<T> left, const mitk::WeakPointer<T> &right) noexcept
+{
+  return !(left < right);
+}
+
 #endif


Made initialize parameters optional

Made initialize parameters optional

--- Modules/Qmitk/QmitkServiceListWidget.h
+++ Modules/Qmitk/QmitkServiceListWidget.h
@@ -113,7 +113,7 @@
     * \endverbatim
     */
     template <class T>
-    void Initialize(const std::string& namingProperty, std::string& filter)
+    void Initialize(const std::string& namingProperty = "", std::string& filter = "")
       {
         std::string interfaceName ( us_service_interface_iid<T*>() );
         m_Interface = interfaceName;


Fixes for Darwin compilation

Fixes for Darwin compilation

--- examples/warpping.c
+++ examples/warpping.c
@@ -1,3 +1,4 @@
+#include <fcntl.h>
 #include <getopt.h>
 #include <netdb.h>
 #include <netinet/in.h>
@@ -11,8 +12,8 @@
 #include "util.h"
 #include "warpcore.h"

-#ifdef __linux__
-#define CLOCK_REALTIME_PRECISE CLOCK_REALTIME
+#ifdef __FreeBSD__
+#define CLOCK_REALTIME CLOCK_REALTIME_PRECISE
 #endif

@@ -130,11 +131,10 @@
             ((struct sockaddr_in *)(void *)peer->ai_addr)->sin_port);
     } else {
         w_init_common();
-        ks = socket(peer->ai_family,
-                    peer->ai_socktype | (busywait ? SOCK_NONBLOCK : 0),
-                    peer->ai_protocol);
-        if (ks == -1)
-            die("socket");
+        assert(
+            ks = socket(peer->ai_family, peer->ai_socktype, peer->ai_protocol),
+            "socket");
+        assert(fcntl(ks, F_SETFL | O_NONBLOCK) != -1, "fcntl");
         before = calloc(1, size);
         after = calloc(1, size);
     }
@@ -146,8 +146,7 @@
             before = o->buf;
         }

-        assert(clock_gettime(CLOCK_REALTIME_PRECISE, before) != -1,
-               "clock_gettime");
+        assert(clock_gettime(CLOCK_REALTIME, before) != -1, "clock_gettime");

         // send
         if (use_warpcore)
@@ -172,8 +171,7 @@
                 socklen_t fromlen = peer->ai_addrlen;
                 s = recvfrom(ks, after, size, 0, peer->ai_addr, &fromlen);
             }
-            assert(clock_gettime(CLOCK_REALTIME_PRECISE, &now) != -1,
-                   "clock_gettime");
+            assert(clock_gettime(CLOCK_REALTIME, &now) != -1, "clock_gettime");
             time_diff(&diff, &now, before);
         } while (i == 0 && (s == 0 || (s == -1 && errno == EAGAIN)) &&
                  diff.tv_sec == 0);
@@ -185,8 +183,7 @@
             continue;
         }

-        assert(clock_gettime(CLOCK_REALTIME_PRECISE, &now) != -1,
-               "clock_gettime");
+        assert(clock_gettime(CLOCK_REALTIME, &now) != -1, "clock_gettime");
         time_diff(&diff, &now, after);
         if (unlikely(diff.tv_sec != 0))
             die("time difference is more than %ld sec", diff.tv_sec);


Update vheap size when moving msgq to heap after GC

--- erts/emulator/beam/erl_gc.c
+++ erts/emulator/beam/erl_gc.c
@@ -150,6 +150,7 @@
 static int reached_max_heap_size(Process *p, Uint total_heap_size,
                                  Uint extra_heap_size, Uint extra_old_heap_size);
 static void init_gc_info(ErtsGCInfo *gcip);
+static Uint64 next_vheap_size(Process* p, Uint64 vheap, Uint64 vheap_sz);

 #ifdef HARDDEBUG
 static void disallow_heap_frag_ref_in_heap(Process* p);
@@ -747,6 +748,9 @@
      */
     p->last_old_htop = p->old_htop;
 #endif
+
+    ASSERT(!p->mbuf);
+    ASSERT(!ERTS_IS_GC_DESIRED(p));

     return reds;
 }
@@ -2250,7 +2254,9 @@
 static void
 move_msgq_to_heap(Process *p)
 {
+
     ErtsMessage **mpp = &p->msg.first;
+    Uint64 pre_oh = MSO(p).overhead;

     while (*mpp) {
 	ErtsMessage *mp = *mpp;
@@ -2292,6 +2298,11 @@
 	}

 	mpp = &(*mpp)->next;
+    }
+
+    if (pre_oh != MSO(p).overhead) {
+	/* Got new binaries; update vheap size... */
+	BIN_VHEAP_SZ(p) = next_vheap_size(p, MSO(p).overhead, BIN_VHEAP_SZ(p));
     }
 }


Refactored Orbiter with sin(), and then Cylon as one Orbiter.

--- PlusPrograms.h
+++ PlusPrograms.h
@@ -114,8 +114,9 @@

   static bool pulser(uint16_t sequence, color_t& color, uint8_t& intensity) {
     const int PHASE = 32;
+    const int PULSE_RATE = 2;  // Above 1 is glitchy but IMO more attractive.
     color = G35::max_color((sequence + PHASE) / (PHASE * 2));
-    intensity = abs(PHASE - (int)(sequence) % (PHASE + PHASE));
+    intensity = abs(PHASE - (int)(sequence * PULSE_RATE) % (PHASE + PHASE));
     return true;
   }

@@ -124,92 +125,41 @@
   uint16_t sequence_;
 };

-class Cylon : public LightProgram {
- public:
- Cylon(G35& g35)
-   : LightProgram(g35),
-    last_light_shifted_((light_count_ << 8) - 1), x_(0), d2x_(-2),
-    color_(G35::max_color(rand())) {}
-
-  uint32_t Do() {
-    uint8_t old_x_pix = x_ >> 8;
-    dx_ += d2x_;
-    x_ += dx_;
-
-    bool moving_right = d2x_ > 0;
-    bool past_right = old_x_pix >= g35_.get_halfway_point();
-    if (moving_right == past_right) {
-      d2x_ = -d2x_;
-    }
-
-    if (x_ <= 0) {
-      x_ = 0;
-      dx_ = 0;
-    }
-    if (x_ > last_light_shifted_) {
-      x_ = last_light_shifted_;
-      dx_ = 0;
-    }
-
-    uint8_t x_pix = x_ >> 8;
-    if (old_x_pix != x_pix) {
-      g35_.set_color(old_x_pix, G35::MAX_INTENSITY, COLOR_BLACK);
-    }
-    g35_.set_color(x_pix, G35::MAX_INTENSITY, color_);
-
-    return bulb_frame_ >> 1;
-  }
-
- private:
-  int16_t last_light_shifted_;
-  int16_t x_;
-  int16_t dx_;
-  int16_t d2x_;
-  color_t color_;
-};
-
+// An Orbiter doesn't know about string length. Its coordinate system is
+// [0.0, 1.0], and it's the caller's job to scale that to real-world
+// values.
 class Orbiter {
  public:
  Orbiter()
-   : center_(rand()),
-    x_(rand()),
-    old_x_(0),
-    dx_(0),
-    d2x_(rand() % 10 - 5),
+   : radius_((float)rand() / (float)RAND_MAX),
+    angle_(2 * PI * (float)rand() / (float)RAND_MAX),
+    d_angle_(-0.01 + 0.02 * (float)rand() / (float)RAND_MAX),
+    x_(0),
     color_(G35::max_color(rand())) {
-    old_x_ = x_;
-    if (d2x_ == 0) {
-      d2x_ = 1;
-    }
+  }
+
+ Orbiter(float radius, float d_angle)
+   : radius_(radius),
+    angle_(0),
+    d_angle_(d_angle),
+    x_(0),
+    color_(G35::max_color(rand())) {
   }

   void Do() {
-    old_x_ = x_;
-    dx_ += d2x_;
-    x_ += dx_;
-
-    bool moving_right = d2x_ > 0;
-    bool past_center = x_ >= center_;
-    if (moving_right == past_center) {
-      d2x_ = -d2x_;
-    }
-
-    if (x_ <= 0) {
-      x_ = 0;
-      dx_ = 0;
-    }
-  }
-
-  int16_t x() { return x_; }
-  int16_t old_x() { return old_x_; }
+    x_ = sin(angle_) * radius_;
+    angle_ += d_angle_;
+  }
+
+  float x() { return x_; }
+  uint8_t x_local(uint8_t range, uint8_t center) {
+    return ((uint8_t)(x_ * range + center)) % range;
+  }
   color_t color() { return color_; }

  private:
-  int16_t center_;
-  int16_t x_;
-  int16_t old_x_;
-  int16_t dx_;
-  int16_t d2x_;
+  float radius_, angle_, d_angle_;
+  float x_;
   color_t color_;
 };

@@ -219,22 +169,25 @@
    : LightProgram(g35),
     should_erase_(should_erase),
     count_(MAX_OBJECTS),
-    last_light_shifted_((light_count_ << 8) - 1),
-    light_count_(g35_.get_light_count()) {}
+    light_count_(g35_.get_light_count()) {
+    for (int i = 0; i < count_; ++i) {
+      orbiter_center_[i] = rand() % light_count_;
+    }
+  }

   uint32_t Do() {
     for (int i = 0; i < count_; ++i) {
       Orbiter *o = &orbiter_[i];
-      int16_t old_x = (o->old_x() >> 8) % light_count_;
       o->Do();
-      int16_t x = (o->x() >> 8) % light_count_;
-
-      if (should_erase_ && old_x != x) {
-        g35_.set_color(old_x, G35::MAX_INTENSITY, COLOR_BLACK);
+      uint8_t x = o->x_local(light_count_, orbiter_center_[i]);
+
+      if (should_erase_ && last_x_[i] != x) {
+        g35_.set_color(last_x_[i], G35::MAX_INTENSITY, COLOR_BLACK);
+	last_x_[i] = x;
       }
       g35_.set_color(x, G35::MAX_INTENSITY, o->color());
     }
-    return bulb_frame_;
+    return bulb_frame_ >> 1;
   }

  private:
@@ -244,6 +197,31 @@
   int16_t last_light_shifted_;
   int8_t light_count_;
   Orbiter orbiter_[MAX_OBJECTS];
-};
+  uint8_t orbiter_center_[MAX_OBJECTS];
+  uint8_t last_x_[MAX_OBJECTS];
+};
+
+class Cylon : public LightProgram {
+ public:
+ Cylon(G35& g35) : LightProgram(g35), orbiter_(0.5, 0.01), last_x_(0) {}
+
+  uint32_t Do() {
+    orbiter_.Do();
+    uint8_t x = orbiter_.x_local(light_count_, light_count_ >> 1);
+
+    if (last_x_ != x) {
+      g35_.set_color(last_x_, G35::MAX_INTENSITY, COLOR_BLACK);
+      last_x_ = x;
+    }
+    g35_.set_color(x, G35::MAX_INTENSITY, orbiter_.color());
+
+    return bulb_frame_ >> 1;
+  }
+
+ private:
+  Orbiter orbiter_;
+  uint8_t last_x_;
+};
+

 #endif  // INCLUDE_G35_PLUS_PROGRAMS_H


fix 64-bit issues in the garbage collection

We discovered that if a single Erlang process tried to grow above 32
GB (i.e., more 64-bit words than can be counted by a 32-bit number),
the VM failed to find the next larger heap size, even though there
were plenty more heap sizes left to pick from and even though we had a
lot more memory available on the machine. (Obviously, this is only
applicable on 64-bit Erlang.)

It turned out to be due to some 'int' variables in the heap resizing
parts of erl_gc.c not being properly updated to 'Uint' or 'Sint'. Once
that was fixed, I got segfaults instead as soon as the heap got larger
than 2^32 words, due to even more 'int' declarations in the same file,
but now in the GC code.

After fixing this as well, I successfully ran an Erlang node in which
a single Erlang process had a heap so large that I'm not at liberty to
divulge the exact size, but I think the scientific term is
"humongous", and I'm confident that there are no further immediate
problems with very very large individual process heaps.

--- erts/emulator/beam/erl_gc.c
+++ erts/emulator/beam/erl_gc.c
@@ -100,14 +100,14 @@
 static void remove_message_buffers(Process* p);
 static int major_collection(Process* p, int need, Eterm* objv, int nobj, Uint *recl);
 static int minor_collection(Process* p, int need, Eterm* objv, int nobj, Uint *recl);
-static void do_minor(Process *p, int new_sz, Eterm* objv, int nobj);
+static void do_minor(Process *p, Uint new_sz, Eterm* objv, int nobj);
 static Eterm* sweep_rootset(Rootset *rootset, Eterm* htop, char* src, Uint src_size);
 static Eterm* sweep_one_area(Eterm* n_hp, Eterm* n_htop, char* src, Uint src_size);
 static Eterm* sweep_one_heap(Eterm* heap_ptr, Eterm* heap_end, Eterm* htop,
 			     char* src, Uint src_size);
 static Eterm* collect_heap_frags(Process* p, Eterm* heap,
 				 Eterm* htop, Eterm* objv, int nobj);
-static Uint adjust_after_fullsweep(Process *p, int size_before,
+static Uint adjust_after_fullsweep(Process *p, Uint size_before,
 				   int need, Eterm *objv, int nobj);
 static void shrink_new_heap(Process *p, Uint new_sz, Eterm *objv, int nobj);
 static void grow_new_heap(Process *p, Uint new_sz, Eterm* objv, int nobj);
@@ -441,7 +441,15 @@
     p->last_old_htop = p->old_htop;
 #endif

-    return ((int) (HEAP_TOP(p) - HEAP_START(p)) / 10);
+    /* FIXME: This function should really return an Sint, i.e., a possibly
+       64 bit wide signed integer, but that requires updating all the code
+       that calls it. For now, we just return INT_MAX if the result is too
+       large for an int. */
+    {
+      Sint result = (HEAP_TOP(p) - HEAP_START(p)) / 10;
+      if (result >= INT_MAX) return INT_MAX;
+      else return (int) result;
+    }
 }

 /*
@@ -599,7 +607,7 @@
     char* area;
     Uint area_size;
     Eterm* old_htop;
-    int n;
+    Uint n;

     /*
      * Set GC state.
@@ -731,7 +739,7 @@
          * This improved Estone by more than 1200 estones on my computer
          * (Ultra Sparc 10).
          */
-        size_t new_sz = erts_next_heap_size(HEAP_TOP(p) - HEAP_START(p), 1);
+        Uint new_sz = erts_next_heap_size(HEAP_TOP(p) - HEAP_START(p), 1);

         /* Create new, empty old_heap */
         n_old = (Eterm *) ERTS_HEAP_ALLOC(ERTS_ALC_T_OLD_HEAP,
@@ -871,12 +879,12 @@
 #endif /* HIPE */

 static void
-do_minor(Process *p, int new_sz, Eterm* objv, int nobj)
+do_minor(Process *p, Uint new_sz, Eterm* objv, int nobj)
 {
     Rootset rootset;            /* Rootset for GC (stack, dictionary, etc). */
     Roots* roots;
     Eterm* n_htop;
-    int n;
+    Uint n;
     Eterm* ptr;
     Eterm val;
     Eterm gval;
@@ -1079,14 +1087,14 @@
 {
     Rootset rootset;
     Roots* roots;
-    int size_before;
+    Uint size_before;
     Eterm* n_heap;
     Eterm* n_htop;
     char* src = (char *) HEAP_START(p);
     Uint src_size = (char *) HEAP_TOP(p) - src;
     char* oh = (char *) OLD_HEAP(p);
     Uint oh_size = (char *) OLD_HTOP(p) - oh;
-    int n;
+    Uint n;
     Uint new_sz;
     Uint fragments = MBUF_SIZE(p) + combined_message_size(p);
     ErlMessage *msgp;
@@ -1312,10 +1320,10 @@
 }

 static Uint
-adjust_after_fullsweep(Process *p, int size_before, int need, Eterm *objv, int nobj)
-{
-    int wanted, sz, size_after, need_after;
-    int stack_size = STACK_SZ_ON_HEAP(p);
+adjust_after_fullsweep(Process *p, Uint size_before, int need, Eterm *objv, int nobj)
+{
+    Uint wanted, sz, size_after, need_after;
+    Uint stack_size = STACK_SZ_ON_HEAP(p);
     Uint reclaimed_now;

     size_after = (HEAP_TOP(p) - HEAP_START(p));
@@ -1915,8 +1923,8 @@
 grow_new_heap(Process *p, Uint new_sz, Eterm* objv, int nobj)
 {
     Eterm* new_heap;
-    int heap_size = HEAP_TOP(p) - HEAP_START(p);
-    int stack_size = p->hend - p->stop;
+    Uint heap_size = HEAP_TOP(p) - HEAP_START(p);
+    Uint stack_size = p->hend - p->stop;
     Sint offs;

     ASSERT(HEAP_SIZE(p) < new_sz);
@@ -1954,10 +1962,10 @@
 shrink_new_heap(Process *p, Uint new_sz, Eterm *objv, int nobj)
 {
     Eterm* new_heap;
-    int heap_size = HEAP_TOP(p) - HEAP_START(p);
+    Uint heap_size = HEAP_TOP(p) - HEAP_START(p);
     Sint offs;

-    int stack_size = p->hend - p->stop;
+    Uint stack_size = p->hend - p->stop;

     ASSERT(new_sz < p->heap_sz);
     sys_memmove(p->heap + new_sz - stack_size, p->stop, stack_size *


Fixed return code if error

Fixed return code if error

--- src/utils/base_encoding.c
+++ src/utils/base_encoding.c
@@ -260,7 +260,7 @@
 		}
 		*out_size = d_stream.total_out;
 		inflateEnd(&d_stream);
-		return GF_OK;
+		return e;
 	}
 	if (e!=GF_OK) {
 		gf_free(*uncompressed_data);


Initialize the ISO11548-1 dots table using the BRL_DOTn constants (rather than hexadecimal constants). (dm)

git-svn-id: 30a5f035a20f1bc647618dbad7eea2a951b61b7c@5331 91a5dbb7-01b9-0310-9b5f-b28072856b6e

--- Programs/brl.c
+++ Programs/brl.c
@@ -468,7 +468,10 @@
 }
 #endif /* ENABLE_LEARN_MODE */

-const DotsTable dotsTable_ISO11548_1 = {0X01, 0X02, 0X04, 0X08, 0X10, 0X20, 0X40, 0X80};
+const DotsTable dotsTable_ISO11548_1 = {
+  BRL_DOT1, BRL_DOT2, BRL_DOT3, BRL_DOT4,
+  BRL_DOT5, BRL_DOT6, BRL_DOT7, BRL_DOT8
+};

 void
 makeTranslationTable (const DotsTable dots, TranslationTable table) {


Speedup for-loops by inlining PyIter_Next().  Saves duplicate tests and a function call resulting in a 15% reduction of total loop overhead (as measured by timeit.Timer('pass')).

--- Python/ceval.c
+++ Python/ceval.c
@@ -2091,21 +2091,23 @@
 		case FOR_ITER:
 			/* before: [iter]; after: [iter, iter()] *or* [] */
 			v = TOP();
-			x = PyIter_Next(v);
+			x = (*v->ob_type->tp_iternext)(v);
 			if (x != NULL) {
 				PUSH(x);
 				PREDICT(STORE_FAST);
 				PREDICT(UNPACK_SEQUENCE);
 				continue;
 			}
-			if (!PyErr_Occurred()) {
-				/* iterator ended normally */
- 				x = v = POP();
-				Py_DECREF(v);
-				JUMPBY(oparg);
-				continue;
-			}
-			break;
+			if (PyErr_Occurred()) {
+				if (!PyErr_ExceptionMatches(PyExc_StopIteration))
+					break;
+				PyErr_Clear();
+			}
+			/* iterator ended normally */
+ 			x = v = POP();
+			Py_DECREF(v);
+			JUMPBY(oparg);
+			continue;

 		case SETUP_LOOP:
 		case SETUP_EXCEPT:


Fixed a buffer overflow vulnerability with QB GH import and increased the buffer to be long enough to allow songs with longer internal filenames to import.

--- src/gh_import.c
+++ src/gh_import.c
@@ -17,6 +17,7 @@
 unsigned long crc32_lookup[256] = {0};	//A lookup table to improve checksum calculation performance
 char crc32_lookup_initialized = 0;	//Is set to nonzero when the lookup table is created
 char eof_gh_skip_size_def = 0;	//Is set to nonzero if it's determined that the size field in GH headers is omitted
+char magicnumber[] = {0x1C,0x08,0x02,0x04,0x10,0x04,0x08,0x0C,0x0C,0x08,0x02,0x04,0x14,0x02,0x04,0x0C,0x10,0x10,0x0C,0x00};	//The magic number is expected 8 bytes into the QB header

 #define GH_IMPORT_DEBUG

@@ -2063,8 +2064,7 @@
 {
 	EOF_SONG * sp;
 	filebuffer *fb;
-	char filename[101], songname[21], buffer[101], forcestrum = 0;
-	char magicnumber[] = {0x1C,0x08,0x02,0x04,0x10,0x04,0x08,0x0C,0x0C,0x08,0x02,0x04,0x14,0x02,0x04,0x0C,0x10,0x10,0x0C,0x00};	//The magic number is expected 8 bytes into the QB header
+	char filename[101], songname[41], buffer[101], forcestrum = 0;
 	unsigned char byte;
 	unsigned long index, ctr, ctr2, ctr3, arraysize, *arrayptr, numbeats, numsigs, tsnum, tsden, dword, lastfretbar = 0, lastsig = 0;
 	unsigned long qbindex;	//Will store the file index of the QB header
@@ -2135,8 +2135,8 @@
 		}
 	}
 //Parse the song name
-	for(index = 0; (filename[index] != '\0') && (filename[index] != '.'); index++)
-	{	//For each character in the file name until the end of the string or a period is reached
+	for(index = 0; (filename[index] != '\0') && (filename[index] != '.') && (index < sizeof(filename) - 1); index++)
+	{	//For each character in the file name until the end of the string or a period is reached (and while a buffer overflow won't occur)
 		songname[index] = filename[index];	//Copy the character
 	}
 	songname[index] = '\0';	//Terminate the string


Use correct flags for this test.

Use correct flags for this test.

git-svn-id: ffe668792ed300d6c2daa1f6eba2e0aa28d7ec6c@169768 91177308-0d34-0410-b5e6-96231b3b80d8

--- test/CodeGen/code-coverage.c
+++ test/CodeGen/code-coverage.c
@@ -1,4 +1,5 @@
-// RUN: %clang -O0 -S -mno-red-zone -fprofile-arcs -ftest-coverage -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -O0 -emit-llvm -disable-red-zone -femit-coverage-notes -femit-coverage-data %s -o - | FileCheck %s
+
 // <rdar://problem/12843084>

 int test1(int a) {


[WebAssembly] Add a test to ensure that -fvisibility=default works.

It should override the default of -fvisibility=hidden.

git-svn-id: ffe668792ed300d6c2daa1f6eba2e0aa28d7ec6c@257007 91177308-0d34-0410-b5e6-96231b3b80d8

--- test/Driver/wasm-toolchain.c
+++ test/Driver/wasm-toolchain.c
@@ -16,6 +16,12 @@

 // RUN: %clang %s -### -target wasm32-unknown-unknown -fno-data-sections 2>&1 | FileCheck -check-prefix=NO_DATA_SECTIONS %s
 // NO_DATA_SECTIONS-NOT: data-sections
+
+// Ditto, but ensure that a user -fvisibility=default disables the default
+// -fvisibilt=hidden.
+
+// RUN: %clang %s -### -target wasm32-unknown-unknown -fvisibility=default 2>&1 | FileCheck -check-prefix=FVISIBILITY_DEFAULT %s
+// FVISIBILITY_DEFAULT-NOT: hidden

 // A basic C link command-line.


put in summary and conditional defines

put in summary and conditional defines

(Logical change 1.564)

--- sediff/sediff_treemodel.h
+++ sediff/sediff_treemodel.h
@@ -23,15 +23,16 @@
 #define SEDIFF_TREE_STORE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  SEDIFF_TYPE_TREE_STORE, SEDiffTreeViewStoreClass))

 /* defines for the sediff options */
-#define OPT_CLASSES 		0
-#define OPT_TYPES 		1
-#define OPT_ATTRIBUTES          2
-#define OPT_ROLES		3
-#define OPT_USERS		4
-#define OPT_BOOLEANS 		5
-#define OPT_TE_RULES		6
-#define OPT_RBAC_RULES		7
-
+#define OPT_SUMMARY             0
+#define OPT_CLASSES 		1
+#define OPT_TYPES 		2
+#define OPT_ATTRIBUTES          3
+#define OPT_ROLES		4
+#define OPT_USERS		5
+#define OPT_BOOLEANS 		6
+#define OPT_TE_RULES		7
+#define OPT_RBAC_RULES		8
+#define OPT_CONDITIONALS        9

 /* The data columns that we export via the tree model interface */
 enum


input/hog: Rework uHID code to use bt_uhid

--- profiles/input/hog.c
+++ profiles/input/hog.c
@@ -34,7 +34,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include "uhid_copy.h"

 #include <bluetooth/bluetooth.h>

@@ -48,6 +47,7 @@
 #include "src/profile.h"
 #include "src/service.h"
 #include "src/shared/util.h"
+#include "src/shared/uhid.h"

 #include "src/plugin.h"

@@ -71,8 +71,6 @@

 #define HOG_PROTO_MODE_BOOT    0
 #define HOG_PROTO_MODE_REPORT  1
-
-#define UHID_DEVICE_FILE	"/dev/uhid"

 #define HOG_REPORT_MAP_MAX_SIZE        512
 #define HID_INFO_SIZE			4
@@ -85,9 +83,8 @@
 	guint			attioid;
 	struct gatt_primary	*hog_primary;
 	GSList			*reports;
-	int			uhid_fd;
+	struct bt_uhid		*uhid;
 	gboolean		has_report_id;
-	guint			uhid_watch_id;
 	uint16_t		bcdhid;
 	uint8_t			bcountrycode;
 	uint16_t		proto_mode_handle;
@@ -112,7 +109,7 @@
 	struct hog_device *hogdev = report->hogdev;
 	struct uhid_event ev;
 	uint8_t *buf;
-	ssize_t status;
+	int err;

 	if (len < ATT_NOTIFICATION_HEADER_SIZE) {
 		error("Malformed ATT notification");
@@ -137,21 +134,13 @@
 		ev.u.input.size = len;
 	}

-	status = write(hogdev->uhid_fd, &ev, sizeof(ev));
-	if (status < 0) {
-		error("uHID dev write error: %s (%d)", strerror(errno), errno);
-		return;
-	}
-
-	/* uHID kernel driver does not handle partial writes */
-	if ((size_t) status < sizeof(ev)) {
-		error("uHID dev write error: partial write (%zd of %zu bytes)",
-							status, sizeof(ev));
-		return;
-	}
-
-	DBG("HoG report (%u bytes) -> uHID fd %d", ev.u.input.size,
-							hogdev->uhid_fd);
+	err = bt_uhid_send(hogdev->uhid, &ev);
+	if (err < 0) {
+		error("bt_uhid_send: %s (%d)", strerror(-err), -err);
+		return;
+	}
+
+	DBG("HoG report (%u bytes)", ev.u.input.size);
 }

 static void report_ccc_written_cb(guint8 status, const guint8 *pdu,
@@ -317,6 +306,72 @@
 					external_service_char_cb, hogdev);
 }

+static int report_type_cmp(gconstpointer a, gconstpointer b)
+{
+	const struct report *report = a;
+	uint8_t type = GPOINTER_TO_UINT(b);
+
+	return report->type - type;
+}
+
+static void output_written_cb(guint8 status, const guint8 *pdu,
+					guint16 plen, gpointer user_data)
+{
+	if (status != 0) {
+		error("Write output report failed: %s", att_ecode2str(status));
+		return;
+	}
+}
+
+static void forward_report(struct uhid_event *ev, void *user_data)
+{
+	struct hog_device *hogdev = user_data;
+	struct report *report;
+	GSList *l;
+	void *data;
+	int size;
+	guint type;
+
+	if (hogdev->has_report_id) {
+		data = ev->u.output.data + 1;
+		size = ev->u.output.size - 1;
+	} else {
+		data = ev->u.output.data;
+		size = ev->u.output.size;
+	}
+
+	switch (ev->type) {
+	case UHID_OUTPUT:
+		type = HOG_REPORT_TYPE_OUTPUT;
+		break;
+	case UHID_FEATURE:
+		type = HOG_REPORT_TYPE_FEATURE;
+		break;
+	default:
+		return;
+	}
+
+	l = g_slist_find_custom(hogdev->reports, GUINT_TO_POINTER(type),
+							report_type_cmp);
+	if (!l)
+		return;
+
+	report = l->data;
+
+	DBG("Sending report type %d to device 0x%04X handle 0x%X", type,
+				hogdev->id, report->decl->value_handle);
+
+	if (hogdev->attrib == NULL)
+		return;
+
+	if (report->decl->properties & GATT_CHR_PROP_WRITE)
+		gatt_write_char(hogdev->attrib, report->decl->value_handle,
+				data, size, output_written_cb, hogdev);
+	else if (report->decl->properties & GATT_CHR_PROP_WRITE_WITHOUT_RESP)
+		gatt_write_cmd(hogdev->attrib, report->decl->value_handle,
+						data, size, NULL, NULL);
+}
+
 static bool get_descriptor_item_info(uint8_t *buf, ssize_t blen, ssize_t *len,
 								bool *is_long)
 {
@@ -389,7 +444,7 @@
 	uint16_t vendor_src, vendor, product, version;
 	ssize_t vlen;
 	char itemstr[20]; /* 5x3 (data) + 4 (continuation) + 1 (null) */
-	int i;
+	int i, err;

 	if (status != 0) {
 		error("Report Map read failed: %s", att_ecode2str(status));
@@ -450,8 +505,14 @@
 	ev.u.create.rd_data = value;
 	ev.u.create.rd_size = vlen;

-	if (write(hogdev->uhid_fd, &ev, sizeof(ev)) < 0)
-		error("Failed to create uHID device: %s", strerror(errno));
+	err = bt_uhid_send(hogdev->uhid, &ev);
+	if (err < 0) {
+		error("bt_uhid_send: %s", strerror(-err));
+		return;
+	}
+
+	bt_uhid_register(hogdev->uhid, UHID_OUTPUT, forward_report, hogdev);
+	bt_uhid_register(hogdev->uhid, UHID_FEATURE, forward_report, hogdev);
 }

 static void info_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
@@ -581,148 +642,6 @@
 									hogdev);
 }

-static void output_written_cb(guint8 status, const guint8 *pdu,
-					guint16 plen, gpointer user_data)
-{
-	if (status != 0) {
-		error("Write output report failed: %s", att_ecode2str(status));
-		return;
-	}
-}
-
-static int report_type_cmp(gconstpointer a, gconstpointer b)
-{
-	const struct report *report = a;
-	uint8_t type = GPOINTER_TO_UINT(b);
-
-	return report->type - type;
-}
-
-static void forward_report(struct hog_device *hogdev,
-						struct uhid_event *ev)
-{
-	struct report *report;
-	GSList *l;
-	void *data;
-	int size;
-	guint type;
-
-	if (hogdev->has_report_id) {
-		data = ev->u.output.data + 1;
-		size = ev->u.output.size - 1;
-	} else {
-		data = ev->u.output.data;
-		size = ev->u.output.size;
-	}
-
-	switch (ev->type) {
-	case UHID_OUTPUT:
-		type = HOG_REPORT_TYPE_OUTPUT;
-		break;
-	case UHID_FEATURE:
-		type = HOG_REPORT_TYPE_FEATURE;
-		break;
-	default:
-		return;
-	}
-
-	l = g_slist_find_custom(hogdev->reports, GUINT_TO_POINTER(type),
-							report_type_cmp);
-	if (!l)
-		return;
-
-	report = l->data;
-
-	DBG("Sending report type %d to device 0x%04X handle 0x%X", type,
-				hogdev->id, report->decl->value_handle);
-
-	if (hogdev->attrib == NULL)
-		return;
-
-	if (report->decl->properties & GATT_CHR_PROP_WRITE)
-		gatt_write_char(hogdev->attrib, report->decl->value_handle,
-				data, size, output_written_cb, hogdev);
-	else if (report->decl->properties & GATT_CHR_PROP_WRITE_WITHOUT_RESP)
-		gatt_write_cmd(hogdev->attrib, report->decl->value_handle,
-						data, size, NULL, NULL);
-}
-
-static gboolean uhid_event_cb(GIOChannel *io, GIOCondition cond,
-							gpointer user_data)
-{
-	struct hog_device *hogdev = user_data;
-	struct uhid_event ev;
-	ssize_t bread;
-	int fd;
-
-	if (cond & (G_IO_ERR | G_IO_NVAL))
-		goto failed;
-
-	fd = g_io_channel_unix_get_fd(io);
-	memset(&ev, 0, sizeof(ev));
-
-	bread = read(fd, &ev, sizeof(ev));
-	if (bread < 0) {
-		int err = -errno;
-		DBG("uhid-dev read: %s(%d)", strerror(-err), -err);
-		goto failed;
-	}
-
-	DBG("uHID event type %d received", ev.type);
-
-	switch (ev.type) {
-	case UHID_START:
-	case UHID_STOP:
-		/* These are called to start and stop the underlying hardware.
-		 * For HoG we open the channels before creating the device so
-		 * the hardware is always ready. No need to handle these.
-		 * Note that these are also called when the kernel switches
-		 * between device-drivers loaded on the HID device. But we can
-		 * simply keep the hardware alive during transitions and it
-		 * works just fine.
-		 * The kernel never destroys a device itself! Only an explicit
-		 * UHID_DESTROY request can remove a device. */
-		break;
-	case UHID_OPEN:
-	case UHID_CLOSE:
-		/* OPEN/CLOSE are sent whenever user-space opens any interface
-		 * provided by the kernel HID device. Whenever the open-count
-		 * is non-zero we must be ready for I/O. As long as it is zero,
-		 * we can decide to drop all I/O and put the device
-		 * asleep This is optional, though. Moreover, some
-		 * special device drivers are buggy in that regard, so
-		 * maybe we just keep I/O always awake like HIDP in the
-		 * kernel does. */
-		break;
-	case UHID_OUTPUT:
-	case UHID_FEATURE:
-		forward_report(hogdev, &ev);
-		break;
-	case UHID_OUTPUT_EV:
-		/* This is only sent by kernels prior to linux-3.11. It
-		 * requires us to parse HID-descriptors in user-space to
-		 * properly handle it. This is redundant as the kernel
-		 * does it already. That's why newer kernels assemble
-		 * the output-reports and send it to us via UHID_OUTPUT.
-		 * We never implemented this, so we rely on users to use
-		 * recent-enough kernels if they want this feature. No reason
-		 * to implement this for older kernels. */
-		DBG("Unsupported uHID output event: type %d code %d value %d",
-			ev.u.output_ev.type, ev.u.output_ev.code,
-			ev.u.output_ev.value);
-		break;
-	default:
-		warn("unexpected uHID event");
-		break;
-	}
-
-	return TRUE;
-
-failed:
-	hogdev->uhid_watch_id = 0;
-	return FALSE;
-}
-
 static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
 {
 	struct hog_device *hogdev = user_data;
@@ -807,26 +726,17 @@
 						struct gatt_primary *prim)
 {
 	struct hog_device *hogdev;
-	GIOCondition cond = G_IO_IN | G_IO_ERR | G_IO_NVAL;
-	GIOChannel *io;

 	hogdev = hog_new_device(device, prim->range.start);
 	if (!hogdev)
 		return NULL;

-	hogdev->uhid_fd = open(UHID_DEVICE_FILE, O_RDWR | O_CLOEXEC);
-	if (hogdev->uhid_fd < 0) {
-		error("Failed to open uHID device: %s(%d)", strerror(errno),
-									errno);
+	hogdev->uhid = bt_uhid_new_default();
+	if (!hogdev->uhid) {
+		error("bt_uhid_new_default: failed");
 		hog_free_device(hogdev);
 		return NULL;
 	}
-
-	io = g_io_channel_unix_new(hogdev->uhid_fd);
-	g_io_channel_set_encoding(io, NULL, NULL);
-	hogdev->uhid_watch_id = g_io_add_watch(io, cond, uhid_event_cb,
-								hogdev);
-	g_io_channel_unref(io);

 	hogdev->hog_primary = g_memdup(prim, sizeof(*prim));

@@ -841,22 +751,17 @@
 static int hog_unregister_device(struct hog_device *hogdev)
 {
 	struct uhid_event ev;
+	int err;

 	btd_device_remove_attio_callback(hogdev->device, hogdev->attioid);
-
-	if (hogdev->uhid_watch_id) {
-		g_source_remove(hogdev->uhid_watch_id);
-		hogdev->uhid_watch_id = 0;
-	}

 	memset(&ev, 0, sizeof(ev));
 	ev.type = UHID_DESTROY;
-	if (write(hogdev->uhid_fd, &ev, sizeof(ev)) < 0)
-		error("Failed to destroy uHID device: %s", strerror(errno));
-
-	close(hogdev->uhid_fd);
-	hogdev->uhid_fd = -1;
-
+	err = bt_uhid_send(hogdev->uhid, &ev);
+	if (err < 0)
+		error("bt_uhid_send: %s (%d)", strerror(-err), -err);
+
+	bt_uhid_unref(hogdev->uhid);
 	hog_free_device(hogdev);

 	return 0;


Increase ClassDef in AliConvEventCuts

Increase ClassDef in AliConvEventCuts

--- PWGGA/GammaConvBase/AliConvEventCuts.h
+++ PWGGA/GammaConvBase/AliConvEventCuts.h
@@ -770,7 +770,7 @@
   private:

       /// \cond CLASSIMP
-      ClassDef(AliConvEventCuts,76)
+      ClassDef(AliConvEventCuts,77)
       /// \endcond
 };


double buffer by default.  if drawSmooth, use 50% alpha at top of polygon

--- progs/demos/texenv.c
+++ progs/demos/texenv.c
@@ -65,7 +65,7 @@
 GLfloat labelLevelColor0[4] = { 0.8, 0.8, 0.1, 1.0 };
 GLfloat labelLevelColor1[4] = { 0.0, 0.0, 0.0, 1.0 };

-GLboolean doubleBuffered = GL_FALSE;
+GLboolean doubleBuffered = GL_TRUE;
 GLboolean drawBackground = GL_FALSE;
 GLboolean drawBlended = GL_TRUE;
 GLboolean drawSmooth = GL_FALSE;
@@ -574,6 +574,10 @@
       glEnable( GL_TEXTURE_2D );
    }

+   /*
+    * if (drawSmooth) then draw quad which goes from purple at the
+    * bottom (100% alpha) to green at the top (50% alpha).
+    */
    glBegin( GL_QUADS );
       if ( drawSmooth )  glColor4f( 1.0, 0.0, 1.0, 1.0 );
       glTexCoord2f( 0.0, 0.0 );
@@ -583,11 +587,11 @@
       glTexCoord2f( 1.0, 0.0 );
       glVertex2f( 0.8, -0.8 );

-      if ( drawSmooth )  glColor4f( 0.0, 1.0, 0.0, 1.0 );
+      if ( drawSmooth )  glColor4f( 0.0, 1.0, 0.0, 0.5 );
       glTexCoord2f( 1.0, 1.0 );
       glVertex2f( 0.8, 0.8 );

-      if ( drawSmooth )  glColor4f( 0.0, 1.0, 0.0, 1.0 );
+      if ( drawSmooth )  glColor4f( 0.0, 1.0, 0.0, 0.5 );
       glTexCoord2f( 0.0, 1.0 );
       glVertex2f( -0.8, 0.8 );
    glEnd();


[AnerleyTpItem] Base presence off of the known-good enum values

Rather that using the presence status string, which may be customised by a CM
we use the enum'ed presence type to determine the presence.

Fixes: MB#7115

--- anerley/anerley-tp-item.c
+++ anerley/anerley-tp-item.c
@@ -42,11 +42,12 @@

   gchar *display_name;
   gchar *avatar_path;
-  gchar *presence_status;
   gchar *presence_message;
   gchar *sortable_name;
   gchar *first_name;
   gchar *last_name;
+
+  const gchar *presence_status;
 };

 enum
@@ -422,6 +423,34 @@
   anerley_item_emit_display_name_changed ((AnerleyItem *)item);
 }

+static const gchar *
+_get_real_presence_status (TpContact *contact)
+{
+  switch (tp_contact_get_presence_type (contact))
+  {
+    case TP_CONNECTION_PRESENCE_TYPE_UNSET:
+      return "offline";
+    case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
+      return "offline";
+    case TP_CONNECTION_PRESENCE_TYPE_AVAILABLE:
+      return "available";
+    case TP_CONNECTION_PRESENCE_TYPE_AWAY:
+      return "away";
+    case TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY:
+      return "xa";
+    case TP_CONNECTION_PRESENCE_TYPE_HIDDEN:
+      return "offline";
+    case TP_CONNECTION_PRESENCE_TYPE_BUSY:
+      return "dnd";
+    case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
+      return "offline";
+    case TP_CONNECTION_PRESENCE_TYPE_ERROR:
+      return "offline";
+    default:
+      return "offline";
+  }
+}
+
 static void
 _contact_notify_presence_status_cb (GObject    *object,
                                     GParamSpec *pspec,
@@ -431,12 +460,11 @@
   AnerleyTpItem *item = (AnerleyTpItem *)userdata;
   AnerleyTpItemPrivate *priv = GET_PRIVATE (item);

-  g_free (priv->presence_status);
-  priv->presence_status = NULL;
-
-  if (tp_contact_get_presence_status (contact))
-  {
-    priv->presence_status = g_strdup (tp_contact_get_presence_status (contact));
+  if (_get_real_presence_status (contact))
+  {
+    priv->presence_status = _get_real_presence_status (contact);
+  } else {
+    priv->presence_status = NULL;
   }

   anerley_item_emit_presence_changed ((AnerleyItem *)item);
@@ -488,7 +516,6 @@

   g_free (priv->display_name);
   g_free (priv->avatar_path);
-  g_free (priv->presence_status);
   g_free (priv->presence_message);

   priv->display_name = NULL;


Header to centralize physics names

Header to centralize physics names

error: pathspec 'src/grins_interface/include/planet/physics_names.h' did not match any file(s) known to git

--- src/grins_interface/include/planet/physics_names.h
+++ src/grins_interface/include/planet/physics_names.h
@@ -0,0 +1,30 @@
+//-----------------------------------------------------------------------bl-
+//--------------------------------------------------------------------------
+//
+// Planet - An atmospheric code for planetary bodies, adapted to Titan
+//
+// Copyright (C) 2013 The PECOS Development Team
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the Version 2.1 GNU Lesser General
+// Public License as published by the Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc. 51 Franklin Street, Fifth Floor,
+// Boston, MA  02110-1301  USA
+//
+//-----------------------------------------------------------------------el-
+
+// C++
+#include <string>
+
+namespace Planet
+{
+  const std::string planet_physics = "Planet";
+} // end namespace Planet


Fix windows compile

Fix windows compile

--- plugins/landmarks/sqlite/databasefilewatcher_p.h
+++ plugins/landmarks/sqlite/databasefilewatcher_p.h
@@ -60,7 +60,7 @@
 // We mean it.
 //

-class Q_AUTOTEST_EXPORT DatabaseFileWatcher : public QObject
+class DatabaseFileWatcher : public QObject
 {
     Q_OBJECT
 public:


semantic check s1

semantic check s1

* fix bug where block context doesn't propagate outward

--- include/language/stage/verifier/visitor/SemanticVerificationStageVisitor1.h
+++ include/language/stage/verifier/visitor/SemanticVerificationStageVisitor1.h
@@ -249,6 +249,9 @@
 		});

 		revisit(node);
+
+		if(isa<Block>(node.parent) && SemanticVerificationBlockContext_AlwaysReturns::get(&node))
+			SemanticVerificationBlockContext_AlwaysReturns::bind(&node);
 	}

 	void verify(IfElseStmt& node)


fix pre-python 2.6 compatibility

fix pre-python 2.6 compatibility

--- jsonlib2.c
+++ jsonlib2.c
@@ -15,6 +15,10 @@

 #define FALSE 0
 #define TRUE 1
+
+#ifndef Py_NAN
+#define Py_NAN (Py_HUGE_VAL *0.)
+#endif

 #if PY_VERSION_HEX < 0x02050000
 typedef int Py_ssize_t;


Revert "vere: fix cttp crash by accounting for synchronous error callback"

--- pkg/urbit/vere/io/cttp.c
+++ pkg/urbit/vere/io/cttp.c
@@ -559,18 +559,13 @@
     return 0;
   }

-  //  parse the url out of the new style url passed to us.
-  //
+  // Parse the url out of the new style url passed to us.
   u3_noun unit_pul = u3do("de-purl:html", u3k(url));
-
-  if ( c3n == u3r_du(unit_pul) ) {
-    c3_c* url_c = u3r_string(url);
-    u3l_log("cttp: unable to parse url:\n    %s\n", url_c);
-    c3_free(url_c);
+  if (c3n == u3r_du(unit_pul)) {
+    u3l_log("cttp: url parsing failed\n");
     u3z(hes);
     return 0;
   }
-
   u3_noun pul = u3t(unit_pul);

   u3_noun hat = u3h(pul);      // +hart
@@ -822,7 +817,7 @@
 */
 static h2o_http1client_head_cb
 _cttp_creq_on_connect(h2o_http1client_t* cli_u, const c3_c* err_c,
-                      h2o_iovec_t** vec_u, size_t* vec_i, c3_i* hed_i)
+                      h2o_iovec_t** vec_p, size_t* vec_t, c3_i* hed_i)
 {
   u3_creq* ceq_u = (u3_creq *)cli_u->data;

@@ -831,16 +826,11 @@
     return 0;
   }

-  //  serialize request (populate rub_u)
-  //
-  _cttp_creq_fire(ceq_u);
-
   {
     c3_w len_w;
     ceq_u->vec_u = _cttp_bods_to_vec(ceq_u->rub_u, &len_w);
-
-    *vec_i = len_w;
-    *vec_u = ceq_u->vec_u;
+    *vec_t = len_w;
+    *vec_p = ceq_u->vec_u;
     *hed_i = (0 == strcmp(ceq_u->met_c, "HEAD"));
   }

@@ -852,28 +842,24 @@
 static void
 _cttp_creq_connect(u3_creq* ceq_u)
 {
-  c3_assert( u3_csat_ripe == ceq_u->sat_e );
-  c3_assert( ceq_u->ipf_c );
-
-  //  set hostname for TLS handshake
-  //
+  c3_assert(u3_csat_ripe == ceq_u->sat_e);
+  c3_assert(ceq_u->ipf_c);
+
+  h2o_iovec_t ipf_u = h2o_iovec_init(ceq_u->ipf_c, strlen(ceq_u->ipf_c));
+  c3_s por_s = ceq_u->por_s ? ceq_u->por_s :
+               ( c3y == ceq_u->sec ) ? 443 : 80;
+
+  // connect by IP
+  h2o_http1client_connect(&ceq_u->cli_u, ceq_u, &ceq_u->ctp_u->ctx_u, ipf_u,
+                          por_s, c3y == ceq_u->sec, _cttp_creq_on_connect);
+
+  // set hostname for TLS handshake
   if ( ceq_u->hot_c && c3y == ceq_u->sec ) {
     c3_free(ceq_u->cli_u->ssl.server_name);
     ceq_u->cli_u->ssl.server_name = strdup(ceq_u->hot_c);
   }

-  //  connect by IP
-  //
-  {
-    h2o_iovec_t ipf_u = h2o_iovec_init(ceq_u->ipf_c, strlen(ceq_u->ipf_c));
-    c3_t        tls_t = ( c3y == ceq_u->sec );
-    c3_s        por_s = ( ceq_u->por_s )
-                        ? ceq_u->por_s
-                        : ( tls_t ) ? 443 : 80;
-
-    h2o_http1client_connect(&ceq_u->cli_u, ceq_u, &ceq_u->ctp_u->ctx_u,
-                            ipf_u, por_s, tls_t, _cttp_creq_on_connect);
-  }
+  _cttp_creq_fire(ceq_u);
 }

 /* _cttp_creq_resolve_cb(): cb upon IP address resolution
@@ -995,6 +981,7 @@
       ret_o = c3y;
     }
     else {
+      u3l_log("cttp: strange request (unparsable url)\n");
       ret_o = c3n;
     }
   }


unix: don't require that string is non-empty

Fixes an assert failure if you try to commit a file named `~.`.

--- pkg/urbit/vere/io/unix.c
+++ pkg/urbit/vere/io/unix.c
@@ -142,7 +142,9 @@
 _unix_string_to_knot(c3_c* pax_c)
 {
   c3_assert(pax_c);
-  c3_assert(*pax_c);
+  //  XX  this can happen if we encounter a file without an extension.
+  //
+  // c3_assert(*pax_c);
   c3_assert(!strchr(pax_c, '/'));
   c3_assert(!strchr(pax_c, '\\'));
   if ( 0 == strncmp("~.", pax_c, 2) ) {


Fix background in superkaramba theme Patch from Pulfer BUG: 275383

--- plasma/skappletadaptor.h
+++ plasma/skappletadaptor.h
@@ -138,6 +138,7 @@
             //, m_widget(new Plasma::Widget(applet->karamba()))
             , m_painterenabled(false) {
             setObjectName( QLatin1String("PlasmaApplet" ));
+            m_applet->setBackgroundHints(Plasma::Applet::DefaultBackground);
         }
         virtual ~SkAppletAdaptor() {
             //delete m_widget;


added REALLOC macro with Python exception raising...

--- pygr/default.h
+++ pygr/default.h
@@ -44,4 +44,26 @@

 #define FREE(P) if (P) {free(P);(P)=NULL;}

+/* IF realloc FAILS, memptr REMAINS VALID, BUT MALLOC_FAILURE_ACTION IS INVOKED. */
+#define REALLOC(memptr,N,ATYPE) \
+  if ((N)<=0) {\
+    char errstr[1024]; \
+    sprintf(errstr,"%s, line %d: *** invalid memory request: %s[%d].\n",\
+              __FILE__,__LINE__,STRINGIFY(memptr),(N));   \
+    PyErr_SetString(PyExc_ValueError,errstr); \
+    MALLOC_FAILURE_ACTION;\
+  }\
+  else {\
+    void *tmp_realloc_ptrZZ; \
+    if (NULL == (tmp_realloc_ptrZZ=realloc((memptr),(size_t)(N)*sizeof(ATYPE))))  { \
+      char errstr[1024]; \
+      sprintf(errstr,"%s, line %d: memory request failed: %s[%d].\n",\
+                __FILE__,__LINE__,STRINGIFY(memptr),(N));   \
+      PyErr_SetString(PyExc_MemoryError,errstr); \
+      MALLOC_FAILURE_ACTION;\
+    } \
+    else \
+      (memptr)=(ATYPE *)tmp_realloc_ptrZZ; \
+  }
+
 #endif


Implemented movement of the ball.  Bounces off window edges.

--- pset3/breakout/breakout.c
+++ pset3/breakout/breakout.c
@@ -73,6 +73,10 @@

     // number of points initially
     int points = 0;
+
+    // ball's initial velocity
+    double velocityX = (drand48() / 20.0) + 0.05;
+    double velocityY = 0.1;

     // keep playing until game over
     while (lives > 0 && bricks > 0)
@@ -104,6 +108,32 @@
             }
         }

+        // move the ball
+        move(ball, velocityX, velocityY);
+
+        // bounce off right edge of window
+        if (getX(ball) + getWidth(ball) >= getWidth(window))
+        {
+            velocityX = -velocityX;
+        }
+
+        // bounce off left edge of window
+        else if (getX(ball) <= 0)
+        {
+            velocityX = -velocityX;
+        }
+
+        // bounce off top edge of window
+        if (getY(ball) <= 0)
+        {
+            velocityY = -velocityY;
+        }
+
+        // bounce off bottom edge of window
+        else if (getY(ball) + getHeight(ball) >= getHeight(window))
+        {
+            velocityY = -velocityY;
+        }
     }

     // wait for click before exiting


pop3-migration: Added more debug and error logging.

--- src/plugins/pop3-migration/pop3-migration-plugin.c
+++ src/plugins/pop3-migration/pop3-migration-plugin.c
@@ -286,8 +286,11 @@
 		map->size = size;
 	}

-	if (mailbox_search_deinit(&ctx) < 0)
+	if (mailbox_search_deinit(&ctx) < 0) {
+		i_error("pop3_migration: Failed to search all POP3 mails: %s",
+			mailbox_get_last_error(pop3_box, NULL));
 		ret = -1;
+	}
 	(void)mailbox_transaction_commit(&t);
 	return ret;
 }
@@ -331,8 +334,11 @@
 			map->hdr_sha1_set = TRUE;
 	}

-	if (mailbox_search_deinit(&ctx) < 0)
+	if (mailbox_search_deinit(&ctx) < 0) {
+		i_error("pop3_migration: Failed to search all POP3 mail hashes: %s",
+			mailbox_get_last_error(pop3_box, NULL));
 		ret = -1;
+	}
 	(void)mailbox_transaction_commit(&t);
 	if (ret == 0 && first_seq == 1)
 		mstorage->pop3_all_hdr_sha1_set = TRUE;
@@ -377,8 +383,11 @@
 		map->psize = psize;
 	}

-	if (mailbox_search_deinit(&ctx) < 0)
+	if (mailbox_search_deinit(&ctx) < 0) {
+		i_error("pop3_migration: Failed to search all IMAP mails: %s",
+			mailbox_get_last_error(box, NULL));
 		ret = -1;
+	}
 	(void)mailbox_transaction_commit(&t);
 	return ret;
 }
@@ -410,8 +419,11 @@
 			map->hdr_sha1_set = TRUE;
 	}

-	if (mailbox_search_deinit(&ctx) < 0)
+	if (mailbox_search_deinit(&ctx) < 0) {
+		i_error("pop3_migration: Failed to search all IMAP mail hashes: %s",
+			mailbox_get_last_error(box, NULL));
 		ret = -1;
+	}
 	(void)mailbox_transaction_commit(&t);
 	return ret;
 }
@@ -443,6 +455,8 @@
 		imap_map[i].pop3_seq = pop3_map[i].pop3_seq;
 	}
 	mbox->first_unfound_idx = i;
+	if (box->storage->user->mail_debug)
+		i_debug("pop3_migration: %u/%u mails matched by size", i, count);
 	return i == count;
 }

@@ -511,6 +525,8 @@
 		}
 		i_warning("pop3_migration: %u POP3 messages have no "
 			  "matching IMAP messages", missing_uids_count);
+	} else if (box->storage->user->mail_debug) {
+		i_debug("pop3_migration: %u mails matched by headers", pop3_count);
 	}
 	array_sort(&mstorage->pop3_uidl_map, pop3_uidl_map_pop3_seq_cmp);
 	array_sort(&mbox->imap_msg_map, imap_msg_map_uid_cmp);
@@ -666,8 +682,11 @@

 	pop3_box_vname = mail_user_plugin_getenv(storage->user,
 						 "pop3_migration_mailbox");
-	if (pop3_box_vname == NULL)
+	if (pop3_box_vname == NULL) {
+		if (storage->user->mail_debug)
+			i_debug("pop3_migration: No pop3_migration_mailbox setting - disabled");
 		return;
+	}

 	mstorage = p_new(storage->pool, struct pop3_migration_mail_storage, 1);
 	mstorage->module_ctx.super = *v;


new class that implements virtual bool ReportContactCallback()  report all contact data any given step to either the console or file.

--- src/demos/trackVehicle/subsys/collision/TrackCollisionCallback.h
+++ src/demos/trackVehicle/subsys/collision/TrackCollisionCallback.h
@@ -97,6 +97,7 @@
   double pin_y_offset;
 };

+
 /// Concave geometry (gear tooth seat) cannot be exactly represented by default collision primitives,
 ///  nor can it be accurately modeled with a mesh or convex hull.
 /// This custom collision checks the sprocket gear seat geometry with all the track shoe pins.
@@ -160,7 +161,7 @@

 	}

-
+  // data container for 6-DOF contact reaction cache
   class GearPinCacheContact{
 	  public:
 		  GearPinCacheContact()
@@ -452,6 +453,59 @@
 };  // end class GearPinCollisionCallback

+// scan through all the contacts, write ascii to console or file
+class _contact_reporter : public ChReportContactCallback
+{
+public:
+
+  // constructor requires user to specify to file or console
+  _contact_reporter(ChStreamOutAscii& out_stream,
+    bool write_to_console = true
+    ): os(out_stream), to_console(write_to_console), contact_num(0) {}
+
+  virtual bool ReportContactCallback(const ChVector<>& pA,
+                                     const ChVector<>& pB,
+                                     const ChMatrix33<>& plane_coord,
+                                     const double& distance,
+                                     const float& mfriction,
+                                     const ChVector<>& react_forces,
+                                     const ChVector<>& react_torques,
+                                     collision::ChCollisionModel* modA,
+                                     collision::ChCollisionModel* modB)
+  {
+    // write to console
+    if(to_console)
+    {
+      os << "\n ---- collision info, # : " << contact_num
+        <<"\n pA : " << pA
+        <<"\n pB : " << pB
+        <<"\n norm: " << plane_coord.Get_A_Xaxis()
+        <<"\n dist: " << distance
+        <<"\n forces: " << react_forces
+        << "\n";
+    }
+    else
+    {
+      // write to file
+      os << pA
+        <<","<< pB
+        <<","<< plane_coord.Get_A_Xaxis()
+        <<","<< distance
+        <<","<< react_forces
+        << "\n";
+    }
+
+    contact_num++;
+    return true; // to continue scanning contacts
+  }
+
+  // can be console or file
+  ChStreamOutAscii& os;
+  bool to_console;
+  int contact_num;  // this contact #
+};  // end class _contact_reporter
+
+
 }  // end namespace chrono

 #endif


Make music controls static functions.

Make music controls static functions.

--- audio/Music.h
+++ audio/Music.h
@@ -93,7 +93,7 @@
 		 * audio to play from where it was paused. Calling this function when no music is loaded or when
 		 * the music is already paused will result in undefined behavior.
 		 */
-		void pause();
+		static void pause();

 		/** Resume playing music.
 		 *
@@ -101,13 +101,13 @@
 		 * when no music is loaded, or when the music is already playing will result in undefined
 		 * behavior.
 		 */
-		void resume();
+		static void resume();

 		/** Stop playing music.
 		 *
 		 * The functional opposite of Music::play(). Stops the music.
 		 */
-		void stop();
+		static void stop();

 		/** Set the fade-in time.
 		 *


pop3-migration: Migrate also POP3 ordering.

--- src/plugins/pop3-migration/pop3-migration-plugin.c
+++ src/plugins/pop3-migration/pop3-migration-plugin.c
@@ -5,6 +5,7 @@
 #include "istream.h"
 #include "istream-header-filter.h"
 #include "sha1.h"
+#include "message-size.h"
 #include "mail-namespace.h"
 #include "mail-search-build.h"
 #include "mail-storage-private.h"
@@ -17,6 +18,7 @@

 struct pop3_uidl_map {
 	uint32_t pop3_seq;
+	uint32_t imap_uid;

 	/* UIDL */
 	const char *pop3_uidl;
@@ -25,11 +27,10 @@
 	/* sha1(TOP 0) - set only when needed */
 	unsigned char hdr_sha1[SHA1_RESULTLEN];
 	unsigned int hdr_sha1_set:1;
-	unsigned int imap_uid_found:1;
 };

 struct imap_msg_map {
-	uint32_t uid;
+	uint32_t uid, pop3_seq;
 	uoff_t psize;
 	const char *pop3_uidl;

@@ -57,6 +58,7 @@

 	unsigned int uidl_synced:1;
 	unsigned int uidl_sync_failed:1;
+	unsigned int uidl_ordered:1;
 };

 static const char *hdr_hash_skip_headers[] = {
@@ -111,22 +113,25 @@

 static int get_hdr_sha1(struct mail *mail, unsigned char sha1[SHA1_RESULTLEN])
 {
-	struct istream *input;
+	struct message_size hdr_size;
+	struct istream *input, *input2;
 	const unsigned char *data;
 	size_t size;
 	struct sha1_ctxt sha1_ctx;

-	if (mail_get_hdr_stream(mail, NULL, &input) < 0) {
+	if (mail_get_hdr_stream(mail, &hdr_size, &input) < 0) {
 		i_error("pop3_migration: Failed to get header for msg %u",
 			mail->seq);
 		return -1;
 	}
+	input2 = i_stream_create_limit(input, hdr_size.physical_size);
 	/* hide headers that might change or be different in IMAP vs. POP3 */
-	input = i_stream_create_header_filter(input,
+	input = i_stream_create_header_filter(input2,
 				HEADER_FILTER_EXCLUDE | HEADER_FILTER_NO_CR,
 				hdr_hash_skip_headers,
 				N_ELEMENTS(hdr_hash_skip_headers),
 				null_header_filter_callback, NULL);
+	i_stream_unref(&input2);

 	sha1_init(&sha1_ctx);
 	while (i_stream_read_data(input, &data, &size, 0) > 0) {
@@ -186,7 +191,7 @@
 	if (array_is_created(&mstorage->pop3_uidl_map)) {
 		/* already read these, just reset the imap_uids */
 		array_foreach_modifiable(&mstorage->pop3_uidl_map, map)
-			map->imap_uid_found = FALSE;
+			map->imap_uid = 0;
 		return 0;
 	}
 	i_array_init(&mstorage->pop3_uidl_map, 128);
@@ -378,9 +383,14 @@
 	for (i = 0; i < count; i++) {
 		if (pop3_map[i].size != imap_map[i].psize)
 			break;
-
-		pop3_map[i].imap_uid_found = TRUE;
+		if (i+1 < count && pop3_map[i].size == pop3_map[i+1].size) {
+			/* two messages with same size, don't trust them */
+			break;
+		}
+
+		pop3_map[i].imap_uid = imap_map[i].uid;
 		imap_map[i].pop3_uidl = pop3_map[i].pop3_uidl;
+		imap_map[i].pop3_seq = pop3_map[i].pop3_seq;
 	}
 	mbox->first_unfound_idx = i;
 	return i == count;
@@ -411,7 +421,7 @@
 	pop3_idx = imap_idx = 0;
 	while (pop3_idx < pop3_count && imap_idx < imap_count) {
 		if (!pop3_map[pop3_idx].hdr_sha1_set ||
-		    pop3_map[pop3_idx].imap_uid_found) {
+		    pop3_map[pop3_idx].imap_uid != 0) {
 			pop3_idx++;
 			continue;
 		}
@@ -428,28 +438,35 @@
 		else if (ret > 0)
 			imap_idx++;
 		else {
-			pop3_map[pop3_idx].imap_uid_found = TRUE;
+			pop3_map[pop3_idx].imap_uid = imap_map[imap_idx].uid;
 			imap_map[imap_idx].pop3_uidl =
 				pop3_map[pop3_idx].pop3_uidl;
+			imap_map[imap_idx].pop3_seq =
+				pop3_map[pop3_idx].pop3_seq;
 		}
 	}
 	missing_uids_count = 0;
 	for (pop3_idx = 0; pop3_idx < pop3_count; pop3_idx++) {
-		if (!pop3_map[pop3_idx].imap_uid_found)
+		if (pop3_map[pop3_idx].imap_uid == 0)
 			missing_uids_count++;
 	}
 	if (missing_uids_count > 0 && !mstorage->all_mailboxes) {
 		i_warning("pop3_migration: %u POP3 messages have no "
 			  "matching IMAP messages", missing_uids_count);
 	}
-
 	array_sort(&mstorage->pop3_uidl_map, pop3_uidl_map_pop3_seq_cmp);
+	array_sort(&mbox->imap_msg_map, imap_msg_map_uid_cmp);
 	return 0;
 }

 static int pop3_migration_uidl_sync(struct mailbox *box)
 {
 	struct pop3_migration_mailbox *mbox = POP3_MIGRATION_CONTEXT(box);
+	struct pop3_migration_mail_storage *mstorage =
+		POP3_MIGRATION_CONTEXT(box->storage);
+	const struct pop3_uidl_map *pop3_map;
+	unsigned int i, count;
+	uint32_t prev_uid;

 	if (mbox->uidl_synced)
 		return 0;
@@ -467,6 +484,21 @@
 			return -1;
 	}

+	/* see if the POP3 UIDL order is the same as IMAP UID order */
+	mbox->uidl_ordered = TRUE;
+	pop3_map = array_get(&mstorage->pop3_uidl_map, &count);
+	prev_uid = 0;
+	for (i = 0; i < count; i++) {
+		if (pop3_map[i].imap_uid == 0)
+			continue;
+
+		if (prev_uid > pop3_map[i].imap_uid) {
+			mbox->uidl_ordered = FALSE;
+			break;
+		}
+		prev_uid = pop3_map[i].imap_uid;
+	}
+
 	mbox->uidl_synced = TRUE;
 	return 0;
 }
@@ -480,7 +512,8 @@
 	struct pop3_migration_mailbox *mbox = POP3_MIGRATION_CONTEXT(_mail->box);
 	struct imap_msg_map map_key, *map;

-	if (field == MAIL_FETCH_UIDL_BACKEND) {
+	if (field == MAIL_FETCH_UIDL_BACKEND ||
+	    field == MAIL_FETCH_POP3_ORDER) {
 		if (mbox->uidl_sync_failed ||
 		    pop3_migration_uidl_sync(_mail->box) < 0) {
 			mbox->uidl_sync_failed = TRUE;
@@ -489,14 +522,19 @@
 					       "POP3 UIDLs couldn't be synced");
 			return -1;
 		}
+
 		memset(&map_key, 0, sizeof(map_key));
 		map_key.uid = _mail->uid;
 		map = array_bsearch(&mbox->imap_msg_map, &map_key,
 				    imap_msg_map_uid_cmp);
 		if (map != NULL && map->pop3_uidl != NULL) {
-			*value_r = map->pop3_uidl;
+			if (field == MAIL_FETCH_UIDL_BACKEND)
+				*value_r = map->pop3_uidl;
+			else
+				*value_r = t_strdup_printf("%u", map->pop3_seq);
 			return 0;
 		}
+		/* not found from POP3 server, fallback to default */
 	}
 	return mmail->super.get_special(_mail, field, value_r);
 }


regmap: irq: Factor register read out of the IRQ parsing loop

In preparation for adding back support for block reads.

Signed-off-by: Mark Brown <b51b9a92386687a9ac927cebfa0f978adeb8cea5@opensource.wolfsonmicro.com>

--- drivers/base/regmap/regmap-irq.c
+++ drivers/base/regmap/regmap-irq.c
@@ -170,6 +170,20 @@
 		}
 	}

+	for (i = 0; i < data->chip->num_regs; i++) {
+		ret = regmap_read(map, chip->status_base + (i * map->reg_stride
+				   * data->irq_reg_stride),
+				   &data->status_buf[i]);
+
+		if (ret != 0) {
+			dev_err(map->dev, "Failed to read IRQ status: %d\n",
+					ret);
+			if (chip->runtime_pm)
+				pm_runtime_put(map->dev);
+			return IRQ_NONE;
+		}
+	}
+
 	/*
 	 * Ignore masked IRQs and ack if we need to; we ack early so
 	 * there is no race between handling and acknowleding the
@@ -178,18 +192,6 @@
 	 * doing a write per register.
 	 */
 	for (i = 0; i < data->chip->num_regs; i++) {
-		ret = regmap_read(map, chip->status_base + (i * map->reg_stride
-				   * data->irq_reg_stride),
-				   &data->status_buf[i]);
-
-		if (ret != 0) {
-			dev_err(map->dev, "Failed to read IRQ status: %d\n",
-					ret);
-			if (chip->runtime_pm)
-				pm_runtime_put(map->dev);
-			return IRQ_NONE;
-		}
-
 		data->status_buf[i] &= ~data->mask_buf[i];

 		if (data->status_buf[i] && chip->ack_base) {


drbd: bm_page_async_io: properly initialize page->private

If bm_page_async_io is advised to use a new page for I/O
(BM_AIO_COPY_PAGES is set), it will get it from a mempool.
Once the mempool has to dip into its reserves the page is
not reinitialized, i.e. page->private contains garbage, which
will lead to various problems once the I/O completes (dereferences
of NULL pointers, the submitting thread getting stuck in D-state,
 ...).

Signed-off-by: Arne Redlich <fe857e7c679ba9b0ec5d0dc3e29c07dd458bcb95@googlemail.com>
Signed-off-by: Lars Ellenberg <31df9cacdc65c624cc60c2dcd22bbf92dc230e16@linbit.com>

--- drivers/block/drbd/drbd_bitmap.c
+++ drivers/block/drbd/drbd_bitmap.c
@@ -200,7 +200,7 @@
 static void bm_store_page_idx(struct page *page, unsigned long idx)
 {
 	BUG_ON(0 != (idx & ~BM_PAGE_IDX_MASK));
-	page_private(page) |= idx;
+	set_page_private(page, idx);
 }

 static unsigned long bm_page_to_idx(struct page *page)


drbd: Fixed a stupid copy and paste error

This caused rs_planed to be not in sync with the content of the fifo.
That in turn could cause that the resync comes to a complete halt.

Signed-off-by: Philipp Reisner <35a55a4ac466b5abd81eb66f3f7d6a972dd0dc24@linbit.com>
Signed-off-by: Lars Ellenberg <31df9cacdc65c624cc60c2dcd22bbf92dc230e16@linbit.com>

--- drivers/block/drbd/drbd_worker.c
+++ drivers/block/drbd/drbd_worker.c
@@ -421,7 +421,7 @@
 	int i;

 	for (i = 0; i < fb->size; i++)
-		fb->values[i] += value;
+		fb->values[i] = value;
 }

 static int fifo_push(struct fifo_buffer *fb, int value)


vfio: fix workaround of BAR mapping

vfio: fix workaround of BAR mapping

Currently, VFIO will try to map around MSI-X table in the BARs. When
MSI-X table (page-aligned) size is equal to (page-aligned) size of BAR,
VFIO will just skip the BAR.

Recent kernel versions will allow VFIO to map the entire BAR containing
MSI-X tables (*), so instead of trying to map around the MSI-X vector
or skipping the BAR entirely if it's not possible, we can now try
mapping the entire BAR first. If mapping the entire BAR doesn't
succeed, fall back to the old behavior of mapping around MSI-X table or
skipping the BAR.

(*): "vfio-pci: Allow mapping MSIX BAR",
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
commit/?id=a32295c612c57990d17fb0f41e7134394b2f35f6

Fixes: 90a1633b2347 ("eal/linux: allow to map BARs with MSI-X tables")

Signed-off-by: Takeshi Yoshimura <837d1d9c32bfa41c7d82d87e8e1d4952c89643cf@gmail.com>
Reviewed-by: Anatoly Burakov <814e00d8f6e4e81b7ccc7e3e5a0bfec0078f0203@intel.com>

--- drivers/bus/pci/linux/pci_vfio.c
+++ drivers/bus/pci/linux/pci_vfio.c
@@ -332,56 +332,71 @@
 	void *bar_addr;
 	struct pci_msix_table *msix_table = &vfio_res->msix_table;
 	struct pci_map *bar = &vfio_res->maps[bar_index];
+	bool again = false;

 	if (bar->size == 0)
 		/* Skip this BAR */
 		return 0;

-	if (msix_table->bar_index == bar_index) {
-		/*
-		 * VFIO will not let us map the MSI-X table,
-		 * but we can map around it.
-		 */
-		uint32_t table_start = msix_table->offset;
-		uint32_t table_end = table_start + msix_table->size;
-		table_end = (table_end + ~PAGE_MASK) & PAGE_MASK;
-		table_start &= PAGE_MASK;
-
-		if (table_start == 0 && table_end >= bar->size) {
-			/* Cannot map this BAR */
-			RTE_LOG(DEBUG, EAL, "Skipping BAR%d\n", bar_index);
-			bar->size = 0;
-			bar->addr = 0;
-			return 0;
-		}
-
-		memreg[0].offset = bar->offset;
-		memreg[0].size = table_start;
-		memreg[1].offset = bar->offset + table_end;
-		memreg[1].size = bar->size - table_end;
-
-		RTE_LOG(DEBUG, EAL,
-			"Trying to map BAR%d that contains the MSI-X "
-			"table. Trying offsets: "
-			"0x%04lx:0x%04lx, 0x%04lx:0x%04lx\n", bar_index,
-			memreg[0].offset, memreg[0].size,
-			memreg[1].offset, memreg[1].size);
-	} else {
-		memreg[0].offset = bar->offset;
-		memreg[0].size = bar->size;
-	}
-
 	/* reserve the address using an inaccessible mapping */
 	bar_addr = mmap(bar->addr, bar->size, 0, MAP_PRIVATE |
 			MAP_ANONYMOUS | additional_flags, -1, 0);
-	if (bar_addr != MAP_FAILED) {
+	if (bar_addr == MAP_FAILED) {
+		RTE_LOG(ERR, EAL,
+			"Failed to create inaccessible mapping for BAR%d\n",
+			bar_index);
+		return -1;
+	}
+
+	memreg[0].offset = bar->offset;
+	memreg[0].size = bar->size;
+	do {
 		void *map_addr = NULL;
+		if (again) {
+			/*
+			 * VFIO did not let us map the MSI-X table,
+			 * but we can map around it.
+			 */
+			uint32_t table_start = msix_table->offset;
+			uint32_t table_end = table_start + msix_table->size;
+			table_end = (table_end + ~PAGE_MASK) & PAGE_MASK;
+			table_start &= PAGE_MASK;
+
+			if (table_start == 0 && table_end >= bar->size) {
+				/* Cannot map this BAR */
+				RTE_LOG(DEBUG, EAL, "Skipping BAR%d\n",
+						bar_index);
+				munmap(bar_addr, bar->size);
+				bar->size = 0;
+				bar->addr = 0;
+				return 0;
+			}
+
+			memreg[0].offset = bar->offset;
+			memreg[0].size = table_start;
+			memreg[1].offset = bar->offset + table_end;
+			memreg[1].size = bar->size - table_end;
+
+			RTE_LOG(DEBUG, EAL,
+				"Trying to map BAR%d that contains the MSI-X "
+				"table. Trying offsets: "
+				"0x%04lx:0x%04lx, 0x%04lx:0x%04lx\n", bar_index,
+				memreg[0].offset, memreg[0].size,
+				memreg[1].offset, memreg[1].size);
+		}
+
 		if (memreg[0].size) {
 			/* actual map of first part */
 			map_addr = pci_map_resource(bar_addr, vfio_dev_fd,
 							memreg[0].offset,
 							memreg[0].size,
 							MAP_FIXED);
+		}
+
+		if (map_addr == MAP_FAILED &&
+			msix_table->bar_index == bar_index && !again) {
+			again = true;
+			continue;
 		}

 		/* if there's a second part, try to map it */
@@ -404,12 +419,8 @@
 					bar_index);
 			return -1;
 		}
-	} else {
-		RTE_LOG(ERR, EAL,
-				"Failed to create inaccessible mapping for BAR%d\n",
-				bar_index);
-		return -1;
-	}
+		break;
+	} while (again);

 	bar->addr = bar_addr;
 	return 0;


[WATCHDOG] Mixcom Watchdog - checkcard

[WATCHDOG] Mixcom Watchdog - checkcard

Simplify the mixcomwd_checkcard and flashcom_checkcard
functions to one checkcard function as part of the
port to an isa watchdog device driver.

Signed-off-by: Wim Van Sebroeck <5f65f6985de1ebf15dde04e0dc4668211868bafa@iguana.be>

--- drivers/char/watchdog/mixcomwd.c
+++ drivers/char/watchdog/mixcomwd.c
@@ -217,7 +217,7 @@
 	.fops	= &mixcomwd_fops,
 };

-static int __init mixcomwd_checkcard(int port)
+static int __init checkcard(int port, int card_id)
 {
 	int id;

@@ -225,29 +225,16 @@
 		return 0;
 	}

-	id=inb_p(port) & 0x3f;
-	if(id!=MIXCOM_ID) {
+	id=inb_p(port);
+	if (card_id==MIXCOM_ID)
+		id &= 0x3f;
+
+	if (id!=card_id) {
 		release_region(port, 1);
 		return 0;
 	}
-	return port;
-}
-
-static int __init flashcom_checkcard(int port)
-{
-	int id;
-
-	if (!request_region(port, 1, "MixCOM watchdog")) {
-		return 0;
-	}
-
-	id=inb_p(port);
- 	if(id!=FLASHCOM_ID) {
-		release_region(port, 1);
-		return 0;
-	}
- 	return port;
- }
+	return 1;
+}

 static int __init mixcomwd_init(void)
 {
@@ -256,17 +243,17 @@
 	int found=0;

 	for (i = 0; !found && mixcomwd_ioports[i] != 0; i++) {
-		watchdog_port = mixcomwd_checkcard(mixcomwd_ioports[i]);
-		if (watchdog_port) {
+		if (checkcard(mixcomwd_ioports[i], MIXCOM_ID)) {
 			found = 1;
+			watchdog_port = mixcomwd_ioports[i];
 		}
 	}

 	/* The FlashCOM card can be set up at 0x304 -> 0x37c, in 0x8 jumps */
 	for (i = 0x304; !found && i < 0x380; i+=0x8) {
-		watchdog_port = flashcom_checkcard(i);
-		if (watchdog_port) {
+		if (checkcard(i, FLASHCOM_ID)) {
 			found = 1;
+			watchdog_port = i;
 		}
 	}


cpufreq: at32ap: Use generic cpufreq routines

Most of the CPUFreq drivers do similar things in .exit() and .verify() routines
and .attr. So its better if we have generic routines for them which can be used
by cpufreq drivers then.

This patch uses these generic routines in the at32ap driver.

Acked-by: Hans-Christian Egtvedt <11ce19a6fc3bb47abce595a29a6ea4cfed5efa4c@samfundet.no>
Signed-off-by: Viresh Kumar <5ff32272b3d9f86512eddc8e0af523fc6f7924e5@linaro.org>
Signed-off-by: Rafael J. Wysocki <27ffc44a8ec6a212fba98cfc3246c6ce8ab131e0@intel.com>

--- drivers/cpufreq/at32ap-cpufreq.c
+++ drivers/cpufreq/at32ap-cpufreq.c
@@ -23,16 +23,6 @@

 static struct clk *cpuclk;
 static struct cpufreq_frequency_table *freq_table;
-
-static int at32_verify_speed(struct cpufreq_policy *policy)
-{
-	if (policy->cpu != 0)
-		return -EINVAL;
-
-	cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
-			policy->cpuinfo.max_freq);
-	return 0;
-}

 static unsigned int at32_get_speed(unsigned int cpu)
 {
@@ -152,7 +142,7 @@
 static struct cpufreq_driver at32_driver = {
 	.name		= "at32ap",
 	.init		= at32_cpufreq_driver_init,
-	.verify		= at32_verify_speed,
+	.verify		= cpufreq_generic_frequency_table_verify,
 	.target		= at32_set_target,
 	.get		= at32_get_speed,
 	.flags		= CPUFREQ_STICKY,


drivers: eeprom: add missing include to nxp eeprom driver

The include <zephyr/kernel.h> is missing from eeprom driver,
causing build error. This is fixing it like PR # 51246 or #51220.

Signed-off-by: Francois Ramu <b83adc7f8a23ee911a37fcb61c4033581aae0b7a@st.com>

--- drivers/eeprom/eeprom_lpc11u6x.c
+++ drivers/eeprom/eeprom_lpc11u6x.c
@@ -16,6 +16,7 @@
  *       EEPROM functions.
  */

+#include <zephyr/kernel.h>
 #include <zephyr/drivers/eeprom.h>
 #include <iap.h>


Do not unlock cs_main in ABC unless we've actually made progress.

Technically, some internal datastructures may be in an inconsistent
state if we do this, though there are no known bugs there. Still,
for future safety, its much better to only unlock cs_main if we've
made progress (not just tried a reorg which may make progress).

--- src/validationinterface.h
+++ src/validationinterface.h
@@ -61,7 +61,11 @@
      */
     ~CValidationInterface() = default;
     /**
-     * Notifies listeners of updated block chain tip
+     * Notifies listeners when the block chain tip advances.
+     *
+     * When multiple blocks are connected at once, UpdatedBlockTip will be called on the final tip
+     * but may not be called on every intermediate tip. If the latter behavior is desired,
+     * subscribe to BlockConnected() instead.
      *
      * Called on a background thread.
      */


drm/i915: Remove duplicated psr.active unset

psr.active is being unset out of the if so this here is useless and
duplicated.

Signed-off-by: Rodrigo Vivi <f714145d6ee82178e54021e0c168f56d17b53c9c@intel.com>
Signed-off-by: Daniel Vetter <c1b6782c4af8f0673da8923a0702a1832e5940f4@ffwll.ch>

--- drivers/gpu/drm/i915/intel_psr.c
+++ drivers/gpu/drm/i915/intel_psr.c
@@ -532,8 +532,6 @@
 		WARN_ON(!(val & EDP_PSR_ENABLE));

 		I915_WRITE(EDP_PSR_CTL(dev), val & ~EDP_PSR_ENABLE);
-
-		dev_priv->psr.active = false;
 	} else {
 		val = I915_READ(VLV_PSRCTL(pipe));


msm: kgsl: Return NULL when done parsing the profiler assignments string

The assignment string parser has a corner condition wherein the user
can craft a malicious string that contains a \0 and force a buffer
overrun.  Avoid this by always returning NULL when the parser encounters
a \0.

CRs-fixed: 547601
Change-Id: Ic0dedbad946e597a5a245df41239b89f114ba9ee
Signed-off-by: Jordan Crouse <fec53db8c4887e6e95defbb5052bc6438029c1e6@codeaurora.org>

--- drivers/gpu/msm/adreno_profile.c
+++ drivers/gpu/msm/adreno_profile.c
@@ -597,7 +597,7 @@
 static char *_parse_next_assignment(struct adreno_device *adreno_dev,
 		char *str, int *groupid, int *countable, bool *remove)
 {
-	char *groupid_str, *countable_str;
+	char *groupid_str, *countable_str, *next_str = NULL;
 	int ret;

 	*groupid = -EINVAL;
@@ -635,8 +635,15 @@
 	if (countable_str == str)
 		return NULL;

-	*str = '\0';
-	str++;
+	/*
+	 * If we have reached the end of the original string then make sure we
+	 * return NULL from this function or we could accidently overrun
+	 */
+
+	if (*str != '\0') {
+		*str = '\0';
+		next_str = str + 1;
+	}

 	/* set results */
 	*groupid = adreno_perfcounter_get_groupid(adreno_dev,
@@ -647,7 +654,7 @@
 	if (ret)
 		return NULL;

-	return str;
+	return next_str;
 }

 static ssize_t profile_assignments_write(struct file *filep,


hwmon: (pmbus) Use krealloc to allocate attribute memory

So far, attribute memory was allocated by pre-calculating the maximum possible
amount of attributes. Not only does this waste memory, it is also risky because
the calculation might be wrong. It also requires a lot of defines to specify
the maximum number of attributes per class.

Allocate attribute memory using krealloc() instead. That means we have to use
kfree(), since devm_krealloc() does not exist, but that is still less costly
and less risky than trying to predict the number of attributes at the beginning.

Signed-off-by: Guenter Roeck <ba324ca7b1c77fc20bb970d5aff6eea9377918a5@roeck-us.net>

--- drivers/hwmon/pmbus/pmbus_core.c
+++ drivers/hwmon/pmbus/pmbus_core.c
@@ -31,39 +31,10 @@
 #include "pmbus.h"

 /*
- * Constants needed to determine number of sensors, booleans, and labels.
+ * Number of additional attribute pointers to allocate
+ * with each call to krealloc
  */
-#define PMBUS_MAX_INPUT_SENSORS		22	/* 10*volt, 7*curr, 5*power */
-#define PMBUS_VOUT_SENSORS_PER_PAGE	9	/* input, min, max, lcrit,
-						   crit, lowest, highest, avg,
-						   reset */
-#define PMBUS_IOUT_SENSORS_PER_PAGE	8	/* input, min, max, crit,
-						   lowest, highest, avg,
-						   reset */
-#define PMBUS_POUT_SENSORS_PER_PAGE	7	/* input, cap, max, crit,
-						 * highest, avg, reset
-						 */
-#define PMBUS_MAX_SENSORS_PER_FAN	1	/* input */
-#define PMBUS_MAX_SENSORS_PER_TEMP	9	/* input, min, max, lcrit,
-						 * crit, lowest, highest, avg,
-						 * reset
-						 */
-
-#define PMBUS_MAX_INPUT_BOOLEANS	7	/* v: min_alarm, max_alarm,
-						   lcrit_alarm, crit_alarm;
-						   c: alarm, crit_alarm;
-						   p: crit_alarm */
-#define PMBUS_VOUT_BOOLEANS_PER_PAGE	4	/* min_alarm, max_alarm,
-						   lcrit_alarm, crit_alarm */
-#define PMBUS_IOUT_BOOLEANS_PER_PAGE	3	/* alarm, lcrit_alarm,
-						   crit_alarm */
-#define PMBUS_POUT_BOOLEANS_PER_PAGE	3	/* cap_alarm, alarm, crit_alarm
-						 */
-#define PMBUS_MAX_BOOLEANS_PER_FAN	2	/* alarm, fault */
-#define PMBUS_MAX_BOOLEANS_PER_TEMP	4	/* min_alarm, max_alarm,
-						   lcrit_alarm, crit_alarm */
-
-#define PMBUS_MAX_INPUT_LABELS		4	/* vin, vcap, iin, pin */
+#define PMBUS_ATTR_ALLOC_SIZE	32

 /*
  * status, status_vout, status_iout, status_fans, status_fan34, and status_temp
@@ -127,7 +98,6 @@

 	int max_attributes;
 	int num_attributes;
-	struct attribute **attributes;
 	struct attribute_group group;

 	struct pmbus_sensor *sensors;
@@ -790,6 +760,22 @@
 	return snprintf(buf, PAGE_SIZE, "%s\n", label->label);
 }

+static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
+{
+	if (data->num_attributes >= data->max_attributes - 1) {
+		data->max_attributes += PMBUS_ATTR_ALLOC_SIZE;
+		data->group.attrs = krealloc(data->group.attrs,
+					     sizeof(struct attribute *) *
+					     data->max_attributes, GFP_KERNEL);
+		if (data->group.attrs == NULL)
+			return -ENOMEM;
+	}
+
+	data->group.attrs[data->num_attributes++] = attr;
+	data->group.attrs[data->num_attributes] = NULL;
+	return 0;
+}
+
 static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
 				const char *name,
 				umode_t mode,
@@ -831,8 +817,6 @@
 	struct pmbus_boolean *boolean;
 	struct sensor_device_attribute *a;

-	BUG_ON(data->num_attributes >= data->max_attributes);
-
 	boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
 	if (!boolean)
 		return -ENOMEM;
@@ -845,9 +829,8 @@
 	boolean->s2 = s2;
 	pmbus_attr_init(a, boolean->name, S_IRUGO, pmbus_show_boolean, NULL,
 			(reg << 8) | mask);
-	data->attributes[data->num_attributes++] = &a->dev_attr.attr;
-
-	return 0;
+
+	return pmbus_add_attribute(data, &a->dev_attr.attr);
 }

 static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
@@ -858,8 +841,6 @@
 {
 	struct pmbus_sensor *sensor;
 	struct device_attribute *a;
-
-	BUG_ON(data->num_attributes >= data->max_attributes);

 	sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
 	if (!sensor)
@@ -876,7 +857,9 @@
 			    readonly ? S_IRUGO : S_IRUGO | S_IWUSR,
 			    pmbus_show_sensor, pmbus_set_sensor);

-	data->attributes[data->num_attributes++] = &a->attr;
+	if (pmbus_add_attribute(data, &a->attr))
+		return NULL;
+
 	sensor->next = data->sensors;
 	data->sensors = sensor;

@@ -889,8 +872,6 @@
 {
 	struct pmbus_label *label;
 	struct device_attribute *a;
-
-	BUG_ON(data->num_attributes >= data->max_attributes);

 	label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
 	if (!label)
@@ -906,62 +887,7 @@
 			 index);

 	pmbus_dev_attr_init(a, label->name, S_IRUGO, pmbus_show_label, NULL);
-	data->attributes[data->num_attributes++] = &a->attr;
-	return 0;
-}
-
-/*
- * Determine maximum number of sensors, booleans, and labels.
- * To keep things simple, only make a rough high estimate.
- */
-static void pmbus_find_max_attr(struct i2c_client *client,
-				struct pmbus_data *data)
-{
-	const struct pmbus_driver_info *info = data->info;
-	int page, max_sensors, max_booleans, max_labels;
-
-	max_sensors = PMBUS_MAX_INPUT_SENSORS;
-	max_booleans = PMBUS_MAX_INPUT_BOOLEANS;
-	max_labels = PMBUS_MAX_INPUT_LABELS;
-
-	for (page = 0; page < info->pages; page++) {
-		if (info->func[page] & PMBUS_HAVE_VOUT) {
-			max_sensors += PMBUS_VOUT_SENSORS_PER_PAGE;
-			max_booleans += PMBUS_VOUT_BOOLEANS_PER_PAGE;
-			max_labels++;
-		}
-		if (info->func[page] & PMBUS_HAVE_IOUT) {
-			max_sensors += PMBUS_IOUT_SENSORS_PER_PAGE;
-			max_booleans += PMBUS_IOUT_BOOLEANS_PER_PAGE;
-			max_labels++;
-		}
-		if (info->func[page] & PMBUS_HAVE_POUT) {
-			max_sensors += PMBUS_POUT_SENSORS_PER_PAGE;
-			max_booleans += PMBUS_POUT_BOOLEANS_PER_PAGE;
-			max_labels++;
-		}
-		if (info->func[page] & PMBUS_HAVE_FAN12) {
-			max_sensors += 2 * PMBUS_MAX_SENSORS_PER_FAN;
-			max_booleans += 2 * PMBUS_MAX_BOOLEANS_PER_FAN;
-		}
-		if (info->func[page] & PMBUS_HAVE_FAN34) {
-			max_sensors += 2 * PMBUS_MAX_SENSORS_PER_FAN;
-			max_booleans += 2 * PMBUS_MAX_BOOLEANS_PER_FAN;
-		}
-		if (info->func[page] & PMBUS_HAVE_TEMP) {
-			max_sensors += PMBUS_MAX_SENSORS_PER_TEMP;
-			max_booleans += PMBUS_MAX_BOOLEANS_PER_TEMP;
-		}
-		if (info->func[page] & PMBUS_HAVE_TEMP2) {
-			max_sensors += PMBUS_MAX_SENSORS_PER_TEMP;
-			max_booleans += PMBUS_MAX_BOOLEANS_PER_TEMP;
-		}
-		if (info->func[page] & PMBUS_HAVE_TEMP3) {
-			max_sensors += PMBUS_MAX_SENSORS_PER_TEMP;
-			max_booleans += PMBUS_MAX_BOOLEANS_PER_TEMP;
-		}
-	}
-	data->max_attributes = max_sensors + max_booleans + max_labels;
+	return pmbus_add_attribute(data, &a->attr);
 }

 /*
@@ -1709,8 +1635,6 @@
 		}
 	}

-	/* Determine maximum number of sensors, booleans, and labels */
-	pmbus_find_max_attr(client, data);
 	pmbus_clear_fault_page(client, 0);
 	return 0;
 }
@@ -1770,14 +1694,9 @@
 		return ret;
 	}

-	data->attributes = devm_kzalloc(dev, sizeof(struct attribute *)
-					* data->max_attributes, GFP_KERNEL);
-	if (!data->attributes)
-		return -ENOMEM;
-
 	ret = pmbus_find_attributes(client, data);
 	if (ret)
-		return ret;
+		goto out_kfree;

 	/*
 	 * If there are no attributes, something is wrong.
@@ -1785,15 +1704,15 @@
 	 */
 	if (!data->num_attributes) {
 		dev_err(dev, "No attributes found\n");
-		return -ENODEV;
+		ret = -ENODEV;
+		goto out_kfree;
 	}

 	/* Register sysfs hooks */
-	data->group.attrs = data->attributes;
 	ret = sysfs_create_group(&dev->kobj, &data->group);
 	if (ret) {
 		dev_err(dev, "Failed to create sysfs entries\n");
-		return ret;
+		goto out_kfree;
 	}
 	data->hwmon_dev = hwmon_device_register(dev);
 	if (IS_ERR(data->hwmon_dev)) {
@@ -1805,6 +1724,8 @@

 out_hwmon_device_register:
 	sysfs_remove_group(&dev->kobj, &data->group);
+out_kfree:
+	kfree(data->group.attrs);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(pmbus_do_probe);
@@ -1814,6 +1735,7 @@
 	struct pmbus_data *data = i2c_get_clientdata(client);
 	hwmon_device_unregister(data->hwmon_dev);
 	sysfs_remove_group(&client->dev.kobj, &data->group);
+	kfree(data->group.attrs);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(pmbus_do_remove);


grn_accessor_resolve_one_data_column_index: reuse index cursor

It's for performance.

--- lib/accessor.c
+++ lib/accessor.c
@@ -312,6 +312,27 @@
   {
     grn_rc rc = GRN_SUCCESS;
     grn_obj *index_column = index_datum->index;
+    grn_obj *index_cursor = grn_index_cursor_open(ctx,
+                                                  NULL,
+                                                  index_column,
+                                                  GRN_ID_NIL,
+                                                  GRN_ID_MAX,
+                                                  0);
+    if (!index_cursor) {
+      grn_obj_unlink(ctx, *next_res);
+      return ctx->rc;
+    }
+    if (index_datum->section > 0) {
+      rc = grn_index_cursor_set_section_id(ctx,
+                                           index_cursor,
+                                           index_datum->section);
+    }
+    if (rc != GRN_SUCCESS) {
+      grn_obj_close(ctx, index_cursor);
+      grn_obj_unlink(ctx, *next_res);
+      return ctx->rc;
+    }
+
     GRN_HASH_EACH_BEGIN(ctx, (grn_hash *)current_res, cursor, id) {
       void *key;
       void *value;
@@ -320,22 +341,7 @@
       grn_id *term_id = key;
       grn_rset_recinfo *recinfo = value;

-      grn_obj *index_cursor = grn_index_cursor_open(ctx,
-                                                    NULL,
-                                                    index_column,
-                                                    GRN_ID_NIL,
-                                                    GRN_ID_MAX,
-                                                    0);
-      if (!index_cursor) {
-        continue;
-      }
-
       rc = grn_index_cursor_set_term_id(ctx, index_cursor, *term_id);
-      if (rc == GRN_SUCCESS && index_datum->section > 0) {
-        rc = grn_index_cursor_set_section_id(ctx,
-                                             index_cursor,
-                                             index_datum->section);
-      }
       if (rc == GRN_SUCCESS) {
         rc = grn_result_set_add_index_cursor(ctx,
                                              (grn_hash *)(*next_res),
@@ -344,12 +350,12 @@
                                              1,
                                              GRN_OP_OR);
       }
-      grn_obj_close(ctx, index_cursor);

       if (rc != GRN_SUCCESS) {
         break;
       }
     } GRN_HASH_EACH_END(ctx, cursor);
+    grn_obj_close(ctx, index_cursor);

     if (rc != GRN_SUCCESS) {
       grn_obj_unlink(ctx, *next_res);


[media] gspca_kinect: add Kinect for Windows USB id

Add the USB ID for the Kinect for Windows RGB camera so it can be used
with the gspca_kinect driver.

Signed-off-by: Jacob Schloss <e45444a92a5e876dabde137da13a623b60d8a3a6@unlimitedautomata.com>
Signed-off-by: Antonio Ospite <93db7fe24fb098f485b7d1c7a8e9771e73894a26@studenti.unina.it>
Signed-off-by: Hans de Goede <9fa1be1a5b5729e4c6b404f34c9ce49ff4882fd8@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <ad86ba2154032c9f55743a190faa2459a9d61d42@redhat.com>

--- drivers/media/usb/gspca/kinect.c
+++ drivers/media/usb/gspca/kinect.c
@@ -381,6 +381,7 @@
 /* -- module initialisation -- */
 static const struct usb_device_id device_table[] = {
 	{USB_DEVICE(0x045e, 0x02ae)},
+	{USB_DEVICE(0x045e, 0x02bf)},
 	{}
 };


can: kvaser_usb: add retries/timeout to kvaser_usb_wait_msg()

On some Kvaser hardware, the firmware returns extra messages after the
request for card info. For instance on a Leaf Light v2:
  --> CMD_GET_CARD_INFO
  <-- CMD_USB_THROTTLE
  <-- CMD_GET_CARD_INFO2
  <-- CMD_GET_CARD_INFO_REQ
When it happens, the probing function fails because we only read
the first usb message.

To overcome this issue, we add a mechanism of retries to the
kvaser_usb_wait_msg() function.

I tested this patch with the following hardware:
 - Kvaser Leaf Light
 - Kvaser Leaf Light v2
 - Kvaser USBCan R

This patch is necessary for the Leaf Light v2 hardware.

Signed-off-by: Olivier Sobrie <77cccf0d7a72ee0036f6f1a239d5c47ee8799014@sobrie.be>
Signed-off-by: Marc Kleine-Budde <4a0ea1158d3cc63151119c05b1bff00c0bdbf421@pengutronix.de>

--- drivers/net/can/usb/kvaser_usb.c
+++ drivers/net/can/usb/kvaser_usb.c
@@ -379,38 +379,43 @@
 	void *buf;
 	int actual_len;
 	int err;
-	int pos = 0;
+	int pos;
+	unsigned long to = jiffies + msecs_to_jiffies(USB_RECV_TIMEOUT);

 	buf = kzalloc(RX_BUFFER_SIZE, GFP_KERNEL);
 	if (!buf)
 		return -ENOMEM;

-	err = usb_bulk_msg(dev->udev,
-			   usb_rcvbulkpipe(dev->udev,
-					   dev->bulk_in->bEndpointAddress),
-			   buf, RX_BUFFER_SIZE, &actual_len,
-			   USB_RECV_TIMEOUT);
-	if (err < 0)
-		goto end;
-
-	while (pos <= actual_len - MSG_HEADER_LEN) {
-		tmp = buf + pos;
-
-		if (!tmp->len)
-			break;
-
-		if (pos + tmp->len > actual_len) {
-			dev_err(dev->udev->dev.parent, "Format error\n");
-			break;
+	do {
+		err = usb_bulk_msg(dev->udev,
+				   usb_rcvbulkpipe(dev->udev,
+					dev->bulk_in->bEndpointAddress),
+				   buf, RX_BUFFER_SIZE, &actual_len,
+				   USB_RECV_TIMEOUT);
+		if (err < 0)
+			goto end;
+
+		pos = 0;
+		while (pos <= actual_len - MSG_HEADER_LEN) {
+			tmp = buf + pos;
+
+			if (!tmp->len)
+				break;
+
+			if (pos + tmp->len > actual_len) {
+				dev_err(dev->udev->dev.parent,
+					"Format error\n");
+				break;
+			}
+
+			if (tmp->id == id) {
+				memcpy(msg, tmp, tmp->len);
+				goto end;
+			}
+
+			pos += tmp->len;
 		}
-
-		if (tmp->id == id) {
-			memcpy(msg, tmp, tmp->len);
-			goto end;
-		}
-
-		pos += tmp->len;
-	}
+	} while (time_before(jiffies, to));

 	err = -EINVAL;