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

C++ PyBytes_GET_SIZE函数代码示例

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

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



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

示例1: complex__format__

static PyObject *
complex__format__(PyObject* self, PyObject* args)
{
    PyObject *format_spec;

    if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
        return NULL;
    if (PyBytes_Check(format_spec))
        return _PyComplex_FormatAdvanced(self,
                                         PyBytes_AS_STRING(format_spec),
                                         PyBytes_GET_SIZE(format_spec));
    if (PyUnicode_Check(format_spec)) {
        /* Convert format_spec to a str */
        PyObject *result;
        PyObject *str_spec = PyObject_Str(format_spec);

        if (str_spec == NULL)
            return NULL;

        result = _PyComplex_FormatAdvanced(self,
                                           PyBytes_AS_STRING(str_spec),
                                           PyBytes_GET_SIZE(str_spec));

        Py_DECREF(str_spec);
        return result;
    }
    PyErr_SetString(PyExc_TypeError, "__format__ requires str or unicode");
    return NULL;
}
开发者ID:youseatao,项目名称:Python-2.7.8,代码行数:29,代码来源:complexobject.c


示例2: p_memcpy

static uint32_t
p_memcpy(char *dst, struct p_place *p, uint32_t amount)
{
	struct p_list *pl = p->list;
	uint32_t offset = p->offset;
	uint32_t amount_left = amount;
	char *src;
	Py_ssize_t chunk_size;

	/* Nothing to read */
	if (pl == NULL)
		return(0);

	src = (PyBytes_AS_STRING(pl->data) + offset);
	chunk_size = PyBytes_GET_SIZE(pl->data) - offset;

	while (amount_left > 0)
	{
		uint32_t this_read =
			chunk_size < amount_left ? chunk_size : amount_left;

		memcpy(dst, src, this_read);
		dst = dst + this_read;
		amount_left = amount_left - this_read;

		pl = pl->next;
		if (pl == NULL)
			break;

		src = PyBytes_AS_STRING(pl->data);
		chunk_size = PyBytes_GET_SIZE(pl->data);
	}

	return(amount - amount_left);
}
开发者ID:wchorolque,项目名称:py-postgresql,代码行数:35,代码来源:buffer.c


示例3: cxBuffer_FromObject

//-----------------------------------------------------------------------------
// cxBuffer_FromObject()
//   Populate the string buffer from a unicode object.
//-----------------------------------------------------------------------------
static int cxBuffer_FromObject(
    udt_Buffer *buf,                    // buffer to fill
    PyObject *obj,                      // object (string or Unicode object)
    const char *encoding)               // encoding to use, if applicable
{
    if (!obj)
        return cxBuffer_Init(buf);
    if (encoding && PyUnicode_Check(obj)) {
        buf->obj = PyUnicode_AsEncodedString(obj, encoding, NULL);
        if (!buf->obj)
            return -1;
        buf->ptr = PyBytes_AS_STRING(buf->obj);
        buf->size = PyBytes_GET_SIZE(buf->obj);
        buf->numCharacters = PyUnicode_GET_SIZE(obj);
    } else if (PyBytes_Check(obj)) {
        Py_INCREF(obj);
        buf->obj = obj;
        buf->ptr = PyBytes_AS_STRING(buf->obj);
        buf->size = buf->numCharacters = PyBytes_GET_SIZE(buf->obj);
#if PY_MAJOR_VERSION < 3
    } else if (PyBuffer_Check(obj)) {
        if (PyObject_AsReadBuffer(obj, &buf->ptr, &buf->size) < 0)
            return -1;
        Py_INCREF(obj);
        buf->obj = obj;
        buf->numCharacters = buf->size;
#endif
    } else {
        PyErr_SetString(PyExc_TypeError, CXORA_TYPE_ERROR);
        return -1;
    }
    return 0;
}
开发者ID:15580056814,项目名称:hue,代码行数:37,代码来源:Buffer.c


示例4: p_at_least

/*
 * p_at_least - whether the position has at least given number of bytes.
 */
static char
p_at_least(struct p_place *p, uint32_t amount)
{
	int32_t current = 0;
	struct p_list *pl;

	pl = p->list;
	if (pl)
		current += PyBytes_GET_SIZE(pl->data) - p->offset;

	if (current >= amount)
		return((char) 1);

	if (pl)
	{
		for (pl = pl->next; pl != NULL; pl = pl->next)
		{
			current += PyBytes_GET_SIZE(pl->data);
			if (current >= amount)
				return((char) 1);
		}
	}

	return((char) 0);
}
开发者ID:wchorolque,项目名称:py-postgresql,代码行数:28,代码来源:buffer.c


示例5: strxor_function

static PyObject *
strxor_function(PyObject *self, PyObject *args)
{
    PyObject *a, *b, *retval;
    Py_ssize_t len_a, len_b;

    if (!PyArg_ParseTuple(args, "SS", &a, &b))
        return NULL;

    len_a = PyBytes_GET_SIZE(a);
    len_b = PyBytes_GET_SIZE(b);

    assert(len_a >= 0);
    assert(len_b >= 0);

    if (len_a != len_b) {
        PyErr_SetString(PyExc_ValueError, "length of both strings must be equal");
        return NULL;
    }

    /* Create return string */
    retval = PyBytes_FromStringAndSize(NULL, len_a);
    if (!retval) {
        return NULL;
    }

    /* retval := a ^ b */
    xor_strings(PyBytes_AS_STRING(retval), PyBytes_AS_STRING(a), PyBytes_AS_STRING(b), len_a);

    return retval;
}
开发者ID:monnerat,项目名称:iseriespython,代码行数:31,代码来源:strxor.c


示例6: decompress

static PyObject *
decompress(Decompressor *d, uint8_t *data, size_t len)
{
    size_t data_size = 0;
    PyObject *result;

    result = PyBytes_FromStringAndSize(NULL, INITIAL_BUFFER_SIZE);
    if (result == NULL)
        return NULL;
    d->lzs.next_in = data;
    d->lzs.avail_in = len;
    d->lzs.next_out = (uint8_t *)PyBytes_AS_STRING(result);
    d->lzs.avail_out = PyBytes_GET_SIZE(result);
    for (;;) {
        lzma_ret lzret;

        Py_BEGIN_ALLOW_THREADS
        lzret = lzma_code(&d->lzs, LZMA_RUN);
        data_size = (char *)d->lzs.next_out - PyBytes_AS_STRING(result);
        Py_END_ALLOW_THREADS
        if (catch_lzma_error(lzret))
            goto error;
        if (lzret == LZMA_GET_CHECK || lzret == LZMA_NO_CHECK)
            d->check = lzma_get_check(&d->lzs);
        if (lzret == LZMA_STREAM_END) {
            d->eof = 1;
            if (d->lzs.avail_in > 0) {
                Py_CLEAR(d->unused_data);
                d->unused_data = PyBytes_FromStringAndSize(
                        (char *)d->lzs.next_in, d->lzs.avail_in);
                if (d->unused_data == NULL)
                    goto error;
            }
            break;
        } else if (d->lzs.avail_in == 0) {
            break;
        } else if (d->lzs.avail_out == 0) {
            if (grow_buffer(&result) == -1)
                goto error;
            d->lzs.next_out = (uint8_t *)PyBytes_AS_STRING(result) + data_size;
            d->lzs.avail_out = PyBytes_GET_SIZE(result) - data_size;
        }
    }
    if (data_size != (size_t)PyBytes_GET_SIZE(result))
        if (_PyBytes_Resize(&result, data_size) == -1)
            goto error;
    return result;

error:
    Py_XDECREF(result);
    return NULL;
}
开发者ID:Alex9029,项目名称:cpython,代码行数:52,代码来源:_lzmamodule.c


示例7: ghash_function

static PyObject *
ghash_function(PyObject *self, PyObject *args)
{
    PyObject *data, *y, *exp_h;
    PyObject *retval = NULL;
    Py_ssize_t len_data, len_y, len_exp_h;

    if (!PyArg_ParseTuple(args, "SSS", &data, &y, &exp_h)) {
        goto out;
    }

    len_data = PyBytes_GET_SIZE(data);
    len_y = PyBytes_GET_SIZE(y);
    len_exp_h = PyBytes_GET_SIZE(exp_h);

    if (len_data%16!=0) {
        PyErr_SetString(PyExc_ValueError, "Length of data must be a multiple of 16 bytes.");
        goto out;
    }

    if (len_y!=16) {
        PyErr_SetString(PyExc_ValueError, "Length of y must be 16 bytes.");
        goto out;
    }

    if (len_exp_h!=sizeof(t_key_tables) && len_exp_h!=16) {
        PyErr_SetString(PyExc_ValueError, "Length of expanded key is incorrect.");
        goto out;
    }

    /* Create return string */
    retval = PyBytes_FromStringAndSize(NULL, 16);
    if (!retval) {
        goto out;
    }

    Py_BEGIN_ALLOW_THREADS;

#define PyBytes_Buffer(a)   (uint8_t*)PyBytes_AS_STRING(a)

    ghash(  PyBytes_Buffer(retval), PyBytes_Buffer(data), len_data,
            PyBytes_Buffer(y),
            PyBytes_Buffer(exp_h), len_exp_h );

#undef PyBytes_Buffer

     Py_END_ALLOW_THREADS;

out:
    return retval;
}
开发者ID:Legrandin,项目名称:pycrypto,代码行数:51,代码来源:galois.c


示例8: source_as_string

// from Python/bltinmodule.c
static const char *
source_as_string(PyObject *cmd, const char *funcname, const char *what, PyCompilerFlags *cf, PyObject **cmd_copy)
{
    const char *str;
    Py_ssize_t size;
    Py_buffer view;

    *cmd_copy = NULL;
    if (PyUnicode_Check(cmd)) {
        cf->cf_flags |= PyCF_IGNORE_COOKIE;
        str = PyUnicode_AsUTF8AndSize(cmd, &size);
        if (str == NULL)
            return NULL;
    }
    else if (PyBytes_Check(cmd)) {
        str = PyBytes_AS_STRING(cmd);
        size = PyBytes_GET_SIZE(cmd);
    }
    else if (PyByteArray_Check(cmd)) {
        str = PyByteArray_AS_STRING(cmd);
        size = PyByteArray_GET_SIZE(cmd);
    }
    else if (PyObject_GetBuffer(cmd, &view, PyBUF_SIMPLE) == 0) {
        /* Copy to NUL-terminated buffer. */
        *cmd_copy = PyBytes_FromStringAndSize(
            (const char *)view.buf, view.len);
        PyBuffer_Release(&view);
        if (*cmd_copy == NULL) {
            return NULL;
        }
        str = PyBytes_AS_STRING(*cmd_copy);
        size = PyBytes_GET_SIZE(*cmd_copy);
    }
    else {
        PyErr_Format(PyExc_TypeError,
          "%s() arg 1 must be a %s object",
          funcname, what);
        return NULL;
    }

    if (strlen(str) != (size_t)size) {
        PyErr_SetString(PyExc_ValueError,
                        "source code string cannot contain null bytes");
        Py_CLEAR(*cmd_copy);
        return NULL;
    }
    return str;
}
开发者ID:Michael0x2a,项目名称:typed_ast,代码行数:49,代码来源:typed_ast.c


示例9: BYTES_ADD_INCREMENTAL

NUITKA_MAY_BE_UNUSED static bool BYTES_ADD_INCREMENTAL(PyObject **operand1, PyObject *operand2) {
    assert(PyBytes_CheckExact(*operand1));
    assert(PyBytes_CheckExact(operand2));

    // Buffer
    Py_buffer wb;
    wb.len = -1;

    if (PyObject_GetBuffer(operand2, &wb, PyBUF_SIMPLE) != 0) {
        PyErr_Format(PyExc_TypeError, "can't concat %s to %s", Py_TYPE(operand2)->tp_name, Py_TYPE(*operand1)->tp_name);

        return false;
    }

    Py_ssize_t oldsize = PyBytes_GET_SIZE(*operand1);

    if (oldsize > PY_SSIZE_T_MAX - wb.len) {
        PyErr_NoMemory();
        PyBuffer_Release(&wb);
        return false;
    }
    if (_PyBytes_Resize(operand1, oldsize + wb.len) < 0) {
        PyBuffer_Release(&wb);
        return false;
    }

    memcpy(PyBytes_AS_STRING(*operand1) + oldsize, wb.buf, wb.len);
    PyBuffer_Release(&wb);
    return true;
}
开发者ID:kayhayen,项目名称:Nuitka,代码行数:30,代码来源:HelpersOperationBinaryInplaceAdd.c


示例10: PyUnicode_CopyPreferredEncoding

int
PyUnicode_CopyPreferredEncoding(char *buffer, Py_ssize_t buffer_size)
{
	PyObject *u = NULL;
	PyObject *b = NULL;
	Py_ssize_t len;

#if (PY_MAJOR_VERSION >= 3)
	u = PyUnicode_GetPreferredEncoding();
	if (u == NULL)
		goto error;
	b = PyUnicode_AsASCIIString(u);
#else
	b = PyUnicode_GetPreferredEncoding();
#endif
	if (b == NULL)
		goto error;

	len = PyBytes_GET_SIZE(b);
	if (len >= buffer_size)
		len = buffer_size - 1;

	strncpy(buffer, PyBytes_AS_STRING(b), len);
	buffer[len] = '\0';

	Py_XDECREF(u);
	Py_DECREF(b);
	return 1;
  error:
	Py_XDECREF(u);
	Py_XDECREF(b);
	return 0;
}
开发者ID:stefanholek,项目名称:rl,代码行数:33,代码来源:unicode.c


示例11: strxor_c_function

static PyObject *
strxor_c_function(PyObject *self, PyObject *args)
{
    PyObject *s, *retval;
    int c;
    Py_ssize_t length;

    if (!PyArg_ParseTuple(args, "Si", &s, &c))
        return NULL;

    if ((c < 0) || (c > 255)) {
        PyErr_SetString(PyExc_ValueError, "c must be in range(256)");
        return NULL;
    }

    length = PyBytes_GET_SIZE(s);
    assert(length >= 0);

    /* Create return string */
    retval = PyBytes_FromStringAndSize(NULL, length);
    if (!retval) {
        return NULL;
    }

    /* retval := a ^ chr(c)*length */
    xor_string_with_char(PyBytes_AS_STRING(retval), PyBytes_AS_STRING(s), (char) c, length);

    return retval;
}
开发者ID:monnerat,项目名称:iseriespython,代码行数:29,代码来源:strxor.c


示例12: Signature_tp_iter

static PyObject *
Signature_tp_iter(PyObject *self)
{
    SignatureIter *iter = PyObject_New(SignatureIter, &SignatureIterType);
    PyObject *self_as_bytes;

    if (!iter) return NULL;

#ifdef PY3
    self_as_bytes = PyUnicode_AsUTF8String(self);
    if (!self_as_bytes) {
        Py_CLEAR(iter);
        return NULL;
    }
#else
    self_as_bytes = self;
    Py_INCREF(self_as_bytes);
#endif

    if (PyBytes_GET_SIZE(self_as_bytes) > 0) {
        iter->bytes = self_as_bytes;
        dbus_signature_iter_init(&(iter->iter),
                                 PyBytes_AS_STRING(self_as_bytes));
    }
    else {
        /* this is a null string, make a null iterator */
        iter->bytes = NULL;
        Py_CLEAR(self_as_bytes);
    }
    return (PyObject *)iter;
}
开发者ID:lichinka,项目名称:dbus-python,代码行数:31,代码来源:signature.c


示例13: _generate_regex

static int
_generate_regex(PyObject *s, void *vg)
{
    int i, count;
    gen_state_t *g = (gen_state_t *)vg;
    regex_pt_t *p;
    const char *pystr;
    unsigned int pystrlen;

    DBGN(D_GEN, "-> regex has %d parts, each generating: [", SYMOBJ(s)->data.regex.n_parts);
    for (i = 0; i < SYMOBJ(s)->data.regex.n_parts; i++) {
        p = SYMOBJ(s)->data.regex.parts + i;
        if (gen_state_hit_limit(g) || gen_state_hit_depth(g))
            count = p->min_count;
        else
            count = rnd(rnd(p->max_count - p->min_count + 1)) + p->min_count;
        if (i)
            PDBGN(D_GEN, ",");
        PDBGN(D_GEN, "%d", count);
        pystr = PyBytes_AS_STRING(p->charset);
        pystrlen = PyBytes_GET_SIZE(p->charset);
        for ( ;count > 0; count--) {
            // TODO: unicode
            if (gen_state_write(g, &pystr[rnd(pystrlen)], 1))
                return -1;
        }
    }
    PDBGN(D_GEN, "]\n");
    return 0;
}
开发者ID:blackberry,项目名称:ALF,代码行数:30,代码来源:symbol.c


示例14: dbm_contains

static int
dbm_contains(PyObject *self, PyObject *arg)
{
    dbmobject *dp = (dbmobject *)self;
    datum key, val;
    Py_ssize_t size;

    if ((dp)->di_dbm == NULL) {
        PyErr_SetString(DbmError,
                        "DBM object has already been closed");
         return -1;
    }
    if (PyUnicode_Check(arg)) {
        key.dptr = PyUnicode_AsUTF8AndSize(arg, &size);
        key.dsize = size;
        if (key.dptr == NULL)
            return -1;
    }
    else if (!PyBytes_Check(arg)) {
        PyErr_Format(PyExc_TypeError,
                     "dbm key must be bytes or string, not %.100s",
                     arg->ob_type->tp_name);
        return -1;
    }
    else {
        key.dptr = PyBytes_AS_STRING(arg);
        key.dsize = PyBytes_GET_SIZE(arg);
    }
    val = dbm_fetch(dp->di_dbm, key);
    return val.dptr != NULL;
}
开发者ID:Martiusweb,项目名称:cpython,代码行数:31,代码来源:_dbmmodule.c


示例15: fixIndex

PyObjectHandle LuaToPythonConverter::convertToUnicode(lua_State* L, int index) {
  fixIndex(L, index);

  if (auto ref = getOpaqueRef(L, index)) {
    // Must convert to a Python unicode object.
    if (PyBytes_Check(ref->obj.get())) {
      char* data = PyBytes_AS_STRING(ref->obj.get());
      Py_ssize_t len = PyBytes_GET_SIZE(ref->obj.get());
      PyObjectHandle obj(PyUnicode_DecodeUTF8(data, len, "strict"));
      checkPythonError(obj, L, "convertToUnicode(bytes)");
      return obj;
    } else if (PyUnicode_Check(ref->obj.get())) {
      return ref->obj;
    } else {
      luaL_error(L, "neither bytes nor unicode");
    }
  }

  int type = lua_type(L, index);
  if (type != LUA_TSTRING) {
    luaL_error(L, "Invalid type for convertToUnicode: %d", type);
  }

  size_t len;
  const char* str = lua_tolstring(L, index, &len);
  PyObjectHandle obj(PyUnicode_DecodeUTF8(str, len, "strict"));
  checkPythonError(obj, L, "convertToUnicdoe");
  return obj;
}
开发者ID:SalemAmeen,项目名称:fblualib,代码行数:29,代码来源:LuaToPython.cpp


示例16: resize_buffer

/* Internal routine for changing the size of the buffer of BytesIO objects.
   The caller should ensure that the 'size' argument is non-negative.  Returns
   0 on success, -1 otherwise. */
static int
resize_buffer(bytesio *self, size_t size)
{
    /* Here, unsigned types are used to avoid dealing with signed integer
       overflow, which is undefined in C. */
    size_t alloc = PyBytes_GET_SIZE(self->buf);

    assert(self->buf != NULL);

    /* For simplicity, stay in the range of the signed type. Anyway, Python
       doesn't allow strings to be longer than this. */
    if (size > PY_SSIZE_T_MAX)
        goto overflow;

    if (size < alloc / 2) {
        /* Major downsize; resize down to exact size. */
        alloc = size + 1;
    }
    else if (size < alloc) {
        /* Within allocated size; quick exit */
        return 0;
    }
    else if (size <= alloc * 1.125) {
        /* Moderate upsize; overallocate similar to list_resize() */
        alloc = size + (size >> 3) + (size < 9 ? 3 : 6);
    }
开发者ID:denfromufa,项目名称:cpython,代码行数:29,代码来源:bytesio.c


示例17: append_signature_bits

static int
append_signature_bits(struct ccn_charbuf *signature,
		PyObject *py_obj_Signature)
{
	PyObject *py_signatureBits = NULL;
	const char *blob;
	Py_ssize_t blobsize;
	int r;

	if (!PyObject_HasAttrString(py_obj_Signature, "signatureBits"))
		return 0;

	py_signatureBits = PyObject_GetAttrString(py_obj_Signature,
			"signatureBits");
	JUMP_IF_NULL(py_signatureBits, error);

	if (py_signatureBits != Py_None) {
		blob = PyBytes_AsString(py_signatureBits);
		JUMP_IF_NULL(blob, error);
		blobsize = PyBytes_GET_SIZE(py_signatureBits);

		r = ccnb_append_tagged_blob(signature, CCN_DTAG_SignatureBits, blob,
				blobsize);
		JUMP_IF_NEG_MEM(r, error);
	}
	Py_DECREF(py_signatureBits);

	return 0;

error:
	Py_XDECREF(py_signatureBits);
	return -1;
}
开发者ID:Emat12,项目名称:PyCCN,代码行数:33,代码来源:methods_signature.c


示例18: _winapi_Overlapped_GetOverlappedResult_impl

static PyObject *
_winapi_Overlapped_GetOverlappedResult_impl(OverlappedObject *self, int wait)
/*[clinic end generated code: output=bdd0c1ed6518cd03 input=194505ee8e0e3565]*/
{
    BOOL res;
    DWORD transferred = 0;
    DWORD err;

    Py_BEGIN_ALLOW_THREADS
    res = GetOverlappedResult(self->handle, &self->overlapped, &transferred,
                              wait != 0);
    Py_END_ALLOW_THREADS

    err = res ? ERROR_SUCCESS : GetLastError();
    switch (err) {
        case ERROR_SUCCESS:
        case ERROR_MORE_DATA:
        case ERROR_OPERATION_ABORTED:
            self->completed = 1;
            self->pending = 0;
            break;
        case ERROR_IO_INCOMPLETE:
            break;
        default:
            self->pending = 0;
            return PyErr_SetExcFromWindowsErr(PyExc_IOError, err);
    }
    if (self->completed && self->read_buffer != NULL) {
        assert(PyBytes_CheckExact(self->read_buffer));
        if (transferred != PyBytes_GET_SIZE(self->read_buffer) &&
            _PyBytes_Resize(&self->read_buffer, transferred))
            return NULL;
    }
    return Py_BuildValue("II", (unsigned) transferred, (unsigned) err);
}
开发者ID:Daetalus,项目名称:cpython,代码行数:35,代码来源:_winapi.c


示例19: qWarning

QDataStream &operator<<(QDataStream& out, const PyObjectWrapper& myObj)
{
    if (Py_IsInitialized() == 0) {
        qWarning() << "Stream operator for PyObject called without python interpreter.";
        return out;
    }

    static PyObject *reduce_func  = 0;

    Shiboken::GilState gil;
    if (!reduce_func) {
        Shiboken::AutoDecRef pickleModule(PyImport_ImportModule("pickle"));
        reduce_func = PyObject_GetAttrString(pickleModule, "dumps");
    }
    Shiboken::AutoDecRef repr(PyObject_CallFunctionObjArgs(reduce_func, (PyObject*)myObj, NULL));
    if (repr.object()) {
        const char* buff = 0;
        Py_ssize_t size  = 0;
        if (PyBytes_Check(repr.object())) {
            buff = PyBytes_AS_STRING(repr.object());
            size = PyBytes_GET_SIZE(repr.object());
        } else if (Shiboken::String::check(repr.object())) {
            buff = Shiboken::String::toCString(repr.object());
            size = Shiboken::String::len(repr.object());
        }
        QByteArray data(buff, size);
        out << data;
    }
    return out;
}
开发者ID:Hasimir,项目名称:PySide,代码行数:30,代码来源:signalmanager.cpp


示例20: __Pyx__PyObject_Ord

static long __Pyx__PyObject_Ord(PyObject* c) {
    Py_ssize_t size;
    if (PyBytes_Check(c)) {
        size = PyBytes_GET_SIZE(c);
        if (likely(size == 1)) {
            return (unsigned char) PyBytes_AS_STRING(c)[0];
        }
#if PY_MAJOR_VERSION < 3
    } else if (PyUnicode_Check(c)) {
        return (long)__Pyx_PyUnicode_AsPy_UCS4(c);
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    } else if (PyByteArray_Check(c)) {
        size = PyByteArray_GET_SIZE(c);
        if (likely(size == 1)) {
            return (unsigned char) PyByteArray_AS_STRING(c)[0];
        }
#endif
    } else {
        // FIXME: support character buffers - but CPython doesn't support them either
        PyErr_Format(PyExc_TypeError,
            "ord() expected string of length 1, but %.200s found", c->ob_type->tp_name);
        return (long)(Py_UCS4)-1;
    }
    PyErr_Format(PyExc_TypeError,
        "ord() expected a character, but string of length %zd found", size);
    return (long)(Py_UCS4)-1;
}
开发者ID:13steinj,项目名称:cython,代码行数:28,代码来源:Builtins.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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