diff options
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-02a | 15 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-03a | 15 | ||||
-rw-r--r-- | ace/ACE.cpp | 46 | ||||
-rw-r--r-- | ace/ACE.h | 5 | ||||
-rw-r--r-- | ace/ACE.i | 32 | ||||
-rw-r--r-- | ace/OS_Memory.cpp | 30 | ||||
-rw-r--r-- | ace/OS_Memory.inl | 30 | ||||
-rw-r--r-- | tests/DLL_Test.cpp | 24 | ||||
-rw-r--r-- | tests/DLL_Test.h | 14 | ||||
-rw-r--r-- | tests/DLL_Test_Impl.cpp | 13 | ||||
-rw-r--r-- | tests/DLL_Test_Impl.h | 6 |
12 files changed, 171 insertions, 74 deletions
diff --git a/ChangeLog b/ChangeLog index 6456cf989fa..bdcc3441449 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +Sat Apr 13 15:42:03 UTC 2002 Don Hinton <dhinton@ieee.org> + + * tests/DLL_Test.{h,cpp}: + * tests/DLL_Test_Impl.{h,cpp}: Added methods to test the + the malloc/free and strnew/strdelete methods below. Also + removed use auto_ptr and added a destroy method to delete + the object within the dll/heap it was allocated. + + * ace/OS_Memory.{inl,cpp}: Changed malloc(), calloc() + realloc(), and free() to be non-inlined to avoid the heap + problem on Windows. + + * ace/ACE.{h,i,cpp}: Changed strnew() to be non-inlined and + added strdelete() for the same reason. + Sat Apr 13 14:33:12 2002 Johnny Willemsen <jwillemsen@remedy.nl> * ace/Configuration.h: diff --git a/ChangeLogs/ChangeLog-02a b/ChangeLogs/ChangeLog-02a index 6456cf989fa..bdcc3441449 100644 --- a/ChangeLogs/ChangeLog-02a +++ b/ChangeLogs/ChangeLog-02a @@ -1,3 +1,18 @@ +Sat Apr 13 15:42:03 UTC 2002 Don Hinton <dhinton@ieee.org> + + * tests/DLL_Test.{h,cpp}: + * tests/DLL_Test_Impl.{h,cpp}: Added methods to test the + the malloc/free and strnew/strdelete methods below. Also + removed use auto_ptr and added a destroy method to delete + the object within the dll/heap it was allocated. + + * ace/OS_Memory.{inl,cpp}: Changed malloc(), calloc() + realloc(), and free() to be non-inlined to avoid the heap + problem on Windows. + + * ace/ACE.{h,i,cpp}: Changed strnew() to be non-inlined and + added strdelete() for the same reason. + Sat Apr 13 14:33:12 2002 Johnny Willemsen <jwillemsen@remedy.nl> * ace/Configuration.h: diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a index 6456cf989fa..bdcc3441449 100644 --- a/ChangeLogs/ChangeLog-03a +++ b/ChangeLogs/ChangeLog-03a @@ -1,3 +1,18 @@ +Sat Apr 13 15:42:03 UTC 2002 Don Hinton <dhinton@ieee.org> + + * tests/DLL_Test.{h,cpp}: + * tests/DLL_Test_Impl.{h,cpp}: Added methods to test the + the malloc/free and strnew/strdelete methods below. Also + removed use auto_ptr and added a destroy method to delete + the object within the dll/heap it was allocated. + + * ace/OS_Memory.{inl,cpp}: Changed malloc(), calloc() + realloc(), and free() to be non-inlined to avoid the heap + problem on Windows. + + * ace/ACE.{h,i,cpp}: Changed strnew() to be non-inlined and + added strdelete() for the same reason. + Sat Apr 13 14:33:12 2002 Johnny Willemsen <jwillemsen@remedy.nl> * ace/Configuration.h: diff --git a/ace/ACE.cpp b/ace/ACE.cpp index c8de70ad12f..79bb485bc3b 100644 --- a/ace/ACE.cpp +++ b/ace/ACE.cpp @@ -3366,6 +3366,52 @@ ACE::strend (const wchar_t *s) } #endif +char * +ACE::strnew (const char *s) +{ + if (s == 0) + return 0; + char *t = 0; + ACE_NEW_RETURN (t, + char [::strlen (s) + 1], + 0); + if (t == 0) + return 0; + else + return ACE_OS::strcpy (t, s); +} + +#if defined (ACE_HAS_WCHAR) +wchar_t * +ACE::strnew (const wchar_t *s) +{ + if (s == 0) + return 0; + wchar_t *t = 0; + ACE_NEW_RETURN (t, + wchar_t[ACE_OS_String::strlen (s) + 1], + 0); + if (t == 0) + return 0; + else + return ACE_OS::strcpy (t, s); +} +#endif /* ACE_HAS_WCHAR */ + +void +ACE::strdelete (char *s) +{ + delete [] s; +} + +#if defined (ACE_HAS_WCHAR) +void +ACE::strdelete (wchar_t *s) +{ + delete [] s; +} +#endif /* ACE_HAS_WCHAR */ + #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) && (defined (__unix) || defined (__unix__) || defined (__Lynx__) || defined (_AIX)) template class ACE_Auto_Array_Ptr<struct ifreq>; template class ACE_Auto_Basic_Array_Ptr<struct ifreq>; diff --git a/ace/ACE.h b/ace/ACE.h index 917e1c4e8cc..1948ef3f590 100644 --- a/ace/ACE.h +++ b/ace/ACE.h @@ -367,6 +367,9 @@ public: /// segfaulting... static char *strnew (const char *s); + /// Delete the memory allocated by <strnew>. + static void strdelete (char *s); + /// Create a fresh new copy of <str>, up to <n> chars long. Uses /// <ACE_OS::malloc> to allocate the new string. static char *strndup (const char *str, size_t n); @@ -380,6 +383,8 @@ public: static wchar_t *strnew (const wchar_t *s); + static void strdelete (wchar_t *s); + static wchar_t *strndup (const wchar_t *str, size_t n); static wchar_t *strnnew (const wchar_t *str, size_t n); diff --git a/ace/ACE.i b/ace/ACE.i index 094606deb93..189aa5d437d 100644 --- a/ace/ACE.i +++ b/ace/ACE.i @@ -310,35 +310,3 @@ ACE::debug (char c) { ACE::debug_ = c; } - -ASYS_INLINE char * -ACE::strnew (const char *s) -{ - if (s == 0) - return 0; - char *t = 0; - ACE_NEW_RETURN (t, - char [::strlen (s) + 1], - 0); - if (t == 0) - return 0; - else - return ACE_OS::strcpy (t, s); -} - -#if defined (ACE_HAS_WCHAR) -ASYS_INLINE wchar_t * -ACE::strnew (const wchar_t *s) -{ - if (s == 0) - return 0; - wchar_t *t = 0; - ACE_NEW_RETURN (t, - wchar_t[ACE_OS_String::strlen (s) + 1], - 0); - if (t == 0) - return 0; - else - return ACE_OS::strcpy (t, s); -} -#endif /* ACE_HAS_WCHAR */ diff --git a/ace/OS_Memory.cpp b/ace/OS_Memory.cpp index 5dae2c598a5..4dfea835b72 100644 --- a/ace/OS_Memory.cpp +++ b/ace/OS_Memory.cpp @@ -11,3 +11,33 @@ ACE_RCSID(ace, OS_Memory, "$Id$") static int shut_up_aCC = 0; #endif /* HPUX && !g++ */ #endif /* !ACE_HAS_INLINED_OS_CALLS */ + +void * +ACE_OS_Memory::malloc (size_t nbytes) +{ + return ACE_MALLOC_FUNC (nbytes); +} + +void * +ACE_OS_Memory::calloc (size_t elements, size_t sizeof_elements) +{ +#if !defined (ACE_HAS_WINCE) + return ACE_CALLOC_FUNC (elements, sizeof_elements); +#else + // @@ This will probably not work since it doesn't consider + // alignment properly. + return ACE_MALLOC_FUNC (elements * sizeof_elements); +#endif /* ACE_HAS_WINCE */ +} + +void * +ACE_OS_Memory::realloc (void *ptr, size_t nbytes) +{ + return ACE_REALLOC_FUNC (ACE_MALLOC_T (ptr), nbytes); +} + +void +ACE_OS_Memory::free (void *ptr) +{ + ACE_FREE_FUNC (ACE_MALLOC_T (ptr)); +} diff --git a/ace/OS_Memory.inl b/ace/OS_Memory.inl index 510a281346c..28a7c76bf74 100644 --- a/ace/OS_Memory.inl +++ b/ace/OS_Memory.inl @@ -18,33 +18,3 @@ ACE_OS_Memory::sbrk (int brk) ACE_OSCALL_RETURN (::sbrk (brk), void *, 0); #endif /* VXWORKS */ } - -ACE_INLINE void * -ACE_OS_Memory::malloc (size_t nbytes) -{ - return ACE_MALLOC_FUNC (nbytes); -} - -ACE_INLINE void * -ACE_OS_Memory::calloc (size_t elements, size_t sizeof_elements) -{ -#if !defined (ACE_HAS_WINCE) - return ACE_CALLOC_FUNC (elements, sizeof_elements); -#else - // @@ This will probably not work since it doesn't consider - // alignment properly. - return ACE_MALLOC_FUNC (elements * sizeof_elements); -#endif /* ACE_HAS_WINCE */ -} - -ACE_INLINE void * -ACE_OS_Memory::realloc (void *ptr, size_t nbytes) -{ - return ACE_REALLOC_FUNC (ACE_MALLOC_T (ptr), nbytes); -} - -ACE_INLINE void -ACE_OS_Memory::free (void *ptr) -{ - ACE_FREE_FUNC (ACE_MALLOC_T (ptr)); -} diff --git a/tests/DLL_Test.cpp b/tests/DLL_Test.cpp index 02381044d48..7619bd5bf54 100644 --- a/tests/DLL_Test.cpp +++ b/tests/DLL_Test.cpp @@ -19,7 +19,7 @@ #include "test_config.h" #include "DLL_Test.h" #include "ace/DLL.h" -#include "ace/Auto_Ptr.h" +#include "ace/ACE.h" ACE_RCSID(tests, DLL_Test, "$Id$") @@ -86,12 +86,24 @@ ACE_TMAIN (int, ACE_TCHAR *[]) dll.error ()), -1); - auto_ptr<Hello> my_hello (factory ()); + Hello *my_hello = factory (); // Make the method calls, as the object pointer is available. my_hello->say_hello (); my_hello->say_next (); + // Allocate and delete a string allocated via new in a different dll. + ACE_TCHAR *new_str = my_hello->new_info (); + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Result for new_info(): %s\n"), new_str)); + ACE::strdelete (new_str); + + // Allocate and free a string allocated via malloc in a different dll. + ACE_TCHAR *malloc_str = my_hello->malloc_info (); + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Result for malloc_info(): %s\n"), malloc_str)); + ACE_OS_Memory::free (malloc_str); + + my_hello->destroy (); + #else ACE_ERROR ((LM_INFO, ACE_TEXT ("Dynamically Linkable Libraries not supported on this platform\n"))); @@ -100,11 +112,3 @@ ACE_TMAIN (int, ACE_TCHAR *[]) ACE_END_TEST; return 0; } - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class auto_ptr <Hello>; -template class ACE_Auto_Basic_Ptr <Hello>; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate auto_ptr <Hello> -#pragma instantiate ACE_Auto_Basic_Ptr <Hello> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/tests/DLL_Test.h b/tests/DLL_Test.h index 160d09846ce..86ff15165be 100644 --- a/tests/DLL_Test.h +++ b/tests/DLL_Test.h @@ -31,8 +31,8 @@ public: /** * @name Methods invoked by the test * - * The test invokes two methods, a non-virtual method and a virtual - * method implemented in the shared library. + * The test invokes four methods, a non-virtual method and a three virtual + * methods implemented in the shared library. */ //@{ void say_hello (void) @@ -42,7 +42,17 @@ public: } virtual void say_next (void) = 0; + + virtual ACE_TCHAR *new_info (void) = 0; + + virtual ACE_TCHAR *malloc_info (void) = 0; //@} + + void destroy (void) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Hello::destroy() \n"))); + delete this; + } }; #endif /* ACE_TESTS_DLL_TEST_H */ diff --git a/tests/DLL_Test_Impl.cpp b/tests/DLL_Test_Impl.cpp index b9b5d50e4a8..9be1224df95 100644 --- a/tests/DLL_Test_Impl.cpp +++ b/tests/DLL_Test_Impl.cpp @@ -17,6 +17,7 @@ // ============================================================================ #include "DLL_Test_Impl.h" +#include "ace/ACE.h" #include "ace/OS_Errno.h" #include "ace/svc_export.h" @@ -41,6 +42,18 @@ Hello_Impl::say_next (void) ACE_TEXT ("How are you?\n"))); } +ACE_TCHAR * +Hello_Impl::new_info (void) +{ + return ACE::strnew (ACE_TEXT ("Hello_Impl::new_info() allocated by ACE::strnew()")); +} + +ACE_TCHAR * +Hello_Impl::malloc_info (void) +{ + return ACE_OS_String::strdup (ACE_TEXT ("Hello_Impl::new_info() allocated by ACE_OS_Memory::malloc()")); +} + extern "C" ACE_Svc_Export Hello * get_hello (void) { diff --git a/tests/DLL_Test_Impl.h b/tests/DLL_Test_Impl.h index 371a7871af8..21f3e2322f4 100644 --- a/tests/DLL_Test_Impl.h +++ b/tests/DLL_Test_Impl.h @@ -40,6 +40,12 @@ public: void say_next (void); // See the documentation in the base class + + ACE_TCHAR *new_info (void); + // Uses ACE::strnew() to allocate the returned string. + + ACE_TCHAR *malloc_info (void); + // Uses ACE_OS_Memory::malloc() to allocate the returned string. }; #endif /* ACE_TESTS_DLL_TEST_IMPL_H */ |