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