[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14180] trunk/blender/source/blender: Python API
Ken Hughes
khughes at pacific.edu
Thu Mar 20 06:00:00 CET 2008
Revision: 14180
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14180
Author: khughes
Date: 2008-03-20 05:59:59 +0100 (Thu, 20 Mar 2008)
Log Message:
-----------
Python API
----------
Bugfix #6543: Blender.Library.Load() could segfault if called more than once
with a library of different endian type. In the process discovered an
invalid memory reference in other another function calling library_append().
Thanks to Brecht for the pointers on tracking this old bug down.
Modified Paths:
--------------
trunk/blender/source/blender/blenloader/BLO_readfile.h
trunk/blender/source/blender/blenloader/intern/readfile.c
trunk/blender/source/blender/python/api2_2x/Library.c
Modified: trunk/blender/source/blender/blenloader/BLO_readfile.h
===================================================================
--- trunk/blender/source/blender/blenloader/BLO_readfile.h 2008-03-19 22:59:11 UTC (rev 14179)
+++ trunk/blender/source/blender/blenloader/BLO_readfile.h 2008-03-20 04:59:59 UTC (rev 14180)
@@ -238,7 +238,7 @@
int BLO_has_bfile_extension(char *str);
void BLO_library_append(struct SpaceFile *sfile, char *dir, int idcode);
void BLO_library_append_(BlendHandle **libfiledata, struct direntry* filelist, int totfile, char *dir, char* file, short flag, int idcode);
-void BLO_script_library_append(BlendHandle *bh, char *dir, char *name, int idcode, short flag, struct Scene *scene);
+void BLO_script_library_append(BlendHandle **bh, char *dir, char *name, int idcode, short flag, struct Scene *scene);
BlendFileData* blo_read_blendafterruntime(int file, int actualsize, BlendReadError *error_r);
Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c 2008-03-19 22:59:11 UTC (rev 14179)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c 2008-03-20 04:59:59 UTC (rev 14180)
@@ -8578,38 +8578,38 @@
/* common routine to append/link something from a library */
static Library* library_append( Scene *scene, char* file, char *dir, int idcode,
- int totsel, FileData *fd, struct direntry* filelist, int totfile, short flag)
+ int totsel, FileData **fd, struct direntry* filelist, int totfile, short flag)
{
Main *mainl;
Library *curlib;
/* make mains */
- blo_split_main(&fd->mainlist, G.main);
+ blo_split_main(&(*fd)->mainlist, G.main);
/* which one do we need? */
- mainl = blo_find_main(fd, &fd->mainlist, dir, G.sce);
+ mainl = blo_find_main(*fd, &(*fd)->mainlist, dir, G.sce);
- mainl->versionfile= fd->fileversion; /* needed for do_version */
+ mainl->versionfile= (*fd)->fileversion; /* needed for do_version */
curlib= mainl->curlib;
if(totsel==0) {
- append_named_part(fd, mainl, scene, file, idcode, flag);
+ append_named_part(*fd, mainl, scene, file, idcode, flag);
}
else {
int a;
for(a=0; a<totfile; a++) {
if(filelist[a].flags & ACTIVE) {
- append_named_part(fd, mainl, scene, filelist[a].relname, idcode, flag);
+ append_named_part(*fd, mainl, scene, filelist[a].relname, idcode, flag);
}
}
}
/* make main consistant */
- expand_main(fd, mainl);
+ expand_main(*fd, mainl);
/* do this when expand found other libs */
- read_libraries(fd, &fd->mainlist);
+ read_libraries(*fd, &(*fd)->mainlist);
if(flag & FILE_STRINGCODE) {
@@ -8620,10 +8620,10 @@
BLI_makestringcode(G.sce, mainl->curlib->name);
}
- blo_join_main(&fd->mainlist);
- G.main= fd->mainlist.first;
+ blo_join_main(&(*fd)->mainlist);
+ G.main= (*fd)->mainlist.first;
- lib_link_all(fd, G.main);
+ lib_link_all(*fd, G.main);
lib_verify_nodetree(G.main, 0);
fix_relpaths_library(G.sce, G.main); /* make all relative paths, relative to the open blend file */
@@ -8642,8 +8642,9 @@
/* 20041208: put back. It only linked direct, not indirect objects (ton) */
/* patch to prevent switch_endian happens twice */
- if(fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
- blo_freefiledata( fd );
+ if((*fd)->flags & FD_FLAGS_SWITCH_ENDIAN) {
+ blo_freefiledata( *fd );
+ *fd = NULL;
}
return curlib;
@@ -8654,11 +8655,11 @@
/* append to G.scene */
/* this should probably be moved into the Python code anyway */
-void BLO_script_library_append(BlendHandle *bh, char *dir, char *name,
+void BLO_script_library_append(BlendHandle **bh, char *dir, char *name,
int idcode, short flag, Scene *scene )
{
/* try to append the requested object */
- library_append( scene, name, dir, idcode, 0, (FileData *)bh, NULL, 0, flag );
+ library_append( scene, name, dir, idcode, 0, (FileData **)bh, NULL, 0, flag );
/* do we need to do this? */
DAG_scene_sort(G.scene);
@@ -8674,6 +8675,7 @@
void BLO_library_append_(BlendHandle** libfiledata, struct direntry* filelist, int totfile, char *dir, char* file, short flag, int idcode)
{
FileData *fd= (FileData*) (*libfiledata);
+ int lastflags = fd->flags;
Library *curlib;
Base *centerbase;
Object *ob;
@@ -8706,13 +8708,8 @@
if(flag & FILE_AUTOSELECT) scene_deselect_all(G.scene);
- curlib = library_append( G.scene, file, dir, idcode, totsel, fd, filelist, totfile,flag );
+ curlib = library_append( G.scene, file, dir, idcode, totsel, (FileData**) libfiledata, filelist, totfile,flag );
- /* patch to prevent switch_endian happens twice */
- if(fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
- (*libfiledata)= 0;
- }
-
/* when not linking (appending)... */
if((flag & FILE_LINK)==0) {
if(flag & FILE_ATCURSOR) {
Modified: trunk/blender/source/blender/python/api2_2x/Library.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Library.c 2008-03-19 22:59:11 UTC (rev 14179)
+++ trunk/blender/source/blender/python/api2_2x/Library.c 2008-03-20 04:59:59 UTC (rev 14180)
@@ -1,5 +1,5 @@
/**
- * $Id: Library.c 10943 2007-06-16 12:24:41Z campbellbarton $
+ * $Id$
*
* Blender.Library BPython module implementation.
* This submodule has functions to append data from .blend files.
@@ -175,7 +175,7 @@
BLI_strncpy(filename, G.sce, sizeof(filename));
bpy_openlib = BLO_blendhandle_from_file( fname1 );
BLI_strncpy(G.sce, filename, sizeof(filename));
-
+
if( !bpy_openlib )
return EXPP_ReturnPyObjError( PyExc_IOError, "file not found" );
@@ -344,6 +344,7 @@
int blocktype = 0;
int linked = 0;
+
if( !bpy_openlib ) {
return EXPP_ReturnPyObjError( PyExc_IOError,
"no library file: you need to open one, first." );
@@ -359,12 +360,19 @@
if( !blocktype )
return EXPP_ReturnPyObjError( PyExc_NameError,
"no such Blender datablock type" );
-
+
if (linked)
- BLO_script_library_append( bpy_openlib, bpy_openlibname, name, blocktype, FILE_LINK, G.scene);
+ BLO_script_library_append( &bpy_openlib, bpy_openlibname, name, blocktype, FILE_LINK, G.scene);
else
- BLO_script_library_append( bpy_openlib, bpy_openlibname, name, blocktype, 0, G.scene);
-
+ BLO_script_library_append( &bpy_openlib, bpy_openlibname, name, blocktype, 0, G.scene);
+
+ /*
+ NOTE: BLO_script_library_append() can close the library if there is
+ an endian issue. if this happened, reopen for the next call.
+ */
+ if ( !bpy_openlib )
+ bpy_openlib = BLO_blendhandle_from_file( bpy_openlibname );
+
if( update ) {
M_Library_Update( self );
Py_DECREF( Py_None ); /* incref'ed by above function */
@@ -610,7 +618,7 @@
}
/* import from the libary */
- BLO_script_library_append( openlib, longFilename, name, self->type, mode,
+ BLO_script_library_append( &openlib, longFilename, name, self->type, mode,
scene );
/*
More information about the Bf-blender-cvs
mailing list