@@ -94,7 +94,7 @@ static int sizeStopList(StopList *list, char *stopFile);
9494static Size
9595max_ispell_mem_size ()
9696{
97- return (Size )max_ispell_mem_size_kb * 1024L ;
97+ return (Size )max_ispell_mem_size_kb * 1024L ;
9898}
9999
100100/*
@@ -134,11 +134,11 @@ _PG_init(void)
134134 */
135135RequestAddinShmemSpace (max_ispell_mem_size ());
136136
137- #if PG_VERSION_NUM >=90600
137+ #if PG_VERSION_NUM >=90600
138138RequestNamedLWLockTranche ("shared_ispell" ,1 );
139- #else
139+ #else
140140RequestAddinLWLocks (1 );
141- #endif
141+ #endif
142142
143143/* Install hooks. */
144144prev_shmem_startup_hook = shmem_startup_hook ;
@@ -166,8 +166,8 @@ _PG_fini(void)
166166static void
167167ispell_shmem_startup ()
168168{
169- bool found = false;
170- char * segment ;
169+ bool found = false;
170+ char * segment ;
171171
172172if (prev_shmem_startup_hook )
173173prev_shmem_startup_hook ();
@@ -191,8 +191,8 @@ ispell_shmem_startup()
191191segment_info -> lock = LWLockAssign ();
192192#endif
193193segment_info -> firstfree = segment + MAXALIGN (sizeof (SegmentInfo ));
194- segment_info -> available = max_ispell_mem_size ()
195- - (int )(segment_info -> firstfree - segment );
194+ segment_info -> available = max_ispell_mem_size ()-
195+ (int ) (segment_info -> firstfree - segment );
196196
197197segment_info -> lastReset = GetCurrentTimestamp ();
198198}
@@ -311,7 +311,7 @@ init_shared_dict(DictInfo *info, MemoryContext infoCntx,
311311/* load the dictionary (word list) if not yet defined */
312312if (shdict == NULL )
313313{
314- IspellDict * dict ;
314+ IspellDict * dict ;
315315
316316dict = (IspellDict * )palloc0 (sizeof (IspellDict ));
317317
@@ -422,14 +422,6 @@ init_shared_dict(DictInfo *info, MemoryContext infoCntx,
422422info -> infoCntx = infoCntx ;
423423}
424424
425- Datum dispell_init (PG_FUNCTION_ARGS );
426- Datum dispell_lexize (PG_FUNCTION_ARGS );
427- Datum dispell_reset (PG_FUNCTION_ARGS );
428- Datum dispell_mem_available (PG_FUNCTION_ARGS );
429- Datum dispell_mem_used (PG_FUNCTION_ARGS );
430- Datum dispell_list_dicts (PG_FUNCTION_ARGS );
431- Datum dispell_list_stoplists (PG_FUNCTION_ARGS );
432-
433425PG_FUNCTION_INFO_V1 (dispell_init );
434426PG_FUNCTION_INFO_V1 (dispell_lexize );
435427PG_FUNCTION_INFO_V1 (dispell_reset );
@@ -453,7 +445,8 @@ dispell_reset(PG_FUNCTION_ARGS)
453445segment_info -> shstop = NULL ;
454446segment_info -> lastReset = GetCurrentTimestamp ();
455447segment_info -> firstfree = ((char * )segment_info )+ MAXALIGN (sizeof (SegmentInfo ));
456- segment_info -> available = max_ispell_mem_size ()- (int )(segment_info -> firstfree - (char * )segment_info );
448+ segment_info -> available = max_ispell_mem_size ()-
449+ (int ) (segment_info -> firstfree - (char * )segment_info );
457450
458451memset (segment_info -> firstfree ,0 ,segment_info -> available );
459452
@@ -479,12 +472,14 @@ dispell_mem_available(PG_FUNCTION_ARGS)
479472}
480473
481474/*
482- * Returns amount of 'occupied space' in the shared segment (used by current dictionaries).
475+ * Returns amount of 'occupied space' in the shared segment (used by current
476+ * dictionaries).
483477 */
484478Datum
485479dispell_mem_used (PG_FUNCTION_ARGS )
486480{
487- int result = 0 ;
481+ int result = 0 ;
482+
488483LWLockAcquire (segment_info -> lock ,LW_SHARED );
489484
490485result = max_ispell_mem_size ()- segment_info -> available ;
@@ -679,7 +674,8 @@ dispell_lexize(PG_FUNCTION_ARGS)
679674static char *
680675shalloc (int bytes )
681676{
682- char * result ;
677+ char * result ;
678+
683679bytes = MAXALIGN (bytes );
684680
685681/* This shouldn't really happen, as the init_shared_dict checks the size
@@ -706,8 +702,10 @@ shalloc(int bytes)
706702static char *
707703shstrcpy (char * str )
708704{
709- char * tmp = shalloc (strlen (str )+ 1 );
705+ char * tmp = shalloc (strlen (str )+ 1 );
706+
710707memcpy (tmp ,str ,strlen (str )+ 1 );
708+
711709return tmp ;
712710}
713711
@@ -801,8 +799,7 @@ sizeStopList(StopList *list, char *stopFile)
801799static SharedIspellDict *
802800copyIspellDict (IspellDict * dict ,char * dictFile ,char * affixFile ,int size ,int words )
803801{
804- int i ;
805-
802+ int i ;
806803SharedIspellDict * copy = (SharedIspellDict * )shalloc (sizeof (SharedIspellDict ));
807804
808805copy -> dictFile = shalloc (strlen (dictFile )+ 1 );
@@ -834,8 +831,8 @@ copyIspellDict(IspellDict *dict, char *dictFile, char *affixFile, int size, int
834831static int
835832sizeIspellDict (IspellDict * dict ,char * dictFile ,char * affixFile )
836833{
837- int i ;
838- int size = MAXALIGN (sizeof (SharedIspellDict ));
834+ int i ;
835+ int size = MAXALIGN (sizeof (SharedIspellDict ));
839836
840837size += MAXALIGN (strlen (dictFile )+ 1 );
841838size += MAXALIGN (strlen (affixFile )+ 1 );