1 /* 2 * **************************************************************************** 3 * Copyright (c) 2013-2019, PyInstaller Development Team. 4 * Distributed under the terms of the GNU General Public License with exception 5 * for distributing bootloader. 6 * 7 * The full license is in the file COPYING.txt, distributed with this software. 8 * **************************************************************************** 9 */ 10 11 /* 12 * Global shared declarations used in many bootloader files. 13 */ 14 15 #ifndef PYI_GLOBAL_H 16 #define PYI_GLOBAL_H 17 18 /* 19 * Detect memory leaks. 20 * 21 * Use Boehm garbage collector to detect memory leaks. 22 * malloc(), free(), strdup() and similar functions 23 * are replaced by calls from the gc library. 24 */ 25 #ifdef PYI_LEAK_DETECTOR 26 #include <gc/leak_detector.h> 27 #endif 28 29 /* 30 * Definition of type boolean. On OSX boolean type is available 31 * in header <stdbool.h>. 32 */ 33 #ifdef __APPLE__ 34 #include <stdbool.h> /* bool, true, false */ 35 #else 36 /* 37 * It looks like more recent versions of MSVC complains about 'typedef int bool'. 38 * They probably have the type 'bool' defined. 39 * TODO find out more info. 40 */ 41 #undef bool 42 #undef true 43 #undef false 44 typedef int bool; 45 #define true 1 46 #define false 0 47 #endif 48 49 /* Type for dynamic library. */ 50 #ifdef _WIN32 51 #define dylib_t HINSTANCE 52 #else 53 #define dylib_t void * 54 #endif 55 56 /* Wrap some windows specific declarations for Unix. */ 57 #ifndef _WIN32 58 #define HMODULE void * 59 #endif 60 61 /* 62 * On Windows PATH_MAX does not exist but MAX_PATH does. 63 * WinAPI MAX_PATH limit is only 256. MSVCR fuctions does not have this limit. 64 * Redefine PATH_MAX for Windows to support longer path names. 65 */ 66 /* TODO use MSVCR function for file path handling. */ 67 #ifdef _WIN32 68 #ifdef PATH_MAX 69 #undef PATH_MAX /* On Windows override PATH_MAX if defined. */ 70 #endif 71 #define PATH_MAX 4096 /* Default value on Linux. */ 72 #elif __APPLE__ 73 #define PATH_MAX 1024 /* Recommended value for OSX. */ 74 #endif 75 76 /* 77 * Debug and error macros. 78 */ 79 80 void pyi_global_printf(const char *fmt, ...); 81 void pyi_global_perror(const char *funcname, const char *fmt, ...); 82 #ifdef _WIN32 83 void pyi_global_winerror(const char *funcname, const char *fmt, ...); 84 #endif 85 /* 86 * On Windows and with windowed mode (no console) show error messages 87 * in message boxes. In windowed mode nothing might be written to console. 88 */ 89 90 #if defined(_WIN32) && defined(WINDOWED) 91 void mbfatalerror(const char *fmt, ...); 92 #define FATALERROR mbfatalerror 93 94 void mbothererror(const char *fmt, ...); 95 #define OTHERERROR mbothererror 96 97 void mbfatal_perror(const char *funcname, const char *fmt, ...); 98 #define FATAL_PERROR mbfatal_perror 99 100 void mbfatal_winerror(const char *funcname, const char *fmt, ...); 101 #define FATAL_WINERROR mbfatal_winerror 102 103 #else 104 /* TODO copy over stbprint to bootloader. */ 105 #define FATALERROR pyi_global_printf 106 #define OTHERERROR pyi_global_printf 107 #define FATAL_PERROR pyi_global_perror 108 #define FATAL_WINERROR pyi_global_winerror 109 #endif /* WIN32 and WINDOWED */ 110 111 /* Enable or disable debug output. */ 112 113 #ifdef LAUNCH_DEBUG 114 #if defined(_WIN32) && defined(WINDOWED) 115 #define VS mbvs 116 void mbvs(const char *fmt, ...); 117 #else 118 #define VS pyi_global_printf 119 #endif 120 #else 121 #ifdef _WIN32 122 #define VS 123 #else 124 #define VS(...) 125 #endif 126 #endif 127 128 /* Path and string macros. */ 129 130 #ifdef _WIN32 131 #define PYI_PATHSEP ';' 132 #define PYI_CURDIR '.' 133 #define PYI_SEP '\\' 134 /* 135 * For some functions like strcat() we need to pass 136 * string and not only char. 137 */ 138 #define PYI_SEPSTR "\\" 139 #define PYI_PATHSEPSTR ";" 140 #else 141 #define PYI_PATHSEP ':' 142 #define PYI_CURDIR '.' 143 #define PYI_SEP '/' 144 #define PYI_SEPSTR "/" 145 #define PYI_PATHSEPSTR ":" 146 #endif 147 148 /* Strings are usually terminated by this character. */ 149 #define PYI_NULLCHAR '\0' 150 151 /* Rewrite ANSI/POSIX functions to Win32 equivalents. */ 152 #if defined(_WIN32) && defined(_MSC_VER) 153 #define getpid _getpid 154 #define mkdir _mkdir 155 #define rmdir _rmdir 156 #define snprintf _snprintf 157 #define stat _stat 158 #define strdup _strdup 159 #define vsnprintf _vsnprintf 160 /* 161 * Mingw on Windows contains the following functions. 162 * Redefine them only if they are not available. 163 */ 164 #ifndef fileno 165 #define fileno _fileno 166 #endif 167 #endif 168 169 /* Saved LC_CTYPE locale */ 170 extern char *saved_locale; 171 172 #endif /* PYI_GLOBAL_H */ 173