Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Things equal to nothing else are equal to each other.


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

SubjectAuthor
o Problem slicing a list with the C APIJen Kris

1
Problem slicing a list with the C API

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: jenk...@tutanota.com (Jen Kris)
Newsgroups: comp.lang.python
Subject: Problem slicing a list with the C API
Date: Sat, 12 Mar 2022 22:24:09 +0100 (CET)
Lines: 37
Message-ID: <mailman.281.1647120257.2329.python-list@python.org>
References: <My-05ih--3-2@tutanota.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de UhBL+gKcw/Usyhw1QiruLQ98FuE0+4Wweg8n/Gzw4FOQ==
Return-Path: <jenkris@tutanota.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=tutanota.com header.i=@tutanota.com header.b=S6fOWBFa;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.052
X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'parameter': 0.05;
'subject:API': 0.07; 'ideas.': 0.09; 'subject:list': 0.11;
'context.': 0.16; 'pyobject*': 0.16; 'tuple': 0.16; 'problem':
0.16; 'python': 0.16; 'api': 0.17; 'to:addr:python-list': 0.20;
'code': 0.23; 'skip:p 30': 0.23; 'received:de': 0.23; 'object':
0.26; 'suspect': 0.26; 'done': 0.28; 'error': 0.29; 'from,': 0.32;
'objects': 0.32; 'research.': 0.32; 'received:192.168.1': 0.32;
'but': 0.32; '0);': 0.33; 'handling': 0.35; 'final': 0.35;
'received:192.168': 0.37; 'thanks': 0.38; 'two': 0.39; 'enough':
0.39; 'this,': 0.39; 'list': 0.39; 'above': 0.62;
'i\xe2\x80\x99ve': 0.62; 'leading': 0.63; 'key': 0.64; 'clear':
0.64; 'relevant': 0.73; 'records': 0.75; 'parts.': 0.84;
'haven\xe2\x80\x99t': 0.91; 'consists': 0.93
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1647120249;
s=s1; d=tutanota.com;
h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:Sender;
bh=6J36IMtgZDsBeOIwDzbhea3JNaECTD92rV7erNmO9n8=;
b=S6fOWBFanaI3HbVdFd+vU0ULYLL94Fh7KYHOCiwccWjL98H6c8MbIpfYwfRF4Ldu
hYHDdyrJ4ArLi7XNo2fmdR7TiPZHIujfl/UfmgqsaGzDr/GbCHtmdNKqNwuDOsaNk85
g+ugToHaKnJy9WrgU4ePKVV5BRhr4MLIRP10DIdjf2F3LtYthiEAw4GhyX0QwMRdyiD
h6b+7BPzIACf0LHTNLTeob92kKxVHFn/asw/T4wN5qr2HGcS4M7WCqAxdoDKDv1oY53
Y8NP2GIFMnsAHdnrxvn2ZJ0HugPVeHk/6hq033OAp+hghdjePytn+Paneq0m/EWlFRc
w4S7w0o6ag==
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
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: <My-05ih--3-2@tutanota.com>
 by: Jen Kris - Sat, 12 Mar 2022 21:24 UTC

I have a C API project where I have to slice a list into two parts.   Unfortunately the documentation on the slice objects is not clear enough for me to understand how to do this, and I haven’t found enough useful info through research.  The list contains tuple records where each tuple consists of a dictionary object and a string. 

The relevant part of the Python code is:

half_slice = int(len(dictdata) * 0.5)
subdata_a = dictdata[half_slice:]
subdata_b = dictdata[:half_slice]

This is what I’ve done so far with the C API:

int64_t Calc_Slices(PyObject* pDictdata, int64_t records_count)
{ long round_half = records_count * 0.5;
PyObject* half_slice = PyLong_FromLong(round_half);

PyObject* slice = PySlice_New(PyLong_FromLong(0), half_slice, 0);
PyObject* subdata_a = PyObject_GetItem(pDictddata, slice);

return 0;
}

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 code shown above omits error handling but none of the objects leading up to the final line is null, they all succeed. 

Thanks for any ideas.

Jen

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor