@@ -1557,6 +1557,11 @@ void v8__base__SetDcheckFunction(void (*func)(const char*, int, const char*)) {
15571557
15581558// Utils
15591559
1560+ struct CZigString {
1561+ const char *ptr = nullptr ;
1562+ uint64_t len = 0 ;
1563+ };
1564+
15601565// / Header for Zig
15611566// / Allocates `bytes` bytes of memory using the allocator.
15621567// / @param allocator: A Zig std.mem.Allocator
@@ -1607,37 +1612,34 @@ const char* allocStringWith0(const v8_inspector::String16& str, const void* allo
16071612// / The strings pointer and length should therefore be returned together
16081613// / @param str: The string contents to allocate
16091614// / @param allocator: A Zig std.mem.Allocator
1610- // / @param out_str: Points to the now allocated string on the heap (without sentinel \0),null if view was null or allocation failed
1611- // / @param out_len: The corresponding length of the string
1615+ // / @param out: Points to the now allocated string on the heap (without sentinel \0), NULL if view was null, invalid if allocation failed
16121616// / @returns false if allocation errored
1613- bool allocString (const v8_inspector::StringView& str , const void * allocator, const char *& out_str, size_t & out_len ) {
1614- if (str .characters8 () == nullptr ) {
1615- out_str = nullptr ;
1616- out_len = 0 ;
1617+ bool allocString (const v8_inspector::StringView& input , const void * allocator, CZigString& output ) {
1618+ if (input .characters8 () == nullptr ) {
1619+ output. ptr = nullptr ;
1620+ output. len = 0 ;
16171621 return true ;
16181622 }
16191623
16201624 std::string utf8_str; // Harmless if not used by 8bit string
1621- if (str .is8Bit ()) {
1622- out_len = str .length ();
1625+ if (input .is8Bit ()) {
1626+ output. len = input .length ();
16231627 } else {
1624- utf8_str = v8_inspector::UTF16ToUTF8 (str .characters16 (), str .length ());
1625- out_len = utf8_str.length ();
1628+ utf8_str = v8_inspector::UTF16ToUTF8 (input .characters16 (), input .length ());
1629+ output. len = utf8_str.length ();
16261630 }
16271631
1628- char * heap_str = zigAlloc (allocator, out_len );
1632+ char * heap_str = zigAlloc (allocator, output. len );
16291633 if (heap_str == nullptr ) {
1630- out_str = nullptr ;
1631- out_len = 0 ;
16321634 return false ;
16331635 }
16341636
1635- if (str .is8Bit ()) {
1636- memcpy (heap_str, str .characters8 (), out_len );
1637+ if (input .is8Bit ()) {
1638+ memcpy (heap_str, input .characters8 (), output. len );
16371639 } else {
1638- memcpy (heap_str, utf8_str.c_str (), out_len );
1640+ memcpy (heap_str, utf8_str.c_str (), output. len );
16391641 }
1640- out_str = heap_str;
1642+ output. ptr = heap_str;
16411643 return true ;
16421644}
16431645
@@ -1714,16 +1716,13 @@ v8_inspector::protocol::Runtime::RemoteObject* v8_inspector__Session__wrapObject
17141716bool v8_inspector__Session__unwrapObject (
17151717 v8_inspector::V8InspectorSession *session,
17161718 const void *allocator,
1717- const char *&out_error,
1718- uint64_t &out_error_len,
1719- const char *in_objectId,
1720- int in_objectId_len,
1719+ CZigString &out_error,
1720+ CZigString in_objectId,
17211721 v8::Local<v8::Value> &out_value,
17221722 v8::Local<v8::Context> &out_context,
1723- const char *&out_objectGroup,
1724- uint64_t &out_objectGroup_len
1723+ CZigString &out_objectGroup
17251724) {
1726- auto objectId = toStringView (in_objectId, in_objectId_len );
1725+ auto objectId = toStringView (in_objectId. ptr , in_objectId. len );
17271726 auto error = v8_inspector::StringBuffer::create ({});
17281727 auto objectGroup = v8_inspector::StringBuffer::create ({});
17291728
@@ -1734,10 +1733,10 @@ bool v8_inspector__Session__unwrapObject(
17341733 // [out optional ] std::unique_ptr<StringBuffer>* objectGroup
17351734 bool result = session->unwrapObject (&error, objectId, &out_value, &out_context, &objectGroup);
17361735 if (!result) {
1737- allocString (error->string (), allocator, out_error, out_error_len );
1736+ allocString (error->string (), allocator, out_error);
17381737 return false ;
17391738 }
1740- return allocString (objectGroup->string (), allocator, out_objectGroup, out_objectGroup_len );
1739+ return allocString (objectGroup->string (), allocator, out_objectGroup);
17411740}
17421741
17431742// RemoteObject
0 commit comments