Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"The voters have spoken, the bastards..." -- unknown


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

SubjectAuthor
o Re: Problem slicing a list with the C APIJen Kris

1
Re: Problem slicing a list with the C API

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

  copy mid

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

  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: Re: Problem slicing a list with the C API
Date: Sat, 12 Mar 2022 22:52:48 +0100 (CET)
Lines: 59
Message-ID: <mailman.285.1647121970.2329.python-list@python.org>
References: <My-05ih--3-2@tutanota.com>
<e1227dc7-cce9-2b3d-1648-fb297f95fd8a@mrabarnett.plus.com>
<My-6eSM--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 TkOu1D9kvZiDtXPf9RDJBARRv1mhlTYC9/wD8ZgpspkQ==
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=0E24bXCC;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'comments': 0.03;
'parameter': 0.05; 'mar': 0.07; 'subject:API': 0.07; 'cc:addr
:python-list': 0.09; 'ideas.': 0.09; 'subject:list': 0.11;
'url:mailman': 0.15; 'that.': 0.15; '2.)': 0.16; '2022,': 0.16;
'both.': 0.16; 'cc:name:python list': 0.16; 'context.': 0.16;
'iterate': 0.16; 'now.\xc2\xa0': 0.16; 'pyobject*': 0.16; 'tuple':
0.16; 'wrote:': 0.16; 'problem': 0.16; 'python': 0.16; 'api':
0.17; 'implement': 0.19; 'cc:addr:python.org': 0.20; 'code': 0.23;
'skip:p 30': 0.23; 'received:de': 0.23; 'url-
ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24': 0.25;
'url:listinfo': 0.25; 'cc:2**0': 0.25; 'url-ip:188.166/16': 0.25;
'object': 0.26; 'suspect': 0.26; 'done': 0.28; 'chris': 0.28;
'error': 0.29; 'url-ip:188/8': 0.31; 'from,': 0.32; 'objects':
0.32; 'python-list': 0.32; 'research.': 0.32;
'received:192.168.1': 0.32; 'but': 0.32; '0);': 0.33; 'header:In-
Reply-To:1': 0.34; 'handling': 0.35; 'final': 0.35; 'also,': 0.36;
'received:192.168': 0.37; 'thanks': 0.38; 'two': 0.39; 'enough':
0.39; 'this,': 0.39; 'list': 0.39; 'use': 0.39; 'above': 0.62;
'i\xe2\x80\x99ve': 0.62; 'leading': 0.63; 'verify': 0.64; 'key':
0.64; 'clear': 0.64; 'per': 0.68; '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=1647121968;
s=s1; d=tutanota.com;
h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:In-Reply-To:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender;
bh=1A4CHLIi15AqQvYJYz3TP0O8LxPXPV6lTyNKPIhY5Kk=;
b=0E24bXCCvsiaHrAvSTOnTElJHy5ENrCvP7wwFRMLvvxvv7OqUMYH9gkX+jMpowUV
o1VblDOPl+Wje4lwm4l+XXTCOtzc7jKmguyZygffWVcXKuDxSmS6cQ9njW0S+cfrNI7
n9+hzQeSJJxlRmoNR6ldwomsbibdunwa0pBamgCfIeWU/GJ9Qy33YkPS/AxAOcU/PJ7
IEnQgjcoN7BA+hTYzz5XOf4MPvN4AkYDvo7J4xa04Fk8hP5FNz40jXnwm9T/J45PxFF
ZNjQgBwa6vJxtD0WwVsPUxTvaXTUcsSYr6jj63p3DYpz3jbVodd2y4+dN7ZgwKl0e9G
tkyykR5qMw==
In-Reply-To: <e1227dc7-cce9-2b3d-1648-fb297f95fd8a@mrabarnett.plus.com>
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-6eSM--3-2@tutanota.com>
X-Mailman-Original-References: <My-05ih--3-2@tutanota.com>
<e1227dc7-cce9-2b3d-1648-fb297f95fd8a@mrabarnett.plus.com>
 by: Jen Kris - Sat, 12 Mar 2022 21:52 UTC

Thanks to you both.  I am going to implement PySequence_Get_Slice now.  If I have trouble then, per comments from Chris Angelico, I will iterate through pDictData to verify it because I haven't done that.  It is not null, however. 

 Jen

Mar 12, 2022, 13:40 by python@mrabarnett.plus.com:

> On 2022-03-12 21:24, Jen Kris via Python-list wrote:
>
>> 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.
>>
> Use PySequence_GetSlice to slice the list.
>
> Also, why use floats when you can use integers?
>
> long round_half = records_count / 2;
>
> (In Python that would be half_slice = len(dictdata) // 2.)
> --
> https://mail.python.org/mailman/listinfo/python-list
>

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor