Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id B36581FC9B63 for ; Mon, 13 Feb 2012 10:45:39 -0400 (AST) Received: from mail-qw0-f53.google.com ([209.85.216.53]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Rwx9u-0002B8-Ri for pgsql-docs@postgresql.org; Mon, 13 Feb 2012 14:45:39 +0000 Received: by qafk1 with SMTP id k1so3261843qaf.19 for ; Mon, 13 Feb 2012 06:45:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type; bh=zoTD90sIQMhIZOQEX9AHfYJp6xK9aMkTgbIfmSbA+aI=; b=oZ3lIBi1bdfOV3s+EWMPSQlNTm5kW5vvOtzn158isl5Hp5H1Ud3Cyvj5cIo9zvOePF U8GA5XwdxadyiFy1dexd5Iw0tyXdz0NFioKigA4wdxr3bQyUVRgGIPr3oMzWCHXhONE9 Q+msdMV0QIoK+JADiga1Jxka1lSA0eMZGbUlc= Received: by 10.229.77.13 with SMTP id e13mr9343328qck.32.1329144326299; Mon, 13 Feb 2012 06:45:26 -0800 (PST) Received: from jay.local (c-24-63-250-125.hsd1.ma.comcast.net. [24.63.250.125]) by mx.google.com with ESMTPS id eo4sm17444004qab.16.2012.02.13.06.45.25 (version=SSLv3 cipher=OTHER); Mon, 13 Feb 2012 06:45:25 -0800 (PST) Message-ID: <4F392203.2040907@gmail.com> Date: Mon, 13 Feb 2012 09:45:23 -0500 From: Jay Levitt User-Agent: Postbox 3.0.2 (Macintosh/20111203) MIME-Version: 1.0 To: "pgsql-docs@postgresql.org" Subject: [PATCH] Use idiomatic style for varlena structs Content-Type: multipart/mixed; boundary="------------040205080303000504080305" X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201202/6 X-Sequence-Number: 7190 This is a multi-part message in MIME format. --------------040205080303000504080305 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I'm new to the codebase, but I think this patch reflects real-world usage; the PostgreSQL code itself always calls the length field "vl_len_", and I believe int32 is preferred over int4 (yes?) Jay Levitt --------------040205080303000504080305 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="vl_len_.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="vl_len_.patch" diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml index a6d2a13..b19801d 100644 --- a/doc/src/sgml/xfunc.sgml +++ b/doc/src/sgml/xfunc.sgml @@ -1733,9 +1733,11 @@ typedef struct Finally, all variable-length types must also be passed by reference. All variable-length types must begin - with a length field of exactly 4 bytes, and all data to + with an opaque length field of exactly 4 bytes, which will be set + by SET_VARSIZE; never set this field directly! All data to be stored within that type must be located in the memory - immediately following that length field. The + immediately following the length field, which is customarily + named vl_len_. The length field contains the total length of the structure, that is, it includes the size of the length field itself. @@ -1766,7 +1768,7 @@ typedef struct typedef struct { - int4 length; + int32 vl_len_; char data[1]; } text; @@ -1799,10 +1801,10 @@ memcpy(destination->data, buffer, 40); ]]> - VARHDRSZ is the same as sizeof(int4), but + VARHDRSZ is the same as sizeof(int32), but it's considered good style to use the macro VARHDRSZ to refer to the size of the overhead for a variable-length type. - Also, the length field must be set using the + Also, the vl_len_ field must be set using the SET_VARSIZE macro, not by simple assignment. --------------040205080303000504080305--