Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Felson's Law: To steal ideas from one person is plagiarism; to steal from many is research.


devel / comp.lang.python / Re: Problem slicing a list with the C API

SubjectAuthor
o Re: Problem slicing a list with the C APIChris Angelico

1
Re: Problem slicing a list with the C API

<mailman.284.1647121284.2329.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17488&group=comp.lang.python#17488

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Problem slicing a list with the C API
Date: Sun, 13 Mar 2022 08:41:12 +1100
Lines: 27
Message-ID: <mailman.284.1647121284.2329.python-list@python.org>
References: <My-05ih--3-2@tutanota.com>
<CAPTjJmrXVvdm5D-AKT_sj+2Mf2CxPUzmcbWTnQv6v9xeCzy+qQ@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de 6frJJkjo8X+84n59Tmzg2Q4NgQvClYBfkXi6SD/5Zqrg==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=e5fWAtP6;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'looks': 0.02; '2022':
0.05; 'parameter': 0.05; 'mar': 0.07; 'subject:API': 0.07; 'sun,':
0.07; 'itself,': 0.09; 'received:209.85.128.46': 0.09; 'received
:mail-wm1-f46.google.com': 0.09; 'subject:list': 0.11; '(b)':
0.16; 'be,': 0.16; 'chrisa': 0.16; 'confused': 0.16; 'context.':
0.16; 'elements.': 0.16; 'from:addr:rosuav': 0.16;
'from:name:chris angelico': 0.16; 'pyobject*': 0.16; 'to?': 0.16;
'wrote:': 0.16; 'problem': 0.16; 'python': 0.16; "aren't": 0.19;
'to:addr:python-list': 0.20; "what's": 0.22; 'skip:p 30': 0.23;
'list,': 0.24; 'intend': 0.26; 'object': 0.26; 'suspect': 0.26;
"isn't": 0.27; 'bit': 0.27; 'expect': 0.28; 'code,': 0.31;
'fine.': 0.32; 'from,': 0.32; 'objects': 0.32; 'python-list':
0.32; 'message-id:@mail.gmail.com': 0.32; 'but': 0.32; "i'm":
0.33; '0);': 0.33; 'same': 0.34; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'final': 0.35; 'from:addr:gmail.com':
0.35; 'received:209.85': 0.37; 'received:209': 0.39; 'list': 0.39;
'break': 0.39; 'here.': 0.61; 'simply': 0.63; 'key': 0.64;
'exactly': 0.68; 'square': 0.69; '(c)': 0.81; 'confirmed': 0.81;
'brackets': 0.84; 'elements,': 0.84; 'touching': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:content-transfer-encoding;
bh=Qh6T1qxmQTy+IL6HqmC2rS8FKE1UEcDRJedBXXhcryU=;
b=e5fWAtP602vNCEqJXz2D7JGZEACy9Kx2N08vcLifvPdSB8GKBZ5AJQk86j0Z65agGw
bmGmX49oMnUmwCU9BctuVk6rjk5V73hl9MB3vjcrkMlIi3G6odR+GefWekPSQbWI+5F7
Et0kPtUOqHSdEhrOnn66XALAi2l3NTJ7vN1EhG2G2KojgBe++u1b81lVLdLJRrhL/5ul
0FiKndbkqLg+jyxwG4RiwNgcz041XYUIWFPheyCc1UGSLAZFef7Xjp5kjCLAJnXXHASZ
c61q1xP/KAGAyLoC/5y6uhuDAEkiQbTyBoud1R8yzhNLDC55aKQzcdA6wJKViRm7VdiU
R7Fw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:content-transfer-encoding;
bh=Qh6T1qxmQTy+IL6HqmC2rS8FKE1UEcDRJedBXXhcryU=;
b=I+gy4m9MSiskehARDnFNf7LIe5/V6T4nCOE+RXbcuNev8oBO/PDZ6vndWVLS9sEoWg
kh7zd14MHxS8oLm1RXk8c3WTEauagwSRLBDIi8Sh2oMgnpUjkBpC9ZxEHI3OfyGsGqE4
CY56utHMWwJ6fXtQ+Cwr5oMbSkpJJi2u8t+slSfyApaSB2E8rOTlrxWKrgQ54qy0Ehw0
qeq+GllAeED1ENisFtLR+6CX5i+YUZAd8j9rQb9Ww1fRgM+juiSbqNtjoJ7oa7CvhKEB
Y4vyuQyE9u+ACSk8VZJy+5pTOdP0kVI86BCR2gsOeqh8bBbxNUmmDEIImC0YDFeIL2Iz
7rkQ==
X-Gm-Message-State: AOAM5311japVOoeKYvGsx3O9rQhiDGoKYZ/pURwuWMdiLmLO5p6j13L+
r9SL2g84Lhl1vNYua2xSFTaXlsN4jgvDbYuU+6QeRjCh
X-Google-Smtp-Source: ABdhPJwlqZKo/vyQOoHXw21Cq1xYZAuqmEf9G4zKZ4YMBuBQXqa+mbwSmJ+z6TOA7sXvsdPMrdID4Xk0ZAq1s0AgnfQ=
X-Received: by 2002:a05:600c:12d4:b0:389:efb7:a5a7 with SMTP id
v20-20020a05600c12d400b00389efb7a5a7mr6741485wmd.184.1647121283781; Sat, 12
Mar 2022 13:41:23 -0800 (PST)
In-Reply-To: <My-05ih--3-2@tutanota.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmrXVvdm5D-AKT_sj+2Mf2CxPUzmcbWTnQv6v9xeCzy+qQ@mail.gmail.com>
X-Mailman-Original-References: <My-05ih--3-2@tutanota.com>
 by: Chris Angelico - Sat, 12 Mar 2022 21:41 UTC

On Sun, 13 Mar 2022 at 08:25, Jen Kris via Python-list
<python-list@python.org> wrote:
> PyObject* slice = PySlice_New(PyLong_FromLong(0), half_slice, 0);
> PyObject* subdata_a = PyObject_GetItem(pDictddata, slice);
>
> On the final line (subdata_a) I get a segfault. I know that the second parameter of PyObject_GetItem is a “key” and I suspect that’s where the problem comes from, but I don’t understand what a key is in this context.
>

The key is simply whatever would be in the square brackets in Python
code, so that part looks fine.

But dictionaries aren't usually subscripted with slices, so I'm a bit
confused as to what's going on here. What exactly is
dictdata/pDictdata?

Have you confirmed that pDictdata (a) isn't NULL, (b) is the object
you intend it to be, and (c) contains the objects you expect it to?
The segfault might not be from the slice object itself, it might be
from actually iterating over the thing being sliced and touching all
its elements. For instance, if dictdata is actually a list, that call
will be constructing a new list with references to the same elements,
so if one of them is broken (maybe NULL), it'll break badly.

ChrisA

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor