Last active
July 4, 2016 15:29
-
-
Save markzz/d657e9a0b565877715c638729245bd6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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