Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109518 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22257 invoked from network); 3 Apr 2020 09:19:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Apr 2020 09:19:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4EE711804C7 for ; Fri, 3 Apr 2020 00:46:36 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 3 Apr 2020 00:46:35 -0700 (PDT) Received: by mail-yb1-f179.google.com with SMTP id f14so3686981ybr.13 for ; Fri, 03 Apr 2020 00:46:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=IEvYdHdrz/AGcNnoXzmoMyyKcID7H5swn0PyHEzmPWI=; b=GEZ1AizlMNqpX/J6ZNuP2y4yHXc0hWEqWMb4g9W5/4sUG5oXS3LASJZZDii1hR2kcv CB+XQkaKikm+Nl4QcerRirGojyt4zq/Ef8U6KfHzWgH/6Ys23L7tJoD1Mw+sBmd7jWle FrdqRUEYzRUrziYJTIzlHNwXvGdZiZiAdaSEFydDFQMhPnbb7sJ9HkA9U8gCIZgJhgEz P34Orrq79oas4HV7bjClliz7JjZ+H6/qlp9Vy/KILh/roGVmWxtrFWl0aouNqZ0ZDwCm ypsWd2EWGyEGwYzPTgLRdO2hnenF7URUo9R82gp7kEB8SF80N19k4rU784+PlLrdmETF 4PQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=IEvYdHdrz/AGcNnoXzmoMyyKcID7H5swn0PyHEzmPWI=; b=FaTKoim34S7fNd4N5jaczFU2kDrfTdiBhddmCPI3s4UwH5N/hHtGUKhuFpkbGq5a3B 0MQnHBvwPRlUt3jKEYhJe3cYf1b4mPng/Nq6XUR8m7LSYUYWuuMe/I4zuK+3+XU8L+Eq i2aNu3V+U4882aGBw7Z56nRPEEwZo8M76QcCNKWf9Hw12WHu+9JptaTcsm6wFeHwdnDM N9afet/icZMwk7SuQcPnh0xx9pLlxzK0qtF/HrLbWHzEhAoBQJLS6KO6V7z+OCWquWLH 00hdU4r9Ph3vfevhXtU8YGcljP5p34nHLDksYlpUJdUdixqA0T9XZ91EX4gtIG39D1ko 7Lsg== X-Gm-Message-State: AGi0PuZJlaB7oFJDq13zIGXYc5ChydIqOEzspUFlr2zM//mnRdjXORg+ thw1NMot8R5n1yEACppBe3pRZwNaLHa2SdScQ0dPyTXWyLQ= X-Google-Smtp-Source: APiQypJLX6Nv4KJ6YACkk/dnR9dGOi8vE6C8ys101yqzITJkeT3ry39Nl0UJ93nnWqGwr0ZlLNFJx119632MnW24KZk= X-Received: by 2002:a25:5556:: with SMTP id j83mr11722357ybb.197.1585899993998; Fri, 03 Apr 2020 00:46:33 -0700 (PDT) MIME-Version: 1.0 Date: Fri, 3 Apr 2020 00:46:22 -0700 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000caac4705a25e1dfa" Subject: Memorizing zval objects From: sutabi@gmail.com (Joseph Montanez) --000000000000caac4705a25e1dfa Content-Type: text/plain; charset="UTF-8" I've been working on a PHP extension, binding RayLib. One issue I am running into is that objects are being freed, which is triggering things I don't want trigger until completely dereferenced. So I have the following lines of PHP code: $font = Font::fromCustom(__DIR__ . "/resources/KAISG.ttf", 96, 0, 0); $font->texture->genMipmaps(); Font is a struct from RayLib that I am trying to mirror into a PHP class with properties. Here is the RayLib C Struct: typedef struct Font { int baseSize; // Base size (default chars height) int charsCount; // Number of characters Texture2D texture; // Characters texture atlas Rectangle *recs; // Characters rectangles in texture CharInfo *chars; // Characters info data } Font; The issue is every time I call $font->texture and the result $texture object is not store, then its deference and the Texture object free function is called, which unloads the texture, even though the Font struct is still needing it. This is my fault as every time $font->texture is called, I create a brand new texture object: static zval * php_raylib_font_texture(php_raylib_font_object *obj) /* {{{ */ { zval *texture = malloc(sizeof(zval)); object_init_ex(texture, php_raylib_texture_ce); php_raylib_texture_object *result = Z_TEXTURE_OBJ_P(texture); result->texture = obj->font.texture; return texture; } /* }}} */ So after this line: $font->texture->genMipmaps(); A Texture object is created, and right dereferenced thus calling my free logic void php_raylib_texture_free_storage(zend_object *object TSRMLS_DC) { php_raylib_texture_object *intern = php_raylib_texture_fetch_object(object); zend_object_std_dtor(&intern->std); UnloadTexture(intern->texture); } So I assume I need to start storing the texture object, on my Font object. Currently, it's defined like this: typedef struct _php_raylib_font_object { Font font; HashTable *prop_handler; zend_object std; } php_raylib_font_object; Am I to add another zend_object, zval or the struct def for Texture? I.E typedef struct _php_raylib_font_object { Font font; HashTable *prop_handler; zend_object texture; // Do I use zend_object? zval texture; // Do I use zval? php_raylib_texture_object texture; //Do I use the struct defined for texture? zend_object std; } php_raylib_font_object; For reference here is the Texture header: https://github.com/joseph-montanez/raylib-php/blob/master/raylib-texture.h Thanks, Joseph Montanez --000000000000caac4705a25e1dfa--