couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r792010 - in /couchdb/trunk: THANKS src/couchdb/couch_js.c src/couchdb/curlhelper.c
Date Wed, 08 Jul 2009 01:26:05 GMT
Author: davisp
Date: Wed Jul  8 01:26:04 2009
New Revision: 792010

URL: http://svn.apache.org/viewvc?rev=792010&view=rev
Log:
Fixes COUCHDB-402

Thanks Mark Hammond


Modified:
    couchdb/trunk/THANKS
    couchdb/trunk/src/couchdb/couch_js.c
    couchdb/trunk/src/couchdb/curlhelper.c

Modified: couchdb/trunk/THANKS
URL: http://svn.apache.org/viewvc/couchdb/trunk/THANKS?rev=792010&r1=792009&r2=792010&view=diff
==============================================================================
--- couchdb/trunk/THANKS (original)
+++ couchdb/trunk/THANKS Wed Jul  8 01:26:04 2009
@@ -31,5 +31,6 @@
  * Nick Gerakines <nick@gerakines.net>
  * Robert Newson <robert.newson@gmail.com>
  * Bob Dionne <dionne@member.fsf.org>
+ * Mark Hammond <mhammond@skippinet.com.au>
 
 For a list of authors see the `AUTHORS` file.

Modified: couchdb/trunk/src/couchdb/couch_js.c
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_js.c?rev=792010&r1=792009&r2=792010&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_js.c (original)
+++ couchdb/trunk/src/couchdb/couch_js.c Wed Jul  8 01:26:04 2009
@@ -434,21 +434,21 @@
 }* BufferCount;
 
 size_t curl_read(void *ptr, size_t size, size_t nmemb, void *stream) {
-  if( size == 0 || nmemb == 0) {
-    return 0;
-  }
-
+  int readlength, spaceleft, i;
   char* databuffer = (char*)ptr;
   Buffer b = ((BufferCount)stream)->buffer;
   int* pos = &(((BufferCount)stream)->pos);
 
+  if( size == 0 || nmemb == 0) {
+    return 0;
+  }
+
   if((b->count - *pos) == 0) {
     return 0;
   }
 
-  int readlength = size*nmemb;
-  int spaceleft = b->count - *pos;
-  int i;
+  readlength = size*nmemb;
+  spaceleft = b->count - *pos;
 
   if(readlength < spaceleft) {
     copy_Buffer(b,databuffer,*pos,readlength);
@@ -462,11 +462,10 @@
 }
 
 size_t curl_write(void *ptr, size_t size, size_t nmemb, void *stream) {
-  if( size == 0 || nmemb == 0 )
-    return 0;
-
   char *data, *tmp;
   Buffer b;
+  if( size == 0 || nmemb == 0 )
+    return 0;
 
   data = (char *)ptr;
   b = (Buffer)stream;
@@ -478,13 +477,13 @@
 
 // This uses MALLOC dont forget to free
 char* JSValToChar(JSContext* context, jsval* arg) {
-  if(!JSVAL_IS_STRING(*arg)) {
-    return NULL;
-  }
-
   char *c, *tmp;
   JSString *jsmsg;
   size_t len;
+  int i;
+  if(!JSVAL_IS_STRING(*arg)) {
+    return NULL;
+  }
 
   jsmsg = JS_ValueToString(context,*arg);
   len = JS_GetStringLength(jsmsg);
@@ -493,8 +492,6 @@
   c = (char*)malloc(len+1);
   c[len] = '\0';
 
-  int i;
-
   for(i = 0;i < len;i++) {
     c[i] = tmp[i];
   }
@@ -534,17 +531,23 @@
 
     struct curl_slist *slist = NULL;
     JSObject* header_obj;
+    JSObject* iterator;
+    jsval *jsProperty;
+    jsval *jsValue;
+    jsid *jsId;
+    Buffer bTmp;
+    char* jsPropertyName, *jsPropertyValue;
 
     // If we fail to convert arg2 to an object. Error!
     if(!JS_ValueToObject(context,*arg,&header_obj)) {
       return NULL;
     }
 
-    JSObject* iterator = JS_NewPropertyIterator(context,header_obj);
+    iterator = JS_NewPropertyIterator(context,header_obj);
 
-    jsval *jsProperty = JS_malloc(context,sizeof(jsval));
-    jsval *jsValue = JS_malloc(context,sizeof(jsval));
-    jsid *jsId = JS_malloc(context,sizeof(jsid));
+    jsProperty = JS_malloc(context,sizeof(jsval));
+    jsValue = JS_malloc(context,sizeof(jsval));
+    jsId = JS_malloc(context,sizeof(jsid));
 
     while(JS_NextProperty(context,iterator,jsId) == JS_TRUE) {
 
@@ -554,16 +557,16 @@
 
       // TODO: Refactor this maybe make a JSValAppendBuffer method b/c that is what you really
want to do.
 
-      Buffer bTmp = init_Buffer();
+      bTmp = init_Buffer();
       JS_IdToValue(context,*jsId,jsProperty);
-      char* jsPropertyName = JSValToChar(context,jsProperty);
+      jsPropertyName = JSValToChar(context,jsProperty);
 
       // TODO: Remove strlen =/
       append_Buffer(bTmp,jsPropertyName,strlen(jsPropertyName));
       append_Buffer(bTmp,": ",2);
 
       JS_GetProperty(context,header_obj,jsPropertyName,jsValue);
-      char* jsPropertyValue = JSValToChar(context,jsValue);
+      jsPropertyValue = JSValToChar(context,jsValue);
       // TODO: Remove strlen =/
       append_Buffer(bTmp,jsPropertyValue,strlen(jsPropertyValue));
       append_Buffer(bTmp,"",1);
@@ -592,6 +595,8 @@
   Buffer b;
   char *url;
   size_t charslen, readlen;
+  struct curl_slist *slist;
+  int exitcode;
 
   // Run GC
   JS_MaybeGC(context);
@@ -620,14 +625,12 @@
   curl_easy_setopt(handle,CURLOPT_NOPROGRESS,1);
   curl_easy_setopt(handle,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);
 
-  struct curl_slist *slist = generateCurlHeaders(context,argv+1);
+  slist = generateCurlHeaders(context,argv+1);
   if(slist != NULL) {
     curl_easy_setopt(handle,CURLOPT_HTTPHEADER,slist);
   }
 
   // Perform
-  int exitcode;
-
   if((exitcode = curl_easy_perform(handle)) != 0) {
     if(slist != NULL) {
       curl_slist_free_all(slist);
@@ -676,6 +679,8 @@
   Buffer b;
   char *url;
   size_t charslen, readlen;
+  struct curl_slist *slist;
+  int exitcode;
 
   // Run GC
   JS_MaybeGC(context);
@@ -704,7 +709,7 @@
   curl_easy_setopt(handle,CURLOPT_NOPROGRESS,1);
   curl_easy_setopt(handle,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);
 
-  struct curl_slist *slist = generateCurlHeaders(context,argv+1);
+  slist = generateCurlHeaders(context,argv+1);
   if(slist != NULL) {
     curl_easy_setopt(handle,CURLOPT_HTTPHEADER,slist);
   }
@@ -712,8 +717,6 @@
   // fprintf(stderr, "about to run HEAD request\n");
 
   // Perform
-  int exitcode;
-
   if((exitcode = curl_easy_perform(handle)) != 0) {
     if(slist != NULL) {
       curl_slist_free_all(slist);
@@ -764,6 +767,8 @@
   Buffer b;
   char *url, *body;
   size_t charslen, readlen;
+  struct curl_slist *slist;
+  int exitcode;
 
   // Run GC
   JS_MaybeGC(context);
@@ -801,13 +806,11 @@
   curl_easy_setopt(handle,CURLOPT_POSTFIELDSIZE,strlen(body));
   curl_easy_setopt(handle,CURLOPT_POSTFIELDS,body);         // Curl wants '\0' terminated,
we oblige
 
-  struct curl_slist *slist = generateCurlHeaders(context,argv+2); // Initialize Headers
+  slist = generateCurlHeaders(context,argv+2); // Initialize Headers
   if(slist != NULL) {
     curl_easy_setopt(handle,CURLOPT_HTTPHEADER,slist);
   }
 
-  int exitcode;
-
   if((exitcode = curl_easy_perform(handle)) != 0) {             // Perform
     curl_slist_free_all(slist);
     free(body);
@@ -849,6 +852,9 @@
   char *url, *data;
   size_t charslen, readlen;
   JSObject* header_obj;
+  CURL* handle;
+  struct curl_slist *slist;
+  int exitcode;
 
   // Run GC
   JS_MaybeGC(context);
@@ -874,8 +880,6 @@
 
   free(data);
 
-  CURL* handle;
-
   // Init Curl
 
   if((handle = curl_easy_init()) == NULL) {
@@ -897,7 +901,7 @@
 
 
   // Curl structure
-  struct curl_slist *slist = generateCurlHeaders(context,argv+2);
+  slist = generateCurlHeaders(context,argv+2);
   if(slist != NULL) {
     curl_easy_setopt(handle,CURLOPT_HTTPHEADER,slist);
   }
@@ -911,8 +915,6 @@
 
 
   // Perform
-  int exitcode;
-
   if((exitcode = curl_easy_perform(handle)) != 0) {
     if(slist != NULL)
       curl_slist_free_all(slist);
@@ -960,6 +962,10 @@
   char *url;
   size_t charslen, readlen;
   char header_name[7];
+  CURL* handle;
+  int exitcode;
+  struct curl_slist *slist = NULL;
+
   strcpy(header_name,"DELETE");
 
   // Run GC
@@ -971,8 +977,6 @@
   // Allocate buffer that will store the del resultant
   b = init_Buffer();
 
-  CURL* handle;
-
   // Init Curl
   if((handle = curl_easy_init()) == NULL) {
     free_Buffer(b);
@@ -990,14 +994,11 @@
   curl_easy_setopt(handle,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);
 
   // Curl structure
-  struct curl_slist *slist = NULL;
   if((slist = generateCurlHeaders(context,argv+1)) != NULL) {
     curl_easy_setopt(handle,CURLOPT_HTTPHEADER,slist);
   }
 
   // Perform
-  int exitcode;
-
   if((exitcode = curl_easy_perform(handle)) != 0) {
     if(slist != NULL)
       curl_slist_free_all(slist);
@@ -1042,6 +1043,10 @@
   char *url;
   size_t charslen, readlen;
   char header_name[5];
+  CURL* handle;
+  int exitcode;
+  struct curl_slist *slist = NULL;
+
   strcpy(header_name,"COPY");
 
   // Run GC
@@ -1053,8 +1058,6 @@
   // Allocate buffer that will store the del resultant
   b = init_Buffer();
 
-  CURL* handle;
-
   // Init Curl
   if((handle = curl_easy_init()) == NULL) {
     free_Buffer(b);
@@ -1072,14 +1075,11 @@
   curl_easy_setopt(handle,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);
 
   // Curl structure
-  struct curl_slist *slist = NULL;
   if((slist = generateCurlHeaders(context,argv+1)) != NULL) {
     curl_easy_setopt(handle,CURLOPT_HTTPHEADER,slist);
   }
 
   // Perform
-  int exitcode;
-
   if((exitcode = curl_easy_perform(handle)) != 0) {
     if(slist != NULL)
       curl_slist_free_all(slist);
@@ -1124,6 +1124,10 @@
   char *url;
   size_t charslen, readlen;
   char header_name[5];
+  CURL* handle;
+  struct curl_slist *slist = NULL;
+  int exitcode;
+
   strcpy(header_name,"MOVE");
 
   // Run GC
@@ -1135,8 +1139,6 @@
   // Allocate buffer that will store the del resultant
   b = init_Buffer();
 
-  CURL* handle;
-
   // Init Curl
   if((handle = curl_easy_init()) == NULL) {
     free_Buffer(b);
@@ -1154,14 +1156,11 @@
   curl_easy_setopt(handle,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);
 
   // Curl structure
-  struct curl_slist *slist = NULL;
   if((slist = generateCurlHeaders(context,argv+1)) != NULL) {
     curl_easy_setopt(handle,CURLOPT_HTTPHEADER,slist);
   }
 
   // Perform
-  int exitcode;
-
   if((exitcode = curl_easy_perform(handle)) != 0) {
     if(slist != NULL)
       curl_slist_free_all(slist);

Modified: couchdb/trunk/src/couchdb/curlhelper.c
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/curlhelper.c?rev=792010&r1=792009&r2=792010&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/curlhelper.c (original)
+++ couchdb/trunk/src/couchdb/curlhelper.c Wed Jul  8 01:26:04 2009
@@ -48,6 +48,7 @@
 int append_Buffer(Buffer b, char* c, int length) {
   int capacity_changed;
   int new_count;
+  int i;
 
   capacity_changed = FALSE;
   new_count = b->count + length;
@@ -67,8 +68,6 @@
     }
   }
 
-  int i;
-
   for(i = 0;i < length;i++) {
     *(b->data + b->count + i) = *(c + i);
   }
@@ -80,6 +79,7 @@
 
 char* toString_Buffer(Buffer b) {
   char* result;
+  int i;
 
   if((result = (char*)malloc(sizeof(char)*(b->count+1))) == NULL) {
     return NULL;
@@ -87,8 +87,6 @@
 
   result[b->count] = '\0';
 
-  int i;
-
   for(i = 0;i < b->count;i++) {
     result[i] = b->data[i];
   }
@@ -122,11 +120,10 @@
 }
 
 void copy_Buffer(Buffer b, char* c, int pos, int length) {
+  int i;
   if((pos + length) > b->count)
     return;
 
-  int i;
-
   for(i = 0; i < length;i++) {
     *(c + i) = *(b->data + pos + i);
   }
@@ -134,11 +131,10 @@
 
 
 List init_List(int capacity) {
+  List l;
   if(capacity < 5)
     capacity = 5;
 
-  List l;
-
   if((l = (List)malloc(sizeof(void**)+sizeof(int)*2)) == NULL) {
     return NULL;
   }
@@ -193,6 +189,7 @@
 int append_List(List l, void* ptr, int length) {
   int capacity_changed;
   int new_count;
+  int i;
 
   capacity_changed = FALSE;
   new_count = l->count + length;
@@ -212,10 +209,8 @@
     }
   }
 
-  int i;
-
   for(i = 0;i < length;i++) {
-    *(l->elements + l->count + i) = ptr + i;
+    *(l->elements + l->count + i) = (void *)((char *)ptr + i);
   }
 
   l->count = new_count;
@@ -226,6 +221,7 @@
 int push_List(List l, void* ptr, int length) {
   int capacity_changed;
   int new_count;
+  int i;
 
   capacity_changed = FALSE;
   new_count = l->count + length;
@@ -245,14 +241,12 @@
     }
   }
 
-  int i;
-
   for(i = 0;i < length;i++) {
     *(l->elements + l->count + i) = *(l->elements + i);
   }
 
   for(i = 0;i < length;i++) {
-    *(l->elements + i) = ptr+i;
+    *(l->elements + i) = (void *)((char *)ptr+i);
   }
 
   l->count = new_count;



Mime
View raw message