diff
stringlengths
41
2.03M
msg
stringlengths
1
1.5k
repo
stringlengths
5
40
sha
stringlengths
40
40
time
stringlengths
20
20
mmm a / tensorflow / contrib / makefile / Makefile <nl> ppp b / tensorflow / contrib / makefile / Makefile <nl> ifeq ( $ ( TARGET ) , IOS ) <nl> IPHONESIMULATOR_SYSROOT : = $ ( shell xcrun - - sdk iphonesimulator \ <nl> - - show - sdk - path ) <nl> IOS_SDK_VERSION : = $ ( shell xcrun - - sdk iphoneos - - show - sdk - version ) <nl> - MIN_SDK_VERSION : = 8 . 0 <nl> + MIN_SDK_VERSION : = 9 . 0 <nl> # Override IOS_ARCH with ARMV7 , ARMV7S , ARM64 , or I386 . <nl> IOS_ARCH : = X86_64 <nl> ifeq ( $ ( IOS_ARCH ) , ARMV7 ) <nl> CXXFLAGS + = - miphoneos - version - min = $ ( MIN_SDK_VERSION ) \ <nl> - arch armv7 \ <nl> - fembed - bitcode \ <nl> - - D__thread = \ <nl> + - D__thread = thread_local \ <nl> - DUSE_GEMM_FOR_CONV \ <nl> - Wno - c + + 11 - narrowing \ <nl> - mno - thumb \ <nl> ifeq ( $ ( TARGET ) , IOS ) <nl> CXXFLAGS + = - miphoneos - version - min = $ ( MIN_SDK_VERSION ) \ <nl> - arch armv7s \ <nl> - fembed - bitcode \ <nl> - - D__thread = \ <nl> + - D__thread = thread_local \ <nl> - DUSE_GEMM_FOR_CONV \ <nl> - Wno - c + + 11 - narrowing \ <nl> - mno - thumb \ <nl> ifeq ( $ ( TARGET ) , IOS ) <nl> CXXFLAGS + = - miphoneos - version - min = $ ( MIN_SDK_VERSION ) \ <nl> - arch arm64 \ <nl> - fembed - bitcode \ <nl> - - D__thread = \ <nl> + - D__thread = thread_local \ <nl> - DUSE_GEMM_FOR_CONV \ <nl> - Wno - c + + 11 - narrowing \ <nl> - DTF_LEAN_BINARY \ <nl> ifeq ( $ ( TARGET ) , IOS ) <nl> - arch i386 \ <nl> - mno - sse \ <nl> - fembed - bitcode \ <nl> - - D__thread = \ <nl> + - D__thread = thread_local \ <nl> - DUSE_GEMM_FOR_CONV \ <nl> - Wno - c + + 11 - narrowing \ <nl> - DTF_LEAN_BINARY \ <nl> ifeq ( $ ( TARGET ) , IOS ) <nl> CXXFLAGS + = - mios - simulator - version - min = $ ( MIN_SDK_VERSION ) \ <nl> - arch x86_64 \ <nl> - fembed - bitcode \ <nl> - - D__thread = \ <nl> + - D__thread = thread_local \ <nl> - DUSE_GEMM_FOR_CONV \ <nl> - Wno - c + + 11 - narrowing \ <nl> - DTF_LEAN_BINARY \ <nl>
Updated iOS build process to handle threading correctly , requires iOS 9 . 0 or later . ( )
tensorflow/tensorflow
eb14ad4e27b15825802b9c213eb64d023f1b1923
2017-08-27T20:19:31Z
mmm a / include / v8 . h <nl> ppp b / include / v8 . h <nl> class String : public Primitive { <nl> PRESERVE_ASCII_NULL = 4 <nl> } ; <nl> <nl> - / / 16 - bit character codes . <nl> + <nl> + enum StringEncoding { <nl> + INVALID_ENCODING = 0 , <nl> + UTF_8_ENCODING = 1 , <nl> + LATIN1_ENCODING = 2 , <nl> + UTF_16_ENCODING = 3 , <nl> + <nl> + ASCII_HINT = 1 < < 16 , <nl> + NOT_ASCII_HINT = 1 < < 17 <nl> + } ; <nl> + <nl> + static const int kStringEncodingMask = 3 ; <nl> + static const int kAsciiHintMask = String : : ASCII_HINT | String : : NOT_ASCII_HINT ; <nl> + <nl> + static const int kUndefinedLength = - 1 ; <nl> + <nl> + <nl> + / / 16 - bit UTF16 code units . PRESERVE_ASCII_NULL is not supported as option , <nl> + / / null - characters are never converted to spaces . <nl> V8EXPORT int Write ( uint16_t * buffer , <nl> int start = 0 , <nl> - int length = - 1 , <nl> + int length = kUndefinedLength , <nl> int options = NO_OPTIONS ) const ; <nl> - / / ASCII characters . <nl> + <nl> + / / ASCII characters . Null - characters are converted to spaces unless <nl> + / / PRESERVE_ASCII_NULL is set as option . <nl> V8EXPORT int WriteAscii ( char * buffer , <nl> int start = 0 , <nl> - int length = - 1 , <nl> + int length = kUndefinedLength , <nl> int options = NO_OPTIONS ) const ; <nl> - / / UTF - 8 encoded characters . <nl> + <nl> + / / Latin1 characters . PRESERVE_ASCII_NULL is not supported as option , <nl> + / / null - characters are never converted to spaces . <nl> + V8EXPORT int WriteLatin1 ( char * buffer , <nl> + int start = 0 , <nl> + int length = kUndefinedLength , <nl> + int options = NO_OPTIONS ) const ; <nl> + <nl> + / / UTF - 8 encoded characters . PRESERVE_ASCII_NULL is not supported as option , <nl> + / / null - characters are never converted to spaces . <nl> V8EXPORT int WriteUtf8 ( char * buffer , <nl> - int length = - 1 , <nl> + int length = kUndefinedLength , <nl> int * nchars_ref = NULL , <nl> int options = NO_OPTIONS ) const ; <nl> <nl> class String : public Primitive { <nl> void operator = ( const ExternalStringResourceBase & ) ; <nl> <nl> friend class v8 : : internal : : Heap ; <nl> + friend class v8 : : String ; <nl> } ; <nl> <nl> / * * <nl> class String : public Primitive { <nl> ExternalAsciiStringResource ( ) { } <nl> } ; <nl> <nl> + / * * <nl> + * An ExternalLatin1StringResource is a wrapper around an Latin1 - encoded <nl> + * string buffer that resides outside V8 ' s heap . For usage in V8 , a Latin1 <nl> + * string is converted to ASCII or two - byte string depending on whether <nl> + * it contains non - ASCII characters . <nl> + * / <nl> + class V8EXPORT ExternalLatin1StringResource <nl> + : public ExternalAsciiStringResource { <nl> + } ; <nl> + <nl> / * * <nl> * Get the ExternalStringResource for an external string . Returns <nl> * NULL if IsExternal ( ) doesn ' t return true . <nl> class String : public Primitive { <nl> V8EXPORT const ExternalAsciiStringResource * GetExternalAsciiStringResource ( ) <nl> const ; <nl> <nl> + / * * <nl> + * If the string is external , return its encoding ( Latin1 or UTF16 ) <nl> + * and possibly a hint on whether the content is ASCII . <nl> + * Return String : : INVALID_ENCODING otherwise . <nl> + * / <nl> + inline int GetExternalStringEncoding ( ) const ; <nl> + <nl> + <nl> + / * * <nl> + * Return the resource of the external string regardless of encoding . <nl> + * Call this only after having made sure that the string is indeed external ! <nl> + * / <nl> + inline ExternalStringResourceBase * GetExternalStringResourceBase ( ) const ; <nl> + <nl> static inline String * Cast ( v8 : : Value * obj ) ; <nl> <nl> / * * <nl> - * Allocates a new string from either UTF - 8 encoded or ASCII data . <nl> - * The second parameter ' length ' gives the buffer length . <nl> - * If the data is UTF - 8 encoded , the caller must <nl> - * be careful to supply the length parameter . <nl> - * If it is not given , the function calls <nl> - * ' strlen ' to determine the buffer length , it might be <nl> - * wrong if ' data ' contains a null character . <nl> + * Allocates a new string from either UTF - 8 or Latin1 - encoded data . <nl> + * The second parameter ' length ' gives the buffer length . If the data may <nl> + * contain zero bytes , the caller must be careful to supply the length <nl> + * parameter . If it is not given , the function calls ' strlen ' to determine <nl> + * the buffer length , it might be wrong if ' data ' contains a null character . <nl> + * The third parameter specifies the encoding , which may include an hint <nl> + * whether the string contains ASCII characters . In the case of Latin1 , the <nl> + * appropriate internal representation ( UTF16 or ASCII ) is chosen . <nl> * / <nl> - V8EXPORT static Local < String > New ( const char * data , int length = - 1 ) ; <nl> + V8EXPORT static Local < String > New ( const char * data , <nl> + int length = kUndefinedLength , <nl> + int encoding = UTF_8_ENCODING ) ; <nl> <nl> - / * * Allocates a new string from 16 - bit character codes . * / <nl> - V8EXPORT static Local < String > New ( const uint16_t * data , int length = - 1 ) ; <nl> + / * * Allocates a new string from 16 - bit UTF - 16 code units . * / <nl> + V8EXPORT static Local < String > New ( const uint16_t * data , <nl> + int length = kUndefinedLength ) ; <nl> <nl> / * * Creates a symbol . Returns one if it exists already . * / <nl> - V8EXPORT static Local < String > NewSymbol ( const char * data , int length = - 1 ) ; <nl> + V8EXPORT static Local < String > NewSymbol ( const char * data , <nl> + int length = kUndefinedLength , <nl> + int encoding = UTF_8_ENCODING ) ; <nl> <nl> / * * <nl> * Creates a new string by concatenating the left and the right strings <nl> class String : public Primitive { <nl> * this function should not otherwise delete or modify the resource . Neither <nl> * should the underlying buffer be deallocated or modified except through the <nl> * destructor of the external string resource . <nl> - * / V8EXPORT static Local < String > NewExternal ( <nl> + * / <nl> + V8EXPORT static Local < String > NewExternal ( <nl> ExternalAsciiStringResource * resource ) ; <nl> <nl> / * * <nl> class String : public Primitive { <nl> * / <nl> V8EXPORT bool MakeExternal ( ExternalAsciiStringResource * resource ) ; <nl> <nl> + <nl> + / * * <nl> + * Creates a new external string using the Latin1 - encoded data defined in the <nl> + * given resource . When the external string is no longer live on V8 ' s heap <nl> + * the resource will be disposed by calling its Dispose method . The caller of <nl> + * this function should not otherwise delete or modify the resource . Neither <nl> + * should the underlying buffer be deallocated or modified except through the <nl> + * destructor of the external string resource . <nl> + * If the data contains a non - ASCII character , the string is created as a new <nl> + * string object on the V8 heap and the Dispose method is called on the <nl> + * resource immediately . This is because V8 is unable to handle non - ASCII <nl> + * Latin1 - encoded strings internally . <nl> + * / <nl> + V8EXPORT static Local < String > NewExternal ( <nl> + ExternalLatin1StringResource * resource , <nl> + int encoding = String : : LATIN1_ENCODING ) ; <nl> + <nl> + <nl> / * * <nl> * Returns true if this string can be made external . <nl> * / <nl> class String : public Primitive { <nl> <nl> / * * Creates an undetectable string from the supplied ASCII or UTF - 8 data . * / <nl> V8EXPORT static Local < String > NewUndetectable ( const char * data , <nl> - int length = - 1 ) ; <nl> + int length = kUndefinedLength , <nl> + int encoding = UTF_8_ENCODING ) ; <nl> <nl> - / * * Creates an undetectable string from the supplied 16 - bit character codes . * / <nl> + / * * Creates an undetectable string from the supplied 16 - bit UTF16 code units . <nl> + * / <nl> V8EXPORT static Local < String > NewUndetectable ( const uint16_t * data , <nl> - int length = - 1 ) ; <nl> + int length = kUndefinedLength ) ; <nl> <nl> / * * <nl> * Converts an object to a UTF - 8 - encoded character array . Useful if <nl> class String : public Primitive { <nl> } ; <nl> <nl> private : <nl> - V8EXPORT void VerifyExternalStringResource ( ExternalStringResource * val ) const ; <nl> + V8EXPORT void VerifyExternalStringEncoding ( int encoding ) const ; <nl> + V8EXPORT void VerifyExternalStringResourceBase ( <nl> + ExternalStringResourceBase * val ) const ; <nl> V8EXPORT static void CheckCast ( v8 : : Value * obj ) ; <nl> } ; <nl> <nl> class Internals { <nl> static const int kJSObjectHeaderSize = 3 * kApiPointerSize ; <nl> static const int kFullStringRepresentationMask = 0x07 ; <nl> static const int kExternalTwoByteRepresentationTag = 0x02 ; <nl> + static const int kExternalAsciiRepresentationTag = 0x06 ; <nl> + static const int kExternalAsciiDataHintMask = 0x08 ; <nl> + static const int kExternalAsciiDataHintTag = 0x08 ; <nl> <nl> static const int kIsolateStateOffset = 0 ; <nl> static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize ; <nl> class Internals { <nl> } <nl> } <nl> <nl> - static inline bool IsExternalTwoByteString ( int instance_type ) { <nl> - int representation = ( instance_type & kFullStringRepresentationMask ) ; <nl> - return representation = = kExternalTwoByteRepresentationTag ; <nl> - } <nl> - <nl> static inline bool IsInitialized ( v8 : : Isolate * isolate ) { <nl> uint8_t * addr = reinterpret_cast < uint8_t * > ( isolate ) + kIsolateStateOffset ; <nl> return * reinterpret_cast < int * > ( addr ) = = 1 ; <nl> Local < String > String : : Empty ( Isolate * isolate ) { <nl> String : : ExternalStringResource * String : : GetExternalStringResource ( ) const { <nl> typedef internal : : Object O ; <nl> typedef internal : : Internals I ; <nl> + String : : ExternalStringResource * result = NULL ; <nl> O * obj = * reinterpret_cast < O * * > ( const_cast < String * > ( this ) ) ; <nl> - String : : ExternalStringResource * result ; <nl> - if ( I : : IsExternalTwoByteString ( I : : GetInstanceType ( obj ) ) ) { <nl> - void * value = I : : ReadField < void * > ( obj , I : : kStringResourceOffset ) ; <nl> - result = reinterpret_cast < String : : ExternalStringResource * > ( value ) ; <nl> - } else { <nl> - result = NULL ; <nl> + if ( ( I : : GetInstanceType ( obj ) & I : : kFullStringRepresentationMask ) = = <nl> + I : : kExternalTwoByteRepresentationTag ) { <nl> + result = reinterpret_cast < String : : ExternalStringResource * > ( <nl> + GetExternalStringResourceBase ( ) ) ; <nl> } <nl> + return result ; <nl> + } <nl> + <nl> + <nl> + int String : : GetExternalStringEncoding ( ) const { <nl> + typedef internal : : Object O ; <nl> + typedef internal : : Internals I ; <nl> + O * obj = * reinterpret_cast < O * * > ( const_cast < String * > ( this ) ) ; <nl> + static const int kRepresentationAndHintMask = <nl> + I : : kFullStringRepresentationMask | I : : kExternalAsciiDataHintMask ; <nl> + <nl> + int encoding ; <nl> + switch ( I : : GetInstanceType ( obj ) & kRepresentationAndHintMask ) { <nl> + case I : : kExternalTwoByteRepresentationTag | I : : kExternalAsciiDataHintTag : <nl> + encoding = UTF_16_ENCODING | ASCII_HINT ; <nl> + break ; <nl> + case I : : kExternalTwoByteRepresentationTag : <nl> + encoding = UTF_16_ENCODING | NOT_ASCII_HINT ; <nl> + break ; <nl> + case I : : kExternalAsciiRepresentationTag : <nl> + encoding = LATIN1_ENCODING | ASCII_HINT ; <nl> + break ; <nl> + default : <nl> + encoding = INVALID_ENCODING ; <nl> + break ; <nl> + } <nl> + # ifdef V8_ENABLE_CHECKS <nl> + VerifyExternalStringEncoding ( encoding ) ; <nl> + # endif <nl> + return encoding ; <nl> + } <nl> + <nl> + <nl> + String : : ExternalStringResourceBase * String : : GetExternalStringResourceBase ( ) <nl> + const { <nl> + typedef internal : : Object O ; <nl> + typedef internal : : Internals I ; <nl> + O * obj = * reinterpret_cast < O * * > ( const_cast < String * > ( this ) ) ; <nl> + void * value = I : : ReadField < void * > ( obj , I : : kStringResourceOffset ) ; <nl> + ExternalStringResourceBase * result = <nl> + reinterpret_cast < String : : ExternalStringResourceBase * > ( value ) ; <nl> # ifdef V8_ENABLE_CHECKS <nl> - VerifyExternalStringResource ( result ) ; <nl> + VerifyExternalStringResourceBase ( result ) ; <nl> # endif <nl> return result ; <nl> } <nl> mmm a / src / api . cc <nl> ppp b / src / api . cc <nl> int String : : WriteUtf8 ( char * buffer , <nl> int string_length = str - > length ( ) ; <nl> if ( str - > IsAsciiRepresentation ( ) ) { <nl> int len ; <nl> - if ( capacity = = - 1 ) { <nl> + if ( capacity = = kUndefinedLength ) { <nl> capacity = str - > length ( ) + 1 ; <nl> len = string_length ; <nl> } else { <nl> int String : : WriteUtf8 ( char * buffer , <nl> return len ; <nl> } <nl> <nl> - if ( capacity = = - 1 | | capacity / 3 > = string_length ) { <nl> + if ( capacity = = kUndefinedLength | | capacity / 3 > = string_length ) { <nl> int32_t previous = unibrow : : Utf16 : : kNoPreviousCharacter ; <nl> const int kMaxRecursion = 100 ; <nl> int utf8_bytes = <nl> int String : : WriteUtf8 ( char * buffer , <nl> int utf8_bytes = i : : Utf8Length ( str ) ; <nl> if ( ( options & NO_NULL_TERMINATION ) = = 0 ) utf8_bytes + + ; <nl> if ( utf8_bytes < = capacity ) { <nl> - return WriteUtf8 ( buffer , - 1 , nchars_ref , options ) ; <nl> + return WriteUtf8 ( buffer , kUndefinedLength , nchars_ref , options ) ; <nl> } <nl> } <nl> <nl> int String : : WriteUtf8 ( char * buffer , <nl> int pos = 0 ; <nl> int nchars = 0 ; <nl> int previous = unibrow : : Utf16 : : kNoPreviousCharacter ; <nl> - for ( i = 0 ; i < len & & ( capacity = = - 1 | | pos < fast_end ) ; i + + ) { <nl> + for ( i = 0 ; <nl> + i < len & & ( capacity = = kUndefinedLength | | pos < fast_end ) ; <nl> + i + + ) { <nl> i : : uc32 c = write_input_buffer . GetNext ( ) ; <nl> int written = unibrow : : Utf8 : : Encode ( buffer + pos , c , previous ) ; <nl> pos + = written ; <nl> int String : : WriteUtf8 ( char * buffer , <nl> } <nl> if ( nchars_ref ! = NULL ) * nchars_ref = nchars ; <nl> if ( ! ( options & NO_NULL_TERMINATION ) & & <nl> - ( i = = len & & ( capacity = = - 1 | | pos < capacity ) ) ) { <nl> + ( i = = len & & ( capacity = = kUndefinedLength | | pos < capacity ) ) ) { <nl> buffer [ pos + + ] = ' \ 0 ' ; <nl> } <nl> return pos ; <nl> int String : : WriteAscii ( char * buffer , <nl> if ( IsDeadCheck ( isolate , " v8 : : String : : WriteAscii ( ) " ) ) return 0 ; <nl> LOG_API ( isolate , " String : : WriteAscii " ) ; <nl> ENTER_V8 ( isolate ) ; <nl> - ASSERT ( start > = 0 & & length > = - 1 ) ; <nl> + ASSERT ( start > = 0 & & length > = kUndefinedLength ) ; <nl> i : : Handle < i : : String > str = Utils : : OpenHandle ( this ) ; <nl> isolate - > string_tracker ( ) - > RecordWrite ( str ) ; <nl> if ( options & HINT_MANY_WRITES_EXPECTED ) { <nl> int String : : WriteAscii ( char * buffer , <nl> <nl> if ( str - > IsAsciiRepresentation ( ) ) { <nl> / / WriteToFlat is faster than using the StringInputBuffer . <nl> - if ( length = = - 1 ) length = str - > length ( ) + 1 ; <nl> + if ( length = = kUndefinedLength ) length = str - > length ( ) + 1 ; <nl> int len = i : : Min ( length , str - > length ( ) - start ) ; <nl> i : : String : : WriteToFlat ( * str , buffer , start , start + len ) ; <nl> if ( ! ( options & PRESERVE_ASCII_NULL ) ) { <nl> int String : : WriteAscii ( char * buffer , <nl> <nl> i : : StringInputBuffer & write_input_buffer = * isolate - > write_input_buffer ( ) ; <nl> int end = length ; <nl> - if ( ( length = = - 1 ) | | ( length > str - > length ( ) - start ) ) { <nl> + if ( ( length = = kUndefinedLength ) | | ( length > str - > length ( ) - start ) ) { <nl> end = str - > length ( ) - start ; <nl> } <nl> if ( end < 0 ) return 0 ; <nl> int String : : WriteAscii ( char * buffer , <nl> } <nl> <nl> <nl> + int String : : WriteLatin1 ( char * buffer , <nl> + int start , <nl> + int length , <nl> + int options ) const { <nl> + i : : Isolate * isolate = Utils : : OpenHandle ( this ) - > GetIsolate ( ) ; <nl> + if ( IsDeadCheck ( isolate , " v8 : : String : : WriteLatin1 ( ) " ) ) return 0 ; <nl> + LOG_API ( isolate , " String : : WriteLatin1 " ) ; <nl> + ENTER_V8 ( isolate ) ; <nl> + ASSERT ( start > = 0 & & length > = kUndefinedLength ) ; <nl> + i : : Handle < i : : String > str = Utils : : OpenHandle ( this ) ; <nl> + isolate - > string_tracker ( ) - > RecordWrite ( str ) ; <nl> + if ( options & HINT_MANY_WRITES_EXPECTED ) { <nl> + FlattenString ( str ) ; / / Flatten the string for efficiency . <nl> + } <nl> + <nl> + if ( length = = kUndefinedLength ) length = str - > length ( ) + 1 ; <nl> + int len = i : : Min ( length , str - > length ( ) - start ) ; <nl> + i : : String : : WriteToFlat ( * str , buffer , start , start + len ) ; <nl> + if ( ! ( options & NO_NULL_TERMINATION ) & & length > len ) { <nl> + buffer [ len ] = ' \ 0 ' ; <nl> + } <nl> + return len ; <nl> + } <nl> + <nl> + <nl> int String : : Write ( uint16_t * buffer , <nl> int start , <nl> int length , <nl> int String : : Write ( uint16_t * buffer , <nl> if ( IsDeadCheck ( isolate , " v8 : : String : : Write ( ) " ) ) return 0 ; <nl> LOG_API ( isolate , " String : : Write " ) ; <nl> ENTER_V8 ( isolate ) ; <nl> - ASSERT ( start > = 0 & & length > = - 1 ) ; <nl> + ASSERT ( start > = 0 & & length > = kUndefinedLength ) ; <nl> i : : Handle < i : : String > str = Utils : : OpenHandle ( this ) ; <nl> isolate - > string_tracker ( ) - > RecordWrite ( str ) ; <nl> if ( options & HINT_MANY_WRITES_EXPECTED ) { <nl> int String : : Write ( uint16_t * buffer , <nl> FlattenString ( str ) ; <nl> } <nl> int end = start + length ; <nl> - if ( ( length = = - 1 ) | | ( length > str - > length ( ) - start ) ) <nl> + if ( ( length = = kUndefinedLength ) | | ( length > str - > length ( ) - start ) ) <nl> end = str - > length ( ) ; <nl> if ( end < 0 ) return 0 ; <nl> i : : String : : WriteToFlat ( * str , buffer , start , end ) ; <nl> bool v8 : : String : : IsExternalAscii ( ) const { <nl> } <nl> <nl> <nl> - void v8 : : String : : VerifyExternalStringResource ( <nl> - v8 : : String : : ExternalStringResource * value ) const { <nl> + void v8 : : String : : VerifyExternalStringEncoding ( int encoding ) const { <nl> + typedef internal : : Internals I ; <nl> i : : Handle < i : : String > str = Utils : : OpenHandle ( this ) ; <nl> - const v8 : : String : : ExternalStringResource * expected ; <nl> + switch ( encoding ) { <nl> + case UTF_16_ENCODING | ASCII_HINT : <nl> + CHECK ( str - > HasOnlyAsciiChars ( ) ) ; <nl> + / / Fall through <nl> + case UTF_16_ENCODING | NOT_ASCII_HINT : <nl> + CHECK ( str - > IsExternalTwoByteString ( ) ) ; <nl> + break ; <nl> + case LATIN1_ENCODING | ASCII_HINT : <nl> + CHECK ( str - > IsExternalAsciiString ( ) ) ; <nl> + break ; <nl> + default : <nl> + CHECK_EQ ( INVALID_ENCODING , encoding ) ; <nl> + CHECK ( ! str - > IsExternalString ( ) ) ; <nl> + break ; <nl> + } <nl> + } <nl> + <nl> + <nl> + void v8 : : String : : VerifyExternalStringResourceBase ( <nl> + v8 : : String : : ExternalStringResourceBase * value ) const { <nl> + i : : Handle < i : : String > str = Utils : : OpenHandle ( this ) ; <nl> + i : : StringShape shape ( * str ) ; <nl> + const void * expected ; <nl> + / / We expect an external string at this point since GetExternalStringEncoding <nl> + / / should have already been called to rule out non - external strings . <nl> if ( i : : StringShape ( * str ) . IsExternalTwoByte ( ) ) { <nl> - const void * resource = <nl> - i : : Handle < i : : ExternalTwoByteString > : : cast ( str ) - > resource ( ) ; <nl> - expected = reinterpret_cast < const ExternalStringResource * > ( resource ) ; <nl> + expected = i : : ExternalTwoByteString : : cast ( * str ) - > resource ( ) ; <nl> } else { <nl> - expected = NULL ; <nl> + ASSERT ( i : : StringShape ( * str ) . IsExternalAscii ( ) ) ; <nl> + expected = i : : ExternalAsciiString : : cast ( * str ) - > resource ( ) ; <nl> } <nl> - CHECK_EQ ( expected , value ) ; <nl> + <nl> + CHECK_EQ ( expected , <nl> + reinterpret_cast < const ExternalStringResourceBase * > ( value ) ) ; <nl> } <nl> <nl> <nl> Local < String > v8 : : String : : Empty ( ) { <nl> } <nl> <nl> <nl> - Local < String > v8 : : String : : New ( const char * data , int length ) { <nl> + static i : : Handle < i : : String > NewOneByteEncodedString ( <nl> + i : : Factory * factory , const char * data , int length , int encoding ) { <nl> + if ( length = = String : : kUndefinedLength ) length = i : : StrLength ( data ) ; <nl> + typedef v8 : : String S ; <nl> + <nl> + static const int kAsciiHintShift = 16 ; <nl> + ASSERT ( IS_POWER_OF_TWO ( encoding & S : : kAsciiHintMask ) ) ; <nl> + i : : String : : AsciiHint ascii_hint = <nl> + static_cast < i : : String : : AsciiHint > ( encoding > > kAsciiHintShift ) ; <nl> + STATIC_ASSERT ( i : : String : : MAYBE_ASCII = = 0 ) ; <nl> + STATIC_ASSERT ( i : : String : : NOT_ASCII = = <nl> + ( v8 : : String : : NOT_ASCII_HINT > > kAsciiHintShift ) ) ; <nl> + STATIC_ASSERT ( i : : String : : ASCII = = <nl> + ( v8 : : String : : ASCII_HINT > > kAsciiHintShift ) ) ; <nl> + <nl> + int masked_encoding = encoding & S : : kStringEncodingMask ; <nl> + <nl> + if ( masked_encoding = = S : : UTF_8_ENCODING ) { <nl> + return factory - > NewStringFromUtf8 ( <nl> + i : : Vector < const char > ( data , length ) , i : : NOT_TENURED , ascii_hint ) ; <nl> + } else if ( masked_encoding = = S : : LATIN1_ENCODING ) { <nl> + return factory - > NewStringFromLatin1 ( <nl> + i : : Vector < const char > ( data , length ) , i : : NOT_TENURED , ascii_hint ) ; <nl> + } else { / / Wrong encoding . <nl> + return i : : Handle < i : : String > ( ) ; <nl> + } <nl> + } <nl> + <nl> + <nl> + Local < String > v8 : : String : : New ( <nl> + const char * data , int length , int encoding ) { <nl> i : : Isolate * isolate = i : : Isolate : : Current ( ) ; <nl> EnsureInitializedForIsolate ( isolate , " v8 : : String : : New ( ) " ) ; <nl> LOG_API ( isolate , " String : : New ( char ) " ) ; <nl> if ( length = = 0 ) return Empty ( ) ; <nl> ENTER_V8 ( isolate ) ; <nl> - if ( length = = - 1 ) length = i : : StrLength ( data ) ; <nl> - i : : Handle < i : : String > result = <nl> - isolate - > factory ( ) - > NewStringFromUtf8 ( <nl> - i : : Vector < const char > ( data , length ) ) ; <nl> - return Utils : : ToLocal ( result ) ; <nl> + return Utils : : ToLocal ( <nl> + NewOneByteEncodedString ( isolate - > factory ( ) , data , length , encoding ) ) ; <nl> } <nl> <nl> <nl> Local < String > v8 : : String : : Concat ( Handle < String > left , Handle < String > right ) { <nl> } <nl> <nl> <nl> - Local < String > v8 : : String : : NewUndetectable ( const char * data , int length ) { <nl> + Local < String > v8 : : String : : NewUndetectable ( <nl> + const char * data , int length , int encoding ) { <nl> i : : Isolate * isolate = i : : Isolate : : Current ( ) ; <nl> EnsureInitializedForIsolate ( isolate , " v8 : : String : : NewUndetectable ( ) " ) ; <nl> LOG_API ( isolate , " String : : NewUndetectable ( char ) " ) ; <nl> ENTER_V8 ( isolate ) ; <nl> - if ( length = = - 1 ) length = i : : StrLength ( data ) ; <nl> i : : Handle < i : : String > result = <nl> - isolate - > factory ( ) - > NewStringFromUtf8 ( <nl> - i : : Vector < const char > ( data , length ) ) ; <nl> + NewOneByteEncodedString ( isolate - > factory ( ) , data , length , encoding ) ; <nl> result - > MarkAsUndetectable ( ) ; <nl> return Utils : : ToLocal ( result ) ; <nl> } <nl> Local < String > v8 : : String : : New ( const uint16_t * data , int length ) { <nl> LOG_API ( isolate , " String : : New ( uint16_ ) " ) ; <nl> if ( length = = 0 ) return Empty ( ) ; <nl> ENTER_V8 ( isolate ) ; <nl> - if ( length = = - 1 ) length = TwoByteStringLength ( data ) ; <nl> + if ( length = = kUndefinedLength ) length = TwoByteStringLength ( data ) ; <nl> i : : Handle < i : : String > result = <nl> isolate - > factory ( ) - > NewStringFromTwoByte ( <nl> i : : Vector < const uint16_t > ( data , length ) ) ; <nl> Local < String > v8 : : String : : NewUndetectable ( const uint16_t * data , int length ) { <nl> EnsureInitializedForIsolate ( isolate , " v8 : : String : : NewUndetectable ( ) " ) ; <nl> LOG_API ( isolate , " String : : NewUndetectable ( uint16_ ) " ) ; <nl> ENTER_V8 ( isolate ) ; <nl> - if ( length = = - 1 ) length = TwoByteStringLength ( data ) ; <nl> + if ( length = = kUndefinedLength ) length = TwoByteStringLength ( data ) ; <nl> i : : Handle < i : : String > result = <nl> isolate - > factory ( ) - > NewStringFromTwoByte ( <nl> i : : Vector < const uint16_t > ( data , length ) ) ; <nl> Local < String > v8 : : String : : NewExternal ( <nl> } <nl> <nl> <nl> - bool v8 : : String : : MakeExternal ( v8 : : String : : ExternalStringResource * resource ) { <nl> - i : : Handle < i : : String > obj = Utils : : OpenHandle ( this ) ; <nl> - i : : Isolate * isolate = obj - > GetIsolate ( ) ; <nl> + template < class StringResourceType > <nl> + static bool MakeStringExternal ( <nl> + i : : Handle < i : : String > string , StringResourceType * resource ) { <nl> + i : : Isolate * isolate = string - > GetIsolate ( ) ; <nl> if ( IsDeadCheck ( isolate , " v8 : : String : : MakeExternal ( ) " ) ) return false ; <nl> - if ( i : : StringShape ( * obj ) . IsExternalTwoByte ( ) ) { <nl> + if ( i : : StringShape ( * string ) . IsExternal ( ) ) { <nl> return false ; / / Already an external string . <nl> } <nl> ENTER_V8 ( isolate ) ; <nl> - if ( isolate - > string_tracker ( ) - > IsFreshUnusedString ( obj ) ) { <nl> + if ( isolate - > string_tracker ( ) - > IsFreshUnusedString ( string ) ) { <nl> return false ; <nl> } <nl> if ( isolate - > heap ( ) - > IsInGCPostProcessing ( ) ) { <nl> return false ; <nl> } <nl> CHECK ( resource & & resource - > data ( ) ) ; <nl> - bool result = obj - > MakeExternal ( resource ) ; <nl> - if ( result & & ! obj - > IsSymbol ( ) ) { <nl> - isolate - > heap ( ) - > external_string_table ( ) - > AddString ( * obj ) ; <nl> + bool result = string - > MakeExternal ( resource ) ; <nl> + if ( result & & ! string - > IsSymbol ( ) ) { <nl> + isolate - > heap ( ) - > external_string_table ( ) - > AddString ( * string ) ; <nl> } <nl> return result ; <nl> } <nl> <nl> <nl> + bool v8 : : String : : MakeExternal ( ExternalStringResource * resource ) { <nl> + i : : Handle < i : : String > obj = Utils : : OpenHandle ( this ) ; <nl> + return MakeStringExternal ( obj , resource ) ; <nl> + } <nl> + <nl> + <nl> + bool v8 : : String : : MakeExternal ( ExternalAsciiStringResource * resource ) { <nl> + i : : Handle < i : : String > obj = Utils : : OpenHandle ( this ) ; <nl> + ASSERT ( obj - > HasOnlyAsciiChars ( ) ) ; <nl> + return MakeStringExternal ( obj , resource ) ; <nl> + } <nl> + <nl> + <nl> Local < String > v8 : : String : : NewExternal ( <nl> v8 : : String : : ExternalAsciiStringResource * resource ) { <nl> i : : Isolate * isolate = i : : Isolate : : Current ( ) ; <nl> Local < String > v8 : : String : : NewExternal ( <nl> } <nl> <nl> <nl> - bool v8 : : String : : MakeExternal ( <nl> - v8 : : String : : ExternalAsciiStringResource * resource ) { <nl> - i : : Handle < i : : String > obj = Utils : : OpenHandle ( this ) ; <nl> - i : : Isolate * isolate = obj - > GetIsolate ( ) ; <nl> - if ( IsDeadCheck ( isolate , " v8 : : String : : MakeExternal ( ) " ) ) return false ; <nl> - if ( i : : StringShape ( * obj ) . IsExternalTwoByte ( ) ) { <nl> - return false ; / / Already an external string . <nl> - } <nl> + Local < String > v8 : : String : : NewExternal ( ExternalLatin1StringResource * resource , <nl> + int encoding ) { <nl> + typedef v8 : : internal : : Internals I ; <nl> + i : : Isolate * isolate = i : : Isolate : : Current ( ) ; <nl> + EnsureInitializedForIsolate ( isolate , " v8 : : String : : NewExternal ( ) " ) ; <nl> + LOG_API ( isolate , " String : : NewExternal " ) ; <nl> ENTER_V8 ( isolate ) ; <nl> - if ( isolate - > string_tracker ( ) - > IsFreshUnusedString ( obj ) ) { <nl> - return false ; <nl> - } <nl> - if ( isolate - > heap ( ) - > IsInGCPostProcessing ( ) ) { <nl> - return false ; <nl> - } <nl> + ASSERT ( ( encoding & kStringEncodingMask ) = = LATIN1_ENCODING ) ; <nl> CHECK ( resource & & resource - > data ( ) ) ; <nl> - bool result = obj - > MakeExternal ( resource ) ; <nl> - if ( result & & ! obj - > IsSymbol ( ) ) { <nl> - isolate - > heap ( ) - > external_string_table ( ) - > AddString ( * obj ) ; <nl> + bool ascii_hint = ( encoding & kAsciiHintMask ) ; <nl> + i : : Handle < i : : String > result ; <nl> + <nl> + if ( ascii_hint = = ASCII_HINT | | <nl> + ( ascii_hint ! = NOT_ASCII_HINT & & <nl> + i : : String : : IsAscii ( resource - > data ( ) , resource - > length ( ) ) ) ) { <nl> + / / Assert that the ascii hint is correct . <nl> + ASSERT ( ascii_hint ! = ASCII_HINT | | <nl> + i : : String : : IsAscii ( resource - > data ( ) , resource - > length ( ) ) ) ; <nl> + result = NewExternalAsciiStringHandle ( isolate , resource ) ; <nl> + isolate - > heap ( ) - > external_string_table ( ) - > AddString ( * result ) ; <nl> + } else { <nl> + / / We cannot simply take the backing store and use it as an ASCII string , <nl> + / / since it ' s not . Instead , we convert it to an internal string and dispose <nl> + / / the external resource . <nl> + result = isolate - > factory ( ) - > NewStringFromLatin1 ( <nl> + i : : Vector < const char > ( resource - > data ( ) , resource - > length ( ) ) , <nl> + i : : NOT_TENURED , <nl> + i : : String : : NOT_ASCII ) ; <nl> + resource - > Dispose ( ) ; <nl> } <nl> - return result ; <nl> + return Utils : : ToLocal ( result ) ; <nl> } <nl> <nl> <nl> Local < Object > Array : : CloneElementAt ( uint32_t index ) { <nl> } <nl> <nl> <nl> - Local < String > v8 : : String : : NewSymbol ( const char * data , int length ) { <nl> + Local < String > v8 : : String : : NewSymbol ( <nl> + const char * data , int length , int encoding ) { <nl> i : : Isolate * isolate = i : : Isolate : : Current ( ) ; <nl> EnsureInitializedForIsolate ( isolate , " v8 : : String : : NewSymbol ( ) " ) ; <nl> LOG_API ( isolate , " String : : NewSymbol ( char ) " ) ; <nl> ENTER_V8 ( isolate ) ; <nl> - if ( length = = - 1 ) length = i : : StrLength ( data ) ; <nl> - i : : Handle < i : : String > result = <nl> - isolate - > factory ( ) - > LookupSymbol ( i : : Vector < const char > ( data , length ) ) ; <nl> + if ( length = = kUndefinedLength ) length = i : : StrLength ( data ) ; <nl> + i : : Handle < i : : String > result ; <nl> + <nl> + ASSERT ( IS_POWER_OF_TWO ( encoding & kAsciiHintMask ) ) ; <nl> + if ( ( ( encoding & kStringEncodingMask ) = = LATIN1_ENCODING ) & & <nl> + ( ( encoding & kAsciiHintMask ) = = NOT_ASCII_HINT | | <nl> + ! i : : String : : IsAscii ( data , length ) ) ) { <nl> + result = isolate - > factory ( ) - > NewStringFromLatin1 ( <nl> + i : : Vector < const char > ( data , length ) , <nl> + i : : NOT_TENURED , <nl> + i : : String : : NOT_ASCII ) ; <nl> + result = isolate - > factory ( ) - > LookupSymbol ( result ) ; <nl> + } else { / / We can handle UTF8 and ASCII strings here . <nl> + result = <nl> + isolate - > factory ( ) - > LookupSymbol ( i : : Vector < const char > ( data , length ) ) ; <nl> + } <nl> return Utils : : ToLocal ( result ) ; <nl> } <nl> <nl> mmm a / src / factory . cc <nl> ppp b / src / factory . cc <nl> Handle < String > Factory : : NewStringFromAscii ( Vector < const char > string , <nl> } <nl> <nl> Handle < String > Factory : : NewStringFromUtf8 ( Vector < const char > string , <nl> - PretenureFlag pretenure ) { <nl> + PretenureFlag pretenure , <nl> + String : : AsciiHint ascii_hint ) { <nl> CALL_HEAP_FUNCTION ( <nl> isolate ( ) , <nl> - isolate ( ) - > heap ( ) - > AllocateStringFromUtf8 ( string , pretenure ) , <nl> + isolate ( ) - > heap ( ) - > AllocateStringFromUtf8 ( <nl> + string , pretenure , ascii_hint ) , <nl> + String ) ; <nl> + } <nl> + <nl> + <nl> + Handle < String > Factory : : NewStringFromLatin1 ( Vector < const char > string , <nl> + PretenureFlag pretenure , <nl> + String : : AsciiHint ascii_hint ) { <nl> + CALL_HEAP_FUNCTION ( <nl> + isolate ( ) , <nl> + isolate ( ) - > heap ( ) - > AllocateStringFromLatin1 ( <nl> + string , pretenure , ascii_hint ) , <nl> String ) ; <nl> } <nl> <nl> mmm a / src / factory . h <nl> ppp b / src / factory . h <nl> class Factory { <nl> / / flags in the parser . <nl> Handle < String > NewStringFromUtf8 ( <nl> Vector < const char > str , <nl> - PretenureFlag pretenure = NOT_TENURED ) ; <nl> + PretenureFlag pretenure = NOT_TENURED , <nl> + String : : AsciiHint ascii_hint = String : : MAYBE_ASCII ) ; <nl> + <nl> + Handle < String > NewStringFromLatin1 ( <nl> + Vector < const char > str , <nl> + PretenureFlag pretenure = NOT_TENURED , <nl> + String : : AsciiHint ascii_hint = String : : MAYBE_ASCII ) ; <nl> <nl> Handle < String > NewStringFromTwoByte ( <nl> Vector < const uc16 > str , <nl> mmm a / src / heap - inl . h <nl> ppp b / src / heap - inl . h <nl> void PromotionQueue : : ActivateGuardIfOnTheSamePage ( ) { <nl> <nl> <nl> MaybeObject * Heap : : AllocateStringFromUtf8 ( Vector < const char > str , <nl> - PretenureFlag pretenure ) { <nl> - / / Check for ASCII first since this is the common case . <nl> - if ( String : : IsAscii ( str . start ( ) , str . length ( ) ) ) { <nl> + PretenureFlag pretenure , <nl> + String : : AsciiHint ascii_hint ) { <nl> + if ( ( ascii_hint = = String : : MAYBE_ASCII & & <nl> + String : : IsAscii ( str . start ( ) , str . length ( ) ) ) | | <nl> + ascii_hint = = String : : ASCII ) { <nl> + / / Assert that the ASCII - hint is correct . <nl> + ASSERT ( ascii_hint ! = String : : ASCII | | <nl> + String : : IsAscii ( str . start ( ) , str . length ( ) ) ) ; <nl> / / If the string is ASCII , we do not need to convert the characters <nl> / / since UTF8 is backwards compatible with ASCII . <nl> return AllocateStringFromAscii ( str , pretenure ) ; <nl> MaybeObject * Heap : : AllocateStringFromUtf8 ( Vector < const char > str , <nl> } <nl> <nl> <nl> + MaybeObject * Heap : : AllocateStringFromLatin1 ( Vector < const char > str , <nl> + PretenureFlag pretenure , <nl> + String : : AsciiHint ascii_hint ) { <nl> + if ( ( ascii_hint = = String : : MAYBE_ASCII & & <nl> + String : : IsAscii ( str . start ( ) , str . length ( ) ) ) | | <nl> + ascii_hint = = String : : ASCII ) { <nl> + / / Assert that the strict ASCII - hint is correct . <nl> + ASSERT ( ascii_hint ! = String : : ASCII | | <nl> + String : : IsAscii ( str . start ( ) , str . length ( ) ) ) ; <nl> + / / If the string is ASCII , we do not need to convert the characters <nl> + / / since Latin1 is backwards compatible with ASCII . <nl> + return AllocateStringFromAscii ( str , pretenure ) ; <nl> + } <nl> + / / Non - ASCII and we need to decode . <nl> + return AllocateStringFromLatin1Slow ( str , pretenure ) ; <nl> + } <nl> + <nl> + <nl> MaybeObject * Heap : : AllocateSymbol ( Vector < const char > str , <nl> int chars , <nl> uint32_t hash_field ) { <nl> mmm a / src / heap . cc <nl> ppp b / src / heap . cc <nl> <nl> # include " snapshot . h " <nl> # include " store - buffer . h " <nl> # include " v8threads . h " <nl> + # include " v8utils . h " <nl> # include " vm - state - inl . h " <nl> # if V8_TARGET_ARCH_ARM & & ! V8_INTERPRETED_REGEXP <nl> # include " regexp - macro - assembler . h " <nl> MaybeObject * Heap : : ReinitializeJSGlobalProxy ( JSFunction * constructor , <nl> <nl> MaybeObject * Heap : : AllocateStringFromAscii ( Vector < const char > string , <nl> PretenureFlag pretenure ) { <nl> - if ( string . length ( ) = = 1 ) { <nl> + int length = string . length ( ) ; <nl> + if ( length = = 1 ) { <nl> return Heap : : LookupSingleCharacterStringFromCode ( string [ 0 ] ) ; <nl> } <nl> Object * result ; <nl> MaybeObject * Heap : : AllocateStringFromAscii ( Vector < const char > string , <nl> if ( ! maybe_result - > ToObject ( & result ) ) return maybe_result ; <nl> } <nl> <nl> + isolate_ - > counters ( ) - > string_length_ascii ( ) - > Increment ( length ) ; <nl> + <nl> / / Copy the characters into the new object . <nl> - SeqAsciiString * string_result = SeqAsciiString : : cast ( result ) ; <nl> - for ( int i = 0 ; i < string . length ( ) ; i + + ) { <nl> - string_result - > SeqAsciiStringSet ( i , string [ i ] ) ; <nl> - } <nl> + CopyChars ( SeqAsciiString : : cast ( result ) - > GetChars ( ) , string . start ( ) , length ) ; <nl> return result ; <nl> } <nl> <nl> MaybeObject * Heap : : AllocateStringFromUtf8Slow ( Vector < const char > string , <nl> if ( ! maybe_result - > ToObject ( & result ) ) return maybe_result ; <nl> } <nl> <nl> + isolate_ - > counters ( ) - > string_length_utf8 ( ) - > Increment ( chars ) ; <nl> + <nl> / / Convert and copy the characters into the new object . <nl> - String * string_result = String : : cast ( result ) ; <nl> + SeqTwoByteString * twobyte = SeqTwoByteString : : cast ( result ) ; <nl> decoder - > Reset ( string . start ( ) , string . length ( ) ) ; <nl> int i = 0 ; <nl> while ( i < chars ) { <nl> uint32_t r = decoder - > GetNext ( ) ; <nl> if ( r > unibrow : : Utf16 : : kMaxNonSurrogateCharCode ) { <nl> - string_result - > Set ( i + + , unibrow : : Utf16 : : LeadSurrogate ( r ) ) ; <nl> - string_result - > Set ( i + + , unibrow : : Utf16 : : TrailSurrogate ( r ) ) ; <nl> + twobyte - > SeqTwoByteStringSet ( i + + , unibrow : : Utf16 : : LeadSurrogate ( r ) ) ; <nl> + twobyte - > SeqTwoByteStringSet ( i + + , unibrow : : Utf16 : : TrailSurrogate ( r ) ) ; <nl> } else { <nl> - string_result - > Set ( i + + , r ) ; <nl> + twobyte - > SeqTwoByteStringSet ( i + + , r ) ; <nl> } <nl> } <nl> return result ; <nl> } <nl> <nl> <nl> + MaybeObject * Heap : : AllocateStringFromLatin1Slow ( Vector < const char > string , <nl> + PretenureFlag pretenure ) { <nl> + int chars = string . length ( ) ; <nl> + Object * result ; <nl> + { MaybeObject * maybe_result = AllocateRawTwoByteString ( chars , pretenure ) ; <nl> + if ( ! maybe_result - > ToObject ( & result ) ) return maybe_result ; <nl> + } <nl> + <nl> + isolate_ - > counters ( ) - > string_length_latin1 ( ) - > Increment ( chars ) ; <nl> + <nl> + / / Convert and copy the characters into the new object . <nl> + SeqTwoByteString * string_result = SeqTwoByteString : : cast ( result ) ; <nl> + CopyChars ( string_result - > GetChars ( ) , <nl> + reinterpret_cast < const unsigned char * > ( string . start ( ) ) , <nl> + chars ) ; <nl> + return result ; <nl> + } <nl> + <nl> + <nl> MaybeObject * Heap : : AllocateStringFromTwoByte ( Vector < const uc16 > string , <nl> PretenureFlag pretenure ) { <nl> / / Check if the string is an ASCII string . <nl> - MaybeObject * maybe_result ; <nl> - if ( String : : IsAscii ( string . start ( ) , string . length ( ) ) ) { <nl> - maybe_result = AllocateRawAsciiString ( string . length ( ) , pretenure ) ; <nl> - } else { / / It ' s not an ASCII string . <nl> - maybe_result = AllocateRawTwoByteString ( string . length ( ) , pretenure ) ; <nl> - } <nl> Object * result ; <nl> - if ( ! maybe_result - > ToObject ( & result ) ) return maybe_result ; <nl> + int length = string . length ( ) ; <nl> + const uc16 * start = string . start ( ) ; <nl> <nl> - / / Copy the characters into the new object , which may be either ASCII or <nl> - / / UTF - 16 . <nl> - String * string_result = String : : cast ( result ) ; <nl> - for ( int i = 0 ; i < string . length ( ) ; i + + ) { <nl> - string_result - > Set ( i , string [ i ] ) ; <nl> + if ( String : : IsAscii ( start , length ) ) { <nl> + MaybeObject * maybe_result = AllocateRawAsciiString ( length , pretenure ) ; <nl> + if ( ! maybe_result - > ToObject ( & result ) ) return maybe_result ; <nl> + isolate_ - > counters ( ) - > string_length_ascii ( ) - > Increment ( length ) ; <nl> + CopyChars ( SeqAsciiString : : cast ( result ) - > GetChars ( ) , start , length ) ; <nl> + } else { / / It ' s not an ASCII string . <nl> + MaybeObject * maybe_result = AllocateRawTwoByteString ( length , pretenure ) ; <nl> + if ( ! maybe_result - > ToObject ( & result ) ) return maybe_result ; <nl> + isolate_ - > counters ( ) - > string_length_utf16 ( ) - > Increment ( length ) ; <nl> + CopyChars ( SeqTwoByteString : : cast ( result ) - > GetChars ( ) , start , length ) ; <nl> } <nl> + <nl> return result ; <nl> } <nl> <nl> mmm a / src / heap . h <nl> ppp b / src / heap . h <nl> class Heap { <nl> PretenureFlag pretenure = NOT_TENURED ) ; <nl> MUST_USE_RESULT inline MaybeObject * AllocateStringFromUtf8 ( <nl> Vector < const char > str , <nl> - PretenureFlag pretenure = NOT_TENURED ) ; <nl> + PretenureFlag pretenure = NOT_TENURED , <nl> + String : : AsciiHint ascii_hint = String : : MAYBE_ASCII ) ; <nl> MUST_USE_RESULT MaybeObject * AllocateStringFromUtf8Slow ( <nl> Vector < const char > str , <nl> PretenureFlag pretenure = NOT_TENURED ) ; <nl> + MUST_USE_RESULT inline MaybeObject * AllocateStringFromLatin1 ( <nl> + Vector < const char > str , <nl> + PretenureFlag pretenure = NOT_TENURED , <nl> + String : : AsciiHint ascii_hint = String : : MAYBE_ASCII ) ; <nl> + MUST_USE_RESULT MaybeObject * AllocateStringFromLatin1Slow ( <nl> + Vector < const char > str , <nl> + PretenureFlag pretenure = NOT_TENURED ) ; <nl> MUST_USE_RESULT MaybeObject * AllocateStringFromTwoByte ( <nl> Vector < const uc16 > str , <nl> PretenureFlag pretenure = NOT_TENURED ) ; <nl> mmm a / src / objects . h <nl> ppp b / src / objects . h <nl> class String : public HeapObject { <nl> friend class String ; <nl> } ; <nl> <nl> + enum AsciiHint { MAYBE_ASCII = 0 , <nl> + ASCII = 1 , <nl> + NOT_ASCII = 2 } ; <nl> + <nl> / / Get and set the length of the string . <nl> inline int length ( ) ; <nl> inline void set_length ( int value ) ; <nl> mmm a / src / v8 - counters . h <nl> ppp b / src / v8 - counters . h <nl> namespace internal { <nl> SC ( string_add_make_two_char , V8 . StringAddMakeTwoChar ) \ <nl> SC ( string_compare_native , V8 . StringCompareNative ) \ <nl> SC ( string_compare_runtime , V8 . StringCompareRuntime ) \ <nl> + SC ( string_length_utf8 , V8 . StringLengthUtf8 ) \ <nl> + SC ( string_length_ascii , V8 . StringLengthAScii ) \ <nl> + SC ( string_length_latin1 , V8 . StringLengthLatin1 ) \ <nl> + SC ( string_length_utf16 , V8 . StringLengthUtf16 ) \ <nl> SC ( regexp_entry_runtime , V8 . RegExpEntryRuntime ) \ <nl> SC ( regexp_entry_native , V8 . RegExpEntryNative ) \ <nl> SC ( number_to_string_native , V8 . NumberToStringNative ) \ <nl> mmm a / test / cctest / test - api . cc <nl> ppp b / test / cctest / test - api . cc <nl> TEST ( ExternalStringWithDisposeHandling ) { <nl> } <nl> <nl> <nl> + static void TestNewLatin1String ( int encoding1 , int encoding2 ) { <nl> + const char * chars1 = " ASCII 123 " ; <nl> + const char * chars1js = " ' ASCII 123 ' " ; <nl> + int str1_len = strlen ( chars1 ) ; <nl> + const char * chars2 = " Non - ASCII \ xAB \ xCD \ xEF " ; <nl> + const char * chars2js = " ' Non - ASCII \ \ u00ab \ \ u00cd \ \ u00ef ' " ; <nl> + int str2_len = strlen ( chars2 ) ; <nl> + <nl> + Local < String > str1 = String : : New ( chars1 , str1_len , encoding1 ) ; <nl> + Local < String > str2 = String : : New ( chars2 , str2_len , encoding2 ) ; <nl> + Local < String > str1_compare = CompileRun ( chars1js ) - > ToString ( ) ; <nl> + Local < String > str2_compare = CompileRun ( chars2js ) - > ToString ( ) ; <nl> + <nl> + if ( encoding1 & String : : NOT_ASCII_HINT ) { <nl> + CHECK ( v8 : : Utils : : OpenHandle ( * str1 ) - > IsSeqTwoByteString ( ) ) ; <nl> + } else { <nl> + CHECK ( v8 : : Utils : : OpenHandle ( * str1 ) - > IsSeqAsciiString ( ) ) ; <nl> + } <nl> + CHECK ( v8 : : Utils : : OpenHandle ( * str1_compare ) - > IsSeqAsciiString ( ) ) ; <nl> + CHECK ( v8 : : Utils : : OpenHandle ( * str2 ) - > IsSeqTwoByteString ( ) ) ; <nl> + CHECK ( v8 : : Utils : : OpenHandle ( * str2_compare ) - > IsSeqTwoByteString ( ) ) ; <nl> + <nl> + CHECK ( str1_compare - > Equals ( str1 ) ) ; <nl> + CHECK ( str2_compare - > Equals ( str2 ) ) ; <nl> + } <nl> + <nl> + <nl> + TEST ( CreateLatin1String ) { <nl> + v8 : : HandleScope scope ; <nl> + LocalContext env ; <nl> + <nl> + int latin1 = String : : LATIN1_ENCODING ; <nl> + int l_noascii = String : : LATIN1_ENCODING | String : : NOT_ASCII_HINT ; <nl> + int l_ascii = String : : LATIN1_ENCODING | String : : ASCII_HINT ; <nl> + <nl> + TestNewLatin1String ( latin1 , latin1 ) ; <nl> + TestNewLatin1String ( l_ascii , latin1 ) ; <nl> + TestNewLatin1String ( l_noascii , l_noascii ) ; <nl> + } <nl> + <nl> + <nl> + TEST ( ExternalStringEncoding ) { <nl> + v8 : : HandleScope scope ; <nl> + LocalContext env ; <nl> + int counter = 0 ; <nl> + <nl> + { HandleScope scope ; <nl> + uint16_t * two_byte_ascii = AsciiToTwoByteString ( " two byte ascii " ) ; <nl> + uint16_t * two_byte = AsciiToTwoByteString ( " two byte non - ascii \ x99 " ) ; <nl> + char * ascii = i : : StrDup ( " ascii " ) ; <nl> + <nl> + TestResource * two_byte_resource = new TestResource ( two_byte , & counter ) ; <nl> + TestResource * two_byte_ascii_resource = <nl> + new TestResource ( two_byte_ascii , & counter ) ; <nl> + TestAsciiResource * ascii_resource = <nl> + new TestAsciiResource ( ascii , & counter ) ; <nl> + <nl> + Local < String > two_byte_external = String : : NewExternal ( two_byte_resource ) ; <nl> + Local < String > two_byte_ascii_external = <nl> + String : : NewExternal ( two_byte_ascii_resource ) ; <nl> + Local < String > ascii_external = String : : NewExternal ( ascii_resource ) ; <nl> + Local < String > not_external = v8_str ( " not external " ) ; <nl> + <nl> + CHECK_EQ ( String : : UTF_16_ENCODING | String : : NOT_ASCII_HINT , <nl> + two_byte_external - > GetExternalStringEncoding ( ) ) ; <nl> + CHECK_EQ ( String : : UTF_16_ENCODING | String : : ASCII_HINT , <nl> + two_byte_ascii_external - > GetExternalStringEncoding ( ) ) ; <nl> + CHECK_EQ ( String : : LATIN1_ENCODING | String : : ASCII_HINT , <nl> + ascii_external - > GetExternalStringEncoding ( ) ) ; <nl> + CHECK_EQ ( String : : INVALID_ENCODING , <nl> + not_external - > GetExternalStringEncoding ( ) ) ; <nl> + <nl> + CHECK_EQ ( two_byte_resource , two_byte_external - > GetExternalStringResource ( ) ) ; <nl> + CHECK_EQ ( two_byte_ascii_resource , <nl> + two_byte_ascii_external - > GetExternalStringResourceBase ( ) ) ; <nl> + CHECK_EQ ( ascii_resource , ascii_external - > GetExternalStringResourceBase ( ) ) ; <nl> + <nl> + CHECK_EQ ( 0 , counter ) ; <nl> + } <nl> + <nl> + HEAP - > CollectAllGarbage ( i : : Heap : : kNoGCFlags ) ; <nl> + <nl> + CHECK_EQ ( 3 , counter ) ; <nl> + } <nl> + <nl> + <nl> + TEST ( WriteLatin1String ) { <nl> + HandleScope scope ; <nl> + LocalContext env ; <nl> + const char * latin1_ascii = " latin1 ascii " ; <nl> + const char * latin1 = " \ x99 latin1 non - ascii \ xF8 " ; <nl> + const char * concat = " latin1 ascii \ x99 latin1 non - ascii \ xF8 " ; <nl> + const char * sub = " latin1 non - ascii \ xF8 " ; <nl> + <nl> + Local < String > latin1_ascii_string = String : : New ( latin1_ascii , <nl> + String : : kUndefinedLength , <nl> + String : : LATIN1_ENCODING ) ; <nl> + Local < String > latin1_string = String : : New ( latin1 , <nl> + String : : kUndefinedLength , <nl> + String : : LATIN1_ENCODING ) ; <nl> + Local < String > concat_string = String : : Concat ( latin1_ascii_string , <nl> + latin1_string ) ; <nl> + Local < String > sub_string = v8 : : Utils : : ToLocal ( <nl> + FACTORY - > NewSubString ( <nl> + v8 : : Utils : : OpenHandle ( * latin1_string ) , 2 , latin1_string - > Length ( ) ) ) ; <nl> + <nl> + CHECK ( v8 : : Utils : : OpenHandle ( * latin1_ascii_string ) - > IsSeqAsciiString ( ) ) ; <nl> + CHECK ( v8 : : Utils : : OpenHandle ( * latin1_string ) - > IsSeqTwoByteString ( ) ) ; <nl> + CHECK ( v8 : : Utils : : OpenHandle ( * concat_string ) - > IsConsString ( ) ) ; <nl> + CHECK ( v8 : : Utils : : OpenHandle ( * sub_string ) - > IsSlicedString ( ) ) ; <nl> + <nl> + char buffer [ 64 ] ; <nl> + CHECK_EQ ( strlen ( latin1_ascii ) , latin1_ascii_string - > WriteLatin1 ( buffer ) ) ; <nl> + CHECK_EQ ( 0 , strcmp ( latin1_ascii , buffer ) ) ; <nl> + CHECK_EQ ( strlen ( latin1 ) , latin1_string - > WriteLatin1 ( buffer ) ) ; <nl> + CHECK_EQ ( 0 , strcmp ( latin1 , buffer ) ) ; <nl> + CHECK_EQ ( strlen ( concat ) , concat_string - > WriteLatin1 ( buffer ) ) ; <nl> + CHECK_EQ ( 0 , strcmp ( concat , buffer ) ) ; <nl> + CHECK_EQ ( strlen ( sub ) , sub_string - > WriteLatin1 ( buffer ) ) ; <nl> + CHECK_EQ ( 0 , strcmp ( sub , buffer ) ) ; <nl> + <nl> + memset ( buffer , 0x1 , sizeof ( buffer ) ) ; <nl> + CHECK_EQ ( strlen ( latin1 ) , <nl> + latin1_string - > WriteLatin1 ( buffer , <nl> + 0 , <nl> + String : : kUndefinedLength , <nl> + String : : NO_NULL_TERMINATION ) ) ; <nl> + CHECK_EQ ( 0 , strncmp ( latin1 , buffer , strlen ( latin1 ) ) ) ; <nl> + CHECK_NE ( 0 , strcmp ( latin1 , buffer ) ) ; <nl> + buffer [ strlen ( latin1 ) ] = ' \ 0 ' ; <nl> + CHECK_EQ ( 0 , strcmp ( latin1 , buffer ) ) ; <nl> + <nl> + CHECK_EQ ( strlen ( latin1 ) - 2 , <nl> + latin1_string - > WriteLatin1 ( buffer , 2 ) ) ; <nl> + CHECK_EQ ( 0 , strncmp ( latin1 + 2 , buffer , strlen ( latin1 ) ) ) ; <nl> + } <nl> + <nl> + <nl> + class TestLatin1Resource : public String : : ExternalLatin1StringResource { <nl> + public : <nl> + explicit TestLatin1Resource ( const char * data , int * counter = NULL ) <nl> + : data_ ( data ) , length_ ( strlen ( data ) ) , counter_ ( counter ) { } <nl> + <nl> + ~ TestLatin1Resource ( ) { <nl> + i : : DeleteArray ( data_ ) ; <nl> + if ( counter_ ! = NULL ) + + * counter_ ; <nl> + } <nl> + <nl> + const char * data ( ) const { <nl> + return data_ ; <nl> + } <nl> + <nl> + size_t length ( ) const { <nl> + return length_ ; <nl> + } <nl> + private : <nl> + const char * data_ ; <nl> + size_t length_ ; <nl> + int * counter_ ; <nl> + } ; <nl> + <nl> + <nl> + TEST ( ExternalLatin1String ) { <nl> + HandleScope scope ; <nl> + LocalContext env ; <nl> + int counter = 0 ; <nl> + <nl> + { HandleScope scope ; <nl> + char * latin1_ascii_a = i : : StrDup ( " latin1 ascii a " ) ; <nl> + char * latin1_ascii_b = i : : StrDup ( " latin1 ascii b " ) ; <nl> + char * latin1_a = i : : StrDup ( " latin non - ascii \ xAA " ) ; <nl> + char * latin1_b = i : : StrDup ( " latin non - ascii \ xBB " ) ; <nl> + <nl> + TestLatin1Resource * latin1_ascii_a_resource = <nl> + new TestLatin1Resource ( latin1_ascii_a , & counter ) ; <nl> + TestLatin1Resource * latin1_ascii_b_resource = <nl> + new TestLatin1Resource ( latin1_ascii_b , & counter ) ; <nl> + TestLatin1Resource * latin1_a_resource = <nl> + new TestLatin1Resource ( latin1_a , & counter ) ; <nl> + TestLatin1Resource * latin1_b_resource = <nl> + new TestLatin1Resource ( latin1_b , & counter ) ; <nl> + <nl> + Local < String > latin1_ascii_a_external = <nl> + String : : NewExternal ( latin1_ascii_a_resource ) ; <nl> + Local < String > latin1_ascii_b_external = String : : NewExternal ( <nl> + latin1_ascii_b_resource , <nl> + String : : LATIN1_ENCODING | String : : ASCII_HINT ) ; <nl> + CHECK_EQ ( 0 , counter ) ; <nl> + <nl> + / / Non - ascii latin1 strings are internalized immediately as two - byte <nl> + / / string and the external resource is disposed . <nl> + Local < String > latin1_a_external = String : : NewExternal ( latin1_a_resource ) ; <nl> + Local < String > latin1_b_external = String : : NewExternal ( <nl> + latin1_b_resource , String : : LATIN1_ENCODING | String : : NOT_ASCII_HINT ) ; <nl> + CHECK ( v8 : : Utils : : OpenHandle ( * latin1_a_external ) - > IsSeqTwoByteString ( ) ) ; <nl> + CHECK ( v8 : : Utils : : OpenHandle ( * latin1_b_external ) - > IsSeqTwoByteString ( ) ) ; <nl> + CHECK_EQ ( 2 , counter ) ; <nl> + <nl> + CHECK_EQ ( latin1_ascii_a_external - > GetExternalStringEncoding ( ) , <nl> + ( v8 : : String : : LATIN1_ENCODING | v8 : : String : : ASCII_HINT ) ) ; <nl> + CHECK_EQ ( latin1_ascii_b_external - > GetExternalStringEncoding ( ) , <nl> + ( v8 : : String : : LATIN1_ENCODING | v8 : : String : : ASCII_HINT ) ) ; <nl> + CHECK_EQ ( latin1_a_external - > GetExternalStringEncoding ( ) , <nl> + v8 : : String : : INVALID_ENCODING ) ; <nl> + CHECK_EQ ( latin1_b_external - > GetExternalStringEncoding ( ) , <nl> + v8 : : String : : INVALID_ENCODING ) ; <nl> + <nl> + CHECK_EQ ( latin1_ascii_a_resource , <nl> + latin1_ascii_a_external - > GetExternalStringResourceBase ( ) ) ; <nl> + CHECK_EQ ( latin1_ascii_b_resource , <nl> + latin1_ascii_b_external - > GetExternalStringResourceBase ( ) ) ; <nl> + } <nl> + <nl> + HEAP - > CollectAllGarbage ( i : : Heap : : kNoGCFlags ) ; <nl> + CHECK_EQ ( 4 , counter ) ; <nl> + } <nl> + <nl> + <nl> + TEST ( ExternalizeLatin1String ) { <nl> + HandleScope scope ; <nl> + LocalContext env ; <nl> + int counter = 0 ; <nl> + <nl> + { HandleScope scope ; <nl> + Local < String > latin1_a_ascii = String : : New ( " latin1 a ascii " ) ; <nl> + Local < String > latin1_b_ascii = String : : New ( " latin1 b ascii " ) ; <nl> + Local < String > latin1 = String : : New ( " latin1 non - ascii \ xAA " , <nl> + String : : kUndefinedLength , <nl> + String : : LATIN1_ENCODING ) ; <nl> + <nl> + CHECK ( v8 : : Utils : : OpenHandle ( * latin1_a_ascii ) - > IsSeqAsciiString ( ) ) ; <nl> + CHECK ( v8 : : Utils : : OpenHandle ( * latin1_b_ascii ) - > IsSeqAsciiString ( ) ) ; <nl> + CHECK ( v8 : : Utils : : OpenHandle ( * latin1 ) - > IsSeqTwoByteString ( ) ) ; <nl> + <nl> + / / Run GC twice to put those strings into old space for externalizing . <nl> + HEAP - > CollectGarbage ( i : : NEW_SPACE ) ; <nl> + HEAP - > CollectGarbage ( i : : NEW_SPACE ) ; <nl> + <nl> + char * latin1_a_ascii_chars = i : : NewArray < char > ( 64 ) ; <nl> + uint16_t * latin1_b_ascii_chars = i : : NewArray < uint16_t > ( 64 ) ; <nl> + uint16_t * latin1_chars = i : : NewArray < uint16_t > ( 64 ) ; <nl> + <nl> + latin1_a_ascii - > WriteLatin1 ( latin1_a_ascii_chars ) ; <nl> + latin1_b_ascii - > Write ( latin1_b_ascii_chars ) ; <nl> + latin1 - > Write ( latin1_chars ) ; <nl> + <nl> + TestLatin1Resource * latin1_a_ascii_resource = <nl> + new TestLatin1Resource ( latin1_a_ascii_chars , & counter ) ; <nl> + TestResource * latin1_b_ascii_resource = <nl> + new TestResource ( latin1_b_ascii_chars , & counter ) ; <nl> + TestResource * latin1_resource = <nl> + new TestResource ( latin1_chars , & counter ) ; <nl> + <nl> + CHECK ( latin1_a_ascii - > MakeExternal ( latin1_a_ascii_resource ) ) ; <nl> + CHECK ( latin1_a_ascii - > IsExternalAscii ( ) ) ; <nl> + CHECK_EQ ( latin1_a_ascii - > GetExternalStringEncoding ( ) , <nl> + ( v8 : : String : : LATIN1_ENCODING | v8 : : String : : ASCII_HINT ) ) ; <nl> + CHECK_EQ ( latin1_a_ascii_resource , <nl> + latin1_a_ascii - > GetExternalStringResourceBase ( ) ) ; <nl> + CHECK ( latin1_a_ascii - > Equals ( String : : New ( " latin1 a ascii " ) ) ) ; <nl> + <nl> + CHECK ( latin1_b_ascii - > MakeExternal ( latin1_b_ascii_resource ) ) ; <nl> + CHECK ( latin1_b_ascii - > IsExternal ( ) ) ; <nl> + CHECK_EQ ( latin1_b_ascii - > GetExternalStringEncoding ( ) , <nl> + ( v8 : : String : : UTF_16_ENCODING | v8 : : String : : ASCII_HINT ) ) ; <nl> + CHECK_EQ ( latin1_b_ascii_resource , <nl> + latin1_b_ascii - > GetExternalStringResourceBase ( ) ) ; <nl> + CHECK ( latin1_b_ascii - > Equals ( String : : New ( " latin1 b ascii " ) ) ) ; <nl> + <nl> + CHECK ( latin1 - > MakeExternal ( latin1_resource ) ) ; <nl> + CHECK ( latin1 - > IsExternal ( ) ) ; <nl> + CHECK_EQ ( latin1 - > GetExternalStringEncoding ( ) , <nl> + ( v8 : : String : : UTF_16_ENCODING | v8 : : String : : NOT_ASCII_HINT ) ) ; <nl> + CHECK_EQ ( latin1_resource , <nl> + latin1 - > GetExternalStringResourceBase ( ) ) ; <nl> + CHECK ( latin1 - > Equals ( String : : New ( " latin1 non - ascii \ xAA " , <nl> + String : : kUndefinedLength , <nl> + String : : LATIN1_ENCODING ) ) ) ; <nl> + } <nl> + <nl> + HEAP - > CollectAllGarbage ( i : : Heap : : kNoGCFlags ) ; <nl> + CHECK_EQ ( 3 , counter ) ; <nl> + } <nl> + <nl> + <nl> THREADED_TEST ( StringConcat ) { <nl> { <nl> - v8 : : HandleScope scope ; <nl> + HandleScope scope ; <nl> LocalContext env ; <nl> const char * one_byte_string_1 = " function a_times_t " ; <nl> const char * two_byte_string_1 = " wo_plus_b ( a , b ) { return " ; <nl>
Add basic support for Latin1 to the API .
v8/v8
74f06b1f998bf66378db1d310dd533b0be172928
2012-09-03T15:06:36Z
mmm a / src / core / lib / gprpp / optional . h <nl> ppp b / src / core / lib / gprpp / optional . h <nl> class Optional { <nl> void reset ( ) { set_ = false ; } <nl> <nl> T value ( ) { return value_ ; } <nl> + <nl> + private : <nl> T value_ ; <nl> bool set_ = false ; <nl> } ; <nl> mmm a / src / core / lib / iomgr / buffer_list . h <nl> ppp b / src / core / lib / iomgr / buffer_list . h <nl> struct ConnectionMetrics { <nl> / * Delivery rate in Bytes / s . * / <nl> Optional < uint64_t > delivery_rate ; <nl> / * If the delivery rate is limited by the application , this is set to true . * / <nl> - Optional < uint64_t > is_delivery_rate_app_limited ; <nl> + Optional < bool > is_delivery_rate_app_limited ; <nl> / * Total packets retransmitted . * / <nl> Optional < uint32_t > packet_retx ; <nl> / * Total packets retransmitted spuriously . This metric is smaller than or <nl>
Reviewer comments
grpc/grpc
789870a00bd358f84ac65dd63a630d6d42f84d31
2019-01-19T20:39:11Z
mmm a / ChangeLog <nl> ppp b / ChangeLog <nl> <nl> <nl> * Fix terminal emulation and argument parsing on FreeBSD <nl> <nl> + * Fix alignment problems on ARM <nl> + <nl> * Now prints message of the day <nl> <nl> * Add support for FreeBSD , Cygwin , RHEL / CentOS 5 , OS X 10 . 5 on PPC . <nl> mmm a / configure . ac <nl> ppp b / configure . ac <nl> <nl> # Process this file with autoconf to produce a configure script . <nl> <nl> AC_PREREQ ( [ 2 . 61 ] ) <nl> - AC_INIT ( [ mosh ] , [ 1 . 1 . 98 ] , [ mosh - devel @ mit . edu ] ) <nl> + AC_INIT ( [ mosh ] , [ 1 . 1 . 99 ] , [ mosh - devel @ mit . edu ] ) <nl> AM_INIT_AUTOMAKE ( [ - Wall - Werror foreign ] ) <nl> m4_ifdef ( [ AM_SILENT_RULES ] , [ AM_SILENT_RULES ( [ yes ] ) ] ) <nl> AC_CONFIG_SRCDIR ( [ src / frontend / mosh - client . cc ] ) <nl> mmm a / debian / changelog <nl> ppp b / debian / changelog <nl> <nl> + mosh ( 1 . 1 . 99 - 1 ) unstable ; urgency = low <nl> + <nl> + * Fix build problems on FreeBSD 7 and 8 <nl> + <nl> + - - Keith Winstein < keithw @ mit . edu > Tue , 24 Apr 2012 23 : 52 : 22 - 0400 <nl> + <nl> mosh ( 1 . 1 . 98 - 1 ) unstable ; urgency = low <nl> <nl> * Fix build problems on Cygwin <nl> mmm a / scripts / mosh <nl> ppp b / scripts / mosh <nl> <nl> # You should have received a copy of the GNU General Public License <nl> # along with this program . If not , see < http : / / www . gnu . org / licenses / > . <nl> <nl> - my $ MOSH_VERSION = ' 1 . 1 . 98 ' ; <nl> + my $ MOSH_VERSION = ' 1 . 1 . 99 ' ; <nl> <nl> use warnings ; <nl> use strict ; <nl>
Bump version to 1 . 1 . 99 ( release candidate )
mobile-shell/mosh
072863f0b94eb6c16143f2bdfafcd8170b8664cb
2012-04-25T03:56:05Z
mmm a / README . md <nl> ppp b / README . md <nl> compiler for C + + 14 support and create a symlink : <nl> <nl> # # # Getting Sources for Swift and Related Projects <nl> <nl> - For those checking out sources as read - only : <nl> + For those checking out sources as read - only : <nl> <nl> git clone https : / / github . com / apple / swift . git swift <nl> git clone https : / / github . com / apple / swift - llvm . git llvm <nl> compiler for C + + 14 support and create a symlink : <nl> git clone https : / / github . com / apple / swift - corelibs - xctest . git <nl> git clone https : / / github . com / apple / swift - corelibs - foundation . git <nl> <nl> - For those who plan on regular making direct commits , cloning over <nl> - SSH may provide a better experience ( which requires uploading <nl> - SSH keys to GitHub ) : <nl> + For those who plan on regular making direct commits , cloning over <nl> + SSH may provide a better experience ( which requires uploading <nl> + SSH keys to GitHub ) : <nl> <nl> git clone git @ github . com : apple / swift . git swift <nl> git clone git @ github . com : apple / swift - llvm . git llvm <nl>
Merge pull request from Fawxy / patch - 1
apple/swift
4a03bb2b95d5ce3fb020bd3e020581115133e6b0
2015-12-04T19:14:20Z
mmm a / hphp / runtime / vm / jit / store - elim . cpp <nl> ppp b / hphp / runtime / vm / jit / store - elim . cpp <nl> BlockAnalysis analyze_block ( Global & genv , Block * block ) { <nl> <nl> void find_all_stores ( Global & genv , Block * blk , uint32_t id , <nl> jit : : vector < IRInstruction * > & stores , <nl> - jit : : hash_set < Block * > & seen ) { <nl> + jit : : hash_set < void * > & seen ) { <nl> ITRACE ( 7 , " find_all_stores : { } B { } \ n " , id , blk - > id ( ) ) ; <nl> Trace : : Indent _i ; <nl> blk - > forEachPred ( <nl> void find_all_stores ( Global & genv , Block * blk , uint32_t id , <nl> IRInstruction * inst ; <nl> if ( ( inst = pst . instruction ( ) ) ! = nullptr | | <nl> ( inst = pst . processed ( ) ) ! = nullptr ) { <nl> - if ( inst - > block ( ) = = pred | | seen . insert ( inst - > block ( ) ) . second ) { <nl> + if ( seen . insert ( inst ) . second ) { <nl> ITRACE ( 7 , " find_all_stores : { } B { } pred B { } : adding { } \ n " , <nl> id , blk - > id ( ) , pred - > id ( ) , inst - > toString ( ) ) ; <nl> stores . push_back ( inst ) ; <nl> void find_all_stores ( Global & genv , Block * blk , uint32_t id , <nl> Block * b ; <nl> if ( ( b = pst . block ( ) ) ! = nullptr | | <nl> ( b = pst . pending ( ) ) ! = nullptr ) { <nl> + if ( b ! = pred & & seen . count ( b ) ) { <nl> + ITRACE ( 7 , <nl> + " find_all_stores : { } B { } pred B { } previously processed B { } \ n " , <nl> + id , blk - > id ( ) , pred - > id ( ) , b - > id ( ) ) ; <nl> + return ; <nl> + } <nl> ITRACE ( 7 , " find_all_stores : { } B { } pred B { } recur to B { } \ n " , <nl> id , blk - > id ( ) , pred - > id ( ) , b - > id ( ) ) ; <nl> return find_all_stores ( genv , b , id , stores , seen ) ; <nl> IRInstruction * resolve_ts ( Global & genv , Block * blk , <nl> void resolve_cycle ( Global & genv , TrackedStore & ts , Block * blk , uint32_t id ) { <nl> genv . needsReflow = true ; <nl> jit : : vector < IRInstruction * > stores ; <nl> - jit : : hash_set < Block * > seen ; <nl> + jit : : hash_set < void * > seen ; <nl> / / find all the stores , so we can determine <nl> / / whether a phi is actually required for each <nl> / / src ( also , we need a candidate store to clone ) <nl>
Fix a bug in store - elim
facebook/hhvm
e20aecdf106eb15bb6e24d3714a79e75b03f6ae0
2018-04-11T02:59:38Z
mmm a / README . md <nl> ppp b / README . md <nl> view of the available documentation . In particular , the documents titled <nl> [ Debugging the Swift Compiler ] ( docs / DebuggingTheCompiler . md ) and <nl> [ Continuous Integration for Swift ] ( docs / ContinuousIntegration . md ) are very <nl> helpful to understand before submitting your first PR . <nl> - <nl> - # # # Building Documentation <nl> - <nl> - To read the compiler documentation , start by installing the <nl> - [ Sphinx ] ( http : / / sphinx - doc . org ) documentation generator tool by running the <nl> - command : <nl> - <nl> - easy_install - U " Sphinx < 2 . 0 " <nl> - <nl> - Once complete , you can build the Swift documentation by changing directory into <nl> - [ docs ] ( https : / / github . com / apple / swift / tree / master / docs ) and typing ` make ` . This <nl> - compiles the ` . rst ` files in the [ docs ] ( https : / / github . com / apple / swift / tree / master / docs ) <nl> - directory into HTML in the ` docs / _build / html ` directory . <nl> - <nl> - Many of the docs are out of date , but you can see some historical design <nl> - documents in the ` docs ` directory . <nl> - <nl> - Another source of documentation is the standard library itself , located in <nl> - ` stdlib ` . Much of the language is actually implemented in the library <nl> - ( including ` Int ` ) , and the standard library gives some examples of what can be <nl> - expressed today . <nl> mmm a / docs / HowToGuides / FAQ . md <nl> ppp b / docs / HowToGuides / FAQ . md <nl> This very depends on what X is , but some broad guidelines are : <nl> - Use ` grep - i - r " mypattern " . ` . <nl> 2 . Go through the [ Documentation Index ] ( / docs / README . md ) . <nl> <nl> + # # # How do I build the documentation as HTML ? <nl> + <nl> + You can build the ReST formatted documentation as HTML using Sphinx . Follow <nl> + [ Sphinx ' s installation instructions ] [ ] and check that ` sphinx - build ` is <nl> + available on your ` PATH ` : <nl> + <nl> + [ Sphinx ' s installation instructions ] : https : / / www . sphinx - doc . org / en / master / usage / installation . html <nl> + <nl> + ` ` ` sh <nl> + sphinx - build - - version <nl> + ` ` ` <nl> + <nl> + If that succeeds , you can build the documentation using ` make ` <nl> + <nl> + ` ` ` sh <nl> + make - C docs <nl> + ` ` ` <nl> + <nl> + ( Tested with ` sphinx - build ` version 3 . 2 . 1 . ) <nl> + <nl> + This compiles the ` . rst ` files in the ` docs ` directory into HTML in the <nl> + ` docs / _build / html ` directory . <nl> + <nl> + For the Markdown documentation , you can view the rendered HTML directly on <nl> + GitHub . For example , this file is rendered on GitHub at <nl> + https : / / github . com / apple / swift / tree / master / docs / HowToGuides / FAQ . md . <nl> + <nl> + HTML documentation for the standard library on Darwin platforms is hosted on the <nl> + [ Apple Developer website ] ( https : / / developer . apple . com / documentation / swift / swift_standard_library ) . <nl> + <nl> # # Pull Request Workflow <nl> <nl> # # # How do I format my changes ? <nl>
[ docs ] Revise documentation building instructions and move to FAQ . md .
apple/swift
ae8db93dd04bebeaa3b33538740dc1c19d9f3645
2020-09-09T03:28:11Z
mmm a / site / source / docs / compiling / Building - Projects . rst <nl> ppp b / site / source / docs / compiling / Building - Projects . rst <nl> To build with Emscripten , you would instead use the following commands : <nl> <nl> The file output from * make * might have a different suffix : * * . a * * for a static library archive , * * . so * * for a shared library , * * . o * * or * * . bc * * for object files ( these file extensions are the same as * gcc * would use for the different types ) . Irrespective of the file extension , these files contain linked LLVM bitcode that * emcc * can compile into JavaScript in the final step . <nl> <nl> - Where possible it is better to generate shared library files ( * * . so * * ) rather than archives ( * * . a * * ) — this is generally a simple change in your project ' s build system . Shared libraries are simpler , and are more predictable with respect to linking and elimination of unneeded code . <nl> - <nl> The last step is to compile the linked bitcode into JavaScript . We do this by calling * emcc * again , specifying the linked LLVM bitcode file as an input , and a JavaScript file as the output . <nl> <nl> <nl> Projects that use * configure * , * cmake * , or some other portable configuration met <nl> . . note : : In general * configure * is not a good match for a cross - compiler like Emscripten . * configure * is designed to build natively for the local setup , and works hard to find the native build system and the local system headers . With a cross - compiler , you are targeting a different system , and ignoring these headers etc . <nl> <nl> <nl> + Archive ( . a ) files <nl> + mmmmmmmmmmmmmmmmmm <nl> + <nl> + Emscripten supports * * . a * * archive files , which are bundles of object files . This is an old format for libraries , and it has special semantics - for example , the order of linking matters with * * . a * * files , but not with plain object files ( in * * . bc * * , * * . o * * or * * . so * * ) . For the most part those special semantics should work in Emscripten , however , we support * * . a * * files using llvm ' s tools , which have a few limitations . <nl> + <nl> + The main limitation is that if you have multiple files in a single * * . a * * archive that have the same basename ( for example , ` ` dir1 / a . o , dir2 / a . o ` ` ) , then llvm - ar cannot access both of those files . Emscripten will attempt to work around this by adding a hash to the basename , but collisions are still possible in principle . <nl> + <nl> + Where possible it is better to generate shared library files ( * * . so * * ) rather than archives ( * * . a * * ) — this is generally a simple change in your project ' s build system . Shared libraries are simpler , and are more predictable with respect to linking . <nl> + <nl> <nl> Manually using emcc <nl> = = = = = = = = = = = = = = = = = = = <nl>
document . a issues
emscripten-core/emscripten
88f6f88ca470f68e5bd4f6f8cab2c035c3ff644d
2015-09-03T20:21:10Z
mmm a / Marlin / src / gcode / queue . cpp <nl> ppp b / Marlin / src / gcode / queue . cpp <nl> inline void get_serial_commands ( ) { <nl> | | ( ( sd_char = = ' # ' | | sd_char = = ' : ' ) & & ! sd_comment_mode ) <nl> ) { <nl> if ( card_eof ) { <nl> - SERIAL_PROTOCOLLNPGM ( MSG_FILE_PRINTED ) ; <nl> + <nl> card . printingHasFinished ( ) ; <nl> - # if ENABLED ( PRINTER_EVENT_LEDS ) <nl> - LCD_MESSAGEPGM ( MSG_INFO_COMPLETED_PRINTS ) ; <nl> - set_led_color ( 0 , 255 , 0 ) ; / / Green <nl> - # if HAS_RESUME_CONTINUE <nl> - enqueue_and_echo_commands_P ( PSTR ( " M0 " ) ) ; / / end of the queue ! <nl> - # else <nl> - safe_delay ( 1000 ) ; <nl> + <nl> + if ( card . sdprinting ) <nl> + sd_count = 0 ; / / If a sub - file was printing , continue from call point <nl> + else { <nl> + SERIAL_PROTOCOLLNPGM ( MSG_FILE_PRINTED ) ; <nl> + # if ENABLED ( PRINTER_EVENT_LEDS ) <nl> + LCD_MESSAGEPGM ( MSG_INFO_COMPLETED_PRINTS ) ; <nl> + set_led_color ( 0 , 255 , 0 ) ; / / Green <nl> + # if HAS_RESUME_CONTINUE <nl> + enqueue_and_echo_commands_P ( PSTR ( " M0 " ) ) ; / / end of the queue ! <nl> + # else <nl> + safe_delay ( 1000 ) ; <nl> + # endif <nl> + set_led_color ( 0 , 0 , 0 ) ; / / OFF <nl> # endif <nl> - set_led_color ( 0 , 0 , 0 ) ; / / OFF <nl> - # endif <nl> - card . checkautostart ( true ) ; <nl> + card . checkautostart ( true ) ; <nl> + } <nl> } <nl> else if ( n = = - 1 ) { <nl> SERIAL_ERROR_START ( ) ; <nl> mmm a / Marlin / src / gcode / sdcard / M20 - M30_M32 - M34_M928 . cpp <nl> ppp b / Marlin / src / gcode / sdcard / M20 - M30_M32 - M34_M928 . cpp <nl> void GcodeSuite : : M30 ( ) { <nl> <nl> / * * <nl> * M32 : Select file and start SD Print <nl> + * <nl> + * Examples : <nl> + * <nl> + * M32 ! PATH / TO / FILE . GCO # ; Start FILE . GCO <nl> + * M32 P ! PATH / TO / FILE . GCO # ; Start FILE . GCO as a procedure <nl> + * M32 S60 ! PATH / TO / FILE . GCO # ; Start FILE . GCO at byte 60 <nl> + * <nl> * / <nl> void GcodeSuite : : M32 ( ) { <nl> - if ( IS_SD_PRINTING ) <nl> - stepper . synchronize ( ) ; <nl> - <nl> - char * namestartpos = parser . string_arg ; <nl> - const bool call_procedure = parser . boolval ( ' P ' ) ; <nl> + if ( card . sdprinting ) stepper . synchronize ( ) ; <nl> <nl> if ( card . cardOK ) { <nl> - card . openFile ( namestartpos , true , call_procedure ) ; <nl> + const bool call_procedure = parser . boolval ( ' P ' ) ; <nl> + <nl> + card . openFile ( parser . string_arg , true , call_procedure ) ; <nl> <nl> - if ( parser . seenval ( ' S ' ) ) <nl> - card . setIndex ( parser . value_long ( ) ) ; <nl> + if ( parser . seenval ( ' S ' ) ) card . setIndex ( parser . value_long ( ) ) ; <nl> <nl> card . startFileprint ( ) ; <nl> <nl> mmm a / Marlin / src / sd / cardreader . cpp <nl> ppp b / Marlin / src / sd / cardreader . cpp <nl> void CardReader : : openLogFile ( char * name ) { <nl> openFile ( name , false ) ; <nl> } <nl> <nl> + void appendAtom ( SdFile & file , char * & dst , uint8_t & cnt ) { <nl> + file . getFilename ( dst ) ; <nl> + while ( * dst & & cnt < MAXPATHNAMELENGTH ) { dst + + ; cnt + + ; } <nl> + if ( cnt < MAXPATHNAMELENGTH ) { * dst = ' / ' ; dst + + ; cnt + + ; } <nl> + } <nl> + <nl> void CardReader : : getAbsFilename ( char * t ) { <nl> - uint8_t cnt = 0 ; <nl> - * t = ' / ' ; t + + ; cnt + + ; <nl> - for ( uint8_t i = 0 ; i < workDirDepth ; i + + ) { <nl> - workDirParents [ i ] . getFilename ( t ) ; / / SDBaseFile . getfilename ! <nl> - while ( * t & & cnt < MAXPATHNAMELENGTH ) { t + + ; cnt + + ; } / / crawl counter forward . <nl> + * t + + = ' / ' ; / / Root folder <nl> + uint8_t cnt = 1 ; <nl> + <nl> + for ( uint8_t i = 0 ; i < workDirDepth ; i + + ) / / Loop to current work dir <nl> + appendAtom ( workDirParents [ i ] , t , cnt ) ; <nl> + <nl> + if ( cnt < MAXPATHNAMELENGTH - ( FILENAME_LENGTH ) ) { <nl> + appendAtom ( file , t , cnt ) ; <nl> + - - t ; <nl> } <nl> - if ( cnt < MAXPATHNAMELENGTH - ( FILENAME_LENGTH ) ) <nl> - file . getFilename ( t ) ; <nl> - else <nl> - t [ 0 ] = 0 ; <nl> + * t = ' \ 0 ' ; <nl> } <nl> <nl> - void CardReader : : openFile ( char * name , bool read , bool push_current / * = false * / ) { <nl> + void CardReader : : openFile ( char * name , const bool read , const bool subcall / * = false * / ) { <nl> <nl> if ( ! cardOK ) return ; <nl> <nl> uint8_t doing = 0 ; <nl> - if ( isFileOpen ( ) ) { / / replacing current file by new file , or subfile call <nl> - if ( push_current ) { <nl> + if ( isFileOpen ( ) ) { / / Replacing current file or doing a subroutine <nl> + if ( subcall ) { <nl> if ( file_subcall_ctr > SD_PROCEDURE_DEPTH - 1 ) { <nl> SERIAL_ERROR_START ( ) ; <nl> SERIAL_ERRORPGM ( " trying to call sub - gcode files with too many levels . MAX level is : " ) ; <nl> void CardReader : : openFile ( char * name , bool read , bool push_current / * = false * / ) { <nl> return ; <nl> } <nl> <nl> - / / Store current filename and position <nl> + / / Store current filename ( based on workDirParents ) and position <nl> getAbsFilename ( proc_filenames [ file_subcall_ctr ] ) ; <nl> + filespos [ file_subcall_ctr ] = sdpos ; <nl> <nl> SERIAL_ECHO_START ( ) ; <nl> SERIAL_ECHOPAIR ( " SUBROUTINE CALL target : \ " " , name ) ; <nl> SERIAL_ECHOPAIR ( " \ " parent : \ " " , proc_filenames [ file_subcall_ctr ] ) ; <nl> SERIAL_ECHOLNPAIR ( " \ " pos " , sdpos ) ; <nl> - filespos [ file_subcall_ctr ] = sdpos ; <nl> file_subcall_ctr + + ; <nl> } <nl> else <nl> doing = 1 ; <nl> } <nl> - else { / / Opening fresh file <nl> + else if ( subcall ) { / / Returning from a subcall ? <nl> + SERIAL_ECHO_START ( ) ; <nl> + SERIAL_ECHOLNPGM ( " END SUBROUTINE " ) ; <nl> + } <nl> + else { / / Opening fresh file <nl> doing = 2 ; <nl> file_subcall_ctr = 0 ; / / Reset procedure depth in case user cancels print while in procedure <nl> } <nl> uint16_t CardReader : : getnrfilenames ( ) { <nl> } <nl> <nl> void CardReader : : chdir ( const char * relpath ) { <nl> - SdFile newfile ; <nl> + SdFile newDir ; <nl> SdFile * parent = & root ; <nl> <nl> if ( workDir . isOpen ( ) ) parent = & workDir ; <nl> <nl> - if ( ! newfile . open ( * parent , relpath , O_READ ) ) { <nl> + if ( ! newDir . open ( * parent , relpath , O_READ ) ) { <nl> SERIAL_ECHO_START ( ) ; <nl> SERIAL_ECHOPGM ( MSG_SD_CANT_ENTER_SUBDIR ) ; <nl> SERIAL_ECHOLN ( relpath ) ; <nl> } <nl> else { <nl> + workDir = newDir ; <nl> if ( workDirDepth < MAX_DIR_DEPTH ) <nl> - workDirParents [ workDirDepth + + ] = * parent ; <nl> - workDir = newfile ; <nl> + workDirParents [ workDirDepth + + ] = workDir ; <nl> # if ENABLED ( SDCARD_SORT_ALPHA ) <nl> presort ( ) ; <nl> # endif <nl> void CardReader : : chdir ( const char * relpath ) { <nl> } <nl> <nl> void CardReader : : updir ( ) { <nl> - if ( workDirDepth > 0 ) { <nl> - workDir = workDirParents [ - - workDirDepth ] ; <nl> + if ( workDirDepth > 0 ) { / / At least 1 dir has been saved <nl> + workDir = - - workDirDepth ? workDirParents [ workDirDepth ] : root ; / / Use parent , or root if none <nl> # if ENABLED ( SDCARD_SORT_ALPHA ) <nl> presort ( ) ; <nl> # endif <nl> mmm a / Marlin / src / sd / cardreader . h <nl> ppp b / Marlin / src / sd / cardreader . h <nl> class CardReader { <nl> / / device is available soon after a reset . <nl> <nl> void checkautostart ( bool x ) ; <nl> - void openFile ( char * name , bool read , bool push_current = false ) ; <nl> + void openFile ( char * name , const bool read , const bool subcall = false ) ; <nl> void openLogFile ( char * name ) ; <nl> void removeFile ( const char * const name ) ; <nl> void closefile ( bool store_location = false ) ; <nl>
Fix M32 P subroutine handling
MarlinFirmware/Marlin
e0d367f1fb12c57eca03df7994eeee629c0fea50
2017-11-15T06:44:21Z
mmm a / csharp / tests / Facebook . Yoga / YGAbsolutePositionTest . cs <nl> ppp b / csharp / tests / Facebook . Yoga / YGAbsolutePositionTest . cs <nl> public void Test_absolute_layout_in_wrap_reverse_row_container ( ) <nl> Assert . AreEqual ( 20f , root_child0 . LayoutHeight ) ; <nl> } <nl> <nl> + [ Test ] <nl> + public void Test_absolute_layout_in_wrap_reverse_column_container_flex_end ( ) <nl> + { <nl> + YogaConfig config = new YogaConfig ( ) ; <nl> + <nl> + YogaNode root = new YogaNode ( config ) ; <nl> + root . Wrap = YogaWrap . WrapReverse ; <nl> + root . Width = 100 ; <nl> + root . Height = 100 ; <nl> + <nl> + YogaNode root_child0 = new YogaNode ( config ) ; <nl> + root_child0 . AlignSelf = YogaAlign . FlexEnd ; <nl> + root_child0 . PositionType = YogaPositionType . Absolute ; <nl> + root_child0 . Width = 20 ; <nl> + root_child0 . Height = 20 ; <nl> + root . Insert ( 0 , root_child0 ) ; <nl> + root . StyleDirection = YogaDirection . LTR ; <nl> + root . CalculateLayout ( ) ; <nl> + <nl> + Assert . AreEqual ( 0f , root . LayoutX ) ; <nl> + Assert . AreEqual ( 0f , root . LayoutY ) ; <nl> + Assert . AreEqual ( 100f , root . LayoutWidth ) ; <nl> + Assert . AreEqual ( 100f , root . LayoutHeight ) ; <nl> + <nl> + Assert . AreEqual ( 0f , root_child0 . LayoutX ) ; <nl> + Assert . AreEqual ( 0f , root_child0 . LayoutY ) ; <nl> + Assert . AreEqual ( 20f , root_child0 . LayoutWidth ) ; <nl> + Assert . AreEqual ( 20f , root_child0 . LayoutHeight ) ; <nl> + <nl> + root . StyleDirection = YogaDirection . RTL ; <nl> + root . CalculateLayout ( ) ; <nl> + <nl> + Assert . AreEqual ( 0f , root . LayoutX ) ; <nl> + Assert . AreEqual ( 0f , root . LayoutY ) ; <nl> + Assert . AreEqual ( 100f , root . LayoutWidth ) ; <nl> + Assert . AreEqual ( 100f , root . LayoutHeight ) ; <nl> + <nl> + Assert . AreEqual ( 80f , root_child0 . LayoutX ) ; <nl> + Assert . AreEqual ( 0f , root_child0 . LayoutY ) ; <nl> + Assert . AreEqual ( 20f , root_child0 . LayoutWidth ) ; <nl> + Assert . AreEqual ( 20f , root_child0 . LayoutHeight ) ; <nl> + } <nl> + <nl> + [ Test ] <nl> + public void Test_absolute_layout_in_wrap_reverse_row_container_flex_end ( ) <nl> + { <nl> + YogaConfig config = new YogaConfig ( ) ; <nl> + <nl> + YogaNode root = new YogaNode ( config ) ; <nl> + root . FlexDirection = YogaFlexDirection . Row ; <nl> + root . Wrap = YogaWrap . WrapReverse ; <nl> + root . Width = 100 ; <nl> + root . Height = 100 ; <nl> + <nl> + YogaNode root_child0 = new YogaNode ( config ) ; <nl> + root_child0 . AlignSelf = YogaAlign . FlexEnd ; <nl> + root_child0 . PositionType = YogaPositionType . Absolute ; <nl> + root_child0 . Width = 20 ; <nl> + root_child0 . Height = 20 ; <nl> + root . Insert ( 0 , root_child0 ) ; <nl> + root . StyleDirection = YogaDirection . LTR ; <nl> + root . CalculateLayout ( ) ; <nl> + <nl> + Assert . AreEqual ( 0f , root . LayoutX ) ; <nl> + Assert . AreEqual ( 0f , root . LayoutY ) ; <nl> + Assert . AreEqual ( 100f , root . LayoutWidth ) ; <nl> + Assert . AreEqual ( 100f , root . LayoutHeight ) ; <nl> + <nl> + Assert . AreEqual ( 0f , root_child0 . LayoutX ) ; <nl> + Assert . AreEqual ( 0f , root_child0 . LayoutY ) ; <nl> + Assert . AreEqual ( 20f , root_child0 . LayoutWidth ) ; <nl> + Assert . AreEqual ( 20f , root_child0 . LayoutHeight ) ; <nl> + <nl> + root . StyleDirection = YogaDirection . RTL ; <nl> + root . CalculateLayout ( ) ; <nl> + <nl> + Assert . AreEqual ( 0f , root . LayoutX ) ; <nl> + Assert . AreEqual ( 0f , root . LayoutY ) ; <nl> + Assert . AreEqual ( 100f , root . LayoutWidth ) ; <nl> + Assert . AreEqual ( 100f , root . LayoutHeight ) ; <nl> + <nl> + Assert . AreEqual ( 80f , root_child0 . LayoutX ) ; <nl> + Assert . AreEqual ( 0f , root_child0 . LayoutY ) ; <nl> + Assert . AreEqual ( 20f , root_child0 . LayoutWidth ) ; <nl> + Assert . AreEqual ( 20f , root_child0 . LayoutHeight ) ; <nl> + } <nl> + <nl> } <nl> } <nl> mmm a / gentest / fixtures / YGAbsolutePositionTest . html <nl> ppp b / gentest / fixtures / YGAbsolutePositionTest . html <nl> <nl> < div style = " width : 20px ; height : 20px ; position : absolute ; " > < / div > <nl> < / div > <nl> <nl> + < div id = " absolute_layout_in_wrap_reverse_column_container_flex_end " style = " flex - direction : column ; width : 100px ; height : 100px ; flex - wrap : wrap - reverse ; " > <nl> + < div style = " width : 20px ; height : 20px ; position : absolute ; align - self : flex - end ; " > < / div > <nl> + < / div > <nl> + <nl> + < div id = " absolute_layout_in_wrap_reverse_row_container_flex_end " style = " flex - direction : row ; width : 100px ; height : 100px ; flex - wrap : wrap - reverse ; " > <nl> + < div style = " width : 20px ; height : 20px ; position : absolute ; align - self : flex - end ; " > < / div > <nl> + < / div > <nl> + <nl> mmm a / java / tests / com / facebook / yoga / YGAbsolutePositionTest . java <nl> ppp b / java / tests / com / facebook / yoga / YGAbsolutePositionTest . java <nl> public void test_absolute_layout_in_wrap_reverse_row_container ( ) { <nl> assertEquals ( 20f , root_child0 . getLayoutHeight ( ) , 0 . 0f ) ; <nl> } <nl> <nl> + @ Test <nl> + public void test_absolute_layout_in_wrap_reverse_column_container_flex_end ( ) { <nl> + YogaConfig config = new YogaConfig ( ) ; <nl> + <nl> + final YogaNode root = new YogaNode ( config ) ; <nl> + root . setWrap ( YogaWrap . WRAP_REVERSE ) ; <nl> + root . setWidth ( 100f ) ; <nl> + root . setHeight ( 100f ) ; <nl> + <nl> + final YogaNode root_child0 = new YogaNode ( config ) ; <nl> + root_child0 . setAlignSelf ( YogaAlign . FLEX_END ) ; <nl> + root_child0 . setPositionType ( YogaPositionType . ABSOLUTE ) ; <nl> + root_child0 . setWidth ( 20f ) ; <nl> + root_child0 . setHeight ( 20f ) ; <nl> + root . addChildAt ( root_child0 , 0 ) ; <nl> + root . setDirection ( YogaDirection . LTR ) ; <nl> + root . calculateLayout ( YogaConstants . UNDEFINED , YogaConstants . UNDEFINED ) ; <nl> + <nl> + assertEquals ( 0f , root . getLayoutX ( ) , 0 . 0f ) ; <nl> + assertEquals ( 0f , root . getLayoutY ( ) , 0 . 0f ) ; <nl> + assertEquals ( 100f , root . getLayoutWidth ( ) , 0 . 0f ) ; <nl> + assertEquals ( 100f , root . getLayoutHeight ( ) , 0 . 0f ) ; <nl> + <nl> + assertEquals ( 0f , root_child0 . getLayoutX ( ) , 0 . 0f ) ; <nl> + assertEquals ( 0f , root_child0 . getLayoutY ( ) , 0 . 0f ) ; <nl> + assertEquals ( 20f , root_child0 . getLayoutWidth ( ) , 0 . 0f ) ; <nl> + assertEquals ( 20f , root_child0 . getLayoutHeight ( ) , 0 . 0f ) ; <nl> + <nl> + root . setDirection ( YogaDirection . RTL ) ; <nl> + root . calculateLayout ( YogaConstants . UNDEFINED , YogaConstants . UNDEFINED ) ; <nl> + <nl> + assertEquals ( 0f , root . getLayoutX ( ) , 0 . 0f ) ; <nl> + assertEquals ( 0f , root . getLayoutY ( ) , 0 . 0f ) ; <nl> + assertEquals ( 100f , root . getLayoutWidth ( ) , 0 . 0f ) ; <nl> + assertEquals ( 100f , root . getLayoutHeight ( ) , 0 . 0f ) ; <nl> + <nl> + assertEquals ( 80f , root_child0 . getLayoutX ( ) , 0 . 0f ) ; <nl> + assertEquals ( 0f , root_child0 . getLayoutY ( ) , 0 . 0f ) ; <nl> + assertEquals ( 20f , root_child0 . getLayoutWidth ( ) , 0 . 0f ) ; <nl> + assertEquals ( 20f , root_child0 . getLayoutHeight ( ) , 0 . 0f ) ; <nl> + } <nl> + <nl> + @ Test <nl> + public void test_absolute_layout_in_wrap_reverse_row_container_flex_end ( ) { <nl> + YogaConfig config = new YogaConfig ( ) ; <nl> + <nl> + final YogaNode root = new YogaNode ( config ) ; <nl> + root . setFlexDirection ( YogaFlexDirection . ROW ) ; <nl> + root . setWrap ( YogaWrap . WRAP_REVERSE ) ; <nl> + root . setWidth ( 100f ) ; <nl> + root . setHeight ( 100f ) ; <nl> + <nl> + final YogaNode root_child0 = new YogaNode ( config ) ; <nl> + root_child0 . setAlignSelf ( YogaAlign . FLEX_END ) ; <nl> + root_child0 . setPositionType ( YogaPositionType . ABSOLUTE ) ; <nl> + root_child0 . setWidth ( 20f ) ; <nl> + root_child0 . setHeight ( 20f ) ; <nl> + root . addChildAt ( root_child0 , 0 ) ; <nl> + root . setDirection ( YogaDirection . LTR ) ; <nl> + root . calculateLayout ( YogaConstants . UNDEFINED , YogaConstants . UNDEFINED ) ; <nl> + <nl> + assertEquals ( 0f , root . getLayoutX ( ) , 0 . 0f ) ; <nl> + assertEquals ( 0f , root . getLayoutY ( ) , 0 . 0f ) ; <nl> + assertEquals ( 100f , root . getLayoutWidth ( ) , 0 . 0f ) ; <nl> + assertEquals ( 100f , root . getLayoutHeight ( ) , 0 . 0f ) ; <nl> + <nl> + assertEquals ( 0f , root_child0 . getLayoutX ( ) , 0 . 0f ) ; <nl> + assertEquals ( 0f , root_child0 . getLayoutY ( ) , 0 . 0f ) ; <nl> + assertEquals ( 20f , root_child0 . getLayoutWidth ( ) , 0 . 0f ) ; <nl> + assertEquals ( 20f , root_child0 . getLayoutHeight ( ) , 0 . 0f ) ; <nl> + <nl> + root . setDirection ( YogaDirection . RTL ) ; <nl> + root . calculateLayout ( YogaConstants . UNDEFINED , YogaConstants . UNDEFINED ) ; <nl> + <nl> + assertEquals ( 0f , root . getLayoutX ( ) , 0 . 0f ) ; <nl> + assertEquals ( 0f , root . getLayoutY ( ) , 0 . 0f ) ; <nl> + assertEquals ( 100f , root . getLayoutWidth ( ) , 0 . 0f ) ; <nl> + assertEquals ( 100f , root . getLayoutHeight ( ) , 0 . 0f ) ; <nl> + <nl> + assertEquals ( 80f , root_child0 . getLayoutX ( ) , 0 . 0f ) ; <nl> + assertEquals ( 0f , root_child0 . getLayoutY ( ) , 0 . 0f ) ; <nl> + assertEquals ( 20f , root_child0 . getLayoutWidth ( ) , 0 . 0f ) ; <nl> + assertEquals ( 20f , root_child0 . getLayoutHeight ( ) , 0 . 0f ) ; <nl> + } <nl> + <nl> } <nl> mmm a / javascript / tests / Facebook . Yoga / YGAbsolutePositionTest . js <nl> ppp b / javascript / tests / Facebook . Yoga / YGAbsolutePositionTest . js <nl> it ( " absolute_layout_in_wrap_reverse_row_container " , function ( ) { <nl> config . free ( ) ; <nl> } <nl> } ) ; <nl> + it ( " absolute_layout_in_wrap_reverse_column_container_flex_end " , function ( ) { <nl> + var config = Yoga . Config . create ( ) ; <nl> + <nl> + try { <nl> + var root = Yoga . Node . create ( config ) ; <nl> + root . setFlexWrap ( Yoga . WRAP_WRAP_REVERSE ) ; <nl> + root . setWidth ( 100 ) ; <nl> + root . setHeight ( 100 ) ; <nl> + <nl> + var root_child0 = Yoga . Node . create ( config ) ; <nl> + root_child0 . setAlignSelf ( Yoga . ALIGN_FLEX_END ) ; <nl> + root_child0 . setPositionType ( Yoga . POSITION_TYPE_ABSOLUTE ) ; <nl> + root_child0 . setWidth ( 20 ) ; <nl> + root_child0 . setHeight ( 20 ) ; <nl> + root . insertChild ( root_child0 , 0 ) ; <nl> + root . calculateLayout ( Yoga . UNDEFINED , Yoga . UNDEFINED , Yoga . DIRECTION_LTR ) ; <nl> + <nl> + console . assert ( 0 = = = root . getComputedLeft ( ) , " 0 = = = root . getComputedLeft ( ) ( " + root . getComputedLeft ( ) + " ) " ) ; <nl> + console . assert ( 0 = = = root . getComputedTop ( ) , " 0 = = = root . getComputedTop ( ) ( " + root . getComputedTop ( ) + " ) " ) ; <nl> + console . assert ( 100 = = = root . getComputedWidth ( ) , " 100 = = = root . getComputedWidth ( ) ( " + root . getComputedWidth ( ) + " ) " ) ; <nl> + console . assert ( 100 = = = root . getComputedHeight ( ) , " 100 = = = root . getComputedHeight ( ) ( " + root . getComputedHeight ( ) + " ) " ) ; <nl> + <nl> + console . assert ( 0 = = = root_child0 . getComputedLeft ( ) , " 0 = = = root_child0 . getComputedLeft ( ) ( " + root_child0 . getComputedLeft ( ) + " ) " ) ; <nl> + console . assert ( 0 = = = root_child0 . getComputedTop ( ) , " 0 = = = root_child0 . getComputedTop ( ) ( " + root_child0 . getComputedTop ( ) + " ) " ) ; <nl> + console . assert ( 20 = = = root_child0 . getComputedWidth ( ) , " 20 = = = root_child0 . getComputedWidth ( ) ( " + root_child0 . getComputedWidth ( ) + " ) " ) ; <nl> + console . assert ( 20 = = = root_child0 . getComputedHeight ( ) , " 20 = = = root_child0 . getComputedHeight ( ) ( " + root_child0 . getComputedHeight ( ) + " ) " ) ; <nl> + <nl> + root . calculateLayout ( Yoga . UNDEFINED , Yoga . UNDEFINED , Yoga . DIRECTION_RTL ) ; <nl> + <nl> + console . assert ( 0 = = = root . getComputedLeft ( ) , " 0 = = = root . getComputedLeft ( ) ( " + root . getComputedLeft ( ) + " ) " ) ; <nl> + console . assert ( 0 = = = root . getComputedTop ( ) , " 0 = = = root . getComputedTop ( ) ( " + root . getComputedTop ( ) + " ) " ) ; <nl> + console . assert ( 100 = = = root . getComputedWidth ( ) , " 100 = = = root . getComputedWidth ( ) ( " + root . getComputedWidth ( ) + " ) " ) ; <nl> + console . assert ( 100 = = = root . getComputedHeight ( ) , " 100 = = = root . getComputedHeight ( ) ( " + root . getComputedHeight ( ) + " ) " ) ; <nl> + <nl> + console . assert ( 80 = = = root_child0 . getComputedLeft ( ) , " 80 = = = root_child0 . getComputedLeft ( ) ( " + root_child0 . getComputedLeft ( ) + " ) " ) ; <nl> + console . assert ( 0 = = = root_child0 . getComputedTop ( ) , " 0 = = = root_child0 . getComputedTop ( ) ( " + root_child0 . getComputedTop ( ) + " ) " ) ; <nl> + console . assert ( 20 = = = root_child0 . getComputedWidth ( ) , " 20 = = = root_child0 . getComputedWidth ( ) ( " + root_child0 . getComputedWidth ( ) + " ) " ) ; <nl> + console . assert ( 20 = = = root_child0 . getComputedHeight ( ) , " 20 = = = root_child0 . getComputedHeight ( ) ( " + root_child0 . getComputedHeight ( ) + " ) " ) ; <nl> + } finally { <nl> + if ( typeof root ! = = " undefined " ) { <nl> + root . freeRecursive ( ) ; <nl> + } <nl> + <nl> + config . free ( ) ; <nl> + } <nl> + } ) ; <nl> + it ( " absolute_layout_in_wrap_reverse_row_container_flex_end " , function ( ) { <nl> + var config = Yoga . Config . create ( ) ; <nl> + <nl> + try { <nl> + var root = Yoga . Node . create ( config ) ; <nl> + root . setFlexDirection ( Yoga . FLEX_DIRECTION_ROW ) ; <nl> + root . setFlexWrap ( Yoga . WRAP_WRAP_REVERSE ) ; <nl> + root . setWidth ( 100 ) ; <nl> + root . setHeight ( 100 ) ; <nl> + <nl> + var root_child0 = Yoga . Node . create ( config ) ; <nl> + root_child0 . setAlignSelf ( Yoga . ALIGN_FLEX_END ) ; <nl> + root_child0 . setPositionType ( Yoga . POSITION_TYPE_ABSOLUTE ) ; <nl> + root_child0 . setWidth ( 20 ) ; <nl> + root_child0 . setHeight ( 20 ) ; <nl> + root . insertChild ( root_child0 , 0 ) ; <nl> + root . calculateLayout ( Yoga . UNDEFINED , Yoga . UNDEFINED , Yoga . DIRECTION_LTR ) ; <nl> + <nl> + console . assert ( 0 = = = root . getComputedLeft ( ) , " 0 = = = root . getComputedLeft ( ) ( " + root . getComputedLeft ( ) + " ) " ) ; <nl> + console . assert ( 0 = = = root . getComputedTop ( ) , " 0 = = = root . getComputedTop ( ) ( " + root . getComputedTop ( ) + " ) " ) ; <nl> + console . assert ( 100 = = = root . getComputedWidth ( ) , " 100 = = = root . getComputedWidth ( ) ( " + root . getComputedWidth ( ) + " ) " ) ; <nl> + console . assert ( 100 = = = root . getComputedHeight ( ) , " 100 = = = root . getComputedHeight ( ) ( " + root . getComputedHeight ( ) + " ) " ) ; <nl> + <nl> + console . assert ( 0 = = = root_child0 . getComputedLeft ( ) , " 0 = = = root_child0 . getComputedLeft ( ) ( " + root_child0 . getComputedLeft ( ) + " ) " ) ; <nl> + console . assert ( 0 = = = root_child0 . getComputedTop ( ) , " 0 = = = root_child0 . getComputedTop ( ) ( " + root_child0 . getComputedTop ( ) + " ) " ) ; <nl> + console . assert ( 20 = = = root_child0 . getComputedWidth ( ) , " 20 = = = root_child0 . getComputedWidth ( ) ( " + root_child0 . getComputedWidth ( ) + " ) " ) ; <nl> + console . assert ( 20 = = = root_child0 . getComputedHeight ( ) , " 20 = = = root_child0 . getComputedHeight ( ) ( " + root_child0 . getComputedHeight ( ) + " ) " ) ; <nl> + <nl> + root . calculateLayout ( Yoga . UNDEFINED , Yoga . UNDEFINED , Yoga . DIRECTION_RTL ) ; <nl> + <nl> + console . assert ( 0 = = = root . getComputedLeft ( ) , " 0 = = = root . getComputedLeft ( ) ( " + root . getComputedLeft ( ) + " ) " ) ; <nl> + console . assert ( 0 = = = root . getComputedTop ( ) , " 0 = = = root . getComputedTop ( ) ( " + root . getComputedTop ( ) + " ) " ) ; <nl> + console . assert ( 100 = = = root . getComputedWidth ( ) , " 100 = = = root . getComputedWidth ( ) ( " + root . getComputedWidth ( ) + " ) " ) ; <nl> + console . assert ( 100 = = = root . getComputedHeight ( ) , " 100 = = = root . getComputedHeight ( ) ( " + root . getComputedHeight ( ) + " ) " ) ; <nl> + <nl> + console . assert ( 80 = = = root_child0 . getComputedLeft ( ) , " 80 = = = root_child0 . getComputedLeft ( ) ( " + root_child0 . getComputedLeft ( ) + " ) " ) ; <nl> + console . assert ( 0 = = = root_child0 . getComputedTop ( ) , " 0 = = = root_child0 . getComputedTop ( ) ( " + root_child0 . getComputedTop ( ) + " ) " ) ; <nl> + console . assert ( 20 = = = root_child0 . getComputedWidth ( ) , " 20 = = = root_child0 . getComputedWidth ( ) ( " + root_child0 . getComputedWidth ( ) + " ) " ) ; <nl> + console . assert ( 20 = = = root_child0 . getComputedHeight ( ) , " 20 = = = root_child0 . getComputedHeight ( ) ( " + root_child0 . getComputedHeight ( ) + " ) " ) ; <nl> + } finally { <nl> + if ( typeof root ! = = " undefined " ) { <nl> + root . freeRecursive ( ) ; <nl> + } <nl> + <nl> + config . free ( ) ; <nl> + } <nl> + } ) ; <nl> mmm a / tests / YGAbsolutePositionTest . cpp <nl> ppp b / tests / YGAbsolutePositionTest . cpp <nl> TEST ( YogaTest , absolute_layout_in_wrap_reverse_row_container ) { <nl> <nl> YGConfigFree ( config ) ; <nl> } <nl> + <nl> + TEST ( YogaTest , absolute_layout_in_wrap_reverse_column_container_flex_end ) { <nl> + const YGConfigRef config = YGConfigNew ( ) ; <nl> + <nl> + const YGNodeRef root = YGNodeNewWithConfig ( config ) ; <nl> + YGNodeStyleSetFlexWrap ( root , YGWrapWrapReverse ) ; <nl> + YGNodeStyleSetWidth ( root , 100 ) ; <nl> + YGNodeStyleSetHeight ( root , 100 ) ; <nl> + <nl> + const YGNodeRef root_child0 = YGNodeNewWithConfig ( config ) ; <nl> + YGNodeStyleSetAlignSelf ( root_child0 , YGAlignFlexEnd ) ; <nl> + YGNodeStyleSetPositionType ( root_child0 , YGPositionTypeAbsolute ) ; <nl> + YGNodeStyleSetWidth ( root_child0 , 20 ) ; <nl> + YGNodeStyleSetHeight ( root_child0 , 20 ) ; <nl> + YGNodeInsertChild ( root , root_child0 , 0 ) ; <nl> + YGNodeCalculateLayout ( root , YGUndefined , YGUndefined , YGDirectionLTR ) ; <nl> + <nl> + ASSERT_FLOAT_EQ ( 0 , YGNodeLayoutGetLeft ( root ) ) ; <nl> + ASSERT_FLOAT_EQ ( 0 , YGNodeLayoutGetTop ( root ) ) ; <nl> + ASSERT_FLOAT_EQ ( 100 , YGNodeLayoutGetWidth ( root ) ) ; <nl> + ASSERT_FLOAT_EQ ( 100 , YGNodeLayoutGetHeight ( root ) ) ; <nl> + <nl> + ASSERT_FLOAT_EQ ( 0 , YGNodeLayoutGetLeft ( root_child0 ) ) ; <nl> + ASSERT_FLOAT_EQ ( 0 , YGNodeLayoutGetTop ( root_child0 ) ) ; <nl> + ASSERT_FLOAT_EQ ( 20 , YGNodeLayoutGetWidth ( root_child0 ) ) ; <nl> + ASSERT_FLOAT_EQ ( 20 , YGNodeLayoutGetHeight ( root_child0 ) ) ; <nl> + <nl> + YGNodeCalculateLayout ( root , YGUndefined , YGUndefined , YGDirectionRTL ) ; <nl> + <nl> + ASSERT_FLOAT_EQ ( 0 , YGNodeLayoutGetLeft ( root ) ) ; <nl> + ASSERT_FLOAT_EQ ( 0 , YGNodeLayoutGetTop ( root ) ) ; <nl> + ASSERT_FLOAT_EQ ( 100 , YGNodeLayoutGetWidth ( root ) ) ; <nl> + ASSERT_FLOAT_EQ ( 100 , YGNodeLayoutGetHeight ( root ) ) ; <nl> + <nl> + ASSERT_FLOAT_EQ ( 80 , YGNodeLayoutGetLeft ( root_child0 ) ) ; <nl> + ASSERT_FLOAT_EQ ( 0 , YGNodeLayoutGetTop ( root_child0 ) ) ; <nl> + ASSERT_FLOAT_EQ ( 20 , YGNodeLayoutGetWidth ( root_child0 ) ) ; <nl> + ASSERT_FLOAT_EQ ( 20 , YGNodeLayoutGetHeight ( root_child0 ) ) ; <nl> + <nl> + YGNodeFreeRecursive ( root ) ; <nl> + <nl> + YGConfigFree ( config ) ; <nl> + } <nl> + <nl> + TEST ( YogaTest , absolute_layout_in_wrap_reverse_row_container_flex_end ) { <nl> + const YGConfigRef config = YGConfigNew ( ) ; <nl> + <nl> + const YGNodeRef root = YGNodeNewWithConfig ( config ) ; <nl> + YGNodeStyleSetFlexDirection ( root , YGFlexDirectionRow ) ; <nl> + YGNodeStyleSetFlexWrap ( root , YGWrapWrapReverse ) ; <nl> + YGNodeStyleSetWidth ( root , 100 ) ; <nl> + YGNodeStyleSetHeight ( root , 100 ) ; <nl> + <nl> + const YGNodeRef root_child0 = YGNodeNewWithConfig ( config ) ; <nl> + YGNodeStyleSetAlignSelf ( root_child0 , YGAlignFlexEnd ) ; <nl> + YGNodeStyleSetPositionType ( root_child0 , YGPositionTypeAbsolute ) ; <nl> + YGNodeStyleSetWidth ( root_child0 , 20 ) ; <nl> + YGNodeStyleSetHeight ( root_child0 , 20 ) ; <nl> + YGNodeInsertChild ( root , root_child0 , 0 ) ; <nl> + YGNodeCalculateLayout ( root , YGUndefined , YGUndefined , YGDirectionLTR ) ; <nl> + <nl> + ASSERT_FLOAT_EQ ( 0 , YGNodeLayoutGetLeft ( root ) ) ; <nl> + ASSERT_FLOAT_EQ ( 0 , YGNodeLayoutGetTop ( root ) ) ; <nl> + ASSERT_FLOAT_EQ ( 100 , YGNodeLayoutGetWidth ( root ) ) ; <nl> + ASSERT_FLOAT_EQ ( 100 , YGNodeLayoutGetHeight ( root ) ) ; <nl> + <nl> + ASSERT_FLOAT_EQ ( 0 , YGNodeLayoutGetLeft ( root_child0 ) ) ; <nl> + ASSERT_FLOAT_EQ ( 0 , YGNodeLayoutGetTop ( root_child0 ) ) ; <nl> + ASSERT_FLOAT_EQ ( 20 , YGNodeLayoutGetWidth ( root_child0 ) ) ; <nl> + ASSERT_FLOAT_EQ ( 20 , YGNodeLayoutGetHeight ( root_child0 ) ) ; <nl> + <nl> + YGNodeCalculateLayout ( root , YGUndefined , YGUndefined , YGDirectionRTL ) ; <nl> + <nl> + ASSERT_FLOAT_EQ ( 0 , YGNodeLayoutGetLeft ( root ) ) ; <nl> + ASSERT_FLOAT_EQ ( 0 , YGNodeLayoutGetTop ( root ) ) ; <nl> + ASSERT_FLOAT_EQ ( 100 , YGNodeLayoutGetWidth ( root ) ) ; <nl> + ASSERT_FLOAT_EQ ( 100 , YGNodeLayoutGetHeight ( root ) ) ; <nl> + <nl> + ASSERT_FLOAT_EQ ( 80 , YGNodeLayoutGetLeft ( root_child0 ) ) ; <nl> + ASSERT_FLOAT_EQ ( 0 , YGNodeLayoutGetTop ( root_child0 ) ) ; <nl> + ASSERT_FLOAT_EQ ( 20 , YGNodeLayoutGetWidth ( root_child0 ) ) ; <nl> + ASSERT_FLOAT_EQ ( 20 , YGNodeLayoutGetHeight ( root_child0 ) ) ; <nl> + <nl> + YGNodeFreeRecursive ( root ) ; <nl> + <nl> + YGConfigFree ( config ) ; <nl> + } <nl> mmm a / yoga / Yoga . c <nl> ppp b / yoga / Yoga . c <nl> static void YGNodeAbsoluteLayoutChild ( const YGNodeRef node , <nl> child - > layout . measuredDimensions [ dim [ crossAxis ] ] ) / <nl> 2 . 0f ; <nl> } else if ( ! YGNodeIsLeadingPosDefined ( child , crossAxis ) & & <nl> - ( YGNodeAlignItem ( node , child ) = = YGAlignFlexEnd | | node - > style . flexWrap = = YGWrapWrapReverse ) ) { <nl> + ( ( YGNodeAlignItem ( node , child ) = = YGAlignFlexEnd ) ^ ( node - > style . flexWrap = = YGWrapWrapReverse ) ) ) { <nl> child - > layout . position [ leading [ crossAxis ] ] = ( node - > layout . measuredDimensions [ dim [ crossAxis ] ] - <nl> child - > layout . measuredDimensions [ dim [ crossAxis ] ] ) ; <nl> } <nl>
Fix absolute position if wrap - reverse and align - items : flex - end
facebook/yoga
a20bde8444474e7a34352a78073de23c26e08fc5
2017-06-01T12:41:25Z
mmm a / modules / csg / csg . cpp <nl> ppp b / modules / csg / csg . cpp <nl> bool CSGBrushOperation : : MeshMerge : : _bvh_inside ( FaceBVH * facebvhptr , int p_max_de <nl> / / Check if faces are co - planar . <nl> if ( ( current_normal - face_normal ) . length_squared ( ) < CMP_EPSILON2 & & <nl> is_point_in_triangle ( face_center , current_points ) ) { <nl> - / / Only add an intersection if checking a B face . <nl> - if ( face . from_b ) { <nl> + / / Only add an intersection if not a B face . <nl> + if ( ! face . from_b ) { <nl> _add_distance ( intersectionsA , intersectionsB , current_face . from_b , 0 ) ; <nl> } <nl> } else if ( ray_intersects_triangle ( face_center , face_normal , current_points , CMP_EPSILON , intersection_point ) ) { <nl>
Mark the first shape as inside , not the second shape , when CSG shapes are
godotengine/godot
5b1e6e35be91b2dc8f4135cea4b415c89b5b10d6
2020-08-12T07:01:02Z
mmm a / extensions / Particle3D / PU / CCPUScriptTranslator . cpp <nl> ppp b / extensions / Particle3D / PU / CCPUScriptTranslator . cpp <nl> <nl> # include " extensions / Particle3D / PU / CCPUTranslateManager . h " <nl> <nl> NS_CC_BEGIN <nl> + <nl> + const std : : string token [ 1000 ] = <nl> + { <nl> + / / Generic <nl> + " group_mask " , <nl> + " acceleration " , <nl> + " max_increment " , <nl> + " min_increment " , <nl> + " number_of_iterations " , <nl> + " colour_change " , <nl> + " initial_colour " , <nl> + " random_initial_colour " , <nl> + " use_vertex_colours " , <nl> + " use_own_rotation " , <nl> + " max_deviation " , <nl> + " time_step " , <nl> + " box_width " , <nl> + " box_height " , <nl> + " box_depth " , <nl> + " velocity " , <nl> + " speed " , <nl> + " rotation_speed " , <nl> + " rotation " , <nl> + " rotation_axis " , <nl> + " normal " , <nl> + " step " , <nl> + " number_of_segments " , <nl> + " max_elements " , <nl> + " update_interval " , <nl> + " distance_threshold " , <nl> + " material " , <nl> + " mesh_name " , <nl> + " radius " , <nl> + " enabled " , <nl> + " position " , <nl> + " keep_local " , <nl> + " less_than " , <nl> + " greater_than " , <nl> + " equals " , <nl> + " visual_particle " , <nl> + " emitter_particle " , <nl> + " affector_particle " , <nl> + " technique_particle " , <nl> + " system_particle " , <nl> + " point " , <nl> + " vertex " , <nl> + " increase " , <nl> + " alias " , <nl> + " use_alias " , <nl> + " since_start_system " , <nl> + <nl> + / / Particle System <nl> + " system " , <nl> + " iteration_interval " , <nl> + " nonvisible_update_timeout " , <nl> + " fixed_timeout " , <nl> + " lod_distances " , <nl> + " main_camera_name " , <nl> + " smooth_lod " , <nl> + " fast_forward " , <nl> + " scale " , <nl> + " scale_velocity " , <nl> + " scale_time " , <nl> + " tight_bounding_box " , <nl> + " category " , <nl> + <nl> + / / Particle Technique <nl> + " technique " , <nl> + " visual_particle_quota " , <nl> + " emitted_emitter_quota " , <nl> + " emitted_affector_quota " , <nl> + " emitted_technique_quota " , <nl> + " emitted_system_quota " , <nl> + " lod_index " , <nl> + " default_particle_width " , <nl> + " default_particle_height " , <nl> + " default_particle_depth " , <nl> + " spatial_hashing_cell_dimension " , <nl> + " spatial_hashing_cell_overlap " , <nl> + " spatial_hashtable_size " , <nl> + " spatial_hashing_update_interval " , <nl> + " max_velocity " , <nl> + <nl> + / / Particle Renderer <nl> + " renderer " , <nl> + " render_queue_group " , <nl> + " sorting " , <nl> + " texture_coords_define " , <nl> + " texture_coords_rows " , <nl> + " texture_coords_set " , <nl> + " texture_coords_columns " , <nl> + " use_soft_particles " , <nl> + " soft_particles_contrast_power " , <nl> + " soft_particles_scale " , <nl> + " soft_particles_delta " , <nl> + <nl> + / / Particle Emitter <nl> + " emitter " , <nl> + " direction " , <nl> + " orientation " , <nl> + " range_start_orientation " , <nl> + " range_end_orientation " , <nl> + " start_orientation_range " , <nl> + " end_orientation_range " , <nl> + " duration " , <nl> + " repeat_delay " , <nl> + " emits " , <nl> + " angle " , <nl> + " emission_rate " , <nl> + " time_to_live " , <nl> + " mass " , <nl> + " start_texture_coords " , <nl> + " end_texture_coords " , <nl> + " start_texture_coords_range " , <nl> + " end_texture_coords_range " , <nl> + " texture_coords " , <nl> + " start_colour_range " , <nl> + " end_colour_range " , <nl> + " colour " , <nl> + " all_particle_dimensions " , <nl> + " particle_width " , <nl> + " particle_height " , <nl> + " particle_depth " , <nl> + " auto_direction " , <nl> + " force_emission " , <nl> + <nl> + / / Particle Affector <nl> + " affector " , <nl> + " mass_affector " , <nl> + " exclude_emitter " , <nl> + " affect_specialisation " , <nl> + " special_default " , <nl> + " special_ttl_increase " , <nl> + " special_ttl_decrease " , <nl> + <nl> + / / Particle Observer <nl> + " observer " , <nl> + " observe_particle_type " , <nl> + " observe_interval " , <nl> + " observe_until_event " , <nl> + <nl> + / / Particle Event Handler <nl> + " handler " , <nl> + <nl> + / / Particle Behaviour <nl> + " behaviour " , <nl> + <nl> + / / Extern <nl> + " extern " , <nl> + " attachable_distance_threshold " , <nl> + <nl> + / / Dynamic Attribute <nl> + " control_point " , <nl> + " min " , <nl> + " max " , <nl> + " oscillate_frequency " , <nl> + " oscillate_phase " , <nl> + " oscillate_base " , <nl> + " oscillate_amplitude " , <nl> + " oscillate_type " , <nl> + " dyn_oscillate " , <nl> + " dyn_random " , <nl> + " dyn_curved_linear " , <nl> + " dyn_curved_spline " , <nl> + " sine " , <nl> + " square " , <nl> + <nl> + / / CameraDependency ( unused ) <nl> + " camera_dependency " , <nl> + <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmm - Renderers mmmmmmmmmmmmmmmmmmmmmmmm - <nl> + / / BeamRenderer <nl> + " beam_update_interval " , <nl> + " beam_max_elements " , <nl> + " beam_deviation " , <nl> + " beam_number_segments " , <nl> + " beam_jump_segments " , <nl> + " beam_texcoord_direction " , <nl> + " beam_vertex_colours " , <nl> + " tcd_u " , <nl> + " tcd_v " , <nl> + <nl> + / / BillboardRenderer <nl> + " billboard_type " , <nl> + " billboard_origin " , <nl> + " billboard_rotation_type " , <nl> + " common_direction " , <nl> + " common_up_vector " , <nl> + " point_rendering " , <nl> + " accurate_facing " , <nl> + " oriented_common " , <nl> + " oriented_self " , <nl> + " oriented_shape " , <nl> + " perpendicular_common " , <nl> + " perpendicular_self " , <nl> + " top_left " , <nl> + " top_center " , <nl> + " top_right " , <nl> + " center_left " , <nl> + " center_right " , <nl> + " center " , <nl> + " bottom_left " , <nl> + " bottom_center " , <nl> + " bottom_right " , <nl> + " texcoord " , <nl> + <nl> + / / BoxRenderer : No properties itself <nl> + <nl> + / / EntityRenderer <nl> + " entity_renderer_mesh_name " , <nl> + " entity_orientation_type " , <nl> + " ent_oriented_self " , <nl> + " ent_oriented_self_mirrored " , <nl> + " ent_oriented_shape " , <nl> + <nl> + / / LightRenderer <nl> + " light_renderer_light_type " , <nl> + " light_renderer_queue_group " , <nl> + " light_renderer_specular " , <nl> + " light_renderer_att_range " , <nl> + " light_renderer_att_constant " , <nl> + " light_renderer_att_linear " , <nl> + " light_renderer_att_quadratic " , <nl> + " light_renderer_spot_inner " , <nl> + " light_renderer_spot_outer " , <nl> + " light_renderer_falloff " , <nl> + " light_renderer_powerscale " , <nl> + " spot " , <nl> + " flash_frequency " , <nl> + " flash_length " , <nl> + " flash_random " , <nl> + <nl> + / / RibbonTrailRenderer <nl> + " ribbontrail_vertex_colours " , <nl> + " ribbontrail_max_elements " , <nl> + " ribbontrail_length " , <nl> + " ribbontrail_width " , <nl> + " ribbontrail_random_initial_colour " , <nl> + " ribbontrail_initial_colour " , <nl> + " ribbontrail_colour_change " , <nl> + <nl> + / / SphereRenderer : No properties itself <nl> + <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmm - Emitters mmmmmmmmmmmmmmmmmmmmmmmm - <nl> + / / BoxEmitter <nl> + " box_em_width " , <nl> + " box_em_height " , <nl> + " box_em_depth " , <nl> + <nl> + / / CircleEmitter <nl> + " circle_em_radius " , <nl> + " circle_em_step " , <nl> + " circle_em_angle " , <nl> + " circle_em_random " , <nl> + " emit_random " , <nl> + " circle_em_normal " , <nl> + <nl> + / / LineEmitter <nl> + " line_em_end " , <nl> + " line_em_max_increment " , <nl> + " line_em_min_increment " , <nl> + " line_em_max_deviation " , <nl> + <nl> + / / MeshSurfaceEmitter <nl> + " mesh_surface_mesh_name " , <nl> + " mesh_surface_distribution " , <nl> + " mesh_surface_scale " , <nl> + " edge " , <nl> + " heterogeneous_1 " , <nl> + " heterogeneous_2 " , <nl> + " homogeneous " , <nl> + <nl> + / / PointEmitter : No properties itself <nl> + <nl> + / / PositionEmitter <nl> + " add_position " , <nl> + " random_position " , <nl> + <nl> + / / SlaveEmitter <nl> + " master_technique_name " , <nl> + " master_emitter_name " , <nl> + <nl> + / / SphereSurfaceEmitter <nl> + " sphere_surface_em_radius " , <nl> + <nl> + / / VertexEmitter <nl> + " vertex_em_step " , <nl> + " vertex_em_segments " , <nl> + " vertex_em_iterations " , <nl> + " vertex_em_mesh_name " , <nl> + <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmm - Affectors mmmmmmmmmmmmmmmmmmmmmmmm - <nl> + / / AlignAffector <nl> + " align_aff_resize " , <nl> + " resize " , <nl> + <nl> + / / BoxCollider <nl> + " box_collider_width " , <nl> + " box_collider_height " , <nl> + " box_collider_depth " , <nl> + <nl> + / / BaseCollider <nl> + " friction " , <nl> + " bouncyness " , <nl> + " intersection " , <nl> + " collision_friction " , <nl> + " collision_bouncyness " , <nl> + " collision_intersection " , <nl> + " collision_type " , <nl> + " bounce " , <nl> + " flow " , <nl> + " none " , <nl> + " point " , <nl> + " box " , <nl> + " inner_collision " , <nl> + <nl> + / / CollisionAvoidanceAffector <nl> + " avoidance_radius " , <nl> + <nl> + / / ColourAffector <nl> + " time_colour " , <nl> + " colour_aff_time_colour " , <nl> + " colour_operation " , <nl> + " multiply " , <nl> + " set " , <nl> + <nl> + / / FlockCenteringAffector : No properties itself <nl> + <nl> + / / BaseForceAffector <nl> + " force_vector " , <nl> + " force_application " , <nl> + " force_aff_vector " , <nl> + " force_aff_application " , <nl> + " add " , <nl> + " average " , <nl> + <nl> + / / ForceFieldAffector <nl> + " forcefield_type " , <nl> + " realtime " , <nl> + " matrix " , <nl> + " delta " , <nl> + " force " , <nl> + " octaves " , <nl> + " frequency " , <nl> + " amplitude " , <nl> + " persistence " , <nl> + " forcefield_size " , <nl> + " worldsize " , <nl> + " ignore_negative_x " , <nl> + " ignore_negative_y " , <nl> + " ignore_negative_z " , <nl> + " movement " , <nl> + " movement_frequency " , <nl> + <nl> + / / GeometryRotator <nl> + " geom_rot_use_own_rotation " , <nl> + " geom_rot_rotation_speed " , <nl> + " geom_rot_axis " , <nl> + <nl> + / / GravityAffector <nl> + " gravity " , <nl> + <nl> + / / InterParticleCollider <nl> + " adjustment " , <nl> + " collision_response " , <nl> + " ip_adjustment " , <nl> + " ip_collision_response " , <nl> + " average_velocity " , <nl> + " angle_based_velocity " , <nl> + <nl> + / / JetAffector <nl> + " jet_aff_accel " , <nl> + <nl> + / / LineAffector <nl> + " end " , <nl> + " drift " , <nl> + " line_aff_max_deviation " , <nl> + " line_aff_time_step " , <nl> + " line_aff_end " , <nl> + " line_aff_drift " , <nl> + <nl> + / / LinearForceAffector : No properties itself <nl> + <nl> + / / ParticleFollower <nl> + " follower_max_distance " , <nl> + " follower_min_distance " , <nl> + " max_distance " , <nl> + " min_distance " , <nl> + <nl> + / / PathFollower <nl> + " path_follower_point " , <nl> + <nl> + / / PlaneCollider <nl> + " plane_collider_normal " , <nl> + <nl> + / / Randomiser <nl> + " rand_aff_max_deviation_x " , <nl> + " rand_aff_max_deviation_y " , <nl> + " rand_aff_max_deviation_z " , <nl> + " max_deviation_x " , <nl> + " max_deviation_y " , <nl> + " max_deviation_z " , <nl> + " rand_aff_time_step " , <nl> + " rand_aff_direction " , <nl> + " use_direction " , <nl> + <nl> + / / ScaleAffector <nl> + " xyz_scale " , <nl> + " x_scale " , <nl> + " y_scale " , <nl> + " z_scale " , <nl> + <nl> + / / ScaleVelocityAffector <nl> + " velocity_scale " , <nl> + " stop_at_flip " , <nl> + <nl> + / / SineForceAffector <nl> + " sinef_aff_frequency_min " , <nl> + " sinef_aff_frequency_max " , <nl> + " min_frequency " , <nl> + " max_frequency " , <nl> + <nl> + / / SphereCollider <nl> + " sphere_collider_radius " , <nl> + <nl> + / / TextureAnimator <nl> + " time_step_animation " , <nl> + " texture_coords_start " , <nl> + " texture_coords_end " , <nl> + " start_texture_coords_range " , <nl> + " end_texture_coords_range " , <nl> + " texture_animation_type " , <nl> + " texture_start_random " , <nl> + " loop " , <nl> + " up_down " , <nl> + " random " , <nl> + <nl> + / / TextureRotator <nl> + " tex_rot_use_own_rotation " , <nl> + " tex_rot_speed " , <nl> + " tex_rot_rotation " , <nl> + <nl> + / / VelocityMatchingAffector <nl> + " velocity_matching_radius " , <nl> + <nl> + / / VortexAffector <nl> + " vortex_aff_vector " , <nl> + " vortex_aff_speed " , <nl> + <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmm - Observers mmmmmmmmmmmmmmmmmmmmmmmm - <nl> + / / OnClearObserver : No properties itself <nl> + <nl> + / / OnCollisionObserver : No properties itself <nl> + <nl> + / / OnCountObserver <nl> + " count_threshold " , <nl> + <nl> + / / OnEmissionObserver : No properties itself <nl> + <nl> + / / OnEventFlagObserver <nl> + " event_flag " , <nl> + <nl> + / / OnExpireObserver : No properties itself <nl> + <nl> + / / OnPositionObserver <nl> + " position_x " , <nl> + " position_y " , <nl> + " position_z " , <nl> + <nl> + / / OnQuotaObserver : No properties itself <nl> + <nl> + / / OnRandomObserver <nl> + " random_threshold " , <nl> + <nl> + / / OnTimeObserver <nl> + " on_time " , <nl> + <nl> + / / OnVelocityObserver <nl> + " velocity_threshold " , <nl> + <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmm - Event Handlers mmmmmmmmmmmmmmmmmmmmmmmm - <nl> + / / DoAffectorEventHandler <nl> + " force_affector " , <nl> + " pre_post " , <nl> + <nl> + / / DoEnableComponentEventHandler <nl> + " enable_component " , <nl> + " emitter_component " , <nl> + " affector_component " , <nl> + " technique_component " , <nl> + " observer_component " , <nl> + <nl> + / / DoExpireEventHandler : No properties itself <nl> + <nl> + / / DoFreezeEventHandler : No properties itself <nl> + <nl> + / / DoPlacementParticleEventHandler <nl> + " force_emitter " , <nl> + " number_of_particles " , <nl> + " inherit_position " , <nl> + " inherit_direction " , <nl> + " inherit_orientation " , <nl> + " inherit_time_to_live " , <nl> + " inherit_mass " , <nl> + " inherit_texture_coord " , <nl> + " inherit_colour " , <nl> + " inherit_width " , <nl> + " inherit_height " , <nl> + " inherit_depth " , <nl> + <nl> + / / DoScaleEventHandler <nl> + " scale_fraction " , <nl> + " scale_type " , <nl> + " st_time_to_live " , <nl> + " st_velocity " , <nl> + <nl> + / / DoStopSystemEventHandler : No properties itself <nl> + <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmm - Behaviours mmmmmmmmmmmmmmmmmmmmmmmm - <nl> + / / SlaveBehaviour : No properties itself <nl> + <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmm - Externs mmmmmmmmmmmmmmmmmmmmmmmm - <nl> + / / BoxColliderExtern : Defined in BoxCollider <nl> + <nl> + / / GravityExtern : Defined in GravityAffector <nl> + <nl> + / / PhysXActorExtern <nl> + " physx_shape " , <nl> + " physx_actor_group " , <nl> + " physx_shape_group " , <nl> + " physx_group_mask " , <nl> + " physx_angular_velocity " , <nl> + " physx_angular_damping " , <nl> + " physx_material_index " , <nl> + " shape " , <nl> + " actor_group " , <nl> + " shape_group " , <nl> + " angular_velocity " , <nl> + " angular_damping " , <nl> + " material_index " , <nl> + " Box " , <nl> + " Sphere " , <nl> + " Capsule " , <nl> + <nl> + / / PhysXFluidExtern <nl> + " rest_particles_per_meter " , <nl> + " rest_density " , <nl> + " kernel_radius_multiplier " , <nl> + " motion_limit_multiplier " , <nl> + " collision_distance_multiplier " , <nl> + " packet_size_multiplier " , <nl> + " stiffness " , <nl> + " viscosity " , <nl> + " surface_tension " , <nl> + " damping " , <nl> + " external_acceleration " , <nl> + " restitution_for_static_shapes " , <nl> + " dynamic_friction_for_static_shapes " , <nl> + " static_friction_for_static_shapes " , <nl> + " attraction_for_static_shapes " , <nl> + " restitution_for_dynamic_shapes " , <nl> + " dynamic_friction_for_dynamic_shapes " , <nl> + " static_friction_for_dynamic_shapes " , <nl> + " attraction_for_dynamic_shapes " , <nl> + " collision_response_coefficient " , <nl> + " collision_group " , <nl> + " simulation_method " , <nl> + " collision_method " , <nl> + " flags " , <nl> + " visualization " , <nl> + " disable_gravity " , <nl> + " collision_twoway " , <nl> + " fluid_enabled " , <nl> + " hardware " , <nl> + " priority_mode " , <nl> + " project_to_plane " , <nl> + " strict_cooking_format " , <nl> + " intercollision " , <nl> + " no_intercollision " , <nl> + " mix_intercollision " , <nl> + " static " , <nl> + " dynamic " , <nl> + <nl> + / / SceneDecoratorExtern <nl> + " scene_mesh_name " , <nl> + " scene_material_name " , <nl> + " scene_node_scale " , <nl> + " scene_node_position " , <nl> + <nl> + / / SphereColliderExtern : Defined in SphereCollider <nl> + <nl> + / / VortexExtern : Defined in VortexAffector <nl> + } ; <nl> + <nl> PUScriptTranslator : : PUScriptTranslator ( void ) <nl> { <nl> } <nl> mmm a / extensions / Particle3D / PU / CCPUScriptTranslator . h <nl> ppp b / extensions / Particle3D / PU / CCPUScriptTranslator . h <nl> enum eDefineStaticToken <nl> TOKEN_SCENE_POSITION <nl> } ; <nl> <nl> - / / Static tokens : Note , that the order must be the same as the enum <nl> - static const std : : string token [ 1000 ] = <nl> - { <nl> - / / Generic <nl> - " group_mask " , <nl> - " acceleration " , <nl> - " max_increment " , <nl> - " min_increment " , <nl> - " number_of_iterations " , <nl> - " colour_change " , <nl> - " initial_colour " , <nl> - " random_initial_colour " , <nl> - " use_vertex_colours " , <nl> - " use_own_rotation " , <nl> - " max_deviation " , <nl> - " time_step " , <nl> - " box_width " , <nl> - " box_height " , <nl> - " box_depth " , <nl> - " velocity " , <nl> - " speed " , <nl> - " rotation_speed " , <nl> - " rotation " , <nl> - " rotation_axis " , <nl> - " normal " , <nl> - " step " , <nl> - " number_of_segments " , <nl> - " max_elements " , <nl> - " update_interval " , <nl> - " distance_threshold " , <nl> - " material " , <nl> - " mesh_name " , <nl> - " radius " , <nl> - " enabled " , <nl> - " position " , <nl> - " keep_local " , <nl> - " less_than " , <nl> - " greater_than " , <nl> - " equals " , <nl> - " visual_particle " , <nl> - " emitter_particle " , <nl> - " affector_particle " , <nl> - " technique_particle " , <nl> - " system_particle " , <nl> - " point " , <nl> - " vertex " , <nl> - " increase " , <nl> - " alias " , <nl> - " use_alias " , <nl> - " since_start_system " , <nl> - <nl> - / / Particle System <nl> - " system " , <nl> - " iteration_interval " , <nl> - " nonvisible_update_timeout " , <nl> - " fixed_timeout " , <nl> - " lod_distances " , <nl> - " main_camera_name " , <nl> - " smooth_lod " , <nl> - " fast_forward " , <nl> - " scale " , <nl> - " scale_velocity " , <nl> - " scale_time " , <nl> - " tight_bounding_box " , <nl> - " category " , <nl> - <nl> - / / Particle Technique <nl> - " technique " , <nl> - " visual_particle_quota " , <nl> - " emitted_emitter_quota " , <nl> - " emitted_affector_quota " , <nl> - " emitted_technique_quota " , <nl> - " emitted_system_quota " , <nl> - " lod_index " , <nl> - " default_particle_width " , <nl> - " default_particle_height " , <nl> - " default_particle_depth " , <nl> - " spatial_hashing_cell_dimension " , <nl> - " spatial_hashing_cell_overlap " , <nl> - " spatial_hashtable_size " , <nl> - " spatial_hashing_update_interval " , <nl> - " max_velocity " , <nl> - <nl> - / / Particle Renderer <nl> - " renderer " , <nl> - " render_queue_group " , <nl> - " sorting " , <nl> - " texture_coords_define " , <nl> - " texture_coords_rows " , <nl> - " texture_coords_set " , <nl> - " texture_coords_columns " , <nl> - " use_soft_particles " , <nl> - " soft_particles_contrast_power " , <nl> - " soft_particles_scale " , <nl> - " soft_particles_delta " , <nl> - <nl> - / / Particle Emitter <nl> - " emitter " , <nl> - " direction " , <nl> - " orientation " , <nl> - " range_start_orientation " , <nl> - " range_end_orientation " , <nl> - " start_orientation_range " , <nl> - " end_orientation_range " , <nl> - " duration " , <nl> - " repeat_delay " , <nl> - " emits " , <nl> - " angle " , <nl> - " emission_rate " , <nl> - " time_to_live " , <nl> - " mass " , <nl> - " start_texture_coords " , <nl> - " end_texture_coords " , <nl> - " start_texture_coords_range " , <nl> - " end_texture_coords_range " , <nl> - " texture_coords " , <nl> - " start_colour_range " , <nl> - " end_colour_range " , <nl> - " colour " , <nl> - " all_particle_dimensions " , <nl> - " particle_width " , <nl> - " particle_height " , <nl> - " particle_depth " , <nl> - " auto_direction " , <nl> - " force_emission " , <nl> - <nl> - / / Particle Affector <nl> - " affector " , <nl> - " mass_affector " , <nl> - " exclude_emitter " , <nl> - " affect_specialisation " , <nl> - " special_default " , <nl> - " special_ttl_increase " , <nl> - " special_ttl_decrease " , <nl> - <nl> - / / Particle Observer <nl> - " observer " , <nl> - " observe_particle_type " , <nl> - " observe_interval " , <nl> - " observe_until_event " , <nl> - <nl> - / / Particle Event Handler <nl> - " handler " , <nl> - <nl> - / / Particle Behaviour <nl> - " behaviour " , <nl> - <nl> - / / Extern <nl> - " extern " , <nl> - " attachable_distance_threshold " , <nl> - <nl> - / / Dynamic Attribute <nl> - " control_point " , <nl> - " min " , <nl> - " max " , <nl> - " oscillate_frequency " , <nl> - " oscillate_phase " , <nl> - " oscillate_base " , <nl> - " oscillate_amplitude " , <nl> - " oscillate_type " , <nl> - " dyn_oscillate " , <nl> - " dyn_random " , <nl> - " dyn_curved_linear " , <nl> - " dyn_curved_spline " , <nl> - " sine " , <nl> - " square " , <nl> - <nl> - / / CameraDependency ( unused ) <nl> - " camera_dependency " , <nl> - <nl> - / / mmmmmmmmmmmmmmmmmmmmmmmm - Renderers mmmmmmmmmmmmmmmmmmmmmmmm - <nl> - / / BeamRenderer <nl> - " beam_update_interval " , <nl> - " beam_max_elements " , <nl> - " beam_deviation " , <nl> - " beam_number_segments " , <nl> - " beam_jump_segments " , <nl> - " beam_texcoord_direction " , <nl> - " beam_vertex_colours " , <nl> - " tcd_u " , <nl> - " tcd_v " , <nl> - <nl> - / / BillboardRenderer <nl> - " billboard_type " , <nl> - " billboard_origin " , <nl> - " billboard_rotation_type " , <nl> - " common_direction " , <nl> - " common_up_vector " , <nl> - " point_rendering " , <nl> - " accurate_facing " , <nl> - " oriented_common " , <nl> - " oriented_self " , <nl> - " oriented_shape " , <nl> - " perpendicular_common " , <nl> - " perpendicular_self " , <nl> - " top_left " , <nl> - " top_center " , <nl> - " top_right " , <nl> - " center_left " , <nl> - " center_right " , <nl> - " center " , <nl> - " bottom_left " , <nl> - " bottom_center " , <nl> - " bottom_right " , <nl> - " texcoord " , <nl> - <nl> - / / BoxRenderer : No properties itself <nl> - <nl> - / / EntityRenderer <nl> - " entity_renderer_mesh_name " , <nl> - " entity_orientation_type " , <nl> - " ent_oriented_self " , <nl> - " ent_oriented_self_mirrored " , <nl> - " ent_oriented_shape " , <nl> - <nl> - / / LightRenderer <nl> - " light_renderer_light_type " , <nl> - " light_renderer_queue_group " , <nl> - " light_renderer_specular " , <nl> - " light_renderer_att_range " , <nl> - " light_renderer_att_constant " , <nl> - " light_renderer_att_linear " , <nl> - " light_renderer_att_quadratic " , <nl> - " light_renderer_spot_inner " , <nl> - " light_renderer_spot_outer " , <nl> - " light_renderer_falloff " , <nl> - " light_renderer_powerscale " , <nl> - " spot " , <nl> - " flash_frequency " , <nl> - " flash_length " , <nl> - " flash_random " , <nl> - <nl> - / / RibbonTrailRenderer <nl> - " ribbontrail_vertex_colours " , <nl> - " ribbontrail_max_elements " , <nl> - " ribbontrail_length " , <nl> - " ribbontrail_width " , <nl> - " ribbontrail_random_initial_colour " , <nl> - " ribbontrail_initial_colour " , <nl> - " ribbontrail_colour_change " , <nl> - <nl> - / / SphereRenderer : No properties itself <nl> - <nl> - / / mmmmmmmmmmmmmmmmmmmmmmmm - Emitters mmmmmmmmmmmmmmmmmmmmmmmm - <nl> - / / BoxEmitter <nl> - " box_em_width " , <nl> - " box_em_height " , <nl> - " box_em_depth " , <nl> - <nl> - / / CircleEmitter <nl> - " circle_em_radius " , <nl> - " circle_em_step " , <nl> - " circle_em_angle " , <nl> - " circle_em_random " , <nl> - " emit_random " , <nl> - " circle_em_normal " , <nl> - <nl> - / / LineEmitter <nl> - " line_em_end " , <nl> - " line_em_max_increment " , <nl> - " line_em_min_increment " , <nl> - " line_em_max_deviation " , <nl> - <nl> - / / MeshSurfaceEmitter <nl> - " mesh_surface_mesh_name " , <nl> - " mesh_surface_distribution " , <nl> - " mesh_surface_scale " , <nl> - " edge " , <nl> - " heterogeneous_1 " , <nl> - " heterogeneous_2 " , <nl> - " homogeneous " , <nl> - <nl> - / / PointEmitter : No properties itself <nl> - <nl> - / / PositionEmitter <nl> - " add_position " , <nl> - " random_position " , <nl> - <nl> - / / SlaveEmitter <nl> - " master_technique_name " , <nl> - " master_emitter_name " , <nl> - <nl> - / / SphereSurfaceEmitter <nl> - " sphere_surface_em_radius " , <nl> - <nl> - / / VertexEmitter <nl> - " vertex_em_step " , <nl> - " vertex_em_segments " , <nl> - " vertex_em_iterations " , <nl> - " vertex_em_mesh_name " , <nl> - <nl> - / / mmmmmmmmmmmmmmmmmmmmmmmm - Affectors mmmmmmmmmmmmmmmmmmmmmmmm - <nl> - / / AlignAffector <nl> - " align_aff_resize " , <nl> - " resize " , <nl> - <nl> - / / BoxCollider <nl> - " box_collider_width " , <nl> - " box_collider_height " , <nl> - " box_collider_depth " , <nl> - <nl> - / / BaseCollider <nl> - " friction " , <nl> - " bouncyness " , <nl> - " intersection " , <nl> - " collision_friction " , <nl> - " collision_bouncyness " , <nl> - " collision_intersection " , <nl> - " collision_type " , <nl> - " bounce " , <nl> - " flow " , <nl> - " none " , <nl> - " point " , <nl> - " box " , <nl> - " inner_collision " , <nl> - <nl> - / / CollisionAvoidanceAffector <nl> - " avoidance_radius " , <nl> - <nl> - / / ColourAffector <nl> - " time_colour " , <nl> - " colour_aff_time_colour " , <nl> - " colour_operation " , <nl> - " multiply " , <nl> - " set " , <nl> - <nl> - / / FlockCenteringAffector : No properties itself <nl> - <nl> - / / BaseForceAffector <nl> - " force_vector " , <nl> - " force_application " , <nl> - " force_aff_vector " , <nl> - " force_aff_application " , <nl> - " add " , <nl> - " average " , <nl> - <nl> - / / ForceFieldAffector <nl> - " forcefield_type " , <nl> - " realtime " , <nl> - " matrix " , <nl> - " delta " , <nl> - " force " , <nl> - " octaves " , <nl> - " frequency " , <nl> - " amplitude " , <nl> - " persistence " , <nl> - " forcefield_size " , <nl> - " worldsize " , <nl> - " ignore_negative_x " , <nl> - " ignore_negative_y " , <nl> - " ignore_negative_z " , <nl> - " movement " , <nl> - " movement_frequency " , <nl> - <nl> - / / GeometryRotator <nl> - " geom_rot_use_own_rotation " , <nl> - " geom_rot_rotation_speed " , <nl> - " geom_rot_axis " , <nl> - <nl> - / / GravityAffector <nl> - " gravity " , <nl> - <nl> - / / InterParticleCollider <nl> - " adjustment " , <nl> - " collision_response " , <nl> - " ip_adjustment " , <nl> - " ip_collision_response " , <nl> - " average_velocity " , <nl> - " angle_based_velocity " , <nl> - <nl> - / / JetAffector <nl> - " jet_aff_accel " , <nl> - <nl> - / / LineAffector <nl> - " end " , <nl> - " drift " , <nl> - " line_aff_max_deviation " , <nl> - " line_aff_time_step " , <nl> - " line_aff_end " , <nl> - " line_aff_drift " , <nl> - <nl> - / / LinearForceAffector : No properties itself <nl> - <nl> - / / ParticleFollower <nl> - " follower_max_distance " , <nl> - " follower_min_distance " , <nl> - " max_distance " , <nl> - " min_distance " , <nl> - <nl> - / / PathFollower <nl> - " path_follower_point " , <nl> - <nl> - / / PlaneCollider <nl> - " plane_collider_normal " , <nl> - <nl> - / / Randomiser <nl> - " rand_aff_max_deviation_x " , <nl> - " rand_aff_max_deviation_y " , <nl> - " rand_aff_max_deviation_z " , <nl> - " max_deviation_x " , <nl> - " max_deviation_y " , <nl> - " max_deviation_z " , <nl> - " rand_aff_time_step " , <nl> - " rand_aff_direction " , <nl> - " use_direction " , <nl> - <nl> - / / ScaleAffector <nl> - " xyz_scale " , <nl> - " x_scale " , <nl> - " y_scale " , <nl> - " z_scale " , <nl> - <nl> - / / ScaleVelocityAffector <nl> - " velocity_scale " , <nl> - " stop_at_flip " , <nl> - <nl> - / / SineForceAffector <nl> - " sinef_aff_frequency_min " , <nl> - " sinef_aff_frequency_max " , <nl> - " min_frequency " , <nl> - " max_frequency " , <nl> - <nl> - / / SphereCollider <nl> - " sphere_collider_radius " , <nl> - <nl> - / / TextureAnimator <nl> - " time_step_animation " , <nl> - " texture_coords_start " , <nl> - " texture_coords_end " , <nl> - " start_texture_coords_range " , <nl> - " end_texture_coords_range " , <nl> - " texture_animation_type " , <nl> - " texture_start_random " , <nl> - " loop " , <nl> - " up_down " , <nl> - " random " , <nl> - <nl> - / / TextureRotator <nl> - " tex_rot_use_own_rotation " , <nl> - " tex_rot_speed " , <nl> - " tex_rot_rotation " , <nl> - <nl> - / / VelocityMatchingAffector <nl> - " velocity_matching_radius " , <nl> - <nl> - / / VortexAffector <nl> - " vortex_aff_vector " , <nl> - " vortex_aff_speed " , <nl> - <nl> - / / mmmmmmmmmmmmmmmmmmmmmmmm - Observers mmmmmmmmmmmmmmmmmmmmmmmm - <nl> - / / OnClearObserver : No properties itself <nl> - <nl> - / / OnCollisionObserver : No properties itself <nl> - <nl> - / / OnCountObserver <nl> - " count_threshold " , <nl> - <nl> - / / OnEmissionObserver : No properties itself <nl> - <nl> - / / OnEventFlagObserver <nl> - " event_flag " , <nl> - <nl> - / / OnExpireObserver : No properties itself <nl> - <nl> - / / OnPositionObserver <nl> - " position_x " , <nl> - " position_y " , <nl> - " position_z " , <nl> - <nl> - / / OnQuotaObserver : No properties itself <nl> - <nl> - / / OnRandomObserver <nl> - " random_threshold " , <nl> - <nl> - / / OnTimeObserver <nl> - " on_time " , <nl> - <nl> - / / OnVelocityObserver <nl> - " velocity_threshold " , <nl> - <nl> - / / mmmmmmmmmmmmmmmmmmmmmmmm - Event Handlers mmmmmmmmmmmmmmmmmmmmmmmm - <nl> - / / DoAffectorEventHandler <nl> - " force_affector " , <nl> - " pre_post " , <nl> - <nl> - / / DoEnableComponentEventHandler <nl> - " enable_component " , <nl> - " emitter_component " , <nl> - " affector_component " , <nl> - " technique_component " , <nl> - " observer_component " , <nl> - <nl> - / / DoExpireEventHandler : No properties itself <nl> - <nl> - / / DoFreezeEventHandler : No properties itself <nl> - <nl> - / / DoPlacementParticleEventHandler <nl> - " force_emitter " , <nl> - " number_of_particles " , <nl> - " inherit_position " , <nl> - " inherit_direction " , <nl> - " inherit_orientation " , <nl> - " inherit_time_to_live " , <nl> - " inherit_mass " , <nl> - " inherit_texture_coord " , <nl> - " inherit_colour " , <nl> - " inherit_width " , <nl> - " inherit_height " , <nl> - " inherit_depth " , <nl> - <nl> - / / DoScaleEventHandler <nl> - " scale_fraction " , <nl> - " scale_type " , <nl> - " st_time_to_live " , <nl> - " st_velocity " , <nl> - <nl> - / / DoStopSystemEventHandler : No properties itself <nl> - <nl> - / / mmmmmmmmmmmmmmmmmmmmmmmm - Behaviours mmmmmmmmmmmmmmmmmmmmmmmm - <nl> - / / SlaveBehaviour : No properties itself <nl> - <nl> - / / mmmmmmmmmmmmmmmmmmmmmmmm - Externs mmmmmmmmmmmmmmmmmmmmmmmm - <nl> - / / BoxColliderExtern : Defined in BoxCollider <nl> - <nl> - / / GravityExtern : Defined in GravityAffector <nl> - <nl> - / / PhysXActorExtern <nl> - " physx_shape " , <nl> - " physx_actor_group " , <nl> - " physx_shape_group " , <nl> - " physx_group_mask " , <nl> - " physx_angular_velocity " , <nl> - " physx_angular_damping " , <nl> - " physx_material_index " , <nl> - " shape " , <nl> - " actor_group " , <nl> - " shape_group " , <nl> - " angular_velocity " , <nl> - " angular_damping " , <nl> - " material_index " , <nl> - " Box " , <nl> - " Sphere " , <nl> - " Capsule " , <nl> - <nl> - / / PhysXFluidExtern <nl> - " rest_particles_per_meter " , <nl> - " rest_density " , <nl> - " kernel_radius_multiplier " , <nl> - " motion_limit_multiplier " , <nl> - " collision_distance_multiplier " , <nl> - " packet_size_multiplier " , <nl> - " stiffness " , <nl> - " viscosity " , <nl> - " surface_tension " , <nl> - " damping " , <nl> - " external_acceleration " , <nl> - " restitution_for_static_shapes " , <nl> - " dynamic_friction_for_static_shapes " , <nl> - " static_friction_for_static_shapes " , <nl> - " attraction_for_static_shapes " , <nl> - " restitution_for_dynamic_shapes " , <nl> - " dynamic_friction_for_dynamic_shapes " , <nl> - " static_friction_for_dynamic_shapes " , <nl> - " attraction_for_dynamic_shapes " , <nl> - " collision_response_coefficient " , <nl> - " collision_group " , <nl> - " simulation_method " , <nl> - " collision_method " , <nl> - " flags " , <nl> - " visualization " , <nl> - " disable_gravity " , <nl> - " collision_twoway " , <nl> - " fluid_enabled " , <nl> - " hardware " , <nl> - " priority_mode " , <nl> - " project_to_plane " , <nl> - " strict_cooking_format " , <nl> - " intercollision " , <nl> - " no_intercollision " , <nl> - " mix_intercollision " , <nl> - " static " , <nl> - " dynamic " , <nl> - <nl> - / / SceneDecoratorExtern <nl> - " scene_mesh_name " , <nl> - " scene_material_name " , <nl> - " scene_node_scale " , <nl> - " scene_node_position " , <nl> - <nl> - / / SphereColliderExtern : Defined in SphereCollider <nl> - <nl> - / / VortexExtern : Defined in VortexAffector <nl> - } ; <nl> - <nl> + / / tokens : Note , that the order must be the same as the enum <nl> + extern const std : : string token [ ] ; <nl> <nl> / * * script translator * / <nl> class PUScriptTranslator <nl>
fix static token array in headfile ( ) ( )
cocos2d/cocos2d-x
4bb958fe29cd60d9dc075863ee05bb757bd183ef
2019-04-10T05:38:13Z
mmm a / lib / Sema / TypeCheckType . cpp <nl> ppp b / lib / Sema / TypeCheckType . cpp <nl> class UnsupportedProtocolVisitor <nl> : public TypeReprVisitor < UnsupportedProtocolVisitor > , public ASTWalker <nl> { <nl> TypeChecker & TC ; <nl> - SmallPtrSet < ProtocolDecl * , 4 > Diagnosed ; <nl> - <nl> + bool recurseIntoSubstatements ; <nl> + bool hitTopStmt ; <nl> + <nl> public : <nl> - UnsupportedProtocolVisitor ( TypeChecker & tc ) : TC ( tc ) { } <nl> + UnsupportedProtocolVisitor ( TypeChecker & tc ) : TC ( tc ) { <nl> + recurseIntoSubstatements = true ; <nl> + hitTopStmt = false ; <nl> + } <nl> <nl> - SmallPtrSet < ProtocolDecl * , 4 > & getDiagnosedProtocols ( ) { return Diagnosed ; } <nl> + void setRecurseIntoSubstatements ( bool recurse ) { <nl> + recurseIntoSubstatements = recurse ; <nl> + } <nl> <nl> bool walkToTypeReprPre ( TypeRepr * T ) { <nl> visit ( T ) ; <nl> return true ; <nl> } <nl> + <nl> + std : : pair < bool , Stmt * > walkToStmtPre ( Stmt * S ) { <nl> + if ( recurseIntoSubstatements ) { <nl> + return { true , S } ; <nl> + } else if ( hitTopStmt ) { <nl> + return { false , S } ; <nl> + } else { <nl> + hitTopStmt = true ; <nl> + return { true , S } ; <nl> + } <nl> + } <nl> <nl> void visitIdentTypeRepr ( IdentTypeRepr * T ) { <nl> + if ( T - > isInvalid ( ) ) <nl> + return ; <nl> + <nl> auto comp = T - > getComponentRange ( ) . back ( ) ; <nl> if ( auto proto = dyn_cast_or_null < ProtocolDecl > ( comp - > getBoundDecl ( ) ) ) { <nl> if ( ! proto - > existentialTypeSupported ( & TC ) ) { <nl> TC . diagnose ( comp - > getIdLoc ( ) , diag : : unsupported_existential_type , <nl> proto - > getName ( ) ) ; <nl> - Diagnosed . insert ( proto ) ; <nl> + T - > setInvalid ( ) ; <nl> } <nl> - <nl> - return ; <nl> + } else if ( auto alias = dyn_cast_or_null < TypeAliasDecl > ( comp - > getBoundDecl ( ) ) ) { <nl> + if ( ! alias - > hasUnderlyingType ( ) ) <nl> + return ; <nl> + auto type = alias - > getUnderlyingType ( ) ; <nl> + type . findIf ( [ & ] ( Type type ) - > bool { <nl> + if ( T - > isInvalid ( ) ) <nl> + return false ; <nl> + SmallVector < ProtocolDecl * , 2 > protocols ; <nl> + if ( type - > isExistentialType ( protocols ) ) { <nl> + for ( auto * proto : protocols ) { <nl> + if ( proto - > existentialTypeSupported ( & TC ) ) <nl> + continue ; <nl> + <nl> + TC . diagnose ( comp - > getIdLoc ( ) , diag : : unsupported_existential_type , <nl> + proto - > getName ( ) ) ; <nl> + T - > setInvalid ( ) ; <nl> + } <nl> + } <nl> + return false ; <nl> + } ) ; <nl> } <nl> } <nl> } ; <nl> void TypeChecker : : checkUnsupportedProtocolType ( Decl * decl ) { <nl> <nl> UnsupportedProtocolVisitor visitor ( * this ) ; <nl> decl - > walk ( visitor ) ; <nl> - if ( auto valueDecl = dyn_cast < ValueDecl > ( decl ) ) { <nl> - if ( auto type = valueDecl - > getType ( ) ) { <nl> - type . findIf ( [ & ] ( Type type ) - > bool { <nl> - SmallVector < ProtocolDecl * , 2 > protocols ; <nl> - if ( type - > isExistentialType ( protocols ) ) { <nl> - for ( auto * proto : protocols ) { <nl> - if ( proto - > existentialTypeSupported ( this ) ) <nl> - continue ; <nl> - <nl> - if ( visitor . getDiagnosedProtocols ( ) . insert ( proto ) . second ) { <nl> - diagnose ( valueDecl - > getLoc ( ) , <nl> - diag : : unsupported_existential_type , <nl> - proto - > getName ( ) ) ; <nl> - } <nl> - } <nl> - } <nl> - <nl> - return false ; <nl> - } ) ; <nl> - } <nl> - } <nl> } <nl> <nl> void TypeChecker : : checkUnsupportedProtocolType ( Stmt * stmt ) { <nl> void TypeChecker : : checkUnsupportedProtocolType ( Stmt * stmt ) { <nl> return ; <nl> <nl> UnsupportedProtocolVisitor visitor ( * this ) ; <nl> + <nl> + / / This method will already be called for all individual statements , so don ' t repeat <nl> + / / that checking by walking into any statement inside this one . <nl> + visitor . setRecurseIntoSubstatements ( false ) ; <nl> stmt - > walk ( visitor ) ; <nl> } <nl> mmm a / test / decl / protocol / recursive_requirement . swift <nl> ppp b / test / decl / protocol / recursive_requirement . swift <nl> protocol AsExistentialB { <nl> } <nl> <nl> protocol AsExistentialAssocTypeA { <nl> - var delegate : AsExistentialAssocTypeB ? { get } / / expected - error 3 { { protocol ' AsExistentialAssocTypeB ' can only be used as a generic constraint because it has Self or associated type requirements } } <nl> + var delegate : AsExistentialAssocTypeB ? { get } / / expected - error { { protocol ' AsExistentialAssocTypeB ' can only be used as a generic constraint because it has Self or associated type requirements } } <nl> } <nl> protocol AsExistentialAssocTypeB { <nl> func aMethod ( object : AsExistentialAssocTypeA ) <nl> protocol AsExistentialAssocTypeAgainA { <nl> associatedtype Bar <nl> } <nl> protocol AsExistentialAssocTypeAgainB { <nl> - func aMethod ( object : AsExistentialAssocTypeAgainA ) / / expected - error * { { protocol ' AsExistentialAssocTypeAgainA ' can only be used as a generic constraint because it has Self or associated type requirements } } <nl> + func aMethod ( object : AsExistentialAssocTypeAgainA ) / / expected - error { { protocol ' AsExistentialAssocTypeAgainA ' can only be used as a generic constraint because it has Self or associated type requirements } } <nl> } <nl> <nl> mmm a / test / type / protocol_types . swift <nl> ppp b / test / type / protocol_types . swift <nl> protocol HasAssoc { <nl> } <nl> <nl> func testHasAssoc ( x : Any ) { <nl> - if let p = x as ? HasAssoc { / / expected - error 2 { { protocol ' HasAssoc ' can only be used as a generic constraint } } <nl> + if let p = x as ? HasAssoc { / / expected - error { { protocol ' HasAssoc ' can only be used as a generic constraint } } <nl> p . foo ( ) / / don ' t crash here . <nl> } <nl> } <nl> protocol InheritsAssoc : HasAssoc { <nl> func testInheritsAssoc ( x : InheritsAssoc ) { / / expected - error { { protocol ' InheritsAssoc ' can only be used as a generic constraint } } <nl> x . silverSpoon ( ) <nl> } <nl> + <nl> + / / SR - 38 <nl> + var b : HasAssoc / / expected - error { { protocol ' HasAssoc ' can only be used as a generic constraint because it has Self or associated type requirements } } <nl> + <nl> + / / Further generic constraint error testing - typealias used inside statements <nl> + protocol P { } <nl> + typealias MoreHasAssoc = protocol < HasAssoc , P > <nl> + func testHasMoreAssoc ( x : Any ) { <nl> + if let p = x as ? MoreHasAssoc { / / expected - error { { protocol ' HasAssoc ' can only be used as a generic constraint } } <nl> + p . foo ( ) / / don ' t crash here . <nl> + } <nl> + } <nl> + <nl> + <nl>
Merge pull request from gregomni / sr - 38
apple/swift
418154e160c1cb2292330514432d32941f53cf7f
2016-01-28T07:01:09Z
new file mode 100644 <nl> index 0000000000 . . 9c2b334412 <nl> mmm / dev / null <nl> ppp b / change / react - native - windows - 2019 - 08 - 01 - 17 - 51 - 54 - developer_menu . json <nl> <nl> + { <nl> + " type " : " prerelease " , <nl> + " comment " : " addedundefined developer menu " , <nl> + " packageName " : " react - native - windows " , <nl> + " email " : " kmelmon @ microsoft . com " , <nl> + " commit " : " 93b975ab7a4e56d28adc204cdd3a03c228bf7955 " , <nl> + " date " : " 2019 - 08 - 02T00 : 51 : 54 . 509Z " <nl> + } <nl> \ No newline at end of file <nl> mmm a / packages / playground / windows / playground / HostingPane . xaml . cpp <nl> ppp b / packages / playground / windows / playground / HostingPane . xaml . cpp <nl> struct HostingPaneReactInstanceCreator : : : react : : uwp : : IReactInstanceCreator { <nl> pane - > markAsNeedsReload ( ) ; <nl> } <nl> <nl> + void persistUseWebDebugger ( bool useWebDebugger ) { <nl> + HostingPane ^ pane = m_wrPane . Resolve < HostingPane > ( ) ; <nl> + if ( pane ) <nl> + pane - > persistUseWebDebugger ( useWebDebugger ) ; <nl> + } <nl> + <nl> private : <nl> Platform : : WeakReference m_wrPane ; <nl> } ; <nl> void HostingPane : : markAsNeedsReload ( ) { <nl> m_instance = nullptr ; <nl> } <nl> <nl> + void HostingPane : : persistUseWebDebugger ( bool useWebDebugger ) { <nl> + x_UseWebDebuggerCheckBox - > IsChecked = useWebDebugger ; <nl> + } <nl> + <nl> void HostingPane : : LoadReactNative ( ) { <nl> std : : shared_ptr < react : : uwp : : IXamlRootView > rootView = m_rootView ; <nl> <nl> mmm a / packages / playground / windows / playground / HostingPane . xaml . h <nl> ppp b / packages / playground / windows / playground / HostingPane . xaml . h <nl> namespace Playground { <nl> <nl> internal : std : : shared_ptr < react : : uwp : : IReactInstance > getInstance ( ) ; <nl> void markAsNeedsReload ( ) ; <nl> + void persistUseWebDebugger ( bool useWebDebugger ) ; <nl> <nl> void InitComboBoxes ( ) ; <nl> void LoadKnownApps ( ) ; <nl> mmm a / vnext / ReactUWP / ABI / Instance_rt . cpp <nl> ppp b / vnext / ReactUWP / ABI / Instance_rt . cpp <nl> struct InstanceReactInstanceCreator : : : react : : uwp : : IReactInstanceCreator { <nl> reinterpret_cast < Instance * > ( spInstance . Get ( ) ) - > markAsNeedsReload ( ) ; <nl> } <nl> <nl> + void persistUseWebDebugger ( bool useWebDebugger ) { <nl> + Microsoft : : WRL : : ComPtr < ABI : : react : : uwp : : IInstance > spInstance ; <nl> + m_wrInstance . As ( & spInstance ) ; <nl> + reinterpret_cast < Instance * > ( spInstance . Get ( ) ) <nl> + - > persistUseWebDebugger ( useWebDebugger ) ; <nl> + } <nl> + <nl> private : <nl> Microsoft : : WRL : : WeakRef m_wrInstance ; <nl> Microsoft : : WRL : : ComPtr < ABI : : react : : uwp : : IInstance > m_instance ; <nl> void Instance : : markAsNeedsReload ( ) { <nl> m_instance = nullptr ; <nl> } <nl> <nl> + void Instance : : persistUseWebDebugger ( bool useWebDebugger ) { <nl> + m_settings . UseWebDebugger = useWebDebugger ; <nl> + } <nl> + <nl> HRESULT Instance : : Start ( ABI : : react : : uwp : : InstanceSettings settings ) { <nl> if ( m_outerInstanceCreator | | m_instance ) <nl> return E_FAIL ; <nl> mmm a / vnext / ReactUWP / ABI / Instance_rt . h <nl> ppp b / vnext / ReactUWP / ABI / Instance_rt . h <nl> class Instance <nl> <nl> std : : shared_ptr < : : react : : uwp : : IReactInstance > getInstance ( ) ; <nl> void markAsNeedsReload ( ) ; <nl> + void persistUseWebDebugger ( bool useWebDebugger ) ; <nl> <nl> private : <nl> std : : string m_jsBundleName ; <nl> mmm a / vnext / ReactUWP / Base / UwpReactInstance . cpp <nl> ppp b / vnext / ReactUWP / Base / UwpReactInstance . cpp <nl> void UwpReactInstance : : Start ( <nl> if ( m_started ) <nl> return ; <nl> <nl> + m_reactInstanceSettings = settings ; <nl> + <nl> assert ( <nl> m_uiDispatcher = = nullptr & & m_defaultNativeThread = = nullptr & & <nl> m_jsThread = = nullptr & & m_initThread = = nullptr & & <nl> mmm a / vnext / ReactUWP / Base / UwpReactInstance . h <nl> ppp b / vnext / ReactUWP / Base / UwpReactInstance . h <nl> class UwpReactInstance <nl> ExpressionAnimationStore & GetExpressionAnimationStore ( ) override { <nl> return m_expressionAnimationStore ; <nl> } <nl> + const ReactInstanceSettings & GetReactInstanceSettings ( ) const override { <nl> + return m_reactInstanceSettings ; <nl> + } <nl> std : : string GetBundleRootPath ( ) const noexcept override { <nl> return m_bundleRootPath ; <nl> } <nl> class UwpReactInstance <nl> std : : function < void ( XamlView ) > m_xamlViewCreatedTestHook ; <nl> <nl> std : : string m_bundleRootPath ; <nl> + ReactInstanceSettings m_reactInstanceSettings ; <nl> } ; <nl> <nl> } / / namespace uwp <nl> mmm a / vnext / ReactUWP / Views / KeyboardEventHandler . cpp <nl> ppp b / vnext / ReactUWP / Views / KeyboardEventHandler . cpp <nl> bool HandledKeyboardEventHandler : : ShouldMarkKeyboardHandled ( <nl> return false ; <nl> } <nl> <nl> - inline bool IsModifiedKeyPressed ( <nl> - winrt : : CoreWindow const & coreWindow , <nl> - winrt : : VirtualKey virtualKey ) { <nl> - return ( coreWindow . GetKeyState ( virtualKey ) & <nl> - winrt : : CoreVirtualKeyStates : : Down ) = = <nl> - winrt : : CoreVirtualKeyStates : : Down ; <nl> - } <nl> - <nl> - inline bool IsModifiedKeyLocked ( <nl> - winrt : : CoreWindow const & coreWindow , <nl> - winrt : : VirtualKey virtualKey ) { <nl> - return ( coreWindow . GetKeyState ( virtualKey ) & <nl> - winrt : : CoreVirtualKeyStates : : Locked ) = = <nl> - winrt : : CoreVirtualKeyStates : : Locked ; <nl> - } <nl> - <nl> template < typename T > <nl> void UpdateModifiedKeyStatusTo ( T & event ) { <nl> auto const & coreWindow = winrt : : CoreWindow : : GetForCurrentThread ( ) ; <nl> - event . altKey = IsModifiedKeyPressed ( coreWindow , winrt : : VirtualKey : : Menu ) ; <nl> - event . shiftKey = IsModifiedKeyPressed ( coreWindow , winrt : : VirtualKey : : Shift ) ; <nl> - event . metaKey = <nl> - IsModifiedKeyPressed ( coreWindow , winrt : : VirtualKey : : LeftWindows ) | | <nl> - IsModifiedKeyPressed ( coreWindow , winrt : : VirtualKey : : RightWindows ) ; <nl> - event . ctrlKey = IsModifiedKeyPressed ( coreWindow , winrt : : VirtualKey : : Control ) ; <nl> - event . capLocked = <nl> - IsModifiedKeyLocked ( coreWindow , winrt : : VirtualKey : : CapitalLock ) ; <nl> + event . altKey = <nl> + KeyboardHelper : : IsModifiedKeyPressed ( coreWindow , winrt : : VirtualKey : : Menu ) ; <nl> + event . shiftKey = KeyboardHelper : : IsModifiedKeyPressed ( <nl> + coreWindow , winrt : : VirtualKey : : Shift ) ; <nl> + event . metaKey = KeyboardHelper : : IsModifiedKeyPressed ( <nl> + coreWindow , winrt : : VirtualKey : : LeftWindows ) | | <nl> + KeyboardHelper : : IsModifiedKeyPressed ( <nl> + coreWindow , winrt : : VirtualKey : : RightWindows ) ; <nl> + event . ctrlKey = KeyboardHelper : : IsModifiedKeyPressed ( <nl> + coreWindow , winrt : : VirtualKey : : Control ) ; <nl> + event . capLocked = KeyboardHelper : : IsModifiedKeyLocked ( <nl> + coreWindow , winrt : : VirtualKey : : CapitalLock ) ; <nl> } ; <nl> <nl> void PreviewKeyboardEventHandlerOnRoot : : DispatchEventToJs ( <nl> inline winrt : : VirtualKey GetLeftOrRightModifiedKey ( <nl> winrt : : CoreWindow const & coreWindow , <nl> winrt : : VirtualKey leftKey , <nl> winrt : : VirtualKey rightKey ) { <nl> - return IsModifiedKeyPressed ( coreWindow , leftKey ) ? leftKey : rightKey ; <nl> + return KeyboardHelper : : IsModifiedKeyPressed ( coreWindow , leftKey ) ? leftKey <nl> + : rightKey ; <nl> } <nl> <nl> std : : string KeyboardHelper : : CodeFromVirtualKey ( winrt : : VirtualKey virtualKey ) { <nl> std : : string KeyboardHelper : : CodeFromVirtualKey ( winrt : : VirtualKey virtualKey ) { <nl> return GetOrUnidentified ( virtualKey , g_virtualKeyToCode ) ; <nl> } <nl> <nl> + bool KeyboardHelper : : IsModifiedKeyPressed ( <nl> + winrt : : CoreWindow const & coreWindow , <nl> + winrt : : VirtualKey virtualKey ) { <nl> + return ( coreWindow . GetKeyState ( virtualKey ) & <nl> + winrt : : CoreVirtualKeyStates : : Down ) = = <nl> + winrt : : CoreVirtualKeyStates : : Down ; <nl> + } <nl> + <nl> + bool KeyboardHelper : : IsModifiedKeyLocked ( <nl> + winrt : : CoreWindow const & coreWindow , <nl> + winrt : : VirtualKey virtualKey ) { <nl> + return ( coreWindow . GetKeyState ( virtualKey ) & <nl> + winrt : : CoreVirtualKeyStates : : Locked ) = = <nl> + winrt : : CoreVirtualKeyStates : : Locked ; <nl> + } <nl> + <nl> } / / namespace uwp <nl> } / / namespace react <nl> mmm a / vnext / ReactUWP / Views / ReactControl . cpp <nl> ppp b / vnext / ReactUWP / Views / ReactControl . cpp <nl> <nl> # include " unicode . h " <nl> <nl> # include < INativeUIManager . h > <nl> + # include < Views / KeyboardEventHandler . h > <nl> # include < Views / ShadowNodeBase . h > <nl> <nl> # include < winrt / Windows . ApplicationModel . Core . h > <nl> <nl> # include < winrt / Windows . UI . Input . h > <nl> # include < winrt / Windows . UI . Xaml . Controls . h > <nl> # include < winrt / Windows . UI . Xaml . Input . h > <nl> + # include < winrt / Windows . UI . Xaml . Markup . h > <nl> # include < winrt / Windows . UI . Xaml . Media . h > <nl> # include < winrt / Windows . UI . Xaml . h > <nl> <nl> void ReactControl : : AttachRoot ( ) noexcept { <nl> auto initialProps = m_initialProps ; <nl> m_reactInstance - > AttachMeasuredRootView ( m_pParent , std : : move ( initialProps ) ) ; <nl> m_isAttached = true ; <nl> + <nl> + # ifdef DEBUG <nl> + / / TODO : Enable this in retail builds via a new API <nl> + / / https : / / github . com / microsoft / react - native - windows / issues / 2870 <nl> + InitializeDeveloperMenu ( ) ; <nl> + # endif <nl> } <nl> <nl> void ReactControl : : DetachRoot ( ) noexcept { <nl> void ReactControl : : EnsureFocusSafeHarbor ( ) { <nl> } <nl> } <nl> <nl> + / / Set keyboard event listener for developer menu <nl> + void ReactControl : : InitializeDeveloperMenu ( ) { <nl> + auto coreWindow = winrt : : CoreWindow : : GetForCurrentThread ( ) ; <nl> + m_coreDispatcherAKARevoker = coreWindow . Dispatcher ( ) . AcceleratorKeyActivated ( <nl> + winrt : : auto_revoke , <nl> + [ this ] ( const auto & sender , const winrt : : AcceleratorKeyEventArgs & args ) { <nl> + if ( ( ( args . VirtualKey ( ) = = winrt : : Windows : : System : : VirtualKey : : F10 ) | | <nl> + ( args . VirtualKey ( ) = = winrt : : Windows : : System : : VirtualKey : : Menu ) ) & & <nl> + KeyboardHelper : : IsModifiedKeyPressed ( <nl> + winrt : : CoreWindow : : GetForCurrentThread ( ) , <nl> + winrt : : VirtualKey : : Shift ) ) { <nl> + if ( ! IsDeveloperMenuShowing ( ) ) { <nl> + ShowDeveloperMenu ( ) ; <nl> + } <nl> + } <nl> + } ) ; <nl> + } <nl> + <nl> + void ReactControl : : ShowDeveloperMenu ( ) { <nl> + assert ( m_developerMenuRoot = = nullptr ) ; <nl> + <nl> + winrt : : hstring xamlString = <nl> + L " < Grid Background = ' { ThemeResource SystemControlBackgroundChromeMediumBrush } ' " <nl> + L " xmlns = ' http : / / schemas . microsoft . com / winfx / 2006 / xaml / presentation ' " <nl> + L " xmlns : x = ' http : / / schemas . microsoft . com / winfx / 2006 / xaml ' > " <nl> + L " < StackPanel HorizontalAlignment = ' Center ' > " <nl> + L " < TextBlock Margin = ' 0 , 0 , 0 , 10 ' FontSize = ' 40 ' > Developer Menu < / TextBlock > " <nl> + L " < Button HorizontalAlignment = ' Stretch ' x : Name = ' Reload ' > Reload Javascript ( TBD ) < / Button > " <nl> + L " < Button HorizontalAlignment = ' Stretch ' x : Name = ' RemoteDebug ' > < / Button > " <nl> + L " < Button HorizontalAlignment = ' Stretch ' x : Name = ' LiveReload ' > Enable Live Reload ( TBD ) < / Button > " <nl> + L " < Button HorizontalAlignment = ' Stretch ' x : Name = ' Inspector ' > Show Inspector ( TBD ) < / Button > " <nl> + L " < Button HorizontalAlignment = ' Stretch ' x : Name = ' Cancel ' > Cancel < / Button > " <nl> + L " < / StackPanel > " <nl> + L " < / Grid > " ; <nl> + m_developerMenuRoot = winrt : : unbox_value < winrt : : Grid > ( <nl> + winrt : : Markup : : XamlReader : : Load ( xamlString ) ) ; <nl> + auto remoteDebugJSButton = <nl> + m_developerMenuRoot . FindName ( L " RemoteDebug " ) . as < winrt : : Button > ( ) ; <nl> + auto cancelButton = <nl> + m_developerMenuRoot . FindName ( L " Cancel " ) . as < winrt : : Button > ( ) ; <nl> + bool useWebDebugger = <nl> + m_reactInstance - > GetReactInstanceSettings ( ) . UseWebDebugger ; <nl> + remoteDebugJSButton . Content ( winrt : : box_value ( <nl> + useWebDebugger ? L " Disable Remote JS Debugging " <nl> + : L " Enable Remote JS Debugging " ) ) ; <nl> + m_remoteDebugJSRevoker = remoteDebugJSButton . Click ( <nl> + winrt : : auto_revoke , <nl> + [ this , useWebDebugger ] ( <nl> + const auto & sender , const winrt : : RoutedEventArgs & args ) { <nl> + DismissDeveloperMenu ( ) ; <nl> + m_instanceCreator - > persistUseWebDebugger ( ! useWebDebugger ) ; <nl> + Reload ( true ) ; <nl> + } ) ; <nl> + m_cancelRevoker = cancelButton . Click ( <nl> + winrt : : auto_revoke , <nl> + [ this ] ( const auto & sender , const winrt : : RoutedEventArgs & args ) { <nl> + DismissDeveloperMenu ( ) ; <nl> + } ) ; <nl> + <nl> + auto xamlRootGrid ( m_xamlRootView . as < winrt : : Grid > ( ) ) ; <nl> + xamlRootGrid . Children ( ) . Append ( m_developerMenuRoot ) ; <nl> + } <nl> + <nl> + void ReactControl : : DismissDeveloperMenu ( ) { <nl> + assert ( m_developerMenuRoot ! = nullptr ) ; <nl> + auto xamlRootGrid ( m_xamlRootView . as < winrt : : Grid > ( ) ) ; <nl> + uint32_t indexToRemove = 0 ; <nl> + xamlRootGrid . Children ( ) . IndexOf ( m_developerMenuRoot , indexToRemove ) ; <nl> + xamlRootGrid . Children ( ) . RemoveAt ( indexToRemove ) ; <nl> + m_developerMenuRoot = nullptr ; <nl> + } <nl> + <nl> + bool ReactControl : : IsDeveloperMenuShowing ( ) const { <nl> + return ( m_developerMenuRoot ! = nullptr ) ; <nl> + } <nl> + <nl> } / / namespace uwp <nl> } / / namespace react <nl> mmm a / vnext / ReactUWP / Views / ReactControl . h <nl> ppp b / vnext / ReactUWP / Views / ReactControl . h <nl> class ReactControl : public std : : enable_shared_from_this < ReactControl > , <nl> void HandleInstanceErrorOnUIThread ( ) ; <nl> void PrepareXamlRootView ( XamlView const & rootView ) ; <nl> void EnsureFocusSafeHarbor ( ) ; <nl> + void InitializeDeveloperMenu ( ) ; <nl> + void ShowDeveloperMenu ( ) ; <nl> + void DismissDeveloperMenu ( ) ; <nl> + bool IsDeveloperMenuShowing ( ) const ; <nl> <nl> IXamlRootView * m_pParent ; <nl> <nl> class ReactControl : public std : : enable_shared_from_this < ReactControl > , <nl> m_focusSafeHarborLosingFocusRevoker { } ; <nl> winrt : : Grid m_redBoxGrid { nullptr } ; <nl> winrt : : TextBlock m_errorTextBlock { nullptr } ; <nl> + winrt : : Grid m_developerMenuRoot { nullptr } ; <nl> + winrt : : Button : : Click_revoker m_remoteDebugJSRevoker { } ; <nl> + winrt : : Button : : Click_revoker m_cancelRevoker { } ; <nl> + winrt : : CoreDispatcher : : AcceleratorKeyActivated_revoker <nl> + m_coreDispatcherAKARevoker { } ; <nl> } ; <nl> <nl> } / / namespace uwp <nl> mmm a / vnext / Universal . IntegrationTests / UniversalTestInstance . cpp <nl> ppp b / vnext / Universal . IntegrationTests / UniversalTestInstance . cpp <nl> struct TestReactInstanceCreator : : : react : : uwp : : IReactInstanceCreator { <nl> / / Test instance isn ' t reloaded <nl> } <nl> <nl> + void persistUseWebDebugger ( bool useWebDebugger ) { } <nl> + <nl> private : <nl> std : : shared_ptr < : : react : : uwp : : IReactInstance > m_instance ; <nl> } ; <nl> mmm a / vnext / Universal . SampleApp / HostingPane . xaml . cpp <nl> ppp b / vnext / Universal . SampleApp / HostingPane . xaml . cpp <nl> struct HostingPaneReactInstanceCreator : : : react : : uwp : : IReactInstanceCreator { <nl> pane - > markAsNeedsReload ( ) ; <nl> } <nl> <nl> + void persistUseWebDebugger ( bool useWebDebugger ) { <nl> + HostingPane ^ pane = m_wrPane . Resolve < HostingPane > ( ) ; <nl> + if ( pane ) { <nl> + pane - > persistUseWebDebugger ( useWebDebugger ) ; <nl> + } <nl> + } <nl> + <nl> private : <nl> Platform : : WeakReference m_wrPane ; <nl> } ; <nl> void HostingPane : : markAsNeedsReload ( ) { <nl> m_instance = nullptr ; <nl> } <nl> <nl> + void HostingPane : : persistUseWebDebugger ( bool useWebDebugger ) { <nl> + x_UseWebDebuggerCheckBox - > IsChecked = useWebDebugger ; <nl> + } <nl> + <nl> void HostingPane : : LoadReactNative ( ) { <nl> std : : shared_ptr < react : : uwp : : IXamlRootView > rootView = m_rootView ; <nl> <nl> mmm a / vnext / Universal . SampleApp / HostingPane . xaml . h <nl> ppp b / vnext / Universal . SampleApp / HostingPane . xaml . h <nl> namespace WindowsSampleApp { <nl> <nl> internal : std : : shared_ptr < react : : uwp : : IReactInstance > getInstance ( ) ; <nl> void markAsNeedsReload ( ) ; <nl> + void persistUseWebDebugger ( bool useWebDebugger ) ; <nl> <nl> void InitComboBoxes ( ) ; <nl> void LoadKnownApps ( ) ; <nl> mmm a / vnext / include / ReactUWP / IReactInstance . h <nl> ppp b / vnext / include / ReactUWP / IReactInstance . h <nl> struct IReactInstance { <nl> virtual void CallXamlViewCreatedTestHook ( react : : uwp : : XamlView view ) = 0 ; <nl> <nl> virtual ExpressionAnimationStore & GetExpressionAnimationStore ( ) = 0 ; <nl> + <nl> + virtual const ReactInstanceSettings & GetReactInstanceSettings ( ) const = 0 ; <nl> } ; <nl> <nl> } / / namespace uwp <nl> mmm a / vnext / include / ReactUWP / InstanceFactory . h <nl> ppp b / vnext / include / ReactUWP / InstanceFactory . h <nl> struct IXamlRootView ; <nl> struct IReactInstanceCreator { <nl> virtual std : : shared_ptr < IReactInstance > getInstance ( ) = 0 ; <nl> virtual void markAsNeedsReload ( ) = 0 ; <nl> + virtual void persistUseWebDebugger ( bool useWebDebugger ) = 0 ; <nl> } ; <nl> <nl> using ReactInstanceCreator = std : : shared_ptr < IReactInstanceCreator > ; <nl> mmm a / vnext / include / ReactUWP / Views / KeyboardEventHandler . h <nl> ppp b / vnext / include / ReactUWP / Views / KeyboardEventHandler . h <nl> struct KeyboardHelper { <nl> static std : : string <nl> FromVirtualKey ( winrt : : VirtualKey key , bool shiftDown , bool capLocked ) ; <nl> static std : : string CodeFromVirtualKey ( winrt : : VirtualKey key ) ; <nl> + static bool IsModifiedKeyPressed ( <nl> + winrt : : CoreWindow const & coreWindow , <nl> + winrt : : VirtualKey virtualKey ) ; <nl> + static bool IsModifiedKeyLocked ( <nl> + winrt : : CoreWindow const & coreWindow , <nl> + winrt : : VirtualKey virtualKey ) ; <nl> } ; <nl> } / / namespace uwp <nl> } / / namespace react <nl>
Developer menu ( )
microsoft/react-native-windows
4b995ea6fe31df89cf91a1e23ee843e40861caae
2019-08-02T17:16:47Z
new file mode 100644 <nl> index 0000000000 . . 994c7abbef <nl> mmm / dev / null <nl> ppp b / code / sorting / comb_sort / comb_sort . swift <nl> <nl> + / * Part of Cosmos by OpenGenus Foundation * / <nl> + <nl> + / / <nl> + / / comb_sort . swift <nl> + / / Created by DaiPei on 2017 / 10 / 15 . <nl> + / / <nl> + <nl> + import Foundation <nl> + <nl> + func combSort ( _ array : inout [ Int ] ) { <nl> + let shrinkFactor = 0 . 8 <nl> + var gap = array . count <nl> + var swapped = true <nl> + while gap > = 1 | | swapped { <nl> + swapped = false <nl> + if gap > = 1 { <nl> + gap = Int ( Double ( gap ) * shrinkFactor ) <nl> + } <nl> + for i in stride ( from : 0 , to : array . count - gap , by : 1 ) { <nl> + if array [ i ] > array [ i + gap ] { <nl> + swap ( & array , at : i , and : i + gap ) <nl> + swapped = true <nl> + } <nl> + } <nl> + } <nl> + } <nl> + <nl> + private func swap ( _ array : inout [ Int ] , at indexA : Int , and indexB : Int ) { <nl> + let tmp = array [ indexA ] <nl> + array [ indexA ] = array [ indexB ] <nl> + array [ indexB ] = tmp <nl> + } <nl>
add comb sort in Swift
OpenGenus/cosmos
1113def7c10d9508cf15600a6fe95fca33c54ca7
2017-10-15T01:36:30Z
new file mode 100644 <nl> index 00000000000 . . cfdd31985ea <nl> mmm / dev / null <nl> ppp b / docs / arithmetics . rst <nl> <nl> + Scalar operations <nl> + = = = = = = = = = = = = = = = = = <nl> + <nl> + Operators <nl> + mmmmmmmmm <nl> + <nl> + Arithmetic operators <nl> + * * * * * * * * * * * * * * * * * * * * <nl> + <nl> + - ` ` - a ` ` <nl> + - ` ` a + b ` ` <nl> + - ` ` a - b ` ` <nl> + - ` ` a * b ` ` <nl> + - ` ` a / b ` ` <nl> + - ` ` a / / b ` ` <nl> + - ` ` a % b ` ` <nl> + - ` ` a * * b ` ` <nl> + <nl> + . . note : : <nl> + <nl> + The ` ` % ` ` operator in Taichi follows the Python style instead of C style , e . g . : <nl> + <nl> + . . code - block : : python <nl> + <nl> + # no matter Taichi - scope or Python - scope : <nl> + print ( 2 % 3 ) # 2 <nl> + print ( - 2 % 3 ) # 1 <nl> + <nl> + For C - style mod , please use ` ` ti . raw_mod ` ` : <nl> + <nl> + . . code - block : : python <nl> + <nl> + print ( ti . raw_mod ( 2 , 3 ) ) # 2 <nl> + print ( ti . raw_mod ( - 2 , 3 ) ) # - 2 <nl> + <nl> + . . note : : <nl> + <nl> + Python 3 distinguishes ` ` / ` ` ( true division ) and ` ` / / ` ` ( floor division ) . For example , ` ` 1 . 0 / 2 . 0 = 0 . 5 ` ` , <nl> + ` ` 1 / 2 = 0 . 5 ` ` , ` ` 1 / / 2 = 0 ` ` , ` ` 4 . 2 / / 2 = 2 ` ` . And Taichi follows the same design : <nl> + <nl> + - * * true divisions * * on integral types will first cast their operands to the default float point type . <nl> + - * * floor divisions * * on float - point types will first cast their operands to the default integer type . <nl> + <nl> + To avoid such implicit casting , you can manually cast your operands to desired types , using ` ` ti . cast ` ` . <nl> + See : ref : ` default_precisions ` for more details on default numerical types . <nl> + <nl> + Logic operators <nl> + * * * * * * * * * * * * * * * <nl> + <nl> + - ` ` ~ a ` ` <nl> + - ` ` a = = b ` ` <nl> + - ` ` a ! = b ` ` <nl> + - ` ` a > b ` ` <nl> + - ` ` a < b ` ` <nl> + - ` ` a > = b ` ` <nl> + - ` ` a < = b ` ` <nl> + - ` ` not a ` ` <nl> + - ` ` a or b ` ` <nl> + - ` ` a and b ` ` <nl> + - ` ` a if cond else b ` ` <nl> + <nl> + Bitwise operators <nl> + * * * * * * * * * * * * * * * * * <nl> + <nl> + - ` ` a & b ` ` <nl> + - ` ` a ^ b ` ` <nl> + - ` ` a | b ` ` <nl> + <nl> + Functions <nl> + mmmmmmmmm <nl> + <nl> + Trigonometric functions <nl> + * * * * * * * * * * * * * * * * * * * * * * * <nl> + <nl> + . . function : : ti . sin ( x ) <nl> + . . function : : ti . cos ( x ) <nl> + . . function : : ti . tan ( x ) <nl> + . . function : : ti . asin ( x ) <nl> + . . function : : ti . acos ( x ) <nl> + . . function : : ti . atan2 ( x , y ) <nl> + . . function : : ti . tanh ( x ) <nl> + <nl> + Other arithmetic functions <nl> + * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> + <nl> + . . function : : ti . sqrt ( x ) <nl> + . . function : : ti . rsqrt ( x ) <nl> + <nl> + A fast version for ` ` 1 / ti . sqrt ( x ) ` ` . <nl> + <nl> + . . function : : ti . exp ( x ) <nl> + . . function : : ti . log ( x ) <nl> + . . function : : ti . floor ( x ) <nl> + . . function : : ti . ceil ( x ) <nl> + <nl> + Casting types <nl> + * * * * * * * * * * * * * <nl> + <nl> + . . function : : ti . cast ( x , dtype ) <nl> + <nl> + See : ref : ` type ` for more details . <nl> + <nl> + . . function : : int ( x ) <nl> + <nl> + A shortcut for ` ` ti . cast ( x , int ) ` ` . <nl> + <nl> + . . function : : float ( x ) <nl> + <nl> + A shortcut for ` ` ti . cast ( x , float ) ` ` . <nl> + <nl> + Builtin - alike functions <nl> + * * * * * * * * * * * * * * * * * * * * * * * <nl> + <nl> + . . function : : abs ( x ) <nl> + . . function : : max ( x , y , . . . ) <nl> + . . function : : min ( x , y , . . . ) <nl> + . . function : : pow ( x , y ) <nl> + <nl> + Same as ` ` x * * y ` ` . <nl> + <nl> + Random number generator <nl> + * * * * * * * * * * * * * * * * * * * * * * * <nl> + <nl> + . . function : : ti . random ( dtype = float ) <nl> + <nl> + <nl> + Element - wise arithmetics for vectors and matrices <nl> + mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> + <nl> + When these scalar functions are applied on : ref : ` matrix ` and : ref : ` vector ` , they are applied in an element - wise manner . <nl> + For example : <nl> + <nl> + . . code - block : : python <nl> + <nl> + B = ti . Matrix ( [ [ 1 . 0 , 2 . 0 , 3 . 0 ] , [ 4 . 0 , 5 . 0 , 6 . 0 ] ] ) <nl> + C = ti . Matrix ( [ [ 3 . 0 , 4 . 0 , 5 . 0 ] , [ 6 . 0 , 7 . 0 , 8 . 0 ] ] ) <nl> + <nl> + A = ti . sin ( B ) <nl> + # is equivalent to <nl> + for i in ti . static ( range ( 2 ) ) : <nl> + for j in ti . static ( range ( 3 ) ) : <nl> + A [ i , j ] = ti . sin ( B [ i , j ] ) <nl> + <nl> + A = B * * 2 <nl> + # is equivalent to <nl> + for i in ti . static ( range ( 2 ) ) : <nl> + for j in ti . static ( range ( 3 ) ) : <nl> + A [ i , j ] = B [ i , j ] * * 2 <nl> + <nl> + A = B * * C <nl> + # is equivalent to <nl> + for i in ti . static ( range ( 2 ) ) : <nl> + for j in ti . static ( range ( 3 ) ) : <nl> + A [ i , j ] = B [ i , j ] * * C [ i , j ] <nl> + <nl> + A + = 2 <nl> + # is equivalent to <nl> + for i in ti . static ( range ( 2 ) ) : <nl> + for j in ti . static ( range ( 3 ) ) : <nl> + A [ i , j ] + = 2 <nl> + <nl> + A + = B <nl> + # is equivalent to <nl> + for i in ti . static ( range ( 2 ) ) : <nl> + for j in ti . static ( range ( 3 ) ) : <nl> + A [ i , j ] + = B [ i , j ] <nl> mmm a / docs / index . rst <nl> ppp b / docs / index . rst <nl> The Taichi Programming Language <nl> type <nl> tensor_matrix <nl> external <nl> - atomic <nl> <nl> <nl> . . toctree : : <nl> The Taichi Programming Language <nl> scalar_tensor <nl> vector <nl> matrix <nl> + arithmetics <nl> + atomic <nl> snode <nl> <nl> <nl> mmm a / docs / syntax . rst <nl> ppp b / docs / syntax . rst <nl> <nl> - Syntax <nl> - = = = = = = <nl> + Kernels and functions <nl> + = = = = = = = = = = = = = = = = = = = = = <nl> <nl> Taichi - scope vs Python - scope <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> reference : <nl> else : <nl> ret = 0 . 0 <nl> return ret <nl> - <nl> - <nl> - Scalar arithmetics <nl> mmmmmmmmmmmmmmmmmm - <nl> - <nl> - Supported scalar functions : <nl> - <nl> - . . function : : ti . sin ( x ) <nl> - . . function : : ti . cos ( x ) <nl> - . . function : : ti . asin ( x ) <nl> - . . function : : ti . acos ( x ) <nl> - . . function : : ti . atan2 ( x , y ) <nl> - . . function : : ti . cast ( x , data_type ) <nl> - . . function : : ti . sqrt ( x ) <nl> - . . function : : ti . rsqrt ( x ) <nl> - . . function : : ti . floor ( x ) <nl> - . . function : : ti . ceil ( x ) <nl> - . . function : : ti . tan ( x ) <nl> - . . function : : ti . tanh ( x ) <nl> - . . function : : ti . exp ( x ) <nl> - . . function : : ti . log ( x ) <nl> - . . function : : ti . random ( data_type ) <nl> - . . function : : abs ( x ) <nl> - . . function : : int ( x ) <nl> - . . function : : float ( x ) <nl> - . . function : : max ( x , y ) <nl> - . . function : : min ( x , y ) <nl> - . . function : : pow ( x , y ) <nl> - <nl> - . . note : : <nl> - <nl> - Python 3 distinguishes ` ` / ` ` ( true division ) and ` ` / / ` ` ( floor division ) . For example , ` ` 1 . 0 / 2 . 0 = 0 . 5 ` ` , <nl> - ` ` 1 / 2 = 0 . 5 ` ` , ` ` 1 / / 2 = 0 ` ` , ` ` 4 . 2 / / 2 = 2 ` ` . Taichi follows this design : <nl> - <nl> - - * * true divisions * * on integral types will first cast their operands to the default float point type . <nl> - - * * floor divisions * * on float - point types will first cast their operands to the default integer type . <nl> - <nl> - To avoid such implicit casting , you can manually cast your operands to desired types , using ` ` ti . cast ` ` . <nl> - See : ref : ` default_precisions ` for more details on default numerical types . <nl> - <nl> - . . note : : <nl> - <nl> - When these scalar functions are applied on : ref : ` matrix ` and : ref : ` vector ` , they are applied in an element - wise manner . <nl> - For example : <nl> - <nl> - . . code - block : : python <nl> - <nl> - B = ti . Matrix ( [ [ 1 . 0 , 2 . 0 , 3 . 0 ] , [ 4 . 0 , 5 . 0 , 6 . 0 ] ] ) <nl> - C = ti . Matrix ( [ [ 3 . 0 , 4 . 0 , 5 . 0 ] , [ 6 . 0 , 7 . 0 , 8 . 0 ] ] ) <nl> - <nl> - A = ti . sin ( B ) <nl> - # is equivalent to <nl> - for i in ti . static ( range ( 2 ) ) : <nl> - for j in ti . static ( range ( 3 ) ) : <nl> - A [ i , j ] = ti . sin ( B [ i , j ] ) <nl> - <nl> - A = ti . pow ( B , 2 ) <nl> - # is equivalent to <nl> - for i in ti . static ( range ( 2 ) ) : <nl> - for j in ti . static ( range ( 3 ) ) : <nl> - A [ i , j ] = ti . pow ( B [ i , j ] , 2 ) <nl> - <nl> - A = ti . pow ( B , C ) <nl> - # is equivalent to <nl> - for i in ti . static ( range ( 2 ) ) : <nl> - for j in ti . static ( range ( 3 ) ) : <nl> - A [ i , j ] = ti . pow ( B [ i , j ] , C [ i , j ] ) <nl> - <nl> - A + = 2 <nl> - # is equivalent to <nl> - for i in ti . static ( range ( 2 ) ) : <nl> - for j in ti . static ( range ( 3 ) ) : <nl> - A [ i , j ] + = 2 <nl> - <nl> - A + = B <nl> - # is equivalent to <nl> - for i in ti . static ( range ( 2 ) ) : <nl> - for j in ti . static ( range ( 3 ) ) : <nl> - A [ i , j ] + = B [ i , j ] <nl> mmm a / docs / type . rst <nl> ppp b / docs / type . rst <nl> <nl> + . . _type : <nl> + <nl> Type system <nl> = = = = = = = = = = = <nl> <nl> mmm a / python / taichi / lang / ops . py <nl> ppp b / python / taichi / lang / ops . py <nl> def logical_not ( a ) : <nl> return _unary_operation ( ti_core . expr_logic_not , lambda x : int ( not x ) , a ) <nl> <nl> <nl> - def random ( dt = None ) : <nl> - if dt is None : <nl> - import taichi <nl> - dt = taichi . get_runtime ( ) . default_fp <nl> - x = Expr ( ti_core . make_rand_expr ( dt ) ) <nl> + def random ( dtype = float ) : <nl> + dtype = cook_dtype ( dtype ) <nl> + x = Expr ( ti_core . make_rand_expr ( dtype ) ) <nl> return expr_init ( x ) <nl> <nl> <nl>
[ Doc ] Separate arithmetics . rst from syntax . rst and fill it with more details ( )
taichi-dev/taichi
0077ccba02fbad22db75763eb3c31b7803e595a5
2020-08-26T14:55:50Z
mmm a / port / jemalloc_helper . h <nl> ppp b / port / jemalloc_helper . h <nl> <nl> <nl> # pragma once <nl> <nl> + # if defined ( __clang__ ) <nl> + / / glibc ' s ` posix_memalign ( ) ` declaration specifies ` throw ( ) ` while clang ' s <nl> + / / declaration does not . There is a hack in clang to make its re - declaration <nl> + / / compatible with glibc ' s if they are declared consecutively . That hack breaks <nl> + / / if yet another ` posix_memalign ( ) ` declaration comes between glibc ' s and <nl> + / / clang ' s declarations . Include " mm_malloc . h " here ensures glibc ' s and clang ' s <nl> + / / declarations both come before " jemalloc . h " ' s ` posix_memalign ( ) ` declaration . <nl> + / / <nl> + / / This problem could also be avoided if " jemalloc . h " ' s ` posix_memalign ( ) ` <nl> + / / declaration did not specify ` throw ( ) ` when built with clang . <nl> + # include < mm_malloc . h > <nl> + # endif <nl> + <nl> # ifdef ROCKSDB_JEMALLOC <nl> # ifdef __FreeBSD__ <nl> # include < malloc_np . h > <nl>
Fix clang build with jemalloc ( )
facebook/rocksdb
09ea5d8944700be9ce00fdd66f29f34573f33e76
2019-07-02T20:02:12Z
mmm a / include / swift / SILAnalysis / AliasAnalysis . h <nl> ppp b / include / swift / SILAnalysis / AliasAnalysis . h <nl> namespace swift { <nl> <nl> class SILValue ; <nl> class SILInstruction ; <nl> + class SideEffectAnalysis ; <nl> <nl> / / / This class is a simple wrapper around an alias analysis cache . This is <nl> / / / needed since we do not have an " analysis " infrastructure . <nl> class AliasAnalysis : public SILAnalysis { <nl> using AliasCacheKey = std : : pair < SILValue , SILValue > ; <nl> llvm : : DenseMap < AliasCacheKey , AliasResult > AliasCache ; <nl> SILModule * Mod ; <nl> + SideEffectAnalysis * SEA ; <nl> <nl> using MemoryBehavior = SILInstruction : : MemoryBehavior ; <nl> <nl> AliasResult cacheValue ( AliasCacheKey Key , AliasResult Result ) ; <nl> <nl> public : <nl> - AliasAnalysis ( SILModule * M ) : SILAnalysis ( AnalysisKind : : Alias ) , Mod ( M ) { } <nl> + AliasAnalysis ( SILModule * M ) : <nl> + SILAnalysis ( AnalysisKind : : Alias ) , Mod ( M ) , SEA ( nullptr ) { } <nl> <nl> static bool classof ( const SILAnalysis * S ) { <nl> return S - > getKind ( ) = = AnalysisKind : : Alias ; <nl> } <nl> + <nl> + virtual void initialize ( SILPassManager * PM ) ; <nl> + <nl> + SideEffectAnalysis * getSideEffectAnalysis ( ) const { return SEA ; } <nl> <nl> / / / Perform an alias query to see if V1 , V2 refer to the same values . <nl> AliasResult alias ( SILValue V1 , SILValue V2 , SILType TBAAType1 = SILType ( ) , <nl> mmm a / include / swift / SILPasses / Passes . def <nl> ppp b / include / swift / SILPasses / Passes . def <nl> PASS ( MandatoryInlining , " mandatory - inlining " , <nl> " Inline transparent functions " ) <nl> PASS ( Mem2Reg , " mem2reg " , <nl> " Promote stack allocations to SSA values " ) <nl> + PASS ( MemBehaviorDumper , " mem - behavior - dump " , <nl> + " Dump MemBehavior results from alias analysis for all instruction pairs " ) <nl> PASS ( MergeCondFails , " merge - cond_fails " , <nl> " Remove redundant overflow checks " ) <nl> PASS ( NoReturnFolding , " noreturn - folding " , <nl> mmm a / lib / SILAnalysis / AliasAnalysis . cpp <nl> ppp b / lib / SILAnalysis / AliasAnalysis . cpp <nl> <nl> # define DEBUG_TYPE " sil - aa " <nl> # include " swift / SILAnalysis / AliasAnalysis . h " <nl> # include " swift / SILAnalysis / ValueTracking . h " <nl> + # include " swift / SILAnalysis / SideEffectAnalysis . h " <nl> # include " swift / SILPasses / Utils / Local . h " <nl> + # include " swift / SILPasses / PassManager . h " <nl> # include " swift / SIL / Projection . h " <nl> # include " swift / SIL / SILValue . h " <nl> # include " swift / SIL / SILInstruction . h " <nl> class MemoryBehaviorVisitor <nl> return Behavior ; <nl> } <nl> } <nl> + <nl> + / / / Get the memory behavior from function side - effects . <nl> + MemBehavior getMemBehavior ( const SideEffectAnalysis : : Effects & E ) ; <nl> <nl> MemBehavior visitLoadInst ( LoadInst * LI ) ; <nl> MemBehavior visitStoreInst ( StoreInst * SI ) ; <nl> MemBehavior MemoryBehaviorVisitor : : visitBuiltinInst ( BuiltinInst * BI ) { <nl> return MemBehavior : : MayHaveSideEffects ; <nl> } <nl> <nl> - MemBehavior MemoryBehaviorVisitor : : visitApplyInst ( ApplyInst * AI ) { <nl> - if ( isLetPointer ( V ) ) <nl> + MemBehavior MemoryBehaviorVisitor : : getMemBehavior ( <nl> + const SideEffectAnalysis : : Effects & E ) { <nl> + if ( E . mayRelease ( ) ) <nl> + return MemBehavior : : MayHaveSideEffects ; <nl> + <nl> + if ( ! IgnoreRefCountIncrements & & E . mayRetain ( ) ) <nl> + return MemBehavior : : MayHaveSideEffects ; <nl> + <nl> + if ( E . mayWrite ( ) ) <nl> + return E . mayRead ( ) ? MemBehavior : : MayReadWrite : MemBehavior : : MayWrite ; <nl> + <nl> + if ( E . mayRead ( ) ) <nl> return MemBehavior : : MayRead ; <nl> <nl> - DEBUG ( llvm : : dbgs ( ) < < " Found apply we don ' t understand returning " <nl> - " MHSF . \ n " ) ; <nl> - return MemBehavior : : MayHaveSideEffects ; <nl> + return MemBehavior : : None ; <nl> + } <nl> + <nl> + MemBehavior MemoryBehaviorVisitor : : visitApplyInst ( ApplyInst * AI ) { <nl> + <nl> + SideEffectAnalysis : : FunctionEffects ApplyEffects ; <nl> + AA . getSideEffectAnalysis ( ) - > getEffects ( ApplyEffects , AI ) ; <nl> + <nl> + MemBehavior Behavior = MemBehavior : : None ; <nl> + <nl> + / / We can ignore mayTrap ( ) . <nl> + if ( ApplyEffects . mayReadRC ( ) | | <nl> + ( ! IgnoreRefCountIncrements & & ApplyEffects . mayAllocObjects ( ) ) ) { <nl> + Behavior = MemBehavior : : MayHaveSideEffects ; <nl> + } else { <nl> + auto & GlobalEffects = ApplyEffects . getGlobalEffects ( ) ; <nl> + Behavior = getMemBehavior ( GlobalEffects ) ; <nl> + <nl> + / / Check all parameter effects . <nl> + for ( unsigned Idx = 0 , End = AI - > getNumArguments ( ) ; <nl> + Idx < End & & Behavior < MemBehavior : : MayHaveSideEffects ; <nl> + + + Idx ) { <nl> + auto & ArgEffect = ApplyEffects . getParameterEffects ( ) [ Idx ] ; <nl> + auto ArgBehavior = getMemBehavior ( ArgEffect ) ; <nl> + if ( ArgBehavior > Behavior ) { <nl> + SILValue Arg = AI - > getArgument ( Idx ) ; <nl> + / / We only consider the argument effects if the argument aliases V . <nl> + if ( ! Arg . getType ( ) . isAddress ( ) | | <nl> + ! AA . isNoAlias ( Arg , V , Arg . getType ( ) , findTypedAccessType ( V ) ) ) { <nl> + Behavior = ArgBehavior ; <nl> + } <nl> + } <nl> + } <nl> + } <nl> + if ( Behavior > MemBehavior : : MayRead & & isLetPointer ( V ) ) <nl> + Behavior = MemBehavior : : MayRead ; <nl> + <nl> + DEBUG ( llvm : : dbgs ( ) < < " Found apply , returning " < < Behavior < < ' \ n ' ) ; <nl> + return Behavior ; <nl> } <nl> <nl> SILInstruction : : MemoryBehavior <nl> AliasAnalysis : : AliasResult AliasAnalysis : : cacheValue ( AliasCacheKey Key , <nl> return AliasCache [ Key ] = Result ; <nl> } <nl> <nl> + void AliasAnalysis : : initialize ( SILPassManager * PM ) { <nl> + SEA = PM - > getAnalysis < SideEffectAnalysis > ( ) ; <nl> + } <nl> + <nl> SILAnalysis * swift : : createAliasAnalysis ( SILModule * M ) { <nl> return new AliasAnalysis ( M ) ; <nl> } <nl> mmm a / lib / SILPasses / AADumper . cpp <nl> ppp b / lib / SILPasses / AADumper . cpp <nl> <nl> # include " swift / SIL / SILFunction . h " <nl> # include " swift / SIL / SILValue . h " <nl> # include " swift / SILAnalysis / AliasAnalysis . h " <nl> + # include " swift / SILAnalysis / SideEffectAnalysis . h " <nl> # include " swift / SILAnalysis / Analysis . h " <nl> # include " swift / SILPasses / Transforms . h " <nl> # include " llvm / Support / Debug . h " <nl> static bool gatherValues ( SILFunction & Fn , std : : vector < SILValue > & Values ) { <nl> <nl> namespace { <nl> <nl> + / / / Dumps the alias relations between all instructions of a function . <nl> class SILAADumper : public SILFunctionTransform { <nl> <nl> void run ( ) override { <nl> class SILAADumper : public SILFunctionTransform { <nl> StringRef getName ( ) override { return " AA Dumper " ; } <nl> } ; <nl> <nl> + / / / Dumps the memory behavior of instructions in a function . <nl> + class MemBehaviorDumper : public SILFunctionTransform { <nl> + <nl> + / / To reduce the amount of output , we only dump the memory behavior of <nl> + / / selected types of instructions . <nl> + static bool shouldTestInstruction ( SILInstruction * I ) { <nl> + / / Only consider function calls . <nl> + if ( FullApplySite : : isa ( I ) ) <nl> + return true ; <nl> + <nl> + return false ; <nl> + } <nl> + <nl> + void run ( ) override { <nl> + SILFunction & Fn = * getFunction ( ) ; <nl> + llvm : : outs ( ) < < " @ " < < Fn . getName ( ) < < " \ n " ; <nl> + / / Gather up all Values in Fn . <nl> + std : : vector < SILValue > Values ; <nl> + if ( ! gatherValues ( Fn , Values ) ) <nl> + return ; <nl> + <nl> + AliasAnalysis * AA = PM - > getAnalysis < AliasAnalysis > ( ) ; <nl> + SideEffectAnalysis * SEA = PM - > getAnalysis < SideEffectAnalysis > ( ) ; <nl> + SEA - > recompute ( ) ; <nl> + <nl> + unsigned PairCount = 0 ; <nl> + for ( auto & BB : Fn ) { <nl> + for ( auto & I : BB ) { <nl> + if ( shouldTestInstruction ( & I ) ) { <nl> + <nl> + / / Print the memory behavior in relation to all other values in the <nl> + / / function . <nl> + for ( auto & V : Values ) { <nl> + bool Read = AA - > mayReadFromMemory ( & I , V ) ; <nl> + bool Write = AA - > mayWriteToMemory ( & I , V ) ; <nl> + bool SideEffects = AA - > mayHaveSideEffects ( & I , V ) ; <nl> + llvm : : outs ( ) < < <nl> + " PAIR # " < < PairCount + + < < " . \ n " < < <nl> + " " < < SILValue ( & I ) < < <nl> + " " < < V < < <nl> + " r = " < < Read < < " , w = " < < Write < < " , se = " < < SideEffects < < " \ n " ; <nl> + } <nl> + } <nl> + } <nl> + } <nl> + llvm : : outs ( ) < < " \ n " ; <nl> + } <nl> + <nl> + StringRef getName ( ) override { return " Memory Behavior Dumper " ; } <nl> + } ; <nl> + <nl> } / / end anonymous namespace <nl> <nl> SILTransform * swift : : createAADumper ( ) { return new SILAADumper ( ) ; } <nl> + <nl> + SILTransform * swift : : createMemBehaviorDumper ( ) { <nl> + return new MemBehaviorDumper ( ) ; <nl> + } <nl> new file mode 100644 <nl> index 000000000000 . . 130df01fce8d <nl> mmm / dev / null <nl> ppp b / test / SILAnalysis / mem - behavior . sil <nl> <nl> + / / RUN : % target - sil - opt % s - aa = basic - aa - mem - behavior - dump - o / dev / null | FileCheck % s <nl> + <nl> + / / REQUIRES : asserts <nl> + <nl> + import Builtin <nl> + import Swift <nl> + <nl> + class X { <nl> + @ sil_stored var a : Int32 <nl> + @ sil_stored var x : X <nl> + <nl> + init ( ) <nl> + } <nl> + <nl> + sil @ unknown_func : $ @ convention ( thin ) ( Int32 , @ inout Int32 ) - > ( ) <nl> + <nl> + sil @ store_to_int : $ @ convention ( thin ) ( Int32 , @ inout Int32 ) - > ( ) { <nl> + bb0 ( % 0 : $ Int32 , % 1 : $ * Int32 ) : <nl> + store % 0 to % 1 : $ * Int32 <nl> + % r = tuple ( ) <nl> + return % r : $ ( ) <nl> + } <nl> + <nl> + sil @ only_retain : $ @ convention ( thin ) ( @ guaranteed X ) - > ( ) { <nl> + bb0 ( % 0 : $ X ) : <nl> + strong_retain % 0 : $ X <nl> + <nl> + % r = tuple ( ) <nl> + return % r : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : @ call_unknown_func <nl> + / / CHECK : PAIR # 1 . <nl> + / / CHECK - NEXT : ( 0 ) : % 4 = apply % 3 ( % 0 , % 1 ) : $ @ convention ( thin ) ( Int32 , @ inout Int32 ) - > ( ) <nl> + / / CHECK - NEXT : ( 0 ) : % 1 = argument of bb0 : $ * Int32 / / user : % 4 <nl> + / / CHECK - NEXT : r = 1 , w = 1 , se = 1 <nl> + / / CHECK : PAIR # 2 . <nl> + / / CHECK - NEXT : ( 0 ) : % 4 = apply % 3 ( % 0 , % 1 ) : $ @ convention ( thin ) ( Int32 , @ inout Int32 ) - > ( ) <nl> + / / CHECK - NEXT : ( 0 ) : % 2 = argument of bb0 : $ * Int32 <nl> + / / CHECK - NEXT : r = 1 , w = 1 , se = 1 <nl> + sil @ call_unknown_func : $ @ convention ( thin ) ( Int32 , @ inout Int32 , @ inout Int32 ) - > ( ) { <nl> + bb0 ( % 0 : $ Int32 , % 1 : $ * Int32 , % 2 : $ * Int32 ) : <nl> + % 3 = function_ref @ unknown_func : $ @ convention ( thin ) ( Int32 , @ inout Int32 ) - > ( ) <nl> + % 4 = apply % 3 ( % 0 , % 1 ) : $ @ convention ( thin ) ( Int32 , @ inout Int32 ) - > ( ) <nl> + <nl> + % r = tuple ( ) <nl> + return % r : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : @ call_store_to_int_not_aliased <nl> + / / CHECK : PAIR # 1 . <nl> + / / CHECK - NEXT : ( 0 ) : % 4 = apply % 3 ( % 0 , % 1 ) : $ @ convention ( thin ) ( Int32 , @ inout Int32 ) - > ( ) <nl> + / / CHECK - NEXT : ( 0 ) : % 1 = argument of bb0 : $ * Int32 / / user : % 4 <nl> + / / CHECK - NEXT : r = 0 , w = 1 , se = 1 <nl> + / / CHECK : PAIR # 2 . <nl> + / / CHECK - NEXT : ( 0 ) : % 4 = apply % 3 ( % 0 , % 1 ) : $ @ convention ( thin ) ( Int32 , @ inout Int32 ) - > ( ) <nl> + / / CHECK - NEXT : ( 0 ) : % 2 = argument of bb0 : $ * Int32 <nl> + / / CHECK - NEXT : r = 0 , w = 0 , se = 0 <nl> + sil @ call_store_to_int_not_aliased : $ @ convention ( thin ) ( Int32 , @ inout Int32 , @ inout Int32 ) - > ( ) { <nl> + bb0 ( % 0 : $ Int32 , % 1 : $ * Int32 , % 2 : $ * Int32 ) : <nl> + % 3 = function_ref @ store_to_int : $ @ convention ( thin ) ( Int32 , @ inout Int32 ) - > ( ) <nl> + % 4 = apply % 3 ( % 0 , % 1 ) : $ @ convention ( thin ) ( Int32 , @ inout Int32 ) - > ( ) <nl> + <nl> + % r = tuple ( ) <nl> + return % r : $ ( ) <nl> + } <nl> + <nl> + / / CHECK - LABEL : @ call_store_to_int_aliased <nl> + / / CHECK : PAIR # 3 . <nl> + / / CHECK - NEXT : ( 0 ) : % 6 = apply % 5 ( % 0 , % 3 ) : $ @ convention ( thin ) ( Int32 , @ inout Int32 ) - > ( ) <nl> + / / CHECK - NEXT : ( 0 ) : % 3 = ref_element_addr % 1 : $ X , # X . a / / user : % 6 <nl> + / / CHECK - NEXT : r = 0 , w = 1 , se = 1 <nl> + / / CHECK : PAIR # 4 . <nl> + / / CHECK - NEXT : ( 0 ) : % 6 = apply % 5 ( % 0 , % 3 ) : $ @ convention ( thin ) ( Int32 , @ inout Int32 ) - > ( ) <nl> + / / CHECK - NEXT : ( 0 ) : % 4 = ref_element_addr % 2 : $ X , # X . a <nl> + / / CHECK - NEXT : r = 0 , w = 1 , se = 1 <nl> + sil @ call_store_to_int_aliased : $ @ convention ( thin ) ( Int32 , @ guaranteed X , @ guaranteed X ) - > ( ) { <nl> + bb0 ( % 0 : $ Int32 , % 1 : $ X , % 2 : $ X ) : <nl> + % 3 = ref_element_addr % 1 : $ X , # X . a <nl> + % 4 = ref_element_addr % 2 : $ X , # X . a <nl> + % 5 = function_ref @ store_to_int : $ @ convention ( thin ) ( Int32 , @ inout Int32 ) - > ( ) <nl> + % 6 = apply % 5 ( % 0 , % 3 ) : $ @ convention ( thin ) ( Int32 , @ inout Int32 ) - > ( ) <nl> + <nl> + % r = tuple ( ) <nl> + return % r : $ ( ) <nl> + } <nl> + <nl> + sil @ call_only_retain : $ @ convention ( thin ) ( @ guaranteed X , @ guaranteed X ) - > ( ) { <nl> + bb0 ( % 0 : $ X , % 1 : $ X ) : <nl> + % 2 = function_ref @ only_retain : $ @ convention ( thin ) ( @ guaranteed X ) - > ( ) <nl> + % 3 = apply % 2 ( % 0 ) : $ @ convention ( thin ) ( @ guaranteed X ) - > ( ) <nl> + <nl> + % r = tuple ( ) <nl> + return % r : $ ( ) <nl> + } <nl> + <nl> mmm a / test / SILPasses / let_propagation . swift <nl> ppp b / test / SILPasses / let_propagation . swift <nl> <nl> / / It is calle just to trigger flushing of all known stored in LoadStore optimizations . <nl> @ inline ( never ) <nl> func action ( ) { <nl> + print ( " " ) <nl> } <nl> <nl> final public class A0 { <nl>
Use side effect analysis in alias analysis .
apple/swift
253d56cbdfc64e37179d2327cbff70121d47ebc5
2015-09-15T17:37:42Z
mmm a / include / swift / SILOptimizer / Utils / SILInliner . h <nl> ppp b / include / swift / SILOptimizer / Utils / SILInliner . h <nl> class SILInliner : public TypeSubstCloner < SILInliner , SILOptFunctionBuilder > { <nl> public : <nl> enum class InlineKind { MandatoryInline , PerformanceInline } ; <nl> <nl> - / / Returns true if this an begin_apply instruction that we can inline or <nl> - / / another application site . <nl> - static bool canInlineBeginApply ( FullApplySite AI ) ; <nl> + / / Returns true if this an apply site that can ' t be inlined for some <nl> + / / structural reason . <nl> + static bool canInline ( FullApplySite AI ) ; <nl> <nl> private : <nl> InlineKind IKind ; <nl> mmm a / lib / SILOptimizer / Utils / PerformanceInlinerUtils . cpp <nl> ppp b / lib / SILOptimizer / Utils / PerformanceInlinerUtils . cpp <nl> SILFunction * swift : : getEligibleFunction ( FullApplySite AI , <nl> return nullptr ; <nl> } <nl> <nl> - / / We don ' t currently support inlining co - routines with several yields . <nl> - if ( ! SILInliner : : canInlineBeginApply ( AI ) ) <nl> + / / Not all apply sites can be inlined , even if they ' re direct . <nl> + if ( ! SILInliner : : canInline ( AI ) ) <nl> return nullptr ; <nl> <nl> auto ModuleName = Callee - > getModule ( ) . getSwiftModule ( ) - > getName ( ) . str ( ) ; <nl> mmm a / lib / SILOptimizer / Utils / SILInliner . cpp <nl> ppp b / lib / SILOptimizer / Utils / SILInliner . cpp <nl> static bool canInlineBeginApply ( BeginApplyInst * BA ) { <nl> return true ; <nl> } <nl> <nl> - bool SILInliner : : canInlineBeginApply ( FullApplySite AI ) { <nl> + bool SILInliner : : canInline ( FullApplySite AI ) { <nl> if ( auto BA = dyn_cast < BeginApplyInst > ( AI ) ) { <nl> - return : : canInlineBeginApply ( BA ) ; <nl> + return canInlineBeginApply ( BA ) ; <nl> } <nl> return true ; <nl> } <nl> <nl> bool SILInliner : : canInlineFunction ( FullApplySite AI ) { <nl> - if ( ! canInlineBeginApply ( AI ) ) <nl> + if ( ! canInline ( AI ) ) <nl> return false ; <nl> return AI . getFunction ( ) ! = & Original ; <nl> } <nl>
Rename " canInlineBeginApply " to just " canInline " ; NFC .
apple/swift
656aba19eaf8b3fc397e9f2aa1d511498d5a3207
2018-08-21T07:44:08Z
mmm a / build / deps / github_hashes / facebook / fbthrift - rev . txt <nl> ppp b / build / deps / github_hashes / facebook / fbthrift - rev . txt <nl> @ @ - 1 + 1 @ @ <nl> - Subproject commit 31c8155517ade84c67d2e5e68abbead99ebed741 <nl> + Subproject commit b2a8577080917f6672ed5d0541f93e6f3439c13d <nl> mmm a / build / deps / github_hashes / facebook / folly - rev . txt <nl> ppp b / build / deps / github_hashes / facebook / folly - rev . txt <nl> @ @ - 1 + 1 @ @ <nl> - Subproject commit fbb0c170af6018bd2a419d09f293c6465cf3aa4f <nl> + Subproject commit e5ccead7a0afa72e623db0e34eb5c040d60def1b <nl>
Updating submodules
facebook/watchman
4dff874de07baf296c88d15e0849d2ae6bac1fe6
2020-03-12T22:42:41Z
mmm a / xbmc / epg / GUIEPGGridContainer . cpp <nl> ppp b / xbmc / epg / GUIEPGGridContainer . cpp <nl> void CGUIEPGGridContainer : : RenderProgressIndicator ( ) <nl> { <nl> if ( g_graphicsContext . SetClipRegion ( m_rulerPosX , m_rulerPosY , m_gridWidth , m_height ) ) <nl> { <nl> + m_guiProgressIndicatorTexture . SetDiffuseColor ( m_diffuseColor ) ; <nl> m_guiProgressIndicatorTexture . Render ( ) ; <nl> g_graphicsContext . RestoreClipRegion ( ) ; <nl> } <nl>
Merge pull request from mkortstiege / fix - progresstexture - diffuse
xbmc/xbmc
bf0f4de51a6955e3eba118e90852fc538d549c79
2015-11-05T15:53:53Z
mmm a / test / test_distributions . py <nl> ppp b / test / test_distributions . py <nl> def _check_sampler_sampler ( self , torch_dist , ref_dist , message , multivariate = Fal <nl> self . assertLess ( - threshold , bias , message ) <nl> self . assertLess ( bias , threshold , message ) <nl> <nl> + @ unittest . skipIf ( not TEST_NUMPY , " NumPy not found " ) <nl> + def _check_sampler_discrete ( self , torch_dist , ref_dist , message , <nl> + num_samples = 10000 , failure_rate = 1e - 3 ) : <nl> + " " " Runs a Chi2 - test for the support , but ignores tail instead of combining " " " <nl> + torch_samples = torch_dist . sample_n ( num_samples ) . squeeze ( ) <nl> + if isinstance ( torch_samples , Variable ) : <nl> + torch_samples = torch_samples . data <nl> + torch_samples = torch_samples . cpu ( ) . numpy ( ) <nl> + unique , counts = np . unique ( torch_samples , return_counts = True ) <nl> + pmf = ref_dist . pmf ( unique ) <nl> + msk = ( counts > 5 ) & ( ( pmf * num_samples ) > 5 ) <nl> + self . assertGreater ( pmf [ msk ] . sum ( ) , 0 . 9 , " Distribution is too sparse for test ; try increasing num_samples " ) <nl> + chisq , p = scipy . stats . chisquare ( counts [ msk ] , pmf [ msk ] * num_samples ) <nl> + self . assertGreater ( p , failure_rate , message ) <nl> + <nl> def _check_enumerate_support ( self , dist , examples ) : <nl> for param , expected in examples : <nl> param = torch . Tensor ( param ) <nl> def ref_log_prob ( idx , val , log_prob ) : <nl> self . assertEqual ( Geometric ( p ) . entropy ( ) . data , scipy . stats . geom ( p . data . numpy ( ) , loc = - 1 ) . entropy ( ) , prec = 1e - 3 ) <nl> self . assertEqual ( float ( Geometric ( s ) . entropy ( ) [ 0 ] ) , scipy . stats . geom ( s , loc = - 1 ) . entropy ( ) . item ( ) , prec = 1e - 3 ) <nl> <nl> + @ unittest . skipIf ( not TEST_NUMPY , " NumPy not found " ) <nl> + def test_geometric_sample ( self ) : <nl> + set_rng_seed ( 0 ) # see Note [ Randomized statistical tests ] <nl> + for prob in [ 0 . 01 , 0 . 18 , 0 . 8 ] : <nl> + self . _check_sampler_discrete ( Geometric ( prob ) , <nl> + scipy . stats . geom ( p = prob , loc = - 1 ) , <nl> + ' Geometric ( prob = { } ) ' . format ( prob ) ) <nl> + <nl> def test_binomial ( self ) : <nl> p = Variable ( torch . arange ( 0 . 05 , 1 , 0 . 1 ) , requires_grad = True ) <nl> for total_count in [ 1 , 2 , 10 ] : <nl>
Added Chi2 test for distributions ( )
pytorch/pytorch
1e7d15953e718417bc8b84766d41d41f4090ac25
2018-01-24T02:29:56Z
mmm a / src / x87 / builtins - x87 . cc <nl> ppp b / src / x87 / builtins - x87 . cc <nl> void Builtins : : Generate_ArrayCode ( MacroAssembler * masm ) { <nl> } <nl> <nl> <nl> + / / static <nl> + void Builtins : : Generate_MathMaxMin ( MacroAssembler * masm , MathMaxMinKind kind ) { <nl> + / / mmmmmmmmm - - S t a t e mmmmmmmmmmmm - <nl> + / / - - eax : number of arguments <nl> + / / - - esp [ 0 ] : return address <nl> + / / - - esp [ ( argc - n ) * 8 ] : arg [ n ] ( zero - based ) <nl> + / / - - esp [ ( argc + 1 ) * 8 ] : receiver <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - <nl> + Condition const cc = ( kind = = MathMaxMinKind : : kMin ) ? below : above ; <nl> + Heap : : RootListIndex const root_index = <nl> + ( kind = = MathMaxMinKind : : kMin ) ? Heap : : kInfinityValueRootIndex <nl> + : Heap : : kMinusInfinityValueRootIndex ; <nl> + const int reg_sel = ( kind = = MathMaxMinKind : : kMin ) ? 1 : 0 ; <nl> + <nl> + / / Load the accumulator with the default return value ( either - Infinity or <nl> + / / + Infinity ) , with the tagged value in edx and the double value in stx_0 . <nl> + __ LoadRoot ( edx , root_index ) ; <nl> + __ fld_d ( FieldOperand ( edx , HeapNumber : : kValueOffset ) ) ; <nl> + __ Move ( ecx , eax ) ; <nl> + <nl> + Label done_loop , loop ; <nl> + __ bind ( & loop ) ; <nl> + { <nl> + / / Check if all parameters done . <nl> + __ test ( ecx , ecx ) ; <nl> + __ j ( zero , & done_loop ) ; <nl> + <nl> + / / Load the next parameter tagged value into ebx . <nl> + __ mov ( ebx , Operand ( esp , ecx , times_pointer_size , 0 ) ) ; <nl> + <nl> + / / Load the double value of the parameter into stx_1 , maybe converting the <nl> + / / parameter to a number first using the ToNumberStub if necessary . <nl> + Label convert , convert_smi , convert_number , done_convert ; <nl> + __ bind ( & convert ) ; <nl> + __ JumpIfSmi ( ebx , & convert_smi ) ; <nl> + __ JumpIfRoot ( FieldOperand ( ebx , HeapObject : : kMapOffset ) , <nl> + Heap : : kHeapNumberMapRootIndex , & convert_number ) ; <nl> + { <nl> + / / Parameter is not a Number , use the ToNumberStub to convert it . <nl> + FrameScope scope ( masm , StackFrame : : INTERNAL ) ; <nl> + __ SmiTag ( eax ) ; <nl> + __ SmiTag ( ecx ) ; <nl> + __ Push ( eax ) ; <nl> + __ Push ( ecx ) ; <nl> + __ Push ( edx ) ; <nl> + __ mov ( eax , ebx ) ; <nl> + ToNumberStub stub ( masm - > isolate ( ) ) ; <nl> + __ CallStub ( & stub ) ; <nl> + __ mov ( ebx , eax ) ; <nl> + __ Pop ( edx ) ; <nl> + __ Pop ( ecx ) ; <nl> + __ Pop ( eax ) ; <nl> + { <nl> + / / Restore the double accumulator value ( stX_0 ) . <nl> + Label restore_smi , done_restore ; <nl> + __ JumpIfSmi ( edx , & restore_smi , Label : : kNear ) ; <nl> + __ fld_d ( FieldOperand ( edx , HeapNumber : : kValueOffset ) ) ; <nl> + __ jmp ( & done_restore , Label : : kNear ) ; <nl> + __ bind ( & restore_smi ) ; <nl> + __ SmiUntag ( edx ) ; <nl> + __ push ( edx ) ; <nl> + __ fild_s ( Operand ( esp , 0 ) ) ; <nl> + __ pop ( edx ) ; <nl> + __ SmiTag ( edx ) ; <nl> + __ bind ( & done_restore ) ; <nl> + } <nl> + __ SmiUntag ( ecx ) ; <nl> + __ SmiUntag ( eax ) ; <nl> + } <nl> + __ jmp ( & convert ) ; <nl> + __ bind ( & convert_number ) ; <nl> + / / Load another value into stx_1 <nl> + __ fld_d ( FieldOperand ( ebx , HeapNumber : : kValueOffset ) ) ; <nl> + __ fxch ( ) ; <nl> + __ jmp ( & done_convert , Label : : kNear ) ; <nl> + __ bind ( & convert_smi ) ; <nl> + __ SmiUntag ( ebx ) ; <nl> + __ push ( ebx ) ; <nl> + __ fild_s ( Operand ( esp , 0 ) ) ; <nl> + __ pop ( ebx ) ; <nl> + __ fxch ( ) ; <nl> + __ SmiTag ( ebx ) ; <nl> + __ bind ( & done_convert ) ; <nl> + <nl> + / / Perform the actual comparison with the accumulator value on the left hand <nl> + / / side ( stx_0 ) and the next parameter value on the right hand side ( stx_1 ) . <nl> + Label compare_equal , compare_nan , compare_swap , done_compare ; <nl> + <nl> + / / Duplicates the 2 float data for FCmp <nl> + __ fld ( 1 ) ; <nl> + __ fld ( 1 ) ; <nl> + __ FCmp ( ) ; <nl> + __ j ( parity_even , & compare_nan , Label : : kNear ) ; <nl> + __ j ( cc , & done_compare , Label : : kNear ) ; <nl> + __ j ( equal , & compare_equal , Label : : kNear ) ; <nl> + <nl> + / / Result is on the right hand side ( stx_0 ) . <nl> + __ bind ( & compare_swap ) ; <nl> + __ fxch ( ) ; <nl> + __ mov ( edx , ebx ) ; <nl> + __ jmp ( & done_compare , Label : : kNear ) ; <nl> + <nl> + / / At least one side is NaN , which means that the result will be NaN too . <nl> + __ bind ( & compare_nan ) ; <nl> + / / Set the result on the right hand side ( stx_0 ) to nan <nl> + __ fstp ( 0 ) ; <nl> + __ LoadRoot ( edx , Heap : : kNanValueRootIndex ) ; <nl> + __ fld_d ( FieldOperand ( edx , HeapNumber : : kValueOffset ) ) ; <nl> + __ jmp ( & done_compare , Label : : kNear ) ; <nl> + <nl> + / / Left and right hand side are equal , check for - 0 vs . + 0 . <nl> + __ bind ( & compare_equal ) ; <nl> + / / Check the sign of the value in reg_sel <nl> + __ fld ( reg_sel ) ; <nl> + __ FXamSign ( ) ; <nl> + __ j ( not_zero , & compare_swap ) ; <nl> + <nl> + __ bind ( & done_compare ) ; <nl> + / / The right result is on the right hand side ( stx_0 ) <nl> + / / and can remove the useless stx_1 now . <nl> + __ fxch ( ) ; <nl> + __ fstp ( 0 ) ; <nl> + __ dec ( ecx ) ; <nl> + __ jmp ( & loop ) ; <nl> + } <nl> + <nl> + __ bind ( & done_loop ) ; <nl> + __ PopReturnAddressTo ( ecx ) ; <nl> + __ lea ( esp , Operand ( esp , eax , times_pointer_size , kPointerSize ) ) ; <nl> + __ PushReturnAddressFrom ( ecx ) ; <nl> + __ mov ( eax , edx ) ; <nl> + __ Ret ( ) ; <nl> + } <nl> + <nl> / / static <nl> void Builtins : : Generate_NumberConstructor ( MacroAssembler * masm ) { <nl> / / mmmmmmmmm - - S t a t e mmmmmmmmmmmm - <nl>
X87 : [ builtins ] Make Math . max and Math . min fast by default .
v8/v8
8944d36fd57aa398a911c7f1e567baf6ddb14b24
2016-02-02T02:47:46Z
mmm a / CNTK . sln <nl> ppp b / CNTK . sln <nl> Project ( " { 2150E333 - 8FDC - 42A3 - 9474 - 1A3956D46DE8 } " ) = " SequenceTraining " , " Sequenc <nl> Tests \ Speech \ DNN \ SequenceTraining \ testcases . yml = Tests \ Speech \ DNN \ SequenceTraining \ testcases . yml <nl> EndProjectSection <nl> EndProject <nl> + Project ( " { 2150E333 - 8FDC - 42A3 - 9474 - 1A3956D46DE8 } " ) = " Image " , " Image " , " { 8071EF60 - 30F7 - 4A77 - 81AA - ADCA0E18B1E3 } " <nl> + EndProject <nl> + Project ( " { 2150E333 - 8FDC - 42A3 - 9474 - 1A3956D46DE8 } " ) = " Data " , " Data " , " { 76F9323D - 34A1 - 43A5 - A594 - C4798931FF21 } " <nl> + ProjectSection ( SolutionItems ) = preProject <nl> + Tests \ Image \ Data \ labelsmap . txt = Tests \ Image \ Data \ labelsmap . txt <nl> + Tests \ Image \ Data \ Test . txt = Tests \ Image \ Data \ Test . txt <nl> + Tests \ Image \ Data \ Train . txt = Tests \ Image \ Data \ Train . txt <nl> + EndProjectSection <nl> + EndProject <nl> + Project ( " { 2150E333 - 8FDC - 42A3 - 9474 - 1A3956D46DE8 } " ) = " QuickE2E " , " QuickE2E " , " { 2A884EB5 - 037C - 481E - 8170 - BCDC8B3EDD93 } " <nl> + ProjectSection ( SolutionItems ) = preProject <nl> + Tests \ Image \ QuickE2E \ baseline . linux . debug . gpu . txt = Tests \ Image \ QuickE2E \ baseline . linux . debug . gpu . txt <nl> + Tests \ Image \ QuickE2E \ baseline . linux . release . gpu . txt = Tests \ Image \ QuickE2E \ baseline . linux . release . gpu . txt <nl> + Tests \ Image \ QuickE2E \ baseline . windows . debug . cpu . txt = Tests \ Image \ QuickE2E \ baseline . windows . debug . cpu . txt <nl> + Tests \ Image \ QuickE2E \ baseline . windows . debug . gpu . txt = Tests \ Image \ QuickE2E \ baseline . windows . debug . gpu . txt <nl> + Tests \ Image \ QuickE2E \ baseline . windows . release . cpu . txt = Tests \ Image \ QuickE2E \ baseline . windows . release . cpu . txt <nl> + Tests \ Image \ QuickE2E \ baseline . windows . release . gpu . txt = Tests \ Image \ QuickE2E \ baseline . windows . release . gpu . txt <nl> + Tests \ Image \ QuickE2E \ cntk . config = Tests \ Image \ QuickE2E \ cntk . config <nl> + Tests \ Image \ QuickE2E \ Convolution . ndl = Tests \ Image \ QuickE2E \ Convolution . ndl <nl> + Tests \ Image \ QuickE2E \ Macros . ndl = Tests \ Image \ QuickE2E \ Macros . ndl <nl> + Tests \ Image \ QuickE2E \ run - test = Tests \ Image \ QuickE2E \ run - test <nl> + Tests \ Image \ QuickE2E \ testcases . yml = Tests \ Image \ QuickE2E \ testcases . yml <nl> + EndProjectSection <nl> + EndProject <nl> Global <nl> GlobalSection ( SolutionConfigurationPlatforms ) = preSolution <nl> Debug | Mixed Platforms = Debug | Mixed Platforms <nl> Global <nl> { EB2BE26F - 6BD4 - 4274 - 971F - 86D080779DD1 } = { DD043083 - 71A4 - 409A - AA91 - F9C548DCF7EC } <nl> { B97BDF88 - F6B5 - 4F3A - BD8E - 45F787D0C3C3 } = { 6F19321A - 65E7 - 4829 - B00C - 3886CD6C6EDE } <nl> { BB8B9FC5 - C4B3 - 477F - 80E2 - 665DC8E431BD } = { 6994C86D - A672 - 4254 - 824A - 51F4DFEB807F } <nl> + { 8071EF60 - 30F7 - 4A77 - 81AA - ADCA0E18B1E3 } = { D45DF403 - 6781 - 444E - B654 - A96868C5BE68 } <nl> + { 76F9323D - 34A1 - 43A5 - A594 - C4798931FF21 } = { 8071EF60 - 30F7 - 4A77 - 81AA - ADCA0E18B1E3 } <nl> + { 2A884EB5 - 037C - 481E - 8170 - BCDC8B3EDD93 } = { 8071EF60 - 30F7 - 4A77 - 81AA - ADCA0E18B1E3 } <nl> EndGlobalSection <nl> EndGlobal <nl> mmm a / Tests / Image / QuickE2E / Convolution . ndl <nl> ppp b / Tests / Image / QuickE2E / Convolution . ndl <nl> <nl> - load = ndlMnistMacros <nl> - run = DNN <nl> + load = ndlMnistMacros <nl> + run = DNN <nl> <nl> ndlMnistMacros = [ <nl> ImageW = 28 <nl> ImageH = 28 <nl> LabelDim = 10 <nl> <nl> - features = ImageInput ( ImageW , ImageH , 1 , tag = feature ) <nl> + features = ImageInput ( ImageW , ImageH , 1 , tag = feature ) <nl> featScale = Const ( 0 . 00390625 ) <nl> featScaled = Scale ( featScale , features ) <nl> - labels = Input ( LabelDim , tag = label ) <nl> + labels = Input ( LabelDim , tag = label ) <nl> ] <nl> <nl> DNN = [ <nl> DNN = [ <nl> h1 = DNNSigmoidLayer ( 512 , h1Dim , pool2 , 1 ) <nl> ol = DNNLayer ( h1Dim , labelDim , h1 , 1 ) <nl> <nl> - CE = CrossEntropyWithSoftmax ( labels , ol , tag = Criteria ) <nl> - Err = ErrorPrediction ( labels , ol , tag = Eval ) <nl> - OutputNodes = ol <nl> + ce = CrossEntropyWithSoftmax ( labels , ol , tag = criterion ) <nl> + err = ErrorPrediction ( labels , ol , tag = eval ) <nl> + outputNodes = ol <nl> ] <nl> - <nl> mmm a / Tests / Image / QuickE2E / Macros . ndl <nl> ppp b / Tests / Image / QuickE2E / Macros . ndl <nl> <nl> - DNNSigmoidLayer ( inDim , outDim , x , parmScale ) <nl> - { <nl> - W = Parameter ( outDim , inDim , init = Uniform , initValueScale = parmScale ) <nl> - b = Parameter ( outDim , init = Uniform , initValueScale = parmScale ) <nl> + DNNSigmoidLayer ( inDim , outDim , x , parmScale ) = [ <nl> + W = Parameter ( outDim , inDim , init = uniform , initValueScale = parmScale ) <nl> + b = Parameter ( outDim , 1 , init = uniform , initValueScale = parmScale ) <nl> t = Times ( W , x ) <nl> z = Plus ( t , b ) <nl> y = Sigmoid ( z ) <nl> - } <nl> + ] <nl> <nl> - DNNLayer ( inDim , outDim , x , parmScale ) <nl> - { <nl> - W = Parameter ( outDim , inDim , init = Uniform , initValueScale = parmScale ) <nl> - b = Parameter ( outDim , init = Uniform , initValueScale = parmScale ) <nl> + DNNLayer ( inDim , outDim , x , parmScale ) = [ <nl> + W = Parameter ( outDim , inDim , init = uniform , initValueScale = parmScale ) <nl> + b = Parameter ( outDim , 1 , init = uniform , initValueScale = parmScale ) <nl> t = Times ( W , x ) <nl> z = Plus ( t , b ) <nl> - } <nl> + ] <nl> <nl> - ConvReLULayer ( inp , outMap , inWCount , kW , kH , hStride , vStride , wScale , bValue ) <nl> - { <nl> - convW = Parameter ( outMap , inWCount , init = Uniform , initValueScale = wScale ) <nl> - conv = Convolution ( convW , inp , kW , kH , outMap , hStride , vStride , zeroPadding = false ) <nl> - convB = Parameter ( outMap , 1 , init = fixedValue , value = bValue ) <nl> + ConvReLULayer ( inp , outMap , inWCount , kW , kH , hStride , vStride , wScale , bValue ) = [ <nl> + convW = Parameter ( outMap , inWCount , init = uniform , initValueScale = wScale ) <nl> + conv = Convolution ( convW , inp , kW , kH , outMap , hStride , vStride , zeroPadding = false ) <nl> + convB = Parameter ( outMap , 1 , init = fixedValue , value = bValue ) <nl> convPlusB = Plus ( conv , convB ) ; <nl> act = RectifiedLinear ( convPlusB ) ; <nl> - } <nl> + ] <nl> <nl> - BatchNorm ( dim , x , scaleInit , biasInit ) <nl> - { <nl> + BatchNorm ( dim , x , scaleInit , biasInit ) = [ <nl> m = Mean ( x ) <nl> isd = InvStdDev ( x ) <nl> norm = ColumnElementTimes ( Minus ( x , m ) , isd ) <nl> - sc = Parameter ( dim , 1 , init = Uniform , initValueScale = scaleInit ) <nl> - b = Parameter ( dim , 1 , init = Uniform , initValueScale = biasInit ) <nl> + sc = Parameter ( dim , 1 , init = uniform , initValueScale = scaleInit ) <nl> + b = Parameter ( dim , 1 , init = uniform , initValueScale = biasInit ) <nl> bn_norm = Plus ( ColumnElementTimes ( norm , sc ) , b ) <nl> - } <nl> \ No newline at end of file <nl> + ] <nl> mmm a / Tests / Image / QuickE2E / cntk . config <nl> ppp b / Tests / Image / QuickE2E / cntk . config <nl> <nl> - precision = float <nl> - command = Train : Test <nl> - deviceId = $ DeviceId $ <nl> + precision = " float " <nl> + command = train : test <nl> + deviceId = $ DeviceId $ <nl> <nl> - ndlMacros = $ ConfigDir $ / Macros . ndl <nl> + ndlMacros = " $ ConfigDir $ / Macros . ndl " <nl> <nl> - parallelTrain = false <nl> - NumCPUThreads = 8 <nl> + parallelTrain = false <nl> + numCPUThreads = 8 <nl> <nl> - Train = [ <nl> - action = train <nl> - modelPath = $ RunDir $ / models / cntk . dnn <nl> - deviceId = $ DeviceId $ <nl> - traceLevel = 1 <nl> + train = [ <nl> + action = " train " <nl> + modelPath = " $ RunDir $ / models / cntk . dnn " <nl> + # deviceId = $ DeviceId $ <nl> + traceLevel = 1 <nl> <nl> - NDLNetworkBuilder = [ <nl> - networkDescription = $ ConfigDir $ / Convolution . ndl <nl> - ] <nl> + NDLNetworkBuilder = [ <nl> + networkDescription = " $ ConfigDir $ / Convolution . ndl " <nl> + ] <nl> <nl> - SGD = [ <nl> - epochSize = 100 <nl> - minibatchSize = 10 <nl> - learningRatesPerMB = 0 . 05 <nl> - momentumPerMB = 0 * 10 : 0 . 7 <nl> - maxEpochs = 12 <nl> + SGD = [ <nl> + epochSize = 100 <nl> + minibatchSize = 10 <nl> + learningRatesPerMB = 0 . 05 <nl> + momentumPerMB = 0 * 10 : 0 . 7 <nl> + maxEpochs = 12 <nl> ] <nl> <nl> - reader = [ <nl> - readerType = UCIFastReader <nl> - file = $ DataDir $ / Train . txt <nl> - features = [ <nl> - dim = 784 <nl> - start = 1 <nl> + reader = [ <nl> + readerType = " UCIFastReader " <nl> + file = " $ DataDir $ / Train . txt " <nl> + features = [ <nl> + dim = 784 <nl> + start = 1 <nl> ] <nl> - labels = [ <nl> - dim = 1 <nl> - start = 0 <nl> - labelDim = 10 <nl> - labelMappingFile = $ DataDir $ / labelsmap . txt <nl> + labels = [ <nl> + dim = 1 <nl> + start = 0 <nl> + labelDim = 10 <nl> + labelMappingFile = " $ DataDir $ / labelsmap . txt " <nl> ] <nl> ] <nl> ] <nl> <nl> - Test = [ <nl> - action = test <nl> - modelPath = $ RunDir $ / models / cntk . dnn <nl> + test = [ <nl> + action = " test " <nl> + modelPath = " $ RunDir $ / models / cntk . dnn " <nl> <nl> - NDLNetworkBuilder = [ <nl> - networkDescription = $ ConfigDir $ / Convolution . ndl <nl> + # TODO : there should be no need for a network builder upon testing <nl> + NDLNetworkBuilder = [ <nl> + networkDescription = " $ ConfigDir $ / Convolution . ndl " <nl> ] <nl> <nl> - reader = [ <nl> - readerType = UCIFastReader <nl> - file = $ DataDir $ / Test . txt <nl> - features = [ <nl> - dim = 784 <nl> - start = 1 <nl> + reader = [ <nl> + readerType = " UCIFastReader " <nl> + file = " $ DataDir $ / Test . txt " <nl> + features = [ <nl> + dim = 784 <nl> + start = 1 <nl> ] <nl> - labels = [ <nl> - dim = 1 <nl> - start = 0 <nl> - labelDim = 10 <nl> - labelMappingFile = $ DataDir $ / labelsmap . txt <nl> + labels = [ <nl> + dim = 1 <nl> + start = 0 <nl> + labelDim = 10 <nl> + labelMappingFile = " $ DataDir $ / labelsmap . txt " <nl> ] <nl> ] <nl> ] <nl> mmm a / Tests / ParallelTraining / SimpleMultiGPU . config <nl> ppp b / Tests / ParallelTraining / SimpleMultiGPU . config <nl> <nl> deviceId = $ DeviceId $ <nl> - command = simpleMultiGPU <nl> + command = SimpleMultiGPU <nl> precision = " float " <nl> <nl> parallelTrain = true <nl> <nl> - simpleMultiGPU = [ <nl> + # TODO : This name should be lowercase ( cameCase ) , but that will break the reference filename in Jenkins on Linux <nl> + SimpleMultiGPU = [ <nl> action = " train " <nl> modelPath = " $ RunDir $ / models / Simple . dnn " <nl> # deviceId = $ DeviceId $ <nl> mmm a / Tests / Speech / DNN / DiscriminativePreTraining / macros . txt <nl> ppp b / Tests / Speech / DNN / DiscriminativePreTraining / macros . txt <nl> DNNLastLayer ( hiddenDim , LabelDim , x ) = [ <nl> # W = Parameter ( LabelDim , hiddenDim , init = uniform , initValueScale = 1 , initOnCPUOnly = true , randomSeed = 1 ) ; <nl> # b = Parameter ( LabelDim , 1 , init = uniform , initValueScale = 1 , initOnCPUOnly = true , randomSeed = 1 ) ; <nl> W = Parameter ( LabelDim , hiddenDim ) ; <nl> - b = Parameter ( LabelDim 1 , ) ; <nl> + b = Parameter ( LabelDim , 1 ) ; <nl> t = Times ( W , x ) ; <nl> z = Plus ( t , b ) ; <nl> ] <nl>
added Image Jenkins tests to VS solution and did the same edits as last commit to it
microsoft/CNTK
4031c04f97b7d30cf99e4c421df915b21458ffdb
2015-11-27T06:38:07Z
mmm a / bindings / csharp / Swig / cntk_cs . i <nl> ppp b / bindings / csharp / Swig / cntk_cs . i <nl> SWIG_STD_VECTOR_ENHANCED ( CNTK : : DeviceDescriptor ) <nl> } <nl> } <nl> <nl> - / / Todo : do we have a better place to put this function ? <nl> - public static Function Combine ( System . Collections . Generic . IEnumerable < Variable > outputVariables ) <nl> + public static Function Combine ( System . Collections . Generic . IEnumerable < Variable > operands ) <nl> { <nl> var varVect = new VariableVector ( ) ; <nl> - foreach ( var v in outputVariables ) <nl> + foreach ( var v in operands ) <nl> { <nl> varVect . Add ( v ) ; <nl> } <nl> SWIG_STD_VECTOR_ENHANCED ( CNTK : : DeviceDescriptor ) <nl> } <nl> % } <nl> <nl> - <nl> % include " CNTKLibraryInternals . h " <nl> % include " CNTKLibrary . h " <nl> <nl>
change parameter name to aligned with C + + API
microsoft/CNTK
820ff81a733f978129856c020a6da8d9151b3b24
2017-04-05T09:24:03Z
mmm a / src / mongo / db / repl / oplog_entry . cpp <nl> ppp b / src / mongo / db / repl / oplog_entry . cpp <nl> OplogEntry : : OplogEntry ( OpTime opTime , <nl> NamespaceString nss , <nl> int version , <nl> const BSONObj & oField , <nl> - const BSONObj & o2Field ) { <nl> + const boost : : optional < BSONObj > & o2Field ) { <nl> setTimestamp ( opTime . getTimestamp ( ) ) ; <nl> setTerm ( opTime . getTerm ( ) ) ; <nl> setHash ( hash ) ; <nl> OplogEntry : : OplogEntry ( OpTime opTime , <nl> setNamespace ( nss ) ; <nl> setVersion ( version ) ; <nl> setObject ( oField ) ; <nl> - setObject2 ( o2Field ) ; <nl> + if ( o2Field ) { <nl> + setObject2 ( o2Field ) ; <nl> + } <nl> <nl> / / This is necessary until we remove ` raw ` in SERVER - 29200 . <nl> raw = toBSON ( ) ; <nl> OplogEntry : : OplogEntry ( OpTime opTime , <nl> NamespaceString nss , <nl> int version , <nl> const BSONObj & oField ) <nl> - : OplogEntry ( opTime , hash , opType , nss , version , oField , BSONObj ( ) ) { } <nl> + : OplogEntry ( opTime , hash , opType , nss , version , oField , boost : : none ) { } <nl> <nl> OplogEntry : : OplogEntry ( <nl> OpTime opTime , long long hash , OpTypeEnum opType , NamespaceString nss , const BSONObj & oField ) <nl> - : OplogEntry ( opTime , hash , opType , nss , OplogEntry : : kOplogVersion , oField , BSONObj ( ) ) { } <nl> + : OplogEntry ( opTime , hash , opType , nss , OplogEntry : : kOplogVersion , oField , boost : : none ) { } <nl> <nl> OplogEntry : : OplogEntry ( OpTime opTime , <nl> long long hash , <nl> OpTypeEnum opType , <nl> NamespaceString nss , <nl> const BSONObj & oField , <nl> - const BSONObj & o2Field ) <nl> + const boost : : optional < BSONObj > & o2Field ) <nl> : OplogEntry ( opTime , hash , opType , nss , OplogEntry : : kOplogVersion , oField , o2Field ) { } <nl> <nl> bool OplogEntry : : isCommand ( ) const { <nl> mmm a / src / mongo / db / repl / oplog_entry . h <nl> ppp b / src / mongo / db / repl / oplog_entry . h <nl> class OplogEntry : public OplogEntryBase { <nl> NamespaceString nss , <nl> int version , <nl> const BSONObj & oField , <nl> - const BSONObj & o2Field ) ; <nl> + const boost : : optional < BSONObj > & o2Field ) ; <nl> OplogEntry ( OpTime opTime , <nl> long long hash , <nl> OpTypeEnum opType , <nl> class OplogEntry : public OplogEntryBase { <nl> OpTypeEnum opType , <nl> NamespaceString nss , <nl> const BSONObj & oField , <nl> - const BSONObj & o2Field ) ; <nl> + const boost : : optional < BSONObj > & o2Field ) ; <nl> <nl> / / DEPRECATED : This constructor can throw . Use static parse method instead . <nl> explicit OplogEntry ( BSONObj raw ) ; <nl> mmm a / src / mongo / db / s / session_catalog_migration_destination . cpp <nl> ppp b / src / mongo / db / s / session_catalog_migration_destination . cpp <nl> repl : : OplogEntry parseOplog ( const BSONObj & oplogBSON ) { <nl> < < redact ( oplogBSON ) , <nl> oplogEntry . getStatementId ( ) ) ; <nl> <nl> - uassert ( ErrorCodes : : UnsupportedFormat , <nl> - str : : stream ( ) < < " oplog with opTime " < < oplogEntry . getTimestamp ( ) . toString ( ) <nl> - < < " does not have o2 : " <nl> - < < redact ( oplogBSON ) , <nl> - oplogEntry . getObject2 ( ) ) ; <nl> - <nl> return oplogEntry ; <nl> } <nl> <nl> ProcessOplogResult processSessionOplog ( OperationContext * opCtx , <nl> / / findAndModify operation . In this case , o field contains the relevant info <nl> / / and o2 will be empty . <nl> <nl> - object2 = oplogEntry . getObject2 ( ) . value ( ) ; <nl> + if ( oplogEntry . getObject2 ( ) ) { <nl> + object2 = * oplogEntry . getObject2 ( ) ; <nl> + } <nl> <nl> if ( object2 . isEmpty ( ) ) { <nl> result . isPrePostImage = true ; <nl> mmm a / src / mongo / db / s / session_catalog_migration_destination_test . cpp <nl> ppp b / src / mongo / db / s / session_catalog_migration_destination_test . cpp <nl> class SessionCatalogMigrationDestinationTest : public ShardingMongodTestFixture <nl> auto innerOplog = extractInnerOplog ( oplogToCheck ) ; <nl> ASSERT_TRUE ( innerOplog . getOpType ( ) = = originalOplog . getOpType ( ) ) ; <nl> ASSERT_BSONOBJ_EQ ( originalOplog . getObject ( ) , innerOplog . getObject ( ) ) ; <nl> - ASSERT_BSONOBJ_EQ ( * originalOplog . getObject2 ( ) , * innerOplog . getObject2 ( ) ) ; <nl> + <nl> + if ( originalOplog . getObject2 ( ) ) { <nl> + ASSERT_TRUE ( innerOplog . getObject2 ( ) ) ; <nl> + ASSERT_BSONOBJ_EQ ( * originalOplog . getObject2 ( ) , * innerOplog . getObject2 ( ) ) ; <nl> + } else { <nl> + ASSERT_FALSE ( innerOplog . getObject2 ( ) ) ; <nl> + } <nl> } <nl> <nl> private : <nl>
SERVER - 30894 Make object2 an optional parameter for OplogEntry
mongodb/mongo
91ea095f495a2011a5c8edec6abbe921893340a9
2017-09-19T16:42:23Z
mmm a / stdlib / public / core / Codable . swift . gyb <nl> ppp b / stdlib / public / core / Codable . swift . gyb <nl> extension Array : Decodable where Element : Decodable { <nl> } <nl> } <nl> <nl> + extension ContiguousArray : Encodable where Element : Encodable { <nl> + / / / Encodes the elements of this contiguous array into the given encoder <nl> + / / / in an unkeyed container . <nl> + / / / <nl> + / / / This function throws an error if any values are invalid for the given <nl> + / / / encoder ' s format . <nl> + / / / <nl> + / / / - Parameter encoder : The encoder to write data to . <nl> + @ inlinable / / FIXME ( sil - serialize - all ) <nl> + public func encode ( to encoder : Encoder ) throws { <nl> + var container = encoder . unkeyedContainer ( ) <nl> + for element in self { <nl> + try container . encode ( element ) <nl> + } <nl> + } <nl> + } <nl> + <nl> + extension ContiguousArray : Decodable where Element : Decodable { <nl> + / / / Creates a new contiguous array by decoding from the given decoder . <nl> + / / / <nl> + / / / This initializer throws an error if reading from the decoder fails , or <nl> + / / / if the data read is corrupted or otherwise invalid . <nl> + / / / <nl> + / / / - Parameter decoder : The decoder to read data from . <nl> + @ inlinable / / FIXME ( sil - serialize - all ) <nl> + public init ( from decoder : Decoder ) throws { <nl> + self . init ( ) <nl> + var container = try decoder . unkeyedContainer ( ) <nl> + while ! container . isAtEnd { <nl> + let element = try container . decode ( Element . self ) <nl> + self . append ( element ) <nl> + } <nl> + } <nl> + } <nl> + <nl> extension Set : Encodable where Element : Encodable { <nl> / / / Encodes the elements of this set into the given encoder in an unkeyed <nl> / / / container . <nl>
[ SR - 7076 ] Make ContiguousArray Codable
apple/swift
300124460fe76b02d6b1bf23bea85712565938f6
2018-11-24T17:09:55Z
mmm a / CHANGELOG . md <nl> ppp b / CHANGELOG . md <nl> CHANGELOG <nl> <nl> Swift 5 . 0 <nl> mmmmmmmmm <nl> + <nl> + * Swift 3 mode has been removed . Supported values for the ` - swift - version ` <nl> + flag are ` 4 ` , ` 4 . 2 ` , and ` 5 ` . <nl> + <nl> + * [ SE - 0228 ] [ ] : <nl> + <nl> + String interpolation has been overhauled to improve its performance , <nl> + clarity , and efficiency . <nl> + <nl> + Note that the old ` _ExpressibleByStringInterpolation ` protocol has been <nl> + removed ; any code making use of this protocol will need to be updated <nl> + for the new design . An ` # if compiler ` block can be used to conditionalize <nl> + code between 4 . 2 and 5 . 0 , for example : <nl> + <nl> + ` ` ` swift <nl> + # if compiler ( < 5 . 0 ) <nl> + extension MyType : _ExpressibleByStringInterpolation { . . . } <nl> + # else <nl> + extension MyType : ExpressibleByStringInterpolation { . . . } <nl> + # endif <nl> + ` ` ` <nl> + <nl> + * [ SE - 0213 ] [ ] : <nl> + <nl> + If ` T ` conforms to one of the ` ExpressibleBy * ` protocols and ` literal ` is a <nl> + literal expression , then ` T ( literal ) ` will construct a literal of type ` T ` <nl> + using the corresponding protocol , rather than calling a constructor member <nl> + of ` T ` with a value of the protocol ' s default literal type . <nl> + <nl> + For example , expressions like ` UInt64 ( 0xffff_ffff_ffff_ffff ) ` are now valid , <nl> + where previously they would overflow the default integer literal type of ` Int ` . <nl> + <nl> + * [ SE - 0230 ] [ ] : <nl> + <nl> + In Swift 5 mode , ` try ? ` with an expression of Optional type will flatten the <nl> + resulting Optional , instead of returning an Optional of an Optional . <nl> + <nl> * [ SR - 5719 ] [ ] : <nl> <nl> - Starting from ` - swift - version 5 ` , implicit ` @ autoclosure ` function type <nl> - forwarding has been disabled , and new a diagnostic has been added suggesting <nl> - to add ` ( ) ` to call the function value in such case . The call itself would be <nl> - wrapped in an implicit closure and passed to the corresponding parameter . <nl> + In Swift 5 mode , ` @ autoclosure ` parameters can no longer be forwarded to <nl> + ` @ autoclosure ` arguments in another function call . Instead , you must explicitly <nl> + call the function value with ` ( ) ` ; the call itself is wrapped inside an <nl> + implicit closure , guaranteeing the same behavior as in Swift 4 mode . <nl> <nl> Example : <nl> <nl> Swift 5 . 0 <nl> } <nl> ` ` ` <nl> <nl> + * [ SR - 8109 ] [ ] : <nl> + <nl> + Single - element labeled tuple expressions , for example ` ( label : 123 ) ` , were <nl> + allowed in some contexts but often resulted in surprising , inconsistent <nl> + behavior that varied across compiler releases . They are now completely <nl> + disallowed . <nl> + <nl> + Note that single - element labeled _types_ , for example ` var x : ( label : Int ) ` , <nl> + have already been prohibited since Swift 3 . <nl> + <nl> + * [ SR - 695 ] [ ] : <nl> + <nl> + In Swift 5 mode , a class method returning ` Self ` can no longer be overridden <nl> + with a method returning a non - final concrete class type . Such code is not <nl> + type safe and will need to be updated . <nl> + <nl> + For example , <nl> + <nl> + ` ` ` swift <nl> + class Base { <nl> + class func factory ( ) - > Self { . . . } <nl> + } <nl> + <nl> + class Derived : Base { <nl> + class override func factory ( ) - > Derived { . . . } <nl> + } <nl> + ` ` ` <nl> + <nl> + * In Swift 5 mode , the type of ` self ` in a convenience initializer of a non - final <nl> + class is now the dynamic ` Self ` type , and not the concrete class type . <nl> + <nl> + * [ SR - 5581 ] [ ] : <nl> + <nl> + Protocols can now constrain their conforming types to those that subclasses a <nl> + given class . Two equivalent forms are supported : <nl> + <nl> + ` ` ` swift <nl> + protocol MyView : UIView { . . . } <nl> + protocol MyView where Self : UIView { . . . } <nl> + ` ` ` <nl> + <nl> + Note that Swift 4 . 2 accepted the second form , but it was not fully implemented <nl> + and could sometimes crash at compile time or run time . <nl> + <nl> + * [ SR - 631 ] [ ] : <nl> + <nl> + Extension binding now supports extensions of nested types which themselves are <nl> + defined inside extensions . Previously this could fail with some declaration orders , <nl> + producing spurious " undeclared type " errors . <nl> + <nl> * [ SR - 7139 ] [ ] : <nl> <nl> Exclusive memory access is now enforced at runtime by default in <nl> Swift 5 . 0 <nl> <nl> * [ SE - 0214 ] [ ] : <nl> <nl> - Renamed the ` DictionaryLiteral ` type to ` KeyValuePairs ` . <nl> + The ` DictionaryLiteral ` type has been renamed to ` KeyValuePairs ` . <nl> A typealias preserves the old name for compatibility . <nl> <nl> * [ SR - 2608 ] [ ] <nl> Swift 5 . 0 <nl> Default arguments are now printed in SourceKit - generated interfaces for Swift <nl> modules , instead of just using a placeholder ` default ` . <nl> <nl> - * Notable bug fix : unowned and unowned ( unsafe ) variables now support optional <nl> - types . <nl> + * ` unowned ` and ` unowned ( unsafe ) ` variables now support Optional types . <nl> + <nl> + * Designated initializers with variadic parameters are now correctly inherited <nl> + in subclasses . <nl> + <nl> + * Extensions of concrete subclasses of generic classes can now contain <nl> + ` @ objc ` members . <nl> + <nl> + * Complex recursive type definitions involving classes and generics that would <nl> + previously cause deadlocks at run time are now fully supported . <nl> <nl> * [ SR - 419 ] [ ] <nl> <nl> Swift 1 . 0 <nl> [ SE - 0225 ] : < https : / / github . com / apple / swift - evolution / blob / master / proposals / 0225 - binaryinteger - iseven - isodd - ismultiple . md > <nl> [ SE - 0226 ] : < https : / / github . com / apple / swift - evolution / blob / master / proposals / 0226 - package - manager - target - based - dep - resolution . md > <nl> [ SE - 0227 ] : < https : / / github . com / apple / swift - evolution / blob / master / proposals / 0227 - identity - keypath . md > <nl> + [ SE - 0228 ] : < https : / / github . com / apple / swift - evolution / blob / master / proposals / 0228 - fix - expressiblebystringinterpolation . md > <nl> + [ SE - 0230 ] : < https : / / github . com / apple / swift - evolution / blob / master / proposals / 0230 - flatten - optional - try . md > <nl> <nl> [ SR - 106 ] : < https : / / bugs . swift . org / browse / SR - 106 > <nl> [ SR - 419 ] : < https : / / bugs . swift . org / browse / SR - 419 > <nl> + [ SR - 631 ] : < https : / / bugs . swift . org / browse / SR - 631 > <nl> + [ SR - 695 ] : < https : / / bugs . swift . org / browse / SR - 695 > <nl> [ SR - 1009 ] : < https : / / bugs . swift . org / browse / SR - 1009 > <nl> [ SR - 1446 ] : < https : / / bugs . swift . org / browse / SR - 1446 > <nl> [ SR - 1529 ] : < https : / / bugs . swift . org / browse / SR - 1529 > <nl> Swift 1 . 0 <nl> [ SR - 2394 ] : < https : / / bugs . swift . org / browse / SR - 2394 > <nl> [ SR - 2608 ] : < https : / / bugs . swift . org / browse / SR - 2608 > <nl> [ SR - 4248 ] : < https : / / bugs . swift . org / browse / SR - 4248 > <nl> + [ SR - 5581 ] : < https : / / bugs . swift . org / browse / SR - 5581 > <nl> + [ SR - 5719 ] : < https : / / bugs . swift . org / browse / SR - 5719 > <nl> [ SR - 7139 ] : < https : / / bugs . swift . org / browse / SR - 7139 > <nl> [ SR - 7251 ] : < https : / / bugs . swift . org / browse / SR - 7251 > <nl> - [ SR - 5719 ] : < https : / / bugs . swift . org / browse / SR - 5719 > <nl> + [ SR - 8109 ] : < https : / / bugs . swift . org / browse / SR - 8109 > <nl>
Merge remote - tracking branch ' origin / master ' into master - next
apple/swift
f27f2517c2d125580299d58691f67ef1f0808d74
2018-12-18T01:50:02Z
mmm a / tensorflow / core / kernels / BUILD <nl> ppp b / tensorflow / core / kernels / BUILD <nl> filegroup ( <nl> " conv_2d . h " , <nl> " image_resizer_state . h " , <nl> " maxpooling_op . h " , <nl> + " pad_op . h " , <nl> " reduction_ops . h " , <nl> " reduction_ops_common . h " , <nl> " relu_op . h " , <nl> filegroup ( <nl> " in_topk_op . cc " , <nl> " lrn_op . cc " , <nl> " maxpooling_op . cc " , <nl> + " pad_op . cc " , <nl> " reduction_ops_common . cc " , <nl> " reduction_ops_max . cc " , <nl> " reduction_ops_mean . cc " , <nl> mmm a / tensorflow / python / tools / BUILD <nl> ppp b / tensorflow / python / tools / BUILD <nl> py_binary ( <nl> ] , <nl> ) <nl> <nl> + py_library ( <nl> + name = " strip_unused_lib " , <nl> + srcs = [ " strip_unused . py " ] , <nl> + srcs_version = " PY2AND3 " , <nl> + deps = [ <nl> + " / / tensorflow : tensorflow_py " , <nl> + " / / tensorflow / python : platform " , <nl> + ] , <nl> + ) <nl> + <nl> + py_binary ( <nl> + name = " strip_unused " , <nl> + srcs = [ " strip_unused . py " ] , <nl> + srcs_version = " PY2AND3 " , <nl> + deps = [ <nl> + " / / tensorflow : tensorflow_py " , <nl> + " / / tensorflow / python : platform " , <nl> + ] , <nl> + ) <nl> + <nl> + py_test ( <nl> + name = " strip_unused_test " , <nl> + size = " small " , <nl> + srcs = [ <nl> + " strip_unused_test . py " , <nl> + ] , <nl> + srcs_version = " PY2AND3 " , <nl> + deps = [ <nl> + " : strip_unused " , <nl> + " / / tensorflow / python : framework_test_lib " , <nl> + " / / tensorflow / python : platform_test " , <nl> + ] , <nl> + ) <nl> + <nl> filegroup ( <nl> name = " all_files " , <nl> srcs = glob ( <nl> new file mode 100644 <nl> index 0000000000000 . . dc7e0ca96a172 <nl> mmm / dev / null <nl> ppp b / tensorflow / python / tools / strip_unused . py <nl> <nl> + # Copyright 2015 Google Inc . All Rights Reserved . <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> + r " " " Removes unneeded nodes from a GraphDef file . <nl> + <nl> + This script is designed to help streamline models , by taking the input and <nl> + output nodes that will be used by an application and figuring out the smallest <nl> + set of operations that are required to run for those arguments . The resulting <nl> + minimal graph is then saved out . <nl> + <nl> + The advantages of running this script are : <nl> + - You may be able to shrink the file size . <nl> + - Operations that are unsupported on your platform but still present can be <nl> + safely removed . <nl> + The resulting graph may not be as flexible as the original though , since any <nl> + input nodes that weren ' t explicitly mentioned may not be accessible any more . <nl> + <nl> + An example of command - line usage is : <nl> + bazel build tensorflow / python / tools : strip_unused & & \ <nl> + bazel - bin / tensorflow / python / tools / strip_unused \ <nl> + - - input_graph = some_graph_def . pb \ <nl> + - - output_graph = / tmp / stripped_graph . pb \ <nl> + - - input_node_names = input0 <nl> + - - output_node_names = softmax <nl> + <nl> + You can also look at strip_unused_test . py for an example of how to use it . <nl> + <nl> + " " " <nl> + from __future__ import absolute_import <nl> + from __future__ import division <nl> + from __future__ import print_function <nl> + import copy <nl> + <nl> + import tensorflow as tf <nl> + <nl> + from google . protobuf import text_format <nl> + from tensorflow . python . client import graph_util <nl> + <nl> + <nl> + FLAGS = tf . app . flags . FLAGS <nl> + <nl> + tf . app . flags . DEFINE_string ( " input_graph " , " " , <nl> + " " " TensorFlow ' GraphDef ' file to load . " " " ) <nl> + tf . app . flags . DEFINE_boolean ( " input_binary " , False , <nl> + " " " Whether the input files are in binary format . " " " ) <nl> + tf . app . flags . DEFINE_string ( " output_graph " , " " , <nl> + " " " Output ' GraphDef ' file name . " " " ) <nl> + tf . app . flags . DEFINE_string ( " input_node_names " , " " , <nl> + " " " The name of the output nodes , comma separated . " " " ) <nl> + tf . app . flags . DEFINE_string ( " output_node_names " , " " , <nl> + " " " The name of the output nodes , comma separated . " " " ) <nl> + tf . app . flags . DEFINE_integer ( " placeholder_type_enum " , <nl> + tf . float32 . as_datatype_enum , <nl> + " " " The AttrValue enum to use for placeholders . " " " ) <nl> + <nl> + <nl> + def strip_unused ( input_graph , input_binary , output_graph , input_node_names , <nl> + output_node_names , placeholder_type_enum ) : <nl> + " " " Removes unused nodes from a graph . " " " <nl> + <nl> + if not tf . gfile . Exists ( input_graph ) : <nl> + print ( " Input graph file ' " + input_graph + " ' does not exist ! " ) <nl> + return - 1 <nl> + <nl> + if not output_node_names : <nl> + print ( " You need to supply the name of a node to - - output_node_names . " ) <nl> + return - 1 <nl> + <nl> + input_graph_def = tf . GraphDef ( ) <nl> + mode = " rb " if input_binary else " r " <nl> + with tf . gfile . FastGFile ( input_graph , mode ) as f : <nl> + if input_binary : <nl> + input_graph_def . ParseFromString ( f . read ( ) ) <nl> + else : <nl> + text_format . Merge ( f . read ( ) , input_graph_def ) <nl> + <nl> + # Here we replace the nodes we ' re going to override as inputs with <nl> + # placeholders so that any unused nodes that are inputs to them are <nl> + # automatically stripped out by extract_sub_graph ( ) . <nl> + input_node_names_list = input_node_names . split ( " , " ) <nl> + inputs_replaced_graph_def = tf . GraphDef ( ) <nl> + for node in input_graph_def . node : <nl> + if node . name in input_node_names_list : <nl> + placeholder_node = tf . NodeDef ( ) <nl> + placeholder_node . op = " Placeholder " <nl> + placeholder_node . name = node . name <nl> + placeholder_node . attr [ " dtype " ] . CopyFrom ( tf . AttrValue ( <nl> + type = placeholder_type_enum ) ) <nl> + inputs_replaced_graph_def . node . extend ( [ placeholder_node ] ) <nl> + else : <nl> + inputs_replaced_graph_def . node . extend ( [ copy . deepcopy ( node ) ] ) <nl> + <nl> + output_graph_def = graph_util . extract_sub_graph ( inputs_replaced_graph_def , <nl> + output_node_names . split ( " , " ) ) <nl> + <nl> + with tf . gfile . GFile ( output_graph , " wb " ) as f : <nl> + f . write ( output_graph_def . SerializeToString ( ) ) <nl> + print ( " % d ops in the final graph . " % len ( output_graph_def . node ) ) <nl> + <nl> + <nl> + def main ( unused_args ) : <nl> + strip_unused ( FLAGS . input_graph , FLAGS . input_binary , FLAGS . output_graph , <nl> + FLAGS . input_node_names , FLAGS . output_node_names , <nl> + FLAGS . placeholder_type_enum ) <nl> + <nl> + if __name__ = = " __main__ " : <nl> + tf . app . run ( ) <nl> new file mode 100644 <nl> index 0000000000000 . . c79024261ce4b <nl> mmm / dev / null <nl> ppp b / tensorflow / python / tools / strip_unused_test . py <nl> <nl> + # Copyright 2015 Google Inc . All Rights Reserved . <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> + " " " Tests the graph freezing tool . " " " <nl> + from __future__ import absolute_import <nl> + from __future__ import division <nl> + from __future__ import print_function <nl> + <nl> + import os <nl> + <nl> + import tensorflow as tf <nl> + <nl> + from tensorflow . python . framework import test_util <nl> + from tensorflow . python . tools import strip_unused <nl> + <nl> + <nl> + class FreezeGraphTest ( test_util . TensorFlowTestCase ) : <nl> + <nl> + def testFreezeGraph ( self ) : <nl> + input_graph_name = " input_graph . pb " <nl> + output_graph_name = " output_graph . pb " <nl> + <nl> + # We ' ll create an input graph that has a single constant containing 1 . 0 , <nl> + # and that then multiplies it by 2 . <nl> + with tf . Graph ( ) . as_default ( ) : <nl> + constant_node = tf . constant ( 1 . 0 , name = " constant_node " ) <nl> + wanted_input_node = tf . sub ( constant_node , 3 . 0 , name = " wanted_input_node " ) <nl> + output_node = tf . mul ( wanted_input_node , 2 . 0 , name = " output_node " ) <nl> + tf . add ( output_node , 2 . 0 , name = " later_node " ) <nl> + sess = tf . Session ( ) <nl> + output = sess . run ( output_node ) <nl> + self . assertNear ( - 4 . 0 , output , 0 . 00001 ) <nl> + tf . train . write_graph ( sess . graph . as_graph_def ( ) , self . get_temp_dir ( ) , <nl> + input_graph_name ) <nl> + <nl> + # We save out the graph to disk , and then call the const conversion <nl> + # routine . <nl> + input_graph_path = os . path . join ( self . get_temp_dir ( ) , input_graph_name ) <nl> + input_binary = False <nl> + input_node_names = " wanted_input_node " <nl> + output_node_names = " output_node " <nl> + output_graph_path = os . path . join ( self . get_temp_dir ( ) , output_graph_name ) <nl> + <nl> + strip_unused . strip_unused ( input_graph_path , input_binary , output_graph_path , <nl> + input_node_names , output_node_names , <nl> + tf . float32 . as_datatype_enum ) <nl> + <nl> + # Now we make sure the variable is now a constant , and that the graph still <nl> + # produces the expected result . <nl> + with tf . Graph ( ) . as_default ( ) : <nl> + output_graph_def = tf . GraphDef ( ) <nl> + with open ( output_graph_path , " rb " ) as f : <nl> + output_graph_def . ParseFromString ( f . read ( ) ) <nl> + _ = tf . import_graph_def ( output_graph_def , name = " " ) <nl> + <nl> + self . assertEqual ( 3 , len ( output_graph_def . node ) ) <nl> + for node in output_graph_def . node : <nl> + self . assertNotEqual ( " Add " , node . op ) <nl> + self . assertNotEqual ( " Sub " , node . op ) <nl> + <nl> + with tf . Session ( ) as sess : <nl> + input_node = sess . graph . get_tensor_by_name ( " wanted_input_node : 0 " ) <nl> + output_node = sess . graph . get_tensor_by_name ( " output_node : 0 " ) <nl> + output = sess . run ( output_node , feed_dict = { input_node : [ 10 . 0 ] } ) <nl> + self . assertNear ( 20 . 0 , output , 0 . 00001 ) <nl> + <nl> + if __name__ = = " __main__ " : <nl> + tf . test . main ( ) <nl> mmm a / tensorflow / tools / benchmark / BUILD <nl> ppp b / tensorflow / tools / benchmark / BUILD <nl> package ( default_visibility = [ " / / visibility : public " ] ) <nl> <nl> licenses ( [ " notice " ] ) # Apache 2 . 0 <nl> <nl> - load ( " / / tensorflow : tensorflow . bzl " , " tf_copts " ) <nl> + load ( <nl> + " / / tensorflow : tensorflow . bzl " , <nl> + " tf_copts " , <nl> + " tf_cc_test " , <nl> + ) <nl> <nl> exports_files ( [ " LICENSE " ] ) <nl> <nl> cc_library ( <nl> srcs = [ <nl> " benchmark_model . cc " , <nl> ] , <nl> + hdrs = [ <nl> + " benchmark_model . h " , <nl> + ] , <nl> copts = tf_copts ( ) , <nl> visibility = [ " / / visibility : public " ] , <nl> deps = select ( { <nl> cc_library ( <nl> } ) , <nl> ) <nl> <nl> + tf_cc_test ( <nl> + name = " benchmark_model_test " , <nl> + size = " medium " , <nl> + deps = [ <nl> + " : benchmark_model_lib " , <nl> + " / / tensorflow / cc : cc_ops " , <nl> + " / / tensorflow / core : core_cpu " , <nl> + " / / tensorflow / core : framework " , <nl> + " / / tensorflow / core : lib " , <nl> + " / / tensorflow / core : test " , <nl> + " / / tensorflow / core : test_main " , <nl> + " / / tensorflow / core : testlib " , <nl> + ] , <nl> + ) <nl> + <nl> # This binary may be built for either desktop or Android . <nl> # A typical Android build command will look like the following : <nl> # bazel build - c opt tensorflow / core : android_tensorflow_lib \ <nl> cc_library ( <nl> # uses . <nl> cc_binary ( <nl> name = " benchmark_model " , <nl> + srcs = [ " benchmark_model_main . cc " ] , <nl> copts = tf_copts ( ) , <nl> linkopts = select ( { <nl> " / / tensorflow : android " : [ <nl> mmm a / tensorflow / tools / benchmark / benchmark_model . cc <nl> ppp b / tensorflow / tools / benchmark / benchmark_model . cc <nl> limitations under the License . <nl> / / <nl> / / See README . md for usage instructions . <nl> <nl> + # include " tensorflow / tools / benchmark / benchmark_model . h " <nl> + <nl> # include < cstdlib > <nl> # include < memory > <nl> # include < string > <nl> limitations under the License . <nl> # include " tensorflow / core / util / stat_summarizer . h " <nl> <nl> namespace tensorflow { <nl> + namespace benchmark_model { <nl> <nl> - / / Global variables that holds the Tensorflow classifier . <nl> - static std : : unique_ptr < tensorflow : : Session > session ; <nl> - <nl> - static std : : unique_ptr < tensorflow : : StatSummarizer > g_stats ; <nl> - <nl> - struct Flags { <nl> - string graph = " / data / local / tmp / tensorflow_inception_graph . pb " ; <nl> - string input_layer = " input : 0 " ; <nl> - string input_layer_shape = " 1 , 224 , 224 , 3 " ; <nl> - string input_layer_type = " float " ; <nl> - string output_layer = " output : 0 " ; <nl> - int num_runs = 50 ; <nl> - string run_delay = " - 1 . 0 " ; <nl> - int num_threads = - 1 ; <nl> - } ; <nl> - <nl> - static Flags * flags ; / / Filled in by main ( ) <nl> - <nl> - static bool InitializeBenchmark ( ) { <nl> + Status InitializeSession ( int num_threads , const string & graph , <nl> + std : : unique_ptr < Session > * session , <nl> + std : : unique_ptr < StatSummarizer > * stats ) { <nl> LOG ( INFO ) < < " Loading Tensorflow . " ; <nl> <nl> tensorflow : : SessionOptions options ; <nl> tensorflow : : ConfigProto & config = options . config ; <nl> - if ( flags - > num_threads > 0 ) { <nl> - config . set_intra_op_parallelism_threads ( flags - > num_threads ) ; <nl> + if ( num_threads > 0 ) { <nl> + config . set_intra_op_parallelism_threads ( num_threads ) ; <nl> } <nl> LOG ( INFO ) < < " Got config , " < < config . device_count_size ( ) < < " devices " ; <nl> <nl> - session . reset ( tensorflow : : NewSession ( options ) ) ; <nl> + session - > reset ( tensorflow : : NewSession ( options ) ) ; <nl> tensorflow : : GraphDef tensorflow_graph ; <nl> - Status s = ReadBinaryProto ( Env : : Default ( ) , flags - > graph , & tensorflow_graph ) ; <nl> + Status s = ReadBinaryProto ( Env : : Default ( ) , graph , & tensorflow_graph ) ; <nl> if ( ! s . ok ( ) ) { <nl> LOG ( ERROR ) < < " Could not create Tensorflow Graph : " < < s ; <nl> - return false ; <nl> + return s ; <nl> } <nl> <nl> - g_stats . reset ( new tensorflow : : StatSummarizer ( tensorflow_graph ) ) ; <nl> + stats - > reset ( new tensorflow : : StatSummarizer ( tensorflow_graph ) ) ; <nl> <nl> - s = session - > Create ( tensorflow_graph ) ; <nl> + s = ( * session ) - > Create ( tensorflow_graph ) ; <nl> if ( ! s . ok ( ) ) { <nl> LOG ( ERROR ) < < " Could not create Tensorflow Session : " < < s ; <nl> - return false ; <nl> + return s ; <nl> } <nl> <nl> / / Clear the proto to save memory space . <nl> tensorflow_graph . Clear ( ) ; <nl> - return true ; <nl> + return Status : : OK ( ) ; <nl> } <nl> <nl> - static bool RunBenchmark ( ) { <nl> - DataType input_data_type ; <nl> - CHECK ( DataTypeFromString ( flags - > input_layer_type , & input_data_type ) ) <nl> - < < flags - > input_layer_type < < " was an invalid type " ; <nl> - <nl> - std : : vector < int32 > sizes ; <nl> - CHECK ( str_util : : SplitAndParseAsInts ( flags - > input_layer_shape , ' , ' , & sizes ) ) <nl> - < < " Incorrect size string specified : " < < flags - > input_layer_shape ; <nl> - TensorShape input_shape ; <nl> - for ( int i = 0 ; i < sizes . size ( ) ; + + i ) { <nl> - input_shape . AddDim ( sizes [ i ] ) ; <nl> - } <nl> - <nl> + Status RunBenchmark ( DataType input_data_type , TensorShape input_shape , <nl> + const string & input_layer , const string output_layer , <nl> + Session * session , StatSummarizer * stats ) { <nl> Tensor input_tensor ( input_data_type , input_shape ) ; <nl> <nl> switch ( input_data_type ) { <nl> static bool RunBenchmark ( ) { <nl> break ; <nl> } <nl> default : <nl> - LOG ( FATAL ) < < " Unsupported input type : " < < flags - > input_layer_type ; <nl> + LOG ( FATAL ) < < " Unsupported input type : " < < input_data_type ; <nl> } <nl> <nl> std : : vector < std : : pair < string , tensorflow : : Tensor > > input_tensors ( <nl> - { { flags - > input_layer , input_tensor } } ) ; <nl> + { { input_layer , input_tensor } } ) ; <nl> <nl> std : : vector < tensorflow : : Tensor > output_tensors ; <nl> - std : : vector < string > output_names ( { flags - > output_layer } ) ; <nl> + std : : vector < string > output_names ( { output_layer } ) ; <nl> <nl> tensorflow : : Status s ; <nl> <nl> static bool RunBenchmark ( ) { <nl> <nl> assert ( run_metadata . has_step_stats ( ) ) ; <nl> <nl> - const StepStats & stats = run_metadata . step_stats ( ) ; <nl> + const StepStats & step_stats = run_metadata . step_stats ( ) ; <nl> <nl> - g_stats - > ProcessStepStats ( stats ) ; <nl> + stats - > ProcessStepStats ( step_stats ) ; <nl> <nl> if ( ! s . ok ( ) ) { <nl> LOG ( ERROR ) < < " Error during inference : " < < s ; <nl> - return false ; <nl> } <nl> - return true ; <nl> + return s ; <nl> } <nl> <nl> - } / / namespace tensorflow <nl> + Status TimeMultipleRuns ( double sleep_seconds , int num_runs , <nl> + DataType input_data_type , TensorShape input_shape , <nl> + const string & input_layer , const string output_layer , <nl> + Session * session , StatSummarizer * stats ) { <nl> + / / Convert the run_delay string into a timespec . <nl> + timespec req ; <nl> + req . tv_sec = static_cast < time_t > ( sleep_seconds ) ; <nl> + req . tv_nsec = ( sleep_seconds - req . tv_sec ) * 1000000000 ; <nl> + <nl> + LOG ( INFO ) < < " Running benchmark " ; <nl> + for ( int i = 0 ; i < num_runs ; + + i ) { <nl> + Status run_status = RunBenchmark ( input_data_type , input_shape , input_layer , <nl> + output_layer , session , stats ) ; <nl> + if ( ! run_status . ok ( ) ) { <nl> + LOG ( INFO ) < < " Failed on run " < < i ; <nl> + return run_status ; <nl> + } <nl> + <nl> + / / If requested , sleep between runs for an arbitrary amount of time . <nl> + / / This can be helpful to determine the effect of mobile processor <nl> + / / scaling and thermal throttling . <nl> + if ( sleep_seconds > 0 . 0 ) { <nl> + nanosleep ( & req , nullptr ) ; <nl> + } <nl> + } <nl> <nl> - int main ( int argc , char * * argv ) { <nl> - tensorflow : : flags = new tensorflow : : Flags ( ) ; <nl> - <nl> - const bool parse_result = tensorflow : : ParseFlags ( <nl> - & argc , argv , <nl> - { <nl> - tensorflow : : Flag ( " graph " , & tensorflow : : flags - > graph ) , <nl> - tensorflow : : Flag ( " input_layer " , & tensorflow : : flags - > input_layer ) , <nl> - tensorflow : : Flag ( " input_layer_shape " , <nl> - & tensorflow : : flags - > input_layer_shape ) , <nl> - tensorflow : : Flag ( " input_layer_type " , <nl> - & tensorflow : : flags - > input_layer_type ) , <nl> - tensorflow : : Flag ( " output_layer " , & tensorflow : : flags - > output_layer ) , <nl> - tensorflow : : Flag ( " num_runs " , & tensorflow : : flags - > num_runs ) , <nl> - tensorflow : : Flag ( " run_delay " , & tensorflow : : flags - > run_delay ) , <nl> - tensorflow : : Flag ( " num_threads " , & tensorflow : : flags - > num_threads ) , <nl> - } ) ; <nl> + return Status : : OK ( ) ; <nl> + } <nl> + <nl> + int Main ( int argc , char * * argv ) { <nl> + string graph = " / data / local / tmp / tensorflow_inception_graph . pb " ; <nl> + string input_layer = " input : 0 " ; <nl> + string input_layer_shape = " 1 , 224 , 224 , 3 " ; <nl> + string input_layer_type = " float " ; <nl> + string output_layer = " output : 0 " ; <nl> + int num_runs = 50 ; <nl> + string run_delay = " - 1 . 0 " ; <nl> + int num_threads = - 1 ; <nl> + <nl> + const bool parse_result = ParseFlags ( <nl> + & argc , argv , { <nl> + Flag ( " graph " , & graph ) , / / <nl> + Flag ( " input_layer " , & input_layer ) , / / <nl> + Flag ( " input_layer_shape " , & input_layer_shape ) , / / <nl> + Flag ( " input_layer_type " , & input_layer_type ) , / / <nl> + Flag ( " output_layer " , & output_layer ) , / / <nl> + Flag ( " num_runs " , & num_runs ) , / / <nl> + Flag ( " run_delay " , & run_delay ) , / / <nl> + Flag ( " num_threads " , & num_threads ) , / / <nl> + } ) ; <nl> <nl> if ( ! parse_result ) { <nl> LOG ( ERROR ) < < " Error parsing command - line flags . " ; <nl> int main ( int argc , char * * argv ) { <nl> return - 1 ; <nl> } <nl> <nl> - LOG ( INFO ) < < " Graph : [ " < < tensorflow : : flags - > graph < < " ] " ; <nl> - LOG ( INFO ) < < " Input layer : [ " < < tensorflow : : flags - > input_layer < < " ] " ; <nl> - LOG ( INFO ) < < " Input shape : [ " < < tensorflow : : flags - > input_layer_shape < < " ] " ; <nl> - LOG ( INFO ) < < " Input type : [ " < < tensorflow : : flags - > input_layer_type < < " ] " ; <nl> - LOG ( INFO ) < < " Output layer : [ " < < tensorflow : : flags - > output_layer < < " ] " ; <nl> - LOG ( INFO ) < < " Num runs : [ " < < tensorflow : : flags - > num_runs < < " ] " ; <nl> - LOG ( INFO ) < < " Inter - run delay ( seconds ) : [ " < < tensorflow : : flags - > run_delay <nl> - < < " ] " ; <nl> - LOG ( INFO ) < < " Num threads : [ " < < tensorflow : : flags - > num_threads < < " ] " ; <nl> - <nl> - if ( ! tensorflow : : InitializeBenchmark ( ) ) { <nl> + LOG ( INFO ) < < " Graph : [ " < < graph < < " ] " ; <nl> + LOG ( INFO ) < < " Input layer : [ " < < input_layer < < " ] " ; <nl> + LOG ( INFO ) < < " Input shape : [ " < < input_layer_shape < < " ] " ; <nl> + LOG ( INFO ) < < " Input type : [ " < < input_layer_type < < " ] " ; <nl> + LOG ( INFO ) < < " Output layer : [ " < < output_layer < < " ] " ; <nl> + LOG ( INFO ) < < " Num runs : [ " < < num_runs < < " ] " ; <nl> + LOG ( INFO ) < < " Inter - run delay ( seconds ) : [ " < < run_delay < < " ] " ; <nl> + LOG ( INFO ) < < " Num threads : [ " < < num_threads < < " ] " ; <nl> + <nl> + std : : unique_ptr < Session > session ; <nl> + std : : unique_ptr < StatSummarizer > stats ; <nl> + Status initialize_status = <nl> + InitializeSession ( num_threads , graph , & session , & stats ) ; <nl> + if ( ! initialize_status . ok ( ) ) { <nl> return - 1 ; <nl> } <nl> <nl> - / / Convert the run_delay string into a timespec . <nl> - const double sleep_seconds = <nl> - std : : strtod ( tensorflow : : flags - > run_delay . c_str ( ) , nullptr ) ; <nl> - timespec req ; <nl> - req . tv_sec = static_cast < time_t > ( sleep_seconds ) ; <nl> - req . tv_nsec = ( sleep_seconds - req . tv_sec ) * 1000000000 ; <nl> - <nl> - LOG ( INFO ) < < " Running benchmark " ; <nl> - for ( int i = 0 ; i < tensorflow : : flags - > num_runs ; + + i ) { <nl> - if ( ! tensorflow : : RunBenchmark ( ) ) { <nl> - LOG ( INFO ) < < " Failed on run " < < i ; <nl> - return - 1 ; <nl> - } <nl> - <nl> - / / If requested , sleep between runs for an arbitrary amount of time . <nl> - / / This can be helpful to determine the effect of mobile processor <nl> - / / scaling and thermal throttling . <nl> - if ( sleep_seconds > 0 . 0 ) { <nl> - nanosleep ( & req , nullptr ) ; <nl> - } <nl> + const double sleep_seconds = std : : strtod ( run_delay . c_str ( ) , nullptr ) ; <nl> + DataType input_data_type ; <nl> + CHECK ( DataTypeFromString ( input_layer_type , & input_data_type ) ) <nl> + < < input_layer_type < < " was an invalid type " ; <nl> + std : : vector < int32 > sizes ; <nl> + CHECK ( str_util : : SplitAndParseAsInts ( input_layer_shape , ' , ' , & sizes ) ) <nl> + < < " Incorrect size string specified : " < < input_layer_shape ; <nl> + TensorShape input_shape ; <nl> + for ( int i = 0 ; i < sizes . size ( ) ; + + i ) { <nl> + input_shape . AddDim ( sizes [ i ] ) ; <nl> } <nl> + Status time_status = <nl> + TimeMultipleRuns ( sleep_seconds , num_runs , input_data_type , input_shape , <nl> + input_layer , output_layer , session . get ( ) , stats . get ( ) ) ; <nl> + if ( ! time_status . ok ( ) ) { <nl> + LOG ( ERROR ) < < " Timing failed with " < < time_status ; <nl> + return - 1 ; <nl> + } <nl> + <nl> + stats - > PrintStepStats ( ) ; <nl> <nl> - tensorflow : : g_stats - > PrintStepStats ( ) ; <nl> return 0 ; <nl> } <nl> + <nl> + } / / namespace benchmark_model <nl> + } / / namespace tensorflow <nl> new file mode 100644 <nl> index 0000000000000 . . 62e36f6cbc4ea <nl> mmm / dev / null <nl> ppp b / tensorflow / tools / benchmark / benchmark_model . h <nl> <nl> + / * Copyright 2015 Google Inc . All Rights Reserved . <nl> + <nl> + Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + you may not use this file except in compliance with the License . <nl> + You may obtain a copy of the License at <nl> + <nl> + http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + <nl> + Unless required by applicable law or agreed to in writing , software <nl> + distributed under the License is distributed on an " AS IS " BASIS , <nl> + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + See the License for the specific language governing permissions and <nl> + limitations under the License . <nl> + = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * / <nl> + <nl> + # ifndef TENSORFLOW_TOOLS_BENCHMARK_BENCHMARK_MODEL_H_ <nl> + # define TENSORFLOW_TOOLS_BENCHMARK_BENCHMARK_MODEL_H_ <nl> + <nl> + # include " tensorflow / core / public / session . h " <nl> + # include " tensorflow / core / util / stat_summarizer . h " <nl> + <nl> + namespace tensorflow { <nl> + namespace benchmark_model { <nl> + <nl> + / / Loads a model from disk into a new session , and sets up the stats collection . <nl> + Status InitializeSession ( int num_threads , const string & graph , <nl> + std : : unique_ptr < Session > * session , <nl> + std : : unique_ptr < StatSummarizer > * stats ) ; <nl> + <nl> + / / Does a single run of the model that ' s been loaded into the given session . <nl> + Status RunBenchmark ( DataType input_data_type , TensorShape input_shape , <nl> + const string & input_layer , const string output_layer , <nl> + Session * session , StatSummarizer * stats ) ; <nl> + <nl> + / / Runs the model multiple time , keeping track of timing information . <nl> + Status TimeMultipleRuns ( double sleep_seconds , int num_runs , <nl> + DataType input_data_type , TensorShape input_shape , <nl> + const string & input_layer , const string output_layer , <nl> + Session * session , StatSummarizer * stats ) ; <nl> + <nl> + / / Handles all setup and argument parsing . <nl> + int Main ( int argc , char * * argv ) ; <nl> + <nl> + } / / namespace benchmark_model <nl> + } / / namespace tensorflow <nl> + <nl> + # endif / / TENSORFLOW_TOOLS_BENCHMARK_BENCHMARK_MODEL_H_ <nl> new file mode 100644 <nl> index 0000000000000 . . 418b04dc6d357 <nl> mmm / dev / null <nl> ppp b / tensorflow / tools / benchmark / benchmark_model_main . cc <nl> <nl> + / * Copyright 2016 Google Inc . All Rights Reserved . <nl> + <nl> + Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + you may not use this file except in compliance with the License . <nl> + You may obtain a copy of the License at <nl> + <nl> + http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + <nl> + Unless required by applicable law or agreed to in writing , software <nl> + distributed under the License is distributed on an " AS IS " BASIS , <nl> + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + See the License for the specific language governing permissions and <nl> + limitations under the License . <nl> + = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * / <nl> + <nl> + # include " tensorflow / tools / benchmark / benchmark_model . h " <nl> + <nl> + int main ( int argc , char * * argv ) { <nl> + return tensorflow : : benchmark_model : : Main ( argc , argv ) ; <nl> + } <nl> new file mode 100644 <nl> index 0000000000000 . . e38efdafa9699 <nl> mmm / dev / null <nl> ppp b / tensorflow / tools / benchmark / benchmark_model_test . cc <nl> <nl> + / * Copyright 2016 Google Inc . All Rights Reserved . <nl> + <nl> + Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + you may not use this file except in compliance with the License . <nl> + You may obtain a copy of the License at <nl> + <nl> + http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + <nl> + Unless required by applicable law or agreed to in writing , software <nl> + distributed under the License is distributed on an " AS IS " BASIS , <nl> + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + See the License for the specific language governing permissions and <nl> + limitations under the License . <nl> + = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * / <nl> + <nl> + # include " tensorflow / tools / benchmark / benchmark_model . h " <nl> + <nl> + # include " tensorflow / cc / ops / standard_ops . h " <nl> + # include " tensorflow / core / framework / tensor_testutil . h " <nl> + # include " tensorflow / core / graph / graph_def_builder . h " <nl> + # include " tensorflow / core / lib / core / status_test_util . h " <nl> + # include " tensorflow / core / lib / io / path . h " <nl> + # include " tensorflow / core / platform / test . h " <nl> + # include " tensorflow / core / platform / test_benchmark . h " <nl> + <nl> + namespace tensorflow { <nl> + namespace { <nl> + <nl> + TEST ( BenchmarkModelTest , InitializeAndRun ) { <nl> + const string dir = testing : : TmpDir ( ) ; <nl> + const string filename_pb = io : : JoinPath ( dir , " graphdef . pb " ) ; <nl> + <nl> + / / Create a simple graph and write it to filename_pb . <nl> + const int input_width = 400 ; <nl> + const int input_height = 10 ; <nl> + const TensorShape input_shape ( { input_width , input_height } ) ; <nl> + const TensorShape constant_shape ( { input_height , input_width } ) ; <nl> + <nl> + Tensor constant_tensor ( DT_FLOAT , constant_shape ) ; <nl> + test : : FillFn < float > ( & constant_tensor , [ ] ( int ) - > float { return 3 . 0 ; } ) ; <nl> + <nl> + GraphDefBuilder b ( GraphDefBuilder : : kFailImmediately ) ; <nl> + Node * placeholder = <nl> + ops : : Placeholder ( DT_FLOAT , b . opts ( ) . WithAttr ( " shape " , input_shape ) ) ; <nl> + const string input_name = placeholder - > name ( ) ; <nl> + Node * constant = ops : : Const ( constant_tensor , b . opts ( ) ) ; <nl> + const string output_name = <nl> + ops : : MatMul ( placeholder , constant , b . opts ( ) ) - > name ( ) ; <nl> + <nl> + GraphDef graph_def ; <nl> + TF_ASSERT_OK ( b . ToGraphDef ( & graph_def ) ) ; <nl> + string graph_def_serialized ; <nl> + graph_def . SerializeToString ( & graph_def_serialized ) ; <nl> + TF_ASSERT_OK ( <nl> + WriteStringToFile ( Env : : Default ( ) , filename_pb , graph_def_serialized ) ) ; <nl> + <nl> + std : : unique_ptr < Session > session ; <nl> + std : : unique_ptr < StatSummarizer > stats ; <nl> + TF_ASSERT_OK ( <nl> + benchmark_model : : InitializeSession ( 1 , filename_pb , & session , & stats ) ) ; <nl> + <nl> + TF_ASSERT_OK ( benchmark_model : : TimeMultipleRuns ( 0 . 0 , 10 , DT_FLOAT , input_shape , <nl> + input_name , output_name , <nl> + session . get ( ) , stats . get ( ) ) ) ; <nl> + } <nl> + <nl> + } / / namespace <nl> + } / / namespace tensorflow <nl>
Added a test to model benchmarking and refactored code .
tensorflow/tensorflow
d704902cb1efab2fa07213bfd0fc1e52ac5b646b
2016-05-17T22:22:33Z
mmm a / package . json <nl> ppp b / package . json <nl> <nl> " version " : " 0 . 4 . 0 " , <nl> " subversion " : { <nl> " browser " : " 0 . 5 . 0 " , <nl> - " framework " : " 0 . 19 . 9 " , <nl> + " framework " : " 0 . 19 . 14 " , <nl> " transformer " : " > = 0 . 1 . 5 < 0 . 5 " <nl> } , <nl> " description " : " A framework for building Mobile cross - platform UI " , <nl> <nl> " semver " : " ^ 5 . 1 . 0 " , <nl> " weex - components " : " ^ 0 . 2 . 0 " , <nl> " weex - picker " : " ^ 0 . 1 . 0 " , <nl> - " weex - rax - framework " : " 0 . 1 . 7 " , <nl> - " weex - vue - framework " : " 2 . 1 . 10 - weex . 1 " <nl> + " weex - rax - framework " : " 0 . 1 . 0 " , <nl> + " weex - vue - framework " : " 2 . 2 . 1 " <nl> } , <nl> " devDependencies " : { <nl> " xml2map " : " ^ 1 . 0 . 2 " , <nl>
* [ jsfm ] v0 . 19 . 14 & & revert weex - rax - framework to 0 . 1 . 0
apache/incubator-weex
716ae549156ae5829011d72b5d838dcdf06ad0f3
2017-03-10T10:54:05Z
mmm a / Marlin / Marlin_main . cpp <nl> ppp b / Marlin / Marlin_main . cpp <nl> static void clean_up_after_endstop_or_probe_move ( ) { <nl> <nl> # endif / / HAS_BED_PROBE <nl> <nl> - # if ENABLED ( Z_PROBE_ALLEN_KEY ) | | ENABLED ( Z_PROBE_SLED ) | | ENABLED ( Z_SAFE_HOMING ) | | HAS_PROBING_PROCEDURE | | HOTENDS > 1 | | ENABLED ( NOZZLE_CLEAN_FEATURE ) | | ENABLED ( NOZZLE_PARK_FEATURE ) <nl> + # if ENABLED ( Z_PROBE_ALLEN_KEY ) | | ENABLED ( Z_PROBE_SLED ) | | HAS_PROBING_PROCEDURE | | HOTENDS > 1 | | ENABLED ( NOZZLE_CLEAN_FEATURE ) | | ENABLED ( NOZZLE_PARK_FEATURE ) <nl> static bool axis_unhomed_error ( const bool x , const bool y , const bool z ) { <nl> const bool xx = x & & ! axis_homed [ X_AXIS ] , <nl> yy = y & & ! axis_homed [ Y_AXIS ] , <nl> bool position_is_reachable ( float target [ XYZ ] <nl> # endif <nl> ) { <nl> float dx = RAW_X_POSITION ( target [ X_AXIS ] ) , <nl> - dy = RAW_Y_POSITION ( target [ Y_AXIS ] ) , <nl> - dz = RAW_Z_POSITION ( target [ Z_AXIS ] ) ; <nl> + dy = RAW_Y_POSITION ( target [ Y_AXIS ] ) ; <nl> <nl> # if HAS_BED_PROBE <nl> if ( by_probe ) { <nl> bool position_is_reachable ( float target [ XYZ ] <nl> # elif ENABLED ( DELTA ) <nl> return HYPOT2 ( dx , dy ) < = sq ( DELTA_PRINTABLE_RADIUS ) ; <nl> # else <nl> + const float dz = RAW_Z_POSITION ( target [ Z_AXIS ] ) ; <nl> return dx > = X_MIN_POS - 0 . 0001 & & dx < = X_MAX_POS + 0 . 0001 <nl> & & dy > = Y_MIN_POS - 0 . 0001 & & dy < = Y_MAX_POS + 0 . 0001 <nl> & & dz > = Z_MIN_POS - 0 . 0001 & & dz < = Z_MAX_POS + 0 . 0001 ; <nl> void ok_to_send ( ) { <nl> <nl> / / Get the Z adjustment for non - linear bed leveling <nl> float nonlinear_z_offset ( float cartesian [ XYZ ] ) { <nl> - if ( planner . abl_enabled ) return ; <nl> <nl> int half_x = ( ABL_GRID_POINTS_X - 1 ) / 2 , <nl> half_y = ( ABL_GRID_POINTS_Y - 1 ) / 2 ; <nl>
Merge pull request from thinkyhead / fix_warnings_etc
MarlinFirmware/Marlin
8061f1fac929817c0ea26ef5c2a5d3106ca4f32f
2016-09-24T08:22:49Z
mmm a / src / video_core / guest_driver . h <nl> ppp b / src / video_core / guest_driver . h <nl> class GuestDriverProfile { <nl> / / This goes with Vulkan and OpenGL standards but Nvidia GPUs can easily <nl> / / use 4 bytes instead . Thus , certain drivers may squish the size . <nl> static constexpr u32 default_texture_handler_size = 8 ; <nl> + <nl> u32 texture_handler_size = default_texture_handler_size ; <nl> bool texture_handler_size_deduced = false ; <nl> } ; <nl> mmm a / src / video_core / renderer_opengl / gl_shader_decompiler . cpp <nl> ppp b / src / video_core / renderer_opengl / gl_shader_decompiler . cpp <nl> class GLSLDecompiler final { <nl> } <nl> <nl> void DeclareCustomVariables ( ) { <nl> - const u32 cv_num = ir . GetCustomVariablesAmount ( ) ; <nl> - for ( u32 i = 0 ; i < cv_num ; + + i ) { <nl> + const u32 num_custom_variables = ir . GetNumCustomVariables ( ) ; <nl> + for ( u32 i = 0 ; i < num_custom_variables ; + + i ) { <nl> code . AddLine ( " float { } = 0 . 0f ; " , GetCustomVariable ( i ) ) ; <nl> } <nl> - if ( cv_num > 0 ) { <nl> + if ( num_custom_variables > 0 ) { <nl> code . AddNewLine ( ) ; <nl> } <nl> } <nl> mmm a / src / video_core / renderer_vulkan / vk_shader_decompiler . cpp <nl> ppp b / src / video_core / renderer_vulkan / vk_shader_decompiler . cpp <nl> class SPIRVDecompiler final : public Sirit : : Module { <nl> } <nl> <nl> void DeclareCustomVariables ( ) { <nl> - const u32 cv_num = ir . GetCustomVariablesAmount ( ) ; <nl> - for ( u32 i = 0 ; i < cv_num ; + + i ) { <nl> + const u32 num_custom_variables = ir . GetNumCustomVariables ( ) ; <nl> + for ( u32 i = 0 ; i < num_custom_variables ; + + i ) { <nl> const Id id = OpVariable ( t_prv_float , spv : : StorageClass : : Private , v_float_zero ) ; <nl> Name ( id , fmt : : format ( " custom_var_ { } " , i ) ) ; <nl> custom_variables . emplace ( i , AddGlobalVariable ( id ) ) ; <nl> class SPIRVDecompiler final : public Sirit : : Module { <nl> <nl> } else if ( const auto cv = std : : get_if < CustomVarNode > ( & * dest ) ) { <nl> target = { custom_variables . at ( cv - > GetIndex ( ) ) , Type : : Float } ; <nl> + <nl> } else { <nl> UNIMPLEMENTED ( ) ; <nl> } <nl> mmm a / src / video_core / shader / const_buffer_locker . h <nl> ppp b / src / video_core / shader / const_buffer_locker . h <nl> class ConstBufferLocker { <nl> return bindless_samplers ; <nl> } <nl> <nl> + / / / Gets bound buffer used on this shader <nl> u32 GetBoundBuffer ( ) const { <nl> return bound_buffer ; <nl> } <nl> <nl> + / / / Obtains access to the guest driver ' s profile . <nl> VideoCore : : GuestDriverProfile * AccessGuestDriverProfile ( ) const { <nl> if ( engine ) { <nl> return & engine - > AccessGuestDriverProfile ( ) ; <nl> mmm a / src / video_core / shader / decode . cpp <nl> ppp b / src / video_core / shader / decode . cpp <nl> constexpr bool IsSchedInstruction ( u32 offset , u32 main_offset ) { <nl> } <nl> <nl> void DeduceTextureHandlerSize ( VideoCore : : GuestDriverProfile * gpu_driver , <nl> - std : : list < Sampler > & used_samplers ) { <nl> + const std : : list < Sampler > & used_samplers ) { <nl> if ( gpu_driver = = nullptr ) { <nl> - LOG_CRITICAL ( HW_GPU , " GPU Driver profile has not been created yet " ) ; <nl> + LOG_CRITICAL ( HW_GPU , " GPU driver profile has not been created yet " ) ; <nl> return ; <nl> } <nl> if ( gpu_driver - > TextureHandlerSizeKnown ( ) | | used_samplers . size ( ) < = 1 ) { <nl> void DeduceTextureHandlerSize ( VideoCore : : GuestDriverProfile * gpu_driver , <nl> } <nl> } <nl> <nl> - std : : optional < u32 > TryDeduceSamplerSize ( Sampler & sampler_to_deduce , <nl> + std : : optional < u32 > TryDeduceSamplerSize ( const Sampler & sampler_to_deduce , <nl> VideoCore : : GuestDriverProfile * gpu_driver , <nl> - std : : list < Sampler > & used_samplers ) { <nl> + const std : : list < Sampler > & used_samplers ) { <nl> if ( gpu_driver = = nullptr ) { <nl> LOG_CRITICAL ( HW_GPU , " GPU Driver profile has not been created yet " ) ; <nl> return std : : nullopt ; <nl> void ShaderIR : : PostDecode ( ) { <nl> auto gpu_driver = locker . AccessGuestDriverProfile ( ) ; <nl> DeduceTextureHandlerSize ( gpu_driver , used_samplers ) ; <nl> / / Deduce Indexed Samplers <nl> - if ( uses_indexed_samplers ) { <nl> - for ( auto & sampler : used_samplers ) { <nl> - if ( sampler . IsIndexed ( ) ) { <nl> - auto size = TryDeduceSamplerSize ( sampler , gpu_driver , used_samplers ) ; <nl> - if ( size ) { <nl> - sampler . SetSize ( * size ) ; <nl> - } else { <nl> - LOG_CRITICAL ( HW_GPU , " Failed to deduce size of indexed sampler " ) ; <nl> - sampler . SetSize ( 1 ) ; <nl> - } <nl> - } <nl> + if ( ! uses_indexed_samplers ) { <nl> + return ; <nl> + } <nl> + for ( auto & sampler : used_samplers ) { <nl> + if ( ! sampler . IsIndexed ( ) ) { <nl> + continue ; <nl> + } <nl> + if ( const auto size = TryDeduceSamplerSize ( sampler , gpu_driver , used_samplers ) ) { <nl> + sampler . SetSize ( * size ) ; <nl> + } else { <nl> + LOG_CRITICAL ( HW_GPU , " Failed to deduce size of indexed sampler " ) ; <nl> + sampler . SetSize ( 1 ) ; <nl> } <nl> } <nl> } <nl> mmm a / src / video_core / shader / decode / texture . cpp <nl> ppp b / src / video_core / shader / decode / texture . cpp <nl> u32 ShaderIR : : DecodeTexture ( NodeBlock & bb , u32 pc ) { <nl> } <nl> <nl> for ( u32 element = 0 ; element < values . size ( ) ; + + element ) { <nl> - MetaTexture meta { * sampler , array_node , { } , { } , { } , derivates , { } , { } , { } , element , index_var } ; <nl> + MetaTexture meta { * sampler , array_node , { } , { } , { } , derivates , <nl> + { } , { } , { } , element , index_var } ; <nl> values [ element ] = Operation ( OperationCode : : TextureGradient , std : : move ( meta ) , coords ) ; <nl> } <nl> <nl> mmm a / src / video_core / shader / node . h <nl> ppp b / src / video_core / shader / node . h <nl> class Sampler { <nl> return size ; <nl> } <nl> <nl> - void SetSize ( u32 new_size ) { <nl> + constexpr void SetSize ( u32 new_size ) { <nl> size = new_size ; <nl> } <nl> <nl> class ArraySamplerNode final { <nl> explicit ArraySamplerNode ( u32 index , u32 base_offset , u32 bindless_var ) <nl> : index { index } , base_offset { base_offset } , bindless_var { bindless_var } { } <nl> <nl> - u32 GetIndex ( ) const { <nl> + constexpr u32 GetIndex ( ) const { <nl> return index ; <nl> } <nl> <nl> - u32 GetBaseOffset ( ) const { <nl> + constexpr u32 GetBaseOffset ( ) const { <nl> return base_offset ; <nl> } <nl> <nl> - u32 GetIndexVar ( ) const { <nl> + constexpr u32 GetIndexVar ( ) const { <nl> return bindless_var ; <nl> } <nl> <nl> class BindlessSamplerNode final { <nl> public : <nl> explicit BindlessSamplerNode ( u32 index , u32 offset ) : index { index } , offset { offset } { } <nl> <nl> - u32 GetIndex ( ) const { <nl> + constexpr u32 GetIndex ( ) const { <nl> return index ; <nl> } <nl> <nl> - u32 GetOffset ( ) const { <nl> + constexpr u32 GetOffset ( ) const { <nl> return offset ; <nl> } <nl> <nl> class CustomVarNode final { <nl> public : <nl> explicit constexpr CustomVarNode ( u32 index ) : index { index } { } <nl> <nl> - u32 GetIndex ( ) const { <nl> + constexpr u32 GetIndex ( ) const { <nl> return index ; <nl> } <nl> <nl> mmm a / src / video_core / shader / shader_ir . cpp <nl> ppp b / src / video_core / shader / shader_ir . cpp <nl> std : : size_t ShaderIR : : DeclareAmend ( Node new_amend ) { <nl> } <nl> <nl> u32 ShaderIR : : NewCustomVariable ( ) { <nl> - const u32 id = num_custom_variables + + ; <nl> - return id ; <nl> + return num_custom_variables + + ; <nl> } <nl> <nl> } / / namespace VideoCommon : : Shader <nl> mmm a / src / video_core / shader / shader_ir . h <nl> ppp b / src / video_core / shader / shader_ir . h <nl> class ShaderIR final { <nl> return amend_code [ index ] ; <nl> } <nl> <nl> - u32 GetCustomVariablesAmount ( ) const { <nl> + u32 GetNumCustomVariables ( ) const { <nl> return num_custom_variables ; <nl> } <nl> <nl> mmm a / src / video_core / shader / track . cpp <nl> ppp b / src / video_core / shader / track . cpp <nl> std : : pair < Node , s64 > FindOperation ( const NodeBlock & code , s64 cursor , <nl> } <nl> return { } ; <nl> } <nl> - } / / Anonymous namespace <nl> <nl> std : : optional < std : : pair < Node , Node > > DecoupleIndirectRead ( const OperationNode & operation ) { <nl> if ( operation . GetCode ( ) ! = OperationCode : : UAdd ) { <nl> std : : optional < std : : pair < Node , Node > > DecoupleIndirectRead ( const OperationNode & o <nl> } <nl> Node gpr { } ; <nl> Node offset { } ; <nl> - if ( operation . GetOperandsCount ( ) ! = 2 ) { <nl> - return std : : nullopt ; <nl> - } <nl> + ASSERT ( operation . GetOperandsCount ( ) = = 2 ) ; <nl> for ( std : : size_t i = 0 ; i < operation . GetOperandsCount ( ) ; i + + ) { <nl> Node operand = operation [ i ] ; <nl> if ( std : : holds_alternative < ImmediateNode > ( * operand ) ) { <nl> std : : optional < std : : pair < Node , Node > > DecoupleIndirectRead ( const OperationNode & o <nl> } <nl> } <nl> if ( offset & & gpr ) { <nl> - return { std : : make_pair ( gpr , offset ) } ; <nl> + return std : : make_pair ( gpr , offset ) ; <nl> } <nl> return std : : nullopt ; <nl> } <nl> bool AmendNodeCv ( std : : size_t amend_index , Node node ) { <nl> return false ; <nl> } <nl> <nl> + } / / Anonymous namespace <nl> + <nl> std : : tuple < Node , TrackSampler > ShaderIR : : TrackBindlessSampler ( Node tracked , const NodeBlock & code , <nl> s64 cursor ) { <nl> if ( const auto cbuf = std : : get_if < CbufNode > ( & * tracked ) ) { <nl>
Shader_IR : Address feedback .
yuzu-emu/yuzu
bb8eb15d392d69693f8cda0427669d011e23db97
2020-01-25T13:04:59Z
mmm a / include / v8 . h <nl> ppp b / include / v8 . h <nl> class V8_EXPORT ValueSerializer { <nl> * SharedArrayBuffer object . The embedder must return an ID for the <nl> * object , using the same ID if this SharedArrayBuffer has already been <nl> * serialized in this buffer . When deserializing , this ID will be passed to <nl> - * ValueDeserializer : : TransferSharedArrayBuffer as | transfer_id | . <nl> + * ValueDeserializer : : GetSharedArrayBufferFromId as | clone_id | . <nl> * <nl> * If the object cannot be serialized , an <nl> * exception should be thrown and Nothing < uint32_t > ( ) returned . <nl> class V8_EXPORT ValueDeserializer { <nl> * / <nl> virtual MaybeLocal < WasmCompiledModule > GetWasmModuleFromId ( <nl> Isolate * isolate , uint32_t transfer_id ) ; <nl> + <nl> + / * * <nl> + * Get a SharedArrayBuffer given a clone_id previously provided <nl> + * by ValueSerializer : : GetSharedArrayBufferId <nl> + * / <nl> + virtual MaybeLocal < SharedArrayBuffer > GetSharedArrayBufferFromId ( <nl> + Isolate * isolate , uint32_t clone_id ) ; <nl> } ; <nl> <nl> ValueDeserializer ( Isolate * isolate , const uint8_t * data , size_t size ) ; <nl> mmm a / src / api . cc <nl> ppp b / src / api . cc <nl> MaybeLocal < WasmCompiledModule > ValueDeserializer : : Delegate : : GetWasmModuleFromId ( <nl> return MaybeLocal < WasmCompiledModule > ( ) ; <nl> } <nl> <nl> + MaybeLocal < SharedArrayBuffer > <nl> + ValueDeserializer : : Delegate : : GetSharedArrayBufferFromId ( Isolate * v8_isolate , <nl> + uint32_t id ) { <nl> + i : : Isolate * isolate = reinterpret_cast < i : : Isolate * > ( v8_isolate ) ; <nl> + isolate - > ScheduleThrow ( * isolate - > factory ( ) - > NewError ( <nl> + isolate - > error_function ( ) , <nl> + i : : MessageTemplate : : kDataCloneDeserializationError ) ) ; <nl> + return MaybeLocal < SharedArrayBuffer > ( ) ; <nl> + } <nl> + <nl> struct ValueDeserializer : : PrivateData { <nl> PrivateData ( i : : Isolate * i , i : : Vector < const uint8_t > data , Delegate * delegate ) <nl> : isolate ( i ) , deserializer ( i , data , delegate ) { } <nl> mmm a / src / d8 . cc <nl> ppp b / src / d8 . cc <nl> class Serializer : public ValueSerializer : : Delegate { <nl> <nl> size_t index = shared_array_buffers_ . size ( ) ; <nl> shared_array_buffers_ . emplace_back ( isolate_ , shared_array_buffer ) ; <nl> + data_ - > shared_array_buffer_contents_ . push_back ( <nl> + MaybeExternalize ( shared_array_buffer ) ) ; <nl> return Just < uint32_t > ( static_cast < uint32_t > ( index ) ) ; <nl> } <nl> <nl> class Serializer : public ValueSerializer : : Delegate { <nl> data_ - > array_buffer_contents_ . push_back ( contents ) ; <nl> } <nl> <nl> - for ( const auto & global_shared_array_buffer : shared_array_buffers_ ) { <nl> - Local < SharedArrayBuffer > shared_array_buffer = <nl> - Local < SharedArrayBuffer > : : New ( isolate_ , global_shared_array_buffer ) ; <nl> - data_ - > shared_array_buffer_contents_ . push_back ( <nl> - MaybeExternalize ( shared_array_buffer ) ) ; <nl> - } <nl> - <nl> return Just ( true ) ; <nl> } <nl> <nl> class Deserializer : public ValueDeserializer : : Delegate { <nl> deserializer_ . TransferArrayBuffer ( index + + , array_buffer ) ; <nl> } <nl> <nl> - index = 0 ; <nl> - for ( const auto & contents : data_ - > shared_array_buffer_contents ( ) ) { <nl> - Local < SharedArrayBuffer > shared_array_buffer = SharedArrayBuffer : : New ( <nl> - isolate_ , contents . Data ( ) , contents . ByteLength ( ) ) ; <nl> - deserializer_ . TransferSharedArrayBuffer ( index + + , shared_array_buffer ) ; <nl> - } <nl> - <nl> return deserializer_ . ReadValue ( context ) ; <nl> } <nl> <nl> + MaybeLocal < SharedArrayBuffer > GetSharedArrayBufferFromId ( <nl> + Isolate * isolate , uint32_t clone_id ) override { <nl> + DCHECK_NOT_NULL ( data_ ) ; <nl> + if ( clone_id < data_ - > shared_array_buffer_contents ( ) . size ( ) ) { <nl> + SharedArrayBuffer : : Contents contents = <nl> + data_ - > shared_array_buffer_contents ( ) . at ( clone_id ) ; <nl> + return SharedArrayBuffer : : New ( isolate_ , contents . Data ( ) , <nl> + contents . ByteLength ( ) ) ; <nl> + } <nl> + return MaybeLocal < SharedArrayBuffer > ( ) ; <nl> + } <nl> + <nl> private : <nl> Isolate * isolate_ ; <nl> ValueDeserializer deserializer_ ; <nl> mmm a / src / value - serializer . cc <nl> ppp b / src / value - serializer . cc <nl> MaybeHandle < Object > ValueDeserializer : : ReadObjectInternal ( ) { <nl> return ReadJSMap ( ) ; <nl> case SerializationTag : : kBeginJSSet : <nl> return ReadJSSet ( ) ; <nl> - case SerializationTag : : kArrayBuffer : <nl> - return ReadJSArrayBuffer ( ) ; <nl> - case SerializationTag : : kArrayBufferTransfer : { <nl> + case SerializationTag : : kArrayBuffer : { <nl> const bool is_shared = false ; <nl> - return ReadTransferredJSArrayBuffer ( is_shared ) ; <nl> + return ReadJSArrayBuffer ( is_shared ) ; <nl> + } <nl> + case SerializationTag : : kArrayBufferTransfer : { <nl> + return ReadTransferredJSArrayBuffer ( ) ; <nl> } <nl> case SerializationTag : : kSharedArrayBuffer : { <nl> const bool is_shared = true ; <nl> - return ReadTransferredJSArrayBuffer ( is_shared ) ; <nl> + return ReadJSArrayBuffer ( is_shared ) ; <nl> } <nl> case SerializationTag : : kWasmModule : <nl> return ReadWasmModule ( ) ; <nl> MaybeHandle < JSSet > ValueDeserializer : : ReadJSSet ( ) { <nl> return scope . CloseAndEscape ( set ) ; <nl> } <nl> <nl> - MaybeHandle < JSArrayBuffer > ValueDeserializer : : ReadJSArrayBuffer ( ) { <nl> + MaybeHandle < JSArrayBuffer > ValueDeserializer : : ReadJSArrayBuffer ( <nl> + bool is_shared ) { <nl> uint32_t id = next_id_ + + ; <nl> + if ( is_shared ) { <nl> + uint32_t clone_id ; <nl> + Local < SharedArrayBuffer > sab_value ; <nl> + if ( ! ReadVarint < uint32_t > ( ) . To ( & clone_id ) | | delegate_ = = nullptr | | <nl> + ! delegate_ <nl> + - > GetSharedArrayBufferFromId ( <nl> + reinterpret_cast < v8 : : Isolate * > ( isolate_ ) , clone_id ) <nl> + . ToLocal ( & sab_value ) ) { <nl> + RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION ( isolate_ , JSArrayBuffer ) ; <nl> + return MaybeHandle < JSArrayBuffer > ( ) ; <nl> + } <nl> + Handle < JSArrayBuffer > array_buffer = Utils : : OpenHandle ( * sab_value ) ; <nl> + DCHECK_EQ ( is_shared , array_buffer - > is_shared ( ) ) ; <nl> + AddObjectWithID ( id , array_buffer ) ; <nl> + return array_buffer ; <nl> + } <nl> uint32_t byte_length ; <nl> if ( ! ReadVarint < uint32_t > ( ) . To ( & byte_length ) | | <nl> byte_length > static_cast < size_t > ( end_ - position_ ) ) { <nl> MaybeHandle < JSArrayBuffer > ValueDeserializer : : ReadJSArrayBuffer ( ) { <nl> return array_buffer ; <nl> } <nl> <nl> - MaybeHandle < JSArrayBuffer > ValueDeserializer : : ReadTransferredJSArrayBuffer ( <nl> - bool is_shared ) { <nl> + MaybeHandle < JSArrayBuffer > ValueDeserializer : : ReadTransferredJSArrayBuffer ( ) { <nl> uint32_t id = next_id_ + + ; <nl> uint32_t transfer_id ; <nl> Handle < NumberDictionary > transfer_map ; <nl> MaybeHandle < JSArrayBuffer > ValueDeserializer : : ReadTransferredJSArrayBuffer ( <nl> } <nl> Handle < JSArrayBuffer > array_buffer ( <nl> JSArrayBuffer : : cast ( transfer_map - > ValueAt ( index ) ) , isolate_ ) ; <nl> - DCHECK_EQ ( is_shared , array_buffer - > is_shared ( ) ) ; <nl> AddObjectWithID ( id , array_buffer ) ; <nl> return array_buffer ; <nl> } <nl> MaybeHandle < WasmMemoryObject > ValueDeserializer : : ReadWasmMemory ( ) { <nl> <nl> const bool is_shared = true ; <nl> Handle < JSArrayBuffer > buffer ; <nl> - if ( ! ReadTransferredJSArrayBuffer ( is_shared ) . ToHandle ( & buffer ) ) { <nl> + if ( ! ReadJSArrayBuffer ( is_shared ) . ToHandle ( & buffer ) ) { <nl> return MaybeHandle < WasmMemoryObject > ( ) ; <nl> } <nl> <nl> mmm a / src / value - serializer . h <nl> ppp b / src / value - serializer . h <nl> class ValueDeserializer { <nl> MaybeHandle < JSRegExp > ReadJSRegExp ( ) WARN_UNUSED_RESULT ; <nl> MaybeHandle < JSMap > ReadJSMap ( ) WARN_UNUSED_RESULT ; <nl> MaybeHandle < JSSet > ReadJSSet ( ) WARN_UNUSED_RESULT ; <nl> - MaybeHandle < JSArrayBuffer > ReadJSArrayBuffer ( ) WARN_UNUSED_RESULT ; <nl> - MaybeHandle < JSArrayBuffer > ReadTransferredJSArrayBuffer ( bool is_shared ) <nl> + MaybeHandle < JSArrayBuffer > ReadJSArrayBuffer ( bool is_shared ) <nl> + WARN_UNUSED_RESULT ; <nl> + MaybeHandle < JSArrayBuffer > ReadTransferredJSArrayBuffer ( ) <nl> WARN_UNUSED_RESULT ; <nl> MaybeHandle < JSArrayBufferView > ReadJSArrayBufferView ( <nl> Handle < JSArrayBuffer > buffer ) WARN_UNUSED_RESULT ; <nl> mmm a / test / mjsunit / d8 / d8 - worker - sharedarraybuffer . js <nl> ppp b / test / mjsunit / d8 / d8 - worker - sharedarraybuffer . js <nl> <nl> / / Flags : - - harmony - sharedarraybuffer <nl> <nl> if ( this . Worker ) { <nl> - ( function TestTransfer ( ) { <nl> + ( function TestClone ( ) { <nl> var workerScript = <nl> ` onmessage = function ( m ) { <nl> var sab = m ; <nl> var ta = new Uint32Array ( sab ) ; <nl> if ( sab . byteLength ! = = 16 ) { <nl> - throw new Error ( ' SharedArrayBuffer transfer byteLength ' ) ; <nl> + throw new Error ( ' SharedArrayBuffer clone byteLength ' ) ; <nl> } <nl> for ( var i = 0 ; i < 4 ; + + i ) { <nl> if ( ta [ i ] ! = = i ) { <nl> - throw new Error ( ' SharedArrayBuffer transfer value ' + i ) ; <nl> + throw new Error ( ' SharedArrayBuffer clone value ' + i ) ; <nl> } <nl> } <nl> / / Atomically update ta [ 0 ] <nl> if ( this . Worker ) { <nl> ta [ i ] = i ; <nl> } <nl> <nl> - / / Transfer SharedArrayBuffer <nl> + / / Clone SharedArrayBuffer <nl> w . postMessage ( sab ) ; <nl> assertEquals ( 16 , sab . byteLength ) ; / / ArrayBuffer should not be neutered . <nl> <nl> if ( this . Worker ) { <nl> assertEquals ( 16 , sab . byteLength ) ; / / Still not neutered . <nl> } ) ( ) ; <nl> <nl> - ( function TestTransferMulti ( ) { <nl> + ( function TestCloneMulti ( ) { <nl> var workerScript = <nl> ` onmessage = function ( msg ) { <nl> var sab = msg . sab ; <nl> mmm a / test / unittests / value - serializer - unittest . cc <nl> ppp b / test / unittests / value - serializer - unittest . cc <nl> TEST_F ( ValueSerializerTest , DecodeInvalidDataView ) { <nl> { 0xFF , 0x09 , 0x42 , 0x02 , 0x00 , 0x00 , 0x56 , 0x3F , 0x01 , 0x03 } ) ; <nl> } <nl> <nl> - class ValueSerializerTestWithSharedArrayBufferTransfer <nl> + class ValueSerializerTestWithSharedArrayBufferClone <nl> : public ValueSerializerTest { <nl> protected : <nl> - ValueSerializerTestWithSharedArrayBufferTransfer ( ) <nl> - : serializer_delegate_ ( this ) { } <nl> + ValueSerializerTestWithSharedArrayBufferClone ( ) <nl> + : serializer_delegate_ ( this ) , deserializer_delegate_ ( this ) { } <nl> <nl> void InitializeData ( const std : : vector < uint8_t > & data ) { <nl> data_ = data ; <nl> class ValueSerializerTestWithSharedArrayBufferTransfer <nl> const Local < SharedArrayBuffer > & input_buffer ( ) { return input_buffer_ ; } <nl> const Local < SharedArrayBuffer > & output_buffer ( ) { return output_buffer_ ; } <nl> <nl> - void BeforeDecode ( ValueDeserializer * deserializer ) override { <nl> - deserializer - > TransferSharedArrayBuffer ( 0 , output_buffer_ ) ; <nl> - } <nl> - <nl> static void SetUpTestCase ( ) { <nl> flag_was_enabled_ = i : : FLAG_harmony_sharedarraybuffer ; <nl> i : : FLAG_harmony_sharedarraybuffer = true ; <nl> class ValueSerializerTestWithSharedArrayBufferTransfer <nl> class SerializerDelegate : public ValueSerializer : : Delegate { <nl> public : <nl> explicit SerializerDelegate ( <nl> - ValueSerializerTestWithSharedArrayBufferTransfer * test ) <nl> + ValueSerializerTestWithSharedArrayBufferClone * test ) <nl> : test_ ( test ) { } <nl> MOCK_METHOD2 ( GetSharedArrayBufferId , <nl> Maybe < uint32_t > ( Isolate * isolate , <nl> Local < SharedArrayBuffer > shared_array_buffer ) ) ; <nl> + MOCK_METHOD2 ( GetSharedArrayBufferFromId , <nl> + MaybeLocal < SharedArrayBuffer > ( Isolate * isolate , uint32_t id ) ) ; <nl> void ThrowDataCloneError ( Local < String > message ) override { <nl> test_ - > isolate ( ) - > ThrowException ( Exception : : Error ( message ) ) ; <nl> } <nl> <nl> private : <nl> - ValueSerializerTestWithSharedArrayBufferTransfer * test_ ; <nl> + ValueSerializerTestWithSharedArrayBufferClone * test_ ; <nl> + } ; <nl> + <nl> + class DeserializerDelegate : public ValueDeserializer : : Delegate { <nl> + public : <nl> + explicit DeserializerDelegate ( <nl> + ValueSerializerTestWithSharedArrayBufferClone * test ) { } <nl> + MOCK_METHOD2 ( GetSharedArrayBufferFromId , <nl> + MaybeLocal < SharedArrayBuffer > ( Isolate * isolate , uint32_t id ) ) ; <nl> } ; <nl> <nl> # if __clang__ <nl> class ValueSerializerTestWithSharedArrayBufferTransfer <nl> return & serializer_delegate_ ; <nl> } <nl> <nl> + ValueDeserializer : : Delegate * GetDeserializerDelegate ( ) override { <nl> + return & deserializer_delegate_ ; <nl> + } <nl> + <nl> SerializerDelegate serializer_delegate_ ; <nl> + DeserializerDelegate deserializer_delegate_ ; <nl> <nl> private : <nl> static bool flag_was_enabled_ ; <nl> class ValueSerializerTestWithSharedArrayBufferTransfer <nl> Local < SharedArrayBuffer > output_buffer_ ; <nl> } ; <nl> <nl> - bool ValueSerializerTestWithSharedArrayBufferTransfer : : flag_was_enabled_ = <nl> - false ; <nl> + bool ValueSerializerTestWithSharedArrayBufferClone : : flag_was_enabled_ = false ; <nl> <nl> - TEST_F ( ValueSerializerTestWithSharedArrayBufferTransfer , <nl> - RoundTripSharedArrayBufferTransfer ) { <nl> + TEST_F ( ValueSerializerTestWithSharedArrayBufferClone , <nl> + RoundTripSharedArrayBufferClone ) { <nl> InitializeData ( { 0x00 , 0x01 , 0x80 , 0xFF } ) ; <nl> <nl> EXPECT_CALL ( serializer_delegate_ , <nl> GetSharedArrayBufferId ( isolate ( ) , input_buffer ( ) ) ) <nl> . WillRepeatedly ( Return ( Just ( 0U ) ) ) ; <nl> + EXPECT_CALL ( deserializer_delegate_ , GetSharedArrayBufferFromId ( isolate ( ) , 0U ) ) <nl> + . WillRepeatedly ( Return ( output_buffer ( ) ) ) ; <nl> <nl> RoundTripTest ( [ this ] ( ) { return input_buffer ( ) ; } , <nl> [ this ] ( Local < Value > value ) { <nl> TEST_F ( ValueSerializerTestWithSharedArrayBufferTransfer , <nl> } ) ; <nl> } <nl> <nl> - TEST_F ( ValueSerializerTestWithSharedArrayBufferTransfer , <nl> + TEST_F ( ValueSerializerTestWithSharedArrayBufferClone , <nl> RoundTripWebAssemblyMemory ) { <nl> bool flag_was_enabled = i : : FLAG_experimental_wasm_threads ; <nl> i : : FLAG_experimental_wasm_threads = true ; <nl> TEST_F ( ValueSerializerTestWithSharedArrayBufferTransfer , <nl> EXPECT_CALL ( serializer_delegate_ , <nl> GetSharedArrayBufferId ( isolate ( ) , input_buffer ( ) ) ) <nl> . WillRepeatedly ( Return ( Just ( 0U ) ) ) ; <nl> + EXPECT_CALL ( deserializer_delegate_ , GetSharedArrayBufferFromId ( isolate ( ) , 0U ) ) <nl> + . WillRepeatedly ( Return ( output_buffer ( ) ) ) ; <nl> <nl> RoundTripTest ( <nl> [ this ] ( ) - > Local < Value > { <nl>
De / serializes SharedArrayBuffers .
v8/v8
982c3164033d3afd51c0d765fc4af98f22b5ccd4
2018-01-18T19:55:48Z
mmm a / Documentation / Examples / shell_replace - document - handle <nl> ppp b / Documentation / Examples / shell_replace - document - handle <nl> <nl> - arango > a5 = db . example . replace ( " 1432124 / 3903044 " , { a : 5 } ) ; <nl> + arango > a5 = db . example . replace ( " example / 3903044 " , { a : 5 } ) ; <nl> { " _id " : " example / 3903044 " , " _key " : " 3903044 " , " _rev " : " 4099652 " , " _oldRev " : " 4034116 " } <nl>
Fix an example .
arangodb/arangodb
fc6ff3e4277ca263afa678c4847360ad1541ed2a
2014-02-12T14:20:40Z
mmm a / emcc . py <nl> ppp b / emcc . py <nl> def optimizing ( opts ) : <nl> # Compiling C code with . c files , don ' t enforce a default C + + std . <nl> clang_compiler = CC <nl> <nl> + if ' - print - search - dirs ' in newargs : <nl> + return run_process ( [ clang_compiler , ' - print - search - dirs ' ] , check = False ) . returncode <nl> + <nl> if options . emrun : <nl> options . pre_js + = open ( shared . path_from_root ( ' src ' , ' emrun_prejs . js ' ) ) . read ( ) + ' \ n ' <nl> options . post_js + = open ( shared . path_from_root ( ' src ' , ' emrun_postjs . js ' ) ) . read ( ) + ' \ n ' <nl> mmm a / tests / test_other . py <nl> ppp b / tests / test_other . py <nl> def test_emcc_cflags ( self ) : <nl> run_process ( [ PYTHON , EMCC , ' a . bc ' ] ) <nl> self . assertContained ( ' hello , world ! ' , run_js ( ' a . out . js ' ) ) <nl> <nl> + def test_emcc_print_search_dirs ( self ) : <nl> + result = run_process ( [ PYTHON , EMCC , ' - print - search - dirs ' ] , stdout = PIPE , stderr = PIPE ) <nl> + self . assertContained ( [ ' programs : = ' , ' libraries : = ' ] , result . stdout , check_all = True ) <nl> + <nl> def test_emar_em_config_flag ( self ) : <nl> # Test that the - - em - config flag is accepted but not passed down do llvm - ar . <nl> # We expand this in case the EM_CONFIG is ~ / . emscripten ( default ) <nl>
Implement - print - search - dirs ( )
emscripten-core/emscripten
89dab7218554c82f22f477f397dbea57d3545eda
2019-08-06T18:12:49Z
mmm a / PowerEditor / src / ScitillaComponent / Buffer . cpp <nl> ppp b / PowerEditor / src / ScitillaComponent / Buffer . cpp <nl> bool FileManager : : saveBuffer ( BufferID id , const TCHAR * filename , bool isCopy , g <nl> if ( isCopy ) <nl> { <nl> _pscratchTilla - > execute ( SCI_SETDOCPOINTER , 0 , _scratchDocDefault ) ; <nl> - <nl> + <nl> + / * for saveAs it ' s not necessary since this action is for the " current " directory , so we let manage in SAVEPOINTREACHED event <nl> + generic_string backupFilePath = buffer - > getBackupFileName ( ) ; <nl> + if ( backupFilePath ! = TEXT ( " " ) ) <nl> + { <nl> + / / delete backup file <nl> + generic_string file2Delete = buffer - > getBackupFileName ( ) ; <nl> + buffer - > setBackupFileName ( TEXT ( " " ) ) ; <nl> + : : DeleteFile ( file2Delete . c_str ( ) ) ; <nl> + } <nl> + * / <nl> + <nl> / / set to signaled state <nl> : : SetEvent ( writeEvent ) ; <nl> - : : CloseHandle ( writeEvent ) ; <nl> + : : CloseHandle ( writeEvent ) ; <nl> return true ; / / all done <nl> } <nl> <nl> bool FileManager : : saveBuffer ( BufferID id , const TCHAR * filename , bool isCopy , g <nl> / / _pscratchTilla - > markSavedLines ( ) ; <nl> _pscratchTilla - > execute ( SCI_SETDOCPOINTER , 0 , _scratchDocDefault ) ; <nl> <nl> + generic_string backupFilePath = buffer - > getBackupFileName ( ) ; <nl> + if ( backupFilePath ! = TEXT ( " " ) ) <nl> + { <nl> + / / delete backup file <nl> + generic_string file2Delete = buffer - > getBackupFileName ( ) ; <nl> + buffer - > setBackupFileName ( TEXT ( " " ) ) ; <nl> + : : DeleteFile ( file2Delete . c_str ( ) ) ; <nl> + } <nl> + <nl> / / set to signaled state <nl> : : SetEvent ( writeEvent ) ; <nl> : : CloseHandle ( writeEvent ) ; <nl> bool FileManager : : loadFileData ( Document doc , const TCHAR * filename , Utf8_16_Rea <nl> _pscratchTilla - > execute ( SCI_SETREADONLY , false ) ; <nl> } <nl> _pscratchTilla - > execute ( SCI_CLEARALL ) ; <nl> - # ifdef UNICODE <nl> + <nl> WcharMbcsConvertor * wmc = WcharMbcsConvertor : : getInstance ( ) ; <nl> - # endif <nl> + <nl> if ( language < L_EXTERNAL ) <nl> { <nl> _pscratchTilla - > execute ( SCI_SETLEXER , ScintillaEditView : : langNames [ language ] . lexerID ) ; <nl> bool FileManager : : loadFileData ( Document doc , const TCHAR * filename , Utf8_16_Rea <nl> { <nl> int id = language - L_EXTERNAL ; <nl> TCHAR * name = NppParameters : : getInstance ( ) - > getELCFromIndex ( id ) . _name ; <nl> - # ifdef UNICODE <nl> const char * pName = wmc - > wchar2char ( name , CP_ACP ) ; <nl> - # else <nl> - const char * pName = name ; <nl> - # endif <nl> _pscratchTilla - > execute ( SCI_SETLEXERLANGUAGE , 0 , ( LPARAM ) pName ) ; <nl> } <nl> <nl>
[ BUG_FIXED ] Fix session snapshot SaveAll bug .
notepad-plus-plus/notepad-plus-plus
e975e06410eac72a0a33a54d0fb01386951ecea8
2014-05-15T16:43:56Z
mmm a / src / qt / forms / rpcconsole . ui <nl> ppp b / src / qt / forms / rpcconsole . ui <nl> <nl> < / widget > <nl> < / item > <nl> < item row = " 3 " column = " 0 " > <nl> + < widget class = " QLabel " name = " label_14 " > <nl> + < property name = " text " > <nl> + < string > Using OpenSSL version < / string > <nl> + < / property > <nl> + < property name = " indent " > <nl> + < number > 10 < / number > <nl> + < / property > <nl> + < / widget > <nl> + < / item > <nl> + < item row = " 3 " column = " 1 " > <nl> + < widget class = " QLabel " name = " openSSLVersion " > <nl> + < property name = " cursor " > <nl> + < cursorShape > IBeamCursor < / cursorShape > <nl> + < / property > <nl> + < property name = " text " > <nl> + < string > N / A < / string > <nl> + < / property > <nl> + < property name = " textFormat " > <nl> + < enum > Qt : : PlainText < / enum > <nl> + < / property > <nl> + < property name = " textInteractionFlags " > <nl> + < set > Qt : : LinksAccessibleByMouse | Qt : : TextSelectableByKeyboard | Qt : : TextSelectableByMouse < / set > <nl> + < / property > <nl> + < / widget > <nl> + < / item > <nl> + < item row = " 4 " column = " 0 " > <nl> < widget class = " QLabel " name = " label_12 " > <nl> < property name = " text " > <nl> < string > Build date < / string > <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 3 " column = " 1 " > <nl> + < item row = " 4 " column = " 1 " > <nl> < widget class = " QLabel " name = " buildDate " > <nl> < property name = " cursor " > <nl> < cursorShape > IBeamCursor < / cursorShape > <nl> <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 4 " column = " 0 " > <nl> + < item row = " 5 " column = " 0 " > <nl> < widget class = " QLabel " name = " label_13 " > <nl> < property name = " text " > <nl> < string > Startup time < / string > <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 4 " column = " 1 " > <nl> + < item row = " 5 " column = " 1 " > <nl> < widget class = " QLabel " name = " startupTime " > <nl> < property name = " cursor " > <nl> < cursorShape > IBeamCursor < / cursorShape > <nl> <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 5 " column = " 0 " > <nl> + < item row = " 6 " column = " 0 " > <nl> < widget class = " QLabel " name = " label_11 " > <nl> < property name = " font " > <nl> < font > <nl> <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 6 " column = " 0 " > <nl> + < item row = " 7 " column = " 0 " > <nl> < widget class = " QLabel " name = " label_7 " > <nl> < property name = " text " > <nl> < string > Number of connections < / string > <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 6 " column = " 1 " > <nl> + < item row = " 7 " column = " 1 " > <nl> < widget class = " QLabel " name = " numberOfConnections " > <nl> < property name = " cursor " > <nl> < cursorShape > IBeamCursor < / cursorShape > <nl> <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 7 " column = " 0 " > <nl> + < item row = " 8 " column = " 0 " > <nl> < widget class = " QLabel " name = " label_8 " > <nl> < property name = " text " > <nl> < string > On testnet < / string > <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 7 " column = " 1 " > <nl> + < item row = " 8 " column = " 1 " > <nl> < widget class = " QCheckBox " name = " isTestNet " > <nl> < property name = " enabled " > <nl> < bool > false < / bool > <nl> <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 8 " column = " 0 " > <nl> + < item row = " 9 " column = " 0 " > <nl> < widget class = " QLabel " name = " label_10 " > <nl> < property name = " font " > <nl> < font > <nl> <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 9 " column = " 0 " > <nl> + < item row = " 10 " column = " 0 " > <nl> < widget class = " QLabel " name = " label_3 " > <nl> < property name = " text " > <nl> < string > Current number of blocks < / string > <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 9 " column = " 1 " > <nl> + < item row = " 10 " column = " 1 " > <nl> < widget class = " QLabel " name = " numberOfBlocks " > <nl> < property name = " cursor " > <nl> < cursorShape > IBeamCursor < / cursorShape > <nl> <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 10 " column = " 0 " > <nl> + < item row = " 11 " column = " 0 " > <nl> < widget class = " QLabel " name = " label_4 " > <nl> < property name = " text " > <nl> < string > Estimated total blocks < / string > <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 10 " column = " 1 " > <nl> + < item row = " 11 " column = " 1 " > <nl> < widget class = " QLabel " name = " totalBlocks " > <nl> < property name = " cursor " > <nl> < cursorShape > IBeamCursor < / cursorShape > <nl> <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 11 " column = " 0 " > <nl> + < item row = " 12 " column = " 0 " > <nl> < widget class = " QLabel " name = " label_2 " > <nl> < property name = " text " > <nl> < string > Last block time < / string > <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 11 " column = " 1 " > <nl> + < item row = " 12 " column = " 1 " > <nl> < widget class = " QLabel " name = " lastBlockTime " > <nl> < property name = " cursor " > <nl> < cursorShape > IBeamCursor < / cursorShape > <nl> <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 12 " column = " 0 " > <nl> + < item row = " 13 " column = " 0 " > <nl> < spacer name = " verticalSpacer_2 " > <nl> < property name = " orientation " > <nl> < enum > Qt : : Vertical < / enum > <nl> <nl> < / property > <nl> < / spacer > <nl> < / item > <nl> - < item row = " 13 " column = " 0 " > <nl> + < item row = " 14 " column = " 0 " > <nl> < widget class = " QLabel " name = " labelDebugLogfile " > <nl> < property name = " font " > <nl> < font > <nl> <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 14 " column = " 0 " > <nl> + < item row = " 15 " column = " 0 " > <nl> < widget class = " QPushButton " name = " openDebugLogfileButton " > <nl> < property name = " toolTip " > <nl> < string > Open the Bitcoin debug logfile from the current data directory . This can take a few seconds for large logfiles . < / string > <nl> <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 15 " column = " 0 " > <nl> + < item row = " 16 " column = " 0 " > <nl> < widget class = " QLabel " name = " labelCLOptions " > <nl> < property name = " font " > <nl> < font > <nl> <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 16 " column = " 0 " > <nl> + < item row = " 17 " column = " 0 " > <nl> < widget class = " QPushButton " name = " showCLOptionsButton " > <nl> < property name = " toolTip " > <nl> < string > Show the Bitcoin - Qt help message to get a list with possible Bitcoin command - line options . < / string > <nl> <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 17 " column = " 0 " > <nl> + < item row = " 18 " column = " 0 " > <nl> < spacer name = " verticalSpacer " > <nl> < property name = " orientation " > <nl> < enum > Qt : : Vertical < / enum > <nl> mmm a / src / qt / rpcconsole . cpp <nl> ppp b / src / qt / rpcconsole . cpp <nl> <nl> # include < QScrollBar > <nl> <nl> # include < boost / tokenizer . hpp > <nl> + # include < openssl / crypto . h > <nl> <nl> / / TODO : make it possible to filter out categories ( esp debug messages when implemented ) <nl> / / TODO : receive errors and debug messages through ClientModel <nl> RPCConsole : : RPCConsole ( QWidget * parent ) : <nl> <nl> connect ( ui - > clearButton , SIGNAL ( clicked ( ) ) , this , SLOT ( clear ( ) ) ) ; <nl> <nl> + / / set OpenSSL version label <nl> + ui - > openSSLVersion - > setText ( SSLeay_version ( SSLEAY_VERSION ) ) ; <nl> + <nl> startExecutor ( ) ; <nl> <nl> clear ( ) ; <nl>
show used OpenSSL library version in debug window
bitcoin/bitcoin
c7441658da9cfc7680f1cc1db098a71c5d2d7a3f
2012-07-07T14:43:46Z
mmm a / modules / viz / include / opencv2 / viz / viz3d . hpp <nl> ppp b / modules / viz / include / opencv2 / viz / viz3d . hpp <nl> namespace cv <nl> class CV_EXPORTS Viz3d <nl> { <nl> public : <nl> + typedef cv : : viz : : Color Color ; <nl> typedef void ( * KeyboardCallback ) ( const KeyboardEvent & , void * ) ; <nl> typedef void ( * MouseCallback ) ( const MouseEvent & , void * ) ; <nl> <nl> mmm a / modules / viz / include / opencv2 / viz / widgets . hpp <nl> ppp b / modules / viz / include / opencv2 / viz / widgets . hpp <nl> namespace cv <nl> class CV_EXPORTS WText : public Widget2D <nl> { <nl> public : <nl> - WText ( const String & text , const Point2i & pos , int font_size = 10 , const Color & color = Color : : white ( ) ) ; <nl> + WText ( const String & text , const Point2i & pos , int font_size = 20 , const Color & color = Color : : white ( ) ) ; <nl> <nl> void setText ( const String & text ) ; <nl> String getText ( ) const ; <nl> mmm a / modules / viz / src / cloud_widgets . cpp <nl> ppp b / modules / viz / src / cloud_widgets . cpp <nl> struct cv : : viz : : WCloud : : CreateCloudWidget <nl> cells - > SetNumberOfTuples ( nr_points ) ; <nl> vtkIdType * cell = cells - > GetPointer ( 0 ) ; <nl> / / Fill it with 1s <nl> - std : : fill_n ( cell , nr_points * 2 , 1 ) ; <nl> + std : : fill ( cell , cell + nr_points * 2 , 1 ) ; <nl> cell + + ; <nl> for ( vtkIdType i = 0 ; i < nr_points ; + + i , cell + = 2 ) <nl> * cell = i ; <nl> cv : : viz : : WCloud : : WCloud ( InputArray _cloud , InputArray _colors ) <nl> <nl> if ( cloud . isContinuous ( ) & & colors . isContinuous ( ) ) <nl> { <nl> - cloud . reshape ( cloud . channels ( ) , 1 ) ; <nl> - colors . reshape ( colors . channels ( ) , 1 ) ; <nl> + cloud = cloud . reshape ( cloud . channels ( ) , 1 ) ; <nl> + colors = colors . reshape ( colors . channels ( ) , 1 ) ; <nl> } <nl> <nl> vtkIdType nr_points ; <nl> struct cv : : viz : : WCloudCollection : : CreateCloudWidget <nl> cells - > SetNumberOfTuples ( nr_points ) ; <nl> vtkIdType * cell = cells - > GetPointer ( 0 ) ; <nl> / / Fill it with 1s <nl> - std : : fill_n ( cell , nr_points * 2 , 1 ) ; <nl> + std : : fill ( cell , cell + nr_points * 2 , 1 ) ; <nl> cell + + ; <nl> for ( vtkIdType i = 0 ; i < nr_points ; + + i , cell + = 2 ) <nl> * cell = i ; <nl> void cv : : viz : : WCloudCollection : : addCloud ( InputArray _cloud , InputArray _colors , <nl> <nl> if ( cloud . isContinuous ( ) & & colors . isContinuous ( ) ) <nl> { <nl> - cloud . reshape ( cloud . channels ( ) , 1 ) ; <nl> - colors . reshape ( colors . channels ( ) , 1 ) ; <nl> + cloud = cloud . reshape ( cloud . channels ( ) , 1 ) ; <nl> + colors = colors . reshape ( colors . channels ( ) , 1 ) ; <nl> } <nl> <nl> vtkIdType nr_points ; <nl> mmm a / modules / viz / src / interactor_style . cpp <nl> ppp b / modules / viz / src / interactor_style . cpp <nl> cv : : viz : : InteractorStyle : : OnKeyDown ( ) <nl> " \ n " <nl> " j , J : take a . PNG snapshot of the current window view \ n " <nl> " c , C : display current camera / window parameters \ n " <nl> - " f , F : fly to point mode \ n " <nl> + " f , F : fly to point mode , hold the key and move mouse where to fly \ n " <nl> " \ n " <nl> " e , E : exit the interactor \ n " <nl> " q , Q : stop and call VTK ' s TerminateApp \ n " <nl> cv : : viz : : InteractorStyle : : OnKeyDown ( ) <nl> { <nl> unsigned int t = static_cast < unsigned int > ( time ( 0 ) ) ; <nl> String png_file = cv : : format ( " screenshot - % d . png " , t ) ; <nl> - String cam_file = cv : : format ( " screenshot - % d . cam " , t ) ; <nl> - <nl> - vtkSmartPointer < vtkCamera > cam = Interactor - > GetRenderWindow ( ) - > GetRenderers ( ) - > GetFirstRenderer ( ) - > GetActiveCamera ( ) ; <nl> - Vec2d clip ; <nl> - Vec3d focal , pos , view ; <nl> - cam - > GetClippingRange ( clip . val ) ; <nl> - cam - > GetFocalPoint ( focal . val ) ; <nl> - cam - > GetPosition ( pos . val ) ; <nl> - cam - > GetViewUp ( view . val ) ; <nl> - Vec2i win_pos ( Interactor - > GetRenderWindow ( ) - > GetPosition ( ) ) ; <nl> - Vec2i win_size ( Interactor - > GetRenderWindow ( ) - > GetSize ( ) ) ; <nl> - double angle = cam - > GetViewAngle ( ) / 180 . 0 * CV_PI ; <nl> - <nl> - String data = cv : : format ( " % f , % f / % f , % f , % f / % f , % f , % f / % f , % f , % f / % f / % d , % d / % d , % d " , clip [ 0 ] , clip [ 1 ] , focal [ 0 ] , focal [ 1 ] , focal [ 2 ] , <nl> - pos [ 0 ] , pos [ 1 ] , pos [ 2 ] , view [ 0 ] , view [ 1 ] , view [ 2 ] , angle , win_size [ 0 ] , win_size [ 1 ] , win_pos [ 0 ] , win_pos [ 1 ] ) ; <nl> - <nl> saveScreenshot ( png_file ) ; <nl> - ofstream ofs_cam ( cam_file . c_str ( ) ) ; <nl> - ofs_cam < < data . c_str ( ) < < endl ; <nl> - ofs_cam . close ( ) ; <nl> - <nl> - cout < < " Screenshot ( " < < png_file . c_str ( ) < < " ) and camera information ( " < < cam_file . c_str ( ) < < " ) successfully captured . " < < endl ; <nl> + cout < < " Screenshot ( " < < png_file . c_str ( ) < < " ) successfully captured . " < < endl ; <nl> break ; <nl> } <nl> / / display current camera settings / parameters <nl> cv : : viz : : InteractorStyle : : OnKeyDown ( ) <nl> vtkSmartPointer < vtkCamera > cam = Interactor - > GetRenderWindow ( ) - > GetRenderers ( ) - > GetFirstRenderer ( ) - > GetActiveCamera ( ) ; <nl> <nl> Vec2d clip ; <nl> - Vec3d focal , pose , view ; <nl> + Vec3d focal , pos , view ; <nl> cam - > GetClippingRange ( clip . val ) ; <nl> cam - > GetFocalPoint ( focal . val ) ; <nl> - cam - > GetPosition ( pose . val ) ; <nl> + cam - > GetPosition ( pos . val ) ; <nl> cam - > GetViewUp ( view . val ) ; <nl> Vec2i win_pos ( Interactor - > GetRenderWindow ( ) - > GetPosition ( ) ) ; <nl> Vec2i win_size ( Interactor - > GetRenderWindow ( ) - > GetSize ( ) ) ; <nl> + double angle = cam - > GetViewAngle ( ) / 180 . 0 * CV_PI ; <nl> + <nl> + String data = cv : : format ( " clip ( % f , % f ) focal ( % f , % f , % f ) pos ( % f , % f , % f ) view ( % f , % f , % f ) angle ( % f ) winsz ( % d , % d ) winpos ( % d , % d ) " , <nl> + clip [ 0 ] , clip [ 1 ] , focal [ 0 ] , focal [ 1 ] , focal [ 2 ] , pos [ 0 ] , pos [ 1 ] , pos [ 2 ] , view [ 0 ] , view [ 1 ] , view [ 2 ] , <nl> + angle , win_size [ 0 ] , win_size [ 1 ] , win_pos [ 0 ] , win_pos [ 1 ] ) ; <nl> + <nl> + std : : cout < < data . c_str ( ) < < std : : endl ; <nl> <nl> - cv : : print ( Mat ( clip , false ) . reshape ( 1 , 1 ) ) ; <nl> - std : : cout < < " / " ; <nl> - cv : : print ( Mat ( focal , false ) . reshape ( 1 , 1 ) ) ; <nl> - std : : cout < < " / " ; <nl> - cv : : print ( Mat ( pose , false ) . reshape ( 1 , 1 ) ) ; <nl> - std : : cout < < " / " ; <nl> - cv : : print ( Mat ( view , false ) . reshape ( 1 , 1 ) ) ; <nl> - std : : cout < < " / " < < cam - > GetViewAngle ( ) / 180 . 0 * CV_PI ; <nl> - cv : : print ( Mat ( win_size , false ) . reshape ( 1 , 1 ) ) ; <nl> - std : : cout < < " / " ; <nl> - cv : : print ( Mat ( win_pos , false ) . reshape ( 1 , 1 ) ) ; <nl> - std : : cout < < std : : endl ; <nl> break ; <nl> } <nl> case ' = ' : <nl>
minor changes , opencv cross - branch code
opencv/opencv
2d63f60d435d7a7db0b79479b68c8051216ab8f6
2014-01-19T14:38:38Z
mmm a / test / stdlib / Inputs / NSSlowString / NSSlowString . m <nl> ppp b / test / stdlib / Inputs / NSSlowString / NSSlowString . m <nl> - ( instancetype ) initWithString : ( NSString * ) name { <nl> return self ; <nl> } <nl> <nl> + - ( instancetype ) initWithCharacters : ( const unichar * _Nonnull ) chars length : ( NSUInteger ) count { <nl> + NSString * str = [ [ NSString alloc ] initWithCharacters : chars length : count ] ; <nl> + self = [ self initWithString : str ] ; <nl> + return self ; <nl> + } <nl> + <nl> - ( NSUInteger ) length { <nl> return self . stringHolder . length ; <nl> } <nl> - ( void * ) _fastCharacterContents { <nl> return nil ; <nl> } <nl> <nl> - @ end <nl> \ No newline at end of file <nl> + @ end <nl> mmm a / validation - test / stdlib / StringUTF8 . swift <nl> ppp b / validation - test / stdlib / StringUTF8 . swift <nl> <nl> <nl> import StdlibUnittest <nl> import StdlibCollectionUnittest <nl> + import StdlibUnicodeUnittest <nl> <nl> # if _runtime ( _ObjC ) <nl> import NSSlowString <nl> var strings : Array < String > = [ <nl> <nl> let kCFStringEncodingASCII : UInt32 = 0x0600 <nl> <nl> + # if _runtime ( _ObjC ) <nl> + <nl> + var utf16ByteSequences = utf16Tests . flatMap { $ 0 . value } . map { $ 0 . encoded } <nl> + <nl> + private func testForeignContiguous ( slowString : NSSlowString , string : String ) { <nl> + / / Lazily bridged strings are not contiguous UTF - 8 <nl> + var slowString = NSSlowString ( string : string ) as String <nl> + expectFalse ( slowString . isFastUTF8 ) <nl> + expectEqualSequence ( string . utf8 , slowString . utf8 ) <nl> + <nl> + / / They become fast when mutated <nl> + slowString . makeNative ( ) <nl> + expectTrue ( slowString . isFastUTF8 ) <nl> + expectEqualSequence ( <nl> + string . utf8 , slowString . withFastUTF8IfAvailable ( Array . init ) ! ) <nl> + <nl> + / / Contiguous ASCII CFStrings provide access , even if lazily bridged <nl> + if string . isASCII { <nl> + let cfString = string . withCString { <nl> + CFStringCreateWithCString ( nil , $ 0 , kCFStringEncodingASCII ) ! <nl> + } as String <nl> + expectTrue ( cfString . isFastUTF8 ) <nl> + expectEqualSequence ( <nl> + string . utf8 , cfString . withFastUTF8IfAvailable ( Array . init ) ! ) <nl> + } <nl> + } <nl> + <nl> + # endif <nl> + <nl> UTF8Tests . test ( " Contiguous Access " ) { <nl> for string in strings { <nl> print ( string ) <nl> UTF8Tests . test ( " Contiguous Access " ) { <nl> / / expectTrue ( ( ( copy as NSString ) as String ) . isFastUTF8 ) <nl> <nl> # if _runtime ( _ObjC ) <nl> - / / Lazily bridged strings are not contiguous UTF - 8 <nl> - var slowString = NSSlowString ( string : string ) as String <nl> - expectFalse ( slowString . isFastUTF8 ) <nl> - expectEqualSequence ( string . utf8 , slowString . utf8 ) <nl> - <nl> - / / They become fast when mutated <nl> - slowString . makeNative ( ) <nl> - expectTrue ( slowString . isFastUTF8 ) <nl> - expectEqualSequence ( <nl> - string . utf8 , slowString . withFastUTF8IfAvailable ( Array . init ) ! ) <nl> - <nl> - / / Contiguous ASCII CFStrings provide access , even if lazily bridged <nl> - if string . isASCII { <nl> - let cfString = string . withCString { <nl> - CFStringCreateWithCString ( nil , $ 0 , kCFStringEncodingASCII ) ! <nl> - } as String <nl> - expectTrue ( cfString . isFastUTF8 ) <nl> - expectEqualSequence ( <nl> - string . utf8 , cfString . withFastUTF8IfAvailable ( Array . init ) ! ) <nl> - } <nl> + testForeignContiguous ( slowString : NSSlowString ( string : string ) , <nl> + string : string ) <nl> # endif <nl> } <nl> + # if _runtime ( _ObjC ) <nl> + for bytes in utf16ByteSequences { <nl> + bytes . withContiguousStorageIfAvailable { <nl> + let slowString = NSSlowString ( characters : $ 0 . baseAddress ! , <nl> + length : UInt ( $ 0 . count ) ) <nl> + let string = String ( decoding : $ 0 , as : UTF16 . self ) <nl> + testForeignContiguous ( slowString : slowString , string : string ) <nl> + } <nl> + } <nl> + # endif <nl> } <nl> <nl> runAllTests ( ) <nl>
Merge remote - tracking branch ' origin / master ' into master - next
apple/swift
f754d30de9fccf1b960f99d4acad9301957ff29d
2019-05-22T23:29:09Z
mmm a / lib / SILOptimizer / IPO / CapturePropagation . cpp <nl> ppp b / lib / SILOptimizer / IPO / CapturePropagation . cpp <nl> class CapturePropagation : public SILFunctionTransform <nl> static LiteralInst * getConstant ( SILValue V ) { <nl> if ( auto I = dyn_cast < ThinToThickFunctionInst > ( V ) ) <nl> return getConstant ( I - > getOperand ( ) ) ; <nl> + if ( auto I = dyn_cast < ConvertFunctionInst > ( V ) ) <nl> + return getConstant ( I - > getOperand ( ) ) ; <nl> return dyn_cast < LiteralInst > ( V ) ; <nl> } <nl> <nl> static bool isProfitable ( SILFunction * Callee ) { <nl> SILBasicBlock * EntryBB = & * Callee - > begin ( ) ; <nl> for ( auto * Arg : EntryBB - > getArguments ( ) ) { <nl> for ( auto * Operand : Arg - > getUses ( ) ) { <nl> - if ( auto * AI = dyn_cast < ApplyInst > ( Operand - > getUser ( ) ) ) { <nl> - if ( AI - > getCallee ( ) = = Operand - > get ( ) ) <nl> + if ( FullApplySite FAS = FullApplySite : : isa ( Operand - > getUser ( ) ) ) { <nl> + if ( FAS . getCallee ( ) = = Operand - > get ( ) ) <nl> return true ; <nl> } <nl> } <nl> mmm a / test / SILOptimizer / capture_propagation . sil <nl> ppp b / test / SILOptimizer / capture_propagation . sil <nl> bb0 : <nl> return % 2 : $ @ callee_owned ( Int32 , Int32 ) - > ( Bool , @ error Error ) <nl> } <nl> <nl> + / / Check if we can handle a non - throwing closure which is passed to a thunk accepting a throwing closure . <nl> + <nl> + sil @ simple_nonthrowing_closure : $ @ convention ( thin ) ( Int32 ) - > Bool <nl> + <nl> + / / CHECK - LABEL : sil shared @ { { . * } } throwing_thunk { { . * } } : $ @ convention ( thin ) ( Int32 ) - > ( Bool , @ error Error ) { <nl> + / / CHECK : = function_ref @ simple_nonthrowing_closure <nl> + / / CHECK - NEXT : thin_to_thick_function <nl> + / / CHECK - NEXT : convert_function <nl> + / / CHECK - NEXT : try_apply <nl> + / / CHECK : return <nl> + / / CHECK : throw <nl> + sil @ throwing_thunk : $ @ convention ( thin ) ( Int32 , @ owned @ callee_owned ( Int32 ) - > ( Bool , @ error Error ) ) - > ( Bool , @ error Error ) { <nl> + bb0 ( % 0 : $ Int32 , % 1 : $ @ callee_owned ( Int32 ) - > ( Bool , @ error Error ) ) : <nl> + try_apply % 1 ( % 0 ) : $ @ callee_owned ( Int32 ) - > ( Bool , @ error Error ) , normal bb1 , error bb2 <nl> + <nl> + bb1 ( % 5 : $ Bool ) : <nl> + return % 5 : $ Bool <nl> + <nl> + bb2 ( % 7 : $ Error ) : <nl> + throw % 7 : $ Error <nl> + } <nl> + <nl> + / / CHECK - LABEL : sil @ return_throwing_thunk_closure <nl> + / / CHECK : [ [ F : % [ 0 - 9 ] + ] ] = function_ref @ { { . * } } throwing_thunk { { . * } } : $ @ convention ( thin ) ( Int32 ) - > ( Bool , @ error Error ) <nl> + / / CHECK : [ [ T : % [ 0 - 9 ] + ] ] = thin_to_thick_function [ [ F ] ] <nl> + / / CHECK : return [ [ T ] ] <nl> + sil @ return_throwing_thunk_closure : $ @ convention ( thin ) ( ) - > @ owned @ callee_owned ( Int32 ) - > ( Bool , @ error Error ) { <nl> + bb0 : <nl> + % c1 = function_ref @ simple_nonthrowing_closure : $ @ convention ( thin ) ( Int32 ) - > Bool <nl> + % c2 = thin_to_thick_function % c1 : $ @ convention ( thin ) ( Int32 ) - > Bool to $ @ callee_owned ( Int32 ) - > Bool <nl> + % c3 = convert_function % c2 : $ @ callee_owned ( Int32 ) - > Bool to $ @ callee_owned ( Int32 ) - > ( Bool , @ error Error ) <nl> + % t1 = function_ref @ throwing_thunk : $ @ convention ( thin ) ( Int32 , @ owned @ callee_owned ( Int32 ) - > ( Bool , @ error Error ) ) - > ( Bool , @ error Error ) <nl> + % 2 = partial_apply % t1 ( % c3 ) : $ @ convention ( thin ) ( Int32 , @ owned @ callee_owned ( Int32 ) - > ( Bool , @ error Error ) ) - > ( Bool , @ error Error ) <nl> + return % 2 : $ @ callee_owned ( Int32 ) - > ( Bool , @ error Error ) <nl> + } <nl> + <nl> / / Negative tests <nl> <nl> sil @ swapped_arguments : $ @ convention ( method ) ( Int32 , Int32 , @ thin Int32 . Type ) - > Bool { <nl>
Merge pull request from eeckstein / capture - prop
apple/swift
697fd96e9cfbff010d8916f4922a52f05cc8772c
2017-02-21T23:50:32Z
mmm a / src / layer / arm / convolution_3x3 . h <nl> ppp b / src / layer / arm / convolution_3x3 . h <nl> static void conv3x3s1_winograd64_neon5 ( const Mat & bottom_blob , Mat & top_blob , co <nl> int w_tm = outw / 6 * 8 ; <nl> int h_tm = outh / 6 * 8 ; <nl> const int tiles = w_tm / 8 * h_tm / 8 ; <nl> - top_blob_tm . create ( 1 , 64 * tiles , outch ) ; <nl> <nl> / / permute <nl> / / bottom_blob_tm . create ( 1 , 64 * tiles , inch ) ; <nl> static void conv3x3s1_winograd64_neon5 ( const Mat & bottom_blob , Mat & top_blob , co <nl> bottom_blob_tm = Mat ( ) ; <nl> / / permute end <nl> <nl> + top_blob_tm . create ( 1 , 64 * tiles , outch ) ; <nl> + <nl> int nn_outch = 0 ; <nl> int remain_outch_start = 0 ; <nl> <nl>
allocate after permute , reduce peak memory usage
Tencent/ncnn
99a343ce7060040f7b89584ccaf4966403d4ca32
2018-06-07T10:02:53Z
mmm a / src / buffer_cache / alt / page . cc <nl> ppp b / src / buffer_cache / alt / page . cc <nl> <nl> # include " buffer_cache / alt / page . hpp " <nl> <nl> # include < algorithm > <nl> + # include < stack > <nl> <nl> # include " arch / runtime / coroutines . hpp " <nl> # include " concurrency / auto_drainer . hpp " <nl> # include " serializer / serializer . hpp " <nl> + # include " stl_utils . hpp " <nl> <nl> / / RSI : temporary debugging macro <nl> - / / # define pagef debugf <nl> - # define pagef ( . . . ) do { } while ( 0 ) <nl> + # define pagef debugf <nl> + / / # define pagef ( . . . ) do { } while ( 0 ) <nl> <nl> namespace alt { <nl> <nl> void page_ptr_t : : reset ( ) { <nl> } <nl> } <nl> <nl> - page_t * page_ptr_t : : get_page_for_read ( ) { <nl> + page_t * page_ptr_t : : get_page_for_read ( ) const { <nl> rassert ( page_ ! = NULL ) ; <nl> return page_ ; <nl> } <nl> page_txn_t : : page_txn_t ( page_cache_t * page_cache , page_txn_t * preceding_txn_or_nu <nl> } <nl> <nl> void page_txn_t : : connect_preceder ( page_txn_t * preceder ) { <nl> + rassert ( preceder ! = this ) ; <nl> + / / RSI : Is this the right condition to check ? <nl> if ( ! preceder - > flush_complete_cond_ . is_pulsed ( ) ) { <nl> / / RSP : performance <nl> if ( std : : find ( preceders_ . begin ( ) , preceders_ . end ( ) , preceder ) <nl> void page_txn_t : : connect_preceder ( page_txn_t * preceder ) { <nl> } <nl> <nl> void page_txn_t : : remove_preceder ( page_txn_t * preceder ) { <nl> + / / RSP : performance <nl> auto it = std : : find ( preceders_ . begin ( ) , preceders_ . end ( ) , preceder ) ; <nl> rassert ( it ! = preceders_ . end ( ) ) ; <nl> preceders_ . erase ( it ) ; <nl> + } <nl> <nl> + void page_txn_t : : remove_subseqer ( page_txn_t * subseqer ) { <nl> + / / RSP : performance <nl> + auto it = std : : find ( subseqers_ . begin ( ) , subseqers_ . end ( ) , subseqer ) ; <nl> + rassert ( it ! = subseqers_ . end ( ) ) ; <nl> + subseqers_ . erase ( it ) ; <nl> } <nl> <nl> + <nl> page_txn_t : : ~ page_txn_t ( ) { <nl> rassert ( live_acqs_ . empty ( ) , " current_page_acq_t lifespan exceeds its page_txn_t ' s " ) ; <nl> <nl> struct ancillary_info_t { <nl> page_t * page ; <nl> } ; <nl> <nl> + / / RSI : Remove commented code . <nl> + # if 0 <nl> void page_cache_t : : do_flush_txn ( page_cache_t * page_cache , page_txn_t * txn ) { <nl> pagef ( " do_flush_txn ( pc = % p , txn = % p ) \ n " , page_cache , txn ) ; <nl> / / We ' re going to flush this transaction . Let ' s start its flush , then detach <nl> void page_cache_t : : do_flush_txn ( page_cache_t * page_cache , page_txn_t * txn ) { <nl> <nl> txn - > flush_complete_cond_ . pulse ( ) ; <nl> } <nl> + # endif / / 0 <nl> + <nl> + std : : map < block_id_t , page_cache_t : : block_change_t > <nl> + page_cache_t : : compute_changes ( const std : : set < page_txn_t * > & txns ) { <nl> + / / The map of changes we make . <nl> + std : : map < block_id_t , block_change_t > changes ; <nl> + <nl> + for ( auto it = txns . begin ( ) ; it ! = txns . end ( ) ; + + it ) { <nl> + page_txn_t * txn = * it ; <nl> + for ( size_t i = 0 , e = txn - > snapshotted_dirtied_pages_ . size ( ) ; i < e ; + + i ) { <nl> + const page_txn_t : : dirtied_page_t & d = txn - > snapshotted_dirtied_pages_ [ i ] ; <nl> + <nl> + block_change_t change ( d . block_version , true , <nl> + d . ptr . has ( ) ? d . ptr . get_page_for_read ( ) : NULL , <nl> + d . tstamp ) ; <nl> + <nl> + auto res = changes . insert ( std : : make_pair ( d . block_id , change ) ) ; <nl> + <nl> + if ( ! res . second ) { <nl> + / / The insertion failed - - we need to use the newer version . <nl> + auto const jt = res . first ; <nl> + / / The versions can ' t be the same for different write transactions . <nl> + rassert ( jt - > second . version ! = d . block_version ) ; <nl> + if ( jt - > second . version < d . block_version ) { <nl> + / / RSI : What if jt - > second . tstamp > d . tstamp ? <nl> + / / Should we take the max of both tstamps ? Ugghh . <nl> + jt - > second = change ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + for ( size_t i = 0 , e = txn - > touched_pages_ . size ( ) ; i < e ; + + i ) { <nl> + const page_txn_t : : touched_page_t & t = txn - > touched_pages_ [ i ] ; <nl> + <nl> + auto res = changes . insert ( std : : make_pair ( t . first , <nl> + block_change_t ( t . block_version , <nl> + false , <nl> + NULL , <nl> + t . second ) ) ) ; <nl> + if ( ! res . second ) { <nl> + / / The insertion failed . We need to combine the versions . <nl> + auto const jt = res . first ; <nl> + / / The versions can ' t be the same for different write transactions . <nl> + rassert ( jt - > second . version ! = t . block_version ) ; <nl> + if ( jt - > second . version < t . block_version ) { <nl> + / / RSI : What if jt - > second . tstamp > t . second ? Just like above , <nl> + / / with the dirtied_page_t , should we take the max of both <nl> + / / tstamps ? Ugghh . <nl> + jt - > second . tstamp = t . second ; <nl> + } <nl> + } <nl> + } <nl> + } <nl> + <nl> + return changes ; <nl> + } <nl> + <nl> + void page_cache_t : : remove_txn_set_from_graph ( page_cache_t * page_cache , <nl> + const std : : set < page_txn_t * > & txns ) { <nl> + for ( auto it = txns . begin ( ) ; it ! = txns . end ( ) ; + + it ) { <nl> + page_txn_t * txn = * it ; <nl> + for ( auto jt = txn - > subseqers_ . begin ( ) ; jt ! = txn - > subseqers_ . end ( ) ; + + jt ) { <nl> + ( * jt ) - > remove_preceder ( txn ) ; <nl> + if ( txns . find ( * jt ) ! = txns . end ( ) ) { <nl> + if ( ( * jt ) - > began_waiting_for_flush_ & & ! ( * jt ) - > spawned_flush_ ) { <nl> + page_cache - > im_waiting_for_flush ( * jt ) ; <nl> + } <nl> + } <nl> + } <nl> + for ( auto jt = txn - > preceders_ . begin ( ) ; jt ! = txn - > preceders_ . end ( ) ; + + jt ) { <nl> + ( * jt ) - > remove_subseqer ( txn ) ; <nl> + } <nl> + <nl> + / / RSI : Maybe we could remove pages_modified_last_ earlier ? Like when we <nl> + / / begin the index write ? ( but that ' s the wrong thread ) Or earlier ? <nl> + for ( auto jt = txn - > pages_modified_last_ . begin ( ) ; <nl> + jt ! = txn - > pages_modified_last_ . end ( ) ; <nl> + + + jt ) { <nl> + current_page_t * current_page = * jt ; <nl> + rassert ( current_page - > last_modifier_ = = txn ) ; <nl> + current_page - > last_modifier_ = NULL ; <nl> + } <nl> + txn - > pages_modified_last_ . clear ( ) ; <nl> + <nl> + / / RSI : Is this the right place ? I guess - - since we remove each txn <nl> + / / from the graph individually . Maybe rename this function ? <nl> + txn - > flush_complete_cond_ . pulse ( ) ; <nl> + } <nl> + } <nl> + <nl> + void page_cache_t : : do_flush_txn_set ( page_cache_t * page_cache , <nl> + const std : : set < page_txn_t * > & txns ) { <nl> + pagef ( " do_flush_txn_set ( pc = % p , tset = % p ) from % s \ n " , page_cache , & txns , <nl> + debug_strprint ( txns ) . c_str ( ) ) ; <nl> + <nl> + / / RSI : We need some way to wait for the preceding txns to have their flushes <nl> + / / stay before our txn ' s . <nl> + <nl> + / / We ' re going to flush these transactions . First we need to figure out what the <nl> + / / set of changes we ' re actually doing is , since any transaction may have touched <nl> + / / the same blocks . <nl> + <nl> + std : : map < block_id_t , block_change_t > changes <nl> + = page_cache_t : : compute_changes ( txns ) ; <nl> + <nl> + std : : vector < block_token_tstamp_t > blocks_by_tokens ; <nl> + blocks_by_tokens . reserve ( changes . size ( ) ) ; <nl> + <nl> + std : : vector < ancillary_info_t > ancillary_infos ; <nl> + std : : vector < buf_write_info_t > write_infos ; <nl> + ancillary_infos . reserve ( changes . size ( ) ) ; <nl> + write_infos . reserve ( changes . size ( ) ) ; <nl> + <nl> + { <nl> + ASSERT_NO_CORO_WAITING ; <nl> + <nl> + for ( auto it = changes . begin ( ) ; it ! = changes . end ( ) ; + + it ) { <nl> + if ( it - > second . modified ) { <nl> + if ( it - > second . page = = NULL ) { <nl> + / / The block is deleted . <nl> + blocks_by_tokens . push_back ( block_token_tstamp_t ( it - > first , <nl> + true , <nl> + counted_t < standard_block_token_t > ( ) , <nl> + it - > second . tstamp , / / RSI : Deleted blocks have tstamps ? <nl> + NULL ) ) ; <nl> + } else { <nl> + / / RSP : We could probably free the resources of <nl> + / / snapshotted_dirtied_pages_ a bit sooner than we do . <nl> + <nl> + page_t * page = it - > second . page ; <nl> + if ( page - > block_token_ . has ( ) ) { <nl> + / / It ' s already on disk , we ' re not going to flush it . <nl> + blocks_by_tokens . push_back ( block_token_tstamp_t ( it - > first , <nl> + false , <nl> + page - > block_token_ , <nl> + it - > second . tstamp , <nl> + page ) ) ; <nl> + } else { <nl> + / / We can ' t be in the process of loading a block we ' re going to <nl> + / / write that we don ' t have a block token . That ' s because we <nl> + / / _actually dirtied the page_ . We had to have acquired the buf , <nl> + / / and the only way to get rid of the buf is for it to be <nl> + / / evicted , in which case the block token would be non - empty . <nl> + rassert ( page - > destroy_ptr_ = = NULL ) ; <nl> + rassert ( page - > buf_ . has ( ) ) ; <nl> + <nl> + / / RSI : Is there a page_acq - t for this buf we ' re writing ? Is it <nl> + / / possible that we might be trying to do an unbacked eviction <nl> + / / for this page right now ? <nl> + write_infos . push_back ( buf_write_info_t ( page - > buf_ . get ( ) , <nl> + block_size_t : : unsafe_make ( page - > ser_buf_size_ ) , <nl> + it - > first ) ) ; <nl> + / / RSI : Does ancillary_infos actually need it - > first again ? Do <nl> + / / we actually use that field ? <nl> + ancillary_infos . push_back ( ancillary_info_t ( it - > first , <nl> + it - > second . tstamp , <nl> + page ) ) ; <nl> + } <nl> + } <nl> + } else { <nl> + / / We only touched the page . <nl> + blocks_by_tokens . push_back ( block_token_tstamp_t ( it - > first , <nl> + false , <nl> + counted_t < standard_block_token_t > ( ) , <nl> + it - > second . tstamp , <nl> + NULL ) ) ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + { <nl> + pagef ( " do_flush_txn_set about to thread switch ( pc = % p , tset = % p ) \ n " , page_cache , & txns ) ; <nl> + <nl> + on_thread_t th ( page_cache - > serializer_ - > home_thread ( ) ) ; <nl> + <nl> + pagef ( " do_flush_txn_set switched threads ( pc = % p , tset = % p ) \ n " , page_cache , & txns ) ; <nl> + <nl> + struct : public iocallback_t , public cond_t { <nl> + void on_io_complete ( ) { <nl> + pulse ( ) ; <nl> + } <nl> + } blocks_releasable_cb ; <nl> + <nl> + std : : vector < counted_t < standard_block_token_t > > tokens <nl> + = page_cache - > serializer_ - > block_writes ( write_infos , <nl> + page_cache - > writes_io_account . get ( ) , <nl> + & blocks_releasable_cb ) ; <nl> + <nl> + rassert ( tokens . size ( ) = = write_infos . size ( ) ) ; <nl> + rassert ( write_infos . size ( ) = = ancillary_infos . size ( ) ) ; <nl> + for ( size_t i = 0 ; i < write_infos . size ( ) ; + + i ) { <nl> + blocks_by_tokens . push_back ( block_token_tstamp_t ( ancillary_infos [ i ] . block_id , <nl> + false , <nl> + std : : move ( tokens [ i ] ) , <nl> + ancillary_infos [ i ] . tstamp , <nl> + ancillary_infos [ i ] . page ) ) ; <nl> + } <nl> + <nl> + / / RSP : Unnecessary copying between blocks_by_tokens and write_ops , inelegant <nl> + / / representation of deletion / touched blocks in blocks_by_tokens . <nl> + std : : vector < index_write_op_t > write_ops ; <nl> + write_ops . reserve ( blocks_by_tokens . size ( ) ) ; <nl> + <nl> + for ( auto it = blocks_by_tokens . begin ( ) ; it ! = blocks_by_tokens . end ( ) ; <nl> + + + it ) { <nl> + if ( it - > is_deleted ) { <nl> + write_ops . push_back ( index_write_op_t ( it - > block_id , <nl> + counted_t < standard_block_token_t > ( ) , <nl> + repli_timestamp_t : : invalid ) ) ; <nl> + } else if ( it - > block_token . has ( ) ) { <nl> + write_ops . push_back ( index_write_op_t ( it - > block_id , <nl> + std : : move ( it - > block_token ) , <nl> + it - > tstamp ) ) ; <nl> + } else { <nl> + write_ops . push_back ( index_write_op_t ( it - > block_id , <nl> + boost : : none , <nl> + it - > tstamp ) ) ; <nl> + } <nl> + } <nl> + <nl> + pagef ( " do_flush_txn_set blocks_releasable_cb . wait ( ) ( pc = % p , tset = % p ) \ n " , page_cache , & txns ) ; <nl> + <nl> + blocks_releasable_cb . wait ( ) ; <nl> + <nl> + / / Set the page_t ' s block token field to their new block tokens . RSI : Can we <nl> + / / do this earlier ? Do we have to wait for blocks_releasable_cb ? It doesn ' t <nl> + / / matter that much as long as we have some way to prevent parallel forced <nl> + / / eviction from happening , though . <nl> + for ( auto it = blocks_by_tokens . begin ( ) ; it ! = blocks_by_tokens . end ( ) ; + + it ) { <nl> + if ( it - > block_token . has ( ) & & it - > page ! = NULL ) { <nl> + / / We know page is still a valid pointer because of the page_ptr_t in <nl> + / / snapshotted_dirtied_pages_ . <nl> + <nl> + / / RSI : This assertion would fail if we try to force - evict the page <nl> + / / simultaneously as this write . <nl> + rassert ( ! it - > page - > block_token_ . has ( ) ) ; <nl> + eviction_bag_t * old_bag <nl> + = page_cache - > evicter ( ) . correct_eviction_category ( it - > page ) ; <nl> + it - > page - > block_token_ = std : : move ( it - > block_token ) ; <nl> + page_cache - > evicter ( ) . change_eviction_bag ( old_bag , it - > page ) ; <nl> + } <nl> + } <nl> + <nl> + pagef ( " do_flush_txn_set blocks_releasable_cb waited ( pc = % p , tset = % p ) \ n " , page_cache , & txns ) ; <nl> + <nl> + / / RSI : This blocks ? Is there any way to set the began_index_write_ <nl> + / / fields ? <nl> + page_cache - > serializer_ - > index_write ( write_ops , <nl> + page_cache - > writes_io_account . get ( ) ) ; <nl> + pagef ( " do_flush_txn_set index write returned ( pc = % p , tset = % p ) \ n " , page_cache , & txns ) ; <nl> + } <nl> + pagef ( " exicted scope after do_flush_txn_set index write returned ( pc = % p , tset = % p ) \ n " , page_cache , & txns ) ; <nl> + <nl> + / / Flush complete , and we ' re back on the page cache ' s thread . <nl> + <nl> + / / RSI : connect_preceder uses flush_complete_cond_ to see whether it should <nl> + / / connect . It should probably use began_index_write_ , when that variable <nl> + / / exists ? ? We had some comment about that ? Or it should use something else ? <nl> + <nl> + page_cache_t : : remove_txn_set_from_graph ( page_cache , txns ) ; <nl> + pagef ( " remove_txn_set_from_graph returned ( pc = % p , tset = % p ) \ n " , page_cache , & txns ) ; <nl> + } <nl> + <nl> + bool page_cache_t : : exists_flushable_txn_set ( page_txn_t * txn , <nl> + std : : set < page_txn_t * > * flush_set_out ) { <nl> + std : : set < page_txn_t * > builder ; <nl> + std : : stack < page_txn_t * > stack ; <nl> + stack . push ( txn ) ; <nl> + <nl> + while ( ! stack . empty ( ) ) { <nl> + page_txn_t * t = stack . top ( ) ; <nl> + stack . pop ( ) ; <nl> + <nl> + if ( ! t - > began_waiting_for_flush_ ) { <nl> + / / We can ' t flush this txn or the others if there ' s a preceder that <nl> + / / hasn ' t begun waiting for flush . <nl> + return false ; <nl> + } <nl> + <nl> + if ( t - > spawned_flush_ ) { <nl> + / / We ignore ( and don ' t continue to traverse ) nodes that are already <nl> + / / spawned flushing . They aren ' t part of our txn set , and they didn ' t <nl> + / / depend on txn before they started flushing . <nl> + continue ; <nl> + } <nl> + <nl> + auto res = builder . insert ( t ) ; <nl> + if ( res . second ) { <nl> + / / An insertion actually took place - - it ' s newly processed ! Add its <nl> + / / preceders to the stack so that we can process them . <nl> + for ( auto it = t - > preceders_ . begin ( ) ; it ! = t - > preceders_ . end ( ) ; + + it ) { <nl> + stack . push ( * it ) ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + / / We built up some txn set . We know it ' s non - empty because at least txn is in <nl> + / / there . Success ! <nl> + * flush_set_out = std : : move ( builder ) ; <nl> + return true ; <nl> + } <nl> <nl> void page_cache_t : : im_waiting_for_flush ( page_txn_t * txn ) { <nl> pagef ( " im_waiting_for_flush ( txn = % p ) \ n " , txn ) ; <nl> rassert ( txn - > began_waiting_for_flush_ ) ; <nl> + rassert ( ! txn - > spawned_flush_ ) ; <nl> / / rassert ( ! txn - > began_index_write_ ) ; / / RSI : This variable doesn ' t exist . <nl> rassert ( txn - > live_acqs_ . empty ( ) ) ; <nl> <nl> + / / We have a new node that ' s waiting for flush . Before this node is flushed , we <nl> + / / will have started to flush all preceders ( recursively ) of this node ( that are <nl> + / / waiting for flush ) that this node doesn ' t itself precede ( recursively ) . Now <nl> + / / we need to ask : Are all this node ' s preceders ( recursively ) ( that are ready to <nl> + / / flush and haven ' t started flushing yet ) ready to flush ? If so , this node must <nl> + / / have been the one that pushed them over the line ( since they haven ' t started <nl> + / / flushing yet ) . So we begin flushing this node and all of its preceders <nl> + / / ( recursively ) in one atomic flush . <nl> + <nl> + <nl> + std : : set < page_txn_t * > flush_set ; <nl> + if ( exists_flushable_txn_set ( txn , & flush_set ) ) { <nl> + pagef ( " built flushable txn set from % s \ n " , <nl> + debug_strprint ( flush_set ) . c_str ( ) ) ; <nl> + for ( auto it = flush_set . begin ( ) ; it ! = flush_set . end ( ) ; + + it ) { <nl> + rassert ( ! ( * it ) - > spawned_flush_ ) ; <nl> + ( * it ) - > spawned_flush_ = true ; <nl> + } <nl> + <nl> + coro_t : : spawn_later_ordered ( std : : bind ( & page_cache_t : : do_flush_txn_set , <nl> + this , <nl> + flush_set ) ) ; <nl> + } <nl> + <nl> + / / RSI : Remove this commented section . <nl> + # if 0 <nl> / / This txn is now waiting to be flushed . Should we flush it ? Let ' s look at the <nl> / / graph of txns . We may flush this txn if all its preceding txns can be <nl> / / flushed . <nl> void page_cache_t : : im_waiting_for_flush ( page_txn_t * txn ) { <nl> if ( txn - > preceders_ . empty ( ) ) { <nl> pagef ( " preceders empty , flushing ( txn = % p ) . \ n " , txn ) ; <nl> <nl> - / / RSI : ' ordered ' ? Really ? <nl> + / / RSI : ' ordered ' ? Really ? ( Yes ? ) <nl> coro_t : : spawn_later_ordered ( std : : bind ( & page_cache_t : : do_flush_txn , this , txn ) ) ; <nl> } <nl> + # endif / / 0 <nl> } <nl> <nl> eviction_bag_t : : eviction_bag_t ( ) <nl> mmm a / src / buffer_cache / alt / page . hpp <nl> ppp b / src / buffer_cache / alt / page . hpp <nl> <nl> # ifndef BUFFER_CACHE_ALT_PAGE_HPP_ <nl> # define BUFFER_CACHE_ALT_PAGE_HPP_ <nl> <nl> + # include < map > <nl> # include < utility > <nl> # include < vector > <nl> + # include < set > <nl> <nl> # include " concurrency / cond_var . hpp " <nl> # include " containers / backindex_bag . hpp " <nl> class page_ptr_t { <nl> page_ptr_t & operator = ( page_ptr_t & & movee ) ; <nl> void init ( page_t * page , page_cache_t * page_cache ) ; <nl> <nl> - page_t * get_page_for_read ( ) ; <nl> + page_t * get_page_for_read ( ) const ; <nl> page_t * get_page_for_write ( page_cache_t * page_cache ) ; <nl> <nl> void reset ( ) ; <nl> <nl> - bool has ( ) { <nl> + bool has ( ) const { <nl> return page_ ! = NULL ; <nl> } <nl> <nl> class block_version_t { <nl> return value_ < other . value_ ; <nl> } <nl> <nl> + bool operator = = ( block_version_t other ) const { <nl> + return value_ = = other . value_ ; <nl> + } <nl> + <nl> + bool operator ! = ( block_version_t other ) const { <nl> + return ! operator = = ( other ) ; <nl> + } <nl> + <nl> private : <nl> uint64_t value_ ; <nl> } ; <nl> class page_cache_t { <nl> evicter_t & evicter ( ) { return evicter_ ; } <nl> <nl> friend class page_txn_t ; <nl> + / / RSI : Remove this commented section . <nl> + # if 0 <nl> static void do_flush_txn ( page_cache_t * page_cache , page_txn_t * txn ) ; <nl> + # endif <nl> + static void do_flush_txn_set ( page_cache_t * page_cache , <nl> + const std : : set < page_txn_t * > & txns ) ; <nl> + static void remove_txn_set_from_graph ( page_cache_t * page_cache , <nl> + const std : : set < page_txn_t * > & txns ) ; <nl> + <nl> + / / RSI : Maybe just have txn_t hold a single list of block_change_t objects . <nl> + struct block_change_t { <nl> + block_change_t ( block_version_t _version , bool _modified , <nl> + page_t * _page , repli_timestamp_t _tstamp ) <nl> + : version ( _version ) , modified ( _modified ) , page ( _page ) , tstamp ( _tstamp ) { } <nl> + block_version_t version ; <nl> + <nl> + / / True if the value of the block was modified ( or the block was deleted ) , false <nl> + / / if the block was only touched . <nl> + bool modified ; <nl> + / / If modified = = true , the new value for the block , or NULL if the block was <nl> + / / deleted . ( The page_t ' s lifetime is kept by some page_txn_t ' s <nl> + / / snapshotted_dirtied_pages_ field . ) <nl> + page_t * page ; <nl> + repli_timestamp_t tstamp ; <nl> + } ; <nl> + <nl> + static std : : map < block_id_t , block_change_t > <nl> + compute_changes ( const std : : set < page_txn_t * > & txns ) ; <nl> + <nl> + bool exists_flushable_txn_set ( page_txn_t * txn , <nl> + std : : set < page_txn_t * > * flush_set_out ) ; <nl> + <nl> void im_waiting_for_flush ( page_txn_t * txn ) ; <nl> <nl> friend class current_page_t ; <nl> class page_txn_t { <nl> / / Removes a preceder , which is already half - way disconnected . <nl> void remove_preceder ( page_txn_t * preceder ) ; <nl> <nl> + / / Removes a subseqer , which is already half - way disconnected . <nl> + void remove_subseqer ( page_txn_t * subseqer ) ; <nl> + <nl> / / current_page_acq should only call add_acquirer and remove_acquirer . <nl> friend class current_page_acq_t ; <nl> void add_acquirer ( current_page_acq_t * acq ) ; <nl> class page_txn_t { <nl> / / RSP : Performance ? remove_acquirer takes linear time . <nl> std : : vector < current_page_acq_t * > live_acqs_ ; <nl> <nl> - struct dirtied_page_t { <nl> + class dirtied_page_t { <nl> + public : <nl> dirtied_page_t ( ) <nl> : block_id ( NULL_BLOCK_ID ) , <nl> tstamp ( repli_timestamp_t : : invalid ) { } <nl> class page_txn_t { <nl> / / Saved pages ( by block id ) . <nl> segmented_vector_t < dirtied_page_t , 8 > snapshotted_dirtied_pages_ ; <nl> <nl> - struct touched_page_t { <nl> + class touched_page_t { <nl> + public : <nl> touched_page_t ( ) <nl> : first ( NULL_BLOCK_ID ) , <nl> second ( repli_timestamp_t : : invalid ) { } <nl> class page_txn_t { <nl> / / Touched pages ( by block id ) . <nl> segmented_vector_t < touched_page_t , 8 > touched_pages_ ; <nl> <nl> + / / RSI : We could probably turn began_waiting_for_flush_ and spawned_flush_ into a <nl> + / / generalized state enum . <nl> + / / <nl> + / / RSI : Should we have the spawned_flush_ variable or should we remove the txn <nl> + / / from the graph ? <nl> + <nl> / / Tells whether this page_txn_t has announced itself ( to the cache ) to be <nl> / / waiting for a flush . <nl> bool began_waiting_for_flush_ ; <nl> + bool spawned_flush_ = false ; / / RSI : compilable <nl> <nl> / / RSI : Actually use this somehow ? <nl> / / Tells whether this page_txn_t , in the process of being flushed , began its <nl> mmm a / src / unittest / page_test . cc <nl> ppp b / src / unittest / page_test . cc <nl> <nl> + # define __STDC_LIMIT_MACROS <nl> + <nl> # include " arch / runtime / coroutines . hpp " <nl> # include " arch / timing . hpp " <nl> # include " buffer_cache / alt / page . hpp " <nl> TEST ( PageTest , CreateDestroy ) { <nl> <nl> void run_OneTxn ( ) { <nl> mock_ser_t mock ; <nl> - page_cache_t page_cache ( mock . ser . get ( ) ) ; <nl> - page_txn_t txn ( & page_cache ) ; <nl> + { <nl> + page_cache_t page_cache ( mock . ser . get ( ) ) ; <nl> + { <nl> + page_txn_t txn ( & page_cache ) ; <nl> + } <nl> + debugf ( " txn destroyed \ n " ) ; <nl> + } <nl> + debugf ( " page_cache destroyed \ n " ) ; <nl> } <nl> <nl> TEST ( PageTest , OneTxn ) { <nl> class bigger_test_t { <nl> condZ1 . pulse ( ) ; <nl> acq8 . reset ( ) ; <nl> condZ2 . pulse ( ) ; <nl> + debugf ( " done txn12 ( pc = % p , txn12 = % p ) \ n " , c , & txn12 ) ; <nl> } <nl> + debugf ( " txn12 destroyed ( pc = % p ) \ n " , c ) ; <nl> condZ3 . pulse ( ) ; <nl> } <nl> <nl> class bigger_test_t { <nl> check_and_append ( acq8 , " t12 " , " t13 " ) ; <nl> condZ4 . pulse ( ) ; <nl> acq8 . reset ( ) ; <nl> + debugf ( " done txn13 ( pc = % p , txn13 = % p ) \ n " , c , & txn13 ) ; <nl> } <nl> + debugf ( " txn13 destroyed ( pc = % p ) \ n " , c ) ; <nl> condZ5 . pulse ( ) ; <nl> } <nl> <nl> mmm a / src / utils . hpp <nl> ppp b / src / utils . hpp <nl> void debugf_dump_buf ( printf_buffer_t * buf ) ; <nl> void debug_print ( printf_buffer_t * buf , uint64_t x ) ; <nl> void debug_print ( printf_buffer_t * buf , const std : : string & s ) ; <nl> <nl> + template < class T > <nl> + void debug_print ( printf_buffer_t * buf , T * ptr ) { <nl> + buf - > appendf ( " % p " , ptr ) ; <nl> + } <nl> + <nl> # ifndef NDEBUG <nl> void debugf ( const char * msg , . . . ) __attribute__ ( ( format ( printf , 1 , 2 ) ) ) ; <nl> template < class T > <nl>
Mutually dependent transactions with bug .
rethinkdb/rethinkdb
942aeca898eff286b299a18e7cec5816cfe10220
2013-11-11T07:22:26Z
mmm a / cocos / 2d / cocos2d . vcxproj <nl> ppp b / cocos / 2d / cocos2d . vcxproj <nl> xcopy / Y / Q " $ ( ProjectDir ) . . \ . . \ external \ win32 - specific \ gles \ prebuilt \ * . * " " $ ( Ou <nl> < None Include = " . . \ math \ Vec4 . inl " / > <nl> < None Include = " cocos2d . def " / > <nl> < / ItemGroup > <nl> + < ItemGroup > <nl> + < ProjectReference Include = " . . \ . . \ external \ chipmunk \ proj . win32 \ chipmunk . vcxproj " > <nl> + < Project > { 207bc7a9 - ccf1 - 4f2f - a04d - 45f72242ae25 } < / Project > <nl> + < / ProjectReference > <nl> + < / ItemGroup > <nl> < Import Project = " $ ( VCTargetsPath ) \ Microsoft . Cpp . targets " / > <nl> < ImportGroup Label = " ExtensionTargets " > <nl> < / ImportGroup > <nl> mmm a / tests / cpp - tests / proj . win32 / cpp - tests . vcxproj <nl> ppp b / tests / cpp - tests / proj . win32 / cpp - tests . vcxproj <nl> <nl> < ProjectReference Include = " . . \ . . \ . . \ cocos \ network \ proj . win32 \ libNetwork . vcxproj " > <nl> < Project > { df2638c0 - 8128 - 4847 - 867c - 6eafe3dee7b5 } < / Project > <nl> < / ProjectReference > <nl> - < ProjectReference Include = " . . \ . . \ . . \ cocos \ storage \ local - storage \ proj . win32 \ libLocalStorage . vcxproj " > <nl> - < Project > { 632a8f38 - d0f0 - 4d22 - 86b3 - d69f5e6bf63a } < / Project > <nl> - < / ProjectReference > <nl> < ProjectReference Include = " . . \ . . \ . . \ extensions \ proj . win32 \ libExtensions . vcxproj " > <nl> < Project > { 21b2c324 - 891f - 48ea - ad1a - 5ae13de12e28 } < / Project > <nl> < ReferenceOutputAssembly > false < / ReferenceOutputAssembly > <nl> mmm a / tests / lua - empty - test / project / proj . win32 / lua - empty - test . vcxproj <nl> ppp b / tests / lua - empty - test / project / proj . win32 / lua - empty - test . vcxproj <nl> <nl> < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 10 . 0 ' " > v100 < / PlatformToolset > <nl> < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 11 . 0 ' " > v110 < / PlatformToolset > <nl> < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 11 . 0 ' and exists ( ' $ ( MSBuildProgramFiles32 ) \ Microsoft SDKs \ Windows \ v7 . 1A ' ) " > v110_xp < / PlatformToolset > <nl> - < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 12 . 0 ' " > v120 < / PlatformToolset > <nl> - < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 12 . 0 ' and exists ( ' $ ( MSBuildProgramFiles32 ) \ Microsoft SDKs \ Windows \ v7 . 1A ' ) " > v120_xp < / PlatformToolset > <nl> + < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 12 . 0 ' " > v120 < / PlatformToolset > <nl> + < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 12 . 0 ' and exists ( ' $ ( MSBuildProgramFiles32 ) \ Microsoft SDKs \ Windows \ v7 . 1A ' ) " > v120_xp < / PlatformToolset > <nl> < / PropertyGroup > <nl> < PropertyGroup Condition = " ' $ ( Configuration ) | $ ( Platform ) ' = = ' Debug | Win32 ' " Label = " Configuration " > <nl> < ConfigurationType > Application < / ConfigurationType > <nl> <nl> < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 10 . 0 ' " > v100 < / PlatformToolset > <nl> < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 11 . 0 ' " > v110 < / PlatformToolset > <nl> < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 11 . 0 ' and exists ( ' $ ( MSBuildProgramFiles32 ) \ Microsoft SDKs \ Windows \ v7 . 1A ' ) " > v110_xp < / PlatformToolset > <nl> - < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 12 . 0 ' " > v120 < / PlatformToolset > <nl> - < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 12 . 0 ' and exists ( ' $ ( MSBuildProgramFiles32 ) \ Microsoft SDKs \ Windows \ v7 . 1A ' ) " > v120_xp < / PlatformToolset > <nl> + < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 12 . 0 ' " > v120 < / PlatformToolset > <nl> + < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 12 . 0 ' and exists ( ' $ ( MSBuildProgramFiles32 ) \ Microsoft SDKs \ Windows \ v7 . 1A ' ) " > v120_xp < / PlatformToolset > <nl> < / PropertyGroup > <nl> < Import Project = " $ ( VCTargetsPath ) \ Microsoft . Cpp . props " / > <nl> < ImportGroup Label = " ExtensionSettings " > <nl> xcopy " $ ( ProjectDir ) . . \ . . \ . . \ . . \ external \ lua \ luasocket \ * . lua " " $ ( ProjectDir ) . . \ . <nl> < ProjectReference Include = " . . \ . . \ . . \ . . \ cocos \ network \ proj . win32 \ libNetwork . vcxproj " > <nl> < Project > { df2638c0 - 8128 - 4847 - 867c - 6eafe3dee7b5 } < / Project > <nl> < / ProjectReference > <nl> - < ProjectReference Include = " . . \ . . \ . . \ . . \ cocos \ storage \ local - storage \ proj . win32 \ libLocalStorage . vcxproj " > <nl> - < Project > { 632a8f38 - d0f0 - 4d22 - 86b3 - d69f5e6bf63a } < / Project > <nl> - < / ProjectReference > <nl> < ProjectReference Include = " . . \ . . \ . . \ . . \ extensions \ proj . win32 \ libExtensions . vcxproj " > <nl> < Project > { 21b2c324 - 891f - 48ea - ad1a - 5ae13de12e28 } < / Project > <nl> < / ProjectReference > <nl> mmm a / tests / lua - tests / project / proj . win32 / lua - tests . win32 . vcxproj <nl> ppp b / tests / lua - tests / project / proj . win32 / lua - tests . win32 . vcxproj <nl> <nl> < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 10 . 0 ' " > v100 < / PlatformToolset > <nl> < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 11 . 0 ' " > v110 < / PlatformToolset > <nl> < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 11 . 0 ' and exists ( ' $ ( MSBuildProgramFiles32 ) \ Microsoft SDKs \ Windows \ v7 . 1A ' ) " > v110_xp < / PlatformToolset > <nl> - < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 12 . 0 ' " > v120 < / PlatformToolset > <nl> - < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 12 . 0 ' and exists ( ' $ ( MSBuildProgramFiles32 ) \ Microsoft SDKs \ Windows \ v7 . 1A ' ) " > v120_xp < / PlatformToolset > <nl> + < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 12 . 0 ' " > v120 < / PlatformToolset > <nl> + < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 12 . 0 ' and exists ( ' $ ( MSBuildProgramFiles32 ) \ Microsoft SDKs \ Windows \ v7 . 1A ' ) " > v120_xp < / PlatformToolset > <nl> < / PropertyGroup > <nl> < PropertyGroup Condition = " ' $ ( Configuration ) | $ ( Platform ) ' = = ' Release | Win32 ' " Label = " Configuration " > <nl> < ConfigurationType > Application < / ConfigurationType > <nl> <nl> < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 10 . 0 ' " > v100 < / PlatformToolset > <nl> < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 11 . 0 ' " > v110 < / PlatformToolset > <nl> < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 11 . 0 ' and exists ( ' $ ( MSBuildProgramFiles32 ) \ Microsoft SDKs \ Windows \ v7 . 1A ' ) " > v110_xp < / PlatformToolset > <nl> - < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 12 . 0 ' " > v120 < / PlatformToolset > <nl> - < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 12 . 0 ' and exists ( ' $ ( MSBuildProgramFiles32 ) \ Microsoft SDKs \ Windows \ v7 . 1A ' ) " > v120_xp < / PlatformToolset > <nl> + < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 12 . 0 ' " > v120 < / PlatformToolset > <nl> + < PlatformToolset Condition = " ' $ ( VisualStudioVersion ) ' = = ' 12 . 0 ' and exists ( ' $ ( MSBuildProgramFiles32 ) \ Microsoft SDKs \ Windows \ v7 . 1A ' ) " > v120_xp < / PlatformToolset > <nl> < / PropertyGroup > <nl> < Import Project = " $ ( VCTargetsPath ) \ Microsoft . Cpp . props " / > <nl> < ImportGroup Label = " ExtensionSettings " > <nl> xcopy / Y / Q " $ ( EngineRoot ) external \ websockets \ prebuilt \ win32 \ * . * " " $ ( OutDir ) " < / C <nl> < ProjectReference Include = " . . \ . . \ . . \ . . \ cocos \ network \ proj . win32 \ libNetwork . vcxproj " > <nl> < Project > { df2638c0 - 8128 - 4847 - 867c - 6eafe3dee7b5 } < / Project > <nl> < / ProjectReference > <nl> - < ProjectReference Include = " . . \ . . \ . . \ . . \ cocos \ storage \ local - storage \ proj . win32 \ libLocalStorage . vcxproj " > <nl> - < Project > { 632a8f38 - d0f0 - 4d22 - 86b3 - d69f5e6bf63a } < / Project > <nl> - < / ProjectReference > <nl> < ProjectReference Include = " . . \ . . \ . . \ . . \ extensions \ proj . win32 \ libExtensions . vcxproj " > <nl> < Project > { 21b2c324 - 891f - 48ea - ad1a - 5ae13de12e28 } < / Project > <nl> < / ProjectReference > <nl>
Merge pull request from dabingnn / v3_windowsDllCompileError
cocos2d/cocos2d-x
8e3220ba9ee2df0e613657534c574c5af8f5c7fa
2014-07-21T09:17:33Z
mmm a / cmake / modules / AddSwift . cmake <nl> ppp b / cmake / modules / AddSwift . cmake <nl> function ( _add_variant_c_compile_flags ) <nl> endif ( ) <nl> <nl> if ( " $ { CFLAGS_SDK } " STREQUAL " ANDROID " ) <nl> + list ( APPEND result - nostdinc + + ) <nl> swift_android_libcxx_include_paths ( CFLAGS_CXX_INCLUDES ) <nl> swift_android_include_for_arch ( " $ { CFLAGS_ARCH } " " $ { CFLAGS_ARCH } _INCLUDE " ) <nl> foreach ( path IN LISTS CFLAGS_CXX_INCLUDES $ { CFLAGS_ARCH } _INCLUDE ) <nl>
Adding - nostdinc + + to Android build of Swift .
apple/swift
1551e014b4df98a6faac5d0ff1474202fa3dd15e
2019-07-09T21:11:05Z
mmm a / tensorflow / compiler / xla / python / BUILD <nl> ppp b / tensorflow / compiler / xla / python / BUILD <nl> pybind_extension ( <nl> " / / tensorflow / core / profiler / lib : profiler_backends " , <nl> " / / tensorflow / core / profiler / lib : profiler_session " , <nl> " / / tensorflow / core / profiler / rpc : profiler_server " , <nl> - " / / tensorflow / python / profiler / internal : traceme_context_manager " , <nl> + " / / tensorflow / python / profiler / internal : traceme_wrapper " , <nl> " / / tensorflow / stream_executor : device_memory_allocator " , <nl> " / / tensorflow / stream_executor : platform " , <nl> ] + select ( { <nl> mmm a / tensorflow / compiler / xla / python / xla . cc <nl> ppp b / tensorflow / compiler / xla / python / xla . cc <nl> limitations under the License . <nl> # include " tensorflow / compiler / xla / xla_data . pb . h " <nl> # include " tensorflow / core / platform / errors . h " <nl> # include " tensorflow / core / profiler / rpc / profiler_server . h " <nl> - # include " tensorflow / python / profiler / internal / traceme_context_manager . h " <nl> + # include " tensorflow / python / profiler / internal / traceme_wrapper . h " <nl> # include " tensorflow / stream_executor / platform . h " <nl> <nl> namespace xla { <nl> namespace { <nl> <nl> namespace py = pybind11 ; <nl> <nl> - using : : tensorflow : : profiler : : TraceMeContextManager ; <nl> + using : : tensorflow : : profiler : : TraceMeWrapper ; <nl> <nl> struct Uniquer { <nl> absl : : Mutex mu ; <nl> void BuildProfilerSubmodule ( py : : module * m ) { <nl> } , <nl> py : : arg ( " port " ) ) ; <nl> <nl> - py : : class_ < TraceMeContextManager > traceme_class ( profiler , " TraceMe " , <nl> - py : : module_local ( ) ) ; <nl> + py : : class_ < TraceMeWrapper > traceme_class ( profiler , " TraceMe " , <nl> + py : : module_local ( ) ) ; <nl> traceme_class . def ( py : : init < py : : str , py : : kwargs > ( ) ) <nl> - . def ( " __enter__ " , <nl> - [ ] ( py : : object self ) - > py : : object { <nl> - py : : cast < TraceMeContextManager * > ( self ) - > Enter ( ) ; <nl> - return self ; <nl> - } ) <nl> + . def ( " __enter__ " , [ ] ( py : : object self ) - > py : : object { return self ; } ) <nl> . def ( " __exit__ " , <nl> [ ] ( py : : object self , const py : : object & ex_type , <nl> const py : : object & ex_value , <nl> const py : : object & traceback ) - > py : : object { <nl> - py : : cast < TraceMeContextManager * > ( self ) - > Exit ( ) ; <nl> + py : : cast < TraceMeWrapper * > ( self ) - > Stop ( ) ; <nl> return py : : none ( ) ; <nl> } ) <nl> - . def ( " set_metadata " , & TraceMeContextManager : : SetMetadata ) <nl> - . def_static ( " is_enabled " , & TraceMeContextManager : : IsEnabled ) ; <nl> + . def ( " set_metadata " , & TraceMeWrapper : : SetMetadata ) <nl> + . def_static ( " is_enabled " , & TraceMeWrapper : : IsEnabled ) ; <nl> } <nl> <nl> } / / namespace <nl> mmm a / tensorflow / python / profiler / internal / BUILD <nl> ppp b / tensorflow / python / profiler / internal / BUILD <nl> tf_python_pybind_extension ( <nl> " / / tensorflow / python / profiler : __subpackages__ " , <nl> ] , <nl> deps = [ <nl> - " : traceme_context_manager " , <nl> + " : traceme_wrapper " , <nl> " @ pybind11 " , <nl> ] , <nl> ) <nl> <nl> cc_library ( <nl> - name = " traceme_context_manager " , <nl> - hdrs = [ " traceme_context_manager . h " ] , <nl> + name = " traceme_wrapper " , <nl> + hdrs = [ " traceme_wrapper . h " ] , <nl> features = [ " - layering_check " ] , <nl> visibility = [ <nl> " / / tensorflow / compiler / xla / python : __pkg__ " , <nl> mmm a / tensorflow / python / profiler / internal / traceme_wrapper . cc <nl> ppp b / tensorflow / python / profiler / internal / traceme_wrapper . cc <nl> See the License for the specific language governing permissions and <nl> limitations under the License . <nl> = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * / <nl> <nl> + # include " tensorflow / python / profiler / internal / traceme_wrapper . h " <nl> + <nl> # include " pybind11 / attr . h " <nl> # include " pybind11 / pybind11 . h " <nl> - # include " tensorflow / python / profiler / internal / traceme_context_manager . h " <nl> <nl> - using : : tensorflow : : profiler : : TraceMeContextManager ; <nl> + namespace py = : : pybind11 ; <nl> + <nl> + using : : tensorflow : : profiler : : TraceMeWrapper ; <nl> <nl> PYBIND11_MODULE ( _pywrap_traceme , m ) { <nl> - py : : class_ < TraceMeContextManager > traceme_class ( m , " TraceMe " , <nl> - py : : module_local ( ) ) ; <nl> - traceme_class . def ( py : : init < py : : str , py : : kwargs > ( ) ) <nl> - . def ( " Enter " , & TraceMeContextManager : : Enter ) <nl> - . def ( " Exit " , & TraceMeContextManager : : Exit ) <nl> - . def ( " SetMetadata " , & TraceMeContextManager : : SetMetadata ) <nl> - . def_static ( " IsEnabled " , & TraceMeContextManager : : IsEnabled ) ; <nl> + py : : class_ < TraceMeWrapper > ( m , " TraceMe " , py : : module_local ( ) ) <nl> + . def ( py : : init < const py : : str & , const py : : kwargs & > ( ) ) <nl> + . def ( " SetMetadata " , & TraceMeWrapper : : SetMetadata ) <nl> + . def_static ( " IsEnabled " , & TraceMeWrapper : : IsEnabled ) ; <nl> } ; <nl> similarity index 53 % <nl> rename from tensorflow / python / profiler / internal / traceme_context_manager . h <nl> rename to tensorflow / python / profiler / internal / traceme_wrapper . h <nl> mmm a / tensorflow / python / profiler / internal / traceme_context_manager . h <nl> ppp b / tensorflow / python / profiler / internal / traceme_wrapper . h <nl> WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> See the License for the specific language governing permissions and <nl> limitations under the License . <nl> = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * / <nl> - # ifndef TENSORFLOW_PYTHON_PROFILER_INTERNAL_TRACEME_CONTEXT_MANAGER_ <nl> - # define TENSORFLOW_PYTHON_PROFILER_INTERNAL_TRACEME_CONTEXT_MANAGER_ <nl> + # ifndef TENSORFLOW_PYTHON_PROFILER_INTERNAL_TRACEME_WRAPPER_ <nl> + # define TENSORFLOW_PYTHON_PROFILER_INTERNAL_TRACEME_WRAPPER_ <nl> <nl> # include < string > <nl> # include < utility > <nl> <nl> # include " absl / strings / str_cat . h " <nl> # include " absl / strings / string_view . h " <nl> - # include " absl / types / optional . h " <nl> # include " pybind11 / pytypes . h " <nl> # include " tensorflow / core / platform / macros . h " <nl> # include " tensorflow / core / platform / types . h " <nl> # include " tensorflow / core / profiler / lib / traceme . h " <nl> <nl> - namespace py = pybind11 ; <nl> - <nl> namespace tensorflow { <nl> namespace profiler { <nl> <nl> - / / Helper to implement TraceMe as a context manager in Python . <nl> - class TraceMeContextManager { <nl> + / / Wraps TraceMe with an interface that takes python types . <nl> + class TraceMeWrapper { <nl> public : <nl> - explicit TraceMeContextManager ( py : : str name , py : : kwargs kwargs ) <nl> - : name_ ( std : : move ( name ) ) , kwargs_ ( std : : move ( kwargs ) ) { } <nl> - <nl> - void Enter ( ) { <nl> - if ( IsEnabled ( ) ) { <nl> - traceme_ . emplace ( [ this ] ( ) { <nl> - std : : string name ( name_ ) ; <nl> - if ( ! kwargs_ . empty ( ) ) { <nl> - AppendMetadata ( & name , kwargs_ ) ; <nl> - } <nl> - return name ; <nl> - } ) ; <nl> - } <nl> - } <nl> - <nl> - void SetMetadata ( py : : kwargs kwargs ) { <nl> - if ( TF_PREDICT_TRUE ( traceme_ . has_value ( ) & & ! kwargs . empty ( ) ) ) { <nl> - traceme_ - > AppendMetadata ( [ & kwargs ] ( ) { <nl> + / / pybind11 : : str and pybind11 : : kwargs are taken by const reference to avoid <nl> + / / python reference - counting overhead . <nl> + TraceMeWrapper ( const pybind11 : : str & name , const pybind11 : : kwargs & kwargs ) <nl> + : traceme_ ( [ & ] ( ) { <nl> + std : : string name_and_metadata ( name ) ; <nl> + if ( ! kwargs . empty ( ) ) { <nl> + AppendMetadata ( & name_and_metadata , kwargs ) ; <nl> + } <nl> + return name_and_metadata ; <nl> + } ) { } <nl> + <nl> + / / pybind11 : : kwargs is taken by const reference to avoid python <nl> + / / reference - counting overhead . <nl> + void SetMetadata ( const pybind11 : : kwargs & kwargs ) { <nl> + if ( TF_PREDICT_FALSE ( ! kwargs . empty ( ) ) ) { <nl> + traceme_ . AppendMetadata ( [ & ] ( ) { <nl> std : : string metadata ; <nl> AppendMetadata ( & metadata , kwargs ) ; <nl> return metadata ; <nl> class TraceMeContextManager { <nl> } <nl> } <nl> <nl> - void Exit ( ) { traceme_ . reset ( ) ; } <nl> + void Stop ( ) { traceme_ . Stop ( ) ; } <nl> <nl> static bool IsEnabled ( ) { return tensorflow : : profiler : : TraceMe : : Active ( ) ; } <nl> <nl> private : <nl> / / Converts kwargs to strings and appends them to name encoded as TraceMe <nl> / / metadata . <nl> - static void AppendMetadata ( std : : string * name , const py : : kwargs & kwargs ) { <nl> + static void AppendMetadata ( std : : string * name , <nl> + const pybind11 : : kwargs & kwargs ) { <nl> name - > push_back ( ' # ' ) ; <nl> for ( const auto & kv : kwargs ) { <nl> - absl : : StrAppend ( name , std : : string ( py : : str ( kv . first ) ) , " = " , <nl> - std : : string ( py : : str ( kv . second ) ) , " , " ) ; <nl> + absl : : StrAppend ( name , std : : string ( pybind11 : : str ( kv . first ) ) , " = " , <nl> + std : : string ( pybind11 : : str ( kv . second ) ) , " , " ) ; <nl> } <nl> name - > back ( ) = ' # ' ; <nl> } <nl> <nl> - py : : str name_ ; <nl> - py : : kwargs kwargs_ ; <nl> - absl : : optional < tensorflow : : profiler : : TraceMe > traceme_ ; <nl> + tensorflow : : profiler : : TraceMe traceme_ ; <nl> } ; <nl> <nl> } / / namespace profiler <nl> } / / namespace tensorflow <nl> <nl> - # endif / / TENSORFLOW_PYTHON_PROFILER_INTERNAL_TRACEME_CONTEXT_MANAGER_ <nl> + # endif / / TENSORFLOW_PYTHON_PROFILER_INTERNAL_TRACEME_WRAPPER_ <nl> mmm a / tensorflow / python / profiler / trace . py <nl> ppp b / tensorflow / python / profiler / trace . py <nl> def __init__ ( self , name , * * kwargs ) : <nl> training step being traced . <nl> " " " <nl> if _pywrap_traceme . TraceMe . IsEnabled ( ) : <nl> + # Creating _pywrap_traceme . TraceMe starts the clock . <nl> self . _traceme = _pywrap_traceme . TraceMe ( name , * * kwargs ) <nl> else : <nl> self . _traceme = None <nl> <nl> def __enter__ ( self ) : <nl> - if self . _traceme : <nl> - self . _traceme . Enter ( ) <nl> + # Starting the TraceMe clock here would require an extra Python - > C + + call . <nl> return self <nl> <nl> def set_metadata ( self , * * kwargs ) : <nl> def call ( function ) : <nl> self . _traceme . SetMetadata ( * * kwargs ) <nl> <nl> def __exit__ ( self , exc_type , exc_val , exc_tb ) : <nl> - if self . _traceme : <nl> - self . _traceme . Exit ( ) <nl> + # Deallocating _pywrap_traceme . TraceMe stops the clock . <nl> + self . _traceme = None <nl>
Speedup python TraceMe
tensorflow/tensorflow
aff44e4ca1f54cc0d840191775e76e4a72f76c3f
2020-05-26T21:51:16Z
mmm a / PHP_API . hpp <nl> ppp b / PHP_API . hpp <nl> extern " C " <nl> # include " php_streams . h " <nl> # include " php_network . h " <nl> <nl> + # if PHP_MAJOR_VERSION < 7 <nl> + # error " only supports PHP7 or later . " <nl> + # endif <nl> + <nl> # include " zend_interfaces . h " <nl> # include " zend_exceptions . h " <nl> # include " zend_variables . h " <nl> extern " C " <nl> # include < ext / standard / info . h > <nl> # include < ext / standard / php_array . h > <nl> # include " ext / standard / php_var . h " <nl> - <nl> - # if PHP_MAJOR_VERSION < 7 <nl> - # error " only supports PHP7 or later . " <nl> - # endif <nl> } <nl> <nl> # include < unordered_map > <nl> mmm a / swoole_channel . c <nl> ppp b / swoole_channel . c <nl> static PHP_METHOD ( swoole_channel , __construct ) <nl> RETURN_FALSE ; <nl> } <nl> <nl> - if ( size < = 1024 * 128 ) <nl> + if ( size < 1024 * 128 ) <nl> { <nl> size = 1024 * 128 ; <nl> } <nl>
code optimization
swoole/swoole-src
aa08d2fd4e78ed057bb67b2fd6f2a2ac23d6ab6a
2017-03-10T08:29:21Z
mmm a / tensorflow / contrib / gdr / gdr_memory_manager . cc <nl> ppp b / tensorflow / contrib / gdr / gdr_memory_manager . cc <nl> <nl> # include " tensorflow / core / common_runtime / device . h " <nl> # include " tensorflow / core / common_runtime / dma_helper . h " <nl> # if GOOGLE_CUDA <nl> - # include " cuda / include / cuda . h " <nl> # include " tensorflow / core / common_runtime / gpu / gpu_util . h " <nl> # include " tensorflow / core / common_runtime / gpu / process_state . h " <nl> # endif / / GOOGLE_CUDA <nl> Status GdrMemoryManager : : Init ( ) { <nl> <nl> # if GOOGLE_CUDA <nl> VisitableAllocator : : Visitor cuda_alloc_visitor = <nl> - std : : bind ( & GdrMemoryManager : : InsertCUDAMemoryRegion , this , _1 , _2 ) ; <nl> + std : : bind ( & GdrMemoryManager : : InsertMemoryRegion , this , _1 , _2 ) ; <nl> if ( IsGDRAvailable ( ) ) { <nl> / / Note we don ' t free allocated GPU memory so there is no free visitor <nl> int32_t bus_id = TryToReadNumaNode ( listening_ - > verbs - > device ) + 1 ; <nl> void GdrMemoryManager : : InsertMemoryRegion ( void * addr , size_t length ) { <nl> } <nl> } <nl> <nl> - # if GOOGLE_CUDA <nl> - void GdrMemoryManager : : InsertCUDAMemoryRegion ( void * addr , size_t length ) { <nl> - if ( length = = 0 ) return ; <nl> - unsigned int flag = 1 ; <nl> - CUresult result = <nl> - cuPointerSetAttribute ( & flag , CU_POINTER_ATTRIBUTE_SYNC_MEMOPS , <nl> - reinterpret_cast < uintptr_t > ( addr ) ) ; <nl> - if ( result ! = CUDA_SUCCESS ) { <nl> - LOG ( WARNING ) < < " Cannot register memory region to GPU " ; <nl> - } <nl> - ibv_mr * mr = rdma_reg_read ( listening_ . get ( ) , addr , length ) ; <nl> - if ( mr ! = nullptr ) { <nl> - mutex_lock l ( alloc_mu_ ) ; <nl> - auto iter = std : : upper_bound ( mrs_ . begin ( ) , mrs_ . end ( ) , addr , & Comparator ) ; <nl> - mrs_ . insert ( iter , { mr , & MRDeleter } ) ; <nl> - } else { <nl> - LOG ( WARNING ) < < " Cannot register memory region to NIC " ; <nl> - } <nl> - } <nl> - # endif <nl> - <nl> void GdrMemoryManager : : EvictMemoryRegion ( void * addr , size_t length ) { <nl> if ( length = = 0 ) return ; <nl> mutex_lock l ( alloc_mu_ ) ; <nl>
fix unnecessary sync_memops cuda pointer attr in gdr ( )
tensorflow/tensorflow
703fd44bf0ae16574eecc04117391ed8111b7b86
2017-08-10T17:25:05Z
mmm a / tensorflow / contrib / data / python / ops / batching . py <nl> ppp b / tensorflow / contrib / data / python / ops / batching . py <nl> def map_and_batch ( map_func , batch_size , num_parallel_batches = 1 ) : <nl> num_parallel_batches : A ` tf . int64 ` scalar ` tf . Tensor ` , representing the <nl> number of batches to create in parallel . On one hand , higher values can <nl> help mitigate the effect of stragglers . On the other hand , higher values <nl> - can increasing contention if CPU is scarce . <nl> + can increase contention if CPU is scarce . <nl> <nl> Returns : <nl> A ` Dataset ` transformation function , which can be passed to <nl>
[ comment - only change ] : Fix grammar error .
tensorflow/tensorflow
28c80ca9d230fb8b235044702b1d96f9be6c1f10
2018-02-02T18:45:15Z
mmm a / modules / dreamview / frontend / src / components / Offlineview . js <nl> ppp b / modules / dreamview / frontend / src / components / Offlineview . js <nl> import Header from " components / Header " ; <nl> import MainView from " components / Layouts / MainView " ; <nl> import ToolView from " components / Layouts / ToolView " ; <nl> import Loader from " components / common / Loader " ; <nl> - import WS from " store / websocket " ; <nl> <nl> + import HOTKEYS_CONFIG from " store / config / hotkeys . yml " ; <nl> + import WS from " store / websocket " ; <nl> <nl> @ inject ( " store " ) @ observer <nl> - export default class Dreamview extends React . Component { <nl> + export default class Offlineview extends React . Component { <nl> + constructor ( props ) { <nl> + super ( props ) ; <nl> + <nl> + this . handleKeyPress = this . handleKeyPress . bind ( this ) ; <nl> + this . updateDimension = this . props . store . updateDimension . bind ( this . props . store ) ; <nl> + } <nl> + <nl> parseQueryString ( queryString ) { <nl> const params = { } ; <nl> <nl> export default class Dreamview extends React . Component { <nl> componentDidMount ( ) { <nl> const params = this . parseQueryString ( window . location . search ) ; <nl> WS . initialize ( params ) ; <nl> - window . addEventListener ( " resize " , ( ) = > { <nl> - this . props . store . updateDimension ( ) ; <nl> - } ) ; <nl> + window . addEventListener ( " resize " , this . updateDimension , false ) ; <nl> + window . addEventListener ( " keypress " , this . handleKeyPress , false ) ; <nl> + } <nl> + <nl> + componentWillUnmount ( ) { <nl> + window . removeEventListener ( " resize " , this . updateDimension , false ) ; <nl> + window . removeEventListener ( " keypress " , this . handleKeyPress , false ) ; <nl> + } <nl> + <nl> + handleKeyPress ( event ) { <nl> + const optionName = HOTKEYS_CONFIG [ event . key ] ; <nl> + if ( ! optionName ) { <nl> + return ; <nl> + } <nl> + <nl> + const { options } = this . props . store ; <nl> + event . preventDefault ( ) ; <nl> + if ( optionName = = = " cameraAngle " ) { <nl> + options . rotateCameraAngle ( ) ; <nl> + } <nl> } <nl> <nl> render ( ) { <nl>
Offlineview : enable hotkeys ( )
ApolloAuto/apollo
6bd9c84882543c39a48792a73a974afc58d8b616
2019-07-03T23:59:12Z
mmm a / tests / queries / 0_stateless / 01514_distributed_cancel_query_on_error . sh <nl> ppp b / tests / queries / 0_stateless / 01514_distributed_cancel_query_on_error . sh <nl> CURDIR = $ ( cd " $ ( dirname " $ { BASH_SOURCE [ 0 ] } " ) " & & pwd ) <nl> # max_block_size to fail faster <nl> # max_memory_usage / _shard_num / repeat ( ) will allow failure on the first shard earlier . <nl> opts = ( <nl> - - - max_memory_usage = 3G <nl> + - - max_memory_usage = 1G <nl> - - max_block_size = 50 <nl> - - max_threads = 1 <nl> - - max_distributed_connections = 2 <nl> ) <nl> - $ { CLICKHOUSE_CLIENT } " $ { opts [ @ ] } " - q " SELECT groupArray ( repeat ( ' a ' , 1000 * _shard_num ) ) , number % 100000 k from remote ( ' 127 . { 2 , 3 } ' , system . numbers ) GROUP BY k LIMIT 10e6 " | & { <nl> + $ { CLICKHOUSE_CLIENT } " $ { opts [ @ ] } " - q " SELECT groupArray ( repeat ( ' a ' , if ( _shard_num = = 2 , 100000 , 1 ) ) ) , number % 100000 k from remote ( ' 127 . { 2 , 3 } ' , system . numbers ) GROUP BY k LIMIT 10e6 " | & { <nl> # the query should fail earlier on 127 . 3 and 127 . 2 should not even go to the memory limit exceeded error . <nl> fgrep - q ' DB : : Exception : Received from 127 . 3 : 9000 . DB : : Exception : Memory limit ( for query ) exceeded : ' <nl> # while if this will not correctly then it will got the exception from the 127 . 2 : 9000 and fail <nl>
Fix 01514_distributed_cancel_query_on_error flackiness
ClickHouse/ClickHouse
983303243b06819d0ea1405ecf16710815325a32
2020-10-07T22:58:31Z
mmm a / aten / src / ATen / Declarations . cwrap <nl> ppp b / aten / src / ATen / Declarations . cwrap <nl> <nl> - bool largest <nl> - bool sorted <nl> ] ] <nl> - [ [ <nl> - name : _th_exp <nl> - cname : exp <nl> - types : <nl> - - floating_point <nl> - backends : <nl> - - CUDA <nl> - variants : function <nl> - return : argument 0 <nl> - arguments : <nl> - - arg : THTensor * result <nl> - output : True <nl> - - THTensor * self <nl> - ] ] <nl> [ [ <nl> name : _th_erfc <nl> cname : erfc <nl> mmm a / aten / src / ATen / native / UnaryOps . cpp <nl> ppp b / aten / src / ATen / native / UnaryOps . cpp <nl> Tensor & ceil_out ( Tensor & result , const Tensor & self ) { <nl> Tensor ceil ( const Tensor & self ) { return unary_op_impl ( self , at : : ceil_out ) ; } <nl> Tensor & ceil_ ( Tensor & self ) { return unary_op_impl_ ( self , at : : ceil_out ) ; } <nl> <nl> + Tensor & exp_out ( Tensor & result , const Tensor & self ) { return unary_op_impl_out ( result , self , exp_stub ) ; } <nl> + Tensor exp ( const Tensor & self ) { return unary_op_impl ( self , at : : exp_out ) ; } <nl> + Tensor & exp_ ( Tensor & self ) { return unary_op_impl_ ( self , at : : exp_out ) ; } <nl> + <nl> Tensor & expm1_out ( Tensor & result , const Tensor & self ) { return unary_op_impl_out ( result , self , expm1_stub ) ; } <nl> Tensor expm1 ( const Tensor & self ) { return unary_op_impl ( self , at : : expm1_out ) ; } <nl> Tensor & expm1_ ( Tensor & self ) { return unary_op_impl_ ( self , at : : expm1_out ) ; } <nl> Tensor & mvlgamma_ ( Tensor & self , int64_t p ) { <nl> <nl> IMPLEMENT_UNARY_OP_VEC ( erfc ) <nl> IMPLEMENT_UNARY_OP_VEC_CUDA ( erfinv ) <nl> - IMPLEMENT_UNARY_OP_VEC ( exp ) <nl> IMPLEMENT_UNARY_OP_VEC_CUDA ( lgamma ) <nl> <nl> DEFINE_DISPATCH ( abs_stub ) ; <nl> mmm a / aten / src / ATen / native / cuda / CUDAUnaryOps . cpp <nl> ppp b / aten / src / ATen / native / cuda / CUDAUnaryOps . cpp <nl> namespace at { namespace native { <nl> } <nl> <nl> IMPLEMENT_UNARY_OP_PREQUEL ( erfc , legacy : : cuda : : _th_erfc ) <nl> - IMPLEMENT_UNARY_OP_PREQUEL ( exp , legacy : : cuda : : _th_exp ) <nl> <nl> } } <nl> mmm a / aten / src / ATen / native / cuda / LossCTC . cu <nl> ppp b / aten / src / ATen / native / cuda / LossCTC . cu <nl> Tensor ctc_loss_backward_gpu_template ( const Tensor & grad_out , const Tensor & log_ <nl> bool is_large = ( 2 * log_probs . size ( 0 ) + ( 24 * batch_size ) / 10 + ( 2 * num_labels ) / 10 ) > 450 ; <nl> if ( is_large ) { / / large alphabet , large batch <nl> / / this computes the probs , minuend in ( 16 ) <nl> - exp_out ( grad , log_probs ) ; <nl> + at : : exp_out ( grad , log_probs ) ; <nl> / / now we compute the subtrahend for the blanks . It is a straightforward reduction because we know that <nl> / / blanks are in every other position . <nl> / / maybe we should kernelize this , too . <nl> mmm a / aten / src / ATen / native / cuda / UnaryOpsKernel . cu <nl> ppp b / aten / src / ATen / native / cuda / UnaryOpsKernel . cu <nl> void bitwise_not_kernel_cuda ( TensorIterator & iter ) { <nl> } <nl> } <nl> <nl> + void exp_kernel_cuda ( TensorIterator & iter ) { <nl> + AT_DISPATCH_FLOATING_TYPES_AND_HALF ( iter . dtype ( ) , " exp_cuda " , [ & ] ( ) { <nl> + gpu_kernel ( iter , [ ] GPU_LAMBDA ( scalar_t a ) - > scalar_t { <nl> + return : : exp ( a ) ; <nl> + } ) ; <nl> + } ) ; <nl> + } <nl> + <nl> void expm1_kernel_cuda ( TensorIterator & iter ) { <nl> AT_DISPATCH_FLOATING_TYPES_AND_HALF ( iter . dtype ( ) , " expm1_cuda " , [ & ] ( ) { <nl> gpu_kernel ( iter , [ ] GPU_LAMBDA ( scalar_t a ) - > scalar_t { <nl> void clamp_max_kernel_cuda ( TensorIterator & iter , Scalar max_value ) { <nl> } <nl> <nl> REGISTER_DISPATCH ( bitwise_not_stub , & bitwise_not_kernel_cuda ) ; <nl> + REGISTER_DISPATCH ( exp_stub , & exp_kernel_cuda ) ; <nl> REGISTER_DISPATCH ( expm1_stub , & expm1_kernel_cuda ) ; <nl> REGISTER_DISPATCH ( rsqrt_stub , & rsqrt_kernel_cuda ) ; <nl> REGISTER_DISPATCH ( sqrt_stub , & sqrt_kernel_cuda ) ; <nl> mmm a / aten / src / ATen / native / native_functions . yaml <nl> ppp b / aten / src / ATen / native / native_functions . yaml <nl> <nl> - func : exp_ ( Tensor ( a ! ) self ) - > Tensor ( a ! ) <nl> supports_named_tensor : True <nl> variants : function , method <nl> - dispatch : <nl> - CPU : _exp__cpu <nl> - CUDA : _exp__cuda <nl> <nl> - func : exp . out ( Tensor self , * , Tensor ( a ! ) out ) - > Tensor ( a ! ) <nl> supports_named_tensor : True <nl> - dispatch : <nl> - CPU : _exp_out_cpu <nl> - CUDA : _exp_out_cuda <nl> <nl> - func : expm1 ( Tensor self ) - > Tensor <nl> use_c10_dispatcher : full <nl> mmm a / aten / src / TH / generic / THVector . h <nl> ppp b / aten / src / TH / generic / THVector . h <nl> TH_API void THVector_ ( neg ) ( scalar_t * y , const scalar_t * x , const ptrdiff_t n ) ; <nl> / * floating point only now * / <nl> # if defined ( TH_REAL_IS_FLOAT ) | | defined ( TH_REAL_IS_DOUBLE ) <nl> <nl> - TH_API void THVector_ ( exp ) ( scalar_t * y , const scalar_t * x , const ptrdiff_t n ) ; <nl> TH_API void THVector_ ( erfc ) ( scalar_t * y , const scalar_t * x , const ptrdiff_t n ) ; <nl> TH_API void THVector_ ( pow ) ( scalar_t * y , const scalar_t * x , const scalar_t c , const ptrdiff_t n ) ; <nl> <nl> mmm a / aten / src / THC / THCNumerics . cuh <nl> ppp b / aten / src / THC / THCNumerics . cuh <nl> struct THCNumerics < at : : Half > { <nl> static inline __host__ __device__ bool eq ( at : : Half a , at : : Half b ) { return a = = b ; } <nl> static inline __host__ __device__ bool ne ( at : : Half a , at : : Half b ) { return a ! = b ; } <nl> <nl> - static inline __host__ __device__ at : : Half exp ( at : : Half a ) { return std : : exp ( a ) ; } <nl> static inline __host__ __device__ at : : Half sqrt ( at : : Half a ) { return : : sqrt ( a ) ; } <nl> static inline __host__ __device__ at : : Half atan ( at : : Half a ) { return : : atan ( a ) ; } <nl> static inline __host__ __device__ at : : Half erfc ( at : : Half a ) { return : : erfc ( a ) ; } <nl> struct THCNumerics < float > { <nl> static inline __host__ __device__ bool eq ( float a , float b ) { return a = = b ; } <nl> static inline __host__ __device__ bool ne ( float a , float b ) { return a ! = b ; } <nl> <nl> - static inline __host__ __device__ float exp ( float a ) { return expf ( a ) ; } <nl> static inline __host__ __device__ float sqrt ( float a ) { return sqrtf ( a ) ; } <nl> static inline __host__ __device__ float atan ( float a ) { return atanf ( a ) ; } <nl> static inline __host__ __device__ float erfc ( float a ) { return erfcf ( a ) ; } <nl> struct THCNumerics < at : : BFloat16 > { <nl> static inline __host__ __device__ bool eq ( at : : BFloat16 a , at : : BFloat16 b ) { return a = = b ; } <nl> static inline __host__ __device__ bool ne ( at : : BFloat16 a , at : : BFloat16 b ) { return a ! = b ; } <nl> <nl> - static inline __host__ __device__ at : : BFloat16 exp ( at : : BFloat16 a ) { return expf ( a ) ; } <nl> static inline __host__ __device__ at : : BFloat16 sqrt ( at : : BFloat16 a ) { return sqrtf ( a ) ; } <nl> static inline __host__ __device__ at : : BFloat16 atan ( at : : BFloat16 a ) { return atanf ( a ) ; } <nl> static inline __host__ __device__ at : : BFloat16 erfc ( at : : BFloat16 a ) { return erfcf ( a ) ; } <nl> struct THCNumerics < double > { <nl> static inline __host__ __device__ bool eq ( double a , double b ) { return a = = b ; } <nl> static inline __host__ __device__ bool ne ( double a , double b ) { return a ! = b ; } <nl> <nl> - static inline __host__ __device__ double exp ( double a ) { return : : exp ( a ) ; } <nl> static inline __host__ __device__ double sqrt ( double a ) { return : : sqrt ( a ) ; } <nl> static inline __host__ __device__ double atan ( double a ) { return : : atan ( a ) ; } <nl> static inline __host__ __device__ double erfc ( double a ) { return : : erfc ( a ) ; } <nl> mmm a / aten / src / THC / generic / THCTensorMathPointwise . cu <nl> ppp b / aten / src / THC / generic / THCTensorMathPointwise . cu <nl> static void propagate_names_if_named_tensor_enabled ( THCTensor * result , THCTensor <nl> <nl> # if defined ( THC_REAL_IS_FLOAT ) | | defined ( THC_REAL_IS_DOUBLE ) | | defined ( THC_REAL_IS_HALF ) <nl> <nl> - IMPLEMENT_CUDA_TENSOR_BASIC_FUNC ( exp , THCNumerics < scalar_t > : : exp , Real ) <nl> IMPLEMENT_CUDA_TENSOR_BASIC_FUNC ( sqrt , THCNumerics < scalar_t > : : sqrt , Real ) <nl> IMPLEMENT_CUDA_TENSOR_BASIC_FUNC ( erfc , THCNumerics < scalar_t > : : erfc , Real ) <nl> <nl> mmm a / aten / src / THC / generic / THCTensorMathPointwise . h <nl> ppp b / aten / src / THC / generic / THCTensorMathPointwise . h <nl> THC_API void THCTensor_ ( cminValue ) ( THCState * state , THCTensor * self , THCTensor * <nl> <nl> # if defined ( THC_REAL_IS_FLOAT ) | | defined ( THC_REAL_IS_DOUBLE ) | | defined ( THC_REAL_IS_HALF ) <nl> <nl> - THC_API void THCTensor_ ( exp ) ( THCState * state , THCTensor * self , THCTensor * src ) ; <nl> THC_API void THCTensor_ ( atan ) ( THCState * state , THCTensor * self , THCTensor * src ) ; <nl> THC_API void THCTensor_ ( erfc ) ( THCState * state , THCTensor * self , THCTensor * src ) ; <nl> THC_API void THCTensor_ ( sqrt ) ( THCState * state , THCTensor * self , THCTensor * src ) ; <nl> mmm a / aten / src / THCUNN / LogSigmoid . cu <nl> ppp b / aten / src / THCUNN / LogSigmoid . cu <nl> struct logSigmoid_updateOutput_functor <nl> { <nl> __device__ void operator ( ) ( T * output , const T * input ) const { <nl> const T max = fmaxType ( T { 0 } , - * input ) ; <nl> - const T z = THCNumerics < T > : : exp ( - max ) + THCNumerics < T > : : exp ( - * input - max ) ; <nl> + const T z = : : exp ( - max ) + : : exp ( - * input - max ) ; <nl> * output = - ( max + static_cast < T > ( std : : log ( z ) ) ) ; <nl> } <nl> } ; <nl> struct logSigmoid_updateGradInput_functor <nl> { <nl> __device__ void operator ( ) ( T * gradInput , const T * input , const T * gradOutput ) const { <nl> const T max = fmaxType ( T { 0 } , - * input ) ; <nl> - const T z = THCNumerics < T > : : exp ( - max ) + THCNumerics < T > : : exp ( - * input - max ) ; <nl> + const T z = : : exp ( - max ) + : : exp ( - * input - max ) ; <nl> T max_deriv = 0 . f ; <nl> T sign = - 1 . f ; <nl> if ( * input < 0 . f ) { <nl> struct logSigmoid_updateOutput_functor < half > { <nl> __device__ __forceinline__ void operator ( ) ( half * output , const half * input ) const { <nl> float in = __half2float ( * input ) ; <nl> float max = fmaxType ( 0 . f , - in ) ; <nl> - float z = THCNumerics < float > : : exp ( - max ) + THCNumerics < float > : : exp ( - in - max ) ; <nl> + float z = : : exp ( - max ) + : : exp ( - in - max ) ; <nl> * output = __float2half ( - ( max + std : : log ( z ) ) ) ; <nl> } <nl> } ; <nl> struct logSigmoid_updateGradInput_functor < half > { <nl> __device__ __forceinline__ void operator ( ) ( half * gradInput , const half * input , const half * gradOutput ) const { <nl> const float in = __half2float ( * input ) ; <nl> const float max = fmaxType ( 0 . f , - in ) ; <nl> - const float z = THCNumerics < float > : : exp ( - max ) + THCNumerics < float > : : exp ( - in - max ) ; <nl> + const float z = : : exp ( - max ) + : : exp ( - in - max ) ; <nl> const float go = __half2float ( * gradOutput ) ; <nl> float max_deriv = 0 . f ; <nl> float sign = - 1 . f ; <nl> mmm a / aten / src / THCUNN / THCHalfAutoNumerics . cuh <nl> ppp b / aten / src / THCUNN / THCHalfAutoNumerics . cuh <nl> inline __host__ __device__ double fmaxType ( double x , double y ) { <nl> <nl> / / arithmetic functions <nl> <nl> - inline __host__ __device__ THHalf exp ( THHalf a ) { <nl> - return THCNumerics < THHalf > : : exp ( a ) ; <nl> - } <nl> - <nl> inline __host__ __device__ THHalf pow ( THHalf a , THHalf b ) { <nl> return THCNumerics < THHalf > : : pow ( a , b ) ; <nl> } <nl> mmm a / test / test_torch . py <nl> ppp b / test / test_torch . py <nl> def test_unary_out_op_mem_overlap ( self , device , dtype ) : <nl> ( " erfinv " , doubles , True , True , ' cpu ' ) , <nl> ( " erfinv " , doubles , True , True , ' cuda ' ) , <nl> ( " exp " , doubles , True , True , ' cpu ' ) , <nl> - ( " exp " , doubles , False , True , ' cuda ' ) , <nl> + ( " exp " , doubles , True , True , ' cuda ' ) , <nl> ( " expm1 " , doubles , True , True , ' cpu ' ) , <nl> ( " expm1 " , doubles , True , True , ' cuda ' ) , <nl> ( " floor " , doubles , True , True , ' cpu ' ) , <nl>
Migrate ` exp ` and ` exp_ ` from the TH to Aten ( CUDA ) ( )
pytorch/pytorch
d86de916a9a4c899f174ac7104d7283628a782ad
2020-05-13T17:06:51Z
mmm a / caffe2 / perfkernels / adagrad . h <nl> ppp b / caffe2 / perfkernels / adagrad . h <nl> static inline void adagrad_update_base_inlined ( <nl> float gi = g [ i ] ; <nl> float hi = decay * h [ i ] + gi * gi ; <nl> nh [ i ] = hi ; <nl> - nw [ i ] = w [ i ] + lr * gi / ( std : : sqrt ( hi ) + epsilon ) ; <nl> + nw [ i ] = w [ i ] + lr / ( std : : sqrt ( hi ) + epsilon ) * gi ; <nl> } <nl> } <nl> <nl> int sparse_adagrad ( <nl> if ( block_size = = 1 ) { \ <nl> float gi = g [ i ] ; \ <nl> float hi = nh [ idx ] = h [ idx ] + gi * gi ; \ <nl> - nw [ idx ] = w [ idx ] + lr * gi / ( std : : sqrt ( hi ) + epsilon ) ; \ <nl> + nw [ idx ] = w [ idx ] + lr / ( std : : sqrt ( hi ) + epsilon ) * gi ; \ <nl> } else { \ <nl> const int prefdist_T0 = 16 ; \ <nl> int i_pref = ( i < num_rows - prefdist_T0 ) ? i + prefdist_T0 : i ; \ <nl> mmm a / caffe2 / perfkernels / adagrad_avx . cc <nl> ppp b / caffe2 / perfkernels / adagrad_avx . cc <nl> void adagrad_update__avx_f16c ( <nl> _mm256_mul_ps ( _mm256_set1_ps ( decay ) , hi ) , _mm256_mul_ps ( gi , gi ) ) ; <nl> _mm256_storeu_ps ( nh + i , nhi ) ; <nl> __m256 vtmp = _mm256_div_ps ( <nl> - gi , _mm256_add_ps ( _mm256_sqrt_ps ( nhi ) , _mm256_set1_ps ( epsilon ) ) ) ; <nl> - _mm256_storeu_ps ( <nl> - nw + i , _mm256_add_ps ( wi , _mm256_mul_ps ( _mm256_set1_ps ( lr ) , vtmp ) ) ) ; <nl> + _mm256_set1_ps ( lr ) , <nl> + _mm256_add_ps ( _mm256_sqrt_ps ( nhi ) , _mm256_set1_ps ( epsilon ) ) ) ; <nl> + _mm256_storeu_ps ( nw + i , _mm256_add_ps ( wi , _mm256_mul_ps ( gi , vtmp ) ) ) ; <nl> } <nl> <nl> for ( ; i < N ; + + i ) { <nl> float gi = g [ i ] ; <nl> float hi = nh [ i ] = decay * h [ i ] + gi * gi ; <nl> - nw [ i ] = w [ i ] + lr * gi / ( std : : sqrt ( hi ) + epsilon ) ; <nl> + nw [ i ] = w [ i ] + lr / ( std : : sqrt ( hi ) + epsilon ) * gi ; <nl> } <nl> } <nl> <nl> void adagrad_fp16_update_prefetch__avx_f16c ( <nl> _mm_storeu_si128 ( reinterpret_cast < __m128i * > ( nh + i ) , nhhi ) ; <nl> <nl> __m256 vtmp = _mm256_div_ps ( <nl> - gi , _mm256_add_ps ( _mm256_sqrt_ps ( nhi ) , _mm256_set1_ps ( epsilon ) ) ) ; <nl> - __m256 nwi = _mm256_add_ps ( wi , _mm256_mul_ps ( _mm256_set1_ps ( lr ) , vtmp ) ) ; <nl> + _mm256_set1_ps ( lr ) , <nl> + _mm256_add_ps ( _mm256_sqrt_ps ( nhi ) , _mm256_set1_ps ( epsilon ) ) ) ; <nl> + __m256 nwi = _mm256_add_ps ( wi , _mm256_mul_ps ( gi , vtmp ) ) ; <nl> __m128i nhwi = _mm256_cvtps_ph ( nwi , 0 ) ; <nl> _mm_storeu_si128 ( reinterpret_cast < __m128i * > ( nw + i ) , nhwi ) ; <nl> } <nl> void adagrad_fp16_update_prefetch__avx_f16c ( <nl> _cvtsh_ss ( reinterpret_cast < const unsigned short * > ( h ) [ i ] ) + gi * gi ; <nl> reinterpret_cast < unsigned short * > ( nh ) [ i ] = _cvtss_sh ( nhi , 0 ) ; <nl> float nwi = _cvtsh_ss ( reinterpret_cast < const unsigned short * > ( w ) [ i ] ) + <nl> - lr * gi / ( std : : sqrt ( nhi ) + epsilon ) ; <nl> + lr / ( std : : sqrt ( nhi ) + epsilon ) * gi ; <nl> reinterpret_cast < unsigned short * > ( nw ) [ i ] = _cvtss_sh ( nwi , 0 ) ; <nl> } <nl> } <nl> mmm a / caffe2 / sgd / adagrad_op . h <nl> ppp b / caffe2 / sgd / adagrad_op . h <nl> class SparseAdagradOp final : public Operator < Context > { <nl> if ( block_size = = 1 ) { <nl> float gi = gradIn [ i ] ; <nl> float hi = momentOut [ idx ] = momentIn [ idx ] + gi * gi ; <nl> - paramOut [ idx ] = paramIn [ idx ] + lr [ 0 ] * gi / ( std : : sqrt ( hi ) + epsilon_ ) ; <nl> + paramOut [ idx ] = paramIn [ idx ] + lr [ 0 ] / ( std : : sqrt ( hi ) + epsilon_ ) * gi ; <nl> } else { <nl> auto offsetI = i * block_size ; <nl> auto offsetIdx = idx * block_size ; <nl> class RowWiseSparseAdagradOp final : public Operator < Context > { <nl> if ( block_size = = 1 ) { <nl> float gi = gradIn [ i ] ; <nl> float hi = momentOut [ idx ] = momentIn [ idx ] + gi * gi ; <nl> - paramOut [ idx ] = paramIn [ idx ] + lr [ 0 ] * gi / ( std : : sqrt ( hi ) + epsilon_ ) ; <nl> + paramOut [ idx ] = paramIn [ idx ] + lr [ 0 ] / ( std : : sqrt ( hi ) + epsilon_ ) * gi ; <nl> } else { <nl> auto offsetI = i * block_size ; <nl> auto offsetIdx = idx * block_size ; <nl>
make the order btw div and mul in adagrad update consistent ( )
pytorch/pytorch
d32f261f1666e60a7d9d0e26073475c3ce80e108
2019-12-02T21:53:38Z
new file mode 100644 <nl> index 00000000000 . . 35f6497c9e3 <nl> mmm / dev / null <nl> ppp b / cmake / FindCUDA . cmake <nl> <nl> + # . rst : <nl> + # FindCUDA <nl> + # mmmmmm - - <nl> + # <nl> + # Tools for building CUDA C files : libraries and build dependencies . <nl> + # <nl> + # This script locates the NVIDIA CUDA C tools . It should work on linux , <nl> + # windows , and mac and should be reasonably up to date with CUDA C <nl> + # releases . <nl> + # <nl> + # This script makes use of the standard find_package arguments of <nl> + # < VERSION > , REQUIRED and QUIET . CUDA_FOUND will report if an <nl> + # acceptable version of CUDA was found . <nl> + # <nl> + # The script will prompt the user to specify CUDA_TOOLKIT_ROOT_DIR if <nl> + # the prefix cannot be determined by the location of nvcc in the system <nl> + # path and REQUIRED is specified to find_package ( ) . To use a different <nl> + # installed version of the toolkit set the environment variable <nl> + # CUDA_BIN_PATH before running cmake ( e . g . <nl> + # CUDA_BIN_PATH = / usr / local / cuda1 . 0 instead of the default <nl> + # / usr / local / cuda ) or set CUDA_TOOLKIT_ROOT_DIR after configuring . If <nl> + # you change the value of CUDA_TOOLKIT_ROOT_DIR , various components that <nl> + # depend on the path will be relocated . <nl> + # <nl> + # It might be necessary to set CUDA_TOOLKIT_ROOT_DIR manually on certain <nl> + # platforms , or to use a cuda runtime not installed in the default <nl> + # location . In newer versions of the toolkit the cuda library is <nl> + # included with the graphics driver - be sure that the driver version <nl> + # matches what is needed by the cuda runtime version . <nl> + # <nl> + # The following variables affect the behavior of the macros in the <nl> + # script ( in alphebetical order ) . Note that any of these flags can be <nl> + # changed multiple times in the same directory before calling <nl> + # CUDA_ADD_EXECUTABLE , CUDA_ADD_LIBRARY , CUDA_COMPILE , CUDA_COMPILE_PTX <nl> + # or CUDA_WRAP_SRCS . <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_64_BIT_DEVICE_CODE ( Default matches host bit size ) <nl> + # - - Set to ON to compile for 64 bit device code , OFF for 32 bit device code . <nl> + # Note that making this different from the host code when generating object <nl> + # or C files from CUDA code just won ' t work , because size_t gets defined by <nl> + # nvcc in the generated source . If you compile to PTX and then load the <nl> + # file yourself , you can mix bit sizes between device and host . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE ( Default ON ) <nl> + # - - Set to ON if you want the custom build rule to be attached to the source <nl> + # file in Visual Studio . Turn OFF if you add the same cuda file to multiple <nl> + # targets . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # This allows the user to build the target from the CUDA file ; however , bad <nl> + # things can happen if the CUDA source file is added to multiple targets . <nl> + # When performing parallel builds it is possible for the custom build <nl> + # command to be run more than once and in parallel causing cryptic build <nl> + # errors . VS runs the rules for every source file in the target , and a <nl> + # source can have only one rule no matter how many projects it is added to . <nl> + # When the rule is run from multiple targets race conditions can occur on <nl> + # the generated file . Eventually everything will get built , but if the user <nl> + # is unaware of this behavior , there may be confusion . It would be nice if <nl> + # this script could detect the reuse of source files across multiple targets <nl> + # and turn the option off for the user , but no good solution could be found . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_BUILD_CUBIN ( Default OFF ) <nl> + # - - Set to ON to enable and extra compilation pass with the - cubin option in <nl> + # Device mode . The output is parsed and register , shared memory usage is <nl> + # printed during build . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_BUILD_EMULATION ( Default OFF for device mode ) <nl> + # - - Set to ON for Emulation mode . - D_DEVICEEMU is defined for CUDA C files <nl> + # when CUDA_BUILD_EMULATION is TRUE . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_GENERATED_OUTPUT_DIR ( Default CMAKE_CURRENT_BINARY_DIR ) <nl> + # - - Set to the path you wish to have the generated files placed . If it is <nl> + # blank output files will be placed in CMAKE_CURRENT_BINARY_DIR . <nl> + # Intermediate files will always be placed in <nl> + # CMAKE_CURRENT_BINARY_DIR / CMakeFiles . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_HOST_COMPILATION_CPP ( Default ON ) <nl> + # - - Set to OFF for C compilation of host code . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_HOST_COMPILER ( Default CMAKE_C_COMPILER , $ ( VCInstallDir ) / bin for VS ) <nl> + # - - Set the host compiler to be used by nvcc . Ignored if - ccbin or <nl> + # - - compiler - bindir is already present in the CUDA_NVCC_FLAGS or <nl> + # CUDA_NVCC_FLAGS_ < CONFIG > variables . For Visual Studio targets <nl> + # $ ( VCInstallDir ) / bin is a special value that expands out to the path when <nl> + # the command is run from withing VS . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_NVCC_FLAGS <nl> + # CUDA_NVCC_FLAGS_ < CONFIG > <nl> + # - - Additional NVCC command line arguments . NOTE : multiple arguments must be <nl> + # semi - colon delimited ( e . g . - - compiler - options ; - Wall ) <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_PROPAGATE_HOST_FLAGS ( Default ON ) <nl> + # - - Set to ON to propagate CMAKE_ { C , CXX } _FLAGS and their configuration <nl> + # dependent counterparts ( e . g . CMAKE_C_FLAGS_DEBUG ) automatically to the <nl> + # host compiler through nvcc ' s - Xcompiler flag . This helps make the <nl> + # generated host code match the rest of the system better . Sometimes <nl> + # certain flags give nvcc problems , and this will help you turn the flag <nl> + # propagation off . This does not affect the flags supplied directly to nvcc <nl> + # via CUDA_NVCC_FLAGS or through the OPTION flags specified through <nl> + # CUDA_ADD_LIBRARY , CUDA_ADD_EXECUTABLE , or CUDA_WRAP_SRCS . Flags used for <nl> + # shared library compilation are not affected by this flag . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_SEPARABLE_COMPILATION ( Default OFF ) <nl> + # - - If set this will enable separable compilation for all CUDA runtime object <nl> + # files . If used outside of CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY <nl> + # ( e . g . calling CUDA_WRAP_SRCS directly ) , <nl> + # CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME and <nl> + # CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS should be called . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_VERBOSE_BUILD ( Default OFF ) <nl> + # - - Set to ON to see all the commands used when building the CUDA file . When <nl> + # using a Makefile generator the value defaults to VERBOSE ( run make <nl> + # VERBOSE = 1 to see output ) , although setting CUDA_VERBOSE_BUILD to ON will <nl> + # always print the output . <nl> + # <nl> + # <nl> + # <nl> + # The script creates the following macros ( in alphebetical order ) : <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_ADD_CUFFT_TO_TARGET ( cuda_target ) <nl> + # - - Adds the cufft library to the target ( can be any target ) . Handles whether <nl> + # you are in emulation mode or not . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_ADD_CUBLAS_TO_TARGET ( cuda_target ) <nl> + # - - Adds the cublas library to the target ( can be any target ) . Handles <nl> + # whether you are in emulation mode or not . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_ADD_EXECUTABLE ( cuda_target file0 file1 . . . <nl> + # [ WIN32 ] [ MACOSX_BUNDLE ] [ EXCLUDE_FROM_ALL ] [ OPTIONS . . . ] ) <nl> + # - - Creates an executable " cuda_target " which is made up of the files <nl> + # specified . All of the non CUDA C files are compiled using the standard <nl> + # build rules specified by CMAKE and the cuda files are compiled to object <nl> + # files using nvcc and the host compiler . In addition CUDA_INCLUDE_DIRS is <nl> + # added automatically to include_directories ( ) . Some standard CMake target <nl> + # calls can be used on the target after calling this macro <nl> + # ( e . g . set_target_properties and target_link_libraries ) , but setting <nl> + # properties that adjust compilation flags will not affect code compiled by <nl> + # nvcc . Such flags should be modified before calling CUDA_ADD_EXECUTABLE , <nl> + # CUDA_ADD_LIBRARY or CUDA_WRAP_SRCS . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_ADD_LIBRARY ( cuda_target file0 file1 . . . <nl> + # [ STATIC | SHARED | MODULE ] [ EXCLUDE_FROM_ALL ] [ OPTIONS . . . ] ) <nl> + # - - Same as CUDA_ADD_EXECUTABLE except that a library is created . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_BUILD_CLEAN_TARGET ( ) <nl> + # - - Creates a convience target that deletes all the dependency files <nl> + # generated . You should make clean after running this target to ensure the <nl> + # dependency files get regenerated . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_COMPILE ( generated_files file0 file1 . . . [ STATIC | SHARED | MODULE ] <nl> + # [ OPTIONS . . . ] ) <nl> + # - - Returns a list of generated files from the input source files to be used <nl> + # with ADD_LIBRARY or ADD_EXECUTABLE . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_COMPILE_PTX ( generated_files file0 file1 . . . [ OPTIONS . . . ] ) <nl> + # - - Returns a list of PTX files generated from the input source files . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME ( output_file_var <nl> + # cuda_target <nl> + # object_files ) <nl> + # - - Compute the name of the intermediate link file used for separable <nl> + # compilation . This file name is typically passed into <nl> + # CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS . output_file_var is produced <nl> + # based on cuda_target the list of objects files that need separable <nl> + # compilation as specified by object_files . If the object_files list is <nl> + # empty , then output_file_var will be empty . This function is called <nl> + # automatically for CUDA_ADD_LIBRARY and CUDA_ADD_EXECUTABLE . Note that <nl> + # this is a function and not a macro . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_INCLUDE_DIRECTORIES ( path0 path1 . . . ) <nl> + # - - Sets the directories that should be passed to nvcc <nl> + # ( e . g . nvcc - Ipath0 - Ipath1 . . . ) . These paths usually contain other . cu <nl> + # files . <nl> + # <nl> + # <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS ( output_file_var cuda_target <nl> + # nvcc_flags object_files ) <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # - - Generates the link object required by separable compilation from the given <nl> + # object files . This is called automatically for CUDA_ADD_EXECUTABLE and <nl> + # CUDA_ADD_LIBRARY , but can be called manually when using CUDA_WRAP_SRCS <nl> + # directly . When called from CUDA_ADD_LIBRARY or CUDA_ADD_EXECUTABLE the <nl> + # nvcc_flags passed in are the same as the flags passed in via the OPTIONS <nl> + # argument . The only nvcc flag added automatically is the bitness flag as <nl> + # specified by CUDA_64_BIT_DEVICE_CODE . Note that this is a function <nl> + # instead of a macro . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_WRAP_SRCS ( cuda_target format generated_files file0 file1 . . . <nl> + # [ STATIC | SHARED | MODULE ] [ OPTIONS . . . ] ) <nl> + # - - This is where all the magic happens . CUDA_ADD_EXECUTABLE , <nl> + # CUDA_ADD_LIBRARY , CUDA_COMPILE , and CUDA_COMPILE_PTX all call this <nl> + # function under the hood . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # Given the list of files ( file0 file1 . . . fileN ) this macro generates <nl> + # custom commands that generate either PTX or linkable objects ( use " PTX " or <nl> + # " OBJ " for the format argument to switch ) . Files that don ' t end with . cu <nl> + # or have the HEADER_FILE_ONLY property are ignored . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # The arguments passed in after OPTIONS are extra command line options to <nl> + # give to nvcc . You can also specify per configuration options by <nl> + # specifying the name of the configuration followed by the options . General <nl> + # options must preceed configuration specific options . Not all <nl> + # configurations need to be specified , only the ones provided will be used . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # OPTIONS - DFLAG = 2 " - DFLAG_OTHER = space in flag " <nl> + # DEBUG - g <nl> + # RELEASE - - use_fast_math <nl> + # RELWITHDEBINFO - - use_fast_math ; - g <nl> + # MINSIZEREL - - use_fast_math <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # For certain configurations ( namely VS generating object files with <nl> + # CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE set to ON ) , no generated file will <nl> + # be produced for the given cuda file . This is because when you add the <nl> + # cuda file to Visual Studio it knows that this file produces an object file <nl> + # and will link in the resulting object file automatically . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # This script will also generate a separate cmake script that is used at <nl> + # build time to invoke nvcc . This is for several reasons . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # 1 . nvcc can return negative numbers as return values which confuses <nl> + # Visual Studio into thinking that the command succeeded . The script now <nl> + # checks the error codes and produces errors when there was a problem . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # 2 . nvcc has been known to not delete incomplete results when it <nl> + # encounters problems . This confuses build systems into thinking the <nl> + # target was generated when in fact an unusable file exists . The script <nl> + # now deletes the output files if there was an error . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # 3 . By putting all the options that affect the build into a file and then <nl> + # make the build rule dependent on the file , the output files will be <nl> + # regenerated when the options change . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # This script also looks at optional arguments STATIC , SHARED , or MODULE to <nl> + # determine when to target the object compilation for a shared library . <nl> + # BUILD_SHARED_LIBS is ignored in CUDA_WRAP_SRCS , but it is respected in <nl> + # CUDA_ADD_LIBRARY . On some systems special flags are added for building <nl> + # objects intended for shared libraries . A preprocessor macro , <nl> + # < target_name > _EXPORTS is defined when a shared library compilation is <nl> + # detected . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # Flags passed into add_definitions with - D or / D are passed along to nvcc . <nl> + # <nl> + # <nl> + # <nl> + # The script defines the following variables : <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_VERSION_MAJOR - - The major version of cuda as reported by nvcc . <nl> + # CUDA_VERSION_MINOR - - The minor version . <nl> + # CUDA_VERSION <nl> + # CUDA_VERSION_STRING - - CUDA_VERSION_MAJOR . CUDA_VERSION_MINOR <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # CUDA_TOOLKIT_ROOT_DIR - - Path to the CUDA Toolkit ( defined if not set ) . <nl> + # CUDA_SDK_ROOT_DIR - - Path to the CUDA SDK . Use this to find files in the <nl> + # SDK . This script will not directly support finding <nl> + # specific libraries or headers , as that isn ' t <nl> + # supported by NVIDIA . If you want to change <nl> + # libraries when the path changes see the <nl> + # FindCUDA . cmake script for an example of how to clear <nl> + # these variables . There are also examples of how to <nl> + # use the CUDA_SDK_ROOT_DIR to locate headers or <nl> + # libraries , if you so choose ( at your own risk ) . <nl> + # CUDA_INCLUDE_DIRS - - Include directory for cuda headers . Added automatically <nl> + # for CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY . <nl> + # CUDA_LIBRARIES - - Cuda RT library . <nl> + # CUDA_CUFFT_LIBRARIES - - Device or emulation library for the Cuda FFT <nl> + # implementation ( alternative to : <nl> + # CUDA_ADD_CUFFT_TO_TARGET macro ) <nl> + # CUDA_CUBLAS_LIBRARIES - - Device or emulation library for the Cuda BLAS <nl> + # implementation ( alterative to : <nl> + # CUDA_ADD_CUBLAS_TO_TARGET macro ) . <nl> + # CUDA_cupti_LIBRARY - - CUDA Profiling Tools Interface library . <nl> + # Only available for CUDA version 4 . 0 + . <nl> + # CUDA_curand_LIBRARY - - CUDA Random Number Generation library . <nl> + # Only available for CUDA version 3 . 2 + . <nl> + # CUDA_cusparse_LIBRARY - - CUDA Sparse Matrix library . <nl> + # Only available for CUDA version 3 . 2 + . <nl> + # CUDA_npp_LIBRARY - - NVIDIA Performance Primitives library . <nl> + # Only available for CUDA version 4 . 0 + . <nl> + # CUDA_nppc_LIBRARY - - NVIDIA Performance Primitives library ( core ) . <nl> + # Only available for CUDA version 5 . 5 + . <nl> + # CUDA_nppi_LIBRARY - - NVIDIA Performance Primitives library ( image processing ) . <nl> + # Only available for CUDA version 5 . 5 + . <nl> + # CUDA_npps_LIBRARY - - NVIDIA Performance Primitives library ( signal processing ) . <nl> + # Only available for CUDA version 5 . 5 + . <nl> + # CUDA_nvcuvenc_LIBRARY - - CUDA Video Encoder library . <nl> + # Only available for CUDA version 3 . 2 + . <nl> + # Windows only . <nl> + # CUDA_nvcuvid_LIBRARY - - CUDA Video Decoder library . <nl> + # Only available for CUDA version 3 . 2 + . <nl> + # Windows only . <nl> + # <nl> + # <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # James Bigler , NVIDIA Corp ( nvidia . com - jbigler ) <nl> + # Abe Stephens , SCI Institute - - http : / / www . sci . utah . edu / ~ abe / FindCuda . html <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # Copyright ( c ) 2008 - 2009 NVIDIA Corporation . All rights reserved . <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # Copyright ( c ) 2007 - 2009 <nl> + # Scientific Computing and Imaging Institute , University of Utah <nl> + # <nl> + # <nl> + # <nl> + # : : <nl> + # <nl> + # This code is licensed under the MIT License . See the FindCUDA . cmake script <nl> + # for the text of the license . <nl> + <nl> + # The MIT License <nl> + # <nl> + # License for the specific language governing rights and limitations under <nl> + # Permission is hereby granted , free of charge , to any person obtaining a <nl> + # copy of this software and associated documentation files ( the " Software " ) , <nl> + # to deal in the Software without restriction , including without limitation <nl> + # the rights to use , copy , modify , merge , publish , distribute , sublicense , <nl> + # and / or sell copies of the Software , and to permit persons to whom the <nl> + # Software is furnished to do so , subject to the following conditions : <nl> + # <nl> + # The above copyright notice and this permission notice shall be included <nl> + # in all copies or substantial portions of the Software . <nl> + # <nl> + # THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS <nl> + # OR IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> + # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL <nl> + # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> + # LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING <nl> + # FROM , OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER <nl> + # DEALINGS IN THE SOFTWARE . <nl> + # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + <nl> + # FindCUDA . cmake <nl> + <nl> + # We need to have at least this version to support the VERSION_LESS argument to ' if ' ( 2 . 6 . 2 ) and unset ( 2 . 6 . 3 ) <nl> + cmake_policy ( PUSH ) <nl> + cmake_minimum_required ( VERSION 2 . 6 . 3 ) <nl> + cmake_policy ( POP ) <nl> + <nl> + # This macro helps us find the location of helper files we will need the full path to <nl> + macro ( CUDA_FIND_HELPER_FILE _name _extension ) <nl> + set ( _full_name " $ { _name } . $ { _extension } " ) <nl> + # CMAKE_CURRENT_LIST_FILE contains the full path to the file currently being <nl> + # processed . Using this variable , we can pull out the current path , and <nl> + # provide a way to get access to the other files we need local to here . <nl> + get_filename_component ( CMAKE_CURRENT_LIST_DIR " $ { CMAKE_CURRENT_LIST_FILE } " PATH ) <nl> + set ( CUDA_ $ { _name } " $ { CMAKE_CURRENT_LIST_DIR } / FindCUDA / $ { _full_name } " ) <nl> + if ( NOT EXISTS " $ { CUDA_ $ { _name } } " ) <nl> + set ( error_message " $ { _full_name } not found in $ { CMAKE_CURRENT_LIST_DIR } / FindCUDA " ) <nl> + if ( CUDA_FIND_REQUIRED ) <nl> + message ( FATAL_ERROR " $ { error_message } " ) <nl> + else ( ) <nl> + if ( NOT CUDA_FIND_QUIETLY ) <nl> + message ( STATUS " $ { error_message } " ) <nl> + endif ( ) <nl> + endif ( ) <nl> + endif ( ) <nl> + # Set this variable as internal , so the user isn ' t bugged with it . <nl> + set ( CUDA_ $ { _name } $ { CUDA_ $ { _name } } CACHE INTERNAL " Location of $ { _full_name } " FORCE ) <nl> + endmacro ( ) <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # CUDA_INCLUDE_NVCC_DEPENDENCIES <nl> + # # <nl> + <nl> + # So we want to try and include the dependency file if it exists . If <nl> + # it doesn ' t exist then we need to create an empty one , so we can <nl> + # include it . <nl> + <nl> + # If it does exist , then we need to check to see if all the files it <nl> + # depends on exist . If they don ' t then we should clear the dependency <nl> + # file and regenerate it later . This covers the case where a header <nl> + # file has disappeared or moved . <nl> + <nl> + macro ( CUDA_INCLUDE_NVCC_DEPENDENCIES dependency_file ) <nl> + set ( CUDA_NVCC_DEPEND ) <nl> + set ( CUDA_NVCC_DEPEND_REGENERATE FALSE ) <nl> + <nl> + <nl> + # Include the dependency file . Create it first if it doesn ' t exist . The <nl> + # INCLUDE puts a dependency that will force CMake to rerun and bring in the <nl> + # new info when it changes . DO NOT REMOVE THIS ( as I did and spent a few <nl> + # hours figuring out why it didn ' t work . <nl> + if ( NOT EXISTS $ { dependency_file } ) <nl> + file ( WRITE $ { dependency_file } " # FindCUDA . cmake generated file . Do not edit . \ n " ) <nl> + endif ( ) <nl> + # Always include this file to force CMake to run again next <nl> + # invocation and rebuild the dependencies . <nl> + # message ( " including dependency_file = $ { dependency_file } " ) <nl> + include ( $ { dependency_file } ) <nl> + <nl> + # Now we need to verify the existence of all the included files <nl> + # here . If they aren ' t there we need to just blank this variable and <nl> + # make the file regenerate again . <nl> + # if ( DEFINED CUDA_NVCC_DEPEND ) <nl> + # message ( " CUDA_NVCC_DEPEND set " ) <nl> + # else ( ) <nl> + # message ( " CUDA_NVCC_DEPEND NOT set " ) <nl> + # endif ( ) <nl> + if ( CUDA_NVCC_DEPEND ) <nl> + # message ( " CUDA_NVCC_DEPEND found " ) <nl> + foreach ( f $ { CUDA_NVCC_DEPEND } ) <nl> + # message ( " searching for $ { f } " ) <nl> + if ( NOT EXISTS $ { f } ) <nl> + # message ( " file $ { f } not found " ) <nl> + set ( CUDA_NVCC_DEPEND_REGENERATE TRUE ) <nl> + endif ( ) <nl> + endforeach ( ) <nl> + else ( ) <nl> + # message ( " CUDA_NVCC_DEPEND false " ) <nl> + # No dependencies , so regenerate the file . <nl> + set ( CUDA_NVCC_DEPEND_REGENERATE TRUE ) <nl> + endif ( ) <nl> + <nl> + # message ( " CUDA_NVCC_DEPEND_REGENERATE = $ { CUDA_NVCC_DEPEND_REGENERATE } " ) <nl> + # No incoming dependencies , so we need to generate them . Make the <nl> + # output depend on the dependency file itself , which should cause the <nl> + # rule to re - run . <nl> + if ( CUDA_NVCC_DEPEND_REGENERATE ) <nl> + set ( CUDA_NVCC_DEPEND $ { dependency_file } ) <nl> + # message ( " Generating an empty dependency_file : $ { dependency_file } " ) <nl> + file ( WRITE $ { dependency_file } " # FindCUDA . cmake generated file . Do not edit . \ n " ) <nl> + endif ( ) <nl> + <nl> + endmacro ( ) <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # Setup variables ' defaults <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + <nl> + # Allow the user to specify if the device code is supposed to be 32 or 64 bit . <nl> + if ( CMAKE_SIZEOF_VOID_P EQUAL 8 ) <nl> + set ( CUDA_64_BIT_DEVICE_CODE_DEFAULT ON ) <nl> + else ( ) <nl> + set ( CUDA_64_BIT_DEVICE_CODE_DEFAULT OFF ) <nl> + endif ( ) <nl> + option ( CUDA_64_BIT_DEVICE_CODE " Compile device code in 64 bit mode " $ { CUDA_64_BIT_DEVICE_CODE_DEFAULT } ) <nl> + <nl> + # Attach the build rule to the source file in VS . This option <nl> + option ( CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE " Attach the build rule to the CUDA source file . Enable only when the CUDA source file is added to at most one target . " ON ) <nl> + <nl> + # Prints out extra information about the cuda file during compilation <nl> + option ( CUDA_BUILD_CUBIN " Generate and parse . cubin files in Device mode . " OFF ) <nl> + <nl> + # Set whether we are using emulation or device mode . <nl> + option ( CUDA_BUILD_EMULATION " Build in Emulation mode " OFF ) <nl> + <nl> + # Where to put the generated output . <nl> + set ( CUDA_GENERATED_OUTPUT_DIR " " CACHE PATH " Directory to put all the output files . If blank it will default to the CMAKE_CURRENT_BINARY_DIR " ) <nl> + <nl> + # Parse HOST_COMPILATION mode . <nl> + option ( CUDA_HOST_COMPILATION_CPP " Generated file extension " ON ) <nl> + <nl> + # Extra user settable flags <nl> + set ( CUDA_NVCC_FLAGS " " CACHE STRING " Semi - colon delimit multiple arguments . " ) <nl> + <nl> + if ( CMAKE_GENERATOR MATCHES " Visual Studio " ) <nl> + set ( CUDA_HOST_COMPILER " $ ( VCInstallDir ) bin " CACHE FILEPATH " Host side compiler used by NVCC " ) <nl> + else ( ) <nl> + set ( CUDA_HOST_COMPILER " $ { CMAKE_C_COMPILER } " CACHE FILEPATH " Host side compiler used by NVCC " ) <nl> + endif ( ) <nl> + <nl> + # Propagate the host flags to the host compiler via - Xcompiler <nl> + option ( CUDA_PROPAGATE_HOST_FLAGS " Propage C / CXX_FLAGS and friends to the host compiler via - Xcompile " ON ) <nl> + <nl> + # Enable CUDA_SEPARABLE_COMPILATION <nl> + option ( CUDA_SEPARABLE_COMPILATION " Compile CUDA objects with separable compilation enabled . Requires CUDA 5 . 0 + " OFF ) <nl> + <nl> + # Specifies whether the commands used when compiling the . cu file will be printed out . <nl> + option ( CUDA_VERBOSE_BUILD " Print out the commands run while compiling the CUDA source file . With the Makefile generator this defaults to VERBOSE variable specified on the command line , but can be forced on with this option . " OFF ) <nl> + <nl> + mark_as_advanced ( <nl> + CUDA_64_BIT_DEVICE_CODE <nl> + CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE <nl> + CUDA_GENERATED_OUTPUT_DIR <nl> + CUDA_HOST_COMPILATION_CPP <nl> + CUDA_NVCC_FLAGS <nl> + CUDA_PROPAGATE_HOST_FLAGS <nl> + ) <nl> + <nl> + # Makefile and similar generators don ' t define CMAKE_CONFIGURATION_TYPES , so we <nl> + # need to add another entry for the CMAKE_BUILD_TYPE . We also need to add the <nl> + # standerd set of 4 build types ( Debug , MinSizeRel , Release , and RelWithDebInfo ) <nl> + # for completeness . We need run this loop in order to accomodate the addition <nl> + # of extra configuration types . Duplicate entries will be removed by <nl> + # REMOVE_DUPLICATES . <nl> + set ( CUDA_configuration_types $ { CMAKE_CONFIGURATION_TYPES } $ { CMAKE_BUILD_TYPE } Debug MinSizeRel Release RelWithDebInfo ) <nl> + list ( REMOVE_DUPLICATES CUDA_configuration_types ) <nl> + foreach ( config $ { CUDA_configuration_types } ) <nl> + string ( TOUPPER $ { config } config_upper ) <nl> + set ( CUDA_NVCC_FLAGS_ $ { config_upper } " " CACHE STRING " Semi - colon delimit multiple arguments . " ) <nl> + mark_as_advanced ( CUDA_NVCC_FLAGS_ $ { config_upper } ) <nl> + endforeach ( ) <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # Locate CUDA , Set Build Type , etc . <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + <nl> + macro ( cuda_unset_include_and_libraries ) <nl> + unset ( CUDA_TOOLKIT_INCLUDE CACHE ) <nl> + unset ( CUDA_CUDART_LIBRARY CACHE ) <nl> + unset ( CUDA_CUDA_LIBRARY CACHE ) <nl> + # Make sure you run this before you unset CUDA_VERSION . <nl> + if ( CUDA_VERSION VERSION_EQUAL " 3 . 0 " ) <nl> + # This only existed in the 3 . 0 version of the CUDA toolkit <nl> + unset ( CUDA_CUDARTEMU_LIBRARY CACHE ) <nl> + endif ( ) <nl> + unset ( CUDA_cupti_LIBRARY CACHE ) <nl> + unset ( CUDA_cublas_LIBRARY CACHE ) <nl> + unset ( CUDA_cublasemu_LIBRARY CACHE ) <nl> + unset ( CUDA_cufft_LIBRARY CACHE ) <nl> + unset ( CUDA_cufftemu_LIBRARY CACHE ) <nl> + unset ( CUDA_curand_LIBRARY CACHE ) <nl> + unset ( CUDA_cusparse_LIBRARY CACHE ) <nl> + unset ( CUDA_npp_LIBRARY CACHE ) <nl> + unset ( CUDA_nppc_LIBRARY CACHE ) <nl> + unset ( CUDA_nppi_LIBRARY CACHE ) <nl> + unset ( CUDA_npps_LIBRARY CACHE ) <nl> + unset ( CUDA_nvcuvenc_LIBRARY CACHE ) <nl> + unset ( CUDA_nvcuvid_LIBRARY CACHE ) <nl> + endmacro ( ) <nl> + <nl> + # Check to see if the CUDA_TOOLKIT_ROOT_DIR and CUDA_SDK_ROOT_DIR have changed , <nl> + # if they have then clear the cache variables , so that will be detected again . <nl> + if ( NOT " $ { CUDA_TOOLKIT_ROOT_DIR } " STREQUAL " $ { CUDA_TOOLKIT_ROOT_DIR_INTERNAL } " ) <nl> + unset ( CUDA_TOOLKIT_TARGET_DIR CACHE ) <nl> + unset ( CUDA_NVCC_EXECUTABLE CACHE ) <nl> + unset ( CUDA_VERSION CACHE ) <nl> + cuda_unset_include_and_libraries ( ) <nl> + endif ( ) <nl> + <nl> + if ( NOT " $ { CUDA_TOOLKIT_TARGET_DIR } " STREQUAL " $ { CUDA_TOOLKIT_TARGET_DIR_INTERNAL } " ) <nl> + cuda_unset_include_and_libraries ( ) <nl> + endif ( ) <nl> + <nl> + if ( NOT " $ { CUDA_SDK_ROOT_DIR } " STREQUAL " $ { CUDA_SDK_ROOT_DIR_INTERNAL } " ) <nl> + # No specific variables to catch . Use this kind of code before calling <nl> + # find_package ( CUDA ) to clean up any variables that may depend on this path . <nl> + <nl> + # unset ( MY_SPECIAL_CUDA_SDK_INCLUDE_DIR CACHE ) <nl> + # unset ( MY_SPECIAL_CUDA_SDK_LIBRARY CACHE ) <nl> + endif ( ) <nl> + <nl> + # Search for the cuda distribution . <nl> + if ( NOT CUDA_TOOLKIT_ROOT_DIR ) <nl> + <nl> + # Search in the CUDA_BIN_PATH first . <nl> + find_path ( CUDA_TOOLKIT_ROOT_DIR <nl> + NAMES nvcc nvcc . exe <nl> + PATHS <nl> + ENV CUDA_PATH <nl> + ENV CUDA_BIN_PATH <nl> + PATH_SUFFIXES bin bin64 <nl> + DOC " Toolkit location . " <nl> + NO_DEFAULT_PATH <nl> + ) <nl> + # Now search default paths <nl> + find_path ( CUDA_TOOLKIT_ROOT_DIR <nl> + NAMES nvcc nvcc . exe <nl> + PATHS / usr / local / bin <nl> + / usr / local / cuda / bin <nl> + DOC " Toolkit location . " <nl> + ) <nl> + <nl> + if ( CUDA_TOOLKIT_ROOT_DIR ) <nl> + string ( REGEX REPLACE " [ / \ \ \ \ ] ? bin [ 64 ] * [ / \ \ \ \ ] ? $ " " " CUDA_TOOLKIT_ROOT_DIR $ { CUDA_TOOLKIT_ROOT_DIR } ) <nl> + # We need to force this back into the cache . <nl> + set ( CUDA_TOOLKIT_ROOT_DIR $ { CUDA_TOOLKIT_ROOT_DIR } CACHE PATH " Toolkit location . " FORCE ) <nl> + endif ( ) <nl> + if ( NOT EXISTS $ { CUDA_TOOLKIT_ROOT_DIR } ) <nl> + if ( CUDA_FIND_REQUIRED ) <nl> + message ( FATAL_ERROR " Specify CUDA_TOOLKIT_ROOT_DIR " ) <nl> + elseif ( NOT CUDA_FIND_QUIETLY ) <nl> + message ( " CUDA_TOOLKIT_ROOT_DIR not found or specified " ) <nl> + endif ( ) <nl> + endif ( ) <nl> + endif ( ) <nl> + <nl> + # CUDA_NVCC_EXECUTABLE <nl> + find_program ( CUDA_NVCC_EXECUTABLE <nl> + NAMES nvcc <nl> + PATHS " $ { CUDA_TOOLKIT_ROOT_DIR } " <nl> + ENV CUDA_PATH <nl> + ENV CUDA_BIN_PATH <nl> + PATH_SUFFIXES bin bin64 <nl> + NO_DEFAULT_PATH <nl> + ) <nl> + # Search default search paths , after we search our own set of paths . <nl> + find_program ( CUDA_NVCC_EXECUTABLE nvcc ) <nl> + mark_as_advanced ( CUDA_NVCC_EXECUTABLE ) <nl> + <nl> + if ( CUDA_NVCC_EXECUTABLE AND NOT CUDA_VERSION ) <nl> + # Compute the version . <nl> + execute_process ( COMMAND $ { CUDA_NVCC_EXECUTABLE } " - - version " OUTPUT_VARIABLE NVCC_OUT ) <nl> + string ( REGEX REPLACE " . * release ( [ 0 - 9 ] + ) \ \ . ( [ 0 - 9 ] + ) . * " " \ \ 1 " CUDA_VERSION_MAJOR $ { NVCC_OUT } ) <nl> + string ( REGEX REPLACE " . * release ( [ 0 - 9 ] + ) \ \ . ( [ 0 - 9 ] + ) . * " " \ \ 2 " CUDA_VERSION_MINOR $ { NVCC_OUT } ) <nl> + set ( CUDA_VERSION " $ { CUDA_VERSION_MAJOR } . $ { CUDA_VERSION_MINOR } " CACHE STRING " Version of CUDA as computed from nvcc . " ) <nl> + mark_as_advanced ( CUDA_VERSION ) <nl> + else ( ) <nl> + # Need to set these based off of the cached value <nl> + string ( REGEX REPLACE " ( [ 0 - 9 ] + ) \ \ . ( [ 0 - 9 ] + ) . * " " \ \ 1 " CUDA_VERSION_MAJOR " $ { CUDA_VERSION } " ) <nl> + string ( REGEX REPLACE " ( [ 0 - 9 ] + ) \ \ . ( [ 0 - 9 ] + ) . * " " \ \ 2 " CUDA_VERSION_MINOR " $ { CUDA_VERSION } " ) <nl> + endif ( ) <nl> + <nl> + # Always set this convenience variable <nl> + set ( CUDA_VERSION_STRING " $ { CUDA_VERSION } " ) <nl> + <nl> + # Support for arm cross compilation with CUDA 5 . 5 <nl> + if ( CUDA_VERSION VERSION_GREATER " 5 . 0 " AND CMAKE_CROSSCOMPILING AND $ { CMAKE_SYSTEM_PROCESSOR } MATCHES " arm " AND EXISTS " $ { CUDA_TOOLKIT_ROOT_DIR } / targets / armv7 - linux - gnueabihf " ) <nl> + set ( CUDA_TOOLKIT_TARGET_DIR " $ { CUDA_TOOLKIT_ROOT_DIR } / targets / armv7 - linux - gnueabihf " CACHE PATH " Toolkit target location . " ) <nl> + else ( ) <nl> + set ( CUDA_TOOLKIT_TARGET_DIR " $ { CUDA_TOOLKIT_ROOT_DIR } " CACHE PATH " Toolkit target location . " ) <nl> + endif ( ) <nl> + mark_as_advanced ( CUDA_TOOLKIT_TARGET_DIR ) <nl> + <nl> + # Target CPU architecture <nl> + if ( CUDA_VERSION VERSION_GREATER " 5 . 0 " AND CMAKE_CROSSCOMPILING AND $ { CMAKE_SYSTEM_PROCESSOR } MATCHES " arm " ) <nl> + set ( _cuda_target_cpu_arch_initial " ARM " ) <nl> + else ( ) <nl> + set ( _cuda_target_cpu_arch_initial " " ) <nl> + endif ( ) <nl> + set ( CUDA_TARGET_CPU_ARCH $ { _cuda_target_cpu_arch_initial } CACHE STRING " Specify the name of the class of CPU architecture for which the input files must be compiled . " ) <nl> + mark_as_advanced ( CUDA_TARGET_CPU_ARCH ) <nl> + <nl> + # CUDA_TOOLKIT_INCLUDE <nl> + find_path ( CUDA_TOOLKIT_INCLUDE <nl> + device_functions . h # Header included in toolkit <nl> + PATHS " $ { CUDA_TOOLKIT_TARGET_DIR } " " $ { CUDA_TOOLKIT_ROOT_DIR } " <nl> + ENV CUDA_PATH <nl> + ENV CUDA_INC_PATH <nl> + PATH_SUFFIXES include <nl> + NO_DEFAULT_PATH <nl> + ) <nl> + # Search default search paths , after we search our own set of paths . <nl> + find_path ( CUDA_TOOLKIT_INCLUDE device_functions . h ) <nl> + mark_as_advanced ( CUDA_TOOLKIT_INCLUDE ) <nl> + <nl> + # Set the user list of include dir to nothing to initialize it . <nl> + set ( CUDA_NVCC_INCLUDE_ARGS_USER " " ) <nl> + set ( CUDA_INCLUDE_DIRS $ { CUDA_TOOLKIT_INCLUDE } ) <nl> + <nl> + macro ( cuda_find_library_local_first_with_path_ext _var _names _doc _path_ext ) <nl> + if ( CMAKE_SIZEOF_VOID_P EQUAL 8 ) <nl> + # CUDA 3 . 2 + on Windows moved the library directories , so we need the new <nl> + # and old paths . <nl> + set ( _cuda_64bit_lib_dir " $ { _path_ext } lib / x64 " " $ { _path_ext } lib64 " " $ { _path_ext } libx64 " ) <nl> + endif ( ) <nl> + # CUDA 3 . 2 + on Windows moved the library directories , so we need to new <nl> + # ( lib / Win32 ) and the old path ( lib ) . <nl> + find_library ( $ { _var } <nl> + NAMES $ { _names } <nl> + PATHS " $ { CUDA_TOOLKIT_TARGET_DIR } " " $ { CUDA_TOOLKIT_ROOT_DIR } " <nl> + ENV CUDA_PATH <nl> + ENV CUDA_LIB_PATH <nl> + PATH_SUFFIXES $ { _cuda_64bit_lib_dir } " $ { _path_ext } lib / Win32 " " $ { _path_ext } lib " " $ { _path_ext } libWin32 " <nl> + DOC $ { _doc } <nl> + NO_DEFAULT_PATH <nl> + ) <nl> + # Search default search paths , after we search our own set of paths . <nl> + find_library ( $ { _var } <nl> + NAMES $ { _names } <nl> + PATHS " / usr / lib / nvidia - current " <nl> + DOC $ { _doc } <nl> + ) <nl> + endmacro ( ) <nl> + <nl> + macro ( cuda_find_library_local_first _var _names _doc ) <nl> + cuda_find_library_local_first_with_path_ext ( " $ { _var } " " $ { _names } " " $ { _doc } " " " ) <nl> + endmacro ( ) <nl> + <nl> + macro ( find_library_local_first _var _names _doc ) <nl> + cuda_find_library_local_first ( " $ { _var } " " $ { _names } " " $ { _doc } " " " ) <nl> + endmacro ( ) <nl> + <nl> + <nl> + # CUDA_LIBRARIES <nl> + cuda_find_library_local_first ( CUDA_CUDART_LIBRARY cudart " \ " cudart \ " library " ) <nl> + if ( CUDA_VERSION VERSION_EQUAL " 3 . 0 " ) <nl> + # The cudartemu library only existed for the 3 . 0 version of CUDA . <nl> + cuda_find_library_local_first ( CUDA_CUDARTEMU_LIBRARY cudartemu " \ " cudartemu \ " library " ) <nl> + mark_as_advanced ( <nl> + CUDA_CUDARTEMU_LIBRARY <nl> + ) <nl> + endif ( ) <nl> + <nl> + # CUPTI library showed up in cuda toolkit 4 . 0 <nl> + if ( NOT CUDA_VERSION VERSION_LESS " 4 . 0 " ) <nl> + cuda_find_library_local_first_with_path_ext ( CUDA_cupti_LIBRARY cupti " \ " cupti \ " library " " extras / CUPTI / " ) <nl> + mark_as_advanced ( CUDA_cupti_LIBRARY ) <nl> + endif ( ) <nl> + <nl> + # If we are using emulation mode and we found the cudartemu library then use <nl> + # that one instead of cudart . <nl> + if ( CUDA_BUILD_EMULATION AND CUDA_CUDARTEMU_LIBRARY ) <nl> + set ( CUDA_LIBRARIES $ { CUDA_CUDARTEMU_LIBRARY } ) <nl> + else ( ) <nl> + set ( CUDA_LIBRARIES $ { CUDA_CUDART_LIBRARY } ) <nl> + endif ( ) <nl> + if ( APPLE ) <nl> + # We need to add the path to cudart to the linker using rpath , since the <nl> + # library name for the cuda libraries is prepended with @ rpath . <nl> + if ( CUDA_BUILD_EMULATION AND CUDA_CUDARTEMU_LIBRARY ) <nl> + get_filename_component ( _cuda_path_to_cudart " $ { CUDA_CUDARTEMU_LIBRARY } " PATH ) <nl> + else ( ) <nl> + get_filename_component ( _cuda_path_to_cudart " $ { CUDA_CUDART_LIBRARY } " PATH ) <nl> + endif ( ) <nl> + if ( _cuda_path_to_cudart ) <nl> + list ( APPEND CUDA_LIBRARIES - Wl , - rpath " - Wl , $ { _cuda_path_to_cudart } " ) <nl> + endif ( ) <nl> + endif ( ) <nl> + <nl> + # 1 . 1 toolkit on linux doesn ' t appear to have a separate library on <nl> + # some platforms . <nl> + cuda_find_library_local_first ( CUDA_CUDA_LIBRARY cuda " \ " cuda \ " library ( older versions only ) . " ) <nl> + <nl> + mark_as_advanced ( <nl> + CUDA_CUDA_LIBRARY <nl> + CUDA_CUDART_LIBRARY <nl> + ) <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # <nl> + # Look for some of the toolkit helper libraries <nl> + macro ( FIND_CUDA_HELPER_LIBS _name ) <nl> + cuda_find_library_local_first ( CUDA_ $ { _name } _LIBRARY $ { _name } " \ " $ { _name } \ " library " ) <nl> + mark_as_advanced ( CUDA_ $ { _name } _LIBRARY ) <nl> + endmacro ( ) <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # <nl> + # Disable emulation for v3 . 1 onward <nl> + if ( CUDA_VERSION VERSION_GREATER " 3 . 0 " ) <nl> + if ( CUDA_BUILD_EMULATION ) <nl> + message ( FATAL_ERROR " CUDA_BUILD_EMULATION is not supported in version 3 . 1 and onwards . You must disable it to proceed . You have version $ { CUDA_VERSION } . " ) <nl> + endif ( ) <nl> + endif ( ) <nl> + <nl> + # Search for additional CUDA toolkit libraries . <nl> + if ( CUDA_VERSION VERSION_LESS " 3 . 1 " ) <nl> + # Emulation libraries aren ' t available in version 3 . 1 onward . <nl> + find_cuda_helper_libs ( cufftemu ) <nl> + find_cuda_helper_libs ( cublasemu ) <nl> + endif ( ) <nl> + find_cuda_helper_libs ( cufft ) <nl> + find_cuda_helper_libs ( cublas ) <nl> + if ( NOT CUDA_VERSION VERSION_LESS " 3 . 2 " ) <nl> + # cusparse showed up in version 3 . 2 <nl> + find_cuda_helper_libs ( cusparse ) <nl> + find_cuda_helper_libs ( curand ) <nl> + if ( WIN32 ) <nl> + find_cuda_helper_libs ( nvcuvenc ) <nl> + find_cuda_helper_libs ( nvcuvid ) <nl> + endif ( ) <nl> + endif ( ) <nl> + if ( CUDA_VERSION VERSION_GREATER " 5 . 0 " ) <nl> + # In CUDA 5 . 5 NPP was splitted onto 3 separate libraries . <nl> + find_cuda_helper_libs ( nppc ) <nl> + find_cuda_helper_libs ( nppi ) <nl> + find_cuda_helper_libs ( npps ) <nl> + set ( CUDA_npp_LIBRARY " $ { CUDA_nppc_LIBRARY } ; $ { CUDA_nppi_LIBRARY } ; $ { CUDA_npps_LIBRARY } " ) <nl> + elseif ( NOT CUDA_VERSION VERSION_LESS " 4 . 0 " ) <nl> + find_cuda_helper_libs ( npp ) <nl> + endif ( ) <nl> + <nl> + if ( CUDA_BUILD_EMULATION ) <nl> + set ( CUDA_CUFFT_LIBRARIES $ { CUDA_cufftemu_LIBRARY } ) <nl> + set ( CUDA_CUBLAS_LIBRARIES $ { CUDA_cublasemu_LIBRARY } ) <nl> + else ( ) <nl> + set ( CUDA_CUFFT_LIBRARIES $ { CUDA_cufft_LIBRARY } ) <nl> + set ( CUDA_CUBLAS_LIBRARIES $ { CUDA_cublas_LIBRARY } ) <nl> + endif ( ) <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # Look for the SDK stuff . As of CUDA 3 . 0 NVSDKCUDA_ROOT has been replaced with <nl> + # NVSDKCOMPUTE_ROOT with the old CUDA C contents moved into the C subdirectory <nl> + find_path ( CUDA_SDK_ROOT_DIR common / inc / cutil . h <nl> + HINTS <nl> + " $ ENV { NVSDKCOMPUTE_ROOT } / C " <nl> + ENV NVSDKCUDA_ROOT <nl> + " [ HKEY_LOCAL_MACHINE \ \ SOFTWARE \ \ NVIDIA Corporation \ \ Installed Products \ \ NVIDIA SDK 10 \ \ Compute ; InstallDir ] " <nl> + PATHS <nl> + " / Developer / GPU \ Computing / C " <nl> + ) <nl> + <nl> + # Keep the CUDA_SDK_ROOT_DIR first in order to be able to override the <nl> + # environment variables . <nl> + set ( CUDA_SDK_SEARCH_PATH <nl> + " $ { CUDA_SDK_ROOT_DIR } " <nl> + " $ { CUDA_TOOLKIT_ROOT_DIR } / local / NVSDK0 . 2 " <nl> + " $ { CUDA_TOOLKIT_ROOT_DIR } / NVSDK0 . 2 " <nl> + " $ { CUDA_TOOLKIT_ROOT_DIR } / NV_CUDA_SDK " <nl> + " $ ENV { HOME } / NVIDIA_CUDA_SDK " <nl> + " $ ENV { HOME } / NVIDIA_CUDA_SDK_MACOSX " <nl> + " / Developer / CUDA " <nl> + ) <nl> + <nl> + # Example of how to find an include file from the CUDA_SDK_ROOT_DIR <nl> + <nl> + # find_path ( CUDA_CUT_INCLUDE_DIR <nl> + # cutil . h <nl> + # PATHS $ { CUDA_SDK_SEARCH_PATH } <nl> + # PATH_SUFFIXES " common / inc " <nl> + # DOC " Location of cutil . h " <nl> + # NO_DEFAULT_PATH <nl> + # ) <nl> + # # Now search system paths <nl> + # find_path ( CUDA_CUT_INCLUDE_DIR cutil . h DOC " Location of cutil . h " ) <nl> + <nl> + # mark_as_advanced ( CUDA_CUT_INCLUDE_DIR ) <nl> + <nl> + <nl> + # Example of how to find a library in the CUDA_SDK_ROOT_DIR <nl> + <nl> + # # cutil library is called cutil64 for 64 bit builds on windows . We don ' t want <nl> + # # to get these confused , so we are setting the name based on the word size of <nl> + # # the build . <nl> + <nl> + # if ( CMAKE_SIZEOF_VOID_P EQUAL 8 ) <nl> + # set ( cuda_cutil_name cutil64 ) <nl> + # else ( ) <nl> + # set ( cuda_cutil_name cutil32 ) <nl> + # endif ( ) <nl> + <nl> + # find_library ( CUDA_CUT_LIBRARY <nl> + # NAMES cutil $ { cuda_cutil_name } <nl> + # PATHS $ { CUDA_SDK_SEARCH_PATH } <nl> + # # The new version of the sdk shows up in common / lib , but the old one is in lib <nl> + # PATH_SUFFIXES " common / lib " " lib " <nl> + # DOC " Location of cutil library " <nl> + # NO_DEFAULT_PATH <nl> + # ) <nl> + # # Now search system paths <nl> + # find_library ( CUDA_CUT_LIBRARY NAMES cutil $ { cuda_cutil_name } DOC " Location of cutil library " ) <nl> + # mark_as_advanced ( CUDA_CUT_LIBRARY ) <nl> + # set ( CUDA_CUT_LIBRARIES $ { CUDA_CUT_LIBRARY } ) <nl> + <nl> + <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # Check for required components <nl> + set ( CUDA_FOUND TRUE ) <nl> + <nl> + set ( CUDA_TOOLKIT_ROOT_DIR_INTERNAL " $ { CUDA_TOOLKIT_ROOT_DIR } " CACHE INTERNAL <nl> + " This is the value of the last time CUDA_TOOLKIT_ROOT_DIR was set successfully . " FORCE ) <nl> + set ( CUDA_TOOLKIT_TARGET_DIR_INTERNAL " $ { CUDA_TOOLKIT_TARGET_DIR } " CACHE INTERNAL <nl> + " This is the value of the last time CUDA_TOOLKIT_TARGET_DIR was set successfully . " FORCE ) <nl> + set ( CUDA_SDK_ROOT_DIR_INTERNAL " $ { CUDA_SDK_ROOT_DIR } " CACHE INTERNAL <nl> + " This is the value of the last time CUDA_SDK_ROOT_DIR was set successfully . " FORCE ) <nl> + <nl> + include ( FindPackageHandleStandardArgs ) <nl> + find_package_handle_standard_args ( CUDA <nl> + REQUIRED_VARS <nl> + CUDA_TOOLKIT_ROOT_DIR <nl> + CUDA_NVCC_EXECUTABLE <nl> + CUDA_INCLUDE_DIRS <nl> + CUDA_CUDART_LIBRARY <nl> + VERSION_VAR <nl> + CUDA_VERSION <nl> + ) <nl> + <nl> + <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # Macros <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # Add include directories to pass to the nvcc command . <nl> + macro ( CUDA_INCLUDE_DIRECTORIES ) <nl> + foreach ( dir $ { ARGN } ) <nl> + list ( APPEND CUDA_NVCC_INCLUDE_ARGS_USER - I $ { dir } ) <nl> + endforeach ( ) <nl> + endmacro ( ) <nl> + <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + cuda_find_helper_file ( parse_cubin cmake ) <nl> + cuda_find_helper_file ( make2cmake cmake ) <nl> + cuda_find_helper_file ( run_nvcc cmake ) <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # Separate the OPTIONS out from the sources <nl> + # <nl> + macro ( CUDA_GET_SOURCES_AND_OPTIONS _sources _cmake_options _options ) <nl> + set ( $ { _sources } ) <nl> + set ( $ { _cmake_options } ) <nl> + set ( $ { _options } ) <nl> + set ( _found_options FALSE ) <nl> + foreach ( arg $ { ARGN } ) <nl> + if ( arg STREQUAL " OPTIONS " ) <nl> + set ( _found_options TRUE ) <nl> + elseif ( <nl> + arg STREQUAL " WIN32 " OR <nl> + arg STREQUAL " MACOSX_BUNDLE " OR <nl> + arg STREQUAL " EXCLUDE_FROM_ALL " OR <nl> + arg STREQUAL " STATIC " OR <nl> + arg STREQUAL " SHARED " OR <nl> + arg STREQUAL " MODULE " <nl> + ) <nl> + list ( APPEND $ { _cmake_options } $ { arg } ) <nl> + else ( ) <nl> + if ( _found_options ) <nl> + list ( APPEND $ { _options } $ { arg } ) <nl> + else ( ) <nl> + # Assume this is a file <nl> + list ( APPEND $ { _sources } $ { arg } ) <nl> + endif ( ) <nl> + endif ( ) <nl> + endforeach ( ) <nl> + endmacro ( ) <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # Parse the OPTIONS from ARGN and set the variables prefixed by _option_prefix <nl> + # <nl> + macro ( CUDA_PARSE_NVCC_OPTIONS _option_prefix ) <nl> + set ( _found_config ) <nl> + foreach ( arg $ { ARGN } ) <nl> + # Determine if we are dealing with a perconfiguration flag <nl> + foreach ( config $ { CUDA_configuration_types } ) <nl> + string ( TOUPPER $ { config } config_upper ) <nl> + if ( arg STREQUAL " $ { config_upper } " ) <nl> + set ( _found_config _ $ { arg } ) <nl> + # Set arg to nothing to keep it from being processed further <nl> + set ( arg ) <nl> + endif ( ) <nl> + endforeach ( ) <nl> + <nl> + if ( arg ) <nl> + list ( APPEND $ { _option_prefix } $ { _found_config } " $ { arg } " ) <nl> + endif ( ) <nl> + endforeach ( ) <nl> + endmacro ( ) <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # Helper to add the include directory for CUDA only once <nl> + function ( CUDA_ADD_CUDA_INCLUDE_ONCE ) <nl> + get_directory_property ( _include_directories INCLUDE_DIRECTORIES ) <nl> + set ( _add TRUE ) <nl> + if ( _include_directories ) <nl> + foreach ( dir $ { _include_directories } ) <nl> + if ( " $ { dir } " STREQUAL " $ { CUDA_INCLUDE_DIRS } " ) <nl> + set ( _add FALSE ) <nl> + endif ( ) <nl> + endforeach ( ) <nl> + endif ( ) <nl> + if ( _add ) <nl> + include_directories ( $ { CUDA_INCLUDE_DIRS } ) <nl> + endif ( ) <nl> + endfunction ( ) <nl> + <nl> + function ( CUDA_BUILD_SHARED_LIBRARY shared_flag ) <nl> + set ( cmake_args $ { ARGN } ) <nl> + # If SHARED , MODULE , or STATIC aren ' t already in the list of arguments , then <nl> + # add SHARED or STATIC based on the value of BUILD_SHARED_LIBS . <nl> + list ( FIND cmake_args SHARED _cuda_found_SHARED ) <nl> + list ( FIND cmake_args MODULE _cuda_found_MODULE ) <nl> + list ( FIND cmake_args STATIC _cuda_found_STATIC ) <nl> + if ( _cuda_found_SHARED GREATER - 1 OR <nl> + _cuda_found_MODULE GREATER - 1 OR <nl> + _cuda_found_STATIC GREATER - 1 ) <nl> + set ( _cuda_build_shared_libs ) <nl> + else ( ) <nl> + if ( BUILD_SHARED_LIBS ) <nl> + set ( _cuda_build_shared_libs SHARED ) <nl> + else ( ) <nl> + set ( _cuda_build_shared_libs STATIC ) <nl> + endif ( ) <nl> + endif ( ) <nl> + set ( $ { shared_flag } $ { _cuda_build_shared_libs } PARENT_SCOPE ) <nl> + endfunction ( ) <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # Helper to avoid clashes of files with the same basename but different paths . <nl> + # This doesn ' t attempt to do exactly what CMake internals do , which is to only <nl> + # add this path when there is a conflict , since by the time a second collision <nl> + # in names is detected it ' s already too late to fix the first one . For <nl> + # consistency sake the relative path will be added to all files . <nl> + function ( CUDA_COMPUTE_BUILD_PATH path build_path ) <nl> + # message ( " CUDA_COMPUTE_BUILD_PATH ( [ $ { path } ] $ { build_path } ) " ) <nl> + # Only deal with CMake style paths from here on out <nl> + file ( TO_CMAKE_PATH " $ { path } " bpath ) <nl> + if ( IS_ABSOLUTE " $ { bpath } " ) <nl> + # Absolute paths are generally unnessary , especially if something like <nl> + # file ( GLOB_RECURSE ) is used to pick up the files . <nl> + <nl> + string ( FIND " $ { bpath } " " $ { CMAKE_CURRENT_BINARY_DIR } " _binary_dir_pos ) <nl> + if ( _binary_dir_pos EQUAL 0 ) <nl> + file ( RELATIVE_PATH bpath " $ { CMAKE_CURRENT_BINARY_DIR } " " $ { bpath } " ) <nl> + else ( ) <nl> + file ( RELATIVE_PATH bpath " $ { CMAKE_CURRENT_SOURCE_DIR } " " $ { bpath } " ) <nl> + endif ( ) <nl> + endif ( ) <nl> + <nl> + # This recipie is from cmLocalGenerator : : CreateSafeUniqueObjectFileName in the <nl> + # CMake source . <nl> + <nl> + # Remove leading / <nl> + string ( REGEX REPLACE " ^ [ / ] + " " " bpath " $ { bpath } " ) <nl> + # Avoid absolute paths by removing ' : ' <nl> + string ( REPLACE " : " " _ " bpath " $ { bpath } " ) <nl> + # Avoid relative paths that go up the tree <nl> + string ( REPLACE " . . / " " __ / " bpath " $ { bpath } " ) <nl> + # Avoid spaces <nl> + string ( REPLACE " " " _ " bpath " $ { bpath } " ) <nl> + <nl> + # Strip off the filename . I wait until here to do it , since removin the <nl> + # basename can make a path that looked like path / . . / basename turn into <nl> + # path / . . ( notice the trailing slash ) . <nl> + get_filename_component ( bpath " $ { bpath } " PATH ) <nl> + <nl> + set ( $ { build_path } " $ { bpath } " PARENT_SCOPE ) <nl> + # message ( " $ { build_path } = $ { bpath } " ) <nl> + endfunction ( ) <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # This helper macro populates the following variables and setups up custom <nl> + # commands and targets to invoke the nvcc compiler to generate C or PTX source <nl> + # dependent upon the format parameter . The compiler is invoked once with - M <nl> + # to generate a dependency file and a second time with - cuda or - ptx to generate <nl> + # a . cpp or . ptx file . <nl> + # INPUT : <nl> + # cuda_target - Target name <nl> + # format - PTX or OBJ <nl> + # FILE1 . . FILEN - The remaining arguments are the sources to be wrapped . <nl> + # OPTIONS - Extra options to NVCC <nl> + # OUTPUT : <nl> + # generated_files - List of generated files <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + <nl> + macro ( CUDA_WRAP_SRCS cuda_target format generated_files ) <nl> + <nl> + # If CMake doesn ' t support separable compilation , complain <nl> + if ( CUDA_SEPARABLE_COMPILATION AND CMAKE_VERSION VERSION_LESS " 2 . 8 . 10 . 1 " ) <nl> + message ( SEND_ERROR " CUDA_SEPARABLE_COMPILATION isn ' t supported for CMake versions less than 2 . 8 . 10 . 1 " ) <nl> + endif ( ) <nl> + <nl> + # Set up all the command line flags here , so that they can be overridden on a per target basis . <nl> + <nl> + set ( nvcc_flags " " ) <nl> + <nl> + # Emulation if the card isn ' t present . <nl> + if ( CUDA_BUILD_EMULATION ) <nl> + # Emulation . <nl> + set ( nvcc_flags $ { nvcc_flags } - - device - emulation - D_DEVICEEMU - g ) <nl> + else ( ) <nl> + # Device mode . No flags necessary . <nl> + endif ( ) <nl> + <nl> + if ( CUDA_HOST_COMPILATION_CPP ) <nl> + set ( CUDA_C_OR_CXX CXX ) <nl> + else ( ) <nl> + if ( CUDA_VERSION VERSION_LESS " 3 . 0 " ) <nl> + set ( nvcc_flags $ { nvcc_flags } - - host - compilation C ) <nl> + else ( ) <nl> + message ( WARNING " - - host - compilation flag is deprecated in CUDA version > = 3 . 0 . Removing - - host - compilation C flag " ) <nl> + endif ( ) <nl> + set ( CUDA_C_OR_CXX C ) <nl> + endif ( ) <nl> + <nl> + set ( generated_extension $ { CMAKE_ $ { CUDA_C_OR_CXX } _OUTPUT_EXTENSION } ) <nl> + <nl> + if ( CUDA_64_BIT_DEVICE_CODE ) <nl> + set ( nvcc_flags $ { nvcc_flags } - m64 ) <nl> + else ( ) <nl> + set ( nvcc_flags $ { nvcc_flags } - m32 ) <nl> + endif ( ) <nl> + <nl> + if ( CUDA_TARGET_CPU_ARCH ) <nl> + set ( nvcc_flags $ { nvcc_flags } " - - target - cpu - architecture = $ { CUDA_TARGET_CPU_ARCH } " ) <nl> + endif ( ) <nl> + <nl> + # This needs to be passed in at this stage , because VS needs to fill out the <nl> + # value of VCInstallDir from within VS . Note that CCBIN is only used if <nl> + # - ccbin or - - compiler - bindir isn ' t used and CUDA_HOST_COMPILER matches <nl> + # $ ( VCInstallDir ) / bin . <nl> + if ( CMAKE_GENERATOR MATCHES " Visual Studio " ) <nl> + set ( ccbin_flags - D " \ " CCBIN : PATH = $ ( VCInstallDir ) bin \ " " ) <nl> + else ( ) <nl> + set ( ccbin_flags ) <nl> + endif ( ) <nl> + <nl> + # Figure out which configure we will use and pass that in as an argument to <nl> + # the script . We need to defer the decision until compilation time , because <nl> + # for VS projects we won ' t know if we are making a debug or release build <nl> + # until build time . <nl> + if ( CMAKE_GENERATOR MATCHES " Visual Studio " ) <nl> + set ( CUDA_build_configuration " $ ( ConfigurationName ) " ) <nl> + else ( ) <nl> + set ( CUDA_build_configuration " $ { CMAKE_BUILD_TYPE } " ) <nl> + endif ( ) <nl> + <nl> + # Initialize our list of includes with the user ones followed by the CUDA system ones . <nl> + set ( CUDA_NVCC_INCLUDE_ARGS $ { CUDA_NVCC_INCLUDE_ARGS_USER } " - I $ { CUDA_INCLUDE_DIRS } " ) <nl> + # Get the include directories for this directory and use them for our nvcc command . <nl> + # Remove duplicate entries which may be present since include_directories <nl> + # in CMake > = 2 . 8 . 8 does not remove them . <nl> + get_directory_property ( CUDA_NVCC_INCLUDE_DIRECTORIES INCLUDE_DIRECTORIES ) <nl> + list ( REMOVE_DUPLICATES CUDA_NVCC_INCLUDE_DIRECTORIES ) <nl> + if ( CUDA_NVCC_INCLUDE_DIRECTORIES ) <nl> + foreach ( dir $ { CUDA_NVCC_INCLUDE_DIRECTORIES } ) <nl> + list ( APPEND CUDA_NVCC_INCLUDE_ARGS - I $ { dir } ) <nl> + endforeach ( ) <nl> + endif ( ) <nl> + <nl> + # Reset these variables <nl> + set ( CUDA_WRAP_OPTION_NVCC_FLAGS ) <nl> + foreach ( config $ { CUDA_configuration_types } ) <nl> + string ( TOUPPER $ { config } config_upper ) <nl> + set ( CUDA_WRAP_OPTION_NVCC_FLAGS_ $ { config_upper } ) <nl> + endforeach ( ) <nl> + <nl> + CUDA_GET_SOURCES_AND_OPTIONS ( _cuda_wrap_sources _cuda_wrap_cmake_options _cuda_wrap_options $ { ARGN } ) <nl> + CUDA_PARSE_NVCC_OPTIONS ( CUDA_WRAP_OPTION_NVCC_FLAGS $ { _cuda_wrap_options } ) <nl> + <nl> + # Figure out if we are building a shared library . BUILD_SHARED_LIBS is <nl> + # respected in CUDA_ADD_LIBRARY . <nl> + set ( _cuda_build_shared_libs FALSE ) <nl> + # SHARED , MODULE <nl> + list ( FIND _cuda_wrap_cmake_options SHARED _cuda_found_SHARED ) <nl> + list ( FIND _cuda_wrap_cmake_options MODULE _cuda_found_MODULE ) <nl> + if ( _cuda_found_SHARED GREATER - 1 OR _cuda_found_MODULE GREATER - 1 ) <nl> + set ( _cuda_build_shared_libs TRUE ) <nl> + endif ( ) <nl> + # STATIC <nl> + list ( FIND _cuda_wrap_cmake_options STATIC _cuda_found_STATIC ) <nl> + if ( _cuda_found_STATIC GREATER - 1 ) <nl> + set ( _cuda_build_shared_libs FALSE ) <nl> + endif ( ) <nl> + <nl> + # CUDA_HOST_FLAGS <nl> + if ( _cuda_build_shared_libs ) <nl> + # If we are setting up code for a shared library , then we need to add extra flags for <nl> + # compiling objects for shared libraries . <nl> + set ( CUDA_HOST_SHARED_FLAGS $ { CMAKE_SHARED_LIBRARY_ $ { CUDA_C_OR_CXX } _FLAGS } ) <nl> + else ( ) <nl> + set ( CUDA_HOST_SHARED_FLAGS ) <nl> + endif ( ) <nl> + # Only add the CMAKE_ { C , CXX } _FLAGS if we are propagating host flags . We <nl> + # always need to set the SHARED_FLAGS , though . <nl> + if ( CUDA_PROPAGATE_HOST_FLAGS ) <nl> + set ( _cuda_host_flags " set ( CMAKE_HOST_FLAGS $ { CMAKE_ $ { CUDA_C_OR_CXX } _FLAGS } $ { CUDA_HOST_SHARED_FLAGS } ) " ) <nl> + else ( ) <nl> + set ( _cuda_host_flags " set ( CMAKE_HOST_FLAGS $ { CUDA_HOST_SHARED_FLAGS } ) " ) <nl> + endif ( ) <nl> + <nl> + set ( _cuda_nvcc_flags_config " # Build specific configuration flags " ) <nl> + # Loop over all the configuration types to generate appropriate flags for run_nvcc . cmake <nl> + foreach ( config $ { CUDA_configuration_types } ) <nl> + string ( TOUPPER $ { config } config_upper ) <nl> + # CMAKE_FLAGS are strings and not lists . By not putting quotes around CMAKE_FLAGS <nl> + # we convert the strings to lists ( like we want ) . <nl> + <nl> + if ( CUDA_PROPAGATE_HOST_FLAGS ) <nl> + # nvcc chokes on - g3 in versions previous to 3 . 0 , so replace it with - g <nl> + set ( _cuda_fix_g3 FALSE ) <nl> + <nl> + if ( CMAKE_COMPILER_IS_GNUCC ) <nl> + if ( CUDA_VERSION VERSION_LESS " 3 . 0 " OR <nl> + CUDA_VERSION VERSION_EQUAL " 4 . 1 " OR <nl> + CUDA_VERSION VERSION_EQUAL " 4 . 2 " <nl> + ) <nl> + set ( _cuda_fix_g3 TRUE ) <nl> + endif ( ) <nl> + endif ( ) <nl> + if ( _cuda_fix_g3 ) <nl> + string ( REPLACE " - g3 " " - g " _cuda_C_FLAGS " $ { CMAKE_ $ { CUDA_C_OR_CXX } _FLAGS_ $ { config_upper } } " ) <nl> + else ( ) <nl> + set ( _cuda_C_FLAGS " $ { CMAKE_ $ { CUDA_C_OR_CXX } _FLAGS_ $ { config_upper } } " ) <nl> + endif ( ) <nl> + <nl> + set ( _cuda_host_flags " $ { _cuda_host_flags } \ nset ( CMAKE_HOST_FLAGS_ $ { config_upper } $ { _cuda_C_FLAGS } ) " ) <nl> + endif ( ) <nl> + <nl> + # Note that if we ever want CUDA_NVCC_FLAGS_ < CONFIG > to be string ( instead of a list <nl> + # like it is currently ) , we can remove the quotes around the <nl> + # $ { CUDA_NVCC_FLAGS_ $ { config_upper } } variable like the CMAKE_HOST_FLAGS_ < CONFIG > variable . <nl> + set ( _cuda_nvcc_flags_config " $ { _cuda_nvcc_flags_config } \ nset ( CUDA_NVCC_FLAGS_ $ { config_upper } $ { CUDA_NVCC_FLAGS_ $ { config_upper } } ; ; $ { CUDA_WRAP_OPTION_NVCC_FLAGS_ $ { config_upper } } ) " ) <nl> + endforeach ( ) <nl> + <nl> + # Get the list of definitions from the directory property <nl> + get_directory_property ( CUDA_NVCC_DEFINITIONS COMPILE_DEFINITIONS ) <nl> + if ( CUDA_NVCC_DEFINITIONS ) <nl> + foreach ( _definition $ { CUDA_NVCC_DEFINITIONS } ) <nl> + list ( APPEND nvcc_flags " - D $ { _definition } " ) <nl> + endforeach ( ) <nl> + endif ( ) <nl> + <nl> + if ( _cuda_build_shared_libs ) <nl> + list ( APPEND nvcc_flags " - D $ { cuda_target } _EXPORTS " ) <nl> + endif ( ) <nl> + <nl> + # Reset the output variable <nl> + set ( _cuda_wrap_generated_files " " ) <nl> + <nl> + # Iterate over the macro arguments and create custom <nl> + # commands for all the . cu files . <nl> + foreach ( file $ { ARGN } ) <nl> + # Ignore any file marked as a HEADER_FILE_ONLY <nl> + get_source_file_property ( _is_header $ { file } HEADER_FILE_ONLY ) <nl> + if ( $ { file } MATCHES " . * \ \ . cu $ " AND NOT _is_header ) <nl> + <nl> + # Allow per source file overrides of the format . <nl> + get_source_file_property ( _cuda_source_format $ { file } CUDA_SOURCE_PROPERTY_FORMAT ) <nl> + if ( NOT _cuda_source_format ) <nl> + set ( _cuda_source_format $ { format } ) <nl> + endif ( ) <nl> + <nl> + if ( $ { _cuda_source_format } MATCHES " PTX " ) <nl> + set ( compile_to_ptx ON ) <nl> + elseif ( $ { _cuda_source_format } MATCHES " OBJ " ) <nl> + set ( compile_to_ptx OFF ) <nl> + else ( ) <nl> + message ( FATAL_ERROR " Invalid format flag passed to CUDA_WRAP_SRCS for file ' $ { file } ' : ' $ { _cuda_source_format } ' . Use OBJ or PTX . " ) <nl> + endif ( ) <nl> + <nl> + <nl> + if ( compile_to_ptx ) <nl> + # Don ' t use any of the host compilation flags for PTX targets . <nl> + set ( CUDA_HOST_FLAGS ) <nl> + set ( CUDA_NVCC_FLAGS_CONFIG ) <nl> + else ( ) <nl> + set ( CUDA_HOST_FLAGS $ { _cuda_host_flags } ) <nl> + set ( CUDA_NVCC_FLAGS_CONFIG $ { _cuda_nvcc_flags_config } ) <nl> + endif ( ) <nl> + <nl> + # Determine output directory <nl> + cuda_compute_build_path ( " $ { file } " cuda_build_path ) <nl> + set ( cuda_compile_intermediate_directory " $ { CMAKE_CURRENT_BINARY_DIR } / CMakeFiles / $ { cuda_target } . dir / $ { cuda_build_path } " ) <nl> + if ( CUDA_GENERATED_OUTPUT_DIR ) <nl> + set ( cuda_compile_output_dir " $ { CUDA_GENERATED_OUTPUT_DIR } " ) <nl> + else ( ) <nl> + if ( compile_to_ptx ) <nl> + set ( cuda_compile_output_dir " $ { CMAKE_CURRENT_BINARY_DIR } " ) <nl> + else ( ) <nl> + set ( cuda_compile_output_dir " $ { cuda_compile_intermediate_directory } " ) <nl> + endif ( ) <nl> + endif ( ) <nl> + <nl> + # Add a custom target to generate a c or ptx file . # # # # # # # # # # # # # # # # # # # # # # <nl> + <nl> + get_filename_component ( basename $ { file } NAME ) <nl> + if ( compile_to_ptx ) <nl> + set ( generated_file_path " $ { cuda_compile_output_dir } " ) <nl> + set ( generated_file_basename " $ { cuda_target } _generated_ $ { basename } . ptx " ) <nl> + set ( format_flag " - ptx " ) <nl> + file ( MAKE_DIRECTORY " $ { cuda_compile_output_dir } " ) <nl> + else ( ) <nl> + set ( generated_file_path " $ { cuda_compile_output_dir } / $ { CMAKE_CFG_INTDIR } " ) <nl> + set ( generated_file_basename " $ { cuda_target } _generated_ $ { basename } $ { generated_extension } " ) <nl> + if ( CUDA_SEPARABLE_COMPILATION ) <nl> + set ( format_flag " - dc " ) <nl> + else ( ) <nl> + set ( format_flag " - c " ) <nl> + endif ( ) <nl> + endif ( ) <nl> + <nl> + # Set all of our file names . Make sure that whatever filenames that have <nl> + # generated_file_path in them get passed in through as a command line <nl> + # argument , so that the $ { CMAKE_CFG_INTDIR } gets expanded at run time <nl> + # instead of configure time . <nl> + set ( generated_file " $ { generated_file_path } / $ { generated_file_basename } " ) <nl> + set ( cmake_dependency_file " $ { cuda_compile_intermediate_directory } / $ { generated_file_basename } . depend " ) <nl> + set ( NVCC_generated_dependency_file " $ { cuda_compile_intermediate_directory } / $ { generated_file_basename } . NVCC - depend " ) <nl> + set ( generated_cubin_file " $ { generated_file_path } / $ { generated_file_basename } . cubin . txt " ) <nl> + set ( custom_target_script " $ { cuda_compile_intermediate_directory } / $ { generated_file_basename } . cmake " ) <nl> + <nl> + # Setup properties for obj files : <nl> + if ( NOT compile_to_ptx ) <nl> + set_source_files_properties ( " $ { generated_file } " <nl> + PROPERTIES <nl> + EXTERNAL_OBJECT true # This is an object file not to be compiled , but only be linked . <nl> + ) <nl> + endif ( ) <nl> + <nl> + # Don ' t add CMAKE_CURRENT_SOURCE_DIR if the path is already an absolute path . <nl> + get_filename_component ( file_path " $ { file } " PATH ) <nl> + if ( IS_ABSOLUTE " $ { file_path } " ) <nl> + set ( source_file " $ { file } " ) <nl> + else ( ) <nl> + set ( source_file " $ { CMAKE_CURRENT_SOURCE_DIR } / $ { file } " ) <nl> + endif ( ) <nl> + <nl> + if ( NOT compile_to_ptx AND CUDA_SEPARABLE_COMPILATION ) <nl> + list ( APPEND $ { cuda_target } _SEPARABLE_COMPILATION_OBJECTS " $ { generated_file } " ) <nl> + endif ( ) <nl> + <nl> + # Bring in the dependencies . Creates a variable CUDA_NVCC_DEPEND # # # # # # # <nl> + cuda_include_nvcc_dependencies ( $ { cmake_dependency_file } ) <nl> + <nl> + # Convience string for output # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + if ( CUDA_BUILD_EMULATION ) <nl> + set ( cuda_build_type " Emulation " ) <nl> + else ( ) <nl> + set ( cuda_build_type " Device " ) <nl> + endif ( ) <nl> + <nl> + # Build the NVCC made dependency file # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + set ( build_cubin OFF ) <nl> + if ( NOT CUDA_BUILD_EMULATION AND CUDA_BUILD_CUBIN ) <nl> + if ( NOT compile_to_ptx ) <nl> + set ( build_cubin ON ) <nl> + endif ( ) <nl> + endif ( ) <nl> + <nl> + # Configure the build script <nl> + configure_file ( " $ { CUDA_run_nvcc } " " $ { custom_target_script } " @ ONLY ) <nl> + <nl> + # So if a user specifies the same cuda file as input more than once , you <nl> + # can have bad things happen with dependencies . Here we check an option <nl> + # to see if this is the behavior they want . <nl> + if ( CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE ) <nl> + set ( main_dep MAIN_DEPENDENCY $ { source_file } ) <nl> + else ( ) <nl> + set ( main_dep DEPENDS $ { source_file } ) <nl> + endif ( ) <nl> + <nl> + if ( CUDA_VERBOSE_BUILD ) <nl> + set ( verbose_output ON ) <nl> + elseif ( CMAKE_GENERATOR MATCHES " Makefiles " ) <nl> + set ( verbose_output " $ ( VERBOSE ) " ) <nl> + else ( ) <nl> + set ( verbose_output OFF ) <nl> + endif ( ) <nl> + <nl> + # Create up the comment string <nl> + file ( RELATIVE_PATH generated_file_relative_path " $ { CMAKE_BINARY_DIR } " " $ { generated_file } " ) <nl> + if ( compile_to_ptx ) <nl> + set ( cuda_build_comment_string " Building NVCC ptx file $ { generated_file_relative_path } " ) <nl> + else ( ) <nl> + set ( cuda_build_comment_string " Building NVCC ( $ { cuda_build_type } ) object $ { generated_file_relative_path } " ) <nl> + endif ( ) <nl> + <nl> + # Build the generated file and dependency file # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + add_custom_command ( <nl> + OUTPUT $ { generated_file } <nl> + # These output files depend on the source_file and the contents of cmake_dependency_file <nl> + $ { main_dep } <nl> + DEPENDS $ { CUDA_NVCC_DEPEND } <nl> + DEPENDS $ { custom_target_script } <nl> + # Make sure the output directory exists before trying to write to it . <nl> + COMMAND $ { CMAKE_COMMAND } - E make_directory " $ { generated_file_path } " <nl> + COMMAND $ { CMAKE_COMMAND } ARGS <nl> + - D verbose : BOOL = $ { verbose_output } <nl> + $ { ccbin_flags } <nl> + - D build_configuration : STRING = $ { CUDA_build_configuration } <nl> + - D " generated_file : STRING = $ { generated_file } " <nl> + - D " generated_cubin_file : STRING = $ { generated_cubin_file } " <nl> + - P " $ { custom_target_script } " <nl> + WORKING_DIRECTORY " $ { cuda_compile_intermediate_directory } " <nl> + COMMENT " $ { cuda_build_comment_string } " <nl> + ) <nl> + <nl> + # Make sure the build system knows the file is generated . <nl> + set_source_files_properties ( $ { generated_file } PROPERTIES GENERATED TRUE ) <nl> + <nl> + list ( APPEND _cuda_wrap_generated_files $ { generated_file } ) <nl> + <nl> + # Add the other files that we want cmake to clean on a cleanup # # # # # # # # # # <nl> + list ( APPEND CUDA_ADDITIONAL_CLEAN_FILES " $ { cmake_dependency_file } " ) <nl> + list ( REMOVE_DUPLICATES CUDA_ADDITIONAL_CLEAN_FILES ) <nl> + set ( CUDA_ADDITIONAL_CLEAN_FILES $ { CUDA_ADDITIONAL_CLEAN_FILES } CACHE INTERNAL " List of intermediate files that are part of the cuda dependency scanning . " ) <nl> + <nl> + endif ( ) <nl> + endforeach ( ) <nl> + <nl> + # Set the return parameter <nl> + set ( $ { generated_files } $ { _cuda_wrap_generated_files } ) <nl> + endmacro ( ) <nl> + <nl> + function ( _cuda_get_important_host_flags important_flags flag_string ) <nl> + if ( CMAKE_GENERATOR MATCHES " Visual Studio " ) <nl> + string ( REGEX MATCHALL " / M [ DT ] [ d ] ? " flags $ { flag_string } ) <nl> + list ( APPEND $ { important_flags } $ { flags } ) <nl> + else ( ) <nl> + string ( REGEX MATCHALL " - fPIC " flags $ { flag_string } ) <nl> + list ( APPEND $ { important_flags } $ { flags } ) <nl> + endif ( ) <nl> + set ( $ { important_flags } $ { $ { important_flags } } PARENT_SCOPE ) <nl> + endfunction ( ) <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # Separable Compilation Link <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + <nl> + # Compute the filename to be used by CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS <nl> + function ( CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME output_file_var cuda_target object_files ) <nl> + if ( object_files ) <nl> + set ( generated_extension $ { CMAKE_ $ { CUDA_C_OR_CXX } _OUTPUT_EXTENSION } ) <nl> + set ( output_file " $ { CMAKE_CURRENT_BINARY_DIR } / CMakeFiles / $ { cuda_target } . dir / $ { CMAKE_CFG_INTDIR } / $ { cuda_target } _intermediate_link $ { generated_extension } " ) <nl> + else ( ) <nl> + set ( output_file ) <nl> + endif ( ) <nl> + <nl> + set ( $ { output_file_var } " $ { output_file } " PARENT_SCOPE ) <nl> + endfunction ( ) <nl> + <nl> + # Setup the build rule for the separable compilation intermediate link file . <nl> + function ( CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options object_files ) <nl> + if ( object_files ) <nl> + <nl> + set_source_files_properties ( " $ { output_file } " <nl> + PROPERTIES <nl> + EXTERNAL_OBJECT TRUE # This is an object file not to be compiled , but only <nl> + # be linked . <nl> + GENERATED TRUE # This file is generated during the build <nl> + ) <nl> + <nl> + # For now we are ignoring all the configuration specific flags . <nl> + set ( nvcc_flags ) <nl> + CUDA_PARSE_NVCC_OPTIONS ( nvcc_flags $ { options } ) <nl> + if ( CUDA_64_BIT_DEVICE_CODE ) <nl> + list ( APPEND nvcc_flags - m64 ) <nl> + else ( ) <nl> + list ( APPEND nvcc_flags - m32 ) <nl> + endif ( ) <nl> + # If - ccbin , - - compiler - bindir has been specified , don ' t do anything . Otherwise add it here . <nl> + list ( FIND nvcc_flags " - ccbin " ccbin_found0 ) <nl> + list ( FIND nvcc_flags " - - compiler - bindir " ccbin_found1 ) <nl> + if ( ccbin_found0 LESS 0 AND ccbin_found1 LESS 0 ) <nl> + list ( APPEND nvcc_flags - ccbin " \ " $ { CUDA_HOST_COMPILER } \ " " ) <nl> + endif ( ) <nl> + set ( flags ) <nl> + foreach ( config $ { CUDA_configuration_types } ) <nl> + string ( TOUPPER $ { config } config_upper ) <nl> + set ( important_host_flags ) <nl> + _cuda_get_important_host_flags ( important_host_flags $ { CMAKE_ $ { CUDA_C_OR_CXX } _FLAGS_ $ { config_upper } } ) <nl> + foreach ( f $ { important_host_flags } ) <nl> + list ( APPEND flags $ < $ < CONFIG : $ { config } > : - Xcompiler > $ < $ < CONFIG : $ { config } > : $ { f } > ) <nl> + endforeach ( ) <nl> + endforeach ( ) <nl> + file ( RELATIVE_PATH output_file_relative_path " $ { CMAKE_BINARY_DIR } " " $ { output_file } " ) <nl> + <nl> + # Some generators don ' t handle the multiple levels of custom command <nl> + # dependencies correctly ( obj1 depends on file1 , obj2 depends on obj1 ) , so <nl> + # we work around that issue by compiling the intermediate link object as a <nl> + # pre - link custom command in that situation . <nl> + set ( do_obj_build_rule TRUE ) <nl> + if ( MSVC_VERSION GREATER 1599 ) <nl> + # VS 2010 and 2012 have this problem . If future versions fix this issue , <nl> + # it should still work , it just won ' t be as nice as the other method . <nl> + set ( do_obj_build_rule FALSE ) <nl> + endif ( ) <nl> + <nl> + if ( do_obj_build_rule ) <nl> + add_custom_command ( <nl> + OUTPUT $ { output_file } <nl> + DEPENDS $ { object_files } <nl> + COMMAND $ { CUDA_NVCC_EXECUTABLE } $ { nvcc_flags } - dlink $ { object_files } - o $ { output_file } <nl> + $ { flags } <nl> + COMMENT " Building NVCC intermediate link file $ { output_file_relative_path } " <nl> + ) <nl> + else ( ) <nl> + add_custom_command ( <nl> + TARGET $ { cuda_target } <nl> + PRE_LINK <nl> + COMMAND $ { CMAKE_COMMAND } - E echo " Building NVCC intermediate link file $ { output_file_relative_path } " <nl> + COMMAND $ { CUDA_NVCC_EXECUTABLE } $ { nvcc_flags } $ { flags } - dlink $ { object_files } - o " $ { output_file } " <nl> + ) <nl> + endif ( ) <nl> + endif ( ) <nl> + endfunction ( ) <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # ADD LIBRARY <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + macro ( CUDA_ADD_LIBRARY cuda_target ) <nl> + <nl> + CUDA_ADD_CUDA_INCLUDE_ONCE ( ) <nl> + <nl> + # Separate the sources from the options <nl> + CUDA_GET_SOURCES_AND_OPTIONS ( _sources _cmake_options _options $ { ARGN } ) <nl> + CUDA_BUILD_SHARED_LIBRARY ( _cuda_shared_flag $ { ARGN } ) <nl> + # Create custom commands and targets for each file . <nl> + CUDA_WRAP_SRCS ( $ { cuda_target } OBJ _generated_files $ { _sources } <nl> + $ { _cmake_options } $ { _cuda_shared_flag } <nl> + OPTIONS $ { _options } ) <nl> + <nl> + # Compute the file name of the intermedate link file used for separable <nl> + # compilation . <nl> + CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME ( link_file $ { cuda_target } " $ { $ { cuda_target } _SEPARABLE_COMPILATION_OBJECTS } " ) <nl> + <nl> + # Add the library . <nl> + add_library ( $ { cuda_target } $ { _cmake_options } <nl> + $ { _generated_files } <nl> + $ { _sources } <nl> + $ { link_file } <nl> + ) <nl> + <nl> + # Add a link phase for the separable compilation if it has been enabled . If <nl> + # it has been enabled then the $ { cuda_target } _SEPARABLE_COMPILATION_OBJECTS <nl> + # variable will have been defined . <nl> + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS ( " $ { link_file } " $ { cuda_target } " $ { _options } " " $ { $ { cuda_target } _SEPARABLE_COMPILATION_OBJECTS } " ) <nl> + <nl> + target_link_libraries ( $ { cuda_target } <nl> + $ { CUDA_LIBRARIES } <nl> + ) <nl> + <nl> + # We need to set the linker language based on what the expected generated file <nl> + # would be . CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP . <nl> + set_target_properties ( $ { cuda_target } <nl> + PROPERTIES <nl> + LINKER_LANGUAGE $ { CUDA_C_OR_CXX } <nl> + ) <nl> + <nl> + endmacro ( ) <nl> + <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # ADD EXECUTABLE <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + macro ( CUDA_ADD_EXECUTABLE cuda_target ) <nl> + <nl> + CUDA_ADD_CUDA_INCLUDE_ONCE ( ) <nl> + <nl> + # Separate the sources from the options <nl> + CUDA_GET_SOURCES_AND_OPTIONS ( _sources _cmake_options _options $ { ARGN } ) <nl> + # Create custom commands and targets for each file . <nl> + CUDA_WRAP_SRCS ( $ { cuda_target } OBJ _generated_files $ { _sources } OPTIONS $ { _options } ) <nl> + <nl> + # Compute the file name of the intermedate link file used for separable <nl> + # compilation . <nl> + CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME ( link_file $ { cuda_target } " $ { $ { cuda_target } _SEPARABLE_COMPILATION_OBJECTS } " ) <nl> + <nl> + # Add the library . <nl> + add_executable ( $ { cuda_target } $ { _cmake_options } <nl> + $ { _generated_files } <nl> + $ { _sources } <nl> + $ { link_file } <nl> + ) <nl> + <nl> + # Add a link phase for the separable compilation if it has been enabled . If <nl> + # it has been enabled then the $ { cuda_target } _SEPARABLE_COMPILATION_OBJECTS <nl> + # variable will have been defined . <nl> + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS ( " $ { link_file } " $ { cuda_target } " $ { _options } " " $ { $ { cuda_target } _SEPARABLE_COMPILATION_OBJECTS } " ) <nl> + <nl> + target_link_libraries ( $ { cuda_target } <nl> + $ { CUDA_LIBRARIES } <nl> + ) <nl> + <nl> + # We need to set the linker language based on what the expected generated file <nl> + # would be . CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP . <nl> + set_target_properties ( $ { cuda_target } <nl> + PROPERTIES <nl> + LINKER_LANGUAGE $ { CUDA_C_OR_CXX } <nl> + ) <nl> + <nl> + endmacro ( ) <nl> + <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # CUDA COMPILE <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + macro ( CUDA_COMPILE generated_files ) <nl> + <nl> + # Separate the sources from the options <nl> + CUDA_GET_SOURCES_AND_OPTIONS ( _sources _cmake_options _options $ { ARGN } ) <nl> + # Create custom commands and targets for each file . <nl> + CUDA_WRAP_SRCS ( cuda_compile OBJ _generated_files $ { _sources } $ { _cmake_options } <nl> + OPTIONS $ { _options } ) <nl> + <nl> + set ( $ { generated_files } $ { _generated_files } ) <nl> + <nl> + endmacro ( ) <nl> + <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # CUDA COMPILE PTX <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + macro ( CUDA_COMPILE_PTX generated_files ) <nl> + <nl> + # Separate the sources from the options <nl> + CUDA_GET_SOURCES_AND_OPTIONS ( _sources _cmake_options _options $ { ARGN } ) <nl> + # Create custom commands and targets for each file . <nl> + CUDA_WRAP_SRCS ( cuda_compile_ptx PTX _generated_files $ { _sources } $ { _cmake_options } <nl> + OPTIONS $ { _options } ) <nl> + <nl> + set ( $ { generated_files } $ { _generated_files } ) <nl> + <nl> + endmacro ( ) <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # CUDA ADD CUFFT TO TARGET <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + macro ( CUDA_ADD_CUFFT_TO_TARGET target ) <nl> + if ( CUDA_BUILD_EMULATION ) <nl> + target_link_libraries ( $ { target } $ { CUDA_cufftemu_LIBRARY } ) <nl> + else ( ) <nl> + target_link_libraries ( $ { target } $ { CUDA_cufft_LIBRARY } ) <nl> + endif ( ) <nl> + endmacro ( ) <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # CUDA ADD CUBLAS TO TARGET <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + macro ( CUDA_ADD_CUBLAS_TO_TARGET target ) <nl> + if ( CUDA_BUILD_EMULATION ) <nl> + target_link_libraries ( $ { target } $ { CUDA_cublasemu_LIBRARY } ) <nl> + else ( ) <nl> + target_link_libraries ( $ { target } $ { CUDA_cublas_LIBRARY } ) <nl> + endif ( ) <nl> + endmacro ( ) <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # CUDA BUILD CLEAN TARGET <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + macro ( CUDA_BUILD_CLEAN_TARGET ) <nl> + # Call this after you add all your CUDA targets , and you will get a convience <nl> + # target . You should also make clean after running this target to get the <nl> + # build system to generate all the code again . <nl> + <nl> + set ( cuda_clean_target_name clean_cuda_depends ) <nl> + if ( CMAKE_GENERATOR MATCHES " Visual Studio " ) <nl> + string ( TOUPPER $ { cuda_clean_target_name } cuda_clean_target_name ) <nl> + endif ( ) <nl> + add_custom_target ( $ { cuda_clean_target_name } <nl> + COMMAND $ { CMAKE_COMMAND } - E remove $ { CUDA_ADDITIONAL_CLEAN_FILES } ) <nl> + <nl> + # Clear out the variable , so the next time we configure it will be empty . <nl> + # This is useful so that the files won ' t persist in the list after targets <nl> + # have been removed . <nl> + set ( CUDA_ADDITIONAL_CLEAN_FILES " " CACHE INTERNAL " List of intermediate files that are part of the cuda dependency scanning . " ) <nl> + endmacro ( ) <nl> new file mode 100644 <nl> index 00000000000 . . 1b53d177d03 <nl> mmm / dev / null <nl> ppp b / cmake / FindCUDA / make2cmake . cmake <nl> <nl> + # James Bigler , NVIDIA Corp ( nvidia . com - jbigler ) <nl> + # Abe Stephens , SCI Institute - - http : / / www . sci . utah . edu / ~ abe / FindCuda . html <nl> + # <nl> + # Copyright ( c ) 2008 - 2009 NVIDIA Corporation . All rights reserved . <nl> + # <nl> + # Copyright ( c ) 2007 - 2009 <nl> + # Scientific Computing and Imaging Institute , University of Utah <nl> + # <nl> + # This code is licensed under the MIT License . See the FindCUDA . cmake script <nl> + # for the text of the license . <nl> + <nl> + # The MIT License <nl> + # <nl> + # License for the specific language governing rights and limitations under <nl> + # Permission is hereby granted , free of charge , to any person obtaining a <nl> + # copy of this software and associated documentation files ( the " Software " ) , <nl> + # to deal in the Software without restriction , including without limitation <nl> + # the rights to use , copy , modify , merge , publish , distribute , sublicense , <nl> + # and / or sell copies of the Software , and to permit persons to whom the <nl> + # Software is furnished to do so , subject to the following conditions : <nl> + # <nl> + # The above copyright notice and this permission notice shall be included <nl> + # in all copies or substantial portions of the Software . <nl> + # <nl> + # THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS <nl> + # OR IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> + # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL <nl> + # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> + # LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING <nl> + # FROM , OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER <nl> + # DEALINGS IN THE SOFTWARE . <nl> + # <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # This converts a file written in makefile syntax into one that can be included <nl> + # by CMake . <nl> + <nl> + file ( READ $ { input_file } depend_text ) <nl> + <nl> + if ( $ { depend_text } MATCHES " . + " ) <nl> + <nl> + # message ( " FOUND DEPENDS " ) <nl> + <nl> + # Remember , four backslashes is escaped to one backslash in the string . <nl> + string ( REGEX REPLACE " \ \ \ \ " " " depend_text $ { depend_text } ) <nl> + <nl> + # This works for the nvcc - M generated dependency files . <nl> + string ( REGEX REPLACE " ^ . * : " " " depend_text $ { depend_text } ) <nl> + string ( REGEX REPLACE " [ \ \ \ \ ] * \ n " " ; " depend_text $ { depend_text } ) <nl> + <nl> + set ( dependency_list " " ) <nl> + <nl> + foreach ( file $ { depend_text } ) <nl> + <nl> + string ( REGEX REPLACE " ^ + " " " file $ { file } ) <nl> + <nl> + # OK , now if we had a UNC path , nvcc has a tendency to only output the first ' / ' <nl> + # instead of ' / / ' . Here we will test to see if the file exists , if it doesn ' t then <nl> + # try to prepend another ' / ' to the path and test again . If it still fails remove the <nl> + # path . <nl> + <nl> + if ( NOT EXISTS " $ { file } " ) <nl> + if ( EXISTS " / $ { file } " ) <nl> + set ( file " / $ { file } " ) <nl> + else ( ) <nl> + message ( WARNING " Removing non - existent dependency file : $ { file } " ) <nl> + set ( file " " ) <nl> + endif ( ) <nl> + endif ( ) <nl> + <nl> + if ( NOT IS_DIRECTORY " $ { file } " ) <nl> + # If softlinks start to matter , we should change this to REALPATH . For now we need <nl> + # to flatten paths , because nvcc can generate stuff like / bin / . . / include instead of <nl> + # just / include . <nl> + get_filename_component ( file_absolute " $ { file } " ABSOLUTE ) <nl> + list ( APPEND dependency_list " $ { file_absolute } " ) <nl> + endif ( ) <nl> + <nl> + endforeach ( ) <nl> + <nl> + else ( ) <nl> + # message ( " FOUND NO DEPENDS " ) <nl> + endif ( ) <nl> + <nl> + # Remove the duplicate entries and sort them . <nl> + list ( REMOVE_DUPLICATES dependency_list ) <nl> + list ( SORT dependency_list ) <nl> + <nl> + foreach ( file $ { dependency_list } ) <nl> + set ( cuda_nvcc_depend " $ { cuda_nvcc_depend } \ " $ { file } \ " \ n " ) <nl> + endforeach ( ) <nl> + <nl> + file ( WRITE $ { output_file } " # Generated by : make2cmake . cmake \ nSET ( CUDA_NVCC_DEPEND \ n $ { cuda_nvcc_depend } ) \ n \ n " ) <nl> new file mode 100644 <nl> index 00000000000 . . e1905cfc660 <nl> mmm / dev / null <nl> ppp b / cmake / FindCUDA / parse_cubin . cmake <nl> <nl> + # James Bigler , NVIDIA Corp ( nvidia . com - jbigler ) <nl> + # Abe Stephens , SCI Institute - - http : / / www . sci . utah . edu / ~ abe / FindCuda . html <nl> + # <nl> + # Copyright ( c ) 2008 - 2009 NVIDIA Corporation . All rights reserved . <nl> + # <nl> + # Copyright ( c ) 2007 - 2009 <nl> + # Scientific Computing and Imaging Institute , University of Utah <nl> + # <nl> + # This code is licensed under the MIT License . See the FindCUDA . cmake script <nl> + # for the text of the license . <nl> + <nl> + # The MIT License <nl> + # <nl> + # License for the specific language governing rights and limitations under <nl> + # Permission is hereby granted , free of charge , to any person obtaining a <nl> + # copy of this software and associated documentation files ( the " Software " ) , <nl> + # to deal in the Software without restriction , including without limitation <nl> + # the rights to use , copy , modify , merge , publish , distribute , sublicense , <nl> + # and / or sell copies of the Software , and to permit persons to whom the <nl> + # Software is furnished to do so , subject to the following conditions : <nl> + # <nl> + # The above copyright notice and this permission notice shall be included <nl> + # in all copies or substantial portions of the Software . <nl> + # <nl> + # THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS <nl> + # OR IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> + # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL <nl> + # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> + # LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING <nl> + # FROM , OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER <nl> + # DEALINGS IN THE SOFTWARE . <nl> + # <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # Parses a . cubin file produced by nvcc and reports statistics about the file . <nl> + <nl> + <nl> + file ( READ $ { input_file } file_text ) <nl> + <nl> + if ( $ { file_text } MATCHES " . + " ) <nl> + <nl> + # Remember , four backslashes is escaped to one backslash in the string . <nl> + string ( REGEX REPLACE " ; " " \ \ \ \ ; " file_text $ { file_text } ) <nl> + string ( REGEX REPLACE " \ ncode " " ; code " file_text $ { file_text } ) <nl> + <nl> + list ( LENGTH file_text len ) <nl> + <nl> + foreach ( line $ { file_text } ) <nl> + <nl> + # Only look at " code { } " blocks . <nl> + if ( line MATCHES " ^ code " ) <nl> + <nl> + # Break into individual lines . <nl> + string ( REGEX REPLACE " \ n " " ; " line $ { line } ) <nl> + <nl> + foreach ( entry $ { line } ) <nl> + <nl> + # Extract kernel names . <nl> + if ( $ { entry } MATCHES " [ ^ g ] name = ( [ ^ ] + ) " ) <nl> + string ( REGEX REPLACE " . * = ( [ ^ ] + ) " " \ \ 1 " entry $ { entry } ) <nl> + <nl> + # Check to see if the kernel name starts with " _ " <nl> + set ( skip FALSE ) <nl> + # if ( $ { entry } MATCHES " ^ _ " ) <nl> + # Skip the rest of this block . <nl> + # message ( " Skipping $ { entry } " ) <nl> + # set ( skip TRUE ) <nl> + # else ( ) <nl> + message ( " Kernel : $ { entry } " ) <nl> + # endif ( ) <nl> + <nl> + endif ( ) <nl> + <nl> + # Skip the rest of the block if necessary <nl> + if ( NOT skip ) <nl> + <nl> + # Registers <nl> + if ( $ { entry } MATCHES " reg ( [ ] + ) = ( [ ] + ) ( [ ^ ] + ) " ) <nl> + string ( REGEX REPLACE " . * ( [ ] + ) = ( [ ] + ) ( [ ^ ] + ) " " \ \ 3 " entry $ { entry } ) <nl> + message ( " Registers : $ { entry } " ) <nl> + endif ( ) <nl> + <nl> + # Local memory <nl> + if ( $ { entry } MATCHES " lmem ( [ ] + ) = ( [ ] + ) ( [ ^ ] + ) " ) <nl> + string ( REGEX REPLACE " . * ( [ ] + ) = ( [ ] + ) ( [ ^ ] + ) " " \ \ 3 " entry $ { entry } ) <nl> + message ( " Local : $ { entry } " ) <nl> + endif ( ) <nl> + <nl> + # Shared memory <nl> + if ( $ { entry } MATCHES " smem ( [ ] + ) = ( [ ] + ) ( [ ^ ] + ) " ) <nl> + string ( REGEX REPLACE " . * ( [ ] + ) = ( [ ] + ) ( [ ^ ] + ) " " \ \ 3 " entry $ { entry } ) <nl> + message ( " Shared : $ { entry } " ) <nl> + endif ( ) <nl> + <nl> + if ( $ { entry } MATCHES " ^ } " ) <nl> + message ( " " ) <nl> + endif ( ) <nl> + <nl> + endif ( ) <nl> + <nl> + <nl> + endforeach ( ) <nl> + <nl> + endif ( ) <nl> + <nl> + endforeach ( ) <nl> + <nl> + else ( ) <nl> + # message ( " FOUND NO DEPENDS " ) <nl> + endif ( ) <nl> new file mode 100644 <nl> index 00000000000 . . f0aac8487a7 <nl> mmm / dev / null <nl> ppp b / cmake / FindCUDA / run_nvcc . cmake <nl> <nl> + # James Bigler , NVIDIA Corp ( nvidia . com - jbigler ) <nl> + # <nl> + # Copyright ( c ) 2008 - 2009 NVIDIA Corporation . All rights reserved . <nl> + # <nl> + # This code is licensed under the MIT License . See the FindCUDA . cmake script <nl> + # for the text of the license . <nl> + <nl> + # The MIT License <nl> + # <nl> + # License for the specific language governing rights and limitations under <nl> + # Permission is hereby granted , free of charge , to any person obtaining a <nl> + # copy of this software and associated documentation files ( the " Software " ) , <nl> + # to deal in the Software without restriction , including without limitation <nl> + # the rights to use , copy , modify , merge , publish , distribute , sublicense , <nl> + # and / or sell copies of the Software , and to permit persons to whom the <nl> + # Software is furnished to do so , subject to the following conditions : <nl> + # <nl> + # The above copyright notice and this permission notice shall be included <nl> + # in all copies or substantial portions of the Software . <nl> + # <nl> + # THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS <nl> + # OR IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> + # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL <nl> + # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> + # LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING <nl> + # FROM , OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER <nl> + # DEALINGS IN THE SOFTWARE . <nl> + <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # This file runs the nvcc commands to produce the desired output file along with <nl> + # the dependency file needed by CMake to compute dependencies . In addition the <nl> + # file checks the output of each command and if the command fails it deletes the <nl> + # output files . <nl> + <nl> + # Input variables <nl> + # <nl> + # verbose : BOOL = < > OFF : Be as quiet as possible ( default ) <nl> + # ON : Describe each step <nl> + # <nl> + # build_configuration : STRING = < > Typically one of Debug , MinSizeRel , Release , or <nl> + # RelWithDebInfo , but it should match one of the <nl> + # entries in CUDA_HOST_FLAGS . This is the build <nl> + # configuration used when compiling the code . If <nl> + # blank or unspecified Debug is assumed as this is <nl> + # what CMake does . <nl> + # <nl> + # generated_file : STRING = < > File to generate . This argument must be passed in . <nl> + # <nl> + # generated_cubin_file : STRING = < > File to generate . This argument must be passed <nl> + # in if build_cubin is true . <nl> + <nl> + if ( NOT generated_file ) <nl> + message ( FATAL_ERROR " You must specify generated_file on the command line " ) <nl> + endif ( ) <nl> + <nl> + # Set these up as variables to make reading the generated file easier <nl> + set ( CMAKE_COMMAND " @ CMAKE_COMMAND @ " ) # path <nl> + set ( source_file " @ source_file @ " ) # path <nl> + set ( NVCC_generated_dependency_file " @ NVCC_generated_dependency_file @ " ) # path <nl> + set ( cmake_dependency_file " @ cmake_dependency_file @ " ) # path <nl> + set ( CUDA_make2cmake " @ CUDA_make2cmake @ " ) # path <nl> + set ( CUDA_parse_cubin " @ CUDA_parse_cubin @ " ) # path <nl> + set ( build_cubin @ build_cubin @ ) # bool <nl> + set ( CUDA_HOST_COMPILER " @ CUDA_HOST_COMPILER @ " ) # bool <nl> + # We won ' t actually use these variables for now , but we need to set this , in <nl> + # order to force this file to be run again if it changes . <nl> + set ( generated_file_path " @ generated_file_path @ " ) # path <nl> + set ( generated_file_internal " @ generated_file @ " ) # path <nl> + set ( generated_cubin_file_internal " @ generated_cubin_file @ " ) # path <nl> + <nl> + set ( CUDA_NVCC_EXECUTABLE " @ CUDA_NVCC_EXECUTABLE @ " ) # path <nl> + set ( CUDA_NVCC_FLAGS @ CUDA_NVCC_FLAGS @ ; ; @ CUDA_WRAP_OPTION_NVCC_FLAGS @ ) # list <nl> + @ CUDA_NVCC_FLAGS_CONFIG @ <nl> + set ( nvcc_flags @ nvcc_flags @ ) # list <nl> + set ( CUDA_NVCC_INCLUDE_ARGS " @ CUDA_NVCC_INCLUDE_ARGS @ " ) # list ( needs to be in quotes to handle spaces properly ) . <nl> + set ( format_flag " @ format_flag @ " ) # string <nl> + <nl> + if ( build_cubin AND NOT generated_cubin_file ) <nl> + message ( FATAL_ERROR " You must specify generated_cubin_file on the command line " ) <nl> + endif ( ) <nl> + <nl> + # This is the list of host compilation flags . It C or CXX should already have <nl> + # been chosen by FindCUDA . cmake . <nl> + @ CUDA_HOST_FLAGS @ <nl> + <nl> + # Take the compiler flags and package them up to be sent to the compiler via - Xcompiler <nl> + set ( nvcc_host_compiler_flags " " ) <nl> + # If we weren ' t given a build_configuration , use Debug . <nl> + if ( NOT build_configuration ) <nl> + set ( build_configuration Debug ) <nl> + endif ( ) <nl> + string ( TOUPPER " $ { build_configuration } " build_configuration ) <nl> + # message ( " CUDA_NVCC_HOST_COMPILER_FLAGS = $ { CUDA_NVCC_HOST_COMPILER_FLAGS } " ) <nl> + foreach ( flag $ { CMAKE_HOST_FLAGS } $ { CMAKE_HOST_FLAGS_ $ { build_configuration } } ) <nl> + # Extra quotes are added around each flag to help nvcc parse out flags with spaces . <nl> + set ( nvcc_host_compiler_flags " $ { nvcc_host_compiler_flags } , \ " $ { flag } \ " " ) <nl> + endforeach ( ) <nl> + if ( nvcc_host_compiler_flags ) <nl> + set ( nvcc_host_compiler_flags " - Xcompiler " $ { nvcc_host_compiler_flags } ) <nl> + endif ( ) <nl> + # message ( " nvcc_host_compiler_flags = \ " $ { nvcc_host_compiler_flags } \ " " ) <nl> + # Add the build specific configuration flags <nl> + list ( APPEND CUDA_NVCC_FLAGS $ { CUDA_NVCC_FLAGS_ $ { build_configuration } } ) <nl> + <nl> + # Any - ccbin existing in CUDA_NVCC_FLAGS gets highest priority <nl> + list ( FIND CUDA_NVCC_FLAGS " - ccbin " ccbin_found0 ) <nl> + list ( FIND CUDA_NVCC_FLAGS " - - compiler - bindir " ccbin_found1 ) <nl> + if ( ccbin_found0 LESS 0 AND ccbin_found1 LESS 0 ) <nl> + if ( CUDA_HOST_COMPILER STREQUAL " $ ( VCInstallDir ) bin " AND DEFINED CCBIN ) <nl> + set ( CCBIN - ccbin " $ { CCBIN } " ) <nl> + else ( ) <nl> + set ( CCBIN - ccbin " $ { CUDA_HOST_COMPILER } " ) <nl> + endif ( ) <nl> + endif ( ) <nl> + <nl> + # cuda_execute_process - Executes a command with optional command echo and status message . <nl> + # <nl> + # status - Status message to print if verbose is true <nl> + # command - COMMAND argument from the usual execute_process argument structure <nl> + # ARGN - Remaining arguments are the command with arguments <nl> + # <nl> + # CUDA_result - return value from running the command <nl> + # <nl> + # Make this a macro instead of a function , so that things like RESULT_VARIABLE <nl> + # and other return variables are present after executing the process . <nl> + macro ( cuda_execute_process status command ) <nl> + set ( _command $ { command } ) <nl> + if ( NOT _command STREQUAL " COMMAND " ) <nl> + message ( FATAL_ERROR " Malformed call to cuda_execute_process . Missing COMMAND as second argument . ( command = $ { command } ) " ) <nl> + endif ( ) <nl> + if ( verbose ) <nl> + execute_process ( COMMAND " $ { CMAKE_COMMAND } " - E echo - - $ { status } ) <nl> + # Now we need to build up our command string . We are accounting for quotes <nl> + # and spaces , anything else is left up to the user to fix if they want to <nl> + # copy and paste a runnable command line . <nl> + set ( cuda_execute_process_string ) <nl> + foreach ( arg $ { ARGN } ) <nl> + # If there are quotes , excape them , so they come through . <nl> + string ( REPLACE " \ " " " \ \ \ " " arg $ { arg } ) <nl> + # Args with spaces need quotes around them to get them to be parsed as a single argument . <nl> + if ( arg MATCHES " " ) <nl> + list ( APPEND cuda_execute_process_string " \ " $ { arg } \ " " ) <nl> + else ( ) <nl> + list ( APPEND cuda_execute_process_string $ { arg } ) <nl> + endif ( ) <nl> + endforeach ( ) <nl> + # Echo the command <nl> + execute_process ( COMMAND $ { CMAKE_COMMAND } - E echo $ { cuda_execute_process_string } ) <nl> + endif ( ) <nl> + # Run the command <nl> + execute_process ( COMMAND $ { ARGN } RESULT_VARIABLE CUDA_result ) <nl> + endmacro ( ) <nl> + <nl> + # Delete the target file <nl> + cuda_execute_process ( <nl> + " Removing $ { generated_file } " <nl> + COMMAND " $ { CMAKE_COMMAND } " - E remove " $ { generated_file } " <nl> + ) <nl> + <nl> + # For CUDA 2 . 3 and below , - G - M doesn ' t work , so remove the - G flag <nl> + # for dependency generation and hope for the best . <nl> + set ( depends_CUDA_NVCC_FLAGS " $ { CUDA_NVCC_FLAGS } " ) <nl> + set ( CUDA_VERSION @ CUDA_VERSION @ ) <nl> + if ( CUDA_VERSION VERSION_LESS " 3 . 0 " ) <nl> + cmake_policy ( PUSH ) <nl> + # CMake policy 0007 NEW states that empty list elements are not <nl> + # ignored . I ' m just setting it to avoid the warning that ' s printed . <nl> + cmake_policy ( SET CMP0007 NEW ) <nl> + # Note that this will remove all occurances of - G . <nl> + list ( REMOVE_ITEM depends_CUDA_NVCC_FLAGS " - G " ) <nl> + cmake_policy ( POP ) <nl> + endif ( ) <nl> + <nl> + # nvcc doesn ' t define __CUDACC__ for some reason when generating dependency files . This <nl> + # can cause incorrect dependencies when # including files based on this macro which is <nl> + # defined in the generating passes of nvcc invokation . We will go ahead and manually <nl> + # define this for now until a future version fixes this bug . <nl> + set ( CUDACC_DEFINE - D__CUDACC__ ) <nl> + <nl> + # Generate the dependency file <nl> + cuda_execute_process ( <nl> + " Generating dependency file : $ { NVCC_generated_dependency_file } " <nl> + COMMAND " $ { CUDA_NVCC_EXECUTABLE } " <nl> + - M <nl> + $ { CUDACC_DEFINE } <nl> + " $ { source_file } " <nl> + - o " $ { NVCC_generated_dependency_file } " <nl> + $ { CCBIN } <nl> + $ { nvcc_flags } <nl> + $ { nvcc_host_compiler_flags } <nl> + $ { depends_CUDA_NVCC_FLAGS } <nl> + - DNVCC <nl> + $ { CUDA_NVCC_INCLUDE_ARGS } <nl> + ) <nl> + <nl> + if ( CUDA_result ) <nl> + message ( FATAL_ERROR " Error generating $ { generated_file } " ) <nl> + endif ( ) <nl> + <nl> + # Generate the cmake readable dependency file to a temp file . Don ' t put the <nl> + # quotes just around the filenames for the input_file and output_file variables . <nl> + # CMake will pass the quotes through and not be able to find the file . <nl> + cuda_execute_process ( <nl> + " Generating temporary cmake readable file : $ { cmake_dependency_file } . tmp " <nl> + COMMAND " $ { CMAKE_COMMAND } " <nl> + - D " input_file : FILEPATH = $ { NVCC_generated_dependency_file } " <nl> + - D " output_file : FILEPATH = $ { cmake_dependency_file } . tmp " <nl> + - P " $ { CUDA_make2cmake } " <nl> + ) <nl> + <nl> + if ( CUDA_result ) <nl> + message ( FATAL_ERROR " Error generating $ { generated_file } " ) <nl> + endif ( ) <nl> + <nl> + # Copy the file if it is different <nl> + cuda_execute_process ( <nl> + " Copy if different $ { cmake_dependency_file } . tmp to $ { cmake_dependency_file } " <nl> + COMMAND " $ { CMAKE_COMMAND } " - E copy_if_different " $ { cmake_dependency_file } . tmp " " $ { cmake_dependency_file } " <nl> + ) <nl> + <nl> + if ( CUDA_result ) <nl> + message ( FATAL_ERROR " Error generating $ { generated_file } " ) <nl> + endif ( ) <nl> + <nl> + # Delete the temporary file <nl> + cuda_execute_process ( <nl> + " Removing $ { cmake_dependency_file } . tmp and $ { NVCC_generated_dependency_file } " <nl> + COMMAND " $ { CMAKE_COMMAND } " - E remove " $ { cmake_dependency_file } . tmp " " $ { NVCC_generated_dependency_file } " <nl> + ) <nl> + <nl> + if ( CUDA_result ) <nl> + message ( FATAL_ERROR " Error generating $ { generated_file } " ) <nl> + endif ( ) <nl> + <nl> + # Generate the code <nl> + cuda_execute_process ( <nl> + " Generating $ { generated_file } " <nl> + COMMAND " $ { CUDA_NVCC_EXECUTABLE } " <nl> + " $ { source_file } " <nl> + $ { format_flag } - o " $ { generated_file } " <nl> + $ { CCBIN } <nl> + $ { nvcc_flags } <nl> + $ { nvcc_host_compiler_flags } <nl> + $ { CUDA_NVCC_FLAGS } <nl> + - DNVCC <nl> + $ { CUDA_NVCC_INCLUDE_ARGS } <nl> + ) <nl> + <nl> + if ( CUDA_result ) <nl> + # Since nvcc can sometimes leave half done files make sure that we delete the output file . <nl> + cuda_execute_process ( <nl> + " Removing $ { generated_file } " <nl> + COMMAND " $ { CMAKE_COMMAND } " - E remove " $ { generated_file } " <nl> + ) <nl> + message ( FATAL_ERROR " Error generating file $ { generated_file } " ) <nl> + else ( ) <nl> + if ( verbose ) <nl> + message ( " Generated $ { generated_file } successfully . " ) <nl> + endif ( ) <nl> + endif ( ) <nl> + <nl> + # Cubin resource report commands . <nl> + if ( build_cubin ) <nl> + # Run with - cubin to produce resource usage report . <nl> + cuda_execute_process ( <nl> + " Generating $ { generated_cubin_file } " <nl> + COMMAND " $ { CUDA_NVCC_EXECUTABLE } " <nl> + " $ { source_file } " <nl> + $ { CUDA_NVCC_FLAGS } <nl> + $ { nvcc_flags } <nl> + $ { CCBIN } <nl> + $ { nvcc_host_compiler_flags } <nl> + - DNVCC <nl> + - cubin <nl> + - o " $ { generated_cubin_file } " <nl> + $ { CUDA_NVCC_INCLUDE_ARGS } <nl> + ) <nl> + <nl> + # Execute the parser script . <nl> + cuda_execute_process ( <nl> + " Executing the parser script " <nl> + COMMAND " $ { CMAKE_COMMAND } " <nl> + - D " input_file : STRING = $ { generated_cubin_file } " <nl> + - P " $ { CUDA_parse_cubin } " <nl> + ) <nl> + <nl> + endif ( ) <nl> mmm a / cmake / OpenCVDetectCUDA . cmake <nl> ppp b / cmake / OpenCVDetectCUDA . cmake <nl> if ( CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL " Cl <nl> return ( ) <nl> endif ( ) <nl> <nl> - find_package ( CUDA 4 . 2 QUIET ) <nl> + set ( CMAKE_MODULE_PATH " $ { OpenCV_SOURCE_DIR } / cmake " $ { CMAKE_MODULE_PATH } ) <nl> + <nl> + find_host_package ( CUDA 4 . 2 QUIET ) <nl> <nl> if ( CUDA_FOUND ) <nl> set ( HAVE_CUDA 1 ) <nl> if ( CUDA_FOUND ) <nl> set ( HAVE_CUBLAS 1 ) <nl> endif ( ) <nl> <nl> - if ( $ { CUDA_VERSION } VERSION_LESS " 5 . 5 " ) <nl> - find_cuda_helper_libs ( npp ) <nl> - else ( ) <nl> - # hack for CUDA 5 . 5 <nl> - if ( $ { CMAKE_SYSTEM_PROCESSOR } STREQUAL " arm " ) <nl> - unset ( CUDA_TOOLKIT_INCLUDE CACHE ) <nl> - unset ( CUDA_CUDART_LIBRARY CACHE ) <nl> - unset ( CUDA_cublas_LIBRARY CACHE ) <nl> - unset ( CUDA_cufft_LIBRARY CACHE ) <nl> - unset ( CUDA_npp_LIBRARY CACHE ) <nl> - <nl> - if ( SOFTFP ) <nl> - set ( cuda_arm_path " $ { CUDA_TOOLKIT_ROOT_DIR } / targets / armv7 - linux - gnueabi " ) <nl> - else ( ) <nl> - set ( cuda_arm_path " $ { CUDA_TOOLKIT_ROOT_DIR } / targets / armv7 - linux - gnueabihf " ) <nl> - endif ( ) <nl> - <nl> - set ( CUDA_TOOLKIT_INCLUDE " $ { cuda_arm_path } / include " CACHE PATH " include path " ) <nl> - set ( CUDA_INCLUDE_DIRS $ { CUDA_TOOLKIT_INCLUDE } ) <nl> - <nl> - set ( cuda_arm_library_path " $ { cuda_arm_path } / lib " ) <nl> - <nl> - set ( CUDA_CUDART_LIBRARY " $ { cuda_arm_library_path } / libcudart . so " CACHE FILEPATH " cudart library " ) <nl> - set ( CUDA_LIBRARIES $ { CUDA_CUDART_LIBRARY } ) <nl> - set ( CUDA_cublas_LIBRARY " $ { cuda_arm_library_path } / libcublas . so " CACHE FILEPATH " cublas library " ) <nl> - set ( CUDA_cufft_LIBRARY " $ { cuda_arm_library_path } / libcufft . so " CACHE FILEPATH " cufft library " ) <nl> - set ( CUDA_nppc_LIBRARY " $ { cuda_arm_library_path } / libnppc . so " CACHE FILEPATH " nppc library " ) <nl> - set ( CUDA_nppi_LIBRARY " $ { cuda_arm_library_path } / libnppi . so " CACHE FILEPATH " nppi library " ) <nl> - set ( CUDA_npps_LIBRARY " $ { cuda_arm_library_path } / libnpps . so " CACHE FILEPATH " npps library " ) <nl> - set ( CUDA_npp_LIBRARY " $ { CUDA_nppc_LIBRARY } ; $ { CUDA_nppi_LIBRARY } ; $ { CUDA_npps_LIBRARY } " CACHE STRING " npp library " ) <nl> - else ( ) <nl> - unset ( CUDA_npp_LIBRARY CACHE ) <nl> - <nl> - find_cuda_helper_libs ( nppc ) <nl> - find_cuda_helper_libs ( nppi ) <nl> - find_cuda_helper_libs ( npps ) <nl> - <nl> - set ( CUDA_npp_LIBRARY " $ { CUDA_nppc_LIBRARY } ; $ { CUDA_nppi_LIBRARY } ; $ { CUDA_npps_LIBRARY } " CACHE STRING " npp library " ) <nl> - endif ( ) <nl> - endif ( ) <nl> - <nl> if ( WITH_NVCUVID ) <nl> find_cuda_helper_libs ( nvcuvid ) <nl> set ( HAVE_NVCUVID 1 ) <nl> if ( CUDA_FOUND ) <nl> set ( OPENCV_CUDA_ARCH_FEATURES " $ { OPENCV_CUDA_ARCH_FEATURES } $ { ARCH } " ) <nl> endforeach ( ) <nl> <nl> - if ( $ { CMAKE_SYSTEM_PROCESSOR } STREQUAL " arm " ) <nl> - set ( CUDA_NVCC_FLAGS " $ { CUDA_NVCC_FLAGS } - - target - cpu - architecture = ARM " ) <nl> - endif ( ) <nl> - <nl> # These vars will be processed in other scripts <nl> set ( CUDA_NVCC_FLAGS $ { CUDA_NVCC_FLAGS } $ { NVCC_FLAGS_EXTRA } ) <nl> set ( OpenCV_CUDA_CC " $ { NVCC_FLAGS_EXTRA } " ) <nl>
Merge pull request from jet47 : cuda - cmake - fix
opencv/opencv
957c85e9c48e1d57ab77d2e320598d8c415b6121
2013-10-29T09:24:14Z
mmm a / tools / cocos2d - console <nl> ppp b / tools / cocos2d - console <nl> @ @ - 1 + 1 @ @ <nl> - Subproject commit a3738ce6acaa9130dfd6f1d1dc92768bf88cb49a <nl> + Subproject commit a5cea83f3c83b870a8859586834dd05fcec33c12 <nl>
fix cocos package can ' t update ( )
cocos2d/cocos2d-x
5db61ca26f4c65c4c8fe3dfeda0a52ad80755f52
2016-08-24T02:09:42Z
mmm a / unittests / whitelist_blacklist_tests . cppx <nl> ppp b / unittests / whitelist_blacklist_tests . cppx <nl> <nl> * @ file <nl> * @ copyright defined in eos / LICENSE . txt <nl> * / <nl> + # include < eosio / chain / generated_transaction_object . hpp > <nl> # include < eosio / testing / tester . hpp > <nl> # include < eosio / testing / tester_network . hpp > <nl> <nl> - # include < eosio / chain / generated_transaction_object . hpp > <nl> - <nl> # include < fc / variant_object . hpp > <nl> <nl> # include < boost / test / unit_test . hpp > <nl> BOOST_AUTO_TEST_CASE ( actor_blacklist_inline_deferred ) { try { <nl> whitelist_blacklist_tester < tester > tester1 ; <nl> tester1 . init ( ) ; <nl> tester1 . chain - > produce_blocks ( ) ; <nl> - tester1 . chain - > set_code ( N ( alice ) , deferred_test_wast ) ; <nl> - tester1 . chain - > set_abi ( N ( alice ) , deferred_test_abi ) ; <nl> - tester1 . chain - > set_code ( N ( bob ) , deferred_test_wast ) ; <nl> - tester1 . chain - > set_abi ( N ( bob ) , deferred_test_abi ) ; <nl> - tester1 . chain - > set_code ( N ( charlie ) , deferred_test_wast ) ; <nl> - tester1 . chain - > set_abi ( N ( charlie ) , deferred_test_abi ) ; <nl> + tester1 . chain - > set_code ( N ( alice ) , contracts : : deferred_test_wasm ( ) ) ; <nl> + tester1 . chain - > set_abi ( N ( alice ) , contracts : : deferred_test_abi ( ) . data ( ) ) ; <nl> + tester1 . chain - > set_code ( N ( bob ) , contracts : : deferred_test_wasm ( ) ) ; <nl> + tester1 . chain - > set_abi ( N ( bob ) , contracts : : deferred_test_abi ( ) . data ( ) ) ; <nl> + tester1 . chain - > set_code ( N ( charlie ) , contracts : : deferred_test_wasm ( ) ) ; <nl> + tester1 . chain - > set_abi ( N ( charlie ) , contracts : : deferred_test_abi ( ) . data ( ) ) ; <nl> tester1 . chain - > produce_blocks ( ) ; <nl> <nl> auto auth = authority ( eosio : : testing : : base_tester : : get_public_key ( " alice " , " active " ) ) ; <nl> BOOST_AUTO_TEST_CASE ( blacklist_sender_bypass ) { try { <nl> whitelist_blacklist_tester < tester > tester1 ; <nl> tester1 . init ( ) ; <nl> tester1 . chain - > produce_blocks ( ) ; <nl> - tester1 . chain - > set_code ( N ( alice ) , deferred_test_wast ) ; <nl> - tester1 . chain - > set_abi ( N ( alice ) , deferred_test_abi ) ; <nl> - tester1 . chain - > set_code ( N ( bob ) , deferred_test_wast ) ; <nl> - tester1 . chain - > set_abi ( N ( bob ) , deferred_test_abi ) ; <nl> - tester1 . chain - > set_code ( N ( charlie ) , deferred_test_wast ) ; <nl> - tester1 . chain - > set_abi ( N ( charlie ) , deferred_test_abi ) ; <nl> + tester1 . chain - > set_code ( N ( alice ) , contracts : : deferred_test_wasm ( ) ) ; <nl> + tester1 . chain - > set_abi ( N ( alice ) , contracts : : deferred_test_abi ( ) . data ( ) ) ; <nl> + tester1 . chain - > set_code ( N ( bob ) , contracts : : deferred_test_wasm ( ) ) ; <nl> + tester1 . chain - > set_abi ( N ( bob ) , contracts : : deferred_test_abi ( ) . data ( ) ) ; <nl> + tester1 . chain - > set_code ( N ( charlie ) , contracts : : deferred_test_wasm ( ) ) ; <nl> + tester1 . chain - > set_abi ( N ( charlie ) , contracts : : deferred_test_abi ( ) . data ( ) ) ; <nl> tester1 . chain - > produce_blocks ( ) ; <nl> <nl> auto auth = authority ( eosio : : testing : : base_tester : : get_public_key ( " alice " , " active " ) ) ; <nl>
Continuation of fixing conflicts
EOSIO/eos
edf4163c978a58f29d974ed3864c8ca526de06f2
2018-12-06T22:10:57Z
mmm a / lib / IRGen / GenCast . cpp <nl> ppp b / lib / IRGen / GenCast . cpp <nl> llvm : : Value * irgen : : emitClassDowncast ( IRGenFunction & IGF , llvm : : Value * from , <nl> return IGF . Builder . CreateBitCast ( call , subTy ) ; <nl> } <nl> <nl> - static Address <nl> - emitOpaqueDowncast ( IRGenFunction & IGF , <nl> - Address value , <nl> - llvm : : Value * srcMetadata , <nl> - SILType destType , <nl> - CheckedCastMode mode ) { <nl> - llvm : : Value * addr = IGF . Builder . CreateBitCast ( value . getAddress ( ) , <nl> - IGF . IGM . OpaquePtrTy ) ; <nl> - <nl> - srcMetadata = IGF . Builder . CreateBitCast ( srcMetadata , IGF . IGM . Int8PtrTy ) ; <nl> - / / FIXME : We should take the formal destination type . <nl> - llvm : : Value * destMetadata = IGF . emitTypeMetadataRef ( destType . getSwiftRValueType ( ) ) ; <nl> - destMetadata = IGF . Builder . CreateBitCast ( destMetadata , IGF . IGM . Int8PtrTy ) ; <nl> - <nl> - llvm : : Value * castFn ; <nl> - switch ( mode ) { <nl> - case CheckedCastMode : : Unconditional : <nl> - castFn = IGF . IGM . getDynamicCastIndirectUnconditionalFn ( ) ; <nl> - break ; <nl> - case CheckedCastMode : : Conditional : <nl> - castFn = IGF . IGM . getDynamicCastIndirectFn ( ) ; <nl> - break ; <nl> - } <nl> - <nl> - auto * call = IGF . Builder . CreateCall3 ( castFn , addr , srcMetadata , destMetadata ) ; <nl> - / / FIXME : Eventually , we may want to throw . <nl> - call - > setDoesNotThrow ( ) ; <nl> - <nl> - / / Convert the cast address to the destination type . <nl> - auto & destTI = IGF . getTypeInfo ( destType ) ; <nl> - llvm : : Value * ptr = IGF . Builder . CreateBitCast ( call , <nl> - destTI . StorageType - > getPointerTo ( ) ) ; <nl> - return destTI . getAddressForPointer ( ptr ) ; <nl> - } <nl> - <nl> / / / Emit a checked cast of a metatype . <nl> llvm : : Value * irgen : : emitMetatypeDowncast ( IRGenFunction & IGF , <nl> llvm : : Value * metatype , <nl> llvm : : Value * irgen : : emitMetatypeDowncast ( IRGenFunction & IGF , <nl> return call ; <nl> } <nl> <nl> - / / / Emit a checked cast of an opaque archetype . <nl> - Address irgen : : emitOpaqueArchetypeDowncast ( IRGenFunction & IGF , <nl> - Address value , <nl> - SILType srcType , <nl> - SILType destType , <nl> - CheckedCastMode mode ) { <nl> - / / FIXME : We should take the formal source and destination types . <nl> - llvm : : Value * srcMetadata = IGF . emitTypeMetadataRef ( srcType . getSwiftRValueType ( ) ) ; <nl> - return emitOpaqueDowncast ( IGF , value , srcMetadata , destType , mode ) ; <nl> - } <nl> - <nl> - / / / Emit a checked unconditional cast of an opaque existential container ' s <nl> - / / / contained value . <nl> - Address irgen : : emitIndirectExistentialDowncast ( IRGenFunction & IGF , <nl> - Address container , <nl> - SILType srcType , <nl> - SILType destType , <nl> - CheckedCastMode mode ) { <nl> - assert ( srcType . isExistentialType ( ) ) ; <nl> - <nl> - / / Project the value pointer and source type metadata out of the existential <nl> - / / container . <nl> - Address value ; <nl> - llvm : : Value * srcMetadata ; <nl> - std : : tie ( value , srcMetadata ) <nl> - = emitIndirectExistentialProjectionWithMetadata ( IGF , container , srcType , <nl> - CanArchetypeType ( ) ) ; <nl> - <nl> - return emitOpaqueDowncast ( IGF , value , srcMetadata , destType , mode ) ; <nl> - } <nl> - <nl> / / / Emit a Protocol * value referencing an ObjC protocol . <nl> llvm : : Value * irgen : : emitReferenceToObjCProtocol ( IRGenFunction & IGF , <nl> ProtocolDecl * proto ) { <nl> mmm a / lib / IRGen / GenCast . h <nl> ppp b / lib / IRGen / GenCast . h <nl> namespace irgen { <nl> CanAnyMetatypeType toMetatype , <nl> CheckedCastMode mode ) ; <nl> <nl> - / / / Emit a checked cast of an opaque archetype . <nl> - Address emitOpaqueArchetypeDowncast ( IRGenFunction & IGF , <nl> - Address value , <nl> - SILType srcType , <nl> - SILType destType , <nl> - CheckedCastMode mode ) ; <nl> - <nl> - / / / Emit a checked cast of an existential container ' s <nl> - / / / contained value . <nl> - Address emitIndirectExistentialDowncast ( IRGenFunction & IGF , <nl> - Address value , <nl> - SILType srcType , <nl> - SILType destType , <nl> - CheckedCastMode mode ) ; <nl> - <nl> / / / Emit a checked cast to an Objective - C protocol or protocol composition . <nl> llvm : : Value * emitObjCExistentialDowncast ( IRGenFunction & IGF , <nl> llvm : : Value * orig , <nl>
IRGen : Remove more obsolete casting entry points .
apple/swift
2047cec286a5b8513af3e2ff1b991fb089233486
2014-11-06T22:09:48Z
mmm a / scripts / nightly_test <nl> ppp b / scripts / nightly_test <nl> <nl> BREAKOUT_FILE_NAME = ~ / nightly_test_running <nl> DESCRIBE_FILE_NAME = last_test_describe <nl> <nl> + if [ " $ 1 " = " - - force " ] ; then <nl> + rm " $ DESCRIBE_FILE_NAME " <nl> + fi <nl> + <nl> # Don ' t start the test if it ' s running already <nl> if [ - f $ BREAKOUT_FILE_NAME ] <nl> then <nl> + echo " Test already running . " <nl> exit <nl> fi <nl> <nl> touch $ BREAKOUT_FILE_NAME <nl> export PATH = $ PATH : / usr / local / bin / <nl> <nl> # Go into var rethinkdb directory <nl> - cd / var / git / rethinkdb / <nl> + # cd / var / git / rethinkdb / <nl> <nl> # Pull latest from master <nl> git pull <nl> last_test_describe = ` cat $ DESCRIBE_FILE_NAME ` <nl> this_test_describe = ` git describe ` <nl> <nl> if [ " $ last_test_describe " = " $ this_test_describe " ] ; then <nl> - echo " Nothing changed since last test " <nl> + echo " Nothing changed since last test use - - force to test anyway " <nl> else <nl> # Cloud retester configuration <nl> export USE_CLOUD = true <nl>
Make nightly test a bit nicer .
rethinkdb/rethinkdb
fe2bafd069ad57fecd99f748e800e68949b7de26
2011-01-12T20:47:08Z
mmm a / x64_dbg_gui / Project / Src / BasicView / ReferenceView . cpp <nl> ppp b / x64_dbg_gui / Project / Src / BasicView / ReferenceView . cpp <nl> void ReferenceView : : setupContextMenu ( ) <nl> <nl> void ReferenceView : : refreshShortcutsSlot ( ) <nl> { <nl> - mToggleBreakpoint - > setShortcut ( QKeySequence ( " F2 " ) ) ; <nl> - mToggleBookmark - > setShortcut ( QKeySequence ( " ctrl + d " ) ) ; <nl> + mToggleBreakpoint - > setShortcut ( ConfigShortcut ( " ActionToggleBreakpoint " ) ) ; <nl> + mToggleBookmark - > setShortcut ( ConfigShortcut ( " ActionToggleBookmark " ) ) ; <nl> } <nl> <nl> void ReferenceView : : addColumnAt ( int width , QString title ) <nl> mmm a / x64_dbg_gui / Project / Src / Gui / BreakpointsView . cpp <nl> ppp b / x64_dbg_gui / Project / Src / Gui / BreakpointsView . cpp <nl> void BreakpointsView : : setupHardBPRightClickContextMenu ( ) <nl> <nl> void BreakpointsView : : refreshShortcutsSlot ( ) <nl> { <nl> - mHardBPRemoveAction - > setShortcut ( QKeySequence ( Qt : : Key_Delete ) ) ; <nl> - mHardBPEnableDisableAction - > setShortcut ( QKeySequence ( Qt : : Key_Space ) ) ; <nl> + mHardBPRemoveAction - > setShortcut ( ConfigShortcut ( " ActionDeleteBreakpoint " ) ) ; <nl> + mHardBPEnableDisableAction - > setShortcut ( ConfigShortcut ( " ActionEnableDisableBreakpoint " ) ) ; <nl> <nl> - mSoftBPRemoveAction - > setShortcut ( QKeySequence ( Qt : : Key_Delete ) ) ; <nl> - mSoftBPEnableDisableAction - > setShortcut ( QKeySequence ( Qt : : Key_Space ) ) ; <nl> + mSoftBPRemoveAction - > setShortcut ( ConfigShortcut ( " ActionDeleteBreakpoint " ) ) ; <nl> + mSoftBPEnableDisableAction - > setShortcut ( ConfigShortcut ( " ActionEnableDisableBreakpoint " ) ) ; <nl> <nl> - mMemBPRemoveAction - > setShortcut ( QKeySequence ( Qt : : Key_Delete ) ) ; <nl> - mMemBPEnableDisableAction - > setShortcut ( QKeySequence ( Qt : : Key_Space ) ) ; <nl> + mMemBPRemoveAction - > setShortcut ( ConfigShortcut ( " ActionDeleteBreakpoint " ) ) ; <nl> + mMemBPEnableDisableAction - > setShortcut ( ConfigShortcut ( " ActionEnableDisableBreakpoint " ) ) ; <nl> } <nl> <nl> void BreakpointsView : : hardwareBPContextMenuSlot ( const QPoint & pos ) <nl> mmm a / x64_dbg_gui / Project / Src / Gui / CPUDisassembly . cpp <nl> ppp b / x64_dbg_gui / Project / Src / Gui / CPUDisassembly . cpp <nl> void CPUDisassembly : : setupRightClickContextMenu ( ) <nl> <nl> void CPUDisassembly : : refreshShortcutsSlot ( ) <nl> { <nl> - mBinaryEditAction - > setShortcut ( QKeySequence ( " ctrl + e " ) ) ; <nl> - mBinaryFillAction - > setShortcut ( QKeySequence ( " f " ) ) ; <nl> - mBinaryFillNopsAction - > setShortcut ( QKeySequence ( " ctrl + 9 " ) ) ; <nl> - mBinaryCopyAction - > setShortcut ( QKeySequence ( " shift + c " ) ) ; <nl> - mBinaryPasteAction - > setShortcut ( QKeySequence ( " shift + v " ) ) ; <nl> - mBinaryPasteIgnoreSizeAction - > setShortcut ( QKeySequence ( " ctrl + shift + v " ) ) ; <nl> - mUndoSelection - > setShortcut ( QKeySequence ( " ctrl + backspace " ) ) ; <nl> - mSetLabel - > setShortcut ( QKeySequence ( " : " ) ) ; <nl> - mSetComment - > setShortcut ( QKeySequence ( " ; " ) ) ; <nl> - mSetBookmark - > setShortcut ( QKeySequence ( " ctrl + d " ) ) ; <nl> - mToggleFunction - > setShortcut ( QKeySequence ( " shift + f " ) ) ; <nl> - mAssemble - > setShortcut ( QKeySequence ( " space " ) ) ; <nl> - mToggleInt3BpAction - > setShortcut ( QKeySequence ( Qt : : Key_F2 ) ) ; <nl> - mPatchesAction - > setShortcut ( QKeySequence ( " ctrl + p " ) ) ; <nl> - mSetNewOriginHere - > setShortcut ( QKeySequence ( " ctrl + * " ) ) ; <nl> - mGotoOrigin - > setShortcut ( QKeySequence ( " * " ) ) ; <nl> - mGotoPrevious - > setShortcut ( QKeySequence ( " - " ) ) ; <nl> - mGotoNext - > setShortcut ( QKeySequence ( " + " ) ) ; <nl> - mGotoExpression - > setShortcut ( QKeySequence ( " ctrl + g " ) ) ; <nl> - mReferenceSelectedAddress - > setShortcut ( QKeySequence ( " ctrl + r " ) ) ; <nl> - mSearchPattern - > setShortcut ( QKeySequence ( " ctrl + b " ) ) ; <nl> - mEnableHighlightingMode - > setShortcut ( QKeySequence ( " ctrl + h " ) ) ; <nl> + mBinaryEditAction - > setShortcut ( ConfigShortcut ( " ActionBinaryEdit " ) ) ; <nl> + mBinaryFillAction - > setShortcut ( ConfigShortcut ( " ActionBinaryFill " ) ) ; <nl> + mBinaryFillNopsAction - > setShortcut ( ConfigShortcut ( " ActionBinaryFillNops " ) ) ; <nl> + mBinaryCopyAction - > setShortcut ( ConfigShortcut ( " ActionBinaryCopy " ) ) ; <nl> + mBinaryPasteAction - > setShortcut ( ConfigShortcut ( " ActionBinaryPaste " ) ) ; <nl> + mBinaryPasteIgnoreSizeAction - > setShortcut ( ConfigShortcut ( " ActionBinaryPasteIgnoreSize " ) ) ; <nl> + mUndoSelection - > setShortcut ( ConfigShortcut ( " ActionUndoSelection " ) ) ; <nl> + mSetLabel - > setShortcut ( ConfigShortcut ( " ActionSetLabel " ) ) ; <nl> + mSetComment - > setShortcut ( ConfigShortcut ( " ActionSetComment " ) ) ; <nl> + mSetBookmark - > setShortcut ( ConfigShortcut ( " ActionToggleBookmark " ) ) ; <nl> + mToggleFunction - > setShortcut ( ConfigShortcut ( " ActionToggleFunction " ) ) ; <nl> + mAssemble - > setShortcut ( ConfigShortcut ( " ActionAssemble " ) ) ; <nl> + mToggleInt3BpAction - > setShortcut ( ConfigShortcut ( " ActionToggleBreakpoint " ) ) ; <nl> + mPatchesAction - > setShortcut ( ConfigShortcut ( " ViewPatches " ) ) ; <nl> + mSetNewOriginHere - > setShortcut ( ConfigShortcut ( " ActionSetNewOriginHere " ) ) ; <nl> + mGotoOrigin - > setShortcut ( ConfigShortcut ( " ActionGotoOrigin " ) ) ; <nl> + mGotoPrevious - > setShortcut ( ConfigShortcut ( " ActionGotoPrevious " ) ) ; <nl> + mGotoNext - > setShortcut ( ConfigShortcut ( " ActionGotoNext " ) ) ; <nl> + mGotoExpression - > setShortcut ( ConfigShortcut ( " ActionGotoExpression " ) ) ; <nl> + mReferenceSelectedAddress - > setShortcut ( ConfigShortcut ( " ActionFindReferencesToSelectedAddress " ) ) ; <nl> + mSearchPattern - > setShortcut ( ConfigShortcut ( " ActionFindPattern " ) ) ; <nl> + mEnableHighlightingMode - > setShortcut ( ConfigShortcut ( " ActionHighlightingMode " ) ) ; <nl> } <nl> <nl> void CPUDisassembly : : gotoOrigin ( ) <nl> mmm a / x64_dbg_gui / Project / Src / Gui / CPUDump . cpp <nl> ppp b / x64_dbg_gui / Project / Src / Gui / CPUDump . cpp <nl> void CPUDump : : setupContextMenu ( ) <nl> <nl> void CPUDump : : refreshShortcutsSlot ( ) <nl> { <nl> - mBinaryEditAction - > setShortcut ( QKeySequence ( " ctrl + e " ) ) ; <nl> - mBinaryFillAction - > setShortcut ( QKeySequence ( " f " ) ) ; <nl> - mBinaryCopyAction - > setShortcut ( QKeySequence ( " shift + c " ) ) ; <nl> - mBinaryPasteAction - > setShortcut ( QKeySequence ( " shift + v " ) ) ; <nl> - mBinaryPasteIgnoreSizeAction - > setShortcut ( QKeySequence ( " ctrl + shift + v " ) ) ; <nl> - mUndoSelection - > setShortcut ( QKeySequence ( " ctrl + backspace " ) ) ; <nl> - mSetLabelAction - > setShortcut ( QKeySequence ( " : " ) ) ; <nl> - mFindPatternAction - > setShortcut ( QKeySequence ( " ctrl + b " ) ) ; <nl> - mGotoExpression - > setShortcut ( QKeySequence ( " ctrl + g " ) ) ; <nl> + mBinaryEditAction - > setShortcut ( ConfigShortcut ( " ActionBinaryEdit " ) ) ; <nl> + mBinaryFillAction - > setShortcut ( ConfigShortcut ( " ActionBinaryFill " ) ) ; <nl> + mBinaryCopyAction - > setShortcut ( ConfigShortcut ( " ActionBinaryCopy " ) ) ; <nl> + mBinaryPasteAction - > setShortcut ( ConfigShortcut ( " ActionBinaryPaste " ) ) ; <nl> + mBinaryPasteIgnoreSizeAction - > setShortcut ( ConfigShortcut ( " ActionBinaryPasteIgnoreSize " ) ) ; <nl> + mUndoSelection - > setShortcut ( ConfigShortcut ( " ActionUndoSelection " ) ) ; <nl> + mSetLabelAction - > setShortcut ( ConfigShortcut ( " ActionSetLabel " ) ) ; <nl> + mFindPatternAction - > setShortcut ( ConfigShortcut ( " ActionFindPattern " ) ) ; <nl> + mGotoExpression - > setShortcut ( ConfigShortcut ( " ActionGotoExpression " ) ) ; <nl> } <nl> <nl> QString CPUDump : : paintContent ( QPainter * painter , int_t rowBase , int rowOffset , int col , int x , int y , int w , int h ) <nl> mmm a / x64_dbg_gui / Project / Src / Gui / CPUStack . cpp <nl> ppp b / x64_dbg_gui / Project / Src / Gui / CPUStack . cpp <nl> void CPUStack : : setupContextMenu ( ) <nl> <nl> void CPUStack : : refreshShortcutsSlot ( ) <nl> { <nl> - mBinaryEditAction - > setShortcut ( QKeySequence ( " ctrl + e " ) ) ; <nl> - mBinaryFillAction - > setShortcut ( QKeySequence ( " f " ) ) ; <nl> - mBinaryCopyAction - > setShortcut ( QKeySequence ( " shift + c " ) ) ; <nl> - mBinaryPasteAction - > setShortcut ( QKeySequence ( " shift + v " ) ) ; <nl> - mBinaryPasteIgnoreSizeAction - > setShortcut ( QKeySequence ( " ctrl + shift + v " ) ) ; <nl> - mUndoSelection - > setShortcut ( QKeySequence ( " ctrl + backspace " ) ) ; <nl> - mGotoSp - > setShortcut ( QKeySequence ( " * " ) ) ; <nl> - mFindPatternAction - > setShortcut ( QKeySequence ( " ctrl + b " ) ) ; <nl> - mGotoExpression - > setShortcut ( QKeySequence ( " ctrl + g " ) ) ; <nl> + mBinaryEditAction - > setShortcut ( ConfigShortcut ( " ActionBinaryEdit " ) ) ; <nl> + mBinaryFillAction - > setShortcut ( ConfigShortcut ( " ActionBinaryFill " ) ) ; <nl> + mBinaryCopyAction - > setShortcut ( ConfigShortcut ( " ActionBinaryCopy " ) ) ; <nl> + mBinaryPasteAction - > setShortcut ( ConfigShortcut ( " ActionBinaryPaste " ) ) ; <nl> + mBinaryPasteIgnoreSizeAction - > setShortcut ( ConfigShortcut ( " ActionBinaryPasteIgnoreSize " ) ) ; <nl> + mUndoSelection - > setShortcut ( ConfigShortcut ( " ActionUndoSelection " ) ) ; <nl> + mGotoSp - > setShortcut ( ConfigShortcut ( " ActionGotoOrigin " ) ) ; <nl> + mFindPatternAction - > setShortcut ( ConfigShortcut ( " ActionFindPattern " ) ) ; <nl> + mGotoExpression - > setShortcut ( ConfigShortcut ( " ActionGotoExpression " ) ) ; <nl> } <nl> <nl> QString CPUStack : : paintContent ( QPainter * painter , int_t rowBase , int rowOffset , int col , int x , int y , int w , int h ) <nl> mmm a / x64_dbg_gui / Project / Src / Gui / MemoryMapView . cpp <nl> ppp b / x64_dbg_gui / Project / Src / Gui / MemoryMapView . cpp <nl> void MemoryMapView : : setupContextMenu ( ) <nl> <nl> void MemoryMapView : : refreshShortcutsSlot ( ) <nl> { <nl> - mMemoryExecuteSingleshoot - > setShortcut ( QKeySequence ( " f2 " ) ) ; <nl> - mMemoryRemove - > setShortcut ( QKeySequence ( " f2 " ) ) ; <nl> - mMemoryExecuteSingleshootToggle - > setShortcut ( QKeySequence ( " f2 " ) ) ; <nl> + mMemoryExecuteSingleshoot - > setShortcut ( ConfigShortcut ( " ActionToggleBreakpoint " ) ) ; <nl> + mMemoryRemove - > setShortcut ( ConfigShortcut ( " ActionToggleBreakpoint " ) ) ; <nl> + mMemoryExecuteSingleshootToggle - > setShortcut ( ConfigShortcut ( " ActionToggleBreakpoint " ) ) ; <nl> } <nl> <nl> void MemoryMapView : : contextMenuSlot ( const QPoint & pos ) <nl> mmm a / x64_dbg_gui / Project / Src / Gui / RegistersView . cpp <nl> ppp b / x64_dbg_gui / Project / Src / Gui / RegistersView . cpp <nl> RegistersView : : RegistersView ( QWidget * parent ) : QAbstractScrollArea ( parent ) , mV <nl> <nl> void RegistersView : : refreshShortcutsSlot ( ) <nl> { <nl> - wCM_Increment - > setShortcut ( QKeySequence ( Qt : : Key_Plus ) ) ; <nl> - wCM_Decrement - > setShortcut ( QKeySequence ( Qt : : Key_Minus ) ) ; <nl> - wCM_Zero - > setShortcut ( QKeySequence ( Qt : : Key_0 ) ) ; <nl> - wCM_SetToOne - > setShortcut ( QKeySequence ( Qt : : Key_1 ) ) ; <nl> - wCM_ToggleValue - > setShortcut ( QKeySequence ( Qt : : Key_Space ) ) ; <nl> - wCM_CopyToClipboard - > setShortcut ( QKeySequence : : Copy ) ; <nl> + wCM_Increment - > setShortcut ( ConfigShortcut ( " ActionIncreaseRegister " ) ) ; <nl> + wCM_Decrement - > setShortcut ( ConfigShortcut ( " ActionDecreaseRegister " ) ) ; <nl> + wCM_Zero - > setShortcut ( ConfigShortcut ( " ActionZeroRegister " ) ) ; <nl> + wCM_SetToOne - > setShortcut ( ConfigShortcut ( " ActionSetOneRegister " ) ) ; <nl> + wCM_ToggleValue - > setShortcut ( ConfigShortcut ( " ActionToggleRegisterValue " ) ) ; <nl> + wCM_CopyToClipboard - > setShortcut ( ConfigShortcut ( " ActionCopy " ) ) ; <nl> } <nl> <nl> RegistersView : : ~ RegistersView ( ) <nl> mmm a / x64_dbg_gui / Project / Src / Gui / ScriptView . cpp <nl> ppp b / x64_dbg_gui / Project / Src / Gui / ScriptView . cpp <nl> void ScriptView : : setupContextMenu ( ) <nl> <nl> void ScriptView : : refreshShortcutsSlot ( ) <nl> { <nl> - mScriptLoad - > setShortcut ( QKeySequence ( " ctrl + o " ) ) ; <nl> - mScriptUnload - > setShortcut ( QKeySequence ( " ctrl + u " ) ) ; <nl> - mScriptRun - > setShortcut ( QKeySequence ( " space " ) ) ; <nl> - mScriptBpToggle - > setShortcut ( QKeySequence ( " F2 " ) ) ; <nl> - mScriptRunCursor - > setShortcut ( QKeySequence ( " F4 " ) ) ; <nl> - mScriptStep - > setShortcut ( QKeySequence ( " tab " ) ) ; <nl> - mScriptAbort - > setShortcut ( QKeySequence ( " esc " ) ) ; <nl> - mScriptCmdExec - > setShortcut ( QKeySequence ( " x " ) ) ; <nl> + mScriptLoad - > setShortcut ( ConfigShortcut ( " ActionLoadScript " ) ) ; <nl> + mScriptUnload - > setShortcut ( ConfigShortcut ( " ActionUnloadScript " ) ) ; <nl> + mScriptRun - > setShortcut ( ConfigShortcut ( " ActionRunScript " ) ) ; <nl> + mScriptBpToggle - > setShortcut ( ConfigShortcut ( " ActionToggleBreakpointScript " ) ) ; <nl> + mScriptRunCursor - > setShortcut ( ConfigShortcut ( " ActionRunToCursorScript " ) ) ; <nl> + mScriptStep - > setShortcut ( ConfigShortcut ( " ActionStepScript " ) ) ; <nl> + mScriptAbort - > setShortcut ( ConfigShortcut ( " ActionAbortScript " ) ) ; <nl> + mScriptCmdExec - > setShortcut ( ConfigShortcut ( " ActionExecuteCommandScript " ) ) ; <nl> } <nl> <nl> bool ScriptView : : isScriptCommand ( QString text , QString cmd ) <nl> mmm a / x64_dbg_gui / Project / Src / Gui / ShortcutsDialog . cpp <nl> ppp b / x64_dbg_gui / Project / Src / Gui / ShortcutsDialog . cpp <nl> ShortcutsDialog : : ShortcutsDialog ( QWidget * parent ) : QDialog ( parent ) , ui ( new Ui : : <nl> / / x64 has no model - view - controler pattern <nl> QStringList tblHeader ; <nl> tblHeader < < " Instruction " < < " Shortcut " ; <nl> - QTableWidget * tbl = ui - > tblShortcuts ; <nl> - tbl - > setColumnCount ( 2 ) ; <nl> - tbl - > verticalHeader ( ) - > setVisible ( false ) ; <nl> - tbl - > setHorizontalHeaderLabels ( tblHeader ) ; <nl> - tbl - > setEditTriggers ( QAbstractItemView : : NoEditTriggers ) ; <nl> - tbl - > setSelectionBehavior ( QAbstractItemView : : SelectRows ) ; <nl> - tbl - > setSelectionMode ( QAbstractItemView : : SingleSelection ) ; <nl> - tbl - > setShowGrid ( false ) ; <nl> - tbl - > horizontalHeader ( ) - > setResizeMode ( 0 , QHeaderView : : Stretch ) ; <nl> - tbl - > verticalHeader ( ) - > setDefaultSectionSize ( 15 ) ; <nl> + <nl> + ui - > tblShortcuts - > setColumnCount ( 2 ) ; <nl> + ui - > tblShortcuts - > verticalHeader ( ) - > setVisible ( false ) ; <nl> + ui - > tblShortcuts - > setHorizontalHeaderLabels ( tblHeader ) ; <nl> + ui - > tblShortcuts - > setEditTriggers ( QAbstractItemView : : NoEditTriggers ) ; <nl> + ui - > tblShortcuts - > setSelectionBehavior ( QAbstractItemView : : SelectRows ) ; <nl> + ui - > tblShortcuts - > setSelectionMode ( QAbstractItemView : : SingleSelection ) ; <nl> + ui - > tblShortcuts - > setShowGrid ( false ) ; <nl> + ui - > tblShortcuts - > horizontalHeader ( ) - > setResizeMode ( 0 , QHeaderView : : Stretch ) ; <nl> + ui - > tblShortcuts - > verticalHeader ( ) - > setDefaultSectionSize ( 15 ) ; <nl> <nl> const unsigned int numShortcuts = Config ( ) - > Shortcuts . count ( ) ; <nl> - tbl - > setRowCount ( numShortcuts ) ; <nl> + ui - > tblShortcuts - > setRowCount ( numShortcuts ) ; <nl> int j = 0 ; <nl> for ( QMap < QString , Configuration : : Shortcut > : : iterator i = Config ( ) - > Shortcuts . begin ( ) ; i ! = Config ( ) - > Shortcuts . end ( ) ; + + i , j + + ) <nl> { <nl> QTableWidgetItem * shortcutName = new QTableWidgetItem ( i . value ( ) . Name ) ; <nl> QTableWidgetItem * shortcutKey = new QTableWidgetItem ( i . value ( ) . Hotkey . toString ( QKeySequence : : NativeText ) ) ; <nl> - tbl - > setItem ( j , 0 , shortcutName ) ; <nl> - tbl - > setItem ( j , 1 , shortcutKey ) ; <nl> + ui - > tblShortcuts - > setItem ( j , 0 , shortcutName ) ; <nl> + ui - > tblShortcuts - > setItem ( j , 1 , shortcutKey ) ; <nl> } <nl> <nl> connect ( ui - > tblShortcuts , SIGNAL ( itemSelectionChanged ( ) ) , this , SLOT ( syncTextfield ( ) ) ) ; <nl> void ShortcutsDialog : : updateShortcut ( ) <nl> if ( newKey ! = currentShortcut . Hotkey ) <nl> { <nl> bool good = true ; <nl> - foreach ( Configuration : : Shortcut S , Config ( ) - > Shortcuts ) <nl> + if ( ! newKey . isEmpty ( ) ) <nl> { <nl> - if ( ! newKey . isEmpty ( ) & & S . Hotkey = = newKey & & S . Name ! = currentShortcut . Name ) <nl> + int idx = 0 ; <nl> + for ( QMap < QString , Configuration : : Shortcut > : : iterator i = Config ( ) - > Shortcuts . begin ( ) ; i ! = Config ( ) - > Shortcuts . end ( ) ; + + i , idx + + ) <nl> { <nl> - good = false ; <nl> - break ; <nl> + if ( i . value ( ) . Name = = currentShortcut . Name ) / / skip current shortcut in list <nl> + continue ; <nl> + if ( i . value ( ) . GlobalShortcut & & i . value ( ) . Hotkey = = newKey ) / / newkey is trying to override a global shortcut <nl> + { <nl> + good = false ; <nl> + break ; <nl> + } <nl> + else if ( currentShortcut . GlobalShortcut & & i . value ( ) . Hotkey = = newKey ) / / current shortcut is global and overrides another local hotkey <nl> + { <nl> + ui - > tblShortcuts - > setItem ( idx , 1 , new QTableWidgetItem ( " " ) ) ; <nl> + Config ( ) - > setShortcut ( i . key ( ) , QKeySequence ( ) ) ; <nl> + } <nl> } <nl> } <nl> if ( good ) <nl> ShortcutsDialog : : ~ ShortcutsDialog ( ) <nl> <nl> void ShortcutsDialog : : on_btnSave_clicked ( ) <nl> { <nl> - Config ( ) - > save ( ) ; <nl> - QMessageBox msg ( QMessageBox : : Information , " Information " , " Shortcuts updated ! \ n \ nYou may need to restart the debugger for all changes to take in effect . " ) ; <nl> + Config ( ) - > writeShortcuts ( ) ; <nl> + QMessageBox msg ( QMessageBox : : Information , " Information " , " Shortcuts updated ! " ) ; <nl> msg . setWindowIcon ( QIcon ( " : / icons / images / information . png " ) ) ; <nl> msg . setParent ( this , Qt : : Dialog ) ; <nl> msg . setWindowFlags ( msg . windowFlags ( ) & ( ~ Qt : : WindowContextHelpButtonHint ) ) ; <nl> mmm a / x64_dbg_gui / Project / Src / Gui / ShortcutsDialog . h <nl> ppp b / x64_dbg_gui / Project / Src / Gui / ShortcutsDialog . h <nl> class ShortcutsDialog ; <nl> class ShortcutsDialog : public QDialog <nl> { <nl> Q_OBJECT <nl> - QTableWidget * tbl ; <nl> Configuration : : Shortcut currentShortcut ; <nl> int currentRow ; <nl> bool editLock ; <nl> mmm a / x64_dbg_gui / Project / Src / Utils / Configuration . cpp <nl> ppp b / x64_dbg_gui / Project / Src / Utils / Configuration . cpp <nl> Configuration : : Configuration ( ) : QObject ( ) <nl> defaultFonts . insert ( " Application " , QApplication : : font ( ) ) ; <nl> <nl> / / hotkeys settings <nl> - defaultShortcuts . insert ( " FileOpen " , Shortcut ( tr ( " File - > Open " ) , " F3 " ) ) ; <nl> - defaultShortcuts . insert ( " FileExit " , Shortcut ( tr ( " File - > Exit " ) , " Alt + X " ) ) ; <nl> - <nl> - defaultShortcuts . insert ( " ViewCpu " , Shortcut ( tr ( " View - > CPU " ) , " Alt + C " ) ) ; <nl> - defaultShortcuts . insert ( " ViewLog " , Shortcut ( tr ( " View - > Log " ) , " Alt + L " ) ) ; <nl> - defaultShortcuts . insert ( " ViewBreakpoints " , Shortcut ( tr ( " View - > Breakpoints " ) , " Alt + B " ) ) ; <nl> - defaultShortcuts . insert ( " ViewMemoryMap " , Shortcut ( tr ( " View - > Memory Map " ) , " Alt + M " ) ) ; <nl> - defaultShortcuts . insert ( " ViewCallStack " , Shortcut ( tr ( " View - > Call Stack " ) , " Alt + K " ) ) ; <nl> - defaultShortcuts . insert ( " ViewScript " , Shortcut ( tr ( " View - > Script " ) , " Alt + S " ) ) ; <nl> - defaultShortcuts . insert ( " ViewSymbolInfo " , Shortcut ( tr ( " View - > Symbol Info " ) , " Ctrl + Alt + S " ) ) ; <nl> - defaultShortcuts . insert ( " ViewReferences " , Shortcut ( tr ( " View - > References " ) , " Alt + R " ) ) ; <nl> - defaultShortcuts . insert ( " ViewThreads " , Shortcut ( tr ( " View - > Threads " ) , " Alt + T " ) ) ; <nl> - defaultShortcuts . insert ( " ViewPatches " , Shortcut ( tr ( " View - > Patches " ) , " Ctrl + P " ) ) ; <nl> - defaultShortcuts . insert ( " ViewComments " , Shortcut ( tr ( " View - > Comments " ) , " Ctrl + Alt + C " ) ) ; <nl> - defaultShortcuts . insert ( " ViewLabels " , Shortcut ( tr ( " View - > Labels " ) , " Ctrl + Alt + L " ) ) ; <nl> - defaultShortcuts . insert ( " ViewBookmarks " , Shortcut ( tr ( " View - > Bookmarks " ) , " Ctrl + Alt + B " ) ) ; <nl> - defaultShortcuts . insert ( " ViewFunctions " , Shortcut ( tr ( " View - > Functions " ) , " Alt + F " ) ) ; <nl> - <nl> - defaultShortcuts . insert ( " DebugRun " , Shortcut ( tr ( " Debug - > Run " ) , " F9 " ) ) ; <nl> - defaultShortcuts . insert ( " DebugeRun " , Shortcut ( tr ( " Debug - > Run ( skip exceptions ) " ) , " Shift + F9 " ) ) ; <nl> - defaultShortcuts . insert ( " DebugRunSelection " , Shortcut ( tr ( " Debug - > Run until selection " ) , " F4 " ) ) ; <nl> - defaultShortcuts . insert ( " DebugPause " , Shortcut ( tr ( " Debug - > Pause " ) , " F12 " ) ) ; <nl> - defaultShortcuts . insert ( " DebugRestart " , Shortcut ( tr ( " Debug - > Restart " ) , " Ctrl + F2 " ) ) ; <nl> - defaultShortcuts . insert ( " DebugClose " , Shortcut ( tr ( " Debug - > Close " ) , " Alt + F2 " ) ) ; <nl> - defaultShortcuts . insert ( " DebugStepInto " , Shortcut ( tr ( " Debug - > Step into " ) , " F7 " ) ) ; <nl> - defaultShortcuts . insert ( " DebugeStepInfo " , Shortcut ( tr ( " Debug - > Step into ( skip execptions ) " ) , " Shift + F7 " ) ) ; <nl> - defaultShortcuts . insert ( " DebugStepOver " , Shortcut ( tr ( " Debug - > Step over " ) , " F8 " ) ) ; <nl> - defaultShortcuts . insert ( " DebugeStepOver " , Shortcut ( tr ( " Debug - > Step over ( skip execptions ) " ) , " Shift + F8 " ) ) ; <nl> - defaultShortcuts . insert ( " DebugRtr " , Shortcut ( tr ( " Debug - > Execute till return " ) , " Ctrl + F9 " ) ) ; <nl> - defaultShortcuts . insert ( " DebugeRtr " , Shortcut ( tr ( " Debug - > execute till return ( skip exceptions ) " ) , " Ctrl + Shift + F9 " ) ) ; <nl> - defaultShortcuts . insert ( " DebugCommand " , Shortcut ( tr ( " Debug - > Command " ) , " Ctrl + Return " ) ) ; <nl> - <nl> - defaultShortcuts . insert ( " PluginsScylla " , Shortcut ( tr ( " Plugins - > Scylla " ) , " Ctrl + I " ) ) ; <nl> - <nl> - defaultShortcuts . insert ( " OptionsPreferences " , Shortcut ( tr ( " Options - > Preferences " ) ) ) ; <nl> - defaultShortcuts . insert ( " OptionsAppearance " , Shortcut ( tr ( " Options - > Preferences " ) ) ) ; <nl> - defaultShortcuts . insert ( " OptionsShortcuts " , Shortcut ( tr ( " Options - > Preferences " ) ) ) ; <nl> - <nl> - defaultShortcuts . insert ( " HelpAbout " , Shortcut ( tr ( " Help - > About " ) ) ) ; <nl> - defaultShortcuts . insert ( " HelpDonate " , Shortcut ( tr ( " Help - > Donate " ) ) ) ; <nl> - defaultShortcuts . insert ( " HelpCheckForUpdates " , Shortcut ( tr ( " Help - > Check for Updates " ) ) ) ; <nl> - <nl> - defaultShortcuts . insert ( " ActionFindStrings " , Shortcut ( tr ( " Actions - > Find Strings " ) ) ) ; <nl> - defaultShortcuts . insert ( " ActionFindIntermodularCalls " , Shortcut ( tr ( " Actions - > Find Intermodular Calls " ) ) ) ; <nl> + defaultShortcuts . insert ( " FileOpen " , Shortcut ( tr ( " File - > Open " ) , " F3 " , true ) ) ; <nl> + defaultShortcuts . insert ( " FileExit " , Shortcut ( tr ( " File - > Exit " ) , " Alt + X " , true ) ) ; <nl> + <nl> + defaultShortcuts . insert ( " ViewCpu " , Shortcut ( tr ( " View - > CPU " ) , " Alt + C " , true ) ) ; <nl> + defaultShortcuts . insert ( " ViewLog " , Shortcut ( tr ( " View - > Log " ) , " Alt + L " , true ) ) ; <nl> + defaultShortcuts . insert ( " ViewBreakpoints " , Shortcut ( tr ( " View - > Breakpoints " ) , " Alt + B " , true ) ) ; <nl> + defaultShortcuts . insert ( " ViewMemoryMap " , Shortcut ( tr ( " View - > Memory Map " ) , " Alt + M " , true ) ) ; <nl> + defaultShortcuts . insert ( " ViewCallStack " , Shortcut ( tr ( " View - > Call Stack " ) , " Alt + K " , true ) ) ; <nl> + defaultShortcuts . insert ( " ViewScript " , Shortcut ( tr ( " View - > Script " ) , " Alt + S " , true ) ) ; <nl> + defaultShortcuts . insert ( " ViewSymbolInfo " , Shortcut ( tr ( " View - > Symbol Info " ) , " Ctrl + Alt + S " , true ) ) ; <nl> + defaultShortcuts . insert ( " ViewReferences " , Shortcut ( tr ( " View - > References " ) , " Alt + R " , true ) ) ; <nl> + defaultShortcuts . insert ( " ViewThreads " , Shortcut ( tr ( " View - > Threads " ) , " Alt + T " , true ) ) ; <nl> + defaultShortcuts . insert ( " ViewPatches " , Shortcut ( tr ( " View - > Patches " ) , " Ctrl + P " , true ) ) ; <nl> + defaultShortcuts . insert ( " ViewComments " , Shortcut ( tr ( " View - > Comments " ) , " Ctrl + Alt + C " , true ) ) ; <nl> + defaultShortcuts . insert ( " ViewLabels " , Shortcut ( tr ( " View - > Labels " ) , " Ctrl + Alt + L " , true ) ) ; <nl> + defaultShortcuts . insert ( " ViewBookmarks " , Shortcut ( tr ( " View - > Bookmarks " ) , " Ctrl + Alt + B " , true ) ) ; <nl> + defaultShortcuts . insert ( " ViewFunctions " , Shortcut ( tr ( " View - > Functions " ) , " Alt + F " , true ) ) ; <nl> + <nl> + defaultShortcuts . insert ( " DebugRun " , Shortcut ( tr ( " Debug - > Run " ) , " F9 " , true ) ) ; <nl> + defaultShortcuts . insert ( " DebugeRun " , Shortcut ( tr ( " Debug - > Run ( skip exceptions ) " ) , " Shift + F9 " , true ) ) ; <nl> + defaultShortcuts . insert ( " DebugRunSelection " , Shortcut ( tr ( " Debug - > Run until selection " ) , " F4 " , true ) ) ; <nl> + defaultShortcuts . insert ( " DebugPause " , Shortcut ( tr ( " Debug - > Pause " ) , " F12 " , true ) ) ; <nl> + defaultShortcuts . insert ( " DebugRestart " , Shortcut ( tr ( " Debug - > Restart " ) , " Ctrl + F2 " , true ) ) ; <nl> + defaultShortcuts . insert ( " DebugClose " , Shortcut ( tr ( " Debug - > Close " ) , " Alt + F2 " , true ) ) ; <nl> + defaultShortcuts . insert ( " DebugStepInto " , Shortcut ( tr ( " Debug - > Step into " ) , " F7 " , true ) ) ; <nl> + defaultShortcuts . insert ( " DebugeStepInfo " , Shortcut ( tr ( " Debug - > Step into ( skip execptions ) " ) , " Shift + F7 " , true ) ) ; <nl> + defaultShortcuts . insert ( " DebugStepOver " , Shortcut ( tr ( " Debug - > Step over " ) , " F8 " , true ) ) ; <nl> + defaultShortcuts . insert ( " DebugeStepOver " , Shortcut ( tr ( " Debug - > Step over ( skip execptions ) " ) , " Shift + F8 " , true ) ) ; <nl> + defaultShortcuts . insert ( " DebugRtr " , Shortcut ( tr ( " Debug - > Execute till return " ) , " Ctrl + F9 " , true ) ) ; <nl> + defaultShortcuts . insert ( " DebugeRtr " , Shortcut ( tr ( " Debug - > execute till return ( skip exceptions ) " ) , " Ctrl + Shift + F9 " , true ) ) ; <nl> + defaultShortcuts . insert ( " DebugCommand " , Shortcut ( tr ( " Debug - > Command " ) , " Ctrl + Return " , true ) ) ; <nl> + <nl> + defaultShortcuts . insert ( " PluginsScylla " , Shortcut ( tr ( " Plugins - > Scylla " ) , " Ctrl + I " , true ) ) ; <nl> + <nl> + defaultShortcuts . insert ( " OptionsPreferences " , Shortcut ( tr ( " Options - > Preferences " ) , " " , true ) ) ; <nl> + defaultShortcuts . insert ( " OptionsAppearance " , Shortcut ( tr ( " Options - > Preferences " ) , " " , true ) ) ; <nl> + defaultShortcuts . insert ( " OptionsShortcuts " , Shortcut ( tr ( " Options - > Preferences " ) , " " , true ) ) ; <nl> + <nl> + defaultShortcuts . insert ( " HelpAbout " , Shortcut ( tr ( " Help - > About " ) , " " , true ) ) ; <nl> + defaultShortcuts . insert ( " HelpDonate " , Shortcut ( tr ( " Help - > Donate " ) , " " , true ) ) ; <nl> + defaultShortcuts . insert ( " HelpCheckForUpdates " , Shortcut ( tr ( " Help - > Check for Updates " ) , " " , true ) ) ; <nl> + <nl> + defaultShortcuts . insert ( " ActionFindStrings " , Shortcut ( tr ( " Actions - > Find Strings " ) , " " , true ) ) ; <nl> + defaultShortcuts . insert ( " ActionFindIntermodularCalls " , Shortcut ( tr ( " Actions - > Find Intermodular Calls " ) , " " , true ) ) ; <nl> + defaultShortcuts . insert ( " ActionToggleBreakpoint " , Shortcut ( tr ( " Actions - > Toggle Breakpoint " ) , " F2 " ) ) ; <nl> + defaultShortcuts . insert ( " ActionToggleBookmark " , Shortcut ( tr ( " Actions - > Toggle Bookmark " ) , " Ctrl + D " ) ) ; <nl> + defaultShortcuts . insert ( " ActionDeleteBreakpoint " , Shortcut ( tr ( " Actions - > Delete Breakpoint " ) , " Delete " ) ) ; <nl> + defaultShortcuts . insert ( " ActionEnableDisableBreakpoint " , Shortcut ( tr ( " Actions - > Enable / Disable Breakpoint " ) , " Space " ) ) ; <nl> + <nl> + defaultShortcuts . insert ( " ActionBinaryEdit " , Shortcut ( tr ( " Actions - > Binary Edit " ) , " Ctrl + E " ) ) ; <nl> + defaultShortcuts . insert ( " ActionBinaryFill " , Shortcut ( tr ( " Actions - > Binary Fill " ) , " F " ) ) ; <nl> + defaultShortcuts . insert ( " ActionBinaryFillNops " , Shortcut ( tr ( " Actions - > Binary Fill NOPs " ) , " Ctrl + 9 " ) ) ; <nl> + defaultShortcuts . insert ( " ActionBinaryCopy " , Shortcut ( tr ( " Actions - > Binary Copy " ) , " Shift + C " ) ) ; <nl> + defaultShortcuts . insert ( " ActionBinaryPaste " , Shortcut ( tr ( " Actions - > Binary Paste " ) , " Shift + V " ) ) ; <nl> + defaultShortcuts . insert ( " ActionBinaryPasteIgnoreSize " , Shortcut ( tr ( " Actions - > Binary Paste ( Ignore Size ) " ) , " Ctrl + Shift + V " ) ) ; <nl> + defaultShortcuts . insert ( " ActionUndoSelection " , Shortcut ( tr ( " Actions - > Undo Selection " ) , " Ctrl + Backspace " ) ) ; <nl> + defaultShortcuts . insert ( " ActionSetLabel " , Shortcut ( tr ( " Actions - > Set Label " ) , " : " ) ) ; <nl> + defaultShortcuts . insert ( " ActionSetComment " , Shortcut ( tr ( " Actions - > Set Comment " ) , " ; " ) ) ; <nl> + defaultShortcuts . insert ( " ActionToggleFunction " , Shortcut ( tr ( " Actions - > Toggle Function " ) , " Shift + F " ) ) ; <nl> + defaultShortcuts . insert ( " ActionAssemble " , Shortcut ( tr ( " Actions - > Assemble " ) , " Space " ) ) ; <nl> + defaultShortcuts . insert ( " ActionSetNewOriginHere " , Shortcut ( tr ( " Actions - > Set New Origin Here " ) , " Ctrl + * " ) ) ; <nl> + defaultShortcuts . insert ( " ActionGotoOrigin " , Shortcut ( tr ( " Actions - > Goto Origin " ) , " * " ) ) ; <nl> + defaultShortcuts . insert ( " ActionGotoPrevious " , Shortcut ( tr ( " Actions - > Goto Previous " ) , " - " ) ) ; <nl> + defaultShortcuts . insert ( " ActionGotoNext " , Shortcut ( tr ( " Actions - > Goto Next " ) , " + " ) ) ; <nl> + defaultShortcuts . insert ( " ActionGotoExpression " , Shortcut ( tr ( " Actions - > Goto Expression " ) , " Ctrl + G " ) ) ; <nl> + defaultShortcuts . insert ( " ActionFindReferencesToSelectedAddress " , Shortcut ( tr ( " Actions - > Find References to Selected Address " ) , " Ctrl + R " ) ) ; <nl> + defaultShortcuts . insert ( " ActionFindPattern " , Shortcut ( tr ( " Actions - > Find Pattern " ) , " Ctrl + B " ) ) ; <nl> + defaultShortcuts . insert ( " ActionHighlightingMode " , Shortcut ( tr ( " Actions - > Highlighting Mode " ) , " Ctrl + H " ) ) ; <nl> + <nl> + defaultShortcuts . insert ( " ActionIncreaseRegister " , Shortcut ( tr ( " Actions - > Increase Register " ) , " + " ) ) ; <nl> + defaultShortcuts . insert ( " ActionDecreaseRegister " , Shortcut ( tr ( " Actions - > Decrease Register " ) , " - " ) ) ; <nl> + defaultShortcuts . insert ( " ActionZeroRegister " , Shortcut ( tr ( " Actions - > Zero Register " ) , " 0 " ) ) ; <nl> + defaultShortcuts . insert ( " ActionSetOneRegister " , Shortcut ( tr ( " Actions - > Set Register to One " ) , " 1 " ) ) ; <nl> + defaultShortcuts . insert ( " ActionToggleRegisterValue " , Shortcut ( tr ( " Actions - > Toggle Register Value " ) , " Space " ) ) ; <nl> + defaultShortcuts . insert ( " ActionCopy " , Shortcut ( tr ( " Actions - > Copy " ) , " Ctrl + C " ) ) ; <nl> + defaultShortcuts . insert ( " ActionLoadScript " , Shortcut ( tr ( " Actions - > Load Script " ) , " Ctrl + O " ) ) ; <nl> + defaultShortcuts . insert ( " ActionUnloadScript " , Shortcut ( tr ( " Actions - > Unload Script " ) , " Ctrl + U " ) ) ; <nl> + defaultShortcuts . insert ( " ActionRunScript " , Shortcut ( tr ( " Actions - > Run Script " ) , " Space " ) ) ; <nl> + defaultShortcuts . insert ( " ActionToggleBreakpointScript " , Shortcut ( tr ( " Actions - > Toggle Script Breakpoint " ) , " F2 " ) ) ; <nl> + defaultShortcuts . insert ( " ActionRunToCursorScript " , Shortcut ( tr ( " Actions - > Run Script to Cursor " ) , " Shift + F4 " ) ) ; <nl> + defaultShortcuts . insert ( " ActionStepScript " , Shortcut ( tr ( " Actions - > Step Script " ) , " Tab " ) ) ; <nl> + defaultShortcuts . insert ( " ActionAbortScript " , Shortcut ( tr ( " Actions - > Abort Script " ) , " Esc " ) ) ; <nl> + defaultShortcuts . insert ( " ActionExecuteCommandScript " , Shortcut ( tr ( " Actions - > Execute Script Command " ) , " X " ) ) ; <nl> <nl> Shortcuts = defaultShortcuts ; <nl> <nl> void Configuration : : writeFonts ( ) <nl> emit fontsUpdated ( ) ; <nl> } <nl> <nl> - <nl> void Configuration : : readShortcuts ( ) <nl> { <nl> Shortcuts = defaultShortcuts ; <nl> void Configuration : : readShortcuts ( ) <nl> { <nl> const QString id = it . key ( ) ; <nl> QString key = shortcutFromConfig ( id ) ; <nl> - if ( key ! = " NOT_SET " ) <nl> + if ( key ! = " " ) <nl> { <nl> - if ( key ! = " " ) <nl> + if ( key = = " NOT_SET " ) <nl> + Shortcuts [ it . key ( ) ] . Hotkey = QKeySequence ( ) ; <nl> + else <nl> { <nl> QKeySequence KeySequence ( key ) ; <nl> Shortcuts [ it . key ( ) ] . Hotkey = KeySequence ; <nl> } <nl> - else <nl> - Shortcuts [ it . key ( ) ] . Hotkey = QKeySequence ( ) ; <nl> } <nl> it + + ; <nl> } <nl> void Configuration : : setShortcut ( const QString key_id , const QKeySequence key_seq <nl> { <nl> if ( Shortcuts . contains ( key_id ) ) <nl> { <nl> - for ( QMap < QString , Shortcut > : : iterator i = Shortcuts . begin ( ) ; i ! = Shortcuts . end ( ) ; + + i ) <nl> - { <nl> - if ( ! key_sequence . isEmpty ( ) & & i . value ( ) . Hotkey = = key_sequence ) <nl> - { <nl> - QMessageBox msg ( QMessageBox : : Warning , " DUPLICATE SHORTCUT " , key_id + " : " + key_sequence . toString ( ) ) ; <nl> - msg . setWindowIcon ( QIcon ( " : / icons / images / compile - warning . png " ) ) ; <nl> - msg . setWindowFlags ( msg . windowFlags ( ) & ( ~ Qt : : WindowContextHelpButtonHint ) ) ; <nl> - msg . exec ( ) ; <nl> - return ; <nl> - } <nl> - } <nl> Shortcuts [ key_id ] . Hotkey = key_sequence ; <nl> return ; <nl> } <nl> QString Configuration : : shortcutFromConfig ( const QString id ) <nl> { <nl> return QString ( setting ) ; <nl> } <nl> - return " NOT_SET " ; <nl> + return " " ; <nl> } <nl> <nl> bool Configuration : : shortcutToConfig ( const QString id , const QKeySequence shortcut ) <nl> bool Configuration : : shortcutToConfig ( const QString id , const QKeySequence shortc <nl> QString _key = " " ; <nl> if ( ! shortcut . isEmpty ( ) ) <nl> _key = shortcut . toString ( QKeySequence : : NativeText ) ; <nl> + else <nl> + _key = " NOT_SET " ; <nl> return BridgeSettingSet ( " Shortcuts " , _id . toUtf8 ( ) . constData ( ) , _key . toUtf8 ( ) . constData ( ) ) ; <nl> } <nl> mmm a / x64_dbg_gui / Project / Src / Utils / Configuration . h <nl> ppp b / x64_dbg_gui / Project / Src / Utils / Configuration . h <nl> <nl> # include < QString > <nl> # include < QColor > <nl> # include < QMap > <nl> - # include < QDebug > <nl> # include < QObject > <nl> # include < QKeySequence > <nl> # include " Bridge . h " <nl> class Configuration : public QObject <nl> { <nl> QString Name ; <nl> QKeySequence Hotkey ; <nl> + bool GlobalShortcut ; <nl> <nl> - Shortcut ( QString n = QString ( ) , QString h = QString ( ) ) <nl> + Shortcut ( QString n = QString ( ) , QString h = QString ( ) , bool g = false ) <nl> { <nl> Name = n ; <nl> Hotkey = QKeySequence ( h ) ; <nl> + GlobalShortcut = g ; <nl> } <nl> } ; <nl> <nl>
GUI : shortcuts now fully customizable
x64dbg/x64dbg
850ad8a1fef0ee5b870a97e2d54ee3eafaf3d8d8
2014-07-30T01:48:32Z
mmm a / lib / IRGen / GenStruct . cpp <nl> ppp b / lib / IRGen / GenStruct . cpp <nl> namespace { <nl> IGF . IGM . getMetadataLayout ( TheStruct . getStructOrBoundGenericStruct ( ) ) ; <nl> auto offset = <nl> structLayout . getFieldOffsetVectorOffset ( ) . offsetBy ( IGF , Size ( index ) ) ; <nl> - return offset . getAsValue ( IGF ) ; <nl> + <nl> + llvm : : Value * metadata = IGF . emitTypeMetadataRefForLayout ( TheStruct ) ; <nl> + Address fieldVector = emitAddressOfFieldOffsetVector ( IGF , metadata , <nl> + TheStruct . getStructOrBoundGenericStruct ( ) ) ; <nl> + fieldVector = IGF . Builder . CreateConstArrayGEP ( fieldVector , index , <nl> + IGF . IGM . getPointerSize ( ) ) ; <nl> + auto oldRet = IGF . Builder . CreateLoad ( fieldVector ) ; <nl> + auto newRet = offset . getAsValue ( IGF ) ; <nl> + <nl> + auto assertEq = IGF . IGM . Module . getFunction ( " __swift_assert_equal " ) ; <nl> + IGF . Builder . CreateCall ( assertEq - > getFunctionType ( ) , <nl> + assertEq , { oldRet , newRet } ) ; <nl> + <nl> + return newRet ; <nl> } <nl> <nl> MemberAccessStrategy getFieldAccessStrategy ( IRGenModule & IGM , <nl>
Modify to catch issue
apple/swift
7720a628fdc2db1b93c2a7a43410411f48c5ced7
2020-01-17T21:16:02Z
mmm a / src / ast / ast . h <nl> ppp b / src / ast / ast . h <nl> class Call final : public Expression { <nl> <nl> Handle < JSFunction > target ( ) { return target_ ; } <nl> <nl> - Handle < AllocationSite > allocation_site ( ) { return allocation_site_ ; } <nl> - <nl> void SetKnownGlobalTarget ( Handle < JSFunction > target ) { <nl> target_ = target ; <nl> set_is_uninitialized ( false ) ; <nl> } <nl> void set_target ( Handle < JSFunction > target ) { target_ = target ; } <nl> - void set_allocation_site ( Handle < AllocationSite > site ) { <nl> - allocation_site_ = site ; <nl> - } <nl> <nl> bool is_uninitialized ( ) const { <nl> return IsUninitializedField : : decode ( bit_field_ ) ; <nl> class Call final : public Expression { <nl> Expression * expression_ ; <nl> ZoneList < Expression * > * arguments_ ; <nl> Handle < JSFunction > target_ ; <nl> - Handle < AllocationSite > allocation_site_ ; <nl> } ; <nl> <nl> <nl> class CallNew final : public Expression { <nl> <nl> bool IsMonomorphic ( ) const { return IsMonomorphicField : : decode ( bit_field_ ) ; } <nl> Handle < JSFunction > target ( ) const { return target_ ; } <nl> - Handle < AllocationSite > allocation_site ( ) const { <nl> - return allocation_site_ ; <nl> - } <nl> <nl> - void set_allocation_site ( Handle < AllocationSite > site ) { <nl> - allocation_site_ = site ; <nl> - } <nl> void set_is_monomorphic ( bool monomorphic ) { <nl> bit_field_ = IsMonomorphicField : : update ( bit_field_ , monomorphic ) ; <nl> } <nl> class CallNew final : public Expression { <nl> Expression * expression_ ; <nl> ZoneList < Expression * > * arguments_ ; <nl> Handle < JSFunction > target_ ; <nl> - Handle < AllocationSite > allocation_site_ ; <nl> <nl> class IsMonomorphicField <nl> : public BitField < bool , Expression : : kNextBitFieldIndex , 1 > { } ; <nl> class BinaryOperation final : public Expression { <nl> void set_left ( Expression * e ) { left_ = e ; } <nl> Expression * right ( ) const { return right_ ; } <nl> void set_right ( Expression * e ) { right_ = e ; } <nl> - Handle < AllocationSite > allocation_site ( ) const { return allocation_site_ ; } <nl> - void set_allocation_site ( Handle < AllocationSite > allocation_site ) { <nl> - allocation_site_ = allocation_site ; <nl> - } <nl> <nl> void MarkTail ( ) { <nl> switch ( op ( ) ) { <nl> class BinaryOperation final : public Expression { <nl> / / sub - expression in | subexpr | and the literal Smi in | literal | . <nl> bool IsSmiLiteralOperation ( Expression * * subexpr , Smi * * literal ) ; <nl> <nl> - Maybe < int > fixed_right_arg ( ) const { <nl> - return has_fixed_right_arg_ ? Just ( fixed_right_arg_value_ ) : Nothing < int > ( ) ; <nl> - } <nl> - void set_fixed_right_arg ( Maybe < int > arg ) { <nl> - has_fixed_right_arg_ = arg . IsJust ( ) ; <nl> - if ( arg . IsJust ( ) ) fixed_right_arg_value_ = arg . FromJust ( ) ; <nl> - } <nl> - <nl> private : <nl> friend class AstNodeFactory ; <nl> <nl> BinaryOperation ( Token : : Value op , Expression * left , Expression * right , int pos ) <nl> - : Expression ( pos , kBinaryOperation ) , <nl> - left_ ( left ) , <nl> - right_ ( right ) , <nl> - has_fixed_right_arg_ ( false ) , <nl> - fixed_right_arg_value_ ( 0 ) { <nl> + : Expression ( pos , kBinaryOperation ) , left_ ( left ) , right_ ( right ) { <nl> bit_field_ | = OperatorField : : encode ( op ) ; <nl> DCHECK ( Token : : IsBinaryOp ( op ) ) ; <nl> } <nl> class BinaryOperation final : public Expression { <nl> FeedbackSlot feedback_slot_ ; <nl> Expression * left_ ; <nl> Expression * right_ ; <nl> - Handle < AllocationSite > allocation_site_ ; <nl> - / / TODO ( rossberg ) : the fixed arg should probably be represented as a Constant <nl> - / / type for the RHS . Currenty it ' s actually a Maybe < int > <nl> - bool has_fixed_right_arg_ ; <nl> - int fixed_right_arg_value_ ; <nl> <nl> class OperatorField <nl> : public BitField < Token : : Value , Expression : : kNextBitFieldIndex , 7 > { } ; <nl>
[ ast ] Remove dead fields from BinaryOperation expression .
v8/v8
2a0bfdb50e2231cca5a935d510240794327f7346
2017-06-22T08:17:50Z
mmm a / hphp / hack / src / typing / typing . ml <nl> ppp b / hphp / hack / src / typing / typing . ml <nl> open Typing_helpers <nl> module TFTerm = Typing_func_terminality <nl> module TUtils = Typing_utils <nl> module Reason = Typing_reason <nl> - module Inst = Decl_instantiate <nl> module Type = Typing_ops <nl> module Env = Typing_env <nl> module Inf = Typing_inference_env <nl> module Union = Typing_union <nl> module Inter = Typing_intersection <nl> module SN = Naming_special_names <nl> module TVis = Typing_visibility <nl> - module TNBody = Typing_naming_body <nl> module Phase = Typing_phase <nl> module TOG = Typing_object_get <nl> module Subst = Decl_subst <nl> module MakeType = Typing_make_type <nl> module Cls = Decl_provider . Class <nl> module Partial = Partial_provider <nl> module Fake = Typing_fake_members <nl> - module TySet = Typing_set <nl> - module TPEnv = Type_parameter_env <nl> - <nl> - exception InvalidPocketUniverse <nl> - <nl> module ExpectedTy = Typing_helpers . ExpectedTy <nl> <nl> ( * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ) <nl> let is_return_disposable_fun_type env ty = <nl> ( Typing_disposable . is_disposable_type env ft . ft_ret . et_type ) <nl> | _ - > false <nl> <nl> - let enforce_param_not_disposable env param ty = <nl> - if has_accept_disposable_attribute param then <nl> - ( ) <nl> - else <nl> - let p = param . param_pos in <nl> - match Typing_disposable . is_disposable_type env ty with <nl> - | Some class_name - > Errors . invalid_disposable_hint p ( strip_ns class_name ) <nl> - | None - > ( ) <nl> - <nl> - let param_has_at_most_rx_as_func p = <nl> - let module UA = SN . UserAttributes in <nl> - Naming_attributes . mem UA . uaAtMostRxAsFunc p . param_user_attributes <nl> - <nl> - let fun_reactivity env attrs params = <nl> - let r = Decl_fun_utils . fun_reactivity env attrs in <nl> - let module UA = Naming_special_names . UserAttributes in <nl> - let r = <nl> - ( * if at least one of parameters has < < __AtMostRxAsFunc > > attribute - <nl> - treat function reactivity as generic that is determined from the reactivity <nl> - of arguments annotated with __AtMostRxAsFunc . Declared reactivity is used as a <nl> - upper boundary of the reactivity function can have . * ) <nl> - if List . exists params ~ f : param_has_at_most_rx_as_func then <nl> - RxVar ( Some r ) <nl> - else <nl> - r <nl> - in <nl> - let r = <nl> - ( * if at least one of arguments have < < __OnlyRxIfImpl > > attribute - <nl> - treat function reactivity as conditional that is determined at the callsite * ) <nl> - if <nl> - List . exists params ~ f : ( fun { param_user_attributes = p ; _ } - > <nl> - Naming_attributes . mem UA . uaOnlyRxIfImpl p ) <nl> - then <nl> - MaybeReactive r <nl> - else <nl> - r <nl> - in <nl> - r <nl> - <nl> - let merge_hint_with_decl_hint env type_hint decl_ty = <nl> - let contains_tvar decl_ty = <nl> - match decl_ty with <nl> - | None - > false <nl> - | Some decl_ty - > TUtils . contains_tvar_decl decl_ty <nl> - in <nl> - if contains_tvar decl_ty then <nl> - decl_ty <nl> - else <nl> - Option . map type_hint ~ f : ( Decl_hint . hint env . decl_env ) <nl> - <nl> - ( * This function is used to determine the type of an argument . <nl> - * When we want to type - check the body of a function , we need to <nl> - * introduce the type of the arguments of the function in the environment <nl> - * Let ' s take an example , we want to check the code of foo : <nl> - * <nl> - * function foo ( int $ x ) : int { <nl> - * / / CALL TO make_param_type on ( int $ x ) <nl> - * / / Now we know that the type of $ x is int <nl> - * <nl> - * return $ x ; / / in the environment $ x is an int , the code is correct <nl> - * } <nl> - * <nl> - * When we localize , we want to resolve to " static " or " $ this " depending on <nl> - * the context . Even though we are passing in CIstatic , resolve_with_class_id <nl> - * is smart enough to know what to do . Why do this ? Consider the following <nl> - * <nl> - * abstract class C { <nl> - * abstract const type T ; <nl> - * <nl> - * private this : : T $ val ; <nl> - * <nl> - * final public function __construct ( this : : T $ x ) { <nl> - * $ this - > val = $ x ; <nl> - * } <nl> - * <nl> - * public static function create ( this : : T $ x ) : this { <nl> - * return new static ( $ x ) ; <nl> - * } <nl> - * } <nl> - * <nl> - * class D extends C { const type T = int ; } <nl> - * <nl> - * In __construct ( ) we want to be able to assign $ x to $ this - > val . The type of <nl> - * $ this - > val will expand to ' $ this : : T ' , so we need $ x to also be ' $ this : : T ' . <nl> - * We can do this soundly because when we construct a new class such as , <nl> - * ' new D ( 0 ) ' we can determine the late static bound type ( D ) and resolve <nl> - * ' this : : T ' to ' D : : T ' which is int . <nl> - * <nl> - * A similar line of reasoning is applied for the static method create . <nl> - * ) <nl> - let make_param_local_ty env decl_hint param = <nl> - let ety_env = { ( Phase . env_with_self env ) with from_class = Some CIstatic } in <nl> - let r = Reason . Rwitness param . param_pos in <nl> - let ( env , ty ) = <nl> - match decl_hint with <nl> - | None - > ( env , mk ( r , TUtils . tany env ) ) <nl> - | Some ty - > <nl> - let { et_type = ty ; _ } = <nl> - Typing_enforceability . compute_enforced_and_pessimize_ty <nl> - ~ explicitly_untrusted : param . param_is_variadic <nl> - env <nl> - ty <nl> - in <nl> - let condition_type = <nl> - Decl_fun_utils . condition_type_from_attributes <nl> - env . decl_env <nl> - param . param_user_attributes <nl> - in <nl> - begin <nl> - match condition_type with <nl> - | Some condition_type - > <nl> - let ( env , ty ) = Phase . localize ~ ety_env env ty in <nl> - begin <nl> - match <nl> - TR . try_substitute_type_with_condition env condition_type ty <nl> - with <nl> - | Some r - > r <nl> - | None - > ( env , ty ) <nl> - end <nl> - | _ <nl> - when Naming_attributes . mem <nl> - SN . UserAttributes . uaAtMostRxAsFunc <nl> - param . param_user_attributes - > <nl> - let ( env , ty ) = Phase . localize ~ ety_env env ty in <nl> - ( * expand type to track aliased function types * ) <nl> - let ( env , expanded_ty ) = Env . expand_type env ty in <nl> - let adjusted_ty = make_function_type_rxvar expanded_ty in <nl> - ( env , <nl> - if phys_equal adjusted_ty expanded_ty then <nl> - ty <nl> - else <nl> - adjusted_ty ) <nl> - | _ - > Phase . localize ~ ety_env env ty <nl> - end <nl> - in <nl> - let ty = <nl> - match get_node ty with <nl> - | t when param . param_is_variadic - > <nl> - ( * when checking the body of a function with a variadic <nl> - * argument , " f ( C . . . $ args ) " , $ args is a varray < C > * ) <nl> - let r = Reason . Rvar_param param . param_pos in <nl> - let arr_values = mk ( r , t ) in <nl> - mk ( r , Tarraykind ( AKvarray arr_values ) ) <nl> - | _ - > ty <nl> - in <nl> - Typing_reactivity . disallow_atmost_rx_as_rxfunc_on_non_functions env param ty ; <nl> - ( env , ty ) <nl> - <nl> ( * Given a localized parameter type and parameter information , infer <nl> * a type for the parameter default expression ( if present ) and check that <nl> * it is a subtype of the parameter type ( if present ) . If no parameter type <nl> let rec bind_param env ( ty1 , param ) = <nl> in <nl> ( env , tparam ) <nl> <nl> - ( * In strict mode , we force you to give a type declaration on a parameter * ) <nl> - ( * But the type checker is nice : it makes a suggestion : - ) * ) <nl> - and check_param_has_hint env param ty is_code_error = <nl> - let env = <nl> - if is_code_error 4231 then <nl> - attributes_check_def <nl> - env <nl> - SN . AttributeKinds . parameter <nl> - param . param_user_attributes <nl> - else <nl> - env <nl> - in <nl> - match hint_of_type_hint param . param_type_hint with <nl> - | None when param . param_is_variadic & & is_code_error 4033 - > <nl> - Errors . expecting_type_hint_variadic param . param_pos <nl> - | None when is_code_error 4032 - > Errors . expecting_type_hint param . param_pos <nl> - | Some _ when is_code_error 4010 - > <nl> - ( * We do not permit hints to implement IDisposable or IAsyncDisposable * ) <nl> - enforce_param_not_disposable env param ty <nl> - | _ - > ( ) <nl> - <nl> and check_inout_return env = <nl> let params = Local_id . Map . elements ( Env . get_params env ) in <nl> List . fold params ~ init : env ~ f : ( fun env ( id , ( ty , mode ) ) - > <nl> and check_inout_return env = <nl> Errors . inout_return_type_mismatch <nl> | _ - > env ) <nl> <nl> - and get_callable_variadicity <nl> - ? ( is_function = false ) ~ partial_callback ~ pos env variadicity_decl_ty = <nl> - function <nl> - | FVvariadicArg vparam - > <nl> - let ( env , ty ) = make_param_local_ty env variadicity_decl_ty vparam in <nl> - check_param_has_hint env vparam ty partial_callback ; <nl> - let ( env , t_variadic ) = bind_param env ( ty , vparam ) in <nl> - ( env , Aast . FVvariadicArg t_variadic ) <nl> - | FVellipsis p - > <nl> - if is_function & & Partial . should_check_error ( Env . get_mode env ) 4223 then <nl> - Errors . ellipsis_strict_mode ~ require : ` Type_and_param_name pos ; <nl> - ( env , Aast . FVellipsis p ) <nl> - | FVnonVariadic - > ( env , Aast . FVnonVariadic ) <nl> - <nl> ( * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ) <nl> ( * function used to type closures , functions and methods * ) <nl> ( * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ) <nl> and string2 env idl = <nl> in <nl> ( env , List . rev tel ) <nl> <nl> - ( * If the current class inherits from classes that take type arguments , we need <nl> - * to check that the arguments provided are consistent with the constraints on <nl> - * the type parameters . * ) <nl> - and check_implements_tparaml ( env : env ) ht = <nl> - let ( _r , ( _ , c ) , paraml ) = TUtils . unwrap_class_type ht in <nl> - let class_ = Env . get_class_dep env c in <nl> - match class_ with <nl> - | None - > <nl> - ( * The class lives in PHP land * ) <nl> - env <nl> - | Some class_ - > <nl> - let subst = Inst . make_subst ( Cls . tparams class_ ) paraml in <nl> - fold2_shortest <nl> - ~ f : ( fun env t ty - > <nl> - let ty_pos = get_pos ty in <nl> - List . fold t . tp_constraints ~ init : env ~ f : ( fun env ( ck , cstr ) - > <nl> - ( * Constraint might contain uses of generic type parameters * ) <nl> - let cstr = Inst . instantiate subst cstr in <nl> - match ck with <nl> - | Ast_defs . Constraint_as - > <nl> - Type . sub_type_decl ty_pos Reason . URnone env ty cstr <nl> - | Ast_defs . Constraint_eq - > <nl> - ( * This code could well be unreachable , because we don ' t allow <nl> - * equality constraints on class generics . * ) <nl> - let env = Type . sub_type_decl ty_pos Reason . URnone env ty cstr in <nl> - let env = Type . sub_type_decl ty_pos Reason . URnone env cstr ty in <nl> - env <nl> - | Ast_defs . Constraint_super - > <nl> - Type . sub_type_decl ty_pos Reason . URnone env cstr ty ) ) <nl> - ~ init : env <nl> - ( Cls . tparams class_ ) <nl> - paraml <nl> - <nl> - and check_parent env class_def class_type = <nl> - match Env . get_parent_class env with <nl> - | Some parent_type - > <nl> - let position = fst class_def . c_name in <nl> - if Cls . const class_type & & not ( Cls . const parent_type ) then <nl> - Errors . self_const_parent_not position ; <nl> - if Cls . final parent_type then <nl> - Errors . extend_final position ( Cls . pos parent_type ) ( Cls . name parent_type ) <nl> - | None - > ( ) <nl> - <nl> - and check_parent_sealed child_type parent_type = <nl> - match Cls . sealed_whitelist parent_type with <nl> - | None - > ( ) <nl> - | Some whitelist - > <nl> - let parent_pos = Cls . pos parent_type in <nl> - let parent_name = Cls . name parent_type in <nl> - let child_pos = Cls . pos child_type in <nl> - let child_name = Cls . name child_type in <nl> - let check kind action = <nl> - if not ( SSet . mem child_name whitelist ) then <nl> - Errors . extend_sealed child_pos parent_pos parent_name kind action <nl> - in <nl> - begin <nl> - match ( Cls . kind parent_type , Cls . kind child_type ) with <nl> - | ( Ast_defs . Cinterface , Ast_defs . Cinterface ) - > check " interface " " extend " <nl> - | ( Ast_defs . Cinterface , _ ) - > check " interface " " implement " <nl> - | ( Ast_defs . Ctrait , _ ) - > check " trait " " use " <nl> - | ( Ast_defs . Cabstract , _ ) <nl> - | ( Ast_defs . Cnormal , _ ) - > <nl> - check " class " " extend " <nl> - | ( Ast_defs . Cenum , _ ) - > ( ) <nl> - end <nl> - <nl> - and check_parents_sealed env child_def child_type = <nl> - let parents = <nl> - child_def . c_extends @ child_def . c_implements @ child_def . c_uses <nl> - in <nl> - List . iter parents ( function <nl> - | ( _ , Happly ( ( _ , name ) , _ ) ) - > <nl> - begin <nl> - match Env . get_class_dep env name with <nl> - | Some parent_type - > check_parent_sealed child_type parent_type <nl> - | None - > ( ) <nl> - end <nl> - | _ - > ( ) ) <nl> - <nl> - and check_const_trait_members pos env use_list = <nl> - let ( _ , trait , _ ) = Decl_utils . unwrap_class_hint use_list in <nl> - match Env . get_class env trait with <nl> - | Some c when Ast_defs . ( equal_class_kind ( Cls . kind c ) Ctrait ) - > <nl> - List . iter ( Cls . props c ) ( fun ( x , ce ) - > <nl> - if not ce . ce_const then Errors . trait_prop_const_class pos x ) <nl> - | _ - > ( ) <nl> - <nl> - and shallow_decl_enabled ( ctx : Provider_context . t ) : bool = <nl> - TypecheckerOptions . shallow_class_decl ctx . Provider_context . tcopt <nl> - <nl> - and class_def ctx c = <nl> - let env = EnvFromDef . class_env ctx c in <nl> - let tc = Env . get_class env ( snd c . c_name ) in <nl> - let env = Env . set_env_pessimize env in <nl> - Typing_helpers . add_decl_errors <nl> - Option . ( map tc ( fun tc - > value_exn ( Cls . decl_errors tc ) ) ) ; <nl> - let c = TNBody . class_meth_bodies ctx c in <nl> - NastCheck . class_ env c ; <nl> - NastInitCheck . class_ env c ; <nl> - match tc with <nl> - | None - > <nl> - ( * This can happen if there was an error during the declaration <nl> - * of the class . * ) <nl> - None <nl> - | Some tc - > <nl> - let env = Typing_requirements . check_class env tc in <nl> - if shallow_decl_enabled ctx then Typing_inheritance . check_class env tc ; <nl> - Some ( class_def_ env c tc ) <nl> - <nl> - ( * The two following functions enable us to retrieve the function ( or class ) <nl> - header from the shared mem . Note that they only return a non None value if <nl> - global inference is on * ) <nl> - and get_decl_method_header tcopt cls method_id ~ is_static = <nl> - let is_global_inference_on = TCO . global_inference tcopt in <nl> - if is_global_inference_on then <nl> - match Cls . get_any_method ~ is_static cls method_id with <nl> - | Some { ce_type = ( lazy ty ) ; _ } - > <nl> - begin <nl> - match get_node ty with <nl> - | Tfun fun_type - > Some fun_type <nl> - | _ - > None <nl> - end <nl> - | _ - > None <nl> - else <nl> - None <nl> - <nl> - and get_decl_prop_ty env cls ~ is_static prop_id = <nl> - let is_global_inference_on = TCO . global_inference ( Env . get_tcopt env ) in <nl> - if is_global_inference_on then <nl> - let prop_opt = <nl> - if is_static then <nl> - ( * this is very ad - hoc , but this is how we do it in the decl - heap * ) <nl> - Cls . get_sprop cls ( " $ " ^ prop_id ) <nl> - else <nl> - Cls . get_prop cls prop_id <nl> - in <nl> - match prop_opt with <nl> - | None - > failwith " error : could not find property in decl heap " <nl> - | Some { ce_type ; _ } - > Some ( Lazy . force ce_type ) <nl> - else <nl> - None <nl> - <nl> - and class_def_ env c tc = <nl> - let env = <nl> - let kind = <nl> - match c . c_kind with <nl> - | Ast_defs . Cenum - > SN . AttributeKinds . enum <nl> - | _ - > SN . AttributeKinds . cls <nl> - in <nl> - attributes_check_def env kind c . c_user_attributes <nl> - in <nl> - let ctx = Env . get_ctx env in <nl> - if <nl> - Ast_defs . ( equal_class_kind c . c_kind Cnormal ) <nl> - & & not ( shallow_decl_enabled ctx ) <nl> - then ( <nl> - ( * This check is only for eager mode . The same check is performed <nl> - * for shallow mode in Typing_inheritance * ) <nl> - let method_pos ~ is_static class_id meth_id = <nl> - let get_meth = <nl> - if is_static then <nl> - Decl_heap . StaticMethods . get <nl> - else <nl> - Decl_heap . Methods . get <nl> - in <nl> - match get_meth ( class_id , meth_id ) with <nl> - | Some { fe_pos ; _ } - > fe_pos <nl> - | None - > Pos . none <nl> - in <nl> - let check_override ~ is_static ( id , ce ) = <nl> - ( * ` ce_override ` is set in Decl when we determine that an <nl> - * override_per_trait error needs emit . This emission is deferred <nl> - * until Typing to ensure that this method has been added to <nl> - * Decl_heap * ) <nl> - if ce . ce_override then <nl> - let pos = method_pos ~ is_static ce . ce_origin id in <nl> - Errors . override_per_trait c . c_name id pos <nl> - in <nl> - List . iter ( Cls . methods tc ) ( check_override ~ is_static : false ) ; <nl> - List . iter ( Cls . smethods tc ) ( check_override ~ is_static : true ) <nl> - ) ; <nl> - let env = <nl> - { <nl> - env with <nl> - inside_ppl_class = <nl> - Naming_attributes . mem <nl> - SN . UserAttributes . uaProbabilisticModel <nl> - c . c_user_attributes ; <nl> - } <nl> - in <nl> - let ( pc , _ ) = c . c_name in <nl> - let impl = <nl> - List . map <nl> - ( c . c_extends @ c . c_implements @ c . c_uses ) <nl> - ( Decl_hint . hint env . decl_env ) <nl> - in <nl> - let c_tparam_list : decl_tparam list = <nl> - List . map <nl> - c . c_tparams . c_tparam_list <nl> - ~ f : ( Decl_hint . aast_tparam_to_decl_tparam env . decl_env ) <nl> - in <nl> - let ( env , constraints ) = <nl> - Phase . localize_generic_parameters_with_bounds <nl> - env <nl> - c_tparam_list <nl> - ~ ety_env : ( Phase . env_with_self env ) <nl> - in <nl> - let env = SubType . add_constraints ( fst c . c_name ) env constraints in <nl> - let env = <nl> - Phase . localize_where_constraints <nl> - ~ ety_env : ( Phase . env_with_self env ) <nl> - env <nl> - c . c_where_constraints <nl> - in <nl> - let env = <nl> - Phase . check_where_constraints <nl> - ~ in_class : true <nl> - ~ use_pos : pc <nl> - ~ definition_pos : pc <nl> - ~ ety_env : ( Phase . env_with_self env ) <nl> - env <nl> - ( Cls . where_constraints tc ) <nl> - in <nl> - Typing_variance . class_ ( Env . get_ctx env ) ( snd c . c_name ) tc impl ; <nl> - let env = List . fold impl ~ init : env ~ f : check_implements_tparaml in <nl> - let check_where_constraints env ht = <nl> - let ( _ , ( p , _ ) , _ ) = TUtils . unwrap_class_type ht in <nl> - let ( env , locl_ty ) = Phase . localize_with_self env ht in <nl> - match get_node ( TUtils . get_base_type env locl_ty ) with <nl> - | Tclass ( cls , _ , tyl ) - > <nl> - ( match Env . get_class env ( snd cls ) with <nl> - | Some cls when not ( List . is_empty ( Cls . where_constraints cls ) ) - > <nl> - let tc_tparams = Cls . tparams cls in <nl> - let ety_env = <nl> - { <nl> - ( Phase . env_with_self env ) with <nl> - substs = Subst . make_locl tc_tparams tyl ; <nl> - } <nl> - in <nl> - Phase . check_where_constraints <nl> - ~ in_class : true <nl> - ~ use_pos : pc <nl> - ~ definition_pos : p <nl> - ~ ety_env <nl> - env <nl> - ( Cls . where_constraints cls ) <nl> - | _ - > env ) <nl> - | _ - > env <nl> - in <nl> - let env = List . fold impl ~ init : env ~ f : check_where_constraints in <nl> - check_parent env c tc ; <nl> - check_parents_sealed env c tc ; <nl> - <nl> - let is_final = Cls . final tc in <nl> - if <nl> - ( Ast_defs . ( equal_class_kind ( Cls . kind tc ) Cnormal ) | | is_final ) <nl> - & & Cls . members_fully_known tc <nl> - then ( <nl> - check_extend_abstract_meth ~ is_final pc ( Cls . methods tc ) ; <nl> - ( match fst ( Cls . construct tc ) with <nl> - | Some constr - > <nl> - check_extend_abstract_meth ~ is_final pc [ ( SN . Members . __construct , constr ) ] <nl> - | None - > ( ) ) ; <nl> - check_extend_abstract_meth ~ is_final pc ( Cls . smethods tc ) ; <nl> - check_extend_abstract_prop ~ is_final pc ( Cls . sprops tc ) ; <nl> - check_extend_abstract_const ~ is_final pc ( Cls . consts tc ) ; <nl> - check_extend_abstract_typeconst ~ is_final pc ( Cls . typeconsts tc ) <nl> - ) ; <nl> - if Cls . const tc then List . iter c . c_uses ( check_const_trait_members pc env ) ; <nl> - let ( static_vars , vars ) = split_vars c in <nl> - List . iter static_vars ~ f : ( fun { cv_id = ( p , id ) ; _ } - > <nl> - check_static_class_element ( Cls . get_prop tc ) ~ elt_type : ` Property id p ) ; <nl> - List . iter vars ~ f : ( fun { cv_id = ( p , id ) ; _ } - > <nl> - check_dynamic_class_element ( Cls . get_sprop tc ) ~ elt_type : ` Property id p ) ; <nl> - let ( constructor , static_methods , methods ) = split_methods c in <nl> - List . iter static_methods ~ f : ( fun { m_name = ( p , id ) ; _ } - > <nl> - check_static_class_element ( Cls . get_method tc ) ~ elt_type : ` Method id p ) ; <nl> - List . iter methods ~ f : ( fun { m_name = ( p , id ) ; _ } - > <nl> - check_dynamic_class_element ( Cls . get_smethod tc ) ~ elt_type : ` Method id p ) ; <nl> - <nl> - ( * get a map of method names to list of traits from which they were removed * ) <nl> - let alist = <nl> - List . map c . c_method_redeclarations ~ f : ( fun m - > <nl> - let ( _ , name ) = m . mt_method in <nl> - let ( _ , trait , _ ) = Decl_utils . unwrap_class_hint m . mt_trait in <nl> - ( name , trait ) ) <nl> - in <nl> - let removals = <nl> - String . Map . of_alist_fold alist ~ init : [ ] ~ f : ( Fn . flip List . cons ) <nl> - in <nl> - let env = <nl> - List . fold ~ init : env impl ~ f : ( fun env - > <nl> - class_implements_type env c removals ) <nl> - in <nl> - let env = <nl> - List . fold <nl> - c . c_method_redeclarations <nl> - ~ init : env <nl> - ~ f : ( supertype_redeclared_method tc ) <nl> - in <nl> - if Cls . is_disposable tc then <nl> - List . iter <nl> - ( c . c_extends @ c . c_uses ) <nl> - ( Typing_disposable . enforce_is_disposable env ) ; <nl> - let ( env , typed_vars_and_global_inference_envs ) = <nl> - List . map_env env vars ( class_var_def ~ is_static : false tc ) <nl> - in <nl> - let ( typed_vars , vars_global_inference_envs ) = <nl> - List . unzip typed_vars_and_global_inference_envs <nl> - in <nl> - let typed_method_redeclarations = [ ] in <nl> - let ( typed_methods , methods_global_inference_envs ) = <nl> - List . filter_map methods ( method_def env tc ) | > List . unzip <nl> - in <nl> - let ( env , typed_typeconsts ) = List . map_env env c . c_typeconsts typeconst_def in <nl> - let ( env , consts ) = List . map_env env c . c_consts class_const_def in <nl> - let ( typed_consts , const_types ) = List . unzip consts in <nl> - let env = Typing_enum . enum_class_check env tc c . c_consts const_types in <nl> - let typed_constructor = class_constr_def env tc constructor in <nl> - let env = Env . set_static env in <nl> - let ( env , typed_static_vars_and_global_inference_envs ) = <nl> - List . map_env env static_vars ( class_var_def ~ is_static : true tc ) <nl> - in <nl> - let ( typed_static_vars , static_vars_global_inference_envs ) = <nl> - List . unzip typed_static_vars_and_global_inference_envs <nl> - in <nl> - let ( typed_static_methods , static_methods_global_inference_envs ) = <nl> - List . filter_map static_methods ( method_def env tc ) | > List . unzip <nl> - in <nl> - let ( env , file_attrs ) = file_attributes env c . c_file_attributes in <nl> - let ( methods , constr_global_inference_env ) = <nl> - match typed_constructor with <nl> - | None - > ( typed_static_methods @ typed_methods , [ ] ) <nl> - | Some ( m , global_inference_env ) - > <nl> - ( ( m : : typed_static_methods ) @ typed_methods , [ global_inference_env ] ) <nl> - in <nl> - let pu_enums = <nl> - try List . map c . c_pu_enums ~ f : ( pu_enum_def env ( snd c . c_name ) ) <nl> - with InvalidPocketUniverse - > [ ] <nl> - in <nl> - let ( env , tparams ) = class_type_param env c . c_tparams in <nl> - let ( env , user_attributes ) = <nl> - List . map_env env c . c_user_attributes user_attribute <nl> - in <nl> - let env = <nl> - Typing_solver . solve_all_unsolved_tyvars env Errors . bad_class_typevar <nl> - in <nl> - ( { <nl> - Aast . c_span = c . c_span ; <nl> - Aast . c_annotation = Env . save ( Env . get_tpenv env ) env ; <nl> - Aast . c_mode = c . c_mode ; <nl> - Aast . c_final = c . c_final ; <nl> - Aast . c_is_xhp = c . c_is_xhp ; <nl> - Aast . c_has_xhp_keyword = c . c_has_xhp_keyword ; <nl> - Aast . c_kind = c . c_kind ; <nl> - Aast . c_name = c . c_name ; <nl> - Aast . c_tparams = tparams ; <nl> - Aast . c_extends = c . c_extends ; <nl> - Aast . c_uses = c . c_uses ; <nl> - ( * c_use_as_alias and c_insteadof_alias are PHP features not supported <nl> - * in Hack but are required since we have runtime support for it <nl> - * ) <nl> - Aast . c_use_as_alias = [ ] ; <nl> - Aast . c_insteadof_alias = [ ] ; <nl> - Aast . c_method_redeclarations = typed_method_redeclarations ; <nl> - Aast . c_xhp_attr_uses = c . c_xhp_attr_uses ; <nl> - Aast . c_xhp_category = c . c_xhp_category ; <nl> - Aast . c_reqs = c . c_reqs ; <nl> - Aast . c_implements = c . c_implements ; <nl> - Aast . c_where_constraints = c . c_where_constraints ; <nl> - Aast . c_consts = typed_consts ; <nl> - Aast . c_typeconsts = typed_typeconsts ; <nl> - Aast . c_vars = typed_static_vars @ typed_vars ; <nl> - Aast . c_methods = methods ; <nl> - Aast . c_file_attributes = file_attrs ; <nl> - Aast . c_user_attributes = user_attributes ; <nl> - Aast . c_namespace = c . c_namespace ; <nl> - Aast . c_enum = c . c_enum ; <nl> - Aast . c_doc_comment = c . c_doc_comment ; <nl> - Aast . c_attributes = [ ] ; <nl> - Aast . c_xhp_children = c . c_xhp_children ; <nl> - Aast . c_xhp_attrs = [ ] ; <nl> - Aast . c_pu_enums = pu_enums ; <nl> - } , <nl> - methods_global_inference_envs <nl> - @ static_methods_global_inference_envs <nl> - @ constr_global_inference_env <nl> - @ static_vars_global_inference_envs <nl> - @ vars_global_inference_envs ) <nl> - <nl> - and check_dynamic_class_element get_static_elt element_name dyn_pos ~ elt_type = <nl> - ( * The non - static properties that we get passed do not start with ' $ ' , but the <nl> - static properties we want to look up do , so add it . * ) <nl> - let id = <nl> - match elt_type with <nl> - | ` Method - > element_name <nl> - | ` Property - > " $ " ^ element_name <nl> - in <nl> - match get_static_elt id with <nl> - | None - > ( ) <nl> - | Some static_element - > <nl> - let ( lazy ty ) = static_element . ce_type in <nl> - Errors . static_redeclared_as_dynamic <nl> - dyn_pos <nl> - ( get_pos ty ) <nl> - element_name <nl> - ~ elt_type <nl> - <nl> - and check_static_class_element get_dyn_elt element_name static_pos ~ elt_type = <nl> - ( * The static properties that we get passed in start with ' $ ' , but the <nl> - non - static properties we ' re matching against don ' t , so we need to detect <nl> - that and remove it if present . * ) <nl> - let element_name = String_utils . lstrip element_name " $ " in <nl> - match get_dyn_elt element_name with <nl> - | None - > ( ) <nl> - | Some dyn_element - > <nl> - let ( lazy ty ) = dyn_element . ce_type in <nl> - Errors . dynamic_redeclared_as_static <nl> - static_pos <nl> - ( get_pos ty ) <nl> - element_name <nl> - ~ elt_type <nl> - <nl> - and check_extend_abstract_meth ~ is_final p seq = <nl> - List . iter seq ( fun ( x , ce ) - > <nl> - match ce . ce_type with <nl> - | ( lazy ty ) when ce . ce_abstract & & is_fun ty - > <nl> - Errors . implement_abstract ~ is_final p ( get_pos ty ) " method " x <nl> - | _ - > ( ) ) <nl> - <nl> - and check_extend_abstract_prop ~ is_final p seq = <nl> - List . iter seq ( fun ( x , ce ) - > <nl> - if ce . ce_abstract then <nl> - let ce_pos = Lazy . force ce . ce_type | > get_pos in <nl> - Errors . implement_abstract ~ is_final p ce_pos " property " x ) <nl> - <nl> - ( * Type constants must be bound to a concrete type for non - abstract classes . <nl> - * ) <nl> - and check_extend_abstract_typeconst ~ is_final p seq = <nl> - List . iter seq ( fun ( x , tc ) - > <nl> - if Option . is_none tc . ttc_type then <nl> - Errors . implement_abstract <nl> - ~ is_final <nl> - p <nl> - ( fst tc . ttc_name ) <nl> - " type constant " <nl> - x ) <nl> - <nl> - and check_extend_abstract_const ~ is_final p seq = <nl> - List . iter seq ( fun ( x , cc ) - > <nl> - if cc . cc_abstract & & not cc . cc_synthesized then <nl> - let cc_pos = get_pos cc . cc_type in <nl> - Errors . implement_abstract ~ is_final p cc_pos " constant " x ) <nl> - <nl> - and typeconst_def <nl> - env <nl> - { <nl> - c_tconst_abstract ; <nl> - c_tconst_name = ( pos , _ ) as id ; <nl> - c_tconst_constraint ; <nl> - c_tconst_type = hint ; <nl> - c_tconst_user_attributes ; <nl> - c_tconst_span ; <nl> - c_tconst_doc_comment ; <nl> - } = <nl> - let ( env , cstr ) = opt Phase . localize_hint_with_self env c_tconst_constraint in <nl> - let ( env , ty ) = opt Phase . localize_hint_with_self env hint in <nl> - let check env t c = <nl> - Type . sub_type pos Reason . URtypeconst_cstr env t c Errors . unify_error <nl> - in <nl> - let env = Option . value ~ default : env @ @ Option . map2 ty cstr ~ f : ( check env ) in <nl> - let env = <nl> - match hint with <nl> - | Some ( pos , Hshape { nsi_field_map ; _ } ) - > <nl> - let get_name sfi = sfi . sfi_name in <nl> - check_shape_keys_validity env pos ( List . map ~ f : get_name nsi_field_map ) <nl> - | _ - > env <nl> - in <nl> - let env = <nl> - attributes_check_def <nl> - env <nl> - SN . AttributeKinds . typeconst <nl> - c_tconst_user_attributes <nl> - in <nl> - let ( env , user_attributes ) = <nl> - List . map_env env c_tconst_user_attributes user_attribute <nl> - in <nl> - ( env , <nl> - { <nl> - Aast . c_tconst_abstract ; <nl> - Aast . c_tconst_name = id ; <nl> - Aast . c_tconst_constraint ; <nl> - Aast . c_tconst_type = hint ; <nl> - Aast . c_tconst_user_attributes = user_attributes ; <nl> - Aast . c_tconst_span ; <nl> - Aast . c_tconst_doc_comment ; <nl> - } ) <nl> - <nl> - and pu_enum_def <nl> - env <nl> - c_name <nl> - { pu_name ; pu_is_final ; pu_case_types ; pu_case_values ; pu_members ; _ } = <nl> - ( * What is a well - formed pocket universe ? <nl> - - pu_name is unique <nl> - - pu_case_types are well - formed if all names are unique <nl> - - pu_case_values are well - formed if all types are well - formed in an <nl> - environment where all names in pu_case_types are bound to abstract types <nl> - - pu_members are well - formed if : <nl> - - each name is unique <nl> - - all types are defined one and only one times in pum_types , and <nl> - are well - formed in an environment <nl> - - all values are defined one and only one times in pum_types , and <nl> - are correctly typed according to pum_types instances . <nl> - <nl> - Note : Structural correctness ( mostly uniqueness and exhaustivity ) <nl> - is checked during Nast check . <nl> - If the Nast check fails , this function might raise InvalidPocketUniverse , <nl> - that we silently ignore not to spam with duplicated errors . <nl> - <nl> - Here we check that all definitions are well - typed . <nl> - * ) <nl> - let pos = fst pu_name in <nl> - let cls = Decl_provider . get_class ( Env . get_ctx env ) c_name in <nl> - let pu_enum = <nl> - Option . bind cls ~ f : ( fun cls - > Cls . get_pu_enum cls ( snd pu_name ) ) <nl> - in <nl> - let make_ty_tparam ( sid , reified ) = <nl> - { <nl> - tp_variance = Ast_defs . Invariant ; <nl> - tp_name = sid ; <nl> - tp_constraints = [ ] ; <nl> - tp_reified = reified ; <nl> - tp_user_attributes = [ ] ; <nl> - } <nl> - in <nl> - let make_aast_tparam ( sid , hint ) = <nl> - let hint_ty = Decl_hint . hint env . decl_env hint in <nl> - { <nl> - tp_variance = Ast_defs . Invariant ; <nl> - tp_name = sid ; <nl> - tp_constraints = [ ( Ast_defs . Constraint_eq , hint_ty ) ] ; <nl> - tp_reified = Aast . Erased ; <nl> - tp_user_attributes = [ ] ; <nl> - } <nl> - in <nl> - let ( env , constraints ) = <nl> - let ( env , constraints ) = <nl> - Phase . localize_generic_parameters_with_bounds <nl> - env <nl> - ~ ety_env : ( Phase . env_with_self env ) <nl> - ( List . map ~ f : make_ty_tparam pu_case_types ) <nl> - in <nl> - let env = <nl> - List . fold pu_case_values ~ init : env ~ f : ( fun env ( _sid , hint ) - > <nl> - let ( env , _ty ) = Phase . localize_hint_with_self env hint in <nl> - env ) <nl> - in <nl> - ( env , constraints ) <nl> - in <nl> - let env = SubType . add_constraints pos env constraints in <nl> - let ( env , members ) = <nl> - let process_member env pum = <nl> - let ( env , cstrs ) = <nl> - let pum_types = List . map ~ f : make_aast_tparam pum . pum_types in <nl> - Phase . localize_generic_parameters_with_bounds <nl> - env <nl> - ~ ety_env : ( Phase . env_with_self env ) <nl> - pum_types <nl> - in <nl> - let env = SubType . add_constraints ( fst pum . pum_atom ) env cstrs in <nl> - let process_mapping env ( sid , map_expr ) = <nl> - let ( env , ty , expected ) = <nl> - let equal ( ( _ , s1 ) : sid ) ( ( _ , s2 ) : sid ) = String . equal s1 s2 in <nl> - let ( env , ty ) = <nl> - match List . Assoc . find ~ equal pu_case_values sid with <nl> - | None - > <nl> - ( ( * Check in parent hierarchy * ) <nl> - match pu_enum with <nl> - | None - > raise InvalidPocketUniverse <nl> - | Some pu_enum - > <nl> - ( match SMap . find_opt ( snd sid ) pu_enum . tpu_case_values with <nl> - | None - > raise InvalidPocketUniverse <nl> - | Some ( _ , decl_ty ) - > Phase . localize_with_self env decl_ty ) ) <nl> - | Some hint - > Phase . localize_hint_with_self env hint <nl> - in <nl> - ( env , ty , Some ( ExpectedTy . make ( fst sid ) Reason . URhint ty ) ) <nl> - in <nl> - let ( env , expr , ty ' ) = expr ? expected env map_expr in <nl> - let env = <nl> - Typing_ops . sub_type <nl> - ( fst sid ) <nl> - Reason . URhint <nl> - env <nl> - ty ' <nl> - ty <nl> - Errors . pocket_universes_typing <nl> - in <nl> - ( env , ( sid , expr ) ) <nl> - in <nl> - let ( env , pum_exprs ) = <nl> - List . fold_map pum . pum_exprs ~ init : env ~ f : process_mapping <nl> - in <nl> - let members = <nl> - { <nl> - Aast . pum_atom = pum . pum_atom ; <nl> - Aast . pum_types = pum . pum_types ; <nl> - Aast . pum_exprs ; <nl> - } <nl> - in <nl> - ( env , members ) <nl> - in <nl> - List . fold_map ~ init : env ~ f : process_member pu_members <nl> - in <nl> - let local_tpenv = Env . get_tpenv env in <nl> - let local_tpenv = <nl> - List . fold <nl> - ~ init : local_tpenv <nl> - ~ f : ( fun tpenv ( ( _ , name ) , reified ) - > <nl> - let tpinfo = <nl> - TPEnv . <nl> - { <nl> - lower_bounds = TySet . empty ; <nl> - upper_bounds = TySet . empty ; <nl> - reified ; <nl> - enforceable = false ; <nl> - ( * TODO ( T35357243 ) improve to support that * ) <nl> - newable = false ( * TODO ( T35357243 ) improve to support that * ) ; <nl> - } <nl> - in <nl> - TPEnv . add name tpinfo tpenv ) <nl> - pu_case_types <nl> - in <nl> - { <nl> - Aast . pu_annotation = Env . save local_tpenv env ; <nl> - Aast . pu_name ; <nl> - Aast . pu_is_final ; <nl> - Aast . pu_case_types ; <nl> - Aast . pu_case_values ; <nl> - Aast . pu_members = members ; <nl> - } <nl> - <nl> - and class_const_def env cc = <nl> - let { cc_type = h ; cc_id = id ; cc_expr = e ; _ } = cc in <nl> - let ( env , ty , opt_expected ) = <nl> - match h with <nl> - | None - > <nl> - let ( env , ty ) = Env . fresh_type env ( fst id ) in <nl> - ( env , MakeType . unenforced ty , None ) <nl> - | Some h - > <nl> - let ty = Decl_hint . hint env . decl_env h in <nl> - let ty = Typing_enforceability . compute_enforced_ty env ty in <nl> - let ( env , ty ) = Phase . localize_possibly_enforced_with_self env ty in <nl> - ( env , <nl> - ty , <nl> - Some ( ExpectedTy . make_and_allow_coercion ( fst id ) Reason . URhint ty ) ) <nl> - in <nl> - let ( env , eopt , ty ) = <nl> - match e with <nl> - | Some e - > <nl> - let ( env , te , ty ' ) = expr ? expected : opt_expected env e in <nl> - let env = <nl> - Typing_coercion . coerce_type <nl> - ( fst id ) <nl> - Reason . URhint <nl> - env <nl> - ty ' <nl> - ty <nl> - Errors . class_constant_value_does_not_match_hint <nl> - in <nl> - ( env , Some te , ty ' ) <nl> - | None - > ( env , None , ty . et_type ) <nl> - in <nl> - ( env , <nl> - ( { <nl> - Aast . cc_type = cc . cc_type ; <nl> - Aast . cc_id = cc . cc_id ; <nl> - Aast . cc_expr = eopt ; <nl> - Aast . cc_doc_comment = cc . cc_doc_comment ; <nl> - } , <nl> - ty ) ) <nl> - <nl> - and class_constr_def env cls constructor = <nl> - let env = { env with inside_constructor = true } in <nl> - Option . bind constructor ( method_def env cls ) <nl> - <nl> - and class_implements_type env c1 removals ctype2 = <nl> - let params = <nl> - List . map c1 . c_tparams . c_tparam_list ( fun { tp_name = ( p , s ) ; _ } - > <nl> - mk ( Reason . Rwitness p , Tgeneric s ) ) <nl> - in <nl> - let r = Reason . Rwitness ( fst c1 . c_name ) in <nl> - let ctype1 = mk ( r , Tapply ( c1 . c_name , params ) ) in <nl> - Typing_extends . check_implements env removals ctype2 ctype1 <nl> - <nl> - ( * Type - check a property declaration , with optional initializer * ) <nl> - and class_var_def ~ is_static cls env cv = <nl> - ( * First pick up and localize the hint if it exists * ) <nl> - let decl_cty = <nl> - merge_hint_with_decl_hint <nl> - env <nl> - ( hint_of_type_hint cv . cv_type ) <nl> - ( get_decl_prop_ty env cls ~ is_static ( snd cv . cv_id ) ) <nl> - in <nl> - let ( env , expected ) = <nl> - match decl_cty with <nl> - | None - > ( env , None ) <nl> - | Some decl_cty - > <nl> - let decl_cty = Typing_enforceability . compute_enforced_ty env decl_cty in <nl> - let ( env , cty ) = <nl> - Phase . localize_possibly_enforced_with_self env decl_cty <nl> - in <nl> - let expected = <nl> - Some ( ExpectedTy . make_and_allow_coercion cv . cv_span Reason . URhint cty ) <nl> - in <nl> - ( env , expected ) <nl> - in <nl> - ( * Next check the expression , passing in expected type if present * ) <nl> - let ( env , typed_cv_expr ) = <nl> - match cv . cv_expr with <nl> - | None - > ( env , None ) <nl> - | Some e - > <nl> - let ( env , te , ty ) = expr ? expected env e in <nl> - ( * Check that the inferred type is a subtype of the expected type . <nl> - * Eventually this will be the responsibility of ` expr ` <nl> - * ) <nl> - let env = <nl> - match expected with <nl> - | None - > env <nl> - | Some ExpectedTy . { pos = p ; reason = ur ; ty = cty } - > <nl> - Typing_coercion . coerce_type <nl> - p <nl> - ur <nl> - env <nl> - ty <nl> - cty <nl> - Errors . class_property_initializer_type_does_not_match_hint <nl> - in <nl> - ( env , Some te ) <nl> - in <nl> - let env = <nl> - if is_static then <nl> - attributes_check_def <nl> - env <nl> - SN . AttributeKinds . staticProperty <nl> - cv . cv_user_attributes <nl> - else <nl> - attributes_check_def <nl> - env <nl> - SN . AttributeKinds . instProperty <nl> - cv . cv_user_attributes <nl> - in <nl> - let ( env , user_attributes ) = <nl> - List . map_env env cv . cv_user_attributes user_attribute <nl> - in <nl> - if <nl> - Option . is_none ( hint_of_type_hint cv . cv_type ) <nl> - & & Partial . should_check_error ( Env . get_mode env ) 2001 <nl> - then <nl> - Errors . prop_without_typehint <nl> - ( string_of_visibility cv . cv_visibility ) <nl> - cv . cv_id ; <nl> - let ( env , global_inference_env ) = Env . extract_global_inference_env env in <nl> - let cv_type = <nl> - match expected with <nl> - | Some expected - > <nl> - ( expected . ExpectedTy . ty . et_type , hint_of_type_hint cv . cv_type ) <nl> - | None - > dummy_type_hint ( hint_of_type_hint cv . cv_type ) <nl> - in <nl> - ( env , <nl> - ( { <nl> - Aast . cv_final = cv . cv_final ; <nl> - Aast . cv_xhp_attr = cv . cv_xhp_attr ; <nl> - Aast . cv_abstract = cv . cv_abstract ; <nl> - Aast . cv_visibility = cv . cv_visibility ; <nl> - Aast . cv_type ; <nl> - Aast . cv_id = cv . cv_id ; <nl> - Aast . cv_expr = typed_cv_expr ; <nl> - Aast . cv_user_attributes = user_attributes ; <nl> - Aast . cv_is_promoted_variadic = cv . cv_is_promoted_variadic ; <nl> - Aast . cv_doc_comment = cv . cv_doc_comment ; <nl> - ( * Can make None to save space * ) <nl> - Aast . cv_is_static = is_static ; <nl> - Aast . cv_span = cv . cv_span ; <nl> - } , <nl> - ( cv . cv_span , global_inference_env ) ) ) <nl> - <nl> - and supertype_redeclared_method tc env m = <nl> - let ( pos , name ) = m . mt_name in <nl> - let get_method = <nl> - if m . mt_static then <nl> - Env . get_static_member <nl> - else <nl> - Env . get_member <nl> - in <nl> - let class_member_opt = get_method true env tc name in <nl> - let ( _ , trait , _ ) = Decl_utils . unwrap_class_hint m . mt_trait in <nl> - let ( _ , trait_method ) = m . mt_method in <nl> - Option . ( <nl> - let trait_member_opt = <nl> - Env . get_class env trait > > = fun trait_tc - > <nl> - get_method true env trait_tc trait_method <nl> - in <nl> - map2 trait_member_opt class_member_opt ~ f : ( fun trait_member class_member - > <nl> - let ( ( lazy ty_child ) , ( lazy ty_parent ) ) = <nl> - ( trait_member . ce_type , class_member . ce_type ) <nl> - in <nl> - match ( deref ty_child , deref ty_parent ) with <nl> - | ( ( r_child , Tfun ft_child ) , ( r_parent , Tfun ft_parent ) ) - > <nl> - let ety_env = Phase . env_with_self env ~ quiet : true in <nl> - let ( env , ft_child ) = <nl> - Phase . localize_ft <nl> - ~ ety_env <nl> - ~ def_pos : ( Reason . to_pos r_child ) <nl> - env <nl> - ft_child <nl> - in <nl> - let ( env , ft_parent ) = <nl> - Phase . localize_ft <nl> - ~ ety_env <nl> - ~ def_pos : ( Reason . to_pos r_parent ) <nl> - env <nl> - ft_parent <nl> - in <nl> - Typing_subtype . ( <nl> - subtype_method <nl> - ~ check_return : true <nl> - ~ extra_info : <nl> - { method_info = None ; class_ty = None ; parent_class_ty = None } <nl> - env <nl> - r_child <nl> - ft_child <nl> - r_parent <nl> - ft_parent ) <nl> - ( fun ? code : _ errorl - > <nl> - Errors . bad_method_override pos name errorl Errors . unify_error ) <nl> - | _ - > env ) <nl> - | > Option . value ~ default : env ) <nl> - <nl> and user_attribute env ua = <nl> let ( env , typed_ua_params ) = <nl> List . map_env env ua . ua_params ( fun env e - > <nl> and file_attributes env file_attrs = <nl> Aast . fa_namespace = fa . fa_namespace ; <nl> } ) ) <nl> <nl> - and reify_kind = function <nl> - | Erased - > Aast . Erased <nl> - | SoftReified - > Aast . SoftReified <nl> - | Reified - > Aast . Reified <nl> - <nl> and type_param env t = <nl> let env = <nl> attributes_check_def env SN . AttributeKinds . typeparam t . tp_user_attributes <nl> and type_param env t = <nl> Aast . tp_user_attributes = user_attributes ; <nl> } ) <nl> <nl> - and class_type_param env ct = <nl> - let ( env , tparam_list ) = List . map_env env ct . c_tparam_list type_param in <nl> - ( env , <nl> - { <nl> - Aast . c_tparam_list = tparam_list ; <nl> - Aast . c_tparam_constraints = <nl> - SMap . map ( Tuple . T2 . map_fst ~ f : reify_kind ) ct . c_tparam_constraints ; <nl> - } ) <nl> - <nl> - ( * During the decl phase we can , for global inference , add " improved type hints " . <nl> - That is we can say that some missing type hints are in fact global tyvars . <nl> - In that case to get the real type hint we must merge the type hint present <nl> - in the ast with the one we created during the decl phase . This function does <nl> - exactly this for the return type , the parameters and the variadic parameters . <nl> - * ) <nl> - and merge_decl_header_with_hints ~ params ~ ret ~ variadic decl_header env = <nl> - let ret_decl_ty = <nl> - merge_hint_with_decl_hint <nl> - env <nl> - ( hint_of_type_hint ret ) <nl> - ( Option . map <nl> - ~ f : ( fun { ft_ret = { et_type ; _ } ; _ } - > et_type ) <nl> - decl_header ) <nl> - in <nl> - let params_decl_ty = <nl> - match decl_header with <nl> - | None - > <nl> - List . map <nl> - ~ f : ( fun h - > <nl> - merge_hint_with_decl_hint <nl> - env <nl> - ( hint_of_type_hint h . param_type_hint ) <nl> - None ) <nl> - params <nl> - | Some { ft_params ; _ } - > <nl> - List . zip_exn params ft_params <nl> - | > List . map ~ f : ( fun ( h , { fp_type = { et_type ; _ } ; _ } ) - > <nl> - merge_hint_with_decl_hint <nl> - env <nl> - ( hint_of_type_hint h . param_type_hint ) <nl> - ( Some et_type ) ) <nl> - in <nl> - let variadicity_decl_ty = <nl> - match ( decl_header , variadic ) with <nl> - | ( Some { ft_arity = Fvariadic ( _ , { fp_type = { et_type ; _ } ; _ } ) ; _ } , <nl> - FVvariadicArg fp ) - > <nl> - merge_hint_with_decl_hint <nl> - env <nl> - ( hint_of_type_hint fp . param_type_hint ) <nl> - ( Some et_type ) <nl> - | ( _ , FVvariadicArg fp ) - > <nl> - merge_hint_with_decl_hint env ( hint_of_type_hint fp . param_type_hint ) None <nl> - | _ - > None <nl> - in <nl> - ( ret_decl_ty , params_decl_ty , variadicity_decl_ty ) <nl> - <nl> - and method_def env cls m = <nl> - with_timeout env m . m_name ~ do_ : ( fun env - > <nl> - let initial_env = env in <nl> - ( * reset the expression dependent display ids for each method body * ) <nl> - Reason . expr_display_id_map : = IMap . empty ; <nl> - let decl_header = <nl> - get_decl_method_header <nl> - ( Env . get_tcopt env ) <nl> - cls <nl> - ( snd m . m_name ) <nl> - ~ is_static : m . m_static <nl> - in <nl> - let pos = fst m . m_name in <nl> - let env = Env . open_tyvars env ( fst m . m_name ) in <nl> - let env = Env . reinitialize_locals env in <nl> - let env = Env . set_env_function_pos env pos in <nl> - let env = <nl> - attributes_check_def env SN . AttributeKinds . mthd m . m_user_attributes <nl> - in <nl> - let reactive = <nl> - fun_reactivity env . decl_env m . m_user_attributes m . m_params <nl> - in <nl> - let mut = <nl> - match TUtils . fun_mutable m . m_user_attributes with <nl> - | None - > <nl> - ( * < < __Mutable > > is implicit on constructors * ) <nl> - if String . equal ( snd m . m_name ) SN . Members . __construct then <nl> - Some Param_borrowed_mutable <nl> - else <nl> - None <nl> - | x - > x <nl> - in <nl> - let env = Env . set_env_reactive env reactive in <nl> - let env = Env . set_fun_mutable env mut in <nl> - let ety_env = <nl> - { ( Phase . env_with_self env ) with from_class = Some CIstatic } <nl> - in <nl> - let m_tparams : decl_tparam list = <nl> - List . map <nl> - m . m_tparams <nl> - ~ f : ( Decl_hint . aast_tparam_to_decl_tparam env . decl_env ) <nl> - in <nl> - let ( env , constraints ) = <nl> - Phase . localize_generic_parameters_with_bounds env m_tparams ~ ety_env <nl> - in <nl> - let env = SubType . add_constraints pos env constraints in <nl> - let env = <nl> - Phase . localize_where_constraints ~ ety_env env m . m_where_constraints <nl> - in <nl> - let env = <nl> - if Env . is_static env then <nl> - env <nl> - else <nl> - Env . set_local env this ( Env . get_self env ) <nl> - in <nl> - let env = <nl> - match Env . get_self_class env with <nl> - | None - > env <nl> - | Some c - > <nl> - ( * Mark $ this as a using variable if it has a disposable type * ) <nl> - if Cls . is_disposable c then <nl> - Env . set_using_var env this <nl> - else <nl> - env <nl> - in <nl> - let env = Env . clear_params env in <nl> - let ( ret_decl_ty , params_decl_ty , variadicity_decl_ty ) = <nl> - merge_decl_header_with_hints <nl> - ~ params : m . m_params <nl> - ~ ret : m . m_ret <nl> - ~ variadic : m . m_variadic <nl> - decl_header <nl> - env <nl> - in <nl> - let env = Env . set_fn_kind env m . m_fun_kind in <nl> - let ( env , locl_ty ) = <nl> - match ret_decl_ty with <nl> - | None - > <nl> - ( env , Typing_return . make_default_return ~ is_method : true env m . m_name ) <nl> - | Some ret - > <nl> - ( * If a ' this ' type appears it needs to be compatible with the <nl> - * late static type <nl> - * ) <nl> - let ety_env = <nl> - { ( Phase . env_with_self env ) with from_class = Some CIstatic } <nl> - in <nl> - Typing_return . make_return_type ( Phase . localize ~ ety_env ) env ret <nl> - in <nl> - let return = <nl> - Typing_return . make_info <nl> - m . m_fun_kind <nl> - m . m_user_attributes <nl> - env <nl> - ~ is_explicit : ( Option . is_some ( hint_of_type_hint m . m_ret ) ) <nl> - locl_ty <nl> - ret_decl_ty <nl> - in <nl> - let ( env , param_tys ) = <nl> - List . zip_exn m . m_params params_decl_ty <nl> - | > List . map_env env ~ f : ( fun env ( param , hint ) - > <nl> - make_param_local_ty env hint param ) <nl> - in <nl> - let partial_callback = Partial . should_check_error ( Env . get_mode env ) in <nl> - let param_fn p t = check_param_has_hint env p t partial_callback in <nl> - List . iter2_exn ~ f : param_fn m . m_params param_tys ; <nl> - Typing_memoize . check_method env m ; <nl> - let ( env , typed_params ) = <nl> - List . map_env env ( List . zip_exn param_tys m . m_params ) bind_param <nl> - in <nl> - let ( env , t_variadic ) = <nl> - get_callable_variadicity <nl> - ~ partial_callback <nl> - ~ pos <nl> - env <nl> - variadicity_decl_ty <nl> - m . m_variadic <nl> - in <nl> - let env = <nl> - set_tyvars_variance_in_callable env locl_ty param_tys t_variadic <nl> - in <nl> - let nb = Nast . assert_named_body m . m_body in <nl> - let local_tpenv = Env . get_tpenv env in <nl> - let disable = <nl> - Naming_attributes . mem <nl> - SN . UserAttributes . uaDisableTypecheckerInternal <nl> - m . m_user_attributes <nl> - in <nl> - let ( env , tb ) = <nl> - fun_ ~ abstract : m . m_abstract ~ disable env return pos nb m . m_fun_kind <nl> - in <nl> - ( * restore original method reactivity * ) <nl> - let env = Env . set_env_reactive env reactive in <nl> - let type_hint ' = <nl> - match hint_of_type_hint m . m_ret with <nl> - | None when String . equal ( snd m . m_name ) SN . Members . __construct - > <nl> - Some ( pos , Hprim Tvoid ) <nl> - | None - > <nl> - if partial_callback 4030 then Errors . expecting_return_type_hint pos ; <nl> - None <nl> - | Some hint - > <nl> - Typing_return . async_suggest_return m . m_fun_kind hint ( fst m . m_name ) ; <nl> - hint_of_type_hint m . m_ret <nl> - in <nl> - let m = { m with m_ret = ( fst m . m_ret , type_hint ' ) } in <nl> - let annotation = <nl> - if Nast . named_body_is_unsafe nb then <nl> - Tast . HasUnsafeBlocks <nl> - else <nl> - Tast . NoUnsafeBlocks <nl> - in <nl> - let ( env , tparams ) = List . map_env env m . m_tparams type_param in <nl> - let ( env , user_attributes ) = <nl> - List . map_env env m . m_user_attributes user_attribute <nl> - in <nl> - let env = <nl> - Typing_solver . close_tyvars_and_solve env Errors . bad_method_typevar <nl> - in <nl> - let env = <nl> - Typing_solver . solve_all_unsolved_tyvars env Errors . bad_method_typevar <nl> - in <nl> - let method_def = <nl> - { <nl> - Aast . m_annotation = Env . save local_tpenv env ; <nl> - Aast . m_span = m . m_span ; <nl> - Aast . m_final = m . m_final ; <nl> - Aast . m_static = m . m_static ; <nl> - Aast . m_abstract = m . m_abstract ; <nl> - Aast . m_visibility = m . m_visibility ; <nl> - Aast . m_name = m . m_name ; <nl> - Aast . m_tparams = tparams ; <nl> - Aast . m_where_constraints = m . m_where_constraints ; <nl> - Aast . m_variadic = t_variadic ; <nl> - Aast . m_params = typed_params ; <nl> - Aast . m_fun_kind = m . m_fun_kind ; <nl> - Aast . m_user_attributes = user_attributes ; <nl> - Aast . m_ret = ( locl_ty , hint_of_type_hint m . m_ret ) ; <nl> - Aast . m_body = { Aast . fb_ast = tb ; fb_annotation = annotation } ; <nl> - Aast . m_external = m . m_external ; <nl> - Aast . m_doc_comment = m . m_doc_comment ; <nl> - } <nl> - in <nl> - let ( env , global_inference_env ) = Env . extract_global_inference_env env in <nl> - let _env = Env . log_env_change " method_def " initial_env env in <nl> - ( method_def , ( pos , global_inference_env ) ) ) <nl> - <nl> and typedef_def ctx typedef = <nl> let env = EnvFromDef . typedef_env ctx typedef in <nl> let tdecl = Env . get_typedef env ( snd typedef . t_name ) in <nl> mmm a / hphp / hack / src / typing / typing . mli <nl> ppp b / hphp / hack / src / typing / typing . mli <nl> val with_expr_hook : <nl> <nl> val debug_print_last_pos : ' a - > unit <nl> <nl> - val class_def : <nl> - Provider_context . t - > <nl> - Nast . class_ - > <nl> - ( Tast . class_ * Typing_inference_env . t_global_with_pos list ) option <nl> - <nl> val typedef_def : Provider_context . t - > Nast . typedef - > Tast . typedef <nl> <nl> val expr : <nl> val file_attributes : <nl> <nl> val type_param : <nl> Typing_env_types . env - > Nast . tparam - > Typing_env_types . env * Tast . tparam <nl> + <nl> + val check_shape_keys_validity : <nl> + Typing_env_types . env - > <nl> + Pos . t - > <nl> + Ast_defs . shape_field_name list - > <nl> + Typing_env_types . env <nl> mmm a / hphp / hack / src / typing / typing_check_service . ml <nl> ppp b / hphp / hack / src / typing / typing_check_service . ml <nl> let type_class ( ctx : Provider_context . t ) ( fn : Relative_path . t ) ( x : string ) : <nl> let class_ = Naming . class_ ctx cls in <nl> Nast_check . def ctx ( Aast . Class class_ ) ; <nl> let def_opt = <nl> - Typing . class_def ctx class_ <nl> + Typing_toplevel . class_def ctx class_ <nl> | > Option . map ~ f : ( fun ( c , global_tvenv ) - > <nl> ( Aast . Class c , global_tvenv ) ) <nl> in <nl> mmm a / hphp / hack / src / typing / typing_helpers . ml <nl> ppp b / hphp / hack / src / typing / typing_helpers . ml <nl> let set_tyvars_variance_in_callable env return_ty param_tys variadic_param_ty = <nl> env <nl> in <nl> env <nl> + <nl> + let reify_kind = function <nl> + | Erased - > Aast . Erased <nl> + | SoftReified - > Aast . SoftReified <nl> + | Reified - > Aast . Reified <nl> mmm a / hphp / hack / src / typing / typing_toplevel . ml <nl> ppp b / hphp / hack / src / typing / typing_toplevel . ml <nl> let get_decl_function_header env function_id = <nl> else <nl> None <nl> <nl> + and get_decl_method_header tcopt cls method_id ~ is_static = <nl> + let is_global_inference_on = TCO . global_inference tcopt in <nl> + if is_global_inference_on then <nl> + match Cls . get_any_method ~ is_static cls method_id with <nl> + | Some { ce_type = ( lazy ty ) ; _ } - > <nl> + begin <nl> + match get_node ty with <nl> + | Tfun fun_type - > Some fun_type <nl> + | _ - > None <nl> + end <nl> + | _ - > None <nl> + else <nl> + None <nl> + <nl> let enforce_param_not_disposable env param ty = <nl> if has_accept_disposable_attribute param then <nl> ( ) <nl> let enforce_param_not_disposable env param ty = <nl> | Some class_name - > Errors . invalid_disposable_hint p ( strip_ns class_name ) <nl> | None - > ( ) <nl> <nl> + ( * In strict mode , we force you to give a type declaration on a parameter * ) <nl> + ( * But the type checker is nice : it makes a suggestion : - ) * ) <nl> let check_param_has_hint env param ty is_code_error = <nl> let env = <nl> if is_code_error 4231 then <nl> let map_funcbody_annotation an = <nl> | Nast . Named - > Tast . NoUnsafeBlocks <nl> | Nast . Unnamed _ - > failwith " Should not map over unnamed body " <nl> <nl> - let fun_def ctx f : <nl> + let rec fun_def ctx f : <nl> ( Tast . fun_def * Typing_inference_env . t_global_with_pos ) option = <nl> let env = EnvFromDef . fun_env ctx f in <nl> with_timeout env f . f_name ~ do_ : ( fun env - > <nl> let fun_def ctx f : <nl> let ( _env , global_inference_env ) = Env . extract_global_inference_env env in <nl> ( fundef , ( pos , global_inference_env ) ) ) <nl> <nl> + and method_def env cls m = <nl> + with_timeout env m . m_name ~ do_ : ( fun env - > <nl> + let initial_env = env in <nl> + ( * reset the expression dependent display ids for each method body * ) <nl> + Reason . expr_display_id_map : = IMap . empty ; <nl> + let decl_header = <nl> + get_decl_method_header <nl> + ( Env . get_tcopt env ) <nl> + cls <nl> + ( snd m . m_name ) <nl> + ~ is_static : m . m_static <nl> + in <nl> + let pos = fst m . m_name in <nl> + let env = Env . open_tyvars env ( fst m . m_name ) in <nl> + let env = Env . reinitialize_locals env in <nl> + let env = Env . set_env_function_pos env pos in <nl> + let env = <nl> + Typing . attributes_check_def <nl> + env <nl> + SN . AttributeKinds . mthd <nl> + m . m_user_attributes <nl> + in <nl> + let reactive = <nl> + fun_reactivity env . decl_env m . m_user_attributes m . m_params <nl> + in <nl> + let mut = <nl> + match TUtils . fun_mutable m . m_user_attributes with <nl> + | None - > <nl> + ( * < < __Mutable > > is implicit on constructors * ) <nl> + if String . equal ( snd m . m_name ) SN . Members . __construct then <nl> + Some Param_borrowed_mutable <nl> + else <nl> + None <nl> + | x - > x <nl> + in <nl> + let env = Env . set_env_reactive env reactive in <nl> + let env = Env . set_fun_mutable env mut in <nl> + let ety_env = <nl> + { ( Phase . env_with_self env ) with from_class = Some CIstatic } <nl> + in <nl> + let m_tparams : decl_tparam list = <nl> + List . map <nl> + m . m_tparams <nl> + ~ f : ( Decl_hint . aast_tparam_to_decl_tparam env . decl_env ) <nl> + in <nl> + let ( env , constraints ) = <nl> + Phase . localize_generic_parameters_with_bounds env m_tparams ~ ety_env <nl> + in <nl> + let env = SubType . add_constraints pos env constraints in <nl> + let env = <nl> + Phase . localize_where_constraints ~ ety_env env m . m_where_constraints <nl> + in <nl> + let env = <nl> + if Env . is_static env then <nl> + env <nl> + else <nl> + Env . set_local env this ( Env . get_self env ) <nl> + in <nl> + let env = <nl> + match Env . get_self_class env with <nl> + | None - > env <nl> + | Some c - > <nl> + ( * Mark $ this as a using variable if it has a disposable type * ) <nl> + if Cls . is_disposable c then <nl> + Env . set_using_var env this <nl> + else <nl> + env <nl> + in <nl> + let env = Env . clear_params env in <nl> + let ( ret_decl_ty , params_decl_ty , variadicity_decl_ty ) = <nl> + merge_decl_header_with_hints <nl> + ~ params : m . m_params <nl> + ~ ret : m . m_ret <nl> + ~ variadic : m . m_variadic <nl> + decl_header <nl> + env <nl> + in <nl> + let env = Env . set_fn_kind env m . m_fun_kind in <nl> + let ( env , locl_ty ) = <nl> + match ret_decl_ty with <nl> + | None - > <nl> + ( env , Typing_return . make_default_return ~ is_method : true env m . m_name ) <nl> + | Some ret - > <nl> + ( * If a ' this ' type appears it needs to be compatible with the <nl> + * late static type <nl> + * ) <nl> + let ety_env = <nl> + { ( Phase . env_with_self env ) with from_class = Some CIstatic } <nl> + in <nl> + Typing_return . make_return_type ( Phase . localize ~ ety_env ) env ret <nl> + in <nl> + let return = <nl> + Typing_return . make_info <nl> + m . m_fun_kind <nl> + m . m_user_attributes <nl> + env <nl> + ~ is_explicit : ( Option . is_some ( hint_of_type_hint m . m_ret ) ) <nl> + locl_ty <nl> + ret_decl_ty <nl> + in <nl> + let ( env , param_tys ) = <nl> + List . zip_exn m . m_params params_decl_ty <nl> + | > List . map_env env ~ f : ( fun env ( param , hint ) - > <nl> + make_param_local_ty env hint param ) <nl> + in <nl> + let partial_callback = Partial . should_check_error ( Env . get_mode env ) in <nl> + let param_fn p t = check_param_has_hint env p t partial_callback in <nl> + List . iter2_exn ~ f : param_fn m . m_params param_tys ; <nl> + Typing_memoize . check_method env m ; <nl> + let ( env , typed_params ) = <nl> + List . map_env env ( List . zip_exn param_tys m . m_params ) Typing . bind_param <nl> + in <nl> + let ( env , t_variadic ) = <nl> + get_callable_variadicity <nl> + ~ partial_callback <nl> + ~ pos <nl> + env <nl> + variadicity_decl_ty <nl> + m . m_variadic <nl> + in <nl> + let env = <nl> + set_tyvars_variance_in_callable env locl_ty param_tys t_variadic <nl> + in <nl> + let nb = Nast . assert_named_body m . m_body in <nl> + let local_tpenv = Env . get_tpenv env in <nl> + let disable = <nl> + Naming_attributes . mem <nl> + SN . UserAttributes . uaDisableTypecheckerInternal <nl> + m . m_user_attributes <nl> + in <nl> + let ( env , tb ) = <nl> + Typing . fun_ <nl> + ~ abstract : m . m_abstract <nl> + ~ disable <nl> + env <nl> + return <nl> + pos <nl> + nb <nl> + m . m_fun_kind <nl> + in <nl> + ( * restore original method reactivity * ) <nl> + let env = Env . set_env_reactive env reactive in <nl> + let type_hint ' = <nl> + match hint_of_type_hint m . m_ret with <nl> + | None when String . equal ( snd m . m_name ) SN . Members . __construct - > <nl> + Some ( pos , Hprim Tvoid ) <nl> + | None - > <nl> + if partial_callback 4030 then Errors . expecting_return_type_hint pos ; <nl> + None <nl> + | Some hint - > <nl> + Typing_return . async_suggest_return m . m_fun_kind hint ( fst m . m_name ) ; <nl> + hint_of_type_hint m . m_ret <nl> + in <nl> + let m = { m with m_ret = ( fst m . m_ret , type_hint ' ) } in <nl> + let annotation = <nl> + if Nast . named_body_is_unsafe nb then <nl> + Tast . HasUnsafeBlocks <nl> + else <nl> + Tast . NoUnsafeBlocks <nl> + in <nl> + let ( env , tparams ) = List . map_env env m . m_tparams Typing . type_param in <nl> + let ( env , user_attributes ) = <nl> + List . map_env env m . m_user_attributes Typing . user_attribute <nl> + in <nl> + let env = <nl> + Typing_solver . close_tyvars_and_solve env Errors . bad_method_typevar <nl> + in <nl> + let env = <nl> + Typing_solver . solve_all_unsolved_tyvars env Errors . bad_method_typevar <nl> + in <nl> + let method_def = <nl> + { <nl> + Aast . m_annotation = Env . save local_tpenv env ; <nl> + Aast . m_span = m . m_span ; <nl> + Aast . m_final = m . m_final ; <nl> + Aast . m_static = m . m_static ; <nl> + Aast . m_abstract = m . m_abstract ; <nl> + Aast . m_visibility = m . m_visibility ; <nl> + Aast . m_name = m . m_name ; <nl> + Aast . m_tparams = tparams ; <nl> + Aast . m_where_constraints = m . m_where_constraints ; <nl> + Aast . m_variadic = t_variadic ; <nl> + Aast . m_params = typed_params ; <nl> + Aast . m_fun_kind = m . m_fun_kind ; <nl> + Aast . m_user_attributes = user_attributes ; <nl> + Aast . m_ret = ( locl_ty , hint_of_type_hint m . m_ret ) ; <nl> + Aast . m_body = { Aast . fb_ast = tb ; fb_annotation = annotation } ; <nl> + Aast . m_external = m . m_external ; <nl> + Aast . m_doc_comment = m . m_doc_comment ; <nl> + } <nl> + in <nl> + let ( env , global_inference_env ) = Env . extract_global_inference_env env in <nl> + let _env = Env . log_env_change " method_def " initial_env env in <nl> + ( method_def , ( pos , global_inference_env ) ) ) <nl> + <nl> + and check_parent env class_def class_type = <nl> + match Env . get_parent_class env with <nl> + | Some parent_type - > <nl> + let position = fst class_def . c_name in <nl> + if Cls . const class_type & & not ( Cls . const parent_type ) then <nl> + Errors . self_const_parent_not position ; <nl> + if Cls . final parent_type then <nl> + Errors . extend_final position ( Cls . pos parent_type ) ( Cls . name parent_type ) <nl> + | None - > ( ) <nl> + <nl> + and check_parent_sealed child_type parent_type = <nl> + match Cls . sealed_whitelist parent_type with <nl> + | None - > ( ) <nl> + | Some whitelist - > <nl> + let parent_pos = Cls . pos parent_type in <nl> + let parent_name = Cls . name parent_type in <nl> + let child_pos = Cls . pos child_type in <nl> + let child_name = Cls . name child_type in <nl> + let check kind action = <nl> + if not ( SSet . mem child_name whitelist ) then <nl> + Errors . extend_sealed child_pos parent_pos parent_name kind action <nl> + in <nl> + begin <nl> + match ( Cls . kind parent_type , Cls . kind child_type ) with <nl> + | ( Ast_defs . Cinterface , Ast_defs . Cinterface ) - > check " interface " " extend " <nl> + | ( Ast_defs . Cinterface , _ ) - > check " interface " " implement " <nl> + | ( Ast_defs . Ctrait , _ ) - > check " trait " " use " <nl> + | ( Ast_defs . Cabstract , _ ) <nl> + | ( Ast_defs . Cnormal , _ ) - > <nl> + check " class " " extend " <nl> + | ( Ast_defs . Cenum , _ ) - > ( ) <nl> + end <nl> + <nl> + and check_parents_sealed env child_def child_type = <nl> + let parents = <nl> + child_def . c_extends @ child_def . c_implements @ child_def . c_uses <nl> + in <nl> + List . iter parents ( function <nl> + | ( _ , Happly ( ( _ , name ) , _ ) ) - > <nl> + begin <nl> + match Env . get_class_dep env name with <nl> + | Some parent_type - > check_parent_sealed child_type parent_type <nl> + | None - > ( ) <nl> + end <nl> + | _ - > ( ) ) <nl> + <nl> + and check_const_trait_members pos env use_list = <nl> + let ( _ , trait , _ ) = Decl_utils . unwrap_class_hint use_list in <nl> + match Env . get_class env trait with <nl> + | Some c when Ast_defs . ( equal_class_kind ( Cls . kind c ) Ctrait ) - > <nl> + List . iter ( Cls . props c ) ( fun ( x , ce ) - > <nl> + if not ce . ce_const then Errors . trait_prop_const_class pos x ) <nl> + | _ - > ( ) <nl> + <nl> + let shallow_decl_enabled ( ctx : Provider_context . t ) : bool = <nl> + TypecheckerOptions . shallow_class_decl ctx . Provider_context . tcopt <nl> + <nl> + ( * If the current class inherits from classes that take type arguments , we need <nl> + * to check that the arguments provided are consistent with the constraints on <nl> + * the type parameters . * ) <nl> + let check_implements_tparaml ( env : env ) ht = <nl> + let ( _r , ( _ , c ) , paraml ) = TUtils . unwrap_class_type ht in <nl> + let class_ = Env . get_class_dep env c in <nl> + match class_ with <nl> + | None - > <nl> + ( * The class lives in PHP land * ) <nl> + env <nl> + | Some class_ - > <nl> + let subst = Inst . make_subst ( Cls . tparams class_ ) paraml in <nl> + fold2_shortest <nl> + ~ f : ( fun env t ty - > <nl> + let ty_pos = get_pos ty in <nl> + List . fold t . tp_constraints ~ init : env ~ f : ( fun env ( ck , cstr ) - > <nl> + ( * Constraint might contain uses of generic type parameters * ) <nl> + let cstr = Inst . instantiate subst cstr in <nl> + match ck with <nl> + | Ast_defs . Constraint_as - > <nl> + Type . sub_type_decl ty_pos Reason . URnone env ty cstr <nl> + | Ast_defs . Constraint_eq - > <nl> + ( * This code could well be unreachable , because we don ' t allow <nl> + * equality constraints on class generics . * ) <nl> + let env = Type . sub_type_decl ty_pos Reason . URnone env ty cstr in <nl> + let env = Type . sub_type_decl ty_pos Reason . URnone env cstr ty in <nl> + env <nl> + | Ast_defs . Constraint_super - > <nl> + Type . sub_type_decl ty_pos Reason . URnone env cstr ty ) ) <nl> + ~ init : env <nl> + ( Cls . tparams class_ ) <nl> + paraml <nl> + <nl> + let class_type_param env ct = <nl> + let ( env , tparam_list ) = <nl> + List . map_env env ct . c_tparam_list Typing . type_param <nl> + in <nl> + ( env , <nl> + { <nl> + Aast . c_tparam_list = tparam_list ; <nl> + Aast . c_tparam_constraints = <nl> + SMap . map ( Tuple . T2 . map_fst ~ f : reify_kind ) ct . c_tparam_constraints ; <nl> + } ) <nl> + <nl> + let rec class_def ctx c = <nl> + let env = EnvFromDef . class_env ctx c in <nl> + let tc = Env . get_class env ( snd c . c_name ) in <nl> + let env = Env . set_env_pessimize env in <nl> + Typing_helpers . add_decl_errors <nl> + Option . ( map tc ( fun tc - > value_exn ( Cls . decl_errors tc ) ) ) ; <nl> + let c = TNBody . class_meth_bodies ctx c in <nl> + NastCheck . class_ env c ; <nl> + NastInitCheck . class_ env c ; <nl> + match tc with <nl> + | None - > <nl> + ( * This can happen if there was an error during the declaration <nl> + * of the class . * ) <nl> + None <nl> + | Some tc - > <nl> + let env = Typing_requirements . check_class env tc in <nl> + if shallow_decl_enabled ctx then Typing_inheritance . check_class env tc ; <nl> + Some ( class_def_ env c tc ) <nl> + <nl> + and class_def_ env c tc = <nl> + let env = <nl> + let kind = <nl> + match c . c_kind with <nl> + | Ast_defs . Cenum - > SN . AttributeKinds . enum <nl> + | _ - > SN . AttributeKinds . cls <nl> + in <nl> + Typing . attributes_check_def env kind c . c_user_attributes <nl> + in <nl> + let ctx = Env . get_ctx env in <nl> + if <nl> + Ast_defs . ( equal_class_kind c . c_kind Cnormal ) <nl> + & & not ( shallow_decl_enabled ctx ) <nl> + then ( <nl> + ( * This check is only for eager mode . The same check is performed <nl> + * for shallow mode in Typing_inheritance * ) <nl> + let method_pos ~ is_static class_id meth_id = <nl> + let get_meth = <nl> + if is_static then <nl> + Decl_heap . StaticMethods . get <nl> + else <nl> + Decl_heap . Methods . get <nl> + in <nl> + match get_meth ( class_id , meth_id ) with <nl> + | Some { fe_pos ; _ } - > fe_pos <nl> + | None - > Pos . none <nl> + in <nl> + let check_override ~ is_static ( id , ce ) = <nl> + ( * ` ce_override ` is set in Decl when we determine that an <nl> + * override_per_trait error needs emit . This emission is deferred <nl> + * until Typing to ensure that this method has been added to <nl> + * Decl_heap * ) <nl> + if ce . ce_override then <nl> + let pos = method_pos ~ is_static ce . ce_origin id in <nl> + Errors . override_per_trait c . c_name id pos <nl> + in <nl> + List . iter ( Cls . methods tc ) ( check_override ~ is_static : false ) ; <nl> + List . iter ( Cls . smethods tc ) ( check_override ~ is_static : true ) <nl> + ) ; <nl> + let env = <nl> + { <nl> + env with <nl> + inside_ppl_class = <nl> + Naming_attributes . mem <nl> + SN . UserAttributes . uaProbabilisticModel <nl> + c . c_user_attributes ; <nl> + } <nl> + in <nl> + let ( pc , _ ) = c . c_name in <nl> + let impl = <nl> + List . map <nl> + ( c . c_extends @ c . c_implements @ c . c_uses ) <nl> + ( Decl_hint . hint env . decl_env ) <nl> + in <nl> + let c_tparam_list : decl_tparam list = <nl> + List . map <nl> + c . c_tparams . c_tparam_list <nl> + ~ f : ( Decl_hint . aast_tparam_to_decl_tparam env . decl_env ) <nl> + in <nl> + let ( env , constraints ) = <nl> + Phase . localize_generic_parameters_with_bounds <nl> + env <nl> + c_tparam_list <nl> + ~ ety_env : ( Phase . env_with_self env ) <nl> + in <nl> + let env = SubType . add_constraints ( fst c . c_name ) env constraints in <nl> + let env = <nl> + Phase . localize_where_constraints <nl> + ~ ety_env : ( Phase . env_with_self env ) <nl> + env <nl> + c . c_where_constraints <nl> + in <nl> + let env = <nl> + Phase . check_where_constraints <nl> + ~ in_class : true <nl> + ~ use_pos : pc <nl> + ~ definition_pos : pc <nl> + ~ ety_env : ( Phase . env_with_self env ) <nl> + env <nl> + ( Cls . where_constraints tc ) <nl> + in <nl> + Typing_variance . class_ ( Env . get_ctx env ) ( snd c . c_name ) tc impl ; <nl> + let env = List . fold impl ~ init : env ~ f : check_implements_tparaml in <nl> + let check_where_constraints env ht = <nl> + let ( _ , ( p , _ ) , _ ) = TUtils . unwrap_class_type ht in <nl> + let ( env , locl_ty ) = Phase . localize_with_self env ht in <nl> + match get_node ( TUtils . get_base_type env locl_ty ) with <nl> + | Tclass ( cls , _ , tyl ) - > <nl> + ( match Env . get_class env ( snd cls ) with <nl> + | Some cls when not ( List . is_empty ( Cls . where_constraints cls ) ) - > <nl> + let tc_tparams = Cls . tparams cls in <nl> + let ety_env = <nl> + { <nl> + ( Phase . env_with_self env ) with <nl> + substs = Subst . make_locl tc_tparams tyl ; <nl> + } <nl> + in <nl> + Phase . check_where_constraints <nl> + ~ in_class : true <nl> + ~ use_pos : pc <nl> + ~ definition_pos : p <nl> + ~ ety_env <nl> + env <nl> + ( Cls . where_constraints cls ) <nl> + | _ - > env ) <nl> + | _ - > env <nl> + in <nl> + let env = List . fold impl ~ init : env ~ f : check_where_constraints in <nl> + check_parent env c tc ; <nl> + check_parents_sealed env c tc ; <nl> + <nl> + let is_final = Cls . final tc in <nl> + if <nl> + ( Ast_defs . ( equal_class_kind ( Cls . kind tc ) Cnormal ) | | is_final ) <nl> + & & Cls . members_fully_known tc <nl> + then ( <nl> + check_extend_abstract_meth ~ is_final pc ( Cls . methods tc ) ; <nl> + ( match fst ( Cls . construct tc ) with <nl> + | Some constr - > <nl> + check_extend_abstract_meth ~ is_final pc [ ( SN . Members . __construct , constr ) ] <nl> + | None - > ( ) ) ; <nl> + check_extend_abstract_meth ~ is_final pc ( Cls . smethods tc ) ; <nl> + check_extend_abstract_prop ~ is_final pc ( Cls . sprops tc ) ; <nl> + check_extend_abstract_const ~ is_final pc ( Cls . consts tc ) ; <nl> + check_extend_abstract_typeconst ~ is_final pc ( Cls . typeconsts tc ) <nl> + ) ; <nl> + if Cls . const tc then List . iter c . c_uses ( check_const_trait_members pc env ) ; <nl> + let ( static_vars , vars ) = split_vars c in <nl> + List . iter static_vars ~ f : ( fun { cv_id = ( p , id ) ; _ } - > <nl> + check_static_class_element ( Cls . get_prop tc ) ~ elt_type : ` Property id p ) ; <nl> + List . iter vars ~ f : ( fun { cv_id = ( p , id ) ; _ } - > <nl> + check_dynamic_class_element ( Cls . get_sprop tc ) ~ elt_type : ` Property id p ) ; <nl> + let ( constructor , static_methods , methods ) = split_methods c in <nl> + List . iter static_methods ~ f : ( fun { m_name = ( p , id ) ; _ } - > <nl> + check_static_class_element ( Cls . get_method tc ) ~ elt_type : ` Method id p ) ; <nl> + List . iter methods ~ f : ( fun { m_name = ( p , id ) ; _ } - > <nl> + check_dynamic_class_element ( Cls . get_smethod tc ) ~ elt_type : ` Method id p ) ; <nl> + <nl> + ( * get a map of method names to list of traits from which they were removed * ) <nl> + let alist = <nl> + List . map c . c_method_redeclarations ~ f : ( fun m - > <nl> + let ( _ , name ) = m . mt_method in <nl> + let ( _ , trait , _ ) = Decl_utils . unwrap_class_hint m . mt_trait in <nl> + ( name , trait ) ) <nl> + in <nl> + let removals = <nl> + String . Map . of_alist_fold alist ~ init : [ ] ~ f : ( Fn . flip List . cons ) <nl> + in <nl> + let env = <nl> + List . fold ~ init : env impl ~ f : ( fun env - > <nl> + class_implements_type env c removals ) <nl> + in <nl> + let env = <nl> + List . fold <nl> + c . c_method_redeclarations <nl> + ~ init : env <nl> + ~ f : ( supertype_redeclared_method tc ) <nl> + in <nl> + if Cls . is_disposable tc then <nl> + List . iter <nl> + ( c . c_extends @ c . c_uses ) <nl> + ( Typing_disposable . enforce_is_disposable env ) ; <nl> + let ( env , typed_vars_and_global_inference_envs ) = <nl> + List . map_env env vars ( class_var_def ~ is_static : false tc ) <nl> + in <nl> + let ( typed_vars , vars_global_inference_envs ) = <nl> + List . unzip typed_vars_and_global_inference_envs <nl> + in <nl> + let typed_method_redeclarations = [ ] in <nl> + let ( typed_methods , methods_global_inference_envs ) = <nl> + List . filter_map methods ( method_def env tc ) | > List . unzip <nl> + in <nl> + let ( env , typed_typeconsts ) = List . map_env env c . c_typeconsts typeconst_def in <nl> + let ( env , consts ) = List . map_env env c . c_consts class_const_def in <nl> + let ( typed_consts , const_types ) = List . unzip consts in <nl> + let env = Typing_enum . enum_class_check env tc c . c_consts const_types in <nl> + let typed_constructor = class_constr_def env tc constructor in <nl> + let env = Env . set_static env in <nl> + let ( env , typed_static_vars_and_global_inference_envs ) = <nl> + List . map_env env static_vars ( class_var_def ~ is_static : true tc ) <nl> + in <nl> + let ( typed_static_vars , static_vars_global_inference_envs ) = <nl> + List . unzip typed_static_vars_and_global_inference_envs <nl> + in <nl> + let ( typed_static_methods , static_methods_global_inference_envs ) = <nl> + List . filter_map static_methods ( method_def env tc ) | > List . unzip <nl> + in <nl> + let ( env , file_attrs ) = Typing . file_attributes env c . c_file_attributes in <nl> + let ( methods , constr_global_inference_env ) = <nl> + match typed_constructor with <nl> + | None - > ( typed_static_methods @ typed_methods , [ ] ) <nl> + | Some ( m , global_inference_env ) - > <nl> + ( ( m : : typed_static_methods ) @ typed_methods , [ global_inference_env ] ) <nl> + in <nl> + let pu_enums = <nl> + try List . map c . c_pu_enums ~ f : ( pu_enum_def env ( snd c . c_name ) ) <nl> + with InvalidPocketUniverse - > [ ] <nl> + in <nl> + let ( env , tparams ) = class_type_param env c . c_tparams in <nl> + let ( env , user_attributes ) = <nl> + List . map_env env c . c_user_attributes Typing . user_attribute <nl> + in <nl> + let env = <nl> + Typing_solver . solve_all_unsolved_tyvars env Errors . bad_class_typevar <nl> + in <nl> + ( { <nl> + Aast . c_span = c . c_span ; <nl> + Aast . c_annotation = Env . save ( Env . get_tpenv env ) env ; <nl> + Aast . c_mode = c . c_mode ; <nl> + Aast . c_final = c . c_final ; <nl> + Aast . c_is_xhp = c . c_is_xhp ; <nl> + Aast . c_has_xhp_keyword = c . c_has_xhp_keyword ; <nl> + Aast . c_kind = c . c_kind ; <nl> + Aast . c_name = c . c_name ; <nl> + Aast . c_tparams = tparams ; <nl> + Aast . c_extends = c . c_extends ; <nl> + Aast . c_uses = c . c_uses ; <nl> + ( * c_use_as_alias and c_insteadof_alias are PHP features not supported <nl> + * in Hack but are required since we have runtime support for it <nl> + * ) <nl> + Aast . c_use_as_alias = [ ] ; <nl> + Aast . c_insteadof_alias = [ ] ; <nl> + Aast . c_method_redeclarations = typed_method_redeclarations ; <nl> + Aast . c_xhp_attr_uses = c . c_xhp_attr_uses ; <nl> + Aast . c_xhp_category = c . c_xhp_category ; <nl> + Aast . c_reqs = c . c_reqs ; <nl> + Aast . c_implements = c . c_implements ; <nl> + Aast . c_where_constraints = c . c_where_constraints ; <nl> + Aast . c_consts = typed_consts ; <nl> + Aast . c_typeconsts = typed_typeconsts ; <nl> + Aast . c_vars = typed_static_vars @ typed_vars ; <nl> + Aast . c_methods = methods ; <nl> + Aast . c_file_attributes = file_attrs ; <nl> + Aast . c_user_attributes = user_attributes ; <nl> + Aast . c_namespace = c . c_namespace ; <nl> + Aast . c_enum = c . c_enum ; <nl> + Aast . c_doc_comment = c . c_doc_comment ; <nl> + Aast . c_attributes = [ ] ; <nl> + Aast . c_xhp_children = c . c_xhp_children ; <nl> + Aast . c_xhp_attrs = [ ] ; <nl> + Aast . c_pu_enums = pu_enums ; <nl> + } , <nl> + methods_global_inference_envs <nl> + @ static_methods_global_inference_envs <nl> + @ constr_global_inference_env <nl> + @ static_vars_global_inference_envs <nl> + @ vars_global_inference_envs ) <nl> + <nl> + and check_dynamic_class_element get_static_elt element_name dyn_pos ~ elt_type = <nl> + ( * The non - static properties that we get passed do not start with ' $ ' , but the <nl> + static properties we want to look up do , so add it . * ) <nl> + let id = <nl> + match elt_type with <nl> + | ` Method - > element_name <nl> + | ` Property - > " $ " ^ element_name <nl> + in <nl> + match get_static_elt id with <nl> + | None - > ( ) <nl> + | Some static_element - > <nl> + let ( lazy ty ) = static_element . ce_type in <nl> + Errors . static_redeclared_as_dynamic <nl> + dyn_pos <nl> + ( get_pos ty ) <nl> + element_name <nl> + ~ elt_type <nl> + <nl> + and check_static_class_element get_dyn_elt element_name static_pos ~ elt_type = <nl> + ( * The static properties that we get passed in start with ' $ ' , but the <nl> + non - static properties we ' re matching against don ' t , so we need to detect <nl> + that and remove it if present . * ) <nl> + let element_name = String_utils . lstrip element_name " $ " in <nl> + match get_dyn_elt element_name with <nl> + | None - > ( ) <nl> + | Some dyn_element - > <nl> + let ( lazy ty ) = dyn_element . ce_type in <nl> + Errors . dynamic_redeclared_as_static <nl> + static_pos <nl> + ( get_pos ty ) <nl> + element_name <nl> + ~ elt_type <nl> + <nl> + and check_extend_abstract_meth ~ is_final p seq = <nl> + List . iter seq ( fun ( x , ce ) - > <nl> + match ce . ce_type with <nl> + | ( lazy ty ) when ce . ce_abstract & & is_fun ty - > <nl> + Errors . implement_abstract ~ is_final p ( get_pos ty ) " method " x <nl> + | _ - > ( ) ) <nl> + <nl> + and check_extend_abstract_prop ~ is_final p seq = <nl> + List . iter seq ( fun ( x , ce ) - > <nl> + if ce . ce_abstract then <nl> + let ce_pos = Lazy . force ce . ce_type | > get_pos in <nl> + Errors . implement_abstract ~ is_final p ce_pos " property " x ) <nl> + <nl> + ( * Type constants must be bound to a concrete type for non - abstract classes . <nl> + * ) <nl> + and check_extend_abstract_typeconst ~ is_final p seq = <nl> + List . iter seq ( fun ( x , tc ) - > <nl> + if Option . is_none tc . ttc_type then <nl> + Errors . implement_abstract <nl> + ~ is_final <nl> + p <nl> + ( fst tc . ttc_name ) <nl> + " type constant " <nl> + x ) <nl> + <nl> + and check_extend_abstract_const ~ is_final p seq = <nl> + List . iter seq ( fun ( x , cc ) - > <nl> + if cc . cc_abstract & & not cc . cc_synthesized then <nl> + let cc_pos = get_pos cc . cc_type in <nl> + Errors . implement_abstract ~ is_final p cc_pos " constant " x ) <nl> + <nl> + and get_decl_prop_ty env cls ~ is_static prop_id = <nl> + let is_global_inference_on = TCO . global_inference ( Env . get_tcopt env ) in <nl> + if is_global_inference_on then <nl> + let prop_opt = <nl> + if is_static then <nl> + ( * this is very ad - hoc , but this is how we do it in the decl - heap * ) <nl> + Cls . get_sprop cls ( " $ " ^ prop_id ) <nl> + else <nl> + Cls . get_prop cls prop_id <nl> + in <nl> + match prop_opt with <nl> + | None - > failwith " error : could not find property in decl heap " <nl> + | Some { ce_type ; _ } - > Some ( Lazy . force ce_type ) <nl> + else <nl> + None <nl> + <nl> + and typeconst_def <nl> + env <nl> + { <nl> + c_tconst_abstract ; <nl> + c_tconst_name = ( pos , _ ) as id ; <nl> + c_tconst_constraint ; <nl> + c_tconst_type = hint ; <nl> + c_tconst_user_attributes ; <nl> + c_tconst_span ; <nl> + c_tconst_doc_comment ; <nl> + } = <nl> + let ( env , cstr ) = opt Phase . localize_hint_with_self env c_tconst_constraint in <nl> + let ( env , ty ) = opt Phase . localize_hint_with_self env hint in <nl> + let check env t c = <nl> + Type . sub_type pos Reason . URtypeconst_cstr env t c Errors . unify_error <nl> + in <nl> + let env = Option . value ~ default : env @ @ Option . map2 ty cstr ~ f : ( check env ) in <nl> + let env = <nl> + match hint with <nl> + | Some ( pos , Hshape { nsi_field_map ; _ } ) - > <nl> + let get_name sfi = sfi . sfi_name in <nl> + Typing . check_shape_keys_validity <nl> + env <nl> + pos <nl> + ( List . map ~ f : get_name nsi_field_map ) <nl> + | _ - > env <nl> + in <nl> + let env = <nl> + Typing . attributes_check_def <nl> + env <nl> + SN . AttributeKinds . typeconst <nl> + c_tconst_user_attributes <nl> + in <nl> + let ( env , user_attributes ) = <nl> + List . map_env env c_tconst_user_attributes Typing . user_attribute <nl> + in <nl> + ( env , <nl> + { <nl> + Aast . c_tconst_abstract ; <nl> + Aast . c_tconst_name = id ; <nl> + Aast . c_tconst_constraint ; <nl> + Aast . c_tconst_type = hint ; <nl> + Aast . c_tconst_user_attributes = user_attributes ; <nl> + Aast . c_tconst_span ; <nl> + Aast . c_tconst_doc_comment ; <nl> + } ) <nl> + <nl> + and pu_enum_def <nl> + env <nl> + c_name <nl> + { pu_name ; pu_is_final ; pu_case_types ; pu_case_values ; pu_members ; _ } = <nl> + ( * What is a well - formed pocket universe ? <nl> + - pu_name is unique <nl> + - pu_case_types are well - formed if all names are unique <nl> + - pu_case_values are well - formed if all types are well - formed in an <nl> + environment where all names in pu_case_types are bound to abstract types <nl> + - pu_members are well - formed if : <nl> + - each name is unique <nl> + - all types are defined one and only one times in pum_types , and <nl> + are well - formed in an environment <nl> + - all values are defined one and only one times in pum_types , and <nl> + are correctly typed according to pum_types instances . <nl> + <nl> + Note : Structural correctness ( mostly uniqueness and exhaustivity ) <nl> + is checked during Nast check . <nl> + If the Nast check fails , this function might raise InvalidPocketUniverse , <nl> + that we silently ignore not to spam with duplicated errors . <nl> + <nl> + Here we check that all definitions are well - typed . <nl> + * ) <nl> + let pos = fst pu_name in <nl> + let cls = Decl_provider . get_class ( Env . get_ctx env ) c_name in <nl> + let pu_enum = <nl> + Option . bind cls ~ f : ( fun cls - > Cls . get_pu_enum cls ( snd pu_name ) ) <nl> + in <nl> + let make_ty_tparam ( sid , reified ) = <nl> + { <nl> + tp_variance = Ast_defs . Invariant ; <nl> + tp_name = sid ; <nl> + tp_constraints = [ ] ; <nl> + tp_reified = reified ; <nl> + tp_user_attributes = [ ] ; <nl> + } <nl> + in <nl> + let make_aast_tparam ( sid , hint ) = <nl> + let hint_ty = Decl_hint . hint env . decl_env hint in <nl> + { <nl> + tp_variance = Ast_defs . Invariant ; <nl> + tp_name = sid ; <nl> + tp_constraints = [ ( Ast_defs . Constraint_eq , hint_ty ) ] ; <nl> + tp_reified = Aast . Erased ; <nl> + tp_user_attributes = [ ] ; <nl> + } <nl> + in <nl> + let ( env , constraints ) = <nl> + let ( env , constraints ) = <nl> + Phase . localize_generic_parameters_with_bounds <nl> + env <nl> + ~ ety_env : ( Phase . env_with_self env ) <nl> + ( List . map ~ f : make_ty_tparam pu_case_types ) <nl> + in <nl> + let env = <nl> + List . fold pu_case_values ~ init : env ~ f : ( fun env ( _sid , hint ) - > <nl> + let ( env , _ty ) = Phase . localize_hint_with_self env hint in <nl> + env ) <nl> + in <nl> + ( env , constraints ) <nl> + in <nl> + let env = SubType . add_constraints pos env constraints in <nl> + let ( env , members ) = <nl> + let process_member env pum = <nl> + let ( env , cstrs ) = <nl> + let pum_types = List . map ~ f : make_aast_tparam pum . pum_types in <nl> + Phase . localize_generic_parameters_with_bounds <nl> + env <nl> + ~ ety_env : ( Phase . env_with_self env ) <nl> + pum_types <nl> + in <nl> + let env = SubType . add_constraints ( fst pum . pum_atom ) env cstrs in <nl> + let process_mapping env ( sid , map_expr ) = <nl> + let ( env , ty , expected ) = <nl> + let equal ( ( _ , s1 ) : sid ) ( ( _ , s2 ) : sid ) = String . equal s1 s2 in <nl> + let ( env , ty ) = <nl> + match List . Assoc . find ~ equal pu_case_values sid with <nl> + | None - > <nl> + ( ( * Check in parent hierarchy * ) <nl> + match pu_enum with <nl> + | None - > raise InvalidPocketUniverse <nl> + | Some pu_enum - > <nl> + ( match SMap . find_opt ( snd sid ) pu_enum . tpu_case_values with <nl> + | None - > raise InvalidPocketUniverse <nl> + | Some ( _ , decl_ty ) - > Phase . localize_with_self env decl_ty ) ) <nl> + | Some hint - > Phase . localize_hint_with_self env hint <nl> + in <nl> + ( env , ty , Some ( ExpectedTy . make ( fst sid ) Reason . URhint ty ) ) <nl> + in <nl> + let ( env , expr , ty ' ) = Typing . expr ? expected env map_expr in <nl> + let env = <nl> + Typing_ops . sub_type <nl> + ( fst sid ) <nl> + Reason . URhint <nl> + env <nl> + ty ' <nl> + ty <nl> + Errors . pocket_universes_typing <nl> + in <nl> + ( env , ( sid , expr ) ) <nl> + in <nl> + let ( env , pum_exprs ) = <nl> + List . fold_map pum . pum_exprs ~ init : env ~ f : process_mapping <nl> + in <nl> + let members = <nl> + { <nl> + Aast . pum_atom = pum . pum_atom ; <nl> + Aast . pum_types = pum . pum_types ; <nl> + Aast . pum_exprs ; <nl> + } <nl> + in <nl> + ( env , members ) <nl> + in <nl> + List . fold_map ~ init : env ~ f : process_member pu_members <nl> + in <nl> + let local_tpenv = Env . get_tpenv env in <nl> + let local_tpenv = <nl> + List . fold <nl> + ~ init : local_tpenv <nl> + ~ f : ( fun tpenv ( ( _ , name ) , reified ) - > <nl> + let tpinfo = <nl> + TPEnv . <nl> + { <nl> + lower_bounds = TySet . empty ; <nl> + upper_bounds = TySet . empty ; <nl> + reified ; <nl> + enforceable = false ; <nl> + ( * TODO ( T35357243 ) improve to support that * ) <nl> + newable = false ( * TODO ( T35357243 ) improve to support that * ) ; <nl> + } <nl> + in <nl> + TPEnv . add name tpinfo tpenv ) <nl> + pu_case_types <nl> + in <nl> + { <nl> + Aast . pu_annotation = Env . save local_tpenv env ; <nl> + Aast . pu_name ; <nl> + Aast . pu_is_final ; <nl> + Aast . pu_case_types ; <nl> + Aast . pu_case_values ; <nl> + Aast . pu_members = members ; <nl> + } <nl> + <nl> + and class_const_def env cc = <nl> + let { cc_type = h ; cc_id = id ; cc_expr = e ; _ } = cc in <nl> + let ( env , ty , opt_expected ) = <nl> + match h with <nl> + | None - > <nl> + let ( env , ty ) = Env . fresh_type env ( fst id ) in <nl> + ( env , MakeType . unenforced ty , None ) <nl> + | Some h - > <nl> + let ty = Decl_hint . hint env . decl_env h in <nl> + let ty = Typing_enforceability . compute_enforced_ty env ty in <nl> + let ( env , ty ) = Phase . localize_possibly_enforced_with_self env ty in <nl> + ( env , <nl> + ty , <nl> + Some ( ExpectedTy . make_and_allow_coercion ( fst id ) Reason . URhint ty ) ) <nl> + in <nl> + let ( env , eopt , ty ) = <nl> + match e with <nl> + | Some e - > <nl> + let ( env , te , ty ' ) = Typing . expr ? expected : opt_expected env e in <nl> + let env = <nl> + Typing_coercion . coerce_type <nl> + ( fst id ) <nl> + Reason . URhint <nl> + env <nl> + ty ' <nl> + ty <nl> + Errors . class_constant_value_does_not_match_hint <nl> + in <nl> + ( env , Some te , ty ' ) <nl> + | None - > ( env , None , ty . et_type ) <nl> + in <nl> + ( env , <nl> + ( { <nl> + Aast . cc_type = cc . cc_type ; <nl> + Aast . cc_id = cc . cc_id ; <nl> + Aast . cc_expr = eopt ; <nl> + Aast . cc_doc_comment = cc . cc_doc_comment ; <nl> + } , <nl> + ty ) ) <nl> + <nl> + and class_constr_def env cls constructor = <nl> + let env = { env with inside_constructor = true } in <nl> + Option . bind constructor ( method_def env cls ) <nl> + <nl> + and class_implements_type env c1 removals ctype2 = <nl> + let params = <nl> + List . map c1 . c_tparams . c_tparam_list ( fun { tp_name = ( p , s ) ; _ } - > <nl> + mk ( Reason . Rwitness p , Tgeneric s ) ) <nl> + in <nl> + let r = Reason . Rwitness ( fst c1 . c_name ) in <nl> + let ctype1 = mk ( r , Tapply ( c1 . c_name , params ) ) in <nl> + Typing_extends . check_implements env removals ctype2 ctype1 <nl> + <nl> + ( * Type - check a property declaration , with optional initializer * ) <nl> + and class_var_def ~ is_static cls env cv = <nl> + ( * First pick up and localize the hint if it exists * ) <nl> + let decl_cty = <nl> + merge_hint_with_decl_hint <nl> + env <nl> + ( hint_of_type_hint cv . cv_type ) <nl> + ( get_decl_prop_ty env cls ~ is_static ( snd cv . cv_id ) ) <nl> + in <nl> + let ( env , expected ) = <nl> + match decl_cty with <nl> + | None - > ( env , None ) <nl> + | Some decl_cty - > <nl> + let decl_cty = Typing_enforceability . compute_enforced_ty env decl_cty in <nl> + let ( env , cty ) = <nl> + Phase . localize_possibly_enforced_with_self env decl_cty <nl> + in <nl> + let expected = <nl> + Some ( ExpectedTy . make_and_allow_coercion cv . cv_span Reason . URhint cty ) <nl> + in <nl> + ( env , expected ) <nl> + in <nl> + ( * Next check the expression , passing in expected type if present * ) <nl> + let ( env , typed_cv_expr ) = <nl> + match cv . cv_expr with <nl> + | None - > ( env , None ) <nl> + | Some e - > <nl> + let ( env , te , ty ) = Typing . expr ? expected env e in <nl> + ( * Check that the inferred type is a subtype of the expected type . <nl> + * Eventually this will be the responsibility of ` expr ` <nl> + * ) <nl> + let env = <nl> + match expected with <nl> + | None - > env <nl> + | Some ExpectedTy . { pos = p ; reason = ur ; ty = cty } - > <nl> + Typing_coercion . coerce_type <nl> + p <nl> + ur <nl> + env <nl> + ty <nl> + cty <nl> + Errors . class_property_initializer_type_does_not_match_hint <nl> + in <nl> + ( env , Some te ) <nl> + in <nl> + let env = <nl> + if is_static then <nl> + Typing . attributes_check_def <nl> + env <nl> + SN . AttributeKinds . staticProperty <nl> + cv . cv_user_attributes <nl> + else <nl> + Typing . attributes_check_def <nl> + env <nl> + SN . AttributeKinds . instProperty <nl> + cv . cv_user_attributes <nl> + in <nl> + let ( env , user_attributes ) = <nl> + List . map_env env cv . cv_user_attributes Typing . user_attribute <nl> + in <nl> + if <nl> + Option . is_none ( hint_of_type_hint cv . cv_type ) <nl> + & & Partial . should_check_error ( Env . get_mode env ) 2001 <nl> + then <nl> + Errors . prop_without_typehint <nl> + ( string_of_visibility cv . cv_visibility ) <nl> + cv . cv_id ; <nl> + let ( env , global_inference_env ) = Env . extract_global_inference_env env in <nl> + let cv_type = <nl> + match expected with <nl> + | Some expected - > <nl> + ( expected . ExpectedTy . ty . et_type , hint_of_type_hint cv . cv_type ) <nl> + | None - > Tast . dummy_type_hint ( hint_of_type_hint cv . cv_type ) <nl> + in <nl> + ( env , <nl> + ( { <nl> + Aast . cv_final = cv . cv_final ; <nl> + Aast . cv_xhp_attr = cv . cv_xhp_attr ; <nl> + Aast . cv_abstract = cv . cv_abstract ; <nl> + Aast . cv_visibility = cv . cv_visibility ; <nl> + Aast . cv_type ; <nl> + Aast . cv_id = cv . cv_id ; <nl> + Aast . cv_expr = typed_cv_expr ; <nl> + Aast . cv_user_attributes = user_attributes ; <nl> + Aast . cv_is_promoted_variadic = cv . cv_is_promoted_variadic ; <nl> + Aast . cv_doc_comment = cv . cv_doc_comment ; <nl> + ( * Can make None to save space * ) <nl> + Aast . cv_is_static = is_static ; <nl> + Aast . cv_span = cv . cv_span ; <nl> + } , <nl> + ( cv . cv_span , global_inference_env ) ) ) <nl> + <nl> + and supertype_redeclared_method tc env m = <nl> + let ( pos , name ) = m . mt_name in <nl> + let get_method = <nl> + if m . mt_static then <nl> + Env . get_static_member <nl> + else <nl> + Env . get_member <nl> + in <nl> + let class_member_opt = get_method true env tc name in <nl> + let ( _ , trait , _ ) = Decl_utils . unwrap_class_hint m . mt_trait in <nl> + let ( _ , trait_method ) = m . mt_method in <nl> + Option . ( <nl> + let trait_member_opt = <nl> + Env . get_class env trait > > = fun trait_tc - > <nl> + get_method true env trait_tc trait_method <nl> + in <nl> + map2 trait_member_opt class_member_opt ~ f : ( fun trait_member class_member - > <nl> + let ( ( lazy ty_child ) , ( lazy ty_parent ) ) = <nl> + ( trait_member . ce_type , class_member . ce_type ) <nl> + in <nl> + match ( deref ty_child , deref ty_parent ) with <nl> + | ( ( r_child , Tfun ft_child ) , ( r_parent , Tfun ft_parent ) ) - > <nl> + let ety_env = Phase . env_with_self env ~ quiet : true in <nl> + let ( env , ft_child ) = <nl> + Phase . localize_ft <nl> + ~ ety_env <nl> + ~ def_pos : ( Reason . to_pos r_child ) <nl> + env <nl> + ft_child <nl> + in <nl> + let ( env , ft_parent ) = <nl> + Phase . localize_ft <nl> + ~ ety_env <nl> + ~ def_pos : ( Reason . to_pos r_parent ) <nl> + env <nl> + ft_parent <nl> + in <nl> + Typing_subtype . ( <nl> + subtype_method <nl> + ~ check_return : true <nl> + ~ extra_info : <nl> + { method_info = None ; class_ty = None ; parent_class_ty = None } <nl> + env <nl> + r_child <nl> + ft_child <nl> + r_parent <nl> + ft_parent ) <nl> + ( fun ? code : _ errorl - > <nl> + Errors . bad_method_override pos name errorl Errors . unify_error ) <nl> + | _ - > env ) <nl> + | > Option . value ~ default : env ) <nl> + <nl> let gconst_def ctx cst = <nl> let env = EnvFromDef . gconst_env ctx cst in <nl> let env = Env . set_env_pessimize env in <nl> let nast_to_tast_gienv ~ ( do_tast_checks : bool ) ctx nast : <nl> | Typedef td - > ( Aast . Typedef ( Typing . typedef_def ctx td ) , [ ] ) <nl> | Class c - > <nl> begin <nl> - match Typing . class_def ctx c with <nl> + match class_def ctx c with <nl> | Some ( c , envs ) - > ( Aast . Class c , envs ) <nl> | None - > <nl> failwith <nl> mmm a / hphp / hack / src / typing / typing_toplevel . mli <nl> ppp b / hphp / hack / src / typing / typing_toplevel . mli <nl> <nl> * <nl> * ) <nl> <nl> + val class_def : <nl> + Provider_context . t - > <nl> + Nast . class_ - > <nl> + ( Tast . class_ * Typing_inference_env . t_global_with_pos list ) option <nl> + <nl> val fun_def : <nl> Provider_context . t - > <nl> Nast . fun_ - > <nl>
Move method_def out of typing . ml
facebook/hhvm
a648e58ae32b3c4c3cc3587256b314cfc6fa19ed
2020-03-04T09:51:46Z
mmm a / scene / resources / audio_stream_sample . cpp <nl> ppp b / scene / resources / audio_stream_sample . cpp <nl> void AudioStreamPlaybackSample : : mix ( AudioFrame * p_buffer , float p_rate_scale , in <nl> sign = - 1 ; <nl> } <nl> <nl> - float base_rate = AudioServer : : get_singleton ( ) - > get_mix_rate ( ) ; <nl> + float global_rate_scale = AudioServer : : get_singleton ( ) - > get_global_rate_scale ( ) ; <nl> + float base_rate = AudioServer : : get_singleton ( ) - > get_mix_rate ( ) * global_rate_scale ; <nl> float srate = base - > mix_rate ; <nl> srate * = p_rate_scale ; <nl> float fincrement = srate / base_rate ; <nl>
Merge pull request from YeldhamDev / rate_scale_wav_fix
godotengine/godot
d105c718fdb776d1b94889fdbdabde1191390af6
2020-11-16T14:52:48Z
mmm a / scripting / javascript / bindings / generated <nl> ppp b / scripting / javascript / bindings / generated <nl> @ @ - 1 + 1 @ @ <nl> - Subproject commit 855e34a62356888e2fb129f6128b735b2a570ab3 <nl> + Subproject commit 2c7340c664991425acc3c24f5f8f74ab599607ef <nl>
cocos2dxmatoMac - mini : updating submodule reference to latest autogenerated bindings
cocos2d/cocos2d-x
5efdb93ef737b5a6fd0a374a4ae96a8a96ca196a
2012-11-06T02:12:52Z
new file mode 100644 <nl> index 0000000000 . . 470846e30b <nl> mmm / dev / null <nl> ppp b / code / sorting / src / postmans_sort / postmans_sort . cpp <nl> <nl> + # include < stdio . h > <nl> + void arrange ( int , int ) ; <nl> + int array [ 100 ] , array1 [ 100 ] ; <nl> + int i , j , temp , max , count , maxdigits = 0 , c = 0 ; <nl> + <nl> + int main ( ) <nl> + { <nl> + int t1 , t2 , k , t , n = 1 ; <nl> + printf ( " Enter size of array : " ) ; <nl> + scanf ( " % d " , & count ) ; <nl> + printf ( " Enter elements into array : " ) ; <nl> + / / inputing array elements <nl> + for ( i = 0 ; i < count ; i + + ) <nl> + { <nl> + scanf ( " % d " , & array [ i ] ) ; <nl> + array1 [ i ] = array [ i ] ; <nl> + } <nl> + / / determining significant digits in all the elements <nl> + for ( i = 0 ; i < count ; i + + ) <nl> + { <nl> + t = array [ i ] ; <nl> + while ( t > 0 ) <nl> + { <nl> + c + + ; <nl> + t = t / 10 ; <nl> + } <nl> + / / maximium significant digits <nl> + if ( maxdigits < c ) <nl> + maxdigits = c ; <nl> + c = 0 ; <nl> + } <nl> + / / setting the base <nl> + while ( - - maxdigits ) <nl> + n = n * 10 ; <nl> + <nl> + / / elements arranged on the basis of MSD <nl> + for ( i = 0 ; i < count ; i + + ) <nl> + { <nl> + max = array [ i ] / n ; <nl> + t = i ; <nl> + for ( j = i + 1 ; j < count ; j + + ) <nl> + { <nl> + if ( max > ( array [ j ] / n ) ) <nl> + { <nl> + max = array [ j ] / n ; <nl> + t = j ; <nl> + } <nl> + } <nl> + temp = array1 [ t ] ; <nl> + array1 [ t ] = array1 [ i ] ; <nl> + array1 [ i ] = temp ; <nl> + temp = array [ t ] ; <nl> + array [ t ] = array [ i ] ; <nl> + array [ i ] = temp ; <nl> + } <nl> + / / elements arranged according to the next MSD <nl> + while ( n > = 1 ) <nl> + { <nl> + for ( i = 0 ; i < count ; ) <nl> + { <nl> + t1 = array [ i ] / n ; <nl> + for ( j = i + 1 ; t1 = = ( array [ j ] / n ) ; j + + ) ; <nl> + arrange ( i , j ) ; <nl> + i = j ; <nl> + } <nl> + n = n / 10 ; <nl> + } <nl> + printf ( " \ nSorted Array ( Postman sort ) : " ) ; <nl> + for ( i = 0 ; i < count ; i + + ) <nl> + printf ( " % d " , array1 [ i ] ) ; <nl> + printf ( " \ n " ) ; <nl> + return 0 ; <nl> + } <nl> + / / function to arrange the intergers having same bases <nl> + void arrange ( int k , int n ) <nl> + { <nl> + for ( i = k ; i < n - 1 ; i + + ) <nl> + { <nl> + for ( j = i + 1 ; j < n ; j + + ) <nl> + { <nl> + if ( array1 [ i ] > array1 [ j ] ) <nl> + { <nl> + temp = array1 [ i ] ; <nl> + array1 [ i ] = array1 [ j ] ; <nl> + array1 [ j ] = temp ; <nl> + temp = ( array [ i ] % 10 ) ; <nl> + array [ i ] = ( array [ j ] % 10 ) ; <nl> + array [ j ] = temp ; <nl> + } <nl> + } <nl> + } <nl> + } <nl> + <nl>
postman sort cpp code added
OpenGenus/cosmos
32e4eaa6a958c8f5aace498fa3b1b4f80594e5af
2020-05-29T15:09:03Z
new file mode 100644 <nl> index 00000000000 . . 38a980e8094 <nl> Binary files / dev / null and b / docs / graph . png differ <nl> Binary files a / docs / paper . pdf and b / docs / paper . pdf differ <nl> mmm a / docs / paper . tex <nl> ppp b / docs / paper . tex <nl> <nl> - \ documentclass [ 11pt ] { proc } <nl> - % \ documentclass [ preprint , 10pt ] { sigplanconf } <nl> + % \ documentclass [ 11pt ] { proc } <nl> + \ documentclass [ preprint , 10pt ] { sigplanconf } <nl> <nl> \ usepackage { amsmath } <nl> \ usepackage { url } <nl> + \ usepackage { graphicx } <nl> <nl> \ begin { document } <nl> <nl> - % \ conferenceinfo { Splash ' 11 } { ? ? - 2011 , Portland . } <nl> - % \ copyrightyear { 2011 } <nl> - % \ copyrightdata { [ to be supplied ] } <nl> + \ title { Emscripten : An LLVM - to - JavaScript Compiler } <nl> + \ conferenceinfo { Splash ' 11 } { ? ? - 2011 , Portland . } <nl> + \ copyrightyear { 2011 } <nl> + \ copyrightdata { [ to be supplied ] } <nl> + \ titlebanner { } % These are ignored unless <nl> + \ preprintfooter { } % ' preprint ' option specified . <nl> + \ authorinfo { Alon Zakai } <nl> + { Mozilla } <nl> + { azakai @ mozilla . com } <nl> <nl> - % \ titlebanner { } % These are ignored unless <nl> - % \ preprintfooter { ( C ) 2011 Alon Zakai , Creative Commons BY - SA Licensed } % ' preprint ' option specified . <nl> + \ maketitle <nl> <nl> - \ title { Emscripten : An LLVM - to - JavaScript Compiler } <nl> + % \ title { Emscripten : An LLVM - to - JavaScript Compiler } <nl> % \ subtitle { } <nl> - <nl> % \ authorinfo { Alon Zakai } <nl> % { Mozilla } <nl> % { azakai @ mozilla . com } <nl> - <nl> - \ author { Alon Zakai \ \ Mozilla \ \ \ url { azakai @ mozilla . com } } <nl> - <nl> - \ maketitle <nl> + % \ author { Alon Zakai \ \ Mozilla \ \ \ url { azakai @ mozilla . com } } <nl> + % \ maketitle <nl> <nl> \ begin { abstract } <nl> We present Emscripten , an LLVM - to - JavaScript compiler . Emscripten compiles <nl> <nl> <nl> \ bigskip <nl> <nl> - \ copyright 2011 Alon Zakai . License : Creative Commons Attribution - ShareAlike ( CC BY - SA ) , \ url { http : / / creativecommons . org / licenses / by - sa / 3 . 0 / } <nl> + % \ copyright 2011 Alon Zakai . License : Creative Commons Attribution - ShareAlike ( CC BY - SA ) , \ url { http : / / creativecommons . org / licenses / by - sa / 3 . 0 / } <nl> <nl> \ section { Introduction } <nl> <nl> \ section { Introduction } <nl> example , there is currently no frontend for Python , however <nl> it is possible to compile CPython - - the standard implementation of <nl> Python , written in C - - into JavaScript , and run Python code on that <nl> - ( see Section ~ \ ref { sec : python } ) . <nl> + ( see Section ~ \ ref { sec : examples } ) . <nl> \ end { itemize } <nl> <nl> From a technical standpoint , one challenge in designing and implementing <nl> \ section { Introduction } <nl> on the web . <nl> \ end { itemize } <nl> <nl> - XXX The remainder of this paper is structured as follows . In Section 2 we <nl> - describe , from a high level , the approach taken to compiling LLVM assembly into JavaScript . <nl> - In Section 3 we describe the workings of Emscripten on a lower , more <nl> - concrete level . <nl> - In Section ~ \ ref { sec : realworldcode } we describe Emscripten ' s <nl> - approach to achieving good compatibility with existing real - world code , while <nl> - still achieving good performance . <nl> - In Section 4 we give an overview of some uses of <nl> - Emscripten . In Section 5 we summarize and give directions for future <nl> - work on Emscripten and uses of it . <nl> + The remainder of this paper is structured as follows . In Section ~ \ ref { sec : compapp } we <nl> + describe the approach Emscripten takes to compiling LLVM assembly into JavaScript , <nl> + and show some benchmark data . <nl> + In Section ~ \ ref { sec : emarch } we describe Emscripten ' s internal design and in <nl> + particular elaborate on the Relooper algorithm . <nl> + In Section ~ \ ref { sec : examples } we give several example uses of <nl> + Emscripten . In Section ~ \ ref { sec : summary } we summarize and give directions for future <nl> + work . <nl> <nl> \ section { Compilation Approach } <nl> + \ label { sec : compapp } <nl> <nl> Let us begin by considering what the challenge is , when we want to compile LLVM assembly <nl> into JavaScript . Assume we are given the <nl> \ section { Compilation Approach } <nl> \ end { itemize } <nl> <nl> \ subsection { Performance } <nl> + \ label { sec : perf } <nl> <nl> In this section we will deal with several topics regarding <nl> Emscripten ' s approach to generating high - performance JavaScript code . <nl> \ subsubsection { Emulating Code Semantics } <nl> practice the procedure above appears to work quite well , and can result in code that <nl> runs very significantly faster . <nl> <nl> - \ subsubsection { Code Optimizations } <nl> + \ subsubsection { Emscripten Code Optimizations } <nl> + \ label { sec : codeopt } <nl> <nl> When comparing the example program from page ~ \ pageref { code : example } , <nl> the generated code was fairly complicated <nl> \ subsubsection { Code Optimizations } <nl> explicitly available to Emscripten . <nl> <nl> \ subsection { Benchmarks } <nl> + \ label { sec : benchmarks } <nl> <nl> We will now take a look at some performance benchmarks : <nl> <nl> \ subsection { Benchmarks } <nl> Compiler . <nl> <nl> \ section { Emscripten ' s Architecture } <nl> + \ label { sec : emarch } <nl> <nl> In the previous section we saw a general overview of Emscripten ' s approach <nl> to compiling LLVM assembly into JavaScript . We will now get into more detail <nl> \ section { Emscripten ' s Architecture } <nl> \ end { itemize } <nl> <nl> \ subsection { The Runtime Environment } <nl> + \ label { sec : runtime } <nl> <nl> Code generated from Emscripten is meant to run in a JavaScript engine , <nl> typically in a web browser . This has implications for the kind of <nl> \ subsection { The Relooper : Recreating high - level loop structures } <nl> <nl> For example , the LLVM assembly on page ~ \ pageref { code : examplellvm } has the following block <nl> structure : <nl> - \ begin { verbatim } <nl> - / mmmmmmmmm - - \ <nl> - | | <nl> - V | <nl> - ENTRY - - > 2 - - > 5 - - > 9 <nl> - | <nl> - V <nl> - 12 <nl> - \ end { verbatim } <nl> + <nl> + \ includegraphics [ width = 80mm ] { graph . png } <nl> + <nl> In this simple example , it is fairly straightforward to see that a natural way to implement it <nl> using normal loop structures is <nl> \ begin { verbatim } <nl> \ subsection { The Relooper : Recreating high - level loop structures } <nl> construction to more natural JavaScript code flow structures . ) <nl> <nl> \ section { Example Uses } <nl> + \ label { sec : examples } <nl> <nl> Emscripten has been run successfully on several real - world codebases . We present <nl> some examples here to give an idea of the various opportunities made possible <nl> \ section { Example Uses } <nl> CPython itself - - the standard , reference implementation of Python - - and <nl> run that on the web , which allows running standard Python code . An online <nl> demo is available at \ url { http : / / syntensity . com / static / python . html } . <nl> + Another example of a language runtime that Emscripten can convert to run <nl> + on the web is Lua , an online demo is available at \ url { http : / / syntensity . com / static / lua . html } . <nl> \ item \ textbf { Poppler and FreeType } : Poppler \ footnote { \ url { http : / / poppler . freedesktop . org / } } is an open source PDF <nl> rendering library . In combination with FreeType \ footnote { \ url { http : / / www . freetype . org / } } , an open source font <nl> engine , it can be used to render PDF files . By compiling it with Emscripten , <nl> \ section { Example Uses } <nl> time - consuming manual conversion of C + + to Java and then to JavaScript , and consequently , <nl> the latest Bullet code can be run in JavaScript and not an earlier version ( JBullet lags <nl> several versions behind the latest Bullet release ) . <nl> - \ item \ textbf { Lua } : XXX <nl> \ end { itemize } <nl> <nl> \ section { Summary } <nl> + \ label { sec : summary } <nl> <nl> We presented Emscripten , an LLVM - to - JavaScript compiler , which opens up <nl> numerous opportunities for running code written in languages other <nl> \ section { Summary } <nl> % \ section { Appendix Title } <nl> % This is the text of the appendix , if you need one . <nl> <nl> - % \ acks <nl> + \ acks <nl> <nl> Thank you to the following people : Brian Crowder ( multithreading ) , Robert O ' Callahan ( JIT into JS ) , add people that contributed <nl> <nl> - % TODO : Acknowledgments <nl> + % TODO : Acknowledgments XXX <nl> <nl> \ bibliographystyle { abbrvnat } <nl> <nl> % The bibliography should be embedded for final submission . <nl> <nl> \ begin { thebibliography } { } <nl> - % \ softraggedright <nl> + \ softraggedright <nl> <nl> \ bibitem [ SOME ~ REF et ~ al . ( 2009 ) Someone , Another ] { someone02 } <nl> A . B . Someone , and X . Y . Another . . . . reference text . . . <nl> <nl> - \ bibitem [ Ashkenas ] { ashkenas } Jeremy Ashkenas ' list of languages that compile to JavaScript \ url { https : / / github . com / jashkenas / coffee - script / wiki / List - of - languages - that - compile - to - JS } <nl> + \ bibitem { ashkenas } <nl> + Jeremy Ashkenas ' list of languages that compile to JavaScript \ url { https : / / github . com / jashkenas / coffee - script / wiki / List - of - languages - that - compile - to - JS } <nl> + <nl> \ bibitem [ Closure Compiler ] { closure } <nl> Google , Inc . \ url { http : / / code . google . com / closure / compiler / } <nl> + <nl> \ bibitem [ Google Web Toolkit ] { gwt } \ url { http : / / code . google . com / webtoolkit / } <nl> + <nl> \ bibitem [ Low Level Virtual Machine ] { llvm } \ url { http : / / llvm . org / } <nl> + <nl> \ bibitem [ newlib ] { newlib } <nl> Red Hat , Inc . \ url { http : / / sourceware . org / newlib / } <nl> + <nl> \ bibitem [ Pyjamas ] { pyjamas } \ url { http : / / pyjs . org / } <nl> + <nl> \ bibitem [ Yee et ~ al . ( 2009 ) ] { nacl } B . Yee , D . Sehr , G . Dardyk , J . B . Chen , R . Muth , T . Ormandy , S . <nl> Okasaka , N . Narula , and N . Fullagar . Native Client : A Sandbox for <nl> Portable , Untrusted x86 Native Code . In IEEE Symposium on <nl> Security and Privacy , May 2009 . <nl> + <nl> \ bibitem [ PNaCl ] { pnacl } \ url { nativeclient . googlecode . com / svn / data / site / pnacl . pdf } <nl> + <nl> \ end { thebibliography } <nl> <nl> \ end { document } <nl>
paper update
emscripten-core/emscripten
07b55a07510f5389cc6fc97b10d3af91c62d9ad8
2011-04-03T01:28:07Z
mmm a / include / grpcpp / server_builder_impl . h <nl> ppp b / include / grpcpp / server_builder_impl . h <nl> <nl> # include < grpcpp / impl / codegen / server_interceptor . h > <nl> # include < grpcpp / impl / server_builder_option . h > <nl> # include < grpcpp / impl / server_builder_plugin . h > <nl> - # include < grpcpp / support / config . h > <nl> # include < grpcpp / server . h > <nl> + # include < grpcpp / support / config . h > <nl> <nl> struct grpc_resource_quota ; <nl> <nl>
Fix clang script errors
grpc/grpc
991409798c2c8e3d8d3e742e5fda27d571427590
2019-04-08T20:09:41Z
mmm a / src / python / grpcio / tests / unit / framework / common / test_control . py <nl> ppp b / src / python / grpcio / tests / unit / framework / common / test_control . py <nl> def control ( self ) : <nl> <nl> <nl> class PauseFailControl ( Control ) : <nl> - " " " A Control that can be used to pause or fail code under control . " " " <nl> + " " " A Control that can be used to pause or fail code under control . <nl> + <nl> + This object is only safe for use from two threads : one of the system under <nl> + test calling control and the other from the test system calling pause , <nl> + block_until_paused , and fail . <nl> + " " " <nl> <nl> def __init__ ( self ) : <nl> self . _condition = threading . Condition ( ) <nl> + self . _pause = False <nl> self . _paused = False <nl> self . _fail = False <nl> <nl> def control ( self ) : <nl> if self . _fail : <nl> raise Defect ( ) <nl> <nl> - while self . _paused : <nl> + while self . _pause : <nl> + self . _paused = True <nl> + self . _condition . notify_all ( ) <nl> self . _condition . wait ( ) <nl> + self . _paused = False <nl> <nl> @ contextlib . contextmanager <nl> def pause ( self ) : <nl> " " " Pauses code under control while controlling code is in context . " " " <nl> with self . _condition : <nl> - self . _paused = True <nl> + self . _pause = True <nl> yield <nl> with self . _condition : <nl> - self . _paused = False <nl> + self . _pause = False <nl> self . _condition . notify_all ( ) <nl> <nl> + def block_until_paused ( self ) : <nl> + " " " Blocks controlling code until code under control is paused . <nl> + <nl> + May only be called within the context of a pause call . <nl> + " " " <nl> + with self . _condition : <nl> + while not self . _paused : <nl> + self . _condition . wait ( ) <nl> + <nl> @ contextlib . contextmanager <nl> def fail ( self ) : <nl> " " " Fails code under control while controlling code is in context . " " " <nl>
Add block_until_paused method to PauseFailControl
grpc/grpc
6f61a13991e2747500285bd39e4eb69b68e623e3
2016-05-27T21:10:39Z
mmm a / libraries / chain / chain_controller . cpp <nl> ppp b / libraries / chain / chain_controller . cpp <nl> void chain_controller : : push_block ( const signed_block & new_block , uint32_t skip ) <nl> } ) ; <nl> } ) ; <nl> } ) ; <nl> - ilog ( " \ rpush block # $ { n } from $ { pro } $ { time } $ { id } lib : $ { l } success " , ( " n " , new_block . block_num ( ) ) ( " pro " , name ( new_block . producer ) ) ( " time " , new_block . timestamp ) ( " id " , new_block . id ( ) ) ( " l " , last_irreversible_block_num ( ) ) ) ; <nl> + ilog ( " push block # $ { n } from $ { pro } $ { time } $ { id } lib : $ { l } success " , ( " n " , new_block . block_num ( ) ) ( " pro " , name ( new_block . producer ) ) ( " time " , new_block . timestamp ) ( " id " , new_block . id ( ) ) ( " l " , last_irreversible_block_num ( ) ) ) ; <nl> } FC_CAPTURE_AND_RETHROW ( ( new_block ) ) } <nl> <nl> bool chain_controller : : _push_block ( const signed_block & new_block ) <nl> void chain_controller : : pop_block ( ) <nl> optional < signed_block > head_block = fetch_block_by_id ( head_id ) ; <nl> <nl> EOS_ASSERT ( head_block . valid ( ) , pop_empty_chain , " there are no blocks to pop " ) ; <nl> - wlog ( " \ rpop block # $ { n } from $ { pro } $ { time } $ { id } " , ( " n " , head_block - > block_num ( ) ) ( " pro " , name ( head_block - > producer ) ) ( " time " , head_block - > timestamp ) ( " id " , head_block - > id ( ) ) ) ; <nl> + wlog ( " pop block # $ { n } from $ { pro } $ { time } $ { id } " , ( " n " , head_block - > block_num ( ) ) ( " pro " , name ( head_block - > producer ) ) ( " time " , head_block - > timestamp ) ( " id " , head_block - > id ( ) ) ) ; <nl> <nl> _fork_db . pop_block ( ) ; <nl> _db . undo ( ) ; <nl> mmm a / libraries / fc / src / log / console_appender . cpp <nl> ppp b / libraries / fc / src / log / console_appender . cpp <nl> namespace fc { <nl> if ( my - > console_handle ! = INVALID_HANDLE_VALUE ) <nl> SetConsoleTextAttribute ( my - > console_handle , get_console_color ( text_color ) ) ; <nl> # else <nl> - if ( isatty ( fileno ( out ) ) ) fprintf ( out , " \ r % s " , get_console_color ( text_color ) ) ; <nl> + if ( isatty ( fileno ( out ) ) ) fprintf ( out , " % s " , get_console_color ( text_color ) ) ; <nl> # endif <nl> <nl> if ( text . size ( ) ) <nl> namespace fc { <nl> if ( my - > console_handle ! = INVALID_HANDLE_VALUE ) <nl> SetConsoleTextAttribute ( my - > console_handle , CONSOLE_DEFAULT ) ; <nl> # else <nl> - if ( isatty ( fileno ( out ) ) ) fprintf ( out , " \ r % s " , CONSOLE_DEFAULT ) ; <nl> + if ( isatty ( fileno ( out ) ) ) fprintf ( out , " % s " , CONSOLE_DEFAULT ) ; <nl> # endif <nl> <nl> if ( my - > cfg . flush ) fflush ( out ) ; <nl> mmm a / plugins / producer_plugin / producer_plugin . cpp <nl> ppp b / plugins / producer_plugin / producer_plugin . cpp <nl> block_production_condition : : block_production_condition_enum producer_plugin_impl <nl> auto producer = db . head_block_producer ( ) ; <nl> / / auto pending = db . pending ( ) . size ( ) ; <nl> <nl> - wlog ( " \ r $ { p } generated block $ { id } . . . # $ { n } @ $ { t } with $ { count } trxs , lib : $ { lib } " , ( " p " , producer ) ( " lib " , db . last_irreversible_block_num ( ) ) ( capture ) ) ; <nl> + wlog ( " $ { p } generated block $ { id } . . . # $ { n } @ $ { t } with $ { count } trxs , lib : $ { lib } " , ( " p " , producer ) ( " lib " , db . last_irreversible_block_num ( ) ) ( capture ) ) ; <nl> break ; <nl> } <nl> case block_production_condition : : not_synced : <nl> mmm a / tests / wasm_tests / exchange_tests . cpp <nl> ppp b / tests / wasm_tests / exchange_tests . cpp <nl> BOOST_AUTO_TEST_CASE ( exchange_create ) try { <nl> extended_asset ( A ( 0 . 01 USD ) , N ( eosio . token ) ) ) ; <nl> <nl> for ( const auto & at : result . action_traces ) <nl> - ilog ( " \ r $ { s } " , ( " s " , at . console ) ) ; <nl> + ilog ( " $ { s } " , ( " s " , at . console ) ) ; <nl> <nl> trader_ex_usd = t . get_exchange_balance ( N ( exchange ) , N ( eosio . token ) , symbol ( 2 , " USD " ) , N ( trader ) ) ; <nl> trader_ex_btc = t . get_exchange_balance ( N ( exchange ) , N ( eosio . token ) , symbol ( 2 , " BTC " ) , N ( trader ) ) ; <nl> BOOST_AUTO_TEST_CASE ( exchange_create ) try { <nl> trader_ex_btc = t . get_exchange_balance ( N ( exchange ) , N ( eosio . token ) , symbol ( 2 , " BTC " ) , N ( trader ) ) ; <nl> <nl> for ( const auto & at : result . action_traces ) <nl> - ilog ( " \ r $ { s } " , ( " s " , at . console ) ) ; <nl> + ilog ( " $ { s } " , ( " s " , at . console ) ) ; <nl> <nl> wdump ( ( trader_ex_btc . quantity ) ) ; <nl> wdump ( ( trader_ex_usd . quantity ) ) ; <nl>
Merge pull request from EOSIO / remove - spurious - carriage - returns
EOSIO/eos
6a55ecf23fc5ce5107ada13ed82f437a66ed6366
2018-04-26T17:49:01Z
mmm a / Telegram / Resources / basic . style <nl> ppp b / Telegram / Resources / basic . style <nl> msgReplyBarPos : point ( 1px , 0px ) ; <nl> msgReplyBarSize : size ( 2px , 36px ) ; <nl> msgReplyBarSkip : 10px ; <nl> msgServicePadding : margins ( 12px , 3px , 12px , 4px ) ; <nl> - msgServiceMargin : margins ( 10px , 10px , 80px , 2px ) ; <nl> + msgServiceMargin : margins ( 10px , 10px , 10px , 2px ) ; <nl> <nl> msgDateSpace : 12px ; <nl> msgDateDelta : point ( 2px , 5px ) ; <nl> mmm a / Telegram / SourceFiles / history / history_admin_log_section . cpp <nl> ppp b / Telegram / SourceFiles / history / history_admin_log_section . cpp <nl> void FixedBar : : setAnimatingMode ( bool enabled ) { <nl> } <nl> <nl> void FixedBar : : paintEvent ( QPaintEvent * e ) { <nl> - Painter p ( this ) ; <nl> - p . fillRect ( e - > rect ( ) , st : : topBarBg ) ; <nl> + if ( ! _animatingMode ) { <nl> + Painter p ( this ) ; <nl> + p . fillRect ( e - > rect ( ) , st : : topBarBg ) ; <nl> + } <nl> } <nl> <nl> void FixedBar : : mousePressEvent ( QMouseEvent * e ) { <nl> mmm a / Telegram / SourceFiles / history / history_item . cpp <nl> ppp b / Telegram / SourceFiles / history / history_item . cpp <nl> TextSelection shiftSelection ( TextSelection selection , const Text & byText ) { <nl> HistoryItem : : HistoryItem ( History * history , MsgId msgId , MTPDmessage : : Flags flags , QDateTime msgDate , int32 from ) : HistoryElement ( ) <nl> , id ( msgId ) <nl> , date ( msgDate ) <nl> - , _from ( from ? App : : user ( from ) : history - > peer ) <nl> , _history ( history ) <nl> + , _from ( from ? App : : user ( from ) : history - > peer ) <nl> , _flags ( flags | MTPDmessage_ClientFlag : : f_pending_init_dimensions | MTPDmessage_ClientFlag : : f_pending_resize ) <nl> , _authorNameVersion ( author ( ) - > nameVersion ) { <nl> } <nl> mmm a / Telegram / SourceFiles / history / history_item . h <nl> ppp b / Telegram / SourceFiles / history / history_item . h <nl> TextSelection shiftSelection ( TextSelection selection , const Text & byText ) ; <nl> <nl> class HistoryItem : public HistoryElement , public RuntimeComposer , public ClickHandlerHost { <nl> public : <nl> - int resizeGetHeight ( int width ) { <nl> + int resizeGetHeight ( int newWidth ) { <nl> if ( _flags & MTPDmessage_ClientFlag : : f_pending_init_dimensions ) { <nl> _flags & = ~ MTPDmessage_ClientFlag : : f_pending_init_dimensions ; <nl> initDimensions ( ) ; <nl> class HistoryItem : public HistoryElement , public RuntimeComposer , public ClickH <nl> if ( _flags & MTPDmessage_ClientFlag : : f_pending_resize ) { <nl> _flags & = ~ MTPDmessage_ClientFlag : : f_pending_resize ; <nl> } <nl> - return resizeGetHeight_ ( width ) ; <nl> + _width = newWidth ; <nl> + return resizeContentGetHeight ( ) ; <nl> } <nl> - virtual void draw ( Painter & p , const QRect & r , TextSelection selection , TimeMs ms ) const = 0 ; <nl> + virtual void draw ( Painter & p , QRect clip , TextSelection selection , TimeMs ms ) const = 0 ; <nl> <nl> virtual void dependencyItemRemoved ( HistoryItem * dependency ) { <nl> } <nl> class HistoryItem : public HistoryElement , public RuntimeComposer , public ClickH <nl> } <nl> <nl> UserData * viaBot ( ) const { <nl> - if ( const HistoryMessageVia * via = Get < HistoryMessageVia > ( ) ) { <nl> + if ( auto via = Get < HistoryMessageVia > ( ) ) { <nl> return via - > _bot ; <nl> } <nl> return nullptr ; <nl> class HistoryItem : public HistoryElement , public RuntimeComposer , public ClickH <nl> return _text . isEmpty ( ) & & ! _media & & ! Has < HistoryMessageLogEntryOriginal > ( ) ; <nl> } <nl> <nl> + int width ( ) const { <nl> + return _width ; <nl> + } <nl> + <nl> void clipCallback ( Media : : Clip : : Notification notification ) ; <nl> void audioTrackUpdated ( ) ; <nl> <nl> class HistoryItem : public HistoryElement , public RuntimeComposer , public ClickH <nl> / / called from resizeGetHeight ( ) when MTPDmessage_ClientFlag : : f_pending_init_dimensions is set <nl> virtual void initDimensions ( ) = 0 ; <nl> <nl> - virtual int resizeGetHeight_ ( int width ) = 0 ; <nl> + virtual int resizeContentGetHeight ( ) = 0 ; <nl> <nl> void finishEdition ( int oldKeyboardTop ) ; <nl> void finishEditionToEmpty ( ) ; <nl> <nl> - PeerData * _from ; <nl> - History * _history ; <nl> + gsl : : not_null < History * > _history ; <nl> + gsl : : not_null < PeerData * > _from ; <nl> HistoryBlock * _block = nullptr ; <nl> int _indexInBlock = - 1 ; <nl> - MTPDmessage : : Flags _flags ; <nl> + MTPDmessage : : Flags _flags = 0 ; <nl> <nl> - mutable int32 _authorNameVersion ; <nl> + mutable int32 _authorNameVersion = 0 ; <nl> <nl> HistoryItem * previousItem ( ) const { <nl> if ( _block & & _indexInBlock > = 0 ) { <nl> class HistoryItem : public HistoryElement , public RuntimeComposer , public ClickH <nl> <nl> private : <nl> int _y = 0 ; <nl> + int _width = 0 ; <nl> <nl> } ; <nl> <nl> template < typename T > <nl> class HistoryItemInstantiated { <nl> public : <nl> template < typename . . . Args > <nl> - static T * _create ( Args & & . . . args ) { <nl> - T * result = new T ( std : : forward < Args > ( args ) . . . ) ; <nl> + static gsl : : not_null < T * > _create ( Args & & . . . args ) { <nl> + auto result = new T ( std : : forward < Args > ( args ) . . . ) ; <nl> result - > finishCreate ( ) ; <nl> return result ; <nl> } <nl> mmm a / Telegram / SourceFiles / history / history_message . cpp <nl> ppp b / Telegram / SourceFiles / history / history_message . cpp <nl> Copyright ( c ) 2014 - 2017 John Preston , https : / / desktop . telegram . org <nl> <nl> namespace { <nl> <nl> + constexpr auto kPinnedMessageTextLimit = 16 ; <nl> + <nl> TextParseOptions _historySrvOptions = { <nl> TextParseLinks | TextParseMentions | TextParseHashtags / * | TextParseMultiline * / | TextParseRichText , / / flags <nl> 0 , / / maxw <nl> ApiWrap : : RequestMessageDataCallback historyDependentItemCallback ( const FullMsgId <nl> } ; <nl> } <nl> <nl> - constexpr auto kPinnedMessageTextLimit = 16 ; <nl> - <nl> style : : color fromNameFg ( int index ) { <nl> - t_assert ( index > = 0 & & index < 8 ) ; <nl> + Expects ( index > = 0 & & index < 8 ) ; <nl> style : : color colors [ ] = { <nl> st : : historyPeer1NameFg , <nl> st : : historyPeer2NameFg , <nl> style : : color fromNameFg ( int index ) { <nl> } <nl> <nl> style : : color fromNameFgSelected ( int index ) { <nl> - t_assert ( index > = 0 & & index < 8 ) ; <nl> + Expects ( index > = 0 & & index < 8 ) ; <nl> style : : color colors [ ] = { <nl> st : : historyPeer1NameFgSelected , <nl> st : : historyPeer2NameFgSelected , <nl> void HistoryMessageVia : : resize ( int32 availw ) const { <nl> } <nl> <nl> void HistoryMessageSigned : : create ( UserData * from , const QDateTime & date ) { <nl> - QString time = qsl ( " , " ) + date . toString ( cTimeFormat ( ) ) , name = App : : peerName ( from ) ; <nl> - int32 timew = st : : msgDateFont - > width ( time ) , namew = st : : msgDateFont - > width ( name ) ; <nl> + auto time = qsl ( " , " ) + date . toString ( cTimeFormat ( ) ) ; <nl> + auto name = App : : peerName ( from ) ; <nl> + auto timew = st : : msgDateFont - > width ( time ) ; <nl> + auto namew = st : : msgDateFont - > width ( name ) ; <nl> if ( timew + namew > st : : maxSignatureSize ) { <nl> name = st : : msgDateFont - > elided ( from - > firstName , st : : maxSignatureSize - timew ) ; <nl> } <nl> int HistoryMessageSigned : : maxWidth ( ) const { <nl> void HistoryMessageEdited : : create ( const QDateTime & editDate , const QDateTime & date ) { <nl> _editDate = editDate ; <nl> <nl> - QString time = date . toString ( cTimeFormat ( ) ) ; <nl> + auto time = date . toString ( cTimeFormat ( ) ) ; <nl> _edited . setText ( st : : msgDateTextStyle , lang ( lng_edited ) + ' ' + time , _textNameOptions ) ; <nl> } <nl> <nl> int HistoryMessage : : KeyboardStyle : : minButtonWidth ( HistoryMessageReplyMarkup : : But <nl> return result ; <nl> } <nl> <nl> - HistoryMessage : : HistoryMessage ( History * history , const MTPDmessage & msg ) <nl> + HistoryMessage : : HistoryMessage ( gsl : : not_null < History * > history , const MTPDmessage & msg ) <nl> : HistoryItem ( history , msg . vid . v , msg . vflags . v , : : date ( msg . vdate ) , msg . has_from_id ( ) ? msg . vfrom_id . v : 0 ) { <nl> CreateConfig config ; <nl> <nl> HistoryMessage : : HistoryMessage ( History * history , const MTPDmessage & msg ) <nl> setText ( { text , entities } ) ; <nl> } <nl> <nl> - HistoryMessage : : HistoryMessage ( History * history , const MTPDmessageService & msg ) <nl> + HistoryMessage : : HistoryMessage ( gsl : : not_null < History * > history , const MTPDmessageService & msg ) <nl> : HistoryItem ( history , msg . vid . v , mtpCastFlags ( msg . vflags . v ) , : : date ( msg . vdate ) , msg . has_from_id ( ) ? msg . vfrom_id . v : 0 ) { <nl> CreateConfig config ; <nl> <nl> HistoryMessage : : HistoryMessage ( History * history , const MTPDmessageService & msg ) <nl> setText ( TextWithEntities { } ) ; <nl> } <nl> <nl> - HistoryMessage : : HistoryMessage ( History * history , MsgId id , MTPDmessage : : Flags flags , QDateTime date , int32 from , HistoryMessage * fwd ) <nl> + HistoryMessage : : HistoryMessage ( gsl : : not_null < History * > history , MsgId id , MTPDmessage : : Flags flags , QDateTime date , int32 from , HistoryMessage * fwd ) <nl> : HistoryItem ( history , id , newForwardedFlags ( history - > peer , from , fwd ) | flags , date , from ) { <nl> CreateConfig config ; <nl> <nl> HistoryMessage : : HistoryMessage ( History * history , MsgId id , MTPDmessage : : Flags fl <nl> setText ( fwd - > originalText ( ) ) ; <nl> } <nl> <nl> - HistoryMessage : : HistoryMessage ( History * history , MsgId id , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , const TextWithEntities & textWithEntities ) <nl> + HistoryMessage : : HistoryMessage ( gsl : : not_null < History * > history , MsgId id , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , const TextWithEntities & textWithEntities ) <nl> : HistoryItem ( history , id , flags , date , ( flags & MTPDmessage : : Flag : : f_from_id ) ? from : 0 ) { <nl> createComponentsHelper ( flags , replyTo , viaBotId , MTPnullMarkup ) ; <nl> <nl> setText ( textWithEntities ) ; <nl> } <nl> <nl> - HistoryMessage : : HistoryMessage ( History * history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , DocumentData * doc , const QString & caption , const MTPReplyMarkup & markup ) <nl> + HistoryMessage : : HistoryMessage ( gsl : : not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , DocumentData * doc , const QString & caption , const MTPReplyMarkup & markup ) <nl> : HistoryItem ( history , msgId , flags , date , ( flags & MTPDmessage : : Flag : : f_from_id ) ? from : 0 ) { <nl> createComponentsHelper ( flags , replyTo , viaBotId , markup ) ; <nl> <nl> HistoryMessage : : HistoryMessage ( History * history , MsgId msgId , MTPDmessage : : Flags <nl> setText ( TextWithEntities ( ) ) ; <nl> } <nl> <nl> - HistoryMessage : : HistoryMessage ( History * history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , PhotoData * photo , const QString & caption , const MTPReplyMarkup & markup ) <nl> + HistoryMessage : : HistoryMessage ( gsl : : not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , PhotoData * photo , const QString & caption , const MTPReplyMarkup & markup ) <nl> : HistoryItem ( history , msgId , flags , date , ( flags & MTPDmessage : : Flag : : f_from_id ) ? from : 0 ) { <nl> createComponentsHelper ( flags , replyTo , viaBotId , markup ) ; <nl> <nl> HistoryMessage : : HistoryMessage ( History * history , MsgId msgId , MTPDmessage : : Flags <nl> setText ( TextWithEntities ( ) ) ; <nl> } <nl> <nl> - HistoryMessage : : HistoryMessage ( History * history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , GameData * game , const MTPReplyMarkup & markup ) <nl> + HistoryMessage : : HistoryMessage ( gsl : : not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , GameData * game , const MTPReplyMarkup & markup ) <nl> : HistoryItem ( history , msgId , flags , date , ( flags & MTPDmessage : : Flag : : f_from_id ) ? from : 0 ) { <nl> createComponentsHelper ( flags , replyTo , viaBotId , markup ) ; <nl> <nl> bool HistoryMessage : : drawBubble ( ) const { <nl> return _media ? ( ! emptyText ( ) | | _media - > needsBubble ( ) ) : ! isEmpty ( ) ; <nl> } <nl> <nl> - void HistoryMessage : : countPositionAndSize ( int32 & left , int32 & width ) const { <nl> - int32 maxwidth = qMin ( int ( st : : msgMaxWidth ) , _maxw ) , hwidth = _history - > width ; <nl> + QRect HistoryMessage : : countGeometry ( ) const { <nl> + auto maxwidth = qMin ( st : : msgMaxWidth , _maxw ) ; <nl> if ( _media & & _media - > currentWidth ( ) < maxwidth ) { <nl> maxwidth = qMax ( _media - > currentWidth ( ) , qMin ( maxwidth , plainMaxWidth ( ) ) ) ; <nl> } <nl> <nl> - left = ( ! isPost ( ) & & out ( ) & & ! Adaptive : : ChatWide ( ) ) ? st : : msgMargin . right ( ) : st : : msgMargin . left ( ) ; <nl> + auto contentLeft = ( ! isPost ( ) & & out ( ) & & ! Adaptive : : ChatWide ( ) ) ? st : : msgMargin . right ( ) : st : : msgMargin . left ( ) ; <nl> if ( hasFromPhoto ( ) ) { <nl> - left + = st : : msgPhotoSkip ; <nl> - / / } else if ( ! Adaptive : : Wide ( ) & & ! out ( ) & & ! fromChannel ( ) & & st : : msgPhotoSkip - ( hmaxwidth - hwidth ) > 0 ) { <nl> - / / left + = st : : msgPhotoSkip - ( hmaxwidth - hwidth ) ; <nl> + contentLeft + = st : : msgPhotoSkip ; <nl> + / / } else if ( ! Adaptive : : Wide ( ) & & ! out ( ) & & ! fromChannel ( ) & & st : : msgPhotoSkip - ( hmaxwidth - hwidth ) > 0 ) { <nl> + / / contentLeft + = st : : msgPhotoSkip - ( hmaxwidth - hwidth ) ; <nl> } <nl> <nl> - width = hwidth - st : : msgMargin . left ( ) - st : : msgMargin . right ( ) ; <nl> - if ( width > maxwidth ) { <nl> + auto contentWidth = width ( ) - st : : msgMargin . left ( ) - st : : msgMargin . right ( ) ; <nl> + if ( contentWidth > maxwidth ) { <nl> if ( ! isPost ( ) & & out ( ) & & ! Adaptive : : ChatWide ( ) ) { <nl> - left + = width - maxwidth ; <nl> + contentLeft + = contentWidth - maxwidth ; <nl> } <nl> - width = maxwidth ; <nl> + contentWidth = maxwidth ; <nl> } <nl> + <nl> + auto contentTop = marginTop ( ) ; <nl> + return QRect ( contentLeft , contentTop , contentWidth , _height - contentTop - marginBottom ( ) ) ; <nl> } <nl> <nl> void HistoryMessage : : fromNameUpdated ( int32 width ) const { <nl> void HistoryMessage : : setId ( MsgId newId ) { <nl> } <nl> } <nl> <nl> - void HistoryMessage : : draw ( Painter & p , const QRect & r , TextSelection selection , TimeMs ms ) const { <nl> + void HistoryMessage : : draw ( Painter & p , QRect clip , TextSelection selection , TimeMs ms ) const { <nl> bool outbg = out ( ) & & ! isPost ( ) , bubble = drawBubble ( ) , selected = ( selection = = FullSelection ) ; <nl> <nl> - int left = 0 , width = 0 , height = _height ; <nl> - countPositionAndSize ( left , width ) ; <nl> - if ( width < 1 ) return ; <nl> + auto g = countGeometry ( ) ; <nl> + if ( g . width ( ) < 1 ) { <nl> + return ; <nl> + } <nl> <nl> - int dateh = 0 , unreadbarh = 0 ; <nl> + auto dateh = 0 ; <nl> if ( auto date = Get < HistoryMessageDate > ( ) ) { <nl> dateh = date - > height ( ) ; <nl> } <nl> if ( auto unreadbar = Get < HistoryMessageUnreadBar > ( ) ) { <nl> - unreadbarh = unreadbar - > height ( ) ; <nl> - if ( r . intersects ( QRect ( 0 , dateh , _history - > width , unreadbarh ) ) ) { <nl> + auto unreadbarh = unreadbar - > height ( ) ; <nl> + if ( clip . intersects ( QRect ( 0 , dateh , width ( ) , unreadbarh ) ) ) { <nl> p . translate ( 0 , dateh ) ; <nl> - unreadbar - > paint ( p , 0 , _history - > width ) ; <nl> + unreadbar - > paint ( p , 0 , width ( ) ) ; <nl> p . translate ( 0 , - dateh ) ; <nl> } <nl> } <nl> void HistoryMessage : : draw ( Painter & p , const QRect & r , TextSelection selection , T <nl> auto bottom = marginBottom ( ) ; <nl> auto fill = qMin ( top , bottom ) ; <nl> auto skiptop = top - fill ; <nl> - auto fillheight = fill + ( height - top - bottom ) + fill ; <nl> + auto fillheight = fill + g . height ( ) + fill ; <nl> <nl> auto dt = ( animms > st : : activeFadeInDuration ) ? ( 1 . - ( animms - st : : activeFadeInDuration ) / float64 ( st : : activeFadeOutDuration ) ) : ( animms / float64 ( st : : activeFadeInDuration ) ) ; <nl> auto o = p . opacity ( ) ; <nl> p . setOpacity ( o * dt ) ; <nl> - p . fillRect ( 0 , skiptop , _history - > width , fillheight , st : : defaultTextPalette . selectOverlay ) ; <nl> + p . fillRect ( 0 , skiptop , width ( ) , fillheight , st : : defaultTextPalette . selectOverlay ) ; <nl> p . setOpacity ( o ) ; <nl> } <nl> } <nl> void HistoryMessage : : draw ( Painter & p , const QRect & r , TextSelection selection , T <nl> <nl> auto keyboard = inlineReplyKeyboard ( ) ; <nl> if ( keyboard ) { <nl> - int h = st : : msgBotKbButton . margin + keyboard - > naturalHeight ( ) ; <nl> - height - = h ; <nl> - int top = height + st : : msgBotKbButton . margin - marginBottom ( ) ; <nl> - p . translate ( left , top ) ; <nl> - keyboard - > paint ( p , width , r . translated ( - left , - top ) , ms ) ; <nl> - p . translate ( - left , - top ) ; <nl> + auto keyboardHeight = st : : msgBotKbButton . margin + keyboard - > naturalHeight ( ) ; <nl> + g . setHeight ( g . height ( ) - keyboardHeight ) ; <nl> + auto keyboardPosition = QPoint ( g . left ( ) , g . top ( ) + g . height ( ) + st : : msgBotKbButton . margin ) ; <nl> + p . translate ( keyboardPosition ) ; <nl> + keyboard - > paint ( p , g . width ( ) , clip . translated ( - keyboardPosition ) , ms ) ; <nl> + p . translate ( - keyboardPosition ) ; <nl> } <nl> <nl> if ( bubble ) { <nl> if ( displayFromName ( ) & & author ( ) - > nameVersion > _authorNameVersion ) { <nl> - fromNameUpdated ( width ) ; <nl> + fromNameUpdated ( g . width ( ) ) ; <nl> } <nl> <nl> auto entry = Get < HistoryMessageLogEntryOriginal > ( ) ; <nl> auto mediaDisplayed = _media & & _media - > isDisplayed ( ) ; <nl> - auto top = marginTop ( ) ; <nl> - auto r = QRect ( left , top , width , height - top - marginBottom ( ) ) ; <nl> <nl> auto skipTail = isAttachedToNext ( ) | | ( _media & & _media - > skipBubbleTail ( ) ) | | ( keyboard ! = nullptr ) ; <nl> auto displayTail = skipTail ? RectPart : : None : ( outbg & & ! Adaptive : : ChatWide ( ) ) ? RectPart : : Right : RectPart : : Left ; <nl> - HistoryLayout : : paintBubble ( p , r , _history - > width , selected , outbg , displayTail ) ; <nl> + HistoryLayout : : paintBubble ( p , g , width ( ) , selected , outbg , displayTail ) ; <nl> <nl> - auto trect = r . marginsAdded ( - st : : msgPadding ) ; <nl> + auto trect = g . marginsAdded ( - st : : msgPadding ) ; <nl> if ( mediaDisplayed & & _media - > isBubbleTop ( ) ) { <nl> trect . setY ( trect . y ( ) - st : : msgPadding . top ( ) ) ; <nl> } else { <nl> void HistoryMessage : : draw ( Painter & p , const QRect & r , TextSelection selection , T <nl> if ( mediaDisplayed ) { <nl> auto mediaAboveText = _media - > isAboveMessage ( ) ; <nl> auto mediaHeight = _media - > height ( ) ; <nl> - auto mediaLeft = trect . x ( ) - st : : msgPadding . left ( ) ; <nl> + auto mediaLeft = g . left ( ) ; <nl> auto mediaTop = mediaAboveText ? trect . y ( ) : ( trect . y ( ) + trect . height ( ) - mediaHeight ) ; <nl> if ( ! mediaAboveText ) { <nl> paintText ( p , trect , selection ) ; <nl> } <nl> p . translate ( mediaLeft , mediaTop ) ; <nl> - _media - > draw ( p , r . translated ( - mediaLeft , - mediaTop ) , toMediaSelection ( selection ) , ms ) ; <nl> + _media - > draw ( p , clip . translated ( - mediaLeft , - mediaTop ) , toMediaSelection ( selection ) , ms ) ; <nl> p . translate ( - mediaLeft , - mediaTop ) ; <nl> <nl> if ( mediaAboveText ) { <nl> void HistoryMessage : : draw ( Painter & p , const QRect & r , TextSelection selection , T <nl> paintText ( p , trect , selection ) ; <nl> } <nl> if ( entry ) { <nl> - auto entryLeft = r . x ( ) ; <nl> + auto entryLeft = g . left ( ) ; <nl> auto entryTop = trect . y ( ) + trect . height ( ) ; <nl> p . translate ( entryLeft , entryTop ) ; <nl> - entry - > _page - > draw ( p , r . translated ( - entryLeft , - entryTop ) , TextSelection ( ) , ms ) ; <nl> + entry - > _page - > draw ( p , clip . translated ( - entryLeft , - entryTop ) , TextSelection ( ) , ms ) ; <nl> p . translate ( - entryLeft , - entryTop ) ; <nl> } <nl> if ( needDrawInfo ) { <nl> - HistoryMessage : : drawInfo ( p , r . x ( ) + r . width ( ) , r . y ( ) + r . height ( ) , 2 * r . x ( ) + r . width ( ) , selected , InfoDisplayDefault ) ; <nl> + HistoryMessage : : drawInfo ( p , g . left ( ) + g . width ( ) , g . top ( ) + g . height ( ) , 2 * g . left ( ) + g . width ( ) , selected , InfoDisplayDefault ) ; <nl> } <nl> } else if ( _media ) { <nl> - auto top = marginTop ( ) ; <nl> - p . translate ( left , top ) ; <nl> - _media - > draw ( p , r . translated ( - left , - top ) , toMediaSelection ( selection ) , ms ) ; <nl> - p . translate ( - left , - top ) ; <nl> + p . translate ( g . topLeft ( ) ) ; <nl> + _media - > draw ( p , clip . translated ( - g . topLeft ( ) ) , toMediaSelection ( selection ) , ms ) ; <nl> + p . translate ( - g . topLeft ( ) ) ; <nl> } <nl> <nl> p . restoreTextPalette ( ) ; <nl> void HistoryMessage : : paintViaBotIdInfo ( Painter & p , QRect & trect , bool selected ) <nl> if ( auto via = Get < HistoryMessageVia > ( ) ) { <nl> p . setFont ( st : : msgServiceNameFont ) ; <nl> p . setPen ( selected ? ( hasOutLayout ( ) ? st : : msgOutServiceFgSelected : st : : msgInServiceFgSelected ) : ( hasOutLayout ( ) ? st : : msgOutServiceFg : st : : msgInServiceFg ) ) ; <nl> - p . drawTextLeft ( trect . left ( ) , trect . top ( ) , _history - > width , via - > _text ) ; <nl> + p . drawTextLeft ( trect . left ( ) , trect . top ( ) , width ( ) , via - > _text ) ; <nl> trect . setY ( trect . y ( ) + st : : msgServiceNameFont - > height ) ; <nl> } <nl> } <nl> void HistoryMessage : : dependencyItemRemoved ( HistoryItem * dependency ) { <nl> } <nl> } <nl> <nl> - int HistoryMessage : : resizeGetHeight_ ( int width ) { <nl> - int result = performResizeGetHeight ( width ) ; <nl> + int HistoryMessage : : resizeContentGetHeight ( ) { <nl> + int result = performResizeGetHeight ( ) ; <nl> <nl> auto keyboard = inlineReplyKeyboard ( ) ; <nl> if ( auto markup = Get < HistoryMessageReplyMarkup > ( ) ) { <nl> int HistoryMessage : : resizeGetHeight_ ( int width ) { <nl> return result ; <nl> } <nl> <nl> - int HistoryMessage : : performResizeGetHeight ( int width ) { <nl> - if ( width < st : : msgMinWidth ) return _height ; <nl> + int HistoryMessage : : performResizeGetHeight ( ) { <nl> + if ( width ( ) < st : : msgMinWidth ) return _height ; <nl> <nl> - width - = st : : msgMargin . left ( ) + st : : msgMargin . right ( ) ; <nl> - if ( width < st : : msgPadding . left ( ) + st : : msgPadding . right ( ) + 1 ) { <nl> - width = st : : msgPadding . left ( ) + st : : msgPadding . right ( ) + 1 ; <nl> - } else if ( width > st : : msgMaxWidth ) { <nl> - width = st : : msgMaxWidth ; <nl> + auto contentWidth = width ( ) - ( st : : msgMargin . left ( ) + st : : msgMargin . right ( ) ) ; <nl> + if ( contentWidth < st : : msgPadding . left ( ) + st : : msgPadding . right ( ) + 1 ) { <nl> + contentWidth = st : : msgPadding . left ( ) + st : : msgPadding . right ( ) + 1 ; <nl> + } else if ( contentWidth > st : : msgMaxWidth ) { <nl> + contentWidth = st : : msgMaxWidth ; <nl> } <nl> if ( drawBubble ( ) ) { <nl> auto forwarded = Get < HistoryMessageForwarded > ( ) ; <nl> int HistoryMessage : : performResizeGetHeight ( int width ) { <nl> mediaDisplayed = _media - > isDisplayed ( ) ; <nl> mediaInBubbleState = _media - > inBubbleState ( ) ; <nl> } <nl> - if ( width > = _maxw ) { <nl> + if ( contentWidth > = _maxw ) { <nl> _height = _minh ; <nl> if ( mediaDisplayed ) { <nl> _media - > resizeGetHeight ( _maxw ) ; <nl> int HistoryMessage : : performResizeGetHeight ( int width ) { <nl> if ( emptyText ( ) ) { <nl> _height = 0 ; <nl> } else { <nl> - auto textWidth = qMax ( width - st : : msgPadding . left ( ) - st : : msgPadding . right ( ) , 1 ) ; <nl> + auto textWidth = qMax ( contentWidth - st : : msgPadding . left ( ) - st : : msgPadding . right ( ) , 1 ) ; <nl> if ( textWidth ! = _textWidth ) { <nl> _textWidth = textWidth ; <nl> _textHeight = _text . countHeight ( textWidth ) ; <nl> int HistoryMessage : : performResizeGetHeight ( int width ) { <nl> if ( ! _media - > isBubbleBottom ( ) ) { <nl> _height + = st : : msgPadding . bottom ( ) + st : : mediaInBubbleSkip ; <nl> } <nl> - _height + = _media - > resizeGetHeight ( width ) ; <nl> + _height + = _media - > resizeGetHeight ( contentWidth ) ; <nl> } else { <nl> _height + = st : : msgPadding . top ( ) + st : : msgPadding . bottom ( ) ; <nl> } <nl> if ( entry ) { <nl> - _height + = entry - > _page - > resizeGetHeight ( width ) ; <nl> + _height + = entry - > _page - > resizeGetHeight ( contentWidth ) ; <nl> } <nl> } <nl> <nl> if ( displayFromName ( ) ) { <nl> - int32 l = 0 , w = 0 ; <nl> - countPositionAndSize ( l , w ) ; <nl> - fromNameUpdated ( w ) ; <nl> + auto g = countGeometry ( ) ; <nl> + fromNameUpdated ( g . width ( ) ) ; <nl> _height + = st : : msgNameFont - > height ; <nl> } else if ( via & & ! forwarded ) { <nl> - int32 l = 0 , w = 0 ; <nl> - countPositionAndSize ( l , w ) ; <nl> - via - > resize ( w - st : : msgPadding . left ( ) - st : : msgPadding . right ( ) ) ; <nl> + auto g = countGeometry ( ) ; <nl> + via - > resize ( g . width ( ) - st : : msgPadding . left ( ) - st : : msgPadding . right ( ) ) ; <nl> _height + = st : : msgNameFont - > height ; <nl> } <nl> <nl> if ( displayForwardedFrom ( ) ) { <nl> - int32 l = 0 , w = 0 ; <nl> - countPositionAndSize ( l , w ) ; <nl> - int32 fwdheight = ( ( forwarded - > _text . maxWidth ( ) > ( w - st : : msgPadding . left ( ) - st : : msgPadding . right ( ) ) ) ? 2 : 1 ) * st : : semiboldFont - > height ; <nl> + auto g = countGeometry ( ) ; <nl> + auto fwdheight = ( ( forwarded - > _text . maxWidth ( ) > ( g . width ( ) - st : : msgPadding . left ( ) - st : : msgPadding . right ( ) ) ) ? 2 : 1 ) * st : : semiboldFont - > height ; <nl> _height + = fwdheight ; <nl> } <nl> <nl> if ( reply ) { <nl> - int32 l = 0 , w = 0 ; <nl> - countPositionAndSize ( l , w ) ; <nl> - reply - > resize ( w - st : : msgPadding . left ( ) - st : : msgPadding . right ( ) ) ; <nl> + auto g = countGeometry ( ) ; <nl> + reply - > resize ( g . width ( ) - st : : msgPadding . left ( ) - st : : msgPadding . right ( ) ) ; <nl> _height + = st : : msgReplyPadding . top ( ) + st : : msgReplyBarSize . height ( ) + st : : msgReplyPadding . bottom ( ) ; <nl> } <nl> } else if ( _media ) { <nl> - _height = _media - > resizeGetHeight ( width ) ; <nl> + _height = _media - > resizeGetHeight ( contentWidth ) ; <nl> } else { <nl> _height = 0 ; <nl> } <nl> if ( auto keyboard = inlineReplyKeyboard ( ) ) { <nl> - int32 l = 0 , w = 0 ; <nl> - countPositionAndSize ( l , w ) ; <nl> - <nl> - int h = st : : msgBotKbButton . margin + keyboard - > naturalHeight ( ) ; <nl> - _height + = h ; <nl> - keyboard - > resize ( w , h - st : : msgBotKbButton . margin ) ; <nl> + auto g = countGeometry ( ) ; <nl> + auto keyboardHeight = st : : msgBotKbButton . margin + keyboard - > naturalHeight ( ) ; <nl> + _height + = keyboardHeight ; <nl> + keyboard - > resize ( g . width ( ) , keyboardHeight - st : : msgBotKbButton . margin ) ; <nl> } <nl> <nl> _height + = marginTop ( ) + marginBottom ( ) ; <nl> int HistoryMessage : : performResizeGetHeight ( int width ) { <nl> } <nl> <nl> bool HistoryMessage : : hasPoint ( int x , int y ) const { <nl> - int left = 0 , width = 0 , height = _height ; <nl> - countPositionAndSize ( left , width ) ; <nl> - if ( width < 1 ) return false ; <nl> + auto g = countGeometry ( ) ; <nl> + if ( g . width ( ) < 1 ) { <nl> + return false ; <nl> + } <nl> <nl> if ( drawBubble ( ) ) { <nl> - int top = marginTop ( ) ; <nl> - QRect r ( left , top , width , height - top - marginBottom ( ) ) ; <nl> - return r . contains ( x , y ) ; <nl> + return g . contains ( x , y ) ; <nl> } else if ( _media ) { <nl> - return _media - > hasPoint ( x - left , y - marginTop ( ) ) ; <nl> + return _media - > hasPoint ( x - g . left ( ) , y - g . top ( ) ) ; <nl> } else { <nl> return false ; <nl> } <nl> bool HistoryMessage : : pointInTime ( int32 right , int32 bottom , int x , int y , InfoDi <nl> HistoryTextState HistoryMessage : : getState ( int x , int y , HistoryStateRequest request ) const { <nl> HistoryTextState result ; <nl> <nl> - int left = 0 , width = 0 , height = _height ; <nl> - countPositionAndSize ( left , width ) ; <nl> - <nl> - if ( width < 1 ) return result ; <nl> + auto g = countGeometry ( ) ; <nl> + if ( g . width ( ) < 1 ) { <nl> + return result ; <nl> + } <nl> <nl> auto keyboard = inlineReplyKeyboard ( ) ; <nl> + auto keyboardHeight = 0 ; <nl> if ( keyboard ) { <nl> - int h = st : : msgBotKbButton . margin + keyboard - > naturalHeight ( ) ; <nl> - height - = h ; <nl> + keyboardHeight = keyboard - > naturalHeight ( ) ; <nl> + g . setHeight ( g . height ( ) - st : : msgBotKbButton . margin - keyboardHeight ) ; <nl> } <nl> <nl> if ( drawBubble ( ) ) { <nl> auto mediaDisplayed = _media & & _media - > isDisplayed ( ) ; <nl> - auto top = marginTop ( ) ; <nl> - QRect r ( left , top , width , height - top - marginBottom ( ) ) ; <nl> - QRect trect ( r . marginsAdded ( - st : : msgPadding ) ) ; <nl> + auto trect = g . marginsAdded ( - st : : msgPadding ) ; <nl> if ( mediaDisplayed & & _media - > isBubbleTop ( ) ) { <nl> trect . setY ( trect . y ( ) - st : : msgPadding . top ( ) ) ; <nl> } else { <nl> HistoryTextState HistoryMessage : : getState ( int x , int y , HistoryStateRequest requ <nl> getStateText ( x , y , trect , & result , request ) ; <nl> } <nl> if ( needDateCheck ) { <nl> - if ( HistoryMessage : : pointInTime ( r . x ( ) + r . width ( ) , r . y ( ) + r . height ( ) , x , y , InfoDisplayDefault ) ) { <nl> + if ( HistoryMessage : : pointInTime ( g . left ( ) + g . width ( ) , g . top ( ) + g . height ( ) , x , y , InfoDisplayDefault ) ) { <nl> result . cursor = HistoryInDateCursorState ; <nl> } <nl> } <nl> } else if ( _media ) { <nl> - result = _media - > getState ( x - left , y - marginTop ( ) , request ) ; <nl> + result = _media - > getState ( x - g . left ( ) , y - g . top ( ) , request ) ; <nl> result . symbol + = _text . length ( ) ; <nl> } <nl> <nl> if ( keyboard ) { <nl> - int top = height + st : : msgBotKbButton . margin - marginBottom ( ) ; <nl> - if ( x > = left & & x < left + width & & y > = top & & y < _height - marginBottom ( ) ) { <nl> - result . link = keyboard - > getState ( x - left , y - top ) ; <nl> + auto keyboardTop = g . top ( ) + g . height ( ) + st : : msgBotKbButton . margin ; <nl> + if ( QRect ( g . left ( ) , keyboardTop , g . width ( ) , keyboardHeight ) . contains ( x , y ) ) { <nl> + result . link = keyboard - > getState ( x - g . left ( ) , y - keyboardTop ) ; <nl> return result ; <nl> } <nl> } <nl> HistoryTextState HistoryMessage : : getState ( int x , int y , HistoryStateRequest requ <nl> void HistoryMessage : : updatePressed ( int x , int y ) { <nl> if ( ! _media ) return ; <nl> <nl> - auto left = 0 , width = 0 , height = _height ; <nl> - countPositionAndSize ( left , width ) ; <nl> - <nl> + auto g = countGeometry ( ) ; <nl> auto keyboard = inlineReplyKeyboard ( ) ; <nl> if ( keyboard ) { <nl> - auto h = st : : msgBotKbButton . margin + keyboard - > naturalHeight ( ) ; <nl> - height - = h ; <nl> + auto keyboardHeight = st : : msgBotKbButton . margin + keyboard - > naturalHeight ( ) ; <nl> + g . setHeight ( g . height ( ) - keyboardHeight ) ; <nl> } <nl> <nl> if ( drawBubble ( ) ) { <nl> auto mediaDisplayed = _media & & _media - > isDisplayed ( ) ; <nl> auto top = marginTop ( ) ; <nl> - QRect r ( left , top , width , height - top - marginBottom ( ) ) ; <nl> - QRect trect ( r . marginsAdded ( - st : : msgPadding ) ) ; <nl> + auto trect = g . marginsAdded ( - st : : msgPadding ) ; <nl> if ( mediaDisplayed & & _media - > isBubbleTop ( ) ) { <nl> trect . setY ( trect . y ( ) - st : : msgPadding . top ( ) ) ; <nl> } else { <nl> void HistoryMessage : : updatePressed ( int x , int y ) { <nl> _media - > updatePressed ( x - mediaLeft , y - mediaTop ) ; <nl> } <nl> } else { <nl> - _media - > updatePressed ( x - left , y - marginTop ( ) ) ; <nl> + _media - > updatePressed ( x - g . left ( ) , y - g . top ( ) ) ; <nl> } <nl> } <nl> <nl> HistoryService : : PreparedText HistoryService : : preparePaymentSentText ( ) { <nl> return result ; <nl> } <nl> <nl> - HistoryService : : HistoryService ( History * history , const MTPDmessageService & message ) : <nl> + HistoryService : : HistoryService ( gsl : : not_null < History * > history , const MTPDmessageService & message ) : <nl> HistoryItem ( history , message . vid . v , mtpCastFlags ( message . vflags . v ) , : : date ( message . vdate ) , message . has_from_id ( ) ? message . vfrom_id . v : 0 ) { <nl> createFromMtp ( message ) ; <nl> setMessageByAction ( message . vaction ) ; <nl> } <nl> <nl> - HistoryService : : HistoryService ( History * history , MsgId msgId , QDateTime date , const PreparedText & message , MTPDmessage : : Flags flags , int32 from , PhotoData * photo ) : <nl> + HistoryService : : HistoryService ( gsl : : not_null < History * > history , MsgId msgId , QDateTime date , const PreparedText & message , MTPDmessage : : Flags flags , int32 from , PhotoData * photo ) : <nl> HistoryItem ( history , msgId , flags , date , from ) { <nl> setServiceText ( message ) ; <nl> if ( photo ) { <nl> bool HistoryService : : updateDependencyItem ( ) { <nl> return HistoryItem : : updateDependencyItem ( ) ; <nl> } <nl> <nl> - void HistoryService : : countPositionAndSize ( int32 & left , int32 & width ) const { <nl> - left = st : : msgServiceMargin . left ( ) ; <nl> - int32 maxwidth = _history - > width ; <nl> + QRect HistoryService : : countGeometry ( ) const { <nl> + auto result = QRect ( 0 , 0 , width ( ) , _height ) ; <nl> if ( Adaptive : : ChatWide ( ) ) { <nl> - maxwidth = qMin ( maxwidth , int32 ( st : : msgMaxWidth + 2 * st : : msgPhotoSkip + 2 * st : : msgMargin . left ( ) ) ) ; <nl> + result . setWidth ( qMin ( result . width ( ) , st : : msgMaxWidth + 2 * st : : msgPhotoSkip + 2 * st : : msgMargin . left ( ) ) ) ; <nl> } <nl> - width = maxwidth - st : : msgServiceMargin . left ( ) - st : : msgServiceMargin . left ( ) ; <nl> + return result . marginsRemoved ( st : : msgServiceMargin ) ; <nl> } <nl> <nl> TextWithEntities HistoryService : : selectedText ( TextSelection selection ) const { <nl> void HistoryService : : setServiceText ( const PreparedText & prepared ) { <nl> _textHeight = 0 ; <nl> } <nl> <nl> - void HistoryService : : draw ( Painter & p , const QRect & r , TextSelection selection , TimeMs ms ) const { <nl> - int height = _height - st : : msgServiceMargin . top ( ) - st : : msgServiceMargin . bottom ( ) ; <nl> - <nl> - QRect clip ( r ) ; <nl> - int dateh = 0 , unreadbarh = 0 ; <nl> + void HistoryService : : draw ( Painter & p , QRect clip , TextSelection selection , TimeMs ms ) const { <nl> + auto height = _height - st : : msgServiceMargin . top ( ) - st : : msgServiceMargin . bottom ( ) ; <nl> + auto dateh = 0 ; <nl> + auto unreadbarh = 0 ; <nl> if ( auto date = Get < HistoryMessageDate > ( ) ) { <nl> dateh = date - > height ( ) ; <nl> - / / if ( clip . intersects ( QRect ( 0 , 0 , _history - > width , dateh ) ) ) { <nl> - / / date - > paint ( p , 0 , _history - > width ) ; <nl> - / / } <nl> p . translate ( 0 , dateh ) ; <nl> clip . translate ( 0 , - dateh ) ; <nl> height - = dateh ; <nl> } <nl> if ( auto unreadbar = Get < HistoryMessageUnreadBar > ( ) ) { <nl> unreadbarh = unreadbar - > height ( ) ; <nl> - if ( clip . intersects ( QRect ( 0 , 0 , _history - > width , unreadbarh ) ) ) { <nl> - unreadbar - > paint ( p , 0 , _history - > width ) ; <nl> + if ( clip . intersects ( QRect ( 0 , 0 , width ( ) , unreadbarh ) ) ) { <nl> + unreadbar - > paint ( p , 0 , width ( ) ) ; <nl> } <nl> p . translate ( 0 , unreadbarh ) ; <nl> clip . translate ( 0 , - unreadbarh ) ; <nl> void HistoryService : : draw ( Painter & p , const QRect & r , TextSelection selection , T <nl> HistoryLayout : : PaintContext context ( ms , clip , selection ) ; <nl> HistoryLayout : : ServiceMessagePainter : : paint ( p , this , context , height ) ; <nl> <nl> - if ( int skiph = dateh + unreadbarh ) { <nl> + if ( auto skiph = dateh + unreadbarh ) { <nl> p . translate ( 0 , - skiph ) ; <nl> } <nl> } <nl> <nl> - int32 HistoryService : : resizeGetHeight_ ( int32 width ) { <nl> + int HistoryService : : resizeContentGetHeight ( ) { <nl> _height = displayedDateHeight ( ) ; <nl> if ( auto unreadbar = Get < HistoryMessageUnreadBar > ( ) ) { <nl> _height + = unreadbar - > height ( ) ; <nl> int32 HistoryService : : resizeGetHeight_ ( int32 width ) { <nl> if ( _text . isEmpty ( ) ) { <nl> _textHeight = 0 ; <nl> } else { <nl> - int32 maxwidth = _history - > width ; <nl> + auto contentWidth = width ( ) ; <nl> if ( Adaptive : : ChatWide ( ) ) { <nl> - maxwidth = qMin ( maxwidth , int32 ( st : : msgMaxWidth + 2 * st : : msgPhotoSkip + 2 * st : : msgMargin . left ( ) ) ) ; <nl> + accumulate_min ( contentWidth , st : : msgMaxWidth + 2 * st : : msgPhotoSkip + 2 * st : : msgMargin . left ( ) ) ; <nl> + } <nl> + contentWidth - = st : : msgServiceMargin . left ( ) + st : : msgServiceMargin . left ( ) ; / / two small margins <nl> + if ( contentWidth < st : : msgServicePadding . left ( ) + st : : msgServicePadding . right ( ) + 1 ) { <nl> + contentWidth = st : : msgServicePadding . left ( ) + st : : msgServicePadding . right ( ) + 1 ; <nl> } <nl> - if ( width > maxwidth ) width = maxwidth ; <nl> - width - = st : : msgServiceMargin . left ( ) + st : : msgServiceMargin . left ( ) ; / / two small margins <nl> - if ( width < st : : msgServicePadding . left ( ) + st : : msgServicePadding . right ( ) + 1 ) width = st : : msgServicePadding . left ( ) + st : : msgServicePadding . right ( ) + 1 ; <nl> <nl> - int32 nwidth = qMax ( width - st : : msgServicePadding . left ( ) - st : : msgServicePadding . right ( ) , 0 ) ; <nl> + auto nwidth = qMax ( contentWidth - st : : msgServicePadding . left ( ) - st : : msgServicePadding . right ( ) , 0 ) ; <nl> if ( nwidth ! = _textWidth ) { <nl> _textWidth = nwidth ; <nl> _textHeight = _text . countHeight ( nwidth ) ; <nl> } <nl> - if ( width > = _maxw ) { <nl> + if ( contentWidth > = _maxw ) { <nl> _height + = _minh ; <nl> } else { <nl> _height + = _textHeight ; <nl> int32 HistoryService : : resizeGetHeight_ ( int32 width ) { <nl> } <nl> <nl> bool HistoryService : : hasPoint ( int x , int y ) const { <nl> - int left = 0 , width = 0 , height = _height - st : : msgServiceMargin . top ( ) - st : : msgServiceMargin . bottom ( ) ; / / two small margins <nl> - countPositionAndSize ( left , width ) ; <nl> - if ( width < 1 ) return false ; <nl> + auto g = countGeometry ( ) ; <nl> + if ( g . width ( ) < 1 ) { <nl> + return false ; <nl> + } <nl> <nl> - if ( int dateh = displayedDateHeight ( ) ) { <nl> - y - = dateh ; <nl> - height - = dateh ; <nl> + if ( auto dateh = displayedDateHeight ( ) ) { <nl> + g . setTop ( g . top ( ) + dateh ) ; <nl> } <nl> if ( auto unreadbar = Get < HistoryMessageUnreadBar > ( ) ) { <nl> - int unreadbarh = unreadbar - > height ( ) ; <nl> - y - = unreadbarh ; <nl> - height - = unreadbarh ; <nl> + g . setTop ( g . top ( ) + unreadbar - > height ( ) ) ; <nl> } <nl> - <nl> if ( _media ) { <nl> - height - = st : : msgServiceMargin . top ( ) + _media - > height ( ) ; <nl> + g . setHeight ( g . height ( ) - ( st : : msgServiceMargin . top ( ) + _media - > height ( ) ) ) ; <nl> } <nl> - return QRect ( left , st : : msgServiceMargin . top ( ) , width , height ) . contains ( x , y ) ; <nl> + return g . contains ( x , y ) ; <nl> } <nl> <nl> HistoryTextState HistoryService : : getState ( int x , int y , HistoryStateRequest request ) const { <nl> HistoryTextState result ; <nl> <nl> - int left = 0 , width = 0 , height = _height - st : : msgServiceMargin . top ( ) - st : : msgServiceMargin . bottom ( ) ; / / two small margins <nl> - countPositionAndSize ( left , width ) ; <nl> - if ( width < 1 ) return result ; <nl> + auto g = countGeometry ( ) ; <nl> + if ( g . width ( ) < 1 ) { <nl> + return result ; <nl> + } <nl> <nl> - if ( int dateh = displayedDateHeight ( ) ) { <nl> + if ( auto dateh = displayedDateHeight ( ) ) { <nl> y - = dateh ; <nl> - height - = dateh ; <nl> + g . setHeight ( g . height ( ) - dateh ) ; <nl> } <nl> if ( auto unreadbar = Get < HistoryMessageUnreadBar > ( ) ) { <nl> - int unreadbarh = unreadbar - > height ( ) ; <nl> + auto unreadbarh = unreadbar - > height ( ) ; <nl> y - = unreadbarh ; <nl> - height - = unreadbarh ; <nl> + g . setHeight ( g . height ( ) - unreadbarh ) ; <nl> } <nl> <nl> if ( _media ) { <nl> - height - = st : : msgServiceMargin . top ( ) + _media - > height ( ) ; <nl> + g . setHeight ( g . height ( ) - ( st : : msgServiceMargin . top ( ) + _media - > height ( ) ) ) ; <nl> } <nl> - auto outer = QRect ( left , st : : msgServiceMargin . top ( ) , width , height ) ; <nl> - auto trect = outer . marginsAdded ( - st : : msgServicePadding ) ; <nl> + auto trect = g . marginsAdded ( - st : : msgServicePadding ) ; <nl> if ( trect . contains ( x , y ) ) { <nl> auto textRequest = request . forText ( ) ; <nl> textRequest . align = style : : al_center ; <nl> result = _text . getState ( x - trect . x ( ) , y - trect . y ( ) , trect . width ( ) , textRequest ) ; <nl> if ( auto gamescore = Get < HistoryServiceGameScore > ( ) ) { <nl> - if ( ! result . link & & result . cursor = = HistoryInTextCursorState & & outer . contains ( x , y ) ) { <nl> + if ( ! result . link & & result . cursor = = HistoryInTextCursorState & & g . contains ( x , y ) ) { <nl> result . link = gamescore - > lnk ; <nl> } <nl> } else if ( auto payment = Get < HistoryServicePayment > ( ) ) { <nl> - if ( ! result . link & & result . cursor = = HistoryInTextCursorState & & outer . contains ( x , y ) ) { <nl> + if ( ! result . link & & result . cursor = = HistoryInTextCursorState & & g . contains ( x , y ) ) { <nl> result . link = payment - > lnk ; <nl> } <nl> } <nl> } else if ( _media ) { <nl> - result = _media - > getState ( x - st : : msgServiceMargin . left ( ) - ( width - _media - > maxWidth ( ) ) / 2 , y - st : : msgServiceMargin . top ( ) - height - st : : msgServiceMargin . top ( ) , request ) ; <nl> + result = _media - > getState ( x - st : : msgServiceMargin . left ( ) - ( g . width ( ) - _media - > maxWidth ( ) ) / 2 , y - st : : msgServiceMargin . top ( ) - g . height ( ) - st : : msgServiceMargin . top ( ) , request ) ; <nl> } <nl> return result ; <nl> } <nl> mmm a / Telegram / SourceFiles / history / history_message . h <nl> ppp b / Telegram / SourceFiles / history / history_message . h <nl> void historyInitMessages ( ) ; <nl> <nl> class HistoryMessage : public HistoryItem , private HistoryItemInstantiated < HistoryMessage > { <nl> public : <nl> - static HistoryMessage * create ( History * history , const MTPDmessage & msg ) { <nl> + static gsl : : not_null < HistoryMessage * > create ( gsl : : not_null < History * > history , const MTPDmessage & msg ) { <nl> return _create ( history , msg ) ; <nl> } <nl> - static HistoryMessage * create ( History * history , const MTPDmessageService & msg ) { <nl> + static gsl : : not_null < HistoryMessage * > create ( gsl : : not_null < History * > history , const MTPDmessageService & msg ) { <nl> return _create ( history , msg ) ; <nl> } <nl> - static HistoryMessage * create ( History * history , MsgId msgId , MTPDmessage : : Flags flags , QDateTime date , int32 from , HistoryMessage * fwd ) { <nl> + static gsl : : not_null < HistoryMessage * > create ( gsl : : not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , QDateTime date , int32 from , HistoryMessage * fwd ) { <nl> return _create ( history , msgId , flags , date , from , fwd ) ; <nl> } <nl> - static HistoryMessage * create ( History * history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , const TextWithEntities & textWithEntities ) { <nl> + static gsl : : not_null < HistoryMessage * > create ( gsl : : not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , const TextWithEntities & textWithEntities ) { <nl> return _create ( history , msgId , flags , replyTo , viaBotId , date , from , textWithEntities ) ; <nl> } <nl> - static HistoryMessage * create ( History * history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , DocumentData * doc , const QString & caption , const MTPReplyMarkup & markup ) { <nl> + static gsl : : not_null < HistoryMessage * > create ( gsl : : not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , DocumentData * doc , const QString & caption , const MTPReplyMarkup & markup ) { <nl> return _create ( history , msgId , flags , replyTo , viaBotId , date , from , doc , caption , markup ) ; <nl> } <nl> - static HistoryMessage * create ( History * history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , PhotoData * photo , const QString & caption , const MTPReplyMarkup & markup ) { <nl> + static gsl : : not_null < HistoryMessage * > create ( gsl : : not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , PhotoData * photo , const QString & caption , const MTPReplyMarkup & markup ) { <nl> return _create ( history , msgId , flags , replyTo , viaBotId , date , from , photo , caption , markup ) ; <nl> } <nl> - static HistoryMessage * create ( History * history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , GameData * game , const MTPReplyMarkup & markup ) { <nl> + static gsl : : not_null < HistoryMessage * > create ( gsl : : not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , GameData * game , const MTPReplyMarkup & markup ) { <nl> return _create ( history , msgId , flags , replyTo , viaBotId , date , from , game , markup ) ; <nl> } <nl> <nl> class HistoryMessage : public HistoryItem , private HistoryItemInstantiated < Histo <nl> void fromNameUpdated ( int32 width ) const ; <nl> <nl> int32 plainMaxWidth ( ) const ; <nl> - void countPositionAndSize ( int32 & left , int32 & width ) const ; <nl> + QRect countGeometry ( ) const ; <nl> <nl> bool drawBubble ( ) const ; <nl> bool hasBubble ( ) const override { <nl> class HistoryMessage : public HistoryItem , private HistoryItemInstantiated < Histo <nl> void drawInfo ( Painter & p , int32 right , int32 bottom , int32 width , bool selected , InfoDisplayType type ) const override ; <nl> void setViewsCount ( int32 count ) override ; <nl> void setId ( MsgId newId ) override ; <nl> - void draw ( Painter & p , const QRect & r , TextSelection selection , TimeMs ms ) const override ; <nl> + void draw ( Painter & p , QRect clip , TextSelection selection , TimeMs ms ) const override ; <nl> <nl> void dependencyItemRemoved ( HistoryItem * dependency ) override ; <nl> <nl> class HistoryMessage : public HistoryItem , private HistoryItemInstantiated < Histo <nl> ~ HistoryMessage ( ) ; <nl> <nl> private : <nl> - HistoryMessage ( History * history , const MTPDmessage & msg ) ; <nl> - HistoryMessage ( History * history , const MTPDmessageService & msg ) ; <nl> - HistoryMessage ( History * history , MsgId msgId , MTPDmessage : : Flags flags , QDateTime date , int32 from , HistoryMessage * fwd ) ; / / local forwarded <nl> - HistoryMessage ( History * history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , const TextWithEntities & textWithEntities ) ; / / local message <nl> - HistoryMessage ( History * history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , DocumentData * doc , const QString & caption , const MTPReplyMarkup & markup ) ; / / local document <nl> - HistoryMessage ( History * history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , PhotoData * photo , const QString & caption , const MTPReplyMarkup & markup ) ; / / local photo <nl> - HistoryMessage ( History * history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , GameData * game , const MTPReplyMarkup & markup ) ; / / local game <nl> + HistoryMessage ( gsl : : not_null < History * > history , const MTPDmessage & msg ) ; <nl> + HistoryMessage ( gsl : : not_null < History * > history , const MTPDmessageService & msg ) ; <nl> + HistoryMessage ( gsl : : not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , QDateTime date , int32 from , HistoryMessage * fwd ) ; / / local forwarded <nl> + HistoryMessage ( gsl : : not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , const TextWithEntities & textWithEntities ) ; / / local message <nl> + HistoryMessage ( gsl : : not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , DocumentData * doc , const QString & caption , const MTPReplyMarkup & markup ) ; / / local document <nl> + HistoryMessage ( gsl : : not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , PhotoData * photo , const QString & caption , const MTPReplyMarkup & markup ) ; / / local photo <nl> + HistoryMessage ( gsl : : not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , int32 viaBotId , QDateTime date , int32 from , GameData * game , const MTPReplyMarkup & markup ) ; / / local game <nl> friend class HistoryItemInstantiated < HistoryMessage > ; <nl> <nl> void setEmptyText ( ) ; <nl> class HistoryMessage : public HistoryItem , private HistoryItemInstantiated < Histo <nl> void replaceBuyWithReceiptInMarkup ( ) ; <nl> <nl> void initDimensions ( ) override ; <nl> - int resizeGetHeight_ ( int width ) override ; <nl> - int performResizeGetHeight ( int width ) ; <nl> + int resizeContentGetHeight ( ) override ; <nl> + int performResizeGetHeight ( ) ; <nl> void applyEditionToEmpty ( ) ; <nl> <nl> bool displayForwardedFrom ( ) const { <nl> class HistoryService : public HistoryItem , private HistoryItemInstantiated < Histo <nl> QList < ClickHandlerPtr > links ; <nl> } ; <nl> <nl> - static HistoryService * create ( History * history , const MTPDmessageService & message ) { <nl> + static gsl : : not_null < HistoryService * > create ( gsl : : not_null < History * > history , const MTPDmessageService & message ) { <nl> return _create ( history , message ) ; <nl> } <nl> - static HistoryService * create ( History * history , MsgId msgId , QDateTime date , const PreparedText & message , MTPDmessage : : Flags flags = 0 , UserId from = 0 , PhotoData * photo = nullptr ) { <nl> + static gsl : : not_null < HistoryService * > create ( gsl : : not_null < History * > history , MsgId msgId , QDateTime date , const PreparedText & message , MTPDmessage : : Flags flags = 0 , UserId from = 0 , PhotoData * photo = nullptr ) { <nl> return _create ( history , msgId , date , message , flags , from , photo ) ; <nl> } <nl> <nl> class HistoryService : public HistoryItem , private HistoryItemInstantiated < Histo <nl> return true ; <nl> } <nl> <nl> - void countPositionAndSize ( int32 & left , int32 & width ) const ; <nl> + QRect countGeometry ( ) const ; <nl> <nl> - void draw ( Painter & p , const QRect & r , TextSelection selection , TimeMs ms ) const override ; <nl> + void draw ( Painter & p , QRect clip , TextSelection selection , TimeMs ms ) const override ; <nl> bool hasPoint ( int x , int y ) const override ; <nl> HistoryTextState getState ( int x , int y , HistoryStateRequest request ) const override ; <nl> <nl> class HistoryService : public HistoryItem , private HistoryItemInstantiated < Histo <nl> protected : <nl> friend class HistoryLayout : : ServiceMessagePainter ; <nl> <nl> - HistoryService ( History * history , const MTPDmessageService & message ) ; <nl> - HistoryService ( History * history , MsgId msgId , QDateTime date , const PreparedText & message , MTPDmessage : : Flags flags = 0 , UserId from = 0 , PhotoData * photo = 0 ) ; <nl> + HistoryService ( gsl : : not_null < History * > history , const MTPDmessageService & message ) ; <nl> + HistoryService ( gsl : : not_null < History * > history , MsgId msgId , QDateTime date , const PreparedText & message , MTPDmessage : : Flags flags = 0 , UserId from = 0 , PhotoData * photo = 0 ) ; <nl> friend class HistoryItemInstantiated < HistoryService > ; <nl> <nl> void initDimensions ( ) override ; <nl> - int resizeGetHeight_ ( int width ) override ; <nl> + int resizeContentGetHeight ( ) override ; <nl> <nl> void setServiceText ( const PreparedText & prepared ) ; <nl> <nl> class HistoryService : public HistoryItem , private HistoryItemInstantiated < Histo <nl> <nl> class HistoryJoined : public HistoryService , private HistoryItemInstantiated < HistoryJoined > { <nl> public : <nl> - static HistoryJoined * create ( gsl : : not_null < History * > history , const QDateTime & inviteDate , gsl : : not_null < UserData * > inviter , MTPDmessage : : Flags flags ) { <nl> + static gsl : : not_null < HistoryJoined * > create ( gsl : : not_null < History * > history , const QDateTime & inviteDate , gsl : : not_null < UserData * > inviter , MTPDmessage : : Flags flags ) { <nl> return _create ( history , inviteDate , inviter , flags ) ; <nl> } <nl> <nl> mmm a / Telegram / SourceFiles / history / history_service_layout . cpp <nl> ppp b / Telegram / SourceFiles / history / history_service_layout . cpp <nl> int WideChatWidth ( ) { <nl> } <nl> <nl> void ServiceMessagePainter : : paint ( Painter & p , const HistoryService * message , const PaintContext & context , int height ) { <nl> - int left = 0 , width = 0 ; <nl> - message - > countPositionAndSize ( left , width ) ; <nl> - if ( width < 1 ) return ; <nl> + auto g = message - > countGeometry ( ) ; <nl> + if ( g . width ( ) < 1 ) return ; <nl> <nl> auto fullAnimMs = App : : main ( ) ? App : : main ( ) - > animActiveTimeStart ( message ) : 0LL ; <nl> if ( fullAnimMs > 0 & & fullAnimMs < = context . ms ) { <nl> void ServiceMessagePainter : : paint ( Painter & p , const HistoryService * message , con <nl> <nl> if ( auto media = message - > getMedia ( ) ) { <nl> height - = st : : msgServiceMargin . top ( ) + media - > height ( ) ; <nl> - int32 left = st : : msgServiceMargin . left ( ) + ( width - media - > maxWidth ( ) ) / 2 , top = st : : msgServiceMargin . top ( ) + height + st : : msgServiceMargin . top ( ) ; <nl> + auto left = st : : msgServiceMargin . left ( ) + ( g . width ( ) - media - > maxWidth ( ) ) / 2 , top = st : : msgServiceMargin . top ( ) + height + st : : msgServiceMargin . top ( ) ; <nl> p . translate ( left , top ) ; <nl> media - > draw ( p , context . clip . translated ( - left , - top ) , message - > toMediaSelection ( context . selection ) , context . ms ) ; <nl> p . translate ( - left , - top ) ; <nl> } <nl> <nl> - QRect trect ( QRect ( left , st : : msgServiceMargin . top ( ) , width , height ) . marginsAdded ( - st : : msgServicePadding ) ) ; <nl> + auto trect = QRect ( g . left ( ) , st : : msgServiceMargin . top ( ) , g . width ( ) , height ) . marginsAdded ( - st : : msgServicePadding ) ; <nl> <nl> - paintComplexBubble ( p , left , width , message - > _text , trect ) ; <nl> - <nl> - if ( width > message - > maxWidth ( ) ) { <nl> - left + = ( width - message - > maxWidth ( ) ) / 2 ; <nl> - width = message - > maxWidth ( ) ; <nl> - } <nl> + paintComplexBubble ( p , g . left ( ) , g . width ( ) , message - > _text , trect ) ; <nl> <nl> p . setBrush ( Qt : : NoBrush ) ; <nl> p . setPen ( st : : msgServiceFg ) ; <nl>
Add to each history item its own width value .
telegramdesktop/tdesktop
507b7d71937c0756f9734297dd7968f0972c9879
2017-06-30T06:21:41Z
mmm a / Telegram / SourceFiles / apiwrap . cpp <nl> ppp b / Telegram / SourceFiles / apiwrap . cpp <nl> FileLoadTo ApiWrap : : fileLoadTaskOptions ( const SendOptions & options ) const { <nl> options . replyTo ) ; <nl> } <nl> <nl> + void ApiWrap : : requestSupportContact ( FnMut < void ( const MTPUser & ) > callback ) { <nl> + _supportContactCallbacks . push_back ( std : : move ( callback ) ) ; <nl> + if ( _supportContactCallbacks . size ( ) > 1 ) { <nl> + return ; <nl> + } <nl> + request ( MTPhelp_GetSupport ( <nl> + ) ) . done ( [ = ] ( const MTPhelp_Support & result ) { <nl> + result . match ( [ & ] ( const MTPDhelp_support & data ) { <nl> + for ( auto & handler : base : : take ( _supportContactCallbacks ) ) { <nl> + handler ( data . vuser ) ; <nl> + } <nl> + } ) ; <nl> + } ) . fail ( [ = ] ( const RPCError & error ) { <nl> + _supportContactCallbacks . clear ( ) ; <nl> + } ) . send ( ) ; <nl> + } <nl> + <nl> void ApiWrap : : readServerHistory ( not_null < History * > history ) { <nl> if ( history - > unreadCount ( ) ) { <nl> readServerHistoryForce ( history ) ; <nl> mmm a / Telegram / SourceFiles / apiwrap . h <nl> ppp b / Telegram / SourceFiles / apiwrap . h <nl> class ApiWrap : private MTP : : Sender , private base : : Subscriber { <nl> TextWithEntities caption , <nl> const SendOptions & options ) ; <nl> <nl> + void requestSupportContact ( FnMut < void ( const MTPUser & ) > callback ) ; <nl> + <nl> ~ ApiWrap ( ) ; <nl> <nl> private : <nl> class ApiWrap : private MTP : : Sender , private base : : Subscriber { <nl> TimeMs _termsUpdateSendAt = 0 ; <nl> mtpRequestId _termsUpdateRequestId = 0 ; <nl> <nl> + std : : vector < FnMut < void ( const MTPUser & ) > > _supportContactCallbacks ; <nl> + <nl> } ; <nl> mmm a / Telegram / SourceFiles / settings / settings . style <nl> ppp b / Telegram / SourceFiles / settings / settings . style <nl> settingsButtonRightPosition : point ( 28px , 10px ) ; <nl> settingsButtonRight : FlatLabel ( defaultFlatLabel ) { <nl> textFg : windowActiveTextFg ; <nl> } <nl> + settingsScalePadding : margins ( 79px , 10px , 28px , 8px ) ; <nl> + settingsSlider : SettingsSlider ( defaultSettingsSlider ) { <nl> + labelFg : windowSubTextFg ; <nl> + labelFgActive : windowActiveTextFg ; <nl> + } <nl> mmm a / Telegram / SourceFiles / settings / settings_main . cpp <nl> ppp b / Telegram / SourceFiles / settings / settings_main . cpp <nl> For license and copyright information please follow this link : <nl> # include " boxes / abstract_box . h " <nl> # include " boxes / language_box . h " <nl> # include " boxes / confirm_box . h " <nl> + # include " boxes / about_box . h " <nl> # include " ui / wrap / vertical_layout . h " <nl> # include " ui / wrap / padding_wrap . h " <nl> # include " ui / widgets / labels . h " <nl> For license and copyright information please follow this link : <nl> # include " info / profile / info_profile_cover . h " <nl> # include " lang / lang_keys . h " <nl> # include " storage / localstorage . h " <nl> + # include " auth_session . h " <nl> + # include " apiwrap . h " <nl> # include " styles / style_settings . h " <nl> <nl> namespace Settings { <nl> void SetupInterfaceScale ( not_null < Ui : : VerticalLayout * > container ) { <nl> container , <nl> rpl : : event_stream < bool > ( ) ) ; <nl> <nl> + const auto switched = ( cConfigScale ( ) = = dbisAuto ) <nl> + | | ( cConfigScale ( ) = = cScreenScale ( ) ) ; <nl> const auto button = container - > add ( object_ptr < Button > ( <nl> container , <nl> Lang : : Viewer ( lng_settings_default_scale ) , <nl> st : : settingsSectionButton ) <nl> - ) - > toggleOn ( toggled - > events_starting_with ( cConfigScale ( ) = = dbisAuto ) ) ; <nl> + ) - > toggleOn ( toggled - > events_starting_with_copy ( switched ) ) ; <nl> <nl> const auto slider = container - > add ( <nl> - object_ptr < Ui : : SettingsSlider > ( container ) , <nl> - st : : settingsSectionButton . padding ) ; <nl> + object_ptr < Ui : : SettingsSlider > ( container , st : : settingsSlider ) , <nl> + st : : settingsScalePadding ) ; <nl> <nl> const auto inSetScale = Ui : : AttachAsChild ( container , false ) ; <nl> const auto setScale = std : : make_shared < Fn < void ( DBIScale ) > > ( ) ; <nl> void SetupInterfaceScale ( not_null < Ui : : VerticalLayout * > container ) { <nl> <nl> if ( cEvalScale ( scale ) ! = cEvalScale ( cRealScale ( ) ) ) { <nl> const auto confirmed = crl : : guard ( button , [ = ] { <nl> - cSetConfigScale ( scale ) ; <nl> + cSetConfigScale ( applying ) ; <nl> Local : : writeSettings ( ) ; <nl> App : : restart ( ) ; <nl> } ) ; <nl> void SetupInterfaceScale ( not_null < Ui : : VerticalLayout * > container ) { <nl> AddSkip ( container ) ; <nl> } <nl> <nl> + void SetupHelp ( not_null < Ui : : VerticalLayout * > container ) { <nl> + AddDivider ( container ) ; <nl> + AddSkip ( container ) ; <nl> + <nl> + container - > add ( object_ptr < Button > ( <nl> + container , <nl> + Lang : : Viewer ( lng_settings_faq ) , <nl> + st : : settingsSectionButton ) <nl> + ) - > addClickHandler ( [ ] { <nl> + QDesktopServices : : openUrl ( telegramFaqLink ( ) ) ; <nl> + } ) ; <nl> + <nl> + if ( AuthSession : : Exists ( ) ) { <nl> + const auto button = container - > add ( object_ptr < Button > ( <nl> + container , <nl> + Lang : : Viewer ( lng_settings_ask_question ) , <nl> + st : : settingsSectionButton ) ) ; <nl> + button - > addClickHandler ( [ = ] { <nl> + const auto ready = crl : : guard ( button , [ ] ( const MTPUser & data ) { <nl> + const auto users = MTP_vector < MTPUser > ( 1 , data ) ; <nl> + if ( const auto user = App : : feedUsers ( users ) ) { <nl> + Ui : : showPeerHistory ( user , ShowAtUnreadMsgId ) ; <nl> + } <nl> + } ) ; <nl> + Auth ( ) . api ( ) . requestSupportContact ( ready ) ; <nl> + } ) ; <nl> + } <nl> + <nl> + AddSkip ( container ) ; <nl> + } <nl> + <nl> } / / namespace <nl> <nl> Main : : Main ( <nl> void Main : : setupContent ( not_null < Window : : Controller * > controller ) { <nl> <nl> setupSections ( content ) ; <nl> SetupInterfaceScale ( content ) ; <nl> + SetupHelp ( content ) ; <nl> <nl> Ui : : ResizeFitChild ( this , content ) ; <nl> } <nl>
Add FAQ and support buttons to settings .
telegramdesktop/tdesktop
e2207e33eff16f51da459255e8f843c828ce197b
2018-09-19T16:22:13Z
mmm a / xbmc / filesystem / CurlFile . cpp <nl> ppp b / xbmc / filesystem / CurlFile . cpp <nl> void CCurlFile : : SetCommonOptions ( CReadState * state , bool failOnError / * = true * <nl> else <nl> { <nl> g_curlInterface . easy_setopt ( h , CURLOPT_REFERER , NULL ) ; <nl> - g_curlInterface . easy_setopt ( h , CURLOPT_AUTOREFERER , CURL_ON ) ; <nl> + / / Do not send referer header on redirects ( same behaviour as ffmpeg and browsers ) <nl> + g_curlInterface . easy_setopt ( h , CURLOPT_AUTOREFERER , CURL_OFF ) ; <nl> } <nl> <nl> / / setup any requested authentication <nl>
Merge pull request from matthuisman / no_auto_referrer
xbmc/xbmc
7d6f7f812c6593b0ed4113e52fe354f6b61b856f
2020-07-03T15:50:58Z
mmm a / editor / import / resource_importer_scene . cpp <nl> ppp b / editor / import / resource_importer_scene . cpp <nl> void ResourceImporterScene : : get_import_options ( List < ImportOption > * r_options , in <nl> <nl> r_options - > push_back ( ImportOption ( PropertyInfo ( Variant : : STRING , " nodes / custom_script " , PROPERTY_HINT_FILE , script_ext_hint ) , " " ) ) ; <nl> r_options - > push_back ( ImportOption ( PropertyInfo ( Variant : : INT , " nodes / storage " , PROPERTY_HINT_ENUM , " Single Scene , Instanced Sub - Scenes " ) , scenes_out ? 1 : 0 ) ) ; <nl> - r_options - > push_back ( ImportOption ( PropertyInfo ( Variant : : INT , " materials / location " , PROPERTY_HINT_ENUM , " Node , Mesh " ) , meshes_out ? 1 : 0 ) ) ; <nl> + r_options - > push_back ( ImportOption ( PropertyInfo ( Variant : : INT , " materials / location " , PROPERTY_HINT_ENUM , " Node , Mesh " ) , ( meshes_out | | materials_out ) ? 1 : 0 ) ) ; <nl> r_options - > push_back ( ImportOption ( PropertyInfo ( Variant : : INT , " materials / storage " , PROPERTY_HINT_ENUM , " Built - In , Files " , PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED ) , materials_out ? 1 : 0 ) ) ; <nl> r_options - > push_back ( ImportOption ( PropertyInfo ( Variant : : BOOL , " materials / keep_on_reimport " ) , materials_out ? true : false ) ) ; <nl> r_options - > push_back ( ImportOption ( PropertyInfo ( Variant : : BOOL , " meshes / compress " ) , true ) ) ; <nl> r_options - > push_back ( ImportOption ( PropertyInfo ( Variant : : BOOL , " meshes / ensure_tangents " ) , true ) ) ; <nl> r_options - > push_back ( ImportOption ( PropertyInfo ( Variant : : INT , " meshes / storage " , PROPERTY_HINT_ENUM , " Built - In , Files " ) , meshes_out ? true : false ) ) ; <nl> - r_options - > push_back ( ImportOption ( PropertyInfo ( Variant : : BOOL , " external_files / store_in_subdir " ) , true ) ) ; <nl> + r_options - > push_back ( ImportOption ( PropertyInfo ( Variant : : BOOL , " external_files / store_in_subdir " ) , false ) ) ; <nl> r_options - > push_back ( ImportOption ( PropertyInfo ( Variant : : BOOL , " animation / import " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED ) , true ) ) ; <nl> r_options - > push_back ( ImportOption ( PropertyInfo ( Variant : : REAL , " animation / fps " , PROPERTY_HINT_RANGE , " 1 , 120 , 1 " ) , 15 ) ) ; <nl> r_options - > push_back ( ImportOption ( PropertyInfo ( Variant : : STRING , " animation / filter_script " , PROPERTY_HINT_MULTILINE_TEXT ) , " " ) ) ; <nl> mmm a / editor / import / resource_importer_scene . h <nl> ppp b / editor / import / resource_importer_scene . h <nl> class ResourceImporterScene : public ResourceImporter { <nl> static ResourceImporterScene * singleton ; <nl> <nl> enum Presets { <nl> - PRESET_SINGLE_SCENE , <nl> PRESET_SEPARATE_MATERIALS , <nl> PRESET_SEPARATE_MESHES , <nl> + PRESET_SINGLE_SCENE , <nl> PRESET_SEPARATE_MESHES_AND_MATERIALS , <nl> PRESET_MULTIPLE_SCENES , <nl> PRESET_MULTIPLE_SCENES_AND_MATERIALS , <nl>
Changed defaults , as it seems to be obviousy better to keep materials outside by default . .
godotengine/godot
efcafab6255ea78365e519ca3a13e9bf8b2a81d4
2017-08-30T00:54:26Z
mmm a / ports / physfs / portfile . cmake <nl> ppp b / ports / physfs / portfile . cmake <nl> <nl> - include ( vcpkg_common_functions ) <nl> + vcpkg_fail_port_install ( ON_ARCH " arm64 " ) <nl> set ( PHYSFS_VERSION 3 . 0 . 2 ) <nl> <nl> vcpkg_download_distfile ( ARCHIVE <nl>
fix clean
microsoft/vcpkg
b0037f4621d4fd5a434259e99ddd48893b3451e5
2020-04-13T03:40:43Z
mmm a / stdlib / public / CMakeLists . txt <nl> ppp b / stdlib / public / CMakeLists . txt <nl> if ( CXX_SUPPORTS_DEFAULT_HIDDEN_VISIBILITY ) <nl> list ( APPEND SWIFT_RUNTIME_CORE_CXX_FLAGS " - fvisibility = hidden " ) <nl> endif ( ) <nl> <nl> + add_subdirectory ( SwiftShims ) <nl> + <nl> if ( SWIFT_BUILD_STDLIB ) <nl> # These must be kept in dependency order so that any referenced targets <nl> # exist at the time we look for them in add_swift_ * . <nl> - add_subdirectory ( SwiftShims ) <nl> add_subdirectory ( runtime ) <nl> add_subdirectory ( stubs ) <nl> add_subdirectory ( core ) <nl> mmm a / utils / vim / syntax / swift . vim <nl> ppp b / utils / vim / syntax / swift . vim <nl> endif <nl> syn keyword swiftKeyword <nl> \ associatedtype <nl> \ break <nl> - \ case <nl> \ catch <nl> \ continue <nl> - \ default <nl> \ defer <nl> \ do <nl> \ else <nl> syn match swiftTypeDeclaration skipwhite skipempty nextgroup = swiftType , swiftInOu <nl> syn match swiftTypeDeclaration skipwhite skipempty nextgroup = swiftType <nl> \ / - > / <nl> <nl> + syn match swiftKeyword <nl> + \ / \ < case \ > / <nl> + syn region swiftCaseLabelRegion <nl> + \ matchgroup = swiftKeyword start = / \ < case \ > / matchgroup = Delimiter end = / : / oneline contains = TOP <nl> + syn region swiftDefaultLabelRegion <nl> + \ matchgroup = swiftKeyword start = / \ < default \ > / matchgroup = Delimiter end = / : / <nl> + <nl> syn region swiftParenthesisRegion matchgroup = NONE start = / ( / end = / ) / contains = TOP <nl> <nl> syn region swiftString start = / " / skip = / \ \ \ \ \ | \ \ " / end = / " / contains = swiftInterpolationRegion <nl>
Merge remote - tracking branch ' origin / master ' into master - next
apple/swift
a33ea2675a06d8580b3d44c66c39c4ce7d710648
2018-10-08T19:09:48Z
mmm a / unittest / heap_test . cc <nl> ppp b / unittest / heap_test . cc <nl> int test_data [ ] = { 8 , 1 , 2 , - 4 , 7 , 9 , 65536 , 4 , 9 , 0 } ; <nl> / / The fixture for testing GenericHeap and DoublePtr . <nl> class HeapTest : public testing : : Test { <nl> public : <nl> + virtual ~ HeapTest ( ) ; <nl> / / Pushes the test data onto both the heap and the KDVector . <nl> void PushTestData ( GenericHeap < IntKDPair > * heap , KDVector * v ) { <nl> for ( int i = 0 ; i < ARRAYSIZE ( test_data ) ; + + i ) { <nl> class HeapTest : public testing : : Test { <nl> } <nl> } ; <nl> <nl> + / / Destructor . <nl> + / / It is defined here , so the compiler can create a single vtable <nl> + / / instead of a weak vtable ( fixes compiler warning ) . <nl> + HeapTest : : ~ HeapTest ( ) = default ; <nl> + <nl> / / Tests that a sort using a GenericHeap matches the result of a sort using <nl> / / a KDVector . <nl> TEST_F ( HeapTest , SortTest ) { <nl>
HeapTest : Add definition for virtual destructor
tesseract-ocr/tesseract
80c1235c129eaa1fbcf49f71b683517d301e3215
2018-09-04T10:11:23Z
mmm a / src / objects . cc <nl> ppp b / src / objects . cc <nl> MaybeObject * JSObject : : AddSlowProperty ( String * name , <nl> <nl> MaybeObject * JSObject : : AddProperty ( String * name , <nl> Object * value , <nl> - PropertyAttributes attributes ) { <nl> + PropertyAttributes attributes , <nl> + StrictModeFlag strict_mode ) { <nl> ASSERT ( ! IsJSGlobalProxy ( ) ) ; <nl> Heap * heap = GetHeap ( ) ; <nl> if ( ! map ( ) - > is_extensible ( ) ) { <nl> - Handle < Object > args [ 1 ] = { Handle < String > ( name ) } ; <nl> - return heap - > isolate ( ) - > Throw ( <nl> - * FACTORY - > NewTypeError ( " object_not_extensible " , HandleVector ( args , 1 ) ) ) ; <nl> + if ( strict_mode = = kNonStrictMode ) { <nl> + return heap - > undefined_value ( ) ; <nl> + } else { <nl> + Handle < Object > args [ 1 ] = { Handle < String > ( name ) } ; <nl> + return heap - > isolate ( ) - > Throw ( <nl> + * FACTORY - > NewTypeError ( " object_not_extensible " , <nl> + HandleVector ( args , 1 ) ) ) ; <nl> + } <nl> } <nl> if ( HasFastProperties ( ) ) { <nl> / / Ensure the descriptor array does not get too big . <nl> MaybeObject * JSObject : : SetPropertyPostInterceptor ( <nl> return SetProperty ( & result , name , value , attributes , strict_mode ) ; <nl> } <nl> / / Add a new real property . <nl> - return AddProperty ( name , value , attributes ) ; <nl> + return AddProperty ( name , value , attributes , strict_mode ) ; <nl> } <nl> <nl> <nl> MaybeObject * JSObject : : SetProperty ( LookupResult * result , <nl> } <nl> if ( ! result - > IsFound ( ) ) { <nl> / / Neither properties nor transitions found . <nl> - return AddProperty ( name , value , attributes ) ; <nl> + return AddProperty ( name , value , attributes , strict_mode ) ; <nl> } <nl> if ( result - > IsReadOnly ( ) & & result - > IsProperty ( ) ) { <nl> if ( strict_mode = = kStrictMode ) { <nl> MaybeObject * JSObject : : SetLocalPropertyIgnoreAttributes ( <nl> / / Check for accessor in prototype chain removed here in clone . <nl> if ( ! result . IsFound ( ) ) { <nl> / / Neither properties nor transitions found . <nl> - return AddProperty ( name , value , attributes ) ; <nl> + return AddProperty ( name , value , attributes , kNonStrictMode ) ; <nl> } <nl> <nl> PropertyDetails details = PropertyDetails ( attributes , NORMAL ) ; <nl> MaybeObject * JSObject : : SetElementWithoutInterceptor ( uint32_t index , <nl> / / When we set the is_extensible flag to false we always force <nl> / / the element into dictionary mode ( and force them to stay there ) . <nl> if ( ! map ( ) - > is_extensible ( ) ) { <nl> - Handle < Object > number ( isolate - > factory ( ) - > NewNumberFromUint ( index ) ) ; <nl> - Handle < String > index_string ( <nl> - isolate - > factory ( ) - > NumberToString ( number ) ) ; <nl> - Handle < Object > args [ 1 ] = { index_string } ; <nl> - return isolate - > Throw ( <nl> - * isolate - > factory ( ) - > NewTypeError ( " object_not_extensible " , <nl> - HandleVector ( args , 1 ) ) ) ; <nl> + if ( strict_mode = = kNonStrictMode ) { <nl> + return isolate - > heap ( ) - > undefined_value ( ) ; <nl> + } else { <nl> + Handle < Object > number ( isolate - > factory ( ) - > NewNumberFromUint ( index ) ) ; <nl> + Handle < String > index_string ( <nl> + isolate - > factory ( ) - > NumberToString ( number ) ) ; <nl> + Handle < Object > args [ 1 ] = { index_string } ; <nl> + return isolate - > Throw ( <nl> + * isolate - > factory ( ) - > NewTypeError ( " object_not_extensible " , <nl> + HandleVector ( args , 1 ) ) ) ; <nl> + } <nl> } <nl> Object * result ; <nl> { MaybeObject * maybe_result = dictionary - > AtNumberPut ( index , value ) ; <nl> mmm a / src / objects . h <nl> ppp b / src / objects . h <nl> class JSObject : public HeapObject { <nl> / / Add a property to an object . <nl> MUST_USE_RESULT MaybeObject * AddProperty ( String * name , <nl> Object * value , <nl> - PropertyAttributes attributes ) ; <nl> + PropertyAttributes attributes , <nl> + StrictModeFlag strict_mode ) ; <nl> <nl> / / Convert the object to use the canonical dictionary <nl> / / representation . If the object is expected to have additional properties <nl> mmm a / test / cctest / test - api . cc <nl> ppp b / test / cctest / test - api . cc <nl> THREADED_TEST ( ExtensibleOnUndetectable ) { <nl> <nl> source = v8_str ( " undetectable . y = 2000 ; " ) ; <nl> script = Script : : Compile ( source ) ; <nl> - v8 : : TryCatch try_catch ; <nl> Local < Value > result = script - > Run ( ) ; <nl> - CHECK ( result . IsEmpty ( ) ) ; <nl> - CHECK ( try_catch . HasCaught ( ) ) ; <nl> + ExpectBoolean ( " undetectable . y = = undefined " , true ) ; <nl> } <nl> <nl> <nl> mmm a / test / mjsunit / object - freeze . js <nl> ppp b / test / mjsunit / object - freeze . js <nl> Object . freeze ( obj ) ; <nl> assertFalse ( Object . isExtensible ( obj ) ) ; <nl> assertTrue ( Object . isFrozen ( obj ) ) ; <nl> <nl> - try { <nl> - obj . foo = 42 ; <nl> - assertUnreachable ( ) ; <nl> - } catch ( e ) { <nl> - assertTrue ( / object is not extensible / . test ( e ) ) ; <nl> - } <nl> + obj . foo = 42 ; <nl> + assertEquals ( obj . foo , undefined ) ; <nl> <nl> desc = Object . getOwnPropertyDescriptor ( obj , ' x ' ) ; <nl> assertFalse ( desc . writable ) ; <nl> assertFalse ( desc . configurable ) ; <nl> assertEquals ( " foobar " , desc . value ) ; <nl> <nl> / / Make sure that even if we try overwrite a value that is not writable , it is <nl> - / / not changed . <nl> + / / not changed . <nl> obj . x = " tete " ; <nl> assertEquals ( 42 , obj . x ) ; <nl> obj . x = { get : function ( ) { return 43 } , set : function ( ) { } } ; <nl> assertEquals ( undefined , desc . value ) ; <nl> assertEquals ( set , desc . set ) ; <nl> assertEquals ( get , desc . get ) ; <nl> <nl> - try { <nl> - obj2 . foo = 42 ; <nl> - assertUnreachable ( ) ; <nl> - } catch ( e ) { <nl> - assertTrue ( / object is not extensible / . test ( e ) ) ; <nl> - } <nl> + obj2 . foo = 42 ; <nl> + assertEquals ( obj2 . foo , undefined ) ; <nl> <nl> <nl> / / Test freeze on arrays . <nl> mmm a / test / mjsunit / object - prevent - extensions . js <nl> ppp b / test / mjsunit / object - prevent - extensions . js <nl> Object . preventExtensions ( obj1 ) ; <nl> <nl> / / Make sure the is_extensible flag is set . <nl> assertFalse ( Object . isExtensible ( obj1 ) ) ; <nl> - / / Try adding a new property . <nl> - try { <nl> - obj1 . x = 42 ; <nl> - assertUnreachable ( ) ; <nl> - } catch ( e ) { <nl> - assertTrue ( / object is not extensible / . test ( e ) ) ; <nl> - } <nl> + obj1 . x = 42 ; <nl> assertEquals ( undefined , obj1 . x ) ; <nl> <nl> / / Try adding a new element . <nl> - try { <nl> - obj1 [ 1 ] = 42 ; <nl> - assertUnreachable ( ) ; <nl> - } catch ( e ) { <nl> - assertTrue ( / object is not extensible / . test ( e ) ) ; <nl> - } <nl> + obj1 [ 1 ] = 42 ; <nl> assertEquals ( undefined , obj1 [ 1 ] ) ; <nl> <nl> <nl> assertTrue ( Object . isExtensible ( obj2 ) ) ; <nl> Object . preventExtensions ( obj2 ) ; <nl> assertEquals ( 42 , obj2 . x ) ; <nl> <nl> - try { <nl> - obj2 . y = 42 ; <nl> - assertUnreachable ( ) ; <nl> - } catch ( e ) { <nl> - assertTrue ( / object is not extensible / . test ( e ) ) ; <nl> - } <nl> - <nl> + obj2 . y = 42 ; <nl> / / obj2 . y should still be undefined . <nl> assertEquals ( undefined , obj2 . y ) ; <nl> / / Make sure we can still write values to obj . x . <nl> obj2 . x = 43 ; <nl> assertEquals ( 43 , obj2 . x ) <nl> <nl> - try { <nl> - obj2 . y = new function ( ) { return 42 ; } ; <nl> - assertUnreachable ( ) ; <nl> - } catch ( e ) { <nl> - assertTrue ( / object is not extensible / . test ( e ) ) ; <nl> - } <nl> + obj2 . y = new function ( ) { return 42 ; } ; <nl> / / obj2 . y should still be undefined . <nl> assertEquals ( undefined , obj2 . y ) ; <nl> assertEquals ( 43 , obj2 . x ) <nl> try { <nl> assertEquals ( undefined , obj2 . y ) ; <nl> assertEquals ( 43 , obj2 . x ) ; <nl> <nl> - try { <nl> - obj2 [ 1 ] = 42 ; <nl> - } catch ( e ) { <nl> - assertTrue ( / object is not extensible / . test ( e ) ) ; <nl> - } <nl> - <nl> + obj2 [ 1 ] = 42 ; <nl> assertEquals ( undefined , obj2 [ 1 ] ) ; <nl> <nl> var arr = new Array ( ) ; <nl> arr [ 1 ] = 10 ; <nl> <nl> Object . preventExtensions ( arr ) ; <nl> <nl> - try { <nl> - arr [ 2 ] = 42 ; <nl> - assertUnreachable ( ) ; <nl> - } catch ( e ) { <nl> - assertTrue ( / object is not extensible / . test ( e ) ) ; <nl> - } <nl> + arr [ 2 ] = 42 ; <nl> assertEquals ( 10 , arr [ 1 ] ) ; <nl> <nl> / / We should still be able to change exiting elements . <nl> var child = Object . create ( parent ) ; <nl> child . y = 42 ; <nl> <nl> / / This should have no influence on the parent class . <nl> - try { <nl> - parent . y = 29 ; <nl> - assertUnreachable ( ) ; <nl> - } catch ( e ) { <nl> - assertTrue ( / object is not extensible / . test ( e ) ) ; <nl> - } <nl> + parent . y = 29 ; <nl> <nl> <nl> / / Test that attributes on functions are also handled correctly . <nl> function foo ( ) { <nl> <nl> Object . preventExtensions ( foo ) ; <nl> <nl> - try { <nl> - foo . x = 29 ; <nl> - assertUnreachable ( ) ; <nl> - } catch ( e ) { <nl> - assertTrue ( / object is not extensible / . test ( e ) ) ; <nl> - } <nl> + foo . x = 29 ; <nl> + assertEquals ( undefined , foo . x ) ; <nl> mmm a / test / mjsunit / object - seal . js <nl> ppp b / test / mjsunit / object - seal . js <nl> assertTrue ( Object . isSealed ( obj ) ) ; <nl> assertFalse ( Object . isFrozen ( obj ) ) ; <nl> <nl> / / We should not allow new properties to be added . <nl> - try { <nl> - obj . foo = 42 ; <nl> - assertUnreachable ( ) ; <nl> - } catch ( e ) { <nl> - assertTrue ( / object is not extensible / . test ( e ) ) ; <nl> - } <nl> + obj . foo = 42 ; <nl> + assertEquals ( obj . foo , undefined ) ; <nl> <nl> desc = Object . getOwnPropertyDescriptor ( obj , ' x ' ) ; <nl> assertTrue ( desc . writable ) ; <nl> assertEquals ( undefined , desc . value ) ; <nl> assertEquals ( set , desc . set ) ; <nl> assertEquals ( get , desc . get ) ; <nl> <nl> - try { <nl> - obj2 . foo = 42 ; <nl> - assertUnreachable ( ) ; <nl> - } catch ( e ) { <nl> - assertTrue ( / object is not extensible / . test ( e ) ) ; <nl> - } <nl> - <nl> + obj2 . foo = 42 ; <nl> + assertEquals ( obj2 . foo , undefined ) ; <nl> <nl> / / Test seal on arrays . <nl> var arr = new Array ( 42 , 43 ) ; <nl> mmm a / test / mjsunit / regress / regress - create - exception . js <nl> ppp b / test / mjsunit / regress / regress - create - exception . js <nl> <nl> / / OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE . <nl> <nl> / / Flags : - - max - new - space - size = 256 <nl> + " use strict " ; <nl> <nl> / / Check for GC bug constructing exceptions . <nl> var v = [ 1 , 2 , 3 , 4 ] <nl> mmm a / test / mjsunit / strict - mode . js <nl> ppp b / test / mjsunit / strict - mode . js <nl> function CheckPillDescriptor ( func , name ) { <nl> function CheckPill ( pill ) { <nl> assertEquals ( " function " , typeof pill ) ; <nl> assertInstanceof ( pill , Function ) ; <nl> - assertThrows ( function ( ) { pill . property = " value " ; } , TypeError ) ; <nl> + pill . property = " value " ; <nl> + assertEquals ( pill . value , undefined ) ; <nl> + assertThrows ( function ( ) { ' use strict ' ; pill . property = " value " ; } , <nl> + TypeError ) ; <nl> assertThrows ( pill , TypeError ) ; <nl> assertEquals ( pill . prototype , ( function ( ) { } ) . prototype ) ; <nl> var d = Object . getOwnPropertyDescriptor ( pill , " prototype " ) ; <nl>
Follow jsc on not throwing when trying to add a property to a non - extensible object .
v8/v8
fb6d7e17df99fd274cdb31c23dd326bfcb67a242
2011-03-28T06:11:08Z
mmm a / tensorflow / core / kernels / data / multi_device_iterator_ops . cc <nl> ppp b / tensorflow / core / kernels / data / multi_device_iterator_ops . cc <nl> See the License for the specific language governing permissions and <nl> limitations under the License . <nl> = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * / <nl> # include < deque > <nl> + # include < memory > <nl> <nl> # include " tensorflow / core / common_runtime / input_colocation_exemption_registry . h " <nl> # include " tensorflow / core / common_runtime / process_function_library_runtime . h " <nl> class MultiDeviceIterator : public ResourceBase { <nl> + + incarnation_id_ ; <nl> * incarnation_id = incarnation_id_ ; <nl> <nl> - multi_device_buffer_ = absl : : make_unique < MultiDeviceBuffer > ( <nl> + multi_device_buffer_ = std : : make_shared < MultiDeviceBuffer > ( <nl> devices_ . size ( ) , max_buffer_size , incarnation_id_ , std : : move ( iterator ) , <nl> this ) ; <nl> return Status : : OK ( ) ; <nl> class MultiDeviceIterator : public ResourceBase { <nl> <nl> void GetNextFromShard ( OpKernelContext * ctx , int shard_num , <nl> int64 incarnation_id , std : : function < void ( ) > done ) { <nl> - tf_shared_lock l ( mu_ ) ; <nl> + / / We capture the multi - device buffer because we should not be calling the <nl> + / / ` done ` callback concurrently with holding the lock since the ` done ` <nl> + / / callback could trigger the MultiDeviceIterator destructor . <nl> + std : : shared_ptr < MultiDeviceBuffer > multi_device_buffer ; <nl> + { <nl> + tf_shared_lock l ( mu_ ) ; <nl> + multi_device_buffer = multi_device_buffer_ ; <nl> + } <nl> IteratorContext : : Params params ( ctx ) ; <nl> params . flr = flr_ ; <nl> params . function_handle_cache = function_handle_cache_ . get ( ) ; <nl> class MultiDeviceIterator : public ResourceBase { <nl> MultiDeviceIteratorCallback callback = std : : bind ( <nl> [ ctx ] ( const HostBufferElement & elem , const std : : function < void ( ) > & done , <nl> const std : : function < void ( ) > & deregister_fn ) { <nl> - / / iterator - > Unref ( ) ; <nl> Status s = elem . status ; <nl> if ( ! s . ok ( ) ) { <nl> ctx - > SetStatus ( s ) ; <nl> class MultiDeviceIterator : public ResourceBase { <nl> } , <nl> std : : placeholders : : _1 , std : : move ( done ) , std : : move ( deregister_fn ) ) ; <nl> <nl> - multi_device_buffer_ - > GetNextFromShard ( & iter_ctx , shard_num , incarnation_id , <nl> - std : : move ( callback ) ) ; <nl> + multi_device_buffer - > GetNextFromShard ( & iter_ctx , shard_num , incarnation_id , <nl> + std : : move ( callback ) ) ; <nl> } <nl> <nl> const DataTypeVector & output_types ( ) const { return output_types_ ; } <nl> class MultiDeviceIterator : public ResourceBase { <nl> CancellationManager cancellation_manager_ ; <nl> <nl> int64 incarnation_id_ GUARDED_BY ( mu_ ) = 0 ; <nl> - std : : unique_ptr < MultiDeviceBuffer > multi_device_buffer_ GUARDED_BY ( mu_ ) ; <nl> + std : : shared_ptr < MultiDeviceBuffer > multi_device_buffer_ GUARDED_BY ( mu_ ) ; <nl> } ; <nl> <nl> / / Used to generate unique names for anonymous multi device iterators . <nl> class MultiDeviceIteratorGetNextFromShardOp : public AsyncOpKernel { <nl> ctx , ctx - > input ( " incarnation_id " , & tensor_incarnation_id ) , done ) ; <nl> int64 incarnation_id = tensor_incarnation_id - > scalar < int64 > ( ) ( ) ; <nl> <nl> - core : : RefCountPtr < MultiDeviceIterator > iterator ; <nl> + MultiDeviceIterator * iterator ; <nl> OP_REQUIRES_OK_ASYNC ( <nl> ctx , LookupResource ( ctx , HandleFromInput ( ctx , 0 ) , & iterator ) , done ) ; <nl> <nl> + / / NOTE : ` iterator ` must be unreffed before ` done ` is called ( because ` done ` <nl> + / / might trigger the entire session / context to be deleted , so we move <nl> + / / the ` iterator - > Unref ( ) ` into a callback wrapper . <nl> + done = std : : bind ( <nl> + [ ] ( const DoneCallback & done , MultiDeviceIterator * iterator ) { <nl> + iterator - > Unref ( ) ; <nl> + done ( ) ; <nl> + } , <nl> + std : : move ( done ) , iterator ) ; <nl> + <nl> iterator - > GetNextFromShard ( ctx , shard_num , incarnation_id , std : : move ( done ) ) ; <nl> } <nl> } ; <nl>
[ tf . data ] Fix potential use - after - free in MultiDeviceIterator .
tensorflow/tensorflow
804f02c0eed678936f3b6fc3c1295583075d5240
2019-09-12T22:13:52Z
mmm a / hphp / runtime / base / array - data . h <nl> ppp b / hphp / runtime / base / array - data . h <nl> struct ArrayData : MaybeCountable { <nl> friend struct BaseMap ; <nl> friend struct c_Map ; <nl> friend struct c_ImmMap ; <nl> + friend struct RecordArray ; <nl> <nl> / / The following fields are blocked into unions with qwords so we <nl> / / can combine the stores when initializing arrays . ( gcc won ' t do <nl> mmm a / hphp / runtime / base / mixed - array - keys . h <nl> ppp b / hphp / runtime / base / mixed - array - keys . h <nl> struct MixedArrayKeys { <nl> static uint16_t packStaticStrsForAux ( ) { <nl> return kTrackStaticStrKeys ? ( kStaticStrKey < < 8 ) : 0 ; <nl> } <nl> + static uint16_t packStrsForAux ( ) { <nl> + return packStaticStrsForAux ( ) | ( kNonStaticStrKey < < 8 ) ; <nl> + } <nl> static uint16_t compactPacked ( uint16_t aux ) { <nl> return aux & ~ ( static_cast < uint16_t > ( kTombstoneKey ) < < 8 ) ; <nl> } <nl> mmm a / hphp / runtime / base / mixed - array . h <nl> ppp b / hphp / runtime / base / mixed - array . h <nl> struct MixedArray final : ArrayData , <nl> friend struct MemoryProfile ; <nl> friend struct EmptyArray ; <nl> friend struct PackedArray ; <nl> + friend struct RecordArray ; <nl> friend struct HashCollection ; <nl> friend struct BaseMap ; <nl> friend struct c_Map ; <nl> mmm a / hphp / runtime / base / record - array . cpp <nl> ppp b / hphp / runtime / base / record - array . cpp <nl> <nl> + mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - + <nl> * / <nl> <nl> - # include " hphp / runtime / base / packed - array - defs . h " <nl> # include " hphp / runtime / base / record - array . h " <nl> + <nl> + # include " hphp / runtime / base / mixed - array . h " <nl> # include " hphp / runtime / vm / runtime . h " <nl> # include " hphp / runtime / base / tv - refcount . h " <nl> <nl> + # include " hphp / runtime / base / mixed - array - defs . h " <nl> + # include " hphp / runtime / base / packed - array - defs . h " <nl> + <nl> namespace HPHP { <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> const RecordArray : : ExtraFieldMap * RecordArray : : extraFieldMap ( ) const { <nl> <nl> bool RecordArray : : checkInvariants ( ) const { <nl> assertx ( checkCount ( ) ) ; <nl> + assertx ( m_pos = = 0 ) ; <nl> return true ; <nl> } <nl> <nl> void RecordArray : : updateField ( StringData * key , Cell val , Slot idx ) { <nl> tvSet ( val , tv ) ; <nl> } else { <nl> auto const extraMap = const_cast < ExtraFieldMap * > ( extraFieldMap ( ) ) ; <nl> - auto const keyStr = String : : attach ( key ) ; <nl> + String keyStr ( key ) ; <nl> auto it = extraMap - > find ( keyStr ) ; <nl> if ( it = = extraMap - > end ( ) ) { <nl> + + m_size ; <nl> ArrayData * RecordArray : : SetStr ( ArrayData * base , StringData * key , Cell val ) { <nl> <nl> size_t RecordArray : : Vsize ( const ArrayData * ) { always_assert ( false ) ; } <nl> <nl> - / / TODO : T47449944 : methods below this are stubs <nl> - tv_rval RecordArray : : NvGetInt ( const ArrayData * , int64_t ) { <nl> - throw_not_implemented ( " This method on RecordArray " ) ; <nl> + MixedArray * RecordArray : : ToMixedHeader ( RecordArray * old ) { <nl> + assertx ( old - > checkInvariants ( ) ) ; <nl> + auto const extra = old - > extraFieldMap ( ) ; <nl> + auto const keyType = extra - > empty ( ) ? <nl> + MixedArrayKeys : : packStaticStrsForAux ( ) : <nl> + MixedArrayKeys : : packStrsForAux ( ) ; <nl> + auto const aux = keyType | ArrayData : : kNotDVArray ; <nl> + auto const oldSize = old - > m_size ; <nl> + auto const scale = MixedArray : : computeScaleFromSize ( oldSize ) ; <nl> + auto const ad = MixedArray : : reqAlloc ( scale ) ; <nl> + ad - > m_sizeAndPos = oldSize ; <nl> + ad - > initHeader_16 ( HeaderKind : : Mixed , OneReference , aux ) ; <nl> + ad - > m_scale_used = scale | uint64_t { oldSize } < < 32 ; / / used = oldSize <nl> + ad - > m_nextKI = 0 ; <nl> + <nl> + assertx ( ad - > m_size = = oldSize ) ; <nl> + assertx ( ad - > m_pos = = old - > m_pos ) ; <nl> + assertx ( ad - > kind ( ) = = ArrayData : : kMixedKind ) ; <nl> + assertx ( ad - > isDArray ( ) = = old - > isVArray ( ) ) ; <nl> + assertx ( ad - > hasExactlyOneRef ( ) ) ; <nl> + assertx ( ad - > m_used = = oldSize ) ; <nl> + assertx ( ad - > m_scale = = scale ) ; <nl> + assertx ( ad - > m_nextKI = = 0 ) ; <nl> + / / Can ' t checkInvariants yet , since we haven ' t populated the payload . <nl> + return ad ; <nl> } <nl> <nl> - tv_rval RecordArray : : NvTryGetInt ( const ArrayData * , int64_t ) { <nl> - throw_not_implemented ( " This method on RecordArray " ) ; <nl> + MixedArray * RecordArray : : ToMixed ( ArrayData * adIn ) { <nl> + auto const old = asRecordArray ( adIn ) ; <nl> + auto const ad = ToMixedHeader ( old ) ; <nl> + auto const mask = ad - > mask ( ) ; <nl> + auto dstData = ad - > data ( ) ; <nl> + auto const dstHash = ad - > initHash ( ad - > scale ( ) ) ; <nl> + auto const rec = old - > record ( ) ; <nl> + auto i = 0 ; <nl> + for ( ; i < rec - > numFields ( ) ; + + i ) { <nl> + auto const & field = rec - > field ( i ) ; <nl> + auto const k = field . name ( ) ; <nl> + assertx ( k - > isStatic ( ) ) ; <nl> + auto const h = k - > hash ( ) ; <nl> + dstData - > setStaticKey ( const_cast < StringData * > ( k ) , h ) ; <nl> + * ad - > findForNewInsert ( dstHash , mask , h ) = i ; <nl> + auto const & val = old - > rvalAt ( i ) ; <nl> + tvDup ( * val , dstData - > data ) ; <nl> + + + dstData ; <nl> + } <nl> + for ( auto const & p : * old - > extraFieldMap ( ) ) { <nl> + auto const k = p . first . get ( ) ; <nl> + auto const h = k - > hash ( ) ; <nl> + dstData - > setStrKey ( k , h ) ; <nl> + * ad - > findForNewInsert ( dstHash , mask , h ) = i ; <nl> + tvDup ( p . second , dstData - > data ) ; <nl> + + + dstData ; <nl> + + + i ; <nl> + } <nl> + assertx ( ad - > checkInvariants ( ) ) ; <nl> + assertx ( ad - > hasExactlyOneRef ( ) ) ; <nl> + return ad ; <nl> } <nl> <nl> - ssize_t RecordArray : : NvGetIntPos ( const ArrayData * , int64_t ) { <nl> - throw_not_implemented ( " This method on RecordArray " ) ; <nl> + tv_rval RecordArray : : NvGetInt ( const ArrayData * , int64_t key ) { <nl> + / / RecordArrays may never have int keys . <nl> + / / Setting int keys escalate them to mixed arrays <nl> + return nullptr ; <nl> } <nl> <nl> - ssize_t RecordArray : : NvGetStrPos ( const ArrayData * , const StringData * ) { <nl> - throw_not_implemented ( " This method on RecordArray " ) ; <nl> + namespace { <nl> + template < typename Op > <nl> + auto PromoteForOp ( ArrayData * ad , Op op , const std : : string & opname ) { <nl> + raise_recordarray_promotion_notice ( opname ) ; <nl> + auto const mixed = RecordArray : : ToMixed ( ad ) ; <nl> + return op ( mixed ) ; <nl> + } <nl> } <nl> <nl> - Cell RecordArray : : NvGetKey ( const ArrayData * , ssize_t ) { <nl> + ArrayData * RecordArray : : SetInt ( ArrayData * adIn , int64_t k , Cell v ) { <nl> + return PromoteForOp ( adIn , <nl> + [ & ] ( MixedArray * mixed ) { return mixed - > addVal ( k , v ) ; } , <nl> + " SetInt " <nl> + ) ; <nl> + } <nl> + <nl> + / / TODO : T47449944 : methods below this are stubs <nl> + <nl> + ssize_t RecordArray : : NvGetStrPos ( ArrayData const * , StringData const * ) { <nl> throw_not_implemented ( " This method on RecordArray " ) ; <nl> } <nl> <nl> - ArrayData * RecordArray : : SetInt ( ArrayData * , int64_t , Cell ) { <nl> + ssize_t RecordArray : : NvGetIntPos ( ArrayData const * , int64_t ) { <nl> throw_not_implemented ( " This method on RecordArray " ) ; <nl> } <nl> <nl> - ArrayData * RecordArray : : SetIntInPlace ( ArrayData * , int64_t , Cell ) { <nl> + Cell RecordArray : : NvGetKey ( const ArrayData * , ssize_t ) { <nl> throw_not_implemented ( " This method on RecordArray " ) ; <nl> } <nl> <nl> mmm a / hphp / runtime / base / record - array . h <nl> ppp b / hphp / runtime / base / record - array . h <nl> <nl> namespace HPHP { <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + struct MixedArray ; <nl> <nl> struct RecordArray : ArrayData , <nl> RecordBase , <nl> struct RecordArray : ArrayData , <nl> / / Array interface <nl> static void Release ( ArrayData * ) ; <nl> static tv_rval NvGetInt ( const ArrayData * , int64_t key ) ; <nl> - static tv_rval NvTryGetInt ( const ArrayData * , int64_t key ) ; <nl> + static constexpr auto NvTryGetInt = & NvGetInt ; <nl> static tv_rval NvGetStr ( const ArrayData * , const StringData * ) ; <nl> static constexpr auto NvTryGetStr = & NvGetStr ; <nl> static ssize_t NvGetIntPos ( const ArrayData * , int64_t k ) ; <nl> static ssize_t NvGetStrPos ( const ArrayData * , const StringData * k ) ; <nl> static Cell NvGetKey ( const ArrayData * , ssize_t pos ) ; <nl> static ArrayData * SetInt ( ArrayData * , int64_t key , Cell v ) ; <nl> - static ArrayData * SetIntInPlace ( ArrayData * , int64_t key , Cell v ) ; <nl> + static constexpr auto SetIntInPlace = & SetInt ; <nl> static ArrayData * SetStr ( ArrayData * , StringData * , Cell v ) ; <nl> static ArrayData * SetStrInPlace ( ArrayData * , StringData * , Cell v ) ; <nl> static size_t Vsize ( const ArrayData * ) ; <nl> struct RecordArray : ArrayData , <nl> static RecordArray * asRecordArray ( ArrayData * ) ; <nl> static const RecordArray * asRecordArray ( const ArrayData * ) ; <nl> <nl> + static MixedArray * ToMixed ( ArrayData * ) ; <nl> + <nl> private : <nl> using ExtraFieldMap = req : : StringFastMap < TypedValue > ; <nl> const ExtraFieldMap * extraFieldMap ( ) const ; <nl> struct RecordArray : ArrayData , <nl> * in the extra field map . <nl> * / <nl> void updateField ( StringData * key , Cell val , Slot idx ) ; <nl> + <nl> + static MixedArray * ToMixedHeader ( RecordArray * ) ; <nl> } ; <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> mmm a / hphp / runtime / base / runtime - error . cpp <nl> ppp b / hphp / runtime / base / runtime - error . cpp <nl> void raise_hackarr_compat_notice ( const std : : string & msg ) { <nl> raise_notice ( " Hack Array Compat : % s " , msg . c_str ( ) ) ; <nl> } <nl> <nl> + void raise_recordarray_promotion_notice ( const std : : string & op ) { <nl> + raise_notice ( " Record - array to mixed - array promotion for % s " , op . c_str ( ) ) ; <nl> + } <nl> + <nl> + void raise_recordarray_unsupported_op_notice ( const std : : string & op ) { <nl> + raise_notice ( " Opertation not supported for records : % s " , op . c_str ( ) ) ; <nl> + } <nl> + <nl> # define HC ( Opt , opt ) \ <nl> void raise_hac_ # # opt # # _notice ( const std : : string & msg ) { \ <nl> if ( UNLIKELY ( RID ( ) . getSuppressHAC # # Opt # # Notices ( ) ) ) return ; \ <nl> mmm a / hphp / runtime / base / runtime - error . h <nl> ppp b / hphp / runtime / base / runtime - error . h <nl> void raise_resolve_undefined ( const StringData * name , const Class * c = nullptr ) ; <nl> <nl> void raise_convert_object_to_string ( const char * cls_name ) ; <nl> void raise_convert_record_to_type ( const char * typeName ) ; <nl> + void raise_recordarray_promotion_notice ( const std : : string & op ) ; <nl> + void raise_recordarray_unsupported_op_notice ( const std : : string & op ) ; <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> / * <nl> new file mode 100644 <nl> index 00000000000 . . da7021702c6 <nl> mmm / dev / null <nl> ppp b / hphp / test / quick / recordarray - to - mixed . php <nl> <nl> + < ? hh <nl> + <nl> + class Bar { <nl> + public int $ f = 42 ; <nl> + } <nl> + <nl> + record FooBar { <nl> + z : Bar , <nl> + } <nl> + <nl> + < < __EntryPoint > > <nl> + function main ( ) { <nl> + $ o1 = new Bar ; <nl> + $ o2 = new Bar ; <nl> + $ o2 - > f = 10 ; <nl> + $ r1 = FooBar @ [ ' z ' = > $ o1 ] ; <nl> + $ key = ' abc ' . count ( [ 1 , 2 ] ) ; <nl> + $ r1 [ $ key ] = 42 ; <nl> + $ r2 = $ r1 ; <nl> + $ r1 [ 1 ] = $ o2 ; <nl> + $ r1 [ ' z ' ] = $ o2 ; <nl> + var_dump ( $ r1 ) ; <nl> + var_dump ( $ r2 [ ' z ' ] ) ; <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . 4526ac20adb <nl> mmm / dev / null <nl> ppp b / hphp / test / quick / recordarray - to - mixed . php . expectf <nl> <nl> + Notice : Record - array to mixed - array promotion for SetInt in % s / recordarray - to - mixed . php on line 20 <nl> + array ( 3 ) { <nl> + [ " z " ] = > <nl> + object ( Bar ) ( 1 ) { <nl> + [ " f " ] = > <nl> + int ( 10 ) <nl> + } <nl> + [ " abc2 " ] = > <nl> + int ( 42 ) <nl> + [ 1 ] = > <nl> + object ( Bar ) ( 1 ) { <nl> + [ " f " ] = > <nl> + int ( 10 ) <nl> + } <nl> + } <nl> + object ( Bar ) ( 1 ) { <nl> + [ " f " ] = > <nl> + int ( 42 ) <nl> + } <nl> + <nl> new file mode 100644 <nl> index 00000000000 . . 9526ac5b063 <nl> mmm / dev / null <nl> ppp b / hphp / test / quick / recordarray - to - mixed . php . hphp_opts <nl> @ @ - 0 , 0 + 1 @ @ <nl> + - vRuntime . Eval . HackRecordArrays = true <nl> new file mode 100644 <nl> index 00000000000 . . dfbfe84bb9c <nl> mmm / dev / null <nl> ppp b / hphp / test / quick / recordarray - to - mixed . php . opts <nl> @ @ - 0 , 0 + 1 @ @ <nl> + - vEval . HackRecordArrays = true <nl> mmm a / hphp / test / quick / simple - recordarray . php <nl> ppp b / hphp / test / quick / simple - recordarray . php <nl> <nl> x : int , <nl> } <nl> <nl> + class Bar { <nl> + public int $ f = 42 ; <nl> + } <nl> + <nl> + record FooBar { <nl> + z : Bar , <nl> + } <nl> + <nl> function foo ( array $ a ) : array { <nl> $ a [ ' x ' ] = $ a [ ' x ' ] + 1 ; <nl> $ a [ ' y ' ] = 42 ; <nl> return $ a ; <nl> } <nl> <nl> + function bar ( array $ x ) : array { <nl> + $ x [ 0 ] = 46 ; <nl> + return $ x ; <nl> + } <nl> + <nl> < < __EntryPoint > > <nl> function main ( ) { <nl> $ a = Foo @ [ ' x ' = > 10 ] ; <nl> function main ( ) { <nl> } catch ( Exception $ e ) { <nl> var_dump ( $ e - > getMessage ( ) ) ; <nl> } <nl> + <nl> + try { <nl> + var_dump ( $ a [ 0 ] ) ; <nl> + } catch ( Exception $ e ) { <nl> + var_dump ( $ e - > getMessage ( ) ) ; <nl> + } <nl> + <nl> + $ a [ 0 ] = 43 ; <nl> + / / No more notice for $ a <nl> + $ a [ 1 ] = 44 ; <nl> + var_dump ( $ a [ 0 ] ) ; <nl> + var_dump ( $ a [ 1 ] ) ; <nl> + var_dump ( $ a [ ' x ' ] ) ; <nl> + <nl> + $ c = bar ( $ b ) ; <nl> + var_dump ( $ c ) ; <nl> + try { <nl> + var_dump ( $ b [ 0 ] ) ; <nl> + } catch ( Exception $ e ) { <nl> + var_dump ( $ e - > getMessage ( ) ) ; <nl> + } <nl> + <nl> + $ o1 = new Bar ; <nl> + $ o2 = new Bar ; <nl> + $ o2 - > f = 10 ; <nl> + $ r1 = FooBar @ [ ' z ' = > $ o1 ] ; <nl> + $ r2 = $ r1 ; <nl> + $ r1 [ ' z ' ] = $ o2 ; <nl> + var_dump ( $ r1 [ ' z ' ] ) ; <nl> + var_dump ( $ r2 [ ' z ' ] ) ; <nl> } <nl> deleted file mode 100644 <nl> index 9a41bf0762e . . 00000000000 <nl> mmm a / hphp / test / quick / simple - recordarray . php . expect <nl> ppp / dev / null <nl> <nl> - int ( 1 ) <nl> - int ( 2 ) <nl> - int ( 10 ) <nl> - int ( 11 ) <nl> - int ( 42 ) <nl> - string ( 18 ) " Undefined index : y " <nl> new file mode 100644 <nl> index 00000000000 . . f3f6d73ed90 <nl> mmm / dev / null <nl> ppp b / hphp / test / quick / simple - recordarray . php . expectf <nl> <nl> + int ( 1 ) <nl> + int ( 2 ) <nl> + int ( 10 ) <nl> + int ( 11 ) <nl> + int ( 42 ) <nl> + string ( 18 ) " Undefined index : y " <nl> + string ( 18 ) " Undefined index : 0 " <nl> + <nl> + Notice : Record - array to mixed - array promotion for SetInt in % s / simple - recordarray . php on line 47 <nl> + int ( 43 ) <nl> + int ( 44 ) <nl> + int ( 10 ) <nl> + <nl> + Notice : Record - array to mixed - array promotion for SetInt in % s / simple - recordarray . php on line 22 <nl> + array ( 3 ) { <nl> + [ " x " ] = > <nl> + int ( 11 ) <nl> + [ " y " ] = > <nl> + int ( 42 ) <nl> + [ 0 ] = > <nl> + int ( 46 ) <nl> + } <nl> + string ( 18 ) " Undefined index : 0 " <nl> + object ( Bar ) ( 1 ) { <nl> + [ " f " ] = > <nl> + int ( 10 ) <nl> + } <nl> + object ( Bar ) ( 1 ) { <nl> + [ " f " ] = > <nl> + int ( 42 ) <nl> + } <nl>
Get / Set with Int keys for RecordArrays
facebook/hhvm
749e267cd62862c7d4841e4ff869bf21d19bf825
2019-11-04T16:50:39Z
mmm a / src / mongo / db / matcher / doc_validation_error . cpp <nl> ppp b / src / mongo / db / matcher / doc_validation_error . cpp <nl> <nl> # include " mongo / db / matcher / match_expression_util . h " <nl> # include " mongo / db / matcher / match_expression_walker . h " <nl> # include " mongo / db / matcher / schema / expression_internal_schema_all_elem_match_from_index . h " <nl> + # include " mongo / db / matcher / schema / expression_internal_schema_allowed_properties . h " <nl> # include " mongo / db / matcher / schema / expression_internal_schema_cond . h " <nl> # include " mongo / db / matcher / schema / expression_internal_schema_fmod . h " <nl> # include " mongo / db / matcher / schema / expression_internal_schema_match_array_index . h " <nl> using ErrorAnnotation = MatchExpression : : ErrorAnnotation ; <nl> using AnnotationMode = ErrorAnnotation : : Mode ; <nl> using LeafArrayBehavior = ElementPath : : LeafArrayBehavior ; <nl> using NonLeafArrayBehavior = ElementPath : : NonLeafArrayBehavior ; <nl> + using PatternSchema = InternalSchemaAllowedPropertiesMatchExpression : : PatternSchema ; <nl> + using Pattern = InternalSchemaAllowedPropertiesMatchExpression : : Pattern ; <nl> <nl> / / Fail point which simulates an internal error for testing . <nl> MONGO_FAIL_POINT_DEFINE ( docValidationInternalErrorFailPoint ) ; <nl> MONGO_FAIL_POINT_DEFINE ( docValidationInternalErrorFailPoint ) ; <nl> * / <nl> enum class InvertError { kNormal , kInverted } ; <nl> <nl> + / * * <nl> + * A set of parameters specific to a given frame . Used to allow a parent node to pass parameters to <nl> + * control how its child node should behave when it gets visited . <nl> + * / <nl> + struct FrameParams { <nl> + FrameParams ( BSONObj currentDoc , InvertError inversion ) <nl> + : currentDoc ( std : : move ( currentDoc ) ) , inversion ( inversion ) { } <nl> + / / Tracks the current subdocument that an error should be generated over . <nl> + BSONObj currentDoc ; <nl> + / / Tracks whether the generated error should be described normally or in an inverted context . <nl> + InvertError inversion ; <nl> + } ; <nl> + <nl> / * * <nl> * A struct which tracks error generation information for some node within the tree . <nl> * / <nl> struct ValidationErrorFrame { <nl> / / nodes when generating an error . For instance , when generating an error for an AND in a <nl> / / normal context , we need to discern which of its clauses failed . <nl> kErrorNeedChildrenInfo , <nl> - / / This node contributes to error generation , but none of its children will contribute to <nl> - / / the error output . <nl> + / / This node contributes to error generation , but its next child will not contribute to <nl> + / / error output . If a node maintains this state across all visits to its children , then none <nl> + / / of its children will contribute to the error output . <nl> kErrorIgnoreChildren , <nl> } ; <nl> <nl> - ValidationErrorFrame ( RuntimeState runtimeState , BSONObj currentDoc , InvertError inversion ) <nl> - : runtimeState ( runtimeState ) , currentDoc ( std : : move ( currentDoc ) ) , inversion ( inversion ) { } <nl> + ValidationErrorFrame ( RuntimeState runtimeState , FrameParams currentParams ) <nl> + : runtimeState ( runtimeState ) , currentParams ( std : : move ( currentParams ) ) { } <nl> <nl> / / BSONBuilders which construct the generated error . <nl> BSONObjBuilder objBuilder ; <nl> struct ValidationErrorFrame { <nl> size_t childIndex = 0 ; <nl> / / Tracks runtime information about how the current node should generate an error . <nl> RuntimeState runtimeState ; <nl> - / / Tracks the current subdocument that an error should be generated over . <nl> - BSONObj currentDoc ; <nl> - / / Tracks whether the generated error should be described normally or in an inverted context . <nl> - InvertError inversion ; <nl> / / Tracks whether the array of ' consideredValues ' was truncated for this frame . <nl> bool consideredValuesTruncated = false ; <nl> + / / Tracks the current frame ' s parameters . <nl> + FrameParams currentParams ; <nl> } ; <nl> <nl> using RuntimeState = ValidationErrorFrame : : RuntimeState ; <nl> struct ValidationErrorContext { <nl> / * * <nl> * Utilities which add / remove ValidationErrorFrames from ' frames ' . <nl> * / <nl> - void pushNewFrame ( const MatchExpression & expr , const BSONObj & subDoc ) { <nl> + void pushNewFrame ( const MatchExpression & expr ) { <nl> / / Clear the last error that was generated . <nl> latestCompleteError = std : : monostate ( ) ; <nl> <nl> / / If this is the first frame , then we know that we ' ve failed validation , so we must be <nl> / / generating an error . <nl> if ( frames . empty ( ) ) { <nl> - frames . emplace ( RuntimeState : : kError , subDoc , InvertError : : kNormal ) ; <nl> + frames . emplace ( RuntimeState : : kError , FrameParams ( rootDoc , InvertError : : kNormal ) ) ; <nl> return ; <nl> } <nl> <nl> auto parentRuntimeState = getCurrentRuntimeState ( ) ; <nl> - auto inversion = getCurrentInversion ( ) ; <nl> + auto frameParams = frames . top ( ) . currentParams ; <nl> + <nl> + / / Record and clear any input given by the parent frame . <nl> + if ( childInput ) { <nl> + frameParams = * childInput ; <nl> + childInput = boost : : none ; <nl> + } <nl> <nl> / / If we ' ve determined at runtime or at parse time that this node shouldn ' t contribute to <nl> / / error generation , then push a frame indicating that this node should not produce an <nl> struct ValidationErrorContext { <nl> if ( parentRuntimeState = = RuntimeState : : kNoError | | <nl> parentRuntimeState = = RuntimeState : : kErrorIgnoreChildren | | <nl> expr . getErrorAnnotation ( ) - > mode = = AnnotationMode : : kIgnore ) { <nl> - frames . emplace ( RuntimeState : : kNoError , subDoc , inversion ) ; <nl> + frames . emplace ( RuntimeState : : kNoError , frameParams ) ; <nl> return ; <nl> } <nl> <nl> / / If our parent needs more information , call ' matches ( ) ' to determine whether the ' expr ' <nl> / / will contribute to error output . <nl> if ( parentRuntimeState = = RuntimeState : : kErrorNeedChildrenInfo ) { <nl> - bool generateErrorValue = expr . matchesBSON ( subDoc ) ? inversion = = InvertError : : kInverted <nl> - : inversion = = InvertError : : kNormal ; <nl> + auto inversion = frameParams . inversion ; <nl> + bool generateErrorValue = expr . matchesBSON ( frameParams . currentDoc ) <nl> + ? inversion = = InvertError : : kInverted <nl> + : inversion = = InvertError : : kNormal ; <nl> frames . emplace ( generateErrorValue ? RuntimeState : : kError : RuntimeState : : kNoError , <nl> - subDoc , <nl> - inversion ) ; <nl> + frameParams ) ; <nl> return ; <nl> } <nl> - frames . emplace ( RuntimeState : : kError , subDoc , inversion ) ; <nl> + frames . emplace ( RuntimeState : : kError , frameParams ) ; <nl> } <nl> void popFrame ( ) { <nl> invariant ( ! frames . empty ( ) ) ; <nl> struct ValidationErrorContext { <nl> frames . top ( ) . runtimeState = runtimeState ; <nl> } <nl> } <nl> + / * * <nl> + * Configures the current frame to have a ' childInput ' , that is , the set of parameters that any <nl> + * child expression will accept as input . <nl> + * / <nl> + void setChildInput ( const BSONObj & doc , InvertError inversion ) { <nl> + childInput = FrameParams ( doc , inversion ) ; <nl> + } <nl> const BSONObj & getCurrentDocument ( ) { <nl> if ( ! frames . empty ( ) ) { <nl> - return frames . top ( ) . currentDoc ; <nl> + return frames . top ( ) . currentParams . currentDoc ; <nl> } <nl> return rootDoc ; <nl> } <nl> - void setCurrentDocument ( const BSONObj & document ) { <nl> + void setCurrentInversion ( InvertError inversion ) { <nl> invariant ( ! frames . empty ( ) ) ; <nl> - frames . top ( ) . currentDoc = document ; <nl> + frames . top ( ) . currentParams . inversion = inversion ; <nl> } <nl> InvertError getCurrentInversion ( ) const { <nl> invariant ( ! frames . empty ( ) ) ; <nl> - return frames . top ( ) . inversion ; <nl> - } <nl> - void setCurrentInversion ( InvertError inversion ) { <nl> - invariant ( ! frames . empty ( ) ) ; <nl> - frames . top ( ) . inversion = inversion ; <nl> + return frames . top ( ) . currentParams . inversion ; <nl> } <nl> <nl> / * * <nl> struct ValidationErrorContext { <nl> void appendLatestCompleteError ( BSONObjBuilder * builder ) { <nl> const static std : : string kDetailsString = " details " ; <nl> stdx : : visit ( <nl> - visit_helper : : Overloaded { <nl> - [ & ] ( const auto & details ) - > void { <nl> - verifySizeAndAppend ( details , kDetailsString , builder ) ; <nl> - } , <nl> - [ & ] ( const std : : monostate & state ) - > void { MONGO_UNREACHABLE ; } , <nl> - [ & ] ( const std : : string & str ) - > void { MONGO_UNREACHABLE ; } } , <nl> + visit_helper : : Overloaded { [ & ] ( const auto & details ) - > void { <nl> + verifySizeAndAppend ( details , kDetailsString , builder ) ; <nl> + } , <nl> + [ & ] ( const std : : monostate & state ) - > void { MONGO_UNREACHABLE } , <nl> + [ & ] ( const std : : string & str ) - > void { MONGO_UNREACHABLE } } , <nl> latestCompleteError ) ; <nl> } <nl> / * * <nl> struct ValidationErrorContext { <nl> * / <nl> void appendLatestCompleteError ( BSONArrayBuilder * builder ) { <nl> stdx : : visit ( <nl> - visit_helper : : Overloaded { [ & ] ( const BSONObj & obj ) - > void { builder - > append ( obj ) ; } , <nl> - [ & ] ( const std : : string & str ) - > void { builder - > append ( str ) ; } , <nl> - [ & ] ( const BSONArray & arr ) - > void { MONGO_UNREACHABLE ; } , <nl> - [ & ] ( const std : : monostate & arr ) - > void { MONGO_UNREACHABLE ; } } , <nl> + visit_helper : : Overloaded { <nl> + [ & ] ( const BSONObj & obj ) - > void { verifySizeAndAppend ( obj , builder ) ; } , <nl> + [ & ] ( const std : : string & str ) - > void { builder - > append ( str ) ; } , <nl> + [ & ] ( const BSONArray & arr ) - > void { <nl> + / / The ' $ _internalSchemaAllowedProperties ' match expression represents two <nl> + / / JSONSchema keywords : ' additionalProperties ' and ' patternProperties ' . As <nl> + / / such , if both keywords produce an error , their errors will be packaged <nl> + / / into an array which the parent expression must absorb when constructing <nl> + / / its array of error details . <nl> + for ( auto & & elem : arr ) { <nl> + verifySizeAndAppend ( elem , builder ) ; <nl> + } <nl> + } , <nl> + [ & ] ( const std : : monostate & state ) - > void { MONGO_UNREACHABLE } } , <nl> latestCompleteError ) ; <nl> } <nl> <nl> struct ValidationErrorContext { <nl> / * * <nl> * Sets ' inversion ' to the opposite of its current value . <nl> * / <nl> - void flipInversion ( ) { <nl> + void flipCurrentInversion ( ) { <nl> getCurrentInversion ( ) = = InvertError : : kNormal ? setCurrentInversion ( InvertError : : kInverted ) <nl> : setCurrentInversion ( InvertError : : kNormal ) ; <nl> } <nl> struct ValidationErrorContext { <nl> / / Tracks whether the generated error should omit appending ' specifiedAs ' and <nl> / / ' consideredValues ' to avoid generating an error larger than the maximum BSONObj size . <nl> const bool truncate = false ; <nl> + / / Tracks an optional input to child frames which require custom parameters from their parent <nl> + / / frame . <nl> + boost : : optional < FrameParams > childInput ; <nl> / / The maximum allowed size for a doc validation error . <nl> const int kMaxDocValidationErrorSize ; <nl> / / Tracks the maximum number of values that will be reported in the ' consideredValues ' array <nl> struct ValidationErrorContext { <nl> const int kMaxConsideredValuesElements ; <nl> } ; <nl> <nl> + / * * <nl> + * Builds a BSON object from a BSON element ' element ' using the same name placeholder as the <nl> + * JSON Schema match expressions . <nl> + * / <nl> + BSONObj toObjectWithPlaceholder ( BSONElement element ) { <nl> + return BSON ( JSONSchemaParser : : kNamePlaceholder < < element ) ; <nl> + } <nl> + <nl> / * * <nl> * Append the error generated by one of ' expr ' s children to the current array builder of ' expr ' <nl> * if said child generated an error . <nl> ItemsKeywordType toItemsKeywordType ( <nl> MONGO_UNREACHABLE ; <nl> } <nl> <nl> + / * * <nl> + * Returns the set of additional properties from ' doc ' . A property is said to be additional if <nl> + * it is not contained in any of the properties of ' expr ' , nor does it match any of the regular <nl> + * expressions in expr ' s patternProperties . <nl> + * / <nl> + BSONArray findAdditionalProperties ( const BSONObj & doc , <nl> + const InternalSchemaAllowedPropertiesMatchExpression & expr ) { <nl> + BSONArrayBuilder additionalProperties ; <nl> + const auto & properties = expr . getProperties ( ) ; <nl> + const auto & patternProperties = expr . getPatternProperties ( ) ; <nl> + for ( auto & & field : doc ) { <nl> + auto fieldName = field . fieldNameStringData ( ) ; <nl> + if ( ! properties . contains ( fieldName ) ) { <nl> + bool additional = true ; <nl> + for ( auto & & pattern : patternProperties ) { <nl> + if ( pattern . first . regex - > PartialMatch ( fieldName . toString ( ) ) ) { <nl> + additional = false ; <nl> + break ; <nl> + } <nl> + } <nl> + if ( additional ) { <nl> + additionalProperties . append ( fieldName ) ; <nl> + } <nl> + } <nl> + } <nl> + return additionalProperties . arr ( ) ; <nl> + } <nl> + <nl> + / * * <nl> + * Sets the necessary state to generate an error for a child expression of an <nl> + * ' InternalSchemaAllowedPropertiesMatchExpression ' . <nl> + * / <nl> + void setAllowedPropertiesChildInput ( BSONElement failingElement , ValidationErrorContext * ctx ) { <nl> + ctx - > setCurrentRuntimeState ( RuntimeState : : kError ) ; <nl> + ctx - > setChildInput ( toObjectWithPlaceholder ( failingElement ) , ctx - > getCurrentInversion ( ) ) ; <nl> + } <nl> + <nl> + / * * <nl> + * Returns the element corresponding to the first property from ' additionalProperties ' whose <nl> + * value in ' doc ' fails to match against ' filter ' , if such an element exists . Returns EOO otherwise . <nl> + * / <nl> + BSONElement findFirstFailingAdditionalProperty ( const MatchExpression & filter , <nl> + const BSONArray & additionalProperties , <nl> + const BSONObj & doc ) { <nl> + for ( auto & & property : additionalProperties ) { <nl> + auto & & elem = doc . getField ( property . valueStringData ( ) ) ; <nl> + if ( ! filter . matchesBSONElement ( elem ) ) { <nl> + return elem ; <nl> + } <nl> + } <nl> + return { } ; <nl> + } <nl> + <nl> + / * * <nl> + * Finds a pattern property failure and returns the failing element ( if one exists ) and EOO <nl> + * otherwise . A pattern property failure corresponds to the first element in a document whose field <nl> + * name matches against a pattern , but fails to match against the corresponding filter . <nl> + * / <nl> + BSONElement findFailingProperty ( const InternalSchemaAllowedPropertiesMatchExpression & expr , <nl> + const PatternSchema & patternSchema , <nl> + ValidationErrorContext * ctx ) { <nl> + / / Before walking the tree corresponding to the subschema of a single child expression of <nl> + / / ' patternProperties ' , we must first determine whether there exists a property which matches <nl> + / / the corresponding regular expression which also fails to match against the subschema . <nl> + auto & pattern = patternSchema . first ; <nl> + auto filter = patternSchema . second - > getFilter ( ) ; <nl> + for ( auto & & elem : ctx - > getCurrentDocument ( ) ) { <nl> + auto field = elem . fieldNameStringData ( ) ; <nl> + if ( pattern . regex - > PartialMatch ( field . toString ( ) ) & & ! filter - > matchesBSONElement ( elem ) ) { <nl> + return elem ; <nl> + } <nl> + } <nl> + return { } ; <nl> + } <nl> + <nl> + / * * <nl> + * Generates an error for a child expression of the ' patternProperties ' keyword , that is , for a <nl> + * property whose name matched one of the regexes of ' expr ' , but failed to match against the <nl> + * corresponding subschema . <nl> + * / <nl> + void generatePatternPropertyError ( const InternalSchemaAllowedPropertiesMatchExpression & expr , <nl> + ValidationErrorContext * ctx ) { <nl> + / / Generate an error for the previous regular expression . The previous regex is indexed by <nl> + / / the current child index minus one since the child expression is offset by one to account <nl> + / / for the expression which represents the ' additionalProperties ' keyword . <nl> + invariant ( ctx - > getCurrentChildIndex ( ) > = 1 ) ; <nl> + auto childIndex = ctx - > getCurrentChildIndex ( ) - 1 ; <nl> + auto & patternSchema = expr . getPatternProperties ( ) [ childIndex ] ; <nl> + auto element = findFailingProperty ( expr , patternSchema , ctx ) ; <nl> + <nl> + / / Only generate an error if we found a regex which matches a property that failed to match <nl> + / / against the corresponding sub - schema . <nl> + if ( ctx - > shouldGenerateError ( expr ) & & ctx - > haveLatestCompleteError ( ) & & element ) { <nl> + auto propertyName = element . fieldNameStringData ( ) . toString ( ) ; <nl> + BSONObjBuilder patternBuilder ; <nl> + patternBuilder . append ( " propertyName " , propertyName ) ; <nl> + patternBuilder . append ( " regexMatched " , patternSchema . first . rawRegex ) ; <nl> + ctx - > appendLatestCompleteError ( & patternBuilder ) ; <nl> + ctx - > verifySizeAndAppend ( patternBuilder . obj ( ) , & ctx - > getCurrentArrayBuilder ( ) ) ; <nl> + } <nl> + } <nl> + <nl> + void generateAdditionalPropertiesFalseError ( const BSONArray & additionalProperties , <nl> + ValidationErrorContext * ctx ) { <nl> + / / Only generate an error if ' additionalProperties ' is non empty , that is , there exists at <nl> + / / least one additional property within the current subdocument tracked by ' ctx ' . <nl> + if ( ! additionalProperties . isEmpty ( ) ) { <nl> + auto & builder = ctx - > getCurrentObjBuilder ( ) ; <nl> + builder . append ( " operatorName " , " additionalProperties " ) ; <nl> + builder . append ( " specifiedAs " , BSON ( " additionalProperties " < < false ) ) ; <nl> + builder . append ( " additionalProperties " , additionalProperties ) ; <nl> + } <nl> + } <nl> + <nl> + / * * <nl> + * Generates an error for the schema { additionalProperties : < subschema > } . This function can only <nl> + * be called if there is at least one property in the current subdocument tracked by ' ctx ' which <nl> + * failed to match ' subschema ' . <nl> + * / <nl> + void generateAdditionalPropertiesSchemaError ( <nl> + const InternalSchemaAllowedPropertiesMatchExpression & expr , ValidationErrorContext * ctx ) { <nl> + auto & & additionalProperties = findAdditionalProperties ( ctx - > getCurrentDocument ( ) , expr ) ; <nl> + auto firstFailingElement = findFirstFailingAdditionalProperty ( <nl> + * expr . getChild ( 0 ) , additionalProperties , ctx - > getCurrentDocument ( ) ) ; <nl> + invariant ( firstFailingElement ) ; <nl> + auto & builder = ctx - > getCurrentObjBuilder ( ) ; <nl> + builder . append ( " operatorName " , " additionalProperties " ) ; <nl> + builder . append ( " reason " , " at least one additional property did not match the subschema " ) ; <nl> + builder . append ( " failingProperty " , firstFailingElement . fieldNameStringData ( ) . toString ( ) ) ; <nl> + ctx - > appendLatestCompleteError ( & builder ) ; <nl> + } <nl> + <nl> + / * * <nl> + * Handle error generation for either an ' additionalProperties : < schema > ' keyword or the child of a <nl> + * ' patternProperties ' keyword . <nl> + * / <nl> + void generateAllowedPropertiesSchemaError ( <nl> + const InternalSchemaAllowedPropertiesMatchExpression & expr , ValidationErrorContext * ctx ) { <nl> + auto childIndex = ctx - > getCurrentChildIndex ( ) ; <nl> + if ( ctx - > haveLatestCompleteError ( ) ) { <nl> + / / Because ' InternalSchemaAllowedPropertiesMatchExpression ' represents both the <nl> + / / ' additionalProperties ' and the ' patternProperties ' keywords , we must determine which <nl> + / / keyword we are generating an error for . In particular , the first child will always be <nl> + / / the expression corresponding to the ' additionalProperties ' keyword , while each <nl> + / / subsequent child will be a single component of the ' patternProperties ' keyword . <nl> + if ( childIndex = = 0 ) { <nl> + / / We handle the { ' additionalProperties ' : < schema > } case here after we ' ve walked the <nl> + / / tree corresponding to the additionalProperties keyword . <nl> + if ( expr . getErrorAnnotation ( ) - > annotation . firstElementType ( ) = = BSONType : : Object ) { <nl> + generateAdditionalPropertiesSchemaError ( expr , ctx ) ; <nl> + } <nl> + } else { <nl> + generatePatternPropertyError ( expr , ctx ) ; <nl> + } <nl> + } <nl> + } <nl> + <nl> / * * <nl> * Visitor which is primarily responsible for error generation . <nl> * / <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> void visit ( const ExistsMatchExpression * expr ) final { <nl> static constexpr auto kNormalReason = " path does not exist " ; <nl> static constexpr auto kInvertedReason = " path does exist " ; <nl> - _context - > pushNewFrame ( * expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( * expr ) ; <nl> / / Only generate an error if this node is tagged with an MQL operator name . The <nl> / / ' _propertyExists ' tag indicates that this node is implementing a JSONSchema feature . <nl> if ( _context - > shouldGenerateError ( * expr ) & & <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> void visit ( const ExprMatchExpression * expr ) final { <nl> static constexpr auto kNormalReason = " $ expr did not match " ; <nl> static constexpr auto kInvertedReason = " $ expr did match " ; <nl> - _context - > pushNewFrame ( * expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( * expr ) ; <nl> if ( _context - > shouldGenerateError ( * expr ) ) { <nl> appendErrorDetails ( * expr ) ; <nl> appendErrorReason ( kNormalReason , kInvertedReason ) ; <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> MONGO_UNREACHABLE ; <nl> } <nl> } <nl> - void visit ( const InternalSchemaAllowedPropertiesMatchExpression * expr ) final { } <nl> + void visit ( const InternalSchemaAllowedPropertiesMatchExpression * expr ) final { <nl> + _context - > pushNewFrame ( * expr ) ; <nl> + <nl> + / / It is the responsibility of ' expr ' to discern which child expression ( s ) failed to <nl> + / / match against which elements of the current document since ' expr ' has knowledge of the <nl> + / / set of defined properties along with the any regex / filter pairs defined by <nl> + / / ' patternProperties ' . We assume that the next child expression will be ignored until <nl> + / / proven otherwise . <nl> + _context - > setCurrentRuntimeState ( RuntimeState : : kErrorIgnoreChildren ) ; <nl> + if ( _context - > shouldGenerateError ( * expr ) ) { <nl> + auto additionalProperties = <nl> + findAdditionalProperties ( _context - > getCurrentDocument ( ) , * expr ) ; <nl> + <nl> + / / The first child expression of ' expr ' always corresponds to the ' additionalProperties ' <nl> + / / keyword . <nl> + auto additionalPropertiesExpr = expr - > getChild ( 0 ) ; <nl> + <nl> + / / We discern whether we are dealing with ' additionalProperties : false ' or <nl> + / / ' additionalProperties : < schema > ' by inspecting the annotation on ' expr ' . <nl> + auto additionalPropertiesType = <nl> + expr - > getErrorAnnotation ( ) - > annotation . firstElementType ( ) ; <nl> + <nl> + / / Only generate an error in the boolean case if the ' additionalProperties ' expression <nl> + / / evaluates to false . <nl> + if ( additionalPropertiesType = = BSONType : : Bool & & <nl> + ! additionalPropertiesExpr - > matchesBSON ( _context - > getCurrentDocument ( ) ) ) { <nl> + generateAdditionalPropertiesFalseError ( additionalProperties , _context ) ; <nl> + } else if ( additionalPropertiesType = = BSONType : : Object ) { <nl> + / / In the case of an additionalProperties keyword which takes a schema argument , <nl> + / / identify the first additional property which violates the subschema , if such a <nl> + / / property exists . <nl> + auto subSchema = expr - > getChild ( 0 ) ; <nl> + if ( auto failingElement = findFirstFailingAdditionalProperty ( <nl> + * subSchema , additionalProperties , _context - > getCurrentDocument ( ) ) ) { <nl> + setAllowedPropertiesChildInput ( failingElement , _context ) ; <nl> + } <nl> + } <nl> + } <nl> + } <nl> void visit ( const InternalSchemaBinDataEncryptedTypeExpression * expr ) final { <nl> static constexpr auto kNormalReason = " encrypted value has wrong type " ; <nl> / / This node will never generate an error in the inverted case . <nl> static constexpr auto kInvertedReason = " " ; <nl> - _context - > pushNewFrame ( * expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( * expr ) ; <nl> if ( _context - > shouldGenerateError ( * expr ) ) { <nl> ElementPath path ( expr - > path ( ) , LeafArrayBehavior : : kNoTraversal ) ; <nl> BSONMatchableDocument doc ( _context - > getCurrentDocument ( ) ) ; <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> void visit ( const InternalSchemaBinDataSubTypeExpression * expr ) final { <nl> static constexpr auto kNormalReason = " value was not encrypted " ; <nl> static constexpr auto kInvertedReason = " value was encrypted " ; <nl> - _context - > pushNewFrame ( * expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( * expr ) ; <nl> if ( _context - > shouldGenerateError ( * expr ) ) { <nl> appendOperatorName ( * expr ) ; <nl> appendErrorReason ( kNormalReason , kInvertedReason ) ; <nl> } <nl> } <nl> void visit ( const InternalSchemaCondMatchExpression * expr ) final { <nl> - _context - > pushNewFrame ( * expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( * expr ) ; <nl> if ( _context - > shouldGenerateError ( * expr ) ) { <nl> / / Since ' expr ' represents a conditional expression corresponding to a single <nl> / / $ jsonSchema dependency whose else branch always evaluates to ' true ' , ' expr ' can only <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> LeafArrayBehavior : : kNoTraversal ) ; <nl> } <nl> void visit ( const InternalSchemaMatchArrayIndexMatchExpression * expr ) final { <nl> - _context - > pushNewFrame ( * expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( * expr ) ; <nl> if ( _context - > shouldGenerateError ( * expr ) ) { <nl> / / Get an element of an array . <nl> ElementPath path ( <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> <nl> / / Build a document corresponding to the array element for the child expression to <nl> / / operate on . <nl> - _context - > setCurrentDocument ( toObjectWithPlaceholder ( arrayElement ) ) ; <nl> + _context - > setChildInput ( toObjectWithPlaceholder ( arrayElement ) , <nl> + _context - > getCurrentInversion ( ) ) ; <nl> } <nl> } <nl> void visit ( const InternalSchemaMaxItemsMatchExpression * expr ) final { <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> invariant ( expr - > getErrorAnnotation ( ) - > mode ! = AnnotationMode : : kGenerateError ) ; <nl> / / As part of pushing a new frame onto the stack , the runtime state may be set to <nl> / / ' kNoError ' if ' expr ' matches the current document . <nl> - _context - > pushNewFrame ( * expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( * expr ) ; <nl> / / Only attempt to find a subdocument if this node failed to match . <nl> if ( _context - > getCurrentRuntimeState ( ) ! = RuntimeState : : kNoError ) { <nl> ElementPath path ( expr - > path ( ) , LeafArrayBehavior : : kNoTraversal ) ; <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> / / InternalSchemaTypeExpression that will explain a type did not match error . <nl> bool ignoreSubTree = false ; <nl> if ( elem . type ( ) = = BSONType : : Object ) { <nl> - _context - > setCurrentDocument ( elem . embeddedObject ( ) ) ; <nl> + _context - > setChildInput ( elem . embeddedObject ( ) , _context - > getCurrentInversion ( ) ) ; <nl> } else { <nl> ignoreSubTree = true ; <nl> } <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> } <nl> void visit ( const InternalSchemaUniqueItemsMatchExpression * expr ) final { <nl> static constexpr auto normalReason = " found a duplicate item " ; <nl> - _context - > pushNewFrame ( * expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( * expr ) ; <nl> if ( auto attributeValue = getValueForArrayKeywordExpressionIfShouldGenerateError ( * expr ) ) { <nl> appendErrorDetails ( * expr ) ; <nl> appendErrorReason ( normalReason , " " ) ; <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> } <nl> } <nl> if ( ! matchingClauses . empty ( ) ) { <nl> - _context - > flipInversion ( ) ; <nl> + _context - > flipCurrentInversion ( ) ; <nl> _context - > setCurrentRuntimeState ( RuntimeState : : kErrorIgnoreChildren ) ; <nl> auto & builder = _context - > getCurrentObjBuilder ( ) ; <nl> / / We only report the matching schema reason in an inverted context , so there is <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> if ( _context - > getCurrentInversion ( ) = = InvertError : : kNormal ) { <nl> _context - > setCurrentRuntimeState ( RuntimeState : : kErrorNeedChildrenInfo ) ; <nl> } <nl> - _context - > flipInversion ( ) ; <nl> + _context - > flipCurrentInversion ( ) ; <nl> } <nl> void visit ( const NotMatchExpression * expr ) final { <nl> preVisitTreeOperator ( expr ) ; <nl> - _context - > flipInversion ( ) ; <nl> + _context - > flipCurrentInversion ( ) ; <nl> / / If this is a $ jsonSchema not , then expr ' s children will not contribute to the error <nl> / / output . <nl> if ( _context - > shouldGenerateError ( * expr ) & & expr - > getErrorAnnotation ( ) - > tag = = " not " ) { <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> const std : : string & invertedReason , <nl> const std : : set < BSONType > * expectedTypes = nullptr , <nl> LeafArrayBehavior leafArrayBehavior = LeafArrayBehavior : : kTraverseOmitArray ) { <nl> - _context - > pushNewFrame ( expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( expr ) ; <nl> if ( _context - > shouldGenerateError ( expr ) ) { <nl> appendErrorDetails ( expr ) ; <nl> auto arr = createValuesArray ( expr . path ( ) , leafArrayBehavior ) ; <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> <nl> template < class T > <nl> void generateTypeError ( const TypeMatchExpressionBase < T > * expr , LeafArrayBehavior behavior ) { <nl> - _context - > pushNewFrame ( * expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( * expr ) ; <nl> static constexpr auto kNormalReason = " type did not match " ; <nl> static constexpr auto kInvertedReason = " type did match " ; <nl> if ( _context - > shouldGenerateError ( * expr ) ) { <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> * / <nl> void preVisitTreeOperator ( const MatchExpression * expr ) { <nl> invariant ( expr - > getCategory ( ) = = MatchExpression : : MatchCategory : : kLogical ) ; <nl> - _context - > pushNewFrame ( * expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( * expr ) ; <nl> if ( _context - > shouldGenerateError ( * expr ) ) { <nl> auto annotation = expr - > getErrorAnnotation ( ) ; <nl> / / Only append the operator name if it will produce an object error corresponding to <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> void generateLogicalLeafError ( const ListOfMatchExpression & expr , <nl> const std : : string & normalReason , <nl> const std : : string & invertedReason ) { <nl> - _context - > pushNewFrame ( expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( expr ) ; <nl> if ( _context - > shouldGenerateError ( expr ) ) { <nl> / / $ all with no children should not translate to an ' AndMatchExpression ' and ' enum ' <nl> / / must have non - zero children . <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> * parse time . <nl> * / <nl> void generateAlwaysBooleanError ( const AlwaysBooleanMatchExpression & expr ) { <nl> - _context - > pushNewFrame ( expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( expr ) ; <nl> if ( _context - > shouldGenerateError ( expr ) ) { <nl> / / An AlwaysBooleanMatchExpression can only contribute to error generation when the <nl> / / inversion matches the value of the ' expr ' . More precisely , it is only possible <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> void generateJSONSchemaMinItemsMaxItemsError ( <nl> const InternalSchemaNumArrayItemsMatchExpression * expr ) { <nl> static constexpr auto normalReason = " array did not match specified length " ; <nl> - _context - > pushNewFrame ( * expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( * expr ) ; <nl> if ( auto attributeValue = getValueForArrayKeywordExpressionIfShouldGenerateError ( * expr ) ) { <nl> appendErrorDetails ( * expr ) ; <nl> appendErrorReason ( normalReason , " " ) ; <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> void generateJSONSchemaAdditionalItemsFalseError ( <nl> const InternalSchemaAllElemMatchFromIndexMatchExpression * expr ) { <nl> static constexpr auto normalReason = " found additional items " ; <nl> - _context - > pushNewFrame ( * expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( * expr ) ; <nl> if ( auto attributeValue = getValueForArrayKeywordExpressionIfShouldGenerateError ( * expr ) ) { <nl> appendErrorDetails ( * expr ) ; <nl> appendErrorReason ( normalReason , " " ) ; <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> * to validate elements of the array . <nl> * / <nl> void generateJSONSchemaItemsSchemaArrayError ( const AndMatchExpression & expr ) { <nl> - _context - > pushNewFrame ( expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( expr ) ; <nl> <nl> / / Determine if we need to generate an error using a child of the " $ and " expression , which <nl> / / must be of InternalSchemaMatchArrayIndexMatchExpression type , since " $ and " does not have <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> } <nl> } <nl> <nl> - / * * <nl> - * Builds a BSON object from a BSON element ' element ' using the same name placeholder as the <nl> - * JSON Schema match expressions . <nl> - * / <nl> - BSONObj toObjectWithPlaceholder ( BSONElement element ) { <nl> - return BSON ( JSONSchemaParser : : kNamePlaceholder < < element ) ; <nl> - } <nl> - <nl> / * * <nl> * Adds elements starting from index ' startIndex ' from array ' array ' to the current object as <nl> * " additionalItems " attribute . <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> const InternalSchemaAllElemMatchFromIndexMatchExpression * expr , <nl> const std : : string & normalReason , <nl> const std : : string & invertedReason ) { <nl> - _context - > pushNewFrame ( * expr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( * expr ) ; <nl> if ( auto attributeValue = getValueForArrayKeywordExpressionIfShouldGenerateError ( * expr ) ) { <nl> appendOperatorName ( * expr ) ; <nl> appendErrorReason ( normalReason , invertedReason ) ; <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> invariant ( failingElement ) ; <nl> _context - > getCurrentObjBuilder ( ) . appendNumber ( <nl> " itemIndex " _sd , std : : stoll ( failingElement . fieldNameStringData ( ) . toString ( ) ) ) ; <nl> - _context - > setCurrentDocument ( toObjectWithPlaceholder ( failingElement ) ) ; <nl> + _context - > setChildInput ( toObjectWithPlaceholder ( failingElement ) , <nl> + _context - > getCurrentInversion ( ) ) ; <nl> } else { <nl> / / Disable error generation by the child expression of ' expr ' . <nl> _context - > setCurrentRuntimeState ( RuntimeState : : kNoError ) ; <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> void generateNumPropertiesError ( const MatchExpression & numPropertiesExpr ) { <nl> static constexpr auto kNormalReason = " specified number of properties was not satisfied " ; <nl> static constexpr auto kInvertedReason = " " ; <nl> - _context - > pushNewFrame ( numPropertiesExpr , _context - > getCurrentDocument ( ) ) ; <nl> + _context - > pushNewFrame ( numPropertiesExpr ) ; <nl> if ( _context - > shouldGenerateError ( numPropertiesExpr ) ) { <nl> appendErrorDetails ( numPropertiesExpr ) ; <nl> appendErrorReason ( kNormalReason , kInvertedReason ) ; <nl> class ValidationErrorPreVisitor final : public MatchExpressionConstVisitor { <nl> } <nl> } <nl> <nl> - <nl> ValidationErrorContext * _context ; <nl> } ; <nl> <nl> class ValidationErrorInVisitor final : public MatchExpressionConstVisitor { <nl> void visit ( const InMatchExpression * expr ) final { } <nl> void visit ( const InternalExprEqMatchExpression * expr ) final { } <nl> void visit ( const InternalSchemaAllElemMatchFromIndexMatchExpression * expr ) final { } <nl> - void visit ( const InternalSchemaAllowedPropertiesMatchExpression * expr ) final { } <nl> + void visit ( const InternalSchemaAllowedPropertiesMatchExpression * expr ) final { <nl> + if ( _context - > shouldGenerateError ( * expr ) ) { <nl> + generateAllowedPropertiesSchemaError ( * expr , _context ) ; <nl> + <nl> + / / Reset the state before determining if the next child should produce an error . <nl> + _context - > setCurrentRuntimeState ( RuntimeState : : kErrorIgnoreChildren ) ; <nl> + <nl> + / / Examine the next patternSchema to determine whether the next clause of <nl> + / / ' patternProperties ' should generate an error . Since the current index corresponds to <nl> + / / one plus the number of patternProperties clauses visited so far , it also represents <nl> + / / the next ' patternProperties ' clause . <nl> + invariant ( _context - > getCurrentChildIndex ( ) < expr - > getPatternProperties ( ) . size ( ) ) ; <nl> + auto & patternSchema = expr - > getPatternProperties ( ) [ _context - > getCurrentChildIndex ( ) ] ; <nl> + if ( auto failingElement = findFailingProperty ( * expr , patternSchema , _context ) ) { <nl> + setAllowedPropertiesChildInput ( failingElement , _context ) ; <nl> + } <nl> + } <nl> + _context - > incrementCurrentChildIndex ( ) ; <nl> + } <nl> void visit ( const InternalSchemaBinDataEncryptedTypeExpression * expr ) final { } <nl> void visit ( const InternalSchemaBinDataSubTypeExpression * expr ) final { } <nl> void visit ( const InternalSchemaCondMatchExpression * expr ) final { <nl> class ValidationErrorPostVisitor final : public MatchExpressionConstVisitor { <nl> } <nl> _context - > finishCurrentError ( expr ) ; <nl> } <nl> - void visit ( const InternalSchemaAllowedPropertiesMatchExpression * expr ) final { } <nl> + void visit ( const InternalSchemaAllowedPropertiesMatchExpression * expr ) final { <nl> + if ( _context - > shouldGenerateError ( * expr ) ) { <nl> + generateAllowedPropertiesSchemaError ( * expr , _context ) ; <nl> + BSONObj additionalPropertiesError = _context - > getCurrentObjBuilder ( ) . obj ( ) ; <nl> + BSONObj patternPropertiesError ; <nl> + / / Only build a ' patternProperties ' error if any were produced . <nl> + auto & arrBuilder = _context - > getCurrentArrayBuilder ( ) ; <nl> + if ( arrBuilder . arrSize ( ) > 0 ) { <nl> + BSONObjBuilder patternProperties ; <nl> + patternProperties . append ( " operatorName " , " patternProperties " ) ; <nl> + patternProperties . append ( " details " , arrBuilder . arr ( ) ) ; <nl> + patternPropertiesError = patternProperties . obj ( ) ; <nl> + } <nl> + if ( additionalPropertiesError . isEmpty ( ) ) { <nl> + invariant ( ! patternPropertiesError . isEmpty ( ) ) ; <nl> + _context - > latestCompleteError = patternPropertiesError ; <nl> + } else if ( patternPropertiesError . isEmpty ( ) ) { <nl> + invariant ( ! additionalPropertiesError . isEmpty ( ) ) ; <nl> + _context - > latestCompleteError = additionalPropertiesError ; <nl> + } else { <nl> + BSONArrayBuilder arr ; <nl> + arr . append ( additionalPropertiesError ) ; <nl> + arr . append ( patternPropertiesError ) ; <nl> + _context - > latestCompleteError = arr . arr ( ) ; <nl> + } <nl> + } <nl> + _context - > popFrame ( ) ; <nl> + } <nl> void visit ( const InternalSchemaBinDataEncryptedTypeExpression * expr ) final { <nl> _context - > finishCurrentError ( expr ) ; <nl> } <nl> mmm a / src / mongo / db / matcher / doc_validation_error_json_schema_test . cpp <nl> ppp b / src / mongo / db / matcher / doc_validation_error_json_schema_test . cpp <nl> TEST ( JSONSchemaLogicalKeywordValidation , CombineLogicalKeywords ) { <nl> doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> } <nl> <nl> + / / Array keywords . <nl> TEST ( JSONSchemaValidation , ArrayType ) { <nl> BSONObj query = fromjson ( <nl> " { ' $ jsonSchema ' : " <nl> TEST ( JSONSchemaValidation , SchemaDependencyAndPropertyDependency ) { <nl> doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> } <nl> <nl> + / / additionalProperties ( boolean argument ) <nl> + TEST ( JSONSchemaValidation , BasicAdditionalPropertiesFalse ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : { ' properties ' : { ' b ' : { ' type ' : ' number ' } } , ' additionalProperties ' : " <nl> + " false } } } " ) ; <nl> + BSONObj document = fromjson ( " { ' _id ' : 0 , ' a ' : 1 , ' b ' : 2 } " ) ; <nl> + BSONObj expectedError = fromjson ( <nl> + " { ' operatorName ' : ' $ jsonSchema ' , ' schemaRulesNotSatisfied ' : [ " <nl> + " { ' operatorName ' : ' additionalProperties ' , " <nl> + " ' specifiedAs ' : { additionalProperties : false } , " <nl> + " ' additionalProperties ' : [ ' _id ' , ' a ' ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + TEST ( JSONSchemaValidation , AdditionalPropertiesTrueProducesNoError ) { <nl> + BSONObj query = <nl> + fromjson ( " { ' $ jsonSchema ' : { ' minProperties ' : 100 , ' additionalProperties ' : true } } " ) ; <nl> + BSONObj document = fromjson ( " { ' _id ' : 0 , ' a ' : 1 , ' b ' : 2 } " ) ; <nl> + BSONObj expectedError = fromjson ( <nl> + " { ' operatorName ' : ' $ jsonSchema ' , " <nl> + " ' schemaRulesNotSatisfied ' : [ " <nl> + " { ' operatorName ' : ' minProperties ' , " <nl> + " ' specifiedAs ' : { minProperties : 100 } , " <nl> + " ' reason ' : ' specified number of properties was not satisfied ' , " <nl> + " ' numberOfProperties ' : 3 } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + TEST ( JSONSchemaValidation , BasicAdditionalPropertiesFalseNested ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : { ' properties ' : { ' b ' : { ' type ' : ' object ' , ' additionalProperties ' : false } } } } " ) ; <nl> + BSONObj document = fromjson ( " { ' b ' : { ' a ' : 1 } } " ) ; <nl> + BSONObj expectedError = fromjson ( <nl> + " { ' operatorName ' : ' $ jsonSchema ' , ' schemaRulesNotSatisfied ' : [ " <nl> + " { ' operatorName ' : ' properties ' , ' propertiesNotSatisfied ' : [ " <nl> + " { ' propertyName ' : ' b ' , ' details ' : [ " <nl> + " { ' operatorName ' : ' additionalProperties ' , " <nl> + " ' specifiedAs ' : { additionalProperties : false } , " <nl> + " ' additionalProperties ' : [ ' a ' ] } ] } ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + TEST ( JSONSchemaValidation , BasicAdditionalPropertiesFalseNestedMultiLevel ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : " <nl> + " { ' additionalProperties ' : false , ' properties ' : " <nl> + " { ' _id ' : { } , ' a ' : { ' type ' : ' object ' , ' additionalProperties ' : false } } } } } " ) ; <nl> + BSONObj document = fromjson ( " { _id : 1 , ' a ' : { ' b ' : 1 } , ' c ' : 1 } " ) ; <nl> + / / Report _id and c at the top level and b in the nested error . <nl> + BSONObj expectedError = fromjson ( <nl> + " { operatorName : ' $ jsonSchema ' , schemaRulesNotSatisfied : [ " <nl> + " { operatorName : ' properties ' , propertiesNotSatisfied : [ " <nl> + " { propertyName : ' a ' , details : [ " <nl> + " { operatorName : ' additionalProperties ' , " <nl> + " specifiedAs : { additionalProperties : false } , " <nl> + " additionalProperties : [ ' b ' ] } ] } ] } , " <nl> + " { operatorName : ' additionalProperties ' , " <nl> + " specifiedAs : { additionalProperties : false } , " <nl> + " additionalProperties : [ ' c ' ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + / / additionalProperties ( object argument ) <nl> + TEST ( JSONSchemaValidation , BasicAdditionalPropertiesSchema ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : " <nl> + " { ' properties ' : { ' a ' : { ' type ' : ' number ' } } , " <nl> + " ' additionalProperties ' : { ' type ' : ' string ' } } } } " ) ; <nl> + BSONObj document = fromjson ( <nl> + " { ' a ' : 1 , ' b ' : ' not this one ' , ' c ' : ' not this one either , but the next one ' , ' d ' : 1 } " ) ; <nl> + / / Should only produce an error for ' d ' . <nl> + BSONObj expectedError = fromjson ( <nl> + " { ' operatorName ' : ' $ jsonSchema ' , ' schemaRulesNotSatisfied ' : [ " <nl> + " { ' operatorName ' : ' additionalProperties ' , " <nl> + " ' reason ' : ' at least one additional property did not match the subschema ' , " <nl> + " ' failingProperty ' : ' d ' , ' details ' : [ " <nl> + " { ' operatorName ' : ' type ' , " <nl> + " ' specifiedAs ' : { type : ' string ' } , " <nl> + " ' reason ' : ' type did not match ' , " <nl> + " ' consideredValue ' : 1 , " <nl> + " ' consideredType ' : ' int ' } ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + TEST ( JSONSchemaValidation , BasicAdditionalPropertiesSchemaNested ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : " <nl> + " { ' properties ' : { ' b ' : { ' type ' : ' object ' , ' additionalProperties ' : { ' type ' : ' string ' } } } } } " ) ; <nl> + BSONObj document = fromjson ( " { ' b ' : { ' a ' : 1 } } " ) ; <nl> + BSONObj expectedError = fromjson ( <nl> + " { ' operatorName ' : ' $ jsonSchema ' , ' schemaRulesNotSatisfied ' : [ " <nl> + " { ' operatorName ' : ' properties ' , ' propertiesNotSatisfied ' : [ " <nl> + " { ' propertyName ' : ' b ' , ' details ' : [ " <nl> + " { ' operatorName ' : ' additionalProperties ' , " <nl> + " ' reason ' : ' at least one additional property did not match the subschema ' , " <nl> + " ' failingProperty ' : ' a ' , ' details ' : [ " <nl> + " { ' operatorName ' : ' type ' , " <nl> + " ' specifiedAs ' : { type : ' string ' } , " <nl> + " ' reason ' : ' type did not match ' , " <nl> + " ' consideredValue ' : 1 , " <nl> + " ' consideredType ' : ' int ' } ] } ] } ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + TEST ( JSONSchemaValidation , AdditionalPropertiesSchemaNoErrorWhenAdditionalPropertiesAreValid ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : " <nl> + " { ' properties ' : { ' _id ' : { } , ' a ' : { ' type ' : ' number ' } } , " <nl> + " ' minProperties ' : 10 , " <nl> + " ' additionalProperties ' : { ' type ' : ' string ' } } } } " ) ; <nl> + BSONObj document = fromjson ( <nl> + " { ' _id ' : ' foo ' , ' a ' : 1 , " <nl> + " ' b ' : ' all ' , ' c ' : ' additional ' , ' d ' : ' properties ' , ' e ' : ' are ' , ' f ' : ' strings ! ' } " ) ; <nl> + / / Should only produce an error for ' d ' . <nl> + BSONObj expectedError = fromjson ( <nl> + " { ' operatorName ' : ' $ jsonSchema ' , ' schemaRulesNotSatisfied ' : [ " <nl> + " { ' operatorName ' : ' minProperties ' , " <nl> + " ' specifiedAs ' : { minProperties : 10 } , " <nl> + " ' reason ' : ' specified number of properties was not satisfied ' , " <nl> + " ' numberOfProperties ' : 7 } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + / / patternProperties <nl> + TEST ( JSONSchemaValidation , BasicPatternProperties ) { <nl> + BSONObj query = fromjson ( " { ' $ jsonSchema ' : { ' patternProperties ' : { ' ^ S ' : { ' type ' : ' number ' } } } } " ) ; <nl> + BSONObj document = fromjson ( " { ' Super ' : 1 , ' Slow ' : ' 67 ' } " ) ; <nl> + BSONObj expectedError = fromjson ( <nl> + " { operatorName : ' $ jsonSchema ' , schemaRulesNotSatisfied : [ " <nl> + " { operatorName : ' patternProperties ' , details : [ " <nl> + " { propertyName : ' Slow ' , " <nl> + " regexMatched : ' ^ S ' , " <nl> + " details : [ { " <nl> + " operatorName : ' type ' , " <nl> + " specifiedAs : { type : ' number ' } , " <nl> + " reason : ' type did not match ' , " <nl> + " consideredValue : ' 67 ' , " <nl> + " consideredType : ' string ' } ] } ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + TEST ( JSONSchemaValidation , NestedPatternProperties ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : { ' properties ' : { ' a ' : { ' patternProperties ' : { ' ^ S ' : { ' type ' : " <nl> + " ' number ' } } } } } } " ) ; <nl> + BSONObj document = fromjson ( " { ' a ' : { ' String ' : 1 , ' StringNoNumber ' : ' 67 ' } } " ) ; <nl> + BSONObj expectedError = fromjson ( <nl> + " { operatorName : ' $ jsonSchema ' , schemaRulesNotSatisfied : [ " <nl> + " { operatorName : ' properties ' , propertiesNotSatisfied : [ " <nl> + " { propertyName : ' a ' , details : [ " <nl> + " { operatorName : ' patternProperties ' , details : [ " <nl> + " { propertyName : ' StringNoNumber ' , " <nl> + " regexMatched : ' ^ S ' , " <nl> + " details : [ " <nl> + " { operatorName : ' type ' , " <nl> + " specifiedAs : { type : ' number ' } , " <nl> + " reason : ' type did not match ' , " <nl> + " consideredValue : ' 67 ' , " <nl> + " consideredType : ' string ' } ] } ] } ] } ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + TEST ( JSONSchemaValidation , PatternPropertiesSomePatternsSatifised ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : { ' patternProperties ' : { ' ^ a ' : { ' type ' : ' string ' } , ' ^ S ' : { ' type ' : " <nl> + " ' number ' } } } } " ) ; <nl> + BSONObj document = fromjson ( <nl> + " { ' a ' : ' foo ' , ' Super ' : 1 , ' aa ' : ' also a string ' , ' aaa ' : ' never a number ! ' , " <nl> + " ' Slow ' : ' 67 ' } " ) ; <nl> + BSONObj expectedError = fromjson ( <nl> + " { operatorName : ' $ jsonSchema ' , schemaRulesNotSatisfied : [ " <nl> + " { operatorName : ' patternProperties ' , details : [ " <nl> + " { propertyName : ' Slow ' , " <nl> + " regexMatched : ' ^ S ' , " <nl> + " details : [ " <nl> + " { operatorName : ' type ' , " <nl> + " specifiedAs : { type : ' number ' } , " <nl> + " reason : ' type did not match ' , " <nl> + " consideredValue : ' 67 ' , " <nl> + " consideredType : ' string ' } ] } ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + TEST ( JSONSchemaValidation , PatternPropertiesRecursive ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : " <nl> + " { ' patternProperties ' : { ' ^ a ' : { ' patternProperties ' : { ' b + ' : { type : ' string ' } } } } } } " ) ; <nl> + BSONObj document = fromjson ( " { ' a ' : { ' bbbbb ' : 1 } } " ) ; <nl> + BSONObj expectedError = fromjson ( <nl> + " { operatorName : ' $ jsonSchema ' , schemaRulesNotSatisfied : [ " <nl> + " { operatorName : ' patternProperties ' , details : [ " <nl> + " { propertyName : ' a ' , regexMatched : ' ^ a ' , details : [ " <nl> + " { operatorName : ' patternProperties ' , details : [ " <nl> + " { propertyName : ' bbbbb ' , regexMatched : ' b + ' , details : [ " <nl> + " { operatorName : ' type ' , " <nl> + " specifiedAs : { type : ' string ' } , " <nl> + " reason : ' type did not match ' , " <nl> + " consideredValue : 1 , " <nl> + " consideredType : ' int ' } ] } ] } ] } ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + TEST ( JSONSchemaValidation , PatternPropertiesOneElementFailsMultiplePatternSchemas ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : { ' patternProperties ' : { ' ^ a ' : { ' minimum ' : 3 } , ' b $ ' : { ' maximum ' : 1 } } } } " ) ; <nl> + BSONObj document = fromjson ( " { ' a ' : 45 , ' b ' : 0 , ' ab ' : 2 } " ) ; <nl> + BSONObj expectedError = fromjson ( <nl> + " { ' operatorName ' : ' $ jsonSchema ' , ' schemaRulesNotSatisfied ' : [ " <nl> + " { ' operatorName ' : ' patternProperties ' , details : [ " <nl> + " { propertyName : ' ab ' , regexMatched : ' ^ a ' , details : [ " <nl> + " { operatorName : ' minimum ' , " <nl> + " specifiedAs : { minimum : 3 } , " <nl> + " reason : ' comparison failed ' , " <nl> + " consideredValue : 2 } ] } , " <nl> + " { propertyName : ' ab ' , regexMatched : ' b $ ' , details : [ " <nl> + " { operatorName : ' maximum ' , " <nl> + " specifiedAs : { maximum : 1 } , " <nl> + " reason : ' comparison failed ' , " <nl> + " consideredValue : 2 } ] } ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + / / patternProperties and additionalProperties ( false ) combined <nl> + TEST ( JSONSchemaValidation , PatternPropertiesAndAdditionalPropertiesFalse ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : { ' patternProperties ' : { ' ^ S ' : { ' type ' : ' number ' } } , " <nl> + " ' additionalProperties ' : false } } " ) ; <nl> + BSONObj document = fromjson ( " { ' Super ' : 1 , ' Slow ' : ' oh no a string ' , b : 1 } " ) ; <nl> + BSONObj expectedError = fromjson ( <nl> + " { operatorName : ' $ jsonSchema ' , schemaRulesNotSatisfied : [ " <nl> + " { operatorName : ' additionalProperties ' , " <nl> + " specifiedAs : { additionalProperties : false } , " <nl> + " additionalProperties : [ ' b ' , ' _id ' ] } , " <nl> + " { operatorName : ' patternProperties ' , details : [ " <nl> + " { propertyName : ' Slow ' , " <nl> + " regexMatched : ' ^ S ' , " <nl> + " details : [ " <nl> + " { operatorName : ' type ' , " <nl> + " specifiedAs : { type : ' number ' } , " <nl> + " reason : ' type did not match ' , " <nl> + " consideredValue : ' oh no a string ' , " <nl> + " consideredType : ' string ' } ] } ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + TEST ( JSONSchemaValidation , <nl> + PatternPropertiesAndAdditionalPropertiesFalseOnlyPatternPropertiesFails ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : " <nl> + " { ' properties ' : { _id : { } } , " <nl> + " ' patternProperties ' : { ' ^ S ' : { ' type ' : ' number ' } } , " <nl> + " ' additionalProperties ' : false } } " ) ; <nl> + BSONObj document = fromjson ( " { ' _id ' : 1 , ' Super ' : 1 , ' Slow ' : ' oh no a string ' } " ) ; <nl> + / / There should be no ' additionalProperties ' error . <nl> + BSONObj expectedError = fromjson ( <nl> + " { operatorName : ' $ jsonSchema ' , schemaRulesNotSatisfied : [ " <nl> + " { operatorName : ' patternProperties ' , details : [ " <nl> + " { propertyName : ' Slow ' , " <nl> + " regexMatched : ' ^ S ' , details : [ " <nl> + " { operatorName : ' type ' , " <nl> + " specifiedAs : { type : ' number ' } , " <nl> + " reason : ' type did not match ' , " <nl> + " consideredValue : ' oh no a string ' , " <nl> + " consideredType : ' string ' } ] } ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + TEST ( JSONSchemaValidation , PatternPropertiesAndAdditionalPropertiesTrueOnlyPatternPropertiesFails ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : " <nl> + " { ' properties ' : { _id : { } } , " <nl> + " ' patternProperties ' : { ' ^ S ' : { ' type ' : ' number ' } } , " <nl> + " ' additionalProperties ' : true } } " ) ; <nl> + BSONObj document = fromjson ( " { ' _id ' : 1 , ' Super ' : 1 , ' Slow ' : ' oh no a string ' , a : ' foo ' } " ) ; <nl> + / / There should be no ' additionalProperties ' error . <nl> + BSONObj expectedError = fromjson ( <nl> + " { operatorName : ' $ jsonSchema ' , schemaRulesNotSatisfied : [ " <nl> + " { operatorName : ' patternProperties ' , details : [ " <nl> + " { propertyName : ' Slow ' , " <nl> + " regexMatched : ' ^ S ' , details : [ " <nl> + " { operatorName : ' type ' , " <nl> + " specifiedAs : { type : ' number ' } , " <nl> + " reason : ' type did not match ' , " <nl> + " consideredValue : ' oh no a string ' , " <nl> + " consideredType : ' string ' } ] } ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + TEST ( JSONSchemaValidation , <nl> + PatternPropertiesAndAdditionalPropertiesFalseOnlyAdditionalPropertiesFails ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : " <nl> + " { ' patternProperties ' : { ' ^ S ' : { ' type ' : ' number ' } } , ' additionalProperties ' : false } } } " ) ; <nl> + BSONObj document = fromjson ( " { ' Super ' : 1 , ' Slow ' : 2 , ' b ' : ' clearly an extra property ' } " ) ; <nl> + / / There should be no ' patternProperties ' error . <nl> + BSONObj expectedError = fromjson ( <nl> + " { operatorName : ' $ jsonSchema ' , schemaRulesNotSatisfied : [ " <nl> + " { operatorName : ' additionalProperties ' , " <nl> + " specifiedAs : { additionalProperties : false } , " <nl> + " additionalProperties : [ ' b ' , ' _id ' ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + TEST ( JSONSchemaValidation , PatternPropertiesAndAdditionalPropertiesFalseNeitherFail ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : " <nl> + " { ' minProperties ' : 10 , " <nl> + " ' patternProperties ' : { ' ^ _id ' : { } , ' ^ S ' : { ' type ' : ' number ' } } , " <nl> + " ' additionalProperties ' : false } } } " ) ; <nl> + BSONObj document = fromjson ( " { ' _id ' : 1 , ' Super ' : 1 , ' Slow ' : 2 } " ) ; <nl> + / / The error should reference neither ' patternProperties ' nor ' additionalProperties ' . <nl> + BSONObj expectedError = fromjson ( <nl> + " { ' operatorName ' : ' $ jsonSchema ' , " <nl> + " ' schemaRulesNotSatisfied ' : [ " <nl> + " { ' operatorName ' : ' minProperties ' , " <nl> + " ' specifiedAs ' : { minProperties : 10 } , " <nl> + " ' reason ' : ' specified number of properties was not satisfied ' , " <nl> + " ' numberOfProperties ' : 3 } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + / / patternProperties and additionalProperties ( object ) combined <nl> + TEST ( JSONSchemaValidation , PatternPropertiesAndAdditionalPropertiesSchema ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : " <nl> + " { ' patternProperties ' : { ' ^ S ' : { ' type ' : ' number ' } } , " <nl> + " ' additionalProperties ' : { ' type ' : ' string ' } } } } " ) ; <nl> + BSONObj document = fromjson ( " { ' Super ' : 1 , ' Slow ' : ' oh no a string ' , b : 1 } " ) ; <nl> + BSONObj expectedError = fromjson ( <nl> + " { operatorName : ' $ jsonSchema ' , schemaRulesNotSatisfied : [ " <nl> + " { operatorName : ' additionalProperties ' , " <nl> + " reason : ' at least one additional property did not match the subschema ' , " <nl> + " failingProperty : ' b ' , details : [ " <nl> + " { operatorName : ' type ' , " <nl> + " specifiedAs : { type : ' string ' } , " <nl> + " reason : ' type did not match ' , " <nl> + " consideredValue : 1 , " <nl> + " consideredType : ' int ' } ] } , " <nl> + " { operatorName : ' patternProperties ' , details : [ " <nl> + " { propertyName : ' Slow ' , " <nl> + " regexMatched : ' ^ S ' , " <nl> + " details : [ " <nl> + " { operatorName : ' type ' , " <nl> + " specifiedAs : { type : ' number ' } , " <nl> + " reason : ' type did not match ' , " <nl> + " consideredValue : ' oh no a string ' , " <nl> + " consideredType : ' string ' } ] } ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + TEST ( JSONSchemaValidation , <nl> + PatternPropertiesAndAdditionalPropertiesSchemaOnlyPatternPropertiesFails ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : " <nl> + " { ' properties ' : { _id : { } } , " <nl> + " ' patternProperties ' : { ' ^ S ' : { ' type ' : ' number ' } } , " <nl> + " ' additionalProperties ' : { ' type ' : ' string ' } } } } " ) ; <nl> + BSONObj document = <nl> + fromjson ( " { _id : 1 , ' Super ' : 1 , ' Slow ' : ' oh no a string ' , b : ' actually a string ! ' } " ) ; <nl> + / / There should only be a ' patternProperties ' error <nl> + BSONObj expectedError = fromjson ( <nl> + " { operatorName : ' $ jsonSchema ' , schemaRulesNotSatisfied : [ " <nl> + " { operatorName : ' patternProperties ' , details : [ " <nl> + " { propertyName : ' Slow ' , " <nl> + " regexMatched : ' ^ S ' , " <nl> + " details : [ " <nl> + " { operatorName : ' type ' , " <nl> + " specifiedAs : { type : ' number ' } , " <nl> + " reason : ' type did not match ' , " <nl> + " consideredValue : ' oh no a string ' , " <nl> + " consideredType : ' string ' } ] } ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + TEST ( JSONSchemaValidation , <nl> + PatternPropertiesAndAdditionalPropertiesSchemaOnlyAdditionalPropertiesFails ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : " <nl> + " { ' patternProperties ' : { ' ^ S ' : { ' type ' : ' number ' } } , " <nl> + " ' additionalProperties ' : { ' type ' : ' string ' } } } } " ) ; <nl> + BSONObj document = fromjson ( " { ' Super ' : 1 , ' Slow ' : 2 , ' b ' : 1 } " ) ; <nl> + / / There should be no ' patternProperties ' error . <nl> + BSONObj expectedError = fromjson ( <nl> + " { operatorName : ' $ jsonSchema ' , schemaRulesNotSatisfied : [ " <nl> + " { operatorName : ' additionalProperties ' , " <nl> + " reason : ' at least one additional property did not match the subschema ' , " <nl> + " failingProperty : ' b ' , details : [ " <nl> + " { operatorName : ' type ' , " <nl> + " specifiedAs : { type : ' string ' } , " <nl> + " reason : ' type did not match ' , " <nl> + " consideredValue : 1 , consideredType : ' int ' } ] } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> + <nl> + TEST ( JSONSchemaValidation , PatternPropertiesAndAdditionalPropertiesSchemaNeitherFail ) { <nl> + BSONObj query = fromjson ( <nl> + " { ' $ jsonSchema ' : " <nl> + " { ' minProperties ' : 10 , " <nl> + " ' patternProperties ' : { ' ^ S ' : { ' type ' : ' number ' } } , " <nl> + " ' additionalProperties ' : { ' type ' : ' number ' } } } } " ) ; <nl> + BSONObj document = fromjson ( " { ' _id ' : 1 , ' Super ' : 1 , ' Slow ' : 2 , ' b ' : 1 } " ) ; <nl> + / / The error should reference neither ' patternProperties ' nor ' additionalProperties ' . <nl> + BSONObj expectedError = fromjson ( <nl> + " { ' operatorName ' : ' $ jsonSchema ' , " <nl> + " ' schemaRulesNotSatisfied ' : [ " <nl> + " { ' operatorName ' : ' minProperties ' , " <nl> + " ' specifiedAs ' : { minProperties : 10 } , " <nl> + " ' reason ' : ' specified number of properties was not satisfied ' , " <nl> + " ' numberOfProperties ' : 4 } ] } " ) ; <nl> + doc_validation_error : : verifyGeneratedError ( query , document , expectedError ) ; <nl> + } <nl> } / / namespace <nl> } / / namespace mongo <nl> mmm a / src / mongo / db / matcher / schema / expression_internal_schema_allowed_properties . cpp <nl> ppp b / src / mongo / db / matcher / schema / expression_internal_schema_allowed_properties . cpp <nl> InternalSchemaAllowedPropertiesMatchExpression : : InternalSchemaAllowedPropertiesM <nl> StringDataSet properties , <nl> StringData namePlaceholder , <nl> std : : vector < PatternSchema > patternProperties , <nl> - std : : unique_ptr < ExpressionWithPlaceholder > otherwise ) <nl> - : MatchExpression ( MatchExpression : : INTERNAL_SCHEMA_ALLOWED_PROPERTIES ) , <nl> + std : : unique_ptr < ExpressionWithPlaceholder > otherwise , <nl> + clonable_ptr < ErrorAnnotation > annotation ) <nl> + : MatchExpression ( MatchExpression : : INTERNAL_SCHEMA_ALLOWED_PROPERTIES , std : : move ( annotation ) ) , <nl> _properties ( std : : move ( properties ) ) , <nl> _namePlaceholder ( namePlaceholder ) , <nl> _patternProperties ( std : : move ( patternProperties ) ) , <nl> std : : unique_ptr < MatchExpression > InternalSchemaAllowedPropertiesMatchExpression : <nl> _properties , <nl> _namePlaceholder , <nl> std : : move ( clonedPatternProperties ) , <nl> - _otherwise - > shallowClone ( ) ) ; <nl> + _otherwise - > shallowClone ( ) , <nl> + _errorAnnotation ) ; <nl> return { std : : move ( clone ) } ; <nl> } <nl> <nl> mmm a / src / mongo / db / matcher / schema / expression_internal_schema_allowed_properties . h <nl> ppp b / src / mongo / db / matcher / schema / expression_internal_schema_allowed_properties . h <nl> class InternalSchemaAllowedPropertiesMatchExpression final : public MatchExpress <nl> StringDataSet properties , <nl> StringData namePlaceholder , <nl> std : : vector < PatternSchema > patternProperties , <nl> - std : : unique_ptr < ExpressionWithPlaceholder > otherwise ) ; <nl> + std : : unique_ptr < ExpressionWithPlaceholder > otherwise , <nl> + clonable_ptr < ErrorAnnotation > annotation = nullptr ) ; <nl> <nl> void debugString ( StringBuilder & debug , int indentationLevel ) const final ; <nl> <nl> class InternalSchemaAllowedPropertiesMatchExpression final : public MatchExpress <nl> visitor - > visit ( this ) ; <nl> } <nl> <nl> + const StringDataSet & getProperties ( ) const { <nl> + return _properties ; <nl> + } <nl> + <nl> + const std : : vector < PatternSchema > & getPatternProperties ( ) const { <nl> + return _patternProperties ; <nl> + } <nl> + <nl> private : <nl> ExpressionOptimizerFunc getOptimizer ( ) const final ; <nl> <nl> mmm a / src / mongo / db / matcher / schema / json_schema_parser . cpp <nl> ppp b / src / mongo / db / matcher / schema / json_schema_parser . cpp <nl> StatusWithMatchExpression parseAdditionalProperties ( <nl> if ( ! additionalPropertiesElt ) { <nl> / / The absence of the ' additionalProperties ' keyword is identical in meaning to the presence <nl> / / of ' additionalProperties ' with a value of true . <nl> - return { std : : make_unique < AlwaysTrueMatchExpression > ( ) } ; <nl> + return { std : : make_unique < AlwaysTrueMatchExpression > ( <nl> + doc_validation_error : : createAnnotation ( expCtx , AnnotationMode : : kIgnore ) ) } ; <nl> } <nl> <nl> if ( additionalPropertiesElt . type ( ) ! = BSONType : : Bool & & <nl> StatusWithMatchExpression parseAdditionalProperties ( <nl> < < " ' must be an object or a boolean " ) } ; <nl> } <nl> <nl> + auto annotation = doc_validation_error : : createAnnotation ( expCtx , AnnotationMode : : kIgnore ) ; <nl> if ( additionalPropertiesElt . type ( ) = = BSONType : : Bool ) { <nl> if ( additionalPropertiesElt . boolean ( ) ) { <nl> - return { std : : make_unique < AlwaysTrueMatchExpression > ( ) } ; <nl> + return { std : : make_unique < AlwaysTrueMatchExpression > ( std : : move ( annotation ) ) } ; <nl> } else { <nl> - return { std : : make_unique < AlwaysFalseMatchExpression > ( ) } ; <nl> + return { std : : make_unique < AlwaysFalseMatchExpression > ( std : : move ( annotation ) ) } ; <nl> } <nl> } <nl> <nl> StatusWithMatchExpression parseAllowedProperties ( <nl> auto otherwiseWithPlaceholder = std : : make_unique < ExpressionWithPlaceholder > ( <nl> kNamePlaceholder . toString ( ) , std : : move ( otherwiseExpr . getValue ( ) ) ) ; <nl> <nl> + clonable_ptr < ErrorAnnotation > annotation ; <nl> + / / In the case of no ' additionalProperties ' keyword , but a ' patternProperties ' keyword is <nl> + / / present , we still want ' $ _internalSchemaAllowedProperties ' to generate an error , so we <nl> + / / provide an annotation with empty information . <nl> + if ( additionalPropertiesElt . eoo ( ) ) { <nl> + annotation = doc_validation_error : : createAnnotation ( expCtx , " " , BSONObj ( ) ) ; <nl> + } else { <nl> + annotation = <nl> + doc_validation_error : : createAnnotation ( expCtx , " " , additionalPropertiesElt . wrap ( ) ) ; <nl> + } <nl> auto allowedPropertiesExpr = std : : make_unique < InternalSchemaAllowedPropertiesMatchExpression > ( <nl> std : : move ( propertyNames ) , <nl> kNamePlaceholder , <nl> std : : move ( patternProperties . getValue ( ) ) , <nl> - std : : move ( otherwiseWithPlaceholder ) ) ; <nl> + std : : move ( otherwiseWithPlaceholder ) , <nl> + std : : move ( annotation ) ) ; <nl> <nl> / / If this is a top - level schema , then we have no path and there is no need for an explicit <nl> / / object match node . <nl> StatusWithMatchExpression parseAllowedProperties ( <nl> } <nl> <nl> auto objectMatch = std : : make_unique < InternalSchemaObjectMatchExpression > ( <nl> - path , std : : move ( allowedPropertiesExpr ) ) ; <nl> + path , <nl> + std : : move ( allowedPropertiesExpr ) , <nl> + doc_validation_error : : createAnnotation ( expCtx , AnnotationMode : : kIgnoreButDescend ) ) ; <nl> <nl> return makeRestriction ( expCtx , BSONType : : Object , path , std : : move ( objectMatch ) , typeExpr ) ; <nl> } <nl>
SERVER - 49446 Implement validation error generation for additionalProperties and patternProperties keywords
mongodb/mongo
333e4e86d03e3bbf1d89654d40dfffc9525eb112
2020-10-20T00:01:23Z
mmm a / xbmc / interfaces / legacy / AddonUtils . h <nl> ppp b / xbmc / interfaces / legacy / AddonUtils . h <nl> <nl> <nl> # pragma once <nl> <nl> - # define ENABLE_TRACE_API <nl> + / / # define ENABLE_TRACE_API <nl> <nl> # include " threads / SingleLock . h " <nl> <nl>
turn back off trace logging .
xbmc/xbmc
6810e4f9306d4a3a80ec15eea6ee2c019fab8a9c
2012-09-18T03:40:12Z
mmm a / xbmc / Application . cpp <nl> ppp b / xbmc / Application . cpp <nl> void CApplication : : Stop ( int exitCode ) <nl> <nl> CVariant vExitCode ( CVariant : : VariantTypeObject ) ; <nl> vExitCode [ " exitcode " ] = exitCode ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : System , " xbmc " , " OnQuit " , vExitCode ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : System , " OnQuit " , vExitCode ) ; <nl> <nl> / / Abort any active screensaver <nl> WakeUpScreenSaverAndDPMS ( ) ; <nl> void CApplication : : OnPlayBackEnded ( ) <nl> <nl> CVariant data ( CVariant : : VariantTypeObject ) ; <nl> data [ " end " ] = true ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnStop " , m_itemCurrentFile , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnStop " , <nl> + m_itemCurrentFile , data ) ; <nl> <nl> CGUIMessage msg ( GUI_MSG_PLAYBACK_ENDED , 0 , 0 ) ; <nl> CServiceBroker : : GetGUI ( ) - > GetWindowManager ( ) . SendThreadMessage ( msg ) ; <nl> void CApplication : : OnPlayBackStopped ( ) <nl> <nl> CVariant data ( CVariant : : VariantTypeObject ) ; <nl> data [ " end " ] = false ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnStop " , m_itemCurrentFile , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnStop " , <nl> + m_itemCurrentFile , data ) ; <nl> <nl> CGUIMessage msg ( GUI_MSG_PLAYBACK_STOPPED , 0 , 0 ) ; <nl> CServiceBroker : : GetGUI ( ) - > GetWindowManager ( ) . SendThreadMessage ( msg ) ; <nl> void CApplication : : OnPlayBackPaused ( ) <nl> CVariant param ; <nl> param [ " player " ] [ " speed " ] = 0 ; <nl> param [ " player " ] [ " playerid " ] = CServiceBroker : : GetPlaylistPlayer ( ) . GetCurrentPlaylist ( ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnPause " , m_itemCurrentFile , param ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnPause " , <nl> + m_itemCurrentFile , param ) ; <nl> } <nl> <nl> void CApplication : : OnPlayBackResumed ( ) <nl> void CApplication : : OnPlayBackResumed ( ) <nl> CVariant param ; <nl> param [ " player " ] [ " speed " ] = 1 ; <nl> param [ " player " ] [ " playerid " ] = CServiceBroker : : GetPlaylistPlayer ( ) . GetCurrentPlaylist ( ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnResume " , m_itemCurrentFile , param ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnResume " , <nl> + m_itemCurrentFile , param ) ; <nl> } <nl> <nl> void CApplication : : OnPlayBackSpeedChanged ( int iSpeed ) <nl> void CApplication : : OnPlayBackSpeedChanged ( int iSpeed ) <nl> CVariant param ; <nl> param [ " player " ] [ " speed " ] = iSpeed ; <nl> param [ " player " ] [ " playerid " ] = CServiceBroker : : GetPlaylistPlayer ( ) . GetCurrentPlaylist ( ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnSpeedChanged " , m_itemCurrentFile , param ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnSpeedChanged " , <nl> + m_itemCurrentFile , param ) ; <nl> } <nl> <nl> void CApplication : : OnPlayBackSeek ( int64_t iTime , int64_t seekOffset ) <nl> void CApplication : : OnPlayBackSeek ( int64_t iTime , int64_t seekOffset ) <nl> CJSONUtils : : MillisecondsToTimeObject ( seekOffset , param [ " player " ] [ " seekoffset " ] ) ; <nl> param [ " player " ] [ " playerid " ] = CServiceBroker : : GetPlaylistPlayer ( ) . GetCurrentPlaylist ( ) ; <nl> param [ " player " ] [ " speed " ] = ( int ) m_appPlayer . GetPlaySpeed ( ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnSeek " , m_itemCurrentFile , param ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnSeek " , <nl> + m_itemCurrentFile , param ) ; <nl> CServiceBroker : : GetGUI ( ) - > GetInfoManager ( ) . GetInfoProviders ( ) . GetPlayerInfoProvider ( ) . SetDisplayAfterSeek ( 2500 , static_cast < int > ( seekOffset ) ) ; <nl> } <nl> <nl> void CApplication : : OnAVStarted ( const CFileItem & file ) <nl> CVariant param ; <nl> param [ " player " ] [ " speed " ] = 1 ; <nl> param [ " player " ] [ " playerid " ] = CServiceBroker : : GetPlaylistPlayer ( ) . GetCurrentPlaylist ( ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnAVStart " , m_itemCurrentFile , param ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnAVStart " , <nl> + m_itemCurrentFile , param ) ; <nl> } <nl> <nl> void CApplication : : OnAVChange ( ) <nl> void CApplication : : OnAVChange ( ) <nl> CVariant param ; <nl> param [ " player " ] [ " speed " ] = 1 ; <nl> param [ " player " ] [ " playerid " ] = CServiceBroker : : GetPlaylistPlayer ( ) . GetCurrentPlaylist ( ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnAVChange " , m_itemCurrentFile , param ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnAVChange " , <nl> + m_itemCurrentFile , param ) ; <nl> } <nl> <nl> void CApplication : : RequestVideoSettings ( const CFileItem & fileItem ) <nl> bool CApplication : : ToggleDPMS ( bool manual ) <nl> m_dpmsIsManual = false ; <nl> SetRenderGUI ( true ) ; <nl> CheckOSScreenSaverInhibitionSetting ( ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : GUI , " xbmc " , " OnDPMSDeactivated " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : GUI , " OnDPMSDeactivated " ) ; <nl> return dpms - > DisablePowerSaving ( ) ; <nl> } <nl> else <nl> bool CApplication : : ToggleDPMS ( bool manual ) <nl> m_dpmsIsManual = manual ; <nl> SetRenderGUI ( false ) ; <nl> CheckOSScreenSaverInhibitionSetting ( ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : GUI , " xbmc " , " OnDPMSActivated " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : GUI , " OnDPMSActivated " ) ; <nl> return true ; <nl> } <nl> } <nl> bool CApplication : : WakeUpScreenSaverAndDPMS ( bool bPowerOffKeyPressed / * = false <nl> / / allow listeners to ignore the deactivation if it precedes a powerdown / suspend etc <nl> CVariant data ( CVariant : : VariantTypeObject ) ; <nl> data [ " shuttingdown " ] = bPowerOffKeyPressed ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : GUI , " xbmc " , " OnScreensaverDeactivated " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : GUI , <nl> + " OnScreensaverDeactivated " , data ) ; <nl> } <nl> <nl> return result ; <nl> void CApplication : : ActivateScreenSaver ( bool forceType / * = false * / ) <nl> } <nl> <nl> m_screensaverActive = true ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : GUI , " xbmc " , " OnScreensaverActivated " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : GUI , " OnScreensaverActivated " ) ; <nl> <nl> / / disable screensaver lock from the login screen <nl> m_iScreenSaveLock = CServiceBroker : : GetGUI ( ) - > GetWindowManager ( ) . GetActiveWindow ( ) = = WINDOW_LOGIN_SCREEN ? 1 : 0 ; <nl> bool CApplication : : OnMessage ( CGUIMessage & message ) <nl> CVariant param ; <nl> param [ " player " ] [ " speed " ] = 1 ; <nl> param [ " player " ] [ " playerid " ] = CServiceBroker : : GetPlaylistPlayer ( ) . GetCurrentPlaylist ( ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnPlay " , m_itemCurrentFile , param ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnPlay " , <nl> + m_itemCurrentFile , param ) ; <nl> <nl> / / we don ' t want a busy dialog when switching channels <nl> if ( ! m_itemCurrentFile - > IsLiveTV ( ) ) <nl> void CApplication : : VolumeChanged ( ) <nl> CVariant data ( CVariant : : VariantTypeObject ) ; <nl> data [ " volume " ] = GetVolumePercent ( ) ; <nl> data [ " muted " ] = m_muted ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Application , " xbmc " , " OnVolumeChanged " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Application , " OnVolumeChanged " , <nl> + data ) ; <nl> <nl> / / if player has volume control , set it . <nl> m_appPlayer . SetVolume ( m_volumeLevel ) ; <nl> mmm a / xbmc / GUIInfoManager . cpp <nl> ppp b / xbmc / GUIInfoManager . cpp <nl> void CGUIInfoManager : : SetCurrentItem ( const CFileItem & item ) <nl> <nl> m_infoProviders . InitCurrentItem ( m_currentFile ) ; <nl> <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Info , " xbmc " , " OnChanged " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Info , " OnChanged " ) ; <nl> } <nl> <nl> void CGUIInfoManager : : SetCurrentAlbumThumb ( const std : : string & thumbFileName ) <nl> mmm a / xbmc / PartyModeManager . cpp <nl> ppp b / xbmc / PartyModeManager . cpp <nl> void CPartyModeManager : : Announce ( ) <nl> <nl> data [ " player " ] [ " playerid " ] = CServiceBroker : : GetPlaylistPlayer ( ) . GetCurrentPlaylist ( ) ; <nl> data [ " property " ] [ " partymode " ] = m_bEnabled ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnPropertyChanged " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnPropertyChanged " , <nl> + data ) ; <nl> } <nl> } <nl> mmm a / xbmc / PlayListPlayer . cpp <nl> ppp b / xbmc / PlayListPlayer . cpp <nl> void CPlayListPlayer : : AnnouncePropertyChanged ( int iPlaylist , const std : : string & <nl> CVariant data ; <nl> data [ " player " ] [ " playerid " ] = iPlaylist ; <nl> data [ " property " ] [ strProperty ] = value ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnPropertyChanged " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnPropertyChanged " , <nl> + data ) ; <nl> } <nl> <nl> int PLAYLIST : : CPlayListPlayer : : GetMessageMask ( ) <nl> mmm a / xbmc / cores / VideoPlayer / VideoPlayerRadioRDS . cpp <nl> ppp b / xbmc / cores / VideoPlayer / VideoPlayerRadioRDS . cpp <nl> unsigned int CDVDRadioRDSData : : DecodeTA_TP ( uint8_t * msgElement ) <nl> <nl> CVariant data ( CVariant : : VariantTypeObject ) ; <nl> data [ " on " ] = true ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : PVR , " xbmc " , " RDSRadioTA " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : PVR , " RDSRadioTA " , data ) ; <nl> } <nl> <nl> if ( ! traffic_announcement & & m_TA_TP_TrafficAdvisory & & CServiceBroker : : GetSettingsComponent ( ) - > GetSettings ( ) - > GetBool ( " pvrplayback . trafficadvisory " ) ) <nl> unsigned int CDVDRadioRDSData : : DecodeTA_TP ( uint8_t * msgElement ) <nl> <nl> CVariant data ( CVariant : : VariantTypeObject ) ; <nl> data [ " on " ] = false ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : PVR , " xbmc " , " RDSRadioTA " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : PVR , " RDSRadioTA " , data ) ; <nl> } <nl> <nl> return 4 ; <nl> unsigned int CDVDRadioRDSData : : DecodeRTC ( uint8_t * msgElement ) <nl> <nl> CVariant data ( CVariant : : VariantTypeObject ) ; <nl> data [ " dateTime " ] = ( m_RTC_DateTime . IsValid ( ) ) ? m_RTC_DateTime . GetAsRFC1123DateTime ( ) : " " ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : PVR , " xbmc " , " RDSRadioRTC " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : PVR , " RDSRadioRTC " , data ) ; <nl> <nl> return 8 ; <nl> } <nl> void CDVDRadioRDSData : : SendTMCSignal ( unsigned int flags , uint8_t * data ) <nl> msg [ " y " ] = ( unsigned int ) ( m_TMC_LastData [ 1 ] < < 8 | m_TMC_LastData [ 2 ] ) ; <nl> msg [ " z " ] = ( unsigned int ) ( m_TMC_LastData [ 3 ] < < 8 | m_TMC_LastData [ 4 ] ) ; <nl> <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : PVR , " xbmc " , " RDSRadioTMC " , msg ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : PVR , " RDSRadioTMC " , msg ) ; <nl> } <nl> } <nl> mmm a / xbmc / dialogs / GUIDialogKeyboardGeneric . cpp <nl> ppp b / xbmc / dialogs / GUIDialogKeyboardGeneric . cpp <nl> <nl> * See LICENSES / README . md for more information . <nl> * / <nl> <nl> - # include " interfaces / AnnouncementManager . h " <nl> - # include " input / XBMC_vkeys . h " <nl> - # include " input / InputCodingTable . h " <nl> + # include " GUIDialogKeyboardGeneric . h " <nl> + <nl> + # include " GUIDialogNumeric . h " <nl> + # include " GUIUserMessages . h " <nl> + # include " ServiceBroker . h " <nl> # include " guilib / GUIComponent . h " <nl> # include " guilib / GUIEditControl . h " <nl> # include " guilib / GUILabelControl . h " <nl> # include " guilib / GUIWindowManager . h " <nl> - # include " input / KeyboardLayoutManager . h " <nl> - # include " input / Key . h " <nl> # include " guilib / LocalizeStrings . h " <nl> - # include " GUIUserMessages . h " <nl> - # include " GUIDialogNumeric . h " <nl> - # include " GUIDialogKeyboardGeneric . h " <nl> - # include " ServiceBroker . h " <nl> + # include " input / InputCodingTable . h " <nl> + # include " input / Key . h " <nl> + # include " input / KeyboardLayoutManager . h " <nl> + # include " input / XBMC_vkeys . h " <nl> + # include " interfaces / AnnouncementManager . h " <nl> + # include " messaging / ApplicationMessenger . h " <nl> # include " settings / Settings . h " <nl> # include " settings / SettingsComponent . h " <nl> + # include " utils / CharsetConverter . h " <nl> # include " utils / RegExp . h " <nl> - # include " utils / Variant . h " <nl> # include " utils / StringUtils . h " <nl> - # include " messaging / ApplicationMessenger . h " <nl> - # include " utils / CharsetConverter . h " <nl> - # include " windowing / WinSystem . h " <nl> + # include " utils / Variant . h " <nl> # include " utils / log . h " <nl> + # include " windowing / WinSystem . h " <nl> <nl> # ifdef TARGET_ANDROID <nl> # include < androidjni / Intent . h > <nl> void CGUIDialogKeyboardGeneric : : OnInitWindow ( ) <nl> data [ " title " ] = m_strHeading ; <nl> data [ " type " ] = ! m_hiddenInput ? " keyboard " : " password " ; <nl> data [ " value " ] = GetText ( ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Input , " xbmc " , " OnInputRequested " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Input , " OnInputRequested " , data ) ; <nl> } <nl> <nl> bool CGUIDialogKeyboardGeneric : : OnAction ( const CAction & action ) <nl> void CGUIDialogKeyboardGeneric : : OnDeinitWindow ( int nextWindowID ) <nl> / / reset the heading ( we don ' t always have this ) <nl> m_strHeading = " " ; <nl> <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Input , " xbmc " , " OnInputFinished " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Input , " OnInputFinished " ) ; <nl> } <nl> <nl> void CGUIDialogKeyboardGeneric : : MoveCursor ( int iAmount ) <nl> mmm a / xbmc / dialogs / GUIDialogNumeric . cpp <nl> ppp b / xbmc / dialogs / GUIDialogNumeric . cpp <nl> void CGUIDialogNumeric : : OnInitWindow ( ) <nl> <nl> data [ " value " ] = GetOutputString ( ) ; <nl> <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Input , " xbmc " , " OnInputRequested " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Input , " OnInputRequested " , data ) ; <nl> } <nl> <nl> void CGUIDialogNumeric : : OnDeinitWindow ( int nextWindowID ) <nl> void CGUIDialogNumeric : : OnDeinitWindow ( int nextWindowID ) <nl> / / call base class <nl> CGUIDialog : : OnDeinitWindow ( nextWindowID ) ; <nl> <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Input , " xbmc " , " OnInputFinished " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Input , " OnInputFinished " ) ; <nl> } <nl> <nl> bool CGUIDialogNumeric : : OnAction ( const CAction & action ) <nl> mmm a / xbmc / games / dialogs / osd / DialogGameVolume . cpp <nl> ppp b / xbmc / games / dialogs / osd / DialogGameVolume . cpp <nl> bool CDialogGameVolume : : IsShown ( ) const <nl> } <nl> <nl> void CDialogGameVolume : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> - const char * sender , <nl> - const char * message , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> const CVariant & data ) <nl> { <nl> - if ( flag = = ANNOUNCEMENT : : Application & & strcmp ( message , " OnVolumeChanged " ) = = 0 ) <nl> + if ( flag = = ANNOUNCEMENT : : Application & & message = = " OnVolumeChanged " ) <nl> { <nl> const float volumePercent = static_cast < float > ( data [ " volume " ] . asDouble ( ) ) ; <nl> <nl> mmm a / xbmc / games / dialogs / osd / DialogGameVolume . h <nl> ppp b / xbmc / games / dialogs / osd / DialogGameVolume . h <nl> class CDialogGameVolume : public CGUIDialogSlider , / / GUI interface <nl> / / implementation of IGUIVolumeBarCallback <nl> bool IsShown ( ) const override ; <nl> <nl> - / / implementation of IAnnouncer <nl> - void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> - const char * sender , <nl> - const char * message , <nl> - const CVariant & data ) override ; <nl> + / / implementation of IAnnouncer <nl> + void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) override ; <nl> <nl> protected : <nl> / / implementation of CGUIWindow via CGUIDialogSlider <nl> mmm a / xbmc / interfaces / AnnouncementManager . cpp <nl> ppp b / xbmc / interfaces / AnnouncementManager . cpp <nl> <nl> <nl> using namespace ANNOUNCEMENT ; <nl> <nl> + const std : : string CAnnouncementManager : : ANNOUNCEMENT_SENDER = " xbmc " ; <nl> + <nl> CAnnouncementManager : : CAnnouncementManager ( ) : CThread ( " Announce " ) <nl> { <nl> } <nl> void CAnnouncementManager : : RemoveAnnouncer ( IAnnouncer * listener ) <nl> } <nl> } <nl> <nl> - void CAnnouncementManager : : Announce ( AnnouncementFlag flag , const char * sender , const char * message ) <nl> + void CAnnouncementManager : : Announce ( AnnouncementFlag flag , const std : : string & message ) <nl> { <nl> CVariant data ; <nl> - Announce ( flag , sender , message , CFileItemPtr ( ) , data ) ; <nl> + Announce ( flag , ANNOUNCEMENT_SENDER , message , CFileItemPtr ( ) , data ) ; <nl> } <nl> <nl> - void CAnnouncementManager : : Announce ( AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) <nl> + void CAnnouncementManager : : Announce ( AnnouncementFlag flag , <nl> + const std : : string & message , <nl> + const CVariant & data ) <nl> { <nl> - Announce ( flag , sender , message , CFileItemPtr ( ) , data ) ; <nl> + Announce ( flag , ANNOUNCEMENT_SENDER , message , CFileItemPtr ( ) , data ) ; <nl> + } <nl> + <nl> + void CAnnouncementManager : : Announce ( AnnouncementFlag flag , <nl> + const std : : string & message , <nl> + const std : : shared_ptr < const CFileItem > & item ) <nl> + { <nl> + CVariant data ; <nl> + Announce ( flag , ANNOUNCEMENT_SENDER , message , item , data ) ; <nl> + } <nl> + <nl> + void CAnnouncementManager : : Announce ( AnnouncementFlag flag , <nl> + const std : : string & message , <nl> + const std : : shared_ptr < const CFileItem > & item , <nl> + const CVariant & data ) <nl> + { <nl> + Announce ( flag , ANNOUNCEMENT_SENDER , message , item , data ) ; <nl> } <nl> <nl> - void CAnnouncementManager : : Announce ( AnnouncementFlag flag , const char * sender , const char * message , const std : : shared_ptr < const CFileItem > & item ) <nl> + <nl> + void CAnnouncementManager : : Announce ( AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message ) <nl> { <nl> CVariant data ; <nl> - Announce ( flag , sender , message , item , data ) ; <nl> + Announce ( flag , sender , message , CFileItemPtr ( ) , data ) ; <nl> + } <nl> + <nl> + void CAnnouncementManager : : Announce ( AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) <nl> + { <nl> + Announce ( flag , sender , message , CFileItemPtr ( ) , data ) ; <nl> } <nl> <nl> - void CAnnouncementManager : : Announce ( AnnouncementFlag flag , const char * sender , const char * message , const std : : shared_ptr < const CFileItem > & item , const CVariant & data ) <nl> + void CAnnouncementManager : : Announce ( AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const std : : shared_ptr < const CFileItem > & item , <nl> + const CVariant & data ) <nl> { <nl> CAnnounceData announcement ; <nl> announcement . flag = flag ; <nl> void CAnnouncementManager : : Announce ( AnnouncementFlag flag , const char * sender , c <nl> m_queueEvent . Set ( ) ; <nl> } <nl> <nl> - void CAnnouncementManager : : DoAnnounce ( AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) <nl> + void CAnnouncementManager : : DoAnnounce ( AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) <nl> { <nl> CLog : : Log ( LOGDEBUG , LOGANNOUNCE , " CAnnouncementManager - Announcement : { } from { } " , message , sender ) ; <nl> <nl> void CAnnouncementManager : : DoAnnounce ( AnnouncementFlag flag , const char * sender , <nl> announcers [ i ] - > Announce ( flag , sender , message , data ) ; <nl> } <nl> <nl> - void CAnnouncementManager : : DoAnnounce ( AnnouncementFlag flag , const char * sender , const char * message , CFileItemPtr item , const CVariant & data ) <nl> + void CAnnouncementManager : : DoAnnounce ( AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + CFileItemPtr item , <nl> + const CVariant & data ) <nl> { <nl> if ( item = = nullptr ) <nl> { <nl> mmm a / xbmc / interfaces / AnnouncementManager . h <nl> ppp b / xbmc / interfaces / AnnouncementManager . h <nl> namespace ANNOUNCEMENT <nl> void AddAnnouncer ( IAnnouncer * listener ) ; <nl> void RemoveAnnouncer ( IAnnouncer * listener ) ; <nl> <nl> - void Announce ( AnnouncementFlag flag , const char * sender , const char * message ) ; <nl> - void Announce ( AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) ; <nl> - void Announce ( AnnouncementFlag flag , const char * sender , const char * message , <nl> - const std : : shared_ptr < const CFileItem > & item ) ; <nl> - void Announce ( AnnouncementFlag flag , const char * sender , const char * message , <nl> - const std : : shared_ptr < const CFileItem > & item , const CVariant & data ) ; <nl> + void Announce ( AnnouncementFlag flag , const std : : string & message ) ; <nl> + void Announce ( AnnouncementFlag flag , const std : : string & message , const CVariant & data ) ; <nl> + void Announce ( AnnouncementFlag flag , <nl> + const std : : string & message , <nl> + const std : : shared_ptr < const CFileItem > & item ) ; <nl> + void Announce ( AnnouncementFlag flag , <nl> + const std : : string & message , <nl> + const std : : shared_ptr < const CFileItem > & item , <nl> + const CVariant & data ) ; <nl> + <nl> + void Announce ( AnnouncementFlag flag , const std : : string & sender , const std : : string & message ) ; <nl> + void Announce ( AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) ; <nl> + void Announce ( AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const std : : shared_ptr < const CFileItem > & item , <nl> + const CVariant & data ) ; <nl> + <nl> + / / The sender is not related to the application name . <nl> + / / Also it ' s part of Kodi ' s API - changing it will break <nl> + / / a big number of python addons and third party json consumers . <nl> + static const std : : string ANNOUNCEMENT_SENDER ; <nl> <nl> protected : <nl> void Process ( ) override ; <nl> - void DoAnnounce ( AnnouncementFlag flag , const char * sender , const char * message , CFileItemPtr item , const CVariant & data ) ; <nl> - void DoAnnounce ( AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) ; <nl> + void DoAnnounce ( AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + CFileItemPtr item , <nl> + const CVariant & data ) ; <nl> + void DoAnnounce ( AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) ; <nl> <nl> struct CAnnounceData <nl> { <nl> mmm a / xbmc / interfaces / IAnnouncer . h <nl> ppp b / xbmc / interfaces / IAnnouncer . h <nl> <nl> <nl> # pragma once <nl> <nl> + # include < string > <nl> + <nl> class CVariant ; <nl> namespace ANNOUNCEMENT <nl> { <nl> namespace ANNOUNCEMENT <nl> public : <nl> IAnnouncer ( ) = default ; <nl> virtual ~ IAnnouncer ( ) = default ; <nl> - virtual void Announce ( AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) = 0 ; <nl> + virtual void Announce ( AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) = 0 ; <nl> } ; <nl> } <nl> mmm a / xbmc / interfaces / json - rpc / IJSONRPCAnnouncer . h <nl> ppp b / xbmc / interfaces / json - rpc / IJSONRPCAnnouncer . h <nl> namespace JSONRPC <nl> ~ IJSONRPCAnnouncer ( ) override = default ; <nl> <nl> protected : <nl> - static std : : string AnnouncementToJSONRPC ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * method , const CVariant & data , bool compactOutput ) <nl> + static std : : string AnnouncementToJSONRPC ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & method , <nl> + const CVariant & data , <nl> + bool compactOutput ) <nl> { <nl> CVariant root ; <nl> root [ " jsonrpc " ] = " 2 . 0 " ; <nl> mmm a / xbmc / interfaces / json - rpc / JSONRPC . cpp <nl> ppp b / xbmc / interfaces / json - rpc / JSONRPC . cpp <nl> JSONRPC_STATUS CJSONRPC : : SetConfiguration ( const std : : string & method , ITransportL <nl> JSONRPC_STATUS CJSONRPC : : NotifyAll ( const std : : string & method , ITransportLayer * transport , IClient * client , const CVariant & parameterObject , CVariant & result ) <nl> { <nl> if ( parameterObject [ " data " ] . isNull ( ) ) <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Other , parameterObject [ " sender " ] . asString ( ) . c_str ( ) , <nl> - parameterObject [ " message " ] . asString ( ) . c_str ( ) ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Other , <nl> + parameterObject [ " sender " ] . asString ( ) , <nl> + parameterObject [ " message " ] . asString ( ) ) ; <nl> else <nl> { <nl> CVariant data = parameterObject [ " data " ] ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Other , parameterObject [ " sender " ] . asString ( ) . c_str ( ) , <nl> - parameterObject [ " message " ] . asString ( ) . c_str ( ) , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Other , <nl> + parameterObject [ " sender " ] . asString ( ) , <nl> + parameterObject [ " message " ] . asString ( ) , data ) ; <nl> } <nl> <nl> return ACK ; <nl> mmm a / xbmc / interfaces / python / XBPython . cpp <nl> ppp b / xbmc / interfaces / python / XBPython . cpp <nl> XBPython : : ~ XBPython ( ) <nl> ( l . hadSomethingRemoved ? ( std : : find ( l . begin ( ) , l . end ( ) , v ) ! = l . end ( ) ) : true ) <nl> <nl> void XBPython : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> - const char * sender , <nl> - const char * message , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> const CVariant & data ) <nl> { <nl> if ( flag & ANNOUNCEMENT : : VideoLibrary ) <nl> { <nl> - if ( strcmp ( message , " OnScanFinished " ) = = 0 ) <nl> + if ( message = = " OnScanFinished " ) <nl> OnScanFinished ( " video " ) ; <nl> - else if ( strcmp ( message , " OnScanStarted " ) = = 0 ) <nl> + else if ( message = = " OnScanStarted " ) <nl> OnScanStarted ( " video " ) ; <nl> - else if ( strcmp ( message , " OnCleanStarted " ) = = 0 ) <nl> + else if ( message = = " OnCleanStarted " ) <nl> OnCleanStarted ( " video " ) ; <nl> - else if ( strcmp ( message , " OnCleanFinished " ) = = 0 ) <nl> + else if ( message = = " OnCleanFinished " ) <nl> OnCleanFinished ( " video " ) ; <nl> } <nl> else if ( flag & ANNOUNCEMENT : : AudioLibrary ) <nl> { <nl> - if ( strcmp ( message , " OnScanFinished " ) = = 0 ) <nl> + if ( message = = " OnScanFinished " ) <nl> OnScanFinished ( " music " ) ; <nl> - else if ( strcmp ( message , " OnScanStarted " ) = = 0 ) <nl> + else if ( message = = " OnScanStarted " ) <nl> OnScanStarted ( " music " ) ; <nl> - else if ( strcmp ( message , " OnCleanStarted " ) = = 0 ) <nl> + else if ( message = = " OnCleanStarted " ) <nl> OnCleanStarted ( " music " ) ; <nl> - else if ( strcmp ( message , " OnCleanFinished " ) = = 0 ) <nl> + else if ( message = = " OnCleanFinished " ) <nl> OnCleanFinished ( " music " ) ; <nl> } <nl> else if ( flag & ANNOUNCEMENT : : GUI ) <nl> { <nl> - if ( strcmp ( message , " OnScreensaverDeactivated " ) = = 0 ) <nl> + if ( message = = " OnScreensaverDeactivated " ) <nl> OnScreensaverDeactivated ( ) ; <nl> - else if ( strcmp ( message , " OnScreensaverActivated " ) = = 0 ) <nl> + else if ( message = = " OnScreensaverActivated " ) <nl> OnScreensaverActivated ( ) ; <nl> - else if ( strcmp ( message , " OnDPMSDeactivated " ) = = 0 ) <nl> + else if ( message = = " OnDPMSDeactivated " ) <nl> OnDPMSDeactivated ( ) ; <nl> - else if ( strcmp ( message , " OnDPMSActivated " ) = = 0 ) <nl> + else if ( message = = " OnDPMSActivated " ) <nl> OnDPMSActivated ( ) ; <nl> } <nl> <nl> mmm a / xbmc / interfaces / python / XBPython . h <nl> ppp b / xbmc / interfaces / python / XBPython . h <nl> class XBPython : public IPlayerCallback , <nl> void OnQueueNextItem ( ) override ; <nl> <nl> void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> - const char * sender , <nl> - const char * message , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> const CVariant & data ) override ; <nl> void RegisterPythonPlayerCallBack ( IPlayerCallback * pCallback ) ; <nl> void UnregisterPythonPlayerCallBack ( IPlayerCallback * pCallback ) ; <nl> mmm a / xbmc / listproviders / DirectoryProvider . cpp <nl> ppp b / xbmc / listproviders / DirectoryProvider . cpp <nl> bool CDirectoryProvider : : Update ( bool forceRefresh ) <nl> return changed ; / / ! @ todo Also returned changed if properties are changed ( if so , need to update scroll to letter ) . <nl> } <nl> <nl> - void CDirectoryProvider : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) <nl> + void CDirectoryProvider : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) <nl> { <nl> / / we are only interested in library , player and GUI changes <nl> if ( ( flag & ( ANNOUNCEMENT : : VideoLibrary | ANNOUNCEMENT : : AudioLibrary | ANNOUNCEMENT : : Player | ANNOUNCEMENT : : GUI ) ) = = 0 ) <nl> void CDirectoryProvider : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const cha <nl> <nl> if ( flag & ANNOUNCEMENT : : Player ) <nl> { <nl> - if ( strcmp ( message , " OnPlay " ) = = 0 | | <nl> - strcmp ( message , " OnResume " ) = = 0 | | <nl> - strcmp ( message , " OnStop " ) = = 0 ) <nl> + if ( message = = " OnPlay " | | message = = " OnResume " | | message = = " OnStop " ) <nl> { <nl> if ( m_currentSort . sortBy = = SortByNone | | / / not nice , but many directories that need to be refreshed on start / stop have no special sort order ( e . g . in progress movies ) <nl> m_currentSort . sortBy = = SortByLastPlayed | | <nl> void CDirectoryProvider : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const cha <nl> <nl> / / if there was a database update , we set the update state <nl> / / to PENDING to fire off a new job in the next update <nl> - if ( strcmp ( message , " OnScanFinished " ) = = 0 | | <nl> - strcmp ( message , " OnCleanFinished " ) = = 0 | | <nl> - strcmp ( message , " OnUpdate " ) = = 0 | | <nl> - strcmp ( message , " OnRemove " ) = = 0 | | <nl> - strcmp ( message , " OnRefresh " ) = = 0 ) <nl> + if ( message = = " OnScanFinished " | | message = = " OnCleanFinished " | | message = = " OnUpdate " | | <nl> + message = = " OnRemove " | | message = = " OnRefresh " ) <nl> m_updateState = INVALIDATED ; <nl> } <nl> } <nl> mmm a / xbmc / listproviders / DirectoryProvider . h <nl> ppp b / xbmc / listproviders / DirectoryProvider . h <nl> class CDirectoryProvider : <nl> ~ CDirectoryProvider ( ) override ; <nl> <nl> bool Update ( bool forceRefresh ) override ; <nl> - void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) override ; <nl> + void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) override ; <nl> void Fetch ( std : : vector < CGUIListItemPtr > & items ) override ; <nl> void Reset ( ) override ; <nl> bool OnClick ( const CGUIListItemPtr & item ) override ; <nl> mmm a / xbmc / music / MusicDatabase . cpp <nl> ppp b / xbmc / music / MusicDatabase . cpp <nl> static void AnnounceRemove ( const std : : string & content , int id ) <nl> data [ " id " ] = id ; <nl> if ( g_application . IsMusicScanning ( ) ) <nl> data [ " transaction " ] = true ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " xbmc " , " OnRemove " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " OnRemove " , data ) ; <nl> } <nl> <nl> static void AnnounceUpdate ( const std : : string & content , int id , bool added = false ) <nl> static void AnnounceUpdate ( const std : : string & content , int id , bool added = fals <nl> data [ " transaction " ] = true ; <nl> if ( added ) <nl> data [ " added " ] = true ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " xbmc " , " OnUpdate " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " OnUpdate " , data ) ; <nl> } <nl> <nl> CMusicDatabase : : CMusicDatabase ( void ) <nl> int CMusicDatabase : : Cleanup ( CGUIDialogProgress * progressDialog / * = nullptr * / ) <nl> int ret = ERROR_OK ; <nl> unsigned int time = XbmcThreads : : SystemClockMillis ( ) ; <nl> CLog : : Log ( LOGINFO , " % s : Starting musicdatabase cleanup . . " , __FUNCTION__ ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " xbmc " , " OnCleanStarted " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " OnCleanStarted " ) ; <nl> <nl> SetLibraryLastCleaned ( ) ; <nl> <nl> int CMusicDatabase : : Cleanup ( CGUIDialogProgress * progressDialog / * = nullptr * / ) <nl> time = XbmcThreads : : SystemClockMillis ( ) - time ; <nl> CLog : : Log ( LOGINFO , " % s : Cleaning musicdatabase done . Operation took % s " , __FUNCTION__ , <nl> StringUtils : : SecondsToTimeString ( time / 1000 ) . c_str ( ) ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " xbmc " , " OnCleanFinished " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " OnCleanFinished " ) ; <nl> <nl> if ( ! Compress ( false ) ) <nl> { <nl> int CMusicDatabase : : Cleanup ( CGUIDialogProgress * progressDialog / * = nullptr * / ) <nl> RollbackTransaction ( ) ; <nl> / / Recreate DELETE triggers on song_artist and album_artist <nl> CreateRemovedLinkTriggers ( ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " xbmc " , " OnCleanFinished " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " OnCleanFinished " ) ; <nl> return ret ; <nl> } <nl> <nl> void CMusicDatabase : : ExportToXML ( const CLibExportSettings & settings , CGUIDialog <nl> data [ " file " ] = xmlFile ; <nl> if ( iFailCount > 0 ) <nl> data [ " failcount " ] = iFailCount ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " xbmc " , " OnExport " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " OnExport " , <nl> + data ) ; <nl> } <nl> } <nl> catch ( . . . ) <nl> mmm a / xbmc / music / infoscanner / MusicInfoScanner . cpp <nl> ppp b / xbmc / music / infoscanner / MusicInfoScanner . cpp <nl> CMusicInfoScanner : : ~ CMusicInfoScanner ( ) = default ; <nl> void CMusicInfoScanner : : Process ( ) <nl> { <nl> m_bStop = false ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " xbmc " , " OnScanStarted " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " OnScanStarted " ) ; <nl> try <nl> { <nl> if ( m_showDialog & & ! CServiceBroker : : GetSettingsComponent ( ) - > GetSettings ( ) - > GetBool ( CSettings : : SETTING_MUSICLIBRARY_BACKGROUNDUPDATE ) ) <nl> void CMusicInfoScanner : : Process ( ) <nl> CLog : : Log ( LOGDEBUG , " % s - Finished scan " , __FUNCTION__ ) ; <nl> <nl> m_bRunning = false ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " xbmc " , " OnScanFinished " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " OnScanFinished " ) ; <nl> <nl> / / we need to clear the musicdb cache and update any active lists <nl> CUtil : : DeleteMusicDatabaseDirectoryCache ( ) ; <nl> mmm a / xbmc / network / AirPlayServer . cpp <nl> ppp b / xbmc / network / AirPlayServer . cpp <nl> <nl> * from Airplayer . https : / / github . com / PascalW / Airplayer <nl> * / <nl> <nl> - # include " network / Network . h " <nl> # include " AirPlayServer . h " <nl> <nl> - # include < netinet / in . h > <nl> - # include < arpa / inet . h > <nl> - # include " utils / log . h " <nl> - # include " utils / StringUtils . h " <nl> - # include " threads / SingleLock . h " <nl> - # include " filesystem / File . h " <nl> - # include " filesystem / Directory . h " <nl> - # include " FileItem . h " <nl> # include " Application . h " <nl> - # include " ServiceBroker . h " <nl> - # include " messaging / ApplicationMessenger . h " <nl> + # include " CompileInfo . h " <nl> + # include " FileItem . h " <nl> # include " PlayListPlayer . h " <nl> - # include " utils / Digest . h " <nl> - # include " utils / Variant . h " <nl> - # include " settings / Settings . h " <nl> - # include " settings / SettingsComponent . h " <nl> - # include " input / Key . h " <nl> + # include " ServiceBroker . h " <nl> # include " URL . h " <nl> # include " cores / IPlayer . h " <nl> + # include " filesystem / Directory . h " <nl> + # include " filesystem / File . h " <nl> + # include " input / Key . h " <nl> # include " interfaces / AnnouncementManager . h " <nl> + # include " messaging / ApplicationMessenger . h " <nl> + # include " network / Network . h " <nl> + # include " settings / Settings . h " <nl> + # include " settings / SettingsComponent . h " <nl> + # include " threads / SingleLock . h " <nl> + # include " utils / Digest . h " <nl> + # include " utils / StringUtils . h " <nl> + # include " utils / Variant . h " <nl> + # include " utils / log . h " <nl> + <nl> + # include < arpa / inet . h > <nl> + # include < netinet / in . h > <nl> # ifdef HAS_ZEROCONF <nl> # include " network / Zeroconf . h " <nl> # endif / / HAS_ZEROCONF <nl> const char * eventStrings [ ] = { " playing " , " paused " , " loading " , " stopped " } ; <nl> # define AUTH_REALM " AirPlay " <nl> # define AUTH_REQUIRED " WWW - Authenticate : Digest realm = \ " " AUTH_REALM " \ " , nonce = \ " % s \ " \ r \ n " <nl> <nl> - void CAirPlayServer : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) <nl> + void CAirPlayServer : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) <nl> { <nl> CSingleLock lock ( ServerInstanceLock ) ; <nl> <nl> - if ( ( flag & ANNOUNCEMENT : : Player ) & & strcmp ( sender , " xbmc " ) = = 0 & & ServerInstance ) <nl> + if ( ( flag & ANNOUNCEMENT : : Player ) & & <nl> + sender = = ANNOUNCEMENT : : CAnnouncementManager : : ANNOUNCEMENT_SENDER & & ServerInstance ) <nl> { <nl> - if ( strcmp ( message , " OnStop " ) = = 0 ) <nl> + if ( message = = " OnStop " ) <nl> { <nl> bool shouldRestoreVolume = true ; <nl> if ( data . isMember ( " player " ) & & data [ " player " ] . isMember ( " playerid " ) ) <nl> void CAirPlayServer : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * s <nl> <nl> ServerInstance - > AnnounceToClients ( EVENT_STOPPED ) ; <nl> } <nl> - else if ( strcmp ( message , " OnPlay " ) = = 0 | | strcmp ( message , " OnResume " ) = = 0 ) <nl> + else if ( message = = " OnPlay " | | message = = " OnResume " ) <nl> { <nl> ServerInstance - > AnnounceToClients ( EVENT_PLAYING ) ; <nl> } <nl> - else if ( strcmp ( message , " OnPause " ) = = 0 ) <nl> + else if ( message = = " OnPause " ) <nl> { <nl> ServerInstance - > AnnounceToClients ( EVENT_PAUSED ) ; <nl> } <nl> mmm a / xbmc / network / AirPlayServer . h <nl> ppp b / xbmc / network / AirPlayServer . h <nl> class CAirPlayServer : public CThread , public ANNOUNCEMENT : : IAnnouncer <nl> { <nl> public : <nl> / / IAnnouncer IF <nl> - void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) override ; <nl> + void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) override ; <nl> <nl> / / AirPlayServer impl . <nl> static bool StartServer ( int port , bool nonlocal ) ; <nl> mmm a / xbmc / network / AirTunesServer . cpp <nl> ppp b / xbmc / network / AirTunesServer . cpp <nl> <nl> <nl> # include " AirTunesServer . h " <nl> <nl> - # include < map > <nl> - # include < string > <nl> - # include < utility > <nl> - <nl> # include " Application . h " <nl> + # include " CompileInfo . h " <nl> + # include " FileItem . h " <nl> + # include " GUIInfoManager . h " <nl> # include " ServiceBroker . h " <nl> + # include " URL . h " <nl> # include " cores / VideoPlayer / DVDDemuxers / DVDDemuxBXA . h " <nl> - # include " FileItem . h " <nl> # include " filesystem / File . h " <nl> # include " filesystem / PipeFile . h " <nl> - # include " GUIInfoManager . h " <nl> # include " guilib / GUIComponent . h " <nl> # include " guilib / GUIWindowManager . h " <nl> # include " input / Key . h " <nl> # include " interfaces / AnnouncementManager . h " <nl> # include " messaging / ApplicationMessenger . h " <nl> # include " music / tags / MusicInfoTag . h " <nl> - # include " network / dacp / dacp . h " <nl> # include " network / Network . h " <nl> # include " network / Zeroconf . h " <nl> # include " network / ZeroconfBrowser . h " <nl> + # include " network / dacp / dacp . h " <nl> + # include " settings / AdvancedSettings . h " <nl> # include " settings / Settings . h " <nl> # include " settings / SettingsComponent . h " <nl> - # include " URL . h " <nl> # include " utils / EndianSwap . h " <nl> - # include " utils / log . h " <nl> # include " utils / StringUtils . h " <nl> # include " utils / SystemInfo . h " <nl> # include " utils / Variant . h " <nl> + # include " utils / log . h " <nl> + <nl> + # include < map > <nl> + # include < string > <nl> + # include < utility > <nl> <nl> # if ! defined ( TARGET_WINDOWS ) <nl> # pragma GCC diagnostic ignored " - Wwrite - strings " <nl> void CAirTunesServer : : SetMetadataFromBuffer ( const char * buffer , unsigned int siz <nl> RefreshMetadata ( ) ; <nl> } <nl> <nl> - void CAirTunesServer : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) <nl> + void CAirTunesServer : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) <nl> { <nl> - if ( ( flag & ANNOUNCEMENT : : Player ) & & strcmp ( sender , " xbmc " ) = = 0 ) <nl> + if ( ( flag & ANNOUNCEMENT : : Player ) & & <nl> + sender = = ANNOUNCEMENT : : CAnnouncementManager : : ANNOUNCEMENT_SENDER ) <nl> { <nl> - if ( ( strcmp ( message , " OnPlay " ) = = 0 | | strcmp ( message , " OnResume " ) = = 0 ) & & m_streamStarted ) <nl> + if ( ( message = = " OnPlay " | | message = = " OnResume " ) & & m_streamStarted ) <nl> { <nl> RefreshMetadata ( ) ; <nl> RefreshCoverArt ( ) ; <nl> void CAirTunesServer : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * <nl> m_pDACP - > Play ( ) ; <nl> } <nl> <nl> - if ( strcmp ( message , " OnStop " ) = = 0 & & m_streamStarted ) <nl> + if ( message = = " OnStop " & & m_streamStarted ) <nl> { <nl> CSingleLock lock ( m_dacpLock ) ; <nl> if ( m_pDACP ) <nl> m_pDACP - > Stop ( ) ; <nl> } <nl> <nl> - if ( strcmp ( message , " OnPause " ) = = 0 & & m_streamStarted ) <nl> + if ( message = = " OnPause " & & m_streamStarted ) <nl> { <nl> CSingleLock lock ( m_dacpLock ) ; <nl> if ( m_pDACP ) <nl> mmm a / xbmc / network / AirTunesServer . h <nl> ppp b / xbmc / network / AirTunesServer . h <nl> class CAirTunesServer : public ANNOUNCEMENT : : IAnnouncer , public IActionListener , <nl> { <nl> public : <nl> / / ANNOUNCEMENT : : IAnnouncer <nl> - void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) override ; <nl> + void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) override ; <nl> <nl> void RegisterActionListener ( bool doRegister ) ; <nl> static void EnableActionProcessing ( bool enable ) ; <nl> mmm a / xbmc / network / TCPServer . cpp <nl> ppp b / xbmc / network / TCPServer . cpp <nl> int CTCPServer : : GetCapabilities ( ) <nl> return Response | Announcing ; <nl> } <nl> <nl> - void CTCPServer : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) <nl> + void CTCPServer : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) <nl> { <nl> std : : string str = IJSONRPCAnnouncer : : AnnouncementToJSONRPC ( flag , sender , message , data , CServiceBroker : : GetSettingsComponent ( ) - > GetAdvancedSettings ( ) - > m_jsonOutputCompact ) ; <nl> <nl> mmm a / xbmc / network / TCPServer . h <nl> ppp b / xbmc / network / TCPServer . h <nl> namespace JSONRPC <nl> bool Download ( const char * path , CVariant & result ) override ; <nl> int GetCapabilities ( ) override ; <nl> <nl> - void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) override ; <nl> + void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) override ; <nl> + <nl> protected : <nl> void Process ( ) override ; <nl> private : <nl> mmm a / xbmc / network / upnp / UPnPRenderer . cpp <nl> ppp b / xbmc / network / upnp / UPnPRenderer . cpp <nl> <nl> # include " utils / StringUtils . h " <nl> # include " utils / URIUtils . h " <nl> # include " utils / Variant . h " <nl> + # include " xbmc / interfaces / AnnouncementManager . h " <nl> <nl> # include < inttypes . h > <nl> <nl> CUPnPRenderer : : ProcessHttpGetRequest ( NPT_HttpRequest & request , <nl> / * mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> | CUPnPRenderer : : Announce <nl> + mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm * / <nl> - void <nl> - CUPnPRenderer : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) <nl> + void CUPnPRenderer : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) <nl> { <nl> - if ( strcmp ( sender , " xbmc " ) ! = 0 ) <nl> - return ; <nl> + if ( sender ! = ANNOUNCEMENT : : CAnnouncementManager : : ANNOUNCEMENT_SENDER ) <nl> + return ; <nl> <nl> - NPT_AutoLock lock ( m_state ) ; <nl> - PLT_Service * avt , * rct ; <nl> - <nl> - if ( flag = = ANNOUNCEMENT : : Player ) { <nl> - if ( NPT_FAILED ( FindServiceByType ( " urn : schemas - upnp - org : service : AVTransport : 1 " , avt ) ) ) <nl> - return ; <nl> - if ( strcmp ( message , " OnPlay " ) = = 0 | | strcmp ( message , " OnResume " ) = = 0 ) { <nl> - avt - > SetStateVariable ( " AVTransportURI " , g_application . CurrentFile ( ) . c_str ( ) ) ; <nl> - avt - > SetStateVariable ( " CurrentTrackURI " , g_application . CurrentFile ( ) . c_str ( ) ) ; <nl> - <nl> - NPT_String meta ; <nl> - if ( NPT_SUCCEEDED ( GetMetadata ( meta ) ) ) { <nl> - avt - > SetStateVariable ( " CurrentTrackMetadata " , meta ) ; <nl> - avt - > SetStateVariable ( " AVTransportURIMetaData " , meta ) ; <nl> - } <nl> + NPT_AutoLock lock ( m_state ) ; <nl> + PLT_Service * avt , * rct ; <nl> <nl> - avt - > SetStateVariable ( " TransportPlaySpeed " , NPT_String : : FromInteger ( data [ " player " ] [ " speed " ] . asInteger ( ) ) ) ; <nl> - avt - > SetStateVariable ( " TransportState " , " PLAYING " ) ; <nl> + if ( flag = = ANNOUNCEMENT : : Player ) <nl> + { <nl> + if ( NPT_FAILED ( FindServiceByType ( " urn : schemas - upnp - org : service : AVTransport : 1 " , avt ) ) ) <nl> + return ; <nl> <nl> - / * this could be a transition to next track , so clear next * / <nl> - avt - > SetStateVariable ( " NextAVTransportURI " , " " ) ; <nl> - avt - > SetStateVariable ( " NextAVTransportURIMetaData " , " " ) ; <nl> - } <nl> - else if ( strcmp ( message , " OnPause " ) = = 0 ) { <nl> - int64_t speed = data [ " player " ] [ " speed " ] . asInteger ( ) ; <nl> - avt - > SetStateVariable ( " TransportPlaySpeed " , NPT_String : : FromInteger ( speed ! = 0 ? speed : 1 ) ) ; <nl> - avt - > SetStateVariable ( " TransportState " , " PAUSED_PLAYBACK " ) ; <nl> - } <nl> - else if ( strcmp ( message , " OnSpeedChanged " ) = = 0 ) { <nl> - avt - > SetStateVariable ( " TransportPlaySpeed " , NPT_String : : FromInteger ( data [ " player " ] [ " speed " ] . asInteger ( ) ) ) ; <nl> - } <nl> + if ( message = = " OnPlay " | | message = = " OnResume " ) <nl> + { <nl> + avt - > SetStateVariable ( " AVTransportURI " , g_application . CurrentFile ( ) . c_str ( ) ) ; <nl> + avt - > SetStateVariable ( " CurrentTrackURI " , g_application . CurrentFile ( ) . c_str ( ) ) ; <nl> + <nl> + NPT_String meta ; <nl> + if ( NPT_SUCCEEDED ( GetMetadata ( meta ) ) ) <nl> + { <nl> + avt - > SetStateVariable ( " CurrentTrackMetadata " , meta ) ; <nl> + avt - > SetStateVariable ( " AVTransportURIMetaData " , meta ) ; <nl> + } <nl> + <nl> + avt - > SetStateVariable ( " TransportPlaySpeed " , <nl> + NPT_String : : FromInteger ( data [ " player " ] [ " speed " ] . asInteger ( ) ) ) ; <nl> + avt - > SetStateVariable ( " TransportState " , " PLAYING " ) ; <nl> + <nl> + / * this could be a transition to next track , so clear next * / <nl> + avt - > SetStateVariable ( " NextAVTransportURI " , " " ) ; <nl> + avt - > SetStateVariable ( " NextAVTransportURIMetaData " , " " ) ; <nl> + } <nl> + else if ( message = = " OnPause " ) <nl> + { <nl> + int64_t speed = data [ " player " ] [ " speed " ] . asInteger ( ) ; <nl> + avt - > SetStateVariable ( " TransportPlaySpeed " , NPT_String : : FromInteger ( speed ! = 0 ? speed : 1 ) ) ; <nl> + avt - > SetStateVariable ( " TransportState " , " PAUSED_PLAYBACK " ) ; <nl> } <nl> - else if ( flag = = ANNOUNCEMENT : : Application & & strcmp ( message , " OnVolumeChanged " ) = = 0 ) { <nl> - if ( NPT_FAILED ( FindServiceByType ( " urn : schemas - upnp - org : service : RenderingControl : 1 " , rct ) ) ) <nl> - return ; <nl> + else if ( message = = " OnSpeedChanged " ) <nl> + { <nl> + avt - > SetStateVariable ( " TransportPlaySpeed " , <nl> + NPT_String : : FromInteger ( data [ " player " ] [ " speed " ] . asInteger ( ) ) ) ; <nl> + } <nl> + } <nl> + else if ( flag = = ANNOUNCEMENT : : Application & & message = = " OnVolumeChanged " ) <nl> + { <nl> + if ( NPT_FAILED ( FindServiceByType ( " urn : schemas - upnp - org : service : RenderingControl : 1 " , rct ) ) ) <nl> + return ; <nl> <nl> - std : : string buffer ; <nl> + std : : string buffer ; <nl> <nl> - buffer = StringUtils : : Format ( " % " PRId64 , data [ " volume " ] . asInteger ( ) ) ; <nl> - rct - > SetStateVariable ( " Volume " , buffer . c_str ( ) ) ; <nl> + buffer = StringUtils : : Format ( " % " PRId64 , data [ " volume " ] . asInteger ( ) ) ; <nl> + rct - > SetStateVariable ( " Volume " , buffer . c_str ( ) ) ; <nl> <nl> - buffer = StringUtils : : Format ( " % " PRId64 , 256 * ( data [ " volume " ] . asInteger ( ) * 60 - 60 ) / 100 ) ; <nl> - rct - > SetStateVariable ( " VolumeDb " , buffer . c_str ( ) ) ; <nl> + buffer = StringUtils : : Format ( " % " PRId64 , 256 * ( data [ " volume " ] . asInteger ( ) * 60 - 60 ) / 100 ) ; <nl> + rct - > SetStateVariable ( " VolumeDb " , buffer . c_str ( ) ) ; <nl> <nl> - rct - > SetStateVariable ( " Mute " , data [ " muted " ] . asBoolean ( ) ? " 1 " : " 0 " ) ; <nl> - } <nl> + rct - > SetStateVariable ( " Mute " , data [ " muted " ] . asBoolean ( ) ? " 1 " : " 0 " ) ; <nl> + } <nl> } <nl> <nl> / * mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> mmm a / xbmc / network / upnp / UPnPRenderer . h <nl> ppp b / xbmc / network / upnp / UPnPRenderer . h <nl> class CUPnPRenderer : public PLT_MediaRenderer <nl> <nl> ~ CUPnPRenderer ( ) override ; <nl> <nl> - void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) override ; <nl> + void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) override ; <nl> void UpdateState ( ) ; <nl> <nl> / / Http server handler <nl> mmm a / xbmc / network / upnp / UPnPServer . cpp <nl> ppp b / xbmc / network / upnp / UPnPServer . cpp <nl> <nl> # include " video / VideoDatabase . h " <nl> # include " video / VideoThumbLoader . h " <nl> # include " view / GUIViewState . h " <nl> + # include " xbmc / interfaces / AnnouncementManager . h " <nl> <nl> # include < Platinum / Source / Platinum / Platinum . h > <nl> <nl> CUPnPServer : : Build ( CFileItemPtr item , <nl> / * mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> | CUPnPServer : : Announce <nl> + mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm * / <nl> - void <nl> - CUPnPServer : : Announce ( AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) <nl> + void CUPnPServer : : Announce ( AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) <nl> { <nl> NPT_String path ; <nl> int item_id ; <nl> std : : string item_type ; <nl> <nl> - if ( strcmp ( sender , " xbmc " ) ) <nl> - return ; <nl> + if ( sender ! = CAnnouncementManager : : ANNOUNCEMENT_SENDER ) <nl> + return ; <nl> <nl> - if ( strcmp ( message , " OnUpdate " ) & & strcmp ( message , " OnRemove " ) <nl> - & & strcmp ( message , " OnScanStarted " ) & & strcmp ( message , " OnScanFinished " ) ) <nl> - return ; <nl> + if ( message ! = " OnUpdate " & & message ! = " OnRemove " & & message ! = " OnScanStarted " & & <nl> + message ! = " OnScanFinished " ) <nl> + return ; <nl> <nl> if ( data . isNull ( ) ) { <nl> - if ( ! strcmp ( message , " OnScanStarted " ) | | ! strcmp ( message , " OnCleanStarted " ) ) { <nl> - m_scanning = true ; <nl> + if ( message = = " OnScanStarted " | | message = = " OnCleanStarted " ) <nl> + { <nl> + m_scanning = true ; <nl> } <nl> - else if ( ! strcmp ( message , " OnScanFinished " ) | | ! strcmp ( message , " OnCleanFinished " ) ) { <nl> - OnScanCompleted ( flag ) ; <nl> + else if ( message = = " OnScanFinished " | | message = = " OnCleanFinished " ) <nl> + { <nl> + OnScanCompleted ( flag ) ; <nl> } <nl> } <nl> else { <nl> CUPnPServer : : OnUpdateObject ( PLT_ActionReference & action , <nl> CVariant data ; <nl> data [ " id " ] = updated . GetVideoInfoTag ( ) - > m_iDbId ; <nl> data [ " type " ] = updated . GetVideoInfoTag ( ) - > m_type ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " xbmc " , " OnUpdate " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , <nl> + " OnUpdate " , data ) ; <nl> } <nl> updatelisting = true ; <nl> } <nl> mmm a / xbmc / network / upnp / UPnPServer . h <nl> ppp b / xbmc / network / upnp / UPnPServer . h <nl> class CUPnPServer : public PLT_MediaConnect , <nl> public : <nl> CUPnPServer ( const char * friendly_name , const char * uuid = NULL , int port = 0 ) ; <nl> ~ CUPnPServer ( ) override ; <nl> - void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) override ; <nl> + void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) override ; <nl> <nl> / / PLT_MediaServer methods <nl> NPT_Result OnBrowseMetadata ( PLT_ActionReference & action , <nl> mmm a / xbmc / peripherals / Peripherals . cpp <nl> ppp b / xbmc / peripherals / Peripherals . cpp <nl> <nl> <nl> # include " Peripherals . h " <nl> <nl> + # include " CompileInfo . h " <nl> # include " EventScanner . h " <nl> # include " addons / AddonButtonMap . h " <nl> # include " addons / AddonManager . h " <nl> int CPeripherals : : GetMessageMask ( ) <nl> } <nl> <nl> void CPeripherals : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> - const char * sender , <nl> - const char * message , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> const CVariant & data ) <nl> { <nl> - if ( flag = = ANNOUNCEMENT : : Player & & strcmp ( sender , " xbmc " ) = = 0 ) <nl> + if ( flag = = ANNOUNCEMENT : : Player & & <nl> + sender = = ANNOUNCEMENT : : CAnnouncementManager : : ANNOUNCEMENT_SENDER ) <nl> { <nl> - if ( strcmp ( message , " OnQuit " ) = = 0 ) <nl> + if ( message = = " OnQuit " ) <nl> { <nl> if ( CServiceBroker : : GetSettingsComponent ( ) - > GetSettings ( ) - > GetBool ( <nl> CSettings : : SETTING_INPUT_CONTROLLERPOWEROFF ) ) <nl> mmm a / xbmc / peripherals / Peripherals . h <nl> ppp b / xbmc / peripherals / Peripherals . h <nl> class CPeripherals : public ISettingCallback , <nl> <nl> / / implementation of IAnnouncer <nl> void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> - const char * sender , <nl> - const char * message , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> const CVariant & data ) override ; <nl> <nl> / * ! <nl> mmm a / xbmc / peripherals / devices / PeripheralCecAdapter . cpp <nl> ppp b / xbmc / peripherals / devices / PeripheralCecAdapter . cpp <nl> <nl> # include " utils / JobManager . h " <nl> # include " utils / Variant . h " <nl> # include " utils / log . h " <nl> + # include " xbmc / interfaces / AnnouncementManager . h " <nl> <nl> # include < libcec / cec . h > <nl> <nl> using namespace KODI ; <nl> using namespace MESSAGING ; <nl> using namespace PERIPHERALS ; <nl> using namespace CEC ; <nl> + using namespace ANNOUNCEMENT ; <nl> <nl> # define CEC_LIB_SUPPORTED_VERSION LIBCEC_VERSION_TO_UINT ( 4 , 0 , 0 ) <nl> <nl> void CPeripheralCecAdapter : : ResetMembers ( void ) <nl> } <nl> <nl> void CPeripheralCecAdapter : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> - const char * sender , <nl> - const char * message , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> const CVariant & data ) <nl> { <nl> - if ( flag = = ANNOUNCEMENT : : System & & ! strcmp ( sender , " xbmc " ) & & ! strcmp ( message , " OnQuit " ) & & <nl> - m_bIsReady ) <nl> + if ( flag = = ANNOUNCEMENT : : System & & sender = = CAnnouncementManager : : ANNOUNCEMENT_SENDER & & <nl> + message = = " OnQuit " & & m_bIsReady ) <nl> { <nl> CSingleLock lock ( m_critSection ) ; <nl> m_iExitCode = static_cast < int > ( data [ " exitcode " ] . asInteger ( EXITCODE_QUIT ) ) ; <nl> CServiceBroker : : GetAnnouncementManager ( ) - > RemoveAnnouncer ( this ) ; <nl> StopThread ( false ) ; <nl> } <nl> - else if ( flag = = ANNOUNCEMENT : : GUI & & ! strcmp ( sender , " xbmc " ) & & <nl> - ! strcmp ( message , " OnScreensaverDeactivated " ) & & m_bIsReady ) <nl> + else if ( flag = = ANNOUNCEMENT : : GUI & & sender = = CAnnouncementManager : : ANNOUNCEMENT_SENDER & & <nl> + message = = " OnScreensaverDeactivated " & & m_bIsReady ) <nl> { <nl> bool bIgnoreDeactivate ( false ) ; <nl> if ( data [ " shuttingdown " ] . isBoolean ( ) ) <nl> void CPeripheralCecAdapter : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> ActivateSource ( ) ; <nl> } <nl> } <nl> - else if ( flag = = ANNOUNCEMENT : : GUI & & ! strcmp ( sender , " xbmc " ) & & <nl> - ! strcmp ( message , " OnScreensaverActivated " ) & & m_bIsReady ) <nl> + else if ( flag = = ANNOUNCEMENT : : GUI & & sender = = CAnnouncementManager : : ANNOUNCEMENT_SENDER & & <nl> + message = = " OnScreensaverActivated " & & m_bIsReady ) <nl> { <nl> / / Don ' t put devices to standby if application is currently playing <nl> if ( ! g_application . GetAppPlayer ( ) . IsPlaying ( ) & & m_bPowerOffScreensaver ) <nl> void CPeripheralCecAdapter : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> StandbyDevices ( ) ; <nl> } <nl> } <nl> - else if ( flag = = ANNOUNCEMENT : : System & & ! strcmp ( sender , " xbmc " ) & & ! strcmp ( message , " OnSleep " ) ) <nl> + else if ( flag = = ANNOUNCEMENT : : System & & sender = = CAnnouncementManager : : ANNOUNCEMENT_SENDER & & <nl> + message = = " OnSleep " ) <nl> { <nl> / / this will also power off devices when we ' re the active source <nl> { <nl> void CPeripheralCecAdapter : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> } <nl> StopThread ( ) ; <nl> } <nl> - else if ( flag = = ANNOUNCEMENT : : System & & ! strcmp ( sender , " xbmc " ) & & ! strcmp ( message , " OnWake " ) ) <nl> + else if ( flag = = ANNOUNCEMENT : : System & & sender = = CAnnouncementManager : : ANNOUNCEMENT_SENDER & & <nl> + message = = " OnWake " ) <nl> { <nl> CLog : : Log ( LOGDEBUG , " % s - reconnecting to the CEC adapter after standby mode " , __FUNCTION__ ) ; <nl> if ( ReopenConnection ( ) ) <nl> void CPeripheralCecAdapter : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> ActivateSource ( ) ; <nl> } <nl> } <nl> - else if ( flag = = ANNOUNCEMENT : : Player & & ! strcmp ( sender , " xbmc " ) & & ! strcmp ( message , " OnStop " ) ) <nl> + else if ( flag = = ANNOUNCEMENT : : Player & & sender = = CAnnouncementManager : : ANNOUNCEMENT_SENDER & & <nl> + message = = " OnStop " ) <nl> { <nl> CSingleLock lock ( m_critSection ) ; <nl> m_preventActivateSourceOnPlay = CDateTime : : GetCurrentDateTime ( ) ; <nl> m_bOnPlayReceived = false ; <nl> } <nl> - else if ( flag = = ANNOUNCEMENT : : Player & & ! strcmp ( sender , " xbmc " ) & & <nl> - ( ! strcmp ( message , " OnPlay " ) | | ! strcmp ( message , " OnResume " ) ) ) <nl> + else if ( flag = = ANNOUNCEMENT : : Player & & sender = = CAnnouncementManager : : ANNOUNCEMENT_SENDER & & <nl> + ( message = = " OnPlay " | | message = = " OnResume " ) ) <nl> { <nl> / / activate the source when playback started , and the option is enabled <nl> bool bActivateSource ( false ) ; <nl> mmm a / xbmc / peripherals / devices / PeripheralCecAdapter . h <nl> ppp b / xbmc / peripherals / devices / PeripheralCecAdapter . h <nl> class CPeripheralCecAdapter : public CPeripheralHID , <nl> CPeripheralBus * bus ) ; <nl> ~ CPeripheralCecAdapter ( void ) override ; <nl> <nl> - void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> - const char * sender , <nl> - const char * message , <nl> - const CVariant & data ) override ; <nl> + void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const std : : string & sender , const std : : string & message , const CVariant & data ) override ; <nl> <nl> / / audio control <nl> bool HasAudioControl ( void ) ; <nl> mmm a / xbmc / pictures / GUIWindowPictures . cpp <nl> ppp b / xbmc / pictures / GUIWindowPictures . cpp <nl> <nl> # include " utils / XTimeUtils . h " <nl> # include " utils / log . h " <nl> # include " view / GUIViewState . h " <nl> - <nl> - # define CONTROL_BTNVIEWASICONS 2 <nl> - # define CONTROL_BTNSORTBY 3 <nl> # define CONTROL_BTNSORTASC 4 <nl> # define CONTROL_LABELFILES 12 <nl> <nl> bool CGUIWindowPictures : : ShowPicture ( int iItem , bool startSlideShow ) <nl> CVariant param ; <nl> param [ " player " ] [ " speed " ] = 1 ; <nl> param [ " player " ] [ " playerid " ] = PLAYLIST_PICTURE ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnPlay " , pSlideShow - > GetCurrentSlide ( ) , param ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnPlay " , <nl> + pSlideShow - > GetCurrentSlide ( ) , param ) ; <nl> } <nl> <nl> m_slideShowStarted = true ; <nl> mmm a / xbmc / pictures / GUIWindowSlideShow . cpp <nl> ppp b / xbmc / pictures / GUIWindowSlideShow . cpp <nl> void CGUIWindowSlideShow : : AnnouncePlayerPlay ( const CFileItemPtr & item ) <nl> CVariant param ; <nl> param [ " player " ] [ " speed " ] = m_bSlideShow & & ! m_bPause ? 1 : 0 ; <nl> param [ " player " ] [ " playerid " ] = PLAYLIST_PICTURE ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnPlay " , item , param ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnPlay " , item , param ) ; <nl> } <nl> <nl> void CGUIWindowSlideShow : : AnnouncePlayerPause ( const CFileItemPtr & item ) <nl> void CGUIWindowSlideShow : : AnnouncePlayerPause ( const CFileItemPtr & item ) <nl> CVariant param ; <nl> param [ " player " ] [ " speed " ] = 0 ; <nl> param [ " player " ] [ " playerid " ] = PLAYLIST_PICTURE ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnPause " , item , param ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnPause " , item , param ) ; <nl> } <nl> <nl> void CGUIWindowSlideShow : : AnnouncePlayerStop ( const CFileItemPtr & item ) <nl> void CGUIWindowSlideShow : : AnnouncePlayerStop ( const CFileItemPtr & item ) <nl> CVariant param ; <nl> param [ " player " ] [ " playerid " ] = PLAYLIST_PICTURE ; <nl> param [ " end " ] = true ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnStop " , item , param ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnStop " , item , param ) ; <nl> } <nl> <nl> void CGUIWindowSlideShow : : AnnouncePlaylistClear ( ) <nl> { <nl> CVariant data ; <nl> data [ " playlistid " ] = PLAYLIST_PICTURE ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Playlist , " xbmc " , " OnClear " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Playlist , " OnClear " , data ) ; <nl> } <nl> <nl> void CGUIWindowSlideShow : : AnnouncePlaylistAdd ( const CFileItemPtr & item , int pos ) <nl> void CGUIWindowSlideShow : : AnnouncePlaylistAdd ( const CFileItemPtr & item , int pos ) <nl> CVariant data ; <nl> data [ " playlistid " ] = PLAYLIST_PICTURE ; <nl> data [ " position " ] = pos ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Playlist , " xbmc " , " OnAdd " , item , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Playlist , " OnAdd " , item , data ) ; <nl> } <nl> <nl> void CGUIWindowSlideShow : : AnnouncePropertyChanged ( const std : : string & strProperty , const CVariant & value ) <nl> void CGUIWindowSlideShow : : AnnouncePropertyChanged ( const std : : string & strProperty <nl> CVariant data ; <nl> data [ " player " ] [ " playerid " ] = PLAYLIST_PICTURE ; <nl> data [ " property " ] [ strProperty ] = value ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnPropertyChanged " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnPropertyChanged " , <nl> + data ) ; <nl> } <nl> <nl> bool CGUIWindowSlideShow : : IsPlaying ( ) const <nl> void CGUIWindowSlideShow : : RunSlideShow ( const std : : string & strPath , <nl> CVariant param ; <nl> param [ " player " ] [ " speed " ] = 0 ; <nl> param [ " player " ] [ " playerid " ] = PLAYLIST_PICTURE ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " xbmc " , " OnPlay " , GetCurrentSlide ( ) , param ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Player , " OnPlay " , <nl> + GetCurrentSlide ( ) , param ) ; <nl> } <nl> <nl> CServiceBroker : : GetGUI ( ) - > GetWindowManager ( ) . ActivateWindow ( WINDOW_SLIDESHOW ) ; <nl> mmm a / xbmc / platform / android / activity / XBMCApp . cpp <nl> ppp b / xbmc / platform / android / activity / XBMCApp . cpp <nl> CXBMCApp : : ~ CXBMCApp ( ) <nl> delete m_wakeLock ; <nl> } <nl> <nl> - void CXBMCApp : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) <nl> + void CXBMCApp : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) <nl> { <nl> - if ( strcmp ( sender , " xbmc " ) ! = 0 ) <nl> + if ( sender ! = CAnnouncementManager : : ANNOUNCEMENT_SENDER ) <nl> return ; <nl> <nl> if ( flag & Input ) <nl> { <nl> - if ( strcmp ( message , " OnInputRequested " ) = = 0 ) <nl> + if ( message = = " OnInputRequested " ) <nl> CAndroidKey : : SetHandleSearchKeys ( true ) ; <nl> - else if ( strcmp ( message , " OnInputFinished " ) = = 0 ) <nl> + else if ( message = = " OnInputFinished " ) <nl> CAndroidKey : : SetHandleSearchKeys ( false ) ; <nl> } <nl> else if ( flag & Player ) <nl> { <nl> - if ( strcmp ( message , " OnPlay " ) = = 0 | | strcmp ( message , " OnResume " ) = = 0 ) <nl> + if ( message = = " OnPlay " | | message = = " OnResume " ) <nl> OnPlayBackStarted ( ) ; <nl> - else if ( strcmp ( message , " OnPause " ) = = 0 ) <nl> + else if ( message = = " OnPause " ) <nl> OnPlayBackPaused ( ) ; <nl> - else if ( strcmp ( message , " OnStop " ) = = 0 ) <nl> + else if ( message = = " OnStop " ) <nl> OnPlayBackStopped ( ) ; <nl> - else if ( strcmp ( message , " OnSeek " ) = = 0 ) <nl> + else if ( message = = " OnSeek " ) <nl> UpdateSessionState ( ) ; <nl> - else if ( strcmp ( message , " OnSpeedChanged " ) = = 0 ) <nl> + else if ( message = = " OnSpeedChanged " ) <nl> UpdateSessionState ( ) ; <nl> } <nl> else if ( flag & Info ) <nl> { <nl> - if ( strcmp ( message , " OnChanged " ) = = 0 ) <nl> + if ( message = = " OnChanged " ) <nl> UpdateSessionMetadata ( ) ; <nl> } <nl> } <nl> mmm a / xbmc / platform / android / activity / XBMCApp . h <nl> ppp b / xbmc / platform / android / activity / XBMCApp . h <nl> class CXBMCApp <nl> static CXBMCApp * get ( ) { return m_xbmcappinstance ; } <nl> <nl> / / IAnnouncer IF <nl> - void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) override ; <nl> + void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) override ; <nl> <nl> void onReceive ( CJNIIntent intent ) override ; <nl> void onNewIntent ( CJNIIntent intent ) override ; <nl> mmm a / xbmc / platform / darwin / ios - common / AnnounceReceiver . h <nl> ppp b / xbmc / platform / darwin / ios - common / AnnounceReceiver . h <nl> class CAnnounceReceiver : public ANNOUNCEMENT : : IAnnouncer <nl> void DeInitialize ( ) ; <nl> <nl> void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> - const char * sender , <nl> - const char * message , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> const CVariant & data ) override ; <nl> <nl> private : <nl> mmm a / xbmc / platform / darwin / ios - common / AnnounceReceiver . mm <nl> ppp b / xbmc / platform / darwin / ios - common / AnnounceReceiver . mm <nl> id objectFromVariant ( const CVariant & data ) <nl> } <nl> <nl> void AnnounceBridge ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> - const char * sender , <nl> - const char * message , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> const CVariant & data ) <nl> { <nl> int item_id = - 1 ; <nl> void AnnounceBridge ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> } <nl> <nl> void CAnnounceReceiver : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> - const char * sender , <nl> - const char * message , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> const CVariant & data ) <nl> { <nl> / / can be called from c + + , we need an auto poll here . <nl> mmm a / xbmc / playlists / PlayList . cpp <nl> ppp b / xbmc / playlists / PlayList . cpp <nl> void CPlayList : : AnnounceRemove ( int pos ) <nl> CVariant data ; <nl> data [ " playlistid " ] = m_id ; <nl> data [ " position " ] = pos ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Playlist , " xbmc " , " OnRemove " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Playlist , " OnRemove " , data ) ; <nl> } <nl> <nl> void CPlayList : : AnnounceClear ( ) <nl> void CPlayList : : AnnounceClear ( ) <nl> <nl> CVariant data ; <nl> data [ " playlistid " ] = m_id ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Playlist , " xbmc " , " OnClear " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Playlist , " OnClear " , data ) ; <nl> } <nl> <nl> void CPlayList : : AnnounceAdd ( const CFileItemPtr & item , int pos ) <nl> void CPlayList : : AnnounceAdd ( const CFileItemPtr & item , int pos ) <nl> CVariant data ; <nl> data [ " playlistid " ] = m_id ; <nl> data [ " position " ] = pos ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Playlist , " xbmc " , " OnAdd " , item , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : Playlist , " OnAdd " , item , data ) ; <nl> } <nl> <nl> void CPlayList : : Add ( const CFileItemPtr & item , int iPosition , int iOrder ) <nl> mmm a / xbmc / powermanagement / PowerManager . cpp <nl> ppp b / xbmc / powermanagement / PowerManager . cpp <nl> bool CPowerManager : : Reboot ( ) <nl> <nl> if ( success ) <nl> { <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : System , " xbmc " , " OnRestart " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : System , " OnRestart " ) ; <nl> <nl> CGUIDialogBusy * dialog = CServiceBroker : : GetGUI ( ) - > GetWindowManager ( ) . GetWindow < CGUIDialogBusy > ( WINDOW_DIALOG_BUSY ) ; <nl> if ( dialog ) <nl> void CPowerManager : : ProcessEvents ( ) <nl> <nl> void CPowerManager : : OnSleep ( ) <nl> { <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : System , " xbmc " , " OnSleep " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : System , " OnSleep " ) ; <nl> <nl> CGUIDialogBusy * dialog = CServiceBroker : : GetGUI ( ) - > GetWindowManager ( ) . GetWindow < CGUIDialogBusy > ( WINDOW_DIALOG_BUSY ) ; <nl> if ( dialog ) <nl> void CPowerManager : : OnWake ( ) <nl> CServiceBroker : : GetPVRManager ( ) . OnWake ( ) ; <nl> RestorePlayerState ( ) ; <nl> <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : System , " xbmc " , " OnWake " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : System , " OnWake " ) ; <nl> } <nl> <nl> void CPowerManager : : OnLowBattery ( ) <nl> void CPowerManager : : OnLowBattery ( ) <nl> <nl> CGUIDialogKaiToast : : QueueNotification ( CGUIDialogKaiToast : : Warning , g_localizeStrings . Get ( 13050 ) , " " ) ; <nl> <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : System , " xbmc " , " OnLowBattery " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : System , " OnLowBattery " ) ; <nl> } <nl> <nl> void CPowerManager : : StorePlayerState ( ) <nl> mmm a / xbmc / pvr / PVRManager . cpp <nl> ppp b / xbmc / pvr / PVRManager . cpp <nl> CPVRManager : : ~ CPVRManager ( ) <nl> CLog : : LogFC ( LOGDEBUG , LOGPVR , " PVR Manager instance destroyed " ) ; <nl> } <nl> <nl> - void CPVRManager : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) <nl> + void CPVRManager : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) <nl> { <nl> if ( ! IsStarted ( ) ) <nl> return ; <nl> <nl> if ( ( flag & ( ANNOUNCEMENT : : GUI ) ) ) <nl> { <nl> - if ( strcmp ( message , " OnScreensaverActivated " ) = = 0 ) <nl> + if ( message = = " OnScreensaverActivated " ) <nl> m_addons - > OnPowerSavingActivated ( ) ; <nl> - else if ( strcmp ( message , " OnScreensaverDeactivated " ) = = 0 ) <nl> + else if ( message = = " OnScreensaverDeactivated " ) <nl> m_addons - > OnPowerSavingDeactivated ( ) ; <nl> } <nl> } <nl> mmm a / xbmc / pvr / PVRManager . h <nl> ppp b / xbmc / pvr / PVRManager . h <nl> namespace PVR <nl> * / <nl> ~ CPVRManager ( ) override ; <nl> <nl> - void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) override ; <nl> + void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) override ; <nl> <nl> / * ! <nl> * @ brief Get the channel groups container . <nl> mmm a / xbmc / settings / MediaSettings . cpp <nl> ppp b / xbmc / settings / MediaSettings . cpp <nl> void CMediaSettings : : OnSettingChanged ( std : : shared_ptr < const CSetting > setting ) <nl> return ; <nl> <nl> if ( setting - > GetId ( ) = = CSettings : : SETTING_VIDEOLIBRARY_SHOWUNWATCHEDPLOTS ) <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " xbmc " , " OnRefresh " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " OnRefresh " ) ; <nl> } <nl> <nl> int CMediaSettings : : GetWatchedMode ( const std : : string & content ) const <nl> mmm a / xbmc / utils / SaveFileStateJob . cpp <nl> ppp b / xbmc / utils / SaveFileStateJob . cpp <nl> void CSaveFileState : : DoWork ( CFileItem & item , <nl> CVariant data ; <nl> data [ " id " ] = item . GetVideoInfoTag ( ) - > m_iDbId ; <nl> data [ " type " ] = item . GetVideoInfoTag ( ) - > m_type ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " xbmc " , " OnUpdate " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , <nl> + " OnUpdate " , data ) ; <nl> } <nl> } <nl> } <nl> void CSaveFileState : : DoWork ( CFileItem & item , <nl> CVariant data ; <nl> data [ " id " ] = item . GetVideoInfoTag ( ) - > m_iDbId ; <nl> data [ " type " ] = item . GetVideoInfoTag ( ) - > m_type ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " xbmc " , " OnUpdate " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , <nl> + " OnUpdate " , data ) ; <nl> } <nl> <nl> updateListing = true ; <nl> void CSaveFileState : : DoWork ( CFileItem & item , <nl> CVariant data ; <nl> data [ " id " ] = item . GetMusicInfoTag ( ) - > GetDatabaseId ( ) ; <nl> data [ " type " ] = item . GetMusicInfoTag ( ) - > GetType ( ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , " xbmc " , " OnUpdate " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : AudioLibrary , <nl> + " OnUpdate " , data ) ; <nl> } <nl> } <nl> } <nl> mmm a / xbmc / video / VideoDatabase . cpp <nl> ppp b / xbmc / video / VideoDatabase . cpp <nl> void CVideoDatabase : : SetPlayCount ( const CFileItem & item , int count , const CDateT <nl> / / Only provide the " playcount " value if it has actually changed <nl> if ( item . GetVideoInfoTag ( ) - > GetPlayCount ( ) ! = count ) <nl> data [ " playcount " ] = count ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " xbmc " , " OnUpdate " , CFileItemPtr ( new CFileItem ( item ) ) , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " OnUpdate " , <nl> + CFileItemPtr ( new CFileItem ( item ) ) , data ) ; <nl> } <nl> } <nl> catch ( . . . ) <nl> void CVideoDatabase : : CleanDatabase ( CGUIDialogProgressBarHandle * handle , const st <nl> <nl> unsigned int time = XbmcThreads : : SystemClockMillis ( ) ; <nl> CLog : : Log ( LOGINFO , " % s : Starting videodatabase cleanup . . " , __FUNCTION__ ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " xbmc " , " OnCleanStarted " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , <nl> + " OnCleanStarted " ) ; <nl> <nl> BeginTransaction ( ) ; <nl> <nl> void CVideoDatabase : : CleanDatabase ( CGUIDialogProgressBarHandle * handle , const st <nl> { <nl> progress - > Close ( ) ; <nl> m_pDS2 - > close ( ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " xbmc " , " OnCleanFinished " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , <nl> + " OnCleanFinished " ) ; <nl> return ; <nl> } <nl> } <nl> void CVideoDatabase : : CleanDatabase ( CGUIDialogProgressBarHandle * handle , const st <nl> if ( progress ) <nl> progress - > Close ( ) ; <nl> <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " xbmc " , " OnCleanFinished " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " OnCleanFinished " ) ; <nl> } <nl> <nl> std : : vector < int > CVideoDatabase : : CleanMediaType ( const std : : string & mediaType , const std : : string & cleanableFileIDs , <nl> void CVideoDatabase : : ExportToXML ( const std : : string & path , bool singleFile / * = t <nl> if ( iFailCount > 0 ) <nl> data [ " failcount " ] = iFailCount ; <nl> } <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " xbmc " , " OnExport " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " OnExport " , <nl> + data ) ; <nl> } <nl> catch ( . . . ) <nl> { <nl> void CVideoDatabase : : AnnounceRemove ( std : : string content , int id , bool scanning / <nl> data [ " id " ] = id ; <nl> if ( scanning ) <nl> data [ " transaction " ] = true ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " xbmc " , " OnRemove " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " OnRemove " , data ) ; <nl> } <nl> <nl> void CVideoDatabase : : AnnounceUpdate ( std : : string content , int id ) <nl> void CVideoDatabase : : AnnounceUpdate ( std : : string content , int id ) <nl> CVariant data ; <nl> data [ " type " ] = content ; <nl> data [ " id " ] = id ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " xbmc " , " OnUpdate " , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " OnUpdate " , data ) ; <nl> } <nl> <nl> bool CVideoDatabase : : GetItemsForPath ( const std : : string & content , const std : : string & strPath , CFileItemList & items ) <nl> mmm a / xbmc / video / VideoInfoScanner . cpp <nl> ppp b / xbmc / video / VideoInfoScanner . cpp <nl> namespace VIDEO <nl> m_bCanInterrupt = true ; <nl> <nl> CLog : : Log ( LOGINFO , " VideoInfoScanner : Starting scan . . " ) ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " xbmc " , " OnScanStarted " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , <nl> + " OnScanStarted " ) ; <nl> <nl> / / Database operations should not be canceled <nl> / / using Interrupt ( ) while scanning as it could <nl> namespace VIDEO <nl> } <nl> <nl> m_bRunning = false ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " xbmc " , " OnScanFinished " ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , <nl> + " OnScanFinished " ) ; <nl> <nl> if ( m_handle ) <nl> m_handle - > MarkFinished ( ) ; <nl> namespace VIDEO <nl> data [ " added " ] = true ; <nl> if ( m_bRunning ) <nl> data [ " transaction " ] = true ; <nl> - CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " xbmc " , " OnUpdate " , itemCopy , data ) ; <nl> + CServiceBroker : : GetAnnouncementManager ( ) - > Announce ( ANNOUNCEMENT : : VideoLibrary , " OnUpdate " , <nl> + itemCopy , data ) ; <nl> return lResult ; <nl> } <nl> <nl> mmm a / xbmc / windowing / win10 / WinEventsWin10 . cpp <nl> ppp b / xbmc / windowing / win10 / WinEventsWin10 . cpp <nl> void CWinEventsWin10 : : OnSystemMediaButtonPressed ( const SystemMediaTransportContr <nl> } <nl> } <nl> <nl> - void CWinEventsWin10 : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) <nl> + void CWinEventsWin10 : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) <nl> { <nl> if ( flag & ANNOUNCEMENT : : Player ) <nl> { <nl> void CWinEventsWin10 : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * <nl> bool changed = false ; <nl> MediaPlaybackStatus status = MediaPlaybackStatus : : Changing ; <nl> <nl> - if ( strcmp ( message , " OnPlay " ) = = 0 | | strcmp ( message , " OnResume " ) = = 0 ) <nl> + if ( message = = " OnPlay " | | message = = " OnResume " ) <nl> { <nl> changed = true ; <nl> status = MediaPlaybackStatus : : Playing ; <nl> } <nl> - else if ( strcmp ( message , " OnStop " ) = = 0 ) <nl> + else if ( message = = " OnStop " ) <nl> { <nl> changed = true ; <nl> status = MediaPlaybackStatus : : Stopped ; <nl> } <nl> - else if ( strcmp ( message , " OnPause " ) = = 0 ) <nl> + else if ( message = = " OnPause " ) <nl> { <nl> changed = true ; <nl> status = MediaPlaybackStatus : : Paused ; <nl> } <nl> - else if ( strcmp ( message , " OnSpeedChanged " ) = = 0 ) <nl> + else if ( message = = " OnSpeedChanged " ) <nl> { <nl> changed = true ; <nl> status = speed ! = 0 . 0 ? MediaPlaybackStatus : : Playing : MediaPlaybackStatus : : Paused ; <nl> mmm a / xbmc / windowing / win10 / WinEventsWin10 . h <nl> ppp b / xbmc / windowing / win10 / WinEventsWin10 . h <nl> class CWinEventsWin10 : public IWinEvents <nl> static void OnSystemMediaButtonPressed ( const winrt : : Windows : : Media : : SystemMediaTransportControls & <nl> , const winrt : : Windows : : Media : : SystemMediaTransportControlsButtonPressedEventArgs & ) ; <nl> / / IAnnouncer overrides <nl> - void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) override ; <nl> + void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) override ; <nl> <nl> private : <nl> friend class CWinSystemWin10 ; <nl> mmm a / xbmc / windows / GUIWindowHome . cpp <nl> ppp b / xbmc / windows / GUIWindowHome . cpp <nl> void CGUIWindowHome : : OnInitWindow ( ) <nl> CGUIWindow : : OnInitWindow ( ) ; <nl> } <nl> <nl> - void CGUIWindowHome : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) <nl> + void CGUIWindowHome : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) <nl> { <nl> int ra_flag = 0 ; <nl> <nl> void CGUIWindowHome : : Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * s <nl> if ( data . isMember ( " transaction " ) & & data [ " transaction " ] . asBoolean ( ) ) <nl> return ; <nl> <nl> - if ( strcmp ( message , " OnScanStarted " ) = = 0 | | <nl> - strcmp ( message , " OnCleanStarted " ) = = 0 ) <nl> + if ( message = = " OnScanStarted " | | message = = " OnCleanStarted " ) <nl> return ; <nl> <nl> - bool onUpdate = strcmp ( message , " OnUpdate " ) = = 0 ; <nl> + bool onUpdate = message = = " OnUpdate " ; <nl> / / always update Totals except on an OnUpdate with no playcount update <nl> if ( ! onUpdate | | data . isMember ( " playcount " ) ) <nl> ra_flag | = Totals ; <nl> mmm a / xbmc / windows / GUIWindowHome . h <nl> ppp b / xbmc / windows / GUIWindowHome . h <nl> class CGUIWindowHome : <nl> CGUIWindowHome ( void ) ; <nl> ~ CGUIWindowHome ( void ) override ; <nl> void OnInitWindow ( ) override ; <nl> - void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , const char * sender , const char * message , const CVariant & data ) override ; <nl> + void Announce ( ANNOUNCEMENT : : AnnouncementFlag flag , <nl> + const std : : string & sender , <nl> + const std : : string & message , <nl> + const CVariant & data ) override ; <nl> <nl> bool OnMessage ( CGUIMessage & message ) override ; <nl> bool OnAction ( const CAction & action ) override ; <nl>
Merge pull request from a1rwulf / announcements
xbmc/xbmc
9655b4ffc45ad57f2511ac33309a786aa75c4de8
2020-10-12T08:53:11Z
mmm a / test / unittest / prettywritertest . cpp <nl> ppp b / test / unittest / prettywritertest . cpp <nl> TEST ( PrettyWriter , RawValue ) { <nl> } <nl> <nl> # if RAPIDJSON_HAS_CXX11_RVALUE_REFS <nl> + <nl> + static PrettyWriter < StringBuffer > WriterGen ( StringBuffer & target ) { <nl> + PrettyWriter < StringBuffer > writer ( target ) ; <nl> + writer . StartObject ( ) ; <nl> + writer . Key ( " a " ) ; <nl> + writer . Int ( 1 ) ; <nl> + return std : : move ( writer ) ; <nl> + } <nl> + <nl> TEST ( PrettyWriter , MoveCtor ) { <nl> StringBuffer buffer ; <nl> - auto writerGen = [ ] ( StringBuffer & target ) - > PrettyWriter < StringBuffer > { <nl> - PrettyWriter < StringBuffer > writer ( target ) ; <nl> - writer . StartObject ( ) ; <nl> - writer . Key ( " a " ) ; <nl> - writer . Int ( 1 ) ; <nl> - return std : : move ( writer ) ; <nl> - } ; <nl> - <nl> - PrettyWriter < StringBuffer > writer ( writerGen ( buffer ) ) ; <nl> + PrettyWriter < StringBuffer > writer ( WriterGen ( buffer ) ) ; <nl> writer . EndObject ( ) ; <nl> EXPECT_TRUE ( writer . IsComplete ( ) ) ; <nl> EXPECT_STREQ ( <nl> mmm a / test / unittest / writertest . cpp <nl> ppp b / test / unittest / writertest . cpp <nl> TEST ( Writer , RawValue ) { <nl> } <nl> <nl> # if RAPIDJSON_HAS_CXX11_RVALUE_REFS <nl> + static Writer < StringBuffer > WriterGen ( StringBuffer & target ) { <nl> + Writer < StringBuffer > writer ( target ) ; <nl> + writer . StartObject ( ) ; <nl> + writer . Key ( " a " ) ; <nl> + writer . Int ( 1 ) ; <nl> + return std : : move ( writer ) ; <nl> + } <nl> + <nl> TEST ( Writer , MoveCtor ) { <nl> StringBuffer buffer ; <nl> - auto writerGen = [ ] ( StringBuffer & target ) - > Writer < StringBuffer > { <nl> - Writer < StringBuffer > writer ( target ) ; <nl> - writer . StartObject ( ) ; <nl> - writer . Key ( " a " ) ; <nl> - writer . Int ( 1 ) ; <nl> - return std : : move ( writer ) ; <nl> - } ; <nl> - <nl> - Writer < StringBuffer > writer ( writerGen ( buffer ) ) ; <nl> + Writer < StringBuffer > writer ( WriterGen ( buffer ) ) ; <nl> writer . EndObject ( ) ; <nl> EXPECT_TRUE ( writer . IsComplete ( ) ) ; <nl> EXPECT_STREQ ( " { \ " a \ " : 1 } " , buffer . GetString ( ) ) ; <nl>
Remove lambda expression in ( pretty ) writertest
Tencent/rapidjson
0761ac126b1aa2144a26c26dfde1c08073eda43a
2016-09-21T13:49:49Z
mmm a / AUTHORS <nl> ppp b / AUTHORS <nl> Paul Lind < plind44 @ gmail . com > <nl> Qingyan Li < qingyan . liqy @ alibaba - inc . com > <nl> Qiuyi Zhang < qiuyi . zqy @ alibaba - inc . com > <nl> Rafal Krypa < rafal @ krypa . net > <nl> + Ray Glover < ray @ rayglover . net > <nl> Refael Ackermann < refack @ gmail . com > <nl> Rene Rebe < rene @ exactcode . de > <nl> Rick Waldron < waldron . rick @ gmail . com > <nl> mmm a / src / flags . cc <nl> ppp b / src / flags . cc <nl> void FlagList : : PrintHelp ( ) { <nl> CpuFeatures : : PrintFeatures ( ) ; <nl> <nl> OFStream os ( stdout ) ; <nl> - os < < " Usage : \ n " <nl> - " shell [ options ] - e string \ n " <nl> - " execute string in V8 \ n " <nl> - " shell [ options ] file1 file2 . . . filek \ n " <nl> - " run JavaScript scripts in file1 , file2 , . . . , filek \ n " <nl> - " shell [ options ] \ n " <nl> - " shell [ options ] - - shell [ file1 file2 . . . filek ] \ n " <nl> - " run an interactive JavaScript shell \ n " <nl> - " d8 [ options ] file1 file2 . . . filek \ n " <nl> - " d8 [ options ] \ n " <nl> - " d8 [ options ] - - shell [ file1 file2 . . . filek ] \ n " <nl> - " run the new debugging shell \ n \ n " <nl> + os < < " Synopsis : \ n " <nl> + " shell [ options ] [ - - shell ] [ < file > . . . ] \ n " <nl> + " d8 [ options ] [ - e < string > ] [ - - shell ] [ [ - - module ] < file > . . . ] \ n \ n " <nl> + " - e execute a string in V8 \ n " <nl> + " - - shell run an interactive JavaScript shell \ n " <nl> + " - - module execute a file as a JavaScript module \ n \ n " <nl> " Options : \ n " ; <nl> <nl> for ( const Flag & f : flags ) { <nl>
Document - - module option for d8
v8/v8
d22b125a0cf9ae3808e89b44670e6f6ee697e0bf
2018-05-16T07:35:46Z
mmm a / cmake / scripts / common / Macros . cmake <nl> ppp b / cmake / scripts / common / Macros . cmake <nl> endfunction ( ) <nl> # APP_NAME_UC - uppercased app name <nl> # APP_PACKAGE - Android full package name <nl> # COMPANY_NAME - company name <nl> + # APP_WEBSITE - site url <nl> # APP_VERSION_MAJOR - the app version major <nl> # APP_VERSION_MINOR - the app version minor <nl> # APP_VERSION_TAG - the app version tag <nl> macro ( core_find_versions ) <nl> core_file_read_filtered ( version_list $ { CORE_SOURCE_DIR } / version . txt ) <nl> core_file_read_filtered ( json_version $ { CORE_SOURCE_DIR } / xbmc / interfaces / json - rpc / schema / version . txt ) <nl> string ( REGEX REPLACE " ( [ ^ ; ] * ) ( [ ^ ; ] * ) " " \ \ 1 ; \ \ 2 " version_list " $ { version_list } ; $ { json_version } " ) <nl> - set ( version_props <nl> + set ( version_props <nl> ADDON_API <nl> APP_NAME <nl> APP_PACKAGE <nl> macro ( core_find_versions ) <nl> # unset variables not used anywhere else <nl> unset ( version_list ) <nl> unset ( APP_APP_NAME ) <nl> + unset ( APP_COMPANY_NAME ) <nl> + unset ( APP_APP_PACKAGE ) <nl> + unset ( APP_JSONRPC_VERSION ) <nl> unset ( BIN_ADDON_PARTS ) <nl> <nl> # bail if we can ' t parse version . txt <nl> mmm a / tools / windows / packaging / uwp / package . appxmanifest . in <nl> ppp b / tools / windows / packaging / uwp / package . appxmanifest . in <nl> <nl> <nl> < Properties > <nl> < DisplayName > @ APP_NAME @ < / DisplayName > <nl> - < PublisherDisplayName > @ APP_COMPANY_NAME @ < / PublisherDisplayName > <nl> + < PublisherDisplayName > @ COMPANY_NAME @ < / PublisherDisplayName > <nl> < Description > @ APP_PACKAGE_DESCRIPTION @ < / Description > <nl> < Logo > media \ icon50x50 . png < / Logo > <nl> < / Properties > <nl> <nl> < uap : Capability Name = " videosLibrary " / > <nl> < uap3 : Capability Name = " backgroundMediaPlayback " / > <nl> < / Capabilities > <nl> - < / Package > <nl> \ No newline at end of file <nl> + < / Package > <nl>
Merge pull request from hudokkow / app_mirrors
xbmc/xbmc
c49d783988a6c1c3adaabfe1425f42e85d3a5ef1
2018-05-24T07:33:29Z
new file mode 100755 <nl> index 000000000000 . . 82bfe21e22e3 <nl> mmm / dev / null <nl> ppp b / utils / analyze_code_size . py <nl> <nl> + # ! / usr / bin / env python <nl> + <nl> + import argparse <nl> + import re <nl> + import subprocess <nl> + import sys <nl> + <nl> + <nl> + def main ( arguments ) : <nl> + parser = argparse . ArgumentParser ( <nl> + description = ' Analyze the code size in a binary ' ) <nl> + parser . add_argument ( ' - arch ' , type = str , <nl> + help = ' the arch to look at ' , default = ' arm64 ' ) <nl> + parser . add_argument ( ' - categorize ' , action = ' store_true ' , <nl> + help = ' categorize symbols ' , dest = ' build_categories ' , <nl> + default = False ) <nl> + parser . add_argument ( ' - list - category ' , type = str , <nl> + help = ' list symbols in category ' ) <nl> + parser . add_argument ( ' - uncategorized ' , action = ' store_true ' , <nl> + help = ' show all uncategorized symbols ' , <nl> + dest = ' show_uncategorized ' , <nl> + default = False ) <nl> + parser . add_argument ( ' bin ' , help = ' the binary ' ) <nl> + <nl> + args = parser . parse_args ( arguments ) <nl> + <nl> + segments = parse_segments ( args . bin , args . arch ) <nl> + <nl> + if args . build_categories : <nl> + categorize ( segments ) <nl> + elif args . show_uncategorized : <nl> + uncategorized ( segments ) <nl> + elif args . list_category : <nl> + list_category ( segments , args . list_category ) <nl> + else : <nl> + show_all ( segments ) <nl> + <nl> + <nl> + class Symbol ( object ) : <nl> + def __init__ ( self , name , mangled_name , size ) : <nl> + self . name = name <nl> + self . mangled_name = mangled_name <nl> + self . count = 1 <nl> + self . size = int ( size ) <nl> + <nl> + <nl> + def get_symbol_size ( sym ) : <nl> + return sym . size <nl> + <nl> + <nl> + class Segment ( object ) : <nl> + def __init__ ( self , name ) : <nl> + self . name = name <nl> + self . sections = [ ] <nl> + <nl> + <nl> + class Section ( object ) : <nl> + def __init__ ( self , name , size ) : <nl> + self . name = name <nl> + self . size = size <nl> + self . symbols = [ ] <nl> + <nl> + <nl> + class Category ( object ) : <nl> + def __init__ ( self , name ) : <nl> + self . name = name <nl> + self . size = 0 <nl> + self . symbols = [ ] <nl> + <nl> + def add ( self , symbol ) : <nl> + self . symbols . append ( symbol ) <nl> + self . size + = symbol . size <nl> + <nl> + <nl> + class Categories ( object ) : <nl> + def __init__ ( self ) : <nl> + self . category_matching = [ <nl> + [ ' Objective - C function ' , re . compile ( r ' . * [ + - ] \ [ ' ) ] , <nl> + [ ' C + + ' , re . compile ( r ' _ + swift ' ) ] , <nl> + [ ' Merged function ' , re . compile ( r ' merged ' ) ] , <nl> + [ ' Key path ' , re . compile ( r ' key path ' ) ] , <nl> + [ ' Function signature specialization ' , <nl> + re . compile ( r ' function signature specialization ' ) ] , <nl> + [ ' Generic specialization ' , re . compile ( r ' generic specialization ' ) ] , <nl> + [ ' Reabstraction thunk helper ' , <nl> + re . compile ( r ' reabstraction thunk helper ' ) ] , <nl> + [ ' vtable thunk ' , re . compile ( r ' vtable thunk for ' ) ] , <nl> + [ ' @ objc thunk ' , re . compile ( r ' @ objc ' ) ] , <nl> + [ ' @ nonobjc thunk ' , re . compile ( r ' @ nonobjc ' ) ] , <nl> + [ ' Value witness ' , re . compile ( r ' . * value witness for ' ) ] , <nl> + [ ' Block copy helper ' , re . compile ( r ' _block_copy_helper ' ) ] , <nl> + [ ' Block destroy helper ' , re . compile ( r ' _block_destroy_helper ' ) ] , <nl> + [ ' Block literal global ' , re . compile ( r ' ___block_literal_global ' ) ] , <nl> + [ ' Destroy helper block ' , re . compile ( r ' ___destroy_helper_block ' ) ] , <nl> + [ ' Copy helper block ' , re . compile ( r ' ___copy_helper_block ' ) ] , <nl> + [ ' Object destroy ' , re . compile ( r ' _objectdestroy ' ) ] , <nl> + [ ' Partial apply forwarder ' , <nl> + re . compile ( r ' partial apply forwarder ' ) ] , <nl> + [ ' Closure function ' , re . compile ( r ' closure # ' ) ] , <nl> + [ ' ObjC metadata update function ' , <nl> + re . compile ( r ' ObjC metadata update function for ' ) ] , <nl> + [ ' Variable initialization expression ' , <nl> + re . compile ( r ' variable initialization expression of ' ) ] , <nl> + [ ' Global initialization ' , re . compile ( r ' _globalinit_ ' ) ] , <nl> + [ ' Unnamed ' , re . compile ( r ' ___unnamed_ ' ) ] , <nl> + [ ' Dyld stubs ' , re . compile ( r ' DYLD - STUB \ $ ' ) ] , <nl> + [ ' Witness table accessor ' , <nl> + re . compile ( r ' . * witness table accessor for ' ) ] , <nl> + [ ' Protocol witness ' , re . compile ( r ' protocol witness for ' ) ] , <nl> + [ ' Outlined variable ' , re . compile ( r ' outlined variable # ' ) ] , <nl> + [ ' Outlined value function ( copy , destroy , release . . . ) ' , <nl> + re . compile ( r ' outlined ' ) ] , <nl> + [ ' _symbolic ' , re . compile ( r ' _symbolic ' ) ] , <nl> + [ ' _associated conformance ' , <nl> + re . compile ( r ' _associated conformance ' ) ] , <nl> + [ ' Direct field offset ' , re . compile ( r ' direct field offset for ' ) ] , <nl> + [ ' Value witness tables ' , re . compile ( r ' . * value witness table ' ) ] , <nl> + [ ' Protocol witness table ' , <nl> + re . compile ( r ' . * protocol witness table for ' ) ] , <nl> + [ ' Protocol conformance descriptor ' , <nl> + re . compile ( r ' protocol conformance descriptor for ' ) ] , <nl> + [ ' Lazy protocol witness table cache var ' , <nl> + re . compile ( <nl> + r ' lazy protocol witness table cache variable for type ' ) ] , <nl> + [ ' Nominal type descriptor ' , <nl> + re . compile ( r ' nominal type descriptor for ' ) ] , <nl> + [ ' ObjC class ' , re . compile ( r ' _OBJC_CLASS_ ' ) ] , <nl> + [ ' ObjC metaclass ' , re . compile ( r ' _OBJC_METACLASS ' ) ] , <nl> + [ ' ObjC ivar ' , re . compile ( r ' _OBJC_IVAR ' ) ] , <nl> + [ ' Metaclass ' , re . compile ( r ' metaclass for ' ) ] , <nl> + [ ' Block descriptor ' , re . compile ( r ' _ + block_descriptor ' ) ] , <nl> + [ ' Extension descriptor ' , re . compile ( r ' extension descriptor ' ) ] , <nl> + [ ' Module descriptor ' , re . compile ( r ' module descriptor ' ) ] , <nl> + [ ' Associated type descriptor ' , <nl> + re . compile ( r ' associated type descriptor for ' ) ] , <nl> + [ ' Associated conformance descriptor ' , <nl> + re . compile ( r ' associated conformance descriptor for ' ) ] , <nl> + [ ' Protocol descriptor ' , re . compile ( r ' protocol descriptor for ' ) ] , <nl> + [ ' Base conformance descriptor ' , <nl> + re . compile ( r ' base conformance descriptor for ' ) ] , <nl> + [ ' Protocol requirements base descriptor ' , <nl> + re . compile ( r ' protocol requirements base descriptor for ' ) ] , <nl> + [ ' Property descriptor ' , re . compile ( r ' property descriptor for ' ) ] , <nl> + [ ' Method descriptor ' , re . compile ( r ' method descriptor for ' ) ] , <nl> + [ ' Anonymous descriptor ' , re . compile ( r ' anonymous descriptor ' ) ] , <nl> + [ ' Type metadata accessor ' , <nl> + re . compile ( r ' . * type metadata accessor ' ) ] , <nl> + [ ' Type metadata ' , re . compile ( r ' . * type metadata ' ) ] , <nl> + [ ' Reflection metadata descriptor ' , <nl> + re . compile ( r ' reflection metadata . * descriptor ' ) ] , <nl> + ] <nl> + <nl> + self . category_mangled_matching = [ <nl> + [ ' Swift variable storage ' , re . compile ( r ' ^ _ \ $ s . * [ v ] [ p ] [ Z ] ? $ ' ) ] , <nl> + [ ' Swift constructor ' , re . compile ( r ' ^ _ \ $ s . * [ f ] [ cC ] $ ' ) ] , <nl> + [ ' Swift initializer ' , re . compile ( r ' ^ _ \ $ s . * [ f ] [ ie ] $ ' ) ] , <nl> + [ ' Swift destructor / destroyer ' , re . compile ( r ' ^ _ \ $ s . * [ f ] [ dDE ] $ ' ) ] , <nl> + [ ' Swift getter ' , re . compile ( r ' ^ _ \ $ s . * [ iv ] [ gG ] $ ' ) ] , <nl> + [ ' Swift setter ' , re . compile ( r ' ^ _ \ $ s . * [ iv ] [ swW ] $ ' ) ] , <nl> + [ ' Swift materializeForSet ' , re . compile ( r ' ^ _ \ $ s . * [ iv ] [ m ] $ ' ) ] , <nl> + [ ' Swift modify ' , re . compile ( r ' ^ _ \ $ s . * [ iv ] [ M ] $ ' ) ] , <nl> + [ ' Swift read ' , re . compile ( r ' ^ _ \ $ s . * [ iv ] [ r ] $ ' ) ] , <nl> + [ ' Swift addressor ' , re . compile ( r ' ^ _ \ $ s . * [ iv ] [ al ] [ uOop ] $ ' ) ] , <nl> + [ ' Swift function ' , re . compile ( r ' ^ _ \ $ s . * F $ ' ) ] , <nl> + [ ' Swift unknown ' , re . compile ( r ' ^ _ \ $ s . * ' ) ] , <nl> + ] <nl> + self . categories = { } <nl> + <nl> + def categorize_by_name ( self , symbol ) : <nl> + for c in self . category_matching : <nl> + if c [ 1 ] . match ( symbol . name ) : <nl> + return c [ 0 ] <nl> + return None <nl> + <nl> + def categorize_by_mangled_name ( self , symbol ) : <nl> + for c in self . category_mangled_matching : <nl> + if c [ 1 ] . match ( symbol . mangled_name ) : <nl> + return c [ 0 ] <nl> + return None <nl> + <nl> + def add_symbol ( self , category_name , symbol ) : <nl> + existing_category = self . categories . get ( category_name ) <nl> + if existing_category : <nl> + existing_category . add ( symbol ) <nl> + else : <nl> + new_category = Category ( category_name ) <nl> + new_category . add ( symbol ) <nl> + self . categories [ category_name ] = new_category <nl> + <nl> + def add ( self , symbol ) : <nl> + category_name = self . categorize_by_name ( symbol ) <nl> + if category_name : <nl> + self . add_symbol ( category_name , symbol ) <nl> + return <nl> + category_name = self . categorize_by_mangled_name ( symbol ) <nl> + if category_name : <nl> + self . add_symbol ( category_name , symbol ) <nl> + else : <nl> + self . add_symbol ( ' Unknown ' , symbol ) <nl> + <nl> + def categorize ( self , symbols ) : <nl> + for sym in symbols : <nl> + self . add ( sym ) <nl> + <nl> + def print_summary ( self , section_size ) : <nl> + names = [ c [ 0 ] for c in self . category_matching ] <nl> + names . extend ( [ c [ 0 ] for c in self . category_mangled_matching ] ) <nl> + names . append ( ' Unknown ' ) <nl> + total_size = 0 <nl> + for name in names : <nl> + category = self . categories . get ( name ) <nl> + size = 0 <nl> + if category : <nl> + size = category . size <nl> + total_size + = size <nl> + if size > 0 : <nl> + print ( " % 60s : % 8d ( % 6 . 2f % % ) " % <nl> + ( name , size , ( float ( size ) * 100 ) / section_size ) ) <nl> + print ( " % 60s : % 8d ( % 6 . 2f % % ) " % ( ' TOTAL ' , total_size , float ( 100 ) ) ) <nl> + <nl> + def uncatorizedSymbols ( self ) : <nl> + category = self . categories . get ( ' Unknown ' ) <nl> + if category : <nl> + return category . symbols <nl> + return None <nl> + <nl> + def print_uncategorizedSymbols ( self ) : <nl> + syms = self . uncatorizedSymbols ( ) <nl> + if syms : <nl> + for symbol in syms : <nl> + print ( symbol . mangled_name + " " + symbol . name + " " + <nl> + str ( symbol . size ) ) <nl> + <nl> + def print_category ( self , category ) : <nl> + category = self . categories . get ( category ) <nl> + if category : <nl> + if category . symbols : <nl> + sorted_symbols = sorted ( category . symbols , key = get_symbol_size ) <nl> + for sym in sorted_symbols : <nl> + print ( ' % 8d % s % s ' % ( sym . size , sym . name , sym . mangled_name ) ) <nl> + <nl> + def has_category ( self , category ) : <nl> + category = self . categories . get ( category ) <nl> + if category : <nl> + if category . symbols : <nl> + return True <nl> + return False <nl> + <nl> + <nl> + def parse_segments ( path , arch ) : <nl> + mangled = subprocess . check_output ( <nl> + [ ' symbols ' , ' - noSources ' , ' - noDemangling ' , ' - arch ' , arch , path ] ) <nl> + demangle = subprocess . Popen ( <nl> + [ ' xcrun ' , ' swift - demangle ' ] , stdin = subprocess . PIPE , <nl> + stdout = subprocess . PIPE ) <nl> + demangled = demangle . communicate ( mangled ) [ 0 ] <nl> + symbols = { } <nl> + segments = [ ] <nl> + segment_regex = re . compile ( <nl> + r " ^ 0x [ 0 - 9a - f ] + \ ( \ s * 0x ( ? P < size > [ 0 - 9a - f ] + ) \ ) " <nl> + r " ( ? P < name > . + ? ) ( ? P < name2 > . + ? ) $ " ) <nl> + section_regex = re . compile ( <nl> + r " ^ 0x [ 0 - 9a - f ] + \ ( \ s * 0x ( ? P < size > [ 0 - 9a - f ] + ) \ ) " <nl> + r " ( ? P < name > . + ? ) ( ? P < name2 > . + ? ) $ " ) <nl> + symbol_regex = re . compile ( <nl> + r " ^ 0x [ 0 - 9a - f ] + \ ( \ s * 0x ( ? P < size > [ 0 - 9a - f ] + ) \ ) " <nl> + r " ( ? P < name > . + ? ) \ [ [ ^ \ ] ] + \ ] $ " ) <nl> + <nl> + mangled_lines = mangled . splitlines ( ) <nl> + current_line_number = 0 <nl> + <nl> + for line in demangled . splitlines ( ) : <nl> + mangled_line = mangled_lines [ current_line_number ] <nl> + current_line_number + = 1 <nl> + <nl> + # Match a segment entry . <nl> + segment_match = segment_regex . match ( line ) <nl> + if segment_match : <nl> + new_segment = Segment ( segment_match . group ( ' name ' ) ) <nl> + segments . append ( new_segment ) <nl> + continue <nl> + <nl> + # Match a section entry . <nl> + section_match = section_regex . match ( line ) <nl> + if section_match : <nl> + new_section = Section ( section_match . group ( ' name2 ' ) , <nl> + int ( section_match . group ( ' size ' ) , 16 ) ) <nl> + segments [ - 1 ] . sections . append ( new_section ) <nl> + continue <nl> + <nl> + # Match a symbol entry . <nl> + symbol_match = symbol_regex . match ( line ) <nl> + if not symbol_match : <nl> + continue <nl> + mangled_symbol_match = symbol_regex . match ( mangled_line ) <nl> + if not mangled_symbol_match : <nl> + print ( ' mangled and demangled mismatch ' ) <nl> + print ( mangled_line ) <nl> + print ( line ) <nl> + assert False <nl> + <nl> + symbol = Symbol ( symbol_match . group ( ' name ' ) , <nl> + mangled_symbol_match . group ( ' name ' ) , <nl> + int ( symbol_match . group ( ' size ' ) , 16 ) ) <nl> + existing = symbols . get ( symbol . name ) <nl> + if existing : <nl> + existing . size + = symbol . size <nl> + else : <nl> + symbols [ symbol . name ] = symbol <nl> + segments [ - 1 ] . sections [ - 1 ] . symbols . append ( symbol ) <nl> + <nl> + return segments <nl> + <nl> + <nl> + def show_all ( segments ) : <nl> + for segment in segments : <nl> + for section in segment . sections : <nl> + symbols = section . symbols <nl> + for sym in symbols : <nl> + print ( str ( sym . size ) + ' ' + sym . name + ' ' + sym . mangled_name ) <nl> + <nl> + <nl> + def categorize ( segments ) : <nl> + for segment in segments : <nl> + for section in segment . sections : <nl> + print ( ' Section % 52s : % 8d ' % <nl> + ( segment . name + ' ; ' + section . name , section . size ) ) <nl> + symbols = section . symbols <nl> + categories = Categories ( ) <nl> + categories . categorize ( symbols ) <nl> + categories . print_summary ( section . size ) <nl> + print ( ' ' ) <nl> + <nl> + <nl> + def uncategorized ( segments ) : <nl> + for segment in segments : <nl> + for section in segment . sections : <nl> + symbols = section . symbols <nl> + categories = Categories ( ) <nl> + categories . categorize ( symbols ) <nl> + categories . print_uncategorizedSymbols ( ) <nl> + <nl> + <nl> + def list_category ( segments , category ) : <nl> + for segment in segments : <nl> + for section in segment . sections : <nl> + symbols = section . symbols <nl> + categories = Categories ( ) <nl> + categories . categorize ( symbols ) <nl> + if categories . has_category ( category ) : <nl> + print ( ' Section % 22s : % 8d ' % <nl> + ( segment . name + ' ; ' + section . name , section . size ) ) <nl> + categories . print_category ( category ) <nl> + <nl> + <nl> + if __name__ = = ' __main__ ' : <nl> + sys . exit ( main ( sys . argv [ 1 : ] ) ) <nl>
Merge remote - tracking branch ' origin / master ' into master - next
apple/swift
f9133d60bcbf004b25497a71e7fde42475e8110c
2019-02-11T15:09:26Z
mmm a / python / examples / simulation / mgpcg_smoke_3d . py <nl> ppp b / python / examples / simulation / mgpcg_smoke_3d . py <nl> <nl> + import cv2 <nl> + <nl> + from taichi . core import tc_core <nl> from taichi . dynamics . smoke3 import Smoke3 <nl> + from taichi . misc . util import * <nl> + from taichi . visual . camera import Camera <nl> + from taichi . visual . particle_renderer import ParticleRenderer <nl> <nl> if __name__ = = ' __main__ ' : <nl> resolution = [ 64 ] * 3 <nl> resolution [ 1 ] * = 2 <nl> + <nl> + particle_renderer = ParticleRenderer ( ' shadow_map ' , <nl> + shadow_map_resolution = 0 . 5 , alpha = 0 . 6 , shadowing = 0 . 07 , ambient_light = 0 . 3 , <nl> + light_direction = ( 1 , 3 , 1 ) ) <nl> + <nl> smoke = Smoke3 ( resolution = tuple ( resolution ) , <nl> - simulation_depth = resolution [ 2 ] , delta_x = 1 . 0 / resolution [ 0 ] , gravity = ( 0 , - 10 ) , <nl> + simulation_depth = resolution [ 2 ] , delta_x = 1 . 0 / resolution [ 0 ] , gravity = ( 0 , 0 , 0 ) , <nl> advection_order = 1 , cfl = 0 . 5 , smoke_alpha = 80 . 0 , smoke_beta = 800 , <nl> - temperature_decay = 0 . 05 , pressure_tolerance = 1e - 4 , density_scaling = 2 , initial_speed = ( 0 , 0 , 0 ) , <nl> - tracker_generation = 20 , perturbation = 0 , pressure_solver = ' mgpcg ' , num_threads = 8 ) <nl> + temperature_decay = 0 . 05 , pressure_tolerance = 1e - 6 , density_scaling = 2 , initial_speed = ( 0 , 0 , 0 ) , <nl> + tracker_generation = 20 , perturbation = 0 , pressure_solver = ' mgpcg ' , num_threads = 2 , open_boundary = True ) <nl> + <nl> + <nl> for i in range ( 600 ) : <nl> smoke . step ( 0 . 03 ) <nl> - <nl> + particles = smoke . c . get_render_particles ( ) <nl> + width , height = 512 , 1024 <nl> + image_buffer = tc_core . RGBImageFloat ( width , height , Vector ( 0 , 0 , 0 . 0 ) ) <nl> + radius = resolution [ 0 ] * 4 <nl> + camera = Camera ( ' pinhole ' , origin = ( 0 , radius * 0 . 3 , radius ) , <nl> + look_at = ( 0 , 0 , 0 ) , up = ( 0 , 1 , 0 ) , fov = 70 , <nl> + width = width , height = height ) <nl> + particle_renderer . set_camera ( camera ) <nl> + particle_renderer . render ( image_buffer , particles ) <nl> + img = image_buffer_to_ndarray ( image_buffer ) <nl> + cv2 . imshow ( ' Vis ' , img ) <nl> + cv2 . waitKey ( 1 ) <nl> <nl> <nl> deleted file mode 100644 <nl> index 24640628add . . 00000000000 <nl> mmm a / python / examples / simulation / mgpcg_smoke_3d_boundary . py <nl> ppp / dev / null <nl> <nl> - import cv2 <nl> - <nl> - from taichi . core import tc_core <nl> - from taichi . dynamics . smoke3 import Smoke3 <nl> - from taichi . misc . util import * <nl> - from taichi . visual . camera import Camera <nl> - from taichi . visual . particle_renderer import ParticleRenderer <nl> - <nl> - if __name__ = = ' __main__ ' : <nl> - resolution = [ 64 ] * 3 <nl> - resolution [ 1 ] * = 2 <nl> - <nl> - particle_renderer = ParticleRenderer ( ' shadow_map ' , <nl> - shadow_map_resolution = 0 . 5 , alpha = 0 . 6 , shadowing = 0 . 07 , ambient_light = 0 . 3 , <nl> - light_direction = ( 1 , 3 , 1 ) ) <nl> - <nl> - smoke = Smoke3 ( resolution = tuple ( resolution ) , <nl> - simulation_depth = resolution [ 2 ] , delta_x = 1 . 0 / resolution [ 0 ] , gravity = ( 0 , 0 , 0 ) , <nl> - advection_order = 1 , cfl = 0 . 5 , smoke_alpha = 80 . 0 , smoke_beta = 800 , <nl> - temperature_decay = 0 . 05 , pressure_tolerance = 1e - 6 , density_scaling = 2 , initial_speed = ( 0 , 0 , 0 ) , <nl> - tracker_generation = 20 , perturbation = 0 , pressure_solver = ' mgpcg ' , num_threads = 2 , open_boundary = True ) <nl> - <nl> - <nl> - for i in range ( 600 ) : <nl> - smoke . step ( 0 . 03 ) <nl> - particles = smoke . c . get_render_particles ( ) <nl> - width , height = 512 , 1024 <nl> - image_buffer = tc_core . RGBImageFloat ( width , height , Vector ( 0 , 0 , 0 . 0 ) ) <nl> - radius = resolution [ 0 ] * 4 <nl> - camera = Camera ( ' pinhole ' , origin = ( 0 , radius * 0 . 3 , radius ) , <nl> - look_at = ( 0 , 0 , 0 ) , up = ( 0 , 1 , 0 ) , fov = 70 , <nl> - width = width , height = height ) <nl> - particle_renderer . set_camera ( camera ) <nl> - particle_renderer . render ( image_buffer , particles ) <nl> - img = image_buffer_to_ndarray ( image_buffer ) <nl> - cv2 . imshow ( ' Vis ' , img ) <nl> - cv2 . waitKey ( 1 ) <nl> - <nl> - <nl> mmm a / python / taichi / core / __init__ . py <nl> ppp b / python / taichi / core / __init__ . py <nl> <nl> from load_core import tc_core <nl> from unit import unit <nl> <nl> + # TODO : ' tc_core ' should be changed to ' core ' . . . <nl> + <nl> __all__ = [ <nl> + ' tc_core ' , <nl> ' core ' , <nl> ' unit ' <nl> ] <nl> mmm a / python / taichi / core / load_core . py <nl> ppp b / python / taichi / core / load_core . py <nl> <nl> sys . path . append ( " . " ) <nl> import taichi_core as tc_core <nl> elif get_os_name ( ) = = ' win ' : <nl> - bin_dir = os . environ [ ' TAICHI_BIN_DIR ' ] + ' / ' <nl> + bin_dir = get_bin_directory ( ) + ' / ' <nl> dll_path = bin_dir + ' / Release / taichi_core . dll ' <nl> <nl> # The problem here is , on windows , when an dll / pyd is loaded , we can not write to it any more . . . <nl> mmm a / python / taichi / dynamics / mpm . py <nl> ppp b / python / taichi / dynamics / mpm . py <nl> class MPM3 : <nl> def __init__ ( self , * * kwargs ) : <nl> self . c = tc_core . create_simulation3d ( ' mpm ' ) <nl> self . c . initialize ( P ( * * kwargs ) ) <nl> - self . directory = tc . get_root_directory ( ) + ' / ' + get_uuid ( ) + ' / ' <nl> + self . directory = tc . get_output_path ( get_unique_task_id ( ) ) <nl> self . video_manager = VideoManager ( self . directory , 960 , 540 ) <nl> try : <nl> os . mkdir ( self . directory ) <nl> def step ( self , step_t ) : <nl> print ' Time : ' , time . time ( ) - T <nl> image_buffer = tc_core . RGBImageFloat ( self . video_manager . width , self . video_manager . height , Vector ( 0 , 0 , 0 . 0 ) ) <nl> particles = self . c . get_render_particles ( ) <nl> - particles . write ( self . directory + ' particles % 05d . bin ' % self . frame ) <nl> + particles . write ( self . directory + ' / particles % 05d . bin ' % self . frame ) <nl> res = map ( float , self . resolution ) <nl> radius = res [ 0 ] * 2 . 5 <nl> theta = 0 <nl> mmm a / python / taichi / dynamics / nbody . py <nl> ppp b / python / taichi / dynamics / nbody . py <nl> <nl> <nl> import cv2 <nl> <nl> + import taichi <nl> from taichi . core import tc_core <nl> from taichi . misc . util import * <nl> from taichi . tools . video import VideoManager <nl> class NBody : <nl> def __init__ ( self , * * kwargs ) : <nl> self . c = tc_core . create_simulation3d ( ' nbody ' ) <nl> self . c . initialize ( P ( * * kwargs ) ) <nl> - self . directory = ' . . / output / frames / ' + get_uuid ( ) + ' / ' <nl> + self . directory = taichi . get_output_path ( get_unique_task_id ( ) ) <nl> try : <nl> os . mkdir ( self . directory ) <nl> except Exception as e : <nl> print e <nl> self . video_manager = VideoManager ( self . directory , 512 , 512 ) <nl> self . particle_renderer = ParticleRenderer ( ' shadow_map ' , <nl> - shadow_map_resolution = 0 . 01 , alpha = 0 . 12 , shadowing = 0 . 1 , ambient_light = 0 . 3 , <nl> + shadow_map_resolution = 0 . 01 , alpha = 0 . 12 , shadowing = 0 . 1 , <nl> + ambient_light = 0 . 3 , <nl> light_direction = ( 1 , 3 , - 3 ) ) <nl> self . step_counter = 0 <nl> <nl> + def get_output_path ( self , path ) : <nl> + return ' / ' . join ( [ self . directory , path ] ) <nl> + <nl> def step ( self , step_t ) : <nl> t = self . c . get_current_time ( ) <nl> print ' Simulation time : ' , t <nl> def step ( self , step_t ) : <nl> print ' Time : ' , time . time ( ) - T <nl> image_buffer = tc_core . RGBImageFloat ( self . video_manager . width , self . video_manager . height , Vector ( 0 , 0 , 0 . 0 ) ) <nl> particles = self . c . get_render_particles ( ) <nl> - particles . write ( self . directory + ' particles % 05d . bin ' % self . step_counter ) <nl> + particles . write ( self . get_output_path ( ' particles % 05d . bin ' % self . step_counter ) ) <nl> camera = Camera ( ' pinhole ' , origin = ( 0 , 0 , 50 ) , <nl> look_at = ( 0 , 0 , 0 ) , up = ( 0 , 1 , 0 ) , fov = 70 , <nl> width = self . video_manager . width , height = self . video_manager . height ) <nl> self . particle_renderer . set_camera ( camera ) <nl> self . particle_renderer . render ( image_buffer , particles ) <nl> img = image_buffer_to_ndarray ( image_buffer ) <nl> - # img = LDRDisplay ( exposure = 1 , adaptive_exposure = False ) . process ( img ) <nl> + # img = LDRDisplay ( exposure = 1 , adaptive_exposure = False ) . process ( img ) <nl> cv2 . imshow ( ' Vis ' , img ) <nl> cv2 . waitKey ( 1 ) <nl> self . video_manager . write_frame ( img ) <nl> mmm a / python / taichi / dynamics / smoke3 . py <nl> ppp b / python / taichi / dynamics / smoke3 . py <nl> <nl> import time <nl> <nl> + import taichi <nl> from taichi . core import tc_core <nl> from taichi . misc . util import * <nl> <nl> class Smoke3 : <nl> def __init__ ( self , * * kwargs ) : <nl> self . c = tc_core . create_simulation3d ( ' smoke ' ) <nl> self . c . initialize ( P ( * * kwargs ) ) <nl> - self . directory = ' . . / output / frames / ' + get_uuid ( ) + ' / ' <nl> + self . directory = taichi . get_output_path ( get_unique_task_id ( ) ) <nl> try : <nl> os . mkdir ( self . directory ) <nl> except Exception as e : <nl> mmm a / python / taichi / misc / settings . py <nl> ppp b / python / taichi / misc / settings . py <nl> <nl> import os <nl> + from taichi . misc . util import get_os_name <nl> <nl> default_num_threads = 2 <nl> <nl> def get_root_directory ( ) : <nl> <nl> <nl> def get_bin_directory ( ) : <nl> - return os . environ . get ( ' TAICHI_BIN_DIR ' , get_root_directory ( ) + ' / taichi / build / ' ) <nl> + if get_os_name ( ) = = ' win ' : <nl> + # for the dlls <nl> + bin_rel_path = ' / taichi / runtimes / ' <nl> + else : <nl> + bin_rel_path = ' / taichi / build / ' <nl> + return os . environ . get ( ' TAICHI_BIN_DIR ' , get_root_directory ( ) + bin_rel_path ) + ' / ' <nl> <nl> <nl> def get_output_directory ( ) : <nl> - return os . environ . get ( ' TAICHI_OUTPUT_DIR ' , get_root_directory ( ) + ' / taichi_outputs / ' ) <nl> + return os . environ . get ( ' TAICHI_OUTPUT_DIR ' , get_root_directory ( ) + ' / taichi_outputs / ' ) + ' / ' <nl> <nl> <nl> def get_output_path ( path ) : <nl> def get_output_path ( path ) : <nl> <nl> <nl> def get_asset_directory ( ) : <nl> - return os . environ . get ( ' TAICHI_ASSET_DIR ' , get_root_directory ( ) + ' / taichi_assets / ' ) <nl> + return os . environ . get ( ' TAICHI_ASSET_DIR ' , get_root_directory ( ) + ' / taichi_assets / ' ) + ' / ' <nl> <nl> <nl> def get_asset_path ( path ) : <nl> mmm a / python / taichi / misc / util . py <nl> ppp b / python / taichi / misc / util . py <nl> def get_os_name ( ) : <nl> <nl> <nl> def get_uuid ( ) : <nl> + print ' Warning : get_uuid is deprecated . Please use get_unique_task_id instead . ' <nl> + return get_unique_task_id ( ) <nl> + <nl> + def get_unique_task_id ( ) : <nl> return datetime . datetime . now ( ) . strftime ( ' task - % Y - % m - % d - % H - % M - % S - r ' ) + ( ' % 05d ' % random . randint ( 0 , 10000 ) ) <nl> <nl> import copy <nl>
Fixed Windows configuration and 3D Smoke / Snow / NBody simulation scripts
taichi-dev/taichi
50df67086fe3e8f27a5b1afcd7818c6e18607245
2017-01-06T05:18:44Z
mmm a / docs / api / web - contents . md <nl> ppp b / docs / api / web - contents . md <nl> Returns : <nl> <nl> Emitted when the preload script ` preloadPath ` throws an unhandled exception ` error ` . <nl> <nl> + # # # # Event : ' ipc - message ' <nl> + <nl> + Returns : <nl> + <nl> + * ` event ` Event <nl> + * ` channel ` String <nl> + * ` . . . args ` any [ ] <nl> + <nl> + Emitted when the renderer process sends an asynchronous message via ` ipcRenderer . send ( ) ` . <nl> + <nl> + # # # # Event : ' ipc - message - sync ' <nl> + <nl> + Returns : <nl> + <nl> + * ` event ` Event <nl> + * ` channel ` String <nl> + * ` . . . args ` any [ ] <nl> + <nl> + Emitted when the renderer process sends a synchronous message via ` ipcRenderer . sendSync ( ) ` . <nl> + <nl> # # # # Event : ' desktop - capturer - get - sources ' <nl> <nl> Returns : <nl> mmm a / lib / browser / api / web - contents . js <nl> ppp b / lib / browser / api / web - contents . js <nl> WebContents . prototype . _init = function ( ) { <nl> this . capturePage = deprecate . promisify ( this . capturePage , 2 ) <nl> <nl> / / Dispatch IPC messages to the ipc module . <nl> - this . on ( ' ipc - message ' , function ( event , [ channel , . . . args ] ) { <nl> + this . on ( ' - ipc - message ' , function ( event , [ channel , . . . args ] ) { <nl> + this . emit ( ' ipc - message ' , event , channel , . . . args ) <nl> ipcMain . emit ( channel , event , . . . args ) <nl> } ) <nl> <nl> - this . on ( ' ipc - message - sync ' , function ( event , [ channel , . . . args ] ) { <nl> + this . on ( ' - ipc - message - sync ' , function ( event , [ channel , . . . args ] ) { <nl> Object . defineProperty ( event , ' returnValue ' , { <nl> set : function ( value ) { <nl> return event . sendReply ( [ value ] ) <nl> } , <nl> get : function ( ) { } <nl> } ) <nl> + this . emit ( ' ipc - message - sync ' , event , channel , . . . args ) <nl> ipcMain . emit ( channel , event , . . . args ) <nl> } ) <nl> <nl> mmm a / lib / renderer / api / ipc - renderer . js <nl> ppp b / lib / renderer / api / ipc - renderer . js <nl> const ipcRenderer = v8Util . getHiddenValue ( global , ' ipc ' ) <nl> const internal = false <nl> <nl> ipcRenderer . send = function ( . . . args ) { <nl> - return binding . send ( ' ipc - message ' , args ) <nl> + return binding . send ( ' - ipc - message ' , args ) <nl> } <nl> <nl> ipcRenderer . sendSync = function ( . . . args ) { <nl> - return binding . sendSync ( ' ipc - message - sync ' , args ) [ 0 ] <nl> + return binding . sendSync ( ' - ipc - message - sync ' , args ) [ 0 ] <nl> } <nl> <nl> ipcRenderer . sendToHost = function ( . . . args ) { <nl> mmm a / spec / api - web - contents - spec . js <nl> ppp b / spec / api - web - contents - spec . js <nl> describe ( ' webContents module ' , ( ) = > { <nl> } ) <nl> } ) <nl> <nl> + describe ( ' ipc - message event ' , ( ) = > { <nl> + it ( ' emits when the renderer process sends an asynchronous message ' , async ( ) = > { <nl> + const webContents = remote . getCurrentWebContents ( ) <nl> + const promise = emittedOnce ( webContents , ' ipc - message ' ) <nl> + <nl> + ipcRenderer . send ( ' message ' , ' Hello World ! ' ) <nl> + <nl> + const [ , channel , message ] = await promise <nl> + expect ( channel ) . to . equal ( ' message ' ) <nl> + expect ( message ) . to . equal ( ' Hello World ! ' ) <nl> + } ) <nl> + } ) <nl> + <nl> + describe ( ' ipc - message - sync event ' , ( ) = > { <nl> + it ( ' emits when the renderer process sends a synchronous message ' , async ( ) = > { <nl> + const webContents = remote . getCurrentWebContents ( ) <nl> + const promise = emittedOnce ( webContents , ' ipc - message - sync ' ) <nl> + <nl> + ipcRenderer . send ( ' handle - next - ipc - message - sync ' , ' foobar ' ) <nl> + const result = ipcRenderer . sendSync ( ' message ' , ' Hello World ! ' ) <nl> + <nl> + const [ , channel , message ] = await promise <nl> + expect ( channel ) . to . equal ( ' message ' ) <nl> + expect ( message ) . to . equal ( ' Hello World ! ' ) <nl> + expect ( result ) . to . equal ( ' foobar ' ) <nl> + } ) <nl> + } ) <nl> + <nl> describe ( ' referrer ' , ( ) = > { <nl> it ( ' propagates referrer information to new target = _blank windows ' , ( done ) = > { <nl> const server = http . createServer ( ( req , res ) = > { <nl> mmm a / spec / chromium - spec . js <nl> ppp b / spec / chromium - spec . js <nl> describe ( ' chromium feature ' , ( ) = > { <nl> session : ses <nl> } <nl> } ) <nl> - w . webContents . on ( ' ipc - message ' , ( event , args ) = > { <nl> - if ( args [ 0 ] = = = ' deviceIds ' ) deviceIds . push ( args [ 1 ] ) <nl> + w . webContents . on ( ' ipc - message ' , ( event , channel , deviceId ) = > { <nl> + if ( channel = = = ' deviceIds ' ) deviceIds . push ( deviceId ) <nl> if ( deviceIds . length = = = 2 ) { <nl> assert . notDeepStrictEqual ( deviceIds [ 0 ] , deviceIds [ 1 ] ) <nl> closeWindow ( w ) . then ( ( ) = > { <nl> describe ( ' chromium feature ' , ( ) = > { <nl> partition : ' sw - file - scheme - spec ' <nl> } <nl> } ) <nl> - w . webContents . on ( ' ipc - message ' , ( event , args ) = > { <nl> - if ( args [ 0 ] = = = ' reload ' ) { <nl> + w . webContents . on ( ' ipc - message ' , ( event , channel , message ) = > { <nl> + if ( channel = = = ' reload ' ) { <nl> w . webContents . reload ( ) <nl> - } else if ( args [ 0 ] = = = ' error ' ) { <nl> - done ( args [ 1 ] ) <nl> - } else if ( args [ 0 ] = = = ' response ' ) { <nl> - assert . strictEqual ( args [ 1 ] , ' Hello from serviceWorker ! ' ) <nl> + } else if ( channel = = = ' error ' ) { <nl> + done ( message ) <nl> + } else if ( channel = = = ' response ' ) { <nl> + assert . strictEqual ( message , ' Hello from serviceWorker ! ' ) <nl> session . fromPartition ( ' sw - file - scheme - spec ' ) . clearStorageData ( { <nl> storages : [ ' serviceworkers ' ] <nl> } , ( ) = > done ( ) ) <nl> describe ( ' chromium feature ' , ( ) = > { <nl> session : customSession <nl> } <nl> } ) <nl> - w . webContents . on ( ' ipc - message ' , ( event , args ) = > { <nl> - if ( args [ 0 ] = = = ' reload ' ) { <nl> + w . webContents . on ( ' ipc - message ' , ( event , channel , message ) = > { <nl> + if ( channel = = = ' reload ' ) { <nl> w . webContents . reload ( ) <nl> - } else if ( args [ 0 ] = = = ' error ' ) { <nl> - done ( ` unexpected error : $ { args [ 1 ] } ` ) <nl> - } else if ( args [ 0 ] = = = ' response ' ) { <nl> - assert . strictEqual ( args [ 1 ] , ' Hello from serviceWorker ! ' ) <nl> + } else if ( channel = = = ' error ' ) { <nl> + done ( ` unexpected error : $ { message } ` ) <nl> + } else if ( channel = = = ' response ' ) { <nl> + assert . strictEqual ( message , ' Hello from serviceWorker ! ' ) <nl> customSession . clearStorageData ( { <nl> storages : [ ' serviceworkers ' ] <nl> } , ( ) = > { <nl> describe ( ' chromium feature ' , ( ) = > { <nl> partition : ' geolocation - spec ' <nl> } <nl> } ) <nl> - w . webContents . on ( ' ipc - message ' , ( event , args ) = > { <nl> - if ( args [ 0 ] = = = ' success ' ) { <nl> + w . webContents . on ( ' ipc - message ' , ( event , channel ) = > { <nl> + if ( channel = = = ' success ' ) { <nl> done ( ) <nl> } else { <nl> done ( ' unexpected response from geolocation api ' ) <nl> describe ( ' chromium feature ' , ( ) = > { <nl> <nl> describe ( ' window . opener ' , ( ) = > { <nl> const url = ` file : / / $ { fixtures } / pages / window - opener . html ` <nl> - it ( ' is null for main window ' , ( done ) = > { <nl> + it ( ' is null for main window ' , async ( ) = > { <nl> w = new BrowserWindow ( { <nl> show : false , <nl> webPreferences : { <nl> nodeIntegration : true <nl> } <nl> } ) <nl> - w . webContents . once ( ' ipc - message ' , ( event , args ) = > { <nl> - assert . deepStrictEqual ( args , [ ' opener ' , null ] ) <nl> - done ( ) <nl> - } ) <nl> + const promise = emittedOnce ( w . webContents , ' ipc - message ' ) <nl> w . loadFile ( path . join ( fixtures , ' pages ' , ' window - opener . html ' ) ) <nl> + const [ , channel , opener ] = await promise <nl> + expect ( channel ) . to . equal ( ' opener ' ) <nl> + expect ( opener ) . to . equal ( null ) <nl> } ) <nl> <nl> it ( ' is not null for window opened by window . open ' , ( done ) = > { <nl> mmm a / spec / static / main . js <nl> ppp b / spec / static / main . js <nl> app . on ( ' ready ' , function ( ) { <nl> } ) <nl> } ) <nl> <nl> + ipcMain . on ( ' handle - next - ipc - message - sync ' , function ( event , returnValue ) { <nl> + event . sender . once ( ' ipc - message - sync ' , ( event , channel , args ) = > { <nl> + event . returnValue = returnValue <nl> + } ) <nl> + } ) <nl> + <nl> for ( const eventName of [ <nl> ' remote - require ' , <nl> ' remote - get - global ' , <nl> mmm a / spec / webview - spec . js <nl> ppp b / spec / webview - spec . js <nl> describe ( ' < webview > tag ' , function ( ) { <nl> } ) <nl> <nl> describe ( ' ipc - message event ' , ( ) = > { <nl> - it ( ' emits when guest sends a ipc message to browser ' , async ( ) = > { <nl> + it ( ' emits when guest sends an ipc message to browser ' , async ( ) = > { <nl> loadWebView ( webview , { <nl> nodeintegration : ' on ' , <nl> src : ` file : / / $ { fixtures } / pages / ipc - message . html ` <nl>
feat : make ` ipc - message ` and ` ipc - message - sync ` events public ( )
electron/electron
6cba2c50a2c9885e0b4de2d76b54cb40ae1d03b3
2019-01-22T16:47:58Z
mmm a / modules / videoio / src / cap_ffmpeg_impl . hpp <nl> ppp b / modules / videoio / src / cap_ffmpeg_impl . hpp <nl> bool CvCapture_FFMPEG : : open ( const char * _filename ) <nl> # else <nl> av_dict_set ( & dict , " rtsp_transport " , " tcp " , 0 ) ; <nl> # endif <nl> - int err = avformat_open_input ( & ic , _filename , NULL , & dict ) ; <nl> + AVInputFormat * input_format = NULL ; <nl> + AVDictionaryEntry * entry = av_dict_get ( dict , " input_format " , NULL , 0 ) ; <nl> + if ( entry ! = 0 ) <nl> + { <nl> + input_format = av_find_input_format ( entry - > value ) ; <nl> + } <nl> + <nl> + int err = avformat_open_input ( & ic , _filename , input_format , & dict ) ; <nl> # else <nl> int err = av_open_input_file ( & ic , _filename , NULL , 0 , NULL ) ; <nl> # endif <nl>
Merge pull request from dgel : force_input_format_ffmpeg
opencv/opencv
32da0705cfb14dadf79043713bdd4753910ee8f5
2019-08-06T20:52:57Z
mmm a / xbmc / settings / GUISettings . cpp <nl> ppp b / xbmc / settings / GUISettings . cpp <nl> void CGUISettings : : Initialize ( ) <nl> AddBool ( fl , " filelists . showhidden " , 21330 , false ) ; <nl> <nl> CSettingsCategory * ss = AddCategory ( SETTINGS_APPEARANCE , " screensaver " , 360 ) ; <nl> - AddInt ( ss , " screensaver . time " , 355 , 3 , 1 , 1 , 60 , SPIN_CONTROL_INT_PLUS , MASK_MINS ) ; <nl> AddDefaultAddon ( ss , " screensaver . mode " , 356 , " screensaver . xbmc . builtin . dim " , ADDON_SCREENSAVER ) ; <nl> AddString ( ss , " screensaver . settings " , 21417 , " " , BUTTON_CONTROL_STANDARD ) ; <nl> AddString ( ss , " screensaver . preview " , 1000 , " " , BUTTON_CONTROL_STANDARD ) ; <nl> + AddInt ( ss , " screensaver . time " , 355 , 3 , 1 , 1 , 60 , SPIN_CONTROL_INT_PLUS , MASK_MINS ) ; <nl> AddSeparator ( ss , " screensaver . sep1 " ) ; <nl> AddBool ( ss , " screensaver . usemusicvisinstead " , 13392 , true ) ; <nl> AddBool ( ss , " screensaver . usedimonpause " , 22014 , true ) ; <nl> mmm a / xbmc / settings / GUIWindowSettingsCategory . cpp <nl> ppp b / xbmc / settings / GUIWindowSettingsCategory . cpp <nl> void CGUIWindowSettingsCategory : : UpdateSettings ( ) <nl> pControl - > SetEnabled ( false ) ; <nl> } <nl> else if ( strSetting . Equals ( " screensaver . preview " ) | | <nl> + strSetting . Equals ( " screensaver . time " ) | | <nl> strSetting . Equals ( " screensaver . usedimonpause " ) | | <nl> strSetting . Equals ( " screensaver . usemusicvisinstead " ) ) <nl> { <nl>
screensaver settings nitpick
xbmc/xbmc
18a1baaf99812f2a4d6661c1d37a73fe574866db
2012-11-23T21:21:15Z
mmm a / js / actions / _api / foxx / app . js <nl> ppp b / js / actions / _api / foxx / app . js <nl> actions . defineHttp ( { <nl> callback : function ( body ) { <nl> var mount = body . mount ; <nl> var options = body . options ; <nl> - return foxxManager . runTests ( mount , options ) <nl> + return foxxManager . runTests ( mount , options ) ; <nl> } <nl> } ) <nl> } ) ; <nl> actions . defineHttp ( { <nl> callback : function ( body ) { <nl> var name = body . name ; <nl> var mount = body . mount ; <nl> - return foxxManager . runScript ( name , mount ) <nl> + return foxxManager . runScript ( name , mount ) ; <nl> } <nl> } ) <nl> } ) ; <nl> mmm a / js / apps / system / _admin / aardvark / APP / frontend / js / views / applicationDetailView . js <nl> ppp b / js / apps / system / _admin / aardvark / APP / frontend / js / views / applicationDetailView . js <nl> <nl> _ . each ( this . model . get ( ' config ' ) , function ( opt , key ) { <nl> var $ el = $ ( " # app_config_ " + key ) ; <nl> var val = window . arangoHelper . escapeHtml ( $ el . val ( ) ) ; <nl> - if ( opt . type = = = " boolean " | | obj . type = = = " bool " ) { <nl> + if ( opt . type = = = " boolean " | | opt . type = = = " bool " ) { <nl> cfg [ key ] = $ el . is ( " : checked " ) ; <nl> return ; <nl> } <nl> <nl> } <nl> if ( opt . type = = = " number " ) { <nl> cfg [ key ] = parseFloat ( val ) ; <nl> - } else if ( opt . type = = = " integer " | | obj . type = = = " int " ) { <nl> + } else if ( opt . type = = = " integer " | | opt . type = = = " int " ) { <nl> cfg [ key ] = parseInt ( val , 10 ) ; <nl> } else { <nl> cfg [ key ] = val ; <nl> mmm a / js / client / modules / org / arangodb / foxx / manager . js <nl> ppp b / js / client / modules / org / arangodb / foxx / manager . js <nl> <nl> var req = { <nl> mount : mount , <nl> options : options <nl> - } <nl> + } ; <nl> var res = arango . POST ( " / _admin / foxx / tests " , JSON . stringify ( req ) ) ; <nl> arangosh . checkRequestResult ( res ) ; <nl> return res ; <nl> mmm a / js / server / modules / org / arangodb / foxx / arangoApp . js <nl> ppp b / js / server / modules / org / arangodb / foxx / arangoApp . js <nl> function computeRootAppPath ( mount , isValidation ) { <nl> if ( ! expected [ name ] ) { <nl> invalid . push ( " Unexpected Option " + name ) ; <nl> } else { <nl> + var type = expected [ name ] . type ; <nl> var result = utils . parameterTypes [ type ] . validate ( value ) ; <nl> if ( result . error ) { <nl> invalid . push ( result . error . message . replace ( / ^ " value " / , ' " ' + name + ' " ' ) ) ; <nl>
Linting .
arangodb/arangodb
71c2e0664962c181ff40124de59e15dfb0d65955
2015-05-06T15:33:05Z
mmm a / dbms / include / DB / DataStreams / BlockInputStreamFromRowInputStream . h <nl> ppp b / dbms / include / DB / DataStreams / BlockInputStreamFromRowInputStream . h <nl> class BlockInputStreamFromRowInputStream : public IProfilingBlockInputStream <nl> return res . str ( ) ; <nl> } <nl> <nl> + RowInputStreamPtr & getRowInput ( ) { return row_input ; } <nl> + <nl> protected : <nl> Block readImpl ( ) override ; <nl> <nl> mmm a / dbms / include / DB / DataStreams / TabSeparatedRowInputStream . h <nl> ppp b / dbms / include / DB / DataStreams / TabSeparatedRowInputStream . h <nl> class TabSeparatedRowInputStream : public IRowInputStream <nl> bool read ( Row & row ) override ; <nl> void readPrefix ( ) override ; <nl> <nl> + / * * В случае исключения при парсинге , вы можете вызвать эту функцию . <nl> + * Она выполняет заново парсинг последних двух строк и выводит подробную информацию о том , что происходит . <nl> + * / <nl> + void printDiagnosticInfo ( WriteBuffer & out ) ; <nl> + <nl> private : <nl> ReadBuffer & istr ; <nl> const Block sample ; <nl> bool with_names ; <nl> bool with_types ; <nl> DataTypes data_types ; <nl> + <nl> + / / / Для удобной диагностики в случае ошибки . <nl> + <nl> + size_t row_num = 0 ; <nl> + <nl> + / / / Сколько байт было считано , не считая тех , что ещё в буфере . <nl> + size_t bytes_read_at_start_of_buffer_on_current_row = 0 ; <nl> + size_t bytes_read_at_start_of_buffer_on_prev_row = 0 ; <nl> + <nl> + BufferBase : : Position pos_of_current_row = nullptr ; <nl> + BufferBase : : Position pos_of_prev_row = nullptr ; <nl> + <nl> + void updateDiagnosticInfo ( ) <nl> + { <nl> + + + row_num ; <nl> + <nl> + bytes_read_at_start_of_buffer_on_prev_row = bytes_read_at_start_of_buffer_on_current_row ; <nl> + bytes_read_at_start_of_buffer_on_current_row = istr . count ( ) - istr . offset ( ) ; <nl> + <nl> + pos_of_prev_row = pos_of_current_row ; <nl> + pos_of_current_row = istr . position ( ) ; <nl> + } <nl> + <nl> + bool parseRowAndPrintDiagnosticInfo ( WriteBuffer & out ) ; <nl> } ; <nl> <nl> } <nl> mmm a / dbms / src / Client / Client . cpp <nl> ppp b / dbms / src / Client / Client . cpp <nl> <nl> # include < DB / IO / ReadBufferFromIStream . h > <nl> <nl> # include < DB / DataStreams / AsynchronousBlockInputStream . h > <nl> + # include < DB / DataStreams / BlockInputStreamFromRowInputStream . h > <nl> + # include < DB / DataStreams / TabSeparatedRowInputStream . h > <nl> <nl> # include < DB / Parsers / ParserQuery . h > <nl> # include < DB / Parsers / ASTSetQuery . h > <nl> class Client : public Poco : : Util : : Application <nl> if ( ! insert - > format . empty ( ) ) <nl> current_format = insert - > format ; <nl> <nl> - BlockInputStreamPtr block_std_in = new AsynchronousBlockInputStream ( context . getFormatFactory ( ) . getInput ( <nl> - current_format , buf , sample , insert_format_max_block_size , context . getDataTypeFactory ( ) ) ) ; <nl> - block_std_in - > readPrefix ( ) ; <nl> + BlockInputStreamPtr block_input = context . getFormatFactory ( ) . getInput ( <nl> + current_format , buf , sample , insert_format_max_block_size , context . getDataTypeFactory ( ) ) ; <nl> <nl> - while ( true ) <nl> + BlockInputStreamPtr async_block_input = new AsynchronousBlockInputStream ( block_input ) ; <nl> + <nl> + try <nl> { <nl> - Block block = block_std_in - > read ( ) ; <nl> - connection - > sendData ( block ) ; <nl> - processed_rows + = block . rows ( ) ; <nl> + async_block_input - > readPrefix ( ) ; <nl> <nl> - if ( ! block ) <nl> - break ; <nl> + while ( true ) <nl> + { <nl> + Block block = async_block_input - > read ( ) ; <nl> + connection - > sendData ( block ) ; <nl> + processed_rows + = block . rows ( ) ; <nl> + <nl> + if ( ! block ) <nl> + break ; <nl> + } <nl> + <nl> + async_block_input - > readSuffix ( ) ; <nl> } <nl> + catch ( . . . ) / / / TODO Более точно <nl> + { <nl> + / * * В частном случае - при использовании формата TabSeparated , мы можем вывести более подробную диагностику . <nl> + * / <nl> + <nl> + BlockInputStreamFromRowInputStream * concrete_block_input = dynamic_cast < BlockInputStreamFromRowInputStream * > ( block_input . get ( ) ) ; <nl> + if ( ! concrete_block_input ) <nl> + throw ; <nl> <nl> - block_std_in - > readSuffix ( ) ; <nl> + RowInputStreamPtr & row_input = concrete_block_input - > getRowInput ( ) ; <nl> + TabSeparatedRowInputStream * concrete_row_input = dynamic_cast < TabSeparatedRowInputStream * > ( row_input . get ( ) ) ; <nl> + if ( ! concrete_row_input ) <nl> + throw ; <nl> + <nl> + WriteBufferFromFileDescriptor stderr_out ( STDERR_FILENO ) ; <nl> + concrete_row_input - > printDiagnosticInfo ( stderr_out ) ; <nl> + <nl> + throw Exception ( " Cannot parse data in tab separated format . " , ErrorCodes : : SYNTAX_ERROR ) ; <nl> + } <nl> } <nl> <nl> <nl> mmm a / dbms / src / DataStreams / TabSeparatedRowInputStream . cpp <nl> ppp b / dbms / src / DataStreams / TabSeparatedRowInputStream . cpp <nl> <nl> # include < DB / IO / ReadHelpers . h > <nl> + # include < DB / IO / Operators . h > <nl> <nl> # include < DB / DataStreams / TabSeparatedRowInputStream . h > <nl> + # include < DB / DataTypes / DataTypesNumberFixed . h > <nl> <nl> <nl> namespace DB <nl> void TabSeparatedRowInputStream : : readPrefix ( ) <nl> <nl> bool TabSeparatedRowInputStream : : read ( Row & row ) <nl> { <nl> + updateDiagnosticInfo ( ) ; <nl> + <nl> size_t size = data_types . size ( ) ; <nl> row . resize ( size ) ; <nl> - <nl> + <nl> for ( size_t i = 0 ; i < size ; + + i ) <nl> { <nl> if ( i = = 0 & & istr . eof ( ) ) <nl> bool TabSeparatedRowInputStream : : read ( Row & row ) <nl> row . clear ( ) ; <nl> return false ; <nl> } <nl> - <nl> + <nl> data_types [ i ] - > deserializeTextEscaped ( row [ i ] , istr ) ; <nl> <nl> / / / пропускаем разделители <nl> bool TabSeparatedRowInputStream : : read ( Row & row ) <nl> return true ; <nl> } <nl> <nl> + <nl> + void TabSeparatedRowInputStream : : printDiagnosticInfo ( WriteBuffer & out ) <nl> + { <nl> + / / / Вывести подробную диагностику возможно лишь если последняя и предпоследняя строка ещё находятся в буфере для чтения . <nl> + size_t bytes_read_at_start_of_buffer = istr . count ( ) - istr . offset ( ) ; <nl> + if ( bytes_read_at_start_of_buffer ! = bytes_read_at_start_of_buffer_on_prev_row ) <nl> + { <nl> + out < < " Could not print diagnostic info because two last rows aren ' t in buffer ( rare case ) \ n " ; <nl> + return ; <nl> + } <nl> + <nl> + / / / Откатываем курсор для чтения на начало предыдущей или текущей строки и парсим всё заново . Но теперь выводим подробную информацию . <nl> + <nl> + if ( pos_of_prev_row ) <nl> + { <nl> + istr . position ( ) = pos_of_prev_row ; <nl> + <nl> + out < < " \ nRow " < < ( row_num - 1 ) < < " : \ n " ; <nl> + if ( ! parseRowAndPrintDiagnosticInfo ( out ) ) <nl> + return ; <nl> + } <nl> + else <nl> + { <nl> + if ( ! pos_of_current_row ) <nl> + { <nl> + out < < " Could not print diagnostic info because parsing of data hasn ' t started . \ n " ; <nl> + return ; <nl> + } <nl> + <nl> + istr . position ( ) = pos_of_current_row ; <nl> + } <nl> + <nl> + out < < " \ nRow " < < row_num < < " : \ n " ; <nl> + parseRowAndPrintDiagnosticInfo ( out ) ; <nl> + out < < " \ n " ; <nl> + } <nl> + <nl> + <nl> + static void verbosePrintString ( BufferBase : : Position begin , BufferBase : : Position end , WriteBuffer & out ) <nl> + { <nl> + if ( end = = begin ) <nl> + { <nl> + out < < " < EMPTY > " ; <nl> + return ; <nl> + } <nl> + <nl> + out < < " \ " " ; <nl> + <nl> + for ( auto pos = begin ; pos < end ; + + pos ) <nl> + { <nl> + switch ( * pos ) <nl> + { <nl> + case ' \ 0 ' : <nl> + out < < " < ASCII NUL > " ; <nl> + break ; <nl> + case ' \ b ' : <nl> + out < < " < BACKSPACE > " ; <nl> + break ; <nl> + case ' \ f ' : <nl> + out < < " < FORM FEED > " ; <nl> + break ; <nl> + case ' \ n ' : <nl> + out < < " < LINE FEED > " ; <nl> + break ; <nl> + case ' \ r ' : <nl> + out < < " < CARRIAGE RETURN > " ; <nl> + break ; <nl> + case ' \ t ' : <nl> + out < < " < TAB > " ; <nl> + break ; <nl> + case ' \ \ ' : <nl> + out < < " < BACKSLASH > " ; <nl> + break ; <nl> + case ' " ' : <nl> + out < < " < DOUBLE QUOTE > " ; <nl> + break ; <nl> + case ' \ ' ' : <nl> + out < < " < SINGLE QUOTE > " ; <nl> + break ; <nl> + <nl> + default : <nl> + { <nl> + if ( * pos > = 0 & & * pos < 32 ) <nl> + { <nl> + static const char * hex = " 0123456789ABCDEF " ; <nl> + out < < " < 0x " < < hex [ * pos / 16 ] < < hex [ * pos % 16 ] < < " > " ; <nl> + } <nl> + else <nl> + out < < * pos ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + out < < " \ " " ; <nl> + } <nl> + <nl> + <nl> + bool TabSeparatedRowInputStream : : parseRowAndPrintDiagnosticInfo ( WriteBuffer & out ) <nl> + { <nl> + size_t size = data_types . size ( ) ; <nl> + for ( size_t i = 0 ; i < size ; + + i ) <nl> + { <nl> + if ( i = = 0 & & istr . eof ( ) ) <nl> + { <nl> + out < < " < End of stream > \ n " ; <nl> + return false ; <nl> + } <nl> + <nl> + out < < " Column " < < i < < " , name : " < < sample . getByPosition ( i ) . name < < " , type : " < < data_types [ i ] - > getName ( ) ; <nl> + <nl> + auto prev_position = istr . position ( ) ; <nl> + std : : exception_ptr exception ; <nl> + <nl> + Field field ; <nl> + try <nl> + { <nl> + data_types [ i ] - > deserializeTextEscaped ( field , istr ) ; <nl> + } <nl> + catch ( . . . ) <nl> + { <nl> + exception = std : : current_exception ( ) ; <nl> + } <nl> + <nl> + auto curr_position = istr . position ( ) ; <nl> + <nl> + if ( curr_position < prev_position ) <nl> + throw Exception ( " Logical error : parsing is non - deterministic . " , ErrorCodes : : LOGICAL_ERROR ) ; <nl> + <nl> + if ( data_types [ i ] - > isNumeric ( ) ) <nl> + { <nl> + / / / Пустая строка вместо числа . <nl> + if ( curr_position = = prev_position ) <nl> + { <nl> + out < < " , ERROR : text " ; <nl> + verbosePrintString ( prev_position , std : : min ( prev_position + 10 , istr . buffer ( ) . end ( ) ) , out ) ; <nl> + out < < " is not like number \ n " ; <nl> + return false ; <nl> + } <nl> + } <nl> + <nl> + out < < " , parsed text : " ; <nl> + verbosePrintString ( prev_position , curr_position , out ) ; <nl> + <nl> + if ( exception ) <nl> + { <nl> + out < < " , ERROR \ n " ; <nl> + return false ; <nl> + } <nl> + <nl> + out < < " as " < < apply_visitor ( FieldVisitorToString ( ) , field ) < < " \ n " ; <nl> + <nl> + if ( data_types [ i ] - > isNumeric ( ) ) <nl> + { <nl> + if ( * curr_position ! = ' \ n ' & & * curr_position ! = ' \ t ' ) <nl> + { <nl> + out < < " ERROR : garbage after number : " ; <nl> + verbosePrintString ( curr_position , std : : min ( curr_position + 10 , istr . buffer ( ) . end ( ) ) , out ) ; <nl> + out < < " \ n " ; <nl> + return false ; <nl> + } <nl> + } <nl> + <nl> + if ( ( typeid_cast < const DataTypeUInt8 * > ( data_types [ i ] . get ( ) ) & & field . get < UInt64 > ( ) > std : : numeric_limits < UInt8 > : : max ( ) ) <nl> + | | ( typeid_cast < const DataTypeUInt16 * > ( data_types [ i ] . get ( ) ) & & field . get < UInt64 > ( ) > std : : numeric_limits < UInt16 > : : max ( ) ) <nl> + | | ( typeid_cast < const DataTypeUInt32 * > ( data_types [ i ] . get ( ) ) & & field . get < UInt64 > ( ) > std : : numeric_limits < UInt32 > : : max ( ) ) <nl> + | | ( typeid_cast < const DataTypeInt8 * > ( data_types [ i ] . get ( ) ) <nl> + & & ( field . get < Int64 > ( ) > std : : numeric_limits < Int8 > : : max ( ) | | field . get < Int64 > ( ) < std : : numeric_limits < Int8 > : : min ( ) ) ) <nl> + | | ( typeid_cast < const DataTypeInt16 * > ( data_types [ i ] . get ( ) ) <nl> + & & ( field . get < Int64 > ( ) > std : : numeric_limits < Int16 > : : max ( ) | | field . get < Int64 > ( ) < std : : numeric_limits < Int16 > : : min ( ) ) ) <nl> + | | ( typeid_cast < const DataTypeInt32 * > ( data_types [ i ] . get ( ) ) <nl> + & & ( field . get < Int64 > ( ) > std : : numeric_limits < Int32 > : : max ( ) | | field . get < Int64 > ( ) < std : : numeric_limits < Int32 > : : min ( ) ) ) ) <nl> + { <nl> + out < < " ERROR : parsed number is out of range of data type . \ n " ; <nl> + return false ; <nl> + } <nl> + <nl> + / / / Разделители <nl> + if ( i + 1 = = size ) <nl> + { <nl> + if ( ! istr . eof ( ) ) <nl> + { <nl> + try <nl> + { <nl> + assertString ( " \ n " , istr ) ; <nl> + } <nl> + catch ( const DB : : Exception & ) <nl> + { <nl> + if ( * istr . position ( ) = = ' \ t ' ) <nl> + { <nl> + out < < " ERROR : Tab found where line feed is expected . " <nl> + " It ' s like your file has more columns than expected . \ n " <nl> + " And if your file have right number of columns , maybe it have unescaped tab in value . \ n " ; <nl> + } <nl> + else if ( * istr . position ( ) = = ' \ r ' ) <nl> + { <nl> + out < < " ERROR : Carriage return found where line feed is expected . " <nl> + " It ' s like your file has DOS / Windows style line separators , that is illegal in TabSeparated format . \ n " ; <nl> + } <nl> + else <nl> + { <nl> + out < < " ERROR : There is no line feed . " ; <nl> + verbosePrintString ( istr . position ( ) , istr . position ( ) + 1 , out ) ; <nl> + out < < " found instead . \ n " ; <nl> + } <nl> + return false ; <nl> + } <nl> + } <nl> + } <nl> + else <nl> + { <nl> + try <nl> + { <nl> + assertString ( " \ t " , istr ) ; <nl> + } <nl> + catch ( const DB : : Exception & ) <nl> + { <nl> + if ( * istr . position ( ) = = ' \ n ' ) <nl> + { <nl> + out < < " ERROR : Line feed found where tab is expected . " <nl> + " It ' s like your file has less columns than expected . \ n " <nl> + " And if your file have right number of columns , maybe it have unescaped backslash in value before tab , which cause tab has escaped . \ n " ; <nl> + } <nl> + else if ( * istr . position ( ) = = ' \ r ' ) <nl> + { <nl> + out < < " ERROR : Carriage return found where tab is expected . \ n " ; <nl> + } <nl> + else <nl> + { <nl> + out < < " ERROR : There is no tab . " ; <nl> + verbosePrintString ( istr . position ( ) , istr . position ( ) + 1 , out ) ; <nl> + out < < " found instead . \ n " ; <nl> + } <nl> + return false ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + return true ; <nl> + } <nl> + <nl> } <nl>
dbms : better diagnostics of errors in TabSeparated format ( development ) [ # METR - 15574 ] .
ClickHouse/ClickHouse
92c2a9ceaaf5257c9abe9fc90bed8c6e4abf58f6
2015-03-29T07:13:38Z
mmm a / Makefile <nl> ppp b / Makefile <nl> STRESS_TEST_SRC = \ <nl> $ ( GENDIR ) / src / proto / grpc / testing / messages . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / messages . grpc . pb . cc \ <nl> $ ( GENDIR ) / src / proto / grpc / testing / metrics . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / metrics . grpc . pb . cc \ <nl> $ ( GENDIR ) / src / proto / grpc / testing / test . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / test . grpc . pb . cc \ <nl> + test / cpp / interop / client_helper . cc \ <nl> test / cpp / interop / interop_client . cc \ <nl> test / cpp / interop / stress_interop_client . cc \ <nl> test / cpp / interop / stress_test . cc \ <nl> $ ( OBJDIR ) / $ ( CONFIG ) / src / proto / grpc / testing / metrics . o : $ ( LIBDIR ) / $ ( CONFIG ) / libgr <nl> <nl> $ ( OBJDIR ) / $ ( CONFIG ) / src / proto / grpc / testing / test . o : $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc + + _test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc_test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc + + . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc . a $ ( LIBDIR ) / $ ( CONFIG ) / libgpr_test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgpr . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc + + _test_config . a <nl> <nl> + $ ( OBJDIR ) / $ ( CONFIG ) / test / cpp / interop / client_helper . o : $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc + + _test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc_test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc + + . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc . a $ ( LIBDIR ) / $ ( CONFIG ) / libgpr_test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgpr . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc + + _test_config . a <nl> + <nl> $ ( OBJDIR ) / $ ( CONFIG ) / test / cpp / interop / interop_client . o : $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc + + _test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc_test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc + + . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc . a $ ( LIBDIR ) / $ ( CONFIG ) / libgpr_test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgpr . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc + + _test_config . a <nl> <nl> $ ( OBJDIR ) / $ ( CONFIG ) / test / cpp / interop / stress_interop_client . o : $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc + + _test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc_test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc + + . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc . a $ ( LIBDIR ) / $ ( CONFIG ) / libgpr_test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgpr . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc + + _test_config . a <nl> ifneq ( $ ( NO_DEPS ) , true ) <nl> - include $ ( STRESS_TEST_OBJS : . o = . dep ) <nl> endif <nl> endif <nl> + $ ( OBJDIR ) / $ ( CONFIG ) / test / cpp / interop / client_helper . o : $ ( GENDIR ) / src / proto / grpc / testing / empty . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / empty . grpc . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / messages . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / messages . grpc . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / metrics . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / metrics . grpc . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / test . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / test . grpc . pb . cc <nl> $ ( OBJDIR ) / $ ( CONFIG ) / test / cpp / interop / interop_client . o : $ ( GENDIR ) / src / proto / grpc / testing / empty . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / empty . grpc . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / messages . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / messages . grpc . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / metrics . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / metrics . grpc . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / test . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / test . grpc . pb . cc <nl> $ ( OBJDIR ) / $ ( CONFIG ) / test / cpp / interop / stress_interop_client . o : $ ( GENDIR ) / src / proto / grpc / testing / empty . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / empty . grpc . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / messages . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / messages . grpc . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / metrics . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / metrics . grpc . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / test . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / test . grpc . pb . cc <nl> $ ( OBJDIR ) / $ ( CONFIG ) / test / cpp / interop / stress_test . o : $ ( GENDIR ) / src / proto / grpc / testing / empty . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / empty . grpc . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / messages . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / messages . grpc . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / metrics . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / metrics . grpc . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / test . pb . cc $ ( GENDIR ) / src / proto / grpc / testing / test . grpc . pb . cc <nl> mmm a / build . yaml <nl> ppp b / build . yaml <nl> targets : <nl> - src / proto / grpc / testing / messages . proto <nl> - src / proto / grpc / testing / metrics . proto <nl> - src / proto / grpc / testing / test . proto <nl> + - test / cpp / interop / client_helper . cc <nl> - test / cpp / interop / interop_client . cc <nl> - test / cpp / interop / stress_interop_client . cc <nl> - test / cpp / interop / stress_test . cc <nl> mmm a / test / cpp / interop / stress_test . cc <nl> ppp b / test / cpp / interop / stress_test . cc <nl> <nl> <nl> # include " src / proto / grpc / testing / metrics . grpc . pb . h " <nl> # include " src / proto / grpc / testing / metrics . pb . h " <nl> + # include " test / cpp / interop / client_helper . h " <nl> # include " test / cpp / interop / interop_client . h " <nl> # include " test / cpp / interop / stress_interop_client . h " <nl> # include " test / cpp / util / metrics_server . h " <nl> DEFINE_int32 ( test_duration_secs , - 1 , <nl> <nl> DEFINE_string ( server_addresses , " localhost : 8080 " , <nl> " The list of server " <nl> - " addresses in the format : \ n " <nl> + " addresses . This option is ignored if either \ n " <nl> + " server_port or server_host is specified . The format is : \ n " <nl> " \ " < name_1 > : < port_1 > , < name_2 > : < port_1 > . . . < name_N > : < port_N > \ " \ n " <nl> " Note : < name > can be servername or IP address . " ) ; <nl> <nl> DEFINE_int32 ( num_stubs_per_channel , 1 , <nl> " indicates the max number of parallel RPC calls on each channel " <nl> " at any given time . " ) ; <nl> <nl> + DEFINE_string ( test_case , " " , <nl> + " Configure different test cases . Valid options are : \ n \ n " <nl> + " all : all test cases ; \ n " <nl> + " cancel_after_begin : cancel stream after starting it ; \ n " <nl> + " cancel_after_first_response : cancel on first response ; \ n " <nl> + " client_compressed_streaming : compressed request streaming with " <nl> + " client_compressed_unary : single compressed request ; \ n " <nl> + " client_streaming : request streaming with single response ; \ n " <nl> + " compute_engine_creds : large_unary with compute engine auth ; \ n " <nl> + " custom_metadata : server will echo custom metadata ; \ n " <nl> + " empty_stream : bi - di stream with no request / response ; \ n " <nl> + " empty_unary : empty ( zero bytes ) request and response ; \ n " <nl> + " half_duplex : half - duplex streaming ; \ n " <nl> + " jwt_token_creds : large_unary with JWT token auth ; \ n " <nl> + " large_unary : single request and ( large ) response ; \ n " <nl> + " oauth2_auth_token : raw oauth2 access token auth ; \ n " <nl> + " per_rpc_creds : raw oauth2 access token on a single rpc ; \ n " <nl> + " ping_pong : full - duplex streaming ; \ n " <nl> + " response streaming ; \ n " <nl> + " server_compressed_streaming : single request with compressed " <nl> + " server_compressed_unary : single compressed response ; \ n " <nl> + " server_streaming : single request with response streaming ; \ n " <nl> + " slow_consumer : single request with response streaming with " <nl> + " slow client consumer ; \ n " <nl> + " status_code_and_message : verify status code & message ; \ n " <nl> + " timeout_on_sleeping_server : deadline exceeds on stream ; \ n " <nl> + " unimplemented_method : client calls an unimplemented_method ; \ n " ) ; <nl> + <nl> / / TODO ( sreek ) : Add more test cases here in future <nl> DEFINE_string ( test_cases , " " , <nl> " List of test cases to call along with the " <nl> DEFINE_bool ( do_not_abort_on_transient_failures , true , <nl> " If set to ' true ' , abort ( ) is not called in case of transient " <nl> " failures like temporary connection failures . " ) ; <nl> <nl> + / / Options from client . cc ( for compatibility with interop test ) . <nl> + / / TODO ( sreek ) : Consolidate overlapping options <nl> + DEFINE_bool ( use_tls , false , " Whether to use tls . " ) ; <nl> + DEFINE_bool ( use_test_ca , false , " False to use SSL roots for google " ) ; <nl> + DEFINE_int32 ( server_port , 0 , " Server port . " ) ; <nl> + DEFINE_string ( server_host , " 127 . 0 . 0 . 1 " , " Server host to connect to " ) ; <nl> + DEFINE_string ( server_host_override , " foo . test . google . fr " , <nl> + " Override the server host which is sent in HTTP header " ) ; <nl> + DEFINE_string ( service_account_key_file , " " , <nl> + " Path to service account json key file . " ) ; <nl> + <nl> using grpc : : testing : : kTestCaseList ; <nl> using grpc : : testing : : MetricsService ; <nl> using grpc : : testing : : MetricsServiceImpl ; <nl> bool ParseTestCasesString ( const grpc : : string & test_cases , <nl> void LogParameterInfo ( const std : : vector < grpc : : string > & addresses , <nl> const std : : vector < std : : pair < TestCaseType , int > > & tests ) { <nl> gpr_log ( GPR_INFO , " server_addresses : % s " , FLAGS_server_addresses . c_str ( ) ) ; <nl> + gpr_log ( GPR_INFO , " server_host : % s " , FLAGS_server_host . c_str ( ) ) ; <nl> + gpr_log ( GPR_INFO , " server_port : % d " , FLAGS_server_port ) ; <nl> gpr_log ( GPR_INFO , " test_cases : % s " , FLAGS_test_cases . c_str ( ) ) ; <nl> gpr_log ( GPR_INFO , " sleep_duration_ms : % d " , FLAGS_sleep_duration_ms ) ; <nl> gpr_log ( GPR_INFO , " test_duration_secs : % d " , FLAGS_test_duration_secs ) ; <nl> int main ( int argc , char * * argv ) { <nl> <nl> / / Parse the server addresses <nl> std : : vector < grpc : : string > server_addresses ; <nl> - ParseCommaDelimitedString ( FLAGS_server_addresses , server_addresses ) ; <nl> + if ( FLAGS_server_port ! = 0 ) { <nl> + / / We are using interop_client style cmdline options . <nl> + const int host_port_buf_size = 1024 ; <nl> + char host_port [ host_port_buf_size ] ; <nl> + snprintf ( host_port , host_port_buf_size , " % s : % d " , FLAGS_server_host . c_str ( ) , <nl> + FLAGS_server_port ) ; <nl> + std : : string host_port_str ( host_port ) ; <nl> + ParseCommaDelimitedString ( host_port_str , server_addresses ) ; <nl> + } else { <nl> + ParseCommaDelimitedString ( FLAGS_server_addresses , server_addresses ) ; <nl> + } <nl> <nl> / / Parse test cases and weights <nl> if ( FLAGS_test_cases . length ( ) = = 0 ) { <nl> - gpr_log ( GPR_ERROR , " Not running tests . The ' test_cases ' string is empty " ) ; <nl> + / / We are using interop_client style test_case option <nl> + FLAGS_test_cases = FLAGS_test_case + " : 100 " ; <nl> + } else if ( FLAGS_test_case ! = " " ) { <nl> + gpr_log ( GPR_ERROR , " specify - - test_case or - - test_cases but not both . " ) ; <nl> return 1 ; <nl> } <nl> <nl> int main ( int argc , char * * argv ) { <nl> / / Create channel ( s ) for each server <nl> for ( int channel_idx = 0 ; channel_idx < FLAGS_num_channels_per_server ; <nl> channel_idx + + ) { <nl> - / / TODO ( sreek ) . This won ' t work for tests that require Authentication <nl> - std : : shared_ptr < grpc : : Channel > channel ( <nl> - grpc : : CreateChannel ( * it , grpc : : InsecureChannelCredentials ( ) ) ) ; <nl> + gpr_log ( GPR_INFO , " Starting test with % s channel_idx = % d . . " , it - > c_str ( ) , <nl> + channel_idx ) ; <nl> + std : : shared_ptr < grpc : : Channel > channel ; <nl> + if ( FLAGS_use_tls ) { <nl> + channel = grpc : : testing : : CreateChannelForTestCase ( FLAGS_test_case ) ; <nl> + } else { <nl> + channel = grpc : : CreateChannel ( * it , grpc : : InsecureChannelCredentials ( ) ) ; <nl> + } <nl> <nl> / / Create stub ( s ) for each channel <nl> for ( int stub_idx = 0 ; stub_idx < FLAGS_num_stubs_per_channel ; <nl> int main ( int argc , char * * argv ) { <nl> } <nl> <nl> / / Start metrics server before waiting for the stress test threads <nl> - std : : unique_ptr < grpc : : Server > metrics_server = <nl> - metrics_service . StartServer ( FLAGS_metrics_port ) ; <nl> + if ( FLAGS_metrics_port > 0 ) { <nl> + std : : unique_ptr < grpc : : Server > metrics_server = <nl> + metrics_service . StartServer ( FLAGS_metrics_port ) ; <nl> + } <nl> <nl> / / Wait for the stress test threads to complete <nl> for ( auto it = test_threads . begin ( ) ; it ! = test_threads . end ( ) ; it + + ) { <nl> mmm a / tools / run_tests / sources_and_headers . json <nl> ppp b / tools / run_tests / sources_and_headers . json <nl> <nl> " language " : " c + + " , <nl> " name " : " stress_test " , <nl> " src " : [ <nl> + " test / cpp / interop / client_helper . cc " , <nl> " test / cpp / interop / client_helper . h " , <nl> " test / cpp / interop / interop_client . cc " , <nl> " test / cpp / interop / interop_client . h " , <nl> mmm a / vsprojects / vcxproj / test / stress_test / stress_test . vcxproj <nl> ppp b / vsprojects / vcxproj / test / stress_test / stress_test . vcxproj <nl> <nl> < / ClCompile > <nl> < ClInclude Include = " $ ( SolutionDir ) \ . . \ src \ proto \ grpc \ testing \ test . grpc . pb . h " > <nl> < / ClInclude > <nl> + < ClCompile Include = " $ ( SolutionDir ) \ . . \ test \ cpp \ interop \ client_helper . cc " > <nl> + < / ClCompile > <nl> < ClCompile Include = " $ ( SolutionDir ) \ . . \ test \ cpp \ interop \ interop_client . cc " > <nl> < / ClCompile > <nl> < ClCompile Include = " $ ( SolutionDir ) \ . . \ test \ cpp \ interop \ stress_interop_client . cc " > <nl> mmm a / vsprojects / vcxproj / test / stress_test / stress_test . vcxproj . filters <nl> ppp b / vsprojects / vcxproj / test / stress_test / stress_test . vcxproj . filters <nl> <nl> < ClCompile Include = " $ ( SolutionDir ) \ . . \ src \ proto \ grpc \ testing \ test . proto " > <nl> < Filter > src \ proto \ grpc \ testing < / Filter > <nl> < / ClCompile > <nl> + < ClCompile Include = " $ ( SolutionDir ) \ . . \ test \ cpp \ interop \ client_helper . cc " > <nl> + < Filter > test \ cpp \ interop < / Filter > <nl> + < / ClCompile > <nl> < ClCompile Include = " $ ( SolutionDir ) \ . . \ test \ cpp \ interop \ interop_client . cc " > <nl> < Filter > test \ cpp \ interop < / Filter > <nl> < / ClCompile > <nl>
Merge pull request from makdharma / stress_test_options
grpc/grpc
b40a8fa95b8ede3fe35e7f07bf902cde807879b2
2016-10-25T16:30:12Z
mmm a / Examples / Image / Detection / FastRCNN / A2_RunCntk . py <nl> ppp b / Examples / Image / Detection / FastRCNN / A2_RunCntk . py <nl> <nl> # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> # Parameters <nl> # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> - cntkCmdStrPattern = " cntk . exe configFile = { 0 } configbs . cntk currentDirectory = { 0 } " <nl> + cntkCmdStrPattern = " cntk . exe configFile = { 0 } configbs . cntk currentDirectory = { 0 } { 1 } " <nl> <nl> + # cntk arguments <nl> + NumLabels = nrClasses <nl> + <nl> + NumTrainROIs = cntk_nrRois <nl> + TrainROIDim = cntk_nrRois * 4 <nl> + TrainROILabelDim = cntk_nrRois * nrClasses <nl> + <nl> + NumTestROIs = cntk_nrRois <nl> + TestROIDim = cntk_nrRois * 4 <nl> + TestROILabelDim = cntk_nrRois * nrClasses <nl> + <nl> + cntk_args = " NumLabels = { } NumTrainROIs = { } " . format ( NumLabels , NumTrainROIs ) <nl> + cntk_args + = " TrainROIDim = { } TrainROILabelDim = { } " . format ( TrainROIDim , TrainROILabelDim ) <nl> + cntk_args + = " NumTestROIs = { } " . format ( NumTestROIs ) <nl> + cntk_args + = " TestROIDim = { } TestROILabelDim = { } " . format ( TestROIDim , TestROILabelDim ) <nl> <nl> # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> # Main <nl> <nl> # run cntk <nl> tstart = datetime . datetime . now ( ) <nl> os . environ [ ' ACML_FMA ' ] = str ( 0 ) <nl> - cmdStr = cntkCmdStrPattern . format ( cntkFilesDir ) <nl> + cmdStr = cntkCmdStrPattern . format ( cntkFilesDir , cntk_args ) <nl> print cmdStr <nl> pid = subprocess . Popen ( cmdStr , cwd = cntkFilesDir ) <nl> pid . wait ( ) <nl> mmm a / Examples / Image / Detection / FastRCNN / A3_ParseAndEvaluateOutput . py <nl> ppp b / Examples / Image / Detection / FastRCNN / A3_ParseAndEvaluateOutput . py <nl> <nl> imdb = imdbs [ image_set ] <nl> net = DummyNet ( 4096 , imdb . num_classes , outParsedDir ) <nl> <nl> - # create empty directory for evaluation files <nl> + # create empty directory for evaluation files <nl> if type ( imdb ) = = imdb_data : <nl> evalTempDir = None <nl> else : <nl> <nl> makeDirectory ( evalTempDir ) <nl> deleteAllFilesInDirectory ( evalTempDir , None ) <nl> <nl> - # compute mAPs <nl> + # compute mAPs <nl> test_net ( net , imdb , evalTempDir , None , classifier , nmsThreshold , boUsePythonImpl = True ) <nl> <nl> print " DONE . " <nl> \ No newline at end of file <nl> mmm a / Examples / Image / Detection / FastRCNN / B3_VisualizeOutputROIs . py <nl> ppp b / Examples / Image / Detection / FastRCNN / B3_VisualizeOutputROIs . py <nl> <nl> locals ( ) . update ( importlib . import_module ( " PARAMETERS " ) . __dict__ ) <nl> <nl> <nl> - <nl> # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> # Parameters <nl> # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> image_set = ' test ' # ' train ' , ' test ' <nl> - svm_experimentName = ' exp1 ' <nl> - decisionThresholds = { ' svm ' : 0 , <nl> - ' nn ' : None } <nl> <nl> - # no need to change these parameters <nl> + # no need to change these parameters <nl> boUseNonMaximaSurpression = True <nl> visualizationDir = resultsDir + " visualizations " <nl> cntkParsedOutputDir = cntkFilesDir + image_set + " _parsed / " <nl> <nl> <nl> - <nl> # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> # Main <nl> # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> - # load svm <nl> - print " classifier = " + classifier <nl> makeDirectory ( resultsDir ) <nl> makeDirectory ( visualizationDir ) <nl> - if classifier = = " svm " : <nl> - print " Loading svm weights . . " <nl> - svmWeights , svmBias , svmFeatScale = loadSvm ( trainedSvmDir , svm_experimentName ) <nl> <nl> - <nl> - # loop over all images and visualize <nl> + # loop over all images and visualize <nl> imdb = imdbs [ image_set ] <nl> for imgIndex in range ( 0 , imdb . num_images ) : <nl> imgPath = imdb . image_path_at ( imgIndex ) <nl> imgWidth , imgHeight = imWidthHeight ( imgPath ) <nl> <nl> - # evaluate classifier for all rois <nl> - if classifier = = " svm " : <nl> - labels , scores = svmPredict ( imgIndex , cntkParsedOutputDir , svmWeights , svmBias , svmFeatScale , cntk_nrRois , len ( classes ) , decisionThresholds [ classifier ] ) <nl> - elif classifier = = " nn " : <nl> - labels , scores = nnPredict ( imgIndex , cntkParsedOutputDir , cntk_nrRois , len ( classes ) , decisionThresholds [ classifier ] ) <nl> - else : <nl> - ERROR <nl> + # evaluate classifier for all rois <nl> + labels , scores = nnPredict ( imgIndex , cntkParsedOutputDir , cntk_nrRois , len ( classes ) , None ) <nl> <nl> - # remove the zero - padded rois <nl> + # remove the zero - padded rois <nl> scores = scores [ : len ( imdb . roidb [ imgIndex ] [ ' boxes ' ] ) ] <nl> labels = labels [ : len ( imdb . roidb [ imgIndex ] [ ' boxes ' ] ) ] <nl> <nl> - # perform non - maxima surpression . note that the detected classes in the image is not affected by this . <nl> + # perform non - maxima surpression . note that the detected classes in the image is not affected by this . <nl> nmsKeepIndices = [ ] <nl> if boUseNonMaximaSurpression : <nl> nmsKeepIndices = applyNonMaximaSuppression ( nmsThreshold , labels , scores , imdb . roidb [ imgIndex ] [ ' boxes ' ] ) <nl> print " Non - maxima surpression kept { : 4 } of { : 4 } rois ( nmsThreshold = { } ) " . format ( len ( nmsKeepIndices ) , len ( labels ) , nmsThreshold ) <nl> <nl> - # visualize results <nl> + # visualize results <nl> imgDebug = visualizeResults ( imgPath , labels , scores , imdb . roidb [ imgIndex ] [ ' boxes ' ] , cntk_padWidth , cntk_padHeight , <nl> classes , nmsKeepIndices , boDrawNegativeRois = True ) <nl> imshow ( imgDebug , waitDuration = 0 , maxDim = 800 ) <nl> - # imwrite ( imgDebug , visualizationDir + " / " + str ( imgIndex ) + os . path . basename ( imgPath ) ) <nl> + # imwrite ( imgDebug , visualizationDir + " / " + str ( imgIndex ) + os . path . basename ( imgPath ) ) <nl> + <nl> print " DONE . " <nl> mmm a / Examples / Image / Detection / FastRCNN / PARAMETERS . py <nl> ppp b / Examples / Image / Detection / FastRCNN / PARAMETERS . py <nl> <nl> datasetName = " toy " <nl> # datasetName = " pascalVoc " <nl> # datasetName = " pascalVoc_aeroplanesOnly " <nl> - print " PARAMETERS : datasetName = " + datasetName <nl> <nl> <nl> # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> # default parameters <nl> # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # cntk params <nl> + cntk_nrRois = 500 # how many ROIs to zero - pad <nl> + cntk_padWidth = 1000 <nl> + cntk_padHeight = 1000 <nl> + cntk_posOverlapThres = { " train " : 0 . 5 , " test " : 0 . 5 } # only used for DNN training ( as opposed to svm training ) <nl> + cntk_featureDimensions = { ' svm ' : 4096 } <nl> + <nl> # directories <nl> rootDir = " C : / src / CNTK / Examples / Image / Detection / FastRCNN / " <nl> imgDir = rootDir + " data / " + datasetName + " / " <nl> - procDir = rootDir + " proc / " + datasetName + " / " <nl> - resultsDir = rootDir + " results / " + datasetName + " / " <nl> + procDir = rootDir + " proc / " + datasetName + " _ { } / " . format ( cntk_nrRois ) <nl> + resultsDir = rootDir + " results / " + datasetName + " _ { } / " . format ( cntk_nrRois ) <nl> roiDir = procDir + " rois / " <nl> cntkFilesDir = procDir + " cntkFiles / " <nl> cntkTemplateDir = rootDir <nl> <nl> - # cntk params <nl> - cntk_nrRois = 100 # how many ROIs to zero - pad <nl> - cntk_padWidth = 1000 <nl> - cntk_padHeight = 1000 <nl> - cntk_posOverlapThres = { " train " : 0 . 5 , " test " : 0 . 5 } # only used for DNN training ( as opposed to svm training ) <nl> - cntk_featureDimensions = { ' svm ' : 4096 } <nl> - <nl> # training svm params <nl> svm_C = 0 . 001 <nl> svm_B = 10 . 0 # intercept scaling <nl> svm_nrEpochs = 5 <nl> - svm_retrainLimit = 2000 <nl> + svm_retrainLimit = 500 <nl> svm_evictThreshold = - 1 . 1 <nl> svm_posWeight = " auto " # " auto " # 2 . 0 , else " balanced " <nl> svm_targetNorm = 20 . 0 # Magic value from traditional R - CNN <nl> <nl> <nl> assert cntk_padWidth = = cntk_padHeight , " ERROR : different width and height for padding currently not supported . " <nl> assert classifier . lower ( ) in [ ' svm ' , ' nn ' ] , " ERROR : only ' nn ' or ' svm ' classifier supported . " <nl> - assert not ( datasetName = = ' pascalVoc ' and classifier = = ' svm ' ) , " ERROR : while technically possibly , writing 2nd - last layer of CNTK model for all pascalVOC images takes too much disk memory . " <nl> \ No newline at end of file <nl> + assert not ( datasetName = = ' pascalVoc ' and classifier = = ' svm ' ) , " ERROR : while technically possibly , writing 2nd - last layer of CNTK model for all pascalVOC images takes too much disk memory . " <nl> + <nl> + print " PARAMETERS : datasetName = " + datasetName <nl> + print " PARAMETERS : cntk_nrRois = { } " . format ( cntk_nrRois ) <nl> mmm a / Examples / Image / Detection / FastRCNN / configbs . cntk <nl> ppp b / Examples / Image / Detection / FastRCNN / configbs . cntk <nl> ImageW = 1000 <nl> ImageC = 3 <nl> <nl> NumLabels = 22 <nl> + NumTrainROIs = 200 <nl> + NumTestROIs = 1000 <nl> <nl> - NumTrainROIs = 100 <nl> - TrainROIDim = 400 # $ NumTrainROIs $ * 4 <nl> - TrainROILabelDim = 2200 # $ NumTrainROIs $ * $ NumLabels $ <nl> - <nl> - NumTestROIs = 100 <nl> - TestROIDim = 400 <nl> - TestROILabelDim = 2200 <nl> + TrainROIDim = 800 # $ NumTrainROIs $ * 4 <nl> + TrainROILabelDim = 4400 # $ NumTrainROIs $ * $ NumLabels $ <nl> + TestROIDim = 4000 # $ NumTestROIs $ * 4 <nl> + TestROILabelDim = 22000 # $ NumTestROIs $ * $ NumLabels $ <nl> <nl> # For training we load a pretrained AlexNet model ( AlexNet . 89 ) and clone three parts of it . <nl> # For the first part ( up to pool1 ) we keep the weights fixed . The middle part contains the <nl> Train = { <nl> SGD = { <nl> epochSize = 0 <nl> minibatchSize = 2 <nl> - maxEpochs = 3 <nl> + maxEpochs = 20 <nl> <nl> - learningRatesPerSample = 0 . 0000005 <nl> - momentumAsTimeConstant = 0 <nl> - L2RegWeight = 0 . 0001 <nl> - dropoutRate = 0 . 5 <nl> + learningRatesPerSample = 0 . 00001 <nl> + momentumAsTimeConstant = 0 * 5 : 10 <nl> + # L2RegWeight = 0 . 0001 <nl> + dropoutRate = 0 <nl> <nl> numMBsToShowResult = 50 <nl> } <nl>
passing ROI params to cntk , learning rate for toy example
microsoft/CNTK
879f2d207bbcdb379b03309cf2f8daceb5daecdb
2016-10-20T21:53:01Z
mmm a / modules / gdscript / gd_tokenizer . cpp <nl> ppp b / modules / gdscript / gd_tokenizer . cpp <nl> void GDTokenizerText : : _advance ( ) { <nl> { TK_OP_AND , " and " } , <nl> / / func <nl> { TK_PR_FUNCTION , " func " } , <nl> - { TK_PR_FUNCTION , " function " } , <nl> { TK_PR_CLASS , " class " } , <nl> { TK_PR_EXTENDS , " extends " } , <nl> { TK_PR_ONREADY , " onready " } , <nl>
Removed GDScript " function " keyword
godotengine/godot
0426806ebf6642de2a122a2ac8ecb3520cd2d8a4
2016-01-13T20:59:39Z
mmm a / xbmc / PartyModeManager . cpp <nl> ppp b / xbmc / PartyModeManager . cpp <nl> void CPartyModeManager : : AddToHistory ( int type , int songID ) <nl> { <nl> while ( m_history . size ( ) > = m_songsInHistory & & m_songsInHistory ) <nl> m_history . erase ( m_history . begin ( ) ) ; <nl> - m_history . push_back ( make_pair < int , int > ( type , songID ) ) ; <nl> + m_history . push_back ( make_pair ( type , songID ) ) ; <nl> } <nl> <nl> void CPartyModeManager : : GetRandomSelection ( vector < pair < int , int > > & in , unsigned int number , vector < pair < int , int > > & out ) <nl> mmm a / xbmc / addons / AddonDatabase . cpp <nl> ppp b / xbmc / addons / AddonDatabase . cpp <nl> bool CAddonDatabase : : GetAddon ( int id , AddonPtr & addon ) <nl> m_pDS2 - > query ( sql . c_str ( ) ) ; <nl> while ( ! m_pDS2 - > eof ( ) ) <nl> { <nl> - props . dependencies . insert ( make_pair ( m_pDS2 - > fv ( 0 ) . get_asString ( ) , make_pair ( m_pDS2 - > fv ( 1 ) . get_asString ( ) , m_pDS2 - > fv ( 2 ) . get_asBool ( ) ) ) ) ; <nl> + props . dependencies . insert ( make_pair ( m_pDS2 - > fv ( 0 ) . get_asString ( ) , make_pair ( AddonVersion ( m_pDS2 - > fv ( 1 ) . get_asString ( ) ) , m_pDS2 - > fv ( 2 ) . get_asBool ( ) ) ) ) ; <nl> m_pDS2 - > next ( ) ; <nl> } <nl> <nl>
Make PartyModeManager . cpp and AddonDatabase . cpp compatible with STL from VS2012
xbmc/xbmc
bfc080e08ca2d98bd5640073006ca3a774479230
2012-08-23T11:16:50Z
mmm a / src / video_core / engines / shader_bytecode . h <nl> ppp b / src / video_core / engines / shader_bytecode . h <nl> union Instruction { <nl> BitField < 40 , 1 , R2pMode > mode ; <nl> BitField < 41 , 2 , u64 > byte ; <nl> BitField < 20 , 7 , u64 > immediate_mask ; <nl> - } r2p ; <nl> + } p2r_r2p ; <nl> <nl> union { <nl> BitField < 39 , 3 , u64 > pred39 ; <nl> class OpCode { <nl> PSET , <nl> CSETP , <nl> R2P_IMM , <nl> + P2R_IMM , <nl> XMAD_IMM , <nl> XMAD_CR , <nl> XMAD_RC , <nl> class OpCode { <nl> INST ( " 0101000010010mmm " , Id : : PSETP , Type : : PredicateSetPredicate , " PSETP " ) , <nl> INST ( " 010100001010mmm - " , Id : : CSETP , Type : : PredicateSetPredicate , " CSETP " ) , <nl> INST ( " 0011100 - 11110mmm " , Id : : R2P_IMM , Type : : RegisterSetPredicate , " R2P_IMM " ) , <nl> + INST ( " 0011100 - 11101mmm " , Id : : P2R_IMM , Type : : RegisterSetPredicate , " P2R_IMM " ) , <nl> INST ( " 0011011 - 00mmmmmm " , Id : : XMAD_IMM , Type : : Xmad , " XMAD_IMM " ) , <nl> INST ( " 0100111mmmmmmmmm " , Id : : XMAD_CR , Type : : Xmad , " XMAD_CR " ) , <nl> INST ( " 010100010mmmmmm - " , Id : : XMAD_RC , Type : : Xmad , " XMAD_RC " ) , <nl> mmm a / src / video_core / shader / decode / register_set_predicate . cpp <nl> ppp b / src / video_core / shader / decode / register_set_predicate . cpp <nl> namespace VideoCommon : : Shader { <nl> using Tegra : : Shader : : Instruction ; <nl> using Tegra : : Shader : : OpCode ; <nl> <nl> + namespace { <nl> + constexpr u64 NUM_PROGRAMMABLE_PREDICATES = 7 ; <nl> + } <nl> + <nl> u32 ShaderIR : : DecodeRegisterSetPredicate ( NodeBlock & bb , u32 pc ) { <nl> const Instruction instr = { program_code [ pc ] } ; <nl> const auto opcode = OpCode : : Decode ( instr ) ; <nl> <nl> - UNIMPLEMENTED_IF ( instr . r2p . mode ! = Tegra : : Shader : : R2pMode : : Pr ) ; <nl> + UNIMPLEMENTED_IF ( instr . p2r_r2p . mode ! = Tegra : : Shader : : R2pMode : : Pr ) ; <nl> <nl> - const Node apply_mask = [ & ] ( ) { <nl> + const Node apply_mask = [ & ] { <nl> switch ( opcode - > get ( ) . GetId ( ) ) { <nl> case OpCode : : Id : : R2P_IMM : <nl> - return Immediate ( static_cast < u32 > ( instr . r2p . immediate_mask ) ) ; <nl> + case OpCode : : Id : : P2R_IMM : <nl> + return Immediate ( static_cast < u32 > ( instr . p2r_r2p . immediate_mask ) ) ; <nl> default : <nl> UNREACHABLE ( ) ; <nl> - return Immediate ( static_cast < u32 > ( instr . r2p . immediate_mask ) ) ; <nl> + return Immediate ( 0 ) ; <nl> } <nl> } ( ) ; <nl> - const Node mask = GetRegister ( instr . gpr8 ) ; <nl> - const auto offset = static_cast < u32 > ( instr . r2p . byte ) * 8 ; <nl> <nl> - constexpr u32 programmable_preds = 7 ; <nl> - for ( u64 pred = 0 ; pred < programmable_preds ; + + pred ) { <nl> - const auto shift = static_cast < u32 > ( pred ) ; <nl> + switch ( opcode - > get ( ) . GetId ( ) ) { <nl> + case OpCode : : Id : : R2P_IMM : { <nl> + const Node mask = GetRegister ( instr . gpr8 ) ; <nl> + const auto offset = static_cast < u32 > ( instr . p2r_r2p . byte ) * 8 ; <nl> + <nl> + for ( u64 pred = 0 ; pred < NUM_PROGRAMMABLE_PREDICATES ; + + pred ) { <nl> + const auto shift = static_cast < u32 > ( pred ) ; <nl> <nl> - const Node apply_compare = BitfieldExtract ( apply_mask , shift , 1 ) ; <nl> - const Node condition = <nl> - Operation ( OperationCode : : LogicalUNotEqual , apply_compare , Immediate ( 0 ) ) ; <nl> + const Node apply_compare = BitfieldExtract ( apply_mask , shift , 1 ) ; <nl> + const Node condition = <nl> + Operation ( OperationCode : : LogicalUNotEqual , apply_compare , Immediate ( 0 ) ) ; <nl> <nl> - const Node value_compare = BitfieldExtract ( mask , offset + shift , 1 ) ; <nl> - const Node value = Operation ( OperationCode : : LogicalUNotEqual , value_compare , Immediate ( 0 ) ) ; <nl> + const Node value_compare = BitfieldExtract ( mask , offset + shift , 1 ) ; <nl> + const Node value = <nl> + Operation ( OperationCode : : LogicalUNotEqual , value_compare , Immediate ( 0 ) ) ; <nl> <nl> - const Node code = Operation ( OperationCode : : LogicalAssign , GetPredicate ( pred ) , value ) ; <nl> - bb . push_back ( Conditional ( condition , { code } ) ) ; <nl> + const Node code = Operation ( OperationCode : : LogicalAssign , GetPredicate ( pred ) , value ) ; <nl> + bb . push_back ( Conditional ( condition , { code } ) ) ; <nl> + } <nl> + break ; <nl> + } <nl> + default : <nl> + UNIMPLEMENTED_MSG ( " Unhandled P2R / R2R instruction : { } " , opcode - > get ( ) . GetName ( ) ) ; <nl> + break ; <nl> } <nl> <nl> return pc ; <nl>
shader / r2p : Refactor P2R to support P2R
yuzu-emu/yuzu
cf27b59493501787320764889a0375711c3f68e1
2019-12-20T20:55:42Z
mmm a / cmake / flags . cmake <nl> ppp b / cmake / flags . cmake <nl> if ( NOT DEFINED OSQUERY_TOOLCHAIN_SYSROOT ) <nl> endif ( ) <nl> set ( CMAKE_POSITION_INDEPENDENT_CODE ON ) <nl> <nl> + set ( CMAKE_MSVC_RUNTIME_LIBRARY " MultiThreaded $ < $ < CONFIG : Debug > : Debug > " ) <nl> + <nl> # The function creates the osquery_ < c | cxx > _settings targets with compiler and linker flags <nl> # for internal targets and < c | cxx > _settings for any other target to use as a base . <nl> # <nl>
Explicitly set the MSVC runtime library ( )
osquery/osquery
90c981a0e9a76f87f30887dba7ce6f8c65039ce1
2020-12-19T23:59:45Z
mmm a / src / common / logging / backend . cpp <nl> ppp b / src / common / logging / backend . cpp <nl> <nl> # include < algorithm > <nl> # include < array > <nl> # include < chrono > <nl> + # include < climits > <nl> # include < condition_variable > <nl> # include < memory > <nl> # include < thread > <nl> class Impl { <nl> } <nl> } ; <nl> while ( true ) { <nl> - std : : unique_lock < std : : mutex > lock ( message_mutex ) ; <nl> - message_cv . wait ( lock , [ & ] { return ! running | | message_queue . Pop ( entry ) ; } ) ; <nl> + { <nl> + std : : unique_lock < std : : mutex > lock ( message_mutex ) ; <nl> + message_cv . wait ( lock , [ & ] { return ! running | | message_queue . Pop ( entry ) ; } ) ; <nl> + } <nl> if ( ! running ) { <nl> break ; <nl> } <nl> class Impl { <nl> } <nl> / / Drain the logging queue . Only writes out up to MAX_LOGS_TO_WRITE to prevent a case <nl> / / where a system is repeatedly spamming logs even on close . <nl> - constexpr int MAX_LOGS_TO_WRITE = 100 ; <nl> + const int MAX_LOGS_TO_WRITE = filter . IsDebug ( ) ? INT_MAX : 100 ; <nl> int logs_written = 0 ; <nl> while ( logs_written + + < MAX_LOGS_TO_WRITE & & message_queue . Pop ( entry ) ) { <nl> write_logs ( entry ) ; <nl> void FmtLogMessageImpl ( Class log_class , Level log_level , const char * filename , <nl> <nl> Impl : : Instance ( ) . PushEntry ( std : : move ( entry ) ) ; <nl> } <nl> - } / / namespace Log <nl> \ No newline at end of file <nl> + } / / namespace Log <nl> mmm a / src / common / logging / filter . cpp <nl> ppp b / src / common / logging / filter . cpp <nl> bool Filter : : ParseFilterRule ( const std : : string : : const_iterator begin , <nl> bool Filter : : CheckMessage ( Class log_class , Level level ) const { <nl> return static_cast < u8 > ( level ) > = static_cast < u8 > ( class_levels [ static_cast < size_t > ( log_class ) ] ) ; <nl> } <nl> + <nl> + bool Filter : : IsDebug ( ) const { <nl> + return std : : any_of ( class_levels . begin ( ) , class_levels . end ( ) , [ ] ( const Level & l ) { <nl> + return static_cast < u8 > ( l ) < = static_cast < u8 > ( Level : : Debug ) ; <nl> + } ) ; <nl> + } <nl> + <nl> } / / namespace Log <nl> mmm a / src / common / logging / filter . h <nl> ppp b / src / common / logging / filter . h <nl> class Filter { <nl> / / / Matches class / level combination against the filter , returning true if it passed . <nl> bool CheckMessage ( Class log_class , Level level ) const ; <nl> <nl> + / / / Returns true if any logging classes are set to debug <nl> + bool IsDebug ( ) const ; <nl> + <nl> private : <nl> std : : array < Level , ( size_t ) Class : : Count > class_levels ; <nl> } ; <nl>
Merge pull request from jroweboy / logging - stuff
yuzu-emu/yuzu
04b9cde4f5a59e55ae7daac20f79121f8c7e0386
2018-07-15T19:58:52Z
mmm a / dbms / include / DB / Functions / FunctionsLogical . h <nl> ppp b / dbms / include / DB / Functions / FunctionsLogical . h <nl> class FunctionAnyArityLogical : public IFunction <nl> return true ; <nl> } <nl> <nl> - void executeUint8Other ( const UInt8Container & uint8_vec , IColumn * column , UInt8Container & res ) <nl> + void executeUInt8Other ( const UInt8Container & uint8_vec , IColumn * column , UInt8Container & res ) <nl> { <nl> if ( ! executeUInt8Type < Int8 > ( uint8_vec , column , res ) & & <nl> ! executeUInt8Type < Int16 > ( uint8_vec , column , res ) & & <nl> class FunctionAnyArityLogical : public IFunction <nl> / / / По одному добавим все столбцы неправильного типа . <nl> while ( ! other_in . empty ( ) ) <nl> { <nl> - executeUint8Other ( uint8_in [ 0 ] - > getData ( ) , other_in . back ( ) , vec_res ) ; <nl> + executeUInt8Other ( uint8_in [ 0 ] - > getData ( ) , other_in . back ( ) , vec_res ) ; <nl> other_in . pop_back ( ) ; <nl> uint8_in [ 0 ] = col_res ; <nl> } <nl>
clickhouse : fixed a typo . [ # METR - 9599 ]
ClickHouse/ClickHouse
a493d85ca941b61e81bff03c81a5f6e425b8a02b
2014-02-13T11:21:06Z
mmm a / src / x87 / builtins - x87 . cc <nl> ppp b / src / x87 / builtins - x87 . cc <nl> static void Generate_Runtime_NewObject ( MacroAssembler * masm , <nl> <nl> static void Generate_JSConstructStubHelper ( MacroAssembler * masm , <nl> bool is_api_function , <nl> + bool use_new_target , <nl> bool create_memento ) { <nl> / / mmmmmmmmm - - S t a t e mmmmmmmmmmmm - <nl> / / - - eax : number of arguments <nl> static void Generate_JSConstructStubHelper ( MacroAssembler * masm , <nl> __ push ( ebx ) ; <nl> } <nl> <nl> - / / Store a smi - tagged arguments count on the stack . <nl> + / / Preserve the incoming parameters on the stack . <nl> __ SmiTag ( eax ) ; <nl> __ push ( eax ) ; <nl> - <nl> - / / Push the function to invoke on the stack . <nl> __ push ( edi ) ; <nl> + if ( use_new_target ) { <nl> + __ push ( edx ) ; <nl> + } <nl> <nl> __ cmp ( edx , edi ) ; <nl> Label normal_new ; <nl> static void Generate_JSConstructStubHelper ( MacroAssembler * masm , <nl> __ bind ( & allocated ) ; <nl> <nl> if ( create_memento ) { <nl> - __ mov ( ecx , Operand ( esp , kPointerSize * 2 ) ) ; <nl> + int offset = ( use_new_target ? 3 : 2 ) * kPointerSize ; <nl> + __ mov ( ecx , Operand ( esp , offset ) ) ; <nl> __ cmp ( ecx , masm - > isolate ( ) - > factory ( ) - > undefined_value ( ) ) ; <nl> __ j ( equal , & count_incremented ) ; <nl> / / ecx is an AllocationSite . We are creating a memento from it , so we <nl> static void Generate_JSConstructStubHelper ( MacroAssembler * masm , <nl> __ bind ( & count_incremented ) ; <nl> } <nl> <nl> - / / Retrieve the function from the stack . <nl> - __ pop ( edi ) ; <nl> + / / Restore the parameters . <nl> + if ( use_new_target ) { <nl> + __ pop ( edx ) ; / / new . target <nl> + } <nl> + __ pop ( edi ) ; / / Constructor function . <nl> <nl> / / Retrieve smi - tagged arguments count from the stack . <nl> __ mov ( eax , Operand ( esp , 0 ) ) ; <nl> __ SmiUntag ( eax ) ; <nl> <nl> + / / Push new . target onto the construct frame . This is stored just below the <nl> + / / receiver on the stack . <nl> + if ( use_new_target ) { <nl> + __ push ( edx ) ; <nl> + } <nl> + <nl> / / Push the allocated receiver to the stack . We need two copies <nl> / / because we may have to return the original one and the calling <nl> / / conventions dictate that the called function pops the receiver . <nl> static void Generate_JSConstructStubHelper ( MacroAssembler * masm , <nl> } <nl> <nl> / / Store offset of return address for deoptimizer . <nl> - if ( ! is_api_function ) { <nl> + / / TODO ( arv ) : Remove the " ! use_new_target " before supporting optimization <nl> + / / of functions that reference new . target <nl> + if ( ! is_api_function & & ! use_new_target ) { <nl> masm - > isolate ( ) - > heap ( ) - > SetConstructStubDeoptPCOffset ( masm - > pc_offset ( ) ) ; <nl> } <nl> <nl> static void Generate_JSConstructStubHelper ( MacroAssembler * masm , <nl> __ bind ( & use_receiver ) ; <nl> __ mov ( eax , Operand ( esp , 0 ) ) ; <nl> <nl> - / / Restore the arguments count and leave the construct frame . <nl> + / / Restore the arguments count and leave the construct frame . The arguments <nl> + / / count is stored below the reciever and the new . target . <nl> __ bind ( & exit ) ; <nl> - __ mov ( ebx , Operand ( esp , kPointerSize ) ) ; / / Get arguments count . <nl> + int offset = ( use_new_target ? 2 : 1 ) * kPointerSize ; <nl> + __ mov ( ebx , Operand ( esp , offset ) ) ; <nl> <nl> / / Leave construct frame . <nl> } <nl> static void Generate_JSConstructStubHelper ( MacroAssembler * masm , <nl> <nl> <nl> void Builtins : : Generate_JSConstructStubGeneric ( MacroAssembler * masm ) { <nl> - Generate_JSConstructStubHelper ( masm , false , FLAG_pretenuring_call_new ) ; <nl> + Generate_JSConstructStubHelper ( masm , false , false , FLAG_pretenuring_call_new ) ; <nl> } <nl> <nl> <nl> void Builtins : : Generate_JSConstructStubApi ( MacroAssembler * masm ) { <nl> - Generate_JSConstructStubHelper ( masm , true , false ) ; <nl> + Generate_JSConstructStubHelper ( masm , true , false , false ) ; <nl> + } <nl> + <nl> + <nl> + void Builtins : : Generate_JSConstructStubNewTarget ( MacroAssembler * masm ) { <nl> + Generate_JSConstructStubHelper ( masm , false , true , FLAG_pretenuring_call_new ) ; <nl> } <nl> <nl> <nl>
X87 : [ es6 ] Make new . target work in functions .
v8/v8
b913e2a97ad9b268751d709de9107d4a409d9280
2015-07-01T12:05:27Z