Skip to content

Commit

Permalink
Create stub
Browse files Browse the repository at this point in the history
  • Loading branch information
cataphract committed Nov 23, 2023
1 parent 3c758fa commit 622a18f
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 26 deletions.
36 changes: 10 additions & 26 deletions ext/integrations/exec_integration.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#include <ext/standard/file.h>
#include <ext/standard/proc_open.h>

#include "compatibility.h"
#include "ddtrace.h"
#include "span.h"
#include "../compatibility.h"
#include "../ddtrace.h"
#include "../span.h"
#include "exec_integration_arginfo.h"

#define NS "DDTrace\\Integrations\\Exec\\"

Expand Down Expand Up @@ -262,33 +263,16 @@ static PHP_FUNCTION(DDTrace_integrations_exec_test_rshutdown) {

ddtrace_exec_handlers_rshutdown();
dd_exec_init_track_streams();
(void)return_value;
RETURN_TRUE;
}

// clang-format off
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(register_stream, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, stream, IS_RESOURCE, 0)
ZEND_ARG_OBJ_INFO(0, span, DDTrace\\SpanData, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(proc_assoc_span, 0, 2, _IS_BOOL, 1)
ZEND_ARG_TYPE_INFO(0, proc_res, IS_RESOURCE, 0)
ZEND_ARG_OBJ_INFO(0, span, DDTrace\\SpanData, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(proc_get_span, 0, 1, DDTrace\\SpanData, 0)
ZEND_ARG_TYPE_INFO(0, proc_res, IS_RESOURCE, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(proc_get_pid, 0, 1, IS_LONG, 1)
ZEND_ARG_TYPE_INFO(0, proc_res, IS_RESOURCE, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(test_rshutdown, 0, 0, IS_NULL, 1)
ZEND_END_ARG_INFO()

static const zend_function_entry functions[] = {
ZEND_RAW_FENTRY(NS "register_stream", PHP_FN(DDTrace_integrations_exec_register_stream), register_stream, 0)
ZEND_RAW_FENTRY(NS "proc_assoc_span", PHP_FN(DDTrace_integrations_exec_proc_assoc_span), proc_assoc_span, 0)
ZEND_RAW_FENTRY(NS "proc_get_span", PHP_FN(DDTrace_integrations_exec_proc_get_span), proc_get_span, 0)
ZEND_RAW_FENTRY(NS "proc_get_pid", PHP_FN(DDTrace_integrations_exec_proc_get_pid), proc_get_pid, 0)
ZEND_RAW_FENTRY(NS "test_rshutdown", PHP_FN(DDTrace_integrations_exec_test_rshutdown), test_rshutdown, 0)
ZEND_RAW_FENTRY(NS "register_stream", PHP_FN(DDTrace_integrations_exec_register_stream), arginfo_DDTrace_Integrations_Exec_register_stream, 0)
ZEND_RAW_FENTRY(NS "proc_assoc_span", PHP_FN(DDTrace_integrations_exec_proc_assoc_span), arginfo_DDTrace_Integrations_Exec_proc_assoc_span, 0)
ZEND_RAW_FENTRY(NS "proc_get_span", PHP_FN(DDTrace_integrations_exec_proc_get_span), arginfo_DDTrace_Integrations_Exec_proc_get_span, 0)
ZEND_RAW_FENTRY(NS "proc_get_pid", PHP_FN(DDTrace_integrations_exec_proc_get_pid), arginfo_DDTrace_Integrations_Exec_proc_get_pid, 0)
ZEND_RAW_FENTRY(NS "test_rshutdown", PHP_FN(DDTrace_integrations_exec_test_rshutdown), arginfo_DDTrace_Integrations_Exec_test_rshutdown, 0)
PHP_FE_END
};
// clang-format on
Expand Down
60 changes: 60 additions & 0 deletions ext/integrations/exec_integration.stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace DDTrace\Integrations\Exec {

/**
* Associates a popen() stream resource with a span so that when the resource is destroyed, the span is updated
* with the exit code and closed.
*
* It is not validated that the stream is actually a popen() stream resource.
*
* Only one span can be associated with a stream resource. A subsequent call replaces the first span.
*
* @internal for use by the exec integration only
* @param resource $stream A stream resource
* @param \DDTrace\SpanData $span The command_execution span to associate
* @return bool true on success or false if the resource is not a stream
*/
function register_stream($stream, \DDTrace\SpanData $span): bool {}

/**
* Associates a proc_open() process handle with a span so that when the handle is closed, there is a waitpid()
* call on the child, and the span is updated with the exit code and closed.
*
* Only one call to this function can be made per process handle. A subsequent call has undefined behavior.
*
* @internal for use by the exec integration only
* @param resource $proc_h A process handle
* @param \DDTrace\SpanData $span The command_execution span to associate
* @return bool true on success or false if the resource is not a process handle
*/
function proc_assoc_span($proc_h, \DDTrace\SpanData $span) : bool {}

/**
* Retrieves a span previously associated with a process handle by proc_assoc_span(), or
* null if there's none.
*
* @internal for use by the exec integration only
* @param resource $proc_h A process handle
* @return \DDTrace\SpanData|null The associated span, if any.
*/
function proc_get_span($proc_h) : ?\DDTrace\SpanData {}

/**
* Retrieves the pid associated with a process handle.
*
* @internal for use by the testes of the exec integration only
* @param resource $proc_h A process handle
* @return int|null The associated span, if any.
*/
function proc_get_pid($proc_h) : ?int {}

/**
* Closes the spans associated with live resources opened by popen() and proc_open()
*
* @internal for use by the testes of the exec integration only
* @return bool
*/
function test_rshutdown() : bool {}
}

23 changes: 23 additions & 0 deletions ext/integrations/exec_integration_arginfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 97cc0e5375b6d1d07fa0db5a4dba3e102709674f */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_DDTrace_Integrations_Exec_register_stream, 0, 2, _IS_BOOL, 0)
ZEND_ARG_INFO(0, stream)
ZEND_ARG_OBJ_INFO(0, span, DDTrace\\SpanData, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_DDTrace_Integrations_Exec_proc_assoc_span, 0, 2, _IS_BOOL, 0)
ZEND_ARG_INFO(0, proc_h)
ZEND_ARG_OBJ_INFO(0, span, DDTrace\\SpanData, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_DDTrace_Integrations_Exec_proc_get_span, 0, 1, DDTrace\\SpanData, 1)
ZEND_ARG_INFO(0, proc_h)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_DDTrace_Integrations_Exec_proc_get_pid, 0, 1, IS_LONG, 1)
ZEND_ARG_INFO(0, proc_h)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_DDTrace_Integrations_Exec_test_rshutdown, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()

0 comments on commit 622a18f

Please sign in to comment.