Skip to content

Commit

Permalink
Merge branch 'master' into fallback-to-use-system-hiredis-library
Browse files Browse the repository at this point in the history
  • Loading branch information
chayim authored Dec 13, 2023
2 parents dacfaf1 + 90ffc4d commit b6614ce
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 24 deletions.
29 changes: 29 additions & 0 deletions .github/spellcheck-settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
matrix:
- name: Markdown
expect_match: false
apsell:
lang: en
d: en_US
ignore-case: true
dictionary:
wordlists:
- .github/wordlist.txt
output: wordlist.dic
pipeline:
- pyspelling.filters.markdown:
markdown_extensions:
- markdown.extensions.extra:
- pyspelling.filters.html:
comments: false
attributes:
- alt
ignores:
- ':matches(code, pre)'
- code
- pre
- blockquote
- img
sources:
- 'README.md'
- 'FAQ.md'
- 'docs/**'
54 changes: 54 additions & 0 deletions .github/wordlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
ACLs
Autoloading
CAS
Customizable
ElastiCache
FPM
IANA
Kops
LRANGE
Lua
Misspelled words:
PSR
Packagist
PhpRedis
Predis
PyPI
README
Redis
SHA
SSL
TCP
TLS
URI
autoload
autoloader
autoloading
backend
backends
behaviour
benchmarking
boolean
customizable
dataset
de
dedcoded
extensibility
gcc
gevent
hiredis
keyspace
keyspaces
localhost
namespace
pipelining
pluggable
py
rebalanced
rebalancing
redis
runtime
sharding
stunnel
submodules
variadic
2 changes: 1 addition & 1 deletion .github/workflows/freebsd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ jobs:
/usr/local/bin/pip install -U pip setuptools wheel
/usr/local/bin/pip install -r dev_requirements.txt
/usr/local/bin/python3.9 setup.py build_ext --inplace
pytest
python -m pytest
python3.9 setup.py bdist_wheel
4 changes: 2 additions & 2 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
pip install -U pip setuptools wheel
pip install -r dev_requirements.txt
python setup.py build_ext --inplace
pytest
python -m pytest
- name: build and install the wheel
run: |
python setup.py bdist_wheel
python setup.py bdist_wheel
14 changes: 14 additions & 0 deletions .github/workflows/spellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: spellcheck
on:
pull_request:
jobs:
check-spelling:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Check Spelling
uses: rojopolis/[email protected]
with:
config_path: .github/spellcheck-settings.yml
task_name: Markdown
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* Implement pack_command that serializes redis-py command to the RESP bytes object.
* Implement garbage collection support in Reader (#162)

### 2.1.1 (2023-10-01)

Expand Down
26 changes: 17 additions & 9 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
Note: This license has also been called the "New BSD License" or "Modified BSD License". See also the 2-clause BSD License.
MIT License

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

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

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

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.

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.

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.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ include README.md
include src/*.[ch]
include vendor/hiredis/COPYING
include vendor/hiredis/*.[ch]
include test.py
graft test
graft tests
global-exclude __pycache__
global-exclude *.py[co]
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ It primarily speeds up parsing of multi bulk replies.

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

## How do I Redis?

[Learn for free at Redis University](https://university.redis.com/)

[Build faster with the Redis Launchpad](https://launchpad.redis.com/)

[Try the Redis Cloud](https://redis.com/try-free/)

[Dive in developer tutorials](https://developer.redis.com/)

[Join the Redis community](https://redis.com/community/)

[Work at Redis](https://redis.com/company/careers/jobs/)

## Install

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

### Requirements
Expand Down
4 changes: 2 additions & 2 deletions hiredis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .hiredis import Reader, HiredisError, pack_command, ProtocolError, ReplyError
from .version import __version__
from hiredis.hiredis import Reader, HiredisError, pack_command, ProtocolError, ReplyError
from hiredis.version import __version__

__all__ = [
"Reader",
Expand Down
2 changes: 1 addition & 1 deletion hiredis/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.2.2"
__version__ = "2.3.0"
19 changes: 14 additions & 5 deletions src/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <assert.h>

static void Reader_dealloc(hiredis_ReaderObject *self);
static int Reader_traverse(hiredis_ReaderObject *self, visitproc visit, void *arg);
static int Reader_init(hiredis_ReaderObject *self, PyObject *args, PyObject *kwds);
static PyObject *Reader_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
static PyObject *Reader_feed(hiredis_ReaderObject *self, PyObject *args);
Expand Down Expand Up @@ -44,9 +45,9 @@ PyTypeObject hiredis_ReaderType = {
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
"Hiredis protocol reader", /*tp_doc */
0, /*tp_traverse */
(traverseproc)Reader_traverse,/*tp_traverse */
0, /*tp_clear */
0, /*tp_richcompare */
0, /*tp_weaklistoffset */
Expand Down Expand Up @@ -209,16 +210,24 @@ redisReplyObjectFunctions hiredis_ObjectFunctions = {
};

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

((PyObject *)self)->ob_type->tp_free((PyObject*)self);
}

static int Reader_traverse(hiredis_ReaderObject *self, visitproc visit, void *arg) {
Py_VISIT(self->protocolErrorClass);
Py_VISIT(self->replyErrorClass);
Py_VISIT(self->notEnoughDataObject);
return 0;
}

static int _Reader_set_exception(PyObject **target, PyObject *value) {
int callable;
callable = PyCallable_Check(value);
Expand Down
Empty file removed tests/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions tests/test_gc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import gc

import hiredis


def test_reader_gc():
class A:
def __init__(self):
self.reader = hiredis.Reader(replyError=self.reply_error)

def reply_error(self, error):
return Exception()

A()
gc.collect()

assert not any(isinstance(o, A) for o in gc.get_objects()), "Referent was not collected"

0 comments on commit b6614ce

Please sign in to comment.