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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
220
chokaizomae
yoya
2
620
wildimagebinary
yoya
1
240
goimagicksyokai
yoya
2
1.2k
GoImagickThumbnail
yoya
0
1.7k
sushigazou
yoya
0
12k
Other Decks in Programming
See All in Programming
flutter_test のその先へ — Flutter アプリの LLM 機能に「評価」という品質保証を
kosukesaigusa
0
200
エージェントを使い続けるためのメタワーク / Meta-work for keeping using the agent
rkaga
6
2.2k
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
4
3.7k
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
320
React Native에 현대적인 빌드 도구 더하기: Rollipop 구현기
leegeunhyeok
0
180
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
420
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
310
Будущее локальных LLM – Алексей Голобурдин, PythoNN
sobolevn
0
110
プロジェクトコードをキレイキレイしよう!暗黙的な参照を読み解く静的解析
ostk0069
0
210
まずはコードより業務と向き合う:テーブル解体のためにPdMを呼んだ話
sakawe_ee
0
180
Railsバージョンを4倍にした話
optim
0
960
Event is what happens
moro
2
3.9k
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
304
22k
For a Future-Friendly Web
brad_frost
184
11k
The Cult of Friendly URLs
andyhume
79
7.1k
Design in an AI World
tapps
1
390
4 Signs Your Business is Dying
shpigford
187
23k
The World Runs on Bad Software
bkeepers
PRO
72
12k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.4k
Leo the Paperboy
mayatellez
10
2.4k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
3
1.2k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
How GitHub (no longer) Works
holman
316
150k
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する)
ありがとうございました