Changeset 330

Show
Ignore:
Timestamp:
Tue Nov 20 07:26:38 2007
Author:
giovannibajo
Message:

Convert invocations of VS(), OTHERERROR() and FATALERROR().

From: Anton Gyllenberg <anton@iki.fi>

Convert some invocations of VS(), OTHERERROR() and FATALERROR() to use
the newly introduced printf style format strings. Examples of invocations
targetted for modification are cases multiple invocations could be handled
by one invocation with format string and those that used a string buffer
filled with strncpy() or the like.

Files:

Legend:

Unmodified
Added
Removed
Modified
  • trunk/source/linux/main.c

    r304 r330  
    61 61         Py_SetProgramName(argv[0]);  
    62 62     strcpy(thisfile, Py_GetProgramFullPath());  
    63       VS(thisfile);  
    64       VS(" is thisfile\n");  
      63     VS("thisfile is %s\n", thisfile);  
    65 64      
    66 65     workpath = getenv( "_MEIPASS2" );  
    67       VS(workpath);  
    68       VS(" is _MEIPASS2 (workpath)\n");  
      66     VS("_MEIPASS2 (workpath) is %s\n", (workpath ? workpath : "NULL"));  
    69 67  
    70 68     /* fill in here (directory of thisfile) */  
    71 69     strcpy(homepath, Py_GetPrefix());  
    72 70     strcat(homepath, "/");  
    73       VS(homepath);  
    74       VS(" is homepath\n");  
      71     VS("homepath is %s\n", homepath);  
    75 72  
    76 73     if (init(homepath, &thisfile[strlen(homepath)], workpath)) {  
     
    79 76         strcat(archivefile, ".pkg");  
    80 77         if (init(homepath, &archivefile[strlen(homepath)], workpath)) {  
    81               FATALERROR("Cannot open self ");  
    82               FATALERROR(thisfile);  
    83               FATALERROR(" or archive ");  
    84               FATALERROR(archivefile);  
    85               FATALERROR("\n");  
      78             FATALERROR("Cannot open self %s or archive %s\n",  
      79                     thisfile, archivefile);  
    86 80             return -1;  
    87 81         }  
     
    125 119             }  
    126 120             putenv(ldlib_envvar);  
    127               VS(ldlib_envvar);  
    128               VS("\n");  
      121             VS("%s\n", ldlib_envvar);  
    129 122             rc = execvp(thisfile, argv);  
    130 123             VS("Back to parent...\n");  
  • trunk/source/common/launch.c

    r329 r330  
    261 261         f_fp = fopen(f_archivename, "rb");  
    262 262         if (f_fp == NULL) {  
    263                   VS("Cannot open archive: ");  
    264                   VS(f_archivename);  
    265                   VS("\n");  
      263                 VS("Cannot open archive: %s\n", f_archivename);  
    266 264                 return -1;  
    267 265         }  
     
    272 270         if (fseek(f_fp, -(int)sizeof(COOKIE), SEEK_END))  
    273 271         {  
    274                   VS(f_archivename);  
    275                   VS(" appears to be an invalid archive\n");  
      272                 VS("%s appears to be an invalid archive\n", f_archivename);  
    276 273                 return -1;  
    277 274         }  
     
    281 278         if (strncmp(f_cookie.magic, MAGIC, strlen(MAGIC)))  
    282 279         {  
    283                   VS(f_archivename);  
    284                   VS(" has bad magic!\n");  
      280                 VS("%s has bad magic!\n", f_archivename);  
    285 281                 return -1;  
    286 282         }  
     
    375 371         dll = LoadLibraryEx(dllpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);   
    376 372         if (dll) {  
    377                   VS(dllpath);  
    378                   VS("\n");  
      373                 VS("%s\n", dllpath);  
    379 374         }  
    380 375         else {  
     
    382 377                 dll = LoadLibraryEx(dllpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH );  
    383 378                 if (dll) {  
    384                           VS(dllpath);  
    385                           VS("\n");  
      379                         VS("%s\n", dllpath);  
    386 380                 }  
    387 381         }  
    388 382         if (dll == 0) {  
    389                   FATALERROR("Error loading Python DLL: ");  
    390                   FATALERROR(dllpath);  
    391                   FATALERROR("\n");  
      383                 FATALERROR("Error loading Python DLL: %s (error code %d)\n",  
      384                         dllpath, GetLastError());  
    392 385                 return -1;  
    393 386         }  
     
    461 454         while (ptoc < f_tocend) {  
    462 455                 if (ptoc->typcd == 'o') {  
    463                           VS(ptoc->name);  
    464                           VS("\n");  
      456                         VS("%s\n", ptoc->name);  
    465 457                         switch (ptoc->name[0]) {  
    466 458                         case 'v':  
     
    557 549  
    558 550         putenv(pypath);  
    559           VS(pypath);  
    560           VS("\n");  
      551         VS("%s\n", pypath);  
    561 552         /* Clear out PYTHONHOME to avoid clashing with any installation */  
    562 553 #ifdef WIN32  
     
    654 645                                 ntohl(ptoc->ulen) - 8);  
    655 646              
    656                           VS(ptoc->name);  
    657                           VS("\n");  
      647                         VS("%s\n", ptoc->name);  
    658 648                          
    659 649                         co = PyObject_CallFunction(loadfunc, "O", mods);  
     
    662 652                         /* Check for errors in loading */  
    663 653                         if (mod == NULL) {  
    664                                   FATALERROR("mod is NULL - ");  
    665                                   FATALERROR(ptoc->name);  
      654                                 FATALERROR("mod is NULL - %s", ptoc->name);  
    666 655                         }  
    667 656                         if (PyErr_Occurred())  
     
    695 684         if (rc != 0)  
    696 685         {  
    697                   FATALERROR("Error in command.");  
    698                   FATALERROR(cmd);  
      686                 FATALERROR("Error in command: %s\n", cmd);  
    699 687                 free(cmd);  
    700 688                 return -1;  
     
    720 708                 if (ptoc->typcd == 'z')  
    721 709                 {  
    722                           VS(ptoc->name);  
    723                           VS("\n");  
      710                         VS("%s\n", ptoc->name);  
    724 711                         installZlib(ptoc);  
    725 712                 }  
     
    740 727         z_stream zstream;  
    741 728         int rc;  
    742           char msg[400];  
    743 729  
    744 730         ver = (zlibVersion)();  
     
    763 749                 }  
    764 750                 else {  
    765                           sprintf(msg, "Error %d from inflate: %s\n", rc, zstream.msg);  
    766                           OTHERERROR(msg);  
      751                         OTHERERROR("Error %d from inflate: %s\n", rc,  
      752                                         zstream.msg);  
    767 753                         return NULL;  
    768 754                 }  
    769 755         }  
    770 756         else {  
    771                   sprintf(msg, "Error %d from inflateInit: %s\n", rc, zstream.msg);  
    772                   OTHERERROR(msg);  
      757                 OTHERERROR("Error %d from inflateInit: %s\n", rc, zstream.msg);  
    773 758                 return NULL;  
    774 759         }         
      760  
    775 761         return out;  
    776 762 }  
     
    784 770         unsigned char *data;  
    785 771         unsigned char *tmp;  
    786           char msg[400];  
    787 772  
    788           sprintf( msg, " extracting %1.20s (%d, %c)\n", ptoc->name, ptoc->cflag, ptoc->typcd);  
    789           /*VS(msg);*/  
    790 773         fseek(f_fp, f_pkgstart + ntohl(ptoc->pos), SEEK_SET);  
    791 774         data = (unsigned char *)malloc(ntohl(ptoc->len));  
     
    801 784                 data = tmp;  
    802 785                 if (data == NULL) {  
    803                           sprintf(msg, "Error decompressing %s\n", ptoc->name);  
    804                           OTHERERROR(msg);  
      786                         OTHERERROR("Error decompressing %s\n", ptoc->name);  
    805 787                         return NULL;  
    806 788                 }  
     
    823 805         strcat(fnm, name);  
    824 806         if (stat(fnm, &sbuf) == -1) {  
    825                   VS(fnm);  
    826                   VS("\n");  
      807                 VS("%s\n", fnm);  
    827 808                 return fopen(fnm, "wb");  
    828 809         }  
     
    855 836  
    856 837         if (out == NULL)  {  
    857                   FATALERROR(ptoc->name);  
    858                   FATALERROR(" could not be extracted!\n");  
      838                 FATALERROR("%s could not be extracted!\n", ptoc->name);  
    859 839         }  
    860 840         else {  
     
    894 874         int rc = 0;  
    895 875         TOC * ptoc = f_tocbuff;  
    896           char msg[400];  
    897 876         VS("Running scripts\n");  
    898 877  
     
    906 885                         /* log errors and abort */  
    907 886                         if (rc != 0) {  
    908                                   sprintf(msg, " RC: %d from %s\n", rc, ptoc->name);  
    909                                   VS(msg);  
      887                                 VS("RC: %d from %s\n", rc, ptoc->name);  
    910 888                                 return rc;  
    911 889                         }  
  • trunk/source/windows/dllmain.c

    r43 r330  
    150 150 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)  
    151 151 {  
    152           char msg[40];  
    153    
    154 152         if ( dwReason == DLL_PROCESS_ATTACH) {  
    155                   sprintf(msg, "Attach from thread %x", GetCurrentThreadId());  
    156                   VS(msg);  
      153                 VS("Attach from thread %x", GetCurrentThreadId());  
    157 154                 gInstance = hInstance;  
    158 155         }  
     
    220 217 HRESULT __stdcall DllCanUnloadNow(void)  
    221 218 {  
    222           char msg[80];  
    223 219         HRESULT rc;  
    224 220  
    225           sprintf(msg, "DllCanUnloadNow from thread %x", GetCurrentThreadId());  
    226           VS(msg);  
      221         VS("DllCanUnloadNow from thread %x", GetCurrentThreadId());  
    227 222         if (gPythoncom == 0)  
    228 223                 startUp();  
    229 224         rc = Pyc_DllCanUnloadNow();  
    230           sprintf(msg, "DllCanUnloadNow returns %x", rc);  
    231           VS(msg);  
      225         VS("DllCanUnloadNow returns %x", rc);  
    232 226         //if (rc == S_OK)  
    233 227         //      PyCom_CoUninitialize();  
     
    238 232 HRESULT __stdcall DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)  
    239 233 {  
    240           char msg[80];  
    241 234         HRESULT rc;  
    242           sprintf(msg, "DllGetClassObject from thread %x", GetCurrentThreadId());  
    243           VS(msg);  
      235  
      236         VS("DllGetClassObject from thread %x", GetCurrentThreadId());  
    244 237         if (gPythoncom == 0)  
    245 238                 startUp();  
    246 239         rc = Pyc_DllGetClassObject(rclsid, riid, ppv);  
    247           sprintf(msg, "DllGetClassObject set %x and returned %x", *ppv, rc);  
    248           VS(msg);  
      240         VS("DllGetClassObject set %x and returned %x", *ppv, rc);  
      241  
    249 242         return rc;  
    250 243 }  
     
    252 245 __declspec(dllexport) int DllRegisterServerEx(LPCSTR fileName)  
    253 246 {  
    254           char msg[40];  
    255           sprintf(msg, "DllRegisterServerEx from thread %x", GetCurrentThreadId());  
    256           VS(msg);  
      247         VS("DllRegisterServerEx from thread %x", GetCurrentThreadId());  
    257 248         if (gPythoncom == 0)  
    258 249                 startUp();  
  • trunk/source/windows/winmain.c

    r285 r330  
    137 137         else {  
    138 138                 if (extractBinaries(&workpath)) {  
    139                           VS("Error extracting binaries");  
      139                         VS("Error extracting binaries\n");  
    139 139                         return -1;  
    140 140                 }