Login | Register
My pages Projects Community openCollabNet

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Catacomb] RE: Porting changes for Catacomb for Microsoft Visual C



Cool!

 

Thanks you so much.

Is Catacomb works well in Windows?

 

Do you want to me make a branch for you?

 

--

Sung Kim

 


From: Andrew Morrow (BTS) [mailto:amorrow@blacktulipsystems.com]
Sent: Thursday, December 18, 2003 8:28 PM
To: Sunghun Kim
Cc: Andrew Morrow (Nouveau)
Subject: Porting changes for Catacomb for Microsoft Visual C

 

 

Mr. Kim:

 

I have ported Catacomb 0.9.0 to Microsoft Visual C 6.0 and I would like to share what I have learned with you.

 

I will include the raw diffs as part of this message

Most of the changes I made highlight what portability problems I found.

 

A usage note: I noticed that you do not update the modfication date of the directory when files are added or deleted.  It would be helpful to do this because when viewing the HTML view of the repository, this update would be reflected in the page modification date.  This is important because modern web browsers cache and reload only when the modification date of the page has changed.  In other words, if you visit a repos directory with your web browsre, then add file to that repos directory, and then hit reload on your web browser, you will not see the change because the mod date on the generated page is still the same.  On Internet Explorer, you have to clear your cache, exit IE, restart IE and then revisit the page before you see the udpate.  You could also solve this problem by just having a "Cache-control: no-cache" HTTP response header, but the modification date update is the most general solution.

 

 

 

 

Line items of what changes I made:

 

- Turned on DEBUG (which you will ignore, I expect)

 

- Added some extra calls to DBG*(), which you can ignore

 

- Implemented my own DBG* functions to perform a primitive (and not thread-safe) write to a file because I could not get Apache logging to work on Windows (I am not sure if there is a way to get the log to work correctly on Apache.  Maybe I just had my logging configuration wrong.  I was running Apache as a console app on my desktop and I did not see any lines form the DBG*() calls).

 

- Used __FILE__, __LINE__ macros rather than GCC-specific __FUNCTION__

 

- Add dummy field to avoid have an empty struct (GCC allows this but MSVC does not)

 

- Propigate the status code in dbms_opendb()/dbms_closedb() (your versoin always returns success code, which seems wrong to me)

 

- Use dav_repos_mk_blank_resource() rather than just apr_pcalloc(), where possible

 

- Check for both 0 and DAV_REPOS_NODATA, where appropriate

 

- Use apr_time_t, rather than "long long"

 

- Use apr_atoi64() rather than atoll()

 

- Implemented a version of lltoa() for Windows, but it is not thread-safe

 

- Hack: Just use NULL rather than call dav_lock_get_activelock() because it is not exported in the current pre-built release of Apache.  Maybe you can get the folks at Apache to get this routine properly exported for Windows.

 

-  dav_find_child() is also not exported on Windows, but as a workaround,  you can just copy the code for this utility function since the structures involved are all public

 

 

 

 

 

There are eight files and I have changed and one new file

 

The new file is porting.h with a very simplistic approach to abstracting GCC-specifc features.

 

 

The files that I changed were:


dav_repos.h
dbms.c
dbms.h
dbms_mysql.c
dbms_mysql.h
repos.c
search.c
util.c

 

 

 

Only in .: porting.h  (new file)

#include <stdlib.h>
#ifdef WIN32
#define my_inline
#define atoll(i) apr_atoi64(i)
extern char * my_lltoa(_int64);
#else
/* Assume GCC for all else */
#define my_inline inline
#define my_lltoa(ll) lltoa(ll)
#endif

 

Here are the raw changes, relatvie to release 0.9.0 :

 

 

 

diff ../../catacomb-0.9.0_orig/dav_repos.h /dav_repos.h
73a74,75
> #define DEBUG 1
>
83a86,102
> #else
>
> #ifdef WIN32
> extern void my_dbg0(const char*);
> extern void my_dbg1(const char*, const void*);
> extern void my_dbg2(const char*, const void*, const void*);
> extern void my_dbg3(const char*, const void*, const void*, const void*);
> #undef DBG0
> #undef DBG1
> #undef DBG2
> #undef DBG3
> #define DBG0(f) my_dbg0(f)
> #define DBG1(f,a1) my_dbg1(f,a1)
> #define DBG2(f,a1,a2)  my_dbg2(f,a1,a2)
> #define DBG3(f,a1,a2,a3)  my_dbg3(f,a1,a2,a3)
> #endif /* WIN32 */
>
86c105,109
< #define TRACE() DBG1("- TRACE : %s",  __func__ )
---
> #ifdef WIN32
> #define TRACE() DBG2("- TRACE :%s %d", __FILE__, (char *) __LINE__)
> #else
> #define TRACE() DBG1("- TRACE :%s", __FUNCTION__)
> #endif
101a125,126
> #else
>  int dummy;  /* MSVC does not like empty struct */

 


diff ../../catacomb-0.9.0_orig/dbms.c ./dbms.c
104a105,107
>  DBG1("db_error_message: str=%s",db_error_message_str);
>  DBG1("db_error_message: errno=%d", dbms_errno(db));
>  DBG1("db_error_message: db_error=%s", dbms_error(pool, db));
140a144
>  int status;
143,144c147,149
<     dbms_create(&(d->db), d->db_id, d->db_pass, d->db_name, d->db_host, 0);
<     return 0;
---
>     status = dbms_create(&(d->db), d->db_id, d->db_pass, d->db_name, d->db_host, 0);
> /* Why did orig always return 0 ? */
>     return status;
153a159
>  int status;
156,157c162,163
<     dbms_destroy(&(d->db));
<     return 0;
---
>     status = dbms_destroy(&(d->db));
>     return status;
324a331,333
>
>  DBG1("New serialno=%ld", *lserialno);
>
2540a2550,2551
>  DBG1("dbms_open_stream: serialno=%ld\n",db_r->serialno);
>
2543c2554
<     if (!db_r->serialno) {
---
>     if (db_r->serialno == 0 || db_r->serialno == DAV_REPOS_NODATA) {

 


diff ../../catacomb-0.9.0_orig/dbms.h ./dbms.h
74a75
> #include "porting.h"
102c103
<     long long creationdate;
---
>     apr_time_t creationdate;
108c109
<     long long getlastmodified;  /* Extra. Not in database table */
---
>     apr_time_t getlastmodified;  /* Extra. Not in database table */

 


diff ../../catacomb-0.9.0_orig/dbms_mysql.c ./dbms_mysql.c
11a12,15
> #ifdef WIN32
> #include "dav_repos.h" /* Only for DBG hacks */
> #endif
>
13c17
< static inline int debug_mysql(const int status, MYSQL *mysql,
---
> static my_inline int debug_mysql(const int status, MYSQL *mysql,
27c31
< static inline int debug_apr(const apr_status_t status) {
---
> static my_inline int debug_apr(const apr_status_t status) {
98c102
<  const int num, const long long value) {
---
>  const int num, const apr_int64_t value) {
99a104,107
> #ifdef WIN32
>     /* TODO: lltoa is not thread-safe */
>     query->parameters[num - 1] = apr_pstrdup(query->pool, my_lltoa(value));
> #else
100a109
> #endif
209c218
< long long dbms_get_int(dav_repos_query *query,
---
> apr_int64_t dbms_get_int(dav_repos_query *query,
214c223
<     return atoll(query->row[column - 1]);
---
>     return apr_atoi64(query->row[column - 1]);

 


diff ../../catacomb-0.9.0_orig/dbms_mysql.h ./dbms_mysql.h
4a5
> #include "porting.h"
73c74
<     const char *host, int port);
---
>     const char *host, const int port);
122c123
<  const int num, const long long value);
---
>  const int num, const apr_int64_t value);
181c182
< long long dbms_get_int(dav_repos_query *query, int column);
---
> apr_int64_t dbms_get_int(dav_repos_query *query, int column);

 


diff ../../catacomb-0.9.0_orig/repos.c ./repos.c
281,282c281,284
<     db_r = apr_pcalloc(pool, sizeof(*db_r));
<    
---
>     /* db_r = apr_pcalloc(pool, sizeof(*db_r)); */
>
>  db_r = dav_repos_mk_blank_resource(pool);
>
349a352
>  DBG1("calculated depth=%d",db_r->depth);
419c422,424
<     db_r = apr_pcalloc(resource->pool, sizeof(*db_r));
---
>     /* db_r = apr_pcalloc(resource->pool, sizeof(*db_r)); */
>  db_r = dav_repos_mk_blank_resource(pool);
>
521c526
<  if (db_r->creationdate == 0)
---
>  if (db_r->creationdate == 0 || db_r->creationdate == DAV_REPOS_NODATA )

 

 

diff ../../catacomb-0.9.0_orig/search.c /search.c
178,180c178,180
<     search_result = (dav_repos_resource *) apr_pcalloc(r->pool,
<              sizeof
<              (*search_result));
---
>     /* search_result = (dav_repos_resource *) apr_pcalloc(r->pool, sizeof (*search_result)); */
>  search_result = dav_repos_mk_blank_resource(r->pool);
>

 

 

 

diff ../../catacomb-0.9.0_orig/util.c /util.c
701a702,710
> #ifdef WIN32
>         /* AWM: The standard Window build does not have
>                 this function exported in the DLL!
>                 What is the proper thing to do here?
>                 Build Apache ourselves and fix the export table? */
>                  DBG0("Using NULL lockdiscovery!");
>
>             db_r->lockdiscovery = NULL;
> #else
710a720
> #endif
870a881,952
> #ifdef WIN32
>
> /* dav_find_child() is not exported in Apache's DLL.
> Copy this from Apache2/modules/dav/main/util.c
> */
>
> /* find and return the (unique) child with a given DAV: tagname */
> apr_xml_elem *dav_find_child(const apr_xml_elem *elem, const char *tagname)
> {
>     apr_xml_elem *child = elem->first_child;
>
>     for (; child; child = child->next)
>         if (child->ns == APR_XML_NS_DAV_ID && !strcmp(child->name, tagname))
>             return child;
>     return NULL;
> }

>
>
>
> FILE *f1 = NULL;
>
> void init_f1(){
>  if(f1==NULL){
>   f1=fopen("C:/temp/q.log","a");
>  }

> }
>
> void fini_f1(){
>  if(f1!=NULL){
>   fclose(f1);
>   f1=NULL;
>  }

> }
>
> void my_dbg0(const char *f){
>  init_f1();
>  fprintf(f1,f);
>  fprintf(f1,"\n");
>  fini_f1();
> }

>
> void my_dbg1(const char *f, const void *a1){
>  init_f1();
>  fprintf(f1,f,a1);
>  fprintf(f1,"\n");
>  fini_f1();
> }

>
> void my_dbg2(const char *f, const void* a1, const void* a2){
>  init_f1();
>  fprintf(f1,f,a1,a2);
>  fprintf(f1,"\n");
>  fini_f1();
> }

>
> void my_dbg3(const char *f, const void *a1, const void* a2, const void* a3){
>  init_f1();
>  fprintf(f1,f,a1,a2,a3);
>  fprintf(f1,"\n");
>  fini_f1();
> }

>
> /* Not thread-safe. */
> static char t[50]; /* Documented as up to 33 bytes */
>
> char * my_lltoa(_int64 value) {
>  char *s;
>  /**/
>  s = _i64toa(value,t,10);
>  return (char *)&t;
> }

>
871a954
> #endif /* WIN32 */