non-nullable

Is it valid to use ptr::NonNull in FFI?

半城伤御伤魂 提交于 2019-12-10 18:40:11
问题 Rust has the ptr::NonNull type that represents a non- NULL pointer. Is it safe to use this type in FFI? Is it guaranteed to have same binary representation (ignoring non-FFI context such as Option optimizations), alignment, register usage as *mut T ? For example, could I implement this interface: void call_me_from_c(char *without_nulls) __attribute__((nonnull)); with extern "C" fn call_me_from_c(without_nulls: ptr::NonNull<c_char>) I don't expect this to do anything (apart from causing UB

Making a Non-nullable value type nullable

邮差的信 提交于 2019-12-09 07:50:18
问题 I have a simple struct that has limited use. The struct is created in a method that calls the data from the database. If there is no data returned from the database I want to be able to return a null, but Visual Studio complains, Cannot convert null to PackageName.StructName because it is a non-nullable value type. How can I make it nullable? 回答1: You want to look into the Nullable<T> value type. 回答2: public struct Something { //... } public static Something GetSomethingSomehow() { Something?

Can we ensure nullability of `+ (nonnull instancetype)sharedInstance;`?

流过昼夜 提交于 2019-12-07 03:34:03
问题 This is a question on how to gracefully circumvent the nullability of init in NSObject class. So here is a classic objective-c implementation: + (instancetype)sharedInstance { static dispatch_once_t onceToken; static id sharedInstance; dispatch_once(&onceToken, ^ { sharedInstance = [[self alloc] init]; }); return sharedInstance; } But now I want to declare it as nonnull , if possible: + (nonnull instancetype)sharedInstance; Unfortunately, init returns a nullable instancetype value. Should I

How to use Objective-C __nonnull in a backwards-compatible way?

非 Y 不嫁゛ 提交于 2019-12-06 04:17:01
问题 Xcode has recently added __nonnull , __nullable , etc. attributes. However, they're not supported by older versions of clang and other compilers. How can I use these attributes in a compatible way? I hoped something like this would work: #ifndef NS_ASSUME_NONNULL_BEGIN #define __nonnull #endif but it seems that NS_ASSUME_NONNULL_BEGIN is not a real macro, and it's "not defined" in Xcode7. And it would make sense for this to work: #if !defined(__is_identifier) || __is_identifier(__nonnull)

Can we ensure nullability of `+ (nonnull instancetype)sharedInstance;`?

与世无争的帅哥 提交于 2019-12-05 09:37:10
This is a question on how to gracefully circumvent the nullability of init in NSObject class. So here is a classic objective-c implementation: + (instancetype)sharedInstance { static dispatch_once_t onceToken; static id sharedInstance; dispatch_once(&onceToken, ^ { sharedInstance = [[self alloc] init]; }); return sharedInstance; } But now I want to declare it as nonnull , if possible: + (nonnull instancetype)sharedInstance; Unfortunately, init returns a nullable instancetype value. Should I add an NSAssert or something after calling init ? I noticed that some people even document nonnull

Eclipse null analysis: The expression of type int needs unchecked conversion to conform to '@Nonnull Integer'

落花浮王杯 提交于 2019-12-05 06:37:04
When configuring Eclipse 4.2.0 to perform a null analysis (configured to use @javax.annotation.Nonnull etc.), the following code will generate the warning Null type safety: The expression of type int needs unchecked conversion to conform to '@Nonnull Integer' class C { static void foo(int i) { bar(i); // Warning } static void bar(@javax.annotation.Nonnull Integer i) { } } How am I supposed to fix this (without using @SuppressWarnings("null") )? It seems that the analyzer does not know that boxed primitives cannot be null . I think it's a bug in Eclipse. I tried the same with IntelliJ, and it

Django 1.7: Makemigration: non-nullable field

白昼怎懂夜的黑 提交于 2019-12-05 00:57:02
问题 I am trying to use django-orderedmodel (https://github.com/kirelagin/django-orderedmodel) in my project. Running makemigrations doesn't work: You are trying to add a non-nullable field 'order' to slide without a default; we can't do that (the database needs something to populate existing rows). Please select a fix: 1) Provide a one-off default now (will be set on all existing rows) 2) Quit, and let me add a default in models.py Select an option: I would like to know where I'm doing this wrong

How to use Objective-C __nonnull in a backwards-compatible way?

江枫思渺然 提交于 2019-12-04 10:00:53
Xcode has recently added __nonnull , __nullable , etc. attributes. However, they're not supported by older versions of clang and other compilers. How can I use these attributes in a compatible way? I hoped something like this would work: #ifndef NS_ASSUME_NONNULL_BEGIN #define __nonnull #endif but it seems that NS_ASSUME_NONNULL_BEGIN is not a real macro, and it's "not defined" in Xcode7. And it would make sense for this to work: #if !defined(__is_identifier) || __is_identifier(__nonnull) #define __nonnull #define __nullable #endif but Xcode 6 chokes on that with "token is not a valid binary

Getter and @Nonnull

孤者浪人 提交于 2019-12-04 04:48:54
I get a warning from eclipse and I know I can remove it with suppress warning but I'd prefer to understand what makes it thing it could be null. package-info.java @ParametersAreNonnullByDefault package test; import javax.annotation.ParametersAreNonnullByDefault; test.java package test; public class Test { public static void main( final String[ ] args ) { System.out.println( new Test( "a" ).getS( ) ); } private final String s; public Test( final String s ) { this.s = s; } public String getS( ) { return this.s;//Null type safety: The expression of type String needs unchecked conversion to

Django 1.7: Makemigration: non-nullable field

孤者浪人 提交于 2019-12-03 16:30:32
I am trying to use django-orderedmodel ( https://github.com/kirelagin/django-orderedmodel ) in my project. Running makemigrations doesn't work: You are trying to add a non-nullable field 'order' to slide without a default; we can't do that (the database needs something to populate existing rows). Please select a fix: 1) Provide a one-off default now (will be set on all existing rows) 2) Quit, and let me add a default in models.py Select an option: I would like to know where I'm doing this wrong. Thanks As the order field is unique, you'll need to add the field in several migration steps,