本文整理汇总了C++中PyString_AsStringAndSize函数的典型用法代码示例。如果您正苦于以下问题:C++ PyString_AsStringAndSize函数的具体用法?C++ PyString_AsStringAndSize怎么用?C++ PyString_AsStringAndSize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyString_AsStringAndSize函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: libvirt_charPtrSizeUnwrap
int libvirt_charPtrSizeUnwrap(PyObject *obj, char **str, Py_ssize_t *size)
{
int ret;
#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 4
int isize;
#endif
*str = NULL;
*size = 0;
if (!obj) {
PyErr_SetString(PyExc_TypeError, "unexpected type");
return -1;
}
#if PY_MAJOR_VERSION > 2
ret = PyBytes_AsStringAndSize(obj, str, size);
#else
# if PY_MINOR_VERSION <= 4
ret = PyString_AsStringAndSize(obj, str, &isize);
*size = isize;
# else
ret = PyString_AsStringAndSize(obj, str, size);
# endif
#endif
return ret;
}
开发者ID:ISI-apex,项目名称:libvirt-ARM,代码行数:26,代码来源:typewrappers.c
示例2: c_set_instance
static PyObject *
c_set_instance(PyObject *self, PyObject *args, PyObject *kwargs)
{
struct pack *p;
int ret;
PyObject *key, *value;
char *str;
size_t strlen;
int pos = 0;
proc_check_shutdown();
p = pack_new(512);
if (!p) return NULL;
while(PyDict_Next(kwargs, &pos, &key, &value)) {
PyString_AsStringAndSize(key, &str, &strlen);
pack_put(p, str, strlen);
PyString_AsStringAndSize(value, &str, &strlen);
pack_put(p, str, strlen);
}
ret = db_put_profile(bk_node, bk_app, p);
if (ret != 0) return NULL;
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:Tayyib,项目名称:uludag,代码行数:28,代码来源:csl.c
示例3: KyotoDB_dump
static std::string
KyotoDB_dump(PyObject *obj, bool use_pickle, bool *ok)
{
*ok = false;
if (use_pickle) {
APR pydata(PyObject_CallFunctionObjArgs(pickle_dumps, obj, NULL));
if (PyErr_Occurred() != NULL)
return "";
char *buffer;
Py_ssize_t size;
if (PyString_AsStringAndSize(pydata, &buffer, &size) < 0) {
return "";
}
*ok = true;
return std::string(buffer, size);
} else {
char *buffer;
Py_ssize_t size;
if (PyString_AsStringAndSize(obj, &buffer, &size) < 0) {
return "";
}
*ok = true;
return std::string(buffer, size);
}
}
开发者ID:informationsea,项目名称:Yet-Another-Kyoto-Cabinet-Python-Binding,代码行数:26,代码来源:yakc.cpp
示例4: th_brk_
static PyObject*
th_brk_(PyObject *self, PyObject *args)
{
PyObject *result = NULL;
Py_UNICODE *s1;
int s1_len;
if (!PyArg_ParseTuple(args, "u#", &s1, &s1_len)) {
PyErr_SetString(PyExc_TypeError, "parameter must be unicode");
return NULL;
}
if(s1_len == 0) {
PyErr_SetString(PyExc_ValueError, "parameter must not be empty string");
return NULL;
}
PyObject *txt_cp874 = PyUnicode_Encode(s1, s1_len, "CP874", NULL);
if(txt_cp874 == NULL) {
return NULL;
}
Py_ssize_t len = PyString_Size(txt_cp874);
char *c_txt_cp874 = PyString_AsString(txt_cp874);
int *pos = (int *)malloc(sizeof(int) * (s1_len + 1));
int n = th_brk((unsigned char *)c_txt_cp874, pos, len);
int i, s = 0;
char *buffer;
result = PyList_New(0);
for(i = 0; i < n; i++) {
PyObject *tok;
PyObject *tok_cp874 = PySequence_GetSlice(txt_cp874, s, pos[i]);
Py_ssize_t tok_len;
PyString_AsStringAndSize(tok_cp874, &buffer, &tok_len);
tok = PyUnicode_Decode(buffer, tok_len, "CP874", NULL);
s = pos[i];
PyList_Append(result, tok);
Py_XDECREF(tok_cp874);
Py_XDECREF(tok);
}
if(s < len) {
PyObject *tok_cp874 = PySequence_GetSlice(txt_cp874, s, len);
Py_ssize_t tok_len;
PyObject *tok;
PyString_AsStringAndSize(tok_cp874, &buffer, &tok_len);
tok = PyUnicode_Decode(buffer, tok_len, "CP874", NULL);
PyList_Append(result, tok);
Py_XDECREF(tok_cp874);
Py_XDECREF(tok);
}
Py_XDECREF(txt_cp874);
free(pos);
return result;
}
开发者ID:Godlil2e,项目名称:pythai,代码行数:55,代码来源:libthai.c
示例5: acpi_object_from_python
static bool acpi_object_from_python(PyObject *pyobj, ACPI_OBJECT *obj)
{
PyObject *value;
if (pyobj == Py_None) {
obj->Type = ACPI_TYPE_ANY;
return true;
}
if (!PyArg_ParseTuple(pyobj, "IO:acpi_object_from_python", &obj->Type, &value))
return false;
switch (obj->Type) {
case ACPI_TYPE_INTEGER:
obj->Integer.Value = PyInt_AsUnsignedLongLongMask(value);
return true;
case ACPI_TYPE_STRING:
{
Py_ssize_t length;
if (PyString_AsStringAndSize(value, &obj->String.Pointer, &length) < 0)
return false;
if (length > GRUB_UINT_MAX) {
PyErr_Format(PyExc_RuntimeError, "Python object provided as ACPI string had > 4G of data");
return false;
}
obj->String.Length = length;
return true;
}
case ACPI_TYPE_BUFFER:
{
Py_ssize_t length;
if (PyString_AsStringAndSize(value, (char **)&obj->Buffer.Pointer, &length) < 0)
return false;
if (length > GRUB_UINT_MAX) {
PyErr_Format(PyExc_RuntimeError, "Python object provided as ACPI buffer had > 4G of data");
return false;
}
obj->Buffer.Length = length;
return true;
}
case ACPI_TYPE_PACKAGE:
return acpi_objects_from_python(value, &obj->Package.Elements, &obj->Package.Count);
case ACPI_TYPE_POWER:
return PyArg_ParseTuple(value, "II", &obj->PowerResource.SystemLevel, &obj->PowerResource.ResourceOrder);
case ACPI_TYPE_PROCESSOR:
return PyArg_ParseTuple(value, "IkI", &obj->Processor.ProcId, &obj->Processor.PblkAddress, &obj->Processor.PblkLength);
default:
PyErr_Format(PyExc_RuntimeError,
"Python object provided as ACPI method parameter used unhandled ACPI_OBJECT_TYPE %u.",
obj->Type);
return false;
}
}
开发者ID:mfleming,项目名称:bits,代码行数:51,代码来源:acpimodule.c
示例6: CdbMake_addmany
static PyObject *
CdbMake_addmany(cdbmakeobject *self, PyObject *args) {
PyObject *list;
if (!PyArg_ParseTuple(args,"O!:addmany",&PyList_Type, &list))
return NULL;
if (self->finished) {
CDBMAKEfinished;
return NULL;
}
Py_ssize_t size = PyList_Size(list);
Py_ssize_t i;
for (i=0; i<size; i++)
{
PyObject *tuple = PyList_GetItem(list, i);
PyObject *key_item;
PyObject *data_item;
if (!PyTuple_Check(tuple)) {
PyErr_SetString(PyExc_TypeError, "list of tuples expected");
return NULL;
}
if (!(key_item = PyTuple_GetItem(tuple,0)))
return NULL;
if (!(data_item = PyTuple_GetItem(tuple,1)))
return NULL;
char *key, *dat;
Py_ssize_t klen, dlen;
if (PyString_AsStringAndSize(key_item, &key, &klen) < 0)
return NULL;
if (PyString_AsStringAndSize(data_item, &dat, &dlen) < 0)
return NULL;
if (cdb_make_add(&self->cm, key, klen, dat, dlen) == -1)
return CDBMAKEerr;
}
return Py_BuildValue("");
}
开发者ID:abael,项目名称:python-cdb,代码行数:48,代码来源:cdbmodule.c
示例7: PyPCAP_fill_buffer
// This is called to fill the buffer when it gets too low:
static int PyPCAP_fill_buffer(PyPCAP *self, PyObject *fd) {
PyObject *data = PyObject_CallMethod(fd, "read", "l", FILL_SIZE);
char *buff;
Py_ssize_t len;
int current_readptr = self->buffer->readptr;
if(!data) return -1;
if(0 > PyString_AsStringAndSize(data, &buff, &len)) return -1;
if(!buff) return -1;
// Append the data to the end:
CALL(self->buffer, skip, self->buffer->readptr);
CALL(self->buffer, seek, 0, SEEK_END);
// Copy the data into our buffer:
CALL(self->buffer, write, buff, len);
CALL(self->buffer, seek, 0, SEEK_SET);
// self->buffer->readptr = current_readptr;
// Finished with the data
Py_DECREF(data);
return len;
};
开发者ID:backupManager,项目名称:pyflag,代码行数:27,代码来源:pypcap.c
示例8: ppm_laplacian
PyObject * ppm_laplacian(PyObject *self, PyObject * args)
{
int width, height;
char *buffer;
unsigned char *data;
unsigned char *srcPR, *destPR;
Py_ssize_t datasize;
PyObject *py_data, *result;
dprint("Starting");
if (!PyArg_ParseTuple(args, "(ii)S", &width, &height, &py_data))
return NULL;
dprint("Parsing data");
PyString_AsStringAndSize(py_data, &buffer, &datasize);
data = (unsigned char *)(buffer);
dprint("width=%d", width);
dprint("height=%d", height);
dprint("datasize=%d", datasize);
if (width*height*3 != datasize) {
PyErr_SetString(PyExc_ValueError, "data size does not match 24bit");
return NULL;
}
destPR = malloc(datasize);
srcPR = malloc(datasize);
memcpy(srcPR, data, datasize);
laplace(width, height, srcPR, destPR);
result = Py_BuildValue("s#", destPR, datasize);
return result;
}
开发者ID:AndrejScak,项目名称:arsoapi,代码行数:33,代码来源:_laplacian.c
示例9: s_py_get_user_defined_prefix
static void idaapi s_py_get_user_defined_prefix(
ea_t ea,
int lnnum,
int indent,
const char *line,
char *buf,
size_t bufsize)
{
PYW_GIL_GET;
newref_t py_ret(
PyObject_CallFunction(
py_get_user_defined_prefix,
PY_FMT64 "iis" PY_FMT64,
ea, lnnum, indent, line, bufsize));
// Error? Display it
// No error? Copy the buffer
if ( !PyW_ShowCbErr("py_get_user_defined_prefix") )
{
Py_ssize_t py_len;
char *py_str;
if ( PyString_AsStringAndSize(py_ret.o, &py_str, &py_len) != -1 )
{
memcpy(buf, py_str, qmin(bufsize, py_len));
if ( py_len < bufsize )
buf[py_len] = '\0';
}
}
}
开发者ID:EiNSTeiN-,项目名称:idapython,代码行数:29,代码来源:py_lines.hpp
示例10: encoded_string_converter
/* Caller is responsible for free-ing memory with PyMem_Free */
static bool
encoded_string_converter(PyObject *o, void *address) {
char **target = (char **)address;
char *buffer;
Py_ssize_t length;
if (o == NULL || o == Py_None) {
return 1;
}
if (PyUnicode_Check(o))
o = PyUnicode_AsEncodedString(o, ENCODING, "strict");
else
Py_INCREF(o);
if (PyString_AsStringAndSize(o, &buffer, &length) == -1) {
Py_DECREF(o);
return 0;
}
*target = PyMem_Malloc(length + 1);
if (target == NULL) {
PyErr_NoMemory();
Py_DECREF(o);
return 0;
}
strcpy(*target, buffer);
Py_DECREF(o);
return 1;
}
开发者ID:ZenithDK,项目名称:pyspotify,代码行数:32,代码来源:session.c
示例11: _K_subscript
static PyObject *
_K_subscript(_K *self, PyObject *key)
{
int i;
K kobj = self->kobj;
char *skey;
int key_length;
int value_index = 1;
if (kobj->t != 5) {
PyErr_Format(PyExc_TypeError,
"k object of type %d is not a dictionary", kobj->t);
return NULL;
}
if (-1 == PyString_AsStringAndSize(key, &skey, &key_length)) {
return NULL;
}
if (skey[key_length-1] == '.') {
--key_length;
++value_index;
}
for (i=0; i < kobj->n; ++i) {
K e = KK(kobj)[i];
if (0 == strncmp(skey,Ks(KK(e)[0]),key_length)) {
PyTypeObject* type = self->ob_type;
_K* k = (_K*)type->tp_alloc(type, 0);
k->kobj = ci(KK(e)[value_index]);
return (PyObject*)k;
}
}
PyErr_SetObject(PyExc_KeyError, key);
return NULL;
}
开发者ID:kevinarpe,项目名称:kx,代码行数:32,代码来源:_k20.c
示例12: dbg_read_memory
/*
#<pydoc>
def dbg_read_memory(ea, sz):
"""
Reads from the debugee's memory at the specified ea
@return:
- The read buffer (as a string)
- Or None on failure
"""
pass
#</pydoc>
*/
static PyObject *dbg_read_memory(PyObject *py_ea, PyObject *py_sz)
{
PYW_GIL_CHECK_LOCKED_SCOPE();
uint64 ea, sz;
if ( !dbg_can_query() || !PyW_GetNumber(py_ea, &ea) || !PyW_GetNumber(py_sz, &sz) )
Py_RETURN_NONE;
// Create a Python string
PyObject *ret = PyString_FromStringAndSize(NULL, Py_ssize_t(sz));
if ( ret == NULL )
Py_RETURN_NONE;
// Get the internal buffer
Py_ssize_t len;
char *buf;
PyString_AsStringAndSize(ret, &buf, &len);
if ( (size_t)read_dbg_memory(ea_t(ea), buf, size_t(sz)) != sz )
{
// Release the string on failure
Py_DECREF(ret);
// Return None on failure
Py_RETURN_NONE;
}
return ret;
}
开发者ID:EiNSTeiN-,项目名称:idapython,代码行数:39,代码来源:py_dbg.hpp
示例13: do_strip
static PyObject *
do_strip(PyObject *args, int striptype)
{
char *s;
Py_ssize_t len, i, j;
if (PyString_AsStringAndSize(args, &s, &len))
return NULL;
i = 0;
if (striptype != RIGHTSTRIP) {
while (i < len && isspace(Py_CHARMASK(s[i]))) {
i++;
}
}
j = len;
if (striptype != LEFTSTRIP) {
do {
j--;
} while (j >= i && isspace(Py_CHARMASK(s[j])));
j++;
}
if (i == 0 && j == len) {
Py_INCREF(args);
return args;
}
else
return PyString_FromStringAndSize(s+i, j-i);
}
开发者ID:siredblood,项目名称:tree-bumpkin-project,代码行数:32,代码来源:stropmodule.c
示例14: _write_value_to_handle
int _write_value_to_handle(const void *value, void *handle)
{
PyObject *py_value = (PyObject *)value,
*py_marshalled = NULL;
char *marshalled;
Py_ssize_t length;
int success = 0;
#ifdef Py_MARSHAL_VERSION
if(!(py_marshalled =
PyMarshal_WriteObjectToString(py_value, Py_MARSHAL_VERSION)))
goto _write_value_to_handle_cleanup;
#else
if(!(py_marshalled = PyMarshal_WriteObjectToString(py_value)))
goto _write_value_to_handle_cleanup;
#endif
if(PyString_AsStringAndSize(py_marshalled, &marshalled, &length) == -1)
goto _write_value_to_handle_cleanup;
if(!_write_to_handle(&length, sizeof(length), handle))
goto _write_value_to_handle_cleanup;
if (length != (int)length)
goto _write_value_to_handle_cleanup;
if(!_write_to_handle(marshalled, (int)length, handle))
goto _write_value_to_handle_cleanup;
success = 1;
_write_value_to_handle_cleanup:
if(py_marshalled) {
Py_DECREF(py_marshalled);
}
return success;
}
开发者ID:GunioRobot,项目名称:biopython,代码行数:33,代码来源:triemodule.c
示例15: PyInt_AsLong
static PyObject *py_socket_setsockopt(pytalloc_Object *self, PyObject *args)
{
int level, optname;
int *sock;
PyObject *pyval;
int optval;
Py_ssize_t optlen;
char *buffer;
int status;
if (!PyArg_ParseTuple(args, "iiO:getsockopt", &level, &optname, &pyval)) {
return NULL;
}
if (PyInt_Check(pyval)) {
optval = PyInt_AsLong(pyval);
buffer = (char *)&optval;
optlen = sizeof(int);
} else {
PyString_AsStringAndSize(pyval, &buffer, &optlen);
}
sock = pytalloc_get_ptr(self);
status = swrap_setsockopt(*sock, level, optname, (void *)buffer, optlen);
if (status < 0) {
return PyErr_SetFromErrno(py_socket_error);
}
Py_RETURN_NONE;
}
开发者ID:amitay,项目名称:samba,代码行数:31,代码来源:py_socket_wrapper.c
示例16: encode_wrapper
PyObject* encode_wrapper(WebPEncodeFunc encode_func, PyObject* self, PyObject* args)
{
PyStringObject *data_string;
int width;
int height;
int stride;
float quality_factor;
if (!PyArg_ParseTuple(args, "Siiif", &data_string, &width, &height, &stride, &quality_factor)) {
Py_INCREF(Py_None);
return Py_None;
}
uint8_t *data;
Py_ssize_t size;
PyString_AsStringAndSize((struct PyObject *) data_string, &data, &size);
if (stride * height > size) {
Py_INCREF(Py_None);
return Py_None;
}
uint8_t *output;
size_t ret_size = encode_func(data, width, height, stride, quality_factor, &output);
if (ret_size > 0) {
PyObject *ret = PyString_FromStringAndSize(output, ret_size);
free(output);
return ret;
}
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:bergundy,项目名称:PIL-WebP,代码行数:32,代码来源:_webp_wrapper.c
示例17: CReader_PySocketBuffer_read
static ssize_t CReader_PySocketBuffer_read(CReader_Buffer *buffer, size_t nr)
{
PyObject *read;
char *readbuf;
int readlen;
CReader_Buffer_lockInterpreter(buffer);
if (!(read = PyObject_CallMethod(buffer->file, "recv", "i", max(nr, buffer->maxsize))))
{
CReader_Buffer_releaseInterpreter(buffer);
return -1;
}
if (PyString_AsStringAndSize(read, &readbuf, &readlen) == -1)
{
Py_DECREF(read);
CReader_Buffer_releaseInterpreter(buffer);
return -1;
}
memcpy(buffer->buf + buffer->pos + buffer->len, readbuf, readlen);
Py_DECREF(read);
CReader_Buffer_releaseInterpreter(buffer);
return readlen;
}
开发者ID:redhog,项目名称:Grimoire,代码行数:25,代码来源:CReader.c
示例18: strop_upper
static PyObject *
strop_upper(PyObject *self, PyObject *args)
{
char *s, *s_new;
Py_ssize_t i, n;
PyObject *newstr;
int changed;
WARN;
if (PyString_AsStringAndSize(args, &s, &n))
return NULL;
newstr = PyString_FromStringAndSize(NULL, n);
if (newstr == NULL)
return NULL;
s_new = PyString_AsString(newstr);
changed = 0;
for (i = 0; i < n; i++) {
int c = Py_CHARMASK(*s++);
if (islower(c)) {
changed = 1;
*s_new = toupper(c);
} else
*s_new = c;
s_new++;
}
if (!changed) {
Py_DECREF(newstr);
Py_INCREF(args);
return args;
}
return newstr;
}
开发者ID:siredblood,项目名称:tree-bumpkin-project,代码行数:32,代码来源:stropmodule.c
示例19: O_writelines
static PyObject *
O_writelines(Oobject *self, PyObject *args) {
PyObject *it, *s;
it = PyObject_GetIter(args);
if (it == NULL)
return NULL;
while ((s = PyIter_Next(it)) != NULL) {
Py_ssize_t n;
char *c;
if (PyString_AsStringAndSize(s, &c, &n) == -1) {
Py_DECREF(it);
Py_DECREF(s);
return NULL;
}
if (O_cwrite((PyObject *)self, c, n) == -1) {
Py_DECREF(it);
Py_DECREF(s);
return NULL;
}
Py_DECREF(s);
}
Py_DECREF(it);
/* See if PyIter_Next failed */
if (PyErr_Occurred())
return NULL;
Py_RETURN_NONE;
}
开发者ID:ChinaQuants,项目名称:pyston,代码行数:31,代码来源:cStringIO.c
示例20: FlacDecoder_update_md5sum
flac_status
FlacDecoder_update_md5sum(decoders_FlacDecoder *self,
PyObject *framelist)
{
if (self->perform_validation) {
PyObject *string = PyObject_CallMethod(framelist,
"to_bytes","ii",
0,
1);
char *string_buffer;
Py_ssize_t length;
if (string != NULL) {
if (PyString_AsStringAndSize(string,
&string_buffer,
&length) == 0) {
audiotools__MD5Update(&(self->md5),
(unsigned char *)string_buffer,
length);
Py_DECREF(string);
return OK;
} else {
Py_DECREF(string);
return ERROR;
}
} else {
return ERROR;
}
} else {
return OK;
}
}
开发者ID:meduz,项目名称:python-audio-tools,代码行数:32,代码来源:flac.c
注:本文中的PyString_AsStringAndSize函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论