diff options
| author | Cyrille Bagard <nocbos@gmail.com> | 2024-06-24 21:55:03 (GMT) | 
|---|---|---|
| committer | Cyrille Bagard <nocbos@gmail.com> | 2024-06-24 21:55:03 (GMT) | 
| commit | 1e30e2c3822f55848e2306e59a2e66d7285f6b78 (patch) | |
| tree | 7a0fd0bce0f27dceb19b0596cc7a00962c3435ad /plugins/pychrysalide/common/bits.c | |
| parent | d49b837c891e0490167b51c4a9811cb2e8276588 (diff) | |
Create functions suitable for [un]setting only one bit.
Diffstat (limited to 'plugins/pychrysalide/common/bits.c')
| -rw-r--r-- | plugins/pychrysalide/common/bits.c | 32 | 
1 files changed, 22 insertions, 10 deletions
| diff --git a/plugins/pychrysalide/common/bits.c b/plugins/pychrysalide/common/bits.c index a127251..35d6ea4 100644 --- a/plugins/pychrysalide/common/bits.c +++ b/plugins/pychrysalide/common/bits.c @@ -534,27 +534,33 @@ static PyObject *py_bitfield_set_all(PyObject *self, PyObject *args)  static PyObject *py_bitfield_reset(PyObject *self, PyObject *args)  { -    unsigned long first;                    /* Indice du premier bit testé */      unsigned long count;                    /* Nombre de bits à analyser   */ +    unsigned long first;                    /* Indice du premier bit testé */      int ret;                                /* Bilan de lecture des args.  */      py_bitfield_t *bf;                      /* Instance à manipuler        */  #define BITFIELD_RESET_METHOD PYTHON_METHOD_DEF             \  (                                                           \ -    reset, "$self, first, count, /",                        \ +    reset, "$self, first, /, count=1",                      \      METH_VARARGS, py_bitfield,                              \      "Switch to 0 a part of bits in a bitfield.\n"           \      "\n"                                                    \      "The area to process starts at bit *first* and has a"   \ -    " size of *count* bits."                                \ +    " size of *count* bits (only one bit is processed if"   \ +    " no *size* is provided)."                              \  ) -    ret = PyArg_ParseTuple(args, "kk", &first, &count); +    count = 1; + +    ret = PyArg_ParseTuple(args, "k|k", &first, &count);      if (!ret) return NULL;      bf = (py_bitfield_t *)self; -    reset_in_bit_field(bf->native, first, count); +    if (count == 1) +        reset_in_bit_field(bf->native, first); +    else +        reset_multi_in_bit_field(bf->native, first, count);      Py_RETURN_NONE; @@ -576,27 +582,33 @@ static PyObject *py_bitfield_reset(PyObject *self, PyObject *args)  static PyObject *py_bitfield_set(PyObject *self, PyObject *args)  { -    unsigned long first;                    /* Indice du premier bit testé */      unsigned long count;                    /* Nombre de bits à analyser   */ +    unsigned long first;                    /* Indice du premier bit testé */      int ret;                                /* Bilan de lecture des args.  */      py_bitfield_t *bf;                      /* Instance à manipuler        */  #define BITFIELD_SET_METHOD PYTHON_METHOD_DEF               \  (                                                           \ -    set, "$self, first, count, /",                          \ +    set, "$self, first, /, count=1",                        \      METH_VARARGS, py_bitfield,                              \      "Switch to 1 a part of bits in a bitfield.\n"           \      "\n"                                                    \      "The area to process starts at bit *first* and has a"   \ -    " size of *count* bits."                                \ +    " size of *count* bits (only one bit is processed if"   \ +    " no *size* is provided)."                              \  ) -    ret = PyArg_ParseTuple(args, "kk", &first, &count); +    count = 1; + +    ret = PyArg_ParseTuple(args, "k|k", &first, &count);      if (!ret) return NULL;      bf = (py_bitfield_t *)self; -    set_in_bit_field(bf->native, first, count); +    if (count == 1) +        set_in_bit_field(bf->native, first); +    else +        set_multi_in_bit_field(bf->native, first, count);      Py_RETURN_NONE; | 
