[Boost-bugs] [Boost C++ Libraries] #11894: boost::python::file_exec not fully closing file with Python 3.4.3

Subject: [Boost-bugs] [Boost C++ Libraries] #11894: boost::python::file_exec not fully closing file with Python 3.4.3
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-01-07 12:03:39


#11894: boost::python::file_exec not fully closing file with Python 3.4.3
------------------------------+-------------------------------
 Reporter: alison.shaw@… | Owner: rwgk
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: python USE GITHUB
  Version: Boost 1.57.0 | Severity: Problem
 Keywords: |
------------------------------+-------------------------------
 Using Python 3.4.3 and Boost 1.57.0 on 64-bit Windows 7 with Visual Studio
 2013.

 After boost::python::exec_file is called on a file, that file can't be
 modified by the program using fopen_s, I think because it is still open.
 Possibly related to #8058.

 In the following example, when ModifyFile is called before executing the
 file, it succeeds. After the file has been executed, fopen_s returns 13
 (Permission denied) and ModifyFile returns false.

 {{{
 #include "stdafx.h"
 #include "boost\python.hpp"
 #include <iostream>

 #define FILE_NAME "myTest.py"

 void ModifyFile( std::string newContent )
 {
   FILE* myFile = nullptr;
   errno_t result = fopen_s( &myFile, FILE_NAME, "wb" );
   if ( result == 0 )
   {
     fwrite( newContent.c_str( ), sizeof( byte ), newContent.length( ),
 myFile );
     fclose( myFile );
     std::cout << "Success" << std::endl;
     return;
   }

   std::cout << "Failure" << std::endl;
 }

 int main( int argc, char** argv )
 {
   Py_Initialize( );

   ModifyFile( "print(\"Hello\")" );

   boost::python::api::object mainNamespace = boost::python::import(
 "__main__" ).attr( "__dict__" );
   boost::python::exec_file( FILE_NAME, mainNamespace, mainNamespace );

   ModifyFile("print(\"Goodbye\")");

   Py_Finalize( );
   return 0;
 }
 }}}

 I have tried a similar example using std::fstream to modify the file, and
 this doesn't seem to have the same problems.

 (Apologies for not using Github as per the component description - I
 didn't find more detailed instructions in the guidelines for reporting
 bugs.)

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/11894>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:19 UTC