httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randy Kobes <ra...@theoryx5.uwinnipeg.ca>
Subject [multi-env] library/t/parsers.t on Win32
Date Fri, 11 Mar 2005 05:19:12 GMT
Currently on Win32 the first 3 tests of library/t/parsers.c
fail, which involve comparing, for example,
 f = apreq_parser(URL_ENCTYPE);
 AT_eq(f, (apreq_parser_function_t)apreq_parser_urlencoded, "%pp");

In trying to understand why, I looked at the following
program, which uses a function get_fn(char) to return
a function (either afn or bfn) depending on the argument
passed in:
==============================================================
// file a.c
#include <stdio.h>
void afn(void);
void bfn(void);
typedef void (*fn)();
fn get_fn(char);

int main(void) {
  fn f;
  f = get_fn('a');
  printf("f=%p and afn=%p\n", f, afn);
  f = get_fn('b');
  printf("f=%p and bfn=%p\n", f, bfn);
}
fn get_fn(char c) {
  fn g;
  g = (c == 'a') ? afn : bfn;
  return g;
}
void afn(void) {
   printf("HELLO from afn\n");
}
void bfn(void) {
   printf("HELLO from bfn\n");
}
=================================================================
This prints out
================================================================
f=0040107A and afn=0040107A
f=0040108C and bfn=0040108C
=================================================================
as might be expected.

However, if one splits off get_fn, afn, and bfn into
a dll:
=================================================================
// file b.h
#define DECLARE_NONSTD(type) __declspec(dllexport) type
#define DECLARE(f) DECLARE_NONSTD(void) (f) (void)
typedef void (*fn)();
DECLARE(afn);
DECLARE(bfn);
DECLARE_NONSTD(fn) get_fn(char);
================================================================
and
================================================================
// file b.c
#include <stdio.h>
#include "b.h"

DECLARE(afn) {
   printf("HELLO from afn\n");
}

DECLARE(bfn) {
   printf("HELLO from bfn\n");
}

DECLARE_NONSTD(fn) get_fn(char c) {
  fn g;
  g = (c == 'a') ? afn : bfn;
  return g;
}
===============================================================
and then links the following program against this dll:
==============================================================
// file c.c
#include <stdio.h>
#include "b.h"

int main(void) {
  fn f;
  f = get_fn('a');
  printf("f=%p and afn=%p\n", f, afn);
  f = get_fn('b');
  printf("f=%p and bfn=%p\n", f, bfn);
}
================================================================
one obtains
================================================================
f=10001000 and afn=00401054
f=1000100D and bfn=0040104E
================================================================

Perhaps someone with more knowledge of dlls will know why
there's this difference, and in particular why the output of
the last program has the pointers unequal. However, unless
there's something fundamentally wrong in the last program,
what I think this illustrates is that, when these functions
are split off into a dll, a comparison of pointers in this
way isn't straightforward. Thus, perhaps it makes sense
to skip the first 3 tests of library/t/parsers.t on Win32?

-- 
best regards,
randy

Mime
View raw message