@@ -4958,107 +4958,97 @@ ZEND_METHOD(FFI_CType, getFuncParameterType) /* {{{ */
49584958}
49594959/* }}} */
49604960
4961+ static char * zend_ffi_skip_ws_and_comments (char * p , bool allow_standalone_newline )
4962+ {
4963+ while (true) {
4964+ if (* p == ' ' || * p == '\t' ) {
4965+ p ++ ;
4966+ } else if (allow_standalone_newline && (* p == '\r' || * p == '\n' || * p == '\f' || * p == '\v' )) {
4967+ p ++ ;
4968+ } else if (allow_standalone_newline && * p == '/' && p [1 ] == '/' ) {
4969+ p += 2 ;
4970+ while (* p && * p != '\r' && * p != '\n' ) {
4971+ p ++ ;
4972+ }
4973+ } else if (* p == '/' && p [1 ] == '*' ) {
4974+ p += 2 ;
4975+ while (* p && (* p != '*' || p [1 ] != '/' )) {
4976+ p ++ ;
4977+ }
4978+ p += 2 ;
4979+ } else {
4980+ break ;
4981+ }
4982+ }
4983+
4984+ return p ;
4985+ }
4986+
49614987static char * zend_ffi_parse_directives (const char * filename , char * code_pos , char * * scope_name , char * * lib , bool preload ) /* {{{ */
49624988{
49634989 char * p ;
49644990
4991+ code_pos = zend_ffi_skip_ws_and_comments (code_pos , true);
4992+
49654993 * scope_name = NULL ;
49664994 * lib = NULL ;
49674995 while (* code_pos == '#' ) {
4968- if (strncmp (code_pos , "#define FFI_SCOPE" , sizeof ("#define FFI_SCOPE" ) - 1 ) == 0
4969- && (code_pos [sizeof ("#define FFI_SCOPE" ) - 1 ] == ' '
4970- || code_pos [sizeof ("#define FFI_SCOPE" ) - 1 ] == '\t' )) {
4971- p = code_pos + sizeof ("#define FFI_SCOPE" );
4972- while (* p == ' ' || * p == '\t' ) {
4973- p ++ ;
4974- }
4975- if (* p != '"' ) {
4976- if (preload ) {
4977- zend_error (E_WARNING , "FFI: failed pre-loading '%s', bad FFI_SCOPE define" , filename );
4978- } else {
4979- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', bad FFI_SCOPE define" , filename );
4980- }
4981- return NULL ;
4982- }
4983- p ++ ;
4984- if (* scope_name ) {
4985- if (preload ) {
4986- zend_error (E_WARNING , "FFI: failed pre-loading '%s', FFI_SCOPE defined twice" , filename );
4987- } else {
4988- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', FFI_SCOPE defined twice" , filename );
4989- }
4990- return NULL ;
4991- }
4992- * scope_name = p ;
4993- while (1 ) {
4994- if (* p == '\"' ) {
4995- * p = 0 ;
4996+ if (strncmp (code_pos , ZEND_STRL ("#define" )) == 0 ) {
4997+ p = zend_ffi_skip_ws_and_comments (code_pos + sizeof ("#define" ) - 1 , false);
4998+
4999+ char * * target = NULL ;
5000+ const char * target_name = NULL ;
5001+ if (strncmp (p , ZEND_STRL ("FFI_SCOPE" )) == 0 ) {
5002+ p = zend_ffi_skip_ws_and_comments (p + sizeof ("FFI_SCOPE" ) - 1 , false);
5003+ target = scope_name ;
5004+ target_name = "FFI_SCOPE" ;
5005+ } else if (strncmp (p , ZEND_STRL ("FFI_LIB" )) == 0 ) {
5006+ p = zend_ffi_skip_ws_and_comments (p + sizeof ("FFI_LIB" ) - 1 , false);
5007+ target = lib ;
5008+ target_name = "FFI_LIB" ;
5009+ } else {
5010+ while (* p && * p != '\n' && * p != '\r' ) {
49965011 p ++ ;
4997- break ;
4998- } else if (* p <= ' ' ) {
4999- if (preload ) {
5000- zend_error (E_WARNING , "FFI: failed pre-loading '%s', bad FFI_SCOPE define" , filename );
5001- } else {
5002- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', bad FFI_SCOPE define" , filename );
5003- }
5004- return NULL ;
50055012 }
5006- p ++ ;
5007- }
5008- while (* p == ' ' || * p == '\t' ) {
5009- p ++ ;
5010- }
5011- while (* p == '\r' || * p == '\n' ) {
5012- p ++ ;
5013- }
5014- code_pos = p ;
5015- } else if (strncmp (code_pos , "#define FFI_LIB" , sizeof ("#define FFI_LIB" ) - 1 ) == 0
5016- && (code_pos [sizeof ("#define FFI_LIB" ) - 1 ] == ' '
5017- || code_pos [sizeof ("#define FFI_LIB" ) - 1 ] == '\t' )) {
5018- p = code_pos + sizeof ("#define FFI_LIB" );
5019- while (* p == ' ' || * p == '\t' ) {
5020- p ++ ;
5013+ code_pos = zend_ffi_skip_ws_and_comments (p , true);
5014+ continue ;
50215015 }
5016+
50225017 if (* p != '"' ) {
50235018 if (preload ) {
5024- zend_error (E_WARNING , "FFI: failed pre-loading '%s', bad FFI_LIB define" , filename );
5019+ zend_error (E_WARNING , "FFI: failed pre-loading '%s', bad %s define" , filename , target_name );
50255020 } else {
5026- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', bad FFI_LIB define" , filename );
5021+ zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', bad %s define" , filename , target_name );
50275022 }
50285023 return NULL ;
50295024 }
50305025 p ++ ;
5031- if (* lib ) {
5026+ if (* target ) {
50325027 if (preload ) {
5033- zend_error (E_WARNING , "FFI: failed pre-loading '%s', FFI_LIB defined twice" , filename );
5028+ zend_error (E_WARNING , "FFI: failed pre-loading '%s', %s defined twice" , filename , target_name );
50345029 } else {
5035- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', FFI_LIB defined twice" , filename );
5030+ zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', %s defined twice" , filename , target_name );
50365031 }
50375032 return NULL ;
50385033 }
5039- * lib = p ;
5034+ * target = p ;
50405035 while (1 ) {
50415036 if (* p == '\"' ) {
50425037 * p = 0 ;
50435038 p ++ ;
50445039 break ;
50455040 } else if (* p <= ' ' ) {
50465041 if (preload ) {
5047- zend_error (E_WARNING , "FFI: failed pre-loading '%s', bad FFI_LIB define" , filename );
5042+ zend_error (E_WARNING , "FFI: failed pre-loading '%s', bad %s define" , filename , target_name );
50485043 } else {
5049- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', bad FFI_LIB define" , filename );
5044+ zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', bad %s define" , filename , target_name );
50505045 }
50515046 return NULL ;
50525047 }
50535048 p ++ ;
50545049 }
5055- while (* p == ' ' || * p == '\t' ) {
5056- p ++ ;
5057- }
5058- while (* p == '\r' || * p == '\n' ) {
5059- p ++ ;
5060- }
5061- code_pos = p ;
5050+
5051+ code_pos = zend_ffi_skip_ws_and_comments (p , true);
50625052 } else {
50635053 break ;
50645054 }
0 commit comments