Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with UDF in Windows platform (FB2) [CORE1222] #1646

Closed
firebird-automations opened this issue Apr 21, 2007 · 8 comments
Closed

Issue with UDF in Windows platform (FB2) [CORE1222] #1646

firebird-automations opened this issue Apr 21, 2007 · 8 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Marco Castro (mcastro)

Attachments:
mcudflib.dll

Hello,

I had some UDFs that runs in FB1.5. I'm trying to recompile them to FB2.0 in Windows platform. I'm using Microsoft Visual Studio and compiled with the fbclient_ms.lib library. The DLL was compiled fine, but FireBird does not recognize it correctly with field data. A query like Select mcUpper('test') from rdb$database works. A query like Select mcUpper(User) from Users raises the error described below.

The function call is:

char* EXPORT fn_upper_c (unsigned char* s)
ARGLIST(unsigned char* s)
{

The error in log is:

MARCO_NB (Server) Fri Mar 16 15:48:50 2007
The user defined function: MCUPPER
referencing entrypoint: fn_upper_c
in module: mcudflib
caused the fatal exception: Access violation.
The code attempted to access a virtual
address without privilege to do so.
This exception will cause the Firebird server
to terminate abnormally.

Any help will be nice.

Thanks,

Marco Castro

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

Please show how you declare this function in a database. A complete function body would also be useful.

@firebird-automations
Copy link
Collaborator Author

Commented by: Marco Castro (mcastro)

Dimitry,

One of the problem functions is. I belive that the problem is with functions that are related to strings.

char* EXPORT fn_upper_c (char* s)
{
char *buf;
char *buffer = (char *)MALLOC(strlen(s)+1);
// char *buffer = (char *)MALLOC(512);
char AccentOff[] = {'\0', '\x1', '\x2', '\x3', '\x4', '\x5', '\x6', '\x7', // x0
'\x8', '\x9', '\xa', '\xb', '\xc', '\xd', '\xe', '\xf', // x8
'\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', // x10
'\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', // x18
' ', '!', '"', '#⁠', '$', '%', '&', '\'', // x20
'(', ')', '*', '+', ',', '-', '.', '/', // x28
'0', '1', '2', '3', '4', '5', '6', '7', // x30
'8', '9', ':', ';', '<', '=', '>', '?', // x38
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', // x40
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', // x48
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', // x50
'X', 'Y', 'Z', '[', '\\', ']', '^', '_', // x58
'`', 'A', 'B', 'C', 'D', 'E', 'F', 'G', // x60
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', // x68
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', // x70
'X', 'Y', 'Z', '{', '|', '}', '~', '\x7f', // x78
'E', '\x81', '?', '?', '?', '...', '?', '?', // x80
'?', '?', 'S', '?', '?', '\x8d', 'Z', '\x8f', // x88
'\x90', ''', ''', '"', '"', '?', '-', '?', // x90
'?', '?', 'S', '?', '?', '\x9d', 'Z', 'Y', // x98
'?', '!', '?', '?', '?', '?', '?', '?', // xa0
'?', '?', 'a', '?', '?', '?', '?', '?', // xa8
'?', '?', '?', '?', '\'', '?', '?', '- ', // xb0
'?', '?', 'o', '?', '?', '?', '?', '?', // xb8
'A', 'A', 'A', 'A', 'A', 'A', 'A', 'C', // xc0
'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', // xc8
'D', 'N', 'O', 'O', 'O', 'O', 'O', '?', // xd0
'?', 'U', 'U', 'U', 'U', 'Y', '?', '?', // xd8
'A', 'A', 'A', 'A', 'A', 'A', 'A', 'C', // xe0
'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', // xe8
'O', 'N', 'O', 'O', 'O', 'O', 'O', '?', // xf0
'?', 'U', 'U', 'U', 'U', 'Y', '?', 'Y'}; // xf8
short length = 0;

buf = buffer;
length = \(short\)\*s;
s \+= 2;
while \(\*s\)
	\*buf\+\+ = AccentOff\[\*s\+\+\];

\*buf = '\\0';
buffer\[length\] = '\\0';

return buffer;

}

In the database is

DECLARE EXTERNAL FUNCTION MCUPPER
VARCHAR(256) CHARACTER SET WIN1252
RETURNS CSTRING(256) CHARACTER SET WIN1252 FREE_IT
ENTRY_POINT 'fn_upper_c' MODULE_NAME 'mcudflib';

Thanks,

Marco Castro

@firebird-automations
Copy link
Collaborator Author

Commented by: Marco Castro (mcastro)

This is the UDF definitions where you can simulate the problem there, It works with any table with string data,

@firebird-automations
Copy link
Collaborator Author

Modified by: Marco Castro (mcastro)

Attachment: mcudflib.dll [ 10340 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

Your code is bug.
You should use ib_util_malloc from ib_util.dll to alloc memory returned by functions using FREE_IT.

@firebird-automations
Copy link
Collaborator Author

Modified by: @asfernandes

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Won't Fix [ 2 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

Workflow: jira [ 11912 ] => Firebird [ 15119 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant