From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 80674 invoked by alias); 20 Jan 2017 16:37:53 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 80621 invoked by uid 89); 20 Jan 2017 16:37:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 20 Jan 2017 16:37:49 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 43C90A89D; Fri, 20 Jan 2017 16:37:49 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0KGbmkh004199; Fri, 20 Jan 2017 11:37:48 -0500 Subject: Re: [PATCH] Fix python-interactive with Python 3.6 To: Simon Marchi , gdb-patches@sourceware.org References: <20170120151550.24928-1-simon.marchi@ericsson.com> From: Pedro Alves Message-ID: <1b7bea3d-3044-a643-d7b9-3b11db14758f@redhat.com> Date: Fri, 20 Jan 2017 16:37:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20170120151550.24928-1-simon.marchi@ericsson.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-01/txt/msg00422.txt.bz2 On 01/20/2017 03:15 PM, Simon Marchi wrote: > Since Python 3.4, the callback installed in PyOS_ReadlineFunctionPointer > should return a value allocated with PyMem_RawMalloc instead of > PyMem_Malloc. The reason is that PyMem_Malloc must be called with the > Python Global Interpreter Lock (GIL) held, which is not the case in the > context where this function is called. PyMem_RawMalloc was introduced > for cases like this. > > +/* Starting from Python 3.4, the result of the PyOS_ReadlineFunctionPointer > + callback must be allocated with PyMem_RawMalloc rather than PyMem_Malloc. */ > + > +#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 4 This will break with PY_MAJOR_VERSION 4 (at some point :-) ). Write: #if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 4) ? Or add some macro that makes it a bit easier to write, like "#if HAVE_PY_AT_LEAST(3, 4)" or "#if GDB_PY_VERSION >= 3004" (like GCC_VERSION). Or use Python's PY_VERSION_HEX, like "#if PY_VERSION_HEX >= 0x03040000". > +#define PyOS_ReadlineFunctionPointer_Malloc PyMem_RawMalloc > +#else > +#define PyOS_ReadlineFunctionPointer_Malloc PyMem_Malloc > +#endif It sounds like we'll find other cases that will need to call PyMem_RawMalloc going forward? How about handling this similarly to how we handle fixing up other missing Python bits, in python-internal.h. Like: #if python < 3.4 static inline void * gdb_PyMem_RawMalloc (size_t n) { return gdb_PyMem_Malloc (n); } #define PyMem_RawMalloc(n) gdb_PyMem_RawMalloc (n) #endif > + > /* Readline function suitable for PyOS_ReadlineFunctionPointer, which > is used for Python's interactive parser and raw_input. In both > cases, sys_stdin and sys_stdout are always stdin and stdout > @@ -63,7 +73,7 @@ gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout, > /* Detect EOF (Ctrl-D). */ > if (p == NULL) > { > - q = (char *) PyMem_Malloc (1); > + q = (char *) PyOS_ReadlineFunctionPointer_Malloc (1); and then write PyMem_RawMalloc here. Thanks, Pedro Alves