× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



You're right Scott - I had forgotten that this function was not returning the repose but modifying the parm. However, now I'm really confused because the OP said that the change to *String fixed his problem.

More to the point - if his code was correct (other than not using %Str) then what would have been the cause of the original error?

I notice that you coded for the fourth parameter. I wonder if the OP is mistaken and he really does need that fourth one?

Very odd.


On May 22, 2020, at 2:53 PM, Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx> wrote:

Hello,

Based on the code that you point us to on GitHub, you should not need to null-terminate the first parameter ("PW_BUF" in your prototype.) You also should not define options(*String).

What options(*string) does is make a copy of your input parameter with x'00' appended. This isn't right in this case because you want to use the PW_BUF parameter for output, and if the C code changes a copy of your string, you'll never see the output.

If you look at how the code accesses 'buf' (the name the C code uses for your PW_BUF is 'buf'). It does not expect it to have a null at the end, it merely replaces its contents, and it will manually add the x'00' at the end.

So what you're doing here is correct -- except that you will need to call %STR afterwards to remove the null from the result. For example:

Dresult s 64a varying
.
.
C MOVE 64 PW_SIZE
C MOVE 3 PW_FLAGS
C CALLP PW_RAND ( PW_BUF: PW_SIZE: PW_FLAGS: *null )
C
C eval result = %str(%addr(PW_BUF))

The %STR simply makes a copy of the data up to the x'00' in PW_BUF, and puts the copy in "result" in my example.

Good luck


On 5/22/2020 4:34 AM, Patrik Schindler wrote:
Hello,

I've ported https://github.com/tytso/pwgen to the CL environment (not PASE!), for easy generation of random characters. and calling the resulting *PGM runs fine.

There's one function (pw_rand) I want to call from RPG, by linking (binding) all (necessary) *MODULE objects from pwgen together with the RPGLE module containing the mainline to one *PGM. I'm *not* talking about a service program.

The C prototype is: void pw_rand(char *buf, int size, int pw_flags);

What I expect it to do: I pass a struct predetermined by the existing C code, stating I want to create a 64 char password with the password flags 3. The password buffer is apparently preallocated by RPG (see debug output below), since it's filled with *BLANKs. The function runs and places a (most likely zero-teminated) string into the buffer: 64 bytes password, 1 byte '00'X. I made the buffer a bit larger to be on the safe side. I also looked up proper field sizes in IBM documentation and that seems correct.

That's what I did in positional RPG:

DPW_BUF S 70A
DPW_SIZE S 10I 0
DPW_FLAGS S 10I 0
*
DPW_RAND PR EXTPROC('pw_rand')
D PW_BUF 70A
D PW_SIZE 10I 0 VALUE
D PW_FLAGS 10I 0 VALUE
*----------------
C MOVE 64 PW_SIZE
C MOVE 3 PW_FLAGS
C CALLP PW_RAND ( PW_BUF : PW_SIZE : PW_FLAGS )

( I hope, my MUA will not mess up with the formatting.)

Compiles and links fine, but when I try to run the call, the application crashes with MCH 3601 (Pointer not set for location referenced.). I read some articles in the net about it but I can't find out where or what I do wrong.

Debug:

PW_BUF CHAR(70) ' '
VALUE IN HEX '40404040404040404040404040404040404040404040404040404040404040404040404040404040'X
41 '404040404040404040404040404040404040404040404040404040404040'X
PW_FLAGS ZONED(1,0) 3. 'F3'X
PW_SIZE ZONED(2,0) 64. 'F6F4'X

Help greatly appreciated! Please refrain from "do it with RPG free", because I don't want to open yet another task on my already big stack. (Learning free is on my list, for a later point in time.)

:wq! PoC

PGP-Key: DDD3 4ABF 6413 38DE - https://www.pocnet.net/poc-key.asc

--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link: https://amazon.midrange.com


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.