mirror of
https://github.com/php/php-src.git
synced 2024-11-24 02:15:04 +08:00
phpng support for ext/enchant
This commit is contained in:
parent
41336194b5
commit
0c27dedb6a
@ -40,16 +40,14 @@ typedef struct _broker_struct {
|
||||
EnchantBroker *pbroker;
|
||||
enchant_dict **dict;
|
||||
unsigned int dictcnt;
|
||||
long rsrc_id;
|
||||
zend_resource *rsrc;
|
||||
} _enchant_broker;
|
||||
|
||||
typedef struct _dict_struct {
|
||||
unsigned int id;
|
||||
EnchantDict *pdict;
|
||||
enchant_broker *pbroker;
|
||||
long rsrc_id;
|
||||
enchant_dict *next;
|
||||
enchant_dict *prev;
|
||||
zend_resource *rsrc;
|
||||
} _enchant_dict;
|
||||
|
||||
|
||||
@ -181,20 +179,19 @@ enumerate_providers_fn (const char * const name,
|
||||
void * ud) /* {{{ */
|
||||
{
|
||||
zval *zdesc = (zval *) ud;
|
||||
zval *tmp_array;
|
||||
zval tmp_array;
|
||||
|
||||
MAKE_STD_ZVAL(tmp_array);
|
||||
array_init(tmp_array);
|
||||
array_init(&tmp_array);
|
||||
|
||||
add_assoc_string(tmp_array, "name", (char *)name);
|
||||
add_assoc_string(tmp_array, "desc", (char *)desc);
|
||||
add_assoc_string(tmp_array, "file", (char *)file);
|
||||
add_assoc_string(&tmp_array, "name", (char *)name);
|
||||
add_assoc_string(&tmp_array, "desc", (char *)desc);
|
||||
add_assoc_string(&tmp_array, "file", (char *)file);
|
||||
|
||||
if (Z_TYPE_P(zdesc)!=IS_ARRAY) {
|
||||
array_init(zdesc);
|
||||
}
|
||||
|
||||
add_next_index_zval(zdesc, tmp_array);
|
||||
add_next_index_zval(zdesc, &tmp_array);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -219,24 +216,23 @@ static void php_enchant_list_dicts_fn( const char * const lang_tag,
|
||||
const char * const provider_file, void * ud) /* {{{ */
|
||||
{
|
||||
zval *zdesc = (zval *) ud;
|
||||
zval *tmp_array;
|
||||
zval tmp_array;
|
||||
|
||||
MAKE_STD_ZVAL(tmp_array);
|
||||
array_init(tmp_array);
|
||||
add_assoc_string(tmp_array, "lang_tag", (char *)lang_tag);
|
||||
add_assoc_string(tmp_array, "provider_name", (char *)provider_name);
|
||||
add_assoc_string(tmp_array, "provider_desc", (char *)provider_desc);
|
||||
add_assoc_string(tmp_array, "provider_file", (char *)provider_file);
|
||||
array_init(&tmp_array);
|
||||
add_assoc_string(&tmp_array, "lang_tag", (char *)lang_tag);
|
||||
add_assoc_string(&tmp_array, "provider_name", (char *)provider_name);
|
||||
add_assoc_string(&tmp_array, "provider_desc", (char *)provider_desc);
|
||||
add_assoc_string(&tmp_array, "provider_file", (char *)provider_file);
|
||||
|
||||
if (Z_TYPE_P(zdesc) != IS_ARRAY) {
|
||||
array_init(zdesc);
|
||||
}
|
||||
add_next_index_zval(zdesc, tmp_array);
|
||||
add_next_index_zval(zdesc, &tmp_array);
|
||||
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void php_enchant_broker_free(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
|
||||
static void php_enchant_broker_free(zend_resource *rsrc TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
if (rsrc->ptr) {
|
||||
enchant_broker *broker = (enchant_broker *)rsrc->ptr;
|
||||
@ -247,8 +243,12 @@ static void php_enchant_broker_free(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{
|
||||
int total;
|
||||
total = broker->dictcnt-1;
|
||||
do {
|
||||
zend_list_delete(broker->dict[total]->rsrc_id);
|
||||
efree(broker->dict[total]);
|
||||
if (broker->dict[total]) {
|
||||
enchant_dict *pdict = broker->dict[total];
|
||||
broker->dict[total] = NULL;
|
||||
zend_list_free(pdict->rsrc);
|
||||
efree(pdict);
|
||||
}
|
||||
total--;
|
||||
} while (total>=0);
|
||||
}
|
||||
@ -263,20 +263,21 @@ static void php_enchant_broker_free(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void php_enchant_dict_free(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
|
||||
static void php_enchant_dict_free(zend_resource *rsrc TSRMLS_DC) /* {{{ */
|
||||
|
||||
{
|
||||
if (rsrc->ptr) {
|
||||
enchant_dict *pdict = (enchant_dict *)rsrc->ptr;
|
||||
if (pdict) {
|
||||
if (pdict->pdict && pdict->pbroker) {
|
||||
enchant_broker_free_dict(pdict->pbroker->pbroker, pdict->pdict);
|
||||
if (pdict->id) {
|
||||
pdict->pbroker->dict[pdict->id-1]->next = NULL;
|
||||
}
|
||||
zend_list_delete(pdict->pbroker->rsrc_id);
|
||||
enchant_broker *pbroker = pdict->pbroker;
|
||||
|
||||
if (pdict->pdict && pbroker) {
|
||||
enchant_broker_free_dict(pbroker->pbroker, pdict->pdict);
|
||||
}
|
||||
|
||||
pbroker->dict[pdict->id] = NULL;
|
||||
efree(pdict);
|
||||
zend_list_delete(pbroker->rsrc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -337,14 +338,14 @@ PHP_MINFO_FUNCTION(enchant)
|
||||
/* }}} */
|
||||
|
||||
#define PHP_ENCHANT_GET_BROKER \
|
||||
ZEND_FETCH_RESOURCE(pbroker, enchant_broker *, &broker, -1, "enchant_broker", le_enchant_broker); \
|
||||
ZEND_FETCH_RESOURCE(pbroker, enchant_broker *, broker, -1, "enchant_broker", le_enchant_broker); \
|
||||
if (!pbroker || !pbroker->pbroker) { \
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", "Resource broker invalid"); \
|
||||
RETURN_FALSE; \
|
||||
}
|
||||
|
||||
#define PHP_ENCHANT_GET_DICT \
|
||||
ZEND_FETCH_RESOURCE(pdict, enchant_dict *, &dict, -1, "enchant_dict", le_enchant_dict); \
|
||||
ZEND_FETCH_RESOURCE(pdict, enchant_dict *, dict, -1, "enchant_dict", le_enchant_dict); \
|
||||
if (!pdict || !pdict->pdict) { \
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", "Invalid dictionary resource."); \
|
||||
RETURN_FALSE; \
|
||||
@ -368,7 +369,7 @@ PHP_FUNCTION(enchant_broker_init)
|
||||
broker->pbroker = pbroker;
|
||||
broker->dict = NULL;
|
||||
broker->dictcnt = 0;
|
||||
broker->rsrc_id = ZEND_REGISTER_RESOURCE(return_value, broker, le_enchant_broker);
|
||||
broker->rsrc = ZEND_REGISTER_RESOURCE(return_value, broker, le_enchant_broker);
|
||||
} else {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
@ -387,7 +388,7 @@ PHP_FUNCTION(enchant_broker_free)
|
||||
}
|
||||
PHP_ENCHANT_GET_BROKER;
|
||||
|
||||
zend_list_delete(Z_RESVAL_P(broker));
|
||||
zend_list_close(Z_RES_P(broker));
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
@ -408,7 +409,7 @@ PHP_FUNCTION(enchant_broker_get_error)
|
||||
|
||||
msg = enchant_broker_get_error(pbroker->pbroker);
|
||||
if (msg) {
|
||||
RETURN_STRING((char *)msg, 1);
|
||||
RETURN_STRING((char *)msg);
|
||||
}
|
||||
RETURN_FALSE;
|
||||
}
|
||||
@ -563,16 +564,10 @@ PHP_FUNCTION(enchant_broker_request_dict)
|
||||
dict->id = pos;
|
||||
dict->pbroker = pbroker;
|
||||
dict->pdict = d;
|
||||
dict->prev = pos ? pbroker->dict[pos-1] : NULL;
|
||||
dict->next = NULL;
|
||||
pbroker->dict[pos] = dict;
|
||||
|
||||
if (pos) {
|
||||
pbroker->dict[pos-1]->next = dict;
|
||||
}
|
||||
|
||||
dict->rsrc_id = ZEND_REGISTER_RESOURCE(return_value, dict, le_enchant_dict);
|
||||
zend_list_addref(pbroker->rsrc_id);
|
||||
dict->rsrc = ZEND_REGISTER_RESOURCE(return_value, dict, le_enchant_dict);
|
||||
pbroker->rsrc->gc.refcount++;
|
||||
} else {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
@ -619,13 +614,10 @@ PHP_FUNCTION(enchant_broker_request_pwl_dict)
|
||||
dict->id = pos;
|
||||
dict->pbroker = pbroker;
|
||||
dict->pdict = d;
|
||||
dict->prev = pos?pbroker->dict[pos-1]:NULL;
|
||||
dict->next = NULL;
|
||||
pbroker->dict[pos] = dict;
|
||||
if (pos) {
|
||||
pbroker->dict[pos-1]->next = dict;
|
||||
}
|
||||
dict->rsrc_id = ZEND_REGISTER_RESOURCE(return_value, dict, le_enchant_dict);
|
||||
|
||||
dict->rsrc = ZEND_REGISTER_RESOURCE(return_value, dict, le_enchant_dict);
|
||||
pbroker->rsrc->gc.refcount++;
|
||||
} else {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
@ -645,7 +637,7 @@ PHP_FUNCTION(enchant_broker_free_dict)
|
||||
|
||||
PHP_ENCHANT_GET_DICT;
|
||||
|
||||
zend_list_delete(Z_RESVAL_P(dict));
|
||||
zend_list_close(Z_RES_P(dict));
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
@ -909,7 +901,7 @@ PHP_FUNCTION(enchant_dict_get_error)
|
||||
|
||||
msg = enchant_dict_get_error(pdict->pdict);
|
||||
if (msg) {
|
||||
RETURN_STRING((char *)msg, 1);
|
||||
RETURN_STRING((char *)msg);
|
||||
}
|
||||
|
||||
RETURN_FALSE;
|
||||
|
Loading…
Reference in New Issue
Block a user