@@ -192,7 +192,7 @@ typedef struct python_info {
192
192
HANDLE dll_hnd ;
193
193
194
194
/** The index of this Python in the `py_programs` smartlist.
195
- * I.e. in the cache-file "python_in_pathX = ...", `py_index == X`.
195
+ * I.e. in the cache-file "python_in_pathX = ...", `py_index == X`.
196
196
*/
197
197
int py_index ;
198
198
@@ -241,7 +241,6 @@ static int longest_py_version = 0; /** set in py_init() */
241
241
static int global_indent = 0 ;
242
242
static int warn_on_py_fail = 1 ;
243
243
244
-
245
244
/**
246
245
* Variables used in the generic callback helper function popen_append_out().
247
246
*/
@@ -253,10 +252,6 @@ static bool popen_py_crash = false;
253
252
static int get_python_version (const char * exe_name );
254
253
static bool py_add_module (struct python_info * pi , const struct python_module * m );
255
254
256
- #if defined(__GNUC__ ) && (__GNUC__ >= 7 )
257
- #pragma GCC diagnostic ignored "-Wformat-truncation"
258
- #endif
259
-
260
255
/**
261
256
* The list of Pythons from the `"%PATH"` and from the
262
257
* `"HKLM\Software\Python\PythonCore\xx\InstallPath"` locations.
@@ -271,22 +266,22 @@ static smartlist_t *py_programs;
271
266
* \param is_opt `== true` if the function is optional.
272
267
* \param f the name of the function (without any `"`).
273
268
*/
274
- #define LOAD_FUNC (pi , is_opt , f ) do { \
275
- f = GETPROCADDRESS (func_##f, pi->dll_hnd, #f); \
276
- if (!f && !is_opt) { \
277
- WARN ("Failed to find \"%s()\" in %s.\n", \
278
- #f, pi->dll_name); \
279
- goto failed; \
280
- } \
281
- TRACE (3, "Function %s(): %*s 0x%p.\n", \
282
- #f, 23-(int)strlen(#f), "", f); \
269
+ #define LOAD_FUNC (pi , is_opt , f ) do { \
270
+ f = GETPROCADDRESS (func_##f, pi->dll_hnd, #f); \
271
+ if (!f && !is_opt) { \
272
+ WARN ("Failed to find \"%s()\" in %s.\n", \
273
+ #f, pi->dll_name); \
274
+ goto failed; \
275
+ } \
276
+ TRACE (3, "Function %s(): %*s 0x%p.\n", \
277
+ #f, 23-(int)strlen(#f), "", f); \
283
278
} while (0)
284
279
285
280
/**
286
281
* \def LOAD_INT_PTR(pi, ptr)
287
282
* A `GetProcAddress()` helper for setting an int-pointer.
288
283
* \param pi the `struct python_info` to work on.
289
- * \param ptr the name of the variable (without any `"`) .
284
+ * \param ptr the int-pointer (and name) to import .
290
285
*/
291
286
#define LOAD_INT_PTR (pi , ptr ) do { \
292
287
ptr = GETPROCADDRESS (int*, pi->dll_hnd, #ptr); \
@@ -1127,7 +1122,7 @@ static char *call_python_func (struct python_info *pi, const char *prog, unsigne
1127
1122
1128
1123
/**
1129
1124
* As above, but with the Python code given as a NULL-terminated array.
1130
- * Each element should be EOL-terminated (`"\n"`) .
1125
+ * Each element should NOT have newlines. These are done here .
1131
1126
*/
1132
1127
static char * call_python_array (struct python_info * pi , const char * * array , unsigned line )
1133
1128
{
@@ -1136,13 +1131,17 @@ static char *call_python_array (struct python_info *pi, const char **array, unsi
1136
1131
size_t i = 0 , size = 1 ;
1137
1132
1138
1133
for (a = array [0 ]; a ; a = array [++ i ])
1139
- size += strlen (a );
1134
+ {
1135
+ size += strlen (a ) + 1 ;
1136
+ ASSERT (strchr (a , '\n' ) == NULL );
1137
+ }
1140
1138
1141
1139
prog = p = alloca (size );
1142
1140
for (a = array [0 ]; a ; a = array [++ i ])
1143
1141
{
1144
1142
strcpy (p , a );
1145
1143
p += strlen (a );
1144
+ * p ++ = '\n' ;
1146
1145
}
1147
1146
return call_python_func (pi , prog , line );
1148
1147
}
@@ -1201,13 +1200,6 @@ static char *fcheck_open_mem (struct python_module *m, const char *file, size_t
1201
1200
1202
1201
snprintf (fqfn , sizeof (fqfn ), "%s%c%s" , pkg_dir , DIR_SEP , file );
1203
1202
FREE (pkg_dir );
1204
-
1205
- /* Hack to avoid this stupid 'gcc 12+ warning':
1206
- * envtool_py.c:1142:13: warning: dangling pointer 'file' to 'fqfn' may be used [-Wdangling-pointer=]
1207
- * 1142 | return fopen_mem (file, f_size);
1208
- * | ^~~~~~~~~~~~~~~~~~~~~~~~
1209
- *
1210
- */
1211
1203
file = strdupa (fqfn );
1212
1204
}
1213
1205
else
@@ -1255,7 +1247,7 @@ static void py_get_meta_details (struct python_module *m)
1255
1247
if (p && q > p )
1256
1248
{
1257
1249
email = m -> author_email ;
1258
- m -> author_email = str_ndup (p + 1 , q - p );
1250
+ m -> author_email = str_ndup (p + 1 , q - p );
1259
1251
FREE (email );
1260
1252
}
1261
1253
if (m -> author && p )
@@ -1317,10 +1309,10 @@ static void py_get_meta_details (struct python_module *m)
1317
1309
*/
1318
1310
static bool test_python_funcs (struct python_info * pi , bool reinit )
1319
1311
{
1320
- static const char * prog [] = { "import sys\n " ,
1321
- "print (sys.version_info)\n " ,
1322
- "for i in range(3):\n " ,
1323
- " print (\" Hello world\")\n " ,
1312
+ static const char * prog [] = { "import sys" ,
1313
+ "print (sys.version_info)" ,
1314
+ "for i in range(3):" ,
1315
+ " print (\" Hello world\")" ,
1324
1316
NULL
1325
1317
};
1326
1318
const char * name = py_variant_name (pi -> variant );
@@ -1570,7 +1562,7 @@ static int py_print_modinfo (const char *spec, bool get_details)
1570
1562
}
1571
1563
}
1572
1564
1573
- if (match_all /* && !get_details */ )
1565
+ if (match_all && !get_details )
1574
1566
C_printf ("~6Found %d modules~0 (%d are ZIP/EGG files).\n" , found , zips_found );
1575
1567
return (found );
1576
1568
}
@@ -1621,73 +1613,73 @@ static int py_print_modinfo (const char *spec, bool get_details)
1621
1613
* modules and packages at runtime.
1622
1614
*/
1623
1615
static const char * py_list_modules2 [] = {
1624
- "from __future__ import print_function\n " ,
1625
- "import os, sys, pip, imp\n " ,
1626
- "\n " ,
1627
- "types = { imp.PY_SOURCE: 'source file', # = 1\n " ,
1628
- " imp.PY_COMPILED: 'object file',\n " ,
1629
- " imp.C_EXTENSION: 'shared library', # = 3\n " ,
1630
- " imp.PKG_DIRECTORY: 'package directory',\n " ,
1631
- " imp.C_BUILTIN: 'built-in module', # = 6\n " ,
1632
- " imp.PY_FROZEN: 'frozen module'\n " ,
1633
- " }\n " ,
1634
- "mod_paths = {}\n " ,
1635
- "mod_builtins = {}\n " ,
1636
- "prev_pathname = ''\n " ,
1637
- "prev_modtype = None\n " ,
1638
- "\n " ,
1639
- "def get_module_path (mod, mod_type, mod_path):\n " ,
1640
- " next_scope = mod.index ('.') + 1\n " ,
1641
- " last_scope = mod.rindex ('.') + 1\n " ,
1642
- "\n " ,
1643
- " fname = mod_path + '\\\\' + mod[next_scope:].replace('.','\\\\\') + '.py'\n " ,
1644
- " if os.path.exists(fname):\n " ,
1645
- " return fname\n " ,
1646
- "\n " ,
1647
- " init = mod_path + '\\\\' + mod[last_scope:] + '\\\\__init__.py'\n " ,
1648
- " if os.path.exists(init):\n " ,
1649
- " return init\n " ,
1650
- "\n " ,
1651
- " try:\n " ,
1652
- " if mod_builtins[mod[last_scope:]] == 1:\n " ,
1653
- " return '__builtin__ ' + mod[last_scope:]\n " ,
1654
- " except KeyError:\n " ,
1655
- " pass\n " ,
1656
- "\n " ,
1657
- " try:\n " ,
1658
- " return mod_paths [mod[last_scope:]] + ' !'\n " ,
1659
- " except KeyError:\n " ,
1660
- " pass\n " ,
1661
- "\n " ,
1662
- " try:\n " ,
1663
- " _x, pathname, _y = imp.find_module (mod, mod_path)\n " ,
1664
- " return pathname\n " ,
1665
- " except ImportError:\n " ,
1666
- " return '<unknown>'\n " ,
1667
- " except RuntimeError:\n " ,
1668
- " mod_builtins [mod] = 1\n " ,
1669
- " return '__builtin__ ' + mod[last_scope:]\n " ,
1670
- "\n " ,
1671
- "for s in sorted(sys.modules):\n " ,
1672
- " print ('%s' % s, end='')\n " ,
1673
- " if '.' in s:\n " ,
1674
- " print (',%s' % get_module_path(s,prev_modtype,prev_pathname))\n " ,
1675
- " continue\n " ,
1676
- "\n " ,
1677
- " try:\n " ,
1678
- " _, pathname, descr = imp.find_module (s)\n " ,
1679
- " t = types [descr[2]]\n " ,
1680
- " prev_modtype = t\n " ,
1681
- " print (',%s,' % t, end='')\n " ,
1682
- " if pathname and '\\\\' in pathname:\n " ,
1683
- " print ('%s' % pathname)\n " ,
1684
- " prev_pathname = pathname\n " ,
1685
- " prev_modtype = t\n " ,
1686
- " mod_paths [s] = pathname\n " ,
1687
- " else:\n " ,
1688
- " mod_builtins [s] = 1\n " ,
1689
- " except ImportError:\n " ,
1690
- " print (',<unknown>')\n " ,
1616
+ "from __future__ import print_function" ,
1617
+ "import os, sys, pip, imp" ,
1618
+ "" ,
1619
+ "types = { imp.PY_SOURCE: 'source file', # = 1" ,
1620
+ " imp.PY_COMPILED: 'object file'," ,
1621
+ " imp.C_EXTENSION: 'shared library', # = 3" ,
1622
+ " imp.PKG_DIRECTORY: 'package directory'," ,
1623
+ " imp.C_BUILTIN: 'built-in module', # = 6" ,
1624
+ " imp.PY_FROZEN: 'frozen module'" ,
1625
+ " }" ,
1626
+ "mod_paths = {}" ,
1627
+ "mod_builtins = {}" ,
1628
+ "prev_pathname = ''" ,
1629
+ "prev_modtype = None" ,
1630
+ "" ,
1631
+ "def get_module_path (mod, mod_type, mod_path):" ,
1632
+ " next_scope = mod.index ('.') + 1" ,
1633
+ " last_scope = mod.rindex ('.') + 1" ,
1634
+ "" ,
1635
+ " fname = mod_path + '\\\\' + mod[next_scope:].replace('.','\\\\\') + '.py'" ,
1636
+ " if os.path.exists(fname):" ,
1637
+ " return fname" ,
1638
+ "" ,
1639
+ " init = mod_path + '\\\\' + mod[last_scope:] + '\\\\__init__.py'" ,
1640
+ " if os.path.exists(init):" ,
1641
+ " return init" ,
1642
+ "" ,
1643
+ " try:" ,
1644
+ " if mod_builtins[mod[last_scope:]] == 1:" ,
1645
+ " return '__builtin__ ' + mod[last_scope:]" ,
1646
+ " except KeyError:" ,
1647
+ " pass" ,
1648
+ "" ,
1649
+ " try:" ,
1650
+ " return mod_paths [mod[last_scope:]] + ' !'" ,
1651
+ " except KeyError:" ,
1652
+ " pass" ,
1653
+ "" ,
1654
+ " try:" ,
1655
+ " _x, pathname, _y = imp.find_module (mod, mod_path)" ,
1656
+ " return pathname" ,
1657
+ " except ImportError:" ,
1658
+ " return '<unknown>'" ,
1659
+ " except RuntimeError:" ,
1660
+ " mod_builtins [mod] = 1" ,
1661
+ " return '__builtin__ ' + mod[last_scope:]" ,
1662
+ "" ,
1663
+ "for s in sorted(sys.modules):" ,
1664
+ " print ('%s' % s, end='')" ,
1665
+ " if '.' in s:" ,
1666
+ " print (',%s' % get_module_path(s,prev_modtype,prev_pathname))" ,
1667
+ " continue" ,
1668
+ "" ,
1669
+ " try:" ,
1670
+ " _, pathname, descr = imp.find_module (s)" ,
1671
+ " t = types [descr[2]]" ,
1672
+ " prev_modtype = t" ,
1673
+ " print (',%s,' % t, end='')" ,
1674
+ " if pathname and '\\\\' in pathname:" ,
1675
+ " print ('%s' % pathname)" ,
1676
+ " prev_pathname = pathname" ,
1677
+ " prev_modtype = t" ,
1678
+ " mod_paths [s] = pathname" ,
1679
+ " else:" ,
1680
+ " mod_builtins [s] = 1" ,
1681
+ " except ImportError:" ,
1682
+ " print (',<unknown>')" ,
1691
1683
NULL
1692
1684
};
1693
1685
@@ -3291,7 +3283,7 @@ static char *py_exec_internal (struct python_info *pi, const char **py_argv, boo
3291
3283
const char * prog0 , * fmt = NULL ;
3292
3284
char * str , * prog ;
3293
3285
size_t size ;
3294
- arg_vector av = { 0 , NULL , NULL }; /* Fill in to shutup warnings from gcc */
3286
+ arg_vector av = { 0 , NULL , NULL };
3295
3287
3296
3288
C_printf ("Executing ~6%s~0 using ~6%s~0: " , py_argv [0 ], pi -> dll_name );
3297
3289
0 commit comments