@@ -4958,107 +4958,102 @@ ZEND_METHOD(FFI_CType, getFuncParameterType) /* {{{ */
4958
4958
}
4959
4959
/* }}} */
4960
4960
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
+ if (* p == '*' ) {
4979
+ p ++ ;
4980
+ if (* p == '/' ) {
4981
+ p ++ ;
4982
+ }
4983
+ }
4984
+ } else {
4985
+ break ;
4986
+ }
4987
+ }
4988
+
4989
+ return p ;
4990
+ }
4991
+
4961
4992
static char * zend_ffi_parse_directives (const char * filename , char * code_pos , char * * scope_name , char * * lib , bool preload ) /* {{{ */
4962
4993
{
4963
4994
char * p ;
4964
4995
4996
+ code_pos = zend_ffi_skip_ws_and_comments (code_pos , true);
4997
+
4965
4998
* scope_name = NULL ;
4966
4999
* lib = NULL ;
4967
5000
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 ;
5001
+ if (strncmp (code_pos , ZEND_STRL ("#define" )) == 0 ) {
5002
+ p = zend_ffi_skip_ws_and_comments (code_pos + sizeof ("#define" ) - 1 , false);
5003
+
5004
+ char * * target = NULL ;
5005
+ const char * target_name = NULL ;
5006
+ if (strncmp (p , ZEND_STRL ("FFI_SCOPE" )) == 0 ) {
5007
+ p = zend_ffi_skip_ws_and_comments (p + sizeof ("FFI_SCOPE" ) - 1 , false);
5008
+ target = scope_name ;
5009
+ target_name = "FFI_SCOPE" ;
5010
+ } else if (strncmp (p , ZEND_STRL ("FFI_LIB" )) == 0 ) {
5011
+ p = zend_ffi_skip_ws_and_comments (p + sizeof ("FFI_LIB" ) - 1 , false);
5012
+ target = lib ;
5013
+ target_name = "FFI_LIB" ;
5014
+ } else {
5015
+ while (* p && * p != '\n' && * p != '\r' ) {
4996
5016
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 ;
5005
5017
}
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 ++ ;
5018
+ code_pos = zend_ffi_skip_ws_and_comments (p , true);
5019
+ continue ;
5021
5020
}
5021
+
5022
5022
if (* p != '"' ) {
5023
5023
if (preload ) {
5024
- zend_error (E_WARNING , "FFI: failed pre-loading '%s', bad FFI_LIB define" , filename );
5024
+ zend_error (E_WARNING , "FFI: failed pre-loading '%s', bad %s define" , filename , target_name );
5025
5025
} else {
5026
- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', bad FFI_LIB define" , filename );
5026
+ zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', bad %s define" , filename , target_name );
5027
5027
}
5028
5028
return NULL ;
5029
5029
}
5030
5030
p ++ ;
5031
- if (* lib ) {
5031
+ if (* target ) {
5032
5032
if (preload ) {
5033
- zend_error (E_WARNING , "FFI: failed pre-loading '%s', FFI_LIB defined twice" , filename );
5033
+ zend_error (E_WARNING , "FFI: failed pre-loading '%s', %s defined twice" , filename , target_name );
5034
5034
} else {
5035
- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', FFI_LIB defined twice" , filename );
5035
+ zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', %s defined twice" , filename , target_name );
5036
5036
}
5037
5037
return NULL ;
5038
5038
}
5039
- * lib = p ;
5039
+ * target = p ;
5040
5040
while (1 ) {
5041
5041
if (* p == '\"' ) {
5042
5042
* p = 0 ;
5043
5043
p ++ ;
5044
5044
break ;
5045
5045
} else if (* p <= ' ' ) {
5046
5046
if (preload ) {
5047
- zend_error (E_WARNING , "FFI: failed pre-loading '%s', bad FFI_LIB define" , filename );
5047
+ zend_error (E_WARNING , "FFI: failed pre-loading '%s', bad %s define" , filename , target_name );
5048
5048
} else {
5049
- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', bad FFI_LIB define" , filename );
5049
+ zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', bad %s define" , filename , target_name );
5050
5050
}
5051
5051
return NULL ;
5052
5052
}
5053
5053
p ++ ;
5054
5054
}
5055
- while (* p == ' ' || * p == '\t' ) {
5056
- p ++ ;
5057
- }
5058
- while (* p == '\r' || * p == '\n' ) {
5059
- p ++ ;
5060
- }
5061
- code_pos = p ;
5055
+
5056
+ code_pos = zend_ffi_skip_ws_and_comments (p , true);
5062
5057
} else {
5063
5058
break ;
5064
5059
}
0 commit comments