[ Sorry for the hindrance ]<br><br><div class="gmail_quote">On Tue, Jul 5, 2011 at 12:18 AM, Jamey Sharp <span dir="ltr">&lt;<a href="mailto:jamey@minilop.net">jamey@minilop.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">On Mon, Jul 04, 2011 at 03:42:24AM +0530, vikash agrawal wrote:<br>
&gt; Also it has been long I am trying to patch a bug, I had several discussion<br>
&gt; with pharris ( I apologise for pestering you so much ) over the same. I am<br>
&gt; still studying c_client.py and a quick glance of it reveals<br>
&gt; &#39;_c_serialize_helper_insert_  function&#39;, with context being sizeof, is<br>
&gt; responsible for xcb_str_sizeof in xproto.c. So I believe this might need<br>
&gt; some hacks.<br>
&gt; Also, if I am not wrong there is a problem with xcb_str_next with respect<br>
&gt; master and 1.7, but for this I have a very n00b and basic idea like if<br>
&gt; self.c_next_name == &#39;xcb_str_next&#39;: # and then necessary conditions of<br>
&gt; _c(&#39;whatever&#39;); might solve the purpose. If this feels a way then can we<br>
&gt; specifically do the same for other buggy issues.<br>
<br>
</div>I&#39;m sorry to say, the problem is not specific to xcb_str_next or to<br>
strings at all. The good news is that it should be solvable in a general<br>
way, without hacks for specific types. I wrote some about this here:<br>
<br>
<a href="http://lists.freedesktop.org/archives/xcb/2011-March/006837.html" target="_blank">http://lists.freedesktop.org/archives/xcb/2011-March/006837.html</a><br>
<br>
Here is a sketch of an algorithm that I believe is correct for<br>
statically computing alignment padding for all X types. I&#39;ll use the<br>
terms from xcbgen/xtypes.py.<br>
<br>
First, compute the minimum alignment requirement for every type:<br>
<br>
- For every SimpleType and ExprType, including the standard types like<br>
  CARD8, the alignment required equals the size of the type, but no more<br>
  than 4 bytes. So CARD8 needs 1 byte, INT16 needs 2 bytes, FLOAT needs<br>
  4 bytes, and DOUBLE also needs 4 bytes.<br>
<br>
- For ListTypes, the alignment is the same as the member type&#39;s<br>
  alignment.<br>
<br>
- Request, Reply, Event, and Error types always have 4-byte alignment.<br>
<br>
- For StructType and UnionType, the alignment is the maximum alignment<br>
  needed by any field in the struct or union. So STR, which is a struct<br>
  containing a CARD8 and a list of CARD8, only needs 1-byte alignment;<br>
  but a struct containing an INT16 and a DOUBLE needs 4-byte alignment.<br>
<br>
I haven&#39;t thought about the rules for Switch or Bitcase yet.<br>
<br>
I think implementing the above in proto/xcbgen would be a good target<br>
for something to finish by the time of the mid-term review. The rest of<br>
the algorithm is below.<br><br></blockquote><div><br>Hello Everyone,<br><br>Thank You Jamey for the reply,<br><br>I am facing few problems,<br><ul><li>I am unable to compile xtypes.py with python interpretor. I reciev an error -&gt; Traceback (most recent call last):<br>

  File &quot;workspace/xcb/proto/xcbgen/xtypes.py&quot;, line 80, in &lt;module&gt;<br>
    class SimpleType(Type):<br>  File &quot;workspace/xcb/proto/xcbgen/xtypes.py&quot;, line 106, in SimpleType<br>    out = __main__.output[&#39;simple&#39;]<br><b>AttributeError: &#39;module&#39; object has no attribute &#39;output&#39; </b>and as a result for every change that I try to bring I need to start from make clean all over again for both ptroto</li>

<li>module.resolve keep troubling me whenever I try to introduce something in the xtypes so how can I resolve those</li></ul>So
 far what I have understood/interpreted from your reply I have tried to 
do something, ( and its compiling :-) ) and here it is, please review it
 [ I have tried to have follow the coding style and tried not not to 
make any typo error, still if any prob occur please notify ]<br>
<br><br>[vikash@localhost proto]$ git diff<br>diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py<br>index 14c318a..98c6811 100644<br>--- a/xcbgen/xtypes.py<br>+++ b/xcbgen/xtypes.py<br>@@ -34,6 +34,7 @@ class Type(object):<br>


         self.is_pad = False<br>         self.is_switch = False<br>         self.is_bitcase = False<br>+        self.is_align = False<br> <br>     def resolve(self, module):<br>         &#39;&#39;&#39;<br>@@ -89,13 +90,19 @@ class SimpleType(Type):<br>


         self.is_simple = True<br>         self.size = size<br>         self.nmemb = 1<br>+        <br>+        # align should be either equal to self.size or 4<br>+        self.align = min(self.size, 4)<br>+        self.is_align = True if self.align else False<br>


+#        print self.is_align<br> <br>+        <br>     def resolve(self, module):<br>         self.resolved = True<br> <br>     def fixed_size(self):<br>         return True<br>-<br>+    <br>     out = __main__.output[&#39;simple&#39;]<br>


 <br> <br>@@ -169,6 +176,15 @@ class ListType(Type):<br> <br>         self.size = member.size if member.fixed_size() else None<br>         self.nmemb = self.expr.nmemb if self.expr.fixed_size() else None<br>+        <br>

+        # Please look over here<br>
+        # align should be between size and 4<br>+        # What should I take instead of None ?<br>+        self.align = min (member.size, 4) if member.fixed_size() else None<br>+        self.is_align = True if self.align else False<br>


+#        print self.is_align<br>+#        Also many a time I am recieving self.align = 0<br>+<br> <br>     def make_member_of(self, module, complex_type, field_type, field_name, v<br>         if not self.fixed_size():<br>


@@ -231,6 +247,13 @@ class ExprType(Type):<br> <br>         self.size = member.size<br>         self.nmemb = 1<br>+    <br>+        # align should be either equal to size or 4<br>+        self.align = min(self.size, 4)<br>


+        self.is_align = True if self.align else False<br>+        print self.align<br>+#        print self.is_align<br>+<br> <br>     def resolve(self, module):<br>         if self.resolved:<br>@@ -273,6 +296,8 @@ class ComplexType(Type):<br>


         self.nmemb = 1<br>         self.size = 0<br>         self.lenfield_parent = [self]<br>+        self.align = []<br>+        <br> <br>     def resolve(self, module):<br>         if self.resolved:<br>@@ -329,7 +354,8 @@ class ComplexType(Type):<br>


 <br>         self.calc_size() # Figure out how big we are<br>         self.resolved = True<br>-<br>+        self.align_size()<br>+  <br>     def calc_size(self):<br>         self.size = 0<br>         for m in self.fields:<br>


@@ -337,7 +363,6 @@ class ComplexType(Type):<br>                 continue<br>             if m.type.fixed_size():<br>                 self.size = self.size + (m.type.size * m.type.nmemb)<br>-            else:<br>                 self.size = None<br>


                 break<br> <br>@@ -346,6 +371,29 @@ class ComplexType(Type):<br>             if not m.type.fixed_size():<br>                 return False<br>         return True<br>+        <br>+    def align_size(self):<br>


+        &#39;&#39;&#39;<br>+        I think this func should work for both StructTypes and UnionTypes<br>+        &#39;&#39;&#39;<br>+        self.size = 0<br>+        arr=[]<br>+        for m in self.fields:<br>+            if not m.wire:<br>


+                continue<br>+            if m.type.fixed_size():<br>+                self.size = self.size + (m.type.size * m.type.nmemb)<br>+#                print &#39;calc_size&#39;,self.size<br>+                arr.append(self.size)<br>


+#                print &#39;arr&#39;, arr<br>+#                print &#39;max of arr&#39;, max(arr)<br>+                self.align=min(max(arr), 4)<br>+                print &#39;align&#39;, self.align<br>+                self.is_align = True<br>


+#                return self.size<br>+                 <br>+<br>+             <br> <br> class SwitchType(ComplexType):<br>     &#39;&#39;&#39;<br>@@ -455,6 +503,7 @@ class Struct(ComplexType):<br>     &#39;&#39;&#39;<br>


     Derived class representing a struct data type.<br>     &#39;&#39;&#39;<br>+    <br>     out = __main__.output[&#39;struct&#39;]<br> <br> <br>@@ -518,6 +567,12 @@ class Reply(ComplexType):<br>     def __init__(self, name, elt):<br>


         ComplexType.__init__(self, name, elt)<br>         self.is_reply = True<br>+        <br>+        # align should be equal to 4<br>+        self.align = 4<br>+        self.is_align = True if self.is_align else False<br>


+#        print self.is_align<br>+        <br> <br>     def resolve(self, module):<br>         if self.resolved:<br>@@ -542,6 +597,12 @@ class Request(ComplexType):<br>         ComplexType.__init__(self, name, elt)<br>         self.reply = None<br>


         self.opcode = elt.get(&#39;opcode&#39;)<br>+        <br>+        # align should be equal to 4<br>+        self.align = 4<br>+        self.is_align = True if self.align else False<br>+#        print self.is_align<br>


+        <br> <br>         for child in list(elt):<br>             if child.tag == &#39;reply&#39;:<br>@@ -578,6 +639,11 @@ class Event(ComplexType):<br>     def __init__(self, name, elt):<br>         ComplexType.__init__(self, name, elt)<br>


         self.opcodes = {}<br>+        <br>+        # align should be equal to 4<br>+        self.align = 4<br>+        self.is_align = True if self.align else False<br>+#        print self.is_align<br>         tmp = elt.get(&#39;no-sequence-number&#39;)<br>


         self.has_seq = (tmp == None or tmp.lower() == &#39;false&#39; or tmp == &#39;0&#39;)<br>@@ -611,7 +677,12 @@ class Error(ComplexType):<br>     def __init__(self, name, elt):<br>         ComplexType.__init__(self, name, elt)<br>


         self.opcodes = {}<br>-<br>+        <br>+        # align should be equal to 4<br>+        self.align = 4<br>+        self.is_align = True if self.align else False<br>+#        print self.is_align<br>+       <br>     def add_opcode(self, opcode, name, main):<br>


         self.opcodes[name] = opcode<br>         if main:<br><br><br>Love <br><br>Vikash<br><br>and waiting for review :) <br></div></div>