Commit 516006ad 516006adffa6bf5cad7625a4eaf6edda3adb2d44 by Sergey Poznyakoff

(sieve_machine_init): Fixed return value.

(sieve_machine_add_destructor,sieve_machine_destroy): New functions.
1 parent d60f602a
...@@ -349,7 +349,7 @@ sieve_machine_init (sieve_machine_t *pmach, void *data) ...@@ -349,7 +349,7 @@ sieve_machine_init (sieve_machine_t *pmach, void *data)
349 if (rc) 349 if (rc)
350 { 350 {
351 free (mach); 351 free (mach);
352 return NULL; 352 return 1;
353 } 353 }
354 list_append (mach->memory_pool, mach); 354 list_append (mach->memory_pool, mach);
355 355
...@@ -404,6 +404,47 @@ sieve_get_ticket (sieve_machine_t mach) ...@@ -404,6 +404,47 @@ sieve_get_ticket (sieve_machine_t mach)
404 return mach->ticket; 404 return mach->ticket;
405 } 405 }
406 406
407 struct sieve_destr_record
408 {
409 sieve_destructor_t destr;
410 void *ptr;
411 };
412
413 int
414 sieve_machine_add_destructor (sieve_machine_t mach, sieve_destructor_t destr,
415 void *ptr)
416 {
417 struct sieve_destr_record *p;
418
419 if (!mach->destr_list && list_create (&mach->destr_list))
420 return 1;
421 p = sieve_palloc (&mach->memory_pool, sizeof (*p));
422 if (!p)
423 return 1;
424 p->destr = destr;
425 p->ptr = ptr;
426 return list_append (mach->memory_pool, p);
427 }
428
429 static int
430 _run_destructor (void *data, void *unused)
431 {
432 struct sieve_destr_record *p = data;
433 p->destr (p->ptr);
434 return 0;
435 }
436
437 void
438 sieve_machine_destroy (sieve_machine_t *pmach)
439 {
440 sieve_machine_t mach = *pmach;
441 list_do (mach->destr_list, _run_destructor, NULL);
442 list_destroy (&mach->destr_list);
443 sieve_slist_destroy (&mach->memory_pool);
444 free (mach);
445 *pmach = NULL;
446 }
447
407 /* FIXME: When posix thread support is added, sieve_machine_begin() should 448 /* FIXME: When posix thread support is added, sieve_machine_begin() should
408 acquire the global mutex, locking the current compilation session, and 449 acquire the global mutex, locking the current compilation session, and
409 sieve_machine_finish() should release it */ 450 sieve_machine_finish() should release it */
......