Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
php7_swfed
Search
yoya
November 22, 2015
Programming
4.5k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
php7_swfed
SWFEditor の PHP7対応
yoya
November 22, 2015
More Decks by yoya
See All by yoya
resize_nitpick
yoya
1
180
ImageFluxBinary
yoya
2
3k
HEIF-kaisetsu
yoya
4
3.6k
go-thumber-imagick
yoya
1
210
chokaizomae
yoya
2
610
wildimagebinary
yoya
1
230
goimagicksyokai
yoya
2
1.2k
GoImagickThumbnail
yoya
0
1.7k
sushigazou
yoya
0
12k
Other Decks in Programming
See All in Programming
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.5k
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
210
Oxcを導入して開発体験が向上した話
yug1224
4
330
スマートグラスで並列バイブコーディング
hyshu
0
260
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
170
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
610
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
300
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
300
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.3k
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
800
Vite+ Unified Toolchain for the Web
naokihaba
0
340
RTSPクライアントを自作してみた話
simotin13
0
630
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
100
6.2k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
200
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
The SEO Collaboration Effect
kristinabergwall1
1
490
Tell your own story through comics
letsgokoyo
1
960
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
1.1k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
370
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
140
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
190
A Tale of Four Properties
chriscoyier
163
24k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
200
Making the Leap to Tech Lead
cromwellryan
135
9.9k
Transcript
SWFEditor の PHP7対応 2015/11/22 “よや”
[email protected]
自己紹介 • id:yoya • すっかり旬の終わった元 Flash のバイナリ屋さん です
– 会社でやる事ないので辞めて実質無職 • 今でも要望を頂くのでメンテしてます – 中国や東南アジアのとある界隈で流行りっぽい – ノセられてるっぽいけど、開発を続けるモチベーショ ンにはなるので嬉しい
SWFEditor について • 昔流行った Flash の動的バイナリ改変で、 ming 使うの面倒だったので作った PHP拡張
– hBps://osdn.jp/projects/swfed/
SWFEditor のサンプル • Flash 内画像入れ替え • 詳しくはこちら
– hBp://www.slideshare.net/yoyayoya1/phpswf $swfdata = fil_get_contents(“foo.swf”); $jpegdata = file_get_contents(“baa.jpg”); $swf = new SWFEditor(); $swf-‐>input($swfdata); $swf-‐>replaceJpegData($image_id, $jpegdata); echo $swf-‐>output();
PHP7 化 • この辺りを読んで覚悟を決める – hBps://wiki.php.net/phpng-‐upgrading – hBp://qiita.com/hnw/items/ d615e0d4122f247d4c75
– hBps://github.com/pasindud/sing-‐php/blob/ master/UPGRADING.INTERNALS – hBp://www.sklar.com/soaware/php/2015/03/23/ converdng-‐a-‐php-‐extension-‐to-‐php-‐7/
MacOSX Homebrew の PHP7 • これだけでPHP7が入る • こうすると便利
• phpize7 $ brew install php7 $ cd /usr/local/bin/ $ ln –s ../Cellar/php70/7.0.0-‐rc.3_2/bin/php (phpize , php-‐configも同様にリンク) $ phpize7 $ ./configure –with-‐php-‐config=php7-‐config
SWFEditor のソース $ git clone git://git.osdn.jp/gitroot/swfed/swfed.git $ ls swfed/src
bitmap_udl.c swf_object.c bitmap_udl.h swf_object.h bitstream.c swf_png.c bitstream.h swf_png.h config-‐lib.m4 swf_rect.c config.m4 swf_rect.h config.w32 swf_rgb.c jpeg_segment.c swf_rgb.h jpeg_segment.h swf_rgba.c php_swfed.c swf_rgba.h
SWFEditorの構造 • php_swfed.c が PHPóC バインディング php_swfed.c swf_object.c swf_*.c,h
pure C library PHPóC binding jpeg_*.c,g php5
PHP7対応 (ファイルを分ける) • php_swfed.c と php7_swfed.c に分ける php_swfed.c swf_object.c swf_*.c,h
pure C library PHPóC binding jpeg_*.c,g php7_swfed.c #ifdef は辛かったので ファイルを分けました php5 php7
PHP7対応 (config.m4) • php_swfed 切り替え config.m4 version-‐lib.m4 PHP_NEW_EXTENSION(swfed, \
swf_object.c swf_header.c swf_tag.c bitstream.c swf_debug.c \ <略> , $ext_shared) if test $PHP_MAJOR_VERSION -‐eq 5; then PHP_NEW_EXTENSION(swfed, php_swfed.c, $ext_shared) else PHP_NEW_EXTENSION(swfed, php7_swfed.c, $ext_shared) fi fi sinclude(version-‐lib.m4)
とりあえず make • 20個 エラー?
-ferror-‐limit • エラーが多すぎて20個でとまってる – 制限を外してみる CFLAGS="-‐ferror-‐limit=9999" ./configure -‐-‐with-‐php-‐config=php7-‐config
実際のエラー • 50個 エラー まぁ 大丈夫
ポイント(1/4) • 文字列周りが結構違う – RETURN_STRINGL の引数が変わった
– zend_string を使わせたがるので注意 // どこかで文字列を foo に格納 RETURN_STRINGL(foo, strlen(foo), 0) // <= エラー => RETVAL_STRINGL(foo, strlen(foo), 4) // 1 固定 free(free); // 元々 dup:0 だったので自分で解放 return ; zend_hash_find(table, “foo”, strlen(“foo”), &value); ⇒ zend_string *foo = zval_get_string(“foo”); value = zend_hash_find(table, foo); zend_string_free(foo) => value = zend_hash_str_find(table, ZEND_STRL(“foo”));
ポイント(2/4) • IS_BOOL がなくなった – IS_TRUE, IS_FALSE がある
– (TRUE型とFALSE型 のイメージ) if (Z_TYPE_P(arg4) == IS_TRUE) { without_converdng = 1; } else if (Z_TYPE_P(arg4) == IS_FALSE) { without_converdng = 0; } else { convert_to_boolean(arg4); without_converdng = (int) Z_LVAL_P(arg4); } if (Z_TYPE_P(arg4) != IS_BOOL) { convert_to_boolean(arg4); } without_converdng = (int) Z_LVAL_P(arg4);
ポイント(3/4) • zval のポインタのレベルが違う – 違うどころか int が zval *
になったりする int ret = 0; ret = zend_list_insert(swf, le_swfed TSRMLS_CC); zval *ret = 0; ret = zend_list_insert(swf, le_swfed TSRMLS_CC);
ポイント(4/4) • zend_hash_get_current_data_ex 駄目 – ZEND_HASH_FOREACH_KEY_VAL を使う zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos);
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **)&entry, & pos) == SUCCESS) { ret = zend_hash_get_current_key_ex(Z_ARRVAL_P(arr), &str_key, & str_key_len, &tmp, 0, &pos); <略> zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos); } ZEND_HASH_FOREACH_KEY_VAL(arr_hash, str_key_len, key, value) { <略> } ZEND_HASH_FOREACH_END(); すっきり
はまった罠 PHP_MINIT_FUNCTION(swfed) { zend_declare_property_stringl(swfeditor_ce,
"swf_object", strlen("swf_object"), "", 0, ZEND_ACC_PUBLIC TSRMLS_CC); PHP_METHOD(swfed, __construct) { ret = zend_list_insert(swf, le_swfed TSRMLS_CC); object_init_ex(getThis(), swfeditor_ce); add_property_resource(getThis(), "swfed", ret); zend_list_addref(ret); … if (zend_hash_find(Z_OBJPROP_P(obj), "swfed", strlen("swfed") + 1, (void **)&tmp) == FAILURE) { return NULL; } id = Z_LVAL_PP(tmp); swf = (swf_object_t *) zend_list_find(id, &type); PHP5では動く
はまった罠 (PHP7 対応してみた) PHP_MINIT_FUNCTION(swfed) { zend_declare_property_stringl(swfeditor_ce,
"swf_object", strlen("swf_object"), "", 0, ZEND_ACC_PUBLIC TSRMLS_CC); PHP_METHOD(swfed, __construct) { ret = zend_list_insert(swf, le_swfed TSRMLS_CC); object_init_ex(getThis(), swfeditor_ce); add_property_resource(getThis(), "swfed", ret); zend_list_addref(ret); … if ((tmp = zend_hash_str_find(Z_OBJPROP_P(obj), ZEND_STRL("swfed”))) == NULL) { return NULL; } id = Z_LVAL_PP(tmp); swf = (swf_object_t *) zend_list_find(id, &type); NULLが返る!
はまった罠 (PHP7 対応してみた) PHP_MINIT_FUNCTION(swfed) { zend_declare_property_stringl(swfeditor_ce,
"swf_object", strlen("swf_object"), "", 0, ZEND_ACC_PUBLIC TSRMLS_CC); PHP_METHOD(swfed, __construct) { ret = zend_list_insert(swf, le_swfed TSRMLS_CC); object_init_ex(getThis(), swfeditor_ce); add_property_resource(getThis(), “swf_object”, ret); // 前は “swfed” zend_list_addref(ret); … if ((tmp = zend_hash_str_find(Z_OBJPROP_P(obj), ZEND_STRL("swf_object”))) == NULL) { return NULL; } id = Z_LVAL_PP(tmp); swf = (swf_object_t *) zend_list_find(id, &type); 全部合わせないと駄目
はまった罠解説 • PHP4,5 では declare_property した文字列 (swf_object)と、無関係に add_property して、 (read_property
や) zend_hash_find で拾えた – お行儀悪い • PHP7 では合わせないと駄目
動作デモ
課題 • 終了処理で落ちるのでデバッグする • エラーを直しただけなので、一通り見直す • RETURN_STRINGL の
dup:0 対応 (freeする)
ありがとうございました