Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Re: [PATCH, GDB] Fix Windows gdb build failure with python support
       [not found] <fd8731d0-1306-3329-5a5f-ac079b773c30@foss.arm.com>
@ 2017-04-06 15:05 ` Pedro Alves
  2017-04-06 16:20   ` Thomas Preudhomme
  0 siblings, 1 reply; 3+ messages in thread
From: Pedro Alves @ 2017-04-06 15:05 UTC (permalink / raw)
  To: Thomas Preudhomme, gdb-patches

On 04/06/2017 03:28 PM, Thomas Preudhomme wrote:
> 
> 
> GDB fails to build for Windows host with python support enabled due to

Uppercase "Python", and would be a good idea to mention that this is
Python 2.

> python_file's second argument 

It's actually PyFile_FromString's second parameter, not python_file's.
"python_file" is a reference that is being initialized from the result
of PyFile_FromString.

> being of type char * and being passed a
> string litteral. 

Typo "literal".

> This patch takes the conservative assumptions that the
> function might indeed modify the character string and use a local char
> array to pass the mode instead.

The Python API is notoriously buggy wrt to const-correctness when
it comes to string parameters.

Note that in gdb/python/python-internal.h, we have fixups for all of:

 PyObject_GetAttrString
 PyObject_HasAttrString
 PyObject_CallMethod
 PyErr_NewException
 PySys_GetObject
 PySys_SetPath
 PyGetSetDef
 PyArg_ParseTupleAndKeywords

Over the years it's been getting better.

A few of those were added just yesterday, but I didn't build Windows
with Python so I missed this one.

Now, this API in particular seems to have been removed completely
in Python 3, so there's no "it was fixed in 3.x" that we could put
in a comment.  Anyway, since this is just one single place, let's just
not bother with anything fancy.

Please just add a cast instead (and update the commit log accordingly):

  PyFile_FromString (full_path.get (), (char *) "r")

OK with that change.

Thanks,
Pedro Alves


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH, GDB] Fix Windows gdb build failure with python support
  2017-04-06 15:05 ` [PATCH, GDB] Fix Windows gdb build failure with python support Pedro Alves
@ 2017-04-06 16:20   ` Thomas Preudhomme
  2017-04-06 16:24     ` Pedro Alves
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Preudhomme @ 2017-04-06 16:20 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1728 bytes --]

Thanks Pedro.

Committed the attached patch.

Best regards,

Thomas

On 06/04/17 16:05, Pedro Alves wrote:
> On 04/06/2017 03:28 PM, Thomas Preudhomme wrote:
>>
>>
>> GDB fails to build for Windows host with python support enabled due to
>
> Uppercase "Python", and would be a good idea to mention that this is
> Python 2.
>
>> python_file's second argument
>
> It's actually PyFile_FromString's second parameter, not python_file's.
> "python_file" is a reference that is being initialized from the result
> of PyFile_FromString.
>
>> being of type char * and being passed a
>> string litteral.
>
> Typo "literal".
>
>> This patch takes the conservative assumptions that the
>> function might indeed modify the character string and use a local char
>> array to pass the mode instead.
>
> The Python API is notoriously buggy wrt to const-correctness when
> it comes to string parameters.
>
> Note that in gdb/python/python-internal.h, we have fixups for all of:
>
>  PyObject_GetAttrString
>  PyObject_HasAttrString
>  PyObject_CallMethod
>  PyErr_NewException
>  PySys_GetObject
>  PySys_SetPath
>  PyGetSetDef
>  PyArg_ParseTupleAndKeywords
>
> Over the years it's been getting better.
>
> A few of those were added just yesterday, but I didn't build Windows
> with Python so I missed this one.
>
> Now, this API in particular seems to have been removed completely
> in Python 3, so there's no "it was fixed in 3.x" that we could put
> in a comment.  Anyway, since this is just one single place, let's just
> not bother with anything fancy.
>
> Please just add a cast instead (and update the commit log accordingly):
>
>   PyFile_FromString (full_path.get (), (char *) "r")
>
> OK with that change.
>
> Thanks,
> Pedro Alves
>

[-- Attachment #2: 0001-Fix-Windows-gdb-build-failure-with-Python-2-support.patch --]
[-- Type: text/x-patch, Size: 1890 bytes --]

From 0dedf3777db42712f460123ac0c63c49de5456f5 Mon Sep 17 00:00:00 2001
From: Thomas Preud'homme <thomas.preudhomme@arm.com>
Date: Thu, 6 Apr 2017 17:17:23 +0100
Subject: [PATCH] Fix Windows gdb build failure with Python 2 support

GDB fails to build for Windows host with Python 2 support enabled due
to PyFile_FromString's second argument being of type char * and being
passed a (const) string literal. This parameter is input only so this
commit fixes the issue by casting to char *.

2017-04-06  Thomas Preud'homme  <thomas.preudhomme@arm.com>

gdb/
	* python/python.c (python_run_simple_file): Cast mode literal to
	non-const char pointer as expected by PyFile_FromString.
---
 gdb/ChangeLog       | 5 +++++
 gdb/python/python.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 880af5b..e906b87 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2017-04-06  Thomas Preud'homme  <thomas.preudhomme@arm.com>
+
+	* python/python.c (python_run_simple_file): Cast mode literal to
+	non-const char pointer as expected by PyFile_FromString.
+
 2017-04-05  Simon Marchi  <simon.marchi@ericsson.com>
 
 	* common/ptid.c (ptid_lwp_p, ptid_tid_p): Remove comparison with
diff --git a/gdb/python/python.c b/gdb/python/python.c
index cc58267..e0e24ac 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -352,7 +352,7 @@ python_run_simple_file (FILE *file, const char *filename)
   /* Because we have a string for a filename, and are using Python to
      open the file, we need to expand any tilde in the path first.  */
   gdb::unique_xmalloc_ptr<char> full_path (tilde_expand (filename));
-  gdbpy_ref<> python_file (PyFile_FromString (full_path.get (), "r"));
+  gdbpy_ref<> python_file (PyFile_FromString (full_path.get (), (char *) "r"));
   if (python_file == NULL)
     {
       gdbpy_print_stack ();
-- 
1.9.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH, GDB] Fix Windows gdb build failure with python support
  2017-04-06 16:20   ` Thomas Preudhomme
@ 2017-04-06 16:24     ` Pedro Alves
  0 siblings, 0 replies; 3+ messages in thread
From: Pedro Alves @ 2017-04-06 16:24 UTC (permalink / raw)
  To: Thomas Preudhomme, gdb-patches

On 04/06/2017 05:20 PM, Thomas Preudhomme wrote:
> Thanks Pedro.
> 
> Committed the attached patch.

Perfect, thanks!

Thanks,
Pedro Alves


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-06 16:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <fd8731d0-1306-3329-5a5f-ac079b773c30@foss.arm.com>
2017-04-06 15:05 ` [PATCH, GDB] Fix Windows gdb build failure with python support Pedro Alves
2017-04-06 16:20   ` Thomas Preudhomme
2017-04-06 16:24     ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox