Files
Python3-Win9x/scripts/fixtures/vc6_compound_literal_smoke.c
T

65 lines
2.4 KiB
C

/* Focused compile smoke test for the VC6 C99 compound-literal /
* designated-initializer fixes applied to cpython/Modules/main.c.
*
* VC6 (a pre-C99 compiler) supports neither C99 compound literals
* (`(PyStatus){...}`) nor C99 designated initializers (`{ .field = value,
* ... }`), at any position in a block. Modules/main.c relied on both via
* three distinct patterns:
*
* 1. `status = _PyStatus_OK();` -- a compound-literal macro used as a
* plain assignment's right-hand side. Fixed by calling the existing
* public API function PyStatus_Ok() instead, which
* Python/initconfig.c defines as `return _PyStatus_OK();` -- the
* identical value, no header change needed.
* 2. `cf = _PyCompilerFlags_INIT;` -- likewise a compound-literal macro
* used as a plain assignment. Fixed by assigning PyCompilerFlags's
* two fields explicitly (cf_flags, cf_feature_version), matching the
* macro's own definition field-for-field.
* 3. `_PyArgv args = { .argc = argc, ... };` -- a designated-initializer
* aggregate initializer with no macro involved. Fixed by declaring
* the variable bare and assigning each field explicitly; field order
* does not matter for plain assignment, unlike an initializer list.
*
* See PORT_STATUS.md ("Compound-literal/designated-initializer slice") for
* full detail. Like vc6_mixed_decls_smoke.c, this fixture includes the
* real "Python.h" (Py_BUILD_CORE is supplied by the probe script) because
* PyStatus, PyCompilerFlags, and _PyArgv are real CPython types pulled in
* through the normal public/internal header chain, the same way
* Modules/main.c itself reaches them.
*/
#include "Python.h"
#include "pycore_initconfig.h" // _PyArgv, _PyStatus_OK()
PyStatus
vc6_status_ok_smoke(void)
{
PyStatus status;
/* pattern 1: was `status = _PyStatus_OK();` */
status = PyStatus_Ok();
return status;
}
PyCompilerFlags
vc6_compiler_flags_smoke(void)
{
PyCompilerFlags cf;
/* pattern 2: was `cf = _PyCompilerFlags_INIT;` */
cf.cf_flags = 0;
cf.cf_feature_version = PY_MINOR_VERSION;
return cf;
}
Py_ssize_t
vc6_argv_designated_init_smoke(int argc, wchar_t **argv)
{
/* pattern 3: was `_PyArgv args = { .argc = argc, ... };` */
_PyArgv args;
args.argc = argc;
args.use_bytes_argv = 0;
args.bytes_argv = NULL;
args.wchar_argv = argv;
return args.argc;
}