From martinwguy at gmail.com Sat Apr 2 12:08:24 2011 From: martinwguy at gmail.com (Martin Guy) Date: Sat, 2 Apr 2011 12:08:24 +0200 Subject: [GiNaC-devel] [PATCH] Fix unsigned character bugs in ginac-1.5.8 Message-ID: Hi There are a couple of bugs that stop ginac from working on machines whose characters are unsigned by default (where a conversion to int goves a value 0-255). It's the classic "char c = getchar(); if (c == EOF)" with result that it doesn't detect EOF on unsigned machines, or exits prematurely on signed machines if it reads a character 255. The fixes are to replace "char" with "int" so that all 257 possible return values are correctly handled. The attached patch for ginac-1.4.3 still applies to 1.5.8 Cheers M -------------- next part -------------- A non-text attachment was scrubbed... Name: ginac-1.4.3+unsignedcharfix.diff Type: text/x-patch Size: 1718 bytes Desc: not available URL: From alexei.sheplyakov at gmail.com Sat Apr 2 14:06:49 2011 From: alexei.sheplyakov at gmail.com (Alexei Sheplyakov) Date: Sat, 2 Apr 2011 15:06:49 +0300 Subject: [GiNaC-devel] Wrong patch (Was: Fix unsigned character bugs in ginac-1.5.8) In-Reply-To: References: Message-ID: <20110402120432.GA24344@vargsbox.jinr.ru> Hello, On Sat, Apr 02, 2011 at 12:08:24PM +0200, Martin Guy wrote: > This patch fixes a bug on machines where char is unsigned by default, by > extending the type of clifford_max_label to include all 257 possible > return values. I'm sorry to confuse you, but your patch is wrong. It just breaks ABI for nothing good at all. In practice there's no need for gamma matrices with 128 representation labels (otherwise GiNaC would have problems on machines where char is *signed* by default). I guess we should fix the documentation (it claims that representation labels from 0 to 255 are supported, which is definitely wrong). Best regards, Alexei From martinwguy at gmail.com Sat Apr 2 14:50:17 2011 From: martinwguy at gmail.com (Martin Guy) Date: Sat, 2 Apr 2011 14:50:17 +0200 Subject: [GiNaC-devel] Wrong patch (Was: Fix unsigned character bugs in ginac-1.5.8) In-Reply-To: <20110402120432.GA24344@vargsbox.jinr.ru> References: <20110402120432.GA24344@vargsbox.jinr.ru> Message-ID: On 2 April 2011 14:06, Alexei Sheplyakov wrote: > On Sat, Apr 02, 2011 at 12:08:24PM +0200, Martin Guy wrote: >> This patch fixes a bug on machines where char is unsigned by default, by >> extending the type of clifford_max_label to include all 257 possiblet >> return values. > > I'm sorry to confuse you, but your patch is wrong. It just breaks ABI for > nothing good at all. In practice there's no need for gamma matrices with > 128 representation labels (otherwise GiNaC would have problems on machines > where char is *signed* by default). I guess we should fix the documentation > (it claims that representation labels from 0 to 255 are supported, which > is definitely wrong). Eh? On unsigned char systems it currently fails to detect an error condition, but continues blindly, wihle users who have spotted the defect are forced to detect errors using "if (x & 255 == EOF & 255), which is crazy. In practice, chars are passed and returned as ints, so nothing changes in the function call/return values (which is what I thought an ABI was). Since users presumably include clifford.h before calling the function, at most they will get a compiler warning about an integer being stored in a character if they have done that, which also correctly pinpoints the error in their code. Anyway M From kreckel at ginac.de Wed Apr 6 09:33:50 2011 From: kreckel at ginac.de (Richard B. Kreckel) Date: Wed, 06 Apr 2011 09:33:50 +0200 Subject: [GiNaC-devel] Wrong patch (Was: Fix unsigned character bugs in ginac-1.5.8) In-Reply-To: <20110402120432.GA24344@vargsbox.jinr.ru> References: <20110402120432.GA24344@vargsbox.jinr.ru> Message-ID: <4D9C175E.2060302@ginac.de> Hi! On 04/02/2011 02:06 PM, Alexei Sheplyakov wrote: > On Sat, Apr 02, 2011 at 12:08:24PM +0200, Martin Guy wrote: > >> This patch fixes a bug on machines where char is unsigned by default, by >> extending the type of clifford_max_label to include all 257 possible >> return values. > > I'm sorry to confuse you, but your patch is wrong. It just breaks ABI for > nothing good at all. In practice there's no need for gamma matrices with > 128 representation labels (otherwise GiNaC would have problems on machines > where char is *signed* by default). I guess we should fix the documentation > (it claims that representation labels from 0 to 255 are supported, which > is definitely wrong). Alexei, does it really break the ABI? Whether we return an int here or a char won't change library symbol names and since chars are returned as ints, it won't change anything binary-wise. There are cases where clifford_max_label returns -1, so this is indeed broken. And this doesn't seem to have anything to do with having 255 different representation labels (which would be crazy, I agree.) So, I don't see a problem with Martin's patch. Did I miss anything? -richy. -- Richard B. Kreckel From alexei.sheplyakov at gmail.com Wed Apr 6 19:08:39 2011 From: alexei.sheplyakov at gmail.com (Alexei Sheplyakov) Date: Wed, 6 Apr 2011 20:08:39 +0300 Subject: [GiNaC-devel] Signed versus unsigned (Was: Wrong patch) In-Reply-To: <4D9C175E.2060302@ginac.de> References: <20110402120432.GA24344@vargsbox.jinr.ru> <4D9C175E.2060302@ginac.de> Message-ID: <20110406170839.GA9406@vargsbox.jinr.ru> Hello, On Wed, Apr 06, 2011 at 09:33:50AM +0200, Richard B. Kreckel wrote: > Alexei, does it really break the ABI? Whether we return an int here > or a char won't change library symbol names and since chars are > returned as ints, it won't change anything binary-wise. Changing the return type might break the ABI, and I think it's better to be safe than sorry. > There are cases where clifford_max_label returns -1, so this is > indeed broken. clifford_max_label returns some magic number (-1 aka 255) to indicate that the expression does not contain any gamma matrices. It's perfectly fine to do so as long as no valid representation label coincides with that magic number. Let's forget about computer algebra for a second and consider the following (C) code: #include /* size_t */ int max_val_s(const unsigned int* data, size_t sz) { size_t i = 0; unsigned int val = 0; if ((!data) || (!sz)) return -1; /* -1 is just a magic number which means "the input is empty */ for (; i < sz; ++i) { if (val < data[i]) val = data[i]; } return val; } The max_val_s is perfectly fine as long as the input data does not contain values greater than INT_MAX (usually 2^31 - 1). unsigned int max_val_u(const unsigned int* data, size_t sz) { size_t i = 0; unsigned int val = 0; if ((!data) || (!sz)) return -1; /* -1 is just a magic number which means "the input is empty */ for (; i < sz; ++i) { if (val < data[i]) val = data[i]; } return val; } The max_val_u is fine, too, as long as the input values are less than UINT_MAX. The above statements still hold if one replaces int with char (INT_MAX with CHAR_MAX, and UINT_MAX with UCHAR_MAX, respectively). Thus, clifford_max_label is OK as long as representation labels are within [0, 127] range (no matter if char is signed or not). > So, I don't see a problem with Martin's patch. Did I miss anything? Apart from a possible ABI change the patch is harmless. On the other hand, it's useless (see the explanation above), so I don't see any reason to apply it (as in "if it ain't broke, don't fix it"). Best regards, Alexei From kisilv at maths.leeds.ac.uk Fri Apr 8 18:54:15 2011 From: kisilv at maths.leeds.ac.uk (Vladimir V. Kisil) Date: Fri, 08 Apr 2011 17:54:15 +0100 Subject: [GiNaC-devel] Conjugated cosh and sinh Message-ID: <3032.1302281655@krein.leeds.ac.uk> Dear All, Analysing a failure of my code I found the reason in the absence of conjugate() method for cosh and sinh functions. Is there a fundamental reason for this? Or shall I prepare a patch defining them similarly to this: static ex cosh_conjugate(const ex & x) { // conjugate(cosh(x))==cosh(conjugate(x)) return cosh(x.conjugate()); } Best wishes, Vladimir -- Vladimir V. Kisil email: kisilv at maths.leeds.ac.uk -- www: http://www.maths.leeds.ac.uk/~kisilv/ From kreckel at ginac.de Fri Apr 8 22:55:19 2011 From: kreckel at ginac.de (Richard B. Kreckel) Date: Fri, 08 Apr 2011 22:55:19 +0200 Subject: [GiNaC-devel] Conjugated cosh and sinh In-Reply-To: <3032.1302281655@krein.leeds.ac.uk> References: <3032.1302281655@krein.leeds.ac.uk> Message-ID: <4D9F7637.5030007@ginac.de> Hi Vladimir, On 04/08/2011 06:54 PM, Vladimir V. Kisil wrote: > Analysing a failure of my code I found the reason in the absence > of conjugate() method for cosh and sinh functions. Is there a > fundamental reason for this? No, it's an oversight. -richy. -- Richard B. Kreckel From kisilv at maths.leeds.ac.uk Fri Apr 8 23:00:47 2011 From: kisilv at maths.leeds.ac.uk (Vladimir V. Kisil) Date: Fri, 08 Apr 2011 22:00:47 +0100 Subject: [GiNaC-devel] Conjugated cosh and sinh In-Reply-To: <4D9F7637.5030007@ginac.de> References: <3032.1302281655@krein.leeds.ac.uk> <4D9F7637.5030007@ginac.de> Message-ID: <4382.1302296447@krein.leeds.ac.uk> >>>>> On Fri, 08 Apr 2011 22:55:19 +0200, "Richard B. Kreckel" said: RK> No, it's an oversight. Alright, I am attaching an easy patch just in case. Best wishes, Vladimir -- Vladimir V. Kisil email: kisilv at maths.leeds.ac.uk -- www: http://www.maths.leeds.ac.uk/~kisilv/ -------------- next part -------------- A non-text attachment was scrubbed... Name: 0001-Add-conjugate()-methods-to-functions-cosh,-sinh,-tanh..patch Type: text/x-c++ Size: 2449 bytes Desc: Conjugation patch URL: From git at ginac.de Sat Apr 9 13:12:35 2011 From: git at ginac.de (Richard B. Kreckel) Date: Sat, 9 Apr 2011 13:12:35 +0200 (CEST) Subject: [GiNaC-devel] [SCM] GiNaC -- a C++ library for symbolic computations branch, master, updated. release_1-4-0-336-ge7d59ed Message-ID: <20110409111236.2DC55F002BE@cebix.net> This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "GiNaC -- a C++ library for symbolic computations". The branch, master has been updated via e7d59ed49503cfe73fdb6038c2c69c87cbde7c24 (commit) from 286b0d93528e35957a50c51343e0b4a9bc623bce (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit e7d59ed49503cfe73fdb6038c2c69c87cbde7c24 Author: Vladimir V. Kisil Date: Sat Apr 9 12:40:38 2011 +0200 Add conjugate() methods to functions cosh, sinh, tanh. ----------------------------------------------------------------------- Summary of changes: ginac/inifcns_trans.cpp | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-) hooks/post-receive -- GiNaC -- a C++ library for symbolic computations