From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alex Gramiak Newsgroups: gmane.emacs.devel Subject: Re: Replace XChar2b with unsigned in all font backends Date: Mon, 20 May 2019 13:34:58 -0600 Message-ID: <87imu4vs0t.fsf@gmail.com> References: <87v9y5uh63.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="238346"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) Cc: emacs-devel@gnu.org To: Andy Moreton Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 20 21:35:43 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hSo4V-000zqy-Gc for ged-emacs-devel@m.gmane.org; Mon, 20 May 2019 21:35:43 +0200 Original-Received: from localhost ([127.0.0.1]:40964 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSo4U-000061-BY for ged-emacs-devel@m.gmane.org; Mon, 20 May 2019 15:35:42 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:34676) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSo3p-0008Va-1b for emacs-devel@gnu.org; Mon, 20 May 2019 15:35:02 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hSo3n-0006V1-HE for emacs-devel@gnu.org; Mon, 20 May 2019 15:35:01 -0400 Original-Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]:39654) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hSo3l-0006T2-HB for emacs-devel@gnu.org; Mon, 20 May 2019 15:34:59 -0400 Original-Received: by mail-pf1-x42e.google.com with SMTP id z26so7710645pfg.6 for ; Mon, 20 May 2019 12:34:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=E+AAQf6aUc8m8VM0qwnY8dPQ9baMwX8cB+7DGomUnDE=; b=XnuvFVaqGTWECKzuVfTZxgugUiVcdmqbW0V2/3PhZ9X3njj10Yq3Xi0MqD5PsBEHQc 43kQX+s9WYshYL7ygiT2IrUwAqGr2cMcnE6AmbChleH9+8Onhw/DZviPMM05fIC5qy5N aXxygDsBxQjBooVZ+1mVEQvgViOlVuP9xQx/cZ0MGVtuCot3ftfa3kEc4nNcPJcVcvQ1 lk1y7RilC2meirRabtX2ia7o/JzkM/0WUwd3881DbCs8+A4afrGjJnt17dcu7XZYke4U kHC8Mh7jvfkzgL9VpzmHNVHBIGrtY+E3y7Pdj6YZCoYFBZbhl3oOqyI+eG6tY2HT/+N3 V7yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=E+AAQf6aUc8m8VM0qwnY8dPQ9baMwX8cB+7DGomUnDE=; b=kznnom/eAHLJpLXuTZFM009WHhNwQX9Y94inAAPPG1zgxr7wTyayW4/szgU5zdN6BI uwbI1H+eI7voacIdTvsw34/VS+h3zliAL0C5MD1XC0Tz2SNHSjEqdlR6wRj4eed6Zp9j x2N0DrBo9QbSKW9+6L4GN75BUjPKPZk2xXqLGxNwLktUR/+hjf0t1b9kcqIWPUJlz1iw 4Su3Nygwtd/ywr+jOohyn8J78vQJm99p+yy/VawGHad8PpD6o/XXKI1LT4wjpJFtgrGV UCMC8La4YoT1rLJAiyyErV5Xw1jfYx8ElpVUfgA0yhbxmMQCzkP/f8MMrLggbVGVZNdD ulAQ== X-Gm-Message-State: APjAAAXMM2vzqph4JN8HfOKa1Y+XXpQC6EHgVrYiEM+Hnj0koUeTiW78 l7SzyhNX/Bnr9DhJIFWWlD81KEtl X-Google-Smtp-Source: APXvYqzD8Di4JQMBGkGAlME/BGroRVR3XFDhyPq8lMr5KdcC/itI/kuvVeFEk7e2E4AW1UOvkS5vYQ== X-Received: by 2002:a63:c750:: with SMTP id v16mr76349630pgg.409.1558380896083; Mon, 20 May 2019 12:34:56 -0700 (PDT) Original-Received: from lylat ([2604:3d09:e37f:1500:1a72:4878:e793:7302]) by smtp.gmail.com with ESMTPSA id 63sm26633029pfu.95.2019.05.20.12.34.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 May 2019 12:34:55 -0700 (PDT) In-Reply-To: (Andy Moreton's message of "Mon, 20 May 2019 19:29:34 +0100") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::42e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:236820 Archived-At: --=-=-= Content-Type: text/plain Andy Moreton writes: > On Mon 20 May 2019, Alex Gramiak wrote: > >> Andy Moreton writes: >> >>> Confirmed. This patch replaces use of XChar2b (a 16bit type) with >>> unsigned (usually 32bit) which seems wrong. >>> >>> AndyM >> >> I originally used unsigned short for this patch, but Eli[1] nudged me >> towards unsigned. Unsigned fits better with other parts of the font >> system, e.g., *encode_char returns unsigned, and *text_extents takes a >> pointer to unsigned. >> >> [1] https://lists.gnu.org/archive/html/emacs-devel/2019-05/msg00457.html > > Yes, but Eli was concerned with efficiency, but correctness comes first. > If you are calling APIs that expect a pointer to an array of 16bit > values, then an array of 32bit values will not suffice. Right, at least not without converting the array; the xfont backend does this when the API expects an array of 8bit values. > Many of the comments around this code talk of 2-byte values, so > changing the code to use 4-byte values is surprising to the reader. I agree, but at least the char2b name signifies that it's a 2-byte value. > The changes also removed the explicit packing/unpacking of 16bit values, > which may give rise to endianness issues on some systems. I haven't dealt with endianness issues before, but from a quick search [1][2] it doesn't appear that it's an issue: [1] https://developer.ibm.com/articles/au-endianc/ [2] https://stackoverflow.com/a/7184905 > Please revert this patch to fix the build on master, and then revisit > these changes after that. I think that the solution is just to do a conversion on the w32font_draw side. Can you confirm if the following diff fixes the build for you? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=w32font.diff Content-Description: w32font v2 diff --git a/src/w32font.c b/src/w32font.c index bd68e22cc9..d3ec2916a5 100644 --- a/src/w32font.c +++ b/src/w32font.c @@ -704,11 +704,20 @@ w32font_draw (struct glyph_string *s, int from, int to, int i; for (i = 0; i < len; i++) - ExtTextOutW (s->hdc, x + i, y, options, NULL, - s->char2b + from + i, 1, NULL); + { + const wchar_t ch = s->char2b[from + i]; + ExtTextOutW (s->hdc, x + i, y, options, NULL, &ch, 1, NULL); + } } else - ExtTextOutW (s->hdc, x, y, options, NULL, s->char2b + from, len, NULL); + { + USE_SAFE_ALLOCA; + wchar_t *str = SAFE_ALLOCA (len * (sizeof (*str))); + for (int i = 0; i < len; ++i) + str[i] = s->char2b[from + i]; + ExtTextOutW (s->hdc, x, y, options, NULL, str, len, NULL); + SAFE_FREE (); + } /* Restore clip region. */ if (s->num_clips > 0) --=-=-=--