Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
php7_swfed
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
yoya
November 22, 2015
Programming
4.6k
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
190
ImageFluxBinary
yoya
2
3.1k
HEIF-kaisetsu
yoya
4
3.6k
go-thumber-imagick
yoya
1
210
chokaizomae
yoya
2
620
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
Domain-Driven Transformation
hschwentner
2
2.3k
AIに “答え“を書かせるのを やめてみた
___akari11
0
130
作って学ぶSpring BootのAuto Configuration / JJUG Night Seminar 2026-10-19
rshindo
0
200
Groovy as a human and AI friendly programming language
paulk
0
100
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
850
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
270
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
410
Jetpack Compose Mechanisms
skydoves
3
860
Kotlinize Is Not Just Converting to Kotlin
chigichan24
1
180
Railsバージョンを4倍にした話
optim
0
530
ActionController meets Protocol Buffers
sorah
0
670
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
160
Featured
See All Featured
So, you think you're a good person
axbom
PRO
2
2.2k
A designer walks into a library…
pauljervisheath
211
25k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
310
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.2k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
67k
KATA
mclloyd
PRO
35
16k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
59k
Code Reviewing Like a Champion
maltzj
529
40k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
1
280
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する)
ありがとうございました