Skip to content

Commit 7e83c4a

Browse files
authored
unify ssize_t definition (#11384)
remove tvm_ssize_t type and unify the definition of ssize_t in Windows build Co-authored-by: Mohamad <[email protected]>
1 parent 7ba8a61 commit 7e83c4a

File tree

6 files changed

+44
-19
lines changed

6 files changed

+44
-19
lines changed

include/tvm/runtime/c_runtime_api.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,6 @@ extern "C" {
7676
#endif
7777
#include <stddef.h>
7878
#include <stdint.h>
79-
#include <stdio.h>
80-
#include <sys/types.h>
81-
82-
#if defined(_MSC_VER)
83-
#if defined(_WIN64)
84-
typedef int64_t tvm_ssize_t;
85-
#else
86-
typedef int32_t tvm_ssize_t;
87-
#endif
88-
#else
89-
typedef ssize_t tvm_ssize_t;
90-
#endif
9179

9280
/*! \brief type of array index. */
9381
typedef int64_t tvm_index_t;

src/runtime/minrpc/minrpc_server.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class MinRPCReturns : public MinRPCReturnInterface {
150150
const uint8_t* buf = static_cast<const uint8_t*>(data);
151151
size_t ndone = 0;
152152
while (ndone < size) {
153-
tvm_ssize_t ret = io_->PosixWrite(buf, size - ndone);
153+
ssize_t ret = io_->PosixWrite(buf, size - ndone);
154154
if (ret <= 0) {
155155
this->ThrowError(RPCServerStatus::kWriteError);
156156
}
@@ -526,7 +526,7 @@ class MinRPCExecute : public MinRPCExecInterface {
526526
uint8_t* buf = static_cast<uint8_t*>(data);
527527
size_t ndone = 0;
528528
while (ndone < size) {
529-
tvm_ssize_t ret = io_->PosixRead(buf, size - ndone);
529+
ssize_t ret = io_->PosixRead(buf, size - ndone);
530530
if (ret <= 0) return ret;
531531
ndone += ret;
532532
buf += ret;
@@ -757,7 +757,7 @@ class MinRPCServer {
757757
uint8_t* buf = static_cast<uint8_t*>(data);
758758
size_t ndone = 0;
759759
while (ndone < size) {
760-
tvm_ssize_t ret = io_->PosixRead(buf, size - ndone);
760+
ssize_t ret = io_->PosixRead(buf, size - ndone);
761761
if (ret == 0) {
762762
if (allow_clean_shutdown_) {
763763
Shutdown();

src/runtime/minrpc/minrpc_server_logging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class MinRPCSniffer {
140140
uint8_t* buf = reinterpret_cast<uint8_t*>(data);
141141
size_t ndone = 0;
142142
while (ndone < size) {
143-
tvm_ssize_t ret = io_->PosixRead(buf, size - ndone);
143+
ssize_t ret = io_->PosixRead(buf, size - ndone);
144144
if (ret <= 0) {
145145
this->ThrowError(RPCServerStatus::kReadError);
146146
return false;

src/runtime/rpc/rpc_channel_logger.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <memory>
3030
#include <utility>
3131

32+
#include "../../support/ssize.h"
3233
#include "../minrpc/minrpc_server_logging.h"
3334
#include "rpc_channel.h"
3435

@@ -98,11 +99,11 @@ class SnifferIOHandler {
9899

99100
void MessageStart(size_t message_size_bytes) {}
100101

101-
tvm_ssize_t PosixWrite(const uint8_t* buf, size_t buf_size_bytes) { return 0; }
102+
ssize_t PosixWrite(const uint8_t* buf, size_t buf_size_bytes) { return 0; }
102103

103104
void MessageDone() {}
104105

105-
tvm_ssize_t PosixRead(uint8_t* buf, size_t buf_size_bytes) {
106+
ssize_t PosixRead(uint8_t* buf, size_t buf_size_bytes) {
106107
return receive_buffer_->Read(buf, buf_size_bytes);
107108
}
108109

src/support/socket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <winsock2.h>
3535
#include <ws2tcpip.h>
3636

37-
using ssize_t = int;
3837
#ifdef _MSC_VER
3938
#pragma comment(lib, "Ws2_32.lib")
4039
#endif
@@ -57,6 +56,7 @@ using ssize_t = int;
5756
#include <unordered_map>
5857
#include <vector>
5958

59+
#include "../support/ssize.h"
6060
#include "../support/utils.h"
6161

6262
#if defined(_WIN32)

src/support/ssize.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
/*!
21+
* \file ssize.h
22+
* \brief this file aims to define ssize_t for Windows platform
23+
*/
24+
25+
#ifndef TVM_SUPPORT_SSIZE_H_
26+
#define TVM_SUPPORT_SSIZE_H_
27+
28+
#if defined(_MSC_VER)
29+
#if defined(_WIN32)
30+
using ssize_t = int32_t;
31+
#else
32+
using ssize_t = int64_t;
33+
#endif
34+
#endif
35+
36+
#endif // TVM_SUPPORT_SSIZE_H_

0 commit comments

Comments
 (0)