diff --git a/edgedb/__init__.py b/edgedb/__init__.py index 1123a15f..dff0215e 100644 --- a/edgedb/__init__.py +++ b/edgedb/__init__.py @@ -25,7 +25,7 @@ from edgedb.datatypes.datatypes import ( Tuple, NamedTuple, EnumValue, RelativeDuration, DateDuration, ConfigMemory ) -from edgedb.datatypes.datatypes import Set, Object, Array, Link, LinkSet +from edgedb.datatypes.datatypes import Object, Link, LinkSet from .abstract import ( Executor, AsyncIOExecutor, ReadOnlyExecutor, AsyncIOReadOnlyExecutor diff --git a/edgedb/abstract.py b/edgedb/abstract.py index cf4a3c5d..69f3908d 100644 --- a/edgedb/abstract.py +++ b/edgedb/abstract.py @@ -103,7 +103,7 @@ class ReadOnlyExecutor(BaseReadOnlyExecutor): def _query(self, query_context: QueryContext): ... - def query(self, query: str, *args, **kwargs) -> datatypes.Set: + def query(self, query: str, *args, **kwargs) -> list: return self._query(QueryContext( query=QueryWithArgs(query, args, kwargs), cache=self._get_query_cache(), @@ -186,7 +186,7 @@ class AsyncIOReadOnlyExecutor(BaseReadOnlyExecutor): async def _query(self, query_context: QueryContext): ... - async def query(self, query: str, *args, **kwargs) -> datatypes.Set: + async def query(self, query: str, *args, **kwargs) -> list: return await self._query(QueryContext( query=QueryWithArgs(query, args, kwargs), cache=self._get_query_cache(), diff --git a/edgedb/datatypes/array.c b/edgedb/datatypes/array.c deleted file mode 100644 index ede55253..00000000 --- a/edgedb/datatypes/array.c +++ /dev/null @@ -1,264 +0,0 @@ -/* -* This source file is part of the EdgeDB open source project. -* -* Copyright 2016-present MagicStack Inc. and the EdgeDB authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - - -#include "datatypes.h" -#include "freelist.h" -#include "internal.h" - - -static int init_type_called = 0; -static Py_hash_t base_hash = -1; - - -EDGE_SETUP_FREELIST( - EDGE_ARRAY, - EdgeArrayObject, - EDGE_ARRAY_FREELIST_MAXSAVE, - EDGE_ARRAY_FREELIST_SIZE) - - -#define EdgeArray_GET_ITEM(op, i) \ - (((EdgeArrayObject *)(op))->ob_item[i]) -#define EdgeArray_SET_ITEM(op, i, v) \ - (((EdgeArrayObject *)(op))->ob_item[i] = v) - - -PyObject * -EdgeArray_New(Py_ssize_t size) -{ - assert(init_type_called); - - EdgeArrayObject *obj = NULL; - - EDGE_NEW_WITH_FREELIST(EDGE_ARRAY, EdgeArrayObject, - &EdgeArray_Type, obj, size) - assert(obj != NULL); - assert(EdgeArray_Check(obj)); - assert(Py_SIZE(obj) == size); - - obj->cached_hash = -1; - obj->weakreflist = NULL; - - PyObject_GC_Track(obj); - return (PyObject *)obj; -} - - -int -EdgeArray_SetItem(PyObject *ob, Py_ssize_t i, PyObject *el) -{ - assert(EdgeArray_Check(ob)); - EdgeArrayObject *o = (EdgeArrayObject *)ob; - assert(i >= 0); - assert(i < Py_SIZE(o)); - Py_INCREF(el); - EdgeArray_SET_ITEM(o, i, el); - return 0; -} - - -static void -array_dealloc(EdgeArrayObject *o) -{ - o->cached_hash = -1; - PyObject_GC_UnTrack(o); - if (o->weakreflist != NULL) { - PyObject_ClearWeakRefs((PyObject*)o); - } - Py_TRASHCAN_SAFE_BEGIN(o) - EDGE_DEALLOC_WITH_FREELIST(EDGE_ARRAY, EdgeArrayObject, o); - Py_TRASHCAN_SAFE_END(o) -} - - -static Py_hash_t -array_hash(EdgeArrayObject *o) -{ - if (o->cached_hash == -1) { - o->cached_hash = _EdgeGeneric_HashWithBase( - base_hash, o->ob_item, Py_SIZE(o)); - } - return o->cached_hash; -} - - -static int -array_traverse(EdgeArrayObject *o, visitproc visit, void *arg) -{ - Py_ssize_t i; - for (i = Py_SIZE(o); --i >= 0;) { - if (o->ob_item[i] != NULL) { - Py_VISIT(o->ob_item[i]); - } - } - return 0; -} - - -static PyObject * -array_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { - PyObject *iterable = NULL; - EdgeArrayObject *o; - - if (type != &EdgeArray_Type) { - PyErr_BadInternalCall(); - return NULL; - } - - if (!_Edge_NoKeywords("edgedb.Array", kwargs) || - !PyArg_UnpackTuple(args, "edgedb.Array", 0, 1, &iterable)) - { - return NULL; - } - - if (iterable == NULL) { - return EdgeArray_New(0); - } - - PyObject *tup = PySequence_Tuple(iterable); - if (tup == NULL) { - return NULL; - } - - o = (EdgeArrayObject *)EdgeArray_New(Py_SIZE(tup)); - if (o == NULL) { - Py_DECREF(tup); - return NULL; - } - - for (Py_ssize_t i = 0; i < Py_SIZE(tup); i++) { - PyObject *el = PyTuple_GET_ITEM(tup, i); - Py_INCREF(el); - EdgeArray_SET_ITEM(o, i, el); - } - Py_DECREF(tup); - return (PyObject *)o; -} - - -static Py_ssize_t -array_length(EdgeArrayObject *o) -{ - return Py_SIZE(o); -} - - -static PyObject * -array_getitem(EdgeArrayObject *o, Py_ssize_t i) -{ - if (i < 0 || i >= Py_SIZE(o)) { - PyErr_SetString(PyExc_IndexError, "array index out of range"); - return NULL; - } - PyObject *el = EdgeArray_GET_ITEM(o, i); - Py_INCREF(el); - return el; -} - - -static PyObject * -array_richcompare(EdgeArrayObject *v, PyObject *w, int op) -{ - if (EdgeArray_Check(w)) { - return _EdgeGeneric_RichCompareValues( - v->ob_item, Py_SIZE(v), - ((EdgeArrayObject *)w)->ob_item, Py_SIZE(w), - op); - } - - if (PyList_CheckExact(w)) { - return _EdgeGeneric_RichCompareValues( - v->ob_item, Py_SIZE(v), - _PyList_ITEMS(w), Py_SIZE(w), - op); - } - - Py_RETURN_NOTIMPLEMENTED; -} - - -static PyObject * -array_repr(EdgeArrayObject *o) -{ - _PyUnicodeWriter writer; - _PyUnicodeWriter_Init(&writer); - writer.overallocate = 1; - - if (_PyUnicodeWriter_WriteChar(&writer, '[') < 0) { - goto error; - } - - if (_EdgeGeneric_RenderValues(&writer, - (PyObject *)o, o->ob_item, Py_SIZE(o)) < 0) - { - goto error; - } - - if (_PyUnicodeWriter_WriteChar(&writer, ']') < 0) { - goto error; - } - - return _PyUnicodeWriter_Finish(&writer); - -error: - _PyUnicodeWriter_Dealloc(&writer); - return NULL; -} - - -static PySequenceMethods array_as_sequence = { - .sq_length = (lenfunc)array_length, - .sq_item = (ssizeargfunc)array_getitem, -}; - - -PyTypeObject EdgeArray_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "edgedb.Array", - .tp_basicsize = sizeof(EdgeArrayObject) - sizeof(PyObject *), - .tp_itemsize = sizeof(PyObject *), - .tp_dealloc = (destructor)array_dealloc, - .tp_as_sequence = &array_as_sequence, - .tp_hash = (hashfunc)array_hash, - .tp_getattro = PyObject_GenericGetAttr, - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, - .tp_traverse = (traverseproc)array_traverse, - .tp_new = array_new, - .tp_richcompare = (richcmpfunc)array_richcompare, - .tp_free = PyObject_GC_Del, - .tp_repr = (reprfunc)array_repr, - .tp_weaklistoffset = offsetof(EdgeArrayObject, weakreflist), -}; - - -PyObject * -EdgeArray_InitType(void) -{ - if (PyType_Ready(&EdgeArray_Type) < 0) { - return NULL; - } - - base_hash = _EdgeGeneric_HashString("edgedb.Array"); - if (base_hash == -1) { - return NULL; - } - - init_type_called = 1; - return (PyObject *)&EdgeArray_Type; -} diff --git a/edgedb/datatypes/datatypes.h b/edgedb/datatypes/datatypes.h index cd0c033b..bf5ad82e 100644 --- a/edgedb/datatypes/datatypes.h +++ b/edgedb/datatypes/datatypes.h @@ -125,50 +125,6 @@ PyObject * EdgeObject_GetItem(PyObject *, Py_ssize_t); PyObject * EdgeObject_GetID(PyObject *ob); -/* === edgedb.Set =========================================== */ - -extern PyTypeObject EdgeSet_Type; - -#define EdgeSet_Check(d) (Py_TYPE(d) == &EdgeSet_Type) - -typedef struct { - PyObject_HEAD - Py_hash_t cached_hash; - PyObject *weakreflist; - PyObject *els; -} EdgeSetObject; - -PyObject * EdgeSet_InitType(void); -PyObject * EdgeSet_New(Py_ssize_t); - -int EdgeSet_SetItem(PyObject *, Py_ssize_t, PyObject *); -PyObject * EdgeSet_GetItem(PyObject *, Py_ssize_t); - -int EdgeSet_AppendItem(PyObject *, PyObject *); -Py_ssize_t EdgeSet_Len(PyObject *); - - -/* === edgedb.Array ========================================= */ - -#define EDGE_ARRAY_FREELIST_SIZE 500 -#define EDGE_ARRAY_FREELIST_MAXSAVE 10 - -extern PyTypeObject EdgeArray_Type; - -#define EdgeArray_Check(d) (Py_TYPE(d) == &EdgeArray_Type) - -typedef struct { - PyObject_VAR_HEAD - PyObject *weakreflist; - Py_hash_t cached_hash; - PyObject *ob_item[1]; -} EdgeArrayObject; - -PyObject * EdgeArray_InitType(void); -PyObject * EdgeArray_New(Py_ssize_t size); -int EdgeArray_SetItem(PyObject *, Py_ssize_t, PyObject *); - - /* === edgedb.Link ========================================== */ extern PyTypeObject EdgeLink_Type; diff --git a/edgedb/datatypes/datatypes.pxd b/edgedb/datatypes/datatypes.pxd index e44241aa..dcdd4ceb 100644 --- a/edgedb/datatypes/datatypes.pxd +++ b/edgedb/datatypes/datatypes.pxd @@ -56,16 +56,6 @@ cdef extern from "datatypes.h": int EdgeObject_SetItem(object, Py_ssize_t, object) except -1 object EdgeObject_GetRecordDesc(object) - bint EdgeSet_Check(object) - object EdgeSet_InitType() - object EdgeSet_New(Py_ssize_t); - int EdgeSet_SetItem(object, Py_ssize_t, object) except -1 - int EdgeSet_AppendItem(object, object) except -1 - - object EdgeArray_InitType() - object EdgeArray_New(Py_ssize_t); - int EdgeArray_SetItem(object, Py_ssize_t, object) except -1 - object EdgeLink_InitType() object EdgeLinkSet_InitType() @@ -78,9 +68,3 @@ cdef namedtuple_new(object namedtuple_type) cdef namedtuple_type_new(object desc) cdef object_new(object desc) cdef object_set(object tuple, Py_ssize_t pos, object elem) -cdef bint set_check(object set) -cdef set_new(Py_ssize_t size) -cdef set_set(object set, Py_ssize_t pos, object elem) -cdef set_append(object set, object elem) -cdef array_new(Py_ssize_t size) -cdef array_set(object array, Py_ssize_t pos, object elem) diff --git a/edgedb/datatypes/datatypes.pyx b/edgedb/datatypes/datatypes.pyx index 73e2432e..606ebaf5 100644 --- a/edgedb/datatypes/datatypes.pyx +++ b/edgedb/datatypes/datatypes.pyx @@ -30,8 +30,6 @@ _RecordDescriptor = EdgeRecordDesc_InitType() Tuple = tuple NamedTuple = EdgeNamedTuple_InitType() Object = EdgeObject_InitType() -Set = EdgeSet_InitType() -Array = EdgeArray_InitType() Link = EdgeLink_InitType() LinkSet = EdgeLinkSet_InitType() @@ -119,27 +117,3 @@ cdef object_new(object desc): cdef object_set(object obj, Py_ssize_t pos, object elem): EdgeObject_SetItem(obj, pos, elem) - - -cdef bint set_check(object set): - return EdgeSet_Check(set) - - -cdef set_new(Py_ssize_t size): - return EdgeSet_New(size) - - -cdef set_set(object set, Py_ssize_t pos, object elem): - EdgeSet_SetItem(set, pos, elem) - - -cdef set_append(object set, object elem): - EdgeSet_AppendItem(set, elem) - - -cdef array_new(Py_ssize_t size): - return EdgeArray_New(size) - - -cdef array_set(object array, Py_ssize_t pos, object elem): - EdgeArray_SetItem(array, pos, elem) diff --git a/edgedb/datatypes/internal.h b/edgedb/datatypes/internal.h index 4ad795fa..258e0ec4 100644 --- a/edgedb/datatypes/internal.h +++ b/edgedb/datatypes/internal.h @@ -28,13 +28,6 @@ #include "datatypes.h" -#define _Edge_IsContainer(o) \ - (PyTuple_Check(o) || \ - EdgeObject_Check(o) || \ - EdgeSet_Check(o) || \ - EdgeArray_Check(o)) - - int _Edge_NoKeywords(const char *, PyObject *); Py_hash_t _EdgeGeneric_Hash(PyObject **, Py_ssize_t); diff --git a/edgedb/datatypes/linkset.c b/edgedb/datatypes/linkset.c index 5e166657..f474c11f 100644 --- a/edgedb/datatypes/linkset.c +++ b/edgedb/datatypes/linkset.c @@ -39,11 +39,11 @@ EdgeLinkSet_New(PyObject *name, PyObject *source, PyObject *targets) return NULL; } - if (!EdgeSet_Check(targets)) { + if (!PyList_Check(targets)) { PyErr_SetString( PyExc_TypeError, "cannot construct a Link object; targets is expected " - "to be an edgedb.Set"); + "to be a list"); return NULL; } @@ -172,8 +172,8 @@ linkset_repr(EdgeLinkSetObject *o) goto error; } - for (Py_ssize_t i = 0; i < EdgeSet_Len(o->targets); i++) { - PyObject *el = EdgeSet_GetItem(o->targets, i); + for (Py_ssize_t i = 0; i < PyList_GET_SIZE(o->targets); i++) { + PyObject *el = PyList_GET_ITEM(o->targets, i); PyObject *item_repr = NULL; if (EdgeObject_Check(el)) { /* should always be the case */ @@ -200,7 +200,7 @@ linkset_repr(EdgeLinkSetObject *o) } Py_DECREF(item_repr); - if (i < EdgeSet_Len(o->targets) - 1) { + if (i < PyList_GET_SIZE(o->targets) - 1) { if (_PyUnicodeWriter_WriteASCIIString(&writer, ", ", 2) < 0) { goto error; } @@ -279,15 +279,15 @@ linkset_richcompare(EdgeLinkSetObject *v, EdgeLinkSetObject *w, int op) static Py_ssize_t linkset_length(EdgeLinkSetObject *o) { - assert(EdgeSet_Check(o->targets)); - return EdgeSet_Len(o->targets); + assert(PyList_Check(o->targets)); + return PyList_GET_SIZE(o->targets); } static PyObject * linkset_getitem(EdgeLinkSetObject *o, Py_ssize_t i) { - PyObject *target = EdgeSet_GetItem(o->targets, i); + PyObject *target = PyList_GetItem(o->targets, i); if (target == NULL) { return NULL; } diff --git a/edgedb/datatypes/object.c b/edgedb/datatypes/object.c index 83e91073..78dfd066 100644 --- a/edgedb/datatypes/object.c +++ b/edgedb/datatypes/object.c @@ -250,7 +250,7 @@ object_getitem(EdgeObject *o, PyObject *name) case L_LINK: { PyObject *val = EdgeObject_GET_ITEM(o, pos); - if (EdgeSet_Check(val)) { + if (PyList_Check(val)) { return EdgeLinkSet_New(name, (PyObject *)o, val); } else if (val == Py_None) { diff --git a/edgedb/datatypes/set.c b/edgedb/datatypes/set.c deleted file mode 100644 index cee915cc..00000000 --- a/edgedb/datatypes/set.c +++ /dev/null @@ -1,340 +0,0 @@ -/* -* This source file is part of the EdgeDB open source project. -* -* Copyright 2016-present MagicStack Inc. and the EdgeDB authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - - -#include "datatypes.h" -#include "internal.h" - - -static int init_type_called = 0; -static Py_hash_t base_hash = -1; - - -PyObject * -EdgeSet_New(Py_ssize_t size) -{ - assert(init_type_called); - - PyObject *l = PyList_New(size); - if (l == NULL) { - return NULL; - } - - EdgeSetObject *o = PyObject_GC_New(EdgeSetObject, &EdgeSet_Type); - if (o == NULL) { - Py_DECREF(l); - return NULL; - } - - o->els = l; - o->cached_hash = -1; - o->weakreflist = NULL; - - PyObject_GC_Track(o); - return (PyObject *)o; -} - - -int -EdgeSet_SetItem(PyObject *ob, Py_ssize_t pos, PyObject *el) -{ - assert(EdgeSet_Check(ob)); - EdgeSetObject *o = (EdgeSetObject *)ob; - Py_INCREF(el); - return PyList_SetItem(o->els, pos, el); -} - - -PyObject * -EdgeSet_GetItem(PyObject *ob, Py_ssize_t pos) -{ - assert(EdgeSet_Check(ob)); - EdgeSetObject *o = (EdgeSetObject *)ob; - PyObject *el = PyList_GetItem(o->els, pos); - Py_XINCREF(el); - return el; -} - - -int -EdgeSet_AppendItem(PyObject *ob, PyObject *el) -{ - assert(EdgeSet_Check(ob)); - EdgeSetObject *o = (EdgeSetObject *)ob; - return PyList_Append(o->els, el); -} - -Py_ssize_t -EdgeSet_Len(PyObject *ob) -{ - assert(EdgeSet_Check(ob)); - EdgeSetObject *o = (EdgeSetObject *)ob; - return PyList_GET_SIZE(o->els); -} - - -static PyObject * -set_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - if (args == NULL || - PyTuple_Size(args) != 1 || - (kwds != NULL && PyDict_Size(kwds))) - { - PyErr_SetString( - PyExc_TypeError, - "edgedb.Set accepts only one positional argument"); - return NULL; - } - - EdgeSetObject *o = (EdgeSetObject *)EdgeSet_New(0); - if (o == NULL) { - return NULL; - } - - PyObject *res = _PyList_Extend((PyListObject *)o->els, - PyTuple_GET_ITEM(args, 0)); - if (res == NULL) { - Py_DECREF(o); - return NULL; - } - Py_DECREF(res); - - return (PyObject *)o; -} - - -static int -set_traverse(EdgeSetObject *o, visitproc visit, void *arg) -{ - Py_VISIT(o->els); - return 0; -} - - -static void -set_dealloc(EdgeSetObject *o) -{ - PyObject_GC_UnTrack(o); - if (o->weakreflist != NULL) { - PyObject_ClearWeakRefs((PyObject*)o); - } - Py_TRASHCAN_SAFE_BEGIN(o) - o->cached_hash = -1; - Py_CLEAR(o->els); - Py_TRASHCAN_SAFE_END(o) - Py_TYPE(o)->tp_free((PyObject *)o); -} - - -static Py_hash_t -set_hash(EdgeSetObject *o) -{ - if (o->cached_hash == -1) { - o->cached_hash = _EdgeGeneric_HashWithBase( - base_hash, - _PyList_ITEMS(o->els), - PyList_GET_SIZE(o->els)); - } - return o->cached_hash; -} - - -static Py_ssize_t -set_length(EdgeSetObject *o) -{ - return PyList_GET_SIZE(o->els); -} - - -static PyObject * -set_getitem(EdgeSetObject *o, Py_ssize_t i) -{ - if (i < 0 || i >= PyList_GET_SIZE(o->els)) { - PyErr_SetString(PyExc_IndexError, "edgedb.Set index out of range"); - return NULL; - } - PyObject *val = PyList_GetItem(o->els, i); - Py_INCREF(val); - return val; -} - - -static PyObject * -set_richcompare(EdgeSetObject *v, PyObject *ww, int op) -{ - if (op != Py_EQ && op != Py_NE) { - goto not_imp; - } - - if (PyList_CheckExact(ww)) { - return PyObject_RichCompare(v->els, ww, op); - } - - if (!EdgeSet_Check(ww)) { - goto not_imp; - } - - EdgeSetObject *w = (EdgeSetObject *)ww; - - int res = -1; - Py_ssize_t vlen = PyList_Size(v->els); - - if (vlen != PyList_Size(w->els)) { - res = 0; - goto done; - } - - if (vlen == 1) { - res = PyObject_RichCompareBool(v->els, w->els, Py_EQ); - if (res < 0) { - return NULL; - } - goto done; - } - - PyObject *left = NULL; - PyObject *right = NULL; - - left = PyList_GetSlice(v->els, 0, vlen); - if (left == NULL) { - goto error; - } - - right = PyList_GetSlice(w->els, 0, vlen); - if (right == NULL) { - goto error; - } - - if (PyList_Sort(left) < 0) { - goto error; - } - - if (PyList_Sort(right) < 0) { - goto error; - } - - res = PyObject_RichCompareBool(left, right, Py_EQ); - Py_CLEAR(left); - Py_CLEAR(right); - if (res < 0) { - goto error; - } - goto done; - -error: - Py_XDECREF(left); - Py_XDECREF(right); - return NULL; - -not_imp: - Py_RETURN_NOTIMPLEMENTED; - -done: - assert(res != -1); - - if (op == Py_NE) { - res = !res; - } - - if (res) { - Py_RETURN_TRUE; - } - else { - Py_RETURN_FALSE; - } -} - - -static PyObject * -set_iter(EdgeSetObject *o) -{ - return Py_TYPE(o->els)->tp_iter(o->els); -} - - -static PyObject * -set_repr(EdgeSetObject *o) -{ - _PyUnicodeWriter writer; - _PyUnicodeWriter_Init(&writer); - writer.overallocate = 1; - - if (_PyUnicodeWriter_WriteASCIIString(&writer, "Set{", 4) < 0) { - goto error; - } - - if (_EdgeGeneric_RenderValues(&writer, (PyObject *)o, - _PyList_ITEMS(o->els), - PyList_GET_SIZE(o->els)) < 0) - { - goto error; - } - - if (_PyUnicodeWriter_WriteChar(&writer, '}') < 0) { - goto error; - } - - return _PyUnicodeWriter_Finish(&writer); - -error: - _PyUnicodeWriter_Dealloc(&writer); - return NULL; -} - - - -static PySequenceMethods set_as_sequence = { - .sq_length = (lenfunc)set_length, - .sq_item = (ssizeargfunc)set_getitem, -}; - - -PyTypeObject EdgeSet_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "edgedb.Set", - .tp_basicsize = sizeof(EdgeSetObject), - .tp_dealloc = (destructor)set_dealloc, - .tp_getattro = PyObject_GenericGetAttr, - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, - .tp_traverse = (traverseproc)set_traverse, - .tp_new = set_tp_new, - .tp_hash = (hashfunc)set_hash, - .tp_as_sequence = &set_as_sequence, - .tp_richcompare = (richcmpfunc)set_richcompare, - .tp_iter = (getiterfunc)set_iter, - .tp_repr = (reprfunc)set_repr, - .tp_free = PyObject_GC_Del, - .tp_weaklistoffset = offsetof(EdgeSetObject, weakreflist), -}; - - -PyObject * -EdgeSet_InitType(void) -{ - if (PyType_Ready(&EdgeSet_Type) < 0) { - return NULL; - } - - base_hash = _EdgeGeneric_HashString("edgedb.Set"); - if (base_hash == -1) { - return NULL; - } - - init_type_called = 1; - return (PyObject *)&EdgeSet_Type; -} diff --git a/edgedb/protocol/codecs/array.pxd b/edgedb/protocol/codecs/array.pxd index 32159c0b..44de315b 100644 --- a/edgedb/protocol/codecs/array.pxd +++ b/edgedb/protocol/codecs/array.pxd @@ -23,11 +23,6 @@ cdef class BaseArrayCodec(BaseCodec): BaseCodec sub_codec int32_t cardinality - cdef _new_collection(self, Py_ssize_t size) - - cdef _set_collection_item(self, object collection, Py_ssize_t i, - object element) - cdef _decode_array(self, FRBuffer *buf) diff --git a/edgedb/protocol/codecs/array.pyx b/edgedb/protocol/codecs/array.pyx index e3e8997d..1a10c7dd 100644 --- a/edgedb/protocol/codecs/array.pyx +++ b/edgedb/protocol/codecs/array.pyx @@ -30,13 +30,6 @@ cdef class BaseArrayCodec(BaseCodec): self.sub_codec = None self.cardinality = -1 - cdef _new_collection(self, Py_ssize_t size): - raise NotImplementedError - - cdef _set_collection_item(self, object collection, Py_ssize_t i, - object element): - raise NotImplementedError - cdef encode(self, WriteBuffer buf, object obj): cdef: WriteBuffer elem_data @@ -102,7 +95,7 @@ cdef class BaseArrayCodec(BaseCodec): raise RuntimeError('only 1-dimensional arrays are supported') if ndims == 0: - return self._new_collection(0) + return [] assert ndims == 1 @@ -115,7 +108,7 @@ cdef class BaseArrayCodec(BaseCodec): frb_read(buf, 4) # Ignore the lower bound information - result = self._new_collection(elem_count) + result = cpython.PyList_New(elem_count) for i in range(elem_count): elem_len = hton.unpack_int32(frb_read(buf, 4)) if elem_len == -1: @@ -128,7 +121,8 @@ cdef class BaseArrayCodec(BaseCodec): f'unexpected trailing data in buffer after ' f'array element decoding: {frb_get_len(&elem_buf)}') - self._set_collection_item(result, i, elem) + cpython.Py_INCREF(elem) + cpython.PyList_SET_ITEM(result, i, elem) return result @@ -139,13 +133,6 @@ cdef class BaseArrayCodec(BaseCodec): @cython.final cdef class ArrayCodec(BaseArrayCodec): - cdef _new_collection(self, Py_ssize_t size): - return datatypes.array_new(size) - - cdef _set_collection_item(self, object collection, Py_ssize_t i, - object element): - datatypes.array_set(collection, i, element) - @staticmethod cdef BaseCodec new(bytes tid, BaseCodec sub_codec, int32_t cardinality): cdef: diff --git a/edgedb/protocol/codecs/set.pyx b/edgedb/protocol/codecs/set.pyx index bda8f9da..f1f43712 100644 --- a/edgedb/protocol/codecs/set.pyx +++ b/edgedb/protocol/codecs/set.pyx @@ -20,13 +20,6 @@ @cython.final cdef class SetCodec(BaseArrayCodec): - cdef _new_collection(self, Py_ssize_t size): - return datatypes.set_new(size) - - cdef _set_collection_item(self, object collection, Py_ssize_t i, - object element): - datatypes.set_set(collection, i, element) - @staticmethod cdef BaseCodec new(bytes tid, BaseCodec sub_codec): cdef: @@ -66,7 +59,7 @@ cdef class SetCodec(BaseArrayCodec): if ndims == 0: # Special case for an empty set. - return self._new_collection(0) + return [] elif ndims > 1: raise RuntimeError('expected a two-dimensional array for a ' 'set of arrays') @@ -74,7 +67,7 @@ cdef class SetCodec(BaseArrayCodec): elem_count = hton.unpack_int32(frb_read(buf, 4)) frb_read(buf, 4) # Ignore the lower bound information - result = self._new_collection(elem_count) + result = cpython.PyList_New(elem_count) for i in range(elem_count): frb_read(buf, 4) # ignore array element size @@ -97,6 +90,7 @@ cdef class SetCodec(BaseArrayCodec): raise RuntimeError( f'unexpected trailing data in buffer after ' f'set element decoding: {frb_get_len(&elem_buf)}') - self._set_collection_item(result, i, elem) + cpython.Py_INCREF(elem) + cpython.PyList_SET_ITEM(result, i, elem) return result diff --git a/edgedb/protocol/protocol.pyx b/edgedb/protocol/protocol.pyx index aeb953a4..3c361ade 100644 --- a/edgedb/protocol/protocol.pyx +++ b/edgedb/protocol/protocol.pyx @@ -381,7 +381,7 @@ cdef class SansIOProtocol: packet.write_bytes(SYNC_MESSAGE) self.write(packet) - result = datatypes.set_new(0) + result = [] exc = None while True: if not self.buffer.take_message(): @@ -1176,9 +1176,9 @@ cdef class SansIOProtocol: if buf.get_message_type() != DATA_MSG: raise RuntimeError('first message is not "DataMsg"') - if not datatypes.set_check(result): + if not isinstance(result, list): raise RuntimeError( - f'result is not an edgedb.Set, but {result!r}') + f'result is not a list, but {result!r}') while take_message_type(buf, DATA_MSG): cbuf = try_consume_message(buf, &cbuf_len) @@ -1207,7 +1207,7 @@ cdef class SansIOProtocol: frb_init(rbuf, cbuf + 6, cbuf_len - 6) row = decoder(out_dc, rbuf) - datatypes.set_append(result, row) + result.append(row) if frb_get_len(rbuf): raise RuntimeError( diff --git a/edgedb/protocol/protocol_v0.pyx b/edgedb/protocol/protocol_v0.pyx index b81c5b08..399f803c 100644 --- a/edgedb/protocol/protocol_v0.pyx +++ b/edgedb/protocol/protocol_v0.pyx @@ -175,7 +175,7 @@ cdef class SansIOProtocolBackwardsCompatible(SansIOProtocol): packet.write_bytes(SYNC_MESSAGE) self.write(packet) - result = datatypes.set_new(0) + result = [] exc = None while True: @@ -269,7 +269,7 @@ cdef class SansIOProtocolBackwardsCompatible(SansIOProtocol): packet.write_bytes(SYNC_MESSAGE) self.write(packet) - result = datatypes.set_new(0) + result = [] re_exec = False exc = None while True: diff --git a/setup.py b/setup.py index a590c8ff..4aeaf0ed 100644 --- a/setup.py +++ b/setup.py @@ -304,9 +304,7 @@ def finalize_options(self): "edgedb/datatypes/record_desc.c", "edgedb/datatypes/namedtuple.c", "edgedb/datatypes/object.c", - "edgedb/datatypes/set.c", "edgedb/datatypes/hash.c", - "edgedb/datatypes/array.c", "edgedb/datatypes/link.c", "edgedb/datatypes/linkset.c", "edgedb/datatypes/repr.c",