You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-dev@httpd.apache.org by Randy Kobes <ra...@theoryx5.uwinnipeg.ca> on 2003/06/16 06:55:36 UTC

[apreq-2] perl glue on Win32

I'm trying to build the perl glue on Win32, and have
found a few things that need changing. One thing, that's
Win32 specific, is how APREQ_DECLARE in apreq.h is defined;
I've found the following seems to work:
==========================================================
Index: apreq.h
===================================================================
RCS file: /home/cvspublic/httpd-apreq-2/src/apreq.h,v
retrieving revision 1.21
diff -u -r1.21 apreq.h
--- apreq.h	15 Jun 2003 10:33:01 -0000	1.21
+++ apreq.h	16 Jun 2003 04:40:45 -0000
@@ -92,14 +92,13 @@
  * @{
  */

-/* XXX temporary workaround for Win32 */
-#ifndef WIN32
-
+#ifdef WIN32
+#define APREQ_DECLARE(type)            __declspec(dllexport) type __stdcall
+#define APREQ_DECLARE_NONSTD(type)     __declspec(dllexport) type
+#define APREQ_DECLARE_DATA             __declspec(dllexport)
+#else
 #define APREQ_DECLARE(d)                APR_DECLARE(d)
 #define APREQ_DECLARE_NONSTD(d)         APR_DECLARE_NONSTD(d)
-#else
-#define APREQ_DECLARE(d)                d
-#define APREQ_DECLARE_NONSTD(d)         d
 #endif

 #define APREQ_URL_ENCTYPE               "application/x-www-form-urlencoded"
==================================================================
I tried defining APREQ_DECLARE in terms of APR_DECLARE, as
is done on non-Win32, and then use a compile-time flag
APR_DECLARE_EXPORT, which I thought would do the same
as the above, but then ran into problems with exporting
and importing some symbols from the tests and from mod_apreq.

With this, I then get a couple of errors in compiling libapreq.
The first one, from apreq_cookie.c, says
===================================================================
apreq_cookie.c
..\src\apreq_cookie.c(65) : error C2059: syntax error : '('
..\src\apreq_cookie.c(71) : error C2059: syntax error : '('
==================================================================
I think this is because VC++ seems to get confused by the
declarations/definitions of apreq_cookie and apreq_add_cookie;
the following
=================================================================
Index: apreq_cookie.c
===================================================================
RCS file: /home/cvspublic/httpd-apreq-2/src/apreq_cookie.c,v
retrieving revision 1.15
diff -u -r1.15 apreq_cookie.c
--- apreq_cookie.c	9 Jun 2003 06:36:06 -0000	1.15
+++ apreq_cookie.c	16 Jun 2003 04:40:24 -0000
@@ -62,16 +62,19 @@
 #include "apr_lib.h"


-APREQ_DECLARE(apreq_cookie_t *) (apreq_cookie)(const apreq_jar_t *jar,
-                                               const char *name)
+APREQ_DECLARE(apreq_cookie_t *) apreq_cookie(const apreq_jar_t *jar,
+                                             const char *name)
 {
-    return apreq_cookie(jar,name);
+  return apreq_value_to_cookie(apreq_char_to_value(
+                                                   apr_table_get(jar->cookies,
+                                                                 name)));
 }

-APREQ_DECLARE(void) (apreq_add_cookie)(apreq_jar_t *jar,
-                                       const apreq_cookie_t *c)
+APREQ_DECLARE(void) apreq_add_cookie(apreq_jar_t *jar,
+                                     const apreq_cookie_t *c)
 {
-    apreq_add_cookie(jar,c);
+    apr_table_addn(jar->cookies,
+                   c->v.name,c->v.data);
 }

 APREQ_DECLARE(void) apreq_cookie_expires(apr_pool_t *p,
Index: apreq_cookie.h
===================================================================
RCS file: /home/cvspublic/httpd-apreq-2/src/apreq_cookie.h,v
retrieving revision 1.15
diff -u -r1.15 apreq_cookie.h
--- apreq_cookie.h	15 Jun 2003 10:33:01 -0000	1.15
+++ apreq_cookie.h	16 Jun 2003 04:40:25 -0000
@@ -125,8 +125,6 @@

 APREQ_DECLARE(apreq_cookie_t *)apreq_cookie(const apreq_jar_t *jar,
                                             const char *name);
-#define apreq_cookie(j,k) apreq_value_to_cookie(apreq_char_to_value( \
-                              apr_table_get((j)->cookies,k)))

 /**
  * Adds a cookie by pushing it to the bottom of the jar.
@@ -137,8 +135,6 @@

 APREQ_DECLARE(void) apreq_add_cookie(apreq_jar_t *jar,
                                      const apreq_cookie_t *c);
-#define apreq_add_cookie(j,c) apr_table_addn((j)->cookies,\
-                                            (c)->v.name,(c)->v.data)

 /**
  * Parse the incoming "Cookie:" headers into a cookie jar.
====================================================================
(which moves the definitions of these in apreq_cookie.h into
the declarations in apreq_cookie.c) lets VC++ gets past this.
The next thing, in apreq_tables.c, is an error:
====================================================================
apreq_tables.c ..\src\apreq_tables.c(504) : error C2152: '=' :
pointers to functions with different attributes
..\src\apreq_tables.c(505) : error C2152: '=' : pointers to
functions with different attributes
===================================================================
I'm not sure of this, but the following helps here:
==================================================================
Index: apreq_tables.c
===================================================================
RCS file: /home/cvspublic/httpd-apreq-2/src/apreq_tables.c,v
retrieving revision 1.31
diff -u -r1.31 apreq_tables.c
--- apreq_tables.c	20 May 2003 20:10:59 -0000	1.31
+++ apreq_tables.c	16 Jun 2003 04:40:35 -0000
@@ -501,8 +501,8 @@
     /* XXX: is memset(*,-1,*) portable ??? */
     memset(t->root, -1, TABLE_HASH_SIZE * sizeof(int));

-    t->merge  = apreq_merge_values;
-    t->copy   = apreq_copy_value;
+    t->merge  = (apreq_value_merge_t *) apreq_merge_values;
+    t->copy   = (apreq_value_copy_t *) apreq_copy_value;
     t->ghosts = 0;
     return t;
 }
=============================================================
Finally, in running the tests, I get an error about
apr_table_compress being unresolved (I'm running Apache/2.0.46).
The following
===========================================================
Index: performance.c
===================================================================
RCS file: /home/cvspublic/httpd-apreq-2/t/performance.c,v
retrieving revision 1.3
diff -u -r1.3 performance.c
--- performance.c	20 May 2003 20:27:32 -0000	1.3
+++ performance.c	16 Jun 2003 04:46:23 -0000
@@ -164,7 +164,10 @@
        apr_table_t *s = init_apr(NELTS);
 /*       apr_table_t *t = apr_table_make(p,NELTS);
 //       apr_table_overlap(t,s,APR_OVERLAP_TABLES_MERGE);
-*/      apr_table_compress(s);
+*/
+#ifndef WIN32
+         apr_table_compress(s);
+#endif
     }
     apr_delta = apr_time_now() - apr_delta;
====================================================================
helps here.

With these diffs, all the enabled tests under t/ pass. The
perl modules build successfully, but there's some problems
with some of the tests, specifically involving inheritance
(for example, in TestApReq/big_input.pm, the methods
$apr->content_type() and $apr->print() can't be found,
but the tests are OK if $r->content_type() and $r->print()
are used). But I'll leave that until the above gets resolved.

-- 
best regards,
randy

Re: [apreq-2] perl glue on Win32

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Joe Schaefer <jo...@sunstarsys.com> writes:

> Randy Kobes <ra...@theoryx5.uwinnipeg.ca> writes:
> 
> [...]
> 
> > in the original I had
> >    #ifdef WIN32
> >    #define APREQ_DECLARE ...
> >    #else
> >    #define APREQ_DELARE ...
> >    #endif
> > but then found, in running build/xsbuilder, that the glue
> > for Apache::Request wasn't being built by ExtUtils::XSBuilder,
> > but only that for Apache::Cookie. Changing the order around:
> >   #ifndef WIN32
> >   #define ...
> >   #else
> >   #define ...
> >   #endif
> > seems to fix this - I hope this is OK on unix ...
> 
> It'll probably break Unix because xsbuilder.pl has a bug in its
> cmacro() sub- it wasn't coded to handle #ifdef. XSBuilder::ParseSource's
> C parser is P::RD based, which needs a few macros to be expanded 
> in the headers prior to the parse.
> 
> I'll see if I can come up with a fix for xsbuilder.pl.

Hmm, current cvs just tested ok on Linux.  I guess it's ok for
P::RD to use the (simpler) Unix defs when parsing the header files.
, and maybe it (or cmacro()) chokes on the WIN32 ones.

Since xsbuilder.pl seems to be working, I'm not going to mess 
with it.


-- 
Joe Schaefer


Re: [apreq-2] perl glue on Win32

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Randy Kobes <ra...@theoryx5.uwinnipeg.ca> writes:

[...]

> in the original I had
>    #ifdef WIN32
>    #define APREQ_DECLARE ...
>    #else
>    #define APREQ_DELARE ...
>    #endif
> but then found, in running build/xsbuilder, that the glue
> for Apache::Request wasn't being built by ExtUtils::XSBuilder,
> but only that for Apache::Cookie. Changing the order around:
>   #ifndef WIN32
>   #define ...
>   #else
>   #define ...
>   #endif
> seems to fix this - I hope this is OK on unix ...

It'll probably break Unix because xsbuilder.pl has a bug in its
cmacro() sub- it wasn't coded to handle #ifdef. XSBuilder::ParseSource's
C parser is P::RD based, which needs a few macros to be expanded 
in the headers prior to the parse.

I'll see if I can come up with a fix for xsbuilder.pl.

[...]

> > Another possibility would be
> > to drop APREQ_DECLARE from apreq_copy_value() & apreq_merge_values()
> > in apreq.[ch].
> 
> That does work, as in the following:

[... patch ...]

+1.

-- 
Joe Schaefer

Re: [apreq-2] perl glue on Win32

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Mon, 16 Jun 2003, Joe Schaefer wrote:

> Randy Kobes <ra...@theoryx5.uwinnipeg.ca> writes:
>
> [...apreq.h patch...]
>
> +0. I can't judge the correctness of this patch wrt Win32, but I've been
> following a commit-then-wait-for-Stas'-wrath^H^H^H^H^H^Hreview myself
> ;-).  Please use the same criterion regarding this and similar Win32
> patches.  If someone breaks your Win32 port in a future commit, just
> holler.

OK :) I committed that change. One thing that was strange -
in the original I had
   #ifdef WIN32
   #define APREQ_DECLARE ...
   #else
   #define APREQ_DELARE ...
   #endif
but then found, in running build/xsbuilder, that the glue
for Apache::Request wasn't being built by ExtUtils::XSBuilder,
but only that for Apache::Cookie. Changing the order around:
  #ifndef WIN32
  #define ...
  #else
  #define ...
  #endif
seems to fix this - I hope this is OK on unix ...

[ .. ]
> > With this, I then get a couple of errors in compiling libapreq.
> > The first one, from apreq_cookie.c, says
> > ===================================================================
> > apreq_cookie.c
> > ..\src\apreq_cookie.c(65) : error C2059: syntax error : '('
> > ..\src\apreq_cookie.c(71) : error C2059: syntax error : '('
> > ==================================================================
> > I think this is because VC++ seems to get confused by the
> > declarations/definitions of apreq_cookie and apreq_add_cookie;
> > the following
> [...apreq_cookie.[ch] patch...]
> +1.

Thanks - that's been committed ...

> > The next thing, in apreq_tables.c, is an error:
> > ====================================================================
> > apreq_tables.c ..\src\apreq_tables.c(504) : error C2152: '=' :
> > pointers to functions with different attributes
> > ..\src\apreq_tables.c(505) : error C2152: '=' : pointers to
> > functions with different attributes
> > ===================================================================
> > I'm not sure of this, but the following helps here:
[ .. ]
> The original source appears broken, but at the moment I
> don't like those casts.  Is it possible to change the
> apreq_value_(merge|copy)_t typedefs to include APREQ_DECLARE?
>
>   typedef APREQ_DECLARE(apreq_value_t *)
>   (apreq_value_merge_t) (apr_pool_t *p, const apr_array_header_t *a);
>
>   typedef APREQ_DECLARE(apreq_value_t *)
>   (apreq_value_copy_t)(apr_pool_t *p, const apreq_value_t *v);
>
> Not sure that will work though.

That's right - there were various syntax errors in trying that.

> Another possibility would be
> to drop APREQ_DECLARE from apreq_copy_value() & apreq_merge_values()
> in apreq.[ch].

That does work, as in the following:
===============================================================
Index: apreq.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq.c,v
retrieving revision 1.19
diff -u -r1.19 apreq.c
--- apreq.c	7 Jun 2003 20:07:41 -0000	1.19
+++ apreq.c	17 Jun 2003 06:28:44 -0000
@@ -84,8 +84,8 @@
 }


-APREQ_DECLARE(apreq_value_t *)apreq_copy_value(apr_pool_t *p,
-                                               const apreq_value_t *val)
+apreq_value_t * apreq_copy_value(apr_pool_t *p,
+                                 const apreq_value_t *val)
 {
     apreq_value_t *v;
     if (val == NULL)
@@ -101,8 +101,8 @@
     return v;
 }

-APREQ_DECLARE(apreq_value_t *)apreq_merge_values(apr_pool_t *p,
-                                           const apr_array_header_t *arr)
+apreq_value_t * apreq_merge_values(apr_pool_t *p,
+                                   const apr_array_header_t *arr)
 {
     apreq_value_t *a = *(apreq_value_t **)(arr->elts);
     apreq_value_t *v = apreq_char_to_value( apreq_join(p, ", ", arr, AS_IS) );
Index: apreq.h
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq.h,v
retrieving revision 1.23
diff -u -r1.23 apreq.h
--- apreq.h	17 Jun 2003 06:16:36 -0000	1.23
+++ apreq.h	17 Jun 2003 06:28:44 -0000
@@ -159,16 +159,16 @@
  * @param p  Pool.
  * @param val Original value to copy.
  */
-APREQ_DECLARE(apreq_value_t *) apreq_copy_value(apr_pool_t *p,
-                                                const apreq_value_t *val);
+apreq_value_t * apreq_copy_value(apr_pool_t *p,
+                                 const apreq_value_t *val);

 /**
  * Merges an array of values into one.
  * @param p   Pool from which the new value is generated.
  * @param arr Array of apr_value_t *.
  */
-APREQ_DECLARE(apreq_value_t *) apreq_merge_values(apr_pool_t *p,
-                                            const apr_array_header_t *arr);
+apreq_value_t * apreq_merge_values(apr_pool_t *p,
+                                   const apr_array_header_t *arr);

 /**
  * Fetches the enctype from the environment.
====================================================================
> > Finally, in running the tests, I get an error about
> > apr_table_compress being unresolved (I'm running Apache/2.0.46).
> > The following
> [...]
>
> There is no apr_table_compress() function in apr_tables yet,
> so the undefined symbol will occur on all platforms.
>
> The plan is to eventually drop apreq_tables once we get
> the necessary (callback/compress) functionality into apr_tables.
> In the meantime I've taken performance.c and tables.c
> out of the CuTest suite, so I wouldn't worry about fixing
> those tests right now.

Thanks - I've taken them out of the Win32 build as well,
and now all the t/ tests pass (with the above diff applied
to apreq.[ch]).

> > With these diffs, all the enabled tests under t/ pass. The
> > perl modules build successfully, but there's some problems
> > with some of the tests, specifically involving inheritance
> > (for example, in TestApReq/big_input.pm, the methods
> > $apr->content_type() and $apr->print() can't be found,
> > but the tests are OK if $r->content_type() and $r->print()
> > are used).
>
> Hmm, this is a pretty important (and timely) issue.
> The base class for Apache::Request is determined
> at load-time via Apache::Request->env, which should
> normally return "Apache::RequestRec".  There might be
> a problem with apreq_xs_env not finding the
> apreq_env = "APACHE2" definition in mod_apreq.c.
> You might try adding some Perl_warn diagnostics to the
> APREQ_XS_DEFINE_ENV macro in xsbuilder/apreq_xs_postperl.h
> and check t/log/error_log for clues.

You're right on about that :) I changed in src/apreq_env.h
to declare apreq_env[] with dllexport if building mod_apreq
or libapreq_cgi, and to use dllimport for libapreq. With this,
all the perl glue tests now pass. Tnanks.

-- 
best regards,
randy

Re: [apreq-2] perl glue on Win32

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Randy Kobes <ra...@theoryx5.uwinnipeg.ca> writes:

[...apreq.h patch...]

+0. I can't judge the correctness of this patch wrt Win32, but I've been 
following a commit-then-wait-for-Stas'-wrath^H^H^H^H^H^Hreview myself
;-).  Please use the same criterion regarding this and similar Win32 
patches.  If someone breaks your Win32 port in a future commit, just 
holler.

> I tried defining APREQ_DECLARE in terms of APR_DECLARE, as
> is done on non-Win32, and then use a compile-time flag
> APR_DECLARE_EXPORT, which I thought would do the same
> as the above, but then ran into problems with exporting
> and importing some symbols from the tests and from mod_apreq.

Interesting. 

> With this, I then get a couple of errors in compiling libapreq.
> The first one, from apreq_cookie.c, says
> ===================================================================
> apreq_cookie.c
> ..\src\apreq_cookie.c(65) : error C2059: syntax error : '('
> ..\src\apreq_cookie.c(71) : error C2059: syntax error : '('
> ==================================================================
> I think this is because VC++ seems to get confused by the
> declarations/definitions of apreq_cookie and apreq_add_cookie;
> the following

[...apreq_cookie.[ch] patch...]

+1.

> The next thing, in apreq_tables.c, is an error:
> ====================================================================
> apreq_tables.c ..\src\apreq_tables.c(504) : error C2152: '=' :
> pointers to functions with different attributes
> ..\src\apreq_tables.c(505) : error C2152: '=' : pointers to
> functions with different attributes
> ===================================================================
> I'm not sure of this, but the following helps here:
> ==================================================================
> Index: apreq_tables.c
> ===================================================================
> RCS file: /home/cvspublic/httpd-apreq-2/src/apreq_tables.c,v
> retrieving revision 1.31
> diff -u -r1.31 apreq_tables.c
> --- apreq_tables.c	20 May 2003 20:10:59 -0000	1.31
> +++ apreq_tables.c	16 Jun 2003 04:40:35 -0000
> @@ -501,8 +501,8 @@
>      /* XXX: is memset(*,-1,*) portable ??? */
>      memset(t->root, -1, TABLE_HASH_SIZE * sizeof(int));
> 
> -    t->merge  = apreq_merge_values;
> -    t->copy   = apreq_copy_value;
> +    t->merge  = (apreq_value_merge_t *) apreq_merge_values;
> +    t->copy   = (apreq_value_copy_t *) apreq_copy_value;
>      t->ghosts = 0;
>      return t;
>  }

The original source appears broken, but at the moment I 
don't like those casts.  Is it possible to change the 
apreq_value_(merge|copy)_t typedefs to include APREQ_DECLARE?

  typedef APREQ_DECLARE(apreq_value_t *) 
  (apreq_value_merge_t) (apr_pool_t *p, const apr_array_header_t *a);

  typedef APREQ_DECLARE(apreq_value_t *)
  (apreq_value_copy_t)(apr_pool_t *p, const apreq_value_t *v);

Not sure that will work though.  Another possibility would be 
to drop APREQ_DECLARE from apreq_copy_value() & apreq_merge_values()
in apreq.[ch].

> =============================================================
> Finally, in running the tests, I get an error about
> apr_table_compress being unresolved (I'm running Apache/2.0.46).
> The following

[...]

> helps here.

There is no apr_table_compress() function in apr_tables yet, 
so the undefined symbol will occur on all platforms.

The plan is to eventually drop apreq_tables once we get
the necessary (callback/compress) functionality into apr_tables.
In the meantime I've taken performance.c and tables.c
out of the CuTest suite, so I wouldn't worry about fixing 
those tests right now.

> With these diffs, all the enabled tests under t/ pass. The
> perl modules build successfully, but there's some problems
> with some of the tests, specifically involving inheritance
> (for example, in TestApReq/big_input.pm, the methods
> $apr->content_type() and $apr->print() can't be found,
> but the tests are OK if $r->content_type() and $r->print()
> are used).

Hmm, this is a pretty important (and timely) issue.
The base class for Apache::Request is determined
at load-time via Apache::Request->env, which should
normally return "Apache::RequestRec".  There might be
a problem with apreq_xs_env not finding the
apreq_env = "APACHE2" definition in mod_apreq.c.
You might try adding some Perl_warn diagnostics to the
APREQ_XS_DEFINE_ENV macro in xsbuilder/apreq_xs_postperl.h 
and check t/log/error_log for clues.

-- 
Joe Schaefer