Skip to content

[abandon] gtk3の実験的サポート テスト版-3 #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 67 commits into from

Conversation

ma8ma
Copy link
Owner

@ma8ma ma8ma commented Dec 9, 2018

このPRは破棄されました。代わりに #13 を見てください。

ma8ma and others added 30 commits November 20, 2018 22:03
…6.0)

* ARTICLE::ArticleViewBase::slot_on_url
* DBTREE::BoardBase::download_subject
* DBTREE::BoardBase::search_cache
* SKELETON::View::is_loading
Fix access violation in DBTREE::NodeTreeBase::receive_data()
The return type of Gtk::FileChooserDialog::get_filenames() becomes
std::vector<std::string> instead of Glib::SListHandle<...> since gtk3.
Gtk::HBox::children() is removed since gtk3.
Gtk::MenuHelpers::MenuList is removed since gtk3.
LLVMスタイルを元にJDスタイルを再現する
表記ゆれのある部分はJDのコードを調べて多数の方を採用する
曖昧な部分はLLVMスタイルを踏襲する

JDスタイルから変更した部分

* 単独のジャンプ文(continue, break, goto, return, throw)を除き
  if-else文のブロックに波括弧を付ける
  ```cpp
  // YES
  if( expr ) return 1;
  if( long_long_expr1 && long_long_expr2 )
      return long_long_func( long_long_value );
  if( expr ) {
      var = 20;
  }

  // NO
  if( expr ) var = 20;
  if( expr )
      var = 20;
  ```

* 空の文(;)を除きループ文のブロックに波括弧を付ける
  ```cpp
  // YES
  while( expr )
      ;
  while( expr ) {
      var += 1;
  }

  // NO
  while( expr );
  while( expr ) var += 1;
  while( expr )
      var += 1;
  ```

ツールで再現できていないスタイル

* マクロGTKMM_CHECK_VERSION()の引数
  -> スペースを取り除いてJDスタイルに準ずる
  ```cpp
  // YES
  #if GTKMM_CHECK_VERSION(2,10,0)
  #endif

  // NO (clang-format)
  #if GTKMM_CHECK_VERSION( 2, 10, 0 )
  #endif
  ```

* 制御構文の条件式の閉じ括弧とブロックの開き波括弧の間
  -> ツールで整形したままでよい
  ```cpp
  // OK (clang-format)
  if( expr ) {
  }

  // (JD style)
  if( expr ){
  }
  ```

* 否定演算子の後
  -> ツールで整形したままでよい
  ```cpp
  // OK (clang-format)
  func( !expr );

  // (JD style)
  func( ! expr );
  ```

* for文の条件式の初期化パートが空のとき
  -> ツールで整形したままでよい
  ```cpp
  // OK (clang-format)
  for( ; expr1; expr2 ) {
  }

  // (JD style)
  for(; expr1; expr2 ){
  }
  ```
バージョン番号とgitリビジョンについて説明をjdversion.hに追加する
コンパイラの拡張機能を禁止し標準に準拠する。

./configureの引数に与えられたCXXFLAGSをJDのフラグより後ろに展開する。
clangは後ろのフラグを優先するため前で展開すると上書きできない場合がある。
仮想関数にはvirtual, override, finalのうち適切な一つを指定する。
例外を投げないデストラクタにnoexceptを指定する。
* -Wextraで有効になる-Wunused-parameterは修正方法が複数あり
  検討が必要なので暫定的に無効にする
* Fix warning for 'const' type qualifier on return type has no effect
* Fix compile warning for missing field unused initializer
C++11では属性[[fallthrough]]が使えないのでGCC 7が認識するコメント[1]
// fallthrough
を代わりに記述し警告を抑制する

[1] https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wimplicit-fallthrough_003d
gtkmm-2.4の代わりにgtkmm-3.0を使ってビルドするconfigureフラグを追加する
gtkmm-3.0のバージョンは3.18以上を推奨
ma8ma added 21 commits December 8, 2018 23:12
* Use Gtk::Widget::override_font() instead of modify_font()
* Use Gtk::StyleContext to get label font instead of Gtk::Style
* Use Gtk::StyleContext to get entry font instead of Gtk::Style
* Use Gtk::Widget::override_color() instead of modify_fg()
* Use Gtk::Widget::override_color() instead of modify_text()
* Use Gtk::Widget::override_background_color() instead of modify_bg()
* Use Gtk::Widget::override_background_color() instead of modify_base()
* Use Gtk::Widget::unset_color() instead of unset_fg()
* Use Gtk::StyleContext to get entry color instead of Gtk::Style
* Use Gtk::StyleContext to get bg color instead of Gtk::Style

ウィジェットの配色ではなくGTKテーマの設定から色を取得するように
変更した箇所がある
* Use Gtk::Widget::set_margin_xxx() instead of Gtk::(Rc)Style::set_(x|y)thickness()
* Use Gtk::Widget::get_margin_xxx() instead of Gtk::(Rc)Style::get_(x|y)thickness()
DragableNoteBookの主なロジックのうち以下をgtk3でも動くように変更する

* タブの描画は、自前で描画するのをやめてデフォルトのハンドラを使う

* タブ幅の計算は、タブの代わりにラベルの領域を使う

既知の問題
* DnDでタブを並べ替えるときに表示する目標の矢印はタブの境界からずれる

* DnDのドロップ範囲がタブの領域より狭くなっている

* タブの上でマウスホイールするとページが切り替わる機能は
  先頭<->最後尾の場合を除いて機能しない

* ラベルの領域からシグナルを拾うのでタブの端付近では
  ドラッグを開始できない

既存のロジックは実装の詳細をgtkのソースコードから引用して使うことで
タブの領域を取得する。gtk3ではデータ構造の変更[1]により今までの方法が
できなくなった。

[1]: gtk 3.20から_GtkNotebookPageは割り当てられた領域(GtkAllocation)
を持たなくなった。
https://gitlab.gnome.org/GNOME/gtk/blob/gtk-2-24/gtk/gtknotebook.c#L148
https://gitlab.gnome.org/GNOME/gtk/blob/gtk-3-24/gtk/gtknotebook.c#L293
タブDnDの目標矢印が境界からずれる&ドロップ範囲がタブの領域より
狭くなっている不具合を低減する。GTKテーマによってはドロップ先を示す
矢印の描画に問題が発生する可能性がある。

XXX: この修正はラベルの左右の余白の大きさが同じであることを前提とする
* Omit DragableNoteBook::draw_box() and get_alloc_notebook().

* Omit custom draw for DragableNoteBook, TabNotebook TabSwitchButton,
  ToolBarNotebook and ViewNotebook.

枠の描画や座標取得のメソッドを省略しDragableNoteBookの描画処理は
自前でやらない

変更の理由
描画処理に必要な座標はgtkのソースコードを引用して実装の詳細に
アクセスして取得している。gtk3ではデータ構造が変更された影響で
今までのコードが使えなくなった。
gtk3ではツールバーのカスタム描画をしない。
gtk2のJDToolbarの描画処理はgtkのソースコードを引用することで
実装の詳細にアクセスして行っている。gtk3ではデータ構造が
変更された影響で今までのコードが使えなくなった。

さらにGTKテーマによってはツールバーの子ウィジェットの配色がテーマに
従わないことがある。ツールバーからcssクラスGTK_STYLE_CLASS_TOOLBARを
削除することで配色を修正する。
style-changed signal is removed since gtk3.
スタイルを反映するシグナルハンドラを省略する
GTK3版ではGtkNotebook in GtkNotebookの背景色は問題がないように見える
gtk3 removes many implementation details and struct members from
public headers.
ハックによる枠の描画は省略する
GTK+ 3.9.2からGTK/GDKのダブルバッファ処理が再構成された [1]
この影響でスレビューのスクロール時に画面のちらつきが発生するようになった
ちらつきを抑えるため3.9.2以降の環境ではデフォルトのダブルバッファを使う

[1]: https://gitlab.gnome.org/GNOME/gtk/commit/d22fd7223c75f4720ddb982c659efb0d8d7543c4
デフォルトの設定ではウインドウの幅が狭いとエントリーが表示されない
gtk3では伸縮するウィジェットを持つダイアログを表示したときに
ウインドウのサイズが小さい場合があるためデフォルトのサイズを
設定するための機能を追加する
Gtk::POLICY_NEVERを設定するとスクロール機能自体がなくなり
コンテンツに合わせてGtk::ScrolledWindowのサイズが拡大してしまう
gtk3はマウスホイールによるGtkNotebookのタブの切り替えが
動作しなくなったのでシグナルハンドラを使って再現する

未修正の問題
この修正に関係なくホイールが全く反応しない環境がある(>= gtk 3.20?)
が厳密な条件は分からない
gtk3 removes many implementation details and struct members from
public headers.

XXX: フラット表示は装飾がない前提でcssが設定されている

* Fix compile error for debug log.  Thanks to @ooinu.
overrideメソッドの代わりにcssの設定で書き込みビューの配色を設定する
また、書き込みビューの配色にGTKテーマを使う設定を合わせて追加する
overrideメソッドでは配色の変更が上手くいかない環境があるので
cssを使って変更する。
ステータスバーのテキスト部分が上手く配色されないGTKテーマがあるので
明示的に設定する
GTK3サポートを追加する(テスト版)

jd-2.92.1-beta20181201 からの変更点

* リベースしてtestブランチを更新する(37181f0)
* overrideキーワードを使って仮想関数の上書きを明示する
* 警告オプション-Wextraを追加(ただし-Wunused-parameterは暫定的に無効)
* テスト版の修正
@ma8ma ma8ma closed this Dec 9, 2018
@ma8ma ma8ma reopened this Dec 9, 2018
@ma8ma
Copy link
Owner Author

ma8ma commented Dec 9, 2018

gtk3-previewを更新したので開き直します。

@ma8ma ma8ma closed this Dec 9, 2018
@ma8ma ma8ma changed the title [BETA] gtk3の実験的サポート テスト版-3 [abandon] gtk3の実験的サポート テスト版-3 Dec 9, 2018
@ma8ma ma8ma deleted the gtk3-beta-3 branch December 22, 2018 01:05
ma8ma pushed a commit that referenced this pull request Jan 27, 2019
ma8ma added a commit that referenced this pull request Mar 19, 2023
開発者向けテスト版の更新(スナップショット)

NOTE: 互換性をしっかりとチェックしていないためテスト用の
キャッシュディレクトリを用意することを推奨。

master(82a564b)からの主な変更点
- DAT/HTMLパーサーの機能を強化
- リファクタリング
- テストケースを追加

---
FIXME: ChunkedDecoder: heap-buffer-overflow

`ChunkedDecoder`のデコード処理で特定の条件のときバッファーオーバーフロー
が発生しました。以下の2条件を満たすときバッファの末尾にヌル文字を
書き込もうとしたときバッファの境界を越えるアクセスが起きます。

* 入力の長さと用意したバッファの長さが等しい
* デコード結果の長さと入力の長さが等しい

ASan report
```
==182784==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61d0014e0480 at pc 0x564e775c611b bp 0x7f763bcc0f00 sp 0x7f763bcc0ef0
WRITE of size 1 at 0x61d0014e0480 thread T48
    #0 0x564e775c611a in JDLIB::ChunkedDecoder::decode(char*, unsigned long&) ../src/jdlib/loader.cpp:351
    #1 0x564e775d6748 in JDLIB::Loader::run_main() ../src/jdlib/loader.cpp:949
    #2 0x564e775f5e9c in void std::__invoke_impl<void, void (JDLIB::Loader::*)(), JDLIB::Loader*>(std::__invoke_memfun_deref, void (JDLIB::Loader::*&&)(), JDLIB::Loader*&&) /usr/include/c++/12/bits/invoke.h:74
    #3 0x564e775f5a4c in std::__invoke_result<void (JDLIB::Loader::*)(), JDLIB::Loader*>::type std::__invoke<void (JDLIB::Loader::*)(), JDLIB::Loader*>(void (JDLIB::Loader::*&&)(), JDLIB::Loader*&&) /usr/include/c++/12/bits/invoke.h:96
    #4 0x564e775f57b9 in void std::thread::_Invoker<std::tuple<void (JDLIB::Loader::*)(), JDLIB::Loader*> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) /usr/include/c++/12/bits/std_thread.h:252
    #5 0x564e775f5607 in std::thread::_Invoker<std::tuple<void (JDLIB::Loader::*)(), JDLIB::Loader*> >::operator()() /usr/include/c++/12/bits/std_thread.h:259
    #6 0x564e775f53f9 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (JDLIB::Loader::*)(), JDLIB::Loader*> > >::_M_run() /usr/include/c++/12/bits/std_thread.h:210
    #7 0x7f76586dc3a2  (/lib/x86_64-linux-gnu/libstdc++.so.6+0xdc3a2)
    #8 0x7f7657a90401 in start_thread nptl/pthread_create.c:442
    #9 0x7f7657b1f58f in clone3 ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

0x61d0014e0480 is located 0 bytes to the right of 2048-byte region [0x61d0014dfc80,0x61d0014e0480)
allocated by thread T48 here:
    #0 0x7f765a4c0488 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:95
    #1 0x564e76c068ca in std::__new_allocator<char>::allocate(unsigned long, void const*) /usr/include/c++/12/bits/new_allocator.h:137
    #2 0x564e76c04f6e in std::allocator_traits<std::allocator<char> >::allocate(std::allocator<char>&, unsigned long) /usr/include/c++/12/bits/alloc_traits.h:464
    #3 0x564e76c02ab9 in std::_Vector_base<char, std::allocator<char> >::_M_allocate(unsigned long) /usr/include/c++/12/bits/stl_vector.h:378
    #4 0x564e76c00813 in std::vector<char, std::allocator<char> >::_M_default_append(unsigned long) /usr/include/c++/12/bits/vector.tcc:650
    #5 0x564e76bfee6b in std::vector<char, std::allocator<char> >::resize(unsigned long) /usr/include/c++/12/bits/stl_vector.h:1011
    #6 0x564e775d3583 in JDLIB::Loader::run_main() ../src/jdlib/loader.cpp:798
    #7 0x564e775f5e9c in void std::__invoke_impl<void, void (JDLIB::Loader::*)(), JDLIB::Loader*>(std::__invoke_memfun_deref, void (JDLIB::Loader::*&&)(), JDLIB::Loader*&&) /usr/include/c++/12/bits/invoke.h:74
    #8 0x564e775f5a4c in std::__invoke_result<void (JDLIB::Loader::*)(), JDLIB::Loader*>::type std::__invoke<void (JDLIB::Loader::*)(), JDLIB::Loader*>(void (JDLIB::Loader::*&&)(), JDLIB::Loader*&&) /usr/include/c++/12/bits/invoke.h:96
    #9 0x564e775f57b9 in void std::thread::_Invoker<std::tuple<void (JDLIB::Loader::*)(), JDLIB::Loader*> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) /usr/include/c++/12/bits/std_thread.h:252
    #10 0x564e775f5607 in std::thread::_Invoker<std::tuple<void (JDLIB::Loader::*)(), JDLIB::Loader*> >::operator()() /usr/include/c++/12/bits/std_thread.h:259
    #11 0x564e775f53f9 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (JDLIB::Loader::*)(), JDLIB::Loader*> > >::_M_run() /usr/include/c++/12/bits/std_thread.h:210
    #12 0x7f76586dc3a2  (/lib/x86_64-linux-gnu/libstdc++.so.6+0xdc3a2)

Thread T48 created by T0 here:
    #0 0x7f765a44af75 in __interceptor_pthread_create ../../../../src/libsanitizer/asan/asan_interceptors.cpp:207
    #1 0x7f76586dc478 in std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) (/lib/x86_64-linux-gnu/libstdc++.so.6+0xdc478)
    #2 0x564e775d1f1d in JDLIB::Loader::create_thread() ../src/jdlib/loader.cpp:745
    #3 0x564e775d18cf in JDLIB::Loader::run(SKELETON::Loadable*, JDLIB::LOADERDATA const&) ../src/jdlib/loader.cpp:724
    #4 0x564e778f53e1 in SKELETON::Loadable::start_load(JDLIB::LOADERDATA const&) ../src/skeleton/loadable.cpp:123
    #5 0x564e7724c305 in DBTREE::BoardBase::download_subject(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) ../src/dbtree/boardbase.cpp:1030
    #6 0x564e772bf21b in DBTREE::board_download_subject(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ../src/dbtree/interface.cpp:422
    #7 0x564e76ddd485 in BOARD::BoardViewBase::show_view() ../src/board/boardviewbase.cpp:1294
    #8 0x564e76d9469a in BOARD::BoardView::show_view() ../src/board/boardview.cpp:115
    #9 0x564e76d94040 in BOARD::BoardView::reload() ../src/board/boardview.cpp:102
    #10 0x564e76de86f9 in BOARD::BoardViewBase::operate_view(int) ../src/board/boardviewbase.cpp:1552
    #11 0x564e76dfef89 in BOARD::BoardViewBase::slot_key_press(_GdkEventKey*) ../src/board/boardviewbase.cpp:2227
    #12 0x564e76e3f089 in sigc::bound_mem_functor1<bool, BOARD::BoardViewBase, _GdkEventKey*>::operator()(_GdkEventKey* const&) const /usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:2066
    #13 0x564e76e39650 in sigc::adaptor_functor<sigc::bound_mem_functor1<bool, BOARD::BoardViewBase, _GdkEventKey*> >::deduce_result_type<_GdkEventKey* const&, void, void, void, void, void, void>::type sigc::adaptor_functor<sigc::bound_mem_functor1<bool, BOARD::BoardViewBase, _GdkEventKey*> >::operator()<_GdkEventKey* const&>(_GdkEventKey* const&) const /usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:89
    #14 0x564e76e3464f in sigc::internal::slot_call<sigc::bound_mem_functor1<bool, BOARD::BoardViewBase, _GdkEventKey*>, bool, _GdkEventKey*>::call_it(sigc::internal::slot_rep*, _GdkEventKey* const&) /usr/include/sigc++-2.0/sigc++/functors/slot.h:451
    #15 0x564e76b74962 in sigc::internal::signal_emit1<bool, _GdkEventKey*, sigc::nil>::emit(sigc::internal::signal_impl*, _GdkEventKey* const&) /usr/include/sigc++-2.0/sigc++/signal.h:952
    #16 0x564e76b65d3d in sigc::signal1<bool, _GdkEventKey*, sigc::nil>::emit(_GdkEventKey* const&) const /usr/include/sigc++-2.0/sigc++/signal.h:2955
    #17 0x564e77a1eba4 in SKELETON::JDTreeViewBase::on_key_press_event(_GdkEventKey*) ../src/skeleton/treeviewbase.cpp:387
    #18 0x564e77849a46 in SKELETON::DragTreeView::on_key_press_event(_GdkEventKey*) ../src/skeleton/dragtreeview.cpp:431
    #19 0x7f765a10a317 in Gtk::Widget_Class::key_press_event_callback(_GtkWidget*, _GdkEventKey*) (/lib/x86_64-linux-gnu/libgtkmm-3.0.so.1+0x30a317)

SUMMARY: AddressSanitizer: heap-buffer-overflow ../src/jdlib/loader.cpp:351 in JDLIB::ChunkedDecoder::decode(char*, unsigned long&)
Shadow bytes around the buggy address:
  0x0c3a80294040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3a80294050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3a80294060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3a80294070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3a80294080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c3a80294090:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3a802940a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3a802940b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3a802940c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3a802940d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3a802940e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==182784==ABORTING
```
ma8ma added a commit that referenced this pull request Jul 16, 2023
スレッド読み込み中に異常終了したため`std::string_view`の部分文字列
を取得する処理を修正します。

gdbのバックトレース
```
\#10 0x0000555555c32acf in std::__sv_check(unsigned long, unsigned long, char const*)
    (__size=243, __pos=244, __s=0x55555598ca42 "basic_string_view::substr") at /usr/include/c++/12/string_view:67
\#11 0x0000555555c32fa2 in std::basic_string_view<char, std::char_traits<char> >::substr(unsigned long, unsigned long) const
    (this=0x7fffe97fe210, __pos=244, __n=18446744073709551615) at /usr/include/c++/12/string_view:311
\#12 0x0000555555c7d072 in DBTREE::NodeTreeBase::parse_date_id(DBTREE::NODE*, std::basic_string_view<char, std::char_traits<char> >)
(gdb) frame 12
\#12 0x0000555555c7d072 in DBTREE::NodeTreeBase::parse_date_id (this=0x5555577c19f0, header=0x555558e6bbe8,
2019                str = str.substr( start_block + lng_block );
(gdb) p str.size()
$3 = 243
(gdb) p start_block + lng_block
$4 = 244
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants