Beispiel #1
0
/*	Initializing UniqueList. */
static int
UniqueList_init(UniqueList *self, PyObject *args, PyObject *kwds) {
	Py_ssize_t i;
	PyObject *tmp;
	PyObject *item, *obj = NULL;

	if (!PyArg_ParseTuple(args, "|O", &obj))
	        return -1;

	/* Checking, that the argument is containing unique values. */
	if (obj != NULL) {
	    tmp = get_lowercase_tuple(obj);
		for (i = 0; i < Py_SIZE(tmp); i++) {
			item = PyTuple_GetItem(tmp, i);
			if (item == NULL) return -1;

			if (PySequence_Count(tmp, item) > 1) {
				Py_DECREF(tmp);
				PyErr_SetString(PyExc_AttributeError, "UniqueList's argument is containing non-unique values. (Bool types converted to number)");
				return -1;
			}
		}
		Py_DECREF(tmp);
	}
	if (PyList_Type.tp_init((PyObject *)self, args, kwds) < 0)
		return -1;
	return 0;
}
Beispiel #2
0
static PyObject *t_sequence_count(t_sequence *self, PyObject *value)
{
    int count;

    if (self->itemvalue.flags & V_PURE)
        count = PySequence_Count(self->sequence, value);
    else
    {
        value = _useValue(self, value);
        if (!value)
            return NULL;

        count = PySequence_Count(self->sequence, value);
        Py_DECREF(value);
    }

    if (count < 0)
        return NULL;

    return PyInt_FromLong(count);
}
 int List::count(const Object &obj) const
 {
     return PySequence_Count(mPtr, obj.borrowReference());
 }