Skip to content

Commit bea4442

Browse files
chopinsdstogov
authored andcommitted
Added FFI\CType::getName() method
1 parent d2efb7e commit bea4442

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ PHP NEWS
1212
. Fixed bug #80057 (DateTimeImmutable::createFromFormat() does not populate
1313
time). (Derick)
1414

15+
- FFI:
16+
. Added FFI\CType::getName() method. (chopins)
17+
1518
03 Sep 2020, PHP 8.0.0beta3
1619

1720
- Calendar:

ext/ffi/ffi.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4427,6 +4427,26 @@ ZEND_METHOD(FFI, isNull) /* {{{ */
44274427
}
44284428
/* }}} */
44294429

4430+
4431+
ZEND_METHOD(CType, getName) /* {{{ */
4432+
{
4433+
zend_ffi_ctype *ctype = (zend_ffi_ctype*)(Z_OBJ_P(ZEND_THIS));
4434+
if (zend_parse_parameters_none() == FAILURE) {
4435+
RETURN_THROWS();
4436+
}
4437+
4438+
zend_ffi_ctype_name_buf buf;
4439+
4440+
buf.start = buf.end = buf.buf + ((MAX_TYPE_NAME_LEN * 3) / 4);
4441+
if (!zend_ffi_ctype_name(&buf, ZEND_FFI_TYPE(ctype->type))) {
4442+
RETURN_STR_COPY(Z_OBJ_P(ZEND_THIS)->ce->name);
4443+
} else {
4444+
size_t len = buf.end - buf.start;
4445+
zend_string *res = zend_string_init(buf.start, len, 0);
4446+
RETURN_STR(res);
4447+
}
4448+
}
4449+
44304450
static char *zend_ffi_parse_directives(const char *filename, char *code_pos, char **scope_name, char **lib, zend_bool preload) /* {{{ */
44314451
{
44324452
char *p;
@@ -4984,7 +5004,7 @@ ZEND_MINIT_FUNCTION(ffi)
49845004
zend_ffi_cdata_free_handlers.get_properties = zend_fake_get_properties;
49855005
zend_ffi_cdata_free_handlers.get_gc = zend_fake_get_gc;
49865006

4987-
INIT_NS_CLASS_ENTRY(ce, "FFI", "CType", NULL);
5007+
INIT_NS_CLASS_ENTRY(ce, "FFI", "CType", class_CType_methods);
49885008
zend_ffi_ctype_ce = zend_register_internal_class(&ce);
49895009
zend_ffi_ctype_ce->ce_flags |= ZEND_ACC_FINAL;
49905010
zend_ffi_ctype_ce->create_object = zend_ffi_ctype_new;
@@ -5004,7 +5024,7 @@ ZEND_MINIT_FUNCTION(ffi)
50045024
zend_ffi_ctype_handlers.unset_property = zend_fake_unset_property;
50055025
zend_ffi_ctype_handlers.has_dimension = zend_fake_has_dimension;
50065026
zend_ffi_ctype_handlers.unset_dimension = zend_fake_unset_dimension;
5007-
zend_ffi_ctype_handlers.get_method = zend_fake_get_method;
5027+
//zend_ffi_ctype_handlers.get_method = zend_fake_get_method;
50085028
zend_ffi_ctype_handlers.get_class_name = zend_ffi_ctype_get_class_name;
50095029
zend_ffi_ctype_handlers.compare = zend_ffi_ctype_compare_objects;
50105030
zend_ffi_ctype_handlers.cast_object = zend_fake_cast_object;

ext/ffi/ffi.stub.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,7 @@ public static function string(FFI\CData $ptr, ?int $size = null): ?string {}
6161
/** @prefer-ref $ptr */
6262
public static function isNull(FFI\CData $ptr): bool {}
6363
}
64+
65+
final class CType {
66+
public function getName() : string {}
67+
}

ext/ffi/ffi_arginfo.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: c5ad08a2c62988e2b50468c1c5b941b5c28f23b5 */
2+
* Stub hash: cf08aabbc0e1c50204772ace9285f1c5ef7a22fe */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_cdef, 0, 0, FFI, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, code, IS_STRING, 0, "\"\"")
@@ -79,6 +79,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_FFI_isNull, 0, 1, _IS_BOOL
7979
ZEND_ARG_OBJ_INFO(ZEND_SEND_PREFER_REF, ptr, FFI\\CData, 0)
8080
ZEND_END_ARG_INFO()
8181

82+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_CType_getName, 0, 0, IS_STRING, 0)
83+
ZEND_END_ARG_INFO()
84+
8285

8386
ZEND_METHOD(FFI, cdef);
8487
ZEND_METHOD(FFI, load);
@@ -97,6 +100,7 @@ ZEND_METHOD(FFI, memcmp);
97100
ZEND_METHOD(FFI, memset);
98101
ZEND_METHOD(FFI, string);
99102
ZEND_METHOD(FFI, isNull);
103+
ZEND_METHOD(CType, getName);
100104

101105

102106
static const zend_function_entry class_FFI_methods[] = {
@@ -119,3 +123,9 @@ static const zend_function_entry class_FFI_methods[] = {
119123
ZEND_ME(FFI, isNull, arginfo_class_FFI_isNull, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
120124
ZEND_FE_END
121125
};
126+
127+
128+
static const zend_function_entry class_CType_methods[] = {
129+
ZEND_ME(CType, getName, arginfo_class_CType_getName, ZEND_ACC_PUBLIC)
130+
ZEND_FE_END
131+
};

0 commit comments

Comments
 (0)