Skip to content

Commit

Permalink
Support for __declspec(align(n))
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Dec 10, 2018
1 parent 6460922 commit 7c2fcf5
Show file tree
Hide file tree
Showing 5 changed files with 490 additions and 377 deletions.
15 changes: 15 additions & 0 deletions ffi.c
Expand Up @@ -5785,6 +5785,21 @@ void zend_ffi_add_attribute_value(zend_ffi_dcl *dcl, const char *name, size_t na
}
/* }}} */

void zend_ffi_add_msvc_attribute_value(zend_ffi_dcl *dcl, const char *name, size_t name_len, zend_ffi_val *val) /* {{{ */
{
if (name_len == sizeof("align")-1 && memcmp(name, "align", sizeof("align")-1) == 0) {
if ((val->kind == ZEND_FFI_VAL_INT32 || val->kind == ZEND_FFI_VAL_UINT32 || val->kind == ZEND_FFI_VAL_INT64 || val->kind == ZEND_FFI_VAL_UINT64)
&& val->i64 > 0 && val->i64 <= 0x80000000 && (val->i64 & (val->i64 - 1)) == 0) {
dcl->align = val->i64;
} else {
zend_ffi_parser_error("incorrect 'alignemnt' value at line %d", FFI_G(line));
}
} else {
/* ignore */
}
}
/* }}} */

static int zend_ffi_nested_type(zend_ffi_type *type, zend_ffi_type *nested_type) /* {{{ */
{
nested_type = ZEND_FFI_TYPE(nested_type);
Expand Down
14 changes: 14 additions & 0 deletions ffi.g
Expand Up @@ -465,6 +465,9 @@ type_name(zend_ffi_dcl *dcl):
;

attributes(zend_ffi_dcl *dcl):
{const char *name;}
{size_t name_len;}
{zend_ffi_val val;}
(
("__attribute"|"__attribute__")
"("
Expand All @@ -475,6 +478,17 @@ attributes(zend_ffi_dcl *dcl):
)*
")"
")"
| "__declspec"
"("
( ID(&name, &name_len)
(
"("
assignment_expression(&val)
{zend_ffi_add_msvc_attribute_value(dcl, name, name_len, &val);}
")"
)?
)+
")"
)++
;

Expand Down

0 comments on commit 7c2fcf5

Please sign in to comment.