aboutsummaryrefslogtreecommitdiffstats
path: root/src/xselect.c
diff options
context:
space:
mode:
authorPaul Eggert2012-07-05 11:35:48 -0700
committerPaul Eggert2012-07-05 11:35:48 -0700
commit38182d901d030c7d65f4aa7a49b583afb30eb9b7 (patch)
treea69e1a571495d6ca1c034359d7c995639774ab9b /src/xselect.c
parent6dd5a677dbf794eedaa8325c46d57ac041373361 (diff)
downloademacs-38182d901d030c7d65f4aa7a49b583afb30eb9b7.tar.gz
emacs-38182d901d030c7d65f4aa7a49b583afb30eb9b7.zip
More xmalloc and related cleanup.
* alloc.c, bidi.c, buffer.c, buffer.h, bytecode.c, callint.c: * callproc.c, charset.c, coding.c, composite.c, data.c, dispnew.c: * doc.c, editfns.c, emacs.c, eval.c, fileio.c, filelock.c, fns.c: * font.c, fontset.c, frame.c, fringe.c, ftfont.c, ftxfont.c, gmalloc.c: * gtkutil.c, image.c, keyboard.c, keymap.c, lread.c, macros.c, menu.c: * nsfns.m, nsfont.m, nsmenu.m, nsterm.m, print.c, process.c, ralloc.c: * regex.c, region-cache.c, scroll.c, search.c, sound.c, syntax.c: * sysdep.c, term.c, termcap.c, unexmacosx.c, window.c, xdisp.c: * xfaces.c, xfns.c, xftfont.c, xgselect.c, xmenu.c, xrdb.c, xselect.c: * xterm.c: Omit needless casts involving void * pointers and allocation. Prefer "P = xmalloc (sizeof *P)" to "P = xmalloc (sizeof (TYPE_OF_P))", as the former is more robust if P's type is changed. Prefer xzalloc to xmalloc + memset 0. Simplify malloc-or-realloc to realloc. Don't worry about xmalloc returning a null pointer. Prefer xstrdup to xmalloc + strcpy. * editfns.c (Fmessage_box): Grow message_text by at least 80 when growing it. * keyboard.c (apply_modifiers_uncached): Prefer local array to alloca of a constant.
Diffstat (limited to 'src/xselect.c')
-rw-r--r--src/xselect.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/src/xselect.c b/src/xselect.c
index 67785b26353..e2da561e953 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -180,7 +180,7 @@ x_queue_event (struct input_event *event)
180 } 180 }
181 } 181 }
182 182
183 queue_tmp = xmalloc (sizeof (struct selection_event_queue)); 183 queue_tmp = xmalloc (sizeof *queue_tmp);
184 TRACE1 ("QUEUE SELECTION EVENT %p", queue_tmp); 184 TRACE1 ("QUEUE SELECTION EVENT %p", queue_tmp);
185 queue_tmp->event = *event; 185 queue_tmp->event = *event;
186 queue_tmp->next = selection_queue; 186 queue_tmp->next = selection_queue;
@@ -907,7 +907,7 @@ x_convert_selection (struct input_event *event, Lisp_Object selection_symbol,
907 { 907 {
908 if (for_multiple) 908 if (for_multiple)
909 { 909 {
910 cs = xmalloc (sizeof (struct selection_data)); 910 cs = xmalloc (sizeof *cs);
911 cs->data = (unsigned char *) &conversion_fail_tag; 911 cs->data = (unsigned char *) &conversion_fail_tag;
912 cs->size = 1; 912 cs->size = 1;
913 cs->format = 32; 913 cs->format = 32;
@@ -924,7 +924,7 @@ x_convert_selection (struct input_event *event, Lisp_Object selection_symbol,
924 } 924 }
925 925
926 /* Otherwise, record the converted selection to binary. */ 926 /* Otherwise, record the converted selection to binary. */
927 cs = xmalloc (sizeof (struct selection_data)); 927 cs = xmalloc (sizeof *cs);
928 cs->data = NULL; 928 cs->data = NULL;
929 cs->nofree = 1; 929 cs->nofree = 1;
930 cs->property = property; 930 cs->property = property;
@@ -1775,20 +1775,24 @@ lisp_data_to_selection_data (Display *display, Lisp_Object obj,
1775 } 1775 }
1776 else if (SYMBOLP (obj)) 1776 else if (SYMBOLP (obj))
1777 { 1777 {
1778 *data_ret = xmalloc (sizeof (Atom) + 1); 1778 void *data = xmalloc (sizeof (Atom) + 1);
1779 Atom *x_atom_ptr = data;
1780 *data_ret = data;
1779 *format_ret = 32; 1781 *format_ret = 32;
1780 *size_ret = 1; 1782 *size_ret = 1;
1781 (*data_ret) [sizeof (Atom)] = 0; 1783 (*data_ret) [sizeof (Atom)] = 0;
1782 (*(Atom **) data_ret) [0] = symbol_to_x_atom (dpyinfo, obj); 1784 *x_atom_ptr = symbol_to_x_atom (dpyinfo, obj);
1783 if (NILP (type)) type = QATOM; 1785 if (NILP (type)) type = QATOM;
1784 } 1786 }
1785 else if (RANGED_INTEGERP (X_SHRT_MIN, obj, X_SHRT_MAX)) 1787 else if (RANGED_INTEGERP (X_SHRT_MIN, obj, X_SHRT_MAX))
1786 { 1788 {
1787 *data_ret = xmalloc (sizeof (short) + 1); 1789 void *data = xmalloc (sizeof (short) + 1);
1790 short *short_ptr = data;
1791 *data_ret = data;
1788 *format_ret = 16; 1792 *format_ret = 16;
1789 *size_ret = 1; 1793 *size_ret = 1;
1790 (*data_ret) [sizeof (short)] = 0; 1794 (*data_ret) [sizeof (short)] = 0;
1791 (*(short **) data_ret) [0] = XINT (obj); 1795 *short_ptr = XINT (obj);
1792 if (NILP (type)) type = QINTEGER; 1796 if (NILP (type)) type = QINTEGER;
1793 } 1797 }
1794 else if (INTEGERP (obj) 1798 else if (INTEGERP (obj)
@@ -1797,11 +1801,13 @@ lisp_data_to_selection_data (Display *display, Lisp_Object obj,
1797 || (CONSP (XCDR (obj)) 1801 || (CONSP (XCDR (obj))
1798 && INTEGERP (XCAR (XCDR (obj))))))) 1802 && INTEGERP (XCAR (XCDR (obj)))))))
1799 { 1803 {
1800 *data_ret = xmalloc (sizeof (unsigned long) + 1); 1804 void *data = xmalloc (sizeof (unsigned long) + 1);
1805 unsigned long *x_long_ptr = data;
1806 *data_ret = data;
1801 *format_ret = 32; 1807 *format_ret = 32;
1802 *size_ret = 1; 1808 *size_ret = 1;
1803 (*data_ret) [sizeof (unsigned long)] = 0; 1809 (*data_ret) [sizeof (unsigned long)] = 0;
1804 (*(unsigned long **) data_ret) [0] = cons_to_x_long (obj); 1810 *x_long_ptr = cons_to_x_long (obj);
1805 if (NILP (type)) type = QINTEGER; 1811 if (NILP (type)) type = QINTEGER;
1806 } 1812 }
1807 else if (VECTORP (obj)) 1813 else if (VECTORP (obj))
@@ -1816,23 +1822,28 @@ lisp_data_to_selection_data (Display *display, Lisp_Object obj,
1816 if (SYMBOLP (AREF (obj, 0))) 1822 if (SYMBOLP (AREF (obj, 0)))
1817 /* This vector is an ATOM set */ 1823 /* This vector is an ATOM set */
1818 { 1824 {
1825 void *data;
1826 Atom *x_atoms;
1819 if (NILP (type)) type = QATOM; 1827 if (NILP (type)) type = QATOM;
1820 for (i = 0; i < size; i++) 1828 for (i = 0; i < size; i++)
1821 if (!SYMBOLP (AREF (obj, i))) 1829 if (!SYMBOLP (AREF (obj, i)))
1822 signal_error ("All elements of selection vector must have same type", obj); 1830 signal_error ("All elements of selection vector must have same type", obj);
1823 1831
1824 *data_ret = xnmalloc (size, sizeof (Atom)); 1832 *data_ret = data = xnmalloc (size, sizeof *x_atoms);
1833 x_atoms = data;
1825 *format_ret = 32; 1834 *format_ret = 32;
1826 *size_ret = size; 1835 *size_ret = size;
1827 for (i = 0; i < size; i++) 1836 for (i = 0; i < size; i++)
1828 (*(Atom **) data_ret) [i] 1837 x_atoms[i] = symbol_to_x_atom (dpyinfo, AREF (obj, i));
1829 = symbol_to_x_atom (dpyinfo, AREF (obj, i));
1830 } 1838 }
1831 else 1839 else
1832 /* This vector is an INTEGER set, or something like it */ 1840 /* This vector is an INTEGER set, or something like it */
1833 { 1841 {
1834 int format = 16; 1842 int format = 16;
1835 int data_size = sizeof (short); 1843 int data_size = sizeof (short);
1844 void *data;
1845 unsigned long *x_atoms;
1846 short *shorts;
1836 if (NILP (type)) type = QINTEGER; 1847 if (NILP (type)) type = QINTEGER;
1837 for (i = 0; i < size; i++) 1848 for (i = 0; i < size; i++)
1838 { 1849 {
@@ -1847,17 +1858,17 @@ lisp_data_to_selection_data (Display *display, Lisp_Object obj,
1847 break; 1858 break;
1848 } 1859 }
1849 } 1860 }
1850 *data_ret = xnmalloc (size, data_size); 1861 *data_ret = data = xnmalloc (size, data_size);
1862 x_atoms = data;
1863 shorts = data;
1851 *format_ret = format; 1864 *format_ret = format;
1852 *size_ret = size; 1865 *size_ret = size;
1853 for (i = 0; i < size; i++) 1866 for (i = 0; i < size; i++)
1854 { 1867 {
1855 if (format == 32) 1868 if (format == 32)
1856 (*((unsigned long **) data_ret)) [i] = 1869 x_atoms[i] = cons_to_x_long (AREF (obj, i));
1857 cons_to_x_long (AREF (obj, i));
1858 else 1870 else
1859 (*((short **) data_ret)) [i] = 1871 shorts[i] = XINT (AREF (obj, i));
1860 XINT (AREF (obj, i));
1861 } 1872 }
1862 } 1873 }
1863 } 1874 }