本文整理汇总了C++中PyBytes_Size函数的典型用法代码示例。如果您正苦于以下问题:C++ PyBytes_Size函数的具体用法?C++ PyBytes_Size怎么用?C++ PyBytes_Size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyBytes_Size函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: PyUnicode_AsASCIIString
static char *GetString( PyObject *value ) {
/*
* Name:
* GetString
* Purpose:
* Get a pointer to a null terminated string from a PyObject.
* It should be freed by the caller.
* Stolen from pyast
*/
char *result = NULL;
if( value && value != Py_None ) {
#ifdef USE_PY3K
PyObject *bytes = PyUnicode_AsASCIIString(value);
#else
PyObject *bytes = value;
#endif
if( bytes ) {
size_t nbytes = PyBytes_Size( bytes );
const char * bytestr = PyBytes_AS_STRING(bytes);
result = malloc( (nbytes+1) * sizeof(*result));
strcpy( result, bytestr );
#ifdef USE_PY3K
Py_DECREF(bytes);
#endif
}
}
return result;
}
开发者ID:timj,项目名称:starlink-pyndf,代码行数:31,代码来源:ndf.c
示例2: OnSysRead
size_t OnSysRead(void *buffer, size_t bufsize)
{
if (bufsize == 0)
return 0;
wxPyThreadBlocker blocker;
PyObject* arglist = Py_BuildValue("(i)", bufsize);
PyObject* result = PyEval_CallObject(m_read, arglist);
Py_DECREF(arglist);
size_t o = 0;
if ((result != NULL) && PyBytes_Check(result)) {
o = PyBytes_Size(result);
if (o == 0)
m_lasterror = wxSTREAM_EOF;
if (o > bufsize)
o = bufsize;
memcpy((char*)buffer, PyBytes_AsString(result), o); // strings only, not unicode...
Py_DECREF(result);
}
else
m_lasterror = wxSTREAM_READ_ERROR;
return o;
}
开发者ID:KenTsui,项目名称:Phoenix,代码行数:25,代码来源:stream_input.cpp
示例3: match
/* Given the contents of a .py[co] file in a buffer, unmarshal the data
and return the code object. Return None if it the magic word doesn't
match (we do this instead of raising an exception as we fall back
to .py if available and we don't want to mask other errors).
Returns a new reference. */
static PyObject *
unmarshal_code(char *pathname, PyObject *data)
{
PyObject *code;
char *buf = PyBytes_AsString(data);
Py_ssize_t size = PyBytes_Size(data);
if (size <= 9) {
PyErr_SetString(PyExc_TypeError,
"bad pyc data");
return NULL;
}
if (get_long((unsigned char *)buf) != PyImport_GetMagicNumber()) {
if (Py_VerboseFlag)
PySys_WriteStderr("# %s has bad magic\n",
pathname);
Py_INCREF(Py_None);
return NULL;
}
code = PyMarshal_ReadObjectFromString(buf + 8, size - 8);
if (code == NULL)
return NULL;
if (!PyCode_Check(code)) {
Py_DECREF(code);
PyErr_Format(PyExc_TypeError,
"compiled module %.200s is not a code object",
pathname);
return NULL;
}
return code;
}
开发者ID:khertan,项目名称:pyotherside,代码行数:38,代码来源:qpython_priv.cpp
示例4: Py_INCREF
static PyObject *dash_getpowhash(PyObject *self, PyObject *args)
{
char *output;
PyObject *value;
#if PY_MAJOR_VERSION >= 3
PyBytesObject *input;
#else
PyStringObject *input;
#endif
if (!PyArg_ParseTuple(args, "S", &input))
return NULL;
Py_INCREF(input);
output = PyMem_Malloc(32);
#if PY_MAJOR_VERSION >= 3
dash_hash((char *)PyBytes_AsString((PyObject*) input), (int)PyBytes_Size((PyObject*) input), output);
#else
dash_hash((char *)PyString_AsString((PyObject*) input), (int)PyString_Size((PyObject*) input), output);
#endif
Py_DECREF(input);
#if PY_MAJOR_VERSION >= 3
value = Py_BuildValue("y#", output, 32);
#else
value = Py_BuildValue("s#", output, 32);
#endif
PyMem_Free(output);
return value;
}
开发者ID:dashpay,项目名称:dash_hash,代码行数:28,代码来源:dashmodule.c
示例5: Rlite_init
static int Rlite_init(hirlite_RliteObject *self, PyObject *args, PyObject *kwds) {
static char *kwlist[] = { "path", "encoding", NULL };
PyObject *encodingObj = NULL;
char *path = ":memory:";
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|sO", kwlist, &path, &encodingObj))
return -1;
if (encodingObj) {
PyObject *encbytes;
char *encstr;
Py_ssize_t enclen;
if (PyUnicode_Check(encodingObj))
encbytes = PyUnicode_AsASCIIString(encodingObj);
else
encbytes = PyObject_Bytes(encodingObj);
if (encbytes == NULL)
return -1;
enclen = PyBytes_Size(encbytes);
encstr = PyBytes_AsString(encbytes);
self->encoding = (char*)malloc(enclen+1);
memcpy(self->encoding, encstr, enclen);
self->encoding[enclen] = '\0';
Py_DECREF(encbytes);
}
self->context = rliteConnect(path, 0);
return 0;
}
开发者ID:miedzinski,项目名称:rlite-py,代码行数:33,代码来源:rlite.c
示例6: chunker_fill
static int
chunker_fill(Chunker *c)
{
size_t n;
memmove(c->data, c->data + c->last, c->position + c->remaining - c->last);
c->position -= c->last;
c->last = 0;
n = c->buf_size - c->position - c->remaining;
if(c->eof || n == 0) {
return 1;
}
PyObject *data = PyObject_CallMethod(c->fd, "read", "i", n);
if(!data) {
return 0;
}
n = PyBytes_Size(data);
if(n) {
memcpy(c->data + c->position + c->remaining, PyBytes_AsString(data), n);
c->remaining += n;
c->bytes_read += n;
}
else {
c->eof = 1;
}
Py_DECREF(data);
return 1;
}
开发者ID:Ernest0x,项目名称:attic,代码行数:27,代码来源:_chunker.c
示例7: chunker_fill
static int
chunker_fill(Chunker *c)
{
ssize_t n;
size_t offset, length;
PyObject *data;
memmove(c->data, c->data + c->last, c->position + c->remaining - c->last);
c->position -= c->last;
c->last = 0;
n = c->buf_size - c->position - c->remaining;
if(c->eof || n == 0) {
return 1;
}
if(c->fh >= 0) {
offset = c->bytes_read;
// if we have a os-level file descriptor, use os-level API
n = read(c->fh, c->data + c->position + c->remaining, n);
if(n > 0) {
c->remaining += n;
c->bytes_read += n;
}
else
if(n == 0) {
c->eof = 1;
}
else {
// some error happened
return 0;
}
length = c->bytes_read - offset;
#if ( _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L )
// We tell the OS that we do not need the data that we just have read any
// more (that it maybe has in the cache). This avoids that we spoil the
// complete cache with data that we only read once and (due to cache
// size limit) kick out data from the cache that might be still useful
// for the OS or other processes.
if (length > 0) {
posix_fadvise(c->fh, (off_t) offset, (off_t) length, POSIX_FADV_DONTNEED);
}
#endif
}
else {
// no os-level file descriptor, use Python file object API
data = PyObject_CallMethod(c->fd, "read", "i", n);
if(!data) {
return 0;
}
n = PyBytes_Size(data);
if(n) {
memcpy(c->data + c->position + c->remaining, PyBytes_AsString(data), n);
c->remaining += n;
c->bytes_read += n;
}
else {
c->eof = 1;
}
Py_DECREF(data);
}
return 1;
}
开发者ID:pieViks,项目名称:borg,代码行数:60,代码来源:_chunker.c
示例8: mmap_ass_item
static int
mmap_ass_item(mmap_object *self, Py_ssize_t i, PyObject *v)
{
const char *buf;
CHECK_VALID(-1);
if (i < 0 || i >= self->size) {
PyErr_SetString(PyExc_IndexError, "mmap index out of range");
return -1;
}
if (v == NULL) {
PyErr_SetString(PyExc_TypeError,
"mmap object doesn't support item deletion");
return -1;
}
if (! (PyBytes_Check(v) && PyBytes_Size(v)==1) ) {
PyErr_SetString(PyExc_IndexError,
"mmap assignment must be length-1 bytes()");
return -1;
}
if (!is_writable(self))
return -1;
buf = PyBytes_AsString(v);
self->data[i] = buf[0];
return 0;
}
开发者ID:1st1,项目名称:cpython,代码行数:26,代码来源:mmapmodule.c
示例9: vm_set_mem
PyObject *
vm_set_mem(JitCpu *self, PyObject *args) {
PyObject *py_addr;
PyObject *py_buffer;
Py_ssize_t py_length;
char *buffer;
Py_ssize_t pysize;
uint64_t addr;
int ret = 0x1337;
if (!PyArg_ParseTuple(args, "OO", &py_addr, &py_buffer))
return NULL;
PyGetInt_uint64_t(py_addr, addr);
if(!PyBytes_Check(py_buffer))
RAISE(PyExc_TypeError,"arg must be bytes");
pysize = PyBytes_Size(py_buffer);
if (pysize < 0) {
RAISE(PyExc_TypeError,"Python error");
}
PyBytes_AsStringAndSize(py_buffer, &buffer, &py_length);
ret = vm_write_mem(&(((VmMngr*)self->pyvm)->vm_mngr), addr, buffer, pysize);
if (ret < 0)
RAISE(PyExc_TypeError,"arg must be str");
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:cea-sec,项目名称:miasm,代码行数:32,代码来源:JitCore_ppc32.c
示例10: init_locale_info
// Initialize the global decimal character and thousands separator character, used when parsing decimal
// objects.
//
static void init_locale_info()
{
Object module(PyImport_ImportModule("locale"));
if (!module)
{
PyErr_Clear();
return;
}
Object ldict(PyObject_CallMethod(module, "localeconv", 0));
if (!ldict)
{
PyErr_Clear();
return;
}
PyObject* value = PyDict_GetItemString(ldict, "decimal_point");
if (value)
{
if (PyBytes_Check(value) && PyBytes_Size(value) == 1)
chDecimal = (Py_UNICODE)PyBytes_AS_STRING(value)[0];
if (PyUnicode_Check(value) && PyUnicode_GET_SIZE(value) == 1)
chDecimal = PyUnicode_AS_UNICODE(value)[0];
}
}
开发者ID:skillian,项目名称:pyodbc,代码行数:28,代码来源:pyodbcmodule.cpp
示例11: vm_set_mem
PyObject* vm_set_mem(VmMngr* self, PyObject* args)
{
PyObject *py_addr;
PyObject *py_buffer;
Py_ssize_t py_length;
char * buffer;
Py_ssize_t pysize;
uint64_t addr;
int ret;
if (!PyArg_ParseTuple(args, "OO", &py_addr, &py_buffer))
RAISE(PyExc_TypeError,"Cannot parse arguments");
PyGetInt_uint64_t(py_addr, addr);
if (!PyBytes_Check(py_buffer))
RAISE(PyExc_TypeError,"arg must be bytes");
pysize = PyBytes_Size(py_buffer);
if (pysize < 0) {
RAISE(PyExc_TypeError,"Python error");
}
PyBytes_AsStringAndSize(py_buffer, &buffer, &py_length);
ret = vm_write_mem(&self->vm_mngr, addr, buffer, pysize);
if (ret < 0)
RAISE(PyExc_TypeError, "Error in set_mem");
add_mem_write(&self->vm_mngr, addr, (size_t)pysize);
check_invalid_code_blocs(&self->vm_mngr);
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:cea-sec,项目名称:miasm,代码行数:35,代码来源:vm_mngr_py.c
示例12: setstate
static void setstate(IM& im, const object & state) {
if(!PyBytes_Check(state.ptr()))
throw std::invalid_argument("Failed to unpickle, unexpected type!");
const int N = im.W()*im.H()*im.C()*sizeof(value_type);
if( PyBytes_Size(state.ptr()) != N )
throw std::invalid_argument("Failed to unpickle, unexpected size!");
memcpy( im.data(), PyBytes_AS_STRING(state.ptr()), N );
}
开发者ID:CUAir,项目名称:edges,代码行数:8,代码来源:imgproc.cpp
示例13: np_char
static int
np_char(char *p, PyObject *v, const formatdef *f)
{
if (!PyBytes_Check(v) || PyBytes_Size(v) != 1) {
PyErr_SetString(StructError,
"char format requires a bytes object of length 1");
return -1;
}
*p = *PyBytes_AsString(v);
return 0;
}
开发者ID:sys-git,项目名称:pyopencl,代码行数:11,代码来源:_pvt_struct_v3.cpp
示例14: PyUnicode_FromString
static PyObject *_internal_stream_load(PyObject *args, unsigned int blocking)
{
PyObject *decoder = NULL;
PyObject *stream = NULL;
PyObject *buffer = NULL;
PyObject *result = NULL;
#ifdef IS_PYTHON3
PyObject *bufferstring = NULL;
#endif
if (!PyArg_ParseTuple(args, "O", &stream)) {
goto bad_type;
}
if (__read == NULL) {
__read = PyUnicode_FromString("read");
}
if (!PyObject_HasAttr(stream, __read)) {
goto bad_type;
}
buffer = PyObject_CallMethodObjArgs(stream, __read, NULL);
if (!buffer)
return NULL;
#ifdef IS_PYTHON3
bufferstring = PyUnicode_AsUTF8String(buffer);
if (!bufferstring)
return NULL;
#endif
decoder = PyObject_Call((PyObject *)(&YajlDecoderType), NULL, NULL);
if (decoder == NULL) {
return NULL;
}
#ifdef IS_PYTHON3
result = _internal_decode((_YajlDecoder *)decoder, PyBytes_AsString(bufferstring),
PyBytes_Size(bufferstring));
Py_XDECREF(bufferstring);
#else
result = _internal_decode((_YajlDecoder *)decoder, PyString_AsString(buffer),
PyString_Size(buffer));
#endif
Py_XDECREF(decoder);
Py_XDECREF(buffer);
return result;
bad_type:
PyErr_SetObject(PyExc_TypeError, PyUnicode_FromString("Must pass a single stream object"));
return NULL;
}
开发者ID:cigor,项目名称:py-yajl,代码行数:54,代码来源:yajl.c
示例15: vm_add_memory_page
PyObject* vm_add_memory_page(VmMngr* self, PyObject* args)
{
PyObject *addr;
PyObject *access;
PyObject *item_str;
PyObject *name=NULL;
uint64_t buf_size;
size_t buf_size_st;
char* buf_data;
Py_ssize_t length;
uint64_t page_addr;
uint64_t page_access;
const char *name_ptr;
struct memory_page_node * mpn;
if (!PyArg_ParseTuple(args, "OOO|O", &addr, &access, &item_str, &name))
RAISE(PyExc_TypeError,"Cannot parse arguments");
PyGetInt_uint64_t(addr, page_addr);
PyGetInt_uint64_t(access, page_access);
if(!PyBytes_Check(item_str))
RAISE(PyExc_TypeError,"arg must be bytes");
buf_size = PyBytes_Size(item_str);
PyBytes_AsStringAndSize(item_str, &buf_data, &length);
if (name == NULL) {
name_ptr = (char*)"";
} else {
PyGetStr(name_ptr, name);
}
mpn = create_memory_page_node(page_addr, (unsigned int)buf_size, (unsigned int)page_access, name_ptr);
if (mpn == NULL)
RAISE(PyExc_TypeError,"cannot create page");
if (is_mpn_in_tab(&self->vm_mngr, mpn)) {
free(mpn->ad_hp);
free(mpn);
RAISE(PyExc_TypeError,"known page in memory");
}
if (buf_size > SIZE_MAX) {
fprintf(stderr, "Size too big\n");
exit(EXIT_FAILURE);
}
buf_size_st = (size_t) buf_size;
memcpy(mpn->ad_hp, buf_data, buf_size_st);
add_memory_page(&self->vm_mngr, mpn);
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:cea-sec,项目名称:miasm,代码行数:54,代码来源:vm_mngr_py.c
示例16: match
/* Given the contents of a .pyc file in a buffer, unmarshal the data
and return the code object. Return None if it the magic word doesn't
match (we do this instead of raising an exception as we fall back
to .py if available and we don't want to mask other errors).
Returns a new reference. */
static PyObject *
unmarshal_code(PyObject *pathname, PyObject *data, time_t mtime)
{
PyObject *code;
unsigned char *buf = (unsigned char *)PyBytes_AsString(data);
Py_ssize_t size = PyBytes_Size(data);
if (size < 16) {
PyErr_SetString(ZipImportError,
"bad pyc data");
return NULL;
}
if (get_uint32(buf) != (unsigned int)PyImport_GetMagicNumber()) {
if (Py_VerboseFlag) {
PySys_FormatStderr("# %R has bad magic\n",
pathname);
}
Py_RETURN_NONE; /* signal caller to try alternative */
}
uint32_t flags = get_uint32(buf + 4);
if (flags != 0) {
// Hash-based pyc. We currently refuse to handle checked hash-based
// pycs. We could validate hash-based pycs against the source, but it
// seems likely that most people putting hash-based pycs in a zipfile
// will use unchecked ones.
if (strcmp(_Py_CheckHashBasedPycsMode, "never") &&
(flags != 0x1 || !strcmp(_Py_CheckHashBasedPycsMode, "always")))
Py_RETURN_NONE;
} else if ((mtime != 0 && !eq_mtime(get_uint32(buf + 8), mtime))) {
if (Py_VerboseFlag) {
PySys_FormatStderr("# %R has bad mtime\n",
pathname);
}
Py_RETURN_NONE; /* signal caller to try alternative */
}
/* XXX the pyc's size field is ignored; timestamp collisions are probably
unimportant with zip files. */
code = PyMarshal_ReadObjectFromString((char *)buf + 16, size - 16);
if (code == NULL) {
return NULL;
}
if (!PyCode_Check(code)) {
Py_DECREF(code);
PyErr_Format(PyExc_TypeError,
"compiled module %R is not a code object",
pathname);
return NULL;
}
return code;
}
开发者ID:1st1,项目名称:cpython,代码行数:58,代码来源:zipimport.c
示例17: get_bytes_or_bytearray_ln
int get_bytes_or_bytearray_ln(bp::object buf)
{
PyObject *py_ba;
py_ba = buf.ptr();
if (PyByteArray_Check(py_ba))
return PyByteArray_Size(py_ba);
else if (PyBytes_Check(py_ba))
return PyBytes_Size(py_ba);
else
throw_ba_exception();
return 0;
}
开发者ID:TMRh20,项目名称:RF24,代码行数:12,代码来源:pyRF24Network.cpp
示例18: AE_GetOSType
/* Convert a 4-char string object argument to an OSType value */
int AE_GetOSType(PyObject *v, OSType *pr)
{
uint32_t tmp;
if (!PyBytes_Check(v) || PyBytes_Size(v) != 4) {
PyErr_SetString(PyExc_TypeError,
"OSType arg must be a bytes object, 4 bytes in length.");
return 0;
}
memcpy((char *)&tmp, PyBytes_AsString(v), 4);
*pr = (OSType)CFSwapInt32HostToBig(tmp);
return 1;
}
开发者ID:AdminCNP,项目名称:appscript,代码行数:13,代码来源:ae.c
示例19: rpmts_Match
static PyObject *
rpmts_Match(rpmtsObject * s, PyObject * args, PyObject * kwds)
{
PyObject *Key = NULL;
PyObject *str = NULL;
PyObject *mio = NULL;
char *key = NULL;
/* XXX lkey *must* be a 32 bit integer, int "works" on all known platforms. */
int lkey = 0;
int len = 0;
rpmDbiTagVal tag = RPMDBI_PACKAGES;
char * kwlist[] = {"tagNumber", "key", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O:Match", kwlist,
tagNumFromPyObject, &tag, &Key))
return NULL;
if (Key) {
if (PyInt_Check(Key)) {
lkey = PyInt_AsLong(Key);
key = (char *)&lkey;
len = sizeof(lkey);
} else if (PyLong_Check(Key)) {
lkey = PyLong_AsLong(Key);
key = (char *)&lkey;
len = sizeof(lkey);
} else if (utf8FromPyObject(Key, &str)) {
key = PyBytes_AsString(str);
len = PyBytes_Size(str);
} else {
PyErr_SetString(PyExc_TypeError, "unknown key type");
return NULL;
}
/* One of the conversions above failed, exception is set already */
if (PyErr_Occurred()) goto exit;
}
/* XXX If not already opened, open the database O_RDONLY now. */
/* XXX FIXME: lazy default rdonly open also done by rpmtsInitIterator(). */
if (rpmtsGetRdb(s->ts) == NULL) {
int rc = rpmtsOpenDB(s->ts, O_RDONLY);
if (rc || rpmtsGetRdb(s->ts) == NULL) {
PyErr_SetString(pyrpmError, "rpmdb open failed");
goto exit;
}
}
mio = rpmmi_Wrap(&rpmmi_Type, rpmtsInitIterator(s->ts, tag, key, len), (PyObject*)s);
exit:
Py_XDECREF(str);
return mio;
}
开发者ID:Conan-Kudo,项目名称:rpm,代码行数:53,代码来源:rpmts-py.c
示例20: PLyObject_ToDatum
/*
* Generic conversion function: Convert PyObject to cstring and
* cstring into PostgreSQL type.
*/
static Datum
PLyObject_ToDatum(PLyObToDatum *arg, int32 typmod, PyObject *plrv)
{
PyObject *volatile plrv_bo = NULL;
Datum rv;
Assert(plrv != Py_None);
if (PyUnicode_Check(plrv))
plrv_bo = PLyUnicode_Bytes(plrv);
else
{
#if PY_MAJOR_VERSION >= 3
PyObject *s = PyObject_Str(plrv);
plrv_bo = PLyUnicode_Bytes(s);
Py_XDECREF(s);
#else
plrv_bo = PyObject_Str(plrv);
#endif
}
if (!plrv_bo)
PLy_elog(ERROR, "could not create string representation of Python object");
PG_TRY();
{
char *plrv_sc = PyBytes_AsString(plrv_bo);
size_t plen = PyBytes_Size(plrv_bo);
size_t slen = strlen(plrv_sc);
if (slen < plen)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("could not convert Python object into cstring: Python string representation appears to contain null bytes")));
else if (slen > plen)
elog(ERROR, "could not convert Python object into cstring: Python string longer than reported length");
pg_verifymbstr(plrv_sc, slen, false);
rv = InputFunctionCall(&arg->typfunc,
plrv_sc,
arg->typioparam,
typmod);
}
PG_CATCH();
{
Py_XDECREF(plrv_bo);
PG_RE_THROW();
}
PG_END_TRY();
Py_XDECREF(plrv_bo);
return rv;
}
开发者ID:AllenDou,项目名称:postgresql,代码行数:57,代码来源:plpy_typeio.c
注:本文中的PyBytes_Size函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论