Re: perl crash with Inline / AP PCRASH // WINDOWS ### GOOD MAIL ###
[email protected] ("Sisyphus")
| Newsgroups | perl.inline |
|---|---|
| Message-ID | <D023513262B54AD19915220E7253DD62@desktop2> |
----- Original Message ----- From: "lh" <[email protected]> To: <[email protected]> Sent: Friday, October 19, 2012 6:28 AM Subject: perl crash with Inline / APPCRASH // WINDOWS ### GOOD MAIL ### Hello, --->I' sorry but thanks toThank you to consider only this email, the previous had a bad copy / paste.<--- <<<< sv_setpvn(out_buffer, compressed_buffer, samples_count); >>>>> I have an application which run with Inline C with 120 Windows threads. THe application run well with 120 threads but when i increase the number of thread to 200, ->>>> i have an windows crash applet APPCRASH error code c000005. I have comment the sv_setpvn function and the crash didnt appeared. Is there a limitation with the number of thread OR my code is not good ? For information samples_count is ALWAYS equal to 160. OS context ------------ Windows 2008 server Perl context -------------- perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for MSWin32-x64-multi-thread Thanks Laurent H. void alaw_compress_buffer_optimized(char *linear, int samples_count, SV * out_buffer) { int i; unsigned short index; short sample; short * samples_vals=(int) linear; unsigned char compressed_buffer[samples_count]; for (i=0;i<samples_count;i=i+1) { sample=samples_vals[i]; index=(samples_vals[i] + 32767); compressed_buffer[i]=l2aTable[index]; } sv_setpvn(out_buffer, compressed_buffer, samples_count); } ============================================= ============================================= Given that samples_count is an *argument* to the sub, I'm not sure that it's a good idea to declare: unsigned char compressed_buffer[samples_count]; Anyone ? I would be inclined to declare: unsigned char * compressed_buffer; and then allocate the memory dynamically. Here's a rewrite (untested): ################################### void alaw_compress_buffer_optimized(char *linear, int samples_count, SV * out_buffer) { int i; unsigned short index; short sample; short * samples_vals=(int) linear; unsigned char *compressed_buffer; Newxz(compressed_buffer, samples_count, unsigned char); if(compressed_buffer == NULL) croak("Failed to allocate memory"); for (i=0;i<samples_count;i=i+1) { sample=samples_vals[i]; index=(samples_vals[i] + 32767); compressed_buffer[i]=l2aTable[index]; } sv_setpvn(out_buffer, compressed_buffer, samples_count); Safefree(compressed_buffer); /* Free memory */ } ################################### If it turns out that threading is involved in the problem, you'll probably get best help from perlmonks ( http://www.perlmonks.org/index.pl?node=Seekers%20of%20Perl%20Wisdom ) where there are one or two very knowledgeable people on Windowx threads issues. (Not me - I run Windows, but I'm a hopeless klutz where threading is involved.) If you could provide a full (but as short as possible) working demo of the problem, your chances of getting the problem sorted out (both here and at perlmonks) would be greatly improved. I don't see any problem with the following code: ################################### use warnings; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; void foo(int samples_count, SV * out_buffer) { int i; unsigned char * x; Newx(x, samples_count, unsigned char); if(x==NULL)croak("Failed to allocate memory"); for(i = 0; i < samples_count; i++) x[i] = 65 + (i % 10); sv_setpvn(out_buffer, x, samples_count); Safefree(x); } EOC my $x; foo(160, $x); print length($x),"\n$x\n"; ################################### Cheers, Rob