Skip to content

Commit b158d3f

Browse files
committed
Rename inited to initialized, convert to bool
1 parent 1978904 commit b158d3f

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

Modules/_zstd/_zstdmodule.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Python module.
1111
#include "zstd.h"
1212
#include "zdict.h"
1313

14+
#include <stdbool.h> // bool
15+
1416

1517
/* Forward declaration of module state */
1618
typedef struct _zstd_state _zstd_state;
@@ -61,7 +63,7 @@ typedef struct {
6163
uint32_t dict_id;
6264

6365
/* __init__ has been called, 0 or 1. */
64-
int inited;
66+
bool initialized;
6567
} ZstdDict;
6668

6769
typedef struct {
@@ -83,7 +85,7 @@ typedef struct {
8385
int compression_level;
8486

8587
/* __init__ has been called, 0 or 1. */
86-
int inited;
88+
bool initialized;
8789
} ZstdCompressor;
8890

8991
typedef struct {
@@ -120,7 +122,7 @@ typedef struct {
120122
char _unused_char_for_align;
121123

122124
/* __init__ has been called, 0 or 1. */
123-
int inited;
125+
bool initialized;
124126
} ZstdDecompressor;
125127

126128
typedef enum {
@@ -163,5 +165,3 @@ set_zstd_error(const _zstd_state* const state,
163165
extern void
164166
set_parameter_error(const _zstd_state* const state, int is_compress,
165167
int key_v, int value_v);
166-
167-
static const char init_twice_msg[] = "__init__ method is called twice.";

Modules/_zstd/compressor.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class _zstd.ZstdCompressor "ZstdCompressor *" "clinic_state()->ZstdCompressor_ty
2020

2121
#include "buffer.h"
2222

23+
#include <stdbool.h> // bool
2324
#include <stddef.h> // offsetof()
2425

2526

@@ -305,7 +306,7 @@ _zstd_ZstdCompressor_new(PyTypeObject *type, PyObject *Py_UNUSED(args), PyObject
305306
goto error;
306307
}
307308

308-
self->inited = 0;
309+
self->initialized = 0;
309310
self->dict = NULL;
310311
self->use_multithread = 0;
311312

@@ -372,12 +373,11 @@ _zstd_ZstdCompressor___init___impl(ZstdCompressor *self, PyObject *level,
372373
PyObject *options, PyObject *zstd_dict)
373374
/*[clinic end generated code: output=215e6c4342732f96 input=9f79b0d8d34c8ef0]*/
374375
{
375-
/* Only called once */
376-
if (self->inited) {
377-
PyErr_SetString(PyExc_RuntimeError, init_twice_msg);
376+
if (self->initialized) {
377+
PyErr_SetString(PyExc_RuntimeError, "reinitialization not supported");
378378
return -1;
379379
}
380-
self->inited = 1;
380+
self->initialized = 1;
381381

382382
if (level != Py_None && options != Py_None) {
383383
PyErr_SetString(PyExc_RuntimeError, "Only one of level or options should be used.");

Modules/_zstd/decompressor.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class _zstd.ZstdDecompressor "ZstdDecompressor *" "clinic_state()->ZstdDecompres
1919

2020
#include "buffer.h"
2121

22+
#include <stdbool.h> // bool
2223
#include <stddef.h> // offsetof()
2324

2425
#define ZstdDecompressor_CAST(op) ((ZstdDecompressor *)op)
@@ -616,7 +617,7 @@ _zstd_ZstdDecompressor_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
616617
goto error;
617618
}
618619

619-
self->inited = 0;
620+
self->initialized = 0;
620621
self->dict = NULL;
621622
self->input_buffer = NULL;
622623
self->input_buffer_size = 0;
@@ -695,11 +696,11 @@ _zstd_ZstdDecompressor___init___impl(ZstdDecompressor *self,
695696
/*[clinic end generated code: output=703af2f1ec226642 input=8fd72999acc1a146]*/
696697
{
697698
/* Only called once */
698-
if (self->inited) {
699-
PyErr_SetString(PyExc_RuntimeError, init_twice_msg);
699+
if (self->initialized) {
700+
PyErr_SetString(PyExc_RuntimeError, "reinitialization not supported");
700701
return -1;
701702
}
702-
self->inited = 1;
703+
self->initialized = 1;
703704

704705
/* Load dictionary to decompression context */
705706
if (zstd_dict != Py_None) {

Modules/_zstd/zstddict.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class _zstd.ZstdDict "ZstdDict *" "clinic_state()->ZstdDict_type"
1717

1818
#include "_zstdmodule.h"
1919

20+
#include <stdbool.h> // bool
2021
#include <stddef.h> // offsetof()
2122

2223
#define ZstdDict_CAST(op) ((ZstdDict *)op)
@@ -31,7 +32,7 @@ _zstd_ZstdDict_new(PyTypeObject *type, PyObject *Py_UNUSED(args), PyObject *Py_U
3132
}
3233

3334
self->dict_content = NULL;
34-
self->inited = 0;
35+
self->initialized = 0;
3536
self->d_dict = NULL;
3637

3738
/* ZSTD_CDict dict */
@@ -92,11 +93,11 @@ _zstd_ZstdDict___init___impl(ZstdDict *self, PyObject *dict_content,
9293
/*[clinic end generated code: output=c5f5a0d8377d037c input=e6750f62a513b3ee]*/
9394
{
9495
/* Only called once */
95-
if (self->inited) {
96-
PyErr_SetString(PyExc_RuntimeError, init_twice_msg);
96+
if (self->initialized) {
97+
PyErr_SetString(PyExc_RuntimeError, "reinitialization not supported");
9798
return -1;
9899
}
99-
self->inited = 1;
100+
self->initialized = 1;
100101

101102
/* Check dict_content's type */
102103
self->dict_content = PyBytes_FromObject(dict_content);

0 commit comments

Comments
 (0)