[pypy-svn] r13240 - in pypy/dist/pypy: documentation rpython rpython/test

arigo at codespeak.net arigo at codespeak.net
Thu Jun 9 20:51:18 CEST 2005


Author: arigo
Date: Thu Jun  9 20:51:15 2005
New Revision: 13240

Modified:
   pypy/dist/pypy/documentation/translation.txt
   pypy/dist/pypy/rpython/lltype.py
   pypy/dist/pypy/rpython/test/test_lltype.py
Log:
Documentation: Arrays can now be of any primitive or pointer type too.
Make malloc() of a non-GC struct or array complain, unless the immortal flag
is specified.


Modified: pypy/dist/pypy/documentation/translation.txt
==============================================================================
--- pypy/dist/pypy/documentation/translation.txt	(original)
+++ pypy/dist/pypy/documentation/translation.txt	Thu Jun  9 20:51:15 2005
@@ -604,10 +604,15 @@
 
 An array type is built as an instance of ``pypy.rpython.lltype.Array``::
 
+    MyIntArray = Array(Signed)
+    MyOtherArray = Array(MyItemType)
+    MyOtherArray = GcArray(MyItemType)
+
+Or, for arrays whose items are structures, as a shortcut::
+
     MyArrayType = Array(('field1', Type1), ('field2', Type2)...)
-    MyArrayType = GcArray(('field1', Type1), ('field2', Type2)...)
 
-The items of an array are always structures; the arguments to Array() give the fields of these structures (it can of course be a single field).  The allowed field types follow the same rules as for Struct(), except that you cannot inline an array into the items' structure.
+You can build arrays whose items are either primitive or pointer types, or (non-GC non-varsize) structures.
 
 GcArrays can be malloc()ed.  The length must be specified when malloc() is called, and arrays cannot be resized; this length is stored explicitely in a header.
 

Modified: pypy/dist/pypy/rpython/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltype.py	(original)
+++ pypy/dist/pypy/rpython/lltype.py	Thu Jun  9 20:51:15 2005
@@ -624,6 +624,8 @@
         o = _array(T, n)
     else:
         raise TypeError, "malloc for Structs and Arrays only"
+    if not isinstance(T, GC_CONTAINER) and not immortal:
+        raise TypeError, "malloc of a non-GC non-immortal structure"
     return _ptr(Ptr(T), o, immortal)
 
 def functionptr(TYPE, name, **attrs):

Modified: pypy/dist/pypy/rpython/test/test_lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_lltype.py	(original)
+++ pypy/dist/pypy/rpython/test/test_lltype.py	Thu Jun  9 20:51:15 2005
@@ -267,11 +267,11 @@
     py.test.raises(TypeError, "Array(S)")
     py.test.raises(TypeError, "Array(As)")
     S = Struct('s', ('x', Signed))
-    A = Array(S)
+    A = GcArray(S)
     a = malloc(A, 2)
     s = S._container_example() # should not happen anyway
     py.test.raises(TypeError, "a[0] = s")
-    S = Struct('s', ('last', A))
+    S = Struct('s', ('last', Array(S)))
     py.test.raises(TypeError, "Array(S)")
     
     



More information about the Pypy-commit mailing list