Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'debugging': 0.05; '"c"': 0.07; 'item.': 0.07; 'reason,': 0.07; 'received:64.202.165': 0.07; 'type,': 0.07; 'python': 0.09; '*is*': 0.09; 'called.': 0.09; 'indicates': 0.09; "object's": 0.09; 'objects.': 0.09; 'pointer;': 0.09; 'pointers': 0.09; 'slices': 0.09; 'storage.': 0.09; 'subject:()': 0.09; 'tuple': 0.09; 'typedef': 0.09; 'undocumented': 0.09; 'count,': 0.16; 'count.': 0.16; 'debugged': 0.16; 'length,': 0.16; 'merely': 0.16; 'pointer,': 0.16; 'pointers,': 0.16; 'received:64.202.165.38': 0.16; 'received:smtpauth21.prod.mesa1.secureserver.net': 0.16; 'subject:array': 0.16; 'wrote:': 0.17; 'bytes': 0.17; 'copied': 0.17; 'odd': 0.17; 'pieces': 0.17; 'pointer': 0.17; 'are:': 0.20; 'all,': 0.21; 'fairly': 0.21; 'struct': 0.22; 'tuples': 0.22; 'somewhere': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'appear': 0.26; '2.6': 0.27; 'start,': 0.27; 'fixed': 0.28; 'chris': 0.28; 'pointer.': 0.29; 'objects': 0.29; 'words': 0.29; 'source': 0.29; 'function': 0.30; 'figure': 0.30; 'code': 0.31; 'getting': 0.33; 'says': 0.33; 'int': 0.33; 'to:addr :python-list': 0.33; 'list': 0.35; 'whatever': 0.35; 'data,': 0.35; 'generic': 0.35; 'expected': 0.35; 'pm,': 0.35; 'there': 0.35; 'but': 0.36; 'be.': 0.36; 'should': 0.36; 'does': 0.37; 'two': 0.37; 'item': 0.37; 'passed': 0.37; 'rather': 0.37; 'subject:: ': 0.38; 'comment': 0.38; 'object': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'step': 0.39; 'called': 0.39; 'your': 0.60; 'received:network': 0.61; 'received:unknown': 0.63; 'information': 0.63; 'making': 0.64; 'note:': 0.64; 'contents.': 0.65; 'forward': 0.66; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'grow': 0.74; 'ref': 0.84; 'stop,': 0.84; 'struct.': 0.84; 'info,': 0.91; 'imagine': 0.96 Date: Mon, 29 Oct 2012 15:39:42 -0700 From: Andrew Robinson User-Agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111126 Thunderbird/8.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Negative array indicies and slice() References: <6998a955-7b34-4f4f-b8d6-62d1028f7561@googlegroups.com> <4c024364-84df-403b-8b9e-4a4c8f06121c@googlegroups.com> <508e6649$0$29967$c3e8da3$5496439d@news.astraweb.com> <508E1BC9.3000308@r3dsolutions.com> <508EC428.5080808@r3dsolutions.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: andrew3@r3dsolutions.com List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351575542 news.xs4all.nl 6932 [2001:888:2000:d::a6]:51855 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32464 On 10/29/2012 06:49 PM, Chris Kaynor wrote: > Every Python object requires two pieces of data, both of which are > pointer-sized (one is a pointer, one is an int the size of a pointer). > These are: a pointer to the object's type, and the object's reference > count. A tuple actually does not need a head pointer: the head pointer > is merely an offset from the tuple's pointer. It merely has a ref > count, type, an item count, and pointers to its contents. A slice has > the same type pointer and reference count, then three pointers to the > start, stop, and step objects. This means a slice object should be the > same size as a two-item tuple: the tuple needs a count, while that is > fixed at 3 for a slice (though some items may be unset). NOTE: The > above is taken from reading the source code for Python 2.6. For some > odd reason, I am getting that an empty tuple consists of 6 > pointer-sized objects (48 bytes on x64), rather than the expected 3 > pointer-sized (24 bytes on x64). Slices are showing up as the expected > 5 pointer-sized (40 bytes on x64), and tuples grow at the expected 1 > pointer (8 bytes on x64) per item. I imagine I am missing something, > but cannot figure out what that would be. >> All I see is: >> typedef struct { object** whatever } PyTupleObject; >> It's fairly straight forward in 3.2.0. I debugged the code with GDB and watched. Perhaps it is the same in 2.6 ? In addition to those items you mention, of which the reference count is not even *inside* the struct -- there is additional debugging information not mentioned. Built in objects contain a "line number", a "column number", and a "context" pointer. These each require a full word of storage. Also, built in types appear to have a "kind" field which indicates the object "type" but is not a pointer. That suggests two "object" type indicators, a generic pointer (probably pointing to "builtin"? somewhere outside the struct) and a specific one (an enum) inside the "C" struct. Inside the tuple struct, I count 4 undocumented words of information. Over all, there is a length, the list of pointers, a "kind", "line", "col" and "context"; making 6 pieces in total. Although your comment says the head pointer is not required; I found in 3.3.0 that it is a true head pointer; The Tuple() function on line 2069 of Python-ast.c, (3.3 version) -- is passed in a pointer called *elts. That pointer is copied into the Tuple struct. How ironic, slices don't have debugging info, that's the main reason they are smaller. When I do slice(3,0,2), suprisingly "Slice()" is NOT called. But when I do a[1:2:3] it *IS* called.