[pypy-commit] pypy stmgc-c7: A better attempt at fixing 31386d1544cb

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: stmgc-c7
Changeset: r70273:0f519ccd4e65
Date: 2014-03-25 08:55 +0100
http://bitbucket.org/pypy/pypy/changeset/0f519ccd4e65/

Log:A better attempt at fixing 31386d1544cb

diff --git a/rpython/jit/backend/x86/arch.py b/rpython/jit/backend/x86/arch.py
--- a/rpython/jit/backend/x86/arch.py
+++ b/rpython/jit/backend/x86/arch.py
@@ -54,10 +54,10 @@
 # meaningful.  We use ebp, i.e. the word at offset +0, to store the
 # resume counter.
 
-STM_RESUME_BUF_WORDS  = 4 # -- for alignment, it can't be 3
+STM_RESUME_BUF_WORDS  = 4
 STM_FRAME_FIXED_SIZE  = FRAME_FIXED_SIZE + STM_RESUME_BUF_WORDS
 STM_JMPBUF_OFS= WORD * FRAME_FIXED_SIZE
 STM_JMPBUF_OFS_RBP= STM_JMPBUF_OFS + 0 * WORD
 STM_JMPBUF_OFS_RIP= STM_JMPBUF_OFS + 1 * WORD
 STM_JMPBUF_OFS_RSP= STM_JMPBUF_OFS + 2 * WORD
-# unused:   STM_JMPBUF_OFS + 3 * WORD
+STM_OLD_SHADOWSTACK   = STM_JMPBUF_OFS + 3 * WORD
diff --git a/rpython/jit/backend/x86/assembler.py 
b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -19,7 +19,8 @@
 from rpython.jit.backend.x86.arch import (
 FRAME_FIXED_SIZE, WORD, IS_X86_64, JITFRAME_FIXED_SIZE, IS_X86_32,
 PASS_ON_MY_FRAME, STM_FRAME_FIXED_SIZE, STM_JMPBUF_OFS,
-STM_JMPBUF_OFS_RIP, STM_JMPBUF_OFS_RSP, STM_JMPBUF_OFS_RBP)
+STM_JMPBUF_OFS_RIP, STM_JMPBUF_OFS_RSP, STM_JMPBUF_OFS_RBP,
+STM_OLD_SHADOWSTACK)
 from rpython.jit.backend.x86.regloc import (eax, ecx, edx, ebx, esp, ebp, esi,
 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, r8, r9, r10, r11, edi,
 r12, r13, r14, r15, X86_64_SCRATCH_REG, X86_64_XMM_SCRATCH_REG,
@@ -158,11 +159,17 @@
 gcrootmap = self.cpu.gc_ll_descr.gcrootmap
 if gcrootmap and gcrootmap.is_shadow_stack:
 mc.MOV(ebx, self.heap_shadowstack_top())
+if self.cpu.gc_ll_descr.stm:
+# STM: there is a restriction on updating the shadowstack
+# in-place: never put young objects below what is the
+# transaction start's shadowstack position!  As we might
+# have started a transction in the same frame with the
+# same value of shadowstack as now, we have nowhere to put
+# this new young jitframe object -- so we have to PUSH it.
+mc.ADD_ri(ebx.value, WORD)
+mc.MOV(self.heap_shadowstack_top(), ebx)
+#
 mc.MOV_mr((self.SEGMENT_NO, ebx.value, -WORD), eax.value)
-# STM note: this stores the updated jitframe object in the
-# position -WORD, but (in this case) leaves the position
-# -2*WORD untouched.  This old jitframe object remains in
-# the shadowstack just in case we do an abort later.
 
 mc.MOV_bi((self.SEGMENT_FRAME, gcmap_ofs), 0)
 self._pop_all_regs_from_frame(mc, [], self.cpu.supports_floats)
@@ -804,10 +811,8 @@
 # to this frame, because we're about to leave.  This is if
 # we called a pypy_stm_start_transaction() earlier.
 assert IS_X86_64
+mc = self.mc
 #
-# load the shadowstack pointer into ebx (a callee-saved register)
-mc = self.mc
-mc.MOV(ebx, self.heap_shadowstack_top())
 # load the address of the jmpbuf
 mc.LEA_rs(edi.value, STM_JMPBUF_OFS)
 # compare it with the currently-stored jmpbuf
@@ -820,20 +825,17 @@
 mc.MOV_ri(edi.value, rstm.adr_jit_default_msg)
 mc.CALL(imm(rstm.adr__stm_become_inevitable))
 # there could have been a collection in _stm_become_inevitable;
-# reload the frame into ebp
-mc.MOV_rm(ebp.value, (self.SEGMENT_NO, ebx.value, -WORD))
+# reload the frame into ebp (but we don't need to apply the
+# write barrier to it now)
+mc.MOV(ecx, self.heap_shadowstack_top())
+mc.MOV_rm(ebp.value, (self.SEGMENT_NO, ecx.value, -WORD))
 #
 # this is where the JNE above jumps
 offset = mc.get_relative_pos() - jne_location
 assert 0  offset = 127
 mc.overwrite(jne_location-1, chr(offset))
-#
-# now decrement ebx by 2*WORD and store it back, which will
-# really decrement the shadowstack
-mc.SUB_ri(ebx.value, 2 * WORD)
-mc.MOV(self.heap_shadowstack_top(), ebx)
 
-elif gcrootmap and gcrootmap.is_shadow_stack:
+if gcrootmap and gcrootmap.is_shadow_stack:
 self._call_footer_shadowstack()
 
 # the return value is the jitframe
@@ -860,23 +862,20 @@
 self.mc.MOV_mr((self.SEGMENT_NO, ebx.value, 0), ebp.value)
   # MOV [ebx], ebp
 if self.cpu.gc_ll_descr.stm:
-# With stm, we push the jitframe twice on the shadowstack.
-   

[pypy-commit] benchmarks default: add multithread richards

2014-03-25 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: 
Changeset: r239:d505ab213546
Date: 2014-03-24 21:26 +0200
http://bitbucket.org/pypy/benchmarks/changeset/d505ab213546/

Log:add multithread richards

diff --git a/multithread/multithread-richards.py 
b/multithread/multithread-richards.py
new file mode 100755
--- /dev/null
+++ b/multithread/multithread-richards.py
@@ -0,0 +1,458 @@
+# based on a Java version:
+#  Based on original version written in BCPL by Dr Martin Richards
+#  in 1981 at Cambridge University Computer Laboratory, England
+#  and a C++ version derived from a Smalltalk version written by
+#  L Peter Deutsch.
+#  Java version:  Copyright (C) 1995 Sun Microsystems, Inc.
+#  Translation from C++, Mario Wolczko
+#  Outer loop added by Alex Jacoby
+
+import thread, os
+#from __pypy__.thread import atomic
+
+
+# Task IDs
+I_IDLE = 1
+I_WORK = 2
+I_HANDLERA = 3
+I_HANDLERB = 4
+I_DEVA = 5
+I_DEVB = 6
+
+# Packet types
+K_DEV = 1000
+K_WORK = 1001
+
+# Packet
+
+BUFSIZE = 4
+
+BUFSIZE_RANGE = range(BUFSIZE)
+
+class Packet(object):
+def __init__(self,l,i,k):
+self.link = l
+self.ident = i
+self.kind = k
+self.datum = 0
+self.data = [0] * BUFSIZE
+
+def append_to(self,lst):
+self.link = None
+if lst is None:
+return self
+else:
+p = lst
+next = p.link
+while next is not None:
+p = next
+next = p.link
+p.link = self
+return lst
+
+# Task Records
+
+class TaskRec(object):
+pass
+
+class DeviceTaskRec(TaskRec):
+def __init__(self):
+self.pending = None
+
+class IdleTaskRec(TaskRec):
+def __init__(self):
+self.control = 1
+self.count = 1
+
+class HandlerTaskRec(TaskRec):
+def __init__(self):
+self.work_in = None
+self.device_in = None
+
+def workInAdd(self,p):
+self.work_in = p.append_to(self.work_in)
+return self.work_in
+
+def deviceInAdd(self,p):
+self.device_in = p.append_to(self.device_in)
+return self.device_in
+
+class WorkerTaskRec(TaskRec):
+def __init__(self):
+self.destination = I_HANDLERA
+self.count = 0
+# Task
+
+class TaskState(object):
+def __init__(self):
+self.packet_pending = True
+self.task_waiting = False
+self.task_holding = False
+
+def packetPending(self):
+self.packet_pending = True
+self.task_waiting = False
+self.task_holding = False
+return self
+
+def waiting(self):
+self.packet_pending = False
+self.task_waiting = True
+self.task_holding = False
+return self
+
+def running(self):
+self.packet_pending = False
+self.task_waiting = False
+self.task_holding = False
+return self
+
+def waitingWithPacket(self):
+self.packet_pending = True
+self.task_waiting = True
+self.task_holding = False
+return self
+
+def isPacketPending(self):
+return self.packet_pending
+
+def isTaskWaiting(self):
+return self.task_waiting
+
+def isTaskHolding(self):
+return self.task_holding
+
+def isTaskHoldingOrWaiting(self):
+return self.task_holding or (not self.packet_pending and 
self.task_waiting)
+
+def isWaitingWithPacket(self):
+return self.packet_pending and self.task_waiting and not 
self.task_holding
+
+
+
+
+
+tracing = False
+layout = 0
+
+def trace(a):
+global layout
+layout -= 1
+if layout = 0:
+print
+layout = 50
+print a,
+
+
+TASKTABSIZE = 10
+
+class TaskWorkArea(object):
+def __init__(self):
+self.taskTab = [None] * TASKTABSIZE
+
+self.taskList = None
+
+self.holdCount = 0
+self.qpktCount = 0
+
+class Task(TaskState):
+
+
+def __init__(self,i,p,w,initialState,r, taskWorkArea):
+self.taskWorkArea = taskWorkArea
+self.link = taskWorkArea.taskList
+self.ident = i
+self.priority = p
+self.input = w
+
+self.packet_pending = initialState.isPacketPending()
+self.task_waiting = initialState.isTaskWaiting()
+self.task_holding = initialState.isTaskHolding()
+
+self.handle = r
+
+taskWorkArea.taskList = self
+taskWorkArea.taskTab[i] = self
+
+def fn(self,pkt,r):
+raise NotImplementedError
+
+
+def addPacket(self,p,old):
+if self.input is None:
+self.input = p
+self.packet_pending = True
+if self.priority  old.priority:
+return self
+else:
+p.append_to(self.input)
+return old
+
+
+def runTask(self):
+if self.isWaitingWithPacket():
+msg = self.input
+self.input = msg.link
+if self.input is None:
+self.running()
+else:
+

[pypy-commit] benchmarks single-run: Backed out changeset 7180631ee8db

2014-03-25 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: single-run
Changeset: r238:2e71651d7222
Date: 2014-03-24 21:25 +0200
http://bitbucket.org/pypy/benchmarks/changeset/2e71651d7222/

Log:Backed out changeset 7180631ee8db

diff --git a/lib/pypy/include/pypy_decl.h b/lib/pypy/include/pypy_decl.h
--- a/lib/pypy/include/pypy_decl.h
+++ b/lib/pypy/include/pypy_decl.h
@@ -513,17 +513,17 @@
 PyAPI_DATA(PyTypeObject) PySlice_Type;
 PyAPI_DATA(PyObject*) PyExc_IOError;
 PyAPI_DATA(PyObject*) PyExc_RuntimeError;
-PyAPI_DATA(PyObject*) PyExc_AttributeError;
+PyAPI_DATA(PyObject*) PyExc_SystemError;
 PyAPI_DATA(PyObject*) PyExc_NameError;
 PyAPI_DATA(PyObject*) PyExc_MemoryError;
 PyAPI_DATA(PyObject*) PyExc_SystemExit;
 PyAPI_DATA(PyTypeObject) PyModule_Type;
 PyAPI_DATA(PyTypeObject) PyBaseObject_Type;
-PyAPI_DATA(PyObject*) PyExc_FloatingPointError;
-PyAPI_DATA(PyObject*) PyExc_UnicodeDecodeError;
+PyAPI_DATA(PyObject*) PyExc_UnicodeTranslateError;
+PyAPI_DATA(PyObject*) PyExc_UnicodeWarning;
 PyAPI_DATA(PyObject*) PyExc_Exception;
 PyAPI_DATA(PyObject*) PyExc_TypeError;
-PyAPI_DATA(PyObject*) PyExc_SystemError;
+PyAPI_DATA(PyObject*) PyExc_AttributeError;
 PyAPI_DATA(PyObject*) PyExc_ReferenceError;
 PyAPI_DATA(PyTypeObject) PyNotImplemented_Type;
 PyAPI_DATA(PyTypeObject) PySet_Type;
@@ -555,14 +555,14 @@
 PyAPI_DATA(PyObject*) PyExc_BytesWarning;
 PyAPI_DATA(PyObject*) PyExc_DeprecationWarning;
 PyAPI_DATA(PyObject*) PyExc_SyntaxError;
-PyAPI_DATA(PyObject*) PyExc_UnicodeWarning;
+PyAPI_DATA(PyObject*) PyExc_UnicodeDecodeError;
 PyAPI_DATA(PyObject*) PyExc_ZeroDivisionError;
 PyAPI_DATA(PyTypeObject) PyFloat_Type;
+PyAPI_DATA(PyTypeObject) PyBaseString_Type;
+PyAPI_DATA(PyObject) _Py_NoneStruct;
+PyAPI_DATA(PyObject*) PyExc_GeneratorExit;
+PyAPI_DATA(PyObject*) PyExc_AssertionError;
 PyAPI_DATA(PyObject*) PyExc_RuntimeWarning;
-PyAPI_DATA(PyObject) _Py_NoneStruct;
-PyAPI_DATA(PyObject*) PyExc_IndentationError;
-PyAPI_DATA(PyObject*) PyExc_AssertionError;
-PyAPI_DATA(PyObject*) PyExc_GeneratorExit;
 PyAPI_DATA(PyObject*) PyExc_ImportWarning;
 PyAPI_DATA(PyObject*) PyExc_UnicodeEncodeError;
 PyAPI_DATA(PyTypeObject) PyInt_Type;
@@ -571,8 +571,8 @@
 PyAPI_DATA(PyObject*) PyExc_OSError;
 PyAPI_DATA(PyObject*) PyExc_KeyError;
 PyAPI_DATA(PyObject*) PyExc_SyntaxWarning;
-PyAPI_DATA(PyTypeObject) PyBaseString_Type;
 PyAPI_DATA(PyObject*) PyExc_StopIteration;
+PyAPI_DATA(PyObject*) PyExc_IndentationError;
 PyAPI_DATA(PyObject*) PyExc_NotImplementedError;
 PyAPI_DATA(PyObject*) PyExc_ImportError;
 PyAPI_DATA(PyDateTime_CAPI*) PyDateTimeAPI;
@@ -582,7 +582,7 @@
 PyAPI_DATA(PyTypeObject) PyClass_Type;
 PyAPI_DATA(PyTypeObject) PyType_Type;
 PyAPI_DATA(PyTypeObject) PyMemoryView_Type;
-PyAPI_DATA(PyObject*) PyExc_UnicodeTranslateError;
+PyAPI_DATA(PyObject*) PyExc_FloatingPointError;
 PyAPI_DATA(PyObject*) PyExc_LookupError;
 PyAPI_DATA(PyObject*) PyExc_EOFError;
 PyAPI_DATA(PyObject*) PyExc_BufferError;
diff --git a/lib/pypy/rpython/translator/c/src/signals.o 
b/lib/pypy/rpython/translator/c/src/signals.o
index 
08b3649ae1483b939bb048d11ecb051f62ffe15d..166016f96874014a34535131bd7cfed3aabe09eb
GIT binary patch

[cut]

diff --git a/lib/pypy/rpython/translator/c/src/stacklet/stacklet.o 
b/lib/pypy/rpython/translator/c/src/stacklet/stacklet.o
index 
6dba4dd0d4a6480683502d1568c529dbaecf9174..e42497399f1f975b42e62fbf236498014c21f654
GIT binary patch

[cut]

diff --git a/lib/pypy/rpython/translator/c/src/thread.o 
b/lib/pypy/rpython/translator/c/src/thread.o
index 
06072cecd32b5f5afce76655ad919f8ff637714c..9b7dcc7cb6e9c6eb94216acf121fbcd5b32297e5
GIT binary patch

[cut]

diff --git a/multithread/multithread-richards.py 
b/multithread/multithread-richards.py
deleted file mode 100755
--- a/multithread/multithread-richards.py
+++ /dev/null
@@ -1,458 +0,0 @@
-# based on a Java version:
-#  Based on original version written in BCPL by Dr Martin Richards
-#  in 1981 at Cambridge University Computer Laboratory, England
-#  and a C++ version derived from a Smalltalk version written by
-#  L Peter Deutsch.
-#  Java version:  Copyright (C) 1995 Sun Microsystems, Inc.
-#  Translation from C++, Mario Wolczko
-#  Outer loop added by Alex Jacoby
-
-import thread, os
-#from __pypy__.thread import atomic
-
-
-# Task IDs
-I_IDLE = 1
-I_WORK = 2
-I_HANDLERA = 3
-I_HANDLERB = 4
-I_DEVA = 5
-I_DEVB = 6
-
-# Packet types
-K_DEV = 1000
-K_WORK = 1001
-
-# Packet
-
-BUFSIZE = 4
-
-BUFSIZE_RANGE = range(BUFSIZE)
-
-class Packet(object):
-def __init__(self,l,i,k):
-self.link = l
-self.ident = i
-self.kind = k
-self.datum = 0
-self.data = [0] * BUFSIZE
-
-def append_to(self,lst):
-self.link = None
-if lst is None:
-return self
-else:
-p = lst
-next = p.link
-while next is not None:
-p = next
-next = p.link
-p.link = self
-return lst
-
-# Task Records
-
-class TaskRec(object):

[pypy-commit] benchmarks default: add some multithreaded benchmarks and a script to run them (optional)

2014-03-25 Thread Remi Meier
Author: Remi Meier
Branch: 
Changeset: r240:06ac9ee33205
Date: 2014-03-25 09:33 +0100
http://bitbucket.org/pypy/benchmarks/changeset/06ac9ee33205/

Log:add some multithreaded benchmarks and a script to run them
(optional)

diff --git a/multithread/bench.py b/multithread/bench.py
new file mode 100644
--- /dev/null
+++ b/multithread/bench.py
@@ -0,0 +1,116 @@
+#!/usr/bin/python
+
+import time
+import math
+import imp, os, sys
+import json
+import contextlib
+
+def import_file(filepath):
+mod_name, file_ext = os.path.splitext(os.path.split(filepath)[-1])
+return imp.load_source(mod_name, filepath)
+
+
+class DummyFile(object):
+def write(self, x): pass
+
+@contextlib.contextmanager
+def nostdout():
+save_stdout = sys.stdout
+sys.stdout = DummyFile()
+yield
+sys.stdout = save_stdout
+
+
+def avg(xs):
+return sum(xs) / len(xs)
+
+def std_dev(xs):
+N = len(xs)
+mu = avg(xs)
+var = sum([(x - mu)**2 for x in xs]) / N
+return math.sqrt(var)
+
+def get_error(times):
+ts = sorted(times)[:args.k]
+best = float(ts[0])
+
+return max((t / best) - 1.0 for t in ts)
+
+def within_error(args, times):
+return get_error(times)  args.error
+
+def main(args):
+basedir = os.path.abspath(os.path.dirname(__file__))
+sys.path.insert(0, basedir+'/')
+import common
+print __file__
+folder = os.path.dirname(args.file)
+os.chdir(folder)
+sys.path.insert(0, os.path.abspath('.'))
+test = import_file(os.path.basename(args.file))
+
+times = []
+k = 1
+try:
+while True:
+time.sleep(0.2)
+if not args.q:
+print Run {}/{}:.format(k, args.k)
+
+test_time = time.time()
+if args.p:
+test.run(*args.more)
+else:
+with nostdout():
+test.run(*args.more)
+times.append(time.time() - test_time)
+
+if not args.q:
+print took {} s.format(times[-1])
+
+if k = args.k:
+if within_error(args, times):
+break
+elif not args.q:
+print error was not within, args.error
+
+if k  2 * args.k:
+if not args.q:
+print max number of iterations reached, \
+error still too great, finish anyway
+break
+k += 1
+finally:
+if not args.q:
+print times:, times
+
+if times:
+times = sorted(times)[:args.k]
+result = {'best':min(times),
+  'error':get_error(times),
+  'std_dev(k)':std_dev(times)}
+print json.dumps(result)
+
+
+
+if __name__ == '__main__':
+import argparse
+
+parser = argparse.ArgumentParser()
+parser.add_argument('-k', default=3, help='K-best K', type=int)
+parser.add_argument('-e', '--error', default=0.05, type=float,
+help='relative allowed error [0.05]')
+parser.add_argument('-q', action='store_const',
+const=True, default=False,
+help='mute except for best run')
+parser.add_argument('-p', action='store_const',
+const=True, default=False,
+help='print to stdout what the benchmark prints')
+parser.add_argument('file', help='file to run')
+parser.add_argument('more', nargs=*, help='file.run() arguments')
+
+args = parser.parse_args()
+if not args.q:
+print args
+main(args)
diff --git a/multithread/common/__init__.py b/multithread/common/__init__.py
new file mode 100644
diff --git a/multithread/common/abstract_threading.py 
b/multithread/common/abstract_threading.py
new file mode 100644
--- /dev/null
+++ b/multithread/common/abstract_threading.py
@@ -0,0 +1,119 @@
+from Queue import Queue, Empty, Full
+from threading import Thread, Condition, Lock
+import thread
+
+try:
+from __pypy__.thread import atomic
+except ImportError:
+atomic = Lock()
+
+class Worker(Thread):
+Thread executing tasks from a given tasks queue
+def __init__(self, queue):
+Thread.__init__(self)
+self.daemon = True
+self.next_task = None
+self.cond = Condition()
+self.queue = queue
+self.start()
+
+def run(self):
+# the next line registers the at_commit_cb on interpreter
+# level for this thread. This should be fixed in the 
+# interpreter (it causes a conflict in 
stmgcintf.register_at_commit_cb).
+# thread.at_commit(lambda : 0, ())
+
+while True:
+with self.cond:
+while self.next_task is None:
+self.cond.wait()
+
+func, args, kargs = self.next_task
+self.next_task = None
+
+try:
+func(*args, **kargs)
+

[pypy-commit] stmgc default: Failing test

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r1091:a51ebf0218a9
Date: 2014-03-25 09:52 +0100
http://bitbucket.org/pypy/stmgc/changeset/a51ebf0218a9/

Log:Failing test

diff --git a/c7/test/test_weakref.py b/c7/test/test_weakref.py
--- a/c7/test/test_weakref.py
+++ b/c7/test/test_weakref.py
@@ -338,3 +338,22 @@
 self.switch(1)
 lp1 = self.pop_root()
 assert stm_get_weakref(lp1) == lp0
+
+def test_weakref_bug2(self):
+self.start_transaction()
+lp0 = stm_allocate(16)
+self.push_root(lp0)
+self.commit_transaction()
+#
+self.start_transaction()
+lp0 = self.pop_root()
+self.push_root(lp0)
+stm_write(lp0)# privatize page
+lp1 = stm_allocate_weakref(lp0)# young object
+self.push_root(lp1)
+stm_minor_collect()
+lp1 = self.pop_root()   # overflow object
+self.push_root(lp1)
+#
+self.switch(1)
+stm_major_collect()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc default: Improve the test so that it crashes more reliably (this includes

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r1092:d8fe314589b8
Date: 2014-03-25 10:01 +0100
http://bitbucket.org/pypy/stmgc/changeset/d8fe314589b8/

Log:Improve the test so that it crashes more reliably (this includes
older revisions now)

diff --git a/c7/test/test_weakref.py b/c7/test/test_weakref.py
--- a/c7/test/test_weakref.py
+++ b/c7/test/test_weakref.py
@@ -340,20 +340,23 @@
 assert stm_get_weakref(lp1) == lp0
 
 def test_weakref_bug2(self):
-self.start_transaction()
-lp0 = stm_allocate(16)
-self.push_root(lp0)
-self.commit_transaction()
+def make_wr():
+self.start_transaction()
+lp0 = stm_allocate(16)
+self.push_root(lp0)
+self.commit_transaction()
+#
+self.start_transaction()
+lp0 = self.pop_root()
+self.push_root(lp0)
+stm_write(lp0)# privatize page
+lp1 = stm_allocate_weakref(lp0)# young object
+self.push_root(lp1)
+stm_minor_collect()
+lp1 = self.pop_root()   # overflow object
+self.push_root(lp1)
 #
-self.start_transaction()
-lp0 = self.pop_root()
-self.push_root(lp0)
-stm_write(lp0)# privatize page
-lp1 = stm_allocate_weakref(lp0)# young object
-self.push_root(lp1)
-stm_minor_collect()
-lp1 = self.pop_root()   # overflow object
-self.push_root(lp1)
-#
+make_wr()
 self.switch(1)
+make_wr()
 stm_major_collect()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc default: Fix for d8fe314589b8

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r1093:5575626c8253
Date: 2014-03-25 10:02 +0100
http://bitbucket.org/pypy/stmgc/changeset/5575626c8253/

Log:Fix for d8fe314589b8

diff --git a/c7/stm/weakref.c b/c7/stm/weakref.c
--- a/c7/stm/weakref.c
+++ b/c7/stm/weakref.c
@@ -126,7 +126,7 @@
 
 ssize_t size = 16;
 stm_char *wr = (stm_char *)WEAKREF_PTR(weakref, size);
-char *real_wr = REAL_ADDRESS(stm_object_pages, wr);
+char *real_wr = REAL_ADDRESS(pseg-pub.segment_base, wr);
 object_t *pointing_to = *(object_t **)real_wr;
 assert(pointing_to != NULL);
 if (!mark_visited_test(pointing_to)) {
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stmgc-c7: import stmgc/5575626c8253

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: stmgc-c7
Changeset: r70274:a8d2c3d28939
Date: 2014-03-25 10:03 +0100
http://bitbucket.org/pypy/pypy/changeset/a8d2c3d28939/

Log:import stmgc/5575626c8253

diff --git a/rpython/translator/stm/src_stm/revision 
b/rpython/translator/stm/src_stm/revision
--- a/rpython/translator/stm/src_stm/revision
+++ b/rpython/translator/stm/src_stm/revision
@@ -1,1 +1,1 @@
-510720112e4c
+5575626c8253
diff --git a/rpython/translator/stm/src_stm/stm/weakref.c 
b/rpython/translator/stm/src_stm/stm/weakref.c
--- a/rpython/translator/stm/src_stm/stm/weakref.c
+++ b/rpython/translator/stm/src_stm/stm/weakref.c
@@ -127,7 +127,7 @@
 
 ssize_t size = 16;
 stm_char *wr = (stm_char *)WEAKREF_PTR(weakref, size);
-char *real_wr = REAL_ADDRESS(stm_object_pages, wr);
+char *real_wr = REAL_ADDRESS(pseg-pub.segment_base, wr);
 object_t *pointing_to = *(object_t **)real_wr;
 assert(pointing_to != NULL);
 if (!mark_visited_test(pointing_to)) {
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stmgc-c7: Missing transactionsafe. Add a no_collect at a place where it used

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: stmgc-c7
Changeset: r70275:b832e861aef4
Date: 2014-03-25 11:45 +0100
http://bitbucket.org/pypy/pypy/changeset/b832e861aef4/

Log:Missing transactionsafe. Add a no_collect at a place where it used
to collect (because of stm_become_inevitable()).

diff --git a/rpython/jit/backend/llsupport/jitframe.py 
b/rpython/jit/backend/llsupport/jitframe.py
--- a/rpython/jit/backend/llsupport/jitframe.py
+++ b/rpython/jit/backend/llsupport/jitframe.py
@@ -3,7 +3,7 @@
 from rpython.rlib.objectmodel import specialize
 from rpython.rlib.debug import ll_assert
 from rpython.rlib.objectmodel import enforceargs
-from rpython.rlib.rgc import stm_is_enabled
+from rpython.rlib import rgc
 
 SIZEOFSIGNED = rffi.sizeof(lltype.Signed)
 IS_32BIT = (SIZEOFSIGNED == 4)
@@ -15,10 +15,11 @@
 GCMAP = lltype.Array(lltype.Unsigned)
 NULLGCMAP = lltype.nullptr(GCMAP)
 
+@rgc.no_collect
 @enforceargs(None, int, int)
 def jitframeinfo_update_depth(jfi, base_ofs, new_depth):
 #
-if stm_is_enabled():
+if rgc.stm_is_enabled():
 from rpython.rlib.atomic_ops import bool_cas
 # careful here, 'jfi' has 'stm_dont_track_raw_accesses'
 while True:
diff --git a/rpython/rlib/atomic_ops.py b/rpython/rlib/atomic_ops.py
--- a/rpython/rlib/atomic_ops.py
+++ b/rpython/rlib/atomic_ops.py
@@ -16,8 +16,10 @@
 
 
 bool_cas = rffi.llexternal('pypy_bool_cas', [llmemory.Address]*3, lltype.Bool,
-   compilation_info=eci, macro=True, _nowrapper=True)
+   compilation_info=eci, macro=True, _nowrapper=True,
+   transactionsafe=True)
 fetch_and_add = rffi.llexternal('pypy_fetch_and_add', [llmemory.Address,
lltype.Signed],
 lltype.Signed, compilation_info=eci,
-macro=True, _nowrapper=True)
+macro=True, _nowrapper=True,
+transactionsafe=True)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc default: Add an extra argument to stm_become_inevitable() just for testing.

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r1094:4024e96d9ba2
Date: 2014-03-25 14:10 +0100
http://bitbucket.org/pypy/stmgc/changeset/4024e96d9ba2/

Log:Add an extra argument to stm_become_inevitable() just for testing.

diff --git a/c7/demo/demo_random.c b/c7/demo/demo_random.c
--- a/c7/demo/demo_random.c
+++ b/c7/demo/demo_random.c
@@ -285,12 +285,12 @@
 return (objptr_t)-1; // break current
 } else if (get_rand(20) == 1) {
 push_roots();
-stm_become_inevitable(please);
+stm_become_inevitable(stm_thread_local, please);
 pop_roots();
 return NULL;
 } else if (get_rand(240) == 1) {
 push_roots();
-stm_become_globally_unique_transaction(really);
+stm_become_globally_unique_transaction(stm_thread_local, really);
 fprintf(stderr, [GUT/%d], (int)STM_SEGMENT-segment_num);
 pop_roots();
 return NULL;
diff --git a/c7/stm/core.c b/c7/stm/core.c
--- a/c7/stm/core.c
+++ b/c7/stm/core.c
@@ -676,9 +676,10 @@
 s_mutex_unlock();
 }
 
-void stm_become_globally_unique_transaction(const char *msg)
+void stm_become_globally_unique_transaction(stm_thread_local_t *tl,
+const char *msg)
 {
-stm_become_inevitable(msg);   /* may still abort */
+stm_become_inevitable(tl, msg);   /* may still abort */
 
 s_mutex_lock();
 synchronize_all_threads(STOP_OTHERS_AND_BECOME_GLOBALLY_UNIQUE);
diff --git a/c7/stm/forksupport.c b/c7/stm/forksupport.c
--- a/c7/stm/forksupport.c
+++ b/c7/stm/forksupport.c
@@ -60,7 +60,7 @@
 
 bool was_in_transaction = _stm_in_transaction(this_tl);
 if (was_in_transaction) {
-stm_become_inevitable(fork);
+stm_become_inevitable(this_tl, fork);
 /* Note that the line above can still fail and abort, which should
be fine */
 }
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -275,7 +275,9 @@
 /* Turn the current transaction inevitable.  The 'jmpbuf' passed to
STM_START_TRANSACTION() is not going to be used any more after
this call (but the stm_become_inevitable() itself may still abort). */
-static inline void stm_become_inevitable(const char* msg) {
+static inline void stm_become_inevitable(stm_thread_local_t *tl,
+ const char* msg) {
+assert(STM_SEGMENT-running_thread == tl);
 if (STM_SEGMENT-jmpbuf_ptr != NULL)
 _stm_become_inevitable(msg);
 }
@@ -330,7 +332,8 @@
transaction is running concurrently.  Avoid as much as possible.
Other transactions will continue running only after this transaction
commits. */
-void stm_become_globally_unique_transaction(const char *msg);
+void stm_become_globally_unique_transaction(stm_thread_local_t *tl,
+const char *msg);
 
 
 /*  END  */
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -53,8 +53,8 @@
 void _stm_start_transaction(stm_thread_local_t *tl, stm_jmpbuf_t *jmpbuf);
 bool _check_commit_transaction(void);
 bool _check_abort_transaction(void);
-bool _check_become_inevitable(void);
-bool _check_become_globally_unique_transaction(void);
+bool _check_become_inevitable(stm_thread_local_t *tl);
+bool _check_become_globally_unique_transaction(stm_thread_local_t *tl);
 int stm_is_inevitable(void);
 
 void _set_type_id(object_t *obj, uint32_t h);
@@ -158,12 +158,12 @@
 CHECKED(stm_abort_transaction());
 }
 
-bool _check_become_inevitable() {
-CHECKED(stm_become_inevitable(TEST));
+bool _check_become_inevitable(stm_thread_local_t *tl) {
+CHECKED(stm_become_inevitable(tl, TEST));
 }
 
-bool _check_become_globally_unique_transaction() {
-CHECKED(stm_become_globally_unique_transaction(TESTGUT));
+bool _check_become_globally_unique_transaction(stm_thread_local_t *tl) {
+CHECKED(stm_become_globally_unique_transaction(tl, TESTGUT));
 }
 
 #undef CHECKED
@@ -358,14 +358,6 @@
 if lib._check_stop_safe_point():
 raise Conflict()
 
-def stm_become_inevitable():
-if lib._check_become_inevitable():
-raise Conflict()
-
-def stm_become_globally_unique_transaction():
-if lib._check_become_globally_unique_transaction():
-raise Conflict()
-
 def stm_minor_collect():
 lib.stm_collect(0)
 
@@ -515,3 +507,13 @@
 def set_thread_local_obj(self, newobj):
 tl = self.tls[self.current_thread]
 tl.thread_local_obj = newobj
+
+def become_inevitable(self):
+tl = self.tls[self.current_thread]
+if lib._check_become_inevitable(tl):
+raise Conflict()
+
+def become_globally_unique_transaction(self):
+tl = self.tls[self.current_thread]
+if lib._check_become_globally_unique_transaction(tl):
+raise Conflict()
diff --git a/c7/test/test_basic.py b/c7/test/test_basic.py
--- a/c7/test/test_basic.py
+++ 

[pypy-commit] stmgc default: Fix?

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r1095:a631a7415a3d
Date: 2014-03-25 14:16 +0100
http://bitbucket.org/pypy/stmgc/changeset/a631a7415a3d/

Log:Fix?

diff --git a/c7/stm/forksupport.c b/c7/stm/forksupport.c
--- a/c7/stm/forksupport.c
+++ b/c7/stm/forksupport.c
@@ -190,6 +190,8 @@
 #ifndef NDEBUG
 pr-running_pthread = pthread_self();
 #endif
+pr-pub.running_thread-shadowstack = (
+pr-shadowstack_at_start_of_transaction);
 stm_abort_transaction();
 }
 }
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc default: Move this error-detection logic into abort_data_structures_from_segment_num()

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r1096:4d330c8e6b92
Date: 2014-03-25 14:17 +0100
http://bitbucket.org/pypy/stmgc/changeset/4d330c8e6b92/

Log:Move this error-detection logic into
abort_data_structures_from_segment_num()

diff --git a/c7/stm/core.c b/c7/stm/core.c
--- a/c7/stm/core.c
+++ b/c7/stm/core.c
@@ -580,6 +580,16 @@
 */
 struct stm_priv_segment_info_s *pseg = get_priv_segment(segment_num);
 
+switch (pseg-transaction_state) {
+case TS_REGULAR:
+break;
+case TS_INEVITABLE:
+stm_fatalerror(abort: transaction_state == TS_INEVITABLE);
+default:
+stm_fatalerror(abort: bad transaction_state == %d,
+   (int)pseg-transaction_state);
+}
+
 /* throw away the content of the nursery */
 long bytes_in_nursery = throw_away_nursery(pseg);
 
@@ -605,15 +615,6 @@
 assert(_has_mutex());
 dprintf((~~~ ABORT\n));
 
-switch (STM_PSEGMENT-transaction_state) {
-case TS_REGULAR:
-break;
-case TS_INEVITABLE:
-stm_fatalerror(abort: transaction_state == TS_INEVITABLE);
-default:
-stm_fatalerror(abort: bad transaction_state == %d,
-   (int)STM_PSEGMENT-transaction_state);
-}
 assert(STM_PSEGMENT-running_pthread == pthread_self());
 
 abort_data_structures_from_segment_num(STM_SEGMENT-segment_num);
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Working on refactoring.

2014-03-25 Thread anton_gulenko
Author: Anton Gulenko anton.gule...@googlemail.com
Branch: storage
Changeset: r694:20c045fd46e5
Date: 2014-03-24 18:31 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/20c045fd46e5/

Log:Working on refactoring.

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -497,14 +497,23 @@
 if not self.shadow:
 self.store_shadow(self.default_storage(space, size))
 else:
+from spyvm.shadow import ClassShadow
+if isinstance(self.shadow, ClassShadow) and self.shadow.name == 
BlockClosure:
+import pdb; pdb.set_trace()
+
 self.shadow.initialize_storage(space, size)
 
 def fillin(self, space, g_self):
+g_self.g_class.fillin(space)
 self.s_class = g_self.get_class().as_class_get_penumbra(space)
+
+if self.s_class.name == BlockClosure:
+import pdb; pdb.set_trace()
+
 self.hash = g_self.get_hash()
 self.space = space
 for g_obj in g_self.get_g_pointers():
-g_obj.fillin(space)
+g_obj.fillin_nonpointers(space)
 pointers = g_self.get_pointers()
 self.initialize_storage(space, len(pointers))
 self.store_all(space, pointers)
@@ -550,6 +559,8 @@
 return self.varsize(space)
 
 def size(self):
+if not self.shadow:
+return 0
 return self._get_shadow().size()
 
 def store_shadow(self, shadow):
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -36,6 +36,58 @@
 return self._executable_path[0]
 
 def make_bootstrap_classes(self):
+def define_cls(cls_nm, supercls_nm, instvarsize=0, 
format=shadow.POINTERS,
+   varsized=False):
+assert cls_nm.startswith(w_)
+self.classtable[cls_nm] = bootstrap_class(self, instvarsize, \
+ None,
+ None,
+ format=format,
+ varsized=varsized,
+ name=cls_nm[2:])
+
+#define_cls(w_Magnitude, w_Object)
+define_cls(w_Character, w_Magnitude, instvarsize=1)
+#define_cls(w_Number, w_Magnitude)
+#define_cls(w_Integer, w_Number)
+define_cls(w_SmallInteger, w_Integer)
+define_cls(w_LargePositiveInteger, w_Integer, format=shadow.BYTES)
+define_cls(w_Float, w_Number, format=shadow.BYTES)
+define_cls(w_Message, w_Object)
+#define_cls(w_Collection, w_Object)
+#define_cls(w_SequenceableCollection, w_Collection)
+#define_cls(w_ArrayedCollection, w_SequenceableCollection)
+define_cls(w_Array, w_ArrayedCollection, varsized=True)
+define_cls(w_String, w_ArrayedCollection, format=shadow.BYTES)
+define_cls(w_Bitmap, w_ArrayedCollection, varsized=True, 
format=shadow.WORDS)
+#define_cls(w_UndefinedObject, w_Object)
+#define_cls(w_Boolean, w_Object)
+#define_cls(w_True, w_Boolean)
+#define_cls(w_False, w_Boolean)
+define_cls(w_ByteArray, w_ArrayedCollection, format=shadow.BYTES)
+define_cls(w_CompiledMethod, w_ByteArray, 
format=shadow.COMPILED_METHOD)
+#define_cls(w_ContextPart, w_Object)
+define_cls(w_MethodContext, w_ContextPart)
+#define_cls(w_Link, w_Object)
+#define_cls(w_Process, w_Link)
+#define_cls(w_Point, w_Object)
+#define_cls(w_LinkedList, w_SequenceableCollection)
+define_cls(w_Semaphore, w_LinkedList)
+#define_cls(w_BlockContext, w_ContextPart, 
instvarsize=constants.BLKCTX_STACK_START)
+define_cls(w_BlockClosure, w_Object, 
instvarsize=constants.BLKCLSR_SIZE, varsized=True)
+
+# make better accessors for classes that can be found in special object
+# table
+for name in constants.classes_in_special_object_table.keys():
+name = 'w_' + name
+if name in self.classtable:
+cls = self.classtable.get(name)
+setattr(self, name, self.classtable.get(name))
+else:
+# assert False, Missing bootstrapped class from special 
objects array: %s % (name,)
+pass
+
+def _make_bootstrap_classes(self):
 def define_core_cls(name, w_superclass, w_metaclass):
 assert name.startswith('w_')
 w_class = bootstrap_class(self, instsize=0,# XXX
@@ -106,42 +158,45 @@
  varsized=varsized,
  name=cls_nm[2:])
 
-define_cls(w_Magnitude, w_Object)
+#define_cls(w_Magnitude, w_Object)
 define_cls(w_Character, w_Magnitude, instvarsize=1)
-define_cls(w_Number, w_Magnitude)
-define_cls(w_Integer, w_Number)
+#define_cls(w_Number, w_Magnitude)
+#define_cls(w_Integer, w_Number)
 

[pypy-commit] lang-smalltalk storage: Merged strategies-tagging.

2014-03-25 Thread anton_gulenko
Author: Anton Gulenko anton.gule...@googlemail.com
Branch: storage
Changeset: r691:80ad6308c3db
Date: 2014-03-24 10:59 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/80ad6308c3db/

Log:Merged strategies-tagging.

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -24,6 +24,7 @@
 from rpython.tool.pairtype import extendabletype
 from rpython.rlib.objectmodel import instantiate, compute_hash, 
import_from_mixin, we_are_translated
 from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.rlib.listsort import TimSort
 from rsdl import RSDL, RSDL_helper
 
 class W_Object(object):
@@ -613,12 +614,24 @@
 className='W_PointersObject',
 additionalInformation='len=%d' % self.size())
 
+class StatsSorter(TimSort):
+def lt(self, a, b):
+if a[0] == b[0]:
+if a[1] == b[1]:
+return a[2]  b[2]
+else:
+return a[1]  b[1]
+else:
+return a[0]  b[0]
+
 class StrategyStatistics(object):
 # Key: (operation_name, old_strategy, new_strategy)
 # Value: [sizes]
 stats = {}
 do_log = False
 do_stats = False
+do_stats_sizes = False
+
 def stat_operation(self, operation_name, old_strategy, new_strategy, size):
 key = (operation_name, old_strategy, new_strategy)
 if not key in self.stats:
@@ -626,14 +639,19 @@
 self.stats[key].append(size)
 def log_operation(self, op, new_strategy_tag, old_strategy_tag, classname, 
size):
 print %s (%s, was %s) of %s size %d % (op, new_strategy_tag, 
old_strategy_tag, classname, size)
+def sorted_keys(self):
+keys = [ x for x in self.stats ]
+StatsSorter(keys).sort()
+return keys
 def print_stats(self):
-for key in self.stats:
+for key in self.sorted_keys():
 sizes = self.stats[key]
 sum = 0
 for s in sizes:
 sum += s
 print %s: %d times, avg size: %d % (key, len(sizes), 
sum/len(sizes))
-printAll sizes: %s % sizes
+if self.do_stats_sizes:
+printAll sizes: %s % sizes
 strategy_stats = StrategyStatistics()
 
 class W_PointersObject(W_AbstractPointersObject):
@@ -644,10 +662,10 @@
 
 @jit.unroll_safe
 def __init__(self, space, w_class, size):
-from spyvm.strategies import strategy_of_size
+from spyvm.strategies import empty_strategy
 Create new object with size = fixed + variable size.
 W_AbstractPointersObject.__init__(self, space, w_class, size)
-self.strategy = strategy_of_size(self.s_class, size)
+self.strategy = empty_strategy(self.s_class)
 self.initialize_storage(space, size)
 self.log_strategy_operation(Initialized)
 
diff --git a/spyvm/strategies.py b/spyvm/strategies.py
--- a/spyvm/strategies.py
+++ b/spyvm/strategies.py
@@ -1,8 +1,11 @@
 
-import sys
-from spyvm import model, shadow
-from rpython.rlib import rerased
+import sys, math
+from spyvm import model, shadow, constants
+from rpython.rlib import longlong2float, rarithmetic
+from rpython.rlib.rstruct.runpack import runpack
+from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rlib.objectmodel import import_from_mixin
+from rpython.rlib.rfloat import string_to_float
 
 # Disables all optimized strategies, for debugging.
 only_list_storage = False
@@ -21,22 +24,32 @@
 def set_storage_copied_from(self, space, w_obj, w_source_obj, 
reuse_storage=False):
 raise NotImplementedError(Abstract base class)
 
+def store(self, space, w_obj, n0, w_val):
+if self.can_contain(space, w_val):
+return self.do_store(space, w_obj, n0, w_val)
+new_strategy = self.generelized_strategy_for(space, w_val)
+return w_obj.store_with_new_strategy(space, new_strategy, n0, w_val)
+
+def generelized_strategy_for(self, space, w_val):
+raise NotImplementedError(Abstract base class)
+def can_contain(self, space, w_val):
+raise NotImplementedError(Abstract base class)
 def fetch(self, space, w_obj, n0):
 raise NotImplementedError(Abstract base class)
-def store(self, space, w_obj, n0, w_val):
+def do_store(self, space, w_obj, n0, w_val):
 raise NotImplementedError(Abstract base class)
 
 class AbstractListStorageStrategy(AbstractStorageStrategy):
 strategy_tag = 'abstract-list'
 
 def storage(self, w_obj):
-return self.unerase(w_obj.list_storage)
+return w_obj.list_storage
 def set_initial_storage(self, space, w_obj, size):
-w_obj.list_storage = self.erase(self.initial_storage(space, size))
+w_obj.list_storage = self.initial_storage(space, size)
 def set_storage_for_list(self, space, w_obj, collection):
-w_obj.list_storage = self.erase(self.storage_for_list(space, 

[pypy-commit] lang-smalltalk storage: Removed the only_list_storage flag.

2014-03-25 Thread anton_gulenko
Author: Anton Gulenko anton.gule...@googlemail.com
Branch: storage
Changeset: r692:8754efd5dc1d
Date: 2014-03-24 11:06 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/8754efd5dc1d/

Log:Removed the only_list_storage flag.

diff --git a/spyvm/strategies.py b/spyvm/strategies.py
--- a/spyvm/strategies.py
+++ b/spyvm/strategies.py
@@ -7,9 +7,6 @@
 from rpython.rlib.objectmodel import import_from_mixin
 from rpython.rlib.rfloat import string_to_float
 
-# Disables all optimized strategies, for debugging.
-only_list_storage = False
-
 class AbstractStorageStrategy(object):
 _immutable_fields_ = []
 _attrs_ = []
@@ -207,9 +204,6 @@
 return space.unwrap_float(w_val)
 
 def find_strategy_for_objects(space, vars):
-if only_list_storage:
-ListStorageStrategy.singleton
-
 specialized_strategies = 3
 all_nil_can_handle = True
 small_int_can_handle = True
@@ -242,7 +236,7 @@
 if s_containing_class is None:
 # This is a weird and rare special case for w_nil
 return ListStorageStrategy.singleton
-if not s_containing_class.isvariable() or only_list_storage:
+if not s_containing_class.isvariable():
 return ListStorageStrategy.singleton
 
 # A newly allocated object contains only nils.
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: .

2014-03-25 Thread anton_gulenko
Author: Anton Gulenko anton.gule...@googlemail.com
Branch: storage
Changeset: r689:154e1c60771d
Date: 2014-03-20 16:20 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/154e1c60771d/

Log:.

diff --git a/a b/a
new file mode 100644
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk strategies-tagging: Added sorted output of strategy statistics, added other flag to control the output, added test.

2014-03-25 Thread anton_gulenko
Author: Anton Gulenko anton.gule...@googlemail.com
Branch: strategies-tagging
Changeset: r690:a58baa9918d7
Date: 2014-03-21 12:50 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/a58baa9918d7/

Log:Added sorted output of strategy statistics, added other flag to
control the output, added test.

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -24,6 +24,7 @@
 from rpython.tool.pairtype import extendabletype
 from rpython.rlib.objectmodel import instantiate, compute_hash, 
import_from_mixin, we_are_translated
 from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.rlib.listsort import TimSort
 from rsdl import RSDL, RSDL_helper
 
 class W_Object(object):
@@ -613,12 +614,24 @@
 className='W_PointersObject',
 additionalInformation='len=%d' % self.size())
 
+class StatsSorter(TimSort):
+def lt(self, a, b):
+if a[0] == b[0]:
+if a[1] == b[1]:
+return a[2]  b[2]
+else:
+return a[1]  b[1]
+else:
+return a[0]  b[0]
+
 class StrategyStatistics(object):
 # Key: (operation_name, old_strategy, new_strategy)
 # Value: [sizes]
 stats = {}
 do_log = False
 do_stats = False
+do_stats_sizes = False
+
 def stat_operation(self, operation_name, old_strategy, new_strategy, size):
 key = (operation_name, old_strategy, new_strategy)
 if not key in self.stats:
@@ -626,14 +639,19 @@
 self.stats[key].append(size)
 def log_operation(self, op, new_strategy_tag, old_strategy_tag, classname, 
size):
 print %s (%s, was %s) of %s size %d % (op, new_strategy_tag, 
old_strategy_tag, classname, size)
+def sorted_keys(self):
+keys = [ x for x in self.stats ]
+StatsSorter(keys).sort()
+return keys
 def print_stats(self):
-for key in self.stats:
+for key in self.sorted_keys():
 sizes = self.stats[key]
 sum = 0
 for s in sizes:
 sum += s
 print %s: %d times, avg size: %d % (key, len(sizes), 
sum/len(sizes))
-printAll sizes: %s % sizes
+if self.do_stats_sizes:
+printAll sizes: %s % sizes
 strategy_stats = StrategyStatistics()
 
 class W_PointersObject(W_AbstractPointersObject):
diff --git a/spyvm/test/test_strategies.py b/spyvm/test/test_strategies.py
--- a/spyvm/test/test_strategies.py
+++ b/spyvm/test/test_strategies.py
@@ -170,4 +170,21 @@
 a.store(space, 1, space.wrap_int(2))
 assert isinstance(a.strategy, strategies.ListStorageStrategy)
 check_arr(a, [1.2, 2, w_nil, w_nil, w_nil])
+
+def test_statistics():
+stats = model.StrategyStatistics()
+stats.stat_operation(B, old, new, 3)
+stats.stat_operation(B, old, new, 4)
+stats.stat_operation(B, old2, new2, 20)
+stats.stat_operation(B, old, new, 5)
+stats.stat_operation(A, old, new, 1)
+stats.stat_operation(A, old, new, 2)
+stats.stat_operation(C, old, new, 10)
+stats.stat_operation(C, old, new, 11)
+keys = stats.sorted_keys()
+assert keys == [ (A, old, new), (B, old, new), (B, old2, 
new2), (C, old, new) ]
+assert stats.stats[keys[0]] == [1, 2]
+assert stats.stats[keys[1]] == [3, 4, 5]
+assert stats.stats[keys[2]] == [20]
+assert stats.stats[keys[3]] == [10, 11]
 
\ No newline at end of file
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -128,6 +128,7 @@
   -p|--poll_events
   --strategy-log
   --strategy-stats
+  --strategy-stats-with-sizes
   [image path, default: Squeak.image]
  % argv[0]
 
@@ -188,6 +189,9 @@
 model.strategy_stats.do_log = True
 elif arg == --strategy-stats:
 model.strategy_stats.do_stats = True
+elif arg == --strategy-stats-with-sizes:
+model.strategy_stats.do_stats = True
+model.strategy_stats.do_stats_sizes = True
 elif path is None:
 path = argv[idx]
 else:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stmgc-c7: add the extra argument

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: stmgc-c7
Changeset: r70277:13baeba618bc
Date: 2014-03-25 14:32 +0100
http://bitbucket.org/pypy/pypy/changeset/13baeba618bc/

Log:add the extra argument

diff --git a/rpython/translator/stm/funcgen.py 
b/rpython/translator/stm/funcgen.py
--- a/rpython/translator/stm/funcgen.py
+++ b/rpython/translator/stm/funcgen.py
@@ -127,10 +127,11 @@
 except IndexError:
 info = rstm.become_inevitable# cannot insert it in 'llop'
 string_literal = c_string_constant(info)
-return 'stm_become_inevitable(%s);' % (string_literal,)
+return 'stm_become_inevitable(stm_thread_local, %s);' % (string_literal,)
 
 def stm_become_globally_unique_transaction(funcgen, op):
-return 'stm_become_globally_unique_transaction(for the JIT);'
+return ('stm_become_globally_unique_transaction(stm_thread_local,'
+' for the JIT);')
 
 def stm_push_root(funcgen, op):
 arg0 = funcgen.expr(op.args[0])
@@ -276,14 +277,6 @@
 ##return '%s = stm_pointer_equal((gcptr)%s, (gcptr)%s);' % (
 ##result, args[0], args[1])
 
-##def stm_become_inevitable(funcgen, op):
-##try:
-##info = op.args[0].value
-##except IndexError:
-##info = rstm.become_inevitable# cannot insert it in 'llop'
-##string_literal = c_string_constant(info)
-##return 'stm_become_inevitable(%s);' % (string_literal,)
-
 ##def stm_stop_all_other_threads(funcgen, op):
 ##return 'stm_stop_all_other_threads();'
 
diff --git a/rpython/translator/stm/src_stm/stmgcintf.h 
b/rpython/translator/stm/src_stm/stmgcintf.h
--- a/rpython/translator/stm/src_stm/stmgcintf.h
+++ b/rpython/translator/stm/src_stm/stmgcintf.h
@@ -23,7 +23,8 @@
 stm_commit_transaction();
 }
 else {
-stm_become_inevitable(commit_if_not_atomic in atomic);
+stm_become_inevitable(stm_thread_local,
+  commit_if_not_atomic in atomic);
 }
 errno = e;
 }
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stmgc-c7: Fix by a quick hack (that can be justified too): give transactionsafe=True

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: stmgc-c7
Changeset: r70278:6d63887bcf1a
Date: 2014-03-25 15:01 +0100
http://bitbucket.org/pypy/pypy/changeset/6d63887bcf1a/

Log:Fix by a quick hack (that can be justified too): give
transactionsafe=True to the calls that actually occur outside a
transaction.

diff --git a/rpython/rtyper/lltypesystem/rffi.py 
b/rpython/rtyper/lltypesystem/rffi.py
--- a/rpython/rtyper/lltypesystem/rffi.py
+++ b/rpython/rtyper/lltypesystem/rffi.py
@@ -127,6 +127,12 @@
 has_callback)   # because the callback can do it
 assert not (elidable_function and random_effects_on_gcobjs)
 
+if not _nowrapper and invoke_around_handlers:
+# enable 'transactionsafe' so that the call to funcptr, which is
+# really done outside a transaction, doesn't force stm/inevitable.py
+# to insert a spurious stm_become_inevitable()
+transactionsafe = True
+
 funcptr = lltype.functionptr(ext_type, name, external='C',
  transactionsafe=transactionsafe,
  compilation_info=compilation_info,
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Working on merging strategies and shadows.

2014-03-25 Thread anton_gulenko
Author: Anton Gulenko anton.gule...@googlemail.com
Branch: storage
Changeset: r693:d5b590bdaa03
Date: 2014-03-24 16:38 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/d5b590bdaa03/

Log:Working on merging strategies and shadows.

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -93,6 +93,7 @@
 raise NotImplementedError()
 
 def fillin(self, space, g_self):
+import pdb; pdb.set_trace()
 raise NotImplementedError()
 
 def getword(self, n0):
@@ -157,6 +158,10 @@
 def __init__(self, value):
 self.value = intmask(value)
 
+def fillin(self, space, g_obj):
+# Is created directly with the correct value.
+pass
+
 def getclass(self, space):
 return space.w_SmallInteger
 
@@ -443,7 +448,10 @@
 
 def as_embellished_string(self, className, additionalInformation):
 from rpython.rlib.objectmodel import current_object_addr_as_int
-name = self.shadow_of_my_class(self.space).name or ?
+if self.s_class and self.s_class.name:
+name = self.s_class.name
+else:
+name = ?
 return %s (a %s) %s % (className, name,
 #hex(current_object_addr_as_int(self)),
 additionalInformation)
@@ -483,13 +491,41 @@
 def __init__(self, space, w_class, size):
 Create new object with size = fixed + variable size.
 W_AbstractObjectWithClassReference.__init__(self, space, w_class)
-self.store_shadow(None)
+self.initialize_storage(space, size)
 
+def initialize_storage(self, space, size):
+if not self.shadow:
+self.store_shadow(self.default_storage(space, size))
+else:
+self.shadow.initialize_storage(space, size)
+
 def fillin(self, space, g_self):
 self.s_class = g_self.get_class().as_class_get_penumbra(space)
 self.hash = g_self.get_hash()
 self.space = space
-
+for g_obj in g_self.get_g_pointers():
+g_obj.fillin(space)
+pointers = g_self.get_pointers()
+self.initialize_storage(space, len(pointers))
+self.store_all(space, pointers)
+
+def fetch_all(self, space):
+return [self.fetch(space, i) for i in range(self.size())]
+
+def store_all(self, space, collection):
+# Be tolerant: copy over as many elements as possible, set rest to nil.
+# The size of the object cannot be changed in any case.
+# This should only by used in tests/debugging.
+my_length = self.size()
+incoming_length = min(my_length, len(collection))
+i = 0
+while i  incoming_length:
+self.store(space, i, collection[i])
+i = i+1
+while i  my_length:
+self.store(space, i, w_nil)
+i = i+1
+
 def at0(self, space, index0):
 # To test, at0 = in varsize part
 return self.fetch(space, index0+self.instsize(space))
@@ -499,14 +535,10 @@
 self.store(space, index0 + self.instsize(space), w_value)
 
 def fetch(self, space, n0):
-if self.has_shadow():
-return self._get_shadow().fetch(n0)
-return self._fetch(space, n0)
+return self._get_shadow().fetch(n0)
 
 def store(self, space, n0, w_value):
-if self.has_shadow():
-return self._get_shadow().store(n0, w_value)
-return self._store(space, n0, w_value)
+return self._get_shadow().store(n0, w_value)
 
 def varsize(self, space):
 return self.size() - self.instsize(space)
@@ -518,32 +550,25 @@
 return self.varsize(space)
 
 def size(self):
-if self.has_shadow():
-return self._get_shadow().size()
-return self.basic_size()
+return self._get_shadow().size()
 
 def store_shadow(self, shadow):
-assert self.shadow is None or self.shadow is shadow
+#assert self.shadow is None or self.shadow is shadow
 self.shadow = shadow
 
 def _get_shadow(self):
 return self.shadow
 
 @objectmodel.specialize.arg(2)
-def attach_shadow_of_class(self, space, TheClass):
-shadow = TheClass(space, self)
-self.store_shadow(shadow)
-shadow.attach_shadow()
-return shadow
-
-@objectmodel.specialize.arg(2)
 def as_special_get_shadow(self, space, TheClass):
-shadow = self._get_shadow()
-if not isinstance(shadow, TheClass):
-if shadow is not None:
-raise DetachingShadowError(shadow, TheClass)
-shadow = self.attach_shadow_of_class(space, TheClass)
-shadow.update()
+old_shadow = self._get_shadow()
+shadow = old_shadow
+if not isinstance(old_shadow, TheClass):
+shadow = TheClass(space, self)
+if old_shadow is not None:
+shadow.copy_from(old_shadow)
+

[pypy-commit] lang-smalltalk storage: Fixed tests (except test_strategies.py which is not functional).

2014-03-25 Thread anton_gulenko
Author: Anton Gulenko anton.gule...@googlemail.com
Branch: storage
Changeset: r696:fdf0149a0aae
Date: 2014-03-25 15:35 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/fdf0149a0aae/

Log:Fixed tests (except test_strategies.py which is not functional).
Added BootstrappedObjSpace in util.py for tests.

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -439,7 +439,7 @@
 return self.w_class
 
 def __str__(self):
-if isinstance(self, W_PointersObject) and self.has_shadow():
+if isinstance(self, W_PointersObject) and self.has_shadow() and 
self.shadow.has_getname:
 return self._get_shadow().getname()
 else:
 name = None
@@ -627,7 +627,7 @@
 def as_context_get_shadow(self, space):
 from spyvm.shadow import ContextPartShadow
 # XXX TODO should figure out itself if its method or block context
-if self._get_shadow() is None:
+if not isinstance(self.shadow, ContextPartShadow):
 if ContextPartShadow.is_block_context(self, space):
 return self.as_blockcontext_get_shadow(space)
 return self.as_methodcontext_get_shadow(space)
diff --git a/spyvm/plugins/bitblt.py b/spyvm/plugins/bitblt.py
--- a/spyvm/plugins/bitblt.py
+++ b/spyvm/plugins/bitblt.py
@@ -53,7 +53,7 @@
 MaskTable.append(r_uint((2 ** (i + 1)) - 1))
 AllOnes = r_uint(0x)
 
-def sync_cache(self):
+def attach_shadow(self):
 pass
 
 def intOrIfNil(self, w_int, i):
@@ -734,7 +734,7 @@
 def intOrIfNil(self, w_int, i):
 return intOrIfNil(self.space, w_int, i)
 
-def sync_cache(self):
+def attach_shadow(self):
 self.invalid = True
 if self.size()  5:
 return
@@ -756,8 +756,8 @@
 w_offset = self.fetch(4)
 assert isinstance(w_offset, model.W_PointersObject)
 if not w_offset is self.space.w_nil:
-self.offsetX = self.intOrIfNil(w_offset._fetch(self.space, 0), 0)
-self.offsetY = self.intOrIfNil(w_offset._fetch(self.space, 1), 0)
+self.offsetX = self.intOrIfNil(w_offset.fetch(self.space, 0), 0)
+self.offsetY = self.intOrIfNil(w_offset.fetch(self.space, 1), 0)
 self.pixPerWord = 32 / self.depth
 self.pitch = (self.width + (self.pixPerWord - 1)) / self.pixPerWord | 0
 if self.w_bits.size()  (self.pitch * self.height):
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -11,7 +11,8 @@
 can be attached at run-time to any Smalltalk object.
 
 _attrs_ = ['_w_self', 'space']
-
+has_getname = True
+
 def __init__(self, space, w_self):
 self.space = space
 self._w_self = w_self
@@ -40,6 +41,7 @@
 
 class ListStorageShadow(AbstractShadow):
 _attrs_ = ['storage']
+has_getname = False
 
 def __init__(self, space, w_self, size):
 AbstractShadow.__init__(self, space, w_self)
@@ -60,6 +62,7 @@
 
 class WeakListStorageShadow(AbstractShadow):
 _attrs_ = ['storage']
+has_getname = False
 
 def __init__(self, space, w_self, size):
 AbstractShadow.__init__(self, space, w_self)
@@ -79,6 +82,7 @@
 _attrs_ = ['version']
 import_from_mixin(version.VersionMixin)
 version = None
+has_getname = True
 
 def __init__(self, space, w_self):
 ListStorageShadow.__init__(self, space, w_self, 0)
@@ -337,7 +341,7 @@
 NOT_RPYTHON # this is only for testing.
 if self._s_methoddict is None:
 w_methoddict = model.W_PointersObject(self.space, None, 2)
-w_methoddict._store(self.space, 1, 
model.W_PointersObject(self.space, None, 0))
+w_methoddict.store(self.space, 1, 
model.W_PointersObject(self.space, None, 0))
 self._s_methoddict = 
w_methoddict.as_methoddict_get_shadow(self.space)
 self.s_methoddict().sync_method_cache()
 self.s_methoddict().invalid = False
@@ -450,6 +454,12 @@
 AbstractRedirectingShadow.__init__(self, space, w_self)
 self.instances_w = {}
 
+def copy_field_from(self, n0, other_shadow):
+try:
+AbstractRedirectingShadow.copy_field_from(self, n0, other_shadow)
+except error.SenderChainManipulation, e:
+assert e.s_context == self
+
 def copy_from(self, other_shadow):
 # Some fields have to be initialized before the rest, to ensure 
correct initialization.
 privileged_fields = self.fields_to_copy_first()
@@ -463,6 +473,9 @@
 if n0 not in privileged_fields:
 self.copy_field_from(n0, other_shadow)
 
+def fields_to_copy_first(self):
+return []
+
 @staticmethod
 def is_block_context(w_pointers, space):
 method_or_argc = w_pointers.fetch(space, constants.MTHDCTX_METHOD)
diff --git a/spyvm/test/jit.py b/spyvm/test/jit.py
--- 

[pypy-commit] pypy stmgc-c7: import stmgc/4d330c8e6b92

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: stmgc-c7
Changeset: r70276:ade60393992a
Date: 2014-03-25 14:18 +0100
http://bitbucket.org/pypy/pypy/changeset/ade60393992a/

Log:import stmgc/4d330c8e6b92

diff --git a/rpython/translator/stm/src_stm/revision 
b/rpython/translator/stm/src_stm/revision
--- a/rpython/translator/stm/src_stm/revision
+++ b/rpython/translator/stm/src_stm/revision
@@ -1,1 +1,1 @@
-5575626c8253
+4d330c8e6b92
diff --git a/rpython/translator/stm/src_stm/stm/core.c 
b/rpython/translator/stm/src_stm/stm/core.c
--- a/rpython/translator/stm/src_stm/stm/core.c
+++ b/rpython/translator/stm/src_stm/stm/core.c
@@ -581,6 +581,16 @@
 */
 struct stm_priv_segment_info_s *pseg = get_priv_segment(segment_num);
 
+switch (pseg-transaction_state) {
+case TS_REGULAR:
+break;
+case TS_INEVITABLE:
+stm_fatalerror(abort: transaction_state == TS_INEVITABLE);
+default:
+stm_fatalerror(abort: bad transaction_state == %d,
+   (int)pseg-transaction_state);
+}
+
 /* throw away the content of the nursery */
 long bytes_in_nursery = throw_away_nursery(pseg);
 
@@ -606,15 +616,6 @@
 assert(_has_mutex());
 dprintf((~~~ ABORT\n));
 
-switch (STM_PSEGMENT-transaction_state) {
-case TS_REGULAR:
-break;
-case TS_INEVITABLE:
-stm_fatalerror(abort: transaction_state == TS_INEVITABLE);
-default:
-stm_fatalerror(abort: bad transaction_state == %d,
-   (int)STM_PSEGMENT-transaction_state);
-}
 assert(STM_PSEGMENT-running_pthread == pthread_self());
 
 abort_data_structures_from_segment_num(STM_SEGMENT-segment_num);
@@ -677,9 +678,10 @@
 s_mutex_unlock();
 }
 
-void stm_become_globally_unique_transaction(const char *msg)
+void stm_become_globally_unique_transaction(stm_thread_local_t *tl,
+const char *msg)
 {
-stm_become_inevitable(msg);   /* may still abort */
+stm_become_inevitable(tl, msg);   /* may still abort */
 
 s_mutex_lock();
 synchronize_all_threads(STOP_OTHERS_AND_BECOME_GLOBALLY_UNIQUE);
diff --git a/rpython/translator/stm/src_stm/stm/forksupport.c 
b/rpython/translator/stm/src_stm/stm/forksupport.c
--- a/rpython/translator/stm/src_stm/stm/forksupport.c
+++ b/rpython/translator/stm/src_stm/stm/forksupport.c
@@ -61,7 +61,7 @@
 
 bool was_in_transaction = _stm_in_transaction(this_tl);
 if (was_in_transaction) {
-stm_become_inevitable(fork);
+stm_become_inevitable(this_tl, fork);
 /* Note that the line above can still fail and abort, which should
be fine */
 }
@@ -191,6 +191,8 @@
 #ifndef NDEBUG
 pr-running_pthread = pthread_self();
 #endif
+pr-pub.running_thread-shadowstack = (
+pr-shadowstack_at_start_of_transaction);
 stm_abort_transaction();
 }
 }
diff --git a/rpython/translator/stm/src_stm/stmgc.h 
b/rpython/translator/stm/src_stm/stmgc.h
--- a/rpython/translator/stm/src_stm/stmgc.h
+++ b/rpython/translator/stm/src_stm/stmgc.h
@@ -276,7 +276,9 @@
 /* Turn the current transaction inevitable.  The 'jmpbuf' passed to
STM_START_TRANSACTION() is not going to be used any more after
this call (but the stm_become_inevitable() itself may still abort). */
-static inline void stm_become_inevitable(const char* msg) {
+static inline void stm_become_inevitable(stm_thread_local_t *tl,
+ const char* msg) {
+assert(STM_SEGMENT-running_thread == tl);
 if (STM_SEGMENT-jmpbuf_ptr != NULL)
 _stm_become_inevitable(msg);
 }
@@ -331,7 +333,8 @@
transaction is running concurrently.  Avoid as much as possible.
Other transactions will continue running only after this transaction
commits. */
-void stm_become_globally_unique_transaction(const char *msg);
+void stm_become_globally_unique_transaction(stm_thread_local_t *tl,
+const char *msg);
 
 
 /*  END  */
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy win32-fixes4: merge default into branch

2014-03-25 Thread mattip
Author: Matti Picus matti.pi...@gmail.com
Branch: win32-fixes4
Changeset: r70279:9359e47f4250
Date: 2014-03-25 17:47 +0200
http://bitbucket.org/pypy/pypy/changeset/9359e47f4250/

Log:merge default into branch

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -117,3 +117,10 @@
 
 .. branch: improve-consecutive-dict-lookups
 Improve the situation when dict lookups of the same key are performed in a 
chain
+
+.. branch: add_PyErr_SetFromErrnoWithFilenameObject_try_2
+.. branch: test_SetFromErrnoWithFilename_NULL
+.. branch: test_SetFromErrnoWithFilename__tweaks
+
+.. branch: refactor_PyErr_SetFromErrnoWithFilename
+Add support for PyErr_SetFromErrnoWithFilenameObject to cpyext
diff --git a/pypy/module/cpyext/pyerrors.py b/pypy/module/cpyext/pyerrors.py
--- a/pypy/module/cpyext/pyerrors.py
+++ b/pypy/module/cpyext/pyerrors.py
@@ -150,14 +150,29 @@
 this is used to define the filename attribute of the exception instance.
 Return value: always NULL.
 # XXX Doesn't actually do anything with PyErr_CheckSignals.
+if llfilename:
+w_filename = rffi.charp2str(llfilename)
+filename = space.wrap(w_filename)
+else:
+filename = space.w_None
+
+PyErr_SetFromErrnoWithFilenameObject(space, w_type, filename)
+
+@cpython_api([PyObject, PyObject], PyObject)
+def PyErr_SetFromErrnoWithFilenameObject(space, w_type, w_value):
+Similar to PyErr_SetFromErrno(), with the additional behavior that if
+w_value is not NULL, it is passed to the constructor of type as a
+third parameter.  In the case of exceptions such as IOError and OSError,
+this is used to define the filename attribute of the exception instance.
+Return value: always NULL.
+# XXX Doesn't actually do anything with PyErr_CheckSignals.
 errno = get_errno()
 msg = os.strerror(errno)
-if llfilename:
-w_filename = rffi.charp2str(llfilename)
+if w_value:
 w_error = space.call_function(w_type,
   space.wrap(errno),
   space.wrap(msg),
-  space.wrap(w_filename))
+  w_value)
 else:
 w_error = space.call_function(w_type,
   space.wrap(errno),
diff --git a/pypy/module/cpyext/test/test_pyerrors.py 
b/pypy/module/cpyext/test/test_pyerrors.py
--- a/pypy/module/cpyext/test/test_pyerrors.py
+++ b/pypy/module/cpyext/test/test_pyerrors.py
@@ -196,29 +196,136 @@
 except OSError, e:
 assert e.errno == errno.EBADF
 assert e.strerror == os.strerror(errno.EBADF)
-assert e.filename == None
+assert e.filename is None
 
 def test_SetFromErrnoWithFilename(self):
-import sys
-if sys.platform != 'win32':
-skip(callbacks through ll2ctypes modify errno)
 import errno, os
 
 module = self.import_extension('foo', [
 (set_from_errno, METH_NOARGS,
  '''
  errno = EBADF;
- PyErr_SetFromErrnoWithFilename(PyExc_OSError, blyf);
+ PyErr_SetFromErrnoWithFilename(PyExc_OSError, 
/path/to/file);
  return NULL;
  '''),
 ],
 prologue=#include errno.h)
-try:
-module.set_from_errno()
-except OSError, e:
-assert e.filename == blyf
-assert e.errno == errno.EBADF
-assert e.strerror == os.strerror(errno.EBADF)
+exc_info = raises(OSError, module.set_from_errno)
+assert exc_info.value.filename == /path/to/file
+assert exc_info.value.errno == errno.EBADF
+assert exc_info.value.strerror == os.strerror(errno.EBADF)
+
+def test_SetFromErrnoWithFilename_NULL(self):
+import errno, os
+
+module = self.import_extension('foo', [
+(set_from_errno, METH_NOARGS,
+ '''
+ errno = EBADF;
+ PyErr_SetFromErrnoWithFilename(PyExc_OSError, NULL);
+ return NULL;
+ '''),
+],
+prologue=#include errno.h)
+exc_info = raises(OSError, module.set_from_errno)
+assert exc_info.value.filename is None
+assert exc_info.value.errno == errno.EBADF
+assert exc_info.value.strerror == os.strerror(errno.EBADF)
+
+def test_SetFromErrnoWithFilenameObject__PyString(self):
+import errno, os
+
+module = self.import_extension('foo', [
+(set_from_errno, METH_NOARGS,
+ '''
+ errno = EBADF;
+ PyObject *filenameObject = 
PyString_FromString(/path/to/file);
+ PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, 
filenameObject);
+ Py_DECREF(filenameObject);
+ 

[pypy-commit] pypy win32-fixes4: document branch

2014-03-25 Thread mattip
Author: Matti Picus matti.pi...@gmail.com
Branch: win32-fixes4
Changeset: r70280:378118928b11
Date: 2014-03-25 17:54 +0200
http://bitbucket.org/pypy/pypy/changeset/378118928b11/

Log:document branch

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -124,3 +124,6 @@
 
 .. branch: refactor_PyErr_SetFromErrnoWithFilename
 Add support for PyErr_SetFromErrnoWithFilenameObject to cpyext
+
+.. branch: win32-fixes4
+fix more tests for win32
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: merge win32-fixes4, which fixes some tests on win32

2014-03-25 Thread mattip
Author: Matti Picus matti.pi...@gmail.com
Branch: 
Changeset: r70282:d2fa62bd86e8
Date: 2014-03-25 17:56 +0200
http://bitbucket.org/pypy/pypy/changeset/d2fa62bd86e8/

Log:merge win32-fixes4, which fixes some tests on win32

diff --git a/lib-python/2.7/test/test_genericpath.py 
b/lib-python/2.7/test/test_genericpath.py
--- a/lib-python/2.7/test/test_genericpath.py
+++ b/lib-python/2.7/test/test_genericpath.py
@@ -231,9 +231,12 @@
 unicwd = u'\xe7w\xf0'
 try:
 fsencoding = test_support.TESTFN_ENCODING or ascii
-unicwd.encode(fsencoding)
+asciival = unicwd.encode(fsencoding)
+v = asciival.find('?')
+if v = 0:
+raise UnicodeEncodeError(fsencoding, unicwd, v, v, asciival)
 except (AttributeError, UnicodeEncodeError):
-# FS encoding is probably ASCII
+# FS encoding is probably ASCII or windows and codepage is 
non-Latin1
 pass
 else:
 with test_support.temp_cwd(unicwd):
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -124,3 +124,6 @@
 
 .. branch: refactor_PyErr_SetFromErrnoWithFilename
 Add support for PyErr_SetFromErrnoWithFilenameObject to cpyext
+
+.. branch: win32-fixes4
+fix more tests for win32
diff --git a/pypy/module/_codecs/test/test_codecs.py 
b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -1,3 +1,5 @@
+import sys
+
 class AppTestCodecs:
 spaceconfig = {
 usemodules: ['unicodedata', 'struct', 'binascii'],
@@ -137,7 +139,9 @@
 
 
 class AppTestPartialEvaluation:
-spaceconfig = dict(usemodules=('array',))
+spaceconfig = dict(usemodules=['array',])
+if sys.platform == 'win32':
+spaceconfig['usemodules'].append('_winreg')
 
 def test_partial_utf8(self):
 import _codecs
@@ -694,8 +698,18 @@
 import sys
 if sys.platform != 'win32':
 return
+toencode = u'caf\xe9', 'caf\xe9'
+try:
+#test for non-latin1 codepage, more general test needed
+import _winreg
+key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 
+r'System\CurrentControlSet\Control\Nls\CodePage')
+if _winreg.QueryValueEx(key, 'ACP')[0] == u'1255': #non-latin1
+toencode = u'caf\xbf','caf\xbf'
+except:
+assert False, 'cannot test mbcs on this windows system, check code 
page'
 assert u'test'.encode('mbcs') == 'test'
-assert u'caf\xe9'.encode('mbcs') == 'caf\xe9'
+assert toencode[0].encode('mbcs') == toencode[1]
 assert u'\u040a'.encode('mbcs') == '?' # some cyrillic letter
 assert 'cafx\e9'.decode('mbcs') == u'cafx\e9'
 
diff --git a/pypy/module/cpyext/test/test_eval.py 
b/pypy/module/cpyext/test/test_eval.py
--- a/pypy/module/cpyext/test/test_eval.py
+++ b/pypy/module/cpyext/test/test_eval.py
@@ -312,8 +312,9 @@
 (get_flags, METH_NOARGS,
  
 PyCompilerFlags flags;
+int result;
 flags.cf_flags = 0;
-int result = PyEval_MergeCompilerFlags(flags);
+result = PyEval_MergeCompilerFlags(flags);
 return Py_BuildValue(ii, result, flags.cf_flags);
  ),
 ])
diff --git a/rpython/jit/backend/detect_cpu.py 
b/rpython/jit/backend/detect_cpu.py
--- a/rpython/jit/backend/detect_cpu.py
+++ b/rpython/jit/backend/detect_cpu.py
@@ -20,10 +20,11 @@
 
 def detect_model_from_c_compiler():
 # based on http://sourceforge.net/p/predef/wiki/Architectures/
+# and http://msdn.microsoft.com/en-us/library/b0084kay.aspx
 mapping = {
-MODEL_X86_64: ['__amd64__', '__amd64', '__x86_64__', '__x86_64'],
-MODEL_ARM:['__arm__', '__thumb__'],
-MODEL_X86:['i386', '__i386', '__i386__', '__i686__'],
+MODEL_X86_64: ['__amd64__', '__amd64', '__x86_64__', '__x86_64', 
'_M_X64', '_M_AMD64'],
+MODEL_ARM:['__arm__', '__thumb__','_M_ARM_EP'],
+MODEL_X86:['i386', '__i386', '__i386__', '__i686__','_M_IX86'],
 MODEL_PPC_64: ['__powerpc64__'],
 }
 for k, v in mapping.iteritems():
diff --git a/rpython/jit/backend/llgraph/runner.py 
b/rpython/jit/backend/llgraph/runner.py
--- a/rpython/jit/backend/llgraph/runner.py
+++ b/rpython/jit/backend/llgraph/runner.py
@@ -66,9 +66,11 @@
 self.args = args
 
 class CallDescr(AbstractDescr):
-def __init__(self, RESULT, ARGS, extrainfo):
+from rpython.rlib.clibffi import FFI_DEFAULT_ABI
+def __init__(self, RESULT, ARGS, extrainfo, ABI=FFI_DEFAULT_ABI):
 self.RESULT = RESULT
 self.ARGS = ARGS
+self.ABI = ABI
 self.extrainfo = extrainfo
 
 def __repr__(self):
@@ -428,7 +430,7 @@
 try:
 return 

[pypy-commit] pypy win32-fixes4: close branch to be merged

2014-03-25 Thread mattip
Author: Matti Picus matti.pi...@gmail.com
Branch: win32-fixes4
Changeset: r70281:3af64b2cdd03
Date: 2014-03-25 17:55 +0200
http://bitbucket.org/pypy/pypy/changeset/3af64b2cdd03/

Log:close branch to be merged

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stmgc-c7: I think it's preferable to avoid rare conflicts even at the cost

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: stmgc-c7
Changeset: r70283:18557316383a
Date: 2014-03-25 17:03 +0100
http://bitbucket.org/pypy/pypy/changeset/18557316383a/

Log:I think it's preferable to avoid rare conflicts even at the cost of
one additional check for zero-ness during strdict lookups.

diff --git a/rpython/rtyper/lltypesystem/rstr.py 
b/rpython/rtyper/lltypesystem/rstr.py
--- a/rpython/rtyper/lltypesystem/rstr.py
+++ b/rpython/rtyper/lltypesystem/rstr.py
@@ -377,17 +377,17 @@
 # special non-computed-yet value.
 if not s:
 return 0
-#with stm_ignored:
-x = s.hash
+with stm_ignored:
+x = s.hash
 if x == 0:
-x = _hash_string(s.chars)
-if x == 0:
-x = 29872897
-# XXX STM note: we would like this write to be stm-ignored,
-# but we can't, because ll_strfasthash() might later miss
-# the written value and return 0 again (rarely).  Think
-# again later about the best option.
-#with stm_ignored:
+x = LLHelpers._ll_compute_strhash(s)
+return x
+
+def _ll_compute_strhash(s):
+x = _hash_string(s.chars)
+if x == 0:
+x = 29872897
+with stm_ignored:
 s.hash = x
 return x
 
@@ -395,7 +395,17 @@
 return len(s.chars)
 
 def ll_strfasthash(s):
-return s.hash # assumes that the hash is already computed
+if rgc.stm_is_enabled():
+# due to with stm_ignored in _ll_strhash(), it is possible
+# that just returning 's.hash' from here would rarely return
+# the old value, which is 0.  We need to check.
+with stm_ignored:
+x = s.hash
+if x == 0:
+x = LLHelpers._ll_compute_strhash(s)
+return x
+else:
+return s.hash # assumes that the hash is already computed
 
 @jit.elidable
 def ll_strconcat(s1, s2):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: cleanups

2014-03-25 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r70284:7950a956ce52
Date: 2014-03-25 12:24 -0400
http://bitbucket.org/pypy/pypy/changeset/7950a956ce52/

Log:cleanups

diff --git a/pypy/module/_codecs/test/test_codecs.py 
b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -700,17 +700,17 @@
 return
 toencode = u'caf\xe9', 'caf\xe9'
 try:
-#test for non-latin1 codepage, more general test needed
+# test for non-latin1 codepage, more general test needed
 import _winreg
-key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 
+key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
 r'System\CurrentControlSet\Control\Nls\CodePage')
-if _winreg.QueryValueEx(key, 'ACP')[0] == u'1255': #non-latin1
+if _winreg.QueryValueEx(key, 'ACP')[0] == u'1255':  # non-latin1
 toencode = u'caf\xbf','caf\xbf'
 except:
 assert False, 'cannot test mbcs on this windows system, check code 
page'
 assert u'test'.encode('mbcs') == 'test'
 assert toencode[0].encode('mbcs') == toencode[1]
-assert u'\u040a'.encode('mbcs') == '?' # some cyrillic letter
+assert u'\u040a'.encode('mbcs') == '?'  # some cyrillic letter
 assert 'cafx\e9'.decode('mbcs') == u'cafx\e9'
 
 def test_bad_handler_string_result(self):
diff --git a/rpython/jit/backend/llgraph/runner.py 
b/rpython/jit/backend/llgraph/runner.py
--- a/rpython/jit/backend/llgraph/runner.py
+++ b/rpython/jit/backend/llgraph/runner.py
@@ -13,6 +13,7 @@
 from rpython.rtyper.llinterp import LLInterpreter, LLException
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi, rclass, rstr
 
+from rpython.rlib.clibffi import FFI_DEFAULT_ABI
 from rpython.rlib.rarithmetic import ovfcheck, r_uint, r_ulonglong
 from rpython.rlib.rtimer import read_timestamp
 
@@ -66,7 +67,6 @@
 self.args = args
 
 class CallDescr(AbstractDescr):
-from rpython.rlib.clibffi import FFI_DEFAULT_ABI
 def __init__(self, RESULT, ARGS, extrainfo, ABI=FFI_DEFAULT_ABI):
 self.RESULT = RESULT
 self.ARGS = ARGS
diff --git a/rpython/rlib/test/test_rposix.py b/rpython/rlib/test/test_rposix.py
--- a/rpython/rlib/test/test_rposix.py
+++ b/rpython/rlib/test/test_rposix.py
@@ -59,9 +59,9 @@
 def f():
 return rposix.stat(self.path).st_mtime
 if sys.platform == 'win32':
-#double vs. float, be satisfied with sub-millisec resolution
+# double vs. float, be satisfied with sub-millisec resolution
 assert abs(interpret(f, []) - os.stat(self.ufilename).st_mtime)  
1e-4
-else:
+else:
 assert interpret(f, []) == os.stat(self.ufilename).st_mtime
 
 def test_access(self):
diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py 
b/rpython/rtyper/lltypesystem/ll2ctypes.py
--- a/rpython/rtyper/lltypesystem/ll2ctypes.py
+++ b/rpython/rtyper/lltypesystem/ll2ctypes.py
@@ -358,7 +358,6 @@
 
 if isinstance(T, lltype.Ptr):
 if isinstance(T.TO, lltype.FuncType):
-
 functype = ctypes.CFUNCTYPE
 if sys.platform == 'win32':
 from rpython.rlib.clibffi import FFI_STDCALL, FFI_DEFAULT_ABI
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stmgc-c7: Tweaks

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: stmgc-c7
Changeset: r70286:b6601e2ca87d
Date: 2014-03-25 17:46 +0100
http://bitbucket.org/pypy/pypy/changeset/b6601e2ca87d/

Log:Tweaks

diff --git a/rpython/jit/backend/x86/stmtlocal.py 
b/rpython/jit/backend/x86/stmtlocal.py
--- a/rpython/jit/backend/x86/stmtlocal.py
+++ b/rpython/jit/backend/x86/stmtlocal.py
@@ -23,4 +23,5 @@
 'pypy__threadlocal_base',
 [], lltype.Signed,
 compilation_info=eci,
-_nowrapper=True)
+_nowrapper=True,
+transactionsafe=True)
diff --git a/rpython/translator/stm/funcgen.py 
b/rpython/translator/stm/funcgen.py
--- a/rpython/translator/stm/funcgen.py
+++ b/rpython/translator/stm/funcgen.py
@@ -125,7 +125,11 @@
 try:
 info = op.args[0].value
 except IndexError:
-info = rstm.become_inevitable# cannot insert it in 'llop'
+info = ?# cannot insert it in 'llop'
+try:
+info = '%s:%s' % funcgen.graph.name
+except AttributeError:
+pass
 string_literal = c_string_constant(info)
 return 'stm_become_inevitable(stm_thread_local, %s);' % (string_literal,)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stmgc-c7: merge heads

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: stmgc-c7
Changeset: r70287:e5c759af77bd
Date: 2014-03-25 17:48 +0100
http://bitbucket.org/pypy/pypy/changeset/e5c759af77bd/

Log:merge heads

diff --git a/rpython/jit/backend/x86/stmtlocal.py 
b/rpython/jit/backend/x86/stmtlocal.py
--- a/rpython/jit/backend/x86/stmtlocal.py
+++ b/rpython/jit/backend/x86/stmtlocal.py
@@ -23,4 +23,5 @@
 'pypy__threadlocal_base',
 [], lltype.Signed,
 compilation_info=eci,
-_nowrapper=True)
+_nowrapper=True,
+transactionsafe=True)
diff --git a/rpython/jit/metainterp/counter.py 
b/rpython/jit/metainterp/counter.py
--- a/rpython/jit/metainterp/counter.py
+++ b/rpython/jit/metainterp/counter.py
@@ -8,12 +8,15 @@
 UINT32MAX = 2 ** 32 - 1
 
 # keep in sync with the C code in pypy__decay_jit_counters
-ENTRY = lltype.Struct('timetable_entry',
-  ('times', lltype.FixedSizeArray(rffi.FLOAT, 5)),
-  ('subhashes', lltype.FixedSizeArray(rffi.USHORT, 5)),
-  hints={'stm_dont_track_raw_accesses': True})
-ENTRY_ARRAY = lltype.Array(ENTRY, hints={'nolength': True,
- 'stm_dont_track_raw_accesses': True})
+_h = {'stm_dont_track_raw_accesses': True}
+ENTRY = lltype.Struct(
+'timetable_entry',
+('times', lltype.FixedSizeArray(rffi.FLOAT, 5, hints=_h)),
+('subhashes', lltype.FixedSizeArray(rffi.USHORT, 5, hints=_h)),
+hints=_h)
+ENTRY_ARRAY = lltype.Array(
+ENTRY,
+hints={'nolength': True, 'stm_dont_track_raw_accesses': True})
 
 
 class JitCounter:
diff --git a/rpython/translator/stm/funcgen.py 
b/rpython/translator/stm/funcgen.py
--- a/rpython/translator/stm/funcgen.py
+++ b/rpython/translator/stm/funcgen.py
@@ -125,7 +125,11 @@
 try:
 info = op.args[0].value
 except IndexError:
-info = rstm.become_inevitable# cannot insert it in 'llop'
+info = ?# cannot insert it in 'llop'
+try:
+info = '%s:%s' % funcgen.graph.name
+except AttributeError:
+pass
 string_literal = c_string_constant(info)
 return 'stm_become_inevitable(stm_thread_local, %s);' % (string_literal,)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stmgc-c7: Fixed (I think): now accessing the raw data structure should not cause stm_become_inevitable, even

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: stmgc-c7
Changeset: r70285:b0f46f29bfa2
Date: 2014-03-25 17:45 +0100
http://bitbucket.org/pypy/pypy/changeset/b0f46f29bfa2/

Log:Fixed (I think): now accessing the raw data structure should not
cause stm_become_inevitable, even though the structure has nested
arrays

diff --git a/rpython/jit/metainterp/counter.py 
b/rpython/jit/metainterp/counter.py
--- a/rpython/jit/metainterp/counter.py
+++ b/rpython/jit/metainterp/counter.py
@@ -8,12 +8,15 @@
 UINT32MAX = 2 ** 32 - 1
 
 # keep in sync with the C code in pypy__decay_jit_counters
-ENTRY = lltype.Struct('timetable_entry',
-  ('times', lltype.FixedSizeArray(rffi.FLOAT, 5)),
-  ('subhashes', lltype.FixedSizeArray(rffi.USHORT, 5)),
-  hints={'stm_dont_track_raw_accesses': True})
-ENTRY_ARRAY = lltype.Array(ENTRY, hints={'nolength': True,
- 'stm_dont_track_raw_accesses': True})
+_h = {'stm_dont_track_raw_accesses': True}
+ENTRY = lltype.Struct(
+'timetable_entry',
+('times', lltype.FixedSizeArray(rffi.FLOAT, 5, hints=_h)),
+('subhashes', lltype.FixedSizeArray(rffi.USHORT, 5, hints=_h)),
+hints=_h)
+ENTRY_ARRAY = lltype.Array(
+ENTRY,
+hints={'nolength': True, 'stm_dont_track_raw_accesses': True})
 
 
 class JitCounter:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stmgc-c7: oups

2014-03-25 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: stmgc-c7
Changeset: r70288:4d60b78acf5c
Date: 2014-03-25 17:49 +0100
http://bitbucket.org/pypy/pypy/changeset/4d60b78acf5c/

Log:oups

diff --git a/rpython/translator/stm/funcgen.py 
b/rpython/translator/stm/funcgen.py
--- a/rpython/translator/stm/funcgen.py
+++ b/rpython/translator/stm/funcgen.py
@@ -127,7 +127,7 @@
 except IndexError:
 info = ?# cannot insert it in 'llop'
 try:
-info = '%s:%s' % funcgen.graph.name
+info = '%s:%s' % (funcgen.graph.name, info)
 except AttributeError:
 pass
 string_literal = c_string_constant(info)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix ndarray setitem with empty index (issue1719)

2014-03-25 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r70289:26e0a68bb6dd
Date: 2014-03-25 13:51 -0400
http://bitbucket.org/pypy/pypy/changeset/26e0a68bb6dd/

Log:fix ndarray setitem with empty index (issue1719)

diff --git a/pypy/module/micronumpy/ndarray.py 
b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -185,7 +185,7 @@
 return chunks.apply(space, self)
 shape = res_shape + self.get_shape()[len(indexes):]
 w_res = W_NDimArray.from_shape(space, shape, self.get_dtype(),
- self.get_order(), w_instance=self)
+   self.get_order(), w_instance=self)
 if not w_res.get_size():
 return w_res
 return loop.getitem_array_int(space, self, w_res, iter_shape, indexes,
@@ -201,6 +201,8 @@
 view = chunks.apply(space, self)
 view.implementation.setslice(space, val_arr)
 return
+if support.product(iter_shape) == 0:
+return
 loop.setitem_array_int(space, self, iter_shape, indexes, val_arr,
prefix)
 
@@ -1169,7 +1171,7 @@
 raise OperationError(space.w_TypeError, space.wrap(
 numpy scalars from buffers not supported yet))
 totalsize = support.product(shape) * dtype.elsize
-if totalsize+offset  buf.getlength():
+if totalsize + offset  buf.getlength():
 raise OperationError(space.w_TypeError, space.wrap(
 buffer is too small for requested array))
 storage = rffi.cast(RAW_STORAGE_PTR, raw_ptr)
diff --git a/pypy/module/micronumpy/test/test_ndarray.py 
b/pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_ndarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -2369,6 +2369,19 @@
 assert b.shape == b[...].shape
 assert (b == b[...]).all()
 
+def test_empty_indexing(self):
+import numpy as np
+r = np.ones(3)
+ind = np.array([], np.int32)
+tmp = np.array([], np.float64)
+assert r[ind].shape == (0,)
+r[ind] = 0
+assert (r == np.ones(3)).all()
+r[ind] = tmp
+assert (r == np.ones(3)).all()
+r[[]] = 0
+assert (r == np.ones(3)).all()
+
 
 class AppTestNumArrayFromBuffer(BaseNumpyAppTest):
 spaceconfig = dict(usemodules=[micronumpy, array, mmap])
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: only apply this workaround for mbcs

2014-03-25 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r70290:ba471437d878
Date: 2014-03-25 17:19 -0400
http://bitbucket.org/pypy/pypy/changeset/ba471437d878/

Log:only apply this workaround for mbcs

diff --git a/lib-python/2.7/test/test_genericpath.py 
b/lib-python/2.7/test/test_genericpath.py
--- a/lib-python/2.7/test/test_genericpath.py
+++ b/lib-python/2.7/test/test_genericpath.py
@@ -232,9 +232,11 @@
 try:
 fsencoding = test_support.TESTFN_ENCODING or ascii
 asciival = unicwd.encode(fsencoding)
-v = asciival.find('?')
-if v = 0:
-raise UnicodeEncodeError(fsencoding, unicwd, v, v, asciival)
+if fsencoding == mbcs:
+# http://bugs.python.org/issue850997
+v = asciival.find('?')
+if v = 0:
+raise UnicodeEncodeError(fsencoding, unicwd, v, v, 
asciival)
 except (AttributeError, UnicodeEncodeError):
 # FS encoding is probably ASCII or windows and codepage is 
non-Latin1
 pass
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: adapt to py3, which allows bytes or unicode here

2014-03-25 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k
Changeset: r70293:1e0b20cb98d7
Date: 2014-03-25 16:55 -0700
http://bitbucket.org/pypy/pypy/changeset/1e0b20cb98d7/

Log:adapt to py3, which allows bytes or unicode here

diff --git a/pypy/module/_codecs/test/test_codecs.py 
b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -772,10 +772,10 @@
 assert u'\u040a'.encode('mbcs') == b'?'  # some cyrillic letter
 assert b'cafx\e9'.decode('mbcs') == u'cafx\e9'
 
-def test_bad_handler_string_result(self):
+def test_handler_string_result(self):
 import _codecs
 def f(exc):
 return (b'foo', exc.end)
 _codecs.register_error(test.test_codecs_not_a_string, f)
-raises(TypeError, u'\u1234'.encode, 'ascii',
-   'test.test_codecs_not_a_string')
+result = '\u1234'.encode('ascii', 'test.test_codecs_not_a_string')
+assert result == b'foo'
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: merge default

2014-03-25 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k
Changeset: r70292:e1951a6821db
Date: 2014-03-25 16:53 -0700
http://bitbucket.org/pypy/pypy/changeset/e1951a6821db/

Log:merge default

diff --git a/lib-python/2.7/test/test_genericpath.py 
b/lib-python/2.7/test/test_genericpath.py
--- a/lib-python/2.7/test/test_genericpath.py
+++ b/lib-python/2.7/test/test_genericpath.py
@@ -231,9 +231,14 @@
 unicwd = u'\xe7w\xf0'
 try:
 fsencoding = test_support.TESTFN_ENCODING or ascii
-unicwd.encode(fsencoding)
+asciival = unicwd.encode(fsencoding)
+if fsencoding == mbcs:
+# http://bugs.python.org/issue850997
+v = asciival.find('?')
+if v = 0:
+raise UnicodeEncodeError(fsencoding, unicwd, v, v, 
asciival)
 except (AttributeError, UnicodeEncodeError):
-# FS encoding is probably ASCII
+# FS encoding is probably ASCII or windows and codepage is 
non-Latin1
 pass
 else:
 with test_support.temp_cwd(unicwd):
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -117,3 +117,13 @@
 
 .. branch: improve-consecutive-dict-lookups
 Improve the situation when dict lookups of the same key are performed in a 
chain
+
+.. branch: add_PyErr_SetFromErrnoWithFilenameObject_try_2
+.. branch: test_SetFromErrnoWithFilename_NULL
+.. branch: test_SetFromErrnoWithFilename__tweaks
+
+.. branch: refactor_PyErr_SetFromErrnoWithFilename
+Add support for PyErr_SetFromErrnoWithFilenameObject to cpyext
+
+.. branch: win32-fixes4
+fix more tests for win32
diff --git a/pypy/module/_codecs/test/test_codecs.py 
b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -1,3 +1,5 @@
+import sys
+
 class AppTestCodecs:
 spaceconfig = {
 usemodules: ['unicodedata', 'struct', 'binascii'],
@@ -138,7 +140,9 @@
 
 
 class AppTestPartialEvaluation:
-spaceconfig = dict(usemodules=('array',))
+spaceconfig = dict(usemodules=['array',])
+if sys.platform == 'win32':
+spaceconfig['usemodules'].append('_winreg')
 
 def test_partial_utf8(self):
 import _codecs
@@ -753,9 +757,25 @@
 import sys
 if sys.platform != 'win32':
 return
-assert 'test'.encode('mbcs') == b'test'
-assert 'caf\xe9'.encode('mbcs') == b'caf\xe9'
-raises(UnicodeEncodeError, '\u040a'.encode, 'mbcs')
-raises(UnicodeEncodeError,
-   -\u5171\u0141\u2661\u0363\uDC80.encode, 'mbcs')
-assert b'cafx\e9'.decode('mbcs') == 'cafx\e9'
+toencode = u'caf\xe9', b'caf\xe9'
+try:
+# test for non-latin1 codepage, more general test needed
+import _winreg
+key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
+r'System\CurrentControlSet\Control\Nls\CodePage')
+if _winreg.QueryValueEx(key, 'ACP')[0] == u'1255':  # non-latin1
+toencode = u'caf\xbf',b'caf\xbf'
+except:
+assert False, 'cannot test mbcs on this windows system, check code 
page'
+assert u'test'.encode('mbcs') == b'test'
+assert toencode[0].encode('mbcs') == toencode[1]
+assert u'\u040a'.encode('mbcs') == b'?'  # some cyrillic letter
+assert b'cafx\e9'.decode('mbcs') == u'cafx\e9'
+
+def test_bad_handler_string_result(self):
+import _codecs
+def f(exc):
+return (b'foo', exc.end)
+_codecs.register_error(test.test_codecs_not_a_string, f)
+raises(TypeError, u'\u1234'.encode, 'ascii',
+   'test.test_codecs_not_a_string')
diff --git a/pypy/module/cpyext/pyerrors.py b/pypy/module/cpyext/pyerrors.py
--- a/pypy/module/cpyext/pyerrors.py
+++ b/pypy/module/cpyext/pyerrors.py
@@ -146,14 +146,29 @@
 this is used to define the filename attribute of the exception instance.
 Return value: always NULL.
 # XXX Doesn't actually do anything with PyErr_CheckSignals.
+if llfilename:
+w_filename = rffi.charp2str(llfilename)
+filename = space.wrap(w_filename)
+else:
+filename = space.w_None
+
+PyErr_SetFromErrnoWithFilenameObject(space, w_type, filename)
+
+@cpython_api([PyObject, PyObject], PyObject)
+def PyErr_SetFromErrnoWithFilenameObject(space, w_type, w_value):
+Similar to PyErr_SetFromErrno(), with the additional behavior that if
+w_value is not NULL, it is passed to the constructor of type as a
+third parameter.  In the case of exceptions such as IOError and OSError,
+this is used to define the filename attribute of the exception instance.
+Return value: always NULL.
+# XXX Doesn't actually do anything with PyErr_CheckSignals.
 errno = get_errno()
 msg = os.strerror(errno)
-if llfilename:
-

[pypy-commit] pypy py3k: fix for 32bit platforms

2014-03-25 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: py3k
Changeset: r70291:aef46bd9f030
Date: 2014-03-25 16:38 -0700
http://bitbucket.org/pypy/pypy/changeset/aef46bd9f030/

Log:fix for 32bit platforms

diff --git a/pypy/objspace/std/test/test_smalllongobject.py 
b/pypy/objspace/std/test/test_smalllongobject.py
--- a/pypy/objspace/std/test/test_smalllongobject.py
+++ b/pypy/objspace/std/test/test_smalllongobject.py
@@ -51,7 +51,7 @@
 from pypy.interpreter import gateway
 from pypy.objspace.std.smalllongobject import W_SmallLongObject
 def w__long(space, w_obj):
-return W_SmallLongObject.fromint(space.int_w(w_obj))
+return W_SmallLongObject.frombigint(space.bigint_w(w_obj))
 cls.w__long = cls.space.wrap(gateway.interp2app(w__long))
 
 def test_sl_simple(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit