int main(int argc, char **argv) { int status; char* env = NULL; env = getenv("GPAW_OFFLOAD"); if (env) { errno = 0; gpaw_offload_enabled = strtol(env, NULL, 10); if (errno) { fprintf(stderr, "Wrong value for for GPAW_OFFLOAD.\nShould be either 0 or 1, but was %s\n", env); } } fprintf(stderr, "GPAW info: GPAW_OFFLOAD=%d\n", gpaw_offload_enabled); #ifdef CRAYPAT PAT_region_begin(1, "C-Initializations"); #endif #ifndef GPAW_OMP MPI_Init(&argc, &argv); #else int granted; MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &granted); if(granted != MPI_THREAD_MULTIPLE) exit(1); #endif // GPAW_OMP // Get initial timing double t0 = MPI_Wtime(); #ifdef GPAW_PERFORMANCE_REPORT gpaw_perf_init(); #endif #ifdef GPAW_MPI_MAP int tag = 99; int myid, numprocs, i, procnamesize; char procname[MPI_MAX_PROCESSOR_NAME]; MPI_Comm_size(MPI_COMM_WORLD, &numprocs ); MPI_Comm_rank(MPI_COMM_WORLD, &myid ); MPI_Get_processor_name(procname, &procnamesize); if (myid > 0) { MPI_Send(&procnamesize, 1, MPI_INT, 0, tag, MPI_COMM_WORLD); MPI_Send(procname, procnamesize, MPI_CHAR, 0, tag, MPI_COMM_WORLD); } else { printf("MPI_COMM_SIZE is %d \n", numprocs); printf("%s \n", procname); for (i = 1; i < numprocs; ++i) { MPI_Recv(&procnamesize, 1, MPI_INT, i, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Recv(procname, procnamesize, MPI_CHAR, i, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); printf("%s \n", procname); } } #endif // GPAW_MPI_MAP #ifdef GPAW_MPI_DEBUG // Default Errhandler is MPI_ERRORS_ARE_FATAL MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN); #endif // Progname seems to be needed in some circumstances to resolve // correct default sys.path Py_SetProgramName(argv[0]); Py_Initialize(); #pragma offload target(mic) if(gpaw_offload_enabled) { init_openmp(); } if (PyType_Ready(&MPIType) < 0) return -1; if (PyType_Ready(&LFCType) < 0) return -1; if (PyType_Ready(&LocalizedFunctionsType) < 0) return -1; if (PyType_Ready(&OperatorType) < 0) return -1; if (PyType_Ready(&SplineType) < 0) return -1; if (PyType_Ready(&TransformerType) < 0) return -1; if (PyType_Ready(&XCFunctionalType) < 0) return -1; if (PyType_Ready(&lxcXCFunctionalType) < 0) return -1; PyObject* m = Py_InitModule3("_gpaw", functions, "C-extension for GPAW\n\n...\n"); if (m == NULL) return -1; Py_INCREF(&MPIType); PyModule_AddObject(m, "Communicator", (PyObject *)&MPIType); // Add initial time to _gpaw object PyModule_AddObject(m, "time0", PyFloat_FromDouble(t0)); Py_INCREF(&LFCType); Py_INCREF(&LocalizedFunctionsType); Py_INCREF(&OperatorType); Py_INCREF(&SplineType); Py_INCREF(&TransformerType); Py_INCREF(&XCFunctionalType); Py_INCREF(&lxcXCFunctionalType); #ifdef GPAW_WITH_HDF5 init_gpaw_hdf5(); #endif import_array1(-1); MPI_Barrier(MPI_COMM_WORLD); #ifdef CRAYPAT PAT_region_end(1); PAT_region_begin(2, "all other"); #endif status = Py_Main(argc, argv); #ifdef CRAYPAT PAT_region_end(2); #endif #ifdef GPAW_PERFORMANCE_REPORT gpaw_perf_finalize(); #endif MPI_Finalize(); return status; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { #define BUF_SIZE 1024 char buf[BUF_SIZE]; char *argv[2] = { "Reinteract.exe", "Reinteract.pyw" }; char *dirend; int count = GetModuleFileNameA(NULL, buf, BUF_SIZE); if (count == 0 || count == BUF_SIZE) fail(); /* This will fail in some exotic cases like C:Reinteract.exe */ dirend = buf + count; while (dirend > buf && *(dirend - 1) != '/' && *(dirend - 1) != '\\') dirend--; /* Change to the the EXE directory so that we find our DLL's despite Python * using LOAD_WITH_ALTERED_SEARCH_PATH. Modifying %PATH% would be another * option. Doing it this way also simplifies passing in Reinteract.pyw * as the first argument. */ if (dirend > buf) { *dirend = '\0'; SetCurrentDirectory(buf); } return Py_Main(2, argv); }
int main(int argc, char** argv) { std::cout << "Greetings. Type from example import *; test()" << std::endl; Py_Initialize(); initexample(); return Py_Main(argc, argv); }
void exec_interactive_interpreter(int argc, char** argv) { Py_Initialize(); Py_Main(argc, argv); // PyRun_SimpleString("print \"whattup\""); Py_Finalize(); }
void python_prompt() { char prgname[] = "python"; char * argv[1] = { prgname }; Py_Main(1, &argv[0]); }
int nacl_main(int argc, char **argv) { if (nacl_startup_untar(argv[0], DATA_FILE, "/")) return -1; wchar_t **argv_copy; /* We need a second copy, as Python might modify the first one. */ wchar_t **argv_copy2; int i, res; char *oldloc; #ifdef __FreeBSD__ fp_except_t m; #endif argv_copy = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1)); argv_copy2 = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1)); if (!argv_copy || !argv_copy2) { fprintf(stderr, "out of memory\n"); return 1; } /* 754 requires that FP exceptions run in "no stop" mode by default, * and until C vendors implement C99's ways to control FP exceptions, * Python requires non-stop mode. Alas, some platforms enable FP * exceptions by default. Here we disable them. */ #ifdef __FreeBSD__ m = fpgetmask(); fpsetmask(m & ~FP_X_OFL); #endif oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL)); if (!oldloc) { fprintf(stderr, "out of memory\n"); return 1; } setlocale(LC_ALL, ""); for (i = 0; i < argc; i++) { argv_copy[i] = _Py_char2wchar(argv[i], NULL); if (!argv_copy[i]) { PyMem_RawFree(oldloc); fprintf(stderr, "Fatal Python error: " "unable to decode the command line argument #%i\n", i + 1); return 1; } argv_copy2[i] = argv_copy[i]; } argv_copy2[argc] = argv_copy[argc] = NULL; setlocale(LC_ALL, oldloc); PyMem_RawFree(oldloc); res = Py_Main(argc, argv_copy); for (i = 0; i < argc; i++) { PyMem_RawFree(argv_copy2[i]); } PyMem_RawFree(argv_copy); PyMem_RawFree(argv_copy2); return res; }
//============================================================================== int py_main() { #ifdef USE_PYTHON Py_Main(0, 0); #endif return ERROR_NONE; }
int main(int argc, char **argv) { #ifdef __APPLE__ QPythonApp app(argc, argv); VCSSecondaryThread mythread(argc, argv); mythread.start(); return app.exec(); #else return Py_Main(argc, argv); #endif }
int main(int argc, char **argv) { PyNet_Args *pn_args; pn_args = PyNet_Init(0); if (pn_args->error) { exit(1); } int rc = Py_Main(argc, argv); PyNet_Finalize(pn_args); exit(rc); }
void common_funcs() { PyObject *tuple, *list; tuple = Py_BuildValue("(iis)", 1, 2, "three"); list = Py_BuildValue("[iis]", 1, 2, "three"); Py_Main(0, NULL); // Py_TTA }
static int test_initialize_pymain(void) { wchar_t *argv[] = {L"PYTHON", L"-c", L"import sys; print(f'Py_Main() after Py_Initialize: sys.argv={sys.argv}')", L"arg2"}; _testembed_Py_Initialize(); /* bpo-34008: Calling Py_Main() after Py_Initialize() must not crash */ Py_Main(Py_ARRAY_LENGTH(argv), argv); Py_Finalize(); return 0; }
extern "C" int pydroid_main(int argc,char *argv[]) { printf("+++++++++++argc %d \n",argc); Py_InitializeEx(0); PyEval_InitThreads(); initPyDroid(); initandroidlog(); android::ProcessState::self()->startThreadPool(); /* PyRun_SimpleString( "import sys, posix\n" \ "import androidlog\n" \ "class LogFile(object):\n" \ " def __init__(self):\n" \ " self.buffer = ''\n" \ " def write(self, s):\n" \ " s = self.buffer + s\n" \ " lines = s.split(\"\\n\")\n" \ " for l in lines[:-1]:\n" \ " pylog.i(l)\n" \ " self.buffer = lines[-1]\n" \ " def flush(self):\n" \ " return\n" \ "sys.stdout = sys.stderr = LogFile()\n"); */ if(argc <= 1) { return PyRun_SimpleString( "import main\n" \ "main.run()\n" ); } else { return Py_Main(argc,argv); } }
int main(int argc, char **argv) { int result = 0; try { // ensure I/O system is initialized before any extensions are imported std::cout << std::flush; result = Py_Main(argc, argv); } catch (std::exception const& exc) { std::cerr << "python: C++ exception: " << exc.what() << std::endl << std::flush; return 1; } catch (...) { std::cerr << "python: unknown C++ exception" << std::endl << std::flush; return 2; } return result; }
int main(int argc, char **argv) { wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); /* We need a second copies, as Python might modify the first one. */ wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); int i, res; char *oldloc; /* 754 requires that FP exceptions run in "no stop" mode by default, * and until C vendors implement C99's ways to control FP exceptions, * Python requires non-stop mode. Alas, some platforms enable FP * exceptions by default. Here we disable them. */ #ifdef __FreeBSD__ fp_except_t m; m = fpgetmask(); fpsetmask(m & ~FP_X_OFL); #endif if (!argv_copy || !argv_copy2) { fprintf(stderr, "out of memory\n"); return 1; } oldloc = strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, ""); for (i = 0; i < argc; i++) { argv_copy2[i] = argv_copy[i] = char2wchar(argv[i]); if (!argv_copy[i]) return 1; } setlocale(LC_ALL, oldloc); free(oldloc); res = Py_Main(argc, argv_copy); for (i = 0; i < argc; i++) { PyMem_Free(argv_copy2[i]); } PyMem_Free(argv_copy); PyMem_Free(argv_copy2); return res; }
void PythonThread(void *argl) { HAB hab; arglist *args; /* PM initialisation */ hab = WinInitialize(0); /* start Python */ args = (arglist *)argl; args->running = 1; PythonRC = Py_Main(args->argc, args->argv); /* enter a critical section and send the termination message */ DosEnterCritSec(); args->running = 0; WinPostMsg(args->Frame, WM_QUIT, NULL, NULL); /* shutdown PM and terminate thread */ WinTerminate(hab); _endthread(); }
void python_interpreter::mainloop() { // now start the interpreter main loop and start executing the commands given to the new interpreter... Py_Main(argc_,argv_); }
int //wmain(int argc, wchar_t **argv) wmain(int argc, wchar_t *argv[]) { return Py_Main(argc, argv); }
int wmain(int argc, wchar_t **argv) { return Py_Main(argc, argv); }
int main(int argc, char* argv[]) { return Py_Main( argc, argv ); }
K py(K f, K x, K lib) { int argc; char **argv; char *error, *p, *buf; void *h; K r; #ifdef PY3K char *oldloc; #endif h = dlopen((const char *)kG(lib), RTLD_NOW|RTLD_GLOBAL); if (!h) R krr(dlerror()); dlerror(); /* Clear any existing error */ Py_Main = dlsym(h, "Py_Main"); P((error = dlerror()),krr(error)); P(xt, krr("argv type")); I m = 0; /* buf length */ DO(xn, K y; P((y = kK(x)[i])->t!=KC, krr("arg type")); m += y->n+1); argc = xn+1; argv = malloc(sizeof(char*) * argc); P(!argv, krr("memory")); buf = malloc(m); P(!buf,(free(argv),krr("memory"))); argv[0] = f->s; p = buf; DO(xn, K y = kK(x)[i]; argv[i+1] = memcpy(p, kG(y), y->n); p += y->n; *p++ = '\0'); #ifdef PY3K dlerror(); /* Clear any existing error */ #if PY3K < 35 c2w = dlsym(h, "_Py_char2wchar"); #else c2w = dlsym(h, "Py_DecodeLocale"); #endif P((error = dlerror()),krr(error)); dlerror(); /* Clear any existing error */ #if PY3K < 34 PyMem_Free = dlsym(h, "PyMem_Free"); #else PyMem_Free = dlsym(h, "PyMem_RawFree"); #endif P((error = dlerror()),krr(error)); wchar_t **wargv = malloc(sizeof(wchar_t*)*(argc+1)); wchar_t **wargv_copy = malloc(sizeof(wchar_t*)*(argc+1)); oldloc = strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, ""); DO(argc,P(!(wargv[i]=c2w(argv[i],NULL)),krr("decode"))); memcpy(wargv_copy, wargv, sizeof(wchar_t*)*argc); setlocale(LC_ALL, oldloc); free(oldloc); wargv[argc] = wargv_copy[argc] = NULL; r = ki(Py_Main(argc, wargv)); DO(argc,PyMem_Free(wargv_copy[i])); free(wargv_copy); free(wargv); #else r = ki(Py_Main(argc, argv)); #endif dlclose(h); free(argv); free(buf); R r; }
ForceInline int main2(LONG_PTR argc, PWSTR *argv) { AppendPackage(); return Py_Main(argc, argv); }
void exec_interactive_interpreter(int argc, char** argv) { Py_Initialize(); Py_Main(argc, argv); Py_Finalize(); }