python3 compatibility: file interface

Document that python3 removes PyFile_FromString,
but provide a wrapper if python3 is in use.

Part of S821-014

Change-Id: I2aeeef23be667810a39004d028f16c60889e9656
This commit is contained in:
Nicolas Boulenguez
2019-09-04 20:18:08 +02:00
committed by Nicolas Roche
parent b508bcf68b
commit f47dbd0271
2 changed files with 13 additions and 2 deletions

View File

@@ -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;