[pypy-commit] lang-smalltalk default: non variable-sized classes can be created through prim 71 if size is 0

timfel noreply at buildbot.pypy.org
Fri Dec 6 17:23:15 CET 2013


Author: Tim Felgentreff <timfelgentreff at gmail.com>
Branch: 
Changeset: r519:a8441ef9359e
Date: 2013-12-06 09:52 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/a8441ef9359e/

Log:	non variable-sized classes can be created through prim 71 if size is
	0

diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -470,7 +470,7 @@
 def func(interp, s_frame, w_cls, size):
     assert isinstance(w_cls, model.W_PointersObject)
     s_class = w_cls.as_class_get_shadow(interp.space)
-    if not s_class.isvariable():
+    if not s_class.isvariable() and size != 0:
         raise PrimitiveFailedError()
     try:
         return s_class.new(size)
@@ -632,7 +632,7 @@
     combinationRule = interp.space.unwrap_positive_32bit_int(w_rcvr.fetch(interp.space, 3))
     if combinationRule > 41:
         raise PrimitiveFailedError
-    
+
     space = interp.space
 
     s_bitblt = w_rcvr.as_bitblt_get_shadow(space)
diff --git a/spyvm/test/test_primitives.py b/spyvm/test/test_primitives.py
--- a/spyvm/test/test_primitives.py
+++ b/spyvm/test/test_primitives.py
@@ -300,6 +300,14 @@
     assert w_res.getclass(space).is_same_object(space.w_String)
     assert w_res.size() == 20
 
+def test_new_with_arg_for_non_variable_sized():
+    prim_fails(primitives.NEW_WITH_ARG, [space.classtable['w_ArrayedCollection'], 10])
+
+def test_new_with_arg_for_non_variable_sized0():
+    w_res = prim(primitives.NEW_WITH_ARG, [space.classtable['w_ArrayedCollection'], 0])
+    assert w_res.getclass(space).is_same_object(space.classtable['w_ArrayedCollection'])
+    assert w_res.size() == 0
+
 def test_invalid_new_with_arg():
     w_Object = space.classtable['w_Object']
     prim_fails(primitives.NEW_WITH_ARG, [w_Object, 20])


More information about the pypy-commit mailing list