From a5b1cee480e202614196c1327ff28796244ae39b Mon Sep 17 00:00:00 2001 From: MatthieuDartiailh Date: Tue, 16 Apr 2024 09:31:00 +0200 Subject: [PATCH] cpp: improve fixed tuple validator --- atom/src/validatebehavior.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/atom/src/validatebehavior.cpp b/atom/src/validatebehavior.cpp index 3e25a765..175721bd 100644 --- a/atom/src/validatebehavior.cpp +++ b/atom/src/validatebehavior.cpp @@ -493,11 +493,6 @@ fixed_tuple_handler( Member* member, CAtom* atom, PyObject* oldvalue, PyObject* // Create a copy in which to store the validated values Py_ssize_t size = PyTuple_GET_SIZE( newvalue ); - cppy::ptr tuplecopy = PyTuple_New( size ); - if( !tuplecopy ) - { - return 0; - } // Check the size match the expected size Py_ssize_t expected_size = PyTuple_GET_SIZE( member->validate_context ); @@ -515,6 +510,13 @@ fixed_tuple_handler( Member* member, CAtom* atom, PyObject* oldvalue, PyObject* return 0; } + // Create a new tuple to store the validate values + cppy::ptr tuplecopy = PyTuple_New( size ); + if( !tuplecopy ) + { + return 0; + } + // Validate each single item for( Py_ssize_t i = 0; i < size; ++i ) {