• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PySys_SetObject函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中PySys_SetObject函数的典型用法代码示例。如果您正苦于以下问题:C++ PySys_SetObject函数的具体用法?C++ PySys_SetObject怎么用?C++ PySys_SetObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了PySys_SetObject函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: PyRun_InteractiveLoop

int
PyRun_InteractiveLoop(FILE *fp, char *filename)
{
	PyObject *v;
	int ret;
	v = PySys_GetObject("ps1");
	if (v == NULL) {
		PySys_SetObject("ps1", v = PyString_FromString(">>> "));
		Py_XDECREF(v);
	}
	v = PySys_GetObject("ps2");
	if (v == NULL) {
		PySys_SetObject("ps2", v = PyString_FromString("... "));
		Py_XDECREF(v);
	}
	for (;;) {
		ret = PyRun_InteractiveOne(fp, filename);
#ifdef Py_REF_DEBUG
		fprintf(stderr, "[%ld refs]\n", _Py_RefTotal);
#endif
		if (ret == E_EOF)
			return 0;
		/*
		if (ret == E_NOMEM)
			return -1;
		*/
	}
}
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:28,代码来源:pythonrun.c


示例2: PyMPI_UnrestrictedOutput

void PyMPI_UnrestrictedOutput(int stream) {
    PyObject* pyOutput = 0;
    PyObject* pyErrput = 0;

    if(stream & 0x01)
    {
        PYCHECK( pyOutput = PySys_GetObject("__stdout__"));
        Py_INCREF(pyOutput);
        PYCHECK( PySys_SetObject("stdout",pyOutput));
        Py_INCREF(Py_None);
        PYCHECK( PyDict_SetItemString(PyMPI_dictionary,"outputQueueFile",Py_None));
    }

    if(stream & 0x02)
    {
        PYCHECK( pyErrput = PySys_GetObject("__stderr__"));
        Py_INCREF(pyErrput);
        PYCHECK( PySys_SetObject("stderr",pyErrput));
        Py_INCREF(Py_None);
        PYCHECK( PyDict_SetItemString(PyMPI_dictionary,"errputQueueFile",Py_None));
    }

    /* Fall through */
pythonError:
    return;
}
开发者ID:rheiland,项目名称:rheiland.github.io,代码行数:26,代码来源:initmpi.c


示例3: handle_python_admin

static void handle_python_admin(admin_handle h, const char * const *args, void *userdata)
{
	char *text;
	PyObject *old_stdout, *old_stderr;
	AdminOutputObject *admin_stdout;

	if (args[1] == NULL) {
		/* Silently ignore */
		return;
	}

	text = g_strjoinv(" ", (char **)args+1);

	old_stdout = PySys_GetObject("stdout");
	old_stderr = PySys_GetObject("stderr");
	admin_stdout = PyObject_New(AdminOutputObject, &AdminOutputType);
	admin_stdout->h = h;
	admin_stdout->buffer = NULL;
	PySys_SetObject("stdout", (PyObject *)admin_stdout);
	PySys_SetObject("stderr", (PyObject *)admin_stdout);
	PyRun_SimpleString(text);
	g_free(text);
	PySys_SetObject("stdout", old_stdout);
	PySys_SetObject("stderr", old_stderr);
	Py_DECREF(admin_stdout);
}
开发者ID:jelmer,项目名称:ctrlproxy,代码行数:26,代码来源:python.c


示例4: PyRun_InteractiveLoopFlags

int
PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)
{
	PyObject *v;
	int ret;
	PyCompilerFlags local_flags;

	if (flags == NULL) {
		flags = &local_flags;
		local_flags.cf_flags = 0;
	}
	v = PySys_GetObject("ps1");
	if (v == NULL) {
		PySys_SetObject("ps1", v = PyString_FromString(">>> "));
		Py_XDECREF(v);
	}
	v = PySys_GetObject("ps2");
	if (v == NULL) {
		PySys_SetObject("ps2", v = PyString_FromString("... "));
		Py_XDECREF(v);
	}
	for (;;) {
		ret = PyRun_InteractiveOneFlags(fp, filename, flags);
		PRINT_TOTAL_REFS();
		if (ret == E_EOF)
			return 0;
		/*
		if (ret == E_NOMEM)
			return -1;
		*/
	}
}
开发者ID:hangyan,项目名称:python-source-code,代码行数:32,代码来源:pythonrun.c


示例5: text

int CPython::ExecCmds(const std::wstring &cmds, std::wstring &err, HANDLE hfile)
{
	int id = 0; FILE *pfile = nullptr; DWORD count = 0;
	PyObject *poldout, *polderr, *pnewout, *pnewerr; 
	if (cmds.length() <= 0) {
		err = text("No python command found"); return 1;
	}
	if (DuplicateHandle (
		GetCurrentProcess(), hfile, GetCurrentProcess(), &hfile, 
		0, false, DUPLICATE_SAME_ACCESS
	)) {
		id = open_osfhandle((intptr_t)hfile, _O_WRONLY);
		pfile = fdopen(id,"w"); setvbuf(pfile,nullptr,_IONBF,1024);
		poldout = PySys_GetObject("stdout"); 
		polderr = PySys_GetObject("stderr"); 
		pnewout = PyFile_FromFile(pfile, "logger", "w", nullptr);
		pnewerr = PyFile_FromFile(pfile, "logger", "w", nullptr);
		PySys_SetObject("stdout", pnewout);
		PySys_SetObject("stderr", pnewerr);
	} else poldout = polderr = pnewout = pnewerr = nullptr;

	std::wstring_convert<std::codecvt_utf8_utf16<wchar>> cvt; 
	std::string str = cvt.to_bytes(cmds); 
	int irslt = PyRun_SimpleString(str.c_str());
	if (irslt != 0) err = text("Internal error that PyRun_SimpleString fail"); 
	else err = text("Execute python commands successfully .."); 

	if (pnewout != nullptr) PySys_SetObject("stdout", poldout); 
	if (pnewerr != nullptr) PySys_SetObject("stderr", polderr); 
	if (pfile != nullptr) fclose(pfile); return irslt; 
}
开发者ID:zzydog,项目名称:OllyDog,代码行数:31,代码来源:Python.cpp


示例6: TS3init

PyMODINIT_FUNC TS3init(void)
{
	PyObject *m;
	printf("Init TS3 module\n");
	m = Py_InitModule("TS3", TS3Methods);	
	PySys_SetObject("stdout", m);
	PySys_SetObject("stderr", m);
}
开发者ID:WesleyLuk90,项目名称:ts3-python-plugin-old,代码行数:8,代码来源:python_functions.c


示例7: initMatpyPrint

static void initMatpyPrint(void)
{
    PyObject *matpyPrintModule = Py_InitModule("print", matpyPrintMethods);
    if (NULL != matpyPrintModule)
    {
        PySys_SetObject((char*)"stdout", matpyPrintModule);
        PySys_SetObject((char*)"stderr", matpyPrintModule);
    }
}
开发者ID:invenia,项目名称:matpy,代码行数:9,代码来源:py.cpp


示例8: ResetStdOut

void ResetStdOut() {
  if (gStdOutSaved)
    PySys_SetObject("stdout", gStdOutSaved);
  if (gStdErrSaved)
    PySys_SetObject("stderr", gStdErrSaved);

  Py_XDECREF(gStdOut);
  gStdOut = 0;
}
开发者ID:IndraVikas,项目名称:expressPython,代码行数:9,代码来源:emb.cpp


示例9: ada_py_initialize_and_module

PyObject*
ada_py_initialize_and_module(char* program_name, char* name) {
   PyObject* module;
   PyObject* imported;

   user_module_name = strdup(name);

#if PY_MAJOR_VERSION >= 3
   user_module.m_name = user_module_name;
   Py_SetProgramName ((wchar_t*)program_name);
#else
   Py_SetProgramName (program_name);
#endif

   PyImport_AppendInittab(user_module_name, init_user_module);
   Py_InitializeEx(0);

   // Initialize the prompt if needed

   PyObject* prompt = PySys_GetObject ("ps1");
   if (prompt == NULL) {
      prompt = PyUnicode_FromString (">>> ");
      PySys_SetObject ("ps1", prompt);
      Py_DECREF (prompt);
   }

   prompt = PySys_GetObject ("ps2");
   if (prompt == NULL) {
      prompt = PyUnicode_FromString ("... ");
      PySys_SetObject ("ps2", prompt);
      Py_DECREF (prompt);
   }

   // Make the user's module visible to scripts. We cannot use
   // PyImport_ImportModule, which imports the module but doesn't add
   // it to the global dictionary and as such it is not visible to
   // user scripts.

   imported = PyImport_ImportModule(name);
   if (imported == NULL) {
      printf ("Could not import module %s", name);
      return NULL;
   }

   // Import 'sys', which is needed for instance in Set_Default_Console
   // to get access to the default value
   PyRun_SimpleString("import sys\n");

   char* command = (char*)malloc(9 + strlen(name));
   strcpy (command, "import ");
   strcat (command, name);
   strcat (command, "\n");
   PyRun_SimpleString(command);
   free (command);

   return imported;
};
开发者ID:cbourgeois,项目名称:gnatcoll,代码行数:57,代码来源:python_support.c


示例10: SetStdout

void SetStdout(StdOutWriteType write) {
  if (!gStdOut) {
    gStdOutSaved = PySys_GetObject("stdout");
    gStdErrSaved = PySys_GetObject("stderr");
    gStdOut = StdoutType.tp_new(&StdoutType, 0, 0);
  }
  StdOut *impl = reinterpret_cast<StdOut *>(gStdOut);
  impl->write = write;
  PySys_SetObject("stdout", gStdOut);
  PySys_SetObject("stderr", gStdOut);
}
开发者ID:IndraVikas,项目名称:expressPython,代码行数:11,代码来源:emb.cpp


示例11: PySys_GetObject

PyObject *set_stdstream(std::string name, PyObject *pystream) {
  PyObject *old_pystream = PySys_GetObject(const_cast<char*>(name.c_str())); // borrowed
  Py_XINCREF(pystream);
  PySys_SetObject(const_cast<char*>(name.c_str()), pystream);
  Py_XDECREF(old_pystream);
  return old_pystream;
}
开发者ID:nonsleepr,项目名称:PyR,代码行数:7,代码来源:py_stream.cpp


示例12: bpy_text_compile

bool bpy_text_compile(Text *text)
{
	char fn_dummy[FILE_MAX];
	PyObject *fn_dummy_py;
	char *buf;

	bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text);

	/* if previously compiled, free the object */
	free_compiled_text(text);

	fn_dummy_py = PyC_UnicodeFromByte(fn_dummy);

	buf = txt_to_buf(text);
	text->compiled = Py_CompileStringObject(buf, fn_dummy_py, Py_file_input, NULL, -1);
	MEM_freeN(buf);

	Py_DECREF(fn_dummy_py);

	if (PyErr_Occurred()) {
		PyErr_Print();
		PyErr_Clear();
		PySys_SetObject("last_traceback", NULL);
		free_compiled_text(text);
		return false;
	}
	else {
		return true;
	}
}
开发者ID:mgschwan,项目名称:blensor,代码行数:30,代码来源:bpy_internal_import.c


示例13: bpy_text_filename_get

PyObject *bpy_text_import(Text *text)
{
	char *buf = NULL;
	char modulename[MAX_ID_NAME + 2];
	int len;

	if (!text->compiled) {
		char fn_dummy[256];
		bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text);

		buf = txt_to_buf(text);
		text->compiled = Py_CompileString(buf, fn_dummy, Py_file_input);
		MEM_freeN(buf);

		if (PyErr_Occurred()) {
			PyErr_Print();
			PyErr_Clear();
			PySys_SetObject("last_traceback", NULL);
			free_compiled_text(text);
			return NULL;
		}
	}

	len = strlen(text->id.name + 2);
	BLI_strncpy(modulename, text->id.name + 2, len);
	modulename[len - 3] = '\0'; /* remove .py */
	return PyImport_ExecCodeModule(modulename, text->compiled);
}
开发者ID:244xiao,项目名称:blender,代码行数:28,代码来源:bpy_internal_import.c


示例14: PyXPCOM_DLLAddRef

void PyXPCOM_DLLAddRef(void)
{
	// Must be thread-safe, although cant have the Python lock!
	CEnterLeaveXPCOMFramework _celf;
	PRInt32 cnt = PR_AtomicIncrement(&g_cLockCount);
	if (cnt==1) { // First call
		if (!Py_IsInitialized()) {
			Py_Initialize();
			// Make sure our Windows framework is all setup.
			PyXPCOM_Globals_Ensure();
			// Make sure we have _something_ as sys.argv.
			if (PySys_GetObject((char*)"argv")==NULL) {
				PyObject *path = PyList_New(0);
#if PY_MAJOR_VERSION <= 2
				PyObject *str = PyString_FromString("");
#else
				PyObject *str = PyUnicode_FromString("");
#endif
				PyList_Append(path, str);
				PySys_SetObject((char*)"argv", path);
				Py_XDECREF(path);
				Py_XDECREF(str);
			}

			// Must force Python to start using thread locks, as
			// we are free-threaded (maybe, I think, sometimes :-)
			PyEval_InitThreads();
#ifndef PYXPCOM_USE_PYGILSTATE
			// Release Python lock, as first thing we do is re-get it.
			ptsGlobal = PyEval_SaveThread();
#endif
			// NOTE: We never finalize Python!!
		}
	}
}
开发者ID:mdaniel,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:35,代码来源:dllmain.cpp


示例15: ssipylog_stdout_reset

void ssipylog_stdout_reset()
{
    if (ssipylog_g_stdout_saved)
        PySys_SetObject("stdout", ssipylog_g_stdout_saved);

    Py_XDECREF(ssipylog_g_stdout);
	ssipylog_g_stdout = 0;
}
开发者ID:hcmlab,项目名称:mobileSSI,代码行数:8,代码来源:ssipylog.c


示例16: PythonRedirector

 PythonRedirector(const char* type, PyObject* obj) : std_out(type), out(obj), old(0)
 {
     if (out) {
         Base::PyGILStateLocker lock;
         old = PySys_GetObject(const_cast<char*>(std_out));
         PySys_SetObject(const_cast<char*>(std_out), out);
     }
 }
开发者ID:AjinkyaDahale,项目名称:FreeCAD,代码行数:8,代码来源:Macro.cpp


示例17: PySys_SetObject

 ~PythonRedirector()
 {
     if (out) {
         Base::PyGILStateLocker lock;
         PySys_SetObject(const_cast<char*>(std_out), old);
         Py_DECREF(out);
     }
 }
开发者ID:AjinkyaDahale,项目名称:FreeCAD,代码行数:8,代码来源:Macro.cpp


示例18: PySys_SetObject

void Redirector::reset_stdout()
{
    if (m_stdout_saved)
        PySys_SetObject(const_cast<char*>("stdout"), m_stdout_saved);

    Py_XDECREF(m_stdout);
    m_stdout = 0;
}
开发者ID:mweisman,项目名称:PDAL,代码行数:8,代码来源:Redirector.cpp


示例19: startPython

/*!
	Starts the python interpreter
*/
void startPython( int argc, char* argv[] )
{
	Py_SetProgramName( argv[0] );

	Py_NoSiteFlag = 1; // No import because we need to set the search path first

	Py_Initialize();
	PySys_SetArgv( argc, argv );

	// Modify our search-path
	PyObject* searchpath = PySys_GetObject( "path" );

	QStringList elements = QStringList::split( ";", Config::instance()->getString( "General", "Python Searchpath", "./scripts;.", true ) );

	// Prepend our items to the searchpath
	for ( int i = elements.count() - 1; i >= 0; --i )
	{
		PyList_Insert( searchpath, 0, PyString_FromString( elements[i].latin1() ) );
	}

	// Import site now
	PyObject* m = PyImport_ImportModule( "site" );
	Py_XDECREF( m );

	// Try changing the stderr + stdout pointers
	PyObject* file = PyFile_FromString( "python.log", "w" );

	if ( file )
	{
		Py_INCREF( file );
		PySys_SetObject( "stderr", file );
		Py_INCREF( file );
		PySys_SetObject( "stdout", file );
		Py_DECREF( file );
	}

	try
	{
		init_wolfpack_globals();
	}
	catch ( ... )
	{
		Console::instance()->send( "Failed to initialize the python extension modules\n" );
	}
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:48,代码来源:engine.cpp


示例20: printf

PyObject *bpy_text_reimport(PyObject *module, int *found)
{
	Text *text;
	const char *name;
	char *filepath;
	char *buf = NULL;
//XXX	Main *maggie = bpy_import_main ? bpy_import_main:G.main;
	Main *maggie = bpy_import_main;
	
	if (!maggie) {
		printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n");
		return NULL;
	}
	
	*found = 0;
	
	/* get name, filename from the module itself */
	if ((name = PyModule_GetName(module)) == NULL)
		return NULL;

	if ((filepath = (char *)PyModule_GetFilename(module)) == NULL)
		return NULL;

	/* look up the text object */
	text = BLI_findstring(&maggie->text, BLI_path_basename(filepath), offsetof(ID, name) + 2);

	/* uh-oh.... didn't find it */
	if (!text)
		return NULL;
	else
		*found = 1;

	/* if previously compiled, free the object */
	/* (can't see how could be NULL, but check just in case) */ 
	if (text->compiled) {
		Py_DECREF((PyObject *)text->compiled);
	}

	/* compile the buffer */
	buf = txt_to_buf(text);
	text->compiled = Py_CompileString(buf, text->id.name + 2, Py_file_input);
	MEM_freeN(buf);

	/* if compile failed.... return this error */
	if (PyErr_Occurred()) {
		PyErr_Print();
		PyErr_Clear();
		PySys_SetObject("last_traceback", NULL);
		free_compiled_text(text);
		return NULL;
	}

	/* make into a module */
	return PyImport_ExecCodeModule((char *)name, text->compiled);
}
开发者ID:244xiao,项目名称:blender,代码行数:55,代码来源:bpy_internal_import.c



注:本文中的PySys_SetObject函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PySys_WriteStderr函数代码示例发布时间:2022-05-30
下一篇:
C++ PySys_SetArgv函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap