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

C++ PyString_GET_SIZE函数代码示例

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

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



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

示例1: string_count

PyObject *
string_count(PyStringObject *self, PyObject *args)
{
    PyObject *sub_obj;
    const char *str = PyString_AS_STRING(self), *sub;
    Py_ssize_t sub_len;
    Py_ssize_t start = 0, end = PY_SSIZE_T_MAX;

    if (!stringlib_parse_args_finds("count", args, &sub_obj, &start, &end))
        return NULL;

    if (PyString_Check(sub_obj)) {
        sub = PyString_AS_STRING(sub_obj);
        sub_len = PyString_GET_SIZE(sub_obj);
    }
#ifdef Py_USING_UNICODE
    else if (PyUnicode_Check(sub_obj)) {
        Py_ssize_t count;
        count = PyUnicode_Count((PyObject *)self, sub_obj, start, end);
        if (count == -1)
            return NULL;
        else
            return PyInt_FromSsize_t(count);
    }
#endif
    else if (PyObject_AsCharBuffer(sub_obj, &sub, &sub_len))
        return NULL;

    ADJUST_INDICES(start, end, PyString_GET_SIZE(self));

    return PyInt_FromSsize_t(
        stringlib_count(str + start, end - start, sub, sub_len, PY_SSIZE_T_MAX)
        );
}
开发者ID:guangwong,项目名称:pyston,代码行数:34,代码来源:stringobject.c


示例2: STRING_ADD_INCREMENTAL

NUITKA_MAY_BE_UNUSED static bool STRING_ADD_INCREMENTAL( PyObject **operand1, PyObject *operand2 )
{
    assert( PyString_CheckExact( *operand1 ) );
    assert( !PyString_CHECK_INTERNED( *operand1 ) );
    assert( PyString_CheckExact( operand2 ) );

    Py_ssize_t operand1_size = PyString_GET_SIZE( *operand1 );
    Py_ssize_t operand2_size = PyString_GET_SIZE( operand2 );

    Py_ssize_t new_size = operand1_size + operand2_size;

    if (unlikely( new_size < 0 ))
    {
        PyErr_Format(
            PyExc_OverflowError,
            "strings are too large to concat"
        );

        return false;
    }

    if (unlikely( STRING_RESIZE( operand1, new_size ) == false ))
    {
        return false;
    }

    memcpy(
        PyString_AS_STRING( *operand1 ) + operand1_size,
        PyString_AS_STRING( operand2 ),
        operand2_size
    );

    return true;
}
开发者ID:gitter-badger,项目名称:Nuitka,代码行数:34,代码来源:operations.hpp


示例3: string_find_internal

string_find_internal(PyStringObject *self, PyObject *args, int dir)
{
    PyObject *subobj;
    const char *sub;
    Py_ssize_t sub_len;
    Py_ssize_t start=0, end=PY_SSIZE_T_MAX;

    if (!stringlib_parse_args_finds("find/rfind/index/rindex",
                                    args, &subobj, &start, &end))
        return -2;

    if (PyString_Check(subobj)) {
        sub = PyString_AS_STRING(subobj);
        sub_len = PyString_GET_SIZE(subobj);
    }
#ifdef Py_USING_UNICODE
    else if (PyUnicode_Check(subobj))
        return PyUnicode_Find(
            (PyObject *)self, subobj, start, end, dir);
#endif
    else if (PyObject_AsCharBuffer(subobj, &sub, &sub_len))
        /* XXX - the "expected a character buffer object" is pretty
           confusing for a non-expert.  remap to something else ? */
        return -2;

    if (dir > 0)
        return stringlib_find_slice(
            PyString_AS_STRING(self), PyString_GET_SIZE(self),
            sub, sub_len, start, end);
    else
        return stringlib_rfind_slice(
            PyString_AS_STRING(self), PyString_GET_SIZE(self),
            sub, sub_len, start, end);
}
开发者ID:guangwong,项目名称:pyston,代码行数:34,代码来源:stringobject.c


示例4: wsgi_getheaders

static size_t
wsgi_getheaders(Request* request, PyObject* buf)
{
  char* bufp = PyString_AS_STRING(buf);
  Py_ssize_t i;

  #define buf_write(src, len) \
    do { \
      size_t n = len; \
      const char* s = src;  \
      while(n--) *bufp++ = *s++; \
    } while(0)
  #define buf_write2(src) buf_write(src, strlen(src))

  buf_write2("HTTP/1.1 ");
  buf_write(PyString_AS_STRING(request->status),
        PyString_GET_SIZE(request->status));

  for(i=0; i<PyList_GET_SIZE(request->headers); ++i) {
    PyObject *tuple = PyList_GET_ITEM(request->headers, i);
    PyObject *field = PyTuple_GET_ITEM(tuple, 0),
         *value = PyTuple_GET_ITEM(tuple, 1);
    buf_write2("\r\n");
    buf_write(PyString_AS_STRING(field), PyString_GET_SIZE(field));
    buf_write2(": ");
    buf_write(PyString_AS_STRING(value), PyString_GET_SIZE(value));
  }
  if(request->state.chunked_response)
    buf_write2("\r\nTransfer-Encoding: chunked");
  buf_write2("\r\n\r\n");

  return bufp - PyString_AS_STRING(buf);
}
开发者ID:SongJLG,项目名称:johan-doc,代码行数:33,代码来源:wsgi.c


示例5: send_chunk

static bool
send_chunk(Request* request)
{
  Py_ssize_t bytes_sent;
  static uv_buf_t resbuf;
  uv_write_t * wr;
  wr = (uv_buf_t*) malloc(sizeof *wr);
  //dprint("发送chunk:\n%s",PyString_AS_STRING(request->current_chunk) + request->current_chunk_p);
  dprint("发送大小:%d",PyString_GET_SIZE(request->current_chunk) - request->current_chunk_p);
  assert(request->current_chunk != NULL);
  assert(!(request->current_chunk_p == PyString_GET_SIZE(request->current_chunk)
         && PyString_GET_SIZE(request->current_chunk) != 0));
  resbuf = uv_buf_init(PyString_AS_STRING(request->current_chunk) + request->current_chunk_p, PyString_GET_SIZE(request->current_chunk) - request->current_chunk_p);
  bytes_sent = uv_write(
		   wr,
		   request->ev_watcher,
		   &resbuf,
		   1,
		   after_write);

  if(bytes_sent == -1){
    dprint("发送数据出错");
	dprint("chunk:\n%s",PyString_AS_STRING(request->current_chunk) + request->current_chunk_p);
    return handle_nonzero_errno(request);
  }
  request->current_chunk_p += resbuf.len;
  if(request->current_chunk_p == PyString_GET_SIZE(request->current_chunk)) {
    Py_CLEAR(request->current_chunk);
    request->current_chunk_p = 0;
    return false;
  }
  //@@@@@@@@@@@@@@@@@ Py_CLEAR(request->current_chunk);
  //@@@@@@@@@@@@@@@@@ free(resbuf.base);
  return true;
}
开发者ID:SongJLG,项目名称:johan-doc,代码行数:35,代码来源:server.c


示例6: send_chunk

static bool
send_chunk(Request* request)
{
  Py_ssize_t bytes_sent;

  assert(request->current_chunk != NULL);
  assert(!(request->current_chunk_p == PyString_GET_SIZE(request->current_chunk)
         && PyString_GET_SIZE(request->current_chunk) != 0));

  bytes_sent = write(
    request->client_fd,
    PyString_AS_STRING(request->current_chunk) + request->current_chunk_p,
    PyString_GET_SIZE(request->current_chunk) - request->current_chunk_p
  );

  if(bytes_sent == -1)
    return handle_nonzero_errno(request);

  request->current_chunk_p += bytes_sent;
  if(request->current_chunk_p == PyString_GET_SIZE(request->current_chunk)) {
    Py_CLEAR(request->current_chunk);
    request->current_chunk_p = 0;
    return false;
  }
  return true;
}
开发者ID:liveck,项目名称:bjoern,代码行数:26,代码来源:server.c


示例7: wsgi_senditer

static bool
wsgi_senditer(Request* request)
{
#define ITER_MAXSEND 1024*4
    PyObject* item = request->iterable_next;
    if(!item) return true;

    ssize_t sent = 0;
    while(item && sent < ITER_MAXSEND) {
        TYPECHECK(item, PyString, "wsgi iterable items", true);
        if(!sendall(request, PyString_AS_STRING(item),
                    PyString_GET_SIZE(item)))
            return true;
        sent += PyString_GET_SIZE(item);
        Py_DECREF(item);
        item = PyIter_Next(request->response);
        if(PyErr_Occurred()) {
            /* TODO: What to do here? Parts of the response are already sent */
            return true;
        }
    }

    if(item) {
        request->iterable_next = item;
        return false;
    } else {
        return true;
    }
}
开发者ID:shigin,项目名称:bjoern,代码行数:29,代码来源:wsgi.c


示例8: string_rsplit

PyObject* string_rsplit(PyStringObject* self, PyObject* args) {
    Py_ssize_t len = PyString_GET_SIZE(self), n;
    Py_ssize_t maxsplit = -1;
    const char* s = PyString_AS_STRING(self), *sub;
    PyObject* subobj = Py_None;

    if (!PyArg_ParseTuple(args, "|On:rsplit", &subobj, &maxsplit))
        return NULL;
    if (maxsplit < 0)
        maxsplit = PY_SSIZE_T_MAX;
    if (subobj == Py_None)
        return stringlib_rsplit_whitespace((PyObject*)self, s, len, maxsplit);
    if (PyString_Check(subobj)) {
        sub = PyString_AS_STRING(subobj);
        n = PyString_GET_SIZE(subobj);
    }
#ifdef Py_USING_UNICODE
    else if (PyUnicode_Check(subobj))
        return PyUnicode_RSplit((PyObject*)self, subobj, maxsplit);
#endif
    else if (PyObject_AsCharBuffer(subobj, &sub, &n))
        return NULL;

    return stringlib_rsplit((PyObject*)self, s, len, sub, n, maxsplit);
}
开发者ID:guangwong,项目名称:pyston,代码行数:25,代码来源:stringobject.c


示例9: generic_write

/* Write stuff to the write buffer (possibly flush it) */
static int
generic_write(genericstreamobject *self, PyObject *data)
{
    PyObject *datastr;
    bufitem *item;
    Py_ssize_t size;

    if (!(datastr = PyObject_Str(data)))
        return -1;
    if (!(item = bufitem_new()))
        goto error;

    size = self->wbuf_size + PyString_GET_SIZE(datastr);
    if ((size < self->wbuf_size) && (generic_flush(self, 0) == -1))
        goto error_item;
    item->load = datastr;
    item->next = self->wbuf;
    self->wbuf_size += PyString_GET_SIZE(datastr);
    self->wbuf = item;
    if ((self->wbuf_size > self->chunk_size) && (generic_flush(self, 0) == -1))
        return -1;

    return 0;

error_item:
    (void)bufitem_del(item);
error:
    Py_DECREF(datastr);
    return -1;
}
开发者ID:ndparker,项目名称:wtf,代码行数:31,代码来源:stream.c


示例10: AsObj

static Tcl_Obj*
AsObj(PyObject *value)
{
	Tcl_Obj *result;

	if (PyString_Check(value))
		return Tcl_NewStringObj(PyString_AS_STRING(value),
					PyString_GET_SIZE(value));
	else if (PyInt_Check(value))
		return Tcl_NewLongObj(PyInt_AS_LONG(value));
	else if (PyFloat_Check(value))
		return Tcl_NewDoubleObj(PyFloat_AS_DOUBLE(value));
	else if (PyTuple_Check(value)) {
		Tcl_Obj **argv = (Tcl_Obj**)
			ckalloc(PyTuple_Size(value)*sizeof(Tcl_Obj*));
		int i;
		if(!argv)
		  return 0;
		for(i=0;i<PyTuple_Size(value);i++)
		  argv[i] = AsObj(PyTuple_GetItem(value,i));
		result = Tcl_NewListObj(PyTuple_Size(value), argv);
		ckfree(FREECAST argv);
		return result;
	}
	else if (PyUnicode_Check(value)) {
#if TKMAJORMINOR <= 8001
		/* In Tcl 8.1 we must use UTF-8 */
		PyObject* utf8 = PyUnicode_AsUTF8String(value);
		if (!utf8)
			return 0;
		result = Tcl_NewStringObj(PyString_AS_STRING(utf8),
					  PyString_GET_SIZE(utf8));
		Py_DECREF(utf8);
		return result;
#else /* TKMAJORMINOR > 8001 */
		/* In Tcl 8.2 and later, use Tcl_NewUnicodeObj() */
		if (sizeof(Py_UNICODE) != sizeof(Tcl_UniChar)) {
			/* XXX Should really test this at compile time */
			PyErr_SetString(PyExc_SystemError,
				"Py_UNICODE and Tcl_UniChar differ in size");
			return 0;
		}
		return Tcl_NewUnicodeObj(PyUnicode_AS_UNICODE(value),
					 PyUnicode_GET_SIZE(value));
#endif /* TKMAJORMINOR > 8001 */
	}
	else {
		PyObject *v = PyObject_Str(value);
		if (!v)
			return 0;
		result = AsObj(v);
		Py_DECREF(v);
		return result;
	}
}
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:55,代码来源:_tkinter.c


示例11: MakeConnectionString

static PyObject* MakeConnectionString(PyObject* existing, PyObject* parts)
{
    // Creates a connection string from an optional existing connection string plus a dictionary of keyword value
    // pairs.  The keywords must be String objects and the values must be Unicode objects.

    Py_ssize_t length = 0;
    if (existing)
        length = PyUnicode_GET_SIZE(existing) + 1; // + 1 to add a trailing 

    Py_ssize_t pos = 0;
    PyObject* key = 0;
    PyObject* value = 0;

    while (PyDict_Next(parts, &pos, &key, &value))
    {
        length += PyString_GET_SIZE(key) + 1 + PyUnicode_GET_SIZE(value) + 1; // key=value;
    }
    
    PyObject* result = PyUnicode_FromUnicode(0, length);
    if (!result)
        return 0;

    Py_UNICODE* buffer = PyUnicode_AS_UNICODE(result);
    Py_ssize_t offset = 0;

    if (existing)
    {
        memcpy(&buffer[offset], PyUnicode_AS_UNICODE(existing), PyUnicode_GET_SIZE(existing) * sizeof(Py_UNICODE));
        offset += PyUnicode_GET_SIZE(existing);
        buffer[offset++] = (Py_UNICODE)';';
    }

    pos = 0;
    while (PyDict_Next(parts, &pos, &key, &value))
    {
        const char* szKey = PyString_AS_STRING(key);
        for (int i = 0; i < PyString_GET_SIZE(key); i++)
            buffer[offset++] = (Py_UNICODE)szKey[i];

        buffer[offset++] = (Py_UNICODE)'=';

        memcpy(&buffer[offset], PyUnicode_AS_UNICODE(value), PyUnicode_GET_SIZE(value) * sizeof(Py_UNICODE));
        offset += PyUnicode_GET_SIZE(value);
        
        buffer[offset++] = (Py_UNICODE)';';
    }

    I(offset == length);

    return result;
}
开发者ID:arvindchari88,项目名称:newGitTest,代码行数:51,代码来源:pyodbcmodule.cpp


示例12: _tnetstring_loads

//  _tnetstring_loads:  parse tnetstring-format value from a string.
//
static PyObject*
_tnetstring_loads(PyObject* self, PyObject *args) 
{
  PyObject *string = NULL;
  PyObject *encoding = Py_None;
  PyObject *val = NULL;
  tns_ops *ops = &_tnetstring_ops_bytes;
  char *data;
  size_t len;

  if(!PyArg_UnpackTuple(args, "loads", 1, 2, &string, &encoding)) {
      return NULL;
  }
  if(!PyString_Check(string)) {
      PyErr_SetString(PyExc_TypeError, "arg must be a string");
      return NULL;
  }
  Py_INCREF(string);

  if(encoding == Py_None) {
      data = PyString_AS_STRING(string);
      len = PyString_GET_SIZE(string);
      val = tns_parse(ops, data, len, NULL);
  } else {
      if(!PyString_Check(encoding)) {
          PyErr_SetString(PyExc_TypeError, "encoding must be a string");
          goto error;
      }
      Py_INCREF(encoding);
      ops = _tnetstring_get_unicode_ops(encoding);
      if(ops == NULL) {
          Py_DECREF(encoding);
          goto error;
      }
      data = PyString_AS_STRING(string);
      len = PyString_GET_SIZE(string);
      val = tns_parse(ops, data, len, NULL);
      free(ops);
      Py_DECREF(encoding);
  }

  Py_DECREF(string);
  return val;

error:
  Py_DECREF(string);
  return NULL;
}
开发者ID:pombredanne,项目名称:tnetstring,代码行数:50,代码来源:_tnetstring.c


示例13: _tnetstring_loads

static PyObject*
_tnetstring_loads(PyObject* self, PyObject *args) 
{
  PyObject *string, *val;
  char *data;
  size_t len;

  if(!PyArg_UnpackTuple(args, "loads", 1, 1, &string)) {
      return NULL;
  }
  if(!PyString_Check(string)) {
      PyErr_SetString(PyExc_TypeError, "arg must be a string");
      return NULL;
  }
  Py_INCREF(string);

  data = PyString_AS_STRING(string);
  len = PyString_GET_SIZE(string);
  val = tns_parse(data, len, NULL);
  Py_DECREF(string);
  if(val == NULL) {
      return NULL;
  }

  return val;
}
开发者ID:Tordek,项目名称:tnetstring,代码行数:26,代码来源:_tnetstring.c


示例14: _set_char

static int
_set_char(const char *name, char *target, PyObject *src, char dflt)
{
    if (src == NULL)
        *target = dflt;
    else {
        *target = '\0';
        if (src != Py_None) {
            Py_ssize_t len;
            if (!PyString_Check(src)) {
                PyErr_Format(PyExc_TypeError,
                    "\"%s\" must be string, not %.200s", name,
                    src->ob_type->tp_name);
                return -1;
            }
            len = PyString_GET_SIZE(src);
            if (len > 1) {
                PyErr_Format(PyExc_TypeError,
                    "\"%s\" must be an 1-character string",
                    name);
                return -1;
            }
            if (len > 0)
                *target = *PyString_AS_STRING(src);
        }
    }
    return 0;
}
开发者ID:AbnerChang,项目名称:edk2-staging,代码行数:28,代码来源:_csv.c


示例15: future_parse

static int
future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename)
{
    int i, found_docstring = 0, done = 0, prev_line = 0;

    if (!(mod->kind == Module_kind || mod->kind == Interactive_kind))
        return 1;

    /* A subsequent pass will detect future imports that don't
       appear at the beginning of the file.  There's one case,
       however, that is easier to handle here: A series of imports
       joined by semi-colons, where the first import is a future
       statement but some subsequent import has the future form
       but is preceded by a regular import.
    */


    for (i = 0; i < asdl_seq_LEN(mod->v.Module.body); i++) {
        stmt_ty s = (stmt_ty)asdl_seq_GET(mod->v.Module.body, i);

        if (done && s->lineno > prev_line)
            return 1;
        prev_line = s->lineno;

        /* The tests below will return from this function unless it is
           still possible to find a future statement.  The only things
           that can precede a future statement are another future
           statement and a doc string.
        */

        if (s->kind == ImportFrom_kind) {
            identifier modname = s->v.ImportFrom.module;
            if (modname && PyString_GET_SIZE(modname) == 10 &&
                !strcmp(PyString_AS_STRING(modname), "__future__")) {
                if (done) {
                    PyErr_SetString(PyExc_SyntaxError,
                                    ERR_LATE_FUTURE);
                    PyErr_SyntaxLocation(filename,
                                         s->lineno);
                    return 0;
                }
                if (!future_check_features(ff, s, filename))
                    return 0;
                ff->ff_lineno = s->lineno;
            }
            else
                done = 1;
        }
        else if (s->kind == Expr_kind && !found_docstring) {
            expr_ty e = s->v.Expr.value;
            if (e->kind != Str_kind)
                done = 1;
            else
                found_docstring = 1;
        }
        else
            done = 1;
    }
    return 1;
}
开发者ID:Max00355,项目名称:python-with-braces,代码行数:60,代码来源:future.c


示例16: TDI_SoupEncoderType_endtag

:See: `EncoderInterface`");

static PyObject *
TDI_SoupEncoderType_endtag(tdi_soup_encoder_t *self, PyObject *args)
{
    PyObject *name, *result;
    char *cresult;
    Py_ssize_t size;

    if (!(PyArg_ParseTuple(args, "S", &name)))
        return NULL;

    if (!PyString_CheckExact(name)) {
        if (!(name = PyObject_Str(name)))
            return NULL;
    }
    else
        Py_INCREF(name);

    size = PyString_GET_SIZE(name);
    if (!(result = PyString_FromStringAndSize(NULL, size + 3))) { /* </> */
        Py_DECREF(name);
        return NULL;
    }
    cresult = PyString_AS_STRING(result);
    *cresult++ = '<';
    *cresult++ = '/';
    (void)memcpy(cresult, PyString_AS_STRING(name), (size_t)size);
    Py_DECREF(name);
    cresult += size;
    *cresult = '>';

    return result;
}
开发者ID:giorgil,项目名称:tdi,代码行数:34,代码来源:soup_encoder.c


示例17: inspect_headers

static inline bool
inspect_headers(Request* request)
{
  Py_ssize_t i;
  PyObject* tuple;

  for(i=0; i<PyList_GET_SIZE(request->headers); ++i) {
    tuple = PyList_GET_ITEM(request->headers, i);

    if(!PyTuple_Check(tuple) || PyTuple_GET_SIZE(tuple) != 2)
      goto err;

    PyObject* field = PyTuple_GET_ITEM(tuple, 0);
    PyObject* value = PyTuple_GET_ITEM(tuple, 1);

    if(!PyString_Check(field) || !PyString_Check(value))
      goto err;

    if(!strncasecmp(PyString_AS_STRING(field), "Content-Length", PyString_GET_SIZE(field)))
      request->state.response_length_unknown = false;
  }
  return true;

err:
  TYPE_ERROR_INNER("start_response argument 2", "a list of 2-tuples",
    "(found invalid '%.200s' object at position %zd)", Py_TYPE(tuple)->tp_name, i);
  return false;
}
开发者ID:Logout22,项目名称:bjoern,代码行数:28,代码来源:wsgi.c


示例18: rpcError_Extract

bool
rpcError_Extract(PyObject *error, int *errorCode, char **errorString)
{
	PyObject	*pyErrorCode,
			*pyErrorString;

	assert(PyErr_GivenExceptionMatches(error, rpcError));
	pyErrorCode = PyObject_GetAttrString(error, "errorCode");
	if (errorCode && PyInt_Check(pyErrorCode))
		*errorCode = (int)PyInt_AS_LONG(pyErrorCode);
	else {
		fprintf(rpcLogger, "invalid error code... deerror to -1\n");
		*errorCode = -1;
	}
	pyErrorString = PyObject_GetAttrString(error, "errorString");
	if (errorString && PyString_Check(pyErrorString)) {
		*errorString = alloc(PyString_GET_SIZE(pyErrorString) + 1);
		if (*errorString == NULL)
			return false;
		strcpy(*errorString, PyString_AS_STRING(pyErrorString));
	} else {
		fprintf(rpcLogger, "invalid error string... deerror to 'unknown error'\n");
		*errorString = alloc(strlen("unknown error") + 1);
		if (*errorString == NULL)
			return false;
		strcpy(*errorString, "unknown error");
	}
	return true;
}
开发者ID:Zemanta,项目名称:py-xmlrpc,代码行数:29,代码来源:rpcError.c


示例19: s_unpack

static PyObject *
s_unpack(PyObject *self, PyObject *inputstr)
{
	char *start;
	Py_ssize_t len;
	PyObject *args=NULL, *result;
	PyStructObject *soself = (PyStructObject *)self;
	assert(PyStruct_Check(self));
	assert(soself->s_codes != NULL);
	if (inputstr == NULL)
		goto fail;
	if (PyString_Check(inputstr) &&
		PyString_GET_SIZE(inputstr) == soself->s_size) {
			return s_unpack_internal(soself, PyString_AS_STRING(inputstr));
	}
	args = PyTuple_Pack(1, inputstr);
	if (args == NULL)
		return NULL;
	if (!PyArg_ParseTuple(args, "s#:unpack", &start, &len))
		goto fail;
	if (soself->s_size != len)
		goto fail;
	result = s_unpack_internal(soself, start);
	Py_DECREF(args);
	return result;

fail:
	Py_XDECREF(args);
	PyErr_Format(StructError,
		"unpack requires a string argument of length %zd",
		soself->s_size);
	return NULL;
}
开发者ID:grobe0ba,项目名称:plan9front,代码行数:33,代码来源:_struct.c


示例20: PyNumber_Int

PyObject *
PyNumber_Int(PyObject *o)
{
	PyNumberMethods *m;
	const char *buffer;
	int buffer_len;

	if (o == NULL)
		return null_error();
	if (PyInt_Check(o)) {
		Py_INCREF(o);
		return o;
	}
	if (PyString_Check(o))
		return int_from_string(PyString_AS_STRING(o), 
				       PyString_GET_SIZE(o));
	if (PyUnicode_Check(o))
		return PyInt_FromUnicode(PyUnicode_AS_UNICODE(o),
					 PyUnicode_GET_SIZE(o),
					 10);
	m = o->ob_type->tp_as_number;
	if (m && m->nb_int)
		return m->nb_int(o);
	if (!PyObject_AsCharBuffer(o, &buffer, &buffer_len))
		return int_from_string((char*)buffer, buffer_len);

	return type_error("object can't be converted to int");
}
开发者ID:asottile,项目名称:ancient-pythons,代码行数:28,代码来源:abstract.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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