Re: [Rd] Tcl socket server (tcltk) does not work any more on R 4.3.2

2024-02-20 Thread webmail.gandi.net
Thank you, Ivan for this investigation. I inspected the R changes file 
(https://cran.r-project.org/doc/manuals/r-devel/NEWS.html) and found nothing 
about this. I should inspect the sources too!

It could possibly break other Tcl/Tk related stuff. The doc about 
Tcl_ServiceAll and Tcl_DoOneEvent is confusing. On one hand, it says when Tcl 
is used from an external program, Tcl_ServiceAll should be used in its event 
loop instead of Tcl_DoOneEvent (and the change in the latest R versions goes in 
that direction). But in the other hand, it is indicated that Tcl_ServiceAll 
does not always handle all Tcl events and extra Tcl_DoOneEvent should be called 
in this case. I think we spotted one case where Tcl_ServiceAll is not doing its 
job correctly. There may be others.

Since the {tcltk} package was working fine with  "while 
(Tcl_DoOneEvent(TCL_DONT_WAIT) && max_ev) max_ev—;", unless there is a clear 
performance enhancement with "while (i-- && Tcl_ServiceAll())", it would 
perhaps be wise to revert this back.

Indeed, when I use this on the server side with R 4.3.2:

library(tcltk)
cmd <- r"(
 proc accept {chan addr port} { ;# Make a proc to accept connections
   puts "$addr:$port says [gets $chan]" ;# Receive a string
   puts $chan goodbye   ;# Send a string
   close $chan  ;# Close the socket (automatically 
flushes)
}   ;#
socket -server accept 12345 ;# Create a server socket)"
.Tcl(cmd)
.Tcl("vwait myvar")

It works again as expected. And vwait is known to call Tcl_DoOneEvent. Of 
course, in this case, R is blocked and waits for the `myvar` variable on the 
Tcl side. Anyway, the problem seems to be really in Tcl_ServiceAll not catching 
all Tcl events.

All the best,

Philippe

..<°}))><
 ) ) ) ) )
( ( ( ( (Prof. Philippe Grosjean
 ) ) ) ) )
( ( ( ( (Numerical Ecology
 ) ) ) ) )   Mons University, Belgium
( ( ( ( (
..

> Le 20 févr. 2024 à 17:13, Ivan Krylov via R-devel  a 
> écrit :
> 
> В Tue, 20 Feb 2024 12:27:35 +0100
> "webmail.gandi.net"  пишет:
> 
>> When R process #1 is R 4.2.3, it works as expected (whatever version
>> of R #2). When R process #1 is R 4.3.2, nothing is sent or received
>> through the socket apparently, but no error is issued and process #2
>> seems to be able to connect to the socket.
> 
> The difference is related to the change in
> src/library/tcltk/src/tcltk_unix.c.
> 
> In R-4.2.1, the function static void TclSpinLoop(void *data) says:
> 
>int max_ev = 100;
>/* Tcl_ServiceAll is not enough here, for reasons that escape me */
>while (Tcl_DoOneEvent(TCL_DONT_WAIT) && max_ev) max_ev--;
> 
> In R-devel, the function instead says:
> 
>int i = R_TCL_SPIN_MAX;
>while (i-- && Tcl_ServiceAll())
>;
> 
> Manually calling Tcl_DoOneEvent(0) from the debugger at this point
> makes the Tcl code respond to the connection. Tcl_ServiceAll() seems to
> be still not enough. I'll try reading Tcl documentation to investigate
> this further.
> 
> -- 
> Best regards,
> Ivan
> 
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel


[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] certain pipe() use cases not working in r-devel

2024-02-20 Thread Tomas Kalibera

On 2/18/24 00:23, Jennifer Bryan wrote:

I've now tested with:

> R.version.string
[1] "R Under development (unstable) (2024-02-16 r85931)"
and all of the previously mentioned examples now work as expected on 
macOS.


Thanks for the quick fix,


Thanks for the testing,
Tomas


Jenny

On Thu, Feb 15, 2024 at 8:02 AM Tomas Kalibera 
 wrote:



On 2/14/24 23:43, Jennifer Bryan wrote:
> Hello,
>
> I've noticed a specific type of pipe() usage that works in
released R, but
> not in r-devel.
>
> In 4.3.2 on macOS, I can write to a connection returned by
pipe(), i.e.
> "hello, world" prints here:
>
>> R.version.string
> [1] "R version 4.3.2 (2023-10-31)"
>> con <- pipe("cat")
>> writeLines("hello, world", con)
> hello, world
>
> But in r-devel on macOS, this is silent no-op, i.e. "hello,
world" does not
> print:
>
>> R.version.string
> [1] "R Under development (unstable) (2024-02-13 r85895)"
>> con <- pipe("cat")
>> writeLines("hello, world", con)
> My colleague Lionel Henry confirms he sees the same results on
linux.
> This particular example with cat doesn't work on Windows, so I
don't have
> any useful observations for that OS.
>
> You might say this is a weird example or use case. The actual
usage where I
> discovered this is the way folks read/write the clipboard on
macOS using
> pbcopy/pbpaste (and, in very similar ways, on linux using xsel
or xclip).
> This is mentioned in the "Clipboard" section of the connections
help topic.
>
> In 4.3.2 on macOS, I can successfully roundtrip with the clipboard:
>
>> pb_write <- pipe("pbcopy")
>> writeChar("hello clipboard!", pb_write, eos = NULL)
>> pb_read <- pipe("pbpaste")
>> readChar(pb_read, 16)
> [1] "hello clipboard!"
>
> In r-devel, it appears that the write operation silently does
nothing:
>
>> pb_write <- pipe("pbcopy")
>> writeChar("hello clipboard!", pb_write, eos = NULL)
>> pb_read <- pipe("pbpaste")
>> readChar(pb_read, 16)
> character(0)
>
> If the clipboard is populated through other means, I can
> use readChar(pipe("pbpaste"), ...) to read the clipboard even in
r-devel.
> So this seems to be specific to writing to the connection.
>
> Is this change in behaviour intentional and will it be present
in the next
> release of R? FWIW, I did a crude search of the source of all
CRAN packages
> and there are quite a few currently using pipe() for clipboard
access on
> *nix.

This should be fixed now in R-devel. Thanks for the report and
thanks to
Ivan for the debugging. It would be great if you could test on
your end
with different examples and report any other issues.

Thanks
Tomas

>
> -- Jenny
>
>       [[alternative HTML version deleted]]
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Tcl socket server (tcltk) does not work any more on R 4.3.2

2024-02-20 Thread Ivan Krylov via R-devel
В Tue, 20 Feb 2024 12:27:35 +0100
"webmail.gandi.net"  пишет:

> When R process #1 is R 4.2.3, it works as expected (whatever version
> of R #2). When R process #1 is R 4.3.2, nothing is sent or received
> through the socket apparently, but no error is issued and process #2
> seems to be able to connect to the socket.

The difference is related to the change in
src/library/tcltk/src/tcltk_unix.c.

In R-4.2.1, the function static void TclSpinLoop(void *data) says:

int max_ev = 100;
/* Tcl_ServiceAll is not enough here, for reasons that escape me */
while (Tcl_DoOneEvent(TCL_DONT_WAIT) && max_ev) max_ev--;

In R-devel, the function instead says:

int i = R_TCL_SPIN_MAX; 
while (i-- && Tcl_ServiceAll())
;

Manually calling Tcl_DoOneEvent(0) from the debugger at this point
makes the Tcl code respond to the connection. Tcl_ServiceAll() seems to
be still not enough. I'll try reading Tcl documentation to investigate
this further.

-- 
Best regards,
Ivan

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Bug in comparison of language objects?

2024-02-20 Thread Duncan Murdoch

On 20/02/2024 8:03 a.m., Duncan Murdoch wrote:

I noticed the following odd behaviour today:

exprs <- expression( mean(a), mean(b), { a }, { b } )

exprs[[1]] == exprs[[2]]
#> [1] FALSE

exprs[[3]] == exprs[[4]]
#> [1] TRUE

Does it make sense to anyone that the argument passed to `mean` matters,
but the expression contained in braces doesn't?


I have done some debugging, and found the cause:  for the comparison of 
language objects, R deparses them to strings using C function 
deparse1(), and looks at only the first line.  "mean(a)" deparses as is, 
but "{ a }" deparses to 3 lines


{
  a
}

and the first line is the same as for "{ b }", so they compare equal.

I think it would make more sense to deparse them to one long string, and 
compare those, i.e. to replace deparse1() with deparse1line() (which may 
have been the intention).


Duncan Murdoch

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Compiling libR as a standalone C library for java+jni (-fPIC)

2024-02-20 Thread Dirk Eddelbuettel


Salut Pierre,

On 20 February 2024 at 10:33, Pierre Lindenbaum wrote:
| (cross-posted on SO: https://stackoverflow.com/questions/78022766)
| 
| Hi all,
| 
| I'm trying to compile R as a static library with the -fPIC flag so I can use 
it within java+JNI (is it only possible ?), but I cannot find the right flags 
in '.configure' to compile R this way.
| 
| I tested various flags but I cannot find the correct syntax.
| 
| for now, my latest attempt was
| 
| ```
| rm -rvf  "TMP/R-4.3.2" TMP/tmp.tar.gz
| mkdir -p TMP/R-4.3.2/lib/
| wget -O TMP/tmp.tar.gz 
"https://pbil.univ-lyon1.fr/CRAN/src/base/R-4/R-4.3.2.tar.gz;
| cd TMP && tar xfz tmp.tar.gz && rm tmp.tar.gz &&  cd R-4.3.2 && \
|      CPICFLAGS=fpic FPICFLAGS=fpic CXXPICFLAGS=fpic SHLIB_LDFLAGS=shared  
SHLIB_CXXLDFLAGS=shared  ./configure --enable-R-static-lib 
--prefix=/path/to/TMP --with-x=no --disable-BLAS-shlib && make
| 
| ```

Looks like you consistenly dropped the '-' from '-fPIC'.

FWIW the Debian (and hence Ubuntu and other derivatives) binaries contain a
libR you can embed. And littler and RInside have done so for maybe 15 years.

Cannot help with JNI but note that the history of the headless (and generally
excellent) Rserve (and its clients) started on Java. Might be worth a try.

Good luck, Dirk

| witch gives the following error during configure:
| 
| 
| ```
| configure: WARNING: you cannot build info or HTML versions of the R manuals
| configure: WARNING: you cannot build PDF versions of the R manuals
| configure: WARNING: you cannot build PDF versions of vignettes and help pages
| make[1]: Entering directory 'R-4.3.2'
| configure.ac:278: error: possibly undefined macro: AM_CONDITIONAL
|    If this token and others are legitimate, please use m4_pattern_allow.
|    See the Autoconf documentation.
| configure.ac:870: error: possibly undefined macro: AC_DISABLE_STATIC
| configure.ac:2226: error: possibly undefined macro: AM_LANGINFO_CODESET
| configure.ac:2876: error: possibly undefined macro: AM_NLS
| configure.ac:2880: error: possibly undefined macro: AM_GNU_GETTEXT_VERSION
| configure.ac:2881: error: possibly undefined macro: AM_GNU_GETTEXT
| make[1]: *** [Makefile:49: configure] Error 1
| 
| ```
| removing the XXXFLAGS=YYY and --prefix (?) allows R to be compiled but It's 
not loaded into java.
| 
| ```
| gcc  -ITMP -I${JAVA_HOME}/include/ -I${JAVA_HOME}/include/linux \
|      -LTMP/R-4.3.2/lib `TMP/R-4.3.2/bin/R CMD config --cppflags` -shared 
-fPIC -o TMP/libRSession.so  -g RSession.c TMP/R-4.3.2/lib/libR.a
| /usr/bin/ld: TMP/R-4.3.2/lib/libR.a(objects.o): warning: relocation against 
`R_dot_Method' in read-only section `.text'
| /usr/bin/ld: TMP/R-4.3.2/lib/libR.a(altrep.o): relocation R_X86_64_PC32 
against symbol `R_NilValue' can not be used when making a shared object; 
recompile with -fPIC
| /usr/bin/ld: final link failed: bad value
| ```
| 
| Any idea ? Thanks
| 
| Pierre
| 
| __
| R-devel@r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Bug in comparison of language objects?

2024-02-20 Thread Duncan Murdoch

I noticed the following odd behaviour today:

  exprs <- expression( mean(a), mean(b), { a }, { b } )

  exprs[[1]] == exprs[[2]]
  #> [1] FALSE

  exprs[[3]] == exprs[[4]]
  #> [1] TRUE

Does it make sense to anyone that the argument passed to `mean` matters, 
but the expression contained in braces doesn't?


Duncan Murdoch

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Compiling libR as a standalone C library for java+jni (-fPIC)

2024-02-20 Thread Pierre Lindenbaum

(cross-posted on SO: https://stackoverflow.com/questions/78022766)

Hi all,

I'm trying to compile R as a static library with the -fPIC flag so I can use it 
within java+JNI (is it only possible ?), but I cannot find the right flags in 
'.configure' to compile R this way.

I tested various flags but I cannot find the correct syntax.

for now, my latest attempt was

```
rm -rvf  "TMP/R-4.3.2" TMP/tmp.tar.gz
mkdir -p TMP/R-4.3.2/lib/
wget -O TMP/tmp.tar.gz 
"https://pbil.univ-lyon1.fr/CRAN/src/base/R-4/R-4.3.2.tar.gz;
cd TMP && tar xfz tmp.tar.gz && rm tmp.tar.gz &&  cd R-4.3.2 && \
    CPICFLAGS=fpic FPICFLAGS=fpic CXXPICFLAGS=fpic SHLIB_LDFLAGS=shared  
SHLIB_CXXLDFLAGS=shared  ./configure --enable-R-static-lib --prefix=/path/to/TMP 
--with-x=no --disable-BLAS-shlib && make

```

witch gives the following error during configure:


```
configure: WARNING: you cannot build info or HTML versions of the R manuals
configure: WARNING: you cannot build PDF versions of the R manuals
configure: WARNING: you cannot build PDF versions of vignettes and help pages
make[1]: Entering directory 'R-4.3.2'
configure.ac:278: error: possibly undefined macro: AM_CONDITIONAL
  If this token and others are legitimate, please use m4_pattern_allow.
  See the Autoconf documentation.
configure.ac:870: error: possibly undefined macro: AC_DISABLE_STATIC
configure.ac:2226: error: possibly undefined macro: AM_LANGINFO_CODESET
configure.ac:2876: error: possibly undefined macro: AM_NLS
configure.ac:2880: error: possibly undefined macro: AM_GNU_GETTEXT_VERSION
configure.ac:2881: error: possibly undefined macro: AM_GNU_GETTEXT
make[1]: *** [Makefile:49: configure] Error 1

```
removing the XXXFLAGS=YYY and --prefix (?) allows R to be compiled but It's not 
loaded into java.

```
gcc  -ITMP -I${JAVA_HOME}/include/ -I${JAVA_HOME}/include/linux \
    -LTMP/R-4.3.2/lib `TMP/R-4.3.2/bin/R CMD config --cppflags` -shared -fPIC 
-o TMP/libRSession.so  -g RSession.c TMP/R-4.3.2/lib/libR.a
/usr/bin/ld: TMP/R-4.3.2/lib/libR.a(objects.o): warning: relocation against 
`R_dot_Method' in read-only section `.text'
/usr/bin/ld: TMP/R-4.3.2/lib/libR.a(altrep.o): relocation R_X86_64_PC32 against 
symbol `R_NilValue' can not be used when making a shared object; recompile with 
-fPIC
/usr/bin/ld: final link failed: bad value
```

Any idea ? Thanks

Pierre

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Tcl socket server (tcltk) does not work any more on R 4.3.2

2024-02-20 Thread Dirk Eddelbuettel


On 20 February 2024 at 12:27, webmail.gandi.net wrote:
| Dear list,
| 
| It seems that something changed between R 4.2.3 and R 4.3 (tested with 4.3.2) 
that broke the Tcl socket server. Here is a reproducible example:
| 
| - R process #1 (Tcl socket server):
| 
| library(tcltk)
| cmd <- r"(
|  proc accept {chan addr port} { ;# Make a proc to accept connections
|puts "$addr:$port says [gets $chan]" ;# Receive a string
|puts $chan goodbye   ;# Send a string
|close $chan  ;# Close the socket (automatically 
flushes)
| }   ;#
| socket -server accept 12345 ;# Create a server socket)"
| .Tcl(cmd)
| 
| - R process #2 (socket client):
| 
| con <- socketConnection(host = "localhost", port = 12345, blocking = FALSE)
| writeLines("Hello, world!", con) # Should print something in R #1 stdout
| readLines(con) # Should receive "goodbye"
| close(con)
| 
| When R process #1 is R 4.2.3, it works as expected (whatever version of R 
#2). When R process #1 is R 4.3.2, nothing is sent or received through the 
socket apparently, but no error is issued and process #2 seems to be able to 
connect to the socket.
| 
| I am stuck with this. Thanks in advance for help.

>From a quick check this issue seems to persist in the (current) R-devel
2024-02-20 r85951 too.

Dirk

| Regards,
| 
| Philippe
| 
| > .Tcl("puts [info patchlevel]")
| 8.6.13
|   
| 
| > sessionInfo()
| R version 4.3.2 (2023-10-31)
| Platform: aarch64-apple-darwin20 (64-bit)
| Running under: macOS Sonoma 14.2.1
| 
| Matrix products: default
| BLAS:   
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
 
| LAPACK: 
/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;
  LAPACK version 3.11.0
| 
| locale:
| [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
| 
| time zone: Europe/Brussels
| tzcode source: internal
| 
| attached base packages:
| [1] tcltk stats graphics  grDevices utils datasets  methods   
base 
| 
| loaded via a namespace (and not attached):
| [1] compiler_4.3.2 tools_4.3.2glue_1.7.0  
| __
| R-devel@r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Tcl socket server (tcltk) does not work any more on R 4.3.2

2024-02-20 Thread webmail.gandi.net
Dear list,

It seems that something changed between R 4.2.3 and R 4.3 (tested with 4.3.2) 
that broke the Tcl socket server. Here is a reproducible example:

- R process #1 (Tcl socket server):

library(tcltk)
cmd <- r"(
 proc accept {chan addr port} { ;# Make a proc to accept connections
   puts "$addr:$port says [gets $chan]" ;# Receive a string
   puts $chan goodbye   ;# Send a string
   close $chan  ;# Close the socket (automatically 
flushes)
}   ;#
socket -server accept 12345 ;# Create a server socket)"
.Tcl(cmd)

- R process #2 (socket client):

con <- socketConnection(host = "localhost", port = 12345, blocking = FALSE)
writeLines("Hello, world!", con) # Should print something in R #1 stdout
readLines(con) # Should receive "goodbye"
close(con)

When R process #1 is R 4.2.3, it works as expected (whatever version of R #2). 
When R process #1 is R 4.3.2, nothing is sent or received through the socket 
apparently, but no error is issued and process #2 seems to be able to connect 
to the socket.

I am stuck with this. Thanks in advance for help.

Regards,

Philippe

> .Tcl("puts [info patchlevel]")
8.6.13
  

> sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.2.1

Matrix products: default
BLAS:   
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
 
LAPACK: 
/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;
  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Brussels
tzcode source: internal

attached base packages:
[1] tcltk stats graphics  grDevices utils datasets  methods   base  
   

loaded via a namespace (and not attached):
[1] compiler_4.3.2 tools_4.3.2glue_1.7.0  
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel