Skip to content

Commit

Permalink
remove tvm_ssize_t type and unify the definition of ssize_t in Windo…
Browse files Browse the repository at this point in the history
…ws build
  • Loading branch information
mkatanbaf committed May 24, 2022
1 parent e02bf82 commit 8d04293
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 19 deletions.
12 changes: 0 additions & 12 deletions include/tvm/runtime/c_runtime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,6 @@ extern "C" {
#endif
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>

#if defined(_MSC_VER)
#if defined(_WIN64)
typedef int64_t tvm_ssize_t;
#else
typedef int32_t tvm_ssize_t;
#endif
#else
typedef ssize_t tvm_ssize_t;
#endif

/*! \brief type of array index. */
typedef int64_t tvm_index_t;
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/minrpc/minrpc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class MinRPCReturns : public MinRPCReturnInterface {
const uint8_t* buf = static_cast<const uint8_t*>(data);
size_t ndone = 0;
while (ndone < size) {
tvm_ssize_t ret = io_->PosixWrite(buf, size - ndone);
ssize_t ret = io_->PosixWrite(buf, size - ndone);
if (ret <= 0) {
this->ThrowError(RPCServerStatus::kWriteError);
}
Expand Down Expand Up @@ -526,7 +526,7 @@ class MinRPCExecute : public MinRPCExecInterface {
uint8_t* buf = static_cast<uint8_t*>(data);
size_t ndone = 0;
while (ndone < size) {
tvm_ssize_t ret = io_->PosixRead(buf, size - ndone);
ssize_t ret = io_->PosixRead(buf, size - ndone);
if (ret <= 0) return ret;
ndone += ret;
buf += ret;
Expand Down Expand Up @@ -757,7 +757,7 @@ class MinRPCServer {
uint8_t* buf = static_cast<uint8_t*>(data);
size_t ndone = 0;
while (ndone < size) {
tvm_ssize_t ret = io_->PosixRead(buf, size - ndone);
ssize_t ret = io_->PosixRead(buf, size - ndone);
if (ret == 0) {
if (allow_clean_shutdown_) {
Shutdown();
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/minrpc/minrpc_server_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class MinRPCSniffer {
uint8_t* buf = reinterpret_cast<uint8_t*>(data);
size_t ndone = 0;
while (ndone < size) {
tvm_ssize_t ret = io_->PosixRead(buf, size - ndone);
ssize_t ret = io_->PosixRead(buf, size - ndone);
if (ret <= 0) {
this->ThrowError(RPCServerStatus::kReadError);
return false;
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/rpc/rpc_channel_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <memory>
#include <utility>

#include "../../support/ssize.h"
#include "../minrpc/minrpc_server_logging.h"
#include "rpc_channel.h"

Expand Down Expand Up @@ -98,11 +99,11 @@ class SnifferIOHandler {

void MessageStart(size_t message_size_bytes) {}

tvm_ssize_t PosixWrite(const uint8_t* buf, size_t buf_size_bytes) { return 0; }
ssize_t PosixWrite(const uint8_t* buf, size_t buf_size_bytes) { return 0; }

void MessageDone() {}

tvm_ssize_t PosixRead(uint8_t* buf, size_t buf_size_bytes) {
ssize_t PosixRead(uint8_t* buf, size_t buf_size_bytes) {
return receive_buffer_->Read(buf, buf_size_bytes);
}

Expand Down
2 changes: 1 addition & 1 deletion src/support/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <winsock2.h>
#include <ws2tcpip.h>

using ssize_t = int;
#ifdef _MSC_VER
#pragma comment(lib, "Ws2_32.lib")
#endif
Expand All @@ -57,6 +56,7 @@ using ssize_t = int;
#include <unordered_map>
#include <vector>

#include "../support/ssize.h"
#include "../support/utils.h"

#if defined(_WIN32)
Expand Down
36 changes: 36 additions & 0 deletions src/support/ssize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*!
* \file ssize.h
* \brief this file aims to define ssize_t for Windows platform
*/

#ifndef TVM_SUPPORT_SSIZE_H_
#define TVM_SUPPORT_SSIZE_H_

#if defined(_MSC_VER)
#if defined(_WIN32)
using ssize_t = int32_t;
#else
using ssize_t = int64_t;
#endif
#endif

#endif // TVM_SUPPORT_SSIZE_H_

0 comments on commit 8d04293

Please sign in to comment.