Skip to content

Commit b1e0335

Browse files
committed
fix linting
1 parent 7f7e7e7 commit b1e0335

File tree

16 files changed

+100
-85
lines changed

16 files changed

+100
-85
lines changed

cpp/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,10 @@ if (UNIX)
864864
IF(NOT ((item MATCHES "_generated.h") OR
865865
(item MATCHES "pyarrow_api.h") OR
866866
(item MATCHES "xxhash.h") OR
867-
(item MATCHES "xxhash.cc")))
867+
(item MATCHES "xxhash.cc") OR
868+
(item MATCHES "config.h") OR
869+
(item MATCHES "zmalloc.h") OR
870+
(item MATCHES "ae.h")))
868871
LIST(APPEND FILTERED_LINT_FILES ${item})
869872
ENDIF()
870873
ENDFOREACH(item ${LINT_FILES})

cpp/src/arrow/status.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,17 @@ class ARROW_EXPORT Status {
155155
bool IsUnknownError() const { return code() == StatusCode::UnknownError; }
156156
bool IsNotImplemented() const { return code() == StatusCode::NotImplemented; }
157157
// An object with this object ID already exists in the plasma store.
158-
bool IsPlasmaObjectExists() const { return code() == StatusCode::PlasmaObjectExists; }
158+
bool IsPlasmaObjectExists() const {
159+
return code() == StatusCode::PlasmaObjectExists;
160+
}
159161
// An object was requested that doesn't exist in the plasma store.
160-
bool IsPlasmaObjectNonexistent() const { return code() == StatusCode::PlasmaObjectNonexistent; }
162+
bool IsPlasmaObjectNonexistent() const {
163+
return code() == StatusCode::PlasmaObjectNonexistent;
164+
}
161165
// An object is too large to fit into the plasma store.
162-
bool IsPlasmaStoreFull() const { return code() == StatusCode::PlasmaStoreFull; }
166+
bool IsPlasmaStoreFull() const {
167+
return code() == StatusCode::PlasmaStoreFull;
168+
}
163169

164170
// Return a string representation of this status suitable for printing.
165171
// Returns the string "OK" for success.

cpp/src/plasma/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ include_directories("${FLATBUFFERS_INCLUDE_DIR}")
8181
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
8282

8383
set_source_files_properties(thirdparty/dlmalloc.c PROPERTIES COMPILE_FLAGS -Wno-all)
84+
set_source_files_properties(extension.cc PROPERTIES COMPILE_FLAGS -Wno-strict-aliasing)
8485

8586
add_library(plasma_lib STATIC
8687
client.cc

cpp/src/plasma/client.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ uint8_t *lookup_or_mmap(PlasmaClient *conn,
9292
close(fd);
9393
return entry->second->pointer;
9494
} else {
95-
uint8_t *result = reinterpret_cast<uint8_t *>(mmap(NULL, map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
95+
uint8_t *result = reinterpret_cast<uint8_t *>(
96+
mmap(NULL, map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
9697
if (result == MAP_FAILED) {
9798
ARROW_LOG(FATAL) << "mmap failed";
9899
}
@@ -589,10 +590,10 @@ Status PlasmaClient::Info(ObjectID object_id, int *object_status) {
589590
return ReadStatusReply(buffer.data(), &object_id, object_status, 1);
590591
}
591592

592-
Status PlasmaClient::Wait(int num_object_requests,
593+
Status PlasmaClient::Wait(int64_t num_object_requests,
593594
ObjectRequest object_requests[],
594595
int num_ready_objects,
595-
uint64_t timeout_ms,
596+
int64_t timeout_ms,
596597
int &num_objects_ready) {
597598
ARROW_CHECK(manager_conn >= 0);
598599
ARROW_CHECK(num_object_requests > 0);

cpp/src/plasma/client.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ class PlasmaClient {
238238
/// the object_requests list. If the returned number is less than
239239
/// min_num_ready_objects this means that timeout expired.
240240
/// @return The return status.
241-
Status Wait(int num_object_requests,
241+
Status Wait(int64_t num_object_requests,
242242
ObjectRequest object_requests[],
243243
int num_ready_objects,
244-
uint64_t timeout_ms,
244+
int64_t timeout_ms,
245245
int &num_objects_ready);
246246

247247
/// Transfer local object to a different plasma manager.

cpp/src/plasma/events.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void EventLoop::file_event_callback(aeEventLoop *loop,
2828
}
2929

3030
int EventLoop::timer_event_callback(aeEventLoop *loop,
31-
long long timer_id,
31+
TimerID timer_id,
3232
void *context) {
3333
TimerCallback *callback = reinterpret_cast<TimerCallback *>(context);
3434
return (*callback)(timer_id);

cpp/src/plasma/events.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ constexpr int kEventLoopRead = AE_READABLE;
3535
/// Write event on the file descriptor.
3636
constexpr int kEventLoopWrite = AE_WRITABLE;
3737

38+
typedef long long TimerID; // NOLINT
39+
3840
class EventLoop {
3941
public:
4042
// Signature of the handler that will be called when there is a new event
@@ -91,7 +93,7 @@ class EventLoop {
9193
int events);
9294

9395
static int timer_event_callback(aeEventLoop *loop,
94-
long long timer_id,
96+
TimerID timer_id,
9597
void *context);
9698

9799
aeEventLoop *loop_;

cpp/src/plasma/extension.cc

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
#include "plasma/common.h"
2020
#include "plasma/protocol.h"
2121
#include "plasma/client.h"
22-
2322
#include "plasma/extension.h"
2423

24+
#include <algorithm>
25+
#include <vector>
26+
2527
PyObject *PlasmaOutOfMemoryError;
2628
PyObject *PlasmaObjectExistsError;
2729

@@ -52,16 +54,16 @@ PyObject *PyPlasma_disconnect(PyObject *self, PyObject *args) {
5254
* is still active (if the context is NULL) or if it is closed (if the context
5355
* is (void*) 0x1). This is neccessary because the primary pointer of the
5456
* capsule cannot be NULL. */
55-
PyCapsule_SetContext(client_capsule, (void *) 0x1);
57+
PyCapsule_SetContext(client_capsule, reinterpret_cast<void *>(0x1));
5658
Py_RETURN_NONE;
5759
}
5860

5961
PyObject *PyPlasma_create(PyObject *self, PyObject *args) {
6062
PlasmaClient *client;
6163
ObjectID object_id;
62-
long long size;
64+
Py_ssize_t size;
6365
PyObject *metadata;
64-
if (!PyArg_ParseTuple(args, "O&O&LO", PyObjectToPlasmaClient, &client,
66+
if (!PyArg_ParseTuple(args, "O&O&nO", PyObjectToPlasmaClient, &client,
6567
PyStringToUniqueID, &object_id, &size, &metadata)) {
6668
return NULL;
6769
}
@@ -71,7 +73,7 @@ PyObject *PyPlasma_create(PyObject *self, PyObject *args) {
7173
}
7274
uint8_t *data;
7375
Status s = client->Create(object_id, size,
74-
(uint8_t *) PyByteArray_AsString(metadata),
76+
reinterpret_cast<uint8_t *>(PyByteArray_AsString(metadata)),
7577
PyByteArray_Size(metadata), &data);
7678
if (s.IsPlasmaObjectExists()) {
7779
PyErr_SetString(PlasmaObjectExistsError,
@@ -88,9 +90,9 @@ PyObject *PyPlasma_create(PyObject *self, PyObject *args) {
8890
ARROW_CHECK(s.ok());
8991

9092
#if PY_MAJOR_VERSION >= 3
91-
return PyMemoryView_FromMemory((char *) data, (Py_ssize_t) size, PyBUF_WRITE);
93+
return PyMemoryView_FromMemory(reinterpret_cast<char *>(data), size, PyBUF_WRITE);
9294
#else
93-
return PyBuffer_FromReadWriteMemory((void *) data, (Py_ssize_t) size);
95+
return PyBuffer_FromReadWriteMemory(reinterpret_cast<void *>(data), size);
9496
#endif
9597
}
9698

@@ -105,7 +107,7 @@ PyObject *PyPlasma_hash(PyObject *self, PyObject *args) {
105107
bool success = plasma_compute_object_hash(client, object_id, digest);
106108
if (success) {
107109
PyObject *digest_string =
108-
PyBytes_FromStringAndSize((char *) digest, kDigestSize);
110+
PyBytes_FromStringAndSize(reinterpret_cast<char *>(digest), kDigestSize);
109111
return digest_string;
110112
} else {
111113
Py_RETURN_NONE;
@@ -137,16 +139,15 @@ PyObject *PyPlasma_release(PyObject *self, PyObject *args) {
137139
PyObject *PyPlasma_get(PyObject *self, PyObject *args) {
138140
PlasmaClient *client;
139141
PyObject *object_id_list;
140-
long long timeout_ms;
141-
if (!PyArg_ParseTuple(args, "O&OL", PyObjectToPlasmaClient, &client,
142+
Py_ssize_t timeout_ms;
143+
if (!PyArg_ParseTuple(args, "O&On", PyObjectToPlasmaClient, &client,
142144
&object_id_list, &timeout_ms)) {
143145
return NULL;
144146
}
145147

146148
Py_ssize_t num_object_ids = PyList_Size(object_id_list);
147-
ObjectID *object_ids = (ObjectID *) malloc(sizeof(ObjectID) * num_object_ids);
148-
ObjectBuffer *object_buffers =
149-
(ObjectBuffer *) malloc(sizeof(ObjectBuffer) * num_object_ids);
149+
ObjectID *object_ids = new ObjectID[num_object_ids];
150+
ObjectBuffer *object_buffers = new ObjectBuffer[num_object_ids];
150151

151152
for (int i = 0; i < num_object_ids; ++i) {
152153
PyStringToUniqueID(PyList_GetItem(object_id_list, i), &object_ids[i]);
@@ -156,39 +157,35 @@ PyObject *PyPlasma_get(PyObject *self, PyObject *args) {
156157
ARROW_CHECK_OK(
157158
client->Get(object_ids, num_object_ids, timeout_ms, object_buffers));
158159
Py_END_ALLOW_THREADS;
159-
free(object_ids);
160+
delete[] object_ids;
160161

161162
PyObject *returns = PyList_New(num_object_ids);
162163
for (int i = 0; i < num_object_ids; ++i) {
163164
if (object_buffers[i].data_size != -1) {
164165
/* The object was retrieved, so return the object. */
165166
PyObject *t = PyTuple_New(2);
167+
Py_ssize_t data_size = static_cast<Py_ssize_t>(object_buffers[i].data_size);
168+
Py_ssize_t metadata_size = static_cast<Py_ssize_t>(object_buffers[i].metadata_size);
166169
#if PY_MAJOR_VERSION >= 3
167-
PyTuple_SetItem(
168-
t, 0, PyMemoryView_FromMemory(
169-
(char *) object_buffers[i].data,
170-
(Py_ssize_t) object_buffers[i].data_size, PyBUF_READ));
171-
PyTuple_SetItem(
172-
t, 1, PyMemoryView_FromMemory(
173-
(char *) object_buffers[i].metadata,
174-
(Py_ssize_t) object_buffers[i].metadata_size, PyBUF_READ));
170+
char *data = reinterpret_cast<char *>(object_buffers[i].data);
171+
char *metadata = reinterpret_cast<char *>(object_buffers[i].metadata);
172+
PyTuple_SetItem(t, 0, PyMemoryView_FromMemory(data, data_size, PyBUF_READ));
173+
PyTuple_SetItem(t, 1, PyMemoryView_FromMemory(metadata, metadata_size, PyBUF_READ));
175174
#else
176-
PyTuple_SetItem(
177-
t, 0, PyBuffer_FromMemory((void *) object_buffers[i].data,
178-
(Py_ssize_t) object_buffers[i].data_size));
179-
PyTuple_SetItem(t, 1, PyBuffer_FromMemory(
180-
(void *) object_buffers[i].metadata,
181-
(Py_ssize_t) object_buffers[i].metadata_size));
175+
void *data = reinterpret_cast<void *>(object_buffers[i].data);
176+
void *metadata = reinterpret_cast<void *>(object_buffers[i].metadata);
177+
PyTuple_SetItem(t, 0, PyBuffer_FromMemory(data, data_size));
178+
PyTuple_SetItem(t, 1, PyBuffer_FromMemory(metadata, metadata_size));
182179
#endif
183180
PyList_SetItem(returns, i, t);
184181
} else {
185182
/* The object was not retrieved, so just add None to the list of return
186183
* values. */
187-
Py_XINCREF(Py_None);
184+
Py_INCREF(Py_None);
188185
PyList_SetItem(returns, i, Py_None);
189186
}
190187
}
191-
free(object_buffers);
188+
delete[] object_buffers;
192189
return returns;
193190
}
194191

@@ -220,21 +217,21 @@ PyObject *PyPlasma_fetch(PyObject *self, PyObject *args) {
220217
return NULL;
221218
}
222219
Py_ssize_t n = PyList_Size(object_id_list);
223-
ObjectID *object_ids = (ObjectID *) malloc(sizeof(ObjectID) * n);
220+
ObjectID *object_ids = new ObjectID[n];
224221
for (int i = 0; i < n; ++i) {
225222
PyStringToUniqueID(PyList_GetItem(object_id_list, i), &object_ids[i]);
226223
}
227-
ARROW_CHECK_OK(client->Fetch((int) n, object_ids));
228-
free(object_ids);
224+
ARROW_CHECK_OK(client->Fetch(static_cast<int>(n), object_ids));
225+
delete[] object_ids;
229226
Py_RETURN_NONE;
230227
}
231228

232229
PyObject *PyPlasma_wait(PyObject *self, PyObject *args) {
233230
PlasmaClient *client;
234231
PyObject *object_id_list;
235-
long long timeout;
232+
Py_ssize_t timeout;
236233
int num_returns;
237-
if (!PyArg_ParseTuple(args, "O&OLi", PyObjectToPlasmaClient, &client,
234+
if (!PyArg_ParseTuple(args, "O&Oni", PyObjectToPlasmaClient, &client,
238235
&object_id_list, &timeout, &num_returns)) {
239236
return NULL;
240237
}
@@ -262,8 +259,7 @@ PyObject *PyPlasma_wait(PyObject *self, PyObject *args) {
262259
return NULL;
263260
}
264261

265-
ObjectRequest *object_requests =
266-
(ObjectRequest *) malloc(sizeof(ObjectRequest) * n);
262+
std::vector<ObjectRequest> object_requests(n);
267263
for (int i = 0; i < n; ++i) {
268264
ARROW_CHECK(PyStringToUniqueID(PyList_GetItem(object_id_list, i),
269265
&object_requests[i].object_id) == 1);
@@ -273,8 +269,8 @@ PyObject *PyPlasma_wait(PyObject *self, PyObject *args) {
273269
* run. */
274270
int num_return_objects;
275271
Py_BEGIN_ALLOW_THREADS;
276-
ARROW_CHECK_OK(client->Wait((int) n, object_requests, num_returns,
277-
(uint64_t) timeout, num_return_objects));
272+
ARROW_CHECK_OK(client->Wait(n, object_requests.data(), num_returns,
273+
timeout, num_return_objects));
278274
Py_END_ALLOW_THREADS;
279275

280276
int num_to_return = std::min(num_return_objects, num_returns);
@@ -287,9 +283,9 @@ PyObject *PyPlasma_wait(PyObject *self, PyObject *args) {
287283
}
288284
if (object_requests[i].status == ObjectStatus_Local ||
289285
object_requests[i].status == ObjectStatus_Remote) {
290-
PyObject *ready =
291-
PyBytes_FromStringAndSize((char *) &object_requests[i].object_id,
292-
sizeof(object_requests[i].object_id));
286+
PyObject *ready = PyBytes_FromStringAndSize(
287+
reinterpret_cast<char *>(&object_requests[i].object_id),
288+
sizeof(object_requests[i].object_id));
293289
PyList_SetItem(ready_ids, num_returned, ready);
294290
PySet_Discard(waiting_ids, ready);
295291
num_returned += 1;
@@ -307,14 +303,14 @@ PyObject *PyPlasma_wait(PyObject *self, PyObject *args) {
307303

308304
PyObject *PyPlasma_evict(PyObject *self, PyObject *args) {
309305
PlasmaClient *client;
310-
long long num_bytes;
311-
if (!PyArg_ParseTuple(args, "O&L", PyObjectToPlasmaClient, &client,
306+
Py_ssize_t num_bytes;
307+
if (!PyArg_ParseTuple(args, "O&n", PyObjectToPlasmaClient, &client,
312308
&num_bytes)) {
313309
return NULL;
314310
}
315311
int64_t evicted_bytes;
316-
ARROW_CHECK_OK(client->Evict((int64_t) num_bytes, evicted_bytes));
317-
return PyLong_FromLong((long) evicted_bytes);
312+
ARROW_CHECK_OK(client->Evict(static_cast<int64_t>(num_bytes), evicted_bytes));
313+
return PyLong_FromSsize_t(static_cast<Py_ssize_t>(evicted_bytes));
318314
}
319315

320316
PyObject *PyPlasma_delete(PyObject *self, PyObject *args) {
@@ -388,7 +384,7 @@ PyObject *PyPlasma_receive_notification(PyObject *self, PyObject *args) {
388384
PyTuple_SetItem(t, 2, PyLong_FromLong(object_info->metadata_size()));
389385
}
390386

391-
free(notification);
387+
delete[] notification;
392388
return t;
393389
}
394390

cpp/src/plasma/extension.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
#define PLASMA_EXTENSION_H
2020

2121
#undef _XOPEN_SOURCE
22+
#undef _POSIX_C_SOURCE
2223
#include <Python.h>
23-
#include "bytesobject.h"
24+
#include "bytesobject.h" // NOLINT
2425

2526
static int PyObjectToPlasmaClient(PyObject *object, PlasmaClient **client) {
2627
if (PyCapsule_IsValid(object, "plasma")) {

cpp/src/plasma/malloc.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <unordered_map>
2727

2828
#include "plasma/common.h"
29+
#include "plasma/malloc.h"
2930

3031
extern "C" {
3132
void *fake_mmap(size_t);

0 commit comments

Comments
 (0)