diff
stringlengths 41
2.03M
| msg
stringlengths 1
1.5k
⌀ | repo
stringlengths 5
40
| sha
stringlengths 40
40
| time
stringlengths 20
20
|
---|---|---|---|---|
mmm a / src / embind / embind . js <nl> ppp b / src / embind / embind . js <nl> function __embind_register_class_function ( <nl> } ) ; <nl> } <nl> <nl> - function __embind_register_class_classmethod ( <nl> + function __embind_register_class_class_function ( <nl> rawClassType , <nl> methodName , <nl> argCount , <nl> mmm a / system / include / emscripten / bind . h <nl> ppp b / system / include / emscripten / bind . h <nl> namespace emscripten { <nl> size_t memberPointerSize , <nl> void * memberPointer ) ; <nl> <nl> - void _embind_register_class_classmethod ( <nl> + void _embind_register_class_class_function ( <nl> TYPEID classType , <nl> const char * methodName , <nl> unsigned argCount , <nl> namespace emscripten { <nl> . template constructor < val > ( ) <nl> ; <nl> <nl> - return classmethod ( <nl> + return class_function ( <nl> " implement " , <nl> & operator_new < WrapperType , val > , <nl> allow_raw_pointer < ret_val > ( ) ) ; <nl> namespace emscripten { <nl> } <nl> <nl> template < typename ReturnType , typename . . . Args , typename . . . Policies > <nl> - class_ & classmethod ( const char * methodName , ReturnType ( * classMethod ) ( Args . . . ) , Policies . . . ) { <nl> + class_ & class_function ( const char * methodName , ReturnType ( * classMethod ) ( Args . . . ) , Policies . . . ) { <nl> using namespace internal ; <nl> <nl> typename WithPolicies < Policies . . . > : : template ArgTypeList < ReturnType , Args . . . > args ; <nl> - _embind_register_class_classmethod ( <nl> + _embind_register_class_class_function ( <nl> TypeID < ClassType > : : get ( ) , <nl> methodName , <nl> args . count , <nl>
|
classmethod - > class_function
|
emscripten-core/emscripten
|
e698d8bbdb77dc7a3c10e2fa9f1676dee194f3ab
|
2013-04-12T11:25:24Z
|
mmm a / modules / matlab / README . md <nl> ppp b / modules / matlab / README . md <nl> Once a source file has been generated for each OpenCV definition , and type conve <nl> <nl> File layout <nl> mmmmmmmmm - - <nl> - - matlab ( this module ) <nl> - * CMakeLists . txt ( main cmake configuration file ) <nl> - * README . md ( this file ) <nl> - * compile . cmake ( the cmake help script for compiling generated source code ) <nl> - + generator ( the folder containing generator code ) <nl> - * jinja2 ( the binding templating engine ) <nl> - * filters . py ( template filters ) <nl> - * gen_matlab . py ( the binding generator control script ) <nl> - * parse_tree . py ( python class to refactor the hdr_parser . py output ) <nl> - * templates ( the raw templates for populating classes , constants , functions and docs ) <nl> - * include ( C + + headers for the bindings ) <nl> - + mxarray . hpp ( C + + OOP - style interface for Matlab mxArray * class ) <nl> - + bridge . hpp ( type conversions ) <nl> - + map . hpp ( hash map interface for instance storage and method lookup ) <nl> - * io ( FileStorage interface for . mat files ) <nl> - * test ( generator , compiler and binding test scripts ) <nl> + matlab ( this module ) <nl> + <nl> + - CMakeLists . txt ( main cmake configuration file ) <nl> + - README . md ( this file ) <nl> + - compile . cmake ( the cmake help script for compiling generated source code ) <nl> + - generator ( the folder containing generator code ) <nl> + * jinja2 ( the binding templating engine ) <nl> + * filters . py ( template filters ) <nl> + * gen_matlab . py ( the binding generator control script ) <nl> + * parse_tree . py ( python class to refactor the hdr_parser . py output ) <nl> + * templates ( the raw templates for populating classes , constants , functions and docs ) <nl> + - include ( C + + headers for the bindings ) <nl> + * mxarray . hpp ( C + + OOP - style interface for Matlab mxArray * class ) <nl> + * bridge . hpp ( type conversions ) <nl> + * map . hpp ( hash map interface for instance storage and method lookup ) <nl> + - io ( FileStorage interface for . mat files ) <nl> + - test ( generator , compiler and binding test scripts ) <nl> <nl> <nl> Call Tree <nl>
|
Updated nest list in markdown
|
opencv/opencv
|
a269e3216eb11f325cea774b4f316e23a868b113
|
2013-08-11T04:46:28Z
|
mmm a / tensorflow / python / eager / pywrap_tensor . cc <nl> ppp b / tensorflow / python / eager / pywrap_tensor . cc <nl> limitations under the License . <nl> # include " tensorflow / python / eager / pywrap_tensor . h " <nl> <nl> # include < stdlib . h > <nl> + # include < string . h > <nl> <nl> # include " structmember . h " / / NOLINT / / For PyMemberDef <nl> # include " tensorflow / c / c_api . h " <nl> TFE_TensorHandle * ConvertToEagerTensorUncached ( TFE_Context * ctx , <nl> / / The approximation is not exact there are GPU kernels which do not require <nl> / / host memory for int32 tensors . This will lead to a discrepancy between <nl> / / eager and graph execution . <nl> + / / <nl> + / / To support remote execution copy int32 tensors to another CPU device . <nl> / / TODO ( ashankar ) : Fix this . <nl> if ( device_name ! = nullptr & & <nl> - TFE_TensorHandleDataType ( handle . get ( ) ) ! = TF_INT32 ) { <nl> + ( TFE_TensorHandleDataType ( handle . get ( ) ) ! = TF_INT32 | | <nl> + strstr ( device_name , " / device : CPU : 0 " ) ! = nullptr ) ) { <nl> / / Note that this is a shallow copy and will share the underlying buffer <nl> / / if copying to the same device . <nl> handle = make_safe ( TFE_TensorHandleCopyToDevice ( handle . get ( ) , ctx , <nl>
|
Automated rollback of commit 82d14d084e3b234ad947aa5ee98ca362b482dcde
|
tensorflow/tensorflow
|
f4a5155d72fab82075090757852eeb44bab7b58f
|
2019-08-08T19:29:40Z
|
mmm a / MavLinkCom / src / serial_com / UdpClientPort . cpp <nl> ppp b / MavLinkCom / src / serial_com / UdpClientPort . cpp <nl> class UdpClientPort : : UdpSocketImpl <nl> } <nl> <nl> socklen_t addrlen = sizeof ( sockaddr_in ) ; <nl> + # if defined ( __APPLE__ ) <nl> + int hr = : : write ( sock , reinterpret_cast < const char * > ( ptr ) , count ) ; <nl> + # else <nl> int hr = sendto ( sock , reinterpret_cast < const char * > ( ptr ) , count , 0 , reinterpret_cast < sockaddr * > ( & remoteaddr ) , addrlen ) ; <nl> + # endif <nl> if ( hr = = SOCKET_ERROR ) <nl> { <nl> hr = WSAGetLastError ( ) ; <nl> class UdpClientPort : : UdpSocketImpl <nl> <nl> int bytesRead = 0 ; <nl> / / try and receive something , up until port is closed anyway . <nl> - <nl> + <nl> while ( ! closed_ ) <nl> { <nl> socklen_t addrlen = sizeof ( sockaddr_in ) ; <nl> + # if defined ( __APPLE__ ) <nl> + int rc = : : read ( sock , reinterpret_cast < char * > ( result ) , bytesToRead ) ; <nl> + # else <nl> int rc = recvfrom ( sock , reinterpret_cast < char * > ( result ) , bytesToRead , 0 , reinterpret_cast < sockaddr * > ( & other ) , & addrlen ) ; <nl> + # endif <nl> if ( rc < 0 ) <nl> { <nl> int hr = WSAGetLastError ( ) ; <nl> # ifdef _WIN32 <nl> if ( hr = = WSAEMSGSIZE ) <nl> { <nl> - / / message was too large for the buffer , no problem , return what we have . <nl> + / / message was too large for the buffer , no problem , return what we have . <nl> } <nl> else if ( hr = = WSAECONNRESET | | hr = = ERROR_IO_PENDING ) <nl> { <nl>
|
Merge pull request from nacho - carnicero / OSX_UDP_socket_fix
|
microsoft/AirSim
|
6458eaf44aff5a802d9953457e06b0734f16d6b9
|
2017-06-02T12:02:32Z
|
mmm a / TMessagesProj / src / main / java / org / telegram / messenger / MediaController . java <nl> ppp b / TMessagesProj / src / main / java / org / telegram / messenger / MediaController . java <nl> private boolean convertVideo ( final MessageObject messageObject ) { <nl> outputFormat . setInteger ( MediaFormat . KEY_BIT_RATE , bitrate > 0 ? bitrate : 921600 ) ; <nl> outputFormat . setInteger ( MediaFormat . KEY_FRAME_RATE , framerate ! = 0 ? framerate : 25 ) ; <nl> outputFormat . setInteger ( MediaFormat . KEY_I_FRAME_INTERVAL , 10 ) ; <nl> - if ( Build . VERSION . SDK_INT > = 21 ) { <nl> + / * if ( Build . VERSION . SDK_INT > = 21 ) { <nl> outputFormat . setInteger ( MediaFormat . KEY_PROFILE , MediaCodecInfo . CodecProfileLevel . AVCProfileHigh ) ; <nl> if ( Build . VERSION . SDK_INT > = 23 ) { <nl> outputFormat . setInteger ( MediaFormat . KEY_LEVEL , MediaCodecInfo . CodecProfileLevel . AVCLevel5 ) ; <nl> } <nl> - } <nl> + } * / <nl> if ( Build . VERSION . SDK_INT < 18 ) { <nl> outputFormat . setInteger ( " stride " , resultWidth + 32 ) ; <nl> outputFormat . setInteger ( " slice - height " , resultHeight ) ; <nl> mmm a / TMessagesProj / src / main / java / org / telegram / ui / BlockedUsersActivity . java <nl> ppp b / TMessagesProj / src / main / java / org / telegram / ui / BlockedUsersActivity . java <nl> public void onItemClick ( int id ) { <nl> return ; <nl> } <nl> Bundle args = new Bundle ( ) ; <nl> - args . putInt ( " user_id " , MessagesController . getInstance ( currentAccount ) . blockedUsers . get ( position ) ) ; <nl> + args . putInt ( " user_id " , MessagesController . getInstance ( currentAccount ) . blockedUsers . keyAt ( position ) ) ; <nl> presentFragment ( new ProfileActivity ( args ) ) ; <nl> } ) ; <nl> <nl> public void onItemClick ( int id ) { <nl> if ( position > = MessagesController . getInstance ( currentAccount ) . blockedUsers . size ( ) | | getParentActivity ( ) = = null ) { <nl> return true ; <nl> } <nl> - selectedUserId = MessagesController . getInstance ( currentAccount ) . blockedUsers . get ( position ) ; <nl> + selectedUserId = MessagesController . getInstance ( currentAccount ) . blockedUsers . keyAt ( position ) ; <nl> <nl> AlertDialog . Builder builder = new AlertDialog . Builder ( getParentActivity ( ) ) ; <nl> CharSequence [ ] items = new CharSequence [ ] { LocaleController . getString ( " Unblock " , R . string . Unblock ) } ; <nl> public boolean isEnabled ( RecyclerView . ViewHolder holder ) { <nl> @ Override <nl> public void onBindViewHolder ( RecyclerView . ViewHolder holder , int position ) { <nl> if ( holder . getItemViewType ( ) = = 0 ) { <nl> - TLRPC . User user = MessagesController . getInstance ( currentAccount ) . getUser ( MessagesController . getInstance ( currentAccount ) . blockedUsers . get ( position ) ) ; <nl> + TLRPC . User user = MessagesController . getInstance ( currentAccount ) . getUser ( MessagesController . getInstance ( currentAccount ) . blockedUsers . keyAt ( position ) ) ; <nl> if ( user ! = null ) { <nl> String number ; <nl> if ( user . bot ) { <nl> mmm a / TMessagesProj / src / main / java / org / telegram / ui / Components / InstantCameraView . java <nl> ppp b / TMessagesProj / src / main / java / org / telegram / ui / Components / InstantCameraView . java <nl> private void prepareEncoder ( ) { <nl> format . setInteger ( MediaFormat . KEY_BIT_RATE , videoBitrate ) ; <nl> format . setInteger ( MediaFormat . KEY_FRAME_RATE , FRAME_RATE ) ; <nl> format . setInteger ( MediaFormat . KEY_I_FRAME_INTERVAL , IFRAME_INTERVAL ) ; <nl> - if ( Build . VERSION . SDK_INT > = 21 ) { <nl> + / * if ( Build . VERSION . SDK_INT > = 21 ) { <nl> format . setInteger ( MediaFormat . KEY_PROFILE , MediaCodecInfo . CodecProfileLevel . AVCProfileHigh ) ; <nl> if ( Build . VERSION . SDK_INT > = 23 ) { <nl> format . setInteger ( MediaFormat . KEY_LEVEL , MediaCodecInfo . CodecProfileLevel . AVCLevel5 ) ; <nl> } <nl> - } <nl> + } * / <nl> <nl> videoEncoder . configure ( format , null , null , MediaCodec . CONFIGURE_FLAG_ENCODE ) ; <nl> surface = videoEncoder . createInputSurface ( ) ; <nl>
|
Bug fixes
|
DrKLO/Telegram
|
5972d1d69f71e097c8f51bf60c8f3845965acf9a
|
2018-08-27T18:45:56Z
|
mmm a / src / objective - c / tests / Podfile <nl> ppp b / src / objective - c / tests / Podfile <nl> GRPC_LOCAL_SRC = ' . . / . . / . . ' <nl> ) . each do | target_name | <nl> target target_name do <nl> pod ' Protobuf ' , : path = > " # { GRPC_LOCAL_SRC } / third_party / protobuf " , : inhibit_warnings = > true <nl> - pod ' ! ProtoCompiler ' , : path = > " # { GRPC_LOCAL_SRC } / src / objective - c " <nl> + <nl> + pod ' ! ProtoCompiler ' , : path = > " # { GRPC_LOCAL_SRC } / src / objective - c " <nl> pod ' ! ProtoCompiler - gRPCPlugin ' , : path = > " # { GRPC_LOCAL_SRC } / src / objective - c " <nl> - pod ' BoringSSL ' , : podspec = > " # { GRPC_LOCAL_SRC } / src / objective - c " , : inhibit_warnings = > true <nl> + <nl> + pod ' BoringSSL ' , : podspec = > " # { GRPC_LOCAL_SRC } / src / objective - c " , : inhibit_warnings = > true <nl> pod ' CronetFramework ' , : podspec = > " # { GRPC_LOCAL_SRC } / src / objective - c " <nl> - pod ' gRPC ' , : path = > GRPC_LOCAL_SRC <nl> - pod ' gRPC - Core ' , : path = > GRPC_LOCAL_SRC <nl> + <nl> + pod ' gRPC ' , : path = > GRPC_LOCAL_SRC <nl> + pod ' gRPC - Core ' , : path = > GRPC_LOCAL_SRC <nl> pod ' gRPC - RxLibrary ' , : path = > GRPC_LOCAL_SRC <nl> pod ' gRPC - ProtoRPC ' , : path = > GRPC_LOCAL_SRC <nl> + <nl> pod ' RemoteTest ' , : path = > " RemoteTestClient " <nl> end <nl> end <nl>
|
Tests Podfile cleanup
|
grpc/grpc
|
54e28ad79e7aabccb5ed2d1361f1523d76d6f285
|
2016-07-11T18:10:26Z
|
mmm a / doc / readme - qt . rst <nl> ppp b / doc / readme - qt . rst <nl> and 4 . X cannot open the new format . This means that you cannot go back to the ol <nl> significant hassle ! <nl> <nl> . . _ ` this Debian issue ` : http : / / bugs . debian . org / cgi - bin / bugreport . cgi ? bug = 621425 <nl> + <nl> + Ubuntu 11 . 10 warning <nl> + = = = = = = = = = = = = = = = = = = = = <nl> + <nl> + Ubuntu 11 . 10 has a package called ' qt - at - spi ' installed by default . At the time of writing , having that package <nl> + installed causes bitcoin - qt to crash intermittently . The issue has been reported as ` launchpad bug 857790 ` _ , but <nl> + isn ' t yet fixed . <nl> + <nl> + Until the bug is fixed , you can remove the qt - at - spi package to work around the problem , though this will presumably <nl> + disable screen reader functionality for Qt apps : <nl> + <nl> + : : <nl> + <nl> + sudo apt - get remove qt - at - spi <nl> + <nl> + . . _ ` launchpad bug 857790 ` : https : / / bugs . launchpad . net / ubuntu / + source / qt - at - spi / + bug / 857790 <nl>
|
Warn about the qt - at - spi bug in Ubuntu 11 . 10 .
|
bitcoin/bitcoin
|
6c33ec404530419ef78d075be92cf0408323bf84
|
2011-10-25T03:38:46Z
|
mmm a / CMakeLists . txt <nl> ppp b / CMakeLists . txt <nl> set ( SOURCES <nl> cache / lru_cache . cc <nl> cache / sharded_cache . cc <nl> db / arena_wrapped_db_iter . cc <nl> - db / blob_file_addition . cc <nl> - db / blob_file_garbage . cc <nl> + db / blob / blob_file_addition . cc <nl> + db / blob / blob_file_garbage . cc <nl> db / builder . cc <nl> db / c . cc <nl> db / column_family . cc <nl> if ( WITH_TESTS ) <nl> set ( TESTS <nl> cache / cache_test . cc <nl> cache / lru_cache_test . cc <nl> - db / blob_file_addition_test . cc <nl> - db / blob_file_garbage_test . cc <nl> + db / blob / blob_file_addition_test . cc <nl> + db / blob / blob_file_garbage_test . cc <nl> + db / blob / db_blob_index_test . cc <nl> db / column_family_test . cc <nl> db / compact_files_test . cc <nl> db / compaction / compaction_job_stats_test . cc <nl> if ( WITH_TESTS ) <nl> db / corruption_test . cc <nl> db / cuckoo_table_db_test . cc <nl> db / db_basic_test . cc <nl> - db / db_blob_index_test . cc <nl> db / db_block_cache_test . cc <nl> db / db_bloom_filter_test . cc <nl> db / db_compaction_filter_test . cc <nl> mmm a / Makefile <nl> ppp b / Makefile <nl> db_test2 : db / db_test2 . o db / db_test_util . o $ ( LIBOBJECTS ) $ ( TESTHARNESS ) <nl> db_logical_block_size_cache_test : db / db_logical_block_size_cache_test . o db / db_test_util . o $ ( LIBOBJECTS ) $ ( TESTHARNESS ) <nl> $ ( AM_LINK ) <nl> <nl> - db_blob_index_test : db / db_blob_index_test . o db / db_test_util . o $ ( LIBOBJECTS ) $ ( TESTHARNESS ) <nl> + db_blob_index_test : db / blob / db_blob_index_test . o db / db_test_util . o $ ( LIBOBJECTS ) $ ( TESTHARNESS ) <nl> $ ( AM_LINK ) <nl> <nl> db_block_cache_test : db / db_block_cache_test . o db / db_test_util . o $ ( LIBOBJECTS ) $ ( TESTHARNESS ) <nl> block_cache_trace_analyzer_test : tools / block_cache_analyzer / block_cache_trace_an <nl> defer_test : util / defer_test . o $ ( LIBOBJECTS ) $ ( TESTHARNESS ) <nl> $ ( AM_LINK ) <nl> <nl> - blob_file_addition_test : db / blob_file_addition_test . o $ ( LIBOBJECTS ) $ ( TESTHARNESS ) <nl> + blob_file_addition_test : db / blob / blob_file_addition_test . o $ ( LIBOBJECTS ) $ ( TESTHARNESS ) <nl> $ ( AM_LINK ) <nl> <nl> - blob_file_garbage_test : db / blob_file_garbage_test . o $ ( LIBOBJECTS ) $ ( TESTHARNESS ) <nl> + blob_file_garbage_test : db / blob / blob_file_garbage_test . o $ ( LIBOBJECTS ) $ ( TESTHARNESS ) <nl> $ ( AM_LINK ) <nl> <nl> # mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> mmm a / TARGETS <nl> ppp b / TARGETS <nl> cpp_library ( <nl> " cache / lru_cache . cc " , <nl> " cache / sharded_cache . cc " , <nl> " db / arena_wrapped_db_iter . cc " , <nl> - " db / blob_file_addition . cc " , <nl> - " db / blob_file_garbage . cc " , <nl> + " db / blob / blob_file_addition . cc " , <nl> + " db / blob / blob_file_garbage . cc " , <nl> " db / builder . cc " , <nl> " db / c . cc " , <nl> " db / column_family . cc " , <nl> ROCKS_TESTS = [ <nl> ] , <nl> [ <nl> " blob_file_addition_test " , <nl> - " db / blob_file_addition_test . cc " , <nl> + " db / blob / blob_file_addition_test . cc " , <nl> " serial " , <nl> [ ] , <nl> [ ] , <nl> ] , <nl> [ <nl> " blob_file_garbage_test " , <nl> - " db / blob_file_garbage_test . cc " , <nl> + " db / blob / blob_file_garbage_test . cc " , <nl> " serial " , <nl> [ ] , <nl> [ ] , <nl> ROCKS_TESTS = [ <nl> ] , <nl> [ <nl> " db_blob_index_test " , <nl> - " db / db_blob_index_test . cc " , <nl> + " db / blob / db_blob_index_test . cc " , <nl> " serial " , <nl> [ ] , <nl> [ ] , <nl> similarity index 100 % <nl> rename from db / blob_constants . h <nl> rename to db / blob / blob_constants . h <nl> similarity index 99 % <nl> rename from db / blob_file_addition . cc <nl> rename to db / blob / blob_file_addition . cc <nl> mmm a / db / blob_file_addition . cc <nl> ppp b / db / blob / blob_file_addition . cc <nl> <nl> / / COPYING file in the root directory ) and Apache 2 . 0 License <nl> / / ( found in the LICENSE . Apache file in the root directory ) . <nl> <nl> - # include " db / blob_file_addition . h " <nl> + # include " db / blob / blob_file_addition . h " <nl> <nl> # include < ostream > <nl> # include < sstream > <nl> similarity index 98 % <nl> rename from db / blob_file_addition . h <nl> rename to db / blob / blob_file_addition . h <nl> mmm a / db / blob_file_addition . h <nl> ppp b / db / blob / blob_file_addition . h <nl> <nl> # include < iosfwd > <nl> # include < string > <nl> <nl> - # include " db / blob_constants . h " <nl> + # include " db / blob / blob_constants . h " <nl> # include " rocksdb / rocksdb_namespace . h " <nl> <nl> namespace ROCKSDB_NAMESPACE { <nl> similarity index 99 % <nl> rename from db / blob_file_addition_test . cc <nl> rename to db / blob / blob_file_addition_test . cc <nl> mmm a / db / blob_file_addition_test . cc <nl> ppp b / db / blob / blob_file_addition_test . cc <nl> <nl> / / COPYING file in the root directory ) and Apache 2 . 0 License <nl> / / ( found in the LICENSE . Apache file in the root directory ) . <nl> <nl> - # include " db / blob_file_addition . h " <nl> + # include " db / blob / blob_file_addition . h " <nl> <nl> # include < cstdint > <nl> # include < cstring > <nl> similarity index 99 % <nl> rename from db / blob_file_garbage . cc <nl> rename to db / blob / blob_file_garbage . cc <nl> mmm a / db / blob_file_garbage . cc <nl> ppp b / db / blob / blob_file_garbage . cc <nl> <nl> / / COPYING file in the root directory ) and Apache 2 . 0 License <nl> / / ( found in the LICENSE . Apache file in the root directory ) . <nl> <nl> - # include " db / blob_file_garbage . h " <nl> + # include " db / blob / blob_file_garbage . h " <nl> <nl> # include < ostream > <nl> # include < sstream > <nl> similarity index 97 % <nl> rename from db / blob_file_garbage . h <nl> rename to db / blob / blob_file_garbage . h <nl> mmm a / db / blob_file_garbage . h <nl> ppp b / db / blob / blob_file_garbage . h <nl> <nl> # include < iosfwd > <nl> # include < string > <nl> <nl> - # include " db / blob_constants . h " <nl> + # include " db / blob / blob_constants . h " <nl> # include " rocksdb / rocksdb_namespace . h " <nl> <nl> namespace ROCKSDB_NAMESPACE { <nl> similarity index 99 % <nl> rename from db / blob_file_garbage_test . cc <nl> rename to db / blob / blob_file_garbage_test . cc <nl> mmm a / db / blob_file_garbage_test . cc <nl> ppp b / db / blob / blob_file_garbage_test . cc <nl> <nl> / / COPYING file in the root directory ) and Apache 2 . 0 License <nl> / / ( found in the LICENSE . Apache file in the root directory ) . <nl> <nl> - # include " db / blob_file_garbage . h " <nl> + # include " db / blob / blob_file_garbage . h " <nl> <nl> # include < cstdint > <nl> # include < cstring > <nl> similarity index 100 % <nl> rename from db / blob_index . h <nl> rename to db / blob / blob_index . h <nl> similarity index 100 % <nl> rename from db / db_blob_index_test . cc <nl> rename to db / blob / db_blob_index_test . cc <nl> mmm a / db / compaction / compaction_job_test . cc <nl> ppp b / db / compaction / compaction_job_test . cc <nl> <nl> # include < string > <nl> # include < tuple > <nl> <nl> - # include " db / blob_index . h " <nl> + # include " db / blob / blob_index . h " <nl> # include " db / column_family . h " <nl> # include " db / compaction / compaction_job . h " <nl> # include " db / db_impl / db_impl . h " <nl> mmm a / db / db_test . cc <nl> ppp b / db / db_test . cc <nl> <nl> # endif <nl> <nl> # include " cache / lru_cache . h " <nl> - # include " db / blob_index . h " <nl> + # include " db / blob / blob_index . h " <nl> # include " db / db_impl / db_impl . h " <nl> # include " db / db_test_util . h " <nl> # include " db / dbformat . h " <nl> mmm a / db / flush_job_test . cc <nl> ppp b / db / flush_job_test . cc <nl> <nl> # include < map > <nl> # include < string > <nl> <nl> - # include " db / blob_index . h " <nl> + # include " db / blob / blob_index . h " <nl> # include " db / column_family . h " <nl> # include " db / db_impl / db_impl . h " <nl> # include " db / flush_job . h " <nl> mmm a / db / listener_test . cc <nl> ppp b / db / listener_test . cc <nl> <nl> / / COPYING file in the root directory ) and Apache 2 . 0 License <nl> / / ( found in the LICENSE . Apache file in the root directory ) . <nl> <nl> - # include " db / blob_index . h " <nl> + # include " db / blob / blob_index . h " <nl> # include " db / db_impl / db_impl . h " <nl> # include " db / db_test_util . h " <nl> # include " db / dbformat . h " <nl> mmm a / db / version_edit . cc <nl> ppp b / db / version_edit . cc <nl> <nl> <nl> # include " db / version_edit . h " <nl> <nl> - # include " db / blob_index . h " <nl> + # include " db / blob / blob_index . h " <nl> # include " db / version_set . h " <nl> # include " logging / event_logger . h " <nl> # include " rocksdb / slice . h " <nl> mmm a / db / version_edit . h <nl> ppp b / db / version_edit . h <nl> <nl> # include < string > <nl> # include < utility > <nl> # include < vector > <nl> - # include " db / blob_file_addition . h " <nl> - # include " db / blob_file_garbage . h " <nl> + # include " db / blob / blob_file_addition . h " <nl> + # include " db / blob / blob_file_garbage . h " <nl> # include " db / dbformat . h " <nl> # include " memory / arena . h " <nl> # include " rocksdb / cache . h " <nl> mmm a / src . mk <nl> ppp b / src . mk <nl> LIB_SOURCES = \ <nl> cache / lru_cache . cc \ <nl> cache / sharded_cache . cc \ <nl> db / arena_wrapped_db_iter . cc \ <nl> - db / blob_file_addition . cc \ <nl> - db / blob_file_garbage . cc \ <nl> + db / blob / blob_file_addition . cc \ <nl> + db / blob / blob_file_garbage . cc \ <nl> db / builder . cc \ <nl> db / c . cc \ <nl> db / column_family . cc \ <nl> MAIN_SOURCES = \ <nl> cache / cache_bench . cc \ <nl> cache / cache_test . cc \ <nl> db_stress_tool / db_stress . cc \ <nl> - db / blob_file_addition_test . cc \ <nl> - db / blob_file_garbage_test . cc \ <nl> + db / blob / blob_file_addition_test . cc \ <nl> + db / blob / blob_file_garbage_test . cc \ <nl> + db / blob / db_blob_index_test . cc \ <nl> db / column_family_test . cc \ <nl> db / compact_files_test . cc \ <nl> db / compaction / compaction_iterator_test . cc \ <nl> MAIN_SOURCES = \ <nl> db / corruption_test . cc \ <nl> db / cuckoo_table_db_test . cc \ <nl> db / db_basic_test . cc \ <nl> - db / db_blob_index_test . cc \ <nl> db / db_block_cache_test . cc \ <nl> db / db_bloom_filter_test . cc \ <nl> db / db_compaction_filter_test . cc \ <nl> mmm a / tools / sst_dump_tool . cc <nl> ppp b / tools / sst_dump_tool . cc <nl> <nl> # include < sstream > <nl> # include < vector > <nl> <nl> - # include " db / blob_index . h " <nl> + # include " db / blob / blob_index . h " <nl> # include " db / memtable . h " <nl> # include " db / write_batch_internal . h " <nl> # include " env / composite_env_wrapper . h " <nl> mmm a / utilities / blob_db / blob_compaction_filter . h <nl> ppp b / utilities / blob_db / blob_compaction_filter . h <nl> <nl> <nl> # include < unordered_set > <nl> <nl> - # include " db / blob_index . h " <nl> + # include " db / blob / blob_index . h " <nl> # include " monitoring / statistics . h " <nl> # include " rocksdb / compaction_filter . h " <nl> # include " rocksdb / env . h " <nl> mmm a / utilities / blob_db / blob_db_impl . cc <nl> ppp b / utilities / blob_db / blob_db_impl . cc <nl> <nl> # include < memory > <nl> # include < sstream > <nl> <nl> - # include " db / blob_index . h " <nl> + # include " db / blob / blob_index . h " <nl> # include " db / db_impl / db_impl . h " <nl> # include " db / write_batch_internal . h " <nl> # include " env / composite_env_wrapper . h " <nl> mmm a / utilities / blob_db / blob_db_test . cc <nl> ppp b / utilities / blob_db / blob_db_test . cc <nl> <nl> # include < string > <nl> # include < vector > <nl> <nl> - # include " db / blob_index . h " <nl> + # include " db / blob / blob_index . h " <nl> # include " db / db_test_util . h " <nl> # include " env / composite_env_wrapper . h " <nl> # include " file / file_util . h " <nl>
|
Move BlobDB related files under db / to db / blob / ( )
|
facebook/rocksdb
|
c15e85bdcb5480517674c58ae16a9f3ff58b2265
|
2020-03-12T18:00:56Z
|
Binary files a / tools / windows / packaging / uwp / kodi_temp_key . pfx and b / tools / windows / packaging / uwp / kodi_temp_key . pfx differ <nl>
|
Merge pull request from pkerling / new - uwp - key
|
xbmc/xbmc
|
196e418b357b588f393b16bd403721abc907cc29
|
2018-12-20T13:06:28Z
|
mmm a / tools / dump . cpp <nl> ppp b / tools / dump . cpp <nl> class Dump : public Tool { <nl> FILE * _f ; <nl> } ; <nl> public : <nl> - Dump ( ) : Tool ( " dump " , ALL , " * " , " * " , false ) { <nl> + Dump ( ) : Tool ( " dump " , ALL , " * " , " * " , true ) { <nl> add_options ( ) <nl> ( " out , o " , po : : value < string > ( ) - > default_value ( " dump " ) , " output directory or \ " - \ " for stdout " ) <nl> ( " query , q " , po : : value < string > ( ) , " json query " ) <nl> class Dump : public Tool { <nl> ; <nl> } <nl> <nl> + virtual void preSetup ( ) { <nl> + string out = getParam ( " out " ) ; <nl> + if ( out = = " - " ) { <nl> + / / write output to standard error to avoid mangling output <nl> + / / must happen early to avoid sending junk to stdout <nl> + useStandardOutput ( false ) ; <nl> + } <nl> + } <nl> + <nl> virtual void printExtraHelp ( ostream & out ) { <nl> out < < " Export MongoDB data to BSON files . \ n " < < endl ; <nl> } <nl>
|
CS - 1535 : Avoid writing to stderr unless dumping to stdout
|
mongodb/mongo
|
1ffc5fd9e578ce5a9c58d04ae7f909cc2241d0f4
|
2011-10-28T20:28:55Z
|
mmm a / doc / base / classes . xml <nl> ppp b / doc / base / classes . xml <nl> This method controls whether the position between two cached points is interpola <nl> < return type = " Vector3 " > <nl> < / return > <nl> < description > <nl> - Returns the vehicle body speed or velocity in a 3D vector , to get the speed in scalar value <nl> - get the length of the return vector , the scalar value is in Godot units / seconds , if you <nl> - assume 1 . 0 is a meter , then it is in meters / sec <nl> - Example : <nl> - # vehicle is an instance of VehicleBody , 1 . 0 asumed as 1 meter : <nl> - var speed_ms = vehicle . get_linear_velocity ( ) . length ( ) <nl> - # Lets convert it to Km / h : <nl> - var speed_kms = speed_ms * 3 . 6 <nl> - < / description > <nl> - < / method > <nl> + Returns the VehicleBody ' s velocity vector . To get the absolute speed in scalar value , get the length of the return vector in pixels / second . Example : <nl> + [ codeblock ] <nl> + # vehicle is an instance of VehicleBody <nl> + var speed = vehicle . get_linear_velocity ( ) . length ( ) <nl> + [ / codeblock ] <nl> + < / description > <nl> + < / method > <nl> < / methods > <nl> < constants > <nl> < / constants > <nl> mmm a / scene / 3d / vehicle_body . cpp <nl> ppp b / scene / 3d / vehicle_body . cpp <nl> float VehicleBody : : get_steering ( ) const { <nl> <nl> Vector3 VehicleBody : : get_linear_velocity ( ) <nl> { <nl> - return linear_velocity ; <nl> + return linear_velocity ; <nl> } <nl> <nl> void VehicleBody : : _bind_methods ( ) { <nl> mmm a / scene / 3d / vehicle_body . h <nl> ppp b / scene / 3d / vehicle_body . h <nl> friend class VehicleWheel ; <nl> <nl> void set_steering ( float p_steering ) ; <nl> float get_steering ( ) const ; <nl> - <nl> + <nl> Vector3 get_linear_velocity ( ) ; <nl> <nl> VehicleBody ( ) ; <nl>
|
VehicleBody : Cosmetic fixes to previous commit
|
godotengine/godot
|
da24bc8f3fa5bb00deb7042b63794f4218dee774
|
2016-05-21T09:52:21Z
|
mmm a / editor / editor_properties_array_dict . cpp <nl> ppp b / editor / editor_properties_array_dict . cpp <nl> void EditorPropertyArray : : update_property ( ) { <nl> vbox - > add_child ( hb ) ; <nl> hb - > add_child ( prop ) ; <nl> prop - > set_h_size_flags ( SIZE_EXPAND_FILL ) ; <nl> - Button * edit = memnew ( Button ) ; <nl> - edit - > set_icon ( get_icon ( " Edit " , " EditorIcons " ) ) ; <nl> - hb - > add_child ( edit ) ; <nl> - edit - > connect ( " pressed " , this , " _change_type " , varray ( edit , i + offset ) ) ; <nl> + <nl> + if ( subtype = = Variant : : NIL ) { <nl> + Button * edit = memnew ( Button ) ; <nl> + edit - > set_icon ( get_icon ( " Edit " , " EditorIcons " ) ) ; <nl> + hb - > add_child ( edit ) ; <nl> + edit - > connect ( " pressed " , this , " _change_type " , varray ( edit , i + offset ) ) ; <nl> + } <nl> + <nl> } else { <nl> vbox - > add_child ( prop ) ; <nl> } <nl>
|
Add static types to arrays ( inspector fix )
|
godotengine/godot
|
f9788f75e59b9e7d9d056faaa13f399736830381
|
2019-01-11T13:31:08Z
|
mmm a / . circleci / config . yml <nl> ppp b / . circleci / config . yml <nl> commands : <nl> - run : <nl> name : embuilder ( LTO ) <nl> command : | <nl> - python3 . / embuilder . py build libcompiler_rt libc libc + + abi libc + + libc + + - noexcept libal libdlmalloc libpthreads_stub libcompiler_rt_wasm libc_rt_wasm struct_info libc - wasm - - lto <nl> + python3 . / embuilder . py build libcompiler_rt libc libc + + abi libc + + abi - noexcept libc + + libc + + - noexcept libal libdlmalloc libpthreads_stub libcompiler_rt_wasm libc_rt_wasm struct_info libc - wasm - - lto <nl> python3 tests / runner . py test_hello_world <nl> - run : <nl> name : embuilder ( PIC ) <nl> commands : <nl> - run : <nl> name : embuilder ( PIC + LTO ) <nl> command : | <nl> - python3 . / embuilder . py build libcompiler_rt libc libc + + abi libc + + libc + + - noexcept libal libdlmalloc libpthreads_stub libcompiler_rt_wasm libc_rt_wasm struct_info libc - wasm - - pic - - lto <nl> + python3 . / embuilder . py build libcompiler_rt libc libc + + abi libc + + abi - noexcept libc + + libc + + - noexcept libal libdlmalloc libpthreads_stub libcompiler_rt_wasm libc_rt_wasm struct_info libc - wasm - - pic - - lto <nl> python3 tests / runner . py test_hello_world <nl> - run : <nl> name : freeze cache <nl> mmm a / tests / other / metadce / hello_libcxx_fastcomp_O2 . funcs <nl> ppp b / tests / other / metadce / hello_libcxx_fastcomp_O2 . funcs <nl> <nl> $ __ZL8is_equalPKSt9type_infoS1_b <nl> + $ __ZN10__cxxabiv116__shim_type_infoD2Ev <nl> + $ __ZN10__cxxabiv117__class_type_infoD0Ev <nl> $ __ZNK10__cxxabiv117__class_type_info16search_above_dstEPNS_19__dynamic_cast_infoEPKvS4_ib <nl> $ __ZNK10__cxxabiv117__class_type_info16search_below_dstEPNS_19__dynamic_cast_infoEPKvib <nl> $ __ZNK10__cxxabiv117__class_type_info24process_found_base_classEPNS_19__dynamic_cast_infoEPvi <nl> $ __ZNSt3__26vectorIPNS_6locale5facetENS_15__sso_allocatorIS3_Lm28EEEE8__appendEm <nl> $ __ZNSt3__26vectorIPNS_6locale5facetENS_15__sso_allocatorIS3_Lm28EEEEC2Em <nl> $ __ZNSt3__27codecvtIwc11__mbstate_tED0Ev <nl> $ __ZNSt3__27codecvtIwc11__mbstate_tED2Ev <nl> - $ __ZNSt3__27collateIcED0Ev <nl> - $ __ZNSt3__27collateIcED2Ev <nl> $ __ZNSt3__28ios_base16__call_callbacksENS0_5eventE <nl> $ __ZNSt3__28ios_base4InitC2Ev <nl> $ __ZNSt3__28ios_base4initEPv <nl> mmm a / tests / other / metadce / hello_libcxx_fastcomp_O2_EMULATED_FUNCTION_POINTERS . funcs <nl> ppp b / tests / other / metadce / hello_libcxx_fastcomp_O2_EMULATED_FUNCTION_POINTERS . funcs <nl> <nl> $ __ZL8is_equalPKSt9type_infoS1_b <nl> + $ __ZN10__cxxabiv116__shim_type_infoD2Ev <nl> + $ __ZN10__cxxabiv117__class_type_infoD0Ev <nl> $ __ZNK10__cxxabiv117__class_type_info16search_above_dstEPNS_19__dynamic_cast_infoEPKvS4_ib <nl> $ __ZNK10__cxxabiv117__class_type_info16search_below_dstEPNS_19__dynamic_cast_infoEPKvib <nl> $ __ZNK10__cxxabiv117__class_type_info24process_found_base_classEPNS_19__dynamic_cast_infoEPvi <nl> $ __ZNSt3__26vectorIPNS_6locale5facetENS_15__sso_allocatorIS3_Lm28EEEE8__appendEm <nl> $ __ZNSt3__26vectorIPNS_6locale5facetENS_15__sso_allocatorIS3_Lm28EEEEC2Em <nl> $ __ZNSt3__27codecvtIwc11__mbstate_tED0Ev <nl> $ __ZNSt3__27codecvtIwc11__mbstate_tED2Ev <nl> - $ __ZNSt3__27collateIcED0Ev <nl> - $ __ZNSt3__27collateIcED2Ev <nl> $ __ZNSt3__28ios_base16__call_callbacksENS0_5eventE <nl> $ __ZNSt3__28ios_base4InitC2Ev <nl> $ __ZNSt3__28ios_base4initEPv <nl> mmm a / tests / test_core . py <nl> ppp b / tests / test_core . py <nl> def test_emulate_function_pointer_casts ( self ) : <nl> ' | 1 . 266 , 1413754136 | ' ) ) # wasm , reinterpret the bits <nl> <nl> @ no_wasm2js ( ' TODO : nicely printed names in wasm2js ' ) <nl> - def test_demangle_stacks ( self ) : <nl> + @ parameterized ( { <nl> + ' normal ' : ( [ ] , ) , <nl> + ' noexcept ' : ( [ ' - fno - exceptions ' ] , ) <nl> + } ) <nl> + def test_demangle_stacks ( self , extra_args ) : <nl> + self . emcc_args + = extra_args <nl> self . set_setting ( ' DEMANGLE_SUPPORT ' , 1 ) <nl> self . set_setting ( ' ASSERTIONS ' , 1 ) <nl> # when optimizing function names are not preserved by default . <nl> mmm a / tools / system_libs . py <nl> ppp b / tools / system_libs . py <nl> class libc_extras ( MuslInternalLibrary ) : <nl> src_files = [ ' extras . c ' ] <nl> <nl> <nl> - class libcxxabi ( CXXLibrary , MTLibrary ) : <nl> + class libcxxabi ( CXXLibrary , MTLibrary , NoExceptLibrary ) : <nl> name = ' libc + + abi ' <nl> depends = [ ' libc ' ] <nl> cflags = [ ' - std = c + + 11 ' , ' - Oz ' , ' - D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS ' ] <nl> def get_cflags ( self ) : <nl> cflags . append ( ' - DNDEBUG ' ) <nl> if not self . is_mt : <nl> cflags . append ( ' - D_LIBCXXABI_HAS_NO_THREADS ' ) <nl> + if self . is_noexcept : <nl> + cflags . append ( ' - D_LIBCXXABI_NO_EXCEPTIONS ' ) <nl> return cflags <nl> <nl> src_dir = [ ' system ' , ' lib ' , ' libcxxabi ' , ' src ' ] <nl>
|
Add a NoExcept variation of libc + + abi ( )
|
emscripten-core/emscripten
|
aae6d15b7e6663c57af8660d521de9f8de4b9d0a
|
2019-09-23T17:17:56Z
|
mmm a / tensorflow / python / autograph / operators / special_values . py <nl> ppp b / tensorflow / python / autograph / operators / special_values . py <nl> class Undefined ( object ) : <nl> symbol_name : Text , identifier for the undefined symbol <nl> " " " <nl> <nl> + __slots__ = ( ' symbol_name ' , ) <nl> + <nl> def __init__ ( self , symbol_name ) : <nl> - # TODO ( aqj ) Possibly remove this after Symbols are fully integrated . <nl> self . symbol_name = symbol_name <nl> <nl> + def __repr__ ( self ) : <nl> + return self . symbol_name <nl> + <nl> + def __getattribute__ ( self , name ) : <nl> + try : <nl> + # If it ' s an existing attribute , return it . <nl> + return object . __getattribute__ ( self , name ) <nl> + except AttributeError : <nl> + # Otherwise return Undefined . <nl> + return self <nl> + <nl> + def __getitem__ ( self , i ) : <nl> + return self <nl> + <nl> <nl> def is_undefined ( value ) : <nl> " " " Checks whether Autograph has determined that a given value is undefined . <nl> mmm a / tensorflow / python / autograph / operators / special_values_test . py <nl> ppp b / tensorflow / python / autograph / operators / special_values_test . py <nl> def test_undefined ( self ) : <nl> self . assertTrue ( special_values . is_undefined ( undefined_symbol ) ) <nl> self . assertTrue ( special_values . is_undefined ( undefined_symbol2 ) ) <nl> <nl> + def test_undefined_operations ( self ) : <nl> + undefined_symbol = special_values . Undefined ( ' name ' ) <nl> + <nl> + self . assertTrue ( special_values . is_undefined ( undefined_symbol . foo ) ) <nl> + self . assertTrue ( special_values . is_undefined ( undefined_symbol [ 0 ] ) ) <nl> + self . assertFalse ( special_values . is_undefined ( undefined_symbol . __class__ ) ) <nl> + <nl> if __name__ = = ' __main__ ' : <nl> test . main ( ) <nl>
|
Allow undefined symbols to be queried for attributes and slices . An upcoming change will create situations when this can happen before the verification for undefined symbols that currently precludes such operations .
|
tensorflow/tensorflow
|
a4b4a8d25165df9bf06e70a2b0e03e5268e1e3d9
|
2020-01-06T19:21:58Z
|
mmm a / tensorflow / core / lib / strings / str_util . cc <nl> ppp b / tensorflow / core / lib / strings / str_util . cc <nl> limitations under the License . <nl> # include " tensorflow / core / lib / strings / str_util . h " <nl> <nl> # include < ctype . h > <nl> + # include < cstring > <nl> # include < algorithm > <nl> # include < vector > <nl> # include " tensorflow / core / lib / strings / numbers . h " <nl> mmm a / tensorflow / core / platform / posix / net . cc <nl> ppp b / tensorflow / core / platform / posix / net . cc <nl> limitations under the License . <nl> <nl> # include < cerrno > <nl> # include < cstdlib > <nl> + # include < cstring > <nl> # include < unordered_set > <nl> <nl> # include < netinet / in . h > <nl> mmm a / tensorflow / core / util / command_line_flags . cc <nl> ppp b / tensorflow / core / util / command_line_flags . cc <nl> limitations under the License . <nl> = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * / <nl> <nl> # include < string > <nl> + # include < cstring > <nl> # include < vector > <nl> <nl> # include " tensorflow / core / lib / core / stringpiece . h " <nl>
|
include < cstring > in a few places that use it
|
tensorflow/tensorflow
|
379c480e1d2b0ea7596143050b2e13f7b0d16463
|
2018-09-27T05:16:41Z
|
mmm a / selfdrive / manager . py <nl> ppp b / selfdrive / manager . py <nl> def get_running ( ) : <nl> interrupt_processes : List [ str ] = [ ] <nl> <nl> # processes to end with SIGKILL instead of SIGTERM <nl> - kill_processes = [ ' sensord ' , ' paramsd ' ] <nl> + kill_processes = [ ' sensord ' ] <nl> <nl> # processes to end if thermal conditions exceed Green parameters <nl> green_temp_processes = [ ' uploader ' ] <nl>
|
Paramsd can now be killed normally
|
commaai/openpilot
|
e3ffdf3647075ce7415a9ba6b808b5021931acc1
|
2020-06-03T18:11:06Z
|
mmm a / src / tests / volume_renderer . h <nl> ppp b / src / tests / volume_renderer . h <nl> class TRenderer { <nl> auto far_t = Var ( std : : numeric_limits < float > : : max ( ) ) ; <nl> auto hit = box_intersect ( o , d , near_t , far_t ) ; <nl> <nl> - auto interaction = Var ( 0 ) ; <nl> - auto t = Var ( near_t ) ; <nl> - <nl> - If ( t > = far_t | | ! point_inside_box ( p ) ) . Else ( [ & ] { interaction = 1 ; } ) ; <nl> - <nl> - dist = t - near_t ; <nl> - <nl> - return hit & & interaction ; <nl> + return hit ; <nl> } ; <nl> <nl> float32 fov = param . get ( " fov " , 0 . 6f ) ; <nl>
|
simplified difference case
|
taichi-dev/taichi
|
e4c61e2214ea236dfcb21953e7ba7f8fba5c28df
|
2019-05-14T17:24:05Z
|
mmm a / python / mxnet / symbol / numpy / _symbol . py <nl> ppp b / python / mxnet / symbol / numpy / _symbol . py <nl> def ones ( shape , dtype = _np . float32 , order = ' C ' , ctx = None ) : <nl> <nl> Returns <nl> mmmmmm - <nl> - out : ndarray <nl> + out : _Symbol <nl> Array of ones with the given shape , dtype , and ctx . <nl> " " " <nl> if order ! = ' C ' : <nl> def divide ( x1 , x2 , out = None , * * kwargs ) : <nl> _npi . rtrue_divide_scalar , out ) <nl> <nl> <nl> - @ set_module ( ' mxnet . ndarray . numpy ' ) <nl> + @ set_module ( ' mxnet . symbol . numpy ' ) <nl> def true_divide ( x1 , x2 , out = None ) : <nl> return _ufunc_helper ( x1 , x2 , _npi . true_divide , _np . divide , _npi . true_divide_scalar , <nl> _npi . rtrue_divide_scalar , out ) <nl> def lcm ( x1 , x2 , out = None , * * kwargs ) : <nl> <nl> Parameters <nl> mmmmmmmmm - <nl> - x1 , x2 : ndarrays or scalar values <nl> + x1 , x2 : _Symbols or scalar values <nl> The arrays for computing lowest common multiple . If x1 . shape ! = x2 . shape , <nl> they must be broadcastable to a common shape ( which may be the shape of <nl> one or the other ) . <nl> <nl> - out : ndarray or None , optional <nl> + out : _Symbol or None , optional <nl> A location into which the result is stored . If provided , it must have a shape <nl> that the inputs broadcast to . If not provided or None , a freshly - allocated array <nl> is returned . <nl> <nl> Returns <nl> mmmmmm - <nl> - y : ndarray or scalar <nl> + y : _Symbol or scalar <nl> The lowest common multiple of the absolute value of the inputs <nl> This is a scalar if both ` x1 ` and ` x2 ` are scalars . <nl> <nl> def eye ( N , M = None , k = 0 , dtype = _np . float32 , * * kwargs ) : <nl> <nl> Returns <nl> mmmmmm - <nl> - I : ndarray of shape ( N , M ) <nl> + I : _Symbol of shape ( N , M ) <nl> An array where all elements are equal to zero , <nl> except for the k - th diagonal , whose values are equal to one . <nl> " " " <nl> def cosh ( x , out = None , * * kwargs ) : <nl> mmmmmmmmm - <nl> x : _Symbol or scalar <nl> Input array or scalar . <nl> - out : ndarray or None <nl> + out : _Symbol or None <nl> Dummy parameter to keep the consistency with the ndarray counterpart . <nl> <nl> Returns <nl> def log2 ( x , out = None , * * kwargs ) : <nl> mmmmmmmmm - <nl> x : _Symbol <nl> Input values . <nl> - out : ndarray or None <nl> + out : _Symbol or None <nl> A location into which the result is stored . <nl> If provided , it must have the same shape and type as the input . <nl> If not provided or None , a freshly - allocated array is returned . <nl> def arange ( start , stop = None , step = 1 , dtype = None , ctx = None ) : <nl> <nl> Returns <nl> mmmmmm - <nl> - arange : ndarray <nl> + arange : _Symbol <nl> Array of evenly spaced values . <nl> <nl> For floating point arguments , the length of the result is <nl> def split ( ary , indices_or_sections , axis = 0 ) : <nl> <nl> Parameters <nl> mmmmmmmmm - <nl> - ary : ndarray <nl> + ary : _Symbol <nl> Array to be divided into sub - arrays . <nl> indices_or_sections : int or 1 - D python tuple , list or set . <nl> If ` indices_or_sections ` is an integer , N , the array will be divided <nl> def split ( ary , indices_or_sections , axis = 0 ) : <nl> <nl> Returns <nl> mmmmmm - <nl> - sub - arrays : list of ndarrays <nl> + sub - arrays : _Symbol <nl> A list of sub - arrays . <nl> <nl> Raises <nl> def split ( ary , indices_or_sections , axis = 0 ) : <nl> <nl> <nl> # pylint : disable = redefined - outer - name <nl> - @ set_module ( ' mxnet . ndarray . numpy ' ) <nl> + @ set_module ( ' mxnet . symbol . numpy ' ) <nl> def hsplit ( ary , indices_or_sections ) : <nl> " " " Split an array into multiple sub - arrays horizontally ( column - wise ) . <nl> <nl> def concatenate ( seq , axis = 0 , out = None ) : <nl> <nl> Parameters <nl> mmmmmmmmm - <nl> - a1 , a2 , . . . : sequence of array_like <nl> + a1 , a2 , . . . : sequence of _Symbols <nl> The arrays must have the same shape , except in the dimension <nl> corresponding to ` axis ` ( the first , by default ) . <nl> axis : int , optional <nl> def concatenate ( seq , axis = 0 , out = None ) : <nl> <nl> Returns <nl> mmmmmm - <nl> - res : ndarray <nl> + res : _Symbol <nl> The concatenated array . <nl> <nl> Examples <nl> def append ( arr , values , axis = None ) : # pylint : disable = redefined - outer - name <nl> <nl> Parameters <nl> mmmmmmmmm - <nl> - arr : ndarray <nl> + arr : _Symbol <nl> Values are appended to a copy of this array . <nl> - values : ndarray <nl> + values : _Symbol <nl> These values are appended to a copy of ` arr ` . It must be of the <nl> correct shape ( the same shape as ` arr ` , excluding ` axis ` ) . If <nl> ` axis ` is not specified , ` values ` can be any shape and will be <nl> def append ( arr , values , axis = None ) : # pylint : disable = redefined - outer - name <nl> <nl> Returns <nl> mmmmmm - <nl> - append : ndarray <nl> + append : _Symbol <nl> A copy of ` arr ` with ` values ` appended to ` axis ` . Note that <nl> ` append ` does not occur in - place : a new array is allocated and <nl> filled . If ` axis ` is None , ` out ` is a flattened array . <nl> def stack ( arrays , axis = 0 , out = None ) : <nl> For example , if ` axis = 0 ` it will be the first dimension and if ` axis = - 1 ` it will be the last dimension . <nl> Parameters <nl> mmmmmmmmm - <nl> - arrays : sequence of array_like <nl> + arrays : sequence of _Symbols <nl> Each array must have the same shape . <nl> axis : int , optional <nl> The axis in the result array along which the input arrays are stacked . <nl> - out : ndarray , optional <nl> + out : _Symbol , optional <nl> If provided , the destination to place the result . The shape must be correct , <nl> matching that of what stack would have returned if no out argument were specified . <nl> Returns <nl> mmmmmm - <nl> - stacked : ndarray <nl> + stacked : _Symbol <nl> The stacked array has one more dimension than the input arrays . " " " <nl> def get_list ( arrays ) : <nl> if not hasattr ( arrays , ' __getitem__ ' ) and hasattr ( arrays , ' __iter__ ' ) : <nl> def ravel ( x , order = ' C ' ) : <nl> <nl> Parameters <nl> mmmmmmmmm - <nl> - x : ndarray <nl> + x : _Symbol <nl> Input array . The elements in ` x ` are read in row - major , C - style order and <nl> packed as a 1 - D array . <nl> order : ` C ` , optional <nl> def ravel ( x , order = ' C ' ) : <nl> <nl> Returns <nl> mmmmmm - <nl> - y : ndarray <nl> + y : _Symbol <nl> y is an array of the same subtype as ` x ` , with shape ` ` ( x . size , ) ` ` . <nl> Note that matrices are special cased for backward compatibility , if ` x ` <nl> is a matrix , then y is a 1 - D ndarray . <nl> def unravel_index ( indices , shape , order = ' C ' ) : # pylint : disable = redefined - outer - <nl> <nl> Parameters : <nl> mmmmmmmmmmmm - <nl> - indices : array_like <nl> + indices : _Symbol <nl> An integer array whose elements are indices into the flattened version of an array of dimensions shape . <nl> Before version 1 . 6 . 0 , this function accepted just one index value . <nl> shape : tuple of ints <nl> def unravel_index ( indices , shape , order = ' C ' ) : # pylint : disable = redefined - outer - <nl> <nl> Returns : <nl> mmmmmmmmmmmm - <nl> - unraveled_coords : ndarray <nl> + unraveled_coords : _Symbol <nl> Each row in the ndarray has the same shape as the indices array . <nl> Each column in the ndarray represents the unravelled index <nl> <nl> def outer ( a , b ) : <nl> <nl> Parameters <nl> mmmmmmmmm - <nl> - a : ( M , ) ndarray <nl> + a : ( M , ) _Symbol <nl> First input vector . Input is flattened if <nl> not already 1 - dimensional . <nl> - b : ( N , ) ndarray <nl> + b : ( N , ) _Symbol <nl> Second input vector . Input is flattened if <nl> not already 1 - dimensional . <nl> <nl> Returns <nl> mmmmmm - <nl> - out : ( M , N ) ndarray <nl> + out : ( M , N ) _Symbol <nl> ` ` out [ i , j ] = a [ i ] * b [ j ] ` ` <nl> <nl> See also <nl> def diff ( a , n = 1 , axis = - 1 , prepend = None , append = None ) : # pylint : disable = redefin <nl> <nl> Parameters <nl> mmmmmmmmm - <nl> - a : ndarray <nl> + a : _Symbol <nl> Input array <nl> n : int , optional <nl> The number of times values are differenced . If zero , the input is returned as - is . <nl> axis : int , optional <nl> The axis along which the difference is taken , default is the last axis . <nl> - prepend , append : ndarray , optional <nl> + prepend , append : _Symbol , optional <nl> Not supported yet <nl> <nl> Returns <nl> mmmmmm - <nl> - diff : ndarray <nl> + diff : _Symbol <nl> The n - th differences . <nl> The shape of the output is the same as a except along axis where the dimension is smaller by n . <nl> The type of the output is the same as the type of the difference between any two elements of a . <nl>
|
fix typo and doc ( )
|
apache/incubator-mxnet
|
5823ce64bfec97cdfa0a781253795a6945d469f3
|
2019-12-06T09:12:18Z
|
mmm a / src / core / hle / service / apm / interface . cpp <nl> ppp b / src / core / hle / service / apm / interface . cpp <nl> class ISession final : public ServiceFramework < ISession > { <nl> IPC : : ResponseBuilder rb { ctx , 2 } ; <nl> rb . Push ( RESULT_SUCCESS ) ; <nl> <nl> - LOG_WARNING ( Service_APM , " ( STUBBED ) called mode = % u config = % u " , static_cast < u32 > ( mode ) , <nl> - config ) ; <nl> + NGLOG_WARNING ( Service_APM , " ( STUBBED ) called mode = { } config = { } " , static_cast < u32 > ( mode ) , <nl> + config ) ; <nl> } <nl> <nl> void GetPerformanceConfiguration ( Kernel : : HLERequestContext & ctx ) { <nl> class ISession final : public ServiceFramework < ISession > { <nl> rb . Push ( RESULT_SUCCESS ) ; <nl> rb . Push < u32 > ( 0 ) ; / / Performance configuration <nl> <nl> - LOG_WARNING ( Service_APM , " ( STUBBED ) called mode = % u " , static_cast < u32 > ( mode ) ) ; <nl> + NGLOG_WARNING ( Service_APM , " ( STUBBED ) called mode = { } " , static_cast < u32 > ( mode ) ) ; <nl> } <nl> } ; <nl> <nl>
|
apm : Move logging macros over to new fmt - compatible ones
|
yuzu-emu/yuzu
|
d652e413654d736d85edbed8b6a387ab526c6d2b
|
2018-04-24T14:16:03Z
|
mmm a / lib / SimpleHttpClient / ConnectionManager . cpp <nl> ppp b / lib / SimpleHttpClient / ConnectionManager . cpp <nl> ConnectionManager : : leaseConnection ( std : : string & endpoint ) { <nl> delete e ; <nl> return 0 ; <nl> } <nl> + if ( ! g - > connect ( ) ) { <nl> + delete g ; <nl> + delete e ; <nl> + return 0 ; <nl> + } <nl> c = new SingleServerConnection ( g , e , endpoint ) ; <nl> if ( 0 = = c ) { <nl> delete g ; <nl> void ConnectionManager : : returnConnection ( SingleServerConnection * c ) { <nl> map < string , ServerConnections * > : : iterator i ; <nl> ServerConnections * s ; <nl> <nl> + if ( ! c - > connection - > isConnected ( ) ) { <nl> + brokenConnection ( c ) ; <nl> + return ; <nl> + } <nl> + <nl> / / First find the collections list : <nl> { <nl> WRITE_LOCKER ( allLock ) ; <nl> mmm a / lib / SimpleHttpClient / SimpleHttpClient . cpp <nl> ppp b / lib / SimpleHttpClient / SimpleHttpClient . cpp <nl> namespace triagens { <nl> _errorMessage = " " ; <nl> _written = 0 ; <nl> _state = IN_CONNECT ; <nl> - <nl> - reset ( ) ; <nl> + if ( _connection - > isConnected ( ) ) { <nl> + _state = FINISHED ; <nl> + } <nl> } <nl> <nl> SimpleHttpClient : : ~ SimpleHttpClient ( ) { <nl>
|
Exorcise closing of connections in SimpleHttpClient .
|
arangodb/arangodb
|
ca2c4cdf521ea8b347e9768f2e5dece74fa1b8e2
|
2014-01-30T19:46:26Z
|
mmm a / src / python / grpcio_tests / tests_aio / unit / channel_test . py <nl> ppp b / src / python / grpcio_tests / tests_aio / unit / channel_test . py <nl> async def test_unary_call_does_not_times_out ( self ) : <nl> ) <nl> <nl> call = hi ( messages_pb2 . SimpleRequest ( ) , <nl> - timeout = UNARY_CALL_WITH_SLEEP_VALUE * 2 ) <nl> + timeout = UNARY_CALL_WITH_SLEEP_VALUE * 5 ) <nl> self . assertEqual ( await call . code ( ) , grpc . StatusCode . OK ) <nl> <nl> async def test_unary_stream ( self ) : <nl> mmm a / src / python / grpcio_tests / tests_aio / unit / interceptor_test . py <nl> ppp b / src / python / grpcio_tests / tests_aio / unit / interceptor_test . py <nl> async def intercept_unary_unary ( self , continuation , <nl> async def test_cancel_before_rpc ( self ) : <nl> <nl> interceptor_reached = asyncio . Event ( ) <nl> + wait_for_ever = self . loop . create_future ( ) <nl> <nl> class Interceptor ( aio . UnaryUnaryClientInterceptor ) : <nl> <nl> async def intercept_unary_unary ( self , continuation , <nl> client_call_details , request ) : <nl> interceptor_reached . set ( ) <nl> - await asyncio . sleep ( 0 ) <nl> - <nl> - # This line should never be reached <nl> - raise Exception ( ) <nl> + await wait_for_ever <nl> <nl> async with aio . insecure_channel ( self . _server_target , <nl> interceptors = [ Interceptor ( ) <nl> async def intercept_unary_unary ( self , continuation , <nl> async def test_cancel_after_rpc ( self ) : <nl> <nl> interceptor_reached = asyncio . Event ( ) <nl> + wait_for_ever = self . loop . create_future ( ) <nl> <nl> class Interceptor ( aio . UnaryUnaryClientInterceptor ) : <nl> <nl> async def intercept_unary_unary ( self , continuation , <nl> call = await continuation ( client_call_details , request ) <nl> await call <nl> interceptor_reached . set ( ) <nl> - await asyncio . sleep ( 0 ) <nl> - <nl> - # This line should never be reached <nl> - raise Exception ( ) <nl> + await wait_for_ever <nl> <nl> async with aio . insecure_channel ( self . _server_target , <nl> interceptors = [ Interceptor ( ) <nl>
|
Apply review feedback , increase timeout threshold
|
grpc/grpc
|
17928a43c063e9a89254e6d98f345854523eb93b
|
2020-01-11T14:31:05Z
|
mmm a / include / swift / AST / DiagnosticsParse . def <nl> ppp b / include / swift / AST / DiagnosticsParse . def <nl> NOTE ( lex_multiline_string_indent_should_match_here , none , <nl> " should match % select { space | tab } 0 here " , ( unsigned ) ) <nl> NOTE ( lex_multiline_string_indent_change_line , none , <nl> " change indentation of % select { this line | these lines } 0 to match closing delimiter " , ( bool ) ) <nl> + ERROR ( lex_escaped_newline_at_lastline , none , <nl> + " escaped newline at the last line is not allowed " , ( ) ) <nl> <nl> ERROR ( lex_invalid_character , none , <nl> " invalid character in source file " , ( ) ) <nl> mmm a / lib / Parse / Lexer . cpp <nl> ppp b / lib / Parse / Lexer . cpp <nl> getMultilineTrailingIndent ( const Token & Str , DiagnosticEngine * Diags ) { <nl> continue ; <nl> case ' \ n ' : <nl> case ' \ r ' : { <nl> - auto bytes = start + 1 ; <nl> - auto length = end - ( start + 1 ) ; <nl> - <nl> - auto bytesLoc = Lexer : : getSourceLoc ( bytes ) ; <nl> - auto string = StringRef ( bytes , length ) ; <nl> - <nl> - return std : : make_tuple ( string , bytesLoc ) ; <nl> + start + + ; <nl> + auto startLoc = Lexer : : getSourceLoc ( start ) ; <nl> + auto string = StringRef ( start , end - start ) ; <nl> + <nl> + / / Disallow escaped newline in the last line . <nl> + if ( Diags ) { <nl> + auto * Ptr = start - 1 ; <nl> + if ( * Ptr = = ' \ n ' ) - - Ptr ; <nl> + if ( * Ptr = = ' \ r ' ) - - Ptr ; <nl> + auto * LineEnd = Ptr + 1 ; <nl> + while ( Ptr > begin & & ( * Ptr = = ' ' | | * Ptr = = ' \ t ' ) ) - - Ptr ; <nl> + if ( * Ptr = = ' \ \ ' ) { <nl> + auto escapeLoc = Lexer : : getSourceLoc ( Ptr ) ; <nl> + bool invalid = true ; <nl> + while ( * - - Ptr = = ' \ \ ' ) invalid = ! invalid ; <nl> + if ( invalid ) <nl> + Diags - > diagnose ( escapeLoc , diag : : lex_escaped_newline_at_lastline ) <nl> + . fixItRemoveChars ( escapeLoc , Lexer : : getSourceLoc ( LineEnd ) ) ; <nl> + } <nl> + } <nl> + <nl> + return std : : make_tuple ( string , startLoc ) ; <nl> } <nl> default : <nl> sawNonWhitespace = true ; <nl> mmm a / test / Parse / multiline_errors . swift <nl> ppp b / test / Parse / multiline_errors . swift <nl> _ = " " " <nl> / / expected - note @ - 1 { { should match tab here } } <nl> / / expected - note @ - 3 { { change indentation of this line to match closing delimiter } } { { 1 - 1 = } } <nl> <nl> + _ = " " " <nl> + \ ( 42 <nl> + ) <nl> + " " " / / expected - error @ - 1 { { insufficient indentation of line in multi - line string literal } } <nl> + / / expected - note @ - 1 { { should match space here } } <nl> + / / expected - note @ - 3 { { change indentation of this line to match closing delimiter } } { { 1 - 1 = } } <nl> + <nl> + _ = " " " <nl> + Foo <nl> + \ <nl> + Bar <nl> + " " " / / expected - error @ - 2 { { insufficient indentation of line in multi - line string literal } } <nl> + / / expected - note @ - 1 { { should match space here } } <nl> + / / expected - note @ - 4 { { change indentation of this line to match closing delimiter } } { { 1 - 1 = } } <nl> + <nl> / / a tab is not the same as multiple spaces for de - indentation <nl> _ = " " " <nl> Thirteen <nl> _ = " " " <nl> line two <nl> " " " <nl> / / expected - error @ - 3 { { invalid escape sequence in literal } } <nl> + <nl> + _ = " " " <nl> + line one <nl> + line two \ <nl> + " " " <nl> + / / expected - error @ - 2 { { escaped newline at the last line is not allowed } } { { 11 - 12 = } } <nl> + <nl> + _ = " " " <nl> + \ \ \ <nl> + " " " <nl> + / / expected - error @ - 2 { { escaped newline at the last line is not allowed } } { { 5 - 10 = } } <nl> + <nl> + _ = " " " <nl> + \ ( 42 ) \ <nl> + " " " <nl> + / / expected - error @ - 2 { { escaped newline at the last line is not allowed } } { { 8 - 11 = } } <nl> + <nl> + _ = " " " <nl> + foo \ <nl> + " " " <nl> + / / expected - error @ - 2 { { escaped newline at the last line is not allowed } } { { 6 - 7 = } } <nl> + <nl> + _ = " " " <nl> + foo \ " " " <nl> + / / expected - error @ - 1 { { escaped newline at the last line is not allowed } } { { 6 - 7 = } } <nl> + <nl> + _ = " " " <nl> + foo \ <nl> + " " " / / OK because LF + CR is two new lines . <nl> + <nl> + _ = " " " <nl> + \ <nl> + " " " <nl> + / / expected - error @ - 2 { { escaped newline at the last line is not allowed } } { { 1 - 2 = } } <nl> + / / expected - error @ - 3 { { insufficient indentation of line in multi - line string literal } } <nl> + / / expected - note @ - 3 { { should match space here } } <nl> + / / expected - note @ - 5 { { change indentation of this line to match closing delimiter } } { { 1 - 1 = } } <nl> + <nl> + _ = " " " \ <nl> + " " " <nl> + / / FIXME : Bad diagnostics <nl> + / / expected - error @ - 3 { { multi - line string literal content must begin on a new line } } <nl> + / / expected - error @ - 4 { { escaped newline at the last line is not allowed } } { { 8 - 9 = } } <nl> new file mode 100644 <nl> index 000000000000 . . acbaa5a1e5f1 <nl> mmm / dev / null <nl> ppp b / test / Parse / multiline_normalize_newline . swift <nl> <nl> + / / RUN : % target - swift - frontend - dump - parse % s 2 > & 1 | % FileCheck % s <nl> + <nl> + / / CR <nl> + _ = " " " " " " <nl> + / / CHECK : string_literal_expr { { . * } } value = " " <nl> + <nl> + _ = " " " test " " " <nl> + / / CHECK : string_literal_expr { { . * } } value = " test " <nl> + <nl> + / / CR + LF <nl> + _ = " " " <nl> + " " " <nl> + / / CHECK : string_literal_expr { { . * } } value = " " <nl> + <nl> + _ = " " " <nl> + test <nl> + " " " <nl> + / / CHECK : string_literal_expr { { . * } } value = " test " <nl> + <nl> + / / CR + LF <nl> + _ = " " " <nl> + " " " <nl> + / / CHECK : string_literal_expr { { . * } } value = " " <nl> + _ = " " " <nl> + test <nl> + test <nl> + " " " <nl> + / / CHECK : string_literal_expr { { . * } } value = " test \ ntest " <nl> + <nl> + / / LF + CR <nl> + _ = " " " <nl> + foo <nl> + foo <nl> + " " " <nl> + / / CHECK : string_literal_expr { { . * } } value = " \ nfoo \ n \ nfoo \ n " <nl> + <nl> + / / LF + CR + LF <nl> + _ = " " " <nl> + <nl> + foo <nl> + <nl> + foo <nl> + <nl> + " " " <nl> + / / CHECK : string_literal_expr { { . * } } value = " \ nfoo \ n \ nfoo \ n " <nl> + <nl> + / / Mixed no - indent . <nl> + _ = " " " <nl> + < LF <nl> + < LF < CR <nl> + < CR + LF <nl> + " " " <nl> + / / CHECK : string_literal_expr { { . * } } value = " < LF \ n < LF \ n < CR \ n < CR + LF " <nl> + <nl> + / / Mixed indent . <nl> + _ = " " " <nl> + < LF <nl> + < LF < CR <nl> + < CR + LF <nl> + " " " <nl> + / / CHECK : string_literal_expr { { . * } } value = " < LF \ n < LF \ n < CR \ n < CR + LF " <nl> + <nl> + / / Empty line CR , CR + LF , LF . <nl> + _ = " " " <nl> + foo <nl> + <nl> + <nl> + bar <nl> + " " " <nl> + / / CHECK : string_literal_expr { { . * } } value = " foo \ n \ n \ n \ nbar " <nl> mmm a / test / Parse / multiline_string . swift <nl> ppp b / test / Parse / multiline_string . swift <nl> _ = " " " <nl> " " " <nl> / / CHECK : " \ \ " <nl> <nl> + _ = " " " <nl> + \ \ <nl> + " " " <nl> + / / CHECK : " \ \ " <nl> + <nl> _ = " " " <nl> <nl> ABC <nl> _ = " " " <nl> \ ( " " " <nl> substring2 \ <nl> substring3 <nl> - " " " ) \ <nl> + " " " ) <nl> " " " ) \ <nl> whitepsace <nl> " " " <nl>
|
[ SE - 0182 ] [ Lexer ] Diagnose escaped newline at the end of the last line in multiline string
|
apple/swift
|
a2d3ff4debce9ba7c88c61c32c98d05b735038e8
|
2017-07-26T12:18:58Z
|
deleted file mode 100644 <nl> index 1ba11bc3da37 . . 000000000000 <nl> mmm a / test / expect / TestScript . test_if_is_none_dispatch . expect <nl> ppp / dev / null <nl> <nl> - graph ( % input : Tensor , <nl> - % opt . 1 : Tensor ? ) : <nl> - % 2 : None = prim : : Constant ( ) <nl> - % 3 : int = prim : : Constant [ value = 1 ] ( ) <nl> - % 4 : int = prim : : Constant [ value = 2 ] ( ) <nl> - % 5 : int = prim : : Constant [ value = 4 ] ( ) <nl> - % x . 1 : Tensor = aten : : add ( % input , % 4 , % 3 ) <nl> - % 7 : bool = aten : : __isnot__ ( % opt . 1 , % 2 ) <nl> - % opt . 4 : Tensor ? , % x . 3 : Tensor = prim : : If ( % 7 ) <nl> - block0 ( ) : <nl> - % opt . 2 : Tensor = prim : : unchecked_unwrap_optional ( % opt . 1 ) <nl> - % opt . 3 : Tensor = aten : : _unwrap_optional ( % opt . 2 ) <nl> - % x . 2 : Tensor = aten : : add ( % opt . 3 , % x . 1 , % 3 ) <nl> - - > ( % opt . 3 , % x . 2 ) <nl> - block1 ( ) : <nl> - - > ( % opt . 1 , % x . 1 ) <nl> - % 13 : bool = aten : : __is__ ( % opt . 4 , % 2 ) <nl> - % x : Tensor = prim : : If ( % 13 ) <nl> - block0 ( ) : <nl> - % x . 4 : Tensor = aten : : add ( % x . 3 , % 5 , % 3 ) <nl> - - > ( % x . 4 ) <nl> - block1 ( ) : <nl> - - > ( % x . 3 ) <nl> - return ( % x ) <nl> deleted file mode 100644 <nl> index 36d29023dede . . 000000000000 <nl> mmm a / test / expect / TestScript . test_if_list . expect <nl> ppp / dev / null <nl> <nl> - graph ( % x : Double ( * , * ) ) : <nl> - % 1 : int = prim : : Constant [ value = 0 ] ( ) <nl> - % 2 : bool = prim : : Constant [ value = 1 ] ( ) <nl> - % c : Tensor [ ] = prim : : If ( % 2 ) <nl> - block0 ( ) : <nl> - % c . 1 : Tensor [ ] = prim : : ListConstruct ( % x , % x ) <nl> - - > ( % c . 1 ) <nl> - block1 ( ) : <nl> - % c . 2 : Tensor [ ] = prim : : ListConstruct ( % x , % x , % x ) <nl> - - > ( % c . 2 ) <nl> - % 6 : Tensor = aten : : cat ( % c , % 1 ) <nl> - return ( % 6 ) <nl> deleted file mode 100644 <nl> index 3f1f4bbc8630 . . 000000000000 <nl> mmm a / test / expect / TestScript . test_if_supertype . expect <nl> ppp / dev / null <nl> <nl> - graph ( % x . 1 : Float ( * , * ) , <nl> - % y . 1 : Long ( * , * ) , <nl> - % z . 1 : Float ( * , * ) ) : <nl> - % 3 : bool = prim : : Constant [ value = 1 ] ( ) <nl> - % x : Float ( * , * ) , % y : Tensor , % z : Tensor = prim : : If ( % 3 ) <nl> - block0 ( ) : <nl> - - > ( % x . 1 , % y . 1 , % z . 1 ) <nl> - block1 ( ) : <nl> - - > ( % x . 1 , % x . 1 , % y . 1 ) <nl> - % 7 : ( Float ( * , * ) , Tensor , Tensor ) = prim : : TupleConstruct ( % x , % y , % z ) <nl> - return ( % 7 ) <nl> deleted file mode 100644 <nl> index 5a09f9ce4ee4 . . 000000000000 <nl> mmm a / test / expect / TestScript . test_index_put_trace_with_view . expect <nl> ppp / dev / null <nl> <nl> - graph ( % target : Double ( 100 ) , <nl> - % indices . 1 : Long ( 4 ) , <nl> - % rhs : Double ( 1 , 1 , 1 , 4 ) ) : <nl> - % 3 : int = prim : : Constant [ value = 4 ] ( ) <nl> - % 4 : int [ ] = prim : : ListConstruct ( % 3 ) <nl> - % 5 : Double ( 4 ) = aten : : view ( % rhs , % 4 ) <nl> - % 6 : int = prim : : Constant [ value = 4 ] ( ) <nl> - % 7 : int = prim : : Constant [ value = 0 ] ( ) <nl> - % 8 : Device = prim : : Constant [ value = " cpu " ] ( ) <nl> - % 9 : bool = prim : : Constant [ value = 0 ] ( ) <nl> - % 10 : bool = prim : : Constant [ value = 0 ] ( ) <nl> - % indices : Long ( 4 ) = aten : : to ( % indices . 1 , % 6 , % 7 , % 8 , % 9 , % 10 ) <nl> - % 12 : Tensor ? [ ] = prim : : ListConstruct ( % indices ) <nl> - % 13 : bool = prim : : Constant [ value = 0 ] ( ) <nl> - % 14 : Double ( 100 ) = aten : : index_put_ ( % target , % 12 , % 5 , % 13 ) <nl> - return ( % 14 ) <nl> deleted file mode 100644 <nl> index c1f2274db94c . . 000000000000 <nl> mmm a / test / expect / TestScript . test_index_put_trace_without_view . expect <nl> ppp / dev / null <nl> <nl> - graph ( % target : Double ( 100 ) , <nl> - % indices . 1 : Long ( 4 ) , <nl> - % rhs : Double ( 4 ) ) : <nl> - % 3 : int = prim : : Constant [ value = 4 ] ( ) <nl> - % 4 : int = prim : : Constant [ value = 0 ] ( ) <nl> - % 5 : Device = prim : : Constant [ value = " cpu " ] ( ) <nl> - % 6 : bool = prim : : Constant [ value = 0 ] ( ) <nl> - % 7 : bool = prim : : Constant [ value = 0 ] ( ) <nl> - % indices : Long ( 4 ) = aten : : to ( % indices . 1 , % 3 , % 4 , % 5 , % 6 , % 7 ) <nl> - % 9 : Tensor ? [ ] = prim : : ListConstruct ( % indices ) <nl> - % 10 : bool = prim : : Constant [ value = 0 ] ( ) <nl> - % 11 : Double ( 100 ) = aten : : index_put_ ( % target , % 9 , % rhs , % 10 ) <nl> - return ( % 11 ) <nl> deleted file mode 100644 <nl> index 6f2f55c78cf6 . . 000000000000 <nl> mmm a / test / expect / TestScript . test_index_select_shape_prop . expect <nl> ppp / dev / null <nl> <nl> - graph ( % x : Double ( 2 , 2 ) , <nl> - % y : Long ( 4 ) ) : <nl> - % 2 : int = prim : : Constant [ value = 1 ] ( ) <nl> - % 3 : Double ( 2 , 4 ) = aten : : index_select ( % x , % 2 , % y ) <nl> - return ( % 3 ) <nl> deleted file mode 100644 <nl> index d85d5d773bf9 . . 000000000000 <nl> mmm a / test / expect / TestScript . test_mutable_dce . expect <nl> ppp / dev / null <nl> <nl> - graph ( ) : <nl> - % 0 : int = prim : : Constant [ value = 1 ] ( ) <nl> - % 1 : Device = prim : : Constant [ value = " cpu " ] ( ) <nl> - % 2 : int = prim : : Constant [ value = 0 ] ( ) <nl> - % 3 : int = prim : : Constant [ value = 6 ] ( ) <nl> - % 4 : int = prim : : Constant [ value = 2 ] ( ) <nl> - % 5 : int = prim : : Constant [ value = 3 ] ( ) <nl> - % 6 : int [ ] = prim : : ListConstruct ( % 4 , % 5 ) <nl> - % a . 1 : Tensor = aten : : rand ( % 6 , % 3 , % 2 , % 1 ) <nl> - % 8 : int [ ] = prim : : ListConstruct ( % 4 , % 5 ) <nl> - % 9 : Tensor = aten : : rand ( % 8 , % 3 , % 2 , % 1 ) <nl> - % a : Tensor = aten : : add_ ( % a . 1 , % 9 , % 0 ) <nl> - return ( % a ) <nl> deleted file mode 100644 <nl> index 53d15f9c31cd . . 000000000000 <nl> mmm a / test / expect / TestScript . test_mutable_dce_block . expect <nl> ppp / dev / null <nl> <nl> - graph ( ) : <nl> - % 0 : int = prim : : Constant [ value = 1 ] ( ) <nl> - % 1 : Device = prim : : Constant [ value = " cpu " ] ( ) <nl> - % 2 : int = prim : : Constant [ value = 0 ] ( ) <nl> - % 3 : int = prim : : Constant [ value = 6 ] ( ) <nl> - % 4 : int = prim : : Constant [ value = 2 ] ( ) <nl> - % 5 : int = prim : : Constant [ value = 3 ] ( ) <nl> - % 6 : int [ ] = prim : : ListConstruct ( % 4 , % 5 ) <nl> - % a . 1 : Tensor = aten : : rand ( % 6 , % 3 , % 2 , % 1 ) <nl> - % 8 : int [ ] = prim : : ListConstruct ( % 4 , % 5 ) <nl> - % 9 : Tensor = aten : : rand ( % 8 , % 3 , % 2 , % 1 ) <nl> - % a . 2 : Tensor = aten : : add_ ( % a . 1 , % 9 , % 0 ) <nl> - % 11 : int [ ] = prim : : ListConstruct ( % 4 , % 5 ) <nl> - % b . 1 : Tensor = aten : : rand ( % 11 , % 3 , % 2 , % 1 ) <nl> - % 13 : int [ ] = prim : : ListConstruct ( % 4 , % 5 ) <nl> - % 14 : Tensor = aten : : zeros ( % 13 , % 3 , % 2 , % 1 ) <nl> - % 15 : Tensor = aten : : gt ( % a . 2 , % 14 ) <nl> - % 16 : bool = prim : : Bool ( % 15 ) <nl> - % b : Tensor = prim : : If ( % 16 ) <nl> - block0 ( ) : <nl> - % 18 : int [ ] = prim : : ListConstruct ( % 4 , % 5 ) <nl> - % 19 : Tensor = aten : : rand ( % 18 , % 3 , % 2 , % 1 ) <nl> - % b . 2 : Tensor = aten : : add_ ( % b . 1 , % 19 , % 0 ) <nl> - - > ( % b . 2 ) <nl> - block1 ( ) : <nl> - - > ( % b . 1 ) <nl> - return ( % b ) <nl> deleted file mode 100644 <nl> index 0bdea9641e4c . . 000000000000 <nl> mmm a / test / expect / TestScript . test_mutable_dce_graph_input . expect <nl> ppp / dev / null <nl> <nl> - graph ( % a . 1 : Tensor ) : <nl> - % 1 : None = prim : : Constant ( ) <nl> - % 2 : int = prim : : Constant [ value = 1 ] ( ) <nl> - % 3 : Device = prim : : Constant [ value = " cpu " ] ( ) <nl> - % 4 : int = prim : : Constant [ value = 0 ] ( ) <nl> - % 5 : int = prim : : Constant [ value = 6 ] ( ) <nl> - % 6 : int = prim : : Constant [ value = 2 ] ( ) <nl> - % 7 : int = prim : : Constant [ value = 3 ] ( ) <nl> - % 8 : int [ ] = prim : : ListConstruct ( % 6 , % 7 ) <nl> - % 9 : Tensor = aten : : rand ( % 8 , % 5 , % 4 , % 3 ) <nl> - % a : Tensor = aten : : add_ ( % a . 1 , % 9 , % 2 ) <nl> - return ( % 1 ) <nl> deleted file mode 100644 <nl> index d7574401189f . . 000000000000 <nl> mmm a / test / expect / TestScript . test_mutable_dce_list . expect <nl> ppp / dev / null <nl> <nl> - graph ( % a : Tensor ) : <nl> - % 1 : int = prim : : Constant [ value = 1 ] ( ) <nl> - % 2 : Device = prim : : Constant [ value = " cpu " ] ( ) <nl> - % 3 : int = prim : : Constant [ value = 6 ] ( ) <nl> - % 4 : int = prim : : Constant [ value = 0 ] ( ) <nl> - % 5 : int = prim : : Constant [ value = 2 ] ( ) <nl> - % 6 : int = prim : : Constant [ value = 3 ] ( ) <nl> - % l : Tensor [ ] = prim : : ListConstruct ( ) <nl> - % 8 : Tensor [ ] = aten : : append ( % l , % a ) <nl> - % c . 1 : Tensor = aten : : select ( % l , % 4 ) <nl> - % 10 : int [ ] = prim : : ListConstruct ( % 5 , % 6 ) <nl> - % b : Tensor = aten : : rand ( % 10 , % 3 , % 4 , % 2 ) <nl> - % 12 : int [ ] = prim : : ListConstruct ( % 5 , % 6 ) <nl> - % 13 : Tensor = aten : : rand ( % 12 , % 3 , % 4 , % 2 ) <nl> - % c : Tensor = aten : : add_ ( % c . 1 , % 13 , % 1 ) <nl> - return ( % b ) <nl> deleted file mode 100644 <nl> index 8f746d01d4d3 . . 000000000000 <nl> mmm a / test / expect / TestScript . test_mutable_dce_loop . expect <nl> ppp / dev / null <nl> <nl> - graph ( % a : Tensor ) : <nl> - % 1 : Device = prim : : Constant [ value = " cpu " ] ( ) <nl> - % 2 : int = prim : : Constant [ value = 6 ] ( ) <nl> - % i . 1 : int = prim : : Constant [ value = 0 ] ( ) <nl> - % 4 : int = prim : : Constant [ value = 2 ] ( ) <nl> - % 5 : int = prim : : Constant [ value = 3 ] ( ) <nl> - % 6 : int = prim : : Constant [ value = 9223372036854775807 ] ( ) <nl> - % 7 : int = prim : : Constant [ value = 1 ] ( ) <nl> - % l : Tensor [ ] = prim : : ListConstruct ( ) <nl> - % 9 : Tensor [ ] = aten : : append ( % l , % a ) <nl> - % 10 : int [ ] = prim : : ListConstruct ( % 4 , % 5 ) <nl> - % b : Tensor = aten : : rand ( % 10 , % 2 , % i . 1 , % 1 ) <nl> - % 12 : bool = aten : : lt ( % i . 1 , % 7 ) <nl> - % i : int = prim : : Loop ( % 6 , % 12 , % i . 1 ) <nl> - block0 ( % 14 : int , % 15 : int ) : <nl> - % c . 1 : Tensor = aten : : select ( % l , % i . 1 ) <nl> - % 17 : int [ ] = prim : : ListConstruct ( % 4 , % 5 ) <nl> - % 18 : Tensor = aten : : rand ( % 17 , % 2 , % i . 1 , % 1 ) <nl> - % c : Tensor = aten : : add_ ( % c . 1 , % 18 , % 7 ) <nl> - % i . 2 : int = aten : : add ( % 15 , % 7 ) <nl> - % 21 : bool = aten : : lt ( % i . 2 , % 7 ) <nl> - - > ( % 21 , % i . 2 ) <nl> - return ( % b ) <nl> deleted file mode 100644 <nl> index e6c8b39f9fe7 . . 000000000000 <nl> mmm a / test / expect / TestScript . test_tuple_indexing . expect <nl> ppp / dev / null <nl> <nl> - graph ( % a : Tensor ) : <nl> - % 1 : int = prim : : Constant [ value = 1 ] ( ) <nl> - % 2 : int = prim : : Constant [ value = 2 ] ( ) <nl> - % 3 : int = prim : : Constant [ value = 0 ] ( ) <nl> - % 4 : bool = prim : : Bool ( % a ) <nl> - % b : ( int , int ) = prim : : If ( % 4 ) <nl> - block0 ( ) : <nl> - % b . 1 : ( int , int ) = prim : : TupleConstruct ( % 1 , % 2 ) <nl> - - > ( % b . 1 ) <nl> - block1 ( ) : <nl> - % b . 2 : ( int , int ) = prim : : TupleConstruct ( % 3 , % 2 ) <nl> - - > ( % b . 2 ) <nl> - % 8 : int = prim : : TupleIndex [ index = 0 ] ( % b ) <nl> - % 9 : int = prim : : TupleIndex [ index = 1 ] ( % b ) <nl> - % 10 : ( int , int ) = prim : : TupleConstruct ( % 8 , % 9 ) <nl> - return ( % 10 ) <nl> deleted file mode 100644 <nl> index 1e3453f1b9ff . . 000000000000 <nl> mmm a / test / expect / TestScript . test_tuple_slicing . expect <nl> ppp / dev / null <nl> <nl> - graph ( % a : Tensor ) : <nl> - % 1 : int = prim : : Constant [ value = 1 ] ( ) <nl> - % 2 : int = prim : : Constant [ value = 2 ] ( ) <nl> - % 3 : int = prim : : Constant [ value = 3 ] ( ) <nl> - % 4 : int = prim : : Constant [ value = 4 ] ( ) <nl> - % 5 : bool = prim : : Bool ( % a ) <nl> - % b : ( int , int , int , int ) = prim : : If ( % 5 ) <nl> - block0 ( ) : <nl> - % b . 1 : ( int , int , int , int ) = prim : : TupleConstruct ( % 1 , % 2 , % 3 , % 4 ) <nl> - - > ( % b . 1 ) <nl> - block1 ( ) : <nl> - % b . 2 : ( int , int , int , int ) = prim : : TupleConstruct ( % 4 , % 3 , % 2 , % 1 ) <nl> - - > ( % b . 2 ) <nl> - % c : ( int , int , int , int ) = prim : : TupleSlice [ beg = 0 , end = 4 ] ( % b ) <nl> - % e : ( int , int ) = prim : : TupleSlice [ beg = 1 , end = 3 ] ( % c ) <nl> - return ( % e ) <nl> mmm a / test / test_jit . py <nl> ppp b / test / test_jit . py <nl> def diff_type_unused ( ) : <nl> print ( c0 ) <nl> return 1 <nl> <nl> - def test_if_list ( self ) : <nl> - # testing that different length lists don ' t throw error <nl> + def test_if_list_cat ( self ) : <nl> + # testing that different length lists don ' t throw error on cat in shape prop <nl> @ torch . jit . script <nl> def test_list ( x ) : <nl> - if True : <nl> + if bool ( x . sum ( ) < 1 ) : <nl> c = [ x , x ] <nl> else : <nl> c = [ x , x , x ] <nl> def test_list ( x ) : <nl> <nl> b = torch . zeros ( 2 , 4 ) <nl> test_list . graph . propagate_shapes ( ( b , ) , False ) <nl> - self . assertExpected ( canonical ( test_list . graph ) ) <nl> <nl> def test_if_supertype ( self ) : <nl> @ torch . jit . script <nl> def tensor_unifying ( x , y , z ) : <nl> - <nl> # testing dynamic is appropriately set for y and z <nl> if True : <nl> x , y , z = x , y , z <nl> def tensor_unifying ( x , y , z ) : <nl> c = torch . zeros ( 2 , 4 , dtype = torch . float ) <nl> <nl> tensor_unifying . graph . propagate_shapes ( ( a , b , c ) , False ) <nl> - self . assertExpected ( canonical ( tensor_unifying . graph ) ) <nl> + if_outputs = list ( tensor_unifying . graph . findNode ( " prim : : If " ) . outputs ( ) ) <nl> + self . assertTrue ( if_outputs [ 0 ] . type ( ) . str ( ) = = " Float ( * , * ) " ) <nl> + self . assertTrue ( if_outputs [ 1 ] . type ( ) . str ( ) = = " Tensor " ) <nl> + self . assertTrue ( if_outputs [ 2 ] . type ( ) . str ( ) = = " Tensor " ) <nl> <nl> def test_list_unify ( self ) : <nl> # allowing a unififed int ? [ ] would cause a runtime error b / c <nl> def foo ( x , y ) : <nl> a = torch . zeros ( 2 , 2 ) <nl> b = torch . zeros ( 4 , dtype = torch . long ) <nl> torch . _C . _jit_pass_complete_shape_analysis ( foo . graph , ( a , b ) , False ) <nl> - self . assertExpected ( canonical ( foo . graph ) ) <nl> + FileCheck ( ) . check ( " Double ( 2 , 4 ) " ) . run ( str ( foo . graph ) ) <nl> <nl> def test_onnx_export_speculate ( self ) : <nl> <nl> def test_index_put ( target , indices , rhs ) : <nl> target [ indices ] = rhs <nl> return target <nl> <nl> - self . assertExpectedGraph ( test_index_put . graph ) <nl> + FileCheck ( ) . check ( " aten : : view " ) . check ( " index_put_ " ) . run ( str ( test_index_put . graph ) ) <nl> <nl> def test_index_put_trace_without_view ( self ) : <nl> @ _trace ( torch . rand ( 100 ) , torch . tensor ( [ 1 , 2 , 3 , 4 ] ) , torch . rand ( 4 ) ) <nl> def test_index_put ( target , indices , rhs ) : <nl> target [ indices ] = rhs <nl> return target <nl> <nl> - self . assertExpectedGraph ( test_index_put . graph ) <nl> + FileCheck ( ) . check_not ( " aten : : view " ) . check ( " index_put_ " ) . run ( str ( test_index_put . graph ) ) <nl> <nl> def test_tuple_indexing ( self ) : <nl> def tuple_index ( a ) : <nl> def tuple_index ( a ) : <nl> b = ( 0 , 2 ) <nl> return b [ - 2 ] , b [ 1 ] <nl> <nl> + self . checkScript ( tuple_index , ( torch . tensor ( [ 0 ] ) , ) ) <nl> self . checkScript ( tuple_index , ( torch . tensor ( [ 1 ] ) , ) ) <nl> self . checkScript ( tuple_index , ( torch . tensor ( [ 1 ] ) , ) , optimize = True ) <nl> tuple_comp = torch . jit . script ( tuple_index ) <nl> - self . assertExpectedGraph ( tuple_comp . graph ) <nl> - self . assertEqual ( tuple_comp ( torch . tensor ( 1 ) ) , ( 1 , 2 ) ) <nl> + FileCheck ( ) . check_count ( " TupleIndex " , 2 , exactly = True ) . run ( str ( tuple_comp . graph ) ) <nl> <nl> with self . assertRaisesRegex ( RuntimeError , " tuple indices must be integer constants " ) : <nl> @ torch . jit . script <nl> def tuple_slice ( a ) : <nl> else : <nl> b = ( 4 , 3 , 2 , 1 ) <nl> c = b [ - 4 : 4 ] <nl> - d = b [ 0 : ] <nl> e = c [ 1 : - 1 ] <nl> return e <nl> <nl> self . checkScript ( tuple_slice , ( torch . tensor ( [ 1 ] ) , ) , optimize = True ) <nl> - tuple_graph = torch . jit . script ( tuple_slice ) <nl> - self . assertExpectedGraph ( tuple_graph . graph ) <nl> - self . run_pass ( ' lower_all_tuples ' , tuple_graph . graph ) <nl> - self . assertTrue ( ' Tuple ' not in str ( tuple_graph . graph ) ) <nl> + tuple_graph = torch . jit . script ( tuple_slice ) . graph <nl> + slices = tuple_graph . findAllNodes ( " prim : : TupleSlice " ) <nl> + num_outputs = set ( map ( lambda x : len ( x . output ( ) . type ( ) . elements ( ) ) , slices ) ) <nl> + # one tuple slice should have an output with 2 elements , other 4 <nl> + self . assertTrue ( num_outputs = = set ( [ 2 , 4 ] ) ) <nl> + self . run_pass ( ' lower_all_tuples ' , tuple_graph ) <nl> + self . assertTrue ( ' Tuple ' not in str ( tuple_graph ) ) <nl> tuple_comp = torch . jit . script ( tuple_slice ) <nl> self . assertEqual ( tuple_comp ( torch . tensor ( 1 ) ) , ( 2 , 3 ) ) <nl> <nl> def foo ( ) : <nl> # b should be cleaned up but not a <nl> return a <nl> <nl> - self . assertExpectedGraph ( foo . graph ) <nl> + FileCheck ( ) . check_count ( " aten : : rand " , 2 , exactly = True ) \ <nl> + . check_count ( " aten : : add " , 1 , exactly = True ) . run ( str ( foo . graph ) ) <nl> <nl> def test_mutable_dce_block ( self ) : <nl> @ torch . jit . script <nl> def foo ( ) : <nl> # a should be cleaned up but not b <nl> return b <nl> <nl> - self . assertExpectedGraph ( foo . graph ) <nl> + FileCheck ( ) . check ( " prim : : If " ) . check_count ( " aten : : rand " , 1 , exactly = True ) \ <nl> + . run ( str ( foo . graph ) ) <nl> <nl> def test_mutable_dce_graph_input ( self ) : <nl> @ torch . jit . script <nl> def foo ( a ) : <nl> a + = torch . rand ( 2 , 3 ) <nl> # shouldn ' t clean up ` a ` even though it ' s not used in the output <nl> <nl> - self . assertExpectedGraph ( foo . graph ) <nl> + FileCheck ( ) . check ( " aten : : rand " ) . check ( " aten : : add " ) . run ( str ( foo . graph ) ) <nl> <nl> def test_mutable_dce_list ( self ) : <nl> @ torch . jit . script <nl> def foo ( a ) : <nl> c + = torch . rand ( 2 , 3 ) <nl> return b <nl> <nl> - self . assertExpectedGraph ( foo . graph ) <nl> + # c does not get cleaned up because there is a wildcard + mutation <nl> + FileCheck ( ) . check_count ( " aten : : rand " , 2 , exactly = True ) . run ( str ( foo . graph ) ) <nl> <nl> def test_mutable_dce_loop ( self ) : <nl> @ torch . jit . script <nl> def foo ( a ) : <nl> i + = 1 <nl> return b <nl> <nl> - self . assertExpectedGraph ( foo . graph ) <nl> + FileCheck ( ) . check ( " prim : : Loop " ) . check_not ( " aten : : rand " ) . check ( " aten : : select " ) \ <nl> + . check_count ( " aten : : rand " , 1 , exactly = True ) . run ( str ( foo . graph ) ) <nl> <nl> def test_mutable_dce_wildcards ( self ) : <nl> def fn ( ) : <nl>
|
Batch of expect file removals Remove dce expect files ( )
|
pytorch/pytorch
|
411cf434afe9c594dfb2a383d5c3475ee0726a28
|
2019-02-26T00:15:19Z
|
mmm a / xbmc / cores / dvdplayer / DVDDemuxers / DVDDemuxFFmpeg . cpp <nl> ppp b / xbmc / cores / dvdplayer / DVDDemuxers / DVDDemuxFFmpeg . cpp <nl> static void ff_flush_avutil_log_buffers ( void ) <nl> + + it ; <nl> } <nl> <nl> - static XbmcThreads : : ThreadLocal < CDVDDemuxFFmpeg > g_demuxer ; <nl> - <nl> - static int interrupt_cb ( void * unused ) <nl> + static int interrupt_cb ( void * ctx ) <nl> { <nl> - CDVDDemuxFFmpeg * demuxer = g_demuxer . get ( ) ; <nl> + CDVDDemuxFFmpeg * demuxer = static_cast < CDVDDemuxFFmpeg * > ( ctx ) ; <nl> if ( demuxer & & demuxer - > Aborted ( ) ) <nl> return 1 ; <nl> return 0 ; <nl> static int dvd_file_open ( URLContext * h , const char * filename , int flags ) <nl> <nl> static int dvd_file_read ( void * h , uint8_t * buf , int size ) <nl> { <nl> - if ( interrupt_cb ( NULL ) ) <nl> - return - 1 ; <nl> + if ( interrupt_cb ( h ) ) <nl> + return AVERROR_EXIT ; <nl> <nl> - CDVDInputStream * pInputStream = ( CDVDInputStream * ) h ; <nl> + CDVDInputStream * pInputStream = static_cast < CDVDDemuxFFmpeg * > ( h ) - > m_pInput ; <nl> return pInputStream - > Read ( buf , size ) ; <nl> } <nl> / * <nl> static int dvd_file_write ( URLContext * h , BYTE * buf , int size ) <nl> * / <nl> static offset_t dvd_file_seek ( void * h , offset_t pos , int whence ) <nl> { <nl> - if ( interrupt_cb ( NULL ) ) <nl> - return - 1 ; <nl> + if ( interrupt_cb ( h ) ) <nl> + return AVERROR_EXIT ; <nl> <nl> - CDVDInputStream * pInputStream = ( CDVDInputStream * ) h ; <nl> + CDVDInputStream * pInputStream = static_cast < CDVDDemuxFFmpeg * > ( h ) - > m_pInput ; <nl> if ( whence = = AVSEEK_SIZE ) <nl> return pInputStream - > GetLength ( ) ; <nl> else <nl> bool CDVDDemuxFFmpeg : : Open ( CDVDInputStream * pInput ) <nl> std : : string strFile ; <nl> m_iCurrentPts = DVD_NOPTS_VALUE ; <nl> m_speed = DVD_PLAYSPEED_NORMAL ; <nl> - g_demuxer . set ( this ) ; <nl> m_program = UINT_MAX ; <nl> - const AVIOInterruptCB int_cb = { interrupt_cb , NULL } ; <nl> + const AVIOInterruptCB int_cb = { interrupt_cb , this } ; <nl> <nl> if ( ! pInput ) return false ; <nl> <nl> bool CDVDDemuxFFmpeg : : Open ( CDVDInputStream * pInput ) <nl> iformat = m_dllAvFormat . av_find_input_format ( " mjpeg " ) ; <nl> } <nl> <nl> + / / open the demuxer <nl> + m_pFormatContext = m_dllAvFormat . avformat_alloc_context ( ) ; <nl> + m_pFormatContext - > interrupt_callback = int_cb ; <nl> + <nl> / / try to abort after 30 seconds <nl> m_timeout . Set ( 30000 ) ; <nl> <nl> bool CDVDDemuxFFmpeg : : Open ( CDVDInputStream * pInput ) <nl> } <nl> <nl> <nl> - / / open the demuxer <nl> - m_pFormatContext = m_dllAvFormat . avformat_alloc_context ( ) ; <nl> m_pFormatContext - > pb = m_ioContext ; <nl> <nl> if ( m_dllAvFormat . avformat_open_input ( & m_pFormatContext , strFile . c_str ( ) , iformat , NULL ) < 0 ) <nl> bool CDVDDemuxFFmpeg : : Open ( CDVDInputStream * pInput ) <nl> } <nl> } <nl> <nl> - / / set the interrupt callback , appeared in libavformat 53 . 15 . 0 <nl> - m_pFormatContext - > interrupt_callback = int_cb ; <nl> - <nl> / / Avoid detecting framerate if advancedsettings . xml says so <nl> if ( g_advancedSettings . m_videoFpsDetect = = 0 ) <nl> m_pFormatContext - > fps_probe_size = 0 ; <nl> bool CDVDDemuxFFmpeg : : Open ( CDVDInputStream * pInput ) <nl> <nl> void CDVDDemuxFFmpeg : : Dispose ( ) <nl> { <nl> - g_demuxer . set ( this ) ; <nl> - <nl> if ( m_pFormatContext ) <nl> { <nl> if ( m_ioContext & & m_pFormatContext - > pb & & m_pFormatContext - > pb ! = m_ioContext ) <nl> void CDVDDemuxFFmpeg : : Reset ( ) <nl> <nl> void CDVDDemuxFFmpeg : : Flush ( ) <nl> { <nl> - g_demuxer . set ( this ) ; <nl> - <nl> / / naughty usage of an internal ffmpeg function <nl> if ( m_pFormatContext ) <nl> m_dllAvFormat . av_read_frame_flush ( m_pFormatContext ) ; <nl> void CDVDDemuxFFmpeg : : Abort ( ) <nl> <nl> void CDVDDemuxFFmpeg : : SetSpeed ( int iSpeed ) <nl> { <nl> - g_demuxer . set ( this ) ; <nl> - <nl> if ( ! m_pFormatContext ) <nl> return ; <nl> <nl> double CDVDDemuxFFmpeg : : ConvertTimestamp ( int64_t pts , int den , int num ) <nl> <nl> DemuxPacket * CDVDDemuxFFmpeg : : Read ( ) <nl> { <nl> - g_demuxer . set ( this ) ; <nl> - <nl> AVPacket pkt ; <nl> DemuxPacket * pPacket = NULL ; <nl> / / on some cases where the received packet is invalid we will need to return an empty packet ( 0 length ) otherwise the main loop ( in CDVDPlayer ) <nl> DemuxPacket * CDVDDemuxFFmpeg : : Read ( ) <nl> <nl> bool CDVDDemuxFFmpeg : : SeekTime ( int time , bool backwords , double * startpts ) <nl> { <nl> - g_demuxer . set ( this ) ; <nl> - <nl> if ( time < 0 ) <nl> time = 0 ; <nl> <nl> bool CDVDDemuxFFmpeg : : SeekTime ( int time , bool backwords , double * startpts ) <nl> <nl> bool CDVDDemuxFFmpeg : : SeekByte ( int64_t pos ) <nl> { <nl> - g_demuxer . set ( this ) ; <nl> - <nl> CSingleLock lock ( m_critSection ) ; <nl> int ret = m_dllAvFormat . av_seek_frame ( m_pFormatContext , - 1 , pos , AVSEEK_FLAG_BYTE ) ; <nl> <nl> mmm a / xbmc / cores / dvdplayer / DVDDemuxers / DVDDemuxFFmpeg . h <nl> ppp b / xbmc / cores / dvdplayer / DVDDemuxers / DVDDemuxFFmpeg . h <nl> class CDVDDemuxFFmpeg : public CDVDDemux <nl> bool Aborted ( ) ; <nl> <nl> AVFormatContext * m_pFormatContext ; <nl> + CDVDInputStream * m_pInput ; <nl> <nl> protected : <nl> friend class CDemuxStreamAudioFFmpeg ; <nl> class CDVDDemuxFFmpeg : public CDVDDemux <nl> unsigned m_program ; <nl> XbmcThreads : : EndTime m_timeout ; <nl> <nl> - CDVDInputStream * m_pInput ; <nl> } ; <nl> <nl>
|
dvdplayer : complete the update of ffmpeg interrupt interface
|
xbmc/xbmc
|
9ced9efad2309a5768bf8a256fa51699f883e64d
|
2013-04-06T10:59:01Z
|
mmm a / . travis . yml <nl> ppp b / . travis . yml <nl> install : <nl> script : <nl> - buck test / / : yoga <nl> - buck test / / java : java <nl> - - buck test / / YogaKit : YogaKitTests - - config cxx . default_platform = iphonesimulator - x86_64 - - config cxx . cflags = - DTRAVIS_CI <nl> + - buck test / / YogaKit : YogaKitTests - - config cxx . default_platform = iphonesimulator - x86_64 <nl> - sh csharp / tests / Facebook . Yoga / test_macos . sh <nl> <nl> - cd javascript <nl> mmm a / YogaKit / Tests / YogaKitTests . m <nl> ppp b / YogaKit / Tests / YogaKitTests . m <nl> @ interface YogaKitTests : XCTestCase <nl> <nl> @ implementation YogaKitTests <nl> <nl> - # ifndef TRAVIS_CI <nl> - <nl> - ( void ) testNodesAreDeallocedWithSingleView <nl> { <nl> - XCTAssertEqual ( 0 , YGNodeGetInstanceCount ( ) ) ; <nl> + __weak YGLayout * layoutRef = nil ; <nl> <nl> - UIView * view = [ [ UIView alloc ] initWithFrame : CGRectZero ] ; <nl> - view . yoga . flexBasis = 1 ; <nl> - XCTAssertEqual ( 1 , YGNodeGetInstanceCount ( ) ) ; <nl> - view = nil ; <nl> + @ autoreleasepool { <nl> + UIView * view = [ [ UIView alloc ] initWithFrame : CGRectZero ] ; <nl> + view . yoga . flexBasis = 1 ; <nl> + <nl> + layoutRef = view . yoga ; <nl> + XCTAssertNotNil ( layoutRef ) ; <nl> + <nl> + view = nil ; <nl> + } <nl> <nl> - XCTAssertEqual ( 0 , YGNodeGetInstanceCount ( ) ) ; <nl> + XCTAssertNil ( layoutRef ) ; <nl> } <nl> <nl> - ( void ) testNodesAreDeallocedCascade <nl> { <nl> - XCTAssertEqual ( 0 , YGNodeGetInstanceCount ( ) ) ; <nl> + __weak YGLayout * topLayout = nil ; <nl> + __weak YGLayout * subviewLayout = nil ; <nl> <nl> - UIView * view = [ [ UIView alloc ] initWithFrame : CGRectZero ] ; <nl> - view . yoga . flexBasis = 1 ; <nl> + @ autoreleasepool { <nl> + UIView * view = [ [ UIView alloc ] initWithFrame : CGRectZero ] ; <nl> + topLayout = view . yoga ; <nl> + topLayout . flexBasis = 1 ; <nl> <nl> - for ( int i = 0 ; i < 10 ; i + + ) { <nl> UIView * subview = [ [ UIView alloc ] initWithFrame : CGRectZero ] ; <nl> - subview . yoga . flexBasis = 1 ; <nl> - [ view addSubview : subview ] ; <nl> + subviewLayout = subview . yoga ; <nl> + subviewLayout . flexBasis = 1 ; <nl> + <nl> + view = nil ; <nl> } <nl> - XCTAssertEqual ( 11 , YGNodeGetInstanceCount ( ) ) ; <nl> - view = nil ; <nl> <nl> - XCTAssertEqual ( 0 , YGNodeGetInstanceCount ( ) ) ; <nl> + XCTAssertNil ( topLayout ) ; <nl> + XCTAssertNil ( subviewLayout ) ; <nl> } <nl> <nl> - # endif <nl> - <nl> - ( void ) testIsEnabled <nl> { <nl> UIView * view = [ [ UIView alloc ] initWithFrame : CGRectZero ] ; <nl> - ( void ) testSizeThatFitsSmoke <nl> <nl> UIView * textBadgeView = [ [ UIView alloc ] initWithFrame : CGRectZero ] ; <nl> textBadgeView . yoga . isEnabled = YES ; <nl> - textBadgeView . yoga . marginLeft = 3 . 0 ; <nl> + textBadgeView . yoga . margin = 0 ; <nl> textBadgeView . yoga . width = 10 ; <nl> textBadgeView . yoga . height = 10 ; <nl> [ container addSubview : textBadgeView ] ; <nl> <nl> + const CGSize textBadgeViewSize = textBadgeView . yoga . intrinsicSize ; <nl> + XCTAssertEqual ( 10 , textBadgeViewSize . height ) ; <nl> + XCTAssertEqual ( 10 , textBadgeViewSize . width ) ; <nl> + <nl> const CGSize containerSize = container . yoga . intrinsicSize ; <nl> - XCTAssertTrue ( CGSizeEqualToSize ( CGSizeMake ( 514 , 21 ) , containerSize ) , @ " Size is actually % @ " , NSStringFromCGSize ( containerSize ) ) ; <nl> + const CGSize longTextLabelSize = longTextLabel . yoga . intrinsicSize ; <nl> + <nl> + XCTAssertEqual ( containerSize . height , longTextLabelSize . height ) ; <nl> + XCTAssertEqual ( containerSize . width , longTextLabelSize . width + textBadgeView . yoga . intrinsicSize . width ) ; <nl> } <nl> <nl> - ( void ) testThatMarkingLeafsAsDirtyWillTriggerASizeRecalculation <nl> - ( void ) testThatMarkingLeafsAsDirtyWillTriggerASizeRecalculation <nl> [ container addSubview : label ] ; <nl> <nl> [ container . yoga applyLayout ] ; <nl> - XCTAssertTrue ( CGSizeEqualToSize ( CGSizeMake ( 146 , 21 ) , label . bounds . size ) , @ " Size is actually % @ " , NSStringFromCGSize ( label . bounds . size ) ) ; <nl> + CGSize const labelSizeAfterFirstPass = label . frame . size ; <nl> <nl> label . text = @ " This is a slightly longer text . " ; <nl> + XCTAssertTrue ( CGSizeEqualToSize ( label . frame . size , labelSizeAfterFirstPass ) ) ; <nl> + <nl> [ label . yoga markDirty ] ; <nl> <nl> [ container . yoga applyLayout ] ; <nl> - XCTAssertTrue ( CGSizeEqualToSize ( CGSizeMake ( 213 , 21 ) , label . bounds . size ) , @ " Size is actually % @ " , NSStringFromCGSize ( label . bounds . size ) ) ; <nl> + XCTAssertFalse ( CGSizeEqualToSize ( label . frame . size , labelSizeAfterFirstPass ) ) ; <nl> } <nl> <nl> - ( void ) testFrameAndOriginPlacement <nl> - ( void ) testFrameAndOriginPlacement <nl> container . yoga . isEnabled = YES ; <nl> container . yoga . flexDirection = YGFlexDirectionRow ; <nl> <nl> - for ( int i = 0 ; i < 3 ; i + + ) { <nl> - UIView * subview = [ [ UIView alloc ] initWithFrame : CGRectZero ] ; <nl> - subview . yoga . isEnabled = YES ; <nl> - subview . yoga . flexGrow = 1 ; <nl> + UIView * subview1 = [ [ UIView alloc ] initWithFrame : CGRectZero ] ; <nl> + subview1 . yoga . isEnabled = YES ; <nl> + subview1 . yoga . flexGrow = 1 ; <nl> + [ container addSubview : subview1 ] ; <nl> + <nl> + UIView * subview2 = [ [ UIView alloc ] initWithFrame : CGRectZero ] ; <nl> + subview2 . yoga . isEnabled = YES ; <nl> + subview2 . yoga . flexGrow = 1 ; <nl> + [ container addSubview : subview2 ] ; <nl> + <nl> + UIView * subview3 = [ [ UIView alloc ] initWithFrame : CGRectZero ] ; <nl> + subview3 . yoga . isEnabled = YES ; <nl> + subview3 . yoga . flexGrow = 1 ; <nl> + [ container addSubview : subview3 ] ; <nl> <nl> - [ container addSubview : subview ] ; <nl> - } <nl> [ container . yoga applyLayout ] ; <nl> <nl> - XCTAssertFalse ( CGRectIntersectsRect ( [ container . subviews objectAtIndex : 0 ] . frame , [ container . subviews objectAtIndex : 1 ] . frame ) ) ; <nl> - XCTAssertFalse ( CGRectIntersectsRect ( [ container . subviews objectAtIndex : 1 ] . frame , [ container . subviews objectAtIndex : 2 ] . frame ) ) ; <nl> - XCTAssertFalse ( CGRectIntersectsRect ( [ container . subviews objectAtIndex : 0 ] . frame , [ container . subviews objectAtIndex : 2 ] . frame ) ) ; <nl> + XCTAssertEqualWithAccuracy ( subview2 . frame . origin . x , CGRectGetMaxX ( subview1 . frame ) , FLT_EPSILON ) ; <nl> + XCTAssertEqualWithAccuracy ( subview3 . frame . origin . x , CGRectGetMaxX ( subview2 . frame ) , FLT_EPSILON ) ; <nl> <nl> CGFloat totalWidth = 0 ; <nl> for ( UIView * view in container . subviews ) { <nl>
|
Make YogaKit tests pass whether they are run in Xcode or BUCK .
|
facebook/yoga
|
a4bab688024c97508341e2e0fc8449f73740a106
|
2017-01-24T03:39:37Z
|
mmm a / cpp - package / include / mxnet - cpp / ndarray . h <nl> ppp b / cpp - package / include / mxnet - cpp / ndarray . h <nl> class NDArray { <nl> * / <nl> std : : vector < mx_uint > GetShape ( ) const ; <nl> / * ! <nl> + * \ return the data type of current NDArray <nl> + * / <nl> + int GetDType ( ) const ; <nl> + / * ! <nl> * \ return the data pointer to the current NDArray <nl> * / <nl> const mx_float * GetData ( ) const ; <nl> mmm a / cpp - package / include / mxnet - cpp / ndarray . hpp <nl> ppp b / cpp - package / include / mxnet - cpp / ndarray . hpp <nl> inline std : : vector < mx_uint > NDArray : : GetShape ( ) const { <nl> <nl> inline int NDArray : : GetDType ( ) const { <nl> int ret ; <nl> - MXNDArrayGetDType ( blob_ptr_ - > handle , & ret ) ; <nl> + MXNDArrayGetDType ( blob_ptr_ - > handle_ , & ret ) ; <nl> return ret ; <nl> } <nl> <nl>
|
Adds GetDType ( ) signature to ndarray . h and fixes typo in implementation . ( )
|
apache/incubator-mxnet
|
5a144585281d58f4e51e3aba14abf04fce33a569
|
2017-04-04T17:51:57Z
|
mmm a / emrun . py <nl> ppp b / emrun . py <nl> def serve_forever ( self , timeout = 0 . 5 ) : <nl> if browser_quit_code is not None : <nl> delete_emrun_safe_firefox_profile ( ) <nl> if not emrun_options . serve_after_close : <nl> - if not have_received_messages : <nl> - emrun_options . serve_after_close = True <nl> - logv ( ' Warning : emrun got detached from the target browser process ( the process quit with code ' + str ( browser_quit_code ) + ' ) . Cannot detect when user closes the browser . Behaving as if - - serve_after_close was passed in . ' ) <nl> - if not emrun_options . browser : <nl> - logv ( ' Try passing the - - browser = / path / to / browser option to avoid this from occurring . See https : / / github . com / emscripten - core / emscripten / issues / 3234 for more discussion . ' ) <nl> - else : <nl> - self . shutdown ( ) <nl> - logv ( ' Browser process has quit . Shutting down web server . . Pass - - serve_after_close to keep serving the page even after the browser closes . ' ) <nl> + emrun_options . serve_after_close = True <nl> + logv ( ' Warning : emrun got detached from the target browser process ( the process quit with code ' + str ( browser_quit_code ) + ' ) . Cannot detect when user closes the browser . Behaving as if - - serve_after_close was passed in . ' ) <nl> + if not emrun_options . browser : <nl> + logv ( ' Try passing the - - browser = / path / to / browser option to avoid this from occurring . See https : / / github . com / emscripten - core / emscripten / issues / 3234 for more discussion . ' ) <nl> <nl> # Serve HTTP <nl> self . handle_request ( ) <nl>
|
emrun stability fix ( )
|
emscripten-core/emscripten
|
83470f1d537b41c2ad518a1ddeb24fa2d3458d5d
|
2019-04-26T19:59:56Z
|
mmm a / lib / Sema / TypeCheckDecl . cpp <nl> ppp b / lib / Sema / TypeCheckDecl . cpp <nl> TypeChecker : : handleSILGenericParams ( GenericParamList * genericParams , <nl> prepareGenericParamList ( genericParams , DC ) ; <nl> <nl> parentEnv = checkGenericEnvironment ( genericParams , DC , parentSig , <nl> - / * allowConcreteGenericParams = * / true ) ; <nl> + / * allowConcreteGenericParams = * / true , <nl> + / * ext = * / nullptr ) ; <nl> parentSig = parentEnv - > getGenericSignature ( ) ; <nl> <nl> / / Compute the final set of archetypes . <nl> checkExtensionGenericParams ( TypeChecker & tc , ExtensionDecl * ext , Type type , <nl> auto * env = tc . checkGenericEnvironment ( genericParams , <nl> ext - > getDeclContext ( ) , nullptr , <nl> / * allowConcreteGenericParams = * / true , <nl> - inferExtendedTypeReqs ) ; <nl> + ext , inferExtendedTypeReqs ) ; <nl> <nl> / / Validate the generic parameters for the last time , to splat down <nl> / / actual archetypes . <nl> mmm a / lib / Sema / TypeCheckGeneric . cpp <nl> ppp b / lib / Sema / TypeCheckGeneric . cpp <nl> static void visitOuterToInner ( <nl> visitor ( genericParams ) ; <nl> } <nl> <nl> + / / / Retrieve the generic parameter depth of the extended type . <nl> + static unsigned getExtendedTypeGenericDepth ( ExtensionDecl * ext ) { <nl> + auto nominal = ext - > getAsNominalTypeOrNominalTypeExtensionContext ( ) ; <nl> + if ( ! nominal ) return static_cast < unsigned > ( - 1 ) ; <nl> + <nl> + auto sig = nominal - > getGenericSignatureOfContext ( ) ; <nl> + if ( ! sig ) return static_cast < unsigned > ( - 1 ) ; <nl> + <nl> + return sig - > getGenericParams ( ) . back ( ) - > getDepth ( ) ; <nl> + } <nl> + <nl> GenericEnvironment * TypeChecker : : checkGenericEnvironment ( <nl> GenericParamList * genericParams , <nl> DeclContext * dc , <nl> GenericSignature * parentSig , <nl> bool allowConcreteGenericParams , <nl> + ExtensionDecl * ext , <nl> llvm : : function_ref < void ( GenericSignatureBuilder & ) > <nl> inferRequirements ) { <nl> assert ( genericParams & & " Missing generic parameters ? " ) ; <nl> bool recursivelyVisitGenericParams = <nl> genericParams - > getOuterParameters ( ) & & ! parentSig ; <nl> <nl> - / / Collect the generic parameters . <nl> - SmallVector < GenericTypeParamType * , 4 > allGenericParams ; <nl> - if ( recursivelyVisitGenericParams ) { <nl> - visitOuterToInner ( genericParams , <nl> - [ & ] ( GenericParamList * gpList ) { <nl> - addGenericParamTypes ( gpList , allGenericParams ) ; <nl> - } ) ; <nl> - } else { <nl> - if ( parentSig ) { <nl> - allGenericParams . append ( parentSig - > getGenericParams ( ) . begin ( ) , <nl> - parentSig - > getGenericParams ( ) . end ( ) ) ; <nl> + GenericSignature * sig ; <nl> + if ( ! ext | | ext - > getTrailingWhereClause ( ) | | <nl> + getExtendedTypeGenericDepth ( ext ) ! = genericParams - > getDepth ( ) ) { <nl> + / / Collect the generic parameters . <nl> + SmallVector < GenericTypeParamType * , 4 > allGenericParams ; <nl> + if ( recursivelyVisitGenericParams ) { <nl> + visitOuterToInner ( genericParams , <nl> + [ & ] ( GenericParamList * gpList ) { <nl> + addGenericParamTypes ( gpList , allGenericParams ) ; <nl> + } ) ; <nl> + } else { <nl> + if ( parentSig ) { <nl> + allGenericParams . append ( parentSig - > getGenericParams ( ) . begin ( ) , <nl> + parentSig - > getGenericParams ( ) . end ( ) ) ; <nl> + } <nl> + <nl> + addGenericParamTypes ( genericParams , allGenericParams ) ; <nl> } <nl> <nl> - addGenericParamTypes ( genericParams , allGenericParams ) ; <nl> - } <nl> + / / Create the generic signature builder . <nl> + GenericSignatureBuilder builder ( Context , LookUpConformance ( * this , dc ) ) ; <nl> <nl> - / / Create the generic signature builder . <nl> - ModuleDecl * module = dc - > getParentModule ( ) ; <nl> - GenericSignatureBuilder builder ( Context , LookUpConformance ( * this , dc ) ) ; <nl> + / / Type check the generic parameters , treating all generic type <nl> + / / parameters as dependent , unresolved . <nl> + DependentGenericTypeResolver dependentResolver ; <nl> + if ( recursivelyVisitGenericParams ) { <nl> + visitOuterToInner ( genericParams , <nl> + [ & ] ( GenericParamList * gpList ) { <nl> + checkGenericParamList ( & builder , gpList , nullptr , & dependentResolver ) ; <nl> + } ) ; <nl> + } else { <nl> + checkGenericParamList ( & builder , genericParams , parentSig , <nl> + & dependentResolver ) ; <nl> + } <nl> <nl> - / / Type check the generic parameters , treating all generic type <nl> - / / parameters as dependent , unresolved . <nl> - DependentGenericTypeResolver dependentResolver ; <nl> - if ( recursivelyVisitGenericParams ) { <nl> - visitOuterToInner ( genericParams , <nl> - [ & ] ( GenericParamList * gpList ) { <nl> - checkGenericParamList ( & builder , gpList , nullptr , & dependentResolver ) ; <nl> - } ) ; <nl> - } else { <nl> - checkGenericParamList ( & builder , genericParams , parentSig , <nl> - & dependentResolver ) ; <nl> - } <nl> + / / / Perform any necessary requirement inference . <nl> + inferRequirements ( builder ) ; <nl> <nl> - / / / Perform any necessary requirement inference . <nl> - inferRequirements ( builder ) ; <nl> + / / Finalize the generic requirements . <nl> + ( void ) builder . finalize ( genericParams - > getSourceRange ( ) . Start , <nl> + allGenericParams , <nl> + allowConcreteGenericParams ) ; <nl> <nl> - / / Finalize the generic requirements . <nl> - ( void ) builder . finalize ( genericParams - > getSourceRange ( ) . Start , <nl> - allGenericParams , <nl> - allowConcreteGenericParams ) ; <nl> + / / The generic signature builder now has all of the requirements , although <nl> + / / there might still be errors that have not yet been diagnosed . Revert the <nl> + / / signature and type - check it again , completely . <nl> + if ( recursivelyVisitGenericParams ) { <nl> + visitOuterToInner ( genericParams , <nl> + [ & ] ( GenericParamList * gpList ) { <nl> + revertGenericParamList ( gpList ) ; <nl> + } ) ; <nl> + } else { <nl> + revertGenericParamList ( genericParams ) ; <nl> + } <nl> <nl> - / / The generic signature builder now has all of the requirements , although <nl> - / / there might still be errors that have not yet been diagnosed . Revert the <nl> - / / signature and type - check it again , completely . <nl> - if ( recursivelyVisitGenericParams ) { <nl> - visitOuterToInner ( genericParams , <nl> - [ & ] ( GenericParamList * gpList ) { <nl> - revertGenericParamList ( gpList ) ; <nl> - } ) ; <nl> - } else { <nl> - revertGenericParamList ( genericParams ) ; <nl> - } <nl> + / / Record the generic type parameter types and the requirements . <nl> + sig = builder . getGenericSignature ( ) ; <nl> <nl> - / / Record the generic type parameter types and the requirements . <nl> - auto sig = builder . getGenericSignature ( ) ; <nl> - <nl> - / / Debugging of the generic signature builder and generic signature <nl> - / / generation . <nl> - if ( Context . LangOpts . DebugGenericSignatures ) { <nl> - dc - > printContext ( llvm : : errs ( ) ) ; <nl> - llvm : : errs ( ) < < " \ n " ; <nl> - builder . dump ( llvm : : errs ( ) ) ; <nl> - llvm : : errs ( ) < < " Generic signature : " ; <nl> - sig - > print ( llvm : : errs ( ) ) ; <nl> - llvm : : errs ( ) < < " \ n " ; <nl> - llvm : : errs ( ) < < " Canonical generic signature : " ; <nl> - sig - > getCanonicalSignature ( ) - > print ( llvm : : errs ( ) ) ; <nl> - llvm : : errs ( ) < < " \ n " ; <nl> + / / Debugging of the generic signature builder and generic signature <nl> + / / generation . <nl> + if ( Context . LangOpts . DebugGenericSignatures ) { <nl> + dc - > printContext ( llvm : : errs ( ) ) ; <nl> + llvm : : errs ( ) < < " \ n " ; <nl> + builder . dump ( llvm : : errs ( ) ) ; <nl> + llvm : : errs ( ) < < " Generic signature : " ; <nl> + sig - > print ( llvm : : errs ( ) ) ; <nl> + llvm : : errs ( ) < < " \ n " ; <nl> + llvm : : errs ( ) < < " Canonical generic signature : " ; <nl> + sig - > getCanonicalSignature ( ) - > print ( llvm : : errs ( ) ) ; <nl> + llvm : : errs ( ) < < " \ n " ; <nl> + } <nl> + } else { <nl> + / / Re - use the signature of the type being extended . <nl> + sig = ext - > getAsNominalTypeOrNominalTypeExtensionContext ( ) <nl> + - > getGenericSignatureOfContext ( ) ; <nl> } <nl> <nl> CompleteGenericTypeResolver completeResolver ( * this , sig , <nl> GenericEnvironment * TypeChecker : : checkGenericEnvironment ( <nl> } <nl> <nl> / / Form the generic environment . <nl> + ModuleDecl * module = dc - > getParentModule ( ) ; <nl> return sig - > createGenericEnvironment ( * module ) ; <nl> } <nl> <nl> void TypeChecker : : validateGenericTypeSignature ( GenericTypeDecl * typeDecl ) { <nl> proto - > computeRequirementSignature ( ) ; <nl> } <nl> <nl> - auto * env = checkGenericEnvironment ( gp , dc , dc - > getGenericSignatureOfContext ( ) , <nl> - / * allowConcreteGenericParams = * / false ) ; <nl> + auto * env = checkGenericEnvironment ( gp , dc , <nl> + dc - > getGenericSignatureOfContext ( ) , <nl> + / * allowConcreteGenericParams = * / false , <nl> + / * ext = * / nullptr ) ; <nl> typeDecl - > setGenericEnvironment ( env ) ; <nl> } <nl> <nl> mmm a / lib / Sema / TypeChecker . h <nl> ppp b / lib / Sema / TypeChecker . h <nl> class TypeChecker final : public LazyResolver { <nl> / / / context , if not available as part of the \ c dc argument ( used <nl> / / / for SIL parsing ) . <nl> / / / <nl> + / / / \ param ext The extension for which we ' re checking the generic <nl> + / / / environment , or null if we ' re not checking an extension . <nl> + / / / <nl> / / / \ param inferRequirements When non - empty , callback that will be invoked <nl> / / / to perform any additional requirement inference that contributes to the <nl> / / / generic environment . . <nl> class TypeChecker final : public LazyResolver { <nl> DeclContext * dc , <nl> GenericSignature * outerSignature , <nl> bool allowConcreteGenericParams , <nl> + ExtensionDecl * ext , <nl> llvm : : function_ref < void ( GenericSignatureBuilder & ) > <nl> inferRequirements ) ; <nl> <nl> class TypeChecker final : public LazyResolver { <nl> GenericParamList * genericParams , <nl> DeclContext * dc , <nl> GenericSignature * outerSignature , <nl> - bool allowConcreteGenericParams ) { <nl> + bool allowConcreteGenericParams , <nl> + ExtensionDecl * ext ) { <nl> return checkGenericEnvironment ( genericParams , dc , outerSignature , <nl> - allowConcreteGenericParams , <nl> + allowConcreteGenericParams , ext , <nl> [ & ] ( GenericSignatureBuilder & ) { } ) ; <nl> } <nl> <nl>
|
Make unconstrained extensions use the generic signature of extended type .
|
apple/swift
|
da56cb33b852fe1ad769cebab0e49cdb3d2310b7
|
2017-09-22T18:32:25Z
|
mmm a / src / core / lib / iomgr / udp_server . h <nl> ppp b / src / core / lib / iomgr / udp_server . h <nl> typedef void ( * grpc_udp_server_write_cb ) ( grpc_exec_ctx * exec_ctx , grpc_fd * emfd , <nl> / * Called when the grpc_fd is about to be orphaned ( and the FD closed ) . * / <nl> typedef void ( * grpc_udp_server_orphan_cb ) ( grpc_exec_ctx * exec_ctx , <nl> grpc_fd * emfd , <nl> - grpc_closure * shutdown_fd_callback , <nl> + grpc_closure * shutdown_fd_callback , <nl> void * user_data ) ; <nl> <nl> / * Create a server , initially not bound to any ports * / <nl> mmm a / test / core / iomgr / udp_server_test . c <nl> ppp b / test / core / iomgr / udp_server_test . c <nl> static void on_write ( grpc_exec_ctx * exec_ctx , grpc_fd * emfd , void * user_data ) { <nl> } <nl> <nl> static void on_fd_orphaned ( grpc_exec_ctx * exec_ctx , grpc_fd * emfd , <nl> - grpc_closure * closure , void * user_data ) { <nl> + grpc_closure * closure , void * user_data ) { <nl> gpr_log ( GPR_INFO , " gRPC FD about to be orphaned : % d " , <nl> grpc_fd_wrapped_fd ( emfd ) ) ; <nl> g_number_of_orphan_calls + + ; <nl>
|
clang format
|
grpc/grpc
|
2d38b05671ca0c6006c775ccb8cbb945118a794c
|
2017-04-06T17:09:34Z
|
mmm a / xbmc / Application . cpp <nl> ppp b / xbmc / Application . cpp <nl> bool CApplication : : OnEvent ( XBMC_Event & newEvent ) <nl> { <nl> / / Special media keys are mapped to WM_APPCOMMAND on Windows ( and to DBUS events on Linux ? ) <nl> / / XBMC translates WM_APPCOMMAND to XBMC_APPCOMMAND events . <nl> - g_application . OnAction ( CAction ( newEvent . appcommand . action ) ) ; <nl> + g_application . OnAppCommand ( CAction ( newEvent . appcommand . action ) ) ; <nl> } <nl> break ; <nl> } <nl> bool CApplication : : OnKey ( const CKey & key ) <nl> return OnAction ( action ) ; <nl> } <nl> <nl> + / / OnAppCommand is called in response to a XBMC_APPCOMMAND event . <nl> + <nl> + bool CApplication : : OnAppCommand ( const CAction & action ) <nl> + { <nl> + / / Reset the screen saver <nl> + ResetScreenSaver ( ) ; <nl> + <nl> + / / If we were currently in the screen saver wake up and don ' t process the appcommand <nl> + if ( WakeUpScreenSaverAndDPMS ( ) ) <nl> + { <nl> + return true ; <nl> + } <nl> + <nl> + / / Process the appcommand <nl> + return OnAction ( action ) ; <nl> + } <nl> + <nl> bool CApplication : : OnAction ( const CAction & action ) <nl> { <nl> # ifdef HAS_HTTPAPI <nl> mmm a / xbmc / Application . h <nl> ppp b / xbmc / Application . h <nl> class CApplication : public CXBApplicationEx , public IPlayerCallback , public IMs <nl> bool IsPlayingFullScreenVideo ( ) const ; <nl> bool IsStartingPlayback ( ) const { return m_bPlaybackStarting ; } <nl> bool OnKey ( const CKey & key ) ; <nl> + bool OnAppCommand ( const CAction & action ) ; <nl> bool OnAction ( const CAction & action ) ; <nl> void RenderMemoryStatus ( ) ; <nl> void CheckShutdown ( ) ; <nl>
|
WM_APPCOMMAND does not wake from screensaver
|
xbmc/xbmc
|
5ee3af67a76cf71e4c806385822ce2a13ad97621
|
2010-07-18T06:16:39Z
|
mmm a / dlib / bound_function_pointer / bound_function_pointer_kernel_abstract . h <nl> ppp b / dlib / bound_function_pointer / bound_function_pointer_kernel_abstract . h <nl> namespace dlib <nl> - calls to this - > operator ( ) will call function_object ( arg1 , arg2 ) <nl> ! * / <nl> <nl> - template < typename T , typename T1 , typename A1 <nl> + template < typename T , typename T1 , typename A1 , <nl> typename T2 , typename A2 > <nl> void set ( <nl> T & object , <nl> namespace dlib <nl> - calls to this - > operator ( ) will call ( object . * funct ) ( arg1 , arg2 ) <nl> ! * / <nl> <nl> - template < typename T , typename T1 , typename A1 <nl> + template < typename T , typename T1 , typename A1 , <nl> typename T2 , typename A2 > <nl> void set ( <nl> const T & object , <nl> namespace dlib <nl> - calls to this - > operator ( ) will call function_object ( arg1 , arg2 , arg3 ) <nl> ! * / <nl> <nl> - template < typename T , typename T1 , typename A1 <nl> + template < typename T , typename T1 , typename A1 , <nl> typename T2 , typename A2 , <nl> typename T3 , typename A3 > <nl> void set ( <nl> namespace dlib <nl> - calls to this - > operator ( ) will call ( object . * funct ) ( arg1 , arg2 , arg3 ) <nl> ! * / <nl> <nl> - template < typename T , typename T1 , typename A1 <nl> + template < typename T , typename T1 , typename A1 , <nl> typename T2 , typename A2 , <nl> typename T3 , typename A3 > <nl> void set ( <nl> namespace dlib <nl> - calls to this - > operator ( ) will call function_object ( arg1 , arg2 , arg3 , arg4 ) <nl> ! * / <nl> <nl> - template < typename T , typename T1 , typename A1 <nl> + template < typename T , typename T1 , typename A1 , <nl> typename T2 , typename A2 , <nl> typename T3 , typename A3 , <nl> typename T4 , typename A4 > <nl> namespace dlib <nl> - calls to this - > operator ( ) will call ( object . * funct ) ( arg1 , arg2 , arg3 , arg4 ) <nl> ! * / <nl> <nl> - template < typename T , typename T1 , typename A1 <nl> + template < typename T , typename T1 , typename A1 , <nl> typename T2 , typename A2 , <nl> typename T3 , typename A3 , <nl> typename T4 , typename A4 > <nl>
|
Added some missing commas
|
davisking/dlib
|
76861bdf301f2e182b9492f912515cd6e24dbfea
|
2010-07-08T00:24:12Z
|
mmm a / libraries / chain / apply_context . cpp <nl> ppp b / libraries / chain / apply_context . cpp <nl> void apply_context : : require_recipient ( account_name code ) { <nl> void apply_context : : execute_inline ( action & & a ) { <nl> if ( ! privileged ) { <nl> if ( a . account ! = receiver ) { <nl> - const auto delay = controller . check_authorization ( { a } , flat_set < public_key_type > ( ) , false , { receiver } ) ; <nl> + const auto delay = controller . check_authorization ( { a } , vector < action > ( ) , flat_set < public_key_type > ( ) , false , { receiver } ) ; <nl> FC_ASSERT ( trx_meta . published + delay < = controller . head_block_time ( ) , <nl> " inline action uses a permission that imposes a delay that is not met , add an action of mindelay with delay of atleast $ { delay } " , <nl> ( " delay " , delay . sec_since_epoch ( ) ) ) ; <nl> void apply_context : : execute_deferred ( deferred_transaction & & trx ) { <nl> } <nl> } <nl> if ( check_auth ) { <nl> - const auto delay = controller . check_authorization ( trx . actions , flat_set < public_key_type > ( ) , false , { receiver } ) ; <nl> + const auto delay = controller . check_authorization ( trx . actions , vector < action > ( ) , flat_set < public_key_type > ( ) , false , { receiver } ) ; <nl> FC_ASSERT ( trx_meta . published + delay < = controller . head_block_time ( ) , <nl> " deferred transaction uses a permission that imposes a delay that is not met , add an action of mindelay with delay of atleast $ { delay } " , <nl> ( " delay " , delay . sec_since_epoch ( ) ) ) ; <nl> mmm a / libraries / chain / chain_controller . cpp <nl> ppp b / libraries / chain / chain_controller . cpp <nl> <nl> # include < eosio / chain / scope_sequence_object . hpp > <nl> # include < eosio / chain / merkle . hpp > <nl> <nl> + # include < eosio / chain / exceptions . hpp > <nl> # include < eosio / chain / wasm_interface . hpp > <nl> <nl> # include < eosio / utilities / rand . hpp > <nl> bool chain_controller : : _push_block ( const signed_block & new_block ) <nl> * queues . <nl> * / <nl> transaction_trace chain_controller : : push_transaction ( const packed_transaction & trx , uint32_t skip ) <nl> - { try { <nl> - return with_skip_flags ( skip , [ & ] ( ) { <nl> - return _db . with_write_lock ( [ & ] ( ) { <nl> - return _push_transaction ( trx ) ; <nl> - } ) ; <nl> - } ) ; <nl> - } FC_CAPTURE_AND_RETHROW ( ) } <nl> + { try { <nl> + return with_skip_flags ( skip , [ & ] ( ) { <nl> + return _db . with_write_lock ( [ & ] ( ) { <nl> + return _push_transaction ( trx ) ; <nl> + } ) ; <nl> + } ) ; <nl> + } EOS_CAPTURE_AND_RETHROW ( transaction_exception ) } <nl> <nl> transaction_trace chain_controller : : _push_transaction ( const packed_transaction & packed_trx ) <nl> { try { <nl> class permission_visitor { <nl> } ; <nl> <nl> time_point chain_controller : : check_authorization ( const vector < action > & actions , <nl> + const vector < action > & context_free_actions , <nl> const flat_set < public_key_type > & provided_keys , <nl> bool allow_unused_signatures , <nl> flat_set < account_name > provided_accounts ) const <nl> time_point chain_controller : : check_authorization ( const vector < action > & actions , <nl> ( " auth " , declared_auth ) ) ; <nl> } <nl> } <nl> + } <nl> <nl> + for ( const auto & act : context_free_actions ) { <nl> if ( act . account = = config : : system_account_name & & act . name = = contracts : : mindelay : : get_name ( ) ) { <nl> const auto mindelay = act . data_as < contracts : : mindelay > ( ) ; <nl> const time_point delay = time_point_sec { mindelay . delay . convert_to < uint32_t > ( ) } ; <nl> time_point chain_controller : : check_transaction_authorization ( const transaction & <nl> const vector < bytes > & cfd , <nl> bool allow_unused_signatures ) const <nl> { <nl> - return check_authorization ( trx . actions , trx . get_signature_keys ( signatures , chain_id_type { } , cfd ) , allow_unused_signatures ) ; <nl> + return check_authorization ( trx . actions , trx . context_free_actions , trx . get_signature_keys ( signatures , chain_id_type { } , cfd ) , allow_unused_signatures ) ; <nl> } <nl> <nl> optional < permission_name > chain_controller : : lookup_minimum_permission ( account_name authorizer_account , <nl> void chain_controller : : validate_uniqueness ( const transaction & trx ) const { <nl> if ( ! should_check_for_duplicate_transactions ( ) ) return ; <nl> <nl> auto transaction = _db . find < transaction_object , by_trx_id > ( trx . id ( ) ) ; <nl> - EOS_ASSERT ( transaction = = nullptr , tx_duplicate , " transaction is not unique " ) ; <nl> + EOS_ASSERT ( transaction = = nullptr , tx_duplicate , " Transaction is not unique " ) ; <nl> } <nl> <nl> void chain_controller : : record_transaction ( const transaction & trx ) <nl> void chain_controller : : validate_tapos ( const transaction & trx ) const { <nl> const auto & tapos_block_summary = _db . get < block_summary_object > ( ( uint16_t ) trx . ref_block_num ) ; <nl> <nl> / / Verify TaPoS block summary has correct ID prefix , and that this block ' s time is not past the expiration <nl> - EOS_ASSERT ( trx . verify_reference_block ( tapos_block_summary . block_id ) , transaction_exception , <nl> - " transaction ' s reference block did not match . Is this transaction from a different fork ? " , <nl> + EOS_ASSERT ( trx . verify_reference_block ( tapos_block_summary . block_id ) , invalid_ref_block_exception , <nl> + " Transaction ' s reference block did not match . Is this transaction from a different fork ? " , <nl> ( " tapos_summary " , tapos_block_summary ) ) ; <nl> } <nl> <nl> void chain_controller : : validate_expiration ( const transaction & trx ) const <nl> const auto & chain_configuration = get_global_properties ( ) . configuration ; <nl> <nl> EOS_ASSERT ( time_point ( trx . expiration ) < = now + fc : : seconds ( chain_configuration . max_transaction_lifetime ) , <nl> - transaction_exception , " transaction expiration is too far in the future " , <nl> + tx_exp_too_far_exception , " Transaction expiration is too far in the future , expiration is $ { trx . expiration } but max expiration is $ { max_til_exp } " , <nl> ( " trx . expiration " , trx . expiration ) ( " now " , now ) <nl> ( " max_til_exp " , chain_configuration . max_transaction_lifetime ) ) ; <nl> - EOS_ASSERT ( now < = time_point ( trx . expiration ) , transaction_exception , " transaction is expired " , <nl> + EOS_ASSERT ( now < = time_point ( trx . expiration ) , expired_tx_exception , " Transaction is expired , now is $ { now } , expiration is $ { trx . exp } " , <nl> ( " now " , now ) ( " trx . exp " , trx . expiration ) ) ; <nl> } FC_CAPTURE_AND_RETHROW ( ( trx ) ) } <nl> <nl> const producer_object & chain_controller : : get_producer ( const account_name & owner_ <nl> const permission_object & chain_controller : : get_permission ( const permission_level & level ) const <nl> { try { <nl> return _db . get < permission_object , by_owner > ( boost : : make_tuple ( level . actor , level . permission ) ) ; <nl> - } FC_CAPTURE_AND_RETHROW ( ( level ) ) } <nl> + } EOS_RETHROW_EXCEPTIONS ( chain : : permission_query_exception , " Fail to retrieve permission : $ { level } " , ( " level " , level ) ) } <nl> <nl> uint32_t chain_controller : : last_irreversible_block_num ( ) const { <nl> return get_dynamic_global_properties ( ) . last_irreversible_block_num ; <nl> mmm a / libraries / chain / contracts / abi_serializer . cpp <nl> ppp b / libraries / chain / contracts / abi_serializer . cpp <nl> namespace eosio { namespace chain { namespace contracts { <nl> } <nl> else { <nl> / / / TODO : default construct field and write it out <nl> - FC_ASSERT ( ! " missing field in variant object " , " Missing ' $ { f } ' in variant object " , ( " f " , field . name ) ) ; <nl> + FC_THROW ( " Missing ' $ { f } ' in variant object " , ( " f " , field . name ) ) ; <nl> } <nl> } <nl> } <nl> mmm a / libraries / chain / contracts / eosio_contract . cpp <nl> ppp b / libraries / chain / contracts / eosio_contract . cpp <nl> void apply_eosio_newaccount ( apply_context & context ) { <nl> auto & db = context . mutable_db ; <nl> <nl> EOS_ASSERT ( create . name . to_string ( ) . size ( ) < = 12 , action_validate_exception , " account names can only be 12 chars long " ) ; <nl> - if ( ! context . privileged ) { <nl> + <nl> + / / Check if the creator is privileged <nl> + const auto & creator = db . get < account_object , by_name > ( create . creator ) ; <nl> + if ( ! creator . privileged ) { <nl> EOS_ASSERT ( name ( create . name ) . to_string ( ) . find ( " eosio . " ) = = std : : string : : npos , action_validate_exception , " only privileged accounts can have names that contain ' eosio . ' " ) ; <nl> } <nl> <nl> void apply_eosio_linkauth ( apply_context & context ) { <nl> try { <nl> EOS_ASSERT ( ! requirement . requirement . empty ( ) , action_validate_exception , " Required permission cannot be empty " ) ; <nl> <nl> - <nl> context . require_authorization ( requirement . account ) ; <nl> <nl> auto & db = context . mutable_db ; <nl> - db . get < account_object , by_name > ( requirement . account ) ; <nl> - db . get < account_object , by_name > ( requirement . code ) ; <nl> - if ( requirement . requirement ! = N ( eosio . any ) ) <nl> - db . get < permission_object , by_name > ( requirement . requirement ) ; <nl> + const auto * account = db . find < account_object , by_name > ( requirement . account ) ; <nl> + EOS_ASSERT ( account ! = nullptr , account_query_exception , <nl> + " Fail to retrieve account : $ { account } " , ( " account " , requirement . account ) ) ; <nl> + const auto * code = db . find < account_object , by_name > ( requirement . code ) ; <nl> + EOS_ASSERT ( code ! = nullptr , account_query_exception , <nl> + " Fail to retrieve code for account : $ { account } " , ( " account " , requirement . code ) ) ; <nl> + if ( requirement . requirement ! = N ( eosio . any ) ) { <nl> + const auto * permission = db . find < permission_object , by_name > ( requirement . requirement ) ; <nl> + EOS_ASSERT ( permission ! = nullptr , permission_query_exception , <nl> + " Fail to retrieve permission : $ { permission } " , ( " permission " , requirement . requirement ) ) ; <nl> + } <nl> <nl> auto link_key = boost : : make_tuple ( requirement . account , requirement . code , requirement . type ) ; <nl> auto link = db . find < permission_link_object , by_action_name > ( link_key ) ; <nl> void apply_eosio_canceldelay ( apply_context & context ) { <nl> const auto & generated_transaction_idx = context . controller . get_database ( ) . get_index < generated_transaction_multi_index > ( ) ; <nl> const auto & generated_index = generated_transaction_idx . indices ( ) . get < by_sender_id > ( ) ; <nl> const auto & itr = generated_index . lower_bound ( boost : : make_tuple ( config : : system_account_name , sender_id ) ) ; <nl> - FC_ASSERT ( itr = = generated_index . end ( ) | | itr - > sender ! = config : : system_account_name | | itr - > sender_id ! = sender_id , <nl> + FC_ASSERT ( itr ! = generated_index . end ( ) & & itr - > sender = = config : : system_account_name & & itr - > sender_id = = sender_id , <nl> " cannot cancel sender_id = $ { sid } , there is no deferred transaction with that sender_id " , ( " sid " , sender_id ) ) ; <nl> <nl> auto dtrx = fc : : raw : : unpack < deferred_transaction > ( itr - > packed_trx . data ( ) , itr - > packed_trx . size ( ) ) ; <nl> mmm a / libraries / chain / include / eosio / chain / chain_controller . hpp <nl> ppp b / libraries / chain / include / eosio / chain / chain_controller . hpp <nl> namespace eosio { namespace chain { <nl> <nl> / * * <nl> * @ param actions - the actions to check authorization across <nl> + * @ param context_free_actions - the context free actions to check for mindelays across <nl> * @ param provided_keys - the set of public keys which have authorized the transaction <nl> * @ param allow_unused_signatures - true if method should not assert on unused signatures <nl> * @ param provided_accounts - the set of accounts which have authorized the transaction ( presumed to be owner ) <nl> namespace eosio { namespace chain { <nl> * @ return time_point set to the max delay that this authorization requires to complete <nl> * / <nl> time_point check_authorization ( const vector < action > & actions , <nl> + const vector < action > & context_free_actions , <nl> const flat_set < public_key_type > & provided_keys , <nl> bool allow_unused_signatures = false , <nl> flat_set < account_name > provided_accounts = flat_set < account_name > ( ) <nl> mmm a / libraries / chain / include / eosio / chain / contracts / abi_serializer . hpp <nl> ppp b / libraries / chain / include / eosio / chain / contracts / abi_serializer . hpp <nl> <nl> # include < eosio / chain / contracts / types . hpp > <nl> # include < eosio / chain / transaction . hpp > <nl> # include < eosio / chain / block . hpp > <nl> - <nl> + # include < eosio / chain / exceptions . hpp > <nl> # include < fc / variant_object . hpp > <nl> <nl> namespace eosio { namespace chain { namespace contracts { <nl> namespace impl { <nl> static void extract ( const variant & v , action & act , Resolver resolver ) <nl> { <nl> const variant_object & vo = v . get_object ( ) ; <nl> - FC_ASSERT ( vo . contains ( " account " ) ) ; <nl> - FC_ASSERT ( vo . contains ( " name " ) ) ; <nl> + EOS_ASSERT ( vo . contains ( " account " ) , packed_transaction_type_exception , " Missing account " ) ; <nl> + EOS_ASSERT ( vo . contains ( " name " ) , packed_transaction_type_exception , " Missing name " ) ; <nl> from_variant ( vo [ " account " ] , act . account ) ; <nl> from_variant ( vo [ " name " ] , act . name ) ; <nl> <nl> namespace impl { <nl> } <nl> } <nl> <nl> - FC_ASSERT ( ! act . data . empty ( ) , " Failed to deserialize data for $ { account } : $ { name } " , ( " account " , act . account ) ( " name " , act . name ) ) ; <nl> + EOS_ASSERT ( ! act . data . empty ( ) , packed_transaction_type_exception , <nl> + " Failed to deserialize data for $ { account } : $ { name } " , ( " account " , act . account ) ( " name " , act . name ) ) ; <nl> } <nl> <nl> template < typename Resolver > <nl> static void extract ( const variant & v , packed_transaction & ptrx , Resolver resolver ) { <nl> const variant_object & vo = v . get_object ( ) ; <nl> - FC_ASSERT ( vo . contains ( " signatures " ) ) ; <nl> - FC_ASSERT ( vo . contains ( " compression " ) ) ; <nl> + EOS_ASSERT ( vo . contains ( " signatures " ) , packed_transaction_type_exception , " Missing signatures " ) ; <nl> + EOS_ASSERT ( vo . contains ( " compression " ) , packed_transaction_type_exception , " Missing compression " ) ; <nl> from_variant ( vo [ " signatures " ] , ptrx . signatures ) ; <nl> if ( vo . contains ( " context_free_data " ) ) { <nl> from_variant ( vo [ " context_free_data " ] , ptrx . context_free_data ) ; <nl> namespace impl { <nl> if ( vo . contains ( " hex_data " ) & & vo [ " hex_data " ] . is_string ( ) & & ! vo [ " hex_data " ] . as_string ( ) . empty ( ) ) { <nl> from_variant ( vo [ " hex_data " ] , ptrx . data ) ; <nl> } else { <nl> - FC_ASSERT ( vo . contains ( " data " ) ) ; <nl> + EOS_ASSERT ( vo . contains ( " data " ) , packed_transaction_type_exception , " Missing data " ) ; <nl> if ( vo [ " data " ] . is_string ( ) ) { <nl> from_variant ( vo [ " data " ] , ptrx . data ) ; <nl> } else { <nl> mmm a / libraries / chain / include / eosio / chain / exceptions . hpp <nl> ppp b / libraries / chain / include / eosio / chain / exceptions . hpp <nl> namespace eosio { namespace chain { <nl> FC_DECLARE_DERIVED_EXCEPTION ( unknown_block_exception , eosio : : chain : : chain_exception , 3110000 , " unknown block " ) <nl> FC_DECLARE_DERIVED_EXCEPTION ( chain_type_exception , eosio : : chain : : chain_exception , 3120000 , " chain type exception " ) <nl> FC_DECLARE_DERIVED_EXCEPTION ( missing_plugin_exception , eosio : : chain : : chain_exception , 3130000 , " missing plugin exception " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( wallet_exception , eosio : : chain : : chain_exception , 3140000 , " wallet exception " ) <nl> <nl> - FC_DECLARE_DERIVED_EXCEPTION ( permission_query_exception , eosio : : chain : : database_query_exception , 3010001 , " permission query exception " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( permission_query_exception , eosio : : chain : : database_query_exception , 3010001 , " Permission Query Exception " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( account_query_exception , eosio : : chain : : database_query_exception , 3010002 , " Account Query Exception " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( contract_table_query_exception , eosio : : chain : : database_query_exception , 3010003 , " Contract Table Query Exception " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( contract_query_exception , eosio : : chain : : database_query_exception , 3010004 , " Contract Query Exception " ) <nl> <nl> FC_DECLARE_DERIVED_EXCEPTION ( block_tx_output_exception , eosio : : chain : : block_validate_exception , 3020001 , " transaction outputs in block do not match transaction outputs from applying block " ) <nl> FC_DECLARE_DERIVED_EXCEPTION ( block_concurrency_exception , eosio : : chain : : block_validate_exception , 3020002 , " block does not guarantee concurrent exection without conflicts " ) <nl> namespace eosio { namespace chain { <nl> FC_DECLARE_DERIVED_EXCEPTION ( tx_msgs_auth_exceeded , eosio : : chain : : transaction_exception , 3030018 , " Number of transaction messages per authorized account has been exceeded " ) <nl> FC_DECLARE_DERIVED_EXCEPTION ( tx_msgs_code_exceeded , eosio : : chain : : transaction_exception , 3030019 , " Number of transaction messages per code account has been exceeded " ) <nl> FC_DECLARE_DERIVED_EXCEPTION ( wasm_execution_error , eosio : : chain : : transaction_exception , 3030020 , " Runtime Error Processing WASM " ) <nl> - FC_DECLARE_DERIVED_EXCEPTION ( tx_decompression_error , eosio : : chain : : transaction_exception , 3030020 , " Error decompressing transaction " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( tx_decompression_error , eosio : : chain : : transaction_exception , 3030021 , " Error decompressing transaction " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( expired_tx_exception , eosio : : chain : : transaction_exception , 3030022 , " Expired Transaction " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( tx_exp_too_far_exception , eosio : : chain : : transaction_exception , 3030023 , " Transaction Expiration Too Far " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( invalid_ref_block_exception , eosio : : chain : : transaction_exception , 3030024 , " Invalid Reference Block " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( tx_apply_exception , eosio : : chain : : transaction_exception , 3030025 , " Transaction Apply Exception " ) <nl> <nl> FC_DECLARE_DERIVED_EXCEPTION ( account_name_exists_exception , eosio : : chain : : action_validate_exception , 3040001 , " account name already exists " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( invalid_action_args_exception , eosio : : chain : : action_validate_exception , 3040002 , " Invalid Action Arguments " ) <nl> FC_DECLARE_DERIVED_EXCEPTION ( invalid_pts_address , eosio : : chain : : utility_exception , 3060001 , " invalid pts address " ) <nl> FC_DECLARE_DERIVED_EXCEPTION ( insufficient_feeds , eosio : : chain : : chain_exception , 37006 , " insufficient feeds " ) <nl> <nl> namespace eosio { namespace chain { <nl> <nl> FC_DECLARE_DERIVED_EXCEPTION ( name_type_exception , eosio : : chain : : chain_type_exception , 3120001 , " Invalid name " ) <nl> FC_DECLARE_DERIVED_EXCEPTION ( public_key_type_exception , eosio : : chain : : chain_type_exception , 3120002 , " Invalid public key " ) <nl> - FC_DECLARE_DERIVED_EXCEPTION ( authority_type_exception , eosio : : chain : : chain_type_exception , 3120003 , " Invalid authority " ) <nl> - FC_DECLARE_DERIVED_EXCEPTION ( action_type_exception , eosio : : chain : : chain_type_exception , 3120004 , " Invalid action " ) <nl> - FC_DECLARE_DERIVED_EXCEPTION ( transaction_type_exception , eosio : : chain : : chain_type_exception , 3120005 , " Invalid transaction " ) <nl> - FC_DECLARE_DERIVED_EXCEPTION ( abi_type_exception , eosio : : chain : : chain_type_exception , 3120006 , " Invalid ABI " ) <nl> - FC_DECLARE_DERIVED_EXCEPTION ( asset_type_exception , eosio : : chain : : chain_type_exception , 3120007 , " Invalid asset " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( private_key_type_exception , eosio : : chain : : chain_type_exception , 3120003 , " Invalid private key " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( authority_type_exception , eosio : : chain : : chain_type_exception , 3120004 , " Invalid authority " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( action_type_exception , eosio : : chain : : chain_type_exception , 3120005 , " Invalid action " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( transaction_type_exception , eosio : : chain : : chain_type_exception , 3120006 , " Invalid transaction " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( abi_type_exception , eosio : : chain : : chain_type_exception , 3120007 , " Invalid ABI " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( block_id_type_exception , eosio : : chain : : chain_type_exception , 3120008 , " Invalid block ID " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( transaction_id_type_exception , eosio : : chain : : chain_type_exception , 3120009 , " Invalid transaction ID " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( packed_transaction_type_exception , eosio : : chain : : chain_type_exception , 3120010 , " Invalid packed transaction " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( asset_type_exception , eosio : : chain : : chain_type_exception , 3120011 , " Invalid asset " ) <nl> <nl> FC_DECLARE_DERIVED_EXCEPTION ( missing_chain_api_plugin_exception , eosio : : chain : : missing_plugin_exception , 3130001 , " Missing Chain API Plugin " ) <nl> FC_DECLARE_DERIVED_EXCEPTION ( missing_wallet_api_plugin_exception , eosio : : chain : : missing_plugin_exception , 3130002 , " Missing Wallet API Plugin " ) <nl> FC_DECLARE_DERIVED_EXCEPTION ( missing_account_history_api_plugin_exception , eosio : : chain : : missing_plugin_exception , 3130003 , " Missing Account History API Plugin " ) <nl> - FC_DECLARE_DERIVED_EXCEPTION ( missing_net_api_plugin_exception , eosio : : chain : : missing_plugin_exception , 3130003 , " Missing Net API Plugin " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( missing_net_api_plugin_exception , eosio : : chain : : missing_plugin_exception , 3130004 , " Missing Net API Plugin " ) <nl> + <nl> + FC_DECLARE_DERIVED_EXCEPTION ( wallet_exist_exception , eosio : : chain : : wallet_exception , 3140001 , " Wallet already exists " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( wallet_nonexistent_exception , eosio : : chain : : wallet_exception , 3140002 , " Nonexistent wallet " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( wallet_locked_exception , eosio : : chain : : wallet_exception , 3140003 , " Locked wallet " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( wallet_missing_pub_key_exception , eosio : : chain : : wallet_exception , 3140004 , " Missing public key " ) <nl> + FC_DECLARE_DERIVED_EXCEPTION ( wallet_invalid_password_exception , eosio : : chain : : wallet_exception , 3140005 , " Invalid wallet password " ) <nl> <nl> <nl> # define EOS_RECODE_EXC ( cause_type , effect_type ) \ <nl> mmm a / libraries / testing / include / eosio / testing / tester . hpp <nl> ppp b / libraries / testing / include / eosio / testing / tester . hpp <nl> namespace eosio { namespace testing { <nl> : expected ( expected ) <nl> { } <nl> <nl> - bool operator ( ) ( const fc : : assert_exception & ex ) { <nl> + bool operator ( ) ( const fc : : exception & ex ) { <nl> auto message = ex . get_log ( ) . at ( 0 ) . get_message ( ) ; <nl> return boost : : algorithm : : ends_with ( message , expected ) ; <nl> } <nl> mmm a / libraries / utilities / include / eosio / utilities / exception_macros . hpp <nl> ppp b / libraries / utilities / include / eosio / utilities / exception_macros . hpp <nl> <nl> FC_THROW_EXCEPTION ( exc_type , FORMAT , __VA_ARGS__ ) ; \ <nl> FC_MULTILINE_MACRO_END <nl> <nl> - # define EOS_CAPTURE_AND_RETHROW ( exc_type , FORMAT , . . . ) \ <nl> - catch ( fc : : exception & e ) { \ <nl> - exc_type new_exception ( FC_LOG_MESSAGE ( error , FORMAT , __VA_ARGS__ ) ) ; \ <nl> + # define EOS_THROW ( exc_type , FORMAT , . . . ) \ <nl> + throw exc_type ( FC_LOG_MESSAGE ( error , FORMAT , __VA_ARGS__ ) ) ; <nl> + <nl> + / * * <nl> + * Macro inspired from FC_RETHROW_EXCEPTIONS <nl> + * The main difference here is that if the exception caught isn ' t of type " eosio : : chain : : chain_exception " <nl> + * This macro will rethrow the exception as the specified " exception_type " <nl> + * / <nl> + # define EOS_RETHROW_EXCEPTIONS ( exception_type , FORMAT , . . . ) \ <nl> + catch ( eosio : : chain : : chain_exception & e ) { \ <nl> + FC_RETHROW_EXCEPTION ( e , warn , FORMAT , __VA_ARGS__ ) ; \ <nl> + } catch ( fc : : exception & e ) { \ <nl> + exception_type new_exception ( FC_LOG_MESSAGE ( warn , FORMAT , __VA_ARGS__ ) ) ; \ <nl> for ( const auto & log : e . get_log ( ) ) { \ <nl> new_exception . append_log ( log ) ; \ <nl> } \ <nl> throw new_exception ; \ <nl> - } <nl> + } catch ( const std : : exception & e ) { \ <nl> + exception_type fce ( FC_LOG_MESSAGE ( warn , FORMAT " ( $ { what } ) " , __VA_ARGS__ ( " what " , e . what ( ) ) ) ) ; \ <nl> + throw fce ; \ <nl> + } catch ( . . . ) { \ <nl> + throw fc : : unhandled_exception ( \ <nl> + FC_LOG_MESSAGE ( warn , FORMAT , __VA_ARGS__ ) , \ <nl> + std : : current_exception ( ) ) ; \ <nl> + } <nl> <nl> + / * * <nl> + * Macro inspired from FC_CAPTURE_AND_RETHROW <nl> + * The main difference here is that if the exception caught isn ' t of type " eosio : : chain : : chain_exception " <nl> + * This macro will rethrow the exception as the specified " exception_type " <nl> + * / <nl> + # define EOS_CAPTURE_AND_RETHROW ( exception_type , . . . ) \ <nl> + catch ( eosio : : chain : : chain_exception & e ) { \ <nl> + FC_RETHROW_EXCEPTION ( e , warn , " " , FC_FORMAT_ARG_PARAMS ( __VA_ARGS__ ) ) ; \ <nl> + } catch ( fc : : exception & e ) { \ <nl> + exception_type new_exception ( e . get_log ( ) ) ; \ <nl> + throw new_exception ; \ <nl> + } catch ( const std : : exception & e ) { \ <nl> + exception_type fce ( \ <nl> + FC_LOG_MESSAGE ( warn , " $ { what } : " , FC_FORMAT_ARG_PARAMS ( __VA_ARGS__ ) ( " what " , e . what ( ) ) ) , \ <nl> + fc : : std_exception_code , \ <nl> + BOOST_CORE_TYPEID ( decltype ( e ) ) . name ( ) , \ <nl> + e . what ( ) ) ; throw fce ; \ <nl> + } catch ( . . . ) { \ <nl> + throw fc : : unhandled_exception ( \ <nl> + FC_LOG_MESSAGE ( warn , " " , FC_FORMAT_ARG_PARAMS ( __VA_ARGS__ ) ) , \ <nl> + std : : current_exception ( ) ) ; \ <nl> + } <nl> <nl> # define EOS_DECLARE_OP_BASE_EXCEPTIONS ( op_name ) \ <nl> FC_DECLARE_DERIVED_EXCEPTION ( \ <nl> mmm a / plugins / chain_plugin / chain_plugin . cpp <nl> ppp b / plugins / chain_plugin / chain_plugin . cpp <nl> read_only : : get_info_results read_only : : get_info ( const read_only : : get_info_params <nl> } <nl> <nl> abi_def get_abi ( const chain_controller & db , const name & account ) { <nl> - const auto & d = db . get_database ( ) ; <nl> - const auto & code_accnt = d . get < account_object , by_name > ( account ) ; <nl> - <nl> + const auto & d = db . get_database ( ) ; <nl> + const account_object * code_accnt = d . find < account_object , by_name > ( account ) ; <nl> + EOS_ASSERT ( code_accnt ! = nullptr , chain : : account_query_exception , " Fail to retrieve account for $ { account } " , ( " account " , account ) ) ; <nl> abi_def abi ; <nl> - abi_serializer : : to_abi ( code_accnt . abi , abi ) ; <nl> + abi_serializer : : to_abi ( code_accnt - > abi , abi ) ; <nl> return abi ; <nl> } <nl> <nl> string get_table_type ( const abi_def & abi , const name & table_name ) { <nl> return t . index_type ; <nl> } <nl> } <nl> - FC_ASSERT ( ! " ABI does not define table " , " Table $ { table } not specified in ABI " , ( " table " , table_name ) ) ; <nl> + EOS_ASSERT ( false , chain : : contract_table_query_exception , " Table $ { table } is not specified in the ABI " , ( " table " , table_name ) ) ; <nl> } <nl> <nl> read_only : : get_table_rows_result read_only : : get_table_rows ( const read_only : : get_table_rows_params & p ) const { <nl> read_only : : get_table_rows_result read_only : : get_table_rows ( const read_only : : get <nl> if ( table_type = = KEYi64 ) { <nl> return get_table_rows_ex < contracts : : key_value_index , contracts : : by_scope_primary > ( p , abi ) ; <nl> } <nl> - FC_ASSERT ( false , " invalid table type / key $ { type } / $ { key } " , ( " type " , table_type ) ( " abi " , abi ) ) ; <nl> + <nl> + EOS_ASSERT ( false , chain : : contract_table_query_exception , " Invalid table type $ { type } " , ( " type " , table_type ) ( " abi " , abi ) ) ; <nl> } <nl> <nl> vector < asset > read_only : : get_currency_balance ( const read_only : : get_currency_balance_params & p ) const { <nl> fc : : variant read_only : : get_block ( const read_only : : get_block_params & params ) cons <nl> block = db . fetch_block_by_number ( fc : : to_uint64 ( params . block_num_or_id ) ) ; <nl> } <nl> <nl> - } catch ( fc : : bad_cast_exception ) { / * do nothing * / } <nl> + } EOS_RETHROW_EXCEPTIONS ( chain : : block_id_type_exception , " Invalid block ID : $ { block_num_or_id } " , ( " block_num_or_id " , params . block_num_or_id ) ) <nl> <nl> if ( ! block ) <nl> FC_THROW_EXCEPTION ( unknown_block_exception , <nl> read_write : : push_block_results read_write : : push_block ( const read_write : : push_blo <nl> read_write : : push_transaction_results read_write : : push_transaction ( const read_write : : push_transaction_params & params ) { <nl> packed_transaction pretty_input ; <nl> auto resolver = make_resolver ( this ) ; <nl> - abi_serializer : : from_variant ( params , pretty_input , resolver ) ; <nl> + try { <nl> + abi_serializer : : from_variant ( params , pretty_input , resolver ) ; <nl> + } EOS_RETHROW_EXCEPTIONS ( chain : : packed_transaction_type_exception , " Invalid packed transaction " ) <nl> + <nl> auto result = db . push_transaction ( pretty_input , skip_flags ) ; <nl> # warning TODO : get transaction results asynchronously <nl> fc : : variant pretty_output ; <nl> read_only : : get_account_results read_only : : get_account ( const get_account_params & <nl> <nl> read_only : : abi_json_to_bin_result read_only : : abi_json_to_bin ( const read_only : : abi_json_to_bin_params & params ) const try { <nl> abi_json_to_bin_result result ; <nl> - const auto & code_account = db . get_database ( ) . get < account_object , by_name > ( params . code ) ; <nl> + const auto code_account = db . get_database ( ) . find < account_object , by_name > ( params . code ) ; <nl> + EOS_ASSERT ( code_account ! = nullptr , contract_query_exception , " Contract can ' t be found $ { contract } " , ( " contract " , params . code ) ) ; <nl> + <nl> abi_def abi ; <nl> - if ( abi_serializer : : to_abi ( code_account . abi , abi ) ) { <nl> + if ( abi_serializer : : to_abi ( code_account - > abi , abi ) ) { <nl> abi_serializer abis ( abi ) ; <nl> - result . binargs = abis . variant_to_binary ( abis . get_action_type ( params . action ) , params . args ) ; <nl> + try { <nl> + result . binargs = abis . variant_to_binary ( abis . get_action_type ( params . action ) , params . args ) ; <nl> + } EOS_RETHROW_EXCEPTIONS ( chain : : invalid_action_args_exception , <nl> + " ' $ { args } ' is invalid args for action ' $ { action } ' code ' $ { code } ' " , <nl> + ( " args " , params . args ) ( " action " , params . action ) ( " code " , params . code ) ) <nl> } <nl> return result ; <nl> } FC_CAPTURE_AND_RETHROW ( ( params . code ) ( params . action ) ( params . args ) ) <nl> mmm a / plugins / http_plugin / include / eosio / http_plugin / http_plugin . hpp <nl> ppp b / plugins / http_plugin / include / eosio / http_plugin / http_plugin . hpp <nl> namespace eosio { <nl> * @ brief Structure used to create JSON error responses <nl> * / <nl> struct error_results { <nl> - struct error_detail { <nl> + uint16_t code ; <nl> + string message ; <nl> + <nl> + struct error_info { <nl> int64_t code ; <nl> string name ; <nl> - string message ; <nl> - string details ; <nl> - vector < fc : : log_context > stack_trace ; <nl> + string what ; <nl> + <nl> + struct error_detail { <nl> + string message ; <nl> + string file ; <nl> + uint64_t line_number ; <nl> + string method ; <nl> + } ; <nl> <nl> - static const uint8_t stack_trace_limit = 10 ; <nl> + vector < error_detail > details ; <nl> <nl> - error_detail ( ) { } ; <nl> + static const uint8_t details_limit = 10 ; <nl> <nl> - error_detail ( const fc : : exception & exc ) { <nl> + error_info ( ) { } ; <nl> + <nl> + error_info ( const fc : : exception & exc ) { <nl> code = exc . code ( ) ; <nl> name = exc . name ( ) ; <nl> - message = exc . what ( ) ; <nl> - details = exc . top_message ( ) ; <nl> + what = exc . what ( ) ; <nl> for ( auto itr = exc . get_log ( ) . begin ( ) ; itr ! = exc . get_log ( ) . end ( ) ; + + itr ) { <nl> / / Prevent sending trace that are too big <nl> - if ( stack_trace . size ( ) > = stack_trace_limit ) break ; <nl> - / / Append context <nl> - stack_trace . emplace_back ( itr - > get_context ( ) ) ; <nl> + if ( details . size ( ) > = details_limit ) break ; <nl> + / / Append error <nl> + error_detail detail = { <nl> + itr - > get_message ( ) , itr - > get_context ( ) . get_file ( ) , <nl> + itr - > get_context ( ) . get_line_number ( ) , itr - > get_context ( ) . get_method ( ) <nl> + } ; <nl> + details . emplace_back ( detail ) ; <nl> } <nl> } <nl> } ; <nl> <nl> - uint16_t code ; <nl> - string message ; <nl> - error_detail error ; <nl> + error_info error ; <nl> } ; <nl> } <nl> <nl> - FC_REFLECT ( eosio : : error_results : : error_detail , ( code ) ( name ) ( message ) ( details ) ( stack_trace ) ) <nl> + FC_REFLECT ( eosio : : error_results : : error_info : : error_detail , ( message ) ( file ) ( line_number ) ( method ) ) <nl> + FC_REFLECT ( eosio : : error_results : : error_info , ( code ) ( name ) ( what ) ( details ) ) <nl> FC_REFLECT ( eosio : : error_results , ( code ) ( message ) ( error ) ) <nl> mmm a / plugins / wallet_plugin / wallet . cpp <nl> ppp b / plugins / wallet_plugin / wallet . cpp <nl> <nl> # ifndef WIN32 <nl> # include < sys / types . h > <nl> # include < sys / stat . h > <nl> + # include < eosio / chain / exceptions . hpp > <nl> + <nl> # endif <nl> <nl> namespace eosio { namespace wallet { <nl> void wallet_api : : unlock ( string password ) <nl> FC_ASSERT ( pk . checksum = = pw ) ; <nl> my - > _keys = std : : move ( pk . keys ) ; <nl> my - > _checksum = pk . checksum ; <nl> - } FC_CAPTURE_AND_RETHROW ( ) } <nl> + } EOS_RETHROW_EXCEPTIONS ( chain : : wallet_invalid_password_exception , <nl> + " Invalid password for wallet : \ " $ { wallet_name } \ " " , ( " wallet_name " , get_wallet_filename ( ) ) ) } <nl> <nl> void wallet_api : : set_password ( string password ) <nl> { <nl> mmm a / plugins / wallet_plugin / wallet_manager . cpp <nl> ppp b / plugins / wallet_plugin / wallet_manager . cpp <nl> <nl> * @ copyright defined in eos / LICENSE . txt <nl> * / <nl> # include < eosio / wallet_plugin / wallet_manager . hpp > <nl> - <nl> + # include < eosio / chain / exceptions . hpp > <nl> namespace eosio { <nl> namespace wallet { <nl> <nl> std : : string wallet_manager : : create ( const std : : string & name ) { <nl> auto wallet_filename = dir / ( name + file_ext ) ; <nl> <nl> if ( fc : : exists ( wallet_filename ) ) { <nl> - FC_THROW ( " Wallet with name : ' $ { n } ' already exists at $ { path } " , ( " n " , name ) ( " path " , fc : : path ( wallet_filename ) ) ) ; <nl> + EOS_THROW ( chain : : wallet_exist_exception , " Wallet with name : ' $ { n } ' already exists at $ { path } " , ( " n " , name ) ( " path " , fc : : path ( wallet_filename ) ) ) ; <nl> } <nl> <nl> wallet_data d ; <nl> void wallet_manager : : open ( const std : : string & name ) { <nl> auto wallet_filename = dir / ( name + file_ext ) ; <nl> wallet - > set_wallet_filename ( wallet_filename . string ( ) ) ; <nl> if ( ! wallet - > load_wallet_file ( ) ) { <nl> - FC_THROW ( " Unable to open file : $ { f } " , ( " f " , wallet_filename . string ( ) ) ) ; <nl> + EOS_THROW ( chain : : wallet_nonexistent_exception , " Unable to open file : $ { f } " , ( " f " , wallet_filename . string ( ) ) ) ; <nl> } <nl> <nl> / / If we have name in our map then remove it since we want the emplace below to replace . <nl> void wallet_manager : : lock_all ( ) { <nl> void wallet_manager : : lock ( const std : : string & name ) { <nl> check_timeout ( ) ; <nl> if ( wallets . count ( name ) = = 0 ) { <nl> - FC_THROW ( " Wallet not found : $ { w } " , ( " w " , name ) ) ; <nl> + EOS_THROW ( chain : : wallet_nonexistent_exception , " Wallet not found : $ { w } " , ( " w " , name ) ) ; <nl> } <nl> auto & w = wallets . at ( name ) ; <nl> if ( w - > is_locked ( ) ) { <nl> void wallet_manager : : unlock ( const std : : string & name , const std : : string & password <nl> void wallet_manager : : import_key ( const std : : string & name , const std : : string & wif_key ) { <nl> check_timeout ( ) ; <nl> if ( wallets . count ( name ) = = 0 ) { <nl> - FC_THROW ( " Wallet not found : $ { w } " , ( " w " , name ) ) ; <nl> + EOS_THROW ( chain : : wallet_nonexistent_exception , " Wallet not found : $ { w } " , ( " w " , name ) ) ; <nl> } <nl> auto & w = wallets . at ( name ) ; <nl> if ( w - > is_locked ( ) ) { <nl> - FC_THROW ( " Wallet is locked : $ { w } " , ( " w " , name ) ) ; <nl> + EOS_THROW ( chain : : wallet_locked_exception , " Wallet is locked : $ { w } " , ( " w " , name ) ) ; <nl> } <nl> w - > import_key ( wif_key ) ; <nl> } <nl> wallet_manager : : sign_transaction ( const chain : : signed_transaction & txn , const fla <nl> } <nl> } <nl> if ( ! found ) { <nl> - FC_THROW ( " Public key not found in unlocked wallets $ { k } " , ( " k " , pk ) ) ; <nl> + EOS_THROW ( chain : : wallet_missing_pub_key_exception , " Public key not found in unlocked wallets $ { k } " , ( " k " , pk ) ) ; <nl> } <nl> } <nl> <nl> mmm a / programs / cleos / help_text . cpp <nl> ppp b / programs / cleos / help_text . cpp <nl> auto smatch_to_variant ( const std : : smatch & smatch ) { <nl> return result ; <nl> } ; <nl> <nl> - const char * error_advice_3120001 = R " = = = = = ( Name should be less than 13 characters and only contains the following symbol . 12345abcdefghijklmnopqrstuvwxyz ) = = = = = " ; <nl> + const char * error_advice_3010001 = " Most likely , the given account / permission doesn ' t exist in the blockchain . " ; <nl> + const char * error_advice_3010002 = " Most likely , the given account doesn ' t exist in the blockchain . " ; <nl> + const char * error_advice_3010003 = " Most likely , the given table doesnt ' exist in the blockchain . " ; <nl> + const char * error_advice_3010004 = " Most likely , the given contract doesnt ' exist in the blockchain . " ; <nl> + <nl> + const char * error_advice_3030000 = " Ensure that your transaction satisfy the contract ' s constraint ! " ; <nl> + const char * error_advice_3030001 = R " = = = = = ( Ensure that you have the related authority inside your transaction ! ; <nl> + If you are currently using ' cleos push action ' command , try to add the relevant authority using - p option . ) = = = = = " ; <nl> + const char * error_advice_3030002 = " Ensure that you have the related private keys inside your wallet and you wallet is unlocked . " ; <nl> + const char * error_advice_3030003 = " Please remove the unnecessary authority from your action ! " ; <nl> + const char * error_advice_3030004 = " Please remove the unnecessary signature from your transaction ! " ; <nl> + const char * error_advice_3030011 = " You can try embedding eosio nonce action inside your transaction to ensure uniqueness . " ; <nl> + const char * error_advice_3030022 = " Please increase the expiration time of your transaction ! " ; <nl> + const char * error_advice_3030023 = " Please decrease the expiration time of your transaction ! " ; <nl> + const char * error_advice_3030024 = " Ensure that the reference block exist in the blockchain ! " ; <nl> + <nl> + const char * error_advice_3040002 = R " = = = = = ( Ensure that your arguments follow the contract abi ! <nl> + You can check the contract ' s abi by using ' cleos get code ' command . ) = = = = = " ; <nl> <nl> + const char * error_advice_3120001 = R " = = = = = ( Name should be less than 13 characters and only contains the following symbol . 12345abcdefghijklmnopqrstuvwxyz ) = = = = = " ; <nl> const char * error_advice_3120002 = R " = = = = = ( Public key should be encoded in base58 and starts with EOS prefix ) = = = = = " ; <nl> - <nl> - const char * error_advice_3120003 = R " = = = = = ( Ensure that your authority JSON follows the following format ! <nl> + const char * error_advice_3120003 = R " = = = = = ( Private key should be encoded in base58 WIF ) = = = = = " ; <nl> + const char * error_advice_3120004 = R " = = = = = ( Ensure that your authority JSON follows the following format ! <nl> { <nl> " threshold " : " uint32_t " , <nl> " keys " : [ { " key " : " public_key " , " weight " : " uint16_t " } ] , <nl> e . g . <nl> " weight " : " 1 <nl> } ] <nl> } ) = = = = = " ; <nl> - <nl> - const char * error_advice_3120004 = R " = = = = = ( Ensure that your action JSON follows the contract ' s abi ! ) = = = = = " ; <nl> - <nl> - const char * error_advice_3120005 = R " = = = = = ( Ensure that your transaction JSON follows the following format ! \ n " <nl> + const char * error_advice_3120005 = R " = = = = = ( Ensure that your action JSON follows the contract ' s abi ! ) = = = = = " ; <nl> + const char * error_advice_3120006 = R " = = = = = ( Ensure that your transaction JSON follows the following format ! \ n " <nl> { <nl> " ref_block_num " : " uint16_t " , <nl> " ref_block_prefix " : " uint32_t " , <nl> e . g . <nl> " data " : " 000000008093dd74000000000094dd74e80300000000000000 " <nl> } ] <nl> } ) = = = = = " ; <nl> - <nl> - const char * error_advice_3120006 = R " = = = = = ( Ensure that your abi JSON follows the following format ! <nl> + const char * error_advice_3120007 = R " = = = = = ( Ensure that your abi JSON follows the following format ! <nl> { <nl> " types " : [ { " new_type_name " : " type_name " , " type " : " type_name " } ] , <nl> " structs " : [ { " name " : " type_name " , " base " : " type_name " , " fields " : [ { " name " : " field_name " , " type " : " type_name " } ] } ] , <nl> e . g . <nl> " type " : " foobar " " <nl> } ] <nl> } ) = = = = = " ; <nl> + const char * error_advice_3120008 = " Ensure that the block ID is a SHA - 256 hexadecimal string ! " ; <nl> + const char * error_advice_3120009 = " Ensure that the transaction ID is a SHA - 256 hexadecimal string ! " ; <nl> + const char * error_advice_3120010 = R " = = = = = ( Ensure that your packed transaction JSON follows the following format ! <nl> + { <nl> + " signatures " : [ " signature " ] , <nl> + " compression " : enum ( " none " , " zlib " ) , <nl> + " data " : " bytes " <nl> + } <nl> + e . g . <nl> + { <nl> + " signatures " : [ " EOSJze4m1ZHQ4UjuHpBcX6uHPN4Xyggv52raQMTBZJghzDLepaPcSGCNYTxaP2NiaF4yRF5RaYwqsQYAwBwFtfuTJr34Z5GJX " ] , <nl> + " compression " : " none " , <nl> + " data " : " 6c36a25a00002602626c5e7f0000000000010000001e4d75af460000000000a53176010000000000ea305500000000a8ed3232180000001e4d75af4680969800000000000443555200000000 " <nl> + } ) = = = = = " ; <nl> + <nl> + const char * error_advice_3130001 = " Ensure that you have \ 033 [ 2meosio : : chain_api_plugin \ 033 [ 0m \ 033 [ 32m added to your node ' s configuration ! " ; <nl> + const char * error_advice_3130002 = " Ensure that you have \ 033 [ 2meosio : : wallet_api_plugin \ 033 [ 0m \ 033 [ 32m added to your node ' s configuration ! \ n " \ <nl> + " Otherwise specify your wallet location with \ 033 [ 2m - - wallet - host \ 033 [ 0m \ 033 [ 32m and \ 033 [ 2m - - wallet_port \ 033 [ 0m \ 033 [ 32m arguments ! " ; <nl> + const char * error_advice_3130003 = " Ensure that you have \ 033 [ 2meosio : : account_history_api_plugin \ 033 [ 0m \ 033 [ 32m added to your node ' s configuration ! " ; <nl> + const char * error_advice_3130004 = " Ensure that you have \ 033 [ 2meosio : : net_api_plugin \ 033 [ 0m \ 033 [ 32m added to your node ' s configuration ! " ; <nl> <nl> - const char * error_advice_3030002 = " Ensure that you have the related private keys inside your wallet . " ; <nl> + const char * error_advice_3140001 = " Try to use different wallet name . " ; <nl> + const char * error_advice_3140002 = " Are you sure you typed the name correctly ? " ; <nl> + const char * error_advice_3140003 = " Ensure that your wallet is unlocked before using it ! " ; <nl> + const char * error_advice_3140004 = " Ensure that you have the relevant private key imported ! " ; <nl> + const char * error_advice_3140005 = " Are you sure you are using the right password ? " ; <nl> <nl> - const char * error_advice_3130001 = " Ensure that you have \ 033 [ 2meosio : : chain_api_plugin \ 033 [ 0m \ 033 [ 32m added to your node ' s configuration . " ; <nl> - const char * error_advice_3130002 = " Ensure that you have \ 033 [ 2meosio : : wallet_api_plugin \ 033 [ 0m \ 033 [ 32m added to your node ' s configuration . \ n " \ <nl> - " Otherwise specify your wallet location with \ 033 [ 2m - - wallet - host \ 033 [ 0m \ 033 [ 32m and \ 033 [ 2m - - wallet_port \ 033 [ 0m \ 033 [ 32m arguments . " ; <nl> - const char * error_advice_3130003 = " Ensure that you have \ 033 [ 2meosio : : account_history_api_plugin \ 033 [ 0m \ 033 [ 32m added to your node ' s configuration . " ; <nl> - const char * error_advice_3130004 = " Ensure that you have \ 033 [ 2meosio : : net_api_plugin \ 033 [ 0m \ 033 [ 32m added to your node ' s configuration " ; <nl> <nl> const std : : map < int64_t , std : : string > error_advice = { <nl> + { 3010001 , error_advice_3010001 } , <nl> + { 3010002 , error_advice_3010002 } , <nl> + { 3010003 , error_advice_3010003 } , <nl> + { 3010004 , error_advice_3010004 } , <nl> + <nl> + { 3030000 , error_advice_3030000 } , <nl> + { 3030001 , error_advice_3030001 } , <nl> + { 3030002 , error_advice_3030002 } , <nl> + { 3030003 , error_advice_3030003 } , <nl> + { 3030004 , error_advice_3030004 } , <nl> + { 3030011 , error_advice_3030011 } , <nl> + { 3030022 , error_advice_3030022 } , <nl> + { 3030023 , error_advice_3030023 } , <nl> + { 3030024 , error_advice_3030024 } , <nl> + <nl> + <nl> + { 3040002 , error_advice_3040002 } , <nl> + <nl> { 3120001 , error_advice_3120001 } , <nl> { 3120002 , error_advice_3120002 } , <nl> { 3120003 , error_advice_3120003 } , <nl> { 3120004 , error_advice_3120004 } , <nl> { 3120005 , error_advice_3120005 } , <nl> { 3120006 , error_advice_3120006 } , <nl> + { 3120007 , error_advice_3120007 } , <nl> + { 3120008 , error_advice_3120008 } , <nl> + { 3120009 , error_advice_3120009 } , <nl> + { 3120010 , error_advice_3120010 } , <nl> + <nl> { 3130001 , error_advice_3130001 } , <nl> { 3130002 , error_advice_3130002 } , <nl> { 3130003 , error_advice_3130003 } , <nl> { 3130004 , error_advice_3130004 } , <nl> - { 3030002 , error_advice_3030002 } <nl> + <nl> + { 3140001 , error_advice_3140001 } , <nl> + { 3140002 , error_advice_3140002 } , <nl> + { 3140003 , error_advice_3140003 } , <nl> + { 3140004 , error_advice_3140004 } , <nl> + { 3140005 , error_advice_3140005 } <nl> } ; <nl> <nl> <nl> bool print_recognized_errors ( const fc : : exception & e , const bool verbose_errors ) <nl> / / Check if there ' s a log to display <nl> if ( ! log . get_format ( ) . empty ( ) ) { <nl> / / Localize the message as needed <nl> - explanation + = " \ n " + localized_with_variant ( log . get_format ( ) . data ( ) , log . get_data ( ) ) ; <nl> + explanation + = " \ n " + localized_with_variant ( log . get_format ( ) . data ( ) , log . get_data ( ) ) ; <nl> } else if ( log . get_data ( ) . size ( ) > 0 & & verbose_errors ) { <nl> / / Show data - only log only if verbose_errors option is enabled <nl> - explanation + = " \ n " + fc : : json : : to_string ( log . get_data ( ) ) ; <nl> + explanation + = " \ n " + fc : : json : : to_string ( log . get_data ( ) ) ; <nl> } <nl> / / Check if there ' s stack trace to be added <nl> if ( ! log . get_context ( ) . get_method ( ) . empty ( ) & & verbose_errors ) { <nl> - stack_trace + = " \ n " + <nl> + stack_trace + = " \ n " + <nl> log . get_context ( ) . get_file ( ) + " : " + <nl> fc : : to_string ( log . get_context ( ) . get_line_number ( ) ) + " " + <nl> log . get_context ( ) . get_method ( ) ; <nl> mmm a / programs / cleos / httpc . cpp <nl> ppp b / programs / cleos / httpc . cpp <nl> namespace eosio { namespace client { namespace http { <nl> throw chain : : missing_net_api_plugin_exception ( FC_LOG_MESSAGE ( error , " Net API plugin is not enabled " ) ) ; <nl> } <nl> } else { <nl> - auto & & error = response_result . as < eosio : : error_results > ( ) . error ; <nl> + auto & & error_info = response_result . as < eosio : : error_results > ( ) . error ; <nl> / / Construct fc exception from error <nl> - const auto & stack_trace = error . stack_trace ; <nl> - fc : : exception new_exception ( error . code , error . name , error . message ) ; <nl> - if ( stack_trace . empty ( ) ) { <nl> - new_exception . append_log ( FC_LOG_MESSAGE ( error , error . details ) ) ; <nl> - } else { <nl> - for ( auto itr = stack_trace . begin ( ) ; itr ! = stack_trace . end ( ) ; itr + + ) { <nl> - const auto & error_message = itr = = stack_trace . begin ( ) ? error . details : std : : string ( ) ; <nl> - new_exception . append_log ( fc : : log_message ( * itr , error_message ) ) ; <nl> - } <nl> + const auto & error_details = error_info . details ; <nl> + <nl> + fc : : log_messages logs ; <nl> + for ( auto itr = error_details . begin ( ) ; itr ! = error_details . end ( ) ; itr + + ) { <nl> + const auto & context = fc : : log_context ( fc : : log_level : : error , itr - > file . data ( ) , itr - > line_number , itr - > method . data ( ) ) ; <nl> + logs . emplace_back ( fc : : log_message ( context , itr - > message ) ) ; <nl> } <nl> - throw new_exception ; <nl> + <nl> + throw fc : : exception ( logs , error_info . code , error_info . name , error_info . what ) ; <nl> } <nl> <nl> FC_ASSERT ( status_code = = 200 , " Error code $ { c } \ n : $ { msg } \ n " , ( " c " , status_code ) ( " msg " , re . str ( ) ) ) ; <nl> } <nl> <nl> FC_ASSERT ( ! " unable to connect " ) ; <nl> - } FC_RETHROW_EXCEPTIONS ( error , " Request Path : $ { server } : $ { port } $ { path } , Request Post Data : $ { postdata } " , <nl> + } FC_RETHROW_EXCEPTIONS ( error , " Request Path : $ { server } : $ { port } $ { path } \ nRequest Post Data : $ { postdata } " , <nl> ( " server " , server ) ( " port " , port ) ( " path " , path ) ( " postdata " , postdata ) ) <nl> } <nl> } } } <nl> \ No newline at end of file <nl> mmm a / programs / cleos / main . cpp <nl> ppp b / programs / cleos / main . cpp <nl> struct set_account_permission_subcommand { <nl> if ( boost : : istarts_with ( authorityJsonOrFile , " EOS " ) ) { <nl> try { <nl> auth = authority ( public_key_type ( authorityJsonOrFile ) ) ; <nl> - } EOS_CAPTURE_AND_RETHROW ( public_key_type_exception , " " ) <nl> + } EOS_RETHROW_EXCEPTIONS ( public_key_type_exception , " Invalid public key : $ { public_key } " , ( " public_key " , authorityJsonOrFile ) ) <nl> } else { <nl> fc : : variant parsedAuthority ; <nl> try { <nl> struct set_account_permission_subcommand { <nl> parsedAuthority = fc : : json : : from_file ( authorityJsonOrFile ) ; <nl> } <nl> auth = parsedAuthority . as < authority > ( ) ; <nl> - } EOS_CAPTURE_AND_RETHROW ( authority_type_exception , " Fail to parse Authority JSON " ) <nl> - <nl> + } EOS_RETHROW_EXCEPTIONS ( authority_type_exception , " Fail to parse Authority JSON " ) <nl> + <nl> } <nl> <nl> name parent ; <nl> int main ( int argc , char * * argv ) { <nl> public_key_type owner_key , active_key ; <nl> try { <nl> owner_key = public_key_type ( owner_key_str ) ; <nl> + } EOS_RETHROW_EXCEPTIONS ( public_key_type_exception , " Invalid owner public key : $ { public_key } " , ( " public_key " , owner_key_str ) ) <nl> + try { <nl> active_key = public_key_type ( active_key_str ) ; <nl> - } EOS_CAPTURE_AND_RETHROW ( public_key_type_exception , " Invalid Public Key " ) <nl> + } EOS_RETHROW_EXCEPTIONS ( public_key_type_exception , " Invalid active public key : $ { public_key } " , ( " public_key " , active_key_str ) ) <nl> send_actions ( { create_newaccount ( creator , account_name , owner_key , active_key ) } ) ; <nl> } ) ; <nl> <nl> int main ( int argc , char * * argv ) { <nl> / / get currency balance <nl> string symbol ; <nl> auto get_currency = get - > add_subcommand ( " currency " , localized ( " Retrieve information related to standard currencies " ) , true ) ; <nl> + get_currency - > require_subcommand ( ) ; <nl> auto get_balance = get_currency - > add_subcommand ( " balance " , localized ( " Retrieve the balance of an account for a given currency " ) , false ) ; <nl> get_balance - > add_option ( " contract " , code , localized ( " The contract that operates the currency " ) ) - > required ( ) ; <nl> get_balance - > add_option ( " account " , accountName , localized ( " The account to query balances for " ) ) - > required ( ) ; <nl> int main ( int argc , char * * argv ) { <nl> } ) ; <nl> <nl> / / get accounts <nl> - string publicKey ; <nl> + string public_key_str ; <nl> auto getAccounts = get - > add_subcommand ( " accounts " , localized ( " Retrieve accounts associated with a public key " ) , false ) ; <nl> - getAccounts - > add_option ( " public_key " , publicKey , localized ( " The public key to retrieve accounts for " ) ) - > required ( ) ; <nl> + getAccounts - > add_option ( " public_key " , public_key_str , localized ( " The public key to retrieve accounts for " ) ) - > required ( ) ; <nl> getAccounts - > set_callback ( [ & ] { <nl> - auto arg = fc : : mutable_variant_object ( " public_key " , publicKey ) ; <nl> + public_key_type public_key ; <nl> + try { <nl> + public_key = public_key_type ( public_key_str ) ; <nl> + } EOS_RETHROW_EXCEPTIONS ( public_key_type_exception , " Invalid public key : $ { public_key } " , ( " public_key " , public_key_str ) ) <nl> + auto arg = fc : : mutable_variant_object ( " public_key " , public_key ) ; <nl> std : : cout < < fc : : json : : to_pretty_string ( call ( get_key_accounts_func , arg ) ) < < std : : endl ; <nl> } ) ; <nl> <nl> int main ( int argc , char * * argv ) { <nl> } ) ; <nl> <nl> / / get transaction <nl> - string transactionId ; <nl> + string transaction_id_str ; <nl> auto getTransaction = get - > add_subcommand ( " transaction " , localized ( " Retrieve a transaction from the blockchain " ) , false ) ; <nl> - getTransaction - > add_option ( " id " , transactionId , localized ( " ID of the transaction to retrieve " ) ) - > required ( ) ; <nl> + getTransaction - > add_option ( " id " , transaction_id_str , localized ( " ID of the transaction to retrieve " ) ) - > required ( ) ; <nl> getTransaction - > set_callback ( [ & ] { <nl> - auto arg = fc : : mutable_variant_object ( " transaction_id " , transactionId ) ; <nl> + transaction_id_type transaction_id ; <nl> + try { <nl> + transaction_id = transaction_id_type ( transaction_id_str ) ; <nl> + } EOS_RETHROW_EXCEPTIONS ( transaction_id_type_exception , " Invalid transaction ID : $ { transaction_id } " , ( " transaction_id " , transaction_id_str ) ) <nl> + auto arg = fc : : mutable_variant_object ( " transaction_id " , transaction_id ) ; <nl> std : : cout < < fc : : json : : to_pretty_string ( call ( get_transaction_func , arg ) ) < < std : : endl ; <nl> } ) ; <nl> <nl> / / get transactions <nl> - string skip_seq ; <nl> - string num_seq ; <nl> + string skip_seq_str ; <nl> + string num_seq_str ; <nl> auto getTransactions = get - > add_subcommand ( " transactions " , localized ( " Retrieve all transactions with specific account name referenced in their scope " ) , false ) ; <nl> getTransactions - > add_option ( " account_name " , account_name , localized ( " name of account to query on " ) ) - > required ( ) ; <nl> - getTransactions - > add_option ( " skip_seq " , skip_seq , localized ( " Number of most recent transactions to skip ( 0 would start at most recent transaction ) " ) ) ; <nl> - getTransactions - > add_option ( " num_seq " , num_seq , localized ( " Number of transactions to return " ) ) ; <nl> + getTransactions - > add_option ( " skip_seq " , skip_seq_str , localized ( " Number of most recent transactions to skip ( 0 would start at most recent transaction ) " ) ) ; <nl> + getTransactions - > add_option ( " num_seq " , num_seq_str , localized ( " Number of transactions to return " ) ) ; <nl> getTransactions - > set_callback ( [ & ] { <nl> - auto arg = ( skip_seq . empty ( ) ) <nl> - ? fc : : mutable_variant_object ( " account_name " , account_name ) <nl> - : ( num_seq . empty ( ) ) <nl> - ? fc : : mutable_variant_object ( " account_name " , account_name ) ( " skip_seq " , skip_seq ) <nl> - : fc : : mutable_variant_object ( " account_name " , account_name ) ( " skip_seq " , skip_seq ) ( " num_seq " , num_seq ) ; <nl> + fc : : mutable_variant_object arg ; <nl> + if ( skip_seq_str . empty ( ) ) { <nl> + arg = fc : : mutable_variant_object ( " account_name " , account_name ) ; <nl> + } else { <nl> + uint64_t skip_seq ; <nl> + try { <nl> + skip_seq = boost : : lexical_cast < uint64_t > ( skip_seq_str ) ; <nl> + } EOS_RETHROW_EXCEPTIONS ( chain_type_exception , " Invalid Skip Seq : $ { skip_seq } " , ( " skip_seq " , skip_seq_str ) ) <nl> + if ( num_seq_str . empty ( ) ) { <nl> + arg = fc : : mutable_variant_object ( " account_name " , account_name ) ( " skip_seq " , skip_seq ) ; <nl> + } else { <nl> + uint64_t num_seq ; <nl> + try { <nl> + num_seq = boost : : lexical_cast < uint64_t > ( num_seq_str ) ; <nl> + } EOS_RETHROW_EXCEPTIONS ( chain_type_exception , " Invalid Num Seq : $ { num_seq } " , ( " num_seq " , num_seq_str ) ) <nl> + arg = fc : : mutable_variant_object ( " account_name " , account_name ) ( " skip_seq " , skip_seq_str ) ( " num_seq " , num_seq ) ; <nl> + } <nl> + } <nl> auto result = call ( get_transactions_func , arg ) ; <nl> std : : cout < < fc : : json : : to_pretty_string ( call ( get_transactions_func , arg ) ) < < std : : endl ; <nl> <nl> int main ( int argc , char * * argv ) { <nl> if ( abi - > count ( ) ) { <nl> try { <nl> actions . emplace_back ( create_setabi ( account , fc : : json : : from_file ( abiPath ) . as < contracts : : abi_def > ( ) ) ) ; <nl> - } EOS_CAPTURE_AND_RETHROW ( abi_type_exception , " Fail to parse ABI JSON " ) <nl> + } EOS_RETHROW_EXCEPTIONS ( abi_type_exception , " Fail to parse ABI JSON " ) <nl> } <nl> <nl> std : : cout < < localized ( " Publishing contract . . . " ) < < std : : endl ; <nl> int main ( int argc , char * * argv ) { <nl> } ) ; <nl> <nl> / / import keys into wallet <nl> - string wallet_key ; <nl> + string wallet_key_str ; <nl> auto importWallet = wallet - > add_subcommand ( " import " , localized ( " Import private key into wallet " ) , false ) ; <nl> importWallet - > add_option ( " - n , - - name " , wallet_name , localized ( " The name of the wallet to import key into " ) ) ; <nl> - importWallet - > add_option ( " key " , wallet_key , localized ( " Private key in WIF format to import " ) ) - > required ( ) ; <nl> - importWallet - > set_callback ( [ & wallet_name , & wallet_key ] { <nl> - private_key_type key ( wallet_key ) ; <nl> - public_key_type pubkey = key . get_public_key ( ) ; <nl> + importWallet - > add_option ( " key " , wallet_key_str , localized ( " Private key in WIF format to import " ) ) - > required ( ) ; <nl> + importWallet - > set_callback ( [ & wallet_name , & wallet_key_str ] { <nl> + private_key_type wallet_key ; <nl> + try { <nl> + wallet_key = private_key_type ( wallet_key_str ) ; <nl> + } catch ( . . . ) { <nl> + EOS_THROW ( private_key_type_exception , " Invalid private key : $ { private_key } " , ( " private_key " , wallet_key_str ) ) <nl> + } <nl> + public_key_type pubkey = wallet_key . get_public_key ( ) ; <nl> <nl> fc : : variants vs = { fc : : variant ( wallet_name ) , fc : : variant ( wallet_key ) } ; <nl> const auto & v = call ( wallet_host , wallet_port , wallet_import_key , vs ) ; <nl> int main ( int argc , char * * argv ) { <nl> fc : : variant action_args_var ; <nl> try { <nl> action_args_var = fc : : json : : from_string ( data ) ; <nl> - } EOS_CAPTURE_AND_RETHROW ( action_type_exception , " Fail to parse action JSON " ) <nl> + } EOS_RETHROW_EXCEPTIONS ( action_type_exception , " Fail to parse action JSON " ) <nl> <nl> auto arg = fc : : mutable_variant_object <nl> ( " code " , contract ) <nl> int main ( int argc , char * * argv ) { <nl> } else { <nl> trx_var = fc : : json : : from_string ( trx_to_push ) ; <nl> } <nl> - } EOS_CAPTURE_AND_RETHROW ( transaction_type_exception , " Fail to parse transaction JSON " ) signed_transaction trx = trx_var . as < signed_transaction > ( ) ; <nl> + } EOS_RETHROW_EXCEPTIONS ( transaction_type_exception , " Fail to parse transaction JSON " ) <nl> + signed_transaction trx = trx_var . as < signed_transaction > ( ) ; <nl> auto trx_result = call ( push_txn_func , packed_transaction ( trx , packed_transaction : : none ) ) ; <nl> std : : cout < < fc : : json : : to_pretty_string ( trx_result ) < < std : : endl ; <nl> } ) ; <nl> int main ( int argc , char * * argv ) { <nl> fc : : variant trx_var ; <nl> try { <nl> trx_var = fc : : json : : from_string ( trxsJson ) ; <nl> - } EOS_CAPTURE_AND_RETHROW ( transaction_type_exception , " Fail to parse transaction JSON " ) <nl> + } EOS_RETHROW_EXCEPTIONS ( transaction_type_exception , " Fail to parse transaction JSON " ) <nl> auto trxs_result = call ( push_txns_func , trx_var ) ; <nl> std : : cout < < fc : : json : : to_pretty_string ( trxs_result ) < < std : : endl ; <nl> } ) ; <nl> mmm a / scripts / abi_to_rc / abi_to_rc . py <nl> ppp b / scripts / abi_to_rc / abi_to_rc . py <nl> def get_actions_inputs_types ( ) : <nl> types [ action [ ' name ' ] ] . append ( field [ ' type ' ] ) <nl> <nl> # builds rows for the table <nl> - def build_table_rows ( ) : <nl> + def build_table_rows ( is_action ) : <nl> table_rows = [ ] <nl> for action in actions : <nl> - action_string = " ` " + action [ ' name ' ] + " ` " <nl> + action_string = " ` { { " + action [ ' name ' ] + " } } ` " <nl> input_string = " " <nl> input_list = [ ] <nl> type_string = " " <nl> type_list = [ ] <nl> if len ( inputs [ action [ ' name ' ] ] ) > = 1 : <nl> for name in inputs [ action [ ' name ' ] ] : <nl> - input_list . append ( " ` " + name + " ` " ) <nl> + input_list . append ( " ` { { " + name + ( " Var } } ` " if is_action else " } } ` " ) ) <nl> input_string = ' < br / > ' . join ( input_list ) <nl> else : <nl> - input_string = " ` " + action [ ' type ' ] + " ` " <nl> + input_string = " ` { { " + action [ ' type ' ] + ( " Var } } ` " if is_action else " } } ` " ) <nl> if len ( types [ action [ ' name ' ] ] ) > = 1 : <nl> for name in types [ action [ ' name ' ] ] : <nl> - type_list . append ( " ` " + name + " ` " ) <nl> + type_list . append ( " ` { { " + name + " } } ` " ) <nl> type_string = ' < br / > ' . join ( type_list ) <nl> else : <nl> - type_string = " ` " + action [ ' type ' ] + " ` " <nl> + type_string = " ` { { " + action [ ' type ' ] + " } } ` " <nl> table_rows . append ( ' | ' + action_string + ' | ' + input_string + ' | ' + type_string + ' | ' ) <nl> return table_rows <nl> <nl> # generates an overview ricardian contract from the overview template <nl> def generate_rc_overview_file ( ) : <nl> - tr = build_table_rows ( ) <nl> + tr = build_table_rows ( False ) <nl> abi_file_name = os . path . split ( args . abi_file ) [ 1 ] <nl> contract_name = os . path . splitext ( abi_file_name ) [ 0 ] <nl> rc_file_name = contract_name + ' - rc . md ' <nl> dirname = os . path . split ( args . abi_file ) [ 0 ] <nl> - subs = { ' contract ' : contract_name , <nl> + subs = { ' contract ' : " { { " + contract_name + " } } " , <nl> ' action ' : ' actions ' if len ( actions ) > 1 else ' action ' , <nl> ' input ' : ' inputs ' if len ( inputs ) > 1 else ' input ' , <nl> ' type ' : ' types ' if len ( types ) > 1 else ' type ' } <nl> def generate_rc_overview_file ( ) : <nl> <nl> # generates a ricardian contract for each action from the action template <nl> def generate_rc_action_files ( ) : <nl> - tr = build_table_rows ( ) <nl> + tr = build_table_rows ( True ) <nl> abi_filename = os . path . split ( args . abi_file ) [ 1 ] <nl> contract_name = os . path . splitext ( abi_filename ) [ 0 ] <nl> dirname = os . path . split ( args . abi_file ) [ 0 ] <nl> for action in actions : <nl> - subs = { ' action ' : action [ ' name ' ] , <nl> + subs = { ' action ' : " { { " + action [ ' name ' ] + " } } " , <nl> ' input ' : ' inputs ' if len ( inputs [ action [ ' name ' ] ] ) > 1 else ' input ' , <nl> ' type ' : ' types ' if len ( types [ action [ ' name ' ] ] ) > 1 else ' type ' } <nl> subs . update ( [ ( k + ' _header ' , v . title ( ) ) for k , v in subs . copy ( ) . items ( ) ] ) <nl> mmm a / tests / api_tests / api_tests . cpp <nl> ppp b / tests / api_tests / api_tests . cpp <nl> BOOST_FIXTURE_TEST_CASE ( action_tests , tester ) { try { <nl> CALL_TEST_FUNCTION ( * this , " test_action " , " assert_true " , { } ) ; <nl> <nl> / / test assert_false <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_action " , " assert_false " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_action " , " assert_false " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " test_action : : assert_false " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( action_tests , tester ) { try { <nl> <nl> / / test now <nl> produce_block ( ) ; <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_action " , " now " , fc : : raw : : pack ( now ) ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_action " , " now " , fc : : raw : : pack ( now ) ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " assertion failed : tmp = = now " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( action_tests , tester ) { try { <nl> CALL_TEST_FUNCTION ( * this , " test_action " , " test_publication_time " , fc : : raw : : pack ( pub_time ) ) ; <nl> <nl> / / test test_abort <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_action " , " test_abort " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_action " , " test_abort " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " abort ( ) called " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( cf_action_tests , tester ) { try { <nl> auto sigs = trx . sign ( get_private_key ( N ( testapi ) , " active " ) , chain_id_type ( ) ) ; <nl> <nl> BOOST_CHECK_EXCEPTION ( push_transaction ( trx ) , tx_irrelevant_sig , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + [ ] ( const fc : : exception & e ) { <nl> edump ( ( e . what ( ) ) ) ; <nl> return expect_assert_message ( e , " signatures " ) ; <nl> } <nl> BOOST_FIXTURE_TEST_CASE ( cf_action_tests , tester ) { try { <nl> set_tapos ( trx ) ; <nl> / / run normal passing case <nl> sigs = trx . sign ( get_private_key ( N ( testapi ) , " active " ) , chain_id_type ( ) ) ; <nl> - BOOST_CHECK_EXCEPTION ( push_transaction ( trx ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( push_transaction ( trx ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " may only be called from context_free " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( cf_action_tests , tester ) { try { <nl> trx . signatures . clear ( ) ; <nl> set_tapos ( trx ) ; <nl> sigs = trx . sign ( get_private_key ( N ( testapi ) , " active " ) , chain_id_type ( ) ) ; <nl> - BOOST_CHECK_EXCEPTION ( push_transaction ( trx ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( push_transaction ( trx ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " context_free : only context free api ' s can be used in this context " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( cf_action_tests , tester ) { try { <nl> BOOST_CHECK_EQUAL ( ttrace . action_traces [ 1 ] . act . name = = account_name ( " event1 " ) , true ) ; <nl> BOOST_CHECK_EQUAL ( ttrace . action_traces [ 1 ] . act . authorization . size ( ) , 0 ) ; <nl> <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_transaction " , " send_cf_action_fail " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_transaction " , " send_cf_action_fail " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " context free actions cannot have authorizations " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( compiler_builtins_tests , tester ) { try { <nl> CALL_TEST_FUNCTION ( * this , " test_compiler_builtins " , " test_divti3 " , { } ) ; <nl> <nl> / / test test_divti3_by_0 <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_compiler_builtins " , " test_divti3_by_0 " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_compiler_builtins " , " test_divti3_by_0 " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " divide by zero " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( compiler_builtins_tests , tester ) { try { <nl> CALL_TEST_FUNCTION ( * this , " test_compiler_builtins " , " test_udivti3 " , { } ) ; <nl> <nl> / / test test_udivti3_by_0 <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_compiler_builtins " , " test_udivti3_by_0 " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_compiler_builtins " , " test_udivti3_by_0 " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " divide by zero " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( compiler_builtins_tests , tester ) { try { <nl> CALL_TEST_FUNCTION ( * this , " test_compiler_builtins " , " test_modti3 " , { } ) ; <nl> <nl> / / test test_modti3_by_0 <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_compiler_builtins " , " test_modti3_by_0 " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_compiler_builtins " , " test_modti3_by_0 " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " divide by zero " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( transaction_tests , tester ) { try { <nl> CALL_TEST_FUNCTION ( * this , " test_transaction " , " send_action_empty " , { } ) ; <nl> <nl> / / test send_action_large <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_transaction " , " send_action_large " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_transaction " , " send_action_large " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " data_len < config : : default_max_inline_action_size : inline action too big " ) ; <nl> } <nl> ) ; <nl> <nl> / / test send_action_inline_fail <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_transaction " , " send_action_inline_fail " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_transaction " , " send_action_inline_fail " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " test_action : : assert_false " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( transaction_tests , tester ) { try { <nl> control - > push_deferred_transactions ( true ) ; <nl> <nl> / / test send_transaction_empty <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_transaction " , " send_transaction_empty " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_transaction " , " send_transaction_empty " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " transaction must have at least one action " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( multi_index_tests , tester ) { try { <nl> CALL_TEST_FUNCTION ( * this , " test_multi_index " , " idx256_general " , { } ) ; <nl> CALL_TEST_FUNCTION ( * this , " test_multi_index " , " idx_double_general " , { } ) ; <nl> CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION ( * this , " test_multi_index " , " idx64_pk_iterator_exceed_end " , { } , <nl> - fc : : assert_exception , " cannot increment end iterator " ) ; <nl> + transaction_exception , " cannot increment end iterator " ) ; <nl> CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION ( * this , " test_multi_index " , " idx64_sk_iterator_exceed_end " , { } , <nl> - fc : : assert_exception , " cannot increment end iterator " ) ; <nl> + transaction_exception , " cannot increment end iterator " ) ; <nl> CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION ( * this , " test_multi_index " , " idx64_pk_iterator_exceed_begin " , { } , <nl> - fc : : assert_exception , " cannot decrement iterator at beginning of table " ) ; <nl> + transaction_exception , " cannot decrement iterator at beginning of table " ) ; <nl> CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION ( * this , " test_multi_index " , " idx64_sk_iterator_exceed_begin " , { } , <nl> - fc : : assert_exception , " cannot decrement iterator at beginning of index " ) ; <nl> + transaction_exception , " cannot decrement iterator at beginning of index " ) ; <nl> CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION ( * this , " test_multi_index " , " idx64_pass_pk_ref_to_other_table " , { } , <nl> - fc : : assert_exception , " object passed to iterator_to is not in multi_index " ) ; <nl> + transaction_exception , " object passed to iterator_to is not in multi_index " ) ; <nl> CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION ( * this , " test_multi_index " , " idx64_pass_sk_ref_to_other_table " , { } , <nl> - fc : : assert_exception , " object passed to iterator_to is not in multi_index " ) ; <nl> + transaction_exception , " object passed to iterator_to is not in multi_index " ) ; <nl> CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION ( * this , " test_multi_index " , " idx64_pass_pk_end_itr_to_iterator_to " , { } , <nl> - fc : : assert_exception , " object passed to iterator_to is not in multi_index " ) ; <nl> + transaction_exception , " object passed to iterator_to is not in multi_index " ) ; <nl> CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION ( * this , " test_multi_index " , " idx64_pass_pk_end_itr_to_modify " , { } , <nl> - fc : : assert_exception , " cannot pass end iterator to modify " ) ; <nl> + transaction_exception , " cannot pass end iterator to modify " ) ; <nl> CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION ( * this , " test_multi_index " , " idx64_pass_pk_end_itr_to_erase " , { } , <nl> - fc : : assert_exception , " cannot pass end iterator to erase " ) ; <nl> + transaction_exception , " cannot pass end iterator to erase " ) ; <nl> CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION ( * this , " test_multi_index " , " idx64_pass_sk_end_itr_to_iterator_to " , { } , <nl> - fc : : assert_exception , " object passed to iterator_to is not in multi_index " ) ; <nl> + transaction_exception , " object passed to iterator_to is not in multi_index " ) ; <nl> CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION ( * this , " test_multi_index " , " idx64_pass_sk_end_itr_to_modify " , { } , <nl> - fc : : assert_exception , " cannot pass end iterator to modify " ) ; <nl> + transaction_exception , " cannot pass end iterator to modify " ) ; <nl> CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION ( * this , " test_multi_index " , " idx64_pass_sk_end_itr_to_erase " , { } , <nl> - fc : : assert_exception , " cannot pass end iterator to erase " ) ; <nl> + transaction_exception , " cannot pass end iterator to erase " ) ; <nl> CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION ( * this , " test_multi_index " , " idx64_modify_primary_key " , { } , <nl> - fc : : assert_exception , " updater cannot change primary key when modifying an object " ) ; <nl> + transaction_exception , " updater cannot change primary key when modifying an object " ) ; <nl> CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION ( * this , " test_multi_index " , " idx64_run_out_of_avl_pk " , { } , <nl> - fc : : assert_exception , " next primary key in table is at autoincrement limit " ) ; <nl> + transaction_exception , " next primary key in table is at autoincrement limit " ) ; <nl> CALL_TEST_FUNCTION ( * this , " test_multi_index " , " idx64_sk_cache_pk_lookup " , { } ) ; <nl> CALL_TEST_FUNCTION ( * this , " test_multi_index " , " idx64_pk_cache_sk_lookup " , { } ) ; <nl> <nl> BOOST_FIXTURE_TEST_CASE ( fixedpoint_tests , tester ) { try { <nl> CALL_TEST_FUNCTION ( * this , " test_fixedpoint " , " test_subtraction " , { } ) ; <nl> CALL_TEST_FUNCTION ( * this , " test_fixedpoint " , " test_multiplication " , { } ) ; <nl> CALL_TEST_FUNCTION ( * this , " test_fixedpoint " , " test_division " , { } ) ; <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_fixedpoint " , " test_division_by_0 " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_fixedpoint " , " test_division_by_0 " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " divide by zero " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( real_tests , tester ) { try { <nl> CALL_TEST_FUNCTION ( * this , " test_real " , " test_addition " , { } ) ; <nl> CALL_TEST_FUNCTION ( * this , " test_real " , " test_multiplication " , { } ) ; <nl> CALL_TEST_FUNCTION ( * this , " test_real " , " test_division " , { } ) ; <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_real " , " test_division_by_0 " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_real " , " test_division_by_0 " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " divide by zero " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( crypto_tests , tester ) { try { <nl> CALL_TEST_FUNCTION ( * this , " test_crypto " , " test_recover_key " , payload ) ; <nl> CALL_TEST_FUNCTION ( * this , " test_crypto " , " test_recover_key_assert_true " , payload ) ; <nl> payload [ payload . size ( ) - 1 ] = 0 ; <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_crypto " , " test_recover_key_assert_false " , payload ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_crypto " , " test_recover_key_assert_false " , payload ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " check = = p : Error expected key different than recovered key " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( crypto_tests , tester ) { try { <nl> CALL_TEST_FUNCTION ( * this , " test_crypto " , " sha512_no_data " , { } ) ; <nl> CALL_TEST_FUNCTION ( * this , " test_crypto " , " ripemd160_no_data " , { } ) ; <nl> <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_crypto " , " assert_sha256_false " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_crypto " , " assert_sha256_false " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " hash miss match " ) ; <nl> } <nl> ) ; <nl> <nl> CALL_TEST_FUNCTION ( * this , " test_crypto " , " assert_sha256_true " , { } ) ; <nl> <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_crypto " , " assert_sha1_false " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_crypto " , " assert_sha1_false " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " hash miss match " ) ; <nl> } <nl> ) ; <nl> <nl> CALL_TEST_FUNCTION ( * this , " test_crypto " , " assert_sha1_true " , { } ) ; <nl> <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_crypto " , " assert_sha1_false " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_crypto " , " assert_sha1_false " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " hash miss match " ) ; <nl> } <nl> ) ; <nl> <nl> CALL_TEST_FUNCTION ( * this , " test_crypto " , " assert_sha1_true " , { } ) ; <nl> <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_crypto " , " assert_sha512_false " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_crypto " , " assert_sha512_false " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " hash miss match " ) ; <nl> } <nl> ) ; <nl> <nl> CALL_TEST_FUNCTION ( * this , " test_crypto " , " assert_sha512_true " , { } ) ; <nl> <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_crypto " , " assert_ripemd160_false " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_crypto " , " assert_ripemd160_false " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " hash miss match " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( math_tests , tester ) { try { <nl> CALL_TEST_FUNCTION ( * this , " test_math " , " test_diveq " , fc : : raw : : pack ( act ) ) ; <nl> } <nl> / / test diveq for divide by zero <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_math " , " test_diveq_by_0 " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_math " , " test_diveq_by_0 " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " divide by zero " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( math_tests , tester ) { try { <nl> std : : copy ( d_vals . whole , d_vals . whole + sizeof ( d_vals ) , ds . begin ( ) ) ; <nl> CALL_TEST_FUNCTION ( * this , " test_math " , " test_double_to_i64 " , ds ) ; <nl> <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_math " , " test_double_api_div_0 " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_math " , " test_double_api_div_0 " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " divide by zero " ) ; <nl> } <nl> ) ; <nl> BOOST_FIXTURE_TEST_CASE ( privileged_tests , tester ) { try { <nl> } <nl> <nl> CALL_TEST_FUNCTION ( * this , " test_privileged " , " test_is_privileged " , { } ) ; <nl> - BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_privileged " , " test_is_privileged " , { } ) , fc : : assert_exception , <nl> - [ ] ( const fc : : assert_exception & e ) { <nl> + BOOST_CHECK_EXCEPTION ( CALL_TEST_FUNCTION ( * this , " test_privileged " , " test_is_privileged " , { } ) , transaction_exception , <nl> + [ ] ( const fc : : exception & e ) { <nl> return expect_assert_message ( e , " context . privileged : testapi does not have permission to call this API " ) ; <nl> } <nl> ) ; <nl> mmm a / tests / chain_tests / auth_tests . cpp <nl> ppp b / tests / chain_tests / auth_tests . cpp <nl> try { <nl> BOOST_TEST ( string ( joe_active_authority . auth . keys [ 0 ] . key ) = = string ( chain . get_public_key ( " joe " , " active " ) ) ) ; <nl> BOOST_TEST ( joe_active_authority . auth . keys [ 0 ] . weight = = 1 ) ; <nl> <nl> + / / Create duplicate name <nl> + BOOST_CHECK_EXCEPTION ( chain . create_account ( " joe " ) , action_validate_exception , <nl> + assert_message_is ( " Cannot create account named joe , as that name is already taken " ) ) ; <nl> + <nl> + / / Creating account with name more than 12 chars <nl> + BOOST_CHECK_EXCEPTION ( chain . create_account ( " aaaaaaaaaaaaa " ) , action_validate_exception , <nl> + assert_message_is ( " account names can only be 12 chars long " ) ) ; <nl> + <nl> + / / Creating account with eosio . prefix with priveleged account <nl> + chain . create_account ( " eosio . test1 " ) ; <nl> + <nl> + / / Creating account with eosio . prefix with non - privileged account , should fail <nl> + BOOST_CHECK_EXCEPTION ( chain . create_account ( " eosio . test2 " , " joe " ) , action_validate_exception , <nl> + assert_message_is ( " only privileged accounts can have names that contain ' eosio . ' " ) ) ; <nl> + <nl> + <nl> } FC_LOG_AND_RETHROW ( ) } <nl> <nl> BOOST_AUTO_TEST_CASE ( any_auth ) { try { <nl> mmm a / tests / chain_tests / delay_tests . cpp <nl> ppp b / tests / chain_tests / delay_tests . cpp <nl> BOOST_AUTO_TEST_CASE ( link_delay_permission_change_test ) { try { <nl> liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> <nl> - / / this transaction will be delayed 20 sec <nl> + / / this transaction will be delayed 20 blocks <nl> trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( tester ) , fc : : mutable_variant_object ( ) <nl> ( " from " , " tester " ) <nl> ( " to " , " tester2 " ) <nl> BOOST_AUTO_TEST_CASE ( link_delay_permission_change_test ) { try { <nl> liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> <nl> - / / this transaction will be delayed 20 sec <nl> + / / this transaction will be delayed 20 blocks <nl> trace = chain . push_action ( config : : system_account_name , contracts : : updateauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> ( " account " , " tester " ) <nl> ( " permission " , " first " ) <nl> BOOST_AUTO_TEST_CASE ( link_delay_permission_change_test ) { try { <nl> liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> <nl> - / / this transaction will be delayed 20 sec <nl> + / / this transaction will be delayed 20 blocks <nl> trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( tester ) , fc : : mutable_variant_object ( ) <nl> ( " from " , " tester " ) <nl> ( " to " , " tester2 " ) <nl> BOOST_AUTO_TEST_CASE ( link_delay_permission_change_test ) { try { <nl> liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> <nl> - / / first transfer will finally performed <nl> + / / first transfer will finally be performed <nl> chain . control - > push_deferred_transactions ( true ) ; <nl> <nl> chain . produce_blocks ( ) ; <nl> BOOST_AUTO_TEST_CASE ( link_delay_permission_change_test ) { try { <nl> <nl> } FC_LOG_AND_RETHROW ( ) } / / / schedule_test <nl> <nl> + / / test removing delay on permission based on heirarchy delay <nl> + BOOST_AUTO_TEST_CASE ( link_delay_permission_change_with_delay_heirarchy_test ) { try { <nl> + tester chain ; <nl> + <nl> + const auto & tester_account = N ( tester ) ; <nl> + <nl> + chain . set_code ( config : : system_account_name , eosio_system_wast ) ; <nl> + chain . set_abi ( config : : system_account_name , eosio_system_abi ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + chain . create_account ( N ( currency ) ) ; <nl> + chain . produce_blocks ( 10 ) ; <nl> + <nl> + chain . set_code ( N ( currency ) , currency_wast ) ; <nl> + chain . set_abi ( N ( currency ) , currency_abi ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + chain . create_account ( N ( tester ) ) ; <nl> + chain . create_account ( N ( tester2 ) ) ; <nl> + chain . produce_blocks ( 10 ) ; <nl> + <nl> + chain . push_action ( config : : system_account_name , contracts : : updateauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> + ( " account " , " tester " ) <nl> + ( " permission " , " first " ) <nl> + ( " parent " , " active " ) <nl> + ( " data " , authority ( chain . get_public_key ( tester_account , " first " ) ) ) <nl> + ( " delay " , 10 ) ) ; <nl> + chain . push_action ( config : : system_account_name , contracts : : updateauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> + ( " account " , " tester " ) <nl> + ( " permission " , " second " ) <nl> + ( " parent " , " first " ) <nl> + ( " data " , authority ( chain . get_public_key ( tester_account , " second " ) ) ) <nl> + ( " delay " , 0 ) ) ; <nl> + chain . push_action ( config : : system_account_name , contracts : : linkauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> + ( " account " , " tester " ) <nl> + ( " code " , " currency " ) <nl> + ( " type " , " transfer " ) <nl> + ( " requirement " , " second " ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + chain . push_action ( N ( currency ) , N ( create ) , N ( currency ) , mutable_variant_object ( ) <nl> + ( " issuer " , " currency " ) <nl> + ( " maximum_supply " , " 9000000 . 0000 CUR " ) <nl> + ( " can_freeze " , 0 ) <nl> + ( " can_recall " , 0 ) <nl> + ( " can_whitelist " , 0 ) <nl> + ) ; <nl> + <nl> + chain . push_action ( N ( currency ) , name ( " issue " ) , N ( currency ) , fc : : mutable_variant_object ( ) <nl> + ( " to " , " currency " ) <nl> + ( " quantity " , " 1000000 . 0000 CUR " ) <nl> + ( " memo " , " for stuff " ) <nl> + ) ; <nl> + <nl> + auto trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( currency ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " currency " ) <nl> + ( " to " , " tester " ) <nl> + ( " quantity " , " 100 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) <nl> + ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : executed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + auto liquid_balance = get_currency_balance ( chain , N ( currency ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 999900 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / this transaction will be delayed 20 blocks <nl> + trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( tester ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " tester " ) <nl> + ( " to " , " tester2 " ) <nl> + ( " quantity " , " 1 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) , <nl> + 30 <nl> + ) ; <nl> + <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : delayed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 1 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . action_traces . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( currency ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 999900 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / this transaction will be delayed 20 blocks <nl> + chain . push_action ( config : : system_account_name , contracts : : updateauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> + ( " account " , " tester " ) <nl> + ( " permission " , " first " ) <nl> + ( " parent " , " active " ) <nl> + ( " data " , authority ( chain . get_public_key ( tester_account , " first " ) ) ) <nl> + ( " delay " , 0 ) , <nl> + 30 ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : delayed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 1 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . action_traces . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( 16 ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / this transaction will be delayed 20 blocks <nl> + trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( tester ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " tester " ) <nl> + ( " to " , " tester2 " ) <nl> + ( " quantity " , " 5 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) , <nl> + 30 <nl> + ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : delayed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 1 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . action_traces . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / first transfer will finally be performed <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 99 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 1 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / this transfer is performed right away since delay is removed <nl> + trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( tester ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " tester " ) <nl> + ( " to " , " tester2 " ) <nl> + ( " quantity " , " 10 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) <nl> + ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : executed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 89 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 11 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( 15 ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 89 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 11 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 89 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 11 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / second transfer finally is performed <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 84 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 16 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + } FC_LOG_AND_RETHROW ( ) } / / / schedule_test <nl> + <nl> + / / test moving link with delay on permission <nl> + BOOST_AUTO_TEST_CASE ( link_delay_link_change_test ) { try { <nl> + tester chain ; <nl> + <nl> + const auto & tester_account = N ( tester ) ; <nl> + <nl> + chain . set_code ( config : : system_account_name , eosio_system_wast ) ; <nl> + chain . set_abi ( config : : system_account_name , eosio_system_abi ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + chain . create_account ( N ( currency ) ) ; <nl> + chain . produce_blocks ( 10 ) ; <nl> + <nl> + chain . set_code ( N ( currency ) , currency_wast ) ; <nl> + chain . set_abi ( N ( currency ) , currency_abi ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + chain . create_account ( N ( tester ) ) ; <nl> + chain . create_account ( N ( tester2 ) ) ; <nl> + chain . produce_blocks ( 10 ) ; <nl> + <nl> + chain . push_action ( config : : system_account_name , contracts : : updateauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> + ( " account " , " tester " ) <nl> + ( " permission " , " first " ) <nl> + ( " parent " , " active " ) <nl> + ( " data " , authority ( chain . get_public_key ( tester_account , " first " ) ) ) <nl> + ( " delay " , 10 ) ) ; <nl> + chain . push_action ( config : : system_account_name , contracts : : linkauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> + ( " account " , " tester " ) <nl> + ( " code " , " currency " ) <nl> + ( " type " , " transfer " ) <nl> + ( " requirement " , " first " ) ) ; <nl> + chain . push_action ( config : : system_account_name , contracts : : updateauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> + ( " account " , " tester " ) <nl> + ( " permission " , " second " ) <nl> + ( " parent " , " active " ) <nl> + ( " data " , authority ( chain . get_public_key ( tester_account , " second " ) ) ) <nl> + ( " delay " , 0 ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + chain . push_action ( N ( currency ) , N ( create ) , N ( currency ) , mutable_variant_object ( ) <nl> + ( " issuer " , " currency " ) <nl> + ( " maximum_supply " , " 9000000 . 0000 CUR " ) <nl> + ( " can_freeze " , 0 ) <nl> + ( " can_recall " , 0 ) <nl> + ( " can_whitelist " , 0 ) <nl> + ) ; <nl> + <nl> + chain . push_action ( N ( currency ) , name ( " issue " ) , N ( currency ) , fc : : mutable_variant_object ( ) <nl> + ( " to " , " currency " ) <nl> + ( " quantity " , " 1000000 . 0000 CUR " ) <nl> + ( " memo " , " for stuff " ) <nl> + ) ; <nl> + <nl> + auto trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( currency ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " currency " ) <nl> + ( " to " , " tester " ) <nl> + ( " quantity " , " 100 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) <nl> + ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : executed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + auto liquid_balance = get_currency_balance ( chain , N ( currency ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 999900 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / this transaction will be delayed 20 blocks <nl> + trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( tester ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " tester " ) <nl> + ( " to " , " tester2 " ) <nl> + ( " quantity " , " 1 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) , <nl> + 30 <nl> + ) ; <nl> + <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : delayed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 1 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . action_traces . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( currency ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 999900 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / this transaction will be delayed 20 blocks <nl> + chain . push_action ( config : : system_account_name , contracts : : linkauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> + ( " account " , " tester " ) <nl> + ( " code " , " currency " ) <nl> + ( " type " , " transfer " ) <nl> + ( " requirement " , " second " ) , <nl> + 30 ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : delayed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 1 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . action_traces . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( 16 ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / this transaction will be delayed 20 blocks <nl> + trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( tester ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " tester " ) <nl> + ( " to " , " tester2 " ) <nl> + ( " quantity " , " 5 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) , <nl> + 30 <nl> + ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : delayed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 1 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . action_traces . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / first transfer will finally be performed <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 99 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 1 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / this transfer is performed right away since delay is removed <nl> + trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( tester ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " tester " ) <nl> + ( " to " , " tester2 " ) <nl> + ( " quantity " , " 10 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) <nl> + ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : executed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 89 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 11 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( 15 ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 89 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 11 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 89 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 11 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / second transfer finally is performed <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 84 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 16 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + } FC_LOG_AND_RETHROW ( ) } / / / schedule_test <nl> + <nl> + / / test moving link with delay on permission ' s parent <nl> + BOOST_AUTO_TEST_CASE ( link_delay_link_change_heirarchy_test ) { try { <nl> + tester chain ; <nl> + <nl> + const auto & tester_account = N ( tester ) ; <nl> + <nl> + chain . set_code ( config : : system_account_name , eosio_system_wast ) ; <nl> + chain . set_abi ( config : : system_account_name , eosio_system_abi ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + chain . create_account ( N ( currency ) ) ; <nl> + chain . produce_blocks ( 10 ) ; <nl> + <nl> + chain . set_code ( N ( currency ) , currency_wast ) ; <nl> + chain . set_abi ( N ( currency ) , currency_abi ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + chain . create_account ( N ( tester ) ) ; <nl> + chain . create_account ( N ( tester2 ) ) ; <nl> + chain . produce_blocks ( 10 ) ; <nl> + <nl> + chain . push_action ( config : : system_account_name , contracts : : updateauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> + ( " account " , " tester " ) <nl> + ( " permission " , " first " ) <nl> + ( " parent " , " active " ) <nl> + ( " data " , authority ( chain . get_public_key ( tester_account , " first " ) ) ) <nl> + ( " delay " , 10 ) ) ; <nl> + chain . push_action ( config : : system_account_name , contracts : : updateauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> + ( " account " , " tester " ) <nl> + ( " permission " , " second " ) <nl> + ( " parent " , " first " ) <nl> + ( " data " , authority ( chain . get_public_key ( tester_account , " first " ) ) ) <nl> + ( " delay " , 0 ) ) ; <nl> + chain . push_action ( config : : system_account_name , contracts : : linkauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> + ( " account " , " tester " ) <nl> + ( " code " , " currency " ) <nl> + ( " type " , " transfer " ) <nl> + ( " requirement " , " second " ) ) ; <nl> + chain . push_action ( config : : system_account_name , contracts : : updateauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> + ( " account " , " tester " ) <nl> + ( " permission " , " third " ) <nl> + ( " parent " , " active " ) <nl> + ( " data " , authority ( chain . get_public_key ( tester_account , " third " ) ) ) <nl> + ( " delay " , 0 ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + chain . push_action ( N ( currency ) , N ( create ) , N ( currency ) , mutable_variant_object ( ) <nl> + ( " issuer " , " currency " ) <nl> + ( " maximum_supply " , " 9000000 . 0000 CUR " ) <nl> + ( " can_freeze " , 0 ) <nl> + ( " can_recall " , 0 ) <nl> + ( " can_whitelist " , 0 ) <nl> + ) ; <nl> + <nl> + chain . push_action ( N ( currency ) , name ( " issue " ) , N ( currency ) , fc : : mutable_variant_object ( ) <nl> + ( " to " , " currency " ) <nl> + ( " quantity " , " 1000000 . 0000 CUR " ) <nl> + ( " memo " , " for stuff " ) <nl> + ) ; <nl> + <nl> + auto trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( currency ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " currency " ) <nl> + ( " to " , " tester " ) <nl> + ( " quantity " , " 100 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) <nl> + ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : executed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + auto liquid_balance = get_currency_balance ( chain , N ( currency ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 999900 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / this transaction will be delayed 20 blocks <nl> + trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( tester ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " tester " ) <nl> + ( " to " , " tester2 " ) <nl> + ( " quantity " , " 1 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) , <nl> + 30 <nl> + ) ; <nl> + <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : delayed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 1 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . action_traces . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( currency ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 999900 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / this transaction will be delayed 20 blocks <nl> + chain . push_action ( config : : system_account_name , contracts : : linkauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> + ( " account " , " tester " ) <nl> + ( " code " , " currency " ) <nl> + ( " type " , " transfer " ) <nl> + ( " requirement " , " third " ) , <nl> + 30 ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : delayed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 1 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . action_traces . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( 16 ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / this transaction will be delayed 20 blocks <nl> + trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( tester ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " tester " ) <nl> + ( " to " , " tester2 " ) <nl> + ( " quantity " , " 5 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) , <nl> + 30 <nl> + ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : delayed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 1 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . action_traces . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / first transfer will finally be performed <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 99 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 1 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / this transfer is performed right away since delay is removed <nl> + trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( tester ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " tester " ) <nl> + ( " to " , " tester2 " ) <nl> + ( " quantity " , " 10 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) <nl> + ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : executed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 89 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 11 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( 15 ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 89 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 11 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 89 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 11 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / second transfer finally is performed <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 84 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 16 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + } FC_LOG_AND_RETHROW ( ) } / / / schedule_test <nl> + <nl> + / / test mindelay action imposing delay <nl> + BOOST_AUTO_TEST_CASE ( mindelay_test ) { try { <nl> + tester chain ; <nl> + <nl> + const auto & tester_account = N ( tester ) ; <nl> + <nl> + chain . set_code ( config : : system_account_name , eosio_system_wast ) ; <nl> + chain . set_abi ( config : : system_account_name , eosio_system_abi ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + chain . create_account ( N ( currency ) ) ; <nl> + chain . produce_blocks ( 10 ) ; <nl> + <nl> + chain . set_code ( N ( currency ) , currency_wast ) ; <nl> + chain . set_abi ( N ( currency ) , currency_abi ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + chain . create_account ( N ( tester ) ) ; <nl> + chain . create_account ( N ( tester2 ) ) ; <nl> + chain . produce_blocks ( 10 ) ; <nl> + <nl> + chain . push_action ( N ( currency ) , N ( create ) , N ( currency ) , mutable_variant_object ( ) <nl> + ( " issuer " , " currency " ) <nl> + ( " maximum_supply " , " 9000000 . 0000 CUR " ) <nl> + ( " can_freeze " , 0 ) <nl> + ( " can_recall " , 0 ) <nl> + ( " can_whitelist " , 0 ) <nl> + ) ; <nl> + <nl> + chain . push_action ( N ( currency ) , name ( " issue " ) , N ( currency ) , fc : : mutable_variant_object ( ) <nl> + ( " to " , " currency " ) <nl> + ( " quantity " , " 1000000 . 0000 CUR " ) <nl> + ( " memo " , " for stuff " ) <nl> + ) ; <nl> + <nl> + auto trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( currency ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " currency " ) <nl> + ( " to " , " tester " ) <nl> + ( " quantity " , " 100 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) <nl> + ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : executed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + auto liquid_balance = get_currency_balance ( chain , N ( currency ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 999900 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( tester ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " tester " ) <nl> + ( " to " , " tester2 " ) <nl> + ( " quantity " , " 1 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) <nl> + ) ; <nl> + <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : executed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( currency ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 999900 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 99 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 1 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / send transfer and mindelay <nl> + const auto & acnt = chain . control - > get_database ( ) . get < account_object , by_name > ( N ( currency ) ) ; <nl> + const auto abi = acnt . get_abi ( ) ; <nl> + chain : : contracts : : abi_serializer abis ( abi ) ; <nl> + const auto a = chain . control - > get_database ( ) . get < account_object , by_name > ( N ( currency ) ) . get_abi ( ) ; <nl> + <nl> + string action_type_name = abis . get_action_type ( name ( " transfer " ) ) ; <nl> + <nl> + action act ; <nl> + act . account = N ( currency ) ; <nl> + act . name = name ( " transfer " ) ; <nl> + act . authorization . push_back ( permission_level { N ( tester ) , config : : active_name } ) ; <nl> + act . data = abis . variant_to_binary ( action_type_name , fc : : mutable_variant_object ( ) <nl> + ( " from " , " tester " ) <nl> + ( " to " , " tester2 " ) <nl> + ( " quantity " , " 3 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) <nl> + ) ; <nl> + <nl> + signed_transaction trx ; <nl> + trx . actions . push_back ( act ) ; <nl> + <nl> + trx . context_free_actions . emplace_back ( vector < permission_level > ( ) , chain : : contracts : : mindelay { . delay = 10 } ) ; <nl> + <nl> + chain . set_tapos ( trx , 30 ) ; <nl> + trx . sign ( chain . get_private_key ( N ( tester ) , " active " ) , chain_id_type ( ) ) ; <nl> + trace = chain . push_transaction ( trx ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : delayed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 1 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . action_traces . size ( ) ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 99 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 1 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 99 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 1 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( 18 ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 99 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 1 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 99 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 1 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 96 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 4 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + } FC_LOG_AND_RETHROW ( ) } / / / schedule_test <nl> + <nl> + / / test canceldelay action cancelling a delayed transaction <nl> + BOOST_AUTO_TEST_CASE ( canceldelay_test ) { try { <nl> + tester chain ; <nl> + <nl> + const auto & tester_account = N ( tester ) ; <nl> + <nl> + chain . set_code ( config : : system_account_name , eosio_system_wast ) ; <nl> + chain . set_abi ( config : : system_account_name , eosio_system_abi ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + chain . create_account ( N ( currency ) ) ; <nl> + chain . produce_blocks ( 10 ) ; <nl> + <nl> + chain . set_code ( N ( currency ) , currency_wast ) ; <nl> + chain . set_abi ( N ( currency ) , currency_abi ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + chain . create_account ( N ( tester ) ) ; <nl> + chain . create_account ( N ( tester2 ) ) ; <nl> + chain . produce_blocks ( 10 ) ; <nl> + <nl> + chain . push_action ( config : : system_account_name , contracts : : updateauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> + ( " account " , " tester " ) <nl> + ( " permission " , " first " ) <nl> + ( " parent " , " active " ) <nl> + ( " data " , authority ( chain . get_public_key ( tester_account , " first " ) ) ) <nl> + ( " delay " , 10 ) ) ; <nl> + chain . push_action ( config : : system_account_name , contracts : : linkauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> + ( " account " , " tester " ) <nl> + ( " code " , " currency " ) <nl> + ( " type " , " transfer " ) <nl> + ( " requirement " , " first " ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + chain . push_action ( N ( currency ) , N ( create ) , N ( currency ) , mutable_variant_object ( ) <nl> + ( " issuer " , " currency " ) <nl> + ( " maximum_supply " , " 9000000 . 0000 CUR " ) <nl> + ( " can_freeze " , 0 ) <nl> + ( " can_recall " , 0 ) <nl> + ( " can_whitelist " , 0 ) <nl> + ) ; <nl> + <nl> + chain . push_action ( N ( currency ) , name ( " issue " ) , N ( currency ) , fc : : mutable_variant_object ( ) <nl> + ( " to " , " currency " ) <nl> + ( " quantity " , " 1000000 . 0000 CUR " ) <nl> + ( " memo " , " for stuff " ) <nl> + ) ; <nl> + <nl> + auto trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( currency ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " currency " ) <nl> + ( " to " , " tester " ) <nl> + ( " quantity " , " 100 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) <nl> + ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : executed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + auto liquid_balance = get_currency_balance ( chain , N ( currency ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 999900 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / this transaction will be delayed 20 blocks <nl> + trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( tester ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " tester " ) <nl> + ( " to " , " tester2 " ) <nl> + ( " quantity " , " 1 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) , <nl> + 30 <nl> + ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : delayed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 1 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . action_traces . size ( ) ) ; <nl> + const auto sender_id_to_cancel = trace . deferred_transaction_requests [ 0 ] . get < deferred_transaction > ( ) . sender_id ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( currency ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 999900 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / this transaction will be delayed 20 blocks <nl> + trace = chain . push_action ( config : : system_account_name , contracts : : updateauth : : get_name ( ) , tester_account , fc : : mutable_variant_object ( ) <nl> + ( " account " , " tester " ) <nl> + ( " permission " , " first " ) <nl> + ( " parent " , " active " ) <nl> + ( " data " , authority ( chain . get_public_key ( tester_account , " first " ) ) ) <nl> + ( " delay " , 0 ) , <nl> + 30 ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : delayed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 1 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . action_traces . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( 16 ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / this transaction will be delayed 20 blocks <nl> + trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( tester ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " tester " ) <nl> + ( " to " , " tester2 " ) <nl> + ( " quantity " , " 5 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) , <nl> + 30 <nl> + ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : delayed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 1 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . action_traces . size ( ) ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / send canceldelay for first delayed transaction <nl> + signed_transaction trx ; <nl> + trx . actions . emplace_back ( vector < permission_level > { { N ( tester ) , config : : active_name } } , <nl> + chain : : contracts : : canceldelay { sender_id_to_cancel } ) ; <nl> + <nl> + chain . set_tapos ( trx ) ; <nl> + trx . sign ( chain . get_private_key ( N ( tester ) , " active " ) , chain_id_type ( ) ) ; <nl> + trace = chain . push_transaction ( trx ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : executed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 1 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + const auto sender_id_canceled = trace . deferred_transaction_requests [ 0 ] . get < deferred_reference > ( ) . sender_id ; <nl> + BOOST_REQUIRE_EQUAL ( sender_id_to_cancel , sender_id_canceled ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / first transfer will finally be performed <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 100 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 0 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / this transfer is performed right away since delay is removed <nl> + trace = chain . push_action ( N ( currency ) , name ( " transfer " ) , N ( tester ) , fc : : mutable_variant_object ( ) <nl> + ( " from " , " tester " ) <nl> + ( " to " , " tester2 " ) <nl> + ( " quantity " , " 10 . 0000 CUR " ) <nl> + ( " memo " , " hi " ) <nl> + ) ; <nl> + BOOST_REQUIRE_EQUAL ( transaction_receipt : : executed , trace . status ) ; <nl> + BOOST_REQUIRE_EQUAL ( 0 , trace . deferred_transaction_requests . size ( ) ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 90 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 10 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( 15 ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 90 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 10 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 90 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 10 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + / / second transfer finally is performed <nl> + chain . control - > push_deferred_transactions ( true ) ; <nl> + <nl> + chain . produce_blocks ( ) ; <nl> + <nl> + liquid_balance = get_currency_balance ( chain , N ( tester ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 85 . 0000 CUR " ) , liquid_balance ) ; <nl> + liquid_balance = get_currency_balance ( chain , N ( tester2 ) ) ; <nl> + BOOST_REQUIRE_EQUAL ( asset : : from_string ( " 15 . 0000 CUR " ) , liquid_balance ) ; <nl> + <nl> + } FC_LOG_AND_RETHROW ( ) } / / / schedule_test <nl> + <nl> BOOST_AUTO_TEST_SUITE_END ( ) <nl> mmm a / tests / wasm_tests / currency_tests . cpp <nl> ppp b / tests / wasm_tests / currency_tests . cpp <nl> BOOST_FIXTURE_TEST_CASE ( test_overspend , currency_tester ) try { <nl> ( " quantity " , " 101 . 0000 CUR " ) <nl> ( " memo " , " overspend ! Alice " ) ; <nl> <nl> - BOOST_CHECK_EXCEPTION ( push_action ( N ( alice ) , N ( transfer ) , data ) , fc : : assert_exception , assert_message_is ( " overdrawn balance " ) ) ; <nl> + BOOST_CHECK_EXCEPTION ( push_action ( N ( alice ) , N ( transfer ) , data ) , transaction_exception , assert_message_is ( " overdrawn balance " ) ) ; <nl> produce_block ( ) ; <nl> <nl> BOOST_REQUIRE_EQUAL ( get_balance ( N ( alice ) ) , asset : : from_string ( " 100 . 0000 CUR " ) ) ; <nl> mmm a / tests / wasm_tests / wasm_tests . cpp <nl> ppp b / tests / wasm_tests / wasm_tests . cpp <nl> BOOST_FIXTURE_TEST_CASE ( basic_test , tester ) try { <nl> trx . sign ( get_private_key ( N ( asserter ) , " active " ) , chain_id_type ( ) ) ; <nl> yes_assert_id = trx . id ( ) ; <nl> <nl> - BOOST_CHECK_THROW ( push_transaction ( trx ) , fc : : assert_exception ) ; <nl> + BOOST_CHECK_THROW ( push_transaction ( trx ) , transaction_exception ) ; <nl> } <nl> <nl> produce_blocks ( 1 ) ; <nl> BOOST_FIXTURE_TEST_CASE ( check_table_maximum , tester ) try { <nl> trx . sign ( get_private_key ( N ( tbl ) , " active " ) , chain_id_type ( ) ) ; <nl> <nl> / / should fail , a check to make sure assert ( ) in wasm is being evaluated correctly <nl> - BOOST_CHECK_THROW ( push_transaction ( trx ) , fc : : assert_exception ) ; <nl> + BOOST_CHECK_THROW ( push_transaction ( trx ) , transaction_exception ) ; <nl> } <nl> <nl> produce_blocks ( 1 ) ; <nl>
|
resolve conflicts ,
|
EOSIO/eos
|
4b8851a4855ae0b539fae5af50f1c6256c2b9e4f
|
2018-03-29T01:45:51Z
|
mmm a / tools / bindings - generator <nl> ppp b / tools / bindings - generator <nl> @ @ - 1 + 1 @ @ <nl> - Subproject commit 25a152fbc798464b85359010bbc666aed5bbc918 <nl> + Subproject commit f2e408f1ce29df573b0ed6bbcc83cf9fd7a795d5 <nl>
|
Update ` bindings - generator ` submodule
|
cocos2d/cocos2d-x
|
a30ce6cfc5681126c56b4d51bbe55856a585ec22
|
2014-03-13T06:47:00Z
|
mmm a / dbms / src / Functions / FunctionsHashing . h <nl> ppp b / dbms / src / Functions / FunctionsHashing . h <nl> class FunctionAnyHash : public IFunction <nl> for ( size_t i = 0 ; i < size ; + + i ) <nl> { <nl> String hex_string = vec_from [ i ] . toHexString ( ) ; <nl> - const ToType h = Impl : : apply ( reinterpret_cast < const char * > ( & hex_string ) , 8 ) ; <nl> + std : : cerr < < " \ n \ n " < < hex_string < < " \ n \ n " ; <nl> + const ToType h = Impl : : apply ( reinterpret_cast < const char * > ( & hex_string ) , 16 ) ; <nl> if ( first ) <nl> vec_to [ i ] = h ; <nl> else <nl> class FunctionAnyHash : public IFunction <nl> size_t size = vec_from . size ( ) ; <nl> for ( size_t i = 0 ; i < size ; + + i ) <nl> { <nl> + const char * to = reinterpret_cast < const char * > ( & vec_from [ i ] ) ; <nl> + std : : cerr < < " \ n \ n " < < to < < " \ n \ n " ; <nl> const ToType h = Impl : : apply ( reinterpret_cast < const char * > ( & vec_from [ i ] ) , 16 ) ; <nl> if ( first ) <nl> vec_to [ i ] = h ; <nl>
|
working commit
|
ClickHouse/ClickHouse
|
7ed84fd46460d0d62cec4a289499def9c4d76679
|
2019-11-12T16:56:18Z
|
mmm a / README . md <nl> ppp b / README . md <nl> Under Windows , we build some tools using the windows / dirent_portable . h file ( whi <nl> const char * filename = . . . / / <nl> <nl> / / use whatever means you want to get a string of your JSON document <nl> - std : : string_view p = get_corpus ( filename ) ; <nl> + std : : string_view p = get_corpus ( filename ) ; / / you are responsible for freeing p . data ( ) <nl> ParsedJson pj ; <nl> pj . allocateCapacity ( p . size ( ) ) ; / / allocate memory for parsing up to p . size ( ) bytes <nl> const int res = json_parse ( p , pj ) ; / / do the parsing , return 0 on success <nl> if ( res ! = 0 ) { <nl> std : : cout < < " Error parsing : " < < simdjson : : errorMsg ( res ) < < std : : endl ; <nl> } <nl> / / You can safely delete the string content <nl> - free ( ( void * ) p . data ( ) ) ; <nl> + aligned_free ( ( void * ) p . data ( ) ) ; <nl> / / the ParsedJson document can be used here <nl> / / js can be reused with other json_parse calls . <nl> ` ` ` <nl> ParsedJson pj = build_parsed_json ( p ) ; / / do the parsing <nl> if ( ! pj . isValid ( ) ) { <nl> / / something went wrong <nl> } <nl> + aligned_free ( ( void * ) p . data ( ) ) ; <nl> ` ` ` <nl> <nl> # # Usage : easy single - header version <nl> int main ( int argc , char * argv [ ] ) { <nl> } else { <nl> std : : cout < < " valid " < < std : : endl ; <nl> } <nl> + aligned_free ( ( void * ) p . data ( ) ) ; <nl> return EXIT_SUCCESS ; <nl> } <nl> ` ` ` <nl>
|
Being explicit about aligned_free
|
simdjson/simdjson
|
40a5d5ddfa2ce7e37415ceed3e02d8b2f73bfd80
|
2019-03-15T16:11:50Z
|
mmm a / scene / main / timer . cpp <nl> ppp b / scene / main / timer . cpp <nl> void Timer : : _bind_methods ( ) { <nl> ADD_SIGNAL ( MethodInfo ( " timeout " ) ) ; <nl> <nl> ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " process_mode " , PROPERTY_HINT_ENUM , " Physics , Idle " ) , " set_timer_process_mode " , " get_timer_process_mode " ) ; <nl> - ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " wait_time " , PROPERTY_HINT_EXP_RANGE , " 0 . 01 , 4096 , 0 . 01 " ) , " set_wait_time " , " get_wait_time " ) ; <nl> + ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " wait_time " , PROPERTY_HINT_EXP_RANGE , " 0 . 001 , 4096 , 0 . 001 , or_greater " ) , " set_wait_time " , " get_wait_time " ) ; <nl> ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " one_shot " ) , " set_one_shot " , " is_one_shot " ) ; <nl> ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " autostart " ) , " set_autostart " , " has_autostart " ) ; <nl> ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " paused " , PROPERTY_HINT_NONE , " " , 0 ) , " set_paused " , " is_paused " ) ; <nl>
|
Improve the Timer wait time property hint
|
godotengine/godot
|
f1052aa893c7e4a050f13f2068b4a85907afa122
|
2019-12-28T21:36:59Z
|
mmm a / cyber / tools / cyber_node / cyber_node <nl> ppp b / cyber / tools / cyber_node / cyber_node <nl> def print_node_info ( node_name , sleep_s = 2 ) : <nl> except : <nl> print ( " RoleAttributes ParseFromString failed . size is " , len ( roleattr_rawdata ) ) <nl> return <nl> - print ( " nodename \ t " , msg . node_name ) <nl> - print ( " processid \ t " , msg . process_id ) <nl> - print ( " hostname \ t " , msg . host_name ) <nl> + print ( " nodename \ t % s " % msg . node_name ) <nl> + print ( " processid \ t % d " % msg . process_id ) <nl> + print ( " hostname \ t % s " % msg . host_name ) <nl> <nl> print ( " [ Reading Channels ] : " ) <nl> reader_channels = sorted ( cyber . NodeUtils . get_readersofnode ( node_name , 0 ) ) <nl>
|
Cyber : fix cyber_node output format issue
|
ApolloAuto/apollo
|
f3a90a3735a5f71fd8f493e5868b5004dc0224f0
|
2020-02-25T02:49:49Z
|
mmm a / tools / optimizer / optimizer . cpp <nl> ppp b / tools / optimizer / optimizer . cpp <nl> StringSet USEFUL_BINARY_OPS ( " < < > > | & ^ " ) , <nl> StringSet ASSOCIATIVE_BINARIES ( " + * | & ^ " ) , <nl> CONTROL_FLOW ( " do while for if switch " ) , <nl> LOOP ( " do while for " ) , <nl> - NAME_OR_NUM ( " name num " ) ; <nl> + NAME_OR_NUM ( " name num " ) , <nl> + CONDITION_CHECKERS ( " if do while switch " ) , <nl> + SAFE_TO_DROP_COERCION ( " unary - prefix name num " ) ; <nl> + <nl> <nl> bool isFunctionTable ( const char * name ) { <nl> static const char * functionTable = " FUNCTION_TABLE " ; <nl> bool isFunctionTable ( Ref value ) { <nl> return value - > isString ( ) & & isFunctionTable ( value - > getCString ( ) ) ; <nl> } <nl> <nl> + / / Internal utilities <nl> + <nl> + bool canDropCoercion ( Ref node ) { <nl> + if ( SAFE_TO_DROP_COERCION . has ( node [ 0 ] ) ) return true ; <nl> + if ( node [ 0 ] = = BINARY ) { <nl> + switch ( node [ 1 ] - > getCString ( ) [ 0 ] ) { <nl> + case ' > ' : return node [ 1 ] = = RSHIFT | | node [ 1 ] = = TRSHIFT ; <nl> + case ' < ' : return node [ 1 ] = = LSHIFT ; <nl> + case ' | ' : case ' ^ ' : case ' & ' : return true ; <nl> + } <nl> + } <nl> + return false ; <nl> + } <nl> + <nl> + Ref simplifyCondition ( Ref node ) { <nl> + node = simplifyNotCompsDirect ( node ) ; <nl> + / / on integers , if ( x = = 0 ) is the same as if ( x ) , and if ( x ! = 0 ) as if ( ! x ) <nl> + if ( node [ 0 ] = = BINARY & & ( node [ 1 ] = = EQ | | node [ 1 ] = = NE ) ) { <nl> + Ref target ; <nl> + if ( detectType ( node [ 2 ] ) = = ASM_INT & & node [ 3 ] [ 0 ] = = NUM & & node [ 3 ] [ 1 ] - > getNumber ( ) = = 0 ) { <nl> + target = node [ 2 ] ; <nl> + } else if ( detectType ( node [ 3 ] ) = = ASM_INT & & node [ 2 ] [ 0 ] = = NUM & & node [ 2 ] [ 1 ] - > getNumber ( ) = = 0 ) { <nl> + target = node [ 3 ] ; <nl> + } <nl> + if ( ! ! target ) { <nl> + if ( target [ 0 ] = = BINARY & & ( target [ 1 ] = = OR | | target [ 1 ] = = TRSHIFT ) & & target [ 3 ] [ 0 ] = = NUM & & target [ 3 ] [ 1 ] - > getNumber ( ) = = 0 & & <nl> + canDropCoercion ( target [ 2 ] ) ) { <nl> + target = target [ 2 ] ; / / drop the coercion , in a condition it is ok to do if ( x ) <nl> + } <nl> + if ( node [ 1 ] = = EQ ) { <nl> + return make2 ( UNARY_PREFIX , L_NOT , target ) ; <nl> + } else { <nl> + return target ; <nl> + } <nl> + } <nl> + } <nl> + return node ; <nl> + } <nl> + <nl> / / Passes <nl> <nl> / / Eliminator aka Expressionizer <nl> void minifyLocals ( Ref ast ) { <nl> } ) ; <nl> } <nl> <nl> + void asmLastOpts ( Ref ast ) { <nl> + std : : vector < Ref > statsStack ; <nl> + traverseFunctions ( ast , [ & ] ( Ref fun ) { <nl> + traversePrePost ( fun , [ & ] ( Ref node ) { <nl> + Ref type = node [ 0 ] ; <nl> + Ref stats = getStatements ( node ) ; <nl> + if ( ! ! stats ) statsStack . push_back ( stats ) ; <nl> + if ( CONDITION_CHECKERS . has ( type ) ) { <nl> + node [ 1 ] = simplifyCondition ( node [ 1 ] ) ; <nl> + } <nl> + if ( type = = WHILE & & node [ 1 ] [ 0 ] = = NUM & & node [ 1 ] [ 1 ] - > getNumber ( ) = = 1 & & node [ 2 ] [ 0 ] = = BLOCK & & node [ 2 ] - > size ( ) = = 2 ) { <nl> + / / This is at the end of the pipeline , we can assume all other optimizations are done , and we modify loops <nl> + / / into shapes that might confuse other passes <nl> + <nl> + / / while ( 1 ) { . . if ( . . ) { break } } = = > do { . . } while ( . . ) <nl> + Ref stats = node [ 2 ] [ 1 ] ; <nl> + Ref last = stats - > back ( ) ; <nl> + if ( ! ! last & & last [ 0 ] = = IF & & ! last [ 3 ] & & last [ 2 ] [ 0 ] = = BLOCK & & ! ! last [ 2 ] [ 1 ] [ 0 ] ) { <nl> + Ref lastStats = last [ 2 ] [ 1 ] ; <nl> + int lastNum = lastStats - > size ( ) ; <nl> + Ref lastLast = lastStats [ lastNum - 1 ] ; <nl> + if ( ! ( lastLast [ 0 ] = = BREAK & & ! lastLast [ 1 ] ) ) return ; / / if not a simple break , dangerous <nl> + for ( int i = 0 ; i < lastNum ; i + + ) { <nl> + if ( lastStats [ i ] [ 0 ] ! = STAT & & lastStats [ i ] [ 0 ] ! = BREAK ) return ; / / something dangerous <nl> + } <nl> + / / ok , a bunch of statements ending in a break <nl> + bool abort = false ; <nl> + int stack = 0 ; <nl> + int breaks = 0 ; <nl> + traversePrePost ( stats , [ & ] ( Ref node ) { <nl> + Ref type = node [ 0 ] ; <nl> + if ( type = = CONTINUE ) { <nl> + if ( stack = = 0 | | ! ! node [ 1 ] ) { / / abort if labeled ( we do not analyze labels here yet ) , or a continue directly on us <nl> + abort = true ; <nl> + } <nl> + } else if ( type = = BREAK ) { <nl> + if ( stack = = 0 | | ! ! node [ 1 ] ) { / / relevant if labeled ( we do not analyze labels here yet ) , or a break directly on us <nl> + breaks + + ; <nl> + } <nl> + } else if ( LOOP . has ( type ) ) { <nl> + stack + + ; <nl> + } <nl> + } , [ & ] ( Ref node ) { <nl> + if ( LOOP . has ( node [ 0 ] ) ) { <nl> + stack - - ; <nl> + } <nl> + } ) ; <nl> + if ( abort ) return ; <nl> + assert ( breaks > 0 ) ; <nl> + if ( lastStats - > size ( ) > 1 & & breaks ! = 1 ) return ; / / if we have code aside from the break , we can only move it out if there is just one break <nl> + / / start to optimize <nl> + if ( lastStats - > size ( ) > 1 ) { <nl> + Ref parent = statsStack . back ( ) ; <nl> + int me = parent - > indexOf ( node ) ; <nl> + if ( me < 0 ) return ; / / not always directly on a stats , could be in a label for example <nl> + parent - > insert ( me + 1 , lastStats - > size ( ) - 1 ) ; <nl> + for ( int i = 0 ; i < lastStats - > size ( ) - 1 ; i + + ) { <nl> + parent [ me + 1 + i ] = lastStats [ i ] ; <nl> + } <nl> + } <nl> + Ref conditionToBreak = last [ 1 ] ; <nl> + stats - > pop_back ( ) ; <nl> + node [ 0 ] - > setString ( DO ) ; <nl> + node [ 1 ] = simplifyNotCompsDirect ( make2 ( UNARY_PREFIX , L_NOT , conditionToBreak ) ) ; <nl> + } <nl> + } else if ( type = = BINARY ) { <nl> + if ( node [ 1 ] = = AND ) { <nl> + if ( node [ 3 ] [ 0 ] = = UNARY_PREFIX & & node [ 3 ] [ 1 ] = = MINUS & & node [ 3 ] [ 2 ] [ 0 ] = = NUM & & node [ 3 ] [ 2 ] [ 1 ] - > getNumber ( ) = = 1 ) { <nl> + / / Change & - 1 into | 0 , at this point the hint is no longer needed <nl> + node [ 1 ] - > setString ( OR ) ; <nl> + node [ 3 ] = node [ 3 ] [ 2 ] ; <nl> + node [ 3 ] [ 1 ] = 0 ; <nl> + } <nl> + } else if ( node [ 1 ] = = MINUS & & node [ 3 ] [ 0 ] = = UNARY_PREFIX ) { <nl> + / / avoid X - ( - Y ) because some minifiers buggily emit X - - Y which is invalid as - - can be a unary . Transform to <nl> + / / X + Y <nl> + if ( node [ 3 ] [ 1 ] = = MINUS ) { / / integer <nl> + node [ 1 ] - > setString ( PLUS ) ; <nl> + node [ 3 ] = node [ 3 ] [ 2 ] ; <nl> + } else if ( node [ 3 ] [ 1 ] = = PLUS ) { / / float <nl> + if ( node [ 3 ] [ 2 ] [ 0 ] = = UNARY_PREFIX & & node [ 3 ] [ 2 ] [ 1 ] = = MINUS ) { <nl> + node [ 1 ] - > setString ( PLUS ) ; <nl> + node [ 3 ] [ 2 ] = node [ 3 ] [ 2 ] [ 2 ] ; <nl> + } <nl> + } <nl> + } <nl> + } <nl> + } , [ & ] ( Ref node ) { <nl> + Ref stats = getStatements ( node ) ; <nl> + if ( ! ! stats ) statsStack . pop_back ( ) ; <nl> + } ) ; <nl> + / / convert { singleton } into singleton <nl> + traversePre ( fun , [ ] ( Ref node ) { <nl> + if ( node [ 0 ] = = BLOCK & & ! ! node [ 1 ] & & node [ 1 ] - > size ( ) = = 1 ) { <nl> + safeCopy ( node , node [ 1 ] [ 0 ] ) ; <nl> + } <nl> + } ) ; <nl> + } ) ; <nl> + } <nl> + <nl> / / = = = = = = = = = = = = = = = = = = <nl> / / Main <nl> / / = = = = = = = = = = = = = = = = = = <nl> int main ( int argc , char * * argv ) { <nl> else if ( str = = " registerize " ) registerize ( doc ) ; <nl> else if ( str = = " minifyLocals " ) minifyLocals ( doc ) ; <nl> else if ( str = = " minifyWhitespace " ) { } <nl> + else if ( str = = " asmLastOpts " ) asmLastOpts ( doc ) ; <nl> else { <nl> fprintf ( stderr , " unrecognized argument : % s \ n " , str . c_str ( ) ) ; <nl> assert ( 0 ) ; <nl>
|
convert asmLastOpts to native optimizer
|
emscripten-core/emscripten
|
dae2a92aa86c0ad66c70f33621ef7a4ef41cbb44
|
2014-11-30T20:08:33Z
|
mmm a / unittests / forked_tests . cpp <nl> ppp b / unittests / forked_tests . cpp <nl> BOOST_AUTO_TEST_CASE ( fork_with_bad_block ) try { <nl> BOOST_REQUIRE ( produce_empty_blocks_until ( bios , N ( e ) , N ( a ) ) ) ; <nl> <nl> / / sync remote node <nl> - tester remote ; <nl> + tester remote ( setup_policy : : none ) ; <nl> push_blocks ( bios , remote ) ; <nl> <nl> / / produce 6 blocks on bios <nl> BOOST_AUTO_TEST_CASE ( forking ) try { <nl> ) ; <nl> <nl> <nl> - tester c2 ; <nl> + tester c2 ( setup_policy : : none ) ; <nl> wlog ( " push c1 blocks to c2 " ) ; <nl> push_blocks ( c , c2 ) ; <nl> wlog ( " end push c1 blocks to c2 " ) ; <nl> BOOST_AUTO_TEST_CASE ( prune_remove_branch ) try { <nl> wlog ( " set producer schedule to [ dan , sam , pam , scott ] " ) ; <nl> c . produce_blocks ( 50 ) ; <nl> <nl> - tester c2 ; <nl> + tester c2 ( setup_policy : : none ) ; <nl> wlog ( " push c1 blocks to c2 " ) ; <nl> push_blocks ( c , c2 ) ; <nl> <nl> BOOST_AUTO_TEST_CASE ( prune_remove_branch ) try { <nl> * / <nl> BOOST_AUTO_TEST_CASE ( validator_accepts_valid_blocks ) try { <nl> <nl> - tester n1 ; <nl> - tester n2 ; <nl> - tester n3 ; <nl> + tester n1 ( setup_policy : : none ) ; <nl> + tester n2 ( setup_policy : : none ) ; <nl> + tester n3 ( setup_policy : : none ) ; <nl> <nl> n1 . produce_block ( ) ; <nl> <nl> BOOST_AUTO_TEST_CASE ( read_modes ) try { <nl> auto head_block_num = c . control - > head_block_num ( ) ; <nl> auto last_irreversible_block_num = c . control - > last_irreversible_block_num ( ) ; <nl> <nl> - tester head ( setup_policy : : old_bios_only , db_read_mode : : HEAD ) ; <nl> + tester head ( setup_policy : : none , db_read_mode : : HEAD ) ; <nl> push_blocks ( c , head ) ; <nl> BOOST_CHECK_EQUAL ( head_block_num , head . control - > fork_db_head_block_num ( ) ) ; <nl> BOOST_CHECK_EQUAL ( head_block_num , head . control - > head_block_num ( ) ) ; <nl> BOOST_AUTO_TEST_CASE ( read_modes ) try { <nl> BOOST_CHECK_EQUAL ( head_block_num , read_only . control - > fork_db_head_block_num ( ) ) ; <nl> BOOST_CHECK_EQUAL ( head_block_num , read_only . control - > head_block_num ( ) ) ; <nl> <nl> - tester irreversible ( setup_policy : : old_bios_only , db_read_mode : : IRREVERSIBLE ) ; <nl> + tester irreversible ( setup_policy : : none , db_read_mode : : IRREVERSIBLE ) ; <nl> push_blocks ( c , irreversible ) ; <nl> BOOST_CHECK_EQUAL ( head_block_num , irreversible . control - > fork_db_pending_head_block_num ( ) ) ; <nl> BOOST_CHECK_EQUAL ( last_irreversible_block_num , irreversible . control - > fork_db_head_block_num ( ) ) ; <nl> BOOST_AUTO_TEST_CASE ( irreversible_mode ) try { <nl> <nl> BOOST_REQUIRE ( lib2 < hbn1 ) ; <nl> <nl> - tester other ; <nl> + tester other ( setup_policy : : none ) ; <nl> <nl> push_blocks ( main , other ) ; <nl> BOOST_CHECK_EQUAL ( other . control - > head_block_num ( ) , hbn2 ) ; <nl> BOOST_AUTO_TEST_CASE ( reopen_forkdb ) try { <nl> c1 . produce_block ( ) ; <nl> produce_empty_blocks_until ( c1 , N ( carol ) , N ( alice ) ) ; <nl> <nl> - tester c2 ; <nl> + tester c2 ( setup_policy : : none ) ; <nl> <nl> push_blocks ( c1 , c2 ) ; <nl> <nl> BOOST_AUTO_TEST_CASE ( push_block_returns_forked_transactions ) try { <nl> wlog ( " set producer schedule to [ dan , sam , pam ] " ) ; <nl> c . produce_blocks ( 40 ) ; <nl> <nl> - tester c2 ; <nl> + tester c2 ( setup_policy : : none ) ; <nl> wlog ( " push c1 blocks to c2 " ) ; <nl> push_blocks ( c , c2 ) ; <nl> <nl>
|
Forked tests had been instantiating peers with the expectation that they would sync into a blockchain , however they had actually been deterministically re - creating the preamble of those chains . Recent changes to the set - up policy violated the implicit expectation by leaving unapplied_transactions around after syncing . These transactions were expired and throwing asserts
|
EOSIO/eos
|
e80e4093a93950dc2d6eff734839f3b289eebf88
|
2019-07-23T14:36:28Z
|
mmm a / Marlin / src / HAL / shared / eeprom_i2c . cpp <nl> ppp b / Marlin / src / HAL / shared / eeprom_i2c . cpp <nl> <nl> / / Private Variables <nl> / / mmmmmmmmmmmmmmmmmmmmmmmm <nl> <nl> - static uint8_t eeprom_device_address = 0x50 ; <nl> + static constexpr uint8_t eeprom_device_address = I2C_ADDRESS ( 0x50 ) ; <nl> <nl> / / mmmmmmmmmmmmmmmmmmmmmmmm <nl> / / Public functions <nl> void eeprom_write_byte ( uint8_t * pos , unsigned char value ) { <nl> <nl> eeprom_init ( ) ; <nl> <nl> - Wire . beginTransmission ( I2C_ADDRESS ( eeprom_device_address ) ) ; <nl> + Wire . beginTransmission ( eeprom_device_address ) ; <nl> Wire . write ( ( int ) ( eeprom_address > > 8 ) ) ; / / MSB <nl> Wire . write ( ( int ) ( eeprom_address & 0xFF ) ) ; / / LSB <nl> Wire . write ( value ) ; <nl> void eeprom_write_byte ( uint8_t * pos , unsigned char value ) { <nl> void eeprom_update_block ( const void * pos , void * eeprom_address , size_t n ) { <nl> eeprom_init ( ) ; <nl> <nl> - Wire . beginTransmission ( I2C_ADDRESS ( eeprom_device_address ) ) ; <nl> + Wire . beginTransmission ( eeprom_device_address ) ; <nl> Wire . write ( ( int ) ( ( unsigned ) eeprom_address > > 8 ) ) ; / / MSB <nl> Wire . write ( ( int ) ( ( unsigned ) eeprom_address & 0xFF ) ) ; / / LSB <nl> Wire . endTransmission ( ) ; <nl> void eeprom_update_block ( const void * pos , void * eeprom_address , size_t n ) { <nl> flag | = Wire . read ( ) ^ ptr [ c ] ; <nl> <nl> if ( flag ) { <nl> - Wire . beginTransmission ( I2C_ADDRESS ( eeprom_device_address ) ) ; <nl> + Wire . beginTransmission ( eeprom_device_address ) ; <nl> Wire . write ( ( int ) ( ( unsigned ) eeprom_address > > 8 ) ) ; / / MSB <nl> Wire . write ( ( int ) ( ( unsigned ) eeprom_address & 0xFF ) ) ; / / LSB <nl> Wire . write ( ( uint8_t * ) pos , n ) ; <nl> uint8_t eeprom_read_byte ( uint8_t * pos ) { <nl> <nl> eeprom_init ( ) ; <nl> <nl> - Wire . beginTransmission ( I2C_ADDRESS ( eeprom_device_address ) ) ; <nl> + Wire . beginTransmission ( eeprom_device_address ) ; <nl> Wire . write ( ( int ) ( eeprom_address > > 8 ) ) ; / / MSB <nl> Wire . write ( ( int ) ( eeprom_address & 0xFF ) ) ; / / LSB <nl> Wire . endTransmission ( ) ; <nl> uint8_t eeprom_read_byte ( uint8_t * pos ) { <nl> void eeprom_read_block ( void * pos , const void * eeprom_address , size_t n ) { <nl> eeprom_init ( ) ; <nl> <nl> - Wire . beginTransmission ( I2C_ADDRESS ( eeprom_device_address ) ) ; <nl> + Wire . beginTransmission ( eeprom_device_address ) ; <nl> Wire . write ( ( int ) ( ( unsigned ) eeprom_address > > 8 ) ) ; / / MSB <nl> Wire . write ( ( int ) ( ( unsigned ) eeprom_address & 0xFF ) ) ; / / LSB <nl> Wire . endTransmission ( ) ; <nl> mmm a / Marlin / src / core / macros . h <nl> ppp b / Marlin / src / core / macros . h <nl> <nl> # define FMOD ( x , y ) fmodf ( x , y ) <nl> # define HYPOT ( x , y ) SQRT ( HYPOT2 ( x , y ) ) <nl> <nl> - # ifdef TARGET_LPC1768 <nl> - # define I2C_ADDRESS ( A ) ( ( A ) < < 1 ) <nl> - # else <nl> - # define I2C_ADDRESS ( A ) A <nl> - # endif <nl> + # define I2C_ADDRESS ( A ) ( TERN ( TARGET_LPC1768 , ( A ) < < 1 , A ) ) <nl> <nl> / / Use NUM_ARGS ( __VA_ARGS__ ) to get the number of variadic arguments <nl> # define _NUM_ARGS ( _ , Z , Y , X , W , V , U , T , S , R , Q , P , O , N , M , L , K , J , I , H , G , F , E , D , C , B , A , OUT , . . . ) OUT <nl> mmm a / Marlin / src / feature / encoder_i2c . cpp <nl> ppp b / Marlin / src / feature / encoder_i2c . cpp <nl> int32_t I2CPositionEncoder : : get_raw_count ( ) { <nl> <nl> encoderCount . val = 0x00 ; <nl> <nl> - if ( Wire . requestFrom ( ( int ) i2cAddress , 3 ) ! = 3 ) { <nl> + if ( Wire . requestFrom ( I2C_ADDRESS ( i2cAddress ) , 3 ) ! = 3 ) { <nl> / / houston , we have a problem . . . <nl> H = I2CPE_MAG_SIG_NF ; <nl> return 0 ; <nl> void I2CPositionEncodersMgr : : report_module_firmware ( const uint8_t address ) { <nl> Wire . endTransmission ( ) ; <nl> <nl> / / Read value <nl> - if ( Wire . requestFrom ( ( int ) address , 32 ) ) { <nl> + if ( Wire . requestFrom ( I2C_ADDRESS ( address ) , 32 ) ) { <nl> char c ; <nl> while ( Wire . available ( ) > 0 & & ( c = ( char ) Wire . read ( ) ) > 0 ) <nl> SERIAL_ECHO ( c ) ; <nl> mmm a / Marlin / src / feature / twibus . cpp <nl> ppp b / Marlin / src / feature / twibus . cpp <nl> bool TWIBus : : request ( const uint8_t bytes ) { <nl> debug ( PSTR ( " request " ) , bytes ) ; <nl> <nl> / / requestFrom ( ) is a blocking function <nl> - if ( Wire . requestFrom ( addr , bytes ) = = 0 ) { <nl> - debug ( " request fail " , addr ) ; <nl> + if ( Wire . requestFrom ( I2C_ADDRESS ( addr ) , bytes ) = = 0 ) { <nl> + debug ( " request fail " , I2C_ADDRESS ( addr ) ) ; <nl> return false ; <nl> } <nl> <nl>
|
Fix M261 , i2c EEPROM , i2c Encoder for LPC ( )
|
MarlinFirmware/Marlin
|
b700b3cde6102cff68f25555bffe5f112e2111e4
|
2020-04-25T16:35:35Z
|
mmm a / src / core / ext / filters / client_channel / xds / xds_api . cc <nl> ppp b / src / core / ext / filters / client_channel / xds / xds_api . cc <nl> grpc_error * RouteConfigParse ( <nl> " No prefix field found in RouteMatch . " ) ; <nl> } <nl> const upb_strview prefix = envoy_api_v2_route_RouteMatch_prefix ( match ) ; <nl> - if ( ! upb_strview_eql ( prefix , upb_strview_makez ( " " ) ) ) { <nl> - return GRPC_ERROR_CREATE_FROM_STATIC_STRING ( " Prefix is not empty string . " ) ; <nl> + if ( ! upb_strview_eql ( prefix , upb_strview_makez ( " " ) ) & & <nl> + ! upb_strview_eql ( prefix , upb_strview_makez ( " / " ) ) ) { <nl> + return GRPC_ERROR_CREATE_FROM_STATIC_STRING ( " Prefix is not \ " \ " or \ " / \ " . " ) ; <nl> } <nl> if ( ! envoy_api_v2_route_Route_has_route ( route ) ) { <nl> return GRPC_ERROR_CREATE_FROM_STATIC_STRING ( <nl> mmm a / test / cpp / end2end / xds_end2end_test . cc <nl> ppp b / test / cpp / end2end / xds_end2end_test . cc <nl> TEST_P ( XdsResolverOnlyTest , RestartsRequestsUponReconnection ) { <nl> EXPECT_EQ ( 0 , std : : get < 1 > ( counts ) ) ; <nl> } <nl> <nl> + TEST_P ( XdsResolverOnlyTest , DefaultRouteSpecifiesSlashPrefix ) { <nl> + RouteConfiguration route_config = <nl> + balancers_ [ 0 ] - > ads_service ( ) - > default_route_config ( ) ; <nl> + route_config . mutable_virtual_hosts ( 0 ) <nl> + - > mutable_routes ( 0 ) <nl> + - > mutable_match ( ) <nl> + - > set_prefix ( " / " ) ; <nl> + balancers_ [ 0 ] - > ads_service ( ) - > SetLdsResource ( <nl> + AdsServiceImpl : : BuildListener ( route_config ) , kDefaultResourceName ) ; <nl> + SetNextResolution ( { } ) ; <nl> + SetNextResolutionForLbChannelAllBalancers ( ) ; <nl> + AdsServiceImpl : : EdsResourceArgs args ( { <nl> + { " locality0 " , GetBackendPorts ( ) } , <nl> + } ) ; <nl> + balancers_ [ 0 ] - > ads_service ( ) - > SetEdsResource ( <nl> + AdsServiceImpl : : BuildEdsResource ( args ) , kDefaultResourceName ) ; <nl> + / / We need to wait for all backends to come online . <nl> + WaitForAllBackends ( ) ; <nl> + } <nl> + <nl> class XdsResolverLoadReportingOnlyTest : public XdsEnd2endTest { <nl> public : <nl> XdsResolverLoadReportingOnlyTest ( ) : XdsEnd2endTest ( 4 , 1 , 3 ) { } <nl>
|
Accept either " " or " / " as the prefix for the default route .
|
grpc/grpc
|
bf6e534714b21468ba6539f3db87d9fccf734fe6
|
2020-04-15T16:24:55Z
|
mmm a / src / bitcoin - cli . cpp <nl> ppp b / src / bitcoin - cli . cpp <nl> class GetinfoRequestHandler : public BaseRequestHandler <nl> } <nl> result . pushKV ( " version " , batch [ ID_NETWORKINFO ] [ " result " ] [ " version " ] ) ; <nl> result . pushKV ( " protocolversion " , batch [ ID_NETWORKINFO ] [ " result " ] [ " protocolversion " ] ) ; <nl> - if ( ! batch [ ID_WALLETINFO ] . isNull ( ) ) { <nl> - result . pushKV ( " walletversion " , batch [ ID_WALLETINFO ] [ " result " ] [ " walletversion " ] ) ; <nl> - result . pushKV ( " balance " , batch [ ID_WALLETINFO ] [ " result " ] [ " balance " ] ) ; <nl> - } <nl> result . pushKV ( " blocks " , batch [ ID_BLOCKCHAININFO ] [ " result " ] [ " blocks " ] ) ; <nl> result . pushKV ( " timeoffset " , batch [ ID_NETWORKINFO ] [ " result " ] [ " timeoffset " ] ) ; <nl> result . pushKV ( " connections " , batch [ ID_NETWORKINFO ] [ " result " ] [ " connections " ] ) ; <nl> mmm a / test / functional / interface_bitcoin_cli . py <nl> ppp b / test / functional / interface_bitcoin_cli . py <nl> def run_test ( self ) : <nl> <nl> assert_equal ( cli_get_info [ ' version ' ] , network_info [ ' version ' ] ) <nl> assert_equal ( cli_get_info [ ' protocolversion ' ] , network_info [ ' protocolversion ' ] ) <nl> - if self . is_wallet_compiled ( ) : <nl> - assert_equal ( cli_get_info [ ' walletversion ' ] , wallet_info [ ' walletversion ' ] ) <nl> - assert_equal ( cli_get_info [ ' balance ' ] , wallet_info [ ' balance ' ] ) <nl> assert_equal ( cli_get_info [ ' blocks ' ] , blockchain_info [ ' blocks ' ] ) <nl> assert_equal ( cli_get_info [ ' timeoffset ' ] , network_info [ ' timeoffset ' ] ) <nl> assert_equal ( cli_get_info [ ' connections ' ] , network_info [ ' connections ' ] ) <nl> def run_test ( self ) : <nl> assert_equal ( cli_get_info [ ' difficulty ' ] , blockchain_info [ ' difficulty ' ] ) <nl> assert_equal ( cli_get_info [ ' testnet ' ] , blockchain_info [ ' chain ' ] = = " test " ) <nl> if self . is_wallet_compiled ( ) : <nl> + assert_equal ( cli_get_info [ ' walletversion ' ] , wallet_info [ ' walletversion ' ] ) <nl> assert_equal ( cli_get_info [ ' balance ' ] , wallet_info [ ' balance ' ] ) <nl> assert_equal ( cli_get_info [ ' keypoololdest ' ] , wallet_info [ ' keypoololdest ' ] ) <nl> assert_equal ( cli_get_info [ ' keypoolsize ' ] , wallet_info [ ' keypoolsize ' ] ) <nl>
|
cli : remove duplicate wallet fields from - getinfo
|
bitcoin/bitcoin
|
3f6568d66b42bd151b26df3bd84c64959bbe3fc9
|
2019-03-09T08:40:46Z
|
mmm a / third - party / fbson / COMMIT . md <nl> ppp b / third - party / fbson / COMMIT . md <nl> @ @ - 1 + 1 , 2 @ @ <nl> - fbson commit : c8f16edf02243dce5a9dc48495f8f5a99f1c7895 <nl> + fbson commit : <nl> + https : / / github . com / facebook / mysql - 5 . 6 / commit / c8f16edf02243dce5a9dc48495f8f5a99f1c7895 <nl> mmm a / utilities / document / document_db . cc <nl> ppp b / utilities / document / document_db . cc <nl> class DocumentDBImpl : public DocumentDB { <nl> for ( const auto & update : updates . Items ( ) ) { <nl> if ( update . first = = " $ set " ) { <nl> JSONDocumentBuilder builder ; <nl> - bool res = builder . WriteStartObject ( ) ; <nl> + bool res __attribute__ ( ( unused ) ) = builder . WriteStartObject ( ) ; <nl> assert ( res ) ; <nl> for ( const auto & itr : update . second . Items ( ) ) { <nl> if ( itr . first = = kPrimaryKey ) { <nl> mmm a / utilities / document / json_document . cc <nl> ppp b / utilities / document / json_document . cc <nl> void InitJSONDocument ( std : : unique_ptr < char [ ] > * data , <nl> Func f ) { <nl> / / TODO ( stash ) : maybe add function to FbsonDocument to avoid creating array ? <nl> fbson : : FbsonWriter writer ; <nl> - bool res = writer . writeStartArray ( ) ; <nl> + bool res __attribute__ ( ( unused ) ) = writer . writeStartArray ( ) ; <nl> assert ( res ) ; <nl> uint32_t bytesWritten __attribute__ ( ( unused ) ) = f ( writer ) ; <nl> assert ( bytesWritten ! = 0 ) ; <nl> void InitString ( std : : unique_ptr < char [ ] > * data , <nl> const std : : string & s ) { <nl> InitJSONDocument ( data , value , std : : bind ( <nl> [ ] ( fbson : : FbsonWriter & writer , const std : : string & str ) - > uint32_t { <nl> - bool res = writer . writeStartString ( ) ; <nl> + bool res __attribute__ ( ( unused ) ) = writer . writeStartString ( ) ; <nl> assert ( res ) ; <nl> auto bytesWritten = writer . writeString ( str . c_str ( ) , <nl> static_cast < uint32_t > ( str . length ( ) ) ) ; <nl> bool IsComparable ( fbson : : FbsonValue * left , fbson : : FbsonValue * right ) { <nl> <nl> void CreateArray ( std : : unique_ptr < char [ ] > * data , fbson : : FbsonValue * * value ) { <nl> fbson : : FbsonWriter writer ; <nl> - bool res = writer . writeStartArray ( ) ; <nl> + bool res __attribute__ ( ( unused ) ) = writer . writeStartArray ( ) ; <nl> assert ( res ) ; <nl> res = writer . writeEndArray ( ) ; <nl> assert ( res ) ; <nl> void CreateArray ( std : : unique_ptr < char [ ] > * data , fbson : : FbsonValue * * value ) { <nl> <nl> void CreateObject ( std : : unique_ptr < char [ ] > * data , fbson : : FbsonValue * * value ) { <nl> fbson : : FbsonWriter writer ; <nl> - bool res = writer . writeStartObject ( ) ; <nl> + bool res __attribute__ ( ( unused ) ) = writer . writeStartObject ( ) ; <nl> assert ( res ) ; <nl> res = writer . writeEndObject ( ) ; <nl> assert ( res ) ; <nl> bool CompareSimpleTypes ( fbson : : FbsonValue * left , fbson : : FbsonValue * right ) { <nl> return memcmp ( left , right , left - > numPackedBytes ( ) ) = = 0 ; <nl> } <nl> <nl> - bool Compare ( fbson : : FbsonValue * left , fbson : : FbsonValue * right ) { <nl> + bool CompareFbsonValue ( fbson : : FbsonValue * left , fbson : : FbsonValue * right ) { <nl> if ( ! IsComparable ( left , right ) ) { <nl> return false ; <nl> } <nl> bool Compare ( fbson : : FbsonValue * left , fbson : : FbsonValue * right ) { <nl> if ( rightObject - > find ( str . c_str ( ) ) = = nullptr ) { <nl> return false ; <nl> } <nl> - if ( ! Compare ( keyValue . value ( ) , <nl> - rightObject - > find ( str . c_str ( ) ) ) ) { <nl> + if ( ! CompareFbsonValue ( keyValue . value ( ) , <nl> + rightObject - > find ( str . c_str ( ) ) ) ) { <nl> return false ; <nl> } <nl> } <nl> bool Compare ( fbson : : FbsonValue * left , fbson : : FbsonValue * right ) { <nl> return false ; <nl> } <nl> for ( int i = 0 ; i < static_cast < int > ( leftArr - > numElem ( ) ) ; + + i ) { <nl> - if ( ! Compare ( leftArr - > get ( i ) , rightArr - > get ( i ) ) ) { <nl> + if ( ! CompareFbsonValue ( leftArr - > get ( i ) , rightArr - > get ( i ) ) ) { <nl> return false ; <nl> } <nl> } <nl> bool Compare ( fbson : : FbsonValue * left , fbson : : FbsonValue * right ) { <nl> } / / namespace <nl> <nl> bool JSONDocument : : operator = = ( const JSONDocument & rhs ) const { <nl> - return Compare ( value_ , rhs . value_ ) ; <nl> + return CompareFbsonValue ( value_ , rhs . value_ ) ; <nl> } <nl> <nl> bool JSONDocument : : operator ! = ( const JSONDocument & rhs ) const { <nl>
|
Fix compile
|
facebook/rocksdb
|
a9f0e2b5b684edb6ed5518716009df57dcf873ca
|
2015-02-27T00:56:39Z
|
mmm a / swoole_redis_coro . cc <nl> ppp b / swoole_redis_coro . cc <nl> static void redis_request ( swRedisClient * redis , int argc , char * * argv , size_t * a <nl> { <nl> if ( redisAppendCommandArgv ( redis - > context , argc , ( const char * * ) argv , ( const size_t * ) argvlen ) = = REDIS_ERR ) <nl> { <nl> - _error : zend_update_property_long ( swoole_redis_coro_ce_ptr , redis - > object , ZEND_STRL ( " errCode " ) , redis - > context - > err ) ; <nl> + _error : <nl> + zend_update_property_long ( swoole_redis_coro_ce_ptr , redis - > object , ZEND_STRL ( " errCode " ) , redis - > context - > err ) ; <nl> zend_update_property_string ( swoole_redis_coro_ce_ptr , redis - > object , ZEND_STRL ( " errMsg " ) , redis - > context - > errstr ) ; <nl> ZVAL_FALSE ( return_value ) ; <nl> if ( redis - > context - > err = = REDIS_ERR_EOF ) <nl> static sw_inline void sw_redis_command_var_key ( INTERNAL_FUNCTION_PARAMETERS , con <nl> if ( argc < min_argc ) { <nl> RETURN_FALSE ; <nl> } <nl> + SW_REDIS_COMMAND_CHECK <nl> SW_REDIS_COMMAND_ALLOC_ARGS_ARR <nl> if ( argc = = 0 | | zend_get_parameters_array ( ht , argc , z_args ) = = FAILURE ) { <nl> efree ( z_args ) ; <nl> RETURN_FALSE ; <nl> } <nl> - SW_REDIS_COMMAND_CHECK <nl> zend_bool single_array = 0 ; <nl> if ( has_timeout = = 0 ) { <nl> single_array = argc = = 1 & & SW_REDIS_COMMAND_ARGS_TYPE ( z_args [ 0 ] ) = = IS_ARRAY ; <nl> static inline void sw_redis_command_key ( INTERNAL_FUNCTION_PARAMETERS , const char <nl> static sw_inline void sw_redis_command_key_var_val ( INTERNAL_FUNCTION_PARAMETERS , const char * cmd , int cmd_len ) <nl> { <nl> int argc = ZEND_NUM_ARGS ( ) ; <nl> - <nl> / / We at least need a key and one value <nl> if ( argc < 2 ) <nl> { <nl> RETURN_FALSE ; <nl> } <nl> - <nl> + SW_REDIS_COMMAND_CHECK <nl> / / Make sure we at least have a key , and we can get other args <nl> SW_REDIS_COMMAND_ALLOC_ARGS_ARR <nl> if ( zend_get_parameters_array ( ht , argc , z_args ) = = FAILURE ) <nl> static sw_inline void sw_redis_command_key_var_val ( INTERNAL_FUNCTION_PARAMETERS , <nl> RETURN_FALSE ; <nl> } <nl> <nl> - SW_REDIS_COMMAND_CHECK <nl> - <nl> int i = 0 , j ; <nl> argc + + ; <nl> SW_REDIS_COMMAND_ALLOC_ARGV <nl> static PHP_METHOD ( swoole_redis_coro , hSetNx ) <nl> static PHP_METHOD ( swoole_redis_coro , hDel ) <nl> { <nl> int argc = ZEND_NUM_ARGS ( ) ; <nl> + SW_REDIS_COMMAND_CHECK <nl> SW_REDIS_COMMAND_ALLOC_ARGS_ARR <nl> if ( argc < 2 | | zend_get_parameters_array ( ht , argc , z_args ) = = FAILURE ) { <nl> efree ( z_args ) ; <nl> RETURN_FALSE ; <nl> } <nl> - SW_REDIS_COMMAND_CHECK <nl> argc + + ; <nl> int i = 0 , j ; <nl> SW_REDIS_COMMAND_ALLOC_ARGV <nl> static PHP_METHOD ( swoole_redis_coro , bRPopLPush ) <nl> static PHP_METHOD ( swoole_redis_coro , blPop ) <nl> { <nl> int argc = ZEND_NUM_ARGS ( ) ; <nl> - <nl> + SW_REDIS_COMMAND_CHECK <nl> SW_REDIS_COMMAND_ALLOC_ARGS_ARR <nl> if ( zend_get_parameters_array ( ht , argc , z_args ) = = FAILURE | | argc < 1 ) <nl> { <nl> efree ( z_args ) ; <nl> return ; <nl> } <nl> - SW_REDIS_COMMAND_CHECK <nl> <nl> zend_bool single_array = 0 ; <nl> if ( argc = = 2 & & SW_REDIS_COMMAND_ARGS_TYPE ( z_args [ 0 ] ) = = IS_ARRAY ) <nl> static PHP_METHOD ( swoole_redis_coro , blPop ) <nl> static PHP_METHOD ( swoole_redis_coro , brPop ) <nl> { <nl> int argc = ZEND_NUM_ARGS ( ) ; <nl> - <nl> + SW_REDIS_COMMAND_CHECK <nl> SW_REDIS_COMMAND_ALLOC_ARGS_ARR <nl> if ( zend_get_parameters_array ( ht , argc , z_args ) = = FAILURE | | argc < 1 ) <nl> { <nl> efree ( z_args ) ; <nl> return ; <nl> } <nl> - SW_REDIS_COMMAND_CHECK <nl> <nl> zend_bool single_array = 0 ; <nl> if ( argc = = 2 & & SW_REDIS_COMMAND_ARGS_TYPE ( z_args [ 0 ] ) = = IS_ARRAY ) <nl> static PHP_METHOD ( swoole_redis_coro , pfadd ) <nl> static PHP_METHOD ( swoole_redis_coro , pfcount ) <nl> { <nl> int argc = ZEND_NUM_ARGS ( ) ; <nl> - <nl> + SW_REDIS_COMMAND_CHECK <nl> SW_REDIS_COMMAND_ALLOC_ARGS_ARR <nl> if ( zend_get_parameters_array ( ht , argc , z_args ) = = FAILURE | | argc ! = 1 ) <nl> { <nl> static PHP_METHOD ( swoole_redis_coro , pfcount ) <nl> single_array = 1 ; <nl> } <nl> <nl> - SW_REDIS_COMMAND_CHECK <nl> argc + = 1 ; <nl> int i = 0 ; <nl> SW_REDIS_COMMAND_ALLOC_ARGV <nl> static PHP_METHOD ( swoole_redis_coro , zIncrBy ) <nl> static PHP_METHOD ( swoole_redis_coro , zAdd ) <nl> { <nl> int argc = ZEND_NUM_ARGS ( ) ; <nl> - <nl> + SW_REDIS_COMMAND_CHECK <nl> SW_REDIS_COMMAND_ALLOC_ARGS_ARR <nl> if ( zend_get_parameters_array ( ht , argc , z_args ) = = FAILURE ) <nl> { <nl> static PHP_METHOD ( swoole_redis_coro , zAdd ) <nl> efree ( z_args ) ; <nl> RETURN_FALSE ; <nl> } <nl> - SW_REDIS_COMMAND_CHECK <nl> <nl> int i = 0 , j , k , valid_params ; <nl> valid_params = argc - 1 ; <nl> static PHP_METHOD ( swoole_redis_coro , bitCount ) <nl> static PHP_METHOD ( swoole_redis_coro , bitOp ) <nl> { <nl> int argc = ZEND_NUM_ARGS ( ) ; <nl> - <nl> + SW_REDIS_COMMAND_CHECK <nl> SW_REDIS_COMMAND_ALLOC_ARGS_ARR <nl> if ( zend_get_parameters_array ( ht , argc , z_args ) = = FAILURE | | <nl> argc < 3 | | SW_REDIS_COMMAND_ARGS_TYPE ( z_args [ 0 ] ) ! = IS_STRING ) <nl> static PHP_METHOD ( swoole_redis_coro , bitOp ) <nl> return ; <nl> } <nl> <nl> - SW_REDIS_COMMAND_CHECK <nl> - <nl> int j , i = 0 ; <nl> argc + + ; <nl> SW_REDIS_COMMAND_ALLOC_ARGV <nl> static PHP_METHOD ( swoole_redis_coro , script ) <nl> { <nl> RETURN_FALSE <nl> } <nl> - <nl> + SW_REDIS_COMMAND_CHECK <nl> SW_REDIS_COMMAND_ALLOC_ARGS_ARR <nl> if ( zend_get_parameters_array ( ht , argc , z_args ) = = FAILURE | | SW_REDIS_COMMAND_ARGS_TYPE ( z_args [ 0 ] ) ! = IS_STRING ) <nl> { <nl> static PHP_METHOD ( swoole_redis_coro , script ) <nl> RETURN_FALSE ; <nl> } <nl> <nl> - SW_REDIS_COMMAND_CHECK <nl> int i = 0 ; <nl> if ( ! strcasecmp ( SW_REDIS_COMMAND_ARGS_STRVAL ( z_args [ 0 ] ) , " flush " ) <nl> | | ! strcasecmp ( SW_REDIS_COMMAND_ARGS_STRVAL ( z_args [ 0 ] ) , " kill " ) ) <nl>
|
Fix memory leak when error happens .
|
swoole/swoole-src
|
74f95eda668ed375ae1fda2ac6b98cdfca8e12bb
|
2018-12-03T10:26:35Z
|
mmm a / tensorflow / contrib / lite / python / convert . py <nl> ppp b / tensorflow / contrib / lite / python / convert . py <nl> def build_toco_convert_protos ( input_tensors , <nl> post_training_quantize = False , <nl> dump_graphviz_dir = None , <nl> dump_graphviz_video = False , <nl> - converter_mode = ConverterMode . DEFAULT ) : <nl> + converter_mode = ConverterMode . DEFAULT , <nl> + allow_nonexistent_arrays = False ) : <nl> " " " Builds protocol buffers describing a conversion of a model using TOCO . <nl> <nl> Typically this is to convert from TensorFlow GraphDef to TFLite , in which <nl> def build_toco_convert_protos ( input_tensors , <nl> every graph transformation . ( default False ) <nl> converter_mode : Experimental flag , subject to change . ConverterMode <nl> indicating which converter to use . ( default ConverterMode . DEFAULT ) <nl> + allow_nonexistent_arrays : Allow specifying array names that don ' t exist <nl> + or are unused in the final graph . ( default False ) <nl> <nl> Returns : <nl> model_flags , toco_flags : two protocol buffers describing the conversion <nl> def build_toco_convert_protos ( input_tensors , <nl> <nl> for output_tensor in output_tensors : <nl> model . output_arrays . append ( tensor_name ( output_tensor ) ) <nl> + <nl> + model . allow_nonexistent_arrays = allow_nonexistent_arrays <nl> + <nl> return model , toco <nl> <nl> <nl> mmm a / tensorflow / contrib / lite / toco / tooling_util . cc <nl> ppp b / tensorflow / contrib / lite / toco / tooling_util . cc <nl> void CheckNonExistentIOArrays ( const Model & model ) { <nl> if ( model . flags . allow_nonexistent_arrays ( ) ) { <nl> return ; <nl> } <nl> + static constexpr char general_comment [ ] = <nl> + " Is it a typo ? To silence this message , pass this flag : " <nl> + " allow_nonexistent_arrays " ; <nl> for ( const auto & input_array : model . flags . input_arrays ( ) ) { <nl> QCHECK ( GetOpWithInput ( model , input_array . name ( ) ) ) <nl> - < < " Specified input array " < < input_array . name ( ) <nl> - < < " is not consumed by any op in this graph . Is it a typo ? " ; <nl> + < < " Specified input array \ " " < < input_array . name ( ) <nl> + < < " \ " is not consumed by any op in this graph . " < < general_comment ; <nl> } <nl> for ( const string & output_array : model . flags . output_arrays ( ) ) { <nl> QCHECK ( GetOpWithOutput ( model , output_array ) ) <nl> - < < " Specified output array " < < output_array <nl> - < < " is not produced by any op in this graph . Is it a typo ? " ; <nl> + < < " Specified output array \ " " < < output_array <nl> + < < " \ " is not produced by any op in this graph . " < < general_comment ; <nl> } <nl> for ( const auto & rnn_state : model . flags . rnn_states ( ) ) { <nl> if ( ! rnn_state . discardable ( ) ) { <nl> / / Check that all RNN states are consumed <nl> QCHECK ( GetOpWithInput ( model , rnn_state . state_array ( ) ) ) <nl> - < < " Specified RNN state " < < rnn_state . state_array ( ) <nl> - < < " is not consumed by any op in this graph . Is it a typo ? " ; <nl> + < < " Specified RNN state \ " " < < rnn_state . state_array ( ) <nl> + < < " \ " is not consumed by any op in this graph . " < < general_comment ; <nl> / / Check that all RNN back - edge source arrays are produced <nl> QCHECK ( GetOpWithOutput ( model , rnn_state . back_edge_source_array ( ) ) ) <nl> - < < " Specified RNN back - edge source array " <nl> + < < " Specified RNN back - edge source array \ " " <nl> < < rnn_state . back_edge_source_array ( ) <nl> - < < " is not produced by any op in this graph . Is it a typo ? " ; <nl> + < < " \ " is not produced by any op in this graph . " < < general_comment ; <nl> } <nl> } <nl> } <nl>
|
Allow passing - - allow_nonexistent_arrays via toco_convert
|
tensorflow/tensorflow
|
508dd179b6b6dd78aa3e24212648789e8fc018a0
|
2018-10-02T19:51:27Z
|
mmm a / src / mongo / s / catalog / replset / catalog_manager_replica_set . cpp <nl> ppp b / src / mongo / s / catalog / replset / catalog_manager_replica_set . cpp <nl> bool CatalogManagerReplicaSet : : runUserManagementWriteCommand ( OperationContext * t <nl> cmdToRun = modifiedCmd . obj ( ) ; <nl> } <nl> <nl> - auto scopedDistLock = <nl> - getDistLockManager ( ) - > lock ( txn , " authorizationData " , commandName , Seconds { 5 } ) ; <nl> - if ( ! scopedDistLock . isOK ( ) ) { <nl> - return Command : : appendCommandStatus ( * result , scopedDistLock . getStatus ( ) ) ; <nl> - } <nl> - <nl> auto response = <nl> grid . shardRegistry ( ) - > runCommandOnConfigWithNotMasterRetries ( txn , dbname , cmdToRun ) ; <nl> + <nl> if ( ! response . isOK ( ) ) { <nl> return Command : : appendCommandStatus ( * result , response . getStatus ( ) ) ; <nl> } <nl> + <nl> result - > appendElements ( response . getValue ( ) ) ; <nl> return Command : : getStatusFromCommandResult ( response . getValue ( ) ) . isOK ( ) ; <nl> } <nl> mmm a / src / mongo / s / catalog / replset / catalog_manager_replica_set_test . cpp <nl> ppp b / src / mongo / s / catalog / replset / catalog_manager_replica_set_test . cpp <nl> TEST_F ( CatalogManagerReplSetTest , RunUserManagementReadCommandUnsatisfiedReadPre <nl> ASSERT_EQUALS ( ErrorCodes : : FailedToSatisfyReadPreference , commandStatus ) ; <nl> } <nl> <nl> - TEST_F ( CatalogManagerReplSetTest , RunUserManagementWriteCommandDistLockHeld ) { <nl> - configTargeter ( ) - > setFindHostReturnValue ( HostAndPort ( " TestHost1 " ) ) ; <nl> - <nl> - distLock ( ) - > expectLock ( <nl> - [ ] ( StringData name , <nl> - StringData whyMessage , <nl> - milliseconds waitFor , <nl> - milliseconds lockTryInterval ) { <nl> - ASSERT_EQUALS ( " authorizationData " , name ) ; <nl> - ASSERT_EQUALS ( " dropUser " , whyMessage ) ; <nl> - } , <nl> - Status ( ErrorCodes : : LockBusy , " lock already held " ) ) ; <nl> - <nl> - BSONObjBuilder responseBuilder ; <nl> - bool ok = catalogManager ( ) - > runUserManagementWriteCommand ( operationContext ( ) , <nl> - " dropUser " , <nl> - " test " , <nl> - BSON ( " dropUser " <nl> - < < " test " ) , <nl> - & responseBuilder ) ; <nl> - ASSERT_FALSE ( ok ) ; <nl> - BSONObj response = responseBuilder . obj ( ) ; <nl> - ASSERT_EQUALS ( ErrorCodes : : LockBusy , Command : : getStatusFromCommandResult ( response ) ) ; <nl> - } <nl> - <nl> TEST_F ( CatalogManagerReplSetTest , RunUserManagementWriteCommandSuccess ) { <nl> configTargeter ( ) - > setFindHostReturnValue ( HostAndPort ( " TestHost1 " ) ) ; <nl> <nl> - distLock ( ) - > expectLock ( <nl> - [ ] ( StringData name , <nl> - StringData whyMessage , <nl> - milliseconds waitFor , <nl> - milliseconds lockTryInterval ) { <nl> - ASSERT_EQUALS ( " authorizationData " , name ) ; <nl> - ASSERT_EQUALS ( " dropUser " , whyMessage ) ; <nl> - } , <nl> - Status : : OK ( ) ) ; <nl> - <nl> auto future = launchAsync ( [ this ] { <nl> BSONObjBuilder responseBuilder ; <nl> bool ok = catalogManager ( ) - > runUserManagementWriteCommand ( operationContext ( ) , <nl> TEST_F ( CatalogManagerReplSetTest , RunUserManagementWriteCommandRewriteWriteConce <nl> TEST_F ( CatalogManagerReplSetTest , RunUserManagementWriteCommandNotMaster ) { <nl> configTargeter ( ) - > setFindHostReturnValue ( HostAndPort ( " TestHost1 " ) ) ; <nl> <nl> - distLock ( ) - > expectLock ( <nl> - [ ] ( StringData name , <nl> - StringData whyMessage , <nl> - milliseconds waitFor , <nl> - milliseconds lockTryInterval ) { <nl> - ASSERT_EQUALS ( " authorizationData " , name ) ; <nl> - ASSERT_EQUALS ( " dropUser " , whyMessage ) ; <nl> - } , <nl> - Status : : OK ( ) ) ; <nl> - <nl> auto future = launchAsync ( [ this ] { <nl> BSONObjBuilder responseBuilder ; <nl> bool ok = catalogManager ( ) - > runUserManagementWriteCommand ( operationContext ( ) , <nl> TEST_F ( CatalogManagerReplSetTest , RunUserManagementWriteCommandNotMasterRetrySuc <nl> HostAndPort host1 ( " TestHost1 " ) ; <nl> HostAndPort host2 ( " TestHost2 " ) ; <nl> <nl> - <nl> configTargeter ( ) - > setFindHostReturnValue ( host1 ) ; <nl> <nl> - distLock ( ) - > expectLock ( <nl> - [ ] ( StringData name , <nl> - StringData whyMessage , <nl> - milliseconds waitFor , <nl> - milliseconds lockTryInterval ) { <nl> - ASSERT_EQUALS ( " authorizationData " , name ) ; <nl> - ASSERT_EQUALS ( " dropUser " , whyMessage ) ; <nl> - } , <nl> - Status : : OK ( ) ) ; <nl> - <nl> auto future = launchAsync ( [ this ] { <nl> BSONObjBuilder responseBuilder ; <nl> bool ok = catalogManager ( ) - > runUserManagementWriteCommand ( operationContext ( ) , <nl>
|
SERVER - 20181 remove dist locking in user mgmt writes for config rs
|
mongodb/mongo
|
f850d55c99056b892e35689c7123cd5c56979644
|
2015-10-15T19:19:25Z
|
mmm a / src / arch / io / timer / timer_signal_provider . cc <nl> ppp b / src / arch / io / timer / timer_signal_provider . cc <nl> <nl> / / heck knows why it isn ' t . . . <nl> # define sigev_notify_thread_id _sigev_un . _tid <nl> <nl> + void timer_signal_provider_signal_handler ( UNUSED int signum , siginfo_t * siginfo , UNUSED void * uctx ) { <nl> + timer_provider_callback_t * callback = static_cast < timer_provider_callback_t * > ( siginfo - > si_value . sival_ptr ) ; <nl> + <nl> + / / The number of timer ticks that have happened is 1 plus the timer signal ' s overrun count . <nl> + callback - > on_timer ( 1 + siginfo - > si_overrun ) ; <nl> + } <nl> + <nl> / * Kernel timer provider based on signals * / <nl> - timer_signal_provider_t : : timer_signal_provider_t ( linux_event_queue_t * _queue , <nl> - timer_provider_callback_t * _callback , <nl> - time_t secs , int32_t nsecs ) <nl> - : queue ( _queue ) , callback ( _callback ) <nl> - { <nl> + timer_signal_provider_t : : timer_signal_provider_t ( UNUSED linux_event_queue_t * queue , <nl> + timer_provider_callback_t * callback , <nl> + time_t secs , int32_t nsecs ) { <nl> + struct sigaction sa ; <nl> + memset ( & sa , 0 , sizeof ( sa ) ) ; <nl> + sa . sa_flags = SA_SIGINFO ; <nl> + sa . sa_sigaction = & timer_signal_provider_signal_handler ; <nl> + <nl> + int res = sigfillset ( & sa . sa_mask ) ; <nl> + guarantee_err ( res = = 0 , " sigfillset failed " ) ; <nl> + <nl> + / / TODO ( OSX ) What the hell ? Do we not initialize sa . sa_mask ? <nl> + / / Register the signal . <nl> + res = sigaction ( TIMER_NOTIFY_SIGNAL , & sa , NULL ) ; <nl> + guarantee_err ( res = = 0 , " timer signal provider could not register the signal handler " ) ; <nl> + <nl> / / Initialize the event structure <nl> + struct sigevent evp ; <nl> bzero ( & evp , sizeof ( sigevent ) ) ; <nl> evp . sigev_signo = TIMER_NOTIFY_SIGNAL ; <nl> evp . sigev_notify = SIGEV_THREAD_ID ; <nl> evp . sigev_notify_thread_id = _gettid ( ) ; <nl> - evp . sigev_value . sival_ptr = this ; <nl> - <nl> - / / Tell the event queue to start watching the signal . It ' s <nl> - / / important to call this before creating the timer , because the <nl> - / / event queue automatically blocks the signal ( which is necessary <nl> - / / to implement poll / epoll properly ) . <nl> - queue - > watch_signal ( & evp , this ) ; <nl> + evp . sigev_value . sival_ptr = callback ; <nl> <nl> / / Create the timer <nl> - int res = timer_create ( CLOCK_MONOTONIC , & evp , & timerid ) ; <nl> + res = timer_create ( CLOCK_MONOTONIC , & evp , & timerid ) ; <nl> guarantee_err ( res = = 0 , " Could not create timer " ) ; <nl> <nl> - / / Arm the timer <nl> + / / Start the timer <nl> itimerspec timer_spec ; <nl> bzero ( & timer_spec , sizeof ( timer_spec ) ) ; <nl> timer_spec . it_value . tv_sec = timer_spec . it_interval . tv_sec = secs ; <nl> timer_signal_provider_t : : timer_signal_provider_t ( linux_event_queue_t * _queue , <nl> <nl> timer_signal_provider_t : : ~ timer_signal_provider_t ( ) { <nl> int res = timer_delete ( timerid ) ; <nl> - guarantee_err ( res = = 0 , " Could not close the timer . " ) ; <nl> - queue - > forget_signal ( & evp , this ) ; <nl> - } <nl> + guarantee_err ( res = = 0 , " timer_delete failed " ) ; <nl> + <nl> + struct sigaction sa ; <nl> + memset ( & sa , 0 , sizeof ( sa ) ) ; <nl> + sa . sa_handler = SIG_DFL ; <nl> <nl> - void timer_signal_provider_t : : on_event ( int events ) { <nl> - / / In case of signals , events argument accepts the number of times <nl> - / / the event was overrun . For signal - based timers this is zero in <nl> - / / most cases , so we should add one when we call the timer <nl> - / / callback api . <nl> - callback - > on_timer ( events + 1 ) ; <nl> + res = sigaction ( TIMER_NOTIFY_SIGNAL , & sa , NULL ) ; <nl> + guarantee_err ( res = = 0 , " timer signal provider could not unregister the signal handler " ) ; <nl> } <nl> <nl> # endif / / RDB_TIMER_PROVIDER = = RDB_TIMER_PROVIDER_SIGNAL <nl> mmm a / src / arch / io / timer / timer_signal_provider . hpp <nl> ppp b / src / arch / io / timer / timer_signal_provider . hpp <nl> struct timer_provider_callback_t ; <nl> # define TIMER_NOTIFY_SIGNAL ( SIGRTMIN + 3 ) <nl> <nl> / * Kernel timer provider based on signals * / <nl> - struct timer_signal_provider_t : public linux_event_callback_t { <nl> + struct timer_signal_provider_t { <nl> public : <nl> timer_signal_provider_t ( linux_event_queue_t * _queue , <nl> timer_provider_callback_t * _callback , <nl> time_t secs , int32_t nsecs ) ; <nl> ~ timer_signal_provider_t ( ) ; <nl> <nl> - void on_event ( int events ) ; <nl> - <nl> private : <nl> - linux_event_queue_t * queue ; <nl> - timer_provider_callback_t * callback ; <nl> timer_t timerid ; <nl> - sigevent evp ; / / notify event <nl> <nl> DISABLE_COPYING ( timer_signal_provider_t ) ; <nl> } ; <nl> mmm a / src / arch / runtime / event_queue . cc <nl> ppp b / src / arch / runtime / event_queue . cc <nl> std : : string format_poll_event ( int event ) { <nl> if ( s = = " " ) s = " ( none ) " ; <nl> return s ; <nl> } <nl> - <nl> - void event_queue_base_t : : signal_handler ( UNUSED int signum , siginfo_t * siginfo , UNUSED void * uctx ) { <nl> - linux_event_callback_t * callback = reinterpret_cast < linux_event_callback_t * > ( siginfo - > si_value . sival_ptr ) ; <nl> - # ifdef RDB_TIMER_PROVIDER_ITIMER <nl> - / / si_overrun isn ' t available on OS X and I saw nothing about itimer support on other OSes <nl> - / / anyway . So we pretend there is no overrun . <nl> - / / TODO ( OSX ) Fix the thing that depends on si_overrun . <nl> - callback - > on_event ( 0 ) ; <nl> - # else <nl> - callback - > on_event ( siginfo - > si_overrun ) ; <nl> - # endif / / __MACH__ <nl> - } <nl> - <nl> - void event_queue_base_t : : watch_signal ( const sigevent * evp , UNUSED linux_event_callback_t * cb ) { <nl> - / / All events are automagically blocked by thread pool , this is a <nl> - / / typical use case for epoll_pwait / ppoll . <nl> - <nl> - / / Establish a handler on the signal that calls the right callback <nl> - struct sigaction sa ; <nl> - memset ( & sa , 0 , sizeof ( sa ) ) ; <nl> - sa . sa_sigaction = & event_queue_base_t : : signal_handler ; <nl> - sa . sa_flags = SA_SIGINFO ; <nl> - <nl> - int res = sigaction ( evp - > sigev_signo , & sa , NULL ) ; <nl> - guarantee_err ( res = = 0 , " Could not install signal handler in event queue " ) ; <nl> - } <nl> - <nl> - void event_queue_base_t : : forget_signal ( UNUSED const sigevent * evp , UNUSED linux_event_callback_t * cb ) { <nl> - / / We don ' t support forgetting signals for now <nl> - } <nl> - <nl> mmm a / src / arch / runtime / event_queue / epoll . hpp <nl> ppp b / src / arch / runtime / event_queue / epoll . hpp <nl> <nl> # include " config / args . hpp " <nl> <nl> / / Event queue structure <nl> - struct epoll_event_queue_t : public event_queue_base_t { <nl> + struct epoll_event_queue_t { <nl> public : <nl> explicit epoll_event_queue_t ( linux_queue_parent_t * parent ) ; <nl> void run ( ) ; <nl> mmm a / src / arch / runtime / event_queue / poll . hpp <nl> ppp b / src / arch / runtime / event_queue / poll . hpp <nl> <nl> # include " arch / runtime / runtime_utils . hpp " <nl> <nl> / / Event queue structure <nl> - struct poll_event_queue_t : public event_queue_base_t { <nl> + struct poll_event_queue_t { <nl> public : <nl> typedef std : : vector < pollfd > pollfd_vector_t ; <nl> typedef std : : map < fd_t , linux_event_callback_t * > callback_map_t ; <nl> mmm a / src / arch / runtime / event_queue_types . hpp <nl> ppp b / src / arch / runtime / event_queue_types . hpp <nl> struct linux_event_callback_t { <nl> virtual ~ linux_event_callback_t ( ) { } <nl> } ; <nl> <nl> - / / Common event queue functionality <nl> - struct event_queue_base_t { <nl> - public : <nl> - void watch_signal ( const sigevent * evp , linux_event_callback_t * cb ) ; <nl> - void forget_signal ( const sigevent * evp , linux_event_callback_t * cb ) ; <nl> - <nl> - private : <nl> - static void signal_handler ( int signum , siginfo_t * siginfo , void * uctx ) ; <nl> - } ; <nl> - <nl> struct linux_queue_parent_t { <nl> virtual void pump ( ) = 0 ; <nl> virtual bool should_shut_down ( ) = 0 ; <nl>
|
Stripped out the quite broken event_queue_base_t class and signal - watching functions .
|
rethinkdb/rethinkdb
|
6e5f8a9de7383e289cb6040754b21f1439fc1673
|
2012-12-03T23:57:28Z
|
mmm a / src / common / CMakeLists . txt <nl> ppp b / src / common / CMakeLists . txt <nl> set ( SRCS break_points . cpp <nl> set ( HEADS atomic . h <nl> atomic_gcc . h <nl> atomic_win32 . h <nl> + bit_field . h <nl> break_points . h <nl> chunk_file . h <nl> common_funcs . h <nl> mmm a / src / core / CMakeLists . txt <nl> ppp b / src / core / CMakeLists . txt <nl> set ( HEADS core . h <nl> mem_map . h <nl> system . h <nl> arm / disassembler / arm_disasm . h <nl> + arm / disassembler / load_symbol_map . h <nl> arm / interpreter / arm_interpreter . h <nl> arm / interpreter / arm_regformat . h <nl> arm / interpreter / armcpu . h <nl> set ( HEADS core . h <nl> arm / interpreter / armmmu . h <nl> arm / interpreter / armos . h <nl> arm / interpreter / skyeye_defs . h <nl> - arm / mmu / arm1176jzf_s_mmu . h <nl> - arm / mmu / cache . h <nl> - arm / mmu / rb . h <nl> - arm / mmu / tlb . h <nl> - arm / mmu / wb . h <nl> + arm / interpreter / mmu / arm1176jzf_s_mmu . h <nl> + arm / interpreter / mmu / cache . h <nl> + arm / interpreter / mmu / rb . h <nl> + arm / interpreter / mmu / sa_mmu . h <nl> + arm / interpreter / mmu / tlb . h <nl> + arm / interpreter / mmu / wb . h <nl> + arm / interpreter / vfp / asm_vfp . h <nl> + arm / interpreter / vfp / vfp . h <nl> + arm / interpreter / vfp / vfp_helper . h <nl> elf / elf_reader . h <nl> elf / elf_types . h <nl> file_sys / directory_file_system . h <nl> file_sys / file_sys . h <nl> file_sys / meta_file_system . h <nl> + hle / config_mem . h <nl> + hle / coprocessor . h <nl> hle / hle . h <nl> - hle / mrc . h <nl> hle / syscall . h <nl> hle / function_wrappers . h <nl> hle / service / apt . h <nl>
|
Updated cmakelists
|
yuzu-emu/yuzu
|
c1394650ff0ab1859b93505771e14c9afdb8aeb3
|
2014-05-17T06:39:27Z
|
mmm a / configure . ac <nl> ppp b / configure . ac <nl> case $ host in <nl> AC_PATH_TOOL ( [ INSTALLNAMETOOL ] , [ install_name_tool ] , install_name_tool ) <nl> AC_PATH_TOOL ( [ OTOOL ] , [ otool ] , otool ) <nl> AC_PATH_PROGS ( [ GENISOIMAGE ] , [ genisoimage mkisofs ] , genisoimage ) <nl> + <nl> + dnl libtool will try to strip the static lib , which is a problem for <nl> + dnl cross - builds because strip attempts to call a hard - coded ld , <nl> + dnl which may not exist in the path . Stripping the . a is not <nl> + dnl necessary , so just disable it . <nl> + old_striplib = <nl> ; ; <nl> esac <nl> fi <nl>
|
build : disable static lib stripping during osx make install - strip
|
bitcoin/bitcoin
|
b7f2cdc8a97ba1a2155c0614895701de0f327154
|
2014-11-25T23:41:27Z
|
mmm a / cocos2dx / misc_nodes / CCMotionStreak . cpp <nl> ppp b / cocos2dx / misc_nodes / CCMotionStreak . cpp <nl> void CCMotionStreak : : draw ( ) <nl> ccGLBindTexture2D ( m_pTexture - > getName ( ) ) ; <nl> <nl> # ifdef EMSCRIPTEN <nl> + / / Size calculations from : : initWithFade <nl> setGLBufferData ( m_pVertices , ( sizeof ( ccVertex2F ) * m_uMaxPoints * 2 ) , 0 ) ; <nl> glVertexAttribPointer ( kCCVertexAttrib_Position , 2 , GL_FLOAT , GL_FALSE , 0 , 0 ) ; <nl> <nl> mmm a / cocos2dx / textures / CCTexture2D . cpp <nl> ppp b / cocos2dx / textures / CCTexture2D . cpp <nl> void CCTexture2D : : drawAtPoint ( const CCPoint & point ) <nl> ccGLBindTexture2D ( m_uName ) ; <nl> <nl> <nl> + # ifdef EMSCRIPTEN <nl> + setGLBufferData ( vertices , 8 * sizeof ( GLfloat ) , 0 ) ; <nl> + glVertexAttribPointer ( kCCVertexAttrib_Position , 2 , GL_FLOAT , GL_FALSE , 0 , 0 ) ; <nl> + <nl> + setGLBufferData ( coordinates , 8 * sizeof ( GLfloat ) , 1 ) ; <nl> + glVertexAttribPointer ( kCCVertexAttrib_TexCoords , 2 , GL_FLOAT , GL_FALSE , 0 , 0 ) ; <nl> + # else <nl> glVertexAttribPointer ( kCCVertexAttrib_Position , 2 , GL_FLOAT , GL_FALSE , 0 , vertices ) ; <nl> glVertexAttribPointer ( kCCVertexAttrib_TexCoords , 2 , GL_FLOAT , GL_FALSE , 0 , coordinates ) ; <nl> + # endif / / EMSCRIPTEN <nl> <nl> glDrawArrays ( GL_TRIANGLE_STRIP , 0 , 4 ) ; <nl> } <nl> void CCTexture2D : : drawInRect ( const CCRect & rect ) <nl> <nl> ccGLBindTexture2D ( m_uName ) ; <nl> <nl> + # ifdef EMSCRIPTEN <nl> + setGLBufferData ( vertices , 8 * sizeof ( GLfloat ) , 0 ) ; <nl> + glVertexAttribPointer ( kCCVertexAttrib_Position , 2 , GL_FLOAT , GL_FALSE , 0 , 0 ) ; <nl> + <nl> + setGLBufferData ( coordinates , 8 * sizeof ( GLfloat ) , 1 ) ; <nl> + glVertexAttribPointer ( kCCVertexAttrib_TexCoords , 2 , GL_FLOAT , GL_FALSE , 0 , 0 ) ; <nl> + # else <nl> glVertexAttribPointer ( kCCVertexAttrib_Position , 2 , GL_FLOAT , GL_FALSE , 0 , vertices ) ; <nl> glVertexAttribPointer ( kCCVertexAttrib_TexCoords , 2 , GL_FLOAT , GL_FALSE , 0 , coordinates ) ; <nl> + # endif / / EMSCRIPTEN <nl> glDrawArrays ( GL_TRIANGLE_STRIP , 0 , 4 ) ; <nl> } <nl> <nl>
|
More client side buffer fixes .
|
cocos2d/cocos2d-x
|
303c5a0ab0e36193c725161554c2cb95bbb8fb93
|
2013-05-01T20:33:52Z
|
mmm a / lib / IRGen / GenFunc . cpp <nl> ppp b / lib / IRGen / GenFunc . cpp <nl> namespace { <nl> / / / Given a Swift type , attempt to return an appropriate Clang <nl> / / / CanQualType for the purpose of generating correct code for the <nl> / / / ABI . <nl> - static clang : : CanQualType getClangABIType ( CanType swiftType ) { <nl> - / / FIXME : ProtocolType generates a struct and might need special <nl> - / / handling here for some platforms . <nl> - if ( auto structType = swiftType - > getAs < StructType > ( ) ) <nl> - if ( auto * clangDecl = structType - > getDecl ( ) - > getClangDecl ( ) ) { <nl> + class ClangTypeGen : public CanTypeVisitor < ClangTypeGen , clang : : CanQualType > { <nl> + public : <nl> + <nl> + / / / Return the Clang struct type which was imported and resulted in <nl> + / / / this Swift struct type . We do not currently handle generating a <nl> + / / / new Clang struct type for Swift struct types that are created <nl> + / / / independently of importing a Clang module . <nl> + clang : : CanQualType visitStructType ( CanStructType type ) { <nl> + if ( auto * clangDecl = type - > getDecl ( ) - > getClangDecl ( ) ) { <nl> auto * typeDecl = cast < clang : : TypeDecl > ( clangDecl ) ; <nl> return typeDecl - > getTypeForDecl ( ) - > getCanonicalTypeUnqualified ( ) ; <nl> } <nl> <nl> - / / FIXME : For parameters , we need to be able to generate a Clang <nl> - / / type for all Swift types . <nl> - return clang : : CanQualType ( ) ; <nl> - } <nl> + / / FIXME : For parameters , we need to be able to generate a Clang <nl> + / / type for all Swift types that can appear in an @ objc parameter <nl> + / / list . <nl> + return clang : : CanQualType ( ) ; <nl> + } <nl> + <nl> + clang : : CanQualType visitType ( CanType type ) { <nl> + return clang : : CanQualType ( ) ; <nl> + } <nl> + } ; <nl> <nl> llvm : : Type * SignatureExpansion : : addIndirectResult ( ) { <nl> auto resultType = FnType - > getResult ( ) . getSILType ( ) ; <nl> llvm : : Type * SignatureExpansion : : expandResult ( ) { <nl> if ( requiresExternalIndirectResult ( IGM , FnType , ExplosionLevel ) ) <nl> return addIndirectResult ( ) ; <nl> <nl> - auto clangType = getClangABIType ( resultType . getSwiftRValueType ( ) ) ; <nl> + ClangTypeGen CTG ; <nl> + auto clangType = CTG . visit ( resultType . getSwiftRValueType ( ) ) ; <nl> <nl> / / Fall back on native Swift type lowering for things that we <nl> / / cannot generate a Clang type from . <nl> irgen : : requiresExternalIndirectResult ( IRGenModule & IGM , <nl> } <nl> <nl> auto resultTy = fnType - > getResult ( ) . getSILType ( ) ; <nl> - auto clangTy = getClangABIType ( resultTy . getSwiftRValueType ( ) ) ; <nl> + ClangTypeGen CTG ; <nl> + auto clangTy = CTG . visit ( resultTy . getSwiftRValueType ( ) ) ; <nl> <nl> / / We are unable to produce an appropriate Clang type in some cases , <nl> / / so fall back on the test used for native Swift types . <nl>
|
Replace getClangABIType ( ) with a CanTypeVisitor < > .
|
apple/swift
|
15a26af8ac2d0dac7ce7251da7397726faf23f79
|
2014-01-10T00:27:25Z
|
mmm a / docs / source / jit . rst <nl> ppp b / docs / source / jit . rst <nl> including control flow operators for loops and conditionals . As an example : <nl> <nl> . . . <nl> <nl> - ` ` graph ` ` follows the same rules described in the ` Inspecting Code ` _ section <nl> + ` ` graph ` ` follows the same rules described in the ` inspecting - code ` section <nl> with regard to ` ` forward ` ` method lookup . <nl> <nl> The example script above produces the graph : : <nl> mmm a / docs / source / nn . functional . rst <nl> ppp b / docs / source / nn . functional . rst <nl> Non - linear activation functions <nl> . . autofunction : : hardtanh_ <nl> <nl> : hidden : ` hardswish ` <nl> - ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ <nl> + ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ <nl> <nl> . . autofunction : : hardswish <nl> <nl> Non - linear activation functions <nl> . . autofunction : : sigmoid <nl> <nl> : hidden : ` hardsigmoid ` <nl> - ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ <nl> + ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ <nl> <nl> . . autofunction : : hardsigmoid <nl> <nl> Dropout functions <nl> . . autofunction : : alpha_dropout <nl> <nl> : hidden : ` feature_alpha_dropout ` <nl> - ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ <nl> + ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ <nl> <nl> . . autofunction : : feature_alpha_dropout <nl> <nl> deleted file mode 100644 <nl> index 7f6477e0cc35 . . 000000000000 <nl> mmm a / docs / source / packages . rst <nl> ppp / dev / null <nl> <nl> - Javadoc <nl> - = = = = = = = <nl> - <nl> - . . toctree : : <nl> - : maxdepth : 2 <nl> - <nl> - org / pytorch / package - index <nl> mmm a / docs / source / quantization . rst <nl> ppp b / docs / source / quantization . rst <nl> accuracy <nl> * : class : ` ~ torch . nn . intrinsic . LinearReLU ` — Linear + ReLU <nl> <nl> * ` ` torch . nn . intrinsic . qat ` ` — versions of layers for quantization - aware training : <nl> + <nl> * : class : ` ~ torch . nn . intrinsic . qat . ConvBn2d ` — Conv2d + BatchNorm <nl> * : class : ` ~ torch . nn . intrinsic . qat . ConvBnReLU2d ` — Conv2d + BatchNorm + ReLU <nl> * : class : ` ~ torch . nn . intrinsic . qat . ConvReLU2d ` — Conv2d + ReLU <nl> accuracy <nl> * ` ` torch . nn . intrinsic . quantized ` ` — quantized version of fused layers for <nl> inference ( no BatchNorm variants as it ' s usually folded into convolution for <nl> inference ) : <nl> + <nl> * : class : ` ~ torch . nn . intrinsic . quantized . LinearReLU ` — Linear + ReLU <nl> * : class : ` ~ torch . nn . intrinsic . quantized . ConvReLU1d ` — 1D Convolution + ReLU <nl> * : class : ` ~ torch . nn . intrinsic . quantized . ConvReLU2d ` — 2D Convolution + ReLU <nl> Layers for the quantization - aware training <nl> * : func : ` ~ torch . quantization . swap_module ` — Swaps the module with its <nl> quantized counterpart ( if quantizable and if it has an observer ) <nl> * : func : ` ~ torch . quantization . default_eval_fn ` — Default evaluation function <nl> - used by the : func : ` torch . quantization . quantize ` <nl> + used by the : func : ` torch . quantization . quantize ` <nl> * : func : ` ~ torch . quantization . fuse_modules ` <nl> <nl> * Functions for graph mode quantization : <nl> + <nl> * : func : ` ~ torch . quantization . quantize_jit ` - Function for graph mode post training static quantization <nl> * : func : ` ~ torch . quantization . quantize_dynamic_jit ` - Function for graph mode post training dynamic quantization <nl> <nl> Layers for the quantization - aware training <nl> * : class : ` ~ torch . quantization . DeQuantStub ` <nl> <nl> * Observers for computing the quantization parameters <nl> + <nl> * Default Observers . The rest of observers are available from <nl> ` ` torch . quantization . observer ` ` : <nl> + <nl> * : attr : ` ~ torch . quantization . default_observer ` — Same as ` ` MinMaxObserver . with_args ( reduce_range = True ) ` ` <nl> * : attr : ` ~ torch . quantization . default_weight_observer ` — Same as ` ` MinMaxObserver . with_args ( dtype = torch . qint8 , qscheme = torch . per_tensor_symmetric ) ` ` <nl> + <nl> * : class : ` ~ torch . quantization . Observer ` — Abstract base class for observers <nl> * : class : ` ~ torch . quantization . MinMaxObserver ` — Derives the quantization <nl> parameters from the running minimum and maximum of the observed tensor inputs <nl> Layers for the quantization - aware training <nl> quantization to ` ` float16 ` ` ) <nl> <nl> * FakeQuantize module <nl> - * : class : ` ~ torch . quantization . FakeQuantize ` — Module for simulating the <nl> - quantization / dequantization at training time <nl> + * : class : ` ~ torch . quantization . FakeQuantize ` — Module for simulating the <nl> + quantization / dequantization at training time <nl> <nl> ` ` torch . nn . quantized ` ` <nl> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ <nl> mmm a / torch / _torch_docs . py <nl> ppp b / torch / _torch_docs . py <nl> def merge_dicts ( * dicts ) : <nl> r " " " <nl> view_as_complex ( input ) - > Tensor <nl> <nl> - Returns a view of : attr : ` input ` as a complex tensor . For an input complex tensor of <nl> - : attr : ` size ` : math : ` m1 , m2 , \ dots , mi , 2 ` , this function returns a new <nl> - complex tensor of : attr : ` size ` : math : ` m1 , m2 , \ dots , mi ` where the last dimension of <nl> - the input tensor is expected to represent the real and imaginary components of complex numbers . <nl> + Returns a view of : attr : ` input ` as a complex tensor . For an input complex <nl> + tensor of : attr : ` size ` : math : ` m1 , m2 , \ dots , mi , 2 ` , this function returns a <nl> + new complex tensor of : attr : ` size ` : math : ` m1 , m2 , \ dots , mi ` where the last <nl> + dimension of the input tensor is expected to represent the real and imaginary <nl> + components of complex numbers . <nl> <nl> . . warning : : <nl> - : func : ` view_as_complex ` is only supported for tensors with : class : ` torch . dtype ` ` ` torch . float64 ` ` and ` ` torch . float32 ` . <nl> - The input is expected to have the last dimension of : attr : ` size ` 2 . In addition , the tensor must have a ` stride ` of 1 <nl> - for its last dimension . The strides of all other dimensions must be even numbers . <nl> + : func : ` view_as_complex ` is only supported for tensors with <nl> + : class : ` torch . dtype ` ` ` torch . float64 ` ` and ` ` torch . float32 ` ` . The input is <nl> + expected to have the last dimension of : attr : ` size ` 2 . In addition , the <nl> + tensor must have a ` stride ` of 1 for its last dimension . The strides of all <nl> + other dimensions must be even numbers . <nl> <nl> Args : <nl> { input } <nl> def merge_dicts ( * dicts ) : <nl> <nl> Args : <nl> { input } <nl> - dim ( int or tuple of ints , optional ) : Dim or tuple of dims along which to count non - zeros . <nl> + dim ( int or tuple of ints , optional ) : Dim or tuple of dims along which to count non - zeros . <nl> <nl> Example : : <nl> <nl> mmm a / torch / autograd / functional . py <nl> ppp b / torch / autograd / functional . py <nl> def vhp ( func , inputs , v = None , create_graph = False , strict = False ) : <nl> func ( function ) : a Python function that takes Tensor inputs and returns <nl> a Tensor with a single element . <nl> inputs ( tuple of Tensors or Tensor ) : inputs to the function ` ` func ` ` . <nl> - v ( tuple of Tensors or Tensor ) : The vector for which the vector Hessian product is computed . Must be the <nl> - same size as the input of ` ` func ` ` . This argument is optional when <nl> - ` ` func ` ` ' s input contains a single element and ( if it is not provided ) will be set as a Tensor <nl> - containing a single ` ` 1 ` ` . <nl> - create_graph ( bool , optional ) : If ` ` True ` ` , both the output and result will be <nl> - computed in a differentiable way . Note that when ` ` strict ` ` is ` ` False ` ` , the result can not <nl> - require gradients or be disconnected from the inputs . <nl> + v ( tuple of Tensors or Tensor ) : The vector for which the vector Hessian <nl> + product is computed . Must be the same size as the input of <nl> + ` ` func ` ` . This argument is optional when ` ` func ` ` ' s input contains <nl> + a single element and ( if it is not provided ) will be set as a <nl> + Tensor containing a single ` ` 1 ` ` . <nl> + create_graph ( bool , optional ) : If ` ` True ` ` , both the output and result <nl> + will be computed in a differentiable way . Note that when ` ` strict ` ` <nl> + is ` ` False ` ` , the result can not require gradients or be <nl> + disconnected from the inputs . <nl> Defaults to ` ` False ` ` . <nl> - strict ( bool , optional ) : If ` ` True ` ` , an error will be raised when we detect that there exists an input <nl> - such that all the outputs are independent of it . If ` ` False ` ` , we return a Tensor of zeros as the <nl> + strict ( bool , optional ) : If ` ` True ` ` , an error will be raised when we <nl> + detect that there exists an input such that all the outputs are <nl> + independent of it . If ` ` False ` ` , we return a Tensor of zeros as the <nl> vhp for said inputs , which is the expected mathematical value . <nl> Defaults to ` ` False ` ` . <nl> <nl> Returns : <nl> - func_output ( tuple of Tensors or Tensor ) : output of ` ` func ( inputs ) ` ` <nl> - vhp ( tuple of Tensors or Tensor ) : result of the dot product with the same shape <nl> - as the inputs . <nl> - Example : : <nl> + output ( tuple ) : tuple with : <nl> + func_output ( tuple of Tensors or Tensor ) : output of ` ` func ( inputs ) ` ` <nl> + <nl> + vhp ( tuple of Tensors or Tensor ) : result of the dot product with the <nl> + same shape as the inputs . <nl> + <nl> + Example : <nl> + <nl> > > > def pow_reducer ( x ) : <nl> . . . return x . pow ( 3 ) . sum ( ) <nl> > > > inputs = torch . rand ( 2 , 2 ) <nl> > > > v = torch . ones ( 2 , 2 ) <nl> > > > vhp ( pow_reducer , inputs , v ) <nl> - ( tensor ( 0 . 5591 ) , <nl> - tensor ( [ [ 1 . 0689 , 1 . 2431 ] , <nl> - [ 3 . 0989 , 4 . 4456 ] ] ) ) <nl> + ( tensor ( 0 . 5591 ) , <nl> + tensor ( [ [ 1 . 0689 , 1 . 2431 ] , <nl> + [ 3 . 0989 , 4 . 4456 ] ] ) ) <nl> > > > vhp ( pow_reducer , inputs , v , create_graph = True ) <nl> ( tensor ( 0 . 5591 , grad_fn = < SumBackward0 > ) , <nl> tensor ( [ [ 1 . 0689 , 1 . 2431 ] , <nl> mmm a / torch / jit / __init__ . py <nl> ppp b / torch / jit / __init__ . py <nl> def fork ( func , * args , * * kwargs ) : <nl> func ( callable or torch . nn . Module ) : A Python function or ` torch . nn . Module ` <nl> that will be invoked . If executed in TorchScript , it will execute asynchronously , <nl> otherwise it will not . Traced invocations of fork will be captured in the IR . <nl> - * args , * * kwargs : arguments to invoke ` func ` with . <nl> + ` ` * args ` ` , ` ` * * kwargs ` ` : arguments to invoke ` func ` with . <nl> Returns : <nl> ` torch . jit . Future [ T ] ` : a reference to the execution of ` func ` . The value ` T ` <nl> can only be accessed by forcing completion of ` func ` through ` torch . jit . wait ` . <nl> Example ( fork a free function ) : <nl> + <nl> . . testcode : : <nl> import torch <nl> from torch import Tensor <nl> def bar ( a ) : <nl> # trace is not run asynchronously , but fork is captured in IR <nl> graph = torch . jit . trace ( bar , ( input , ) ) . graph <nl> assert " fork " in str ( graph ) <nl> + <nl> Example ( fork a module method ) : <nl> + <nl> . . testcode : : <nl> import torch <nl> from torch import Tensor <nl> def freeze ( mod , preserved_attrs : Optional [ List [ str ] ] = None ) : <nl> Frozen : class : ` ScriptModule ` . <nl> <nl> Example ( Freezing a simple module with a Parameter ) : <nl> + <nl> . . testcode : : <nl> import torch <nl> class MyModule ( torch . nn . Module ) : <nl> def forward ( self , input ) : <nl> print ( frozen_module . code ) <nl> <nl> Example ( Freezing a module with preserved attributes ) <nl> + <nl> . . testcode : : <nl> import torch <nl> class MyModule2 ( torch . nn . Module ) : <nl> def _reconstruct ( self , cpp_module ) : <nl> def graph ( self ) : <nl> r " " " <nl> Returns a string representation of the internal graph for the <nl> - ` ` forward ` ` method . See ` Interpreting Graphs ` _ for details . <nl> + ` ` forward ` ` method . See ` interpreting - graphs ` for details . <nl> " " " <nl> return self . forward . graph <nl> <nl> def inlined_graph ( self ) : <nl> r " " " <nl> Returns a string representation of the internal graph for the <nl> ` ` forward ` ` method . This graph will be preprocessed to inline all function and method calls . <nl> - See ` Interpreting Graphs ` _ for details . <nl> + See ` interpreting - graphs ` for details . <nl> " " " <nl> return self . forward . inlined_graph <nl> <nl> def inlined_graph ( self ) : <nl> def code ( self ) : <nl> r " " " <nl> Returns a pretty - printed representation ( as valid Python syntax ) of <nl> - the internal graph for the ` ` forward ` ` method . See ` Inspecting Code ` _ <nl> + the internal graph for the ` ` forward ` ` method . See ` inspecting - code ` <nl> for details . <nl> " " " <nl> return self . forward . code <nl> def code_with_constants ( self ) : <nl> [ 1 ] a ConstMap following the CONSTANT . cN format of the output in [ 0 ] . <nl> The indices in the [ 0 ] output are keys to the underlying constant ' s values . <nl> <nl> - See ` Inspecting Code ` _ for details . <nl> + See ` inspecting - code ` for details . <nl> " " " <nl> r = self . forward . code_with_constants <nl> return ( r [ 0 ] , ConstMap ( r [ 1 ] ) ) <nl> mmm a / torch / jit / _trace . py <nl> ppp b / torch / jit / _trace . py <nl> def trace ( <nl> single Tensor in which case it is automatically wrapped in a tuple . <nl> <nl> Keyword arguments : <nl> - check_trace ( bool , optional ) : Check if the same inputs run through <nl> + check_trace ( ` ` bool ` ` , optional ) : Check if the same inputs run through <nl> traced code produce the same outputs . Default : ` ` True ` ` . You might want <nl> to disable this if , for example , your network contains non - <nl> deterministic ops or if you are sure that the network is correct despite <nl> def trace ( <nl> to use in the checker procedure . This can be used to relax the <nl> checker strictness in the event that results diverge numerically <nl> for a known reason , such as operator fusion . <nl> - strict ( bool , optional ) : run the tracer in a strict mode or not <nl> + strict ( ` ` bool ` ` , optional ) : run the tracer in a strict mode or not <nl> ( default : ` ` True ` ` ) . Only turn this off when you want the tracer to <nl> record your mutable container types ( currently ` ` list ` ` / ` ` dict ` ` ) <nl> and you are sure that the containuer you are using in your <nl> mmm a / torch / jit / supported_ops . py <nl> ppp b / torch / jit / supported_ops . py <nl> def _get_global_builtins ( ) : <nl> <nl> magic_methods_rows = [ ] <nl> for fn , magic_method in magic_methods : <nl> - magic_methods_rows . append ( ' " : any : ` { } ` " , " ` ` { } ` ` " ' . format ( fn , magic_method ) ) <nl> + magic_methods_rows . append ( ' " { } " , " ` ` { } ` ` " ' . format ( fn , magic_method ) ) <nl> <nl> schematized_ops = [ ] <nl> schemaless_ops = [ ] <nl> def _get_global_builtins ( ) : <nl> <nl> { } <nl> <nl> - These built - in functions do have a schema <nl> + These built - in functions use the schema <nl> <nl> . . rst - class : : codeblock - height - limiter <nl> <nl> mmm a / torch / nn / modules / conv . py <nl> ppp b / torch / nn / modules / conv . py <nl> class ConvTranspose1d ( _ConvTransposeNd ) : <nl> If : attr : ` bias ` is ` ` True ` ` , then the values of these weights are <nl> sampled from : math : ` \ mathcal { U } ( - \ sqrt { k } , \ sqrt { k } ) ` where <nl> : math : ` k = \ frac { groups } { C_ \ text { out } * \ text { kernel \ _size } } ` <nl> + <nl> + . . _cross - correlation : <nl> + https : / / en . wikipedia . org / wiki / Cross - correlation <nl> + <nl> + . . _link : <nl> + https : / / github . com / vdumoulin / conv_arithmetic / blob / master / README . md <nl> " " " <nl> <nl> def __init__ ( <nl> mmm a / torch / nn / utils / prune . py <nl> ppp b / torch / nn / utils / prune . py <nl> def compute_mask ( self , t , default_mask ) : <nl> that were not zeroed out by the ` ` default_mask ` ` . <nl> Which portions of the tensor ` ` t ` ` the new mask will be calculated from <nl> depends on the ` ` PRUNING_TYPE ` ` ( handled by the type handler ) : <nl> - * for ' unstructured ' , the mask will be computed from the raveled <nl> - list of nonmasked entries ; <nl> <nl> - * for ' structured ' , the mask will be computed from the nonmasked <nl> - channels in the tensor ; <nl> + * for ' unstructured ' , the mask will be computed from the raveled <nl> + list of nonmasked entries ; <nl> <nl> - * for ' global ' , the mask will be computed across all entries . <nl> + * for ' structured ' , the mask will be computed from the nonmasked <nl> + channels in the tensor ; <nl> + <nl> + * for ' global ' , the mask will be computed across all entries . <nl> <nl> Args : <nl> t ( torch . Tensor ) : tensor representing the parameter to prune <nl> mmm a / torch / onnx / __init__ . py <nl> ppp b / torch / onnx / __init__ . py <nl> def export ( model , args , f , export_params = True , verbose = False , training = TrainingM <nl> OperatorExportTypes . ONNX_ATEN_FALLBACK : If an ATen op is not supported <nl> in ONNX or its symbolic is missing , fall back on ATen op . Registered ops <nl> are exported to ONNX regularly . <nl> - Example graph : <nl> - graph ( % 0 : Float ) : <nl> + Example graph : : <nl> + <nl> + graph ( % 0 : Float ) : : <nl> % 3 : int = prim : : Constant [ value = 0 ] ( ) <nl> % 4 : Float = aten : : triu ( % 0 , % 3 ) # missing op <nl> % 5 : Float = aten : : mul ( % 4 , % 0 ) # registered op <nl> return ( % 5 ) <nl> - is exported as : <nl> - graph ( % 0 : Float ) : <nl> + <nl> + is exported as : : <nl> + <nl> + graph ( % 0 : Float ) : : <nl> % 1 : Long ( ) = onnx : : Constant [ value = { 0 } ] ( ) <nl> % 2 : Float = aten : : ATen [ operator = " triu " ] ( % 0 , % 1 ) # missing op <nl> % 3 : Float = onnx : : Mul ( % 2 , % 0 ) # registered op <nl> return ( % 3 ) <nl> + <nl> In the above example , aten : : triu is not supported in ONNX , hence <nl> exporter falls back on this op . <nl> OperatorExportTypes . RAW : Export raw ir . <nl> def export ( model , args , f , export_params = True , verbose = False , training = TrainingM <nl> in ONNX , fall through and export the operator as is , as a custom <nl> ONNX op . Using this mode , the op can be exported and implemented by <nl> the user for their runtime backend . <nl> - Example graph : <nl> - graph ( % x . 1 : Long ( 1 : 1 ) ) : <nl> + Example graph : : <nl> + <nl> + graph ( % x . 1 : Long ( 1 : 1 ) ) : : <nl> % 1 : None = prim : : Constant ( ) <nl> % 2 : Tensor = aten : : sum ( % x . 1 , % 1 ) <nl> % y . 1 : Tensor [ ] = prim : : ListConstruct ( % 2 ) <nl> return ( % y . 1 ) <nl> - is exported as : <nl> - graph ( % x . 1 : Long ( 1 : 1 ) ) : <nl> + <nl> + is exported as : : <nl> + <nl> + graph ( % x . 1 : Long ( 1 : 1 ) ) : : <nl> % 1 : Tensor = onnx : : ReduceSum [ keepdims = 0 ] ( % x . 1 ) <nl> % y . 1 : Long ( ) = prim : : ListConstruct ( % 1 ) <nl> return ( % y . 1 ) <nl> + <nl> In the above example , prim : : ListConstruct is not supported , hence <nl> exporter falls through . <nl> <nl> def export ( model , args , f , export_params = True , verbose = False , training = TrainingM <nl> and shape ( input_2 ) = ( ' b ' , 4 ) <nl> and shape ( output ) = ( ' b ' , ' d ' , 5 ) <nl> <nl> - Then dynamic axes can be defined either as : <nl> - ( a ) . ONLY INDICES : <nl> - dynamic_axes = { ' input_1 ' : [ 0 , 2 , 3 ] , ' input_2 ' : [ 0 ] , ' output ' : [ 0 , 1 ] } <nl> - <nl> - where automatic names will be generated for exported dynamic axes <nl> - <nl> - ( b ) . INDICES WITH CORRESPONDING NAMES : <nl> - dynamic_axes = { ' input_1 ' : { 0 : ' batch ' , 1 : ' width ' , 2 : ' height ' } , <nl> - ' input_2 ' : { 0 : ' batch ' } , <nl> - ' output ' : { 0 : ' batch ' , 1 : ' detections ' } <nl> - <nl> - where provided names will be applied to exported dynamic axes <nl> - <nl> - ( c ) . MIXED MODE OF ( a ) and ( b ) <nl> - dynamic_axes = { ' input_1 ' : [ 0 , 2 , 3 ] , ' input_2 ' : { 0 : ' batch ' } , ' output ' : [ 0 , 1 ] } <nl> - keep_initializers_as_inputs ( bool , default None ) : If True , all the initializers <nl> - ( typically corresponding to parameters ) in the exported graph will also be <nl> - added as inputs to the graph . If False , then initializers are not added as <nl> - inputs to the graph , and only the non - parameter inputs are added as inputs . <nl> - This may allow for better optimizations ( such as constant folding etc . ) by <nl> - backends / runtimes that execute these graphs . If unspecified ( default None ) , <nl> - then the behavior is chosen automatically as follows . If operator_export_type <nl> - is OperatorExportTypes . ONNX , the behavior is equivalent to setting this <nl> - argument to False . For other values of operator_export_type , the behavior is <nl> - equivalent to setting this argument to True . Note that for ONNX opset version < 9 , <nl> - initializers MUST be part of graph inputs . Therefore , if opset_version argument is <nl> - set to a 8 or lower , this argument will be ignored . <nl> + Then ` dynamic axes ` can be defined either as : <nl> + <nl> + 1 . ONLY INDICES : : <nl> + <nl> + ` ` dynamic_axes = { ' input_1 ' : [ 0 , 2 , 3 ] , <nl> + ' input_2 ' : [ 0 ] , <nl> + ' output ' : [ 0 , 1 ] } ` ` <nl> + where automatic names will be generated for exported dynamic axes <nl> + <nl> + 2 . INDICES WITH CORRESPONDING NAMES : : <nl> + <nl> + ` ` dynamic_axes = { ' input_1 ' : { 0 : ' batch ' , <nl> + 1 : ' width ' , <nl> + 2 : ' height ' } , <nl> + ' input_2 ' : { 0 : ' batch ' } , <nl> + ' output ' : { 0 : ' batch ' , <nl> + 1 : ' detections ' } ` ` <nl> + where provided names will be applied to exported dynamic axes <nl> + <nl> + 3 . MIXED MODE OF ( 1 ) and ( 2 ) : : <nl> + <nl> + ` ` dynamic_axes = { ' input_1 ' : [ 0 , 2 , 3 ] , <nl> + ' input_2 ' : { 0 : ' batch ' } , <nl> + ' output ' : [ 0 , 1 ] } ` ` <nl> + <nl> + keep_initializers_as_inputs ( bool , default None ) : If True , all the <nl> + initializers ( typically corresponding to parameters ) in the <nl> + exported graph will also be added as inputs to the graph . If False , <nl> + then initializers are not added as inputs to the graph , and only <nl> + the non - parameter inputs are added as inputs . <nl> + <nl> + This may allow for better optimizations ( such as constant folding <nl> + etc . ) by backends / runtimes that execute these graphs . If <nl> + unspecified ( default None ) , then the behavior is chosen <nl> + automatically as follows . If operator_export_type is <nl> + OperatorExportTypes . ONNX , the behavior is equivalent to setting <nl> + this argument to False . For other values of operator_export_type , <nl> + the behavior is equivalent to setting this argument to True . Note <nl> + that for ONNX opset version < 9 , initializers MUST be part of graph <nl> + inputs . Therefore , if opset_version argument is set to a 8 or <nl> + lower , this argument will be ignored . <nl> custom_opsets ( dict < string , int > , default empty dict ) : A dictionary to indicate <nl> custom opset domain and version at export . If model contains a custom opset , <nl> it is optional to specify the domain and opset version in the dictionary : <nl> mmm a / torch / serialization . py <nl> ppp b / torch / serialization . py <nl> def save ( obj , f : Union [ str , os . PathLike , BinaryIO ] , <nl> A common PyTorch convention is to save tensors using . pt file extension . <nl> <nl> . . note : : <nl> - PyTorch preserves storage sharing across serialization . See : ref : ` preserve - storage - sharing ` <nl> - for more details . <nl> + PyTorch preserves storage sharing across serialization . See <nl> + ` preserve - storage - sharing ` for more details . <nl> <nl> . . note : : <nl> The 1 . 6 release of PyTorch switched ` ` torch . save ` ` to use a new <nl>
|
Doc warnings ( )
|
pytorch/pytorch
|
75155df8b4a1e87e22b6778a51619d9faf7c64f5
|
2020-07-07T18:43:21Z
|
mmm a / src / video_core / memory_manager . cpp <nl> ppp b / src / video_core / memory_manager . cpp <nl> MemoryManager : : MemoryManager ( ) { <nl> } <nl> <nl> GPUVAddr MemoryManager : : AllocateSpace ( u64 size , u64 align ) { <nl> + const u64 aligned_size { Common : : AlignUp ( size , page_size ) } ; <nl> const GPUVAddr gpu_addr { <nl> - FindFreeRegion ( address_space_base , size , align , VirtualMemoryArea : : Type : : Unmapped ) } ; <nl> - AllocateMemory ( gpu_addr , 0 , size ) ; <nl> + FindFreeRegion ( address_space_base , aligned_size , align , VirtualMemoryArea : : Type : : Unmapped ) } ; <nl> + <nl> + AllocateMemory ( gpu_addr , 0 , aligned_size ) ; <nl> + <nl> return gpu_addr ; <nl> } <nl> <nl> GPUVAddr MemoryManager : : AllocateSpace ( GPUVAddr gpu_addr , u64 size , u64 align ) { <nl> - AllocateMemory ( gpu_addr , 0 , size ) ; <nl> + const u64 aligned_size { Common : : AlignUp ( size , page_size ) } ; <nl> + <nl> + AllocateMemory ( gpu_addr , 0 , aligned_size ) ; <nl> + <nl> return gpu_addr ; <nl> } <nl> <nl> GPUVAddr MemoryManager : : MapBufferEx ( VAddr cpu_addr , u64 size ) { <nl> - const GPUVAddr gpu_addr { <nl> - FindFreeRegion ( address_space_base , size , page_size , VirtualMemoryArea : : Type : : Unmapped ) } ; <nl> - MapBackingMemory ( gpu_addr , Memory : : GetPointer ( cpu_addr ) , ( ( size + page_mask ) & ~ page_mask ) , <nl> - cpu_addr ) ; <nl> + const u64 aligned_size { Common : : AlignUp ( size , page_size ) } ; <nl> + const GPUVAddr gpu_addr { FindFreeRegion ( address_space_base , aligned_size , page_size , <nl> + VirtualMemoryArea : : Type : : Unmapped ) } ; <nl> + <nl> + MapBackingMemory ( gpu_addr , Memory : : GetPointer ( cpu_addr ) , aligned_size , cpu_addr ) ; <nl> + <nl> return gpu_addr ; <nl> } <nl> <nl> GPUVAddr MemoryManager : : MapBufferEx ( VAddr cpu_addr , GPUVAddr gpu_addr , u64 size ) { <nl> ASSERT ( ( gpu_addr & page_mask ) = = 0 ) ; <nl> <nl> - MapBackingMemory ( gpu_addr , Memory : : GetPointer ( cpu_addr ) , ( ( size + page_mask ) & ~ page_mask ) , <nl> - cpu_addr ) ; <nl> + const u64 aligned_size { Common : : AlignUp ( size , page_size ) } ; <nl> + <nl> + MapBackingMemory ( gpu_addr , Memory : : GetPointer ( cpu_addr ) , aligned_size , cpu_addr ) ; <nl> <nl> return gpu_addr ; <nl> } <nl> GPUVAddr MemoryManager : : MapBufferEx ( VAddr cpu_addr , GPUVAddr gpu_addr , u64 size ) <nl> GPUVAddr MemoryManager : : UnmapBuffer ( GPUVAddr gpu_addr , u64 size ) { <nl> ASSERT ( ( gpu_addr & page_mask ) = = 0 ) ; <nl> <nl> + const u64 aligned_size { Common : : AlignUp ( size , page_size ) } ; <nl> const CacheAddr cache_addr { ToCacheAddr ( GetPointer ( gpu_addr ) ) } ; <nl> - Core : : System : : GetInstance ( ) . Renderer ( ) . Rasterizer ( ) . FlushAndInvalidateRegion ( cache_addr , size ) ; <nl> <nl> - UnmapRange ( gpu_addr , ( ( size + page_mask ) & ~ page_mask ) ) ; <nl> + Core : : System : : GetInstance ( ) . Renderer ( ) . Rasterizer ( ) . FlushAndInvalidateRegion ( cache_addr , <nl> + aligned_size ) ; <nl> + UnmapRange ( gpu_addr , aligned_size ) ; <nl> <nl> return gpu_addr ; <nl> } <nl>
|
memory_manager : Use Common : : AlignUp in public interface as needed .
|
yuzu-emu/yuzu
|
5a5fccaa23f8670d85666efd6ea12b42883c4edc
|
2019-03-21T02:58:49Z
|
mmm a / src / mips / builtins - mips . cc <nl> ppp b / src / mips / builtins - mips . cc <nl> void Builtins : : Generate_OnStackReplacement ( MacroAssembler * masm ) { <nl> } <nl> <nl> <nl> + void Builtins : : Generate_OsrAfterStackCheck ( MacroAssembler * masm ) { <nl> + / / We check the stack limit as indicator that recompilation might be done . <nl> + Label ok ; <nl> + __ LoadRoot ( at , Heap : : kStackLimitRootIndex ) ; <nl> + __ Branch ( & ok , hs , sp , Operand ( at ) ) ; <nl> + { <nl> + FrameScope scope ( masm , StackFrame : : INTERNAL ) ; <nl> + __ CallRuntime ( Runtime : : kStackGuard , 0 ) ; <nl> + } <nl> + __ Jump ( masm - > isolate ( ) - > builtins ( ) - > OnStackReplacement ( ) , <nl> + RelocInfo : : CODE_TARGET ) ; <nl> + <nl> + __ bind ( & ok ) ; <nl> + __ Ret ( ) ; <nl> + } <nl> + <nl> + <nl> void Builtins : : Generate_FunctionCall ( MacroAssembler * masm ) { <nl> / / 1 . Make sure we have at least one argument . <nl> / / a0 : actual number of arguments <nl> mmm a / src / mips / full - codegen - mips . cc <nl> ppp b / src / mips / full - codegen - mips . cc <nl> FullCodeGenerator : : NestedStatement * FullCodeGenerator : : TryFinally : : Exit ( <nl> # undef __ <nl> <nl> <nl> - / / This structure comes from FullCodeGenerator : : EmitBackEdgeBookkeeping . <nl> - / / The back edge bookkeeping code matches the pattern : <nl> - / / <nl> - / / sltu at , sp , t0 / slt at , a3 , zero_reg ( in case of count based interrupts ) <nl> - / / beq at , zero_reg , ok <nl> - / / lui t9 , < interrupt stub address > upper <nl> - / / ori t9 , < interrupt stub address > lower <nl> - / / jalr t9 <nl> - / / nop <nl> - / / ok - label mmm - - pc_after points here <nl> - / / <nl> - / / We patch the code to the following form : <nl> - / / <nl> - / / addiu at , zero_reg , 1 <nl> - / / beq at , zero_reg , ok ; ; Not changed <nl> - / / lui t9 , < on - stack replacement address > upper <nl> - / / ori t9 , < on - stack replacement address > lower <nl> - / / jalr t9 ; ; Not changed <nl> - / / nop ; ; Not changed <nl> - / / ok - label mmm - - pc_after points here <nl> - <nl> void BackEdgeTable : : PatchAt ( Code * unoptimized_code , <nl> - Address pc_after , <nl> + Address pc , <nl> + BackEdgeState target_state , <nl> Code * replacement_code ) { <nl> static const int kInstrSize = Assembler : : kInstrSize ; <nl> - / / Replace the sltu instruction with load - imm 1 to at , so beq is not taken . <nl> - CodePatcher patcher ( pc_after - 6 * kInstrSize , 1 ) ; <nl> - patcher . masm ( ) - > addiu ( at , zero_reg , 1 ) ; <nl> + Address branch_address = pc - 6 * kInstrSize ; <nl> + CodePatcher patcher ( branch_address , 1 ) ; <nl> + <nl> + switch ( target_state ) { <nl> + case INTERRUPT : <nl> + / / slt at , a3 , zero_reg ( in case of count based interrupts ) <nl> + / / beq at , zero_reg , ok <nl> + / / lui t9 , < interrupt stub address > upper <nl> + / / ori t9 , < interrupt stub address > lower <nl> + / / jalr t9 <nl> + / / nop <nl> + / / ok - label mmm - - pc_after points here <nl> + patcher . masm ( ) - > slt ( at , a3 , zero_reg ) ; <nl> + break ; <nl> + case ON_STACK_REPLACEMENT : <nl> + case OSR_AFTER_STACK_CHECK : <nl> + / / addiu at , zero_reg , 1 <nl> + / / beq at , zero_reg , ok ; ; Not changed <nl> + / / lui t9 , < on - stack replacement address > upper <nl> + / / ori t9 , < on - stack replacement address > lower <nl> + / / jalr t9 ; ; Not changed <nl> + / / nop ; ; Not changed <nl> + / / ok - label mmm - - pc_after points here <nl> + patcher . masm ( ) - > addiu ( at , zero_reg , 1 ) ; <nl> + break ; <nl> + } <nl> + Address pc_immediate_load_address = pc - 4 * kInstrSize ; <nl> / / Replace the stack check address in the load - immediate ( lui / ori pair ) <nl> / / with the entry address of the replacement code . <nl> - Assembler : : set_target_address_at ( pc_after - 4 * kInstrSize , <nl> + Assembler : : set_target_address_at ( pc_immediate_load_address , <nl> replacement_code - > entry ( ) ) ; <nl> <nl> unoptimized_code - > GetHeap ( ) - > incremental_marking ( ) - > RecordCodeTargetPatch ( <nl> - unoptimized_code , pc_after - 4 * kInstrSize , replacement_code ) ; <nl> - } <nl> - <nl> - <nl> - void BackEdgeTable : : RevertAt ( Code * unoptimized_code , <nl> - Address pc_after , <nl> - Code * interrupt_code ) { <nl> - static const int kInstrSize = Assembler : : kInstrSize ; <nl> - / / Restore the sltu instruction so beq can be taken again . <nl> - CodePatcher patcher ( pc_after - 6 * kInstrSize , 1 ) ; <nl> - patcher . masm ( ) - > slt ( at , a3 , zero_reg ) ; <nl> - / / Restore the original call address . <nl> - Assembler : : set_target_address_at ( pc_after - 4 * kInstrSize , <nl> - interrupt_code - > entry ( ) ) ; <nl> - <nl> - interrupt_code - > GetHeap ( ) - > incremental_marking ( ) - > RecordCodeTargetPatch ( <nl> - unoptimized_code , pc_after - 4 * kInstrSize , interrupt_code ) ; <nl> + unoptimized_code , pc_immediate_load_address , replacement_code ) ; <nl> } <nl> <nl> <nl> - # ifdef DEBUG <nl> BackEdgeTable : : BackEdgeState BackEdgeTable : : GetBackEdgeState ( <nl> Isolate * isolate , <nl> Code * unoptimized_code , <nl> - Address pc_after ) { <nl> + Address pc ) { <nl> static const int kInstrSize = Assembler : : kInstrSize ; <nl> - ASSERT ( Assembler : : IsBeq ( Assembler : : instr_at ( pc_after - 5 * kInstrSize ) ) ) ; <nl> - if ( Assembler : : IsAddImmediate ( <nl> - Assembler : : instr_at ( pc_after - 6 * kInstrSize ) ) ) { <nl> - Code * osr_builtin = <nl> - isolate - > builtins ( ) - > builtin ( Builtins : : kOnStackReplacement ) ; <nl> - ASSERT ( reinterpret_cast < uint32_t > ( <nl> - Assembler : : target_address_at ( pc_after - 4 * kInstrSize ) ) = = <nl> - reinterpret_cast < uint32_t > ( osr_builtin - > entry ( ) ) ) ; <nl> - return ON_STACK_REPLACEMENT ; <nl> - } else { <nl> - / / Get the interrupt stub code object to match against from cache . <nl> - Code * interrupt_builtin = <nl> - isolate - > builtins ( ) - > builtin ( Builtins : : kInterruptCheck ) ; <nl> + Address branch_address = pc - 6 * kInstrSize ; <nl> + Address pc_immediate_load_address = pc - 4 * kInstrSize ; <nl> + <nl> + ASSERT ( Assembler : : IsBeq ( Assembler : : instr_at ( pc - 5 * kInstrSize ) ) ) ; <nl> + if ( ! Assembler : : IsAddImmediate ( Assembler : : instr_at ( branch_address ) ) ) { <nl> ASSERT ( reinterpret_cast < uint32_t > ( <nl> - Assembler : : target_address_at ( pc_after - 4 * kInstrSize ) ) = = <nl> - reinterpret_cast < uint32_t > ( interrupt_builtin - > entry ( ) ) ) ; <nl> + Assembler : : target_address_at ( pc_immediate_load_address ) ) = = <nl> + reinterpret_cast < uint32_t > ( <nl> + isolate - > builtins ( ) - > InterruptCheck ( ) - > entry ( ) ) ) ; <nl> return INTERRUPT ; <nl> } <nl> + <nl> + ASSERT ( Assembler : : IsAddImmediate ( Assembler : : instr_at ( branch_address ) ) ) ; <nl> + <nl> + if ( reinterpret_cast < uint32_t > ( <nl> + Assembler : : target_address_at ( pc_immediate_load_address ) ) = = <nl> + reinterpret_cast < uint32_t > ( <nl> + isolate - > builtins ( ) - > OnStackReplacement ( ) - > entry ( ) ) ) { <nl> + return ON_STACK_REPLACEMENT ; <nl> + } <nl> + <nl> + ASSERT ( reinterpret_cast < uint32_t > ( <nl> + Assembler : : target_address_at ( pc_immediate_load_address ) ) = = <nl> + reinterpret_cast < uint32_t > ( <nl> + isolate - > builtins ( ) - > OsrAfterStackCheck ( ) - > entry ( ) ) ) ; <nl> + return OSR_AFTER_STACK_CHECK ; <nl> } <nl> - # endif / / DEBUG <nl> <nl> <nl> } } / / namespace v8 : : internal <nl>
|
MIPS : Less aggressive polling when concurrently compiling for OSR .
|
v8/v8
|
9c455ab79dacbae02ad27b0daf0c5b1735ad2111
|
2013-09-25T16:27:52Z
|
mmm a / src / base / LICENSE . txt <nl> ppp b / src / base / LICENSE . txt <nl> <nl> - Copyright ( c ) 2001 - 2013 David Capello <nl> + Copyright ( c ) 2001 - 2014 David Capello <nl> <nl> Permission is hereby granted , free of charge , to any person obtaining <nl> a copy of this software and associated documentation files ( the <nl> mmm a / src / base / bind . h <nl> ppp b / src / base / bind . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_BIND_H_INCLUDED <nl> # define BASE_BIND_H_INCLUDED <nl> mmm a / src / base / cfile . cpp <nl> ppp b / src / base / cfile . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / cfile . h <nl> ppp b / src / base / cfile . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_CFILE_H_INCLUDED <nl> # define BASE_CFILE_H_INCLUDED <nl> mmm a / src / base / chrono . cpp <nl> ppp b / src / base / chrono . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / chrono . h <nl> ppp b / src / base / chrono . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_CHRONO_H_INCLUDED <nl> # define BASE_CHRONO_H_INCLUDED <nl> mmm a / src / base / chrono_unix . h <nl> ppp b / src / base / chrono_unix . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < time . h > <nl> # include < sys / time . h > <nl> mmm a / src / base / chrono_win32 . h <nl> ppp b / src / base / chrono_win32 . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # define WIN32_LEAN_AND_MEAN <nl> # include < windows . h > <nl> mmm a / src / base / clamp . h <nl> ppp b / src / base / clamp . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_CLAMP_H_INCLUDED <nl> # define BASE_CLAMP_H_INCLUDED <nl> mmm a / src / base / compiler_specific . h <nl> ppp b / src / base / compiler_specific . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_COMPILER_SPECIFIC_H_INCLUDED <nl> # define BASE_COMPILER_SPECIFIC_H_INCLUDED <nl> mmm a / src / base / convert_to . cpp <nl> ppp b / src / base / convert_to . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / convert_to . h <nl> ppp b / src / base / convert_to . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_CONVERT_TO_H_INCLUDED <nl> # define BASE_CONVERT_TO_H_INCLUDED <nl> mmm a / src / base / disable_copying . h <nl> ppp b / src / base / disable_copying . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_DISABLE_COPYING_H_INCLUDED <nl> # define BASE_DISABLE_COPYING_H_INCLUDED <nl> mmm a / src / base / errno_string . cpp <nl> ppp b / src / base / errno_string . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / errno_string . h <nl> ppp b / src / base / errno_string . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_ERRNO_STRING_H_INCLUDED <nl> # define BASE_ERRNO_STRING_H_INCLUDED <nl> mmm a / src / base / exception . cpp <nl> ppp b / src / base / exception . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / exception . h <nl> ppp b / src / base / exception . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_EXCEPTION_H_INCLUDED <nl> # define BASE_EXCEPTION_H_INCLUDED <nl> mmm a / src / base / file_handle . cpp <nl> ppp b / src / base / file_handle . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / file_handle . h <nl> ppp b / src / base / file_handle . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_OPEN_FILE_H_INCLUDED <nl> # define BASE_OPEN_FILE_H_INCLUDED <nl> mmm a / src / base / file_handle_unittest . cpp <nl> ppp b / src / base / file_handle_unittest . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < gtest / gtest . h > <nl> <nl> mmm a / src / base / fs . cpp <nl> ppp b / src / base / fs . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / fs . h <nl> ppp b / src / base / fs . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_FS_H_INCLUDED <nl> # define BASE_FS_H_INCLUDED <nl> mmm a / src / base / fs_unix . h <nl> ppp b / src / base / fs_unix . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < sys / types . h > <nl> # include < sys / stat . h > <nl> mmm a / src / base / fs_win32 . h <nl> ppp b / src / base / fs_win32 . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < stdexcept > <nl> # include < windows . h > <nl> mmm a / src / base / launcher . cpp <nl> ppp b / src / base / launcher . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / launcher . h <nl> ppp b / src / base / launcher . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_LAUNCHER_H_INCLUDED <nl> # define BASE_LAUNCHER_H_INCLUDED <nl> mmm a / src / base / mem_utils . cpp <nl> ppp b / src / base / mem_utils . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / mem_utils . h <nl> ppp b / src / base / mem_utils . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_MEM_UTILS_H_INCLUDED <nl> # define BASE_MEM_UTILS_H_INCLUDED <nl> mmm a / src / base / memory . cpp <nl> ppp b / src / base / memory . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / memory . h <nl> ppp b / src / base / memory . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_MEMORY_H_INCLUDED <nl> # define BASE_MEMORY_H_INCLUDED <nl> mmm a / src / base / memory_dump . cpp <nl> ppp b / src / base / memory_dump . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / memory_dump . h <nl> ppp b / src / base / memory_dump . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_MEMORY_DUMP_H_INCLUDED <nl> # define BASE_MEMORY_DUMP_H_INCLUDED <nl> mmm a / src / base / memory_dump_none . h <nl> ppp b / src / base / memory_dump_none . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_MEMORY_DUMP_NONE_H_INCLUDED <nl> # define BASE_MEMORY_DUMP_NONE_H_INCLUDED <nl> mmm a / src / base / memory_dump_win32 . h <nl> ppp b / src / base / memory_dump_win32 . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_MEMORY_DUMP_WIN32_H_INCLUDED <nl> # define BASE_MEMORY_DUMP_WIN32_H_INCLUDED <nl> mmm a / src / base / mutex . cpp <nl> ppp b / src / base / mutex . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / mutex . h <nl> ppp b / src / base / mutex . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_MUTEX_H_INCLUDED <nl> # define BASE_MUTEX_H_INCLUDED <nl> mmm a / src / base / mutex_pthread . h <nl> ppp b / src / base / mutex_pthread . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_MUTEX_PTHREAD_H_INCLUDED <nl> # define BASE_MUTEX_PTHREAD_H_INCLUDED <nl> mmm a / src / base / mutex_win32 . h <nl> ppp b / src / base / mutex_win32 . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_MUTEX_WIN32_H_INCLUDED <nl> # define BASE_MUTEX_WIN32_H_INCLUDED <nl> mmm a / src / base / observable . h <nl> ppp b / src / base / observable . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_OBSERVABLE_H_INCLUDED <nl> # define BASE_OBSERVABLE_H_INCLUDED <nl> mmm a / src / base / observers . h <nl> ppp b / src / base / observers . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_OBSERVERS_H_INCLUDED <nl> # define BASE_OBSERVERS_H_INCLUDED <nl> mmm a / src / base / path . cpp <nl> ppp b / src / base / path . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / path . h <nl> ppp b / src / base / path . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_PATH_H_INCLUDED <nl> # define BASE_PATH_H_INCLUDED <nl> mmm a / src / base / path_unittest . cpp <nl> ppp b / src / base / path_unittest . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < gtest / gtest . h > <nl> <nl> mmm a / src / base / program_options . cpp <nl> ppp b / src / base / program_options . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / program_options . h <nl> ppp b / src / base / program_options . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_PROGRAM_OPTIONS_H_INCLUDED <nl> # define BASE_PROGRAM_OPTIONS_H_INCLUDED <nl> mmm a / src / base / program_options_unittest . cpp <nl> ppp b / src / base / program_options_unittest . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < gtest / gtest . h > <nl> <nl> mmm a / src / base / recent_items . h <nl> ppp b / src / base / recent_items . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_RECENT_ITEMS_H_INCLUDED <nl> # define BASE_RECENT_ITEMS_H_INCLUDED <nl> mmm a / src / base / remove_from_container . h <nl> ppp b / src / base / remove_from_container . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_REMOVE_FROM_CONTAINER_H_INCLUDED <nl> # define BASE_REMOVE_FROM_CONTAINER_H_INCLUDED <nl> mmm a / src / base / scoped_lock . h <nl> ppp b / src / base / scoped_lock . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_SCOPED_LOCK_H_INCLUDED <nl> # define BASE_SCOPED_LOCK_H_INCLUDED <nl> mmm a / src / base / serialization . cpp <nl> ppp b / src / base / serialization . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / serialization . h <nl> ppp b / src / base / serialization . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_SERIALIZATION_H_INCLUDED <nl> # define BASE_SERIALIZATION_H_INCLUDED <nl> mmm a / src / base / sha1 . cpp <nl> ppp b / src / base / sha1 . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / sha1 . h <nl> ppp b / src / base / sha1 . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_SHA1_H_INCLUDED <nl> # define BASE_SHA1_H_INCLUDED <nl> mmm a / src / base / shared_ptr . h <nl> ppp b / src / base / shared_ptr . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_SHARED_PTR_H_INCLUDED <nl> # define BASE_SHARED_PTR_H_INCLUDED <nl> mmm a / src / base / shared_ptr_unittest . cpp <nl> ppp b / src / base / shared_ptr_unittest . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < gtest / gtest . h > <nl> <nl> mmm a / src / base / signal . h <nl> ppp b / src / base / signal . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_SIGNAL_H_INCLUDED <nl> # define BASE_SIGNAL_H_INCLUDED <nl> mmm a / src / base / slot . h <nl> ppp b / src / base / slot . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_SLOT_H_INCLUDED <nl> # define BASE_SLOT_H_INCLUDED <nl> mmm a / src / base / split_string . cpp <nl> ppp b / src / base / split_string . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / split_string . h <nl> ppp b / src / base / split_string . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_SPLIT_STRING_H_INCLUDED <nl> # define BASE_SPLIT_STRING_H_INCLUDED <nl> mmm a / src / base / split_string_unittest . cpp <nl> ppp b / src / base / split_string_unittest . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < gtest / gtest . h > <nl> <nl> mmm a / src / base / string . cpp <nl> ppp b / src / base / string . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / string . h <nl> ppp b / src / base / string . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_STRING_H_INCLUDED <nl> # define BASE_STRING_H_INCLUDED <nl> mmm a / src / base / string_unittest . cpp <nl> ppp b / src / base / string_unittest . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < gtest / gtest . h > <nl> <nl> mmm a / src / base / system_console . cpp <nl> ppp b / src / base / system_console . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / system_console . h <nl> ppp b / src / base / system_console . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_SYSTEM_CONSOLE_H_INCLUDED <nl> # define BASE_SYSTEM_CONSOLE_H_INCLUDED <nl> mmm a / src / base / temp_dir . cpp <nl> ppp b / src / base / temp_dir . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / temp_dir . h <nl> ppp b / src / base / temp_dir . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_TEMP_DIR_H_INCLUDED <nl> # define BASE_TEMP_DIR_H_INCLUDED <nl> mmm a / src / base / thread . cpp <nl> ppp b / src / base / thread . cpp <nl> <nl> - / / ASEPRITE gui library <nl> - / / Copyright ( C ) 2001 - 2013 David Capello <nl> + / / Aseprite Base Library <nl> + / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / thread . h <nl> ppp b / src / base / thread . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_THREAD_H_INCLUDED <nl> # define BASE_THREAD_H_INCLUDED <nl> mmm a / src / base / thread_unittest . cpp <nl> ppp b / src / base / thread_unittest . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < gtest / gtest . h > <nl> <nl> mmm a / src / base / trim_string . cpp <nl> ppp b / src / base / trim_string . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / trim_string . h <nl> ppp b / src / base / trim_string . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_TRIM_STRING_H_INCLUDED <nl> # define BASE_TRIM_STRING_H_INCLUDED <nl> mmm a / src / base / unique_ptr . h <nl> ppp b / src / base / unique_ptr . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_UNIQUE_PTR_H_INCLUDED <nl> # define BASE_UNIQUE_PTR_H_INCLUDED <nl> mmm a / src / base / unique_ptr_unittest . cpp <nl> ppp b / src / base / unique_ptr_unittest . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < gtest / gtest . h > <nl> <nl> mmm a / src / base / vector2d . h <nl> ppp b / src / base / vector2d . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_VECTOR2D_H_INCLUDED <nl> # define BASE_VECTOR2D_H_INCLUDED <nl> mmm a / src / base / version . cpp <nl> ppp b / src / base / version . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / version . h <nl> ppp b / src / base / version . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_VERSION_H_INCLUDED <nl> # define BASE_VERSION_H_INCLUDED <nl> mmm a / src / base / version_unittest . cpp <nl> ppp b / src / base / version_unittest . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < gtest / gtest . h > <nl> <nl> mmm a / src / base / win32_exception . cpp <nl> ppp b / src / base / win32_exception . cpp <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / base / win32_exception . h <nl> ppp b / src / base / win32_exception . h <nl> <nl> / / Aseprite Base Library <nl> / / Copyright ( c ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef BASE_WIN32_EXCEPTION_H_INCLUDED <nl> # define BASE_WIN32_EXCEPTION_H_INCLUDED <nl> mmm a / src / css / compound_style . cpp <nl> ppp b / src / css / compound_style . cpp <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / css / compound_style . h <nl> ppp b / src / css / compound_style . h <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef CSS_COMPOUND_STYLE_H_INCLUDED <nl> # define CSS_COMPOUND_STYLE_H_INCLUDED <nl> mmm a / src / css / css . h <nl> ppp b / src / css / css . h <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef CSS_CSS_H_INCLUDED <nl> # define CSS_CSS_H_INCLUDED <nl> mmm a / src / css / css_unittest . cpp <nl> ppp b / src / css / css_unittest . cpp <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < gtest / gtest . h > <nl> <nl> mmm a / src / css / map . h <nl> ppp b / src / css / map . h <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef CSS_MAP_H_INCLUDED <nl> # define CSS_MAP_H_INCLUDED <nl> mmm a / src / css / query . cpp <nl> ppp b / src / css / query . cpp <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / css / query . h <nl> ppp b / src / css / query . h <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef CSS_QUERY_H_INCLUDED <nl> # define CSS_QUERY_H_INCLUDED <nl> mmm a / src / css / rule . cpp <nl> ppp b / src / css / rule . cpp <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / css / rule . h <nl> ppp b / src / css / rule . h <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef CSS_RULE_H_INCLUDED <nl> # define CSS_RULE_H_INCLUDED <nl> mmm a / src / css / sheet . cpp <nl> ppp b / src / css / sheet . cpp <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / css / sheet . h <nl> ppp b / src / css / sheet . h <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef CSS_SHEET_H_INCLUDED <nl> # define CSS_SHEET_H_INCLUDED <nl> mmm a / src / css / state . h <nl> ppp b / src / css / state . h <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef CSS_STATE_H_INCLUDED <nl> # define CSS_STATE_H_INCLUDED <nl> mmm a / src / css / stateful_style . h <nl> ppp b / src / css / stateful_style . h <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef CSS_STATEFUL_STYLE_H_INCLUDED <nl> # define CSS_STATEFUL_STYLE_H_INCLUDED <nl> mmm a / src / css / style . cpp <nl> ppp b / src / css / style . cpp <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / css / style . h <nl> ppp b / src / css / style . h <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef CSS_STYLE_H_INCLUDED <nl> # define CSS_STYLE_H_INCLUDED <nl> mmm a / src / css / value . cpp <nl> ppp b / src / css / value . cpp <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / css / value . h <nl> ppp b / src / css / value . h <nl> <nl> / / Aseprite CSS Library <nl> / / Copyright ( C ) 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef CSS_VALUE_H_INCLUDED <nl> # define CSS_VALUE_H_INCLUDED <nl> mmm a / src / doc / document . cpp <nl> ppp b / src / doc / document . cpp <nl> <nl> / / Aseprite Document Library <nl> / / Copyright ( c ) 2014 David Capello <nl> / / <nl> - / / This source file is distributed under the terms of the MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / doc / document . h <nl> ppp b / src / doc / document . h <nl> <nl> / / Aseprite Document Library <nl> / / Copyright ( c ) 2014 David Capello <nl> / / <nl> - / / This source file is distributed under the terms of the MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef DOC_DOCUMENT_H_INCLUDED <nl> # define DOC_DOCUMENT_H_INCLUDED <nl> mmm a / src / doc / export_data . h <nl> ppp b / src / doc / export_data . h <nl> <nl> / / Aseprite Document Library <nl> / / Copyright ( c ) 2014 David Capello <nl> / / <nl> - / / This source file is distributed under the terms of the MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef DOC_EXPORT_DATA_H_INCLUDED <nl> # define DOC_EXPORT_DATA_H_INCLUDED <nl> mmm a / src / doc / object . cpp <nl> ppp b / src / doc / object . cpp <nl> <nl> / / Aseprite Document Library <nl> / / Copyright ( c ) 2014 David Capello <nl> / / <nl> - / / This source file is distributed under the terms of the MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / doc / object . h <nl> ppp b / src / doc / object . h <nl> <nl> / / Aseprite Document Library <nl> / / Copyright ( c ) 2014 David Capello <nl> / / <nl> - / / This source file is distributed under the terms of the MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef DOC_OBJECT_H_INCLUDED <nl> # define DOC_OBJECT_H_INCLUDED <nl> mmm a / src / doc / object_id . h <nl> ppp b / src / doc / object_id . h <nl> <nl> / / Aseprite Document Library <nl> / / Copyright ( c ) 2014 David Capello <nl> / / <nl> - / / This source file is distributed under the terms of the MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef DOC_OBJECT_ID_H_INCLUDED <nl> # define DOC_OBJECT_ID_H_INCLUDED <nl> mmm a / src / gfx / border . h <nl> ppp b / src / gfx / border . h <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef GFX_BORDER_H_INCLUDED <nl> # define GFX_BORDER_H_INCLUDED <nl> mmm a / src / gfx / fwd . h <nl> ppp b / src / gfx / fwd . h <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef GFX_FWD_H_INCLUDED <nl> # define GFX_FWD_H_INCLUDED <nl> mmm a / src / gfx / hsv . cpp <nl> ppp b / src / gfx / hsv . cpp <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include " gfx / hsv . h " <nl> # include " gfx / rgb . h " <nl> mmm a / src / gfx / hsv . h <nl> ppp b / src / gfx / hsv . h <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef GFX_HSV_H_INCLUDED <nl> # define GFX_HSV_H_INCLUDED <nl> mmm a / src / gfx / hsv_unittest . cpp <nl> ppp b / src / gfx / hsv_unittest . cpp <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < gtest / gtest . h > <nl> <nl> mmm a / src / gfx / point . h <nl> ppp b / src / gfx / point . h <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef GFX_POINT_H_INCLUDED <nl> # define GFX_POINT_H_INCLUDED <nl> mmm a / src / gfx / rect . h <nl> ppp b / src / gfx / rect . h <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef GFX_RECT_H_INCLUDED <nl> # define GFX_RECT_H_INCLUDED <nl> mmm a / src / gfx / rect_unittest . cpp <nl> ppp b / src / gfx / rect_unittest . cpp <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < gtest / gtest . h > <nl> <nl> mmm a / src / gfx / region . cpp <nl> ppp b / src / gfx / region . cpp <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / gfx / region . h <nl> ppp b / src / gfx / region . h <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef GFX_REGION_H_INCLUDED <nl> # define GFX_REGION_H_INCLUDED <nl> mmm a / src / gfx / region_unittest . cpp <nl> ppp b / src / gfx / region_unittest . cpp <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < gtest / gtest . h > <nl> <nl> mmm a / src / gfx / rgb . cpp <nl> ppp b / src / gfx / rgb . cpp <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include " gfx / rgb . h " <nl> # include " gfx / hsv . h " <nl> mmm a / src / gfx / rgb . h <nl> ppp b / src / gfx / rgb . h <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef GFX_RGB_H_INCLUDED <nl> # define GFX_RGB_H_INCLUDED <nl> mmm a / src / gfx / rgb_unittest . cpp <nl> ppp b / src / gfx / rgb_unittest . cpp <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < gtest / gtest . h > <nl> <nl> mmm a / src / gfx / size . h <nl> ppp b / src / gfx / size . h <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef GFX_SIZE_H_INCLUDED <nl> # define GFX_SIZE_H_INCLUDED <nl> mmm a / src / gfx / transformation . cpp <nl> ppp b / src / gfx / transformation . cpp <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / gfx / transformation . h <nl> ppp b / src / gfx / transformation . h <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef TRANSFORMATION_H_INCLUDED <nl> # define TRANSFORMATION_H_INCLUDED <nl> mmm a / src / raster / algofill . cpp <nl> ppp b / src / raster / algofill . cpp <nl> <nl> / / By Shawn Hargreaves . <nl> / / Adapted to Aseprite by David Capello <nl> / / <nl> - / / This source file is distributed under a Allegro license , please <nl> - / / read allegro4 - LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / raster / resize_image_unittest . cpp <nl> ppp b / src / raster / resize_image_unittest . cpp <nl> <nl> / / Aseprite Gfx Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / raster / rotate . cpp <nl> ppp b / src / raster / rotate . cpp <nl> <nl> / / Optimized by Sven Sandberg . <nl> / / To C + + templates by David Capello <nl> / / <nl> - / / This source file is distributed under a Allegro license , please <nl> - / / read allegro4 - LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / she / capabilities . h <nl> ppp b / src / she / capabilities . h <nl> <nl> / / SHE library <nl> / / Copyright ( C ) 2012 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef SHE_CAPABILITIES_H_INCLUDED <nl> # define SHE_CAPABILITIES_H_INCLUDED <nl> mmm a / src / she / display . h <nl> ppp b / src / she / display . h <nl> <nl> / / SHE library <nl> / / Copyright ( C ) 2012 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef SHE_DISPLAY_H_INCLUDED <nl> # define SHE_DISPLAY_H_INCLUDED <nl> mmm a / src / she / locked_surface . h <nl> ppp b / src / she / locked_surface . h <nl> <nl> / / SHE library <nl> / / Copyright ( C ) 2012 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef SHE_LOCKED_SURFACE_H_INCLUDED <nl> # define SHE_LOCKED_SURFACE_H_INCLUDED <nl> mmm a / src / she / scoped_handle . h <nl> ppp b / src / she / scoped_handle . h <nl> <nl> / / SHE library <nl> / / Copyright ( C ) 2012 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef SHE_SCOPED_HANDLE_H_INCLUDED <nl> # define SHE_SCOPED_HANDLE_H_INCLUDED <nl> mmm a / src / she / scoped_surface_lock . h <nl> ppp b / src / she / scoped_surface_lock . h <nl> <nl> / / SHE library <nl> / / Copyright ( C ) 2012 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef SHE_SCOPED_SURFACE_LOCK_H_INCLUDED <nl> # define SHE_SCOPED_SURFACE_LOCK_H_INCLUDED <nl> mmm a / src / she / she . h <nl> ppp b / src / she / she . h <nl> <nl> / / SHE library <nl> / / Copyright ( C ) 2012 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef SHE_H_INCLUDED <nl> # define SHE_H_INCLUDED <nl> mmm a / src / she / she_alleg4 . cpp <nl> ppp b / src / she / she_alleg4 . cpp <nl> <nl> / / SHE library <nl> / / Copyright ( C ) 2012 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / she / surface . h <nl> ppp b / src / she / surface . h <nl> <nl> / / SHE library <nl> / / Copyright ( C ) 2012 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef SHE_SURFACE_H_INCLUDED <nl> # define SHE_SURFACE_H_INCLUDED <nl> mmm a / src / she / system . h <nl> ppp b / src / she / system . h <nl> <nl> / / SHE library <nl> / / Copyright ( C ) 2012 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef SHE_SYSTEM_H_INCLUDED <nl> # define SHE_SYSTEM_H_INCLUDED <nl> mmm a / src / ui / accelerator . cpp <nl> ppp b / src / ui / accelerator . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / accelerator . h <nl> ppp b / src / ui / accelerator . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_ACCELERATOR_H_INCLUDED <nl> # define UI_ACCELERATOR_H_INCLUDED <nl> mmm a / src / ui / alert . cpp <nl> ppp b / src / ui / alert . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> <nl> mmm a / src / ui / alert . h <nl> ppp b / src / ui / alert . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_ALERT_H_INCLUDED <nl> # define UI_ALERT_H_INCLUDED <nl> mmm a / src / ui / base . h <nl> ppp b / src / ui / base . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_BASE_H_INCLUDED <nl> # define UI_BASE_H_INCLUDED <nl> mmm a / src / ui / box . cpp <nl> ppp b / src / ui / box . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> / * Based on code from GTK + 2 . 1 . 2 ( gtk + / gtk / gtkhbox . c ) * / <nl> <nl> mmm a / src / ui / box . h <nl> ppp b / src / ui / box . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_BOX_H_INCLUDED <nl> # define UI_BOX_H_INCLUDED <nl> mmm a / src / ui / button . cpp <nl> ppp b / src / ui / button . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / button . h <nl> ppp b / src / ui / button . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_BUTTON_H_INCLUDED <nl> # define UI_BUTTON_H_INCLUDED <nl> mmm a / src / ui / clipboard . cpp <nl> ppp b / src / ui / clipboard . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / clipboard . h <nl> ppp b / src / ui / clipboard . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_CLIPBOARD_H_INCLUDED <nl> # define UI_CLIPBOARD_H_INCLUDED <nl> mmm a / src / ui / clipboard_none . h <nl> ppp b / src / ui / clipboard_none . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2014 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include < string > <nl> <nl> mmm a / src / ui / clipboard_win . h <nl> ppp b / src / ui / clipboard_win . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2014 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include " base / string . h " <nl> <nl> mmm a / src / ui / close_event . h <nl> ppp b / src / ui / close_event . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_CLOSE_EVENT_H_INCLUDED <nl> # define UI_CLOSE_EVENT_H_INCLUDED <nl> mmm a / src / ui / color . cpp <nl> ppp b / src / ui / color . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / color . h <nl> ppp b / src / ui / color . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_COLOR_H_INCLUDED <nl> # define UI_COLOR_H_INCLUDED <nl> mmm a / src / ui / combobox . cpp <nl> ppp b / src / ui / combobox . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / combobox . h <nl> ppp b / src / ui / combobox . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_COMBOBOX_H_INCLUDED <nl> # define UI_COMBOBOX_H_INCLUDED <nl> mmm a / src / ui / component . cpp <nl> ppp b / src / ui / component . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / component . h <nl> ppp b / src / ui / component . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_COMPONENT_H_INCLUDED <nl> # define UI_COMPONENT_H_INCLUDED <nl> mmm a / src / ui / cursor . cpp <nl> ppp b / src / ui / cursor . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / cursor . h <nl> ppp b / src / ui / cursor . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_CURSOR_H_INCLUDED <nl> # define UI_CURSOR_H_INCLUDED <nl> mmm a / src / ui / cursor_type . h <nl> ppp b / src / ui / cursor_type . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_CURSOR_TYPE_H_INCLUDED <nl> # define UI_CURSOR_TYPE_H_INCLUDED <nl> mmm a / src / ui / custom_label . cpp <nl> ppp b / src / ui / custom_label . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / custom_label . h <nl> ppp b / src / ui / custom_label . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_CUSTOM_LABEL_H_INCLUDED <nl> # define UI_CUSTOM_LABEL_H_INCLUDED <nl> mmm a / src / ui / draw . cpp <nl> ppp b / src / ui / draw . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / draw . h <nl> ppp b / src / ui / draw . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_DRAW_H_INCLUDED <nl> # define UI_DRAW_H_INCLUDED <nl> mmm a / src / ui / entry . cpp <nl> ppp b / src / ui / entry . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / entry . h <nl> ppp b / src / ui / entry . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_ENTRY_H_INCLUDED <nl> # define UI_ENTRY_H_INCLUDED <nl> mmm a / src / ui / event . cpp <nl> ppp b / src / ui / event . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include " ui / event . h " <nl> <nl> mmm a / src / ui / event . h <nl> ppp b / src / ui / event . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_EVENT_H_INCLUDED <nl> # define UI_EVENT_H_INCLUDED <nl> mmm a / src / ui / font . cpp <nl> ppp b / src / ui / font . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> / * Based on code of AllegroFont , Copyright ( c ) 2001 , 2002 Javier Gonzalez * / <nl> <nl> mmm a / src / ui / font . h <nl> ppp b / src / ui / font . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_FONT_H_INCLUDED <nl> # define UI_FONT_H_INCLUDED <nl> mmm a / src / ui / fontbmp . cpp <nl> ppp b / src / ui / fontbmp . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> / * Original code from : <nl> allegro / tools / datedit . c <nl> mmm a / src / ui / graphics . cpp <nl> ppp b / src / ui / graphics . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / graphics . h <nl> ppp b / src / ui / graphics . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_GRAPHICS_H_INCLUDED <nl> # define UI_GRAPHICS_H_INCLUDED <nl> mmm a / src / ui / grid . cpp <nl> ppp b / src / ui / grid . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / grid . h <nl> ppp b / src / ui / grid . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_GRID_H_INCLUDED <nl> # define UI_GRID_H_INCLUDED <nl> mmm a / src / ui / hit_test_event . h <nl> ppp b / src / ui / hit_test_event . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_HIT_TEST_EVENT_H_INCLUDED <nl> # define UI_HIT_TEST_EVENT_H_INCLUDED <nl> mmm a / src / ui / image_view . cpp <nl> ppp b / src / ui / image_view . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / image_view . h <nl> ppp b / src / ui / image_view . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_IMAGE_VIEW_H_INCLUDED <nl> # define UI_IMAGE_VIEW_H_INCLUDED <nl> mmm a / src / ui / init_theme_event . h <nl> ppp b / src / ui / init_theme_event . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_INIT_THEME_EVENT_H_INCLUDED <nl> # define UI_INIT_THEME_EVENT_H_INCLUDED <nl> mmm a / src / ui / int_entry . cpp <nl> ppp b / src / ui / int_entry . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / int_entry . h <nl> ppp b / src / ui / int_entry . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_INT_ENTRY_H_INCLUDED <nl> # define UI_INT_ENTRY_H_INCLUDED <nl> mmm a / src / ui / intern . cpp <nl> ppp b / src / ui / intern . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / intern . h <nl> ppp b / src / ui / intern . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_INTERN_H_INCLUDED <nl> # define UI_INTERN_H_INCLUDED <nl> mmm a / src / ui / keys . cpp <nl> ppp b / src / ui / keys . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / keys . h <nl> ppp b / src / ui / keys . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_KEYS_H_INCLUDED <nl> # define UI_KEYS_H_INCLUDED <nl> mmm a / src / ui / label . cpp <nl> ppp b / src / ui / label . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / label . h <nl> ppp b / src / ui / label . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_LABEL_H_INCLUDED <nl> # define UI_LABEL_H_INCLUDED <nl> mmm a / src / ui / layout_io . h <nl> ppp b / src / ui / layout_io . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_LAYOUT_IO_H_INCLUDED <nl> # define UI_LAYOUT_IO_H_INCLUDED <nl> mmm a / src / ui / link_label . cpp <nl> ppp b / src / ui / link_label . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> <nl> # ifdef HAVE_CONFIG_H <nl> mmm a / src / ui / link_label . h <nl> ppp b / src / ui / link_label . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_LINK_LABEL_H_INCLUDED <nl> # define UI_LINK_LABEL_H_INCLUDED <nl> mmm a / src / ui / listbox . cpp <nl> ppp b / src / ui / listbox . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / listbox . h <nl> ppp b / src / ui / listbox . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_LISTBOX_H_INCLUDED <nl> # define UI_LISTBOX_H_INCLUDED <nl> mmm a / src / ui / listitem . cpp <nl> ppp b / src / ui / listitem . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / listitem . h <nl> ppp b / src / ui / listitem . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_LISTITEM_H_INCLUDED <nl> # define UI_LISTITEM_H_INCLUDED <nl> mmm a / src / ui / load_layout_event . h <nl> ppp b / src / ui / load_layout_event . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_LOAD_LAYOUT_EVENT_H_INCLUDED <nl> # define UI_LOAD_LAYOUT_EVENT_H_INCLUDED <nl> mmm a / src / ui / manager . cpp <nl> ppp b / src / ui / manager . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> / / # define REPORT_EVENTS <nl> / / # define LIMIT_DISPATCH_TIME <nl> mmm a / src / ui / manager . h <nl> ppp b / src / ui / manager . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_MANAGER_H_INCLUDED <nl> # define UI_MANAGER_H_INCLUDED <nl> mmm a / src / ui / menu . cpp <nl> ppp b / src / ui / menu . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / menu . h <nl> ppp b / src / ui / menu . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_MENU_H_INCLUDED <nl> # define UI_MENU_H_INCLUDED <nl> mmm a / src / ui / message . cpp <nl> ppp b / src / ui / message . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / message . h <nl> ppp b / src / ui / message . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_MESSAGE_H_INCLUDED <nl> # define UI_MESSAGE_H_INCLUDED <nl> mmm a / src / ui / message_loop . cpp <nl> ppp b / src / ui / message_loop . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / message_loop . h <nl> ppp b / src / ui / message_loop . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_MESSAGE_LOOP_H_INCLUDED <nl> # define UI_MESSAGE_LOOP_H_INCLUDED <nl> mmm a / src / ui / message_type . h <nl> ppp b / src / ui / message_type . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_MESSAGE_TYPE_H_INCLUDED <nl> # define UI_MESSAGE_TYPE_H_INCLUDED <nl> mmm a / src / ui / mouse_buttons . h <nl> ppp b / src / ui / mouse_buttons . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_MOUSE_BUTTONS_H_INCLUDED <nl> # define UI_MOUSE_BUTTONS_H_INCLUDED <nl> mmm a / src / ui / overlay . cpp <nl> ppp b / src / ui / overlay . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / overlay . h <nl> ppp b / src / ui / overlay . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_OVERLAY_H_INCLUDED <nl> # define UI_OVERLAY_H_INCLUDED <nl> mmm a / src / ui / overlay_manager . cpp <nl> ppp b / src / ui / overlay_manager . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / overlay_manager . h <nl> ppp b / src / ui / overlay_manager . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_OVERLAY_MANAGER_H_INCLUDED <nl> # define UI_OVERLAY_MANAGER_H_INCLUDED <nl> mmm a / src / ui / paint_event . cpp <nl> ppp b / src / ui / paint_event . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / paint_event . h <nl> ppp b / src / ui / paint_event . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_PAINT_EVENT_H_INCLUDED <nl> # define UI_PAINT_EVENT_H_INCLUDED <nl> mmm a / src / ui / popup_window . cpp <nl> ppp b / src / ui / popup_window . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / popup_window . h <nl> ppp b / src / ui / popup_window . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_POPUP_WINDOW_H_INCLUDED <nl> # define UI_POPUP_WINDOW_H_INCLUDED <nl> mmm a / src / ui / preferred_size_event . cpp <nl> ppp b / src / ui / preferred_size_event . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / preferred_size_event . h <nl> ppp b / src / ui / preferred_size_event . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_PREFERRED_SIZE_EVENT_H_INCLUDED <nl> # define UI_PREFERRED_SIZE_EVENT_H_INCLUDED <nl> mmm a / src / ui / property . cpp <nl> ppp b / src / ui / property . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # include " ui / property . h " <nl> <nl> mmm a / src / ui / property . h <nl> ppp b / src / ui / property . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_PROPERTY_H_INCLUDED <nl> # define UI_PROPERTY_H_INCLUDED <nl> mmm a / src / ui / register_message . cpp <nl> ppp b / src / ui / register_message . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / register_message . h <nl> ppp b / src / ui / register_message . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_REGISTER_MESSAGE_H_INCLUDED <nl> # define UI_REGISTER_MESSAGE_H_INCLUDED <nl> mmm a / src / ui / resize_event . cpp <nl> ppp b / src / ui / resize_event . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / resize_event . h <nl> ppp b / src / ui / resize_event . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_RESIZE_EVENT_H_INCLUDED <nl> # define UI_RESIZE_EVENT_H_INCLUDED <nl> mmm a / src / ui / save_layout_event . h <nl> ppp b / src / ui / save_layout_event . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_SAVE_LAYOUT_EVENT_H_INCLUDED <nl> # define UI_SAVE_LAYOUT_EVENT_H_INCLUDED <nl> mmm a / src / ui / scroll_bar . cpp <nl> ppp b / src / ui / scroll_bar . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / scroll_bar . h <nl> ppp b / src / ui / scroll_bar . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_SCROLL_BAR_H_INCLUDED <nl> # define UI_SCROLL_BAR_H_INCLUDED <nl> mmm a / src / ui / separator . cpp <nl> ppp b / src / ui / separator . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / separator . h <nl> ppp b / src / ui / separator . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_SEPARATOR_H_INCLUDED <nl> # define UI_SEPARATOR_H_INCLUDED <nl> mmm a / src / ui / slider . cpp <nl> ppp b / src / ui / slider . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / slider . h <nl> ppp b / src / ui / slider . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_SLIDER_H_INCLUDED <nl> # define UI_SLIDER_H_INCLUDED <nl> mmm a / src / ui / splitter . cpp <nl> ppp b / src / ui / splitter . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / splitter . h <nl> ppp b / src / ui / splitter . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_SPLITTER_H_INCLUDED <nl> # define UI_SPLITTER_H_INCLUDED <nl> mmm a / src / ui / system . cpp <nl> ppp b / src / ui / system . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / system . h <nl> ppp b / src / ui / system . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_SYSTEM_H_INCLUDED <nl> # define UI_SYSTEM_H_INCLUDED <nl> mmm a / src / ui / textbox . cpp <nl> ppp b / src / ui / textbox . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / textbox . h <nl> ppp b / src / ui / textbox . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_TEXTBOX_H_INCLUDED <nl> # define UI_TEXTBOX_H_INCLUDED <nl> mmm a / src / ui / theme . cpp <nl> ppp b / src / ui / theme . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / theme . h <nl> ppp b / src / ui / theme . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_THEME_H_INCLUDED <nl> # define UI_THEME_H_INCLUDED <nl> mmm a / src / ui / timer . cpp <nl> ppp b / src / ui / timer . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / timer . h <nl> ppp b / src / ui / timer . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_TIMER_H_INCLUDED <nl> # define UI_TIMER_H_INCLUDED <nl> mmm a / src / ui / tooltips . cpp <nl> ppp b / src / ui / tooltips . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / tooltips . h <nl> ppp b / src / ui / tooltips . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_TOOLTIPS_H_INCLUDED <nl> # define UI_TOOLTIPS_H_INCLUDED <nl> mmm a / src / ui / ui . cpp <nl> ppp b / src / ui / ui . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / ui . h <nl> ppp b / src / ui / ui . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_UI_H_INCLUDED <nl> # define UI_UI_H_INCLUDED <nl> mmm a / src / ui / view . cpp <nl> ppp b / src / ui / view . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / view . h <nl> ppp b / src / ui / view . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_VIEW_H_INCLUDED <nl> # define UI_VIEW_H_INCLUDED <nl> mmm a / src / ui / viewport . cpp <nl> ppp b / src / ui / viewport . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / ui / viewport . h <nl> ppp b / src / ui / viewport . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_VIEWPORT_H_INCLUDED <nl> # define UI_VIEWPORT_H_INCLUDED <nl> mmm a / src / ui / widget . cpp <nl> ppp b / src / ui / widget . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> / * # define REPORT_SIGNALS * / <nl> <nl> mmm a / src / ui / widget . h <nl> ppp b / src / ui / widget . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_WIDGET_H_INCLUDED <nl> # define UI_WIDGET_H_INCLUDED <nl> mmm a / src / ui / widget_type . h <nl> ppp b / src / ui / widget_type . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_WIDGET_TYPE_H_INCLUDED <nl> # define UI_WIDGET_TYPE_H_INCLUDED <nl> mmm a / src / ui / widgets_list . h <nl> ppp b / src / ui / widgets_list . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_WIDGETS_LIST_H_INCLUDED <nl> # define UI_WIDGETS_LIST_H_INCLUDED <nl> mmm a / src / ui / window . cpp <nl> ppp b / src / ui / window . cpp <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # define REDRAW_MOVEMENT <nl> <nl> mmm a / src / ui / window . h <nl> ppp b / src / ui / window . h <nl> <nl> / / Aseprite UI Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UI_WINDOW_H_INCLUDED <nl> # define UI_WINDOW_H_INCLUDED <nl> mmm a / src / undo / modification . h <nl> ppp b / src / undo / modification . h <nl> <nl> / / Aseprite Undo Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UNDO_MODIFICATION_H_INCLUDED <nl> # define UNDO_MODIFICATION_H_INCLUDED <nl> mmm a / src / undo / object_id . h <nl> ppp b / src / undo / object_id . h <nl> <nl> / / Aseprite Undo Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UNDO_OBJECT_ID_H_INCLUDED <nl> # define UNDO_OBJECT_ID_H_INCLUDED <nl> mmm a / src / undo / objects_container . h <nl> ppp b / src / undo / objects_container . h <nl> <nl> / / Aseprite Undo Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UNDO_OBJECTS_CONTAINER_H_INCLUDED <nl> # define UNDO_OBJECTS_CONTAINER_H_INCLUDED <nl> mmm a / src / undo / undo_exception . h <nl> ppp b / src / undo / undo_exception . h <nl> <nl> / / Aseprite Undo Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UNDO_UNDO_EXCEPTION_H_INCLUDED <nl> # define UNDO_UNDO_EXCEPTION_H_INCLUDED <nl> mmm a / src / undo / undo_history . cpp <nl> ppp b / src / undo / undo_history . cpp <nl> <nl> / / Aseprite Undo Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / undo / undo_history . h <nl> ppp b / src / undo / undo_history . h <nl> <nl> / / Aseprite Undo Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UNDO_UNDO_HISTORY_H_INCLUDED <nl> # define UNDO_UNDO_HISTORY_H_INCLUDED <nl> mmm a / src / undo / undoer . h <nl> ppp b / src / undo / undoer . h <nl> <nl> / / Aseprite Undo Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UNDO_UNDOER_H_INCLUDED <nl> # define UNDO_UNDOER_H_INCLUDED <nl> mmm a / src / undo / undoers_collector . h <nl> ppp b / src / undo / undoers_collector . h <nl> <nl> / / Aseprite Undo Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UNDO_UNDOERS_COLLECTOR_H_INCLUDED <nl> # define UNDO_UNDOERS_COLLECTOR_H_INCLUDED <nl> mmm a / src / undo / undoers_stack . cpp <nl> ppp b / src / undo / undoers_stack . cpp <nl> <nl> / / Aseprite Undo Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifdef HAVE_CONFIG_H <nl> # include " config . h " <nl> mmm a / src / undo / undoers_stack . h <nl> ppp b / src / undo / undoers_stack . h <nl> <nl> / / Aseprite Undo Library <nl> / / Copyright ( C ) 2001 - 2013 David Capello <nl> / / <nl> - / / This source file is distributed under MIT license , <nl> - / / please read LICENSE . txt for more information . <nl> + / / This file is released under the terms of the MIT license . <nl> + / / Read LICENSE . txt for more information . <nl> <nl> # ifndef UNDO_UNDOERS_STACK_H_INCLUDED <nl> # define UNDO_UNDOERS_STACK_H_INCLUDED <nl>
|
Fix header of files distributed under the terms of the MIT license
|
aseprite/aseprite
|
78ce23375627bc3c5ff6bf4c61090f6a9c3a0028
|
2014-03-29T23:08:05Z
|
mmm a / src / core / hle / service / audio / audren_u . cpp <nl> ppp b / src / core / hle / service / audio / audren_u . cpp <nl> <nl> / / Licensed under GPLv2 or any later version <nl> / / Refer to the license . txt file included . <nl> <nl> + # include < array > <nl> + <nl> # include " common / alignment . h " <nl> # include " common / logging / log . h " <nl> # include " core / core_timing . h " <nl> class IAudioDevice final : public ServiceFramework < IAudioDevice > { <nl> LOG_WARNING ( Service_Audio , " ( STUBBED ) called " ) ; <nl> IPC : : RequestParser rp { ctx } ; <nl> <nl> - const std : : string audio_interface = " AudioInterface " ; <nl> + constexpr std : : array < char , 15 > audio_interface { { " AudioInterface " } } ; <nl> ctx . WriteBuffer ( audio_interface ) ; <nl> <nl> IPC : : ResponseBuilder rb = rp . MakeBuilder ( 3 , 0 , 0 ) ; <nl> class IAudioDevice final : public ServiceFramework < IAudioDevice > { <nl> LOG_WARNING ( Service_Audio , " ( STUBBED ) called " ) ; <nl> IPC : : RequestParser rp { ctx } ; <nl> <nl> - const std : : string audio_interface = " AudioDevice " ; <nl> + constexpr std : : array < char , 12 > audio_interface { { " AudioDevice " } } ; <nl> ctx . WriteBuffer ( audio_interface ) ; <nl> <nl> IPC : : ResponseBuilder rb = rp . MakeBuilder ( 3 , 0 , 0 ) ; <nl>
|
audren_u : Use a std : : array instead of std : : string for holding the audio interface / device name
|
yuzu-emu/yuzu
|
40c9c5a55c7c9e00d96f55b1cd898a51120451fe
|
2018-07-20T03:15:27Z
|
mmm a / folly / python / __init__ . pxd <nl> ppp b / folly / python / __init__ . pxd <nl> cdef extern from " folly / Try . h " namespace " folly " nogil : <nl> <nl> cdef extern from " folly / futures / Future . h " namespace " folly " nogil : <nl> cdef cppclass cFollyFuture " folly : : Future " [ T ] : <nl> - pass <nl> + T get ( ) <nl> # TODO add via and then <nl> <nl> cdef extern from " folly / Unit . h " namespace " folly " : <nl>
|
Safer Clients
|
facebook/folly
|
cf504d17595763a7f8e633a2280dff97ca2b37cb
|
2018-03-28T05:06:28Z
|
mmm a / dbms / tests / queries / 0_stateless / 00429_long_http_bufferization . sh <nl> ppp b / dbms / tests / queries / 0_stateless / 00429_long_http_bufferization . sh <nl> function query { <nl> } <nl> <nl> function ch_url ( ) { <nl> - $ { CLICKHOUSE_CURL } - sS " $ URL ? max_block_size = $ max_block_size & $ 1 " - d " ` query $ 2 ` " <nl> + $ { CLICKHOUSE_CURL_COMMAND } - sS " $ URL ? max_block_size = $ max_block_size & $ 1 " - d " ` query $ 2 ` " <nl> } <nl> <nl> <nl> mmm a / dbms / tests / queries / shell_config . sh <nl> ppp b / dbms / tests / queries / shell_config . sh <nl> export CLICKHOUSE_PORT_HTTPS = $ { CLICKHOUSE_PORT_HTTPS : = " 8443 " } <nl> export CLICKHOUSE_PORT_HTTP_PROTO = $ { CLICKHOUSE_PORT_HTTP_PROTO : = " http " } <nl> export CLICKHOUSE_URL = $ { CLICKHOUSE_URL : = " $ { CLICKHOUSE_PORT_HTTP_PROTO } : / / $ { CLICKHOUSE_HOST } : $ { CLICKHOUSE_PORT_HTTP } / " } <nl> export CLICKHOUSE_URL_HTTPS = $ { CLICKHOUSE_URL_HTTPS : = " https : / / $ { CLICKHOUSE_HOST } : $ { CLICKHOUSE_PORT_HTTPS } / " } <nl> - export CLICKHOUSE_CURL = $ { CLICKHOUSE_CURL : = " curl - - max - time 10 " } <nl> + export CLICKHOUSE_CURL_COMMAND = $ { CLICKHOUSE_CURL_COMMAND : = " curl " } <nl> + export CLICKHOUSE_CURL = $ { CLICKHOUSE_CURL : = " $ { CLICKHOUSE_CURL_COMMAND } - - max - time 10 " } <nl> export CLICKHOUSE_TMP = $ { CLICKHOUSE_TMP : = " . " } <nl> mkdir - p $ { CLICKHOUSE_TMP } <nl>
|
Merge pull request from proller / fix14
|
ClickHouse/ClickHouse
|
aeaf8cf14c7c70e8d10495b90c301975773c2079
|
2018-03-29T20:20:35Z
|
mmm a / dlib / CMakeLists . txt <nl> ppp b / dlib / CMakeLists . txt <nl> include ( release_build_by_default ) <nl> project ( dlib ) <nl> <nl> set ( CPACK_PACKAGE_VERSION_MAJOR " 18 " ) <nl> - set ( CPACK_PACKAGE_VERSION_MINOR " 17 " ) <nl> - set ( CPACK_PACKAGE_VERSION_PATCH " 100 " ) <nl> + set ( CPACK_PACKAGE_VERSION_MINOR " 18 " ) <nl> + set ( CPACK_PACKAGE_VERSION_PATCH " 0 " ) <nl> set ( VERSION $ { CPACK_PACKAGE_VERSION_MAJOR } . $ { CPACK_PACKAGE_VERSION_MINOR } . $ { CPACK_PACKAGE_VERSION_PATCH } ) <nl> <nl> set ( CMAKE_LEGACY_CYGWIN_WIN32 0 ) # Remove when CMake > = 2 . 8 . 4 is required <nl>
|
Created release v18 . 18
|
davisking/dlib
|
6124442f86cbb0850c33608983561a9dd97d4528
|
2015-10-29T00:25:59Z
|
mmm a / python / taichi_lang / transformer . py <nl> ppp b / python / taichi_lang / transformer . py <nl> def visit_For ( self , node ) : <nl> bgn = node . iter . args [ 0 ] <nl> end = node . iter . args [ 1 ] <nl> else : <nl> - bgn = ast . Constant ( value = 0 ) <nl> + bgn = self . make_constant ( value = 0 ) <nl> end = node . iter . args [ 0 ] <nl> <nl> t . body [ 1 ] . value . args [ 0 ] = bgn <nl> def visit_Module ( self , node ) : <nl> self . generic_visit ( node ) <nl> return node <nl> <nl> + @ staticmethod <nl> + def make_constant ( value ) : <nl> + # Do not use ast . Constant which does not exist in python3 . 5 <nl> + node = ASTTransformer . parse_expr ( ' 0 ' ) <nl> + node . value = value <nl> + return node <nl> + <nl> def visit_FunctionDef ( self , node ) : <nl> with self . variable_scope ( ) : <nl> self . generic_visit ( node ) <nl> def visit_FunctionDef ( self , node ) : <nl> arg_init = self . parse_stmt ( ' x = ti . decl_arg ( 0 , 0 ) ' ) <nl> arg_init . targets [ 0 ] . id = arg . arg <nl> arg_init . value . args [ 0 ] = arg . annotation <nl> - arg_init . value . args [ 1 ] = ast . Constant ( val = i ) <nl> + arg_init . value . args [ 1 ] = self . make_constant ( val = i ) <nl> arg_decls . append ( arg_init ) <nl> node . body = arg_decls + node . body <nl> return node <nl> mmm a / src / python_bindings . cpp <nl> ppp b / src / python_bindings . cpp <nl> PYBIND11_MODULE ( taichi_lang_core , m ) { <nl> m . def ( " make_frontend_assign_stmt " , <nl> Stmt : : make < FrontendAssignStmt , const Expr & , const Expr & > ) ; <nl> <nl> - m . def ( " make_arg_load_expr " , Expr : : make < ArgLoadExpression > ) ; <nl> + m . def ( " make_arg_load_expr " , Expr : : make < ArgLoadExpression , int > ) ; <nl> <nl> m . def ( " make_id_expr " , Expr : : make < IdExpression , std : : string > ) ; <nl> m . def ( " make_constant_expr " , Expr : : make < ConstExpression , int > ) ; <nl>
|
fixed compile and ast . Constant
|
taichi-dev/taichi
|
577479e44c11686a83c0ee3fc0d1a0b49b2d2109
|
2019-06-14T04:43:47Z
|
mmm a / modules / core / src / drawing . cpp <nl> ppp b / modules / core / src / drawing . cpp <nl> LineIterator : : LineIterator ( const Mat & img , Point pt1 , Point pt2 , <nl> } <nl> <nl> this - > ptr0 = img . data ; <nl> - this - > step = ( int ) step ; <nl> - this - > elemSize = bt_pix ; <nl> + this - > step = ( int ) img . step ; <nl> + this - > elemSize = bt_pix0 ; <nl> } <nl> <nl> static void <nl>
|
fixed LineIterator constructor in order to make LineIterator : : pos ( ) work properly ( )
|
opencv/opencv
|
808190c02e3cfa1b650a01f30ef53bf235cb3dc1
|
2010-07-29T13:26:01Z
|
mmm a / tensorflow / python / keras / mixed_precision / experimental / autocast_variable_test . py <nl> ppp b / tensorflow / python / keras / mixed_precision / experimental / autocast_variable_test . py <nl> def test_repr_distributed ( self ) : <nl> with strategy . scope ( ) : <nl> x = get_var ( 1 . , dtypes . float32 ) <nl> x = autocast_variable . create_autocast_variable ( x ) <nl> - use_policy = getattr ( strategy . extended , ' _use_policy ' , False ) <nl> + use_policy = getattr ( strategy . extended , ' _use_var_policy ' , False ) <nl> if use_policy : <nl> self . assertRegex ( <nl> repr ( x ) . replace ( ' \ n ' , ' ' ) , <nl>
|
Update the name of the var policy property .
|
tensorflow/tensorflow
|
f8ed115dbcc9d59b83497e153e26fd7767941282
|
2020-08-17T17:46:51Z
|
mmm a / ports / pegtl / CONTROL <nl> ppp b / ports / pegtl / CONTROL <nl> <nl> Source : pegtl <nl> - Version : 3 . 0 . 0 - pre - 70971f4 <nl> + Version : 2020 - 12 - 07 <nl> Description : The Parsing Expression Grammar Template Library ( PEGTL ) is a zero - dependency C + + header - only parser combinator library for creating parsers according to a Parsing Expression Grammar ( PEG ) . <nl> Homepage : https : / / github . com / taocpp / PEGTL <nl> mmm a / ports / pegtl / portfile . cmake <nl> ppp b / ports / pegtl / portfile . cmake <nl> <nl> vcpkg_from_github ( <nl> OUT_SOURCE_PATH SOURCE_PATH <nl> REPO taocpp / pegtl <nl> - REF 70971f441d7611ba3905b5c0d5c8bf4338602ef2 <nl> - SHA512 8ff0f06eaa59e547e4f00002d27241f99f06b398d7cd021c3b8475431d59234d0aa32fff8ce74faee3468c9fb542020326547a6d9cd7b98561b3bdd233a1e715 <nl> + REF 93b53c80058b2632a7260ab10ef2a06abcc0fc7f <nl> + SHA512 83b198465bca60b95c670aa72681aed0448025b506c6f6a196446608eb47ee9d8828c51ac8735caa2b2ec1e53d6a13bd6ad287a4abb8690a570036b90918907a <nl> HEAD_REF master <nl> ) <nl> <nl>
|
[ pegtl ] Update to 3 . 0 . 0 release ( )
|
microsoft/vcpkg
|
af87209c50b8970c839d1d4c9c7a3286aeb51347
|
2020-12-07T16:25:38Z
|
mmm a / lib / IRGen / GenMeta . cpp <nl> ppp b / lib / IRGen / GenMeta . cpp <nl> void IRGenModule : : emitProtocolDecl ( ProtocolDecl * protocol ) { <nl> return ; <nl> } <nl> <nl> - auto * defaultWitnesses = SILMod - > lookUpDefaultWitnessTable ( protocol ) ; <nl> + SILDefaultWitnessTable * defaultWitnesses = nullptr ; <nl> + if ( ! protocol - > hasFixedLayout ( ) ) <nl> + defaultWitnesses = SILMod - > lookUpDefaultWitnessTable ( protocol ) ; <nl> ProtocolDescriptorBuilder builder ( * this , protocol , defaultWitnesses ) ; <nl> builder . layout ( ) ; <nl> <nl> mmm a / lib / SIL / SILModule . cpp <nl> ppp b / lib / SIL / SILModule . cpp <nl> SILModule : : lookUpDefaultWitnessTable ( const ProtocolDecl * Protocol ) { <nl> / / protocol descriptor metadata for the protocol . <nl> <nl> auto found = DefaultWitnessTableMap . find ( Protocol ) ; <nl> - if ( found = = DefaultWitnessTableMap . end ( ) ) { <nl> - return nullptr ; <nl> - } <nl> + assert ( found ! = DefaultWitnessTableMap . end ( ) & & <nl> + " Missing default witness table for protocol " ) ; <nl> + <nl> + SILDefaultWitnessTable * wtable = found - > second ; <nl> <nl> <nl> - return found - > second ; <nl> + / / Just return the declaration . <nl> + return wtable ; <nl> } <nl> <nl> SILDefaultWitnessTable * <nl> mmm a / lib / SILGen / SILGenType . cpp <nl> ppp b / lib / SILGen / SILGenType . cpp <nl> class SILGenType : public TypeMemberVisitor < SILGenType > { <nl> } <nl> <nl> if ( auto protocol = dyn_cast < ProtocolDecl > ( theType ) ) { <nl> - if ( ! protocol - > hasFixedLayout ( ) ) <nl> + if ( ! protocol - > isObjC ( ) ) <nl> SGM . emitDefaultWitnessTable ( protocol ) ; <nl> - <nl> return ; <nl> } <nl> <nl> mmm a / test / SILGen / protocol_resilience . swift <nl> ppp b / test / SILGen / protocol_resilience . swift <nl> <nl> - / / RUN : % target - swift - frontend - I % S / . . / Inputs - enable - source - import - emit - silgen - enable - resilience % s | FileCheck % s - - check - prefix = CHECK - - check - prefix = GLOBAL <nl> + / / RUN : % target - swift - frontend - I % S / . . / Inputs - enable - source - import - emit - silgen - enable - resilience % s | FileCheck % s - - check - prefix = CHECK <nl> <nl> import resilient_protocol <nl> <nl> func inoutResilientProtocol ( x : inout OtherConformingType ) { <nl> inoutFunc ( & OtherConformingType . staticPropertyInExtension ) <nl> } <nl> <nl> - / / Protocol is not public - - doesn ' t need default witness table <nl> + / / Protocol is not public - - make sure default witnesses have the right linkage <nl> protocol InternalProtocol { <nl> - func f ( ) <nl> + func noDefaultF ( ) <nl> + func defaultG ( ) <nl> } <nl> <nl> + extension InternalProtocol { <nl> + <nl> + / / CHECK - LABEL : sil hidden [ transparent ] [ thunk ] @ _TFP19protocol_resilience16InternalProtocol8defaultGfT_T_ <nl> + / / CHECK : return <nl> + func defaultG ( ) { } <nl> + } <nl> <nl> / / CHECK - LABEL : sil_default_witness_table P { <nl> / / CHECK - NEXT : } <nl> protocol InternalProtocol { <nl> / / CHECK - NEXT : method # ReabstractSelfRefined . callback ! materializeForSet . 1 : @ _TFP19protocol_resilience21ReabstractSelfRefinedm8callbackFxx <nl> / / CHECK - NEXT : } <nl> <nl> - / / GLOBAL - NOT : sil_default_witness_table InternalProtocol <nl> + / / CHECK - LABEL : sil_default_witness_table hidden InternalProtocol { <nl> + / / CHECK - NEXT : no_default <nl> + / / CHECK - NEXT : method # InternalProtocol . defaultG ! 1 : @ _TFP19protocol_resilience16InternalProtocol8defaultGfT_T_ <nl> + / / CHECK - NEXT : } <nl>
|
SILGen : Emit default witness tables for all non - @ objc protocols
|
apple/swift
|
f440decd23aebb2d926277e861dcf369c1f11eb8
|
2016-03-17T10:57:23Z
|
mmm a / CHANGELOG <nl> ppp b / CHANGELOG <nl> v1 . 4 . 10 ( XXXX - XX - XX ) <nl> <nl> * removed 2 tests due to change in ruby library . <nl> <nl> + * issue # 756 : set access - control - expose - headers on CORS response <nl> + <nl> + the following headers are now whitelisted by ArangoDB in CORS responses : <nl> + - etag <nl> + - content - encoding <nl> + - content - length <nl> + - location <nl> + - x - arango - errors <nl> + - x - arango - async - id <nl> <nl> v1 . 4 . 9 ( 2014 - 02 - 07 ) <nl> mmmmmmmmmmmmmmmmmm - <nl> mmm a / lib / HttpServer / HttpCommTask . h <nl> ppp b / lib / HttpServer / HttpCommTask . h <nl> namespace triagens { <nl> / / the request contained an Origin header . We have to send back the <nl> / / access - control - allow - origin header now <nl> LOGGER_TRACE ( " handling CORS response " ) ; <nl> - <nl> + <nl> + response - > setHeader ( " access - control - expose - headers " , strlen ( " access - control - expose - headers " ) , " etag , content - encoding , content - length , location , server , x - arango - errors , x - arango - async - id " ) ; <nl> + <nl> / / send back original value of " Origin " header <nl> response - > setHeader ( " access - control - allow - origin " , strlen ( " access - control - allow - origin " ) , this - > _origin ) ; <nl> <nl>
|
issue : set access - control - expose - headers on CORS response
|
arangodb/arangodb
|
bbbb089405550004a79c3a27cc805d578c9d7acf
|
2014-02-11T07:41:57Z
|
mmm a / cocos / 3d / CCBundle3D . cpp <nl> ppp b / cocos / 3d / CCBundle3D . cpp <nl> NodeData * Bundle3D : : parseNodesRecursivelyJson ( const rapidjson : : Value & jvalue ) <nl> <nl> if ( modelnodedata - > subMeshId = = " " | | modelnodedata - > matrialId = = " " ) <nl> { <nl> - std : : string err = " Node " + nodedata - > id + " part is missing meshPartId or materialId " ; <nl> CCLOG ( " warning : Node % s part is missing meshPartId or materialId " , nodedata - > id . c_str ( ) ) ; <nl> return nullptr ; <nl> } <nl>
|
Merge pull request from lvlonggame / v3
|
cocos2d/cocos2d-x
|
7ecd8c519a6394278a98d753b0d2b6d76e4c4dcc
|
2014-10-09T02:14:06Z
|
mmm a / test / IDE / reconstruct_type_from_mangled_name . swift <nl> ppp b / test / IDE / reconstruct_type_from_mangled_name . swift <nl> class Myclass2 { <nl> <nl> var arr3 : [ Myclass1 ] <nl> arr3 . append ( Myclass1 ( ) ) <nl> - / / CHECK : reconstructed type from usr for ' arr3 ' is ' Array < Myclass1 > ' fdasfd <nl> + / / CHECK : reconstructed type from usr for ' arr3 ' is ' Array < Myclass1 > ' <nl> / / CHECK : reconstructed type from usr for ' append ' is ' @ lvalue Array < Myclass1 > - > Myclass1 - > ( ) ' <nl> } <nl> } <nl>
|
[ test ] Remove some accidentally committed text .
|
apple/swift
|
09867746a1449226efd451810aa9c5eeacc477ab
|
2016-01-13T22:25:48Z
|
mmm a / lib / SILPasses / Devirtualizer . cpp <nl> ppp b / lib / SILPasses / Devirtualizer . cpp <nl> static bool specializeClassMethodDispatch ( ApplyInst * AI ) { <nl> SILBuilder Builder ( Entry ) ; <nl> / / Create the checked_cast_branch instruction that checks at runtime if the <nl> / / class instance is identical to the SILType . <nl> - Builder . createCheckedCastBranch ( AI - > getLoc ( ) , CheckedCastKind : : Identical , <nl> - ClassInstance , InstanceType , Iden , Virt ) ; <nl> + It = Builder . createCheckedCastBranch ( AI - > getLoc ( ) , CheckedCastKind : : Identical , <nl> + ClassInstance , InstanceType , Iden , Virt ) ; <nl> <nl> SILBuilder VirtBuilder ( Virt ) ; <nl> SILBuilder IdenBuilder ( Iden ) ; <nl> <nl> + / / Try sinking the retain of the class instance into the diamond . This may <nl> + / / allow additional ARC optimizations on the fast path . <nl> + if ( It ! = Entry - > begin ( ) ) { <nl> + StrongRetainInst * SRI = dyn_cast < StrongRetainInst > ( - - It ) ; <nl> + / / Try to skip another instruction , in case the class_method came first . <nl> + if ( ! SRI & & It ! = Entry - > begin ( ) ) <nl> + SRI = dyn_cast < StrongRetainInst > ( - - It ) ; <nl> + if ( SRI & & SRI - > getOperand ( ) = = ClassInstance ) { <nl> + VirtBuilder . createStrongRetain ( SRI - > getLoc ( ) , ClassInstance ) ; <nl> + IdenBuilder . createStrongRetain ( SRI - > getLoc ( ) , ClassInstance ) ; <nl> + SRI - > eraseFromParent ( ) ; <nl> + } <nl> + } <nl> + <nl> / / Copy the two apply instructions into the two blocks . <nl> ApplyInst * IdenAI = CloneApply ( AI , IdenBuilder ) ; <nl> ApplyInst * VirtAI = CloneApply ( AI , VirtBuilder ) ; <nl> new file mode 100644 <nl> index 000000000000 . . 82d7d3af26a0 <nl> mmm / dev / null <nl> ppp b / test / SILPasses / earlybinding_arc . sil <nl> <nl> + / / RUN : % sil - opt % s - earlybinding | FileCheck % s <nl> + sil_stage canonical <nl> + <nl> + import Builtin <nl> + import Swift <nl> + <nl> + class Foo { <nl> + func ping ( ) - > Int <nl> + } <nl> + <nl> + sil @ _TFC4main3Foo4pingfS0_FT_Si : $ @ cc ( method ) @ thin ( @ owned Foo ) - > Int { <nl> + bb0 ( % 0 : $ Foo ) : <nl> + debug_value % 0 : $ Foo / / let self / / id : % 1 <nl> + % 2 = integer_literal $ Builtin . Word , 1 / / user : % 3 <nl> + % 3 = struct $ Int ( % 2 : $ Builtin . Word ) / / user : % 5 <nl> + strong_release % 0 : $ Foo / / id : % 4 <nl> + return % 3 : $ Int / / id : % 5 <nl> + } <nl> + <nl> + sil @ _TFC4main3FoocfMS0_FT_S0_ : $ @ cc ( method ) @ thin ( @ owned Foo ) - > @ owned Foo { <nl> + bb0 ( % 0 : $ Foo ) : <nl> + debug_value % 0 : $ Foo / / let self / / id : % 1 <nl> + return % 0 : $ Foo / / id : % 2 <nl> + } <nl> + <nl> + sil @ _TF4main7my_mainFCS_3FooSi : $ @ thin ( @ owned Foo ) - > Int { <nl> + bb0 ( % 0 : $ Foo ) : <nl> + / / CHECK - LABLE : _TF4main7my_mainFCS_3FooSi <nl> + / / CHECK - NOT : strong_retain <nl> + / / CHECK : checked_cast_br identical % 0 : $ Foo to $ Foo <nl> + / / CHECK : strong_retain <nl> + / / CHECK - NEXT : class_method <nl> + / / CHECK : strong_retain <nl> + / / CHECK - NEXT : class_method <nl> + debug_value % 0 : $ Foo / / let x / / id : % 1 <nl> + strong_retain % 0 : $ Foo / / id : % 2 <nl> + % 3 = class_method % 0 : $ Foo , # Foo . ping ! 1 : Foo - > ( ) - > Int , $ @ cc ( method ) @ thin ( @ owned Foo ) - > Int / / user : % 4 <nl> + % 4 = apply % 3 ( % 0 ) : $ @ cc ( method ) @ thin ( @ owned Foo ) - > Int / / user : % 6 <nl> + strong_release % 0 : $ Foo / / id : % 5 <nl> + return % 4 : $ Int / / id : % 6 <nl> + } <nl> + <nl> + sil_vtable Foo { <nl> + # Foo . ping ! 1 : _TFC4main3Foo4pingfS0_FT_Si / / main . Foo . ping ( main . Foo ) ( ) - > Swift . Int <nl> + # Foo . init ! initializer . 1 : _TFC4main3FoocfMS0_FT_S0_ / / main . Foo . init ( main . Foo . Type ) ( ) - > main . Foo <nl> + } <nl>
|
When performing specialization of virtual calls try to sink the retain into the diamond shaped CFG . This will ensure that the ARC optimizer will get a chance to remove the calling convention overhead after inlining .
|
apple/swift
|
96f37fdd4d6c39e1484ea9a3903514abac7a1643
|
2014-06-13T08:58:41Z
|
mmm a / include / grpcpp / impl / codegen / call_op_set . h <nl> ppp b / include / grpcpp / impl / codegen / call_op_set . h <nl> class CallOpSet : public CallOpSetInterface , <nl> public : <nl> CallOpSet ( ) : cq_tag_ ( this ) , return_tag_ ( this ) { } <nl> / / The copy constructor and assignment operator reset the value of <nl> - / / cq_tag_ and return_tag_ since those are only meaningful on a specific <nl> - / / object , not across objects . <nl> + / / cq_tag_ , return_tag_ , done_intercepting_ and interceptor_methods_ since <nl> + / / those are only meaningful on a specific object , not across objects . <nl> CallOpSet ( const CallOpSet & other ) <nl> : cq_tag_ ( this ) , <nl> return_tag_ ( this ) , <nl> mmm a / include / grpcpp / impl / codegen / client_interceptor . h <nl> ppp b / include / grpcpp / impl / codegen / client_interceptor . h <nl> class ClientRpcInfo { <nl> grpc : : ChannelInterface * channel_ = nullptr ; <nl> std : : vector < std : : unique_ptr < experimental : : Interceptor > > interceptors_ ; <nl> bool hijacked_ = false ; <nl> - int hijacked_interceptor_ = false ; <nl> + size_t hijacked_interceptor_ = false ; <nl> <nl> friend class internal : : InterceptorBatchMethodsImpl ; <nl> friend class grpc : : ClientContext ; <nl> mmm a / include / grpcpp / impl / codegen / interceptor_common . h <nl> ppp b / include / grpcpp / impl / codegen / interceptor_common . h <nl> class InternalInterceptorBatchMethods <nl> <nl> virtual void SetRecvMessage ( void * message ) = 0 ; <nl> <nl> - virtual void SetRecvInitialMetadata ( internal : : MetadataMap * map ) = 0 ; <nl> + virtual void SetRecvInitialMetadata ( MetadataMap * map ) = 0 ; <nl> <nl> virtual void SetRecvStatus ( Status * status ) = 0 ; <nl> <nl> - virtual void SetRecvTrailingMetadata ( internal : : MetadataMap * map ) = 0 ; <nl> + virtual void SetRecvTrailingMetadata ( MetadataMap * map ) = 0 ; <nl> } ; <nl> <nl> class InterceptorBatchMethodsImpl : public InternalInterceptorBatchMethods { <nl> public : <nl> InterceptorBatchMethodsImpl ( ) { <nl> - for ( auto i = 0 ; <nl> - i < static_cast < int > ( <nl> - experimental : : InterceptionHookPoints : : NUM_INTERCEPTION_HOOKS ) ; <nl> - i + + ) { <nl> - hooks_ [ i ] = false ; <nl> + for ( auto i = static_cast < experimental : : InterceptionHookPoints > ( 0 ) ; <nl> + i < experimental : : InterceptionHookPoints : : NUM_INTERCEPTION_HOOKS ; <nl> + i = static_cast < experimental : : InterceptionHookPoints > ( <nl> + static_cast < size_t > ( i ) + 1 ) ) { <nl> + hooks_ [ static_cast < size_t > ( i ) ] = false ; <nl> } <nl> } <nl> <nl> - virtual ~ InterceptorBatchMethodsImpl ( ) { } <nl> + ~ InterceptorBatchMethodsImpl ( ) { } <nl> <nl> - virtual bool QueryInterceptionHookPoint ( <nl> + bool QueryInterceptionHookPoint ( <nl> experimental : : InterceptionHookPoints type ) override { <nl> - return hooks_ [ static_cast < int > ( type ) ] ; <nl> + return hooks_ [ static_cast < size_t > ( type ) ] ; <nl> } <nl> <nl> - virtual void Proceed ( ) override { / * fill this * / <nl> + void Proceed ( ) override { / * fill this * / <nl> if ( call_ - > client_rpc_info ( ) ! = nullptr ) { <nl> return ProceedClient ( ) ; <nl> } <nl> class InterceptorBatchMethodsImpl : public InternalInterceptorBatchMethods { <nl> ProceedServer ( ) ; <nl> } <nl> <nl> - virtual void Hijack ( ) override { <nl> + void Hijack ( ) override { <nl> / / Only the client can hijack when sending down initial metadata <nl> GPR_CODEGEN_ASSERT ( ! reverse_ & & ops_ ! = nullptr & & <nl> call_ - > client_rpc_info ( ) ! = nullptr ) ; <nl> class InterceptorBatchMethodsImpl : public InternalInterceptorBatchMethods { <nl> GPR_CODEGEN_ASSERT ( ! ran_hijacking_interceptor_ ) ; <nl> auto * rpc_info = call_ - > client_rpc_info ( ) ; <nl> rpc_info - > hijacked_ = true ; <nl> - rpc_info - > hijacked_interceptor_ = curr_iteration_ ; <nl> + rpc_info - > hijacked_interceptor_ = current_interceptor_index_ ; <nl> ClearHookPoints ( ) ; <nl> ops_ - > SetHijackingState ( ) ; <nl> ran_hijacking_interceptor_ = true ; <nl> - rpc_info - > RunInterceptor ( this , curr_iteration_ ) ; <nl> + rpc_info - > RunInterceptor ( this , current_interceptor_index_ ) ; <nl> } <nl> <nl> - virtual void AddInterceptionHookPoint ( <nl> + void AddInterceptionHookPoint ( <nl> experimental : : InterceptionHookPoints type ) override { <nl> - hooks_ [ static_cast < int > ( type ) ] = true ; <nl> + hooks_ [ static_cast < size_t > ( type ) ] = true ; <nl> } <nl> <nl> - virtual ByteBuffer * GetSendMessage ( ) override { return send_message_ ; } <nl> + ByteBuffer * GetSendMessage ( ) override { return send_message_ ; } <nl> <nl> - virtual std : : multimap < grpc : : string , grpc : : string > * GetSendInitialMetadata ( ) <nl> - override { <nl> + std : : multimap < grpc : : string , grpc : : string > * GetSendInitialMetadata ( ) override { <nl> return send_initial_metadata_ ; <nl> } <nl> <nl> - virtual Status GetSendStatus ( ) override { <nl> + Status GetSendStatus ( ) override { <nl> return Status ( static_cast < StatusCode > ( * code_ ) , * error_message_ , <nl> * error_details_ ) ; <nl> } <nl> <nl> - virtual void ModifySendStatus ( const Status & status ) override { <nl> + void ModifySendStatus ( const Status & status ) override { <nl> * code_ = static_cast < grpc_status_code > ( status . error_code ( ) ) ; <nl> * error_details_ = status . error_details ( ) ; <nl> * error_message_ = status . error_message ( ) ; <nl> } <nl> <nl> - virtual std : : multimap < grpc : : string , grpc : : string > * GetSendTrailingMetadata ( ) <nl> + std : : multimap < grpc : : string , grpc : : string > * GetSendTrailingMetadata ( ) <nl> override { <nl> return send_trailing_metadata_ ; <nl> } <nl> <nl> - virtual void * GetRecvMessage ( ) override { return recv_message_ ; } <nl> + void * GetRecvMessage ( ) override { return recv_message_ ; } <nl> <nl> - virtual std : : multimap < grpc : : string_ref , grpc : : string_ref > * <nl> - GetRecvInitialMetadata ( ) override { <nl> + std : : multimap < grpc : : string_ref , grpc : : string_ref > * GetRecvInitialMetadata ( ) <nl> + override { <nl> return recv_initial_metadata_ - > map ( ) ; <nl> } <nl> <nl> - virtual Status * GetRecvStatus ( ) override { return recv_status_ ; } <nl> + Status * GetRecvStatus ( ) override { return recv_status_ ; } <nl> <nl> - virtual std : : multimap < grpc : : string_ref , grpc : : string_ref > * <nl> - GetRecvTrailingMetadata ( ) override { <nl> + std : : multimap < grpc : : string_ref , grpc : : string_ref > * GetRecvTrailingMetadata ( ) <nl> + override { <nl> return recv_trailing_metadata_ - > map ( ) ; <nl> } <nl> <nl> - virtual void SetSendMessage ( ByteBuffer * buf ) override { send_message_ = buf ; } <nl> + void SetSendMessage ( ByteBuffer * buf ) override { send_message_ = buf ; } <nl> <nl> - virtual void SetSendInitialMetadata ( <nl> + void SetSendInitialMetadata ( <nl> std : : multimap < grpc : : string , grpc : : string > * metadata ) override { <nl> send_initial_metadata_ = metadata ; <nl> } <nl> <nl> - virtual void SetSendStatus ( grpc_status_code * code , <nl> - grpc : : string * error_details , <nl> - grpc : : string * error_message ) override { <nl> + void SetSendStatus ( grpc_status_code * code , grpc : : string * error_details , <nl> + grpc : : string * error_message ) override { <nl> code_ = code ; <nl> error_details_ = error_details ; <nl> error_message_ = error_message ; <nl> } <nl> <nl> - virtual void SetSendTrailingMetadata ( <nl> + void SetSendTrailingMetadata ( <nl> std : : multimap < grpc : : string , grpc : : string > * metadata ) override { <nl> send_trailing_metadata_ = metadata ; <nl> } <nl> <nl> - virtual void SetRecvMessage ( void * message ) override { <nl> - recv_message_ = message ; <nl> - } <nl> + void SetRecvMessage ( void * message ) override { recv_message_ = message ; } <nl> <nl> - virtual void SetRecvInitialMetadata ( internal : : MetadataMap * map ) override { <nl> + void SetRecvInitialMetadata ( MetadataMap * map ) override { <nl> recv_initial_metadata_ = map ; <nl> } <nl> <nl> - virtual void SetRecvStatus ( Status * status ) override { recv_status_ = status ; } <nl> + void SetRecvStatus ( Status * status ) override { recv_status_ = status ; } <nl> <nl> - virtual void SetRecvTrailingMetadata ( internal : : MetadataMap * map ) override { <nl> + void SetRecvTrailingMetadata ( MetadataMap * map ) override { <nl> recv_trailing_metadata_ = map ; <nl> } <nl> <nl> - virtual std : : unique_ptr < ChannelInterface > GetInterceptedChannel ( ) override { <nl> + std : : unique_ptr < ChannelInterface > GetInterceptedChannel ( ) override { <nl> auto * info = call_ - > client_rpc_info ( ) ; <nl> if ( info = = nullptr ) { <nl> return std : : unique_ptr < ChannelInterface > ( nullptr ) ; <nl> } <nl> / / The intercepted channel starts from the interceptor just after the <nl> / / current interceptor <nl> - return std : : unique_ptr < ChannelInterface > ( new internal : : InterceptedChannel ( <nl> - reinterpret_cast < grpc : : ChannelInterface * > ( info - > channel ( ) ) , <nl> - curr_iteration_ + 1 ) ) ; <nl> + return std : : unique_ptr < ChannelInterface > ( new InterceptedChannel ( <nl> + info - > channel ( ) , current_interceptor_index_ + 1 ) ) ; <nl> } <nl> <nl> / / Clears all state <nl> class InterceptorBatchMethodsImpl : public InternalInterceptorBatchMethods { <nl> void RunClientInterceptors ( ) { <nl> auto * rpc_info = call_ - > client_rpc_info ( ) ; <nl> if ( ! reverse_ ) { <nl> - curr_iteration_ = 0 ; <nl> + current_interceptor_index_ = 0 ; <nl> } else { <nl> if ( rpc_info - > hijacked_ ) { <nl> - curr_iteration_ = rpc_info - > hijacked_interceptor_ ; <nl> + current_interceptor_index_ = rpc_info - > hijacked_interceptor_ ; <nl> } else { <nl> - curr_iteration_ = rpc_info - > interceptors_ . size ( ) - 1 ; <nl> + current_interceptor_index_ = rpc_info - > interceptors_ . size ( ) - 1 ; <nl> } <nl> } <nl> - rpc_info - > RunInterceptor ( this , curr_iteration_ ) ; <nl> + rpc_info - > RunInterceptor ( this , current_interceptor_index_ ) ; <nl> } <nl> <nl> void RunServerInterceptors ( ) { <nl> auto * rpc_info = call_ - > server_rpc_info ( ) ; <nl> if ( ! reverse_ ) { <nl> - curr_iteration_ = 0 ; <nl> + current_interceptor_index_ = 0 ; <nl> } else { <nl> - curr_iteration_ = rpc_info - > interceptors_ . size ( ) - 1 ; <nl> + current_interceptor_index_ = rpc_info - > interceptors_ . size ( ) - 1 ; <nl> } <nl> - rpc_info - > RunInterceptor ( this , curr_iteration_ ) ; <nl> + rpc_info - > RunInterceptor ( this , current_interceptor_index_ ) ; <nl> } <nl> <nl> void ProceedClient ( ) { <nl> auto * rpc_info = call_ - > client_rpc_info ( ) ; <nl> if ( rpc_info - > hijacked_ & & ! reverse_ & & <nl> - curr_iteration_ = = rpc_info - > hijacked_interceptor_ & & <nl> + static_cast < size_t > ( current_interceptor_index_ ) = = <nl> + rpc_info - > hijacked_interceptor_ & & <nl> ! ran_hijacking_interceptor_ ) { <nl> / / We now need to provide hijacked recv ops to this interceptor <nl> ClearHookPoints ( ) ; <nl> ops_ - > SetHijackingState ( ) ; <nl> ran_hijacking_interceptor_ = true ; <nl> - rpc_info - > RunInterceptor ( this , curr_iteration_ ) ; <nl> + rpc_info - > RunInterceptor ( this , current_interceptor_index_ ) ; <nl> return ; <nl> } <nl> if ( ! reverse_ ) { <nl> - curr_iteration_ + + ; <nl> + current_interceptor_index_ + + ; <nl> / / We are going down the stack of interceptors <nl> - if ( curr_iteration_ < static_cast < long > ( rpc_info - > interceptors_ . size ( ) ) ) { <nl> + if ( static_cast < size_t > ( current_interceptor_index_ ) < <nl> + rpc_info - > interceptors_ . size ( ) ) { <nl> if ( rpc_info - > hijacked_ & & <nl> - curr_iteration_ > rpc_info - > hijacked_interceptor_ ) { <nl> + static_cast < size_t > ( current_interceptor_index_ ) > <nl> + rpc_info - > hijacked_interceptor_ ) { <nl> / / This is a hijacked RPC and we are done with hijacking <nl> ops_ - > ContinueFillOpsAfterInterception ( ) ; <nl> } else { <nl> - rpc_info - > RunInterceptor ( this , curr_iteration_ ) ; <nl> + rpc_info - > RunInterceptor ( this , current_interceptor_index_ ) ; <nl> } <nl> } else { <nl> / / we are done running all the interceptors without any hijacking <nl> ops_ - > ContinueFillOpsAfterInterception ( ) ; <nl> } <nl> } else { <nl> - curr_iteration_ - - ; <nl> + current_interceptor_index_ - - ; <nl> / / We are going up the stack of interceptors <nl> - if ( curr_iteration_ > = 0 ) { <nl> + if ( current_interceptor_index_ > = 0 ) { <nl> / / Continue running interceptors <nl> - rpc_info - > RunInterceptor ( this , curr_iteration_ ) ; <nl> + rpc_info - > RunInterceptor ( this , current_interceptor_index_ ) ; <nl> } else { <nl> / / we are done running all the interceptors without any hijacking <nl> ops_ - > ContinueFinalizeResultAfterInterception ( ) ; <nl> class InterceptorBatchMethodsImpl : public InternalInterceptorBatchMethods { <nl> void ProceedServer ( ) { <nl> auto * rpc_info = call_ - > server_rpc_info ( ) ; <nl> if ( ! reverse_ ) { <nl> - curr_iteration_ + + ; <nl> - if ( curr_iteration_ < static_cast < long > ( rpc_info - > interceptors_ . size ( ) ) ) { <nl> - return rpc_info - > RunInterceptor ( this , curr_iteration_ ) ; <nl> + current_interceptor_index_ + + ; <nl> + if ( static_cast < size_t > ( current_interceptor_index_ ) < <nl> + rpc_info - > interceptors_ . size ( ) ) { <nl> + return rpc_info - > RunInterceptor ( this , current_interceptor_index_ ) ; <nl> } else if ( ops_ ) { <nl> return ops_ - > ContinueFillOpsAfterInterception ( ) ; <nl> } <nl> } else { <nl> - curr_iteration_ - - ; <nl> + current_interceptor_index_ - - ; <nl> / / We are going up the stack of interceptors <nl> - if ( curr_iteration_ > = 0 ) { <nl> + if ( current_interceptor_index_ > = 0 ) { <nl> / / Continue running interceptors <nl> - return rpc_info - > RunInterceptor ( this , curr_iteration_ ) ; <nl> + return rpc_info - > RunInterceptor ( this , current_interceptor_index_ ) ; <nl> } else if ( ops_ ) { <nl> return ops_ - > ContinueFinalizeResultAfterInterception ( ) ; <nl> } <nl> class InterceptorBatchMethodsImpl : public InternalInterceptorBatchMethods { <nl> } <nl> <nl> void ClearHookPoints ( ) { <nl> - for ( auto i = 0 ; <nl> - i < static_cast < int > ( <nl> - experimental : : InterceptionHookPoints : : NUM_INTERCEPTION_HOOKS ) ; <nl> - i + + ) { <nl> - hooks_ [ i ] = false ; <nl> + for ( auto i = static_cast < experimental : : InterceptionHookPoints > ( 0 ) ; <nl> + i < experimental : : InterceptionHookPoints : : NUM_INTERCEPTION_HOOKS ; <nl> + i = static_cast < experimental : : InterceptionHookPoints > ( <nl> + static_cast < size_t > ( i ) + 1 ) ) { <nl> + hooks_ [ static_cast < size_t > ( i ) ] = false ; <nl> } <nl> } <nl> <nl> std : : array < bool , <nl> - static_cast < int > ( <nl> + static_cast < size_t > ( <nl> experimental : : InterceptionHookPoints : : NUM_INTERCEPTION_HOOKS ) > <nl> hooks_ ; <nl> <nl> - int curr_iteration_ = 0 ; / / Current iterator <nl> + long current_interceptor_index_ = 0 ; / / Current iterator <nl> bool reverse_ = false ; <nl> bool ran_hijacking_interceptor_ = false ; <nl> Call * call_ = <nl> class InterceptorBatchMethodsImpl : public InternalInterceptorBatchMethods { <nl> <nl> void * recv_message_ = nullptr ; <nl> <nl> - internal : : MetadataMap * recv_initial_metadata_ = nullptr ; <nl> + MetadataMap * recv_initial_metadata_ = nullptr ; <nl> <nl> Status * recv_status_ = nullptr ; <nl> <nl> - internal : : MetadataMap * recv_trailing_metadata_ = nullptr ; <nl> + MetadataMap * recv_trailing_metadata_ = nullptr ; <nl> } ; <nl> <nl> } / / namespace internal <nl>
|
Missed reviewer comments
|
grpc/grpc
|
005eb292989fb9d1fb7aee8dfca2e7ac31cfa02f
|
2018-10-26T23:52:18Z
|
mmm a / docs / _static / mxnet - theme / index . html <nl> ppp b / docs / _static / mxnet - theme / index . html <nl> < h3 > MXNet Joining Apache < / h3 > <nl> < div class = " row " > <nl> < div id = " model - zoo - blk " class = " col - lg - 4 col - sm - 12 " > <nl> < span class = " glyphicon glyphicon - folder - open " > < / span > <nl> - < h2 > Model Zoo < / h2 > <nl> - < p > Off the shelf pre - trained models . Fast implementations of many state - of - art models . < / p > <nl> + < h2 > Gluon Model Zoo < / h2 > <nl> + < p > One - click pre - trained models , included in Gluon . Fast implementations of many state - of - the - art models , for plug - and - play effortless use . < / p > <nl> < div class = ' util - btn ' > <nl> - < a id = " model - zoo - link " href = " model_zoo / index . html " > Model zoo < / a > <nl> + < a id = " model - zoo - link " href = " api / python / gluon / model_zoo . html " > Gluon model zoo < / a > <nl> < / div > <nl> < / div > <nl> < div id = " example - blk " class = " col - lg - 4 col - sm - 12 " > <nl> mmm a / docs / api / python / gluon / model_zoo . md <nl> ppp b / docs / api / python / gluon / model_zoo . md <nl> In the rest of this document , we list routines provided by the ` gluon . model_zoo ` <nl> . . automodule : : mxnet . gluon . model_zoo . vision <nl> ` ` ` <nl> <nl> + The following table summarizes the available models . <nl> + <nl> + | Alias | Network | # Parameters | Top - 1 Accuracy | Top - 5 Accuracy | Origin | <nl> + | mmmmmmmmmmmmmmm | mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm | mmmmmmmmmmmm - - | mmmmmmmmmmmmmmm - | mmmmmmmmmmmmmmm - | mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm | <nl> + | alexnet | [ AlexNet ] ( https : / / arxiv . org / abs / 1404 . 5997 ) | 61 , 100 , 840 | 0 . 5492 | 0 . 7803 | Converted from pytorch vision | <nl> + | densenet121 | [ DenseNet - 121 ] ( https : / / arxiv . org / pdf / 1608 . 06993 . pdf ) | 8 , 062 , 504 | 0 . 7497 | 0 . 9225 | Converted from pytorch vision | <nl> + | densenet161 | [ DenseNet - 161 ] ( https : / / arxiv . org / pdf / 1608 . 06993 . pdf ) | 28 , 900 , 936 | 0 . 7770 | 0 . 9380 | Converted from pytorch vision | <nl> + | densenet169 | [ DenseNet - 169 ] ( https : / / arxiv . org / pdf / 1608 . 06993 . pdf ) | 14 , 307 , 880 | 0 . 7617 | 0 . 9317 | Converted from pytorch vision | <nl> + | densenet201 | [ DenseNet - 201 ] ( https : / / arxiv . org / pdf / 1608 . 06993 . pdf ) | 20 , 242 , 984 | 0 . 7732 | 0 . 9362 | Converted from pytorch vision | <nl> + | inceptionv3 | [ Inception V3 299x299 ] ( http : / / arxiv . org / abs / 1512 . 00567 ) | 23 , 869 , 000 | 0 . 7755 | 0 . 9364 | Converted from pytorch vision | <nl> + | mobilenet0 . 25 | [ MobileNet 0 . 25 ] ( https : / / arxiv . org / abs / 1704 . 04861 ) | 475 , 544 | 0 . 5185 | 0 . 7608 | Trained with [ script ] ( https : / / github . com / zhreshold / mxnet / blob / 2fbfdbcbacff8b738bd9f44e9c8cefc84d6dfbb5 / example / gluon / train_imagenet . py ) | <nl> + | mobilenet0 . 5 | [ MobileNet 0 . 5 ] ( https : / / arxiv . org / abs / 1704 . 04861 ) | 1 , 342 , 536 | 0 . 6307 | 0 . 8475 | Trained with [ script ] ( https : / / github . com / zhreshold / mxnet / blob / 2fbfdbcbacff8b738bd9f44e9c8cefc84d6dfbb5 / example / gluon / train_imagenet . py ) | <nl> + | mobilenet0 . 75 | [ MobileNet 0 . 75 ] ( https : / / arxiv . org / abs / 1704 . 04861 ) | 2 , 601 , 976 | 0 . 6738 | 0 . 8782 | Trained with [ script ] ( https : / / github . com / zhreshold / mxnet / blob / 2fbfdbcbacff8b738bd9f44e9c8cefc84d6dfbb5 / example / gluon / train_imagenet . py ) | <nl> + | mobilenet1 . 0 | [ MobileNet 1 . 0 ] ( https : / / arxiv . org / abs / 1704 . 04861 ) | 4 , 253 , 864 | 0 . 7105 | 0 . 9006 | Trained with [ script ] ( https : / / github . com / zhreshold / mxnet / blob / 2fbfdbcbacff8b738bd9f44e9c8cefc84d6dfbb5 / example / gluon / train_imagenet . py ) | <nl> + | resnet18_v1 | [ ResNet - 18 V1 ] ( http : / / arxiv . org / abs / 1512 . 03385 ) | 11 , 699 , 112 | 0 . 6803 | 0 . 8818 | Converted from pytorch vision | <nl> + | resnet34_v1 | [ ResNet - 34 V1 ] ( http : / / arxiv . org / abs / 1512 . 03385 ) | 21 , 814 , 696 | 0 . 7202 | 0 . 9066 | Converted from pytorch vision | <nl> + | resnet50_v1 | [ ResNet - 50 V1 ] ( http : / / arxiv . org / abs / 1512 . 03385 ) | 25 , 629 , 032 | 0 . 7540 | 0 . 9266 | Trained with [ script ] ( https : / / github . com / zhreshold / mxnet / blob / 2fbfdbcbacff8b738bd9f44e9c8cefc84d6dfbb5 / example / gluon / train_imagenet . py ) | <nl> + | resnet101_v1 | [ ResNet - 101 V1 ] ( http : / / arxiv . org / abs / 1512 . 03385 ) | 44 , 695 , 144 | 0 . 7693 | 0 . 9334 | Trained with [ script ] ( https : / / github . com / zhreshold / mxnet / blob / 2fbfdbcbacff8b738bd9f44e9c8cefc84d6dfbb5 / example / gluon / train_imagenet . py ) | <nl> + | resnet152_v1 | [ ResNet - 152 V1 ] ( http : / / arxiv . org / abs / 1512 . 03385 ) | 60 , 404 , 072 | 0 . 7727 | 0 . 9353 | Trained with [ script ] ( https : / / github . com / zhreshold / mxnet / blob / 2fbfdbcbacff8b738bd9f44e9c8cefc84d6dfbb5 / example / gluon / train_imagenet . py ) | <nl> + | resnet18_v2 | [ ResNet - 18 V2 ] ( https : / / arxiv . org / abs / 1603 . 05027 ) | 11 , 695 , 796 | 0 . 6961 | 0 . 8901 | Trained with [ script ] ( https : / / github . com / apache / incubator - mxnet / blob / 4dcd96ae2f6820e01455079d00f49db1cd21eda9 / example / gluon / image_classification . py ) | <nl> + | resnet34_v2 | [ ResNet - 34 V2 ] ( https : / / arxiv . org / abs / 1603 . 05027 ) | 21 , 811 , 380 | 0 . 7324 | 0 . 9125 | Trained with [ script ] ( https : / / github . com / apache / incubator - mxnet / blob / 4dcd96ae2f6820e01455079d00f49db1cd21eda9 / example / gluon / image_classification . py ) | <nl> + | resnet50_v2 | [ ResNet - 50 V2 ] ( https : / / arxiv . org / abs / 1603 . 05027 ) | 25 , 595 , 060 | 0 . 7622 | 0 . 9297 | Trained with [ script ] ( https : / / github . com / zhreshold / mxnet / blob / 2fbfdbcbacff8b738bd9f44e9c8cefc84d6dfbb5 / example / gluon / train_imagenet . py ) | <nl> + | resnet101_v2 | [ ResNet - 101 V2 ] ( https : / / arxiv . org / abs / 1603 . 05027 ) | 44 , 639 , 412 | 0 . 7747 | 0 . 9375 | Trained with [ script ] ( https : / / github . com / zhreshold / mxnet / blob / 2fbfdbcbacff8b738bd9f44e9c8cefc84d6dfbb5 / example / gluon / train_imagenet . py ) | <nl> + | resnet152_v2 | [ ResNet - 152 V2 ] ( https : / / arxiv . org / abs / 1603 . 05027 ) | 60 , 329 , 140 | 0 . 7833 | 0 . 9409 | Trained with [ script ] ( https : / / github . com / zhreshold / mxnet / blob / 2fbfdbcbacff8b738bd9f44e9c8cefc84d6dfbb5 / example / gluon / train_imagenet . py ) | <nl> + | squeezenet1 . 0 | [ SqueezeNet 1 . 0 ] ( https : / / arxiv . org / abs / 1602 . 07360 ) | 1 , 248 , 424 | 0 . 5611 | 0 . 7909 | Converted from pytorch vision | <nl> + | squeezenet1 . 1 | [ SqueezeNet 1 . 1 ] ( https : / / github . com / DeepScale / SqueezeNet / tree / master / SqueezeNet_v1 . 1 ) | 1 , 235 , 496 | 0 . 5496 | 0 . 7817 | Converted from pytorch vision | <nl> + | vgg11 | [ VGG - 11 ] ( https : / / arxiv . org / abs / 1409 . 1556 ) | 132 , 863 , 336 | 0 . 6662 | 0 . 8734 | Converted from pytorch vision | <nl> + | vgg13 | [ VGG - 13 ] ( https : / / arxiv . org / abs / 1409 . 1556 ) | 133 , 047 , 848 | 0 . 6774 | 0 . 8811 | Converted from pytorch vision | <nl> + | vgg16 | [ VGG - 16 ] ( https : / / arxiv . org / abs / 1409 . 1556 ) | 138 , 357 , 544 | 0 . 6986 | 0 . 8945 | Converted from pytorch vision | <nl> + | vgg19 | [ VGG - 19 ] ( https : / / arxiv . org / abs / 1409 . 1556 ) | 143 , 667 , 240 | 0 . 7072 | 0 . 8988 | Converted from pytorch vision | <nl> + | vgg11_bn | [ VGG - 11 with batch normalization ] ( https : / / arxiv . org / abs / 1409 . 1556 ) | 132 , 874 , 344 | 0 . 6859 | 0 . 8872 | Converted from pytorch vision | <nl> + | vgg13_bn | [ VGG - 13 with batch normalization ] ( https : / / arxiv . org / abs / 1409 . 1556 ) | 133 , 059 , 624 | 0 . 6884 | 0 . 8882 | Converted from pytorch vision | <nl> + | vgg16_bn | [ VGG - 16 with batch normalization ] ( https : / / arxiv . org / abs / 1409 . 1556 ) | 138 , 374 , 440 | 0 . 7142 | 0 . 9043 | Converted from pytorch vision | <nl> + | vgg19_bn | [ VGG - 19 with batch normalization ] ( https : / / arxiv . org / abs / 1409 . 1556 ) | 143 , 689 , 256 | 0 . 7241 | 0 . 9093 | Converted from pytorch vision | <nl> + <nl> ` ` ` eval_rst <nl> . . autosummary : : <nl> : nosignatures : <nl> mmm a / python / mxnet / gluon / model_zoo / vision / __init__ . py <nl> ppp b / python / mxnet / gluon / model_zoo / vision / __init__ . py <nl> <nl> squeezenet = vision . squeezenet1_0 ( ) <nl> densenet = vision . densenet_161 ( ) <nl> <nl> - We provide pre - trained models for all the models except ResNet V2 . <nl> - These can constructed by passing ` ` pretrained = True ` ` : <nl> + We provide pre - trained models for all the listed models . <nl> + These models can constructed by passing ` ` pretrained = True ` ` : <nl> <nl> . . code : : <nl> <nl>
|
update front - page model zoo to gluon model zoo ( )
|
apache/incubator-mxnet
|
4e3ac338c84e9b6662f9fa5a40d84c3c39fdef42
|
2018-01-03T18:38:14Z
|
deleted file mode 100644 <nl> index c33b68589ab8 . . 000000000000 <nl> mmm a / tools / shared / cwrap_common . py <nl> ppp / dev / null <nl> <nl> - # this code should be common among cwrap and TensorLib preprocessing <nl> - # for now , I have put it in one place but right now is copied out of cwrap <nl> - <nl> - from copy import deepcopy <nl> - from itertools import product <nl> - <nl> - <nl> - def parse_arguments ( args ) : <nl> - new_args = [ ] <nl> - for arg in args : <nl> - # Simple arg declaration of form " < type > < name > " <nl> - if isinstance ( arg , str ) : <nl> - t , _ , name = arg . partition ( ' ' ) <nl> - new_args . append ( { ' type ' : t , ' name ' : name } ) <nl> - elif isinstance ( arg , dict ) : <nl> - if ' arg ' in arg : <nl> - arg [ ' type ' ] , _ , arg [ ' name ' ] = arg [ ' arg ' ] . partition ( ' ' ) <nl> - del arg [ ' arg ' ] <nl> - new_args . append ( arg ) <nl> - else : <nl> - assert False <nl> - return new_args <nl> - <nl> - <nl> - def set_declaration_defaults ( declaration ) : <nl> - declaration . setdefault ( ' arguments ' , [ ] ) <nl> - declaration . setdefault ( ' return ' , ' void ' ) <nl> - if ' cname ' not in declaration : <nl> - declaration [ ' cname ' ] = declaration [ ' name ' ] <nl> - if ' backends ' not in declaration : <nl> - declaration [ ' backends ' ] = [ ' CPU ' , ' CUDA ' ] <nl> - if ' api_name ' not in declaration : <nl> - declaration [ ' api_name ' ] = ( declaration [ ' python_name ' ] <nl> - if ' python_name ' in declaration else declaration [ ' name ' ] ) <nl> - # Simulate multiple dispatch , even if it ' s not necessary <nl> - if ' options ' not in declaration : <nl> - declaration [ ' options ' ] = [ { ' arguments ' : declaration [ ' arguments ' ] } ] <nl> - del declaration [ ' arguments ' ] <nl> - # Parse arguments ( some of them can be strings ) <nl> - for option in declaration [ ' options ' ] : <nl> - option [ ' arguments ' ] = parse_arguments ( option [ ' arguments ' ] ) <nl> - # Propagate defaults from declaration to options <nl> - for option in declaration [ ' options ' ] : <nl> - for k , v in declaration . items ( ) : <nl> - # TODO ( zach ) : why does cwrap not propagate ' name ' ? I need it <nl> - # propagaged for TensorLib <nl> - if k ! = ' options ' : <nl> - option . setdefault ( k , v ) <nl> - <nl> - # TODO ( zach ) : added option to remove keyword handling for C + + which cannot <nl> - # support it . <nl> - <nl> - <nl> - def filter_unique_options ( options , allow_kwarg , type_to_signature , remove_self ) : <nl> - def exclude_arg ( arg ) : <nl> - return arg . get ( ' ignore_check ' ) <nl> - <nl> - def exclude_arg_with_self_check ( arg ) : <nl> - return exclude_arg ( arg ) or ( remove_self and arg [ ' name ' ] = = ' self ' ) <nl> - <nl> - def signature ( option , kwarg_only_count ) : <nl> - if kwarg_only_count = = 0 : <nl> - kwarg_only_count = None <nl> - else : <nl> - kwarg_only_count = - kwarg_only_count <nl> - arg_signature = ' # ' . join ( <nl> - type_to_signature . get ( arg [ ' type ' ] , arg [ ' type ' ] ) <nl> - for arg in option [ ' arguments ' ] [ : kwarg_only_count ] <nl> - if not exclude_arg_with_self_check ( arg ) ) <nl> - if kwarg_only_count is None : <nl> - return arg_signature <nl> - kwarg_only_signature = ' # ' . join ( <nl> - arg [ ' name ' ] + ' # ' + arg [ ' type ' ] <nl> - for arg in option [ ' arguments ' ] [ kwarg_only_count : ] <nl> - if not exclude_arg ( arg ) ) <nl> - return arg_signature + " # - # " + kwarg_only_signature <nl> - seen_signatures = set ( ) <nl> - unique = [ ] <nl> - for option in options : <nl> - # if only check num_kwarg_only = = 0 if allow_kwarg = = False <nl> - limit = len ( option [ ' arguments ' ] ) if allow_kwarg else 0 <nl> - for num_kwarg_only in range ( 0 , limit + 1 ) : <nl> - sig = signature ( option , num_kwarg_only ) <nl> - if sig not in seen_signatures : <nl> - if num_kwarg_only > 0 : <nl> - for arg in option [ ' arguments ' ] [ - num_kwarg_only : ] : <nl> - arg [ ' kwarg_only ' ] = True <nl> - unique . append ( option ) <nl> - seen_signatures . add ( sig ) <nl> - break <nl> - return unique <nl> - <nl> - <nl> - def enumerate_options_due_to_default ( declaration , <nl> - allow_kwarg = True , type_to_signature = [ ] , remove_self = True ) : <nl> - # TODO ( zach ) : in cwrap this is shared among all declarations <nl> - # but seems to assume that all declarations will have the same <nl> - new_options = [ ] <nl> - for option in declaration [ ' options ' ] : <nl> - optional_args = [ ] <nl> - for i , arg in enumerate ( option [ ' arguments ' ] ) : <nl> - if ' default ' in arg : <nl> - optional_args . append ( i ) <nl> - for permutation in product ( ( True , False ) , repeat = len ( optional_args ) ) : <nl> - option_copy = deepcopy ( option ) <nl> - for i , bit in zip ( optional_args , permutation ) : <nl> - arg = option_copy [ ' arguments ' ] [ i ] <nl> - if not bit : <nl> - arg [ ' type ' ] = ' CONSTANT ' <nl> - arg [ ' ignore_check ' ] = True <nl> - # PyYAML interprets NULL as None . . . <nl> - arg [ ' name ' ] = ' NULL ' if arg [ ' default ' ] is None else arg [ ' default ' ] <nl> - new_options . append ( option_copy ) <nl> - declaration [ ' options ' ] = filter_unique_options ( new_options , <nl> - allow_kwarg , type_to_signature , remove_self ) <nl> - <nl> - <nl> - def sort_by_number_of_options ( declaration , reverse = True ) : <nl> - def num_checked_args ( option ) : <nl> - return sum ( map ( lambda a : not a . get ( ' ignore_check ' , False ) , option [ ' arguments ' ] ) ) <nl> - declaration [ ' options ' ] . sort ( key = num_checked_args , reverse = reverse ) <nl> new file mode 120000 <nl> index 000000000000 . . 1293e5a67e18 <nl> mmm / dev / null <nl> ppp b / tools / shared / cwrap_common . py <nl> @ @ - 0 , 0 + 1 @ @ <nl> + . . / . . / torch / lib / ATen / common_with_cwrap . py <nl> \ No newline at end of file <nl> mmm a / torch / csrc / Exceptions . h <nl> ppp b / torch / csrc / Exceptions . h <nl> struct python_error : public std : : exception { <nl> <nl> # ifdef _THP_CORE <nl> <nl> - struct THException : public std : : exception { <nl> - THException ( const char * msg ) : msg ( msg ) { } ; <nl> - <nl> - virtual const char * what ( ) const throw ( ) { <nl> - return msg . c_str ( ) ; <nl> - } <nl> - <nl> - std : : string msg ; <nl> - } ; <nl> - <nl> - struct THArgException : public THException { <nl> - THArgException ( const char * msg , int argNumber ) : THException ( msg ) , argNumber ( argNumber ) { } ; <nl> - <nl> - const int argNumber ; <nl> - } ; <nl> - <nl> bool THPException_init ( PyObject * module ) ; <nl> # endif <nl> <nl> mmm a / torch / csrc / Module . cpp <nl> ppp b / torch / csrc / Module . cpp <nl> <nl> # include < unordered_map > <nl> # include < libshm . h > <nl> # include < TH / TH . h > <nl> + # include < ATen / ATen . h > <nl> <nl> # include " torch / csrc / utils / python_strings . h " <nl> <nl> static PyMethodDef TorchMethods [ ] = { <nl> { NULL , NULL , 0 , NULL } <nl> } ; <nl> <nl> - static void errorHandler ( const char * msg , void * data ) <nl> - { <nl> - throw THException ( msg ) ; <nl> - } <nl> - <nl> - static void errorHandlerArg ( int argNumber , const char * msg , void * data ) <nl> - { <nl> - throw THArgException ( msg , argNumber ) ; <nl> - } <nl> - <nl> - static void updateErrorHandlers ( ) <nl> - { <nl> - THSetDefaultErrorHandler ( errorHandler , NULL ) ; <nl> - THSetDefaultArgErrorHandler ( errorHandlerArg , NULL ) ; <nl> - } <nl> - <nl> bool THCPDoubleStorage_init ( PyObject * module ) ; <nl> bool THCPFloatStorage_init ( PyObject * module ) ; <nl> bool THCPHalfStorage_init ( PyObject * module ) ; <nl> PyMODINIT_FUNC PyInit__C ( ) <nl> ASSERT_TRUE ( THPDefaultGenerator ! = nullptr ) ; <nl> ASSERT_TRUE ( PyModule_AddObject ( module , " default_generator " , ( PyObject * ) THPDefaultGenerator ) = = 0 ) ; <nl> <nl> - updateErrorHandlers ( ) ; <nl> + / / force ATen to initialize because it handles <nl> + / / setting up TH Errors so that they throw C + + exceptions <nl> + at : : init ( ) ; <nl> <nl> # ifdef WITH_NUMPY <nl> import_array ( ) ; <nl> mmm a / torch / csrc / cuda / Module . cpp <nl> ppp b / torch / csrc / cuda / Module . cpp <nl> <nl> # include < stdbool . h > <nl> # include < unordered_map > <nl> # include < TH / TH . h > <nl> + # include < ATen / ATen . h > <nl> # include < THC / THCCachingAllocator . h > <nl> # ifdef WITH_NCCL <nl> # include < nccl . h > <nl> PyObject * THCPModule_cudaUnlockMutex ( PyObject * module ) <nl> bool THCPModule_initCuda ( PyObject * torch_module ) { <nl> HANDLE_TH_ERRORS <nl> # define ASSERT_TRUE ( cond ) if ( ! ( cond ) ) { return false ; } <nl> - state = THCState_alloc ( ) ; <nl> - THCState_setDeviceAllocator ( state , THCCachingAllocator_get ( ) ) ; <nl> - state - > cudaHostAllocator = & THCCachingHostAllocator ; <nl> - THCudaInit ( state ) ; <nl> + state = at : : globalContext ( ) . lazyInitCUDA ( ) ; <nl> <nl> # ifdef USE_MAGMA <nl> THCMagma_init ( state ) ; <nl>
|
initialize aten and pytorch to share the same THCState
|
pytorch/pytorch
|
9d8cff9bc1cb182771e2102d57b1a7de70ef6908
|
2017-07-11T14:35:03Z
|
mmm a / lib / AST / Decl . cpp <nl> ppp b / lib / AST / Decl . cpp <nl> ProtocolDecl : : getInheritedProtocols ( ) const { <nl> llvm : : TinyPtrVector < AssociatedTypeDecl * > <nl> ProtocolDecl : : getAssociatedTypeMembers ( ) const { <nl> llvm : : TinyPtrVector < AssociatedTypeDecl * > result ; <nl> - if ( ! hasClangNode ( ) ) { <nl> - for ( auto member : getMembers ( ) ) { <nl> - if ( auto ATD = dyn_cast < AssociatedTypeDecl > ( member ) ) { <nl> - result . push_back ( ATD ) ; <nl> - } <nl> + <nl> + / / Clang - imported protocols never have associated types . <nl> + if ( hasClangNode ( ) ) <nl> + return result ; <nl> + <nl> + / / Deserialized @ objc protocols never have associated types . <nl> + if ( ! getParentSourceFile ( ) & & isObjC ( ) ) <nl> + return result ; <nl> + <nl> + / / Find the associated type declarations . <nl> + for ( auto member : getMembers ( ) ) { <nl> + if ( auto ATD = dyn_cast < AssociatedTypeDecl > ( member ) ) { <nl> + result . push_back ( ATD ) ; <nl> } <nl> } <nl> + <nl> return result ; <nl> } <nl> <nl> similarity index 84 % <nl> rename from validation - test / compiler_crashers / 28859 - resolver - unable - to - resolve - type - witness . swift <nl> rename to validation - test / compiler_crashers_fixed / 28859 - resolver - unable - to - resolve - type - witness . swift <nl> mmm a / validation - test / compiler_crashers / 28859 - resolver - unable - to - resolve - type - witness . swift <nl> ppp b / validation - test / compiler_crashers_fixed / 28859 - resolver - unable - to - resolve - type - witness . swift <nl> <nl> / / See https : / / swift . org / LICENSE . txt for license information <nl> / / See https : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> <nl> - / / REQUIRES : asserts <nl> - / / RUN : not - - crash % target - swift - frontend % s - emit - ir <nl> + <nl> + / / RUN : not % target - swift - frontend % s - emit - ir <nl> class a : P @ objc protocol P { { } func a : a { } { } typealias a <nl>
|
[ AST ] Don ’ t deserialize members of @ objc protocol looking for associated types
|
apple/swift
|
de18384d89c730b641bafa4ff54e35f2c8dcedf4
|
2018-10-07T05:08:45Z
|
mmm a / tensorflow / compiler / xla / python / xla_client . py <nl> ppp b / tensorflow / compiler / xla / python / xla_client . py <nl> <nl> # which case we need to be able to detect when incompatible versions are <nl> # installed . <nl> def version ( ) : <nl> - return ( 0 , 1 , 7 ) <nl> + return ( 0 , 1 , 8 ) <nl> <nl> <nl> _OP_METADATA_FIELDS = [ <nl> def transfer_from_outfeed ( shape , replica_number = None ) : <nl> <nl> <nl> class Computation ( object ) : <nl> - " " " Python wrapper for a local XLA Computation . <nl> + " " " Python wrapper for an XLA Computation . <nl> <nl> - A Computation can be compiled to form an Executable . Otherwise , it <nl> - can still be used as a Computation where required by the <nl> - ComputationBuilder methods . <nl> + A Computation can be compiled to form an Executable , or used as a <nl> + subcomputation in ComputationBuilder methods . <nl> " " " <nl> <nl> - def __init__ ( self , c_computation , backend = XLA_LOCAL_BACKEND ) : <nl> + def __init__ ( self , c_computation , backend = None ) : <nl> self . _c_computation = c_computation <nl> + # The backend argument is deprecated . Pass a backend to Compile ( ) instead . <nl> self . _backend = backend <nl> <nl> @ property <nl> def GetProto ( self ) : <nl> proto = hlo_pb2 . HloModuleProto . FromString ( serialized ) <nl> return proto <nl> <nl> - def Compile ( self , argument_shapes = ( ) , compile_options = None , layout_fn = None ) : <nl> + def Compile ( self , argument_shapes = ( ) , compile_options = None , layout_fn = None , <nl> + backend = None ) : <nl> " " " Compiles a computation . <nl> <nl> Computations are the result of a " ComputationBuild ' ing " process . <nl> def Compile ( self , argument_shapes = ( ) , compile_options = None , layout_fn = None ) : <nl> compile_options : options to use for compilation , includes an optional laid <nl> out result shape for the computation . <nl> layout_fn : lambda that is used to lay out the argument / result shapes . <nl> + backend : a ` Backend ` for which an executable should be generated . <nl> <nl> Returns : <nl> A Executable instance . <nl> " " " <nl> + backend = backend or self . _backend or XLA_LOCAL_BACKEND <nl> result_shape = _wrap_shape ( self . computation . GetReturnValueShape ( ) ) <nl> <nl> if layout_fn : <nl> def Compile ( self , argument_shapes = ( ) , compile_options = None , layout_fn = None ) : <nl> <nl> compile_options = compile_options or CompileOptions ( ) <nl> compile_options . result_shape = result_shape <nl> - c = self . _backend . compile ( self . computation , argument_shapes , <nl> - compile_options ) <nl> - return Executable ( c , backend = self . _backend ) <nl> + c = backend . compile ( self . computation , argument_shapes , compile_options ) <nl> + return Executable ( c , backend = backend ) <nl> <nl> def CompileWithExampleArguments ( self , <nl> arguments = ( ) , <nl> compile_options = None , <nl> - layout_fn = None ) : <nl> + layout_fn = None , <nl> + backend = None ) : <nl> return self . Compile ( <nl> argument_shapes = [ Shape . from_pyval ( arg ) for arg in arguments ] , <nl> compile_options = compile_options , <nl> - layout_fn = layout_fn ) <nl> + layout_fn = layout_fn , <nl> + backend = backend ) <nl> <nl> def GetProgramShape ( self ) : <nl> ( arg_shapes , result_shape ) = self . _c_computation . GetProgramShape ( ) <nl> def __del__ ( self ) : <nl> class Executable ( object ) : <nl> " " " Python wrapper for an XLA Executable . " " " <nl> <nl> - def __init__ ( self , c_executable , backend = XLA_LOCAL_BACKEND ) : <nl> + def __init__ ( self , c_executable , backend = None ) : <nl> self . _c_executable = c_executable <nl> self . _backend = backend <nl> <nl> def __init__ ( self , name ) : <nl> self . _client = c_api . ComputationBuilder ( name . encode ( ' utf8 ' ) ) <nl> self . _parameter_numbering = itertools . count ( ) <nl> <nl> - def Build ( self , root = None , backend = XLA_LOCAL_BACKEND ) : <nl> + def Build ( self , root = None , backend = None ) : <nl> + " " " Builds a ` Computation ` from the contents of the builder . <nl> + <nl> + Args : <nl> + root : if not None , the operator containing the return value of the <nl> + computation . <nl> + backend : deprecated . Pass a ` backend ` to ` Computation . Compile ` instead . <nl> + Returns : <nl> + A ` Computation ` . <nl> + " " " <nl> if root is not None : <nl> return Computation ( self . _client . BuildWithRoot ( root ) , backend = backend ) <nl> else : <nl>
|
[ XLA : Python ] Don ' t require a Backend to call ComputationBuilder . Build ( ) , instead require it on Computation . Compile ( ) .
|
tensorflow/tensorflow
|
fb4a5700b0342b5240ad54ec23abe1d254d97e3b
|
2019-02-13T18:58:10Z
|
mmm a / src / webGLWorker . js <nl> ppp b / src / webGLWorker . js <nl> function WebGLWorker ( ) { <nl> this . uniform1i = function ( location , data ) { <nl> commandBuffer . push ( ' uniform1i ' , 2 , location . id , data ) ; <nl> } ; <nl> + this . uniform1f = function ( location , data ) { <nl> + commandBuffer . push ( ' uniform1f ' , 2 , location . id , data ) ; <nl> + } ; <nl> this . uniform4fv = function ( location , data ) { <nl> commandBuffer . push ( ' uniform4fv ' , 2 , location . id , new Float32Array ( data ) ) ; <nl> } ; <nl>
|
uniform1f
|
emscripten-core/emscripten
|
34f6c172da1dd2bd51e80a06007efd75581c38a3
|
2014-06-13T23:52:05Z
|
mmm a / cocos / gui / UILayout . cpp <nl> ppp b / cocos / gui / UILayout . cpp <nl> <nl> # include " gui / UILayout . h " <nl> # include " gui / UIHelper . h " <nl> # include " extensions / GUI / CCControlExtension / CCScale9Sprite . h " <nl> + # include " kazmath / GL / matrix . h " <nl> + # include " CCGLProgram . h " <nl> + # include " CCShaderCache . h " <nl> + # include " CCDirector . h " <nl> + # include " CCDrawingPrimitives . h " <nl> + # include " CCRenderer . h " <nl> + # include " CCGroupCommand . h " <nl> + # include " CCCustomCommand . h " <nl> <nl> NS_CC_BEGIN <nl> <nl> static const int BACKGROUNDIMAGE_Z = ( - 1 ) ; <nl> static const int BCAKGROUNDCOLORRENDERER_Z = ( - 2 ) ; <nl> <nl> static GLint g_sStencilBits = - 1 ; <nl> + static GLint s_layer = - 1 ; <nl> <nl> Layout : : Layout ( ) : <nl> _clippingEnabled ( false ) , <nl> _backGroundImageTextureSize ( Size : : ZERO ) , <nl> _layoutType ( LAYOUT_ABSOLUTE ) , <nl> _clippingType ( LAYOUT_CLIPPING_STENCIL ) , <nl> _clippingStencil ( nullptr ) , <nl> - _handleScissor ( false ) , <nl> _scissorRectDirty ( false ) , <nl> _clippingRect ( Rect : : ZERO ) , <nl> _clippingParent ( nullptr ) , <nl> - _doLayoutDirty ( true ) <nl> + _doLayoutDirty ( true ) , <nl> + _currentStencilEnabled ( GL_FALSE ) , <nl> + _currentStencilWriteMask ( ~ 0 ) , <nl> + _currentStencilFunc ( GL_ALWAYS ) , <nl> + _currentStencilRef ( 0 ) , <nl> + _currentStencilValueMask ( ~ 0 ) , <nl> + _currentStencilFail ( GL_KEEP ) , <nl> + _currentStencilPassDepthFail ( GL_KEEP ) , <nl> + _currentStencilPassDepthPass ( GL_KEEP ) , <nl> + _currentDepthWriteMask ( GL_TRUE ) , <nl> + _currentAlphaTestEnabled ( GL_FALSE ) , <nl> + _currentAlphaTestFunc ( GL_ALWAYS ) , <nl> + _currentAlphaTestRef ( 1 ) <nl> { <nl> _widgetType = WidgetTypeContainer ; <nl> } <nl> _doLayoutDirty ( true ) <nl> Layout : : ~ Layout ( ) <nl> { <nl> } <nl> + <nl> + void Layout : : onEnter ( ) <nl> + { <nl> + Widget : : onEnter ( ) ; <nl> + if ( _clippingStencil ) <nl> + { <nl> + _clippingStencil - > onEnter ( ) ; <nl> + } <nl> + } <nl> + <nl> + void Layout : : onExit ( ) <nl> + { <nl> + Widget : : onExit ( ) ; <nl> + if ( _clippingStencil ) <nl> + { <nl> + _clippingStencil - > onExit ( ) ; <nl> + } <nl> + } <nl> <nl> Layout * Layout : : create ( ) <nl> { <nl> void Layout : : sortAllChildren ( ) <nl> <nl> void Layout : : stencilClippingVisit ( ) <nl> { <nl> - if ( ! _clippingStencil | | ! _clippingStencil - > isVisible ( ) ) <nl> - { <nl> - Node : : visit ( ) ; <nl> - return ; <nl> - } <nl> - if ( g_sStencilBits < 1 ) <nl> - { <nl> - Node : : visit ( ) ; <nl> + if ( ! _visible ) <nl> return ; <nl> - } <nl> - static GLint layer = - 1 ; <nl> - if ( layer + 1 = = g_sStencilBits ) <nl> + <nl> + kmGLPushMatrix ( ) ; <nl> + transform ( ) ; <nl> + / / Add group command <nl> + <nl> + Renderer * renderer = Director : : getInstance ( ) - > getRenderer ( ) ; <nl> + <nl> + _groupCommand . init ( 0 , _vertexZ ) ; <nl> + renderer - > addCommand ( & _groupCommand ) ; <nl> + <nl> + renderer - > pushGroup ( _groupCommand . getRenderQueueID ( ) ) ; <nl> + <nl> + _beforeVisitCmdStencil . init ( 0 , _vertexZ ) ; <nl> + _beforeVisitCmdStencil . func = CC_CALLBACK_0 ( Layout : : onBeforeVisitStencil , this ) ; <nl> + renderer - > addCommand ( & _beforeVisitCmdStencil ) ; <nl> + <nl> + _clippingStencil - > visit ( ) ; <nl> + <nl> + _afterDrawStencilCmd . init ( 0 , _vertexZ ) ; <nl> + _afterDrawStencilCmd . func = CC_CALLBACK_0 ( Layout : : onAfterDrawStencil , this ) ; <nl> + renderer - > addCommand ( & _afterDrawStencilCmd ) ; <nl> + <nl> + int i = 0 ; <nl> + <nl> + if ( ! _children . empty ( ) ) <nl> { <nl> - static bool once = true ; <nl> - if ( once ) <nl> + sortAllChildren ( ) ; <nl> + / / draw children zOrder < 0 <nl> + for ( ; i < _children . size ( ) ; i + + ) <nl> { <nl> - char warning [ 200 ] = { 0 } ; <nl> - snprintf ( warning , sizeof ( warning ) , " Nesting more than % d stencils is not supported . Everything will be drawn without stencil for this node and its childs . " , g_sStencilBits ) ; <nl> - CCLOG ( " % s " , warning ) ; <nl> + auto node = _children . at ( i ) ; <nl> <nl> - once = false ; <nl> + if ( node & & node - > getZOrder ( ) < 0 ) <nl> + node - > visit ( ) ; <nl> + else <nl> + break ; <nl> } <nl> - Node : : visit ( ) ; <nl> - return ; <nl> + / / self draw <nl> + this - > draw ( ) ; <nl> + <nl> + for ( auto it = _children . cbegin ( ) + i ; it ! = _children . cend ( ) ; + + it ) <nl> + ( * it ) - > visit ( ) ; <nl> } <nl> - layer + + ; <nl> - GLint mask_layer = 0x1 < < layer ; <nl> + else <nl> + { <nl> + this - > draw ( ) ; <nl> + } <nl> + <nl> + _afterVisitCmdStencil . init ( 0 , _vertexZ ) ; <nl> + _afterVisitCmdStencil . func = CC_CALLBACK_0 ( Layout : : onAfterVisitStencil , this ) ; <nl> + renderer - > addCommand ( & _afterVisitCmdStencil ) ; <nl> + <nl> + renderer - > popGroup ( ) ; <nl> + <nl> + kmGLPopMatrix ( ) ; <nl> + } <nl> + <nl> + void Layout : : onBeforeVisitStencil ( ) <nl> + { <nl> + s_layer + + ; <nl> + GLint mask_layer = 0x1 < < s_layer ; <nl> GLint mask_layer_l = mask_layer - 1 ; <nl> - GLint mask_layer_le = mask_layer | mask_layer_l ; <nl> - GLboolean currentStencilEnabled = GL_FALSE ; <nl> - GLuint currentStencilWriteMask = ~ 0 ; <nl> - GLenum currentStencilFunc = GL_ALWAYS ; <nl> - GLint currentStencilRef = 0 ; <nl> - GLuint currentStencilValueMask = ~ 0 ; <nl> - GLenum currentStencilFail = GL_KEEP ; <nl> - GLenum currentStencilPassDepthFail = GL_KEEP ; <nl> - GLenum currentStencilPassDepthPass = GL_KEEP ; <nl> - currentStencilEnabled = glIsEnabled ( GL_STENCIL_TEST ) ; <nl> - glGetIntegerv ( GL_STENCIL_WRITEMASK , ( GLint * ) & currentStencilWriteMask ) ; <nl> - glGetIntegerv ( GL_STENCIL_FUNC , ( GLint * ) & currentStencilFunc ) ; <nl> - glGetIntegerv ( GL_STENCIL_REF , & currentStencilRef ) ; <nl> - glGetIntegerv ( GL_STENCIL_VALUE_MASK , ( GLint * ) & currentStencilValueMask ) ; <nl> - glGetIntegerv ( GL_STENCIL_FAIL , ( GLint * ) & currentStencilFail ) ; <nl> - glGetIntegerv ( GL_STENCIL_PASS_DEPTH_FAIL , ( GLint * ) & currentStencilPassDepthFail ) ; <nl> - glGetIntegerv ( GL_STENCIL_PASS_DEPTH_PASS , ( GLint * ) & currentStencilPassDepthPass ) ; <nl> + _mask_layer_le = mask_layer | mask_layer_l ; <nl> + _currentStencilEnabled = glIsEnabled ( GL_STENCIL_TEST ) ; <nl> + glGetIntegerv ( GL_STENCIL_WRITEMASK , ( GLint * ) & _currentStencilWriteMask ) ; <nl> + glGetIntegerv ( GL_STENCIL_FUNC , ( GLint * ) & _currentStencilFunc ) ; <nl> + glGetIntegerv ( GL_STENCIL_REF , & _currentStencilRef ) ; <nl> + glGetIntegerv ( GL_STENCIL_VALUE_MASK , ( GLint * ) & _currentStencilValueMask ) ; <nl> + glGetIntegerv ( GL_STENCIL_FAIL , ( GLint * ) & _currentStencilFail ) ; <nl> + glGetIntegerv ( GL_STENCIL_PASS_DEPTH_FAIL , ( GLint * ) & _currentStencilPassDepthFail ) ; <nl> + glGetIntegerv ( GL_STENCIL_PASS_DEPTH_PASS , ( GLint * ) & _currentStencilPassDepthPass ) ; <nl> + <nl> glEnable ( GL_STENCIL_TEST ) ; <nl> CHECK_GL_ERROR_DEBUG ( ) ; <nl> glStencilMask ( mask_layer ) ; <nl> - GLboolean currentDepthWriteMask = GL_TRUE ; <nl> - glGetBooleanv ( GL_DEPTH_WRITEMASK , & currentDepthWriteMask ) ; <nl> + glGetBooleanv ( GL_DEPTH_WRITEMASK , & _currentDepthWriteMask ) ; <nl> glDepthMask ( GL_FALSE ) ; <nl> glStencilFunc ( GL_NEVER , mask_layer , mask_layer ) ; <nl> - glStencilOp ( GL_ZERO , GL_KEEP , GL_KEEP ) ; <nl> + glStencilOp ( ! false ? GL_ZERO : GL_REPLACE , GL_KEEP , GL_KEEP ) ; <nl> kmGLMatrixMode ( KM_GL_MODELVIEW ) ; <nl> kmGLPushMatrix ( ) ; <nl> kmGLLoadIdentity ( ) ; <nl> + <nl> kmGLMatrixMode ( KM_GL_PROJECTION ) ; <nl> kmGLPushMatrix ( ) ; <nl> kmGLLoadIdentity ( ) ; <nl> + <nl> DrawPrimitives : : drawSolidRect ( Point ( - 1 , - 1 ) , Point ( 1 , 1 ) , Color4F ( 1 , 1 , 1 , 1 ) ) ; <nl> + <nl> kmGLMatrixMode ( KM_GL_PROJECTION ) ; <nl> kmGLPopMatrix ( ) ; <nl> kmGLMatrixMode ( KM_GL_MODELVIEW ) ; <nl> kmGLPopMatrix ( ) ; <nl> glStencilFunc ( GL_NEVER , mask_layer , mask_layer ) ; <nl> - glStencilOp ( GL_REPLACE , GL_KEEP , GL_KEEP ) ; <nl> + glStencilOp ( ! false ? GL_REPLACE : GL_ZERO , GL_KEEP , GL_KEEP ) ; <nl> + } <nl> <nl> - kmGLPushMatrix ( ) ; <nl> - transform ( ) ; <nl> - _clippingStencil - > visit ( ) ; <nl> - kmGLPopMatrix ( ) ; <nl> - glDepthMask ( currentDepthWriteMask ) ; <nl> - glStencilFunc ( GL_EQUAL , mask_layer_le , mask_layer_le ) ; <nl> + void Layout : : onAfterDrawStencil ( ) <nl> + { <nl> + glDepthMask ( _currentDepthWriteMask ) ; <nl> + glStencilFunc ( GL_EQUAL , _mask_layer_le , _mask_layer_le ) ; <nl> glStencilOp ( GL_KEEP , GL_KEEP , GL_KEEP ) ; <nl> - Node : : visit ( ) ; <nl> - glStencilFunc ( currentStencilFunc , currentStencilRef , currentStencilValueMask ) ; <nl> - glStencilOp ( currentStencilFail , currentStencilPassDepthFail , currentStencilPassDepthPass ) ; <nl> - glStencilMask ( currentStencilWriteMask ) ; <nl> - if ( ! currentStencilEnabled ) <nl> + } <nl> + <nl> + <nl> + void Layout : : onAfterVisitStencil ( ) <nl> + { <nl> + glStencilFunc ( _currentStencilFunc , _currentStencilRef , _currentStencilValueMask ) ; <nl> + glStencilOp ( _currentStencilFail , _currentStencilPassDepthFail , _currentStencilPassDepthPass ) ; <nl> + glStencilMask ( _currentStencilWriteMask ) ; <nl> + if ( ! _currentStencilEnabled ) <nl> { <nl> glDisable ( GL_STENCIL_TEST ) ; <nl> } <nl> - layer - - ; <nl> + s_layer - - ; <nl> } <nl> <nl> - void Layout : : scissorClippingVisit ( ) <nl> + void Layout : : onBeforeVisitScissor ( ) <nl> { <nl> Rect clippingRect = getClippingRect ( ) ; <nl> - if ( _handleScissor ) <nl> - { <nl> - glEnable ( GL_SCISSOR_TEST ) ; <nl> - } <nl> + glEnable ( GL_SCISSOR_TEST ) ; <nl> EGLView : : getInstance ( ) - > setScissorInPoints ( clippingRect . origin . x , clippingRect . origin . y , clippingRect . size . width , clippingRect . size . height ) ; <nl> + } <nl> + <nl> + void Layout : : onAfterVisitScissor ( ) <nl> + { <nl> + glDisable ( GL_SCISSOR_TEST ) ; <nl> + } <nl> + <nl> + void Layout : : scissorClippingVisit ( ) <nl> + { <nl> + Renderer * renderer = Director : : getInstance ( ) - > getRenderer ( ) ; <nl> + <nl> + _beforeVisitCmdScissor . init ( 0 , _vertexZ ) ; <nl> + _beforeVisitCmdScissor . func = CC_CALLBACK_0 ( Layout : : onBeforeVisitScissor , this ) ; <nl> + renderer - > addCommand ( & _beforeVisitCmdScissor ) ; <nl> + <nl> Node : : visit ( ) ; <nl> - if ( _handleScissor ) <nl> - { <nl> - glDisable ( GL_SCISSOR_TEST ) ; <nl> - } <nl> + <nl> + _afterVisitCmdScissor . init ( 0 , _vertexZ ) ; <nl> + _afterVisitCmdScissor . func = CC_CALLBACK_0 ( Layout : : onAfterVisitScissor , this ) ; <nl> + renderer - > addCommand ( & _afterVisitCmdScissor ) ; <nl> } <nl> <nl> void Layout : : setClippingEnabled ( bool able ) <nl> void Layout : : setClippingEnabled ( bool able ) <nl> case LAYOUT_CLIPPING_STENCIL : <nl> if ( able ) <nl> { <nl> - glGetIntegerv ( GL_STENCIL_BITS , & g_sStencilBits ) ; <nl> + static bool once = true ; <nl> + if ( once ) <nl> + { <nl> + glGetIntegerv ( GL_STENCIL_BITS , & g_sStencilBits ) ; <nl> + if ( g_sStencilBits < = 0 ) <nl> + { <nl> + CCLOG ( " Stencil buffer is not enabled . " ) ; <nl> + } <nl> + once = false ; <nl> + } <nl> _clippingStencil = DrawNode : : create ( ) ; <nl> - _clippingStencil - > onEnter ( ) ; <nl> + if ( _running ) <nl> + { <nl> + _clippingStencil - > onEnter ( ) ; <nl> + } <nl> _clippingStencil - > retain ( ) ; <nl> setStencilClippingSize ( _size ) ; <nl> } <nl> else <nl> { <nl> - _clippingStencil - > onExit ( ) ; <nl> + if ( _running ) <nl> + { <nl> + _clippingStencil - > onExit ( ) ; <nl> + } <nl> _clippingStencil - > release ( ) ; <nl> _clippingStencil = nullptr ; <nl> } <nl> void Layout : : setStencilClippingSize ( const Size & size ) <nl> <nl> const Rect & Layout : : getClippingRect ( ) <nl> { <nl> - _handleScissor = true ; <nl> Point worldPos = convertToWorldSpace ( Point : : ZERO ) ; <nl> AffineTransform t = nodeToWorldTransform ( ) ; <nl> float scissorWidth = _size . width * t . a ; <nl> const Rect & Layout : : getClippingRect ( ) <nl> { <nl> _clippingParent = parent ; <nl> firstClippingParentFounded = true ; <nl> - } <nl> - <nl> - if ( parent - > _clippingType = = LAYOUT_CLIPPING_SCISSOR ) <nl> - { <nl> - _handleScissor = false ; <nl> break ; <nl> } <nl> } <nl> mmm a / cocos / gui / UILayout . h <nl> ppp b / cocos / gui / UILayout . h <nl> class Layout : public Widget <nl> virtual void sortAllChildren ( ) override ; <nl> <nl> void requestDoLayout ( ) ; <nl> + <nl> + virtual void onEnter ( ) override ; <nl> + virtual void onExit ( ) override ; <nl> protected : <nl> / / override " init " method of widget . <nl> virtual bool init ( ) override ; <nl> class Layout : public Widget <nl> void setStencilClippingSize ( const Size & size ) ; <nl> const Rect & getClippingRect ( ) ; <nl> virtual void doLayout ( ) ; <nl> + <nl> + / / clipping <nl> + void onBeforeVisitStencil ( ) ; <nl> + void onAfterDrawStencil ( ) ; <nl> + void onAfterVisitStencil ( ) ; <nl> + <nl> + void onBeforeVisitScissor ( ) ; <nl> + void onAfterVisitScissor ( ) ; <nl> protected : <nl> bool _clippingEnabled ; <nl> <nl> class Layout : public Widget <nl> LayoutType _layoutType ; <nl> LayoutClippingType _clippingType ; <nl> DrawNode * _clippingStencil ; <nl> - bool _handleScissor ; <nl> bool _scissorRectDirty ; <nl> Rect _clippingRect ; <nl> Layout * _clippingParent ; <nl> bool _doLayoutDirty ; <nl> + <nl> + / / clipping <nl> + <nl> + GLboolean _currentStencilEnabled ; <nl> + GLuint _currentStencilWriteMask ; <nl> + GLenum _currentStencilFunc ; <nl> + GLint _currentStencilRef ; <nl> + GLuint _currentStencilValueMask ; <nl> + GLenum _currentStencilFail ; <nl> + GLenum _currentStencilPassDepthFail ; <nl> + GLenum _currentStencilPassDepthPass ; <nl> + GLboolean _currentDepthWriteMask ; <nl> + <nl> + GLboolean _currentAlphaTestEnabled ; <nl> + GLenum _currentAlphaTestFunc ; <nl> + GLclampf _currentAlphaTestRef ; <nl> + <nl> + GLint _mask_layer_le ; <nl> + <nl> + GroupCommand _groupCommand ; <nl> + CustomCommand _beforeVisitCmdStencil ; <nl> + CustomCommand _afterDrawStencilCmd ; <nl> + CustomCommand _afterVisitCmdStencil ; <nl> + CustomCommand _beforeVisitCmdScissor ; <nl> + CustomCommand _afterVisitCmdScissor ; <nl> } ; <nl> <nl> } <nl>
|
Fixed bug of clippinglayout
|
cocos2d/cocos2d-x
|
ad30f8ff9677b9a40822f8437eb1868be00f5507
|
2014-01-06T02:56:33Z
|
mmm a / docs / CODING_STYLE . md <nl> ppp b / docs / CODING_STYLE . md <nl> We are using some C + + 11 features , mainly : <nl> ` base : : SharedPtr ` and ` base : : UniquePtr ` but you should use the STL <nl> ones now ) <nl> * You can use ` < atomic > ` , ` < thread > ` , ` < mutex > ` , and ` < condition_variable > ` <nl> + * We use GCC 4 . 8 on Linux , so check the features available since GCC 4 . 8 in <nl> + https : / / developer . mozilla . org / en - US / docs / Mozilla / Using_CXX_in_Mozilla_code <nl>
|
Add a link to Mozilla summart of C + + 11 features available in gcc 4 . 8
|
aseprite/aseprite
|
2b937ad0e1d52155f56fd7a018b186d399639ed5
|
2018-08-03T15:00:38Z
|
mmm a / src / mongo / db / commands / index_filter_commands_test . cpp <nl> ppp b / src / mongo / db / commands / index_filter_commands_test . cpp <nl> namespace { <nl> PlanRankingDecision * createDecision ( size_t numPlans ) { <nl> auto_ptr < PlanRankingDecision > why ( new PlanRankingDecision ( ) ) ; <nl> for ( size_t i = 0 ; i < numPlans ; + + i ) { <nl> - auto_ptr < PlanStageStats > stats ( new PlanStageStats ( CommonStats ( ) , STAGE_COLLSCAN ) ) ; <nl> + CommonStats common ( " COLLSCAN " ) ; <nl> + auto_ptr < PlanStageStats > stats ( new PlanStageStats ( common , STAGE_COLLSCAN ) ) ; <nl> stats - > specific . reset ( new CollectionScanStats ( ) ) ; <nl> why - > stats . mutableVector ( ) . push_back ( stats . release ( ) ) ; <nl> why - > scores . push_back ( 0U ) ; <nl> mmm a / src / mongo / db / commands / plan_cache_commands_test . cpp <nl> ppp b / src / mongo / db / commands / plan_cache_commands_test . cpp <nl> namespace { <nl> PlanRankingDecision * createDecision ( size_t numPlans ) { <nl> auto_ptr < PlanRankingDecision > why ( new PlanRankingDecision ( ) ) ; <nl> for ( size_t i = 0 ; i < numPlans ; + + i ) { <nl> - auto_ptr < PlanStageStats > stats ( new PlanStageStats ( CommonStats ( ) , STAGE_COLLSCAN ) ) ; <nl> + CommonStats common ( " COLLSCAN " ) ; <nl> + auto_ptr < PlanStageStats > stats ( new PlanStageStats ( common , STAGE_COLLSCAN ) ) ; <nl> stats - > specific . reset ( new CollectionScanStats ( ) ) ; <nl> why - > stats . mutableVector ( ) . push_back ( stats . release ( ) ) ; <nl> why - > scores . push_back ( 0U ) ; <nl> mmm a / src / mongo / db / exec / 2dnear . cpp <nl> ppp b / src / mongo / db / exec / 2dnear . cpp <nl> <nl> <nl> namespace mongo { <nl> <nl> - TwoDNear : : TwoDNear ( const TwoDNearParams & params , WorkingSet * ws ) { <nl> + / / static <nl> + const char * TwoDNear : : kStageType = " GEO_NEAR_2D " ; <nl> + <nl> + TwoDNear : : TwoDNear ( const TwoDNearParams & params , WorkingSet * ws ) <nl> + : _commonStats ( kStageType ) { <nl> _params = params ; <nl> _workingSet = ws ; <nl> _initted = false ; <nl> namespace mongo { <nl> <nl> PlanStageStats * TwoDNear : : getStats ( ) { <nl> _commonStats . isEOF = isEOF ( ) ; <nl> + _specificStats . keyPattern = _params . indexKeyPattern ; <nl> auto_ptr < PlanStageStats > ret ( new PlanStageStats ( _commonStats , STAGE_GEO_NEAR_2D ) ) ; <nl> ret - > specific . reset ( new TwoDNearStats ( _specificStats ) ) ; <nl> return ret . release ( ) ; <nl> mmm a / src / mongo / db / exec / 2dnear . h <nl> ppp b / src / mongo / db / exec / 2dnear . h <nl> namespace mongo { <nl> <nl> virtual PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> WorkingSet * _workingSet ; <nl> <nl> mmm a / src / mongo / db / exec / and_hash . cpp <nl> ppp b / src / mongo / db / exec / and_hash . cpp <nl> namespace mongo { <nl> <nl> const size_t AndHashStage : : kLookAheadWorks = 10 ; <nl> <nl> + / / static <nl> + const char * AndHashStage : : kStageType = " AND_HASH " ; <nl> + <nl> AndHashStage : : AndHashStage ( WorkingSet * ws , <nl> const MatchExpression * filter , <nl> const Collection * collection ) <nl> namespace mongo { <nl> _filter ( filter ) , <nl> _hashingChildren ( true ) , <nl> _currentChild ( 0 ) , <nl> + _commonStats ( kStageType ) , <nl> _memUsage ( 0 ) , <nl> _maxMemUsage ( kDefaultMaxMemUsageBytes ) { } <nl> <nl> namespace mongo { <nl> _filter ( filter ) , <nl> _hashingChildren ( true ) , <nl> _currentChild ( 0 ) , <nl> + _commonStats ( kStageType ) , <nl> _memUsage ( 0 ) , <nl> _maxMemUsage ( maxMemUsage ) { } <nl> <nl> namespace mongo { <nl> _specificStats . memLimit = _maxMemUsage ; <nl> _specificStats . memUsage = _memUsage ; <nl> <nl> + / / Add a BSON representation of the filter to the stats tree , if there is one . <nl> + if ( NULL ! = _filter ) { <nl> + BSONObjBuilder bob ; <nl> + _filter - > toBSON ( & bob ) ; <nl> + _commonStats . filter = bob . obj ( ) ; <nl> + } <nl> + <nl> auto_ptr < PlanStageStats > ret ( new PlanStageStats ( _commonStats , STAGE_AND_HASH ) ) ; <nl> ret - > specific . reset ( new AndHashStats ( _specificStats ) ) ; <nl> for ( size_t i = 0 ; i < _children . size ( ) ; + + i ) { <nl> mmm a / src / mongo / db / exec / and_hash . h <nl> ppp b / src / mongo / db / exec / and_hash . h <nl> namespace mongo { <nl> <nl> virtual PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> static const size_t kLookAheadWorks ; <nl> <nl> mmm a / src / mongo / db / exec / and_sorted . cpp <nl> ppp b / src / mongo / db / exec / and_sorted . cpp <nl> <nl> <nl> namespace mongo { <nl> <nl> + / / static <nl> + const char * AndSortedStage : : kStageType = " AND_SORTED " ; <nl> + <nl> AndSortedStage : : AndSortedStage ( WorkingSet * ws , <nl> const MatchExpression * filter , <nl> const Collection * collection ) <nl> namespace mongo { <nl> _ws ( ws ) , <nl> _filter ( filter ) , <nl> _targetNode ( numeric_limits < size_t > : : max ( ) ) , <nl> - _targetId ( WorkingSet : : INVALID_ID ) , _isEOF ( false ) { } <nl> + _targetId ( WorkingSet : : INVALID_ID ) , _isEOF ( false ) , <nl> + _commonStats ( kStageType ) { } <nl> <nl> AndSortedStage : : ~ AndSortedStage ( ) { <nl> for ( size_t i = 0 ; i < _children . size ( ) ; + + i ) { delete _children [ i ] ; } <nl> namespace mongo { <nl> PlanStageStats * AndSortedStage : : getStats ( ) { <nl> _commonStats . isEOF = isEOF ( ) ; <nl> <nl> + / / Add a BSON representation of the filter to the stats tree , if there is one . <nl> + if ( NULL ! = _filter ) { <nl> + BSONObjBuilder bob ; <nl> + _filter - > toBSON ( & bob ) ; <nl> + _commonStats . filter = bob . obj ( ) ; <nl> + } <nl> + <nl> auto_ptr < PlanStageStats > ret ( new PlanStageStats ( _commonStats , STAGE_AND_SORTED ) ) ; <nl> ret - > specific . reset ( new AndSortedStats ( _specificStats ) ) ; <nl> for ( size_t i = 0 ; i < _children . size ( ) ; + + i ) { <nl> mmm a / src / mongo / db / exec / and_sorted . h <nl> ppp b / src / mongo / db / exec / and_sorted . h <nl> namespace mongo { <nl> <nl> virtual PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> / / Find a node to AND against . <nl> PlanStage : : StageState getTargetLoc ( WorkingSetID * out ) ; <nl> mmm a / src / mongo / db / exec / cached_plan . cpp <nl> ppp b / src / mongo / db / exec / cached_plan . cpp <nl> <nl> <nl> namespace mongo { <nl> <nl> + / / static <nl> + const char * CachedPlanStage : : kStageType = " CACHED_PLAN " ; <nl> + <nl> CachedPlanStage : : CachedPlanStage ( const Collection * collection , <nl> CanonicalQuery * cq , <nl> PlanStage * mainChild , <nl> namespace mongo { <nl> _backupChildPlan ( backupChild ) , <nl> _usingBackupChild ( false ) , <nl> _alreadyProduced ( false ) , <nl> - _updatedCache ( false ) { } <nl> + _updatedCache ( false ) , <nl> + _commonStats ( kStageType ) { } <nl> <nl> CachedPlanStage : : ~ CachedPlanStage ( ) { <nl> / / We may have produced all necessary results without hitting EOF . <nl> mmm a / src / mongo / db / exec / cached_plan . h <nl> ppp b / src / mongo / db / exec / cached_plan . h <nl> namespace mongo { <nl> <nl> virtual PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> PlanStage * getActiveChild ( ) const ; <nl> void updateCache ( ) ; <nl> mmm a / src / mongo / db / exec / collection_scan . cpp <nl> ppp b / src / mongo / db / exec / collection_scan . cpp <nl> <nl> <nl> namespace mongo { <nl> <nl> + / / static <nl> + const char * CollectionScan : : kStageType = " COLLSCAN " ; <nl> + <nl> CollectionScan : : CollectionScan ( const CollectionScanParams & params , <nl> WorkingSet * workingSet , <nl> const MatchExpression * filter ) <nl> : _workingSet ( workingSet ) , <nl> _filter ( filter ) , <nl> _params ( params ) , <nl> - _nsDropped ( false ) { } <nl> + _nsDropped ( false ) , <nl> + _commonStats ( kStageType ) { } <nl> <nl> PlanStage : : StageState CollectionScan : : work ( WorkingSetID * out ) { <nl> + + _commonStats . works ; <nl> namespace mongo { <nl> <nl> PlanStageStats * CollectionScan : : getStats ( ) { <nl> _commonStats . isEOF = isEOF ( ) ; <nl> + <nl> + / / Add a BSON representation of the filter to the stats tree , if there is one . <nl> + if ( NULL ! = _filter ) { <nl> + BSONObjBuilder bob ; <nl> + _filter - > toBSON ( & bob ) ; <nl> + _commonStats . filter = bob . obj ( ) ; <nl> + } <nl> + <nl> auto_ptr < PlanStageStats > ret ( new PlanStageStats ( _commonStats , STAGE_COLLSCAN ) ) ; <nl> ret - > specific . reset ( new CollectionScanStats ( _specificStats ) ) ; <nl> return ret . release ( ) ; <nl> mmm a / src / mongo / db / exec / collection_scan . h <nl> ppp b / src / mongo / db / exec / collection_scan . h <nl> namespace mongo { <nl> virtual void recoverFromYield ( ) ; <nl> <nl> virtual PlanStageStats * getStats ( ) ; <nl> + <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> / * * <nl> * Returns true if the record ' loc ' references is in memory , false otherwise . <nl> mmm a / src / mongo / db / exec / count . cpp <nl> ppp b / src / mongo / db / exec / count . cpp <nl> <nl> <nl> namespace mongo { <nl> <nl> + / / static <nl> + const char * Count : : kStageType = " COUNT " ; <nl> + <nl> Count : : Count ( const CountParams & params , WorkingSet * workingSet ) <nl> : _workingSet ( workingSet ) , <nl> _descriptor ( params . descriptor ) , <nl> namespace mongo { <nl> _btreeCursor ( NULL ) , <nl> _params ( params ) , <nl> _hitEnd ( false ) , <nl> - _shouldDedup ( params . descriptor - > isMultikey ( ) ) { } <nl> + _shouldDedup ( params . descriptor - > isMultikey ( ) ) , <nl> + _commonStats ( kStageType ) { } <nl> <nl> void Count : : initIndexCursor ( ) { <nl> CursorOptions cursorOptions ; <nl> mmm a / src / mongo / db / exec / count . h <nl> ppp b / src / mongo / db / exec / count . h <nl> namespace mongo { <nl> <nl> virtual PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> / * * <nl> * Initialize the underlying IndexCursor <nl> namespace mongo { <nl> bool _hitEnd ; <nl> <nl> bool _shouldDedup ; <nl> + <nl> + CommonStats _commonStats ; <nl> } ; <nl> <nl> } / / namespace mongo <nl> mmm a / src / mongo / db / exec / distinct_scan . cpp <nl> ppp b / src / mongo / db / exec / distinct_scan . cpp <nl> <nl> <nl> namespace mongo { <nl> <nl> + / / static <nl> + const char * DistinctScan : : kStageType = " DISTINCT " ; <nl> + <nl> DistinctScan : : DistinctScan ( const DistinctParams & params , WorkingSet * workingSet ) <nl> : _workingSet ( workingSet ) , <nl> _descriptor ( params . descriptor ) , <nl> _iam ( params . descriptor - > getIndexCatalog ( ) - > getIndex ( params . descriptor ) ) , <nl> _btreeCursor ( NULL ) , <nl> _hitEnd ( false ) , <nl> - _params ( params ) { } <nl> + _params ( params ) , <nl> + _commonStats ( kStageType ) { } <nl> <nl> void DistinctScan : : initIndexCursor ( ) { <nl> / / Create an IndexCursor over the btree we ' re distinct - ing over . <nl> mmm a / src / mongo / db / exec / distinct_scan . h <nl> ppp b / src / mongo / db / exec / distinct_scan . h <nl> namespace mongo { <nl> <nl> virtual PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> / * * <nl> * Initialize the underlying IndexCursor <nl> mmm a / src / mongo / db / exec / fetch . cpp <nl> ppp b / src / mongo / db / exec / fetch . cpp <nl> <nl> <nl> namespace mongo { <nl> <nl> - FetchStage : : FetchStage ( WorkingSet * ws , <nl> - PlanStage * child , <nl> - const MatchExpression * filter , <nl> + / / static <nl> + const char * FetchStage : : kStageType = " FETCH " ; <nl> + <nl> + FetchStage : : FetchStage ( WorkingSet * ws , <nl> + PlanStage * child , <nl> + const MatchExpression * filter , <nl> const Collection * collection ) <nl> : _collection ( collection ) , <nl> - _ws ( ws ) , <nl> - _child ( child ) , <nl> - _filter ( filter ) { } <nl> + _ws ( ws ) , <nl> + _child ( child ) , <nl> + _filter ( filter ) , <nl> + _commonStats ( kStageType ) { } <nl> <nl> FetchStage : : ~ FetchStage ( ) { } <nl> <nl> namespace mongo { <nl> PlanStageStats * FetchStage : : getStats ( ) { <nl> _commonStats . isEOF = isEOF ( ) ; <nl> <nl> + / / Add a BSON representation of the filter to the stats tree , if there is one . <nl> + if ( NULL ! = _filter ) { <nl> + BSONObjBuilder bob ; <nl> + _filter - > toBSON ( & bob ) ; <nl> + _commonStats . filter = bob . obj ( ) ; <nl> + } <nl> + <nl> auto_ptr < PlanStageStats > ret ( new PlanStageStats ( _commonStats , STAGE_FETCH ) ) ; <nl> ret - > specific . reset ( new FetchStats ( _specificStats ) ) ; <nl> ret - > children . push_back ( _child - > getStats ( ) ) ; <nl> mmm a / src / mongo / db / exec / fetch . h <nl> ppp b / src / mongo / db / exec / fetch . h <nl> namespace mongo { <nl> <nl> PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> <nl> / * * <nl> mmm a / src / mongo / db / exec / index_scan . cpp <nl> ppp b / src / mongo / db / exec / index_scan . cpp <nl> <nl> # include " mongo / db / index / index_access_method . h " <nl> # include " mongo / db / index / index_cursor . h " <nl> # include " mongo / db / index / index_descriptor . h " <nl> + # include " mongo / db / query / explain . h " <nl> <nl> namespace { <nl> <nl> namespace { <nl> <nl> namespace mongo { <nl> <nl> + / / static <nl> + const char * IndexScan : : kStageType = " IXSCAN " ; <nl> + <nl> IndexScan : : IndexScan ( const IndexScanParams & params , WorkingSet * workingSet , <nl> const MatchExpression * filter ) <nl> : _workingSet ( workingSet ) , <nl> namespace mongo { <nl> _shouldDedup ( true ) , <nl> _yieldMovedCursor ( false ) , <nl> _params ( params ) , <nl> - _btreeCursor ( NULL ) { } <nl> - <nl> - void IndexScan : : initIndexScan ( ) { <nl> - / / Perform the possibly heavy - duty initialization of the underlying index cursor . <nl> + _btreeCursor ( NULL ) , <nl> + _commonStats ( kStageType ) { <nl> _iam = _params . descriptor - > getIndexCatalog ( ) - > getIndex ( _params . descriptor ) ; <nl> _keyPattern = _params . descriptor - > keyPattern ( ) . getOwned ( ) ; <nl> + } <nl> <nl> + void IndexScan : : initIndexScan ( ) { <nl> + / / Perform the possibly heavy - duty initialization of the underlying index cursor . <nl> if ( _params . doNotDedup ) { <nl> _shouldDedup = false ; <nl> } <nl> namespace mongo { <nl> / / catalog information here . <nl> _commonStats . isEOF = isEOF ( ) ; <nl> <nl> + / / Add a BSON representation of the filter to the stats tree , if there is one . <nl> + if ( NULL ! = _filter ) { <nl> + BSONObjBuilder bob ; <nl> + _filter - > toBSON ( & bob ) ; <nl> + _commonStats . filter = bob . obj ( ) ; <nl> + } <nl> + <nl> / / These specific stats fields never change . <nl> if ( _specificStats . indexType . empty ( ) ) { <nl> _specificStats . indexType = " BtreeCursor " ; / / TODO amName ; <nl> - _specificStats . indexBounds = _params . bounds . toBSON ( ) ; <nl> + <nl> + / / TODO this can be simplified once the new explain format is <nl> + / / the default . Probably won ' t need to include explain . h here either . <nl> + if ( enableNewExplain ) { <nl> + _specificStats . indexBounds = _params . bounds . toBSON ( ) ; <nl> + } <nl> + else { <nl> + _specificStats . indexBounds = _params . bounds . toLegacyBSON ( ) ; <nl> + } <nl> + <nl> _specificStats . indexBoundsVerbose = _params . bounds . toString ( ) ; <nl> _specificStats . direction = _params . direction ; <nl> _specificStats . keyPattern = _keyPattern ; <nl> mmm a / src / mongo / db / exec / index_scan . h <nl> ppp b / src / mongo / db / exec / index_scan . h <nl> namespace mongo { <nl> <nl> virtual PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> / * * <nl> * Initialize the underlying IndexCursor , grab information from the catalog for stats . <nl> mmm a / src / mongo / db / exec / keep_mutations . cpp <nl> ppp b / src / mongo / db / exec / keep_mutations . cpp <nl> <nl> <nl> namespace mongo { <nl> <nl> + / / static <nl> + const char * KeepMutationsStage : : kStageType = " KEEP_MUTATIONS " ; <nl> + <nl> KeepMutationsStage : : KeepMutationsStage ( const MatchExpression * filter , <nl> WorkingSet * ws , <nl> PlanStage * child ) <nl> namespace mongo { <nl> _child ( child ) , <nl> _filter ( filter ) , <nl> _doneReadingChild ( false ) , <nl> - _doneReturningFlagged ( false ) { } <nl> + _doneReturningFlagged ( false ) , <nl> + _commonStats ( kStageType ) { } <nl> <nl> KeepMutationsStage : : ~ KeepMutationsStage ( ) { } <nl> <nl> mmm a / src / mongo / db / exec / keep_mutations . h <nl> ppp b / src / mongo / db / exec / keep_mutations . h <nl> namespace mongo { <nl> <nl> virtual PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> / / Not owned here . <nl> WorkingSet * _workingSet ; <nl> mmm a / src / mongo / db / exec / limit . cpp <nl> ppp b / src / mongo / db / exec / limit . cpp <nl> <nl> <nl> namespace mongo { <nl> <nl> + / / static <nl> + const char * LimitStage : : kStageType = " LIMIT " ; <nl> + <nl> LimitStage : : LimitStage ( int limit , WorkingSet * ws , PlanStage * child ) <nl> - : _ws ( ws ) , _child ( child ) , _numToReturn ( limit ) { } <nl> + : _ws ( ws ) , _child ( child ) , _numToReturn ( limit ) , _commonStats ( kStageType ) { } <nl> <nl> LimitStage : : ~ LimitStage ( ) { } <nl> <nl> namespace mongo { <nl> <nl> PlanStageStats * LimitStage : : getStats ( ) { <nl> _commonStats . isEOF = isEOF ( ) ; <nl> + _specificStats . limit = _numToReturn ; <nl> auto_ptr < PlanStageStats > ret ( new PlanStageStats ( _commonStats , STAGE_LIMIT ) ) ; <nl> + ret - > specific . reset ( new LimitStats ( _specificStats ) ) ; <nl> ret - > children . push_back ( _child - > getStats ( ) ) ; <nl> return ret . release ( ) ; <nl> } <nl> mmm a / src / mongo / db / exec / limit . h <nl> ppp b / src / mongo / db / exec / limit . h <nl> namespace mongo { <nl> <nl> virtual PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> WorkingSet * _ws ; <nl> scoped_ptr < PlanStage > _child ; <nl> namespace mongo { <nl> <nl> / / Stats <nl> CommonStats _commonStats ; <nl> + LimitStats _specificStats ; <nl> } ; <nl> <nl> } / / namespace mongo <nl> mmm a / src / mongo / db / exec / merge_sort . cpp <nl> ppp b / src / mongo / db / exec / merge_sort . cpp <nl> <nl> <nl> namespace mongo { <nl> <nl> + / / static <nl> + const char * MergeSortStage : : kStageType = " SORT_MERGE " ; <nl> + <nl> MergeSortStage : : MergeSortStage ( const MergeSortStageParams & params , <nl> WorkingSet * ws , <nl> const Collection * collection ) <nl> namespace mongo { <nl> _ws ( ws ) , <nl> _pattern ( params . pattern ) , <nl> _dedup ( params . dedup ) , <nl> - _merging ( StageWithValueComparison ( ws , params . pattern ) ) { } <nl> + _merging ( StageWithValueComparison ( ws , params . pattern ) ) , <nl> + _commonStats ( kStageType ) { } <nl> <nl> MergeSortStage : : ~ MergeSortStage ( ) { <nl> for ( size_t i = 0 ; i < _children . size ( ) ; + + i ) { delete _children [ i ] ; } <nl> namespace mongo { <nl> PlanStageStats * MergeSortStage : : getStats ( ) { <nl> _commonStats . isEOF = isEOF ( ) ; <nl> <nl> + _specificStats . sortPattern = _pattern ; <nl> + <nl> auto_ptr < PlanStageStats > ret ( new PlanStageStats ( _commonStats , STAGE_SORT_MERGE ) ) ; <nl> ret - > specific . reset ( new MergeSortStats ( _specificStats ) ) ; <nl> for ( size_t i = 0 ; i < _children . size ( ) ; + + i ) { <nl> mmm a / src / mongo / db / exec / merge_sort . h <nl> ppp b / src / mongo / db / exec / merge_sort . h <nl> namespace mongo { <nl> <nl> PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> / / Not owned by us . <nl> const Collection * _collection ; <nl> mmm a / src / mongo / db / exec / multi_plan . cpp <nl> ppp b / src / mongo / db / exec / multi_plan . cpp <nl> <nl> # include " mongo / db / query / qlog . h " <nl> <nl> namespace mongo { <nl> + <nl> + / / static <nl> + const char * MultiPlanStage : : kStageType = " MULTI_PLAN " ; <nl> + <nl> MultiPlanStage : : MultiPlanStage ( const Collection * collection , CanonicalQuery * cq ) <nl> : _collection ( collection ) , <nl> _query ( cq ) , <nl> namespace mongo { <nl> _backupPlanIdx ( kNoSuchPlan ) , <nl> _failure ( false ) , <nl> _failureCount ( 0 ) , <nl> - _statusMemberId ( WorkingSet : : INVALID_ID ) { } <nl> + _statusMemberId ( WorkingSet : : INVALID_ID ) , <nl> + _commonStats ( kStageType ) { } <nl> <nl> MultiPlanStage : : ~ MultiPlanStage ( ) { <nl> if ( bestPlanChosen ( ) ) { <nl> namespace mongo { <nl> delete _candidates [ _backupPlanIdx ] . solution ; <nl> delete _candidates [ _backupPlanIdx ] . root ; <nl> } <nl> + <nl> + / / Clean up the losing candidates . <nl> + clearCandidates ( ) ; <nl> } <nl> else { <nl> for ( size_t ix = 0 ; ix < _candidates . size ( ) ; + + ix ) { <nl> namespace mongo { <nl> _collection - > infoCache ( ) - > getPlanCache ( ) - > add ( * _query , solutions , ranking . release ( ) ) ; <nl> } <nl> } <nl> + } <nl> <nl> - / / Clear out the candidate plans , leaving only stats as we ' re all done w / them . <nl> - / / Traverse candidate plans in order or score <nl> - for ( size_t orderingIndex = 0 ; <nl> - orderingIndex < candidateOrder . size ( ) ; + + orderingIndex ) { <nl> - / / index into candidates / ranking <nl> - int ix = candidateOrder [ orderingIndex ] ; <nl> - <nl> - if ( ix = = _bestPlanIdx ) { continue ; } <nl> - if ( ix = = _backupPlanIdx ) { continue ; } <nl> - <nl> - delete _candidates [ ix ] . solution ; <nl> + vector < PlanStageStats * > * MultiPlanStage : : generateCandidateStats ( ) { <nl> + for ( size_t ix = 0 ; ix < _candidates . size ( ) ; ix + + ) { <nl> + if ( ix = = ( size_t ) _bestPlanIdx ) { continue ; } <nl> + if ( ix = = ( size_t ) _backupPlanIdx ) { continue ; } <nl> <nl> / / Remember the stats for the candidate plan because we always show it on an <nl> / / explain . ( The { verbose : false } in explain ( ) is client - side trick ; we always <nl> namespace mongo { <nl> if ( stats ) { <nl> _candidateStats . push_back ( stats ) ; <nl> } <nl> + } <nl> + <nl> + return & _candidateStats ; <nl> + } <nl> + <nl> + void MultiPlanStage : : clearCandidates ( ) { <nl> + / / Clear out the candidate plans , leaving only stats as we ' re all done w / them . <nl> + / / Traverse candidate plans in order or score <nl> + for ( size_t ix = 0 ; ix < _candidates . size ( ) ; ix + + ) { <nl> + if ( ix = = ( size_t ) _bestPlanIdx ) { continue ; } <nl> + if ( ix = = ( size_t ) _backupPlanIdx ) { continue ; } <nl> + <nl> delete _candidates [ ix ] . root ; <nl> + delete _candidates [ ix ] . solution ; <nl> } <nl> } <nl> <nl> namespace mongo { <nl> return ! doneWorking ; <nl> } <nl> <nl> + Status MultiPlanStage : : executeWinningPlan ( ) { <nl> + invariant ( _bestPlanIdx ! = kNoSuchPlan ) ; <nl> + PlanStage * winner = _candidates [ _bestPlanIdx ] . root ; <nl> + WorkingSet * ws = _candidates [ _bestPlanIdx ] . ws ; <nl> + <nl> + bool doneWorking = false ; <nl> + <nl> + while ( ! doneWorking ) { <nl> + WorkingSetID id = WorkingSet : : INVALID_ID ; <nl> + PlanStage : : StageState state = winner - > work ( & id ) ; <nl> + <nl> + if ( PlanStage : : IS_EOF = = state | | PlanStage : : DEAD = = state ) { <nl> + doneWorking = true ; <nl> + } <nl> + else if ( PlanStage : : FAILURE = = state ) { <nl> + / / Propogate error . <nl> + BSONObj errObj ; <nl> + WorkingSetCommon : : getStatusMemberObject ( * ws , id , & errObj ) ; <nl> + return Status ( ErrorCodes : : BadValue , WorkingSetCommon : : toStatusString ( errObj ) ) ; <nl> + } <nl> + } <nl> + <nl> + return Status : : OK ( ) ; <nl> + } <nl> + <nl> + Status MultiPlanStage : : executeAllPlans ( ) { <nl> + / / Boolean vector keeping track of which plans are done . <nl> + vector < bool > planDone ( _candidates . size ( ) , false ) ; <nl> + <nl> + / / Number of plans that are done . <nl> + size_t doneCount = 0 ; <nl> + <nl> + while ( doneCount < _candidates . size ( ) ) { <nl> + for ( size_t i = 0 ; i < _candidates . size ( ) ; i + + ) { <nl> + if ( planDone [ i ] ) { <nl> + continue ; <nl> + } <nl> + <nl> + WorkingSetID id = WorkingSet : : INVALID_ID ; <nl> + PlanStage : : StageState state = _candidates [ i ] . root - > work ( & id ) ; <nl> + <nl> + if ( PlanStage : : IS_EOF = = state | | PlanStage : : DEAD = = state ) { <nl> + doneCount + + ; <nl> + planDone [ i ] = true ; <nl> + } <nl> + else if ( PlanStage : : FAILURE = = state ) { <nl> + / / Propogate error . <nl> + BSONObj errObj ; <nl> + WorkingSetCommon : : getStatusMemberObject ( * _candidates [ i ] . ws , id , & errObj ) ; <nl> + return Status ( ErrorCodes : : BadValue , WorkingSetCommon : : toStatusString ( errObj ) ) ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + return Status : : OK ( ) ; <nl> + } <nl> + <nl> void MultiPlanStage : : prepareToYield ( ) { <nl> if ( _failure ) return ; <nl> <nl> mmm a / src / mongo / db / exec / multi_plan . h <nl> ppp b / src / mongo / db / exec / multi_plan . h <nl> namespace mongo { <nl> <nl> virtual ~ MultiPlanStage ( ) ; <nl> <nl> + / * * <nl> + * Helper used by the destructor to delete losing candidate plans . <nl> + * / <nl> + void clearCandidates ( ) ; <nl> + <nl> virtual bool isEOF ( ) ; <nl> <nl> virtual StageState work ( WorkingSetID * out ) ; <nl> namespace mongo { <nl> void addPlan ( QuerySolution * solution , PlanStage * root , WorkingSet * sharedWs ) ; <nl> <nl> / * * <nl> - * Runs all plans added by addPlan , ranks them , and picks a best . Deletes all loser plans . <nl> + * Runs all plans added by addPlan , ranks them , and picks a best . <nl> * All further calls to getNext ( . . . ) will return results from the best plan . <nl> * / <nl> void pickBestPlan ( ) ; <nl> namespace mongo { <nl> * / <nl> bool hasBackupPlan ( ) const ; <nl> <nl> + / * * <nl> + * Gathers execution stats for all losing plans . <nl> + * / <nl> + vector < PlanStageStats * > * generateCandidateStats ( ) ; <nl> + <nl> + / / <nl> + / / Used by explain . <nl> + / / <nl> + <nl> + / * * <nl> + * Runs the winning plan into it hits EOF or returns DEAD , throwing out the results . <nl> + * Execution stats are gathered in the process . <nl> + * <nl> + * You can call this after calling pickBestPlan ( . . . ) . It expects that a winning plan <nl> + * has already been selected . <nl> + * / <nl> + Status executeWinningPlan ( ) ; <nl> + <nl> + / * * <nl> + * Runs the candidate plans until each has either hit EOF or returned DEAD . Results <nl> + * from the plans are thrown out , but execution stats are gathered . <nl> + * <nl> + * You can call this after calling pickBestPlan ( . . . ) . It expects that a winning plan <nl> + * has already been selected . <nl> + * / <nl> + Status executeAllPlans ( ) ; <nl> + <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> / / <nl> / / Have all our candidate plans do something . <nl> mmm a / src / mongo / db / exec / or . cpp <nl> ppp b / src / mongo / db / exec / or . cpp <nl> <nl> <nl> namespace mongo { <nl> <nl> + / / static <nl> + const char * OrStage : : kStageType = " OR " ; <nl> + <nl> OrStage : : OrStage ( WorkingSet * ws , bool dedup , const MatchExpression * filter ) <nl> - : _ws ( ws ) , _filter ( filter ) , _currentChild ( 0 ) , _dedup ( dedup ) { } <nl> + : _ws ( ws ) , _filter ( filter ) , _currentChild ( 0 ) , _dedup ( dedup ) , _commonStats ( kStageType ) { } <nl> <nl> OrStage : : ~ OrStage ( ) { <nl> for ( size_t i = 0 ; i < _children . size ( ) ; + + i ) { <nl> namespace mongo { <nl> PlanStageStats * OrStage : : getStats ( ) { <nl> _commonStats . isEOF = isEOF ( ) ; <nl> <nl> + / / Add a BSON representation of the filter to the stats tree , if there is one . <nl> + if ( NULL ! = _filter ) { <nl> + BSONObjBuilder bob ; <nl> + _filter - > toBSON ( & bob ) ; <nl> + _commonStats . filter = bob . obj ( ) ; <nl> + } <nl> + <nl> auto_ptr < PlanStageStats > ret ( new PlanStageStats ( _commonStats , STAGE_OR ) ) ; <nl> ret - > specific . reset ( new OrStats ( _specificStats ) ) ; <nl> for ( size_t i = 0 ; i < _children . size ( ) ; + + i ) { <nl> mmm a / src / mongo / db / exec / or . h <nl> ppp b / src / mongo / db / exec / or . h <nl> namespace mongo { <nl> <nl> virtual PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> / / Not owned by us . <nl> WorkingSet * _ws ; <nl> mmm a / src / mongo / db / exec / plan_stats . h <nl> ppp b / src / mongo / db / exec / plan_stats . h <nl> namespace mongo { <nl> <nl> / / Every stage has CommonStats . <nl> struct CommonStats { <nl> - CommonStats ( ) : works ( 0 ) , <nl> + CommonStats ( const char * type ) <nl> + : stageTypeStr ( type ) , <nl> + works ( 0 ) , <nl> yields ( 0 ) , <nl> unyields ( 0 ) , <nl> invalidates ( 0 ) , <nl> advanced ( 0 ) , <nl> needTime ( 0 ) , <nl> isEOF ( false ) { } <nl> + / / String giving the type of the stage . Not owned . <nl> + const char * stageTypeStr ; <nl> <nl> / / Count calls into the stage . <nl> size_t works ; <nl> namespace mongo { <nl> size_t advanced ; <nl> size_t needTime ; <nl> <nl> + / / BSON representation of a MatchExpression affixed to this node . If there <nl> + / / is no filter affixed , then ' filter ' should be an empty BSONObj . <nl> + BSONObj filter ; <nl> + <nl> / / TODO : have some way of tracking WSM sizes ( or really any series of # s ) . We can measure <nl> / / the size of our inputs and the size of our outputs . We can do a lot with the WS here . <nl> <nl> namespace mongo { <nl> / / the user , eg . time_t totalTimeSpent ; <nl> <nl> bool isEOF ; <nl> + private : <nl> + / / Default constructor is illegal . <nl> + CommonStats ( ) ; <nl> } ; <nl> <nl> / / The universal container for a stage ' s stats . <nl> namespace mongo { <nl> <nl> } ; <nl> <nl> + struct LimitStats : public SpecificStats { <nl> + LimitStats ( ) : limit ( 0 ) { } <nl> + <nl> + virtual SpecificStats * clone ( ) const { <nl> + LimitStats * specific = new LimitStats ( * this ) ; <nl> + return specific ; <nl> + } <nl> + <nl> + size_t limit ; <nl> + } ; <nl> + <nl> struct MultiPlanStats : public SpecificStats { <nl> MultiPlanStats ( ) { } <nl> <nl> namespace mongo { <nl> std : : vector < size_t > matchTested ; <nl> } ; <nl> <nl> + struct ProjectionStats : public SpecificStats { <nl> + ProjectionStats ( ) { } <nl> + <nl> + virtual SpecificStats * clone ( ) const { <nl> + ProjectionStats * specific = new ProjectionStats ( * this ) ; <nl> + return specific ; <nl> + } <nl> + <nl> + / / Object specifying the projection transformation to apply . <nl> + BSONObj projObj ; <nl> + } ; <nl> + <nl> struct SortStats : public SpecificStats { <nl> SortStats ( ) : forcedFetches ( 0 ) , memUsage ( 0 ) , memLimit ( 0 ) { } <nl> <nl> namespace mongo { <nl> <nl> / / What ' s our memory limit ? <nl> size_t memLimit ; <nl> + <nl> + / / The number of results to return from the sort . <nl> + size_t limit ; <nl> + <nl> + / / The pattern according to which we are sorting . <nl> + BSONObj sortPattern ; <nl> } ; <nl> <nl> struct MergeSortStats : public SpecificStats { <nl> namespace mongo { <nl> <nl> / / How many records were we forced to fetch as the result of an invalidation ? <nl> size_t forcedFetches ; <nl> + <nl> + / / The pattern according to which we are sorting . <nl> + BSONObj sortPattern ; <nl> } ; <nl> <nl> struct ShardingFilterStats : public SpecificStats { <nl> namespace mongo { <nl> size_t chunkSkips ; <nl> } ; <nl> <nl> + struct SkipStats : public SpecificStats { <nl> + SkipStats ( ) : skip ( 0 ) { } <nl> + <nl> + virtual SpecificStats * clone ( ) const { <nl> + SkipStats * specific = new SkipStats ( * this ) ; <nl> + return specific ; <nl> + } <nl> + <nl> + size_t skip ; <nl> + } ; <nl> + <nl> struct TwoDStats : public SpecificStats { <nl> TwoDStats ( ) { } <nl> <nl> namespace mongo { <nl> / / Geo hashes generated by GeoBrowse : : fillStack . <nl> / / Raw data for explain index bounds . <nl> std : : vector < GeoHash > expPrefixes ; <nl> + <nl> + BSONObj keyPattern ; <nl> } ; <nl> <nl> struct TwoDNearStats : public SpecificStats { <nl> namespace mongo { <nl> <nl> size_t objectsLoaded ; <nl> <nl> - / / Since 2d ' s near does all its work in one go we can ' t divine the real nscanned from <nl> - / / anything else . <nl> + / / Since 2d ' s near does all its work in one go we can ' t divine the real number of <nl> + / / keys scanned from anything else . <nl> size_t nscanned ; <nl> + <nl> + BSONObj keyPattern ; <nl> } ; <nl> <nl> struct TextStats : public SpecificStats { <nl> namespace mongo { <nl> <nl> / / Human - readable form of the FTSQuery associated with the text stage . <nl> BSONObj parsedTextQuery ; <nl> + <nl> + / / Index keys that precede the " text " index key . <nl> + BSONObj indexPrefix ; <nl> } ; <nl> <nl> } / / namespace mongo <nl> mmm a / src / mongo / db / exec / projection . cpp <nl> ppp b / src / mongo / db / exec / projection . cpp <nl> namespace mongo { <nl> <nl> static const char * kIdField = " _id " ; <nl> <nl> + / / static <nl> + const char * ProjectionStage : : kStageType = " PROJECTION " ; <nl> + <nl> ProjectionStage : : ProjectionStage ( const ProjectionStageParams & params , <nl> WorkingSet * ws , <nl> PlanStage * child ) <nl> : _ws ( ws ) , <nl> _child ( child ) , <nl> + _commonStats ( kStageType ) , <nl> _projImpl ( params . projImpl ) { <nl> <nl> if ( ProjectionStageParams : : NO_FAST_PATH = = _projImpl ) { <nl> namespace mongo { <nl> <nl> PlanStageStats * ProjectionStage : : getStats ( ) { <nl> _commonStats . isEOF = isEOF ( ) ; <nl> + _specificStats . projObj = _projObj ; <nl> auto_ptr < PlanStageStats > ret ( new PlanStageStats ( _commonStats , STAGE_PROJECTION ) ) ; <nl> + ret - > specific . reset ( new ProjectionStats ( _specificStats ) ) ; <nl> ret - > children . push_back ( _child - > getStats ( ) ) ; <nl> return ret . release ( ) ; <nl> } <nl> mmm a / src / mongo / db / exec / projection . h <nl> ppp b / src / mongo / db / exec / projection . h <nl> namespace mongo { <nl> const FieldSet & includedFields , <nl> BSONObjBuilder & bob ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> Status transform ( WorkingSetMember * member ) ; <nl> <nl> namespace mongo { <nl> <nl> / / Stats <nl> CommonStats _commonStats ; <nl> + ProjectionStats _specificStats ; <nl> <nl> / / Fast paths : <nl> ProjectionStageParams : : ProjectionImplementation _projImpl ; <nl> mmm a / src / mongo / db / exec / s2near . cpp <nl> ppp b / src / mongo / db / exec / s2near . cpp <nl> <nl> <nl> namespace mongo { <nl> <nl> - S2NearStage : : S2NearStage ( const S2NearParams & params , WorkingSet * ws ) { <nl> + / / static <nl> + const char * S2NearStage : : kStageType = " GEO_NEAR_2DSPHERE " ; <nl> + <nl> + S2NearStage : : S2NearStage ( const S2NearParams & params , WorkingSet * ws ) <nl> + : _commonStats ( kStageType ) { <nl> _initted = false ; <nl> _params = params ; <nl> _ws = ws ; <nl> namespace mongo { <nl> virtual void debugString ( StringBuilder & debug , int level = 0 ) const { <nl> } <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const { <nl> + } <nl> + <nl> virtual bool equivalent ( const MatchExpression * other ) const { <nl> return false ; <nl> } <nl> mmm a / src / mongo / db / exec / s2near . h <nl> ppp b / src / mongo / db / exec / s2near . h <nl> namespace mongo { <nl> <nl> PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> void init ( ) ; <nl> StageState addResultToQueue ( WorkingSetID * out ) ; <nl> mmm a / src / mongo / db / exec / shard_filter . cpp <nl> ppp b / src / mongo / db / exec / shard_filter . cpp <nl> <nl> <nl> namespace mongo { <nl> <nl> + / / static <nl> + const char * ShardFilterStage : : kStageType = " SHARDING_FILTER " ; <nl> + <nl> ShardFilterStage : : ShardFilterStage ( const CollectionMetadataPtr & metadata , <nl> WorkingSet * ws , <nl> PlanStage * child ) <nl> - : _ws ( ws ) , _child ( child ) , _metadata ( metadata ) { } <nl> + : _ws ( ws ) , _child ( child ) , _commonStats ( kStageType ) , _metadata ( metadata ) { } <nl> <nl> ShardFilterStage : : ~ ShardFilterStage ( ) { } <nl> <nl> mmm a / src / mongo / db / exec / shard_filter . h <nl> ppp b / src / mongo / db / exec / shard_filter . h <nl> namespace mongo { <nl> <nl> virtual PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> WorkingSet * _ws ; <nl> scoped_ptr < PlanStage > _child ; <nl> mmm a / src / mongo / db / exec / skip . cpp <nl> ppp b / src / mongo / db / exec / skip . cpp <nl> <nl> <nl> namespace mongo { <nl> <nl> + / / static <nl> + const char * SkipStage : : kStageType = " SKIP " ; <nl> + <nl> SkipStage : : SkipStage ( int toSkip , WorkingSet * ws , PlanStage * child ) <nl> - : _ws ( ws ) , _child ( child ) , _toSkip ( toSkip ) { } <nl> + : _ws ( ws ) , _child ( child ) , _toSkip ( toSkip ) , _commonStats ( kStageType ) { } <nl> <nl> SkipStage : : ~ SkipStage ( ) { } <nl> <nl> namespace mongo { <nl> <nl> PlanStageStats * SkipStage : : getStats ( ) { <nl> _commonStats . isEOF = isEOF ( ) ; <nl> + _specificStats . skip = _toSkip ; <nl> auto_ptr < PlanStageStats > ret ( new PlanStageStats ( _commonStats , STAGE_SKIP ) ) ; <nl> + ret - > specific . reset ( new SkipStats ( _specificStats ) ) ; <nl> ret - > children . push_back ( _child - > getStats ( ) ) ; <nl> return ret . release ( ) ; <nl> } <nl> mmm a / src / mongo / db / exec / skip . h <nl> ppp b / src / mongo / db / exec / skip . h <nl> namespace mongo { <nl> <nl> virtual PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> WorkingSet * _ws ; <nl> scoped_ptr < PlanStage > _child ; <nl> namespace mongo { <nl> <nl> / / Stats <nl> CommonStats _commonStats ; <nl> + SkipStats _specificStats ; <nl> } ; <nl> <nl> } / / namespace mongo <nl> mmm a / src / mongo / db / exec / sort . cpp <nl> ppp b / src / mongo / db / exec / sort . cpp <nl> namespace mongo { <nl> <nl> const size_t kMaxBytes = 32 * 1024 * 1024 ; <nl> <nl> + / / static <nl> + const char * SortStage : : kStageType = " SORT " ; <nl> + <nl> SortStageKeyGenerator : : SortStageKeyGenerator ( const Collection * collection , <nl> const BSONObj & sortSpec , <nl> const BSONObj & queryObj ) { <nl> namespace mongo { <nl> _limit ( params . limit ) , <nl> _sorted ( false ) , <nl> _resultIterator ( _data . end ( ) ) , <nl> + _commonStats ( kStageType ) , <nl> _memUsage ( 0 ) { <nl> } <nl> <nl> namespace mongo { <nl> _commonStats . isEOF = isEOF ( ) ; <nl> _specificStats . memLimit = kMaxBytes ; <nl> _specificStats . memUsage = _memUsage ; <nl> + _specificStats . limit = _limit ; <nl> + _specificStats . sortPattern = _pattern . getOwned ( ) ; <nl> <nl> auto_ptr < PlanStageStats > ret ( new PlanStageStats ( _commonStats , STAGE_SORT ) ) ; <nl> ret - > specific . reset ( new SortStats ( _specificStats ) ) ; <nl> mmm a / src / mongo / db / exec / sort . h <nl> ppp b / src / mongo / db / exec / sort . h <nl> namespace mongo { <nl> <nl> PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> <nl> / / <nl> mmm a / src / mongo / db / exec / text . cpp <nl> ppp b / src / mongo / db / exec / text . cpp <nl> <nl> <nl> namespace mongo { <nl> <nl> + / / static <nl> + const char * TextStage : : kStageType = " TEXT " ; <nl> + <nl> TextStage : : TextStage ( const TextStageParams & params , <nl> WorkingSet * ws , <nl> const MatchExpression * filter ) <nl> namespace mongo { <nl> _ftsMatcher ( params . query , params . spec ) , <nl> _ws ( ws ) , <nl> _filter ( filter ) , <nl> + _commonStats ( kStageType ) , <nl> _internalState ( INIT_SCANS ) , <nl> _currentIndexScanner ( 0 ) { <nl> - <nl> _scoreIterator = _scores . end ( ) ; <nl> } <nl> <nl> namespace mongo { <nl> <nl> PlanStageStats * TextStage : : getStats ( ) { <nl> _commonStats . isEOF = isEOF ( ) ; <nl> + <nl> + / / Add a BSON representation of the filter to the stats tree , if there is one . <nl> + if ( NULL ! = _filter ) { <nl> + BSONObjBuilder bob ; <nl> + _filter - > toBSON ( & bob ) ; <nl> + _commonStats . filter = bob . obj ( ) ; <nl> + } <nl> + <nl> + _specificStats . indexPrefix = _params . indexPrefix ; <nl> + <nl> auto_ptr < PlanStageStats > ret ( new PlanStageStats ( _commonStats , STAGE_TEXT ) ) ; <nl> ret - > specific . reset ( new TextStats ( _specificStats ) ) ; <nl> return ret . release ( ) ; <nl> mmm a / src / mongo / db / exec / text . h <nl> ppp b / src / mongo / db / exec / text . h <nl> namespace mongo { <nl> <nl> PlanStageStats * getStats ( ) ; <nl> <nl> + static const char * kStageType ; <nl> + <nl> private : <nl> / * * <nl> * Initializes sub - scanners . <nl> mmm a / src / mongo / db / matcher / expression . cpp <nl> ppp b / src / mongo / db / matcher / expression . cpp <nl> namespace mongo { <nl> debug < < " $ atomic \ n " ; <nl> } <nl> <nl> + void AtomicMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + out - > append ( " $ isolated " , 1 ) ; <nl> + } <nl> + <nl> void FalseMatchExpression : : debugString ( StringBuilder & debug , int level ) const { <nl> _debugAddSpace ( debug , level ) ; <nl> debug < < " $ false \ n " ; <nl> } <nl> <nl> + void FalseMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + out - > append ( " $ false " , 1 ) ; <nl> + } <nl> + <nl> } <nl> <nl> <nl> mmm a / src / mongo / db / matcher / expression . h <nl> ppp b / src / mongo / db / matcher / expression . h <nl> <nl> # include " mongo / base / disallow_copying . h " <nl> # include " mongo / base / status . h " <nl> # include " mongo / bson / bsonobj . h " <nl> + # include " mongo / bson / bsonobjbuilder . h " <nl> # include " mongo / db / matcher / matchable . h " <nl> # include " mongo / db / matcher / match_details . h " <nl> <nl> namespace mongo { <nl> / / <nl> virtual std : : string toString ( ) const ; <nl> virtual void debugString ( StringBuilder & debug , int level = 0 ) const = 0 ; <nl> + virtual void toBSON ( BSONObjBuilder * out ) const = 0 ; <nl> <nl> protected : <nl> void _debugAddSpace ( StringBuilder & debug , int level ) const ; <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level = 0 ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> virtual bool equivalent ( const MatchExpression * other ) const { <nl> return other - > matchType ( ) = = ATOMIC ; <nl> } <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level = 0 ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> virtual bool equivalent ( const MatchExpression * other ) const { <nl> return other - > matchType ( ) = = ALWAYS_FALSE ; <nl> } <nl> mmm a / src / mongo / db / matcher / expression_array . cpp <nl> ppp b / src / mongo / db / matcher / expression_array . cpp <nl> namespace mongo { <nl> _sub - > debugString ( debug , level + 1 ) ; <nl> } <nl> <nl> + void ElemMatchObjectMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + BSONObjBuilder subBob ; <nl> + _sub - > toBSON ( & subBob ) ; <nl> + if ( path ( ) . empty ( ) ) { <nl> + out - > append ( " $ elemMatch " , subBob . obj ( ) ) ; <nl> + } <nl> + else { <nl> + out - > append ( path ( ) , BSON ( " $ elemMatch " < < subBob . obj ( ) ) ) ; <nl> + } <nl> + } <nl> + <nl> <nl> / / mmmmmm - <nl> <nl> namespace mongo { <nl> } <nl> } <nl> <nl> + void ElemMatchValueMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + BSONObjBuilder emBob ; <nl> + for ( unsigned i = 0 ; i < _subs . size ( ) ; i + + ) { <nl> + _subs [ i ] - > toBSON ( & emBob ) ; <nl> + } <nl> + if ( path ( ) . empty ( ) ) { <nl> + out - > append ( " $ elemMatch " , emBob . obj ( ) ) ; <nl> + } <nl> + else { <nl> + out - > append ( path ( ) , BSON ( " $ elemMatch " < < emBob . obj ( ) ) ) ; <nl> + } <nl> + } <nl> + <nl> <nl> / / mmmmmm <nl> <nl> namespace mongo { <nl> for ( size_t i = 0 ; i < _list . size ( ) ; i + + ) { <nl> _list [ i ] - > debugString ( debug , level + 1 ) ; <nl> } <nl> + } <nl> + <nl> + void AllElemMatchOp : : toBSON ( BSONObjBuilder * out ) const { <nl> + BSONObjBuilder allBob ( out - > subobjStart ( path ( ) ) ) ; <nl> + <nl> + BSONArrayBuilder arrBob ( allBob . subarrayStart ( " $ all " ) ) ; <nl> + for ( unsigned i = 0 ; i < _list . size ( ) ; i + + ) { <nl> + BSONObjBuilder childBob ( arrBob . subobjStart ( ) ) ; <nl> + _list [ i ] - > toBSON ( & childBob ) ; <nl> + } <nl> + arrBob . doneFast ( ) ; <nl> <nl> + allBob . doneFast ( ) ; <nl> } <nl> <nl> bool AllElemMatchOp : : equivalent ( const MatchExpression * other ) const { <nl> namespace mongo { <nl> } <nl> } <nl> <nl> + void SizeMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + out - > append ( path ( ) , BSON ( " $ size " < < _size ) ) ; <nl> + } <nl> + <nl> bool SizeMatchExpression : : equivalent ( const MatchExpression * other ) const { <nl> if ( matchType ( ) ! = other - > matchType ( ) ) <nl> return false ; <nl> mmm a / src / mongo / db / matcher / expression_array . h <nl> ppp b / src / mongo / db / matcher / expression_array . h <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> virtual size_t numChildren ( ) const { return 1 ; } <nl> <nl> virtual MatchExpression * getChild ( size_t i ) const { return _sub . get ( ) ; } <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> virtual size_t numChildren ( ) const { return _subs . size ( ) ; } <nl> <nl> virtual MatchExpression * getChild ( size_t i ) const { return _subs [ i ] ; } <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> virtual bool equivalent ( const MatchExpression * other ) const ; <nl> <nl> int getData ( ) const { return _size ; } <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> virtual bool equivalent ( const MatchExpression * other ) const ; <nl> <nl> virtual size_t numChildren ( ) const { return _list . size ( ) ; } <nl> mmm a / src / mongo / db / matcher / expression_geo . cpp <nl> ppp b / src / mongo / db / matcher / expression_geo . cpp <nl> namespace mongo { <nl> debug < < " \ n " ; <nl> } <nl> <nl> + void GeoMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + out - > appendElements ( _rawObj ) ; <nl> + } <nl> + <nl> bool GeoMatchExpression : : equivalent ( const MatchExpression * other ) const { <nl> if ( matchType ( ) ! = other - > matchType ( ) ) <nl> return false ; <nl> namespace mongo { <nl> debug < < " \ n " ; <nl> } <nl> <nl> + void GeoNearMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + out - > appendElements ( _rawObj ) ; <nl> + } <nl> + <nl> bool GeoNearMatchExpression : : equivalent ( const MatchExpression * other ) const { <nl> if ( matchType ( ) ! = other - > matchType ( ) ) <nl> return false ; <nl> mmm a / src / mongo / db / matcher / expression_geo . h <nl> ppp b / src / mongo / db / matcher / expression_geo . h <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level = 0 ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> virtual bool equivalent ( const MatchExpression * other ) const ; <nl> <nl> virtual LeafMatchExpression * shallowClone ( ) const ; <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level = 0 ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> virtual bool equivalent ( const MatchExpression * other ) const ; <nl> <nl> virtual LeafMatchExpression * shallowClone ( ) const ; <nl> mmm a / src / mongo / db / matcher / expression_leaf . cpp <nl> ppp b / src / mongo / db / matcher / expression_leaf . cpp <nl> namespace mongo { <nl> debug < < " \ n " ; <nl> } <nl> <nl> + void ComparisonMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + string opString = " " ; <nl> + switch ( matchType ( ) ) { <nl> + case LT : opString = " $ lt " ; break ; <nl> + case LTE : opString = " $ lte " ; break ; <nl> + case EQ : opString = " $ eq " ; break ; <nl> + case GT : opString = " $ gt " ; break ; <nl> + case GTE : opString = " $ gte " ; break ; <nl> + default : opString = " UNKNOWN - should be impossible " ; break ; <nl> + } <nl> + <nl> + out - > append ( path ( ) , BSON ( opString < < _rhs ) ) ; <nl> + } <nl> + <nl> / / mmmmmmmmmmmmmmm <nl> <nl> / / TODO : move <nl> namespace mongo { <nl> debug < < " \ n " ; <nl> } <nl> <nl> + void RegexMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + out - > appendRegex ( path ( ) , _regex , _flags ) ; <nl> + } <nl> + <nl> void RegexMatchExpression : : shortDebugString ( StringBuilder & debug ) const { <nl> debug < < " / " < < _regex < < " / " < < _flags ; <nl> } <nl> namespace mongo { <nl> debug < < " \ n " ; <nl> } <nl> <nl> + void ModMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + out - > append ( path ( ) , BSON ( " $ mod " < < BSON_ARRAY ( _divisor < < _remainder ) ) ) ; <nl> + } <nl> + <nl> bool ModMatchExpression : : equivalent ( const MatchExpression * other ) const { <nl> if ( matchType ( ) ! = other - > matchType ( ) ) <nl> return false ; <nl> namespace mongo { <nl> debug < < " \ n " ; <nl> } <nl> <nl> + void ExistsMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + out - > append ( path ( ) , BSON ( " $ exists " < < true ) ) ; <nl> + } <nl> + <nl> bool ExistsMatchExpression : : equivalent ( const MatchExpression * other ) const { <nl> if ( matchType ( ) ! = other - > matchType ( ) ) <nl> return false ; <nl> namespace mongo { <nl> debug < < " \ n " ; <nl> } <nl> <nl> + void TypeMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + out - > append ( path ( ) , BSON ( " $ type " < < _type ) ) ; <nl> + } <nl> <nl> bool TypeMatchExpression : : equivalent ( const MatchExpression * other ) const { <nl> if ( matchType ( ) ! = other - > matchType ( ) ) <nl> namespace mongo { <nl> debug < < " ] " ; <nl> } <nl> <nl> + void ArrayFilterEntries : : toBSON ( BSONArrayBuilder * out ) const { <nl> + for ( BSONElementSet : : const_iterator it = _equalities . begin ( ) ; <nl> + it ! = _equalities . end ( ) ; + + it ) { <nl> + out - > append ( * it ) ; <nl> + } <nl> + for ( size_t i = 0 ; i < _regexes . size ( ) ; + + i ) { <nl> + BSONObjBuilder regexBob ; <nl> + _regexes [ i ] - > toBSON ( & regexBob ) ; <nl> + out - > append ( regexBob . obj ( ) . firstElement ( ) ) ; <nl> + } <nl> + out - > doneFast ( ) ; <nl> + } <nl> + <nl> / / mmmmmmmmm - - <nl> <nl> Status InMatchExpression : : init ( const StringData & path ) { <nl> namespace mongo { <nl> debug < < " \ n " ; <nl> } <nl> <nl> + void InMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + BSONObjBuilder inBob ( out - > subobjStart ( path ( ) ) ) ; <nl> + BSONArrayBuilder arrBob ( inBob . subarrayStart ( " $ in " ) ) ; <nl> + _arrayEntries . toBSON ( & arrBob ) ; <nl> + inBob . doneFast ( ) ; <nl> + } <nl> + <nl> bool InMatchExpression : : equivalent ( const MatchExpression * other ) const { <nl> if ( matchType ( ) ! = other - > matchType ( ) ) <nl> return false ; <nl> mmm a / src / mongo / db / matcher / expression_leaf . h <nl> ppp b / src / mongo / db / matcher / expression_leaf . h <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level = 0 ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> virtual bool equivalent ( const MatchExpression * other ) const ; <nl> <nl> const BSONElement & getData ( ) const { return _rhs ; } <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> void shortDebugString ( StringBuilder & debug ) const ; <nl> <nl> virtual bool equivalent ( const MatchExpression * other ) const ; <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> virtual bool equivalent ( const MatchExpression * other ) const ; <nl> <nl> int getDivisor ( ) const { return _divisor ; } <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> virtual bool equivalent ( const MatchExpression * other ) const ; <nl> } ; <nl> <nl> namespace mongo { <nl> <nl> void debugString ( StringBuilder & debug ) const ; <nl> <nl> + void toBSON ( BSONArrayBuilder * out ) const ; <nl> + <nl> private : <nl> bool _hasNull ; / / if _equalities has a jstNULL element in it <nl> bool _hasEmptyArray ; <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> virtual bool equivalent ( const MatchExpression * other ) const ; <nl> <nl> void copyTo ( InMatchExpression * toFillIn ) const ; <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> virtual bool equivalent ( const MatchExpression * other ) const ; <nl> <nl> / * * <nl> mmm a / src / mongo / db / matcher / expression_text . cpp <nl> ppp b / src / mongo / db / matcher / expression_text . cpp <nl> namespace mongo { <nl> debug < < " \ n " ; <nl> } <nl> <nl> + void TextMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + out - > append ( " $ text " , BSON ( " $ search " < < _query < < " $ language " < < _language ) ) ; <nl> + } <nl> + <nl> bool TextMatchExpression : : equivalent ( const MatchExpression * other ) const { <nl> if ( matchType ( ) ! = other - > matchType ( ) ) { <nl> return false ; <nl> mmm a / src / mongo / db / matcher / expression_text . h <nl> ppp b / src / mongo / db / matcher / expression_text . h <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level = 0 ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> virtual bool equivalent ( const MatchExpression * other ) const ; <nl> <nl> virtual LeafMatchExpression * shallowClone ( ) const ; <nl> mmm a / src / mongo / db / matcher / expression_tree . cpp <nl> ppp b / src / mongo / db / matcher / expression_tree . cpp <nl> <nl> <nl> # include " mongo / db / matcher / expression_tree . h " <nl> <nl> - # include " mongo / bson / bsonobjiterator . h " <nl> # include " mongo / bson / bsonobj . h " <nl> # include " mongo / bson / bsonmisc . h " <nl> + # include " mongo / bson / bsonobjbuilder . h " <nl> + # include " mongo / bson / bsonobjiterator . h " <nl> + # include " mongo / bson / bson - inl . h " <nl> # include " mongo / util / log . h " <nl> <nl> namespace mongo { <nl> namespace mongo { <nl> _expressions [ i ] - > debugString ( debug , level + 1 ) ; <nl> } <nl> <nl> + void ListOfMatchExpression : : _listToBSON ( BSONArrayBuilder * out ) const { <nl> + for ( unsigned i = 0 ; i < _expressions . size ( ) ; i + + ) { <nl> + BSONObjBuilder childBob ( out - > subobjStart ( ) ) ; <nl> + _expressions [ i ] - > toBSON ( & childBob ) ; <nl> + } <nl> + out - > doneFast ( ) ; <nl> + } <nl> + <nl> bool ListOfMatchExpression : : equivalent ( const MatchExpression * other ) const { <nl> if ( matchType ( ) ! = other - > matchType ( ) ) <nl> return false ; <nl> namespace mongo { <nl> _debugList ( debug , level ) ; <nl> } <nl> <nl> + void AndMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + BSONArrayBuilder arrBob ( out - > subarrayStart ( " $ and " ) ) ; <nl> + _listToBSON ( & arrBob ) ; <nl> + } <nl> + <nl> / / mmm - - <nl> <nl> bool OrMatchExpression : : matches ( const MatchableDocument * doc , MatchDetails * details ) const { <nl> namespace mongo { <nl> _debugList ( debug , level ) ; <nl> } <nl> <nl> + void OrMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + BSONArrayBuilder arrBob ( out - > subarrayStart ( " $ or " ) ) ; <nl> + _listToBSON ( & arrBob ) ; <nl> + } <nl> + <nl> / / mmm - <nl> <nl> bool NorMatchExpression : : matches ( const MatchableDocument * doc , MatchDetails * details ) const { <nl> namespace mongo { <nl> _debugList ( debug , level ) ; <nl> } <nl> <nl> + void NorMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + BSONArrayBuilder arrBob ( out - > subarrayStart ( " $ nor " ) ) ; <nl> + _listToBSON ( & arrBob ) ; <nl> + } <nl> + <nl> / / mmmmmm - <nl> <nl> void NotMatchExpression : : debugString ( StringBuilder & debug , int level ) const { <nl> namespace mongo { <nl> _exp - > debugString ( debug , level + 1 ) ; <nl> } <nl> <nl> + void NotMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + BSONObjBuilder childBob ( out - > subobjStart ( " $ not " ) ) ; <nl> + _exp - > toBSON ( & childBob ) ; <nl> + childBob . doneFast ( ) ; <nl> + } <nl> + <nl> bool NotMatchExpression : : equivalent ( const MatchExpression * other ) const { <nl> if ( matchType ( ) ! = other - > matchType ( ) ) <nl> return false ; <nl> mmm a / src / mongo / db / matcher / expression_tree . h <nl> ppp b / src / mongo / db / matcher / expression_tree . h <nl> namespace mongo { <nl> protected : <nl> void _debugList ( StringBuilder & debug , int level ) const ; <nl> <nl> + void _listToBSON ( BSONArrayBuilder * out ) const ; <nl> + <nl> private : <nl> std : : vector < MatchExpression * > _expressions ; <nl> } ; <nl> namespace mongo { <nl> } <nl> <nl> virtual void debugString ( StringBuilder & debug , int level = 0 ) const ; <nl> + <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> } ; <nl> <nl> class OrMatchExpression : public ListOfMatchExpression { <nl> namespace mongo { <nl> } <nl> <nl> virtual void debugString ( StringBuilder & debug , int level = 0 ) const ; <nl> + <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> } ; <nl> <nl> class NorMatchExpression : public ListOfMatchExpression { <nl> namespace mongo { <nl> } <nl> <nl> virtual void debugString ( StringBuilder & debug , int level = 0 ) const ; <nl> + <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> } ; <nl> <nl> class NotMatchExpression : public MatchExpression { <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level = 0 ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> bool equivalent ( const MatchExpression * other ) const ; <nl> <nl> virtual size_t numChildren ( ) const { return 1 ; } <nl> mmm a / src / mongo / db / matcher / expression_where . cpp <nl> ppp b / src / mongo / db / matcher / expression_where . cpp <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level = 0 ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> virtual bool equivalent ( const MatchExpression * other ) const ; <nl> <nl> virtual void resetTag ( ) { setTag ( NULL ) ; } <nl> namespace mongo { <nl> debug < < " scope : " < < _userScope < < " \ n " ; <nl> } <nl> <nl> + void WhereMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + out - > append ( " $ where " , _code ) ; <nl> + } <nl> + <nl> bool WhereMatchExpression : : equivalent ( const MatchExpression * other ) const { <nl> if ( matchType ( ) ! = other - > matchType ( ) ) <nl> return false ; <nl> mmm a / src / mongo / db / matcher / expression_where_noop . cpp <nl> ppp b / src / mongo / db / matcher / expression_where_noop . cpp <nl> namespace mongo { <nl> <nl> virtual void debugString ( StringBuilder & debug , int level = 0 ) const ; <nl> <nl> + virtual void toBSON ( BSONObjBuilder * out ) const ; <nl> + <nl> virtual bool equivalent ( const MatchExpression * other ) const ; <nl> <nl> virtual void resetTag ( ) { setTag ( NULL ) ; } <nl> namespace mongo { <nl> debug < < " code : " < < _code < < " \ n " ; <nl> } <nl> <nl> + void WhereNoOpMatchExpression : : toBSON ( BSONObjBuilder * out ) const { <nl> + out - > append ( " $ where " , _code ) ; <nl> + } <nl> + <nl> bool WhereNoOpMatchExpression : : equivalent ( const MatchExpression * other ) const { <nl> if ( matchType ( ) ! = other - > matchType ( ) ) <nl> return false ; <nl> mmm a / src / mongo / db / query / SConscript <nl> ppp b / src / mongo / db / query / SConscript <nl> env . Library ( <nl> target = ' query ' , <nl> source = [ <nl> " eof_runner . cpp " , <nl> + " explain . cpp " , <nl> " explain_plan . cpp " , <nl> " get_runner . cpp " , <nl> " idhack_runner . cpp " , <nl> new file mode 100644 <nl> index 000000000000 . . 7477c1a0285d <nl> mmm / dev / null <nl> ppp b / src / mongo / db / query / explain . cpp <nl> <nl> + / * * <nl> + * Copyright ( C ) 2013 - 2014 MongoDB Inc . <nl> + * <nl> + * This program is free software : you can redistribute it and / or modify <nl> + * it under the terms of the GNU Affero General Public License , version 3 , <nl> + * as published by the Free Software Foundation . <nl> + * <nl> + * This program is distributed in the hope that it will be useful , <nl> + * but WITHOUT ANY WARRANTY ; without even the implied warranty of <nl> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the <nl> + * GNU Affero General Public License for more details . <nl> + * <nl> + * You should have received a copy of the GNU Affero General Public License <nl> + * along with this program . If not , see < http : / / www . gnu . org / licenses / > . <nl> + * <nl> + * As a special exception , the copyright holders give permission to link the <nl> + * code of portions of this program with the OpenSSL library under certain <nl> + * conditions as described in each individual source file and distribute <nl> + * linked combinations including the program with the OpenSSL library . You <nl> + * must comply with the GNU Affero General Public License in all respects for <nl> + * all of the code used other than as permitted herein . If you modify file ( s ) <nl> + * with this exception , you may extend this exception to your version of the <nl> + * file ( s ) , but you are not obligated to do so . If you do not wish to do so , <nl> + * delete this exception statement from your version . If you delete this <nl> + * exception statement from all source files in the program , then also delete <nl> + * it in the license file . <nl> + * / <nl> + <nl> + # include " mongo / platform / basic . h " <nl> + <nl> + # include " mongo / db / query / explain . h " <nl> + <nl> + # include " mongo / db / exec / multi_plan . h " <nl> + # include " mongo / db / query / get_runner . h " <nl> + # include " mongo / db / query / plan_executor . h " <nl> + # include " mongo / db / query / query_planner . h " <nl> + # include " mongo / db / query / stage_builder . h " <nl> + # include " mongo / db / exec / working_set_common . h " <nl> + # include " mongo / db / server_options . h " <nl> + # include " mongo / db / server_parameters . h " <nl> + # include " mongo / util / mongoutils / str . h " <nl> + # include " mongo / util / processinfo . h " <nl> + # include " mongo / util / version . h " <nl> + <nl> + namespace mongo { <nl> + <nl> + using mongoutils : : str : : stream ; <nl> + <nl> + MONGO_EXPORT_SERVER_PARAMETER ( enableNewExplain , bool , false ) ; <nl> + <nl> + / / static <nl> + void Explain : : explainTree ( const PlanStageStats & stats , <nl> + Explain : : Verbosity verbosity , <nl> + BSONObjBuilder * bob ) { <nl> + invariant ( bob ) ; <nl> + <nl> + / / Stage name . <nl> + bob - > append ( " stage " , stats . common . stageTypeStr ) ; <nl> + <nl> + if ( ! stats . common . filter . isEmpty ( ) ) { <nl> + bob - > append ( " filter " , stats . common . filter ) ; <nl> + } <nl> + <nl> + / / Stage - specific stats <nl> + if ( STAGE_IXSCAN = = stats . stageType ) { <nl> + IndexScanStats * spec = static_cast < IndexScanStats * > ( stats . specific . get ( ) ) ; <nl> + bob - > append ( " keyPattern " , spec - > keyPattern ) ; <nl> + bob - > appendBool ( " isMultiKey " , spec - > isMultiKey ) ; <nl> + bob - > append ( " indexBounds " , spec - > indexBounds ) ; <nl> + } <nl> + else if ( STAGE_GEO_NEAR_2D = = stats . stageType ) { <nl> + TwoDNearStats * spec = static_cast < TwoDNearStats * > ( stats . specific . get ( ) ) ; <nl> + bob - > append ( " keyPattern " , spec - > keyPattern ) ; <nl> + <nl> + / / TODO these things are execution stats <nl> + / * bob - > appendNumber ( " keysExamined " , spec - > nscanned ) ; <nl> + bob - > appendNumber ( " objectsLoaded " , spec - > objectsLoaded ) ; * / <nl> + } <nl> + else if ( STAGE_TEXT = = stats . stageType ) { <nl> + TextStats * spec = static_cast < TextStats * > ( stats . specific . get ( ) ) ; <nl> + bob - > append ( " indexPrefix " , spec - > indexPrefix ) ; <nl> + bob - > append ( " parsedTextQuery " , spec - > parsedTextQuery ) ; <nl> + <nl> + / / TODO these things are execution stats <nl> + / * bob - > appendNumber ( " keysExamined " , spec - > keysExamined ) ; <nl> + bob - > appendNumber ( " fetches " , spec - > fetches ) ; * / <nl> + } <nl> + else if ( STAGE_SORT = = stats . stageType ) { <nl> + SortStats * spec = static_cast < SortStats * > ( stats . specific . get ( ) ) ; <nl> + bob - > append ( " sortPattern " , spec - > sortPattern ) ; <nl> + if ( spec - > limit > 0 ) { <nl> + bob - > appendNumber ( " limitAmount " , spec - > limit ) ; <nl> + } <nl> + bob - > appendNumber ( " memUsage " , spec - > memUsage ) ; <nl> + } <nl> + else if ( STAGE_SORT_MERGE = = stats . stageType ) { <nl> + MergeSortStats * spec = static_cast < MergeSortStats * > ( stats . specific . get ( ) ) ; <nl> + bob - > append ( " sortPattern " , spec - > sortPattern ) ; <nl> + } <nl> + else if ( STAGE_PROJECTION = = stats . stageType ) { <nl> + ProjectionStats * spec = static_cast < ProjectionStats * > ( stats . specific . get ( ) ) ; <nl> + bob - > append ( " transformBy " , spec - > projObj ) ; <nl> + } <nl> + else if ( STAGE_SKIP = = stats . stageType ) { <nl> + SkipStats * spec = static_cast < SkipStats * > ( stats . specific . get ( ) ) ; <nl> + bob - > appendNumber ( " skipAmount " , spec - > skip ) ; <nl> + } <nl> + else if ( STAGE_LIMIT = = stats . stageType ) { <nl> + LimitStats * spec = static_cast < LimitStats * > ( stats . specific . get ( ) ) ; <nl> + bob - > appendNumber ( " limitAmount " , spec - > limit ) ; <nl> + } <nl> + <nl> + / / We ' re done if there are no children . <nl> + if ( stats . children . empty ( ) ) { <nl> + return ; <nl> + } <nl> + <nl> + / / If there ' s just one child ( a common scenario ) , avoid making an array . This makes <nl> + / / the output more readable by saving a level of nesting . Name the field ' inputStage ' <nl> + / / rather than ' inputStages ' . <nl> + if ( 1 = = stats . children . size ( ) ) { <nl> + BSONObjBuilder childBob ; <nl> + explainTree ( * stats . children [ 0 ] , verbosity , & childBob ) ; <nl> + bob - > append ( " inputStage " , childBob . obj ( ) ) ; <nl> + return ; <nl> + } <nl> + <nl> + / / There is more than one child . Recursively explainTree ( . . . ) on each <nl> + / / of them and add them to the ' inputStages ' array . <nl> + <nl> + BSONArrayBuilder childrenBob ( bob - > subarrayStart ( " inputStages " ) ) ; <nl> + for ( size_t i = 0 ; i < stats . children . size ( ) ; + + i ) { <nl> + BSONObjBuilder childBob ( childrenBob . subobjStart ( ) ) ; <nl> + explainTree ( * stats . children [ i ] , verbosity , & childBob ) ; <nl> + } <nl> + childrenBob . doneFast ( ) ; <nl> + } <nl> + <nl> + / / static <nl> + void Explain : : generatePlannerInfo ( CanonicalQuery * query , <nl> + PlanStageStats * winnerStats , <nl> + vector < PlanStageStats * > & rejectedStats , <nl> + BSONObjBuilder * out ) { <nl> + BSONObjBuilder plannerBob ( out - > subobjStart ( " queryPlanner " ) ) ; ; <nl> + <nl> + plannerBob . append ( " plannerVersion " , QueryPlanner : : kPlannerVersion ) ; <nl> + <nl> + BSONObjBuilder parsedQueryBob ( plannerBob . subobjStart ( " parsedQuery " ) ) ; <nl> + query - > root ( ) - > toBSON ( & parsedQueryBob ) ; <nl> + parsedQueryBob . doneFast ( ) ; <nl> + <nl> + BSONObjBuilder winningPlanBob ( plannerBob . subobjStart ( " winningPlan " ) ) ; <nl> + explainTree ( * winnerStats , Explain : : QUERY_PLANNER , & winningPlanBob ) ; <nl> + winningPlanBob . doneFast ( ) ; <nl> + <nl> + / / Genenerate array of rejected plans . <nl> + BSONArrayBuilder allPlansBob ( plannerBob . subarrayStart ( " rejectedPlans " ) ) ; <nl> + for ( size_t i = 0 ; i < rejectedStats . size ( ) ; i + + ) { <nl> + BSONObjBuilder childBob ( allPlansBob . subobjStart ( ) ) ; <nl> + explainTree ( * rejectedStats . at ( i ) , Explain : : QUERY_PLANNER , & childBob ) ; <nl> + } <nl> + allPlansBob . doneFast ( ) ; <nl> + <nl> + plannerBob . doneFast ( ) ; <nl> + } <nl> + <nl> + / / static <nl> + void Explain : : generateServerInfo ( BSONObjBuilder * out ) { <nl> + BSONObjBuilder serverBob ( out - > subobjStart ( " serverInfo " ) ) ; <nl> + out - > append ( " host " , getHostNameCached ( ) ) ; <nl> + out - > appendNumber ( " port " , serverGlobalParams . port ) ; <nl> + out - > append ( " version " , versionString ) ; <nl> + out - > append ( " gitVersion " , gitVersion ( ) ) ; <nl> + <nl> + ProcessInfo p ; <nl> + BSONObjBuilder bOs ; <nl> + bOs . append ( " type " , p . getOsType ( ) ) ; <nl> + bOs . append ( " name " , p . getOsName ( ) ) ; <nl> + bOs . append ( " version " , p . getOsVersion ( ) ) ; <nl> + serverBob . append ( StringData ( " os " ) , bOs . obj ( ) ) ; <nl> + <nl> + serverBob . doneFast ( ) ; <nl> + } <nl> + <nl> + / / static <nl> + Status Explain : : explainSinglePlan ( Collection * collection , <nl> + CanonicalQuery * rawCanonicalQuery , <nl> + QuerySolution * solution , <nl> + Explain : : Verbosity verbosity , <nl> + BSONObjBuilder * out ) { <nl> + / / Only one possible plan . Build the stages from the solution . <nl> + WorkingSet * ws = new WorkingSet ( ) ; <nl> + PlanStage * root ; <nl> + verify ( StageBuilder : : build ( collection , * solution , ws , & root ) ) ; <nl> + <nl> + / / Wrap the exec stages in a plan executor . Takes ownership of ' ws ' and ' root ' . <nl> + scoped_ptr < PlanExecutor > exec ( new PlanExecutor ( ws , root , collection ) ) ; <nl> + <nl> + / / If we need execution stats , then we should run the plan . <nl> + if ( verbosity > Explain : : QUERY_PLANNER ) { <nl> + Runner : : RunnerState state ; <nl> + BSONObj obj ; <nl> + while ( Runner : : RUNNER_ADVANCED = = ( state = exec - > getNext ( & obj , NULL ) ) ) ; <nl> + <nl> + if ( Runner : : RUNNER_ERROR = = state ) { <nl> + return Status ( ErrorCodes : : BadValue , <nl> + " Exec error : " + WorkingSetCommon : : toStatusString ( obj ) ) ; <nl> + } <nl> + } <nl> + <nl> + scoped_ptr < PlanStageStats > stats ( exec - > getStats ( ) ) ; <nl> + <nl> + / / Actually generate the explain results . <nl> + <nl> + if ( verbosity > = Explain : : QUERY_PLANNER ) { <nl> + vector < PlanStageStats * > rejected ; <nl> + generatePlannerInfo ( rawCanonicalQuery , stats . get ( ) , rejected , out ) ; <nl> + generateServerInfo ( out ) ; <nl> + } <nl> + <nl> + if ( verbosity > = Explain : : EXEC_STATS ) { <nl> + / / TODO : generate executionStats section <nl> + } <nl> + <nl> + if ( verbosity > = Explain : : EXEC_ALL_PLANS ) { <nl> + / / TODO : generate rejected plans execution stats <nl> + } <nl> + <nl> + return Status : : OK ( ) ; <nl> + } <nl> + <nl> + / / static <nl> + Status Explain : : explainMultiPlan ( Collection * collection , <nl> + CanonicalQuery * rawCanonicalQuery , <nl> + vector < QuerySolution * > & solutions , <nl> + Explain : : Verbosity verbosity , <nl> + BSONObjBuilder * out ) { <nl> + scoped_ptr < WorkingSet > sharedWorkingSet ( new WorkingSet ( ) ) ; <nl> + <nl> + scoped_ptr < MultiPlanStage > multiPlanStage ( <nl> + new MultiPlanStage ( collection , rawCanonicalQuery ) ) ; <nl> + <nl> + for ( size_t ix = 0 ; ix < solutions . size ( ) ; + + ix ) { <nl> + / / version of StageBuild : : build when WorkingSet is shared <nl> + PlanStage * nextPlanRoot ; <nl> + verify ( StageBuilder : : build ( collection , * solutions [ ix ] , <nl> + sharedWorkingSet . get ( ) , & nextPlanRoot ) ) ; <nl> + <nl> + / / Takes ownership of the solution and the root PlanStage , but not the working set . <nl> + multiPlanStage - > addPlan ( solutions [ ix ] , nextPlanRoot , sharedWorkingSet . get ( ) ) ; <nl> + } <nl> + <nl> + / / Run the plan / do the plan selection as required by the requested verbosity . <nl> + multiPlanStage - > pickBestPlan ( ) ; <nl> + if ( Explain : : EXEC_STATS = = verbosity ) { <nl> + Status execStatus = multiPlanStage - > executeWinningPlan ( ) ; <nl> + if ( ! execStatus . isOK ( ) ) { <nl> + return execStatus ; <nl> + } <nl> + } <nl> + else if ( Explain : : EXEC_ALL_PLANS = = verbosity ) { <nl> + Status execStatus = multiPlanStage - > executeAllPlans ( ) ; <nl> + if ( ! execStatus . isOK ( ) ) { <nl> + return execStatus ; <nl> + } <nl> + } <nl> + <nl> + / / Get stats for the winning plan . <nl> + scoped_ptr < PlanStageStats > stats ( multiPlanStage - > getStats ( ) ) ; <nl> + <nl> + / / Actually generate the explain results . <nl> + <nl> + if ( verbosity > = Explain : : QUERY_PLANNER ) { <nl> + vector < PlanStageStats * > * rejected = multiPlanStage - > generateCandidateStats ( ) ; <nl> + generatePlannerInfo ( rawCanonicalQuery , stats . get ( ) , * rejected , out ) ; <nl> + generateServerInfo ( out ) ; <nl> + } <nl> + <nl> + if ( verbosity > = Explain : : EXEC_STATS ) { <nl> + / / TODO : generate executionStats section <nl> + } <nl> + <nl> + if ( verbosity > = Explain : : EXEC_ALL_PLANS ) { <nl> + / / TODO : generate rejected plans execution stats <nl> + } <nl> + <nl> + return Status : : OK ( ) ; <nl> + } <nl> + <nl> + / / static <nl> + void Explain : : explainEmptyColl ( CanonicalQuery * rawCanonicalQuery , <nl> + BSONObjBuilder * out ) { <nl> + BSONObjBuilder plannerBob ( out - > subobjStart ( " queryPlanner " ) ) ; <nl> + <nl> + plannerBob . append ( " plannerVersion " , QueryPlanner : : kPlannerVersion ) ; <nl> + <nl> + BSONObjBuilder parsedQueryBob ( plannerBob . subobjStart ( " parsedQuery " ) ) ; <nl> + rawCanonicalQuery - > root ( ) - > toBSON ( & parsedQueryBob ) ; <nl> + parsedQueryBob . doneFast ( ) ; <nl> + <nl> + plannerBob . appendBool ( " emptyCollection " , true ) ; <nl> + <nl> + plannerBob . append ( " winningPlan " , " EOF " ) ; <nl> + <nl> + / / Empty array of rejected plans . <nl> + BSONArrayBuilder allPlansBob ( plannerBob . subarrayStart ( " rejectedPlans " ) ) ; <nl> + allPlansBob . doneFast ( ) ; <nl> + <nl> + plannerBob . doneFast ( ) ; <nl> + <nl> + generateServerInfo ( out ) ; <nl> + } <nl> + <nl> + / / static <nl> + Status Explain : : explain ( Collection * collection , <nl> + CanonicalQuery * rawCanonicalQuery , <nl> + size_t plannerOptions , <nl> + Explain : : Verbosity verbosity , <nl> + BSONObjBuilder * out ) { <nl> + invariant ( rawCanonicalQuery ) ; <nl> + auto_ptr < CanonicalQuery > canonicalQuery ( rawCanonicalQuery ) ; <nl> + <nl> + if ( NULL = = collection ) { <nl> + explainEmptyColl ( rawCanonicalQuery , out ) ; <nl> + return Status : : OK ( ) ; <nl> + } <nl> + <nl> + QueryPlannerParams plannerParams ; <nl> + plannerParams . options = plannerOptions ; <nl> + fillOutPlannerParams ( collection , rawCanonicalQuery , & plannerParams ) ; <nl> + <nl> + vector < QuerySolution * > solutions ; <nl> + Status status = QueryPlanner : : plan ( * canonicalQuery , plannerParams , & solutions ) ; <nl> + if ( ! status . isOK ( ) ) { <nl> + return Status ( ErrorCodes : : BadValue , <nl> + " error processing explain : " + canonicalQuery - > toString ( ) + <nl> + " planner returned error : " + status . reason ( ) ) ; <nl> + } <nl> + <nl> + / / We cannot figure out how to answer the query . Perhaps it requires an index <nl> + / / we do not have ? <nl> + if ( 0 = = solutions . size ( ) ) { <nl> + stream ss ; <nl> + ss < < " error processing explain : " < < canonicalQuery - > toString ( ) <nl> + < < " No query solutions " ; <nl> + return Status ( ErrorCodes : : BadValue , ss ) ; <nl> + } <nl> + else if ( 1 = = solutions . size ( ) ) { <nl> + return explainSinglePlan ( collection , rawCanonicalQuery , solutions [ 0 ] , verbosity , out ) ; <nl> + } <nl> + else { <nl> + return explainMultiPlan ( collection , rawCanonicalQuery , solutions , verbosity , out ) ; <nl> + } <nl> + } <nl> + <nl> + } / / namespace mongo <nl> new file mode 100644 <nl> index 000000000000 . . 675109bc2946 <nl> mmm / dev / null <nl> ppp b / src / mongo / db / query / explain . h <nl> <nl> + / * * <nl> + * Copyright ( C ) 2013 - 2014 MongoDB Inc . <nl> + * <nl> + * This program is free software : you can redistribute it and / or modify <nl> + * it under the terms of the GNU Affero General Public License , version 3 , <nl> + * as published by the Free Software Foundation . <nl> + * <nl> + * This program is distributed in the hope that it will be useful , <nl> + * but WITHOUT ANY WARRANTY ; without even the implied warranty of <nl> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the <nl> + * GNU Affero General Public License for more details . <nl> + * <nl> + * You should have received a copy of the GNU Affero General Public License <nl> + * along with this program . If not , see < http : / / www . gnu . org / licenses / > . <nl> + * <nl> + * As a special exception , the copyright holders give permission to link the <nl> + * code of portions of this program with the OpenSSL library under certain <nl> + * conditions as described in each individual source file and distribute <nl> + * linked combinations including the program with the OpenSSL library . You <nl> + * must comply with the GNU Affero General Public License in all respects for <nl> + * all of the code used other than as permitted herein . If you modify file ( s ) <nl> + * with this exception , you may extend this exception to your version of the <nl> + * file ( s ) , but you are not obligated to do so . If you do not wish to do so , <nl> + * delete this exception statement from your version . If you delete this <nl> + * exception statement from all source files in the program , then also delete <nl> + * it in the license file . <nl> + * / <nl> + <nl> + # pragma once <nl> + <nl> + # include " mongo / db / exec / plan_stats . h " <nl> + # include " mongo / db / query / canonical_query . h " <nl> + # include " mongo / db / query / query_planner_params . h " <nl> + # include " mongo / db / query / query_solution . h " <nl> + <nl> + namespace mongo { <nl> + <nl> + class Collection ; <nl> + <nl> + / / Temporarily hide the new explain implementation behind a setParameter . <nl> + / / TODO : take this out , and make the new implementation the default . <nl> + extern bool enableNewExplain ; <nl> + <nl> + / * * <nl> + * Namespace for the collection of static methods used to generate explain information . <nl> + * / <nl> + class Explain { <nl> + public : <nl> + / * * <nl> + * The various supported verbosity levels for explain . The order is <nl> + * significant : the enum values are assigned in order of increasing verbosity . <nl> + * / <nl> + enum Verbosity { <nl> + / / At all verbosities greater than or equal to QUERY_PLANNER , we display information <nl> + / / about the plan selected and alternate rejected plans . Does not include any execution - <nl> + / / related info . String alias is " queryPlanner " . <nl> + QUERY_PLANNER = 0 , <nl> + <nl> + / / At all verbosities greater than or equal to EXEC_STATS , we display a section of <nl> + / / output containing both overall execution stats , and stats per stage in the <nl> + / / execution tree . String alias is " execStats " . <nl> + EXEC_STATS = 1 , <nl> + <nl> + / / At this highest verbosity level , we generate the execution stats for each rejected <nl> + / / plan as well as the winning plan . String alias is " allPlansExecution " . <nl> + EXEC_ALL_PLANS = 2 <nl> + } ; <nl> + <nl> + / * * <nl> + * Adds the ' queryPlanner ' explain section to the BSON object being built <nl> + * by ' out ' . <nl> + * <nl> + * @ param query - - the query part of the operation being explained . <nl> + * @ param winnerStats - - the stats tree for the winning plan . <nl> + * @ param rejectedStats - - an array of stats trees , one per rejected plan <nl> + * / <nl> + static void generatePlannerInfo ( CanonicalQuery * query , <nl> + PlanStageStats * winnerStats , <nl> + vector < PlanStageStats * > & rejectedStats , <nl> + BSONObjBuilder * out ) ; <nl> + <nl> + / * * <nl> + * Adds the ' serverInfo ' explain section to the BSON object being build <nl> + * by ' out ' . <nl> + * / <nl> + static void generateServerInfo ( BSONObjBuilder * out ) ; <nl> + <nl> + / * * <nl> + * Converts the stats tree ' stats ' into a corresponding BSON object containing <nl> + * explain information . <nl> + * <nl> + * Explain info is added to ' bob ' according to the verbosity level passed in <nl> + * ' verbosity ' . <nl> + * / <nl> + static void explainTree ( const PlanStageStats & stats , <nl> + Explain : : Verbosity verbosity , <nl> + BSONObjBuilder * bob ) ; <nl> + <nl> + / * * <nl> + * Add explain info to ' out ' at verbosity ' verbosity ' in the case that there is <nl> + * only one query solution available . <nl> + * <nl> + * The query ' rawCanonicalQuery ' has one viable query solution ' solution ' in the <nl> + * collection ' collection ' . <nl> + * <nl> + * May use a PlanExecutor to run the solution in order to produce exec stats . <nl> + * / <nl> + static Status explainSinglePlan ( Collection * collection , <nl> + CanonicalQuery * rawCanonicalQuery , <nl> + QuerySolution * solution , <nl> + Explain : : Verbosity verbosity , <nl> + BSONObjBuilder * out ) ; <nl> + <nl> + / * * <nl> + * Add explain info to ' out ' at verbosity ' verbosity ' in the case that there are <nl> + * multiple query solutions available . <nl> + * <nl> + * The query ' rawCanonicalQuery ' has the corresponding query solutions in ' solutions ' . <nl> + * <nl> + * Uses a MultiPlan stage to choose the best plan , and to run the winning plan or the <nl> + * rejected plans as required by the verbosity level . <nl> + * / <nl> + static Status explainMultiPlan ( Collection * collection , <nl> + CanonicalQuery * rawCanonicalQuery , <nl> + vector < QuerySolution * > & solutions , <nl> + Explain : : Verbosity verbosity , <nl> + BSONObjBuilder * out ) ; <nl> + <nl> + / * * <nl> + * The format of the explain output is special if the collection is empty . <nl> + * <nl> + * Assuming that the collection is empty , adds the explain info for query <nl> + * ' rawCanonicalQuery ' to ' out ' . <nl> + * / <nl> + static void explainEmptyColl ( CanonicalQuery * rawCanonicalQuery , <nl> + BSONObjBuilder * out ) ; <nl> + <nl> + / * * <nl> + * Top - level explain entry point for a query . Plans ' rawCanonicalQuery ' in collection <nl> + * ' collection ' using the planner parameters in ' plannerOptions ' . <nl> + * <nl> + * The resulting explain BSON is added to ' out ' . The level of detail in the output is <nl> + * controlled by ' verbosity ' . <nl> + * <nl> + * If necessary , run the query in order to generate execution stats ( but throw out <nl> + * the results of the query ) . <nl> + * / <nl> + static Status explain ( Collection * collection , <nl> + CanonicalQuery * rawCanonicalQuery , <nl> + size_t plannerOptions , <nl> + Explain : : Verbosity verbosity , <nl> + BSONObjBuilder * out ) ; <nl> + } ; <nl> + <nl> + } / / namespace <nl> mmm a / src / mongo / db / query / get_runner . cpp <nl> ppp b / src / mongo / db / query / get_runner . cpp <nl> namespace mongo { <nl> / / Owns none of the arguments <nl> multiPlanStage - > addPlan ( solutions [ ix ] , nextPlanRoot , sharedWorkingSet ) ; <nl> } <nl> + <nl> multiPlanStage - > pickBestPlan ( ) ; <nl> + multiPlanStage - > generateCandidateStats ( ) ; <nl> + <nl> * out = new SingleSolutionRunner ( collection , <nl> canonicalQuery . release ( ) , <nl> multiPlanStage - > bestSolution ( ) , <nl> mmm a / src / mongo / db / query / index_bounds . cpp <nl> ppp b / src / mongo / db / query / index_bounds . cpp <nl> namespace mongo { <nl> return ss ; <nl> } <nl> <nl> - BSONObj IndexBounds : : toBSON ( ) const { <nl> + BSONObj IndexBounds : : toLegacyBSON ( ) const { <nl> BSONObjBuilder builder ; <nl> if ( isSimpleRange ) { <nl> / / TODO <nl> namespace mongo { <nl> return builder . obj ( ) ; <nl> } <nl> <nl> + BSONObj IndexBounds : : toBSON ( ) const { <nl> + BSONObjBuilder bob ; <nl> + vector < OrderedIntervalList > : : const_iterator itField ; <nl> + for ( itField = fields . begin ( ) ; itField ! = fields . end ( ) ; + + itField ) { <nl> + BSONArrayBuilder fieldBuilder ( bob . subarrayStart ( itField - > name ) ) ; <nl> + <nl> + vector < Interval > : : const_iterator itInterval ; <nl> + for ( itInterval = itField - > intervals . begin ( ) <nl> + ; itInterval ! = itField - > intervals . end ( ) <nl> + ; + + itInterval ) { <nl> + fieldBuilder . append ( itInterval - > toString ( ) ) ; <nl> + } <nl> + <nl> + fieldBuilder . doneFast ( ) ; <nl> + } <nl> + <nl> + return bob . obj ( ) ; <nl> + } <nl> + <nl> / / <nl> / / Validity checking for bounds <nl> / / <nl> mmm a / src / mongo / db / query / index_bounds . h <nl> ppp b / src / mongo / db / query / index_bounds . h <nl> namespace mongo { <nl> size_t getNumIntervals ( size_t i ) const ; <nl> Interval getInterval ( size_t i , size_t j ) const ; <nl> std : : string toString ( ) const ; <nl> + <nl> + / * * <nl> + * Legacy BSON format for explain . The format is an array of arrays for each field . <nl> + * <nl> + * TODO remove this function once the new explain format is on by default . <nl> + * <nl> + * Ex . <nl> + * { a : [ [ 1 , 1 ] , [ 3 , 10 ] ] , b : [ [ Infinity , 10 ] ] } <nl> + * / <nl> + BSONObj toLegacyBSON ( ) const ; <nl> + <nl> + / * * <nl> + * BSON format for explain . The format is an array of strings for each field . <nl> + * Each string represents an interval . The strings use " [ " and " ] " if the interval <nl> + * bounds are inclusive , and " ( " / " ) " if exclusive . <nl> + * <nl> + * Ex . <nl> + * { a : [ " [ 1 , 1 ] " , " ( 3 , 10 ) " ] , b : [ " [ Infinity , 10 ) " ] } <nl> + * / <nl> BSONObj toBSON ( ) const ; <nl> <nl> / / TODO : we use this for max / min scan . Consider migrating that . <nl> mmm a / src / mongo / db / query / new_find . cpp <nl> ppp b / src / mongo / db / query / new_find . cpp <nl> <nl> # include " mongo / db / exec / oplogstart . h " <nl> # include " mongo / db / exec / working_set_common . h " <nl> # include " mongo / db / keypattern . h " <nl> + # include " mongo / db / query / explain . h " <nl> # include " mongo / db / query / find_constants . h " <nl> # include " mongo / db / query / get_runner . h " <nl> # include " mongo / db / query / internal_plans . h " <nl> namespace mongo { <nl> / / We use this a lot below . <nl> const LiteParsedQuery & pq = cq - > getParsed ( ) ; <nl> <nl> + / / set this outside loop . we will need to use this both within loop and when deciding <nl> + / / to fill in explain information <nl> + const bool isExplain = pq . isExplain ( ) ; <nl> + <nl> + / / New - style explains get diverted through a separate path which calls back into the <nl> + / / query planner and query execution mechanisms . <nl> + / / <nl> + / / TODO temporary until find ( ) becomes a real command . <nl> + if ( isExplain & & enableNewExplain ) { <nl> + size_t options = QueryPlannerParams : : DEFAULT ; <nl> + if ( shardingState . needCollectionMetadata ( pq . ns ( ) ) ) { <nl> + options | = QueryPlannerParams : : INCLUDE_SHARD_FILTER ; <nl> + } <nl> + <nl> + BufBuilder bb ; <nl> + bb . skip ( sizeof ( QueryResult ) ) ; <nl> + <nl> + BSONObjBuilder explainBob ; <nl> + Status explainStatus = Explain : : explain ( collection , cq , options , <nl> + Explain : : QUERY_PLANNER , & explainBob ) ; <nl> + if ( ! explainStatus . isOK ( ) ) { <nl> + uasserted ( 17510 , " Explain error : " + explainStatus . reason ( ) ) ; <nl> + } <nl> + <nl> + / / Add the resulting object to the return buffer . <nl> + BSONObj explainObj = explainBob . obj ( ) ; <nl> + bb . appendBuf ( ( void * ) explainObj . objdata ( ) , explainObj . objsize ( ) ) ; <nl> + <nl> + curop . debug ( ) . iscommand = true ; <nl> + / / TODO : Does this get overwritten / do we really need to set this twice ? <nl> + curop . debug ( ) . query = q . query ; <nl> + <nl> + / / Set query result fields . <nl> + QueryResult * qr = reinterpret_cast < QueryResult * > ( bb . buf ( ) ) ; <nl> + bb . decouple ( ) ; <nl> + qr - > setResultFlagsToOk ( ) ; <nl> + qr - > len = bb . len ( ) ; <nl> + curop . debug ( ) . responseLength = bb . len ( ) ; <nl> + qr - > setOperation ( opReply ) ; <nl> + qr - > cursorId = 0 ; <nl> + qr - > startingFrom = 0 ; <nl> + qr - > nReturned = 1 ; <nl> + result . setData ( qr , true ) ; <nl> + return " " ; <nl> + } <nl> + <nl> / / We ' ll now try to get the query runner that will execute this query for us . There <nl> / / are a few cases in which we know upfront which runner we should get and , therefore , <nl> / / we shortcut the selection process here . <nl> namespace mongo { <nl> Runner : : RunnerState state ; <nl> / / uint64_t numMisplacedDocs = 0 ; <nl> <nl> - / / set this outside loop . we will need to use this both within loop and when deciding <nl> - / / to fill in explain information <nl> - const bool isExplain = pq . isExplain ( ) ; <nl> - <nl> / / Have we retrieved info about which plan the runner will <nl> / / use to execute the query yet ? <nl> bool gotPlanInfo = false ; <nl> mmm a / src / mongo / db / query / plan_cache_test . cpp <nl> ppp b / src / mongo / db / query / plan_cache_test . cpp <nl> namespace { <nl> PlanRankingDecision * createDecision ( size_t numPlans ) { <nl> auto_ptr < PlanRankingDecision > why ( new PlanRankingDecision ( ) ) ; <nl> for ( size_t i = 0 ; i < numPlans ; + + i ) { <nl> - auto_ptr < PlanStageStats > stats ( new PlanStageStats ( CommonStats ( ) , STAGE_COLLSCAN ) ) ; <nl> + CommonStats common ( " COLLSCAN " ) ; <nl> + auto_ptr < PlanStageStats > stats ( new PlanStageStats ( common , STAGE_COLLSCAN ) ) ; <nl> stats - > specific . reset ( new CollectionScanStats ( ) ) ; <nl> why - > stats . mutableVector ( ) . push_back ( stats . release ( ) ) ; <nl> why - > scores . push_back ( 0U ) ; <nl> mmm a / src / mongo / db / query / query_planner . cpp <nl> ppp b / src / mongo / db / query / query_planner . cpp <nl> namespace mongo { <nl> return ! sortIt . more ( ) ; <nl> } <nl> <nl> + / / static <nl> + const int QueryPlanner : : kPlannerVersion = 1 ; <nl> + <nl> Status QueryPlanner : : cacheDataFromTaggedTree ( const MatchExpression * const taggedTree , <nl> const vector < IndexEntry > & relevantIndices , <nl> PlanCacheIndexTree * * out ) { <nl> mmm a / src / mongo / db / query / query_planner . h <nl> ppp b / src / mongo / db / query / query_planner . h <nl> namespace mongo { <nl> * / <nl> class QueryPlanner { <nl> public : <nl> + / / Identifies the version of the query planner module . Reported in explain . <nl> + static const int kPlannerVersion ; <nl> + <nl> / * * <nl> * Outputs a series of possible solutions for the provided ' query ' into ' out ' . Uses the <nl> * indices and other data in ' params ' to plan with . <nl>
|
SERVER - 14096 explain find ( ) at queryPlanner verbosity
|
mongodb/mongo
|
3e39c96ebbd90ebeb91d46f9dace6988a0152763
|
2014-06-11T15:57:00Z
|
new file mode 100644 <nl> index 000000000000 . . 599e182ff5a4 <nl> mmm / dev / null <nl> ppp b / jstests / aggregation / expressions / merge_objects . js <nl> <nl> + / / Tests for the $ mergeObjects aggregation expression . <nl> + ( function ( ) { <nl> + " use strict " ; <nl> + <nl> + / / For assertErrorCode ( ) . <nl> + load ( " jstests / aggregation / extras / utils . js " ) ; <nl> + <nl> + let coll = db . merge_object_expr ; <nl> + coll . drop ( ) ; <nl> + <nl> + / / Test merging two objects together . <nl> + assert . writeOK ( coll . insert ( { _id : 0 , subObject : { b : 1 , c : 1 } } ) ) ; <nl> + let result = coll . aggregate ( [ <nl> + { $ match : { _id : 0 } } , <nl> + { $ project : { mergedDocument : { $ mergeObjects : [ " $ subObject " , { d : 1 } ] } } } <nl> + ] ) <nl> + . toArray ( ) ; <nl> + assert . eq ( result , [ { _id : 0 , mergedDocument : { b : 1 , c : 1 , d : 1 } } ] ) ; <nl> + <nl> + / / Test merging the root document with a new field . <nl> + assert . writeOK ( coll . insert ( { _id : 1 , a : 0 , b : 1 } ) ) ; <nl> + result = <nl> + coll . aggregate ( [ <nl> + { $ match : { _id : 1 } } , <nl> + { $ project : { mergedDocument : { $ mergeObjects : [ " $ $ ROOT " , { newField : " newValue " } ] } } } <nl> + ] ) <nl> + . toArray ( ) ; <nl> + assert . eq ( result , [ { _id : 1 , mergedDocument : { _id : 1 , a : 0 , b : 1 , newField : " newValue " } } ] ) ; <nl> + <nl> + / / Test replacing a field in the root . <nl> + assert . writeOK ( coll . insert ( { _id : 2 , a : 0 , b : 1 } ) ) ; <nl> + result = coll . aggregate ( [ <nl> + { $ match : { _id : 2 } } , <nl> + { $ project : { mergedDocument : { $ mergeObjects : [ " $ $ ROOT " , { a : " newValue " } ] } } } <nl> + ] ) <nl> + . toArray ( ) ; <nl> + assert . eq ( result , [ { _id : 2 , mergedDocument : { _id : 2 , a : " newValue " , b : 1 } } ] ) ; <nl> + <nl> + / / Test overriding a document with root . <nl> + assert . writeOK ( coll . insert ( { _id : 3 , a : 0 , b : 1 } ) ) ; <nl> + result = <nl> + coll . aggregate ( [ <nl> + { $ match : { _id : 3 } } , <nl> + { $ project : { mergedDocument : { $ mergeObjects : [ { a : " defaultValue " } , " $ $ ROOT " ] } } } <nl> + ] ) <nl> + . toArray ( ) ; <nl> + assert . eq ( result , [ { _id : 3 , mergedDocument : { a : 0 , _id : 3 , b : 1 } } ] ) ; <nl> + <nl> + / / Test replacing root with merged document . <nl> + assert . writeOK ( coll . insert ( { _id : 4 , a : 0 , subObject : { b : 1 , c : 2 } } ) ) ; <nl> + result = coll . aggregate ( [ <nl> + { $ match : { _id : 4 } } , <nl> + { $ replaceRoot : { newRoot : { $ mergeObjects : [ " $ $ ROOT " , " $ subObject " ] } } } <nl> + ] ) <nl> + . toArray ( ) ; <nl> + assert . eq ( result , [ { _id : 4 , a : 0 , subObject : { b : 1 , c : 2 } , b : 1 , c : 2 } ] ) ; <nl> + <nl> + / / Test merging with an embedded object . <nl> + assert . writeOK ( coll . insert ( { _id : 5 , subObject : { b : 1 , c : 1 } } ) ) ; <nl> + result = coll . aggregate ( [ <nl> + { $ match : { _id : 5 } } , <nl> + { <nl> + $ project : { <nl> + mergedDocument : <nl> + { $ mergeObjects : [ " $ subObject " , { subObject1 : { d : 1 } } , { e : 1 } ] } <nl> + } <nl> + } <nl> + ] ) <nl> + . toArray ( ) ; <nl> + assert . eq ( result , [ { _id : 5 , mergedDocument : { b : 1 , c : 1 , subObject1 : { d : 1 } , e : 1 } } ] ) ; <nl> + <nl> + / / Test for errors on non - document types . <nl> + assert . writeOK ( coll . insert ( { _id : 6 , a : " string " } ) ) ; <nl> + assertErrorCode ( coll , <nl> + [ <nl> + { $ match : { _id : 6 } } , <nl> + { $ project : { mergedDocument : { $ mergeObjects : [ " $ a " , { a : " newString " } ] } } } <nl> + ] , <nl> + 40400 ) ; <nl> + <nl> + assert . writeOK ( coll . insert ( { _id : 7 , a : { b : 1 } , c : 1 } ) ) ; <nl> + assertErrorCode ( <nl> + coll , <nl> + [ { $ match : { _id : 7 } } , { $ project : { mergedDocument : { $ mergeObjects : [ " $ a " , " $ c " ] } } } ] , <nl> + 40400 ) ; <nl> + <nl> + / / Test outputs with null values . <nl> + assert . writeOK ( coll . insert ( { _id : 8 , a : { b : 1 } } ) ) ; <nl> + result = coll . aggregate ( [ <nl> + { $ match : { _id : 8 } } , <nl> + { $ project : { mergedDocument : { $ mergeObjects : [ " $ a " , { b : null } ] } } } <nl> + ] ) <nl> + . toArray ( ) ; <nl> + assert . eq ( result , [ { _id : 8 , mergedDocument : { b : null } } ] ) ; <nl> + <nl> + / / Test output with undefined values . <nl> + assert . writeOK ( coll . insert ( { _id : 9 , a : { b : 1 } } ) ) ; <nl> + result = coll . aggregate ( [ <nl> + { $ match : { _id : 9 } } , <nl> + { $ project : { mergedDocument : { $ mergeObjects : [ " $ a " , { b : undefined } ] } } } <nl> + ] ) <nl> + . toArray ( ) ; <nl> + assert . eq ( result , [ { _id : 9 , mergedDocument : { b : undefined } } ] ) ; <nl> + <nl> + / / Test output with missing values . <nl> + assert . writeOK ( coll . insert ( { _id : 10 , a : { b : 1 } } ) ) ; <nl> + result = <nl> + coll . aggregate ( [ <nl> + { $ match : { _id : 10 } } , <nl> + { $ project : { mergedDocument : { $ mergeObjects : [ " $ a " , { b : " $ nonExistentField " } ] } } } <nl> + ] ) <nl> + . toArray ( ) ; <nl> + assert . eq ( result , [ { _id : 10 , mergedDocument : { b : 1 } } ] ) ; <nl> + <nl> + assert . writeOK ( coll . insert ( { _id : 11 , a : { b : 1 } } ) ) ; <nl> + result = coll . aggregate ( [ <nl> + { $ match : { _id : 11 } } , <nl> + { $ project : { mergedDocument : { $ mergeObjects : [ " $ a " , { b : " " } ] } } } <nl> + ] ) <nl> + . toArray ( ) ; <nl> + assert . eq ( result , [ { _id : 11 , mergedDocument : { b : " " } } ] ) ; <nl> + <nl> + / / Test outputs with empty values . <nl> + assert . writeOK ( coll . insert ( { _id : 12 , b : 1 , c : 1 } ) ) ; <nl> + result = <nl> + coll . aggregate ( [ { $ match : { _id : 12 } } , { $ project : { mergedDocument : { $ mergeObjects : [ { } ] } } } ] ) <nl> + . toArray ( ) ; <nl> + assert . eq ( result , [ { _id : 12 , mergedDocument : { } } ] ) ; <nl> + <nl> + result = coll . aggregate ( <nl> + [ { $ match : { _id : 12 } } , { $ project : { mergedDocument : { $ mergeObjects : [ { } , { } ] } } } ] ) <nl> + . toArray ( ) ; <nl> + assert . eq ( result , [ { _id : 12 , mergedDocument : { } } ] ) ; <nl> + <nl> + / / Test merge within a $ group stage . <nl> + assert . writeOK ( coll . insert ( { _id : 13 , group : 1 , obj : { } } ) ) ; <nl> + assert . writeOK ( coll . insert ( { _id : 14 , group : 1 , obj : { a : 2 , b : 2 } } ) ) ; <nl> + assert . writeOK ( coll . insert ( { _id : 15 , group : 1 , obj : { a : 1 , c : 3 } } ) ) ; <nl> + assert . writeOK ( coll . insert ( { _id : 16 , group : 2 , obj : { a : 1 , b : 1 } } ) ) ; <nl> + result = coll . aggregate ( [ <nl> + { $ match : { _id : { $ in : [ 13 , 14 , 15 , 16 ] } } } , <nl> + { $ sort : { _id : 1 } } , <nl> + { $ group : { _id : " $ group " , mergedDocument : { $ mergeObjects : " $ obj " } } } , <nl> + { $ sort : { _id : 1 } } , <nl> + ] ) <nl> + . toArray ( ) ; <nl> + assert . eq ( <nl> + result , <nl> + [ { _id : 1 , mergedDocument : { a : 1 , b : 2 , c : 3 } } , { _id : 2 , mergedDocument : { a : 1 , b : 1 } } ] ) ; <nl> + <nl> + / / Test merge with $ $ REMOVE operator . <nl> + assert . writeOK ( coll . insert ( { _id : 17 , a : { b : 2 } } ) ) ; <nl> + result = coll . aggregate ( [ <nl> + { $ match : { _id : 17 } } , <nl> + { $ project : { mergedDocument : { $ mergeObjects : [ " $ a " , { b : " $ $ REMOVE " } ] } } } <nl> + ] ) <nl> + . toArray ( ) ; <nl> + assert . eq ( result , [ { _id : 17 , mergedDocument : { b : 2 } } ] ) ; <nl> + <nl> + } ( ) ) ; <nl> mmm a / src / mongo / db / pipeline / SConscript <nl> ppp b / src / mongo / db / pipeline / SConscript <nl> env . Library ( <nl> ' accumulator_push . cpp ' , <nl> ' accumulator_std_dev . cpp ' , <nl> ' accumulator_sum . cpp ' , <nl> + ' accumulator_merge_objects . cpp ' <nl> ] , <nl> LIBDEPS = [ <nl> ' document_value ' , <nl> mmm a / src / mongo / db / pipeline / accumulator . h <nl> ppp b / src / mongo / db / pipeline / accumulator . h <nl> class Accumulator : public RefCountable { <nl> / * * Marks the end of the evaluate ( ) phase and return accumulated result . <nl> * toBeMerged should be true when the outputs will be merged by process ( ) . <nl> * / <nl> - virtual Value getValue ( bool toBeMerged ) const = 0 ; <nl> + virtual Value getValue ( bool toBeMerged ) = 0 ; <nl> <nl> / / / The name of the op as used in a serialization of the pipeline . <nl> virtual const char * getOpName ( ) const = 0 ; <nl> class AccumulatorAddToSet final : public Accumulator { <nl> explicit AccumulatorAddToSet ( const boost : : intrusive_ptr < ExpressionContext > & expCtx ) ; <nl> <nl> void processInternal ( const Value & input , bool merging ) final ; <nl> - Value getValue ( bool toBeMerged ) const final ; <nl> + Value getValue ( bool toBeMerged ) final ; <nl> const char * getOpName ( ) const final ; <nl> void reset ( ) final ; <nl> <nl> class AccumulatorFirst final : public Accumulator { <nl> explicit AccumulatorFirst ( const boost : : intrusive_ptr < ExpressionContext > & expCtx ) ; <nl> <nl> void processInternal ( const Value & input , bool merging ) final ; <nl> - Value getValue ( bool toBeMerged ) const final ; <nl> + Value getValue ( bool toBeMerged ) final ; <nl> const char * getOpName ( ) const final ; <nl> void reset ( ) final ; <nl> <nl> class AccumulatorLast final : public Accumulator { <nl> explicit AccumulatorLast ( const boost : : intrusive_ptr < ExpressionContext > & expCtx ) ; <nl> <nl> void processInternal ( const Value & input , bool merging ) final ; <nl> - Value getValue ( bool toBeMerged ) const final ; <nl> + Value getValue ( bool toBeMerged ) final ; <nl> const char * getOpName ( ) const final ; <nl> void reset ( ) final ; <nl> <nl> class AccumulatorSum final : public Accumulator { <nl> explicit AccumulatorSum ( const boost : : intrusive_ptr < ExpressionContext > & expCtx ) ; <nl> <nl> void processInternal ( const Value & input , bool merging ) final ; <nl> - Value getValue ( bool toBeMerged ) const final ; <nl> + Value getValue ( bool toBeMerged ) final ; <nl> const char * getOpName ( ) const final ; <nl> void reset ( ) final ; <nl> <nl> class AccumulatorMinMax : public Accumulator { <nl> AccumulatorMinMax ( const boost : : intrusive_ptr < ExpressionContext > & expCtx , Sense sense ) ; <nl> <nl> void processInternal ( const Value & input , bool merging ) final ; <nl> - Value getValue ( bool toBeMerged ) const final ; <nl> + Value getValue ( bool toBeMerged ) final ; <nl> const char * getOpName ( ) const final ; <nl> void reset ( ) final ; <nl> <nl> class AccumulatorPush final : public Accumulator { <nl> explicit AccumulatorPush ( const boost : : intrusive_ptr < ExpressionContext > & expCtx ) ; <nl> <nl> void processInternal ( const Value & input , bool merging ) final ; <nl> - Value getValue ( bool toBeMerged ) const final ; <nl> + Value getValue ( bool toBeMerged ) final ; <nl> const char * getOpName ( ) const final ; <nl> void reset ( ) final ; <nl> <nl> class AccumulatorAvg final : public Accumulator { <nl> explicit AccumulatorAvg ( const boost : : intrusive_ptr < ExpressionContext > & expCtx ) ; <nl> <nl> void processInternal ( const Value & input , bool merging ) final ; <nl> - Value getValue ( bool toBeMerged ) const final ; <nl> + Value getValue ( bool toBeMerged ) final ; <nl> const char * getOpName ( ) const final ; <nl> void reset ( ) final ; <nl> <nl> class AccumulatorStdDev : public Accumulator { <nl> AccumulatorStdDev ( const boost : : intrusive_ptr < ExpressionContext > & expCtx , bool isSamp ) ; <nl> <nl> void processInternal ( const Value & input , bool merging ) final ; <nl> - Value getValue ( bool toBeMerged ) const final ; <nl> + Value getValue ( bool toBeMerged ) final ; <nl> const char * getOpName ( ) const final ; <nl> void reset ( ) final ; <nl> <nl> class AccumulatorStdDevSamp final : public AccumulatorStdDev { <nl> static boost : : intrusive_ptr < Accumulator > create ( <nl> const boost : : intrusive_ptr < ExpressionContext > & expCtx ) ; <nl> } ; <nl> + <nl> + class AccumulatorMergeObjects : public Accumulator { <nl> + public : <nl> + AccumulatorMergeObjects ( const boost : : intrusive_ptr < ExpressionContext > & expCtx ) ; <nl> + <nl> + void processInternal ( const Value & input , bool merging ) final ; <nl> + Value getValue ( bool toBeMerged ) final ; <nl> + const char * getOpName ( ) const final ; <nl> + void reset ( ) final ; <nl> + <nl> + static boost : : intrusive_ptr < Accumulator > create ( <nl> + const boost : : intrusive_ptr < ExpressionContext > & expCtx ) ; <nl> + <nl> + private : <nl> + MutableDocument _output ; <nl> + } ; <nl> } <nl> mmm a / src / mongo / db / pipeline / accumulator_add_to_set . cpp <nl> ppp b / src / mongo / db / pipeline / accumulator_add_to_set . cpp <nl> void AccumulatorAddToSet : : processInternal ( const Value & input , bool merging ) { <nl> } <nl> } <nl> <nl> - Value AccumulatorAddToSet : : getValue ( bool toBeMerged ) const { <nl> + Value AccumulatorAddToSet : : getValue ( bool toBeMerged ) { <nl> return Value ( vector < Value > ( _set . begin ( ) , _set . end ( ) ) ) ; <nl> } <nl> <nl> mmm a / src / mongo / db / pipeline / accumulator_avg . cpp <nl> ppp b / src / mongo / db / pipeline / accumulator_avg . cpp <nl> Decimal128 AccumulatorAvg : : _getDecimalTotal ( ) const { <nl> return _decimalTotal . add ( _nonDecimalTotal . getDecimal ( ) ) ; <nl> } <nl> <nl> - Value AccumulatorAvg : : getValue ( bool toBeMerged ) const { <nl> + Value AccumulatorAvg : : getValue ( bool toBeMerged ) { <nl> if ( toBeMerged ) { <nl> if ( _isDecimal ) <nl> return Value ( Document { { subTotalName , _getDecimalTotal ( ) } , { countName , _count } } ) ; <nl> mmm a / src / mongo / db / pipeline / accumulator_first . cpp <nl> ppp b / src / mongo / db / pipeline / accumulator_first . cpp <nl> void AccumulatorFirst : : processInternal ( const Value & input , bool merging ) { <nl> } <nl> } <nl> <nl> - Value AccumulatorFirst : : getValue ( bool toBeMerged ) const { <nl> + Value AccumulatorFirst : : getValue ( bool toBeMerged ) { <nl> return _first ; <nl> } <nl> <nl> mmm a / src / mongo / db / pipeline / accumulator_last . cpp <nl> ppp b / src / mongo / db / pipeline / accumulator_last . cpp <nl> void AccumulatorLast : : processInternal ( const Value & input , bool merging ) { <nl> _memUsageBytes = sizeof ( * this ) + _last . getApproximateSize ( ) - sizeof ( Value ) ; <nl> } <nl> <nl> - Value AccumulatorLast : : getValue ( bool toBeMerged ) const { <nl> + Value AccumulatorLast : : getValue ( bool toBeMerged ) { <nl> return _last ; <nl> } <nl> <nl> new file mode 100644 <nl> index 000000000000 . . 1584d8ba2c4c <nl> mmm / dev / null <nl> ppp b / src / mongo / db / pipeline / accumulator_merge_objects . cpp <nl> <nl> + / * * <nl> + * Copyright ( c ) 2017 10gen Inc . <nl> + * <nl> + * This program is free software : you can redistribute it and / or modify <nl> + * it under the terms of the GNU Affero General Public License , version 3 , <nl> + * as published by the Free Software Foundation . <nl> + * <nl> + * This program is distributed in the hope that it will be useful , <nl> + * but WITHOUT ANY WARRANTY ; without even the implied warranty of <nl> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the <nl> + * GNU Affero General Public License for more details . <nl> + * <nl> + * You should have received a copy of the GNU Affero General Public License <nl> + * along with this program . If not , see < http : / / www . gnu . org / licenses / > . <nl> + * <nl> + * As a special exception , the copyright holders give permission to link the <nl> + * code of portions of this program with the OpenSSL library under certain <nl> + * conditions as described in each individual source file and distribute <nl> + * linked combinations including the program with the OpenSSL library . You <nl> + * must comply with the GNU Affero General Public License in all respects for <nl> + * all of the code used other than as permitted herein . If you modify file ( s ) <nl> + * with this exception , you may extend this exception to your version of the <nl> + * file ( s ) , but you are not obligated to do so . If you do not wish to do so , <nl> + * delete this exception statement from your version . If you delete this <nl> + * exception statement from all source files in the program , then also delete <nl> + * it in the license file . <nl> + * / <nl> + <nl> + # include " mongo / platform / basic . h " <nl> + <nl> + # include " mongo / db / pipeline / accumulator . h " <nl> + <nl> + # include " mongo / db / pipeline / accumulation_statement . h " <nl> + # include " mongo / db / pipeline / expression . h " <nl> + # include " mongo / db / pipeline / value . h " <nl> + <nl> + namespace mongo { <nl> + <nl> + using boost : : intrusive_ptr ; <nl> + <nl> + / * mmmmmmmmmmmmmmmmmmmmmmmm - AccumulatorMergeObjects mmmmmmmmmmmmmmmmmmmmmmmmmmm - - * / <nl> + <nl> + REGISTER_ACCUMULATOR ( mergeObjects , AccumulatorMergeObjects : : create ) ; <nl> + REGISTER_EXPRESSION ( mergeObjects , ExpressionFromAccumulator < AccumulatorMergeObjects > : : parse ) ; <nl> + <nl> + const char * AccumulatorMergeObjects : : getOpName ( ) const { <nl> + return " $ mergeObjects " ; <nl> + } <nl> + <nl> + intrusive_ptr < Accumulator > AccumulatorMergeObjects : : create ( <nl> + const boost : : intrusive_ptr < ExpressionContext > & expCtx ) { <nl> + return new AccumulatorMergeObjects ( expCtx ) ; <nl> + } <nl> + <nl> + AccumulatorMergeObjects : : AccumulatorMergeObjects ( <nl> + const boost : : intrusive_ptr < ExpressionContext > & expCtx ) <nl> + : Accumulator ( expCtx ) { <nl> + _memUsageBytes = sizeof ( * this ) ; <nl> + } <nl> + <nl> + void AccumulatorMergeObjects : : reset ( ) { <nl> + _memUsageBytes = sizeof ( * this ) ; <nl> + _output . reset ( ) ; <nl> + } <nl> + <nl> + void AccumulatorMergeObjects : : processInternal ( const Value & input , bool merging ) { <nl> + if ( input . nullish ( ) ) { <nl> + return ; <nl> + } <nl> + <nl> + uassert ( 40400 , <nl> + str : : stream ( ) < < " $ mergeObjects requires object inputs , but input " < < input . toString ( ) <nl> + < < " is of type " <nl> + < < typeName ( input . getType ( ) ) , <nl> + ( input . getType ( ) = = BSONType : : Object ) ) ; <nl> + <nl> + FieldIterator iter = input . getDocument ( ) . fieldIterator ( ) ; <nl> + while ( iter . more ( ) ) { <nl> + Document : : FieldPair pair = iter . next ( ) ; <nl> + / / Ignore missing values only , null and undefined are still considered . <nl> + if ( pair . second . missing ( ) ) <nl> + continue ; <nl> + <nl> + _output . setField ( pair . first , pair . second ) ; <nl> + } <nl> + _memUsageBytes = sizeof ( * this ) + _output . getApproximateSize ( ) ; <nl> + } <nl> + <nl> + Value AccumulatorMergeObjects : : getValue ( bool toBeMerged ) { <nl> + return _output . freezeToValue ( ) ; <nl> + } <nl> + <nl> + } / / namespace mongo <nl> mmm a / src / mongo / db / pipeline / accumulator_min_max . cpp <nl> ppp b / src / mongo / db / pipeline / accumulator_min_max . cpp <nl> void AccumulatorMinMax : : processInternal ( const Value & input , bool merging ) { <nl> } <nl> } <nl> <nl> - Value AccumulatorMinMax : : getValue ( bool toBeMerged ) const { <nl> + Value AccumulatorMinMax : : getValue ( bool toBeMerged ) { <nl> if ( _val . missing ( ) ) { <nl> return Value ( BSONNULL ) ; <nl> } <nl> mmm a / src / mongo / db / pipeline / accumulator_push . cpp <nl> ppp b / src / mongo / db / pipeline / accumulator_push . cpp <nl> void AccumulatorPush : : processInternal ( const Value & input , bool merging ) { <nl> } <nl> } <nl> <nl> - Value AccumulatorPush : : getValue ( bool toBeMerged ) const { <nl> + Value AccumulatorPush : : getValue ( bool toBeMerged ) { <nl> return Value ( vpValue ) ; <nl> } <nl> <nl> mmm a / src / mongo / db / pipeline / accumulator_std_dev . cpp <nl> ppp b / src / mongo / db / pipeline / accumulator_std_dev . cpp <nl> void AccumulatorStdDev : : processInternal ( const Value & input , bool merging ) { <nl> } <nl> } <nl> <nl> - Value AccumulatorStdDev : : getValue ( bool toBeMerged ) const { <nl> + Value AccumulatorStdDev : : getValue ( bool toBeMerged ) { <nl> if ( ! toBeMerged ) { <nl> const long long adjustedCount = ( _isSamp ? _count - 1 : _count ) ; <nl> if ( adjustedCount < = 0 ) <nl> mmm a / src / mongo / db / pipeline / accumulator_sum . cpp <nl> ppp b / src / mongo / db / pipeline / accumulator_sum . cpp <nl> intrusive_ptr < Accumulator > AccumulatorSum : : create ( <nl> return new AccumulatorSum ( expCtx ) ; <nl> } <nl> <nl> - Value AccumulatorSum : : getValue ( bool toBeMerged ) const { <nl> + Value AccumulatorSum : : getValue ( bool toBeMerged ) { <nl> switch ( totalType ) { <nl> case NumberInt : <nl> if ( nonDecimalTotal . fitsLong ( ) ) <nl> mmm a / src / mongo / db / pipeline / accumulator_test . cpp <nl> ppp b / src / mongo / db / pipeline / accumulator_test . cpp <nl> TEST ( Accumulators , AddToSetRespectsCollation ) { <nl> Value ( std : : vector < Value > { Value ( " a " _sd ) } ) } } ) ; <nl> } <nl> <nl> + / * mmmmmmmmmmmmmmmmmmmmmmmm - AccumulatorMergeObjects mmmmmmmmmmmmmmmmmmmmmmmm - - * / <nl> + <nl> + namespace AccumulatorMergeObjects { <nl> + <nl> + TEST ( AccumulatorMergeObjects , MergingZeroObjectsShouldReturnEmptyDocument ) { <nl> + intrusive_ptr < ExpressionContext > expCtx ( new ExpressionContextForTest ( ) ) ; <nl> + <nl> + assertExpectedResults ( " $ mergeObjects " , expCtx , { { { } , { Value ( Document ( { } ) ) } } } ) ; <nl> + } <nl> + <nl> + TEST ( AccumulatorMergeObjects , MergingWithSingleObjectShouldLeaveUnchanged ) { <nl> + intrusive_ptr < ExpressionContext > expCtx ( new ExpressionContextForTest ( ) ) ; <nl> + <nl> + assertExpectedResults ( " $ mergeObjects " , expCtx , { { { } , { Value ( Document ( { } ) ) } } } ) ; <nl> + <nl> + auto doc = Value ( Document ( { { " a " , 1 } , { " b " , 1 } } ) ) ; <nl> + assertExpectedResults ( " $ mergeObjects " , expCtx , { { { doc } , doc } } ) ; <nl> + } <nl> + <nl> + TEST ( AccumulatorMergeObjects , MergingDisjointObjectsShouldIncludeAllFields ) { <nl> + intrusive_ptr < ExpressionContext > expCtx ( new ExpressionContextForTest ( ) ) ; <nl> + auto first = Value ( Document ( { { " a " , 1 } , { " b " , 1 } } ) ) ; <nl> + auto second = Value ( Document ( { { " c " , 1 } } ) ) ; <nl> + assertExpectedResults ( " $ mergeObjects " , <nl> + expCtx , <nl> + { { { first , second } , Value ( Document ( { { " a " , 1 } , { " b " , 1 } , { " c " , 1 } } ) ) } } ) ; <nl> + } <nl> + <nl> + TEST ( AccumulatorMergeObjects , MergingIntersectingObjectsShouldOverrideInOrderReceived ) { <nl> + intrusive_ptr < ExpressionContext > expCtx ( new ExpressionContextForTest ( ) ) ; <nl> + auto first = Value ( Document ( { { " a " , " oldValue " _sd } , { " b " , 0 } , { " c " , 1 } } ) ) ; <nl> + auto second = Value ( Document ( { { " a " , " newValue " _sd } } ) ) ; <nl> + assertExpectedResults ( <nl> + " $ mergeObjects " , <nl> + expCtx , <nl> + { { { first , second } , Value ( Document ( { { " a " , " newValue " _sd } , { " b " , 0 } , { " c " , 1 } } ) ) } } ) ; <nl> + } <nl> + <nl> + TEST ( AccumulatorMergeObjects , MergingIntersectingEmbeddedObjectsShouldOverrideInOrderReceived ) { <nl> + intrusive_ptr < ExpressionContext > expCtx ( new ExpressionContextForTest ( ) ) ; <nl> + auto firstSubDoc = Document ( { { " a " , 1 } , { " b " , 2 } , { " c " , 3 } } ) ; <nl> + auto secondSubDoc = Document ( { { " a " , 2 } , { " b " , 1 } } ) ; <nl> + auto first = Value ( Document ( { { " d " , 1 } , { " subDoc " , firstSubDoc } } ) ) ; <nl> + auto second = Value ( Document ( { { " subDoc " , secondSubDoc } } ) ) ; <nl> + auto expected = Value ( Document ( { { " d " , 1 } , { " subDoc " , secondSubDoc } } ) ) ; <nl> + assertExpectedResults ( " $ mergeObjects " , expCtx , { { { first , second } , expected } } ) ; <nl> + } <nl> + <nl> + TEST ( AccumulatorMergeObjects , MergingWithEmptyDocumentShouldIgnore ) { <nl> + intrusive_ptr < ExpressionContext > expCtx ( new ExpressionContextForTest ( ) ) ; <nl> + auto first = Value ( Document ( { { " a " , 0 } , { " b " , 1 } , { " c " , 1 } } ) ) ; <nl> + auto second = Value ( Document ( { } ) ) ; <nl> + auto expected = Value ( Document ( { { " a " , 0 } , { " b " , 1 } , { " c " , 1 } } ) ) ; <nl> + assertExpectedResults ( " $ mergeObjects " , expCtx , { { { first , second } , expected } } ) ; <nl> + } <nl> + <nl> + } / / namespace AccumulatorMergeObjects <nl> + <nl> } / / namespace AccumulatorTests <nl> mmm a / src / mongo / db / pipeline / document . h <nl> ppp b / src / mongo / db / pipeline / document . h <nl> class MutableDocument { <nl> return Document ( storagePtr ( ) ) ; <nl> } <nl> <nl> + size_t getApproximateSize ( ) { <nl> + return peek ( ) . getApproximateSize ( ) ; <nl> + } <nl> + <nl> private : <nl> friend class MutableValue ; / / for access to next constructor <nl> explicit MutableDocument ( MutableValue mv ) : _storageHolder ( NULL ) , _storage ( mv . getDocPtr ( ) ) { } <nl> mmm a / src / mongo / db / pipeline / expression_test . cpp <nl> ppp b / src / mongo / db / pipeline / expression_test . cpp <nl> using std : : string ; <nl> using std : : vector ; <nl> using std : : list ; <nl> <nl> + / * * <nl> + * Creates an expression given by ' expressionName ' and evaluates it using <nl> + * ' operands ' as inputs , returning the result . <nl> + * / <nl> + static Value evaluateExpression ( const string & expressionName , <nl> + const vector < ImplicitValue > & operands ) { <nl> + intrusive_ptr < ExpressionContextForTest > expCtx ( new ExpressionContextForTest ( ) ) ; <nl> + VariablesIdGenerator idGenerator ; <nl> + VariablesParseState vps ( & idGenerator ) ; <nl> + const BSONObj obj = BSON ( expressionName < < ImplicitValue : : convertToValue ( operands ) ) ; <nl> + auto expression = Expression : : parseExpression ( expCtx , obj , vps ) ; <nl> + Value result = expression - > evaluate ( Document ( ) ) ; <nl> + return result ; <nl> + } <nl> + <nl> / * * <nl> * Takes the name of an expression as its first argument and a list of pairs of arguments and <nl> * expected results as its second argument , and asserts that for the given expression the arguments <nl> * evaluate to the expected results . <nl> * / <nl> - static void assertExpectedResults ( string expression , <nl> - initializer_list < pair < vector < Value > , Value > > operations ) { <nl> + static void assertExpectedResults ( <nl> + const string & expression , <nl> + initializer_list < pair < vector < ImplicitValue > , ImplicitValue > > operations ) { <nl> for ( auto & & op : operations ) { <nl> try { <nl> - intrusive_ptr < ExpressionContextForTest > expCtx ( new ExpressionContextForTest ( ) ) ; <nl> - VariablesIdGenerator idGenerator ; <nl> - VariablesParseState vps ( & idGenerator ) ; <nl> - const BSONObj obj = BSON ( expression < < Value ( op . first ) ) ; <nl> - auto expression = Expression : : parseExpression ( expCtx , obj , vps ) ; <nl> - Value result = expression - > evaluate ( Document ( ) ) ; <nl> + Value result = evaluateExpression ( expression , op . first ) ; <nl> ASSERT_VALUE_EQ ( op . second , result ) ; <nl> ASSERT_EQUALS ( op . second . getType ( ) , result . getType ( ) ) ; <nl> } catch ( . . . ) { <nl> - log ( ) < < " failed with arguments : " < < Value ( op . first ) ; <nl> + log ( ) < < " failed with arguments : " < < ImplicitValue : : convertToValue ( op . first ) ; <nl> throw ; <nl> } <nl> } <nl> TEST ( BuiltinRemoveVariableTest , RemoveSerializesCorrectlyAfterOptimization ) { <nl> <nl> } / / namespace BuiltinRemoveVariable <nl> <nl> + / * mmmmmmmmmmmmmmmmmmmmmmmm - ExpressionMergeObjects mmmmmmmmmmmmmmmmmmmmmmmm - - * / <nl> + <nl> + namespace ExpressionMergeObjects { <nl> + <nl> + TEST ( ExpressionMergeObjects , MergingWithSingleObjectShouldLeaveUnchanged ) { <nl> + assertExpectedResults ( " $ mergeObjects " , { { { } , { Document ( { } ) } } } ) ; <nl> + <nl> + auto doc = Document ( { { " a " , 1 } , { " b " , 1 } } ) ; <nl> + assertExpectedResults ( " $ mergeObjects " , { { { doc } , doc } } ) ; <nl> + } <nl> + <nl> + TEST ( ExpressionMergeObjects , MergingDisjointObjectsShouldIncludeAllFields ) { <nl> + auto first = Document ( { { " a " , 1 } , { " b " , 1 } } ) ; <nl> + auto second = Document ( { { " c " , 1 } } ) ; <nl> + assertExpectedResults ( " $ mergeObjects " , <nl> + { { { first , second } , Document ( { { " a " , 1 } , { " b " , 1 } , { " c " , 1 } } ) } } ) ; <nl> + } <nl> + <nl> + TEST ( ExpressionMergeObjects , MergingIntersectingObjectsShouldOverrideInOrderReceived ) { <nl> + auto first = Document ( { { " a " , " oldValue " _sd } , { " b " , 0 } , { " c " , 1 } } ) ; <nl> + auto second = Document ( { { " a " , " newValue " _sd } } ) ; <nl> + assertExpectedResults ( <nl> + " $ mergeObjects " , { { { first , second } , Document ( { { " a " , " newValue " _sd } , { " b " , 0 } , { " c " , 1 } } ) } } ) ; <nl> + } <nl> + <nl> + TEST ( ExpressionMergeObjects , MergingIntersectingEmbeddedObjectsShouldOverrideInOrderReceived ) { <nl> + auto firstSubDoc = Document ( { { " a " , 1 } , { " b " , 2 } , { " c " , 3 } } ) ; <nl> + auto secondSubDoc = Document ( { { " a " , 2 } , { " b " , 1 } } ) ; <nl> + auto first = Document ( { { " d " , 1 } , { " subDoc " , firstSubDoc } } ) ; <nl> + auto second = Document ( { { " subDoc " , secondSubDoc } } ) ; <nl> + auto expected = Document ( { { " d " , 1 } , { " subDoc " , secondSubDoc } } ) ; <nl> + assertExpectedResults ( " $ mergeObjects " , { { { first , second } , expected } } ) ; <nl> + } <nl> + <nl> + TEST ( ExpressionMergeObjects , MergingWithEmptyDocumentShouldIgnore ) { <nl> + auto first = Document ( { { " a " , 0 } , { " b " , 1 } , { " c " , 1 } } ) ; <nl> + auto second = Document ( { } ) ; <nl> + auto expected = Document ( { { " a " , 0 } , { " b " , 1 } , { " c " , 1 } } ) ; <nl> + assertExpectedResults ( " $ mergeObjects " , { { { first , second } , expected } } ) ; <nl> + } <nl> + <nl> + TEST ( ExpressionMergeObjects , MergingSingleArgumentArrayShouldUnwindAndMerge ) { <nl> + std : : vector < Document > first = { Document ( { { " a " , 1 } } ) , Document ( { { " a " , 2 } } ) } ; <nl> + auto expected = Document ( { { " a " , 2 } } ) ; <nl> + assertExpectedResults ( " $ mergeObjects " , { { { first } , expected } } ) ; <nl> + } <nl> + <nl> + TEST ( ExpressionMergeObjects , MergingArrayWithDocumentShouldThrowException ) { <nl> + std : : vector < Document > first = { Document ( { { " a " , 1 } } ) , Document ( { { " a " , 2 } } ) } ; <nl> + auto second = Document ( { { " b " , 2 } } ) ; <nl> + ASSERT_THROWS_CODE ( evaluateExpression ( " $ mergeObjects " , { first , second } ) , UserException , 40400 ) ; <nl> + } <nl> + <nl> + TEST ( ExpressionMergeObjects , MergingArrayContainingInvalidTypesShouldThrowException ) { <nl> + std : : vector < Value > first = { Value ( Document ( { { " validType " , 1 } } ) ) , Value ( " invalidType " _sd ) } ; <nl> + ASSERT_THROWS_CODE ( evaluateExpression ( " $ mergeObjects " , { first } ) , UserException , 40400 ) ; <nl> + } <nl> + <nl> + TEST ( ExpressionMergeObjects , MergingNonObjectsShouldThrowException ) { <nl> + ASSERT_THROWS_CODE ( <nl> + evaluateExpression ( " $ mergeObjects " , { " invalidArg " _sd } ) , UserException , 40400 ) ; <nl> + <nl> + ASSERT_THROWS_CODE ( <nl> + evaluateExpression ( " $ mergeObjects " , { " invalidArg " _sd , Document ( { { " validArg " , 1 } } ) } ) , <nl> + UserException , <nl> + 40400 ) ; <nl> + <nl> + ASSERT_THROWS_CODE ( evaluateExpression ( " $ mergeObjects " , { 1 , Document ( { { " validArg " , 1 } } ) } ) , <nl> + UserException , <nl> + 40400 ) ; <nl> + } <nl> + <nl> + } / / namespace ExpressionMergeObjects <nl> + <nl> + <nl> namespace ToLower { <nl> <nl> class ExpectedResultBase { <nl> mmm a / src / mongo / db / pipeline / value . h <nl> ppp b / src / mongo / db / pipeline / value . h <nl> class ImplicitValue : public Value { <nl> public : <nl> template < typename T > <nl> ImplicitValue ( T arg ) : Value ( std : : move ( arg ) ) { } <nl> + <nl> + / * * <nl> + * Converts a vector of Implicit values to a single Value object . <nl> + * / <nl> + static Value convertToValue ( const std : : vector < ImplicitValue > & vec ) { <nl> + std : : vector < Value > values ; <nl> + for_each ( <nl> + vec . begin ( ) , vec . end ( ) , ( [ & ] ( const ImplicitValue & val ) { values . push_back ( val ) ; } ) ) ; <nl> + return Value ( values ) ; <nl> + } <nl> } ; <nl> } <nl> <nl> mmm a / src / mongo / unittest / unittest . h <nl> ppp b / src / mongo / unittest / unittest . h <nl> <nl> * Behaves like ASSERT_THROWS , above , but also fails if calling getCode ( ) on the thrown exception <nl> * does not return an error code equal to EXPECTED_CODE . <nl> * / <nl> - # define ASSERT_THROWS_CODE ( STATEMENT , EXCEPTION_TYPE , EXPECTED_CODE ) \ <nl> - ASSERT_THROWS_PRED ( STATEMENT , EXCEPTION_TYPE , ( [ ] ( const EXCEPTION_TYPE & ex ) { \ <nl> - return ( EXPECTED_CODE ) = = ex . getCode ( ) ; \ <nl> + # define ASSERT_THROWS_CODE ( STATEMENT , EXCEPTION_TYPE , EXPECTED_CODE ) \ <nl> + ASSERT_THROWS_PRED ( STATEMENT , EXCEPTION_TYPE , ( [ & ] ( const EXCEPTION_TYPE & ex ) { \ <nl> + return ( EXPECTED_CODE ) = = ex . getCode ( ) ; \ <nl> } ) ) <nl> <nl> / * * <nl> <nl> * does not return a string equal to EXPECTED_WHAT . <nl> * / <nl> # define ASSERT_THROWS_CODE_AND_WHAT ( STATEMENT , EXCEPTION_TYPE , EXPECTED_CODE , EXPECTED_WHAT ) \ <nl> - ASSERT_THROWS_PRED ( STATEMENT , EXCEPTION_TYPE , ( [ ] ( const EXCEPTION_TYPE & ex ) { \ <nl> + ASSERT_THROWS_PRED ( STATEMENT , EXCEPTION_TYPE , ( [ & ] ( const EXCEPTION_TYPE & ex ) { \ <nl> return ( EXPECTED_CODE ) = = ex . getCode ( ) & & \ <nl> : : mongo : : StringData ( ex . what ( ) ) = = \ <nl> : : mongo : : StringData ( EXPECTED_WHAT ) ; \ <nl>
|
SERVER - 24879 Add $ mergeObjects aggregation expression
|
mongodb/mongo
|
896687b8ae6b7f848da88c7186a44bf3163c2254
|
2017-03-31T17:24:40Z
|
mmm a / torch / csrc / generic / Tensor . cpp <nl> ppp b / torch / csrc / generic / Tensor . cpp <nl> static PyObject * THPTensor_ ( pynew ) ( PyTypeObject * type , PyObject * args , PyObject <nl> END_HANDLE_TH_ERRORS <nl> } <nl> <nl> + # define INDEX_LONG ( DIM , IDX_VARIABLE , TENSOR_VARIABLE , CASE_1D , CASE_MD ) \ <nl> + long idx = PyLong_AsLong ( IDX_VARIABLE ) ; \ <nl> + long dimsize = THTensor_ ( size ) ( TENSOR_VARIABLE , DIM ) ; \ <nl> + idx = ( idx < 0 ) ? dimsize + idx : idx ; \ <nl> + \ <nl> + THArgCheck ( dimsize > 0 , 1 , " empty tensor " ) ; \ <nl> + THArgCheck ( idx > = 0 & & idx < dimsize , 2 , " out of range " ) ; \ <nl> + \ <nl> + if ( THTensor_ ( nDimension ) ( TENSOR_VARIABLE ) = = 1 ) { \ <nl> + CASE_1D ; \ <nl> + } else { \ <nl> + CASE_MD ; \ <nl> + } <nl> + # define GET_PTR_1D ( t , idx ) \ <nl> + t - > storage - > data + t - > storageOffset + t - > stride [ 0 ] * idx ; <nl> + static bool THPTensor_ ( _index ) ( THPTensor * self , PyObject * index , <nl> + THTensor * & tresult , real * & rresult ) <nl> + { <nl> + tresult = NULL ; <nl> + rresult = NULL ; <nl> + try { <nl> + / / Indexing with an integer <nl> + if ( PyLong_Check ( index ) ) { <nl> + THTensor * self_t = self - > cdata ; <nl> + INDEX_LONG ( 0 , index , self_t , <nl> + / / 1D tensor <nl> + rresult = GET_PTR_1D ( self_t , idx ) , <nl> + / / > 1D tensor <nl> + tresult = THTensor_ ( newWithTensor ) ( self_t ) ; <nl> + THTensor_ ( select ) ( tresult , NULL , 0 , idx ) <nl> + ) <nl> + / / Indexing with a single element tuple <nl> + } else if ( PyTuple_Check ( index ) & & <nl> + PyTuple_Size ( index ) = = 1 & & <nl> + PyLong_Check ( PyTuple_GET_ITEM ( index , 0 ) ) ) { <nl> + PyObject * index_obj = PyTuple_GET_ITEM ( index , 0 ) ; <nl> + tresult = THTensor_ ( newWithTensor ) ( self - > cdata ) ; <nl> + INDEX_LONG ( 0 , index_obj , tresult , <nl> + THTensor_ ( narrow ) ( tresult , NULL , 0 , idx , 1 ) , <nl> + THTensor_ ( narrow ) ( tresult , NULL , 0 , idx , 1 ) <nl> + ) <nl> + / / Indexing with a slice <nl> + } else if ( PySlice_Check ( index ) ) { <nl> + tresult = THTensor_ ( newWithTensor ) ( self - > cdata ) ; <nl> + Py_ssize_t start , end , length ; <nl> + if ( ! THPUtils_ ( parseSlice ) ( index , THTensor_ ( size ) ( tresult , 0 ) , & start , & end , & length ) ) <nl> + return false ; <nl> + THTensor_ ( narrow ) ( tresult , NULL , 0 , start , length ) ; <nl> + / / Indexing multiple dimensions <nl> + } else if ( PyTuple_Check ( index ) ) { <nl> + THArgCheck ( PyTuple_Size ( index ) < = THTensor_ ( nDimension ) ( self - > cdata ) , 2 , <nl> + " Indexing too many dimensions " ) ; <nl> + tresult = THTensor_ ( newWithTensor ) ( self - > cdata ) ; <nl> + int t_dim = 0 ; <nl> + <nl> + for ( int dim = 0 ; dim < PyTuple_Size ( index ) ; dim + + ) { <nl> + PyObject * dimidx = PyTuple_GET_ITEM ( index , dim ) ; <nl> + if ( PyLong_Check ( dimidx ) ) { <nl> + INDEX_LONG ( t_dim , dimidx , tresult , <nl> + / / 1D tensor <nl> + rresult = GET_PTR_1D ( tresult , idx ) ; <nl> + THTensor_ ( free ) ( tresult ) ; <nl> + tresult = NULL ; <nl> + return true , <nl> + / / > 1D tensor <nl> + THTensor_ ( select ) ( tresult , NULL , t_dim , idx ) <nl> + ) <nl> + } else if ( PyTuple_Check ( dimidx ) ) { <nl> + if ( PyTuple_Size ( dimidx ) ! = 1 | | ! PyLong_Check ( PyTuple_GET_ITEM ( dimidx , 0 ) ) ) { <nl> + PyErr_SetString ( PyExc_RuntimeError , " Expected a single integer " ) ; <nl> + return false ; <nl> + } <nl> + PyObject * index_obj = PyTuple_GET_ITEM ( dimidx , 0 ) ; <nl> + INDEX_LONG ( t_dim , index_obj , tresult , <nl> + THTensor_ ( narrow ) ( tresult , NULL , t_dim + + , idx , 1 ) , <nl> + THTensor_ ( narrow ) ( tresult , NULL , t_dim + + , idx , 1 ) <nl> + ) <nl> + } else if ( PySlice_Check ( dimidx ) ) { <nl> + Py_ssize_t start , end , length ; <nl> + if ( ! THPUtils_ ( parseSlice ) ( dimidx , THTensor_ ( size ) ( tresult , t_dim ) , & start , & end , & length ) ) <nl> + return false ; <nl> + THTensor_ ( narrow ) ( tresult , NULL , t_dim + + , start , length ) ; <nl> + } else { <nl> + PyErr_SetString ( PyExc_RuntimeError , " Slicing with an unsupported type " ) ; <nl> + return false ; <nl> + } <nl> + } <nl> + } <nl> + return true ; <nl> + } catch ( . . . ) { <nl> + THTensor_ ( free ) ( tresult ) ; <nl> + throw ; <nl> + } <nl> + } <nl> + # undef INDEX_LONG <nl> + # undef GET_PTR_1D <nl> + <nl> static PyObject * THPTensor_ ( get ) ( THPTensor * self , PyObject * index ) <nl> { <nl> HANDLE_TH_ERRORS <nl> - int ndim = THTensor_ ( nDimension ) ( self - > cdata ) ; <nl> - / * Integer index * / <nl> - if ( PyLong_Check ( index ) ) { <nl> - if ( ndim = = 1 ) { <nl> - size_t nindex = PyLong_AsSize_t ( index ) ; <nl> - return THPUtils_ ( newReal ) ( THTensor_ ( get1d ) ( self - > cdata , nindex ) ) ; <nl> - } <nl> + if ( THPByteTensor_IsSubclass ( index ) ) { <nl> + THTensor * t = THTensor_ ( new ) ( ) ; <nl> + THTensor_ ( maskedSelect ) ( t , self - > cdata , ( ( THPByteTensor * ) index ) - > cdata ) ; <nl> + return THPTensor_ ( newObject ) ( t ) ; <nl> + } else { <nl> + THTensor * tresult ; <nl> + real * rresult ; <nl> + if ( ! THPTensor_ ( _index ) ( self , index , tresult , rresult ) ) <nl> + return NULL ; <nl> + if ( tresult ) <nl> + return THPTensor_ ( newObject ) ( tresult ) ; <nl> + if ( rresult ) <nl> + return THPUtils_ ( newReal ) ( * rresult ) ; <nl> + PyErr_SetString ( PyExc_RuntimeError , " Unknown exception " ) ; <nl> + return NULL ; <nl> } <nl> - PyErr_SetString ( PyExc_RuntimeError , " Only indexing 1D tensors with integers supported " ) ; <nl> - return NULL ; <nl> END_HANDLE_TH_ERRORS <nl> } <nl> <nl> + int THPTensor_ ( set ) ( THPTensor * self , PyObject * index , PyObject * value ) <nl> + { <nl> + HANDLE_TH_ERRORS <nl> + if ( THPByteTensor_IsSubclass ( index ) ) { <nl> + THPByteTensor * byte_index = ( THPByteTensor * ) index ; <nl> + if ( THPUtils_ ( checkReal ) ( value ) ) { <nl> + real v ; <nl> + if ( ! THPUtils_ ( parseReal ) ( value , & v ) ) <nl> + return - 1 ; <nl> + THTensor_ ( maskedFill ) ( self - > cdata , byte_index - > cdata , v ) ; <nl> + } else if ( THPTensor_ ( IsSubclass ) ( index ) ) { <nl> + THTensor_ ( maskedCopy ) ( self - > cdata , byte_index - > cdata , ( ( THPTensor * ) value ) - > cdata ) ; <nl> + } <nl> + THError ( " number or Tensor expected " ) ; <nl> + } else { <nl> + THTensor * tresult ; <nl> + real * rresult ; <nl> + real v ; <nl> + if ( ! THPTensor_ ( _index ) ( self , index , tresult , rresult ) ) <nl> + return - 1 ; <nl> + <nl> + if ( rresult ) { <nl> + if ( ! THPUtils_ ( parseReal ) ( value , & v ) ) <nl> + return - 1 ; <nl> + * rresult = v ; <nl> + } else { <nl> + try { <nl> + if ( THPUtils_ ( checkReal ) ( value ) ) { <nl> + if ( ! THPUtils_ ( parseReal ) ( value , & v ) ) <nl> + return - 1 ; <nl> + THTensor_ ( fill ) ( tresult , v ) ; <nl> + } else { <nl> + if ( THPByteTensor_IsSubclass ( value ) ) <nl> + THTensor_ ( copyByte ) ( self - > cdata , ( ( THPByteTensor * ) value ) - > cdata ) ; <nl> + else if ( THPCharTensor_IsSubclass ( value ) ) <nl> + THTensor_ ( copyChar ) ( self - > cdata , ( ( THPCharTensor * ) value ) - > cdata ) ; <nl> + else if ( THPShortTensor_IsSubclass ( value ) ) <nl> + THTensor_ ( copyShort ) ( self - > cdata , ( ( THPShortTensor * ) value ) - > cdata ) ; <nl> + else if ( THPIntTensor_IsSubclass ( value ) ) <nl> + THTensor_ ( copyInt ) ( self - > cdata , ( ( THPIntTensor * ) value ) - > cdata ) ; <nl> + else if ( THPLongTensor_IsSubclass ( value ) ) <nl> + THTensor_ ( copyLong ) ( self - > cdata , ( ( THPLongTensor * ) value ) - > cdata ) ; <nl> + else if ( THPFloatTensor_IsSubclass ( value ) ) <nl> + THTensor_ ( copyFloat ) ( self - > cdata , ( ( THPFloatTensor * ) value ) - > cdata ) ; <nl> + else if ( THPDoubleTensor_IsSubclass ( value ) ) <nl> + THTensor_ ( copyDouble ) ( self - > cdata , ( ( THPDoubleTensor * ) value ) - > cdata ) ; <nl> + else <nl> + PyErr_SetString ( PyExc_RuntimeError , " Expected a number or tensor " ) ; <nl> + } <nl> + } catch ( . . . ) { <nl> + THTensor_ ( free ) ( tresult ) ; <nl> + throw ; <nl> + } <nl> + THTensor_ ( free ) ( tresult ) ; <nl> + } <nl> + } <nl> + return 0 ; <nl> + END_HANDLE_TH_ERRORS_RET ( - 1 ) <nl> + } <nl> <nl> static PyMappingMethods THPTensor_ ( mappingmethods ) = { <nl> NULL , <nl> ( binaryfunc ) THPTensor_ ( get ) , <nl> - NULL <nl> + ( objobjargproc ) THPTensor_ ( set ) <nl> } ; <nl> <nl> PyTypeObject THPTensorType = { <nl> mmm a / torch / csrc / generic / utils . cpp <nl> ppp b / torch / csrc / generic / utils . cpp <nl> bool THPUtils_ ( parseReal ) ( PyObject * value , real * result ) <nl> return true ; <nl> } <nl> <nl> + bool THPUtils_ ( checkReal ) ( PyObject * value ) <nl> + { <nl> + return PyFloat_Check ( value ) | | PyLong_Check ( value ) ; <nl> + } <nl> + <nl> PyObject * THPUtils_ ( newReal ) ( real value ) <nl> { <nl> # if defined ( TH_REAL_IS_DOUBLE ) | | defined ( TH_REAL_IS_FLOAT ) <nl> mmm a / torch / csrc / generic / utils . h <nl> ppp b / torch / csrc / generic / utils . h <nl> <nl> bool THPUtils_ ( parseSlice ) ( PyObject * slice , Py_ssize_t len , Py_ssize_t * ostart , Py_ssize_t * ostop , Py_ssize_t * oslicelength ) ; <nl> bool THPUtils_ ( parseReal ) ( PyObject * value , real * result ) ; <nl> PyObject * THPUtils_ ( newReal ) ( real value ) ; <nl> + bool THPUtils_ ( checkReal ) ( PyObject * value ) ; <nl> <nl> # endif <nl> mmm a / torch / printing . py <nl> ppp b / torch / printing . py <nl> def _printVector ( tensor ) : <nl> strt = ' ' <nl> if scale ! = 1 : <nl> strt + = SCALE_FORMAT . format ( scale ) <nl> - return ' \ n ' . join ( fmt . format ( val / scale ) for val in tensor . storage ( ) ) + ' \ n ' <nl> + return ' \ n ' . join ( fmt . format ( val / scale ) for val in tensor ) + ' \ n ' <nl> <nl> def printTensor ( self ) : <nl> if self . nDimension ( ) = = 0 : <nl>
|
Add Tensor indexing functions
|
pytorch/pytorch
|
7c11cb9b687393d92a4b4d9af26bdf26ade88dae
|
2016-06-07T21:40:37Z
|
mmm a / include / swift / AST / FineGrainedDependencies . h <nl> ppp b / include / swift / AST / FineGrainedDependencies . h <nl> class BiIndexedTwoStageMap { <nl> / / / Write out the . swiftdeps file for a frontend compilation of a primary file . <nl> bool emitReferenceDependencies ( DiagnosticEngine & diags , SourceFile * SF , <nl> const DependencyTracker & depTracker , <nl> - StringRef outputPath ) ; <nl> + StringRef outputPath , bool alsoEmitDotFile ) ; <nl> / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> / / MARK : Enums <nl> / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> class DependencyKey { <nl> name ( ) { } <nl> <nl> / / / For constructing a key in the frontend . <nl> - DependencyKey ( NodeKind kind , DeclAspect aspect , std : : string context , <nl> - std : : string name ) <nl> + DependencyKey ( NodeKind kind , DeclAspect aspect , const std : : string & context , <nl> + const std : : string & name ) <nl> : kind ( kind ) , aspect ( aspect ) , context ( context ) , name ( name ) { <nl> assert ( verify ( ) ) ; <nl> } <nl> class DependencyKey { <nl> StringRef getContext ( ) const { return context ; } <nl> StringRef getName ( ) const { return name ; } <nl> <nl> - StringRef getSwiftDepsFromSourceFileProvide ( ) const { <nl> + StringRef getSwiftDepsFromASourceFileProvideNodeKey ( ) const { <nl> assert ( getKind ( ) = = NodeKind : : sourceFileProvide & & <nl> " Receiver must be sourceFileProvide . " ) ; <nl> return getName ( ) ; <nl> class DependencyKey { <nl> static std : : string computeNameForProvidedEntity ( Entity ) ; <nl> <nl> / / / Given some type of depended - upon entity create the key . <nl> - template < NodeKind kind , typename Entity > <nl> - static DependencyKey createDependedUponKey ( const Entity & ) ; <nl> + static DependencyKey createDependedUponKey ( StringRef mangledHolderName , <nl> + StringRef memberBaseName ) ; <nl> + <nl> + template < NodeKind kind > <nl> + static DependencyKey createDependedUponKey ( StringRef ) ; <nl> + <nl> + static DependencyKey <nl> + createTransitiveKeyForWholeSourceFile ( StringRef swiftDeps ) ; <nl> <nl> std : : string humanReadableName ( ) const ; <nl> <nl> + StringRef aspectName ( ) const { return DeclAspectNames [ size_t ( aspect ) ] ; } <nl> + <nl> void dump ( llvm : : raw_ostream & os ) const { os < < asString ( ) < < " \ n " ; } <nl> SWIFT_DEBUG_DUMP { dump ( llvm : : errs ( ) ) ; } <nl> <nl> struct std : : hash < typename swift : : fine_grained_dependencies : : DeclAspect > { <nl> } <nl> } ; <nl> <nl> + namespace swift { <nl> + namespace fine_grained_dependencies { <nl> + using ContextNameFingerprint = <nl> + std : : tuple < std : : string , std : : string , Optional < std : : string > > ; <nl> + } <nl> + } / / namespace swift <nl> + <nl> / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> / / MARK : DepGraphNode <nl> / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> class SourceFileDepGraphNode : public DepGraphNode { <nl> } <nl> <nl> / / / Record the sequence number , \ p n , of another use . <nl> + / / / The relationship between an interface and its implementation is NOT <nl> + / / / included here . See \ c <nl> + / / / SourceFileDepGraph : : findExistingNodePairOrCreateAndAddIfNew . <nl> void addDefIDependUpon ( size_t n ) { <nl> if ( n ! = getSequenceNumber ( ) ) <nl> defsIDependUpon . insert ( n ) ; <nl> class SourceFileDepGraph { <nl> SourceFileDepGraph ( const SourceFileDepGraph & g ) = delete ; <nl> SourceFileDepGraph ( SourceFileDepGraph & & g ) = default ; <nl> <nl> + / / / Simulate loading for unit testing : <nl> + / / / \ param swiftDepsFileName The name of the swiftdeps file of the phony job <nl> + / / / \ param includePrivateDeps Whether the graph includes intra - file arcs <nl> + / / / \ param hadCompilationError Simulate a compilation error <nl> + / / / \ param interfaceHash The interface hash of the simulated graph <nl> + / / / \ param simpleNamesByRDK A map of vectors of names keyed by reference <nl> + / / / dependency key \ param compoundNamesByRDK A map of ( mangledHolder , <nl> + / / / baseName ) pairs keyed by reference dependency key . For single - name <nl> + / / / dependencies , an initial underscore indicates that the name does not <nl> + / / / cascade . For compound names , it is the first name , the holder which <nl> + / / / indicates non - cascading . For member names , an initial underscore indicates <nl> + / / / file - privacy . <nl> + static SourceFileDepGraph <nl> + simulateLoad ( std : : string swiftDepsFileName , const bool includePrivateDeps , <nl> + const bool hadCompilationError , std : : string interfaceHash , <nl> + llvm : : StringMap < std : : vector < std : : string > > simpleNamesByRDK , <nl> + llvm : : StringMap < std : : vector < std : : pair < std : : string , std : : string > > > <nl> + compoundNamesByRDK ) ; <nl> + <nl> / / / Nodes are owned by the graph . <nl> ~ SourceFileDepGraph ( ) { <nl> forEachNode ( [ & ] ( SourceFileDepGraphNode * n ) { delete n ; } ) ; <nl> class SourceFileDepGraph { <nl> InterfaceAndImplementationPair < SourceFileDepGraphNode > <nl> getSourceFileNodePair ( ) const ; <nl> <nl> - StringRef getSwiftDepsFromSourceFileProvide ( ) const ; <nl> + StringRef getSwiftDepsOfJobThatProducedThisGraph ( ) const ; <nl> <nl> std : : string getGraphID ( ) const { <nl> return getSourceFileNodePair ( ) . getInterface ( ) - > getKey ( ) . humanReadableName ( ) ; <nl> class SourceFileDepGraph { <nl> / / / The frontend creates a pair of nodes for every tracked Decl and the source <nl> / / / file itself . <nl> InterfaceAndImplementationPair < SourceFileDepGraphNode > <nl> - findExistingNodePairOrCreateAndAddIfNew ( NodeKind k , StringRef context , <nl> - StringRef name , <nl> - Optional < std : : string > fingerprint ) ; <nl> + findExistingNodePairOrCreateAndAddIfNew ( <nl> + NodeKind k , const ContextNameFingerprint & contextNameFingerprint ) ; <nl> <nl> - SourceFileDepGraphNode * findExistingNodeOrCreateIfNew ( <nl> - DependencyKey key , Optional < std : : string > fingerprint , bool isProvides ) ; <nl> + SourceFileDepGraphNode * <nl> + findExistingNodeOrCreateIfNew ( DependencyKey key , <nl> + const Optional < std : : string > & fingerprint , <nl> + bool isProvides ) ; <nl> <nl> / / / \ p Use is the Node that must be rebuilt when \ p def changes . <nl> / / / Record that fact in the graph . <nl> template < typename GraphT > class DotFileEmitter { <nl> } <nl> void emitArcs ( ) { <nl> g . forEachArc ( [ & ] ( const NodeT * def , const NodeT * use ) { <nl> - if ( includeGraphArc ( use , def ) ) <nl> + if ( includeGraphArc ( def , use ) ) <nl> emitGraphArc ( def , use ) ; <nl> } ) ; <nl> } <nl> mmm a / include / swift / Basic / LangOptions . h <nl> ppp b / include / swift / Basic / LangOptions . h <nl> namespace swift { <nl> / / / Whether to verify the parsed syntax tree and emit related diagnostics . <nl> bool VerifySyntaxTree = false ; <nl> <nl> - / / / Scaffolding to permit experimentation with finer - grained dependencies <nl> - / / / and faster rebuilds . <nl> + / / / Emit the newer , finer - grained swiftdeps file . Eventually will support <nl> + / / / faster rebuilds . <nl> bool EnableFineGrainedDependencies = false ; <nl> - <nl> + <nl> + / / / When using fine - grained dependencies , emit dot files for every swiftdeps <nl> + / / / file . <nl> + bool EmitFineGrainedDependencySourcefileDotFiles = false ; <nl> + <nl> / / / To mimic existing system , set to false . <nl> / / / To experiment with including file - private and private dependency info , <nl> / / / set to true . <nl> mmm a / include / swift / Driver / Action . h <nl> ppp b / include / swift / Driver / Action . h <nl> class CompileJobAction : public JobAction { <nl> static bool classof ( const Action * A ) { <nl> return A - > getKind ( ) = = Action : : Kind : : CompileJob ; <nl> } <nl> + <nl> + / / / Return a _single_ TY_Swift InputAction , if one exists ; <nl> + / / / if 0 or > 1 such inputs exist , return nullptr . <nl> + const InputAction * findSingleSwiftInput ( ) const { <nl> + auto Inputs = getInputs ( ) ; <nl> + auto isSwiftInput = [ ] ( const Action * A ) - > const InputAction * { <nl> + if ( auto const * S = dyn_cast < InputAction > ( A ) ) <nl> + return S - > getType ( ) = = file_types : : TY_Swift ? S : nullptr ; <nl> + return nullptr ; <nl> + } ; <nl> + const auto loc1 = std : : find_if ( Inputs . begin ( ) , Inputs . end ( ) , isSwiftInput ) ; <nl> + if ( loc1 = = Inputs . end ( ) ) <nl> + return nullptr ; / / none found <nl> + / / Ensure uniqueness <nl> + const auto loc2 = std : : find_if ( loc1 + 1 , Inputs . end ( ) , isSwiftInput ) ; <nl> + return loc2 = = Inputs . end ( ) ? dyn_cast < InputAction > ( * loc1 ) : nullptr ; <nl> + } <nl> } ; <nl> <nl> class InterpretJobAction : public JobAction { <nl> mmm a / include / swift / Driver / Compilation . h <nl> ppp b / include / swift / Driver / Compilation . h <nl> class Compilation { <nl> / / / How many . swift input files ? <nl> unsigned countSwiftInputs ( ) const ; <nl> <nl> + / / / Unfortunately the success or failure of a Swift compilation is currently <nl> + / / / sensitive to the order in which files are processed , at least in terms of <nl> + / / / the order of processing extensions ( and likely other ways we haven ' t <nl> + / / / discovered yet ) . So long as this is true , we need to make sure any batch <nl> + / / / job we build names its inputs in an order that ' s a subsequence of the <nl> + / / / sequence of inputs the driver was initially invoked with . <nl> + / / / <nl> + / / / Also use to write out information in a consistent order . <nl> + void sortJobsToMatchCompilationInputs ( <nl> + ArrayRef < const Job * > unsortedJobs , <nl> + SmallVectorImpl < const Job * > & sortedJobs ) const ; <nl> + <nl> private : <nl> / / / Perform all jobs . <nl> / / / <nl> mmm a / include / swift / Driver / FineGrainedDependencyDriverGraph . h <nl> ppp b / include / swift / Driver / FineGrainedDependencyDriverGraph . h <nl> namespace fine_grained_dependencies { <nl> / / / Keep separate type from Node for type - checking . <nl> class ModuleDepGraphNode : public DepGraphNode { <nl> <nl> - / / / The swiftDeps file that holds this entity . <nl> + / / / The swiftDeps file that holds this entity iff this is a provides node . <nl> / / / If more than one source file has the same DependencyKey , then there <nl> - / / / will be one node for each in the driver . <nl> + / / / will be one node for each in the driver , distinguished by this field . <nl> Optional < std : : string > swiftDeps ; <nl> <nl> public : <nl> class ModuleDepGraphNode : public DepGraphNode { <nl> <nl> const Optional < std : : string > & getSwiftDeps ( ) const { return swiftDeps ; } <nl> <nl> - bool assertImplementationMustBeInAFile ( ) const { <nl> - assert ( ( getSwiftDeps ( ) . hasValue ( ) | | ! getKey ( ) . isImplementation ( ) ) & & <nl> - " Implementations must be in some file . " ) ; <nl> - return true ; <nl> + std : : string getSwiftDepsOrEmpty ( ) const { <nl> + return getSwiftDeps ( ) . getValueOr ( std : : string ( ) ) ; <nl> } <nl> <nl> - std : : string humanReadableName ( ) const { <nl> - StringRef where = <nl> - ! getSwiftDeps ( ) . hasValue ( ) <nl> - ? " " <nl> - : llvm : : sys : : path : : filename ( getSwiftDeps ( ) . getValue ( ) ) ; <nl> - return DepGraphNode : : humanReadableName ( where ) ; <nl> + std : : string getSwiftDepsForMapKey ( ) const { <nl> + / / Use the empty string for nodes whose source file is unknown , <nl> + / / i . e . depends . ( Known depends are represented by arcs , not nodes . ) <nl> + return getSwiftDepsOrEmpty ( ) ; <nl> } <nl> <nl> - SWIFT_DEBUG_DUMP ; <nl> - <nl> - bool assertProvidedEntityMustBeInAFile ( ) const { <nl> - assert ( ( getSwiftDeps ( ) . hasValue ( ) | | ! getKey ( ) . isImplementation ( ) ) & & <nl> - " Implementations must be in some file . " ) ; <nl> - return true ; <nl> + const std : : string & getSwiftDepsOfProvides ( ) const { <nl> + return getSwiftDeps ( ) . getValue ( ) ; <nl> } <nl> <nl> / / / Nodes can move from file to file when the driver reads the result of a <nl> class ModuleDepGraphNode : public DepGraphNode { <nl> void setSwiftDeps ( Optional < std : : string > s ) { swiftDeps = s ; } <nl> <nl> bool getIsProvides ( ) const { return getSwiftDeps ( ) . hasValue ( ) ; } <nl> - } ; <nl> <nl> - / / / A placeholder allowing the experimental system to fit into the driver <nl> - / / / without changing as much code . <nl> - class CoarseGrainedDependencyGraphImpl { <nl> - public : <nl> - / / / Use the status quo LoadResult for now . <nl> - using LoadResult = <nl> - typename swift : : CoarseGrainedDependencyGraphImpl : : LoadResult ; <nl> + / / / Return true if this node describes a definition for which the job is known <nl> + bool isDefinedInAKnownFile ( ) const { return getIsProvides ( ) ; } <nl> + <nl> + bool doesNodeProvideAnInterface ( ) const { <nl> + return getKey ( ) . isInterface ( ) & & getIsProvides ( ) ; <nl> + } <nl> + <nl> + bool assertImplementationMustBeInAFile ( ) const { <nl> + assert ( ( isDefinedInAKnownFile ( ) | | ! getKey ( ) . isImplementation ( ) ) & & <nl> + " Implementations must be in some file . " ) ; <nl> + return true ; <nl> + } <nl> + <nl> + std : : string humanReadableName ( ) const { <nl> + StringRef where = ! getIsProvides ( ) <nl> + ? " " <nl> + : llvm : : sys : : path : : filename ( getSwiftDepsOfProvides ( ) ) ; <nl> + return DepGraphNode : : humanReadableName ( where ) ; <nl> + } <nl> + <nl> + SWIFT_DEBUG_DUMP ; <nl> } ; <nl> <nl> / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> class ModuleDepGraph { <nl> std : : unordered_set < std : : string > externalDependencies ; <nl> <nl> / / / The new version of " Marked . " <nl> - / / / Record cascading jobs by swiftDepsFilename because that ' s what <nl> - / / / nodes store directly . <nl> - / / / <nl> - / / / The status quo system uses " cascade " for the following : <nl> - / / / Def1 - > def2 - > def3 , where arrows are uses , so 3 depends on 2 which <nl> - / / / depends on 1 . The first use is said to " cascade " if when def1 changes , <nl> - / / / def3 is dirtied . <nl> - / / / TODO : Move cascadingJobs out of the graph , ultimately . <nl> - / / / If marked , any Job that depends on me must be rebuilt after compiling me <nl> - / / / if I have changed . <nl> - <nl> - std : : unordered_set < std : : string > cascadingJobs ; <nl> + / / / Aka " isMarked " . Holds the swiftDeps paths for jobs the driver has or will <nl> + / / / schedule . <nl> + / / / TODO : Move scheduledJobs out of the graph , ultimately . <nl> + std : : unordered_set < std : : string > swiftDepsOfJobsThatNeedRunning ; <nl> <nl> / / / Keyed by swiftdeps filename , so we can get back to Jobs . <nl> std : : unordered_map < std : : string , const driver : : Job * > jobsBySwiftDeps ; <nl> class ModuleDepGraph { <nl> const bool verifyFineGrainedDependencyGraphAfterEveryImport ; <nl> const bool emitFineGrainedDependencyDotFileAfterEveryImport ; <nl> <nl> - / / / If tracing dependencies , holds the current node traversal path <nl> + / / / If tracing dependencies , holds a vector used to hold the current path <nl> + / / / def - use / def - use / def - . . . <nl> Optional < std : : vector < const ModuleDepGraphNode * > > currentPathIfTracing ; <nl> <nl> - / / / If tracing dependencies , record the node sequence <nl> + / / / If tracing dependencies , holds the sequence of defs used to get to the job <nl> + / / / that is the key <nl> std : : unordered_multimap < const driver : : Job * , <nl> std : : vector < const ModuleDepGraphNode * > > <nl> dependencyPathsToJobs ; <nl> class ModuleDepGraph { <nl> / / / Encapsulate the invariant between where the node resides in <nl> / / / nodesBySwiftDepsFile and the swiftDeps node instance variable here . <nl> void addToMap ( ModuleDepGraphNode * n ) { <nl> - nodeMap . insert ( n - > getSwiftDeps ( ) . getValueOr ( std : : string ( ) ) , n - > getKey ( ) , n ) ; <nl> + nodeMap . insert ( n - > getSwiftDepsForMapKey ( ) , n - > getKey ( ) , n ) ; <nl> } <nl> <nl> / / / When integrating a SourceFileDepGraph , there might be a node representing <nl> class ModuleDepGraph { <nl> / / / Remove node from nodeMap , check invariants . <nl> ModuleDepGraphNode * eraseNodeFromMap ( ModuleDepGraphNode * nodeToErase ) { <nl> ModuleDepGraphNode * nodeActuallyErased = nodeMap . findAndErase ( <nl> - nodeToErase - > getSwiftDeps ( ) . getValueOr ( std : : string ( ) ) , <nl> - nodeToErase - > getKey ( ) ) ; <nl> + nodeToErase - > getSwiftDepsForMapKey ( ) , nodeToErase - > getKey ( ) ) ; <nl> ( void ) nodeActuallyErased ; <nl> assert ( <nl> nodeToErase = = nodeActuallyErased | | <nl> class ModuleDepGraph { <nl> return nodeToErase ; <nl> } <nl> <nl> + void eraseNodeFromUsesByDef ( ModuleDepGraphNode * nodeToErase ) { <nl> + for ( auto & defAndUses : usesByDef ) <nl> + defAndUses . second . erase ( nodeToErase ) ; <nl> + } <nl> + <nl> + void eraseNodeFromCurrentPathIfTracing ( ModuleDepGraphNode * nodeToErase ) { <nl> + if ( currentPathIfTracing ) <nl> + eraseNodeFromVector ( currentPathIfTracing . getValue ( ) , nodeToErase ) ; <nl> + } <nl> + <nl> + void eraseNodeFromDependencyPathToJobs ( ModuleDepGraphNode * nodeToErase ) { <nl> + for ( auto & jobAndPath : dependencyPathsToJobs ) <nl> + eraseNodeFromVector ( jobAndPath . second , nodeToErase ) ; <nl> + } <nl> + <nl> + static void eraseNodeFromVector ( std : : vector < const ModuleDepGraphNode * > & v , <nl> + const ModuleDepGraphNode * n ) { <nl> + const auto where = std : : find ( v . begin ( ) , v . end ( ) , n ) ; <nl> + if ( where ! = v . end ( ) ) <nl> + v . erase ( where ) ; <nl> + } <nl> + <nl> static StringRef getSwiftDeps ( const driver : : Job * cmd ) { <nl> return cmd - > getOutput ( ) . getAdditionalOutputForType ( <nl> file_types : : TY_SwiftDeps ) ; <nl> class ModuleDepGraph { <nl> assert ( verify ( ) & & " ModuleDepGraph should be fine when created " ) ; <nl> } <nl> <nl> + ModuleDepGraph ( ) : ModuleDepGraph ( false , false , false , nullptr ) { } <nl> + <nl> / / / Unlike the standard \ c CoarseGrainedDependencyGraph , returns \ c <nl> / / / CoarseGrainedDependencyGraphImpl : : LoadResult : : AffectsDownstream when <nl> / / / loading a new file , i . e . when determining the initial set . Caller <nl> class ModuleDepGraph { <nl> CoarseGrainedDependencyGraphImpl : : LoadResult <nl> loadFromPath ( const driver : : Job * , StringRef , DiagnosticEngine & ) ; <nl> <nl> + CoarseGrainedDependencyGraphImpl : : LoadResult <nl> + loadFromString ( const driver : : Job * cmd , StringRef data ) ; <nl> + <nl> + CoarseGrainedDependencyGraphImpl : : LoadResult <nl> + loadFromSourceFileDepGraph ( const driver : : Job * cmd , <nl> + const SourceFileDepGraph & ) ; <nl> + <nl> / / / For the dot file . <nl> std : : string getGraphID ( ) const { return " driver " ; } <nl> <nl> class ModuleDepGraph { <nl> / / / 1 . Return value ( via visited ) is the set of jobs needing recompilation <nl> / / / after this one , and <nl> / / / 2 . Jobs not previously known to need dependencies reexamined after they <nl> - / / / are recompiled . Such jobs are added to the \ ref cascadingJobs set , and <nl> + / / / are recompiled . Such jobs are added to the \ ref scheduledJobs set , and <nl> / / / accessed via \ ref isMarked . <nl> + / / / <nl> + / / / Only return jobs marked that were previously unmarked . Not required for <nl> + / / / the driver because it won ' t run a job twice , but required for the unit <nl> + / / / test . <nl> std : : vector < const driver : : Job * > markTransitive ( <nl> const driver : : Job * jobToBeRecompiled , const void * ignored = nullptr ) ; <nl> <nl> class ModuleDepGraph { <nl> <nl> std : : vector < StringRef > getExternalDependencies ( ) const ; <nl> <nl> + / / / Find jobs that were previously not known to need compilation but that <nl> + / / / depend on \ c externalDependency . <nl> std : : vector < const driver : : Job * > markExternal ( StringRef externalDependency ) ; <nl> <nl> void forEachUnmarkedJobDirectlyDependentOnExternalSwiftdeps ( <nl> class ModuleDepGraph { <nl> / / / Given a definition node , and a list of already found dependents , <nl> / / / recursively add transitive closure of dependents of the definition <nl> / / / into the already found dependents . <nl> - / / / Also record any dependents that " cascade " , i . e . whose dependencies must be <nl> - / / / recomputed after recompilation so that its dependents can be recompiled . <nl> - void findDependentNodesAndRecordCascadingOnes ( <nl> + void findDependentNodes ( <nl> std : : unordered_set < const ModuleDepGraphNode * > & foundDependents , <nl> const ModuleDepGraphNode * definition ) ; <nl> <nl> - std : : vector < const driver : : Job * > computeUniqueJobsFromNodes ( <nl> - const std : : unordered_set < const ModuleDepGraphNode * > & nodes ) ; <nl> + / / / Givien a set of nodes , return the set of swiftDeps for the jobs those <nl> + / / / nodes are in . <nl> + llvm : : StringSet < > computeSwiftDepsFromInterfaceNodes ( <nl> + ArrayRef < const ModuleDepGraphNode * > nodes ) ; <nl> <nl> / / / Record a visit to this node for later dependency printing <nl> size_t traceArrival ( const ModuleDepGraphNode * visitedNode ) ; <nl> class ModuleDepGraph { <nl> const std : : vector < const ModuleDepGraphNode * > & pathToJob , <nl> const driver : : Job * dependentJob ) ; <nl> <nl> - / / / Return true if job did not cascade before <nl> - bool rememberThatJobCascades ( StringRef swiftDeps ) { <nl> - return cascadingJobs . insert ( swiftDeps ) . second ; <nl> + / / / Return true if job was not scheduled before <nl> + bool recordJobNeedsRunning ( StringRef swiftDeps ) { <nl> + return swiftDepsOfJobsThatNeedRunning . insert ( swiftDeps ) . second ; <nl> } <nl> <nl> - / / / For debugging , write out the graph to a dot file . <nl> + / / / For debugging and visualization , write out the graph to a dot file . <nl> / / / \ p diags may be null if no diagnostics are needed . <nl> void emitDotFileForJob ( DiagnosticEngine & , const driver : : Job * ) ; <nl> void emitDotFile ( DiagnosticEngine & , StringRef baseName ) ; <nl> class ModuleDepGraph { <nl> void printPath ( raw_ostream & out , const driver : : Job * node ) const ; <nl> <nl> private : <nl> + / / / Get a printable filename , given a node ' s swiftDeps . <nl> + StringRef getProvidingFilename ( Optional < std : : string > swiftDeps ) const ; <nl> + <nl> + / / / Print one node on the dependency path . <nl> + static void printOneNodeOfPath ( raw_ostream & out , const DependencyKey & key , <nl> + const StringRef filename ) ; <nl> + <nl> bool isCurrentPathForTracingEmpty ( ) const { <nl> return ! currentPathIfTracing . hasValue ( ) | | currentPathIfTracing - > empty ( ) ; <nl> } <nl> mmm a / include / swift / Driver / Job . h <nl> ppp b / include / swift / Driver / Job . h <nl> class CommandOutput { <nl> public : <nl> CommandOutput ( file_types : : ID PrimaryOutputType , OutputFileMap & Derived ) ; <nl> <nl> + / / / For testing dependency graphs that use Jobs <nl> + CommandOutput ( StringRef dummyBaseName , OutputFileMap & ) ; <nl> + <nl> / / / Return the primary output type for this CommandOutput . <nl> file_types : : ID getPrimaryOutputType ( ) const ; <nl> <nl> class Job { <nl> ExtraEnvironment ( std : : move ( ExtraEnvironment ) ) , <nl> FilelistFileInfos ( std : : move ( Infos ) ) , ResponseFile ( ResponseFile ) { } <nl> <nl> + / / / For testing dependency graphs that use Jobs <nl> + Job ( OutputFileMap & OFM , StringRef dummyBaseName ) <nl> + : Job ( CompileJobAction ( file_types : : TY_Object ) , <nl> + SmallVector < const Job * , 4 > ( ) , <nl> + std : : make_unique < CommandOutput > ( dummyBaseName , OFM ) , nullptr , { } ) { } <nl> + <nl> virtual ~ Job ( ) ; <nl> <nl> const JobAction & getSource ( ) const { <nl> mmm a / include / swift / Option / Options . td <nl> ppp b / include / swift / Option / Options . td <nl> def driver_always_rebuild_dependents : <nl> <nl> def enable_fine_grained_dependencies : <nl> Flag < [ " - " ] , " enable - fine - grained - dependencies " > , Flags < [ FrontendOption , HelpHidden ] > , <nl> - HelpText < " Experimental work - in - progress to be more selective about incremental recompilation " > ; <nl> + HelpText < " Be more selective about incremental recompilation " > ; <nl> + <nl> + def disable_fine_grained_dependencies : <nl> + Flag < [ " - " ] , " disable - fine - grained - dependencies " > , Flags < [ FrontendOption , HelpHidden ] > , <nl> + HelpText < " Don ' t be more selective about incremental recompilation " > ; <nl> <nl> <nl> def enable_only_one_dependency_file : <nl> Flag < [ " - " ] , " fine - grained - dependency - include - intrafile " > , <nl> InternalDebugOpt , <nl> HelpText < " Include within - file dependencies . " > ; <nl> <nl> + def emit_fine_grained_dependency_sourcefile_dot_files : <nl> + Flag < [ " - " ] , " emit - fine - grained - dependency - sourcefile - dot - files " > , <nl> + InternalDebugOpt , <nl> + HelpText < " Emit dot files for every source file . " > ; <nl> + <nl> def driver_mode : Joined < [ " - - " ] , " driver - mode = " > , Flags < [ HelpHidden ] > , <nl> HelpText < " Set the driver mode to either ' swift ' or ' swiftc ' " > ; <nl> <nl> mmm a / lib / AST / FineGrainedDependencies . cpp <nl> ppp b / lib / AST / FineGrainedDependencies . cpp <nl> SourceFileDepGraph : : getSourceFileNodePair ( ) const { <nl> getNode ( 1 ) ) ; <nl> } <nl> <nl> - StringRef SourceFileDepGraph : : getSwiftDepsFromSourceFileProvide ( ) const { <nl> + StringRef SourceFileDepGraph : : getSwiftDepsOfJobThatProducedThisGraph ( ) const { <nl> return getSourceFileNodePair ( ) <nl> . getInterface ( ) <nl> - > getKey ( ) <nl> - . getSwiftDepsFromSourceFileProvide ( ) ; <nl> + . getSwiftDepsFromASourceFileProvideNodeKey ( ) ; <nl> } <nl> <nl> void SourceFileDepGraph : : forEachArc ( <nl> void SourceFileDepGraph : : forEachArc ( <nl> <nl> InterfaceAndImplementationPair < SourceFileDepGraphNode > <nl> SourceFileDepGraph : : findExistingNodePairOrCreateAndAddIfNew ( <nl> - NodeKind k , StringRef context , StringRef name , <nl> - Optional < std : : string > fingerprint ) { <nl> + NodeKind k , const ContextNameFingerprint & contextNameFingerprint ) { <nl> + const std : : string & context = std : : get < 0 > ( contextNameFingerprint ) ; <nl> + const std : : string & name = std : : get < 1 > ( contextNameFingerprint ) ; <nl> + const Optional < std : : string > & fingerprint = <nl> + std : : get < 2 > ( contextNameFingerprint ) ; <nl> InterfaceAndImplementationPair < SourceFileDepGraphNode > nodePair { <nl> findExistingNodeOrCreateIfNew ( <nl> DependencyKey ( k , DeclAspect : : interface , context , name ) , fingerprint , <nl> SourceFileDepGraph : : findExistingNodePairOrCreateAndAddIfNew ( <nl> findExistingNodeOrCreateIfNew ( <nl> DependencyKey ( k , DeclAspect : : implementation , context , name ) , <nl> fingerprint , true / * = isProvides * / ) } ; <nl> - / / if interface changes , have to rebuild implementation <nl> - addArc ( nodePair . getInterface ( ) , nodePair . getImplementation ( ) ) ; <nl> + / / if interface changes , have to rebuild implementation . <nl> + / / This dependency used to be represented by <nl> + / / addArc ( nodePair . getInterface ( ) , nodePair . getImplementation ( ) ) ; <nl> + / / However , recall that the dependency scheme as of 1 / 2020 chunks <nl> + / / declarations together by base name . <nl> + / / So if the arc were added , a dirtying of a same - based - named interface <nl> + / / in a different file would dirty the implementation in this file , <nl> + / / causing the needless recompilation of this file . <nl> + / / But , if an arc is added for this , then * any * change that causes <nl> + / / a same - named interface to be dirty will dirty this implementation , <nl> + / / even if that interface is in another file . <nl> + / / Therefor no such arc is added here , and any dirtying of either <nl> + / / the interface or implementation of this declaration will cause <nl> + / / the driver to recompile this source file . <nl> return nodePair ; <nl> } <nl> <nl> SourceFileDepGraphNode * SourceFileDepGraph : : findExistingNodeOrCreateIfNew ( <nl> - DependencyKey key , Optional < std : : string > fingerprint , <nl> + DependencyKey key , const Optional < std : : string > & fingerprint , <nl> const bool isProvides ) { <nl> SourceFileDepGraphNode * result = memoizedNodes . findExistingOrCreateIfNew ( <nl> key , [ & ] ( DependencyKey key ) - > SourceFileDepGraphNode * { <nl> SourceFileDepGraphNode * SourceFileDepGraph : : findExistingNodeOrCreateIfNew ( <nl> addNode ( n ) ; <nl> return n ; <nl> } ) ; <nl> + assert ( result - > getKey ( ) = = key & & " Keys must match . " ) ; <nl> + if ( ! isProvides ) <nl> + return result ; <nl> / / If have provides and depends with same key , result is one node that <nl> / / isProvides <nl> - if ( isProvides ) <nl> + if ( ! result - > getIsProvides ( ) & & fingerprint ) { <nl> result - > setIsProvides ( ) ; <nl> - assert ( result - > getKey ( ) = = key & & " Keys must match . " ) ; <nl> + assert ( ! result - > getFingerprint ( ) & & " Depends should not have fingerprints " ) ; <nl> + result - > setFingerprint ( fingerprint ) ; <nl> + return result ; <nl> + } <nl> + / / If there are two Decls with same base name but differ only in fingerprint , <nl> + / / since we won ' t be able to tell which Decl is depended - upon ( is this right ? ) <nl> + / / just use the one node , but erase its print : <nl> + if ( fingerprint ! = result - > getFingerprint ( ) ) <nl> + result - > setFingerprint ( None ) ; <nl> return result ; <nl> } <nl> <nl> std : : string DependencyKey : : demangleTypeAsContext ( StringRef s ) { <nl> return swift : : Demangle : : demangleTypeAsString ( s . str ( ) ) ; <nl> } <nl> <nl> + DependencyKey DependencyKey : : createTransitiveKeyForWholeSourceFile ( <nl> + const StringRef swiftDeps ) { <nl> + assert ( ! swiftDeps . empty ( ) ) ; <nl> + const auto context = DependencyKey : : computeContextForProvidedEntity < <nl> + NodeKind : : sourceFileProvide > ( swiftDeps ) ; <nl> + const auto name = <nl> + DependencyKey : : computeNameForProvidedEntity < NodeKind : : sourceFileProvide > ( <nl> + swiftDeps ) ; <nl> + return DependencyKey ( NodeKind : : sourceFileProvide , DeclAspect : : interface , <nl> + context , name ) ; <nl> + } <nl> + <nl> / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> / / MARK : Debugging <nl> / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> std : : string DependencyKey : : humanReadableName ( ) const { <nl> } <nl> <nl> std : : string DependencyKey : : asString ( ) const { <nl> - return NodeKindNames [ size_t ( kind ) ] + " " + <nl> - " aspect : " + DeclAspectNames [ size_t ( aspect ) ] + " , " + <nl> - humanReadableName ( ) ; <nl> + return NodeKindNames [ size_t ( kind ) ] + " " + " aspect : " + aspectName ( ) . str ( ) + <nl> + " , " + humanReadableName ( ) ; <nl> } <nl> <nl> / / / Needed for TwoStageMap : : verify : <nl> mmm a / lib / AST / FineGrainedDependenciesSourceFileDepGraphConstructor . cpp <nl> ppp b / lib / AST / FineGrainedDependenciesSourceFileDepGraphConstructor . cpp <nl> <nl> # include " swift / AST / Types . h " <nl> # include " swift / Basic / FileSystem . h " <nl> # include " swift / Basic / LLVM . h " <nl> + # include " swift / Basic / ReferenceDependencyKeys . h " <nl> # include " swift / Demangling / Demangle . h " <nl> # include " swift / Frontend / FrontendOptions . h " <nl> # include " llvm / ADT / MapVector . h " <nl> struct SourceFileDeclFinder { <nl> private : <nl> / / / Extensions may contain nominals and operators . <nl> void findNominalsFromExtensions ( ) { <nl> - for ( auto * ED : extensions ) <nl> - findNominalsAndOperatorsIn ( ED - > getExtendedNominal ( ) , ED ) ; <nl> + for ( auto * ED : extensions ) { <nl> + const auto * const NTD = ED - > getExtendedNominal ( ) ; <nl> + if ( NTD ) <nl> + findNominalsAndOperatorsIn ( NTD , ED ) ; <nl> + } <nl> } <nl> / / / Top - level nominals may contain nominals and operators . <nl> void findNominalsInTopNominals ( ) { <nl> struct SourceFileDeclFinder { <nl> / / / Extensions may contain ValueDecls . <nl> void findValuesInExtensions ( ) { <nl> for ( const auto * ED : extensions ) { <nl> - if ( excludeIfPrivate ( ED - > getExtendedNominal ( ) ) ) <nl> + const auto * const NTD = ED - > getExtendedNominal ( ) ; <nl> + if ( ! NTD | | excludeIfPrivate ( NTD ) ) <nl> continue ; <nl> if ( ! includePrivateDecls & & <nl> ( ! allInheritedProtocolsArePrivate ( ED ) | | allMembersArePrivate ( ED ) ) ) <nl> continue ; <nl> for ( const auto * member : ED - > getMembers ( ) ) <nl> if ( const auto * VD = dyn_cast < ValueDecl > ( member ) ) <nl> - if ( VD - > hasName ( ) & & ( includePrivateDecls | | ! declIsPrivate ( VD ) ) ) <nl> - valuesInExtensions . push_back ( <nl> - std : : make_pair ( ED - > getExtendedNominal ( ) , VD ) ) ; <nl> + if ( VD - > hasName ( ) & & ( includePrivateDecls | | ! declIsPrivate ( VD ) ) ) { <nl> + const auto * const NTD = ED - > getExtendedNominal ( ) ; <nl> + if ( NTD ) <nl> + valuesInExtensions . push_back ( std : : make_pair ( NTD , VD ) ) ; <nl> + } <nl> } <nl> } <nl> <nl> std : : string DependencyKey : : computeContextForProvidedEntity < <nl> return mangleTypeAsContext ( holderAndMember . first ) ; <nl> } <nl> <nl> + / / Linux compiler requires the following : <nl> + template <nl> + std : : string <nl> + DependencyKey : : computeContextForProvidedEntity < NodeKind : : sourceFileProvide , <nl> + StringRef > ( StringRef ) ; <nl> + <nl> / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> / / MARK : computeNameForProvidedEntity <nl> / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> std : : string DependencyKey : : computeNameForProvidedEntity < <nl> <nl> template < > <nl> DependencyKey <nl> - DependencyKey : : createDependedUponKey < NodeKind : : topLevel , DeclBaseName > ( <nl> - const DeclBaseName & dbn ) { <nl> - return DependencyKey ( NodeKind : : topLevel , DeclAspect : : interface , " " , <nl> - dbn . userFacingName ( ) ) ; <nl> + DependencyKey : : createDependedUponKey < NodeKind : : topLevel > ( StringRef name ) { <nl> + return DependencyKey ( NodeKind : : topLevel , DeclAspect : : interface , " " , name ) ; <nl> } <nl> <nl> template < > <nl> DependencyKey <nl> - DependencyKey : : createDependedUponKey < NodeKind : : dynamicLookup , DeclBaseName > ( <nl> - const DeclBaseName & dbn ) { <nl> + DependencyKey : : createDependedUponKey < NodeKind : : dynamicLookup > ( StringRef name ) { <nl> return DependencyKey ( NodeKind : : dynamicLookup , DeclAspect : : interface , " " , <nl> - dbn . userFacingName ( ) ) ; <nl> + name ) ; <nl> } <nl> <nl> template < > <nl> - DependencyKey DependencyKey : : createDependedUponKey < <nl> - NodeKind : : nominal , std : : pair < const NominalTypeDecl * , DeclBaseName > > ( <nl> - const std : : pair < const NominalTypeDecl * , DeclBaseName > & p ) { <nl> - return DependencyKey ( NodeKind : : nominal , DeclAspect : : interface , <nl> - mangleTypeAsContext ( p . first ) , " " ) ; <nl> + DependencyKey <nl> + DependencyKey : : createDependedUponKey < NodeKind : : externalDepend > ( StringRef name ) { <nl> + return DependencyKey ( NodeKind : : externalDepend , DeclAspect : : interface , " " , <nl> + name ) ; <nl> } <nl> <nl> template < > <nl> - DependencyKey DependencyKey : : createDependedUponKey < <nl> - NodeKind : : member , std : : pair < const NominalTypeDecl * , DeclBaseName > > ( <nl> - const std : : pair < const NominalTypeDecl * , DeclBaseName > & p ) { <nl> - const bool isMemberBlank = p . second . empty ( ) ; <nl> - const auto kind = <nl> - isMemberBlank ? NodeKind : : potentialMember : NodeKind : : member ; <nl> - return DependencyKey ( kind , DeclAspect : : interface , <nl> - mangleTypeAsContext ( p . first ) , <nl> - isMemberBlank ? " " : p . second . userFacingName ( ) ) ; <nl> + DependencyKey <nl> + DependencyKey : : createDependedUponKey < NodeKind : : nominal > ( StringRef mangledName ) { <nl> + return DependencyKey ( NodeKind : : nominal , DeclAspect : : interface , mangledName , <nl> + " " ) ; <nl> } <nl> <nl> - template < > <nl> - DependencyKey <nl> - DependencyKey : : createDependedUponKey < NodeKind : : externalDepend , std : : string > ( <nl> - const std : : string & file ) { <nl> - return DependencyKey ( NodeKind : : externalDepend , DeclAspect : : interface , " " , <nl> - file ) ; <nl> + DependencyKey DependencyKey : : createDependedUponKey ( StringRef mangledHolderName , <nl> + StringRef memberBaseName ) { <nl> + const bool isMemberBlank = memberBaseName . empty ( ) ; <nl> + const auto kind = <nl> + isMemberBlank ? NodeKind : : potentialMember : NodeKind : : member ; <nl> + return DependencyKey ( kind , DeclAspect : : interface , mangledHolderName , <nl> + isMemberBlank ? " " : memberBaseName ) ; <nl> } <nl> <nl> / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> namespace { <nl> / / / Reads the information provided by the frontend and builds the <nl> / / / SourceFileDepGraph <nl> class SourceFileDepGraphConstructor { <nl> - / / / The SourceFile containing the Decls . <nl> - SourceFile * SF ; <nl> - <nl> - / / / Furnishes depended - upon names resulting from lookups . <nl> - const DependencyTracker & depTracker ; <nl> - <nl> / / / Name of the swiftDeps file , for inclusion in the constructed graph . <nl> StringRef swiftDeps ; / / TODO rm ? <nl> <nl> class SourceFileDepGraphConstructor { <nl> / / / If there was an error , cannot get accurate info . <nl> const bool hadCompilationError ; <nl> <nl> + / / / Functions as the fingerprint of the entire file <nl> + const std : : string interfaceHash ; <nl> + <nl> + / / / Top - level base names of decls that are depended - upon and a flag indicating <nl> + / / / if the dependency " cascades " <nl> + const std : : vector < std : : pair < std : : string , bool > > topLevelDepends ; <nl> + <nl> + / / / A mangled nominal name and the member base name that are depended - upon , <nl> + / / / a flag indicating if the member is private to its enclosing file , and <nl> + / / / a flag indicating if the dependency cascades . <nl> + const std : : vector < std : : pair < std : : tuple < std : : string , std : : string , bool > , bool > > <nl> + memberDepends ; <nl> + <nl> + / / / The base name of a class member depended - upon for dynamic lookup , and a <nl> + / / / cascades flag . <nl> + const std : : vector < std : : pair < std : : string , bool > > dynamicLookupDepends ; <nl> + <nl> + / / / The paths of swiftdeps files of other modules that are depended - upon . <nl> + const std : : vector < std : : string > externalDependencies ; <nl> + <nl> + / / / Provided names <nl> + std : : vector < ContextNameFingerprint > precedenceGroups ; <nl> + std : : vector < ContextNameFingerprint > memberOperatorDecls ; <nl> + std : : vector < ContextNameFingerprint > operators ; <nl> + std : : vector < ContextNameFingerprint > topNominals ; <nl> + std : : vector < ContextNameFingerprint > topValues ; <nl> + std : : vector < ContextNameFingerprint > allNominals ; <nl> + std : : vector < ContextNameFingerprint > potentialMemberHolders ; <nl> + std : : vector < ContextNameFingerprint > valuesInExtensions ; <nl> + std : : vector < ContextNameFingerprint > classMembers ; <nl> + <nl> / / / Graph under construction <nl> SourceFileDepGraph g ; <nl> <nl> public : <nl> - SourceFileDepGraphConstructor ( SourceFile * SF , <nl> + / / / Expose this layer to enable faking up a constructor for testing . <nl> + / / / See the instance variable comments for explanation . <nl> + / / clang - format off <nl> + SourceFileDepGraphConstructor ( <nl> + StringRef swiftDeps , <nl> + bool includePrivateDeps , <nl> + bool hadCompilationError , <nl> + const std : : string & interfaceHash , <nl> + ArrayRef < std : : pair < std : : string , bool > > topLevelDepends , <nl> + ArrayRef < std : : pair < std : : tuple < std : : string , std : : string , bool > , bool > > memberDepends , <nl> + ArrayRef < std : : pair < std : : string , bool > > dynamicLookupDepends , <nl> + ArrayRef < std : : string > externalDependencies , <nl> + <nl> + ArrayRef < ContextNameFingerprint > precedenceGroups , <nl> + ArrayRef < ContextNameFingerprint > memberOperatorDecls , <nl> + ArrayRef < ContextNameFingerprint > operators , <nl> + ArrayRef < ContextNameFingerprint > topNominals , <nl> + ArrayRef < ContextNameFingerprint > topValues , <nl> + ArrayRef < ContextNameFingerprint > allNominals , <nl> + ArrayRef < ContextNameFingerprint > potentialMemberHolders , <nl> + ArrayRef < ContextNameFingerprint > valuesInExtensions , <nl> + ArrayRef < ContextNameFingerprint > classMembers <nl> + ) : <nl> + swiftDeps ( swiftDeps ) , <nl> + includePrivateDeps ( includePrivateDeps ) , <nl> + hadCompilationError ( hadCompilationError ) , <nl> + <nl> + interfaceHash ( interfaceHash ) , <nl> + topLevelDepends ( topLevelDepends ) , <nl> + memberDepends ( memberDepends ) , <nl> + dynamicLookupDepends ( dynamicLookupDepends ) , <nl> + externalDependencies ( externalDependencies ) , <nl> + <nl> + precedenceGroups ( precedenceGroups ) , <nl> + memberOperatorDecls ( memberOperatorDecls ) , <nl> + operators ( operators ) , <nl> + topNominals ( topNominals ) , <nl> + topValues ( topValues ) , <nl> + allNominals ( allNominals ) , <nl> + potentialMemberHolders ( potentialMemberHolders ) , <nl> + valuesInExtensions ( valuesInExtensions ) , <nl> + classMembers ( classMembers ) <nl> + { } <nl> + <nl> + SourceFileDepGraphConstructor static forSourceFile ( SourceFile * SF , <nl> const DependencyTracker & depTracker , <nl> StringRef swiftDeps , <nl> const bool includePrivateDeps , <nl> - const bool hadCompilationError ) <nl> - : SF ( SF ) , depTracker ( depTracker ) , swiftDeps ( swiftDeps ) , <nl> - includePrivateDeps ( includePrivateDeps ) , <nl> - hadCompilationError ( hadCompilationError ) { } <nl> + const bool hadCompilationError ) { <nl> + <nl> + SourceFileDeclFinder declFinder ( SF , includePrivateDeps ) ; <nl> + std : : vector < std : : pair < std : : string , bool > > topLevelDepends ; <nl> + for ( const auto p : SF - > getReferencedNameTracker ( ) - > getTopLevelNames ( ) ) <nl> + topLevelDepends . push_back ( std : : make_pair ( p . getFirst ( ) . userFacingName ( ) , p . getSecond ( ) ) ) ; <nl> + <nl> + std : : vector < std : : pair < std : : string , bool > > dynamicLookupDepends ; <nl> + for ( const auto p : SF - > getReferencedNameTracker ( ) - > getDynamicLookupNames ( ) ) <nl> + dynamicLookupDepends . push_back ( std : : make_pair ( p . getFirst ( ) . userFacingName ( ) , p . getSecond ( ) ) ) ; <nl> + <nl> + std : : vector < std : : pair < std : : tuple < std : : string , std : : string , bool > , bool > > memberDepends ; <nl> + for ( const auto & p : SF - > getReferencedNameTracker ( ) - > getUsedMembers ( ) ) <nl> + memberDepends . push_back ( <nl> + std : : make_pair ( <nl> + std : : make_tuple ( <nl> + mangleTypeAsContext ( p . getFirst ( ) . first ) , <nl> + p . getFirst ( ) . second . userFacingName ( ) , <nl> + declIsPrivate ( p . getFirst ( ) . first ) ) , <nl> + p . getSecond ( ) ) ) ; <nl> + <nl> + return SourceFileDepGraphConstructor ( <nl> + swiftDeps , <nl> + includePrivateDeps , <nl> + hadCompilationError , <nl> + <nl> + getInterfaceHash ( SF ) , <nl> + topLevelDepends , <nl> + memberDepends , <nl> + dynamicLookupDepends , <nl> + depTracker . getDependencies ( ) , <nl> + <nl> + namesForProvidersOfAGivenType < NodeKind : : topLevel > ( declFinder . precedenceGroups ) , <nl> + namesForProvidersOfAGivenType < NodeKind : : topLevel > ( declFinder . memberOperatorDecls ) , <nl> + namesForProvidersOfAGivenType < NodeKind : : topLevel > ( declFinder . operators ) , <nl> + namesForProvidersOfAGivenType < NodeKind : : topLevel > ( declFinder . topNominals ) , <nl> + namesForProvidersOfAGivenType < NodeKind : : topLevel > ( declFinder . topValues ) , <nl> + namesForProvidersOfAGivenType < NodeKind : : nominal > ( declFinder . allNominals ) , <nl> + namesForProvidersOfAGivenType < NodeKind : : potentialMember > ( declFinder . potentialMemberHolders ) , <nl> + namesForProvidersOfAGivenType < NodeKind : : member > ( declFinder . valuesInExtensions ) , <nl> + namesForProvidersOfAGivenType < NodeKind : : dynamicLookup > ( declFinder . classMembers ) <nl> + ) ; <nl> + } <nl> + / / clang - format on <nl> <nl> / / / Construct the graph and return it . <nl> SourceFileDepGraph construct ( ) { <nl> class SourceFileDepGraphConstructor { <nl> } <nl> <nl> private : <nl> - std : : string getSourceFileFingerprint ( ) const { return getInterfaceHash ( SF ) ; } <nl> + std : : string getSourceFileFingerprint ( ) const { return interfaceHash ; } <nl> <nl> static std : : string getInterfaceHash ( SourceFile * SF ) { <nl> llvm : : SmallString < 32 > interfaceHash ; <nl> class SourceFileDepGraphConstructor { <nl> void addDependencyArcsToGraph ( ) ; <nl> <nl> / / / Given an array of Decls or pairs of them in \ p declsOrPairs <nl> - / / / create nodes if needed and add the new nodes to the graph . <nl> + / / / create string pairs for context and name <nl> template < NodeKind kind , typename ContentsT > <nl> - void addAllProviderNodesOfAGivenType ( std : : vector < ContentsT > & contentsVec ) { <nl> - for ( const auto declOrPair : contentsVec ) { <nl> - / / No fingerprints for providers ( Decls ) yet . <nl> - / / Someday . . . <nl> - const Optional < std : : string > fingerprint = None ; <nl> - auto p = g . findExistingNodePairOrCreateAndAddIfNew ( <nl> - kind , <nl> + static std : : vector < ContextNameFingerprint > <nl> + namesForProvidersOfAGivenType ( std : : vector < ContentsT > & contentsVec ) { <nl> + std : : vector < ContextNameFingerprint > result ; <nl> + for ( const auto declOrPair : contentsVec ) <nl> + result . push_back ( ContextNameFingerprint ( <nl> DependencyKey : : computeContextForProvidedEntity < kind > ( declOrPair ) , <nl> DependencyKey : : computeNameForProvidedEntity < kind > ( declOrPair ) , <nl> - fingerprint ) ; <nl> - / / Since we don ' t have fingerprints yet , must rebuild every provider when <nl> + Optional < std : : string > ( ) ) ) ; <nl> + return result ; <nl> + } <nl> + <nl> + template < NodeKind kind > <nl> + void addAllProviderNodesOfAGivenType ( <nl> + ArrayRef < ContextNameFingerprint > contextNameFingerprints ) { <nl> + for ( const auto & contextNameFingerprint : contextNameFingerprints ) { <nl> + auto p = g . findExistingNodePairOrCreateAndAddIfNew ( <nl> + kind , contextNameFingerprint ) ; <nl> + / / When we don ' t have a fingerprint yet , must rebuild every provider when <nl> / / interfaceHash changes . So when interface ( i . e . interface hash ) of <nl> / / sourceFile changes , every provides is dirty . And since we don ' t know <nl> / / what happened , dirtyness might affect the interface . <nl> class SourceFileDepGraphConstructor { <nl> / / / Given a map of names and isCascades , add the resulting dependencies to the <nl> / / / graph . <nl> template < NodeKind kind > <nl> - void addAllDependenciesFrom ( const llvm : : DenseMap < DeclBaseName , bool > & map ) { <nl> - for ( const auto & p : map ) <nl> + void addAllDependenciesFrom ( ArrayRef < std : : pair < std : : string , bool > > names ) { <nl> + for ( const auto & p : names ) <nl> recordThatThisWholeFileDependsOn ( <nl> DependencyKey : : createDependedUponKey < kind > ( p . first ) , p . second ) ; <nl> } <nl> class SourceFileDepGraphConstructor { <nl> / / / Given a map of holder - and - member - names and isCascades , add the resulting <nl> / / / dependencies to the graph . <nl> void addAllDependenciesFrom ( <nl> - const llvm : : DenseMap < std : : pair < const NominalTypeDecl * , DeclBaseName > , <nl> - bool > & ) ; <nl> + ArrayRef < std : : pair < std : : tuple < std : : string , std : : string , bool > , bool > > ) ; <nl> <nl> / / / Given an array of external swiftDeps files , add the resulting external <nl> / / / dependencies to the graph . <nl> class SourceFileDepGraphConstructor { <nl> } ; <nl> } / / namespace <nl> <nl> - using UsedMembersMap = <nl> - llvm : : DenseMap < std : : pair < const NominalTypeDecl * , DeclBaseName > , bool > ; <nl> void SourceFileDepGraphConstructor : : addAllDependenciesFrom ( <nl> - const UsedMembersMap & map ) { <nl> - <nl> - UsedMembersMap filteredMap ; <nl> - for ( const auto & entry : map ) <nl> - if ( includePrivateDeps | | ! declIsPrivate ( entry . first . first ) ) <nl> - filteredMap [ entry . getFirst ( ) ] = entry . getSecond ( ) ; <nl> + ArrayRef < std : : pair < std : : tuple < std : : string , std : : string , bool > , bool > > <nl> + members ) { <nl> <nl> - std : : unordered_set < const NominalTypeDecl * > holdersOfCascadingMembers ; <nl> - for ( auto & entry : filteredMap ) <nl> + llvm : : StringSet < > holdersOfCascadingMembers ; <nl> + for ( const auto & entry : members ) { <nl> + if ( ! includePrivateDeps & & std : : get < 2 > ( entry . first ) ) <nl> + continue ; <nl> if ( entry . second ) <nl> - holdersOfCascadingMembers . insert ( entry . first . first ) ; <nl> - <nl> - for ( auto & entry : filteredMap ) { <nl> - / / mangles twice in the name of symmetry <nl> + holdersOfCascadingMembers . insert ( std : : get < 0 > ( entry . first ) ) ; <nl> + } <nl> + for ( const auto & entry : members ) { <nl> + if ( ! includePrivateDeps & & std : : get < 2 > ( entry . first ) ) <nl> + continue ; <nl> recordThatThisWholeFileDependsOn ( <nl> - DependencyKey : : createDependedUponKey < NodeKind : : nominal > ( entry . first ) , <nl> - holdersOfCascadingMembers . count ( entry . first . first ) ! = 0 ) ; <nl> + DependencyKey : : createDependedUponKey < NodeKind : : nominal > ( <nl> + std : : get < 0 > ( entry . first ) ) , <nl> + holdersOfCascadingMembers . count ( std : : get < 0 > ( entry . first ) ) ! = 0 ) ; <nl> recordThatThisWholeFileDependsOn ( <nl> - DependencyKey : : createDependedUponKey < NodeKind : : member > ( entry . first ) , <nl> + DependencyKey : : createDependedUponKey ( std : : get < 0 > ( entry . first ) , <nl> + std : : get < 1 > ( entry . first ) ) , <nl> entry . second ) ; <nl> } <nl> } <nl> void SourceFileDepGraphConstructor : : addAllDependenciesFrom ( <nl> void SourceFileDepGraphConstructor : : addSourceFileNodesToGraph ( ) { <nl> g . findExistingNodePairOrCreateAndAddIfNew ( <nl> NodeKind : : sourceFileProvide , <nl> - DependencyKey : : computeContextForProvidedEntity < <nl> - NodeKind : : sourceFileProvide > ( swiftDeps ) , <nl> - DependencyKey : : computeNameForProvidedEntity < NodeKind : : sourceFileProvide > ( <nl> - swiftDeps ) , <nl> - getSourceFileFingerprint ( ) ) ; <nl> + ContextNameFingerprint ( DependencyKey : : computeContextForProvidedEntity < <nl> + NodeKind : : sourceFileProvide > ( swiftDeps ) , <nl> + DependencyKey : : computeNameForProvidedEntity < <nl> + NodeKind : : sourceFileProvide > ( swiftDeps ) , <nl> + getSourceFileFingerprint ( ) ) ) ; <nl> } <nl> <nl> void SourceFileDepGraphConstructor : : addProviderNodesToGraph ( ) { <nl> - SourceFileDeclFinder declFinder ( SF , includePrivateDeps ) ; <nl> / / TODO : express the multiple provides and depends streams with variadic <nl> / / templates <nl> <nl> / / Many kinds of Decls become top - level depends . <nl> - addAllProviderNodesOfAGivenType < NodeKind : : topLevel > ( <nl> - declFinder . precedenceGroups ) ; <nl> - addAllProviderNodesOfAGivenType < NodeKind : : topLevel > ( <nl> - declFinder . memberOperatorDecls ) ; <nl> - addAllProviderNodesOfAGivenType < NodeKind : : topLevel > ( declFinder . operators ) ; <nl> - addAllProviderNodesOfAGivenType < NodeKind : : topLevel > ( declFinder . topNominals ) ; <nl> - addAllProviderNodesOfAGivenType < NodeKind : : topLevel > ( declFinder . topValues ) ; <nl> + addAllProviderNodesOfAGivenType < NodeKind : : topLevel > ( precedenceGroups ) ; <nl> + addAllProviderNodesOfAGivenType < NodeKind : : topLevel > ( memberOperatorDecls ) ; <nl> + addAllProviderNodesOfAGivenType < NodeKind : : topLevel > ( operators ) ; <nl> + addAllProviderNodesOfAGivenType < NodeKind : : topLevel > ( topNominals ) ; <nl> + addAllProviderNodesOfAGivenType < NodeKind : : topLevel > ( topValues ) ; <nl> <nl> - addAllProviderNodesOfAGivenType < NodeKind : : nominal > ( declFinder . allNominals ) ; <nl> + addAllProviderNodesOfAGivenType < NodeKind : : nominal > ( allNominals ) ; <nl> <nl> addAllProviderNodesOfAGivenType < NodeKind : : potentialMember > ( <nl> - declFinder . potentialMemberHolders ) ; <nl> - addAllProviderNodesOfAGivenType < NodeKind : : member > ( <nl> - declFinder . valuesInExtensions ) ; <nl> + potentialMemberHolders ) ; <nl> + addAllProviderNodesOfAGivenType < NodeKind : : member > ( valuesInExtensions ) ; <nl> <nl> - addAllProviderNodesOfAGivenType < NodeKind : : dynamicLookup > ( <nl> - declFinder . classMembers ) ; <nl> + addAllProviderNodesOfAGivenType < NodeKind : : dynamicLookup > ( classMembers ) ; <nl> } <nl> <nl> void SourceFileDepGraphConstructor : : addDependencyArcsToGraph ( ) { <nl> / / TODO : express the multiple provides and depends streams with variadic <nl> / / templates <nl> - addAllDependenciesFrom < NodeKind : : topLevel > ( <nl> - SF - > getReferencedNameTracker ( ) - > getTopLevelNames ( ) ) ; <nl> - addAllDependenciesFrom ( SF - > getReferencedNameTracker ( ) - > getUsedMembers ( ) ) ; <nl> - addAllDependenciesFrom < NodeKind : : dynamicLookup > ( <nl> - SF - > getReferencedNameTracker ( ) - > getDynamicLookupNames ( ) ) ; <nl> - addAllDependenciesFrom ( depTracker . getDependencies ( ) ) ; <nl> + addAllDependenciesFrom < NodeKind : : topLevel > ( topLevelDepends ) ; <nl> + addAllDependenciesFrom ( memberDepends ) ; <nl> + addAllDependenciesFrom < NodeKind : : dynamicLookup > ( dynamicLookupDepends ) ; <nl> + addAllDependenciesFrom ( externalDependencies ) ; <nl> } <nl> <nl> void SourceFileDepGraphConstructor : : recordThatThisWholeFileDependsOn ( <nl> void SourceFileDepGraphConstructor : : recordThatThisWholeFileDependsOn ( <nl> <nl> bool swift : : fine_grained_dependencies : : emitReferenceDependencies ( <nl> DiagnosticEngine & diags , SourceFile * const SF , <nl> - const DependencyTracker & depTracker , StringRef outputPath ) { <nl> + const DependencyTracker & depTracker , StringRef outputPath , <nl> + const bool alsoEmitDotFile ) { <nl> <nl> / / Before writing to the dependencies file path , preserve any previous file <nl> / / that may have been there . No error handling - - this is just a nicety , it <nl> bool swift : : fine_grained_dependencies : : emitReferenceDependencies ( <nl> const bool includeIntrafileDeps = <nl> SF - > getASTContext ( ) . LangOpts . FineGrainedDependenciesIncludeIntrafileOnes ; <nl> const bool hadCompilationError = SF - > getASTContext ( ) . hadError ( ) ; <nl> - SourceFileDepGraphConstructor gc ( SF , depTracker , outputPath , <nl> - includeIntrafileDeps , hadCompilationError ) ; <nl> + auto gc = SourceFileDepGraphConstructor : : forSourceFile ( <nl> + SF , depTracker , outputPath , includeIntrafileDeps , hadCompilationError ) ; <nl> SourceFileDepGraph g = gc . construct ( ) ; <nl> <nl> const bool hadError = <nl> bool swift : : fine_grained_dependencies : : emitReferenceDependencies ( <nl> <nl> assert ( g . verifyReadsWhatIsWritten ( outputPath ) ) ; <nl> <nl> - std : : string dotFileName = outputPath . str ( ) + " . dot " ; <nl> - withOutputFile ( diags , dotFileName , [ & ] ( llvm : : raw_pwrite_stream & out ) { <nl> - DotFileEmitter < SourceFileDepGraph > ( out , g , false , false ) . emit ( ) ; <nl> - return false ; <nl> - } ) ; <nl> + if ( alsoEmitDotFile ) { <nl> + std : : string dotFileName = outputPath . str ( ) + " . dot " ; <nl> + withOutputFile ( diags , dotFileName , [ & ] ( llvm : : raw_pwrite_stream & out ) { <nl> + DotFileEmitter < SourceFileDepGraph > ( out , g , false , false ) . emit ( ) ; <nl> + return false ; <nl> + } ) ; <nl> + } <nl> return hadError ; <nl> } <nl> + <nl> + / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> + / / Entry point from the unit tests <nl> + / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> + <nl> + static std : : vector < ContextNameFingerprint > <nl> + getBaseNameProvides ( ArrayRef < std : : string > simpleNames ) { <nl> + std : : vector < ContextNameFingerprint > result ; <nl> + for ( StringRef n : simpleNames ) <nl> + result . push_back ( ContextNameFingerprint ( " " , n . str ( ) , None ) ) ; <nl> + return result ; <nl> + } <nl> + <nl> + static std : : vector < ContextNameFingerprint > <nl> + getMangledHolderProvides ( ArrayRef < std : : string > simpleNames ) { <nl> + std : : vector < ContextNameFingerprint > result ; <nl> + for ( StringRef n : simpleNames ) <nl> + result . push_back ( ContextNameFingerprint ( n . str ( ) , " " , None ) ) ; <nl> + return result ; <nl> + } <nl> + <nl> + static std : : vector < ContextNameFingerprint > getCompoundProvides ( <nl> + ArrayRef < std : : pair < std : : string , std : : string > > compoundNames ) { <nl> + std : : vector < ContextNameFingerprint > result ; <nl> + for ( const auto & p : compoundNames ) <nl> + result . push_back ( ContextNameFingerprint ( p . first , p . second , None ) ) ; <nl> + return result ; <nl> + } <nl> + <nl> + / / Use ' _ ' as a prefix indicating non - cascading <nl> + static bool cascades ( const std : : string & s ) { return s . empty ( ) | | s [ 0 ] ! = ' _ ' ; } <nl> + <nl> + / / Use ' _ ' as a prefix for a file - private member <nl> + static bool isPrivate ( const std : : string & s ) { <nl> + return ! s . empty ( ) & & s [ 0 ] = = ' _ ' ; <nl> + } <nl> + <nl> + static std : : vector < std : : pair < std : : string , bool > > <nl> + getSimpleDepends ( ArrayRef < std : : string > simpleNames ) { <nl> + std : : vector < std : : pair < std : : string , bool > > result ; <nl> + for ( std : : string n : simpleNames ) <nl> + result . push_back ( { n , cascades ( ( n ) ) } ) ; <nl> + return result ; <nl> + } <nl> + <nl> + static std : : vector < std : : string > <nl> + getExternalDepends ( ArrayRef < std : : string > simpleNames ) { <nl> + return simpleNames ; <nl> + } <nl> + <nl> + static std : : vector < std : : pair < std : : tuple < std : : string , std : : string , bool > , bool > > <nl> + getCompoundDepends ( <nl> + ArrayRef < std : : string > simpleNames , <nl> + ArrayRef < std : : pair < std : : string , std : : string > > compoundNames ) { <nl> + std : : vector < std : : pair < std : : tuple < std : : string , std : : string , bool > , bool > > <nl> + result ; <nl> + for ( std : : string n : simpleNames ) { <nl> + / / ( On Linux , the compiler needs more verbosity than : <nl> + / / result . push_back ( { { n , " " , false } , cascades ( n ) } ) ; <nl> + result . push_back ( <nl> + std : : make_pair ( std : : make_tuple ( n , std : : string ( ) , false ) , cascades ( n ) ) ) ; <nl> + } <nl> + for ( auto & p : compoundNames ) { <nl> + / / Likewise , for Linux expand the following out : <nl> + / / result . push_back ( <nl> + / / { { p . first , p . second , isPrivate ( p . second ) } , cascades ( p . first ) } ) ; <nl> + result . push_back ( <nl> + std : : make_pair ( std : : make_tuple ( p . first , p . second , isPrivate ( p . second ) ) , <nl> + cascades ( p . first ) ) ) ; <nl> + } <nl> + return result ; <nl> + } <nl> + <nl> + SourceFileDepGraph SourceFileDepGraph : : simulateLoad ( <nl> + std : : string swiftDepsFilename , const bool includePrivateDeps , <nl> + const bool hadCompilationError , std : : string interfaceHash , <nl> + llvm : : StringMap < std : : vector < std : : string > > simpleNamesByRDK , <nl> + llvm : : StringMap < std : : vector < std : : pair < std : : string , std : : string > > > <nl> + compoundNamesByRDK ) { <nl> + <nl> + using namespace reference_dependency_keys ; <nl> + <nl> + / / clang - format off <nl> + SourceFileDepGraphConstructor c ( <nl> + swiftDepsFilename , includePrivateDeps , hadCompilationError , interfaceHash , <nl> + getSimpleDepends ( simpleNamesByRDK [ dependsTopLevel ] ) , <nl> + getCompoundDepends ( simpleNamesByRDK [ dependsNominal ] , compoundNamesByRDK [ dependsMember ] ) , <nl> + getSimpleDepends ( simpleNamesByRDK [ dependsDynamicLookup ] ) , <nl> + getExternalDepends ( simpleNamesByRDK [ dependsExternal ] ) , <nl> + { } , / / precedence groups <nl> + { } , / / memberOperatorDecls <nl> + { } , / / operators <nl> + getMangledHolderProvides ( simpleNamesByRDK [ providesNominal ] ) , / / topNominals <nl> + getBaseNameProvides ( simpleNamesByRDK [ providesTopLevel ] ) , / / topValues <nl> + getMangledHolderProvides ( simpleNamesByRDK [ providesNominal ] ) , / / allNominals <nl> + getMangledHolderProvides ( simpleNamesByRDK [ providesNominal ] ) , / / potentialMemberHolders <nl> + getCompoundProvides ( compoundNamesByRDK [ providesMember ] ) , / / valuesInExtensions <nl> + getBaseNameProvides ( simpleNamesByRDK [ providesDynamicLookup ] ) / / classMembers <nl> + ) ; <nl> + / / clang - format on <nl> + return c . construct ( ) ; <nl> + } <nl> mmm a / lib / Driver / Compilation . cpp <nl> ppp b / lib / Driver / Compilation . cpp <nl> namespace driver { <nl> <nl> void noteBuilding ( const Job * cmd , const bool willBeBuilding , <nl> const bool isTentative , const bool forRanges , <nl> - StringRef reason ) { <nl> + StringRef reason ) const { <nl> if ( ! Comp . getShowIncrementalBuildDecisions ( ) ) <nl> return ; <nl> if ( ScheduledCommands . count ( cmd ) ) <nl> namespace driver { <nl> } ) ; <nl> } <nl> <nl> + template < typename JobsCollection > <nl> + void noteBuildingJobs ( const JobsCollection & unsortedJobsArg , <nl> + const bool forRanges , const StringRef reason ) const { <nl> + if ( ! Comp . getShowIncrementalBuildDecisions ( ) & & <nl> + ! Comp . getShowJobLifecycle ( ) ) <nl> + return ; <nl> + / / Sigh , must manually convert SmallPtrSet to ArrayRef - able container <nl> + llvm : : SmallVector < const Job * , 16 > unsortedJobs ; <nl> + for ( const Job * j : unsortedJobsArg ) <nl> + unsortedJobs . push_back ( j ) ; <nl> + llvm : : SmallVector < const Job * , 16 > sortedJobs ; <nl> + Comp . sortJobsToMatchCompilationInputs ( unsortedJobs , sortedJobs ) ; <nl> + for ( const Job * j : sortedJobs ) <nl> + noteBuilding ( j , / * willBeBuilding = * / true , / * isTentative = * / false , <nl> + forRanges , reason ) ; <nl> + } <nl> + <nl> const Job * findUnfinishedJob ( ArrayRef < const Job * > JL ) { <nl> for ( const Job * Cmd : JL ) { <nl> if ( ! FinishedCommands . count ( Cmd ) ) <nl> namespace driver { <nl> diag : : warn_unable_to_load_dependencies , <nl> DependenciesFile ) ; <nl> Comp . disableIncrementalBuild ( <nl> - Twine ( " Malformed swift dependencies file ' " ) + DependenciesFile + <nl> + Twine ( " malformed swift dependencies file ' " ) + DependenciesFile + <nl> " ' " ) ; <nl> } <nl> <nl> namespace driver { <nl> / / other recompilations . It is possible that the current code marks <nl> / / things that do not need to be marked . Unecessary compilation would <nl> / / result if that were the case . <nl> - bool wasCascading = isMarkedInDepGraph ( FinishedCmd , forRanges ) ; <nl> + bool wasKnownToNeedRunning = isMarkedInDepGraph ( FinishedCmd , forRanges ) ; <nl> <nl> switch ( loadDepGraphFromPath ( FinishedCmd , DependenciesFile , <nl> Comp . getDiags ( ) , forRanges ) ) { <nl> namespace driver { <nl> break ; <nl> <nl> case CoarseGrainedDependencyGraph : : LoadResult : : UpToDate : <nl> - if ( ! wasCascading ) <nl> + if ( ! wasKnownToNeedRunning ) <nl> break ; <nl> LLVM_FALLTHROUGH ; <nl> case CoarseGrainedDependencyGraph : : LoadResult : : AffectsDownstream : <nl> namespace driver { <nl> const CommandSet & DependentsInEffect = useRangesForScheduling <nl> ? DependentsWithRanges <nl> : DependentsWithoutRanges ; <nl> - for ( const Job * Cmd : DependentsInEffect ) { <nl> + <nl> + noteBuildingJobs ( DependentsInEffect , useRangesForScheduling , <nl> + " because of dependencies discovered later " ) ; <nl> + <nl> + / / Sort dependents for more deterministic behavior <nl> + llvm : : SmallVector < const Job * , 16 > UnsortedDependents ; <nl> + for ( const Job * j : DependentsInEffect ) <nl> + UnsortedDependents . push_back ( j ) ; <nl> + llvm : : SmallVector < const Job * , 16 > SortedDependents ; <nl> + Comp . sortJobsToMatchCompilationInputs ( UnsortedDependents , <nl> + SortedDependents ) ; <nl> + <nl> + for ( const Job * Cmd : SortedDependents ) { <nl> DeferredCommands . erase ( Cmd ) ; <nl> - noteBuilding ( Cmd , / * willBeBuilding = * / true , useRangesForScheduling , <nl> - / * isTentative = * / false , <nl> - " because of dependencies discovered later " ) ; <nl> scheduleCommandIfNecessaryAndPossible ( Cmd ) ; <nl> } <nl> - <nl> return TaskFinishedResponse : : ContinueExecution ; <nl> } <nl> <nl> namespace driver { <nl> <nl> / / Store this task ' s ReturnCode as our Result if we haven ' t stored <nl> / / anything yet . <nl> + <nl> if ( Result = = EXIT_SUCCESS ) <nl> Result = ReturnCode ; <nl> <nl> namespace driver { <nl> <nl> const bool isCascading = isCascadingJobAccordingToCondition ( <nl> Cmd , Cond , HasDependenciesFileName ) ; <nl> - <nl> - if ( Comp . getEnableFineGrainedDependencies ( ) ) <nl> - assert ( getFineGrainedDepGraph ( / * forRanges = * / false ) <nl> - . emitDotFileAndVerify ( Comp . getDiags ( ) ) ) ; <nl> return std : : make_pair ( shouldSched , isCascading ) ; <nl> } <nl> <nl> namespace driver { <nl> const Job * const Cmd , const Job : : Condition Condition , <nl> const bool hasDependenciesFileName , const bool forRanges ) { <nl> <nl> + / / When using ranges may still decide not to schedule the job . <nl> + const bool isTentative = <nl> + Comp . getEnableSourceRangeDependencies ( ) | | forRanges ; <nl> + <nl> switch ( Condition ) { <nl> case Job : : Condition : : Always : <nl> case Job : : Condition : : NewlyAdded : <nl> namespace driver { <nl> } <nl> LLVM_FALLTHROUGH ; <nl> case Job : : Condition : : RunWithoutCascading : <nl> - noteBuilding ( Cmd , / * willBeBuilding = * / true , / * isTentative = * / true , <nl> + noteBuilding ( Cmd , / * willBeBuilding = * / true , / * isTentative = * / isTentative , <nl> forRanges , " ( initial ) " ) ; <nl> return true ; <nl> case Job : : Condition : : CheckDependencies : <nl> - noteBuilding ( Cmd , / * willBeBuilding = * / false , / * isTentative = * / true , <nl> + noteBuilding ( Cmd , / * willBeBuilding = * / false , / * isTentative = * / isTentative , <nl> forRanges , " file is up - to - date and output exists " ) ; <nl> return false ; <nl> } <nl> namespace driver { <nl> IncrementalTracer ) ) <nl> CascadedJobs . insert ( transitiveCmd ) ; <nl> } <nl> - for ( auto * transitiveCmd : CascadedJobs ) <nl> - noteBuilding ( transitiveCmd , / * willBeBuilding = * / true , <nl> - / * isTentative = * / false , forRanges , <nl> - " because of the initial set " ) ; <nl> - <nl> + noteBuildingJobs ( CascadedJobs , forRanges , " because of the initial set " ) ; <nl> return CascadedJobs ; <nl> } <nl> <nl> namespace driver { <nl> for ( const Job * marked : markExternalInDepGraph ( dependency , forRanges ) ) <nl> ExternallyDependentJobs . push_back ( marked ) ; <nl> } ) ; <nl> - for ( auto * externalCmd : ExternallyDependentJobs ) { <nl> - noteBuilding ( externalCmd , / * willBeBuilding = * / true , <nl> - / * isTentative = * / false , forRanges , <nl> - " because of external dependencies " ) ; <nl> - } <nl> + noteBuildingJobs ( ExternallyDependentJobs , forRanges , <nl> + " because of external dependencies " ) ; <nl> return ExternallyDependentJobs ; <nl> } <nl> <nl> namespace driver { <nl> continue ; <nl> <nl> / / Be conservative , in case we use ranges this time but not next . <nl> - bool isCascading = true ; <nl> + bool mightBeCascading = true ; <nl> if ( Comp . getIncrementalBuildEnabled ( ) ) <nl> - isCascading = isMarkedInDepGraph ( <nl> + mightBeCascading = isMarkedInDepGraph ( <nl> Cmd , / * forRanges = * / Comp . getEnableSourceRangeDependencies ( ) ) ; <nl> - UnfinishedCommands . insert ( { Cmd , isCascading } ) ; <nl> + UnfinishedCommands . insert ( { Cmd , mightBeCascading } ) ; <nl> } <nl> } <nl> } <nl> int Compilation : : performJobsImpl ( bool & abnormalExit , <nl> CompilationRecordPath + " ~ moduleonly " ) ; <nl> } <nl> } <nl> - if ( getEnableFineGrainedDependencies ( ) ) <nl> - assert ( State . FineGrainedDepGraph . emitDotFileAndVerify ( getDiags ( ) ) ) ; <nl> abnormalExit = State . hadAnyAbnormalExit ( ) ; <nl> return State . getResult ( ) ; <nl> } <nl> void Compilation : : addDependencyPathOrCreateDummy ( <nl> llvm : : raw_fd_ostream ( depPath , EC , llvm : : sys : : fs : : F_None ) ; <nl> } <nl> } <nl> + <nl> + void Compilation : : sortJobsToMatchCompilationInputs ( <nl> + const ArrayRef < const Job * > unsortedJobs , <nl> + SmallVectorImpl < const Job * > & sortedJobs ) const { <nl> + llvm : : DenseMap < StringRef , const Job * > jobsByInput ; <nl> + for ( const Job * J : unsortedJobs ) { <nl> + const CompileJobAction * CJA = cast < CompileJobAction > ( & J - > getSource ( ) ) ; <nl> + const InputAction * IA = CJA - > findSingleSwiftInput ( ) ; <nl> + auto R = <nl> + jobsByInput . insert ( std : : make_pair ( IA - > getInputArg ( ) . getValue ( ) , J ) ) ; <nl> + assert ( R . second ) ; <nl> + ( void ) R ; <nl> + } <nl> + for ( const InputPair & P : getInputFiles ( ) ) { <nl> + auto I = jobsByInput . find ( P . second - > getValue ( ) ) ; <nl> + if ( I ! = jobsByInput . end ( ) ) { <nl> + sortedJobs . push_back ( I - > second ) ; <nl> + } <nl> + } <nl> + } <nl> mmm a / lib / Driver / Driver . cpp <nl> ppp b / lib / Driver / Driver . cpp <nl> Driver : : buildCompilation ( const ToolChain & TC , <nl> <nl> / / relies on the new dependency graph <nl> const bool EnableFineGrainedDependencies = <nl> - ArgList - > hasArg ( options : : OPT_enable_fine_grained_dependencies ) ; <nl> + ArgList - > hasFlag ( options : : OPT_enable_fine_grained_dependencies , <nl> + options : : OPT_disable_fine_grained_dependencies , false ) ; <nl> <nl> const bool VerifyFineGrainedDependencyGraphAfterEveryImport = ArgList - > hasArg ( <nl> options : : <nl> mmm a / lib / Driver / FineGrainedDependencyDriverGraph . cpp <nl> ppp b / lib / Driver / FineGrainedDependencyDriverGraph . cpp <nl> using namespace swift : : driver ; <nl> / / MARK : Interfacing to Compilation <nl> / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> <nl> - using LoadResult = <nl> - fine_grained_dependencies : : CoarseGrainedDependencyGraphImpl : : LoadResult ; <nl> + using LoadResult = CoarseGrainedDependencyGraphImpl : : LoadResult ; <nl> <nl> LoadResult ModuleDepGraph : : loadFromPath ( const Job * Cmd , StringRef path , <nl> DiagnosticEngine & diags ) { <nl> LoadResult ModuleDepGraph : : loadFromPath ( const Job * Cmd , StringRef path , <nl> return r ; <nl> } <nl> <nl> + LoadResult ModuleDepGraph : : loadFromString ( const Job * cmd , StringRef data ) { <nl> + auto buffer = llvm : : MemoryBuffer : : getMemBuffer ( data ) ; <nl> + return loadFromBuffer ( cmd , * buffer . get ( ) ) ; <nl> + } <nl> + <nl> LoadResult ModuleDepGraph : : loadFromBuffer ( const Job * job , <nl> llvm : : MemoryBuffer & buffer ) { <nl> <nl> LoadResult ModuleDepGraph : : loadFromBuffer ( const Job * job , <nl> SourceFileDepGraph : : loadFromBuffer ( buffer ) ; <nl> if ( ! sourceFileDepGraph ) <nl> return CoarseGrainedDependencyGraphImpl : : LoadResult : : HadError ; <nl> + return loadFromSourceFileDepGraph ( job , sourceFileDepGraph . getValue ( ) ) ; <nl> + } <nl> + <nl> + LoadResult ModuleDepGraph : : loadFromSourceFileDepGraph ( <nl> + const Job * job , const SourceFileDepGraph & sourceFileDepGraph ) { <nl> addIndependentNode ( job ) ; <nl> - return integrate ( sourceFileDepGraph . getValue ( ) ) ; <nl> + return integrate ( sourceFileDepGraph ) ; <nl> } <nl> <nl> bool ModuleDepGraph : : isMarked ( const Job * cmd ) const { <nl> - return cascadingJobs . count ( getSwiftDeps ( cmd ) ) ; <nl> + return swiftDepsOfJobsThatNeedRunning . count ( getSwiftDeps ( cmd ) ) ; <nl> } <nl> <nl> std : : vector < const Job * > ModuleDepGraph : : markTransitive ( <nl> const Job * jobToBeRecompiled , const void * ignored ) { <nl> FrontendStatsTracer tracer ( stats , " fine - grained - dependencies - markTransitive " ) ; <nl> + assert ( jobToBeRecompiled & & " Ensure there is really a job " ) ; <nl> <nl> std : : unordered_set < const ModuleDepGraphNode * > dependentNodes ; <nl> const StringRef swiftDepsToBeRecompiled = getSwiftDeps ( jobToBeRecompiled ) ; <nl> - / / Do the traversal . <nl> + assert ( ! swiftDepsToBeRecompiled . empty ( ) & & " Must have a swift deps " ) ; <nl> + / / Caller already knows to run this job , no need to return it . <nl> + recordJobNeedsRunning ( swiftDepsToBeRecompiled ) ; <nl> + <nl> + / / Do the traversal for every node in the job to be recompiled . <nl> for ( auto & fileAndNode : nodeMap [ swiftDepsToBeRecompiled ] ) { <nl> assert ( isCurrentPathForTracingEmpty ( ) ) ; <nl> - findDependentNodesAndRecordCascadingOnes ( dependentNodes , <nl> - fileAndNode . second ) ; <nl> + findDependentNodes ( dependentNodes , fileAndNode . second ) ; <nl> } <nl> - return computeUniqueJobsFromNodes ( dependentNodes ) ; <nl> + std : : vector < const Job * > newJobsToCompile ; <nl> + / / The job containing the interface " cascades " , in other words <nl> + / / whenever that job gets recompiled , anything depending on it <nl> + / / ( since we don ' t have interface - specific dependency info as of Dec . <nl> + / / 2018 ) must be recompiled . <nl> + std : : vector < const ModuleDepGraphNode * > dependentNodesVec { <nl> + dependentNodes . begin ( ) , dependentNodes . end ( ) } ; <nl> + for ( const auto & entry : <nl> + computeSwiftDepsFromInterfaceNodes ( dependentNodesVec ) ) { <nl> + const StringRef swiftDeps = entry . getKey ( ) ; <nl> + if ( recordJobNeedsRunning ( swiftDeps ) ) { <nl> + const Job * j = getJob ( swiftDeps . str ( ) ) ; <nl> + newJobsToCompile . push_back ( j ) ; <nl> + } <nl> + } <nl> + return newJobsToCompile ; <nl> } <nl> <nl> - std : : vector < const Job * > ModuleDepGraph : : computeUniqueJobsFromNodes ( <nl> - const std : : unordered_set < const ModuleDepGraphNode * > & nodes ) { <nl> - <nl> - std : : vector < const Job * > jobs ; <nl> + llvm : : StringSet < > ModuleDepGraph : : computeSwiftDepsFromInterfaceNodes ( <nl> + const ArrayRef < const ModuleDepGraphNode * > nodes ) { <nl> <nl> - std : : unordered_set < std : : string > swiftDepsOfNodes ; <nl> + llvm : : StringSet < > swiftDepsOfNodes ; <nl> for ( const ModuleDepGraphNode * n : nodes ) { <nl> - if ( ! n - > getSwiftDeps ( ) . hasValue ( ) ) <nl> + / / if ( ! n - > doesNodeProvideAnInterface ( ) ) <nl> + / / continue ; <nl> + if ( ! n - > getIsProvides ( ) ) <nl> continue ; <nl> - const std : : string & swiftDeps = n - > getSwiftDeps ( ) . getValue ( ) ; <nl> + const std : : string & swiftDeps = n - > getSwiftDepsOfProvides ( ) ; <nl> if ( swiftDepsOfNodes . insert ( swiftDeps ) . second ) { <nl> assert ( n - > assertImplementationMustBeInAFile ( ) ) ; <nl> - ensureJobIsTracked ( swiftDeps ) ; <nl> - jobs . push_back ( getJob ( swiftDeps ) ) ; <nl> + assert ( ensureJobIsTracked ( swiftDeps ) ) ; <nl> } <nl> } <nl> - return jobs ; <nl> + return swiftDepsOfNodes ; <nl> } <nl> <nl> - bool ModuleDepGraph : : markIntransitive ( const Job * node ) { <nl> - return rememberThatJobCascades ( getSwiftDeps ( node ) ) ; <nl> + bool ModuleDepGraph : : markIntransitive ( const Job * job ) { <nl> + return recordJobNeedsRunning ( getSwiftDeps ( job ) ) ; <nl> } <nl> <nl> void ModuleDepGraph : : addIndependentNode ( const Job * job ) { <nl> void ModuleDepGraph : : forEachUnmarkedJobDirectlyDependentOnExternalSwiftdeps ( <nl> DependencyKey key = <nl> DependencyKey : : createDependedUponKey < NodeKind : : externalDepend > ( <nl> externalSwiftDeps . str ( ) ) ; <nl> - / / collect answers into useSet <nl> - std : : unordered_set < std : : string > visitedSet ; <nl> for ( const ModuleDepGraphNode * useNode : usesByDef [ key ] ) { <nl> - const Job * job = getJob ( useNode - > getSwiftDeps ( ) ) ; <nl> - if ( ! isMarked ( job ) ) <nl> + const auto swiftDepsOfUse = useNode - > getSwiftDepsOfProvides ( ) ; <nl> + const Job * job = getJob ( swiftDepsOfUse ) ; <nl> + if ( isMarked ( job ) ) <nl> continue ; <nl> fn ( job ) ; <nl> } <nl> void ModuleDepGraph : : forEachUnmarkedJobDirectlyDependentOnExternalSwiftdeps ( <nl> LoadResult ModuleDepGraph : : integrate ( const SourceFileDepGraph & g ) { <nl> FrontendStatsTracer tracer ( stats , " fine - grained - dependencies - integrate " ) ; <nl> <nl> - StringRef swiftDeps = g . getSwiftDepsFromSourceFileProvide ( ) ; <nl> + StringRef swiftDeps = g . getSwiftDepsOfJobThatProducedThisGraph ( ) ; <nl> / / When done , disappearedNodes contains the nodes which no longer exist . <nl> auto disappearedNodes = nodeMap [ swiftDeps ] ; <nl> / / When done , changeDependencyKeys contains a list of keys that changed <nl> bool ModuleDepGraph : : integrateSourceFileDepGraphNode ( <nl> if ( integrand - > getKey ( ) . getKind ( ) = = NodeKind : : externalDepend ) <nl> return externalDependencies . insert ( integrand - > getKey ( ) . getName ( ) ) . second ; <nl> <nl> + / / Since dependencies are modeled as arcs in both SourceFile and Module <nl> + / / dependency graphs , no more integration need be done for a depends node . The <nl> + / / information will be obtained front the using node ' s arcs . <nl> if ( integrand - > isDepends ( ) ) <nl> - return false ; / / dependency will be handled by the use node <nl> + return false ; <nl> <nl> - StringRef swiftDepsOfSourceFileGraph = g . getSwiftDepsFromSourceFileProvide ( ) ; <nl> + StringRef swiftDepsOfSourceFileGraph = <nl> + g . getSwiftDepsOfJobThatProducedThisGraph ( ) ; <nl> auto changedAndUseNode = integrateSourceFileDeclNode ( <nl> integrand , swiftDepsOfSourceFileGraph , preexistingMatch ) ; <nl> recordWhatUseDependsUpon ( g , integrand , changedAndUseNode . second ) ; <nl> void ModuleDepGraph : : recordWhatUseDependsUpon ( <nl> <nl> void ModuleDepGraph : : removeNode ( ModuleDepGraphNode * n ) { <nl> eraseNodeFromMap ( n ) ; <nl> + eraseNodeFromUsesByDef ( n ) ; <nl> + eraseNodeFromCurrentPathIfTracing ( n ) ; <nl> + eraseNodeFromDependencyPathToJobs ( n ) ; <nl> + <nl> delete n ; <nl> } <nl> <nl> void ModuleDepGraph : : forEachUseOf ( <nl> return ; <nl> for ( const ModuleDepGraphNode * useNode : iter - > second ) <nl> fn ( useNode ) ; <nl> + / / Add in implicit interface - > implementation dependency <nl> + if ( def - > getKey ( ) . isInterface ( ) & & def - > getSwiftDeps ( ) ) { <nl> + const auto & dk = def - > getKey ( ) ; <nl> + const DependencyKey key ( dk . getKind ( ) , DeclAspect : : interface , <nl> + dk . getContext ( ) , dk . getName ( ) ) ; <nl> + if ( const auto interfaceNode = <nl> + nodeMap . find ( def - > getSwiftDeps ( ) . getValue ( ) , dk ) ) <nl> + fn ( interfaceNode . getValue ( ) ) ; <nl> + } <nl> } <nl> <nl> void ModuleDepGraph : : forEachNode ( <nl> void ModuleDepGraph : : forEachArc ( <nl> / / Could be faster by passing in a file , not a node , but we are trying for <nl> / / generality . <nl> <nl> - void ModuleDepGraph : : findDependentNodesAndRecordCascadingOnes ( <nl> + void ModuleDepGraph : : findDependentNodes ( <nl> std : : unordered_set < const ModuleDepGraphNode * > & foundDependents , <nl> const ModuleDepGraphNode * definition ) { <nl> <nl> - size_t pathLengthAfterArrival = traceArrival ( definition ) ; <nl> + size_t pathLengthAfterArrival = traceArrival ( definition ) ; <nl> <nl> / / Moved this out of the following loop for effieciency . <nl> - assert ( definition - > getSwiftDeps ( ) . hasValue ( ) & & <nl> - " Should only call me for Decl nodes . " ) ; <nl> + assert ( definition - > getIsProvides ( ) & & " Should only call me for Decl nodes . " ) ; <nl> <nl> forEachUseOf ( definition , [ & ] ( const ModuleDepGraphNode * u ) { <nl> / / Cycle recording and check . <nl> if ( ! foundDependents . insert ( u ) . second ) <nl> return ; <nl> - if ( u - > getKey ( ) . isInterface ( ) & & u - > getSwiftDeps ( ) . hasValue ( ) ) { <nl> - / / An interface depends on something . Thus , if that something changes <nl> - / / the interface must be recompiled . But if an interface changes , then <nl> - / / anything using that interface must also be recompiled . <nl> - / / So , the job containing the interface " cascades " , in other words <nl> - / / whenever that job gets recompiled , anything depending on it <nl> - / / ( since we don ' t have interface - specific dependency info as of Dec . <nl> - / / 2018 ) must be recompiled . <nl> - rememberThatJobCascades ( u - > getSwiftDeps ( ) . getValue ( ) ) ; <nl> - findDependentNodesAndRecordCascadingOnes ( foundDependents , u ) ; <nl> - } <nl> + / / If this use also provides something , follow it <nl> + if ( u - > getIsProvides ( ) ) <nl> + findDependentNodes ( foundDependents , u ) ; <nl> } ) ; <nl> traceDeparture ( pathLengthAfterArrival ) ; <nl> } <nl> size_t ModuleDepGraph : : traceArrival ( const ModuleDepGraphNode * visitedNode ) { <nl> if ( ! currentPathIfTracing . hasValue ( ) ) <nl> return 0 ; <nl> auto & currentPath = currentPathIfTracing . getValue ( ) ; <nl> - recordDependencyPathToJob ( currentPath , getJob ( visitedNode - > getSwiftDeps ( ) ) ) ; <nl> - <nl> currentPath . push_back ( visitedNode ) ; <nl> + const auto visitedSwiftDepsIfAny = visitedNode - > getSwiftDeps ( ) ; <nl> + recordDependencyPathToJob ( currentPath , getJob ( visitedSwiftDepsIfAny ) ) ; <nl> return currentPath . size ( ) ; <nl> } <nl> <nl> void ModuleDepGraph : : traceDeparture ( size_t pathLengthAfterArrival ) { <nl> currentPath . pop_back ( ) ; <nl> } <nl> <nl> - / / Emitting Dot file for ModuleDepGraph <nl> - / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> + / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> + / / MARK : Emitting Dot file for ModuleDepGraph <nl> + / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> <nl> void ModuleDepGraph : : emitDotFileForJob ( DiagnosticEngine & diags , <nl> const Job * job ) { <nl> void ModuleDepGraph : : emitDotFileForJob ( DiagnosticEngine & diags , <nl> <nl> void ModuleDepGraph : : emitDotFile ( DiagnosticEngine & diags , StringRef baseName ) { <nl> unsigned seqNo = dotFileSequenceNumber [ baseName ] + + ; <nl> - std : : string fullName = baseName . str ( ) + " . " + std : : to_string ( seqNo ) + " . dot " ; <nl> + std : : string fullName = <nl> + baseName . str ( ) + " - post - integration . " + std : : to_string ( seqNo ) + " . dot " ; <nl> withOutputFile ( diags , fullName , [ & ] ( llvm : : raw_ostream & out ) { <nl> emitDotFile ( out ) ; <nl> return false ; <nl> void ModuleDepGraph : : emitDotFile ( llvm : : raw_ostream & out ) { <nl> <nl> void ModuleDepGraphNode : : dump ( ) const { <nl> DepGraphNode : : dump ( ) ; <nl> - if ( getSwiftDeps ( ) . hasValue ( ) ) <nl> - llvm : : errs ( ) < < " swiftDeps : < " < < getSwiftDeps ( ) . getValue ( ) < < " > \ n " ; <nl> + if ( getIsProvides ( ) ) <nl> + llvm : : errs ( ) < < " swiftDeps : < " < < getSwiftDepsOfProvides ( ) < < " > \ n " ; <nl> else <nl> llvm : : errs ( ) < < " no swiftDeps \ n " ; <nl> } <nl> void ModuleDepGraph : : verifyNodeIsUniqueWithinSubgraph ( <nl> assert ( submapIndex < nodesSeenInNodeMap . size ( ) & & <nl> " submapIndex is out of bounds . " ) ; <nl> auto iterInserted = nodesSeenInNodeMap [ submapIndex ] [ n - > getKey ( ) ] . insert ( <nl> - std : : make_pair ( n - > getSwiftDeps ( ) . hasValue ( ) ? n - > getSwiftDeps ( ) . getValue ( ) <nl> - : std : : string ( ) , <nl> - n ) ) ; <nl> + std : : make_pair ( n - > getSwiftDepsForMapKey ( ) , n ) ) ; <nl> if ( ! iterInserted . second ) { <nl> llvm_unreachable ( " duplicate driver keys " ) ; <nl> } <nl> void ModuleDepGraph : : verifyEachJobInGraphIsTracked ( ) const { <nl> } ) ; <nl> } <nl> <nl> - bool ModuleDepGraph : : emitDotFileAndVerify ( DiagnosticEngine & diags ) { <nl> - if ( ! driverDotFileBasePath . empty ( ) ) <nl> - emitDotFile ( diags , driverDotFileBasePath ) ; <nl> - return verify ( ) ; <nl> - } <nl> - <nl> - / / / Dump the path that led to \ p node . <nl> - / / / TODO : make output more like existing system ' s <nl> + / / / Dump the path ( s ) that led to \ p node . <nl> + / / / TODO : break up <nl> void ModuleDepGraph : : printPath ( raw_ostream & out , <nl> const driver : : Job * jobToBeBuilt ) const { <nl> assert ( currentPathIfTracing . hasValue ( ) & & <nl> " Cannot print paths of paths weren ' t tracked . " ) ; <nl> - auto const allPaths = dependencyPathsToJobs . find ( jobToBeBuilt ) ; <nl> - if ( allPaths = = dependencyPathsToJobs . cend ( ) ) <nl> - return ; <nl> - for ( const auto * n : allPaths - > second ) { <nl> - out < < n - > humanReadableName ( ) < < " \ n " ; <nl> + <nl> + for ( auto paths = dependencyPathsToJobs . find ( jobToBeBuilt ) ; <nl> + paths ! = dependencyPathsToJobs . end ( ) & & paths - > first = = jobToBeBuilt ; <nl> + + + paths ) { <nl> + const auto & path = paths - > second ; <nl> + bool first = true ; <nl> + out < < " \ t " ; <nl> + for ( const ModuleDepGraphNode * n : path ) { <nl> + if ( first ) <nl> + first = false ; <nl> + else <nl> + out < < " - > " ; <nl> + <nl> + const StringRef providerName = getProvidingFilename ( n - > getSwiftDeps ( ) ) ; <nl> + printOneNodeOfPath ( out , n - > getKey ( ) , providerName ) ; <nl> + } <nl> + out < < " \ n " ; <nl> + } <nl> + } <nl> + <nl> + StringRef ModuleDepGraph : : getProvidingFilename ( <nl> + const Optional < std : : string > swiftDeps ) const { <nl> + if ( ! swiftDeps ) <nl> + return " < unknown " ; <nl> + const StringRef inputName = <nl> + llvm : : sys : : path : : filename ( getJob ( swiftDeps ) - > getFirstSwiftPrimaryInput ( ) ) ; <nl> + / / FineGrainedDependencyGraphTests work with simulated jobs with empty <nl> + / / input names . <nl> + return ! inputName . empty ( ) ? inputName : StringRef ( swiftDeps . getValue ( ) ) ; <nl> + } <nl> + <nl> + void ModuleDepGraph : : printOneNodeOfPath ( raw_ostream & out , <nl> + const DependencyKey & key , <nl> + const StringRef filename ) { <nl> + switch ( key . getKind ( ) ) { <nl> + case NodeKind : : topLevel : <nl> + out < < key . aspectName ( ) < < " of top - level name ' " < < key . humanReadableName ( ) <nl> + < < " ' in " < < filename ; <nl> + break ; <nl> + case NodeKind : : nominal : <nl> + out < < key . aspectName ( ) < < " of type ' " < < key . humanReadableName ( ) <nl> + < < " ' in " < < filename ; <nl> + break ; <nl> + case NodeKind : : potentialMember : <nl> + out < < key . aspectName ( ) < < " of non - private members ' " <nl> + < < key . humanReadableName ( ) < < " ' in " < < filename ; <nl> + break ; <nl> + case NodeKind : : member : <nl> + out < < key . aspectName ( ) < < " of member ' " < < key . humanReadableName ( ) <nl> + < < " ' in " < < filename ; <nl> + break ; <nl> + case NodeKind : : dynamicLookup : <nl> + out < < key . aspectName ( ) < < " of AnyObject member ' " <nl> + < < key . humanReadableName ( ) < < " ' in " < < filename ; <nl> + break ; <nl> + case NodeKind : : externalDepend : <nl> + out < < filename < < " depends on " < < key . aspectName ( ) < < " of module ' " <nl> + < < key . humanReadableName ( ) < < " ' " ; <nl> + break ; <nl> + case NodeKind : : sourceFileProvide : <nl> + out < < key . aspectName ( ) < < " of source file " < < key . humanReadableName ( ) ; <nl> + break ; <nl> + default : <nl> + llvm_unreachable ( " unknown NodeKind " ) ; <nl> } <nl> - out < < " \ n " ; <nl> } <nl> mmm a / lib / Driver / Job . cpp <nl> ppp b / lib / Driver / Job . cpp <nl> <nl> using namespace swift ; <nl> using namespace swift : : driver ; <nl> <nl> + CommandOutput : : CommandOutput ( StringRef dummyBase , OutputFileMap & dummyOFM ) <nl> + : Inputs ( { CommandInputPair ( dummyBase , " " ) } ) , DerivedOutputMap ( dummyOFM ) { <nl> + setAdditionalOutputForType ( file_types : : TY_SwiftDeps , dummyBase ) ; <nl> + } <nl> + <nl> StringRef CommandOutput : : getOutputForInputAndType ( StringRef PrimaryInputFile , <nl> file_types : : ID Type ) const { <nl> if ( Type = = file_types : : TY_Nothing ) <nl> mmm a / lib / Driver / ToolChain . cpp <nl> ppp b / lib / Driver / ToolChain . cpp <nl> file_types : : ID ToolChain : : lookupTypeForExtension ( StringRef Ext ) const { <nl> return file_types : : lookupTypeForExtension ( Ext ) ; <nl> } <nl> <nl> - / / / Return a _single_ TY_Swift InputAction , if one exists ; <nl> - / / / if 0 or > 1 such inputs exist , return nullptr . <nl> - static const InputAction * findSingleSwiftInput ( const CompileJobAction * CJA ) { <nl> - auto Inputs = CJA - > getInputs ( ) ; <nl> - const InputAction * IA = nullptr ; <nl> - for ( auto const * I : Inputs ) { <nl> - if ( auto const * S = dyn_cast < InputAction > ( I ) ) { <nl> - if ( S - > getType ( ) = = file_types : : TY_Swift ) { <nl> - if ( IA = = nullptr ) { <nl> - IA = S ; <nl> - } else { <nl> - / / Already found one , two is too many . <nl> - return nullptr ; <nl> - } <nl> - } <nl> - } <nl> - } <nl> - return IA ; <nl> - } <nl> - <nl> static bool jobsHaveSameExecutableNames ( const Job * A , const Job * B ) { <nl> / / Jobs that get here ( that are derived from CompileJobActions ) should always <nl> / / have the same executable name - - it should always be SWIFT_EXECUTABLE_NAME <nl> bool ToolChain : : jobIsBatchable ( const Compilation & C , const Job * A ) const { <nl> if ( C . OnlyOneDependencyFile & & <nl> A - > getOutput ( ) . hasAdditionalOutputForType ( file_types : : TY_Dependencies ) ) <nl> return false ; <nl> - return findSingleSwiftInput ( CJActA ) ! = nullptr ; <nl> + return CJActA - > findSingleSwiftInput ( ) ! = nullptr ; <nl> } <nl> <nl> bool ToolChain : : jobsAreBatchCombinable ( const Compilation & C , const Job * A , <nl> mergeBatchInputs ( ArrayRef < const Job * > jobs , <nl> return false ; <nl> } <nl> <nl> - / / / Unfortunately the success or failure of a Swift compilation is currently <nl> - / / / sensitive to the order in which files are processed , at least in terms of <nl> - / / / the order of processing extensions ( and likely other ways we haven ' t <nl> - / / / discovered yet ) . So long as this is true , we need to make sure any batch job <nl> - / / / we build names its inputs in an order that ' s a subsequence of the sequence <nl> - / / / of inputs the driver was initially invoked with . <nl> - static void <nl> - sortJobsToMatchCompilationInputs ( ArrayRef < const Job * > unsortedJobs , <nl> - SmallVectorImpl < const Job * > & sortedJobs , <nl> - Compilation & C ) { <nl> - llvm : : DenseMap < StringRef , const Job * > jobsByInput ; <nl> - for ( const Job * J : unsortedJobs ) { <nl> - const CompileJobAction * CJA = cast < CompileJobAction > ( & J - > getSource ( ) ) ; <nl> - const InputAction * IA = findSingleSwiftInput ( CJA ) ; <nl> - auto R = <nl> - jobsByInput . insert ( std : : make_pair ( IA - > getInputArg ( ) . getValue ( ) , J ) ) ; <nl> - assert ( R . second ) ; <nl> - ( void ) R ; <nl> - } <nl> - for ( const InputPair & P : C . getInputFiles ( ) ) { <nl> - auto I = jobsByInput . find ( P . second - > getValue ( ) ) ; <nl> - if ( I ! = jobsByInput . end ( ) ) { <nl> - sortedJobs . push_back ( I - > second ) ; <nl> - } <nl> - } <nl> - } <nl> - <nl> / / / Construct a \ c BatchJob by merging the constituent \ p jobs ' CommandOutput , <nl> / / / input \ c Job and \ c Action members . Call through to \ c constructInvocation <nl> / / / on \ p BatchJob , to build the \ c InvocationInfo . <nl> ToolChain : : constructBatchJob ( ArrayRef < const Job * > unsortedJobs , <nl> return nullptr ; <nl> <nl> llvm : : SmallVector < const Job * , 16 > sortedJobs ; <nl> - sortJobsToMatchCompilationInputs ( unsortedJobs , sortedJobs , C ) ; <nl> + C . sortJobsToMatchCompilationInputs ( unsortedJobs , sortedJobs ) ; <nl> <nl> / / Synthetic OutputInfo is a slightly - modified version of the initial <nl> / / compilation ' s OI . <nl> mmm a / lib / Driver / ToolChains . cpp <nl> ppp b / lib / Driver / ToolChains . cpp <nl> static void addCommonFrontendArgs ( const ToolChain & TC , const OutputInfo & OI , <nl> inputArgs . AddLastArg ( arguments , options : : OPT_AssumeSingleThreaded ) ; <nl> inputArgs . AddLastArg ( arguments , <nl> options : : OPT_enable_fine_grained_dependencies ) ; <nl> + inputArgs . AddLastArg ( arguments , <nl> + options : : OPT_disable_fine_grained_dependencies ) ; <nl> inputArgs . AddLastArg ( arguments , <nl> options : : OPT_fine_grained_dependency_include_intrafile ) ; <nl> inputArgs . AddLastArg ( arguments , options : : OPT_package_description_version ) ; <nl> void ToolChain : : JobContext : : addFrontendCommandLineInputArguments ( <nl> if ( ( ! isPrimary | | usePrimaryFileList ) & & ! useFileList ) <nl> arguments . push_back ( inputName ) ; <nl> } <nl> + if ( C . getEnableFineGrainedDependencies ( ) ) <nl> + arguments . push_back ( " - enable - fine - grained - dependencies " ) ; <nl> + <nl> + if ( Args . hasArg ( <nl> + options : : OPT_emit_fine_grained_dependency_sourcefile_dot_files ) ) <nl> + arguments . push_back ( " - emit - fine - grained - dependency - sourcefile - dot - files " ) ; <nl> } <nl> <nl> void ToolChain : : JobContext : : addFrontendSupplementaryOutputArguments ( <nl> mmm a / lib / Frontend / CompilerInvocation . cpp <nl> ppp b / lib / Frontend / CompilerInvocation . cpp <nl> static bool ParseLangArgs ( LangOptions & Opts , ArgList & Args , <nl> Opts . BuildSyntaxTree = true ; <nl> Opts . VerifySyntaxTree = true ; <nl> } <nl> - <nl> - if ( Args . hasArg ( OPT_enable_fine_grained_dependencies ) ) <nl> - Opts . EnableFineGrainedDependencies = true ; <nl> + <nl> + Opts . EnableFineGrainedDependencies = <nl> + Args . hasFlag ( options : : OPT_enable_fine_grained_dependencies , <nl> + options : : OPT_disable_fine_grained_dependencies , false ) ; <nl> + <nl> + if ( Args . hasArg ( OPT_emit_fine_grained_dependency_sourcefile_dot_files ) ) <nl> + Opts . EmitFineGrainedDependencySourcefileDotFiles = true ; <nl> <nl> if ( Args . hasArg ( OPT_fine_grained_dependency_include_intrafile ) ) <nl> Opts . FineGrainedDependenciesIncludeIntrafileOnes = true ; <nl> mmm a / lib / FrontendTool / FrontendTool . cpp <nl> ppp b / lib / FrontendTool / FrontendTool . cpp <nl> static void emitReferenceDependenciesForAllPrimaryInputsIfNeeded ( <nl> if ( Invocation . getLangOptions ( ) . EnableFineGrainedDependencies ) <nl> ( void ) fine_grained_dependencies : : emitReferenceDependencies ( <nl> Instance . getASTContext ( ) . Diags , SF , <nl> - * Instance . getDependencyTracker ( ) , referenceDependenciesFilePath ) ; <nl> + * Instance . getDependencyTracker ( ) , referenceDependenciesFilePath , <nl> + Invocation . getLangOptions ( ) <nl> + . EmitFineGrainedDependencySourcefileDotFiles ) ; <nl> else <nl> ( void ) emitReferenceDependencies ( Instance . getASTContext ( ) . Diags , SF , <nl> * Instance . getDependencyTracker ( ) , <nl> mmm a / test / Driver / batch_mode_dependencies_make_wrong_order . swift <nl> ppp b / test / Driver / batch_mode_dependencies_make_wrong_order . swift <nl> <nl> / / RUN : cd % t & & % swiftc_driver - enable - batch - mode - incremental - output - file - map % S / Inputs / abcd_filemap . yaml - module - name main - j 1 d . swift c . swift b . swift a . swift main . swift - driver - show - incremental - driver - show - job - lifecycle > % t / out . txt 2 > & 1 <nl> / / RUN : % FileCheck % s < % t / out . txt <nl> / / <nl> - / / Check that we saw invalidation happen in alphabetic order <nl> - / / CHECK : Queuing because of dependencies discovered later : { compile : b . o < = b . swift } <nl> - / / CHECK : Queuing because of dependencies discovered later : { compile : c . o < = c . swift } <nl> + / / Check that we saw invalidation happen in command - line argument order <nl> / / CHECK : Queuing because of dependencies discovered later : { compile : d . o < = d . swift } <nl> - / / CHECK : Batchable : { compile : b . o < = b . swift } <nl> - / / CHECK : Batchable : { compile : c . o < = c . swift } <nl> + / / CHECK : Queuing because of dependencies discovered later : { compile : c . o < = c . swift } <nl> + / / CHECK : Queuing because of dependencies discovered later : { compile : b . o < = b . swift } <nl> / / CHECK : Batchable : { compile : d . o < = d . swift } <nl> + / / CHECK : Batchable : { compile : c . o < = c . swift } <nl> + / / CHECK : Batchable : { compile : b . o < = b . swift } <nl> / / <nl> - / / But check that we still issued the job in reverse - alphabetic order <nl> + / / Check that we still issued the job in reverse - alphabetic order <nl> / / CHECK : Adding batch job to task queue : { compile : d . o c . o b . o < = d . swift c . swift b . swift } <nl>
|
Fine - grained and driver fixes .
|
apple/swift
|
cc89dad5265e104968542ae18a26c1255f7d0cfe
|
2020-01-12T05:57:14Z
|
mmm a / src / node / examples / pubsub / pubsub_demo . js <nl> ppp b / src / node / examples / pubsub / pubsub_demo . js <nl> <nl> / / ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE <nl> / / OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE . <nl> <nl> + ' use strict ' ; <nl> + <nl> var async = require ( ' async ' ) ; <nl> var fs = require ( ' fs ' ) ; <nl> var GoogleAuth = require ( ' googleauth ' ) ; <nl> function main ( callback ) { <nl> <nl> if ( require . main = = = module ) { <nl> main ( function ( err ) { <nl> - if ( err ) throw err ; <nl> + if ( err ) { <nl> + throw err ; <nl> + } <nl> } ) ; <nl> } <nl> <nl> mmm a / src / node / examples / route_guide_client . js <nl> ppp b / src / node / examples / route_guide_client . js <nl> <nl> / / ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE <nl> / / OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE . <nl> <nl> + ' use strict ' ; <nl> + <nl> var async = require ( ' async ' ) ; <nl> var fs = require ( ' fs ' ) ; <nl> var parseArgs = require ( ' minimist ' ) ; <nl> function runRecordRoute ( callback ) { <nl> string : ' db_path ' <nl> } ) ; <nl> fs . readFile ( path . resolve ( argv . db_path ) , function ( err , data ) { <nl> - if ( err ) callback ( err ) ; <nl> + if ( err ) { <nl> + callback ( err ) ; <nl> + } <nl> var feature_list = JSON . parse ( data ) ; <nl> <nl> var num_points = 10 ; <nl> mmm a / src / node / examples / route_guide_server . js <nl> ppp b / src / node / examples / route_guide_server . js <nl> <nl> / / ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE <nl> / / OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE . <nl> <nl> + ' use strict ' ; <nl> + <nl> var fs = require ( ' fs ' ) ; <nl> var parseArgs = require ( ' minimist ' ) ; <nl> var path = require ( ' path ' ) ; <nl> function recordRoute ( call , callback ) { <nl> } <nl> / * For each point after the first , add the incremental distance from the <nl> * previous point to the total distance value * / <nl> - if ( previous ! = null ) { <nl> + if ( previous ! = = null ) { <nl> distance + = getDistance ( previous , point ) ; <nl> } <nl> previous = point ; <nl> function recordRoute ( call , callback ) { <nl> point_count : point_count , <nl> feature_count : feature_count , <nl> / / Cast the distance to an integer <nl> - distance : distance | 0 , <nl> + distance : Math . floor ( distance ) , <nl> / / End the timer <nl> elapsed_time : process . hrtime ( start_time ) [ 0 ] <nl> } ) ; <nl> if ( require . main = = = module ) { <nl> string : ' db_path ' <nl> } ) ; <nl> fs . readFile ( path . resolve ( argv . db_path ) , function ( err , data ) { <nl> - if ( err ) throw err ; <nl> + if ( err ) { <nl> + throw err ; <nl> + } <nl> feature_list = JSON . parse ( data ) ; <nl> routeServer . listen ( ) ; <nl> } ) ; <nl>
|
Merge pull request from murgatroid99 / node_fix_lint
|
grpc/grpc
|
a29a1223d7371bcbb2c2ee5045c8901798a26704
|
2015-02-24T17:07:17Z
|
mmm a / src / python / grpcio_tests / tests_aio / unit / server_test . py <nl> ppp b / src / python / grpcio_tests / tests_aio / unit / server_test . py <nl> async def _stream_stream_evilly_mixed ( self , request_iterator , context ) : <nl> <nl> def service ( self , handler_details ) : <nl> self . _called . set_result ( None ) <nl> - return self . _routing_table [ handler_details . method ] <nl> + return self . _routing_table . get ( handler_details . method ) <nl> <nl> async def wait_for_call ( self ) : <nl> await self . _called <nl> async def test_shutdown_before_call ( self ) : <nl> await channel . unary_unary ( _SIMPLE_UNARY_UNARY ) ( _REQUEST ) <nl> <nl> async def test_unimplemented ( self ) : <nl> - async with aio . insecure_channel ( self . _server_target ) as channel : <nl> - call = channel . unary_unary ( _UNIMPLEMENTED_METHOD ) <nl> - with self . assertRaises ( aio . AioRpcError ) as exception_context : <nl> - await call ( _REQUEST ) <nl> - rpc_error = exception_context . exception <nl> - self . assertEqual ( grpc . StatusCode . UNIMPLEMENTED , rpc_error . code ( ) ) <nl> + call = self . _channel . unary_unary ( _UNIMPLEMENTED_METHOD ) <nl> + with self . assertRaises ( aio . AioRpcError ) as exception_context : <nl> + await call ( _REQUEST ) <nl> + rpc_error = exception_context . exception <nl> + self . assertEqual ( grpc . StatusCode . UNIMPLEMENTED , rpc_error . code ( ) ) <nl> <nl> <nl> if __name__ = = ' __main__ ' : <nl>
|
Fix the breakage due to conflict
|
grpc/grpc
|
c6a97f125adec89eaa1204eb76fed455545b98dd
|
2020-01-15T19:30:58Z
|
mmm a / aten / src / ATen / native / ChanelShuffle . cpp <nl> ppp b / aten / src / ATen / native / ChanelShuffle . cpp <nl> <nl> <nl> # include < ATen / NamedTensorUtils . h > <nl> # include < ATen / NativeFunctions . h > <nl> + # if defined ( C10_MOBILE ) & & defined ( USE_XNNPACK ) <nl> + # include < ATen / native / xnnpack / Engine . h > <nl> + # endif <nl> # include < c10 / util / Exception . h > <nl> <nl> # include < algorithm > <nl> Tensor channel_shuffle ( const Tensor & self , int64_t groups ) { <nl> AT_ASSERTM ( ( c % groups ) = = 0 , <nl> " Number of channels must be divisible by groups . Got " , <nl> c , " channels and " , groups , " groups . " ) ; <nl> + <nl> + # if defined ( C10_MOBILE ) & & defined ( USE_XNNPACK ) <nl> + if ( self . is_contiguous ( MemoryFormat : : ChannelsLast ) & & <nl> + xnnpack : : use_channel_shuffle ( self , groups ) ) { <nl> + return xnnpack : : channel_shuffle ( self , groups ) ; <nl> + } <nl> + # endif <nl> + <nl> int64_t oc = c / groups ; <nl> <nl> auto input_reshaped = self . view ( { b , groups , oc , - 1 } ) ; <nl> new file mode 100644 <nl> index 000000000000 . . 036f53abcc23 <nl> mmm / dev / null <nl> ppp b / aten / src / ATen / native / xnnpack / ChannelShuffle . cpp <nl> <nl> + # ifdef USE_XNNPACK <nl> + <nl> + # include < ATen / native / xnnpack / Common . h > <nl> + # include < ATen / native / utils / Factory . h > <nl> + <nl> + namespace at { <nl> + namespace native { <nl> + namespace xnnpack { <nl> + <nl> + bool use_channel_shuffle ( <nl> + const Tensor & input , <nl> + const int64_t groups ) { <nl> + using namespace internal ; <nl> + <nl> + / / Here are the list of conditions required for this code path to be taken : <nl> + / / * Input must be 4D CPU float tensor with no gradients and <nl> + / / and all dimensions must be positive . <nl> + / / * The number of groups must be larger than 1 and <nl> + / / the number of channels must be divisible by the number of groups . <nl> + return xnnpack : : internal : : available ( ) & & <nl> + / / Input <nl> + ( 4 = = input . dim ( ) ) & & <nl> + ( c10 : : DeviceType : : CPU = = input . device ( ) . type ( ) ) & & <nl> + ( kFloat = = input . scalar_type ( ) ) & & <nl> + ( input . size ( Layout : : Activation4D : : batch ) > = 0 ) & & <nl> + ( input . size ( Layout : : Activation4D : : channels ) > 0 ) & & <nl> + ( input . size ( Layout : : Activation4D : : height ) > 0 ) & & <nl> + ( input . size ( Layout : : Activation4D : : width ) > 0 ) & & <nl> + ! input . requires_grad ( ) & & <nl> + / / Groups <nl> + groups > 1 & & <nl> + ( 0 = = input . size ( Layout : : Activation4D : : channels ) % groups ) & & <nl> + true ; <nl> + } <nl> + <nl> + Tensor channel_shuffle ( <nl> + const Tensor & input , <nl> + const int64_t groups ) { <nl> + using namespace internal ; <nl> + <nl> + / / A call to channel_shuffle must have been gated by a call to use_channel_shuffle , <nl> + / / so the parameters are guaranteed to be valid at this point . <nl> + <nl> + const Tensor input_padded_contig_nhwc = <nl> + mobile : : allocate_padded_contiguous_if_needed ( <nl> + input , <nl> + MemoryFormat : : ChannelsLast ) ; <nl> + <nl> + Tensor output_padded_contig_nhwc = mobile : : empty_with_tail_padding ( <nl> + { <nl> + input_padded_contig_nhwc . size ( Layout : : Activation4D : : batch ) , <nl> + input_padded_contig_nhwc . size ( Layout : : Activation4D : : channels ) , <nl> + input_padded_contig_nhwc . size ( Layout : : Activation4D : : height ) , <nl> + input_padded_contig_nhwc . size ( Layout : : Activation4D : : width ) , <nl> + } , <nl> + input_padded_contig_nhwc . options ( ) . dtype ( ) , <nl> + MemoryFormat : : ChannelsLast , <nl> + input_padded_contig_nhwc . names ( ) ) ; <nl> + <nl> + int64_t channels_per_group = <nl> + input_padded_contig_nhwc . size ( Layout : : Activation4D : : channels ) / groups ; <nl> + <nl> + xnn_operator_t channel_shuffle_op { } ; <nl> + <nl> + const xnn_status create_status = xnn_create_channel_shuffle_nc_x32 ( <nl> + groups , / / number of groups <nl> + channels_per_group , / / number of channels per group <nl> + input_padded_contig_nhwc . size ( Layout : : Activation4D : : channels ) , / / input_pixel_stride - NHWC Contiguous <nl> + output_padded_contig_nhwc . size ( Layout : : Activation4D : : channels ) , / / output_pixel_stride - NHWC Contiguous <nl> + 0u , / / flags <nl> + & channel_shuffle_op ) ; / / operator <nl> + <nl> + Operator channel_shuffle_scoped_op ( channel_shuffle_op ) ; <nl> + <nl> + TORCH_CHECK ( <nl> + xnn_status_success = = create_status , <nl> + " xnn_create_channel_shuffle_nc_x32 failed ! " ) ; <nl> + <nl> + int64_t batch_size = input_padded_contig_nhwc . size ( Layout : : Activation4D : : batch ) * <nl> + input_padded_contig_nhwc . size ( Layout : : Activation4D : : height ) * <nl> + input_padded_contig_nhwc . size ( Layout : : Activation4D : : width ) ; <nl> + <nl> + const xnn_status setup_status = xnn_setup_channel_shuffle_nc_x32 ( <nl> + channel_shuffle_op , / / operator <nl> + batch_size , / / batch_size <nl> + input_padded_contig_nhwc . data_ptr < float > ( ) , / / input <nl> + output_padded_contig_nhwc . data_ptr < float > ( ) , / / output <nl> + caffe2 : : pthreadpool_ ( ) ) ; / / threadpool <nl> + <nl> + TORCH_CHECK ( <nl> + xnn_status_success = = setup_status , <nl> + " xnn_setup_channel_shuffle_nc_x32 failed ! " ) ; <nl> + <nl> + const xnn_status run_status = xnn_run_operator ( <nl> + channel_shuffle_op , / / operator <nl> + caffe2 : : pthreadpool_ ( ) ) ; / / threadpool <nl> + <nl> + TORCH_INTERNAL_ASSERT ( <nl> + xnn_status_success = = run_status , <nl> + " xnn_run_operator failed ! " ) ; <nl> + <nl> + return output_padded_contig_nhwc . contiguous ( input . suggest_memory_format ( ) ) ; <nl> + } <nl> + <nl> + } / / namespace xnnpack <nl> + } / / namespace native <nl> + } / / namespace at <nl> + <nl> + # endif / * USE_XNNPACK * / <nl> mmm a / aten / src / ATen / native / xnnpack / Engine . h <nl> ppp b / aten / src / ATen / native / xnnpack / Engine . h <nl> Tensor max_pool2d ( <nl> float output_min = - std : : numeric_limits < float > : : infinity ( ) , <nl> float output_max = + std : : numeric_limits < float > : : infinity ( ) ) ; <nl> <nl> + / / <nl> + / / Channel Shuffle <nl> + / / <nl> + <nl> + bool use_channel_shuffle ( <nl> + const Tensor & input , <nl> + const int64_t groups ) ; <nl> + <nl> + Tensor channel_shuffle ( <nl> + const Tensor & input , <nl> + const int64_t groups ) ; <nl> + <nl> } / / namespace xnnpack <nl> } / / namespace native <nl> } / / namespace at <nl>
|
Implement ChannelShuffle op with XNNPACK ( )
|
pytorch/pytorch
|
a6789074fce4589ef6b81817b56663b585f377ec
|
2020-09-02T16:18:25Z
|
mmm a / hphp / hack / src / typing / typing_async . ml <nl> ppp b / hphp / hack / src / typing / typing_async . ml <nl> let overload_extract_from_awaitable env ~ p opt_ty_maybe = <nl> ( * We want to try to avoid easy double nullables here , so we handle Toption <nl> * with some special logic . * ) <nl> let env , ty = extract_inner env ty in <nl> - let env , ty = TUtils . non_null env p ty in <nl> - env , ( r , Toption ty ) <nl> + TUtils . union env ( MakeType . null r ) ty <nl> | _ , Tintersection tyl - > <nl> let env , rtyl = List . fold_map ~ init : env tyl ~ f : extract_inner in <nl> env , ( r , Tintersection rtyl ) <nl> mmm a / hphp / hack / test / typecheck / double_nullable_through_await . php . exp <nl> ppp b / hphp / hack / test / typecheck / double_nullable_through_await . php . exp <nl> <nl> File " double_nullable_through_await . php " , line 18 , characters 3 - 15 : <nl> - ? Foo <nl> + ? ? Foo <nl> No errors <nl>
|
remove usage of non_null in typing of await
|
facebook/hhvm
|
a9f6ebba213a2fed7bc0da1b6a9cb99535e86635
|
2019-07-08T17:36:41Z
|
mmm a / lib / IDE / Formatting . cpp <nl> ppp b / lib / IDE / Formatting . cpp <nl> class FormatWalker : public SourceEntityWalker { <nl> / / FIXME : We are going to revisit the behavior and the indentation we <nl> / / want for dictionary / array literals . <nl> / / <nl> - / * SourceLoc LBracketLoc = AE - > getLBracketLoc ( ) ; <nl> + # ifdef 0 <nl> + SourceLoc LBracketLoc = AE - > getLBracketLoc ( ) ; <nl> if ( isTargetImmediateAfter ( LBracketLoc ) & & <nl> ! sameLineWithTarget ( LBracketLoc ) ) { <nl> FoundSibling = LBracketLoc ; <nl> NeedExtraIndentation = true ; <nl> - } * / <nl> + } <nl> + # endif <nl> for ( unsigned I = 0 , N = AE - > getNumElements ( ) ; I < N ; I + + ) { <nl> addPair ( AE - > getElement ( I ) - > getEndLoc ( ) , <nl> FindAlignLoc ( AE - > getElement ( I ) - > getStartLoc ( ) ) , tok : : comma ) ; <nl> } <nl> } <nl> - <nl> / / Case label items in a case statement are siblings . <nl> if ( auto CS = dyn_cast_or_null < CaseStmt > ( Node . dyn_cast < Stmt * > ( ) ) ) { <nl> for ( const CaseLabelItem & Item : CS - > getCaseLabelItems ( ) ) { <nl>
|
Merge pull request from practicalswift / remove - commented - out - code
|
apple/swift
|
20c5f53372385717785b6f4b9427fbfa602574f5
|
2016-06-05T19:06:20Z
|
mmm a / editor / plugins / node_3d_editor_plugin . cpp <nl> ppp b / editor / plugins / node_3d_editor_plugin . cpp <nl> void Node3DEditorViewport : : _notification ( int p_what ) { <nl> } <nl> <nl> Transform t = sp - > get_global_gizmo_transform ( ) ; <nl> + VisualInstance3D * vi = Object : : cast_to < VisualInstance3D > ( sp ) ; <nl> + AABB new_aabb = vi ? vi - > get_aabb ( ) : _calculate_spatial_bounds ( sp ) ; <nl> <nl> exist = true ; <nl> - if ( se - > last_xform = = t & & ! se - > last_xform_dirty ) { <nl> + if ( se - > last_xform = = t & & se - > aabb = = new_aabb & & ! se - > last_xform_dirty ) { <nl> continue ; <nl> } <nl> changed = true ; <nl> se - > last_xform_dirty = false ; <nl> se - > last_xform = t ; <nl> <nl> - VisualInstance3D * vi = Object : : cast_to < VisualInstance3D > ( sp ) ; <nl> - <nl> - se - > aabb = vi ? vi - > get_aabb ( ) : _calculate_spatial_bounds ( sp ) ; <nl> + se - > aabb = new_aabb ; <nl> <nl> t . translate ( se - > aabb . position ) ; <nl> <nl>
|
Merge pull request from DavidSichma / fix - aabb - update
|
godotengine/godot
|
ca2c0b8937d287e608448a9a5ba553a8deaf46d9
|
2020-10-10T08:55:52Z
|
mmm a / src / rdb_protocol / query_cache . cc <nl> ppp b / src / rdb_protocol / query_cache . cc <nl> query_id_t : : query_id_t ( query_cache_t * _parent ) : <nl> } <nl> <nl> query_id_t : : ~ query_id_t ( ) { <nl> - parent - > assert_thread ( ) ; <nl> + if ( parent ! = nullptr ) { <nl> + parent - > assert_thread ( ) ; <nl> + } else { <nl> + rassert ( ! in_a_list ( ) ) ; <nl> + } <nl> + <nl> if ( in_a_list ( ) ) { <nl> parent - > outstanding_query_ids . remove ( this ) ; <nl> if ( value_ = = parent - > oldest_outstanding_query_id . get ( ) ) { <nl>
|
fixing assert in ~ query_id_t ( )
|
rethinkdb/rethinkdb
|
90a8ee6a1572ece68b3fbc9932f23a5eb40c865c
|
2015-02-13T23:35:01Z
|
mmm a / dbms / tests / queries / 0_stateless / 01030_limit_by_with_ties_error . sh <nl> ppp b / dbms / tests / queries / 0_stateless / 01030_limit_by_with_ties_error . sh <nl> $ CLICKHOUSE_CLIENT - - query = " SELECT * FROM VALUES ( ' Phrase String , Payload String ' <nl> $ CLICKHOUSE_CLIENT - - query = " SELECT * FROM VALUES ( ' Phrase String , Payload String ' , ( ' hello ' , ' x ' ) , ( ' world ' , ' x ' ) , ( ' hello ' , ' z ' ) , ( ' upyachka ' , ' a ' ) , ( ' test ' , ' b ' ) , ( ' foo ' , ' c ' ) , ( ' bar ' , ' d ' ) ) ORDER BY Payload LIMIT 1 BY Phrase LIMIT 5 WITH TIES " <nl> <nl> $ CLICKHOUSE_CLIENT - - query = " SELECT TOP 5 WITH TIES * FROM VALUES ( ' Phrase String , Payload String ' , ( ' hello ' , ' x ' ) , ( ' world ' , ' x ' ) , ( ' hello ' , ' z ' ) , ( ' upyachka ' , ' a ' ) , ( ' test ' , ' b ' ) , ( ' foo ' , ' c ' ) , ( ' bar ' , ' d ' ) ) ORDER BY Payload LIMIT 1 BY Phrase " <nl> - <nl>
|
empty commit
|
ClickHouse/ClickHouse
|
797820a99399af86ee17f62043bb50397dc8dac2
|
2019-11-15T12:44:09Z
|
mmm a / dbms / include / DB / IO / WriteBufferValidUTF8 . h <nl> ppp b / dbms / include / DB / IO / WriteBufferValidUTF8 . h <nl> namespace DB <nl> } <nl> else <nl> { <nl> - / / / Невалидная последовательность . Пропустим ее всю . <nl> + / / / Невалидная последовательность . Пропустим только первый байт . <nl> putValid ( valid_start , p - valid_start ) ; <nl> putReplacement ( ) ; <nl> - p + = len ; <nl> + + + p ; <nl> valid_start = p ; <nl> } <nl> } <nl> namespace DB <nl> static const size_t DEFAULT_SIZE ; <nl> <nl> WriteBufferValidUTF8 ( DB : : WriteBuffer & output_buffer , bool group_replacements = true , const char * replacement = " \ xEF \ xBF \ xBD " , size_t size = DEFAULT_SIZE ) <nl> - : BufferWithOwnMemory < DB : : WriteBuffer > ( size ) , output_buffer ( output_buffer ) , <nl> + : BufferWithOwnMemory < DB : : WriteBuffer > ( std : : max ( 4LU , size ) ) , output_buffer ( output_buffer ) , <nl> group_replacements ( group_replacements ) , just_put_replacement ( false ) , replacement ( replacement ) { } <nl> <nl> virtual ~ WriteBufferValidUTF8 ( ) <nl> new file mode 100644 <nl> index 00000000000 . . 9a9f6016cff <nl> mmm / dev / null <nl> ppp b / dbms / src / IO / tests / valid_utf8 . cpp <nl> <nl> + # include < DB / IO / WriteBufferValidUTF8 . h > <nl> + # include < DB / IO / WriteBufferFromString . h > <nl> + # include < DB / IO / ReadHelpers . h > <nl> + # include < DB / IO / WriteHelpers . h > <nl> + # include < string > <nl> + # include < streambuf > <nl> + # include < iostream > <nl> + # include < cstdio > <nl> + <nl> + int main ( int argc , char * * argv ) <nl> + { <nl> + try <nl> + { <nl> + std : : string test1 = " kjhsgdfkjhg2378rtzgvxkz877 % ^ & ^ * % & ^ * & * " ; <nl> + std : : string test2 = " { \ " asd \ " = \ " qw1 \ " , \ " qwe24 \ " = \ " 3asd \ " } " ; <nl> + test2 [ test2 . find ( " 1 " ) ] = 127 + 64 ; <nl> + test2 [ test2 . find ( " 2 " ) ] = 127 + 64 + 32 ; <nl> + test2 [ test2 . find ( " 3 " ) ] = 127 + 64 + 32 + 16 ; <nl> + test2 [ test2 . find ( " 4 " ) ] = 127 + 64 + 32 + 16 + 8 ; <nl> + <nl> + std : : string str ; <nl> + { <nl> + DB : : WriteBufferFromString str_buf ( str ) ; <nl> + { <nl> + DB : : WriteBufferValidUTF8 utf_buf ( str_buf , true , " - " ) ; <nl> + DB : : writeEscapedString ( test1 , utf_buf ) ; <nl> + } <nl> + } <nl> + std : : cout < < str < < std : : endl ; <nl> + <nl> + str = " " ; <nl> + { <nl> + DB : : WriteBufferFromString str_buf ( str ) ; <nl> + { <nl> + DB : : WriteBufferValidUTF8 utf_buf ( str_buf , true , " - " ) ; <nl> + DB : : writeEscapedString ( test2 , utf_buf ) ; <nl> + } <nl> + } <nl> + std : : cout < < str < < std : : endl ; <nl> + } <nl> + catch ( const DB : : Exception & e ) <nl> + { <nl> + std : : cerr < < e . what ( ) < < " , " < < e . displayText ( ) < < std : : endl ; <nl> + return 1 ; <nl> + } <nl> + <nl> + return 0 ; <nl> + } <nl>
|
dbms : fixed WriteBufferValidUTF8 skipping too many characters , added test for it [ # CONV - 5902 ] .
|
ClickHouse/ClickHouse
|
940f9881b882818a82d9c84410e8ed21f9f95691
|
2012-11-16T09:42:48Z
|
mmm a / scene / resources / tile_set . cpp <nl> ppp b / scene / resources / tile_set . cpp <nl> void TileSet : : _bind_methods ( ) { <nl> ClassDB : : bind_method ( D_METHOD ( " tile_get_shape_count " , " id " ) , & TileSet : : tile_get_shape_count ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " tile_set_shapes " , " id " , " shapes " ) , & TileSet : : _tile_set_shapes ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " tile_get_shapes " , " id " ) , & TileSet : : _tile_get_shapes ) ; <nl> + ClassDB : : bind_method ( D_METHOD ( " tile_set_tile_mode " , " id " , " tilemode " ) , & TileSet : : tile_set_tile_mode ) ; <nl> + ClassDB : : bind_method ( D_METHOD ( " tile_get_tile_mode " , " id " ) , & TileSet : : tile_get_tile_mode ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " tile_set_navigation_polygon " , " id " , " navigation_polygon " ) , & TileSet : : tile_set_navigation_polygon ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " tile_get_navigation_polygon " , " id " ) , & TileSet : : tile_get_navigation_polygon ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " tile_set_navigation_polygon_offset " , " id " , " navigation_polygon_offset " ) , & TileSet : : tile_set_navigation_polygon_offset ) ; <nl> void TileSet : : _bind_methods ( ) { <nl> BIND_ENUM_CONSTANT ( BIND_BOTTOMLEFT ) ; <nl> BIND_ENUM_CONSTANT ( BIND_BOTTOM ) ; <nl> BIND_ENUM_CONSTANT ( BIND_BOTTOMRIGHT ) ; <nl> + <nl> + BIND_ENUM_CONSTANT ( SINGLE_TILE ) ; <nl> + BIND_ENUM_CONSTANT ( AUTO_TILE ) ; <nl> + BIND_ENUM_CONSTANT ( ANIMATED_TILE ) ; <nl> } <nl> <nl> TileSet : : TileSet ( ) { <nl> mmm a / scene / resources / tile_set . h <nl> ppp b / scene / resources / tile_set . h <nl> class TileSet : public Resource { <nl> <nl> VARIANT_ENUM_CAST ( TileSet : : AutotileBindings ) ; <nl> VARIANT_ENUM_CAST ( TileSet : : BitmaskMode ) ; <nl> + VARIANT_ENUM_CAST ( TileSet : : TileMode ) ; <nl> <nl> # endif / / TILE_SET_H <nl>
|
Merge pull request from AlexHolly / master
|
godotengine/godot
|
0ee72fbd30b25ff397b570294c3cd2f65c176e34
|
2018-04-09T00:44:07Z
|
mmm a / src / json . hpp <nl> ppp b / src / json . hpp <nl> <nl> | | | __ | | | | | | version 2 . 0 . 0 <nl> | _____ | _____ | _____ | _ | ___ | https : / / github . com / nlohmann / json <nl> <nl> - Copyright ( c ) 2013 - 2016 Niels Lohmann < http : / / nlohmann . me > . <nl> Licensed under the MIT License < http : / / opensource . org / licenses / MIT > . <nl> + Copyright ( c ) 2013 - 2016 Niels Lohmann < http : / / nlohmann . me > . <nl> + <nl> + Permission is hereby granted , free of charge , to any person obtaining a copy <nl> + of this software and associated documentation files ( the " Software " ) , to deal <nl> + in the Software without restriction , including without limitation the rights <nl> + to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> + copies of the Software , and to permit persons to whom the Software is <nl> + furnished to do so , subject to the following conditions : <nl> + <nl> + The above copyright notice and this permission notice shall be included in all <nl> + copies or substantial portions of the Software . <nl> + <nl> + THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> + IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> + LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE <nl> + SOFTWARE . <nl> * / <nl> <nl> # ifndef NLOHMANN_JSON_HPP <nl> mmm a / src / json . hpp . re2c <nl> ppp b / src / json . hpp . re2c <nl> <nl> | | | __ | | | | | | version 2 . 0 . 0 <nl> | _____ | _____ | _____ | _ | ___ | https : / / github . com / nlohmann / json <nl> <nl> - Copyright ( c ) 2013 - 2016 Niels Lohmann < http : / / nlohmann . me > . <nl> Licensed under the MIT License < http : / / opensource . org / licenses / MIT > . <nl> + Copyright ( c ) 2013 - 2016 Niels Lohmann < http : / / nlohmann . me > . <nl> + <nl> + Permission is hereby granted , free of charge , to any person obtaining a copy <nl> + of this software and associated documentation files ( the " Software " ) , to deal <nl> + in the Software without restriction , including without limitation the rights <nl> + to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> + copies of the Software , and to permit persons to whom the Software is <nl> + furnished to do so , subject to the following conditions : <nl> + <nl> + The above copyright notice and this permission notice shall be included in all <nl> + copies or substantial portions of the Software . <nl> + <nl> + THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> + IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> + LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE <nl> + SOFTWARE . <nl> * / <nl> <nl> # ifndef NLOHMANN_JSON_HPP <nl> mmm a / test / unit . cpp <nl> ppp b / test / unit . cpp <nl> <nl> | | | __ | | | | | | version 2 . 0 . 0 <nl> | _____ | _____ | _____ | _ | ___ | https : / / github . com / nlohmann / json <nl> <nl> - Copyright ( c ) 2013 - 2016 Niels Lohmann < http : / / nlohmann . me > . <nl> Licensed under the MIT License < http : / / opensource . org / licenses / MIT > . <nl> + Copyright ( c ) 2013 - 2016 Niels Lohmann < http : / / nlohmann . me > . <nl> + <nl> + Permission is hereby granted , free of charge , to any person obtaining a copy <nl> + of this software and associated documentation files ( the " Software " ) , to deal <nl> + in the Software without restriction , including without limitation the rights <nl> + to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> + copies of the Software , and to permit persons to whom the Software is <nl> + furnished to do so , subject to the following conditions : <nl> + <nl> + The above copyright notice and this permission notice shall be included in all <nl> + copies or substantial portions of the Software . <nl> + <nl> + THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> + IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> + LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE <nl> + SOFTWARE . <nl> * / <nl> <nl> # define CATCH_CONFIG_MAIN <nl>
|
added copyright information to files to make release more self - contained
|
nlohmann/json
|
2f63e5fb4544a1c743810358c24d9edb217dc032
|
2016-03-25T16:41:36Z
|
mmm a / libraries / chain / authorization_manager . cpp <nl> ppp b / libraries / chain / authorization_manager . cpp <nl> namespace eosio { namespace chain { <nl> void authorization_manager : : read_from_snapshot ( const snapshot_reader_ptr & snapshot ) { <nl> authorization_index_set : : walk_indices ( [ this , & snapshot ] ( auto utils ) { <nl> snapshot - > read_section < typename decltype ( utils ) : : index_t : : value_type > ( [ this ] ( auto & section ) { <nl> - bool done = section . empty ( ) ; <nl> - while ( ! done ) { <nl> - decltype ( utils ) : : create ( _db , [ & section ] ( auto & row ) { <nl> - section . read_row ( row ) ; <nl> + bool more = ! section . empty ( ) ; <nl> + while ( more ) { <nl> + decltype ( utils ) : : create ( _db , [ & section , & more ] ( auto & row ) { <nl> + more = section . read_row ( row ) ; <nl> } ) ; <nl> } <nl> } ) ; <nl> mmm a / libraries / chain / block_log . cpp <nl> ppp b / libraries / chain / block_log . cpp <nl> <nl> <nl> namespace eosio { namespace chain { <nl> <nl> - const uint32_t block_log : : supported_version = 1 ; <nl> + const uint32_t block_log : : min_supported_version = 1 ; <nl> + <nl> + / * * <nl> + * History : <nl> + * Version 1 : complete block log from genesis <nl> + * Version 2 : adds optional partial block log , cannot be used for replay without snapshot <nl> + * this is in the form of an first_block_num that is written immediately after the version <nl> + * / <nl> + const uint32_t block_log : : max_supported_version = 2 ; <nl> <nl> namespace detail { <nl> class block_log_impl { <nl> namespace eosio { namespace chain { <nl> bool block_write ; <nl> bool index_write ; <nl> bool genesis_written_to_block_log = false ; <nl> + uint32_t version = 0 ; <nl> + uint32_t first_block_num = 0 ; <nl> <nl> inline void check_block_read ( ) { <nl> if ( block_write ) { <nl> namespace eosio { namespace chain { <nl> ilog ( " Log is nonempty " ) ; <nl> my - > check_block_read ( ) ; <nl> my - > block_stream . seekg ( 0 ) ; <nl> - uint32_t version = 0 ; <nl> - my - > block_stream . read ( ( char * ) & version , sizeof ( version ) ) ; <nl> - EOS_ASSERT ( version > 0 , block_log_exception , " Block log was not setup properly with genesis information . " ) ; <nl> - EOS_ASSERT ( version = = block_log : : supported_version , block_log_unsupported_version , <nl> - " Unsupported version of block log . Block log version is $ { version } while code supports version $ { supported } " , <nl> - ( " version " , version ) ( " supported " , block_log : : supported_version ) ) ; <nl> + my - > version = 0 ; <nl> + my - > block_stream . read ( ( char * ) & my - > version , sizeof ( my - > version ) ) ; <nl> + EOS_ASSERT ( my - > version > 0 , block_log_exception , " Block log was not setup properly " ) ; <nl> + EOS_ASSERT ( my - > version > = min_supported_version & & my - > version < = max_supported_version , block_log_unsupported_version , <nl> + " Unsupported version of block log . Block log version is $ { version } while code supports version ( s ) [ $ { min } , $ { max } ] " , <nl> + ( " version " , my - > version ) ( " min " , block_log : : min_supported_version ) ( " max " , block_log : : max_supported_version ) ) ; <nl> + <nl> <nl> my - > genesis_written_to_block_log = true ; / / Assume it was constructed properly . <nl> + if ( my - > version > 1 ) { <nl> + my - > first_block_num = 0 ; <nl> + my - > block_stream . read ( ( char * ) & my - > first_block_num , sizeof ( my - > first_block_num ) ) ; <nl> + EOS_ASSERT ( my - > first_block_num > 0 , block_log_exception , " Block log is malformed , first recorded block number is 0 but must be greater than or equal to 1 " ) ; <nl> + } <nl> + <nl> my - > head = read_head ( ) ; <nl> my - > head_id = my - > head - > id ( ) ; <nl> <nl> namespace eosio { namespace chain { <nl> my - > check_index_write ( ) ; <nl> <nl> uint64_t pos = my - > block_stream . tellp ( ) ; <nl> - EOS_ASSERT ( my - > index_stream . tellp ( ) = = sizeof ( uint64_t ) * ( b - > block_num ( ) - 1 ) , <nl> + EOS_ASSERT ( my - > index_stream . tellp ( ) = = sizeof ( uint64_t ) * ( b - > block_num ( ) - my - > first_block_num ) , <nl> block_log_append_fail , <nl> " Append to index file occuring at wrong position . " , <nl> ( " position " , ( uint64_t ) my - > index_stream . tellp ( ) ) <nl> - ( " expected " , ( b - > block_num ( ) - 1 ) * sizeof ( uint64_t ) ) ) ; <nl> + ( " expected " , ( b - > block_num ( ) - my - > first_block_num ) * sizeof ( uint64_t ) ) ) ; <nl> auto data = fc : : raw : : pack ( * b ) ; <nl> my - > block_stream . write ( data . data ( ) , data . size ( ) ) ; <nl> my - > block_stream . write ( ( char * ) & pos , sizeof ( pos ) ) ; <nl> namespace eosio { namespace chain { <nl> my - > index_stream . flush ( ) ; <nl> } <nl> <nl> - uint64_t block_log : : reset_to_genesis ( const genesis_state & gs , const signed_block_ptr & genesis_block ) { <nl> - if ( my - > block_stream . is_open ( ) ) <nl> + void block_log : : reset ( const genesis_state & gs , const signed_block_ptr & first_block , uint32_t first_block_num ) { <nl> + if ( my - > block_stream . is_open ( ) ) <nl> my - > block_stream . close ( ) ; <nl> - if ( my - > index_stream . is_open ( ) ) <nl> + if ( my - > index_stream . is_open ( ) ) <nl> my - > index_stream . close ( ) ; <nl> <nl> - fc : : remove_all ( my - > block_file ) ; <nl> - fc : : remove_all ( my - > index_file ) ; <nl> + fc : : remove_all ( my - > block_file ) ; <nl> + fc : : remove_all ( my - > index_file ) ; <nl> <nl> my - > block_stream . open ( my - > block_file . generic_string ( ) . c_str ( ) , LOG_WRITE ) ; <nl> my - > index_stream . open ( my - > index_file . generic_string ( ) . c_str ( ) , LOG_WRITE ) ; <nl> my - > block_write = true ; <nl> my - > index_write = true ; <nl> <nl> - auto data = fc : : raw : : pack ( gs ) ; <nl> - uint32_t version = 0 ; / / version of 0 is invalid ; it indicates that the genesis was not properly written to the block log <nl> - my - > block_stream . write ( ( char * ) & version , sizeof ( version ) ) ; <nl> - my - > block_stream . write ( data . data ( ) , data . size ( ) ) ; <nl> + auto data = fc : : raw : : pack ( gs ) ; <nl> + my - > version = 0 ; / / version of 0 is invalid ; it indicates that the genesis was not properly written to the block log <nl> + my - > first_block_num = first_block_num ; <nl> + my - > block_stream . write ( ( char * ) & my - > version , sizeof ( my - > version ) ) ; <nl> + my - > block_stream . write ( ( char * ) & my - > first_block_num , sizeof ( my - > first_block_num ) ) ; <nl> + my - > block_stream . write ( data . data ( ) , data . size ( ) ) ; <nl> my - > genesis_written_to_block_log = true ; <nl> <nl> - auto ret = append ( genesis_block ) ; <nl> + / / append a totem to indicate the division between blocks and header <nl> + auto totem = npos ; <nl> + my - > block_stream . write ( ( char * ) & totem , sizeof ( totem ) ) ; <nl> + <nl> + if ( first_block ) { <nl> + auto ret = append ( first_block ) ; <nl> + } <nl> <nl> auto pos = my - > block_stream . tellp ( ) ; <nl> <nl> my - > block_stream . close ( ) ; <nl> my - > block_stream . open ( my - > block_file . generic_string ( ) . c_str ( ) , std : : ios : : in | std : : ios : : out | std : : ios : : binary ) ; / / Bypass append - only writing just once <nl> <nl> - static_assert ( block_log : : supported_version > 0 , " a version number of zero is not supported " ) ; <nl> - version = block_log : : supported_version ; <nl> + static_assert ( block_log : : max_supported_version > 0 , " a version number of zero is not supported " ) ; <nl> + my - > version = block_log : : max_supported_version ; <nl> my - > block_stream . seekp ( 0 ) ; <nl> - my - > block_stream . write ( ( char * ) & version , sizeof ( version ) ) ; / / Finally write actual version to disk . <nl> + my - > block_stream . write ( ( char * ) & my - > version , sizeof ( my - > version ) ) ; <nl> my - > block_stream . seekp ( pos ) ; <nl> flush ( ) ; <nl> <nl> my - > block_write = false ; <nl> my - > check_block_write ( ) ; / / Reset to append - only writing . <nl> - <nl> - return ret ; <nl> } <nl> <nl> std : : pair < signed_block_ptr , uint64_t > block_log : : read_block ( uint64_t pos ) const { <nl> namespace eosio { namespace chain { <nl> <nl> uint64_t block_log : : get_block_pos ( uint32_t block_num ) const { <nl> my - > check_index_read ( ) ; <nl> - <nl> - if ( ! ( my - > head & & block_num < = block_header : : num_from_id ( my - > head_id ) & & block_num > 0 ) ) <nl> + if ( ! ( my - > head & & block_num < = block_header : : num_from_id ( my - > head_id ) & & block_num > = my - > first_block_num ) ) <nl> return npos ; <nl> - my - > index_stream . seekg ( sizeof ( uint64_t ) * ( block_num - 1 ) ) ; <nl> + my - > index_stream . seekg ( sizeof ( uint64_t ) * ( block_num - my - > first_block_num ) ) ; <nl> uint64_t pos ; <nl> my - > index_stream . read ( ( char * ) & pos , sizeof ( pos ) ) ; <nl> return pos ; <nl> namespace eosio { namespace chain { <nl> <nl> my - > block_stream . seekg ( - sizeof ( pos ) , std : : ios : : end ) ; <nl> my - > block_stream . read ( ( char * ) & pos , sizeof ( pos ) ) ; <nl> - return read_block ( pos ) . first ; <nl> + if ( pos ! = npos ) { <nl> + return read_block ( pos ) . first ; <nl> + } else { <nl> + return { } ; <nl> + } <nl> } <nl> <nl> const signed_block_ptr & block_log : : head ( ) const { <nl> return my - > head ; <nl> } <nl> <nl> + uint32_t block_log : : first_block_num ( ) const { <nl> + return my - > first_block_num ; <nl> + } <nl> + <nl> void block_log : : construct_index ( ) { <nl> ilog ( " Reconstructing Block Log Index . . . " ) ; <nl> my - > index_stream . close ( ) ; <nl> namespace eosio { namespace chain { <nl> my - > block_stream . read ( ( char * ) & end_pos , sizeof ( end_pos ) ) ; <nl> signed_block tmp ; <nl> <nl> - uint64_t pos = 4 ; / / Skip version which should have already been checked . <nl> + uint64_t pos = 0 ; <nl> + if ( my - > version = = 1 ) { <nl> + pos = 4 ; / / Skip version which should have already been checked . <nl> + } else { <nl> + pos = 8 ; / / Skip version and first block offset which should have already been checked <nl> + } <nl> my - > block_stream . seekg ( pos ) ; <nl> <nl> genesis_state gs ; <nl> namespace eosio { namespace chain { <nl> <nl> uint32_t version = 0 ; <nl> old_block_stream . read ( ( char * ) & version , sizeof ( version ) ) ; <nl> - EOS_ASSERT ( version > 0 , block_log_exception , " Block log was not setup properly with genesis information . " ) ; <nl> - EOS_ASSERT ( version = = block_log : : supported_version , block_log_unsupported_version , <nl> - " Unsupported version of block log . Block log version is $ { version } while code supports version $ { supported } " , <nl> - ( " version " , version ) ( " supported " , block_log : : supported_version ) ) ; <nl> + EOS_ASSERT ( version > 0 , block_log_exception , " Block log was not setup properly " ) ; <nl> + EOS_ASSERT ( version > = min_supported_version & & version < = max_supported_version , block_log_unsupported_version , <nl> + " Unsupported version of block log . Block log version is $ { version } while code supports version ( s ) [ $ { min } , $ { max } ] " , <nl> + ( " version " , version ) ( " min " , block_log : : min_supported_version ) ( " max " , block_log : : max_supported_version ) ) ; <nl> + <nl> + new_block_stream . write ( ( char * ) & version , sizeof ( version ) ) ; <nl> + <nl> + uint32_t first_block_num = 1 ; <nl> + if ( version ! = 1 ) { <nl> + old_block_stream . read ( ( char * ) & first_block_num , sizeof ( first_block_num ) ) ; <nl> + new_block_stream . write ( ( char * ) & first_block_num , sizeof ( first_block_num ) ) ; <nl> + } <nl> <nl> genesis_state gs ; <nl> fc : : raw : : unpack ( old_block_stream , gs ) ; <nl> <nl> auto data = fc : : raw : : pack ( gs ) ; <nl> - new_block_stream . write ( ( char * ) & version , sizeof ( version ) ) ; <nl> new_block_stream . write ( data . data ( ) , data . size ( ) ) ; <nl> <nl> std : : exception_ptr except_ptr ; <nl> namespace eosio { namespace chain { <nl> <nl> uint32_t version = 0 ; <nl> block_stream . read ( ( char * ) & version , sizeof ( version ) ) ; <nl> - EOS_ASSERT ( version > 0 , block_log_exception , " Block log was not setup properly with genesis information . " ) ; <nl> - EOS_ASSERT ( version = = block_log : : supported_version , block_log_unsupported_version , <nl> - " Unsupported version of block log . Block log version is $ { version } while code supports version $ { supported } " , <nl> - ( " version " , version ) ( " supported " , block_log : : supported_version ) ) ; <nl> + EOS_ASSERT ( version > 0 , block_log_exception , " Block log was not setup properly . " ) ; <nl> + EOS_ASSERT ( version > = min_supported_version & & version < = max_supported_version , block_log_unsupported_version , <nl> + " Unsupported version of block log . Block log version is $ { version } while code supports version ( s ) [ $ { min } , $ { max } ] " , <nl> + ( " version " , version ) ( " min " , block_log : : min_supported_version ) ( " max " , block_log : : max_supported_version ) ) ; <nl> + <nl> + uint32_t first_block_num = 1 ; <nl> + if ( version ! = 1 ) { <nl> + block_stream . read ( ( char * ) & first_block_num , sizeof ( first_block_num ) ) ; <nl> + } <nl> <nl> genesis_state gs ; <nl> fc : : raw : : unpack ( block_stream , gs ) ; <nl> mmm a / libraries / chain / controller . cpp <nl> ppp b / libraries / chain / controller . cpp <nl> struct controller_impl { <nl> blog . read_head ( ) ; <nl> <nl> const auto & log_head = blog . head ( ) ; <nl> - EOS_ASSERT ( log_head , block_log_exception , " block log head can not be found " ) ; <nl> - auto lh_block_num = log_head - > block_num ( ) ; <nl> + bool append_to_blog = false ; <nl> + if ( ! log_head ) { <nl> + if ( s - > block ) { <nl> + EOS_ASSERT ( s - > block_num = = blog . first_block_num ( ) , block_log_exception , " block log has no blocks and is appending the wrong first block . Expected $ { expecgted } , but received : $ { actual } " , <nl> + ( " expected " , blog . first_block_num ( ) ) ( " actual " , s - > block_num ) ) ; <nl> + append_to_blog = true ; <nl> + } else { <nl> + EOS_ASSERT ( s - > block_num = = blog . first_block_num ( ) - 1 , block_log_exception , " block log has no blocks and is not properly set up to start after the snapshot " ) ; <nl> + } <nl> + } else { <nl> + auto lh_block_num = log_head - > block_num ( ) ; <nl> + if ( s - > block_num > lh_block_num ) { <nl> + EOS_ASSERT ( s - > block_num - 1 = = lh_block_num , unlinkable_block_exception , " unlinkable block " , ( " s - > block_num " , s - > block_num ) ( " lh_block_num " , lh_block_num ) ) ; <nl> + EOS_ASSERT ( s - > block - > previous = = log_head - > id ( ) , unlinkable_block_exception , " irreversible doesn ' t link to block log head " ) ; <nl> + append_to_blog = true ; <nl> + } <nl> + } <nl> + <nl> <nl> db . commit ( s - > block_num ) ; <nl> <nl> - if ( s - > block_num < = lh_block_num ) { <nl> - / / edump ( ( s - > block_num ) ( " double call to on_irr " ) ) ; <nl> - / / edump ( ( s - > block_num ) ( s - > block - > previous ) ( log_head - > id ( ) ) ) ; <nl> - return ; <nl> + if ( append_to_blog ) { <nl> + blog . append ( s - > block ) ; <nl> } <nl> <nl> - EOS_ASSERT ( s - > block_num - 1 = = lh_block_num , unlinkable_block_exception , " unlinkable block " , ( " s - > block_num " , s - > block_num ) ( " lh_block_num " , lh_block_num ) ) ; <nl> - EOS_ASSERT ( s - > block - > previous = = log_head - > id ( ) , unlinkable_block_exception , " irreversible doesn ' t link to block log head " ) ; <nl> - blog . append ( s - > block ) ; <nl> - <nl> const auto & ubi = reversible_blocks . get_index < reversible_block_index , by_num > ( ) ; <nl> auto objitr = ubi . begin ( ) ; <nl> while ( objitr ! = ubi . end ( ) & & objitr - > blocknum < = s - > block_num ) { <nl> struct controller_impl { <nl> objitr = ubi . begin ( ) ; <nl> } <nl> <nl> - if ( read_mode = = db_read_mode : : IRREVERSIBLE ) { <nl> - apply_block ( s - > block , controller : : block_status : : complete ) ; <nl> - fork_db . mark_in_current_chain ( s , true ) ; <nl> - fork_db . set_validity ( s , true ) ; <nl> - head = s ; <nl> + / / the " head " block when a snapshot is loaded is virtual and has no block data , all of its effects <nl> + / / should already have been loaded from the snapshot so , it cannot be applied <nl> + if ( s - > block ) { <nl> + if ( read_mode = = db_read_mode : : IRREVERSIBLE ) { <nl> + apply_block ( s - > block , controller : : block_status : : complete ) ; <nl> + fork_db . mark_in_current_chain ( s , true ) ; <nl> + fork_db . set_validity ( s , true ) ; <nl> + head = s ; <nl> + } <nl> + emit ( self . irreversible_block , s ) ; <nl> } <nl> - emit ( self . irreversible_block , s ) ; <nl> + } <nl> + <nl> + void replay ( ) { <nl> + auto blog_head = blog . read_head ( ) ; <nl> + auto blog_head_time = blog_head - > timestamp . to_time_point ( ) ; <nl> + replaying = true ; <nl> + replay_head_time = blog_head_time ; <nl> + ilog ( " existing block log , attempting to replay $ { n } blocks " , ( " n " , blog_head - > block_num ( ) ) ) ; <nl> + <nl> + auto start = fc : : time_point : : now ( ) ; <nl> + while ( auto next = blog . read_block_by_num ( head - > block_num + 1 ) ) { <nl> + self . push_block ( next , controller : : block_status : : irreversible ) ; <nl> + if ( next - > block_num ( ) % 100 = = 0 ) { <nl> + std : : cerr < < std : : setw ( 10 ) < < next - > block_num ( ) < < " of " < < blog_head - > block_num ( ) < < " \ r " ; <nl> + } <nl> + } <nl> + std : : cerr < < " \ n " ; <nl> + ilog ( " $ { n } blocks replayed " , ( " n " , head - > block_num ) ) ; <nl> + <nl> + / / if the irreverible log is played without undo sessions enabled , we need to sync the <nl> + / / revision ordinal to the appropriate expected value here . <nl> + if ( self . skip_db_sessions ( controller : : block_status : : irreversible ) ) <nl> + db . set_revision ( head - > block_num ) ; <nl> + <nl> + int rev = 0 ; <nl> + while ( auto obj = reversible_blocks . find < reversible_block_object , by_num > ( head - > block_num + 1 ) ) { <nl> + + + rev ; <nl> + self . push_block ( obj - > get_block ( ) , controller : : block_status : : validated ) ; <nl> + } <nl> + <nl> + ilog ( " $ { n } reversible blocks replayed " , ( " n " , rev ) ) ; <nl> + auto end = fc : : time_point : : now ( ) ; <nl> + ilog ( " replayed $ { n } blocks in $ { duration } seconds , $ { mspb } ms / block " , <nl> + ( " n " , head - > block_num ) ( " duration " , ( end - start ) . count ( ) / 1000000 ) <nl> + ( " mspb " , ( ( end - start ) . count ( ) / 1000 . 0 ) / head - > block_num ) ) ; <nl> + replaying = false ; <nl> + replay_head_time . reset ( ) ; <nl> } <nl> <nl> void init ( const snapshot_reader_ptr & snapshot ) { <nl> struct controller_impl { <nl> <nl> read_from_snapshot ( snapshot ) ; <nl> <nl> + auto end = blog . read_head ( ) ; <nl> + if ( ! end ) { <nl> + blog . reset ( conf . genesis , signed_block_ptr ( ) , head - > block_num + 1 ) ; <nl> + } else if ( end - > block_num ( ) > head - > block_num ) { <nl> + replay ( ) ; <nl> + } <nl> + <nl> } else if ( ! head ) { <nl> initialize_fork_db ( ) ; / / set head to genesis state <nl> <nl> auto end = blog . read_head ( ) ; <nl> if ( end & & end - > block_num ( ) > 1 ) { <nl> - auto end_time = end - > timestamp . to_time_point ( ) ; <nl> - replaying = true ; <nl> - replay_head_time = end_time ; <nl> - ilog ( " existing block log , attempting to replay $ { n } blocks " , ( " n " , end - > block_num ( ) ) ) ; <nl> - <nl> - auto start = fc : : time_point : : now ( ) ; <nl> - while ( auto next = blog . read_block_by_num ( head - > block_num + 1 ) ) { <nl> - self . push_block ( next , controller : : block_status : : irreversible ) ; <nl> - if ( next - > block_num ( ) % 100 = = 0 ) { <nl> - std : : cerr < < std : : setw ( 10 ) < < next - > block_num ( ) < < " of " < < end - > block_num ( ) < < " \ r " ; <nl> - } <nl> - } <nl> - std : : cerr < < " \ n " ; <nl> - ilog ( " $ { n } blocks replayed " , ( " n " , head - > block_num ) ) ; <nl> - <nl> - / / if the irreverible log is played without undo sessions enabled , we need to sync the <nl> - / / revision ordinal to the appropriate expected value here . <nl> - if ( self . skip_db_sessions ( controller : : block_status : : irreversible ) ) <nl> - db . set_revision ( head - > block_num ) ; <nl> - <nl> - int rev = 0 ; <nl> - while ( auto obj = reversible_blocks . find < reversible_block_object , by_num > ( head - > block_num + 1 ) ) { <nl> - + + rev ; <nl> - self . push_block ( obj - > get_block ( ) , controller : : block_status : : validated ) ; <nl> - } <nl> - <nl> - ilog ( " $ { n } reversible blocks replayed " , ( " n " , rev ) ) ; <nl> - auto end = fc : : time_point : : now ( ) ; <nl> - ilog ( " replayed $ { n } blocks in $ { duration } seconds , $ { mspb } ms / block " , <nl> - ( " n " , head - > block_num ) ( " duration " , ( end - start ) . count ( ) / 1000000 ) <nl> - ( " mspb " , ( ( end - start ) . count ( ) / 1000 . 0 ) / head - > block_num ) ) ; <nl> - replaying = false ; <nl> - replay_head_time . reset ( ) ; <nl> - <nl> + replay ( ) ; <nl> } else if ( ! end ) { <nl> - blog . reset_to_genesis ( conf . genesis , head - > block ) ; <nl> + blog . reset ( conf . genesis , head - > block ) ; <nl> } <nl> } <nl> <nl> struct controller_impl { <nl> return enc . result ( ) ; <nl> } <nl> <nl> - struct json_snapshot_writer : public snapshot_writer { <nl> - json_snapshot_writer ( ) <nl> - : snapshot ( fc : : mutable_variant_object ( ) ( " sections " , fc : : variants ( ) ) ) <nl> - { <nl> - <nl> - } <nl> - <nl> - void write_start_section ( const string & section_name ) override { <nl> - current_rows . clear ( ) ; <nl> - current_section_name = section_name ; <nl> - } <nl> - <nl> - void write_row ( const detail : : abstract_snapshot_row_writer & row_writer ) override { <nl> - current_rows . emplace_back ( row_writer . to_variant ( ) ) ; <nl> - } <nl> - <nl> - void write_end_section ( ) override { <nl> - snapshot [ " sections " ] . get_array ( ) . emplace_back ( mutable_variant_object ( ) ( " name " , std : : move ( current_section_name ) ) ( " rows " , std : : move ( current_rows ) ) ) ; <nl> - } <nl> - <nl> - fc : : mutable_variant_object snapshot ; <nl> - string current_section_name ; <nl> - fc : : variants current_rows ; <nl> - } ; <nl> - <nl> - struct json_snapshot_reader : public snapshot_reader { <nl> - json_snapshot_reader ( const fc : : variant & snapshot ) <nl> - : snapshot ( snapshot ) <nl> - , cur_row ( 0 ) <nl> - { <nl> - <nl> - } <nl> - <nl> - void set_section ( const string & section_name ) override { <nl> - const auto & sections = snapshot [ " sections " ] . get_array ( ) ; <nl> - for ( const auto & section : sections ) { <nl> - if ( section [ " name " ] . as_string ( ) = = section_name ) { <nl> - cur_section = & section . get_object ( ) ; <nl> - break ; <nl> - } <nl> - } <nl> - } <nl> - <nl> - bool read_row ( detail : : abstract_snapshot_row_reader & row_reader ) override { <nl> - const auto & rows = ( * cur_section ) [ " rows " ] . get_array ( ) ; <nl> - row_reader . provide ( rows . at ( cur_row + + ) ) ; <nl> - return cur_row < rows . size ( ) ; <nl> - } <nl> - <nl> - bool empty ( ) override { <nl> - const auto & rows = ( * cur_section ) [ " rows " ] . get_array ( ) ; <nl> - return rows . empty ( ) ; <nl> - } <nl> - <nl> - void clear_section ( ) override { <nl> - cur_section = nullptr ; <nl> - cur_row = 0 ; <nl> - } <nl> - <nl> - const fc : : variant & snapshot ; <nl> - const fc : : variant_object * cur_section ; <nl> - int cur_row ; <nl> - } ; <nl> - <nl> void add_to_snapshot ( const snapshot_writer_ptr & snapshot ) const { <nl> snapshot - > write_section < block_state > ( [ this ] ( auto & section ) { <nl> section . template add_row < block_header_state > ( * fork_db . head ( ) ) ; <nl> struct controller_impl { <nl> resource_limits . add_to_snapshot ( snapshot ) ; <nl> } <nl> <nl> - void print_json_snapshot ( ) const { <nl> - json_snapshot_writer snapshot ; <nl> - auto snapshot_ptr = shared_ptr < snapshot_writer > ( & snapshot , [ ] ( snapshot_writer * ) { } ) ; <nl> - add_to_snapshot ( snapshot_ptr ) ; <nl> - std : : cerr < < fc : : json : : to_pretty_string ( snapshot . snapshot ) < < std : : endl ; <nl> - } <nl> - <nl> void read_from_snapshot ( const snapshot_reader_ptr & snapshot ) { <nl> snapshot - > read_section < block_state > ( [ this ] ( auto & section ) { <nl> block_header_state head_header_state ; <nl> struct controller_impl { <nl> <nl> controller_index_set : : walk_indices ( [ this , & snapshot ] ( auto utils ) { <nl> snapshot - > read_section < typename decltype ( utils ) : : index_t : : value_type > ( [ this ] ( auto & section ) { <nl> - bool done = section . empty ( ) ; <nl> - while ( ! done ) { <nl> - decltype ( utils ) : : create ( db , [ & section ] ( auto & row ) { <nl> - section . read_row ( row ) ; <nl> + bool more = ! section . empty ( ) ; <nl> + while ( more ) { <nl> + decltype ( utils ) : : create ( db , [ & section , & more ] ( auto & row ) { <nl> + more = section . read_row ( row ) ; <nl> } ) ; <nl> } <nl> } ) ; <nl> sha256 controller : : calculate_integrity_hash ( ) const { try { <nl> return my - > calculate_integrity_hash ( ) ; <nl> } FC_LOG_AND_RETHROW ( ) } <nl> <nl> + void controller : : write_snapshot ( const snapshot_writer_ptr & snapshot ) const { <nl> + EOS_ASSERT ( ! my - > pending , block_validate_exception , " cannot take a consistent snapshot with a pending block " ) ; <nl> + return my - > add_to_snapshot ( snapshot ) ; <nl> + } <nl> + <nl> void controller : : pop_block ( ) { <nl> my - > pop_block ( ) ; <nl> } <nl> mmm a / libraries / chain / include / eosio / chain / block_log . hpp <nl> ppp b / libraries / chain / include / eosio / chain / block_log . hpp <nl> namespace eosio { namespace chain { <nl> <nl> namespace detail { class block_log_impl ; } <nl> <nl> - / * The block log is an external append only log of the blocks . Blocks should only be written <nl> - * to the log after they irreverisble as the log is append only . The log is a doubly linked <nl> - * list of blocks . There is a secondary index file of only block positions that enables O ( 1 ) <nl> - * random access lookup by block number . <nl> + / * The block log is an external append only log of the blocks with a header . Blocks should only <nl> + * be written to the log after they irreverisble as the log is append only . The log is a doubly <nl> + * linked list of blocks . There is a secondary index file of only block positions that enables <nl> + * O ( 1 ) random access lookup by block number . <nl> * <nl> * + mmmmmmmmm + mmmmmmmmmmmmmmm - + mmmmmmmmm + mmmmmmmmmmmmmmm - + mmm - - + mmmmmmmmmmmm + mmmmmmmmmmmmmmmmmm - + <nl> * | Block 1 | Pos of Block 1 | Block 2 | Pos of Block 2 | . . . | Head Block | Pos of Head Block | <nl> namespace eosio { namespace chain { <nl> <nl> uint64_t append ( const signed_block_ptr & b ) ; <nl> void flush ( ) ; <nl> - uint64_t reset_to_genesis ( const genesis_state & gs , const signed_block_ptr & genesis_block ) ; <nl> + void reset ( const genesis_state & gs , const signed_block_ptr & genesis_block , uint32_t first_block_num = 1 ) ; <nl> <nl> std : : pair < signed_block_ptr , uint64_t > read_block ( uint64_t file_pos ) const ; <nl> signed_block_ptr read_block_by_num ( uint32_t block_num ) const ; <nl> namespace eosio { namespace chain { <nl> uint64_t get_block_pos ( uint32_t block_num ) const ; <nl> signed_block_ptr read_head ( ) const ; <nl> const signed_block_ptr & head ( ) const ; <nl> + uint32_t first_block_num ( ) const ; <nl> <nl> static const uint64_t npos = std : : numeric_limits < uint64_t > : : max ( ) ; <nl> <nl> - static const uint32_t supported_version ; <nl> + static const uint32_t min_supported_version ; <nl> + static const uint32_t max_supported_version ; <nl> <nl> static fc : : path repair_log ( const fc : : path & data_dir , uint32_t truncate_at_block = 0 ) ; <nl> <nl> mmm a / libraries / chain / include / eosio / chain / controller . hpp <nl> ppp b / libraries / chain / include / eosio / chain / controller . hpp <nl> namespace eosio { namespace chain { <nl> block_id_type get_block_id_for_num ( uint32_t block_num ) const ; <nl> <nl> sha256 calculate_integrity_hash ( ) const ; <nl> + void write_snapshot ( const snapshot_writer_ptr & snapshot ) const ; <nl> <nl> void check_contract_list ( account_name code ) const ; <nl> void check_action_list ( account_name code , action_name action ) const ; <nl> mmm a / libraries / chain / include / eosio / chain / snapshot . hpp <nl> ppp b / libraries / chain / include / eosio / chain / snapshot . hpp <nl> namespace eosio { namespace chain { <nl> write_end_section ( ) ; <nl> } <nl> <nl> + virtual ~ snapshot_writer ( ) { } ; <nl> + <nl> protected : <nl> virtual void write_start_section ( const std : : string & section_name ) = 0 ; <nl> virtual void write_row ( const detail : : abstract_snapshot_row_writer & row_writer ) = 0 ; <nl> namespace eosio { namespace chain { <nl> clear_section ( ) ; <nl> } <nl> <nl> + virtual ~ snapshot_reader ( ) { } ; <nl> + <nl> protected : <nl> virtual void set_section ( const std : : string & section_name ) = 0 ; <nl> virtual bool read_row ( detail : : abstract_snapshot_row_reader & row_reader ) = 0 ; <nl> namespace eosio { namespace chain { <nl> <nl> using snapshot_reader_ptr = std : : shared_ptr < snapshot_reader > ; <nl> <nl> + class variant_snapshot_writer : public snapshot_writer { <nl> + public : <nl> + variant_snapshot_writer ( ) <nl> + : snapshot ( fc : : mutable_variant_object ( ) ( " sections " , fc : : variants ( ) ) ) <nl> + { <nl> + <nl> + } <nl> + <nl> + void write_start_section ( const std : : string & section_name ) override { <nl> + current_rows . clear ( ) ; <nl> + current_section_name = section_name ; <nl> + } <nl> + <nl> + void write_row ( const detail : : abstract_snapshot_row_writer & row_writer ) override { <nl> + current_rows . emplace_back ( row_writer . to_variant ( ) ) ; <nl> + } <nl> + <nl> + void write_end_section ( ) override { <nl> + snapshot [ " sections " ] . get_array ( ) . emplace_back ( fc : : mutable_variant_object ( ) ( " name " , std : : move ( current_section_name ) ) ( " rows " , std : : move ( current_rows ) ) ) ; <nl> + } <nl> + <nl> + fc : : variant finalize ( ) { <nl> + fc : : variant result = std : : move ( snapshot ) ; <nl> + return result ; <nl> + } <nl> + private : <nl> + fc : : mutable_variant_object snapshot ; <nl> + std : : string current_section_name ; <nl> + fc : : variants current_rows ; <nl> + } ; <nl> + <nl> + class variant_snapshot_reader : public snapshot_reader { <nl> + public : <nl> + variant_snapshot_reader ( const fc : : variant & snapshot ) <nl> + : snapshot ( snapshot ) <nl> + , cur_row ( 0 ) <nl> + { <nl> + <nl> + } <nl> + <nl> + void set_section ( const string & section_name ) override { <nl> + const auto & sections = snapshot [ " sections " ] . get_array ( ) ; <nl> + for ( const auto & section : sections ) { <nl> + if ( section [ " name " ] . as_string ( ) = = section_name ) { <nl> + cur_section = & section . get_object ( ) ; <nl> + break ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + bool read_row ( detail : : abstract_snapshot_row_reader & row_reader ) override { <nl> + const auto & rows = ( * cur_section ) [ " rows " ] . get_array ( ) ; <nl> + row_reader . provide ( rows . at ( cur_row + + ) ) ; <nl> + return cur_row < rows . size ( ) ; <nl> + } <nl> + <nl> + bool empty ( ) override { <nl> + const auto & rows = ( * cur_section ) [ " rows " ] . get_array ( ) ; <nl> + return rows . empty ( ) ; <nl> + } <nl> + <nl> + void clear_section ( ) override { <nl> + cur_section = nullptr ; <nl> + cur_row = 0 ; <nl> + } <nl> + <nl> + private : <nl> + const fc : : variant & snapshot ; <nl> + const fc : : variant_object * cur_section ; <nl> + int cur_row ; <nl> + } ; <nl> + <nl> } } <nl> mmm a / libraries / chain / resource_limits . cpp <nl> ppp b / libraries / chain / resource_limits . cpp <nl> void resource_limits_manager : : add_to_snapshot ( const snapshot_writer_ptr & snapsh <nl> void resource_limits_manager : : read_from_snapshot ( const snapshot_reader_ptr & snapshot ) { <nl> resource_index_set : : walk_indices ( [ this , & snapshot ] ( auto utils ) { <nl> snapshot - > read_section < typename decltype ( utils ) : : index_t : : value_type > ( [ this ] ( auto & section ) { <nl> - bool done = section . empty ( ) ; <nl> - while ( ! done ) { <nl> - decltype ( utils ) : : create ( _db , [ & section ] ( auto & row ) { <nl> - section . read_row ( row ) ; <nl> + bool more = ! section . empty ( ) ; <nl> + while ( more ) { <nl> + decltype ( utils ) : : create ( _db , [ & section , & more ] ( auto & row ) { <nl> + more = section . read_row ( row ) ; <nl> } ) ; <nl> } <nl> } ) ; <nl> mmm a / libraries / testing / include / eosio / testing / tester . hpp <nl> ppp b / libraries / testing / include / eosio / testing / tester . hpp <nl> namespace eosio { namespace testing { <nl> virtual ~ base_tester ( ) { } ; <nl> <nl> void init ( bool push_genesis = true , db_read_mode read_mode = db_read_mode : : SPECULATIVE ) ; <nl> - void init ( controller : : config config ) ; <nl> + void init ( controller : : config config , const snapshot_reader_ptr & snapshot = nullptr ) ; <nl> <nl> void close ( ) ; <nl> - void open ( ) ; <nl> + void open ( const snapshot_reader_ptr & snapshot ) ; <nl> bool is_same_chain ( base_tester & other ) ; <nl> <nl> virtual signed_block_ptr produce_block ( fc : : microseconds skip_time = fc : : milliseconds ( config : : block_interval_ms ) , uint32_t skip_flag = 0 / * skip_missed_block_penalty * / ) = 0 ; <nl> namespace eosio { namespace testing { <nl> return true ; <nl> } <nl> <nl> + const controller : : config & get_config ( ) const { <nl> + return cfg ; <nl> + } <nl> + <nl> protected : <nl> signed_block_ptr _produce_block ( fc : : microseconds skip_time , bool skip_pending_trxs = false , uint32_t skip_flag = 0 ) ; <nl> void _start_block ( fc : : time_point block_time ) ; <nl> mmm a / libraries / testing / tester . cpp <nl> ppp b / libraries / testing / tester . cpp <nl> namespace eosio { namespace testing { <nl> cfg . wasm_runtime = chain : : wasm_interface : : vm_type : : wabt ; <nl> } <nl> <nl> - open ( ) ; <nl> + open ( nullptr ) ; <nl> <nl> if ( push_genesis ) <nl> push_genesis_block ( ) ; <nl> } <nl> <nl> <nl> - void base_tester : : init ( controller : : config config ) { <nl> + void base_tester : : init ( controller : : config config , const snapshot_reader_ptr & snapshot ) { <nl> cfg = config ; <nl> - open ( ) ; <nl> + open ( snapshot ) ; <nl> } <nl> <nl> <nl> namespace eosio { namespace testing { <nl> } <nl> <nl> <nl> - void base_tester : : open ( ) { <nl> + void base_tester : : open ( const snapshot_reader_ptr & snapshot ) { <nl> control . reset ( new controller ( cfg ) ) ; <nl> control - > add_indices ( ) ; <nl> - control - > startup ( ) ; <nl> + control - > startup ( snapshot ) ; <nl> chain_transactions . clear ( ) ; <nl> control - > accepted_block . connect ( [ this ] ( const block_state_ptr & block_state ) { <nl> FC_ASSERT ( block_state - > block ) ; <nl> mmm a / unittests / CMakeLists . txt <nl> ppp b / unittests / CMakeLists . txt <nl> target_include_directories ( unit_test PUBLIC <nl> $ { CMAKE_CURRENT_SOURCE_DIR } / contracts <nl> $ { CMAKE_CURRENT_BINARY_DIR } / contracts <nl> $ { CMAKE_CURRENT_BINARY_DIR } / include ) <nl> - add_dependencies ( unit_test asserter test_api test_api_mem test_api_db test_ram_limit test_api_multi_index eosio . token proxy identity identity_test stltest infinite eosio . system eosio . token eosio . bios test . inline multi_index_test noop dice eosio . msig payloadless tic_tac_toe deferred_test ) <nl> + add_dependencies ( unit_test asserter test_api test_api_mem test_api_db test_ram_limit test_api_multi_index eosio . token proxy identity identity_test stltest infinite eosio . system eosio . token eosio . bios test . inline multi_index_test noop dice eosio . msig payloadless tic_tac_toe deferred_test snapshot_test ) <nl> <nl> # Manually run unit_test for all supported runtimes <nl> # To run unit_test with all log from blockchain displayed , put - - verbose after - - , i . e . unit_test - - - - verbose <nl> mmm a / unittests / snapshot_tests . cpp <nl> ppp b / unittests / snapshot_tests . cpp <nl> <nl> # include < boost / test / unit_test . hpp > <nl> # include < eosio / testing / tester . hpp > <nl> <nl> + # include < eosio / chain / snapshot . hpp > <nl> + <nl> + # include < snapshot_test / snapshot_test . wast . hpp > <nl> + # include < snapshot_test / snapshot_test . abi . hpp > <nl> + <nl> + <nl> using namespace eosio ; <nl> using namespace testing ; <nl> using namespace chain ; <nl> <nl> + class snapshotted_tester : public base_tester { <nl> + public : <nl> + snapshotted_tester ( controller : : config config , const snapshot_reader_ptr & snapshot , int ordinal ) { <nl> + FC_ASSERT ( config . blocks_dir . filename ( ) . generic_string ( ) ! = " . " <nl> + & & config . state_dir . filename ( ) . generic_string ( ) ! = " . " , " invalid path names in controller : : config " ) ; <nl> + <nl> + controller : : config copied_config = config ; <nl> + copied_config . blocks_dir = <nl> + config . blocks_dir . parent_path ( ) / std : : to_string ( ordinal ) . append ( config . blocks_dir . filename ( ) . generic_string ( ) ) ; <nl> + copied_config . state_dir = <nl> + config . state_dir . parent_path ( ) / std : : to_string ( ordinal ) . append ( config . state_dir . filename ( ) . generic_string ( ) ) ; <nl> + <nl> + init ( copied_config , snapshot ) ; <nl> + } <nl> + <nl> + signed_block_ptr produce_block ( fc : : microseconds skip_time = fc : : milliseconds ( config : : block_interval_ms ) , uint32_t skip_flag = 0 / * skip_missed_block_penalty * / ) override { <nl> + return _produce_block ( skip_time , false , skip_flag ) ; <nl> + } <nl> + <nl> + signed_block_ptr produce_empty_block ( fc : : microseconds skip_time = fc : : milliseconds ( config : : block_interval_ms ) , uint32_t skip_flag = 0 / * skip_missed_block_penalty * / ) override { <nl> + control - > abort_block ( ) ; <nl> + return _produce_block ( skip_time , true , skip_flag ) ; <nl> + } <nl> + <nl> + bool validate ( ) { return true ; } <nl> + } ; <nl> + <nl> BOOST_AUTO_TEST_SUITE ( snapshot_tests ) <nl> <nl> BOOST_AUTO_TEST_CASE ( test_multi_index_snapshot ) <nl> { <nl> - tester main ; <nl> + tester chain ; <nl> + <nl> + chain . create_account ( N ( snapshot ) ) ; <nl> + chain . produce_blocks ( 1 ) ; <nl> + chain . set_code ( N ( snapshot ) , snapshot_test_wast ) ; <nl> + chain . set_abi ( N ( snapshot ) , snapshot_test_abi ) ; <nl> + chain . produce_blocks ( 1 ) ; <nl> + chain . control - > abort_block ( ) ; <nl> + <nl> + <nl> + static const int generation_count = 20 ; <nl> + std : : list < snapshotted_tester > sub_testers ; <nl> + <nl> + for ( int generation = 0 ; generation < generation_count ; generation + + ) { <nl> + / / create a new snapshot child <nl> + variant_snapshot_writer writer ; <nl> + auto writer_p = std : : shared_ptr < snapshot_writer > ( & writer , [ ] ( snapshot_writer * ) { } ) ; <nl> + chain . control - > write_snapshot ( writer_p ) ; <nl> + auto snapshot = writer . finalize ( ) ; <nl> + <nl> + / / create a new child at this snapshot <nl> + sub_testers . emplace_back ( chain . get_config ( ) , std : : make_shared < variant_snapshot_reader > ( snapshot ) , generation ) ; <nl> + <nl> + / / increment the test contract <nl> + <nl> + / / produce block <nl> + auto new_block = chain . produce_block ( ) ; <nl> + <nl> + / / undo the auto - pending from tester <nl> + chain . control - > abort_block ( ) ; <nl> <nl> + auto integrity_value = chain . control - > calculate_integrity_hash ( ) ; <nl> <nl> + / / push that block to all sub testers and validate the integrity of the database after it . <nl> + for ( auto & other : sub_testers ) { <nl> + other . push_block ( new_block ) ; <nl> + BOOST_REQUIRE_EQUAL ( integrity_value . str ( ) , other . control - > calculate_integrity_hash ( ) . str ( ) ) ; <nl> + } <nl> + } <nl> } <nl> <nl> BOOST_AUTO_TEST_SUITE_END ( ) <nl>
|
add basic snapshot test , modify block log to support partial logs , fix several bugs that result from that concept
|
EOSIO/eos
|
cdbe373494584b50d659e01f2885a1fbdbdb327f
|
2018-10-04T15:49:11Z
|
mmm a / src / httpserver . cpp <nl> ppp b / src / httpserver . cpp <nl> void StopHTTPServer ( ) <nl> } <nl> if ( eventBase ) { <nl> LogPrint ( BCLog : : HTTP , " Waiting for HTTP event thread to exit \ n " ) ; <nl> + / / Exit the event loop as soon as there are no active events . <nl> + event_base_loopexit ( eventBase , nullptr ) ; <nl> / / Give event loop a few seconds to exit ( to send back last RPC responses ) , then break it <nl> / / Before this was solved with event_base_loopexit , but that didn ' t work as expected in <nl> / / at least libevent 2 . 0 . 21 and always introduced a delay . In libevent <nl>
|
Improve shutdown process
|
bitcoin/bitcoin
|
793667af1c31835e0eefcdd283930bb89cfeda8f
|
2017-08-12T03:42:00Z
|
mmm a / folly / test / DeterministicSchedule . cpp <nl> ppp b / folly / test / DeterministicSchedule . cpp <nl> FutexResult futexWaitUntilImpl ( Futex < DeterministicAtomic > * futex , <nl> break ; <nl> } <nl> } <nl> + } else { <nl> + futexErrno = EWOULDBLOCK ; <nl> } <nl> futexLock . unlock ( ) ; <nl> DeterministicSchedule : : afterSharedAccess ( ) ; <nl>
|
folly : futexWaitUntilImpl : avoid abort triggered via tao / queues tests
|
facebook/folly
|
b27ed0f6ed5325abcc368f8433fc92fb3c9dc77a
|
2014-06-27T22:07:42Z
|
mmm a / R - package / man / getinfo . Rd <nl> ppp b / R - package / man / getinfo . Rd <nl> Get information of an xgb . DMatrix object <nl> } <nl> \ examples { <nl> data ( iris ) <nl> - iris [ , 5 ] < - as . numeric ( iris [ , 5 ] ) <nl> + iris [ , 5 ] < - as . numeric ( iris [ , 5 ] = = ' setosa ' ) <nl> dtrain < - xgb . DMatrix ( as . matrix ( iris [ , 1 : 4 ] ) , label = iris [ , 5 ] ) <nl> labels < - getinfo ( dtrain , " label " ) <nl> } <nl> mmm a / R - package / man / predict - xgb . Booster - method . Rd <nl> ppp b / R - package / man / predict - xgb . Booster - method . Rd <nl> value of sum of functions , when outputmargin = TRUE , the prediction is <nl> untransformed margin value . In logistic regression , outputmargin = T will <nl> output value before logistic transformation . } <nl> <nl> - \ item { ntreelimit } { limit number of trees used in prediction , this parameter is only valid for gbtree , but not for gblinear . <nl> - set it to be value bigger than 0 . It will use all trees by default . } <nl> + \ item { ntreelimit } { limit number of trees used in prediction , this parameter is <nl> + only valid for gbtree , but not for gblinear . set it to be value bigger <nl> + than 0 . It will use all trees by default . } <nl> } <nl> \ description { <nl> Predicted values based on xgboost model object . <nl> } <nl> \ examples { <nl> data ( iris ) <nl> - bst < - xgboost ( as . matrix ( iris [ , 1 : 4 ] ) , as . numeric ( iris [ , 5 ] ) , nrounds = 2 ) <nl> + bst < - xgboost ( as . matrix ( iris [ , 1 : 4 ] ) , as . numeric ( iris [ , 5 ] = = ' setosa ' ) , nrounds = 2 ) <nl> pred < - predict ( bst , as . matrix ( iris [ , 1 : 4 ] ) ) <nl> } <nl> <nl> mmm a / R - package / man / slice . Rd <nl> ppp b / R - package / man / slice . Rd <nl> orginal xgb . DMatrix object <nl> } <nl> \ examples { <nl> data ( iris ) <nl> - iris [ , 5 ] < - as . numeric ( iris [ , 5 ] ) <nl> + iris [ , 5 ] < - as . numeric ( iris [ , 5 ] = = ' setosa ' ) <nl> dtrain < - xgb . DMatrix ( as . matrix ( iris [ , 1 : 4 ] ) , label = iris [ , 5 ] ) <nl> dsub < - slice ( dtrain , 1 : 3 ) <nl> } <nl> mmm a / R - package / man / xgb . DMatrix . Rd <nl> ppp b / R - package / man / xgb . DMatrix . Rd <nl> Contruct xgb . DMatrix object from dense matrix , sparse matrix or local file . <nl> } <nl> \ examples { <nl> data ( iris ) <nl> - iris [ , 5 ] < - as . numeric ( iris [ , 5 ] ) <nl> + iris [ , 5 ] < - as . numeric ( iris [ , 5 ] = = ' setosa ' ) <nl> dtrain < - xgb . DMatrix ( as . matrix ( iris [ , 1 : 4 ] ) , label = iris [ , 5 ] ) <nl> xgb . DMatrix . save ( dtrain , ' iris . xgb . DMatrix ' ) <nl> dtrain < - xgb . DMatrix ( ' iris . xgb . DMatrix ' ) <nl> mmm a / R - package / man / xgb . DMatrix . save . Rd <nl> ppp b / R - package / man / xgb . DMatrix . save . Rd <nl> Save xgb . DMatrix object to binary file <nl> } <nl> \ examples { <nl> data ( iris ) <nl> - iris [ , 5 ] < - as . numeric ( iris [ , 5 ] ) <nl> + iris [ , 5 ] < - as . numeric ( iris [ , 5 ] = = ' setosa ' ) <nl> dtrain < - xgb . DMatrix ( as . matrix ( iris [ , 1 : 4 ] ) , label = iris [ , 5 ] ) <nl> xgb . DMatrix . save ( dtrain , ' iris . xgb . DMatrix ' ) <nl> dtrain < - xgb . DMatrix ( ' iris . xgb . DMatrix ' ) <nl> mmm a / R - package / man / xgb . dump . Rd <nl> ppp b / R - package / man / xgb . dump . Rd <nl> Save a xgboost model to text file . Could be parsed later . <nl> } <nl> \ examples { <nl> data ( iris ) <nl> - bst < - xgboost ( as . matrix ( iris [ , 1 : 4 ] ) , as . numeric ( iris [ , 5 ] ) , nrounds = 2 ) <nl> + bst < - xgboost ( as . matrix ( iris [ , 1 : 4 ] ) , as . numeric ( iris [ , 5 ] = = ' setosa ' ) , nrounds = 2 ) <nl> xgb . dump ( bst , ' iris . xgb . model . dump ' ) <nl> } <nl> <nl> mmm a / R - package / man / xgb . load . Rd <nl> ppp b / R - package / man / xgb . load . Rd <nl> Load xgboost model from the binary model file <nl> } <nl> \ examples { <nl> data ( iris ) <nl> - bst < - xgboost ( as . matrix ( iris [ , 1 : 4 ] ) , as . numeric ( iris [ , 5 ] ) , nrounds = 2 ) <nl> + bst < - xgboost ( as . matrix ( iris [ , 1 : 4 ] ) , as . numeric ( iris [ , 5 ] = = ' setosa ' ) , nrounds = 2 ) <nl> xgb . save ( bst , ' iris . xgb . model ' ) <nl> bst < - xgb . load ( ' iris . xgb . model ' ) <nl> pred < - predict ( bst , as . matrix ( iris [ , 1 : 4 ] ) ) <nl> mmm a / R - package / man / xgb . save . Rd <nl> ppp b / R - package / man / xgb . save . Rd <nl> Save xgboost model from xgboost or xgb . train <nl> } <nl> \ examples { <nl> data ( iris ) <nl> - bst < - xgboost ( as . matrix ( iris [ , 1 : 4 ] ) , as . numeric ( iris [ , 5 ] ) , nrounds = 2 ) <nl> + bst < - xgboost ( as . matrix ( iris [ , 1 : 4 ] ) , as . numeric ( iris [ , 5 ] = = ' setosa ' ) , nrounds = 2 ) <nl> xgb . save ( bst , ' iris . xgb . model ' ) <nl> bst < - xgb . load ( ' iris . xgb . model ' ) <nl> pred < - predict ( bst , as . matrix ( iris [ , 1 : 4 ] ) ) <nl> mmm a / R - package / man / xgb . train . Rd <nl> ppp b / R - package / man / xgb . train . Rd <nl> therefore it is more flexible than \ code { \ link { xgboost } } . <nl> } <nl> \ examples { <nl> data ( iris ) <nl> - iris [ , 5 ] < - as . numeric ( iris [ , 5 ] ) <nl> + iris [ , 5 ] < - as . numeric ( iris [ , 5 ] = = ' setosa ' ) <nl> dtrain < - xgb . DMatrix ( as . matrix ( iris [ , 1 : 4 ] ) , label = iris [ , 5 ] ) <nl> dtest < - dtrain <nl> watchlist < - list ( eval = dtest , train = dtrain ) <nl> mmm a / R - package / man / xgboost . Rd <nl> ppp b / R - package / man / xgboost . Rd <nl> Number of threads can also be manually specified via " nthread " parameter <nl> } <nl> \ examples { <nl> data ( iris ) <nl> - bst < - xgboost ( as . matrix ( iris [ , 1 : 4 ] ) , as . numeric ( iris [ , 5 ] ) , nrounds = 2 ) <nl> + bst < - xgboost ( as . matrix ( iris [ , 1 : 4 ] ) , as . numeric ( iris [ , 5 ] = = ' setosa ' ) , nrounds = 2 ) <nl> pred < - predict ( bst , as . matrix ( iris [ , 1 : 4 ] ) ) <nl> } <nl> <nl> new file mode 100644 <nl> index 0000000000 . . 6e6babc4c4 <nl> mmm / dev / null <nl> ppp b / R - package / vignettes / xgboost . aux <nl> <nl> + \ relax <nl> + \ providecommand \ hyper @ newdestlabel [ 2 ] { } <nl> + \ providecommand \ HyperFirstAtBeginDocument { \ AtBeginDocument } <nl> + \ HyperFirstAtBeginDocument { \ ifx \ hyper @ anchor \ @ undefined <nl> + \ global \ let \ oldcontentsline \ contentsline <nl> + \ gdef \ contentsline # 1 # 2 # 3 # 4 { \ oldcontentsline { # 1 } { # 2 } { # 3 } } <nl> + \ global \ let \ oldnewlabel \ newlabel <nl> + \ gdef \ newlabel # 1 # 2 { \ newlabelxx { # 1 } # 2 } <nl> + \ gdef \ newlabelxx # 1 # 2 # 3 # 4 # 5 # 6 { \ oldnewlabel { # 1 } { { # 2 } { # 3 } } } <nl> + \ AtEndDocument { \ ifx \ hyper @ anchor \ @ undefined <nl> + \ let \ contentsline \ oldcontentsline <nl> + \ let \ newlabel \ oldnewlabel <nl> + \ fi } <nl> + \ fi } <nl> + \ global \ let \ hyper @ last \ relax <nl> + \ gdef \ HyperFirstAtBeginDocument # 1 { # 1 } <nl> + \ providecommand \ HyField @ AuxAddToFields [ 1 ] { } <nl> + \ providecommand \ HyField @ AuxAddToCoFields [ 2 ] { } <nl> + \ citation { friedman2001greedy } <nl> + \ @ writefile { toc } { \ contentsline { section } { \ numberline { 1 } Introduction } { 1 } { section . 1 } } <nl> + \ @ writefile { toc } { \ contentsline { section } { \ numberline { 2 } Example with iris } { 1 } { section . 2 } } <nl> + \ @ writefile { toc } { \ contentsline { section } { \ numberline { 3 } Advanced Examples } { 2 } { section . 3 } } <nl> + \ bibstyle { jss } <nl> + \ citation { * } <nl> + \ bibdata { xgboost } <nl> + \ bibcite { friedman2000additive } { { 1 } { 2000 } { { Friedman \ emph { et ~ al . } } } { { Friedman , Hastie , Tibshirani \ emph { et ~ al . } } } } <nl> + \ bibcite { friedman2001greedy } { { 2 } { 2001 } { { Friedman } } { { } } } <nl> + \ @ writefile { toc } { \ contentsline { section } { \ numberline { 4 } The Higgs Boson competition } { 3 } { section . 4 } } <nl> new file mode 100644 <nl> index 0000000000 . . fdf58e763f <nl> mmm / dev / null <nl> ppp b / R - package / vignettes / xgboost . bbl <nl> <nl> + \ begin { thebibliography } { 2 } <nl> + \ newcommand { \ enquote } [ 1 ] { ` ` # 1 ' ' } <nl> + \ providecommand { \ natexlab } [ 1 ] { # 1 } <nl> + \ providecommand { \ url } [ 1 ] { \ texttt { # 1 } } <nl> + \ providecommand { \ urlprefix } { URL } <nl> + \ expandafter \ ifx \ csname urlstyle \ endcsname \ relax <nl> + \ providecommand { \ doi } [ 1 ] { doi : \ discretionary { } { } { } # 1 } \ else <nl> + \ providecommand { \ doi } { doi : \ discretionary { } { } { } \ begingroup <nl> + \ urlstyle { rm } \ Url } \ fi <nl> + \ providecommand { \ eprint } [ 2 ] [ ] { \ url { # 2 } } <nl> + <nl> + \ bibitem [ { Friedman \ emph { et ~ al . } ( 2000 ) Friedman , Hastie , Tibshirani <nl> + \ emph { et ~ al . } } ] { friedman2000additive } <nl> + Friedman J , Hastie T , Tibshirani R , \ emph { et ~ al . } ( 2000 ) . <nl> + \ newblock \ enquote { Additive logistic regression : a statistical view of boosting <nl> + ( with discussion and a rejoinder by the authors ) . } <nl> + \ newblock \ emph { The annals of statistics } , \ textbf { 28 } ( 2 ) , 337 - - 407 . <nl> + <nl> + \ bibitem [ { Friedman ( 2001 ) } ] { friedman2001greedy } <nl> + Friedman JH ( 2001 ) . <nl> + \ newblock \ enquote { Greedy function approximation : a gradient boosting machine . } <nl> + \ newblock \ emph { Annals of Statistics } , pp . 1189 - - 1232 . <nl> + <nl> + \ end { thebibliography } <nl> new file mode 100644 <nl> index 0000000000 . . 2c0e87387d <nl> mmm / dev / null <nl> ppp b / R - package / vignettes / xgboost . blg <nl> <nl> + This is BibTeX , Version 0 . 99d ( TeX Live 2013 / Debian ) <nl> + Capacity : max_strings = 35307 , hash_size = 35307 , hash_prime = 30011 <nl> + The top - level auxiliary file : xgboost . aux <nl> + The style file : jss . bst <nl> + Database file # 1 : xgboost . bib <nl> + Reallocated wiz_functions ( elt_size = 4 ) to 6000 items from 3000 . <nl> + You ' ve used 2 entries , <nl> + 3140 wiz_defined - function locations , <nl> + 641 strings with 5430 characters , <nl> + and the built_in function - call counts , 1920 in all , are : <nl> + = - - 162 <nl> + > - - 44 <nl> + < - - 2 <nl> + + - - 17 <nl> + - - - 15 <nl> + * - - 149 <nl> + : = - - 256 <nl> + add . period $ - - 8 <nl> + call . type $ - - 2 <nl> + change . case $ - - 12 <nl> + chr . to . int $ - - 2 <nl> + cite $ - - 2 <nl> + duplicate $ - - 171 <nl> + empty $ - - 175 <nl> + format . name $ - - 19 <nl> + if $ - - 395 <nl> + int . to . chr $ - - 1 <nl> + int . to . str $ - - 1 <nl> + missing $ - - 24 <nl> + newline $ - - 21 <nl> + num . names $ - - 8 <nl> + pop $ - - 51 <nl> + preamble $ - - 1 <nl> + purify $ - - 12 <nl> + quote $ - - 0 <nl> + skip $ - - 53 <nl> + stack $ - - 0 <nl> + substring $ - - 181 <nl> + swap $ - - 65 <nl> + text . length $ - - 1 <nl> + text . prefix $ - - 0 <nl> + top $ - - 0 <nl> + type $ - - 18 <nl> + warning $ - - 0 <nl> + while $ - - 16 <nl> + width $ - - 0 <nl> + write $ - - 36 <nl> new file mode 100644 <nl> index 0000000000 . . 6d60796a37 <nl> mmm / dev / null <nl> ppp b / R - package / vignettes / xgboost . out <nl> <nl> + \ BOOKMARK [ 1 ] [ - ] { section . 1 } { Introduction } { } % 1 <nl> + \ BOOKMARK [ 1 ] [ - ] { section . 2 } { Example with iris } { } % 2 <nl> + \ BOOKMARK [ 1 ] [ - ] { section . 3 } { Advanced Examples } { } % 3 <nl> + \ BOOKMARK [ 1 ] [ - ] { section . 4 } { The Higgs Boson competition } { } % 4 <nl> new file mode 100644 <nl> index 0000000000 . . 0ed4015b70 <nl> mmm / dev / null <nl> ppp b / R - package / vignettes / xgboost . tex <nl> <nl> + \ documentclass { article } \ usepackage [ ] { graphicx } \ usepackage [ ] { color } <nl> + % % maxwidth is the original width if it is less than linewidth <nl> + % % otherwise use linewidth ( to make sure the graphics do not exceed the margin ) <nl> + \ makeatletter <nl> + \ def \ maxwidth { % <nl> + \ ifdim \ Gin @ nat @ width > \ linewidth <nl> + \ linewidth <nl> + \ else <nl> + \ Gin @ nat @ width <nl> + \ fi <nl> + } <nl> + \ makeatother <nl> + <nl> + \ definecolor { fgcolor } { rgb } { 0 . 345 , 0 . 345 , 0 . 345 } <nl> + \ newcommand { \ hlnum } [ 1 ] { \ textcolor [ rgb ] { 0 . 686 , 0 . 059 , 0 . 569 } { # 1 } } % <nl> + \ newcommand { \ hlstr } [ 1 ] { \ textcolor [ rgb ] { 0 . 192 , 0 . 494 , 0 . 8 } { # 1 } } % <nl> + \ newcommand { \ hlcom } [ 1 ] { \ textcolor [ rgb ] { 0 . 678 , 0 . 584 , 0 . 686 } { \ textit { # 1 } } } % <nl> + \ newcommand { \ hlopt } [ 1 ] { \ textcolor [ rgb ] { 0 , 0 , 0 } { # 1 } } % <nl> + \ newcommand { \ hlstd } [ 1 ] { \ textcolor [ rgb ] { 0 . 345 , 0 . 345 , 0 . 345 } { # 1 } } % <nl> + \ newcommand { \ hlkwa } [ 1 ] { \ textcolor [ rgb ] { 0 . 161 , 0 . 373 , 0 . 58 } { \ textbf { # 1 } } } % <nl> + \ newcommand { \ hlkwb } [ 1 ] { \ textcolor [ rgb ] { 0 . 69 , 0 . 353 , 0 . 396 } { # 1 } } % <nl> + \ newcommand { \ hlkwc } [ 1 ] { \ textcolor [ rgb ] { 0 . 333 , 0 . 667 , 0 . 333 } { # 1 } } % <nl> + \ newcommand { \ hlkwd } [ 1 ] { \ textcolor [ rgb ] { 0 . 737 , 0 . 353 , 0 . 396 } { \ textbf { # 1 } } } % <nl> + <nl> + \ usepackage { framed } <nl> + \ makeatletter <nl> + \ newenvironment { kframe } { % <nl> + \ def \ at @ end @ of @ kframe { } % <nl> + \ ifinner \ ifhmode % <nl> + \ def \ at @ end @ of @ kframe { \ end { minipage } } % <nl> + \ begin { minipage } { \ columnwidth } % <nl> + \ fi \ fi % <nl> + \ def \ FrameCommand # # 1 { \ hskip \ @ totalleftmargin \ hskip - \ fboxsep <nl> + \ colorbox { shadecolor } { # # 1 } \ hskip - \ fboxsep <nl> + % There is no \ \ @ totalrightmargin , so : <nl> + \ hskip - \ linewidth \ hskip - \ @ totalleftmargin \ hskip \ columnwidth } % <nl> + \ MakeFramed { \ advance \ hsize - \ width <nl> + \ @ totalleftmargin \ z @ \ linewidth \ hsize <nl> + \ @ setminipage } } % <nl> + { \ par \ unskip \ endMakeFramed % <nl> + \ at @ end @ of @ kframe } <nl> + \ makeatother <nl> + <nl> + \ definecolor { shadecolor } { rgb } { . 97 , . 97 , . 97 } <nl> + \ definecolor { messagecolor } { rgb } { 0 , 0 , 0 } <nl> + \ definecolor { warningcolor } { rgb } { 1 , 0 , 1 } <nl> + \ definecolor { errorcolor } { rgb } { 1 , 0 , 0 } <nl> + \ newenvironment { knitrout } { } { } % an empty environment to be redefined in TeX <nl> + <nl> + \ usepackage { alltt } <nl> + \ RequirePackage { url } <nl> + \ usepackage { hyperref } <nl> + \ RequirePackage { amsmath } <nl> + \ RequirePackage { natbib } <nl> + \ RequirePackage [ a4paper , lmargin = { 1 . 25in } , rmargin = { 1 . 25in } , tmargin = { 1in } , bmargin = { 1in } ] { geometry } <nl> + <nl> + \ makeatletter <nl> + % \ VignetteIndexEntry { xgboost : eXtreme Gradient Boosting } <nl> + % \ VignetteKeywords { xgboost , gbm , gradient boosting machines } <nl> + % \ VignettePackage { xgboost } <nl> + % \ VignetteEngine { knitr : : knitr } <nl> + \ makeatother <nl> + \ IfFileExists { upquote . sty } { \ usepackage { upquote } } { } <nl> + \ begin { document } <nl> + % \ SweaveOpts { concordance = TRUE } <nl> + <nl> + <nl> + <nl> + % <nl> + <nl> + % <nl> + <nl> + \ begin { center } <nl> + \ vspace * { 6 \ baselineskip } <nl> + \ rule { \ textwidth } { 1 . 6pt } \ vspace * { - \ baselineskip } \ vspace * { 2pt } <nl> + \ rule { \ textwidth } { 0 . 4pt } \ \ [ 2 \ baselineskip ] <nl> + { \ LARGE \ textbf { xgboost : eXtreme Gradient Boosting } } \ \ [ 1 . 2 \ baselineskip ] <nl> + \ rule { \ textwidth } { 0 . 4pt } \ vspace * { - \ baselineskip } \ vspace { 3 . 2pt } <nl> + \ rule { \ textwidth } { 1 . 6pt } \ \ [ 2 \ baselineskip ] <nl> + { \ Large Tianqi Chen , Tong He } \ \ [ \ baselineskip ] <nl> + { \ large Package Version : 0 . 3 - 0 } \ \ [ \ baselineskip ] <nl> + { \ large \ today } \ par <nl> + \ vfill <nl> + \ end { center } <nl> + <nl> + \ thispagestyle { empty } <nl> + <nl> + \ clearpage <nl> + <nl> + \ setcounter { page } { 1 } <nl> + <nl> + \ section { Introduction } <nl> + <nl> + This is an introductory document of using the \ verb @ xgboost @ package in R . <nl> + <nl> + \ verb @ xgboost @ is short for eXtreme Gradient Boosting package . It is an efficient <nl> + and scalable implementation of gradient boosting framework by \ citep { friedman2001greedy } . <nl> + The package includes efficient linear model solver and tree learning algorithm . <nl> + It supports various objective functions , including regression , classification <nl> + and ranking . The package is made to be extendible , so that users are also allowed to define their own objectives easily . It has several features : <nl> + \ begin { enumerate } <nl> + \ item { Speed : } { \ verb @ xgboost @ can automatically do parallel computation on <nl> + Windows and Linux , with openmp . It is generally over 10 times faster than <nl> + \ verb @ gbm @ . } <nl> + \ item { Input Type : } { \ verb @ xgboost @ takes several types of input data : } <nl> + \ begin { itemize } <nl> + \ item { Dense Matrix : } { R ' s dense matrix , i . e . \ verb @ matrix @ } <nl> + \ item { Sparse Matrix : } { R ' s sparse matrix \ verb @ Matrix : : dgCMatrix @ } <nl> + \ item { Data File : } { Local data files } <nl> + \ item { xgb . DMatrix : } { \ verb @ xgboost @ ' s own class . Recommended . } <nl> + \ end { itemize } <nl> + \ item { Sparsity : } { \ verb @ xgboost @ accepts sparse input for both tree booster <nl> + and linear booster , and is optimized for sparse input . } <nl> + \ item { Customization : } { \ verb @ xgboost @ supports customized objective function <nl> + and evaluation function } <nl> + \ item { Performance : } { \ verb @ xgboost @ has better performance on several different <nl> + datasets . } <nl> + \ end { enumerate } <nl> + <nl> + <nl> + \ section { Example with iris } <nl> + <nl> + In this section , we will illustrate some common usage of \ verb @ xgboost @ . <nl> + <nl> + \ begin { knitrout } <nl> + \ definecolor { shadecolor } { rgb } { 0 . 969 , 0 . 969 , 0 . 969 } \ color { fgcolor } \ begin { kframe } <nl> + \ begin { alltt } <nl> + \ hlkwd { library } \ hlstd { ( xgboost ) } <nl> + \ hlkwd { data } \ hlstd { ( iris ) } <nl> + \ hlstd { bst } \ hlkwb { < - } \ hlkwd { xgboost } \ hlstd { ( } \ hlkwd { as . matrix } \ hlstd { ( iris [ , } \ hlnum { 1 } \ hlopt { : } \ hlnum { 4 } \ hlstd { ] ) , } \ hlkwd { as . numeric } \ hlstd { ( iris [ , } \ hlnum { 5 } \ hlstd { ] } \ hlopt { = = } \ hlstr { ' setosa ' } \ hlstd { ) , } <nl> + \ hlkwc { nrounds } \ hlstd { = } \ hlnum { 5 } \ hlstd { ) } <nl> + \ end { alltt } <nl> + \ begin { verbatim } <nl> + # # [ 0 ] train - rmse : 0 . 351971 <nl> + # # [ 1 ] train - rmse : 0 . 247769 <nl> + # # [ 2 ] train - rmse : 0 . 174418 <nl> + # # [ 3 ] train - rmse : 0 . 122783 <nl> + # # [ 4 ] train - rmse : 0 . 086435 <nl> + \ end { verbatim } <nl> + \ begin { alltt } <nl> + \ hlkwd { xgb . save } \ hlstd { ( bst , } \ hlstr { ' model . save ' } \ hlstd { ) } <nl> + \ end { alltt } <nl> + \ begin { verbatim } <nl> + # # [ 1 ] TRUE <nl> + \ end { verbatim } <nl> + \ begin { alltt } <nl> + \ hlstd { bst } \ hlkwb { = } \ hlkwd { xgb . load } \ hlstd { ( } \ hlstr { ' model . save ' } \ hlstd { ) } <nl> + \ hlstd { pred } \ hlkwb { < - } \ hlkwd { predict } \ hlstd { ( bst , } \ hlkwd { as . matrix } \ hlstd { ( iris [ , } \ hlnum { 1 } \ hlopt { : } \ hlnum { 4 } \ hlstd { ] ) ) } <nl> + \ end { alltt } <nl> + \ end { kframe } <nl> + \ end { knitrout } <nl> + <nl> + \ verb @ xgboost @ is the main function to train a \ verb @ Booster @ , i . e . a model . <nl> + \ verb @ predict @ does prediction on the model . <nl> + <nl> + Here we can save the model to a binary local file , and load it when needed . <nl> + We can ' t inspect the trees inside . However we have another function to save the <nl> + model in plain text . <nl> + \ begin { knitrout } <nl> + \ definecolor { shadecolor } { rgb } { 0 . 969 , 0 . 969 , 0 . 969 } \ color { fgcolor } \ begin { kframe } <nl> + \ begin { alltt } <nl> + \ hlkwd { xgb . dump } \ hlstd { ( bst , } \ hlstr { ' model . dump ' } \ hlstd { ) } <nl> + \ end { alltt } <nl> + \ begin { verbatim } <nl> + # # [ 1 ] TRUE <nl> + \ end { verbatim } <nl> + \ end { kframe } <nl> + \ end { knitrout } <nl> + <nl> + The output looks like <nl> + <nl> + \ begin { verbatim } <nl> + booster [ 0 ] : <nl> + 0 : [ f2 < 2 . 45 ] yes = 1 , no = 2 , missing = 1 <nl> + 1 : leaf = 0 . 147059 <nl> + 2 : [ f3 < 1 . 65 ] yes = 3 , no = 4 , missing = 3 <nl> + 3 : leaf = 0 . 464151 <nl> + 4 : leaf = 0 . 722449 <nl> + booster [ 1 ] : <nl> + 0 : [ f2 < 2 . 45 ] yes = 1 , no = 2 , missing = 1 <nl> + 1 : leaf = 0 . 103806 <nl> + 2 : [ f2 < 4 . 85 ] yes = 3 , no = 4 , missing = 3 <nl> + 3 : leaf = 0 . 316341 <nl> + 4 : leaf = 0 . 510365 <nl> + \ end { verbatim } <nl> + <nl> + It is important to know \ verb @ xgboost @ ' s own data type : \ verb @ xgb . DMatrix @ . <nl> + It speeds up \ verb @ xgboost @ , and is needed for advanced features such as <nl> + training from initial prediction value , weighted training instance . <nl> + <nl> + We can use \ verb @ xgb . DMatrix @ to construct an \ verb @ xgb . DMatrix @ object : <nl> + \ begin { knitrout } <nl> + \ definecolor { shadecolor } { rgb } { 0 . 969 , 0 . 969 , 0 . 969 } \ color { fgcolor } \ begin { kframe } <nl> + \ begin { alltt } <nl> + \ hlstd { iris . mat } \ hlkwb { < - } \ hlkwd { as . matrix } \ hlstd { ( iris [ , } \ hlnum { 1 } \ hlopt { : } \ hlnum { 4 } \ hlstd { ] ) } <nl> + \ hlstd { iris . label } \ hlkwb { < - } \ hlkwd { as . numeric } \ hlstd { ( iris [ , } \ hlnum { 5 } \ hlstd { ] } \ hlopt { = = } \ hlstr { ' setosa ' } \ hlstd { ) } <nl> + \ hlstd { diris } \ hlkwb { < - } \ hlkwd { xgb . DMatrix } \ hlstd { ( iris . mat , } \ hlkwc { label } \ hlstd { = iris . label ) } <nl> + \ hlkwd { class } \ hlstd { ( diris ) } <nl> + \ end { alltt } <nl> + \ begin { verbatim } <nl> + # # [ 1 ] " xgb . DMatrix " <nl> + \ end { verbatim } <nl> + \ begin { alltt } <nl> + \ hlkwd { getinfo } \ hlstd { ( diris , } \ hlstr { ' label ' } \ hlstd { ) } <nl> + \ end { alltt } <nl> + \ begin { verbatim } <nl> + # # [ 1 ] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 <nl> + # # [ 36 ] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 <nl> + # # [ 71 ] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 <nl> + # # [ 106 ] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 <nl> + # # [ 141 ] 0 0 0 0 0 0 0 0 0 0 <nl> + \ end { verbatim } <nl> + \ end { kframe } <nl> + \ end { knitrout } <nl> + <nl> + We can also save the matrix to a binary file . Then load it simply with <nl> + \ verb @ xgb . DMatrix @ <nl> + \ begin { knitrout } <nl> + \ definecolor { shadecolor } { rgb } { 0 . 969 , 0 . 969 , 0 . 969 } \ color { fgcolor } \ begin { kframe } <nl> + \ begin { alltt } <nl> + \ hlkwd { xgb . DMatrix . save } \ hlstd { ( diris , } \ hlstr { ' iris . xgb . DMatrix ' } \ hlstd { ) } <nl> + \ end { alltt } <nl> + \ begin { verbatim } <nl> + # # 150x4 matrix with 600 entries is saved to iris . xgb . DMatrix <nl> + # # [ 1 ] TRUE <nl> + \ end { verbatim } <nl> + \ begin { alltt } <nl> + \ hlstd { diris } \ hlkwb { = } \ hlkwd { xgb . DMatrix } \ hlstd { ( } \ hlstr { ' iris . xgb . DMatrix ' } \ hlstd { ) } <nl> + \ end { alltt } <nl> + \ begin { verbatim } <nl> + # # 150x4 matrix with 600 entries is loaded from iris . xgb . DMatrix <nl> + \ end { verbatim } <nl> + \ end { kframe } <nl> + \ end { knitrout } <nl> + <nl> + \ section { Advanced Examples } <nl> + <nl> + The function \ verb @ xgboost @ is a simple function with less parameter , in order <nl> + to be R - friendly . The core training function is wrapped in \ verb @ xgb . train @ . It is more flexible than \ verb @ xgboost @ , but it requires users to read the document a bit more carefully . <nl> + <nl> + \ verb @ xgb . train @ only accept a \ verb @ xgb . DMatrix @ object as its input , while it supports advanced features as custom objective and evaluation functions . <nl> + <nl> + \ begin { knitrout } <nl> + \ definecolor { shadecolor } { rgb } { 0 . 969 , 0 . 969 , 0 . 969 } \ color { fgcolor } \ begin { kframe } <nl> + \ begin { alltt } <nl> + \ hlstd { logregobj } \ hlkwb { < - } \ hlkwa { function } \ hlstd { ( } \ hlkwc { preds } \ hlstd { , } \ hlkwc { dtrain } \ hlstd { ) \ { } <nl> + \ hlstd { labels } \ hlkwb { < - } \ hlkwd { getinfo } \ hlstd { ( dtrain , } \ hlstr { " label " } \ hlstd { ) } <nl> + \ hlstd { preds } \ hlkwb { < - } \ hlnum { 1 } \ hlopt { / } \ hlstd { ( } \ hlnum { 1 } \ hlopt { + } \ hlkwd { exp } \ hlstd { ( } \ hlopt { - } \ hlstd { preds ) ) } <nl> + \ hlstd { grad } \ hlkwb { < - } \ hlstd { preds } \ hlopt { - } \ hlstd { labels } <nl> + \ hlstd { hess } \ hlkwb { < - } \ hlstd { preds } \ hlopt { * } \ hlstd { ( } \ hlnum { 1 } \ hlopt { - } \ hlstd { preds ) } <nl> + \ hlkwd { return } \ hlstd { ( } \ hlkwd { list } \ hlstd { ( } \ hlkwc { grad } \ hlstd { = grad , } \ hlkwc { hess } \ hlstd { = hess ) ) } <nl> + \ hlstd { \ } } <nl> + <nl> + \ hlstd { evalerror } \ hlkwb { < - } \ hlkwa { function } \ hlstd { ( } \ hlkwc { preds } \ hlstd { , } \ hlkwc { dtrain } \ hlstd { ) \ { } <nl> + \ hlstd { labels } \ hlkwb { < - } \ hlkwd { getinfo } \ hlstd { ( dtrain , } \ hlstr { " label " } \ hlstd { ) } <nl> + \ hlstd { err } \ hlkwb { < - } \ hlkwd { sqrt } \ hlstd { ( } \ hlkwd { mean } \ hlstd { ( ( preds } \ hlopt { - } \ hlstd { labels ) } \ hlopt { ^ } \ hlnum { 2 } \ hlstd { ) ) } <nl> + \ hlkwd { return } \ hlstd { ( } \ hlkwd { list } \ hlstd { ( } \ hlkwc { metric } \ hlstd { = } \ hlstr { " MSE " } \ hlstd { , } \ hlkwc { value } \ hlstd { = err ) ) } <nl> + \ hlstd { \ } } <nl> + <nl> + \ hlstd { dtest } \ hlkwb { < - } \ hlkwd { slice } \ hlstd { ( diris , } \ hlnum { 1 } \ hlopt { : } \ hlnum { 100 } \ hlstd { ) } <nl> + \ hlstd { watchlist } \ hlkwb { < - } \ hlkwd { list } \ hlstd { ( } \ hlkwc { eval } \ hlstd { = dtest , } \ hlkwc { train } \ hlstd { = diris ) } <nl> + \ hlstd { param } \ hlkwb { < - } \ hlkwd { list } \ hlstd { ( } \ hlkwc { max_depth } \ hlstd { = } \ hlnum { 2 } \ hlstd { , } \ hlkwc { eta } \ hlstd { = } \ hlnum { 1 } \ hlstd { , } \ hlkwc { silent } \ hlstd { = } \ hlnum { 1 } \ hlstd { ) } <nl> + <nl> + \ hlstd { bst } \ hlkwb { < - } \ hlkwd { xgb . train } \ hlstd { ( param , diris , } \ hlkwc { nround } \ hlstd { = } \ hlnum { 2 } \ hlstd { , watchlist , logregobj , evalerror ) } <nl> + \ end { alltt } <nl> + \ begin { verbatim } <nl> + # # [ 1 ] eval - MSE : 1 . 601 train - MSE : 1 . 76 <nl> + # # [ 2 ] eval - MSE : 2 . 567 train - MSE : 2 . 745 <nl> + \ end { verbatim } <nl> + \ end { kframe } <nl> + \ end { knitrout } <nl> + <nl> + The gradient and second order gradient is required for the output of customized <nl> + objective function . <nl> + <nl> + We also have \ verb @ slice @ for row extraction . It is useful in <nl> + cross - validation . <nl> + <nl> + For a walkthrough demo , please see \ verb @ R - package / inst / examples / demo . R @ for further <nl> + details . <nl> + <nl> + \ section { The Higgs Boson competition } <nl> + <nl> + We have made a demo for \ href { http : / / www . kaggle . com / c / higgs - boson } { the Higgs <nl> + Boson Machine Learning Challenge } . <nl> + <nl> + Here are the instructions to make a submission <nl> + \ begin { enumerate } <nl> + \ item Download the \ href { http : / / www . kaggle . com / c / higgs - boson / data } { datasets } <nl> + and extract them to \ verb @ data / @ . <nl> + \ item Run scripts under \ verb @ xgboost / demo / kaggle - higgs / @ : <nl> + \ href { https : / / github . com / tqchen / xgboost / blob / master / demo / kaggle - higgs / higgs - train . R } { higgs - train . R } <nl> + and \ href { https : / / github . com / tqchen / xgboost / blob / master / demo / kaggle - higgs / higgs - pred . R } { higgs - pred . R } . <nl> + The computation will take less than a minute on Intel i7 . <nl> + \ item Go to the \ href { http : / / www . kaggle . com / c / higgs - boson / submissions / attach } { submission page } <nl> + and submit your result . <nl> + \ end { enumerate } <nl> + <nl> + We provide \ href { https : / / github . com / tqchen / xgboost / blob / master / demo / kaggle - higgs / speedtest . R } { a script } <nl> + to compare the time cost on the higgs dataset with \ verb @ gbm @ and \ verb @ xgboost @ . <nl> + The training set contains 350000 records and 30 features . <nl> + <nl> + \ verb @ xgboost @ can automatically do parallel computation . On a machine with Intel <nl> + i7 - 4700MQ and 24GB memories , we found that \ verb @ xgboost @ costs about 35 seconds , which is about 20 times faster <nl> + than \ verb @ gbm @ . When we limited \ verb @ xgboost @ to use only one thread , it was <nl> + still about two times faster than \ verb @ gbm @ . <nl> + <nl> + Meanwhile , the result from \ verb @ xgboost @ reaches <nl> + \ href { http : / / www . kaggle . com / c / higgs - boson / details / evaluation } { 3 . 60 @ AMS } with a <nl> + single model . This results stands in the <nl> + \ href { http : / / www . kaggle . com / c / higgs - boson / leaderboard } { top 30 \ % } of the <nl> + competition . <nl> + <nl> + \ bibliographystyle { jss } <nl> + \ nocite { * } % list uncited references <nl> + \ bibliography { xgboost } <nl> + <nl> + \ end { document } <nl> + <nl>
|
fix iris to Rd files
|
dmlc/xgboost
|
801a17fa02cf4357caf292724b876f0c8807e7dc
|
2014-09-06T02:47:58Z
|
mmm a / src / api - natives . cc <nl> ppp b / src / api - natives . cc <nl> MaybeHandle < Object > DefineDataProperty ( Isolate * isolate , <nl> ASSIGN_RETURN_ON_EXCEPTION ( isolate , value , <nl> Instantiate ( isolate , prop_data , key ) , Object ) ; <nl> <nl> + uint32_t index = 0 ; <nl> + LookupIterator : : Configuration c = LookupIterator : : OWN_SKIP_INTERCEPTOR ; <nl> + LookupIterator it = key - > AsArrayIndex ( & index ) <nl> + ? LookupIterator ( isolate , object , index , c ) <nl> + : LookupIterator ( object , key , c ) ; <nl> + <nl> # ifdef DEBUG <nl> - bool duplicate ; <nl> - if ( key - > IsName ( ) ) { <nl> - LookupIterator it ( object , Handle < Name > : : cast ( key ) , <nl> - LookupIterator : : OWN_SKIP_INTERCEPTOR ) ; <nl> - Maybe < PropertyAttributes > maybe = JSReceiver : : GetPropertyAttributes ( & it ) ; <nl> - DCHECK ( maybe . IsJust ( ) ) ; <nl> - duplicate = it . IsFound ( ) ; <nl> - } else { <nl> - uint32_t index = 0 ; <nl> - key - > ToArrayIndex ( & index ) ; <nl> - Maybe < bool > maybe = JSReceiver : : HasOwnElement ( object , index ) ; <nl> - if ( ! maybe . IsJust ( ) ) return MaybeHandle < Object > ( ) ; <nl> - duplicate = maybe . FromJust ( ) ; <nl> - } <nl> - if ( duplicate ) { <nl> + Maybe < PropertyAttributes > maybe = JSReceiver : : GetPropertyAttributes ( & it ) ; <nl> + DCHECK ( maybe . IsJust ( ) ) ; <nl> + if ( it . IsFound ( ) ) { <nl> THROW_NEW_ERROR ( <nl> isolate , NewTypeError ( MessageTemplate : : kDuplicateTemplateProperty , key ) , <nl> Object ) ; <nl> } <nl> # endif <nl> <nl> - RETURN_ON_EXCEPTION ( <nl> - isolate , Runtime : : DefineObjectProperty ( object , key , value , attributes ) , <nl> - Object ) ; <nl> - return object ; <nl> + return Object : : AddDataProperty ( & it , value , attributes , STRICT , <nl> + Object : : CERTAINLY_NOT_STORE_FROM_KEYED ) ; <nl> } <nl> <nl> <nl> mmm a / src / api . cc <nl> ppp b / src / api . cc <nl> Maybe < bool > v8 : : Object : : CreateDataProperty ( v8 : : Local < v8 : : Context > context , <nl> <nl> if ( it . IsFound ( ) & & ! it . IsConfigurable ( ) ) return Just ( false ) ; <nl> <nl> - has_pending_exception = i : : Runtime : : DefineObjectProperty ( <nl> + has_pending_exception = i : : JSObject : : SetOwnPropertyIgnoreAttributes ( <nl> self , key_obj , value_obj , NONE ) . is_null ( ) ; <nl> RETURN_ON_FAILED_EXECUTION_PRIMITIVE ( bool ) ; <nl> return Just ( true ) ; <nl> Maybe < bool > v8 : : Object : : CreateDataProperty ( v8 : : Local < v8 : : Context > context , <nl> return Just ( false ) ; <nl> } <nl> <nl> - has_pending_exception = i : : Runtime : : DefineObjectProperty ( <nl> - self , isolate - > factory ( ) - > Uint32ToString ( index ) , <nl> - value_obj , NONE ) . is_null ( ) ; <nl> + has_pending_exception = i : : JSObject : : SetOwnElementIgnoreAttributes ( <nl> + self , index , value_obj , NONE ) . is_null ( ) ; <nl> RETURN_ON_FAILED_EXECUTION_PRIMITIVE ( bool ) ; <nl> return Just ( true ) ; <nl> } <nl> Maybe < bool > v8 : : Object : : DefineOwnProperty ( v8 : : Local < v8 : : Context > context , <nl> } <nl> <nl> <nl> + MUST_USE_RESULT <nl> + static i : : MaybeHandle < i : : Object > DefineObjectProperty ( <nl> + i : : Handle < i : : JSObject > js_object , i : : Handle < i : : Object > key , <nl> + i : : Handle < i : : Object > value , PropertyAttributes attrs ) { <nl> + i : : Isolate * isolate = js_object - > GetIsolate ( ) ; <nl> + / / Check if the given key is an array index . <nl> + uint32_t index = 0 ; <nl> + if ( key - > ToArrayIndex ( & index ) ) { <nl> + return i : : JSObject : : SetOwnElementIgnoreAttributes ( js_object , index , value , <nl> + attrs ) ; <nl> + } <nl> + <nl> + i : : Handle < i : : Name > name ; <nl> + if ( key - > IsName ( ) ) { <nl> + name = i : : Handle < i : : Name > : : cast ( key ) ; <nl> + } else { <nl> + / / Call - back into JavaScript to convert the key to a string . <nl> + i : : Handle < i : : Object > converted ; <nl> + ASSIGN_RETURN_ON_EXCEPTION_VALUE ( isolate , converted , <nl> + i : : Execution : : ToString ( isolate , key ) , <nl> + i : : MaybeHandle < i : : Object > ( ) ) ; <nl> + name = i : : Handle < i : : String > : : cast ( converted ) ; <nl> + } <nl> + <nl> + return i : : JSObject : : DefinePropertyOrElement ( js_object , name , value , attrs ) ; <nl> + } <nl> + <nl> + <nl> Maybe < bool > v8 : : Object : : ForceSet ( v8 : : Local < v8 : : Context > context , <nl> v8 : : Local < Value > key , v8 : : Local < Value > value , <nl> v8 : : PropertyAttribute attribs ) { <nl> Maybe < bool > v8 : : Object : : ForceSet ( v8 : : Local < v8 : : Context > context , <nl> auto self = Utils : : OpenHandle ( this ) ; <nl> auto key_obj = Utils : : OpenHandle ( * key ) ; <nl> auto value_obj = Utils : : OpenHandle ( * value ) ; <nl> - has_pending_exception = i : : Runtime : : DefineObjectProperty ( <nl> - self , <nl> - key_obj , <nl> - value_obj , <nl> - static_cast < PropertyAttributes > ( attribs ) ) . is_null ( ) ; <nl> + has_pending_exception = <nl> + DefineObjectProperty ( self , key_obj , value_obj , <nl> + static_cast < PropertyAttributes > ( attribs ) ) . is_null ( ) ; <nl> RETURN_ON_FAILED_EXECUTION_PRIMITIVE ( bool ) ; <nl> return Just ( true ) ; <nl> } <nl> bool v8 : : Object : : ForceSet ( v8 : : Handle < Value > key , v8 : : Handle < Value > value , <nl> i : : Handle < i : : Object > key_obj = Utils : : OpenHandle ( * key ) ; <nl> i : : Handle < i : : Object > value_obj = Utils : : OpenHandle ( * value ) ; <nl> has_pending_exception = <nl> - i : : Runtime : : DefineObjectProperty ( self , key_obj , value_obj , <nl> - static_cast < PropertyAttributes > ( attribs ) ) <nl> - . is_null ( ) ; <nl> + DefineObjectProperty ( self , key_obj , value_obj , <nl> + static_cast < PropertyAttributes > ( attribs ) ) . is_null ( ) ; <nl> EXCEPTION_BAILOUT_CHECK_SCOPED ( isolate , false ) ; <nl> return true ; <nl> } <nl> mmm a / src / bootstrapper . cc <nl> ppp b / src / bootstrapper . cc <nl> void Genesis : : HookUpGlobalObject ( Handle < GlobalObject > global_object , <nl> <nl> static const PropertyAttributes attributes = <nl> static_cast < PropertyAttributes > ( READ_ONLY | DONT_DELETE ) ; <nl> - Runtime : : DefineObjectProperty ( builtins_global , factory ( ) - > global_string ( ) , <nl> - global_object , attributes ) . Assert ( ) ; <nl> + JSObject : : SetOwnPropertyIgnoreAttributes ( builtins_global , <nl> + factory ( ) - > global_string ( ) , <nl> + global_object , attributes ) . Assert ( ) ; <nl> / / Set up the reference from the global object to the builtins object . <nl> JSGlobalObject : : cast ( * global_object ) - > set_builtins ( * builtins_global ) ; <nl> TransferNamedProperties ( global_object_from_snapshot , global_object ) ; <nl> mmm a / src / ic / ic . cc <nl> ppp b / src / ic / ic . cc <nl> static Handle < Object > TryConvertKey ( Handle < Object > key , Isolate * isolate ) { <nl> } else { <nl> int int_value = FastD2I ( value ) ; <nl> if ( value = = int_value & & Smi : : IsValid ( int_value ) ) { <nl> - key = Handle < Smi > ( Smi : : FromInt ( int_value ) , isolate ) ; <nl> + key = handle ( Smi : : FromInt ( int_value ) , isolate ) ; <nl> } <nl> } <nl> } else if ( key - > IsUndefined ( ) ) { <nl> mmm a / src / json - parser . h <nl> ppp b / src / json - parser . h <nl> Handle < Object > JsonParser < seq_one_byte > : : ParseJsonObject ( ) { <nl> / / Commit the intermediate state to the object and stop transitioning . <nl> CommitStateToJsonObject ( json_object , map , & properties ) ; <nl> <nl> - Runtime : : DefineObjectProperty ( json_object , key , value , NONE ) . Check ( ) ; <nl> + JSObject : : DefinePropertyOrElement ( json_object , key , value ) . Check ( ) ; <nl> } while ( transitioning & & MatchSkipWhiteSpace ( ' , ' ) ) ; <nl> <nl> / / If we transitioned until the very end , transition the map now . <nl> Handle < Object > JsonParser < seq_one_byte > : : ParseJsonObject ( ) { <nl> value = ParseJsonValue ( ) ; <nl> if ( value . is_null ( ) ) return ReportUnexpectedCharacter ( ) ; <nl> <nl> - Runtime : : DefineObjectProperty ( json_object , key , value , NONE ) . Check ( ) ; <nl> + JSObject : : DefinePropertyOrElement ( json_object , key , value ) . Check ( ) ; <nl> } <nl> } <nl> <nl> mmm a / src / lookup . cc <nl> ppp b / src / lookup . cc <nl> Handle < Object > LookupIterator : : GetDataValue ( ) const { <nl> } <nl> <nl> <nl> - Handle < Object > LookupIterator : : WriteDataValue ( Handle < Object > value ) { <nl> + void LookupIterator : : WriteDataValue ( Handle < Object > value ) { <nl> DCHECK_EQ ( DATA , state_ ) ; <nl> Handle < JSObject > holder = GetHolder < JSObject > ( ) ; <nl> if ( IsElement ( ) ) { <nl> ElementsAccessor * accessor = holder - > GetElementsAccessor ( ) ; <nl> - return accessor - > Set ( holder , index_ , value ) ; <nl> + accessor - > Set ( holder , index_ , value ) ; <nl> } else if ( holder - > IsGlobalObject ( ) ) { <nl> Handle < GlobalDictionary > property_dictionary = <nl> handle ( holder - > global_dictionary ( ) ) ; <nl> Handle < Object > LookupIterator : : WriteDataValue ( Handle < Object > value ) { <nl> } else { <nl> DCHECK_EQ ( v8 : : internal : : DATA_CONSTANT , property_details_ . type ( ) ) ; <nl> } <nl> - return value ; <nl> } <nl> <nl> <nl> mmm a / src / lookup . h <nl> ppp b / src / lookup . h <nl> class LookupIterator final BASE_EMBEDDED { <nl> holder_map_ ( holder_ - > map ( ) , isolate_ ) , <nl> initial_holder_ ( holder_ ) , <nl> number_ ( DescriptorArray : : kNotFound ) { <nl> - # if 0 / / TODO ( verwaest ) : Enable once blocking hacks are removed . <nl> # ifdef DEBUG <nl> uint32_t index ; / / Assert that the name is not an array index . <nl> DCHECK ( ! name - > AsArrayIndex ( & index ) ) ; <nl> # endif / / DEBUG <nl> - # endif <nl> Next ( ) ; <nl> } <nl> <nl> class LookupIterator final BASE_EMBEDDED { <nl> holder_map_ ( holder_ - > map ( ) , isolate_ ) , <nl> initial_holder_ ( holder_ ) , <nl> number_ ( DescriptorArray : : kNotFound ) { <nl> - # if 0 / / TODO ( verwaest ) : Enable once blocking hacks are removed . <nl> # ifdef DEBUG <nl> uint32_t index ; / / Assert that the name is not an array index . <nl> DCHECK ( ! name - > AsArrayIndex ( & index ) ) ; <nl> # endif / / DEBUG <nl> - # endif <nl> Next ( ) ; <nl> } <nl> <nl> class LookupIterator final BASE_EMBEDDED { <nl> Handle < Object > GetAccessors ( ) const ; <nl> Handle < InterceptorInfo > GetInterceptor ( ) const ; <nl> Handle < Object > GetDataValue ( ) const ; <nl> - / / Usually returns the value that was passed in . In case of typed array <nl> - / / accesses it returns the converted value . <nl> - Handle < Object > WriteDataValue ( Handle < Object > value ) ; <nl> + void WriteDataValue ( Handle < Object > value ) ; <nl> void InternalizeName ( ) ; <nl> <nl> private : <nl> mmm a / src / objects - inl . h <nl> ppp b / src / objects - inl . h <nl> MaybeHandle < Object > Object : : GetProperty ( Isolate * isolate , <nl> } <nl> <nl> <nl> + MaybeHandle < Object > JSObject : : DefinePropertyOrElement ( <nl> + Handle < JSObject > object , Handle < Name > name , Handle < Object > value , <nl> + PropertyAttributes attributes ) { <nl> + uint32_t index ; <nl> + if ( name - > AsArrayIndex ( & index ) ) { <nl> + return SetOwnElementIgnoreAttributes ( object , index , value , attributes ) ; <nl> + } <nl> + <nl> + / / TODO ( verwaest ) : Is this necessary ? <nl> + if ( name - > IsString ( ) ) name = String : : Flatten ( Handle < String > : : cast ( name ) ) ; <nl> + return SetOwnPropertyIgnoreAttributes ( object , name , value , attributes ) ; <nl> + } <nl> + <nl> + <nl> # define FIELD_ADDR ( p , offset ) \ <nl> ( reinterpret_cast < byte * > ( p ) + offset - kHeapObjectTag ) <nl> <nl> mmm a / src / objects . cc <nl> ppp b / src / objects . cc <nl> MaybeHandle < Object > Object : : WriteToReadOnlyProperty ( <nl> } <nl> <nl> <nl> - MaybeHandle < Object > Object : : WriteToReadOnlyElement ( Isolate * isolate , <nl> - Handle < Object > receiver , <nl> - uint32_t index , <nl> - Handle < Object > value , <nl> - LanguageMode language_mode ) { <nl> - return WriteToReadOnlyProperty ( isolate , receiver , <nl> - isolate - > factory ( ) - > NewNumberFromUint ( index ) , <nl> - value , language_mode ) ; <nl> - } <nl> - <nl> - <nl> MaybeHandle < Object > Object : : RedefineNonconfigurableProperty ( <nl> Isolate * isolate , Handle < Object > name , Handle < Object > value , <nl> LanguageMode language_mode ) { <nl> MaybeHandle < Object > Object : : SetDataProperty ( LookupIterator * it , <nl> MaybeHandle < Object > maybe_old ; <nl> if ( is_observed ) maybe_old = it - > GetDataValue ( ) ; <nl> <nl> + Handle < Object > to_assign = value ; <nl> / / Convert the incoming value to a number for storing into typed arrays . <nl> if ( it - > IsElement ( ) & & ( receiver - > HasExternalArrayElements ( ) | | <nl> receiver - > HasFixedTypedArrayElements ( ) ) ) { <nl> if ( ! value - > IsNumber ( ) & & ! value - > IsUndefined ( ) ) { <nl> - ASSIGN_RETURN_ON_EXCEPTION ( it - > isolate ( ) , value , <nl> + ASSIGN_RETURN_ON_EXCEPTION ( it - > isolate ( ) , to_assign , <nl> Execution : : ToNumber ( it - > isolate ( ) , value ) , <nl> Object ) ; <nl> } <nl> MaybeHandle < Object > Object : : SetDataProperty ( LookupIterator * it , <nl> <nl> / / Possibly migrate to the most up - to - date map that will be able to store <nl> / / | value | under it - > name ( ) . <nl> - it - > PrepareForDataProperty ( value ) ; <nl> + it - > PrepareForDataProperty ( to_assign ) ; <nl> <nl> / / Write the property value . <nl> - value = it - > WriteDataValue ( value ) ; <nl> + it - > WriteDataValue ( to_assign ) ; <nl> <nl> / / Send the change record if there are observers . <nl> if ( is_observed & & ! value - > SameValue ( * maybe_old . ToHandleChecked ( ) ) ) { <nl> MaybeHandle < Object > JSObject : : SetOwnPropertyIgnoreAttributes ( <nl> DCHECK ( ! value - > IsTheHole ( ) ) ; <nl> LookupIterator it ( object , name , LookupIterator : : OWN_SKIP_INTERCEPTOR ) ; <nl> if ( it . state ( ) = = LookupIterator : : ACCESS_CHECK ) { <nl> - if ( ! it . isolate ( ) - > MayAccess ( object ) ) { <nl> + if ( ! it . HasAccess ( ) ) { <nl> return SetPropertyWithFailedAccessCheck ( & it , value , SLOPPY ) ; <nl> } <nl> it . Next ( ) ; <nl> MaybeHandle < Object > JSObject : : SetOwnElementIgnoreAttributes ( <nl> LookupIterator it ( isolate , object , index , <nl> LookupIterator : : OWN_SKIP_INTERCEPTOR ) ; <nl> if ( it . state ( ) = = LookupIterator : : ACCESS_CHECK ) { <nl> - if ( ! isolate - > MayAccess ( object ) ) { <nl> + if ( ! it . HasAccess ( ) ) { <nl> return SetPropertyWithFailedAccessCheck ( & it , value , STRICT ) ; <nl> } <nl> it . Next ( ) ; <nl> mmm a / src / objects . h <nl> ppp b / src / objects . h <nl> class Object { <nl> MUST_USE_RESULT static MaybeHandle < Object > WriteToReadOnlyProperty ( <nl> Isolate * isolate , Handle < Object > reciever , Handle < Object > name , <nl> Handle < Object > value , LanguageMode language_mode ) ; <nl> - MUST_USE_RESULT static MaybeHandle < Object > WriteToReadOnlyElement ( <nl> - Isolate * isolate , Handle < Object > receiver , uint32_t index , <nl> - Handle < Object > value , LanguageMode language_mode ) ; <nl> MUST_USE_RESULT static MaybeHandle < Object > RedefineNonconfigurableProperty ( <nl> Isolate * isolate , Handle < Object > name , Handle < Object > value , <nl> LanguageMode language_mode ) ; <nl> class JSObject : public JSReceiver { <nl> MUST_USE_RESULT static MaybeHandle < Object > SetPropertyWithInterceptor ( <nl> LookupIterator * it , Handle < Object > value ) ; <nl> <nl> + / / Calls SetOwn [ Property | Element ] IgnoreAttributes depending on whether name is <nl> + / / convertible to an index . <nl> + MUST_USE_RESULT static inline MaybeHandle < Object > DefinePropertyOrElement ( <nl> + Handle < JSObject > object , Handle < Name > name , Handle < Object > value , <nl> + PropertyAttributes attributes = NONE ) ; <nl> + <nl> MUST_USE_RESULT static MaybeHandle < Object > SetOwnPropertyIgnoreAttributes ( <nl> Handle < JSObject > object , Handle < Name > name , Handle < Object > value , <nl> PropertyAttributes attributes ) ; <nl> class ScopeInfo : public FixedArray { <nl> FunctionKind function_kind ( ) ; <nl> <nl> / / Copies all the context locals into an object used to materialize a scope . <nl> - static bool CopyContextLocalsToScopeObject ( Handle < ScopeInfo > scope_info , <nl> + static void CopyContextLocalsToScopeObject ( Handle < ScopeInfo > scope_info , <nl> Handle < Context > context , <nl> Handle < JSObject > scope_object ) ; <nl> <nl> mmm a / src / runtime / runtime - classes . cc <nl> ppp b / src / runtime / runtime - classes . cc <nl> RUNTIME_FUNCTION ( Runtime_DefineClassMethod ) { <nl> CONVERT_ARG_HANDLE_CHECKED ( Name , name , 1 ) ; <nl> CONVERT_ARG_HANDLE_CHECKED ( JSFunction , function , 2 ) ; <nl> <nl> - uint32_t index ; <nl> - if ( name - > AsArrayIndex ( & index ) ) { <nl> - RETURN_FAILURE_ON_EXCEPTION ( <nl> - isolate , JSObject : : SetOwnElementIgnoreAttributes ( object , index , <nl> - function , DONT_ENUM ) ) ; <nl> - } else { <nl> - RETURN_FAILURE_ON_EXCEPTION ( <nl> - isolate , JSObject : : SetOwnPropertyIgnoreAttributes ( object , name , <nl> - function , DONT_ENUM ) ) ; <nl> - } <nl> + RETURN_FAILURE_ON_EXCEPTION ( isolate , JSObject : : DefinePropertyOrElement ( <nl> + object , name , function , DONT_ENUM ) ) ; <nl> return isolate - > heap ( ) - > undefined_value ( ) ; <nl> } <nl> <nl> mmm a / src / runtime / runtime - debug . cc <nl> ppp b / src / runtime / runtime - debug . cc <nl> static bool ParameterIsShadowedByContextLocal ( Handle < ScopeInfo > info , <nl> } <nl> <nl> <nl> - MUST_USE_RESULT <nl> - static MaybeHandle < Context > MaterializeReceiver ( Isolate * isolate , <nl> - Handle < Context > target , <nl> - Handle < JSFunction > function , <nl> - JavaScriptFrame * frame ) { <nl> + static Handle < Context > MaterializeReceiver ( Isolate * isolate , <nl> + Handle < Context > target , <nl> + Handle < JSFunction > function , <nl> + JavaScriptFrame * frame ) { <nl> Handle < SharedFunctionInfo > shared ( function - > shared ( ) ) ; <nl> Handle < ScopeInfo > scope_info ( shared - > scope_info ( ) ) ; <nl> Handle < Object > receiver ; <nl> static MaybeHandle < Context > MaterializeReceiver ( Isolate * isolate , <nl> & init_flag , & maybe_assigned_flag ) > = 0 ) { <nl> return target ; <nl> } <nl> - receiver = Handle < Object > ( frame - > receiver ( ) , isolate ) ; <nl> + receiver = handle ( frame - > receiver ( ) , isolate ) ; <nl> break ; <nl> } <nl> case MODULE_SCOPE : <nl> receiver = isolate - > factory ( ) - > undefined_value ( ) ; <nl> break ; <nl> case SCRIPT_SCOPE : <nl> - receiver = Handle < Object > ( function - > global_proxy ( ) , isolate ) ; <nl> + receiver = handle ( function - > global_proxy ( ) , isolate ) ; <nl> break ; <nl> default : <nl> / / For eval code , arrow functions , and the like , there ' s no " this " binding <nl> static MaybeHandle < Context > MaterializeReceiver ( Isolate * isolate , <nl> <nl> / / Create a plain JSObject which materializes the local scope for the specified <nl> / / frame . <nl> - MUST_USE_RESULT <nl> - static MaybeHandle < JSObject > MaterializeStackLocalsWithFrameInspector ( <nl> + static void MaterializeStackLocalsWithFrameInspector ( <nl> Isolate * isolate , Handle < JSObject > target , Handle < ScopeInfo > scope_info , <nl> FrameInspector * frame_inspector ) { <nl> / / First fill all parameters . <nl> static MaybeHandle < JSObject > MaterializeStackLocalsWithFrameInspector ( <nl> isolate ) ; <nl> DCHECK ( ! value - > IsTheHole ( ) ) ; <nl> <nl> - RETURN_ON_EXCEPTION ( isolate , Runtime : : SetObjectProperty ( <nl> - isolate , target , name , value , SLOPPY ) , <nl> - JSObject ) ; <nl> + JSObject : : SetOwnPropertyIgnoreAttributes ( target , name , value , NONE ) . Check ( ) ; <nl> } <nl> <nl> / / Second fill all stack locals . <nl> static MaybeHandle < JSObject > MaterializeStackLocalsWithFrameInspector ( <nl> value = isolate - > factory ( ) - > undefined_value ( ) ; <nl> } <nl> <nl> - RETURN_ON_EXCEPTION ( isolate , Runtime : : SetObjectProperty ( <nl> - isolate , target , name , value , SLOPPY ) , <nl> - JSObject ) ; <nl> + JSObject : : SetOwnPropertyIgnoreAttributes ( target , name , value , NONE ) . Check ( ) ; <nl> } <nl> - <nl> - return target ; <nl> } <nl> <nl> - MUST_USE_RESULT <nl> - static MaybeHandle < JSObject > MaterializeStackLocalsWithFrameInspector ( <nl> + static void MaterializeStackLocalsWithFrameInspector ( <nl> Isolate * isolate , Handle < JSObject > target , Handle < JSFunction > function , <nl> FrameInspector * frame_inspector ) { <nl> Handle < SharedFunctionInfo > shared ( function - > shared ( ) ) ; <nl> Handle < ScopeInfo > scope_info ( shared - > scope_info ( ) ) ; <nl> <nl> - return MaterializeStackLocalsWithFrameInspector ( isolate , target , scope_info , <nl> - frame_inspector ) ; <nl> + MaterializeStackLocalsWithFrameInspector ( isolate , target , scope_info , <nl> + frame_inspector ) ; <nl> } <nl> <nl> <nl> MUST_USE_RESULT static MaybeHandle < JSObject > MaterializeLocalContext ( <nl> / / Third fill all context locals . <nl> Handle < Context > frame_context ( Context : : cast ( frame - > context ( ) ) ) ; <nl> Handle < Context > function_context ( frame_context - > declaration_context ( ) ) ; <nl> - if ( ! ScopeInfo : : CopyContextLocalsToScopeObject ( scope_info , function_context , <nl> - target ) ) { <nl> - return MaybeHandle < JSObject > ( ) ; <nl> - } <nl> + ScopeInfo : : CopyContextLocalsToScopeObject ( scope_info , function_context , <nl> + target ) ; <nl> <nl> / / Finally copy any properties from the function context extension . <nl> / / These will be variables introduced by eval . <nl> MUST_USE_RESULT static MaybeHandle < JSObject > MaterializeScriptScope ( <nl> Handle < Context > context = <nl> ScriptContextTable : : GetContext ( script_contexts , context_index ) ; <nl> Handle < ScopeInfo > scope_info ( ScopeInfo : : cast ( context - > extension ( ) ) ) ; <nl> - if ( ! ScopeInfo : : CopyContextLocalsToScopeObject ( scope_info , context , <nl> - script_scope ) ) { <nl> - return MaybeHandle < JSObject > ( ) ; <nl> - } <nl> + ScopeInfo : : CopyContextLocalsToScopeObject ( scope_info , context , <nl> + script_scope ) ; <nl> } <nl> return script_scope ; <nl> } <nl> MUST_USE_RESULT static MaybeHandle < JSObject > MaterializeLocalScope ( <nl> <nl> Handle < JSObject > local_scope = <nl> isolate - > factory ( ) - > NewJSObject ( isolate - > object_function ( ) ) ; <nl> - ASSIGN_RETURN_ON_EXCEPTION ( <nl> - isolate , local_scope , <nl> - MaterializeStackLocalsWithFrameInspector ( isolate , local_scope , function , <nl> - & frame_inspector ) , <nl> - JSObject ) ; <nl> + MaterializeStackLocalsWithFrameInspector ( isolate , local_scope , function , <nl> + & frame_inspector ) ; <nl> <nl> return MaterializeLocalContext ( isolate , local_scope , function , frame ) ; <nl> } <nl> static bool SetBlockVariableValue ( Isolate * isolate , <nl> <nl> / / Create a plain JSObject which materializes the closure content for the <nl> / / context . <nl> - MUST_USE_RESULT static MaybeHandle < JSObject > MaterializeClosure ( <nl> - Isolate * isolate , Handle < Context > context ) { <nl> + static Handle < JSObject > MaterializeClosure ( Isolate * isolate , <nl> + Handle < Context > context ) { <nl> DCHECK ( context - > IsFunctionContext ( ) ) ; <nl> <nl> Handle < SharedFunctionInfo > shared ( context - > closure ( ) - > shared ( ) ) ; <nl> MUST_USE_RESULT static MaybeHandle < JSObject > MaterializeClosure ( <nl> isolate - > factory ( ) - > NewJSObject ( isolate - > object_function ( ) ) ; <nl> <nl> / / Fill all context locals to the context extension . <nl> - if ( ! ScopeInfo : : CopyContextLocalsToScopeObject ( scope_info , context , <nl> - closure_scope ) ) { <nl> - return MaybeHandle < JSObject > ( ) ; <nl> - } <nl> + ScopeInfo : : CopyContextLocalsToScopeObject ( scope_info , context , closure_scope ) ; <nl> <nl> / / Finally copy any properties from the function context extension . This will <nl> / / be variables introduced by eval . <nl> if ( context - > has_extension ( ) ) { <nl> Handle < JSObject > ext ( JSObject : : cast ( context - > extension ( ) ) ) ; <nl> - Handle < FixedArray > keys ; <nl> - ASSIGN_RETURN_ON_EXCEPTION ( <nl> - isolate , keys , JSReceiver : : GetKeys ( ext , JSReceiver : : INCLUDE_PROTOS ) , <nl> - JSObject ) ; <nl> + DCHECK ( ext - > IsJSContextExtensionObject ( ) ) ; <nl> + Handle < FixedArray > keys = <nl> + JSReceiver : : GetKeys ( ext , JSReceiver : : OWN_ONLY ) . ToHandleChecked ( ) ; <nl> <nl> for ( int i = 0 ; i < keys - > length ( ) ; i + + ) { <nl> HandleScope scope ( isolate ) ; <nl> / / Names of variables introduced by eval are strings . <nl> DCHECK ( keys - > get ( i ) - > IsString ( ) ) ; <nl> Handle < String > key ( String : : cast ( keys - > get ( i ) ) ) ; <nl> - Handle < Object > value ; <nl> - ASSIGN_RETURN_ON_EXCEPTION ( <nl> - isolate , value , Object : : GetPropertyOrElement ( ext , key ) , JSObject ) ; <nl> - RETURN_ON_EXCEPTION ( isolate , Runtime : : DefineObjectProperty ( <nl> - closure_scope , key , value , NONE ) , <nl> - JSObject ) ; <nl> + Handle < Object > value = Object : : GetProperty ( ext , key ) . ToHandleChecked ( ) ; <nl> + JSObject : : SetOwnPropertyIgnoreAttributes ( closure_scope , key , value , NONE ) <nl> + . Check ( ) ; <nl> } <nl> } <nl> <nl> static bool SetClosureVariableValue ( Isolate * isolate , Handle < Context > context , <nl> / / be variables introduced by eval . <nl> if ( context - > has_extension ( ) ) { <nl> Handle < JSObject > ext ( JSObject : : cast ( context - > extension ( ) ) ) ; <nl> - Maybe < bool > maybe = JSReceiver : : HasProperty ( ext , variable_name ) ; <nl> + DCHECK ( ext - > IsJSContextExtensionObject ( ) ) ; <nl> + Maybe < bool > maybe = JSReceiver : : HasOwnProperty ( ext , variable_name ) ; <nl> DCHECK ( maybe . IsJust ( ) ) ; <nl> if ( maybe . FromJust ( ) ) { <nl> / / We don ' t expect this to do anything except replacing property value . <nl> - Runtime : : DefineObjectProperty ( ext , variable_name , new_value , NONE ) <nl> - . Assert ( ) ; <nl> + JSObject : : SetOwnPropertyIgnoreAttributes ( ext , variable_name , new_value , <nl> + NONE ) . Check ( ) ; <nl> return true ; <nl> } <nl> } <nl> static bool SetScriptVariableValue ( Handle < Context > context , <nl> <nl> / / Create a plain JSObject which materializes the scope for the specified <nl> / / catch context . <nl> - MUST_USE_RESULT static MaybeHandle < JSObject > MaterializeCatchScope ( <nl> - Isolate * isolate , Handle < Context > context ) { <nl> + static Handle < JSObject > MaterializeCatchScope ( Isolate * isolate , <nl> + Handle < Context > context ) { <nl> DCHECK ( context - > IsCatchContext ( ) ) ; <nl> Handle < String > name ( String : : cast ( context - > extension ( ) ) ) ; <nl> Handle < Object > thrown_object ( context - > get ( Context : : THROWN_OBJECT_INDEX ) , <nl> isolate ) ; <nl> Handle < JSObject > catch_scope = <nl> isolate - > factory ( ) - > NewJSObject ( isolate - > object_function ( ) ) ; <nl> - RETURN_ON_EXCEPTION ( isolate , Runtime : : DefineObjectProperty ( <nl> - catch_scope , name , thrown_object , NONE ) , <nl> - JSObject ) ; <nl> + JSObject : : SetOwnPropertyIgnoreAttributes ( catch_scope , name , thrown_object , <nl> + NONE ) . Check ( ) ; <nl> return catch_scope ; <nl> } <nl> <nl> static bool SetCatchVariableValue ( Isolate * isolate , Handle < Context > context , <nl> <nl> / / Create a plain JSObject which materializes the block scope for the specified <nl> / / block context . <nl> - MUST_USE_RESULT static MaybeHandle < JSObject > MaterializeBlockScope ( <nl> - Isolate * isolate , Handle < ScopeInfo > scope_info , Handle < Context > context , <nl> - JavaScriptFrame * frame , int inlined_jsframe_index ) { <nl> + static Handle < JSObject > MaterializeBlockScope ( Isolate * isolate , <nl> + Handle < ScopeInfo > scope_info , <nl> + Handle < Context > context , <nl> + JavaScriptFrame * frame , <nl> + int inlined_jsframe_index ) { <nl> Handle < JSObject > block_scope = <nl> isolate - > factory ( ) - > NewJSObject ( isolate - > object_function ( ) ) ; <nl> <nl> if ( frame ! = nullptr ) { <nl> FrameInspector frame_inspector ( frame , inlined_jsframe_index , isolate ) ; <nl> - RETURN_ON_EXCEPTION ( isolate , <nl> - MaterializeStackLocalsWithFrameInspector ( <nl> - isolate , block_scope , scope_info , & frame_inspector ) , <nl> - JSObject ) ; <nl> + MaterializeStackLocalsWithFrameInspector ( isolate , block_scope , scope_info , <nl> + & frame_inspector ) ; <nl> } <nl> <nl> if ( ! context . is_null ( ) ) { <nl> Handle < ScopeInfo > scope_info_from_context ( <nl> ScopeInfo : : cast ( context - > extension ( ) ) ) ; <nl> / / Fill all context locals . <nl> - if ( ! ScopeInfo : : CopyContextLocalsToScopeObject ( scope_info_from_context , <nl> - context , block_scope ) ) { <nl> - return MaybeHandle < JSObject > ( ) ; <nl> - } <nl> + ScopeInfo : : CopyContextLocalsToScopeObject ( scope_info_from_context , context , <nl> + block_scope ) ; <nl> } <nl> <nl> return block_scope ; <nl> MUST_USE_RESULT static MaybeHandle < JSObject > MaterializeModuleScope ( <nl> isolate - > factory ( ) - > NewJSObject ( isolate - > object_function ( ) ) ; <nl> <nl> / / Fill all context locals . <nl> - if ( ! ScopeInfo : : CopyContextLocalsToScopeObject ( scope_info , context , <nl> - module_scope ) ) { <nl> - return MaybeHandle < JSObject > ( ) ; <nl> - } <nl> + ScopeInfo : : CopyContextLocalsToScopeObject ( scope_info , context , module_scope ) ; <nl> <nl> return module_scope ; <nl> } <nl> RUNTIME_FUNCTION ( Runtime_ClearStepping ) { <nl> <nl> / / Helper function to find or create the arguments object for <nl> / / Runtime_DebugEvaluate . <nl> - MUST_USE_RESULT static MaybeHandle < JSObject > MaterializeArgumentsObject ( <nl> - Isolate * isolate , Handle < JSObject > target , Handle < JSFunction > function ) { <nl> + static void MaterializeArgumentsObject ( Isolate * isolate , <nl> + Handle < JSObject > target , <nl> + Handle < JSFunction > function ) { <nl> / / Do not materialize the arguments object for eval or top - level code . <nl> / / Skip if " arguments " is already taken . <nl> - if ( ! function - > shared ( ) - > is_function ( ) ) return target ; <nl> + if ( ! function - > shared ( ) - > is_function ( ) ) return ; <nl> Maybe < bool > maybe = JSReceiver : : HasOwnProperty ( <nl> target , isolate - > factory ( ) - > arguments_string ( ) ) ; <nl> - if ( ! maybe . IsJust ( ) ) return MaybeHandle < JSObject > ( ) ; <nl> - if ( maybe . FromJust ( ) ) return target ; <nl> + DCHECK ( maybe . IsJust ( ) ) ; <nl> + if ( maybe . FromJust ( ) ) return ; <nl> <nl> / / FunctionGetArguments can ' t throw an exception . <nl> Handle < JSObject > arguments = <nl> Handle < JSObject > : : cast ( Accessors : : FunctionGetArguments ( function ) ) ; <nl> Handle < String > arguments_str = isolate - > factory ( ) - > arguments_string ( ) ; <nl> - RETURN_ON_EXCEPTION ( isolate , Runtime : : DefineObjectProperty ( <nl> - target , arguments_str , arguments , NONE ) , <nl> - JSObject ) ; <nl> - return target ; <nl> + JSObject : : SetOwnPropertyIgnoreAttributes ( target , arguments_str , arguments , <nl> + NONE ) . Check ( ) ; <nl> } <nl> <nl> <nl> class EvaluationContextBuilder { <nl> <nl> / / The " this " binding , if any , can ' t be bound via " with " . If we need <nl> / / to , add another node onto the outer context to bind " this " . <nl> - if ( ! MaterializeReceiver ( isolate , parent_context , function , frame ) <nl> - . ToHandle ( & parent_context ) ) <nl> - return ; <nl> + parent_context = <nl> + MaterializeReceiver ( isolate , parent_context , function , frame ) ; <nl> <nl> Handle < JSObject > materialized_function = <nl> NewJSObjectWithNullProto ( isolate ) ; <nl> <nl> - if ( ! MaterializeStackLocalsWithFrameInspector ( <nl> - isolate , materialized_function , function , & frame_inspector ) <nl> - . ToHandle ( & materialized_function ) ) <nl> - return ; <nl> + MaterializeStackLocalsWithFrameInspector ( isolate , materialized_function , <nl> + function , & frame_inspector ) ; <nl> <nl> - if ( ! MaterializeArgumentsObject ( isolate , materialized_function , <nl> - function ) <nl> - . ToHandle ( & materialized_function ) ) <nl> - return ; <nl> + MaterializeArgumentsObject ( isolate , materialized_function , function ) ; <nl> <nl> Handle < Context > with_context = isolate - > factory ( ) - > NewWithContext ( <nl> function , parent_context , materialized_function ) ; <nl> class EvaluationContextBuilder { <nl> } else if ( scope_type = = ScopeIterator : : ScopeTypeBlock ) { <nl> Handle < JSObject > materialized_object = <nl> NewJSObjectWithNullProto ( isolate ) ; <nl> - if ( ! MaterializeStackLocalsWithFrameInspector ( <nl> - isolate , materialized_object , it . CurrentScopeInfo ( ) , <nl> - & frame_inspector ) . ToHandle ( & materialized_object ) ) <nl> - return ; <nl> + MaterializeStackLocalsWithFrameInspector ( isolate , materialized_object , <nl> + it . CurrentScopeInfo ( ) , <nl> + & frame_inspector ) ; <nl> if ( it . HasContext ( ) ) { <nl> Handle < Context > cloned_context = <nl> Handle < Context > : : cast ( FixedArray : : CopySize ( <nl> mmm a / src / runtime / runtime - object . cc <nl> ppp b / src / runtime / runtime - object . cc <nl> MaybeHandle < Object > Runtime : : SetObjectProperty ( Isolate * isolate , <nl> Object ) ; <nl> } <nl> <nl> - if ( object - > IsJSProxy ( ) ) { <nl> - Handle < Object > name_object ; <nl> - if ( key - > IsSymbol ( ) ) { <nl> - name_object = key ; <nl> - } else { <nl> - ASSIGN_RETURN_ON_EXCEPTION ( isolate , name_object , <nl> - Execution : : ToString ( isolate , key ) , Object ) ; <nl> - } <nl> - Handle < Name > name = Handle < Name > : : cast ( name_object ) ; <nl> - return Object : : SetProperty ( Handle < JSProxy > : : cast ( object ) , name , value , <nl> - language_mode ) ; <nl> - } <nl> - <nl> - / / Check if the given key is an array index . <nl> - uint32_t index = 0 ; <nl> - if ( key - > ToArrayIndex ( & index ) ) { <nl> - / / TODO ( verwaest ) : Support non - JSObject receivers . <nl> - if ( ! object - > IsJSObject ( ) ) return value ; <nl> - Handle < JSObject > js_object = Handle < JSObject > : : cast ( object ) ; <nl> - <nl> - / / In Firefox / SpiderMonkey , Safari and Opera you can access the characters <nl> - / / of a string using [ ] notation . We need to support this too in <nl> - / / JavaScript . <nl> - / / In the case of a String object we just need to redirect the assignment to <nl> - / / the underlying string if the index is in range . Since the underlying <nl> - / / string does nothing with the assignment then we can ignore such <nl> - / / assignments . <nl> - if ( js_object - > IsStringObjectWithCharacterAt ( index ) ) { <nl> - return value ; <nl> - } <nl> - <nl> - JSObject : : ValidateElements ( js_object ) ; <nl> - if ( js_object - > HasExternalArrayElements ( ) | | <nl> - js_object - > HasFixedTypedArrayElements ( ) ) { <nl> - if ( ! value - > IsNumber ( ) & & ! value - > IsUndefined ( ) ) { <nl> - ASSIGN_RETURN_ON_EXCEPTION ( isolate , value , <nl> - Execution : : ToNumber ( isolate , value ) , Object ) ; <nl> - } <nl> - } <nl> - <nl> - MaybeHandle < Object > result = <nl> - JSObject : : SetElement ( js_object , index , value , language_mode ) ; <nl> - JSObject : : ValidateElements ( js_object ) ; <nl> - <nl> - return result . is_null ( ) ? result : value ; <nl> - } <nl> - <nl> - if ( key - > IsName ( ) ) { <nl> - Handle < Name > name = Handle < Name > : : cast ( key ) ; <nl> - if ( name - > AsArrayIndex ( & index ) ) { <nl> - / / TODO ( verwaest ) : Support non - JSObject receivers . <nl> - if ( ! object - > IsJSObject ( ) ) return value ; <nl> - Handle < JSObject > js_object = Handle < JSObject > : : cast ( object ) ; <nl> - if ( js_object - > HasExternalArrayElements ( ) ) { <nl> - if ( ! value - > IsNumber ( ) & & ! value - > IsUndefined ( ) ) { <nl> - ASSIGN_RETURN_ON_EXCEPTION ( <nl> - isolate , value , Execution : : ToNumber ( isolate , value ) , Object ) ; <nl> - } <nl> - } <nl> - return JSObject : : SetElement ( js_object , index , value , language_mode ) ; <nl> - } else { <nl> - if ( name - > IsString ( ) ) name = String : : Flatten ( Handle < String > : : cast ( name ) ) ; <nl> - return Object : : SetProperty ( object , name , value , language_mode ) ; <nl> - } <nl> - } <nl> - <nl> - / / Call - back into JavaScript to convert the key to a string . <nl> - Handle < Object > converted ; <nl> - ASSIGN_RETURN_ON_EXCEPTION ( isolate , converted , <nl> - Execution : : ToString ( isolate , key ) , Object ) ; <nl> - Handle < String > name = Handle < String > : : cast ( converted ) ; <nl> - <nl> - if ( name - > AsArrayIndex ( & index ) ) { <nl> - / / TODO ( verwaest ) : Support non - JSObject receivers . <nl> - if ( ! object - > IsJSObject ( ) ) return value ; <nl> - Handle < JSObject > js_object = Handle < JSObject > : : cast ( object ) ; <nl> - return JSObject : : SetElement ( js_object , index , value , language_mode ) ; <nl> - } <nl> - return Object : : SetProperty ( object , name , value , language_mode ) ; <nl> - } <nl> - <nl> - <nl> - MaybeHandle < Object > Runtime : : DefineObjectProperty ( Handle < JSObject > js_object , <nl> - Handle < Object > key , <nl> - Handle < Object > value , <nl> - PropertyAttributes attrs ) { <nl> - Isolate * isolate = js_object - > GetIsolate ( ) ; <nl> / / Check if the given key is an array index . <nl> uint32_t index = 0 ; <nl> if ( key - > ToArrayIndex ( & index ) ) { <nl> - return JSObject : : SetOwnElementIgnoreAttributes ( js_object , index , value , <nl> - attrs ) ; <nl> + / / TODO ( verwaest ) : Support other objects as well . <nl> + if ( ! object - > IsJSReceiver ( ) ) return value ; <nl> + return JSReceiver : : SetElement ( Handle < JSReceiver > : : cast ( object ) , index , <nl> + value , language_mode ) ; <nl> } <nl> <nl> Handle < Name > name ; <nl> MaybeHandle < Object > Runtime : : DefineObjectProperty ( Handle < JSObject > js_object , <nl> } <nl> <nl> if ( name - > AsArrayIndex ( & index ) ) { <nl> - return JSObject : : SetOwnElementIgnoreAttributes ( js_object , index , value , <nl> - attrs ) ; <nl> - } else { <nl> - if ( name - > IsString ( ) ) name = String : : Flatten ( Handle < String > : : cast ( name ) ) ; <nl> - return JSObject : : SetOwnPropertyIgnoreAttributes ( js_object , name , value , <nl> - attrs ) ; <nl> + / / TODO ( verwaest ) : Support other objects as well . <nl> + if ( ! object - > IsJSReceiver ( ) ) return value ; <nl> + return JSReceiver : : SetElement ( Handle < JSReceiver > : : cast ( object ) , index , <nl> + value , language_mode ) ; <nl> } <nl> + return Object : : SetProperty ( object , name , value , language_mode ) ; <nl> } <nl> <nl> <nl> RUNTIME_FUNCTION ( Runtime_DefineAccessorPropertyUnchecked ) { <nl> RUNTIME_FUNCTION ( Runtime_DefineDataPropertyUnchecked ) { <nl> HandleScope scope ( isolate ) ; <nl> DCHECK ( args . length ( ) = = 4 ) ; <nl> - CONVERT_ARG_HANDLE_CHECKED ( JSObject , js_object , 0 ) ; <nl> + CONVERT_ARG_HANDLE_CHECKED ( JSObject , object , 0 ) ; <nl> CONVERT_ARG_HANDLE_CHECKED ( Name , name , 1 ) ; <nl> - CONVERT_ARG_HANDLE_CHECKED ( Object , obj_value , 2 ) ; <nl> + CONVERT_ARG_HANDLE_CHECKED ( Object , value , 2 ) ; <nl> CONVERT_PROPERTY_ATTRIBUTES_CHECKED ( attrs , 3 ) ; <nl> <nl> - LookupIterator it ( js_object , name , LookupIterator : : OWN_SKIP_INTERCEPTOR ) ; <nl> - if ( it . IsFound ( ) & & it . state ( ) = = LookupIterator : : ACCESS_CHECK ) { <nl> - if ( ! isolate - > MayAccess ( js_object ) ) { <nl> - return isolate - > heap ( ) - > undefined_value ( ) ; <nl> - } <nl> - it . Next ( ) ; <nl> + uint32_t index = 0 ; <nl> + LookupIterator : : Configuration c = LookupIterator : : OWN_SKIP_INTERCEPTOR ; <nl> + LookupIterator it = name - > AsArrayIndex ( & index ) <nl> + ? LookupIterator ( isolate , object , index , c ) <nl> + : LookupIterator ( object , name , c ) ; <nl> + if ( it . state ( ) = = LookupIterator : : ACCESS_CHECK & & ! it . HasAccess ( ) ) { <nl> + return isolate - > heap ( ) - > undefined_value ( ) ; <nl> } <nl> <nl> Handle < Object > result ; <nl> - ASSIGN_RETURN_FAILURE_ON_EXCEPTION ( <nl> - isolate , result , <nl> - Runtime : : DefineObjectProperty ( js_object , name , obj_value , attrs ) ) ; <nl> + MaybeHandle < Object > maybe_result = <nl> + it . IsElement ( ) <nl> + ? JSObject : : SetOwnElementIgnoreAttributes ( object , index , value , attrs ) <nl> + : JSObject : : SetOwnPropertyIgnoreAttributes ( object , name , value , <nl> + attrs ) ; <nl> + ASSIGN_RETURN_FAILURE_ON_EXCEPTION ( isolate , result , maybe_result ) ; <nl> return * result ; <nl> } <nl> <nl> RUNTIME_FUNCTION ( Runtime_GetDataProperty ) { <nl> HandleScope scope ( isolate ) ; <nl> DCHECK ( args . length ( ) = = 2 ) ; <nl> CONVERT_ARG_HANDLE_CHECKED ( JSReceiver , object , 0 ) ; <nl> - CONVERT_ARG_HANDLE_CHECKED ( Name , key , 1 ) ; <nl> - return * JSReceiver : : GetDataProperty ( object , key ) ; <nl> + CONVERT_ARG_HANDLE_CHECKED ( Name , name , 1 ) ; <nl> + return * JSReceiver : : GetDataProperty ( object , name ) ; <nl> } <nl> <nl> <nl> mmm a / src / runtime / runtime . h <nl> ppp b / src / runtime / runtime . h <nl> class Runtime : public AllStatic { <nl> Isolate * isolate , Handle < Object > object , Handle < Object > key , <nl> Handle < Object > value , LanguageMode language_mode ) ; <nl> <nl> - MUST_USE_RESULT static MaybeHandle < Object > DefineObjectProperty ( <nl> - Handle < JSObject > object , Handle < Object > key , Handle < Object > value , <nl> - PropertyAttributes attr ) ; <nl> - <nl> MUST_USE_RESULT static MaybeHandle < Object > GetObjectProperty ( <nl> Isolate * isolate , Handle < Object > object , Handle < Object > key ) ; <nl> <nl> mmm a / src / scopeinfo . cc <nl> ppp b / src / scopeinfo . cc <nl> FunctionKind ScopeInfo : : function_kind ( ) { <nl> } <nl> <nl> <nl> - bool ScopeInfo : : CopyContextLocalsToScopeObject ( Handle < ScopeInfo > scope_info , <nl> + void ScopeInfo : : CopyContextLocalsToScopeObject ( Handle < ScopeInfo > scope_info , <nl> Handle < Context > context , <nl> Handle < JSObject > scope_object ) { <nl> Isolate * isolate = scope_info - > GetIsolate ( ) ; <nl> int local_count = scope_info - > ContextLocalCount ( ) ; <nl> - if ( local_count = = 0 ) return true ; <nl> + if ( local_count = = 0 ) return ; <nl> / / Fill all context locals to the context extension . <nl> int first_context_var = scope_info - > StackLocalCount ( ) ; <nl> int start = scope_info - > ContextLocalNameEntriesIndex ( ) ; <nl> bool ScopeInfo : : CopyContextLocalsToScopeObject ( Handle < ScopeInfo > scope_info , <nl> Handle < Object > value = Handle < Object > ( context - > get ( context_index ) , isolate ) ; <nl> / / Reflect variables under TDZ as undefined in scope object . <nl> if ( value - > IsTheHole ( ) ) continue ; <nl> - RETURN_ON_EXCEPTION_VALUE ( <nl> - isolate , Runtime : : DefineObjectProperty ( <nl> - scope_object , <nl> - Handle < String > ( String : : cast ( scope_info - > get ( i + start ) ) ) , <nl> - value , : : NONE ) , <nl> - false ) ; <nl> + / / This should always succeed . <nl> + / / TODO ( verwaest ) : Use AddDataProperty instead . <nl> + JSObject : : SetOwnPropertyIgnoreAttributes ( <nl> + scope_object , handle ( String : : cast ( scope_info - > get ( i + start ) ) ) , value , <nl> + : : NONE ) . Check ( ) ; <nl> } <nl> - return true ; <nl> } <nl> <nl> <nl> mmm a / test / cctest / test - debug . cc <nl> ppp b / test / cctest / test - debug . cc <nl> class DebugLocalContext { <nl> v8 : : Utils : : OpenHandle ( * context_ - > Global ( ) ) ) ) ; <nl> Handle < v8 : : internal : : String > debug_string = <nl> factory - > InternalizeOneByteString ( STATIC_CHAR_VECTOR ( " debug " ) ) ; <nl> - v8 : : internal : : Runtime : : DefineObjectProperty ( global , debug_string , <nl> - handle ( debug_context - > global_proxy ( ) , isolate ) , DONT_ENUM ) . Check ( ) ; <nl> + v8 : : internal : : JSObject : : SetOwnPropertyIgnoreAttributes ( <nl> + global , debug_string , handle ( debug_context - > global_proxy ( ) ) , DONT_ENUM ) <nl> + . Check ( ) ; <nl> } <nl> <nl> private : <nl>
|
Replace SetObjectProperty / DefineObjectProperty with less powerful alternatives where relevant .
|
v8/v8
|
15aa811f8fe2708a757c3b53ca89db736aa8b222
|
2015-06-11T16:37:48Z
|
mmm a / src / objects / js - number - format . cc <nl> ppp b / src / objects / js - number - format . cc <nl> bool UseGroupingFromSkeleton ( const icu : : UnicodeString & skeleton ) { <nl> <nl> / / Parse currency code from skeleton . For example , skeleton as <nl> / / " currency / TWD . 00 rounding - mode - half - up unit - width - full - name ; " <nl> - std : : string CurrencyFromSkeleton ( const icu : : UnicodeString & skeleton ) { <nl> - std : : string str ; <nl> - str = skeleton . toUTF8String < std : : string > ( str ) ; <nl> - std : : string search ( " currency / " ) ; <nl> - size_t index = str . find ( search ) ; <nl> - if ( index = = str . npos ) return " " ; <nl> - return str . substr ( index + search . size ( ) , 3 ) ; <nl> + const icu : : UnicodeString CurrencyFromSkeleton ( <nl> + const icu : : UnicodeString & skeleton ) { <nl> + const char currency [ ] = " currency / " ; <nl> + int32_t index = skeleton . indexOf ( currency ) ; <nl> + if ( index < 0 ) return " " ; <nl> + return skeleton . tempSubString ( index + std : : strlen ( currency ) , 3 ) ; <nl> } <nl> <nl> - std : : string NumberingSystemFromSkeleton ( const icu : : UnicodeString & skeleton ) { <nl> - std : : string str ; <nl> - str = skeleton . toUTF8String < std : : string > ( str ) ; <nl> - size_t index = str . find ( " latin " ) ; <nl> - if ( index ! = str . npos ) return " latn " ; <nl> - std : : string search ( " numbering - system / " ) ; <nl> - index = str . find ( search ) ; <nl> - if ( index = = str . npos ) return " " ; <nl> - size_t space_index = str . find ( " " , index + search . size ( ) ) ; <nl> - if ( space_index ! = str . npos ) { <nl> - space_index - = index + search . size ( ) ; <nl> - } <nl> - return str . substr ( index + search . size ( ) , space_index ) ; <nl> + const icu : : UnicodeString NumberingSystemFromSkeleton ( <nl> + const icu : : UnicodeString & skeleton ) { <nl> + int32_t index = skeleton . indexOf ( " latin " ) ; <nl> + if ( index > = 0 ) return " latn " ; <nl> + const char numbering_system [ ] = " numbering - system / " ; <nl> + index = skeleton . indexOf ( numbering_system ) ; <nl> + if ( index < 0 ) return " " ; <nl> + const icu : : UnicodeString res = <nl> + skeleton . tempSubString ( index + std : : strlen ( numbering_system ) ) ; <nl> + index = res . indexOf ( " " ) ; <nl> + if ( index < 0 ) return res ; <nl> + return res . tempSubString ( 0 , index ) ; <nl> } <nl> <nl> / / Return CurrencySign as string based on skeleton . <nl> Handle < JSObject > JSNumberFormat : : ResolvedOptions ( <nl> Handle < JSObject > options = factory - > NewJSObject ( isolate - > object_function ( ) ) ; <nl> <nl> Handle < String > locale = Handle < String > ( number_format - > locale ( ) , isolate ) ; <nl> - std : : string numberingSystem = NumberingSystemFromSkeleton ( skeleton ) ; <nl> + const icu : : UnicodeString numberingSystem_ustr = <nl> + NumberingSystemFromSkeleton ( skeleton ) ; <nl> / / 5 . For each row of Table 4 , except the header row , in table order , do <nl> / / Table 4 : Resolved Options of NumberFormat Instances <nl> / / Internal Slot Property <nl> Handle < JSObject > JSNumberFormat : : ResolvedOptions ( <nl> factory - > locale_string ( ) , locale , <nl> Just ( kDontThrow ) ) <nl> . FromJust ( ) ) ; <nl> - CHECK ( JSReceiver : : CreateDataProperty ( <nl> - isolate , options , factory - > numberingSystem_string ( ) , <nl> - factory - > NewStringFromAsciiChecked ( numberingSystem . c_str ( ) ) , <nl> - Just ( kDontThrow ) ) <nl> + Handle < String > numberingSystem_string ; <nl> + CHECK ( Intl : : ToString ( isolate , numberingSystem_ustr ) <nl> + . ToHandle ( & numberingSystem_string ) ) ; <nl> + CHECK ( JSReceiver : : CreateDataProperty ( isolate , options , <nl> + factory - > numberingSystem_string ( ) , <nl> + numberingSystem_string , Just ( kDontThrow ) ) <nl> . FromJust ( ) ) ; <nl> Style style = StyleFromSkeleton ( skeleton ) ; <nl> CHECK ( JSReceiver : : CreateDataProperty ( <nl> isolate , options , factory - > style_string ( ) , <nl> StyleAsString ( isolate , style ) , Just ( kDontThrow ) ) <nl> . FromJust ( ) ) ; <nl> - std : : string currency = CurrencyFromSkeleton ( skeleton ) ; <nl> - if ( ! currency . empty ( ) ) { <nl> - CHECK ( JSReceiver : : CreateDataProperty ( <nl> - isolate , options , factory - > currency_string ( ) , <nl> - factory - > NewStringFromAsciiChecked ( currency . c_str ( ) ) , <nl> - Just ( kDontThrow ) ) <nl> + const icu : : UnicodeString currency_ustr = CurrencyFromSkeleton ( skeleton ) ; <nl> + if ( ! currency_ustr . isEmpty ( ) ) { <nl> + Handle < String > currency_string ; <nl> + CHECK ( Intl : : ToString ( isolate , currency_ustr ) . ToHandle ( & currency_string ) ) ; <nl> + CHECK ( JSReceiver : : CreateDataProperty ( isolate , options , <nl> + factory - > currency_string ( ) , <nl> + currency_string , Just ( kDontThrow ) ) <nl> . FromJust ( ) ) ; <nl> <nl> CHECK ( JSReceiver : : CreateDataProperty ( <nl>
|
Avoid UTF8 conversion in JSNumberFormat
|
v8/v8
|
f70e5abf437ce5214e22c9a392c121f11b37a397
|
2020-02-19T19:26:02Z
|
mmm a / tensorflow / python / ops / linalg_grad . py <nl> ppp b / tensorflow / python / ops / linalg_grad . py <nl> def _BatchMatrixDeterminantGrad ( op , grad ) : <nl> @ ops . RegisterGradient ( " Cholesky " ) <nl> def _cholesky_grad ( op , grad ) : <nl> " " " Gradient for Cholesky . " " " <nl> - return linalg_ops . cholesky_grad ( op . outputs [ 0 ] , grad ) <nl> - <nl> - <nl> - @ ops . RegisterGradient ( " Cholesky " ) <nl> - def _cholesky_grad ( op , grad ) : <nl> - " " " Gradient for Cholesky . " " " <nl> - return linalg_ops . cholesky_grad ( op . outputs [ 0 ] , grad ) <nl> + return linalg_ops . cholesky_grad ( op . outputs [ 0 ] , grad ) <nl> <nl> <nl> @ ops . RegisterGradient ( " MatrixSolve " ) <nl>
|
Remove duplicate Cholesky gradient registration
|
tensorflow/tensorflow
|
d70c765817b1c53aef924cff87c0d8161f3e9f2f
|
2016-04-20T03:27:34Z
|
mmm a / src / core / qtlibtorrent / alertdispatcher . cpp <nl> ppp b / src / core / qtlibtorrent / alertdispatcher . cpp <nl> <nl> const size_t DEFAULT_ALERTS_CAPACITY = 32 ; <nl> <nl> struct QAlertDispatcher : : Tag { <nl> - Tag ( QAlertDispatcher * dispatcher ) ; <nl> + Tag ( QAlertDispatcher * dispatcher ) ; <nl> <nl> - QAlertDispatcher * dispatcher ; <nl> - QMutex alerts_mutex ; <nl> + QAlertDispatcher * dispatcher ; <nl> + QMutex alerts_mutex ; <nl> } ; <nl> <nl> QAlertDispatcher : : Tag : : Tag ( QAlertDispatcher * dispatcher ) <nl> - : dispatcher ( dispatcher ) <nl> + : dispatcher ( dispatcher ) <nl> { } <nl> <nl> QAlertDispatcher : : QAlertDispatcher ( libtorrent : : session * session , QObject * parent ) <nl> - : QObject ( parent ) <nl> - , m_session ( session ) <nl> - , current_tag ( new Tag ( this ) ) <nl> - , event_posted ( false ) <nl> + : QObject ( parent ) <nl> + , m_session ( session ) <nl> + , current_tag ( new Tag ( this ) ) <nl> + , event_posted ( false ) <nl> { <nl> - alerts . reserve ( DEFAULT_ALERTS_CAPACITY ) ; <nl> - m_session - > set_alert_dispatch ( boost : : bind ( & QAlertDispatcher : : dispatch , current_tag , _1 ) ) ; <nl> + alerts . reserve ( DEFAULT_ALERTS_CAPACITY ) ; <nl> + m_session - > set_alert_dispatch ( boost : : bind ( & QAlertDispatcher : : dispatch , current_tag , _1 ) ) ; <nl> } <nl> <nl> QAlertDispatcher : : ~ QAlertDispatcher ( ) { <nl> - / / When QAlertDispatcher is destoyed , libtorrent still can call <nl> - / / QAlertDispatcher : : dispatch a few times after destruction . This is <nl> - / / handled by passing a " tag " . A tag is a object that references QAlertDispatch . <nl> - / / Tag could be invalidated . So on destruction QAlertDispatcher invalidates a tag <nl> - / / and then unsubscribes from alerts . When QAlertDispatcher : : dispatch is called <nl> - / / with invalid tag it simply discard an alert . <nl> - <nl> - { <nl> - QMutexLocker lock ( & current_tag - > alerts_mutex ) ; <nl> - current_tag - > dispatcher = 0 ; <nl> - current_tag . clear ( ) ; <nl> - } <nl> - <nl> - typedef boost : : function < void ( std : : auto_ptr < libtorrent : : alert > ) > dispatch_function_t ; <nl> - m_session - > set_alert_dispatch ( dispatch_function_t ( ) ) ; <nl> + / / When QAlertDispatcher is destoyed , libtorrent still can call <nl> + / / QAlertDispatcher : : dispatch a few times after destruction . This is <nl> + / / handled by passing a " tag " . A tag is a object that references QAlertDispatch . <nl> + / / Tag could be invalidated . So on destruction QAlertDispatcher invalidates a tag <nl> + / / and then unsubscribes from alerts . When QAlertDispatcher : : dispatch is called <nl> + / / with invalid tag it simply discard an alert . <nl> + <nl> + { <nl> + QMutexLocker lock ( & current_tag - > alerts_mutex ) ; <nl> + current_tag - > dispatcher = 0 ; <nl> + current_tag . clear ( ) ; <nl> + } <nl> + <nl> + typedef boost : : function < void ( std : : auto_ptr < libtorrent : : alert > ) > dispatch_function_t ; <nl> + m_session - > set_alert_dispatch ( dispatch_function_t ( ) ) ; <nl> } <nl> <nl> void QAlertDispatcher : : getPendingAlertsNoWait ( std : : vector < libtorrent : : alert * > & out ) { <nl> - Q_ASSERT ( out . empty ( ) ) ; <nl> - out . reserve ( DEFAULT_ALERTS_CAPACITY ) ; <nl> + Q_ASSERT ( out . empty ( ) ) ; <nl> + out . reserve ( DEFAULT_ALERTS_CAPACITY ) ; <nl> <nl> - QMutexLocker lock ( & current_tag - > alerts_mutex ) ; <nl> - alerts . swap ( out ) ; <nl> - event_posted = false ; <nl> + QMutexLocker lock ( & current_tag - > alerts_mutex ) ; <nl> + alerts . swap ( out ) ; <nl> + event_posted = false ; <nl> } <nl> <nl> void QAlertDispatcher : : getPendingAlerts ( std : : vector < libtorrent : : alert * > & out , unsigned long time ) { <nl> - Q_ASSERT ( out . empty ( ) ) ; <nl> - out . reserve ( DEFAULT_ALERTS_CAPACITY ) ; <nl> + Q_ASSERT ( out . empty ( ) ) ; <nl> + out . reserve ( DEFAULT_ALERTS_CAPACITY ) ; <nl> <nl> - QMutexLocker lock ( & current_tag - > alerts_mutex ) ; <nl> + QMutexLocker lock ( & current_tag - > alerts_mutex ) ; <nl> <nl> - while ( alerts . empty ( ) ) <nl> - alerts_condvar . wait ( & current_tag - > alerts_mutex , time ) ; <nl> + while ( alerts . empty ( ) ) <nl> + alerts_condvar . wait ( & current_tag - > alerts_mutex , time ) ; <nl> <nl> - alerts . swap ( out ) ; <nl> - event_posted = false ; <nl> + alerts . swap ( out ) ; <nl> + event_posted = false ; <nl> } <nl> <nl> void QAlertDispatcher : : dispatch ( QSharedPointer < Tag > tag , <nl> std : : auto_ptr < libtorrent : : alert > alert_ptr ) { <nl> - QMutexLocker lock ( & ( tag - > alerts_mutex ) ) ; <nl> - QAlertDispatcher * that = tag - > dispatcher ; <nl> - if ( ! that ) <nl> - return ; <nl> + QMutexLocker lock ( & ( tag - > alerts_mutex ) ) ; <nl> + QAlertDispatcher * that = tag - > dispatcher ; <nl> + if ( ! that ) <nl> + return ; <nl> <nl> - bool was_empty = that - > alerts . empty ( ) ; <nl> + bool was_empty = that - > alerts . empty ( ) ; <nl> <nl> - that - > alerts . push_back ( alert_ptr . get ( ) ) ; <nl> - alert_ptr . release ( ) ; <nl> + that - > alerts . push_back ( alert_ptr . get ( ) ) ; <nl> + alert_ptr . release ( ) ; <nl> <nl> - if ( was_empty ) <nl> - that - > alerts_condvar . wakeAll ( ) ; <nl> + if ( was_empty ) <nl> + that - > alerts_condvar . wakeAll ( ) ; <nl> <nl> - that - > enqueueToMainThread ( ) ; <nl> + that - > enqueueToMainThread ( ) ; <nl> <nl> - Q_ASSERT ( that - > current_tag = = tag ) ; <nl> + Q_ASSERT ( that - > current_tag = = tag ) ; <nl> } <nl> <nl> void QAlertDispatcher : : enqueueToMainThread ( ) { <nl> - if ( ! event_posted ) { <nl> - event_posted = true ; <nl> - QMetaObject : : invokeMethod ( this , " deliverSignal " , Qt : : QueuedConnection ) ; <nl> - } <nl> + if ( ! event_posted ) { <nl> + event_posted = true ; <nl> + QMetaObject : : invokeMethod ( this , " deliverSignal " , Qt : : QueuedConnection ) ; <nl> + } <nl> } <nl> <nl> void QAlertDispatcher : : deliverSignal ( ) { <nl> - emit alertsReceived ( ) ; <nl> + emit alertsReceived ( ) ; <nl> <nl> - QMutexLocker lock ( & current_tag - > alerts_mutex ) ; <nl> - event_posted = false ; <nl> + QMutexLocker lock ( & current_tag - > alerts_mutex ) ; <nl> + event_posted = false ; <nl> <nl> - if ( ! alerts . empty ( ) ) <nl> - enqueueToMainThread ( ) ; <nl> + if ( ! alerts . empty ( ) ) <nl> + enqueueToMainThread ( ) ; <nl> } <nl> mmm a / src / core / qtlibtorrent / alertdispatcher . h <nl> ppp b / src / core / qtlibtorrent / alertdispatcher . h <nl> <nl> # include < memory > <nl> <nl> namespace libtorrent { <nl> - class session ; <nl> - class alert ; <nl> + class session ; <nl> + class alert ; <nl> } <nl> <nl> class QAlertDispatcher : public QObject { <nl> - Q_OBJECT <nl> - Q_DISABLE_COPY ( QAlertDispatcher ) <nl> + Q_OBJECT <nl> + Q_DISABLE_COPY ( QAlertDispatcher ) <nl> <nl> - struct Tag ; <nl> + struct Tag ; <nl> <nl> public : <nl> - QAlertDispatcher ( libtorrent : : session * session , QObject * parent ) ; <nl> - ~ QAlertDispatcher ( ) ; <nl> + QAlertDispatcher ( libtorrent : : session * session , QObject * parent ) ; <nl> + ~ QAlertDispatcher ( ) ; <nl> <nl> - void getPendingAlertsNoWait ( std : : vector < libtorrent : : alert * > & ) ; <nl> - void getPendingAlerts ( std : : vector < libtorrent : : alert * > & , unsigned long time = ULONG_MAX ) ; <nl> + void getPendingAlertsNoWait ( std : : vector < libtorrent : : alert * > & ) ; <nl> + void getPendingAlerts ( std : : vector < libtorrent : : alert * > & , unsigned long time = ULONG_MAX ) ; <nl> <nl> signals : <nl> - void alertsReceived ( ) ; <nl> + void alertsReceived ( ) ; <nl> <nl> private : <nl> - static void dispatch ( QSharedPointer < Tag > , <nl> - std : : auto_ptr < libtorrent : : alert > ) ; <nl> - void enqueueToMainThread ( ) ; <nl> + static void dispatch ( QSharedPointer < Tag > , <nl> + std : : auto_ptr < libtorrent : : alert > ) ; <nl> + void enqueueToMainThread ( ) ; <nl> <nl> private slots : <nl> - void deliverSignal ( ) ; <nl> + void deliverSignal ( ) ; <nl> <nl> private : <nl> - libtorrent : : session * m_session ; <nl> - QWaitCondition alerts_condvar ; <nl> - std : : vector < libtorrent : : alert * > alerts ; <nl> - QSharedPointer < Tag > current_tag ; <nl> - bool event_posted ; <nl> + libtorrent : : session * m_session ; <nl> + QWaitCondition alerts_condvar ; <nl> + std : : vector < libtorrent : : alert * > alerts ; <nl> + QSharedPointer < Tag > current_tag ; <nl> + bool event_posted ; <nl> } ; <nl> <nl> # endif / / ALERTDISPATCHER_H <nl> mmm a / src / core / qtlibtorrent / bandwidthscheduler . h <nl> ppp b / src / core / qtlibtorrent / bandwidthscheduler . h <nl> <nl> <nl> <nl> class BandwidthScheduler : public QTimer { <nl> - Q_OBJECT <nl> + Q_OBJECT <nl> <nl> public : <nl> - BandwidthScheduler ( QObject * parent ) : QTimer ( parent ) { <nl> - Q_ASSERT ( Preferences : : instance ( ) - > isSchedulerEnabled ( ) ) ; <nl> - / / Signal shot , we call start ( ) again manually <nl> - setSingleShot ( true ) ; <nl> - / / Connect Signals / Slots <nl> - connect ( this , SIGNAL ( timeout ( ) ) , this , SLOT ( start ( ) ) ) ; <nl> - } <nl> + BandwidthScheduler ( QObject * parent ) : QTimer ( parent ) { <nl> + Q_ASSERT ( Preferences : : instance ( ) - > isSchedulerEnabled ( ) ) ; <nl> + / / Signal shot , we call start ( ) again manually <nl> + setSingleShot ( true ) ; <nl> + / / Connect Signals / Slots <nl> + connect ( this , SIGNAL ( timeout ( ) ) , this , SLOT ( start ( ) ) ) ; <nl> + } <nl> <nl> public slots : <nl> - void start ( ) { <nl> - const Preferences * const pref = Preferences : : instance ( ) ; <nl> - Q_ASSERT ( pref - > isSchedulerEnabled ( ) ) ; <nl> - bool alt_bw_enabled = pref - > isAltBandwidthEnabled ( ) ; <nl> + void start ( ) { <nl> + const Preferences * const pref = Preferences : : instance ( ) ; <nl> + Q_ASSERT ( pref - > isSchedulerEnabled ( ) ) ; <nl> + bool alt_bw_enabled = pref - > isAltBandwidthEnabled ( ) ; <nl> <nl> - QTime start = pref - > getSchedulerStartTime ( ) ; <nl> - QTime end = pref - > getSchedulerEndTime ( ) ; <nl> - QTime now = QTime : : currentTime ( ) ; <nl> - int sched_days = pref - > getSchedulerDays ( ) ; <nl> - int day = QDateTime : : currentDateTime ( ) . toLocalTime ( ) . date ( ) . dayOfWeek ( ) ; <nl> - bool new_mode = false ; <nl> - bool reverse = false ; <nl> + QTime start = pref - > getSchedulerStartTime ( ) ; <nl> + QTime end = pref - > getSchedulerEndTime ( ) ; <nl> + QTime now = QTime : : currentTime ( ) ; <nl> + int sched_days = pref - > getSchedulerDays ( ) ; <nl> + int day = QDateTime : : currentDateTime ( ) . toLocalTime ( ) . date ( ) . dayOfWeek ( ) ; <nl> + bool new_mode = false ; <nl> + bool reverse = false ; <nl> <nl> - if ( start > end ) { <nl> - QTime temp = start ; <nl> - start = end ; <nl> - end = temp ; <nl> - reverse = true ; <nl> - } <nl> + if ( start > end ) { <nl> + QTime temp = start ; <nl> + start = end ; <nl> + end = temp ; <nl> + reverse = true ; <nl> + } <nl> <nl> - if ( start < = now & & end > = now ) { <nl> - switch ( sched_days ) { <nl> - case EVERY_DAY : <nl> - new_mode = true ; <nl> - break ; <nl> - case WEEK_ENDS : <nl> - if ( day = = 6 | | day = = 7 ) <nl> - new_mode = true ; <nl> - break ; <nl> - case WEEK_DAYS : <nl> - if ( day ! = 6 & & day ! = 7 ) <nl> - new_mode = true ; <nl> - break ; <nl> - default : <nl> - if ( day = = sched_days - 2 ) <nl> - new_mode = true ; <nl> - break ; <nl> - } <nl> - } <nl> + if ( start < = now & & end > = now ) { <nl> + switch ( sched_days ) { <nl> + case EVERY_DAY : <nl> + new_mode = true ; <nl> + break ; <nl> + case WEEK_ENDS : <nl> + if ( day = = 6 | | day = = 7 ) <nl> + new_mode = true ; <nl> + break ; <nl> + case WEEK_DAYS : <nl> + if ( day ! = 6 & & day ! = 7 ) <nl> + new_mode = true ; <nl> + break ; <nl> + default : <nl> + if ( day = = sched_days - 2 ) <nl> + new_mode = true ; <nl> + break ; <nl> + } <nl> + } <nl> <nl> - if ( reverse ) <nl> - new_mode = ! new_mode ; <nl> + if ( reverse ) <nl> + new_mode = ! new_mode ; <nl> <nl> - if ( new_mode ! = alt_bw_enabled ) <nl> - emit switchToAlternativeMode ( new_mode ) ; <nl> + if ( new_mode ! = alt_bw_enabled ) <nl> + emit switchToAlternativeMode ( new_mode ) ; <nl> <nl> - / / Timeout regularly to accomodate for external system clock changes <nl> - / / eg from the user or from a timesync utility <nl> - QTimer : : start ( 1500 ) ; <nl> - } <nl> + / / Timeout regularly to accomodate for external system clock changes <nl> + / / eg from the user or from a timesync utility <nl> + QTimer : : start ( 1500 ) ; <nl> + } <nl> <nl> signals : <nl> - void switchToAlternativeMode ( bool alternative ) ; <nl> + void switchToAlternativeMode ( bool alternative ) ; <nl> } ; <nl> <nl> # endif / / BANDWIDTHSCHEDULER_H <nl> mmm a / src / core / qtlibtorrent / filterparserthread . cpp <nl> ppp b / src / core / qtlibtorrent / filterparserthread . cpp <nl> FilterParserThread : : FilterParserThread ( QObject * parent , libtorrent : : session * s ) <nl> } <nl> <nl> FilterParserThread : : ~ FilterParserThread ( ) { <nl> - abort = true ; <nl> - wait ( ) ; <nl> + abort = true ; <nl> + wait ( ) ; <nl> } <nl> <nl> / / Parser for eMule ip filter in DAT format <nl> int FilterParserThread : : parseDATFilterFile ( QString filePath , libtorrent : : ip_filter & filter ) { <nl> - int ruleCount = 0 ; <nl> - QFile file ( filePath ) ; <nl> - if ( file . exists ( ) ) { <nl> - if ( ! file . open ( QIODevice : : ReadOnly | QIODevice : : Text ) ) { <nl> - std : : cerr < < " I / O Error : Could not open ip filer file in read mode . " < < std : : endl ; <nl> - return ruleCount ; <nl> - } <nl> - unsigned int nbLine = 0 ; <nl> - while ( ! file . atEnd ( ) & & ! abort ) { <nl> - + + nbLine ; <nl> - QByteArray line = file . readLine ( ) ; <nl> - / / Ignoring empty lines <nl> - line = line . trimmed ( ) ; <nl> - if ( line . isEmpty ( ) ) continue ; <nl> - / / Ignoring commented lines <nl> - if ( line . startsWith ( ' # ' ) | | line . startsWith ( " / / " ) ) continue ; <nl> + int ruleCount = 0 ; <nl> + QFile file ( filePath ) ; <nl> + if ( file . exists ( ) ) { <nl> + if ( ! file . open ( QIODevice : : ReadOnly | QIODevice : : Text ) ) { <nl> + std : : cerr < < " I / O Error : Could not open ip filer file in read mode . " < < std : : endl ; <nl> + return ruleCount ; <nl> + } <nl> + unsigned int nbLine = 0 ; <nl> + while ( ! file . atEnd ( ) & & ! abort ) { <nl> + + + nbLine ; <nl> + QByteArray line = file . readLine ( ) ; <nl> + / / Ignoring empty lines <nl> + line = line . trimmed ( ) ; <nl> + if ( line . isEmpty ( ) ) continue ; <nl> + / / Ignoring commented lines <nl> + if ( line . startsWith ( ' # ' ) | | line . startsWith ( " / / " ) ) continue ; <nl> <nl> - / / Line should be splitted by commas <nl> - QList < QByteArray > partsList = line . split ( ' , ' ) ; <nl> - const uint nbElem = partsList . size ( ) ; <nl> + / / Line should be splitted by commas <nl> + QList < QByteArray > partsList = line . split ( ' , ' ) ; <nl> + const uint nbElem = partsList . size ( ) ; <nl> <nl> - / / IP Range should be splitted by a dash <nl> - QList < QByteArray > IPs = partsList . first ( ) . split ( ' - ' ) ; <nl> - if ( IPs . size ( ) ! = 2 ) { <nl> - qDebug ( " Ipfilter . dat : line % d is malformed . " , nbLine ) ; <nl> - qDebug ( " Line was % s " , line . constData ( ) ) ; <nl> - continue ; <nl> - } <nl> + / / IP Range should be splitted by a dash <nl> + QList < QByteArray > IPs = partsList . first ( ) . split ( ' - ' ) ; <nl> + if ( IPs . size ( ) ! = 2 ) { <nl> + qDebug ( " Ipfilter . dat : line % d is malformed . " , nbLine ) ; <nl> + qDebug ( " Line was % s " , line . constData ( ) ) ; <nl> + continue ; <nl> + } <nl> <nl> - boost : : system : : error_code ec ; <nl> - const QString strStartIP = cleanupIPAddress ( IPs . at ( 0 ) ) ; <nl> - if ( strStartIP . isEmpty ( ) ) { <nl> - qDebug ( " Ipfilter . dat : line % d is malformed . " , nbLine ) ; <nl> - qDebug ( " Start IP of the range is malformated : % s " , qPrintable ( strStartIP ) ) ; <nl> - continue ; <nl> - } <nl> - libtorrent : : address startAddr = libtorrent : : address : : from_string ( qPrintable ( strStartIP ) , ec ) ; <nl> - if ( ec ) { <nl> - qDebug ( " Ipfilter . dat : line % d is malformed . " , nbLine ) ; <nl> - qDebug ( " Start IP of the range is malformated : % s " , qPrintable ( strStartIP ) ) ; <nl> - continue ; <nl> - } <nl> - const QString strEndIP = cleanupIPAddress ( IPs . at ( 1 ) ) ; <nl> - if ( strEndIP . isEmpty ( ) ) { <nl> - qDebug ( " Ipfilter . dat : line % d is malformed . " , nbLine ) ; <nl> - qDebug ( " End IP of the range is malformated : % s " , qPrintable ( strEndIP ) ) ; <nl> - continue ; <nl> - } <nl> - libtorrent : : address endAddr = libtorrent : : address : : from_string ( qPrintable ( strEndIP ) , ec ) ; <nl> - if ( ec ) { <nl> - qDebug ( " Ipfilter . dat : line % d is malformed . " , nbLine ) ; <nl> - qDebug ( " End IP of the range is malformated : % s " , qPrintable ( strEndIP ) ) ; <nl> - continue ; <nl> - } <nl> - if ( startAddr . is_v4 ( ) ! = endAddr . is_v4 ( ) ) { <nl> - qDebug ( " Ipfilter . dat : line % d is malformed . " , nbLine ) ; <nl> - qDebug ( " One IP is IPv4 and the other is IPv6 ! " ) ; <nl> - continue ; <nl> - } <nl> + boost : : system : : error_code ec ; <nl> + const QString strStartIP = cleanupIPAddress ( IPs . at ( 0 ) ) ; <nl> + if ( strStartIP . isEmpty ( ) ) { <nl> + qDebug ( " Ipfilter . dat : line % d is malformed . " , nbLine ) ; <nl> + qDebug ( " Start IP of the range is malformated : % s " , qPrintable ( strStartIP ) ) ; <nl> + continue ; <nl> + } <nl> + libtorrent : : address startAddr = libtorrent : : address : : from_string ( qPrintable ( strStartIP ) , ec ) ; <nl> + if ( ec ) { <nl> + qDebug ( " Ipfilter . dat : line % d is malformed . " , nbLine ) ; <nl> + qDebug ( " Start IP of the range is malformated : % s " , qPrintable ( strStartIP ) ) ; <nl> + continue ; <nl> + } <nl> + const QString strEndIP = cleanupIPAddress ( IPs . at ( 1 ) ) ; <nl> + if ( strEndIP . isEmpty ( ) ) { <nl> + qDebug ( " Ipfilter . dat : line % d is malformed . " , nbLine ) ; <nl> + qDebug ( " End IP of the range is malformated : % s " , qPrintable ( strEndIP ) ) ; <nl> + continue ; <nl> + } <nl> + libtorrent : : address endAddr = libtorrent : : address : : from_string ( qPrintable ( strEndIP ) , ec ) ; <nl> + if ( ec ) { <nl> + qDebug ( " Ipfilter . dat : line % d is malformed . " , nbLine ) ; <nl> + qDebug ( " End IP of the range is malformated : % s " , qPrintable ( strEndIP ) ) ; <nl> + continue ; <nl> + } <nl> + if ( startAddr . is_v4 ( ) ! = endAddr . is_v4 ( ) ) { <nl> + qDebug ( " Ipfilter . dat : line % d is malformed . " , nbLine ) ; <nl> + qDebug ( " One IP is IPv4 and the other is IPv6 ! " ) ; <nl> + continue ; <nl> + } <nl> <nl> - / / Check if there is an access value ( apparently not mandatory ) <nl> - int nbAccess = 0 ; <nl> - if ( nbElem > 1 ) { <nl> - / / There is possibly one <nl> - nbAccess = partsList . at ( 1 ) . trimmed ( ) . toInt ( ) ; <nl> - } <nl> + / / Check if there is an access value ( apparently not mandatory ) <nl> + int nbAccess = 0 ; <nl> + if ( nbElem > 1 ) { <nl> + / / There is possibly one <nl> + nbAccess = partsList . at ( 1 ) . trimmed ( ) . toInt ( ) ; <nl> + } <nl> <nl> - if ( nbAccess > 127 ) { <nl> - / / Ignoring this rule because access value is too high <nl> - continue ; <nl> - } <nl> - / / Now Add to the filter <nl> - try { <nl> - filter . add_rule ( startAddr , endAddr , libtorrent : : ip_filter : : blocked ) ; <nl> - + + ruleCount ; <nl> - } catch ( exception ) { <nl> - qDebug ( " Bad line in filter file , avoided crash . . . " ) ; <nl> - } <nl> + if ( nbAccess > 127 ) { <nl> + / / Ignoring this rule because access value is too high <nl> + continue ; <nl> + } <nl> + / / Now Add to the filter <nl> + try { <nl> + filter . add_rule ( startAddr , endAddr , libtorrent : : ip_filter : : blocked ) ; <nl> + + + ruleCount ; <nl> + } catch ( exception ) { <nl> + qDebug ( " Bad line in filter file , avoided crash . . . " ) ; <nl> + } <nl> + } <nl> + file . close ( ) ; <nl> } <nl> - file . close ( ) ; <nl> - } <nl> - return ruleCount ; <nl> + return ruleCount ; <nl> } <nl> <nl> / / Parser for PeerGuardian ip filter in p2p format <nl> int FilterParserThread : : parseP2PFilterFile ( QString filePath , libtorrent : : ip_filter & filter ) { <nl> - int ruleCount = 0 ; <nl> - QFile file ( filePath ) ; <nl> - if ( file . exists ( ) ) { <nl> - if ( ! file . open ( QIODevice : : ReadOnly | QIODevice : : Text ) ) { <nl> - std : : cerr < < " I / O Error : Could not open ip filer file in read mode . " < < std : : endl ; <nl> - return ruleCount ; <nl> - } <nl> - unsigned int nbLine = 0 ; <nl> - while ( ! file . atEnd ( ) & & ! abort ) { <nl> - + + nbLine ; <nl> - QByteArray line = file . readLine ( ) . trimmed ( ) ; <nl> - if ( line . isEmpty ( ) ) continue ; <nl> - / / Ignoring commented lines <nl> - if ( line . startsWith ( ' # ' ) | | line . startsWith ( " / / " ) ) continue ; <nl> - / / Line is splitted by : <nl> - QList < QByteArray > partsList = line . split ( ' : ' ) ; <nl> - if ( partsList . size ( ) < 2 ) { <nl> - qDebug ( " p2p file : line % d is malformed . " , nbLine ) ; <nl> - continue ; <nl> - } <nl> - / / Get IP range <nl> - QList < QByteArray > IPs = partsList . last ( ) . split ( ' - ' ) ; <nl> - if ( IPs . size ( ) ! = 2 ) { <nl> - qDebug ( " p2p file : line % d is malformed . " , nbLine ) ; <nl> - qDebug ( " line was : % s " , line . constData ( ) ) ; <nl> - continue ; <nl> - } <nl> - boost : : system : : error_code ec ; <nl> - QString strStartIP = cleanupIPAddress ( IPs . at ( 0 ) ) ; <nl> - if ( strStartIP . isEmpty ( ) ) { <nl> - qDebug ( " p2p file : line % d is malformed . " , nbLine ) ; <nl> - qDebug ( " Start IP is invalid : % s " , qPrintable ( strStartIP ) ) ; <nl> - continue ; <nl> - } <nl> - libtorrent : : address startAddr = libtorrent : : address : : from_string ( qPrintable ( strStartIP ) , ec ) ; <nl> - if ( ec ) { <nl> - qDebug ( " p2p file : line % d is malformed . " , nbLine ) ; <nl> - qDebug ( " Start IP is invalid : % s " , qPrintable ( strStartIP ) ) ; <nl> - continue ; <nl> - } <nl> - QString strEndIP = cleanupIPAddress ( IPs . at ( 1 ) ) ; <nl> - if ( strEndIP . isEmpty ( ) ) { <nl> - qDebug ( " p2p file : line % d is malformed . " , nbLine ) ; <nl> - qDebug ( " End IP is invalid : % s " , qPrintable ( strStartIP ) ) ; <nl> - continue ; <nl> - } <nl> - libtorrent : : address endAddr = libtorrent : : address : : from_string ( qPrintable ( strEndIP ) , ec ) ; <nl> - if ( ec ) { <nl> - qDebug ( " p2p file : line % d is malformed . " , nbLine ) ; <nl> - qDebug ( " End IP is invalid : % s " , qPrintable ( strStartIP ) ) ; <nl> - continue ; <nl> - } <nl> - if ( startAddr . is_v4 ( ) ! = endAddr . is_v4 ( ) ) { <nl> - qDebug ( " p2p file : line % d is malformed . " , nbLine ) ; <nl> - qDebug ( " Line was : % s " , line . constData ( ) ) ; <nl> - continue ; <nl> - } <nl> - try { <nl> - filter . add_rule ( startAddr , endAddr , libtorrent : : ip_filter : : blocked ) ; <nl> - + + ruleCount ; <nl> - } catch ( std : : exception & ) { <nl> - qDebug ( " p2p file : line % d is malformed . " , nbLine ) ; <nl> - qDebug ( " Line was : % s " , line . constData ( ) ) ; <nl> - continue ; <nl> - } <nl> + int ruleCount = 0 ; <nl> + QFile file ( filePath ) ; <nl> + if ( file . exists ( ) ) { <nl> + if ( ! file . open ( QIODevice : : ReadOnly | QIODevice : : Text ) ) { <nl> + std : : cerr < < " I / O Error : Could not open ip filer file in read mode . " < < std : : endl ; <nl> + return ruleCount ; <nl> + } <nl> + unsigned int nbLine = 0 ; <nl> + while ( ! file . atEnd ( ) & & ! abort ) { <nl> + + + nbLine ; <nl> + QByteArray line = file . readLine ( ) . trimmed ( ) ; <nl> + if ( line . isEmpty ( ) ) continue ; <nl> + / / Ignoring commented lines <nl> + if ( line . startsWith ( ' # ' ) | | line . startsWith ( " / / " ) ) continue ; <nl> + / / Line is splitted by : <nl> + QList < QByteArray > partsList = line . split ( ' : ' ) ; <nl> + if ( partsList . size ( ) < 2 ) { <nl> + qDebug ( " p2p file : line % d is malformed . " , nbLine ) ; <nl> + continue ; <nl> + } <nl> + / / Get IP range <nl> + QList < QByteArray > IPs = partsList . last ( ) . split ( ' - ' ) ; <nl> + if ( IPs . size ( ) ! = 2 ) { <nl> + qDebug ( " p2p file : line % d is malformed . " , nbLine ) ; <nl> + qDebug ( " line was : % s " , line . constData ( ) ) ; <nl> + continue ; <nl> + } <nl> + boost : : system : : error_code ec ; <nl> + QString strStartIP = cleanupIPAddress ( IPs . at ( 0 ) ) ; <nl> + if ( strStartIP . isEmpty ( ) ) { <nl> + qDebug ( " p2p file : line % d is malformed . " , nbLine ) ; <nl> + qDebug ( " Start IP is invalid : % s " , qPrintable ( strStartIP ) ) ; <nl> + continue ; <nl> + } <nl> + libtorrent : : address startAddr = libtorrent : : address : : from_string ( qPrintable ( strStartIP ) , ec ) ; <nl> + if ( ec ) { <nl> + qDebug ( " p2p file : line % d is malformed . " , nbLine ) ; <nl> + qDebug ( " Start IP is invalid : % s " , qPrintable ( strStartIP ) ) ; <nl> + continue ; <nl> + } <nl> + QString strEndIP = cleanupIPAddress ( IPs . at ( 1 ) ) ; <nl> + if ( strEndIP . isEmpty ( ) ) { <nl> + qDebug ( " p2p file : line % d is malformed . " , nbLine ) ; <nl> + qDebug ( " End IP is invalid : % s " , qPrintable ( strStartIP ) ) ; <nl> + continue ; <nl> + } <nl> + libtorrent : : address endAddr = libtorrent : : address : : from_string ( qPrintable ( strEndIP ) , ec ) ; <nl> + if ( ec ) { <nl> + qDebug ( " p2p file : line % d is malformed . " , nbLine ) ; <nl> + qDebug ( " End IP is invalid : % s " , qPrintable ( strStartIP ) ) ; <nl> + continue ; <nl> + } <nl> + if ( startAddr . is_v4 ( ) ! = endAddr . is_v4 ( ) ) { <nl> + qDebug ( " p2p file : line % d is malformed . " , nbLine ) ; <nl> + qDebug ( " Line was : % s " , line . constData ( ) ) ; <nl> + continue ; <nl> + } <nl> + try { <nl> + filter . add_rule ( startAddr , endAddr , libtorrent : : ip_filter : : blocked ) ; <nl> + + + ruleCount ; <nl> + } catch ( std : : exception & ) { <nl> + qDebug ( " p2p file : line % d is malformed . " , nbLine ) ; <nl> + qDebug ( " Line was : % s " , line . constData ( ) ) ; <nl> + continue ; <nl> + } <nl> + } <nl> + file . close ( ) ; <nl> } <nl> - file . close ( ) ; <nl> - } <nl> - return ruleCount ; <nl> + return ruleCount ; <nl> } <nl> <nl> int FilterParserThread : : getlineInStream ( QDataStream & stream , string & name , char delim ) { <nl> - char c ; <nl> - int total_read = 0 ; <nl> - int read ; <nl> - do { <nl> - read = stream . readRawData ( & c , 1 ) ; <nl> - total_read + = read ; <nl> - if ( read > 0 ) { <nl> - if ( c ! = delim ) { <nl> - name + = c ; <nl> - } else { <nl> - / / Delim found <nl> - return total_read ; <nl> - } <nl> - } <nl> - } while ( read > 0 ) ; <nl> - return total_read ; <nl> + char c ; <nl> + int total_read = 0 ; <nl> + int read ; <nl> + do { <nl> + read = stream . readRawData ( & c , 1 ) ; <nl> + total_read + = read ; <nl> + if ( read > 0 ) { <nl> + if ( c ! = delim ) { <nl> + name + = c ; <nl> + } else { <nl> + / / Delim found <nl> + return total_read ; <nl> + } <nl> + } <nl> + } while ( read > 0 ) ; <nl> + return total_read ; <nl> } <nl> <nl> / / Parser for PeerGuardian ip filter in p2p format <nl> int FilterParserThread : : parseP2BFilterFile ( QString filePath , libtorrent : : ip_filter & filter ) { <nl> - int ruleCount = 0 ; <nl> - QFile file ( filePath ) ; <nl> - if ( file . exists ( ) ) { <nl> - if ( ! file . open ( QIODevice : : ReadOnly ) ) { <nl> - std : : cerr < < " I / O Error : Could not open ip filer file in read mode . " < < std : : endl ; <nl> - return ruleCount ; <nl> - } <nl> - QDataStream stream ( & file ) ; <nl> - / / Read header <nl> - char buf [ 7 ] ; <nl> - unsigned char version ; <nl> - if ( <nl> - ! stream . readRawData ( buf , sizeof ( buf ) ) | | <nl> - memcmp ( buf , " \ xFF \ xFF \ xFF \ xFFP2B " , 7 ) | | <nl> - ! stream . readRawData ( ( char * ) & version , sizeof ( version ) ) <nl> - ) { <nl> - std : : cerr < < " Parsing Error : The filter file is not a valid PeerGuardian P2B file . " < < std : : endl ; <nl> - return ruleCount ; <nl> - } <nl> - <nl> - if ( version = = 1 | | version = = 2 ) { <nl> - qDebug ( " p2b version 1 or 2 " ) ; <nl> - unsigned int start , end ; <nl> - <nl> - string name ; <nl> - while ( getlineInStream ( stream , name , ' \ 0 ' ) & & ! abort ) { <nl> + int ruleCount = 0 ; <nl> + QFile file ( filePath ) ; <nl> + if ( file . exists ( ) ) { <nl> + if ( ! file . open ( QIODevice : : ReadOnly ) ) { <nl> + std : : cerr < < " I / O Error : Could not open ip filer file in read mode . " < < std : : endl ; <nl> + return ruleCount ; <nl> + } <nl> + QDataStream stream ( & file ) ; <nl> + / / Read header <nl> + char buf [ 7 ] ; <nl> + unsigned char version ; <nl> if ( <nl> - ! stream . readRawData ( ( char * ) & start , sizeof ( start ) ) | | <nl> - ! stream . readRawData ( ( char * ) & end , sizeof ( end ) ) <nl> + ! stream . readRawData ( buf , sizeof ( buf ) ) | | <nl> + memcmp ( buf , " \ xFF \ xFF \ xFF \ xFFP2B " , 7 ) | | <nl> + ! stream . readRawData ( ( char * ) & version , sizeof ( version ) ) <nl> ) { <nl> - std : : cerr < < " Parsing Error : The filter file is not a valid PeerGuardian P2B file . " < < std : : endl ; <nl> - return ruleCount ; <nl> + std : : cerr < < " Parsing Error : The filter file is not a valid PeerGuardian P2B file . " < < std : : endl ; <nl> + return ruleCount ; <nl> } <nl> - / / Network byte order to Host byte order <nl> - / / asio address_v4 contructor expects it <nl> - / / that way <nl> - libtorrent : : address_v4 first ( ntohl ( start ) ) ; <nl> - libtorrent : : address_v4 last ( ntohl ( end ) ) ; <nl> - / / Apply to bittorrent session <nl> - try { <nl> - filter . add_rule ( first , last , libtorrent : : ip_filter : : blocked ) ; <nl> - + + ruleCount ; <nl> - } catch ( std : : exception & ) { } <nl> - } <nl> - } <nl> - else if ( version = = 3 ) { <nl> - qDebug ( " p2b version 3 " ) ; <nl> - unsigned int namecount ; <nl> - if ( ! stream . readRawData ( ( char * ) & namecount , sizeof ( namecount ) ) ) { <nl> - std : : cerr < < " Parsing Error : The filter file is not a valid PeerGuardian P2B file . " < < std : : endl ; <nl> - return ruleCount ; <nl> - } <nl> - namecount = ntohl ( namecount ) ; <nl> - / / Reading names although , we don ' t really care about them <nl> - for ( unsigned int i = 0 ; i < namecount ; i + + ) { <nl> - string name ; <nl> - if ( ! getlineInStream ( stream , name , ' \ 0 ' ) ) { <nl> - std : : cerr < < " Parsing Error : The filter file is not a valid PeerGuardian P2B file . " < < std : : endl ; <nl> - return ruleCount ; <nl> + <nl> + if ( version = = 1 | | version = = 2 ) { <nl> + qDebug ( " p2b version 1 or 2 " ) ; <nl> + unsigned int start , end ; <nl> + <nl> + string name ; <nl> + while ( getlineInStream ( stream , name , ' \ 0 ' ) & & ! abort ) { <nl> + if ( <nl> + ! stream . readRawData ( ( char * ) & start , sizeof ( start ) ) | | <nl> + ! stream . readRawData ( ( char * ) & end , sizeof ( end ) ) <nl> + ) { <nl> + std : : cerr < < " Parsing Error : The filter file is not a valid PeerGuardian P2B file . " < < std : : endl ; <nl> + return ruleCount ; <nl> + } <nl> + / / Network byte order to Host byte order <nl> + / / asio address_v4 contructor expects it <nl> + / / that way <nl> + libtorrent : : address_v4 first ( ntohl ( start ) ) ; <nl> + libtorrent : : address_v4 last ( ntohl ( end ) ) ; <nl> + / / Apply to bittorrent session <nl> + try { <nl> + filter . add_rule ( first , last , libtorrent : : ip_filter : : blocked ) ; <nl> + + + ruleCount ; <nl> + } catch ( std : : exception & ) { } <nl> + } <nl> } <nl> - if ( abort ) return ruleCount ; <nl> - } <nl> - / / Reading the ranges <nl> - unsigned int rangecount ; <nl> - if ( ! stream . readRawData ( ( char * ) & rangecount , sizeof ( rangecount ) ) ) { <nl> - std : : cerr < < " Parsing Error : The filter file is not a valid PeerGuardian P2B file . " < < std : : endl ; <nl> - return ruleCount ; <nl> - } <nl> - rangecount = ntohl ( rangecount ) ; <nl> + else if ( version = = 3 ) { <nl> + qDebug ( " p2b version 3 " ) ; <nl> + unsigned int namecount ; <nl> + if ( ! stream . readRawData ( ( char * ) & namecount , sizeof ( namecount ) ) ) { <nl> + std : : cerr < < " Parsing Error : The filter file is not a valid PeerGuardian P2B file . " < < std : : endl ; <nl> + return ruleCount ; <nl> + } <nl> + namecount = ntohl ( namecount ) ; <nl> + / / Reading names although , we don ' t really care about them <nl> + for ( unsigned int i = 0 ; i < namecount ; i + + ) { <nl> + string name ; <nl> + if ( ! getlineInStream ( stream , name , ' \ 0 ' ) ) { <nl> + std : : cerr < < " Parsing Error : The filter file is not a valid PeerGuardian P2B file . " < < std : : endl ; <nl> + return ruleCount ; <nl> + } <nl> + if ( abort ) return ruleCount ; <nl> + } <nl> + / / Reading the ranges <nl> + unsigned int rangecount ; <nl> + if ( ! stream . readRawData ( ( char * ) & rangecount , sizeof ( rangecount ) ) ) { <nl> + std : : cerr < < " Parsing Error : The filter file is not a valid PeerGuardian P2B file . " < < std : : endl ; <nl> + return ruleCount ; <nl> + } <nl> + rangecount = ntohl ( rangecount ) ; <nl> <nl> - unsigned int name , start , end ; <nl> + unsigned int name , start , end ; <nl> <nl> - for ( unsigned int i = 0 ; i < rangecount ; i + + ) { <nl> - if ( <nl> - ! stream . readRawData ( ( char * ) & name , sizeof ( name ) ) | | <nl> - ! stream . readRawData ( ( char * ) & start , sizeof ( start ) ) | | <nl> - ! stream . readRawData ( ( char * ) & end , sizeof ( end ) ) <nl> - ) { <nl> - std : : cerr < < " Parsing Error : The filter file is not a valid PeerGuardian P2B file . " < < std : : endl ; <nl> - return ruleCount ; <nl> + for ( unsigned int i = 0 ; i < rangecount ; i + + ) { <nl> + if ( <nl> + ! stream . readRawData ( ( char * ) & name , sizeof ( name ) ) | | <nl> + ! stream . readRawData ( ( char * ) & start , sizeof ( start ) ) | | <nl> + ! stream . readRawData ( ( char * ) & end , sizeof ( end ) ) <nl> + ) { <nl> + std : : cerr < < " Parsing Error : The filter file is not a valid PeerGuardian P2B file . " < < std : : endl ; <nl> + return ruleCount ; <nl> + } <nl> + / / Network byte order to Host byte order <nl> + / / asio address_v4 contructor expects it <nl> + / / that way <nl> + libtorrent : : address_v4 first ( ntohl ( start ) ) ; <nl> + libtorrent : : address_v4 last ( ntohl ( end ) ) ; <nl> + / / Apply to bittorrent session <nl> + try { <nl> + filter . add_rule ( first , last , libtorrent : : ip_filter : : blocked ) ; <nl> + + + ruleCount ; <nl> + } catch ( std : : exception & ) { } <nl> + if ( abort ) return ruleCount ; <nl> + } <nl> + } else { <nl> + std : : cerr < < " Parsing Error : The filter file is not a valid PeerGuardian P2B file . " < < std : : endl ; <nl> + return ruleCount ; <nl> } <nl> - / / Network byte order to Host byte order <nl> - / / asio address_v4 contructor expects it <nl> - / / that way <nl> - libtorrent : : address_v4 first ( ntohl ( start ) ) ; <nl> - libtorrent : : address_v4 last ( ntohl ( end ) ) ; <nl> - / / Apply to bittorrent session <nl> - try { <nl> - filter . add_rule ( first , last , libtorrent : : ip_filter : : blocked ) ; <nl> - + + ruleCount ; <nl> - } catch ( std : : exception & ) { } <nl> - if ( abort ) return ruleCount ; <nl> - } <nl> - } else { <nl> - std : : cerr < < " Parsing Error : The filter file is not a valid PeerGuardian P2B file . " < < std : : endl ; <nl> - return ruleCount ; <nl> + file . close ( ) ; <nl> } <nl> - file . close ( ) ; <nl> - } <nl> - return ruleCount ; <nl> + return ruleCount ; <nl> } <nl> <nl> / / Process ip filter file <nl> int FilterParserThread : : parseP2BFilterFile ( QString filePath , libtorrent : : ip_filt <nl> / / * PeerGuardian Text ( P2P ) : http : / / wiki . phoenixlabs . org / wiki / P2P_Format <nl> / / * PeerGuardian Binary ( P2B ) : http : / / wiki . phoenixlabs . org / wiki / P2B_Format <nl> void FilterParserThread : : processFilterFile ( QString _filePath ) { <nl> - if ( isRunning ( ) ) { <nl> - / / Already parsing a filter , abort first <nl> - abort = true ; <nl> - wait ( ) ; <nl> - } <nl> - abort = false ; <nl> - filePath = _filePath ; <nl> - / / Run it <nl> - start ( ) ; <nl> + if ( isRunning ( ) ) { <nl> + / / Already parsing a filter , abort first <nl> + abort = true ; <nl> + wait ( ) ; <nl> + } <nl> + abort = false ; <nl> + filePath = _filePath ; <nl> + / / Run it <nl> + start ( ) ; <nl> } <nl> <nl> void FilterParserThread : : processFilterList ( libtorrent : : session * s , const QStringList & IPs ) { <nl> - / / First , import current filter <nl> - libtorrent : : ip_filter filter = s - > get_ip_filter ( ) ; <nl> - foreach ( const QString & ip , IPs ) { <nl> - qDebug ( " Manual ban of peer % s " , ip . toLocal8Bit ( ) . constData ( ) ) ; <nl> - boost : : system : : error_code ec ; <nl> - libtorrent : : address addr = libtorrent : : address : : from_string ( ip . toLocal8Bit ( ) . constData ( ) , ec ) ; <nl> - Q_ASSERT ( ! ec ) ; <nl> - if ( ! ec ) <nl> - filter . add_rule ( addr , addr , libtorrent : : ip_filter : : blocked ) ; <nl> - } <nl> - s - > set_ip_filter ( filter ) ; <nl> + / / First , import current filter <nl> + libtorrent : : ip_filter filter = s - > get_ip_filter ( ) ; <nl> + foreach ( const QString & ip , IPs ) { <nl> + qDebug ( " Manual ban of peer % s " , ip . toLocal8Bit ( ) . constData ( ) ) ; <nl> + boost : : system : : error_code ec ; <nl> + libtorrent : : address addr = libtorrent : : address : : from_string ( ip . toLocal8Bit ( ) . constData ( ) , ec ) ; <nl> + Q_ASSERT ( ! ec ) ; <nl> + if ( ! ec ) <nl> + filter . add_rule ( addr , addr , libtorrent : : ip_filter : : blocked ) ; <nl> + } <nl> + s - > set_ip_filter ( filter ) ; <nl> } <nl> <nl> QString FilterParserThread : : cleanupIPAddress ( QString _ip ) { <nl> - QHostAddress ip ( _ip . trimmed ( ) ) ; <nl> - if ( ip . isNull ( ) ) { <nl> - return QString ( ) ; <nl> - } <nl> - return ip . toString ( ) ; <nl> + QHostAddress ip ( _ip . trimmed ( ) ) ; <nl> + if ( ip . isNull ( ) ) { <nl> + return QString ( ) ; <nl> + } <nl> + return ip . toString ( ) ; <nl> } <nl> <nl> void FilterParserThread : : run ( ) { <nl> - qDebug ( " Processing filter file " ) ; <nl> - libtorrent : : ip_filter filter = s - > get_ip_filter ( ) ; <nl> - int ruleCount = 0 ; <nl> - if ( filePath . endsWith ( " . p2p " , Qt : : CaseInsensitive ) ) { <nl> - / / PeerGuardian p2p file <nl> - ruleCount = parseP2PFilterFile ( filePath , filter ) ; <nl> - } else { <nl> - if ( filePath . endsWith ( " . p2b " , Qt : : CaseInsensitive ) ) { <nl> - / / PeerGuardian p2b file <nl> - ruleCount = parseP2BFilterFile ( filePath , filter ) ; <nl> + qDebug ( " Processing filter file " ) ; <nl> + libtorrent : : ip_filter filter = s - > get_ip_filter ( ) ; <nl> + int ruleCount = 0 ; <nl> + if ( filePath . endsWith ( " . p2p " , Qt : : CaseInsensitive ) ) { <nl> + / / PeerGuardian p2p file <nl> + ruleCount = parseP2PFilterFile ( filePath , filter ) ; <nl> } else { <nl> - / / Default : eMule DAT format <nl> - ruleCount = parseDATFilterFile ( filePath , filter ) ; <nl> + if ( filePath . endsWith ( " . p2b " , Qt : : CaseInsensitive ) ) { <nl> + / / PeerGuardian p2b file <nl> + ruleCount = parseP2BFilterFile ( filePath , filter ) ; <nl> + } else { <nl> + / / Default : eMule DAT format <nl> + ruleCount = parseDATFilterFile ( filePath , filter ) ; <nl> + } <nl> } <nl> - } <nl> - if ( abort ) <nl> - return ; <nl> - try { <nl> - s - > set_ip_filter ( filter ) ; <nl> - emit IPFilterParsed ( ruleCount ) ; <nl> - } catch ( std : : exception & ) { <nl> - emit IPFilterError ( ) ; <nl> - } <nl> - qDebug ( " IP Filter thread : finished parsing , filter applied " ) ; <nl> + if ( abort ) <nl> + return ; <nl> + try { <nl> + s - > set_ip_filter ( filter ) ; <nl> + emit IPFilterParsed ( ruleCount ) ; <nl> + } catch ( std : : exception & ) { <nl> + emit IPFilterError ( ) ; <nl> + } <nl> + qDebug ( " IP Filter thread : finished parsing , filter applied " ) ; <nl> } <nl> mmm a / src / core / qtlibtorrent / filterparserthread . h <nl> ppp b / src / core / qtlibtorrent / filterparserthread . h <nl> <nl> # include < QStringList > <nl> <nl> namespace libtorrent { <nl> - class session ; <nl> - struct ip_filter ; <nl> + class session ; <nl> + struct ip_filter ; <nl> } <nl> <nl> using namespace std ; <nl> using namespace std ; <nl> / / End of P2B stuff <nl> <nl> class FilterParserThread : public QThread { <nl> - Q_OBJECT <nl> + Q_OBJECT <nl> <nl> public : <nl> - FilterParserThread ( QObject * parent , libtorrent : : session * s ) ; <nl> - ~ FilterParserThread ( ) ; <nl> + FilterParserThread ( QObject * parent , libtorrent : : session * s ) ; <nl> + ~ FilterParserThread ( ) ; <nl> <nl> - int parseDATFilterFile ( QString filePath , libtorrent : : ip_filter & filter ) ; <nl> - int parseP2PFilterFile ( QString filePath , libtorrent : : ip_filter & filter ) ; <nl> - int getlineInStream ( QDataStream & stream , string & name , char delim ) ; <nl> - int parseP2BFilterFile ( QString filePath , libtorrent : : ip_filter & filter ) ; <nl> - void processFilterFile ( QString _filePath ) ; <nl> - static void processFilterList ( libtorrent : : session * s , const QStringList & IPs ) ; <nl> + int parseDATFilterFile ( QString filePath , libtorrent : : ip_filter & filter ) ; <nl> + int parseP2PFilterFile ( QString filePath , libtorrent : : ip_filter & filter ) ; <nl> + int getlineInStream ( QDataStream & stream , string & name , char delim ) ; <nl> + int parseP2BFilterFile ( QString filePath , libtorrent : : ip_filter & filter ) ; <nl> + void processFilterFile ( QString _filePath ) ; <nl> + static void processFilterList ( libtorrent : : session * s , const QStringList & IPs ) ; <nl> <nl> signals : <nl> - void IPFilterParsed ( int ruleCount ) ; <nl> - void IPFilterError ( ) ; <nl> + void IPFilterParsed ( int ruleCount ) ; <nl> + void IPFilterError ( ) ; <nl> <nl> protected : <nl> - QString cleanupIPAddress ( QString _ip ) ; <nl> - void run ( ) ; <nl> + QString cleanupIPAddress ( QString _ip ) ; <nl> + void run ( ) ; <nl> <nl> private : <nl> - libtorrent : : session * s ; <nl> - bool abort ; <nl> - QString filePath ; <nl> + libtorrent : : session * s ; <nl> + bool abort ; <nl> + QString filePath ; <nl> } ; <nl> <nl> # endif <nl> mmm a / src / core / qtlibtorrent / qbtsession . cpp <nl> ppp b / src / core / qtlibtorrent / qbtsession . cpp <nl> const int MAX_TRACKER_ERRORS = 2 ; <nl> <nl> / * Converts a QString hash into a libtorrent sha1_hash * / <nl> static libtorrent : : sha1_hash QStringToSha1 ( const QString & s ) { <nl> - QByteArray raw = s . toLatin1 ( ) ; <nl> - Q_ASSERT ( raw . size ( ) = = 40 ) ; <nl> - libtorrent : : sha1_hash ret ; <nl> - from_hex ( raw . constData ( ) , 40 , ( char * ) & ret [ 0 ] ) ; <nl> - return ret ; <nl> + QByteArray raw = s . toLatin1 ( ) ; <nl> + Q_ASSERT ( raw . size ( ) = = 40 ) ; <nl> + libtorrent : : sha1_hash ret ; <nl> + from_hex ( raw . constData ( ) , 40 , ( char * ) & ret [ 0 ] ) ; <nl> + return ret ; <nl> } <nl> <nl> / / Main constructor <nl> QBtSession : : QBtSession ( ) <nl> - : m_scanFolders ( ScanFoldersModel : : instance ( this ) ) , <nl> - preAllocateAll ( false ) , global_ratio_limit ( - 1 ) , <nl> - LSDEnabled ( false ) , <nl> - DHTEnabled ( false ) , queueingEnabled ( false ) , <nl> - m_torrentExportEnabled ( false ) , <nl> - m_finishedTorrentExportEnabled ( false ) <nl> - # ifndef DISABLE_GUI <nl> - , geoipDBLoaded ( false ) , resolve_countries ( false ) <nl> - # endif <nl> - , m_tracker ( 0 ) , m_shutdownAct ( NO_SHUTDOWN ) <nl> - # if LIBTORRENT_VERSION_NUM < 10000 <nl> - , m_upnp ( 0 ) , m_natpmp ( 0 ) <nl> - # endif <nl> - , m_alertDispatcher ( 0 ) <nl> + : m_scanFolders ( ScanFoldersModel : : instance ( this ) ) , <nl> + preAllocateAll ( false ) , global_ratio_limit ( - 1 ) , <nl> + LSDEnabled ( false ) , <nl> + DHTEnabled ( false ) , queueingEnabled ( false ) , <nl> + m_torrentExportEnabled ( false ) , <nl> + m_finishedTorrentExportEnabled ( false ) <nl> + # ifndef DISABLE_GUI <nl> + , geoipDBLoaded ( false ) , resolve_countries ( false ) <nl> + # endif <nl> + , m_tracker ( 0 ) , m_shutdownAct ( NO_SHUTDOWN ) <nl> + # if LIBTORRENT_VERSION_NUM < 10000 <nl> + , m_upnp ( 0 ) , m_natpmp ( 0 ) <nl> + # endif <nl> + , m_alertDispatcher ( 0 ) <nl> { <nl> - BigRatioTimer = new QTimer ( this ) ; <nl> - BigRatioTimer - > setInterval ( 10000 ) ; <nl> - connect ( BigRatioTimer , SIGNAL ( timeout ( ) ) , SLOT ( processBigRatios ( ) ) ) ; <nl> - Preferences * const pref = Preferences : : instance ( ) ; <nl> - / / Creating Bittorrent session <nl> - QList < int > version ; <nl> - version < < VERSION_MAJOR ; <nl> - version < < VERSION_MINOR ; <nl> - version < < VERSION_BUGFIX ; <nl> - version < < VERSION_BUILD ; <nl> - const QString peer_id = " qB " ; <nl> - / / Construct session <nl> - s = new session ( fingerprint ( peer_id . toLocal8Bit ( ) . constData ( ) , version . at ( 0 ) , version . at ( 1 ) , version . at ( 2 ) , version . at ( 3 ) ) , 0 ) ; <nl> - / / std : : cout < < " Peer ID : " < < fingerprint ( peer_id . toLocal8Bit ( ) . constData ( ) , version . at ( 0 ) , version . at ( 1 ) , version . at ( 2 ) , version . at ( 3 ) ) . to_string ( ) < < std : : endl ; <nl> - Logger : : instance ( ) - > addMessage ( " Peer ID : " + misc : : toQString ( fingerprint ( peer_id . toLocal8Bit ( ) . constData ( ) , version . at ( 0 ) , version . at ( 1 ) , version . at ( 2 ) , version . at ( 3 ) ) . to_string ( ) ) ) ; <nl> - <nl> - / / Set severity level of libtorrent session <nl> - s - > set_alert_mask ( alert : : error_notification | alert : : peer_notification | alert : : port_mapping_notification | alert : : storage_notification | alert : : tracker_notification | alert : : status_notification | alert : : ip_block_notification | alert : : progress_notification | alert : : stats_notification ) ; <nl> - / / Load previous state <nl> - loadSessionState ( ) ; <nl> - / / Enabling plugins <nl> - / / s - > add_extension ( & create_metadata_plugin ) ; <nl> - s - > add_extension ( & create_ut_metadata_plugin ) ; <nl> - if ( pref - > trackerExchangeEnabled ( ) ) <nl> - s - > add_extension ( & create_lt_trackers_plugin ) ; <nl> - if ( pref - > isPeXEnabled ( ) ) { <nl> - PeXEnabled = true ; <nl> - s - > add_extension ( & create_ut_pex_plugin ) ; <nl> - } else { <nl> - PeXEnabled = false ; <nl> - } <nl> - s - > add_extension ( & create_smart_ban_plugin ) ; <nl> - m_alertDispatcher = new QAlertDispatcher ( s , this ) ; <nl> - connect ( m_alertDispatcher , SIGNAL ( alertsReceived ( ) ) , SLOT ( readAlerts ( ) ) ) ; <nl> - appendLabelToSavePath = pref - > appendTorrentLabel ( ) ; <nl> - appendqBExtension = pref - > useIncompleteFilesExtension ( ) ; <nl> - connect ( m_scanFolders , SIGNAL ( torrentsAdded ( QStringList & ) ) , SLOT ( addTorrentsFromScanFolder ( QStringList & ) ) ) ; <nl> - / / Apply user settings to Bittorrent session <nl> - configureSession ( ) ; <nl> - connect ( pref , SIGNAL ( changed ( ) ) , SLOT ( configureSession ( ) ) ) ; <nl> - / / Torrent speed monitor <nl> - m_speedMonitor = new TorrentSpeedMonitor ( this ) ; <nl> - m_torrentStatistics = new TorrentStatistics ( this , this ) ; <nl> - / / To download from urls <nl> - downloader = new DownloadThread ( this ) ; <nl> - connect ( downloader , SIGNAL ( downloadFinished ( QString , QString ) ) , SLOT ( processDownloadedFile ( QString , QString ) ) ) ; <nl> - connect ( downloader , SIGNAL ( downloadFailure ( QString , QString ) ) , SLOT ( handleDownloadFailure ( QString , QString ) ) ) ; <nl> - connect ( downloader , SIGNAL ( magnetRedirect ( QString , QString ) ) , SLOT ( handleMagnetRedirect ( QString , QString ) ) ) ; <nl> - / / Regular saving of fastresume data <nl> - connect ( & resumeDataTimer , SIGNAL ( timeout ( ) ) , SLOT ( saveTempFastResumeData ( ) ) ) ; <nl> - resumeDataTimer . start ( pref - > saveResumeDataInterval ( ) * 60 * 1000 ) ; <nl> - qDebug ( " * BTSession constructed " ) ; <nl> + BigRatioTimer = new QTimer ( this ) ; <nl> + BigRatioTimer - > setInterval ( 10000 ) ; <nl> + connect ( BigRatioTimer , SIGNAL ( timeout ( ) ) , SLOT ( processBigRatios ( ) ) ) ; <nl> + Preferences * const pref = Preferences : : instance ( ) ; <nl> + / / Creating Bittorrent session <nl> + QList < int > version ; <nl> + version < < VERSION_MAJOR ; <nl> + version < < VERSION_MINOR ; <nl> + version < < VERSION_BUGFIX ; <nl> + version < < VERSION_BUILD ; <nl> + const QString peer_id = " qB " ; <nl> + / / Construct session <nl> + s = new session ( fingerprint ( peer_id . toLocal8Bit ( ) . constData ( ) , version . at ( 0 ) , version . at ( 1 ) , version . at ( 2 ) , version . at ( 3 ) ) , 0 ) ; <nl> + / / std : : cout < < " Peer ID : " < < fingerprint ( peer_id . toLocal8Bit ( ) . constData ( ) , version . at ( 0 ) , version . at ( 1 ) , version . at ( 2 ) , version . at ( 3 ) ) . to_string ( ) < < std : : endl ; <nl> + Logger : : instance ( ) - > addMessage ( " Peer ID : " + misc : : toQString ( fingerprint ( peer_id . toLocal8Bit ( ) . constData ( ) , version . at ( 0 ) , version . at ( 1 ) , version . at ( 2 ) , version . at ( 3 ) ) . to_string ( ) ) ) ; <nl> + <nl> + / / Set severity level of libtorrent session <nl> + s - > set_alert_mask ( alert : : error_notification | alert : : peer_notification | alert : : port_mapping_notification | alert : : storage_notification | alert : : tracker_notification | alert : : status_notification | alert : : ip_block_notification | alert : : progress_notification | alert : : stats_notification ) ; <nl> + / / Load previous state <nl> + loadSessionState ( ) ; <nl> + / / Enabling plugins <nl> + / / s - > add_extension ( & create_metadata_plugin ) ; <nl> + s - > add_extension ( & create_ut_metadata_plugin ) ; <nl> + if ( pref - > trackerExchangeEnabled ( ) ) <nl> + s - > add_extension ( & create_lt_trackers_plugin ) ; <nl> + if ( pref - > isPeXEnabled ( ) ) { <nl> + PeXEnabled = true ; <nl> + s - > add_extension ( & create_ut_pex_plugin ) ; <nl> + } else { <nl> + PeXEnabled = false ; <nl> + } <nl> + s - > add_extension ( & create_smart_ban_plugin ) ; <nl> + m_alertDispatcher = new QAlertDispatcher ( s , this ) ; <nl> + connect ( m_alertDispatcher , SIGNAL ( alertsReceived ( ) ) , SLOT ( readAlerts ( ) ) ) ; <nl> + appendLabelToSavePath = pref - > appendTorrentLabel ( ) ; <nl> + appendqBExtension = pref - > useIncompleteFilesExtension ( ) ; <nl> + connect ( m_scanFolders , SIGNAL ( torrentsAdded ( QStringList & ) ) , SLOT ( addTorrentsFromScanFolder ( QStringList & ) ) ) ; <nl> + / / Apply user settings to Bittorrent session <nl> + configureSession ( ) ; <nl> + connect ( pref , SIGNAL ( changed ( ) ) , SLOT ( configureSession ( ) ) ) ; <nl> + / / Torrent speed monitor <nl> + m_speedMonitor = new TorrentSpeedMonitor ( this ) ; <nl> + m_torrentStatistics = new TorrentStatistics ( this , this ) ; <nl> + / / To download from urls <nl> + downloader = new DownloadThread ( this ) ; <nl> + connect ( downloader , SIGNAL ( downloadFinished ( QString , QString ) ) , SLOT ( processDownloadedFile ( QString , QString ) ) ) ; <nl> + connect ( downloader , SIGNAL ( downloadFailure ( QString , QString ) ) , SLOT ( handleDownloadFailure ( QString , QString ) ) ) ; <nl> + connect ( downloader , SIGNAL ( magnetRedirect ( QString , QString ) ) , SLOT ( handleMagnetRedirect ( QString , QString ) ) ) ; <nl> + / / Regular saving of fastresume data <nl> + connect ( & resumeDataTimer , SIGNAL ( timeout ( ) ) , SLOT ( saveTempFastResumeData ( ) ) ) ; <nl> + resumeDataTimer . start ( pref - > saveResumeDataInterval ( ) * 60 * 1000 ) ; <nl> + qDebug ( " * BTSession constructed " ) ; <nl> } <nl> <nl> / / Main destructor <nl> QBtSession : : ~ QBtSession ( ) { <nl> - qDebug ( " BTSession destructor IN " ) ; <nl> - delete m_speedMonitor ; <nl> - qDebug ( " Deleted the torrent speed monitor " ) ; <nl> - / / Do some BT related saving <nl> - saveSessionState ( ) ; <nl> - saveFastResumeData ( ) ; <nl> - / / Delete our objects <nl> - if ( m_tracker ) <nl> - delete m_tracker ; <nl> - if ( BigRatioTimer ) <nl> - delete BigRatioTimer ; <nl> - if ( filterParser ) <nl> - delete filterParser ; <nl> - delete downloader ; <nl> - if ( bd_scheduler ) <nl> - delete bd_scheduler ; <nl> - delete m_alertDispatcher ; <nl> - delete m_torrentStatistics ; <nl> - qDebug ( " Deleting the session " ) ; <nl> - delete s ; <nl> - qDebug ( " BTSession destructor OUT " ) ; <nl> + qDebug ( " BTSession destructor IN " ) ; <nl> + delete m_speedMonitor ; <nl> + qDebug ( " Deleted the torrent speed monitor " ) ; <nl> + / / Do some BT related saving <nl> + saveSessionState ( ) ; <nl> + saveFastResumeData ( ) ; <nl> + / / Delete our objects <nl> + if ( m_tracker ) <nl> + delete m_tracker ; <nl> + if ( BigRatioTimer ) <nl> + delete BigRatioTimer ; <nl> + if ( filterParser ) <nl> + delete filterParser ; <nl> + delete downloader ; <nl> + if ( bd_scheduler ) <nl> + delete bd_scheduler ; <nl> + delete m_alertDispatcher ; <nl> + delete m_torrentStatistics ; <nl> + qDebug ( " Deleting the session " ) ; <nl> + delete s ; <nl> + qDebug ( " BTSession destructor OUT " ) ; <nl> # ifndef DISABLE_GUI <nl> - if ( m_shutdownAct ! = NO_SHUTDOWN ) { <nl> - qDebug ( ) < < " Sending computer shutdown / suspend / hibernate signal . . . " ; <nl> - misc : : shutdownComputer ( m_shutdownAct ) ; <nl> - } <nl> + if ( m_shutdownAct ! = NO_SHUTDOWN ) { <nl> + qDebug ( ) < < " Sending computer shutdown / suspend / hibernate signal . . . " ; <nl> + misc : : shutdownComputer ( m_shutdownAct ) ; <nl> + } <nl> # endif <nl> } <nl> <nl> void QBtSession : : preAllocateAllFiles ( bool b ) { <nl> - const bool change = ( preAllocateAll ! = b ) ; <nl> - if ( change ) { <nl> - qDebug ( " PreAllocateAll changed , reloading all torrents ! " ) ; <nl> - preAllocateAll = b ; <nl> - } <nl> + const bool change = ( preAllocateAll ! = b ) ; <nl> + if ( change ) { <nl> + qDebug ( " PreAllocateAll changed , reloading all torrents ! " ) ; <nl> + preAllocateAll = b ; <nl> + } <nl> } <nl> <nl> void QBtSession : : processBigRatios ( ) { <nl> - qDebug ( " Process big ratios . . . " ) ; <nl> - std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> - <nl> - std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> - std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> - for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> - const QTorrentHandle h ( * torrentIT ) ; <nl> - if ( ! h . is_valid ( ) ) continue ; <nl> - if ( h . is_seed ( ) ) { <nl> - const QString hash = h . hash ( ) ; <nl> - const qreal ratio = getRealRatio ( h . status ( torrent_handle : : query_accurate_download_counters ) ) ; <nl> - qreal ratio_limit = TorrentPersistentData : : instance ( ) - > getRatioLimit ( hash ) ; <nl> - if ( ratio_limit = = TorrentPersistentData : : USE_GLOBAL_RATIO ) <nl> - ratio_limit = global_ratio_limit ; <nl> - if ( ratio_limit = = TorrentPersistentData : : NO_RATIO_LIMIT ) <nl> - continue ; <nl> - qDebug ( " Ratio : % f ( limit : % f ) " , ratio , ratio_limit ) ; <nl> - Q_ASSERT ( ratio_limit > = 0 . f ) ; <nl> - if ( ratio < = MAX_RATIO & & ratio > = ratio_limit ) { <nl> - Logger * const logger = Logger : : instance ( ) ; <nl> - if ( high_ratio_action = = REMOVE_ACTION ) { <nl> - logger - > addMessage ( tr ( " % 1 reached the maximum ratio you set . " ) . arg ( h . name ( ) ) ) ; <nl> - logger - > addMessage ( tr ( " Removing torrent % 1 . . . " ) . arg ( h . name ( ) ) ) ; <nl> - deleteTorrent ( hash ) ; <nl> - } else { <nl> - / / Pause it <nl> - if ( ! h . is_paused ( ) ) { <nl> - logger - > addMessage ( tr ( " % 1 reached the maximum ratio you set . " ) . arg ( h . name ( ) ) ) ; <nl> - logger - > addMessage ( tr ( " Pausing torrent % 1 . . . " ) . arg ( h . name ( ) ) ) ; <nl> - pauseTorrent ( hash ) ; <nl> - } <nl> + qDebug ( " Process big ratios . . . " ) ; <nl> + std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> + <nl> + std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> + std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> + for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> + const QTorrentHandle h ( * torrentIT ) ; <nl> + if ( ! h . is_valid ( ) ) continue ; <nl> + if ( h . is_seed ( ) ) { <nl> + const QString hash = h . hash ( ) ; <nl> + const qreal ratio = getRealRatio ( h . status ( torrent_handle : : query_accurate_download_counters ) ) ; <nl> + qreal ratio_limit = TorrentPersistentData : : instance ( ) - > getRatioLimit ( hash ) ; <nl> + if ( ratio_limit = = TorrentPersistentData : : USE_GLOBAL_RATIO ) <nl> + ratio_limit = global_ratio_limit ; <nl> + if ( ratio_limit = = TorrentPersistentData : : NO_RATIO_LIMIT ) <nl> + continue ; <nl> + qDebug ( " Ratio : % f ( limit : % f ) " , ratio , ratio_limit ) ; <nl> + Q_ASSERT ( ratio_limit > = 0 . f ) ; <nl> + if ( ratio < = MAX_RATIO & & ratio > = ratio_limit ) { <nl> + Logger * const logger = Logger : : instance ( ) ; <nl> + if ( high_ratio_action = = REMOVE_ACTION ) { <nl> + logger - > addMessage ( tr ( " % 1 reached the maximum ratio you set . " ) . arg ( h . name ( ) ) ) ; <nl> + logger - > addMessage ( tr ( " Removing torrent % 1 . . . " ) . arg ( h . name ( ) ) ) ; <nl> + deleteTorrent ( hash ) ; <nl> + } else { <nl> + / / Pause it <nl> + if ( ! h . is_paused ( ) ) { <nl> + logger - > addMessage ( tr ( " % 1 reached the maximum ratio you set . " ) . arg ( h . name ( ) ) ) ; <nl> + logger - > addMessage ( tr ( " Pausing torrent % 1 . . . " ) . arg ( h . name ( ) ) ) ; <nl> + pauseTorrent ( hash ) ; <nl> + } <nl> + } <nl> + / / emit torrent_ratio_deleted ( fileName ) ; <nl> + } <nl> } <nl> - / / emit torrent_ratio_deleted ( fileName ) ; <nl> - } <nl> } <nl> - } <nl> } <nl> <nl> void QBtSession : : setDownloadLimit ( QString hash , long val ) { <nl> - QTorrentHandle h = getTorrentHandle ( hash ) ; <nl> - if ( h . is_valid ( ) ) { <nl> - h . set_download_limit ( val ) ; <nl> - } <nl> + QTorrentHandle h = getTorrentHandle ( hash ) ; <nl> + if ( h . is_valid ( ) ) { <nl> + h . set_download_limit ( val ) ; <nl> + } <nl> } <nl> <nl> void QBtSession : : setUploadLimit ( QString hash , long val ) { <nl> - qDebug ( " Set upload limit rate to % ld " , val ) ; <nl> - QTorrentHandle h = getTorrentHandle ( hash ) ; <nl> - if ( h . is_valid ( ) ) { <nl> - h . set_upload_limit ( val ) ; <nl> - } <nl> + qDebug ( " Set upload limit rate to % ld " , val ) ; <nl> + QTorrentHandle h = getTorrentHandle ( hash ) ; <nl> + if ( h . is_valid ( ) ) { <nl> + h . set_upload_limit ( val ) ; <nl> + } <nl> } <nl> <nl> void QBtSession : : handleDownloadFailure ( QString url , QString reason ) { <nl> - emit downloadFromUrlFailure ( url , reason ) ; <nl> - / / Clean up <nl> - const QUrl qurl = QUrl : : fromEncoded ( url . toUtf8 ( ) ) ; <nl> - url_skippingDlg . removeOne ( qurl ) ; <nl> - savepathLabel_fromurl . remove ( qurl ) ; <nl> + emit downloadFromUrlFailure ( url , reason ) ; <nl> + / / Clean up <nl> + const QUrl qurl = QUrl : : fromEncoded ( url . toUtf8 ( ) ) ; <nl> + url_skippingDlg . removeOne ( qurl ) ; <nl> + savepathLabel_fromurl . remove ( qurl ) ; <nl> # ifndef DISABLE_GUI <nl> - addpaused_fromurl . remove ( qurl ) ; <nl> + addpaused_fromurl . remove ( qurl ) ; <nl> # endif <nl> } <nl> <nl> void QBtSession : : handleMagnetRedirect ( const QString & url_new , const QString & url_old ) { <nl> - if ( url_skippingDlg . contains ( url_old ) ) { <nl> - url_skippingDlg . removeOne ( url_old ) ; <nl> - QPair < QString , QString > savePath_label ; <nl> - if ( savepathLabel_fromurl . contains ( url_old ) ) { <nl> - savePath_label = savepathLabel_fromurl . take ( url_old ) ; <nl> - } <nl> + if ( url_skippingDlg . contains ( url_old ) ) { <nl> + url_skippingDlg . removeOne ( url_old ) ; <nl> + QPair < QString , QString > savePath_label ; <nl> + if ( savepathLabel_fromurl . contains ( url_old ) ) { <nl> + savePath_label = savepathLabel_fromurl . take ( url_old ) ; <nl> + } <nl> # ifndef DISABLE_GUI <nl> - RssDownloadRule : : AddPausedState state = RssDownloadRule : : USE_GLOBAL ; <nl> - if ( addpaused_fromurl . contains ( url_old ) ) { <nl> - state = addpaused_fromurl . take ( url_old ) ; <nl> - } <nl> + RssDownloadRule : : AddPausedState state = RssDownloadRule : : USE_GLOBAL ; <nl> + if ( addpaused_fromurl . contains ( url_old ) ) { <nl> + state = addpaused_fromurl . take ( url_old ) ; <nl> + } <nl> # endif <nl> - addMagnetSkipAddDlg ( url_new , savePath_label . first , savePath_label . second , <nl> - # ifndef DISABLE_GUI <nl> - state , <nl> - # endif <nl> - url_old ) ; <nl> - } <nl> - else <nl> - addMagnetInteractive ( url_new ) ; <nl> + addMagnetSkipAddDlg ( url_new , savePath_label . first , savePath_label . second , <nl> + # ifndef DISABLE_GUI <nl> + state , <nl> + # endif <nl> + url_old ) ; <nl> + } <nl> + else <nl> + addMagnetInteractive ( url_new ) ; <nl> } <nl> <nl> void QBtSession : : setQueueingEnabled ( bool enable ) { <nl> - if ( queueingEnabled ! = enable ) { <nl> - qDebug ( " Queueing system is changing state . . . " ) ; <nl> - queueingEnabled = enable ; <nl> - } <nl> + if ( queueingEnabled ! = enable ) { <nl> + qDebug ( " Queueing system is changing state . . . " ) ; <nl> + queueingEnabled = enable ; <nl> + } <nl> } <nl> <nl> / / Set BT session configuration <nl> void QBtSession : : configureSession ( ) { <nl> - qDebug ( " Configuring session " ) ; <nl> - Preferences * const pref = Preferences : : instance ( ) ; <nl> - <nl> - const unsigned short old_listenPort = getListenPort ( ) ; <nl> - const unsigned short new_listenPort = pref - > getSessionPort ( ) ; <nl> - if ( old_listenPort ! = new_listenPort ) { <nl> - qDebug ( " Session port changes in program preferences : % d - > % d " , old_listenPort , new_listenPort ) ; <nl> - setListeningPort ( new_listenPort ) ; <nl> - } <nl> - <nl> - / / Downloads <nl> - / / * Save path <nl> - defaultSavePath = pref - > getSavePath ( ) ; <nl> - if ( pref - > isTempPathEnabled ( ) ) { <nl> - setDefaultTempPath ( pref - > getTempPath ( ) ) ; <nl> - } else { <nl> - setDefaultTempPath ( QString : : null ) ; <nl> - } <nl> - setAppendLabelToSavePath ( pref - > appendTorrentLabel ( ) ) ; <nl> - setAppendqBExtension ( pref - > useIncompleteFilesExtension ( ) ) ; <nl> - preAllocateAllFiles ( pref - > preAllocateAllFiles ( ) ) ; <nl> - / / * Torrent export directory <nl> - const bool torrentExportEnabled = pref - > isTorrentExportEnabled ( ) ; <nl> - if ( m_torrentExportEnabled ! = torrentExportEnabled ) { <nl> - m_torrentExportEnabled = torrentExportEnabled ; <nl> - if ( m_torrentExportEnabled ) { <nl> - qDebug ( " Torrent export is enabled , exporting the current torrents " ) ; <nl> - exportTorrentFiles ( pref - > getTorrentExportDir ( ) ) ; <nl> - } <nl> - } <nl> - / / * Finished Torrent export directory <nl> - const bool finishedTorrentExportEnabled = pref - > isFinishedTorrentExportEnabled ( ) ; <nl> - if ( m_finishedTorrentExportEnabled ! = finishedTorrentExportEnabled ) <nl> - m_finishedTorrentExportEnabled = finishedTorrentExportEnabled ; <nl> - / / Connection <nl> - / / * Global download limit <nl> - const bool alternative_speeds = pref - > isAltBandwidthEnabled ( ) ; <nl> - int down_limit ; <nl> - if ( alternative_speeds ) <nl> - down_limit = pref - > getAltGlobalDownloadLimit ( ) ; <nl> - else <nl> - down_limit = pref - > getGlobalDownloadLimit ( ) ; <nl> - if ( down_limit < = 0 ) { <nl> - / / Download limit disabled <nl> - setDownloadRateLimit ( - 1 ) ; <nl> - } else { <nl> - / / Enabled <nl> - setDownloadRateLimit ( down_limit * 1024 ) ; <nl> - } <nl> - int up_limit ; <nl> - if ( alternative_speeds ) <nl> - up_limit = pref - > getAltGlobalUploadLimit ( ) ; <nl> - else <nl> - up_limit = pref - > getGlobalUploadLimit ( ) ; <nl> - / / * Global Upload limit <nl> - if ( up_limit < = 0 ) { <nl> - / / Upload limit disabled <nl> - setUploadRateLimit ( - 1 ) ; <nl> - } else { <nl> - / / Enabled <nl> - setUploadRateLimit ( up_limit * 1024 ) ; <nl> - } <nl> - if ( pref - > isSchedulerEnabled ( ) ) { <nl> - if ( ! bd_scheduler ) { <nl> - bd_scheduler = new BandwidthScheduler ( this ) ; <nl> - connect ( bd_scheduler , SIGNAL ( switchToAlternativeMode ( bool ) ) , this , SLOT ( useAlternativeSpeedsLimit ( bool ) ) ) ; <nl> - } <nl> - bd_scheduler - > start ( ) ; <nl> - } else { <nl> - delete bd_scheduler ; <nl> - } <nl> - # ifndef DISABLE_GUI <nl> - / / Resolve countries <nl> - qDebug ( " Loading country resolution settings " ) ; <nl> - const bool new_resolv_countries = pref - > resolvePeerCountries ( ) ; <nl> - if ( resolve_countries ! = new_resolv_countries ) { <nl> - qDebug ( " in country resolution settings " ) ; <nl> - resolve_countries = new_resolv_countries ; <nl> - if ( resolve_countries & & ! geoipDBLoaded ) { <nl> - qDebug ( " Loading geoip database " ) ; <nl> - GeoIPManager : : loadDatabase ( s ) ; <nl> - geoipDBLoaded = true ; <nl> - } <nl> - / / Update torrent handles <nl> - std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> + qDebug ( " Configuring session " ) ; <nl> + Preferences * const pref = Preferences : : instance ( ) ; <nl> <nl> - std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> - std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> - for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> - QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> - if ( h . is_valid ( ) ) <nl> - h . resolve_countries ( resolve_countries ) ; <nl> + const unsigned short old_listenPort = getListenPort ( ) ; <nl> + const unsigned short new_listenPort = pref - > getSessionPort ( ) ; <nl> + if ( old_listenPort ! = new_listenPort ) { <nl> + qDebug ( " Session port changes in program preferences : % d - > % d " , old_listenPort , new_listenPort ) ; <nl> + setListeningPort ( new_listenPort ) ; <nl> } <nl> - } <nl> - # endif <nl> - / / * UPnP / NAT - PMP <nl> - Logger * const logger = Logger : : instance ( ) ; <nl> - if ( pref - > isUPnPEnabled ( ) ) { <nl> - enableUPnP ( true ) ; <nl> - logger - > addMessage ( tr ( " UPnP / NAT - PMP support [ ON ] " ) , Log : : INFO ) ; <nl> - } else { <nl> - enableUPnP ( false ) ; <nl> - logger - > addMessage ( tr ( " UPnP / NAT - PMP support [ OFF ] " ) , Log : : INFO ) ; <nl> - } <nl> - / / * Session settings <nl> - session_settings sessionSettings = s - > settings ( ) ; <nl> - sessionSettings . user_agent = " qBittorrent " VERSION ; <nl> - / / std : : cout < < " HTTP user agent is " < < sessionSettings . user_agent < < std : : endl ; <nl> - logger - > addMessage ( tr ( " HTTP user agent is % 1 " ) . arg ( misc : : toQString ( sessionSettings . user_agent ) ) ) ; <nl> - <nl> - sessionSettings . upnp_ignore_nonrouters = true ; <nl> - sessionSettings . use_dht_as_fallback = false ; <nl> - / / Disable support for SSL torrents for now <nl> - sessionSettings . ssl_listen = 0 ; <nl> - / / To prevent ISPs from blocking seeding <nl> - sessionSettings . lazy_bitfields = true ; <nl> - / / Speed up exit <nl> - sessionSettings . stop_tracker_timeout = 1 ; <nl> - / / sessionSettings . announce_to_all_trackers = true ; <nl> - sessionSettings . auto_scrape_interval = 1200 ; / / 20 minutes <nl> - bool announce_to_all = pref - > announceToAllTrackers ( ) ; <nl> - sessionSettings . announce_to_all_trackers = announce_to_all ; <nl> - sessionSettings . announce_to_all_tiers = announce_to_all ; <nl> - sessionSettings . auto_scrape_min_interval = 900 ; / / 15 minutes <nl> - int cache_size = pref - > diskCacheSize ( ) ; <nl> - sessionSettings . cache_size = cache_size ? cache_size * 64 : - 1 ; <nl> - sessionSettings . cache_expiry = pref - > diskCacheTTL ( ) ; <nl> - qDebug ( ) < < " Using a disk cache size of " < < cache_size < < " MiB " ; <nl> - session_settings : : io_buffer_mode_t mode = pref - > osCache ( ) ? session_settings : : enable_os_cache : session_settings : : disable_os_cache ; <nl> - sessionSettings . disk_io_read_mode = mode ; <nl> - sessionSettings . disk_io_write_mode = mode ; <nl> - resumeDataTimer . setInterval ( pref - > saveResumeDataInterval ( ) * 60 * 1000 ) ; <nl> - sessionSettings . anonymous_mode = pref - > isAnonymousModeEnabled ( ) ; <nl> - if ( sessionSettings . anonymous_mode ) { <nl> - logger - > addMessage ( tr ( " Anonymous mode [ ON ] " ) , Log : : INFO ) ; <nl> - } else { <nl> - logger - > addMessage ( tr ( " Anonymous mode [ OFF ] " ) , Log : : INFO ) ; <nl> - } <nl> - / / Queueing System <nl> - if ( pref - > isQueueingSystemEnabled ( ) ) { <nl> - int max_downloading = pref - > getMaxActiveDownloads ( ) ; <nl> - int max_active = pref - > getMaxActiveTorrents ( ) ; <nl> - if ( max_downloading > - 1 ) <nl> - sessionSettings . active_downloads = max_downloading + HiddenData : : getDownloadingSize ( ) ; <nl> + <nl> + / / Downloads <nl> + / / * Save path <nl> + defaultSavePath = pref - > getSavePath ( ) ; <nl> + if ( pref - > isTempPathEnabled ( ) ) { <nl> + setDefaultTempPath ( pref - > getTempPath ( ) ) ; <nl> + } else { <nl> + setDefaultTempPath ( QString : : null ) ; <nl> + } <nl> + setAppendLabelToSavePath ( pref - > appendTorrentLabel ( ) ) ; <nl> + setAppendqBExtension ( pref - > useIncompleteFilesExtension ( ) ) ; <nl> + preAllocateAllFiles ( pref - > preAllocateAllFiles ( ) ) ; <nl> + / / * Torrent export directory <nl> + const bool torrentExportEnabled = pref - > isTorrentExportEnabled ( ) ; <nl> + if ( m_torrentExportEnabled ! = torrentExportEnabled ) { <nl> + m_torrentExportEnabled = torrentExportEnabled ; <nl> + if ( m_torrentExportEnabled ) { <nl> + qDebug ( " Torrent export is enabled , exporting the current torrents " ) ; <nl> + exportTorrentFiles ( pref - > getTorrentExportDir ( ) ) ; <nl> + } <nl> + } <nl> + / / * Finished Torrent export directory <nl> + const bool finishedTorrentExportEnabled = pref - > isFinishedTorrentExportEnabled ( ) ; <nl> + if ( m_finishedTorrentExportEnabled ! = finishedTorrentExportEnabled ) <nl> + m_finishedTorrentExportEnabled = finishedTorrentExportEnabled ; <nl> + / / Connection <nl> + / / * Global download limit <nl> + const bool alternative_speeds = pref - > isAltBandwidthEnabled ( ) ; <nl> + int down_limit ; <nl> + if ( alternative_speeds ) <nl> + down_limit = pref - > getAltGlobalDownloadLimit ( ) ; <nl> else <nl> - sessionSettings . active_downloads = max_downloading ; <nl> - if ( max_active > - 1 ) { <nl> - int limit = max_active + HiddenData : : getDownloadingSize ( ) ; <nl> - sessionSettings . active_limit = limit ; <nl> - sessionSettings . active_tracker_limit = limit ; <nl> - sessionSettings . active_dht_limit = limit ; <nl> - sessionSettings . active_lsd_limit = limit ; <nl> + down_limit = pref - > getGlobalDownloadLimit ( ) ; <nl> + if ( down_limit < = 0 ) { <nl> + / / Download limit disabled <nl> + setDownloadRateLimit ( - 1 ) ; <nl> + } else { <nl> + / / Enabled <nl> + setDownloadRateLimit ( down_limit * 1024 ) ; <nl> } <nl> - else { <nl> - sessionSettings . active_limit = max_active ; <nl> - sessionSettings . active_tracker_limit = max_active ; <nl> - sessionSettings . active_dht_limit = max_active ; <nl> - sessionSettings . active_lsd_limit = max_active ; <nl> - } <nl> - sessionSettings . active_seeds = pref - > getMaxActiveUploads ( ) ; <nl> - sessionSettings . dont_count_slow_torrents = pref - > ignoreSlowTorrentsForQueueing ( ) ; <nl> - setQueueingEnabled ( true ) ; <nl> - } else { <nl> - sessionSettings . active_downloads = - 1 ; <nl> - sessionSettings . active_seeds = - 1 ; <nl> - sessionSettings . active_limit = - 1 ; <nl> - sessionSettings . active_tracker_limit = - 1 ; <nl> - sessionSettings . active_dht_limit = - 1 ; <nl> - sessionSettings . active_lsd_limit = - 1 ; <nl> - setQueueingEnabled ( false ) ; <nl> - } <nl> - / / Outgoing ports <nl> - sessionSettings . outgoing_ports = std : : make_pair ( pref - > outgoingPortsMin ( ) , pref - > outgoingPortsMax ( ) ) ; <nl> - / / Ignore limits on LAN <nl> - qDebug ( ) < < " Ignore limits on LAN " < < pref - > ignoreLimitsOnLAN ( ) ; <nl> - sessionSettings . ignore_limits_on_local_network = pref - > ignoreLimitsOnLAN ( ) ; <nl> - / / Include overhead in transfer limits <nl> - sessionSettings . rate_limit_ip_overhead = pref - > includeOverheadInLimits ( ) ; <nl> - / / IP address to announce to trackers <nl> - QString announce_ip = pref - > getNetworkAddress ( ) ; <nl> - if ( ! announce_ip . isEmpty ( ) ) <nl> - sessionSettings . announce_ip = announce_ip . toStdString ( ) ; <nl> - / / Super seeding <nl> - sessionSettings . strict_super_seeding = pref - > isSuperSeedingEnabled ( ) ; <nl> - / / * Max Half - open connections <nl> - sessionSettings . half_open_limit = pref - > getMaxHalfOpenConnections ( ) ; <nl> - / / * Max connections limit <nl> - sessionSettings . connections_limit = pref - > getMaxConnecs ( ) ; <nl> - / / * Global max upload slots <nl> - sessionSettings . unchoke_slots_limit = pref - > getMaxUploads ( ) ; <nl> - / / uTP <nl> - sessionSettings . enable_incoming_utp = pref - > isuTPEnabled ( ) ; <nl> - sessionSettings . enable_outgoing_utp = pref - > isuTPEnabled ( ) ; <nl> - / / uTP rate limiting <nl> - sessionSettings . rate_limit_utp = pref - > isuTPRateLimited ( ) ; <nl> - if ( sessionSettings . rate_limit_utp ) <nl> - sessionSettings . mixed_mode_algorithm = session_settings : : prefer_tcp ; <nl> - else <nl> - sessionSettings . mixed_mode_algorithm = session_settings : : peer_proportional ; <nl> - sessionSettings . connection_speed = 20 ; / / default is 10 <nl> + int up_limit ; <nl> + if ( alternative_speeds ) <nl> + up_limit = pref - > getAltGlobalUploadLimit ( ) ; <nl> + else <nl> + up_limit = pref - > getGlobalUploadLimit ( ) ; <nl> + / / * Global Upload limit <nl> + if ( up_limit < = 0 ) { <nl> + / / Upload limit disabled <nl> + setUploadRateLimit ( - 1 ) ; <nl> + } else { <nl> + / / Enabled <nl> + setUploadRateLimit ( up_limit * 1024 ) ; <nl> + } <nl> + if ( pref - > isSchedulerEnabled ( ) ) { <nl> + if ( ! bd_scheduler ) { <nl> + bd_scheduler = new BandwidthScheduler ( this ) ; <nl> + connect ( bd_scheduler , SIGNAL ( switchToAlternativeMode ( bool ) ) , this , SLOT ( useAlternativeSpeedsLimit ( bool ) ) ) ; <nl> + } <nl> + bd_scheduler - > start ( ) ; <nl> + } else { <nl> + delete bd_scheduler ; <nl> + } <nl> + # ifndef DISABLE_GUI <nl> + / / Resolve countries <nl> + qDebug ( " Loading country resolution settings " ) ; <nl> + const bool new_resolv_countries = pref - > resolvePeerCountries ( ) ; <nl> + if ( resolve_countries ! = new_resolv_countries ) { <nl> + qDebug ( " in country resolution settings " ) ; <nl> + resolve_countries = new_resolv_countries ; <nl> + if ( resolve_countries & & ! geoipDBLoaded ) { <nl> + qDebug ( " Loading geoip database " ) ; <nl> + GeoIPManager : : loadDatabase ( s ) ; <nl> + geoipDBLoaded = true ; <nl> + } <nl> + / / Update torrent handles <nl> + std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> + <nl> + std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> + std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> + for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> + QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> + if ( h . is_valid ( ) ) <nl> + h . resolve_countries ( resolve_countries ) ; <nl> + } <nl> + } <nl> + # endif <nl> + / / * UPnP / NAT - PMP <nl> + Logger * const logger = Logger : : instance ( ) ; <nl> + if ( pref - > isUPnPEnabled ( ) ) { <nl> + enableUPnP ( true ) ; <nl> + logger - > addMessage ( tr ( " UPnP / NAT - PMP support [ ON ] " ) , Log : : INFO ) ; <nl> + } else { <nl> + enableUPnP ( false ) ; <nl> + logger - > addMessage ( tr ( " UPnP / NAT - PMP support [ OFF ] " ) , Log : : INFO ) ; <nl> + } <nl> + / / * Session settings <nl> + session_settings sessionSettings = s - > settings ( ) ; <nl> + sessionSettings . user_agent = " qBittorrent " VERSION ; <nl> + / / std : : cout < < " HTTP user agent is " < < sessionSettings . user_agent < < std : : endl ; <nl> + logger - > addMessage ( tr ( " HTTP user agent is % 1 " ) . arg ( misc : : toQString ( sessionSettings . user_agent ) ) ) ; <nl> + <nl> + sessionSettings . upnp_ignore_nonrouters = true ; <nl> + sessionSettings . use_dht_as_fallback = false ; <nl> + / / Disable support for SSL torrents for now <nl> + sessionSettings . ssl_listen = 0 ; <nl> + / / To prevent ISPs from blocking seeding <nl> + sessionSettings . lazy_bitfields = true ; <nl> + / / Speed up exit <nl> + sessionSettings . stop_tracker_timeout = 1 ; <nl> + / / sessionSettings . announce_to_all_trackers = true ; <nl> + sessionSettings . auto_scrape_interval = 1200 ; / / 20 minutes <nl> + bool announce_to_all = pref - > announceToAllTrackers ( ) ; <nl> + sessionSettings . announce_to_all_trackers = announce_to_all ; <nl> + sessionSettings . announce_to_all_tiers = announce_to_all ; <nl> + sessionSettings . auto_scrape_min_interval = 900 ; / / 15 minutes <nl> + int cache_size = pref - > diskCacheSize ( ) ; <nl> + sessionSettings . cache_size = cache_size ? cache_size * 64 : - 1 ; <nl> + sessionSettings . cache_expiry = pref - > diskCacheTTL ( ) ; <nl> + qDebug ( ) < < " Using a disk cache size of " < < cache_size < < " MiB " ; <nl> + session_settings : : io_buffer_mode_t mode = pref - > osCache ( ) ? session_settings : : enable_os_cache : session_settings : : disable_os_cache ; <nl> + sessionSettings . disk_io_read_mode = mode ; <nl> + sessionSettings . disk_io_write_mode = mode ; <nl> + resumeDataTimer . setInterval ( pref - > saveResumeDataInterval ( ) * 60 * 1000 ) ; <nl> + sessionSettings . anonymous_mode = pref - > isAnonymousModeEnabled ( ) ; <nl> + if ( sessionSettings . anonymous_mode ) { <nl> + logger - > addMessage ( tr ( " Anonymous mode [ ON ] " ) , Log : : INFO ) ; <nl> + } else { <nl> + logger - > addMessage ( tr ( " Anonymous mode [ OFF ] " ) , Log : : INFO ) ; <nl> + } <nl> + / / Queueing System <nl> + if ( pref - > isQueueingSystemEnabled ( ) ) { <nl> + int max_downloading = pref - > getMaxActiveDownloads ( ) ; <nl> + int max_active = pref - > getMaxActiveTorrents ( ) ; <nl> + if ( max_downloading > - 1 ) <nl> + sessionSettings . active_downloads = max_downloading + HiddenData : : getDownloadingSize ( ) ; <nl> + else <nl> + sessionSettings . active_downloads = max_downloading ; <nl> + if ( max_active > - 1 ) { <nl> + int limit = max_active + HiddenData : : getDownloadingSize ( ) ; <nl> + sessionSettings . active_limit = limit ; <nl> + sessionSettings . active_tracker_limit = limit ; <nl> + sessionSettings . active_dht_limit = limit ; <nl> + sessionSettings . active_lsd_limit = limit ; <nl> + } <nl> + else { <nl> + sessionSettings . active_limit = max_active ; <nl> + sessionSettings . active_tracker_limit = max_active ; <nl> + sessionSettings . active_dht_limit = max_active ; <nl> + sessionSettings . active_lsd_limit = max_active ; <nl> + } <nl> + sessionSettings . active_seeds = pref - > getMaxActiveUploads ( ) ; <nl> + sessionSettings . dont_count_slow_torrents = pref - > ignoreSlowTorrentsForQueueing ( ) ; <nl> + setQueueingEnabled ( true ) ; <nl> + } else { <nl> + sessionSettings . active_downloads = - 1 ; <nl> + sessionSettings . active_seeds = - 1 ; <nl> + sessionSettings . active_limit = - 1 ; <nl> + sessionSettings . active_tracker_limit = - 1 ; <nl> + sessionSettings . active_dht_limit = - 1 ; <nl> + sessionSettings . active_lsd_limit = - 1 ; <nl> + setQueueingEnabled ( false ) ; <nl> + } <nl> + / / Outgoing ports <nl> + sessionSettings . outgoing_ports = std : : make_pair ( pref - > outgoingPortsMin ( ) , pref - > outgoingPortsMax ( ) ) ; <nl> + / / Ignore limits on LAN <nl> + qDebug ( ) < < " Ignore limits on LAN " < < pref - > ignoreLimitsOnLAN ( ) ; <nl> + sessionSettings . ignore_limits_on_local_network = pref - > ignoreLimitsOnLAN ( ) ; <nl> + / / Include overhead in transfer limits <nl> + sessionSettings . rate_limit_ip_overhead = pref - > includeOverheadInLimits ( ) ; <nl> + / / IP address to announce to trackers <nl> + QString announce_ip = pref - > getNetworkAddress ( ) ; <nl> + if ( ! announce_ip . isEmpty ( ) ) <nl> + sessionSettings . announce_ip = announce_ip . toStdString ( ) ; <nl> + / / Super seeding <nl> + sessionSettings . strict_super_seeding = pref - > isSuperSeedingEnabled ( ) ; <nl> + / / * Max Half - open connections <nl> + sessionSettings . half_open_limit = pref - > getMaxHalfOpenConnections ( ) ; <nl> + / / * Max connections limit <nl> + sessionSettings . connections_limit = pref - > getMaxConnecs ( ) ; <nl> + / / * Global max upload slots <nl> + sessionSettings . unchoke_slots_limit = pref - > getMaxUploads ( ) ; <nl> + / / uTP <nl> + sessionSettings . enable_incoming_utp = pref - > isuTPEnabled ( ) ; <nl> + sessionSettings . enable_outgoing_utp = pref - > isuTPEnabled ( ) ; <nl> + / / uTP rate limiting <nl> + sessionSettings . rate_limit_utp = pref - > isuTPRateLimited ( ) ; <nl> + if ( sessionSettings . rate_limit_utp ) <nl> + sessionSettings . mixed_mode_algorithm = session_settings : : prefer_tcp ; <nl> + else <nl> + sessionSettings . mixed_mode_algorithm = session_settings : : peer_proportional ; <nl> + sessionSettings . connection_speed = 20 ; / / default is 10 <nl> # if LIBTORRENT_VERSION_NUM > = 10000 <nl> - if ( pref - > isProxyEnabled ( ) ) <nl> - sessionSettings . force_proxy = pref - > getForceProxy ( ) ; <nl> - else <nl> - sessionSettings . force_proxy = false ; <nl> + if ( pref - > isProxyEnabled ( ) ) <nl> + sessionSettings . force_proxy = pref - > getForceProxy ( ) ; <nl> + else <nl> + sessionSettings . force_proxy = false ; <nl> # endif <nl> - sessionSettings . no_connect_privileged_ports = false ; <nl> - sessionSettings . seed_choking_algorithm = session_settings : : fastest_upload ; <nl> - qDebug ( ) < < " Settings SessionSettings " ; <nl> - setSessionSettings ( sessionSettings ) ; <nl> - / / Bittorrent <nl> - / / * Max connections per torrent limit <nl> - setMaxConnectionsPerTorrent ( pref - > getMaxConnecsPerTorrent ( ) ) ; <nl> - / / * Max uploads per torrent limit <nl> - setMaxUploadsPerTorrent ( pref - > getMaxUploadsPerTorrent ( ) ) ; <nl> - / / * DHT <nl> - enableDHT ( pref - > isDHTEnabled ( ) ) ; <nl> - / / * PeX <nl> - if ( PeXEnabled ) { <nl> - logger - > addMessage ( tr ( " PeX support [ ON ] " ) , Log : : INFO ) ; <nl> - } else { <nl> - logger - > addMessage ( tr ( " PeX support [ OFF ] " ) , Log : : CRITICAL ) ; <nl> - } <nl> - if ( PeXEnabled ! = pref - > isPeXEnabled ( ) ) { <nl> - logger - > addMessage ( tr ( " Restart is required to toggle PeX support " ) , Log : : CRITICAL ) ; <nl> - } <nl> - / / * LSD <nl> - if ( pref - > isLSDEnabled ( ) ) { <nl> - enableLSD ( true ) ; <nl> - logger - > addMessage ( tr ( " Local Peer Discovery support [ ON ] " ) , Log : : INFO ) ; <nl> - } else { <nl> - enableLSD ( false ) ; <nl> - logger - > addMessage ( tr ( " Local Peer Discovery support [ OFF ] " ) , Log : : INFO ) ; <nl> - } <nl> - / / * Encryption <nl> - const int encryptionState = pref - > getEncryptionSetting ( ) ; <nl> - / / The most secure , rc4 only so that all streams and encrypted <nl> - pe_settings encryptionSettings ; <nl> - encryptionSettings . allowed_enc_level = pe_settings : : rc4 ; <nl> - encryptionSettings . prefer_rc4 = true ; <nl> - switch ( encryptionState ) { <nl> - case 0 : / / Enabled <nl> - encryptionSettings . out_enc_policy = pe_settings : : enabled ; <nl> - encryptionSettings . in_enc_policy = pe_settings : : enabled ; <nl> - logger - > addMessage ( tr ( " Encryption support [ ON ] " ) , Log : : INFO ) ; <nl> - break ; <nl> - case 1 : / / Forced <nl> - encryptionSettings . out_enc_policy = pe_settings : : forced ; <nl> - encryptionSettings . in_enc_policy = pe_settings : : forced ; <nl> - logger - > addMessage ( tr ( " Encryption support [ FORCED ] " ) , Log : : INFO ) ; <nl> - break ; <nl> - default : / / Disabled <nl> - encryptionSettings . out_enc_policy = pe_settings : : disabled ; <nl> - encryptionSettings . in_enc_policy = pe_settings : : disabled ; <nl> - logger - > addMessage ( tr ( " Encryption support [ OFF ] " ) , Log : : INFO ) ; <nl> - } <nl> - applyEncryptionSettings ( encryptionSettings ) ; <nl> - / / * Maximum ratio <nl> - high_ratio_action = pref - > getMaxRatioAction ( ) ; <nl> - setGlobalMaxRatio ( pref - > getGlobalMaxRatio ( ) ) ; <nl> - updateRatioTimer ( ) ; <nl> - / / Ip Filter <nl> - FilterParserThread : : processFilterList ( s , pref - > bannedIPs ( ) ) ; <nl> - if ( pref - > isFilteringEnabled ( ) ) { <nl> - enableIPFilter ( pref - > getFilter ( ) ) ; <nl> - } else { <nl> - disableIPFilter ( ) ; <nl> - } <nl> - / / * Proxy settings <nl> - proxy_settings proxySettings ; <nl> - if ( pref - > isProxyEnabled ( ) ) { <nl> - qDebug ( " Enabling P2P proxy " ) ; <nl> - proxySettings . hostname = pref - > getProxyIp ( ) . toStdString ( ) ; <nl> - qDebug ( " hostname is % s " , proxySettings . hostname . c_str ( ) ) ; <nl> - proxySettings . port = pref - > getProxyPort ( ) ; <nl> - qDebug ( " port is % d " , proxySettings . port ) ; <nl> - if ( pref - > isProxyAuthEnabled ( ) ) { <nl> - proxySettings . username = pref - > getProxyUsername ( ) . toStdString ( ) ; <nl> - proxySettings . password = pref - > getProxyPassword ( ) . toStdString ( ) ; <nl> - qDebug ( " username is % s " , proxySettings . username . c_str ( ) ) ; <nl> - qDebug ( " password is % s " , proxySettings . password . c_str ( ) ) ; <nl> - } <nl> - } <nl> - switch ( pref - > getProxyType ( ) ) { <nl> - case Proxy : : HTTP : <nl> - qDebug ( " type : http " ) ; <nl> - proxySettings . type = proxy_settings : : http ; <nl> - break ; <nl> - case Proxy : : HTTP_PW : <nl> - qDebug ( " type : http_pw " ) ; <nl> - proxySettings . type = proxy_settings : : http_pw ; <nl> - break ; <nl> - case Proxy : : SOCKS4 : <nl> - proxySettings . type = proxy_settings : : socks4 ; <nl> - break ; <nl> - case Proxy : : SOCKS5 : <nl> - qDebug ( " type : socks5 " ) ; <nl> - proxySettings . type = proxy_settings : : socks5 ; <nl> - break ; <nl> - case Proxy : : SOCKS5_PW : <nl> - qDebug ( " type : socks5_pw " ) ; <nl> - proxySettings . type = proxy_settings : : socks5_pw ; <nl> - break ; <nl> - default : <nl> - proxySettings . type = proxy_settings : : none ; <nl> - } <nl> - setProxySettings ( proxySettings ) ; <nl> - / / Tracker <nl> - if ( pref - > isTrackerEnabled ( ) ) { <nl> - if ( ! m_tracker ) { <nl> - m_tracker = new QTracker ( this ) ; <nl> - } <nl> - if ( m_tracker - > start ( ) ) { <nl> - logger - > addMessage ( tr ( " Embedded Tracker [ ON ] " ) , Log : : INFO ) ; <nl> + sessionSettings . no_connect_privileged_ports = false ; <nl> + sessionSettings . seed_choking_algorithm = session_settings : : fastest_upload ; <nl> + qDebug ( ) < < " Settings SessionSettings " ; <nl> + setSessionSettings ( sessionSettings ) ; <nl> + / / Bittorrent <nl> + / / * Max connections per torrent limit <nl> + setMaxConnectionsPerTorrent ( pref - > getMaxConnecsPerTorrent ( ) ) ; <nl> + / / * Max uploads per torrent limit <nl> + setMaxUploadsPerTorrent ( pref - > getMaxUploadsPerTorrent ( ) ) ; <nl> + / / * DHT <nl> + enableDHT ( pref - > isDHTEnabled ( ) ) ; <nl> + / / * PeX <nl> + if ( PeXEnabled ) { <nl> + logger - > addMessage ( tr ( " PeX support [ ON ] " ) , Log : : INFO ) ; <nl> } else { <nl> - logger - > addMessage ( tr ( " Failed to start the embedded tracker ! " ) , Log : : CRITICAL ) ; <nl> + logger - > addMessage ( tr ( " PeX support [ OFF ] " ) , Log : : CRITICAL ) ; <nl> } <nl> - } else { <nl> - logger - > addMessage ( tr ( " Embedded Tracker [ OFF ] " ) ) ; <nl> - if ( m_tracker ) <nl> - delete m_tracker ; <nl> - } <nl> - / / * Scan dirs <nl> - const QStringList scan_dirs = pref - > getScanDirs ( ) ; <nl> - QList < bool > downloadInDirList = pref - > getDownloadInScanDirs ( ) ; <nl> - while ( scan_dirs . size ( ) > downloadInDirList . size ( ) ) { <nl> - downloadInDirList < < false ; <nl> - } <nl> - int i = 0 ; <nl> - foreach ( const QString & dir , scan_dirs ) { <nl> - qDebug ( ) < < " Adding scan dir " < < dir < < downloadInDirList . at ( i ) ; <nl> - m_scanFolders - > addPath ( dir , downloadInDirList . at ( i ) ) ; <nl> - + + i ; <nl> - } <nl> - qDebug ( " Session configured " ) ; <nl> + if ( PeXEnabled ! = pref - > isPeXEnabled ( ) ) { <nl> + logger - > addMessage ( tr ( " Restart is required to toggle PeX support " ) , Log : : CRITICAL ) ; <nl> + } <nl> + / / * LSD <nl> + if ( pref - > isLSDEnabled ( ) ) { <nl> + enableLSD ( true ) ; <nl> + logger - > addMessage ( tr ( " Local Peer Discovery support [ ON ] " ) , Log : : INFO ) ; <nl> + } else { <nl> + enableLSD ( false ) ; <nl> + logger - > addMessage ( tr ( " Local Peer Discovery support [ OFF ] " ) , Log : : INFO ) ; <nl> + } <nl> + / / * Encryption <nl> + const int encryptionState = pref - > getEncryptionSetting ( ) ; <nl> + / / The most secure , rc4 only so that all streams and encrypted <nl> + pe_settings encryptionSettings ; <nl> + encryptionSettings . allowed_enc_level = pe_settings : : rc4 ; <nl> + encryptionSettings . prefer_rc4 = true ; <nl> + switch ( encryptionState ) { <nl> + case 0 : / / Enabled <nl> + encryptionSettings . out_enc_policy = pe_settings : : enabled ; <nl> + encryptionSettings . in_enc_policy = pe_settings : : enabled ; <nl> + logger - > addMessage ( tr ( " Encryption support [ ON ] " ) , Log : : INFO ) ; <nl> + break ; <nl> + case 1 : / / Forced <nl> + encryptionSettings . out_enc_policy = pe_settings : : forced ; <nl> + encryptionSettings . in_enc_policy = pe_settings : : forced ; <nl> + logger - > addMessage ( tr ( " Encryption support [ FORCED ] " ) , Log : : INFO ) ; <nl> + break ; <nl> + default : / / Disabled <nl> + encryptionSettings . out_enc_policy = pe_settings : : disabled ; <nl> + encryptionSettings . in_enc_policy = pe_settings : : disabled ; <nl> + logger - > addMessage ( tr ( " Encryption support [ OFF ] " ) , Log : : INFO ) ; <nl> + } <nl> + applyEncryptionSettings ( encryptionSettings ) ; <nl> + / / * Maximum ratio <nl> + high_ratio_action = pref - > getMaxRatioAction ( ) ; <nl> + setGlobalMaxRatio ( pref - > getGlobalMaxRatio ( ) ) ; <nl> + updateRatioTimer ( ) ; <nl> + / / Ip Filter <nl> + FilterParserThread : : processFilterList ( s , pref - > bannedIPs ( ) ) ; <nl> + if ( pref - > isFilteringEnabled ( ) ) { <nl> + enableIPFilter ( pref - > getFilter ( ) ) ; <nl> + } else { <nl> + disableIPFilter ( ) ; <nl> + } <nl> + / / * Proxy settings <nl> + proxy_settings proxySettings ; <nl> + if ( pref - > isProxyEnabled ( ) ) { <nl> + qDebug ( " Enabling P2P proxy " ) ; <nl> + proxySettings . hostname = pref - > getProxyIp ( ) . toStdString ( ) ; <nl> + qDebug ( " hostname is % s " , proxySettings . hostname . c_str ( ) ) ; <nl> + proxySettings . port = pref - > getProxyPort ( ) ; <nl> + qDebug ( " port is % d " , proxySettings . port ) ; <nl> + if ( pref - > isProxyAuthEnabled ( ) ) { <nl> + proxySettings . username = pref - > getProxyUsername ( ) . toStdString ( ) ; <nl> + proxySettings . password = pref - > getProxyPassword ( ) . toStdString ( ) ; <nl> + qDebug ( " username is % s " , proxySettings . username . c_str ( ) ) ; <nl> + qDebug ( " password is % s " , proxySettings . password . c_str ( ) ) ; <nl> + } <nl> + } <nl> + switch ( pref - > getProxyType ( ) ) { <nl> + case Proxy : : HTTP : <nl> + qDebug ( " type : http " ) ; <nl> + proxySettings . type = proxy_settings : : http ; <nl> + break ; <nl> + case Proxy : : HTTP_PW : <nl> + qDebug ( " type : http_pw " ) ; <nl> + proxySettings . type = proxy_settings : : http_pw ; <nl> + break ; <nl> + case Proxy : : SOCKS4 : <nl> + proxySettings . type = proxy_settings : : socks4 ; <nl> + break ; <nl> + case Proxy : : SOCKS5 : <nl> + qDebug ( " type : socks5 " ) ; <nl> + proxySettings . type = proxy_settings : : socks5 ; <nl> + break ; <nl> + case Proxy : : SOCKS5_PW : <nl> + qDebug ( " type : socks5_pw " ) ; <nl> + proxySettings . type = proxy_settings : : socks5_pw ; <nl> + break ; <nl> + default : <nl> + proxySettings . type = proxy_settings : : none ; <nl> + } <nl> + setProxySettings ( proxySettings ) ; <nl> + / / Tracker <nl> + if ( pref - > isTrackerEnabled ( ) ) { <nl> + if ( ! m_tracker ) { <nl> + m_tracker = new QTracker ( this ) ; <nl> + } <nl> + if ( m_tracker - > start ( ) ) { <nl> + logger - > addMessage ( tr ( " Embedded Tracker [ ON ] " ) , Log : : INFO ) ; <nl> + } else { <nl> + logger - > addMessage ( tr ( " Failed to start the embedded tracker ! " ) , Log : : CRITICAL ) ; <nl> + } <nl> + } else { <nl> + logger - > addMessage ( tr ( " Embedded Tracker [ OFF ] " ) ) ; <nl> + if ( m_tracker ) <nl> + delete m_tracker ; <nl> + } <nl> + / / * Scan dirs <nl> + const QStringList scan_dirs = pref - > getScanDirs ( ) ; <nl> + QList < bool > downloadInDirList = pref - > getDownloadInScanDirs ( ) ; <nl> + while ( scan_dirs . size ( ) > downloadInDirList . size ( ) ) { <nl> + downloadInDirList < < false ; <nl> + } <nl> + int i = 0 ; <nl> + foreach ( const QString & dir , scan_dirs ) { <nl> + qDebug ( ) < < " Adding scan dir " < < dir < < downloadInDirList . at ( i ) ; <nl> + m_scanFolders - > addPath ( dir , downloadInDirList . at ( i ) ) ; <nl> + + + i ; <nl> + } <nl> + qDebug ( " Session configured " ) ; <nl> } <nl> <nl> void QBtSession : : useAlternativeSpeedsLimit ( bool alternative ) { <nl> - qDebug ( ) < < Q_FUNC_INFO < < alternative ; <nl> - / / Save new state to remember it on startup <nl> - Preferences * const pref = Preferences : : instance ( ) ; <nl> - / / Stop the scheduler when the user has manually changed the bandwidth mode <nl> - if ( ! pref - > isSchedulerEnabled ( ) ) <nl> - delete bd_scheduler ; <nl> - pref - > setAltBandwidthEnabled ( alternative ) ; <nl> - / / Apply settings to the bittorrent session <nl> - int down_limit = alternative ? pref - > getAltGlobalDownloadLimit ( ) : pref - > getGlobalDownloadLimit ( ) ; <nl> - if ( down_limit < = 0 ) { <nl> - down_limit = - 1 ; <nl> - } else { <nl> - down_limit * = 1024 ; <nl> - } <nl> - setDownloadRateLimit ( down_limit ) ; <nl> - / / Upload rate <nl> - int up_limit = alternative ? pref - > getAltGlobalUploadLimit ( ) : pref - > getGlobalUploadLimit ( ) ; <nl> - if ( up_limit < = 0 ) { <nl> - up_limit = - 1 ; <nl> - } else { <nl> - up_limit * = 1024 ; <nl> - } <nl> - setUploadRateLimit ( up_limit ) ; <nl> - / / Notify <nl> - emit alternativeSpeedsModeChanged ( alternative ) ; <nl> + qDebug ( ) < < Q_FUNC_INFO < < alternative ; <nl> + / / Save new state to remember it on startup <nl> + Preferences * const pref = Preferences : : instance ( ) ; <nl> + / / Stop the scheduler when the user has manually changed the bandwidth mode <nl> + if ( ! pref - > isSchedulerEnabled ( ) ) <nl> + delete bd_scheduler ; <nl> + pref - > setAltBandwidthEnabled ( alternative ) ; <nl> + / / Apply settings to the bittorrent session <nl> + int down_limit = alternative ? pref - > getAltGlobalDownloadLimit ( ) : pref - > getGlobalDownloadLimit ( ) ; <nl> + if ( down_limit < = 0 ) { <nl> + down_limit = - 1 ; <nl> + } else { <nl> + down_limit * = 1024 ; <nl> + } <nl> + setDownloadRateLimit ( down_limit ) ; <nl> + / / Upload rate <nl> + int up_limit = alternative ? pref - > getAltGlobalUploadLimit ( ) : pref - > getGlobalUploadLimit ( ) ; <nl> + if ( up_limit < = 0 ) { <nl> + up_limit = - 1 ; <nl> + } else { <nl> + up_limit * = 1024 ; <nl> + } <nl> + setUploadRateLimit ( up_limit ) ; <nl> + / / Notify <nl> + emit alternativeSpeedsModeChanged ( alternative ) ; <nl> } <nl> <nl> / / Return the torrent handle , given its hash <nl> QTorrentHandle QBtSession : : getTorrentHandle ( const QString & hash ) const { <nl> - return QTorrentHandle ( s - > find_torrent ( QStringToSha1 ( hash ) ) ) ; <nl> + return QTorrentHandle ( s - > find_torrent ( QStringToSha1 ( hash ) ) ) ; <nl> } <nl> <nl> bool QBtSession : : hasActiveTorrents ( ) const { <nl> - std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> + std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> <nl> - std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> - std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> - for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> - const QTorrentHandle h ( * torrentIT ) ; <nl> - if ( h . is_valid ( ) & & ! h . is_paused ( ) & & ! h . is_queued ( ) ) <nl> - return true ; <nl> - } <nl> - return false ; <nl> + std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> + std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> + for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> + const QTorrentHandle h ( * torrentIT ) ; <nl> + if ( h . is_valid ( ) & & ! h . is_paused ( ) & & ! h . is_queued ( ) ) <nl> + return true ; <nl> + } <nl> + return false ; <nl> } <nl> <nl> bool QBtSession : : hasDownloadingTorrents ( ) const { <nl> - std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> + std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> <nl> - std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> - std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> - for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> - if ( torrentIT - > is_valid ( ) ) { <nl> - try { <nl> - const torrent_status status = torrentIT - > status ( ) ; <nl> - if ( status . state ! = torrent_status : : finished & & status . state ! = torrent_status : : seeding <nl> - & & ! ( status . paused & & ! status . auto_managed ) ) <nl> - return true ; <nl> - } catch ( std : : exception ) { } <nl> + std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> + std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> + for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> + if ( torrentIT - > is_valid ( ) ) { <nl> + try { <nl> + const torrent_status status = torrentIT - > status ( ) ; <nl> + if ( status . state ! = torrent_status : : finished & & status . state ! = torrent_status : : seeding <nl> + & & ! ( status . paused & & ! status . auto_managed ) ) <nl> + return true ; <nl> + } catch ( std : : exception ) { } <nl> + } <nl> } <nl> - } <nl> - return false ; <nl> + return false ; <nl> } <nl> <nl> void QBtSession : : banIP ( QString ip ) { <nl> - FilterParserThread : : processFilterList ( s , QStringList ( ip ) ) ; <nl> - Preferences : : instance ( ) - > banIP ( ip ) ; <nl> + FilterParserThread : : processFilterList ( s , QStringList ( ip ) ) ; <nl> + Preferences : : instance ( ) - > banIP ( ip ) ; <nl> } <nl> <nl> / / Delete a torrent from the session , given its hash <nl> / / permanent = true means that the torrent will be removed from the hard - drive too <nl> void QBtSession : : deleteTorrent ( const QString & hash , bool delete_local_files ) { <nl> - qDebug ( " Deleting torrent with hash : % s " , qPrintable ( hash ) ) ; <nl> - const QTorrentHandle h = getTorrentHandle ( hash ) ; <nl> - if ( ! h . is_valid ( ) ) { <nl> - qDebug ( " / ! \ \ Error : Invalid handle " ) ; <nl> - return ; <nl> - } <nl> - emit torrentAboutToBeRemoved ( h ) ; <nl> - qDebug ( " h is valid , getting name or hash . . . " ) ; <nl> - QString fileName ; <nl> - if ( h . has_metadata ( ) ) <nl> - fileName = h . name ( ) ; <nl> - else <nl> - fileName = h . hash ( ) ; <nl> - / / Remove it from session <nl> - if ( delete_local_files ) { <nl> - if ( h . has_metadata ( ) ) { <nl> - QDir save_dir ( h . save_path ( ) ) ; <nl> - if ( save_dir ! = QDir ( defaultSavePath ) & & ( defaultTempPath . isEmpty ( ) | | save_dir ! = QDir ( defaultTempPath ) ) ) { <nl> - savePathsToRemove [ hash ] = save_dir . absolutePath ( ) ; <nl> - qDebug ( ) < < " Save path to remove ( async ) : " < < save_dir . absolutePath ( ) ; <nl> - } <nl> + qDebug ( " Deleting torrent with hash : % s " , qPrintable ( hash ) ) ; <nl> + const QTorrentHandle h = getTorrentHandle ( hash ) ; <nl> + if ( ! h . is_valid ( ) ) { <nl> + qDebug ( " / ! \ \ Error : Invalid handle " ) ; <nl> + return ; <nl> } <nl> - s - > remove_torrent ( h , session : : delete_files ) ; <nl> - } else { <nl> - QStringList uneeded_files ; <nl> + emit torrentAboutToBeRemoved ( h ) ; <nl> + qDebug ( " h is valid , getting name or hash . . . " ) ; <nl> + QString fileName ; <nl> if ( h . has_metadata ( ) ) <nl> - uneeded_files = h . absolute_files_path_uneeded ( ) ; <nl> - s - > remove_torrent ( h ) ; <nl> - / / Remove unneeded and incomplete files <nl> - foreach ( const QString & uneeded_file , uneeded_files ) { <nl> - qDebug ( " Removing uneeded file : % s " , qPrintable ( uneeded_file ) ) ; <nl> - fsutils : : forceRemove ( uneeded_file ) ; <nl> - const QString parent_folder = fsutils : : branchPath ( uneeded_file ) ; <nl> - qDebug ( " Attempt to remove parent folder ( if empty ) : % s " , qPrintable ( parent_folder ) ) ; <nl> - QDir ( ) . rmpath ( parent_folder ) ; <nl> - } <nl> - } <nl> - / / Remove it from torrent backup directory <nl> - QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ; <nl> - QStringList filters ; <nl> - filters < < hash + " . * " ; <nl> - const QStringList files = torrentBackup . entryList ( filters , QDir : : Files , QDir : : Unsorted ) ; <nl> - foreach ( const QString & file , files ) { <nl> - fsutils : : forceRemove ( torrentBackup . absoluteFilePath ( file ) ) ; <nl> - } <nl> - TorrentPersistentData : : instance ( ) - > deletePersistentData ( hash ) ; <nl> - TorrentTempData : : deleteTempData ( hash ) ; <nl> - HiddenData : : deleteData ( hash ) ; <nl> - / / Remove tracker errors <nl> - trackersInfos . remove ( hash ) ; <nl> - if ( delete_local_files ) <nl> - Logger : : instance ( ) - > addMessage ( tr ( " ' % 1 ' was removed from transfer list and hard disk . " , " ' xxx . avi ' was removed . . . " ) . arg ( fileName ) ) ; <nl> - else <nl> - Logger : : instance ( ) - > addMessage ( tr ( " ' % 1 ' was removed from transfer list . " , " ' xxx . avi ' was removed . . . " ) . arg ( fileName ) ) ; <nl> - qDebug ( " Torrent deleted . " ) ; <nl> + fileName = h . name ( ) ; <nl> + else <nl> + fileName = h . hash ( ) ; <nl> + / / Remove it from session <nl> + if ( delete_local_files ) { <nl> + if ( h . has_metadata ( ) ) { <nl> + QDir save_dir ( h . save_path ( ) ) ; <nl> + if ( save_dir ! = QDir ( defaultSavePath ) & & ( defaultTempPath . isEmpty ( ) | | save_dir ! = QDir ( defaultTempPath ) ) ) { <nl> + savePathsToRemove [ hash ] = save_dir . absolutePath ( ) ; <nl> + qDebug ( ) < < " Save path to remove ( async ) : " < < save_dir . absolutePath ( ) ; <nl> + } <nl> + } <nl> + s - > remove_torrent ( h , session : : delete_files ) ; <nl> + } else { <nl> + QStringList uneeded_files ; <nl> + if ( h . has_metadata ( ) ) <nl> + uneeded_files = h . absolute_files_path_uneeded ( ) ; <nl> + s - > remove_torrent ( h ) ; <nl> + / / Remove unneeded and incomplete files <nl> + foreach ( const QString & uneeded_file , uneeded_files ) { <nl> + qDebug ( " Removing uneeded file : % s " , qPrintable ( uneeded_file ) ) ; <nl> + fsutils : : forceRemove ( uneeded_file ) ; <nl> + const QString parent_folder = fsutils : : branchPath ( uneeded_file ) ; <nl> + qDebug ( " Attempt to remove parent folder ( if empty ) : % s " , qPrintable ( parent_folder ) ) ; <nl> + QDir ( ) . rmpath ( parent_folder ) ; <nl> + } <nl> + } <nl> + / / Remove it from torrent backup directory <nl> + QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ; <nl> + QStringList filters ; <nl> + filters < < hash + " . * " ; <nl> + const QStringList files = torrentBackup . entryList ( filters , QDir : : Files , QDir : : Unsorted ) ; <nl> + foreach ( const QString & file , files ) { <nl> + fsutils : : forceRemove ( torrentBackup . absoluteFilePath ( file ) ) ; <nl> + } <nl> + TorrentPersistentData : : instance ( ) - > deletePersistentData ( hash ) ; <nl> + TorrentTempData : : deleteTempData ( hash ) ; <nl> + HiddenData : : deleteData ( hash ) ; <nl> + / / Remove tracker errors <nl> + trackersInfos . remove ( hash ) ; <nl> + if ( delete_local_files ) <nl> + Logger : : instance ( ) - > addMessage ( tr ( " ' % 1 ' was removed from transfer list and hard disk . " , " ' xxx . avi ' was removed . . . " ) . arg ( fileName ) ) ; <nl> + else <nl> + Logger : : instance ( ) - > addMessage ( tr ( " ' % 1 ' was removed from transfer list . " , " ' xxx . avi ' was removed . . . " ) . arg ( fileName ) ) ; <nl> + qDebug ( " Torrent deleted . " ) ; <nl> } <nl> <nl> void QBtSession : : pauseAllTorrents ( ) { <nl> - std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> + std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> <nl> - std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> - std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> - for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> - try { <nl> - QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> - if ( ! h . is_paused ( ) ) { <nl> - h . pause ( ) ; <nl> - emit pausedTorrent ( h ) ; <nl> - } <nl> - } catch ( invalid_handle & ) { } <nl> - } <nl> + std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> + std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> + for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> + try { <nl> + QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> + if ( ! h . is_paused ( ) ) { <nl> + h . pause ( ) ; <nl> + emit pausedTorrent ( h ) ; <nl> + } <nl> + } catch ( invalid_handle & ) { } <nl> + } <nl> } <nl> <nl> std : : vector < torrent_handle > QBtSession : : getTorrents ( ) const { <nl> - return s - > get_torrents ( ) ; <nl> + return s - > get_torrents ( ) ; <nl> } <nl> <nl> void QBtSession : : resumeAllTorrents ( ) { <nl> - std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> + std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> <nl> - std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> - std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> - for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> - try { <nl> - QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> - if ( h . is_paused ( ) ) { <nl> - h . resume ( ) ; <nl> - emit resumedTorrent ( h ) ; <nl> - } <nl> - } catch ( invalid_handle & ) { } <nl> - } <nl> + std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> + std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> + for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> + try { <nl> + QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> + if ( h . is_paused ( ) ) { <nl> + h . resume ( ) ; <nl> + emit resumedTorrent ( h ) ; <nl> + } <nl> + } catch ( invalid_handle & ) { } <nl> + } <nl> } <nl> <nl> void QBtSession : : pauseTorrent ( const QString & hash ) { <nl> - QTorrentHandle h = getTorrentHandle ( hash ) ; <nl> - if ( ! h . is_paused ( ) ) { <nl> - h . pause ( ) ; <nl> - emit pausedTorrent ( h ) ; <nl> - } <nl> + QTorrentHandle h = getTorrentHandle ( hash ) ; <nl> + if ( ! h . is_paused ( ) ) { <nl> + h . pause ( ) ; <nl> + emit pausedTorrent ( h ) ; <nl> + } <nl> } <nl> <nl> void QBtSession : : resumeTorrent ( const QString & hash ) { <nl> - QTorrentHandle h = getTorrentHandle ( hash ) ; <nl> - if ( h . is_paused ( ) ) { <nl> - h . resume ( ) ; <nl> - emit resumedTorrent ( h ) ; <nl> - } <nl> + QTorrentHandle h = getTorrentHandle ( hash ) ; <nl> + if ( h . is_paused ( ) ) { <nl> + h . resume ( ) ; <nl> + emit resumedTorrent ( h ) ; <nl> + } <nl> } <nl> <nl> bool QBtSession : : loadFastResumeData ( const QString & hash , std : : vector < char > & buf ) { <nl> - const QString fastresume_path = QDir ( fsutils : : BTBackupLocation ( ) ) . absoluteFilePath ( hash + QString ( " . fastresume " ) ) ; <nl> - qDebug ( " Trying to load fastresume data : % s " , qPrintable ( fastresume_path ) ) ; <nl> - QFile fastresume_file ( fastresume_path ) ; <nl> - if ( fastresume_file . size ( ) < = 0 ) <nl> - return false ; <nl> - if ( ! fastresume_file . open ( QIODevice : : ReadOnly ) ) <nl> - return false ; <nl> - const QByteArray content = fastresume_file . readAll ( ) ; <nl> - const int content_size = content . size ( ) ; <nl> - Q_ASSERT ( content_size > 0 ) ; <nl> - buf . resize ( content_size ) ; <nl> - memcpy ( & buf [ 0 ] , content . data ( ) , content_size ) ; <nl> - fastresume_file . close ( ) ; <nl> - return true ; <nl> + const QString fastresume_path = QDir ( fsutils : : BTBackupLocation ( ) ) . absoluteFilePath ( hash + QString ( " . fastresume " ) ) ; <nl> + qDebug ( " Trying to load fastresume data : % s " , qPrintable ( fastresume_path ) ) ; <nl> + QFile fastresume_file ( fastresume_path ) ; <nl> + if ( fastresume_file . size ( ) < = 0 ) <nl> + return false ; <nl> + if ( ! fastresume_file . open ( QIODevice : : ReadOnly ) ) <nl> + return false ; <nl> + const QByteArray content = fastresume_file . readAll ( ) ; <nl> + const int content_size = content . size ( ) ; <nl> + Q_ASSERT ( content_size > 0 ) ; <nl> + buf . resize ( content_size ) ; <nl> + memcpy ( & buf [ 0 ] , content . data ( ) , content_size ) ; <nl> + fastresume_file . close ( ) ; <nl> + return true ; <nl> } <nl> <nl> void QBtSession : : loadTorrentSettings ( QTorrentHandle & h ) { <nl> - Preferences * const pref = Preferences : : instance ( ) ; <nl> - / / Connections limit per torrent <nl> - h . set_max_connections ( pref - > getMaxConnecsPerTorrent ( ) ) ; <nl> - / / Uploads limit per torrent <nl> - h . set_max_uploads ( pref - > getMaxUploadsPerTorrent ( ) ) ; <nl> + Preferences * const pref = Preferences : : instance ( ) ; <nl> + / / Connections limit per torrent <nl> + h . set_max_connections ( pref - > getMaxConnecsPerTorrent ( ) ) ; <nl> + / / Uploads limit per torrent <nl> + h . set_max_uploads ( pref - > getMaxUploadsPerTorrent ( ) ) ; <nl> # ifndef DISABLE_GUI <nl> - / / Resolve countries <nl> - h . resolve_countries ( resolve_countries ) ; <nl> + / / Resolve countries <nl> + h . resolve_countries ( resolve_countries ) ; <nl> # endif <nl> } <nl> <nl> QTorrentHandle QBtSession : : addMagnetUri ( QString magnet_uri , bool resumed , bool fromScanDir , const QString & filePath ) <nl> { <nl> - Q_UNUSED ( fromScanDir ) ; <nl> - Q_UNUSED ( filePath ) ; <nl> - Preferences * const pref = Preferences : : instance ( ) ; <nl> - Logger * const logger = Logger : : instance ( ) ; <nl> - QTorrentHandle h ; <nl> - add_torrent_params p ; <nl> - libtorrent : : error_code ec ; <nl> - <nl> - libtorrent : : parse_magnet_uri ( magnet_uri . toUtf8 ( ) . constData ( ) , p , ec ) ; <nl> - if ( ec ) { <nl> - logger - > addMessage ( tr ( " Couldn ' t parse this Magnet URI : ' % 1 ' " ) . arg ( magnet_uri ) ) ; <nl> - return h ; <nl> - } <nl> - const QString hash ( misc : : toQString ( p . info_hash ) ) ; <nl> - if ( hash . isEmpty ( ) ) { <nl> - logger - > addMessage ( tr ( " ' % 1 ' is not a valid magnet URI . " ) . arg ( magnet_uri ) ) ; <nl> - return h ; <nl> - } <nl> - const QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ; <nl> - if ( resumed ) { <nl> - / / Load metadata <nl> - const QString torrent_path = torrentBackup . absoluteFilePath ( hash + " . torrent " ) ; <nl> - if ( QFile : : exists ( torrent_path ) ) <nl> - return addTorrent ( torrent_path , false , QString : : null , true ) ; <nl> - } <nl> - qDebug ( " Adding a magnet URI : % s " , qPrintable ( hash ) ) ; <nl> - Q_ASSERT ( magnet_uri . startsWith ( " magnet : " , Qt : : CaseInsensitive ) ) ; <nl> - <nl> - / / limit h_ex scope <nl> - { <nl> - / / Check for duplicate torrent <nl> - QTorrentHandle h_ex = QTorrentHandle ( s - > find_torrent ( p . info_hash ) ) ; <nl> - if ( h_ex . is_valid ( ) ) { <nl> - qDebug ( " / ! \ \ Torrent is already in download list " ) ; <nl> - logger - > addMessage ( tr ( " ' % 1 ' is already in download list . " , " e . g : ' xxx . avi ' is already in download list . " ) . arg ( magnet_uri ) ) ; <nl> - / / Check if the torrent contains trackers or url seeds we don ' t know about <nl> - / / and add them <nl> - mergeTorrents ( h_ex , magnet_uri ) ; <nl> - return h ; <nl> - } <nl> - } <nl> - <nl> - initializeAddTorrentParams ( hash , p ) ; <nl> - <nl> - / / Get save path <nl> - QString savePath ; <nl> - if ( ! resumed & & savepathLabel_fromurl . contains ( magnet_uri ) ) { <nl> - QPair < QString , QString > savePath_label = savepathLabel_fromurl . take ( magnet_uri ) ; <nl> - if ( ! savePath_label . first . isEmpty ( ) ) <nl> - savePath = savePath_label . first ; <nl> - / / Remember label <nl> - if ( ! savePath_label . second . isEmpty ( ) ) <nl> - TorrentTempData : : setLabel ( hash , savePath_label . second ) ; <nl> - } <nl> - if ( savePath . isEmpty ( ) ) <nl> - savePath = getSavePath ( hash , false ) ; <nl> - if ( ! defaultTempPath . isEmpty ( ) & & ! TorrentPersistentData : : instance ( ) - > isSeed ( hash ) ) { <nl> - qDebug ( " addMagnetURI : Temp folder is enabled . " ) ; <nl> - QString torrent_tmp_path = defaultTempPath ; <nl> - p . save_path = fsutils : : toNativePath ( torrent_tmp_path ) . toUtf8 ( ) . constData ( ) ; <nl> - / / Check if save path exists , creating it otherwise <nl> - if ( ! QDir ( torrent_tmp_path ) . exists ( ) ) <nl> - QDir ( ) . mkpath ( torrent_tmp_path ) ; <nl> - qDebug ( " addTorrent : using save_path : % s " , qPrintable ( torrent_tmp_path ) ) ; <nl> - } else { <nl> - p . save_path = fsutils : : toNativePath ( savePath ) . toUtf8 ( ) . constData ( ) ; <nl> - / / Check if save path exists , creating it otherwise <nl> - if ( ! QDir ( savePath ) . exists ( ) ) QDir ( ) . mkpath ( savePath ) ; <nl> - qDebug ( " addTorrent : using save_path : % s " , qPrintable ( savePath ) ) ; <nl> - } <nl> - <nl> - qDebug ( " Adding magnet URI : % s " , qPrintable ( magnet_uri ) ) ; <nl> - <nl> - / / Adding torrent to Bittorrent session <nl> - try { <nl> - h = QTorrentHandle ( s - > add_torrent ( p ) ) ; <nl> - } catch ( std : : exception & e ) { <nl> - qDebug ( " Error : % s " , e . what ( ) ) ; <nl> - } <nl> - / / Check if it worked <nl> - if ( ! h . is_valid ( ) ) { <nl> - / / No need to keep on , it failed . <nl> - qDebug ( " / ! \ \ Error : Invalid handle " ) ; <nl> - return h ; <nl> - } <nl> - Q_ASSERT ( h . hash ( ) = = hash ) ; <nl> - <nl> - loadTorrentSettings ( h ) ; <nl> - <nl> - / / Load filtered files <nl> - bool add_paused = pref - > addTorrentsInPause ( ) ; <nl> - if ( ! resumed ) { <nl> - if ( TorrentTempData : : hasTempData ( hash ) ) <nl> - add_paused = TorrentTempData : : isAddPaused ( hash ) ; <nl> - loadTorrentTempData ( h , savePath , true ) ; <nl> - } <nl> - if ( HiddenData : : hasData ( hash ) & & pref - > isQueueingSystemEnabled ( ) ) { <nl> - / / Internally increase the queue limits to ensure that the magnet is started <nl> - libtorrent : : session_settings sessionSettings ( s - > settings ( ) ) ; <nl> - int max_downloading = pref - > getMaxActiveDownloads ( ) ; <nl> - int max_active = pref - > getMaxActiveTorrents ( ) ; <nl> - if ( max_downloading > - 1 ) <nl> - sessionSettings . active_downloads = max_downloading + HiddenData : : getDownloadingSize ( ) ; <nl> - else <nl> - sessionSettings . active_downloads = max_downloading ; <nl> - if ( max_active > - 1 ) <nl> - sessionSettings . active_limit = max_active + HiddenData : : getDownloadingSize ( ) ; <nl> - else <nl> - sessionSettings . active_limit = max_active ; <nl> - s - > set_settings ( sessionSettings ) ; <nl> - h . queue_position_top ( ) ; <nl> - } <nl> - if ( ! add_paused | | HiddenData : : hasData ( hash ) ) { <nl> - / / Start torrent because it was added in paused state <nl> - h . resume ( ) ; <nl> - } <nl> - / / Send torrent addition signal <nl> - logger - > addMessage ( tr ( " ' % 1 ' added to download list . " , " ' / home / y / xxx . torrent ' was added to download list . " ) . arg ( magnet_uri ) ) ; <nl> - if ( ! HiddenData : : hasData ( hash ) ) <nl> - emit addedTorrent ( h ) ; <nl> + Q_UNUSED ( fromScanDir ) ; <nl> + Q_UNUSED ( filePath ) ; <nl> + Preferences * const pref = Preferences : : instance ( ) ; <nl> + Logger * const logger = Logger : : instance ( ) ; <nl> + QTorrentHandle h ; <nl> + add_torrent_params p ; <nl> + libtorrent : : error_code ec ; <nl> + <nl> + libtorrent : : parse_magnet_uri ( magnet_uri . toUtf8 ( ) . constData ( ) , p , ec ) ; <nl> + if ( ec ) { <nl> + logger - > addMessage ( tr ( " Couldn ' t parse this Magnet URI : ' % 1 ' " ) . arg ( magnet_uri ) ) ; <nl> + return h ; <nl> + } <nl> + const QString hash ( misc : : toQString ( p . info_hash ) ) ; <nl> + if ( hash . isEmpty ( ) ) { <nl> + logger - > addMessage ( tr ( " ' % 1 ' is not a valid magnet URI . " ) . arg ( magnet_uri ) ) ; <nl> + return h ; <nl> + } <nl> + const QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ; <nl> + if ( resumed ) { <nl> + / / Load metadata <nl> + const QString torrent_path = torrentBackup . absoluteFilePath ( hash + " . torrent " ) ; <nl> + if ( QFile : : exists ( torrent_path ) ) <nl> + return addTorrent ( torrent_path , false , QString : : null , true ) ; <nl> + } <nl> + qDebug ( " Adding a magnet URI : % s " , qPrintable ( hash ) ) ; <nl> + Q_ASSERT ( magnet_uri . startsWith ( " magnet : " , Qt : : CaseInsensitive ) ) ; <nl> + <nl> + / / limit h_ex scope <nl> + { <nl> + / / Check for duplicate torrent <nl> + QTorrentHandle h_ex = QTorrentHandle ( s - > find_torrent ( p . info_hash ) ) ; <nl> + if ( h_ex . is_valid ( ) ) { <nl> + qDebug ( " / ! \ \ Torrent is already in download list " ) ; <nl> + logger - > addMessage ( tr ( " ' % 1 ' is already in download list . " , " e . g : ' xxx . avi ' is already in download list . " ) . arg ( magnet_uri ) ) ; <nl> + / / Check if the torrent contains trackers or url seeds we don ' t know about <nl> + / / and add them <nl> + mergeTorrents ( h_ex , magnet_uri ) ; <nl> + return h ; <nl> + } <nl> + } <nl> <nl> - return h ; <nl> + initializeAddTorrentParams ( hash , p ) ; <nl> + <nl> + / / Get save path <nl> + QString savePath ; <nl> + if ( ! resumed & & savepathLabel_fromurl . contains ( magnet_uri ) ) { <nl> + QPair < QString , QString > savePath_label = savepathLabel_fromurl . take ( magnet_uri ) ; <nl> + if ( ! savePath_label . first . isEmpty ( ) ) <nl> + savePath = savePath_label . first ; <nl> + / / Remember label <nl> + if ( ! savePath_label . second . isEmpty ( ) ) <nl> + TorrentTempData : : setLabel ( hash , savePath_label . second ) ; <nl> + } <nl> + if ( savePath . isEmpty ( ) ) <nl> + savePath = getSavePath ( hash , false ) ; <nl> + if ( ! defaultTempPath . isEmpty ( ) & & ! TorrentPersistentData : : instance ( ) - > isSeed ( hash ) ) { <nl> + qDebug ( " addMagnetURI : Temp folder is enabled . " ) ; <nl> + QString torrent_tmp_path = defaultTempPath ; <nl> + p . save_path = fsutils : : toNativePath ( torrent_tmp_path ) . toUtf8 ( ) . constData ( ) ; <nl> + / / Check if save path exists , creating it otherwise <nl> + if ( ! QDir ( torrent_tmp_path ) . exists ( ) ) <nl> + QDir ( ) . mkpath ( torrent_tmp_path ) ; <nl> + qDebug ( " addTorrent : using save_path : % s " , qPrintable ( torrent_tmp_path ) ) ; <nl> + } else { <nl> + p . save_path = fsutils : : toNativePath ( savePath ) . toUtf8 ( ) . constData ( ) ; <nl> + / / Check if save path exists , creating it otherwise <nl> + if ( ! QDir ( savePath ) . exists ( ) ) QDir ( ) . mkpath ( savePath ) ; <nl> + qDebug ( " addTorrent : using save_path : % s " , qPrintable ( savePath ) ) ; <nl> + } <nl> + <nl> + qDebug ( " Adding magnet URI : % s " , qPrintable ( magnet_uri ) ) ; <nl> + <nl> + / / Adding torrent to Bittorrent session <nl> + try { <nl> + h = QTorrentHandle ( s - > add_torrent ( p ) ) ; <nl> + } catch ( std : : exception & e ) { <nl> + qDebug ( " Error : % s " , e . what ( ) ) ; <nl> + } <nl> + / / Check if it worked <nl> + if ( ! h . is_valid ( ) ) { <nl> + / / No need to keep on , it failed . <nl> + qDebug ( " / ! \ \ Error : Invalid handle " ) ; <nl> + return h ; <nl> + } <nl> + Q_ASSERT ( h . hash ( ) = = hash ) ; <nl> + <nl> + loadTorrentSettings ( h ) ; <nl> + <nl> + / / Load filtered files <nl> + bool add_paused = pref - > addTorrentsInPause ( ) ; <nl> + if ( ! resumed ) { <nl> + if ( TorrentTempData : : hasTempData ( hash ) ) <nl> + add_paused = TorrentTempData : : isAddPaused ( hash ) ; <nl> + loadTorrentTempData ( h , savePath , true ) ; <nl> + } <nl> + if ( HiddenData : : hasData ( hash ) & & pref - > isQueueingSystemEnabled ( ) ) { <nl> + / / Internally increase the queue limits to ensure that the magnet is started <nl> + libtorrent : : session_settings sessionSettings ( s - > settings ( ) ) ; <nl> + int max_downloading = pref - > getMaxActiveDownloads ( ) ; <nl> + int max_active = pref - > getMaxActiveTorrents ( ) ; <nl> + if ( max_downloading > - 1 ) <nl> + sessionSettings . active_downloads = max_downloading + HiddenData : : getDownloadingSize ( ) ; <nl> + else <nl> + sessionSettings . active_downloads = max_downloading ; <nl> + if ( max_active > - 1 ) <nl> + sessionSettings . active_limit = max_active + HiddenData : : getDownloadingSize ( ) ; <nl> + else <nl> + sessionSettings . active_limit = max_active ; <nl> + s - > set_settings ( sessionSettings ) ; <nl> + h . queue_position_top ( ) ; <nl> + } <nl> + if ( ! add_paused | | HiddenData : : hasData ( hash ) ) { <nl> + / / Start torrent because it was added in paused state <nl> + h . resume ( ) ; <nl> + } <nl> + / / Send torrent addition signal <nl> + logger - > addMessage ( tr ( " ' % 1 ' added to download list . " , " ' / home / y / xxx . torrent ' was added to download list . " ) . arg ( magnet_uri ) ) ; <nl> + if ( ! HiddenData : : hasData ( hash ) ) <nl> + emit addedTorrent ( h ) ; <nl> + <nl> + return h ; <nl> } <nl> <nl> / / Add a torrent to the Bittorrent session <nl> QTorrentHandle QBtSession : : addTorrent ( QString path , bool fromScanDir , QString from_url , bool resumed , bool imported ) { <nl> - QTorrentHandle h ; <nl> - Preferences * const pref = Preferences : : instance ( ) ; <nl> - Logger * const logger = Logger : : instance ( ) ; <nl> + QTorrentHandle h ; <nl> + Preferences * const pref = Preferences : : instance ( ) ; <nl> + Logger * const logger = Logger : : instance ( ) ; <nl> <nl> - / / Check if BT_backup directory exists <nl> - const QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ; <nl> - if ( ! torrentBackup . exists ( ) ) { <nl> - / / If temporary file , remove it <nl> - if ( ! from_url . isNull ( ) | | fromScanDir ) <nl> - fsutils : : forceRemove ( path ) ; <nl> - return h ; <nl> - } <nl> + / / Check if BT_backup directory exists <nl> + const QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ; <nl> + if ( ! torrentBackup . exists ( ) ) { <nl> + / / If temporary file , remove it <nl> + if ( ! from_url . isNull ( ) | | fromScanDir ) <nl> + fsutils : : forceRemove ( path ) ; <nl> + return h ; <nl> + } <nl> <nl> - / / Fix the input path if necessary <nl> - path = fsutils : : fromNativePath ( path ) ; <nl> + / / Fix the input path if necessary <nl> + path = fsutils : : fromNativePath ( path ) ; <nl> # ifdef Q_OS_WIN <nl> - / / Windows hack <nl> - if ( ! path . endsWith ( " . torrent " ) ) <nl> - if ( QFile : : rename ( path , path + " . torrent " ) ) path + = " . torrent " ; <nl> + / / Windows hack <nl> + if ( ! path . endsWith ( " . torrent " ) ) <nl> + if ( QFile : : rename ( path , path + " . torrent " ) ) path + = " . torrent " ; <nl> # endif <nl> - if ( path . startsWith ( " file : " , Qt : : CaseInsensitive ) ) <nl> - path = QUrl : : fromEncoded ( path . toLocal8Bit ( ) ) . toLocalFile ( ) ; <nl> - if ( path . isEmpty ( ) ) return h ; <nl> - <nl> - Q_ASSERT ( ! misc : : isUrl ( path ) ) ; <nl> - <nl> - qDebug ( " Adding % s to download list " , qPrintable ( path ) ) ; <nl> - boost : : intrusive_ptr < torrent_info > t ; <nl> - try { <nl> - qDebug ( ) < < " Loading torrent at " < < path ; <nl> - / / Getting torrent file informations <nl> - std : : vector < char > buffer ; <nl> - lazy_entry entry ; <nl> - libtorrent : : error_code ec ; <nl> - misc : : loadBencodedFile ( path , buffer , entry , ec ) ; <nl> - t = new torrent_info ( entry ) ; <nl> - if ( ! t - > is_valid ( ) ) <nl> - throw std : : exception ( ) ; <nl> - } catch ( std : : exception & e ) { <nl> - if ( ! from_url . isNull ( ) ) { <nl> - logger - > addMessage ( tr ( " Unable to decode torrent file : ' % 1 ' " , " e . g : Unable to decode torrent file : ' / home / y / xxx . torrent ' " ) . arg ( from_url ) , Log : : CRITICAL ) ; <nl> - logger - > addMessage ( misc : : toQStringU ( e . what ( ) ) , Log : : CRITICAL ) ; <nl> - / / emit invalidTorrent ( from_url ) ; <nl> - fsutils : : forceRemove ( path ) ; <nl> - } else { <nl> - logger - > addMessage ( tr ( " Unable to decode torrent file : ' % 1 ' " , " e . g : Unable to decode torrent file : ' / home / y / xxx . torrent ' " ) . arg ( fsutils : : toNativePath ( path ) ) , Log : : CRITICAL ) ; <nl> - / / emit invalidTorrent ( path ) ; <nl> - } <nl> - logger - > addMessage ( tr ( " This file is either corrupted or this isn ' t a torrent . " ) , Log : : CRITICAL ) ; <nl> - if ( fromScanDir ) { <nl> - / / Remove file <nl> - fsutils : : forceRemove ( path ) ; <nl> - } <nl> - return h ; <nl> - } <nl> + if ( path . startsWith ( " file : " , Qt : : CaseInsensitive ) ) <nl> + path = QUrl : : fromEncoded ( path . toLocal8Bit ( ) ) . toLocalFile ( ) ; <nl> + if ( path . isEmpty ( ) ) return h ; <nl> <nl> - const QString hash = misc : : toQString ( t - > info_hash ( ) ) ; <nl> + Q_ASSERT ( ! misc : : isUrl ( path ) ) ; <nl> <nl> - qDebug ( " - > Hash : % s " , qPrintable ( hash ) ) ; <nl> - qDebug ( " - > Name : % s " , t - > name ( ) . c_str ( ) ) ; <nl> - <nl> - / / Check for duplicate <nl> - if ( s - > find_torrent ( t - > info_hash ( ) ) . is_valid ( ) ) { <nl> - qDebug ( " / ! \ \ Torrent is already in download list " ) ; <nl> - / / Update info Bar <nl> - if ( ! from_url . isNull ( ) ) { <nl> - logger - > addMessage ( tr ( " ' % 1 ' is already in download list . " , " e . g : ' xxx . avi ' is already in download list . " ) . arg ( from_url ) ) ; <nl> - } else { <nl> - logger - > addMessage ( tr ( " ' % 1 ' is already in download list . " , " e . g : ' xxx . avi ' is already in download list . " ) . arg ( fsutils : : toNativePath ( path ) ) ) ; <nl> + qDebug ( " Adding % s to download list " , qPrintable ( path ) ) ; <nl> + boost : : intrusive_ptr < torrent_info > t ; <nl> + try { <nl> + qDebug ( ) < < " Loading torrent at " < < path ; <nl> + / / Getting torrent file informations <nl> + std : : vector < char > buffer ; <nl> + lazy_entry entry ; <nl> + libtorrent : : error_code ec ; <nl> + misc : : loadBencodedFile ( path , buffer , entry , ec ) ; <nl> + t = new torrent_info ( entry ) ; <nl> + if ( ! t - > is_valid ( ) ) <nl> + throw std : : exception ( ) ; <nl> + } catch ( std : : exception & e ) { <nl> + if ( ! from_url . isNull ( ) ) { <nl> + logger - > addMessage ( tr ( " Unable to decode torrent file : ' % 1 ' " , " e . g : Unable to decode torrent file : ' / home / y / xxx . torrent ' " ) . arg ( from_url ) , Log : : CRITICAL ) ; <nl> + logger - > addMessage ( misc : : toQStringU ( e . what ( ) ) , Log : : CRITICAL ) ; <nl> + / / emit invalidTorrent ( from_url ) ; <nl> + fsutils : : forceRemove ( path ) ; <nl> + } else { <nl> + logger - > addMessage ( tr ( " Unable to decode torrent file : ' % 1 ' " , " e . g : Unable to decode torrent file : ' / home / y / xxx . torrent ' " ) . arg ( fsutils : : toNativePath ( path ) ) , Log : : CRITICAL ) ; <nl> + / / emit invalidTorrent ( path ) ; <nl> + } <nl> + logger - > addMessage ( tr ( " This file is either corrupted or this isn ' t a torrent . " ) , Log : : CRITICAL ) ; <nl> + if ( fromScanDir ) { <nl> + / / Remove file <nl> + fsutils : : forceRemove ( path ) ; <nl> + } <nl> + return h ; <nl> } <nl> - / / Check if the torrent contains trackers or url seeds we don ' t know about <nl> - / / and add them <nl> - QTorrentHandle h_ex = getTorrentHandle ( hash ) ; <nl> - mergeTorrents ( h_ex , t ) ; <nl> <nl> - / / Delete file if temporary <nl> - if ( ! from_url . isNull ( ) | | fromScanDir ) <nl> - fsutils : : forceRemove ( path ) ; <nl> - return h ; <nl> - } <nl> + const QString hash = misc : : toQString ( t - > info_hash ( ) ) ; <nl> <nl> - / / Check number of files <nl> - if ( t - > num_files ( ) < 1 ) { <nl> - logger - > addMessage ( tr ( " Error : The torrent % 1 does not contain any file . " ) . arg ( misc : : toQStringU ( t - > name ( ) ) ) ) ; <nl> - / / Delete file if temporary <nl> - if ( ! from_url . isNull ( ) | | fromScanDir ) <nl> - fsutils : : forceRemove ( path ) ; <nl> - return h ; <nl> - } <nl> - <nl> - / / Actually add the torrent <nl> - add_torrent_params p ; <nl> - initializeAddTorrentParams ( hash , p ) ; <nl> - p . ti = t ; <nl> - <nl> - / / Get fast resume data if existing <nl> - bool fastResume = false ; <nl> - std : : vector < char > buf ; / / Needs to stay in the function scope <nl> - if ( resumed ) { <nl> - if ( loadFastResumeData ( hash , buf ) ) { <nl> - fastResume = true ; <nl> + qDebug ( " - > Hash : % s " , qPrintable ( hash ) ) ; <nl> + qDebug ( " - > Name : % s " , t - > name ( ) . c_str ( ) ) ; <nl> + <nl> + / / Check for duplicate <nl> + if ( s - > find_torrent ( t - > info_hash ( ) ) . is_valid ( ) ) { <nl> + qDebug ( " / ! \ \ Torrent is already in download list " ) ; <nl> + / / Update info Bar <nl> + if ( ! from_url . isNull ( ) ) { <nl> + logger - > addMessage ( tr ( " ' % 1 ' is already in download list . " , " e . g : ' xxx . avi ' is already in download list . " ) . arg ( from_url ) ) ; <nl> + } else { <nl> + logger - > addMessage ( tr ( " ' % 1 ' is already in download list . " , " e . g : ' xxx . avi ' is already in download list . " ) . arg ( fsutils : : toNativePath ( path ) ) ) ; <nl> + } <nl> + / / Check if the torrent contains trackers or url seeds we don ' t know about <nl> + / / and add them <nl> + QTorrentHandle h_ex = getTorrentHandle ( hash ) ; <nl> + mergeTorrents ( h_ex , t ) ; <nl> + <nl> + / / Delete file if temporary <nl> + if ( ! from_url . isNull ( ) | | fromScanDir ) <nl> + fsutils : : forceRemove ( path ) ; <nl> + return h ; <nl> + } <nl> + <nl> + / / Check number of files <nl> + if ( t - > num_files ( ) < 1 ) { <nl> + logger - > addMessage ( tr ( " Error : The torrent % 1 does not contain any file . " ) . arg ( misc : : toQStringU ( t - > name ( ) ) ) ) ; <nl> + / / Delete file if temporary <nl> + if ( ! from_url . isNull ( ) | | fromScanDir ) <nl> + fsutils : : forceRemove ( path ) ; <nl> + return h ; <nl> + } <nl> + <nl> + / / Actually add the torrent <nl> + add_torrent_params p ; <nl> + initializeAddTorrentParams ( hash , p ) ; <nl> + p . ti = t ; <nl> + <nl> + / / Get fast resume data if existing <nl> + bool fastResume = false ; <nl> + std : : vector < char > buf ; / / Needs to stay in the function scope <nl> + if ( resumed ) { <nl> + if ( loadFastResumeData ( hash , buf ) ) { <nl> + fastResume = true ; <nl> # if LIBTORRENT_VERSION_NUM < 10000 <nl> - p . resume_data = & buf ; <nl> + p . resume_data = & buf ; <nl> # else <nl> - p . resume_data = buf ; <nl> + p . resume_data = buf ; <nl> # endif <nl> - qDebug ( " Successfully loaded fast resume data " ) ; <nl> + qDebug ( " Successfully loaded fast resume data " ) ; <nl> + } <nl> + } <nl> + <nl> + recoverPersistentData ( hash , buf ) ; <nl> + QString savePath ; <nl> + if ( ! from_url . isEmpty ( ) & & savepathLabel_fromurl . contains ( QUrl : : fromEncoded ( from_url . toUtf8 ( ) ) ) ) { <nl> + / / Enforcing the save path defined before URL download ( from RSS for example ) <nl> + QPair < QString , QString > savePath_label = savepathLabel_fromurl . take ( QUrl : : fromEncoded ( from_url . toUtf8 ( ) ) ) ; <nl> + if ( savePath_label . first . isEmpty ( ) ) <nl> + savePath = getSavePath ( hash , fromScanDir , path ) ; <nl> + else <nl> + savePath = savePath_label . first ; <nl> + / / Remember label <nl> + TorrentTempData : : setLabel ( hash , savePath_label . second ) ; <nl> + } else { <nl> + savePath = getSavePath ( hash , fromScanDir , path , imported ) ; <nl> + } <nl> + if ( ! imported & & ! defaultTempPath . isEmpty ( ) & & ! TorrentPersistentData : : instance ( ) - > isSeed ( hash ) ) { <nl> + qDebug ( " addTorrent : : Temp folder is enabled . " ) ; <nl> + QString torrent_tmp_path = defaultTempPath ; <nl> + p . save_path = fsutils : : toNativePath ( torrent_tmp_path ) . toUtf8 ( ) . constData ( ) ; <nl> + / / Check if save path exists , creating it otherwise <nl> + if ( ! QDir ( torrent_tmp_path ) . exists ( ) ) QDir ( ) . mkpath ( torrent_tmp_path ) ; <nl> + qDebug ( " addTorrent : using save_path : % s " , qPrintable ( torrent_tmp_path ) ) ; <nl> + } else { <nl> + p . save_path = fsutils : : toNativePath ( savePath ) . toUtf8 ( ) . constData ( ) ; <nl> + / / Check if save path exists , creating it otherwise <nl> + if ( ! QDir ( savePath ) . exists ( ) ) QDir ( ) . mkpath ( savePath ) ; <nl> + qDebug ( " addTorrent : using save_path : % s " , qPrintable ( savePath ) ) ; <nl> + } <nl> + <nl> + / / Adding torrent to Bittorrent session <nl> + try { <nl> + h = QTorrentHandle ( s - > add_torrent ( p ) ) ; <nl> + } catch ( std : : exception & e ) { <nl> + qDebug ( " Error : % s " , e . what ( ) ) ; <nl> + } <nl> + / / Check if it worked <nl> + if ( ! h . is_valid ( ) ) { <nl> + qDebug ( " / ! \ \ Error : Invalid handle " ) ; <nl> + / / If temporary file , remove it <nl> + if ( ! from_url . isNull ( ) | | fromScanDir ) <nl> + fsutils : : forceRemove ( path ) ; <nl> + return h ; <nl> + } <nl> + <nl> + loadTorrentSettings ( h ) ; <nl> + <nl> + bool add_paused = pref - > addTorrentsInPause ( ) ; <nl> + if ( ! resumed ) { <nl> + qDebug ( " This is a NEW torrent ( first time ) . . . " ) ; <nl> + if ( TorrentTempData : : hasTempData ( hash ) ) <nl> + add_paused = TorrentTempData : : isAddPaused ( hash ) ; <nl> + <nl> + loadTorrentTempData ( h , savePath , false ) ; <nl> + <nl> + / / Append . ! qB to incomplete files <nl> + if ( appendqBExtension ) <nl> + appendqBextensionToTorrent ( h , true ) ; <nl> + <nl> + / / Backup torrent file <nl> + const QString newFile = torrentBackup . absoluteFilePath ( hash + " . torrent " ) ; <nl> + if ( path ! = newFile ) <nl> + QFile : : copy ( path , newFile ) ; <nl> + / / Copy the torrent file to the export folder <nl> + if ( m_torrentExportEnabled ) <nl> + exportTorrentFile ( h ) ; <nl> + } <nl> + <nl> + if ( ! fastResume & & ! add_paused ) { <nl> + / / Start torrent because it was added in paused state <nl> + h . resume ( ) ; <nl> } <nl> - } <nl> <nl> - recoverPersistentData ( hash , buf ) ; <nl> - QString savePath ; <nl> - if ( ! from_url . isEmpty ( ) & & savepathLabel_fromurl . contains ( QUrl : : fromEncoded ( from_url . toUtf8 ( ) ) ) ) { <nl> - / / Enforcing the save path defined before URL download ( from RSS for example ) <nl> - QPair < QString , QString > savePath_label = savepathLabel_fromurl . take ( QUrl : : fromEncoded ( from_url . toUtf8 ( ) ) ) ; <nl> - if ( savePath_label . first . isEmpty ( ) ) <nl> - savePath = getSavePath ( hash , fromScanDir , path ) ; <nl> - else <nl> - savePath = savePath_label . first ; <nl> - / / Remember label <nl> - TorrentTempData : : setLabel ( hash , savePath_label . second ) ; <nl> - } else { <nl> - savePath = getSavePath ( hash , fromScanDir , path , imported ) ; <nl> - } <nl> - if ( ! imported & & ! defaultTempPath . isEmpty ( ) & & ! TorrentPersistentData : : instance ( ) - > isSeed ( hash ) ) { <nl> - qDebug ( " addTorrent : : Temp folder is enabled . " ) ; <nl> - QString torrent_tmp_path = defaultTempPath ; <nl> - p . save_path = fsutils : : toNativePath ( torrent_tmp_path ) . toUtf8 ( ) . constData ( ) ; <nl> - / / Check if save path exists , creating it otherwise <nl> - if ( ! QDir ( torrent_tmp_path ) . exists ( ) ) QDir ( ) . mkpath ( torrent_tmp_path ) ; <nl> - qDebug ( " addTorrent : using save_path : % s " , qPrintable ( torrent_tmp_path ) ) ; <nl> - } else { <nl> - p . save_path = fsutils : : toNativePath ( savePath ) . toUtf8 ( ) . constData ( ) ; <nl> - / / Check if save path exists , creating it otherwise <nl> - if ( ! QDir ( savePath ) . exists ( ) ) QDir ( ) . mkpath ( savePath ) ; <nl> - qDebug ( " addTorrent : using save_path : % s " , qPrintable ( savePath ) ) ; <nl> - } <nl> - <nl> - / / Adding torrent to Bittorrent session <nl> - try { <nl> - h = QTorrentHandle ( s - > add_torrent ( p ) ) ; <nl> - } catch ( std : : exception & e ) { <nl> - qDebug ( " Error : % s " , e . what ( ) ) ; <nl> - } <nl> - / / Check if it worked <nl> - if ( ! h . is_valid ( ) ) { <nl> - qDebug ( " / ! \ \ Error : Invalid handle " ) ; <nl> / / If temporary file , remove it <nl> if ( ! from_url . isNull ( ) | | fromScanDir ) <nl> - fsutils : : forceRemove ( path ) ; <nl> - return h ; <nl> - } <nl> - <nl> - loadTorrentSettings ( h ) ; <nl> - <nl> - bool add_paused = pref - > addTorrentsInPause ( ) ; <nl> - if ( ! resumed ) { <nl> - qDebug ( " This is a NEW torrent ( first time ) . . . " ) ; <nl> - if ( TorrentTempData : : hasTempData ( hash ) ) <nl> - add_paused = TorrentTempData : : isAddPaused ( hash ) ; <nl> - <nl> - loadTorrentTempData ( h , savePath , false ) ; <nl> - <nl> - / / Append . ! qB to incomplete files <nl> - if ( appendqBExtension ) <nl> - appendqBextensionToTorrent ( h , true ) ; <nl> - <nl> - / / Backup torrent file <nl> - const QString newFile = torrentBackup . absoluteFilePath ( hash + " . torrent " ) ; <nl> - if ( path ! = newFile ) <nl> - QFile : : copy ( path , newFile ) ; <nl> - / / Copy the torrent file to the export folder <nl> - if ( m_torrentExportEnabled ) <nl> - exportTorrentFile ( h ) ; <nl> - } <nl> - <nl> - if ( ! fastResume & & ! add_paused ) { <nl> - / / Start torrent because it was added in paused state <nl> - h . resume ( ) ; <nl> - } <nl> - <nl> - / / If temporary file , remove it <nl> - if ( ! from_url . isNull ( ) | | fromScanDir ) <nl> - fsutils : : forceRemove ( path ) ; <nl> - <nl> - / / Display console message <nl> - if ( ! from_url . isNull ( ) ) { <nl> - if ( fastResume ) <nl> - logger - > addMessage ( tr ( " ' % 1 ' resumed . ( fast resume ) " , " ' / home / y / xxx . torrent ' was resumed . ( fast resume ) " ) . arg ( from_url ) ) ; <nl> - else <nl> - logger - > addMessage ( tr ( " ' % 1 ' added to download list . " , " ' / home / y / xxx . torrent ' was added to download list . " ) . arg ( from_url ) ) ; <nl> - } else { <nl> - if ( fastResume ) <nl> - logger - > addMessage ( tr ( " ' % 1 ' resumed . ( fast resume ) " , " ' / home / y / xxx . torrent ' was resumed . ( fast resume ) " ) . arg ( fsutils : : toNativePath ( path ) ) ) ; <nl> - else <nl> - logger - > addMessage ( tr ( " ' % 1 ' added to download list . " , " ' / home / y / xxx . torrent ' was added to download list . " ) . arg ( fsutils : : toNativePath ( path ) ) ) ; <nl> - } <nl> + fsutils : : forceRemove ( path ) ; <nl> + <nl> + / / Display console message <nl> + if ( ! from_url . isNull ( ) ) { <nl> + if ( fastResume ) <nl> + logger - > addMessage ( tr ( " ' % 1 ' resumed . ( fast resume ) " , " ' / home / y / xxx . torrent ' was resumed . ( fast resume ) " ) . arg ( from_url ) ) ; <nl> + else <nl> + logger - > addMessage ( tr ( " ' % 1 ' added to download list . " , " ' / home / y / xxx . torrent ' was added to download list . " ) . arg ( from_url ) ) ; <nl> + } else { <nl> + if ( fastResume ) <nl> + logger - > addMessage ( tr ( " ' % 1 ' resumed . ( fast resume ) " , " ' / home / y / xxx . torrent ' was resumed . ( fast resume ) " ) . arg ( fsutils : : toNativePath ( path ) ) ) ; <nl> + else <nl> + logger - > addMessage ( tr ( " ' % 1 ' added to download list . " , " ' / home / y / xxx . torrent ' was added to download list . " ) . arg ( fsutils : : toNativePath ( path ) ) ) ; <nl> + } <nl> <nl> - / / Send torrent addition signal <nl> - emit addedTorrent ( h ) ; <nl> - return h ; <nl> + / / Send torrent addition signal <nl> + emit addedTorrent ( h ) ; <nl> + return h ; <nl> } <nl> <nl> void QBtSession : : exportTorrentFile ( const QTorrentHandle & h , TorrentExportFolder folder ) { <nl> - Q_ASSERT ( ( folder = = RegularTorrentExportFolder & & m_torrentExportEnabled ) | | <nl> - ( folder = = FinishedTorrentExportFolder & & m_finishedTorrentExportEnabled ) ) ; <nl> - QString torrent_path = QDir ( fsutils : : BTBackupLocation ( ) ) . absoluteFilePath ( h . hash ( ) + " . torrent " ) ; <nl> - QDir exportPath ( folder = = RegularTorrentExportFolder ? Preferences : : instance ( ) - > getTorrentExportDir ( ) : Preferences : : instance ( ) - > getFinishedTorrentExportDir ( ) ) ; <nl> - if ( exportPath . exists ( ) | | exportPath . mkpath ( exportPath . absolutePath ( ) ) ) { <nl> - QString new_torrent_path = exportPath . absoluteFilePath ( h . name ( ) + " . torrent " ) ; <nl> - if ( QFile : : exists ( new_torrent_path ) & & fsutils : : sameFiles ( torrent_path , new_torrent_path ) ) { <nl> - / / Append hash to torrent name to make it unique <nl> - new_torrent_path = exportPath . absoluteFilePath ( h . name ( ) + " - " + h . hash ( ) + " . torrent " ) ; <nl> + Q_ASSERT ( ( folder = = RegularTorrentExportFolder & & m_torrentExportEnabled ) | | <nl> + ( folder = = FinishedTorrentExportFolder & & m_finishedTorrentExportEnabled ) ) ; <nl> + QString torrent_path = QDir ( fsutils : : BTBackupLocation ( ) ) . absoluteFilePath ( h . hash ( ) + " . torrent " ) ; <nl> + QDir exportPath ( folder = = RegularTorrentExportFolder ? Preferences : : instance ( ) - > getTorrentExportDir ( ) : Preferences : : instance ( ) - > getFinishedTorrentExportDir ( ) ) ; <nl> + if ( exportPath . exists ( ) | | exportPath . mkpath ( exportPath . absolutePath ( ) ) ) { <nl> + QString new_torrent_path = exportPath . absoluteFilePath ( h . name ( ) + " . torrent " ) ; <nl> + if ( QFile : : exists ( new_torrent_path ) & & fsutils : : sameFiles ( torrent_path , new_torrent_path ) ) { <nl> + / / Append hash to torrent name to make it unique <nl> + new_torrent_path = exportPath . absoluteFilePath ( h . name ( ) + " - " + h . hash ( ) + " . torrent " ) ; <nl> + } <nl> + QFile : : copy ( torrent_path , new_torrent_path ) ; <nl> } <nl> - QFile : : copy ( torrent_path , new_torrent_path ) ; <nl> - } <nl> } <nl> <nl> void QBtSession : : initializeAddTorrentParams ( const QString & hash , add_torrent_params & p ) { <nl> - / / Seeding mode <nl> - / / Skip checking and directly start seeding ( new in libtorrent v0 . 15 ) <nl> - if ( TorrentTempData : : isSeedingMode ( hash ) ) <nl> - p . flags | = add_torrent_params : : flag_seed_mode ; <nl> - else <nl> - p . flags & = ~ add_torrent_params : : flag_seed_mode ; <nl> - <nl> - / / Preallocation mode <nl> - if ( preAllocateAll ) <nl> - p . storage_mode = storage_mode_allocate ; <nl> - else <nl> - p . storage_mode = storage_mode_sparse ; <nl> - <nl> - / / Priorities <nl> - / * if ( TorrentTempData : : hasTempData ( hash ) ) { <nl> + / / Seeding mode <nl> + / / Skip checking and directly start seeding ( new in libtorrent v0 . 15 ) <nl> + if ( TorrentTempData : : isSeedingMode ( hash ) ) <nl> + p . flags | = add_torrent_params : : flag_seed_mode ; <nl> + else <nl> + p . flags & = ~ add_torrent_params : : flag_seed_mode ; <nl> + <nl> + / / Preallocation mode <nl> + if ( preAllocateAll ) <nl> + p . storage_mode = storage_mode_allocate ; <nl> + else <nl> + p . storage_mode = storage_mode_sparse ; <nl> + <nl> + / / Priorities <nl> + / * if ( TorrentTempData : : hasTempData ( hash ) ) { <nl> std : : vector < int > fp ; <nl> TorrentTempData : : getFilesPriority ( hash , fp ) ; <nl> if ( ! fp . empty ( ) ) { <nl> void QBtSession : : initializeAddTorrentParams ( const QString & hash , add_torrent_par <nl> } <nl> } * / <nl> <nl> - / / Start in pause <nl> - p . flags | = add_torrent_params : : flag_paused ; <nl> - p . flags & = ~ add_torrent_params : : flag_duplicate_is_error ; / / Already checked <nl> - p . flags & = ~ add_torrent_params : : flag_auto_managed ; / / Because it is added in paused state <nl> + / / Start in pause <nl> + p . flags | = add_torrent_params : : flag_paused ; <nl> + p . flags & = ~ add_torrent_params : : flag_duplicate_is_error ; / / Already checked <nl> + p . flags & = ~ add_torrent_params : : flag_auto_managed ; / / Because it is added in paused state <nl> } <nl> <nl> void QBtSession : : loadTorrentTempData ( QTorrentHandle & h , QString savePath , bool magnet ) { <nl> - qDebug ( " loadTorrentTempdata ( ) - ENTER " ) ; <nl> - const QString hash = h . hash ( ) ; <nl> - / / Sequential download <nl> - if ( TorrentTempData : : hasTempData ( hash ) ) { <nl> - / / sequential download <nl> - h . set_sequential_download ( TorrentTempData : : isSequential ( hash ) ) ; <nl> - <nl> - / / The following is useless for newly added magnet <nl> - if ( ! magnet ) { <nl> - / / Files priorities <nl> - vector < int > fp ; <nl> - TorrentTempData : : getFilesPriority ( hash , fp ) ; <nl> - h . prioritize_files ( fp ) ; <nl> - <nl> - / / Prioritize first / last piece <nl> - h . prioritize_first_last_piece ( TorrentTempData : : isSequential ( hash ) ) ; <nl> - <nl> - / / Update file names <nl> - const QStringList files_path = TorrentTempData : : getFilesPath ( hash ) ; <nl> - bool force_recheck = false ; <nl> - QDir base_dir ( h . save_path ( ) ) ; <nl> - if ( files_path . size ( ) = = h . num_files ( ) ) { <nl> - for ( int i = 0 ; i < h . num_files ( ) ; + + i ) { <nl> - const QString & path = files_path . at ( i ) ; <nl> - if ( ! force_recheck & & base_dir . exists ( path ) ) <nl> - force_recheck = true ; <nl> - qDebug ( " Renaming file to % s " , qPrintable ( path ) ) ; <nl> - h . rename_file ( i , path ) ; <nl> - } <nl> - / / Force recheck <nl> - if ( force_recheck ) h . force_recheck ( ) ; <nl> - } <nl> + qDebug ( " loadTorrentTempdata ( ) - ENTER " ) ; <nl> + const QString hash = h . hash ( ) ; <nl> + / / Sequential download <nl> + if ( TorrentTempData : : hasTempData ( hash ) ) { <nl> + / / sequential download <nl> + h . set_sequential_download ( TorrentTempData : : isSequential ( hash ) ) ; <nl> + <nl> + / / The following is useless for newly added magnet <nl> + if ( ! magnet ) { <nl> + / / Files priorities <nl> + vector < int > fp ; <nl> + TorrentTempData : : getFilesPriority ( hash , fp ) ; <nl> + h . prioritize_files ( fp ) ; <nl> + <nl> + / / Prioritize first / last piece <nl> + h . prioritize_first_last_piece ( TorrentTempData : : isSequential ( hash ) ) ; <nl> + <nl> + / / Update file names <nl> + const QStringList files_path = TorrentTempData : : getFilesPath ( hash ) ; <nl> + bool force_recheck = false ; <nl> + QDir base_dir ( h . save_path ( ) ) ; <nl> + if ( files_path . size ( ) = = h . num_files ( ) ) { <nl> + for ( int i = 0 ; i < h . num_files ( ) ; + + i ) { <nl> + const QString & path = files_path . at ( i ) ; <nl> + if ( ! force_recheck & & base_dir . exists ( path ) ) <nl> + force_recheck = true ; <nl> + qDebug ( " Renaming file to % s " , qPrintable ( path ) ) ; <nl> + h . rename_file ( i , path ) ; <nl> + } <nl> + / / Force recheck <nl> + if ( force_recheck ) h . force_recheck ( ) ; <nl> + } <nl> + } <nl> } <nl> - } <nl> - / / Save persistent data for new torrent <nl> - qDebug ( " Saving torrent persistant data " ) ; <nl> - if ( defaultTempPath . isEmpty ( ) ) <nl> - TorrentPersistentData : : instance ( ) - > saveTorrentPersistentData ( h , QString : : null , magnet ) ; <nl> - else <nl> - TorrentPersistentData : : instance ( ) - > saveTorrentPersistentData ( h , fsutils : : fromNativePath ( savePath ) , magnet ) ; <nl> + / / Save persistent data for new torrent <nl> + qDebug ( " Saving torrent persistant data " ) ; <nl> + if ( defaultTempPath . isEmpty ( ) ) <nl> + TorrentPersistentData : : instance ( ) - > saveTorrentPersistentData ( h , QString : : null , magnet ) ; <nl> + else <nl> + TorrentPersistentData : : instance ( ) - > saveTorrentPersistentData ( h , fsutils : : fromNativePath ( savePath ) , magnet ) ; <nl> } <nl> <nl> void QBtSession : : mergeTorrents ( QTorrentHandle & h_ex , const QString & magnet_uri ) <nl> { <nl> - QList < QUrl > new_trackers = misc : : magnetUriToTrackers ( magnet_uri ) ; <nl> - bool trackers_added = false ; <nl> - foreach ( const QUrl & new_tracker , new_trackers ) { <nl> - bool found = false ; <nl> - std : : vector < announce_entry > existing_trackers = h_ex . trackers ( ) ; <nl> - foreach ( const announce_entry & existing_tracker , existing_trackers ) { <nl> - if ( new_tracker = = QUrl ( existing_tracker . url . c_str ( ) ) ) { <nl> - found = true ; <nl> - break ; <nl> - } <nl> - } <nl> + QList < QUrl > new_trackers = misc : : magnetUriToTrackers ( magnet_uri ) ; <nl> + bool trackers_added = false ; <nl> + foreach ( const QUrl & new_tracker , new_trackers ) { <nl> + bool found = false ; <nl> + std : : vector < announce_entry > existing_trackers = h_ex . trackers ( ) ; <nl> + foreach ( const announce_entry & existing_tracker , existing_trackers ) { <nl> + if ( new_tracker = = QUrl ( existing_tracker . url . c_str ( ) ) ) { <nl> + found = true ; <nl> + break ; <nl> + } <nl> + } <nl> <nl> - if ( ! found ) { <nl> - h_ex . add_tracker ( announce_entry ( new_tracker . toString ( ) . toStdString ( ) ) ) ; <nl> - trackers_added = true ; <nl> + if ( ! found ) { <nl> + h_ex . add_tracker ( announce_entry ( new_tracker . toString ( ) . toStdString ( ) ) ) ; <nl> + trackers_added = true ; <nl> + } <nl> } <nl> - } <nl> - if ( trackers_added ) <nl> - Logger : : instance ( ) - > addMessage ( tr ( " Note : new trackers were added to the existing torrent . " ) ) ; <nl> + if ( trackers_added ) <nl> + Logger : : instance ( ) - > addMessage ( tr ( " Note : new trackers were added to the existing torrent . " ) ) ; <nl> } <nl> <nl> void QBtSession : : mergeTorrents ( QTorrentHandle & h_ex , boost : : intrusive_ptr < torrent_info > t ) { <nl> - / / Check if the torrent contains trackers or url seeds we don ' t know about <nl> - / / and add them <nl> - if ( ! h_ex . is_valid ( ) ) return ; <nl> - std : : vector < announce_entry > existing_trackers = h_ex . trackers ( ) ; <nl> - std : : vector < announce_entry > new_trackers = t - > trackers ( ) ; <nl> - bool trackers_added = false ; <nl> - foreach ( const announce_entry & new_tracker , new_trackers ) { <nl> - std : : string new_tracker_url = new_tracker . url ; <nl> - / / Check if existing torrent has this tracker <nl> - bool found = false ; <nl> - foreach ( const announce_entry & existing_tracker , existing_trackers ) { <nl> - if ( QUrl ( new_tracker_url . c_str ( ) ) = = QUrl ( existing_tracker . url . c_str ( ) ) ) { <nl> - found = true ; <nl> - break ; <nl> - } <nl> - } <nl> + / / Check if the torrent contains trackers or url seeds we don ' t know about <nl> + / / and add them <nl> + if ( ! h_ex . is_valid ( ) ) return ; <nl> + std : : vector < announce_entry > existing_trackers = h_ex . trackers ( ) ; <nl> + std : : vector < announce_entry > new_trackers = t - > trackers ( ) ; <nl> + bool trackers_added = false ; <nl> + foreach ( const announce_entry & new_tracker , new_trackers ) { <nl> + std : : string new_tracker_url = new_tracker . url ; <nl> + / / Check if existing torrent has this tracker <nl> + bool found = false ; <nl> + foreach ( const announce_entry & existing_tracker , existing_trackers ) { <nl> + if ( QUrl ( new_tracker_url . c_str ( ) ) = = QUrl ( existing_tracker . url . c_str ( ) ) ) { <nl> + found = true ; <nl> + break ; <nl> + } <nl> + } <nl> <nl> - if ( ! found ) { <nl> - h_ex . add_tracker ( announce_entry ( new_tracker_url ) ) ; <nl> - trackers_added = true ; <nl> + if ( ! found ) { <nl> + h_ex . add_tracker ( announce_entry ( new_tracker_url ) ) ; <nl> + trackers_added = true ; <nl> + } <nl> } <nl> - } <nl> - <nl> - Logger * const logger = Logger : : instance ( ) ; <nl> - if ( trackers_added ) <nl> - logger - > addMessage ( tr ( " Note : new trackers were added to the existing torrent . " ) ) ; <nl> - <nl> - bool urlseeds_added = false ; <nl> - const QStringList old_urlseeds = h_ex . url_seeds ( ) ; <nl> - std : : vector < web_seed_entry > new_urlseeds = t - > web_seeds ( ) ; <nl> <nl> - std : : vector < web_seed_entry > : : iterator it = new_urlseeds . begin ( ) ; <nl> - std : : vector < web_seed_entry > : : iterator itend = new_urlseeds . end ( ) ; <nl> - for ( ; it ! = itend ; + + it ) { <nl> - const QString new_url = misc : : toQString ( it - > url . c_str ( ) ) ; <nl> - if ( ! old_urlseeds . contains ( new_url ) ) { <nl> - urlseeds_added = true ; <nl> - h_ex . add_url_seed ( new_url ) ; <nl> + Logger * const logger = Logger : : instance ( ) ; <nl> + if ( trackers_added ) <nl> + logger - > addMessage ( tr ( " Note : new trackers were added to the existing torrent . " ) ) ; <nl> + <nl> + bool urlseeds_added = false ; <nl> + const QStringList old_urlseeds = h_ex . url_seeds ( ) ; <nl> + std : : vector < web_seed_entry > new_urlseeds = t - > web_seeds ( ) ; <nl> + <nl> + std : : vector < web_seed_entry > : : iterator it = new_urlseeds . begin ( ) ; <nl> + std : : vector < web_seed_entry > : : iterator itend = new_urlseeds . end ( ) ; <nl> + for ( ; it ! = itend ; + + it ) { <nl> + const QString new_url = misc : : toQString ( it - > url . c_str ( ) ) ; <nl> + if ( ! old_urlseeds . contains ( new_url ) ) { <nl> + urlseeds_added = true ; <nl> + h_ex . add_url_seed ( new_url ) ; <nl> + } <nl> } <nl> - } <nl> - if ( urlseeds_added ) <nl> - logger - > addMessage ( tr ( " Note : new URL seeds were added to the existing torrent . " ) ) ; <nl> + if ( urlseeds_added ) <nl> + logger - > addMessage ( tr ( " Note : new URL seeds were added to the existing torrent . " ) ) ; <nl> } <nl> <nl> void QBtSession : : exportTorrentFiles ( QString path ) { <nl> - Q_ASSERT ( m_torrentExportEnabled ) ; <nl> - QDir exportDir ( path ) ; <nl> - if ( ! exportDir . exists ( ) ) { <nl> - if ( ! exportDir . mkpath ( exportDir . absolutePath ( ) ) ) { <nl> - std : : cerr < < " Error : Could not create torrent export directory : " < < qPrintable ( exportDir . absolutePath ( ) ) < < std : : endl ; <nl> - return ; <nl> - } <nl> - } <nl> - QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ; <nl> - std : : vector < torrent_handle > handles = s - > get_torrents ( ) ; <nl> - <nl> - std : : vector < torrent_handle > : : iterator itr = handles . begin ( ) ; <nl> - std : : vector < torrent_handle > : : iterator itrend = handles . end ( ) ; <nl> - for ( ; itr ! = itrend ; + + itr ) { <nl> - const QTorrentHandle h ( * itr ) ; <nl> - if ( ! h . is_valid ( ) ) { <nl> - std : : cerr < < " Torrent Export : torrent is invalid , skipping . . . " < < std : : endl ; <nl> - continue ; <nl> - } <nl> - const QString src_path ( torrentBackup . absoluteFilePath ( h . hash ( ) + " . torrent " ) ) ; <nl> - if ( QFile : : exists ( src_path ) ) { <nl> - QString dst_path = exportDir . absoluteFilePath ( h . name ( ) + " . torrent " ) ; <nl> - if ( QFile : : exists ( dst_path ) ) { <nl> - if ( ! fsutils : : sameFiles ( src_path , dst_path ) ) { <nl> - dst_path = exportDir . absoluteFilePath ( h . name ( ) + " - " + h . hash ( ) + " . torrent " ) ; <nl> + Q_ASSERT ( m_torrentExportEnabled ) ; <nl> + QDir exportDir ( path ) ; <nl> + if ( ! exportDir . exists ( ) ) { <nl> + if ( ! exportDir . mkpath ( exportDir . absolutePath ( ) ) ) { <nl> + std : : cerr < < " Error : Could not create torrent export directory : " < < qPrintable ( exportDir . absolutePath ( ) ) < < std : : endl ; <nl> + return ; <nl> + } <nl> + } <nl> + QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ; <nl> + std : : vector < torrent_handle > handles = s - > get_torrents ( ) ; <nl> + <nl> + std : : vector < torrent_handle > : : iterator itr = handles . begin ( ) ; <nl> + std : : vector < torrent_handle > : : iterator itrend = handles . end ( ) ; <nl> + for ( ; itr ! = itrend ; + + itr ) { <nl> + const QTorrentHandle h ( * itr ) ; <nl> + if ( ! h . is_valid ( ) ) { <nl> + std : : cerr < < " Torrent Export : torrent is invalid , skipping . . . " < < std : : endl ; <nl> + continue ; <nl> + } <nl> + const QString src_path ( torrentBackup . absoluteFilePath ( h . hash ( ) + " . torrent " ) ) ; <nl> + if ( QFile : : exists ( src_path ) ) { <nl> + QString dst_path = exportDir . absoluteFilePath ( h . name ( ) + " . torrent " ) ; <nl> + if ( QFile : : exists ( dst_path ) ) { <nl> + if ( ! fsutils : : sameFiles ( src_path , dst_path ) ) { <nl> + dst_path = exportDir . absoluteFilePath ( h . name ( ) + " - " + h . hash ( ) + " . torrent " ) ; <nl> + } else { <nl> + qDebug ( " Torrent Export : Destination file exists , skipping . . . " ) ; <nl> + continue ; <nl> + } <nl> + } <nl> + qDebug ( " Export Torrent : % s - > % s " , qPrintable ( src_path ) , qPrintable ( dst_path ) ) ; <nl> + QFile : : copy ( src_path , dst_path ) ; <nl> } else { <nl> - qDebug ( " Torrent Export : Destination file exists , skipping . . . " ) ; <nl> - continue ; <nl> + std : : cerr < < " Error : could not export torrent " < < qPrintable ( h . hash ( ) ) < < " , maybe it has not metadata yet . " < < std : : endl ; <nl> } <nl> - } <nl> - qDebug ( " Export Torrent : % s - > % s " , qPrintable ( src_path ) , qPrintable ( dst_path ) ) ; <nl> - QFile : : copy ( src_path , dst_path ) ; <nl> - } else { <nl> - std : : cerr < < " Error : could not export torrent " < < qPrintable ( h . hash ( ) ) < < " , maybe it has not metadata yet . " < < std : : endl ; <nl> } <nl> - } <nl> } <nl> <nl> void QBtSession : : setMaxConnectionsPerTorrent ( int max ) { <nl> - qDebug ( ) < < Q_FUNC_INFO < < max ; <nl> - / / Apply this to all session torrents <nl> - std : : vector < torrent_handle > handles = s - > get_torrents ( ) ; <nl> - <nl> - std : : vector < torrent_handle > : : const_iterator it = handles . begin ( ) ; <nl> - std : : vector < torrent_handle > : : const_iterator itend = handles . end ( ) ; <nl> - for ( ; it ! = itend ; + + it ) { <nl> - if ( ! it - > is_valid ( ) ) <nl> - continue ; <nl> - try { <nl> - it - > set_max_connections ( max ) ; <nl> - } catch ( std : : exception ) { } <nl> - } <nl> + qDebug ( ) < < Q_FUNC_INFO < < max ; <nl> + / / Apply this to all session torrents <nl> + std : : vector < torrent_handle > handles = s - > get_torrents ( ) ; <nl> + <nl> + std : : vector < torrent_handle > : : const_iterator it = handles . begin ( ) ; <nl> + std : : vector < torrent_handle > : : const_iterator itend = handles . end ( ) ; <nl> + for ( ; it ! = itend ; + + it ) { <nl> + if ( ! it - > is_valid ( ) ) <nl> + continue ; <nl> + try { <nl> + it - > set_max_connections ( max ) ; <nl> + } catch ( std : : exception ) { } <nl> + } <nl> } <nl> <nl> void QBtSession : : setMaxUploadsPerTorrent ( int max ) { <nl> - qDebug ( ) < < Q_FUNC_INFO < < max ; <nl> - / / Apply this to all session torrents <nl> - std : : vector < torrent_handle > handles = s - > get_torrents ( ) ; <nl> - <nl> - std : : vector < torrent_handle > : : const_iterator it = handles . begin ( ) ; <nl> - std : : vector < torrent_handle > : : const_iterator itend = handles . end ( ) ; <nl> - for ( ; it ! = itend ; + + it ) { <nl> - if ( ! it - > is_valid ( ) ) <nl> - continue ; <nl> - try { <nl> - it - > set_max_uploads ( max ) ; <nl> - } catch ( std : : exception ) { } <nl> - } <nl> + qDebug ( ) < < Q_FUNC_INFO < < max ; <nl> + / / Apply this to all session torrents <nl> + std : : vector < torrent_handle > handles = s - > get_torrents ( ) ; <nl> + <nl> + std : : vector < torrent_handle > : : const_iterator it = handles . begin ( ) ; <nl> + std : : vector < torrent_handle > : : const_iterator itend = handles . end ( ) ; <nl> + for ( ; it ! = itend ; + + it ) { <nl> + if ( ! it - > is_valid ( ) ) <nl> + continue ; <nl> + try { <nl> + it - > set_max_uploads ( max ) ; <nl> + } catch ( std : : exception ) { } <nl> + } <nl> } <nl> <nl> void QBtSession : : enableUPnP ( bool b ) { <nl> - Preferences * const pref = Preferences : : instance ( ) ; <nl> - if ( b ) { <nl> - qDebug ( " Enabling UPnP / NAT - PMP " ) ; <nl> + Preferences * const pref = Preferences : : instance ( ) ; <nl> + if ( b ) { <nl> + qDebug ( " Enabling UPnP / NAT - PMP " ) ; <nl> # if LIBTORRENT_VERSION_NUM < 10000 <nl> - m_upnp = s - > start_upnp ( ) ; <nl> - m_natpmp = s - > start_natpmp ( ) ; <nl> + m_upnp = s - > start_upnp ( ) ; <nl> + m_natpmp = s - > start_natpmp ( ) ; <nl> # else <nl> - s - > start_upnp ( ) ; <nl> - s - > start_natpmp ( ) ; <nl> + s - > start_upnp ( ) ; <nl> + s - > start_natpmp ( ) ; <nl> # endif <nl> - / / TODO : Remove dependency from WebUI <nl> - / / Use UPnP / NAT - PMP for Web UI too <nl> - if ( pref - > isWebUiEnabled ( ) & & pref - > useUPnPForWebUIPort ( ) ) { <nl> - const qint16 port = pref - > getWebUiPort ( ) ; <nl> + / / TODO : Remove dependency from WebUI <nl> + / / Use UPnP / NAT - PMP for Web UI too <nl> + if ( pref - > isWebUiEnabled ( ) & & pref - > useUPnPForWebUIPort ( ) ) { <nl> + const qint16 port = pref - > getWebUiPort ( ) ; <nl> # if LIBTORRENT_VERSION_NUM < 10000 <nl> - m_upnp - > add_mapping ( upnp : : tcp , port , port ) ; <nl> - m_natpmp - > add_mapping ( natpmp : : tcp , port , port ) ; <nl> + m_upnp - > add_mapping ( upnp : : tcp , port , port ) ; <nl> + m_natpmp - > add_mapping ( natpmp : : tcp , port , port ) ; <nl> # else <nl> - s - > add_port_mapping ( session : : tcp , port , port ) ; <nl> + s - > add_port_mapping ( session : : tcp , port , port ) ; <nl> # endif <nl> - } <nl> - } else { <nl> - qDebug ( " Disabling UPnP / NAT - PMP " ) ; <nl> - s - > stop_upnp ( ) ; <nl> - s - > stop_natpmp ( ) ; <nl> + } <nl> + } else { <nl> + qDebug ( " Disabling UPnP / NAT - PMP " ) ; <nl> + s - > stop_upnp ( ) ; <nl> + s - > stop_natpmp ( ) ; <nl> <nl> # if LIBTORRENT_VERSION_NUM < 10000 <nl> - m_upnp = 0 ; <nl> - m_natpmp = 0 ; <nl> + m_upnp = 0 ; <nl> + m_natpmp = 0 ; <nl> # endif <nl> - } <nl> + } <nl> } <nl> <nl> void QBtSession : : enableLSD ( bool b ) { <nl> - if ( b ) { <nl> - if ( ! LSDEnabled ) { <nl> - qDebug ( " Enabling Local Peer Discovery " ) ; <nl> - s - > start_lsd ( ) ; <nl> - LSDEnabled = true ; <nl> - } <nl> - } else { <nl> - if ( LSDEnabled ) { <nl> - qDebug ( " Disabling Local Peer Discovery " ) ; <nl> - s - > stop_lsd ( ) ; <nl> - LSDEnabled = false ; <nl> + if ( b ) { <nl> + if ( ! LSDEnabled ) { <nl> + qDebug ( " Enabling Local Peer Discovery " ) ; <nl> + s - > start_lsd ( ) ; <nl> + LSDEnabled = true ; <nl> + } <nl> + } else { <nl> + if ( LSDEnabled ) { <nl> + qDebug ( " Disabling Local Peer Discovery " ) ; <nl> + s - > stop_lsd ( ) ; <nl> + LSDEnabled = false ; <nl> + } <nl> } <nl> - } <nl> } <nl> <nl> void QBtSession : : loadSessionState ( ) { <nl> - const QString state_path = fsutils : : cacheLocation ( ) + " / " + QString : : fromUtf8 ( " ses_state " ) ; <nl> - if ( ! QFile : : exists ( state_path ) ) return ; <nl> - if ( QFile ( state_path ) . size ( ) = = 0 ) { <nl> - / / Remove empty invalid state file <nl> - fsutils : : forceRemove ( state_path ) ; <nl> - return ; <nl> - } <nl> - std : : vector < char > in ; <nl> - lazy_entry e ; <nl> - libtorrent : : error_code ec ; <nl> - misc : : loadBencodedFile ( state_path , in , e , ec ) ; <nl> - if ( ! ec ) <nl> - s - > load_state ( e ) ; <nl> + const QString state_path = fsutils : : cacheLocation ( ) + " / " + QString : : fromUtf8 ( " ses_state " ) ; <nl> + if ( ! QFile : : exists ( state_path ) ) return ; <nl> + if ( QFile ( state_path ) . size ( ) = = 0 ) { <nl> + / / Remove empty invalid state file <nl> + fsutils : : forceRemove ( state_path ) ; <nl> + return ; <nl> + } <nl> + std : : vector < char > in ; <nl> + lazy_entry e ; <nl> + libtorrent : : error_code ec ; <nl> + misc : : loadBencodedFile ( state_path , in , e , ec ) ; <nl> + if ( ! ec ) <nl> + s - > load_state ( e ) ; <nl> } <nl> <nl> void QBtSession : : saveSessionState ( ) { <nl> - qDebug ( " Saving session state to disk . . . " ) ; <nl> - const QString state_path = fsutils : : cacheLocation ( ) + " / " + QString : : fromUtf8 ( " ses_state " ) ; <nl> - entry session_state ; <nl> - s - > save_state ( session_state ) ; <nl> - vector < char > out ; <nl> - bencode ( back_inserter ( out ) , session_state ) ; <nl> - QFile session_file ( state_path ) ; <nl> - if ( ! out . empty ( ) & & session_file . open ( QIODevice : : WriteOnly ) ) { <nl> - session_file . write ( & out [ 0 ] , out . size ( ) ) ; <nl> - session_file . close ( ) ; <nl> - } <nl> + qDebug ( " Saving session state to disk . . . " ) ; <nl> + const QString state_path = fsutils : : cacheLocation ( ) + " / " + QString : : fromUtf8 ( " ses_state " ) ; <nl> + entry session_state ; <nl> + s - > save_state ( session_state ) ; <nl> + vector < char > out ; <nl> + bencode ( back_inserter ( out ) , session_state ) ; <nl> + QFile session_file ( state_path ) ; <nl> + if ( ! out . empty ( ) & & session_file . open ( QIODevice : : WriteOnly ) ) { <nl> + session_file . write ( & out [ 0 ] , out . size ( ) ) ; <nl> + session_file . close ( ) ; <nl> + } <nl> } <nl> <nl> / / Enable DHT <nl> void QBtSession : : enableDHT ( bool b ) { <nl> - Logger * const logger = Logger : : instance ( ) ; <nl> - if ( b ) { <nl> - if ( ! DHTEnabled ) { <nl> - try { <nl> - qDebug ( ) < < " Starting DHT . . . " ; <nl> - Q_ASSERT ( ! s - > is_dht_running ( ) ) ; <nl> - s - > start_dht ( ) ; <nl> - s - > add_dht_router ( std : : make_pair ( std : : string ( " router . bittorrent . com " ) , 6881 ) ) ; <nl> - s - > add_dht_router ( std : : make_pair ( std : : string ( " router . utorrent . com " ) , 6881 ) ) ; <nl> - s - > add_dht_router ( std : : make_pair ( std : : string ( " dht . transmissionbt . com " ) , 6881 ) ) ; <nl> - s - > add_dht_router ( std : : make_pair ( std : : string ( " dht . aelitis . com " ) , 6881 ) ) ; / / Vuze <nl> - DHTEnabled = true ; <nl> - logger - > addMessage ( tr ( " DHT support [ ON ] " ) , Log : : INFO ) ; <nl> - qDebug ( " DHT enabled " ) ; <nl> - } <nl> - catch ( std : : exception & e ) { <nl> - qDebug ( " Could not enable DHT , reason : % s " , e . what ( ) ) ; <nl> - logger - > addMessage ( tr ( " DHT support [ OFF ] . Reason : % 1 " ) . arg ( misc : : toQStringU ( e . what ( ) ) ) , Log : : CRITICAL ) ; <nl> - } <nl> + Logger * const logger = Logger : : instance ( ) ; <nl> + if ( b ) { <nl> + if ( ! DHTEnabled ) { <nl> + try { <nl> + qDebug ( ) < < " Starting DHT . . . " ; <nl> + Q_ASSERT ( ! s - > is_dht_running ( ) ) ; <nl> + s - > start_dht ( ) ; <nl> + s - > add_dht_router ( std : : make_pair ( std : : string ( " router . bittorrent . com " ) , 6881 ) ) ; <nl> + s - > add_dht_router ( std : : make_pair ( std : : string ( " router . utorrent . com " ) , 6881 ) ) ; <nl> + s - > add_dht_router ( std : : make_pair ( std : : string ( " dht . transmissionbt . com " ) , 6881 ) ) ; <nl> + s - > add_dht_router ( std : : make_pair ( std : : string ( " dht . aelitis . com " ) , 6881 ) ) ; / / Vuze <nl> + DHTEnabled = true ; <nl> + logger - > addMessage ( tr ( " DHT support [ ON ] " ) , Log : : INFO ) ; <nl> + qDebug ( " DHT enabled " ) ; <nl> + } <nl> + catch ( std : : exception & e ) { <nl> + qDebug ( " Could not enable DHT , reason : % s " , e . what ( ) ) ; <nl> + logger - > addMessage ( tr ( " DHT support [ OFF ] . Reason : % 1 " ) . arg ( misc : : toQStringU ( e . what ( ) ) ) , Log : : CRITICAL ) ; <nl> + } <nl> + } <nl> } <nl> - } <nl> - else { <nl> - if ( DHTEnabled ) { <nl> - DHTEnabled = false ; <nl> - s - > stop_dht ( ) ; <nl> - logger - > addMessage ( tr ( " DHT support [ OFF ] " ) , Log : : INFO ) ; <nl> - qDebug ( " DHT disabled " ) ; <nl> + else { <nl> + if ( DHTEnabled ) { <nl> + DHTEnabled = false ; <nl> + s - > stop_dht ( ) ; <nl> + logger - > addMessage ( tr ( " DHT support [ OFF ] " ) , Log : : INFO ) ; <nl> + qDebug ( " DHT disabled " ) ; <nl> + } <nl> } <nl> - } <nl> } <nl> <nl> qreal QBtSession : : getRealRatio ( const libtorrent : : torrent_status & status ) const { <nl> - libtorrent : : size_type all_time_upload = status . all_time_upload ; <nl> - libtorrent : : size_type all_time_download = status . all_time_download ; <nl> - libtorrent : : size_type total_done = status . total_done ; <nl> - <nl> - if ( all_time_download < total_done ) { <nl> - / / We have more data on disk than we downloaded <nl> - / / either because the user imported the file <nl> - / / or because of crash the download histroy was lost . <nl> - / / Otherwise will get weird ratios <nl> - / / eg when downloaded 1KB and uploaded 700MB of a <nl> - / / 700MB torrent . <nl> - all_time_download = total_done ; <nl> - } <nl> - <nl> - if ( all_time_download = = 0 ) { <nl> - if ( all_time_upload = = 0 ) <nl> - return 0 . 0 ; <nl> - return MAX_RATIO + 1 ; <nl> - } <nl> - <nl> - qreal ratio = all_time_upload / ( float ) all_time_download ; <nl> - Q_ASSERT ( ratio > = 0 . ) ; <nl> - if ( ratio > MAX_RATIO ) <nl> - ratio = MAX_RATIO ; <nl> - return ratio ; <nl> + libtorrent : : size_type all_time_upload = status . all_time_upload ; <nl> + libtorrent : : size_type all_time_download = status . all_time_download ; <nl> + libtorrent : : size_type total_done = status . total_done ; <nl> + <nl> + if ( all_time_download < total_done ) { <nl> + / / We have more data on disk than we downloaded <nl> + / / either because the user imported the file <nl> + / / or because of crash the download histroy was lost . <nl> + / / Otherwise will get weird ratios <nl> + / / eg when downloaded 1KB and uploaded 700MB of a <nl> + / / 700MB torrent . <nl> + all_time_download = total_done ; <nl> + } <nl> + <nl> + if ( all_time_download = = 0 ) { <nl> + if ( all_time_upload = = 0 ) <nl> + return 0 . 0 ; <nl> + return MAX_RATIO + 1 ; <nl> + } <nl> + <nl> + qreal ratio = all_time_upload / ( float ) all_time_download ; <nl> + Q_ASSERT ( ratio > = 0 . ) ; <nl> + if ( ratio > MAX_RATIO ) <nl> + ratio = MAX_RATIO ; <nl> + return ratio ; <nl> } <nl> <nl> / / Called periodically <nl> void QBtSession : : saveTempFastResumeData ( ) { <nl> - std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> + std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> <nl> - std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> - std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> - for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> - QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> - try { <nl> - if ( ! h . is_valid ( ) | | ! h . has_metadata ( ) / * | | h . is_seed ( ) | | h . is_paused ( ) * / ) continue ; <nl> - if ( ! h . need_save_resume_data ( ) ) continue ; <nl> - if ( h . state ( ) = = torrent_status : : checking_files | | h . state ( ) = = torrent_status : : queued_for_checking | | h . has_error ( ) <nl> - | | TorrentPersistentData : : instance ( ) - > getHasMissingFiles ( h . hash ( ) ) ) continue ; <nl> - qDebug ( " Saving fastresume data for % s " , qPrintable ( h . name ( ) ) ) ; <nl> - h . save_resume_data ( ) ; <nl> - } catch ( std : : exception & e ) { } <nl> - } <nl> + std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> + std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> + for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> + QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> + try { <nl> + if ( ! h . is_valid ( ) | | ! h . has_metadata ( ) / * | | h . is_seed ( ) | | h . is_paused ( ) * / ) continue ; <nl> + if ( ! h . need_save_resume_data ( ) ) continue ; <nl> + if ( h . state ( ) = = torrent_status : : checking_files | | h . state ( ) = = torrent_status : : queued_for_checking | | h . has_error ( ) <nl> + | | TorrentPersistentData : : instance ( ) - > getHasMissingFiles ( h . hash ( ) ) ) continue ; <nl> + qDebug ( " Saving fastresume data for % s " , qPrintable ( h . name ( ) ) ) ; <nl> + h . save_resume_data ( ) ; <nl> + } catch ( std : : exception & e ) { } <nl> + } <nl> } <nl> <nl> / / Only save fast resume data for unfinished and unpaused torrents ( Optimization ) <nl> / / Called on exit <nl> void QBtSession : : saveFastResumeData ( ) { <nl> - qDebug ( " Saving fast resume data . . . " ) ; <nl> - / / Stop listening for alerts <nl> - resumeDataTimer . stop ( ) ; <nl> - int num_resume_data = 0 ; <nl> - / / Pause session <nl> - s - > pause ( ) ; <nl> - std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> - <nl> - std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> - std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> - for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> - QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> - if ( ! h . is_valid ( ) ) <nl> - continue ; <nl> - try { <nl> - if ( isQueueingEnabled ( ) ) <nl> - TorrentPersistentData : : instance ( ) - > savePriority ( h ) ; <nl> - if ( ! h . has_metadata ( ) ) <nl> - continue ; <nl> - / / Actually with should save fast resume data for paused files too <nl> - / / if ( h . is_paused ( ) ) continue ; <nl> - if ( h . state ( ) = = torrent_status : : checking_files | | h . state ( ) = = torrent_status : : queued_for_checking | | h . has_error ( ) ) continue ; <nl> - if ( TorrentPersistentData : : instance ( ) - > getHasMissingFiles ( h . hash ( ) ) ) { <nl> - TorrentPersistentData : : instance ( ) - > setHasMissingFiles ( h . hash ( ) , false ) ; <nl> - continue ; <nl> - } <nl> - h . save_resume_data ( ) ; <nl> - + + num_resume_data ; <nl> - } catch ( libtorrent : : invalid_handle & ) { } <nl> - } <nl> - while ( num_resume_data > 0 ) { <nl> - std : : vector < alert * > alerts ; <nl> - m_alertDispatcher - > getPendingAlerts ( alerts , 30 * 1000 ) ; <nl> - if ( alerts . empty ( ) ) { <nl> - std : : cerr < < " aborting with " < < num_resume_data < < " outstanding " <nl> - " torrents to save resume data for " < < std : : endl ; <nl> - break ; <nl> - } <nl> - <nl> - for ( std : : vector < alert * > : : const_iterator i = alerts . begin ( ) , end = alerts . end ( ) ; i ! = end ; + + i ) <nl> - { <nl> - alert const * a = * i ; <nl> - / / Saving fastresume data can fail <nl> - save_resume_data_failed_alert const * rda = dynamic_cast < save_resume_data_failed_alert const * > ( a ) ; <nl> - if ( rda ) { <nl> - - - num_resume_data ; <nl> + qDebug ( " Saving fast resume data . . . " ) ; <nl> + / / Stop listening for alerts <nl> + resumeDataTimer . stop ( ) ; <nl> + int num_resume_data = 0 ; <nl> + / / Pause session <nl> + s - > pause ( ) ; <nl> + std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> + <nl> + std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> + std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> + for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> + QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> + if ( ! h . is_valid ( ) ) <nl> + continue ; <nl> try { <nl> - / / Remove torrent from session <nl> - if ( rda - > handle . is_valid ( ) ) <nl> - s - > remove_torrent ( rda - > handle ) ; <nl> - } catch ( libtorrent : : libtorrent_exception ) { } <nl> - delete a ; <nl> - continue ; <nl> - } <nl> - save_resume_data_alert const * rd = dynamic_cast < save_resume_data_alert const * > ( a ) ; <nl> - if ( ! rd ) { <nl> - delete a ; <nl> - continue ; <nl> - } <nl> - / / Saving fast resume data was successful <nl> - - - num_resume_data ; <nl> - if ( ! rd - > resume_data ) { <nl> - delete a ; <nl> - continue ; <nl> - } <nl> - QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ; <nl> - const QTorrentHandle h ( rd - > handle ) ; <nl> - if ( ! h . is_valid ( ) ) { <nl> - delete a ; <nl> - continue ; <nl> - } <nl> - try { <nl> - / / Remove old fastresume file if it exists <nl> - backupPersistentData ( h . hash ( ) , rd - > resume_data ) ; <nl> - vector < char > out ; <nl> - bencode ( back_inserter ( out ) , * rd - > resume_data ) ; <nl> - const QString filepath = torrentBackup . absoluteFilePath ( h . hash ( ) + " . fastresume " ) ; <nl> - QFile resume_file ( filepath ) ; <nl> - if ( resume_file . exists ( ) ) <nl> - fsutils : : forceRemove ( filepath ) ; <nl> - if ( ! out . empty ( ) & & resume_file . open ( QIODevice : : WriteOnly ) ) { <nl> - resume_file . write ( & out [ 0 ] , out . size ( ) ) ; <nl> - resume_file . close ( ) ; <nl> + if ( isQueueingEnabled ( ) ) <nl> + TorrentPersistentData : : instance ( ) - > savePriority ( h ) ; <nl> + if ( ! h . has_metadata ( ) ) <nl> + continue ; <nl> + / / Actually with should save fast resume data for paused files too <nl> + / / if ( h . is_paused ( ) ) continue ; <nl> + if ( h . state ( ) = = torrent_status : : checking_files | | h . state ( ) = = torrent_status : : queued_for_checking | | h . has_error ( ) ) continue ; <nl> + if ( TorrentPersistentData : : instance ( ) - > getHasMissingFiles ( h . hash ( ) ) ) { <nl> + TorrentPersistentData : : instance ( ) - > setHasMissingFiles ( h . hash ( ) , false ) ; <nl> + continue ; <nl> + } <nl> + h . save_resume_data ( ) ; <nl> + + + num_resume_data ; <nl> + } catch ( libtorrent : : invalid_handle & ) { } <nl> + } <nl> + while ( num_resume_data > 0 ) { <nl> + std : : vector < alert * > alerts ; <nl> + m_alertDispatcher - > getPendingAlerts ( alerts , 30 * 1000 ) ; <nl> + if ( alerts . empty ( ) ) { <nl> + std : : cerr < < " aborting with " < < num_resume_data < < " outstanding " <nl> + " torrents to save resume data for " < < std : : endl ; <nl> + break ; <nl> } <nl> - / / Remove torrent from session <nl> - s - > remove_torrent ( rd - > handle ) ; <nl> - } catch ( libtorrent : : invalid_handle & ) { } <nl> <nl> - delete a ; <nl> + for ( std : : vector < alert * > : : const_iterator i = alerts . begin ( ) , end = alerts . end ( ) ; i ! = end ; + + i ) <nl> + { <nl> + alert const * a = * i ; <nl> + / / Saving fastresume data can fail <nl> + save_resume_data_failed_alert const * rda = dynamic_cast < save_resume_data_failed_alert const * > ( a ) ; <nl> + if ( rda ) { <nl> + - - num_resume_data ; <nl> + try { <nl> + / / Remove torrent from session <nl> + if ( rda - > handle . is_valid ( ) ) <nl> + s - > remove_torrent ( rda - > handle ) ; <nl> + } catch ( libtorrent : : libtorrent_exception ) { } <nl> + delete a ; <nl> + continue ; <nl> + } <nl> + save_resume_data_alert const * rd = dynamic_cast < save_resume_data_alert const * > ( a ) ; <nl> + if ( ! rd ) { <nl> + delete a ; <nl> + continue ; <nl> + } <nl> + / / Saving fast resume data was successful <nl> + - - num_resume_data ; <nl> + if ( ! rd - > resume_data ) { <nl> + delete a ; <nl> + continue ; <nl> + } <nl> + QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ; <nl> + const QTorrentHandle h ( rd - > handle ) ; <nl> + if ( ! h . is_valid ( ) ) { <nl> + delete a ; <nl> + continue ; <nl> + } <nl> + try { <nl> + / / Remove old fastresume file if it exists <nl> + backupPersistentData ( h . hash ( ) , rd - > resume_data ) ; <nl> + vector < char > out ; <nl> + bencode ( back_inserter ( out ) , * rd - > resume_data ) ; <nl> + const QString filepath = torrentBackup . absoluteFilePath ( h . hash ( ) + " . fastresume " ) ; <nl> + QFile resume_file ( filepath ) ; <nl> + if ( resume_file . exists ( ) ) <nl> + fsutils : : forceRemove ( filepath ) ; <nl> + if ( ! out . empty ( ) & & resume_file . open ( QIODevice : : WriteOnly ) ) { <nl> + resume_file . write ( & out [ 0 ] , out . size ( ) ) ; <nl> + resume_file . close ( ) ; <nl> + } <nl> + / / Remove torrent from session <nl> + s - > remove_torrent ( rd - > handle ) ; <nl> + } catch ( libtorrent : : invalid_handle & ) { } <nl> + <nl> + delete a ; <nl> + } <nl> } <nl> - } <nl> } <nl> <nl> bool QBtSession : : isFilePreviewPossible ( const QString & hash ) const { <nl> - / / See if there are supported files in the torrent <nl> - const QTorrentHandle h = getTorrentHandle ( hash ) ; <nl> - if ( ! h . is_valid ( ) | | ! h . has_metadata ( ) ) { <nl> + / / See if there are supported files in the torrent <nl> + const QTorrentHandle h = getTorrentHandle ( hash ) ; <nl> + if ( ! h . is_valid ( ) | | ! h . has_metadata ( ) ) { <nl> + return false ; <nl> + } <nl> + const unsigned int nbFiles = h . num_files ( ) ; <nl> + for ( unsigned int i = 0 ; i < nbFiles ; + + i ) { <nl> + const QString extension = fsutils : : fileExtension ( h . filename_at ( i ) ) ; <nl> + if ( misc : : isPreviewable ( extension ) ) <nl> + return true ; <nl> + } <nl> return false ; <nl> - } <nl> - const unsigned int nbFiles = h . num_files ( ) ; <nl> - for ( unsigned int i = 0 ; i < nbFiles ; + + i ) { <nl> - const QString extension = fsutils : : fileExtension ( h . filename_at ( i ) ) ; <nl> - if ( misc : : isPreviewable ( extension ) ) <nl> - return true ; <nl> - } <nl> - return false ; <nl> } <nl> <nl> void QBtSession : : addTorrentsFromScanFolder ( QStringList & pathList ) <nl> void QBtSession : : addTorrentsFromScanFolder ( QStringList & pathList ) <nl> } <nl> <nl> void QBtSession : : setDefaultSavePath ( const QString & savepath ) { <nl> - if ( savepath . isEmpty ( ) ) <nl> - return ; <nl> + if ( savepath . isEmpty ( ) ) <nl> + return ; <nl> <nl> - defaultSavePath = fsutils : : fromNativePath ( savepath ) ; <nl> + defaultSavePath = fsutils : : fromNativePath ( savepath ) ; <nl> } <nl> <nl> void QBtSession : : setDefaultTempPath ( const QString & temppath ) { <nl> - if ( QDir ( defaultTempPath ) = = QDir ( temppath ) ) <nl> - return ; <nl> - <nl> - if ( temppath . isEmpty ( ) ) { <nl> - / / Disabling temp dir <nl> - / / Moving all torrents to their destination folder <nl> - std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> - <nl> - std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> - std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> - for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> - QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> - if ( ! h . is_valid ( ) ) continue ; <nl> - h . move_storage ( getSavePath ( h . hash ( ) ) ) ; <nl> - } <nl> - } else { <nl> - qDebug ( " Enabling default temp path . . . " ) ; <nl> - / / Moving all downloading torrents to temporary save path <nl> - std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> - <nl> - std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> - std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> - for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> - QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> - if ( ! h . is_valid ( ) ) continue ; <nl> - if ( ! h . is_seed ( ) ) { <nl> - qDebug ( " Moving torrent to its temp save path : % s " , qPrintable ( temppath ) ) ; <nl> - h . move_storage ( temppath ) ; <nl> - } <nl> + if ( QDir ( defaultTempPath ) = = QDir ( temppath ) ) <nl> + return ; <nl> + <nl> + if ( temppath . isEmpty ( ) ) { <nl> + / / Disabling temp dir <nl> + / / Moving all torrents to their destination folder <nl> + std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> + <nl> + std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> + std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> + for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> + QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> + if ( ! h . is_valid ( ) ) continue ; <nl> + h . move_storage ( getSavePath ( h . hash ( ) ) ) ; <nl> + } <nl> + } else { <nl> + qDebug ( " Enabling default temp path . . . " ) ; <nl> + / / Moving all downloading torrents to temporary save path <nl> + std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> + <nl> + std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> + std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> + for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> + QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> + if ( ! h . is_valid ( ) ) continue ; <nl> + if ( ! h . is_seed ( ) ) { <nl> + qDebug ( " Moving torrent to its temp save path : % s " , qPrintable ( temppath ) ) ; <nl> + h . move_storage ( temppath ) ; <nl> + } <nl> + } <nl> } <nl> - } <nl> - defaultTempPath = fsutils : : fromNativePath ( temppath ) ; <nl> + defaultTempPath = fsutils : : fromNativePath ( temppath ) ; <nl> } <nl> <nl> void QBtSession : : appendqBextensionToTorrent ( const QTorrentHandle & h , bool append ) { <nl> - if ( ! h . is_valid ( ) | | ! h . has_metadata ( ) ) return ; <nl> - std : : vector < size_type > fp ; <nl> - h . file_progress ( fp ) ; <nl> - for ( int i = 0 ; i < h . num_files ( ) ; + + i ) { <nl> - if ( append ) { <nl> - const qulonglong file_size = h . filesize_at ( i ) ; <nl> - if ( file_size > 0 & & ( fp [ i ] / ( double ) file_size ) < 1 . ) { <nl> - const QString name = h . filepath_at ( i ) ; <nl> - if ( ! name . endsWith ( " . ! qB " ) ) { <nl> - const QString new_name = name + " . ! qB " ; <nl> - qDebug ( " Renaming % s to % s " , qPrintable ( name ) , qPrintable ( new_name ) ) ; <nl> - h . rename_file ( i , new_name ) ; <nl> + if ( ! h . is_valid ( ) | | ! h . has_metadata ( ) ) return ; <nl> + std : : vector < size_type > fp ; <nl> + h . file_progress ( fp ) ; <nl> + for ( int i = 0 ; i < h . num_files ( ) ; + + i ) { <nl> + if ( append ) { <nl> + const qulonglong file_size = h . filesize_at ( i ) ; <nl> + if ( file_size > 0 & & ( fp [ i ] / ( double ) file_size ) < 1 . ) { <nl> + const QString name = h . filepath_at ( i ) ; <nl> + if ( ! name . endsWith ( " . ! qB " ) ) { <nl> + const QString new_name = name + " . ! qB " ; <nl> + qDebug ( " Renaming % s to % s " , qPrintable ( name ) , qPrintable ( new_name ) ) ; <nl> + h . rename_file ( i , new_name ) ; <nl> + } <nl> + } <nl> + } else { <nl> + QString name = h . filepath_at ( i ) ; <nl> + if ( name . endsWith ( " . ! qB " ) ) { <nl> + const QString old_name = name ; <nl> + name . chop ( 4 ) ; <nl> + qDebug ( " Renaming % s to % s " , qPrintable ( old_name ) , qPrintable ( name ) ) ; <nl> + h . rename_file ( i , name ) ; <nl> + } <nl> } <nl> - } <nl> - } else { <nl> - QString name = h . filepath_at ( i ) ; <nl> - if ( name . endsWith ( " . ! qB " ) ) { <nl> - const QString old_name = name ; <nl> - name . chop ( 4 ) ; <nl> - qDebug ( " Renaming % s to % s " , qPrintable ( old_name ) , qPrintable ( name ) ) ; <nl> - h . rename_file ( i , name ) ; <nl> - } <nl> } <nl> - } <nl> } <nl> <nl> void QBtSession : : changeLabelInTorrentSavePath ( const QTorrentHandle & h , QString old_label , QString new_label ) { <nl> - if ( ! h . is_valid ( ) ) return ; <nl> - if ( ! appendLabelToSavePath ) return ; <nl> - QString old_save_path = fsutils : : fromNativePath ( TorrentPersistentData : : instance ( ) - > getSavePath ( h . hash ( ) ) ) ; <nl> - if ( ! old_save_path . startsWith ( defaultSavePath ) ) return ; <nl> - QString new_save_path = fsutils : : updateLabelInSavePath ( defaultSavePath , old_save_path , old_label , new_label ) ; <nl> - if ( new_save_path ! = old_save_path ) { <nl> - / / Move storage <nl> - qDebug ( " Moving storage to % s " , qPrintable ( new_save_path ) ) ; <nl> - QDir ( ) . mkpath ( new_save_path ) ; <nl> - h . move_storage ( new_save_path ) ; <nl> - } <nl> + if ( ! h . is_valid ( ) ) return ; <nl> + if ( ! appendLabelToSavePath ) return ; <nl> + QString old_save_path = fsutils : : fromNativePath ( TorrentPersistentData : : instance ( ) - > getSavePath ( h . hash ( ) ) ) ; <nl> + if ( ! old_save_path . startsWith ( defaultSavePath ) ) return ; <nl> + QString new_save_path = fsutils : : updateLabelInSavePath ( defaultSavePath , old_save_path , old_label , new_label ) ; <nl> + if ( new_save_path ! = old_save_path ) { <nl> + / / Move storage <nl> + qDebug ( " Moving storage to % s " , qPrintable ( new_save_path ) ) ; <nl> + QDir ( ) . mkpath ( new_save_path ) ; <nl> + h . move_storage ( new_save_path ) ; <nl> + } <nl> } <nl> <nl> void QBtSession : : appendLabelToTorrentSavePath ( const QTorrentHandle & h ) { <nl> - if ( ! h . is_valid ( ) ) return ; <nl> - const TorrentPersistentData * const TorPersistent = TorrentPersistentData : : instance ( ) ; <nl> - const QString label = TorPersistent - > getLabel ( h . hash ( ) ) ; <nl> - if ( label . isEmpty ( ) ) return ; <nl> - / / Current save path <nl> - QString old_save_path = fsutils : : fromNativePath ( TorPersistent - > getSavePath ( h . hash ( ) ) ) ; <nl> - QString new_save_path = fsutils : : updateLabelInSavePath ( defaultSavePath , old_save_path , " " , label ) ; <nl> - if ( old_save_path ! = new_save_path ) { <nl> - / / Move storage <nl> - QDir ( ) . mkpath ( new_save_path ) ; <nl> - h . move_storage ( new_save_path ) ; <nl> - } <nl> + if ( ! h . is_valid ( ) ) return ; <nl> + const TorrentPersistentData * const TorPersistent = TorrentPersistentData : : instance ( ) ; <nl> + const QString label = TorPersistent - > getLabel ( h . hash ( ) ) ; <nl> + if ( label . isEmpty ( ) ) return ; <nl> + / / Current save path <nl> + QString old_save_path = fsutils : : fromNativePath ( TorPersistent - > getSavePath ( h . hash ( ) ) ) ; <nl> + QString new_save_path = fsutils : : updateLabelInSavePath ( defaultSavePath , old_save_path , " " , label ) ; <nl> + if ( old_save_path ! = new_save_path ) { <nl> + / / Move storage <nl> + QDir ( ) . mkpath ( new_save_path ) ; <nl> + h . move_storage ( new_save_path ) ; <nl> + } <nl> } <nl> <nl> void QBtSession : : setAppendLabelToSavePath ( bool append ) { <nl> - if ( appendLabelToSavePath ! = append ) { <nl> - appendLabelToSavePath = ! appendLabelToSavePath ; <nl> - if ( appendLabelToSavePath ) { <nl> - / / Move torrents storage to sub folder with label name <nl> - std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> - <nl> - std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> - std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> - for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> - QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> - appendLabelToTorrentSavePath ( h ) ; <nl> - } <nl> + if ( appendLabelToSavePath ! = append ) { <nl> + appendLabelToSavePath = ! appendLabelToSavePath ; <nl> + if ( appendLabelToSavePath ) { <nl> + / / Move torrents storage to sub folder with label name <nl> + std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> + <nl> + std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> + std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> + for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> + QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> + appendLabelToTorrentSavePath ( h ) ; <nl> + } <nl> + } <nl> } <nl> - } <nl> } <nl> <nl> void QBtSession : : setAppendqBExtension ( bool append ) { <nl> - if ( appendqBExtension ! = append ) { <nl> - appendqBExtension = ! appendqBExtension ; <nl> - / / append or remove . ! qB extension for incomplete files <nl> - std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> - <nl> - std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> - std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> - for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> - QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> - appendqBextensionToTorrent ( h , appendqBExtension ) ; <nl> + if ( appendqBExtension ! = append ) { <nl> + appendqBExtension = ! appendqBExtension ; <nl> + / / append or remove . ! qB extension for incomplete files <nl> + std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> + <nl> + std : : vector < torrent_handle > : : iterator torrentIT = torrents . begin ( ) ; <nl> + std : : vector < torrent_handle > : : iterator torrentITend = torrents . end ( ) ; <nl> + for ( ; torrentIT ! = torrentITend ; + + torrentIT ) { <nl> + QTorrentHandle h = QTorrentHandle ( * torrentIT ) ; <nl> + appendqBextensionToTorrent ( h , appendqBExtension ) ; <nl> + } <nl> } <nl> - } <nl> } <nl> <nl> / / Set the ports range in which is chosen the port the Bittorrent <nl> / / session will listen to <nl> void QBtSession : : setListeningPort ( int port ) { <nl> - qDebug ( ) < < Q_FUNC_INFO < < port ; <nl> - Preferences * const pref = Preferences : : instance ( ) ; <nl> - Logger * const logger = Logger : : instance ( ) ; <nl> - std : : pair < int , int > ports ( port , port ) ; <nl> - libtorrent : : error_code ec ; <nl> - const QString iface_name = pref - > getNetworkInterface ( ) ; <nl> - const bool listen_ipv6 = pref - > getListenIPv6 ( ) ; <nl> - if ( iface_name . isEmpty ( ) ) { <nl> - logger - > addMessage ( tr ( " qBittorrent is trying to listen on any interface port : % 1 " , " e . g : qBittorrent is trying to listen on any interface port : TCP / 6881 " ) . arg ( QString : : number ( port ) ) , Log : : INFO ) ; <nl> - if ( listen_ipv6 ) <nl> - s - > listen_on ( ports , ec , " : : " , session : : listen_no_system_port ) ; <nl> - else <nl> - s - > listen_on ( ports , ec , " 0 . 0 . 0 . 0 " , session : : listen_no_system_port ) ; <nl> - <nl> - if ( ec ) <nl> - logger - > addMessage ( tr ( " qBittorrent failed to listen on any interface port : % 1 . Reason : % 2 " , " e . g : qBittorrent failed to listen on any interface port : TCP / 6881 . Reason : no such interface " ) . arg ( QString : : number ( port ) ) . arg ( misc : : toQStringU ( ec . message ( ) ) ) , Log : : CRITICAL ) ; <nl> - <nl> - return ; <nl> - } <nl> - / / Attempt to listen on provided interface <nl> - const QNetworkInterface network_iface = QNetworkInterface : : interfaceFromName ( iface_name ) ; <nl> - if ( ! network_iface . isValid ( ) ) { <nl> - qDebug ( " Invalid network interface : % s " , qPrintable ( iface_name ) ) ; <nl> - logger - > addMessage ( tr ( " The network interface defined is invalid : % 1 " ) . arg ( iface_name ) , Log : : CRITICAL ) ; <nl> - return ; <nl> - } <nl> - QString ip ; <nl> - qDebug ( " This network interface has % d IP addresses " , network_iface . addressEntries ( ) . size ( ) ) ; <nl> - foreach ( const QNetworkAddressEntry & entry , network_iface . addressEntries ( ) ) { <nl> - if ( ( ! listen_ipv6 & & ( entry . ip ( ) . protocol ( ) = = QAbstractSocket : : IPv6Protocol ) ) <nl> - | | ( listen_ipv6 & & ( entry . ip ( ) . protocol ( ) = = QAbstractSocket : : IPv4Protocol ) ) ) <nl> - continue ; <nl> - qDebug ( " Trying to listen on IP % s ( % s ) " , qPrintable ( entry . ip ( ) . toString ( ) ) , qPrintable ( iface_name ) ) ; <nl> - s - > listen_on ( ports , ec , entry . ip ( ) . toString ( ) . toLatin1 ( ) . constData ( ) , session : : listen_no_system_port ) ; <nl> - if ( ! ec ) { <nl> - ip = entry . ip ( ) . toString ( ) ; <nl> - logger - > addMessage ( tr ( " qBittorrent is trying to listen on interface % 1 port : % 2 " , " e . g : qBittorrent is trying to listen on interface 192 . 168 . 0 . 1 port : TCP / 6881 " ) . arg ( ip ) . arg ( QString : : number ( port ) ) , Log : : INFO ) ; <nl> - return ; <nl> - } <nl> - } <nl> - logger - > addMessage ( tr ( " qBittorrent didn ' t find an % 1 local address to listen on " , " qBittorrent didn ' t find an IPv4 local address to listen on " ) . arg ( listen_ipv6 ? " IPv6 " : " IPv4 " ) , Log : : CRITICAL ) ; <nl> + qDebug ( ) < < Q_FUNC_INFO < < port ; <nl> + Preferences * const pref = Preferences : : instance ( ) ; <nl> + Logger * const logger = Logger : : instance ( ) ; <nl> + std : : pair < int , int > ports ( port , port ) ; <nl> + libtorrent : : error_code ec ; <nl> + const QString iface_name = pref - > getNetworkInterface ( ) ; <nl> + const bool listen_ipv6 = pref - > getListenIPv6 ( ) ; <nl> + if ( iface_name . isEmpty ( ) ) { <nl> + logger - > addMessage ( tr ( " qBittorrent is trying to listen on any interface port : % 1 " , " e . g : qBittorrent is trying to listen on any interface port : TCP / 6881 " ) . arg ( QString : : number ( port ) ) , Log : : INFO ) ; <nl> + if ( listen_ipv6 ) <nl> + s - > listen_on ( ports , ec , " : : " , session : : listen_no_system_port ) ; <nl> + else <nl> + s - > listen_on ( ports , ec , " 0 . 0 . 0 . 0 " , session : : listen_no_system_port ) ; <nl> + <nl> + if ( ec ) <nl> + logger - > addMessage ( tr ( " qBittorrent failed to listen on any interface port : % 1 . Reason : % 2 " , " e . g : qBittorrent failed to listen on any interface port : TCP / 6881 . Reason : no such interface " ) . arg ( QString : : number ( port ) ) . arg ( misc : : toQStringU ( ec . message ( ) ) ) , Log : : CRITICAL ) ; <nl> + <nl> + return ; <nl> + } <nl> + / / Attempt to listen on provided interface <nl> + const QNetworkInterface network_iface = QNetworkInterface : : interfaceFromName ( iface_name ) ; <nl> + if ( ! network_iface . isValid ( ) ) { <nl> + qDebug ( " Invalid network interface : % s " , qPrintable ( iface_name ) ) ; <nl> + logger - > addMessage ( tr ( " The network interface defined is invalid : % 1 " ) . arg ( iface_name ) , Log : : CRITICAL ) ; <nl> + return ; <nl> + } <nl> + QString ip ; <nl> + qDebug ( " This network interface has % d IP addresses " , network_iface . addressEntries ( ) . size ( ) ) ; <nl> + foreach ( const QNetworkAddressEntry & entry , network_iface . addressEntries ( ) ) { <nl> + if ( ( ! listen_ipv6 & & ( entry . ip ( ) . protocol ( ) = = QAbstractSocket : : IPv6Protocol ) ) <nl> + | | ( listen_ipv6 & & ( entry . ip ( ) . protocol ( ) = = QAbstractSocket : : IPv4Protocol ) ) ) <nl> + continue ; <nl> + qDebug ( " Trying to listen on IP % s ( % s ) " , qPrintable ( entry . ip ( ) . toString ( ) ) , qPrintable ( iface_name ) ) ; <nl> + s - > listen_on ( ports , ec , entry . ip ( ) . toString ( ) . toLatin1 ( ) . constData ( ) , session : : listen_no_system_port ) ; <nl> + if ( ! ec ) { <nl> + ip = entry . ip ( ) . toString ( ) ; <nl> + logger - > addMessage ( tr ( " qBittorrent is trying to listen on interface % 1 port : % 2 " , " e . g : qBittorrent is trying to listen on interface 192 . 168 . 0 . 1 port : TCP / 6881 " ) . arg ( ip ) . arg ( QString : : number ( port ) ) , Log : : INFO ) ; <nl> + return ; <nl> + } <nl> + } <nl> + logger - > addMessage ( tr ( " qBittorrent didn ' t find an % 1 local address to listen on " , " qBittorrent didn ' t find an IPv4 local address to listen on " ) . arg ( listen_ipv6 ? " IPv6 " : " IPv4 " ) , Log : : CRITICAL ) ; <nl> } <nl> <nl> / / Set download rate limit <nl> / / - 1 to disable <nl> void QBtSession : : setDownloadRateLimit ( long rate ) { <nl> - qDebug ( ) < < Q_FUNC_INFO < < rate ; <nl> - Q_ASSERT ( rate = = - 1 | | rate > = 0 ) ; <nl> - session_settings settings = s - > settings ( ) ; <nl> - settings . download_rate_limit = rate ; <nl> - s - > set_settings ( settings ) ; <nl> + qDebug ( ) < < Q_FUNC_INFO < < rate ; <nl> + Q_ASSERT ( rate = = - 1 | | rate > = 0 ) ; <nl> + session_settings settings = s - > settings ( ) ; <nl> + settings . download_rate_limit = rate ; <nl> + s - > set_settings ( settings ) ; <nl> } <nl> <nl> / / Set upload rate limit <nl> / / - 1 to disable <nl> void QBtSession : : setUploadRateLimit ( long rate ) { <nl> - qDebug ( ) < < Q_FUNC_INFO < < rate ; <nl> - Q_ASSERT ( rate = = - 1 | | rate > = 0 ) ; <nl> - session_settings settings = s - > settings ( ) ; <nl> - settings . upload_rate_limit = rate ; <nl> - s - > set_settings ( settings ) ; <nl> + qDebug ( ) < < Q_FUNC_INFO < < rate ; <nl> + Q_ASSERT ( rate = = - 1 | | rate > = 0 ) ; <nl> + session_settings settings = s - > settings ( ) ; <nl> + settings . upload_rate_limit = rate ; <nl> + s - > set_settings ( settings ) ; <nl> } <nl> <nl> / / Torrents will a ratio superior to the given value will <nl> / / be automatically deleted <nl> void QBtSession : : setGlobalMaxRatio ( qreal ratio ) { <nl> - if ( ratio < 0 ) ratio = - 1 . ; <nl> - if ( global_ratio_limit ! = ratio ) { <nl> - global_ratio_limit = ratio ; <nl> - qDebug ( " * Set global deleteRatio to % . 1f " , global_ratio_limit ) ; <nl> - updateRatioTimer ( ) ; <nl> - } <nl> + if ( ratio < 0 ) ratio = - 1 . ; <nl> + if ( global_ratio_limit ! = ratio ) { <nl> + global_ratio_limit = ratio ; <nl> + qDebug ( " * Set global deleteRatio to % . 1f " , global_ratio_limit ) ; <nl> + updateRatioTimer ( ) ; <nl> + } <nl> } <nl> <nl> void QBtSession : : setMaxRatioPerTorrent ( const QString & hash , qreal ratio ) <nl> { <nl> - if ( ratio < 0 ) <nl> - ratio = - 1 ; <nl> - if ( ratio > MAX_RATIO ) <nl> - ratio = MAX_RATIO ; <nl> - qDebug ( " * Set individual max ratio for torrent % s to % . 1f . " , <nl> - qPrintable ( hash ) , ratio ) ; <nl> - TorrentPersistentData : : instance ( ) - > setRatioLimit ( hash , ratio ) ; <nl> - updateRatioTimer ( ) ; <nl> + if ( ratio < 0 ) <nl> + ratio = - 1 ; <nl> + if ( ratio > MAX_RATIO ) <nl> + ratio = MAX_RATIO ; <nl> + qDebug ( " * Set individual max ratio for torrent % s to % . 1f . " , <nl> + qPrintable ( hash ) , ratio ) ; <nl> + TorrentPersistentData : : instance ( ) - > setRatioLimit ( hash , ratio ) ; <nl> + updateRatioTimer ( ) ; <nl> } <nl> <nl> void QBtSession : : removeRatioPerTorrent ( const QString & hash ) <nl> { <nl> - qDebug ( " * Remove individual max ratio for torrent % s . " , qPrintable ( hash ) ) ; <nl> - TorrentPersistentData : : instance ( ) - > setRatioLimit ( hash , TorrentPersistentData : : USE_GLOBAL_RATIO ) ; <nl> - updateRatioTimer ( ) ; <nl> + qDebug ( " * Remove individual max ratio for torrent % s . " , qPrintable ( hash ) ) ; <nl> + TorrentPersistentData : : instance ( ) - > setRatioLimit ( hash , TorrentPersistentData : : USE_GLOBAL_RATIO ) ; <nl> + updateRatioTimer ( ) ; <nl> } <nl> <nl> qreal QBtSession : : getMaxRatioPerTorrent ( const QString & hash , bool * usesGlobalRatio ) const <nl> { <nl> - qreal ratio_limit = TorrentPersistentData : : instance ( ) - > getRatioLimit ( hash ) ; <nl> - if ( ratio_limit = = TorrentPersistentData : : USE_GLOBAL_RATIO ) { <nl> - ratio_limit = global_ratio_limit ; <nl> - if ( usesGlobalRatio ) <nl> - * usesGlobalRatio = true ; <nl> - } else { <nl> - if ( usesGlobalRatio ) <nl> - * usesGlobalRatio = false ; <nl> - } <nl> - return ratio_limit ; <nl> + qreal ratio_limit = TorrentPersistentData : : instance ( ) - > getRatioLimit ( hash ) ; <nl> + if ( ratio_limit = = TorrentPersistentData : : USE_GLOBAL_RATIO ) { <nl> + ratio_limit = global_ratio_limit ; <nl> + if ( usesGlobalRatio ) <nl> + * usesGlobalRatio = true ; <nl> + } else { <nl> + if ( usesGlobalRatio ) <nl> + * usesGlobalRatio = false ; <nl> + } <nl> + return ratio_limit ; <nl> } <nl> <nl> void QBtSession : : updateRatioTimer ( ) <nl> { <nl> - if ( global_ratio_limit = = - 1 & & ! TorrentPersistentData : : instance ( ) - > hasPerTorrentRatioLimit ( ) ) { <nl> - if ( BigRatioTimer - > isActive ( ) ) <nl> - BigRatioTimer - > stop ( ) ; <nl> - } else if ( ! BigRatioTimer - > isActive ( ) ) { <nl> - BigRatioTimer - > start ( ) ; <nl> - } <nl> + if ( global_ratio_limit = = - 1 & & ! TorrentPersistentData : : instance ( ) - > hasPerTorrentRatioLimit ( ) ) { <nl> + if ( BigRatioTimer - > isActive ( ) ) <nl> + BigRatioTimer - > stop ( ) ; <nl> + } else if ( ! BigRatioTimer - > isActive ( ) ) { <nl> + BigRatioTimer - > start ( ) ; <nl> + } <nl> } <nl> <nl> / / Enable IP Filtering <nl> void QBtSession : : enableIPFilter ( const QString & filter_path , bool force ) { <nl> - qDebug ( " Enabling IPFiler " ) ; <nl> - if ( ! filterParser ) { <nl> - filterParser = new FilterParserThread ( this , s ) ; <nl> - connect ( filterParser . data ( ) , SIGNAL ( IPFilterParsed ( int ) ) , SLOT ( handleIPFilterParsed ( int ) ) ) ; <nl> - connect ( filterParser . data ( ) , SIGNAL ( IPFilterError ( ) ) , SLOT ( handleIPFilterError ( ) ) ) ; <nl> - } <nl> - if ( filterPath . isEmpty ( ) | | filterPath ! = fsutils : : fromNativePath ( filter_path ) | | force ) { <nl> - filterPath = fsutils : : fromNativePath ( filter_path ) ; <nl> - filterParser - > processFilterFile ( fsutils : : fromNativePath ( filter_path ) ) ; <nl> - } <nl> + qDebug ( " Enabling IPFiler " ) ; <nl> + if ( ! filterParser ) { <nl> + filterParser = new FilterParserThread ( this , s ) ; <nl> + connect ( filterParser . data ( ) , SIGNAL ( IPFilterParsed ( int ) ) , SLOT ( handleIPFilterParsed ( int ) ) ) ; <nl> + connect ( filterParser . data ( ) , SIGNAL ( IPFilterError ( ) ) , SLOT ( handleIPFilterError ( ) ) ) ; <nl> + } <nl> + if ( filterPath . isEmpty ( ) | | filterPath ! = fsutils : : fromNativePath ( filter_path ) | | force ) { <nl> + filterPath = fsutils : : fromNativePath ( filter_path ) ; <nl> + filterParser - > processFilterFile ( fsutils : : fromNativePath ( filter_path ) ) ; <nl> + } <nl> } <nl> <nl> / / Disable IP Filtering <nl> void QBtSession : : disableIPFilter ( ) { <nl> - qDebug ( " Disabling IPFilter " ) ; <nl> - s - > set_ip_filter ( ip_filter ( ) ) ; <nl> - if ( filterParser ) { <nl> - disconnect ( filterParser . data ( ) , 0 , this , 0 ) ; <nl> - delete filterParser ; <nl> - } <nl> - filterPath = " " ; <nl> + qDebug ( " Disabling IPFilter " ) ; <nl> + s - > set_ip_filter ( ip_filter ( ) ) ; <nl> + if ( filterParser ) { <nl> + disconnect ( filterParser . data ( ) , 0 , this , 0 ) ; <nl> + delete filterParser ; <nl> + } <nl> + filterPath = " " ; <nl> } <nl> <nl> void QBtSession : : recursiveTorrentDownload ( const QTorrentHandle & h ) <nl> void QBtSession : : recursiveTorrentDownload ( const QTorrentHandle & h ) <nl> } <nl> <nl> void QBtSession : : autoRunExternalProgram ( const QTorrentHandle & h ) { <nl> - if ( ! h . is_valid ( ) ) return ; <nl> - QString program = Preferences : : instance ( ) - > getAutoRunProgram ( ) . trimmed ( ) ; <nl> - if ( program . isEmpty ( ) ) return ; <nl> - / / Replace % f by torrent path <nl> - QString torrent_path ; <nl> - if ( h . num_files ( ) = = 1 ) <nl> - torrent_path = h . firstFileSavePath ( ) ; <nl> - else <nl> - torrent_path = h . save_path ( ) ; <nl> - program . replace ( " % f " , torrent_path ) ; <nl> - / / Replace % n by torrent name <nl> - program . replace ( " % n " , h . name ( ) ) ; <nl> - QProcess : : startDetached ( program ) ; <nl> + if ( ! h . is_valid ( ) ) return ; <nl> + QString program = Preferences : : instance ( ) - > getAutoRunProgram ( ) . trimmed ( ) ; <nl> + if ( program . isEmpty ( ) ) return ; <nl> + / / Replace % f by torrent path <nl> + QString torrent_path ; <nl> + if ( h . num_files ( ) = = 1 ) <nl> + torrent_path = h . firstFileSavePath ( ) ; <nl> + else <nl> + torrent_path = h . save_path ( ) ; <nl> + program . replace ( " % f " , torrent_path ) ; <nl> + / / Replace % n by torrent name <nl> + program . replace ( " % n " , h . name ( ) ) ; <nl> + QProcess : : startDetached ( program ) ; <nl> } <nl> <nl> void QBtSession : : sendNotificationEmail ( const QTorrentHandle & h ) { <nl> - libtorrent : : torrent_status status = h . status ( torrent_handle : : query_accurate_download_counters ) ; <nl> - / / Prepare mail content <nl> - QString content = tr ( " Torrent name : % 1 " ) . arg ( h . name ( ) ) + " \ n " ; <nl> - content + = tr ( " Torrent size : % 1 " ) . arg ( misc : : friendlyUnit ( status . total_wanted ) ) + " \ n " ; <nl> - content + = tr ( " Save path : % 1 " ) . arg ( TorrentPersistentData : : instance ( ) - > getSavePath ( h . hash ( ) ) ) + " \ n \ n " ; <nl> - content + = tr ( " The torrent was downloaded in % 1 . " , " The torrent was downloaded in 1 hour and 20 seconds " ) . arg ( misc : : userFriendlyDuration ( status . active_time ) ) + " \ n \ n \ n " ; <nl> - content + = tr ( " Thank you for using qBittorrent . " ) + " \ n " ; <nl> - / / Send the notification email <nl> - Smtp * sender = new Smtp ( this ) ; <nl> - sender - > sendMail ( " notification @ qbittorrent . org " , Preferences : : instance ( ) - > getMailNotificationEmail ( ) , tr ( " [ qBittorrent ] % 1 has finished downloading " ) . arg ( h . name ( ) ) , content ) ; <nl> + libtorrent : : torrent_status status = h . status ( torrent_handle : : query_accurate_download_counters ) ; <nl> + / / Prepare mail content <nl> + QString content = tr ( " Torrent name : % 1 " ) . arg ( h . name ( ) ) + " \ n " ; <nl> + content + = tr ( " Torrent size : % 1 " ) . arg ( misc : : friendlyUnit ( status . total_wanted ) ) + " \ n " ; <nl> + content + = tr ( " Save path : % 1 " ) . arg ( TorrentPersistentData : : instance ( ) - > getSavePath ( h . hash ( ) ) ) + " \ n \ n " ; <nl> + content + = tr ( " The torrent was downloaded in % 1 . " , " The torrent was downloaded in 1 hour and 20 seconds " ) . arg ( misc : : userFriendlyDuration ( status . active_time ) ) + " \ n \ n \ n " ; <nl> + content + = tr ( " Thank you for using qBittorrent . " ) + " \ n " ; <nl> + / / Send the notification email <nl> + Smtp * sender = new Smtp ( this ) ; <nl> + sender - > sendMail ( " notification @ qbittorrent . org " , Preferences : : instance ( ) - > getMailNotificationEmail ( ) , tr ( " [ qBittorrent ] % 1 has finished downloading " ) . arg ( h . name ( ) ) , content ) ; <nl> } <nl> <nl> / / Read alerts sent by the Bittorrent session <nl> void QBtSession : : readAlerts ( ) { <nl> <nl> - typedef std : : vector < alert * > alerts_t ; <nl> - alerts_t alerts ; <nl> - m_alertDispatcher - > getPendingAlertsNoWait ( alerts ) ; <nl> + typedef std : : vector < alert * > alerts_t ; <nl> + alerts_t alerts ; <nl> + m_alertDispatcher - > getPendingAlertsNoWait ( alerts ) ; <nl> <nl> - for ( alerts_t : : const_iterator i = alerts . begin ( ) , end = alerts . end ( ) ; i ! = end ; + + i ) { <nl> - handleAlert ( * i ) ; <nl> - delete * i ; <nl> - } <nl> + for ( alerts_t : : const_iterator i = alerts . begin ( ) , end = alerts . end ( ) ; i ! = end ; + + i ) { <nl> + handleAlert ( * i ) ; <nl> + delete * i ; <nl> + } <nl> } <nl> <nl> void QBtSession : : handleAlert ( libtorrent : : alert * a ) { <nl> - try { <nl> - switch ( a - > type ( ) ) { <nl> - case torrent_finished_alert : : alert_type : <nl> - handleTorrentFinishedAlert ( static_cast < torrent_finished_alert * > ( a ) ) ; <nl> - break ; <nl> - case save_resume_data_alert : : alert_type : <nl> - handleSaveResumeDataAlert ( static_cast < save_resume_data_alert * > ( a ) ) ; <nl> - break ; <nl> - case file_renamed_alert : : alert_type : <nl> - handleFileRenamedAlert ( static_cast < file_renamed_alert * > ( a ) ) ; <nl> - break ; <nl> - case torrent_deleted_alert : : alert_type : <nl> - handleTorrentDeletedAlert ( static_cast < torrent_deleted_alert * > ( a ) ) ; <nl> - break ; <nl> - case storage_moved_alert : : alert_type : <nl> - handleStorageMovedAlert ( static_cast < storage_moved_alert * > ( a ) ) ; <nl> - break ; <nl> - case storage_moved_failed_alert : : alert_type : <nl> - handleStorageMovedFailedAlert ( static_cast < storage_moved_failed_alert * > ( a ) ) ; <nl> - break ; <nl> - case metadata_received_alert : : alert_type : <nl> - handleMetadataReceivedAlert ( static_cast < metadata_received_alert * > ( a ) ) ; <nl> - break ; <nl> - case file_error_alert : : alert_type : <nl> - handleFileErrorAlert ( static_cast < file_error_alert * > ( a ) ) ; <nl> - break ; <nl> - case file_completed_alert : : alert_type : <nl> - handleFileCompletedAlert ( static_cast < file_completed_alert * > ( a ) ) ; <nl> - break ; <nl> - case torrent_paused_alert : : alert_type : <nl> - handleTorrentPausedAlert ( static_cast < torrent_paused_alert * > ( a ) ) ; <nl> - break ; <nl> - case tracker_error_alert : : alert_type : <nl> - handleTrackerErrorAlert ( static_cast < tracker_error_alert * > ( a ) ) ; <nl> - break ; <nl> - case tracker_reply_alert : : alert_type : <nl> - handleTrackerReplyAlert ( static_cast < tracker_reply_alert * > ( a ) ) ; <nl> - break ; <nl> - case tracker_warning_alert : : alert_type : <nl> - handleTrackerWarningAlert ( static_cast < tracker_warning_alert * > ( a ) ) ; <nl> - break ; <nl> - case portmap_error_alert : : alert_type : <nl> - handlePortmapWarningAlert ( static_cast < portmap_error_alert * > ( a ) ) ; <nl> - break ; <nl> - case portmap_alert : : alert_type : <nl> - handlePortmapAlert ( static_cast < portmap_alert * > ( a ) ) ; <nl> - break ; <nl> - case peer_blocked_alert : : alert_type : <nl> - handlePeerBlockedAlert ( static_cast < peer_blocked_alert * > ( a ) ) ; <nl> - break ; <nl> - case peer_ban_alert : : alert_type : <nl> - handlePeerBanAlert ( static_cast < peer_ban_alert * > ( a ) ) ; <nl> - break ; <nl> - case fastresume_rejected_alert : : alert_type : <nl> - handleFastResumeRejectedAlert ( static_cast < fastresume_rejected_alert * > ( a ) ) ; <nl> - break ; <nl> - case url_seed_alert : : alert_type : <nl> - handleUrlSeedAlert ( static_cast < url_seed_alert * > ( a ) ) ; <nl> - break ; <nl> - case listen_succeeded_alert : : alert_type : <nl> - handleListenSucceededAlert ( static_cast < listen_succeeded_alert * > ( a ) ) ; <nl> - break ; <nl> - case listen_failed_alert : : alert_type : <nl> - handleListenFailedAlert ( static_cast < listen_failed_alert * > ( a ) ) ; <nl> - break ; <nl> - case torrent_checked_alert : : alert_type : <nl> - handleTorrentCheckedAlert ( static_cast < torrent_checked_alert * > ( a ) ) ; <nl> - break ; <nl> - case external_ip_alert : : alert_type : <nl> - handleExternalIPAlert ( static_cast < external_ip_alert * > ( a ) ) ; <nl> - break ; <nl> - case state_update_alert : : alert_type : <nl> - handleStateUpdateAlert ( static_cast < state_update_alert * > ( a ) ) ; <nl> - break ; <nl> - case stats_alert : : alert_type : <nl> - handleStatsAlert ( static_cast < stats_alert * > ( a ) ) ; <nl> - break ; <nl> - } <nl> - } catch ( const std : : exception & e ) { <nl> - qWarning ( ) < < " Caught exception in readAlerts ( ) : " < < misc : : toQStringU ( e . what ( ) ) ; <nl> - } <nl> + try { <nl> + switch ( a - > type ( ) ) { <nl> + case torrent_finished_alert : : alert_type : <nl> + handleTorrentFinishedAlert ( static_cast < torrent_finished_alert * > ( a ) ) ; <nl> + break ; <nl> + case save_resume_data_alert : : alert_type : <nl> + handleSaveResumeDataAlert ( static_cast < save_resume_data_alert * > ( a ) ) ; <nl> + break ; <nl> + case file_renamed_alert : : alert_type : <nl> + handleFileRenamedAlert ( static_cast < file_renamed_alert * > ( a ) ) ; <nl> + break ; <nl> + case torrent_deleted_alert : : alert_type : <nl> + handleTorrentDeletedAlert ( static_cast < torrent_deleted_alert * > ( a ) ) ; <nl> + break ; <nl> + case storage_moved_alert : : alert_type : <nl> + handleStorageMovedAlert ( static_cast < storage_moved_alert * > ( a ) ) ; <nl> + break ; <nl> + case storage_moved_failed_alert : : alert_type : <nl> + handleStorageMovedFailedAlert ( static_cast < storage_moved_failed_alert * > ( a ) ) ; <nl> + break ; <nl> + case metadata_received_alert : : alert_type : <nl> + handleMetadataReceivedAlert ( static_cast < metadata_received_alert * > ( a ) ) ; <nl> + break ; <nl> + case file_error_alert : : alert_type : <nl> + handleFileErrorAlert ( static_cast < file_error_alert * > ( a ) ) ; <nl> + break ; <nl> + case file_completed_alert : : alert_type : <nl> + handleFileCompletedAlert ( static_cast < file_completed_alert * > ( a ) ) ; <nl> + break ; <nl> + case torrent_paused_alert : : alert_type : <nl> + handleTorrentPausedAlert ( static_cast < torrent_paused_alert * > ( a ) ) ; <nl> + break ; <nl> + case tracker_error_alert : : alert_type : <nl> + handleTrackerErrorAlert ( static_cast < tracker_error_alert * > ( a ) ) ; <nl> + break ; <nl> + case tracker_reply_alert : : alert_type : <nl> + handleTrackerReplyAlert ( static_cast < tracker_reply_alert * > ( a ) ) ; <nl> + break ; <nl> + case tracker_warning_alert : : alert_type : <nl> + handleTrackerWarningAlert ( static_cast < tracker_warning_alert * > ( a ) ) ; <nl> + break ; <nl> + case portmap_error_alert : : alert_type : <nl> + handlePortmapWarningAlert ( static_cast < portmap_error_alert * > ( a ) ) ; <nl> + break ; <nl> + case portmap_alert : : alert_type : <nl> + handlePortmapAlert ( static_cast < portmap_alert * > ( a ) ) ; <nl> + break ; <nl> + case peer_blocked_alert : : alert_type : <nl> + handlePeerBlockedAlert ( static_cast < peer_blocked_alert * > ( a ) ) ; <nl> + break ; <nl> + case peer_ban_alert : : alert_type : <nl> + handlePeerBanAlert ( static_cast < peer_ban_alert * > ( a ) ) ; <nl> + break ; <nl> + case fastresume_rejected_alert : : alert_type : <nl> + handleFastResumeRejectedAlert ( static_cast < fastresume_rejected_alert * > ( a ) ) ; <nl> + break ; <nl> + case url_seed_alert : : alert_type : <nl> + handleUrlSeedAlert ( static_cast < url_seed_alert * > ( a ) ) ; <nl> + break ; <nl> + case listen_succeeded_alert : : alert_type : <nl> + handleListenSucceededAlert ( static_cast < listen_succeeded_alert * > ( a ) ) ; <nl> + break ; <nl> + case listen_failed_alert : : alert_type : <nl> + handleListenFailedAlert ( static_cast < listen_failed_alert * > ( a ) ) ; <nl> + break ; <nl> + case torrent_checked_alert : : alert_type : <nl> + handleTorrentCheckedAlert ( static_cast < torrent_checked_alert * > ( a ) ) ; <nl> + break ; <nl> + case external_ip_alert : : alert_type : <nl> + handleExternalIPAlert ( static_cast < external_ip_alert * > ( a ) ) ; <nl> + break ; <nl> + case state_update_alert : : alert_type : <nl> + handleStateUpdateAlert ( static_cast < state_update_alert * > ( a ) ) ; <nl> + break ; <nl> + case stats_alert : : alert_type : <nl> + handleStatsAlert ( static_cast < stats_alert * > ( a ) ) ; <nl> + break ; <nl> + } <nl> + } catch ( const std : : exception & e ) { <nl> + qWarning ( ) < < " Caught exception in readAlerts ( ) : " < < misc : : toQStringU ( e . what ( ) ) ; <nl> + } <nl> } <nl> <nl> void QBtSession : : handleTorrentFinishedAlert ( libtorrent : : torrent_finished_alert * p ) { <nl> - QTorrentHandle h ( p - > handle ) ; <nl> - if ( h . is_valid ( ) ) { <nl> - const QString hash = h . hash ( ) ; <nl> - qDebug ( " Got a torrent finished alert for % s " , qPrintable ( h . name ( ) ) ) ; <nl> - / / Remove . ! qB extension if necessary <nl> - if ( appendqBExtension ) <nl> - appendqBextensionToTorrent ( h , false ) ; <nl> - <nl> - TorrentPersistentData * const TorPersistent = TorrentPersistentData : : instance ( ) ; <nl> - const bool was_already_seeded = TorPersistent - > isSeed ( hash ) ; <nl> - qDebug ( " Was already seeded : % d " , was_already_seeded ) ; <nl> - if ( ! was_already_seeded ) { <nl> - h . save_resume_data ( ) ; <nl> - qDebug ( " Checking if the torrent contains torrent files to download " ) ; <nl> - / / Check if there are torrent files inside <nl> - for ( int i = 0 ; i < h . num_files ( ) ; + + i ) { <nl> - const QString torrent_relpath = h . filepath_at ( i ) ; <nl> - qDebug ( ) < < " File path : " < < torrent_relpath ; <nl> - if ( torrent_relpath . endsWith ( " . torrent " , Qt : : CaseInsensitive ) ) { <nl> - qDebug ( " Found possible recursive torrent download . " ) ; <nl> - const QString torrent_fullpath = h . save_path ( ) + " / " + torrent_relpath ; <nl> - qDebug ( " Full subtorrent path is % s " , qPrintable ( torrent_fullpath ) ) ; <nl> - try { <nl> - std : : vector < char > buffer ; <nl> - lazy_entry entry ; <nl> - libtorrent : : error_code ec ; <nl> - misc : : loadBencodedFile ( torrent_fullpath , buffer , entry , ec ) ; <nl> - boost : : intrusive_ptr < torrent_info > t = new torrent_info ( entry ) ; <nl> - if ( t - > is_valid ( ) ) { <nl> - qDebug ( " emitting recursiveTorrentDownloadPossible ( ) " ) ; <nl> - emit recursiveTorrentDownloadPossible ( h ) ; <nl> - break ; <nl> - } <nl> - } <nl> - catch ( std : : exception & ) { <nl> - qDebug ( " Caught error loading torrent " ) ; <nl> - Logger : : instance ( ) - > addMessage ( tr ( " Unable to decode % 1 torrent file . " ) . arg ( fsutils : : toNativePath ( torrent_fullpath ) ) , Log : : CRITICAL ) ; <nl> - } <nl> - } <nl> - } <nl> - / / Move to download directory if necessary <nl> - if ( ! defaultTempPath . isEmpty ( ) ) { <nl> - / / Check if directory is different <nl> - const QDir current_dir ( h . save_path ( ) ) ; <nl> - const QDir save_dir ( getSavePath ( hash ) ) ; <nl> - if ( current_dir ! = save_dir ) { <nl> - qDebug ( " Moving torrent from the temp folder " ) ; <nl> - h . move_storage ( save_dir . absolutePath ( ) ) ; <nl> - } <nl> - } <nl> - / / Remember finished state <nl> - qDebug ( " Saving seed status " ) ; <nl> - TorPersistent - > saveSeedStatus ( h ) ; <nl> - / / Recheck if the user asked to <nl> - Preferences * const pref = Preferences : : instance ( ) ; <nl> - if ( pref - > recheckTorrentsOnCompletion ( ) ) { <nl> - h . force_recheck ( ) ; <nl> - } <nl> - qDebug ( " Emitting finishedTorrent ( ) signal " ) ; <nl> - emit finishedTorrent ( h ) ; <nl> - qDebug ( " Received finished alert for % s " , qPrintable ( h . name ( ) ) ) ; <nl> + QTorrentHandle h ( p - > handle ) ; <nl> + if ( h . is_valid ( ) ) { <nl> + const QString hash = h . hash ( ) ; <nl> + qDebug ( " Got a torrent finished alert for % s " , qPrintable ( h . name ( ) ) ) ; <nl> + / / Remove . ! qB extension if necessary <nl> + if ( appendqBExtension ) <nl> + appendqBextensionToTorrent ( h , false ) ; <nl> + <nl> + TorrentPersistentData * const TorPersistent = TorrentPersistentData : : instance ( ) ; <nl> + const bool was_already_seeded = TorPersistent - > isSeed ( hash ) ; <nl> + qDebug ( " Was already seeded : % d " , was_already_seeded ) ; <nl> + if ( ! was_already_seeded ) { <nl> + h . save_resume_data ( ) ; <nl> + qDebug ( " Checking if the torrent contains torrent files to download " ) ; <nl> + / / Check if there are torrent files inside <nl> + for ( int i = 0 ; i < h . num_files ( ) ; + + i ) { <nl> + const QString torrent_relpath = h . filepath_at ( i ) ; <nl> + qDebug ( ) < < " File path : " < < torrent_relpath ; <nl> + if ( torrent_relpath . endsWith ( " . torrent " , Qt : : CaseInsensitive ) ) { <nl> + qDebug ( " Found possible recursive torrent download . " ) ; <nl> + const QString torrent_fullpath = h . save_path ( ) + " / " + torrent_relpath ; <nl> + qDebug ( " Full subtorrent path is % s " , qPrintable ( torrent_fullpath ) ) ; <nl> + try { <nl> + std : : vector < char > buffer ; <nl> + lazy_entry entry ; <nl> + libtorrent : : error_code ec ; <nl> + misc : : loadBencodedFile ( torrent_fullpath , buffer , entry , ec ) ; <nl> + boost : : intrusive_ptr < torrent_info > t = new torrent_info ( entry ) ; <nl> + if ( t - > is_valid ( ) ) { <nl> + qDebug ( " emitting recursiveTorrentDownloadPossible ( ) " ) ; <nl> + emit recursiveTorrentDownloadPossible ( h ) ; <nl> + break ; <nl> + } <nl> + } <nl> + catch ( std : : exception & ) { <nl> + qDebug ( " Caught error loading torrent " ) ; <nl> + Logger : : instance ( ) - > addMessage ( tr ( " Unable to decode % 1 torrent file . " ) . arg ( fsutils : : toNativePath ( torrent_fullpath ) ) , Log : : CRITICAL ) ; <nl> + } <nl> + } <nl> + } <nl> + / / Move to download directory if necessary <nl> + if ( ! defaultTempPath . isEmpty ( ) ) { <nl> + / / Check if directory is different <nl> + const QDir current_dir ( h . save_path ( ) ) ; <nl> + const QDir save_dir ( getSavePath ( hash ) ) ; <nl> + if ( current_dir ! = save_dir ) { <nl> + qDebug ( " Moving torrent from the temp folder " ) ; <nl> + h . move_storage ( save_dir . absolutePath ( ) ) ; <nl> + } <nl> + } <nl> + / / Remember finished state <nl> + qDebug ( " Saving seed status " ) ; <nl> + TorPersistent - > saveSeedStatus ( h ) ; <nl> + / / Recheck if the user asked to <nl> + Preferences * const pref = Preferences : : instance ( ) ; <nl> + if ( pref - > recheckTorrentsOnCompletion ( ) ) { <nl> + h . force_recheck ( ) ; <nl> + } <nl> + qDebug ( " Emitting finishedTorrent ( ) signal " ) ; <nl> + emit finishedTorrent ( h ) ; <nl> + qDebug ( " Received finished alert for % s " , qPrintable ( h . name ( ) ) ) ; <nl> # ifndef DISABLE_GUI <nl> - bool will_shutdown = ( pref - > shutdownWhenDownloadsComplete ( ) | | <nl> - pref - > shutdownqBTWhenDownloadsComplete ( ) | | <nl> - pref - > suspendWhenDownloadsComplete ( ) | | <nl> - pref - > hibernateWhenDownloadsComplete ( ) ) <nl> - & & ! hasDownloadingTorrents ( ) ; <nl> + bool will_shutdown = ( pref - > shutdownWhenDownloadsComplete ( ) | | <nl> + pref - > shutdownqBTWhenDownloadsComplete ( ) | | <nl> + pref - > suspendWhenDownloadsComplete ( ) | | <nl> + pref - > hibernateWhenDownloadsComplete ( ) ) <nl> + & & ! hasDownloadingTorrents ( ) ; <nl> # else <nl> - bool will_shutdown = false ; <nl> + bool will_shutdown = false ; <nl> # endif <nl> - / / AutoRun program <nl> - if ( pref - > isAutoRunEnabled ( ) ) <nl> - autoRunExternalProgram ( h ) ; <nl> - / / Move . torrent file to another folder <nl> - if ( pref - > isFinishedTorrentExportEnabled ( ) ) <nl> - exportTorrentFile ( h , FinishedTorrentExportFolder ) ; <nl> - / / Mail notification <nl> - if ( pref - > isMailNotificationEnabled ( ) ) <nl> - sendNotificationEmail ( h ) ; <nl> + / / AutoRun program <nl> + if ( pref - > isAutoRunEnabled ( ) ) <nl> + autoRunExternalProgram ( h ) ; <nl> + / / Move . torrent file to another folder <nl> + if ( pref - > isFinishedTorrentExportEnabled ( ) ) <nl> + exportTorrentFile ( h , FinishedTorrentExportFolder ) ; <nl> + / / Mail notification <nl> + if ( pref - > isMailNotificationEnabled ( ) ) <nl> + sendNotificationEmail ( h ) ; <nl> # ifndef DISABLE_GUI <nl> - / / Auto - Shutdown <nl> - if ( will_shutdown ) { <nl> - bool suspend = pref - > suspendWhenDownloadsComplete ( ) ; <nl> - bool hibernate = pref - > hibernateWhenDownloadsComplete ( ) ; <nl> - bool shutdown = pref - > shutdownWhenDownloadsComplete ( ) ; <nl> - / / Confirm shutdown <nl> - shutDownAction action = NO_SHUTDOWN ; <nl> - <nl> - if ( suspend ) <nl> - action = SUSPEND_COMPUTER ; <nl> - else if ( hibernate ) <nl> - action = HIBERNATE_COMPUTER ; <nl> - else if ( shutdown ) <nl> - action = SHUTDOWN_COMPUTER ; <nl> - if ( ! ShutdownConfirmDlg : : askForConfirmation ( action ) ) <nl> - return ; <nl> - <nl> - / / Actually shut down <nl> - if ( suspend | | hibernate | | shutdown ) { <nl> - qDebug ( " Preparing for auto - shutdown because all downloads are complete ! " ) ; <nl> - / / Disabling it for next time <nl> - pref - > setShutdownWhenDownloadsComplete ( false ) ; <nl> - pref - > setSuspendWhenDownloadsComplete ( false ) ; <nl> - pref - > setHibernateWhenDownloadsComplete ( false ) ; <nl> - / / Make sure preferences are synced before exiting <nl> - m_shutdownAct = action ; <nl> - } <nl> - qDebug ( " Exiting the application " ) ; <nl> - qApp - > exit ( ) ; <nl> - return ; <nl> - } <nl> + / / Auto - Shutdown <nl> + if ( will_shutdown ) { <nl> + bool suspend = pref - > suspendWhenDownloadsComplete ( ) ; <nl> + bool hibernate = pref - > hibernateWhenDownloadsComplete ( ) ; <nl> + bool shutdown = pref - > shutdownWhenDownloadsComplete ( ) ; <nl> + / / Confirm shutdown <nl> + shutDownAction action = NO_SHUTDOWN ; <nl> + <nl> + if ( suspend ) <nl> + action = SUSPEND_COMPUTER ; <nl> + else if ( hibernate ) <nl> + action = HIBERNATE_COMPUTER ; <nl> + else if ( shutdown ) <nl> + action = SHUTDOWN_COMPUTER ; <nl> + if ( ! ShutdownConfirmDlg : : askForConfirmation ( action ) ) <nl> + return ; <nl> + <nl> + / / Actually shut down <nl> + if ( suspend | | hibernate | | shutdown ) { <nl> + qDebug ( " Preparing for auto - shutdown because all downloads are complete ! " ) ; <nl> + / / Disabling it for next time <nl> + pref - > setShutdownWhenDownloadsComplete ( false ) ; <nl> + pref - > setSuspendWhenDownloadsComplete ( false ) ; <nl> + pref - > setHibernateWhenDownloadsComplete ( false ) ; <nl> + / / Make sure preferences are synced before exiting <nl> + m_shutdownAct = action ; <nl> + } <nl> + qDebug ( " Exiting the application " ) ; <nl> + qApp - > exit ( ) ; <nl> + return ; <nl> + } <nl> # endif / / DISABLE_GUI <nl> + } <nl> } <nl> - } <nl> } <nl> <nl> void QBtSession : : handleSaveResumeDataAlert ( libtorrent : : save_resume_data_alert * p ) { <nl> - const QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ; <nl> - const QTorrentHandle h ( p - > handle ) ; <nl> - if ( h . is_valid ( ) & & p - > resume_data ) { <nl> - const QString filepath = torrentBackup . absoluteFilePath ( h . hash ( ) + " . fastresume " ) ; <nl> - QFile resume_file ( filepath ) ; <nl> - if ( resume_file . exists ( ) ) <nl> - fsutils : : forceRemove ( filepath ) ; <nl> - qDebug ( " Saving fastresume data in % s " , qPrintable ( filepath ) ) ; <nl> - backupPersistentData ( h . hash ( ) , p - > resume_data ) ; <nl> - vector < char > out ; <nl> - bencode ( back_inserter ( out ) , * p - > resume_data ) ; <nl> - if ( ! out . empty ( ) & & resume_file . open ( QIODevice : : WriteOnly ) ) { <nl> - resume_file . write ( & out [ 0 ] , out . size ( ) ) ; <nl> - resume_file . close ( ) ; <nl> + const QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ; <nl> + const QTorrentHandle h ( p - > handle ) ; <nl> + if ( h . is_valid ( ) & & p - > resume_data ) { <nl> + const QString filepath = torrentBackup . absoluteFilePath ( h . hash ( ) + " . fastresume " ) ; <nl> + QFile resume_file ( filepath ) ; <nl> + if ( resume_file . exists ( ) ) <nl> + fsutils : : forceRemove ( filepath ) ; <nl> + qDebug ( " Saving fastresume data in % s " , qPrintable ( filepath ) ) ; <nl> + backupPersistentData ( h . hash ( ) , p - > resume_data ) ; <nl> + vector < char > out ; <nl> + bencode ( back_inserter ( out ) , * p - > resume_data ) ; <nl> + if ( ! out . empty ( ) & & resume_file . open ( QIODevice : : WriteOnly ) ) { <nl> + resume_file . write ( & out [ 0 ] , out . size ( ) ) ; <nl> + resume_file . close ( ) ; <nl> + } <nl> } <nl> - } <nl> } <nl> <nl> void QBtSession : : handleFileRenamedAlert ( libtorrent : : file_renamed_alert * p ) { <nl> - QTorrentHandle h ( p - > handle ) ; <nl> - if ( h . is_valid ( ) ) { <nl> - if ( h . num_files ( ) > 1 ) { <nl> - / / Check if folders were renamed <nl> - QStringList old_path_parts = h . orig_filepath_at ( p - > index ) . split ( " / " ) ; <nl> - old_path_parts . removeLast ( ) ; <nl> - QString old_path = old_path_parts . join ( " / " ) ; <nl> - QStringList new_path_parts = fsutils : : fromNativePath ( misc : : toQStringU ( p - > name ) ) . split ( " / " ) ; <nl> - new_path_parts . removeLast ( ) ; <nl> - if ( ! new_path_parts . isEmpty ( ) & & old_path ! = new_path_parts . join ( " / " ) ) { <nl> - qDebug ( " Old_path ( % s ) ! = new_path ( % s ) " , qPrintable ( old_path ) , qPrintable ( new_path_parts . join ( " / " ) ) ) ; <nl> - old_path = h . save_path ( ) + " / " + old_path ; <nl> - qDebug ( " Detected folder renaming , attempt to delete old folder : % s " , qPrintable ( old_path ) ) ; <nl> - QDir ( ) . rmpath ( old_path ) ; <nl> - } <nl> - } else { <nl> - / / Single - file torrent <nl> - / / Renaming a file corresponds to changing the save path <nl> - emit savePathChanged ( h ) ; <nl> + QTorrentHandle h ( p - > handle ) ; <nl> + if ( h . is_valid ( ) ) { <nl> + if ( h . num_files ( ) > 1 ) { <nl> + / / Check if folders were renamed <nl> + QStringList old_path_parts = h . orig_filepath_at ( p - > index ) . split ( " / " ) ; <nl> + old_path_parts . removeLast ( ) ; <nl> + QString old_path = old_path_parts . join ( " / " ) ; <nl> + QStringList new_path_parts = fsutils : : fromNativePath ( misc : : toQStringU ( p - > name ) ) . split ( " / " ) ; <nl> + new_path_parts . removeLast ( ) ; <nl> + if ( ! new_path_parts . isEmpty ( ) & & old_path ! = new_path_parts . join ( " / " ) ) { <nl> + qDebug ( " Old_path ( % s ) ! = new_path ( % s ) " , qPrintable ( old_path ) , qPrintable ( new_path_parts . join ( " / " ) ) ) ; <nl> + old_path = h . save_path ( ) + " / " + old_path ; <nl> + qDebug ( " Detected folder renaming , attempt to delete old folder : % s " , qPrintable ( old_path ) ) ; <nl> + QDir ( ) . rmpath ( old_path ) ; <nl> + } <nl> + } else { <nl> + / / Single - file torrent <nl> + / / Renaming a file corresponds to changing the save path <nl> + emit savePathChanged ( h ) ; <nl> + } <nl> } <nl> - } <nl> } <nl> <nl> void QBtSession : : handleTorrentDeletedAlert ( libtorrent : : torrent_deleted_alert * p ) { <nl> - qDebug ( " A torrent was deleted from the hard disk , attempting to remove the root folder too . . . " ) ; <nl> - QString hash = misc : : toQString ( p - > info_hash ) ; <nl> - if ( ! hash . isEmpty ( ) ) { <nl> - if ( savePathsToRemove . contains ( hash ) ) { <nl> - const QString dirpath = savePathsToRemove . take ( hash ) ; <nl> - qDebug ( ) < < " Removing save path : " < < dirpath < < " . . . " ; <nl> - bool ok = fsutils : : smartRemoveEmptyFolderTree ( dirpath ) ; <nl> - Q_UNUSED ( ok ) ; <nl> - qDebug ( ) < < " Folder was removed : " < < ok ; <nl> - } <nl> - } else { <nl> - / / Fallback <nl> - qDebug ( ) < < " hash is empty , use fallback to remove save path " ; <nl> - foreach ( const QString & key , savePathsToRemove . keys ( ) ) { <nl> - / / Attempt to delete <nl> - if ( QDir ( ) . rmdir ( savePathsToRemove [ key ] ) ) { <nl> - savePathsToRemove . remove ( key ) ; <nl> - } <nl> + qDebug ( " A torrent was deleted from the hard disk , attempting to remove the root folder too . . . " ) ; <nl> + QString hash = misc : : toQString ( p - > info_hash ) ; <nl> + if ( ! hash . isEmpty ( ) ) { <nl> + if ( savePathsToRemove . contains ( hash ) ) { <nl> + const QString dirpath = savePathsToRemove . take ( hash ) ; <nl> + qDebug ( ) < < " Removing save path : " < < dirpath < < " . . . " ; <nl> + bool ok = fsutils : : smartRemoveEmptyFolderTree ( dirpath ) ; <nl> + Q_UNUSED ( ok ) ; <nl> + qDebug ( ) < < " Folder was removed : " < < ok ; <nl> + } <nl> + } else { <nl> + / / Fallback <nl> + qDebug ( ) < < " hash is empty , use fallback to remove save path " ; <nl> + foreach ( const QString & key , savePathsToRemove . keys ( ) ) { <nl> + / / Attempt to delete <nl> + if ( QDir ( ) . rmdir ( savePathsToRemove [ key ] ) ) { <nl> + savePathsToRemove . remove ( key ) ; <nl> + } <nl> + } <nl> } <nl> - } <nl> } <nl> <nl> void QBtSession : : handleStorageMovedAlert ( libtorrent : : storage_moved_alert * p ) { <nl> - QTorrentHandle h ( p - > handle ) ; <nl> - if ( ! h . is_valid ( ) ) { <nl> - qWarning ( " invalid handle received in storage_moved_alert " ) ; <nl> - return ; <nl> - } <nl> - <nl> - QString hash = h . hash ( ) ; <nl> - <nl> - if ( ! TorrentTempData : : isMoveInProgress ( hash ) ) { <nl> - qWarning ( " unexpected storage_moved_alert received " ) ; <nl> - return ; <nl> - } <nl> - <nl> - QString new_save_path = fsutils : : fromNativePath ( misc : : toQStringU ( p - > path . c_str ( ) ) ) ; <nl> - if ( new_save_path ! = fsutils : : fromNativePath ( TorrentTempData : : getNewPath ( hash ) ) ) { <nl> - qWarning ( " new path received in handleStorageMovedAlert ( ) doesn ' t match a path in a queue " ) ; <nl> - return ; <nl> - } <nl> - <nl> - QString oldPath = fsutils : : fromNativePath ( TorrentTempData : : getOldPath ( hash ) ) ; <nl> - <nl> - qDebug ( " Torrent is successfully moved from % s to % s " , qPrintable ( oldPath ) , qPrintable ( new_save_path ) ) ; <nl> - <nl> - / / Attempt to remove old folder if empty <nl> - QDir old_save_dir ( oldPath ) ; <nl> - if ( old_save_dir ! = QDir ( defaultSavePath ) & & old_save_dir ! = QDir ( defaultTempPath ) ) { <nl> - qDebug ( " Attempting to remove % s " , qPrintable ( oldPath ) ) ; <nl> - QDir ( ) . rmpath ( oldPath ) ; <nl> - } <nl> - if ( defaultTempPath . isEmpty ( ) | | ! new_save_path . startsWith ( defaultTempPath ) ) { <nl> - qDebug ( " Storage has been moved , updating save path to % s " , qPrintable ( new_save_path ) ) ; <nl> - TorrentPersistentData : : instance ( ) - > saveSavePath ( h . hash ( ) , new_save_path ) ; <nl> - } <nl> - emit savePathChanged ( h ) ; <nl> - / / h . force_recheck ( ) ; <nl> - <nl> - QString queued = TorrentTempData : : getQueuedPath ( hash ) ; <nl> - if ( ! queued . isEmpty ( ) ) { <nl> - TorrentTempData : : finishMove ( hash ) ; <nl> - h . move_storage ( queued ) ; <nl> - } <nl> - else { <nl> - TorrentTempData : : finishMove ( hash ) ; <nl> - } <nl> + QTorrentHandle h ( p - > handle ) ; <nl> + if ( ! h . is_valid ( ) ) { <nl> + qWarning ( " invalid handle received in storage_moved_alert " ) ; <nl> + return ; <nl> + } <nl> + <nl> + QString hash = h . hash ( ) ; <nl> + <nl> + if ( ! TorrentTempData : : isMoveInProgress ( hash ) ) { <nl> + qWarning ( " unexpected storage_moved_alert received " ) ; <nl> + return ; <nl> + } <nl> + <nl> + QString new_save_path = fsutils : : fromNativePath ( misc : : toQStringU ( p - > path . c_str ( ) ) ) ; <nl> + if ( new_save_path ! = fsutils : : fromNativePath ( TorrentTempData : : getNewPath ( hash ) ) ) { <nl> + qWarning ( " new path received in handleStorageMovedAlert ( ) doesn ' t match a path in a queue " ) ; <nl> + return ; <nl> + } <nl> + <nl> + QString oldPath = fsutils : : fromNativePath ( TorrentTempData : : getOldPath ( hash ) ) ; <nl> + <nl> + qDebug ( " Torrent is successfully moved from % s to % s " , qPrintable ( oldPath ) , qPrintable ( new_save_path ) ) ; <nl> + <nl> + / / Attempt to remove old folder if empty <nl> + QDir old_save_dir ( oldPath ) ; <nl> + if ( old_save_dir ! = QDir ( defaultSavePath ) & & old_save_dir ! = QDir ( defaultTempPath ) ) { <nl> + qDebug ( " Attempting to remove % s " , qPrintable ( oldPath ) ) ; <nl> + QDir ( ) . rmpath ( oldPath ) ; <nl> + } <nl> + if ( defaultTempPath . isEmpty ( ) | | ! new_save_path . startsWith ( defaultTempPath ) ) { <nl> + qDebug ( " Storage has been moved , updating save path to % s " , qPrintable ( new_save_path ) ) ; <nl> + TorrentPersistentData : : instance ( ) - > saveSavePath ( h . hash ( ) , new_save_path ) ; <nl> + } <nl> + emit savePathChanged ( h ) ; <nl> + / / h . force_recheck ( ) ; <nl> + <nl> + QString queued = TorrentTempData : : getQueuedPath ( hash ) ; <nl> + if ( ! queued . isEmpty ( ) ) { <nl> + TorrentTempData : : finishMove ( hash ) ; <nl> + h . move_storage ( queued ) ; <nl> + } <nl> + else { <nl> + TorrentTempData : : finishMove ( hash ) ; <nl> + } <nl> } <nl> <nl> void QBtSession : : handleStorageMovedFailedAlert ( libtorrent : : storage_moved_failed_alert * p ) { <nl> <nl> - QTorrentHandle h ( p - > handle ) ; <nl> - if ( ! h . is_valid ( ) ) { <nl> - qWarning ( " invalid handle received in storage_moved_failed_alert " ) ; <nl> - return ; <nl> - } <nl> + QTorrentHandle h ( p - > handle ) ; <nl> + if ( ! h . is_valid ( ) ) { <nl> + qWarning ( " invalid handle received in storage_moved_failed_alert " ) ; <nl> + return ; <nl> + } <nl> <nl> - QString hash = h . hash ( ) ; <nl> + QString hash = h . hash ( ) ; <nl> <nl> - if ( ! TorrentTempData : : isMoveInProgress ( hash ) ) { <nl> - qWarning ( " unexpected storage_moved_alert received " ) ; <nl> - return ; <nl> - } <nl> + if ( ! TorrentTempData : : isMoveInProgress ( hash ) ) { <nl> + qWarning ( " unexpected storage_moved_alert received " ) ; <nl> + return ; <nl> + } <nl> <nl> - Logger * const logger = Logger : : instance ( ) ; <nl> - logger - > addMessage ( tr ( " Could not move torrent : ' % 1 ' . Reason : % 2 " ) . arg ( h . name ( ) ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) , Log : : CRITICAL ) ; <nl> + Logger * const logger = Logger : : instance ( ) ; <nl> + logger - > addMessage ( tr ( " Could not move torrent : ' % 1 ' . Reason : % 2 " ) . arg ( h . name ( ) ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) , Log : : CRITICAL ) ; <nl> <nl> - QString queued = TorrentTempData : : getQueuedPath ( hash ) ; <nl> - if ( ! queued . isEmpty ( ) ) { <nl> - TorrentTempData : : finishMove ( hash ) ; <nl> - logger - > addMessage ( tr ( " Attempting to move torrent : ' % 1 ' to path : ' % 2 ' . " ) . arg ( h . name ( ) ) . arg ( fsutils : : toNativePath ( queued ) ) ) ; <nl> - h . move_storage ( queued ) ; <nl> - } <nl> - else { <nl> - TorrentTempData : : finishMove ( hash ) ; <nl> - } <nl> + QString queued = TorrentTempData : : getQueuedPath ( hash ) ; <nl> + if ( ! queued . isEmpty ( ) ) { <nl> + TorrentTempData : : finishMove ( hash ) ; <nl> + logger - > addMessage ( tr ( " Attempting to move torrent : ' % 1 ' to path : ' % 2 ' . " ) . arg ( h . name ( ) ) . arg ( fsutils : : toNativePath ( queued ) ) ) ; <nl> + h . move_storage ( queued ) ; <nl> + } <nl> + else { <nl> + TorrentTempData : : finishMove ( hash ) ; <nl> + } <nl> } <nl> <nl> void QBtSession : : handleMetadataReceivedAlert ( libtorrent : : metadata_received_alert * p ) { <nl> - QTorrentHandle h ( p - > handle ) ; <nl> - Preferences * const pref = Preferences : : instance ( ) ; <nl> - if ( h . is_valid ( ) ) { <nl> - QString hash ( h . hash ( ) ) ; <nl> - if ( HiddenData : : hasData ( hash ) ) { <nl> - HiddenData : : gotMetadata ( hash ) ; <nl> - if ( pref - > isQueueingSystemEnabled ( ) ) { <nl> - / / Internally decrease the queue limits to ensure that that other queued items aren ' t started <nl> - libtorrent : : session_settings sessionSettings ( s - > settings ( ) ) ; <nl> - int max_downloading = pref - > getMaxActiveDownloads ( ) ; <nl> - int max_active = pref - > getMaxActiveTorrents ( ) ; <nl> - if ( max_downloading > - 1 ) <nl> - sessionSettings . active_downloads = max_downloading + HiddenData : : getDownloadingSize ( ) ; <nl> - else <nl> - sessionSettings . active_downloads = max_downloading ; <nl> - if ( max_active > - 1 ) <nl> - sessionSettings . active_limit = max_active + HiddenData : : getDownloadingSize ( ) ; <nl> + QTorrentHandle h ( p - > handle ) ; <nl> + Preferences * const pref = Preferences : : instance ( ) ; <nl> + if ( h . is_valid ( ) ) { <nl> + QString hash ( h . hash ( ) ) ; <nl> + if ( HiddenData : : hasData ( hash ) ) { <nl> + HiddenData : : gotMetadata ( hash ) ; <nl> + if ( pref - > isQueueingSystemEnabled ( ) ) { <nl> + / / Internally decrease the queue limits to ensure that that other queued items aren ' t started <nl> + libtorrent : : session_settings sessionSettings ( s - > settings ( ) ) ; <nl> + int max_downloading = pref - > getMaxActiveDownloads ( ) ; <nl> + int max_active = pref - > getMaxActiveTorrents ( ) ; <nl> + if ( max_downloading > - 1 ) <nl> + sessionSettings . active_downloads = max_downloading + HiddenData : : getDownloadingSize ( ) ; <nl> + else <nl> + sessionSettings . active_downloads = max_downloading ; <nl> + if ( max_active > - 1 ) <nl> + sessionSettings . active_limit = max_active + HiddenData : : getDownloadingSize ( ) ; <nl> + else <nl> + sessionSettings . active_limit = max_active ; <nl> + s - > set_settings ( sessionSettings ) ; <nl> + } <nl> + h . pause ( ) ; <nl> + } <nl> + qDebug ( " Received metadata for % s " , qPrintable ( h . hash ( ) ) ) ; <nl> + / / Save metadata <nl> + const QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ; <nl> + if ( ! QFile : : exists ( torrentBackup . absoluteFilePath ( h . hash ( ) + QString ( " . torrent " ) ) ) ) <nl> + h . save_torrent_file ( torrentBackup . absoluteFilePath ( h . hash ( ) + QString ( " . torrent " ) ) ) ; <nl> + / / Copy the torrent file to the export folder <nl> + if ( m_torrentExportEnabled ) <nl> + exportTorrentFile ( h ) ; <nl> + / / Append . ! qB to incomplete files <nl> + if ( appendqBExtension ) <nl> + appendqBextensionToTorrent ( h , true ) ; <nl> + <nl> + if ( ! HiddenData : : hasData ( hash ) ) <nl> + emit metadataReceived ( h ) ; <nl> else <nl> - sessionSettings . active_limit = max_active ; <nl> - s - > set_settings ( sessionSettings ) ; <nl> - } <nl> - h . pause ( ) ; <nl> - } <nl> - qDebug ( " Received metadata for % s " , qPrintable ( h . hash ( ) ) ) ; <nl> - / / Save metadata <nl> - const QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ; <nl> - if ( ! QFile : : exists ( torrentBackup . absoluteFilePath ( h . hash ( ) + QString ( " . torrent " ) ) ) ) <nl> - h . save_torrent_file ( torrentBackup . absoluteFilePath ( h . hash ( ) + QString ( " . torrent " ) ) ) ; <nl> - / / Copy the torrent file to the export folder <nl> - if ( m_torrentExportEnabled ) <nl> - exportTorrentFile ( h ) ; <nl> - / / Append . ! qB to incomplete files <nl> - if ( appendqBExtension ) <nl> - appendqBextensionToTorrent ( h , true ) ; <nl> - <nl> - if ( ! HiddenData : : hasData ( hash ) ) <nl> - emit metadataReceived ( h ) ; <nl> - else <nl> - emit metadataReceivedHidden ( h ) ; <nl> + emit metadataReceivedHidden ( h ) ; <nl> <nl> - if ( h . is_paused ( ) & & ! HiddenData : : hasData ( hash ) ) { <nl> - / / XXX : Unfortunately libtorrent - rasterbar does not send a torrent_paused_alert <nl> - / / and the torrent can be paused when metadata is received <nl> - emit pausedTorrent ( h ) ; <nl> + if ( h . is_paused ( ) & & ! HiddenData : : hasData ( hash ) ) { <nl> + / / XXX : Unfortunately libtorrent - rasterbar does not send a torrent_paused_alert <nl> + / / and the torrent can be paused when metadata is received <nl> + emit pausedTorrent ( h ) ; <nl> + } <nl> } <nl> - } <nl> } <nl> <nl> void QBtSession : : handleFileErrorAlert ( libtorrent : : file_error_alert * p ) { <nl> - QTorrentHandle h ( p - > handle ) ; <nl> - if ( h . is_valid ( ) ) { <nl> - h . pause ( ) ; <nl> - std : : cerr < < " File Error : " < < p - > message ( ) . c_str ( ) < < std : : endl ; <nl> - Logger * const logger = Logger : : instance ( ) ; <nl> - logger - > addMessage ( tr ( " An I / O error occurred , ' % 1 ' paused . " ) . arg ( h . name ( ) ) ) ; <nl> - logger - > addMessage ( tr ( " Reason : % 1 " ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) ) ; <nl> + QTorrentHandle h ( p - > handle ) ; <nl> if ( h . is_valid ( ) ) { <nl> - emit fullDiskError ( h , misc : : toQStringU ( p - > message ( ) ) ) ; <nl> - / / h . pause ( ) ; <nl> - emit pausedTorrent ( h ) ; <nl> + h . pause ( ) ; <nl> + std : : cerr < < " File Error : " < < p - > message ( ) . c_str ( ) < < std : : endl ; <nl> + Logger * const logger = Logger : : instance ( ) ; <nl> + logger - > addMessage ( tr ( " An I / O error occurred , ' % 1 ' paused . " ) . arg ( h . name ( ) ) ) ; <nl> + logger - > addMessage ( tr ( " Reason : % 1 " ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) ) ; <nl> + if ( h . is_valid ( ) ) { <nl> + emit fullDiskError ( h , misc : : toQStringU ( p - > message ( ) ) ) ; <nl> + / / h . pause ( ) ; <nl> + emit pausedTorrent ( h ) ; <nl> + } <nl> } <nl> - } <nl> } <nl> <nl> void QBtSession : : handleFileCompletedAlert ( libtorrent : : file_completed_alert * p ) { <nl> - QTorrentHandle h ( p - > handle ) ; <nl> - qDebug ( " A file completed download in torrent % s " , qPrintable ( h . name ( ) ) ) ; <nl> - if ( appendqBExtension ) { <nl> - qDebug ( " appendqBTExtension is true " ) ; <nl> - QString name = h . filepath_at ( p - > index ) ; <nl> - if ( name . endsWith ( " . ! qB " ) ) { <nl> - const QString old_name = name ; <nl> - name . chop ( 4 ) ; <nl> - qDebug ( " Renaming % s to % s " , qPrintable ( old_name ) , qPrintable ( name ) ) ; <nl> - h . rename_file ( p - > index , name ) ; <nl> + QTorrentHandle h ( p - > handle ) ; <nl> + qDebug ( " A file completed download in torrent % s " , qPrintable ( h . name ( ) ) ) ; <nl> + if ( appendqBExtension ) { <nl> + qDebug ( " appendqBTExtension is true " ) ; <nl> + QString name = h . filepath_at ( p - > index ) ; <nl> + if ( name . endsWith ( " . ! qB " ) ) { <nl> + const QString old_name = name ; <nl> + name . chop ( 4 ) ; <nl> + qDebug ( " Renaming % s to % s " , qPrintable ( old_name ) , qPrintable ( name ) ) ; <nl> + h . rename_file ( p - > index , name ) ; <nl> + } <nl> } <nl> - } <nl> } <nl> <nl> void QBtSession : : handleTorrentPausedAlert ( libtorrent : : torrent_paused_alert * p ) { <nl> - if ( p - > handle . is_valid ( ) ) { <nl> - QTorrentHandle h ( p - > handle ) ; <nl> - if ( ! HiddenData : : hasData ( h . hash ( ) ) ) { <nl> - if ( ! h . has_error ( ) & & ! TorrentPersistentData : : instance ( ) - > getHasMissingFiles ( h . hash ( ) ) ) <nl> - h . save_resume_data ( ) ; <nl> - emit pausedTorrent ( h ) ; <nl> + if ( p - > handle . is_valid ( ) ) { <nl> + QTorrentHandle h ( p - > handle ) ; <nl> + if ( ! HiddenData : : hasData ( h . hash ( ) ) ) { <nl> + if ( ! h . has_error ( ) & & ! TorrentPersistentData : : instance ( ) - > getHasMissingFiles ( h . hash ( ) ) ) <nl> + h . save_resume_data ( ) ; <nl> + emit pausedTorrent ( h ) ; <nl> + } <nl> } <nl> - } <nl> } <nl> <nl> void QBtSession : : handleTrackerErrorAlert ( libtorrent : : tracker_error_alert * p ) { <nl> - / / Level : fatal <nl> - QTorrentHandle h ( p - > handle ) ; <nl> - if ( h . is_valid ( ) ) { <nl> - / / Authentication <nl> - if ( p - > status_code ! = 401 ) { <nl> - qDebug ( " Received a tracker error for % s : % s " , p - > url . c_str ( ) , p - > msg . c_str ( ) ) ; <nl> - const QString tracker_url = misc : : toQString ( p - > url ) ; <nl> - QHash < QString , TrackerInfos > trackers_data = trackersInfos . value ( h . hash ( ) , QHash < QString , TrackerInfos > ( ) ) ; <nl> - TrackerInfos data = trackers_data . value ( tracker_url , TrackerInfos ( tracker_url ) ) ; <nl> - data . last_message = misc : : toQStringU ( p - > msg ) ; <nl> - trackers_data . insert ( tracker_url , data ) ; <nl> - trackersInfos [ h . hash ( ) ] = trackers_data ; <nl> - } else { <nl> - emit trackerAuthenticationRequired ( h ) ; <nl> + / / Level : fatal <nl> + QTorrentHandle h ( p - > handle ) ; <nl> + if ( h . is_valid ( ) ) { <nl> + / / Authentication <nl> + if ( p - > status_code ! = 401 ) { <nl> + qDebug ( " Received a tracker error for % s : % s " , p - > url . c_str ( ) , p - > msg . c_str ( ) ) ; <nl> + const QString tracker_url = misc : : toQString ( p - > url ) ; <nl> + QHash < QString , TrackerInfos > trackers_data = trackersInfos . value ( h . hash ( ) , QHash < QString , TrackerInfos > ( ) ) ; <nl> + TrackerInfos data = trackers_data . value ( tracker_url , TrackerInfos ( tracker_url ) ) ; <nl> + data . last_message = misc : : toQStringU ( p - > msg ) ; <nl> + trackers_data . insert ( tracker_url , data ) ; <nl> + trackersInfos [ h . hash ( ) ] = trackers_data ; <nl> + } else { <nl> + emit trackerAuthenticationRequired ( h ) ; <nl> + } <nl> } <nl> - } <nl> } <nl> <nl> void QBtSession : : handleTrackerReplyAlert ( libtorrent : : tracker_reply_alert * p ) { <nl> - const QTorrentHandle h ( p - > handle ) ; <nl> - if ( h . is_valid ( ) ) { <nl> - qDebug ( " Received a tracker reply from % s ( Num_peers = % d ) " , p - > url . c_str ( ) , p - > num_peers ) ; <nl> - / / Connection was successful now . Remove possible old errors <nl> - QHash < QString , TrackerInfos > trackers_data = trackersInfos . value ( h . hash ( ) , QHash < QString , TrackerInfos > ( ) ) ; <nl> - const QString tracker_url = misc : : toQString ( p - > url ) ; <nl> - TrackerInfos data = trackers_data . value ( tracker_url , TrackerInfos ( tracker_url ) ) ; <nl> - data . last_message = " " ; / / Reset error / warning message <nl> - data . num_peers = p - > num_peers ; <nl> - trackers_data . insert ( tracker_url , data ) ; <nl> - trackersInfos [ h . hash ( ) ] = trackers_data ; <nl> - } <nl> + const QTorrentHandle h ( p - > handle ) ; <nl> + if ( h . is_valid ( ) ) { <nl> + qDebug ( " Received a tracker reply from % s ( Num_peers = % d ) " , p - > url . c_str ( ) , p - > num_peers ) ; <nl> + / / Connection was successful now . Remove possible old errors <nl> + QHash < QString , TrackerInfos > trackers_data = trackersInfos . value ( h . hash ( ) , QHash < QString , TrackerInfos > ( ) ) ; <nl> + const QString tracker_url = misc : : toQString ( p - > url ) ; <nl> + TrackerInfos data = trackers_data . value ( tracker_url , TrackerInfos ( tracker_url ) ) ; <nl> + data . last_message = " " ; / / Reset error / warning message <nl> + data . num_peers = p - > num_peers ; <nl> + trackers_data . insert ( tracker_url , data ) ; <nl> + trackersInfos [ h . hash ( ) ] = trackers_data ; <nl> + } <nl> } <nl> <nl> void QBtSession : : handleTrackerWarningAlert ( libtorrent : : tracker_warning_alert * p ) { <nl> - const QTorrentHandle h ( p - > handle ) ; <nl> - if ( h . is_valid ( ) ) { <nl> - / / Connection was successful now but there is a warning message <nl> - QHash < QString , TrackerInfos > trackers_data = trackersInfos . value ( h . hash ( ) , QHash < QString , TrackerInfos > ( ) ) ; <nl> - const QString tracker_url = misc : : toQString ( p - > url ) ; <nl> - TrackerInfos data = trackers_data . value ( tracker_url , TrackerInfos ( tracker_url ) ) ; <nl> - data . last_message = misc : : toQStringU ( p - > msg ) ; / / Store warning message <nl> - trackers_data . insert ( tracker_url , data ) ; <nl> - trackersInfos [ h . hash ( ) ] = trackers_data ; <nl> - qDebug ( " Received a tracker warning from % s : % s " , p - > url . c_str ( ) , p - > msg . c_str ( ) ) ; <nl> - } <nl> + const QTorrentHandle h ( p - > handle ) ; <nl> + if ( h . is_valid ( ) ) { <nl> + / / Connection was successful now but there is a warning message <nl> + QHash < QString , TrackerInfos > trackers_data = trackersInfos . value ( h . hash ( ) , QHash < QString , TrackerInfos > ( ) ) ; <nl> + const QString tracker_url = misc : : toQString ( p - > url ) ; <nl> + TrackerInfos data = trackers_data . value ( tracker_url , TrackerInfos ( tracker_url ) ) ; <nl> + data . last_message = misc : : toQStringU ( p - > msg ) ; / / Store warning message <nl> + trackers_data . insert ( tracker_url , data ) ; <nl> + trackersInfos [ h . hash ( ) ] = trackers_data ; <nl> + qDebug ( " Received a tracker warning from % s : % s " , p - > url . c_str ( ) , p - > msg . c_str ( ) ) ; <nl> + } <nl> } <nl> <nl> void QBtSession : : handlePortmapWarningAlert ( libtorrent : : portmap_error_alert * p ) { <nl> - Logger : : instance ( ) - > addMessage ( tr ( " UPnP / NAT - PMP : Port mapping failure , message : % 1 " ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) , Log : : CRITICAL ) ; <nl> + Logger : : instance ( ) - > addMessage ( tr ( " UPnP / NAT - PMP : Port mapping failure , message : % 1 " ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) , Log : : CRITICAL ) ; <nl> } <nl> <nl> void QBtSession : : handlePortmapAlert ( libtorrent : : portmap_alert * p ) { <nl> - qDebug ( " UPnP Success , msg : % s " , p - > message ( ) . c_str ( ) ) ; <nl> - Logger : : instance ( ) - > addMessage ( tr ( " UPnP / NAT - PMP : Port mapping successful , message : % 1 " ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) , Log : : INFO ) ; <nl> + qDebug ( " UPnP Success , msg : % s " , p - > message ( ) . c_str ( ) ) ; <nl> + Logger : : instance ( ) - > addMessage ( tr ( " UPnP / NAT - PMP : Port mapping successful , message : % 1 " ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) , Log : : INFO ) ; <nl> } <nl> <nl> void QBtSession : : handlePeerBlockedAlert ( libtorrent : : peer_blocked_alert * p ) <nl> void QBtSession : : handlePeerBlockedAlert ( libtorrent : : peer_blocked_alert * p ) <nl> } <nl> <nl> void QBtSession : : handlePeerBanAlert ( libtorrent : : peer_ban_alert * p ) { <nl> - boost : : system : : error_code ec ; <nl> - string ip = p - > ip . address ( ) . to_string ( ec ) ; <nl> - if ( ! ec ) <nl> - Logger : : instance ( ) - > addPeer ( QString : : fromLatin1 ( ip . c_str ( ) ) , false ) ; <nl> + boost : : system : : error_code ec ; <nl> + string ip = p - > ip . address ( ) . to_string ( ec ) ; <nl> + if ( ! ec ) <nl> + Logger : : instance ( ) - > addPeer ( QString : : fromLatin1 ( ip . c_str ( ) ) , false ) ; <nl> } <nl> <nl> void QBtSession : : handleFastResumeRejectedAlert ( libtorrent : : fastresume_rejected_alert * p ) { <nl> - Logger * const logger = Logger : : instance ( ) ; <nl> - QTorrentHandle h ( p - > handle ) ; <nl> - if ( h . is_valid ( ) ) { <nl> - qDebug ( " / ! \ \ Fast resume failed for % s , reason : % s " , qPrintable ( h . name ( ) ) , p - > message ( ) . c_str ( ) ) ; <nl> - if ( p - > error . value ( ) = = errors : : mismatching_file_size ) { <nl> - / / Mismatching file size ( files were probably moved ) <nl> - const QString hash = h . hash ( ) ; <nl> - logger - > addMessage ( tr ( " File sizes mismatch for torrent % 1 , pausing it . " ) . arg ( h . name ( ) ) , Log : : CRITICAL ) ; <nl> - TorrentPersistentData : : instance ( ) - > setHasMissingFiles ( h . hash ( ) , true ) ; <nl> - pauseTorrent ( hash ) ; <nl> - } else { <nl> - logger - > addMessage ( tr ( " Fast resume data was rejected for torrent % 1 , checking again . . . " ) . arg ( h . name ( ) ) , Log : : CRITICAL ) ; <nl> - logger - > addMessage ( tr ( " Reason : % 1 " ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) ) ; <nl> + Logger * const logger = Logger : : instance ( ) ; <nl> + QTorrentHandle h ( p - > handle ) ; <nl> + if ( h . is_valid ( ) ) { <nl> + qDebug ( " / ! \ \ Fast resume failed for % s , reason : % s " , qPrintable ( h . name ( ) ) , p - > message ( ) . c_str ( ) ) ; <nl> + if ( p - > error . value ( ) = = errors : : mismatching_file_size ) { <nl> + / / Mismatching file size ( files were probably moved ) <nl> + const QString hash = h . hash ( ) ; <nl> + logger - > addMessage ( tr ( " File sizes mismatch for torrent % 1 , pausing it . " ) . arg ( h . name ( ) ) , Log : : CRITICAL ) ; <nl> + TorrentPersistentData : : instance ( ) - > setHasMissingFiles ( h . hash ( ) , true ) ; <nl> + pauseTorrent ( hash ) ; <nl> + } else { <nl> + logger - > addMessage ( tr ( " Fast resume data was rejected for torrent % 1 , checking again . . . " ) . arg ( h . name ( ) ) , Log : : CRITICAL ) ; <nl> + logger - > addMessage ( tr ( " Reason : % 1 " ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) ) ; <nl> + } <nl> } <nl> - } <nl> } <nl> <nl> void QBtSession : : handleUrlSeedAlert ( libtorrent : : url_seed_alert * p ) { <nl> - Logger : : instance ( ) - > addMessage ( tr ( " Url seed lookup failed for url : % 1 , message : % 2 " ) . arg ( misc : : toQString ( p - > url ) ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) , Log : : CRITICAL ) ; <nl> + Logger : : instance ( ) - > addMessage ( tr ( " Url seed lookup failed for url : % 1 , message : % 2 " ) . arg ( misc : : toQString ( p - > url ) ) . arg ( misc : : toQStringU ( p - > message ( ) ) ) , Log : : CRITICAL ) ; <nl> } <nl> <nl> void QBtSession : : handleListenSucceededAlert ( libtorrent : : listen_succeeded_alert * p ) { <nl> - boost : : system : : error_code ec ; <nl> - QString proto = " TCP " ; <nl> + boost : : system : : error_code ec ; <nl> + QString proto = " TCP " ; <nl> # if LIBTORRENT_VERSION_NUM > = 10000 <nl> - if ( p - > sock_type = = listen_succeeded_alert : : udp ) <nl> - proto = " UDP " ; <nl> - else if ( p - > sock_type = = listen_succeeded_alert : : tcp ) <nl> - proto = " TCP " ; <nl> - else if ( p - > sock_type = = listen_succeeded_alert : : tcp_ssl ) <nl> - proto = " TCP_SSL " ; <nl> + if ( p - > sock_type = = listen_succeeded_alert : : udp ) <nl> + proto = " UDP " ; <nl> + else if ( p - > sock_type = = listen_succeeded_alert : : tcp ) <nl> + proto = " TCP " ; <nl> + else if ( p - > sock_type = = listen_succeeded_alert : : tcp_ssl ) <nl> + proto = " TCP_SSL " ; <nl> # endif <nl> - qDebug ( ) < < " Successfully listening on " < < proto < < p - > endpoint . address ( ) . to_string ( ec ) . c_str ( ) < < " / " < < p - > endpoint . port ( ) ; <nl> - Logger : : instance ( ) - > addMessage ( tr ( " qBittorrent is successfully listening on interface % 1 port : % 2 / % 3 " , " e . g : qBittorrent is successfully listening on interface 192 . 168 . 0 . 1 port : TCP / 6881 " ) . arg ( p - > endpoint . address ( ) . to_string ( ec ) . c_str ( ) ) . arg ( proto ) . arg ( QString : : number ( p - > endpoint . port ( ) ) ) , Log : : INFO ) ; <nl> - / / Force reannounce on all torrents because some trackers blacklist some ports <nl> - std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> + qDebug ( ) < < " Successfully listening on " < < proto < < p - > endpoint . address ( ) . to_string ( ec ) . c_str ( ) < < " / " < < p - > endpoint . port ( ) ; <nl> + Logger : : instance ( ) - > addMessage ( tr ( " qBittorrent is successfully listening on interface % 1 port : % 2 / % 3 " , " e . g : qBittorrent is successfully listening on interface 192 . 168 . 0 . 1 port : TCP / 6881 " ) . arg ( p - > endpoint . address ( ) . to_string ( ec ) . c_str ( ) ) . arg ( proto ) . arg ( QString : : number ( p - > endpoint . port ( ) ) ) , Log : : INFO ) ; <nl> + / / Force reannounce on all torrents because some trackers blacklist some ports <nl> + std : : vector < torrent_handle > torrents = s - > get_torrents ( ) ; <nl> <nl> - std : : vector < torrent_handle > : : iterator it = torrents . begin ( ) ; <nl> - std : : vector < torrent_handle > : : iterator itend = torrents . end ( ) ; <nl> - for ( ; it ! = itend ; + + it ) { <nl> - it - > force_reannounce ( ) ; <nl> - } <nl> + std : : vector < torrent_handle > : : iterator it = torrents . begin ( ) ; <nl> + std : : vector < torrent_handle > : : iterator itend = torrents . end ( ) ; <nl> + for ( ; it ! = itend ; + + it ) { <nl> + it - > force_reannounce ( ) ; <nl> + } <nl> } <nl> <nl> void QBtSession : : handleListenFailedAlert ( libtorrent : : listen_failed_alert * p ) { <nl> - boost : : system : : error_code ec ; <nl> - QString proto = " TCP " ; <nl> + boost : : system : : error_code ec ; <nl> + QString proto = " TCP " ; <nl> # if LIBTORRENT_VERSION_NUM > = 10000 <nl> - if ( p - > sock_type = = listen_failed_alert : : udp ) <nl> - proto = " UDP " ; <nl> - else if ( p - > sock_type = = listen_failed_alert : : tcp ) <nl> - proto = " TCP " ; <nl> - else if ( p - > sock_type = = listen_failed_alert : : tcp_ssl ) <nl> - proto = " TCP_SSL " ; <nl> - else if ( p - > sock_type = = listen_failed_alert : : i2p ) <nl> - proto = " I2P " ; <nl> - else if ( p - > sock_type = = listen_failed_alert : : socks5 ) <nl> - proto = " SOCKS5 " ; <nl> + if ( p - > sock_type = = listen_failed_alert : : udp ) <nl> + proto = " UDP " ; <nl> + else if ( p - > sock_type = = listen_failed_alert : : tcp ) <nl> + proto = " TCP " ; <nl> + else if ( p - > sock_type = = listen_failed_alert : : tcp_ssl ) <nl> + proto = " TCP_SSL " ; <nl> + else if ( p - > sock_type = = listen_failed_alert : : i2p ) <nl> + proto = " I2P " ; <nl> + else if ( p - > sock_type = = listen_failed_alert : : socks5 ) <nl> + proto = " SOCKS5 " ; <nl> # endif <nl> - qDebug ( ) < < " Failed listening on " < < proto < < p - > endpoint . address ( ) . to_string ( ec ) . c_str ( ) < < " / " < < p - > endpoint . port ( ) ; <nl> - Logger : : instance ( ) - > addMessage ( tr ( " qBittorrent failed listening on interface % 1 port : % 2 / % 3 . Reason : % 4 " , " e . g : qBittorrent failed listening on interface 192 . 168 . 0 . 1 port : TCP / 6881 . Reason : already in use " ) . arg ( p - > endpoint . address ( ) . to_string ( ec ) . c_str ( ) ) . arg ( proto ) . arg ( QString : : number ( p - > endpoint . port ( ) ) ) . arg ( misc : : toQStringU ( p - > error . message ( ) ) ) , Log : : CRITICAL ) ; <nl> + qDebug ( ) < < " Failed listening on " < < proto < < p - > endpoint . address ( ) . to_string ( ec ) . c_str ( ) < < " / " < < p - > endpoint . port ( ) ; <nl> + Logger : : instance ( ) - > addMessage ( tr ( " qBittorrent failed listening on interface % 1 port : % 2 / % 3 . Reason : % 4 " , " e . g : qBittorrent failed listening on interface 192 . 168 . 0 . 1 port : TCP / 6881 . Reason : already in use " ) . arg ( p - > endpoint . address ( ) . to_string ( ec ) . c_str ( ) ) . arg ( proto ) . arg ( QString : : number ( p - > endpoint . port ( ) ) ) . arg ( misc : : toQStringU ( p - > error . message ( ) ) ) , Log : : CRITICAL ) ; <nl> <nl> } <nl> <nl> void QBtSession : : handleTorrentCheckedAlert ( libtorrent : : torrent_checked_alert * p ) { <nl> - QTorrentHandle h ( p - > handle ) ; <nl> - if ( h . is_valid ( ) ) { <nl> - const QString hash = h . hash ( ) ; <nl> - qDebug ( " % s have just finished checking " , qPrintable ( hash ) ) ; <nl> - / / Save seed status <nl> - TorrentPersistentData : : instance ( ) - > saveSeedStatus ( h ) ; <nl> - / / Move to temp directory if necessary <nl> - if ( ! h . is_seed ( ) & & ! defaultTempPath . isEmpty ( ) ) { <nl> - / / Check if directory is different <nl> - const QDir current_dir ( h . save_path ( ) ) ; <nl> - const QDir save_dir ( getSavePath ( h . hash ( ) ) ) ; <nl> - if ( current_dir = = save_dir ) { <nl> - qDebug ( " Moving the torrent to the temp directory . . . " ) ; <nl> - QString torrent_tmp_path = defaultTempPath ; <nl> - h . move_storage ( torrent_tmp_path ) ; <nl> - } <nl> - } <nl> - emit torrentFinishedChecking ( h ) ; <nl> - if ( torrentsToPausedAfterChecking . contains ( hash ) ) { <nl> - torrentsToPausedAfterChecking . removeOne ( hash ) ; <nl> - h . pause ( ) ; <nl> - emit pausedTorrent ( h ) ; <nl> + QTorrentHandle h ( p - > handle ) ; <nl> + if ( h . is_valid ( ) ) { <nl> + const QString hash = h . hash ( ) ; <nl> + qDebug ( " % s have just finished checking " , qPrintable ( hash ) ) ; <nl> + / / Save seed status <nl> + TorrentPersistentData : : instance ( ) - > saveSeedStatus ( h ) ; <nl> + / / Move to temp directory if necessary <nl> + if ( ! h . is_seed ( ) & & ! defaultTempPath . isEmpty ( ) ) { <nl> + / / Check if directory is different <nl> + const QDir current_dir ( h . save_path ( ) ) ; <nl> + const QDir save_dir ( getSavePath ( h . hash ( ) ) ) ; <nl> + if ( current_dir = = save_dir ) { <nl> + qDebug ( " Moving the torrent to the temp directory . . . " ) ; <nl> + QString torrent_tmp_path = defaultTempPath ; <nl> + h . move_storage ( torrent_tmp_path ) ; <nl> + } <nl> + } <nl> + emit torrentFinishedChecking ( h ) ; <nl> + if ( torrentsToPausedAfterChecking . contains ( hash ) ) { <nl> + torrentsToPausedAfterChecking . removeOne ( hash ) ; <nl> + h . pause ( ) ; <nl> + emit pausedTorrent ( h ) ; <nl> + } <nl> } <nl> - } <nl> } <nl> <nl> void QBtSession : : handleExternalIPAlert ( libtorrent : : external_ip_alert * p ) { <nl> - boost : : system : : error_code ec ; <nl> - Logger : : instance ( ) - > addMessage ( tr ( " External IP : % 1 " , " e . g . External IP : 192 . 168 . 0 . 1 " ) . arg ( p - > external_address . to_string ( ec ) . c_str ( ) ) , Log : : INFO ) ; <nl> + boost : : system : : error_code ec ; <nl> + Logger : : instance ( ) - > addMessage ( tr ( " External IP : % 1 " , " e . g . External IP : 192 . 168 . 0 . 1 " ) . arg ( p - > external_address . to_string ( ec ) . c_str ( ) ) , Log : : INFO ) ; <nl> } <nl> <nl> void QBtSession : : handleStateUpdateAlert ( libtorrent : : state_update_alert * p ) { <nl> - emit stateUpdate ( p - > status ) ; <nl> + emit stateUpdate ( p - > status ) ; <nl> } <nl> <nl> void QBtSession : : handleStatsAlert ( libtorrent : : stats_alert * p ) { <nl> - emit statsReceived ( * p ) ; <nl> + emit statsReceived ( * p ) ; <nl> } <nl> <nl> void QBtSession : : recheckTorrent ( const QString & hash ) { <nl> - QTorrentHandle h = getTorrentHandle ( hash ) ; <nl> - if ( h . is_valid ( ) & & h . has_metadata ( ) ) { <nl> - if ( h . is_paused ( ) ) { <nl> - if ( ! torrentsToPausedAfterChecking . contains ( h . hash ( ) ) ) { <nl> - torrentsToPausedAfterChecking < < h . hash ( ) ; <nl> - h . resume ( ) ; <nl> - } <nl> + QTorrentHandle h = getTorrentHandle ( hash ) ; <nl> + if ( h . is_valid ( ) & & h . has_metadata ( ) ) { <nl> + if ( h . is_paused ( ) ) { <nl> + if ( ! torrentsToPausedAfterChecking . contains ( h . hash ( ) ) ) { <nl> + torrentsToPausedAfterChecking < < h . hash ( ) ; <nl> + h . resume ( ) ; <nl> + } <nl> + } <nl> + h . force_recheck ( ) ; <nl> } <nl> - h . force_recheck ( ) ; <nl> - } <nl> } <nl> <nl> QHash < QString , TrackerInfos > QBtSession : : getTrackersInfo ( const QString & hash ) const { <nl> - return trackersInfos . value ( hash , QHash < QString , TrackerInfos > ( ) ) ; <nl> + return trackersInfos . value ( hash , QHash < QString , TrackerInfos > ( ) ) ; <nl> } <nl> <nl> int QBtSession : : getListenPort ( ) const { <nl> - qDebug ( ) < < Q_FUNC_INFO < < s - > listen_port ( ) ; <nl> - return s - > listen_port ( ) ; <nl> + qDebug ( ) < < Q_FUNC_INFO < < s - > listen_port ( ) ; <nl> + return s - > listen_port ( ) ; <nl> } <nl> <nl> session_status QBtSession : : getSessionStatus ( ) const { <nl> - return s - > status ( ) ; <nl> + return s - > status ( ) ; <nl> } <nl> <nl> void QBtSession : : applyEncryptionSettings ( pe_settings se ) { <nl> - qDebug ( " Applying encryption settings " ) ; <nl> - s - > set_pe_settings ( se ) ; <nl> + qDebug ( " Applying encryption settings " ) ; <nl> + s - > set_pe_settings ( se ) ; <nl> } <nl> <nl> / / Set Proxy <nl> void QBtSession : : setProxySettings ( proxy_settings proxySettings ) { <nl> - qDebug ( ) < < Q_FUNC_INFO ; <nl> - <nl> - proxySettings . proxy_peer_connections = Preferences : : instance ( ) - > proxyPeerConnections ( ) ; <nl> - s - > set_proxy ( proxySettings ) ; <nl> - <nl> - / / Define environment variable <nl> - QString proxy_str ; <nl> - switch ( proxySettings . type ) { <nl> - case proxy_settings : : http_pw : <nl> - proxy_str = " http : / / " + misc : : toQString ( proxySettings . username ) + " : " + misc : : toQString ( proxySettings . password ) + " @ " + misc : : toQString ( proxySettings . hostname ) + " : " + QString : : number ( proxySettings . port ) ; <nl> - break ; <nl> - case proxy_settings : : http : <nl> - proxy_str = " http : / / " + misc : : toQString ( proxySettings . hostname ) + " : " + QString : : number ( proxySettings . port ) ; <nl> - break ; <nl> - case proxy_settings : : socks5 : <nl> - proxy_str = misc : : toQString ( proxySettings . hostname ) + " : " + QString : : number ( proxySettings . port ) ; <nl> - break ; <nl> - case proxy_settings : : socks5_pw : <nl> - proxy_str = misc : : toQString ( proxySettings . username ) + " : " + misc : : toQString ( proxySettings . password ) + " @ " + misc : : toQString ( proxySettings . hostname ) + " : " + QString : : number ( proxySettings . port ) ; <nl> - break ; <nl> - default : <nl> - qDebug ( " Disabling HTTP communications proxy " ) ; <nl> - qputenv ( " http_proxy " , QByteArray ( ) ) ; <nl> - qputenv ( " sock_proxy " , QByteArray ( ) ) ; <nl> - return ; <nl> - } <nl> - / / We need this for urllib in search engine plugins <nl> - qDebug ( " HTTP communications proxy string : % s " , qPrintable ( proxy_str ) ) ; <nl> - if ( proxySettings . type = = proxy_settings : : socks5 | | proxySettings . type = = proxy_settings : : socks5_pw ) <nl> - qputenv ( " sock_proxy " , proxy_str . toLocal8Bit ( ) ) ; <nl> - else <nl> - qputenv ( " http_proxy " , proxy_str . toLocal8Bit ( ) ) ; <nl> + qDebug ( ) < < Q_FUNC_INFO ; <nl> + <nl> + proxySettings . proxy_peer_connections = Preferences : : instance ( ) - > proxyPeerConnections ( ) ; <nl> + s - > set_proxy ( proxySettings ) ; <nl> + <nl> + / / Define environment variable <nl> + QString proxy_str ; <nl> + switch ( proxySettings . type ) { <nl> + case proxy_settings : : http_pw : <nl> + proxy_str = " http : / / " + misc : : toQString ( proxySettings . username ) + " : " + misc : : toQString ( proxySettings . password ) + " @ " + misc : : toQString ( proxySettings . hostname ) + " : " + QString : : number ( proxySettings . port ) ; <nl> + break ; <nl> + case proxy_settings : : http : <nl> + proxy_str = " http : / / " + misc : : toQString ( proxySettings . hostname ) + " : " + QString : : number ( proxySettings . port ) ; <nl> + break ; <nl> + case proxy_settings : : socks5 : <nl> + proxy_str = misc : : toQString ( proxySettings . hostname ) + " : " + QString : : number ( proxySettings . port ) ; <nl> + break ; <nl> + case proxy_settings : : socks5_pw : <nl> + proxy_str = misc : : toQString ( proxySettings . username ) + " : " + misc : : toQString ( proxySettings . password ) + " @ " + misc : : toQString ( proxySettings . hostname ) + " : " + QString : : number ( proxySettings . port ) ; <nl> + break ; <nl> + default : <nl> + qDebug ( " Disabling HTTP communications proxy " ) ; <nl> + qputenv ( " http_proxy " , QByteArray ( ) ) ; <nl> + qputenv ( " sock_proxy " , QByteArray ( ) ) ; <nl> + return ; <nl> + } <nl> + / / We need this for urllib in search engine plugins <nl> + qDebug ( " HTTP communications proxy string : % s " , qPrintable ( proxy_str ) ) ; <nl> + if ( proxySettings . type = = proxy_settings : : socks5 | | proxySettings . type = = proxy_settings : : socks5_pw ) <nl> + qputenv ( " sock_proxy " , proxy_str . toLocal8Bit ( ) ) ; <nl> + else <nl> + qputenv ( " http_proxy " , proxy_str . toLocal8Bit ( ) ) ; <nl> } <nl> <nl> / / Set BT session settings ( user_agent ) <nl> void QBtSession : : setSessionSettings ( const session_settings & sessionSettings ) { <nl> - qDebug ( " Set session settings " ) ; <nl> - s - > set_settings ( sessionSettings ) ; <nl> + qDebug ( " Set session settings " ) ; <nl> + s - > set_settings ( sessionSettings ) ; <nl> } <nl> <nl> QString QBtSession : : getSavePath ( const QString & hash , bool fromScanDir , QString filePath , bool imported ) { <nl> - QString savePath ; <nl> - if ( TorrentTempData : : hasTempData ( hash ) ) { <nl> - savePath = fsutils : : fromNativePath ( TorrentTempData : : getSavePath ( hash ) ) ; <nl> - if ( savePath . isEmpty ( ) ) { <nl> - savePath = defaultSavePath ; <nl> - } <nl> - if ( ! imported & & appendLabelToSavePath ) { <nl> - qDebug ( " appendLabelToSavePath is true " ) ; <nl> - const QString label = TorrentTempData : : getLabel ( hash ) ; <nl> - if ( ! label . isEmpty ( ) ) { <nl> - savePath = fsutils : : updateLabelInSavePath ( defaultSavePath , savePath , " " , label ) ; <nl> - } <nl> - } <nl> - qDebug ( " getSavePath , got save_path from temp data : % s " , qPrintable ( savePath ) ) ; <nl> - } else { <nl> - savePath = fsutils : : fromNativePath ( TorrentPersistentData : : instance ( ) - > getSavePath ( hash ) ) ; <nl> - qDebug ( " SavePath got from persistant data is % s " , qPrintable ( savePath ) ) ; <nl> - if ( savePath . isEmpty ( ) ) { <nl> - if ( fromScanDir & & m_scanFolders - > downloadInTorrentFolder ( filePath ) ) { <nl> - savePath = QFileInfo ( filePath ) . dir ( ) . path ( ) ; <nl> - } else { <nl> - savePath = defaultSavePath ; <nl> - } <nl> - } <nl> - if ( ! fromScanDir & & appendLabelToSavePath ) { <nl> - const QString label = TorrentPersistentData : : instance ( ) - > getLabel ( hash ) ; <nl> - if ( ! label . isEmpty ( ) ) { <nl> - qDebug ( " Torrent label is % s " , qPrintable ( label ) ) ; <nl> - savePath = fsutils : : updateLabelInSavePath ( defaultSavePath , savePath , " " , label ) ; <nl> - } <nl> + QString savePath ; <nl> + if ( TorrentTempData : : hasTempData ( hash ) ) { <nl> + savePath = fsutils : : fromNativePath ( TorrentTempData : : getSavePath ( hash ) ) ; <nl> + if ( savePath . isEmpty ( ) ) { <nl> + savePath = defaultSavePath ; <nl> + } <nl> + if ( ! imported & & appendLabelToSavePath ) { <nl> + qDebug ( " appendLabelToSavePath is true " ) ; <nl> + const QString label = TorrentTempData : : getLabel ( hash ) ; <nl> + if ( ! label . isEmpty ( ) ) { <nl> + savePath = fsutils : : updateLabelInSavePath ( defaultSavePath , savePath , " " , label ) ; <nl> + } <nl> + } <nl> + qDebug ( " getSavePath , got save_path from temp data : % s " , qPrintable ( savePath ) ) ; <nl> + } else { <nl> + savePath = fsutils : : fromNativePath ( TorrentPersistentData : : instance ( ) - > getSavePath ( hash ) ) ; <nl> + qDebug ( " SavePath got from persistant data is % s " , qPrintable ( savePath ) ) ; <nl> + if ( savePath . isEmpty ( ) ) { <nl> + if ( fromScanDir & & m_scanFolders - > downloadInTorrentFolder ( filePath ) ) { <nl> + savePath = QFileInfo ( filePath ) . dir ( ) . path ( ) ; <nl> + } else { <nl> + savePath = defaultSavePath ; <nl> + } <nl> + } <nl> + if ( ! fromScanDir & & appendLabelToSavePath ) { <nl> + const QString label = TorrentPersistentData : : instance ( ) - > getLabel ( hash ) ; <nl> + if ( ! label . isEmpty ( ) ) { <nl> + qDebug ( " Torrent label is % s " , qPrintable ( label ) ) ; <nl> + savePath = fsutils : : updateLabelInSavePath ( defaultSavePath , savePath , " " , label ) ; <nl> + } <nl> + } <nl> + qDebug ( " getSavePath , got save_path from persistent data : % s " , qPrintable ( savePath ) ) ; <nl> } <nl> - qDebug ( " getSavePath , got save_path from persistent data : % s " , qPrintable ( savePath ) ) ; <nl> - } <nl> - / / Clean path <nl> - savePath = fsutils : : expandPathAbs ( savePath ) ; <nl> - if ( ! savePath . endsWith ( " / " ) ) <nl> - savePath + = " / " ; <nl> - return savePath ; <nl> + / / Clean path <nl> + savePath = fsutils : : expandPathAbs ( savePath ) ; <nl> + if ( ! savePath . endsWith ( " / " ) ) <nl> + savePath + = " / " ; <nl> + return savePath ; <nl> } <nl> <nl> / / Take an url string to a torrent file , <nl> QString QBtSession : : getSavePath ( const QString & hash , bool fromScanDir , QString f <nl> / / add it to download list <nl> void QBtSession : : downloadFromUrl ( const QString & url , const QList < QNetworkCookie > & cookies ) <nl> { <nl> - Logger : : instance ( ) - > addMessage ( tr ( " Downloading ' % 1 ' , please wait . . . " , " e . g : Downloading ' xxx . torrent ' , please wait . . . " ) . arg ( url ) ) ; <nl> - / / Launch downloader thread <nl> - downloader - > downloadTorrentUrl ( url , cookies ) ; <nl> + Logger : : instance ( ) - > addMessage ( tr ( " Downloading ' % 1 ' , please wait . . . " , " e . g : Downloading ' xxx . torrent ' , please wait . . . " ) . arg ( url ) ) ; <nl> + / / Launch downloader thread <nl> + downloader - > downloadTorrentUrl ( url , cookies ) ; <nl> } <nl> <nl> void QBtSession : : downloadFromURLList ( const QStringList & urls ) { <nl> - foreach ( const QString & url , urls ) { <nl> - downloadFromUrl ( url ) ; <nl> - } <nl> + foreach ( const QString & url , urls ) { <nl> + downloadFromUrl ( url ) ; <nl> + } <nl> } <nl> <nl> void QBtSession : : addMagnetInteractive ( const QString & uri ) <nl> { <nl> - emit newMagnetLink ( uri ) ; <nl> + emit newMagnetLink ( uri ) ; <nl> } <nl> <nl> # ifndef DISABLE_GUI <nl> - void QBtSession : : addMagnetSkipAddDlg ( const QString & uri , const QString & save_path , const QString & label , <nl> - const RssDownloadRule : : AddPausedState & aps , const QString & uri_old ) { <nl> + void QBtSession : : addMagnetSkipAddDlg ( const QString & uri , const QString & save_path , const QString & label , <nl> + const RssDownloadRule : : AddPausedState & aps , const QString & uri_old ) { <nl> # else <nl> - void QBtSession : : addMagnetSkipAddDlg ( const QString & uri , const QString & save_path , const QString & label , const QString & uri_old ) { <nl> + void QBtSession : : addMagnetSkipAddDlg ( const QString & uri , const QString & save_path , const QString & label , const QString & uri_old ) { <nl> # endif <nl> - if ( ! save_path . isEmpty ( ) | | ! label . isEmpty ( ) ) <nl> - savepathLabel_fromurl [ uri ] = qMakePair ( fsutils : : fromNativePath ( save_path ) , label ) ; <nl> + if ( ! save_path . isEmpty ( ) | | ! label . isEmpty ( ) ) <nl> + savepathLabel_fromurl [ uri ] = qMakePair ( fsutils : : fromNativePath ( save_path ) , label ) ; <nl> <nl> # ifndef DISABLE_GUI <nl> - QString hash = misc : : magnetUriToHash ( uri ) ; <nl> - switch ( aps ) { <nl> - case RssDownloadRule : : ALWAYS_PAUSED : <nl> - TorrentTempData : : setAddPaused ( hash , true ) ; <nl> - break ; <nl> - case RssDownloadRule : : NEVER_PAUSED : <nl> - TorrentTempData : : setAddPaused ( hash , false ) ; <nl> - break ; <nl> - case RssDownloadRule : : USE_GLOBAL : <nl> - default : ; <nl> - / / Use global preferences <nl> - } <nl> + QString hash = misc : : magnetUriToHash ( uri ) ; <nl> + switch ( aps ) { <nl> + case RssDownloadRule : : ALWAYS_PAUSED : <nl> + TorrentTempData : : setAddPaused ( hash , true ) ; <nl> + break ; <nl> + case RssDownloadRule : : NEVER_PAUSED : <nl> + TorrentTempData : : setAddPaused ( hash , false ) ; <nl> + break ; <nl> + case RssDownloadRule : : USE_GLOBAL : <nl> + default : ; <nl> + / / Use global preferences <nl> + } <nl> # endif <nl> <nl> - addMagnetUri ( uri , false ) ; <nl> - emit newDownloadedTorrentFromRss ( uri_old . isEmpty ( ) ? uri : uri_old ) ; <nl> + addMagnetUri ( uri , false ) ; <nl> + emit newDownloadedTorrentFromRss ( uri_old . isEmpty ( ) ? uri : uri_old ) ; <nl> } <nl> <nl> # ifndef DISABLE_GUI <nl> - void QBtSession : : downloadUrlAndSkipDialog ( QString url , QString save_path , QString label , <nl> - const QList < QNetworkCookie > & cookies , const RssDownloadRule : : AddPausedState & aps ) { <nl> + void QBtSession : : downloadUrlAndSkipDialog ( QString url , QString save_path , QString label , <nl> + const QList < QNetworkCookie > & cookies , const RssDownloadRule : : AddPausedState & aps ) { <nl> # else <nl> - void QBtSession : : downloadUrlAndSkipDialog ( QString url , QString save_path , QString label , const QList < QNetworkCookie > & cookies ) { <nl> + void QBtSession : : downloadUrlAndSkipDialog ( QString url , QString save_path , QString label , const QList < QNetworkCookie > & cookies ) { <nl> # endif <nl> - / / emit aboutToDownloadFromUrl ( url ) ; <nl> - const QUrl qurl = QUrl : : fromEncoded ( url . toUtf8 ( ) ) ; <nl> - if ( ! save_path . isEmpty ( ) | | ! label . isEmpty ( ) ) <nl> - savepathLabel_fromurl [ qurl ] = qMakePair ( fsutils : : fromNativePath ( save_path ) , label ) ; <nl> + / / emit aboutToDownloadFromUrl ( url ) ; <nl> + const QUrl qurl = QUrl : : fromEncoded ( url . toUtf8 ( ) ) ; <nl> + if ( ! save_path . isEmpty ( ) | | ! label . isEmpty ( ) ) <nl> + savepathLabel_fromurl [ qurl ] = qMakePair ( fsutils : : fromNativePath ( save_path ) , label ) ; <nl> <nl> # ifndef DISABLE_GUI <nl> - if ( aps ! = RssDownloadRule : : USE_GLOBAL ) <nl> - addpaused_fromurl [ qurl ] = aps ; <nl> + if ( aps ! = RssDownloadRule : : USE_GLOBAL ) <nl> + addpaused_fromurl [ qurl ] = aps ; <nl> # endif <nl> - url_skippingDlg < < qurl ; <nl> - / / Launch downloader thread <nl> - downloader - > downloadTorrentUrl ( url , cookies ) ; <nl> + url_skippingDlg < < qurl ; <nl> + / / Launch downloader thread <nl> + downloader - > downloadTorrentUrl ( url , cookies ) ; <nl> } <nl> <nl> / / Add to Bittorrent session the downloaded torrent file <nl> void QBtSession : : processDownloadedFile ( QString url , QString file_path ) { <nl> - const int index = url_skippingDlg . indexOf ( QUrl : : fromEncoded ( url . toUtf8 ( ) ) ) ; <nl> - if ( index < 0 ) { <nl> - / / Add file to torrent download list <nl> - file_path = fsutils : : fromNativePath ( file_path ) ; <nl> + const int index = url_skippingDlg . indexOf ( QUrl : : fromEncoded ( url . toUtf8 ( ) ) ) ; <nl> + if ( index < 0 ) { <nl> + / / Add file to torrent download list <nl> + file_path = fsutils : : fromNativePath ( file_path ) ; <nl> # ifdef Q_OS_WIN <nl> - / / Windows hack <nl> - if ( ! file_path . endsWith ( " . torrent " , Qt : : CaseInsensitive ) ) { <nl> - Q_ASSERT ( QFile : : exists ( file_path ) ) ; <nl> - qDebug ( " Torrent name does not end with . torrent , from % s " , qPrintable ( file_path ) ) ; <nl> - if ( QFile : : rename ( file_path , file_path + " . torrent " ) ) { <nl> - file_path + = " . torrent " ; <nl> - } else { <nl> - qDebug ( " Failed to rename torrent file ! " ) ; <nl> - } <nl> - } <nl> - qDebug ( " Downloading torrent at path : % s " , qPrintable ( file_path ) ) ; <nl> + / / Windows hack <nl> + if ( ! file_path . endsWith ( " . torrent " , Qt : : CaseInsensitive ) ) { <nl> + Q_ASSERT ( QFile : : exists ( file_path ) ) ; <nl> + qDebug ( " Torrent name does not end with . torrent , from % s " , qPrintable ( file_path ) ) ; <nl> + if ( QFile : : rename ( file_path , file_path + " . torrent " ) ) { <nl> + file_path + = " . torrent " ; <nl> + } else { <nl> + qDebug ( " Failed to rename torrent file ! " ) ; <nl> + } <nl> + } <nl> + qDebug ( " Downloading torrent at path : % s " , qPrintable ( file_path ) ) ; <nl> # endif <nl> - emit newDownloadedTorrent ( file_path , url ) ; <nl> - } else { <nl> - url_skippingDlg . removeAt ( index ) ; <nl> + emit newDownloadedTorrent ( file_path , url ) ; <nl> + } else { <nl> + url_skippingDlg . removeAt ( index ) ; <nl> <nl> # ifndef DISABLE_GUI <nl> - libtorrent : : error_code ec ; <nl> - / / Get hash <nl> - libtorrent : : torrent_info ti ( file_path . toStdString ( ) , ec ) ; <nl> - QString hash ; <nl> - <nl> - if ( ! ec ) { <nl> - hash = misc : : toQString ( ti . info_hash ( ) ) ; <nl> - RssDownloadRule : : AddPausedState aps = addpaused_fromurl [ url ] ; <nl> - addpaused_fromurl . remove ( url ) ; <nl> - switch ( aps ) { <nl> - case RssDownloadRule : : ALWAYS_PAUSED : <nl> - TorrentTempData : : setAddPaused ( hash , true ) ; <nl> - break ; <nl> - case RssDownloadRule : : NEVER_PAUSED : <nl> - TorrentTempData : : setAddPaused ( hash , false ) ; <nl> - break ; <nl> - case RssDownloadRule : : USE_GLOBAL : <nl> - default : ; <nl> - / / Use global preferences <nl> - } <nl> - } <nl> + libtorrent : : error_code ec ; <nl> + / / Get hash <nl> + libtorrent : : torrent_info ti ( file_path . toStdString ( ) , ec ) ; <nl> + QString hash ; <nl> + <nl> + if ( ! ec ) { <nl> + hash = misc : : toQString ( ti . info_hash ( ) ) ; <nl> + RssDownloadRule : : AddPausedState aps = addpaused_fromurl [ url ] ; <nl> + addpaused_fromurl . remove ( url ) ; <nl> + switch ( aps ) { <nl> + case RssDownloadRule : : ALWAYS_PAUSED : <nl> + TorrentTempData : : setAddPaused ( hash , true ) ; <nl> + break ; <nl> + case RssDownloadRule : : NEVER_PAUSED : <nl> + TorrentTempData : : setAddPaused ( hash , false ) ; <nl> + break ; <nl> + case RssDownloadRule : : USE_GLOBAL : <nl> + default : ; <nl> + / / Use global preferences <nl> + } <nl> + } <nl> # endif <nl> <nl> - addTorrent ( file_path , false , url , false ) ; <nl> - emit newDownloadedTorrentFromRss ( url ) ; <nl> - } <nl> + addTorrent ( file_path , false , url , false ) ; <nl> + emit newDownloadedTorrentFromRss ( url ) ; <nl> + } <nl> } <nl> <nl> / / Return current download rate for the BT <nl> / / session . Payload means that it only take into <nl> / / account " useful " part of the rate <nl> qreal QBtSession : : getPayloadDownloadRate ( ) const { <nl> - return s - > status ( ) . payload_download_rate ; <nl> + return s - > status ( ) . payload_download_rate ; <nl> } <nl> <nl> / / Return current upload rate for the BT <nl> / / session . Payload means that it only take into <nl> / / account " useful " part of the rate <nl> qreal QBtSession : : getPayloadUploadRate ( ) const { <nl> - return s - > status ( ) . payload_upload_rate ; <nl> + return s - > status ( ) . payload_upload_rate ; <nl> } <nl> <nl> / / Will fast resume torrents in <nl> / / backup directory <nl> void QBtSession : : startUpTorrents ( ) { <nl> - qDebug ( " Resuming unfinished torrents " ) ; <nl> - const QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ; <nl> - const TorrentPersistentData * const TorPersistent = TorrentPersistentData : : instance ( ) ; <nl> - const QStringList known_torrents = TorPersistent - > knownTorrents ( ) ; <nl> - <nl> - / / Safety measure because some people reported torrent loss since <nl> - / / we switch the v1 . 5 way of resuming torrents on startup <nl> - QStringList filters ; <nl> - filters < < " * . torrent " ; <nl> - const QStringList torrents_on_hd = torrentBackup . entryList ( filters , QDir : : Files , QDir : : Unsorted ) ; <nl> - foreach ( QString hash , torrents_on_hd ) { <nl> - hash . chop ( 8 ) ; / / remove trailing . torrent <nl> - if ( ! known_torrents . contains ( hash ) ) { <nl> - qDebug ( " found torrent with hash : % s on hard disk " , qPrintable ( hash ) ) ; <nl> - std : : cerr < < " ERROR Detected ! ! ! Adding back torrent " < < qPrintable ( hash ) < < " which got lost for some reason . " < < std : : endl ; <nl> - addTorrent ( torrentBackup . path ( ) + " / " + hash + " . torrent " , false , QString ( ) , true ) ; <nl> - } <nl> - } <nl> - / / End of safety measure <nl> - <nl> - qDebug ( " Starting up torrents " ) ; <nl> - if ( isQueueingEnabled ( ) ) { <nl> - priority_queue < QPair < int , QString > , vector < QPair < int , QString > > , std : : greater < QPair < int , QString > > > torrent_queue ; <nl> - foreach ( const QString & hash , known_torrents ) { <nl> - const int prio = TorPersistent - > getPriority ( hash ) ; <nl> - torrent_queue . push ( qMakePair ( prio , hash ) ) ; <nl> - } <nl> - qDebug ( " Priority_queue size : % ld " , ( long ) torrent_queue . size ( ) ) ; <nl> - / / Resume downloads <nl> - while ( ! torrent_queue . empty ( ) ) { <nl> - const QString hash = torrent_queue . top ( ) . second ; <nl> - torrent_queue . pop ( ) ; <nl> - qDebug ( " Starting up torrent % s " , qPrintable ( hash ) ) ; <nl> - if ( TorPersistent - > isMagnet ( hash ) ) { <nl> - addMagnetUri ( TorPersistent - > getMagnetUri ( hash ) , true ) ; <nl> - } else { <nl> - addTorrent ( torrentBackup . path ( ) + " / " + hash + " . torrent " , false , QString ( ) , true ) ; <nl> - } <nl> + qDebug ( " Resuming unfinished torrents " ) ; <nl> + const QDir torrentBackup ( fsutils : : BTBackupLocation ( ) ) ; <nl> + const TorrentPersistentData * const TorPersistent = TorrentPersistentData : : instance ( ) ; <nl> + const QStringList known_torrents = TorPersistent - > knownTorrents ( ) ; <nl> + <nl> + / / Safety measure because some people reported torrent loss since <nl> + / / we switch the v1 . 5 way of resuming torrents on startup <nl> + QStringList filters ; <nl> + filters < < " * . torrent " ; <nl> + const QStringList torrents_on_hd = torrentBackup . entryList ( filters , QDir : : Files , QDir : : Unsorted ) ; <nl> + foreach ( QString hash , torrents_on_hd ) { <nl> + hash . chop ( 8 ) ; / / remove trailing . torrent <nl> + if ( ! known_torrents . contains ( hash ) ) { <nl> + qDebug ( " found torrent with hash : % s on hard disk " , qPrintable ( hash ) ) ; <nl> + std : : cerr < < " ERROR Detected ! ! ! Adding back torrent " < < qPrintable ( hash ) < < " which got lost for some reason . " < < std : : endl ; <nl> + addTorrent ( torrentBackup . path ( ) + " / " + hash + " . torrent " , false , QString ( ) , true ) ; <nl> + } <nl> } <nl> - } else { <nl> - / / Resume downloads <nl> - foreach ( const QString & hash , known_torrents ) { <nl> - qDebug ( " Starting up torrent % s " , qPrintable ( hash ) ) ; <nl> - if ( TorPersistent - > isMagnet ( hash ) ) <nl> - addMagnetUri ( TorPersistent - > getMagnetUri ( hash ) , true ) ; <nl> - else <nl> - addTorrent ( torrentBackup . path ( ) + " / " + hash + " . torrent " , false , QString ( ) , true ) ; <nl> + / / End of safety measure <nl> + <nl> + qDebug ( " Starting up torrents " ) ; <nl> + if ( isQueueingEnabled ( ) ) { <nl> + priority_queue < QPair < int , QString > , vector < QPair < int , QString > > , std : : greater < QPair < int , QString > > > torrent_queue ; <nl> + foreach ( const QString & hash , known_torrents ) { <nl> + const int prio = TorPersistent - > getPriority ( hash ) ; <nl> + torrent_queue . push ( qMakePair ( prio , hash ) ) ; <nl> + } <nl> + qDebug ( " Priority_queue size : % ld " , ( long ) torrent_queue . size ( ) ) ; <nl> + / / Resume downloads <nl> + while ( ! torrent_queue . empty ( ) ) { <nl> + const QString hash = torrent_queue . top ( ) . second ; <nl> + torrent_queue . pop ( ) ; <nl> + qDebug ( " Starting up torrent % s " , qPrintable ( hash ) ) ; <nl> + if ( TorPersistent - > isMagnet ( hash ) ) { <nl> + addMagnetUri ( TorPersistent - > getMagnetUri ( hash ) , true ) ; <nl> + } else { <nl> + addTorrent ( torrentBackup . path ( ) + " / " + hash + " . torrent " , false , QString ( ) , true ) ; <nl> + } <nl> + } <nl> + } else { <nl> + / / Resume downloads <nl> + foreach ( const QString & hash , known_torrents ) { <nl> + qDebug ( " Starting up torrent % s " , qPrintable ( hash ) ) ; <nl> + if ( TorPersistent - > isMagnet ( hash ) ) <nl> + addMagnetUri ( TorPersistent - > getMagnetUri ( hash ) , true ) ; <nl> + else <nl> + addTorrent ( torrentBackup . path ( ) + " / " + hash + " . torrent " , false , QString ( ) , true ) ; <nl> + } <nl> } <nl> - } <nl> - qDebug ( " Unfinished torrents resumed " ) ; <nl> + qDebug ( " Unfinished torrents resumed " ) ; <nl> } <nl> <nl> QBtSession * QBtSession : : instance ( ) <nl> { <nl> - if ( ! m_instance ) { <nl> - m_instance = new QBtSession ; <nl> - } <nl> - return m_instance ; <nl> + if ( ! m_instance ) { <nl> + m_instance = new QBtSession ; <nl> + } <nl> + return m_instance ; <nl> } <nl> <nl> void QBtSession : : drop ( ) <nl> { <nl> - if ( m_instance ) { <nl> - delete m_instance ; <nl> - m_instance = 0 ; <nl> - } <nl> + if ( m_instance ) { <nl> + delete m_instance ; <nl> + m_instance = 0 ; <nl> + } <nl> } <nl> <nl> qlonglong QBtSession : : getETA ( const QString & hash , const libtorrent : : torrent_status & status ) const <nl> { <nl> - return m_speedMonitor - > getETA ( hash , status ) ; <nl> + return m_speedMonitor - > getETA ( hash , status ) ; <nl> } <nl> <nl> quint64 QBtSession : : getAlltimeDL ( ) const { <nl> - return m_torrentStatistics - > getAlltimeDL ( ) ; <nl> + return m_torrentStatistics - > getAlltimeDL ( ) ; <nl> } <nl> <nl> quint64 QBtSession : : getAlltimeUL ( ) const { <nl> - return m_torrentStatistics - > getAlltimeUL ( ) ; <nl> + return m_torrentStatistics - > getAlltimeUL ( ) ; <nl> } <nl> <nl> void QBtSession : : postTorrentUpdate ( ) { <nl> - s - > post_torrent_updates ( ) ; <nl> + s - > post_torrent_updates ( ) ; <nl> } <nl> <nl> void QBtSession : : handleIPFilterParsed ( int ruleCount ) <nl> { <nl> - Logger : : instance ( ) - > addMessage ( tr ( " Successfully parsed the provided IP filter : % 1 rules were applied . " , " % 1 is a number " ) . arg ( ruleCount ) ) ; <nl> - emit ipFilterParsed ( false , ruleCount ) ; <nl> + Logger : : instance ( ) - > addMessage ( tr ( " Successfully parsed the provided IP filter : % 1 rules were applied . " , " % 1 is a number " ) . arg ( ruleCount ) ) ; <nl> + emit ipFilterParsed ( false , ruleCount ) ; <nl> } <nl> <nl> void QBtSession : : handleIPFilterError ( ) <nl> { <nl> - Logger : : instance ( ) - > addMessage ( tr ( " Error : Failed to parse the provided IP filter . " ) , Log : : CRITICAL ) ; <nl> - emit ipFilterParsed ( true , 0 ) ; <nl> + Logger : : instance ( ) - > addMessage ( tr ( " Error : Failed to parse the provided IP filter . " ) , Log : : CRITICAL ) ; <nl> + emit ipFilterParsed ( true , 0 ) ; <nl> } <nl> <nl> void QBtSession : : recoverPersistentData ( const QString & hash , const std : : vector < char > & buf ) { <nl> - TorrentPersistentData * const TorPersistent = TorrentPersistentData : : instance ( ) ; <nl> - if ( TorPersistent - > isKnownTorrent ( hash ) | | TorrentTempData : : hasTempData ( hash ) | | buf . empty ( ) ) <nl> - return ; <nl> + TorrentPersistentData * const TorPersistent = TorrentPersistentData : : instance ( ) ; <nl> + if ( TorPersistent - > isKnownTorrent ( hash ) | | TorrentTempData : : hasTempData ( hash ) | | buf . empty ( ) ) <nl> + return ; <nl> <nl> - libtorrent : : lazy_entry fast ; <nl> - libtorrent : : error_code ec ; <nl> + libtorrent : : lazy_entry fast ; <nl> + libtorrent : : error_code ec ; <nl> <nl> - libtorrent : : lazy_bdecode ( & ( buf . front ( ) ) , & ( buf . back ( ) ) , fast , ec ) ; <nl> - if ( fast . type ( ) ! = libtorrent : : lazy_entry : : dict_t & & ! ec ) <nl> - return ; <nl> + libtorrent : : lazy_bdecode ( & ( buf . front ( ) ) , & ( buf . back ( ) ) , fast , ec ) ; <nl> + if ( fast . type ( ) ! = libtorrent : : lazy_entry : : dict_t & & ! ec ) <nl> + return ; <nl> <nl> - QString savePath = fsutils : : fromNativePath ( QString : : fromUtf8 ( fast . dict_find_string_value ( " qBt - savePath " ) . c_str ( ) ) ) ; <nl> - qreal ratioLimit = QString : : fromUtf8 ( fast . dict_find_string_value ( " qBt - ratioLimit " ) . c_str ( ) ) . toDouble ( ) ; <nl> - QDateTime addedDate = QDateTime : : fromTime_t ( fast . dict_find_int_value ( " added_time " ) ) ; <nl> - QString label = QString : : fromUtf8 ( fast . dict_find_string_value ( " qBt - label " ) . c_str ( ) ) ; <nl> - int priority = fast . dict_find_int_value ( " qBt - queuePosition " ) ; <nl> - bool seedStatus = fast . dict_find_int_value ( " qBt - seedStatus " ) ; <nl> + QString savePath = fsutils : : fromNativePath ( QString : : fromUtf8 ( fast . dict_find_string_value ( " qBt - savePath " ) . c_str ( ) ) ) ; <nl> + qreal ratioLimit = QString : : fromUtf8 ( fast . dict_find_string_value ( " qBt - ratioLimit " ) . c_str ( ) ) . toDouble ( ) ; <nl> + QDateTime addedDate = QDateTime : : fromTime_t ( fast . dict_find_int_value ( " added_time " ) ) ; <nl> + QString label = QString : : fromUtf8 ( fast . dict_find_string_value ( " qBt - label " ) . c_str ( ) ) ; <nl> + int priority = fast . dict_find_int_value ( " qBt - queuePosition " ) ; <nl> + bool seedStatus = fast . dict_find_int_value ( " qBt - seedStatus " ) ; <nl> <nl> - TorPersistent - > saveSavePath ( hash , savePath ) ; <nl> - TorPersistent - > setRatioLimit ( hash , ratioLimit ) ; <nl> - TorPersistent - > setAddedDate ( hash , addedDate ) ; <nl> - TorPersistent - > saveLabel ( hash , label ) ; <nl> - TorPersistent - > savePriority ( hash , priority ) ; <nl> - TorPersistent - > saveSeedStatus ( hash , seedStatus ) ; <nl> + TorPersistent - > saveSavePath ( hash , savePath ) ; <nl> + TorPersistent - > setRatioLimit ( hash , ratioLimit ) ; <nl> + TorPersistent - > setAddedDate ( hash , addedDate ) ; <nl> + TorPersistent - > saveLabel ( hash , label ) ; <nl> + TorPersistent - > savePriority ( hash , priority ) ; <nl> + TorPersistent - > saveSeedStatus ( hash , seedStatus ) ; <nl> } <nl> <nl> void QBtSession : : backupPersistentData ( const QString & hash , boost : : shared_ptr < libtorrent : : entry > data ) { <nl> - const TorrentPersistentData * const TorPersistent = TorrentPersistentData : : instance ( ) ; <nl> - ( * data ) [ " qBt - savePath " ] = fsutils : : fromNativePath ( TorPersistent - > getSavePath ( hash ) ) . toUtf8 ( ) . constData ( ) ; <nl> - ( * data ) [ " qBt - ratioLimit " ] = QString : : number ( TorPersistent - > getRatioLimit ( hash ) ) . toUtf8 ( ) . constData ( ) ; <nl> - ( * data ) [ " qBt - label " ] = TorPersistent - > getLabel ( hash ) . toUtf8 ( ) . constData ( ) ; <nl> - ( * data ) [ " qBt - queuePosition " ] = TorPersistent - > getPriority ( hash ) ; <nl> - ( * data ) [ " qBt - seedStatus " ] = ( int ) TorPersistent - > isSeed ( hash ) ; <nl> + const TorrentPersistentData * const TorPersistent = TorrentPersistentData : : instance ( ) ; <nl> + ( * data ) [ " qBt - savePath " ] = fsutils : : fromNativePath ( TorPersistent - > getSavePath ( hash ) ) . toUtf8 ( ) . constData ( ) ; <nl> + ( * data ) [ " qBt - ratioLimit " ] = QString : : number ( TorPersistent - > getRatioLimit ( hash ) ) . toUtf8 ( ) . constData ( ) ; <nl> + ( * data ) [ " qBt - label " ] = TorPersistent - > getLabel ( hash ) . toUtf8 ( ) . constData ( ) ; <nl> + ( * data ) [ " qBt - queuePosition " ] = TorPersistent - > getPriority ( hash ) ; <nl> + ( * data ) [ " qBt - seedStatus " ] = ( int ) TorPersistent - > isSeed ( hash ) ; <nl> } <nl> <nl> void QBtSession : : unhideMagnet ( const QString & hash ) { <nl> - Preferences * const pref = Preferences : : instance ( ) ; <nl> - HiddenData : : deleteData ( hash ) ; <nl> - QString save_path = getSavePath ( hash , false ) ; / / appends label if necessary <nl> - QTorrentHandle h ( getTorrentHandle ( hash ) ) ; <nl> + Preferences * const pref = Preferences : : instance ( ) ; <nl> + HiddenData : : deleteData ( hash ) ; <nl> + QString save_path = getSavePath ( hash , false ) ; / / appends label if necessary <nl> + QTorrentHandle h ( getTorrentHandle ( hash ) ) ; <nl> <nl> - if ( ! h . is_valid ( ) ) { <nl> - if ( pref - > isQueueingSystemEnabled ( ) ) { <nl> - / / Internally decrease the queue limits to ensure that other queued items aren ' t started <nl> - libtorrent : : session_settings sessionSettings ( s - > settings ( ) ) ; <nl> - int max_downloading = pref - > getMaxActiveDownloads ( ) ; <nl> - int max_active = pref - > getMaxActiveTorrents ( ) ; <nl> - if ( max_downloading > - 1 ) <nl> - sessionSettings . active_downloads = max_downloading + HiddenData : : getDownloadingSize ( ) ; <nl> - else <nl> - sessionSettings . active_downloads = max_downloading ; <nl> - if ( max_active > - 1 ) <nl> - sessionSettings . active_limit = max_active + HiddenData : : getDownloadingSize ( ) ; <nl> - else <nl> - sessionSettings . active_limit = max_active ; <nl> - s - > set_settings ( sessionSettings ) ; <nl> - } <nl> - TorrentTempData : : deleteTempData ( hash ) ; <nl> - return ; <nl> - } <nl> + if ( ! h . is_valid ( ) ) { <nl> + if ( pref - > isQueueingSystemEnabled ( ) ) { <nl> + / / Internally decrease the queue limits to ensure that other queued items aren ' t started <nl> + libtorrent : : session_settings sessionSettings ( s - > settings ( ) ) ; <nl> + int max_downloading = pref - > getMaxActiveDownloads ( ) ; <nl> + int max_active = pref - > getMaxActiveTorrents ( ) ; <nl> + if ( max_downloading > - 1 ) <nl> + sessionSettings . active_downloads = max_downloading + HiddenData : : getDownloadingSize ( ) ; <nl> + else <nl> + sessionSettings . active_downloads = max_downloading ; <nl> + if ( max_active > - 1 ) <nl> + sessionSettings . active_limit = max_active + HiddenData : : getDownloadingSize ( ) ; <nl> + else <nl> + sessionSettings . active_limit = max_active ; <nl> + s - > set_settings ( sessionSettings ) ; <nl> + } <nl> + TorrentTempData : : deleteTempData ( hash ) ; <nl> + return ; <nl> + } <nl> + <nl> + bool add_paused = pref - > addTorrentsInPause ( ) ; <nl> + if ( TorrentTempData : : hasTempData ( hash ) ) { <nl> + add_paused = TorrentTempData : : isAddPaused ( hash ) ; <nl> + } <nl> + <nl> + if ( ! h . has_metadata ( ) ) { <nl> + if ( pref - > isQueueingSystemEnabled ( ) ) { <nl> + / / Internally decrease the queue limits to ensure that other queued items aren ' t started <nl> + libtorrent : : session_settings sessionSettings ( s - > settings ( ) ) ; <nl> + int max_downloading = pref - > getMaxActiveDownloads ( ) ; <nl> + int max_active = pref - > getMaxActiveTorrents ( ) ; <nl> + if ( max_downloading > - 1 ) <nl> + sessionSettings . active_downloads = max_downloading + HiddenData : : getDownloadingSize ( ) ; <nl> + else <nl> + sessionSettings . active_downloads = max_downloading ; <nl> + if ( max_active > - 1 ) <nl> + sessionSettings . active_limit = max_active + HiddenData : : getDownloadingSize ( ) ; <nl> + else <nl> + sessionSettings . active_limit = max_active ; <nl> + s - > set_settings ( sessionSettings ) ; <nl> + } <nl> + if ( add_paused ) <nl> + h . pause ( ) ; <nl> + } <nl> <nl> - bool add_paused = pref - > addTorrentsInPause ( ) ; <nl> - if ( TorrentTempData : : hasTempData ( hash ) ) { <nl> - add_paused = TorrentTempData : : isAddPaused ( hash ) ; <nl> - } <nl> + h . queue_position_bottom ( ) ; <nl> + loadTorrentTempData ( h , h . save_path ( ) , ! h . has_metadata ( ) ) ; / / TempData are deleted by a call to TorrentPersistentData : : instance ( ) - > saveTorrentPersistentData ( ) <nl> + if ( ! add_paused ) <nl> + h . resume ( ) ; <nl> + h . move_storage ( save_path ) ; <nl> <nl> - if ( ! h . has_metadata ( ) ) { <nl> - if ( pref - > isQueueingSystemEnabled ( ) ) { <nl> - / / Internally decrease the queue limits to ensure that other queued items aren ' t started <nl> - libtorrent : : session_settings sessionSettings ( s - > settings ( ) ) ; <nl> - int max_downloading = pref - > getMaxActiveDownloads ( ) ; <nl> - int max_active = pref - > getMaxActiveTorrents ( ) ; <nl> - if ( max_downloading > - 1 ) <nl> - sessionSettings . active_downloads = max_downloading + HiddenData : : getDownloadingSize ( ) ; <nl> - else <nl> - sessionSettings . active_downloads = max_downloading ; <nl> - if ( max_active > - 1 ) <nl> - sessionSettings . active_limit = max_active + HiddenData : : getDownloadingSize ( ) ; <nl> - else <nl> - sessionSettings . active_limit = max_active ; <nl> - s - > set_settings ( sessionSettings ) ; <nl> - } <nl> - if ( add_paused ) <nl> - h . pause ( ) ; <nl> - } <nl> - <nl> - h . queue_position_bottom ( ) ; <nl> - loadTorrentTempData ( h , h . save_path ( ) , ! h . has_metadata ( ) ) ; / / TempData are deleted by a call to TorrentPersistentData : : instance ( ) - > saveTorrentPersistentData ( ) <nl> - if ( ! add_paused ) <nl> - h . resume ( ) ; <nl> - h . move_storage ( save_path ) ; <nl> - <nl> - emit addedTorrent ( h ) ; <nl> + emit addedTorrent ( h ) ; <nl> } <nl> mmm a / src / core / qtlibtorrent / qbtsession . h <nl> ppp b / src / core / qtlibtorrent / qbtsession . h <nl> <nl> # endif <nl> <nl> namespace libtorrent { <nl> - struct add_torrent_params ; <nl> - struct pe_settings ; <nl> - struct proxy_settings ; <nl> - class session ; <nl> - struct session_status ; <nl> + struct add_torrent_params ; <nl> + struct pe_settings ; <nl> + struct proxy_settings ; <nl> + class session ; <nl> + struct session_status ; <nl> <nl> - class alert ; <nl> - struct torrent_finished_alert ; <nl> - struct save_resume_data_alert ; <nl> - struct file_renamed_alert ; <nl> - struct torrent_deleted_alert ; <nl> - struct storage_moved_alert ; <nl> - struct storage_moved_failed_alert ; <nl> - struct metadata_received_alert ; <nl> - struct file_error_alert ; <nl> - struct file_completed_alert ; <nl> - struct torrent_paused_alert ; <nl> - struct tracker_error_alert ; <nl> - struct tracker_reply_alert ; <nl> - struct tracker_warning_alert ; <nl> - struct portmap_error_alert ; <nl> - struct portmap_alert ; <nl> - struct peer_blocked_alert ; <nl> - struct peer_ban_alert ; <nl> - struct fastresume_rejected_alert ; <nl> - struct url_seed_alert ; <nl> - struct listen_succeeded_alert ; <nl> - struct listen_failed_alert ; <nl> - struct torrent_checked_alert ; <nl> - struct external_ip_alert ; <nl> - struct state_update_alert ; <nl> - struct stats_alert ; <nl> + class alert ; <nl> + struct torrent_finished_alert ; <nl> + struct save_resume_data_alert ; <nl> + struct file_renamed_alert ; <nl> + struct torrent_deleted_alert ; <nl> + struct storage_moved_alert ; <nl> + struct storage_moved_failed_alert ; <nl> + struct metadata_received_alert ; <nl> + struct file_error_alert ; <nl> + struct file_completed_alert ; <nl> + struct torrent_paused_alert ; <nl> + struct tracker_error_alert ; <nl> + struct tracker_reply_alert ; <nl> + struct tracker_warning_alert ; <nl> + struct portmap_error_alert ; <nl> + struct portmap_alert ; <nl> + struct peer_blocked_alert ; <nl> + struct peer_ban_alert ; <nl> + struct fastresume_rejected_alert ; <nl> + struct url_seed_alert ; <nl> + struct listen_succeeded_alert ; <nl> + struct listen_failed_alert ; <nl> + struct torrent_checked_alert ; <nl> + struct external_ip_alert ; <nl> + struct state_update_alert ; <nl> + struct stats_alert ; <nl> <nl> # if LIBTORRENT_VERSION_NUM < 10000 <nl> - class upnp ; <nl> - class natpmp ; <nl> + class upnp ; <nl> + class natpmp ; <nl> # endif <nl> } <nl> <nl> class TorrentStatistics ; <nl> class QAlertDispatcher ; <nl> <nl> enum TorrentExportFolder { <nl> - RegularTorrentExportFolder , <nl> - FinishedTorrentExportFolder <nl> + RegularTorrentExportFolder , <nl> + FinishedTorrentExportFolder <nl> } ; <nl> <nl> class QTracker ; <nl> <nl> class QBtSession : public QObject { <nl> - Q_OBJECT <nl> - Q_DISABLE_COPY ( QBtSession ) <nl> + Q_OBJECT <nl> + Q_DISABLE_COPY ( QBtSession ) <nl> <nl> public : <nl> - static const qreal MAX_RATIO ; <nl> + static const qreal MAX_RATIO ; <nl> <nl> private : <nl> - explicit QBtSession ( ) ; <nl> - static QBtSession * m_instance ; <nl> + explicit QBtSession ( ) ; <nl> + static QBtSession * m_instance ; <nl> <nl> public : <nl> - static QBtSession * instance ( ) ; <nl> - static void drop ( ) ; <nl> - ~ QBtSession ( ) ; <nl> - QTorrentHandle getTorrentHandle ( const QString & hash ) const ; <nl> - std : : vector < libtorrent : : torrent_handle > getTorrents ( ) const ; <nl> - bool isFilePreviewPossible ( const QString & hash ) const ; <nl> - qreal getPayloadDownloadRate ( ) const ; <nl> - qreal getPayloadUploadRate ( ) const ; <nl> - libtorrent : : session_status getSessionStatus ( ) const ; <nl> - int getListenPort ( ) const ; <nl> - qreal getRealRatio ( const libtorrent : : torrent_status & status ) const ; <nl> - QHash < QString , TrackerInfos > getTrackersInfo ( const QString & hash ) const ; <nl> - bool hasActiveTorrents ( ) const ; <nl> - bool hasDownloadingTorrents ( ) const ; <nl> - / / int getMaximumActiveDownloads ( ) const ; <nl> - / / int getMaximumActiveTorrents ( ) const ; <nl> - inline libtorrent : : session * getSession ( ) const { return s ; } <nl> - inline bool useTemporaryFolder ( ) const { return ! defaultTempPath . isEmpty ( ) ; } <nl> - inline QString getDefaultSavePath ( ) const { return defaultSavePath ; } <nl> - inline ScanFoldersModel * getScanFoldersModel ( ) const { return m_scanFolders ; } <nl> - inline bool isDHTEnabled ( ) const { return DHTEnabled ; } <nl> - inline bool isLSDEnabled ( ) const { return LSDEnabled ; } <nl> - inline bool isPexEnabled ( ) const { return PeXEnabled ; } <nl> - inline bool isQueueingEnabled ( ) const { return queueingEnabled ; } <nl> - quint64 getAlltimeDL ( ) const ; <nl> - quint64 getAlltimeUL ( ) const ; <nl> - void postTorrentUpdate ( ) ; <nl> + static QBtSession * instance ( ) ; <nl> + static void drop ( ) ; <nl> + ~ QBtSession ( ) ; <nl> + QTorrentHandle getTorrentHandle ( const QString & hash ) const ; <nl> + std : : vector < libtorrent : : torrent_handle > getTorrents ( ) const ; <nl> + bool isFilePreviewPossible ( const QString & hash ) const ; <nl> + qreal getPayloadDownloadRate ( ) const ; <nl> + qreal getPayloadUploadRate ( ) const ; <nl> + libtorrent : : session_status getSessionStatus ( ) const ; <nl> + int getListenPort ( ) const ; <nl> + qreal getRealRatio ( const libtorrent : : torrent_status & status ) const ; <nl> + QHash < QString , TrackerInfos > getTrackersInfo ( const QString & hash ) const ; <nl> + bool hasActiveTorrents ( ) const ; <nl> + bool hasDownloadingTorrents ( ) const ; <nl> + / / int getMaximumActiveDownloads ( ) const ; <nl> + / / int getMaximumActiveTorrents ( ) const ; <nl> + inline libtorrent : : session * getSession ( ) const { return s ; } <nl> + inline bool useTemporaryFolder ( ) const { return ! defaultTempPath . isEmpty ( ) ; } <nl> + inline QString getDefaultSavePath ( ) const { return defaultSavePath ; } <nl> + inline ScanFoldersModel * getScanFoldersModel ( ) const { return m_scanFolders ; } <nl> + inline bool isDHTEnabled ( ) const { return DHTEnabled ; } <nl> + inline bool isLSDEnabled ( ) const { return LSDEnabled ; } <nl> + inline bool isPexEnabled ( ) const { return PeXEnabled ; } <nl> + inline bool isQueueingEnabled ( ) const { return queueingEnabled ; } <nl> + quint64 getAlltimeDL ( ) const ; <nl> + quint64 getAlltimeUL ( ) const ; <nl> + void postTorrentUpdate ( ) ; <nl> <nl> public slots : <nl> - QTorrentHandle addTorrent ( QString path , bool fromScanDir = false , QString from_url = QString ( ) , bool resumed = false , bool imported = false ) ; <nl> - QTorrentHandle addMagnetUri ( QString magnet_uri , bool resumed = false , bool fromScanDir = false , const QString & filePath = QString ( ) ) ; <nl> - void loadSessionState ( ) ; <nl> - void saveSessionState ( ) ; <nl> - void downloadFromUrl ( const QString & url , const QList < QNetworkCookie > & cookies = QList < QNetworkCookie > ( ) ) ; <nl> - void deleteTorrent ( const QString & hash , bool delete_local_files = false ) ; <nl> - void startUpTorrents ( ) ; <nl> - void recheckTorrent ( const QString & hash ) ; <nl> - void useAlternativeSpeedsLimit ( bool alternative ) ; <nl> - qlonglong getETA ( const QString & hash , const libtorrent : : torrent_status & status ) const ; <nl> - / * Needed by Web UI * / <nl> - void pauseAllTorrents ( ) ; <nl> - void pauseTorrent ( const QString & hash ) ; <nl> - void resumeTorrent ( const QString & hash ) ; <nl> - void resumeAllTorrents ( ) ; <nl> - / * End Web UI * / <nl> - void preAllocateAllFiles ( bool b ) ; <nl> - void saveFastResumeData ( ) ; <nl> - void enableIPFilter ( const QString & filter_path , bool force = false ) ; <nl> - void disableIPFilter ( ) ; <nl> - void setQueueingEnabled ( bool enable ) ; <nl> - void handleDownloadFailure ( QString url , QString reason ) ; <nl> - void handleMagnetRedirect ( const QString & url_new , const QString & url_old ) ; <nl> + QTorrentHandle addTorrent ( QString path , bool fromScanDir = false , QString from_url = QString ( ) , bool resumed = false , bool imported = false ) ; <nl> + QTorrentHandle addMagnetUri ( QString magnet_uri , bool resumed = false , bool fromScanDir = false , const QString & filePath = QString ( ) ) ; <nl> + void loadSessionState ( ) ; <nl> + void saveSessionState ( ) ; <nl> + void downloadFromUrl ( const QString & url , const QList < QNetworkCookie > & cookies = QList < QNetworkCookie > ( ) ) ; <nl> + void deleteTorrent ( const QString & hash , bool delete_local_files = false ) ; <nl> + void startUpTorrents ( ) ; <nl> + void recheckTorrent ( const QString & hash ) ; <nl> + void useAlternativeSpeedsLimit ( bool alternative ) ; <nl> + qlonglong getETA ( const QString & hash , const libtorrent : : torrent_status & status ) const ; <nl> + / * Needed by Web UI * / <nl> + void pauseAllTorrents ( ) ; <nl> + void pauseTorrent ( const QString & hash ) ; <nl> + void resumeTorrent ( const QString & hash ) ; <nl> + void resumeAllTorrents ( ) ; <nl> + / * End Web UI * / <nl> + void preAllocateAllFiles ( bool b ) ; <nl> + void saveFastResumeData ( ) ; <nl> + void enableIPFilter ( const QString & filter_path , bool force = false ) ; <nl> + void disableIPFilter ( ) ; <nl> + void setQueueingEnabled ( bool enable ) ; <nl> + void handleDownloadFailure ( QString url , QString reason ) ; <nl> + void handleMagnetRedirect ( const QString & url_new , const QString & url_old ) ; <nl> # ifndef DISABLE_GUI <nl> - void downloadUrlAndSkipDialog ( QString url , QString save_path = QString ( ) , QString label = QString ( ) , <nl> - const QList < QNetworkCookie > & cookies = QList < QNetworkCookie > ( ) , <nl> - const RssDownloadRule : : AddPausedState & aps = RssDownloadRule : : USE_GLOBAL ) ; <nl> + void downloadUrlAndSkipDialog ( QString url , QString save_path = QString ( ) , QString label = QString ( ) , <nl> + const QList < QNetworkCookie > & cookies = QList < QNetworkCookie > ( ) , <nl> + const RssDownloadRule : : AddPausedState & aps = RssDownloadRule : : USE_GLOBAL ) ; <nl> # else <nl> - void downloadUrlAndSkipDialog ( QString url , QString save_path = QString ( ) , QString label = QString ( ) , <nl> - const QList < QNetworkCookie > & cookies = QList < QNetworkCookie > ( ) ) ; <nl> + void downloadUrlAndSkipDialog ( QString url , QString save_path = QString ( ) , QString label = QString ( ) , <nl> + const QList < QNetworkCookie > & cookies = QList < QNetworkCookie > ( ) ) ; <nl> # endif <nl> - / / Session configuration - Setters <nl> - void setListeningPort ( int port ) ; <nl> - void setMaxConnectionsPerTorrent ( int max ) ; <nl> - void setMaxUploadsPerTorrent ( int max ) ; <nl> - void setDownloadRateLimit ( long rate ) ; <nl> - void setUploadRateLimit ( long rate ) ; <nl> - void setGlobalMaxRatio ( qreal ratio ) ; <nl> - qreal getGlobalMaxRatio ( ) const { return global_ratio_limit ; } <nl> - void setMaxRatioPerTorrent ( const QString & hash , qreal ratio ) ; <nl> - qreal getMaxRatioPerTorrent ( const QString & hash , bool * usesGlobalRatio ) const ; <nl> - void removeRatioPerTorrent ( const QString & hash ) ; <nl> - void setDefaultSavePath ( const QString & savepath ) ; <nl> - void setDefaultTempPath ( const QString & temppath ) ; <nl> - void setAppendLabelToSavePath ( bool append ) ; <nl> - void appendLabelToTorrentSavePath ( const QTorrentHandle & h ) ; <nl> - void changeLabelInTorrentSavePath ( const QTorrentHandle & h , QString old_label , QString new_label ) ; <nl> - void appendqBextensionToTorrent ( const QTorrentHandle & h , bool append ) ; <nl> - void setAppendqBExtension ( bool append ) ; <nl> - void setDownloadLimit ( QString hash , long val ) ; <nl> - void setUploadLimit ( QString hash , long val ) ; <nl> - void enableUPnP ( bool b ) ; <nl> - void enableLSD ( bool b ) ; <nl> - void enableDHT ( bool b ) ; <nl> - void processDownloadedFile ( QString , QString ) ; <nl> + / / Session configuration - Setters <nl> + void setListeningPort ( int port ) ; <nl> + void setMaxConnectionsPerTorrent ( int max ) ; <nl> + void setMaxUploadsPerTorrent ( int max ) ; <nl> + void setDownloadRateLimit ( long rate ) ; <nl> + void setUploadRateLimit ( long rate ) ; <nl> + void setGlobalMaxRatio ( qreal ratio ) ; <nl> + qreal getGlobalMaxRatio ( ) const { return global_ratio_limit ; } <nl> + void setMaxRatioPerTorrent ( const QString & hash , qreal ratio ) ; <nl> + qreal getMaxRatioPerTorrent ( const QString & hash , bool * usesGlobalRatio ) const ; <nl> + void removeRatioPerTorrent ( const QString & hash ) ; <nl> + void setDefaultSavePath ( const QString & savepath ) ; <nl> + void setDefaultTempPath ( const QString & temppath ) ; <nl> + void setAppendLabelToSavePath ( bool append ) ; <nl> + void appendLabelToTorrentSavePath ( const QTorrentHandle & h ) ; <nl> + void changeLabelInTorrentSavePath ( const QTorrentHandle & h , QString old_label , QString new_label ) ; <nl> + void appendqBextensionToTorrent ( const QTorrentHandle & h , bool append ) ; <nl> + void setAppendqBExtension ( bool append ) ; <nl> + void setDownloadLimit ( QString hash , long val ) ; <nl> + void setUploadLimit ( QString hash , long val ) ; <nl> + void enableUPnP ( bool b ) ; <nl> + void enableLSD ( bool b ) ; <nl> + void enableDHT ( bool b ) ; <nl> + void processDownloadedFile ( QString , QString ) ; <nl> # ifndef DISABLE_GUI <nl> - void addMagnetSkipAddDlg ( const QString & uri , const QString & save_path = QString ( ) , const QString & label = QString ( ) , <nl> - const RssDownloadRule : : AddPausedState & aps = RssDownloadRule : : USE_GLOBAL , const QString & uri_old = QString ( ) ) ; <nl> + void addMagnetSkipAddDlg ( const QString & uri , const QString & save_path = QString ( ) , const QString & label = QString ( ) , <nl> + const RssDownloadRule : : AddPausedState & aps = RssDownloadRule : : USE_GLOBAL , const QString & uri_old = QString ( ) ) ; <nl> # else <nl> - void addMagnetSkipAddDlg ( const QString & uri , const QString & save_path = QString ( ) , const QString & label = QString ( ) , const QString & uri_old = QString ( ) ) ; <nl> + void addMagnetSkipAddDlg ( const QString & uri , const QString & save_path = QString ( ) , const QString & label = QString ( ) , const QString & uri_old = QString ( ) ) ; <nl> # endif <nl> - void addMagnetInteractive ( const QString & uri ) ; <nl> - void downloadFromURLList ( const QStringList & urls ) ; <nl> - void banIP ( QString ip ) ; <nl> - void recursiveTorrentDownload ( const QTorrentHandle & h ) ; <nl> - void unhideMagnet ( const QString & hash ) ; <nl> + void addMagnetInteractive ( const QString & uri ) ; <nl> + void downloadFromURLList ( const QStringList & urls ) ; <nl> + void banIP ( QString ip ) ; <nl> + void recursiveTorrentDownload ( const QTorrentHandle & h ) ; <nl> + void unhideMagnet ( const QString & hash ) ; <nl> <nl> private : <nl> - void applyEncryptionSettings ( libtorrent : : pe_settings se ) ; <nl> - void setProxySettings ( libtorrent : : proxy_settings proxySettings ) ; <nl> - void setSessionSettings ( const libtorrent : : session_settings & sessionSettings ) ; <nl> - QString getSavePath ( const QString & hash , bool fromScanDir = false , QString filePath = QString : : null , bool imported = false ) ; <nl> - bool loadFastResumeData ( const QString & hash , std : : vector < char > & buf ) ; <nl> - void loadTorrentSettings ( QTorrentHandle & h ) ; <nl> - void loadTorrentTempData ( QTorrentHandle & h , QString savePath , bool magnet ) ; <nl> - void initializeAddTorrentParams ( const QString & hash , libtorrent : : add_torrent_params & p ) ; <nl> - void updateRatioTimer ( ) ; <nl> - void recoverPersistentData ( const QString & hash , const std : : vector < char > & buf ) ; <nl> - void backupPersistentData ( const QString & hash , boost : : shared_ptr < libtorrent : : entry > data ) ; <nl> - void handleAlert ( libtorrent : : alert * a ) ; <nl> - void handleTorrentFinishedAlert ( libtorrent : : torrent_finished_alert * p ) ; <nl> - void handleSaveResumeDataAlert ( libtorrent : : save_resume_data_alert * p ) ; <nl> - void handleFileRenamedAlert ( libtorrent : : file_renamed_alert * p ) ; <nl> - void handleTorrentDeletedAlert ( libtorrent : : torrent_deleted_alert * p ) ; <nl> - void handleStorageMovedAlert ( libtorrent : : storage_moved_alert * p ) ; <nl> - void handleStorageMovedFailedAlert ( libtorrent : : storage_moved_failed_alert * p ) ; <nl> - void handleMetadataReceivedAlert ( libtorrent : : metadata_received_alert * p ) ; <nl> - void handleFileErrorAlert ( libtorrent : : file_error_alert * p ) ; <nl> - void handleFileCompletedAlert ( libtorrent : : file_completed_alert * p ) ; <nl> - void handleTorrentPausedAlert ( libtorrent : : torrent_paused_alert * p ) ; <nl> - void handleTrackerErrorAlert ( libtorrent : : tracker_error_alert * p ) ; <nl> - void handleTrackerReplyAlert ( libtorrent : : tracker_reply_alert * p ) ; <nl> - void handleTrackerWarningAlert ( libtorrent : : tracker_warning_alert * p ) ; <nl> - void handlePortmapWarningAlert ( libtorrent : : portmap_error_alert * p ) ; <nl> - void handlePortmapAlert ( libtorrent : : portmap_alert * p ) ; <nl> - void handlePeerBlockedAlert ( libtorrent : : peer_blocked_alert * p ) ; <nl> - void handlePeerBanAlert ( libtorrent : : peer_ban_alert * p ) ; <nl> - void handleFastResumeRejectedAlert ( libtorrent : : fastresume_rejected_alert * p ) ; <nl> - void handleUrlSeedAlert ( libtorrent : : url_seed_alert * p ) ; <nl> - void handleListenSucceededAlert ( libtorrent : : listen_succeeded_alert * p ) ; <nl> - void handleListenFailedAlert ( libtorrent : : listen_failed_alert * p ) ; <nl> - void handleTorrentCheckedAlert ( libtorrent : : torrent_checked_alert * p ) ; <nl> - void handleExternalIPAlert ( libtorrent : : external_ip_alert * p ) ; <nl> - void handleStateUpdateAlert ( libtorrent : : state_update_alert * p ) ; <nl> - void handleStatsAlert ( libtorrent : : stats_alert * p ) ; <nl> + void applyEncryptionSettings ( libtorrent : : pe_settings se ) ; <nl> + void setProxySettings ( libtorrent : : proxy_settings proxySettings ) ; <nl> + void setSessionSettings ( const libtorrent : : session_settings & sessionSettings ) ; <nl> + QString getSavePath ( const QString & hash , bool fromScanDir = false , QString filePath = QString : : null , bool imported = false ) ; <nl> + bool loadFastResumeData ( const QString & hash , std : : vector < char > & buf ) ; <nl> + void loadTorrentSettings ( QTorrentHandle & h ) ; <nl> + void loadTorrentTempData ( QTorrentHandle & h , QString savePath , bool magnet ) ; <nl> + void initializeAddTorrentParams ( const QString & hash , libtorrent : : add_torrent_params & p ) ; <nl> + void updateRatioTimer ( ) ; <nl> + void recoverPersistentData ( const QString & hash , const std : : vector < char > & buf ) ; <nl> + void backupPersistentData ( const QString & hash , boost : : shared_ptr < libtorrent : : entry > data ) ; <nl> + void handleAlert ( libtorrent : : alert * a ) ; <nl> + void handleTorrentFinishedAlert ( libtorrent : : torrent_finished_alert * p ) ; <nl> + void handleSaveResumeDataAlert ( libtorrent : : save_resume_data_alert * p ) ; <nl> + void handleFileRenamedAlert ( libtorrent : : file_renamed_alert * p ) ; <nl> + void handleTorrentDeletedAlert ( libtorrent : : torrent_deleted_alert * p ) ; <nl> + void handleStorageMovedAlert ( libtorrent : : storage_moved_alert * p ) ; <nl> + void handleStorageMovedFailedAlert ( libtorrent : : storage_moved_failed_alert * p ) ; <nl> + void handleMetadataReceivedAlert ( libtorrent : : metadata_received_alert * p ) ; <nl> + void handleFileErrorAlert ( libtorrent : : file_error_alert * p ) ; <nl> + void handleFileCompletedAlert ( libtorrent : : file_completed_alert * p ) ; <nl> + void handleTorrentPausedAlert ( libtorrent : : torrent_paused_alert * p ) ; <nl> + void handleTrackerErrorAlert ( libtorrent : : tracker_error_alert * p ) ; <nl> + void handleTrackerReplyAlert ( libtorrent : : tracker_reply_alert * p ) ; <nl> + void handleTrackerWarningAlert ( libtorrent : : tracker_warning_alert * p ) ; <nl> + void handlePortmapWarningAlert ( libtorrent : : portmap_error_alert * p ) ; <nl> + void handlePortmapAlert ( libtorrent : : portmap_alert * p ) ; <nl> + void handlePeerBlockedAlert ( libtorrent : : peer_blocked_alert * p ) ; <nl> + void handlePeerBanAlert ( libtorrent : : peer_ban_alert * p ) ; <nl> + void handleFastResumeRejectedAlert ( libtorrent : : fastresume_rejected_alert * p ) ; <nl> + void handleUrlSeedAlert ( libtorrent : : url_seed_alert * p ) ; <nl> + void handleListenSucceededAlert ( libtorrent : : listen_succeeded_alert * p ) ; <nl> + void handleListenFailedAlert ( libtorrent : : listen_failed_alert * p ) ; <nl> + void handleTorrentCheckedAlert ( libtorrent : : torrent_checked_alert * p ) ; <nl> + void handleExternalIPAlert ( libtorrent : : external_ip_alert * p ) ; <nl> + void handleStateUpdateAlert ( libtorrent : : state_update_alert * p ) ; <nl> + void handleStatsAlert ( libtorrent : : stats_alert * p ) ; <nl> <nl> private slots : <nl> - void addTorrentsFromScanFolder ( QStringList & ) ; <nl> - void readAlerts ( ) ; <nl> - void processBigRatios ( ) ; <nl> - void exportTorrentFiles ( QString path ) ; <nl> - void saveTempFastResumeData ( ) ; <nl> - void sendNotificationEmail ( const QTorrentHandle & h ) ; <nl> - void autoRunExternalProgram ( const QTorrentHandle & h ) ; <nl> - void mergeTorrents ( QTorrentHandle & h_ex , boost : : intrusive_ptr < libtorrent : : torrent_info > t ) ; <nl> - void mergeTorrents ( QTorrentHandle & h_ex , const QString & magnet_uri ) ; <nl> - void exportTorrentFile ( const QTorrentHandle & h , TorrentExportFolder folder = RegularTorrentExportFolder ) ; <nl> - void handleIPFilterParsed ( int ruleCount ) ; <nl> - void handleIPFilterError ( ) ; <nl> - void configureSession ( ) ; <nl> + void addTorrentsFromScanFolder ( QStringList & ) ; <nl> + void readAlerts ( ) ; <nl> + void processBigRatios ( ) ; <nl> + void exportTorrentFiles ( QString path ) ; <nl> + void saveTempFastResumeData ( ) ; <nl> + void sendNotificationEmail ( const QTorrentHandle & h ) ; <nl> + void autoRunExternalProgram ( const QTorrentHandle & h ) ; <nl> + void mergeTorrents ( QTorrentHandle & h_ex , boost : : intrusive_ptr < libtorrent : : torrent_info > t ) ; <nl> + void mergeTorrents ( QTorrentHandle & h_ex , const QString & magnet_uri ) ; <nl> + void exportTorrentFile ( const QTorrentHandle & h , TorrentExportFolder folder = RegularTorrentExportFolder ) ; <nl> + void handleIPFilterParsed ( int ruleCount ) ; <nl> + void handleIPFilterError ( ) ; <nl> + void configureSession ( ) ; <nl> <nl> signals : <nl> - void addedTorrent ( const QTorrentHandle & h ) ; <nl> - void torrentAboutToBeRemoved ( const QTorrentHandle & h ) ; <nl> - void pausedTorrent ( const QTorrentHandle & h ) ; <nl> - void resumedTorrent ( const QTorrentHandle & h ) ; <nl> - void finishedTorrent ( const QTorrentHandle & h ) ; <nl> - void fullDiskError ( const QTorrentHandle & h , QString msg ) ; <nl> - void trackerError ( const QString & hash , QString time , QString msg ) ; <nl> - void trackerAuthenticationRequired ( const QTorrentHandle & h ) ; <nl> - void newDownloadedTorrent ( QString path , QString url ) ; <nl> - void newDownloadedTorrentFromRss ( QString url ) ; <nl> - void newMagnetLink ( const QString & link ) ; <nl> - void updateFileSize ( const QString & hash ) ; <nl> - void downloadFromUrlFailure ( QString url , QString reason ) ; <nl> - void torrentFinishedChecking ( const QTorrentHandle & h ) ; <nl> - void metadataReceived ( const QTorrentHandle & h ) ; <nl> - void savePathChanged ( const QTorrentHandle & h ) ; <nl> - void alternativeSpeedsModeChanged ( bool alternative ) ; <nl> - void recursiveTorrentDownloadPossible ( const QTorrentHandle & h ) ; <nl> - void ipFilterParsed ( bool error , int ruleCount ) ; <nl> - void metadataReceivedHidden ( const QTorrentHandle & h ) ; <nl> - void stateUpdate ( const std : : vector < libtorrent : : torrent_status > & statuses ) ; <nl> - void statsReceived ( const libtorrent : : stats_alert & ) ; <nl> + void addedTorrent ( const QTorrentHandle & h ) ; <nl> + void torrentAboutToBeRemoved ( const QTorrentHandle & h ) ; <nl> + void pausedTorrent ( const QTorrentHandle & h ) ; <nl> + void resumedTorrent ( const QTorrentHandle & h ) ; <nl> + void finishedTorrent ( const QTorrentHandle & h ) ; <nl> + void fullDiskError ( const QTorrentHandle & h , QString msg ) ; <nl> + void trackerError ( const QString & hash , QString time , QString msg ) ; <nl> + void trackerAuthenticationRequired ( const QTorrentHandle & h ) ; <nl> + void newDownloadedTorrent ( QString path , QString url ) ; <nl> + void newDownloadedTorrentFromRss ( QString url ) ; <nl> + void newMagnetLink ( const QString & link ) ; <nl> + void updateFileSize ( const QString & hash ) ; <nl> + void downloadFromUrlFailure ( QString url , QString reason ) ; <nl> + void torrentFinishedChecking ( const QTorrentHandle & h ) ; <nl> + void metadataReceived ( const QTorrentHandle & h ) ; <nl> + void savePathChanged ( const QTorrentHandle & h ) ; <nl> + void alternativeSpeedsModeChanged ( bool alternative ) ; <nl> + void recursiveTorrentDownloadPossible ( const QTorrentHandle & h ) ; <nl> + void ipFilterParsed ( bool error , int ruleCount ) ; <nl> + void metadataReceivedHidden ( const QTorrentHandle & h ) ; <nl> + void stateUpdate ( const std : : vector < libtorrent : : torrent_status > & statuses ) ; <nl> + void statsReceived ( const libtorrent : : stats_alert & ) ; <nl> <nl> private : <nl> - / / Bittorrent <nl> - libtorrent : : session * s ; <nl> - QPointer < BandwidthScheduler > bd_scheduler ; <nl> - QMap < QUrl , QPair < QString , QString > > savepathLabel_fromurl ; / / Use QMap for compatibility with Qt < 4 . 7 : qHash ( QUrl ) <nl> + / / Bittorrent <nl> + libtorrent : : session * s ; <nl> + QPointer < BandwidthScheduler > bd_scheduler ; <nl> + QMap < QUrl , QPair < QString , QString > > savepathLabel_fromurl ; / / Use QMap for compatibility with Qt < 4 . 7 : qHash ( QUrl ) <nl> # ifndef DISABLE_GUI <nl> - QMap < QUrl , RssDownloadRule : : AddPausedState > addpaused_fromurl ; <nl> + QMap < QUrl , RssDownloadRule : : AddPausedState > addpaused_fromurl ; <nl> # endif <nl> - QHash < QString , QHash < QString , TrackerInfos > > trackersInfos ; <nl> - QHash < QString , QString > savePathsToRemove ; <nl> - QStringList torrentsToPausedAfterChecking ; <nl> - QTimer resumeDataTimer ; <nl> - / / Ratio <nl> - QPointer < QTimer > BigRatioTimer ; <nl> - / / HTTP <nl> - DownloadThread * downloader ; <nl> - / / File System <nl> - ScanFoldersModel * m_scanFolders ; <nl> - / / Settings <nl> - bool preAllocateAll ; <nl> - qreal global_ratio_limit ; <nl> - int high_ratio_action ; <nl> - bool LSDEnabled ; <nl> - bool DHTEnabled ; <nl> - bool PeXEnabled ; <nl> - bool queueingEnabled ; <nl> - bool appendLabelToSavePath ; <nl> - bool m_torrentExportEnabled ; <nl> - bool m_finishedTorrentExportEnabled ; <nl> - bool appendqBExtension ; <nl> - QString defaultSavePath ; <nl> - QString defaultTempPath ; <nl> - / / IP filtering <nl> - QPointer < FilterParserThread > filterParser ; <nl> - QString filterPath ; <nl> - QList < QUrl > url_skippingDlg ; <nl> - / / GeoIP <nl> + QHash < QString , QHash < QString , TrackerInfos > > trackersInfos ; <nl> + QHash < QString , QString > savePathsToRemove ; <nl> + QStringList torrentsToPausedAfterChecking ; <nl> + QTimer resumeDataTimer ; <nl> + / / Ratio <nl> + QPointer < QTimer > BigRatioTimer ; <nl> + / / HTTP <nl> + DownloadThread * downloader ; <nl> + / / File System <nl> + ScanFoldersModel * m_scanFolders ; <nl> + / / Settings <nl> + bool preAllocateAll ; <nl> + qreal global_ratio_limit ; <nl> + int high_ratio_action ; <nl> + bool LSDEnabled ; <nl> + bool DHTEnabled ; <nl> + bool PeXEnabled ; <nl> + bool queueingEnabled ; <nl> + bool appendLabelToSavePath ; <nl> + bool m_torrentExportEnabled ; <nl> + bool m_finishedTorrentExportEnabled ; <nl> + bool appendqBExtension ; <nl> + QString defaultSavePath ; <nl> + QString defaultTempPath ; <nl> + / / IP filtering <nl> + QPointer < FilterParserThread > filterParser ; <nl> + QString filterPath ; <nl> + QList < QUrl > url_skippingDlg ; <nl> + / / GeoIP <nl> # ifndef DISABLE_GUI <nl> - bool geoipDBLoaded ; <nl> - bool resolve_countries ; <nl> + bool geoipDBLoaded ; <nl> + bool resolve_countries ; <nl> # endif <nl> - / / Tracker <nl> - QPointer < QTracker > m_tracker ; <nl> - TorrentSpeedMonitor * m_speedMonitor ; <nl> - shutDownAction m_shutdownAct ; <nl> - / / Port forwarding <nl> + / / Tracker <nl> + QPointer < QTracker > m_tracker ; <nl> + TorrentSpeedMonitor * m_speedMonitor ; <nl> + shutDownAction m_shutdownAct ; <nl> + / / Port forwarding <nl> # if LIBTORRENT_VERSION_NUM < 10000 <nl> - libtorrent : : upnp * m_upnp ; <nl> - libtorrent : : natpmp * m_natpmp ; <nl> + libtorrent : : upnp * m_upnp ; <nl> + libtorrent : : natpmp * m_natpmp ; <nl> # endif <nl> - QAlertDispatcher * m_alertDispatcher ; <nl> - TorrentStatistics * m_torrentStatistics ; <nl> + QAlertDispatcher * m_alertDispatcher ; <nl> + TorrentStatistics * m_torrentStatistics ; <nl> } ; <nl> <nl> # endif <nl> mmm a / src / core / qtlibtorrent / qtorrenthandle . cpp <nl> ppp b / src / core / qtlibtorrent / qtorrenthandle . cpp <nl> bool QTorrentHandle : : first_last_piece_first ( ) const <nl> QPair < int , int > extremities = get_file_extremity_pieces ( * t , index ) ; <nl> <nl> return ( torrent_handle : : piece_priority ( extremities . first ) = = 7 ) <nl> - & & ( torrent_handle : : piece_priority ( extremities . second ) = = 7 ) ; <nl> + & & ( torrent_handle : : piece_priority ( extremities . second ) = = 7 ) ; <nl> } <nl> <nl> QString QTorrentHandle : : save_path ( ) const <nl> void QTorrentHandle : : pause ( ) const <nl> torrent_handle : : auto_managed ( false ) ; <nl> torrent_handle : : pause ( ) ; <nl> if ( ! TorrentPersistentData : : instance ( ) - > getHasMissingFiles ( this - > hash ( ) ) ) <nl> - torrent_handle : : save_resume_data ( ) ; <nl> + torrent_handle : : save_resume_data ( ) ; <nl> } <nl> <nl> void QTorrentHandle : : resume ( ) const <nl> bool QTorrentHandle : : is_queued ( const libtorrent : : torrent_status & status ) <nl> bool QTorrentHandle : : is_seed ( const libtorrent : : torrent_status & status ) <nl> { <nl> return status . state = = torrent_status : : finished <nl> - | | status . state = = torrent_status : : seeding ; <nl> + | | status . state = = torrent_status : : seeding ; <nl> } <nl> <nl> bool QTorrentHandle : : is_checking ( const libtorrent : : torrent_status & status ) <nl> { <nl> return status . state = = torrent_status : : checking_files <nl> - | | status . state = = torrent_status : : checking_resume_data ; <nl> + | | status . state = = torrent_status : : checking_resume_data ; <nl> } <nl> <nl> bool QTorrentHandle : : has_error ( const libtorrent : : torrent_status & status ) <nl> mmm a / src / core / qtlibtorrent / shutdownconfirm . cpp <nl> ppp b / src / core / qtlibtorrent / shutdownconfirm . cpp <nl> <nl> # include < QPushButton > <nl> <nl> ShutdownConfirmDlg : : ShutdownConfirmDlg ( const shutDownAction & action ) : exit_now ( NULL ) , timeout ( 15 ) , action0 ( action ) { <nl> - / / Title and button <nl> - if ( action0 = = NO_SHUTDOWN ) { <nl> - setWindowTitle ( tr ( " Exit confirmation " ) ) ; <nl> - exit_now = addButton ( tr ( " Exit now " ) , QMessageBox : : AcceptRole ) ; <nl> - } <nl> - else { <nl> - setWindowTitle ( tr ( " Shutdown confirmation " ) ) ; <nl> - exit_now = addButton ( tr ( " Shutdown now " ) , QMessageBox : : AcceptRole ) ; <nl> - } <nl> - / / Cancel Button <nl> - addButton ( QMessageBox : : Cancel ) ; <nl> - / / Text <nl> - updateText ( ) ; <nl> - / / Icon <nl> - setIcon ( QMessageBox : : Warning ) ; <nl> - / / Always on top <nl> - setWindowFlags ( windowFlags ( ) | Qt : : WindowStaysOnTopHint ) ; <nl> - / / Set ' Cancel ' as default button . <nl> - setDefaultButton ( QMessageBox : : Cancel ) ; <nl> - timer . setInterval ( 1000 ) ; / / 1sec <nl> - connect ( & timer , SIGNAL ( timeout ( ) ) , this , SLOT ( updateSeconds ( ) ) ) ; <nl> - show ( ) ; <nl> - / / Move to center <nl> - move ( misc : : screenCenter ( this ) ) ; <nl> + / / Title and button <nl> + if ( action0 = = NO_SHUTDOWN ) { <nl> + setWindowTitle ( tr ( " Exit confirmation " ) ) ; <nl> + exit_now = addButton ( tr ( " Exit now " ) , QMessageBox : : AcceptRole ) ; <nl> + } <nl> + else { <nl> + setWindowTitle ( tr ( " Shutdown confirmation " ) ) ; <nl> + exit_now = addButton ( tr ( " Shutdown now " ) , QMessageBox : : AcceptRole ) ; <nl> + } <nl> + / / Cancel Button <nl> + addButton ( QMessageBox : : Cancel ) ; <nl> + / / Text <nl> + updateText ( ) ; <nl> + / / Icon <nl> + setIcon ( QMessageBox : : Warning ) ; <nl> + / / Always on top <nl> + setWindowFlags ( windowFlags ( ) | Qt : : WindowStaysOnTopHint ) ; <nl> + / / Set ' Cancel ' as default button . <nl> + setDefaultButton ( QMessageBox : : Cancel ) ; <nl> + timer . setInterval ( 1000 ) ; / / 1sec <nl> + connect ( & timer , SIGNAL ( timeout ( ) ) , this , SLOT ( updateSeconds ( ) ) ) ; <nl> + show ( ) ; <nl> + / / Move to center <nl> + move ( misc : : screenCenter ( this ) ) ; <nl> } <nl> <nl> void ShutdownConfirmDlg : : showEvent ( QShowEvent * event ) { <nl> - QMessageBox : : showEvent ( event ) ; <nl> - timer . start ( ) ; <nl> + QMessageBox : : showEvent ( event ) ; <nl> + timer . start ( ) ; <nl> } <nl> <nl> bool ShutdownConfirmDlg : : askForConfirmation ( const shutDownAction & action ) { <nl> - ShutdownConfirmDlg dlg ( action ) ; <nl> - dlg . exec ( ) ; <nl> - return dlg . shutdown ( ) ; <nl> + ShutdownConfirmDlg dlg ( action ) ; <nl> + dlg . exec ( ) ; <nl> + return dlg . shutdown ( ) ; <nl> } <nl> <nl> void ShutdownConfirmDlg : : updateSeconds ( ) { <nl> - - - timeout ; <nl> - updateText ( ) ; <nl> - if ( timeout = = 0 ) { <nl> - timer . stop ( ) ; <nl> - accept ( ) ; <nl> - } <nl> + - - timeout ; <nl> + updateText ( ) ; <nl> + if ( timeout = = 0 ) { <nl> + timer . stop ( ) ; <nl> + accept ( ) ; <nl> + } <nl> } <nl> <nl> bool ShutdownConfirmDlg : : shutdown ( ) const { <nl> - / / This is necessary because result ( ) in the case of QMessageBox <nl> - / / returns a type of StandardButton , but since we use a custom button <nl> - / / it will return 0 instead , even though we set the ' accept ' role on it . <nl> - if ( result ( ) ! = QDialog : : Accepted ) <nl> - return ( clickedButton ( ) = = exit_now ) ; <nl> - else <nl> - return true ; <nl> + / / This is necessary because result ( ) in the case of QMessageBox <nl> + / / returns a type of StandardButton , but since we use a custom button <nl> + / / it will return 0 instead , even though we set the ' accept ' role on it . <nl> + if ( result ( ) ! = QDialog : : Accepted ) <nl> + return ( clickedButton ( ) = = exit_now ) ; <nl> + else <nl> + return true ; <nl> } <nl> <nl> void ShutdownConfirmDlg : : updateText ( ) { <nl> - QString text ; <nl> + QString text ; <nl> <nl> - switch ( action0 ) { <nl> - case NO_SHUTDOWN : <nl> - text = tr ( " qBittorrent will now exit unless you cancel within the next % 1 seconds . " ) . arg ( QString : : number ( timeout ) ) ; <nl> - break ; <nl> - case SHUTDOWN_COMPUTER : <nl> - text = tr ( " The computer will now be switched off unless you cancel within the next % 1 seconds . " ) . arg ( QString : : number ( timeout ) ) ; <nl> - break ; <nl> - case SUSPEND_COMPUTER : <nl> - text = tr ( " The computer will now go to sleep mode unless you cancel within the next % 1 seconds . " ) . arg ( QString : : number ( timeout ) ) ; <nl> - break ; <nl> - case HIBERNATE_COMPUTER : <nl> - text = tr ( " The computer will now go to hibernation mode unless you cancel within the next % 1 seconds . " ) . arg ( QString : : number ( timeout ) ) ; <nl> - break ; <nl> - } <nl> + switch ( action0 ) { <nl> + case NO_SHUTDOWN : <nl> + text = tr ( " qBittorrent will now exit unless you cancel within the next % 1 seconds . " ) . arg ( QString : : number ( timeout ) ) ; <nl> + break ; <nl> + case SHUTDOWN_COMPUTER : <nl> + text = tr ( " The computer will now be switched off unless you cancel within the next % 1 seconds . " ) . arg ( QString : : number ( timeout ) ) ; <nl> + break ; <nl> + case SUSPEND_COMPUTER : <nl> + text = tr ( " The computer will now go to sleep mode unless you cancel within the next % 1 seconds . " ) . arg ( QString : : number ( timeout ) ) ; <nl> + break ; <nl> + case HIBERNATE_COMPUTER : <nl> + text = tr ( " The computer will now go to hibernation mode unless you cancel within the next % 1 seconds . " ) . arg ( QString : : number ( timeout ) ) ; <nl> + break ; <nl> + } <nl> <nl> - setText ( text ) ; <nl> + setText ( text ) ; <nl> } <nl> <nl> mmm a / src / core / qtlibtorrent / shutdownconfirm . h <nl> ppp b / src / core / qtlibtorrent / shutdownconfirm . h <nl> <nl> # include " misc . h " <nl> <nl> class ShutdownConfirmDlg : public QMessageBox { <nl> - Q_OBJECT <nl> + Q_OBJECT <nl> <nl> public : <nl> - ShutdownConfirmDlg ( const shutDownAction & action ) ; <nl> - bool shutdown ( ) const ; <nl> + ShutdownConfirmDlg ( const shutDownAction & action ) ; <nl> + bool shutdown ( ) const ; <nl> <nl> - static bool askForConfirmation ( const shutDownAction & action ) ; <nl> + static bool askForConfirmation ( const shutDownAction & action ) ; <nl> <nl> protected : <nl> - void showEvent ( QShowEvent * event ) ; <nl> + void showEvent ( QShowEvent * event ) ; <nl> <nl> private slots : <nl> - void updateSeconds ( ) ; <nl> + void updateSeconds ( ) ; <nl> <nl> private : <nl> - / / Methods <nl> - void updateText ( ) ; <nl> + / / Methods <nl> + void updateText ( ) ; <nl> <nl> - / / Vars <nl> - QAbstractButton * exit_now ; <nl> - QTimer timer ; <nl> - int timeout ; <nl> - shutDownAction action0 ; <nl> + / / Vars <nl> + QAbstractButton * exit_now ; <nl> + QTimer timer ; <nl> + int timeout ; <nl> + shutDownAction action0 ; <nl> } ; <nl> <nl> # endif / / SHUTDOWNCONFIRM_H <nl> mmm a / src / core / qtlibtorrent / torrentmodel . cpp <nl> ppp b / src / core / qtlibtorrent / torrentmodel . cpp <nl> namespace { <nl> QIcon get_paused_icon ( ) { <nl> static QIcon cached = QIcon ( " : / icons / skin / paused . png " ) ; <nl> return cached ; <nl> - } <nl> + } <nl> <nl> QIcon get_queued_icon ( ) { <nl> static QIcon cached = QIcon ( " : / icons / skin / queued . png " ) ; <nl> return cached ; <nl> - } <nl> + } <nl> <nl> QIcon get_downloading_icon ( ) { <nl> static QIcon cached = QIcon ( " : / icons / skin / downloading . png " ) ; <nl> return cached ; <nl> - } <nl> + } <nl> <nl> QIcon get_stalled_downloading_icon ( ) { <nl> static QIcon cached = QIcon ( " : / icons / skin / stalledDL . png " ) ; <nl> return cached ; <nl> - } <nl> + } <nl> <nl> QIcon get_uploading_icon ( ) { <nl> static QIcon cached = QIcon ( " : / icons / skin / uploading . png " ) ; <nl> return cached ; <nl> - } <nl> + } <nl> <nl> QIcon get_stalled_uploading_icon ( ) { <nl> static QIcon cached = QIcon ( " : / icons / skin / stalledUP . png " ) ; <nl> return cached ; <nl> - } <nl> + } <nl> <nl> QIcon get_checking_icon ( ) { <nl> static QIcon cached = QIcon ( " : / icons / skin / checking . png " ) ; <nl> return cached ; <nl> - } <nl> + } <nl> <nl> QIcon get_error_icon ( ) { <nl> static QIcon cached = QIcon ( " : / icons / skin / error . png " ) ; <nl> return cached ; <nl> - } <nl> + } <nl> } <nl> <nl> TorrentModelItem : : TorrentModelItem ( const QTorrentHandle & h ) <nl> - : m_torrent ( h ) <nl> - , m_lastStatus ( h . status ( torrent_handle : : query_accurate_download_counters ) ) <nl> - , m_addedTime ( TorrentPersistentData : : instance ( ) - > getAddedDate ( h . hash ( ) ) ) <nl> - , m_label ( TorrentPersistentData : : instance ( ) - > getLabel ( h . hash ( ) ) ) <nl> - , m_name ( TorrentPersistentData : : instance ( ) - > getName ( h . hash ( ) ) ) <nl> - , m_hash ( h . hash ( ) ) <nl> + : m_torrent ( h ) <nl> + , m_lastStatus ( h . status ( torrent_handle : : query_accurate_download_counters ) ) <nl> + , m_addedTime ( TorrentPersistentData : : instance ( ) - > getAddedDate ( h . hash ( ) ) ) <nl> + , m_label ( TorrentPersistentData : : instance ( ) - > getLabel ( h . hash ( ) ) ) <nl> + , m_name ( TorrentPersistentData : : instance ( ) - > getName ( h . hash ( ) ) ) <nl> + , m_hash ( h . hash ( ) ) <nl> { <nl> - if ( m_name . isEmpty ( ) ) <nl> - m_name = h . name ( ) ; <nl> + if ( m_name . isEmpty ( ) ) <nl> + m_name = h . name ( ) ; <nl> } <nl> <nl> void TorrentModelItem : : refreshStatus ( libtorrent : : torrent_status const & status ) { <nl> - m_lastStatus = status ; <nl> + m_lastStatus = status ; <nl> } <nl> <nl> TorrentModelItem : : State TorrentModelItem : : state ( ) const { <nl> - try { <nl> - / / Pause or Queued <nl> - if ( m_torrent . is_paused ( m_lastStatus ) ) { <nl> - if ( TorrentPersistentData : : instance ( ) - > getHasMissingFiles ( misc : : toQString ( m_lastStatus . info_hash ) ) ) <nl> - return STATE_PAUSED_MISSING ; <nl> - else <nl> - return m_torrent . is_seed ( m_lastStatus ) ? STATE_PAUSED_UP : STATE_PAUSED_DL ; <nl> - } <nl> - <nl> - if ( m_torrent . is_queued ( m_lastStatus ) <nl> - & & m_lastStatus . state ! = torrent_status : : queued_for_checking <nl> - & & m_lastStatus . state ! = torrent_status : : checking_resume_data <nl> - & & m_lastStatus . state ! = torrent_status : : checking_files ) <nl> - return m_torrent . is_seed ( m_lastStatus ) ? STATE_QUEUED_UP : STATE_QUEUED_DL ; <nl> - <nl> - / / Other states <nl> - switch ( m_lastStatus . state ) { <nl> - case torrent_status : : allocating : <nl> - return STATE_ALLOCATING ; <nl> - case torrent_status : : downloading_metadata : <nl> - return STATE_DOWNLOADING_META ; <nl> - case torrent_status : : downloading : <nl> - return m_lastStatus . download_payload_rate > 0 ? STATE_DOWNLOADING : STATE_STALLED_DL ; <nl> - case torrent_status : : finished : <nl> - case torrent_status : : seeding : <nl> - return m_lastStatus . upload_payload_rate > 0 ? STATE_SEEDING : STATE_STALLED_UP ; <nl> - case torrent_status : : queued_for_checking : <nl> - return STATE_QUEUED_CHECK ; <nl> - case torrent_status : : checking_resume_data : <nl> - return STATE_QUEUED_FASTCHECK ; <nl> - case torrent_status : : checking_files : <nl> - return m_torrent . is_seed ( m_lastStatus ) ? STATE_CHECKING_UP : STATE_CHECKING_DL ; <nl> - default : <nl> - return STATE_INVALID ; <nl> + try { <nl> + / / Pause or Queued <nl> + if ( m_torrent . is_paused ( m_lastStatus ) ) { <nl> + if ( TorrentPersistentData : : instance ( ) - > getHasMissingFiles ( misc : : toQString ( m_lastStatus . info_hash ) ) ) <nl> + return STATE_PAUSED_MISSING ; <nl> + else <nl> + return m_torrent . is_seed ( m_lastStatus ) ? STATE_PAUSED_UP : STATE_PAUSED_DL ; <nl> + } <nl> + <nl> + if ( m_torrent . is_queued ( m_lastStatus ) <nl> + & & m_lastStatus . state ! = torrent_status : : queued_for_checking <nl> + & & m_lastStatus . state ! = torrent_status : : checking_resume_data <nl> + & & m_lastStatus . state ! = torrent_status : : checking_files ) <nl> + return m_torrent . is_seed ( m_lastStatus ) ? STATE_QUEUED_UP : STATE_QUEUED_DL ; <nl> + <nl> + / / Other states <nl> + switch ( m_lastStatus . state ) { <nl> + case torrent_status : : allocating : <nl> + return STATE_ALLOCATING ; <nl> + case torrent_status : : downloading_metadata : <nl> + return STATE_DOWNLOADING_META ; <nl> + case torrent_status : : downloading : <nl> + return m_lastStatus . download_payload_rate > 0 ? STATE_DOWNLOADING : STATE_STALLED_DL ; <nl> + case torrent_status : : finished : <nl> + case torrent_status : : seeding : <nl> + return m_lastStatus . upload_payload_rate > 0 ? STATE_SEEDING : STATE_STALLED_UP ; <nl> + case torrent_status : : queued_for_checking : <nl> + return STATE_QUEUED_CHECK ; <nl> + case torrent_status : : checking_resume_data : <nl> + return STATE_QUEUED_FASTCHECK ; <nl> + case torrent_status : : checking_files : <nl> + return m_torrent . is_seed ( m_lastStatus ) ? STATE_CHECKING_UP : STATE_CHECKING_DL ; <nl> + default : <nl> + return STATE_INVALID ; <nl> + } <nl> + } catch ( invalid_handle & ) { <nl> + return STATE_INVALID ; <nl> } <nl> - } catch ( invalid_handle & ) { <nl> - return STATE_INVALID ; <nl> - } <nl> } <nl> <nl> QIcon TorrentModelItem : : getIconByState ( State state ) { <nl> - switch ( state ) { <nl> - case STATE_DOWNLOADING : <nl> - case STATE_DOWNLOADING_META : <nl> - return get_downloading_icon ( ) ; <nl> - case STATE_ALLOCATING : <nl> - case STATE_STALLED_DL : <nl> - return get_stalled_downloading_icon ( ) ; <nl> - case STATE_STALLED_UP : <nl> - return get_stalled_uploading_icon ( ) ; <nl> - case STATE_SEEDING : <nl> - return get_uploading_icon ( ) ; <nl> - case STATE_PAUSED_DL : <nl> - case STATE_PAUSED_UP : <nl> - return get_paused_icon ( ) ; <nl> - case STATE_QUEUED_DL : <nl> - case STATE_QUEUED_UP : <nl> - return get_queued_icon ( ) ; <nl> - case STATE_CHECKING_UP : <nl> - case STATE_CHECKING_DL : <nl> - case STATE_QUEUED_CHECK : <nl> - case STATE_QUEUED_FASTCHECK : <nl> - return get_checking_icon ( ) ; <nl> - case STATE_INVALID : <nl> - case STATE_PAUSED_MISSING : <nl> - return get_error_icon ( ) ; <nl> - default : <nl> - Q_ASSERT ( false ) ; <nl> - return get_error_icon ( ) ; <nl> - } <nl> + switch ( state ) { <nl> + case STATE_DOWNLOADING : <nl> + case STATE_DOWNLOADING_META : <nl> + return get_downloading_icon ( ) ; <nl> + case STATE_ALLOCATING : <nl> + case STATE_STALLED_DL : <nl> + return get_stalled_downloading_icon ( ) ; <nl> + case STATE_STALLED_UP : <nl> + return get_stalled_uploading_icon ( ) ; <nl> + case STATE_SEEDING : <nl> + return get_uploading_icon ( ) ; <nl> + case STATE_PAUSED_DL : <nl> + case STATE_PAUSED_UP : <nl> + return get_paused_icon ( ) ; <nl> + case STATE_QUEUED_DL : <nl> + case STATE_QUEUED_UP : <nl> + return get_queued_icon ( ) ; <nl> + case STATE_CHECKING_UP : <nl> + case STATE_CHECKING_DL : <nl> + case STATE_QUEUED_CHECK : <nl> + case STATE_QUEUED_FASTCHECK : <nl> + return get_checking_icon ( ) ; <nl> + case STATE_INVALID : <nl> + case STATE_PAUSED_MISSING : <nl> + return get_error_icon ( ) ; <nl> + default : <nl> + Q_ASSERT ( false ) ; <nl> + return get_error_icon ( ) ; <nl> + } <nl> } <nl> <nl> QColor TorrentModelItem : : getColorByState ( State state ) { <nl> - switch ( state ) { <nl> - case STATE_DOWNLOADING : <nl> - case STATE_DOWNLOADING_META : <nl> - return QColor ( 0 , 128 , 0 ) ; / / green <nl> - case STATE_ALLOCATING : <nl> - case STATE_STALLED_DL : <nl> - case STATE_STALLED_UP : <nl> - return QColor ( 128 , 128 , 128 ) ; / / grey <nl> - case STATE_SEEDING : <nl> - return QColor ( 255 , 165 , 0 ) ; / / orange <nl> - case STATE_PAUSED_DL : <nl> - case STATE_PAUSED_UP : <nl> - case STATE_PAUSED_MISSING : <nl> - return QColor ( 255 , 0 , 0 ) ; / / red <nl> - case STATE_QUEUED_DL : <nl> - case STATE_QUEUED_UP : <nl> - case STATE_CHECKING_UP : <nl> - case STATE_CHECKING_DL : <nl> - case STATE_QUEUED_CHECK : <nl> - case STATE_QUEUED_FASTCHECK : <nl> - return QColor ( 128 , 128 , 128 ) ; / / grey <nl> - case STATE_INVALID : <nl> - return QColor ( 255 , 0 , 0 ) ; / / red <nl> - default : <nl> - Q_ASSERT ( false ) ; <nl> - return QColor ( 255 , 0 , 0 ) ; / / red <nl> - } <nl> + switch ( state ) { <nl> + case STATE_DOWNLOADING : <nl> + case STATE_DOWNLOADING_META : <nl> + return QColor ( 0 , 128 , 0 ) ; / / green <nl> + case STATE_ALLOCATING : <nl> + case STATE_STALLED_DL : <nl> + case STATE_STALLED_UP : <nl> + return QColor ( 128 , 128 , 128 ) ; / / grey <nl> + case STATE_SEEDING : <nl> + return QColor ( 255 , 165 , 0 ) ; / / orange <nl> + case STATE_PAUSED_DL : <nl> + case STATE_PAUSED_UP : <nl> + case STATE_PAUSED_MISSING : <nl> + return QColor ( 255 , 0 , 0 ) ; / / red <nl> + case STATE_QUEUED_DL : <nl> + case STATE_QUEUED_UP : <nl> + case STATE_CHECKING_UP : <nl> + case STATE_CHECKING_DL : <nl> + case STATE_QUEUED_CHECK : <nl> + case STATE_QUEUED_FASTCHECK : <nl> + return QColor ( 128 , 128 , 128 ) ; / / grey <nl> + case STATE_INVALID : <nl> + return QColor ( 255 , 0 , 0 ) ; / / red <nl> + default : <nl> + Q_ASSERT ( false ) ; <nl> + return QColor ( 255 , 0 , 0 ) ; / / red <nl> + } <nl> } <nl> <nl> bool TorrentModelItem : : setData ( int column , const QVariant & value , int role ) <nl> { <nl> - qDebug ( ) < < Q_FUNC_INFO < < column < < value ; <nl> - if ( role ! = Qt : : DisplayRole ) return false ; <nl> - / / Label , seed date and Name columns can be edited <nl> - switch ( column ) { <nl> - case TR_NAME : <nl> - m_name = value . toString ( ) ; <nl> - TorrentPersistentData : : instance ( ) - > saveName ( m_torrent . hash ( ) , m_name ) ; <nl> - return true ; <nl> - case TR_LABEL : { <nl> - QString new_label = value . toString ( ) ; <nl> - if ( m_label ! = new_label ) { <nl> - QString old_label = m_label ; <nl> - m_label = new_label ; <nl> - TorrentPersistentData : : instance ( ) - > saveLabel ( m_torrent . hash ( ) , new_label ) ; <nl> - emit labelChanged ( old_label , new_label ) ; <nl> + qDebug ( ) < < Q_FUNC_INFO < < column < < value ; <nl> + if ( role ! = Qt : : DisplayRole ) return false ; <nl> + / / Label , seed date and Name columns can be edited <nl> + switch ( column ) { <nl> + case TR_NAME : <nl> + m_name = value . toString ( ) ; <nl> + TorrentPersistentData : : instance ( ) - > saveName ( m_torrent . hash ( ) , m_name ) ; <nl> + return true ; <nl> + case TR_LABEL : { <nl> + QString new_label = value . toString ( ) ; <nl> + if ( m_label ! = new_label ) { <nl> + QString old_label = m_label ; <nl> + m_label = new_label ; <nl> + TorrentPersistentData : : instance ( ) - > saveLabel ( m_torrent . hash ( ) , new_label ) ; <nl> + emit labelChanged ( old_label , new_label ) ; <nl> + } <nl> + return true ; <nl> + } <nl> + default : <nl> + break ; <nl> } <nl> - return true ; <nl> - } <nl> - default : <nl> - break ; <nl> - } <nl> - return false ; <nl> + return false ; <nl> } <nl> <nl> QVariant TorrentModelItem : : data ( int column , int role ) const <nl> { <nl> - if ( role = = Qt : : DecorationRole & & column = = TR_NAME ) { <nl> - return getIconByState ( state ( ) ) ; <nl> - } <nl> - if ( role = = Qt : : ForegroundRole ) { <nl> - return getColorByState ( state ( ) ) ; <nl> - } <nl> - if ( role ! = Qt : : DisplayRole & & role ! = Qt : : UserRole ) return QVariant ( ) ; <nl> - switch ( column ) { <nl> - case TR_NAME : <nl> - return m_name . isEmpty ( ) ? m_torrent . name ( ) : m_name ; <nl> - case TR_PRIORITY : { <nl> - int pos = m_torrent . queue_position ( m_lastStatus ) ; <nl> - if ( pos > - 1 ) <nl> - return pos - HiddenData : : getSize ( ) ; <nl> - else <nl> - return pos ; <nl> - } <nl> - case TR_SIZE : <nl> - return m_lastStatus . has_metadata ? static_cast < qlonglong > ( m_lastStatus . total_wanted ) : - 1 ; <nl> - case TR_PROGRESS : <nl> - return m_torrent . progress ( m_lastStatus ) ; <nl> - case TR_STATUS : <nl> - return state ( ) ; <nl> - case TR_SEEDS : { <nl> - return ( role = = Qt : : DisplayRole ) ? m_lastStatus . num_seeds : m_lastStatus . num_complete ; <nl> - } <nl> - case TR_PEERS : { <nl> - return ( role = = Qt : : DisplayRole ) ? ( m_lastStatus . num_peers - m_lastStatus . num_seeds ) : m_lastStatus . num_incomplete ; <nl> - } <nl> - case TR_DLSPEED : <nl> - return m_lastStatus . download_payload_rate ; <nl> - case TR_UPSPEED : <nl> - return m_lastStatus . upload_payload_rate ; <nl> - case TR_ETA : { <nl> - / / XXX : Is this correct ? <nl> - if ( m_torrent . is_paused ( m_lastStatus ) | | m_torrent . is_queued ( m_lastStatus ) ) return MAX_ETA ; <nl> - return QBtSession : : instance ( ) - > getETA ( m_hash , m_lastStatus ) ; <nl> - } <nl> - case TR_RATIO : <nl> - return QBtSession : : instance ( ) - > getRealRatio ( m_lastStatus ) ; <nl> - case TR_LABEL : <nl> - return m_label ; <nl> - case TR_ADD_DATE : <nl> - return m_addedTime ; <nl> - case TR_SEED_DATE : <nl> - return m_lastStatus . completed_time ? QDateTime : : fromTime_t ( m_lastStatus . completed_time ) : QDateTime ( ) ; <nl> - case TR_TRACKER : <nl> - return misc : : toQString ( m_lastStatus . current_tracker ) ; <nl> - case TR_DLLIMIT : <nl> - return m_torrent . download_limit ( ) ; <nl> - case TR_UPLIMIT : <nl> - return m_torrent . upload_limit ( ) ; <nl> - case TR_AMOUNT_DOWNLOADED : <nl> - return static_cast < qlonglong > ( m_lastStatus . all_time_download ) ; <nl> - case TR_AMOUNT_UPLOADED : <nl> - return static_cast < qlonglong > ( m_lastStatus . all_time_upload ) ; <nl> - case TR_AMOUNT_LEFT : <nl> - return static_cast < qlonglong > ( m_lastStatus . total_wanted - m_lastStatus . total_wanted_done ) ; <nl> - case TR_TIME_ELAPSED : <nl> - return ( role = = Qt : : DisplayRole ) ? m_lastStatus . active_time : m_lastStatus . seeding_time ; <nl> - case TR_SAVE_PATH : <nl> - return fsutils : : toNativePath ( m_torrent . save_path_parsed ( ) ) ; <nl> - case TR_COMPLETED : <nl> - return static_cast < qlonglong > ( m_lastStatus . total_wanted_done ) ; <nl> - case TR_RATIO_LIMIT : { <nl> - QString hash = misc : : toQString ( m_lastStatus . info_hash ) ; <nl> - return QBtSession : : instance ( ) - > getMaxRatioPerTorrent ( hash , NULL ) ; <nl> - } <nl> - case TR_SEEN_COMPLETE_DATE : <nl> - return m_lastStatus . last_seen_complete ? QDateTime : : fromTime_t ( m_lastStatus . last_seen_complete ) : QDateTime ( ) ; <nl> - case TR_LAST_ACTIVITY : <nl> - if ( m_torrent . is_paused ( m_lastStatus ) | | m_torrent . is_checking ( m_lastStatus ) ) <nl> - return - 1 ; <nl> - if ( m_lastStatus . time_since_upload < m_lastStatus . time_since_download ) <nl> - return m_lastStatus . time_since_upload ; <nl> - else <nl> - return m_lastStatus . time_since_download ; <nl> - case TR_TOTAL_SIZE : <nl> - return m_lastStatus . has_metadata ? static_cast < qlonglong > ( m_torrent . total_size ( ) ) : - 1 ; <nl> - default : <nl> - return QVariant ( ) ; <nl> - } <nl> + if ( role = = Qt : : DecorationRole & & column = = TR_NAME ) { <nl> + return getIconByState ( state ( ) ) ; <nl> + } <nl> + if ( role = = Qt : : ForegroundRole ) { <nl> + return getColorByState ( state ( ) ) ; <nl> + } <nl> + if ( role ! = Qt : : DisplayRole & & role ! = Qt : : UserRole ) return QVariant ( ) ; <nl> + switch ( column ) { <nl> + case TR_NAME : <nl> + return m_name . isEmpty ( ) ? m_torrent . name ( ) : m_name ; <nl> + case TR_PRIORITY : { <nl> + int pos = m_torrent . queue_position ( m_lastStatus ) ; <nl> + if ( pos > - 1 ) <nl> + return pos - HiddenData : : getSize ( ) ; <nl> + else <nl> + return pos ; <nl> + } <nl> + case TR_SIZE : <nl> + return m_lastStatus . has_metadata ? static_cast < qlonglong > ( m_lastStatus . total_wanted ) : - 1 ; <nl> + case TR_PROGRESS : <nl> + return m_torrent . progress ( m_lastStatus ) ; <nl> + case TR_STATUS : <nl> + return state ( ) ; <nl> + case TR_SEEDS : { <nl> + return ( role = = Qt : : DisplayRole ) ? m_lastStatus . num_seeds : m_lastStatus . num_complete ; <nl> + } <nl> + case TR_PEERS : { <nl> + return ( role = = Qt : : DisplayRole ) ? ( m_lastStatus . num_peers - m_lastStatus . num_seeds ) : m_lastStatus . num_incomplete ; <nl> + } <nl> + case TR_DLSPEED : <nl> + return m_lastStatus . download_payload_rate ; <nl> + case TR_UPSPEED : <nl> + return m_lastStatus . upload_payload_rate ; <nl> + case TR_ETA : { <nl> + / / XXX : Is this correct ? <nl> + if ( m_torrent . is_paused ( m_lastStatus ) | | m_torrent . is_queued ( m_lastStatus ) ) return MAX_ETA ; <nl> + return QBtSession : : instance ( ) - > getETA ( m_hash , m_lastStatus ) ; <nl> + } <nl> + case TR_RATIO : <nl> + return QBtSession : : instance ( ) - > getRealRatio ( m_lastStatus ) ; <nl> + case TR_LABEL : <nl> + return m_label ; <nl> + case TR_ADD_DATE : <nl> + return m_addedTime ; <nl> + case TR_SEED_DATE : <nl> + return m_lastStatus . completed_time ? QDateTime : : fromTime_t ( m_lastStatus . completed_time ) : QDateTime ( ) ; <nl> + case TR_TRACKER : <nl> + return misc : : toQString ( m_lastStatus . current_tracker ) ; <nl> + case TR_DLLIMIT : <nl> + return m_torrent . download_limit ( ) ; <nl> + case TR_UPLIMIT : <nl> + return m_torrent . upload_limit ( ) ; <nl> + case TR_AMOUNT_DOWNLOADED : <nl> + return static_cast < qlonglong > ( m_lastStatus . all_time_download ) ; <nl> + case TR_AMOUNT_UPLOADED : <nl> + return static_cast < qlonglong > ( m_lastStatus . all_time_upload ) ; <nl> + case TR_AMOUNT_LEFT : <nl> + return static_cast < qlonglong > ( m_lastStatus . total_wanted - m_lastStatus . total_wanted_done ) ; <nl> + case TR_TIME_ELAPSED : <nl> + return ( role = = Qt : : DisplayRole ) ? m_lastStatus . active_time : m_lastStatus . seeding_time ; <nl> + case TR_SAVE_PATH : <nl> + return fsutils : : toNativePath ( m_torrent . save_path_parsed ( ) ) ; <nl> + case TR_COMPLETED : <nl> + return static_cast < qlonglong > ( m_lastStatus . total_wanted_done ) ; <nl> + case TR_RATIO_LIMIT : { <nl> + QString hash = misc : : toQString ( m_lastStatus . info_hash ) ; <nl> + return QBtSession : : instance ( ) - > getMaxRatioPerTorrent ( hash , NULL ) ; <nl> + } <nl> + case TR_SEEN_COMPLETE_DATE : <nl> + return m_lastStatus . last_seen_complete ? QDateTime : : fromTime_t ( m_lastStatus . last_seen_complete ) : QDateTime ( ) ; <nl> + case TR_LAST_ACTIVITY : <nl> + if ( m_torrent . is_paused ( m_lastStatus ) | | m_torrent . is_checking ( m_lastStatus ) ) <nl> + return - 1 ; <nl> + if ( m_lastStatus . time_since_upload < m_lastStatus . time_since_download ) <nl> + return m_lastStatus . time_since_upload ; <nl> + else <nl> + return m_lastStatus . time_since_download ; <nl> + case TR_TOTAL_SIZE : <nl> + return m_lastStatus . has_metadata ? static_cast < qlonglong > ( m_torrent . total_size ( ) ) : - 1 ; <nl> + default : <nl> + return QVariant ( ) ; <nl> + } <nl> } <nl> <nl> / / TORRENT MODEL <nl> <nl> TorrentModel : : TorrentModel ( QObject * parent ) : <nl> - QAbstractListModel ( parent ) , m_refreshInterval ( 2000 ) <nl> + QAbstractListModel ( parent ) , m_refreshInterval ( 2000 ) <nl> { <nl> } <nl> <nl> void TorrentModel : : populate ( ) { <nl> - / / Load the torrents <nl> - std : : vector < torrent_handle > torrents = QBtSession : : instance ( ) - > getSession ( ) - > get_torrents ( ) ; <nl> - <nl> - std : : vector < torrent_handle > : : const_iterator it = torrents . begin ( ) ; <nl> - std : : vector < torrent_handle > : : const_iterator itend = torrents . end ( ) ; <nl> - for ( ; it ! = itend ; + + it ) { <nl> - const QTorrentHandle h ( * it ) ; <nl> - if ( HiddenData : : hasData ( h . hash ( ) ) ) <nl> - continue ; <nl> - addTorrent ( h ) ; <nl> - } <nl> - / / Refresh timer <nl> - connect ( & m_refreshTimer , SIGNAL ( timeout ( ) ) , SLOT ( forceModelRefresh ( ) ) ) ; <nl> - m_refreshTimer . start ( m_refreshInterval ) ; <nl> - / / Listen for torrent changes <nl> - connect ( QBtSession : : instance ( ) , SIGNAL ( addedTorrent ( QTorrentHandle ) ) , SLOT ( addTorrent ( QTorrentHandle ) ) ) ; <nl> - connect ( QBtSession : : instance ( ) , SIGNAL ( torrentAboutToBeRemoved ( QTorrentHandle ) ) , SLOT ( handleTorrentAboutToBeRemoved ( QTorrentHandle ) ) ) ; <nl> - connect ( QBtSession : : instance ( ) , SIGNAL ( finishedTorrent ( QTorrentHandle ) ) , SLOT ( handleFinishedTorrent ( QTorrentHandle ) ) ) ; <nl> - connect ( QBtSession : : instance ( ) , SIGNAL ( metadataReceived ( QTorrentHandle ) ) , SLOT ( handleTorrentUpdate ( QTorrentHandle ) ) ) ; <nl> - connect ( QBtSession : : instance ( ) , SIGNAL ( resumedTorrent ( QTorrentHandle ) ) , SLOT ( handleTorrentUpdate ( QTorrentHandle ) ) ) ; <nl> - connect ( QBtSession : : instance ( ) , SIGNAL ( pausedTorrent ( QTorrentHandle ) ) , SLOT ( handleTorrentUpdate ( QTorrentHandle ) ) ) ; <nl> - connect ( QBtSession : : instance ( ) , SIGNAL ( torrentFinishedChecking ( QTorrentHandle ) ) , SLOT ( handleTorrentUpdate ( QTorrentHandle ) ) ) ; <nl> - connect ( QBtSession : : instance ( ) , SIGNAL ( stateUpdate ( std : : vector < libtorrent : : torrent_status > ) ) , SLOT ( stateUpdated ( std : : vector < libtorrent : : torrent_status > ) ) ) ; <nl> + / / Load the torrents <nl> + std : : vector < torrent_handle > torrents = QBtSession : : instance ( ) - > getSession ( ) - > get_torrents ( ) ; <nl> + <nl> + std : : vector < torrent_handle > : : const_iterator it = torrents . begin ( ) ; <nl> + std : : vector < torrent_handle > : : const_iterator itend = torrents . end ( ) ; <nl> + for ( ; it ! = itend ; + + it ) { <nl> + const QTorrentHandle h ( * it ) ; <nl> + if ( HiddenData : : hasData ( h . hash ( ) ) ) <nl> + continue ; <nl> + addTorrent ( h ) ; <nl> + } <nl> + / / Refresh timer <nl> + connect ( & m_refreshTimer , SIGNAL ( timeout ( ) ) , SLOT ( forceModelRefresh ( ) ) ) ; <nl> + m_refreshTimer . start ( m_refreshInterval ) ; <nl> + / / Listen for torrent changes <nl> + connect ( QBtSession : : instance ( ) , SIGNAL ( addedTorrent ( QTorrentHandle ) ) , SLOT ( addTorrent ( QTorrentHandle ) ) ) ; <nl> + connect ( QBtSession : : instance ( ) , SIGNAL ( torrentAboutToBeRemoved ( QTorrentHandle ) ) , SLOT ( handleTorrentAboutToBeRemoved ( QTorrentHandle ) ) ) ; <nl> + connect ( QBtSession : : instance ( ) , SIGNAL ( finishedTorrent ( QTorrentHandle ) ) , SLOT ( handleFinishedTorrent ( QTorrentHandle ) ) ) ; <nl> + connect ( QBtSession : : instance ( ) , SIGNAL ( metadataReceived ( QTorrentHandle ) ) , SLOT ( handleTorrentUpdate ( QTorrentHandle ) ) ) ; <nl> + connect ( QBtSession : : instance ( ) , SIGNAL ( resumedTorrent ( QTorrentHandle ) ) , SLOT ( handleTorrentUpdate ( QTorrentHandle ) ) ) ; <nl> + connect ( QBtSession : : instance ( ) , SIGNAL ( pausedTorrent ( QTorrentHandle ) ) , SLOT ( handleTorrentUpdate ( QTorrentHandle ) ) ) ; <nl> + connect ( QBtSession : : instance ( ) , SIGNAL ( torrentFinishedChecking ( QTorrentHandle ) ) , SLOT ( handleTorrentUpdate ( QTorrentHandle ) ) ) ; <nl> + connect ( QBtSession : : instance ( ) , SIGNAL ( stateUpdate ( std : : vector < libtorrent : : torrent_status > ) ) , SLOT ( stateUpdated ( std : : vector < libtorrent : : torrent_status > ) ) ) ; <nl> } <nl> <nl> TorrentModel : : ~ TorrentModel ( ) { <nl> - qDebug ( ) < < Q_FUNC_INFO < < " ENTER " ; <nl> - qDeleteAll ( m_torrents ) ; <nl> - m_torrents . clear ( ) ; <nl> - qDebug ( ) < < Q_FUNC_INFO < < " EXIT " ; <nl> + qDebug ( ) < < Q_FUNC_INFO < < " ENTER " ; <nl> + qDeleteAll ( m_torrents ) ; <nl> + m_torrents . clear ( ) ; <nl> + qDebug ( ) < < Q_FUNC_INFO < < " EXIT " ; <nl> } <nl> <nl> QVariant TorrentModel : : headerData ( int section , Qt : : Orientation orientation , <nl> int role ) const <nl> { <nl> - if ( orientation = = Qt : : Horizontal ) { <nl> - if ( role = = Qt : : DisplayRole ) { <nl> - switch ( section ) { <nl> - case TorrentModelItem : : TR_NAME : return tr ( " Name " , " i . e : torrent name " ) ; <nl> - case TorrentModelItem : : TR_PRIORITY : return " # " ; <nl> - case TorrentModelItem : : TR_SIZE : return tr ( " Size " , " i . e : torrent size " ) ; <nl> - case TorrentModelItem : : TR_PROGRESS : return tr ( " Done " , " % Done " ) ; <nl> - case TorrentModelItem : : TR_STATUS : return tr ( " Status " , " Torrent status ( e . g . downloading , seeding , paused ) " ) ; <nl> - case TorrentModelItem : : TR_SEEDS : return tr ( " Seeds " , " i . e . full sources ( often untranslated ) " ) ; <nl> - case TorrentModelItem : : TR_PEERS : return tr ( " Peers " , " i . e . partial sources ( often untranslated ) " ) ; <nl> - case TorrentModelItem : : TR_DLSPEED : return tr ( " Down Speed " , " i . e : Download speed " ) ; <nl> - case TorrentModelItem : : TR_UPSPEED : return tr ( " Up Speed " , " i . e : Upload speed " ) ; <nl> - case TorrentModelItem : : TR_RATIO : return tr ( " Ratio " , " Share ratio " ) ; <nl> - case TorrentModelItem : : TR_ETA : return tr ( " ETA " , " i . e : Estimated Time of Arrival / Time left " ) ; <nl> - case TorrentModelItem : : TR_LABEL : return tr ( " Label " ) ; <nl> - case TorrentModelItem : : TR_ADD_DATE : return tr ( " Added On " , " Torrent was added to transfer list on 01 / 01 / 2010 08 : 00 " ) ; <nl> - case TorrentModelItem : : TR_SEED_DATE : return tr ( " Completed On " , " Torrent was completed on 01 / 01 / 2010 08 : 00 " ) ; <nl> - case TorrentModelItem : : TR_TRACKER : return tr ( " Tracker " ) ; <nl> - case TorrentModelItem : : TR_DLLIMIT : return tr ( " Down Limit " , " i . e : Download limit " ) ; <nl> - case TorrentModelItem : : TR_UPLIMIT : return tr ( " Up Limit " , " i . e : Upload limit " ) ; <nl> - case TorrentModelItem : : TR_AMOUNT_DOWNLOADED : return tr ( " Downloaded " , " Amount of data downloaded ( e . g . in MB ) " ) ; <nl> - case TorrentModelItem : : TR_AMOUNT_UPLOADED : return tr ( " Uploaded " , " Amount of data uploaded ( e . g . in MB ) " ) ; <nl> - case TorrentModelItem : : TR_AMOUNT_LEFT : return tr ( " Remaining " , " Amount of data left to download ( e . g . in MB ) " ) ; <nl> - case TorrentModelItem : : TR_TIME_ELAPSED : return tr ( " Time Active " , " Time ( duration ) the torrent is active ( not paused ) " ) ; <nl> - case TorrentModelItem : : TR_SAVE_PATH : return tr ( " Save path " , " Torrent save path " ) ; <nl> - case TorrentModelItem : : TR_COMPLETED : return tr ( " Completed " , " Amount of data completed ( e . g . in MB ) " ) ; <nl> - case TorrentModelItem : : TR_RATIO_LIMIT : return tr ( " Ratio Limit " , " Upload share ratio limit " ) ; <nl> - case TorrentModelItem : : TR_SEEN_COMPLETE_DATE : return tr ( " Last Seen Complete " , " Indicates the time when the torrent was last seen complete / whole " ) ; <nl> - case TorrentModelItem : : TR_LAST_ACTIVITY : return tr ( " Last Activity " , " Time passed since a chunk was downloaded / uploaded " ) ; <nl> - case TorrentModelItem : : TR_TOTAL_SIZE : return tr ( " Total Size " , " i . e . Size including unwanted data " ) ; <nl> - default : <nl> - return QVariant ( ) ; <nl> - } <nl> - } <nl> - else if ( role = = Qt : : TextAlignmentRole ) { <nl> - switch ( section ) { <nl> - case TorrentModelItem : : TR_AMOUNT_DOWNLOADED : <nl> - case TorrentModelItem : : TR_AMOUNT_UPLOADED : <nl> - case TorrentModelItem : : TR_AMOUNT_LEFT : <nl> - case TorrentModelItem : : TR_COMPLETED : <nl> - case TorrentModelItem : : TR_SIZE : <nl> - case TorrentModelItem : : TR_TOTAL_SIZE : <nl> - case TorrentModelItem : : TR_ETA : <nl> - case TorrentModelItem : : TR_SEEDS : <nl> - case TorrentModelItem : : TR_PEERS : <nl> - case TorrentModelItem : : TR_UPSPEED : <nl> - case TorrentModelItem : : TR_DLSPEED : <nl> - case TorrentModelItem : : TR_UPLIMIT : <nl> - case TorrentModelItem : : TR_DLLIMIT : <nl> - case TorrentModelItem : : TR_RATIO_LIMIT : <nl> - case TorrentModelItem : : TR_RATIO : <nl> - case TorrentModelItem : : TR_PRIORITY : <nl> - case TorrentModelItem : : TR_LAST_ACTIVITY : <nl> - return QVariant ( Qt : : AlignRight | Qt : : AlignVCenter ) ; <nl> - default : <nl> - return QAbstractListModel : : headerData ( section , orientation , role ) ; <nl> - } <nl> + if ( orientation = = Qt : : Horizontal ) { <nl> + if ( role = = Qt : : DisplayRole ) { <nl> + switch ( section ) { <nl> + case TorrentModelItem : : TR_NAME : return tr ( " Name " , " i . e : torrent name " ) ; <nl> + case TorrentModelItem : : TR_PRIORITY : return " # " ; <nl> + case TorrentModelItem : : TR_SIZE : return tr ( " Size " , " i . e : torrent size " ) ; <nl> + case TorrentModelItem : : TR_PROGRESS : return tr ( " Done " , " % Done " ) ; <nl> + case TorrentModelItem : : TR_STATUS : return tr ( " Status " , " Torrent status ( e . g . downloading , seeding , paused ) " ) ; <nl> + case TorrentModelItem : : TR_SEEDS : return tr ( " Seeds " , " i . e . full sources ( often untranslated ) " ) ; <nl> + case TorrentModelItem : : TR_PEERS : return tr ( " Peers " , " i . e . partial sources ( often untranslated ) " ) ; <nl> + case TorrentModelItem : : TR_DLSPEED : return tr ( " Down Speed " , " i . e : Download speed " ) ; <nl> + case TorrentModelItem : : TR_UPSPEED : return tr ( " Up Speed " , " i . e : Upload speed " ) ; <nl> + case TorrentModelItem : : TR_RATIO : return tr ( " Ratio " , " Share ratio " ) ; <nl> + case TorrentModelItem : : TR_ETA : return tr ( " ETA " , " i . e : Estimated Time of Arrival / Time left " ) ; <nl> + case TorrentModelItem : : TR_LABEL : return tr ( " Label " ) ; <nl> + case TorrentModelItem : : TR_ADD_DATE : return tr ( " Added On " , " Torrent was added to transfer list on 01 / 01 / 2010 08 : 00 " ) ; <nl> + case TorrentModelItem : : TR_SEED_DATE : return tr ( " Completed On " , " Torrent was completed on 01 / 01 / 2010 08 : 00 " ) ; <nl> + case TorrentModelItem : : TR_TRACKER : return tr ( " Tracker " ) ; <nl> + case TorrentModelItem : : TR_DLLIMIT : return tr ( " Down Limit " , " i . e : Download limit " ) ; <nl> + case TorrentModelItem : : TR_UPLIMIT : return tr ( " Up Limit " , " i . e : Upload limit " ) ; <nl> + case TorrentModelItem : : TR_AMOUNT_DOWNLOADED : return tr ( " Downloaded " , " Amount of data downloaded ( e . g . in MB ) " ) ; <nl> + case TorrentModelItem : : TR_AMOUNT_UPLOADED : return tr ( " Uploaded " , " Amount of data uploaded ( e . g . in MB ) " ) ; <nl> + case TorrentModelItem : : TR_AMOUNT_LEFT : return tr ( " Remaining " , " Amount of data left to download ( e . g . in MB ) " ) ; <nl> + case TorrentModelItem : : TR_TIME_ELAPSED : return tr ( " Time Active " , " Time ( duration ) the torrent is active ( not paused ) " ) ; <nl> + case TorrentModelItem : : TR_SAVE_PATH : return tr ( " Save path " , " Torrent save path " ) ; <nl> + case TorrentModelItem : : TR_COMPLETED : return tr ( " Completed " , " Amount of data completed ( e . g . in MB ) " ) ; <nl> + case TorrentModelItem : : TR_RATIO_LIMIT : return tr ( " Ratio Limit " , " Upload share ratio limit " ) ; <nl> + case TorrentModelItem : : TR_SEEN_COMPLETE_DATE : return tr ( " Last Seen Complete " , " Indicates the time when the torrent was last seen complete / whole " ) ; <nl> + case TorrentModelItem : : TR_LAST_ACTIVITY : return tr ( " Last Activity " , " Time passed since a chunk was downloaded / uploaded " ) ; <nl> + case TorrentModelItem : : TR_TOTAL_SIZE : return tr ( " Total Size " , " i . e . Size including unwanted data " ) ; <nl> + default : <nl> + return QVariant ( ) ; <nl> + } <nl> + } <nl> + else if ( role = = Qt : : TextAlignmentRole ) { <nl> + switch ( section ) { <nl> + case TorrentModelItem : : TR_AMOUNT_DOWNLOADED : <nl> + case TorrentModelItem : : TR_AMOUNT_UPLOADED : <nl> + case TorrentModelItem : : TR_AMOUNT_LEFT : <nl> + case TorrentModelItem : : TR_COMPLETED : <nl> + case TorrentModelItem : : TR_SIZE : <nl> + case TorrentModelItem : : TR_TOTAL_SIZE : <nl> + case TorrentModelItem : : TR_ETA : <nl> + case TorrentModelItem : : TR_SEEDS : <nl> + case TorrentModelItem : : TR_PEERS : <nl> + case TorrentModelItem : : TR_UPSPEED : <nl> + case TorrentModelItem : : TR_DLSPEED : <nl> + case TorrentModelItem : : TR_UPLIMIT : <nl> + case TorrentModelItem : : TR_DLLIMIT : <nl> + case TorrentModelItem : : TR_RATIO_LIMIT : <nl> + case TorrentModelItem : : TR_RATIO : <nl> + case TorrentModelItem : : TR_PRIORITY : <nl> + case TorrentModelItem : : TR_LAST_ACTIVITY : <nl> + return QVariant ( Qt : : AlignRight | Qt : : AlignVCenter ) ; <nl> + default : <nl> + return QAbstractListModel : : headerData ( section , orientation , role ) ; <nl> + } <nl> + } <nl> } <nl> - } <nl> <nl> - return QVariant ( ) ; <nl> + return QVariant ( ) ; <nl> } <nl> <nl> QVariant TorrentModel : : data ( const QModelIndex & index , int role ) const <nl> { <nl> - if ( ! index . isValid ( ) ) return QVariant ( ) ; <nl> - try { <nl> - if ( index . row ( ) > = 0 & & index . row ( ) < rowCount ( ) & & index . column ( ) > = 0 & & index . column ( ) < columnCount ( ) ) <nl> - return m_torrents [ index . row ( ) ] - > data ( index . column ( ) , role ) ; <nl> - } catch ( invalid_handle & ) { } <nl> - return QVariant ( ) ; <nl> + if ( ! index . isValid ( ) ) return QVariant ( ) ; <nl> + try { <nl> + if ( index . row ( ) > = 0 & & index . row ( ) < rowCount ( ) & & index . column ( ) > = 0 & & index . column ( ) < columnCount ( ) ) <nl> + return m_torrents [ index . row ( ) ] - > data ( index . column ( ) , role ) ; <nl> + } catch ( invalid_handle & ) { } <nl> + return QVariant ( ) ; <nl> } <nl> <nl> bool TorrentModel : : setData ( const QModelIndex & index , const QVariant & value , int role ) <nl> { <nl> - qDebug ( ) < < Q_FUNC_INFO < < value ; <nl> - if ( ! index . isValid ( ) | | role ! = Qt : : DisplayRole ) return false ; <nl> - qDebug ( " Index is valid and role is DisplayRole " ) ; <nl> - try { <nl> - if ( index . row ( ) > = 0 & & index . row ( ) < rowCount ( ) & & index . column ( ) > = 0 & & index . column ( ) < columnCount ( ) ) { <nl> - bool change = m_torrents [ index . row ( ) ] - > setData ( index . column ( ) , value , role ) ; <nl> - if ( change ) <nl> - notifyTorrentChanged ( index . row ( ) ) ; <nl> - return change ; <nl> - } <nl> - } catch ( invalid_handle & ) { } <nl> - return false ; <nl> + qDebug ( ) < < Q_FUNC_INFO < < value ; <nl> + if ( ! index . isValid ( ) | | role ! = Qt : : DisplayRole ) return false ; <nl> + qDebug ( " Index is valid and role is DisplayRole " ) ; <nl> + try { <nl> + if ( index . row ( ) > = 0 & & index . row ( ) < rowCount ( ) & & index . column ( ) > = 0 & & index . column ( ) < columnCount ( ) ) { <nl> + bool change = m_torrents [ index . row ( ) ] - > setData ( index . column ( ) , value , role ) ; <nl> + if ( change ) <nl> + notifyTorrentChanged ( index . row ( ) ) ; <nl> + return change ; <nl> + } <nl> + } catch ( invalid_handle & ) { } <nl> + return false ; <nl> } <nl> <nl> int TorrentModel : : torrentRow ( const QString & hash ) const <nl> { <nl> - int row = 0 ; <nl> + int row = 0 ; <nl> <nl> - QList < TorrentModelItem * > : : const_iterator it = m_torrents . constBegin ( ) ; <nl> - QList < TorrentModelItem * > : : const_iterator itend = m_torrents . constEnd ( ) ; <nl> - for ( ; it ! = itend ; + + it ) { <nl> - if ( ( * it ) - > hash ( ) = = hash ) return row ; <nl> - + + row ; <nl> - } <nl> - return - 1 ; <nl> + QList < TorrentModelItem * > : : const_iterator it = m_torrents . constBegin ( ) ; <nl> + QList < TorrentModelItem * > : : const_iterator itend = m_torrents . constEnd ( ) ; <nl> + for ( ; it ! = itend ; + + it ) { <nl> + if ( ( * it ) - > hash ( ) = = hash ) return row ; <nl> + + + row ; <nl> + } <nl> + return - 1 ; <nl> } <nl> <nl> void TorrentModel : : addTorrent ( const QTorrentHandle & h ) <nl> { <nl> - if ( torrentRow ( h . hash ( ) ) < 0 ) { <nl> - beginInsertTorrent ( m_torrents . size ( ) ) ; <nl> - TorrentModelItem * item = new TorrentModelItem ( h ) ; <nl> - connect ( item , SIGNAL ( labelChanged ( QString , QString ) ) , SLOT ( handleTorrentLabelChange ( QString , QString ) ) ) ; <nl> - m_torrents < < item ; <nl> - emit torrentAdded ( item ) ; <nl> - endInsertTorrent ( ) ; <nl> - } <nl> + if ( torrentRow ( h . hash ( ) ) < 0 ) { <nl> + beginInsertTorrent ( m_torrents . size ( ) ) ; <nl> + TorrentModelItem * item = new TorrentModelItem ( h ) ; <nl> + connect ( item , SIGNAL ( labelChanged ( QString , QString ) ) , SLOT ( handleTorrentLabelChange ( QString , QString ) ) ) ; <nl> + m_torrents < < item ; <nl> + emit torrentAdded ( item ) ; <nl> + endInsertTorrent ( ) ; <nl> + } <nl> } <nl> <nl> void TorrentModel : : beginInsertTorrent ( int row ) <nl> { <nl> - beginInsertRows ( QModelIndex ( ) , row , row ) ; <nl> + beginInsertRows ( QModelIndex ( ) , row , row ) ; <nl> } <nl> <nl> void TorrentModel : : endInsertTorrent ( ) <nl> { <nl> - endInsertRows ( ) ; <nl> + endInsertRows ( ) ; <nl> } <nl> <nl> void TorrentModel : : beginRemoveTorrent ( int row ) <nl> { <nl> - beginRemoveRows ( QModelIndex ( ) , row , row ) ; <nl> + beginRemoveRows ( QModelIndex ( ) , row , row ) ; <nl> } <nl> <nl> void TorrentModel : : endRemoveTorrent ( ) <nl> { <nl> - endRemoveRows ( ) ; <nl> + endRemoveRows ( ) ; <nl> } <nl> <nl> void TorrentModel : : handleTorrentUpdate ( const QTorrentHandle & h ) <nl> { <nl> - const int row = torrentRow ( h . hash ( ) ) ; <nl> - if ( row > = 0 ) { <nl> - m_torrents [ row ] - > refreshStatus ( h . status ( torrent_handle : : query_accurate_download_counters ) ) ; <nl> - notifyTorrentChanged ( row ) ; <nl> - } <nl> + const int row = torrentRow ( h . hash ( ) ) ; <nl> + if ( row > = 0 ) { <nl> + m_torrents [ row ] - > refreshStatus ( h . status ( torrent_handle : : query_accurate_download_counters ) ) ; <nl> + notifyTorrentChanged ( row ) ; <nl> + } <nl> } <nl> <nl> void TorrentModel : : handleFinishedTorrent ( const QTorrentHandle & h ) <nl> { <nl> - const int row = torrentRow ( h . hash ( ) ) ; <nl> - if ( row < 0 ) <nl> - return ; <nl> + const int row = torrentRow ( h . hash ( ) ) ; <nl> + if ( row < 0 ) <nl> + return ; <nl> <nl> - / / Update completion date <nl> - m_torrents [ row ] - > refreshStatus ( h . status ( torrent_handle : : query_accurate_download_counters ) ) ; <nl> - notifyTorrentChanged ( row ) ; <nl> + / / Update completion date <nl> + m_torrents [ row ] - > refreshStatus ( h . status ( torrent_handle : : query_accurate_download_counters ) ) ; <nl> + notifyTorrentChanged ( row ) ; <nl> } <nl> <nl> void TorrentModel : : notifyTorrentChanged ( int row ) <nl> { <nl> - emit dataChanged ( index ( row , 0 ) , index ( row , columnCount ( ) - 1 ) ) ; <nl> + emit dataChanged ( index ( row , 0 ) , index ( row , columnCount ( ) - 1 ) ) ; <nl> } <nl> <nl> void TorrentModel : : setRefreshInterval ( int refreshInterval ) <nl> { <nl> - if ( m_refreshInterval ! = refreshInterval ) { <nl> - m_refreshInterval = refreshInterval ; <nl> - m_refreshTimer . stop ( ) ; <nl> - m_refreshTimer . start ( m_refreshInterval ) ; <nl> - } <nl> + if ( m_refreshInterval ! = refreshInterval ) { <nl> + m_refreshInterval = refreshInterval ; <nl> + m_refreshTimer . stop ( ) ; <nl> + m_refreshTimer . start ( m_refreshInterval ) ; <nl> + } <nl> } <nl> <nl> void TorrentModel : : forceModelRefresh ( ) <nl> { <nl> - QBtSession : : instance ( ) - > postTorrentUpdate ( ) ; <nl> + QBtSession : : instance ( ) - > postTorrentUpdate ( ) ; <nl> } <nl> <nl> TorrentStatusReport TorrentModel : : getTorrentStatusReport ( ) const <nl> { <nl> - TorrentStatusReport report ; <nl> - <nl> - QList < TorrentModelItem * > : : const_iterator it = m_torrents . constBegin ( ) ; <nl> - QList < TorrentModelItem * > : : const_iterator itend = m_torrents . constEnd ( ) ; <nl> - for ( ; it ! = itend ; + + it ) { <nl> - switch ( ( * it ) - > state ( ) ) { <nl> - case TorrentModelItem : : STATE_DOWNLOADING : <nl> - + + report . nb_active ; <nl> - + + report . nb_downloading ; <nl> - break ; <nl> - case TorrentModelItem : : STATE_DOWNLOADING_META : <nl> - + + report . nb_downloading ; <nl> - break ; <nl> - case TorrentModelItem : : STATE_PAUSED_DL : <nl> - + + report . nb_paused ; <nl> - case TorrentModelItem : : STATE_STALLED_DL : <nl> - case TorrentModelItem : : STATE_CHECKING_DL : <nl> - case TorrentModelItem : : STATE_QUEUED_DL : { <nl> - + + report . nb_inactive ; <nl> - + + report . nb_downloading ; <nl> - break ; <nl> - } <nl> - case TorrentModelItem : : STATE_SEEDING : <nl> - + + report . nb_active ; <nl> - + + report . nb_seeding ; <nl> - break ; <nl> - case TorrentModelItem : : STATE_PAUSED_UP : <nl> - case TorrentModelItem : : STATE_PAUSED_MISSING : <nl> - + + report . nb_paused ; <nl> - case TorrentModelItem : : STATE_STALLED_UP : <nl> - case TorrentModelItem : : STATE_CHECKING_UP : <nl> - case TorrentModelItem : : STATE_QUEUED_UP : { <nl> - + + report . nb_seeding ; <nl> - + + report . nb_inactive ; <nl> - break ; <nl> + TorrentStatusReport report ; <nl> + <nl> + QList < TorrentModelItem * > : : const_iterator it = m_torrents . constBegin ( ) ; <nl> + QList < TorrentModelItem * > : : const_iterator itend = m_torrents . constEnd ( ) ; <nl> + for ( ; it ! = itend ; + + it ) { <nl> + switch ( ( * it ) - > state ( ) ) { <nl> + case TorrentModelItem : : STATE_DOWNLOADING : <nl> + + + report . nb_active ; <nl> + + + report . nb_downloading ; <nl> + break ; <nl> + case TorrentModelItem : : STATE_DOWNLOADING_META : <nl> + + + report . nb_downloading ; <nl> + break ; <nl> + case TorrentModelItem : : STATE_PAUSED_DL : <nl> + + + report . nb_paused ; <nl> + case TorrentModelItem : : STATE_STALLED_DL : <nl> + case TorrentModelItem : : STATE_CHECKING_DL : <nl> + case TorrentModelItem : : STATE_QUEUED_DL : { <nl> + + + report . nb_inactive ; <nl> + + + report . nb_downloading ; <nl> + break ; <nl> + } <nl> + case TorrentModelItem : : STATE_SEEDING : <nl> + + + report . nb_active ; <nl> + + + report . nb_seeding ; <nl> + break ; <nl> + case TorrentModelItem : : STATE_PAUSED_UP : <nl> + case TorrentModelItem : : STATE_PAUSED_MISSING : <nl> + + + report . nb_paused ; <nl> + case TorrentModelItem : : STATE_STALLED_UP : <nl> + case TorrentModelItem : : STATE_CHECKING_UP : <nl> + case TorrentModelItem : : STATE_QUEUED_UP : { <nl> + + + report . nb_seeding ; <nl> + + + report . nb_inactive ; <nl> + break ; <nl> + } <nl> + default : <nl> + break ; <nl> + } <nl> } <nl> - default : <nl> - break ; <nl> - } <nl> - } <nl> - return report ; <nl> + return report ; <nl> } <nl> <nl> Qt : : ItemFlags TorrentModel : : flags ( const QModelIndex & index ) const <nl> { <nl> - if ( ! index . isValid ( ) ) <nl> - return 0 ; <nl> - / / Explicitely mark as editable <nl> - return QAbstractListModel : : flags ( index ) | Qt : : ItemIsEditable ; <nl> + if ( ! index . isValid ( ) ) <nl> + return 0 ; <nl> + / / Explicitely mark as editable <nl> + return QAbstractListModel : : flags ( index ) | Qt : : ItemIsEditable ; <nl> } <nl> <nl> void TorrentModel : : handleTorrentLabelChange ( QString previous , QString current ) <nl> { <nl> - emit torrentChangedLabel ( static_cast < TorrentModelItem * > ( sender ( ) ) , previous , current ) ; <nl> + emit torrentChangedLabel ( static_cast < TorrentModelItem * > ( sender ( ) ) , previous , current ) ; <nl> } <nl> <nl> QString TorrentModel : : torrentHash ( int row ) const <nl> { <nl> - if ( row > = 0 & & row < rowCount ( ) ) <nl> - return m_torrents . at ( row ) - > hash ( ) ; <nl> - return QString ( ) ; <nl> + if ( row > = 0 & & row < rowCount ( ) ) <nl> + return m_torrents . at ( row ) - > hash ( ) ; <nl> + return QString ( ) ; <nl> } <nl> <nl> void TorrentModel : : handleTorrentAboutToBeRemoved ( const QTorrentHandle & h ) <nl> { <nl> - const int row = torrentRow ( h . hash ( ) ) ; <nl> - qDebug ( ) < < Q_FUNC_INFO < < row ; <nl> - if ( row > = 0 ) { <nl> - emit torrentAboutToBeRemoved ( m_torrents . at ( row ) ) ; <nl> + const int row = torrentRow ( h . hash ( ) ) ; <nl> + qDebug ( ) < < Q_FUNC_INFO < < row ; <nl> + if ( row > = 0 ) { <nl> + emit torrentAboutToBeRemoved ( m_torrents . at ( row ) ) ; <nl> <nl> - beginRemoveTorrent ( row ) ; <nl> - delete m_torrents [ row ] ; <nl> - m_torrents . removeAt ( row ) ; <nl> - endRemoveTorrent ( ) ; <nl> - } <nl> + beginRemoveTorrent ( row ) ; <nl> + delete m_torrents [ row ] ; <nl> + m_torrents . removeAt ( row ) ; <nl> + endRemoveTorrent ( ) ; <nl> + } <nl> } <nl> <nl> void TorrentModel : : stateUpdated ( const std : : vector < libtorrent : : torrent_status > & statuses ) { <nl> - typedef std : : vector < libtorrent : : torrent_status > statuses_t ; <nl> + typedef std : : vector < libtorrent : : torrent_status > statuses_t ; <nl> <nl> - for ( statuses_t : : const_iterator i = statuses . begin ( ) , end = statuses . end ( ) ; i ! = end ; + + i ) { <nl> - libtorrent : : torrent_status const & status = * i ; <nl> + for ( statuses_t : : const_iterator i = statuses . begin ( ) , end = statuses . end ( ) ; i ! = end ; + + i ) { <nl> + libtorrent : : torrent_status const & status = * i ; <nl> <nl> - const int row = torrentRow ( misc : : toQString ( status . info_hash ) ) ; <nl> - if ( row > = 0 ) { <nl> - m_torrents [ row ] - > refreshStatus ( status ) ; <nl> - notifyTorrentChanged ( row ) ; <nl> + const int row = torrentRow ( misc : : toQString ( status . info_hash ) ) ; <nl> + if ( row > = 0 ) { <nl> + m_torrents [ row ] - > refreshStatus ( status ) ; <nl> + notifyTorrentChanged ( row ) ; <nl> + } <nl> } <nl> - } <nl> <nl> - emit modelRefreshed ( ) ; <nl> + emit modelRefreshed ( ) ; <nl> } <nl> <nl> bool TorrentModel : : inhibitSystem ( ) <nl> { <nl> - QList < TorrentModelItem * > : : const_iterator it = m_torrents . constBegin ( ) ; <nl> - QList < TorrentModelItem * > : : const_iterator itend = m_torrents . constEnd ( ) ; <nl> - for ( ; it ! = itend ; + + it ) { <nl> - switch ( ( * it ) - > data ( TorrentModelItem : : TR_STATUS ) . toInt ( ) ) { <nl> - case TorrentModelItem : : STATE_DOWNLOADING : <nl> - case TorrentModelItem : : STATE_DOWNLOADING_META : <nl> - case TorrentModelItem : : STATE_STALLED_DL : <nl> - case TorrentModelItem : : STATE_SEEDING : <nl> - case TorrentModelItem : : STATE_STALLED_UP : <nl> - return true ; <nl> - default : <nl> - break ; <nl> + QList < TorrentModelItem * > : : const_iterator it = m_torrents . constBegin ( ) ; <nl> + QList < TorrentModelItem * > : : const_iterator itend = m_torrents . constEnd ( ) ; <nl> + for ( ; it ! = itend ; + + it ) { <nl> + switch ( ( * it ) - > data ( TorrentModelItem : : TR_STATUS ) . toInt ( ) ) { <nl> + case TorrentModelItem : : STATE_DOWNLOADING : <nl> + case TorrentModelItem : : STATE_DOWNLOADING_META : <nl> + case TorrentModelItem : : STATE_STALLED_DL : <nl> + case TorrentModelItem : : STATE_SEEDING : <nl> + case TorrentModelItem : : STATE_STALLED_UP : <nl> + return true ; <nl> + default : <nl> + break ; <nl> + } <nl> } <nl> - } <nl> - return false ; <nl> + return false ; <nl> } <nl> mmm a / src / core / qtlibtorrent / torrentmodel . h <nl> ppp b / src / core / qtlibtorrent / torrentmodel . h <nl> <nl> # include " qtorrenthandle . h " <nl> <nl> struct TorrentStatusReport { <nl> - TorrentStatusReport ( ) : nb_downloading ( 0 ) , nb_seeding ( 0 ) , nb_active ( 0 ) , nb_inactive ( 0 ) , nb_paused ( 0 ) { } <nl> - uint nb_downloading ; uint nb_seeding ; uint nb_active ; uint nb_inactive ; uint nb_paused ; <nl> + TorrentStatusReport ( ) : nb_downloading ( 0 ) , nb_seeding ( 0 ) , nb_active ( 0 ) , nb_inactive ( 0 ) , nb_paused ( 0 ) { } <nl> + uint nb_downloading ; uint nb_seeding ; uint nb_active ; uint nb_inactive ; uint nb_paused ; <nl> } ; <nl> <nl> class TorrentModelItem : public QObject { <nl> - Q_OBJECT <nl> + Q_OBJECT <nl> <nl> public : <nl> - enum State { STATE_DOWNLOADING , STATE_DOWNLOADING_META , STATE_ALLOCATING , STATE_STALLED_DL , STATE_SEEDING , STATE_STALLED_UP , STATE_QUEUED_DL , STATE_QUEUED_UP , STATE_CHECKING_UP , STATE_CHECKING_DL , STATE_QUEUED_CHECK , STATE_QUEUED_FASTCHECK , STATE_PAUSED_DL , STATE_PAUSED_UP , STATE_PAUSED_MISSING , STATE_INVALID } ; <nl> - enum Column { TR_NAME , TR_PRIORITY , TR_SIZE , TR_TOTAL_SIZE , TR_PROGRESS , TR_STATUS , TR_SEEDS , TR_PEERS , TR_DLSPEED , TR_UPSPEED , TR_ETA , TR_RATIO , TR_LABEL , TR_ADD_DATE , TR_SEED_DATE , TR_TRACKER , TR_DLLIMIT , TR_UPLIMIT , TR_AMOUNT_DOWNLOADED , TR_AMOUNT_UPLOADED , TR_AMOUNT_LEFT , TR_TIME_ELAPSED , TR_SAVE_PATH , TR_COMPLETED , TR_RATIO_LIMIT , TR_SEEN_COMPLETE_DATE , TR_LAST_ACTIVITY , NB_COLUMNS } ; <nl> + enum State { STATE_DOWNLOADING , STATE_DOWNLOADING_META , STATE_ALLOCATING , STATE_STALLED_DL , STATE_SEEDING , STATE_STALLED_UP , STATE_QUEUED_DL , STATE_QUEUED_UP , STATE_CHECKING_UP , STATE_CHECKING_DL , STATE_QUEUED_CHECK , STATE_QUEUED_FASTCHECK , STATE_PAUSED_DL , STATE_PAUSED_UP , STATE_PAUSED_MISSING , STATE_INVALID } ; <nl> + enum Column { TR_NAME , TR_PRIORITY , TR_SIZE , TR_TOTAL_SIZE , TR_PROGRESS , TR_STATUS , TR_SEEDS , TR_PEERS , TR_DLSPEED , TR_UPSPEED , TR_ETA , TR_RATIO , TR_LABEL , TR_ADD_DATE , TR_SEED_DATE , TR_TRACKER , TR_DLLIMIT , TR_UPLIMIT , TR_AMOUNT_DOWNLOADED , TR_AMOUNT_UPLOADED , TR_AMOUNT_LEFT , TR_TIME_ELAPSED , TR_SAVE_PATH , TR_COMPLETED , TR_RATIO_LIMIT , TR_SEEN_COMPLETE_DATE , TR_LAST_ACTIVITY , NB_COLUMNS } ; <nl> <nl> public : <nl> - TorrentModelItem ( const QTorrentHandle & h ) ; <nl> - void refreshStatus ( libtorrent : : torrent_status const & status ) ; <nl> - inline int columnCount ( ) const { return NB_COLUMNS ; } <nl> - QVariant data ( int column , int role = Qt : : DisplayRole ) const ; <nl> - bool setData ( int column , const QVariant & value , int role = Qt : : DisplayRole ) ; <nl> - inline QString const & hash ( ) const { return m_hash ; } <nl> - State state ( ) const ; <nl> + TorrentModelItem ( const QTorrentHandle & h ) ; <nl> + void refreshStatus ( libtorrent : : torrent_status const & status ) ; <nl> + inline int columnCount ( ) const { return NB_COLUMNS ; } <nl> + QVariant data ( int column , int role = Qt : : DisplayRole ) const ; <nl> + bool setData ( int column , const QVariant & value , int role = Qt : : DisplayRole ) ; <nl> + inline QString const & hash ( ) const { return m_hash ; } <nl> + State state ( ) const ; <nl> <nl> signals : <nl> - void labelChanged ( QString previous , QString current ) ; <nl> + void labelChanged ( QString previous , QString current ) ; <nl> <nl> private : <nl> - static QIcon getIconByState ( State state ) ; <nl> - static QColor getColorByState ( State state ) ; <nl> + static QIcon getIconByState ( State state ) ; <nl> + static QColor getColorByState ( State state ) ; <nl> <nl> private : <nl> - QTorrentHandle m_torrent ; <nl> - libtorrent : : torrent_status m_lastStatus ; <nl> - QDateTime m_addedTime ; <nl> - QString m_label ; <nl> - QString m_name ; <nl> - QString m_hash ; / / Cached for safety reasons <nl> + QTorrentHandle m_torrent ; <nl> + libtorrent : : torrent_status m_lastStatus ; <nl> + QDateTime m_addedTime ; <nl> + QString m_label ; <nl> + QString m_name ; <nl> + QString m_hash ; / / Cached for safety reasons <nl> } ; <nl> <nl> class TorrentModel : public QAbstractListModel <nl> { <nl> - Q_OBJECT <nl> - Q_DISABLE_COPY ( TorrentModel ) <nl> + Q_OBJECT <nl> + Q_DISABLE_COPY ( TorrentModel ) <nl> <nl> public : <nl> - explicit TorrentModel ( QObject * parent = 0 ) ; <nl> - ~ TorrentModel ( ) ; <nl> - inline int rowCount ( const QModelIndex & index = QModelIndex ( ) ) const { Q_UNUSED ( index ) ; return m_torrents . size ( ) ; } <nl> - int columnCount ( const QModelIndex & parent = QModelIndex ( ) ) const { Q_UNUSED ( parent ) ; return TorrentModelItem : : NB_COLUMNS ; } <nl> - QVariant data ( const QModelIndex & index , int role = Qt : : DisplayRole ) const ; <nl> - bool setData ( const QModelIndex & index , const QVariant & value , int role = Qt : : DisplayRole ) ; <nl> - QVariant headerData ( int section , Qt : : Orientation orientation , int role ) const ; <nl> - int torrentRow ( const QString & hash ) const ; <nl> - QString torrentHash ( int row ) const ; <nl> - void setRefreshInterval ( int refreshInterval ) ; <nl> - TorrentStatusReport getTorrentStatusReport ( ) const ; <nl> - Qt : : ItemFlags flags ( const QModelIndex & index ) const ; <nl> - void populate ( ) ; <nl> - bool inhibitSystem ( ) ; <nl> + explicit TorrentModel ( QObject * parent = 0 ) ; <nl> + ~ TorrentModel ( ) ; <nl> + inline int rowCount ( const QModelIndex & index = QModelIndex ( ) ) const { Q_UNUSED ( index ) ; return m_torrents . size ( ) ; } <nl> + int columnCount ( const QModelIndex & parent = QModelIndex ( ) ) const { Q_UNUSED ( parent ) ; return TorrentModelItem : : NB_COLUMNS ; } <nl> + QVariant data ( const QModelIndex & index , int role = Qt : : DisplayRole ) const ; <nl> + bool setData ( const QModelIndex & index , const QVariant & value , int role = Qt : : DisplayRole ) ; <nl> + QVariant headerData ( int section , Qt : : Orientation orientation , int role ) const ; <nl> + int torrentRow ( const QString & hash ) const ; <nl> + QString torrentHash ( int row ) const ; <nl> + void setRefreshInterval ( int refreshInterval ) ; <nl> + TorrentStatusReport getTorrentStatusReport ( ) const ; <nl> + Qt : : ItemFlags flags ( const QModelIndex & index ) const ; <nl> + void populate ( ) ; <nl> + bool inhibitSystem ( ) ; <nl> <nl> signals : <nl> - void torrentAdded ( TorrentModelItem * torrentItem ) ; <nl> - void torrentAboutToBeRemoved ( TorrentModelItem * torrentItem ) ; <nl> - void torrentChangedLabel ( TorrentModelItem * torrentItem , QString previous , QString current ) ; <nl> - void modelRefreshed ( ) ; <nl> + void torrentAdded ( TorrentModelItem * torrentItem ) ; <nl> + void torrentAboutToBeRemoved ( TorrentModelItem * torrentItem ) ; <nl> + void torrentChangedLabel ( TorrentModelItem * torrentItem , QString previous , QString current ) ; <nl> + void modelRefreshed ( ) ; <nl> <nl> private slots : <nl> - void addTorrent ( const QTorrentHandle & h ) ; <nl> - void handleTorrentUpdate ( const QTorrentHandle & h ) ; <nl> - void handleFinishedTorrent ( const QTorrentHandle & h ) ; <nl> - void notifyTorrentChanged ( int row ) ; <nl> - void forceModelRefresh ( ) ; <nl> - void handleTorrentLabelChange ( QString previous , QString current ) ; <nl> - void handleTorrentAboutToBeRemoved ( const QTorrentHandle & h ) ; <nl> - void stateUpdated ( const std : : vector < libtorrent : : torrent_status > & statuses ) ; <nl> + void addTorrent ( const QTorrentHandle & h ) ; <nl> + void handleTorrentUpdate ( const QTorrentHandle & h ) ; <nl> + void handleFinishedTorrent ( const QTorrentHandle & h ) ; <nl> + void notifyTorrentChanged ( int row ) ; <nl> + void forceModelRefresh ( ) ; <nl> + void handleTorrentLabelChange ( QString previous , QString current ) ; <nl> + void handleTorrentAboutToBeRemoved ( const QTorrentHandle & h ) ; <nl> + void stateUpdated ( const std : : vector < libtorrent : : torrent_status > & statuses ) ; <nl> <nl> private : <nl> - void beginInsertTorrent ( int row ) ; <nl> - void endInsertTorrent ( ) ; <nl> - void beginRemoveTorrent ( int row ) ; <nl> - void endRemoveTorrent ( ) ; <nl> + void beginInsertTorrent ( int row ) ; <nl> + void endInsertTorrent ( ) ; <nl> + void beginRemoveTorrent ( int row ) ; <nl> + void endRemoveTorrent ( ) ; <nl> <nl> private : <nl> - QList < TorrentModelItem * > m_torrents ; <nl> - int m_refreshInterval ; <nl> - QTimer m_refreshTimer ; <nl> + QList < TorrentModelItem * > m_torrents ; <nl> + int m_refreshInterval ; <nl> + QTimer m_refreshTimer ; <nl> } ; <nl> <nl> # endif / / TORRENTMODEL_H <nl> mmm a / src / core / qtlibtorrent / torrentspeedmonitor . cpp <nl> ppp b / src / core / qtlibtorrent / torrentspeedmonitor . cpp <nl> using namespace libtorrent ; <nl> <nl> namespace { <nl> <nl> - template < class T > struct Sample { <nl> + template < class T > struct Sample { <nl> Sample ( ) <nl> - : download ( ) <nl> - , upload ( ) <nl> + : download ( ) <nl> + , upload ( ) <nl> { } <nl> <nl> Sample ( T download , T upload ) <nl> - : download ( download ) <nl> - , upload ( upload ) <nl> + : download ( download ) <nl> + , upload ( upload ) <nl> { } <nl> <nl> template < typename U > <nl> explicit Sample ( Sample < U > other ) <nl> - : download ( static_cast < U > ( other . download ) ) <nl> - , upload ( static_cast < U > ( other . upload ) ) <nl> + : download ( static_cast < U > ( other . download ) ) <nl> + , upload ( static_cast < U > ( other . upload ) ) <nl> { } <nl> <nl> T download ; <nl> T upload ; <nl> - } ; <nl> + } ; <nl> <nl> - template < typename T > <nl> - Sample < T > & operator + = ( Sample < T > & lhs , Sample < T > const & rhs ) { <nl> + template < typename T > <nl> + Sample < T > & operator + = ( Sample < T > & lhs , Sample < T > const & rhs ) { <nl> lhs . download + = rhs . download ; <nl> lhs . upload + = rhs . upload ; <nl> return lhs ; <nl> - } <nl> + } <nl> <nl> - template < typename T > <nl> - Sample < T > & operator - = ( Sample < T > & lhs , Sample < T > const & rhs ) { <nl> + template < typename T > <nl> + Sample < T > & operator - = ( Sample < T > & lhs , Sample < T > const & rhs ) { <nl> lhs . download - = rhs . download ; <nl> lhs . upload - = rhs . upload ; <nl> return lhs ; <nl> - } <nl> + } <nl> <nl> - template < typename T > <nl> - Sample < T > operator + ( Sample < T > const & lhs , Sample < T > const & rhs ) { <nl> + template < typename T > <nl> + Sample < T > operator + ( Sample < T > const & lhs , Sample < T > const & rhs ) { <nl> return Sample < T > ( lhs . download + rhs . download , lhs . upload + rhs . upload ) ; <nl> - } <nl> + } <nl> <nl> - template < typename T > <nl> - Sample < T > operator - ( Sample < T > const & lhs , Sample < T > const & rhs ) { <nl> + template < typename T > <nl> + Sample < T > operator - ( Sample < T > const & lhs , Sample < T > const & rhs ) { <nl> return Sample < T > ( lhs . download - rhs . download , lhs . upload - rhs . upload ) ; <nl> - } <nl> + } <nl> <nl> - template < typename T > <nl> - Sample < T > operator * ( Sample < T > const & lhs , T rhs ) { <nl> + template < typename T > <nl> + Sample < T > operator * ( Sample < T > const & lhs , T rhs ) { <nl> return Sample < T > ( lhs . download * rhs , lhs . upload * rhs ) ; <nl> - } <nl> + } <nl> <nl> - template < typename T > <nl> - Sample < T > operator * ( T lhs , Sample < T > const & rhs ) { <nl> + template < typename T > <nl> + Sample < T > operator * ( T lhs , Sample < T > const & rhs ) { <nl> return Sample < T > ( lhs * rhs . download , lhs * rhs . upload ) ; <nl> - } <nl> + } <nl> <nl> - template < typename T > <nl> - Sample < T > operator / ( Sample < T > const & lhs , T rhs ) { <nl> + template < typename T > <nl> + Sample < T > operator / ( Sample < T > const & lhs , T rhs ) { <nl> return Sample < T > ( lhs . download / rhs , lhs . upload / rhs ) ; <nl> - } <nl> + } <nl> } <nl> <nl> class SpeedSample { <nl> <nl> public : <nl> - SpeedSample ( ) { } <nl> - void addSample ( Sample < int > const & item ) ; <nl> - Sample < qreal > average ( ) const ; <nl> + SpeedSample ( ) { } <nl> + void addSample ( Sample < int > const & item ) ; <nl> + Sample < qreal > average ( ) const ; <nl> <nl> private : <nl> - static const int max_samples = 30 ; <nl> + static const int max_samples = 30 ; <nl> <nl> private : <nl> - QList < Sample < int > > m_speedSamples ; <nl> - Sample < long long > m_sum ; <nl> + QList < Sample < int > > m_speedSamples ; <nl> + Sample < long long > m_sum ; <nl> } ; <nl> <nl> TorrentSpeedMonitor : : TorrentSpeedMonitor ( QBtSession * session ) <nl> - : m_session ( session ) <nl> + : m_session ( session ) <nl> { <nl> - connect ( m_session , SIGNAL ( torrentAboutToBeRemoved ( QTorrentHandle ) ) , SLOT ( removeSamples ( QTorrentHandle ) ) ) ; <nl> - connect ( m_session , SIGNAL ( pausedTorrent ( QTorrentHandle ) ) , SLOT ( removeSamples ( QTorrentHandle ) ) ) ; <nl> - connect ( m_session , SIGNAL ( statsReceived ( libtorrent : : stats_alert ) ) , SLOT ( statsReceived ( libtorrent : : stats_alert ) ) ) ; <nl> + connect ( m_session , SIGNAL ( torrentAboutToBeRemoved ( QTorrentHandle ) ) , SLOT ( removeSamples ( QTorrentHandle ) ) ) ; <nl> + connect ( m_session , SIGNAL ( pausedTorrent ( QTorrentHandle ) ) , SLOT ( removeSamples ( QTorrentHandle ) ) ) ; <nl> + connect ( m_session , SIGNAL ( statsReceived ( libtorrent : : stats_alert ) ) , SLOT ( statsReceived ( libtorrent : : stats_alert ) ) ) ; <nl> } <nl> <nl> TorrentSpeedMonitor : : ~ TorrentSpeedMonitor ( ) <nl> TorrentSpeedMonitor : : ~ TorrentSpeedMonitor ( ) <nl> <nl> void SpeedSample : : addSample ( Sample < int > const & item ) <nl> { <nl> - m_speedSamples . push_back ( item ) ; <nl> - m_sum + = Sample < long long > ( item ) ; <nl> - if ( m_speedSamples . size ( ) > max_samples ) { <nl> - m_sum - = Sample < long long > ( m_speedSamples . front ( ) ) ; <nl> - m_speedSamples . pop_front ( ) ; <nl> - } <nl> + m_speedSamples . push_back ( item ) ; <nl> + m_sum + = Sample < long long > ( item ) ; <nl> + if ( m_speedSamples . size ( ) > max_samples ) { <nl> + m_sum - = Sample < long long > ( m_speedSamples . front ( ) ) ; <nl> + m_speedSamples . pop_front ( ) ; <nl> + } <nl> } <nl> <nl> Sample < qreal > SpeedSample : : average ( ) const <nl> { <nl> - if ( m_speedSamples . empty ( ) ) <nl> - return Sample < qreal > ( ) ; <nl> + if ( m_speedSamples . empty ( ) ) <nl> + return Sample < qreal > ( ) ; <nl> <nl> - return Sample < qreal > ( m_sum ) * ( qreal ( 1 . ) / m_speedSamples . size ( ) ) ; <nl> + return Sample < qreal > ( m_sum ) * ( qreal ( 1 . ) / m_speedSamples . size ( ) ) ; <nl> } <nl> <nl> void TorrentSpeedMonitor : : removeSamples ( const QTorrentHandle & h ) { <nl> - try { <nl> - m_samples . remove ( h . hash ( ) ) ; <nl> - } catch ( invalid_handle & ) { } <nl> + try { <nl> + m_samples . remove ( h . hash ( ) ) ; <nl> + } catch ( invalid_handle & ) { } <nl> } <nl> <nl> qlonglong TorrentSpeedMonitor : : getETA ( const QString & hash , const libtorrent : : torrent_status & status ) const <nl> { <nl> - if ( QTorrentHandle : : is_paused ( status ) ) <nl> - return MAX_ETA ; <nl> + if ( QTorrentHandle : : is_paused ( status ) ) <nl> + return MAX_ETA ; <nl> <nl> - QHash < QString , SpeedSample > : : const_iterator i = m_samples . find ( hash ) ; <nl> - if ( i = = m_samples . end ( ) ) <nl> - return MAX_ETA ; <nl> + QHash < QString , SpeedSample > : : const_iterator i = m_samples . find ( hash ) ; <nl> + if ( i = = m_samples . end ( ) ) <nl> + return MAX_ETA ; <nl> <nl> - const Sample < qreal > speed_average = i - > average ( ) ; <nl> + const Sample < qreal > speed_average = i - > average ( ) ; <nl> <nl> - if ( QTorrentHandle : : is_seed ( status ) ) { <nl> - if ( ! speed_average . upload ) <nl> - return MAX_ETA ; <nl> + if ( QTorrentHandle : : is_seed ( status ) ) { <nl> + if ( ! speed_average . upload ) <nl> + return MAX_ETA ; <nl> <nl> - bool _unused ; <nl> - qreal max_ratio = m_session - > getMaxRatioPerTorrent ( hash , & _unused ) ; <nl> - if ( max_ratio < 0 ) <nl> - return MAX_ETA ; <nl> + bool _unused ; <nl> + qreal max_ratio = m_session - > getMaxRatioPerTorrent ( hash , & _unused ) ; <nl> + if ( max_ratio < 0 ) <nl> + return MAX_ETA ; <nl> <nl> - libtorrent : : size_type realDL = status . all_time_download ; <nl> - if ( realDL < = 0 ) <nl> - realDL = status . total_wanted ; <nl> + libtorrent : : size_type realDL = status . all_time_download ; <nl> + if ( realDL < = 0 ) <nl> + realDL = status . total_wanted ; <nl> <nl> - return ( realDL * max_ratio - status . all_time_upload ) / speed_average . upload ; <nl> - } <nl> + return ( realDL * max_ratio - status . all_time_upload ) / speed_average . upload ; <nl> + } <nl> <nl> - if ( ! speed_average . download ) <nl> - return MAX_ETA ; <nl> + if ( ! speed_average . download ) <nl> + return MAX_ETA ; <nl> <nl> - return ( status . total_wanted - status . total_wanted_done ) / speed_average . download ; <nl> + return ( status . total_wanted - status . total_wanted_done ) / speed_average . download ; <nl> } <nl> <nl> void TorrentSpeedMonitor : : statsReceived ( const stats_alert & stats ) <nl> { <nl> - Q_ASSERT ( stats . interval > = 1000 ) ; <nl> + Q_ASSERT ( stats . interval > = 1000 ) ; <nl> <nl> - Sample < int > transferred ( stats . transferred [ stats_alert : : download_payload ] , <nl> - stats . transferred [ stats_alert : : upload_payload ] ) ; <nl> + Sample < int > transferred ( stats . transferred [ stats_alert : : download_payload ] , <nl> + stats . transferred [ stats_alert : : upload_payload ] ) ; <nl> <nl> - Sample < int > normalized = Sample < int > ( Sample < long long > ( transferred ) * 1000LL / static_cast < long long > ( stats . interval ) ) ; <nl> + Sample < int > normalized = Sample < int > ( Sample < long long > ( transferred ) * 1000LL / static_cast < long long > ( stats . interval ) ) ; <nl> <nl> - m_samples [ misc : : toQString ( stats . handle . info_hash ( ) ) ] . addSample ( normalized ) ; <nl> + m_samples [ misc : : toQString ( stats . handle . info_hash ( ) ) ] . addSample ( normalized ) ; <nl> } <nl> mmm a / src / core / qtlibtorrent / torrentspeedmonitor . h <nl> ppp b / src / core / qtlibtorrent / torrentspeedmonitor . h <nl> class SpeedSample ; <nl> <nl> class TorrentSpeedMonitor : public QObject <nl> { <nl> - Q_OBJECT <nl> - Q_DISABLE_COPY ( TorrentSpeedMonitor ) <nl> + Q_OBJECT <nl> + Q_DISABLE_COPY ( TorrentSpeedMonitor ) <nl> <nl> public : <nl> - explicit TorrentSpeedMonitor ( QBtSession * session ) ; <nl> - ~ TorrentSpeedMonitor ( ) ; <nl> - qlonglong getETA ( const QString & hash , const libtorrent : : torrent_status & status ) const ; <nl> + explicit TorrentSpeedMonitor ( QBtSession * session ) ; <nl> + ~ TorrentSpeedMonitor ( ) ; <nl> + qlonglong getETA ( const QString & hash , const libtorrent : : torrent_status & status ) const ; <nl> <nl> private slots : <nl> - void statsReceived ( const libtorrent : : stats_alert & stats ) ; <nl> - void removeSamples ( const QTorrentHandle & h ) ; <nl> + void statsReceived ( const libtorrent : : stats_alert & stats ) ; <nl> + void removeSamples ( const QTorrentHandle & h ) ; <nl> <nl> private : <nl> - QHash < QString , SpeedSample > m_samples ; <nl> - QBtSession * m_session ; <nl> + QHash < QString , SpeedSample > m_samples ; <nl> + QBtSession * m_session ; <nl> } ; <nl> <nl> # endif / / TORRENTSPEEDMONITOR_H <nl> mmm a / src / core / qtlibtorrent / torrentstatistics . cpp <nl> ppp b / src / core / qtlibtorrent / torrentstatistics . cpp <nl> <nl> # include " preferences . h " <nl> <nl> TorrentStatistics : : TorrentStatistics ( QBtSession * session , QObject * parent ) <nl> - : QObject ( parent ) <nl> - , m_session ( session ) <nl> - , m_sessionUL ( 0 ) <nl> - , m_sessionDL ( 0 ) <nl> - , m_lastWrite ( 0 ) <nl> - , m_dirty ( false ) <nl> + : QObject ( parent ) <nl> + , m_session ( session ) <nl> + , m_sessionUL ( 0 ) <nl> + , m_sessionDL ( 0 ) <nl> + , m_lastWrite ( 0 ) <nl> + , m_dirty ( false ) <nl> { <nl> - loadStats ( ) ; <nl> - connect ( & m_timer , SIGNAL ( timeout ( ) ) , this , SLOT ( gatherStats ( ) ) ) ; <nl> - m_timer . start ( 60 * 1000 ) ; <nl> + loadStats ( ) ; <nl> + connect ( & m_timer , SIGNAL ( timeout ( ) ) , this , SLOT ( gatherStats ( ) ) ) ; <nl> + m_timer . start ( 60 * 1000 ) ; <nl> } <nl> <nl> TorrentStatistics : : ~ TorrentStatistics ( ) { <nl> - if ( m_dirty ) <nl> - m_lastWrite = 0 ; <nl> - saveStats ( ) ; <nl> + if ( m_dirty ) <nl> + m_lastWrite = 0 ; <nl> + saveStats ( ) ; <nl> } <nl> <nl> quint64 TorrentStatistics : : getAlltimeDL ( ) const { <nl> - return m_alltimeDL + m_sessionDL ; <nl> + return m_alltimeDL + m_sessionDL ; <nl> } <nl> <nl> quint64 TorrentStatistics : : getAlltimeUL ( ) const { <nl> - return m_alltimeUL + m_sessionUL ; <nl> + return m_alltimeUL + m_sessionUL ; <nl> } <nl> <nl> void TorrentStatistics : : gatherStats ( ) { <nl> - libtorrent : : session_status ss = m_session - > getSessionStatus ( ) ; <nl> - if ( ss . total_download > m_sessionDL ) { <nl> - m_sessionDL = ss . total_download ; <nl> - m_dirty = true ; <nl> - } <nl> - if ( ss . total_upload > m_sessionUL ) { <nl> - m_sessionUL = ss . total_upload ; <nl> - m_dirty = true ; <nl> - } <nl> + libtorrent : : session_status ss = m_session - > getSessionStatus ( ) ; <nl> + if ( ss . total_download > m_sessionDL ) { <nl> + m_sessionDL = ss . total_download ; <nl> + m_dirty = true ; <nl> + } <nl> + if ( ss . total_upload > m_sessionUL ) { <nl> + m_sessionUL = ss . total_upload ; <nl> + m_dirty = true ; <nl> + } <nl> <nl> - saveStats ( ) ; <nl> + saveStats ( ) ; <nl> } <nl> <nl> void TorrentStatistics : : saveStats ( ) const { <nl> - if ( ! ( m_dirty & & ( QDateTime : : currentMSecsSinceEpoch ( ) - m_lastWrite > = 15 * 60 * 1000 ) ) ) <nl> - return ; <nl> - QIniSettings s ( " qBittorrent " , " qBittorrent - data " ) ; <nl> - QVariantHash v ; <nl> - v . insert ( " AlltimeDL " , m_alltimeDL + m_sessionDL ) ; <nl> - v . insert ( " AlltimeUL " , m_alltimeUL + m_sessionUL ) ; <nl> - s . setValue ( " Stats / AllStats " , v ) ; <nl> - m_dirty = false ; <nl> - m_lastWrite = QDateTime : : currentMSecsSinceEpoch ( ) ; <nl> + if ( ! ( m_dirty & & ( QDateTime : : currentMSecsSinceEpoch ( ) - m_lastWrite > = 15 * 60 * 1000 ) ) ) <nl> + return ; <nl> + QIniSettings s ( " qBittorrent " , " qBittorrent - data " ) ; <nl> + QVariantHash v ; <nl> + v . insert ( " AlltimeDL " , m_alltimeDL + m_sessionDL ) ; <nl> + v . insert ( " AlltimeUL " , m_alltimeUL + m_sessionUL ) ; <nl> + s . setValue ( " Stats / AllStats " , v ) ; <nl> + m_dirty = false ; <nl> + m_lastWrite = QDateTime : : currentMSecsSinceEpoch ( ) ; <nl> } <nl> <nl> void TorrentStatistics : : loadStats ( ) { <nl> - / / Temp code . Versions v3 . 1 . 4 and v3 . 1 . 5 saved the data in the qbittorrent . ini file . <nl> - / / This code reads the data from there , writes it to the new file , and removes the keys <nl> - / / from the old file . This code should be removed after some time has passed . <nl> - / / e . g . When we reach v3 . 3 . 0 <nl> - / / Don ' t forget to remove : <nl> - / / 1 . Preferences : : getStats ( ) <nl> - / / 2 . Preferences : : removeStats ( ) <nl> - / / 3 . # include " preferences . h " <nl> - Preferences * const pref = Preferences : : instance ( ) ; <nl> - QIniSettings s ( " qBittorrent " , " qBittorrent - data " ) ; <nl> - QVariantHash v = pref - > getStats ( ) ; <nl> + / / Temp code . Versions v3 . 1 . 4 and v3 . 1 . 5 saved the data in the qbittorrent . ini file . <nl> + / / This code reads the data from there , writes it to the new file , and removes the keys <nl> + / / from the old file . This code should be removed after some time has passed . <nl> + / / e . g . When we reach v3 . 3 . 0 <nl> + / / Don ' t forget to remove : <nl> + / / 1 . Preferences : : getStats ( ) <nl> + / / 2 . Preferences : : removeStats ( ) <nl> + / / 3 . # include " preferences . h " <nl> + Preferences * const pref = Preferences : : instance ( ) ; <nl> + QIniSettings s ( " qBittorrent " , " qBittorrent - data " ) ; <nl> + QVariantHash v = pref - > getStats ( ) ; <nl> <nl> - / / Let ' s test if the qbittorrent . ini holds the key <nl> - if ( ! v . isEmpty ( ) ) { <nl> - m_dirty = true ; <nl> + / / Let ' s test if the qbittorrent . ini holds the key <nl> + if ( ! v . isEmpty ( ) ) { <nl> + m_dirty = true ; <nl> <nl> - / / If the user has used qbt > 3 . 1 . 5 and then reinstalled / used <nl> - / / qbt < 3 . 1 . 6 , there will be stats in qbittorrent - data . ini too <nl> - / / so we need to merge those 2 . <nl> - if ( s . contains ( " Stats / AllStats " ) ) { <nl> - QVariantHash tmp = s . value ( " Stats / AllStats " ) . toHash ( ) ; <nl> - v [ " AlltimeDL " ] = v [ " AlltimeDL " ] . toULongLong ( ) + tmp [ " AlltimeDL " ] . toULongLong ( ) ; <nl> - v [ " AlltimeUL " ] = v [ " AlltimeUL " ] . toULongLong ( ) + tmp [ " AlltimeUL " ] . toULongLong ( ) ; <nl> + / / If the user has used qbt > 3 . 1 . 5 and then reinstalled / used <nl> + / / qbt < 3 . 1 . 6 , there will be stats in qbittorrent - data . ini too <nl> + / / so we need to merge those 2 . <nl> + if ( s . contains ( " Stats / AllStats " ) ) { <nl> + QVariantHash tmp = s . value ( " Stats / AllStats " ) . toHash ( ) ; <nl> + v [ " AlltimeDL " ] = v [ " AlltimeDL " ] . toULongLong ( ) + tmp [ " AlltimeDL " ] . toULongLong ( ) ; <nl> + v [ " AlltimeUL " ] = v [ " AlltimeUL " ] . toULongLong ( ) + tmp [ " AlltimeUL " ] . toULongLong ( ) ; <nl> + } <nl> } <nl> - } <nl> - else <nl> - v = s . value ( " Stats / AllStats " ) . toHash ( ) ; <nl> + else <nl> + v = s . value ( " Stats / AllStats " ) . toHash ( ) ; <nl> <nl> - m_alltimeDL = v [ " AlltimeDL " ] . toULongLong ( ) ; <nl> - m_alltimeUL = v [ " AlltimeUL " ] . toULongLong ( ) ; <nl> + m_alltimeDL = v [ " AlltimeDL " ] . toULongLong ( ) ; <nl> + m_alltimeUL = v [ " AlltimeUL " ] . toULongLong ( ) ; <nl> <nl> - if ( m_dirty ) { <nl> - saveStats ( ) ; <nl> - pref - > removeStats ( ) ; <nl> - } <nl> + if ( m_dirty ) { <nl> + saveStats ( ) ; <nl> + pref - > removeStats ( ) ; <nl> + } <nl> } <nl> mmm a / src / core / qtlibtorrent / torrentstatistics . h <nl> ppp b / src / core / qtlibtorrent / torrentstatistics . h <nl> class QBtSession ; <nl> <nl> class TorrentStatistics : QObject <nl> { <nl> - Q_OBJECT <nl> - Q_DISABLE_COPY ( TorrentStatistics ) <nl> + Q_OBJECT <nl> + Q_DISABLE_COPY ( TorrentStatistics ) <nl> <nl> public : <nl> - TorrentStatistics ( QBtSession * session , QObject * parent = 0 ) ; <nl> - ~ TorrentStatistics ( ) ; <nl> + TorrentStatistics ( QBtSession * session , QObject * parent = 0 ) ; <nl> + ~ TorrentStatistics ( ) ; <nl> <nl> - quint64 getAlltimeDL ( ) const ; <nl> - quint64 getAlltimeUL ( ) const ; <nl> + quint64 getAlltimeDL ( ) const ; <nl> + quint64 getAlltimeUL ( ) const ; <nl> <nl> private slots : <nl> - void gatherStats ( ) ; <nl> + void gatherStats ( ) ; <nl> <nl> private : <nl> - void saveStats ( ) const ; <nl> - void loadStats ( ) ; <nl> + void saveStats ( ) const ; <nl> + void loadStats ( ) ; <nl> <nl> private : <nl> - QBtSession * m_session ; <nl> - / / Will overflow at 15 . 9 EiB <nl> - quint64 m_alltimeUL ; <nl> - quint64 m_alltimeDL ; <nl> - qint64 m_sessionUL ; <nl> - qint64 m_sessionDL ; <nl> - mutable qint64 m_lastWrite ; <nl> - mutable bool m_dirty ; <nl> - <nl> - QTimer m_timer ; <nl> + QBtSession * m_session ; <nl> + / / Will overflow at 15 . 9 EiB <nl> + quint64 m_alltimeUL ; <nl> + quint64 m_alltimeDL ; <nl> + qint64 m_sessionUL ; <nl> + qint64 m_sessionDL ; <nl> + mutable qint64 m_lastWrite ; <nl> + mutable bool m_dirty ; <nl> + <nl> + QTimer m_timer ; <nl> } ; <nl> <nl> # endif / / TORRENTSTATISTICS_H <nl> mmm a / src / core / qtlibtorrent / trackerinfos . h <nl> ppp b / src / core / qtlibtorrent / trackerinfos . h <nl> <nl> <nl> class TrackerInfos { <nl> public : <nl> - QString name_or_url ; <nl> - QString last_message ; <nl> - unsigned long num_peers ; <nl> + QString name_or_url ; <nl> + QString last_message ; <nl> + unsigned long num_peers ; <nl> <nl> - / / TrackerInfos ( ) { } <nl> - TrackerInfos ( const TrackerInfos & b ) <nl> - : name_or_url ( b . name_or_url ) <nl> - , last_message ( b . last_message ) <nl> - , num_peers ( b . num_peers ) <nl> - { <nl> - Q_ASSERT ( ! name_or_url . isEmpty ( ) ) ; <nl> - } <nl> + / / TrackerInfos ( ) { } <nl> + TrackerInfos ( const TrackerInfos & b ) <nl> + : name_or_url ( b . name_or_url ) <nl> + , last_message ( b . last_message ) <nl> + , num_peers ( b . num_peers ) <nl> + { <nl> + Q_ASSERT ( ! name_or_url . isEmpty ( ) ) ; <nl> + } <nl> <nl> - TrackerInfos ( QString name_or_url ) <nl> - : name_or_url ( name_or_url ) <nl> - , last_message ( " " ) <nl> - , num_peers ( 0 ) <nl> - { <nl> - } <nl> + TrackerInfos ( QString name_or_url ) <nl> + : name_or_url ( name_or_url ) <nl> + , last_message ( " " ) <nl> + , num_peers ( 0 ) <nl> + { <nl> + } <nl> } ; <nl> <nl> # endif / / TRACKERINFOS_H <nl>
|
Merge pull request from glassez / indent_size
|
qbittorrent/qBittorrent
|
42b9e3d2c4198ebec4d6b5887ddc53070018961b
|
2015-02-25T14:23:39Z
|
mmm a / tensorflow / compiler / mlir / lite / ir / tfl_ops . cc <nl> ppp b / tensorflow / compiler / mlir / lite / ir / tfl_ops . cc <nl> struct WhileResultOperandsMatchAndImplicitCapture <nl> <nl> LogicalResult matchAndRewrite ( WhileOp while_op , <nl> PatternRewriter & rewriter ) const override { <nl> - / / Replace values simply passed through the body with extern values . The <nl> + / / Replace values simply passed through the body with extern values <nl> + / / ( in both body and condition regions as well as while result ) . The <nl> / / block arguments of body and while match and so the corresponding cond <nl> / / argument can be easily found . <nl> bool unchanged = true ; <nl> struct WhileResultOperandsMatchAndImplicitCapture <nl> auto & cond_block = while_op . cond ( ) . front ( ) ; <nl> auto & yield = * body_block . getTerminator ( ) ; <nl> for ( auto ba : body_block . getArguments ( ) ) { <nl> - if ( ba = = yield . getOperand ( ba . getArgNumber ( ) ) ) { <nl> + int arg_no = ba . getArgNumber ( ) ; <nl> + if ( ba = = yield . getOperand ( arg_no ) ) { <nl> unchanged = false ; <nl> - auto value = while_op . getOperand ( ba . getArgNumber ( ) ) ; <nl> + auto value = while_op . getOperand ( arg_no ) ; <nl> ba . replaceAllUsesWith ( value ) ; <nl> - cond_block . getArgument ( ba . getArgNumber ( ) ) . replaceAllUsesWith ( value ) ; <nl> + cond_block . getArgument ( arg_no ) . replaceAllUsesWith ( value ) ; <nl> + <nl> + / / This could be relaxed and casts inserted . <nl> + if ( while_op . getResult ( arg_no ) . getType ( ) = = value . getType ( ) ) <nl> + while_op . getResult ( arg_no ) . replaceAllUsesWith ( value ) ; <nl> } <nl> } <nl> <nl> / / The While ops operands and result types need to match <nl> SmallVector < Value , 4 > new_operands ; <nl> SmallVector < Value , 4 > new_body_yield ; <nl> - SmallVector < bool , 4 > const_operand ( while_op . getNumOperands ( ) , false ) ; <nl> + SmallVector < bool , 4 > removed_operand ( while_op . getNumOperands ( ) , false ) ; <nl> llvm : : SmallVector < Type , 4 > types ; <nl> new_operands . reserve ( while_op . getNumOperands ( ) ) ; <nl> new_body_yield . reserve ( while_op . getNumOperands ( ) ) ; <nl> struct WhileResultOperandsMatchAndImplicitCapture <nl> auto value = while_op . getOperand ( while_index ) ; <nl> if ( body_block . getArgument ( arg_index ) . use_empty ( ) & & <nl> cond_block . getArgument ( arg_index ) . use_empty ( ) & & <nl> - / / This could be relaxed and casts inserted . <nl> - while_op . getResult ( while_index ) . getType ( ) = = value . getType ( ) ) { <nl> + / / Note : since we are not erasing results , need to use while_index <nl> + / / to check if the corresponding result is unused . <nl> + while_op . getResult ( while_index ) . use_empty ( ) ) { <nl> unchanged = false ; <nl> body_block . eraseArgument ( arg_index ) ; <nl> cond_block . eraseArgument ( arg_index ) ; <nl> <nl> - / / Mark operand as constant and replace all uses with input to while . <nl> - while_op . getResult ( while_index ) . replaceAllUsesWith ( value ) ; <nl> - const_operand [ while_index ] = true ; <nl> + / / Mark operand for removal . <nl> + removed_operand [ while_index ] = true ; <nl> } else { <nl> new_operands . push_back ( value ) ; <nl> new_body_yield . push_back ( yield . getOperand ( while_index ) ) ; <nl> struct WhileResultOperandsMatchAndImplicitCapture <nl> for ( int i = 0 ; i < 2 ; + + i ) new_op - > getRegion ( i ) . takeBody ( op - > getRegion ( i ) ) ; <nl> int new_index = 0 ; <nl> for ( int op_index = 0 , e = op - > getNumResults ( ) ; op_index < e ; + + op_index ) { <nl> - if ( const_operand [ op_index ] ) continue ; <nl> + if ( removed_operand [ op_index ] ) continue ; <nl> op - > getResult ( op_index ) . replaceAllUsesWith ( new_op - > getResult ( new_index ) ) ; <nl> + + new_index ; <nl> } <nl> mmm a / tensorflow / compiler / mlir / lite / tests / canonicalize . mlir <nl> ppp b / tensorflow / compiler / mlir / lite / tests / canonicalize . mlir <nl> func @ Int64SliceBeginSize ( % arg0 : tensor < 4x128x32xf32 > ) - > tensor < 1x128x32xf32 > { <nl> / / CHECK : [ [ VAL_2 : % . * ] ] = constant dense < [ 1 , 128 , 32 ] > : tensor < 3xi32 > <nl> / / CHECK : [ [ VAL_3 : % . * ] ] = " tfl . slice " ( % arg0 , [ [ VAL_1 ] ] , [ [ VAL_2 ] ] ) : ( tensor < 4x128x32xf32 > , tensor < 3xi32 > , tensor < 3xi32 > ) - > tensor < 1x128x32xf32 > <nl> } <nl> + <nl> + / / mmm - - <nl> + <nl> + / / CHECK - LABEL : @ WhileCanonicalizeBug <nl> + / / Make sure that second output of the tf . while is not incorrectly inferred as <nl> + / / pass through just because the corresponding input is not used in either <nl> + / / condition or body . The tensor < f32 > result of the loop can be either % arg1 <nl> + / / ( if the body never executes , or 22 . 0 if the body executes atleast once ) . <nl> + func @ WhileCanonicalizeBug ( % arg0 : tensor < i32 > , % arg1 : tensor < f32 > ) - > tensor < f32 > { <nl> + % 0 : 2 = " tfl . while " ( % arg0 , % arg1 ) ( { <nl> + ^ bb0 ( % arg2 : tensor < i32 > , % arg3 : tensor < f32 > ) : <nl> + % limit = constant dense < 100 > : tensor < i32 > <nl> + % test = " tfl . less " ( % arg0 , % limit ) : ( tensor < i32 > , tensor < i32 > ) - > tensor < i1 > <nl> + " tfl . yield " ( % test ) : ( tensor < i1 > ) - > ( ) <nl> + } , { <nl> + ^ bb0 ( % arg2 : tensor < i32 > , % arg3 : tensor < f32 > ) : <nl> + % cst = constant dense < 22 . 0 > : tensor < f32 > <nl> + % stride = constant dense < 1 > : tensor < i32 > <nl> + % inc = tfl . add % arg2 , % stride { fused_activation_function = " NONE " } : tensor < i32 > <nl> + " tfl . yield " ( % inc , % cst ) : ( tensor < i32 > , tensor < f32 > ) - > ( ) <nl> + } ) : ( tensor < i32 > , tensor < f32 > ) - > ( tensor < i32 > , tensor < f32 > ) <nl> + / / CHECK : return % 0 # 1 : tensor < f32 > <nl> + return % 0 # 1 : tensor < f32 > <nl> + } <nl> + <nl> + / / mmm - - <nl> + <nl> + / / Test case to test bug due to checking <nl> + / / ` while_op . getResult ( arg_index ) . use_empty ( ) ` instead of <nl> + / / ` while_op . getResult ( while_index ) . use_empty ( ) ` in the tfl . while <nl> + / / canonicalization . <nl> + / / arg0 is a pass through . After first iteration , arg_index = 0 <nl> + / / and while_index = 1 . Make arg1 use empty in block and condition , but not in <nl> + / / result . Canonicalize will think it can remove both slot # 0 and slot # 1 and do <nl> + / / so without replacing all operands , and in assert builds it will fail an <nl> + / / assert failure ( op - > use_empty ( ) & & " expected ' op ' to have no uses " ) <nl> + / / CHECK - LABEL : WhileCanonicalizeBug1 <nl> + func @ WhileCanonicalizeBug1 ( % arg0 : tensor < f32 > , % arg1 : tensor < f32 > ) - > tensor < f32 > { <nl> + % 0 : 2 = " tfl . while " ( % arg0 , % arg1 ) ( { <nl> + ^ bb0 ( % carg0 : tensor < f32 > , % carg1 : tensor < f32 > ) : <nl> + % limit = constant dense < 100 > : tensor < i32 > <nl> + % test = " tfl . less " ( % limit , % limit ) : ( tensor < i32 > , tensor < i32 > ) - > tensor < i1 > <nl> + " tfl . yield " ( % test ) : ( tensor < i1 > ) - > ( ) <nl> + } , { <nl> + ^ bb0 ( % barg0 : tensor < f32 > , % barg1 : tensor < f32 > ) : <nl> + % cst = constant dense < 22 . 0 > : tensor < f32 > <nl> + " tfl . yield " ( % barg0 , % cst ) : ( tensor < f32 > , tensor < f32 > ) - > ( ) <nl> + } ) : ( tensor < f32 > , tensor < f32 > ) - > ( tensor < f32 > , tensor < f32 > ) <nl> + return % 0 # 1 : tensor < f32 > <nl> + } <nl>
|
[ MLIR ] Fix incorrect tfl . while canonicalization
|
tensorflow/tensorflow
|
d69c8e8c9c570202641c18eeab366ce72826f296
|
2020-07-06T16:26:30Z
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.