RE: Static Linked on Linux and Win32

2004-09-28 Thread David Barrett
Ok, with Dror's and William's help I'm up and running with APR.  Now, what
about static linking with APRICONV?

Starting with Dror's HelloWorld DSW (which compiles, links, and runs fine
with just APR), I added the lines:

# #include apr_iconv.h
# ...
# apr_iconv_open( 0, 0, 0, 0 );

I also added the apriconv-1/include directory to the search path, and
static library (/libd/apriconv-1.lib).  Compiled fine, but linker produced
this error:

# Main.obj : error LNK2019: unresolved external symbol int __stdcall
apr_iconv_open(char const *,char const *,struct apr_pool_t *,void * *)
(?apr_iconv_open@@YGHPBD0PAUapr_pool_t@@[EMAIL PROTECTED]) referenced in 
function
_main
# .\Debug/AprHelloWorld.exe : fatal error LNK1120: 1 unresolved externals

I tried declaring API_DECLARE_STATIC, but that doesn't seem to change
things.  Any suggestions?

-david

 -Original Message-
 From: Dror Shilo [mailto:[EMAIL PROTECTED]
 Sent: Monday, September 27, 2004 1:08 AM
 To: David Barrett
 Cc: dev@apr.apache.org
 Subject: RE: Static Linked on Linux and Win32
 
 On win32 to link statically you have to add the flag APR_DECLARE_STATIC
 
 I send you this sample
 the apr is installed at
 c:\Ericom++\apr
 
 Dror Shilo
 Ericom Software
 
 
 -Original Message-
 From: David Barrett [mailto:[EMAIL PROTECTED]
 Sent: Sunday, September 26, 2004 9:22 PM
 To: dev@apr.apache.org
 Subject: Static Linked on Linux and Win32
 
 
 Hi, I'm really excited to use APR, but I'm having trouble getting my
 Hello
 World application to work with static linkage, on both Linux and Win32.
 
 Basically, I have a single-file application:
 
 # // Main.cpp
 # #include iostream
 # #include apr.h
 # #include apr_general.h
 #
 # using namespace std;
 #
 # // main
 # int main( int argc, char const* const* argv )
 # {
 # cout  Hello world!;
 #
 # // Start APR
 # apr_app_initialize( argc, argv, 0 );
 #
 # unsigned char buf[10];
 # apr_generate_random_bytes( buf, 10 );
 #
 # // Done
 # apr_terminate( );
 # return 0;
 # }
 
 I can successfully compile, link, and execute the file on Win32 with APR
 1.0.0 when linking with the dynamic library:
 
 # $APRBASE\Debug\libapr-1.lib
 # $APRBASE\Debug\libapr-1.dll
 
 However, if I try to link with the static library on Win32:
 
 # $APRBASE\libd\apr-1.lib
 
 I get the following linker errors:
 
 # Linking...
 # main.obj : error LNK2019: unresolved external symbol
 __imp__apr_terminate
 referenced in function _main
 # main.obj : error LNK2019: unresolved external symbol
 [EMAIL PROTECTED] referenced in function _main
 # main.obj : error LNK2019: unresolved external symbol
 [EMAIL PROTECTED] referenced in function _main
 # Debug/APRtest.exe : fatal error LNK1120: 3 unresolved externals
 
 Likewise, I can compile and link on Linux (Fedora Core 2) using the shared
 library using the following Ant build file:
 
 # project name=aprtest default=compile
 # target name=compile
 # exec executable=g++
 # arg value=-oaprtest/
 # arg value=-I./unixlibs/apr-1/include/apr-1/
 # arg value=-L./unixlibs/apr-1/lib/
 # arg value=-lapr-1/
 # arg value=-shared/
 # arg file=main.cpp/
 # /exec
 # /target
 # /project
 
 But if I change line 8 from -shared to -static, I get the following
 linker errors:
 
 # compile:
 #  [exec] /tmp/ccNWTzJF.o(.text+0x33): In function `main':
 #  [exec] : undefined reference to `apr_app_initialize'
 #  [exec] /tmp/ccNWTzJF.o(.text+0x44): In function `main':
 #  [exec] : undefined reference to `apr_generate_random_bytes'
 #  [exec] /tmp/ccNWTzJF.o(.text+0x4c): In function `main':
 #  [exec] : undefined reference to `apr_terminate'
 #  [exec] collect2: ld returned 1 exit status
 
 So, I'm seeing the exact same problem on both platforms.  Obviously I'm
 doing something wrong, and I'm hoping it's something simple.  Does anyone
 see what I should do differently to get static linkage to work?
 
 -david




Threads Best Practices

2004-09-28 Thread David Barrett
Hi there, I'm really starting to get into APR.  I was able to port to APR
mutexes without a hitch.  However, I'm a bit confused on threads, and I'd
appreciate any direction you can offer:
 
1) What should I do with apr_threadattr_t?  Need I create one, or can I
pass NULL for that field into apr_thread_create?  If I need to create one,
do I need to do anything with it, or can I use it with its default state?


2) What's the proper way to declare an apr_start_thread_t function?  Is
this what I'm supposed to do?

# void* ThreadProc( apr_thread_t* thread, void* data ) { }
# void foo( )
# {
#   ...
#   apr_thread_create(
#   thread, 
#   attr, 
#   (apr_thread_start_t)ThreadProc, 
#   (void*)data, 
#   pool
#   );
# }


3) What's the portable equivalent to Win32's GetCurrentThreadId( )?  I'd
like to associate some data with the thread, and then query it down the
road.  Currently I use GetCurrentThreadId( ) in conjunction with my own
global map.  What I'd like to do us apr_thread_data_get( ) to just query
the current thread's data, but it looks like I need to know the thread's
handle.  Is there any way to look up the handle for the current thread, or
query the data of the current thread without knowing its handle?


4) What's the proper way to clean up a thread?  I'm new to the whole pool
paradigm; do I simply destroy the pool I used to create the thread and its
attribute?  I assume I need to apr_thread_join( ) on that thread first,
correct?


5) What's the portable equivalent to Win32's Sleep( ) function?  I see
there is apr_thread_yield( ), but that's not quite the same.  I'd like to
explicitly sleep the thread for some period; can APR do this?


Thanks for all your help, and the excellent library!

-david

PS: Is there any more-accessible form of the dev@apr.apache.org archives
than what's posted up on http://apr.apache.org/mail/dev/?  I'm finding it
difficult to search that effectively.  Alternatively, can you recommend any
better tools for searching the archives than grep and vi?  Like...
Google? :)



RE: Threads Best Practices

2004-09-28 Thread Dror Shilo
1) you can put null
2) see apr samples

void * APR_THREAD_FUNC ThreadProc(apr_thread_t *, void *context)
{
}
3)  use
apr_os_thread_current()

4) distroy the pool
apr_thread_join is not needed if you now that the thread has ended.
5) use apr_sleep()

Dror Shilo


-Original Message-
From: David Barrett [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 28, 2004 7:36 AM
To: dev@apr.apache.org
Subject: Threads Best Practices


Hi there, I'm really starting to get into APR.  I was able to port to APR
mutexes without a hitch.  However, I'm a bit confused on threads, and I'd
appreciate any direction you can offer:
 
1) What should I do with apr_threadattr_t?  Need I create one, or can I
pass NULL for that field into apr_thread_create?  If I need to create one,
do I need to do anything with it, or can I use it with its default state?


2) What's the proper way to declare an apr_start_thread_t function?  Is
this what I'm supposed to do?

# void* ThreadProc( apr_thread_t* thread, void* data ) { }
# void foo( )
# {
#   ...
#   apr_thread_create(
#   thread, 
#   attr, 
#   (apr_thread_start_t)ThreadProc, 
#   (void*)data, 
#   pool
#   );
# }


3) What's the portable equivalent to Win32's GetCurrentThreadId( )?  I'd
like to associate some data with the thread, and then query it down the
road.  Currently I use GetCurrentThreadId( ) in conjunction with my own
global map.  What I'd like to do us apr_thread_data_get( ) to just query
the current thread's data, but it looks like I need to know the thread's
handle.  Is there any way to look up the handle for the current thread, or
query the data of the current thread without knowing its handle?


4) What's the proper way to clean up a thread?  I'm new to the whole pool
paradigm; do I simply destroy the pool I used to create the thread and its
attribute?  I assume I need to apr_thread_join( ) on that thread first,
correct?


5) What's the portable equivalent to Win32's Sleep( ) function?  I see
there is apr_thread_yield( ), but that's not quite the same.  I'd like to
explicitly sleep the thread for some period; can APR do this?


Thanks for all your help, and the excellent library!

-david

PS: Is there any more-accessible form of the dev@apr.apache.org archives
than what's posted up on http://apr.apache.org/mail/dev/?  I'm finding it
difficult to search that effectively.  Alternatively, can you recommend any
better tools for searching the archives than grep and vi?  Like...
Google? :)



RE: Static Linked on Linux and Win32

2004-09-28 Thread William A. Rowe, Jr.
At 11:06 PM 9/27/2004, David Barrett wrote:
Ok, with Dror's and William's help I'm up and running with APR.  Now, what
about static linking with APRICONV?

Starting with Dror's HelloWorld DSW (which compiles, links, and runs fine
with just APR), I added the lines:

# #include apr_iconv.h
# ...
# apr_iconv_open( 0, 0, 0, 0 );

apr_iconv is a private interface.  It will soon be gone.

Stick with the apr_xlate interface.

Bill




Re: Hello :-)

2004-09-28 Thread William A. Rowe, Jr.
At 01:14 PM 9/28/2004, you wrote:

Hi Guys,

We're starting a new open source project, and are looking into using APR
for our portable framework.

Wonderful!  Once you have a beta release, we would love to include
you in the list of APR-based projects!

We started with the Win32 side first, and found out that the DSP and DSW
had to be converted to CRLF since Visual Studio 6.0 could not recognize
those files properly.

Simple enough - use apr/build/lineends.pl

Posting -win32-src.zip flavors, including exporting makefiles, has been
on my list of round tuits, thanks for the nudge :)

We're wondering if there's a nice reference project we can take a look at,
that compiles well on Win32 and Linux.

First and foremost is httpd server.  Version 2.1 (available from
http://httpd.apache.org/dev/dist/) is the version that builds
against APR 1.0, just drop apr and apr-util under it's srclib/ tree.
For Win32, also drop apr-iconv in there.

Another issue that arose was the dependency of the code on LDAP. To get it
to compile, we had to download Novel's ldap implementation +
libraries/headers. Is there a way to get around this?

This is already noted as an issue with 1.0 - for 0.9 it shouldn't
adversely affect you.  But we hope you stick with release 1.0 and
look forward to our 1.0.1 release which should allow you to configure
apr without ldap on unix.  On win32, ldap is always available to APR.

Bill



Re: Hello :-)

2004-09-28 Thread William A. Rowe, Jr.
At 02:49 PM 9/28/2004, [EMAIL PROTECTED] wrote:

 First and foremost is httpd server.  Version 2.1 (available from
 http://httpd.apache.org/dev/dist/) is the version that builds
 against APR 1.0, just drop apr and apr-util under it's srclib/ tree.
 For Win32, also drop apr-iconv in there.

What's the role of the apr-iconv package? What do I do when I want to
compile my application under Un*x? Does it have defines that will simply
not include the apr-iconv source? Ideally I would like to have a shared
source tree for all platforms.

Win32 does not have the iconv library.  We are considering moving to
the BSD distribution of iconv with Win32 specific patches, rather than
attempting to maintain a win32 flavor.  For that reason, apr-iconv
should not be considered a permanent fixture.

 This is already noted as an issue with 1.0 - for 0.9 it shouldn't
 adversely affect you.  But we hope you stick with release 1.0 and
 look forward to our 1.0.1 release which should allow you to configure
 apr without ldap on unix.  On win32, ldap is always available to APR.

Why do I need LDAP to begin with? And why in a portable runtime?

Don't use apr-util if you don't want such features.  apr-util are
utility accessors to help provide for portable ldap, xlate and other 
system library features.

If it doesn't relate to another library, you will find it in apr.
If it relates to external libraries, e.g. database, ldap, iconv,
etc, you will find it in apr-util.

Because those libraries have small discrepancies, but the authors
needed a modestly portable interface to basic database, conversion
and authentication features, the apr-util project was born.

Another issue we discovered today is a conflict of APR with STL. Is this a
known issue? When STL is added into the project, we get the following
error:

   error C2955: 'allocator' : use of class template requires template
argument list

If you search the archives, I recall something about that.  Feel free
to offer a patch of course.

Bill




RE: Hello :-)

2004-09-28 Thread David Barrett
 -Original Message-
 From: William A. Rowe, Jr. [mailto:[EMAIL PROTECTED]
 Subject: Re: Hello :-)
 
 At 02:49 PM 9/28/2004, [EMAIL PROTECTED] wrote:
 
 Another issue we discovered today is a conflict of APR with STL. Is this
 a known issue? When STL is added into the project, we get the following
 error:
 
error C2955: 'allocator' : use of class template requires template
 argument list
 
 If you search the archives, I recall something about that.  Feel free
 to offer a patch of course.

I'm using apr/apr-util/apr-iconv in a Win32 project with STL, and seeing no
problems.  I haven't tried Unix yet, but I'll let you know what I find.  Are
you seeing it on Win32, or only in Unix?

-david 



Re: Hello :-)

2004-09-28 Thread William A. Rowe, Jr.
At 03:30 PM 9/28/2004, William A. Rowe, Jr. wrote:

Win32 does not have the iconv library.  We are considering moving to
the BSD distribution of iconv with Win32 specific patches, rather than
attempting to maintain a win32 flavor.  For that reason, apr-iconv
should not be considered a permanent fixture.

I should have been more specific.  YES win32 has a codepage translation
facility.  That native library will not convert partial-content (e.g.,
when the destination string overflows, it will not report the partial
conversion results.)

There is a COM based component which will perform partial content
translation - but the overhead of writing this as a COM consumer
was less than appealing.

Bill



Using xlate on Win32

2004-09-28 Thread David Barrett
Threads and mutexes went in cleanly, thanks for all your help!  Next up -- 
i18n.  I'd like to convert between UTF-8 and UTF-16 using the 
apr_xlate_conv_buffer( ) function, but I can't get it to produce useful data. 
 Does anyone see what Im doing wrong?  The following code compiles, links, 
and runs fine (Visual Studio .NET 2003), but doesn't produce the correct 
output: 

# // Main.cpp
# #include string
# using namespace std;
# #include apr.h
# #include apr_general.h
# #include apr_xlate.h
#
# // main
# int main( int argc, char const* const* argv )
# {
#   // Start APR
#   apr_app_initialize( argc, argv, 0 );
#
#   // Create an APR pool and xlate converter
#   apr_pool_t*  pool = 0;
#   apr_xlate_t* xlate = 0;
#   apr_pool_create( pool, 0 );
#   apr_xlate_open( xlate, utf-8, utf-16, pool );
#
#   // Prepare the source UTF-16 string
#   wstring utf16String = LHello world!;
#   const char* utf16Buffer = (char*)utf16String.c_str( );
#   apr_size_t  utf16Length = utf16String.size( ) * 2;
#   
#   // Prepare the destination UTF-8 string
#   string  utf8String;
#   utf8String.resize( utf16Length );
#   char*   utf8Buffer = (char*)utf8String.c_str( );
#   apr_size_t  utf8Length = utf8String.size( );
#   
#   // Do the conversion
#   apr_xlate_conv_buffer( xlate, utf16Buffer, utf16Length, utf8Buffer, 
utf8Length );
#   utf8String.resize( utf8String.size( ) - utf8Length );
#   apr_xlate_close( xlate );
#
#   // Done
#   apr_terminate( );
#   return 0;
# }

I'm not checking return values here for brevity of example, but they all return 
success with one exception: apr_xlate_conv_buffer( ).  

apr_xlate_conv_buffer( ) returns 70008, which I'm assuming has something to 
do with buffer overflow, though I dont know how to convert into a real error 
message.

utf16Length starts out as 24, and ends at 8.  utf8Length starts at 
24, and ends at 0.  So far as I can tell, this means it's only consuming 
2/3 of the input buffer, but overflowing the output buffer (which is the likely 
cause of the error return value).

The final value of utf8String is:  
  (ie, a bunch of 
gibberish characters, if it's stripped from the email)

Any ideas what I'm doing wrong?

-david



Re: cvs commit: apr/network_io/win32 sendrecv.c

2004-09-28 Thread Jeff Trawick
On 28 Sep 2004 16:16:17 -, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 clar2004/09/28 09:16:17
 
   Modified:file_io/win32 readwrite.c
include  apr.hnw apr.hw
network_io/win32 sendrecv.c
   Log:
   replaced define for DWORD_MAX with APR_DWORD_MAX

   Index: apr.hw
   ===
   RCS file: /home/cvs/apr/include/apr.hw,v
   retrieving revision 1.125
   retrieving revision 1.126
   diff -u -r1.125 -r1.126
   --- apr.hw22 Sep 2004 18:21:30 -  1.125
   +++ apr.hw28 Sep 2004 16:16:17 -  1.126
   @@ -342,7 +342,7 @@
#define APR_SIZEOF_VOIDP   4
#endif
 
   -#define DWORD_MAX 4294967295
   +#define APR_DWORD_MAX 4294967295

or

#define APR_DWORD_MAX (DWORD_MAX)

since this is a platform which defines it?