Comments (7)
As you found out on stackoverflow, size
needs to be length
, as in ruby. A call on nil segfaults unfortunately.
A method on nil just silently fails as you also found out in #79.
from potion.
Related to this most probably, the comparison operators also segfault on nil. You can see this by running example/palindrome.pn with no arguments. With the -B switch it completes successfully, but segfaults under the jit.
from potion.
The question is if we should slow down jit by checking argument types or not.
So far I check with a debugging potion, and not without.
from potion.
I don't think it's necessary to type check arguments.
The problem is in potion_x86_call, where it doesn't check for nil before attempting to dereference memory. I think this needs to be added to the beginning of the function, otherwise it attempts to call potion_obj_get_call which returns nil, which is then attempted to be deferenced as a memory location.
Alternatively, the necessary code could be added just after the lines (in vm-x86.c)
//[b]: got the method, call it (first special slot from PNClosure)
TAG_LABEL(tag_b);
The memory deference for nil is in the line immediately following this.
I'm not sure where the best place is to put it, nor do I have the necessary ASM skills to do the modification myself.
from potion.
On Oct 16, 2015, at 5:44 PM, Peter Arthur [email protected] wrote:
I don't think it's necessary to type check arguments.
The problem is in potion_x86_call, where it doesn't check for nil before attempting to dereference memory. I think this needs to be added to the beginning of the function, otherwise it attempts to call potion_obj_get_call which returns nil, which is then attempted to be deferenced as a memory location.
Alternatively, the necessary code could be added just after the lines (in vm-x86.c)
//[b]: got the method, call it (first special slot from PNClosure)
TAG_LABEL(tag_b);
The memory deference for nil is in the line immediately following this.
Good idea. That would be only 2 lines.
I'm not sure where the best place is to put it, nor do I have the necessary ASM skills to do the modification myself.
I’ll try when I have a bit more time.
from potion.
Hi @rurban
I've dug a bit deeper into this. This particular issue is caused by potion_object_size, which attempts to return the size of the object.
Unfortunately, there are a few problems with this function.
- The number returned is a raw number, and needs to be wrapped in PN_NUM() macro in order for it to return the correct value to the caller.
- The function is not GC aware, which means that if it gets passed a FWD struct, it will fail horribly.
- The function does not consider non-pointer objects, such as PN_TRUE, PN_FALSE and PN_NUM.
I can confirm that the original code does not segfault when the line
potion_method(obj_vt, "size", potion_object_size, 0);
is commented out, indicating this is the problem.
Changing the vm call function would not fix this problem, although it wouldn't hurt to still make those changes. In fact, I think the current code correctly handles null
I really don't think this function is that useful and personally I would remove it unless we can find a reason to keep it. It can quite easily be confused with the length method, as we have already seen.
from potion.
Just fixed it, thanks.
length vs size methods:
- length is defined for tuples, tables, str and bytes, returning the number of elements
- size is defined of all objects and now also for all primitives, returning the number of used bytes for the members and fields, but not for variable length data, like str, bytes.
size is a bit ill-defined and currently not used, yes. But I'll keep it asis for now
from potion.
Related Issues (20)
- Problem with potion installation HOT 2
- Make fails HOT 4
- Migrate LGTM.com installation from OAuth to GitHub App
- Make fails HOT 1
- 1 out of 282 tests failed HOT 3
- Unable to build with the new -D_FORTIFY_SOURCE=2 HOT 3
- When building under vagrant/precise32, build succeeds but some tests, examples fail HOT 3
- test/tutorial/07_subclass.pn is failing on master HOT 4
- wrong x-1 parsing precedence, whitespace
- numeric compare in wrong integer context HOT 2
- change numcmp for eq and neq
- call on nil methods silently fail HOT 3
- Installation issue HOT 4
- callset on nil segfaults HOT 2
- fatal: Not a git repository (or any of the parent directories): .git HOT 1
- compile: unknown builtin '__builtin_saddl_overflow' HOT 4
- More segmentation faults HOT 7
- Comparison between String and number does not work as expected HOT 1
- replace mersenne twister by pcg
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from potion.