MCPcopy Create free account
hub / github.com/bloomberg/pystack / loadFromPython3

Method loadFromPython3

src/pystack/_pystack/pytypes.cpp:358–405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

356}
357
358void
359DictObject::loadFromPython3(remote_addr_t addr)
360{
361 Structure<py_dict_v> dict(d_manager, addr);
362
363 ssize_t num_items;
364 std::vector<Python3::PyDictKeyEntry> valid_entries;
365
366 getDictEntries(d_manager, dict, num_items, valid_entries);
367
368 // Copy the keys
369 d_keys.reserve(valid_entries.size());
370 std::transform(
371 valid_entries.cbegin(),
372 valid_entries.cend(),
373 std::back_inserter(d_keys),
374 [](auto& entry) { return (remote_addr_t)entry.me_key; });
375
376 /* The DictObject can be in one of two forms.
377 *
378 * Either:
379 * A combined table:
380 * ma_values == NULL, dk_refcnt == 1.
381 * Values are stored in the me_value field of the PyDictKeysObject.
382 * Or:
383 * A split table:
384 * ma_values != NULL, dk_refcnt >= 1
385 * Values are stored in the ma_values array.
386 * Only string (unicode) keys are allowed.
387 * All dicts sharing same key must have same insertion order.
388 */
389
390 remote_addr_t dictvalues_addr = dict.getField(&py_dict_v::o_ma_values);
391 Structure<py_dictvalues_v> dictvalues(d_manager, dictvalues_addr);
392
393 // Get the values in one copy if we are dealing with a split-table dictionary
394 if (dictvalues_addr != 0) {
395 d_values.resize(num_items);
396 auto values_addr = dictvalues.getFieldRemoteAddress(&py_dictvalues_v::o_values);
397 d_manager->copyMemoryFromProcess(values_addr, num_items * sizeof(PyObject*), d_values.data());
398 } else {
399 std::transform(
400 valid_entries.cbegin(),
401 valid_entries.cend(),
402 std::back_inserter(d_values),
403 [](auto& entry) { return (remote_addr_t)entry.me_value; });
404 }
405}
406
407void
408DictObject::loadFromPython2(remote_addr_t addr)

Callers

nothing calls this directly

Calls 4

getDictEntriesFunction · 0.85
sizeMethod · 0.80
getFieldRemoteAddressMethod · 0.80
copyMemoryFromProcessMethod · 0.45

Tested by

no test coverage detected