#endif
/* Argument must be a char or an int in [-128, 127] or [0, 255]. */
-#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
+#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
#include "pyfpe.h"
#define Py_RETURN_NAN return PyFloat_FromDouble(Py_NAN)
#endif
-#define Py_RETURN_INF(sign) do \
- if (copysign(1., sign) == 1.) { \
- return PyFloat_FromDouble(Py_HUGE_VAL); \
- } else { \
- return PyFloat_FromDouble(-Py_HUGE_VAL); \
- } while(0)
+#define Py_RETURN_INF(sign) do \
+ if (copysign(1., sign) == 1.) { \
+ return PyFloat_FromDouble(Py_HUGE_VAL); \
+ } else { \
+ return PyFloat_FromDouble(-Py_HUGE_VAL); \
+ } while(0)
PyAPI_FUNC(double) PyFloat_GetMax(void);
PyAPI_FUNC(double) PyFloat_GetMin(void);
/* Format the object based on the format_spec, as defined in PEP 3101
(Advanced String Formatting). */
PyAPI_FUNC(PyObject *) _PyFloat_FormatAdvanced(PyObject *obj,
- PyObject *format_spec,
- Py_ssize_t start,
- Py_ssize_t end);
+ PyObject *format_spec,
+ Py_ssize_t start,
+ Py_ssize_t end);
#endif /* Py_LIMITED_API */
#ifdef __cplusplus
PyAPI_DATA(PyTypeObject) PyLong_Type;
#define PyLong_Check(op) \
- PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS)
+ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS)
#define PyLong_CheckExact(op) (Py_TYPE(op) == &PyLong_Type)
PyAPI_FUNC(PyObject *) PyLong_FromLong(long);
enough memory to create the Python long.
*/
PyAPI_FUNC(PyObject *) _PyLong_FromByteArray(
- const unsigned char* bytes, size_t n,
- int little_endian, int is_signed);
+ const unsigned char* bytes, size_t n,
+ int little_endian, int is_signed);
/* _PyLong_AsByteArray: Convert the least-significant 8*n bits of long
v to a base-256 integer, stored in array bytes. Normally return 0,
case, but bytes holds the least-signficant n bytes of the true value.
*/
PyAPI_FUNC(int) _PyLong_AsByteArray(PyLongObject* v,
- unsigned char* bytes, size_t n,
- int little_endian, int is_signed);
+ unsigned char* bytes, size_t n,
+ int little_endian, int is_signed);
/* _PyLong_Format: Convert the long to a string object with given base,
/* Format the object based on the format_spec, as defined in PEP 3101
(Advanced String Formatting). */
PyAPI_FUNC(PyObject *) _PyLong_FormatAdvanced(PyObject *obj,
- PyObject *format_spec,
- Py_ssize_t start,
- Py_ssize_t end);
+ PyObject *format_spec,
+ Py_ssize_t start,
+ Py_ssize_t end);
#endif /* Py_LIMITED_API */
/* These aren't really part of the long object, but they're handy. The
if (!ptr)
return NULL;
- if (logical_charsize == 1 && pattern->logical_charsize > 1) {
- PyErr_SetString(PyExc_TypeError,
- "can't use a string pattern on a bytes-like object");
- return NULL;
- }
- if (logical_charsize > 1 && pattern->logical_charsize == 1) {
- PyErr_SetString(PyExc_TypeError,
- "can't use a bytes pattern on a string-like object");
- return NULL;
- }
+ if (logical_charsize == 1 && pattern->logical_charsize > 1) {
+ PyErr_SetString(PyExc_TypeError,
+ "can't use a string pattern on a bytes-like object");
+ return NULL;
+ }
+ if (logical_charsize > 1 && pattern->logical_charsize == 1) {
+ PyErr_SetString(PyExc_TypeError,
+ "can't use a bytes pattern on a string-like object");
+ return NULL;
+ }
/* adjust boundaries */
if (start < 0)
status = sre_usearch(&state, PatternObject_GetCode(self));
}
- if (PyErr_Occurred())
- goto error;
+ if (PyErr_Occurred())
+ goto error;
if (status <= 0) {
if (status == 0)
status = sre_usearch(&state, PatternObject_GetCode(self));
}
- if (PyErr_Occurred())
- goto error;
+ if (PyErr_Occurred())
+ goto error;
if (status <= 0) {
if (status == 0)
status = sre_usearch(&state, PatternObject_GetCode(self));
}
- if (PyErr_Occurred())
- goto error;
+ if (PyErr_Occurred())
+ goto error;
if (status <= 0) {
if (status == 0)
static PyMethodDef pattern_methods[] = {
{"match", (PyCFunction) pattern_match, METH_VARARGS|METH_KEYWORDS,
- pattern_match_doc},
+ pattern_match_doc},
{"search", (PyCFunction) pattern_search, METH_VARARGS|METH_KEYWORDS,
- pattern_search_doc},
+ pattern_search_doc},
{"sub", (PyCFunction) pattern_sub, METH_VARARGS|METH_KEYWORDS,
- pattern_sub_doc},
+ pattern_sub_doc},
{"subn", (PyCFunction) pattern_subn, METH_VARARGS|METH_KEYWORDS,
- pattern_subn_doc},
+ pattern_subn_doc},
{"split", (PyCFunction) pattern_split, METH_VARARGS|METH_KEYWORDS,
- pattern_split_doc},
+ pattern_split_doc},
{"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS,
- pattern_findall_doc},
+ pattern_findall_doc},
#if PY_VERSION_HEX >= 0x02020000
{"finditer", (PyCFunction) pattern_finditer, METH_VARARGS,
- pattern_finditer_doc},
+ pattern_finditer_doc},
#endif
{"scanner", (PyCFunction) pattern_scanner, METH_VARARGS},
{"__copy__", (PyCFunction) pattern_copy, METH_NOARGS},
PyVarObject_HEAD_INIT(NULL, 0)
"_" SRE_MODULE ".SRE_Pattern",
sizeof(PatternObject), sizeof(SRE_CODE),
- (destructor)pattern_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_reserved */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- pattern_doc, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- offsetof(PatternObject, weakreflist), /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- pattern_methods, /* tp_methods */
- pattern_members, /* tp_members */
+ (destructor)pattern_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_reserved */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ pattern_doc, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ offsetof(PatternObject, weakreflist), /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ pattern_methods, /* tp_methods */
+ pattern_members, /* tp_members */
};
static int _validate(PatternObject *self); /* Forward */
Py_ssize_t i;
if (index == NULL)
- /* Default value */
- return 0;
+ /* Default value */
+ return 0;
if (PyLong_Check(index))
return PyLong_AsSsize_t(index);
match_lastindex_get(MatchObject *self)
{
if (self->lastindex >= 0)
- return Py_BuildValue("i", self->lastindex);
+ return Py_BuildValue("i", self->lastindex);
Py_INCREF(Py_None);
return Py_None;
}
PyVarObject_HEAD_INIT(NULL,0)
"_" SRE_MODULE ".SRE_Match",
sizeof(MatchObject), sizeof(Py_ssize_t),
- (destructor)match_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_reserved */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- match_methods, /* tp_methods */
- match_members, /* tp_members */
- match_getset, /* tp_getset */
+ (destructor)match_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_reserved */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ match_methods, /* tp_methods */
+ match_members, /* tp_members */
+ match_getset, /* tp_getset */
};
static PyObject*
#define SCAN_OFF(x) offsetof(ScannerObject, x)
static PyMemberDef scanner_members[] = {
- {"pattern", T_OBJECT, SCAN_OFF(pattern), READONLY},
+ {"pattern", T_OBJECT, SCAN_OFF(pattern), READONLY},
{NULL} /* Sentinel */
};
"_" SRE_MODULE ".SRE_Scanner",
sizeof(ScannerObject), 0,
(destructor)scanner_dealloc,/* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_reserved */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- scanner_methods, /* tp_methods */
- scanner_members, /* tp_members */
- 0, /* tp_getset */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_reserved */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ scanner_methods, /* tp_methods */
+ scanner_members, /* tp_members */
+ 0, /* tp_getset */
};
static PyObject*
};
static struct PyModuleDef sremodule = {
- PyModuleDef_HEAD_INIT,
- "_" SRE_MODULE,
- NULL,
- -1,
- _functions,
- NULL,
- NULL,
- NULL,
- NULL
+ PyModuleDef_HEAD_INIT,
+ "_" SRE_MODULE,
+ NULL,
+ -1,
+ _functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
};
PyMODINIT_FUNC PyInit__sre(void)
m = PyModule_Create(&sremodule);
if (m == NULL)
- return NULL;
+ return NULL;
d = PyModule_GetDict(m);
x = PyLong_FromLong(SRE_MAGIC);
return NULL;
res->ht_name = PyUnicode_FromString(spec->name);
if (!res->ht_name)
- goto fail;
+ goto fail;
res->ht_type.tp_name = _PyUnicode_AsString(res->ht_name);
if (!res->ht_type.tp_name)
- goto fail;
+ goto fail;
res->ht_type.tp_basicsize = spec->basicsize;
res->ht_type.tp_itemsize = spec->itemsize;
res->ht_type.tp_flags = spec->flags | Py_TPFLAGS_HEAPTYPE;
for (slot = spec->slots; slot->slot; slot++) {
- if (slot->slot >= sizeof(slotoffsets)/sizeof(slotoffsets[0])) {
- PyErr_SetString(PyExc_RuntimeError, "invalid slot offset");
- goto fail;
- }
- *(void**)(res_start + slotoffsets[slot->slot]) = slot->pfunc;
+ if (slot->slot >= sizeof(slotoffsets)/sizeof(slotoffsets[0])) {
+ PyErr_SetString(PyExc_RuntimeError, "invalid slot offset");
+ goto fail;
+ }
+ *(void**)(res_start + slotoffsets[slot->slot]) = slot->pfunc;
/* need to make a copy of the docstring slot, which usually
points to a static string literal */
ssize_t len = strlen(slot->pfunc)+1;
char *tp_doc = PyObject_MALLOC(len);
if (tp_doc == NULL)
- goto fail;
+ goto fail;
memcpy(tp_doc, slot->pfunc, len);
res->ht_type.tp_doc = tp_doc;
}
static void
raise_encode_exception(PyObject **exceptionObject,
- const char *encoding,
- const Py_UNICODE *unicode, Py_ssize_t size,
- Py_ssize_t startpos, Py_ssize_t endpos,
- const char *reason);
+ const char *encoding,
+ const Py_UNICODE *unicode, Py_ssize_t size,
+ Py_ssize_t startpos, Py_ssize_t endpos,
+ const char *reason);
/* Same for linebreaks */
static unsigned char ascii_linebreak[] = {
PyObject *
PyUnicode_FromEncodedObject(register PyObject *obj,
- const char *encoding,
- const char *errors)
+ const char *encoding,
+ const char *errors)
{
Py_buffer buffer;
PyObject *v;
PyObject *
PyUnicode_Decode(const char *s,
- Py_ssize_t size,
- const char *encoding,
- const char *errors)
+ Py_ssize_t size,
+ const char *encoding,
+ const char *errors)
{
PyObject *buffer = NULL, *unicode;
Py_buffer info;
PyObject *
PyUnicode_AsDecodedObject(PyObject *unicode,
- const char *encoding,
- const char *errors)
+ const char *encoding,
+ const char *errors)
{
PyObject *v;
PyObject *
PyUnicode_AsDecodedUnicode(PyObject *unicode,
- const char *encoding,
- const char *errors)
+ const char *encoding,
+ const char *errors)
{
PyObject *v;
PyObject *
PyUnicode_Encode(const Py_UNICODE *s,
- Py_ssize_t size,
- const char *encoding,
- const char *errors)
+ Py_ssize_t size,
+ const char *encoding,
+ const char *errors)
{
PyObject *v, *unicode;
PyObject *
PyUnicode_AsEncodedObject(PyObject *unicode,
- const char *encoding,
- const char *errors)
+ const char *encoding,
+ const char *errors)
{
PyObject *v;
PyObject *
PyUnicode_AsEncodedString(PyObject *unicode,
- const char *encoding,
- const char *errors)
+ const char *encoding,
+ const char *errors)
{
PyObject *v;
char lower[11]; /* Enough for any encoding shortcut */
PyObject *
PyUnicode_AsEncodedUnicode(PyObject *unicode,
- const char *encoding,
- const char *errors)
+ const char *encoding,
+ const char *errors)
{
PyObject *v;
static int
unicode_decode_call_errorhandler(const char *errors, PyObject **errorHandler,
- const char *encoding, const char *reason,
- const char **input, const char **inend, Py_ssize_t *startinpos,
- Py_ssize_t *endinpos, PyObject **exceptionObject, const char **inptr,
- PyUnicodeObject **output, Py_ssize_t *outpos, Py_UNICODE **outptr)
+ const char *encoding, const char *reason,
+ const char **input, const char **inend, Py_ssize_t *startinpos,
+ Py_ssize_t *endinpos, PyObject **exceptionObject, const char **inptr,
+ PyUnicodeObject **output, Py_ssize_t *outpos, Py_UNICODE **outptr)
{
static char *argparse = "O!n;decoding error handler must return (str, int) tuple";
PyObject *
PyUnicode_DecodeUTF7(const char *s,
- Py_ssize_t size,
- const char *errors)
+ Py_ssize_t size,
+ const char *errors)
{
return PyUnicode_DecodeUTF7Stateful(s, size, errors, NULL);
}
PyObject *
PyUnicode_DecodeUTF7Stateful(const char *s,
- Py_ssize_t size,
- const char *errors,
- Py_ssize_t *consumed)
+ Py_ssize_t size,
+ const char *errors,
+ Py_ssize_t *consumed)
{
const char *starts = s;
Py_ssize_t startinpos;
PyObject *
PyUnicode_EncodeUTF7(const Py_UNICODE *s,
- Py_ssize_t size,
- int base64SetO,
- int base64WhiteSpace,
- const char *errors)
+ Py_ssize_t size,
+ int base64SetO,
+ int base64WhiteSpace,
+ const char *errors)
{
PyObject *v;
/* It might be possible to tighten this worst case */
PyObject *
PyUnicode_DecodeUTF8(const char *s,
- Py_ssize_t size,
- const char *errors)
+ Py_ssize_t size,
+ const char *errors)
{
return PyUnicode_DecodeUTF8Stateful(s, size, errors, NULL);
}
PyObject *
PyUnicode_DecodeUnicodeEscape(const char *s,
- Py_ssize_t size,
- const char *errors)
+ Py_ssize_t size,
+ const char *errors)
{
const char *starts = s;
Py_ssize_t startinpos;
PyObject *
PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
- Py_ssize_t size)
+ Py_ssize_t size)
{
PyObject *repr;
char *p;
PyObject *
PyUnicode_DecodeRawUnicodeEscape(const char *s,
- Py_ssize_t size,
- const char *errors)
+ Py_ssize_t size,
+ const char *errors)
{
const char *starts = s;
Py_ssize_t startinpos;
PyObject *
PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s,
- Py_ssize_t size)
+ Py_ssize_t size)
{
PyObject *repr;
char *p;
PyObject *
_PyUnicode_DecodeUnicodeInternal(const char *s,
- Py_ssize_t size,
- const char *errors)
+ Py_ssize_t size,
+ const char *errors)
{
const char *starts = s;
Py_ssize_t startinpos;
PyObject *
PyUnicode_DecodeLatin1(const char *s,
- Py_ssize_t size,
- const char *errors)
+ Py_ssize_t size,
+ const char *errors)
{
/* Latin-1 is equivalent to the first 256 ordinals in Unicode. */
return _PyUnicode_FromUCS1((unsigned char*)s, size);
/* create or adjust a UnicodeEncodeError */
static void
make_encode_exception(PyObject **exceptionObject,
- const char *encoding,
- const Py_UNICODE *unicode, Py_ssize_t size,
- Py_ssize_t startpos, Py_ssize_t endpos,
- const char *reason)
+ const char *encoding,
+ const Py_UNICODE *unicode, Py_ssize_t size,
+ Py_ssize_t startpos, Py_ssize_t endpos,
+ const char *reason)
{
if (*exceptionObject == NULL) {
*exceptionObject = PyUnicodeEncodeError_Create(
/* raises a UnicodeEncodeError */
static void
raise_encode_exception(PyObject **exceptionObject,
- const char *encoding,
- const Py_UNICODE *unicode, Py_ssize_t size,
- Py_ssize_t startpos, Py_ssize_t endpos,
- const char *reason)
+ const char *encoding,
+ const Py_UNICODE *unicode, Py_ssize_t size,
+ Py_ssize_t startpos, Py_ssize_t endpos,
+ const char *reason)
{
make_encode_exception(exceptionObject,
encoding, unicode, size, startpos, endpos, reason);
has to be freed by the caller */
static PyObject *
unicode_encode_call_errorhandler(const char *errors,
- PyObject **errorHandler,
- const char *encoding, const char *reason,
- const Py_UNICODE *unicode, Py_ssize_t size, PyObject **exceptionObject,
- Py_ssize_t startpos, Py_ssize_t endpos,
- Py_ssize_t *newpos)
+ PyObject **errorHandler,
+ const char *encoding, const char *reason,
+ const Py_UNICODE *unicode, Py_ssize_t size, PyObject **exceptionObject,
+ Py_ssize_t startpos, Py_ssize_t endpos,
+ Py_ssize_t *newpos)
{
static char *argparse = "On;encoding error handler must return (str/bytes, int) tuple";
static PyObject *
unicode_encode_ucs1(const Py_UNICODE *p,
- Py_ssize_t size,
- const char *errors,
- int limit)
+ Py_ssize_t size,
+ const char *errors,
+ int limit)
{
/* output object */
PyObject *res;
PyObject *
PyUnicode_EncodeLatin1(const Py_UNICODE *p,
- Py_ssize_t size,
- const char *errors)
+ Py_ssize_t size,
+ const char *errors)
{
return unicode_encode_ucs1(p, size, errors, 256);
}