forked from protocolbuffers/protobuf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New PHP C Extension based on upb_msg (protocolbuffers#7614)
* Added code for the new PHP extension. * Removed a bunch of unused variables shown by compiler warnings. * Test protobuf2 in the tests. * Updated upb version to fix a goldenfile test. * Added pure-PHP changes. Extension now passes all tests. * Enabled protobuf2 for all C extension tests. * Fixed pure=PHP lib: full names no longer start with '.'. * Added files for new extension to Makefile.am. * Downgraded make-preload.py to python 2, since python3 isn't available in the php_all Kokoro image. * Disable tests of new C extension with PHP 5.x. * Also do not compile the extension for PHP5. * Accept version 5.*.*, and use /usr/bin/python. * Addressed PR comments. * Addressed PR comments. * Added "const" to a parameter and fixed a memory leak seen in Valgrind. * Stop testing the C extension for PHP5. The next release of protobuf will deprecate the C extension for PHP5, see: protocolbuffers#7525 * Made the PHP5.6 Mac test only exercise pure-PHP. * Build protoc for PHP 5.6 test. * Rewrote bundling script in PHP to avoid dependency on Python. * A few more fixes. * Fixed int32/int64 behavior for 32-bit builds. * Match more PHP versions in testing script. * Use phpize --clean before building extension. * Force-delete configure.in to avoid phpize problems cross-version. * Delete both configure.ac and configure.in.
- Loading branch information
Showing
28 changed files
with
16,922 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Protocol Buffers - Google's data interchange format | ||
// Copyright 2008 Google Inc. All rights reserved. | ||
// https://developers.google.com/protocol-buffers/ | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are | ||
// met: | ||
// | ||
// * Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// * Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following disclaimer | ||
// in the documentation and/or other materials provided with the | ||
// distribution. | ||
// * Neither the name of Google Inc. nor the names of its | ||
// contributors may be used to endorse or promote products derived from | ||
// this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
#include <Zend/zend_API.h> | ||
|
||
#include "php-upb.h" | ||
|
||
// ----------------------------------------------------------------------------- | ||
// Arena | ||
// ----------------------------------------------------------------------------- | ||
|
||
typedef struct Arena { | ||
zend_object std; | ||
upb_arena* arena; | ||
} Arena; | ||
|
||
zend_class_entry *Arena_class_entry; | ||
static zend_object_handlers Arena_object_handlers; | ||
|
||
// PHP Object Handlers ///////////////////////////////////////////////////////// | ||
|
||
static zend_object* Arena_Create(zend_class_entry *class_type) { | ||
Arena *intern = emalloc(sizeof(Arena)); | ||
zend_object_std_init(&intern->std, class_type); | ||
intern->std.handlers = &Arena_object_handlers; | ||
intern->arena = upb_arena_new(); | ||
// Skip object_properties_init(), we don't allow derived classes. | ||
return &intern->std; | ||
} | ||
|
||
static void Arena_Free(zend_object* obj) { | ||
Arena* intern = (Arena*)obj; | ||
upb_arena_free(intern->arena); | ||
zend_object_std_dtor(&intern->std); | ||
} | ||
|
||
// C Functions from arena.h //////////////////////////////////////////////////// | ||
|
||
void Arena_Init(zval* val) { | ||
ZVAL_OBJ(val, Arena_Create(Arena_class_entry)); | ||
} | ||
|
||
upb_arena *Arena_Get(zval *val) { | ||
Arena *a = (Arena*)Z_OBJ_P(val); | ||
return a->arena; | ||
} | ||
|
||
// ----------------------------------------------------------------------------- | ||
// Module init. | ||
// ----------------------------------------------------------------------------- | ||
|
||
// No public methods. | ||
static const zend_function_entry Arena_methods[] = { | ||
ZEND_FE_END | ||
}; | ||
|
||
void Arena_ModuleInit() { | ||
zend_class_entry tmp_ce; | ||
|
||
INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\Arena", Arena_methods); | ||
Arena_class_entry = zend_register_internal_class(&tmp_ce); | ||
Arena_class_entry->create_object = Arena_Create; | ||
Arena_class_entry->ce_flags |= ZEND_ACC_FINAL; | ||
|
||
memcpy(&Arena_object_handlers, &std_object_handlers, | ||
sizeof(zend_object_handlers)); | ||
Arena_object_handlers.free_obj = Arena_Free; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Protocol Buffers - Google's data interchange format | ||
// Copyright 2008 Google Inc. All rights reserved. | ||
// https://developers.google.com/protocol-buffers/ | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are | ||
// met: | ||
// | ||
// * Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// * Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following disclaimer | ||
// in the documentation and/or other materials provided with the | ||
// distribution. | ||
// * Neither the name of Google Inc. nor the names of its | ||
// contributors may be used to endorse or promote products derived from | ||
// this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
#ifndef PHP_PROTOBUF_ARENA_H_ | ||
#define PHP_PROTOBUF_ARENA_H_ | ||
|
||
#include <php.h> | ||
|
||
#include "php-upb.h" | ||
|
||
// Registers the PHP Arena class. | ||
void Arena_ModuleInit(); | ||
|
||
// Creates and returns a new arena object that wraps a new upb_arena*. | ||
void Arena_Init(zval *val); | ||
|
||
// Gets the underlying upb_arena from this arena object. | ||
upb_arena *Arena_Get(zval *arena); | ||
|
||
#endif // PHP_PROTOBUF_ARENA_H_ |
Oops, something went wrong.