@@ -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]);
0 commit comments