当前位置: 首页>>代码示例>>C++>>正文


C++ PyObject_New函数代码示例

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


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

示例1: new_membership_msg

static PyObject *
new_membership_msg(int type, PyObject *group, int num_members,
		   char (*members)[MAX_GROUP_NAME], char *buffer, int size)
{
    MembershipMsg *self;
    group_id grp_id;
    membership_info memb_info;
    int32 num_extra_members = 0;
    int i;
    int ret;

    assert(group != NULL);
    self = PyObject_New(MembershipMsg, &MembershipMsg_Type);
    if (self == NULL)
        return NULL;
    self->reason = type & CAUSED_BY_MASK; /* from sp.h defines */
    self->msg_subtype = type & (TRANSITION_MESS | REG_MEMB_MESS);
    Py_INCREF(group);
    self->group = group;
    self->members = NULL;
    self->extra = NULL;
    self->group_id = NULL;
    self->changed_member = NULL;
    self->members = PyTuple_New(num_members);
    if (self->members == NULL) {
        Py_DECREF(self);
        return NULL;
    }
    for (i = 0; i < num_members; ++i) {
        PyObject *s = PyString_FromString(members[i]);
        if (!s) {
            Py_DECREF(self);
            return NULL;
        }
        PyTuple_SET_ITEM(self->members, i, s);
    }


    if ((ret = SP_get_memb_info(buffer, type, &memb_info)) < 0) {
	      PyErr_Format(SpreadError, "error %d on SP_get_memb_info", ret);
        Py_DECREF(self);
        return NULL;
    }


    memcpy(&grp_id, &memb_info.gid, sizeof(group_id));
    self->group_id = new_group_id(grp_id);
    if (self->group_id == NULL) {
        Py_DECREF(self);
        return NULL;
    }


    /* The extra attribute is a tuple initialized for 0 or more items.
     * If the member event is a single member event such as a join, leave or disconnect,
     * the changed member attribute is set from memb_info.changed_member
     * and a single value from vs_set, which is stored inside the message, is added to extra tuple.
     * If the member event is a merge or partition, the list of member names
     * from vs_set is stored in extra.
     */


    if (Is_reg_memb_mess(type) && (Is_caused_join_mess(type) || Is_caused_disconnect_mess(type) || Is_caused_leave_mess(type))) {
        self->changed_member =  PyString_FromString(memb_info.changed_member);
        if (!self->changed_member) {
            Py_DECREF(self);
            return NULL;
        }
    }
    else {
        self->changed_member = Py_BuildValue("");
    }

    num_extra_members = memb_info.my_vs_set.num_members;

    self->extra = PyTuple_New(num_extra_members);
    if (self->extra == NULL) {
        Py_DECREF(self);
        return NULL;
    }

    if (num_extra_members > 0) {

        char (*member_names)[MAX_GROUP_NAME] = (char (*)[MAX_GROUP_NAME]) malloc(num_extra_members * MAX_GROUP_NAME);

        if (member_names == NULL) {
            Py_DECREF(self);
            PyErr_NoMemory();
            return NULL;
        }

        if ((ret = SP_get_vs_set_members(buffer, &memb_info.my_vs_set, member_names, num_extra_members)) < 0) {
	          PyErr_Format(SpreadError, "error %d on SP_get_vs_set_members", ret);
            Py_DECREF(self);
            free(member_names);
            return NULL;
        }

        for (i = 0; i < num_extra_members; i++) {
            PyObject *s;
//.........这里部分代码省略.........
开发者ID:gyepisam,项目名称:spread-python,代码行数:101,代码来源:spreadmodule.c

示例2: pcre_RegexObject_match

static PyObject *
pcre_RegexObject_match(pcre_RegexObject* self, PyObject *args, PyObject *keywds)
{
	char *subject;
	int pos = INT_MIN, endpos = INT_MIN; // values of non-passed parameters

	static char *kwlist[] = {"string", "pos", "endpos", NULL};

	if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|ii", kwlist, &subject, &pos, &endpos))
		return NULL;

	// negative positions aren't accepted
	if ((pos < 0 && pos != INT_MIN) || (endpos < 0 && endpos != INT_MIN)) {
		Py_RETURN_NONE;
	}

	int subject_len = strlen(subject);
	int lastindex = subject_len - 1;

	if (pos > lastindex || endpos > lastindex) {
		Py_RETURN_NONE;
	}

	// set defaults
	if (pos == INT_MIN)
		pos = 0;
	if (endpos == INT_MIN)
		endpos = lastindex;


	// length of substring
	int substring_len = endpos - pos + 1;

	// FIXME: jak spravne spocitat velikost vektoru???!!!
	int ovector_size = self->groups * 3;
	int *ovector = (int*)malloc(ovector_size * sizeof(int));
	if (ovector == NULL) {
		PyErr_SetString(PcreError, "An error when allocating the offset vector.");
		return NULL;
	}

	int rc = pcre_exec(self->re, self->study, subject, substring_len, pos, 0, ovector, ovector_size);
	if (rc < 0) {
		if (rc == PCRE_ERROR_NOMATCH)
			goto NOMATCH;

		sprintf(message_buffer, "Match execution exited with an error (code = %d).", rc);
		PyErr_SetString(PcreError, message_buffer); // TODO: rozliseni chybovych kodu
		goto ERROR;
	}

	pcre_MatchObject *match = PyObject_New(pcre_MatchObject, &pcre_MatchType);
	if (match == NULL) {
		PyErr_SetString(PcreError, "An error when allocating _pcre.MatchObject.");
		goto ERROR;
	}
	Py_INCREF(match);

	Py_INCREF(self);
	match->re = self;

	match->offsetvector = ovector;
	match->stringcount = rc;

	match->pos = pos;
	match->endpos = endpos;

	match->subject = (char *)malloc((subject_len + 1) * sizeof(char)); // +1 for '\0'
	if (match->subject == NULL) {
		PyErr_SetString(PcreError, "An error when allocating the subject.");
		goto ERROR1;
	}

	strcpy(match->subject, subject);

	return match;

NOMATCH:
	free(ovector);
	Py_RETURN_NONE;

ERROR1:
	Py_XDECREF(self);
	Py_XDECREF(match);

ERROR:
	free(ovector);

	return NULL;
}
开发者ID:jakm,项目名称:python-pcre,代码行数:90,代码来源:pcre_regex.c

示例3: BLOCK_CREATE_FROM

	BLOCK_CREATE_FROM(keydata, klen, k, k_len);
	ivdata = NULL;
	if (iv_len) BLOCK_CREATE_FROM(ivdata, len, iv, iv_len);

	cipher->ctx = CYFER_BlockCipher_Init(type, keydata, klen, mtype, ivdata);
	if (!cipher->ctx) {
		Py_DECREF(cipher);
		PyErr_SetString(PyExc_ValueError, "out of memory");
		return -1;
	}
	return 0;
}

static PyObject *new(PyTypeObject *objtype, PyObject *args, PyObject *kwargs)
{
	BlockCipherObject *obj = PyObject_New(BlockCipherObject, &BlockCipherType);

	obj->ctx = NULL;
	obj->keylen = 0;
	obj->length = 0;

	return (PyObject *) obj;
}


static PyObject *bcipher_encrypt(BlockCipherObject *self, PyObject *args)
{
	unsigned char *s, *in, *out;
	size_t s_len;

	if (!PyArg_ParseTuple(args, "s#:Encrypt", &s, &s_len)) return NULL;
开发者ID:senko,项目名称:CyFER,代码行数:31,代码来源:bcipher.c

示例4:

PyObject *py_ue_new_edgraphpin(UEdGraphPin *pin)
{
	ue_PyEdGraphPin *ret = (ue_PyEdGraphPin *)PyObject_New(ue_PyEdGraphPin, &ue_PyEdGraphPinType);
	ret->pin = pin;
	return (PyObject *)ret;
}
开发者ID:rdsgautier,项目名称:UnrealEnginePython,代码行数:6,代码来源:UEPyEdGraphPin.cpp

示例5: AerospikeNullObject_Type_New

static PyObject * AerospikeNullObject_Type_New(PyTypeObject * parent, PyObject * args, PyObject * kwds)
{
	return (PyObject *) PyObject_New(AerospikeNullObject, parent);
}
开发者ID:BeeswaxIO,项目名称:aerospike-client-python,代码行数:4,代码来源:type.c

示例6: wrap_patch

PyObject *
wrap_patch(git_patch *patch)
{
    Patch *py_patch;

    if (!patch)
        Py_RETURN_NONE;

    py_patch = PyObject_New(Patch, &PatchType);
    if (py_patch) {
        size_t i, j, hunk_amounts, lines_in_hunk, additions, deletions;
        const git_diff_delta *delta;
        const git_diff_hunk *hunk;
        const git_diff_line *line;
        int err;

        delta = git_patch_get_delta(patch);

        py_patch->old_file_path = delta->old_file.path;
        py_patch->new_file_path = delta->new_file.path;
        py_patch->status = git_diff_status_char(delta->status);
        py_patch->similarity = delta->similarity;
        py_patch->flags = delta->flags;
        py_patch->old_id = git_oid_allocfmt(&delta->old_file.id);
        py_patch->new_id = git_oid_allocfmt(&delta->new_file.id);

        git_patch_line_stats(NULL, &additions, &deletions, patch);
        py_patch->additions = additions;
        py_patch->deletions = deletions;

        hunk_amounts = git_patch_num_hunks(patch);
        py_patch->hunks = PyList_New(hunk_amounts);
        for (i = 0; i < hunk_amounts; ++i) {
            Hunk *py_hunk = NULL;

            err = git_patch_get_hunk(&hunk, &lines_in_hunk, patch, i);
            if (err < 0)
                return Error_set(err);

            py_hunk = PyObject_New(Hunk, &HunkType);
            if (py_hunk != NULL) {
                py_hunk->old_start = hunk->old_start;
                py_hunk->old_lines = hunk->old_lines;
                py_hunk->new_start = hunk->new_start;
                py_hunk->new_lines = hunk->new_lines;

                py_hunk->lines = PyList_New(lines_in_hunk);
                for (j = 0; j < lines_in_hunk; ++j) {
                    PyObject *py_line_origin = NULL, *py_line = NULL;

                    err = git_patch_get_line_in_hunk(&line, patch, i, j);
                    if (err < 0)
                        return Error_set(err);

                    py_line_origin = to_unicode_n(&line->origin, 1,
                        NULL, NULL);
                    py_line = to_unicode_n(line->content, line->content_len,
                        NULL, NULL);
                    PyList_SetItem(py_hunk->lines, j,
                        Py_BuildValue("OO", py_line_origin, py_line));

                    Py_DECREF(py_line_origin);
                    Py_DECREF(py_line);
                }

                PyList_SetItem((PyObject*) py_patch->hunks, i,
                    (PyObject*) py_hunk);
            }
        }
    }
    git_patch_free(patch);

    return (PyObject*) py_patch;
}
开发者ID:goibibo,项目名称:pygit2,代码行数:74,代码来源:diff.c

示例7: PyObject_New

static SpongeObject *alloc_sponge(void)
{
	return PyObject_New(SpongeObject, &SpongeType);
}
开发者ID:markokr,项目名称:spongeshaker,代码行数:4,代码来源:pykeccak.c

示例8: pyLODDist_FromLODDist

PyObject* pyLODDist_FromLODDist(plLODDist& dist) {
    pyLODDist* obj = PyObject_New(pyLODDist, &pyLODDist_Type);
    obj->fThis = &dist;
    return (PyObject*)obj;
}
开发者ID:GPNMilano,项目名称:libhsplasma,代码行数:5,代码来源:pyLODDist.cpp

示例9: crypto_X509Extension_New

/*
 * Constructor for X509Extension, never called by Python code directly
 *
 * Arguments: type_name - ???
 *            critical  - ???
 *            value     - ???
 *            subject   - An x509v3 certificate which is the subject for this extension.
 *            issuer    - An x509v3 certificate which is the issuer for this extension.
 * Returns:   The newly created X509Extension object
 */
crypto_X509ExtensionObj *
crypto_X509Extension_New(char *type_name, int critical, char *value,
                         crypto_X509Obj *subject, crypto_X509Obj  *issuer) {
    X509V3_CTX ctx;
    crypto_X509ExtensionObj *self;
    char* value_with_critical = NULL;


    /*
     * A context is necessary for any extension which uses the r2i conversion
     * method.  That is, X509V3_EXT_nconf may segfault if passed a NULL ctx.
     * Start off by initializing most of the fields to NULL.
     */
    X509V3_set_ctx(&ctx, NULL, NULL, NULL, NULL, 0);

    /*
     * We have no configuration database - but perhaps we should (some
     * extensions may require it).
     */
    X509V3_set_ctx_nodb(&ctx);

    /*
     * Initialize the subject and issuer, if appropriate.  ctx is a local, and
     * as far as I can tell none of the X509V3_* APIs invoked here steal any
     * references, so no need to incref subject or issuer.
     */
    if (subject) {
            ctx.subject_cert = subject->x509;
    }

    if (issuer) {
            ctx.issuer_cert = issuer->x509;
    }

    self = PyObject_New(crypto_X509ExtensionObj, &crypto_X509Extension_Type);

    if (self == NULL) {
	    goto error;
    }

    self->dealloc = 0;

    /* There are other OpenSSL APIs which would let us pass in critical
     * separately, but they're harder to use, and since value is already a pile
     * of crappy junk smuggling a ton of utterly important structured data,
     * what's the point of trying to avoid nasty stuff with strings? (However,
     * X509V3_EXT_i2d in particular seems like it would be a better API to
     * invoke.  I do not know where to get the ext_struc it desires for its
     * last parameter, though.) */
    value_with_critical = malloc(strlen("critical,") + strlen(value) + 1);
    if (!value_with_critical) {
	    goto critical_malloc_error;
    }

    if (critical) {
	    strcpy(value_with_critical, "critical,");
	    strcpy(value_with_critical + strlen("critical,"), value);
    } else {
	    strcpy(value_with_critical, value);
    }

    self->x509_extension = X509V3_EXT_nconf(
	    NULL, &ctx, type_name, value_with_critical);

    free(value_with_critical);

    if (!self->x509_extension) {
	    goto nconf_error;
    }

    self->dealloc = 1;
    return self;

  nconf_error:
    exception_from_error_queue(crypto_Error);

  critical_malloc_error:
    Py_XDECREF(self);

  error:
    return NULL;

}
开发者ID:bennbollay,项目名称:pyOpenSSL,代码行数:93,代码来源:x509ext.c

示例10:

PyObject *py_ue_new_fviewport_client(TSharedRef<FViewportClient> viewport_client)
{
	ue_PyFViewportClient *ret = (ue_PyFViewportClient *)PyObject_New(ue_PyFViewportClient, &ue_PyFViewportClientType);
	new(&ret->viewport_client) TSharedRef<FViewportClient>(viewport_client);
	return (PyObject *)ret;
}
开发者ID:20tab,项目名称:UnrealEnginePython,代码行数:6,代码来源:UEPyFViewportClient.cpp

示例11: pyLocation_FromLocation

PyObject* pyLocation_FromLocation(const plLocation& loc) {
    pyLocation* obj = PyObject_New(pyLocation, &pyLocation_Type);
    obj->fThis = new plLocation(loc);
    return (PyObject*)obj;
}
开发者ID:GPNMilano,项目名称:libhsplasma,代码行数:5,代码来源:pyLocation.cpp

示例12: GetNewPySfColor

PySfColor *
GetNewPySfColor()
{
	return PyObject_New(PySfColor, &PySfColorType);
}
开发者ID:TheMiss,项目名称:SFML,代码行数:5,代码来源:Color.cpp

示例13: srd_inst_decode

/**
 * Decode a chunk of samples.
 *
 * @param di The decoder instance to call. Must not be NULL.
 * @param start_samplenum The starting sample number for the buffer's sample
 * 			  set, relative to the start of capture.
 * @param end_samplenum The ending sample number for the buffer's sample
 * 			  set, relative to the start of capture.
 * @param inbuf The buffer to decode. Must not be NULL.
 * @param inbuflen Length of the buffer. Must be > 0.
 * @param unitsize The number of bytes per sample. Must be > 0.
 *
 * @return SRD_OK upon success, a (negative) error code otherwise.
 *
 * @private
 */
SRD_PRIV int srd_inst_decode(const struct srd_decoder_inst *di,
		uint64_t start_samplenum, uint64_t end_samplenum,
		const uint8_t *inbuf, uint64_t inbuflen, uint64_t unitsize)
{
	PyObject *py_res;
	srd_logic *logic;
	long apiver;

	/* Return an error upon unusable input. */
	if (!di) {
		srd_dbg("empty decoder instance");
		return SRD_ERR_ARG;
	}
	if (!inbuf) {
		srd_dbg("NULL buffer pointer");
		return SRD_ERR_ARG;
	}
	if (inbuflen == 0) {
		srd_dbg("empty buffer");
		return SRD_ERR_ARG;
	}
	if (unitsize == 0) {
		srd_dbg("unitsize 0");
		return SRD_ERR_ARG;
	}

	((struct srd_decoder_inst *)di)->data_unitsize = unitsize;

	srd_dbg("Decoding: start sample %" PRIu64 ", end sample %"
		PRIu64 " (%" PRIu64 " samples, %" PRIu64 " bytes, unitsize = "
		"%d), instance %s.", start_samplenum, end_samplenum,
		end_samplenum - start_samplenum, inbuflen, di->data_unitsize,
		di->inst_id);

	apiver = srd_decoder_apiver(di->decoder);

	if (apiver == 2) {
		/*
		 * Create new srd_logic object. Each iteration around the PD's
		 * loop will fill one sample into this object.
		 */
		logic = PyObject_New(srd_logic, (PyTypeObject *)srd_logic_type);
		Py_INCREF(logic);
		logic->di = (struct srd_decoder_inst *)di;
		logic->start_samplenum = start_samplenum;
		logic->itercnt = 0;
		logic->inbuf = (uint8_t *)inbuf;
		logic->inbuflen = inbuflen;
		logic->sample = PyList_New(2);
		Py_INCREF(logic->sample);

		Py_IncRef(di->py_inst);
		if (!(py_res = PyObject_CallMethod(di->py_inst, "decode",
			"KKO", start_samplenum, end_samplenum, logic))) {
			srd_exception_catch("Protocol decoder instance %s",
					di->inst_id);
			return SRD_ERR_PYTHON;
		}
		Py_DecRef(py_res);
	}

	return SRD_OK;
}
开发者ID:vpalatin,项目名称:libsigrokdecode,代码行数:79,代码来源:instance.c

示例14: PyObject_New

PyObject* cDBResult::getPyObject()
{
	wpDbResult* returnVal = PyObject_New( wpDbResult, &wpDbResultType );
	returnVal->result = this;
	return ( PyObject * ) returnVal;
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:6,代码来源:dbdriver.cpp

示例15: pyMatrix44_FromMatrix44

PyObject* pyMatrix44_FromMatrix44(const hsMatrix44& mat) {
    pyMatrix44* pmat = PyObject_New(pyMatrix44, &pyMatrix44_Type);
    pmat->fThis = new hsMatrix44(mat);
    return (PyObject*)pmat;
}
开发者ID:NadnerbD,项目名称:libhsplasma,代码行数:5,代码来源:pyMatrix44.cpp


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