apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gst...@locus.apache.org
Subject cvs commit: apr-util/test .cvsignore Makefile.in testdbm.c
Date Sat, 09 Dec 2000 09:07:15 GMT
gstein      00/12/09 01:07:15

  Modified:    src/dbm  apr_dbm.c
               test     .cvsignore Makefile.in testdbm.c
  Log:
  *) some DBMs need cleanups registered for the memory they return, just in
     case the caller forgets to call apr_dbm_freedatum() on it.
  
  *) add testdbm to .cvsignore
  
  *) add more dependencies on the testdbm make target
  
  *) testdbm: proactively toss the pool [and terminate APR]. it seemed the
     pool wasn't getting registered within APR for cleanup(?)
  
  Revision  Changes    Path
  1.10      +35 -7     apr-util/src/dbm/apr_dbm.c
  
  Index: apr_dbm.c
  ===================================================================
  RCS file: /home/cvs/apr-util/src/dbm/apr_dbm.c,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -u -r1.9 -r1.10
  --- apr_dbm.c	2000/12/08 17:18:08	1.9
  +++ apr_dbm.c	2000/12/09 09:07:14	1.10
  @@ -71,7 +71,7 @@
   #define APR_DBM_DELETE(f, k)	sdbm_delete((f), (k))
   #define APR_DBM_FIRSTKEY(f)	sdbm_firstkey(f)
   #define APR_DBM_NEXTKEY(f, k)	sdbm_nextkey(f)
  -#define APR_DBM_FREEDATUM(f, d)	if (0) ; else	/* stop "no effect" warning */
  +#define APR_DBM_FREEDPTR(dptr)	if (0) ; else	/* stop "no effect" warning */
   
   #define APR_DBM_DBMODE_RO       APR_READ
   #define APR_DBM_DBMODE_RW       (APR_READ | APR_WRITE)
  @@ -90,8 +90,10 @@
   #define APR_DBM_DELETE(f, k)	g2s(gdbm_delete((f), (k)))
   #define APR_DBM_FIRSTKEY(f)	gdbm_firstkey(f)
   #define APR_DBM_NEXTKEY(f, k)	gdbm_nextkey((f), (k))
  -#define APR_DBM_FREEDATUM(f, d)	((d).dptr ? free((d).dptr) : 0)
  +#define APR_DBM_FREEDPTR(dptr)	((dptr) ? free(dptr) : 0)
   
  +#define NEEDS_CLEANUP
  +
   #define APR_DBM_DBMODE_RO       GDBM_READER
   #define APR_DBM_DBMODE_RW       GDBM_WRITER
   #define APR_DBM_DBMODE_RWCREATE GDBM_WRCREAT
  @@ -126,6 +128,26 @@
   #define R2A_DATUM(d)    (*(apr_datum_t *)&(d))
   
   
  +#ifdef NEEDS_CLEANUP
  +
  +static apr_status_t datum_cleanup(void *dptr)
  +{
  +    APR_DBM_FREEDPTR(dptr);
  +    return APR_SUCCESS;
  +}
  +
  +#define REG_CLEANUP(db, pdatum) \
  +    if ((pdatum)->dptr) \
  +        apr_register_cleanup((db)->pool, (pdatum)->dptr, \
  +                             datum_cleanup, apr_null_cleanup); \
  +    else
  +
  +#else /* NEEDS_CLEANUP */
  +
  +#define REG_CLEANUP(db, pdatum) if (0) ; else   /* stop "no effect" warning */
  +
  +#endif /* NEEDS_CLEANUP */
  +
   static apr_status_t set_error(apr_dbm_t *db)
   {
       apr_status_t rv = APR_SUCCESS;
  @@ -217,6 +239,8 @@
   {
       *(real_datum_t *) pvalue = APR_DBM_FETCH(db->file, A2R_DATUM(key));
   
  +    REG_CLEANUP(db, pvalue);
  +
       /* store the error info into DB, and return a status code. Also, note
          that *pvalue should have been cleared on error. */
       return set_error(db);
  @@ -272,6 +296,8 @@
   {
       *(real_datum_t *) pkey = APR_DBM_FIRSTKEY(db->file);
   
  +    REG_CLEANUP(db, pkey);
  +
       /* store the error info into DB, and return a status code. Also, note
          that *pvalue should have been cleared on error. */
       return set_error(db);
  @@ -281,18 +307,20 @@
   {
       *(real_datum_t *) pkey = APR_DBM_NEXTKEY(db->file, A2R_DATUM(*pkey));
   
  +    REG_CLEANUP(db, pkey);
  +
       /* store the error info into DB, and return a status code. Also, note
          that *pvalue should have been cleared on error. */
       return set_error(db);
   }
   
  -/* XXX: This is wrong - we must call freedatum after moving the
  - * datum contents into the pool before we return, the user can't
  - * concern themselves with free in a pool-managed application.
  - */
   void apr_dbm_freedatum(apr_dbm_t *db, apr_datum_t data)
   {
  -    APR_DBM_FREEDATUM(db, data);
  +#ifdef NEEDS_CLEANUP
  +    (void) apr_run_cleanup(db->pool, data.dptr, datum_cleanup);
  +#else
  +    APR_DBM_FREEDPTR(data.dptr);
  +#endif
   }
   
   /* XXX: This is wrong... need to return a canonical errcode as part
  
  
  
  1.2       +1 -0      apr-util/test/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  RCS file: /home/cvs/apr-util/test/.cvsignore,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- .cvsignore	2000/12/02 16:13:50	1.1
  +++ .cvsignore	2000/12/09 09:07:14	1.2
  @@ -2,3 +2,4 @@
   *.lo
   *.la
   .libs
  +testdbm
  
  
  
  1.4       +1 -1      apr-util/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apr-util/test/Makefile.in,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -u -r1.3 -r1.4
  --- Makefile.in	2000/12/08 22:50:39	1.3
  +++ Makefile.in	2000/12/09 09:07:14	1.4
  @@ -8,5 +8,5 @@
   
   testdbm_OBJECTS = testdbm.lo
   testdbm_LDADD =  ../libaprutil.la @APR_SOURCE_DIR@/libapr.a
  -testdbm: $(testdbm_OBJECTS)
  +testdbm: $(testdbm_OBJECTS) $(testdbm_LDADD)
   	$(LINK) $(testdbm_OBJECTS) $(testdbm_LDADD) $(LIBS)
  
  
  
  1.4       +3 -2      apr-util/test/testdbm.c
  
  Index: testdbm.c
  ===================================================================
  RCS file: /home/cvs/apr-util/test/testdbm.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -u -r1.3 -r1.4
  --- testdbm.c	2000/12/08 18:05:33	1.3
  +++ testdbm.c	2000/12/09 09:07:14	1.4
  @@ -135,8 +135,6 @@
       const char *optarg;
   
       (void) apr_initialize();
  -    atexit(apr_terminate);
  -
       apr_create_pool(&pool, NULL);
   
       (void) apr_initopt(&os, pool, argc, argv);
  @@ -161,6 +159,9 @@
           badk(argv[os->ind]);
       os->ind++;
       doit(act, argv[os->ind], pool);
  +
  +    apr_destroy_pool(pool);
  +    apr_terminate();
       return 0;
   }
   
  
  
  

Mime
View raw message