ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I actually still did it myself, but used your code to help me where I got stuck. There were a few places where you misinterpreted my code because of my mistakes.
Now I'll see if it actually works...
Click here to see the post LQ members have rated as the most helpful post in this thread.
Why did you delete all your posts? Was I the one who insulted you?
Anyway:
I made it try to evaluate a single number node, but it segfaults.
I used GDB, and it says that it's trying to push to an array whose count is a really huge appearantly random number. I have no idea how it happens. The error occurred in GC_realloc, which was callsed by array_push, which was called by env_set, which was called by create_number_env.
Here is my code, in case you want it (while making the archive, I accidentally overwrote array.c with an archive of the rest of the files because of a mistake in the command line. But I got it back via the attachment I made to a previous post, and thankfully array.c was one of the files that had no errors that I would need to fix again):
I actually still did it myself, but used your code to help me where I got stuck. There were a few places where you misinterpreted my code because of my mistakes.
Now I'll see if it actually works...
Great! I hoped you'd do exactly that, use it as a helper to fix your own code. It's much more useful that way.
I'm not surprised I'd misinterpreted your code here and there, especially the macros are a devil to parse right.
Perhaps static inline functions would be better than macros here? They're just as fast in C99, no downsides or overhead compared to macros.
Instead of the build.sh script, you might find this Makefile easier to use:
For example, make will track changes, so that it only recompiles the changed bits. To do a full rebuild, run make clean all
I also used quite aggressive optimization settings, -O3 -ftree-vectorize -fomit-frame-pointer that tend to produce very efficient code on all architectures.
If you really like the output with ANSI colors, you could use this Makefile instead:
Why did you delete all your posts? Was I the one who insulted you?
No, of course not. It was an unambiguous direct insult from a member that to my knowledge has never participated in the same threads I have. I thought XavierP had decided to let the insult stand, but I was wrong; it was an unfortunate oversight -- and an understandable one, because XavierP couldn't even see the insult at all. I assumed this was modus operandi for LQ moderators, and deleted my posts in an attempt to bring it to wider attention. So it wasn't the insult per se; I have very little tolerance for bullying, and none at all for those that turn a blind eye. Unfortunately, I ended up bullying XavierP myself.
Quote:
Originally Posted by MTK358
I used GDB, and it says that it's trying to push to an array whose count is a really huge appearantly random number. I have no idea how it happens. The error occurred in GC_realloc, which was callsed by array_push, which was called by env_set, which was called by create_number_env.
Here is the warning gcc-4.4.3 with the above Makefile reports:
Code:
env.c: In function ‘env_set’:
env.c:30: warning: ‘env_with_member’ may be used uninitialized in this function
Basically, env_with_member may not be set in the do-while loop. Because it's a local variable, it's not initialized by the compiler (to zeros), and gets some random value (whatever was in the stack there earlier).
I think you can just set env_with_member initially to this, if I understand the code correctly -- that it's supposed to be the topmost parent with a key of that name, or this one if no such key exists.
Last edited by Nominal Animal; 02-27-2011 at 06:00 PM.
Reason: added why I deleted my posts.
No, of course not. It was an unambiguous direct insult from a member that to my knowledge has never participated in the same threads I have. I thought XavierP had decided to let the insult stand, but I was wrong; it was an unfortunate oversight -- and an understandable one, because XavierP couldn't even see the insult at all. I assumed this was modus operandi for LQ moderators, and deleted my posts in an attempt to bring it to wider attention. So it wasn't the insult per se; I have very little tolerance for bullying, and none at all for those that turn a blind eye. Unfortunately, I ended up bullying XavierP myself.
But you deleted your first post here, before anyone ever posted in this thread!
Almost all your useful posts are gone, and I don't remember seeing anything remotely insulting to anyone in them!
I would like to know, but it seems like you have PM disabled.
Reading symbols from /home/michael/newlang/a.out...done.
(gdb) run
Starting program: /home/michael/newlang/a.out
[Thread debugging using libthread_db enabled]
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff785954e in ?? () from /lib/libc.so.6
(gdb) bt
#0 0x00007ffff785954e in ?? () from /lib/libc.so.6
#1 0xdac803ff83b189c2 in ?? ()
Cannot access memory at address 0xdac803ff83b189c2
?????????????????
Note that it first segfaulted due to an unititialized pointer, because initially I wrote
Code:
if (node->child_count == 1) env_with_var = (env_t*) node_eval(node->children[1], env);
instead of
Code:
if (node->child_count == 1) env_with_var = (env_t*) node_eval(node->children[0], env);
in line 95 of ast.c (in the part that evaluates member access nodes). But when I fixed it, the above error happens!
Okay, so the first complex bit of code executed is this in ast.c, right?
Code:
case NODETYPE_CALL:
{
function_t *func = (function_t*) node_eval(node->children[0], env);
if (func == NULL || func->objtype != OBJTYPE_FUNCTION)
node_eval_throw_exception(create_exception_env((object_t*) create_string_env("TypeError"), (object_t*) create_string_env("Only functions can be called")));
int i;
for (i=0; i<((array_t*) (node->payload))->count; i++)
array_set(node->payload, i, node_eval(array_get(node->payload, i), env));
return func->call(func, node->payload);
}
I'd first add a couple of fprintf(stderr, ...)'s in there, to see how far that gets, and what the various variables actually hold. Also, I'd add another fprintf(stderr, ...) in the beginning of node_function_call() in node_function.c, to see if the callback stuff is initialized correctly. (If it never gets called, something must be wrong in the construction phase, node_function_new() in the same file.)
Hey, is there a return missing from before the node_eval_throw_exception above?
Quote:
Originally Posted by MTK358
Same thing happens (using "gcc -c -g -O0 -Wall sourcefile.c" to compile each file, and "gcc -lgc *.o" to link).
Yes, but the gdb output should contain more details, like function names and so on, where the problems happen. Could you show the gdb output when the binaries are compiled like that and the program run in gdb, please?
Last edited by Nominal Animal; 02-28-2011 at 12:24 PM.
number_type.c: In function ‘ismembernum’:
number_type.c:8:12: error: ‘member’ redeclared as different kind of symbol
number_type.c:6:35: note: previous definition of ‘member’ was here
number_type.c:8:5: warning: passing argument 2 of ‘env_get’ from incompatible pointer type
env.h:29:7: note: expected ‘char *’ but argument is of type ‘struct env_t *’
number_type.c: In function ‘ismembernum’:
number_type.c:8:12: error: ‘member’ redeclared as different kind of symbol
number_type.c:6:35: note: previous definition of ‘member’ was here
number_type.c:8:5: warning: passing argument 2 of ‘env_get’ from incompatible pointer type
env.h:29:7: note: expected ‘char *’ but argument is of type ‘struct env_t *’
What does it mean? This is the code:
You have a local env_t variable named member, but also a parameter member to the function. You need to rename one.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.