class: ExternalStructure
authorClaus Gittinger <cg@exept.de>
Mon, 09 Feb 2015 12:52:18 +0100
changeset 17455 374a772dfd00
parent 17454 f543998a9ed1
child 17456 2365cd3471c9
class: ExternalStructure added: #fields #generateCTypeFromFieldDescription: changed: #sizeof
ExternalStructure.st
--- a/ExternalStructure.st	Mon Feb 09 11:07:35 2015 +0100
+++ b/ExternalStructure.st	Mon Feb 09 12:52:18 2015 +0100
@@ -11,6 +11,8 @@
 "
 "{ Package: 'stx:libbasic' }"
 
+"{ NameSpace: Smalltalk }"
+
 ExternalBytes subclass:#ExternalStructure
 	instanceVariableNames:''
 	classVariableNames:''
@@ -113,15 +115,38 @@
     ^ cType
 !
 
+fields
+    "for Squeak compatibility support: may return a literal array structure definition,
+     from which the size and layout of the fields can be constructed.
+     Returns nil for ST/X subclasses, which redefine the sizeof method"
+
+    ^ nil
+!
+
 sizeof
     "the sizeof my instances in bytes"
 
+    cType isNil ifTrue:[
+        "/ second chance for Squeak external structures
+        self fields notNil ifTrue:[
+            self generateCTypeFromFieldDescription:self fields.
+        ].
+    ].
     cType notNil ifTrue:[
         ^ cType sizeof
     ].
     self subclassResponsibility
 ! !
 
+!ExternalStructure class methodsFor:'utilities'!
+
+generateCTypeFromFieldDescription:fieldsSpec
+    "to support Squeak external structures, which define a fields method,
+     which returns a literal array spec of fields"
+
+    self halt.
+! !
+
 !ExternalStructure methodsFor:'private'!
 
 fromExternalAddress:anExternalAddress
@@ -131,10 +156,10 @@
 !ExternalStructure class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStructure.st,v 1.5 2013-01-28 18:04:13 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStructure.st,v 1.6 2015-02-09 11:52:18 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStructure.st,v 1.5 2013-01-28 18:04:13 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStructure.st,v 1.6 2015-02-09 11:52:18 cg Exp $'
 ! !