Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert resources to objects in ext/pgsql #6791

Closed
wants to merge 14 commits into from

Conversation

kocsismate
Copy link
Member

@kocsismate kocsismate commented Mar 21, 2021

No description provided.

ext/pgsql/pgsql.stub.php Outdated Show resolved Hide resolved

/* Compatibility definitions */

#ifndef HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT
#define pg_encoding_to_char(x) "SQL_ASCII"
#endif

/* {{{ _php_pgsql_trim_message */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed some of these unnecessary comments because they annoyed me at some point

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does make a lot of noise in the PR sadly :-/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it was not a good idea to do this here. I can get rid of these changes If they make code review difficult

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to simply separately land a removal of all folder marks in pgsql (though I don't mind it being part of this change).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do it separately!

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK from a quick glance if persistent connections still work (as currently there is no plan nor deprecation getting rid of those)

ext/pgsql/pgsql.c Outdated Show resolved Hide resolved
ext/pgsql/pgsql.c Show resolved Hide resolved
ext/pgsql/pgsql.c Outdated Show resolved Hide resolved
ext/pgsql/pgsql.c Outdated Show resolved Hide resolved
@nikic
Copy link
Member

nikic commented Mar 22, 2021

/home/vsts/work/1/s/ext/pgsql/pgsql.c:1515:10: error: unused variable ‘pg_link’ [-Werror=unused-variable]

@kocsismate kocsismate marked this pull request as draft March 22, 2021 09:17
@kocsismate kocsismate force-pushed the pgsql-resource branch 2 times, most recently from 9c9bb86 to 45f55f7 Compare March 24, 2021 23:51
@kocsismate
Copy link
Member Author

Now only ~12 tests fail and I also tried to implement the suggestionss in in c7a86a3 (notices doesn't yet work perfectly).

@kocsismate
Copy link
Member Author

kocsismate commented Apr 2, 2021

My latest commit (6931655) fixes all tests, finally!

@kocsismate kocsismate force-pushed the pgsql-resource branch 2 times, most recently from 6931655 to eb22b17 Compare April 2, 2021 19:29
@kocsismate kocsismate force-pushed the pgsql-resource branch 2 times, most recently from dbf23ba to 98c2c0d Compare April 20, 2021 22:38
NEWS Outdated Show resolved Hide resolved
ext/pgsql/pgsql.stub.php Outdated Show resolved Hide resolved
ext/pgsql/tests/80_bug32223b.phpt Show resolved Hide resolved
ext/pgsql/pgsql.c Outdated Show resolved Hide resolved
ext/pgsql/php_pgsql.h Outdated Show resolved Hide resolved

/* Compatibility definitions */

#ifndef HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT
#define pg_encoding_to_char(x) "SQL_ASCII"
#endif

/* {{{ _php_pgsql_trim_message */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to simply separately land a removal of all folder marks in pgsql (though I don't mind it being part of this change).

ext/pgsql/pgsql.c Outdated Show resolved Hide resolved
ext/pgsql/pgsql.c Outdated Show resolved Hide resolved
ext/pgsql/pgsql.c Outdated Show resolved Hide resolved
ext/pgsql/pgsql.c Show resolved Hide resolved
@kocsismate
Copy link
Member Author

I addressed most of the review comments, however, currently many tests end up with a memory leak. The issue is with the default connection handling, so I'll continue chasing this problem.

@nikic
Copy link
Member

nikic commented May 10, 2021

I pushed a few changes that should fix the leaks.

@nikic
Copy link
Member

nikic commented May 10, 2021

Windows build failed with:

========DIFF========
002+  
     int(%d)
     int(%d)
========DONE========
FAIL Bug #72197 pg_lo_create arbitrary read [C:\projects\php-src\ext\pgsql\tests\bug72197.phpt]

Not really obvious to me why ...

}

if ((pgsql = (PGconn *)zend_fetch_resource2(link, "PostgreSQL link", le_link, le_plink)) == NULL) {
zend_argument_type_error(1, "must be of type PgSql when the connection is provided");
Copy link
Member

@nikic nikic May 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zend_argument_type_error(1, "must be of type PgSql when the connection is provided");
zend_argument_type_error(1, "must be of type PgSql\\Connection when the connection is provided");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one isn't resolved yet.

ext/pgsql/pgsql.c Outdated Show resolved Hide resolved
ext/pgsql/pgsql.c Outdated Show resolved Hide resolved
ext/pgsql/pgsql.c Outdated Show resolved Hide resolved
ext/pgsql/php_pgsql.h Outdated Show resolved Hide resolved
ext/pgsql/pgsql.c Outdated Show resolved Hide resolved
ext/pgsql/pgsql.c Outdated Show resolved Hide resolved
@kocsismate
Copy link
Member Author

I had to force push because of a conflict in the readme, but only the last commit is new.

}

if ((pgsql = (PGconn *)zend_fetch_resource2(link, "PostgreSQL link", le_link, le_plink)) == NULL) {
zend_argument_type_error(1, "must be of type PgSql when the connection is provided");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one isn't resolved yet.

@kocsismate kocsismate deleted the pgsql-resource branch May 10, 2021 22:11
@kocsismate
Copy link
Member Author

This one isn't resolved yet.

Did it when applying the commit!

weierophinney added a commit to weierophinney/laminas-db that referenced this pull request Sep 21, 2021
Per:

- php/php-src#6791
- https://github.com/php/php-src/blob/a846547ed4bb67f00dc12bbfc529e9c992cbfd07/UPGRADING

The pgsql functions now accept and return **resource objects** and not **resources**.
As such, the return value of `get_resource_type()` varies, and technically, in PHP 8.1, we should not use `is_resource()`, but a typecheck instead.
However, we still need to support pre-8.1 code as well.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants