Branch: Tag:

2003-10-07

2003-10-07 16:21:01 by Martin Stjernholm <mast@lysator.liu.se>

Fixed some races if Image.Font.load() is called in several threads.
(Probably not a serious bug since Image.TTF or Image.FreeType mostly is used
instead of these bitmapped fonts.) The bug did not affect use of the builtin
font.

Rev: src/modules/Image/font.c:1.80

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: font.c,v 1.79 2003/03/26 14:15:41 mast Exp $ + || $Id: font.c,v 1.80 2003/10/07 16:21:01 mast Exp $   */      #include "global.h"
341:    size = (size_t) file_size(fd);    if (size > 0)    { -  new_font=THIS=(struct font *)xalloc(sizeof(struct font)); +  new_font=(struct font *)xalloc(sizeof(struct font));       THREADS_ALLOW();   #ifdef HAVE_MMAP
371:   #endif    THREADS_DISALLOW();    +  if (THIS) +  /* In case font_load got called again in the THREADS_ALLOW block. */ +  free_font_struct(THIS); +  THIS = new_font; +    loading_default:       if (THIS->mem)
622:    {    case 0:    to_write0 = STR0(sp[j-args].u.string); -  THREADS_ALLOW(); +  /* THREADS_ALLOW(); */ +  /* Can't release the thread here; this would point to freed +  * memory if font_load got called. */    for (i = 0; i < to_write_len; i++)    {    c=*(to_write0++);
638:    xsize += char_space(this, c);    }    } -  THREADS_DISALLOW(); +  /* THREADS_DISALLOW(); */    break;    case 1:    to_write1 = STR1(sp[j-args].u.string); -  THREADS_ALLOW(); +  /* THREADS_ALLOW(); */    for (i = 0; i < to_write_len; i++)    {    c=*(to_write1++);
658:    xsize += char_space(this, c);    }    } -  THREADS_DISALLOW(); +  /* THREADS_DISALLOW(); */    break;    case 2:    to_write2 = STR2(sp[j-args].u.string); -  THREADS_ALLOW(); +  /* THREADS_ALLOW(); */    for (i = 0; i < to_write_len; i++)    {    c=*(to_write2++);
678:    xsize += char_space(this, c);    }    } -  THREADS_DISALLOW(); +  /* THREADS_DISALLOW(); */    break;    default:    Pike_fatal("Illegal shift size!\n");