开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 0

source-code-analysis/python3.8.1

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
python3.8.1
/
Mac
/
Tools
/
pythonw.c
python3.8.1
/
Mac
/
Tools
/
pythonw.c
pythonw.c 5.84 KB
一键复制 编辑 原始数据 按行查看 历史
zhangweibo 提交于 2021年11月16日 09:46 +08:00 . git init
/*
* This wrapper program executes a python executable hidden inside an
* application bundle inside the Python framework. This is needed to run
* GUI code: some GUI API's don't work unless the program is inside an
* application bundle.
*
* This program uses posix_spawn rather than plain execv because we need
* slightly more control over how the "real" interpreter is executed.
*
* On OSX 10.4 (and earlier) this falls back to using exec because the
* posix_spawnv functions aren't available there.
*/
#pragma weak_import posix_spawnattr_init
#pragma weak_import posix_spawnattr_setbinpref_np
#pragma weak_import posix_spawnattr_setflags
#pragma weak_import posix_spawn
#include <Python.h>
#include <unistd.h>
#ifdef HAVE_SPAWN_H
#include <spawn.h>
#endif
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <err.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <Python.h>
#include <mach-o/dyld.h>
extern char** environ;
/*
* Locate the python framework by looking for the
* library that contains Py_Initialize.
*
* In a regular framework the structure is:
*
* Python.framework/Versions/2.7
* /Python
* /Resources/Python.app/Contents/MacOS/Python
*
* In a virtualenv style structure the expected
* structure is:
*
* ROOT
* /bin/pythonw
* /.Python <- the dylib
* /.Resources/Python.app/Contents/MacOS/Python
*
* NOTE: virtualenv's are not an officially supported
* feature, support for that structure is provided as
* a convenience.
*/
static char* get_python_path(void)
{
size_t len;
Dl_info info;
char* end;
char* g_path;
if (dladdr(Py_Initialize, &info) == 0) {
return NULL;
}
len = strlen(info.dli_fname);
g_path = malloc(len+60);
if (g_path == NULL) {
return NULL;
}
strcpy(g_path, info.dli_fname);
end = g_path + len - 1;
while (end != g_path && *end != '/') {
end --;
}
end++;
if (*end == '.') {
end++;
}
strcpy(end, "Resources/Python.app/Contents/MacOS/" PYTHONFRAMEWORK);
return g_path;
}
#ifdef HAVE_SPAWN_H
static void
setup_spawnattr(posix_spawnattr_t* spawnattr)
{
size_t ocount;
size_t count;
cpu_type_t cpu_types[1];
short flags = 0;
#ifdef __LP64__
int ch;
#endif
if ((errno = posix_spawnattr_init(spawnattr)) != 0) {
err(2, "posix_spawnattr_int");
/* NOTREACHTED */
}
count = 1;
/* Run the real python executable using the same architecture as this
* executable, this allows users to control the architecture using
* "arch -ppc python"
*/
#if defined(__ppc64__)
cpu_types[0] = CPU_TYPE_POWERPC64;
#elif defined(__x86_64__)
cpu_types[0] = CPU_TYPE_X86_64;
#elif defined(__ppc__)
cpu_types[0] = CPU_TYPE_POWERPC;
#elif defined(__i386__)
cpu_types[0] = CPU_TYPE_X86;
#else
# error "Unknown CPU"
#endif
if (posix_spawnattr_setbinpref_np(spawnattr, count,
cpu_types, &ocount) == -1) {
err(1, "posix_spawnattr_setbinpref");
/* NOTREACHTED */
}
if (count != ocount) {
fprintf(stderr, "posix_spawnattr_setbinpref failed to copy\n");
exit(1);
/* NOTREACHTED */
}
/*
* Set flag that causes posix_spawn to behave like execv
*/
flags |= POSIX_SPAWN_SETEXEC;
if ((errno = posix_spawnattr_setflags(spawnattr, flags)) != 0) {
err(1, "posix_spawnattr_setflags");
/* NOTREACHTED */
}
}
#endif
int
main(int argc, char **argv) {
char* exec_path = get_python_path();
static char path[PATH_MAX * 2];
static char real_path[PATH_MAX * 2];
int status;
uint32_t size = PATH_MAX * 2;
/* Set the original executable path in the environment. */
status = _NSGetExecutablePath(path, &size);
if (status == 0) {
/*
* Note: don't call 'realpath', that will
* erase symlink information, and that
* breaks "pyvenv --symlink"
*
* It is nice to have the directory name
* as a cleaned up absolute path though,
* therefore call realpath on dirname(path)
*/
char* slash = strrchr(path, '/');
if (slash) {
char replaced;
replaced = slash[1];
slash[1] = 0;
if (realpath(path, real_path) == NULL) {
err(1, "realpath: %s", path);
}
slash[1] = replaced;
if (strlcat(real_path, slash, sizeof(real_path)) > sizeof(real_path)) {
errno = EINVAL;
err(1, "realpath: %s", path);
}
} else {
if (realpath(".", real_path) == NULL) {
err(1, "realpath: %s", path);
}
if (strlcat(real_path, "/", sizeof(real_path)) > sizeof(real_path)) {
errno = EINVAL;
err(1, "realpath: %s", path);
}
if (strlcat(real_path, path, sizeof(real_path)) > sizeof(real_path)) {
errno = EINVAL;
err(1, "realpath: %s", path);
}
}
setenv("__PYVENV_LAUNCHER__", real_path, 1);
}
/*
* Let argv[0] refer to the new interpreter. This is needed to
* get the effect we want on OSX 10.5 or earlier. That is, without
* changing argv[0] the real interpreter won't have access to
* the Window Server.
*/
argv[0] = exec_path;
#ifdef HAVE_SPAWN_H
/* We're weak-linking to posix-spawnv to ensure that
* an executable build on 10.5 can work on 10.4.
*/
if (posix_spawn != NULL) {
posix_spawnattr_t spawnattr = NULL;
setup_spawnattr(&spawnattr);
posix_spawn(NULL, exec_path, NULL,
&spawnattr, argv, environ);
err(1, "posix_spawn: %s", exec_path);
}
#endif
execve(exec_path, argv, environ);
err(1, "execve: %s", argv[0]);
/* NOTREACHED */
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

暂无描述
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/python_sourcecode/python3.8.1.git
git@gitee.com:python_sourcecode/python3.8.1.git
python_sourcecode
python3.8.1
python3.8.1
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /