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

Re: Bug#504340: djvulibre-plugin/testing and #504340



Hi,

Adeodato Simó wrote:
>> How about using O2 for the plugin (or generally)?

> 22:08 <dato> tomv_w: and let's go for -O2 in djvulibre; for only the plugin if 
>              that's enough

So here is something even better (IMHO): Change map_lookup to return the
return value (note that this would be funny if we stored NULLs in the
hash table, but we actually don't). This avoids the pointer-type-funnies
in map_lookup altogether and works in my testing. Granted, the diff has
a couple of lines more, but it is very straightforward.

Kind regards

T.
-- 
Thomas Viehmann, http://thomas.viehmann.net/
diff -u djvulibre-3.5.20/debian/changelog djvulibre-3.5.20/debian/changelog
--- djvulibre-3.5.20/debian/changelog
+++ djvulibre-3.5.20/debian/changelog
@@ -1,3 +1,13 @@
+djvulibre (3.5.20-8+lenny1) testing; urgency=low
+
+  * Non-maintainer upload.
+  * gui/nsdejavu/nsdejavu.c: Don't assume NPP_SetWindow is
+    alsways passed good data. Patch from upstream.
+    Make map_lookup return the result instead of an error code.
+    Closes: #504340
+
+ -- Thomas Viehmann <tv@beamnet.de>  Tue, 30 Dec 2008 00:11:49 +0100
+
 djvulibre (3.5.20-8+lenny0) testing; urgency=low
 
   * Non-maintainer upload to testing.
only in patch2:
unchanged:
--- djvulibre-3.5.20.orig/gui/nsdejavu/nsdejavu.c
+++ djvulibre-3.5.20/gui/nsdejavu/nsdejavu.c
@@ -815,8 +815,8 @@
   m->nbuckets = new_nbuckets;
 }
 
-static int
-map_lookup(Map *m, void *key, void *pval)
+static void*
+map_lookup(Map *m, void *key)
 {
   int h;
   struct map_entry_s *q;
@@ -825,11 +825,10 @@
     for (q=m->buckets[h]; q; q=q->next)
       if (q->key == key) {
         if (pval)
-          *(void**)pval = q->val;
-        return 1;
+          return q->val;
       }
   }
-  return -1;
+  return NULL;
 }
 
 static int
@@ -1167,12 +1166,12 @@
       switch(reqp->req_num)
         {
         case CMD_SHOW_STATUS:
-          if (map_lookup(&instance, reqp->id, &inst) >= 0)
+          if (inst = map_lookup(&instance, reqp->id))
             if (inst->widget) 
               NPN_Status(inst->np_instance, reqp->status);
           break;
         case CMD_GET_URL:
-          if (map_lookup(&instance, reqp->id, &inst) >= 0)
+          if (inst = map_lookup(&instance, reqp->id))
             {
               const char *target = (reqp->target && reqp->target[0]) 
                 ? reqp->target : 0;
@@ -1180,7 +1179,7 @@
             }
           break;
         case CMD_GET_URL_NOTIFY:
-          if (map_lookup(&instance, reqp->id, &inst) >= 0)
+          if (inst = map_lookup(&instance, reqp->id))
             {
               const char *target = (reqp->target && reqp->target[0]) 
                 ? reqp->target : 0;
@@ -1297,7 +1296,7 @@
     {
       Instance *inst;
       void *id = (void*)cl_data;
-      if (map_lookup(&instance, id, &inst) >= 0)
+      if (inst = map_lookup(&instance, reqp->id))
         if (Resize(id) <= 0)
           ProgramDied();
     }
@@ -1325,7 +1324,7 @@
   Instance *inst;
   void *id = (void*)cl_data;
   *cont = True;
-  if (map_lookup(&instance, id, &inst) >= 0)
+  if (inst = map_lookup(&instance, reqp->id))
     {
       Widget   wid = inst->widget;
       Display *dpy = XtDisplay(wid);
@@ -1567,7 +1566,7 @@
      resizeCallback here and send the appropriate request to the
      application */
   Instance *inst;
-  if (map_lookup(&instance, id, &inst) < 0)
+  if (! inst = map_lookup(&instance, reqp->id))
     return 1;
   if (inst->widget)
    {
@@ -1591,7 +1590,7 @@
 Detach(void * id)
 {
   Instance *inst;
-  if (map_lookup(&instance, id, &inst) < 0)
+  if (! inst = map_lookup(&instance, reqp->id))
     return 1;
   if (inst->widget)
     {
@@ -1630,7 +1629,7 @@
   XColor cell;
   
   XSync(displ, False);
-  if (map_lookup(&instance, id, &inst) < 0)
+  if (! inst = map_lookup(&instance, reqp->id))
     return 1;
 
   widget = XtWindowToWidget(displ, window);
@@ -1968,7 +1967,7 @@
     goto problem;
   if (ReadPointer(pipe_read, &id, 0, 0) <= 0)
     goto problem;
-  if (map_lookup(&instance, id, &inst) >= 0)
+  if (inst = map_lookup(&instance, id))
     /* This can happen because we do not clear
        the instance array when restarting djview.
        We just undo it... */
@@ -1988,7 +1987,7 @@
   void * id = np_inst->pdata;
   SavedData saved_data;
   
-  if (map_lookup(&instance, id, &inst) < 0)
+  if (! inst = map_lookup(&instance, id))
     return NPERR_INVALID_INSTANCE_ERROR;
   /* Detach the main window, if not already detached */
   NPP_SetWindow(np_inst, 0);
@@ -2035,7 +2034,7 @@
   void * id = np_inst->pdata;
   Window cur_window, new_window;
 
-  if (map_lookup(&instance, id, &inst) < 0)
+  if (! inst = map_lookup(&instance, id))
     return NPERR_INVALID_INSTANCE_ERROR;
   cur_window = inst->window;
   new_window = (win_str) ? (Window) win_str->window : 0;
@@ -2054,9 +2053,9 @@
     }
   if (new_window)
     {
-      NPSetWindowCallbackStruct *cbs 
-        = (NPSetWindowCallbackStruct *) win_str->ws_info;
-      Display * displ=cbs->display;
+      Display *displ = 0;
+      if (NPN_GetValue(np_inst, NPNVxDisplay, &displ) != NPERR_NO_ERROR)
+        displ = ((NPSetWindowCallbackStruct *)(win_str->ws_info))->display;
       if (!IsConnectionOK(FALSE)) 
         return NPERR_GENERIC_ERROR;
       if (Attach(displ, new_window, id) < 0)
@@ -2075,7 +2074,7 @@
   Instance *inst = 0;
   void * id = np_inst->pdata;
 
-  if (map_lookup(&instance, id, &inst) > 0)
+  if (inst = map_lookup(&instance, id))
     if (inst->widget)
       {
         if (printInfo && printInfo->mode==NP_FULL)
@@ -2103,7 +2102,7 @@
   void * id = np_inst->pdata;
   void * sid = 0;
   
-  if (map_lookup(&instance, id, &inst) < 0)
+  if (! inst = map_lookup(&instance, id))
     return NPERR_INVALID_INSTANCE_ERROR;
   
   if ( (WriteInteger(pipe_write, CMD_NEW_STREAM) <= 0) ||
@@ -2136,7 +2135,7 @@
   
   if (sid)
     {
-      if (map_lookup(&strinstance, sid, 0) < 0)
+      if (! inst = map_lookup(&strinstance, sid))
         return res;
       if ( (WriteInteger(pipe_write, CMD_WRITE) <= 0) ||
            (WritePointer(pipe_write, sid) <= 0) ||
@@ -2164,7 +2163,7 @@
 NPP_DestroyStream(NPP np_inst, NPStream *stream, NPError reason)
 {
   void * sid = stream->pdata;
-  if (map_lookup(&strinstance, sid, 0) < 0)
+  if (! inst = map_lookup(&strinstance, sid))
     return NPERR_INVALID_INSTANCE_ERROR;
   if (!IsConnectionOK(FALSE)) 
     return NPERR_GENERIC_ERROR;

Reply to: