@@ -4995,107 +4995,102 @@ ZEND_METHOD(FFI_CType, getFuncParameterType) /* {{{ */
4995
4995
}
4996
4996
/* }}} */
4997
4997
4998
+ static char * zend_ffi_skip_ws_and_comments (char * p , bool allow_standalone_newline )
4999
+ {
5000
+ while (true) {
5001
+ if (* p == ' ' || * p == '\t' ) {
5002
+ p ++ ;
5003
+ } else if (allow_standalone_newline && (* p == '\r' || * p == '\n' || * p == '\f' || * p == '\v' )) {
5004
+ p ++ ;
5005
+ } else if (allow_standalone_newline && * p == '/' && p [1 ] == '/' ) {
5006
+ p += 2 ;
5007
+ while (* p && * p != '\r' && * p != '\n' ) {
5008
+ p ++ ;
5009
+ }
5010
+ } else if (* p == '/' && p [1 ] == '*' ) {
5011
+ p += 2 ;
5012
+ while (* p && (* p != '*' || p [1 ] != '/' )) {
5013
+ p ++ ;
5014
+ }
5015
+ if (* p == '*' ) {
5016
+ p ++ ;
5017
+ if (* p == '/' ) {
5018
+ p ++ ;
5019
+ }
5020
+ }
5021
+ } else {
5022
+ break ;
5023
+ }
5024
+ }
5025
+
5026
+ return p ;
5027
+ }
5028
+
4998
5029
static char * zend_ffi_parse_directives (const char * filename , char * code_pos , char * * scope_name , char * * lib , bool preload ) /* {{{ */
4999
5030
{
5000
5031
char * p ;
5001
5032
5033
+ code_pos = zend_ffi_skip_ws_and_comments (code_pos , true);
5034
+
5002
5035
* scope_name = NULL ;
5003
5036
* lib = NULL ;
5004
5037
while (* code_pos == '#' ) {
5005
- if (strncmp (code_pos , "#define FFI_SCOPE" , sizeof ("#define FFI_SCOPE" ) - 1 ) == 0
5006
- && (code_pos [sizeof ("#define FFI_SCOPE" ) - 1 ] == ' '
5007
- || code_pos [sizeof ("#define FFI_SCOPE" ) - 1 ] == '\t' )) {
5008
- p = code_pos + sizeof ("#define FFI_SCOPE" );
5009
- while (* p == ' ' || * p == '\t' ) {
5010
- p ++ ;
5011
- }
5012
- if (* p != '"' ) {
5013
- if (preload ) {
5014
- zend_error (E_WARNING , "FFI: failed pre-loading '%s', bad FFI_SCOPE define" , filename );
5015
- } else {
5016
- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', bad FFI_SCOPE define" , filename );
5017
- }
5018
- return NULL ;
5019
- }
5020
- p ++ ;
5021
- if (* scope_name ) {
5022
- if (preload ) {
5023
- zend_error (E_WARNING , "FFI: failed pre-loading '%s', FFI_SCOPE defined twice" , filename );
5024
- } else {
5025
- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', FFI_SCOPE defined twice" , filename );
5026
- }
5027
- return NULL ;
5028
- }
5029
- * scope_name = p ;
5030
- while (1 ) {
5031
- if (* p == '\"' ) {
5032
- * p = 0 ;
5038
+ if (strncmp (code_pos , ZEND_STRL ("#define" )) == 0 ) {
5039
+ p = zend_ffi_skip_ws_and_comments (code_pos + sizeof ("#define" ) - 1 , false);
5040
+
5041
+ char * * target = NULL ;
5042
+ const char * target_name = NULL ;
5043
+ if (strncmp (p , ZEND_STRL ("FFI_SCOPE" )) == 0 ) {
5044
+ p = zend_ffi_skip_ws_and_comments (p + sizeof ("FFI_SCOPE" ) - 1 , false);
5045
+ target = scope_name ;
5046
+ target_name = "FFI_SCOPE" ;
5047
+ } else if (strncmp (p , ZEND_STRL ("FFI_LIB" )) == 0 ) {
5048
+ p = zend_ffi_skip_ws_and_comments (p + sizeof ("FFI_LIB" ) - 1 , false);
5049
+ target = lib ;
5050
+ target_name = "FFI_LIB" ;
5051
+ } else {
5052
+ while (* p && * p != '\n' && * p != '\r' ) {
5033
5053
p ++ ;
5034
- break ;
5035
- } else if (* p <= ' ' ) {
5036
- if (preload ) {
5037
- zend_error (E_WARNING , "FFI: failed pre-loading '%s', bad FFI_SCOPE define" , filename );
5038
- } else {
5039
- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', bad FFI_SCOPE define" , filename );
5040
- }
5041
- return NULL ;
5042
5054
}
5043
- p ++ ;
5044
- }
5045
- while (* p == ' ' || * p == '\t' ) {
5046
- p ++ ;
5047
- }
5048
- while (* p == '\r' || * p == '\n' ) {
5049
- p ++ ;
5050
- }
5051
- code_pos = p ;
5052
- } else if (strncmp (code_pos , "#define FFI_LIB" , sizeof ("#define FFI_LIB" ) - 1 ) == 0
5053
- && (code_pos [sizeof ("#define FFI_LIB" ) - 1 ] == ' '
5054
- || code_pos [sizeof ("#define FFI_LIB" ) - 1 ] == '\t' )) {
5055
- p = code_pos + sizeof ("#define FFI_LIB" );
5056
- while (* p == ' ' || * p == '\t' ) {
5057
- p ++ ;
5055
+ code_pos = zend_ffi_skip_ws_and_comments (p , true);
5056
+ continue ;
5058
5057
}
5058
+
5059
5059
if (* p != '"' ) {
5060
5060
if (preload ) {
5061
- zend_error (E_WARNING , "FFI: failed pre-loading '%s', bad FFI_LIB define" , filename );
5061
+ zend_error (E_WARNING , "FFI: failed pre-loading '%s', bad %s define" , filename , target_name );
5062
5062
} else {
5063
- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', bad FFI_LIB define" , filename );
5063
+ zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', bad %s define" , filename , target_name );
5064
5064
}
5065
5065
return NULL ;
5066
5066
}
5067
5067
p ++ ;
5068
- if (* lib ) {
5068
+ if (* target ) {
5069
5069
if (preload ) {
5070
- zend_error (E_WARNING , "FFI: failed pre-loading '%s', FFI_LIB defined twice" , filename );
5070
+ zend_error (E_WARNING , "FFI: failed pre-loading '%s', %s defined twice" , filename , target_name );
5071
5071
} else {
5072
- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', FFI_LIB defined twice" , filename );
5072
+ zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', %s defined twice" , filename , target_name );
5073
5073
}
5074
5074
return NULL ;
5075
5075
}
5076
- * lib = p ;
5076
+ * target = p ;
5077
5077
while (1 ) {
5078
5078
if (* p == '\"' ) {
5079
5079
* p = 0 ;
5080
5080
p ++ ;
5081
5081
break ;
5082
5082
} else if (* p <= ' ' ) {
5083
5083
if (preload ) {
5084
- zend_error (E_WARNING , "FFI: failed pre-loading '%s', bad FFI_LIB define" , filename );
5084
+ zend_error (E_WARNING , "FFI: failed pre-loading '%s', bad %s define" , filename , target_name );
5085
5085
} else {
5086
- zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', bad FFI_LIB define" , filename );
5086
+ zend_throw_error (zend_ffi_exception_ce , "Failed loading '%s', bad %s define" , filename , target_name );
5087
5087
}
5088
5088
return NULL ;
5089
5089
}
5090
5090
p ++ ;
5091
5091
}
5092
- while (* p == ' ' || * p == '\t' ) {
5093
- p ++ ;
5094
- }
5095
- while (* p == '\r' || * p == '\n' ) {
5096
- p ++ ;
5097
- }
5098
- code_pos = p ;
5092
+
5093
+ code_pos = zend_ffi_skip_ws_and_comments (p , true);
5099
5094
} else {
5100
5095
break ;
5101
5096
}
0 commit comments