# How to use pointer chain?

**URL:** <https://discourse.ats-lang.org/t/how-to-use-pointer-chain/819>\
**Category:** Google Group\
**Created:** [March 2, 2015, 1:53pm UTC](https://discourse.ats-lang.org/t/how-to-use-pointer-chain/819 "2015-03-02T13:53:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [March 2, 2015, 1:53pm UTC](https://discourse.ats-lang.org/t/how-to-use-pointer-chain/819/1 "2015-03-02T13:53:54Z")

</div>

Yes, this is a question I have been asking myself for a long time!

I do not yet have a good solution. I can outline some of my ideas in a  
separate message.

> > The wall is code “dentry-\>d\_sb-\>s\_op-\>statfs”.  
> > In ATS2, we should create own view and use takeout/addback pattern?

Doing it manually is simply too much work.

Basically, I think we need to implement some kind of meta-programming  
support for  
handling structs in C.On Mon, Mar 2, 2015 at 8:39 AM, Kiwamu Okabe [kiw...@debian.or.jp](mailto:kiw...@debian.or.jp) wrote:

> Hi all,
> 
> I have read “Preventing heartbleed bugs with safe programming languages”  
> entry  
> at BLUISH CODER.
> 
> [Preventing heartbleed bugs with safe programming languages](http://bluishcoder.co.nz/2014/04/11/preventing-heartbleed-bugs-with-safe-languages.html)
> 
> It explains re-write C language implementation using ATS, little by little.  
> So great!
> 
> However, my code sometimes meet wall called as “pointer chain”.  
> The “pointer chain” example is following:
> 
> static int statfs\_by\_dentry(struct dentry \*dentry, struct kstatfs \*buf)  
> {  
> int retval;
> 
> ```
> if (!dentry->d_sb->s_op->statfs)
> return -ENOSYS;
> 
> memset(buf, 0, sizeof(*buf));
> retval = security_sb_statfs(dentry);
> if (retval)
> return retval;
> retval = dentry->d_sb->s_op->statfs(dentry, buf);
> 
> ```
> 
> The wall is code “dentry-\>d\_sb-\>s\_op-\>statfs”.  
> In ATS2, we should create own view and use takeout/addback pattern?
> 
> [Design patterns · githwxi/ATS-Postiats Wiki · GitHub](https://github.com/githwxi/ATS-Postiats/wiki/Design-patterns#takeout-addback-pattern)
> 
> Or, is there more better solution?
> 
> ## Thank’s,
> 
> Kiwamu Okabe at METASEPI DESIGN
> 
> –  
> You received this message because you are subscribed to the Google Groups  
> “ats-lang-users” group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dmOt7CW-aQ%2BTBuby8i%3DRaD2mLqZhMLHx0i4%3DH-n6nwudA%40mail.gmail.com](https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dmOt7CW-aQ%2BTBuby8i%3DRaD2mLqZhMLHx0i4%3DH-n6nwudA%40mail.gmail.com)  
> .

---

<div class="post-metadata">

**Author:** ![Shea\_Levy](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@Shea\_Levy](https://discourse.ats-lang.org/u/Shea_Levy)\
**Post date:** [March 2, 2015, 2:12pm UTC](https://discourse.ats-lang.org/t/how-to-use-pointer-chain/819/2 "2015-03-02T14:12:11Z")

</div>

Could we leverage something like operator dot overloading but for → to wrap all of the takeout/addback?\> On Mar 2, 2015, at 8:53 AM, Hongwei Xi [gmh...@gmail.com](mailto:gmh...@gmail.com) wrote:

> Yes, this is a question I have been asking myself for a long time!
> 
> I do not yet have a good solution. I can outline some of my ideas in a separate message.
> 
> > > The wall is code “dentry-\>d\_sb-\>s\_op-\>statfs”.  
> > > In ATS2, we should create own view and use takeout/addback pattern?
> 
> Doing it manually is simply too much work.
> 
> Basically, I think we need to implement some kind of meta-programming support for  
> handling structs in C.
> 
> On Mon, Mar 2, 2015 at 8:39 AM, Kiwamu Okabe \<kiw…@debian.or.jp [mailto:kiw...@debian.or.jp](mailto:kiw...@debian.or.jp)\> wrote:  
> Hi all,
> 
> I have read “Preventing heartbleed bugs with safe programming languages” entry  
> at BLUISH CODER.
> 
> [Preventing heartbleed bugs with safe programming languages](http://bluishcoder.co.nz/2014/04/11/preventing-heartbleed-bugs-with-safe-languages.html) [http://bluishcoder.co.nz/2014/04/11/preventing-heartbleed-bugs-with-safe-languages.html](http://bluishcoder.co.nz/2014/04/11/preventing-heartbleed-bugs-with-safe-languages.html)
> 
> It explains re-write C language implementation using ATS, little by little.  
> So great!
> 
> However, my code sometimes meet wall called as “pointer chain”.  
> The “pointer chain” example is following:
> 
> static int statfs\_by\_dentry(struct dentry \*dentry, struct kstatfs \*buf)  
> {  
> int retval;
> 
> ```
> if (!dentry->d_sb->s_op->statfs)
> return -ENOSYS;
> 
> memset(buf, 0, sizeof(*buf));
> retval = security_sb_statfs(dentry);
> if (retval)
> return retval;
> retval = dentry->d_sb->s_op->statfs(dentry, buf);
> 
> ```
> 
> The wall is code “dentry-\>d\_sb-\>s\_op-\>statfs”.  
> In ATS2, we should create own view and use takeout/addback pattern?
> 
> [Design patterns · githwxi/ATS-Postiats Wiki · GitHub](https://github.com/githwxi/ATS-Postiats/wiki/Design-patterns#takeout-addback-pattern) [https://github.com/githwxi/ATS-Postiats/wiki/Design-patterns#takeout-addback-pattern](https://github.com/githwxi/ATS-Postiats/wiki/Design-patterns#takeout-addback-pattern)
> 
> Or, is there more better solution?
> 
> ## Thank’s,
> 
> Kiwamu Okabe at METASEPI DESIGN
> 
> –  
> You received this message because you are subscribed to the Google Groups “ats-lang-users” group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com) [mailto:ats-lang-users...@googlegroups.com](mailto:ats-lang-users...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com) [mailto:ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users) [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dmOt7CW-aQ%2BTBuby8i%3DRaD2mLqZhMLHx0i4%3DH-n6nwudA%40mail.gmail.com](https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dmOt7CW-aQ%2BTBuby8i%3DRaD2mLqZhMLHx0i4%3DH-n6nwudA%40mail.gmail.com) [https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dmOt7CW-aQ%2BTBuby8i%3DRaD2mLqZhMLHx0i4%3DH-n6nwudA%40mail.gmail.com](https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dmOt7CW-aQ%2BTBuby8i%3DRaD2mLqZhMLHx0i4%3DH-n6nwudA%40mail.gmail.com).
> 
> –  
> You received this message because you are subscribed to the Google Groups “ats-lang-users” group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com) [mailto:ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com) [mailto:ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users) [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrbrkuN%3DEB8gRWCbQb28U%3DgU-cGisaOCS25k%2BGEn37gvQ%40mail.gmail.com](https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrbrkuN%3DEB8gRWCbQb28U%3DgU-cGisaOCS25k%2BGEn37gvQ%40mail.gmail.com) [https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrbrkuN%3DEB8gRWCbQb28U%3DgU-cGisaOCS25k%2BGEn37gvQ%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrbrkuN%3DEB8gRWCbQb28U%3DgU-cGisaOCS25k%2BGEn37gvQ%40mail.gmail.com?utm_medium=email&utm_source=footer).

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [March 2, 2015, 4:49pm UTC](https://discourse.ats-lang.org/t/how-to-use-pointer-chain/819/3 "2015-03-02T16:49:22Z")

</div>

That helps. But I feel it is still too burdensome.On Monday, March 2, 2015 at 9:12:16 AM UTC-5, Shea Levy wrote:

> Could we leverage something like operator dot overloading but for → to  
> wrap all of the takeout/addback?
> 
> On Mar 2, 2015, at 8:53 AM, Hongwei Xi \<[gmh...@gmail.com](mailto:gmh...@gmail.com) \<javascript:\>\> wrote:
> 
> Yes, this is a question I have been asking myself for a long time!
> 
> I do not yet have a good solution. I can outline some of my ideas in a  
> separate message.
> 
> > > The wall is code “dentry-\>d\_sb-\>s\_op-\>statfs”.  
> > > In ATS2, we should create own view and use takeout/addback pattern?
> 
> Doing it manually is simply too much work.
> 
> Basically, I think we need to implement some kind of meta-programming  
> support for  
> handling structs in C.
> 
> On Mon, Mar 2, 2015 at 8:39 AM, Kiwamu Okabe \<kiw…@debian.or.jp \<javascript:\>\> wrote:
> 
> > Hi all,
> > 
> > I have read “Preventing heartbleed bugs with safe programming languages”  
> > entry  
> > at BLUISH CODER.
> > 
> > [Preventing heartbleed bugs with safe programming languages](http://bluishcoder.co.nz/2014/04/11/preventing-heartbleed-bugs-with-safe-languages.html)
> > 
> > It explains re-write C language implementation using ATS, little by  
> > little.  
> > So great!
> > 
> > However, my code sometimes meet wall called as “pointer chain”.  
> > The “pointer chain” example is following:
> > 
> > static int statfs\_by\_dentry(struct dentry \*dentry, struct kstatfs \*buf)  
> > {  
> > int retval;
> > 
> > ```
> > if (!dentry->d_sb->s_op->statfs)
> > return -ENOSYS;
> > 
> > memset(buf, 0, sizeof(*buf));
> > retval = security_sb_statfs(dentry);
> > if (retval)
> > return retval;
> > retval = dentry->d_sb->s_op->statfs(dentry, buf);
> > 
> > ```
> > 
> > The wall is code “dentry-\>d\_sb-\>s\_op-\>statfs”.  
> > In ATS2, we should create own view and use takeout/addback pattern?
> > 
> > [Design patterns · githwxi/ATS-Postiats Wiki · GitHub](https://github.com/githwxi/ATS-Postiats/wiki/Design-patterns#takeout-addback-pattern)
> > 
> > Or, is there more better solution?
> > 
> > ## Thank’s,
> > 
> > Kiwamu Okabe at METASEPI DESIGN
> > 
> > –  
> > You received this message because you are subscribed to the Google Groups  
> > “ats-lang-users” group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [ats-lang...@googlegroups.com](mailto:ats-lang...@googlegroups.com) \<javascript:\>.  
> > To post to this group, send email to [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com)  
> > \<javascript:\>.  
> > Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dmOt7CW-aQ%2BTBuby8i%3DRaD2mLqZhMLHx0i4%3DH-n6nwudA%40mail.gmail.com](https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dmOt7CW-aQ%2BTBuby8i%3DRaD2mLqZhMLHx0i4%3DH-n6nwudA%40mail.gmail.com)  
> > .
> 
> –  
> You received this message because you are subscribed to the Google Groups  
> “ats-lang-users” group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [ats-lang...@googlegroups.com](mailto:ats-lang...@googlegroups.com) \<javascript:\>.  
> To post to this group, send email to [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com)  
> \<javascript:\>.  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrbrkuN%3DEB8gRWCbQb28U%3DgU-cGisaOCS25k%2BGEn37gvQ%40mail.gmail.com](https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrbrkuN%3DEB8gRWCbQb28U%3DgU-cGisaOCS25k%2BGEn37gvQ%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrbrkuN%3DEB8gRWCbQb28U%3DgU-cGisaOCS25k%2BGEn37gvQ%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrbrkuN%3DEB8gRWCbQb28U%3DgU-cGisaOCS25k%2BGEn37gvQ%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> .
