Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 0 additions & 59 deletions elisp/proto/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2945,10 +2945,6 @@ static HANDLE StdinHandle(struct Context ctx) {
return StandardHandle(ctx, STD_INPUT_HANDLE);
}

static HANDLE StdoutHandle(struct Context ctx) {
return StandardHandle(ctx, STD_OUTPUT_HANDLE);
}

static upb_StringView ReadHandle(struct Context ctx, HANDLE handle,
char* buffer, size_t size) {
upb_StringView null = UPB_STRINGVIEW_INIT(NULL, 0);
Expand All @@ -2965,22 +2961,6 @@ static upb_StringView ReadHandle(struct Context ctx, HANDLE handle,
if (n == 0) return null;
return upb_StringView_FromDataAndSize(buffer, n);
}

static bool WriteHandle(struct Context ctx, HANDLE handle,
upb_StringView* data) {
if (!Success(ctx)) return false;
DWORD n;
if (!WriteFile(handle, data->data,
data->size <= MAXDWORD ? (DWORD)data->size : MAXDWORD, &n,
NULL)) {
assert(n == 0);
FileError(ctx, GetLastError());
return false;
}
data->data += n;
data->size -= n;
return true;
}
#else
static void FileError(struct Context ctx, int code) {
emacs_value message = Nil(ctx);
Expand All @@ -3004,10 +2984,6 @@ static int StdinHandle(struct Context ctx ABSL_ATTRIBUTE_UNUSED) {
return STDIN_FILENO;
}

static int StdoutHandle(struct Context ctx ABSL_ATTRIBUTE_UNUSED) {
return STDOUT_FILENO;
}

static upb_StringView ReadHandle(struct Context ctx, int fd, char* buffer,
size_t size) {
upb_StringView null = UPB_STRINGVIEW_INIT(NULL, 0);
Expand All @@ -3021,18 +2997,6 @@ static upb_StringView ReadHandle(struct Context ctx, int fd, char* buffer,
assert((size_t)n <= size);
return upb_StringView_FromDataAndSize(buffer, (size_t)n);
}

static bool WriteHandle(struct Context ctx, int fd, upb_StringView* data) {
if (!Success(ctx)) return false;
ssize_t n = write(fd, data->data, data->size <= kMaxIO ? data->size : kMaxIO);
if (n < 0) {
FileError(ctx, errno);
return false;
}
data->data += n;
data->size -= (size_t)n;
return true;
}
#endif

/// Function definitions
Expand Down Expand Up @@ -4245,22 +4209,6 @@ static emacs_value InsertStdin(emacs_env* env,
return Nil(ctx);
}

static emacs_value WriteStdout(emacs_env* env,
ptrdiff_t nargs ABSL_ATTRIBUTE_UNUSED,
emacs_value* args, void* data) {
struct Context ctx = {env, data};
assert(nargs == 1);
struct Allocator alloc = HeapAllocator();
FileHandle handle = StdoutHandle(ctx);
if (!ValidHandle(handle)) return NULL;
struct MutableString content = ExtractUnibyteString(ctx, alloc, args[0]);
if (content.data == NULL) return NULL;
upb_StringView left = View(content);
while (left.size > 0 && WriteHandle(ctx, handle, &left));
Free(alloc, content.data);
return Nil(ctx);
}

static emacs_value ParseCodeGeneratorRequest(
emacs_env* env, ptrdiff_t nargs ABSL_ATTRIBUTE_UNUSED, emacs_value* args,
void* data) {
Expand Down Expand Up @@ -4776,13 +4724,6 @@ int EXPORT emacs_module_init(struct emacs_runtime* rt) {
"This function is used by the protocol buffer compiler;\n"
"users should not call it directly.",
Params0(), kT, 0, InsertStdin);
Defun(ctx, "elisp/proto/write-stdout", 1, 1,
"Write STRING to standard output.\n"
"STRING must be a unibyte string.\n"
"This function is used by the protocol buffer compiler;\n"
"users should not call it directly.\n\n"
"(fn string)",
Params1(kString), kT, 0, WriteStdout);
Defun(ctx, "elisp/proto/parse-code-generator-request", 1, 1,
"Parse a protocol buffer code generator request.\n"
"SERIALIZED must be the serialized form of a\n"
Expand Down
8 changes: 2 additions & 6 deletions tests/proto/integration/cat.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; cat.el --- helper binary for module test -*- lexical-binding: t; -*-

;; Copyright 2024, 2025 Philipp Stephani
;; Copyright 2024-2026 Philipp Stephani
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,10 +40,6 @@
(pcase-exhaustive op
(">"
(with-temp-file file
(elisp/proto/insert-stdin)))
("<"
(insert-file-contents-literally file)
(elisp/proto/write-stdout
(buffer-substring-no-properties (point-min) (point-max))))))))
(elisp/proto/insert-stdin)))))))

;;; cat.el ends here
24 changes: 1 addition & 23 deletions tests/proto/integration/module_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024, 2025 Philipp Stephani
// Copyright 2024-2026 Philipp Stephani
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -57,25 +57,3 @@ func TestInsertStdin(t *testing.T) {
t.Errorf("unexpected file content: %q", got)
}
}

// Integration test for elisp/proto/write-stdout.
func TestWriteStdout(t *testing.T) {
infile := filepath.Join(t.TempDir(), "in")
if err := os.WriteFile(infile, []byte("stdout \xFF"), 0400); err != nil {
t.Error(err)
}
cmd := exec.Command(*cat, "<", infile)
stdout := new(strings.Builder)
stderr := new(bytes.Buffer)
cmd.Stdout = stdout
cmd.Stderr = stderr
if err := cmd.Run(); err != nil {
t.Error(err)
}
if got := stdout.String(); got != "stdout \xFF" {
t.Errorf("unexpected stdout: %q", got)
}
if stderr.Len() != 0 {
t.Errorf("unexpected stderr: %q", stderr.Bytes())
}
}