ç§ã¯Linuxã®ã¿ã§éçºãè¡ã£ãŠããããããã³ã䜿çšããŠVisual Studioçšã®ããªãããŒãªã¢ããªã³ãäœæããã«ãŒãããäœæããŸã:)ããŠãããã«ç解ããŠããäœæ¥ãç°¡çŽ åããæ¹ãè¯ãã§ãããã
ãŸãã config.m4ãšMakefileã® 2ã€ã®ãã¡ã€ã«ãäœæããå¿ èŠããããŸãã æåã®æ¡åŒµæ©èœã¯æ¡åŒµæ©èœãæ§ç¯ããããã«å¿ èŠã§ããã2çªç®ã®æ¡åŒµæ©èœã¯...ãã®ã¢ã»ã³ããªãã«ã¿ãã°ããœãŒã¹ã³ãŒãã§æãªããªãããã«ããããã§ã:)
1. config.m4
ããã§ã¯å§ããŸãããã ã¢ã»ã³ããªçšã®ãã¡ã€ã«ãæžãããšã¯ããŸãé¢çœããªãã®ã§ãããããæž¡ããŠäœãäœãªã®ãã説æããŸãã ããã«èšå®ã®äžè¬çãªãã¥ãŒããããŸãã
dnlã§å§ãŸãè¡ã¯ã³ã¡ã³ãã§ãã
æåã®2è¡ã¯--enable-mystringãªãã·ã§ã³ãè¿œå ããŠãã«ãããŸãã ãã®ãããPHPãœãŒã¹ã®/ ext /ãã©ã«ããŒã«ã¢ãžã¥ãŒã«ãé 眮ããPHPããã«ããããã©ãããéžæã§ããŸãã
1-2è¡ç®ãã³ã¡ã³ãã¢ãŠãããŠ3-4è¡ç®ãã³ã¡ã³ã解é€ãããšããªãã·ã§ã³ã§ãã¹ãæå®ã§ãã--with-mystringãªãã·ã§ã³ã衚瀺ãããŸãã ãªãã§ïŒ ãã¡ã€ã«ã«æ®ã£ãŠãããã¹ãŠã®è¡ã«ã€ããŠ:)ç¹å®ã®ã©ã€ãã©ãªïŒãã®äŸã§ã¯mylib1ããã³mylib2ã©ã€ãã©ãªãæå®ïŒã䜿çšããå Žåãèšå®æã«ãã¹ãæž¡ãããšãã§ããŸãã å®éã12ã29è¡ç®ã§ãããã®ã©ã€ãã©ãªãèŠã€ããŠæ¥ç¶ããããšããŠããŸãã
次ã«ã9è¡ç®ã«æ³šæããŠãã ãããããã«ãããæ§æçšã®å€æ°<MODULE_NAME> _SHARED_LIBADDãè¿œå ããããªã³ã¯çšã®ã©ã€ãã©ãªãè¿œå ãããŸãã äžè¬ã«ãm4ã«ã¯ä»»æã®å€æ°åã§ã¯ãªãå³å¯ãªå€æ°åãå¿ èŠã§ãããšããäºå®ã«æ £ããŠãã ããã ããã¯ã¹ãã«ã¿ã§ãã
33ã35è¡ç®ã§ã¯ãæãäžè¬çãªã©ã€ãã©ãªããªã³ã¯ã«è¿œå ããŸã-ããããæ€çŽ¢ããå¿ èŠã¯ãããŸããã
36è¡ç®ã§ã¯ãã©ã®ãã¡ã€ã«ããæ¡åŒµæ©èœãæ§ç¯ããå¿ èŠããããã瀺ããŠããŸãã
è¡32ã¯ããã«ãã¢ãžã¥ãŒã«ãCã§ã¯ãªãC ++ã§äœæããŠããããšã瀺ããŠããŸãïŒã¢ãžã¥ãŒã«ãäœæããå Žå-éãã¯ãããã§ããããã©ã¹ã©ã€ãã©ãªãŸãã¯ãã©ã¹ã³ãŒããæ¥ç¶ããå Žåã¯å¿ èŠã«ãªããŸãïŒã
ä»åã¯äœãæ¥ç¶ããªããã ãèšå®ãå€§å¹ ã«ççž®ããŸãã ãã£ã10è¡-ãã以äžã¯ãããŸããã
2. Makefile
ã¡ã€ã¯ãã¡ã€ã«ã¯ãèªå°å¿ã®ããããã°ã©ããŒã人çã§å°ãªããšãäžåºŠã¯æžããããšããããšæãã®ã§ã説æã¯å¿ èŠãããŸããã ã§ããããã䜿çšããŸã ã `php-config --extension-dir`ã³ãã³ãã¯PHPæ¡åŒµæ©èœãä¿åãããŠãããã£ã¬ã¯ããªãæäŸãã __ buildãã£ã¬ã¯ããªã¯ãã¹ãŠãåéãããã£ã¬ã¯ããªã§ããããšã«æ³šæããŠãã ããã
3. mystring.hãã¡ã€ã«ãäœæããŸã
ä»äœãå¿ èŠã§ããïŒ ãŸãšããªC / C ++ããã°ã©ã ã®ããã«-ããããŒãã¡ã€ã«ãšã³ãŒããã¡ã€ã«ã ããããŒããå§ããŸãããã ãã¡ã€ã«ã40è¡æªæºã®ã·ã³ãã«ãªãã®ã«ãªããŸãã ãããèŠãŠã¿ãŸãããã
è¡4ã5ã§ã¯ãæ¡åŒµæ©èœã®ååãšããŒãžã§ã³ã宣èšããŸãã ããã¯ãã¢ãžã¥ãŒã«æ å ±ã®åŸåã§ãã®è²Žéãªæ å ±ã衚瀺ããããã ãã«å¿ èŠã§ãã
è¡7ã¯ãã¯ã©ã¹ã®ååã瀺ããŠããŸãã ãã¡ããããmystringãã®èšè¿°ã¯PHP_MYSTRING_CLASS_NAMEãããçãã§ããããã€ã§ã1ãæã§ã¯ã©ã¹åãå€æŽã§ããŸãã ããšãã°ãã¯ã©ã¹ã®ååããMystringãã«å€æŽããŸã-倧æåã䜿çšããé©åãªäººã ã«é©ããŠããŸãã
9è¡ç®ãã11è¡ç®ã«ã¯ãã¢ã»ã³ããªããã»ã¹äžã«çæãããconfig.hãã¡ã€ã«ãå«ãŸããŠããŸã-èªåã§äœæããããšã¯ãããŸããã
次ã«ãæšæºããããŒãå«ããŠãé¢æ°ã宣èšããŸãã ããã§è©³ãã説æããŸãã é¢æ°PHP_MINIT_FUNCTIONããã³PHP_MSHUTDOWN_FUNCTIONã¯ãã¢ãžã¥ãŒã«ã®ããŒãããã³ã¢ã³ããŒãæã«å®è¡ãããé¢æ°ã§ãã ãããã«å ããŠã * _GINIT_ *ããã³* _GSHUTDOWN_ *-PHPãã°ããŒãã«ã«èµ·å/ã¢ã³ããŒãããããã®é¢æ°ãããã³* _RINIT_ *ããã³* _RSHUTDOWN_ * -ã¢ãžã¥ãŒã«ãã¢ã¯ãã£ãå/éã¢ã¯ãã£ãåãããšãããããŸãã PHP_MINFO_FUNCTIONé¢æ°ã¯ã phpinfoïŒïŒãåŒã³åºããããšãã«å®è¡ãããé¢æ°ã§ãã¢ãžã¥ãŒã«ã«é¢ããæ å ±ãçæããŸãã
次ã«ãããã€ãã®ã¡ãœããã宣èšããŸã-æåã®éšåã§ã PHP_FUNCTIONãã¯ãã䜿çšããŠãããã宣èšããŸãããããããã¯ã°ããŒãã«ã§ãããïŒ ããã§ã¯ãåºæ¬çã«åãããšãè¡ã£ãŠããŸãããã¯ãã®ã¿ããã¯ã©ã¹ãšãã®ã¡ãœããã®ååãšãã2ã€ã®ãã©ã¡ãŒã¿ãŒãåããŸãã
ããŠã35è¡ç®ã®çµããã«ãã¢ãžã¥ãŒã«ã宣èšããŸãã
ããããŒãã¡ã€ã«ã«ã¯ä»ã«äœãå¿ èŠãããŸãããã³ãŒãã«é²ã¿ãŸãã
4.ã¢ãžã¥ãŒã«ã³ãŒããèšè¿°ããŸã-mystring.cc
ããã§ã¯ãã³ãŒãã¯ããè€éã§ãã æ®å¿µãªããããããèšäºã«çŽæ¥å ¥ããããšã¯ã§ããŸããã§ãã-Habrã¯æè°ããŸãã-ããã§ç§ã¯ããã«ãã¹ãŠã®ã³ãŒããããã«æçš¿ããŸãã ãããã§ã¯ãã®å 容ã®ã¿ãæ€èšããŸãã
1ã27è¡ç®
ãããŸã§ã®ãšããããã¹ãŠãåçŽã§ã-å°æ¥ã®ã¯ã©ã¹ã宣èšããã¢ãžã¥ãŒã«ã宣èšããŸãã 泚æããŠãã ãã-ååãããŒãžã§ã³ãããã³é¢æ°MINIT ã MSHUTDOWNããã³MINFOãæå®ããŸãã ã ä»åã¯ã°ããŒãã«é¢æ°ã宣èšããã RINITãšRSHUTDOWNãå¿ èŠãããŸãããä»ã®ãã¹ãŠã¯ããã©ã«ããšèŠãªãããšãã§ããŸãã
29ã49è¡ç®
ããã§ãã¢ãžã¥ãŒã«ãPHPã®äžéšãšããŠã ãã§ãªããæ¡åŒµæ©èœãšããŠã³ã³ãã€ã«ã§ããããšãPHPã«äŒãããã¯ãã眮ãæããŸããã ãã®åŸãã¯ã©ã¹é¢æ°ã®ã»ãããçºè¡šããŸããã åé¢æ°ã«ã¯ãã¯ã©ã¹åãé¢æ°ã®ååã arg_infoæ§é äœãžã®ãã€ã³ã¿ãŒãããã³ã¢ã¯ã»ã¹ãã©ã¡ãŒã¿ãŒã®4ã€ã®ãã©ã¡ãŒã¿ãŒã瀺ãããŸãã arg_infoæ§é ã®æ確ãªèª¬æã«åºäŒã£ãããšããªããããå€ãæ¹æ³ã§NULLãæž¡ããé¢æ°èªäœã«æ¢ã«ãããã©ã¡ãŒã¿ãŒã確èªããŸãã
äž»ãªã¢ã¯ã»ã¹ãã©ã¡ãŒã¿ã¯ããã¡ããZEND_ACC_PUBLIC ã ZEND_ACC_PROTECTEDããã³ZEND_ACC_PRIVATEã§ãã ãããã«å ããŠã ZEND_ACC_STATICãŸãã¯ZEND_ACC_ALLOW_STATICãæå®ã§ããŸãïŒãã®ã¡ãœããã¯éçããã³éåžžã®äž¡æ¹ã§äœ¿çšã§ããŸãïŒã ã³ã³ã¹ãã©ã¯ã¿ããã¹ãã©ã¯ã¿ãããã³ã¯ããŒã³æŒç®åïŒPHPã§__cloneã®é¢æ°ãšããŠå®£èšãããŠããïŒã®å Žåããã©ã°ZEND_ACC_CTOR ã ZEND_ACC_DTOR ãããã³ZEND_ACC_CLONEãããããæå®ããå¿ èŠããããŸãã
ãã ããããããŒãã¡ã€ã«ã§å®å šãªãªã¹ãã確èªã§ããŸããç§ã®ãã·ã³ã§ã¯ãããã¯/usr/include/php5/Zend/zend_compile.hãã¡ã€ã«ã§ãã
PHP_MEïŒïŒ ã䜿çšããŠèª¬æããåã¡ãœããã®åŸã«ãã«ã³ããå ¥ããå¿ èŠããªãããšã«æ³šæããŠãã ããã ãããŠæåŸã«ãåžžã«3ã€ã®NULLã®é åãããã¯ãã§ãã
ãã®éãå ã«é²ã¿ãŸãã
51ã76è¡ç®
以åã«çºè¡šããã3ã€ã®æ¹æ³ïŒããŒããã¢ã³ããŒããããã³ã¢ãžã¥ãŒã«æ å ±ïŒãç¹å®ãããŸããã 3ã€ãã¹ãŠã®ãã¡ã1ã€ã ãã«èå³ããããŸããã¢ãžã¥ãŒã«ã®ããŒãã§ãã ãŸãã宣èšããã¯ã©ã¹ãç»é²ããå¿ èŠããããŸãã
次ã«ãç»é²ãããã¯ã©ã¹ã«ããããã£ãäœæããŸããç»é²ãããã¯ã©ã¹ãžã®ãã€ã³ã¿ãããããã£ã®ååããã®ååã®é·ãïŒãã®è¡ã«ã€ããŠã¯åŸã»ã©ïŒãããã©ã«ãå€ãæž¡ããåã³ã¢ã¯ã»ã¹ãã©ã¡ãŒã¿ãæž¡ããŸãã æåŸã«ãããžãã¯ã¯ãŒãTSRMLS_CCãééããªãèšè¿°ããå¿ èŠããããŸãã ãã®èšèã¯ç¹ã«èšåããå¿ èŠããããŸãã é¢æ°å ã§PHPã®çŸåšã®ç¶æ ãæäœããã«ã¯ãçŸåšã®å Žæãç¥ããã¯ã©ã¹ã«é¢ããæ å ±ãååŸããå¿ èŠããããŸãã ãªã©ããã®æ å ±ãéä¿¡ããå¿ èŠããããŸãã ãããè¡ãã«ã¯ãé¢æ°ã宣èšãããšãã«ãæåŸã«ãã¯ãTSRMLS_DCãèšè¿°ãã -TSRMLS_CCãåŒã³åºãå¿ èŠããããŸãã ã©ã¡ãã®å Žåãããã¯ãã®åã«ã³ã³ãã眮ãå¿ èŠã¯ãããŸãã ã
ããã§ãããããã£åã®é·ãã«æ»ããŸãã ããŸããŸãªãœãŒã¹ã®ããããã£ã®å®£èšã«é¢ããæ å ±ã¯éåžžã«å°ãªããççŸããŠããŸãã ãããã£ãŠãåãSarah Golemonã®ããã¥ã¢ã«ã§ã¯ãããããã£ããã©ã€ããŒããšããŠå®£èšãããŠããå Žåãã \ 0 class_name \ 0 property_nameããšãã圢åŒã®ååãæã£ãŠããå¿ èŠããããšèšèŒãããŠããŸãã å®éã«ã¯ã zend_mangle_property_nameã䜿çšãããšãããããã£ãžã®ã¢ã¯ã»ã¹æã«PHPãããŒãã£ãèªãããšãããããŸããããäžèšã®åŒã³åºãã§ã¯ãã¹ãŠãçŽ æŽãããããšã§ãã ãããã¯ã«é¢ããæç®ãèªãå Žåã¯æ³šæããŠãã ããã
78ã106è¡ç®
ããã§ã¯ãæšæºã¯ã©ã¹ã®ã¡ãœãããå®çŸ©ããŸãããã ãã€ã³ãã«è¡ããŸãããã
getThisïŒïŒé¢æ°ã¯ãã¡ãœãããåŒã³åºããã¯ã©ã¹ã®ãªããžã§ã¯ããžã®ãã€ã³ã¿ãŒãè¿ããŸãã ã³ã³ã¹ãã©ã¯ã¿ãŒãšãã¹ãã©ã¯ã¿ã«ã€ããŠã¯ããã®ãã€ã³ã¿ãŒããã§ãã¯ããŸãããããã®ã¡ãœãããéçã«åŒã³åºããªãããã«ããŸãã 次ã«ãã³ã³ã¹ãã©ã¯ã¿ãŒã§ããã®é¢æ°ã瀺ãããã«ãæ¢ã«å®£èšãããŠããããããã£ãstrããå€æŽããŸãã ãããè¡ãã«ã¯ããªããžã§ã¯ãïŒã¯ã©ã¹ïŒã®åããªããžã§ã¯ãèªäœãžã®ãã€ã³ã¿ãŒãããããã£åã®ååãšé·ããããã³æ°ããå€ãæž¡ããŸãã * _stringïŒïŒé¢æ°ã§ã¯ãªã* _stringlïŒïŒã䜿çšããŠããããšã«æ³šæããŠãã ãã-ãŸããæ°ããå€ã®é·ããæž¡ãå¿ èŠããããŸãã ååãšããŠãæååã«æåã\ 0ããå«ãŸããå ŽåããŸãã¯éã«æååã®æåã®Næåã®ã¿ãæžã蟌ã¿ããå Žåã«äœ¿çšãããŸããã * _stringïŒïŒãªãã·ã§ã³ãããå°ãéãåäœããããããã®ãããªäºçŽ°ãªç¶æ³ã§äœ¿çšããŸãããè¿œå ã®ãã©ã¡ãŒã¿ãŒãèšå®ããŠãããŸããŸããã
åæ§ã«ãé¢æ°ã§RETURN_STRINGLãã¯ãã䜿çšããŠãã¯ã©ã¹ãæååã«ãã£ã¹ãããŸãã æåŸã®ãã©ã¡ãŒã¿ã1ãã«æ³šæããŠãã ãã-ããã¯ããªããžã§ã¯ãèªäœã§ã¯ãªãããã®ã³ããŒã転éããããšãæå³ããŸãã ããªãã¯åœŒããåŸã§ç§ãã¡ã®ã©ã€ã³ã§äœããããã®ã決ããŠããããŸããã
108è¡ç®ãã133è¡ç®
è¡ãè¿œå ããæ¹æ³ã説æããŸãããã
ãŸããæååããã©ã¡ãŒã¿ãŒãšããŠæž¡ããããã©ããã確èªããŸã-ããã«ã€ããŠã¯ãæåã®éšåã§æ¢ã«èª¬æããŸããã
次ã«ããªããžã§ã¯ãã«æ ŒçŽãããŠããæååããªããžã§ã¯ãããèªã¿åããŸãã ããããã£ãæååãšããŠäœæããŸãããããã€ã³ã¿ãŒãzvalã«æ»ã£ãããšã«æ³šæããŠãã ãã ã äºã¯ã絶察ã«phpã®ãã¹ãŠã®ããŒã¿åãzvalåã§è¡šãããããšã§ã ã ã©ã®ããã«æ©èœãããã«èå³ãããå Žåã¯ããã¡ã€ã«/usr/include/php5/Zend/zend.hã§struct _zval_structãšunion _zvalue_valueã®å®çŸ©ãåç §ããŠãã ããã
æåŸã«ãæ°ããè¡ã«ã¡ã¢ãªãå²ãåœãŠãå ã®è¡ãšãã¢ãã€ã³ããããã«ã³ããŒããŸãã 次ã«ã䜿ãæ £ããzend_update_property_stringlïŒïŒã¡ãœããã䜿çšããŠãæ°ããå€ãæžã蟌ã¿ãŸãã PHPã§ã¯ã malloc ã callocãããã³freeã®ä»£ããã«ã emalloc ã ecallocãããã³efreeã®éä¿¡é¡äŒŒç©ã䜿çšããã®ãç¿æ £ã§ã ã
æ°ããå€ã¯å¿ èŠãªå Žæã«ããã NULLãè¿ãããšãã§ããŸã ã 宿é¡ïŒãªããžã§ã¯ãèªäœãè¿ãæ¹æ³ãææ¡ããŠã $ a-> appendïŒ "a"ïŒ-> appendïŒ "b"ïŒãšãã圢åŒã®ãã§ãŒã³ãäœæã§ããããã«ããŸã...
135è¡ç®ãã148è¡ç®
æåŸã«ãæ¯èŒã¡ãœãããå®è£ ããŸãã ãã®äžã§ãå®éã®æ¯èŒãå®è£ ããŸããïŒæªéã¯ãã®ã¡ãœãããåŒã³åºãçç±ãç¥ã£ãŠããŸãïŒããè¡ãå°å·ããŸã-å°ãªããšãã©ããã«è¡šç€ºããå¿ èŠããããŸã-ãããŠå°ãéæ³ã瀺ããŸãã
ãŸããæååstrãèªã¿åã£ãŠåºåããŸãã ãæ°ã¥ããããããŸãããã zend_printfïŒïŒé¢æ°ã®æ§æã¯ãæšæºã®printfïŒïŒãšãŸã£ããåãã§ãã ãããŠ...ããã¯äœã§ããïŒ ã¯ããç§ãã¡ã¯ç°¡åãã€å¶çŽãªãPHPã³ãŒããååŸããŠå®è¡ããŸããã ãã©ã¡ãŒã¿ãŒãšããŠãã³ãŒãã®è¡ãå€æ°ãžã®ãã€ã³ã¿ãŒãå®è¡çµæãé 眮ããå Žæãããã³ã¹ã¯ãªããã®ååãæž¡ããŸãã äœãçºæããªãããã«ãmyvardumpãäœæããŸããã
ãŸãšã
` make all install`ãšå ¥åããŸã ã 次ã®ããã«å ¥åããŸããphp -r '$ s = new mystringïŒïŒ; echo $ sã "\ n"; $ s-> appendïŒ "PopyachsoïŒ"ïŒ; $ s-> compareïŒïŒ; ' ãåºåãèŠãŠãã ããïŒ
mystring
upchk !
object(mystring)#1 (1) {
["str:private"]=>
string(21) "upchk !"
}
æåã®è¡ã¯ãã¯ã©ã¹ã®è¡ãžã®ãã£ã¹ããæšæž¬ããããšã§ãïŒ__toStringïŒïŒãåç §ïŒã 2çªç®-ãã§ã«å€æŽãããæååstrãåºåããŸãã ãããŠæ®ãã®3è¡ã¯ãã¯ã©ã¹ã®ãã³ãã§ããzend_eval_stringã®çµæã§ãã äœæãããç§æ財ç£ã芳å¯ããŸã-ãã¹ãŠãå ¬æ£ã§ãã
次ã¯ïŒ
ãŸããèªå·±PRã®äžç°ãšããŠãæè¿æžããæ¡åŒµæ©èœã®ã¿ããã§ãã¯ã¢ãŠãããããšããå§ãããŸãã
svn checkout http://dingo-php.googlecode.com/svn/trunk/ dingo-php
ã»ãšãã©ã®ãŠãŒã¶ãŒã«ãšã£ãŠãæ¡åŒµæ©èœèªäœã¯å®éã®ã¢ããªã±ãŒã·ã§ã³ã®èŠ³ç¹ããã¯ãŸã£ããé¢çœããªãã§ããããã次ã®ããã«èŠãããšãã§ããŸãã
-ã³ã³ãã€ã«äžã«ãªã³/ãªãã§ãã1ã€ã®æ¡åŒµæ©èœã§è€æ°ã®ã¯ã©ã¹ãäœæããæ¹æ³
-ãµãŒãããŒãã£ã®ã©ã€ãã©ãªãã©ããããŠäœ¿çšããæ¹æ³
-ãŸããå®éã®ã³ãŒãã®ããã
ããã«ããµã©ãŽã¬ã¢ã³ã®æ¬ããå§ãããŸãã
>> ãµã©ãŽã¬ã¢ã³ãPHPã®æ¡åŒµãšåã蟌ã¿ã
ãã·ã¢ã§ã¯ãããªãã®éã®ãã³ã²ãããããŸãããã€ã³ã¿ãŒãããäžã§ããçšåºŠã®åªåãããã°ãé»åçãèŠã€ããããšãã§ããŸãã
ãã®æ¬ã¯å°ãæ代é ãã§ãããRINIT / RSHUTDOWNãå¿ èŠãªçç±ãã¯ã©ã¹ã«çºçããã€ãã³ãã«ãã³ãã©ãŒãæããæ¹æ³ãã¹ããªãŒã ãäœæããæ¹æ³ãini-configãæäœããæ¹æ³ãããã³ãªããžã§ã¯ãã§ããã«å€ãã®ããšãè¡ãæ¹æ³ãèŠã€ããããšãã§ããŸãã
Pså®éšã®ããã«ã³ããŒã¢ã³ãããŒã¹ãããã®ãé¢åãªäººã®ããã«ãã³ã³ãã€ã«ã®æºåãã§ããã¢ãžã¥ãŒã«ãå«ãã¢ãŒã«ã€ããæçš¿ããŸããïŒ narod.ru/disk/15177450000/mystring.tar.gz.html