Skip to content

Commit b6614ce

Browse files
authored
Merge branch 'master' into fallback-to-use-system-hiredis-library
2 parents dacfaf1 + 90ffc4d commit b6614ce

File tree

15 files changed

+169
-24
lines changed

15 files changed

+169
-24
lines changed

.github/spellcheck-settings.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
matrix:
2+
- name: Markdown
3+
expect_match: false
4+
apsell:
5+
lang: en
6+
d: en_US
7+
ignore-case: true
8+
dictionary:
9+
wordlists:
10+
- .github/wordlist.txt
11+
output: wordlist.dic
12+
pipeline:
13+
- pyspelling.filters.markdown:
14+
markdown_extensions:
15+
- markdown.extensions.extra:
16+
- pyspelling.filters.html:
17+
comments: false
18+
attributes:
19+
- alt
20+
ignores:
21+
- ':matches(code, pre)'
22+
- code
23+
- pre
24+
- blockquote
25+
- img
26+
sources:
27+
- 'README.md'
28+
- 'FAQ.md'
29+
- 'docs/**'

.github/wordlist.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
ACLs
2+
Autoloading
3+
CAS
4+
Customizable
5+
ElastiCache
6+
FPM
7+
IANA
8+
Kops
9+
LRANGE
10+
Lua
11+
Misspelled words:
12+
PSR
13+
Packagist
14+
PhpRedis
15+
Predis
16+
PyPI
17+
README
18+
Redis
19+
SHA
20+
SSL
21+
TCP
22+
TLS
23+
URI
24+
autoload
25+
autoloader
26+
autoloading
27+
backend
28+
backends
29+
behaviour
30+
benchmarking
31+
boolean
32+
customizable
33+
dataset
34+
de
35+
dedcoded
36+
extensibility
37+
gcc
38+
gevent
39+
hiredis
40+
keyspace
41+
keyspaces
42+
localhost
43+
namespace
44+
pipelining
45+
pluggable
46+
py
47+
rebalanced
48+
rebalancing
49+
redis
50+
runtime
51+
sharding
52+
stunnel
53+
submodules
54+
variadic

.github/workflows/freebsd.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ jobs:
4343
/usr/local/bin/pip install -U pip setuptools wheel
4444
/usr/local/bin/pip install -r dev_requirements.txt
4545
/usr/local/bin/python3.9 setup.py build_ext --inplace
46-
pytest
46+
python -m pytest
4747
python3.9 setup.py bdist_wheel

.github/workflows/integration.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
pip install -U pip setuptools wheel
4646
pip install -r dev_requirements.txt
4747
python setup.py build_ext --inplace
48-
pytest
48+
python -m pytest
4949
- name: build and install the wheel
5050
run: |
51-
python setup.py bdist_wheel
51+
python setup.py bdist_wheel

.github/workflows/spellcheck.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: spellcheck
2+
on:
3+
pull_request:
4+
jobs:
5+
check-spelling:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout
9+
uses: actions/checkout@v3
10+
- name: Check Spelling
11+
uses: rojopolis/[email protected]
12+
with:
13+
config_path: .github/spellcheck-settings.yml
14+
task_name: Markdown

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
* Implement pack_command that serializes redis-py command to the RESP bytes object.
2+
* Implement garbage collection support in Reader (#162)
23

34
### 2.1.1 (2023-10-01)
45

LICENSE

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
Note: This license has also been called the "New BSD License" or "Modified BSD License". See also the 2-clause BSD License.
1+
MIT License
22

3-
Copyright 2011 Pieter Noordhuis
3+
Copyright (c) 2022-2023, the maintainers of this library.
44

5-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
611

7-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
814

9-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10-
11-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
12-
13-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MANIFEST.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ include README.md
44
include src/*.[ch]
55
include vendor/hiredis/COPYING
66
include vendor/hiredis/*.[ch]
7-
include test.py
8-
graft test
7+
graft tests
98
global-exclude __pycache__
109
global-exclude *.py[co]

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ It primarily speeds up parsing of multi bulk replies.
88

99
[hiredis]: http://github.com/redis/hiredis
1010

11+
## How do I Redis?
12+
13+
[Learn for free at Redis University](https://university.redis.com/)
14+
15+
[Build faster with the Redis Launchpad](https://launchpad.redis.com/)
16+
17+
[Try the Redis Cloud](https://redis.com/try-free/)
18+
19+
[Dive in developer tutorials](https://developer.redis.com/)
20+
21+
[Join the Redis community](https://redis.com/community/)
22+
23+
[Work at Redis](https://redis.com/company/careers/jobs/)
24+
1125
## Install
1226

1327
hiredis-py is available on [PyPI](https://pypi.org/project/hiredis/), and can be installed via:
@@ -22,7 +36,7 @@ Building this repository requires a recursive checkout of submodules, and buildi
2236
```bash
2337
git clone --recursse-submodules https://github.com/redis/hiredis-py
2438
python setup.py build_ext --inplace
25-
pytest
39+
python -m pytest
2640
```
2741

2842
### Requirements

hiredis/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .hiredis import Reader, HiredisError, pack_command, ProtocolError, ReplyError
2-
from .version import __version__
1+
from hiredis.hiredis import Reader, HiredisError, pack_command, ProtocolError, ReplyError
2+
from hiredis.version import __version__
33

44
__all__ = [
55
"Reader",

hiredis/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.2.2"
1+
__version__ = "2.3.0"

src/reader.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <assert.h>
44

55
static void Reader_dealloc(hiredis_ReaderObject *self);
6+
static int Reader_traverse(hiredis_ReaderObject *self, visitproc visit, void *arg);
67
static int Reader_init(hiredis_ReaderObject *self, PyObject *args, PyObject *kwds);
78
static PyObject *Reader_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
89
static PyObject *Reader_feed(hiredis_ReaderObject *self, PyObject *args);
@@ -44,9 +45,9 @@ PyTypeObject hiredis_ReaderType = {
4445
0, /*tp_getattro*/
4546
0, /*tp_setattro*/
4647
0, /*tp_as_buffer*/
47-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
48+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
4849
"Hiredis protocol reader", /*tp_doc */
49-
0, /*tp_traverse */
50+
(traverseproc)Reader_traverse,/*tp_traverse */
5051
0, /*tp_clear */
5152
0, /*tp_richcompare */
5253
0, /*tp_weaklistoffset */
@@ -209,16 +210,24 @@ redisReplyObjectFunctions hiredis_ObjectFunctions = {
209210
};
210211

211212
static void Reader_dealloc(hiredis_ReaderObject *self) {
213+
PyObject_GC_UnTrack(self);
212214
// we don't need to free self->encoding as the buffer is managed by Python
213215
// https://docs.python.org/3/c-api/arg.html#strings-and-buffers
214216
redisReaderFree(self->reader);
215-
Py_XDECREF(self->protocolErrorClass);
216-
Py_XDECREF(self->replyErrorClass);
217-
Py_XDECREF(self->notEnoughDataObject);
217+
Py_CLEAR(self->protocolErrorClass);
218+
Py_CLEAR(self->replyErrorClass);
219+
Py_CLEAR(self->notEnoughDataObject);
218220

219221
((PyObject *)self)->ob_type->tp_free((PyObject*)self);
220222
}
221223

224+
static int Reader_traverse(hiredis_ReaderObject *self, visitproc visit, void *arg) {
225+
Py_VISIT(self->protocolErrorClass);
226+
Py_VISIT(self->replyErrorClass);
227+
Py_VISIT(self->notEnoughDataObject);
228+
return 0;
229+
}
230+
222231
static int _Reader_set_exception(PyObject **target, PyObject *value) {
223232
int callable;
224233
callable = PyCallable_Check(value);

tests/__init__.py

Whitespace-only changes.

tests/test_gc.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import gc
2+
3+
import hiredis
4+
5+
6+
def test_reader_gc():
7+
class A:
8+
def __init__(self):
9+
self.reader = hiredis.Reader(replyError=self.reply_error)
10+
11+
def reply_error(self, error):
12+
return Exception()
13+
14+
A()
15+
gc.collect()
16+
17+
assert not any(isinstance(o, A) for o in gc.get_objects()), "Referent was not collected"

0 commit comments

Comments
 (0)