Description: Updates from upstream's 5.x release branch
 Up to and including 83410:b5d52a043b5e
Origin: upstream, https://bitbucket.org/pypy/pypy/branch/release-5.x

--- a/rpython/jit/backend/llsupport/gc.py
+++ b/rpython/jit/backend/llsupport/gc.py
@@ -164,13 +164,11 @@
             array_index = moving_obj_tracker.get_array_index(v)
 
             size, offset, _ = unpack_arraydescr(moving_obj_tracker.ptr_array_descr)
-            scale = size
+            array_index = array_index * size + offset
             args = [moving_obj_tracker.const_ptr_gcref_array,
                     ConstInt(array_index),
-                    ConstInt(scale),
-                    ConstInt(offset),
                     ConstInt(size)]
-            load_op = ResOperation(rop.GC_LOAD_INDEXED_R, args)
+            load_op = ResOperation(rop.GC_LOAD_R, args)
             newops.append(load_op)
             op.setarg(arg_i, load_op)
         #
--- a/rpython/rlib/rvmprof/src/vmprof_config.h
+++ b/rpython/rlib/rvmprof/src/vmprof_config.h
@@ -1,5 +1,11 @@
 #define HAVE_SYS_UCONTEXT_H
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#if defined(__i386__)
+#define PC_FROM_UCONTEXT uc_mcontext.mc_eip
+#else
+#define PC_FROM_UCONTEXT uc_mcontext.mc_rip
+#endif
+#elif defined(__APPLE__)
 #define PC_FROM_UCONTEXT uc_mcontext.mc_rip
 #else
 #define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP]
--- a/rpython/translator/c/src/thread.h
+++ b/rpython/translator/c/src/thread.h
@@ -42,13 +42,13 @@
 RPY_EXTERN long rpy_fastgil;
 
 static inline void _RPyGilAcquire(void) {
-    long old_fastgil = lock_test_and_set(&rpy_fastgil, 1);
+    long old_fastgil = pypy_lock_test_and_set(&rpy_fastgil, 1);
     if (old_fastgil != 0)
         RPyGilAcquireSlowPath(old_fastgil);
 }
 static inline void _RPyGilRelease(void) {
     assert(RPY_FASTGIL_LOCKED(rpy_fastgil));
-    lock_release(&rpy_fastgil);
+    pypy_lock_release(&rpy_fastgil);
 }
 static inline long *_RPyFetchFastGil(void) {
     return &rpy_fastgil;
--- a/rpython/translator/c/src/thread_gil.c
+++ b/rpython/translator/c/src/thread_gil.c
@@ -70,7 +70,7 @@
 {
     /* Acquires the GIL.  This assumes that we already did:
 
-          old_fastgil = lock_test_and_set(&rpy_fastgil, 1);
+          old_fastgil = pypy_lock_test_and_set(&rpy_fastgil, 1);
      */
     if (!RPY_FASTGIL_LOCKED(old_fastgil)) {
         /* The fastgil was not previously locked: success.
@@ -122,7 +122,7 @@
                released.
             */
             if (!RPY_FASTGIL_LOCKED(rpy_fastgil)) {
-                old_fastgil = lock_test_and_set(&rpy_fastgil, 1);
+                old_fastgil = pypy_lock_test_and_set(&rpy_fastgil, 1);
                 if (!RPY_FASTGIL_LOCKED(old_fastgil))
                     /* yes, got a non-held value!  Now we hold it. */
                     break;
--- a/rpython/translator/c/src/thread_nt.c
+++ b/rpython/translator/c/src/thread_nt.c
@@ -245,7 +245,7 @@
     LeaveCriticalSection(mutex);
 }
 
-//#define lock_test_and_set(ptr, value)  see thread_nt.h
+//#define pypy_lock_test_and_set(ptr, value)  see thread_nt.h
 #define atomic_increment(ptr)          InterlockedIncrement(ptr)
 #define atomic_decrement(ptr)          InterlockedDecrement(ptr)
 
--- a/rpython/translator/c/src/thread_nt.h
+++ b/rpython/translator/c/src/thread_nt.h
@@ -34,8 +34,8 @@
 
 #ifdef _M_IA64
 /* On Itanium, use 'acquire' memory ordering semantics */
-#define lock_test_and_set(ptr, value)  InterlockedExchangeAcquire(ptr, value)
+#define pypy_lock_test_and_set(ptr, value) InterlockedExchangeAcquire(ptr,value)
 #else
-#define lock_test_and_set(ptr, value)  InterlockedExchange(ptr, value)
+#define pypy_lock_test_and_set(ptr, value) InterlockedExchange(ptr, value)
 #endif
-#define lock_release(ptr)              (*((volatile long *)ptr) = 0)
+#define pypy_lock_release(ptr)             (*((volatile long *)ptr) = 0)
--- a/rpython/translator/c/src/thread_pthread.c
+++ b/rpython/translator/c/src/thread_pthread.c
@@ -546,7 +546,7 @@
     return result;
 }
 
-//#define lock_test_and_set(ptr, value)  see thread_pthread.h
+//#define pypy_lock_test_and_set(ptr, value)  see thread_pthread.h
 #define atomic_increment(ptr)          __sync_fetch_and_add(ptr, 1)
 #define atomic_decrement(ptr)          __sync_fetch_and_sub(ptr, 1)
 #define HAVE_PTHREAD_ATFORK            1
--- a/rpython/translator/c/src/thread_pthread.h
+++ b/rpython/translator/c/src/thread_pthread.h
@@ -80,5 +80,5 @@
 void RPyThreadAfterFork(void);
 
 
-#define lock_test_and_set(ptr, value)  __sync_lock_test_and_set(ptr, value)
-#define lock_release(ptr)              __sync_lock_release(ptr)
+#define pypy_lock_test_and_set(ptr, value)  __sync_lock_test_and_set(ptr, value)
+#define pypy_lock_release(ptr)              __sync_lock_release(ptr)
--- a/rpython/translator/c/src/threadlocal.c
+++ b/rpython/translator/c/src/threadlocal.c
@@ -15,14 +15,14 @@
 static int check_valid(void);
 
 void _RPython_ThreadLocals_Acquire(void) {
-    while (!lock_test_and_set(&pypy_threadlocal_lock, 1)) {
+    while (!pypy_lock_test_and_set(&pypy_threadlocal_lock, 1)) {
         /* busy loop */
     }
     assert(check_valid());
 }
 void _RPython_ThreadLocals_Release(void) {
     assert(check_valid());
-    lock_release(&pypy_threadlocal_lock);
+    pypy_lock_release(&pypy_threadlocal_lock);
 }
 
 
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -827,7 +827,7 @@
         lltype.free(status_p, flavor='raw')
 
 def _make_waitmacro(name):
-    c_func = external(name, [lltype.Signed], lltype.Signed,
+    c_func = external(name, [rffi.INT], lltype.Signed,
                       macro=_MACRO_ON_POSIX)
     returning_int = name in ('WEXITSTATUS', 'WSTOPSIG', 'WTERMSIG')
 
