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

C++ PyString_InternFromString函数代码示例

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

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



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

示例1: dbus_py_init_abstract

dbus_bool_t
dbus_py_init_abstract(void)
{
    _dbus_py_variant_levels = PyDict_New();
    if (!_dbus_py_variant_levels) return 0;

    dbus_py__dbus_object_path__const = PyString_InternFromString("__dbus_object_path__");
    if (!dbus_py__dbus_object_path__const) return 0;

    dbus_py_variant_level_const = PyString_InternFromString("variant_level");
    if (!dbus_py_variant_level_const) return 0;

    dbus_py_signature_const = PyString_InternFromString("signature");
    if (!dbus_py_signature_const) return 0;

    DBusPyIntBase_Type.tp_base = &PyInt_Type;
    if (PyType_Ready(&DBusPyIntBase_Type) < 0) return 0;
    /* disable the tp_print copied from PyInt_Type, so tp_repr gets called as
    desired */
    DBusPyIntBase_Type.tp_print = NULL;

    DBusPyFloatBase_Type.tp_base = &PyFloat_Type;
    if (PyType_Ready(&DBusPyFloatBase_Type) < 0) return 0;
    DBusPyFloatBase_Type.tp_print = NULL;

    DBusPyLongBase_Type.tp_base = &PyLong_Type;
    if (PyType_Ready(&DBusPyLongBase_Type) < 0) return 0;
    DBusPyLongBase_Type.tp_print = NULL;

    DBusPyStrBase_Type.tp_base = &PyString_Type;
    if (PyType_Ready(&DBusPyStrBase_Type) < 0) return 0;
    DBusPyStrBase_Type.tp_print = NULL;

    return 1;
}
开发者ID:mahomahomaho,项目名称:dbus-python-egg,代码行数:35,代码来源:abstract.c


示例2: init_template

PyMODINIT_FUNC
init_template(void)
{
  // Set interned strings.
  Skip_Filter_PyString = PyString_InternFromString("skip_filter");
  filter_function_name = PyString_InternFromString("_filter_function");

  // Get SanitizedPlaceholder from the baked module.
  PyObject *baked_module = PyImport_ImportModule("spitfire.runtime.baked");
  if (baked_module == NULL)
    return;
  baked_SanitizedPlaceholder = (struct _typeobject *)
      PyObject_GetAttrString(baked_module, "SanitizedPlaceholder");
  Py_DECREF(baked_module);
  if (baked_SanitizedPlaceholder == NULL)
    return;


  // Setup module and class.
  PyObject *m;
  BaseSpitfireTemplateType.tp_new = PyType_GenericNew;
  if (PyType_Ready(&BaseSpitfireTemplateType) < 0)
    return;

  m = Py_InitModule3("_template", module_methods, "Template Module");
  if (m == NULL)
    return;

  Py_INCREF(&BaseSpitfireTemplateType);
  PyModule_AddObject(m, "BaseSpitfireTemplate",
                     (PyObject *)&BaseSpitfireTemplateType);
}
开发者ID:abraxasllc,项目名称:spitfire,代码行数:32,代码来源:_template.c


示例3: _SKCurve_InitCurveObject

int
_SKCurve_InitCurveObject(void)
{
    set_nodes_and_segments_string =
	PyString_InternFromString("_set_nodes_and_segments");
    undo_close_string = PyString_InternFromString("_undo_close");
    return 1;
}
开发者ID:kindlychung,项目名称:sk1,代码行数:8,代码来源:curveobject.c


示例4: bool_repr

static PyObject *
bool_repr(PyBoolObject *self)
{
	PyObject *s;

	if (self->ob_ival)
		s = true_str ? true_str :
			(true_str = PyString_InternFromString("True"));
	else
		s = false_str ? false_str :
			(false_str = PyString_InternFromString("False"));
	Py_XINCREF(s);
	return s;
}
开发者ID:JupiterSmalltalk,项目名称:openqwaq,代码行数:14,代码来源:boolobject.c


示例5: PyObject_Unicode

PyObject *
PyObject_Unicode(PyObject *v)
{
	PyObject *res;
	PyObject *func;
	PyObject *str;
	static PyObject *unicodestr;

	if (v == NULL) {
		res = PyString_FromString("<NULL>");
		if (res == NULL)
			return NULL;
		str = PyUnicode_FromEncodedObject(res, NULL, "strict");
		Py_DECREF(res);
		return str;
	} else if (PyUnicode_CheckExact(v)) {
		Py_INCREF(v);
		return v;
	}
	/* XXX As soon as we have a tp_unicode slot, we should
	   check this before trying the __unicode__
	   method. */
	if (unicodestr == NULL) {
		unicodestr= PyString_InternFromString("__unicode__");
		if (unicodestr == NULL)
			return NULL;
	}
	func = PyObject_GetAttr(v, unicodestr);
	if (func != NULL) {
		res = PyEval_CallObject(func, (PyObject *)NULL);
		Py_DECREF(func);
	}
	else {
		PyErr_Clear();
		if (PyUnicode_Check(v)) {
			/* For a Unicode subtype that's didn't overwrite __unicode__,
			   return a true Unicode object with the same data. */
			return PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(v),
			                             PyUnicode_GET_SIZE(v));
		}
		if (PyString_CheckExact(v)) {
			Py_INCREF(v);
			res = v;
		}
		else {
			if (v->ob_type->tp_str != NULL)
				res = (*v->ob_type->tp_str)(v);
			else
				res = PyObject_Repr(v);
		}
	}
	if (res == NULL)
		return NULL;
	if (!PyUnicode_Check(res)) {
		str = PyUnicode_FromEncodedObject(res, NULL, "strict");
		Py_DECREF(res);
		res = str;
	}
	return res;
}
开发者ID:Charlian,项目名称:python-cobra,代码行数:60,代码来源:object.c


示例6: __Pyx_InitStrings

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else  /* Python 3+ has unicode identifiers */
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}
开发者ID:skipperkongen,项目名称:the_education_of,代码行数:29,代码来源:hello.c


示例7: propertyDocCopy

static void propertyDocCopy(BoxedProperty* prop, Box* fget) {
    assert(prop);
    assert(fget);
    Box* get_doc;

    static BoxedString* doc_str = static_cast<BoxedString*>(PyString_InternFromString("__doc__"));
    try {
        get_doc = getattrInternal(fget, doc_str, NULL);
    } catch (ExcInfo e) {
        if (!e.matches(Exception)) {
            throw e;
        }
        get_doc = NULL;
    }

    if (get_doc) {
        if (prop->cls == property_cls) {
            prop->prop_doc = get_doc;
        } else {
            /* If this is a property subclass, put __doc__
            in dict of the subclass instance instead,
            otherwise it gets shadowed by __doc__ in the
            class's dict. */
            setattr(prop, doc_str, get_doc);
        }
        prop->getter_doc = true;
    }
}
开发者ID:rowhit,项目名称:pyston,代码行数:28,代码来源:descr.cpp


示例8: try_complex_special_method

static PyObject *
try_complex_special_method(PyObject *op) {
    PyObject *f;
    static PyObject *complexstr;

    if (complexstr == NULL) {
        complexstr = PyString_InternFromString("__complex__");
        if (complexstr == NULL)
            return NULL;
    }
    if (PyInstance_Check(op)) {
        f = PyObject_GetAttr(op, complexstr);
        if (f == NULL) {
            if (PyErr_ExceptionMatches(PyExc_AttributeError))
                PyErr_Clear();
            else
                return NULL;
        }
    }
    else {
        f = _PyObject_LookupSpecial(op, "__complex__", &complexstr);
        if (f == NULL && PyErr_Occurred())
            return NULL;
    }
    if (f != NULL) {
        PyObject *res = PyObject_CallFunctionObjArgs(f, NULL);
        Py_DECREF(f);
        return res;
    }
    return NULL;
}
开发者ID:youseatao,项目名称:Python-2.7.8,代码行数:31,代码来源:complexobject.c


示例9: _PyFrame_Init

int _PyFrame_Init()
{
    builtin_object = PyString_InternFromString("__builtins__");
    if (builtin_object == NULL)
        return 0;
    return 1;
}
开发者ID:nashuiliang,项目名称:source-python2.6.6,代码行数:7,代码来源:frameobject.c


示例10: PyObject_GenericGetAttr

static PyObject *Proxy_getattro(
        ProxyObject *self, PyObject *name)
{
    PyObject *object = NULL;
    PyObject *result = NULL;

    static PyObject *getattr_str = NULL;

    object = PyObject_GenericGetAttr((PyObject *)self, name);

    if (object)
        return object;

    PyErr_Clear();

    if (!getattr_str) {
#if PY_MAJOR_VERSION >= 3
        getattr_str = PyUnicode_InternFromString("__getattr__");
#else
        getattr_str = PyString_InternFromString("__getattr__");
#endif
    }

    object = PyObject_GenericGetAttr((PyObject *)self, getattr_str);

    if (!object)
        return NULL;

    result = PyObject_CallFunctionObjArgs(object, name, NULL);

    Py_DECREF(object);

    return result;
}
开发者ID:FeodorFitsner,项目名称:python-lazy-object-proxy,代码行数:34,代码来源:cext.c


示例11: _PyWarnings_Init

PyMODINIT_FUNC
_PyWarnings_Init(void)
{
    PyObject *m, *default_action;

    m = Py_InitModule3(MODULE_NAME, warnings_functions, warnings__doc__);
    if (m == NULL)
        return;

    _filters = init_filters();
    if (_filters == NULL)
        return;
    Py_INCREF(_filters);
    if (PyModule_AddObject(m, "filters", _filters) < 0)
        return;

    _once_registry = PyDict_New();
    if (_once_registry == NULL)
        return;
    Py_INCREF(_once_registry);
    if (PyModule_AddObject(m, "once_registry", _once_registry) < 0)
        return;

    default_action = PyString_InternFromString("default");
    if (default_action == NULL)
        return;
    if (PyModule_AddObject(m, DEFAULT_ACTION_NAME, default_action) < 0)
        return;
}
开发者ID:1310701102,项目名称:sl4a,代码行数:29,代码来源:_warnings.c


示例12: Call_GetClassObject

long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
    PyObject *mod, *func, *result;
    long retval;
    static PyObject *context;

    if (context == NULL)
        context = PyString_InternFromString("_ctypes.DllGetClassObject");

    mod = PyImport_ImportModuleNoBlock("ctypes");
    if (!mod) {
        PyErr_WriteUnraisable(context ? context : Py_None);
        /* There has been a warning before about this already */
        return E_FAIL;
    }

    func = PyObject_GetAttrString(mod, "DllGetClassObject");
    Py_DECREF(mod);
    if (!func) {
        PyErr_WriteUnraisable(context ? context : Py_None);
        return E_FAIL;
    }

    {
        PyObject *py_rclsid = PyLong_FromVoidPtr((void *)rclsid);
        PyObject *py_riid = PyLong_FromVoidPtr((void *)riid);
        PyObject *py_ppv = PyLong_FromVoidPtr(ppv);
        if (!py_rclsid || !py_riid || !py_ppv) {
            Py_XDECREF(py_rclsid);
            Py_XDECREF(py_riid);
            Py_XDECREF(py_ppv);
            Py_DECREF(func);
            PyErr_WriteUnraisable(context ? context : Py_None);
            return E_FAIL;
        }
        result = PyObject_CallFunctionObjArgs(func,
                                              py_rclsid,
                                              py_riid,
                                              py_ppv,
                                              NULL);
        Py_DECREF(py_rclsid);
        Py_DECREF(py_riid);
        Py_DECREF(py_ppv);
    }
    Py_DECREF(func);
    if (!result) {
        PyErr_WriteUnraisable(context ? context : Py_None);
        return E_FAIL;
    }

    retval = PyInt_AsLong(result);
    if (PyErr_Occurred()) {
        PyErr_WriteUnraisable(context ? context : Py_None);
        retval = E_FAIL;
    }
    Py_DECREF(result);
    return retval;
}
开发者ID:yurenyong123,项目名称:pyston,代码行数:58,代码来源:callbacks.c


示例13: create_filter

static PyObject *
create_filter(PyObject *category, const char *action)
{
    static PyObject *ignore_str = NULL;
    static PyObject *error_str = NULL;
    static PyObject *default_str = NULL;
    PyObject *action_obj = NULL;
    PyObject *lineno, *result;

    if (!strcmp(action, "ignore")) {
        if (ignore_str == NULL) {
            ignore_str = PyString_InternFromString("ignore");
            if (ignore_str == NULL)
                return NULL;
        }
        action_obj = ignore_str;
    }
    else if (!strcmp(action, "error")) {
        if (error_str == NULL) {
            error_str = PyString_InternFromString("error");
            if (error_str == NULL)
                return NULL;
        }
        action_obj = error_str;
    }
    else if (!strcmp(action, "default")) {
        if (default_str == NULL) {
            default_str = PyString_InternFromString("default");
            if (default_str == NULL)
                return NULL;
        }
        action_obj = default_str;
    }
    else {
        Py_FatalError("unknown action");
    }

    /* This assumes the line number is zero for now. */
    lineno = PyInt_FromLong(0);
    if (lineno == NULL)
        return NULL;
    result = PyTuple_Pack(5, action_obj, Py_None, category, Py_None, lineno);
    Py_DECREF(lineno);
    return result;
}
开发者ID:GINK03,项目名称:StaticPython,代码行数:45,代码来源:_warnings.c


示例14: __Pyx_InternStrings

static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) {
    while (t->p) {
        *t->p = PyString_InternFromString(t->s);
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}
开发者ID:rkern,项目名称:redir,代码行数:9,代码来源:redir.c


示例15: GetClassName

static
PyObject* GetClassName(PyObject* obj) {
    CapsuleContext* context = GetContext(obj);
    if (!context) {
        return NULL;
    } else {
        return PyString_InternFromString(context->className);
    }
}
开发者ID:KennethNielsen,项目名称:llvmpy,代码行数:9,代码来源:capsule.cpp


示例16: PyFunction_New

//pycodeobject 对象和 global名字空间传进来
PyObject *
PyFunction_New(PyObject *code, PyObject *globals)
{
    PyFunctionObject *op = PyObject_GC_New(PyFunctionObject,
                                        &PyFunction_Type);
    static PyObject *__name__ = 0;
    if (op != NULL) {
        PyObject *doc;
        PyObject *consts;
        PyObject *module;
        op->func_weakreflist = NULL;
        Py_INCREF(code);
        op->func_code = code;//PyCodeObject 设置上去
        Py_INCREF(globals);
        op->func_globals = globals;
        op->func_name = ((PyCodeObject *)code)->co_name;
        Py_INCREF(op->func_name);
		//默认参数
        op->func_defaults = NULL; /* No default arguments */
		//闭包数据
        op->func_closure = NULL;
        consts = ((PyCodeObject *)code)->co_consts;
        if (PyTuple_Size(consts) >= 1) {
			//第0项一定是doc了....
            doc = PyTuple_GetItem(consts, 0);
            if (!PyString_Check(doc) && !PyUnicode_Check(doc))
                doc = Py_None;
        }
        else
            doc = Py_None;
        Py_INCREF(doc);
        op->func_doc = doc;
        op->func_dict = NULL;
        op->func_module = NULL;

        /* __module__: If module name is in globals, use it.
           Otherwise, use None.
        */
        if (!__name__) {
            __name__ = PyString_InternFromString("__name__");
            if (!__name__) {
                Py_DECREF(op);
                return NULL;
            }
        }
        module = PyDict_GetItem(globals, __name__);
        if (module) {
            Py_INCREF(module);
            op->func_module = module;
        }
    }
    else
        return NULL;
    _PyObject_GC_TRACK(op);
    return (PyObject *)op;
}
开发者ID:0xcc,项目名称:python-read,代码行数:57,代码来源:funcobject.c


示例17: iterwrapperHasnextUnboxed

bool iterwrapperHasnextUnboxed(Box* s) {
    RELEASE_ASSERT(s->cls == iterwrapper_cls, "");
    BoxedIterWrapper* self = static_cast<BoxedIterWrapper*>(s);

    static BoxedString* next_str = static_cast<BoxedString*>(PyString_InternFromString("next"));
    Box* next;
    try {
        next = callattr(self->iter, next_str, CallattrFlags({.cls_only = true, .null_on_nonexistent = false }),
                        ArgPassSpec(0), NULL, NULL, NULL, NULL, NULL);
    } catch (ExcInfo e) {
开发者ID:lameiro,项目名称:pyston,代码行数:10,代码来源:iterobject.cpp


示例18: initpax

void
initpax(void)
{
    int i;
    PyObject * d, *m, *v;

    m = Py_InitModule("pax", pax_methods);
    d = PyModule_GetDict(m);
    
#define ADD_INT(name) add_int(d, name, #name)
    ADD_INT(TCL_WINDOW_EVENTS);
    ADD_INT(TCL_FILE_EVENTS);
    ADD_INT(TCL_TIMER_EVENTS);
    ADD_INT(TCL_IDLE_EVENTS);
    ADD_INT(TCL_ALL_EVENTS);
    ADD_INT(TCL_DONT_WAIT);
    ADD_INT(TK_RELIEF_RAISED);
    ADD_INT(TK_RELIEF_SUNKEN);
    ADD_INT(TK_RELIEF_GROOVE);
    ADD_INT(TK_RELIEF_RIDGE);
    ADD_INT(TK_RELIEF_FLAT);
    ADD_INT(TK_3D_FLAT_GC);
    ADD_INT(TK_3D_LIGHT_GC);
    ADD_INT(TK_3D_DARK_GC);
    add_string(d, TK_VERSION, "TK_VERSION");
    add_string(d, TCL_VERSION, "TCL_VERSION");
    
    for (i = 0; i < NUM_METHOD_NAMES; i++)
    {
	/* Python 1.5! */
	PyObject * string = PyString_InternFromString(method_names[i]);
	if (!string)
	{
	   Py_FatalError("pax: Cannot create string objects");
	}
	method_names_obj[i] = string;
    }

    object_registry = PyDict_New();
    PyDict_SetItemString(d, "object_registry", object_registry);

    v = PyCObject_FromVoidPtr(&pax_functions, NULL);
    PyDict_SetItemString(d, "Pax_Functions", v);

#define ADD_TYPE(type) PyDict_SetItemString(d, #type, (PyObject*)(&type))

    ADD_TYPE(TkWinType);
    ADD_TYPE(PaxPixmapType);
    ADD_TYPE(PaxImageType);
    ADD_TYPE(PaxRegionType);
    ADD_TYPE(PaxCMapType);
    ADD_TYPE(PaxFontType);
    ADD_TYPE(PaxGCType);
    ADD_TYPE(PaxBorderType);
}
开发者ID:sk1project,项目名称:skencil,代码行数:55,代码来源:paxmodule.c


示例19: function_get_name

    static PyObject* function_get_name(PyObject* op, void*)
    {
        function* f = downcast<function>(op);
        if (f->name().is_none())
#if PY_VERSION_HEX >= 0x03000000
            return PyUnicode_InternFromString("<unnamed Boost.Python function>");
#else
            return PyString_InternFromString("<unnamed Boost.Python function>");
#endif
        else
            return python::incref(f->name().ptr());
开发者ID:Alexander--,项目名称:Wesnoth-1.8-for-Android,代码行数:11,代码来源:function.cpp


示例20: init_fibers

/* Module */
PyObject *
init_fibers(void)
{
    PyObject *fibers;

    /* Main module */
#if PY_MAJOR_VERSION >= 3
    fibers = PyModule_Create(&fibers_module);
#else
    fibers = Py_InitModule("fibers._cfibers", fibers_methods);
#endif

    /* keys for per-thread dictionary */
#if PY_MAJOR_VERSION >= 3
    main_fiber_key = PyUnicode_InternFromString("__fibers_main");
    current_fiber_key = PyUnicode_InternFromString("__fibers_current");
#else
    main_fiber_key = PyString_InternFromString("__fibers_main");
    current_fiber_key = PyString_InternFromString("__fibers_current");
#endif
    if ((current_fiber_key == NULL) || (main_fiber_key == NULL)) {
        goto fail;
    }

    /* Exceptions */
    PyExc_FiberError = PyErr_NewException("fibers._cfibers.error", NULL, NULL);
    MyPyModule_AddType(fibers, "error", (PyTypeObject *)PyExc_FiberError);

    /* Types */
    MyPyModule_AddType(fibers, "Fiber", &FiberType);

    return fibers;

fail:
#if PY_MAJOR_VERSION >= 3
    Py_DECREF(fibers);
#endif
    return NULL;

}
开发者ID:eugene-eeo,项目名称:python-fibers,代码行数:41,代码来源:fibers.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ PyString_Size函数代码示例发布时间:2022-05-30
下一篇:
C++ PyString_GET_SIZE函数代码示例发布时间: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