X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=phpstr%2Fphpstr.h;h=5b2ee5664a09c75ee7cec172e5ed5adfc01bdb91;hp=40c59ed2c00325f68757c3a4fb4d5eec6037f347;hb=ffc893b125c6cc9b385a68a357b08ba2cc4e91f6;hpb=020d5b055921392c0dfb25043962a40867d8b033 diff --git a/phpstr/phpstr.h b/phpstr/phpstr.h index 40c59ed..5b2ee56 100644 --- a/phpstr/phpstr.h +++ b/phpstr/phpstr.h @@ -6,6 +6,18 @@ #include "php.h" +#ifndef PHPSTR_DEFAULT_SIZE +# define PHPSTR_DEFAULT_SIZE 256 +#endif + +#ifndef STR_SET +# define STR_SET(STR, SET) \ + { \ + STR_FREE(STR); \ + STR = SET; \ + } +#endif + #if defined(PHP_WIN32) # if defined(PHPSTR_EXPORTS) # define PHPSTR_API __declspec(dllexport) @@ -24,21 +36,26 @@ #define FREE_PHPSTR_PTR(STR) efree(STR) #define FREE_PHPSTR_VAL(STR) phpstr_dtor(STR) -#define FREE_PHPSTR_ALL(STR) phpstr_free(STR) +#define FREE_PHPSTR_ALL(STR) phpstr_free(&(STR)) #define FREE_PHPSTR(free, STR) \ switch (free) \ { \ + case PHPSTR_FREE_NOT: break; \ case PHPSTR_FREE_PTR: efree(STR); break; \ case PHPSTR_FREE_VAL: phpstr_dtor(STR); break; \ - case PHPSTR_FREE_ALL: phpstr_free(STR); break; \ - case PHPSTR_FREE_NOT: break; \ + case PHPSTR_FREE_ALL: \ + { \ + phpstr *PTR = (STR); \ + phpstr_free(&PTR); \ + } \ + break; \ default: break; \ } #define RETURN_PHPSTR_PTR(STR) RETURN_PHPSTR((STR), PHPSTR_FREE_PTR, 0) -#define RETURN_PHPSTR_VAL(STR) RETURN_PHPSTR(&(STR), PHPSTR_FREE_NOT, 0) +#define RETURN_PHPSTR_VAL(STR) RETURN_PHPSTR((STR), PHPSTR_FREE_NOT, 0) #define RETVAL_PHPSTR_PTR(STR) RETVAL_PHPSTR((STR), PHPSTR_FREE_PTR, 0) -#define RETVAL_PHPSTR_VAL(STR) RETVAL_PHPSTR(&(STR), PHPSTR_FREE_NOT, 0) +#define RETVAL_PHPSTR_VAL(STR) RETVAL_PHPSTR((STR), PHPSTR_FREE_NOT, 0) /* RETURN_PHPSTR(buf, PHPSTR_FREE_PTR, 0) */ #define RETURN_PHPSTR(STR, free, dup) \ RETVAL_PHPSTR((STR), (free), (dup)); \ @@ -136,7 +153,7 @@ PHPSTR_API void phpstr_fix(phpstr *buf); PHPSTR_API void phpstr_dtor(phpstr *buf); /* free a phpstr object completely */ -PHPSTR_API void phpstr_free(phpstr *buf); +PHPSTR_API void phpstr_free(phpstr **buf); #endif