@@ -221,7 +221,7 @@ struct value_and_holder {
221
221
return reinterpret_cast <V *&>(vh[0 ]);
222
222
}
223
223
// 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 (); }
225
225
226
226
template <typename H> H &holder () const {
227
227
return reinterpret_cast <H &>(vh[1 ]);
@@ -254,18 +254,17 @@ struct values_and_holders {
254
254
instance *inst;
255
255
using vec_iter = std::vector<detail::type_info *>::const_iterator;
256
256
vec_iter typeit;
257
- size_t end;
258
257
value_and_holder curr;
259
258
friend struct values_and_holders ;
260
259
iterator (instance *inst, const type_vec &tinfo)
261
- : inst{inst}, typeit{tinfo.begin ()}, end{tinfo. size ()},
260
+ : inst{inst}, typeit{tinfo.begin ()},
262
261
curr (inst /* instance */ ,
263
- end > 0 ? *typeit : nullptr /* type info */ ,
262
+ tinfo.size() > 0 ? *typeit : nullptr /* type info */ ,
264
263
0 , /* vpos: (non-simple types only): the first vptr comes first */
265
264
0 /* index */ )
266
265
{}
267
266
// Past-the-end iterator:
268
- iterator (size_t end) : end{end}, curr(end) {}
267
+ iterator (size_t end) : curr(end) {}
269
268
public:
270
269
bool operator ==(const iterator &other) { return curr.index == other.curr .index ; }
271
270
bool operator !=(const iterator &other) { return curr.index != other.curr .index ; }
@@ -346,7 +345,6 @@ PYBIND11_NOINLINE inline void instance::allocate_layout() {
346
345
// values that tracks whether each associated holder has been initialized. Each [block] is
347
346
// padded, if necessary, to an integer multiple of sizeof(void *).
348
347
size_t space = 0 ;
349
- size_in_ptrs (n_types);
350
348
for (auto t : tinfo) {
351
349
space += 1 ; // value pointer
352
350
space += t->holder_size_in_ptrs ; // holder instance
@@ -361,8 +359,10 @@ PYBIND11_NOINLINE inline void instance::allocate_layout() {
361
359
// just wrappers around malloc.
362
360
#if PY_VERSION_HEX >= 0x03050000
363
361
nonsimple.values_and_holders = (void **) PyMem_Calloc (space, sizeof (void *));
362
+ if (!nonsimple.values_and_holders ) throw std::bad_alloc ();
364
363
#else
365
364
nonsimple.values_and_holders = (void **) PyMem_New (void *, space);
365
+ if (!nonsimple.values_and_holders ) throw std::bad_alloc ();
366
366
std::memset (nonsimple.values_and_holders , 0 , space * sizeof (void *));
367
367
#endif
368
368
nonsimple.holder_constructed = reinterpret_cast <unsigned char *>(&nonsimple.values_and_holders [flags_at]);
0 commit comments