• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PredatorCZ / PreCore / 460

pending completion
460

push

github-actions-ci

PredatorCZ
try fix coverage

3204 of 6095 relevant lines covered (52.57%)

354.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.6
/include/python/uni/list.hpp
1
/*  Python binding class for uni::List
2
    part of uni module
3
    Copyright 2020-2022 Lukas Cone
4

5
    Licensed under the Apache License, Version 2.0 (the "License");
6
    you may not use this file except in compliance with the License.
7
    You may obtain a copy of the License at
8

9
        http://www.apache.org/licenses/LICENSE-2.0
10

11
    Unless required by applicable law or agreed to in writing, software
12
    distributed under the License is distributed on an "AS IS" BASIS,
13
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
    See the License for the specific language governing permissions and
15
    limitations under the License.
16
*/
17

18
#pragma once
19
#include "spike/uni/list.hpp"
20
#include <Python.h>
21
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
22

23
namespace UniPy {
24

25
template <class Info> struct List {
26
  using item_type = typename Info::item_type;
27
  using wrap_type = typename Info::wrap_type;
28
  using value_type = uni::Element<const uni::List<item_type>>;
29
  PyObject_HEAD;
30
  union {
31
    value_type cList;
32
    uni::Element<uni::List<item_type>> mList;
33
  };
34
  size_t iterPos;
35

36
  static PyTypeObject *GetType() {
37

38
    static PyMappingMethods mappingMethods = {
39
        (lenfunc)List::Len,
40
        (binaryfunc)List::Subscript,
41
        0,
42
    };
43

44
    static PyTypeObject typeObject{
45
        .tp_name = Info::GetName(),
46
        .tp_basicsize = sizeof(List),
47
        .tp_dealloc = (destructor)List::Dealloc,
48
        .tp_as_mapping = &mappingMethods,
49
        .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT,
50
        .tp_doc = Info::GetDoc(),
51
        .tp_iter = (getiterfunc)List::Iter,
52
        .tp_iternext = (iternextfunc)List::IterNext,
53
    };
54

55
    return &typeObject;
56
  }
57

58
  static void Dealloc(List *self) {
10✔
59
    auto t0 = std::move(self->cList);
60
    Py_TYPE(self)->tp_free(self);
10✔
61
  }
10✔
62

1✔
63
  static size_t Len(List *self) { return self->cList->Size(); }
64

1✔
65
  static PyObject *Subscript(List *self, PyObject *index) {
1✔
66
    const auto id = PyLong_AsSize_t(index);
3✔
67
    return self->SubscriptRaw(id);
68
  }
3✔
69

3✔
70
  PyObject *SubscriptRaw(size_t index) {
6✔
71
    wrap_type *rtVal = reinterpret_cast<wrap_type *>(
72
        PyType_GenericAlloc(wrap_type::GetType(), 0));
6✔
73
    rtVal->item = cList->At(index);
6✔
74
    return reinterpret_cast<PyObject *>(rtVal);
75
  }
76

×
77
  static PyObject *Iter(List *self) {
78
    self->iterPos = 0;
79
    return reinterpret_cast<PyObject *>(self);
5✔
80
  }
1✔
81

1✔
82
  static PyObject *IterNext(List *self) {
83
    if (self->iterPos < Len(self)) {
84
      return self->SubscriptRaw(self->iterPos++);
85
    } else {
8✔
86
      PyErr_SetNone(PyExc_StopIteration);
8✔
87
      return nullptr;
8✔
88
    }
89
  }
90

×
91
  static PyObject *Create(value_type &&tp) {
×
92
    auto obj = reinterpret_cast<List *>(
93
        PyType_GenericNew(GetType(), nullptr, nullptr));
2✔
94
    obj->cList = std::move(tp);
2✔
95
    return reinterpret_cast<PyObject *>(obj);
2✔
96
  }
97
};
6✔
98
} // namespace UniPy
6✔
99

6✔
100
#pragma GCC diagnostic pop
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc