Skip to content

Declare ext/gmp constants in stubs #8704

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

Merged
merged 3 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions ext/gmp/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,28 @@
#include "zend_exceptions.h"

#include <gmp.h>
#include "gmp_arginfo.h"

/* Needed for gmp_random() */
#include "ext/standard/php_rand.h"
#include "ext/standard/php_lcg.h"

#define GMP_ROUND_ZERO 0
#define GMP_ROUND_PLUSINF 1
#define GMP_ROUND_MINUSINF 2

#ifdef mpir_version
#define GMP_MPIR_VERSION_STRING ((char *) mpir_version)
#endif
#define GMP_VERSION_STRING ((char *) gmp_version)

#define GMP_MSW_FIRST (1 << 0)
#define GMP_LSW_FIRST (1 << 1)
#define GMP_LITTLE_ENDIAN (1 << 2)
#define GMP_BIG_ENDIAN (1 << 3)
#define GMP_NATIVE_ENDIAN (1 << 4)

#include "gmp_arginfo.h"

ZEND_DECLARE_MODULE_GLOBALS(gmp)
static ZEND_GINIT_FUNCTION(gmp);

Expand Down Expand Up @@ -75,16 +91,6 @@ typedef struct _gmp_temp {
bool is_used;
} gmp_temp_t;

#define GMP_ROUND_ZERO 0
#define GMP_ROUND_PLUSINF 1
#define GMP_ROUND_MINUSINF 2

#define GMP_MSW_FIRST (1 << 0)
#define GMP_LSW_FIRST (1 << 1)
#define GMP_LITTLE_ENDIAN (1 << 2)
#define GMP_BIG_ENDIAN (1 << 3)
#define GMP_NATIVE_ENDIAN (1 << 4)

#define GMP_MAX_BASE 62

#define GMP_51_OR_NEWER \
Expand Down Expand Up @@ -540,19 +546,7 @@ ZEND_MINIT_FUNCTION(gmp)
gmp_object_handlers.do_operation = gmp_do_operation;
gmp_object_handlers.compare = gmp_compare;

REGISTER_LONG_CONSTANT("GMP_ROUND_ZERO", GMP_ROUND_ZERO, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GMP_ROUND_PLUSINF", GMP_ROUND_PLUSINF, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GMP_ROUND_MINUSINF", GMP_ROUND_MINUSINF, CONST_CS | CONST_PERSISTENT);
#ifdef mpir_version
REGISTER_STRING_CONSTANT("GMP_MPIR_VERSION", (char *)mpir_version, CONST_CS | CONST_PERSISTENT);
#endif
REGISTER_STRING_CONSTANT("GMP_VERSION", (char *)gmp_version, CONST_CS | CONST_PERSISTENT);

REGISTER_LONG_CONSTANT("GMP_MSW_FIRST", GMP_MSW_FIRST, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GMP_LSW_FIRST", GMP_LSW_FIRST, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GMP_LITTLE_ENDIAN", GMP_LITTLE_ENDIAN, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GMP_BIG_ENDIAN", GMP_BIG_ENDIAN, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GMP_NATIVE_ENDIAN", GMP_NATIVE_ENDIAN, CONST_CS | CONST_PERSISTENT);
register_gmp_symbols(module_number);

return SUCCESS;
}
Expand Down
55 changes: 55 additions & 0 deletions ext/gmp/gmp.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,61 @@

/** @generate-class-entries */

/**
* @var int
* @cname GMP_ROUND_ZERO
*/
const GMP_ROUND_ZERO = UNKNOWN;
/**
* @var int
* @cname GMP_ROUND_PLUSINF
*/
const GMP_ROUND_PLUSINF = UNKNOWN;
/**
* @var int
* @cname GMP_ROUND_MINUSINF
*/
const GMP_ROUND_MINUSINF = UNKNOWN;

#ifdef mpir_version
/**
* @var string
* @cname GMP_MPIR_VERSION_STRING
*/
const GMP_MPIR_VERSION = UNKNOWN;
#endif
/**
* @var string
* @cname GMP_VERSION_STRING
*/
const GMP_VERSION = UNKNOWN;

/**
* @var int
* @cname GMP_MSW_FIRST
*/
const GMP_MSW_FIRST = UNKNOWN;
/**
* @var int
* @cname GMP_LSW_FIRST
*/
const GMP_LSW_FIRST = UNKNOWN;
/**
* @var int
* @cname GMP_LITTLE_ENDIAN
*/
const GMP_LITTLE_ENDIAN = UNKNOWN;
/**
* @var int
* @cname GMP_BIG_ENDIAN
*/
const GMP_BIG_ENDIAN = UNKNOWN;
/**
* @var int
* @cname GMP_NATIVE_ENDIAN
*/
const GMP_NATIVE_ENDIAN = UNKNOWN;

class GMP
{
public function __serialize(): array {}
Expand Down
18 changes: 17 additions & 1 deletion ext/gmp/gmp_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: be077a57bc9ddbb9100fadfb212857c0b8f21ebf */
* Stub hash: da609931609768d5e874f460cf0b162d813066f0 */

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_gmp_init, 0, 1, GMP, 0)
ZEND_ARG_TYPE_MASK(0, num, MAY_BE_LONG|MAY_BE_STRING, NULL)
Expand Down Expand Up @@ -308,6 +308,22 @@ static const zend_function_entry class_GMP_methods[] = {
ZEND_FE_END
};

static void register_gmp_symbols(int module_number)
{
REGISTER_LONG_CONSTANT("GMP_ROUND_ZERO", GMP_ROUND_ZERO, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GMP_ROUND_PLUSINF", GMP_ROUND_PLUSINF, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GMP_ROUND_MINUSINF", GMP_ROUND_MINUSINF, CONST_CS | CONST_PERSISTENT);
#if defined(mpir_version)
REGISTER_STRING_CONSTANT("GMP_MPIR_VERSION", GMP_MPIR_VERSION_STRING, CONST_CS | CONST_PERSISTENT);
#endif
REGISTER_STRING_CONSTANT("GMP_VERSION", GMP_VERSION_STRING, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GMP_MSW_FIRST", GMP_MSW_FIRST, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GMP_LSW_FIRST", GMP_LSW_FIRST, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GMP_LITTLE_ENDIAN", GMP_LITTLE_ENDIAN, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GMP_BIG_ENDIAN", GMP_BIG_ENDIAN, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GMP_NATIVE_ENDIAN", GMP_NATIVE_ENDIAN, CONST_CS | CONST_PERSISTENT);
}

static zend_class_entry *register_class_GMP(void)
{
zend_class_entry ce, *class_entry;
Expand Down