Compiling and running Average.c ( included in src zip file, syx\examples\embedding\average.c)

18 views
Skip to first unread message

faruque

unread,
May 22, 2009, 8:55:06 PM5/22/09
to Syx general discussion
Hi,
I have compiled average.c but the progam keeps crashing.
Here is my stack trace at the point of the crash

msvcr80d.dll!strlen(unsigned char * buf=0x0012ed5c) Line 81 Asm
MySyx.exe!syx_to_wstring(const char * s=0x00000000) Line 577 + 0x9
bytes C
MySyx.exe!syx_library_open(const char * location=0x00000000) Line
148 + 0x9 bytes C
MySyx.exe!syx_plugin_load(const char * name=0x00000000) Line 284 +
0x7 bytes C
MySyx.exe!syx_plugin_symbol(const char * plugin_name=0x00000000,
const char * symbol_name=0x0083c088) Line 418 + 0x9 bytes C
> MySyx.exe!syx_plugin_call(SyxInterpState * es=0x0043c808, const char * plugin_name=0x00000000, const char * func_name=0x0083c088, long method=4623972) Line 482 + 0xd bytes C
MySyx.exe!Smalltalk_pluginCall(SyxInterpState * es=0x0043c808, long
method=4623972) Line 1619 + 0x1e bytes C
MySyx.exe!syx_interp_call_primitive(short primitive=99, long
method=4623972) Line 184 + 0x13 bytes C
MySyx.exe!syx_interp_send_message(unsigned short argument=0) Line
696 + 0xe bytes C
MySyx.exe!_syx_interp_execute_byte(unsigned short byte=24576) Line
1083 + 0xa bytes C
MySyx.exe!syx_process_execute_blocking(long process=4718852) Line
415 + 0xd bytes C
MySyx.exe!syx_file_in_blocking(const char * file=0x00437ec4) Line
549 + 0x9 bytes C
MySyx.exe!main(int argc=3, char * * argv=0x00356a90) Line 45 + 0xa
bytes C


the stack trace suggests that thet crash is because the function
syx_library_open is being called to load the library at location 0.
This 0 value originated from the the function Smalltalk_pluginCall in
line 1600 of syx-primitives.c

syx_symbol plugin_name = NULL;

Any ideas on whats going wrong?


Im compiling in MS VS 2005 on XP using files from Src.syx-0.1.7.zip.
Before compiling I have added the following defines in msvs/syx-
config.

#define HAVE_FSTAT 1
#define WITH_PLUGINS 1


Thanks
Faruque

Luca Bruno

unread,
May 23, 2009, 4:56:33 AM5/23/09
to syx-d...@googlegroups.com

Passing NULL is right, because NULL means the program itself, no external
library. That's right the case of average which searches for a function
inside the program itself. The real reason is that unicode string
conversions don't ensure the given string is non-NULL.

Please consider applying the attached patch.

> #define WITH_PLUGINS 1

Nice guess, I'll commit this too if it works. Let me know.

Thanks

--
http://syx.googlecode.com - Smalltalk YX
http://lethalman.blogspot.com - Thoughts about computer technologies
http://www.debian.org - The Universal Operating System

unicode.patch
signature.asc

Gulam Faruque

unread,
May 23, 2009, 11:07:46 AM5/23/09
to syx-d...@googlegroups.com
Hi
Thanks for the patch, I have added the patch you supplied, and the program does not crash any more.

I have had to add few changes to the source code to get average.c to work.
Some of them may need to be added to the source tree files/documented

1) In average.c
changed

SYX_FUNC_PRIMITIVE(average)

to

__declspec(dllexport) SYX_FUNC_PRIMITIVE(average)

Without this, GetProcAddress cannot locate the function in the exe.


2) In syx-plugins.c function syx_library_open
changed

ret = LoadLibrary (SYX_IFDEF_UNICODE (location));

to

  if (location)
      ret = LoadLibrary (SYX_IFDEF_UNICODE (location));
  else
      ret=GetModuleHandle(NULL);

LoadLibrary cannot accept a NULL address

3) removed #define UNICODE in syx-config.h
This is highly likely to be specific to my settings.

Thanks again.
Faruque


2009/5/23 Luca Bruno <letha...@gmail.com>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkoXukEACgkQw9Qj+8Kak3GV2ACfUsnurv0pjrvyTg9H6wHw3cfp
caIAn11R5rl7Cw4zN5Uvm5w67P8bmvyg
=Ilsx
-----END PGP SIGNATURE-----


Luca Bruno

unread,
May 23, 2009, 1:26:01 PM5/23/09
to syx-d...@googlegroups.com
On Sat, May 23, 2009 at 04:07:46PM +0100, Gulam Faruque wrote:
> Hi
> Thanks for the patch, I have added the patch you supplied, and the program
> does not crash any more.
>
> I have had to add few changes to the source code to get average.c to work.
> Some of them may need to be added to the source tree files/documented
>
> 1) In average.c
> changed
>
> SYX_FUNC_PRIMITIVE(average)
>
> to
>
> __declspec(dllexport) SYX_FUNC_PRIMITIVE(average)

What if you instead use EXPORT in syx-interp.h:

#define SYX_FUNC_PRIMITIVE(name) \
EXPORT syx_bool \
name (SyxInterpState *es, SyxOop method)

Also try __declspec(dllexport) please.

>
> Without this, GetProcAddress cannot locate the function in the exe.
>
>
> 2) In syx-plugins.c function syx_library_open
> changed
>
> ret = LoadLibrary (SYX_IFDEF_UNICODE (location));
>
> to
>
> if (location)
> ret = LoadLibrary (SYX_IFDEF_UNICODE (location));
> else
> ret=GetModuleHandle(NULL);
>
> LoadLibrary cannot accept a NULL address
>
> 3) removed #define UNICODE in syx-config.h
> This is highly likely to be specific to my settings.
>

Thanks very much! I'll apply those for the next release.

signature.asc

Gulam Faruque

unread,
May 23, 2009, 5:44:04 PM5/23/09
to syx-d...@googlegroups.com
Both of your suggestions below for updating syx-interp.h fix work and fix the issue.

Thanks
Faruque

2009/5/23 Luca Bruno <letha...@gmail.com>
On Sat, May 23, 2009 at 04:07:46PM +0100, Gulam Faruque wrote:
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkoYMakACgkQw9Qj+8Kak3FF7QCeK+jMylav8jq/b05Xt0jeLKLz
QT4An1T/nc/n0GmcgayzidgDRvrGh+99
=Glhc
-----END PGP SIGNATURE-----


Luca Bruno

unread,
May 23, 2009, 6:04:56 PM5/23/09
to syx-d...@googlegroups.com
On Sat, May 23, 2009 at 10:44:04PM +0100, Gulam Faruque wrote:
> Both of your suggestions below for updating syx-interp.h fix work and fix
> the issue.

I think I'll opt for the EXPORT one then, committing the fixes.

Thanks for your contribution.

signature.asc
Reply all
Reply to author
Forward
0 new messages