-
Notifications
You must be signed in to change notification settings - Fork 10
BREAKING CHANGE: buffer expose as bytes instead of str #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
src/questdb/ingress.pyi
Outdated
""" | ||
|
||
def __str__(self) -> str: | ||
"""Return the constructed buffer as a string. Use for debugging.""" | ||
def peek(self) -> bytes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Python it would be idiomatic to use __bytes__
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/questdb/extra_cpython.pxd
Outdated
# Ditto, see comment on why not returning a `PyObject` above. | ||
object PyBytes_FromStringAndSize( | ||
const char* u, Py_ssize_t size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove.
This is already defined in the cython standard lib correctly.
See: https://github.com/cython/cython/blob/master/Cython/Includes/cpython/bytes.pxd where it defines:
bytes PyBytes_FromStringAndSize(char *v, Py_ssize_t len)
Usage within ingress.pyx
would be something like:
from cpython.bytes cimport PyBytes_FromStringAndSize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/questdb/ingress.pyi
Outdated
@@ -345,11 +345,11 @@ class Buffer: | |||
""" | |||
The current number of bytes currently in the buffer. | |||
|
|||
Equivalent (but cheaper) to ``len(str(sender))``. | |||
Equivalent (but cheaper) to ``len(buffer.peek())``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update docs to to len(bytes(buffer))
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/questdb/ingress.pyi
Outdated
""" | ||
|
||
def __str__(self) -> str: | ||
"""Return the constructed buffer as a string. Use for debugging.""" | ||
def peek(self) -> bytes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__bytes__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/questdb/ingress.pyi
Outdated
|
||
Also see :func:`Sender.__len__`. | ||
Equivalent (but cheaper) to ``len(sender.peek())``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/questdb/ingress.pyi
Outdated
""" | ||
|
||
def __len__(self) -> int: | ||
def peek(self) -> bytes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__bytes__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/questdb/ingress.pyx
Outdated
@@ -825,18 +825,20 @@ cdef class Buffer: | |||
""" | |||
The current number of bytes currently in the buffer. | |||
|
|||
Equivalent (but cheaper) to ``len(str(sender))``. | |||
Equivalent (but cheaper) to ``len(buffer.peek())``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update doc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/questdb/ingress.pyx
Outdated
""" | ||
return line_sender_buffer_size(self._impl) | ||
|
||
def __str__(self) -> str: | ||
def peek(self) -> bytes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__bytes__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/questdb/ingress.pyx
Outdated
return PyUnicode_FromStringAndSize(utf8, <Py_ssize_t>size) | ||
cdef inline object _to_bytes(self): | ||
cdef line_sender_buffer_view view = line_sender_buffer_peek(self._impl) | ||
if view.len: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if statement is redundant here I think. Impl:
PyObject *
PyBytes_FromStringAndSize(const char *str, Py_ssize_t size)
{
PyBytesObject *op;
if (size < 0) {
PyErr_SetString(PyExc_SystemError,
"Negative size passed to PyBytes_FromStringAndSize");
return NULL;
}
if (size == 1 && str != NULL) {
op = CHARACTER(*str & 255);
assert(_Py_IsImmortal(op));
return (PyObject *)op;
}
if (size == 0) {
return bytes_get_empty(); // <<<<<<<<<<<<<<<<<<<
}
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, PyBytes_FromStringAndSize
handles the <= 0 case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor tweaks required.
CI needs a tweak as well:
I suspect |
Yeah, macOS-12 has been moved |
BREAKING CHANGE: buffer expose as bytes instead of str