httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject [mp2 patch] getting APR to work w/o modperl
Date Wed, 05 May 2004 23:39:05 GMT
OK, I did some code reshuffling and with a few workarounds got APR::Table, 
APR::UUID, APR::Pool and APR::PerlIO work outside httpd. I haven't tested 
other modules yet. It's a big patch but it really does two things:

1) splits:
modperl_util.c => modperl_common_util.c
modperl_log.c  => modperl_common_log.c

the common files contain the minimal things needed for APR to work w/o httpd. 
(notice I haven't tested all the APR:: modules yet).

I'm not sure whether I've chosen the best name when using "common", may be I 
should have called it apr. But if you look at the code, modperl_log.h includes 
modperl_common_log.h (so it's sort of inheritance) where common is the base 
[hc]. The only confusing part is that we don't want to have everything that 
it's not including ap_ modperl_ symbolds in those common files, in order to 
keep the external libs small. So your comments are welcome.

2) moved some of the modperl_util.c functions to a new file modperl_debug.c 
(it's really unrelated to this patch, I'll commit it separately)

3) APR.so now links against  modperl_common_log.o modperl_common_util.o 
modperl_error.o. think of APR.so as mod_perl.so which bootstraps the rest.

I'll probably make all APR:: modules load APR.pm internally, so one doesn't 
need to remember to load APR, to use APR::Table for example.

Here is the patch (you will need to do a complete rebuild). Oh and I didn't 
run the source scan for those on win32. But you should be able to do it on 
your own now. I'm mainly looking for the comments now. And commit the scan 
when everybody is happy with this change.

Index: Apache-Test/lib/Apache/TestRun.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestRun.pm,v
retrieving revision 1.166
diff -u -u -r1.166 TestRun.pm
--- Apache-Test/lib/Apache/TestRun.pm	16 Apr 2004 20:29:23 -0000	1.166
+++ Apache-Test/lib/Apache/TestRun.pm	5 May 2004 23:28:56 -0000
@@ -643,7 +643,7 @@
      }
      close $sh;

-    $original_command = "ulimit -c unlimited; $original_command";
+    $original_command = "ulimit -c unlimited; PERL_DL_NONLAZY=1 
$original_command";
      warning "setting ulimit to allow core files\n$original_command";
      exec $original_command;
      die "exec $original_command has failed"; # shouldn't be reached
Index: lib/ModPerl/Code.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/lib/ModPerl/Code.pm,v
retrieving revision 1.121
diff -u -u -r1.121 Code.pm
--- lib/ModPerl/Code.pm	4 May 2004 06:10:37 -0000	1.121
+++ lib/ModPerl/Code.pm	5 May 2004 23:28:56 -0000
@@ -641,7 +641,8 @@
  my @c_src_names = qw(interp tipool log config cmd options callback handler
                       gtop util io io_apache filter bucket mgv pcw global env
                       cgi perl perl_global perl_pp sys module svptr_table
-                     const constants apache_compat error);
+                     const constants apache_compat error debug
+                     common_util common_log);
  my @h_src_names = qw(perl_unembed);
  my @g_c_names = map { "modperl_$_" } qw(hooks directives flags xsinit);
  my @c_names   = ('mod_perl', (map "modperl_$_", @c_src_names));
@@ -652,7 +653,8 @@
  my @g_h_names = map { "modperl_$_" } qw(hooks directives flags trace
                                          largefiles);
  my @h_names = (@c_names, map { "modperl_$_" } @h_src_names,
-               qw(types time apache_includes perl_includes));
+               qw(types time apache_includes perl_includes apr_includes
+                  common_includes));
  sub h_files { [map { "$_.h" } @h_names, @g_h_names] }

  sub clean_files {
Index: src/modules/perl/mod_perl.h
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/mod_perl.h,v
retrieving revision 1.65
diff -u -u -r1.65 mod_perl.h
--- src/modules/perl/mod_perl.h	4 May 2004 06:10:37 -0000	1.65
+++ src/modules/perl/mod_perl.h	5 May 2004 23:28:56 -0000
@@ -17,7 +17,7 @@
  #define MOD_PERL_H

  #include "modperl_apache_includes.h"
-#include "modperl_perl_includes.h"
+#include "modperl_common_includes.h"
  #include "modperl_apache_compat.h"

  #ifdef WIN32
@@ -91,6 +91,7 @@
  #include "modperl_perl.h"
  #include "modperl_svptr_table.h"
  #include "modperl_module.h"
+#include "modperl_debug.h"

  int modperl_init_vhost(server_rec *s, apr_pool_t *p,
                         server_rec *base_server);
Index: src/modules/perl/modperl_apache_includes.h
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_apache_includes.h,v
retrieving revision 1.28
diff -u -u -r1.28 modperl_apache_includes.h
--- src/modules/perl/modperl_apache_includes.h	4 Mar 2004 06:01:06 -0000	1.28
+++ src/modules/perl/modperl_apache_includes.h	5 May 2004 23:28:56 -0000
@@ -34,18 +34,6 @@
  #include "http_vhost.h"
  #include "ap_mpm.h"

-#include "apr_version.h"
-#include "apr_poll.h"
-#include "apr_lib.h"
-#include "apr_strings.h"
-#include "apr_uri.h"
-#include "apr_date.h"
-#include "apr_buckets.h"
-#include "apr_time.h"
-#include "apr_network_io.h"
-#include "apr_general.h"
-#include "apr_uuid.h"
-#include "apr_env.h"
  #include "util_filter.h"

  #include "util_script.h"
Index: src/modules/perl/modperl_cmd.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_cmd.c,v
retrieving revision 1.58
diff -u -u -r1.58 modperl_cmd.c
--- src/modules/perl/modperl_cmd.c	4 Mar 2004 06:01:07 -0000	1.58
+++ src/modules/perl/modperl_cmd.c	5 May 2004 23:28:56 -0000
@@ -153,7 +153,7 @@
  MP_CMD_SRV_DECLARE(trace)
  {
      MP_CMD_SRV_CHECK;
-    modperl_trace_level_set(parms->server, arg);
+    modperl_trace_level_set_apache(parms->server, arg);
      return NULL;
  }

Index: src/modules/perl/modperl_config.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_config.c,v
retrieving revision 1.78
diff -u -u -r1.78 modperl_config.c
--- src/modules/perl/modperl_config.c	4 Mar 2004 06:01:07 -0000	1.78
+++ src/modules/perl/modperl_config.c	5 May 2004 23:28:57 -0000
@@ -268,7 +268,7 @@
           * PerlTrace. This place is the earliest point in mod_perl
           * configuration parsing, when we have the server object
           */
-        modperl_trace_level_set(s, NULL);
+        modperl_trace_level_set_apache(s, NULL);

          /* Must store the global server record as early as possible,
           * because if mod_perl happens to be started from within a
Index: src/modules/perl/modperl_error.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_error.c,v
retrieving revision 1.1
diff -u -u -r1.1 modperl_error.c
--- src/modules/perl/modperl_error.c	4 May 2004 06:03:52 -0000	1.1
+++ src/modules/perl/modperl_error.c	5 May 2004 23:28:57 -0000
@@ -55,7 +55,10 @@
      HV *data;

      /* XXX: it'd be nice to arrange for it to load early */
-    modperl_require_module(aTHX_ "APR::Error", TRUE);
+    Perl_require_pv(aTHX_ "APR/Error.pm");
+    if (SvTRUE(ERRSV)) {
+        Perl_croak(aTHX_ "%s", SvPV_nolen(ERRSV));
+    }

      stash = gv_stashpvn("APR::Error", 10, FALSE);
      data = newHV();
Index: src/modules/perl/modperl_gtop.h
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_gtop.h,v
retrieving revision 1.6
diff -u -u -r1.6 modperl_gtop.h
--- src/modules/perl/modperl_gtop.h	27 Apr 2004 00:27:38 -0000	1.6
+++ src/modules/perl/modperl_gtop.h	5 May 2004 23:28:57 -0000
@@ -21,7 +21,7 @@
  #endif

  #ifdef MP_USE_GTOP
-
+#define __GLIBTOP_ERROR_H__
  #include <glibtop.h>
  #include <glibtop/open.h>
  #include <glibtop/close.h>
Index: src/modules/perl/modperl_log.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_log.c,v
retrieving revision 1.11
diff -u -u -r1.11 modperl_log.c
--- src/modules/perl/modperl_log.c	4 Mar 2004 06:01:07 -0000	1.11
+++ src/modules/perl/modperl_log.c	5 May 2004 23:28:57 -0000
@@ -13,81 +13,4 @@
   * limitations under the License.
   */

-#include "modperl_apache_includes.h"
-#include "apr_lib.h"
-#include "modperl_trace.h"
  #include "modperl_log.h"
-
-#undef getenv /* from XSUB.h */
-
-static apr_file_t *logfile = NULL;
-
-#ifdef WIN32
-static unsigned long debug_level = 0;
-#else
-unsigned long MP_debug_level = 0;
-#define debug_level MP_debug_level
-#endif
-
-unsigned long modperl_debug_level(void)
-{
-    return debug_level;
-}
-
-void modperl_trace_logfile_set(apr_file_t *logfile_new)
-{
-    logfile = logfile_new;
-}
-
-void modperl_trace(const char *func, const char *fmt, ...)
-{
-    char vstr[8192];
-    apr_size_t vstr_len = 0;
-    va_list args;
-
-    if (!logfile) {
-        return;
-    }
-
-    if (func) {
-        apr_file_printf(logfile, "%s: ", func);
-    }
-
-    va_start(args, fmt);
-    vstr_len = apr_vsnprintf(vstr, sizeof(vstr), fmt, args);
-    va_end(args);
-
-    apr_file_write(logfile, vstr, &vstr_len);
-    apr_file_printf(logfile, "\n");
-}
-
-void modperl_trace_level_set(server_rec *s, const char *level)
-{
-    if (!level) {
-        if (!(level = getenv("MOD_PERL_TRACE"))) {
-            return;
-        }
-    }
-    debug_level = 0x0;
-
-    if (strcasecmp(level, "all") == 0) {
-        debug_level = 0xffffffff;
-    }
-    else if (apr_isalpha(level[0])) {
-        static char debopts[] = MP_TRACE_OPTS;
-        char *d;
-
-        for (; *level && (d = strchr(debopts, *level)); level++) {
-            debug_level |= 1 << (d - debopts);
-        }
-    }
-    else {
-        debug_level = atoi(level);
-    }
-
-    debug_level |= 0x80000000;
-
-    modperl_trace_logfile_set(s->error_log);
-
-    MP_TRACE_any_do(MP_TRACE_dump_flags());
-}
Index: src/modules/perl/modperl_log.h
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_log.h,v
retrieving revision 1.13
diff -u -u -r1.13 modperl_log.h
--- src/modules/perl/modperl_log.h	4 Mar 2004 06:01:07 -0000	1.13
+++ src/modules/perl/modperl_log.h	5 May 2004 23:28:57 -0000
@@ -16,47 +16,11 @@
  #ifndef MODPERL_LOG_H
  #define MODPERL_LOG_H

-#define MP_STRINGIFY(n) MP_STRINGIFY_HELPER(n)
-#define MP_STRINGIFY_HELPER(n) #n
+#include "modperl_common_log.h"
+#include "modperl_apache_includes.h"

-#ifdef MP_TRACE
-#   if defined(__GNUC__)
-#      if (__GNUC__ > 2)
-#         define MP_FUNC __func__
-#      else
-#         define MP_FUNC __FUNCTION__
-#      endif
-#   else
-#      define MP_FUNC __FILE__ ":" MP_STRINGIFY(__LINE__)
-#   endif
-#else
-#   define MP_FUNC NULL
-#endif
-
-#include "modperl_trace.h"
-
-#ifdef _PTHREAD_H
-#define modperl_thread_self() pthread_self()
-#else
-#define modperl_thread_self() 0
-#endif
-
-#define MP_TIDF \
-(unsigned long)modperl_thread_self()
-
-void modperl_trace_logfile_set(apr_file_t *logfile_new);
-
-unsigned long modperl_debug_level(void);
-
-#ifdef WIN32
-#define MP_debug_level modperl_debug_level()
-#else
-extern unsigned long MP_debug_level;
-#endif
-
-void modperl_trace(const char *func, const char *fmt, ...);
-
-void modperl_trace_level_set(server_rec *s, const char *level);
+#define modperl_trace_level_set_apache(s, level) \
+    modperl_trace_level_set(s->error_log, level);

  #define modperl_log_warn(s,msg) \
      ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "%s", msg)
Index: src/modules/perl/modperl_util.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_util.c,v
retrieving revision 1.67
diff -u -u -r1.67 modperl_util.c
--- src/modules/perl/modperl_util.c	4 May 2004 06:16:46 -0000	1.67
+++ src/modules/perl/modperl_util.c	5 May 2004 23:28:57 -0000
@@ -290,26 +290,6 @@
      return status;
  }

-char *modperl_server_desc(server_rec *s, apr_pool_t *p)
-{
-    return apr_psprintf(p, "%s:%u", s->server_hostname, s->port);
-}
-
-/* used in debug traces */
-MP_INLINE char *modperl_pid_tid(apr_pool_t *p)
-{
-    return apr_psprintf(p, "%lu"
-#if APR_HAS_THREADS
-                 "/%lu"
-#endif /* APR_HAS_THREADS */
-                 , (unsigned long)getpid()
-#if APR_HAS_THREADS
-                 , (unsigned long)apr_os_thread_current()
-#endif /* APR_HAS_THREADS */
-        );
-}
-
-
  #define dl_librefs "DynaLoader::dl_librefs"
  #define dl_modules "DynaLoader::dl_modules"

@@ -402,54 +382,6 @@
      return uri;
  }

-MP_INLINE SV *modperl_hash_tie(pTHX_
-                               const char *classname,
-                               SV *tsv, void *p)
-{
-    SV *hv = (SV*)newHV();
-    SV *rsv = sv_newmortal();
-
-    sv_setref_pv(rsv, classname, p);
-    sv_magic(hv, rsv, PERL_MAGIC_tied, Nullch, 0);
-
-    return SvREFCNT_inc(sv_bless(sv_2mortal(newRV_noinc(hv)),
-                                 gv_stashpv(classname, TRUE)));
-}
-
-MP_INLINE void *modperl_hash_tied_object(pTHX_
-                                         const char *classname,
-                                         SV *tsv)
-{
-    if (sv_derived_from(tsv, classname)) {
-        if (SVt_PVHV == SvTYPE(SvRV(tsv))) {
-            SV *hv = SvRV(tsv);
-            MAGIC *mg;
-
-            if (SvMAGICAL(hv)) {
-                if ((mg = mg_find(hv, PERL_MAGIC_tied))) {
-                    return (void *)MgObjIV(mg);
-                }
-                else {
-                    Perl_warn(aTHX_ "Not a tied hash: (magic=%c)", mg);
-                }
-            }
-            else {
-                Perl_warn(aTHX_ "SV is not tied");
-            }
-        }
-        else {
-            return (void *)SvObjIV(tsv);
-        }
-    }
-    else {
-        Perl_croak(aTHX_
-                   "argument is not a blessed reference "
-                   "(expecting an %s derived object)", classname);
-    }
-
-    return NULL;
-}
-
  MP_INLINE void modperl_perl_av_push_elts_ref(pTHX_ AV *dst, AV *src)
  {
      I32 i, j, src_fill = AvFILLp(src), dst_fill = AvFILLp(dst);
@@ -890,51 +822,3 @@

      return text;
  }
-
-#ifdef MP_TRACE
-
-/* XXX: internal debug function, a candidate for modperl_debug.c */
-/* any non-false value for MOD_PERL_TRACE/PerlTrace enables this function */
-void modperl_apr_table_dump(pTHX_ apr_table_t *table, char *name)
-{
-    int i;
-    const apr_array_header_t *array;
-    apr_table_entry_t *elts;
-
-    array = apr_table_elts(table);
-    elts  = (apr_table_entry_t *)array->elts;
-    modperl_trace(MP_FUNC, "Contents of table %s", name);
-    for (i = 0; i < array->nelts; i++) {
-        if (!elts[i].key || !elts[i].val) {
-            continue;
-        }
-        modperl_trace(MP_FUNC, "%s => %s", elts[i].key, elts[i].val);
-    }
-}
-
-/* XXX: internal debug function, a candidate for modperl_debug.c */
-void modperl_perl_modglobal_dump(pTHX)
-{
-    HV *hv = PL_modglobal;
-    AV *val;
-    char *key;
-    I32 klen;
-    hv_iterinit(hv);
-
-    MP_TRACE_g(MP_FUNC, "|-------- PL_modglobal --------");
-#ifdef USE_ITHREADS
-    MP_TRACE_g(MP_FUNC, "| perl 0x%lx", (unsigned long)aTHX);
-#endif
-    MP_TRACE_g(MP_FUNC, "| PL_modglobal 0x%lx",
-               (unsigned long)PL_modglobal);
-
-    while ((val = (AV*)hv_iternextsv(hv, &key, &klen))) {
-        MP_TRACE_g(MP_FUNC, "| %s => 0x%lx", key, val);
-    }
-
-    MP_TRACE_g(MP_FUNC, "|-------- PL_modglobal --------\n");
-
-}
-
-
-#endif
Index: src/modules/perl/modperl_util.h
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_util.h,v
retrieving revision 1.56
diff -u -u -r1.56 modperl_util.h
--- src/modules/perl/modperl_util.h	4 May 2004 06:19:11 -0000	1.56
+++ src/modules/perl/modperl_util.h	5 May 2004 23:28:57 -0000
@@ -16,55 +16,7 @@
  #ifndef MODPERL_UTIL_H
  #define MODPERL_UTIL_H

-#ifdef MP_DEBUG
-#define MP_INLINE
-#else
-#define MP_INLINE APR_INLINE
-#endif
-
-#ifdef WIN32
-#   define MP_FUNC_T(name) (_stdcall *name)
-/* XXX: not all functions get inlined
- * so its unclear what to and not to include in the .def files
- */
-#   undef MP_INLINE
-#   define MP_INLINE
-#else
-#   define MP_FUNC_T(name)          (*name)
-#endif
-
-#define MP_SSTRLEN(string) (sizeof(string)-1)
-
-#ifndef strcaseEQ
-#   define strcaseEQ(s1,s2) (!strcasecmp(s1,s2))
-#endif
-#ifndef strncaseEQ
-#   define strncaseEQ(s1,s2,l) (!strncasecmp(s1,s2,l))
-#endif
-
-#ifndef SvCLASS
-#define SvCLASS(o) HvNAME(SvSTASH(SvRV(o)))
-#endif
-
-#define SvObjIV(o) SvIV((SV*)SvRV(o))
-#define MgObjIV(m) SvIV((SV*)SvRV(m->mg_obj))
-
-#define MP_SvGROW(sv, len) \
-    (void)SvUPGRADE(sv, SVt_PV); \
-    SvGROW(sv, len+1)
-
-#define MP_SvCUR_set(sv, len) \
-    SvCUR_set(sv, len); \
-    *SvEND(sv) = '\0'; \
-    SvPOK_only(sv)
-
-#define MP_magical_untie(sv, mg_flags) \
-    mg_flags = SvMAGICAL((SV*)sv); \
-    SvMAGICAL_off((SV*)sv)
-
-#define MP_magical_tie(sv, mg_flags) \
-    SvFLAGS((SV*)sv) |= mg_flags
-
+#include "modperl_common_util.h"

  /* XXX: this should be removed */
  #define MP_FAILURE_CROAK(rc_run) do { \
@@ -109,10 +61,6 @@
  int modperl_require_module(pTHX_ const char *pv, int logfailure);
  int modperl_require_file(pTHX_ const char *pv, int logfailure);

-char *modperl_server_desc(server_rec *s, apr_pool_t *p);
-
-MP_INLINE char *modperl_pid_tid(apr_pool_t *p);
-
  void modperl_xs_dl_handles_clear(pTHX);

  void **modperl_xs_dl_handles_get(pTHX);
@@ -123,14 +71,6 @@

  MP_INLINE modperl_uri_t *modperl_uri_new(apr_pool_t *p);

-/* tie %hash */
-MP_INLINE SV *modperl_hash_tie(pTHX_ const char *classname,
-                               SV *tsv, void *p);
-
-/* tied %hash */
-MP_INLINE void *modperl_hash_tied_object(pTHX_ const char *classname,
-                                         SV *tsv);
-
  MP_INLINE void modperl_perl_av_push_elts_ref(pTHX_ AV *dst, AV *src);

  HE *modperl_perl_hv_fetch_he(pTHX_ HV *hv,
@@ -180,14 +120,5 @@
   * @return string of original source code
   */
  char *modperl_coderef2text(pTHX_ apr_pool_t *p, CV *cv);
-
-#ifdef MP_TRACE
-
-void modperl_apr_table_dump(pTHX_ apr_table_t *table, char *name);
-
-/* dump the contents of PL_modglobal */
-void modperl_perl_modglobal_dump(pTHX);
-
-#endif

  #endif /* MODPERL_UTIL_H */
Index: t/apr-ext/perlio.t
===================================================================
RCS file: /home/cvs/modperl-2.0/t/apr-ext/perlio.t,v
retrieving revision 1.4
diff -u -u -r1.4 perlio.t
--- t/apr-ext/perlio.t	28 Aug 2003 01:59:28 -0000	1.4
+++ t/apr-ext/perlio.t	5 May 2004 23:28:57 -0000
@@ -13,11 +13,7 @@
  use Apache::TestUtil;
  use Apache::Build ();

-# XXX: skip for now until the dependency on mod_perl symbols is resolved
-# see STATUS for more info
-# to see the problems run:
-# env PERL_DL_NONLAZY=1 t/TEST -v apr-ext/perlio'
-plan tests => 1, under_construction;
+plan tests => 1;

  use Fcntl ();
  use File::Spec::Functions qw(catfile);
Index: xs/APR/Makefile.PL
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/APR/Makefile.PL,v
retrieving revision 1.3
diff -u -u -r1.3 Makefile.PL
--- xs/APR/Makefile.PL	22 Mar 2003 07:21:37 -0000	1.3
+++ xs/APR/Makefile.PL	5 May 2004 23:28:57 -0000
@@ -2,6 +2,6 @@
  use ModPerl::BuildMM ();

  ModPerl::BuildMM::WriteMakefile(
-    NAME => "APR",
+    NAME => "APR_build",
      VERSION => '0.01'
  );
Index: xs/APR/APR/APR.xs
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/APR/APR/APR.xs,v
retrieving revision 1.10
diff -u -u -r1.10 APR.xs
--- xs/APR/APR/APR.xs	4 Mar 2004 06:01:09 -0000	1.10
+++ xs/APR/APR/APR.xs	5 May 2004 23:28:57 -0000
@@ -15,6 +15,12 @@

  #include "mod_perl.h"

+/* XXX: provide the missing symbol for APR::Pool as a tmp workaround  */
+#ifndef modperl_interp_unselect
+apr_status_t modperl_interp_unselect(void *data);
+apr_status_t modperl_interp_unselect(void *data) { return APR_SUCCESS; }
+#endif
+
  #ifdef MP_HAVE_APR_LIBS
  #   define APR_initialize apr_initialize
  #   define APR_terminate  apr_terminate
Index: xs/APR/APR/Makefile.PL
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/APR/APR/Makefile.PL,v
retrieving revision 1.19
diff -u -u -r1.19 Makefile.PL
--- xs/APR/APR/Makefile.PL	3 Jan 2004 01:17:33 -0000	1.19
+++ xs/APR/APR/Makefile.PL	5 May 2004 23:28:57 -0000
@@ -54,4 +54,32 @@

  $args{LIBS} = [$libs] if $libs;

+my $srcdir = '../../../src/modules/perl';
+
+# link the following into APR.so so other APR:: modules can be used
+# outside of httpd
+my @names = map { "modperl_$_" } (qw(error),
+                                  map { "common_$_" } qw(util log));
+my(@obj, @clean, %src);
+for (@names) {
+    push @obj, join '.', $_, 'o';
+    my $cfile = join '.', $_, 'c';
+    push @clean, $cfile;
+    $src{$cfile} = "$srcdir/$cfile";
+}
+
+$args{OBJECT} = "APR.o @obj";
+$args{clean}  = { FILES => "@clean" };
+
  ModPerl::BuildMM::WriteMakefile(%args);
+
+sub MY::postamble {
+    my $self = shift;
+    my $string = $self->ModPerl::BuildMM::MY::postamble;
+
+    $string .= join '', map {
+        "$_: $src{$_}\n\t\$(CP) $src{$_} .\n";
+    } keys %src;
+
+    return $string;
+}
Index: xs/Apache/Makefile.PL
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/Apache/Makefile.PL,v
retrieving revision 1.3
diff -u -u -r1.3 Makefile.PL
--- xs/Apache/Makefile.PL	22 Mar 2003 07:21:37 -0000	1.3
+++ xs/Apache/Makefile.PL	5 May 2004 23:28:57 -0000
@@ -2,6 +2,6 @@
  use ModPerl::BuildMM ();

  ModPerl::BuildMM::WriteMakefile(
-    NAME => "Apache",
+    NAME => "Apache_build",
      VERSION => '0.01'
  );

--- /dev/null	1969-12-31 16:00:00.000000000 -0800
+++ src/modules/perl/modperl_apr_includes.h	2004-05-05 12:28:38.000000000 -0700
@@ -0,0 +1,38 @@
+/* Copyright 2001-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MODPERL_APR_INCLUDES_H
+#define MODPERL_APR_INCLUDES_H
+
+/* header files for APR */
+
+#ifndef CORE_PRIVATE
+#define CORE_PRIVATE
+#endif
+
+#include "apr_version.h"
+#include "apr_poll.h"
+#include "apr_lib.h"
+#include "apr_strings.h"
+#include "apr_uri.h"
+#include "apr_date.h"
+#include "apr_buckets.h"
+#include "apr_time.h"
+#include "apr_network_io.h"
+#include "apr_general.h"
+#include "apr_uuid.h"
+#include "apr_env.h"
+
+#endif /* MODPERL_APR_INCLUDES_H */

--- /dev/null	1969-12-31 16:00:00.000000000 -0800
+++ src/modules/perl/modperl_common_debug.c	2004-05-05 12:40:01.000000000 -0700
@@ -0,0 +1,19 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* This file must not contain any symbols from apache/mod_perl
+ *  (apr and perl are OK) */
+#include "modperl_common_includes.h"
+

--- /dev/null	1969-12-31 16:00:00.000000000 -0800
+++ src/modules/perl/modperl_common_debug.h	2004-05-05 12:40:17.000000000 -0700
@@ -0,0 +1,20 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MODPERL_COMMON_DEBUG_H
+#define MODPERL_COMMON_DEBUG_H
+
+
+#endif /* MODPERL_COMMON_DEBUG_H */

--- /dev/null	1969-12-31 16:00:00.000000000 -0800
+++ src/modules/perl/modperl_common_includes.h	2004-05-05 12:30:17.000000000 -0700
@@ -0,0 +1,24 @@
+/* Copyright 2001-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MODPERL_COMMON_INCLUDES_H
+#define MODPERL_COMMON_INCLUDES_H
+
+/* header files which are independet of Apache/mod_perl */
+
+#include "modperl_apr_includes.h"
+#include "modperl_perl_includes.h"
+
+#endif /* MODPERL_COMMON_INCLUDES_H */

--- /dev/null	1969-12-31 16:00:00.000000000 -0800
+++ src/modules/perl/modperl_common_log.c	2004-05-05 15:34:18.936976547 -0700
@@ -0,0 +1,91 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "modperl_common_includes.h"
+#include "modperl_common_log.h"
+
+#undef getenv /* from XSUB.h */
+
+static apr_file_t *logfile = NULL;
+
+#ifdef WIN32
+static unsigned long debug_level = 0;
+#else
+unsigned long MP_debug_level = 0;
+#define debug_level MP_debug_level
+#endif
+
+unsigned long modperl_debug_level(void)
+{
+    return debug_level;
+}
+
+void modperl_trace_logfile_set(apr_file_t *logfile_new)
+{
+    logfile = logfile_new;
+}
+
+void modperl_trace(const char *func, const char *fmt, ...)
+{
+    char vstr[8192];
+    apr_size_t vstr_len = 0;
+    va_list args;
+
+    if (!logfile) {
+        return;
+    }
+
+    if (func) {
+        apr_file_printf(logfile, "%s: ", func);
+    }
+
+    va_start(args, fmt);
+    vstr_len = apr_vsnprintf(vstr, sizeof(vstr), fmt, args);
+    va_end(args);
+
+    apr_file_write(logfile, vstr, &vstr_len);
+    apr_file_printf(logfile, "\n");
+}
+
+void modperl_trace_level_set(apr_file_t *logfile, const char *level)
+{
+    if (!level) {
+        if (!(level = getenv("MOD_PERL_TRACE"))) {
+            return;
+        }
+    }
+    debug_level = 0x0;
+
+    if (strcasecmp(level, "all") == 0) {
+        debug_level = 0xffffffff;
+    }
+    else if (apr_isalpha(level[0])) {
+        static char debopts[] = MP_TRACE_OPTS;
+        char *d;
+
+        for (; *level && (d = strchr(debopts, *level)); level++) {
+            debug_level |= 1 << (d - debopts);
+        }
+    }
+    else {
+        debug_level = atoi(level);
+    }
+
+    debug_level |= 0x80000000;
+
+    modperl_trace_logfile_set(logfile);
+
+    MP_TRACE_any_do(MP_TRACE_dump_flags());
+}

--- /dev/null	1969-12-31 16:00:00.000000000 -0800
+++ src/modules/perl/modperl_common_log.h	2004-05-05 15:20:40.327461074 -0700
@@ -0,0 +1,63 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MODPERL_COMMON_LOG_H
+#define MODPERL_COMMON_LOG_H
+
+#define MP_STRINGIFY(n) MP_STRINGIFY_HELPER(n)
+#define MP_STRINGIFY_HELPER(n) #n
+
+#ifdef MP_TRACE
+#   if defined(__GNUC__)
+#      if (__GNUC__ > 2)
+#         define MP_FUNC __func__
+#      else
+#         define MP_FUNC __FUNCTION__
+#      endif
+#   else
+#      define MP_FUNC __FILE__ ":" MP_STRINGIFY(__LINE__)
+#   endif
+#else
+#   define MP_FUNC NULL
+#endif
+
+#include "modperl_apr_includes.h"
+#include "apr_lib.h"
+#include "modperl_trace.h"
+
+#ifdef _PTHREAD_H
+#define modperl_thread_self() pthread_self()
+#else
+#define modperl_thread_self() 0
+#endif
+
+#define MP_TIDF \
+(unsigned long)modperl_thread_self()
+
+void modperl_trace_logfile_set(apr_file_t *logfile_new);
+
+unsigned long modperl_debug_level(void);
+
+#ifdef WIN32
+#define MP_debug_level modperl_debug_level()
+#else
+extern unsigned long MP_debug_level;
+#endif
+
+void modperl_trace(const char *func, const char *fmt, ...);
+
+void modperl_trace_level_set(apr_file_t *logfile, const char *level);
+
+#endif /* MODPERL_COMMON_LOG_H */

--- /dev/null	1969-12-31 16:00:00.000000000 -0800
+++ src/modules/perl/modperl_common_util.c	2004-05-05 13:05:50.000000000 -0700
@@ -0,0 +1,72 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* This file must not contain any symbols from apache/mod_perl (apr
+ *  and perl are OK). Also try to keep all the mod_perl specific
+ *  functions (even if they don't contain symbols from apache/mod_perl
+ *  on in modperl_util.c, unless we want them elsewhere. That is
+ *  needed in order to keep the libraries used outside mod_perl
+ *  small  */
+
+#include "modperl_common_util.h"
+
+MP_INLINE SV *modperl_hash_tie(pTHX_
+                               const char *classname,
+                               SV *tsv, void *p)
+{
+    SV *hv = (SV*)newHV();
+    SV *rsv = sv_newmortal();
+
+    sv_setref_pv(rsv, classname, p);
+    sv_magic(hv, rsv, PERL_MAGIC_tied, Nullch, 0);
+
+    return SvREFCNT_inc(sv_bless(sv_2mortal(newRV_noinc(hv)),
+                                 gv_stashpv(classname, TRUE)));
+}
+
+MP_INLINE void *modperl_hash_tied_object(pTHX_
+                                         const char *classname,
+                                         SV *tsv)
+{
+    if (sv_derived_from(tsv, classname)) {
+        if (SVt_PVHV == SvTYPE(SvRV(tsv))) {
+            SV *hv = SvRV(tsv);
+            MAGIC *mg;
+
+            if (SvMAGICAL(hv)) {
+                if ((mg = mg_find(hv, PERL_MAGIC_tied))) {
+                    return (void *)MgObjIV(mg);
+                }
+                else {
+                    Perl_warn(aTHX_ "Not a tied hash: (magic=%c)", mg);
+                }
+            }
+            else {
+                Perl_warn(aTHX_ "SV is not tied");
+            }
+        }
+        else {
+            return (void *)SvObjIV(tsv);
+        }
+    }
+    else {
+        Perl_croak(aTHX_
+                   "argument is not a blessed reference "
+                   "(expecting an %s derived object)", classname);
+    }
+
+    return NULL;
+}
+

--- /dev/null	1969-12-31 16:00:00.000000000 -0800
+++ src/modules/perl/modperl_common_util.h	2004-05-05 13:17:06.000000000 -0700
@@ -0,0 +1,81 @@
+
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "modperl_common_includes.h"
+
+#ifndef MODPERL_COMMON_UTIL_H
+#define MODPERL_COMMON_UTIL_H
+
+#ifdef MP_DEBUG
+#define MP_INLINE
+#else
+#define MP_INLINE APR_INLINE
+#endif
+
+#ifdef WIN32
+#   define MP_FUNC_T(name) (_stdcall *name)
+/* XXX: not all functions get inlined
+ * so its unclear what to and not to include in the .def files
+ */
+#   undef MP_INLINE
+#   define MP_INLINE
+#else
+#   define MP_FUNC_T(name)          (*name)
+#endif
+
+
+#define MP_SSTRLEN(string) (sizeof(string)-1)
+
+#ifndef strcaseEQ
+#   define strcaseEQ(s1,s2) (!strcasecmp(s1,s2))
+#endif
+#ifndef strncaseEQ
+#   define strncaseEQ(s1,s2,l) (!strncasecmp(s1,s2,l))
+#endif
+
+#ifndef SvCLASS
+#define SvCLASS(o) HvNAME(SvSTASH(SvRV(o)))
+#endif
+
+#define SvObjIV(o) SvIV((SV*)SvRV(o))
+#define MgObjIV(m) SvIV((SV*)SvRV(m->mg_obj))
+
+#define MP_SvGROW(sv, len) \
+    (void)SvUPGRADE(sv, SVt_PV); \
+    SvGROW(sv, len+1)
+
+#define MP_SvCUR_set(sv, len) \
+    SvCUR_set(sv, len); \
+    *SvEND(sv) = '\0'; \
+    SvPOK_only(sv)
+
+#define MP_magical_untie(sv, mg_flags) \
+    mg_flags = SvMAGICAL((SV*)sv); \
+    SvMAGICAL_off((SV*)sv)
+
+#define MP_magical_tie(sv, mg_flags) \
+    SvFLAGS((SV*)sv) |= mg_flags
+
+
+/* tie %hash */
+MP_INLINE SV *modperl_hash_tie(pTHX_ const char *classname,
+                               SV *tsv, void *p);
+
+/* tied %hash */
+MP_INLINE void *modperl_hash_tied_object(pTHX_ const char *classname,
+                                         SV *tsv);
+#endif /* MODPERL_COMMON_UTIL_H */
+

--- /dev/null	1969-12-31 16:00:00.000000000 -0800
+++ src/modules/perl/modperl_debug.c	2004-05-05 13:19:43.000000000 -0700
@@ -0,0 +1,81 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "mod_perl.h"
+
+char *modperl_server_desc(server_rec *s, apr_pool_t *p)
+{
+    return apr_psprintf(p, "%s:%u", s->server_hostname, s->port);
+}
+
+/* used in debug traces */
+MP_INLINE char *modperl_pid_tid(apr_pool_t *p)
+{
+    return apr_psprintf(p, "%lu"
+#if APR_HAS_THREADS
+                 "/%lu"
+#endif /* APR_HAS_THREADS */
+                 , (unsigned long)getpid()
+#if APR_HAS_THREADS
+                 , (unsigned long)apr_os_thread_current()
+#endif /* APR_HAS_THREADS */
+        );
+}
+
+#ifdef MP_TRACE
+/* any non-false value for MOD_PERL_TRACE/PerlTrace enables this function */
+void modperl_apr_table_dump(pTHX_ apr_table_t *table, char *name)
+{
+    int i;
+    const apr_array_header_t *array;
+    apr_table_entry_t *elts;
+
+    array = apr_table_elts(table);
+    elts  = (apr_table_entry_t *)array->elts;
+    modperl_trace(MP_FUNC, "Contents of table %s", name);
+    for (i = 0; i < array->nelts; i++) {
+        if (!elts[i].key || !elts[i].val) {
+            continue;
+        }
+        modperl_trace(MP_FUNC, "%s => %s", elts[i].key, elts[i].val);
+    }
+}
+#endif
+
+#ifdef MP_TRACE
+void modperl_perl_modglobal_dump(pTHX)
+{
+    HV *hv = PL_modglobal;
+    AV *val;
+    char *key;
+    I32 klen;
+    hv_iterinit(hv);
+
+    MP_TRACE_g(MP_FUNC, "|-------- PL_modglobal --------");
+#ifdef USE_ITHREADS
+    MP_TRACE_g(MP_FUNC, "| perl 0x%lx", (unsigned long)aTHX);
+#endif
+    MP_TRACE_g(MP_FUNC, "| PL_modglobal 0x%lx",
+               (unsigned long)PL_modglobal);
+
+    while ((val = (AV*)hv_iternextsv(hv, &key, &klen))) {
+        MP_TRACE_g(MP_FUNC, "| %s => 0x%lx", key, val);
+    }
+
+    MP_TRACE_g(MP_FUNC, "|-------- PL_modglobal --------\n");
+
+}
+#endif
+

--- /dev/null	1969-12-31 16:00:00.000000000 -0800
+++ src/modules/perl/modperl_debug.h	2004-05-05 13:05:13.000000000 -0700
@@ -0,0 +1,30 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MODPERL_DEBUG_H
+#define MODPERL_DEBUG_H
+
+#include "mod_perl.h"
+
+char *modperl_server_desc(server_rec *s, apr_pool_t *p);
+MP_INLINE char *modperl_pid_tid(apr_pool_t *p);
+
+#ifdef MP_TRACE
+void modperl_apr_table_dump(pTHX_ apr_table_t *table, char *name);
+/* dump the contents of PL_modglobal */
+void modperl_perl_modglobal_dump(pTHX);
+#endif
+
+#endif /* MODPERL_DEBUG_H */

--- /dev/null	1969-12-31 16:00:00.000000000 -0800
+++ t/apr-ext/table.t	2004-05-05 16:25:40.287570443 -0700
@@ -0,0 +1,15 @@
+use Apache::Test;
+
+use blib;
+use Apache2;
+
+plan tests => 1;
+
+require APR;
+require APR::Table;
+require APR::Pool;
+
+my $p = APR::Pool->new;
+
+my $table = APR::Table::make($p, 2);
+ok ref $table eq 'APR::Table';

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Mime
View raw message