From 7a9ade7740de07f7091940c7d38e4ee3781562ec Mon Sep 17 00:00:00 2001

From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= jaakko.keranen@iki.fi

Date: Sun, 25 Apr 2021 08:57:59 +0300

Subject: [PATCH 1/1] GmRequest: Use unique IDs to avoid confusion

It is conceivable that a newly created GmRequest gets the same memory location than the one just destroyed.

IssueID #148


src/gmrequest.c | 21 ++++++++++++++++-----

src/gmrequest.h | 1 +

src/ui/command.c | 9 +++++++++

src/ui/command.h | 21 +++++++++++----------

src/ui/documentwidget.c | 18 +++++++++++++-----

5 files changed, 50 insertions(+), 20 deletions(-)

diff --git a/src/gmrequest.c b/src/gmrequest.c

index c968990c..693bfe4a 100644

--- a/src/gmrequest.c

+++ b/src/gmrequest.c

@@ -116,6 +116,8 @@ void deserialize_GmResponse(iGmResponse *d, iStream *ins) {

/----------------------------------------------------------------------------------------------/

+static iAtomicInt idGen_;

enum iGmRequestState {

 initialized_GmRequestState,

 receivingHeader_GmRequestState,

@@ -126,6 +128,7 @@ enum iGmRequestState {

struct Impl_GmRequest {

 iObject              object;

 iMutex *             mtx;

 iGmCerts *           certs; /* not owned */

 enum iGmRequestState state;

@@ -471,7 +474,8 @@ static void beginGopherConnection_GmRequest_(iGmRequest *d, const iString *host,

/----------------------------------------------------------------------------------------------/

void init_GmRequest(iGmRequest *d, iGmCerts *certs) {

 d->resp = new_GmResponse();

 d->isFilterEnabled = iTrue;

 d->isRespLocked    = iFalse;

@@ -713,11 +717,18 @@ void unlockResponse_GmRequest(iGmRequest *d) {

 }

}

+uint32_t id_GmRequest(const iGmRequest *d) {

+}

iBool isFinished_GmRequest(const iGmRequest *d) {

}

enum iGmStatusCode status_GmRequest(const iGmRequest *d) {

diff --git a/src/gmrequest.h b/src/gmrequest.h

index 9f20e0eb..2cf9e4ff 100644

--- a/src/gmrequest.h

+++ b/src/gmrequest.h

@@ -73,6 +73,7 @@ void cancel_GmRequest (iGmRequest *);

iGmResponse * lockResponse_GmRequest (iGmRequest *);

void unlockResponse_GmRequest (iGmRequest *);

+uint32_t id_GmRequest (const iGmRequest ); / unique ID */

iBool isFinished_GmRequest (const iGmRequest *);

enum iGmStatusCode status_GmRequest (const iGmRequest *);

const iString * meta_GmRequest (const iGmRequest *);

diff --git a/src/ui/command.c b/src/ui/command.c

index c5ca164e..3ae0f0c9 100644

--- a/src/ui/command.c

+++ b/src/ui/command.c

@@ -50,6 +50,15 @@ int arg_Command(const char *cmd) {

 return argLabel_Command(cmd, "arg");

}

+uint32_t argU32Label_Command(const char *cmd, const char *label) {

+}

float argfLabel_Command(const char *cmd, const char *label) {

 const iString *tok = tokenString_(label);

 const char *ptr = strstr(cmd, cstr_String(tok));

diff --git a/src/ui/command.h b/src/ui/command.h

index 43992b8e..10a29101 100644

--- a/src/ui/command.h

+++ b/src/ui/command.h

@@ -25,16 +25,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

#include <the_Foundation/range.h>

#include <the_Foundation/vec2.h>

-iBool equal_Command (const char *commandWithArgs, const char *command);

-int arg_Command (const char ); / arg: */

-float argf_Command (const char ); / arg: */

-int argLabel_Command (const char *, const char *label);

-float argfLabel_Command (const char *, const char *label);

-void * pointer_Command (const char ); / ptr: */

-void * pointerLabel_Command (const char *, const char *label);

-iInt2 coord_Command (const char *);

-iInt2 dir_Command (const char *);

+iBool equal_Command (const char *commandWithArgs, const char *command);

+int arg_Command (const char ); / arg: */

+float argf_Command (const char ); / arg: */

+int argLabel_Command (const char *, const char *label);

+uint32_t argU32Label_Command (const char *, const char *label);

+float argfLabel_Command (const char *, const char *label);

+void * pointer_Command (const char ); / ptr: */

+void * pointerLabel_Command (const char *, const char *label);

+iInt2 coord_Command (const char *);

+iInt2 dir_Command (const char *);

const iString * string_Command (const char *, const char label); / space-delimited */

iRangecc range_Command (const char *, const char label); / space-delimited */

diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c

index f3c9ea82..13ef878f 100644

--- a/src/ui/documentwidget.c

+++ b/src/ui/documentwidget.c

@@ -394,13 +394,21 @@ static void requestUpdated_DocumentWidget_(iAnyObject *obj) {

 iDocumentWidget *d = obj;

 const int wasUpdated = exchange_Atomic(&d->isRequestUpdated, iTrue);

 if (!wasUpdated) {

 }

}

static void requestFinished_DocumentWidget_(iAnyObject *obj) {

 iDocumentWidget *d = obj;

}

static int documentWidth_DocumentWidget_(const iDocumentWidget *d) {

@@ -965,7 +973,7 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse

 if (d->state == ready_RequestState) {

     return;

 }

 /* TODO: Do document update in the background. However, that requires a text metrics calculator

    that does not try to cache the glyph bitmaps. */

 const enum iGmStatusCode statusCode = response->statusCode;

@@ -1892,7 +1900,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)

     return iTrue;

 }

 else if (equalWidget_Command(cmd, w, "document.request.updated") &&

     set_Block(&d->sourceContent, &lockResponse_GmRequest(d->request)->body);

     unlockResponse_GmRequest(d->request);

     if (document_App() == d) {

@@ -1903,7 +1911,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)

     return iFalse;

 }

 else if (equalWidget_Command(cmd, w, "document.request.finished") &&

     set_Block(&d->sourceContent, body_GmRequest(d->request));

     if (!isSuccess_GmStatusCode(status_GmRequest(d->request))) {

         format_String(&d->sourceHeader,

--

2.25.1

Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.15/patch/7a9ade7740de07f7091940c7d38e4ee3781562ec.patch
Status Code
Success (20)
Meta
text/plain
Capsule Response Time
431.86797 milliseconds
Gemini-to-HTML Time
2.835219 milliseconds

This content has been proxied by September (ba2dc).