[PATCH] Store a binding inside CTypes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Store a binding inside CTypes

Paolo Bonzini-2
This allows the #{DatumStruct} forward reference to work properly.  This
is a better design because it allows circular references (which would
not work in the 2.x-compatible system).

With this set of patches, GDBM converts successfully.

Paolo

2007-08-13  Paolo Bonzini  <[hidden email]>

        * kernel/CType.st: Store a VariableBinding inside a CType.

        * libgst/dict.c: Dereference the VariableBinding stored in a CType.


--- orig/kernel/CType.st
+++ mod/kernel/CType.st
@@ -129,11 +129,16 @@ initialize
 
 !CType class methodsFor: 'C instance creation'!
 
-cObjectType: aCObjectSubclassBinding
+cObjectBinding: aCObjectSubclassBinding
     "Create a new CType for the given subclass of CObject"
     ^self basicNew init: aCObjectSubclassBinding
 !
 
+cObjectType: aCObjectSubclass
+    "Create a new CType for the given subclass of CObject"
+    ^self cObjectBinding: aCObjectSubclass binding
+!
+
 from: type
     "Private - Pass the size, alignment, and description of CType for aBlock,
     given the field description in `type' (the second element of each pair)."
@@ -144,7 +149,7 @@ from: type
     "must be a type name, either built in or struct, either a Symbol
      or an Association"
 
-    type isSymbol ifFalse: [ ^type value type ].
+    type isSymbol ifFalse: [ ^self cObjectBinding: type ].
     ^TypeMap at: type ifAbsent: [ Namespace current at: type ]
 !
 
@@ -202,7 +207,7 @@ ptrType
 cObjectType
     "Answer the CObject subclass whose instance is created when new is sent
      to the receiver"
-    ^cObjectType
+    ^cObjectType value
 !
 
 sizeof
@@ -284,7 +289,7 @@ from: type
 
 elementType: aCType
     "Answer a new instance of CPtrCType that maps pointers to the given CType"
-    ^self new init: CPtr; elementType: aCType
+    ^(self cObjectType: CPtr) elementType: aCType; yourself
 ! !
 
 
@@ -341,10 +346,10 @@ elementType: aCType numberOfElements: an
     are of the given CType, and whose size is exactly anInteger elements
     (of course, anInteger only matters for allocation, not for access, since
     no out-of-bounds protection is provided for C objects)."
-    ^self new
-        init: CArray;
+    ^(self cObjectType: CArray)
         elementType: aCType;
-        numberOfElements: anInteger
+        numberOfElements: anInteger;
+ yourself
 ! !
 
 


--- orig/libgst/dict.c
+++ mod/libgst/dict.c
@@ -2069,7 +2069,7 @@ _gst_c_object_new (PTR cObjPtr,
   if (!IS_NIL (typeOOP))
     {
       cType = (gst_ctype) OOP_TO_OBJ (typeOOP);
-      classOOP = cType->cObjectType;
+      classOOP = ASSOCIATION_VALUE (cType->cObjectType);
     }
   else
     classOOP = defaultClassOOP;




_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk