pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jay Levitt <jay.levitt@gmail.com>
To: pgsql-docs@postgresql.org <pgsql-docs@postgresql.org>
Subject: [PATCH] Use idiomatic style for varlena structs
Date: Mon, 13 Feb 2012 09:45:23 -0500
Message-ID: <4F392203.2040907@gmail.com> (raw)

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

Attachments:

vl_len_.patch (text/plain, 1.6K) download 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 <para> 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 <literal>vl_len_</literal>. 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 <programlisting> typedef struct { - int4 length; + int32 vl_len_; char data[1]; } text; </programlisting> @@ -1799,10 +1801,10 @@ memcpy(destination->data, buffer, 40); ]]> </programlisting> - <literal>VARHDRSZ</> is the same as <literal>sizeof(int4)</>, but + <literal>VARHDRSZ</> is the same as <literal>sizeof(int32)</>, but it's considered good style to use the macro <literal>VARHDRSZ</> to refer to the size of the overhead for a variable-length type. - Also, the length field <emphasis>must</> be set using the + Also, the vl_len_ field <emphasis>must</> be set using the <literal>SET_VARSIZE</> macro, not by simple assignment. </para>

view thread (4+ messages)  latest in thread

Message-ID: <4F392203.2040907@gmail.com>
Permalink:  ../4F392203.2040907@gmail.com/
Also on:    postgresql.org/message-id/4F392203.2040907@gmail.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: jay.levitt@gmail.com
  Subject: Re: [PATCH] Use idiomatic style for varlena structs
  In-Reply-To: <4F392203.2040907@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox