[Bf-python] PyRun_File vs PyRun_String

Campbell Barton ideasman42 at gmail.com
Sat May 10 17:32:13 CEST 2008


Hi, yesterday I was looking into a bug where the python file had
windows line endings converted incorrectly.
Now I'm left wondering why we cant use PyRun_File which would be a lot
easier/faster, then loading the buffer and doing line ending checks.

The comments give this reason, but Im wondering if its still valid.
Id like to know what platforms PyRun_File didnt work on or maybe some
more details from "Python/C API Ref Manual, chapter 2"

its too late to change this before release but it would be nice to
make use of pythons builtin functions where possible.

- Cam

---------- Details below.
Existing workaround

		/* 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 */

--------------------------------- Commends from svn blame - stivs?
3209       stiv 	/* Previously we used PyRun_File to run directly the
code on a FILE
3209       stiv 	 * object, but as written in the Python/C API Ref
Manual, chapter 2,
3209       stiv 	 * 'FILE structs for different C libraries can be
different and
3209       stiv 	 * incompatible'.
1955    ianwill 	 * So now we load the script file data to a buffer */

------------------------------------------------------------------------
r3209 | stiv | 2004-10-07 21:25:40 +0200 (Thu, 07 Oct 2004) | 16 lines

Another step in the Big Bpy Cleanup.

- move static declarations and data definitions out of headers.
  the BGL module still need cleaning.

- move declarations out of modules.h and into appropriate .h files.
  modules.h still exists as a container for the few modules that
  need to #include almost everything.

- all files now have a $Id tag and have been formatted by indent

there are no changes to executable code.

pre-commit versions are tagged with bpy-cleanup-pre-20041007
for the sake of paranoia.



More information about the Bf-python mailing list