diff --git a/python/gnatcoll-python.ads b/python/gnatcoll-python.ads index ad88dc7a..3d3e9d77 100644 --- a/python/gnatcoll-python.ads +++ b/python/gnatcoll-python.ads @@ -1,7 +1,7 @@ ------------------------------------------------------------------------------ -- G N A T C O L L -- -- -- --- Copyright (C) 2003-2019, AdaCore -- +-- Copyright (C) 2003-2020, AdaCore -- -- -- -- This library is free software; you can redistribute it and/or modify it -- -- under terms of the GNU General Public License as published by the Free -- @@ -853,6 +853,7 @@ package GNATCOLL.Python is function PyFile_FromString (File_Name, Mode : String) return PyObject; -- Create an instance of file. + -- Python3 removes this function. Use "io.open()" instead. ----------------- -- Class types -- diff --git a/python/python_support.c b/python/python_support.c index 3cf7e504..adb60552 100644 --- a/python/python_support.c +++ b/python/python_support.c @@ -1,7 +1,7 @@ /*---------------------------------------------------------------------------- -- G N A T C O L L -- -- -- --- Copyright (C) 2003-2019, AdaCore -- +-- Copyright (C) 2003-2020, AdaCore -- -- -- -- This is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -886,6 +886,16 @@ PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtr( (PyCapsule_Destructor) destruct); }; +PyAPI_FUNC(PyObject *) PyFile_FromString + (const char *file_name, const char *mode) +{ + PyObject * io = PyImport_ImportModule ("io"); + if (io == NULL) { + return NULL; + } + return PyObject_CallMethod (io, "open", "ss", file_name, mode); +} + #else int ada_is_python3() { return 0;