[pypy-dev] String or None segmentation fault

2008-12-30 Thread Hakan Ardo
Hi,
the following code compiles into something that segfaults. Attached is
a patch trying to fix that.

def nstr(i):
if i==0: return None
return str(i)
def fn(i):
return (str(nstr(0)), str(nstr(i)))


-- 
Håkan Ardö
Index: pypy/rpython/rstr.py
===
--- pypy/rpython/rstr.py	(revision 60718)
+++ pypy/rpython/rstr.py	(working copy)
@@ -9,6 +9,7 @@
 from pypy.rpython import rint
 from pypy.rpython.lltypesystem.lltype import Signed, Bool, Void, UniChar,\
  cast_primitive
+from pypy.rpython.annlowlevel import llstr
 
 class AbstractStringRepr(Repr):
 pass
@@ -278,6 +279,16 @@
 hop.exception_is_here()
 return hop.gendirectcall(self.ll.ll_float, v_str)
 
+def rtype_str(self, hop):
+[v_self] = hop.inputargs(self)
+if hop.args_s[0].can_be_none():
+return hop.gendirectcall(self.ll_str_or_none, v_self)
+return hop.gendirectcall(self.ll_str, v_self)
+
+def ll_str_or_none(self,s):
+if not s: return llstr('None')
+return s
+
 def ll_str(self, s):
 return s
 
Index: pypy/rpython/test/test_rstr.py
===
--- pypy/rpython/test/test_rstr.py	(revision 60718)
+++ pypy/rpython/test/test_rstr.py	(working copy)
@@ -820,6 +820,16 @@
 res = self.interpret(f, [1])
 assert self.ll_to_string(res) == hello
 
+def test_none_or_string(self):
+def nstr(i):
+if i==0: return None
+return str(i)
+def fn(i):
+return (str(nstr(0)), str(nstr(i)))
+from pypy.translator.c.test.test_genc import compile
+f = compile(fn,[int])
+assert f(7)==('None', '7')
+
 def FIXME_test_str_to_pystringobj():
 def f(n):
 if n = 0:
___
pypy-dev@codespeak.net
http://codespeak.net/mailman/listinfo/pypy-dev

[pypy-dev] [Fwd: [Fwd: Re: Threaded interpretation]]

2008-12-30 Thread Antonio Cuni
Hi,
Antoine Pitrou told me that his mail got rejected by the mailing list, so I'm 
forwarding it.

 Message transféré 
De: Antoine Pitrou solip...@pitrou.net
À: pypy-dev@codespeak.net
Sujet: Re: Threaded interpretation
Date: Fri, 26 Dec 2008 21:16:36 + (UTC)

Hi people,

By reading this thread I had the idea to write a threaded interpretation patch
for py3k. Speedup on pybench and pystone is 15-20%.
http://bugs.python.org/issue4753

Regards

Antoine.

___
pypy-dev@codespeak.net
http://codespeak.net/mailman/listinfo/pypy-dev