Skip to content

Instantly share code, notes, and snippets.

@markzz
Last active July 4, 2016 15:29
Show Gist options
  • Save markzz/d657e9a0b565877715c638729245bd6e to your computer and use it in GitHub Desktop.
Save markzz/d657e9a0b565877715c638729245bd6e to your computer and use it in GitHub Desktop.
PHP_METHOD(Handle, get_array_of_something) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
RETURN_NULL()
}
handle_object *intern = Z_HANDLEO_P(getThis());
alpm_list_t *list = some_alpm_function(intern->handle);
if (list == NULL) {
RETURN_NULL()
}
zval array;
alpm_list_to_zval(list, &array);
RETURN_ZVAL(array, 0, 0)
}
#include "util.h"
void alpm_list_to_zval(alpm_list_t *list, zval *array) {
alpm_list_t *item;
char *tmp;
array_init(array);
for (item = list; item; item = alpm_list_next(item)) {
tmp = malloc(sizeof(char) * strlen((char *)item->data));
strcpy(tmp, (char *)item->data);
add_next_index_string(array, tmp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment