[Home]

Summary:ASTERISK-05093: on Big Endian platforms, expressions $[] don't work with the new expression parser
Reporter:Alex Zhilyakov (azhilyakov)Labels:
Date Opened:2005-09-14 17:42:49Date Closed:2008-01-15 15:49:01.000-0600
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Core/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) endian.patch
Description:I just compiled Asterisk 1.2.0-beta1 on Solaris 10 (sparc).
While configuring it, I noticed that expressions $[ ] do not work at all.

Example:
Line: exten => s,6,NoOp($[1+1])
Debugs: -- Executing NoOp("SIP/fwd.pulver.com-0010ece8", "0") in new stack
Problem: 1+1 should be 2, not 0

Investigating the problem, I compiled testexpr2 program, which does not work too:

$./testexpr2 1+1
=====0======
(should be 2, not 0)

./testexpr2 XX=XX
=====0======
(should be 1, not 0)

./testexpr2 AAA    
=====AAA======
(OK)

Please assist me with the problem when possible.
Thank you.

-Alex


****** ADDITIONAL INFORMATION ******

gcc version 3.4.2
flex 2.5.31
bison (GNU Bison) 1.875d
Comments:By: Kevin P. Fleming (kpfleming) 2005-09-14 19:06:10

Can you give us remote access to your machine for testing? Find somebody on the #asterisk-bugs IRC channel to help you.

By: Russell Bryant (russell) 2005-09-19 08:46:49

The same problem has been reported for mac osx as well.

Try running testexpr2 the following way:

$ ./testexpr2 "$[3 + 2]"
=====5======
$ ./testexpr2 "$[1 > 0]"
=====1======
$ ./testexpr2 "$[0 > 1]"
=====0======

By: Alex Zhilyakov (azhilyakov) 2005-09-19 09:57:32

I tested testexpr with provided syntax and it works fine.

However, I'm still not getting expressions to work in extensions.conf and extensions.ael

As reported in original post:
Line: exten => s,6,NoOp($[1+1])
Debugs: -- Executing NoOp("SIP/fwd.pulver.com-0010ece8", "0") in new stack
Problem: 1+1 should be 2, not 0

Same problem shows up for both, extensions.conf and .ael.

Please advise.


-Alex

By: Russell Bryant (russell) 2005-09-19 11:11:25

Yes, I am seeing the same behavior on my mac.

I just wanted to verify that testexpr2 worked correctly on Solaris as well.

By: Tilghman Lesher (tilghman) 2005-09-19 11:46:18

azhilyakov:  try adding spaces to your expressions, i.e.

$[1 + 1], not
$[1+1]

By: Tilghman Lesher (tilghman) 2005-09-19 11:48:29

I suspect the problem is that build_tools/vercomp is a Linux binary, which does not run on Solaris, so you're getting the older parser, which requires spaces around operators.

By: Alex Zhilyakov (azhilyakov) 2005-09-19 12:00:22

Created the following:

context default {
       s => {
               Wait(1);
               Answer();

               NoOp($[1+1]);
               NoOp($[1 + 1]);
               NoOp($[ 1 + 1 ]);
               NoOp( $[ 1 + 1 ] );

               HangUp();
       };
};

Debugs to:

*CLI>     -- Executing Wait("SIP/callcentric.com-00118c18", "1") in new stack
   -- Executing Answer("SIP/callcentric.com-00118c18", "") in new stack
   -- Executing NoOp("SIP/callcentric.com-00118c18", "0") in new stack
   -- Executing NoOp("SIP/callcentric.com-00118c18", "0") in new stack
   -- Executing NoOp("SIP/callcentric.com-00118c18", "0") in new stack
   -- Executing NoOp("SIP/callcentric.com-00118c18", " 0 ") in new stack
   -- Executing Hangup("SIP/callcentric.com-00118c18", "") in new stack
 == Spawn extension (default, s, 7) exited non-zero on 'SIP/callcentric.com-00118c18'


Problem: all four expressions resulted 0, not 2.
So, spaces are not an issue here.


-Alex

By: Tilghman Lesher (tilghman) 2005-09-19 12:06:20

Could you run your test out of extensions.conf, to isolate any possible issues with AEL?

By: Alex Zhilyakov (azhilyakov) 2005-09-19 12:23:31

Sure thing!

extensions.conf:

[default]
exten => s,1,Wait(1)
exten => s,2,Answer()
exten => s,3,NoOp($[1+1]);
exten => s,4,NoOp($[1 + 1]);
exten => s,5,NoOp($[ 1 + 1 ]);
exten => s,6,NoOp( $[ 1 + 1 ] );
exten => s,7,HangUp()

Debugs to:
*CLI>     -- Executing Wait("SIP/callcentric.com-001162f8", "1") in new stack
   -- Executing Answer("SIP/callcentric.com-001162f8", "") in new stack
   -- Executing NoOp("SIP/callcentric.com-001162f8", "0") in new stack
   -- Executing NoOp("SIP/callcentric.com-001162f8", "0") in new stack
   -- Executing NoOp("SIP/callcentric.com-001162f8", "0") in new stack
   -- Executing NoOp("SIP/callcentric.com-001162f8", " 0 ") in new stack
   -- Executing Hangup("SIP/callcentric.com-001162f8", "") in new stack
 == Spawn extension (default, s, 7) exited non-zero on 'SIP/callcentric.com-001162f8'

Problem: 0 instead of 2

-Alex

By: Russell Bryant (russell) 2005-09-19 13:46:24

I'm merging issue ASTERISK-5111 with this one since they appear to be the same problem.

By: Russell Bryant (russell) 2005-09-22 22:35:30

Well, testexpr2 in fact does *not* work.  The syntax used in the original report was the correct syntax.  The reason it worked when I did ./testexpr2 "$[1 + 1]", bash was evaluating that expression, so the application was just receiving "2".  D'OH!

This appears to be an Endianness issue.  Just recently, we started directly including the C files for the expression parser to remove the dependency on flex/bison.  I would like to verify that expressions do not work on linux PPC to verify this.  Likewise, someone could test this in Solaris x86.



By: Alex Zhilyakov (azhilyakov) 2005-09-23 06:32:02

Oh! That's correct. Must use single quotes for the expresion not to be evaluated by bash.

$echo "$[ 1 + 1 ]"
2
$echo '$[ 1 + 1 ]'
$[ 1 + 1 ]
$./testexpr2 '$[ 1 + 1 ]'
[LOG: lev:3 file:ast_expr2.fl  line:168 func: ast_yyerror  ast_yyerror(): syntax error: syntax error, unexpected TOKEN, expecting $end; Input:
$[ 1 + 1 ]
  ^
=====$======


-Alex

By: Alex Zhilyakov (azhilyakov) 2005-09-23 06:37:50

Do you have a Linux/PPC or we'll have to wait until somebody kindly donates Linux/PPC diagnostics?

I have a spare Sparc Ultra5 machine doing nothing here. It has sol10 now. I can give it to you as test-bed, or I could install linux/ppc on it and test. Let me know.


-Alex Zhilyakov

By: Russell Bryant (russell) 2005-09-23 11:32:28

There is a linux/ppc machine at Digium that I should be able to test this on.  I just haven't had the chance yet.  I have a test in a couple of hours.  :)

I will surely test it this weekend if nobody else gets to it first.

By: Russell Bryant (russell) 2005-09-24 18:00:16

Confirmed.  Expressions do not work on linux PPC, either.

By: Russell Bryant (russell) 2005-09-24 18:14:27

FYI, I regenerated the .c files on a Linux/PPC machine and the expressions still don't work.  This is a problem directly related to the new parser, and not the fact that we are now including the C files directly instead of having them generated at build time.

By: Michael Jerris (mikej) 2005-09-24 18:26:41

murf- Can you please take a peek at this issue.

By: Steve Murphy (murf) 2005-09-24 22:29:19

Hey, guys... I've just read thru the bug history. Not that it much matters,
but even typing:

./testexpr2 '$[ 1 + 1 ]'

will ALWAYS yield:

[LOG: lev:3 file:ast_expr2.fl line:168 func: ast_yyerror ast_yyerror(): syntax error: syntax error, unexpected TOKEN, expecting $end; Input:
$[ 1 + 1 ]
  ^
=====$======

on all architectures, not because of big or little endian-ness, but because the expression parser normally gets the contents of the $[  ], and chokes if the "wrapper" is present. The better test would be:

./testexpr2 ' 1 + 1 '


This should yield '2', but I suspect on the BigEndian machines, it will behave as asterisk did, and yield a '0'.

I need to debug this on a big-endian machine, and all I have is a solaris 2.6 machine. I'll try to compile at least the expression parser and testexpr, and try to see what gives.

One little thing, of low probability, but should be verified nonetheless. When asterisk reports a '0' result, are there any error messages in the /var/log/asterisk/messages file? Anything of relevance there?

By: Russell Bryant (russell) 2005-09-24 22:45:50

Yeah, I noted in a previous bugnote that I knew that using $[...] with testexpr2 was the incorrect syntax.

By: Roy Sigurd Karlsbakk (rkarlsba) 2005-09-25 08:14:20

MATH() seems to work, though

By: Steve Murphy (murf) 2005-09-25 08:37:11

OK, did the debug last night on Solaris, which replicated the problem.
It was caused by some perfectly bad coding on my part. I made a small fix, and values are now properly passed forward up the grammar chain. And yes, it could easily be a endian issue, as it had to everything to do with how the union of a string pointer (32 bits) and a long long (64 bits) were laid out in memory. Was the string pointer overlaying the left or right side of the long long? Ugh, I can't believe I could have been so sloppy. Sorry.

I'll post the patch here asap, but if I get interrupted this morn, it may have to wait till afternoon...

By: Steve Murphy (murf) 2005-09-25 08:45:21

OK, yes, here's the patch. Maintainers, consider applying it ASAP.

By: Roy Sigurd Karlsbakk (rkarlsba) 2005-09-25 08:48:06

return -ENOATTACHMENT ?

By: Steve Murphy (murf) 2005-09-25 09:09:54

Hmm. Thought the "upload file" did its thing. Guess not. Did it again, my bug page now registers the "endian.patch" as attached file. The world is full of wonder.

By: Alex Zhilyakov (azhilyakov) 2005-09-25 09:16:03

testexpr2 is fine now.

$./testexpr2 '1+1'
=====2======
./testexpr2 '1 + 1'
=====2======
./testexpr2 '1+2*3'
=====7======
$./testexpr2 '(1+1) > (5-4)'
=====1======
$./testexpr2 '(1+1) < (5-4)'
=====0======

By: Alex Zhilyakov (azhilyakov) 2005-09-25 09:27:59

expressions in extensions.conf work fine too:

[default]
exten => s,1,Wait(1)
exten => s,2,Answer()
exten => s,3,NoOp($[1+1]);
exten => s,4,NoOp($[1 + 1]);
exten => s,5,NoOp($[1 + 2 * 3]);
exten => s,6,NoOp($[(1+1) > (5-4)]);
exten => s,7,NoOp($[(1+1) < (5-4)]);
exten => s,8,HangUp()

Debugs to:
   -- Executing Wait("SIP/17772852090-2538", "1") in new stack
   -- Executing Answer("SIP/17772852090-2538", "") in new stack
   -- Executing NoOp("SIP/17772852090-2538", "2") in new stack
   -- Executing NoOp("SIP/17772852090-2538", "2") in new stack
   -- Executing NoOp("SIP/17772852090-2538", "7") in new stack
   -- Executing NoOp("SIP/17772852090-2538", "1") in new stack
   -- Executing NoOp("SIP/17772852090-2538", "0") in new stack
   -- Executing Hangup("SIP/17772852090-2538", "") in new stack

By: Roy Sigurd Karlsbakk (rkarlsba) 2005-09-25 09:39:36

eeh. i don't understand this. this is what's at the start: where that patch is trying to change stuff. the patch simply doesn't fit......

this is current (20050925 16:38 CEST) CVS

   146 %%
   147
   148 start: expr { ((struct parser_control *)kota)->result = $$; }
   149         ;
   150
   151 expr:   TOKEN

By: Russell Bryant (russell) 2005-09-25 13:06:59

I got this approved by Mark and it has been applied to cvs head.  Thanks to everyone that helped figure this one out!

By: Digium Subversion (svnbot) 2008-01-15 15:49:01.000-0600

Repository: asterisk
Revision: 6645

U   trunk/ast_expr2.c
U   trunk/ast_expr2.y
U   trunk/ast_expr2f.c

------------------------------------------------------------------------
r6645 | russell | 2008-01-15 15:49:00 -0600 (Tue, 15 Jan 2008) | 3 lines

Fix expressions on Big Endian platforms (issue ASTERISK-5093)
using bison version 1.875d, flex version 2.5.31

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=6645