Index: pjproject/trunk/pjlib/src/pj/pool.c
===================================================================
--- pjproject/trunk/pjlib/src/pj/pool.c	(revision 3081)
+++ pjproject/trunk/pjlib/src/pj/pool.c	(revision 3082)
@@ -32,5 +32,6 @@
 #endif
 
-#define LOG(expr)   PJ_LOG(6,expr)
+#define LOG(expr)   			PJ_LOG(6,expr)
+#define ALIGN_PTR(PTR,ALIGNMENT)	(PTR + (-(long)(PTR) & (ALIGNMENT-1)))
 
 PJ_DEF_DATA(int) PJ_NO_MEMORY_EXCEPTION;
@@ -72,7 +73,5 @@
 
     /* Set the start pointer, aligning it as needed */
-    block->cur = (unsigned char*)
-                 (((unsigned long)block->buf + PJ_POOL_ALIGNMENT - 1) & 
-                  ~(PJ_POOL_ALIGNMENT - 1));
+    block->cur = ALIGN_PTR(block->buf, PJ_POOL_ALIGNMENT);
 
     /* Insert in the front of the list. */
@@ -217,7 +216,5 @@
 
     /* Set the start pointer, aligning it as needed */
-    block->cur = (unsigned char*)
-                 (((unsigned long)block->buf + PJ_POOL_ALIGNMENT - 1) &
-                  ~(PJ_POOL_ALIGNMENT - 1));
+    block->cur = ALIGN_PTR(block->buf, PJ_POOL_ALIGNMENT);
 
     pj_list_insert_after(&pool->block_list, block);
@@ -263,7 +260,5 @@
 
     /* Set the start pointer, aligning it as needed */
-    block->cur = (unsigned char*)
-                 (((unsigned long)block->buf + PJ_POOL_ALIGNMENT - 1) &
-                  ~(PJ_POOL_ALIGNMENT - 1));
+    block->cur = ALIGN_PTR(block->buf, PJ_POOL_ALIGNMENT);
 
     pool->capacity = block->end - (unsigned char*)pool;
Index: pjproject/trunk/pjlib/src/pjlib-test/pool.c
===================================================================
--- pjproject/trunk/pjlib/src/pjlib-test/pool.c	(revision 3081)
+++ pjproject/trunk/pjlib/src/pjlib-test/pool.c	(revision 3082)
@@ -85,8 +85,10 @@
     pj_pool_t *pool;
     void *ptr;
+    enum { MEMSIZE = 64, LOOP = 100 };
+    unsigned i;
 
     PJ_LOG(3,("test", "...alignment test"));
 
-    pool = pj_pool_create(mem, NULL, PJ_POOL_SIZE+64, 64, NULL);
+    pool = pj_pool_create(mem, NULL, PJ_POOL_SIZE+MEMSIZE, MEMSIZE, NULL);
     if (!pool)
 	return -300;
@@ -94,40 +96,28 @@
 #define IS_ALIGNED(p)	((((unsigned long)p) & (PJ_POOL_ALIGNMENT-1)) == 0)
 
-    /* Test first allocation */
-    ptr = pj_pool_alloc(pool, 1);
-    if (!IS_ALIGNED(ptr)) {
-	pj_pool_release(pool);
-	return -310;
-    }
-
-    /* Test subsequent allocation */
-    ptr = pj_pool_alloc(pool, 1);
-    if (!IS_ALIGNED(ptr)) {
-	pj_pool_release(pool);
-	return -320;
-    }
-
-    /* Test allocation after new block is created */
-    ptr = pj_pool_alloc(pool, 127);
-    if (!IS_ALIGNED(ptr)) {
-	pj_pool_release(pool);
-	return -330;
-    }
-
-    /* Reset the pool */
-    pj_pool_reset(pool);
-
-    /* Retest first allocation */
-    ptr = pj_pool_alloc(pool, 1);
-    if (!IS_ALIGNED(ptr)) {
-	pj_pool_release(pool);
-	return -340;
-    }
-
-    /* Retest subsequent allocation */
-    ptr = pj_pool_alloc(pool, 1);
-    if (!IS_ALIGNED(ptr)) {
-	pj_pool_release(pool);
-	return -350;
+    for (i=0; i<LOOP; ++i) {
+	/* Test first allocation */
+	ptr = pj_pool_alloc(pool, 1);
+	if (!IS_ALIGNED(ptr)) {
+	    pj_pool_release(pool);
+	    return -310;
+	}
+
+	/* Test subsequent allocation */
+	ptr = pj_pool_alloc(pool, 1);
+	if (!IS_ALIGNED(ptr)) {
+	    pj_pool_release(pool);
+	    return -320;
+	}
+
+	/* Test allocation after new block is created */
+	ptr = pj_pool_alloc(pool, MEMSIZE*2+1);
+	if (!IS_ALIGNED(ptr)) {
+	    pj_pool_release(pool);
+	    return -330;
+	}
+
+	/* Reset the pool */
+	pj_pool_reset(pool);
     }
 
@@ -142,6 +132,8 @@
 {
     pj_pool_t *pool;
-    char buf[256];
+    char buf[512];
     void *ptr;
+    enum { LOOP = 100 };
+    unsigned i;
 
     PJ_LOG(3,("test", "...pool_buf alignment test"));
@@ -151,33 +143,21 @@
 	return -400;
 
-    /* Test first allocation */
-    ptr = pj_pool_alloc(pool, 1);
-    if (!IS_ALIGNED(ptr)) {
-	pj_pool_release(pool);
-	return -410;
-    }
-
-    /* Test subsequent allocation */
-    ptr = pj_pool_alloc(pool, 1);
-    if (!IS_ALIGNED(ptr)) {
-	pj_pool_release(pool);
-	return -420;
-    }
-
-    /* Reset the pool */
-    pj_pool_reset(pool);
-
-    /* Retest first allocation */
-    ptr = pj_pool_alloc(pool, 1);
-    if (!IS_ALIGNED(ptr)) {
-	pj_pool_release(pool);
-	return -430;
-    }
-
-    /* Retest subsequent allocation */
-    ptr = pj_pool_alloc(pool, 1);
-    if (!IS_ALIGNED(ptr)) {
-	pj_pool_release(pool);
-	return -440;
+    for (i=0; i<LOOP; ++i) {
+	/* Test first allocation */
+	ptr = pj_pool_alloc(pool, 1);
+	if (!IS_ALIGNED(ptr)) {
+	    pj_pool_release(pool);
+	    return -410;
+	}
+
+	/* Test subsequent allocation */
+	ptr = pj_pool_alloc(pool, 1);
+	if (!IS_ALIGNED(ptr)) {
+	    pj_pool_release(pool);
+	    return -420;
+	}
+
+	/* Reset the pool */
+	pj_pool_reset(pool);
     }
 
