[gambit-list] gambit-c pcre loadable library crashes at ___make_vector

Ben Weaver weaver at coptix.com
Thu Oct 19 22:32:50 EDT 2006


Hello All,

I'm trying to write a PCRE FFI for Gambit Version 4.0 beta 17.  One of
my C functions, c_wrap_pcre_match_ovector, is meant to convert the
offset vector from a PCRE match (simply an array of integers) into a
scheme vector.  This function is attached at the end of this email as
well as a crash report.

The code works fine if everything is compiled and run like this:

   gsc pcre.scm
   gcc pcre*.c -lpcre -lgambc
   ./a.out

But when I try to compile it as a loadable library, my programs
crash as soon as ___make_vector is called from
c_wrap_pcre_match_ovector.  This is how I'm trying to compile and use the
library:

   gsc -o pcre.o1.c -flat pcre > /dev/null
   gcc -o pcre.o1 -bundle -D___DYNAMIC -lpcre pcre-wrapper.c pcre.c pcre.o1.c
   gsi pcre.o1 pcre-test.scm

My source files are:

   pcre.scm        The FFI wrappers
   pcre-wrapper.c  Some wrapper functions, including c_wrap_pcre_match_ovector
   pcre-wrapper.h  Declarations for pcre-wrapper.c
   pcre-test.scm   Some test calls to pcre-match, etc.

I'm using gcc 4.0.1 on Mac OS X 10.4.8 (PowerPC).

Any help is appreciated.  On a related note, is there a benefit to
constructing a vector like this in C-space versus making a c-lambda to
grab an entry from the int[] and constructing the vector in
scheme-space instead?  I considered both options, but my rational for
constructing the vector in C-space is to minimize the number of FFI
calls needed to process a match.

Thanks,

-Ben

=================================================================

___SCMOBJ c_wrap_pcre_match_ovector(c_wrap_pcre_match *match) {
        ___SCMOBJ ___err = ___FIX(___NO_ERR);
        ___SCMOBJ result;
        ___SCMOBJ offset;
        ___SCMOBJ length;
        int i, limit;

        if ((match == NULL) || ((limit = match->rc) < 0)) {
                return ___FAL;
        }

        if (limit == 0) {
                /*
                 * ovector wasn't big enough, the first 2/3 are used 
                 * and the rest of the matches were discarded
                 */
                limit = match->ovecsize / 3;
        }

        /*  convert the ovector to a scheme vector */
        limit = 2 * limit;

        /* CRASH happens at the line below */
        result = ___EXT(___make_vector)(limit, ___FAL, ___STILL);

        if (___FIXNUMP(result)) {
                return result;
        }

        for (i = 0; (i < limit) && (___err == ___FIX(___NO_ERR)); i++)
	{
                ___BEGIN_SFUN_INT_TO_SCMOBJ(match->ovector[i], offset, 1)
                ___FIELD(result, i) = offset;
                ___END_SFUN_INT_TO_SCMOBJ(match->ovector[i], offset, 1)
        }

        ___EXT(___release_scmobj)(result);

        if (___err != ___FIX(___NO_ERR)) {              
                return ___err;
        }

        return result;
}

=================================================================

Date/Time:      2006-10-19 22:06:37.043 -0400
OS Version:     10.4.8 (Build 8L127)
Report Version: 4

Command: gsi
Path:    /usr/local/bin/gsi
Parent:  zsh [25726]

Version: ??? (???)

PID:    27331
Thread: 0

Exception:  EXC_BAD_ACCESS (0x0001)
Codes:      KERN_PROTECTION_FAILURE (0x0002) at 0x0000040c

Thread 0 Crashed:
0   pcre.o1	0x003e34e8 c_wrap_pcre_match_ovector + 156 (bundle1.s:283)
1   pcre.o1	0x003e5244 ___H__20_pcre_23_5 + 412 (bundle1.s:283)
2   gsi		0x001bb338 ___call + 376 (crt.c:355)
3   gsi		0x001bc2bc ___setup + 3204 (crt.c:355)
4   gsi		0x001b6390 ___main + 2464 (crt.c:355)
5   gsi		0x000048e8 ___main_char + 132 (crt.c:355)
6   gsi		0x000047f4 main + 40 (crt.c:355)
7   gsi		0x00001e30 _start + 344 (crt.c:272)
8   gsi		0x00001cd4 start + 60

Binary Images Description:
    0x1000 -   0x1d7fff gsi	/usr/local/bin/gsi
  0x3e2000 -   0x3f6fff pcre.o1 /Users/bweaver/work/weaver at coptix.com/pcre/pcre.o1
  0x505000 -   0x514fff libpcre.0.dylib /usr/local/lib/libpcre.0.dylib
0x8fe00000 - 0x8fe51fff dyld 45.3	/usr/lib/dyld
0x90000000 - 0x901bcfff libSystem.B.dylib /usr/lib/libSystem.B.dylib
0x90214000 - 0x90219fff libmathCommon.A.dylib /usr/lib/system/libmathCommon.A.dylib
0x94be3000 - 0x94c03fff libmx.A.dylib	/usr/lib/libmx.A.dylib

Model: PowerBook6,2, BootROM 4.7.5f1, 1 processors, PowerPC G4  (1.1),
1 GHz, 768 MB
Graphics: GeForce FX Go5200 32MB, GeForce FX Go5200 32MB, AGP, 32 MB
Memory Module: DIMM0/BUILT-IN, 256 MB, built-in, built-in
Memory Module: DIMM1/J31, 512 MB, DDR SDRAM, PC2700U-25330
AirPort: AirPort Extreme, 405.1 (3.90.34.0.p18)
Modem: MicroDash, UCJ, V.92, 1.0F, APPLE VERSION 2.6.6
Bluetooth: Version 1.7.8f2, 2 service, 0 devices, 1 incoming serial
ports
Network Service: Built-in Ethernet, Ethernet, en0
Parallel ATA Device: MATSHITACD-RW  CW-8123, 
Parallel ATA Device: TOSHIBA MK6025GAS, 55.89 GB
USB Device: Hub in Apple Pro Keyboard, Mitsumi Electric, Up to 12
Mb/sec, 500 mA
USB Device: Microsoft IntelliMouse. Explorer, Microsoft, Up to 1.5
Mb/sec, 100 mA
USB Device: Apple Pro Keyboard, Mitsumi Electric, Up to 12 Mb/sec, 250
mA
USB Device: Bluetooth HCI, , Up to 12 Mb/sec, 500 mA




More information about the Gambit-list mailing list