HUGE changeset to make the rest of the libraries compile with C++ mode

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1266 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/src/pj/except.c b/pjlib/src/pj/except.c
index 3b7e981..006671e 100644
--- a/pjlib/src/pj/except.c
+++ b/pjlib/src/pj/except.c
@@ -41,7 +41,8 @@
 {
     struct pj_exception_state_t *handler;
 
-    handler = pj_thread_local_get(thread_local_id);
+    handler = (struct pj_exception_state_t*) 
+	      pj_thread_local_get(thread_local_id);
     if (handler == NULL) {
         PJ_LOG(1,("except.c", "!!!FATAL: unhandled exception %s!\n", 
 		   pj_exception_id_name(exception_id)));
@@ -78,7 +79,8 @@
 	pj_assert(thread_local_id != -1);
 	pj_atexit(&exception_cleanup);
     }
-    parent_handler = pj_thread_local_get(thread_local_id);
+    parent_handler = (struct pj_exception_state_t *)
+		      pj_thread_local_get(thread_local_id);
     rec->prev = parent_handler;
     pj_thread_local_set(thread_local_id, rec);
 }
@@ -87,7 +89,8 @@
 {
     struct pj_exception_state_t *handler;
 
-    handler = pj_thread_local_get(thread_local_id);
+    handler = (struct pj_exception_state_t *)
+	      pj_thread_local_get(thread_local_id);
     pj_assert(handler != NULL);
     pj_thread_local_set(thread_local_id, handler->prev);
 }
diff --git a/pjlib/src/pj/ioqueue_common_abs.c b/pjlib/src/pj/ioqueue_common_abs.c
index 82f962c..8fd1be7 100644
--- a/pjlib/src/pj/ioqueue_common_abs.c
+++ b/pjlib/src/pj/ioqueue_common_abs.c
@@ -301,7 +301,7 @@
 	    //write_op->op = 0;
         } else {
             pj_assert(!"Invalid operation type!");
-	    write_op->op = 0;
+	    write_op->op = PJ_IOQUEUE_OP_NONE;
             send_rc = PJ_EBUG;
         }
 
@@ -318,7 +318,7 @@
             h->fd_type == PJ_SOCK_DGRAM) 
         {
 
-	    write_op->op = 0;
+	    write_op->op = PJ_IOQUEUE_OP_NONE;
 
             if (h->fd_type != PJ_SOCK_DGRAM) {
                 /* Write completion of the whole stream. */
@@ -375,7 +375,7 @@
         /* Get one accept operation from the list. */
 	accept_op = h->accept_list.next;
         pj_list_erase(accept_op);
-        accept_op->op = 0;
+        accept_op->op = PJ_IOQUEUE_OP_NONE;
 
 	/* Clear bit in fdset if there is no more pending accept */
         if (pj_list_empty(&h->accept_list))
@@ -417,18 +417,18 @@
         bytes_read = read_op->size;
 
 	if ((read_op->op == PJ_IOQUEUE_OP_RECV_FROM)) {
-	    read_op->op = 0;
+	    read_op->op = PJ_IOQUEUE_OP_NONE;
 	    rc = pj_sock_recvfrom(h->fd, read_op->buf, &bytes_read, 
 				  read_op->flags,
 				  read_op->rmt_addr, 
                                   read_op->rmt_addrlen);
 	} else if ((read_op->op == PJ_IOQUEUE_OP_RECV)) {
-	    read_op->op = 0;
+	    read_op->op = PJ_IOQUEUE_OP_NONE;
 	    rc = pj_sock_recv(h->fd, read_op->buf, &bytes_read, 
 			      read_op->flags);
         } else {
             pj_assert(read_op->op == PJ_IOQUEUE_OP_READ);
-	    read_op->op = 0;
+	    read_op->op = PJ_IOQUEUE_OP_NONE;
             /*
              * User has specified pj_ioqueue_read().
              * On Win32, we should do ReadFile(). But because we got
@@ -561,7 +561,7 @@
     PJ_CHECK_STACK();
 
     read_op = (struct read_operation*)op_key;
-    read_op->op = 0;
+    read_op->op = PJ_IOQUEUE_OP_NONE;
 
     /* Check if key is closing. */
     if (IS_CLOSING(key))
@@ -630,7 +630,7 @@
 	return PJ_ECANCELLED;
 
     read_op = (struct read_operation*)op_key;
-    read_op->op = 0;
+    read_op->op = PJ_IOQUEUE_OP_NONE;
 
     /* Try to see if there's data immediately available. 
      */
@@ -768,7 +768,7 @@
     }
 
     write_op->op = PJ_IOQUEUE_OP_SEND;
-    write_op->buf = (void*)data;
+    write_op->buf = (char*)data;
     write_op->size = *length;
     write_op->written = 0;
     write_op->flags = flags;
@@ -848,7 +848,7 @@
     /*
      * Check that address storage can hold the address parameter.
      */
-    PJ_ASSERT_RETURN(addrlen <= sizeof(pj_sockaddr_in), PJ_EBUG);
+    PJ_ASSERT_RETURN(addrlen <= (int)sizeof(pj_sockaddr_in), PJ_EBUG);
 
     /*
      * Schedule asynchronous send.
@@ -883,7 +883,7 @@
     }
 
     write_op->op = PJ_IOQUEUE_OP_SEND_TO;
-    write_op->buf = (void*)data;
+    write_op->buf = (char*)data;
     write_op->size = *length;
     write_op->written = 0;
     write_op->flags = flags;
@@ -920,7 +920,7 @@
 	return PJ_ECANCELLED;
 
     accept_op = (struct accept_operation*)op_key;
-    accept_op->op = 0;
+    accept_op->op = PJ_IOQUEUE_OP_NONE;
 
     /* Fast track:
      *  See if there's new connection available immediately.
@@ -1052,7 +1052,7 @@
     while (op_rec != (void*)&key->read_list) {
         if (op_rec == (void*)op_key) {
             pj_list_erase(op_rec);
-            op_rec->op = 0;
+            op_rec->op = PJ_IOQUEUE_OP_NONE;
             pj_mutex_unlock(key->mutex);
 
             (*key->cb.on_read_complete)(key, op_key, bytes_status);
@@ -1066,7 +1066,7 @@
     while (op_rec != (void*)&key->write_list) {
         if (op_rec == (void*)op_key) {
             pj_list_erase(op_rec);
-            op_rec->op = 0;
+            op_rec->op = PJ_IOQUEUE_OP_NONE;
             pj_mutex_unlock(key->mutex);
 
             (*key->cb.on_write_complete)(key, op_key, bytes_status);
@@ -1080,7 +1080,7 @@
     while (op_rec != (void*)&key->accept_list) {
         if (op_rec == (void*)op_key) {
             pj_list_erase(op_rec);
-            op_rec->op = 0;
+            op_rec->op = PJ_IOQUEUE_OP_NONE;
             pj_mutex_unlock(key->mutex);
 
             (*key->cb.on_accept_complete)(key, op_key, 
diff --git a/pjlib/src/pj/ioqueue_select.c b/pjlib/src/pj/ioqueue_select.c
index f5e3690..e200d64 100644
--- a/pjlib/src/pj/ioqueue_select.c
+++ b/pjlib/src/pj/ioqueue_select.c
@@ -193,7 +193,7 @@
                      sizeof(union operation_key), PJ_EBUG);
 
     /* Create and init common ioqueue stuffs */
-    ioqueue = pj_pool_alloc(pool, sizeof(pj_ioqueue_t));
+    ioqueue = PJ_POOL_ALLOC_T(pool, pj_ioqueue_t);
     ioqueue_init(ioqueue);
 
     ioqueue->max = max_fd;
@@ -230,7 +230,7 @@
     for (i=0; i<max_fd; ++i) {
 	pj_ioqueue_key_t *key;
 
-	key = pj_pool_alloc(pool, sizeof(pj_ioqueue_key_t));
+	key = PJ_POOL_ALLOC_T(pool, pj_ioqueue_key_t);
 	key->ref_count = 0;
 	rc = pj_mutex_create_recursive(pool, NULL, &key->mutex);
 	if (rc != PJ_SUCCESS) {
diff --git a/pjlib/src/pj/log.c b/pjlib/src/pj/log.c
index bc39554..518854c 100644
--- a/pjlib/src/pj/log.c
+++ b/pjlib/src/pj/log.c
@@ -146,7 +146,7 @@
 				     "<logging error: msg too long>");
     }
     len = len + print_len;
-    if (len > 0 && len < sizeof(log_buffer)-2) {
+    if (len > 0 && len < (int)sizeof(log_buffer)-2) {
 	if (log_decor & PJ_LOG_HAS_CR) {
 	    log_buffer[len++] = '\r';
 	}
diff --git a/pjlib/src/pj/os_core_unix.c b/pjlib/src/pj/os_core_unix.c
index 2528694..33a8a85 100644
--- a/pjlib/src/pj/os_core_unix.c
+++ b/pjlib/src/pj/os_core_unix.c
@@ -21,7 +21,9 @@
  * - Thanks for Zetron, Inc. (Phil Torre, ptorre@zetron.com) for donating
  *   the RTEMS port.
  */
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#   define _GNU_SOURCE
+#endif
 #include <pj/os.h>
 #include <pj/assert.h>
 #include <pj/pool.h>
@@ -339,7 +341,7 @@
  */
 static void *thread_main(void *param)
 {
-    pj_thread_t *rec = param;
+    pj_thread_t *rec = (pj_thread_t*)param;
     void *result;
     pj_status_t rc;
 
@@ -506,7 +508,7 @@
 PJ_DEF(pj_thread_t*) pj_thread_this(void)
 {
 #if PJ_HAS_THREADS
-    pj_thread_t *rec = pj_thread_local_get(thread_tls_id);
+    pj_thread_t *rec = (pj_thread_t*)pj_thread_local_get(thread_tls_id);
     
     if (rec == NULL) {
 	pj_assert(!"Calling pjlib from unknown/external thread. You must "
@@ -663,7 +665,10 @@
 				      pj_atomic_t **ptr_atomic)
 {
     pj_status_t rc;
-    pj_atomic_t *atomic_var = pj_pool_calloc(pool, 1, sizeof(pj_atomic_t));
+    pj_atomic_t *atomic_var;
+
+    atomic_var = PJ_POOL_ZALLOC_T(pool, pj_atomic_t);
+
     PJ_ASSERT_RETURN(atomic_var, PJ_ENOMEM);
     
 #if PJ_HAS_THREADS
@@ -907,6 +912,12 @@
 
 
 ///////////////////////////////////////////////////////////////////////////////
+#if defined(PJ_LINUX) && PJ_LINUX!=0
+PJ_BEGIN_DECL
+PJ_DECL(int) pthread_mutexattr_settype(pthread_mutexattr_t*,int);
+PJ_END_DECL
+#endif
+
 static pj_status_t init_mutex(pj_mutex_t *mutex, const char *name, int type)
 {
 #if PJ_HAS_THREADS
@@ -921,7 +932,6 @@
 
     if (type == PJ_MUTEX_SIMPLE) {
 #if defined(PJ_LINUX) && PJ_LINUX!=0
-	extern int pthread_mutexattr_settype(pthread_mutexattr_t*,int);
 	rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_FAST_NP);
 #elif defined(PJ_RTEMS) && PJ_RTEMS!=0
 	/* Nothing to do, default is simple */
@@ -930,7 +940,6 @@
 #endif
     } else {
 #if defined(PJ_LINUX) && PJ_LINUX!=0
-	extern int pthread_mutexattr_settype(pthread_mutexattr_t*,int);
 	rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
 #elif defined(PJ_RTEMS) && PJ_RTEMS!=0
 	// Phil Torre <ptorre@zetron.com>:
@@ -991,7 +1000,7 @@
 
     PJ_ASSERT_RETURN(pool && ptr_mutex, PJ_EINVAL);
 
-    mutex = pj_pool_alloc(pool, sizeof(*mutex));
+    mutex = PJ_POOL_ALLOC_T(pool, pj_mutex_t);
     PJ_ASSERT_RETURN(mutex, PJ_ENOMEM);
 
     if ((rc=init_mutex(mutex, name, type)) != PJ_SUCCESS)
@@ -1228,7 +1237,7 @@
 
     PJ_UNUSED_ARG(name);
     
-    rwm = pj_pool_alloc(pool, sizeof(pj_rwmutex_t));
+    rwm = PJ_POOL_ALLOC_T(pool, pj_rwmutex_t);
     PJ_ASSERT_RETURN(rwm, PJ_ENOMEM);
 
     status = pthread_rwlock_init(&rwm->rwlock, NULL);
@@ -1329,7 +1338,7 @@
     PJ_CHECK_STACK();
     PJ_ASSERT_RETURN(pool != NULL && ptr_sem != NULL, PJ_EINVAL);
 
-    sem = pj_pool_alloc(pool, sizeof(*sem));
+    sem = PJ_POOL_ALLOC_T(pool, pj_sem_t);
     PJ_ASSERT_RETURN(sem, PJ_ENOMEM);
 
     if (sem_init( &sem->sem, 0, initial) != 0) 
diff --git a/pjlib/src/pj/os_error_unix.c b/pjlib/src/pj/os_error_unix.c
index d3cfe14..3d4b526 100644
--- a/pjlib/src/pj/os_error_unix.c
+++ b/pjlib/src/pj/os_error_unix.c
@@ -40,6 +40,12 @@
     errno = PJ_STATUS_TO_OS(code);
 }
 
+PJ_BEGIN_DECL
+
+    PJ_DECL(int) platform_strerror(pj_os_err_type code, 
+                              	   char *buf, pj_size_t bufsize );
+PJ_END_DECL
+
 /* 
  * platform_strerror()
  *
diff --git a/pjlib/src/pj/sock_bsd.c b/pjlib/src/pj/sock_bsd.c
index 8fc4f70..3e39335 100644
--- a/pjlib/src/pj/sock_bsd.c
+++ b/pjlib/src/pj/sock_bsd.c
@@ -385,7 +385,7 @@
 {
     PJ_CHECK_STACK();
 
-    PJ_ASSERT_RETURN(addr && len >= sizeof(struct sockaddr_in), PJ_EINVAL);
+    PJ_ASSERT_RETURN(addr && len >= (int)sizeof(struct sockaddr_in), PJ_EINVAL);
 
     if (bind(sock, (struct sockaddr*)addr, len) != 0)
 	return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());