Skip to content

Commit 66e654a

Browse files
committed
Various minor cleanups
1 parent 18fd95e commit 66e654a

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

include/pybind11/cast.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ struct value_and_holder {
221221
return reinterpret_cast<V *&>(vh[0]);
222222
}
223223
// True if this `value_and_holder` has a non-null value pointer
224-
operator bool() const { return value_ptr(); }
224+
explicit operator bool() const { return value_ptr(); }
225225

226226
template <typename H> H &holder() const {
227227
return reinterpret_cast<H &>(vh[1]);
@@ -254,18 +254,17 @@ struct values_and_holders {
254254
instance *inst;
255255
using vec_iter = std::vector<detail::type_info *>::const_iterator;
256256
vec_iter typeit;
257-
size_t end;
258257
value_and_holder curr;
259258
friend struct values_and_holders;
260259
iterator(instance *inst, const type_vec &tinfo)
261-
: inst{inst}, typeit{tinfo.begin()}, end{tinfo.size()},
260+
: inst{inst}, typeit{tinfo.begin()},
262261
curr(inst /* instance */,
263-
end > 0 ? *typeit : nullptr /* type info */,
262+
tinfo.size() > 0 ? *typeit : nullptr /* type info */,
264263
0, /* vpos: (non-simple types only): the first vptr comes first */
265264
0 /* index */)
266265
{}
267266
// Past-the-end iterator:
268-
iterator(size_t end) : end{end}, curr(end) {}
267+
iterator(size_t end) : curr(end) {}
269268
public:
270269
bool operator==(const iterator &other) { return curr.index == other.curr.index; }
271270
bool operator!=(const iterator &other) { return curr.index != other.curr.index; }
@@ -346,7 +345,6 @@ PYBIND11_NOINLINE inline void instance::allocate_layout() {
346345
// values that tracks whether each associated holder has been initialized. Each [block] is
347346
// padded, if necessary, to an integer multiple of sizeof(void *).
348347
size_t space = 0;
349-
size_in_ptrs(n_types);
350348
for (auto t : tinfo) {
351349
space += 1; // value pointer
352350
space += t->holder_size_in_ptrs; // holder instance
@@ -361,8 +359,10 @@ PYBIND11_NOINLINE inline void instance::allocate_layout() {
361359
// just wrappers around malloc.
362360
#if PY_VERSION_HEX >= 0x03050000
363361
nonsimple.values_and_holders = (void **) PyMem_Calloc(space, sizeof(void *));
362+
if (!nonsimple.values_and_holders) throw std::bad_alloc();
364363
#else
365364
nonsimple.values_and_holders = (void **) PyMem_New(void *, space);
365+
if (!nonsimple.values_and_holders) throw std::bad_alloc();
366366
std::memset(nonsimple.values_and_holders, 0, space * sizeof(void *));
367367
#endif
368368
nonsimple.holder_constructed = reinterpret_cast<unsigned char *>(&nonsimple.values_and_holders[flags_at]);

include/pybind11/class_support.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,6 @@ inline PyObject* make_new_python_type(const type_record &rec) {
528528
type->tp_doc = tp_doc;
529529
type->tp_base = (PyTypeObject *) handle(base).inc_ref().ptr();
530530
type->tp_basicsize = static_cast<ssize_t>(sizeof(instance));
531-
//type->tp_itemsize = 16;
532531
if (bases.size() > 0)
533532
type->tp_bases = bases.release().ptr();
534533

include/pybind11/common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ constexpr size_t instance_simple_holder_in_ptrs() {
365365

366366
// Forward declarations
367367
struct type_info;
368-
struct all_type_info;
369368
struct value_and_holder;
370369

371370
/// The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')

0 commit comments

Comments
 (0)