Segfault - bug or feature?

13 views
Skip to first unread message

Hans Nowak

unread,
Mar 31, 2015, 4:12:22 PM3/31/15
to ooc-...@googlegroups.com
Hi,

I was tinkering with some Regexp code and ran into a segfault. The following snippet reproduces it:

/* null-class.ooc */

null class name println()
/* this does NOT segfault */

import text/Regexp

pattern
:= Regexp compile("[abc]+")
found
:= pattern matches("zzz")
found
class name println()
/* this does segfault */


In the documentation, it says that Regexp.matches returns null if there is no match (see http://ooc-lang.org/docs/sdk/text/#regular-expressions). I'm not sure what it returns here, but 'found class' and 'found class name' by themselves don't cause the segfault; it is not until the println() is added, that it appears.

This happens with rock 0.9.9 on Mac OS X 10.9, installed via Homebrew.

Of course, I am probably doing something wrong (being an ooc beginner and all), but I thought I'd ask. :-)

Thanks,

--Hans

Amos Wenger

unread,
Mar 31, 2015, 4:18:00 PM3/31/15
to Hans Nowak, ooc-...@googlegroups.com
Hey Hans,

I'm assuming the C compiler optimizes away accesses to 'found class' and 'found class name', seeing as they're not used. Calling println on it makes it used and so, it crashes.

As for why `null class` doesn't crash, it's because it's replaced directly by `Pointer` in the generated code, which looks like this:

lang_String__String_println(((lang_types__Class*)lang_types__Pointer_class())->name);

Cheers,
- Amos

--
You received this message because you are subscribed to the Google Groups "ooc-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ooc-lang+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages