Revision: 16451 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16451 Author: campbellbarton Date: 2008-09-10 03:17:03 +0200 (Wed, 10 Sep 2008)
Log Message: ----------- BPY merge from apricot branch. work around non unix line endings using pythons execfile() function rather then loading the binary data and manually stripping the line endings. Modified Paths: -------------- trunk/blender/source/blender/python/BPY_interface.c Modified: trunk/blender/source/blender/python/BPY_interface.c =================================================================== --- trunk/blender/source/blender/python/BPY_interface.c 2008-09-09 22:40:10 UTC (rev 16450) +++ trunk/blender/source/blender/python/BPY_interface.c 2008-09-10 01:17:03 UTC (rev 16451) @@ -778,10 +778,7 @@ PyObject *py_dict, *py_res, *pyarg; Text *text = NULL; BPy_constant *info; - int len; - FILE *fp = NULL; - PyGILState_STATE gilstate = PyGILState_Ensure(); if (!BLI_exists(script->scriptname)) { @@ -825,12 +822,8 @@ Py_INCREF( Py_None ); pyarg = Py_None; } else { - if (BLI_exists(script->scriptname)) { - fp = fopen( script->scriptname, "rb" ); - } - - if( !fp ) { - printf( "Error loading script: couldn't open file %s\n", script->scriptname ); + if (!BLI_exists(script->scriptname)) { + printf( "Script does not exit %s\n", script->scriptname ); free_libblock( &G.main->script, script ); PyGILState_Release(gilstate); return 0; @@ -875,51 +868,17 @@ if (text) { py_res = RunPython( text, py_dict ); } else { + char pystring[sizeof(script->scriptname) + 15]; + sprintf(pystring, "execfile(r'%s')", script->scriptname); + py_res = PyRun_String( pystring, Py_file_input, py_dict, py_dict ); + } + + if( !py_res ) { /* Failed execution of the script */ /* Previously we used PyRun_File to run directly the code on a FILE * object, but as written in the Python/C API Ref Manual, chapter 2, * 'FILE structs for different C libraries can be different and * incompatible'. * So now we load the script file data to a buffer */ - char *buffer=NULL, *buffer_ofs=NULL, *b_to, *b_from; - - fseek( fp, 0L, SEEK_END ); - len = ftell( fp ); - fseek( fp, 0L, SEEK_SET ); - - buffer = buffer_ofs = MEM_mallocN( len + 2, "pyfilebuf" ); /* len+2 to add '\n\0' */ - len = fread( buffer, 1, len, fp ); - - buffer[len] = '\n'; /* fix syntax error in files w/o eol */ - buffer[len + 1] = '\0'; - - - /* fast clean-up of dos cr/lf line endings, remove convert '\r\n's to '\n' */ - if (*buffer_ofs == '\r' && *(buffer_ofs+1) == '\n') { - buffer_ofs++; - } - b_from = b_to = buffer_ofs; - - while(*b_from != '\0') { - if (*b_from == '\r' && *( b_from+1 ) == '\n') { - b_from++; - } - if (b_from != b_to) { - *b_to = *b_from; - } - b_to++; - b_from++; - } - *b_to = '\0'; - /* done cleaning the string */ - - fclose( fp ); - - py_res = PyRun_String( buffer_ofs, Py_file_input, py_dict, py_dict ); - MEM_freeN( buffer ); - } - - if( !py_res ) { /* Failed execution of the script */ - BPY_Err_Handle( script->id.name + 2 ); ReleaseGlobalDictionary( py_dict ); script->py_globaldict = NULL; _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs