diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/erl_interface/test/port_call_SUITE_data/port_call_drv.c | 25 | ||||
-rw-r--r-- | lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java | 55 | ||||
-rw-r--r-- | lib/kernel/test/seq_trace_SUITE_data/echo_drv.c | 21 | ||||
-rw-r--r-- | lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src | 37 | ||||
-rw-r--r-- | lib/mnesia/src/mnesia_log.erl | 2 | ||||
-rw-r--r-- | lib/runtime_tools/c_src/trace_file_drv.c | 33 | ||||
-rw-r--r-- | lib/runtime_tools/c_src/trace_ip_drv.c | 19 | ||||
-rw-r--r-- | lib/wx/c_src/wxe_driver.c | 22 |
8 files changed, 141 insertions, 73 deletions
diff --git a/lib/erl_interface/test/port_call_SUITE_data/port_call_drv.c b/lib/erl_interface/test/port_call_SUITE_data/port_call_drv.c index 80811fb973..1c71ea8567 100644 --- a/lib/erl_interface/test/port_call_SUITE_data/port_call_drv.c +++ b/lib/erl_interface/test/port_call_SUITE_data/port_call_drv.c @@ -18,14 +18,17 @@ */ #include <stdio.h> +#include <string.h> +#include <stdlib.h> #include "erl_interface.h" #include "erl_driver.h" static ErlDrvPort my_erlang_port; static ErlDrvData echo_start(ErlDrvPort, char *); -static void from_erlang(ErlDrvData, char*, int); -static int do_call(ErlDrvData drv_data, unsigned int command, char *buf, - int len, char **rbuf, int rlen, unsigned *ret_flags); +static void from_erlang(ErlDrvData, char*, ErlDrvSizeT); +static ErlDrvSSizeT do_call(ErlDrvData drv_data, unsigned int command, + char *buf, ErlDrvSizeT len, char **rbuf, + ErlDrvSizeT rlen, unsigned *ret_flags); static ErlDrvEntry echo_driver_entry = { NULL, /* Init */ echo_start, @@ -41,7 +44,15 @@ static ErlDrvEntry echo_driver_entry = { NULL, NULL, NULL, - do_call + do_call, + NULL, + ERL_DRV_EXTENDED_MARKER, + ERL_DRV_EXTENDED_MAJOR_VERSION, + ERL_DRV_EXTENDED_MINOR_VERSION, + 0, + NULL, + NULL, + NULL, }; DRIVER_INIT(echo_drv) @@ -56,14 +67,14 @@ echo_start(ErlDrvPort port, char *buf) } static void -from_erlang(ErlDrvData data, char *buf, int count) +from_erlang(ErlDrvData data, char *buf, ErlDrvSizeT count) { driver_output((ErlDrvPort) data, buf, count); } -static int +static ErlDrvSSizeT do_call(ErlDrvData drv_data, unsigned int command, char *buf, - int len, char **rbuf, int rlen, unsigned *ret_flags) + ErlDrvSizeT len, char **rbuf, ErlDrvSizeT rlen, unsigned *ret_flags) { int nlen; ei_x_buff x; diff --git a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java index 181350100f..ab7642d49d 100644 --- a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java +++ b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java @@ -25,6 +25,7 @@ import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.math.BigInteger; import java.text.DecimalFormat; +import java.util.Arrays; /** * Provides a stream for encoding Erlang terms to external format, for @@ -39,7 +40,7 @@ public class OtpOutputStream extends ByteArrayOutputStream { /** The default initial size of the stream. * */ public static final int defaultInitialSize = 2048; - /** The default increment used when growing the stream. * */ + /** The default increment used when growing the stream (increment at least this much). * */ public static final int defaultIncrement = 2048; // static formats, used to encode floats and doubles @@ -95,6 +96,41 @@ public class OtpOutputStream extends ByteArrayOutputStream { } /** + * Trims the capacity of this <tt>OtpOutputStream</tt> instance to be the + * buffer's current size. An application can use this operation to minimize + * the storage of an <tt>OtpOutputStream</tt> instance. + */ + public void trimToSize() { + if (super.count < super.buf.length) { + final byte[] tmp = new byte[super.count]; + System.arraycopy(super.buf, 0, tmp, 0, super.count); + super.buf = tmp; + } + } + + /** + * Increases the capacity of this <tt>OtpOutputStream</tt> instance, if + * necessary, to ensure that it can hold at least the number of elements + * specified by the minimum capacity argument. + * + * @param minCapacity the desired minimum capacity + */ + public void ensureCapacity(int minCapacity) { + int oldCapacity = super.buf.length; + if (minCapacity > oldCapacity) { + int newCapacity = (oldCapacity * 3)/2 + 1; + if (newCapacity < oldCapacity + defaultIncrement) + newCapacity = oldCapacity + defaultIncrement; + if (newCapacity < minCapacity) + newCapacity = minCapacity; + // minCapacity is usually close to size, so this is a win: + final byte[] tmp = new byte[newCapacity]; + System.arraycopy(super.buf, 0, tmp, 0, super.count); + super.buf = tmp; + } + } + + /** * Write one byte to the stream. * * @param b @@ -102,13 +138,7 @@ public class OtpOutputStream extends ByteArrayOutputStream { * */ public void write(final byte b) { - if (super.count >= super.buf.length) { - // System.err.println("Expanding buffer from " + this.buf.length - // + " to " + (this.buf.length+defaultIncrement)); - final byte[] tmp = new byte[super.buf.length + defaultIncrement]; - System.arraycopy(super.buf, 0, tmp, 0, super.count); - super.buf = tmp; - } + ensureCapacity(super.count + 1); super.buf[super.count++] = b; } @@ -122,14 +152,7 @@ public class OtpOutputStream extends ByteArrayOutputStream { @Override public void write(final byte[] buf) { - if (super.count + buf.length > super.buf.length) { - // System.err.println("Expanding buffer from " + super.buf.length - // + " to " + (buf.length + super.buf.lengt + defaultIncrement)); - final byte[] tmp = new byte[super.buf.length + buf.length - + defaultIncrement]; - System.arraycopy(super.buf, 0, tmp, 0, super.count); - super.buf = tmp; - } + ensureCapacity(super.count + buf.length); System.arraycopy(buf, 0, super.buf, super.count, buf.length); super.count += buf.length; } diff --git a/lib/kernel/test/seq_trace_SUITE_data/echo_drv.c b/lib/kernel/test/seq_trace_SUITE_data/echo_drv.c index dcbb3348d8..aa182b0877 100644 --- a/lib/kernel/test/seq_trace_SUITE_data/echo_drv.c +++ b/lib/kernel/test/seq_trace_SUITE_data/echo_drv.c @@ -3,7 +3,7 @@ static ErlDrvPort erlang_port; static ErlDrvData echo_start(ErlDrvPort, char *); -static void echo_stop(ErlDrvData), echo_read(ErlDrvData, char*, int); +static void echo_stop(ErlDrvData), echo_read(ErlDrvData, char*, ErlDrvSizeT); static ErlDrvEntry echo_driver_entry = { NULL, @@ -13,7 +13,22 @@ static ErlDrvEntry echo_driver_entry = { NULL, NULL, "echo_drv", - NULL + NULL, + NULL, /* handle */ + NULL, /* control */ + NULL, /* timeout */ + NULL, /* outputv */ + NULL, /* ready_async */ + NULL, + NULL, + NULL, + ERL_DRV_EXTENDED_MARKER, + ERL_DRV_EXTENDED_MAJOR_VERSION, + ERL_DRV_EXTENDED_MINOR_VERSION, + 0, + NULL, + NULL, + NULL, }; DRIVER_INIT(echo_drv) @@ -31,7 +46,7 @@ static ErlDrvData echo_start(ErlDrvPort port,char *buf) return (ErlDrvData)port; } -static void echo_read(ErlDrvData data, char *buf, int count) +static void echo_read(ErlDrvData data, char *buf, ErlDrvSizeT count) { driver_output(erlang_port, buf, count); } diff --git a/lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src b/lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src index 9b4f717201..26991d3412 100644 --- a/lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src +++ b/lib/megaco/src/flex/megaco_flex_scanner_drv.flex.src @@ -60,18 +60,11 @@ #define NUL 0x0 #if defined(MEGACO_REENTRANT_FLEX_SCANNER) - #define MEGACO_EXTENDED_MARKER ERL_DRV_EXTENDED_MARKER - #define MEGACO_DRIVER_FLAGS ERL_DRV_FLAG_USE_PORT_LOCKING - #define MEGACO_EXTENDED_MAJOR_VERSION ERL_DRV_EXTENDED_MAJOR_VERSION - #define MEGACO_EXTENDED_MINOR_VERSION ERL_DRV_EXTENDED_MINOR_VERSION -#else - #define MEGACO_EXTENDED_MARKER 0 - #define MEGACO_DRIVER_FLAGS 0 - #define MEGACO_EXTENDED_MAJOR_VERSION 0 - #define MEGACO_EXTENDED_MINOR_VERSION 0 +# define MEGACO_DRIVER_FLAGS ERL_DRV_FLAG_USE_PORT_LOCKING +#else +# define MEGACO_DRIVER_FLAGS 0 #endif - #define FREE(bufP) driver_free(bufP) #define ALLOC(sz) driver_alloc(sz) #define REALLOC(bufP, sz) driver_realloc(bufP, sz) @@ -320,11 +313,11 @@ static void mfs_load_map_token(); static ErlDrvData mfs_start(ErlDrvPort port, char *buf); static void mfs_stop(ErlDrvData handle); static void mfs_command(ErlDrvData handle, - char *buf, int buf_len); -static int mfs_control(ErlDrvData handle, + char *buf, ErlDrvSizeT buf_len); +static ErlDrvSSizeT mfs_control(ErlDrvData handle, unsigned int command, - char *buf, int buf_len, - char **res_buf, int res_buf_len); + char *buf, ErlDrvSizeT buf_len, + char **res_buf, ErlDrvSizeT res_buf_len); static void mfs_finish(void); /* @@ -348,10 +341,10 @@ static ErlDrvEntry mfs_entry = { NULL, /* flush, port is about to be closed */ NULL, /* call, a syncronous call into the driver */ NULL, /* event, event selected by driver_event() has occurred */ - MEGACO_EXTENDED_MARKER, /* extended_marker, which we use if reentrant */ - MEGACO_EXTENDED_MAJOR_VERSION, /* major_version, ... */ - MEGACO_EXTENDED_MINOR_VERSION, /* minor_version, ... */ - MEGACO_DRIVER_FLAGS, /* driver_flags, used for port lock indication */ + ERL_DRV_EXTENDED_MARKER, + ERL_DRV_EXTENDED_MAJOR_VERSION, + ERL_DRV_EXTENDED_MINOR_VERSION, + MEGACO_DRIVER_FLAGS, /* driver_flags, used for port lock indication */ NULL, /* handle2, emulator internal use */ NULL /* process_exit, Called when a process monitor fires */ }; @@ -1685,17 +1678,17 @@ static void mfs_stop(ErlDrvData handle) } static void mfs_command(ErlDrvData handle, - char *buf, int buf_len) + char *buf, ErlDrvSizeT buf_len) { driver_failure_atom(((MfsErlDrvData*) handle)->port, "bad_usage"); return; } -static int mfs_control(ErlDrvData handle, +static ErlDrvSSizeT mfs_control(ErlDrvData handle, unsigned int command, - char *buf, int buf_len, - char **res_buf, int res_buf_len) + char *buf, ErlDrvSizeT buf_len, + char **res_buf, ErlDrvSizeT res_buf_len) { MfsErlDrvData* dataP = (MfsErlDrvData*) handle; char* tmp; diff --git a/lib/mnesia/src/mnesia_log.erl b/lib/mnesia/src/mnesia_log.erl index 94153473cb..e22eb706ad 100644 --- a/lib/mnesia/src/mnesia_log.erl +++ b/lib/mnesia/src/mnesia_log.erl @@ -927,7 +927,7 @@ ets2dcd(Tab, Ftype) -> ets2dcd('$end_of_table', _Tab, _Log) -> ok; ets2dcd({Recs, Cont}, Tab, Log) -> - ok = disk_log:alog_terms(Log, Recs), + ok = disk_log:log_terms(Log, Recs), ets2dcd(mnesia_lib:db_chunk(ram_copies, Cont), Tab, Log). dcd2ets(Tab) -> diff --git a/lib/runtime_tools/c_src/trace_file_drv.c b/lib/runtime_tools/c_src/trace_file_drv.c index 5de2a65917..08bace80ef 100644 --- a/lib/runtime_tools/c_src/trace_file_drv.c +++ b/lib/runtime_tools/c_src/trace_file_drv.c @@ -173,11 +173,13 @@ static TraceFileData *first_data; */ static ErlDrvData trace_file_start(ErlDrvPort port, char *buff); static void trace_file_stop(ErlDrvData handle); -static void trace_file_output(ErlDrvData handle, char *buff, int bufflen); +static void trace_file_output(ErlDrvData handle, char *buff, + ErlDrvSizeT bufflen); static void trace_file_finish(void); -static int trace_file_control(ErlDrvData handle, unsigned int command, - char* buff, int count, - char** res, int res_size); +static ErlDrvSSizeT trace_file_control(ErlDrvData handle, + unsigned int command, + char* buff, ErlDrvSizeT count, + char** res, ErlDrvSizeT res_size); static void trace_file_timeout(ErlDrvData handle); /* @@ -215,7 +217,18 @@ ErlDrvEntry trace_file_driver_entry = { NULL, /* void * that is not used (BC) */ trace_file_control, /* F_PTR control, port_control callback */ trace_file_timeout, /* F_PTR timeout, driver_set_timer callback */ - NULL /* F_PTR outputv, reserved */ + NULL, /* F_PTR outputv, reserved */ + NULL, /* ready_async */ + NULL, /* flush */ + NULL, /* call */ + NULL, /* event */ + ERL_DRV_EXTENDED_MARKER, + ERL_DRV_EXTENDED_MAJOR_VERSION, + ERL_DRV_EXTENDED_MINOR_VERSION, + 0, + NULL, + NULL, + NULL, }; /* @@ -351,7 +364,8 @@ static void trace_file_stop(ErlDrvData handle) /* ** Data sent from erlang to port. */ -static void trace_file_output(ErlDrvData handle, char *buff, int bufflen) +static void trace_file_output(ErlDrvData handle, char *buff, + ErlDrvSizeT bufflen) { int heavy = 0; TraceFileData *data = (TraceFileData *) handle; @@ -395,9 +409,10 @@ static void trace_file_output(ErlDrvData handle, char *buff, int bufflen) /* ** Control message from erlang, we handle $f, which is flush. */ -static int trace_file_control(ErlDrvData handle, unsigned int command, - char* buff, int count, - char** res, int res_size) +static ErlDrvSSizeT trace_file_control(ErlDrvData handle, + unsigned int command, + char* buff, ErlDrvSizeT count, + char** res, ErlDrvSizeT res_size) { if (command == 'f') { TraceFileData *data = (TraceFileData *) handle; diff --git a/lib/runtime_tools/c_src/trace_ip_drv.c b/lib/runtime_tools/c_src/trace_ip_drv.c index d2ed1a294b..713ae924f6 100644 --- a/lib/runtime_tools/c_src/trace_ip_drv.c +++ b/lib/runtime_tools/c_src/trace_ip_drv.c @@ -185,7 +185,8 @@ static TraceIpData *first_data; */ static ErlDrvData trace_ip_start(ErlDrvPort port, char *buff); static void trace_ip_stop(ErlDrvData handle); -static void trace_ip_output(ErlDrvData handle, char *buff, int bufflen); +static void trace_ip_output(ErlDrvData handle, char *buff, + ErlDrvSizeT bufflen); #ifdef __WIN32__ static void trace_ip_event(ErlDrvData handle, ErlDrvEvent event); #endif @@ -193,9 +194,10 @@ static void trace_ip_ready_input(ErlDrvData handle, ErlDrvEvent fd); static void trace_ip_ready_output(ErlDrvData handle, ErlDrvEvent fd); static void trace_ip_finish(void); /* No arguments, despite what might be stated in any documentation */ -static int trace_ip_control(ErlDrvData handle, unsigned int command, - char* buff, int count, - char** res, int res_size); +static ErlDrvSSizeT trace_ip_control(ErlDrvData handle, + unsigned int command, + char* buff, ErlDrvSizeT count, + char** res, ErlDrvSizeT res_size); /* ** Internal routines @@ -382,7 +384,7 @@ static void trace_ip_stop(ErlDrvData handle) /* ** Data sent from erlang to port. */ -static void trace_ip_output(ErlDrvData handle, char *buff, int bufflen) +static void trace_ip_output(ErlDrvData handle, char *buff, ErlDrvSizeT bufflen) { TraceIpData *data = (TraceIpData *) handle; if (data->flags & FLAG_LISTEN_PORT) { @@ -548,9 +550,10 @@ static void trace_ip_ready_output(ErlDrvData handle, ErlDrvEvent fd) /* ** Control message from erlang, we handle $p, which is get_listen_port. */ -static int trace_ip_control(ErlDrvData handle, unsigned int command, - char* buff, int count, - char** res, int res_size) +static ErlDrvSSizeT trace_ip_control(ErlDrvData handle, + unsigned int command, + char* buff, ErlDrvSizeT count, + char** res, ErlDrvSizeT res_size) { register void *void_ptr; /* Soft type cast */ diff --git a/lib/wx/c_src/wxe_driver.c b/lib/wx/c_src/wxe_driver.c index 2404b13cc3..d1ed252ec0 100644 --- a/lib/wx/c_src/wxe_driver.c +++ b/lib/wx/c_src/wxe_driver.c @@ -40,9 +40,14 @@ static ErlDrvData wxe_driver_start(ErlDrvPort port, char *buff); static int wxe_driver_load(void); static void wxe_driver_stop(ErlDrvData handle); static void wxe_driver_unload(void); -static int wxe_driver_control(ErlDrvData handle, unsigned int command, - char* buf, int count, char** res, int res_size); -static int wxe_driver_call(ErlDrvData drv_data, unsigned int command, char *buf, int len, char **rbuf, int rlen, unsigned int *flags); +static ErlDrvSSizeT wxe_driver_control(ErlDrvData handle, + unsigned int command, + char* buf, ErlDrvSizeT count, + char** res, ErlDrvSizeT res_size); +static ErlDrvSSizeT wxe_driver_call(ErlDrvData drv_data, unsigned int command, + char *buf, ErlDrvSizeT len, + char **rbuf, ErlDrvSizeT rlen, + unsigned int *flags); static void standard_outputv(ErlDrvData drv_data, ErlIOVec *ev); static void wxe_process_died(ErlDrvData drv_data, ErlDrvMonitor *monitor); @@ -151,17 +156,20 @@ wxe_driver_unload(void) wxe_master = NULL; } -static int +static ErlDrvSSizeT wxe_driver_control(ErlDrvData handle, unsigned op, - char* buf, int count, char** res, int res_size) + char* buf, ErlDrvSizeT count, + char** res, ErlDrvSizeT res_size) { wxe_data *sd = ((wxe_data *)handle); push_command(op,buf,count,sd); return 0; } -static int wxe_driver_call(ErlDrvData handle, unsigned int command, - char *buf, int len, char **res, int rlen, unsigned int *flags) +static ErlDrvSSizeT +wxe_driver_call(ErlDrvData handle, unsigned int command, + char *buf, ErlDrvSizeT len, + char **res, ErlDrvSizeT rlen, unsigned int *flags) { wxe_data *sd = ((wxe_data *)handle); if(command == WXE_DEBUG_DRIVER) { |