<p>Patch set 1:<span style="border-radius: 3px; display: inline-block; margin: 0 2px; padding: 4px;background-color: #ffd4d4;">Code-Review -1</span></p><p><a href="https://gerrit.asterisk.org/10294">View Change</a></p><p>6 comments:</p><ul style="list-style: none; padding: 0;"><li style="margin: 0; padding: 0;"><p><a href="https://gerrit.asterisk.org/#/c/10294/1/main/astobj2.c">File main/astobj2.c:</a></p><ul style="list-style: none; padding: 0;"><li style="margin: 0; padding: 0 0 0 16px;"><p style="margin-bottom: 4px;"><a href="https://gerrit.asterisk.org/#/c/10294/1/main/astobj2.c@50">Patch Set #1, Line 50:</a> <code style="font-family:monospace,monospace">struct __priv_data {</code></p><p style="white-space: pre-wrap; word-wrap: break-word;">FYI</p><p style="white-space: pre-wrap; word-wrap: break-word;">I think you are getting an overall reduction in struct size but the amount is dependent upon the architecture because you are shifting padding bytes around and eliminating a uint32_t member.  For the x86_64 you are recovering 4 bytes of padding and eliminating a 4 byte uint32_t for 8 bytes.</p><p style="white-space: pre-wrap; word-wrap: break-word;">8 bytes per pointer<br>4 bytes per size_t (This may be 8 depending upon the base int type of size_t)<br>4 bytes per int32_t/uint32_t</p><p style="white-space: pre-wrap; word-wrap: break-word;">This gives this struct<br>8 + 8 + (4 or 8) + 4 + 4 = 28 or 32 bytes used</p><p style="white-space: pre-wrap; word-wrap: break-word;">The alignment of the struct is going to be based upon the largest alignment object in the struct which in this case would be a pointer.  So the alignment will be 8.</p><p style="white-space: pre-wrap; word-wrap: break-word;">Then taking the alignment of the struct into consideration, there will be 4 bytes of padding at the end of the struct if size_t is 4 bytes.  So the size of the struct should now be 32 regardless of the size_t size.</p><p style="white-space: pre-wrap; word-wrap: break-word;">For the original layout:<br>4 + 4(pad) + 8 + 8 + (4 or 8) + 4 + 4 = 36 or 40 bytes used</p><p style="white-space: pre-wrap; word-wrap: break-word;">With the overall struct alignment the size would be 40 because there may or may not be 4 bytes of padding at the end of the struct to bring it to 8 byte alignment.</p></li><li style="margin: 0; padding: 0 0 0 16px;"><p style="margin-bottom: 4px;"><a href="https://gerrit.asterisk.org/#/c/10294/1/main/astobj2.c@60">Patch Set #1, Line 60:</a> </p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;"><pre style="font-family: monospace,monospace; white-space: pre-wrap;">      /*! The ao2 object option flags */<br>    uint32_t options:2;<br>   /*! magic number.  This is used to verify that a pointer passed in is a<br>        *  valid astobj2 or ao2_weak reference */<br>    uint32_t magic:30;<br></pre></blockquote></p><p style="white-space: pre-wrap; word-wrap: break-word;">FYI</p><p style="white-space: pre-wrap; word-wrap: break-word;">You are squeezing the bits out of the magic number safety/sanity check.  We now have 29 bits out of 32 for the safety check.</p><p style="white-space: pre-wrap; word-wrap: break-word;">I suppose if we ever need any more bits for the ao2 options flags we will have to pull options back out as its own uint32_t.</p></li><li style="margin: 0; padding: 0 0 0 16px;"><p style="margin-bottom: 4px;"><a href="https://gerrit.asterisk.org/#/c/10294/1/main/astobj2.c@545">Patch Set #1, Line 545:</a> <code style="font-family:monospace,monospace">                            current_value, user_data);</code></p><p style="white-space: pre-wrap; word-wrap: break-word;">To be safe you should cast current_value to int here.</p></li><li style="margin: 0; padding: 0 0 0 16px;"><p style="margin-bottom: 4px;"><a href="https://gerrit.asterisk.org/#/c/10294/1/main/astobj2.c@554">Patch Set #1, Line 554:</a> <code style="font-family:monospace,monospace">                            file, line, func, ret, tag);</code></p><p style="white-space: pre-wrap; word-wrap: break-word;">To be safe you should cast ret here to int.</p></li><li style="margin: 0; padding: 0 0 0 16px;"><p style="margin-bottom: 4px;"><a href="https://gerrit.asterisk.org/#/c/10294/1/main/astobj2.c@563">Patch Set #1, Line 563:</a> <code style="font-family:monospace,monospace">                    "Invalid refcount %d on ao2 object %p\n", current_value, user_data);</code></p><p style="white-space: pre-wrap; word-wrap: break-word;">To be safe you should cast current_value to int here.</p></li><li style="margin: 0; padding: 0 0 0 16px;"><p style="margin-bottom: 4px;"><a href="https://gerrit.asterisk.org/#/c/10294/1/main/astobj2.c@696">Patch Set #1, Line 696:</a> </p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;"><pre style="font-family: monospace,monospace; white-space: pre-wrap;">   obj->priv_data.ref_counter = 1;<br>    obj->priv_data.destructor_fn = destructor_fn;        /* can be NULL */<br>     obj->priv_data.options = options;<br>  obj->priv_data.magic = AO2_MAGIC;<br></pre></blockquote></p><p style="white-space: pre-wrap; word-wrap: break-word;">Should reorder this to match the new layout.</p></li></ul></li></ul><p>To view, visit <a href="https://gerrit.asterisk.org/10294">change 10294</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/10294"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: comment </div>
<div style="display:none"> Gerrit-Change-Id: Idc1baabb35ec3b3d8de463c4fa3011eaf7fcafb5 </div>
<div style="display:none"> Gerrit-Change-Number: 10294 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Comment-Date: Thu, 27 Sep 2018 17:05:27 +0000 </div>
<div style="display:none"> Gerrit-HasComments: Yes </div>
<div style="display:none"> Gerrit-HasLabels: Yes </div>