aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2018-05-22 09:13:20 -0700
committerPaul Eggert2018-05-22 09:14:03 -0700
commita51725280ac3f4db3b9a1a552f25fb4204f45a4d (patch)
tree850cf52efa4eca0b5ac73db94a805d9323e2dd87 /src
parent19e642fdb07b0b6522983e2fa35872ba5fb9f75e (diff)
downloademacs-a51725280ac3f4db3b9a1a552f25fb4204f45a4d.tar.gz
emacs-a51725280ac3f4db3b9a1a552f25fb4204f45a4d.zip
Minor tweaks to recent fix for Bug#31545
* src/xwidget.c (webkit_javascript_finished_cb) (Fxwidget_webkit_execute_script): Use intptr_t to avoid warnings in the (unlikely) event that ptrdiff_t and void * differ in width. (save_script_callback): Simplify by using xlispdstrdup and larger_vector.
Diffstat (limited to 'src')
-rw-r--r--src/xwidget.c35
1 files changed, 11 insertions, 24 deletions
diff --git a/src/xwidget.c b/src/xwidget.c
index 16243b7789e..32022abf341 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -370,7 +370,7 @@ webkit_javascript_finished_cb (GObject *webview,
370 GError *error = NULL; 370 GError *error = NULL;
371 struct xwidget *xw = g_object_get_data (G_OBJECT (webview), 371 struct xwidget *xw = g_object_get_data (G_OBJECT (webview),
372 XG_XWIDGET); 372 XG_XWIDGET);
373 ptrdiff_t script_idx = (ptrdiff_t) arg; 373 ptrdiff_t script_idx = (intptr_t) arg;
374 Lisp_Object script_callback = AREF (xw->script_callbacks, script_idx); 374 Lisp_Object script_callback = AREF (xw->script_callbacks, script_idx);
375 ASET (xw->script_callbacks, script_idx, Qnil); 375 ASET (xw->script_callbacks, script_idx, Qnil);
376 if (!NILP (script_callback)) 376 if (!NILP (script_callback))
@@ -711,33 +711,20 @@ DEFUN ("xwidget-webkit-zoom",
711static ptrdiff_t 711static ptrdiff_t
712save_script_callback (struct xwidget *xw, Lisp_Object script, Lisp_Object fun) 712save_script_callback (struct xwidget *xw, Lisp_Object script, Lisp_Object fun)
713{ 713{
714 ptrdiff_t script_bytes = STRING_BYTES (XSTRING (script));
715 char *script_data = xmalloc (script_bytes + 1);
716 memcpy (script_data, SSDATA (script), script_bytes + 1);
717
718 ptrdiff_t idx;
719 Lisp_Object cbs = xw->script_callbacks; 714 Lisp_Object cbs = xw->script_callbacks;
720 if (NILP (cbs)) 715 if (NILP (cbs))
721 xw->script_callbacks = cbs = Fmake_vector (make_number (32), Qnil); 716 xw->script_callbacks = cbs = Fmake_vector (make_number (32), Qnil);
722 717
723 /* Find first free index. */ 718 /* Find first free index. */
724 for (idx = 0; ; idx++) 719 ptrdiff_t idx;
725 { 720 for (idx = 0; !NILP (AREF (cbs, idx)); idx++)
726 if (idx >= ASIZE (cbs)) 721 if (idx + 1 == ASIZE (cbs))
727 { 722 {
728 /* Resize script/callback save vector. */ 723 xw->script_callbacks = cbs = larger_vector (cbs, 1, -1);
729 Lisp_Object new_cbs = Fmake_vector (make_number (idx + 32), Qnil); 724 break;
730 ptrdiff_t n; 725 }
731 for (n = 0; n < idx; n++) 726
732 ASET (new_cbs, n, AREF (cbs, n)); 727 ASET (cbs, idx, Fcons (make_save_ptr (xlispstrdup (script)), fun));
733 xw->script_callbacks = cbs = new_cbs;
734 }
735 if (NILP (AREF (cbs, idx)))
736 {
737 ASET (cbs, idx, Fcons (make_save_ptr (script_data), fun));
738 break;
739 }
740 }
741 return idx; 728 return idx;
742} 729}
743 730
@@ -757,7 +744,7 @@ argument procedure FUN.*/)
757 script = ENCODE_SYSTEM (script); 744 script = ENCODE_SYSTEM (script);
758 745
759 /* Protect script and fun during GC. */ 746 /* Protect script and fun during GC. */
760 ptrdiff_t idx = save_script_callback (xw, script, fun); 747 intptr_t idx = save_script_callback (xw, script, fun);
761 748
762 /* JavaScript execution happens asynchronously. If an elisp 749 /* JavaScript execution happens asynchronously. If an elisp
763 callback function is provided we pass it to the C callback 750 callback function is provided we pass it to the C callback