external library passing pointer to bytes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

external library passing pointer to bytes

Eric Winger-5
I'm having trouble with an external library call. I keep getting the
error message below.

Here's my primitive:

compress: destBuffer with: destSize with: sourceBuffer with: sourceSize
       
        " int compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong
sourceLen)"

        <cdecl: dword compress byte* dword* byte dword>
        ^self invalidCall

and here's a test call which fails:

ZLibLibrary default compress: (ByteArray new: 30)  with: 30 with: 'hi
there' asByteArray with: 8

I'm not really expecting anyone to solve this one for me (unless they've
worked with zlib from dolphin before), but I thought someone who is more
experienced in dll calls from dolphin (in particular byte pointers)
could at least tell me if I've set up my primitive correctly & am
passing the right types of arguments.

Note - that the bytef* is a pointer to a byte with the old FAR keyword.
So I thought I would be safe passing a ByteArray with a byte* type.

thx much for any help...

Eric






9:07:20 AM, Sunday, March 10, 2002: 'Invalid access to memory location.
Reading 0xFFFFFFFF, IP 0x1DD129B (C:\PROGRAM FILES\DOLPHIN SMALLTALK
4.0\ZLIB.DLL)'
ProcessorScheduler>>gpFault:
[] in ProcessorScheduler>>vmi:list:no:with:
BlockClosure>>ifCurtailed:
ProcessorScheduler>>vmi:list:no:with:
SmallInteger(Object)>>doesNotUnderstand:
SmallInteger(ZLibLibrary)>>compress:with:with:with:
UndefinedObject>>{unbound}doIt
CompiledExpression>>value:
SmalltalkWorkspace>>evaluateRange:ifFail:debug:
SmalltalkWorkspace>>evaluateItIfFail:debug:
SmalltalkWorkspace>>evaluateItIfFail:
SmalltalkWorkspace>>evaluateIt
Symbol>>forwardTo:
[] in Command>>value
BlockClosure>>ifCurtailed:
BlockClosure>>ensure:
Command>>value
SmalltalkWorkspaceDocument(Shell)>>performCommand:
CommandQuery>>perform
DelegatingCommandPolicy(CommandPolicy)>>route:
[] in RichTextEdit(View)>>onCommand:
BlockClosure>>ifCurtailed:
BlockClosure>>ensure:
Cursor>>showWhile:
RichTextEdit(View)>>onCommand:
RichTextEdit(View)>>wmCommand:wParam:lParam:
RichTextEdit(View)>>dispatchMessage:wParam:lParam:
[] in InputState>>wndProc:message:wParam:lParam:cookie:
BlockClosure>>ifCurtailed:
ProcessorScheduler>>callback:evaluate:
InputState>>wndProc:message:wParam:lParam:cookie:
InputState>>pumpMessage:
InputState>>loopWhile:
InputState>>mainLoop
[] in InputState>>forkMain
ExceptionHandler(ExceptionHandlerAbstract)>>markAndTry
[] in ExceptionHandler(ExceptionHandlerAbstract)>>try:
BlockClosure>>ifCurtailed:
BlockClosure>>ensure:
ExceptionHandler(ExceptionHandlerAbstract)>>try:
BlockClosure>>on:do:
[] in BlockClosure>>newProcess


Reply | Threaded
Open this post in threaded view
|

Re: external library passing pointer to bytes

Stefan Schmiedl
On Sun, 10 Mar 2002 09:18:14 -0800,
Eric Winger <[hidden email]> wrote:

> Here's my primitive:
>
> compress: destBuffer with: destSize with: sourceBuffer with: sourceSize
>
> " int compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong
> sourceLen)"
>
> <cdecl: dword compress byte* dword* byte dword>
> ^self invalidCall
>
> and here's a test call which fails:
>
> ZLibLibrary default compress: (ByteArray new: 30)  with: 30 with: 'hi
> there' asByteArray with: 8
>

Hi Eric,

why do you have "byte*" for "Bytef *dest",
but "byte" for "Bytef *source"?

OT: Which compression algorithm is used in ZLibLibrary?

s.


Reply | Threaded
Open this post in threaded view
|

Re: external library passing pointer to bytes

Eric Winger-5
Stefan Schmiedl wrote:

> On Sun, 10 Mar 2002 09:18:14 -0800,
> Eric Winger <[hidden email]> wrote:
>
>>Here's my primitive:
>>
>>compress: destBuffer with: destSize with: sourceBuffer with: sourceSize
>>
>> " int compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong
>>sourceLen)"
>>
>> <cdecl: dword compress byte* dword* byte dword>
>> ^self invalidCall
>>
>>and here's a test call which fails:
>>
>>ZLibLibrary default compress: (ByteArray new: 30)  with: 30 with: 'hi
>>there' asByteArray with: 8
>>
>>
>
> Hi Eric,
>
> why do you have "byte*" for "Bytef *dest",
> but "byte" for "Bytef *source"?


That would probably just be a typo when I made the comment.

In looking back, I probably should have commented an "exact" copy of the
function prototype. I quote "exact" because it uses some funky macros
and I'm guessing a little. Herein may be the problem.

extern int __declspec(dllexport) compress args(Bytef *dest, uLongf
*destLen, const Bytef *source, uLong sourceLen);


 >
 > OT: Which compression algorithm is used in ZLibLibrary?


If you mean which .dll I am interfacing with, I just got a copy of a
win32 version of zlib (zlib.dll) from the zlib home page.
http://www.gzip.org/zlib/

The only other thing I thought I had to do in my ExternalInterface
subclass was to make a fileName class method

fileName
        ^'ZLIB'

...

Also, when I inspect the input vars to my primitive, I see some really
funky values:

destBuffer- 91619830
destSize - a CompiledExpression
sourceBuffer - 91619830
sourceSize - a ZLibLibrary(16r8B90000 - 'C:\PROGRAM FILES\DOLPHIN
SMALLTALK 4.0\ZLIB.DLL')

I thought at first glance that these might be the munged parameters that
Dolphin actually sends down to the external library. But the
compiledExpression & instance of zlibrary really threw me.  Any ideas?

thx

Eric


Reply | Threaded
Open this post in threaded view
|

Re: external library passing pointer to bytes

Blair McGlashan
"Eric Winger" <[hidden email]> wrote in message
news:[hidden email]...

> ...
> Also, when I inspect the input vars to my primitive, I see some really
> funky values:
>
> destBuffer- 91619830
> destSize - a CompiledExpression
> sourceBuffer - 91619830
> sourceSize - a ZLibLibrary(16r8B90000 - 'C:\PROGRAM FILES\DOLPHIN
> SMALLTALK 4.0\ZLIB.DLL')
>
> I thought at first glance that these might be the munged parameters that
> Dolphin actually sends down to the external library. But the
> compiledExpression & instance of zlibrary really threw me.  Any ideas?

Are you sure that the lib has been compiled using the cdecl calling
convention? The most common cause of stack corruption like this is using the
wrong number or size of arguments or getting the calling convention wrong.

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: external library passing pointer to bytes

Bill Schwab-2
In reply to this post by Eric Winger-5
Eric,

> I'm not really expecting anyone to solve this one for me (unless they've
> worked with zlib from dolphin before)

There are a few ZLib wrappers.  Mine is available here:

  http://needle.anest.ufl.edu/anest4/bills/Smalltalk.htm

and I think there might even be one that allows streaming - a search of the
archives might turn it up.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: external library passing pointer to bytes

Eric Winger-4
Ugh... Eric learn not reinvent wheel anymore.

This works just fine for my needs. Thx much.

Eric

Bill Schwab wrote:

> Eric,
>
>
>>I'm not really expecting anyone to solve this one for me (unless they've
>>worked with zlib from dolphin before)
>>
>
> There are a few ZLib wrappers.  Mine is available here:
>
>   http://needle.anest.ufl.edu/anest4/bills/Smalltalk.htm
>
> and I think there might even be one that allows streaming - a search of the
> archives might turn it up.
>
> Have a good one,
>
> Bill
>
> --
> Wilhelm K. Schwab, Ph.D.
> [hidden email]
>
>
>
>