Return-Path: X-Original-To: apmail-incubator-lucy-dev-archive@www.apache.org Delivered-To: apmail-incubator-lucy-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B8A0193D1 for ; Thu, 5 Jan 2012 19:33:39 +0000 (UTC) Received: (qmail 2987 invoked by uid 500); 5 Jan 2012 19:33:39 -0000 Delivered-To: apmail-incubator-lucy-dev-archive@incubator.apache.org Received: (qmail 2939 invoked by uid 500); 5 Jan 2012 19:33:39 -0000 Mailing-List: contact lucy-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucy-dev@incubator.apache.org Delivered-To: mailing list lucy-dev@incubator.apache.org Received: (qmail 2931 invoked by uid 99); 5 Jan 2012 19:33:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jan 2012 19:33:38 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of loganbell@gmail.com designates 209.85.215.175 as permitted sender) Received: from [209.85.215.175] (HELO mail-ey0-f175.google.com) (209.85.215.175) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jan 2012 19:33:32 +0000 Received: by eaal1 with SMTP id l1so608478eaa.6 for ; Thu, 05 Jan 2012 11:33:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=wwH2bVvmcGIdolqm8ZuIq8oaSnnRc4jTwCoLrDNK+n8=; b=W01T6VWaIEiukPYrJ34/TenIg+rvLem8XfeU/65ff2jd7vPymMDEJUDpx9YHRLW5Nw U8OXBqCTcbIkd3vAF+Vhjala/Pw/qdNX6H/uFs/tu9u9Zr3PGF0rawOllJ4Um1mQxzYe bnH2e1jW0Lmvc3Hrto3naIuwZExBWF49YkgvE= MIME-Version: 1.0 Received: by 10.205.133.129 with SMTP id hy1mr1436360bkc.28.1325791992323; Thu, 05 Jan 2012 11:33:12 -0800 (PST) Received: by 10.204.58.138 with HTTP; Thu, 5 Jan 2012 11:33:12 -0800 (PST) In-Reply-To: <20120105184129.GA30433@rectangular.com> References: <20120105073824.93378238890B@eris.apache.org> <20120105184129.GA30433@rectangular.com> Date: Thu, 5 Jan 2012 11:33:12 -0800 Message-ID: From: Logan Bell To: lucy-dev@incubator.apache.org Content-Type: multipart/alternative; boundary=001517475f76bf9fb504b5cd006f X-Virus-Checked: Checked by ClamAV on apache.org Subject: Re: [lucy-dev] Ruby allocation/initialization --001517475f76bf9fb504b5cd006f Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable In regard to the allocation function and the need to create an empty object has had me digging a bit more in the pickaxe book. The allocator is only needed "if the object you=92re implementing doesn=92t use any data other th= an Ruby instance variables, then you don=92t need to write an allocation function=97Ruby=92s default allocator will work just fine. " If I understan= d that correctly, since our (Clownfish::CFC::Hierarchy) object does need data then we need to allocate the space up front in the allocator function. Further it goes on to outline reasons why this is necessary ( marshaling as you pointed out being one of them ): "One of the reasons for this multistep object creation protocol is that it lets the interpreter handle situations where objects have to be created by =93back-door means.=94 One example is when objects are being deserialized f= rom their marshaled form. Here, the interpreter needs to create an empty object (by calling the allocator), but it cannot call the initializer (because it has no knowledge of the parameters to use). Another common situation is when objects are duplicated or cloned." It might be worth doing some code diving on the ruby end to see for sure, but I can see value in in having constructors that accept no arguments. /Logan On Thu, Jan 5, 2012 at 10:41 AM, Marvin Humphrey wr= ote: > On Thu, Jan 05, 2012 at 07:38:24AM -0000, logie@apache.org wrote: > > URL: http://svn.apache.org/viewvc?rev=3D1227512&view=3Drev > > Log: > > Added CFCHierarchy_allocate in order to play nice within > > the ruby object allocation patterns. Updated CFCHierarchy_new to > > call this function instead when creating the base CFCHIERARCHY_META > > struct. > > Summarizing and continuing an IRC discussion: > > The example code in the pickaxe book's appendix on the Ruby's C API (free > download linked off of < > http://pragprog.com/book/ruby3/programming-ruby-1-9>) > for defining a class requires both an allocation function and an > initialization function. We have the initialization function already: > > CFCHierarchy* > CFCHierarchy_init(CFCHierarchy *self, const char *source, const char > *dest); > > However, before this commit, we did not have an allocation function which > met > Ruby's needs: > > * Take no arguments. > * Return a "blank" object. (Essentially, something suitable for runni= ng > through the initialization function.) > > We have CFCHierarchy_new(), but it takes arguments and returns a complete > object. > > CFCHierarchy* > CFCHierarchy_new(const char *source, const char *dest); > > Here the new allocator: > > CFCHierarchy* > CFCHierarchy_allocate(); > > I understand the need for zero-argument constructors e.g. when > deserializing, > though I don't completely understand whether the allocator is an absolute > requirement for defining a Ruby class extension or just a quirk of the > example > code. > > If it's a requirement, we'll presumably be modifying Lucy's classes > eventually > and adding allocators there to accommodate Ruby. > > Marvin Humphrey > > --001517475f76bf9fb504b5cd006f--