#!/bin/sh PYVER=${PYVER:-3.8} echo "testing bpo-14916 for python${PYVER}" cat < test-bpo-14916.c #include #include #define PY_SSIZE_T_CLEAN #include #define MAX 1024 char buf[MAX]; #define TEST_CODE "file_io" int main(int argc, char *argv[]) { wchar_t *program = Py_DecodeLocale(argv[0], NULL); if (program == NULL) { fprintf(stderr, "Fatal error: cannot decode argv[0]\n"); exit(1); } Py_SetProgramName(program); /* optional but recommended */ Py_Initialize(); FILE *one_file = fopen(TEST_CODE,"w+"); setenv("BPO14916","FOUND!",1); fputs("__import__('os').environ['BPO14916']='not present'\n", one_file); fflush(one_file); fclose(one_file); one_file = fopen(TEST_CODE, "r"); int line = 0; if (one_file) { while( fgets(&buf[0], MAX, one_file) ) { fprintf( stderr, "%d: %s",++line, buf ); } rewind(one_file); int res = PyRun_InteractiveOne( one_file, TEST_CODE); fclose(one_file); } else { fprintf( stderr, "IO error\n"); } printf("\nStatus of bug 14916 : %s\n\n", getenv("BPO14916") ); if (Py_FinalizeEx() < 0) { exit(120); } PyMem_RawFree(program); return 0; } END gcc -o test-bpo-14916 test-bpo-14916.c -I/usr/local/include/python${PYVER} -L/usr/local/lib -lpython${PYVER} -lpthread -ldl -lm -lutil echo i_should_not_be_parsed | ./test-bpo-14916