X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/e21f11bb2a7263033cb017793b6ec8ef33c91966..ddd4720bd8a7e04bb37ba6825b46f1bbdce9d3e7:/bytestring.c diff --git a/bytestring.c b/bytestring.c index 82d117f..3bf1b25 100644 --- a/bytestring.c +++ b/bytestring.c @@ -30,7 +30,7 @@ /*----- Main code ---------------------------------------------------------*/ -PyTypeObject *bytestring_pytype; +static PyTypeObject *bytestring_pytype; static PyObject *empty, *bytev[256]; @@ -96,11 +96,11 @@ end: return (0); } -static PyObject *meth__ByteString_zero(PyObject *me, PyObject *arg) +static PyObject *bymeth_zero(PyObject *me, PyObject *arg) { size_t sz; PyObject *rc = 0; - if (!PyArg_ParseTuple(arg, "OO&:zero", &me, convszt, &sz)) goto end; + if (!PyArg_ParseTuple(arg, "O&:zero", convszt, &sz)) goto end; rc = bytestring_pywrap(0, sz); memset(PyString_AS_STRING(rc), 0, sz); end: @@ -265,7 +265,14 @@ BINOP(xor, ^) } UNOP(not, ~) -static PyNumberMethods bytestring_pynumber = { +static const PyMethodDef bytestring_pymethods[] = { +#define METHNAME(name) bymeth_##name + SMTH (zero, "zero(N) -> 0000...00") +#undef METHNAME + { 0 } +}; + +static const PyNumberMethods bytestring_pynumber = { 0, /* @nb_add@ */ 0, /* @nb_subtract@ */ 0, /* @nb_multiply@ */ @@ -291,7 +298,7 @@ static PyNumberMethods bytestring_pynumber = { 0, /* @nb_hex@ */ }; -static PySequenceMethods bytestring_pysequence = { +static const PySequenceMethods bytestring_pysequence = { 0, /* @sq_length@ */ bytestring_pyconcat, /* @sq_concat@ */ bytestring_pyrepeat, /* @sq_repeat@ */ @@ -304,15 +311,13 @@ static PySequenceMethods bytestring_pysequence = { 0, /* @sq_inplace_repeat@ */ }; -static PyMappingMethods bytestring_pymapping = { +static const PyMappingMethods bytestring_pymapping = { 0, /* @mp_length@ */ bytestring_pysubscript, /* @mp_subscript@ */ 0, /* @mp_ass_subscript@ */ }; -static PyBufferProcs bytestring_pybuffer; - -static PyTypeObject bytestring_pytype_skel = { +static const PyTypeObject bytestring_pytype_skel = { PyObject_HEAD_INIT(0) 0, /* Header */ "ByteString", /* @tp_name@ */ 0, /* @tp_basicsize@ */ @@ -324,21 +329,21 @@ static PyTypeObject bytestring_pytype_skel = { 0, /* @tp_setattr@ */ 0, /* @tp_compare@ */ 0, /* @tp_repr@ */ - &bytestring_pynumber, /* @tp_as_number@ */ - &bytestring_pysequence, /* @tp_as_sequence@ */ - &bytestring_pymapping, /* @tp_as_mapping@ */ + PYNUMBER(bytestring), /* @tp_as_number@ */ + PYSEQUENCE(bytestring), /* @tp_as_sequence@ */ + PYMAPPING(bytestring), /* @tp_as_mapping@ */ 0, /* @tp_hash@ */ 0, /* @tp_call@ */ 0, /* @tp_str@ */ 0, /* @tp_getattro@ */ 0, /* @tp_setattro@ */ - &bytestring_pybuffer, /* @tp_as_buffer@ */ + 0, /* @tp_as_buffer@ */ Py_TPFLAGS_DEFAULT | /* @tp_flags@ */ Py_TPFLAGS_CHECKTYPES | Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"ByteString(STR): byte string class.", + "ByteString(STR): byte string class.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -346,7 +351,7 @@ static PyTypeObject bytestring_pytype_skel = { 0, /* @tp_weaklistoffset@ */ 0, /* @tp_iter@ */ 0, /* @tp_iternext@ */ - 0, /* @tp_methods@ */ + PYMETHODS(bytestring), /* @tp_methods@ */ 0, /* @tp_members@ */ 0, /* @tp_getset@ */ 0, /* @tp_base@ */ @@ -363,10 +368,9 @@ static PyTypeObject bytestring_pytype_skel = { /*----- Initialization ----------------------------------------------------*/ -static PyMethodDef methods[] = { +static const PyMethodDef methods[] = { #define METHNAME(func) meth_##func - METH (ctstreq, "ctstreq(S, T) -> BOOL") - METH (_ByteString_zero, "zero(N) -> 0000...00") + METH (ctstreq, "ctstreq(S, T) -> BOOL") #undef METHNAME { 0 } };