From 92c7cd98a2222fc15cb6dc74c6f9d85f27742aff Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 24 Feb 2009 17:01:59 +0000 Subject: [PATCH] Make ca_put use best_type for both single-valued and array PVs. --- src/cap5/CA.pm | 10 ++++------ src/cap5/Cap5.xs | 32 ++++++++++++++++---------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/cap5/CA.pm b/src/cap5/CA.pm index 993af54fe..f8aef89a3 100644 --- a/src/cap5/CA.pm +++ b/src/cap5/CA.pm @@ -4,7 +4,7 @@ use strict; use warnings; -my $version = '0.2'; +my $version = '0.3'; exists $ENV{EPICS_HOST_ARCH} or die "EPICS_HOST_ARCH environment variable not set"; @@ -240,10 +240,8 @@ class method. =item put( I, I, ... ) The C method makes a C or C call depending on the -number of elements given in its argument list. For single values the data type -used depends on the actual data item provided by Perl. For arrays the data type -used will be the native type of the channel widened to one of C, C -or C. +number of elements given in its argument list. The data type used will be the +native type of the channel, widened to one of C, C or C. =item put_callback( I, I ) @@ -593,7 +591,7 @@ not follow this pattern, but are still printable strings. =item [1] R3.14 Channel Access Reference Manual by Jeffrey O. Hill -L +L =back diff --git a/src/cap5/Cap5.xs b/src/cap5/Cap5.xs index bc2f4b88f..c1e263b8a 100644 --- a/src/cap5/Cap5.xs +++ b/src/cap5/Cap5.xs @@ -483,6 +483,7 @@ void CA_put(SV *ca_ref, SV *val, ...) { CA_channel *pch = (CA_channel *)SvIV(SvRV(ca_ref)); int num_values = items - 1; int status; + chtype type = best_type(pch); if (num_values == 1) { union { @@ -490,22 +491,21 @@ void CA_put(SV *ca_ref, SV *val, ...) { dbr_double_t dbr_double; dbr_string_t dbr_string; } data; - chtype type; - if (SvIOKp(val)) { + switch (type) { + case DBF_LONG: data.dbr_long = SvIV(val); - type = DBR_LONG; - } else if (SvNOKp(val)) { + break; + case DBF_DOUBLE: data.dbr_double = SvNV(val); - type = DBR_DOUBLE; - } else { + break; + case DBF_STRING: strncpy(data.dbr_string, SvPV_nolen(val), MAX_STRING_SIZE); - type = DBR_STRING; + break; } status = ca_put(type, pch->chan, &data); } else { - chtype type = best_type(pch); union { dbr_long_t *dbr_long; dbr_double_t *dbr_double; @@ -559,6 +559,7 @@ void CA_put_callback(SV *ca_ref, SV *sub, SV *val, ...) { SV *put_sub = newSVsv(sub); int n = items - 2; int status; + chtype type = best_type(pch); if (n == 1) { union { @@ -566,22 +567,21 @@ void CA_put_callback(SV *ca_ref, SV *sub, SV *val, ...) { dbr_double_t dbr_double; dbr_string_t dbr_string; } data; - chtype type; - if (SvIOKp(val)) { + switch (type) { + case DBF_LONG: data.dbr_long = SvIV(val); - type = DBF_LONG; - } else if (SvNOKp(val)) { + break; + case DBF_DOUBLE: data.dbr_double = SvNV(val); - type = DBF_DOUBLE; - } else { + break; + case DBF_STRING: strncpy(data.dbr_string, SvPV_nolen(val), MAX_STRING_SIZE); - type = DBF_STRING; + break; } status = ca_put_callback(type, pch->chan, &data, put_handler, put_sub); } else { - chtype type = best_type(pch); union { dbr_long_t *dbr_long; dbr_double_t *dbr_double;