Problem with concating of multiple wide string in wcout - unnecessary space after each charcater
Radosław Smogura
mail at smogura.eu
Tue Dec 14 16:36:10 UTC 2021
Hi,
Can it be released to terminal? Maybe your terminal does not accept wide chars and the space is 0x00? I wonder if you could copy paste output form terminal to some file and check hex content, or forward output to text file and check hex?
BR,
Rado
> On Dec 14, 2021, at 5:22 PM, Jorn Vernee <jorn.vernee at oracle.com> wrote:
>
> (Sending my earlier reply to panama-dev as well)
>
> Hi Ladislav,
>
> I'm also not able to reproduce the issue. Can we try a simpler example first?
>
> I have a lib.cpp file like so:
>
> #include <iostream>
>
> extern "C"
> __declspec(dllexport)
> void print() {
> std::wcout << "Testing wcout" << std::endl;
> }
>
> A CMakeLists.txt to compile it:
>
> cmake_minimum_required(VERSION 3.14)
> project(TestingWCout)
>
> add_library(Lib SHARED lib.cpp)
>
> install(TARGETS Lib)
>
> And a file Test.java like so:
>
> import jdk.incubator.foreign.*;
> import java.lang.invoke.*;
>
> public class Test {
> public static void main(String[] args) throws Throwable {
> System.loadLibrary("Lib");
> MemoryAddress sym = SymbolLookup.loaderLookup().lookup("print").get();
> MethodHandle mh = CLinker.getInstance().downcallHandle(sym, MethodType.methodType(void.class), FunctionDescriptor.ofVoid());
> mh.invokeExact();
> }
> }
>
> And, using the panama snapshot:
>
> > java --version
> openjdk 17-panama 2021-09-14
> OpenJDK Runtime Environment (build 17-panama+3-167)
> OpenJDK 64-Bit Server VM (build 17-panama+3-167, mixed mode, sharing)
>
> Build and run it with (I've used powershell here):
>
> $ cmake -B build -S . '-DCMAKE_INSTALL_PREFIX=install' -T host=x64 -A x64
> $ cmake --build build --config Release --target install
> $ java --add-modules jdk.incubator.foreign --enable-native-access=ALL-UNNAMED '-Djava.library.path=./install/bin' Test.java
>
> This ends up printing:
>
> WARNING: Using incubator modules: jdk.incubator.foreign
> warning: using incubating module(s): jdk.incubator.foreign
> 1 warning
> Testing wcout
>
> Could you try and see if that works? I've also uploaded the files here: http://cr.openjdk.java.net/~jvernee/wcout/
>
> Thanks,
> Jorn
>
>
>> On 14/12/2021 12:47, Ladislav Török wrote:
>> Here is copy of my conversation with Maurizio Cimadamore:
>> 1. email by me:
>> Hi,
>>
>> use the example panama-tutorial-005 on
>> https://github.com/tornaia/panama-tutorial.
>> I am checked and result in my console on Windows (CMD) is:
>> ---
>> D:\repositories\moje\GitHub\tornaia\panama-tutorial\panama-tutorial-005>java
>> --enable-preview --add-modules jdk.incubator.foreign
>> --enable-native-access=ALL-UNNAMED
>> -Djava.library.path=lib/helloworldwinrt/target -classpath
>> target/classes;lib/target/jar/*
>> com.github.tornaia.panama.tutorial005.Tutorial005
>> WARNING: Using incubator modules: jdk.incubator.foreign
>> Start
>> N u m b e r o f d e v i c e s : 2 5 9 5
>> End
>>
>> D:\repositories\moje\GitHub\tornaia\panama-tutorial\panama-tutorial-005>
>> ---
>> See space after each character of started in place where is used concating
>> of multiple wide string in wcout.
>> !!! Build the sample is in Microsoft Visual Studio 2019, configuration is
>> Release x64 !!! For configuration Debug x64 is all ok.
>> Output is:
>> ---
>> D:\repositories\moje\GitHub\tornaia\panama-tutorial\panama-tutorial-005>java
>> --enable-preview --add-modules jdk.incubator.foreign
>> --enable-native-access=ALL-UNNAMED
>> -Djava.library.path=lib/helloworldwinrt/target -classpath
>> target/classes;lib/target/jar/*
>> com.github.tornaia.panama.tutorial005.Tutorial005
>> WARNING: Using incubator modules: jdk.incubator.foreign
>> Start
>> Number of devices: 2595
>> End
>>
>> D:\repositories\moje\GitHub\tornaia\panama-tutorial\panama-tutorial-005>
>> ---
>>
>> Thanks.
>>
>> 2. email by Maurizio Cimadamore (his answer on my 1. email by me):
>>
>> Adding Jorn, who might know more.
>>
>> One control question first: have you tried calling your C++ code directly
>> (e.g. w/o Panama, using a `main`) ? I have a feeling that you might get the
>> same behavior there. I note that your CPP library is not really returning a
>> string back to Java, but it's doing a `cout` to print things on the
>> terminal console. It's unlikely that Panama will have any effect here.
>>
>> (in general, please use mailing list :-)).
>>
>> Thanks
>> Maurizio
>>
>> *** Here is my reaction on previous 2. email by Maurizio Cimadamore ***
>> I was try of calling my C++ code directly (without Panama, using a 'main')
>> in other application - building of this application in Microsoft Visual
>> Studio 2019, configuration1 Release x64 and configuration2 Debug x64 and is
>> all ok (in both cases):
>> --- Debug ---
>> Microsoft Windows [Version 10.0.19043.1348]
>> (c) Microsoft Corporation. All rights reserved.
>>
>> D:\MSVS2019\Projects\Project2\x64\Debug>Project2.exe
>> Number of devices: 2595
>> Result: 0
>>
>> D:\MSVS2019\Projects\Project2\x64\Debug>
>> --- Debug ---
>>
>> --- Release ---
>> Microsoft Windows [Version 10.0.19043.1348]
>> (c) Microsoft Corporation. All rights reserved.
>>
>> D:\MSVS2019\Projects\Project2\x64\Release>Project2.exe
>> Number of devices: 2595
>> Result: 0
>>
>> D:\MSVS2019\Projects\Project2\x64\Release>
>> --- Release ---
>>
>> Code of my client application:
>> #include "helloworldwinrt.h"
>> #include <stdio.h>
>>
>> int main()
>> {
>> int result = print_number_of_devices();
>> printf("Result: %d\n", result);
>> }
>>
>> "I note that your CPP library is not really returning a string back to
>> Java, but it's doing a `cout` to print things on the terminal console." ---
>> Yes.
>>
>> " It's unlikely that Panama will have any effect here." --- It doesn't look
>> like that yet. Could someone practically try it?
>>
>> Thanks
>> Ladislav
More information about the panama-dev
mailing list