Dear experts,

Can anyone see what I'm doing wrong here.  Source archive is attached,
but here is the entire code:

----------------------------------------------------------------------
' Gambas module file

' void uuid_generate(uuid_t out);
Extern UUID_Gen(op As Pointer) As Pointer In "libuuid:1" Exec
"uuid_generate"

' void uuid_unparse(uuid_t uu, char *out)
Extern UUID_ToStr(ip As Pointer, op As Pointer) As Pointer In
"libuuid:1" Exec "uuid_unparse"

Public Sub Main()

  Dim OP As Pointer    ' ptr to the uuid returned by uuid_generate
  Dim SP As Pointer    ' ptr to the string returned by uuid_unparse
  
  Dim sOP As String    ' our result (UUID as a string)
  Dim rtn As Integer   ' int rtn code from extern funcs
  Dim sArch As String  ' system architecture (selects pointer length)
  
  sArch = System.Architecture
  Error "Arch=" & sArch
  
  OP = Alloc(IIf(sArch = "x86", 4, 8))
  SP = Alloc(IIf(sArch = "x86", 4, 8))
  
  rtn = UUID_Gen(OP)
  Error "UUID_Gen=" & rtn
  
  rtn = UUID_ToStr(OP, SP)
  sOP = String@(SP)
  Error Subst("UUID_ToStr=&1\tUUID=&2", rtn, sOP)
  Error
  
  Free(OP)
  Free(SP)
  
End         '<- the problem happens here
----------------------------------------------------------------------

I get variously a SegFault(11) or an Aborted(6) here. The Segfault shows
nothing, but the Abort produces an invalid pointer dump like the
following: 

*** glibc detected *** demoUUID: munmap_chunk(): invalid pointer:
0x0899eba0 ***
======= Backtrace: =========
/lib/i686/libc.so.6(+0x72d32)[0xb75ffd32]
demoUUID[0x8055232]
demoUUID[0x806b872]
demoUUID[0x804b3cd]
/lib/i686/libc.so.6(__libc_start_main+0xf5)[0xb75a69e5]
demoUUID[0x804b40d]
======= Memory map: ========
08048000-08094000 r-xp 00000000 08:01 818112     /usr/bin/gbx3
08094000-08099000 rw-p 0004c000 08:01 818112     /usr/bin/gbx3
08099000-0809b000 rw-p 00000000 00:00 0 
08996000-089b7000 rw-p 00000000 00:00 0          [heap]
417e7000-417ec000 r-xp 00000000 08:01
597595     /usr/lib/libffi.so.5.0.9
417ec000-417ed000 rw-p 00005000 08:01
597595     /usr/lib/libffi.so.5.0.9
b69d3000-b69d6000 r-xp 00000000 08:01 1112777    /lib/libuuid.so.1.3.0
b69d6000-b69d7000 rw-p 00002000 08:01 1112777    /lib/libuuid.so.1.3.0
b69ff000-b6a00000 rw-p 00000000 00:00 0 
b6a00000-b6a07000 r--s 00000000 08:01
761994     /usr/lib/gconv/gconv-modules.cache
b6a07000-b6a19000 r-xp 00000000 08:01
683710     /usr/lib/gambas3/gb.eval.so.0.0.0
b6a19000-b6a1c000 rw-p 00011000 08:01
683710     /usr/lib/gambas3/gb.eval.so.0.0.0
b6a1c000-b721c000 rw-p 00000000 00:00 0 
b721c000-b738c000 r--p 00334000 08:01
738240     /usr/share/locale/locale-archive
b738c000-b758c000 r--p 00000000 08:01
738240     /usr/share/locale/locale-archive
b758c000-b758d000 rw-p 00000000 00:00 0 
b758d000-b7734000 r-xp 00000000 08:01 1117283    /lib/i686/libc-2.16.so
b7734000-b7735000 ---p 001a7000 08:01 1117283    /lib/i686/libc-2.16.so
b7735000-b7737000 r--p 001a7000 08:01 1117283    /lib/i686/libc-2.16.so
b7737000-b7738000 rw-p 001a9000 08:01 1117283    /lib/i686/libc-2.16.so
b7738000-b773c000 rw-p 00000000 00:00 0 
b773c000-b7752000 r-xp 00000000 08:01
1112626    /lib/i686/libpthread-2.16.so
b7752000-b7753000 r--p 00015000 08:01
1112626    /lib/i686/libpthread-2.16.so
b7753000-b7754000 rw-p 00016000 08:01
1112626    /lib/i686/libpthread-2.16.so
b7754000-b7756000 rw-p 00000000 00:00 0 
b7756000-b7759000 r-xp 00000000 08:01 1112764    /lib/libdl-2.16.so
b7759000-b775a000 r--p 00002000 08:01 1112764    /lib/libdl-2.16.so
b775a000-b775b000 rw-p 00003000 08:01 1112764    /lib/libdl-2.16.so
b775b000-b7764000 r-xp 00000000 08:01 1112247    /lib/libintl.so.8.1.2
b7764000-b7765000 rw-p 00009000 08:01 1112247    /lib/libintl.so.8.1.2
b7765000-b77a3000 r-xp 00000000 08:01 1112624    /lib/i686/libm-2.16.so
b77a3000-b77a4000 r--p 0003d000 08:01 1112624    /lib/i686/libm-2.16.so
b77a4000-b77a5000 rw-p 0003e000 08:01 1112624    /lib/i686/libm-2.16.so
b77a9000-b77c5000 r-xp 00000000 08:01
1117309    /lib/libgcc_s-4.7.2.so.1
b77c5000-b77c6000 rw-p 0001b000 08:01
1117309    /lib/libgcc_s-4.7.2.so.1
b77c6000-b77c8000 rw-p 00000000 00:00 0 
b77c8000-b77cd000 r-xp 00000000 08:01
683612     /usr/lib/gambas3/gb.debug.so.0.0.0
b77cd000-b77ce000 rw-p 00004000 08:01
683612     /usr/lib/gambas3/gb.debug.so.0.0.0
b77ce000-b77cf000 rw-p 00000000 00:00 0 
b77cf000-b77ed000 r-xp 00000000 08:01 1112632    /lib/ld-2.16.so
b77ed000-b77ee000 r--p 0001d000 08:01 1112632    /lib/ld-2.16.so
b77ee000-b77ef000 rw-p 0001e000 08:01 1112632    /lib/ld-2.16.so
bff86000-bffa7000 rw-p 00000000 00:00 0          [stack]
ffffe000-fffff000 r-xp 00000000 00:00 0          [vdso]


tia
Bruce

Attachment: demoUUID-0.0.1.tar.gz
Description: application/compressed-tar

------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most 
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to