const formatdef *f;
const formatdef *e;
formatcode *codes;
-
+
const char *s;
const char *fmt;
char c;
fmt = PyString_AS_STRING(self->s_format);
f = whichtable((char **)&fmt);
-
+
s = fmt;
size = 0;
len = 0;
e = getentry(c, f);
if (e == NULL)
return -1;
-
+
switch (c) {
case 's': /* fall through */
case 'p': len++; break;
return -1;
}
self->s_codes = codes;
-
+
s = fmt;
size = 0;
while ((c = *s++) != '\0') {
num = 1;
e = getentry(c, f);
-
+
size = align(size, c, e);
if (c == 's' || c == 'p') {
codes->offset = size;
codes->fmtdef = NULL;
codes->offset = size;
codes->size = 0;
-
+
return 0;
}
Py_INCREF(o_format);
Py_XDECREF(soself->s_format);
soself->s_format = o_format;
-
+
ret = prepare_s(soself);
return ret;
}
{
PyStructObject *soself = (PyStructObject *)self;
assert(PyStruct_Check(self));
- assert(soself->s_codes != NULL);
+ assert(soself->s_codes != NULL);
if (inputstr == NULL || !PyString_Check(inputstr) ||
PyString_GET_SIZE(inputstr) != soself->s_size) {
PyErr_Format(StructError,
"unpack_from requires a buffer argument");
return NULL;
}
-
+
if (offset < 0)
offset += buffer_len;
}
}
}
-
+
/* Success */
return 0;
}
"pack requires exactly %zd arguments", soself->s_len);
return NULL;
}
-
+
/* Allocate a new string */
result = PyString_FromStringAndSize((char *)NULL, soself->s_size);
if (result == NULL)
return NULL;
-
+
/* Call the guts */
if ( s_pack_internal(soself, args, 0, PyString_AS_STRING(result)) != 0 ) {
Py_DECREF(result);
PyTuple_GET_SIZE(args) != (soself->s_len + 2))
{
PyErr_Format(StructError,
- "pack_to requires exactly %zd arguments",
+ "pack_to requires exactly %zd arguments",
(soself->s_len + 2));
return NULL;
}
/* Extract a writable memory buffer from the first argument */
- if ( PyObject_AsWriteBuffer(PyTuple_GET_ITEM(args, 0),
- (void**)&buffer, &buffer_len) == -1 ) {
+ if ( PyObject_AsWriteBuffer(PyTuple_GET_ITEM(args, 0),
+ (void**)&buffer, &buffer_len) == -1 ) {
return NULL;
}
assert( buffer_len >= 0 );
soself->s_size);
return NULL;
}
-
+
/* Call the guts */
if ( s_pack_internal(soself, args, 2, buffer + offset) != 0 ) {
return NULL;
static struct PyMethodDef s_methods[] = {
{"pack", (PyCFunction)s_pack, METH_VARARGS, s_pack__doc__},
- {"pack_to", (PyCFunction)s_pack_to, METH_VARARGS, s_pack_to__doc__},
+ {"pack_to", (PyCFunction)s_pack_to, METH_VARARGS, s_pack_to__doc__},
{"unpack", (PyCFunction)s_unpack, METH_O, s_unpack__doc__},
{"unpack_from", (PyCFunction)s_unpack_from, METH_KEYWORDS, s_unpack_from__doc__},
{NULL, NULL} /* sentinel */
return;
}
-#else
+#else
/* This speed trick can't be used until overflow masking goes away, because
native endian always raises exceptions instead of overflow masking. */
-
+
/* Check endian and swap in faster functions */
{
int one = 1;
listed in the same order */
if (ptr == other)
other++;
- /* Only use the trick if the
+ /* Only use the trick if the
size matches */
if (ptr->size != native->size)
break;
}
}
#endif
-
+
/* Add some symbolic constants to the module */
if (StructError == NULL) {
StructError = PyErr_NewException("struct.error", NULL, NULL);
Py_INCREF((PyObject*)&PyStructType);
PyModule_AddObject(m, "Struct", (PyObject*)&PyStructType);
-
+
PyModule_AddIntConstant(m, "_PY_STRUCT_RANGE_CHECKING", 1);
#ifdef PY_STRUCT_OVERFLOW_MASKING
PyModule_AddIntConstant(m, "_PY_STRUCT_OVERFLOW_MASKING", 1);