示例#1
0
/*
 * Set Python list sys.argv from *argv/argc. (Command-line options).
 * sys.argv[0] should be full absolute path to the executable (Derived from
 * status->archivename).
 */
static int pyi_pylib_set_sys_argv(ARCHIVE_STATUS *status)
{
	char ** mbcs_argv;
 	wchar_t ** wargv;

	VS("LOADER: Setting sys.argv\n");

    /* last parameter '0' to PySys_SetArgv means do not update sys.path. */
    if (is_py2) {
#ifdef _WIN32
      /* status->argv is UTF-8, convert to ANSI without SFN */
      /* TODO: pyi-option to enable SFNs for argv? */
	  mbcs_argv = pyi_win32_argv_mbcs_from_utf8(status->argc, status->argv);
	  if(mbcs_argv) {
		  PI_Py2Sys_SetArgvEx(status->argc, mbcs_argv, 0);
		  free(mbcs_argv);
	  } else {
	  	  FATALERROR("Failed to convert argv to mbcs\n");
	  	  return -1;
	  }
#else /* _WIN32 */
      // For Python2, status->argv must be "char **". In Python 2.7's
      // `main.c`, argv is used without any other handling, so do we.
      PI_Py2Sys_SetArgvEx(status->argc, status->argv, 0);
#endif

    } else {
#ifdef _WIN32
	  /* Convert UTF-8 argv back to wargv */
	  wargv = pyi_win32_wargv_from_utf8(status->argc, status->argv);
#else
      /* Convert argv to wargv using Python's Py_DecodeLocale (formerly _Py_char2wchar) */
      wargv = pyi_wargv_from_argv(status->argc, status->argv);
#endif
      if(wargv) {
		  PI_PySys_SetArgvEx(status->argc, wargv, 0);
		  pyi_free_wargv(wargv);
	  } else {
	  	  FATALERROR("Failed to convert argv to wchar_t\n");
	  	  return -1;
	  }
    };
    return 0;
}
示例#2
0
int
PI_Py2Sys_SetArgvEx(int argc, char ** argv, int updatepath)
{
    return PI_PySys_SetArgvEx(argc, (wchar_t **) argv, updatepath);
};