job: Refactor job_write to receive WBuffer instances.

This was done to give more control over memory management to job_write callers.
This commit is contained in:
Thiago de Arruda
2014-06-17 10:02:23 -03:00
parent 287967a2c0
commit abc423983d
3 changed files with 9 additions and 7 deletions

View File

@@ -10540,9 +10540,10 @@ static void f_job_write(typval_T *argvars, typval_T *rettv)
EMSG(_(e_invjob)); EMSG(_(e_invjob));
} }
rettv->vval.v_number = job_write(job, WBuffer *buf = wstream_new_buffer(xstrdup((char *)argvars[1].vval.v_string),
xstrdup((char *)argvars[1].vval.v_string), strlen((char *)argvars[1].vval.v_string),
strlen((char *)argvars[1].vval.v_string)); free);
rettv->vval.v_number = job_write(job, buf);
} }
/* /*

View File

@@ -260,13 +260,12 @@ void job_stop(Job *job)
/// returns when the write request was sent. /// returns when the write request was sent.
/// ///
/// @param job The Job instance /// @param job The Job instance
/// @param data Buffer containing the data to be written /// @param buffer The buffer which contains the data to be written
/// @param len Size of the data
/// @return true if the write request was successfully sent, false if writing /// @return true if the write request was successfully sent, false if writing
/// to the job stream failed (possibly because the OS buffer is full) /// to the job stream failed (possibly because the OS buffer is full)
bool job_write(Job *job, char *data, uint32_t len) bool job_write(Job *job, WBuffer *buffer)
{ {
return wstream_write(job->in, wstream_new_buffer(data, len, free)); return wstream_write(job->in, buffer);
} }
/// Sets the `defer` flag for a Job instance /// Sets the `defer` flag for a Job instance

View File

@@ -12,6 +12,8 @@
#include "nvim/os/rstream_defs.h" #include "nvim/os/rstream_defs.h"
#include "nvim/os/event_defs.h" #include "nvim/os/event_defs.h"
#include "nvim/os/wstream.h"
#include "nvim/os/wstream_defs.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/job.h.generated.h" # include "os/job.h.generated.h"