chiark / gitweb /
Reentrancy: Introduce adns__returning
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 12 Oct 2014 20:35:25 +0000 (21:35 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 19 Oct 2014 20:09:56 +0000 (21:09 +0100)
Replace all the adns__consistency calls on the return paths from adns
with adns__returning (except in setup.c, whose functions never set up
any queries).

I have separately gone through the public entrypoints in adns.h and
checked that they have the expected adns__consistency calls.  So with
this patch, the new imprecation about adns__returning is satisfied.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/event.c
src/internal.h
src/poll.c
src/query.c

index 52a2efcb13084a8ab2b6e0cd6e1b9447093c4bf2..5b2b42df3a0e2ad01cff09a33253f179ea8d12ed 100644 (file)
@@ -286,7 +286,7 @@ void adns_firsttimeout(adns_state ads,
                       struct timeval now) {
   adns__consistency(ads,0,cc_entex);
   adns__timeouts(ads, 0, tv_io,tvbuf, now);
-  adns__consistency(ads,0,cc_entex);
+  adns__returning(ads,0);
 }
 
 void adns_processtimeouts(adns_state ads, const struct timeval *now) {
@@ -295,7 +295,7 @@ void adns_processtimeouts(adns_state ads, const struct timeval *now) {
   adns__consistency(ads,0,cc_entex);
   adns__must_gettimeofday(ads,&now,&tv_buf);
   if (now) adns__timeouts(ads, 1, 0,0, *now);
-  adns__consistency(ads,0,cc_entex);
+  adns__returning(ads,0);
 }
 
 /* fd handling functions.  These are the top-level of the real work of
@@ -426,7 +426,7 @@ int adns_processreadable(adns_state ads, int fd, const struct timeval *now) {
   }
   r= 0;
 xit:
-  adns__consistency(ads,0,cc_entex);
+  adns__returning(ads,0);
   return r;
 }
 
@@ -483,7 +483,7 @@ int adns_processwriteable(adns_state ads, int fd, const struct timeval *now) {
   }
   r= 0;
 xit:
-  adns__consistency(ads,0,cc_entex);
+  adns__returning(ads,0);
   return r;
 }
   
@@ -502,7 +502,7 @@ int adns_processexceptional(adns_state ads, int fd,
   default:
     abort();
   }
-  adns__consistency(ads,0,cc_entex);
+  adns__returning(ads,0);
   return 0;
 }
 
@@ -579,7 +579,7 @@ void adns_beforeselect(adns_state ads, int *maxfd_io, fd_set *readfds_io,
   *maxfd_io= maxfd;
 
 xit:
-  adns__consistency(ads,0,cc_entex);
+  adns__returning(ads,0);
 }
 
 void adns_afterselect(adns_state ads, int maxfd, const fd_set *readfds,
@@ -601,7 +601,7 @@ void adns_afterselect(adns_state ads, int maxfd, const fd_set *readfds,
                 maxfd,readfds,writefds,exceptfds,
                 *now, 0);
 xit:
-  adns__consistency(ads,0,cc_entex);
+  adns__returning(ads,0);
 }
 
 /* General helpful functions. */
@@ -623,7 +623,7 @@ void adns_globalsystemfailure(adns_state ads) {
   default:
     abort();
   }
-  adns__consistency(ads,0,cc_entex);
+  adns__returning(ads,0);
 }
 
 int adns_processany(adns_state ads) {
@@ -648,7 +648,7 @@ int adns_processany(adns_state ads) {
                 0,0,0,0,
                 now,&r);
 
-  adns__consistency(ads,0,cc_entex);
+  adns__returning(ads,0);
   return 0;
 }
 
@@ -712,7 +712,7 @@ int adns_wait(adns_state ads,
       adns_afterselect(ads,maxfd,&readfds,&writefds,&exceptfds,0);
     }
   }
-  adns__consistency(ads,0,cc_entex);
+  adns__returning(ads,0);
   return r;
 }
 
@@ -728,6 +728,6 @@ int adns_check(adns_state ads,
   if (!r) adns__autosys(ads,now);
 
   r= adns__internal_check(ads,query_io,answer_r,context_r);
-  adns__consistency(ads,0,cc_entex);
+  adns__returning(ads,0);
   return r;
 }
index 0374accfa56b3db401b914d1622f7968775436e2..13740b293a8e395ba7edd0ff49e53906d5723a30 100644 (file)
@@ -708,6 +708,10 @@ void adns__query_done(adns_query qu);
 void adns__query_fail(adns_query qu, adns_status stat);
 void adns__cancel_children(adns_query qu);
 
+void adns__returning(adns_state ads, adns_query qu);
+/* Must be called before returning from adns any time that we have
+ * progressed (including made, finished or destroyed) queries. */
+
 /* From reply.c: */
 
 void adns__procdgram(adns_state ads, const byte *dgram, int len,
index 25075ed8dbf061850801f346e220a83f7b4e8bf9..60ff6ecf26f2c5dacc465e013ef22bf03db381ac 100644 (file)
@@ -77,7 +77,7 @@ int adns_beforepoll(adns_state ads, struct pollfd *fds, int *nfds_io,
   }
   r= 0;
 xit:
-  adns__consistency(ads,0,cc_entex);
+  adns__returning(ads,0);
   return r;
 }
 
@@ -91,7 +91,7 @@ void adns_afterpoll(adns_state ads, const struct pollfd *fds, int nfds,
     adns__timeouts(ads, 1, 0,0, *now);
     adns__fdevents(ads, fds,nfds, 0,0,0,0, *now,0);
   }
-  adns__consistency(ads,0,cc_entex);
+  adns__returning(ads,0);
 }
 
 int adns_wait_poll(adns_state ads,
@@ -123,7 +123,7 @@ int adns_wait_poll(adns_state ads,
   }
 
  xit:
-  adns__consistency(ads,0,cc_entex);
+  adns__returning(ads,0);
   return r;
 }
 
index 6a1ec75ffd8df3b0d838793d8c6b0e1a76736e2b..3e93fc2ef81a54b601d7bb51ca1a3b6799e8e181 100644 (file)
@@ -312,18 +312,18 @@ int adns_submit(adns_state ads,
     query_simple(ads,qu, owner,ol, typei,flags, now);
   }
   adns__autosys(ads,now);
-  adns__consistency(ads,qu,cc_entex);
+  adns__returning(ads,qu);
   return 0;
 
  x_adnsfail:
   adns__query_fail(qu,stat);
-  adns__consistency(ads,qu,cc_entex);
+  adns__returning(ads,qu);
   return 0;
 
  x_errno:
   r= errno;
   assert(r);
-  adns__consistency(ads,0,cc_entex);
+  adns__returning(ads,0);
   return r;
 }
 
@@ -496,6 +496,10 @@ static void free_query_allocs(adns_query qu) {
   qu->query_dgram= 0;
 }
 
+void adns__returning(adns_state ads, adns_query qu_for_caller) {
+  adns__consistency(ads,qu_for_caller,cc_entex);
+}
+
 void adns_cancel(adns_query qu) {
   adns_state ads;
 
@@ -521,7 +525,7 @@ void adns_cancel(adns_query qu) {
   free_query_allocs(qu);
   free(qu->answer);
   free(qu);
-  adns__consistency(ads,0,cc_entex);
+  adns__returning(ads,0);
 }
 
 void adns__update_expires(adns_query qu, unsigned long ttl,