[Plib-devel] Porting plib to compile under win32/borland; bugs/leaks report
Brought to you by:
sjbaker
From: Maciej K. <Mac...@cs...> - 2001-08-24 11:04:32
|
Dear developers, I have been trying to build a part of plib under borland compiler and windows. I compiled sg/ssg/util, making many ad-hoc corrections (in 1.4.1). Here I will try to compare what I did with the original source, and hopefully you will incorporate my changes so that the source is more portable. COMPILATION ----------- In general, all fopen("ra") are not valid under borland. "a" is equivalent to "t" (=text). Thus every open("ra") should be changed to "rt". This could be resolved by using a global macro, like #ifdef __BORLANDC__ #define FOPEN_READ "rt" #define FOPEN_WRITE "wt" #else #define FOPEN_READ "ra" #define FOPEN_WRITE "wa" #endif ...=fopen(f,FOPEN_READ); ----- Functions ssgLoaderOptions* ssgGetCurrentOptions () void ssgSetCurrentOptions ( ssgLoaderOptions* options ) ssgEntity *ssgLoad ( char *fname, ssgBranch *(*cb)(char *)) void ssgSetAppStateCallback ( ssgState *(*cb)(char *) ) void ssgModelPath ( const char *path ) void ssgTexturePath ( const char *path ) could be moved to ssg.cxx. It would make it easier to produce libs/dlls from the source. ----- Directories are under Win32 separated by \, not /. Thus the function should look like: char* ssgLoaderOptions::make_path ( char* path, const char* dir, const char* fname ) const { if ( fname != NULL && fname [ 0 ] != '\0' ) { if ( fname [ 0 ] != '/' && fname [ 0 ] != '\\' && dir != NULL && dir[0] != '\0' ) { strcpy ( path, dir ) ; strcat ( path, "\\" ) ; strcat ( path, fname ) ; } else strcpy ( path, fname ) ; //convert backward slashes to forward slashes for ( char* ptr = path ; *ptr ; ptr ++ ) { if ( *ptr == '/' ) *ptr = '\\' ; } } else path [0] = 0 ; return( path ); } you might localize differences and use #ifdef WIN32 to choose the form suitable for the platform. [BTW, I don't know if cygwin doesn't define WIN32. If it does, and uses / to separate directiories, then it would be better to use #ifdef __BORLANDC__. But this wouldn't be perfect, because VisualC++ also uses \ to separate dirs and it defines WIN32]. The /\ problem may be present in another source files (for example, during save), maybe it should be resolved in one shared util function. --- in ssg\ssgLoadASE.cxx, #include <string.h> is needed. also, in static ssgSimpleState* get_state( aseMaterial* mat, bool prelit ) if ( strnicmp ( "ifl_", mat -> name, 4 ) == 0 ) there is no such function as strnicmp ;-(, so there should be some workaround for __BORLANDC__ using another str functions. --- in ssg\ssgLoaderWriterStuff.cxx #include <malloc.h> is needed for alloca. Two corrections for .h file, ssgListOfLists ( int init = 3 ) : ssgSimpleList ( sizeof(class ssgSimpleList*), init ) {} ssgSimpleStateList( int init = 3 ) : ssgSimpleList ( sizeof(class ssgSimpleState*), init ) {} --- in ssg\ssgLoadFLT.cxx add #include <malloc.h> --- in ssg\ssgParser.cxx problems with const, should be char *mystrchr( const char *string, int c ) // like strchr, but string may be NULL { if (string == NULL ) return NULL; else return strchr( (char*)string, c ); } [or (const)c] [[if you wish use #ifdef __BORLANDC__]] --- Similar situation in ssg\ssgSaveAC.cxx in int ssgSaveLeaf ( ssgEntity *ent ) if ( writeTextureWithoutPath ) { char *s = strrchr ( (char*)tfname, '\\' ) ; if ( s == NULL ) s = strrchr ( (char*)tfname, '/' ) ; if ( s == NULL ) fprintf ( save_fd, "texture \"%s\"\n", tfname ) ; else fprintf ( save_fd, "texture \"%s\"\n", ++s ) ; } STYLE ----- In many places, new[] is NOT matched by delete[] but by delete. I will not include the long list here, but it would be nice to fix all occurences. LEAKS ----- There are numerous memory leaks, especially in loaders. Hopefully they will be located. Hope my contribution will help in development of stable and portable plib, Regards, MacKo |