CVS update: php3
| From: | zeev | Date: | Sat, 17 Oct 1998 18:17:28 +0000 |
| Subject: | CVS update: php3 | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-1862@lists.php.net to get a copy of this message | ||
Date: Saturday October 17, 1998 @ 14:17
Author: zeev
Update of /repository/php3
In directory asf:/u2/tmp/cvs-serv13287
Modified Files:
ChangeLog alloc.c language-scanner.lex main.c token_cache.c
token_cache.h
Log Message:
* Handle out of memory errors
* Optimize and stablize token cache code - should now handle extreme cases
Index: php3/ChangeLog
diff -c php3/ChangeLog:1.512 php3/ChangeLog:1.513
*** php3/ChangeLog:1.512 Mon Oct 12 19:55:01 1998
--- php3/ChangeLog Sat Oct 17 14:17:26 1998
***************
*** 1,11 ****
! 'PHP 3.0 CHANGE LOG ChangeLog
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
??, Version 3.0.6
- Unterimated comments in include files were being reported with the wrong line
number. Fixed.
- Added ImageCopy() and ImageColorDeallocate(). ImageCopy() is about
20% faster than ImageCopyResized(). ImageColorDeallocate() marks
! palette entries free for reuse. <mka@satama.com>
- In the CGI version, it was impossible to access resources (e.g. SQL links,
images) from user-defined shutdown functions. Fixed.
- Added optional third parameter to strpos() to specify the offset to
--- 1,14 ----
! PHP 3.0 CHANGE LOG ChangeLog
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
??, Version 3.0.6
+ - Optimized parts of the token cache code.
+ - Terminate on out-of-memory errors. Until now, PHP could crash in our of
+ memory situations (clean-up, no real effect).
- Unterimated comments in include files were being reported with the wrong line
number. Fixed.
- Added ImageCopy() and ImageColorDeallocate(). ImageCopy() is about
20% faster than ImageCopyResized(). ImageColorDeallocate() marks
! palette entries free for reuse (by <mka@satama.com>).
- In the CGI version, it was impossible to access resources (e.g. SQL links,
images) from user-defined shutdown functions. Fixed.
- Added optional third parameter to strpos() to specify the offset to
Index: php3/alloc.c
diff -c php3/alloc.c:1.71 php3/alloc.c:1.72
*** php3/alloc.c:1.71 Fri May 29 12:25:35 1998
--- php3/alloc.c Sat Oct 17 14:17:26 1998
***************
*** 126,131 ****
--- 126,133 ----
}
if (!p) {
+ fprintf(stderr,"FATAL: emalloc(): Unable to allocate %d bytes\n", size);
+ exit(1);
UNBLOCK_INTERRUPTIONS;
return (void *)p;
}
***************
*** 220,225 ****
--- 222,229 ----
REMOVE_POINTER_FROM_LIST(p);
p = (mem_header *) realloc(p,sizeof(mem_header)+size+PLATFORM_PADDING);
if (!p) {
+ fprintf(stderr,"FATAL: erealloc(): Unable to allocate %d bytes\n", size);
+ exit(1);
orig->pNext = GLOBAL(head);
if (GLOBAL(head)) {
GLOBAL(head)->pLast = orig;
Index: php3/language-scanner.lex
diff -c php3/language-scanner.lex:1.175 php3/language-scanner.lex:1.176
*** php3/language-scanner.lex:1.175 Mon Oct 12 19:55:01 1998
--- php3/language-scanner.lex Sat Oct 17 14:17:26 1998
***************
*** 184,190 ****
yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
BEGIN(INITIAL);
GLOBAL(include_count)++;
! GLOBAL(phplineno)=1+MAX_TOKENS_PER_CACHE*GLOBAL(include_count);
filename = estrndup(file->value.str.val,file->value.str.len);
_php3_hash_index_update(&GLOBAL(include_names),GLOBAL(include_count),(void *)
&filename,sizeof(char *),NULL);
--- 184,190 ----
yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
BEGIN(INITIAL);
GLOBAL(include_count)++;
! GLOBAL(phplineno) = 1 + (GLOBAL(include_count)<<TOKEN_BITS);
filename = estrndup(file->value.str.val,file->value.str.len);
_php3_hash_index_update(&GLOBAL(include_names),GLOBAL(include_count),(void *)
&filename,sizeof(char *),NULL);
***************
*** 225,231 ****
yyin=NULL;
if (!display_source) {
! tcm_new(&GLOBAL(token_cache_manager));
} else {
if (display_source==2 && !pval_is_true(return_offset)) {
display_source=1;
--- 225,234 ----
yyin=NULL;
if (!display_source) {
! if (tcm_new(&GLOBAL(token_cache_manager),TOKEN_CACHE_EVAL_BLOCK_SIZE)==FAILURE) {
! php3_error(E_ERROR,"Unable to initialize a new token cache");
! return;
! }
} else {
if (display_source==2 && !pval_is_true(return_offset)) {
display_source=1;
***************
*** 278,289 ****
yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
BEGIN(INITIAL);
GLOBAL(include_count)++;
! GLOBAL(phplineno)=1+MAX_TOKENS_PER_CACHE*GLOBAL(include_count);
filename = file->value.str.val;
_php3_hash_index_update(&GLOBAL(include_names),GLOBAL(include_count),(void *)
&filename,sizeof(char *),NULL);
! tcm_new(&GLOBAL(token_cache_manager));
! return SUCCESS;
}
--- 281,296 ----
yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
BEGIN(INITIAL);
GLOBAL(include_count)++;
! GLOBAL(phplineno) = 1 + (GLOBAL(include_count)<<TOKEN_BITS);
filename = file->value.str.val;
_php3_hash_index_update(&GLOBAL(include_names),GLOBAL(include_count),(void *)
&filename,sizeof(char *),NULL);
! if (tcm_new(&GLOBAL(token_cache_manager),TOKEN_CACHE_INCLUDE_BLOCK_SIZE)==FAILURE) {
! php3_error(E_ERROR, "Unable to initialize a new token cache");
! return FAILURE;
! } else {
! return SUCCESS;
! }
}
Index: php3/main.c
diff -c php3/main.c:1.474 php3/main.c:1.475
*** php3/main.c:1.474 Mon Oct 12 19:55:01 1998
--- php3/main.c Sat Oct 17 14:17:27 1998
***************
*** 29,35 ****
+----------------------------------------------------------------------+
*/
! /* $Id: main.c,v 1.474 1998/10/12 23:55:01 zeev Exp $ */
/* #define CRASH_DETECTION */
--- 29,35 ----
+----------------------------------------------------------------------+
*/
! /* $Id: main.c,v 1.475 1998/10/17 18:17:27 zeev Exp $ */
/* #define CRASH_DETECTION */
***************
*** 145,157 ****
int php3_get_lineno(int lineno)
{
! return (lineno % MAX_TOKENS_PER_CACHE);
}
char *php3_get_filename(int lineno)
{
char **filename_ptr;
! int file_offset = lineno / MAX_TOKENS_PER_CACHE;
TLS_VARS;
if ((GLOBAL(initialized) & INIT_INCLUDE_NAMES_HASH) &&
_php3_hash_index_find(&GLOBAL(include_names), file_offset, (void **) &filename_ptr) ==
SUCCESS) {
--- 145,157 ----
int php3_get_lineno(int lineno)
{
! return LINE_OFFSET(lineno);
}
char *php3_get_filename(int lineno)
{
char **filename_ptr;
! int file_offset = FILE_OFFSET(lineno);
TLS_VARS;
if ((GLOBAL(initialized) & INIT_INCLUDE_NAMES_HASH) &&
_php3_hash_index_find(&GLOBAL(include_names), file_offset, (void **) &filename_ptr) ==
SUCCESS) {
***************
*** 384,391 ****
if (GLOBAL(debugger_on)) {
va_start(args, format);
vsnprintf(buffer, sizeof(buffer) - 1, format, args);
! php3_debugger_error(buffer, type, filename,
! GLOBAL(current_lineno) % MAX_TOKENS_PER_CACHE);
va_end(args);
}
#endif
--- 384,390 ----
if (GLOBAL(debugger_on)) {
va_start(args, format);
vsnprintf(buffer, sizeof(buffer) - 1, format, args);
! php3_debugger_error(buffer, type, filename, php3_get_lineno());
va_end(args);
}
#endif
Index: php3/token_cache.c
diff -c php3/token_cache.c:1.89 php3/token_cache.c:1.90
*** php3/token_cache.c:1.89 Thu Sep 10 19:56:57 1998
--- php3/token_cache.c Sat Oct 17 14:17:28 1998
***************
*** 29,35 ****
*/
! /* $Id: token_cache.c,v 1.89 1998/09/10 23:56:57 zeev Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
--- 29,35 ----
*/
! /* $Id: token_cache.c,v 1.90 1998/10/17 18:17:28 zeev Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
***************
*** 83,93 ****
/* prepare a new token cache */
! int tcm_new(TokenCacheManager *tcm)
{
TLS_VARS;
tcm->initialized++;
if (tcm->initialized >= tcm->max) {
tcm->token_caches = (TokenCache *) erealloc(tcm->token_caches, (tcm->max +
TOKEN_CACHES_BLOCK_SIZE) * sizeof(TokenCache));
if (!tcm->token_caches) {
--- 83,97 ----
/* prepare a new token cache */
! int tcm_new(TokenCacheManager *tcm, int block_size)
{
TLS_VARS;
+ if (tcm->initialized >= (1<<TC_BITS)) {
+ return FAILURE;
+ }
tcm->initialized++;
+ fprintf(stderr,"%d\n", tcm->initialized);
if (tcm->initialized >= tcm->max) {
tcm->token_caches = (TokenCache *) erealloc(tcm->token_caches, (tcm->max +
TOKEN_CACHES_BLOCK_SIZE) * sizeof(TokenCache));
if (!tcm->token_caches) {
***************
*** 96,102 ****
tcm->max += TOKEN_CACHES_BLOCK_SIZE;
}
tcm->active = tcm->initialized - 1;
! if (tc_init(&tcm->token_caches[tcm->active],TOKEN_CACHE_EVAL_BLOCK_SIZE) == FAILURE) {
return FAILURE;
}
GLOBAL(tc) = &tcm->token_caches[tcm->active];
--- 100,106 ----
tcm->max += TOKEN_CACHES_BLOCK_SIZE;
}
tcm->active = tcm->initialized - 1;
! if (tc_init(&tcm->token_caches[tcm->active],block_size) == FAILURE) {
return FAILURE;
}
GLOBAL(tc) = &tcm->token_caches[tcm->active];
***************
*** 150,156 ****
}
next_token.phplval = *phplval;
next_token.lineno = GLOBAL(phplineno);
! next_token.phplval.offset = tcm->active * MAX_TOKENS_PER_CACHE + GLOBAL(tc)->count;
/* ugly hack to support $keyword */
if (last_token_suggests_variable_reference() && is_reserved_word(next_token.token_type))
{
--- 154,160 ----
}
next_token.phplval = *phplval;
next_token.lineno = GLOBAL(phplineno);
! next_token.phplval.offset = (tcm->active<<TOKEN_BITS) + GLOBAL(tc)->count;
/* ugly hack to support $keyword */
if (last_token_suggests_variable_reference() && is_reserved_word(next_token.token_type))
{
***************
*** 181,192 ****
TLS_VARS;
clear_lookahead(yychar);
- tc_offset = token_number / MAX_TOKENS_PER_CACHE;
if (tc_offset >= tcm->initialized) {
return FAILURE;
}
! t_offset = token_number % MAX_TOKENS_PER_CACHE;
if (t_offset > tcm->token_caches[tc_offset].count) {
return FAILURE;
}
--- 185,198 ----
TLS_VARS;
clear_lookahead(yychar);
+
+
+ tc_offset = TC_OFFSET(token_number);
if (tc_offset >= tcm->initialized) {
return FAILURE;
}
! t_offset = TOKEN_OFFSET(token_number);
if (t_offset > tcm->token_caches[tc_offset].count) {
return FAILURE;
}
***************
*** 200,214 ****
/* switch tokens between start to middle-1, and middle+1 to end */
int tc_switch(TokenCacheManager *tcm, int start, int end, int middle)
{
! int active = start/MAX_TOKENS_PER_CACHE;
TokenCache *tc = &tcm->token_caches[active];
Token *temp_tokens, middle_token;
int first_chunk, second_chunk, i;
! start %= MAX_TOKENS_PER_CACHE;
! end %= MAX_TOKENS_PER_CACHE;
! middle %= MAX_TOKENS_PER_CACHE;
if (start < 0 || end >= tc->count || middle < start || middle > end) {
return FAILURE;
--- 206,220 ----
/* switch tokens between start to middle-1, and middle+1 to end */
int tc_switch(TokenCacheManager *tcm, int start, int end, int middle)
{
! int active = TC_OFFSET(start);
TokenCache *tc = &tcm->token_caches[active];
Token *temp_tokens, middle_token;
int first_chunk, second_chunk, i;
! start = TOKEN_OFFSET(start);
! end = TOKEN_OFFSET(end);
! middle = TOKEN_OFFSET(middle);
if (start < 0 || end >= tc->count || middle < start || middle > end) {
return FAILURE;
***************
*** 239,245 ****
tc->tokens[start + second_chunk] = middle_token;
for (i = start; i <= end; i++) {
! tc->tokens[i].phplval.offset = active * MAX_TOKENS_PER_CACHE + i;
}
return SUCCESS;
}
--- 245,251 ----
tc->tokens[start + second_chunk] = middle_token;
for (i = start; i <= end; i++) {
! tc->tokens[i].phplval.offset = (active<<TOKEN_BITS) + i;
}
return SUCCESS;
}
***************
*** 247,255 ****
inline int tc_set_token(TokenCacheManager *tcm, int offset, int type)
{
! TokenCache *tc = &tcm->token_caches[offset/MAX_TOKENS_PER_CACHE];
! offset %= MAX_TOKENS_PER_CACHE;
if (offset < 0 || offset >= tc->count) {
return FAILURE;
}
--- 253,261 ----
inline int tc_set_token(TokenCacheManager *tcm, int offset, int type)
{
! TokenCache *tc = &tcm->token_caches[TC_OFFSET(offset)];
! offset = TOKEN_OFFSET(offset);
if (offset < 0 || offset >= tc->count) {
return FAILURE;
}
***************
*** 261,269 ****
inline int tc_get_token(TokenCacheManager *tcm, int offset)
{
! TokenCache *tc = &tcm->token_caches[offset/MAX_TOKENS_PER_CACHE];
! offset %= MAX_TOKENS_PER_CACHE;
if (offset < 0 || offset >= tc->count) {
return FAILURE;
}
--- 267,275 ----
inline int tc_get_token(TokenCacheManager *tcm, int offset)
{
! TokenCache *tc = &tcm->token_caches[TC_OFFSET(offset)];
! offset = TOKEN_OFFSET(offset);
if (offset < 0 || offset >= tc->count) {
return FAILURE;
}
***************
*** 273,287 ****
int tc_get_current_offset(TokenCacheManager *tcm)
{
! return tcm->active * MAX_TOKENS_PER_CACHE + GLOBAL(tc)->pos;
}
inline int tc_set_switched(TokenCacheManager *tcm, int offset)
{
! TokenCache *tc = &tcm->token_caches[offset / MAX_TOKENS_PER_CACHE];
! offset %= MAX_TOKENS_PER_CACHE;
if (offset < 0 || offset >= tc->count) {
return FAILURE;
}
--- 279,293 ----
int tc_get_current_offset(TokenCacheManager *tcm)
{
! return (tcm->active<<TOKEN_BITS) + GLOBAL(tc)->pos;
}
inline int tc_set_switched(TokenCacheManager *tcm, int offset)
{
! TokenCache *tc = &tcm->token_caches[TC_OFFSET(offset)];
! offset = TOKEN_OFFSET(offset);
if (offset < 0 || offset >= tc->count) {
return FAILURE;
}
***************
*** 293,301 ****
inline int tc_set_included(TokenCacheManager *tcm, int offset)
{
! TokenCache *tc = &tcm->token_caches[offset / MAX_TOKENS_PER_CACHE];
! offset %= MAX_TOKENS_PER_CACHE;
if (offset < 0 || offset >= tc->count) {
return FAILURE;
}
--- 299,307 ----
inline int tc_set_included(TokenCacheManager *tcm, int offset)
{
! TokenCache *tc = &tcm->token_caches[TC_OFFSET(offset)];
! offset = TOKEN_OFFSET(offset);
if (offset < 0 || offset >= tc->count) {
return FAILURE;
}
Index: php3/token_cache.h
diff -c php3/token_cache.h:1.32 php3/token_cache.h:1.33
*** php3/token_cache.h:1.32 Tue Jul 28 18:00:05 1998
--- php3/token_cache.h Sat Oct 17 14:17:28 1998
***************
*** 29,35 ****
*/
! /* $Id: token_cache.h,v 1.32 1998/07/28 22:00:05 rasmus Exp $ */
#ifndef _TOKEN_CACHE
--- 29,35 ----
*/
! /* $Id: token_cache.h,v 1.33 1998/10/17 18:17:28 zeev Exp $ */
#ifndef _TOKEN_CACHE
***************
*** 58,65 ****
#define TOKEN_CACHE_BLOCK_SIZE 8192
#define TOKEN_CACHE_EVAL_BLOCK_SIZE 32
#define TOKEN_CACHES_BLOCK_SIZE 4
! #define MAX_TOKENS_PER_CACHE 1048576
extern int tcm_init(TokenCacheManager *tcm);
extern int tc_init(TokenCache *tc,int block_size);
--- 58,74 ----
#define TOKEN_CACHE_BLOCK_SIZE 8192
#define TOKEN_CACHE_EVAL_BLOCK_SIZE 32
+ #define TOKEN_CACHE_INCLUDE_BLOCK_SIZE 512
+
#define TOKEN_CACHES_BLOCK_SIZE 4
!
! #define TOKEN_BITS 20
! #define TC_BITS ((sizeof(int))*8-TOKEN_BITS)
!
! #define TC_OFFSET(token_number) (token_number>>TOKEN_BITS)
! #define TOKEN_OFFSET(token_number) (token_number & ((1<<TOKEN_BITS)-1))
! #define FILE_OFFSET TC_OFFSET
! #define LINE_OFFSET TOKEN_OFFSET
extern int tcm_init(TokenCacheManager *tcm);
extern int tc_init(TokenCache *tc,int block_size);
***************
*** 75,81 ****
extern int tc_get_current_offset(TokenCacheManager *tcm);
extern int tc_destroy(TokenCache *tc);
extern void tcm_destroy(TokenCacheManager *tcm);
! extern int tcm_new(TokenCacheManager *tcm);
extern void tcm_save(TokenCacheManager *tcm);
#if FHTTPD
extern int tcm_load(TokenCacheManager *tcm, FILE *input);
--- 84,90 ----
extern int tc_get_current_offset(TokenCacheManager *tcm);
extern int tc_destroy(TokenCache *tc);
extern void tcm_destroy(TokenCacheManager *tcm);
! extern int tcm_new(TokenCacheManager *tcm, int block_size);
extern void tcm_save(TokenCacheManager *tcm);
#if FHTTPD
extern int tcm_load(TokenCacheManager *tcm, FILE *input);
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net