Skip to content

Commit 2317f6c

Browse files
dsnopekRepiteo
andcommitted
Add RequiredParam<T> and RequiredValue<T> to mark Object * arguments and return values as required
Co-authored-by: Thaddeus Crews <[email protected]>
1 parent 7864ac8 commit 2317f6c

File tree

11 files changed

+433
-1
lines changed

11 files changed

+433
-1
lines changed

core/error/error_macros.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ void _physics_interpolation_warning(const char *p_function, const char *p_file,
175175
#define ERR_FAIL_INDEX_V(m_index, m_size, m_retval) \
176176
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
177177
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
178+
GODOT_DEPRECATED_BEGIN \
178179
return m_retval; \
180+
GODOT_DEPRECATED_END \
179181
} else \
180182
((void)0)
181183

@@ -186,7 +188,9 @@ void _physics_interpolation_warning(const char *p_function, const char *p_file,
186188
#define ERR_FAIL_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
187189
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
188190
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
191+
GODOT_DEPRECATED_BEGIN \
189192
return m_retval; \
193+
GODOT_DEPRECATED_END \
190194
} else \
191195
((void)0)
192196

@@ -196,7 +200,9 @@ void _physics_interpolation_warning(const char *p_function, const char *p_file,
196200
#define ERR_FAIL_INDEX_V_EDMSG(m_index, m_size, m_retval, m_msg) \
197201
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
198202
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, true); \
203+
GODOT_DEPRECATED_BEGIN \
199204
return m_retval; \
205+
GODOT_DEPRECATED_END \
200206
} else \
201207
((void)0)
202208

@@ -278,7 +284,9 @@ void _physics_interpolation_warning(const char *p_function, const char *p_file,
278284
#define ERR_FAIL_UNSIGNED_INDEX_V(m_index, m_size, m_retval) \
279285
if (unlikely((m_index) >= (m_size))) { \
280286
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
287+
GODOT_DEPRECATED_BEGIN \
281288
return m_retval; \
289+
GODOT_DEPRECATED_END \
282290
} else \
283291
((void)0)
284292

@@ -289,7 +297,9 @@ void _physics_interpolation_warning(const char *p_function, const char *p_file,
289297
#define ERR_FAIL_UNSIGNED_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
290298
if (unlikely((m_index) >= (m_size))) { \
291299
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
300+
GODOT_DEPRECATED_BEGIN \
292301
return m_retval; \
302+
GODOT_DEPRECATED_END \
293303
} else \
294304
((void)0)
295305

@@ -299,7 +309,9 @@ void _physics_interpolation_warning(const char *p_function, const char *p_file,
299309
#define ERR_FAIL_UNSIGNED_INDEX_V_EDMSG(m_index, m_size, m_retval, m_msg) \
300310
if (unlikely((m_index) >= (m_size))) { \
301311
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, true); \
312+
GODOT_DEPRECATED_BEGIN \
302313
return m_retval; \
314+
GODOT_DEPRECATED_END \
303315
} else \
304316
((void)0)
305317

@@ -381,7 +393,9 @@ void _physics_interpolation_warning(const char *p_function, const char *p_file,
381393
#define ERR_FAIL_NULL_V(m_param, m_retval) \
382394
if (unlikely(m_param == nullptr)) { \
383395
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null."); \
396+
GODOT_DEPRECATED_BEGIN \
384397
return m_retval; \
398+
GODOT_DEPRECATED_END \
385399
} else \
386400
((void)0)
387401

@@ -392,7 +406,9 @@ void _physics_interpolation_warning(const char *p_function, const char *p_file,
392406
#define ERR_FAIL_NULL_V_MSG(m_param, m_retval, m_msg) \
393407
if (unlikely(m_param == nullptr)) { \
394408
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null.", m_msg); \
409+
GODOT_DEPRECATED_BEGIN \
395410
return m_retval; \
411+
GODOT_DEPRECATED_END \
396412
} else \
397413
((void)0)
398414

@@ -402,7 +418,9 @@ void _physics_interpolation_warning(const char *p_function, const char *p_file,
402418
#define ERR_FAIL_NULL_V_EDMSG(m_param, m_retval, m_msg) \
403419
if (unlikely(m_param == nullptr)) { \
404420
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null.", m_msg, true); \
421+
GODOT_DEPRECATED_BEGIN \
405422
return m_retval; \
423+
GODOT_DEPRECATED_END \
406424
} else \
407425
((void)0)
408426

@@ -458,7 +476,9 @@ void _physics_interpolation_warning(const char *p_function, const char *p_file,
458476
#define ERR_FAIL_COND_V(m_cond, m_retval) \
459477
if (unlikely(m_cond)) { \
460478
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Returning: " _STR(m_retval)); \
479+
GODOT_DEPRECATED_BEGIN \
461480
return m_retval; \
481+
GODOT_DEPRECATED_END \
462482
} else \
463483
((void)0)
464484

@@ -472,7 +492,9 @@ void _physics_interpolation_warning(const char *p_function, const char *p_file,
472492
#define ERR_FAIL_COND_V_MSG(m_cond, m_retval, m_msg) \
473493
if (unlikely(m_cond)) { \
474494
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Returning: " _STR(m_retval), m_msg); \
495+
GODOT_DEPRECATED_BEGIN \
475496
return m_retval; \
497+
GODOT_DEPRECATED_END \
476498
} else \
477499
((void)0)
478500

@@ -482,7 +504,9 @@ void _physics_interpolation_warning(const char *p_function, const char *p_file,
482504
#define ERR_FAIL_COND_V_EDMSG(m_cond, m_retval, m_msg) \
483505
if (unlikely(m_cond)) { \
484506
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Returning: " _STR(m_retval), m_msg, true); \
507+
GODOT_DEPRECATED_BEGIN \
485508
return m_retval; \
509+
GODOT_DEPRECATED_END \
486510
} else \
487511
((void)0)
488512

@@ -636,7 +660,9 @@ void _physics_interpolation_warning(const char *p_function, const char *p_file,
636660
#define ERR_FAIL_V(m_retval) \
637661
if (true) { \
638662
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/function failed. Returning: " _STR(m_retval)); \
663+
GODOT_DEPRECATED_BEGIN \
639664
return m_retval; \
665+
GODOT_DEPRECATED_END \
640666
} else \
641667
((void)0)
642668

@@ -649,7 +675,9 @@ void _physics_interpolation_warning(const char *p_function, const char *p_file,
649675
#define ERR_FAIL_V_MSG(m_retval, m_msg) \
650676
if (true) { \
651677
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/function failed. Returning: " _STR(m_retval), m_msg); \
678+
GODOT_DEPRECATED_BEGIN \
652679
return m_retval; \
680+
GODOT_DEPRECATED_END \
653681
} else \
654682
((void)0)
655683

@@ -659,7 +687,9 @@ void _physics_interpolation_warning(const char *p_function, const char *p_file,
659687
#define ERR_FAIL_V_EDMSG(m_retval, m_msg) \
660688
if (true) { \
661689
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/function failed. Returning: " _STR(m_retval), m_msg, true); \
690+
GODOT_DEPRECATED_BEGIN \
662691
return m_retval; \
692+
GODOT_DEPRECATED_END \
663693
} else \
664694
((void)0)
665695

core/extension/extension_api_dump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static String get_property_info_type_name(const PropertyInfo &p_info) {
8888
}
8989

9090
static String get_type_meta_name(const GodotTypeInfo::Metadata metadata) {
91-
static const char *argmeta[13] = { "none", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float", "double", "char16", "char32" };
91+
static const char *argmeta[14] = { "none", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float", "double", "char16", "char32", "required" };
9292
return argmeta[metadata];
9393
}
9494

core/extension/gdextension_interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ typedef enum {
432432
GDEXTENSION_METHOD_ARGUMENT_METADATA_REAL_IS_DOUBLE,
433433
GDEXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_CHAR16,
434434
GDEXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_CHAR32,
435+
GDEXTENSION_METHOD_ARGUMENT_METADATA_OBJECT_IS_REQUIRED,
435436
} GDExtensionClassMethodArgumentMetadata;
436437

437438
typedef void (*GDExtensionClassMethodCall)(void *method_userdata, GDExtensionClassInstancePtr p_instance, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionVariantPtr r_return, GDExtensionCallError *r_error);

core/object/object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "core/templates/hash_set.h"
4040
#include "core/templates/list.h"
4141
#include "core/templates/safe_refcount.h"
42+
#include "core/variant/required_ptr.h"
4243
#include "core/variant/variant.h"
4344

4445
template <typename T>

core/typedefs.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,15 @@ inline constexpr bool is_zero_constructible_v = is_zero_constructible<T>::value;
446446
#define GODOT_MSVC_WARNING_PUSH_AND_IGNORE(m_warning)
447447
#endif
448448

449+
#define GODOT_DEPRECATED_BEGIN \
450+
GODOT_CLANG_WARNING_PUSH_AND_IGNORE("-Wdeprecated-declarations") \
451+
GODOT_GCC_WARNING_PUSH_AND_IGNORE("-Wdeprecated-declarations") \
452+
GODOT_MSVC_WARNING_PUSH_AND_IGNORE(4996)
453+
#define GODOT_DEPRECATED_END \
454+
GODOT_CLANG_WARNING_POP \
455+
GODOT_GCC_WARNING_POP \
456+
GODOT_MSVC_WARNING_POP
457+
449458
template <typename T, typename = void>
450459
struct is_fully_defined : std::false_type {};
451460

core/variant/binder_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "core/templates/simple_type.h"
3737
#include "core/typedefs.h"
3838
#include "core/variant/method_ptrcall.h"
39+
#include "core/variant/required_ptr.h"
3940
#include "core/variant/type_info.h"
4041
#include "core/variant/variant.h"
4142
#include "core/variant/variant_internal.h"

core/variant/method_ptrcall.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,51 @@ struct PtrToArg<const T *> {
269269
}
270270
};
271271

272+
// This is for RequiredParam.
273+
274+
template <class T>
275+
struct PtrToArg<RequiredParam<T>> {
276+
typedef typename RequiredParam<T>::value_type EncodeT;
277+
278+
_FORCE_INLINE_ static RequiredParam<T> convert(const void *p_ptr) {
279+
if (p_ptr == nullptr) {
280+
// Should we show an error?
281+
GODOT_DEPRECATED_BEGIN
282+
return RequiredParam<T>::err_return();
283+
GODOT_DEPRECATED_END
284+
}
285+
return RequiredParam<T>(*reinterpret_cast<T *const *>(p_ptr));
286+
}
287+
288+
_FORCE_INLINE_ static void encode(const RequiredParam<T> &p_var, void *p_ptr) {
289+
GODOT_DEPRECATED_BEGIN
290+
*((typename RequiredParam<T>::value_type *)p_ptr) = p_var._internal_ptr();
291+
GODOT_DEPRECATED_END
292+
}
293+
};
294+
295+
// This is for RequiredResult.
296+
297+
template <class T>
298+
struct PtrToArg<RequiredResult<T>> {
299+
typedef typename RequiredResult<T>::value_type EncodeT;
300+
301+
_FORCE_INLINE_ static RequiredResult<T> convert(const void *p_ptr) {
302+
if (p_ptr == nullptr) {
303+
GODOT_DEPRECATED_BEGIN
304+
return RequiredResult<T>::err_return();
305+
GODOT_DEPRECATED_END
306+
}
307+
return RequiredResult<T>(*reinterpret_cast<T *const *>(p_ptr));
308+
}
309+
310+
_FORCE_INLINE_ static void encode(const RequiredResult<T> &p_var, void *p_ptr) {
311+
GODOT_DEPRECATED_BEGIN
312+
*((typename RequiredResult<T>::value_type *)p_ptr) = p_var._internal_ptr();
313+
GODOT_DEPRECATED_END
314+
}
315+
};
316+
272317
// This is for ObjectID.
273318

274319
template <>

0 commit comments

Comments
 (0)