[pypy-commit] pypy default: increment default_magic for the new co_flag (oops)

2014-01-18 Thread jerith
Author: Jeremy Thurgood 
Branch: 
Changeset: r68757:9f9f78e7e299
Date: 2014-01-18 12:07 +0200
http://bitbucket.org/pypy/pypy/changeset/9f9f78e7e299/

Log:increment default_magic for the new co_flag (oops)

diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -31,7 +31,7 @@
 # Magic numbers for the bytecode version in code objects.
 # See comments in pypy/module/imp/importing.
 cpython_magic, = struct.unpack("https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy utf8-unicode: break the world, and implement W_UnicodeObject as utf8 rpython strings

2014-01-18 Thread antocuni
Author: Antonio Cuni 
Branch: utf8-unicode
Changeset: r68759:eb1500901ddf
Date: 2014-01-17 22:54 +0100
http://bitbucket.org/pypy/pypy/changeset/eb1500901ddf/

Log:break the world, and implement W_UnicodeObject as utf8 rpython
strings

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -199,7 +199,7 @@
 def str_w(self, space):
 self._typed_unwrap_error(space, "string")
 
-def unicode_w(self, space):
+def utf8_w(self, space):
 self._typed_unwrap_error(space, "unicode")
 
 def int_w(self, space):
@@ -1376,11 +1376,11 @@
  self.wrap('argument must be a string'))
 return self.str_w(w_obj)
 
-def unicode_w(self, w_obj):
-return w_obj.unicode_w(self)
+def utf8_w(self, w_obj):
+return w_obj.utf8_w(self)
 
-def unicode0_w(self, w_obj):
-"Like unicode_w, but rejects strings with NUL bytes."
+def utf8_0_w(self, w_obj):
+"Like utf8_w, but rejects strings with NUL bytes."
 from rpython.rlib import rstring
 result = w_obj.unicode_w(self)
 if u'\x00' in result:
diff --git a/pypy/interpreter/unicodehelper.py 
b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -61,3 +61,20 @@
 uni, len(uni), "strict",
 errorhandler=encode_error_handler(space),
 allow_surrogates=True)
+
+def ensure_ascii(space, s, errors='strict'):
+# ASCII is equivalent to the first 128 ordinals in Unicode.
+eh = decode_error_handler(space)
+pos = 0
+size = len(s)
+while pos < size:
+c = s[pos]
+if ord(c) >= 128:
+r, pos = eh(errors, "ascii", "ordinal not in range(128)",
+s,  pos, pos + 1)
+pos += 1
+return s
+
+def ensure_utf8(space, s, errors='strict'):
+# XXXY implement me!
+return s
diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -658,8 +658,8 @@
 if space.isinstance_w(w_sub, space.w_unicode):
 from pypy.objspace.std.unicodeobject import W_UnicodeObject
 assert isinstance(w_sub, W_UnicodeObject)
-self_as_unicode = unicode_from_encoded_object(space, self, None, 
None)
-return space.newbool(self_as_unicode._value.find(w_sub._value) >= 
0)
+self_as_utf8 = unicode_from_encoded_object(space, self, None, None)
+return space.newbool(self_as_utf8._utf8val.find(w_sub._utf8val) >= 
0)
 return self._StringMethods_descr_contains(space, w_sub)
 
 _StringMethods_descr_replace = descr_replace
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -1633,10 +1633,10 @@
 _applevel_repr = "unicode"
 
 def wrap(self, stringval):
-return self.space.wrap(stringval)
+return self.space.wrap_utf8(stringval)
 
 def unwrap(self, w_string):
-return self.space.unicode_w(w_string)
+return self.space.utf8_w(w_string)
 
 erase, unerase = rerased.new_erasing_pair("unicode")
 erase = staticmethod(erase)
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -158,7 +158,8 @@
 if isinstance(x, str):
 return wrapstr(self, x)
 if isinstance(x, unicode):
-return wrapunicode(self, x)
+# we might want to kill support for wrap(u'...') eventually
+return wrapunicode(self, x.encode('utf-8'))
 if isinstance(x, float):
 return W_FloatObject(x)
 if isinstance(x, W_Root):
@@ -181,6 +182,14 @@
 return self._wrap_not_rpython(x)
 wrap._annspecialcase_ = "specialize:wrap"
 
+def wrap_utf8(self, utf8val):
+"""
+Take an utf8-encoded RPython string an return an unicode applevel
+object
+"""
+# the constructor of W_UnicodeObject checks that it's valid UTF8
+return wrapunicode(self, utf8val)
+
 def _wrap_not_rpython(self, x):
 "NOT_RPYTHON"
 # _ this code is here to support testing only _
diff --git a/pypy/objspace/std/unicodeobject.py 
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -11,7 +11,7 @@
 from pypy.objspace.std.stdtypedef import StdTypeDef
 from pypy.objspace.std.stringmethods import StringMethods
 from rpython.rlib.objectmodel import compute_hash, compute_unique_id, 
import_from_mixin
-from rpython.rlib.rstring import UnicodeBuilder
+from rpython.rlib.rstring import StringBuilder
 from rpython.rlib.runicode import (str_decode_utf_8, str_decode_ascii,
   

[pypy-commit] pypy utf8-unicode: a branch where to implement unicode objects are utf8-encoded rpython strings

2014-01-18 Thread antocuni
Author: Antonio Cuni 
Branch: utf8-unicode
Changeset: r68758:e5291f543f0f
Date: 2014-01-17 14:35 +0100
http://bitbucket.org/pypy/pypy/changeset/e5291f543f0f/

Log:a branch where to implement unicode objects are utf8-encoded rpython
strings

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


[pypy-commit] pypy default: Try to clear up the comment

2014-01-18 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r68760:c8c63a87f605
Date: 2014-01-18 11:14 +0100
http://bitbucket.org/pypy/pypy/changeset/c8c63a87f605/

Log:Try to clear up the comment

diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -839,9 +839,9 @@
 # any number between CPython + 2 and CPython + 9.  Right now,
 # default_magic = CPython + 7.
 #
-# default_magic - 7-- used by CPython without the -U option
-# default_magic - 6-- used by CPython with the -U option
-# default_magic-- used by PyPy [because of CALL_METHOD]
+# CPython + 0  -- used by CPython without the -U option
+# CPython + 1  -- used by CPython with the -U option
+# CPython + 7 = default_magic  -- used by PyPy (incompatible!)
 #
 from pypy.interpreter.pycode import default_magic
 MARSHAL_VERSION_FOR_PYC = 2
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc c7: add spinlock implementation of reader-writer lock

2014-01-18 Thread Raemi
Author: Remi Meier 
Branch: c7
Changeset: r637:cae45c13aee6
Date: 2014-01-18 11:39 +0100
http://bitbucket.org/pypy/stmgc/changeset/cae45c13aee6/

Log:add spinlock implementation of reader-writer lock

diff --git a/c7/Makefile b/c7/Makefile
--- a/c7/Makefile
+++ b/c7/Makefile
@@ -14,9 +14,9 @@
rm -f $(BUILD_EXE) $(DEBUG_EXE) $(RELEASE_EXE)
 
 
-H_FILES = core.h list.h pagecopy.h
+H_FILES = core.h list.h pagecopy.h reader_writer_lock.h
 
-C_FILES = core.c list.c pagecopy.c
+C_FILES = core.c list.c pagecopy.c reader_writer_lock.c
 
 DEBUG = -g 
 
diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -13,6 +13,7 @@
 #include "core.h"
 #include "list.h"
 #include "pagecopy.h"
+#include "reader_writer_lock.h"
 
 
 #define NB_PAGES(256*256)// 256MB
@@ -142,41 +143,40 @@
 
 //
 
+rwticket rw_shared_lock;
+
 /* a multi-reader, single-writer lock: transactions normally take a reader
lock, so don't conflict with each other; when we need to do a global GC,
we take a writer lock to "stop the world".  Note the initializer here,
which should give the correct priority for stm_possible_safe_point(). */
-static pthread_rwlock_t rwlock_shared;
+
 
 struct tx_descriptor *in_single_thread = NULL;
 
 void stm_start_shared_lock(void)
 {
-int err = pthread_rwlock_rdlock(&rwlock_shared);
-if (err != 0)
-abort();
+rwticket_rdlock(&rw_shared_lock);
 }
 
-void stm_stop_lock(void)
+void stm_stop_shared_lock(void)
 {
-int err = pthread_rwlock_unlock(&rwlock_shared);
-if (err != 0)
-abort();
+rwticket_rdunlock(&rw_shared_lock);
+}
+
+void stm_stop_exclusive_lock(void)
+{
+rwticket_wrunlock(&rw_shared_lock);
 }
 
 void stm_start_exclusive_lock(void)
 {
-int err = pthread_rwlock_wrlock(&rwlock_shared);
-if (err != 0)
-abort();
-if (_STM_TL2->need_abort)
-stm_abort_transaction();
+rwticket_wrlock(&rw_shared_lock);
 }
 
 void _stm_start_safe_point(void)
 {
 assert(!_STM_TL2->need_abort);
-stm_stop_lock();
+stm_stop_shared_lock();
 }
 
 void _stm_stop_safe_point(void)
@@ -376,9 +376,12 @@
 uintptr_t lock_idx = (((uintptr_t)obj) >> 4) - READMARKER_START;
 uint8_t previous;
 while ((previous = __sync_lock_test_and_set(&write_locks[lock_idx], 1))) {
-usleep(1);  /* XX */
-if (!(previous = __sync_lock_test_and_set(&write_locks[lock_idx], 1))) 
-break;
+/* XX */
+//_stm_start_semi_safe_point();
+usleep(1);
+//_stm_stop_semi_safe_point();
+//if (!(previous = __sync_lock_test_and_set(&write_locks[lock_idx], 
1))) 
+//break;
 stm_abort_transaction();
 /* XXX: only abort if we are younger */
 spin_loop();
@@ -583,13 +586,8 @@
 
 
 void stm_setup(void)
-{
-pthread_rwlockattr_t attr;
-pthread_rwlockattr_init(&attr);
-pthread_rwlockattr_setkind_np(&attr,
-  
PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
-pthread_rwlock_init(&rwlock_shared, &attr);
-pthread_rwlockattr_destroy(&attr);
+{
+memset(&rw_shared_lock, 0, sizeof(rwticket));
 
 /* Check that some values are acceptable */
 assert(4096 <= ((uintptr_t)_STM_TL1));
@@ -685,8 +683,8 @@
 
 void _stm_teardown_thread(void)
 {
-assert(!pthread_rwlock_trywrlock(&rwlock_shared));
-assert(!pthread_rwlock_unlock(&rwlock_shared));
+assert(!rwticket_wrtrylock(&rw_shared_lock));
+assert(!rwticket_wrunlock(&rw_shared_lock));
 
 stm_list_free(_STM_TL2->modified_objects);
 _STM_TL2->modified_objects = NULL;
@@ -708,7 +706,6 @@
 munmap(object_pages, TOTAL_MEMORY);
 memset(flag_page_private, 0, sizeof(flag_page_private));
 memset(write_locks, 0, sizeof(write_locks));
-pthread_rwlock_destroy(&rwlock_shared);
 object_pages = NULL;
 }
 
@@ -794,7 +791,7 @@
 void stm_stop_transaction(void)
 {
 assert(_STM_TL2->running_transaction);
-stm_stop_lock();
+stm_stop_shared_lock();
 stm_start_exclusive_lock();
 
 _STM_TL1->jmpbufptr = NULL;  /* cannot abort any more */
@@ -899,7 +896,7 @@
 /* } */
 
 _STM_TL2->running_transaction = 0;
-stm_stop_lock();
+stm_stop_exclusive_lock();
 fprintf(stderr, "%c", 'C'+_STM_TL2->thread_num*32);
 }
 
@@ -978,7 +975,7 @@
 assert(_STM_TL1->jmpbufptr != NULL);
 assert(_STM_TL1->jmpbufptr != (jmpbufptr_t *)-1);   /* for tests only */
 _STM_TL2->running_transaction = 0;
-stm_stop_lock();
+stm_stop_shared_lock();
 fprintf(stderr, "%c", 'A'+_STM_TL2->thread_num*32);
 
 /* reset all the modified objects (incl. re-adding GCFLAG_WRITE_BARRIER) */
diff --git a/c7/demo2.c b/c7/demo2.c
--- a/c7/demo2.c
+++ b/c7/demo2.c
@@ -57,7 +57,9 @@
 r_n = r_n->next;
 stm_read((objptr_t)r_n);
 sum += r_n->value;
-
+
+_stm_start_safe_point();

[pypy-commit] pypy default: Fix strbufobject.

2014-01-18 Thread Manuel Jacob
Author: Manuel Jacob
Branch: 
Changeset: r68761:286528b6716e
Date: 2014-01-18 12:16 +0100
http://bitbucket.org/pypy/pypy/changeset/286528b6716e/

Log:Fix strbufobject.

diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -633,9 +633,15 @@
 return space.add(self_as_bytearray, w_other)
 if space.config.objspace.std.withstrbuf:
 from pypy.objspace.std.strbufobject import W_StringBufferObject
+try:
+other = self._op_val(space, w_other)
+except OperationError, e:
+if e.match(space, space.w_TypeError):
+return space.w_NotImplemented
+raise
 builder = StringBuilder()
 builder.append(self._value)
-builder.append(self._op_val(space, w_other))
+builder.append(other)
 return W_StringBufferObject(builder)
 return self._StringMethods_descr_add(space, w_other)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc c7: makefile update

2014-01-18 Thread Raemi
Author: Remi Meier 
Branch: c7
Changeset: r638:1c101c79f4dd
Date: 2014-01-18 12:40 +0100
http://bitbucket.org/pypy/stmgc/changeset/1c101c79f4dd/

Log:makefile update

diff --git a/c7/Makefile b/c7/Makefile
--- a/c7/Makefile
+++ b/c7/Makefile
@@ -24,4 +24,6 @@
 # note that we don't say -DNDEBUG, so that asserts should still be compiled in
 # also, all debug code with extra checks but not the debugprints
 build-%: %.c ${H_FILES} ${C_FILES} 
-   clang -pthread  -g  $< -o build-$* -Wall ${C_FILES}
+   clang -pthread  -g -O1  $< -o build-$* -Wall ${C_FILES}
+release-%: %.c ${H_FILES} ${C_FILES} 
+   clang -pthread  -g -DNDEBUG -O2 $< -o release-$* -Wall ${C_FILES}
diff --git a/c7/demo2.c b/c7/demo2.c
--- a/c7/demo2.c
+++ b/c7/demo2.c
@@ -7,7 +7,7 @@
 #include "core.h"
 
 
-#define LIST_LENGTH 5000
+#define LIST_LENGTH 6000
 #define BUNCH   400
 
 typedef TLPREFIX struct node_s node_t;
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy llvm-translation-backend: Fix datalayout fishing.

2014-01-18 Thread Manuel Jacob
Author: Manuel Jacob
Branch: llvm-translation-backend
Changeset: r68762:2870c4a2d133
Date: 2014-01-18 13:25 +0100
http://bitbucket.org/pypy/pypy/changeset/2870c4a2d133/

Log:Fix datalayout fishing.

diff --git a/rpython/translator/llvm/genllvm.py 
b/rpython/translator/llvm/genllvm.py
--- a/rpython/translator/llvm/genllvm.py
+++ b/rpython/translator/llvm/genllvm.py
@@ -1738,7 +1738,9 @@
 output = cmdexec('clang -emit-llvm -S -x c {} -o -'
 .format(devnull))
 self._parse_datalayout(output)
-f.write(output)
+for line in output.splitlines(True):
+if line.startswith('target '):
+f.write(line)
 
 database = Database(self, f)
 self._write_special_declarations(f)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc c7: add files...

2014-01-18 Thread Raemi
Author: Remi Meier 
Branch: c7
Changeset: r639:cf5b0f66205f
Date: 2014-01-18 13:44 +0100
http://bitbucket.org/pypy/stmgc/changeset/cf5b0f66205f/

Log:add files...

diff --git a/c7/reader_writer_lock.c b/c7/reader_writer_lock.c
new file mode 100644
--- /dev/null
+++ b/c7/reader_writer_lock.c
@@ -0,0 +1,93 @@
+/* Taken from: http://locklessinc.com/articles/locks/
+   
+   Sticking to semi-portable C code, we can still do a little better.
+   There exists a form of the ticket lock that is designed for read-write
+   locks. An example written in assembly was posted to the Linux kernel
+   mailing list in 2002 by David Howells from RedHat. This was a highly
+   optimized version of a read-write ticket lock developed at IBM in the
+   early 90's by Joseph Seigh. Note that a similar (but not identical)
+   algorithm was published by John Mellor-Crummey and Michael Scott in
+   their landmark paper "Scalable Reader-Writer Synchronization for
+   Shared-Memory Multiprocessors". Converting the algorithm from
+   assembly language to C yields:
+*/
+
+#include "reader_writer_lock.h"
+
+
+#define EBUSY 1
+#define atomic_xadd(P, V) __sync_fetch_and_add((P), (V))
+#define cmpxchg(P, O, N) __sync_val_compare_and_swap((P), (O), (N))
+#define atomic_inc(P) __sync_add_and_fetch((P), 1)
+#define atomic_dec(P) __sync_add_and_fetch((P), -1) 
+#define atomic_add(P, V) __sync_add_and_fetch((P), (V))
+#define atomic_set_bit(P, V) __sync_or_and_fetch((P), 1<<(V))
+#define atomic_clear_bit(P, V) __sync_and_and_fetch((P), ~(1<<(V)))
+/* Compile read-write barrier */
+#define barrier() asm volatile("": : :"memory")
+
+/* Pause instruction to prevent excess processor bus usage */ 
+#define cpu_relax() asm volatile("pause\n": : :"memory")
+
+
+
+void rwticket_wrlock(rwticket *l)
+{
+   unsigned me = atomic_xadd(&l->u, (1<<16));
+   unsigned char val = me >> 16;
+   
+   while (val != l->s.write) cpu_relax();
+}
+
+int rwticket_wrunlock(rwticket *l)
+{
+   rwticket t = *l;
+   
+   barrier();
+
+   t.s.write++;
+   t.s.read++;
+   
+   *(unsigned short *) l = t.us;
+return 0;
+}
+
+int rwticket_wrtrylock(rwticket *l)
+{
+   unsigned me = l->s.users;
+   unsigned char menew = me + 1;
+   unsigned read = l->s.read << 8;
+   unsigned cmp = (me << 16) + read + me;
+   unsigned cmpnew = (menew << 16) + read + me;
+
+   if (cmpxchg(&l->u, cmp, cmpnew) == cmp) return 0;
+   
+   return EBUSY;
+}
+
+void rwticket_rdlock(rwticket *l)
+{
+   unsigned me = atomic_xadd(&l->u, (1<<16));
+   unsigned char val = me >> 16;
+   
+   while (val != l->s.read) cpu_relax();
+   l->s.read++;
+}
+
+void rwticket_rdunlock(rwticket *l)
+{
+   atomic_inc(&l->s.write);
+}
+
+int rwticket_rdtrylock(rwticket *l)
+{
+   unsigned me = l->s.users;
+   unsigned write = l->s.write;
+   unsigned char menew = me + 1;
+   unsigned cmp = (me << 16) + (me << 8) + write;
+   unsigned cmpnew = ((unsigned) menew << 16) + (menew << 8) + write;
+
+   if (cmpxchg(&l->u, cmp, cmpnew) == cmp) return 0;
+   
+   return EBUSY;
+}
diff --git a/c7/reader_writer_lock.h b/c7/reader_writer_lock.h
new file mode 100644
--- /dev/null
+++ b/c7/reader_writer_lock.h
@@ -0,0 +1,22 @@
+
+typedef union rwticket rwticket;
+union rwticket
+{
+   unsigned u;
+   unsigned short us;
+   struct
+   {
+   unsigned char write;
+   unsigned char read;
+   unsigned char users;
+   } s;
+};
+
+void rwticket_wrlock(rwticket *l);
+int rwticket_wrunlock(rwticket *l);
+int rwticket_wrtrylock(rwticket *l);
+void rwticket_rdlock(rwticket *l);
+void rwticket_rdunlock(rwticket *l);
+int rwticket_rdtrylock(rwticket *l);
+
+
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Copy the CPython-style error messages more closely

2014-01-18 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r68763:3f01d4d55bcc
Date: 2014-01-18 14:44 +0100
http://bitbucket.org/pypy/pypy/changeset/3f01d4d55bcc/

Log:Copy the CPython-style error messages more closely

diff --git a/rpython/rlib/runicode.py b/rpython/rlib/runicode.py
--- a/rpython/rlib/runicode.py
+++ b/rpython/rlib/runicode.py
@@ -153,7 +153,7 @@
 # about the pos anymore and we just ignore the value
 if not charsleft:
 # there's only the start byte and nothing else
-r, pos = errorhandler(errors, 'utf-8',
+r, pos = errorhandler(errors, 'utf8',
   'unexpected end of data',
   s, pos, pos+1)
 result.append(r)
@@ -165,14 +165,14 @@
 (ordch1 == 0xe0 and ordch2 < 0xa0)):
 # or (ordch1 == 0xed and ordch2 > 0x9f)
 # second byte invalid, take the first and continue
-r, pos = errorhandler(errors, 'utf-8',
+r, pos = errorhandler(errors, 'utf8',
   'invalid continuation byte',
   s, pos, pos+1)
 result.append(r)
 continue
 else:
 # second byte valid, but third byte missing
-r, pos = errorhandler(errors, 'utf-8',
+r, pos = errorhandler(errors, 'utf8',
   'unexpected end of data',
   s, pos, pos+2)
 result.append(r)
@@ -183,28 +183,28 @@
 (ordch1 == 0xf0 and ordch2 < 0x90) or
 (ordch1 == 0xf4 and ordch2 > 0x8f)):
 # second byte invalid, take the first and continue
-r, pos = errorhandler(errors, 'utf-8',
+r, pos = errorhandler(errors, 'utf8',
   'invalid continuation byte',
   s, pos, pos+1)
 result.append(r)
 continue
 elif charsleft == 2 and ord(s[pos+2])>>6 != 0x2:   # 0b10
 # third byte invalid, take the first two and continue
-r, pos = errorhandler(errors, 'utf-8',
+r, pos = errorhandler(errors, 'utf8',
   'invalid continuation byte',
   s, pos, pos+2)
 result.append(r)
 continue
 else:
 # there's only 1 or 2 valid cb, but the others are missing
-r, pos = errorhandler(errors, 'utf-8',
+r, pos = errorhandler(errors, 'utf8',
   'unexpected end of data',
   s, pos, pos+charsleft+1)
 result.append(r)
 break
 
 if n == 0:
-r, pos = errorhandler(errors, 'utf-8',
+r, pos = errorhandler(errors, 'utf8',
   'invalid start byte',
   s, pos, pos+1)
 result.append(r)
@@ -215,7 +215,7 @@
 elif n == 2:
 ordch2 = ord(s[pos+1])
 if ordch2>>6 != 0x2:   # 0b10
-r, pos = errorhandler(errors, 'utf-8',
+r, pos = errorhandler(errors, 'utf8',
   'invalid continuation byte',
   s, pos, pos+1)
 result.append(r)
@@ -233,13 +233,13 @@
 # surrogates shouldn't be valid UTF-8!
 or (not allow_surrogates and ordch1 == 0xed and ordch2 > 0x9f)
 ):
-r, pos = errorhandler(errors, 'utf-8',
+r, pos = errorhandler(errors, 'utf8',
   'invalid continuation byte',
   s, pos, pos+1)
 result.append(r)
 continue
 elif ordch3>>6 != 0x2: # 0b10
-r, pos = errorhandler(errors, 'utf-8',
+r, pos = errorhandler(errors, 'utf8',
   'invalid continuation byte',
   s, pos, pos+2)
 result.append(r)
@@ -257,19 +257,19 @@
 if (ordch2>>6 != 0x2 or # 0b10
 (ordch1 == 0xf0 and ordch2 < 0x90) or
 (ordch1 == 0xf4 and ordch2 > 0x8f)):
-r, pos = errorhandler(errors, 'utf-8',
+r, pos = errorhandler(errors, 'utf8',
   'invalid continuation byte',
   s, pos, pos+1)
 result.append(r)
 continue
  

[pypy-commit] stmgc c7: in-progress

2014-01-18 Thread arigo
Author: Armin Rigo 
Branch: c7
Changeset: r640:d1bebba84ce9
Date: 2014-01-18 15:35 +0100
http://bitbucket.org/pypy/stmgc/changeset/d1bebba84ce9/

Log:in-progress

diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -219,6 +219,11 @@
 return o;
 }
 
+object_t *stm_allocate_prebuilt(size_t size)
+{
+return _stm_allocate_old(size);  /* XXX */
+}
+
 
 static void _stm_privatize(uintptr_t pagenum)
 {
diff --git a/c7/core.h b/c7/core.h
--- a/c7/core.h
+++ b/c7/core.h
@@ -1,6 +1,7 @@
 #ifndef _STM_CORE_H
 #define _STM_CORE_H
 
+#include 
 #include 
 #include 
 
@@ -117,6 +118,8 @@
 bool _stm_is_young(object_t *o);
 object_t *_stm_allocate_old(size_t size);
 
+object_t *stm_allocate_prebuilt(size_t size);
+
 void _stm_start_safe_point(void);
 void _stm_stop_safe_point(void);
 
diff --git a/duhton/Makefile b/duhton/Makefile
--- a/duhton/Makefile
+++ b/duhton/Makefile
@@ -1,11 +1,16 @@
+
+C7SOURCES = ../c7/core.c \
+../c7/pagecopy.c \
+../c7/list.c \
+../c7/reader_writer_lock.c
 
 all: duhton_debug duhton
 
 duhton: *.c *.h ../c4/*.c ../c4/*.h
-   gcc -pthread -g -O2 -o duhton *.c ../c4/stmgc.c -Wall -lrt 
+   clang -pthread -g -O2 -o duhton *.c $(C7SOURCES) -Wall
 
 duhton_debug: *.c *.h ../c4/*.c ../c4/*.h
-   gcc -pthread -g -DDu_DEBUG -D_GC_DEBUGPRINTS=1 -DGC_NURSERY=2048 -o 
duhton_debug *.c ../c4/stmgc.c -Wall -lrt 
+   clang -pthread -g -DDu_DEBUG -o duhton_debug *.c $(C7SOURCES) -Wall
 
 clean:
rm -f duhton duhton_debug
diff --git a/duhton/README b/duhton/README
--- a/duhton/README
+++ b/duhton/README
@@ -16,3 +16,12 @@
 There are demos: try "time duhton demo/many_square_roots.duh".
 
 For more general information see the PAPERS file.
+
+
+
+
+
+XXX
+===
+
+* remove _du_read1() on immutable objects
diff --git a/duhton/consobject.c b/duhton/consobject.c
--- a/duhton/consobject.c
+++ b/duhton/consobject.c
@@ -1,10 +1,10 @@
 #include "duhton.h"
 
 
-void cons_trace(DuConsObject *ob, void visit(gcptr *))
+void cons_trace(struct DuConsObject_s *ob, void visit(object_t **))
 {
-visit(&ob->car);
-visit(&ob->cdr);
+visit((object_t **)&ob->car);
+visit((object_t **)&ob->cdr);
 }
 
 void cons_print(DuConsObject *ob)
diff --git a/duhton/containerobject.c b/duhton/containerobject.c
--- a/duhton/containerobject.c
+++ b/duhton/containerobject.c
@@ -1,14 +1,14 @@
 #include "duhton.h"
 
-typedef struct {
-DuOBJECT_HEAD
+typedef TLPREFIX struct DuContainerObject_s {
+DuOBJECT_HEAD1
 DuObject *ob_reference;
 } DuContainerObject;
 
 
-void container_trace(DuContainerObject *ob, void visit(gcptr *))
+void container_trace(struct DuContainerObject_s *ob, void visit(object_t **))
 {
-visit(&ob->ob_reference);
+visit((object_t **)&ob->ob_reference);
 }
 
 void container_print(DuContainerObject *ob)
diff --git a/duhton/duhton.c b/duhton/duhton.c
--- a/duhton/duhton.c
+++ b/duhton/duhton.c
@@ -1,3 +1,4 @@
+#include 
 #include "duhton.h"
 
 #define DEFAULT_NUM_THREADS 4
diff --git a/duhton/duhton.h b/duhton/duhton.h
--- a/duhton/duhton.h
+++ b/duhton/duhton.h
@@ -1,18 +1,20 @@
 #ifndef _DUHTON_H_
 #define _DUHTON_H_
 
-#include "../c4/stmgc.h"
-#include "../c4/fprintcolor.h"
+#include "../c7/core.h"
 #include 
 #include 
 #include 
 
 
-typedef struct stm_object_s DuObject;
+struct DuObject_s {
+struct object_s header;
+uint32_t type_id;
+};
+typedef TLPREFIX struct DuObject_s DuObject;
 
-#define DuOBJECT_HEAD   DuObject ob_base;
 
-#define DuOBJECT_HEAD_INIT(type)   { type | PREBUILT_FLAGS, PREBUILT_REVISION }
+#define DuOBJECT_HEAD1   DuObject ob_base;
 
 
 #ifdef __GNUC__
@@ -22,8 +24,8 @@
 #endif
 
 
-typedef void(*trace_fn)(DuObject *, void visit(gcptr *));
-typedef size_t(*bytesize_fn)(DuObject *);
+typedef void(*trace_fn)(struct DuObject_s *, void visit(object_t **));
+typedef size_t(*bytesize_fn)(struct DuObject_s *);
 typedef void(*print_fn)(DuObject *);
 typedef DuObject *(*eval_fn)(DuObject *, DuObject *);
 typedef int(*len_fn)(DuObject *);
@@ -71,10 +73,9 @@
 int DuObject_Length(DuObject *ob);
 
 
-extern DuObject _Du_NoneStruct;
-#define Du_None (&_Du_NoneStruct)
+extern DuObject *Du_None;
 
-#define _DuObject_TypeNum(ob) stm_get_tid((DuObject*)(ob))
+#define _DuObject_TypeNum(ob) (((DuObject*)(ob))->type_id)
 #define Du_TYPE(ob)   (Du_Types[_DuObject_TypeNum(ob)])
 #define DuInt_Check(ob)   (_DuObject_TypeNum(ob) == DUTYPE_INT)
 #define DuSymbol_Check(ob)(_DuObject_TypeNum(ob) == DUTYPE_SYMBOL)
@@ -107,9 +108,10 @@
 
 DuObject *DuSymbol_FromString(const char *name);
 char *DuSymbol_AsString(DuObject *ob);
+int DuSymbol_Id(DuObject *ob);
 
-typedef struct {
-DuOBJECT_HEAD
+typedef TLPREFIX struct DuConsObject_s {
+DuOBJECT_HEAD1
 DuObject *car, *cdr;
 } DuConsObject;
 
@@ -136,11 +138,10 @@
  DuObject *arglist, DuObject *progn);
 DuObject *_DuFrame_EvalCall(DuObject *frame, DuObject *symbol,
 DuObject *rest

[pypy-commit] stmgc c7: getting closer

2014-01-18 Thread arigo
Author: Armin Rigo 
Branch: c7
Changeset: r641:1de3c5245ed2
Date: 2014-01-18 16:29 +0100
http://bitbucket.org/pypy/stmgc/changeset/1de3c5245ed2/

Log:getting closer

diff --git a/c7/core.h b/c7/core.h
--- a/c7/core.h
+++ b/c7/core.h
@@ -124,7 +124,8 @@
 void _stm_stop_safe_point(void);
 
 void stm_abort_transaction(void);
+
+#define stm_become_inevitable(msg)   /* XXX implement me! */
+
+
 #endif
-
-
-
diff --git a/duhton/duhton.c b/duhton/duhton.c
--- a/duhton/duhton.c
+++ b/duhton/duhton.c
@@ -42,17 +42,22 @@
 printf("))) ");
 fflush(stdout);
 }
+stm_start_transaction(NULL);
 DuObject *code = Du_Compile(filename, interactive);
+stm_stop_transaction();
 if (code == NULL) {
 printf("\n");
 break;
 }
 /*Du_Print(code, 1);
   printf("\n");*/
+stm_start_transaction(NULL);
 DuObject *res = Du_Eval(code, Du_Globals);
 if (interactive) {
 Du_Print(res, 1);
 }
+stm_stop_transaction();
+
 Du_TransactionRun();
 if (!interactive)
 break;
diff --git a/duhton/glob.c b/duhton/glob.c
--- a/duhton/glob.c
+++ b/duhton/glob.c
@@ -610,16 +610,30 @@
 }
 
 extern void init_prebuilt_frame_objects(void);
+extern void init_prebuilt_list_objects(void);
+extern void init_prebuilt_object_objects(void);
+extern void init_prebuilt_symbol_objects(void);
+extern void init_prebuilt_transaction_objects(void);
 
 void Du_Initialize(int num_threads)
 {
-stm_initialize();
+assert(num_threads == 2);
 
+stm_setup();
+stm_setup_thread();
+stm_setup_thread();
+_stm_restore_local_state(0);
+
+init_prebuilt_object_objects();
+init_prebuilt_symbol_objects();
+init_prebuilt_list_objects();
 init_prebuilt_frame_objects();
+init_prebuilt_transaction_objects();
 
 all_threads_count = num_threads;
 all_threads = (pthread_t*)malloc(sizeof(pthread_t) * num_threads);
 
+stm_start_transaction(NULL);
 DuFrame_SetBuiltinMacro(Du_Globals, "progn", Du_Progn);
 DuFrame_SetBuiltinMacro(Du_Globals, "setq", du_setq);
 DuFrame_SetBuiltinMacro(Du_Globals, "print", du_print);
@@ -655,9 +669,16 @@
 DuFrame_SetBuiltinMacro(Du_Globals, "pair?", du_pair);
 DuFrame_SetBuiltinMacro(Du_Globals, "assert", du_assert);
 DuFrame_SetSymbolStr(Du_Globals, "None", Du_None);
+stm_stop_transaction();
 }
 
 void Du_Finalize(void)
 {
-stm_finalize();
+_stm_restore_local_state(1);
+_stm_teardown_thread();
+
+_stm_restore_local_state(0);
+_stm_teardown_thread();
+
+_stm_teardown();
 }
diff --git a/duhton/intobject.c b/duhton/intobject.c
--- a/duhton/intobject.c
+++ b/duhton/intobject.c
@@ -1,7 +1,7 @@
 #include "duhton.h"
 
-typedef struct {
-DuOBJECT_HEAD
+typedef TLPREFIX struct DuIntObject_s {
+DuOBJECT_HEAD1
 int ob_intval;
 } DuIntObject;
 
diff --git a/duhton/listobject.c b/duhton/listobject.c
--- a/duhton/listobject.c
+++ b/duhton/listobject.c
@@ -5,34 +5,34 @@
 /* 'tuple' objects are only used internally as the current items
of 'list' objects
 */
-typedef struct {
-DuOBJECT_HEAD
+typedef TLPREFIX struct DuTupleObject_s {
+DuOBJECT_HEAD1
 int ob_count;
 DuObject *ob_items[1];
 } DuTupleObject;
 
-typedef struct {
-DuOBJECT_HEAD
+typedef TLPREFIX struct DuListObject_s {
+DuOBJECT_HEAD1
 DuTupleObject *ob_tuple;
 } DuListObject;
 
 
-void tuple_trace(DuTupleObject *ob, void visit(gcptr *))
+void tuple_trace(struct DuTupleObject_s *ob, void visit(object_t **))
 {
 int i;
 for (i=ob->ob_count-1; i>=0; i--) {
-visit(&ob->ob_items[i]);
+visit((object_t **)&ob->ob_items[i]);
 }
 }
 
-size_t tuple_bytesize(DuTupleObject *ob)
+size_t tuple_bytesize(struct DuTupleObject_s *ob)
 {
 return sizeof(DuTupleObject) + (ob->ob_count - 1) * sizeof(DuObject *);
 }
 
-void list_trace(DuListObject *ob, void visit(gcptr *))
+void list_trace(struct DuListObject_s *ob, void visit(object_t **))
 {
-visit((gcptr *)&ob->ob_tuple);
+visit((object_t **)&ob->ob_tuple);
 }
 
 void list_print(DuListObject *ob)
@@ -68,7 +68,8 @@
 {
 DuTupleObject *ob;
 size_t size = sizeof(DuTupleObject) + (length-1)*sizeof(DuObject *);
-ob = (DuTupleObject *)stm_allocate(size, DUTYPE_TUPLE);
+ob = (DuTupleObject *)stm_allocate(size);
+ob->ob_base.type_id = DUTYPE_TUPLE;
 ob->ob_count = length;
 return ob;
 }
@@ -187,10 +188,18 @@
 
 static DuTupleObject *du_empty_tuple;
 
+void init_prebuilt_list_objects(void)
+{
+du_empty_tuple = (DuTupleObject *)
+stm_allocate_prebuilt(sizeof(DuTupleObject));
+du_empty_tuple->ob_base.type_id = DUTYPE_TUPLE;
+du_empty_tuple->ob_count = 0;
+}
+
 DuObject *DuList_New()
 {
 DuListObject *ob = (DuListObject *)DuObject_New(&DuList_Type);
-ob->ob_tuple = &du_empty_tuple;
+ob->ob_tuple = du_empty_tuple;
 return (DuObject *)ob;
 }
 
diff --git a/duhton/object

[pypy-commit] stmgc c7: tweaks

2014-01-18 Thread arigo
Author: Armin Rigo 
Branch: c7
Changeset: r642:65db74df8ff6
Date: 2014-01-18 16:48 +0100
http://bitbucket.org/pypy/stmgc/changeset/65db74df8ff6/

Log:tweaks

diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -19,7 +19,7 @@
 #define NB_PAGES(256*256)// 256MB
 #define NB_THREADS  2
 #define MAP_PAGES_FLAGS (MAP_SHARED | MAP_ANONYMOUS | MAP_NORESERVE)
-#define LARGE_OBJECT_WORDS  36
+#define LARGE_OBJECT_WORDS  220  // XXX was 36
 #define NB_NURSERY_PAGES1024
 #define LENGTH_SHADOW_STACK   163840
 
diff --git a/duhton/Makefile b/duhton/Makefile
--- a/duhton/Makefile
+++ b/duhton/Makefile
@@ -4,12 +4,15 @@
 ../c7/list.c \
 ../c7/reader_writer_lock.c
 
+C7HEADERS = ../c7/*.h
+
+
 all: duhton_debug duhton
 
-duhton: *.c *.h ../c4/*.c ../c4/*.h
+duhton: *.c *.h $(C7SOURCES) $(C7HEADERS)
clang -pthread -g -O2 -o duhton *.c $(C7SOURCES) -Wall
 
-duhton_debug: *.c *.h ../c4/*.c ../c4/*.h
+duhton_debug: *.c *.h $(C7SOURCES) $(C7HEADERS)
clang -pthread -g -DDu_DEBUG -o duhton_debug *.c $(C7SOURCES) -Wall
 
 clean:
diff --git a/duhton/duhton.c b/duhton/duhton.c
--- a/duhton/duhton.c
+++ b/duhton/duhton.c
@@ -1,7 +1,7 @@
 #include 
 #include "duhton.h"
 
-#define DEFAULT_NUM_THREADS 4
+#define DEFAULT_NUM_THREADS 2
 
 int main(int argc, char **argv)
 {
diff --git a/duhton/duhton.h b/duhton/duhton.h
--- a/duhton/duhton.h
+++ b/duhton/duhton.h
@@ -67,6 +67,8 @@
 
 extern DuType *Du_Types[_DUTYPE_TOTAL];
 
+#define ROUND_UP(size)  ((size) < 16 ? 16 : ((size) + 7) & ~7)
+
 
 DuObject *DuObject_New(DuType *tp);
 int DuObject_IsTrue(DuObject *ob);
diff --git a/duhton/object.c b/duhton/object.c
--- a/duhton/object.c
+++ b/duhton/object.c
@@ -23,7 +23,7 @@
 size_t result = tp->dt_size;
 if (result == 0)
 result = tp->dt_bytesize((struct DuObject_s *)obj);
-return result;
+return ROUND_UP(result);
 }
 
 /* callback: trace the content of an object */
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc c7: fixes until minimal.duh works

2014-01-18 Thread arigo
Author: Armin Rigo 
Branch: c7
Changeset: r643:d3f5c236e429
Date: 2014-01-18 17:13 +0100
http://bitbucket.org/pypy/stmgc/changeset/d3f5c236e429/

Log:fixes until minimal.duh works

diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -543,6 +543,7 @@
 item->stm_flags |= GCFLAG_WRITE_BARRIER;
 
 stmcb_trace(real_address(item), trace_if_young);
+old_objs = _STM_TL2->old_objects_to_trace;
 }
 
 
diff --git a/duhton/duhton.c b/duhton/duhton.c
--- a/duhton/duhton.c
+++ b/duhton/duhton.c
@@ -44,7 +44,9 @@
 }
 stm_start_transaction(NULL);
 DuObject *code = Du_Compile(filename, interactive);
+_du_save1(code);
 stm_stop_transaction();
+_du_restore1(code);
 if (code == NULL) {
 printf("\n");
 break;
diff --git a/duhton/object.c b/duhton/object.c
--- a/duhton/object.c
+++ b/duhton/object.c
@@ -39,7 +39,7 @@
 DuObject *DuObject_New(DuType *tp)
 {
 assert(tp->dt_size >= sizeof(DuObject));
-DuObject *ob = (DuObject *)stm_allocate(tp->dt_size);
+DuObject *ob = (DuObject *)stm_allocate(ROUND_UP(tp->dt_size));
 assert(ob);
 ob->type_id = tp->dt_typeindex;
 return ob;
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc c7: fix warning

2014-01-18 Thread Raemi
Author: Remi Meier 
Branch: c7
Changeset: r644:ccf30dfc88db
Date: 2014-01-18 17:14 +0100
http://bitbucket.org/pypy/stmgc/changeset/ccf30dfc88db/

Log:fix warning

diff --git a/duhton/duhton.h b/duhton/duhton.h
--- a/duhton/duhton.h
+++ b/duhton/duhton.h
@@ -14,7 +14,7 @@
 typedef TLPREFIX struct DuObject_s DuObject;
 
 
-#define DuOBJECT_HEAD1   DuObject ob_base;
+#define DuOBJECT_HEAD1   struct DuObject_s ob_base;
 
 
 #ifdef __GNUC__
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc c7: fix

2014-01-18 Thread Raemi
Author: Remi Meier 
Branch: c7
Changeset: r645:53410d7b096d
Date: 2014-01-18 17:33 +0100
http://bitbucket.org/pypy/stmgc/changeset/53410d7b096d/

Log:fix

diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -19,7 +19,7 @@
 #define NB_PAGES(256*256)// 256MB
 #define NB_THREADS  2
 #define MAP_PAGES_FLAGS (MAP_SHARED | MAP_ANONYMOUS | MAP_NORESERVE)
-#define LARGE_OBJECT_WORDS  220  // XXX was 36
+#define LARGE_OBJECT_WORDS  230  // XXX was 36
 #define NB_NURSERY_PAGES1024
 #define LENGTH_SHADOW_STACK   163840
 
diff --git a/duhton/duhton.c b/duhton/duhton.c
--- a/duhton/duhton.c
+++ b/duhton/duhton.c
@@ -58,7 +58,9 @@
 if (interactive) {
 Du_Print(res, 1);
 }
+_du_save1(stm_thread_local_obj);
 stm_stop_transaction();
+_du_restore1(stm_thread_local_obj);
 
 Du_TransactionRun();
 if (!interactive)
diff --git a/duhton/duhton.h b/duhton/duhton.h
--- a/duhton/duhton.h
+++ b/duhton/duhton.h
@@ -188,4 +188,5 @@
 extern pthread_t *all_threads;
 extern int all_threads_count;
 
+extern __thread DuObject *stm_thread_local_obj;  /* XXX temp */
 #endif  /* _DUHTON_H_ */
diff --git a/duhton/transaction.c b/duhton/transaction.c
--- a/duhton/transaction.c
+++ b/duhton/transaction.c
@@ -64,6 +64,7 @@
 _du_write1(root);
 root->cdr = stm_thread_local_obj;
 stm_stop_transaction();
+
 stm_thread_local_obj = NULL;
 
 run_all_threads();
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc c7: push limit even higher

2014-01-18 Thread Raemi
Author: Remi Meier 
Branch: c7
Changeset: r646:034be314c0b8
Date: 2014-01-18 17:36 +0100
http://bitbucket.org/pypy/stmgc/changeset/034be314c0b8/

Log:push limit even higher

diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -19,7 +19,7 @@
 #define NB_PAGES(256*256)// 256MB
 #define NB_THREADS  2
 #define MAP_PAGES_FLAGS (MAP_SHARED | MAP_ANONYMOUS | MAP_NORESERVE)
-#define LARGE_OBJECT_WORDS  230  // XXX was 36
+#define LARGE_OBJECT_WORDS  232  // XXX was 36
 #define NB_NURSERY_PAGES1024
 #define LENGTH_SHADOW_STACK   163840
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc c7: add some safepoint somewhere

2014-01-18 Thread Raemi
Author: Remi Meier 
Branch: c7
Changeset: r647:2296dea545e3
Date: 2014-01-18 17:44 +0100
http://bitbucket.org/pypy/stmgc/changeset/2296dea545e3/

Log:add some safepoint somewhere

diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -570,6 +570,8 @@
 
 object_t *stm_allocate(size_t size)
 {
+_stm_start_safe_point();
+_stm_stop_safe_point();
 assert(_STM_TL2->running_transaction);
 assert(size % 8 == 0);
 size_t i = size / 8;
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: An extra test

2014-01-18 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r1455:22a6af557fbc
Date: 2014-01-14 14:17 +0100
http://bitbucket.org/cffi/cffi/changeset/22a6af557fbc/

Log:An extra test

diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -1855,3 +1855,24 @@
 
 def test_various_calls_libffi():
 _test_various_calls(force_libffi=True)
+
+def test_ptr_to_opaque():
+ffi = FFI()
+ffi.cdef("typedef ... foo_t; int f1(foo_t*); foo_t *f2(int);")
+lib = ffi.verify("""
+#include 
+typedef struct { int x; } foo_t;
+int f1(foo_t* p) {
+int x = p->x;
+free(p);
+return x;
+}
+foo_t *f2(int x) {
+foo_t *p = malloc(sizeof(foo_t));
+p->x = x;
+return p;
+}
+""")
+p = lib.f2(42)
+x = lib.f1(p)
+assert x == 42
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Fix

2014-01-18 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r1456:7eb548fec961
Date: 2014-01-18 18:39 +0100
http://bitbucket.org/cffi/cffi/changeset/7eb548fec961/

Log:Fix

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -3785,6 +3785,7 @@
 PyErr_Format(PyExc_TypeError,
  "field '%s.%s' is declared with :0",
  ct->ct_name, PyText_AS_UTF8(fname));
+goto error;
 }
 if (!(sflags & SF_MSVC_BITFIELDS)) {
 /* GCC's notion of "ftype :0;" */
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy annotator: Rename FlowSpaceFrame to FlowContext

2014-01-18 Thread rlamy
Author: Ronan Lamy 
Branch: annotator
Changeset: r68764:5a3e82f87ef9
Date: 2014-01-18 20:07 +
http://bitbucket.org/pypy/pypy/changeset/5a3e82f87ef9/

Log:Rename FlowSpaceFrame to FlowContext

diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -23,13 +23,13 @@
 
 class FlowingError(Exception):
 """ Signals invalid RPython in the function being analysed"""
-frame = None
+ctx = None
 
 def __str__(self):
 msg = ["\n"]
 msg += map(str, self.args)
 msg += [""]
-msg += source_lines(self.frame.graph, None, 
offset=self.frame.last_instr)
+msg += source_lines(self.ctx.graph, None, offset=self.ctx.last_instr)
 return "\n".join(msg)
 
 class StopFlowing(Exception):
@@ -116,7 +116,7 @@
 def append(self, operation):
 raise NotImplementedError
 
-def guessbool(self, frame, w_condition):
+def guessbool(self, ctx, w_condition):
 raise AssertionError("cannot guessbool(%s)" % (w_condition,))
 
 
@@ -132,13 +132,13 @@
 def append(self, operation):
 self.crnt_block.operations.append(operation)
 
-def guessbool(self, frame, w_condition):
+def guessbool(self, ctx, w_condition):
 block = self.crnt_block
 vars = block.getvariables()
 links = []
 for case in [False, True]:
 egg = EggBlock(vars, block, case)
-frame.pendingblocks.append(egg)
+ctx.pendingblocks.append(egg)
 link = Link(vars, egg, case)
 links.append(link)
 
@@ -150,7 +150,7 @@
 # block.exits[True] = ifLink.
 raise StopFlowing
 
-def guessexception(self, frame, *cases):
+def guessexception(self, ctx, *cases):
 block = self.crnt_block
 bvars = vars = vars2 = block.getvariables()
 links = []
@@ -167,7 +167,7 @@
 vars.extend([last_exc, last_exc_value])
 vars2.extend([Variable(), Variable()])
 egg = EggBlock(vars2, block, case)
-frame.pendingblocks.append(egg)
+ctx.pendingblocks.append(egg)
 link = Link(vars, egg, case)
 if case is not None:
 link.extravars(last_exception=last_exc, 
last_exc_value=last_exc_value)
@@ -198,14 +198,14 @@
   [str(s) for s in self.listtoreplay[self.index:]]))
 self.index += 1
 
-def guessbool(self, frame, w_condition):
+def guessbool(self, ctx, w_condition):
 assert self.index == len(self.listtoreplay)
-frame.recorder = self.nextreplayer
+ctx.recorder = self.nextreplayer
 return self.booloutcome
 
-def guessexception(self, frame, *classes):
+def guessexception(self, ctx, *classes):
 assert self.index == len(self.listtoreplay)
-frame.recorder = self.nextreplayer
+ctx.recorder = self.nextreplayer
 outcome = self.booloutcome
 if outcome is not None:
 egg = self.nextreplayer.crnt_block
@@ -305,7 +305,7 @@
 "cmp_exc_match",
 ]
 
-class FlowSpaceFrame(object):
+class FlowContext(object):
 opcode_method_names = host_bytecode_spec.method_names
 
 def __init__(self, graph, code):
@@ -320,7 +320,6 @@
 self.last_instr = 0
 
 self.init_locals_stack(code)
-self.w_locals = None # XXX: only for compatibility with PyFrame
 
 self.joinpoints = {}
 
@@ -402,7 +401,7 @@
 return FrameState(data, self.blockstack[:], next_pos)
 
 def setstate(self, state):
-""" Reset the frame to the given state. """
+""" Reset the context to the given frame state. """
 data = state.mergeable[:]
 recursively_unflatten(data)
 self.restore_locals_stack(data[:-2])  # Nones == undefined locals
@@ -490,8 +489,8 @@
 self.recorder.crnt_block.closeblock(link)
 
 except FlowingError as exc:
-if exc.frame is None:
-exc.frame = self
+if exc.ctx is None:
+exc.ctx = self
 raise
 
 self.recorder = None
@@ -1316,9 +1315,9 @@
 """Abstract base class for frame blocks from the blockstack,
 used by the SETUP_XXX and POP_BLOCK opcodes."""
 
-def __init__(self, frame, handlerposition):
+def __init__(self, ctx, handlerposition):
 self.handlerposition = handlerposition
-self.valuestackdepth = frame.valuestackdepth
+self.valuestackdepth = ctx.valuestackdepth
 
 def __eq__(self, other):
 return (self.__class__ is other.__class__ and
@@ -1331,10 +1330,10 @@
 def __hash__(self):
 return hash((self.handlerposition, self.valuestackdepth))
 
-def cleanupstack(self, frame):
-frame.dropvaluesuntil(self.valuestackdepth)
+def cleanupstack(self, ctx):
+ctx.dropvaluesuntil(self.valuestackdepth)
 
-def handle(self, frame, unroller):
+de